1 /*******************************************************************************
2 * Copyright (c) 2010, 2016 Ericsson
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * Patrick Tasse - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.tracecompass
.internal
.tmf
.ui
.parsers
.wizards
;
15 import static org
.eclipse
.tracecompass
.common
.core
.NonNullUtils
.checkNotNull
;
17 import java
.io
.BufferedReader
;
18 import java
.io
.IOException
;
19 import java
.io
.InputStreamReader
;
21 import java
.text
.ParseException
;
22 import java
.util
.AbstractMap
.SimpleEntry
;
23 import java
.util
.ArrayList
;
24 import java
.util
.Arrays
;
25 import java
.util
.HashMap
;
26 import java
.util
.Iterator
;
27 import java
.util
.List
;
29 import java
.util
.Map
.Entry
;
30 import java
.util
.Scanner
;
31 import java
.util
.regex
.Matcher
;
32 import java
.util
.regex
.Pattern
;
33 import java
.util
.regex
.PatternSyntaxException
;
35 import org
.eclipse
.core
.resources
.IFile
;
36 import org
.eclipse
.core
.runtime
.CoreException
;
37 import org
.eclipse
.core
.runtime
.FileLocator
;
38 import org
.eclipse
.core
.runtime
.IPath
;
39 import org
.eclipse
.core
.runtime
.Path
;
40 import org
.eclipse
.core
.runtime
.Platform
;
41 import org
.eclipse
.jface
.viewers
.ColumnLabelProvider
;
42 import org
.eclipse
.jface
.viewers
.ISelection
;
43 import org
.eclipse
.jface
.viewers
.ISelectionChangedListener
;
44 import org
.eclipse
.jface
.viewers
.IStructuredSelection
;
45 import org
.eclipse
.jface
.viewers
.ITreeContentProvider
;
46 import org
.eclipse
.jface
.viewers
.SelectionChangedEvent
;
47 import org
.eclipse
.jface
.viewers
.StructuredSelection
;
48 import org
.eclipse
.jface
.viewers
.TreeViewer
;
49 import org
.eclipse
.jface
.viewers
.Viewer
;
50 import org
.eclipse
.jface
.wizard
.WizardPage
;
51 import org
.eclipse
.osgi
.util
.NLS
;
52 import org
.eclipse
.swt
.SWT
;
53 import org
.eclipse
.swt
.browser
.Browser
;
54 import org
.eclipse
.swt
.browser
.TitleEvent
;
55 import org
.eclipse
.swt
.browser
.TitleListener
;
56 import org
.eclipse
.swt
.custom
.SashForm
;
57 import org
.eclipse
.swt
.custom
.ScrolledComposite
;
58 import org
.eclipse
.swt
.custom
.StyleRange
;
59 import org
.eclipse
.swt
.custom
.StyledText
;
60 import org
.eclipse
.swt
.events
.ModifyEvent
;
61 import org
.eclipse
.swt
.events
.ModifyListener
;
62 import org
.eclipse
.swt
.events
.SelectionAdapter
;
63 import org
.eclipse
.swt
.events
.SelectionEvent
;
64 import org
.eclipse
.swt
.events
.SelectionListener
;
65 import org
.eclipse
.swt
.events
.VerifyEvent
;
66 import org
.eclipse
.swt
.events
.VerifyListener
;
67 import org
.eclipse
.swt
.graphics
.Color
;
68 import org
.eclipse
.swt
.graphics
.Font
;
69 import org
.eclipse
.swt
.graphics
.FontData
;
70 import org
.eclipse
.swt
.graphics
.Image
;
71 import org
.eclipse
.swt
.graphics
.Point
;
72 import org
.eclipse
.swt
.graphics
.Rectangle
;
73 import org
.eclipse
.swt
.layout
.FillLayout
;
74 import org
.eclipse
.swt
.layout
.GridData
;
75 import org
.eclipse
.swt
.layout
.GridLayout
;
76 import org
.eclipse
.swt
.widgets
.Button
;
77 import org
.eclipse
.swt
.widgets
.Combo
;
78 import org
.eclipse
.swt
.widgets
.Composite
;
79 import org
.eclipse
.swt
.widgets
.Display
;
80 import org
.eclipse
.swt
.widgets
.Group
;
81 import org
.eclipse
.swt
.widgets
.Label
;
82 import org
.eclipse
.swt
.widgets
.Shell
;
83 import org
.eclipse
.swt
.widgets
.Text
;
84 import org
.eclipse
.tracecompass
.internal
.tmf
.ui
.Activator
;
85 import org
.eclipse
.tracecompass
.internal
.tmf
.ui
.Messages
;
86 import org
.eclipse
.tracecompass
.tmf
.core
.parsers
.custom
.CustomTraceDefinition
;
87 import org
.eclipse
.tracecompass
.tmf
.core
.parsers
.custom
.CustomTraceDefinition
.Tag
;
88 import org
.eclipse
.tracecompass
.tmf
.core
.parsers
.custom
.CustomTxtTraceDefinition
;
89 import org
.eclipse
.tracecompass
.tmf
.core
.parsers
.custom
.CustomTxtTraceDefinition
.Cardinality
;
90 import org
.eclipse
.tracecompass
.tmf
.core
.parsers
.custom
.CustomTxtTraceDefinition
.InputData
;
91 import org
.eclipse
.tracecompass
.tmf
.core
.parsers
.custom
.CustomTxtTraceDefinition
.InputLine
;
92 import org
.eclipse
.tracecompass
.tmf
.core
.project
.model
.TmfTraceType
;
93 import org
.eclipse
.tracecompass
.tmf
.core
.project
.model
.TraceTypeHelper
;
94 import org
.eclipse
.tracecompass
.tmf
.core
.timestamp
.TmfTimestampFormat
;
95 import org
.osgi
.framework
.Bundle
;
98 * Input wizard page for custom text parsers.
100 * @author Patrick Tasse
102 public class CustomTxtParserInputWizardPage
extends WizardPage
{
104 private static final String DEFAULT_REGEX
= "\\s*(.*\\S)"; //$NON-NLS-1$
105 private static final String DEFAULT_TIMESTAMP_FORMAT
= "yyyy-MM-dd HH:mm:ss.SSS"; //$NON-NLS-1$
106 private static final String TIMESTAMP_FORMAT_BUNDLE
= "org.eclipse.tracecompass.doc.user"; //$NON-NLS-1$
107 private static final String TIMESTAMP_FORMAT_PATH
= "reference/api/org/eclipse/tracecompass/tmf/core/timestamp/TmfTimestampFormat.html"; //$NON-NLS-1$
108 private static final String PATTERN_URL
= "http://docs.oracle.com/javase/8/docs/api/java/util/regex/Pattern.html#sum"; //$NON-NLS-1$
109 private static final Image LINE_IMAGE
= Activator
.getDefault().getImageFromPath("/icons/elcl16/line_icon.gif"); //$NON-NLS-1$
110 private static final Image ADD_IMAGE
= Activator
.getDefault().getImageFromPath("/icons/elcl16/add_button.gif"); //$NON-NLS-1$
111 private static final Image ADD_NEXT_IMAGE
= Activator
.getDefault().getImageFromPath("/icons/elcl16/addnext_button.gif"); //$NON-NLS-1$
112 private static final Image ADD_CHILD_IMAGE
= Activator
.getDefault().getImageFromPath("/icons/elcl16/addchild_button.gif"); //$NON-NLS-1$
113 private static final Image DELETE_IMAGE
= Activator
.getDefault().getImageFromPath("/icons/elcl16/delete_button.gif"); //$NON-NLS-1$
114 private static final Image MOVE_UP_IMAGE
= Activator
.getDefault().getImageFromPath("/icons/elcl16/moveup_button.gif"); //$NON-NLS-1$
115 private static final Image MOVE_DOWN_IMAGE
= Activator
.getDefault().getImageFromPath("/icons/elcl16/movedown_button.gif"); //$NON-NLS-1$
116 private static final Image HELP_IMAGE
= Activator
.getDefault().getImageFromPath("/icons/elcl16/help_button.gif"); //$NON-NLS-1$
117 private static final Color COLOR_BLACK
= Display
.getDefault().getSystemColor(SWT
.COLOR_BLACK
);
118 private static final Color COLOR_LIGHT_GREEN
= new Color(Display
.getDefault(), 192, 255, 192);
119 private static final Color COLOR_GREEN
= Display
.getDefault().getSystemColor(SWT
.COLOR_GREEN
);
120 private static final Color COLOR_LIGHT_YELLOW
= new Color(Display
.getDefault(), 255, 255, 192);
121 private static final Color COLOR_YELLOW
= Display
.getDefault().getSystemColor(SWT
.COLOR_YELLOW
);
122 private static final Color COLOR_LIGHT_MAGENTA
= new Color(Display
.getDefault(), 255, 192, 255);
123 private static final Color COLOR_MAGENTA
= Display
.getDefault().getSystemColor(SWT
.COLOR_MAGENTA
);
124 private static final Color COLOR_LIGHT_RED
= new Color(Display
.getDefault(), 255, 192, 192);
125 private static final Color COLOR_TEXT_BACKGROUND
= Display
.getDefault().getSystemColor(SWT
.COLOR_WHITE
);
126 private static final Color COLOR_WIDGET_BACKGROUND
= Display
.getDefault().getSystemColor(SWT
.COLOR_WIDGET_BACKGROUND
);
127 private static final Color COLOR_GRAY
= Display
.getDefault().getSystemColor(SWT
.COLOR_GRAY
);
129 private final ISelection selection
;
130 private CustomTxtTraceDefinition definition
;
131 private String editCategoryName
;
132 private String editDefinitionName
;
133 private String defaultDescription
;
134 private Line selectedLine
;
135 private Composite container
;
136 private Text categoryText
;
137 private Text logtypeText
;
138 private Text timestampOutputFormatText
;
139 private Text timestampPreviewText
;
140 private ScrolledComposite lineScrolledComposite
;
141 private TreeViewer treeViewer
;
142 private Composite lineContainer
;
143 private StyledText inputText
;
144 private Font fixedFont
;
145 private UpdateListener updateListener
;
146 private Browser helpBrowser
;
148 // variables used recursively through line traversal
149 private String timeStampFormat
;
150 private boolean timestampFound
;
156 * The Selection object
158 * The trace definition
160 protected CustomTxtParserInputWizardPage(ISelection selection
,
161 CustomTxtTraceDefinition definition
) {
162 super("CustomParserWizardPage"); //$NON-NLS-1$
163 if (definition
== null) {
164 setTitle(Messages
.CustomTxtParserInputWizardPage_titleNew
);
165 defaultDescription
= Messages
.CustomTxtParserInputWizardPage_descriptionNew
;
167 setTitle(Messages
.CustomTxtParserInputWizardPage_titleEdit
);
168 defaultDescription
= Messages
.CustomTxtParserInputWizardPage_desccriptionEdit
;
170 setDescription(defaultDescription
);
171 this.selection
= selection
;
172 this.definition
= definition
;
173 if (definition
!= null) {
174 this.editCategoryName
= definition
.categoryName
;
175 this.editDefinitionName
= definition
.definitionName
;
180 public void createControl(Composite parent
) {
181 container
= new Composite(parent
, SWT
.NULL
);
182 container
.setLayout(new GridLayout());
184 updateListener
= new UpdateListener();
186 Composite headerComposite
= new Composite(container
, SWT
.FILL
);
187 GridLayout headerLayout
= new GridLayout(5, false);
188 headerLayout
.marginHeight
= 0;
189 headerLayout
.marginWidth
= 0;
190 headerComposite
.setLayout(headerLayout
);
191 headerComposite
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
193 Label categoryLabel
= new Label(headerComposite
, SWT
.NULL
);
194 categoryLabel
.setText(Messages
.CustomTxtParserInputWizardPage_category
);
196 categoryText
= new Text(headerComposite
, SWT
.BORDER
| SWT
.SINGLE
);
197 categoryText
.setLayoutData(new GridData(120, SWT
.DEFAULT
));
199 Label timestampFormatLabel
= new Label(headerComposite
, SWT
.NULL
);
200 timestampFormatLabel
.setText(Messages
.CustomTxtParserInputWizardPage_timestampFormat
);
202 timestampOutputFormatText
= new Text(headerComposite
, SWT
.BORDER
| SWT
.SINGLE
);
203 timestampOutputFormatText
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
204 timestampOutputFormatText
.setText(DEFAULT_TIMESTAMP_FORMAT
);
205 timestampOutputFormatText
.addPaintListener(e
-> {
206 if (!timestampOutputFormatText
.isFocusControl() && timestampOutputFormatText
.getText().trim().isEmpty()) {
207 e
.gc
.setForeground(COLOR_GRAY
);
208 int borderWidth
= timestampOutputFormatText
.getBorderWidth();
209 e
.gc
.drawText(Messages
.CustomTxtParserInputWizardPage_default
, borderWidth
, borderWidth
);
213 Button timeStampFormatHelpButton
= new Button(headerComposite
, SWT
.PUSH
);
214 timeStampFormatHelpButton
.setImage(HELP_IMAGE
);
215 timeStampFormatHelpButton
.setToolTipText(Messages
.CustomTxtParserInputWizardPage_timestampFormatHelp
);
216 timeStampFormatHelpButton
.addSelectionListener(new SelectionAdapter() {
218 public void widgetSelected(SelectionEvent e
) {
219 Bundle plugin
= Platform
.getBundle(TIMESTAMP_FORMAT_BUNDLE
);
220 IPath path
= new Path(TIMESTAMP_FORMAT_PATH
);
221 URL fileURL
= FileLocator
.find(plugin
, path
, null);
223 URL pageURL
= FileLocator
.toFileURL(fileURL
);
224 openHelpShell(pageURL
.toString());
225 } catch (IOException e1
) {
230 Label logtypeLabel
= new Label(headerComposite
, SWT
.NULL
);
231 logtypeLabel
.setText(Messages
.CustomTxtParserInputWizardPage_logType
);
233 logtypeText
= new Text(headerComposite
, SWT
.BORDER
| SWT
.SINGLE
);
234 logtypeText
.setLayoutData(new GridData(120, SWT
.DEFAULT
));
235 logtypeText
.setFocus();
237 Label timestampPreviewLabel
= new Label(headerComposite
, SWT
.NULL
);
238 timestampPreviewLabel
.setText(Messages
.CustomTxtParserInputWizardPage_preview
);
240 timestampPreviewText
= new Text(headerComposite
, SWT
.BORDER
| SWT
.SINGLE
| SWT
.READ_ONLY
);
241 timestampPreviewText
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false, 2, 1));
242 timestampPreviewText
.setText(Messages
.CustomTxtParserInputWizardPage_noMatchingTimestamp
);
244 Composite buttonBar
= new Composite(container
, SWT
.NONE
);
245 GridLayout buttonBarLayout
= new GridLayout(5, false);
246 buttonBarLayout
.marginHeight
= 0;
247 buttonBarLayout
.marginWidth
= 0;
248 buttonBar
.setLayout(buttonBarLayout
);
250 Button removeButton
= new Button(buttonBar
, SWT
.PUSH
);
251 removeButton
.setImage(DELETE_IMAGE
);
252 removeButton
.setToolTipText(Messages
.CustomTxtParserInputWizardPage_removeLine
);
253 removeButton
.addSelectionListener(new SelectionAdapter() {
255 public void widgetSelected(SelectionEvent e
) {
256 if (treeViewer
.getSelection().isEmpty() || selectedLine
== null) {
260 InputLine inputLine
= (InputLine
) ((IStructuredSelection
) treeViewer
.getSelection()).getFirstElement();
261 if (inputLine
.parentInput
== null) {
262 definition
.inputs
.remove(inputLine
);
264 int index
= inputLine
.parentInput
.childrenInputs
.indexOf(inputLine
);
266 inputLine
.parentInput
.childrenInputs
.get(index
- 1).nextInput
= inputLine
.nextInput
;
268 inputLine
.parentInput
.childrenInputs
.remove(inputLine
);
270 treeViewer
.refresh();
275 Button addNextButton
= new Button(buttonBar
, SWT
.PUSH
);
276 addNextButton
.setImage(ADD_NEXT_IMAGE
);
277 addNextButton
.setToolTipText(Messages
.CustomTxtParserInputWizardPage_addNextLine
);
278 addNextButton
.addSelectionListener(new SelectionAdapter() {
280 public void widgetSelected(SelectionEvent e
) {
281 InputLine inputLine
= new InputLine(Cardinality
.ZERO_OR_MORE
, "", null); //$NON-NLS-1$
282 if (((List
<?
>) treeViewer
.getInput()).size() == 0) {
283 definition
.inputs
.add(inputLine
);
284 } else if (treeViewer
.getSelection().isEmpty()) {
287 InputLine previousInputLine
= (InputLine
) ((IStructuredSelection
) treeViewer
.getSelection()).getFirstElement();
288 if (previousInputLine
.parentInput
== null) {
289 for (int i
= 0; i
< definition
.inputs
.size(); i
++) {
290 if (definition
.inputs
.get(i
).equals(previousInputLine
)) {
291 definition
.inputs
.add(i
+ 1, inputLine
);
295 previousInputLine
.addNext(inputLine
);
298 treeViewer
.refresh();
299 treeViewer
.setSelection(new StructuredSelection(inputLine
), true);
302 Button addChildButton
= new Button(buttonBar
, SWT
.PUSH
);
303 addChildButton
.setImage(ADD_CHILD_IMAGE
);
304 addChildButton
.setToolTipText(Messages
.CustomTxtParserInputWizardPage_addChildLine
);
305 addChildButton
.addSelectionListener(new SelectionAdapter() {
307 public void widgetSelected(SelectionEvent e
) {
308 InputLine inputLine
= new InputLine(Cardinality
.ZERO_OR_MORE
, "", null); //$NON-NLS-1$
309 if (((List
<?
>) treeViewer
.getInput()).size() == 0) {
310 definition
.inputs
.add(inputLine
);
311 } else if (treeViewer
.getSelection().isEmpty()) {
314 InputLine parentInputLine
= (InputLine
) ((IStructuredSelection
) treeViewer
.getSelection()).getFirstElement();
315 parentInputLine
.addChild(inputLine
);
317 treeViewer
.refresh();
318 treeViewer
.setSelection(new StructuredSelection(inputLine
), true);
321 Button moveUpButton
= new Button(buttonBar
, SWT
.PUSH
);
322 moveUpButton
.setImage(MOVE_UP_IMAGE
);
323 moveUpButton
.setToolTipText(Messages
.CustomTxtParserInputWizardPage_moveUp
);
324 moveUpButton
.addSelectionListener(new SelectionAdapter() {
326 public void widgetSelected(SelectionEvent e
) {
327 if (treeViewer
.getSelection().isEmpty()) {
330 InputLine inputLine
= (InputLine
) ((IStructuredSelection
) treeViewer
.getSelection()).getFirstElement();
331 if (inputLine
.parentInput
== null) {
332 for (int i
= 1; i
< definition
.inputs
.size(); i
++) {
333 if (definition
.inputs
.get(i
).equals(inputLine
)) {
334 definition
.inputs
.add(i
- 1, definition
.inputs
.remove(i
));
341 treeViewer
.refresh();
346 Button moveDownButton
= new Button(buttonBar
, SWT
.PUSH
);
347 moveDownButton
.setImage(MOVE_DOWN_IMAGE
);
348 moveDownButton
.setToolTipText(Messages
.CustomTxtParserInputWizardPage_moveDown
);
349 moveDownButton
.addSelectionListener(new SelectionAdapter() {
351 public void widgetSelected(SelectionEvent e
) {
352 if (treeViewer
.getSelection().isEmpty()) {
355 InputLine inputLine
= (InputLine
) ((IStructuredSelection
) treeViewer
.getSelection()).getFirstElement();
356 if (inputLine
.parentInput
== null) {
357 for (int i
= 0; i
< definition
.inputs
.size() - 1; i
++) {
358 if (definition
.inputs
.get(i
).equals(inputLine
)) {
359 definition
.inputs
.add(i
+ 1, definition
.inputs
.remove(i
));
364 inputLine
.moveDown();
366 treeViewer
.refresh();
372 SashForm vSash
= new SashForm(container
, SWT
.VERTICAL
);
373 vSash
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
374 vSash
.setBackground(COLOR_GRAY
);
376 SashForm hSash
= new SashForm(vSash
, SWT
.HORIZONTAL
);
377 hSash
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
379 ScrolledComposite treeScrolledComposite
= new ScrolledComposite(hSash
, SWT
.V_SCROLL
| SWT
.H_SCROLL
);
380 GridData gd
= new GridData(SWT
.FILL
, SWT
.FILL
, true, true);
383 treeScrolledComposite
.setLayoutData(gd
);
384 Composite treeContainer
= new Composite(treeScrolledComposite
, SWT
.NONE
);
385 treeContainer
.setLayout(new FillLayout());
386 treeScrolledComposite
.setContent(treeContainer
);
387 treeScrolledComposite
.setExpandHorizontal(true);
388 treeScrolledComposite
.setExpandVertical(true);
390 treeViewer
= new TreeViewer(treeContainer
, SWT
.SINGLE
| SWT
.BORDER
);
391 treeViewer
.setContentProvider(new InputLineTreeNodeContentProvider());
392 treeViewer
.setLabelProvider(new InputLineTreeLabelProvider());
393 treeViewer
.addSelectionChangedListener(new InputLineTreeSelectionChangedListener());
394 treeContainer
.layout();
396 treeScrolledComposite
.setMinSize(treeContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).x
, treeContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).y
);
398 lineScrolledComposite
= new ScrolledComposite(hSash
, SWT
.V_SCROLL
);
399 lineScrolledComposite
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
400 lineContainer
= new Composite(lineScrolledComposite
, SWT
.NONE
);
401 GridLayout linesLayout
= new GridLayout();
402 linesLayout
.marginHeight
= 1;
403 linesLayout
.marginWidth
= 0;
404 lineContainer
.setLayout(linesLayout
);
405 lineScrolledComposite
.setContent(lineContainer
);
406 lineScrolledComposite
.setExpandHorizontal(true);
407 lineScrolledComposite
.setExpandVertical(true);
409 if (definition
== null) {
410 definition
= new CustomTxtTraceDefinition();
411 definition
.inputs
.add(new InputLine(Cardinality
.ZERO_OR_MORE
, DEFAULT_REGEX
,
412 Arrays
.asList(new InputData(Tag
.MESSAGE
, CustomTraceDefinition
.ACTION_SET
))));
414 loadDefinition(definition
);
415 treeViewer
.expandAll();
416 lineContainer
.layout();
418 categoryText
.addModifyListener(updateListener
);
419 logtypeText
.addModifyListener(updateListener
);
420 timestampOutputFormatText
.addModifyListener(updateListener
);
422 lineScrolledComposite
.setMinSize(lineContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).x
, lineContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).y
- 1);
424 hSash
.setWeights(new int[] { 1, 2 });
426 Composite sashBottom
= new Composite(vSash
, SWT
.NONE
);
427 GridLayout sashBottomLayout
= new GridLayout(3, false);
428 sashBottomLayout
.marginHeight
= 0;
429 sashBottomLayout
.marginWidth
= 0;
430 sashBottom
.setLayout(sashBottomLayout
);
432 Label previewLabel
= new Label(sashBottom
, SWT
.NULL
);
433 previewLabel
.setText(Messages
.CustomTxtParserInputWizardPage_previewInput
);
434 previewLabel
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
436 Button highlightAllButton
= new Button(sashBottom
, SWT
.PUSH
);
437 highlightAllButton
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
438 highlightAllButton
.setText(Messages
.CustomTxtParserInputWizardPage_highlightAll
);
439 highlightAllButton
.addSelectionListener(new SelectionAdapter() {
441 public void widgetSelected(SelectionEvent e
) {
442 updatePreviews(true);
446 Button legendButton
= new Button(sashBottom
, SWT
.PUSH
);
447 legendButton
.setImage(HELP_IMAGE
);
448 legendButton
.setToolTipText(Messages
.CustomTxtParserInputWizardPage_previewLegend
);
449 legendButton
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
450 legendButton
.addSelectionListener(new SelectionAdapter() {
452 public void widgetSelected(SelectionEvent e
) {
457 inputText
= new StyledText(sashBottom
, SWT
.MULTI
| SWT
.V_SCROLL
| SWT
.H_SCROLL
);
458 if (fixedFont
== null) {
459 if (System
.getProperty("os.name").contains("Windows")) { //$NON-NLS-1$ //$NON-NLS-2$
460 fixedFont
= new Font(Display
.getCurrent(), new FontData("Courier New", 10, SWT
.NORMAL
)); //$NON-NLS-1$
462 fixedFont
= new Font(Display
.getCurrent(), new FontData("Monospace", 10, SWT
.NORMAL
)); //$NON-NLS-1$
465 inputText
.setFont(fixedFont
);
466 gd
= new GridData(SWT
.FILL
, SWT
.FILL
, true, true, 3, 1);
467 gd
.heightHint
= inputText
.computeSize(SWT
.DEFAULT
, inputText
.getLineHeight() * 4).y
;
469 inputText
.setLayoutData(gd
);
470 inputText
.setText(getSelectionText());
471 inputText
.addModifyListener(updateListener
);
473 vSash
.setWeights(new int[] { hSash
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).y
, sashBottom
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).y
});
475 setControl(container
);
481 private static class InputLineTreeNodeContentProvider
implements ITreeContentProvider
{
484 public Object
[] getElements(Object inputElement
) {
485 return ((List
<?
>) inputElement
).toArray();
489 public Object
[] getChildren(Object parentElement
) {
490 InputLine inputLine
= (InputLine
) parentElement
;
491 if (inputLine
.childrenInputs
== null) {
492 return new InputLine
[0];
494 return inputLine
.childrenInputs
.toArray();
498 public boolean hasChildren(Object element
) {
499 InputLine inputLine
= (InputLine
) element
;
500 return (inputLine
.childrenInputs
!= null && inputLine
.childrenInputs
.size() > 0);
504 public void dispose() {
508 public void inputChanged(Viewer viewer
, Object oldInput
, Object newInput
) {
512 public Object
getParent(Object element
) {
513 InputLine inputLine
= (InputLine
) element
;
514 return inputLine
.parentInput
;
518 private class InputLineTreeLabelProvider
extends ColumnLabelProvider
{
521 public Image
getImage(Object element
) {
526 public String
getText(Object element
) {
527 InputLine inputLine
= (InputLine
) element
;
528 if (inputLine
.parentInput
== null) {
529 return "Root Line " + getName(inputLine
) + " " + inputLine
.cardinality
.toString() + " : " + inputLine
.getRegex(); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
531 return "Line " + getName(inputLine
) + " " + inputLine
.cardinality
.toString() + " : " + inputLine
.getRegex(); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
535 private class InputLineTreeSelectionChangedListener
implements ISelectionChangedListener
{
537 public void selectionChanged(SelectionChangedEvent event
) {
538 if (selectedLine
!= null) {
539 selectedLine
.dispose();
541 if (!(event
.getSelection().isEmpty()) && event
.getSelection() instanceof IStructuredSelection
) {
542 IStructuredSelection sel
= (IStructuredSelection
) event
.getSelection();
543 InputLine inputLine
= (InputLine
) sel
.getFirstElement();
544 selectedLine
= new Line(lineContainer
, getName(inputLine
), inputLine
);
545 lineContainer
.layout();
546 lineScrolledComposite
.setMinSize(lineContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).x
, lineContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).y
- 1);
555 public void dispose() {
556 if (fixedFont
!= null) {
563 private void loadDefinition(CustomTxtTraceDefinition def
) {
564 categoryText
.setText(def
.categoryName
);
565 logtypeText
.setText(def
.definitionName
);
566 if (def
.timeStampOutputFormat
!= null) {
567 timestampOutputFormatText
.setText(def
.timeStampOutputFormat
);
569 timestampOutputFormatText
.setText(""); //$NON-NLS-1$
571 treeViewer
.setInput(def
.inputs
);
572 if (def
.inputs
.size() > 0) {
573 InputLine inputLine
= def
.inputs
.get(0);
574 treeViewer
.setSelection(new StructuredSelection(inputLine
));
578 private String
getName(InputLine inputLine
) {
579 if (inputLine
.parentInput
== null) {
580 return Integer
.toString(definition
.inputs
.indexOf(inputLine
) + 1);
582 return getName(inputLine
.parentInput
) + "." + Integer
.toString(inputLine
.parentInput
.childrenInputs
.indexOf(inputLine
) + 1); //$NON-NLS-1$
586 * Get the global list of inputs.
588 * @return The list of inputs
590 public List
<Entry
<Tag
, String
>> getInputs() {
591 List
<Entry
<Tag
, String
>> inputs
= new ArrayList
<>();
592 for (InputLine inputLine
: definition
.inputs
) {
593 for (Entry
<Tag
, String
> input
: getInputs(inputLine
)) {
594 if (!inputs
.contains(input
)) {
603 * Get the list of inputs for the given input line, recursively.
607 * @return The list of inputs
609 private List
<Entry
<Tag
, String
>> getInputs(InputLine inputLine
) {
610 List
<Entry
<Tag
, String
>> inputs
= new ArrayList
<>();
611 if (inputLine
.columns
!= null) {
612 for (InputData inputData
: inputLine
.columns
) {
613 Entry
<Tag
, String
> input
= new SimpleEntry
<>(inputData
.tag
, inputData
.name
);
614 if (!inputs
.contains(input
)) {
619 if (inputLine
.childrenInputs
!= null) {
620 for (InputLine childInputLine
: inputLine
.childrenInputs
) {
621 for (Entry
<Tag
, String
> input
: getInputs(childInputLine
)) {
622 if (!inputs
.contains(input
)) {
631 private void removeLine() {
632 selectedLine
.dispose();
634 lineContainer
.layout();
635 lineScrolledComposite
.setMinSize(lineContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).x
, lineContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).y
- 1);
639 private String
getSelectionText() {
640 if (this.selection
instanceof IStructuredSelection
) {
641 Object sel
= ((IStructuredSelection
) this.selection
).getFirstElement();
642 if (sel
instanceof IFile
) {
643 IFile file
= (IFile
) sel
;
644 BufferedReader reader
= null;
646 reader
= new BufferedReader(new InputStreamReader(file
.getContents()));
647 StringBuilder sb
= new StringBuilder();
649 while ((line
= reader
.readLine()) != null) {
653 return sb
.toString();
654 } catch (CoreException e
) {
655 return ""; //$NON-NLS-1$
656 } catch (IOException e
) {
657 return ""; //$NON-NLS-1$
659 if (reader
!= null) {
662 } catch (IOException e
) {
668 return ""; //$NON-NLS-1$
671 private void updatePreviews() {
672 updatePreviews(false);
675 private void updatePreviews(boolean updateAll
) {
676 if (inputText
== null) {
677 // early update during construction
680 inputText
.setStyleRanges(new StyleRange
[] {});
682 try (Scanner scanner
= new Scanner(inputText
.getText());) {
683 scanner
.useDelimiter("\n"); //$NON-NLS-1$
686 // skip starting delimiters
687 String skip
= scanner
.findWithinHorizon("\\A\n+", 0); //$NON-NLS-1$
689 rawPos
+= skip
.length();
692 timeStampFormat
= null;
693 if (selectedLine
!= null) {
694 for (InputGroup input
: selectedLine
.inputs
) {
695 input
.previewText
.setText(Messages
.CustomTxtParserInputWizardPage_noMathcingLine
);
699 Map
<Object
, String
> data
= new HashMap
<>();
700 int rootLineMatches
= 0;
701 String firstEntryTimeStamp
= null;
702 String firstEntryTimeStampInputFormat
= null;
704 boolean lineIsNull
= true; // needed because of JDT bug with continue at label
705 event
: while (scanner
.hasNext() || !lineIsNull
) {
706 if (rootLineMatches
> 0 && !updateAll
) {
710 line
= scanner
.next();
713 int length
= line
.length();
714 String log
= line
.replaceAll("\r", ""); //$NON-NLS-1$ //$NON-NLS-2$
715 for (InputLine rootInputLine
: definition
.inputs
) {
718 pattern
= rootInputLine
.getPattern();
719 } catch (PatternSyntaxException e
) {
722 Matcher matcher
= pattern
.matcher(log
);
723 if (matcher
.matches()) {
725 inputText
.setStyleRange(new StyleRange(rawPos
, length
,
726 COLOR_BLACK
, COLOR_YELLOW
, SWT
.ITALIC
));
727 data
= new HashMap
<>();
728 timeStampFormat
= null;
729 updatePreviewLine(rootInputLine
, matcher
, data
, rawPos
, rootLineMatches
);
730 if (rootLineMatches
== 1) {
731 firstEntryTimeStamp
= data
.get(Tag
.TIMESTAMP
);
732 firstEntryTimeStampInputFormat
= timeStampFormat
;
734 HashMap
<InputLine
, Integer
> countMap
= new HashMap
<>();
735 InputLine currentInput
= null;
736 if (rootInputLine
.childrenInputs
!= null && rootInputLine
.childrenInputs
.size() > 0) {
737 currentInput
= rootInputLine
.childrenInputs
.get(0);
738 countMap
.put(currentInput
, 0);
740 rawPos
+= length
+ 1; // +1 for \n
741 while (scanner
.hasNext()) {
742 line
= scanner
.next();
743 length
= line
.length();
744 log
= line
.replaceAll("\r", ""); //$NON-NLS-1$ //$NON-NLS-2$
745 boolean processed
= false;
746 if (currentInput
== null) {
747 for (InputLine input
: definition
.inputs
) {
749 matcher
= input
.getPattern().matcher(log
);
750 } catch (PatternSyntaxException e
) {
753 if (matcher
.matches()) {
758 if (checkNotNull(countMap
.get(currentInput
)) >= currentInput
.getMinCount()) {
759 List
<InputLine
> nextInputs
= currentInput
.getNextInputs(countMap
);
760 if (nextInputs
.size() == 0 || nextInputs
.get(nextInputs
.size() - 1).getMinCount() == 0) {
761 for (InputLine input
: definition
.inputs
) {
763 matcher
= input
.getPattern().matcher(log
);
764 } catch (PatternSyntaxException e
) {
767 if (matcher
.matches()) {
772 for (InputLine input
: nextInputs
) {
774 matcher
= input
.getPattern().matcher(log
);
775 } catch (PatternSyntaxException e
) {
778 if (matcher
.matches()) {
779 inputText
.setStyleRange(new StyleRange(rawPos
, length
,
780 COLOR_BLACK
, COLOR_LIGHT_YELLOW
, SWT
.ITALIC
));
781 currentInput
= input
;
782 updatePreviewLine(currentInput
, matcher
, data
, rawPos
, rootLineMatches
);
783 if (countMap
.get(currentInput
) == null) {
784 countMap
.put(currentInput
, 1);
786 countMap
.put(currentInput
, checkNotNull(countMap
.get(currentInput
)) + 1);
788 Iterator
<InputLine
> iter
= countMap
.keySet().iterator();
789 while (iter
.hasNext()) {
790 InputLine inputLine
= iter
.next();
791 if (inputLine
.level
> currentInput
.level
) {
795 if (currentInput
.childrenInputs
!= null && currentInput
.childrenInputs
.size() > 0) {
796 currentInput
= currentInput
.childrenInputs
.get(0);
797 countMap
.put(currentInput
, 0);
799 if (checkNotNull(countMap
.get(currentInput
)) >= currentInput
.getMaxCount()) {
800 if (currentInput
.getNextInputs(countMap
).size() > 0) {
801 currentInput
= currentInput
.getNextInputs(countMap
).get(0);
802 if (countMap
.get(currentInput
) == null) {
803 countMap
.put(currentInput
, 0);
805 iter
= countMap
.keySet().iterator();
806 while (iter
.hasNext()) {
807 InputLine inputLine
= iter
.next();
808 if (inputLine
.level
> currentInput
.level
) {
822 if (!processed
&& currentInput
!= null) {
825 matcher
= currentInput
.getPattern().matcher(log
);
826 } catch (PatternSyntaxException e
) {
828 if (matcher
!= null && matcher
.matches()) {
829 inputText
.setStyleRange(new StyleRange(rawPos
, length
,
830 COLOR_BLACK
, COLOR_LIGHT_YELLOW
, SWT
.ITALIC
));
831 updatePreviewLine(currentInput
, matcher
, data
, rawPos
, rootLineMatches
);
832 countMap
.put(currentInput
, checkNotNull(countMap
.get(currentInput
)) + 1);
833 if (currentInput
.childrenInputs
!= null && currentInput
.childrenInputs
.size() > 0) {
834 currentInput
= currentInput
.childrenInputs
.get(0);
835 countMap
.put(currentInput
, 0);
837 if (checkNotNull(countMap
.get(currentInput
)) >= currentInput
.getMaxCount()) {
838 if (currentInput
.getNextInputs(countMap
).size() > 0) {
839 currentInput
= currentInput
.getNextInputs(countMap
).get(0);
840 if (countMap
.get(currentInput
) == null) {
841 countMap
.put(currentInput
, 0);
843 Iterator
<InputLine
> iter
= countMap
.keySet().iterator();
844 while (iter
.hasNext()) {
845 InputLine inputLine
= iter
.next();
846 if (inputLine
.level
> currentInput
.level
) {
858 rawPos
+= length
+ 1; // +1 for \n
864 rawPos
+= length
+ 1; // +1 for \n
869 if (rootLineMatches
== 1) {
870 firstEntryTimeStamp
= data
.get(Tag
.TIMESTAMP
);
871 firstEntryTimeStampInputFormat
= timeStampFormat
;
873 if (firstEntryTimeStamp
== null) {
874 timestampPreviewText
.setText(Messages
.CustomTxtParserInputWizardPage_noTimestampGroup
);
875 if (selectedLine
!= null) {
876 for (InputGroup group
: selectedLine
.inputs
) {
877 if (group
.tagCombo
.getText().equals(Tag
.TIMESTAMP
.toString())) {
878 timestampPreviewText
.setText(Messages
.CustomTxtParserInputWizardPage_noMatchingTimestamp
);
885 TmfTimestampFormat timestampFormat
= new TmfTimestampFormat(firstEntryTimeStampInputFormat
);
886 long timestamp
= timestampFormat
.parseValue(firstEntryTimeStamp
);
887 if (timestampOutputFormatText
.getText().trim().isEmpty()) {
888 timestampFormat
= new TmfTimestampFormat();
890 timestampFormat
= new TmfTimestampFormat(timestampOutputFormatText
.getText().trim());
892 timestampPreviewText
.setText(timestampFormat
.format(timestamp
));
893 } catch (ParseException e
) {
894 timestampPreviewText
.setText("*parse exception* [" + firstEntryTimeStamp
+ "] <> [" + firstEntryTimeStampInputFormat
+ "]"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
895 } catch (IllegalArgumentException e
) {
896 timestampPreviewText
.setText("*parse exception* [Illegal Argument: " + e
.getMessage() + "]"); //$NON-NLS-1$ //$NON-NLS-2$
903 private void updatePreviewLine(InputLine line
, Matcher matcher
, Map
<Object
, String
> data
, int rawPos
, int rootLineMatches
) {
904 for (int i
= 0; i
< line
.columns
.size(); i
++) {
905 InputData input
= line
.columns
.get(i
);
906 if (i
< matcher
.groupCount() && matcher
.group(i
+ 1) != null) {
907 if (line
.parentInput
== null) {
908 inputText
.setStyleRange(new StyleRange(rawPos
+ matcher
.start(i
+ 1), matcher
.end(i
+ 1) - matcher
.start(i
+ 1),
909 COLOR_BLACK
, COLOR_GREEN
, SWT
.BOLD
));
911 inputText
.setStyleRange(new StyleRange(rawPos
+ matcher
.start(i
+ 1), matcher
.end(i
+ 1) - matcher
.start(i
+ 1),
912 COLOR_BLACK
, COLOR_LIGHT_GREEN
, SWT
.BOLD
));
914 String value
= matcher
.group(i
+ 1).trim();
915 if (selectedLine
!= null && selectedLine
.inputLine
.equals(line
) && rootLineMatches
== 1 &&
916 selectedLine
.inputs
.get(i
).previewText
.getText().equals(Messages
.CustomTxtParserInputWizardPage_noMatchingLine
)) {
917 selectedLine
.inputs
.get(i
).previewText
.setText(value
);
919 if (value
.length() == 0) {
922 Object key
= (input
.tag
.equals(Tag
.OTHER
) ? input
.name
: input
.tag
);
923 if (input
.action
== CustomTraceDefinition
.ACTION_SET
) {
924 data
.put(key
, value
);
925 if (input
.tag
.equals(Tag
.TIMESTAMP
)) {
926 timeStampFormat
= input
.format
;
928 } else if (input
.action
== CustomTraceDefinition
.ACTION_APPEND
) {
929 String s
= data
.get(key
);
931 data
.put(key
, s
+ value
);
933 data
.put(key
, value
);
935 if (input
.tag
.equals(Tag
.TIMESTAMP
)) {
936 if (timeStampFormat
!= null) {
937 timeStampFormat
+= input
.format
;
939 timeStampFormat
= input
.format
;
942 } else if (input
.action
== CustomTraceDefinition
.ACTION_APPEND_WITH_SEPARATOR
) {
943 String s
= data
.get(key
);
945 data
.put(key
, s
+ " | " + value
); //$NON-NLS-1$
947 data
.put(key
, value
);
949 if (input
.tag
.equals(Tag
.TIMESTAMP
)) {
950 if (timeStampFormat
!= null) {
951 timeStampFormat
+= " | " + input
.format
; //$NON-NLS-1$
953 timeStampFormat
= input
.format
;
958 if (selectedLine
!= null && selectedLine
.inputLine
.equals(line
) && rootLineMatches
== 1) {
959 if (selectedLine
.inputs
.get(i
).previewText
.getText().equals(Messages
.CustomTxtParserInputWizardPage_noMatchingLine
)) {
960 selectedLine
.inputs
.get(i
).previewText
.setText(Messages
.CustomTxtParserInputWizardPage_noMatchingGroup
);
965 // highlight the matching groups that have no corresponponding input
966 for (int i
= line
.columns
.size(); i
< matcher
.groupCount(); i
++) {
967 if (matcher
.group(i
+ 1) != null) {
968 if (line
.parentInput
== null) {
969 inputText
.setStyleRange(new StyleRange(rawPos
+ matcher
.start(i
+ 1), matcher
.end(i
+ 1) - matcher
.start(i
+ 1),
970 COLOR_BLACK
, COLOR_MAGENTA
));
972 inputText
.setStyleRange(new StyleRange(rawPos
+ matcher
.start(i
+ 1), matcher
.end(i
+ 1) - matcher
.start(i
+ 1),
973 COLOR_BLACK
, COLOR_LIGHT_MAGENTA
));
979 private void openHelpShell(String url
) {
980 if (helpBrowser
!= null && !helpBrowser
.isDisposed()) {
981 helpBrowser
.getShell().setActive();
982 if (!helpBrowser
.getUrl().equals(url
)) {
983 helpBrowser
.setUrl(url
);
987 final Shell helpShell
= new Shell(getShell(), SWT
.SHELL_TRIM
);
988 helpShell
.setLayout(new FillLayout());
989 helpBrowser
= new Browser(helpShell
, SWT
.NONE
);
990 helpBrowser
.addTitleListener(new TitleListener() {
992 public void changed(TitleEvent event
) {
993 helpShell
.setText(event
.title
);
996 Rectangle r
= container
.getBounds();
997 Point p
= container
.toDisplay(r
.x
, r
.y
);
998 Rectangle trim
= helpShell
.computeTrim(p
.x
+ (r
.width
- 750) / 2, p
.y
+ (r
.height
- 400) / 2, 750, 400);
999 helpShell
.setBounds(trim
);
1001 helpBrowser
.setUrl(url
);
1004 private void openLegend() {
1005 final String cg
= Messages
.CustomTxtParserInputWizardPage_capturedGroup
;
1006 final String ucg
= Messages
.CustomTxtParserInputWizardPage_unidentifiedCaptureGroup
;
1007 final String ut
= Messages
.CustomTxtParserInputWizardPage_uncapturedText
;
1009 String line1
= Messages
.CustomTxtParserInputWizardPage_nonMatchingLine
;
1010 int line2start
= line1start
+ line1
.length();
1011 String line2
= Messages
.CustomTxtParserInputWizardPage_matchingRootLine
+ ' ' + cg
+ ' ' + ucg
+ ' ' + ut
+ " \n"; //$NON-NLS-1$
1012 int line3start
= line2start
+ line2
.length();
1013 String line3
= Messages
.CustomTxtParserInputWizardPage_matchingOtherLine
+ ' ' + cg
+ ' ' + ucg
+ ' ' + ut
+ " \n"; //$NON-NLS-1$
1014 int line4start
= line3start
+ line3
.length();
1015 String line4
= Messages
.CustomTxtParserInputWizardPage_matchingOtherLine
+ ' ' + cg
+ ' ' + ucg
+ ' ' + ut
+ " \n"; //$NON-NLS-1$
1016 int line5start
= line4start
+ line4
.length();
1017 String line5
= Messages
.CustomTxtParserInputWizardPage_nonMatchingLine
;
1018 int line6start
= line5start
+ line5
.length();
1019 String line6
= Messages
.CustomTxtParserInputWizardPage_matchingRootLine
+ cg
+ ' ' + ucg
+ ' ' + ut
+ " \n"; //$NON-NLS-1$
1021 final Shell legendShell
= new Shell(getShell(), SWT
.DIALOG_TRIM
);
1022 legendShell
.setLayout(new FillLayout());
1023 StyledText legendText
= new StyledText(legendShell
, SWT
.MULTI
);
1024 legendText
.setFont(fixedFont
);
1025 legendText
.setText(line1
+ line2
+ line3
+ line4
+ line5
+ line6
);
1026 legendText
.setStyleRange(new StyleRange(line2start
, line2
.length(), COLOR_BLACK
, COLOR_YELLOW
, SWT
.ITALIC
));
1027 legendText
.setStyleRange(new StyleRange(line3start
, line3
.length(), COLOR_BLACK
, COLOR_LIGHT_YELLOW
, SWT
.ITALIC
));
1028 legendText
.setStyleRange(new StyleRange(line4start
, line4
.length(), COLOR_BLACK
, COLOR_LIGHT_YELLOW
, SWT
.ITALIC
));
1029 legendText
.setStyleRange(new StyleRange(line6start
, line6
.length(), COLOR_BLACK
, COLOR_YELLOW
, SWT
.ITALIC
));
1030 legendText
.setStyleRange(new StyleRange(line2start
+ line2
.indexOf(cg
), cg
.length(), COLOR_BLACK
, COLOR_GREEN
, SWT
.BOLD
));
1031 legendText
.setStyleRange(new StyleRange(line2start
+ line2
.indexOf(ucg
), ucg
.length(), COLOR_BLACK
, COLOR_MAGENTA
));
1032 legendText
.setStyleRange(new StyleRange(line3start
+ line3
.indexOf(cg
), cg
.length(), COLOR_BLACK
, COLOR_LIGHT_GREEN
, SWT
.BOLD
));
1033 legendText
.setStyleRange(new StyleRange(line3start
+ line3
.indexOf(ucg
), ucg
.length(), COLOR_BLACK
, COLOR_LIGHT_MAGENTA
));
1034 legendText
.setStyleRange(new StyleRange(line4start
+ line4
.indexOf(cg
), cg
.length(), COLOR_BLACK
, COLOR_LIGHT_GREEN
, SWT
.BOLD
));
1035 legendText
.setStyleRange(new StyleRange(line4start
+ line4
.indexOf(ucg
), ucg
.length(), COLOR_BLACK
, COLOR_LIGHT_MAGENTA
));
1036 legendText
.setStyleRange(new StyleRange(line6start
+ line6
.indexOf(cg
), cg
.length(), COLOR_BLACK
, COLOR_GREEN
, SWT
.BOLD
));
1037 legendText
.setStyleRange(new StyleRange(line6start
+ line6
.indexOf(ucg
), ucg
.length(), COLOR_BLACK
, COLOR_MAGENTA
));
1038 legendShell
.setText(Messages
.CustomTxtParserInputWizardPage_previewLegend
);
1043 private class UpdateListener
implements ModifyListener
, SelectionListener
{
1046 public void modifyText(ModifyEvent e
) {
1052 public void widgetDefaultSelected(SelectionEvent e
) {
1058 public void widgetSelected(SelectionEvent e
) {
1065 private class Line
{
1066 private static final String INFINITY_STRING
= "\u221E"; //$NON-NLS-1$
1067 private InputLine inputLine
;
1068 private Group group
;
1069 private Composite labelComposite
;
1070 private Text regexText
;
1071 private Composite cardinalityContainer
;
1072 private Combo cardinalityCombo
;
1073 private Label cardinalityMinLabel
;
1074 private Text cardinalityMinText
;
1075 private Label cardinalityMaxLabel
;
1076 private Text cardinalityMaxText
;
1077 private Button infiniteButton
;
1078 private Button eventTypeButton
;
1079 private Text eventTypeText
;
1080 private List
<InputGroup
> inputs
= new ArrayList
<>();
1081 private Button addGroupButton
;
1082 private Label addGroupLabel
;
1084 public Line(Composite parent
, String name
, InputLine inputLine
) {
1085 this.inputLine
= inputLine
;
1087 group
= new Group(parent
, SWT
.NONE
);
1088 group
.setText(name
);
1089 group
.setLayout(new GridLayout(2, false));
1090 group
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
1092 labelComposite
= new Composite(group
, SWT
.FILL
);
1093 GridLayout labelLayout
= new GridLayout(1, false);
1094 labelLayout
.marginWidth
= 0;
1095 labelLayout
.marginHeight
= 0;
1096 labelComposite
.setLayout(labelLayout
);
1097 labelComposite
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
1099 Label label
= new Label(labelComposite
, SWT
.NULL
);
1100 label
.setText(Messages
.CustomTxtParserInputWizardPage_regularExpression
);
1102 Composite regexContainer
= new Composite(group
, SWT
.NONE
);
1103 GridLayout regexLayout
= new GridLayout(2, false);
1104 regexLayout
.marginHeight
= 0;
1105 regexLayout
.marginWidth
= 0;
1106 regexContainer
.setLayout(regexLayout
);
1107 regexContainer
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
1109 regexText
= new Text(regexContainer
, SWT
.BORDER
| SWT
.SINGLE
);
1110 GridData gd
= new GridData(SWT
.FILL
, SWT
.CENTER
, true, false);
1112 regexText
.setLayoutData(gd
);
1113 regexText
.setText(inputLine
.getRegex());
1114 regexText
.addModifyListener(updateListener
);
1116 Button regexHelpButton
= new Button(regexContainer
, SWT
.PUSH
);
1117 regexHelpButton
.setImage(HELP_IMAGE
);
1118 regexHelpButton
.setToolTipText(Messages
.CustomTxtParserInputWizardPage_regularExpressionHelp
);
1119 regexHelpButton
.addSelectionListener(new SelectionAdapter() {
1121 public void widgetSelected(SelectionEvent e
) {
1122 openHelpShell(PATTERN_URL
);
1126 label
= new Label(group
, SWT
.NONE
);
1127 label
.setText(Messages
.CustomTxtParserInputWizardPage_cardinality
);
1128 label
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
1130 cardinalityContainer
= new Composite(group
, SWT
.NONE
);
1131 GridLayout cardinalityLayout
= new GridLayout(6, false);
1132 cardinalityLayout
.marginHeight
= 0;
1133 cardinalityLayout
.marginWidth
= 0;
1134 cardinalityContainer
.setLayout(cardinalityLayout
);
1135 cardinalityContainer
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
1137 cardinalityCombo
= new Combo(cardinalityContainer
, SWT
.DROP_DOWN
| SWT
.READ_ONLY
);
1138 cardinalityCombo
.setItems(new String
[] {
1139 Cardinality
.ZERO_OR_MORE
.toString(),
1140 Cardinality
.ONE_OR_MORE
.toString(),
1141 Cardinality
.ZERO_OR_ONE
.toString(),
1142 Cardinality
.ONE
.toString(), "(?,?)" }); //$NON-NLS-1$
1143 cardinalityCombo
.addSelectionListener(new SelectionListener() {
1145 public void widgetDefaultSelected(SelectionEvent e
) {
1149 public void widgetSelected(SelectionEvent e
) {
1150 switch (cardinalityCombo
.getSelectionIndex()) {
1152 cardinalityMinLabel
.setVisible(true);
1153 cardinalityMinText
.setVisible(true);
1154 cardinalityMaxLabel
.setVisible(true);
1155 cardinalityMaxText
.setVisible(true);
1156 infiniteButton
.setVisible(true);
1159 cardinalityMinLabel
.setVisible(false);
1160 cardinalityMinText
.setVisible(false);
1161 cardinalityMaxLabel
.setVisible(false);
1162 cardinalityMaxText
.setVisible(false);
1163 infiniteButton
.setVisible(false);
1166 cardinalityContainer
.layout();
1172 cardinalityMinLabel
= new Label(cardinalityContainer
, SWT
.NONE
);
1173 cardinalityMinLabel
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
1174 cardinalityMinLabel
.setText(Messages
.CustomTxtParserInputWizardPage_min
);
1175 cardinalityMinLabel
.setVisible(false);
1177 cardinalityMinText
= new Text(cardinalityContainer
, SWT
.BORDER
| SWT
.SINGLE
);
1178 gd
= new GridData(SWT
.CENTER
, SWT
.CENTER
, false, false);
1180 cardinalityMinText
.setLayoutData(gd
);
1181 cardinalityMinText
.setVisible(false);
1183 cardinalityMaxLabel
= new Label(cardinalityContainer
, SWT
.NONE
);
1184 cardinalityMaxLabel
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
1185 cardinalityMaxLabel
.setText(Messages
.CustomTxtParserInputWizardPage_max
);
1186 cardinalityMaxLabel
.setVisible(false);
1188 cardinalityMaxText
= new Text(cardinalityContainer
, SWT
.BORDER
| SWT
.SINGLE
);
1189 gd
= new GridData(SWT
.CENTER
, SWT
.CENTER
, false, false);
1191 cardinalityMaxText
.setLayoutData(gd
);
1192 cardinalityMaxText
.setVisible(false);
1194 infiniteButton
= new Button(cardinalityContainer
, SWT
.PUSH
);
1195 infiniteButton
.setText(INFINITY_STRING
);
1196 infiniteButton
.setVisible(false);
1197 infiniteButton
.addSelectionListener(new SelectionAdapter() {
1199 public void widgetSelected(SelectionEvent e
) {
1200 cardinalityMaxText
.setText(INFINITY_STRING
);
1204 if (inputLine
.cardinality
.equals(Cardinality
.ZERO_OR_MORE
)) {
1205 cardinalityCombo
.select(0);
1206 } else if (inputLine
.cardinality
.equals(Cardinality
.ONE_OR_MORE
)) {
1207 cardinalityCombo
.select(1);
1208 } else if (inputLine
.cardinality
.equals(Cardinality
.ZERO_OR_ONE
)) {
1209 cardinalityCombo
.select(2);
1210 } else if (inputLine
.cardinality
.equals(Cardinality
.ONE
)) {
1211 cardinalityCombo
.select(3);
1213 cardinalityCombo
.select(4);
1214 cardinalityMinLabel
.setVisible(true);
1215 cardinalityMinText
.setVisible(true);
1216 if (inputLine
.getMinCount() >= 0) {
1217 cardinalityMinText
.setText(Integer
.toString(inputLine
.getMinCount()));
1219 cardinalityMaxLabel
.setVisible(true);
1220 cardinalityMaxText
.setVisible(true);
1221 if (inputLine
.getMaxCount() == Cardinality
.INF
) {
1222 cardinalityMaxText
.setText(INFINITY_STRING
);
1223 } else if (inputLine
.getMaxCount() >= 0) {
1224 cardinalityMaxText
.setText(Integer
.toString(inputLine
.getMaxCount()));
1226 infiniteButton
.setVisible(true);
1229 VerifyListener digitsListener
= new VerifyListener() {
1231 public void verifyText(VerifyEvent e
) {
1232 if (e
.text
.equals(INFINITY_STRING
)) {
1233 e
.doit
= e
.widget
== cardinalityMaxText
&& e
.start
== 0 && e
.end
== ((Text
) e
.widget
).getText().length();
1235 if (((Text
) e
.widget
).getText().equals(INFINITY_STRING
)) {
1236 e
.doit
= e
.start
== 0 && e
.end
== ((Text
) e
.widget
).getText().length();
1238 for (int i
= 0; i
< e
.text
.length(); i
++) {
1239 if (!Character
.isDigit(e
.text
.charAt(i
))) {
1248 cardinalityMinText
.addModifyListener(updateListener
);
1249 cardinalityMaxText
.addModifyListener(updateListener
);
1250 cardinalityMinText
.addVerifyListener(digitsListener
);
1251 cardinalityMaxText
.addVerifyListener(digitsListener
);
1253 eventTypeButton
= new Button(group
, SWT
.CHECK
);
1254 eventTypeButton
.setText(Messages
.CustomTxtParserInputWizardPage_eventType
);
1255 eventTypeButton
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
1256 eventTypeButton
.addSelectionListener(new SelectionAdapter() {
1258 public void widgetSelected(SelectionEvent e
) {
1259 if (eventTypeButton
.getSelection()) {
1260 eventTypeText
.setEnabled(true);
1262 eventTypeText
.setEnabled(false);
1266 eventTypeButton
.addSelectionListener(updateListener
);
1268 eventTypeText
= new Text(group
, SWT
.BORDER
| SWT
.SINGLE
);
1269 gd
= new GridData(SWT
.FILL
, SWT
.CENTER
, true, false);
1271 eventTypeText
.setLayoutData(gd
);
1272 if (inputLine
.eventType
!= null) {
1273 eventTypeText
.setText(inputLine
.eventType
);
1274 eventTypeButton
.setSelection(true);
1276 eventTypeText
.setEnabled(false);
1277 eventTypeButton
.setSelection(false);
1279 eventTypeText
.addModifyListener(updateListener
);
1282 if (inputLine
.columns
!= null) {
1283 for (InputData inputData
: inputLine
.columns
) {
1284 InputGroup inputGroup
= new InputGroup(group
, this, inputs
.size() + 1);
1285 if (inputData
.tag
.equals(Tag
.TIMESTAMP
)) {
1286 inputGroup
.tagCombo
.select(0);
1287 inputGroup
.tagText
.setText(inputData
.format
);
1288 inputGroup
.tagLabel
.setText(Messages
.CustomTxtParserInputWizardPage_format
);
1289 inputGroup
.tagLabel
.setVisible(true);
1290 inputGroup
.tagText
.setVisible(true);
1291 inputGroup
.tagText
.addModifyListener(updateListener
);
1292 } else if (inputData
.tag
.equals(Tag
.EVENT_TYPE
)) {
1293 inputGroup
.tagCombo
.select(1);
1294 } else if (inputData
.tag
.equals(Tag
.MESSAGE
)) {
1295 inputGroup
.tagCombo
.select(2);
1297 inputGroup
.tagCombo
.select(3);
1298 inputGroup
.tagText
.setText(inputData
.name
);
1299 inputGroup
.tagLabel
.setText(Messages
.CustomTxtParserInputWizardPage_name
);
1300 inputGroup
.tagLabel
.setVisible(true);
1301 inputGroup
.tagText
.setVisible(true);
1302 inputGroup
.tagText
.addModifyListener(updateListener
);
1304 inputGroup
.actionCombo
.select(inputData
.action
);
1305 inputs
.add(inputGroup
);
1309 createAddGroupButton();
1312 private void createAddGroupButton() {
1313 addGroupButton
= new Button(group
, SWT
.PUSH
);
1314 addGroupButton
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
1315 addGroupButton
.setImage(ADD_IMAGE
);
1316 addGroupButton
.setToolTipText(Messages
.CustomTxtParserInputWizardPage_addGroup
);
1317 addGroupButton
.addSelectionListener(new SelectionAdapter() {
1319 public void widgetSelected(SelectionEvent e
) {
1320 removeAddGroupButton();
1321 inputs
.add(new InputGroup(group
, Line
.this, inputs
.size() + 1));
1322 createAddGroupButton();
1323 lineContainer
.layout();
1324 lineScrolledComposite
.setMinSize(lineContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).x
, lineContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).y
- 1);
1325 group
.getParent().layout();
1331 addGroupLabel
= new Label(group
, SWT
.NULL
);
1332 addGroupLabel
.setText(Messages
.CustomTxtParserInputWizardPage_newGroup
);
1335 private void removeAddGroupButton() {
1336 addGroupButton
.dispose();
1337 addGroupLabel
.dispose();
1340 private void removeInput(int inputNumber
) {
1341 int nb
= inputNumber
;
1342 if (--nb
< inputs
.size()) {
1343 inputs
.remove(nb
).dispose();
1344 for (int i
= nb
; i
< inputs
.size(); i
++) {
1345 inputs
.get(i
).setInputNumber(i
+ 1);
1347 lineContainer
.layout();
1348 lineScrolledComposite
.setMinSize(lineContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).x
, lineContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).y
- 1);
1349 group
.getParent().layout();
1353 private void dispose() {
1357 private void extractInputs() {
1358 inputLine
.setRegex(selectedLine
.regexText
.getText());
1359 inputLine
.eventType
= selectedLine
.eventTypeButton
.getSelection() ? selectedLine
.eventTypeText
.getText().trim() : null;
1360 switch (cardinalityCombo
.getSelectionIndex()) {
1362 inputLine
.cardinality
= Cardinality
.ZERO_OR_MORE
;
1365 inputLine
.cardinality
= Cardinality
.ONE_OR_MORE
;
1368 inputLine
.cardinality
= Cardinality
.ZERO_OR_ONE
;
1371 inputLine
.cardinality
= Cardinality
.ONE
;
1377 min
= Integer
.parseInt(cardinalityMinText
.getText());
1378 } catch (NumberFormatException e
) {
1382 if (cardinalityMaxText
.getText().equals(INFINITY_STRING
)) {
1383 max
= Cardinality
.INF
;
1385 max
= Integer
.parseInt(cardinalityMaxText
.getText());
1387 } catch (NumberFormatException e
) {
1390 inputLine
.cardinality
= new Cardinality(min
, max
);
1393 inputLine
.cardinality
= Cardinality
.ZERO_OR_MORE
;
1396 inputLine
.columns
= new ArrayList
<>(inputs
.size());
1397 for (int i
= 0; i
< inputs
.size(); i
++) {
1398 InputGroup grp
= inputs
.get(i
);
1399 InputData inputData
= new InputData();
1400 inputData
.tag
= Tag
.fromLabel(grp
.tagCombo
.getText());
1401 if (inputData
.tag
.equals(Tag
.OTHER
)) {
1402 inputData
.name
= grp
.tagText
.getText().trim();
1404 inputData
.name
= inputData
.tag
.toString();
1405 if (inputData
.tag
.equals(Tag
.TIMESTAMP
)) {
1406 inputData
.format
= grp
.tagText
.getText().trim();
1409 inputData
.action
= grp
.actionCombo
.getSelectionIndex();
1410 inputLine
.columns
.add(inputData
);
1415 private class InputGroup
{
1417 private int inputNumber
;
1419 // children of parent (must be disposed)
1420 private Composite labelComposite
;
1421 private Composite tagComposite
;
1422 private Label previewLabel
;
1423 private Text previewText
;
1425 // children of labelComposite
1426 private Label inputLabel
;
1428 // children of tagComposite
1429 private Combo tagCombo
;
1430 private Label tagLabel
;
1431 private Text tagText
;
1432 private Combo actionCombo
;
1434 public InputGroup(Composite parent
, Line line
, int inputNumber
) {
1436 this.inputNumber
= inputNumber
;
1438 labelComposite
= new Composite(parent
, SWT
.FILL
);
1439 GridLayout labelLayout
= new GridLayout(2, false);
1440 labelLayout
.marginWidth
= 0;
1441 labelLayout
.marginHeight
= 0;
1442 labelComposite
.setLayout(labelLayout
);
1443 labelComposite
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
1445 Button deleteButton
= new Button(labelComposite
, SWT
.PUSH
);
1446 deleteButton
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
1447 deleteButton
.setImage(DELETE_IMAGE
);
1448 deleteButton
.setToolTipText(Messages
.CustomTxtParserInputWizardPage_removeGroup
);
1449 deleteButton
.addSelectionListener(new SelectionAdapter() {
1451 public void widgetSelected(SelectionEvent e
) {
1452 InputGroup
.this.line
.removeInput(InputGroup
.this.inputNumber
);
1458 inputLabel
= new Label(labelComposite
, SWT
.NULL
);
1459 inputLabel
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
1460 inputLabel
.setText(NLS
.bind(Messages
.CustomTxtParserInputWizardPage_group
, inputNumber
));
1462 tagComposite
= new Composite(parent
, SWT
.FILL
);
1463 GridLayout tagLayout
= new GridLayout(4, false);
1464 tagLayout
.marginWidth
= 0;
1465 tagLayout
.marginHeight
= 0;
1466 tagComposite
.setLayout(tagLayout
);
1467 tagComposite
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
1469 tagCombo
= new Combo(tagComposite
, SWT
.DROP_DOWN
| SWT
.READ_ONLY
);
1470 tagCombo
.setItems(new String
[] {
1471 Tag
.TIMESTAMP
.toString(),
1472 Tag
.EVENT_TYPE
.toString(),
1473 Tag
.MESSAGE
.toString(),
1474 Tag
.OTHER
.toString()});
1476 tagCombo
.addSelectionListener(new SelectionListener() {
1478 public void widgetDefaultSelected(SelectionEvent e
) {
1482 public void widgetSelected(SelectionEvent e
) {
1483 tagText
.removeModifyListener(updateListener
);
1484 switch (tagCombo
.getSelectionIndex()) {
1485 case 0: // Time Stamp
1486 tagLabel
.setText(Messages
.CustomTxtParserInputWizardPage_format
);
1487 tagLabel
.setVisible(true);
1488 tagText
.setVisible(true);
1489 tagText
.addModifyListener(updateListener
);
1491 case 1: // Event type
1492 tagLabel
.setVisible(false);
1493 tagText
.setVisible(false);
1496 tagLabel
.setVisible(false);
1497 tagText
.setVisible(false);
1500 tagLabel
.setText(Messages
.CustomTxtParserInputWizardPage_name
);
1501 tagLabel
.setVisible(true);
1502 tagText
.setVisible(true);
1503 tagText
.addModifyListener(updateListener
);
1508 tagComposite
.layout();
1514 tagLabel
= new Label(tagComposite
, SWT
.NULL
);
1515 tagLabel
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
1516 tagLabel
.setVisible(false);
1518 tagText
= new Text(tagComposite
, SWT
.BORDER
| SWT
.SINGLE
);
1519 GridData gd
= new GridData(SWT
.FILL
, SWT
.CENTER
, true, false);
1521 tagText
.setLayoutData(gd
);
1522 tagText
.setVisible(false);
1524 actionCombo
= new Combo(tagComposite
, SWT
.DROP_DOWN
| SWT
.READ_ONLY
);
1525 actionCombo
.setItems(new String
[] { Messages
.CustomTxtParserInputWizardPage_set
, Messages
.CustomTxtParserInputWizardPage_append
, Messages
.CustomTxtParserInputWizardPage_appendWith
});
1526 actionCombo
.select(0);
1527 actionCombo
.addSelectionListener(updateListener
);
1529 previewLabel
= new Label(parent
, SWT
.NULL
);
1530 previewLabel
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
1531 previewLabel
.setText(Messages
.CustomTxtParserInputWizardPage_preview
);
1533 previewText
= new Text(parent
, SWT
.BORDER
| SWT
.SINGLE
| SWT
.READ_ONLY
);
1534 gd
= new GridData(SWT
.FILL
, SWT
.CENTER
, true, false);
1536 previewText
.setLayoutData(gd
);
1537 previewText
.setText(Messages
.CustomTxtParserInputWizardPage_noMatch
);
1538 previewText
.setBackground(COLOR_WIDGET_BACKGROUND
);
1541 private void dispose() {
1542 labelComposite
.dispose();
1543 tagComposite
.dispose();
1544 previewLabel
.dispose();
1545 previewText
.dispose();
1548 private void setInputNumber(int inputNumber
) {
1549 this.inputNumber
= inputNumber
;
1550 inputLabel
.setText(NLS
.bind(Messages
.CustomTxtParserInputWizardPage_group
, inputNumber
));
1551 labelComposite
.layout();
1555 private void validate() {
1557 definition
.categoryName
= categoryText
.getText().trim();
1558 definition
.definitionName
= logtypeText
.getText().trim();
1559 definition
.timeStampOutputFormat
= timestampOutputFormatText
.getText().trim();
1561 if (selectedLine
!= null) {
1562 selectedLine
.extractInputs();
1563 treeViewer
.refresh();
1566 StringBuffer errors
= new StringBuffer();
1568 if (definition
.categoryName
.length() == 0) {
1569 errors
.append("Enter a category for the new trace type. "); //$NON-NLS-1$
1570 categoryText
.setBackground(COLOR_LIGHT_RED
);
1571 } else if (definition
.definitionName
.length() == 0) {
1572 errors
.append("Enter a name for the new trace type. "); //$NON-NLS-1$
1573 logtypeText
.setBackground(COLOR_LIGHT_RED
);
1575 categoryText
.setBackground(COLOR_TEXT_BACKGROUND
);
1576 logtypeText
.setBackground(COLOR_TEXT_BACKGROUND
);
1577 if (definition
.categoryName
.indexOf(':') != -1) {
1578 errors
.append("Invalid character ':' in category. "); //$NON-NLS-1$
1579 categoryText
.setBackground(COLOR_LIGHT_RED
);
1581 if (definition
.definitionName
.indexOf(':') != -1) {
1582 errors
.append("Invalid character ':' in trace type. "); //$NON-NLS-1$
1583 logtypeText
.setBackground(COLOR_LIGHT_RED
);
1585 for (TraceTypeHelper helper
: TmfTraceType
.getTraceTypeHelpers()) {
1586 if (definition
.categoryName
.equals(helper
.getCategoryName()) &&
1587 definition
.definitionName
.equals(helper
.getName()) &&
1588 (editDefinitionName
== null || !editDefinitionName
.equals(definition
.definitionName
)) &&
1589 (editCategoryName
== null || !editCategoryName
.equals(definition
.categoryName
))) {
1590 errors
.append("The trace type name already exists. "); //$NON-NLS-1$
1591 logtypeText
.setBackground(COLOR_LIGHT_RED
);
1597 timestampFound
= false;
1598 for (int i
= 0; i
< definition
.inputs
.size(); i
++) {
1600 InputLine inputLine
= definition
.inputs
.get(i
);
1601 String name
= Integer
.toString(i
+ 1);
1602 errors
.append(validateLine(inputLine
, name
));
1604 if (timestampFound
&& !definition
.timeStampOutputFormat
.isEmpty()) {
1606 new TmfTimestampFormat(definition
.timeStampOutputFormat
);
1607 timestampOutputFormatText
.setBackground(COLOR_TEXT_BACKGROUND
);
1608 } catch (IllegalArgumentException e
) {
1609 errors
.append("Enter a valid output format for the Time Stamp field [" + e
.getMessage() + "]."); //$NON-NLS-1$ //$NON-NLS-2$
1610 timestampOutputFormatText
.setBackground(COLOR_LIGHT_RED
);
1613 timestampOutputFormatText
.setBackground(COLOR_TEXT_BACKGROUND
);
1616 if (errors
.length() == 0) {
1617 setDescription(defaultDescription
);
1618 setPageComplete(true);
1620 setDescription(errors
.toString());
1621 setPageComplete(false);
1626 * Validate an input line.
1629 * The line to clean up
1631 * The name of the line
1632 * @return The cleaned up line
1634 public StringBuffer
validateLine(InputLine inputLine
, String name
) {
1635 StringBuffer errors
= new StringBuffer();
1637 if (selectedLine
!= null && selectedLine
.inputLine
.equals(inputLine
)) {
1638 line
= selectedLine
;
1641 Pattern
.compile(inputLine
.getRegex());
1643 line
.regexText
.setBackground(COLOR_TEXT_BACKGROUND
);
1645 } catch (PatternSyntaxException e
) {
1646 errors
.append("Enter a valid regular expression (Line " + name
+ "). "); //$NON-NLS-1$ //$NON-NLS-2$
1648 line
.regexText
.setBackground(COLOR_LIGHT_RED
);
1651 if (inputLine
.getMinCount() == -1) {
1652 errors
.append("Enter a minimum value for cardinality (Line " + name
+ "). "); //$NON-NLS-1$ //$NON-NLS-2$
1654 line
.cardinalityMinText
.setBackground(COLOR_LIGHT_RED
);
1658 line
.cardinalityMinText
.setBackground(COLOR_TEXT_BACKGROUND
);
1661 if (inputLine
.getMaxCount() == -1) {
1662 errors
.append("Enter a maximum value for cardinality (Line " + name
+ "). "); //$NON-NLS-1$ //$NON-NLS-2$
1664 line
.cardinalityMaxText
.setBackground(COLOR_LIGHT_RED
);
1666 } else if (inputLine
.getMinCount() > inputLine
.getMaxCount()) {
1667 errors
.append("Enter correct (min <= max) values for cardinality (Line " + name
+ "). "); //$NON-NLS-1$ //$NON-NLS-2$
1669 line
.cardinalityMinText
.setBackground(COLOR_LIGHT_RED
);
1672 line
.cardinalityMaxText
.setBackground(COLOR_LIGHT_RED
);
1676 line
.cardinalityMaxText
.setBackground(COLOR_TEXT_BACKGROUND
);
1679 if (inputLine
.eventType
!= null && inputLine
.eventType
.trim().isEmpty()) {
1680 errors
.append("Enter the event type (Line " + name
+ "). "); //$NON-NLS-1$ //$NON-NLS-2$
1682 line
.eventTypeText
.setBackground(COLOR_LIGHT_RED
);
1686 line
.eventTypeText
.setBackground(COLOR_TEXT_BACKGROUND
);
1689 for (int i
= 0; inputLine
.columns
!= null && i
< inputLine
.columns
.size(); i
++) {
1690 InputData inputData
= inputLine
.columns
.get(i
);
1691 InputGroup group
= null;
1693 group
= line
.inputs
.get(i
);
1695 if (inputData
.tag
.equals(Tag
.TIMESTAMP
)) {
1696 timestampFound
= true;
1697 if (inputData
.format
.length() == 0) {
1698 errors
.append("Enter the input format for the Time Stamp (Line " + name
+ " Group " + (i
+ 1) + "). "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
1699 if (group
!= null) {
1700 group
.tagText
.setBackground(COLOR_LIGHT_RED
);
1704 new TmfTimestampFormat(inputData
.format
);
1705 if (group
!= null) {
1706 group
.tagText
.setBackground(COLOR_TEXT_BACKGROUND
);
1708 } catch (IllegalArgumentException e
) {
1709 errors
.append("Enter a valid input format for the Time Stamp (Line " + name
+ " Group " + (i
+ 1) + ") [" + e
.getMessage() + "]. "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
1710 if (group
!= null) {
1711 group
.tagText
.setBackground(COLOR_LIGHT_RED
);
1715 } else if (inputData
.tag
.equals(Tag
.OTHER
)) {
1716 if (inputData
.name
.isEmpty()) {
1717 errors
.append("Enter a name for the data group (Line " + name
+ " Group " + (i
+ 1) + "). "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
1718 if (group
!= null) {
1719 group
.tagText
.setBackground(COLOR_LIGHT_RED
);
1721 } else if (Tag
.fromLabel(inputData
.name
) != null) {
1722 errors
.append("Cannot use reserved name for the data group (Line " + name
+ " Group " + (i
+ 1) + "). "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
1723 if (group
!= null) {
1724 group
.tagText
.setBackground(COLOR_LIGHT_RED
);
1727 if (group
!= null) {
1728 group
.tagText
.setBackground(COLOR_TEXT_BACKGROUND
);
1732 if (group
!= null) {
1733 group
.tagText
.setBackground(COLOR_TEXT_BACKGROUND
);
1737 for (int i
= 0; inputLine
.childrenInputs
!= null && i
< inputLine
.childrenInputs
.size(); i
++) {
1738 errors
.append(validateLine(inputLine
.childrenInputs
.get(i
), name
+ "." + (i
+ 1))); //$NON-NLS-1$
1744 * Get the trace definition.
1746 * @return The trace definition
1748 public CustomTxtTraceDefinition
getDefinition() {
1753 * Get the raw text of the input.
1755 * @return The raw input text
1757 public char[] getInputText() {
1758 return inputText
.getText().toCharArray();