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 inputLine
.parentInput
.childrenInputs
.remove(inputLine
);
266 treeViewer
.refresh();
271 Button addNextButton
= new Button(buttonBar
, SWT
.PUSH
);
272 addNextButton
.setImage(ADD_NEXT_IMAGE
);
273 addNextButton
.setToolTipText(Messages
.CustomTxtParserInputWizardPage_addNextLine
);
274 addNextButton
.addSelectionListener(new SelectionAdapter() {
276 public void widgetSelected(SelectionEvent e
) {
277 InputLine inputLine
= new InputLine(Cardinality
.ZERO_OR_MORE
, "", null); //$NON-NLS-1$
278 if (((List
<?
>) treeViewer
.getInput()).size() == 0) {
279 definition
.inputs
.add(inputLine
);
280 } else if (treeViewer
.getSelection().isEmpty()) {
283 InputLine previousInputLine
= (InputLine
) ((IStructuredSelection
) treeViewer
.getSelection()).getFirstElement();
284 if (previousInputLine
.parentInput
== null) {
285 for (int i
= 0; i
< definition
.inputs
.size(); i
++) {
286 if (definition
.inputs
.get(i
).equals(previousInputLine
)) {
287 definition
.inputs
.add(i
+ 1, inputLine
);
291 previousInputLine
.addNext(inputLine
);
294 treeViewer
.refresh();
295 treeViewer
.setSelection(new StructuredSelection(inputLine
), true);
298 Button addChildButton
= new Button(buttonBar
, SWT
.PUSH
);
299 addChildButton
.setImage(ADD_CHILD_IMAGE
);
300 addChildButton
.setToolTipText(Messages
.CustomTxtParserInputWizardPage_addChildLine
);
301 addChildButton
.addSelectionListener(new SelectionAdapter() {
303 public void widgetSelected(SelectionEvent e
) {
304 InputLine inputLine
= new InputLine(Cardinality
.ZERO_OR_MORE
, "", null); //$NON-NLS-1$
305 if (((List
<?
>) treeViewer
.getInput()).size() == 0) {
306 definition
.inputs
.add(inputLine
);
307 } else if (treeViewer
.getSelection().isEmpty()) {
310 InputLine parentInputLine
= (InputLine
) ((IStructuredSelection
) treeViewer
.getSelection()).getFirstElement();
311 parentInputLine
.addChild(inputLine
);
313 treeViewer
.refresh();
314 treeViewer
.setSelection(new StructuredSelection(inputLine
), true);
317 Button moveUpButton
= new Button(buttonBar
, SWT
.PUSH
);
318 moveUpButton
.setImage(MOVE_UP_IMAGE
);
319 moveUpButton
.setToolTipText(Messages
.CustomTxtParserInputWizardPage_moveUp
);
320 moveUpButton
.addSelectionListener(new SelectionAdapter() {
322 public void widgetSelected(SelectionEvent e
) {
323 if (treeViewer
.getSelection().isEmpty()) {
326 InputLine inputLine
= (InputLine
) ((IStructuredSelection
) treeViewer
.getSelection()).getFirstElement();
327 if (inputLine
.parentInput
== null) {
328 for (int i
= 1; i
< definition
.inputs
.size(); i
++) {
329 if (definition
.inputs
.get(i
).equals(inputLine
)) {
330 definition
.inputs
.add(i
- 1, definition
.inputs
.remove(i
));
337 treeViewer
.refresh();
342 Button moveDownButton
= new Button(buttonBar
, SWT
.PUSH
);
343 moveDownButton
.setImage(MOVE_DOWN_IMAGE
);
344 moveDownButton
.setToolTipText(Messages
.CustomTxtParserInputWizardPage_moveDown
);
345 moveDownButton
.addSelectionListener(new SelectionAdapter() {
347 public void widgetSelected(SelectionEvent e
) {
348 if (treeViewer
.getSelection().isEmpty()) {
351 InputLine inputLine
= (InputLine
) ((IStructuredSelection
) treeViewer
.getSelection()).getFirstElement();
352 if (inputLine
.parentInput
== null) {
353 for (int i
= 0; i
< definition
.inputs
.size() - 1; i
++) {
354 if (definition
.inputs
.get(i
).equals(inputLine
)) {
355 definition
.inputs
.add(i
+ 1, definition
.inputs
.remove(i
));
360 inputLine
.moveDown();
362 treeViewer
.refresh();
368 SashForm vSash
= new SashForm(container
, SWT
.VERTICAL
);
369 vSash
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
370 vSash
.setBackground(COLOR_GRAY
);
372 SashForm hSash
= new SashForm(vSash
, SWT
.HORIZONTAL
);
373 hSash
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
375 ScrolledComposite treeScrolledComposite
= new ScrolledComposite(hSash
, SWT
.V_SCROLL
| SWT
.H_SCROLL
);
376 GridData gd
= new GridData(SWT
.FILL
, SWT
.FILL
, true, true);
379 treeScrolledComposite
.setLayoutData(gd
);
380 Composite treeContainer
= new Composite(treeScrolledComposite
, SWT
.NONE
);
381 treeContainer
.setLayout(new FillLayout());
382 treeScrolledComposite
.setContent(treeContainer
);
383 treeScrolledComposite
.setExpandHorizontal(true);
384 treeScrolledComposite
.setExpandVertical(true);
386 treeViewer
= new TreeViewer(treeContainer
, SWT
.SINGLE
| SWT
.BORDER
);
387 treeViewer
.setContentProvider(new InputLineTreeNodeContentProvider());
388 treeViewer
.setLabelProvider(new InputLineTreeLabelProvider());
389 treeViewer
.addSelectionChangedListener(new InputLineTreeSelectionChangedListener());
390 treeContainer
.layout();
392 treeScrolledComposite
.setMinSize(treeContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).x
, treeContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).y
);
394 lineScrolledComposite
= new ScrolledComposite(hSash
, SWT
.V_SCROLL
);
395 lineScrolledComposite
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
396 lineContainer
= new Composite(lineScrolledComposite
, SWT
.NONE
);
397 GridLayout linesLayout
= new GridLayout();
398 linesLayout
.marginHeight
= 1;
399 linesLayout
.marginWidth
= 0;
400 lineContainer
.setLayout(linesLayout
);
401 lineScrolledComposite
.setContent(lineContainer
);
402 lineScrolledComposite
.setExpandHorizontal(true);
403 lineScrolledComposite
.setExpandVertical(true);
405 if (definition
== null) {
406 definition
= new CustomTxtTraceDefinition();
407 definition
.inputs
.add(new InputLine(Cardinality
.ZERO_OR_MORE
, DEFAULT_REGEX
,
408 Arrays
.asList(new InputData(Tag
.MESSAGE
, CustomTraceDefinition
.ACTION_SET
))));
410 loadDefinition(definition
);
411 treeViewer
.expandAll();
412 lineContainer
.layout();
414 categoryText
.addModifyListener(updateListener
);
415 logtypeText
.addModifyListener(updateListener
);
416 timestampOutputFormatText
.addModifyListener(updateListener
);
418 lineScrolledComposite
.setMinSize(lineContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).x
, lineContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).y
- 1);
420 hSash
.setWeights(new int[] { 1, 2 });
422 Composite sashBottom
= new Composite(vSash
, SWT
.NONE
);
423 GridLayout sashBottomLayout
= new GridLayout(3, false);
424 sashBottomLayout
.marginHeight
= 0;
425 sashBottomLayout
.marginWidth
= 0;
426 sashBottom
.setLayout(sashBottomLayout
);
428 Label previewLabel
= new Label(sashBottom
, SWT
.NULL
);
429 previewLabel
.setText(Messages
.CustomTxtParserInputWizardPage_previewInput
);
430 previewLabel
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
432 Button highlightAllButton
= new Button(sashBottom
, SWT
.PUSH
);
433 highlightAllButton
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
434 highlightAllButton
.setText(Messages
.CustomTxtParserInputWizardPage_highlightAll
);
435 highlightAllButton
.addSelectionListener(new SelectionAdapter() {
437 public void widgetSelected(SelectionEvent e
) {
438 updatePreviews(true);
442 Button legendButton
= new Button(sashBottom
, SWT
.PUSH
);
443 legendButton
.setImage(HELP_IMAGE
);
444 legendButton
.setToolTipText(Messages
.CustomTxtParserInputWizardPage_previewLegend
);
445 legendButton
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
446 legendButton
.addSelectionListener(new SelectionAdapter() {
448 public void widgetSelected(SelectionEvent e
) {
453 inputText
= new StyledText(sashBottom
, SWT
.MULTI
| SWT
.V_SCROLL
| SWT
.H_SCROLL
);
454 if (fixedFont
== null) {
455 if (System
.getProperty("os.name").contains("Windows")) { //$NON-NLS-1$ //$NON-NLS-2$
456 fixedFont
= new Font(Display
.getCurrent(), new FontData("Courier New", 10, SWT
.NORMAL
)); //$NON-NLS-1$
458 fixedFont
= new Font(Display
.getCurrent(), new FontData("Monospace", 10, SWT
.NORMAL
)); //$NON-NLS-1$
461 inputText
.setFont(fixedFont
);
462 gd
= new GridData(SWT
.FILL
, SWT
.FILL
, true, true, 3, 1);
463 gd
.heightHint
= inputText
.computeSize(SWT
.DEFAULT
, inputText
.getLineHeight() * 4).y
;
465 inputText
.setLayoutData(gd
);
466 inputText
.setText(getSelectionText());
467 inputText
.addModifyListener(updateListener
);
469 vSash
.setWeights(new int[] { hSash
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).y
, sashBottom
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).y
});
471 setControl(container
);
477 private static class InputLineTreeNodeContentProvider
implements ITreeContentProvider
{
480 public Object
[] getElements(Object inputElement
) {
481 return ((List
<?
>) inputElement
).toArray();
485 public Object
[] getChildren(Object parentElement
) {
486 InputLine inputLine
= (InputLine
) parentElement
;
487 if (inputLine
.childrenInputs
== null) {
488 return new InputLine
[0];
490 return inputLine
.childrenInputs
.toArray();
494 public boolean hasChildren(Object element
) {
495 InputLine inputLine
= (InputLine
) element
;
496 return (inputLine
.childrenInputs
!= null && inputLine
.childrenInputs
.size() > 0);
500 public void dispose() {
504 public void inputChanged(Viewer viewer
, Object oldInput
, Object newInput
) {
508 public Object
getParent(Object element
) {
509 InputLine inputLine
= (InputLine
) element
;
510 return inputLine
.parentInput
;
514 private class InputLineTreeLabelProvider
extends ColumnLabelProvider
{
517 public Image
getImage(Object element
) {
522 public String
getText(Object element
) {
523 InputLine inputLine
= (InputLine
) element
;
524 if (inputLine
.parentInput
== null) {
525 return "Root Line " + getName(inputLine
) + " " + inputLine
.cardinality
.toString() + " : " + inputLine
.getRegex(); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
527 return "Line " + getName(inputLine
) + " " + inputLine
.cardinality
.toString() + " : " + inputLine
.getRegex(); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
531 private class InputLineTreeSelectionChangedListener
implements ISelectionChangedListener
{
533 public void selectionChanged(SelectionChangedEvent event
) {
534 if (selectedLine
!= null) {
535 selectedLine
.dispose();
537 if (!(event
.getSelection().isEmpty()) && event
.getSelection() instanceof IStructuredSelection
) {
538 IStructuredSelection sel
= (IStructuredSelection
) event
.getSelection();
539 InputLine inputLine
= (InputLine
) sel
.getFirstElement();
540 selectedLine
= new Line(lineContainer
, getName(inputLine
), inputLine
);
541 lineContainer
.layout();
542 lineScrolledComposite
.setMinSize(lineContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).x
, lineContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).y
- 1);
551 public void dispose() {
552 if (fixedFont
!= null) {
559 private void loadDefinition(CustomTxtTraceDefinition def
) {
560 categoryText
.setText(def
.categoryName
);
561 logtypeText
.setText(def
.definitionName
);
562 if (def
.timeStampOutputFormat
!= null) {
563 timestampOutputFormatText
.setText(def
.timeStampOutputFormat
);
565 timestampOutputFormatText
.setText(""); //$NON-NLS-1$
567 treeViewer
.setInput(def
.inputs
);
568 if (def
.inputs
.size() > 0) {
569 InputLine inputLine
= def
.inputs
.get(0);
570 treeViewer
.setSelection(new StructuredSelection(inputLine
));
574 private String
getName(InputLine inputLine
) {
575 if (inputLine
.parentInput
== null) {
576 return Integer
.toString(definition
.inputs
.indexOf(inputLine
) + 1);
578 return getName(inputLine
.parentInput
) + "." + Integer
.toString(inputLine
.parentInput
.childrenInputs
.indexOf(inputLine
) + 1); //$NON-NLS-1$
582 * Get the global list of inputs.
584 * @return The list of inputs
586 public List
<Entry
<Tag
, String
>> getInputs() {
587 List
<Entry
<Tag
, String
>> inputs
= new ArrayList
<>();
588 for (InputLine inputLine
: definition
.inputs
) {
589 for (Entry
<Tag
, String
> input
: getInputs(inputLine
)) {
590 if (!inputs
.contains(input
)) {
599 * Get the list of inputs for the given input line, recursively.
603 * @return The list of inputs
605 private List
<Entry
<Tag
, String
>> getInputs(InputLine inputLine
) {
606 List
<Entry
<Tag
, String
>> inputs
= new ArrayList
<>();
607 if (inputLine
.columns
!= null) {
608 for (InputData inputData
: inputLine
.columns
) {
609 Entry
<Tag
, String
> input
= new SimpleEntry
<>(inputData
.tag
, inputData
.name
);
610 if (!inputs
.contains(input
)) {
615 if (inputLine
.childrenInputs
!= null) {
616 for (InputLine childInputLine
: inputLine
.childrenInputs
) {
617 for (Entry
<Tag
, String
> input
: getInputs(childInputLine
)) {
618 if (!inputs
.contains(input
)) {
627 private void removeLine() {
628 selectedLine
.dispose();
630 lineContainer
.layout();
631 lineScrolledComposite
.setMinSize(lineContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).x
, lineContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).y
- 1);
635 private String
getSelectionText() {
636 if (this.selection
instanceof IStructuredSelection
) {
637 Object sel
= ((IStructuredSelection
) this.selection
).getFirstElement();
638 if (sel
instanceof IFile
) {
639 IFile file
= (IFile
) sel
;
640 BufferedReader reader
= null;
642 reader
= new BufferedReader(new InputStreamReader(file
.getContents()));
643 StringBuilder sb
= new StringBuilder();
645 while ((line
= reader
.readLine()) != null) {
649 return sb
.toString();
650 } catch (CoreException e
) {
651 return ""; //$NON-NLS-1$
652 } catch (IOException e
) {
653 return ""; //$NON-NLS-1$
655 if (reader
!= null) {
658 } catch (IOException e
) {
664 return ""; //$NON-NLS-1$
667 private void updatePreviews() {
668 updatePreviews(false);
671 private void updatePreviews(boolean updateAll
) {
672 if (inputText
== null) {
673 // early update during construction
676 inputText
.setStyleRanges(new StyleRange
[] {});
678 try (Scanner scanner
= new Scanner(inputText
.getText());) {
679 scanner
.useDelimiter("\n"); //$NON-NLS-1$
682 // skip starting delimiters
683 String skip
= scanner
.findWithinHorizon("\\A\n+", 0); //$NON-NLS-1$
685 rawPos
+= skip
.length();
688 timeStampFormat
= null;
689 if (selectedLine
!= null) {
690 for (InputGroup input
: selectedLine
.inputs
) {
691 input
.previewText
.setText(Messages
.CustomTxtParserInputWizardPage_noMathcingLine
);
695 Map
<Object
, String
> data
= new HashMap
<>();
696 int rootLineMatches
= 0;
697 String firstEntryTimeStamp
= null;
698 String firstEntryTimeStampInputFormat
= null;
700 boolean lineIsNull
= true; // needed because of JDT bug with continue at label
701 event
: while (scanner
.hasNext() || !lineIsNull
) {
702 if (rootLineMatches
> 0 && !updateAll
) {
706 line
= scanner
.next();
709 int length
= line
.length();
710 String log
= line
.replaceAll("\r", ""); //$NON-NLS-1$ //$NON-NLS-2$
711 for (InputLine rootInputLine
: definition
.inputs
) {
714 pattern
= rootInputLine
.getPattern();
715 } catch (PatternSyntaxException e
) {
718 Matcher matcher
= pattern
.matcher(log
);
719 if (matcher
.matches()) {
721 inputText
.setStyleRange(new StyleRange(rawPos
, length
,
722 COLOR_BLACK
, COLOR_YELLOW
, SWT
.ITALIC
));
723 data
= new HashMap
<>();
724 timeStampFormat
= null;
725 updatePreviewLine(rootInputLine
, matcher
, data
, rawPos
, rootLineMatches
);
726 if (rootLineMatches
== 1) {
727 firstEntryTimeStamp
= data
.get(Tag
.TIMESTAMP
);
728 firstEntryTimeStampInputFormat
= timeStampFormat
;
730 HashMap
<InputLine
, Integer
> countMap
= new HashMap
<>();
731 InputLine currentInput
= null;
732 if (rootInputLine
.childrenInputs
!= null && rootInputLine
.childrenInputs
.size() > 0) {
733 currentInput
= rootInputLine
.childrenInputs
.get(0);
734 countMap
.put(currentInput
, 0);
736 rawPos
+= length
+ 1; // +1 for \n
737 while (scanner
.hasNext()) {
738 line
= scanner
.next();
739 length
= line
.length();
740 log
= line
.replaceAll("\r", ""); //$NON-NLS-1$ //$NON-NLS-2$
741 boolean processed
= false;
742 if (currentInput
== null) {
743 for (InputLine input
: definition
.inputs
) {
745 matcher
= input
.getPattern().matcher(log
);
746 } catch (PatternSyntaxException e
) {
749 if (matcher
.matches()) {
754 if (checkNotNull(countMap
.get(currentInput
)) >= currentInput
.getMinCount()) {
755 List
<InputLine
> nextInputs
= currentInput
.getNextInputs(countMap
);
756 if (nextInputs
.size() == 0 || nextInputs
.get(nextInputs
.size() - 1).getMinCount() == 0) {
757 for (InputLine input
: definition
.inputs
) {
759 matcher
= input
.getPattern().matcher(log
);
760 } catch (PatternSyntaxException e
) {
763 if (matcher
.matches()) {
768 for (InputLine input
: nextInputs
) {
770 matcher
= input
.getPattern().matcher(log
);
771 } catch (PatternSyntaxException e
) {
774 if (matcher
.matches()) {
775 inputText
.setStyleRange(new StyleRange(rawPos
, length
,
776 COLOR_BLACK
, COLOR_LIGHT_YELLOW
, SWT
.ITALIC
));
777 currentInput
= input
;
778 updatePreviewLine(currentInput
, matcher
, data
, rawPos
, rootLineMatches
);
779 if (countMap
.get(currentInput
) == null) {
780 countMap
.put(currentInput
, 1);
782 countMap
.put(currentInput
, checkNotNull(countMap
.get(currentInput
)) + 1);
784 Iterator
<InputLine
> iter
= countMap
.keySet().iterator();
785 while (iter
.hasNext()) {
786 InputLine inputLine
= iter
.next();
787 if (inputLine
.level
> currentInput
.level
) {
791 if (currentInput
.childrenInputs
!= null && currentInput
.childrenInputs
.size() > 0) {
792 currentInput
= currentInput
.childrenInputs
.get(0);
793 countMap
.put(currentInput
, 0);
795 if (checkNotNull(countMap
.get(currentInput
)) >= currentInput
.getMaxCount()) {
796 if (currentInput
.getNextInputs(countMap
).size() > 0) {
797 currentInput
= currentInput
.getNextInputs(countMap
).get(0);
798 if (countMap
.get(currentInput
) == null) {
799 countMap
.put(currentInput
, 0);
801 iter
= countMap
.keySet().iterator();
802 while (iter
.hasNext()) {
803 InputLine inputLine
= iter
.next();
804 if (inputLine
.level
> currentInput
.level
) {
818 if (!processed
&& currentInput
!= null) {
821 matcher
= currentInput
.getPattern().matcher(log
);
822 } catch (PatternSyntaxException e
) {
824 if (matcher
!= null && matcher
.matches()) {
825 inputText
.setStyleRange(new StyleRange(rawPos
, length
,
826 COLOR_BLACK
, COLOR_LIGHT_YELLOW
, SWT
.ITALIC
));
827 updatePreviewLine(currentInput
, matcher
, data
, rawPos
, rootLineMatches
);
828 countMap
.put(currentInput
, checkNotNull(countMap
.get(currentInput
)) + 1);
829 if (currentInput
.childrenInputs
!= null && currentInput
.childrenInputs
.size() > 0) {
830 currentInput
= currentInput
.childrenInputs
.get(0);
831 countMap
.put(currentInput
, 0);
833 if (checkNotNull(countMap
.get(currentInput
)) >= currentInput
.getMaxCount()) {
834 if (currentInput
.getNextInputs(countMap
).size() > 0) {
835 currentInput
= currentInput
.getNextInputs(countMap
).get(0);
836 if (countMap
.get(currentInput
) == null) {
837 countMap
.put(currentInput
, 0);
839 Iterator
<InputLine
> iter
= countMap
.keySet().iterator();
840 while (iter
.hasNext()) {
841 InputLine inputLine
= iter
.next();
842 if (inputLine
.level
> currentInput
.level
) {
854 rawPos
+= length
+ 1; // +1 for \n
860 rawPos
+= length
+ 1; // +1 for \n
865 if (rootLineMatches
== 1) {
866 firstEntryTimeStamp
= data
.get(Tag
.TIMESTAMP
);
867 firstEntryTimeStampInputFormat
= timeStampFormat
;
869 if (firstEntryTimeStamp
== null) {
870 timestampPreviewText
.setText(Messages
.CustomTxtParserInputWizardPage_noTimestampGroup
);
871 if (selectedLine
!= null) {
872 for (InputGroup group
: selectedLine
.inputs
) {
873 if (group
.tagCombo
.getText().equals(Tag
.TIMESTAMP
.toString())) {
874 timestampPreviewText
.setText(Messages
.CustomTxtParserInputWizardPage_noMatchingTimestamp
);
881 TmfTimestampFormat timestampFormat
= new TmfTimestampFormat(firstEntryTimeStampInputFormat
);
882 long timestamp
= timestampFormat
.parseValue(firstEntryTimeStamp
);
883 if (timestampOutputFormatText
.getText().trim().isEmpty()) {
884 timestampFormat
= new TmfTimestampFormat();
886 timestampFormat
= new TmfTimestampFormat(timestampOutputFormatText
.getText().trim());
888 timestampPreviewText
.setText(timestampFormat
.format(timestamp
));
889 } catch (ParseException e
) {
890 timestampPreviewText
.setText("*parse exception* [" + firstEntryTimeStamp
+ "] <> [" + firstEntryTimeStampInputFormat
+ "]"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
891 } catch (IllegalArgumentException e
) {
892 timestampPreviewText
.setText("*parse exception* [Illegal Argument: " + e
.getMessage() + "]"); //$NON-NLS-1$ //$NON-NLS-2$
899 private void updatePreviewLine(InputLine line
, Matcher matcher
, Map
<Object
, String
> data
, int rawPos
, int rootLineMatches
) {
900 for (int i
= 0; i
< line
.columns
.size(); i
++) {
901 InputData input
= line
.columns
.get(i
);
902 if (i
< matcher
.groupCount() && matcher
.group(i
+ 1) != null) {
903 if (line
.parentInput
== null) {
904 inputText
.setStyleRange(new StyleRange(rawPos
+ matcher
.start(i
+ 1), matcher
.end(i
+ 1) - matcher
.start(i
+ 1),
905 COLOR_BLACK
, COLOR_GREEN
, SWT
.BOLD
));
907 inputText
.setStyleRange(new StyleRange(rawPos
+ matcher
.start(i
+ 1), matcher
.end(i
+ 1) - matcher
.start(i
+ 1),
908 COLOR_BLACK
, COLOR_LIGHT_GREEN
, SWT
.BOLD
));
910 String value
= matcher
.group(i
+ 1).trim();
911 if (selectedLine
!= null && selectedLine
.inputLine
.equals(line
) && rootLineMatches
== 1 &&
912 selectedLine
.inputs
.get(i
).previewText
.getText().equals(Messages
.CustomTxtParserInputWizardPage_noMatchingLine
)) {
913 selectedLine
.inputs
.get(i
).previewText
.setText(value
);
915 if (value
.length() == 0) {
918 Object key
= (input
.tag
.equals(Tag
.OTHER
) ? input
.name
: input
.tag
);
919 if (input
.action
== CustomTraceDefinition
.ACTION_SET
) {
920 data
.put(key
, value
);
921 if (input
.tag
.equals(Tag
.TIMESTAMP
)) {
922 timeStampFormat
= input
.format
;
924 } else if (input
.action
== CustomTraceDefinition
.ACTION_APPEND
) {
925 String s
= data
.get(key
);
927 data
.put(key
, s
+ value
);
929 data
.put(key
, value
);
931 if (input
.tag
.equals(Tag
.TIMESTAMP
)) {
932 if (timeStampFormat
!= null) {
933 timeStampFormat
+= input
.format
;
935 timeStampFormat
= input
.format
;
938 } else if (input
.action
== CustomTraceDefinition
.ACTION_APPEND_WITH_SEPARATOR
) {
939 String s
= data
.get(key
);
941 data
.put(key
, s
+ " | " + value
); //$NON-NLS-1$
943 data
.put(key
, value
);
945 if (input
.tag
.equals(Tag
.TIMESTAMP
)) {
946 if (timeStampFormat
!= null) {
947 timeStampFormat
+= " | " + input
.format
; //$NON-NLS-1$
949 timeStampFormat
= input
.format
;
954 if (selectedLine
!= null && selectedLine
.inputLine
.equals(line
) && rootLineMatches
== 1) {
955 if (selectedLine
.inputs
.get(i
).previewText
.getText().equals(Messages
.CustomTxtParserInputWizardPage_noMatchingLine
)) {
956 selectedLine
.inputs
.get(i
).previewText
.setText(Messages
.CustomTxtParserInputWizardPage_noMatchingGroup
);
961 // highlight the matching groups that have no corresponponding input
962 for (int i
= line
.columns
.size(); i
< matcher
.groupCount(); i
++) {
963 if (matcher
.group(i
+ 1) != null) {
964 if (line
.parentInput
== null) {
965 inputText
.setStyleRange(new StyleRange(rawPos
+ matcher
.start(i
+ 1), matcher
.end(i
+ 1) - matcher
.start(i
+ 1),
966 COLOR_BLACK
, COLOR_MAGENTA
));
968 inputText
.setStyleRange(new StyleRange(rawPos
+ matcher
.start(i
+ 1), matcher
.end(i
+ 1) - matcher
.start(i
+ 1),
969 COLOR_BLACK
, COLOR_LIGHT_MAGENTA
));
975 private void openHelpShell(String url
) {
976 if (helpBrowser
!= null && !helpBrowser
.isDisposed()) {
977 helpBrowser
.getShell().setActive();
978 if (!helpBrowser
.getUrl().equals(url
)) {
979 helpBrowser
.setUrl(url
);
983 final Shell helpShell
= new Shell(getShell(), SWT
.SHELL_TRIM
);
984 helpShell
.setLayout(new FillLayout());
985 helpBrowser
= new Browser(helpShell
, SWT
.NONE
);
986 helpBrowser
.addTitleListener(new TitleListener() {
988 public void changed(TitleEvent event
) {
989 helpShell
.setText(event
.title
);
992 Rectangle r
= container
.getBounds();
993 Point p
= container
.toDisplay(r
.x
, r
.y
);
994 Rectangle trim
= helpShell
.computeTrim(p
.x
+ (r
.width
- 750) / 2, p
.y
+ (r
.height
- 400) / 2, 750, 400);
995 helpShell
.setBounds(trim
);
997 helpBrowser
.setUrl(url
);
1000 private void openLegend() {
1001 final String cg
= Messages
.CustomTxtParserInputWizardPage_capturedGroup
;
1002 final String ucg
= Messages
.CustomTxtParserInputWizardPage_unidentifiedCaptureGroup
;
1003 final String ut
= Messages
.CustomTxtParserInputWizardPage_uncapturedText
;
1005 String line1
= Messages
.CustomTxtParserInputWizardPage_nonMatchingLine
;
1006 int line2start
= line1start
+ line1
.length();
1007 String line2
= Messages
.CustomTxtParserInputWizardPage_matchingRootLine
+ ' ' + cg
+ ' ' + ucg
+ ' ' + ut
+ " \n"; //$NON-NLS-1$
1008 int line3start
= line2start
+ line2
.length();
1009 String line3
= Messages
.CustomTxtParserInputWizardPage_matchingOtherLine
+ ' ' + cg
+ ' ' + ucg
+ ' ' + ut
+ " \n"; //$NON-NLS-1$
1010 int line4start
= line3start
+ line3
.length();
1011 String line4
= Messages
.CustomTxtParserInputWizardPage_matchingOtherLine
+ ' ' + cg
+ ' ' + ucg
+ ' ' + ut
+ " \n"; //$NON-NLS-1$
1012 int line5start
= line4start
+ line4
.length();
1013 String line5
= Messages
.CustomTxtParserInputWizardPage_nonMatchingLine
;
1014 int line6start
= line5start
+ line5
.length();
1015 String line6
= Messages
.CustomTxtParserInputWizardPage_matchingRootLine
+ cg
+ ' ' + ucg
+ ' ' + ut
+ " \n"; //$NON-NLS-1$
1017 final Shell legendShell
= new Shell(getShell(), SWT
.DIALOG_TRIM
);
1018 legendShell
.setLayout(new FillLayout());
1019 StyledText legendText
= new StyledText(legendShell
, SWT
.MULTI
);
1020 legendText
.setFont(fixedFont
);
1021 legendText
.setText(line1
+ line2
+ line3
+ line4
+ line5
+ line6
);
1022 legendText
.setStyleRange(new StyleRange(line2start
, line2
.length(), COLOR_BLACK
, COLOR_YELLOW
, SWT
.ITALIC
));
1023 legendText
.setStyleRange(new StyleRange(line3start
, line3
.length(), COLOR_BLACK
, COLOR_LIGHT_YELLOW
, SWT
.ITALIC
));
1024 legendText
.setStyleRange(new StyleRange(line4start
, line4
.length(), COLOR_BLACK
, COLOR_LIGHT_YELLOW
, SWT
.ITALIC
));
1025 legendText
.setStyleRange(new StyleRange(line6start
, line6
.length(), COLOR_BLACK
, COLOR_YELLOW
, SWT
.ITALIC
));
1026 legendText
.setStyleRange(new StyleRange(line2start
+ line2
.indexOf(cg
), cg
.length(), COLOR_BLACK
, COLOR_GREEN
, SWT
.BOLD
));
1027 legendText
.setStyleRange(new StyleRange(line2start
+ line2
.indexOf(ucg
), ucg
.length(), COLOR_BLACK
, COLOR_MAGENTA
));
1028 legendText
.setStyleRange(new StyleRange(line3start
+ line3
.indexOf(cg
), cg
.length(), COLOR_BLACK
, COLOR_LIGHT_GREEN
, SWT
.BOLD
));
1029 legendText
.setStyleRange(new StyleRange(line3start
+ line3
.indexOf(ucg
), ucg
.length(), COLOR_BLACK
, COLOR_LIGHT_MAGENTA
));
1030 legendText
.setStyleRange(new StyleRange(line4start
+ line4
.indexOf(cg
), cg
.length(), COLOR_BLACK
, COLOR_LIGHT_GREEN
, SWT
.BOLD
));
1031 legendText
.setStyleRange(new StyleRange(line4start
+ line4
.indexOf(ucg
), ucg
.length(), COLOR_BLACK
, COLOR_LIGHT_MAGENTA
));
1032 legendText
.setStyleRange(new StyleRange(line6start
+ line6
.indexOf(cg
), cg
.length(), COLOR_BLACK
, COLOR_GREEN
, SWT
.BOLD
));
1033 legendText
.setStyleRange(new StyleRange(line6start
+ line6
.indexOf(ucg
), ucg
.length(), COLOR_BLACK
, COLOR_MAGENTA
));
1034 legendShell
.setText(Messages
.CustomTxtParserInputWizardPage_previewLegend
);
1039 private class UpdateListener
implements ModifyListener
, SelectionListener
{
1042 public void modifyText(ModifyEvent e
) {
1048 public void widgetDefaultSelected(SelectionEvent e
) {
1054 public void widgetSelected(SelectionEvent e
) {
1061 private class Line
{
1062 private static final String INFINITY_STRING
= "\u221E"; //$NON-NLS-1$
1063 private InputLine inputLine
;
1064 private Group group
;
1065 private Composite labelComposite
;
1066 private Text regexText
;
1067 private Composite cardinalityContainer
;
1068 private Combo cardinalityCombo
;
1069 private Label cardinalityMinLabel
;
1070 private Text cardinalityMinText
;
1071 private Label cardinalityMaxLabel
;
1072 private Text cardinalityMaxText
;
1073 private Button infiniteButton
;
1074 private Button eventTypeButton
;
1075 private Text eventTypeText
;
1076 private List
<InputGroup
> inputs
= new ArrayList
<>();
1077 private Button addGroupButton
;
1078 private Label addGroupLabel
;
1080 public Line(Composite parent
, String name
, InputLine inputLine
) {
1081 this.inputLine
= inputLine
;
1083 group
= new Group(parent
, SWT
.NONE
);
1084 group
.setText(name
);
1085 group
.setLayout(new GridLayout(2, false));
1086 group
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
1088 labelComposite
= new Composite(group
, SWT
.FILL
);
1089 GridLayout labelLayout
= new GridLayout(1, false);
1090 labelLayout
.marginWidth
= 0;
1091 labelLayout
.marginHeight
= 0;
1092 labelComposite
.setLayout(labelLayout
);
1093 labelComposite
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
1095 Label label
= new Label(labelComposite
, SWT
.NULL
);
1096 label
.setText(Messages
.CustomTxtParserInputWizardPage_regularExpression
);
1098 Composite regexContainer
= new Composite(group
, SWT
.NONE
);
1099 GridLayout regexLayout
= new GridLayout(2, false);
1100 regexLayout
.marginHeight
= 0;
1101 regexLayout
.marginWidth
= 0;
1102 regexContainer
.setLayout(regexLayout
);
1103 regexContainer
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
1105 regexText
= new Text(regexContainer
, SWT
.BORDER
| SWT
.SINGLE
);
1106 GridData gd
= new GridData(SWT
.FILL
, SWT
.CENTER
, true, false);
1108 regexText
.setLayoutData(gd
);
1109 regexText
.setText(inputLine
.getRegex());
1110 regexText
.addModifyListener(updateListener
);
1112 Button regexHelpButton
= new Button(regexContainer
, SWT
.PUSH
);
1113 regexHelpButton
.setImage(HELP_IMAGE
);
1114 regexHelpButton
.setToolTipText(Messages
.CustomTxtParserInputWizardPage_regularExpressionHelp
);
1115 regexHelpButton
.addSelectionListener(new SelectionAdapter() {
1117 public void widgetSelected(SelectionEvent e
) {
1118 openHelpShell(PATTERN_URL
);
1122 label
= new Label(group
, SWT
.NONE
);
1123 label
.setText(Messages
.CustomTxtParserInputWizardPage_cardinality
);
1124 label
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
1126 cardinalityContainer
= new Composite(group
, SWT
.NONE
);
1127 GridLayout cardinalityLayout
= new GridLayout(6, false);
1128 cardinalityLayout
.marginHeight
= 0;
1129 cardinalityLayout
.marginWidth
= 0;
1130 cardinalityContainer
.setLayout(cardinalityLayout
);
1131 cardinalityContainer
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
1133 cardinalityCombo
= new Combo(cardinalityContainer
, SWT
.DROP_DOWN
| SWT
.READ_ONLY
);
1134 cardinalityCombo
.setItems(new String
[] {
1135 Cardinality
.ZERO_OR_MORE
.toString(),
1136 Cardinality
.ONE_OR_MORE
.toString(),
1137 Cardinality
.ZERO_OR_ONE
.toString(),
1138 Cardinality
.ONE
.toString(), "(?,?)" }); //$NON-NLS-1$
1139 cardinalityCombo
.addSelectionListener(new SelectionListener() {
1141 public void widgetDefaultSelected(SelectionEvent e
) {
1145 public void widgetSelected(SelectionEvent e
) {
1146 switch (cardinalityCombo
.getSelectionIndex()) {
1148 cardinalityMinLabel
.setVisible(true);
1149 cardinalityMinText
.setVisible(true);
1150 cardinalityMaxLabel
.setVisible(true);
1151 cardinalityMaxText
.setVisible(true);
1152 infiniteButton
.setVisible(true);
1155 cardinalityMinLabel
.setVisible(false);
1156 cardinalityMinText
.setVisible(false);
1157 cardinalityMaxLabel
.setVisible(false);
1158 cardinalityMaxText
.setVisible(false);
1159 infiniteButton
.setVisible(false);
1162 cardinalityContainer
.layout();
1168 cardinalityMinLabel
= new Label(cardinalityContainer
, SWT
.NONE
);
1169 cardinalityMinLabel
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
1170 cardinalityMinLabel
.setText(Messages
.CustomTxtParserInputWizardPage_min
);
1171 cardinalityMinLabel
.setVisible(false);
1173 cardinalityMinText
= new Text(cardinalityContainer
, SWT
.BORDER
| SWT
.SINGLE
);
1174 gd
= new GridData(SWT
.CENTER
, SWT
.CENTER
, false, false);
1176 cardinalityMinText
.setLayoutData(gd
);
1177 cardinalityMinText
.setVisible(false);
1179 cardinalityMaxLabel
= new Label(cardinalityContainer
, SWT
.NONE
);
1180 cardinalityMaxLabel
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
1181 cardinalityMaxLabel
.setText(Messages
.CustomTxtParserInputWizardPage_max
);
1182 cardinalityMaxLabel
.setVisible(false);
1184 cardinalityMaxText
= new Text(cardinalityContainer
, SWT
.BORDER
| SWT
.SINGLE
);
1185 gd
= new GridData(SWT
.CENTER
, SWT
.CENTER
, false, false);
1187 cardinalityMaxText
.setLayoutData(gd
);
1188 cardinalityMaxText
.setVisible(false);
1190 infiniteButton
= new Button(cardinalityContainer
, SWT
.PUSH
);
1191 infiniteButton
.setText(INFINITY_STRING
);
1192 infiniteButton
.setVisible(false);
1193 infiniteButton
.addSelectionListener(new SelectionAdapter() {
1195 public void widgetSelected(SelectionEvent e
) {
1196 cardinalityMaxText
.setText(INFINITY_STRING
);
1200 if (inputLine
.cardinality
.equals(Cardinality
.ZERO_OR_MORE
)) {
1201 cardinalityCombo
.select(0);
1202 } else if (inputLine
.cardinality
.equals(Cardinality
.ONE_OR_MORE
)) {
1203 cardinalityCombo
.select(1);
1204 } else if (inputLine
.cardinality
.equals(Cardinality
.ZERO_OR_ONE
)) {
1205 cardinalityCombo
.select(2);
1206 } else if (inputLine
.cardinality
.equals(Cardinality
.ONE
)) {
1207 cardinalityCombo
.select(3);
1209 cardinalityCombo
.select(4);
1210 cardinalityMinLabel
.setVisible(true);
1211 cardinalityMinText
.setVisible(true);
1212 if (inputLine
.getMinCount() >= 0) {
1213 cardinalityMinText
.setText(Integer
.toString(inputLine
.getMinCount()));
1215 cardinalityMaxLabel
.setVisible(true);
1216 cardinalityMaxText
.setVisible(true);
1217 if (inputLine
.getMaxCount() == Cardinality
.INF
) {
1218 cardinalityMaxText
.setText(INFINITY_STRING
);
1219 } else if (inputLine
.getMaxCount() >= 0) {
1220 cardinalityMaxText
.setText(Integer
.toString(inputLine
.getMaxCount()));
1222 infiniteButton
.setVisible(true);
1225 VerifyListener digitsListener
= new VerifyListener() {
1227 public void verifyText(VerifyEvent e
) {
1228 if (e
.text
.equals(INFINITY_STRING
)) {
1229 e
.doit
= e
.widget
== cardinalityMaxText
&& e
.start
== 0 && e
.end
== ((Text
) e
.widget
).getText().length();
1231 if (((Text
) e
.widget
).getText().equals(INFINITY_STRING
)) {
1232 e
.doit
= e
.start
== 0 && e
.end
== ((Text
) e
.widget
).getText().length();
1234 for (int i
= 0; i
< e
.text
.length(); i
++) {
1235 if (!Character
.isDigit(e
.text
.charAt(i
))) {
1244 cardinalityMinText
.addModifyListener(updateListener
);
1245 cardinalityMaxText
.addModifyListener(updateListener
);
1246 cardinalityMinText
.addVerifyListener(digitsListener
);
1247 cardinalityMaxText
.addVerifyListener(digitsListener
);
1249 eventTypeButton
= new Button(group
, SWT
.CHECK
);
1250 eventTypeButton
.setText(Messages
.CustomTxtParserInputWizardPage_eventType
);
1251 eventTypeButton
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
1252 eventTypeButton
.addSelectionListener(new SelectionAdapter() {
1254 public void widgetSelected(SelectionEvent e
) {
1255 if (eventTypeButton
.getSelection()) {
1256 eventTypeText
.setEnabled(true);
1258 eventTypeText
.setEnabled(false);
1262 eventTypeButton
.addSelectionListener(updateListener
);
1264 eventTypeText
= new Text(group
, SWT
.BORDER
| SWT
.SINGLE
);
1265 gd
= new GridData(SWT
.FILL
, SWT
.CENTER
, true, false);
1267 eventTypeText
.setLayoutData(gd
);
1268 if (inputLine
.eventType
!= null) {
1269 eventTypeText
.setText(inputLine
.eventType
);
1270 eventTypeButton
.setSelection(true);
1272 eventTypeText
.setEnabled(false);
1273 eventTypeButton
.setSelection(false);
1275 eventTypeText
.addModifyListener(updateListener
);
1278 if (inputLine
.columns
!= null) {
1279 for (InputData inputData
: inputLine
.columns
) {
1280 InputGroup inputGroup
= new InputGroup(group
, this, inputs
.size() + 1);
1281 if (inputData
.tag
.equals(Tag
.TIMESTAMP
)) {
1282 inputGroup
.tagCombo
.select(0);
1283 inputGroup
.tagText
.setText(inputData
.format
);
1284 inputGroup
.tagLabel
.setText(Messages
.CustomTxtParserInputWizardPage_format
);
1285 inputGroup
.tagLabel
.setVisible(true);
1286 inputGroup
.tagText
.setVisible(true);
1287 inputGroup
.tagText
.addModifyListener(updateListener
);
1288 } else if (inputData
.tag
.equals(Tag
.EVENT_TYPE
)) {
1289 inputGroup
.tagCombo
.select(1);
1290 } else if (inputData
.tag
.equals(Tag
.MESSAGE
)) {
1291 inputGroup
.tagCombo
.select(2);
1293 inputGroup
.tagCombo
.select(3);
1294 inputGroup
.tagText
.setText(inputData
.name
);
1295 inputGroup
.tagLabel
.setText(Messages
.CustomTxtParserInputWizardPage_name
);
1296 inputGroup
.tagLabel
.setVisible(true);
1297 inputGroup
.tagText
.setVisible(true);
1298 inputGroup
.tagText
.addModifyListener(updateListener
);
1300 inputGroup
.actionCombo
.select(inputData
.action
);
1301 inputs
.add(inputGroup
);
1305 createAddGroupButton();
1308 private void createAddGroupButton() {
1309 addGroupButton
= new Button(group
, SWT
.PUSH
);
1310 addGroupButton
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
1311 addGroupButton
.setImage(ADD_IMAGE
);
1312 addGroupButton
.setToolTipText(Messages
.CustomTxtParserInputWizardPage_addGroup
);
1313 addGroupButton
.addSelectionListener(new SelectionAdapter() {
1315 public void widgetSelected(SelectionEvent e
) {
1316 removeAddGroupButton();
1317 inputs
.add(new InputGroup(group
, Line
.this, inputs
.size() + 1));
1318 createAddGroupButton();
1319 lineContainer
.layout();
1320 lineScrolledComposite
.setMinSize(lineContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).x
, lineContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).y
- 1);
1321 group
.getParent().layout();
1327 addGroupLabel
= new Label(group
, SWT
.NULL
);
1328 addGroupLabel
.setText(Messages
.CustomTxtParserInputWizardPage_newGroup
);
1331 private void removeAddGroupButton() {
1332 addGroupButton
.dispose();
1333 addGroupLabel
.dispose();
1336 private void removeInput(int inputNumber
) {
1337 int nb
= inputNumber
;
1338 if (--nb
< inputs
.size()) {
1339 inputs
.remove(nb
).dispose();
1340 for (int i
= nb
; i
< inputs
.size(); i
++) {
1341 inputs
.get(i
).setInputNumber(i
+ 1);
1343 lineContainer
.layout();
1344 lineScrolledComposite
.setMinSize(lineContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).x
, lineContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).y
- 1);
1345 group
.getParent().layout();
1349 private void dispose() {
1353 private void extractInputs() {
1354 inputLine
.setRegex(selectedLine
.regexText
.getText());
1355 inputLine
.eventType
= selectedLine
.eventTypeButton
.getSelection() ? selectedLine
.eventTypeText
.getText().trim() : null;
1356 switch (cardinalityCombo
.getSelectionIndex()) {
1358 inputLine
.cardinality
= Cardinality
.ZERO_OR_MORE
;
1361 inputLine
.cardinality
= Cardinality
.ONE_OR_MORE
;
1364 inputLine
.cardinality
= Cardinality
.ZERO_OR_ONE
;
1367 inputLine
.cardinality
= Cardinality
.ONE
;
1373 min
= Integer
.parseInt(cardinalityMinText
.getText());
1374 } catch (NumberFormatException e
) {
1378 if (cardinalityMaxText
.getText().equals(INFINITY_STRING
)) {
1379 max
= Cardinality
.INF
;
1381 max
= Integer
.parseInt(cardinalityMaxText
.getText());
1383 } catch (NumberFormatException e
) {
1386 inputLine
.cardinality
= new Cardinality(min
, max
);
1389 inputLine
.cardinality
= Cardinality
.ZERO_OR_MORE
;
1392 inputLine
.columns
= new ArrayList
<>(inputs
.size());
1393 for (int i
= 0; i
< inputs
.size(); i
++) {
1394 InputGroup grp
= inputs
.get(i
);
1395 InputData inputData
= new InputData();
1396 inputData
.tag
= Tag
.fromLabel(grp
.tagCombo
.getText());
1397 if (inputData
.tag
.equals(Tag
.OTHER
)) {
1398 inputData
.name
= grp
.tagText
.getText().trim();
1400 inputData
.name
= inputData
.tag
.toString();
1401 if (inputData
.tag
.equals(Tag
.TIMESTAMP
)) {
1402 inputData
.format
= grp
.tagText
.getText().trim();
1405 inputData
.action
= grp
.actionCombo
.getSelectionIndex();
1406 inputLine
.columns
.add(inputData
);
1411 private class InputGroup
{
1413 private int inputNumber
;
1415 // children of parent (must be disposed)
1416 private Composite labelComposite
;
1417 private Composite tagComposite
;
1418 private Label previewLabel
;
1419 private Text previewText
;
1421 // children of labelComposite
1422 private Label inputLabel
;
1424 // children of tagComposite
1425 private Combo tagCombo
;
1426 private Label tagLabel
;
1427 private Text tagText
;
1428 private Combo actionCombo
;
1430 public InputGroup(Composite parent
, Line line
, int inputNumber
) {
1432 this.inputNumber
= inputNumber
;
1434 labelComposite
= new Composite(parent
, SWT
.FILL
);
1435 GridLayout labelLayout
= new GridLayout(2, false);
1436 labelLayout
.marginWidth
= 0;
1437 labelLayout
.marginHeight
= 0;
1438 labelComposite
.setLayout(labelLayout
);
1439 labelComposite
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
1441 Button deleteButton
= new Button(labelComposite
, SWT
.PUSH
);
1442 deleteButton
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
1443 deleteButton
.setImage(DELETE_IMAGE
);
1444 deleteButton
.setToolTipText(Messages
.CustomTxtParserInputWizardPage_removeGroup
);
1445 deleteButton
.addSelectionListener(new SelectionAdapter() {
1447 public void widgetSelected(SelectionEvent e
) {
1448 InputGroup
.this.line
.removeInput(InputGroup
.this.inputNumber
);
1454 inputLabel
= new Label(labelComposite
, SWT
.NULL
);
1455 inputLabel
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
1456 inputLabel
.setText(NLS
.bind(Messages
.CustomTxtParserInputWizardPage_group
, inputNumber
));
1458 tagComposite
= new Composite(parent
, SWT
.FILL
);
1459 GridLayout tagLayout
= new GridLayout(4, false);
1460 tagLayout
.marginWidth
= 0;
1461 tagLayout
.marginHeight
= 0;
1462 tagComposite
.setLayout(tagLayout
);
1463 tagComposite
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
1465 tagCombo
= new Combo(tagComposite
, SWT
.DROP_DOWN
| SWT
.READ_ONLY
);
1466 tagCombo
.setItems(new String
[] {
1467 Tag
.TIMESTAMP
.toString(),
1468 Tag
.EVENT_TYPE
.toString(),
1469 Tag
.MESSAGE
.toString(),
1470 Tag
.OTHER
.toString()});
1472 tagCombo
.addSelectionListener(new SelectionListener() {
1474 public void widgetDefaultSelected(SelectionEvent e
) {
1478 public void widgetSelected(SelectionEvent e
) {
1479 tagText
.removeModifyListener(updateListener
);
1480 switch (tagCombo
.getSelectionIndex()) {
1481 case 0: // Time Stamp
1482 tagLabel
.setText(Messages
.CustomTxtParserInputWizardPage_format
);
1483 tagLabel
.setVisible(true);
1484 tagText
.setVisible(true);
1485 tagText
.addModifyListener(updateListener
);
1487 case 1: // Event type
1488 tagLabel
.setVisible(false);
1489 tagText
.setVisible(false);
1492 tagLabel
.setVisible(false);
1493 tagText
.setVisible(false);
1496 tagLabel
.setText(Messages
.CustomTxtParserInputWizardPage_name
);
1497 tagLabel
.setVisible(true);
1498 tagText
.setVisible(true);
1499 tagText
.addModifyListener(updateListener
);
1504 tagComposite
.layout();
1510 tagLabel
= new Label(tagComposite
, SWT
.NULL
);
1511 tagLabel
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
1512 tagLabel
.setVisible(false);
1514 tagText
= new Text(tagComposite
, SWT
.BORDER
| SWT
.SINGLE
);
1515 GridData gd
= new GridData(SWT
.FILL
, SWT
.CENTER
, true, false);
1517 tagText
.setLayoutData(gd
);
1518 tagText
.setVisible(false);
1520 actionCombo
= new Combo(tagComposite
, SWT
.DROP_DOWN
| SWT
.READ_ONLY
);
1521 actionCombo
.setItems(new String
[] { Messages
.CustomTxtParserInputWizardPage_set
, Messages
.CustomTxtParserInputWizardPage_append
, Messages
.CustomTxtParserInputWizardPage_appendWith
});
1522 actionCombo
.select(0);
1523 actionCombo
.addSelectionListener(updateListener
);
1525 previewLabel
= new Label(parent
, SWT
.NULL
);
1526 previewLabel
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
1527 previewLabel
.setText(Messages
.CustomTxtParserInputWizardPage_preview
);
1529 previewText
= new Text(parent
, SWT
.BORDER
| SWT
.SINGLE
| SWT
.READ_ONLY
);
1530 gd
= new GridData(SWT
.FILL
, SWT
.CENTER
, true, false);
1532 previewText
.setLayoutData(gd
);
1533 previewText
.setText(Messages
.CustomTxtParserInputWizardPage_noMatch
);
1534 previewText
.setBackground(COLOR_WIDGET_BACKGROUND
);
1537 private void dispose() {
1538 labelComposite
.dispose();
1539 tagComposite
.dispose();
1540 previewLabel
.dispose();
1541 previewText
.dispose();
1544 private void setInputNumber(int inputNumber
) {
1545 this.inputNumber
= inputNumber
;
1546 inputLabel
.setText(NLS
.bind(Messages
.CustomTxtParserInputWizardPage_group
, inputNumber
));
1547 labelComposite
.layout();
1551 private void validate() {
1553 definition
.categoryName
= categoryText
.getText().trim();
1554 definition
.definitionName
= logtypeText
.getText().trim();
1555 definition
.timeStampOutputFormat
= timestampOutputFormatText
.getText().trim();
1557 if (selectedLine
!= null) {
1558 selectedLine
.extractInputs();
1559 treeViewer
.refresh();
1562 StringBuffer errors
= new StringBuffer();
1564 if (definition
.categoryName
.length() == 0) {
1565 errors
.append("Enter a category for the new trace type. "); //$NON-NLS-1$
1566 categoryText
.setBackground(COLOR_LIGHT_RED
);
1567 } else if (definition
.definitionName
.length() == 0) {
1568 errors
.append("Enter a name for the new trace type. "); //$NON-NLS-1$
1569 logtypeText
.setBackground(COLOR_LIGHT_RED
);
1571 categoryText
.setBackground(COLOR_TEXT_BACKGROUND
);
1572 logtypeText
.setBackground(COLOR_TEXT_BACKGROUND
);
1573 if (definition
.categoryName
.indexOf(':') != -1) {
1574 errors
.append("Invalid character ':' in category. "); //$NON-NLS-1$
1575 categoryText
.setBackground(COLOR_LIGHT_RED
);
1577 if (definition
.definitionName
.indexOf(':') != -1) {
1578 errors
.append("Invalid character ':' in trace type. "); //$NON-NLS-1$
1579 logtypeText
.setBackground(COLOR_LIGHT_RED
);
1581 for (TraceTypeHelper helper
: TmfTraceType
.getTraceTypeHelpers()) {
1582 if (definition
.categoryName
.equals(helper
.getCategoryName()) &&
1583 definition
.definitionName
.equals(helper
.getName()) &&
1584 (editDefinitionName
== null || !editDefinitionName
.equals(definition
.definitionName
)) &&
1585 (editCategoryName
== null || !editCategoryName
.equals(definition
.categoryName
))) {
1586 errors
.append("The trace type name already exists. "); //$NON-NLS-1$
1587 logtypeText
.setBackground(COLOR_LIGHT_RED
);
1593 timestampFound
= false;
1594 for (int i
= 0; i
< definition
.inputs
.size(); i
++) {
1596 InputLine inputLine
= definition
.inputs
.get(i
);
1597 String name
= Integer
.toString(i
+ 1);
1598 errors
.append(validateLine(inputLine
, name
));
1600 if (timestampFound
&& !definition
.timeStampOutputFormat
.isEmpty()) {
1602 new TmfTimestampFormat(definition
.timeStampOutputFormat
);
1603 timestampOutputFormatText
.setBackground(COLOR_TEXT_BACKGROUND
);
1604 } catch (IllegalArgumentException e
) {
1605 errors
.append("Enter a valid output format for the Time Stamp field [" + e
.getMessage() + "]."); //$NON-NLS-1$ //$NON-NLS-2$
1606 timestampOutputFormatText
.setBackground(COLOR_LIGHT_RED
);
1609 timestampOutputFormatText
.setBackground(COLOR_TEXT_BACKGROUND
);
1612 if (errors
.length() == 0) {
1613 setDescription(defaultDescription
);
1614 setPageComplete(true);
1616 setDescription(errors
.toString());
1617 setPageComplete(false);
1622 * Validate an input line.
1625 * The line to clean up
1627 * The name of the line
1628 * @return The cleaned up line
1630 public StringBuffer
validateLine(InputLine inputLine
, String name
) {
1631 StringBuffer errors
= new StringBuffer();
1633 if (selectedLine
!= null && selectedLine
.inputLine
.equals(inputLine
)) {
1634 line
= selectedLine
;
1637 Pattern
.compile(inputLine
.getRegex());
1639 line
.regexText
.setBackground(COLOR_TEXT_BACKGROUND
);
1641 } catch (PatternSyntaxException e
) {
1642 errors
.append("Enter a valid regular expression (Line " + name
+ "). "); //$NON-NLS-1$ //$NON-NLS-2$
1644 line
.regexText
.setBackground(COLOR_LIGHT_RED
);
1647 if (inputLine
.getMinCount() == -1) {
1648 errors
.append("Enter a minimum value for cardinality (Line " + name
+ "). "); //$NON-NLS-1$ //$NON-NLS-2$
1650 line
.cardinalityMinText
.setBackground(COLOR_LIGHT_RED
);
1654 line
.cardinalityMinText
.setBackground(COLOR_TEXT_BACKGROUND
);
1657 if (inputLine
.getMaxCount() == -1) {
1658 errors
.append("Enter a maximum value for cardinality (Line " + name
+ "). "); //$NON-NLS-1$ //$NON-NLS-2$
1660 line
.cardinalityMaxText
.setBackground(COLOR_LIGHT_RED
);
1662 } else if (inputLine
.getMinCount() > inputLine
.getMaxCount()) {
1663 errors
.append("Enter correct (min <= max) values for cardinality (Line " + name
+ "). "); //$NON-NLS-1$ //$NON-NLS-2$
1665 line
.cardinalityMinText
.setBackground(COLOR_LIGHT_RED
);
1668 line
.cardinalityMaxText
.setBackground(COLOR_LIGHT_RED
);
1672 line
.cardinalityMaxText
.setBackground(COLOR_TEXT_BACKGROUND
);
1675 if (inputLine
.eventType
!= null && inputLine
.eventType
.trim().isEmpty()) {
1676 errors
.append("Enter the event type (Line " + name
+ "). "); //$NON-NLS-1$ //$NON-NLS-2$
1678 line
.eventTypeText
.setBackground(COLOR_LIGHT_RED
);
1682 line
.eventTypeText
.setBackground(COLOR_TEXT_BACKGROUND
);
1685 for (int i
= 0; inputLine
.columns
!= null && i
< inputLine
.columns
.size(); i
++) {
1686 InputData inputData
= inputLine
.columns
.get(i
);
1687 InputGroup group
= null;
1689 group
= line
.inputs
.get(i
);
1691 if (inputData
.tag
.equals(Tag
.TIMESTAMP
)) {
1692 timestampFound
= true;
1693 if (inputData
.format
.length() == 0) {
1694 errors
.append("Enter the input format for the Time Stamp (Line " + name
+ " Group " + (i
+ 1) + "). "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
1695 if (group
!= null) {
1696 group
.tagText
.setBackground(COLOR_LIGHT_RED
);
1700 new TmfTimestampFormat(inputData
.format
);
1701 if (group
!= null) {
1702 group
.tagText
.setBackground(COLOR_TEXT_BACKGROUND
);
1704 } catch (IllegalArgumentException e
) {
1705 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$
1706 if (group
!= null) {
1707 group
.tagText
.setBackground(COLOR_LIGHT_RED
);
1711 } else if (inputData
.tag
.equals(Tag
.OTHER
)) {
1712 if (inputData
.name
.isEmpty()) {
1713 errors
.append("Enter a name for the data group (Line " + name
+ " Group " + (i
+ 1) + "). "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
1714 if (group
!= null) {
1715 group
.tagText
.setBackground(COLOR_LIGHT_RED
);
1717 } else if (Tag
.fromLabel(inputData
.name
) != null) {
1718 errors
.append("Cannot use reserved name for the data group (Line " + name
+ " Group " + (i
+ 1) + "). "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
1719 if (group
!= null) {
1720 group
.tagText
.setBackground(COLOR_LIGHT_RED
);
1723 if (group
!= null) {
1724 group
.tagText
.setBackground(COLOR_TEXT_BACKGROUND
);
1728 if (group
!= null) {
1729 group
.tagText
.setBackground(COLOR_TEXT_BACKGROUND
);
1733 for (int i
= 0; inputLine
.childrenInputs
!= null && i
< inputLine
.childrenInputs
.size(); i
++) {
1734 errors
.append(validateLine(inputLine
.childrenInputs
.get(i
), name
+ "." + (i
+ 1))); //$NON-NLS-1$
1740 * Get the trace definition.
1742 * @return The trace definition
1744 public CustomTxtTraceDefinition
getDefinition() {
1749 * Get the raw text of the input.
1751 * @return The raw input text
1753 public char[] getInputText() {
1754 return inputText
.getText().toCharArray();