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
);
128 private final ISelection selection
;
129 private CustomTxtTraceDefinition definition
;
130 private String editCategoryName
;
131 private String editDefinitionName
;
132 private String defaultDescription
;
133 private Line selectedLine
;
134 private Composite container
;
135 private Text categoryText
;
136 private Text logtypeText
;
137 private Text timestampOutputFormatText
;
138 private Text timestampPreviewText
;
139 private ScrolledComposite lineScrolledComposite
;
140 private TreeViewer treeViewer
;
141 private Composite lineContainer
;
142 private StyledText inputText
;
143 private Font fixedFont
;
144 private UpdateListener updateListener
;
145 private Browser helpBrowser
;
147 // variables used recursively through line traversal
148 private String timeStampFormat
;
149 private boolean timestampFound
;
155 * The Selection object
157 * The trace definition
159 protected CustomTxtParserInputWizardPage(ISelection selection
,
160 CustomTxtTraceDefinition definition
) {
161 super("CustomParserWizardPage"); //$NON-NLS-1$
162 if (definition
== null) {
163 setTitle(Messages
.CustomTxtParserInputWizardPage_titleNew
);
164 defaultDescription
= Messages
.CustomTxtParserInputWizardPage_descriptionNew
;
166 setTitle(Messages
.CustomTxtParserInputWizardPage_titleEdit
);
167 defaultDescription
= Messages
.CustomTxtParserInputWizardPage_desccriptionEdit
;
169 setDescription(defaultDescription
);
170 this.selection
= selection
;
171 this.definition
= definition
;
172 if (definition
!= null) {
173 this.editCategoryName
= definition
.categoryName
;
174 this.editDefinitionName
= definition
.definitionName
;
179 public void createControl(Composite parent
) {
180 container
= new Composite(parent
, SWT
.NULL
);
181 container
.setLayout(new GridLayout());
183 updateListener
= new UpdateListener();
185 Composite headerComposite
= new Composite(container
, SWT
.FILL
);
186 GridLayout headerLayout
= new GridLayout(5, false);
187 headerLayout
.marginHeight
= 0;
188 headerLayout
.marginWidth
= 0;
189 headerComposite
.setLayout(headerLayout
);
190 headerComposite
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
192 Label categoryLabel
= new Label(headerComposite
, SWT
.NULL
);
193 categoryLabel
.setText(Messages
.CustomTxtParserInputWizardPage_category
);
195 categoryText
= new Text(headerComposite
, SWT
.BORDER
| SWT
.SINGLE
);
196 categoryText
.setLayoutData(new GridData(120, SWT
.DEFAULT
));
198 Label timestampFormatLabel
= new Label(headerComposite
, SWT
.NULL
);
199 timestampFormatLabel
.setText(Messages
.CustomTxtParserInputWizardPage_timestampFormat
);
201 timestampOutputFormatText
= new Text(headerComposite
, SWT
.BORDER
| SWT
.SINGLE
);
202 timestampOutputFormatText
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
203 timestampOutputFormatText
.setText(DEFAULT_TIMESTAMP_FORMAT
);
205 Button timeStampFormatHelpButton
= new Button(headerComposite
, SWT
.PUSH
);
206 timeStampFormatHelpButton
.setImage(HELP_IMAGE
);
207 timeStampFormatHelpButton
.setToolTipText(Messages
.CustomTxtParserInputWizardPage_timestampFormatHelp
);
208 timeStampFormatHelpButton
.addSelectionListener(new SelectionAdapter() {
210 public void widgetSelected(SelectionEvent e
) {
211 Bundle plugin
= Platform
.getBundle(TIMESTAMP_FORMAT_BUNDLE
);
212 IPath path
= new Path(TIMESTAMP_FORMAT_PATH
);
213 URL fileURL
= FileLocator
.find(plugin
, path
, null);
215 URL pageURL
= FileLocator
.toFileURL(fileURL
);
216 openHelpShell(pageURL
.toString());
217 } catch (IOException e1
) {
222 Label logtypeLabel
= new Label(headerComposite
, SWT
.NULL
);
223 logtypeLabel
.setText(Messages
.CustomTxtParserInputWizardPage_logType
);
225 logtypeText
= new Text(headerComposite
, SWT
.BORDER
| SWT
.SINGLE
);
226 logtypeText
.setLayoutData(new GridData(120, SWT
.DEFAULT
));
227 logtypeText
.setFocus();
229 Label timestampPreviewLabel
= new Label(headerComposite
, SWT
.NULL
);
230 timestampPreviewLabel
.setText(Messages
.CustomTxtParserInputWizardPage_preview
);
232 timestampPreviewText
= new Text(headerComposite
, SWT
.BORDER
| SWT
.SINGLE
| SWT
.READ_ONLY
);
233 timestampPreviewText
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false, 2, 1));
234 timestampPreviewText
.setText(Messages
.CustomTxtParserInputWizardPage_noMatchingTimestamp
);
236 Composite buttonBar
= new Composite(container
, SWT
.NONE
);
237 GridLayout buttonBarLayout
= new GridLayout(5, false);
238 buttonBarLayout
.marginHeight
= 0;
239 buttonBarLayout
.marginWidth
= 0;
240 buttonBar
.setLayout(buttonBarLayout
);
242 Button removeButton
= new Button(buttonBar
, SWT
.PUSH
);
243 removeButton
.setImage(DELETE_IMAGE
);
244 removeButton
.setToolTipText(Messages
.CustomTxtParserInputWizardPage_removeLine
);
245 removeButton
.addSelectionListener(new SelectionAdapter() {
247 public void widgetSelected(SelectionEvent e
) {
248 if (treeViewer
.getSelection().isEmpty() || selectedLine
== null) {
252 InputLine inputLine
= (InputLine
) ((IStructuredSelection
) treeViewer
.getSelection()).getFirstElement();
253 if (inputLine
.parentInput
== null) {
254 definition
.inputs
.remove(inputLine
);
256 inputLine
.parentInput
.childrenInputs
.remove(inputLine
);
258 treeViewer
.refresh();
263 Button addNextButton
= new Button(buttonBar
, SWT
.PUSH
);
264 addNextButton
.setImage(ADD_NEXT_IMAGE
);
265 addNextButton
.setToolTipText(Messages
.CustomTxtParserInputWizardPage_addNextLine
);
266 addNextButton
.addSelectionListener(new SelectionAdapter() {
268 public void widgetSelected(SelectionEvent e
) {
269 InputLine inputLine
= new InputLine(Cardinality
.ZERO_OR_MORE
, "", null); //$NON-NLS-1$
270 if (((List
<?
>) treeViewer
.getInput()).size() == 0) {
271 definition
.inputs
.add(inputLine
);
272 } else if (treeViewer
.getSelection().isEmpty()) {
275 InputLine previousInputLine
= (InputLine
) ((IStructuredSelection
) treeViewer
.getSelection()).getFirstElement();
276 if (previousInputLine
.parentInput
== null) {
277 for (int i
= 0; i
< definition
.inputs
.size(); i
++) {
278 if (definition
.inputs
.get(i
).equals(previousInputLine
)) {
279 definition
.inputs
.add(i
+ 1, inputLine
);
283 previousInputLine
.addNext(inputLine
);
286 treeViewer
.refresh();
287 treeViewer
.setSelection(new StructuredSelection(inputLine
), true);
290 Button addChildButton
= new Button(buttonBar
, SWT
.PUSH
);
291 addChildButton
.setImage(ADD_CHILD_IMAGE
);
292 addChildButton
.setToolTipText(Messages
.CustomTxtParserInputWizardPage_addChildLine
);
293 addChildButton
.addSelectionListener(new SelectionAdapter() {
295 public void widgetSelected(SelectionEvent e
) {
296 InputLine inputLine
= new InputLine(Cardinality
.ZERO_OR_MORE
, "", null); //$NON-NLS-1$
297 if (((List
<?
>) treeViewer
.getInput()).size() == 0) {
298 definition
.inputs
.add(inputLine
);
299 } else if (treeViewer
.getSelection().isEmpty()) {
302 InputLine parentInputLine
= (InputLine
) ((IStructuredSelection
) treeViewer
.getSelection()).getFirstElement();
303 parentInputLine
.addChild(inputLine
);
305 treeViewer
.refresh();
306 treeViewer
.setSelection(new StructuredSelection(inputLine
), true);
309 Button moveUpButton
= new Button(buttonBar
, SWT
.PUSH
);
310 moveUpButton
.setImage(MOVE_UP_IMAGE
);
311 moveUpButton
.setToolTipText(Messages
.CustomTxtParserInputWizardPage_moveUp
);
312 moveUpButton
.addSelectionListener(new SelectionAdapter() {
314 public void widgetSelected(SelectionEvent e
) {
315 if (treeViewer
.getSelection().isEmpty()) {
318 InputLine inputLine
= (InputLine
) ((IStructuredSelection
) treeViewer
.getSelection()).getFirstElement();
319 if (inputLine
.parentInput
== null) {
320 for (int i
= 1; i
< definition
.inputs
.size(); i
++) {
321 if (definition
.inputs
.get(i
).equals(inputLine
)) {
322 definition
.inputs
.add(i
- 1, definition
.inputs
.remove(i
));
329 treeViewer
.refresh();
334 Button moveDownButton
= new Button(buttonBar
, SWT
.PUSH
);
335 moveDownButton
.setImage(MOVE_DOWN_IMAGE
);
336 moveDownButton
.setToolTipText(Messages
.CustomTxtParserInputWizardPage_moveDown
);
337 moveDownButton
.addSelectionListener(new SelectionAdapter() {
339 public void widgetSelected(SelectionEvent e
) {
340 if (treeViewer
.getSelection().isEmpty()) {
343 InputLine inputLine
= (InputLine
) ((IStructuredSelection
) treeViewer
.getSelection()).getFirstElement();
344 if (inputLine
.parentInput
== null) {
345 for (int i
= 0; i
< definition
.inputs
.size() - 1; i
++) {
346 if (definition
.inputs
.get(i
).equals(inputLine
)) {
347 definition
.inputs
.add(i
+ 1, definition
.inputs
.remove(i
));
352 inputLine
.moveDown();
354 treeViewer
.refresh();
360 SashForm vSash
= new SashForm(container
, SWT
.VERTICAL
);
361 vSash
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
362 vSash
.setBackground(vSash
.getDisplay().getSystemColor(SWT
.COLOR_GRAY
));
364 SashForm hSash
= new SashForm(vSash
, SWT
.HORIZONTAL
);
365 hSash
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
367 ScrolledComposite treeScrolledComposite
= new ScrolledComposite(hSash
, SWT
.V_SCROLL
| SWT
.H_SCROLL
);
368 GridData gd
= new GridData(SWT
.FILL
, SWT
.FILL
, true, true);
371 treeScrolledComposite
.setLayoutData(gd
);
372 Composite treeContainer
= new Composite(treeScrolledComposite
, SWT
.NONE
);
373 treeContainer
.setLayout(new FillLayout());
374 treeScrolledComposite
.setContent(treeContainer
);
375 treeScrolledComposite
.setExpandHorizontal(true);
376 treeScrolledComposite
.setExpandVertical(true);
378 treeViewer
= new TreeViewer(treeContainer
, SWT
.SINGLE
| SWT
.BORDER
);
379 treeViewer
.setContentProvider(new InputLineTreeNodeContentProvider());
380 treeViewer
.setLabelProvider(new InputLineTreeLabelProvider());
381 treeViewer
.addSelectionChangedListener(new InputLineTreeSelectionChangedListener());
382 treeContainer
.layout();
384 treeScrolledComposite
.setMinSize(treeContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).x
, treeContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).y
);
386 lineScrolledComposite
= new ScrolledComposite(hSash
, SWT
.V_SCROLL
);
387 lineScrolledComposite
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
388 lineContainer
= new Composite(lineScrolledComposite
, SWT
.NONE
);
389 GridLayout linesLayout
= new GridLayout();
390 linesLayout
.marginHeight
= 1;
391 linesLayout
.marginWidth
= 0;
392 lineContainer
.setLayout(linesLayout
);
393 lineScrolledComposite
.setContent(lineContainer
);
394 lineScrolledComposite
.setExpandHorizontal(true);
395 lineScrolledComposite
.setExpandVertical(true);
397 if (definition
== null) {
398 definition
= new CustomTxtTraceDefinition();
399 definition
.inputs
.add(new InputLine(Cardinality
.ZERO_OR_MORE
, DEFAULT_REGEX
,
400 Arrays
.asList(new InputData(Tag
.MESSAGE
, CustomTraceDefinition
.ACTION_SET
))));
402 loadDefinition(definition
);
403 treeViewer
.expandAll();
404 lineContainer
.layout();
406 categoryText
.addModifyListener(updateListener
);
407 logtypeText
.addModifyListener(updateListener
);
408 timestampOutputFormatText
.addModifyListener(updateListener
);
410 lineScrolledComposite
.setMinSize(lineContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).x
, lineContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).y
- 1);
412 hSash
.setWeights(new int[] { 1, 2 });
414 Composite sashBottom
= new Composite(vSash
, SWT
.NONE
);
415 GridLayout sashBottomLayout
= new GridLayout(3, false);
416 sashBottomLayout
.marginHeight
= 0;
417 sashBottomLayout
.marginWidth
= 0;
418 sashBottom
.setLayout(sashBottomLayout
);
420 Label previewLabel
= new Label(sashBottom
, SWT
.NULL
);
421 previewLabel
.setText(Messages
.CustomTxtParserInputWizardPage_previewInput
);
422 previewLabel
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
424 Button highlightAllButton
= new Button(sashBottom
, SWT
.PUSH
);
425 highlightAllButton
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
426 highlightAllButton
.setText(Messages
.CustomTxtParserInputWizardPage_highlightAll
);
427 highlightAllButton
.addSelectionListener(new SelectionAdapter() {
429 public void widgetSelected(SelectionEvent e
) {
430 updatePreviews(true);
434 Button legendButton
= new Button(sashBottom
, SWT
.PUSH
);
435 legendButton
.setImage(HELP_IMAGE
);
436 legendButton
.setToolTipText(Messages
.CustomTxtParserInputWizardPage_previewLegend
);
437 legendButton
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
438 legendButton
.addSelectionListener(new SelectionAdapter() {
440 public void widgetSelected(SelectionEvent e
) {
445 inputText
= new StyledText(sashBottom
, SWT
.MULTI
| SWT
.V_SCROLL
| SWT
.H_SCROLL
);
446 if (fixedFont
== null) {
447 if (System
.getProperty("os.name").contains("Windows")) { //$NON-NLS-1$ //$NON-NLS-2$
448 fixedFont
= new Font(Display
.getCurrent(), new FontData("Courier New", 10, SWT
.NORMAL
)); //$NON-NLS-1$
450 fixedFont
= new Font(Display
.getCurrent(), new FontData("Monospace", 10, SWT
.NORMAL
)); //$NON-NLS-1$
453 inputText
.setFont(fixedFont
);
454 gd
= new GridData(SWT
.FILL
, SWT
.FILL
, true, true, 3, 1);
455 gd
.heightHint
= inputText
.computeSize(SWT
.DEFAULT
, inputText
.getLineHeight() * 4).y
;
457 inputText
.setLayoutData(gd
);
458 inputText
.setText(getSelectionText());
459 inputText
.addModifyListener(updateListener
);
461 vSash
.setWeights(new int[] { hSash
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).y
, sashBottom
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).y
});
463 setControl(container
);
469 private static class InputLineTreeNodeContentProvider
implements ITreeContentProvider
{
472 public Object
[] getElements(Object inputElement
) {
473 return ((List
<?
>) inputElement
).toArray();
477 public Object
[] getChildren(Object parentElement
) {
478 InputLine inputLine
= (InputLine
) parentElement
;
479 if (inputLine
.childrenInputs
== null) {
480 return new InputLine
[0];
482 return inputLine
.childrenInputs
.toArray();
486 public boolean hasChildren(Object element
) {
487 InputLine inputLine
= (InputLine
) element
;
488 return (inputLine
.childrenInputs
!= null && inputLine
.childrenInputs
.size() > 0);
492 public void dispose() {
496 public void inputChanged(Viewer viewer
, Object oldInput
, Object newInput
) {
500 public Object
getParent(Object element
) {
501 InputLine inputLine
= (InputLine
) element
;
502 return inputLine
.parentInput
;
506 private class InputLineTreeLabelProvider
extends ColumnLabelProvider
{
509 public Image
getImage(Object element
) {
514 public String
getText(Object element
) {
515 InputLine inputLine
= (InputLine
) element
;
516 if (inputLine
.parentInput
== null) {
517 return "Root Line " + getName(inputLine
) + " " + inputLine
.cardinality
.toString() + " : " + inputLine
.getRegex(); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
519 return "Line " + getName(inputLine
) + " " + inputLine
.cardinality
.toString() + " : " + inputLine
.getRegex(); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
523 private class InputLineTreeSelectionChangedListener
implements ISelectionChangedListener
{
525 public void selectionChanged(SelectionChangedEvent event
) {
526 if (selectedLine
!= null) {
527 selectedLine
.dispose();
529 if (!(event
.getSelection().isEmpty()) && event
.getSelection() instanceof IStructuredSelection
) {
530 IStructuredSelection sel
= (IStructuredSelection
) event
.getSelection();
531 InputLine inputLine
= (InputLine
) sel
.getFirstElement();
532 selectedLine
= new Line(lineContainer
, getName(inputLine
), inputLine
);
533 lineContainer
.layout();
534 lineScrolledComposite
.setMinSize(lineContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).x
, lineContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).y
- 1);
543 public void dispose() {
544 if (fixedFont
!= null) {
551 private void loadDefinition(CustomTxtTraceDefinition def
) {
552 categoryText
.setText(def
.categoryName
);
553 logtypeText
.setText(def
.definitionName
);
554 timestampOutputFormatText
.setText(def
.timeStampOutputFormat
);
555 treeViewer
.setInput(def
.inputs
);
556 if (def
.inputs
.size() > 0) {
557 InputLine inputLine
= def
.inputs
.get(0);
558 treeViewer
.setSelection(new StructuredSelection(inputLine
));
562 private String
getName(InputLine inputLine
) {
563 if (inputLine
.parentInput
== null) {
564 return Integer
.toString(definition
.inputs
.indexOf(inputLine
) + 1);
566 return getName(inputLine
.parentInput
) + "." + Integer
.toString(inputLine
.parentInput
.childrenInputs
.indexOf(inputLine
) + 1); //$NON-NLS-1$
570 * Get the global list of inputs.
572 * @return The list of inputs
574 public List
<Entry
<Tag
, String
>> getInputs() {
575 List
<Entry
<Tag
, String
>> inputs
= new ArrayList
<>();
576 for (InputLine inputLine
: definition
.inputs
) {
577 for (Entry
<Tag
, String
> input
: getInputs(inputLine
)) {
578 if (!inputs
.contains(input
)) {
587 * Get the list of inputs for the given input line, recursively.
591 * @return The list of inputs
593 private List
<Entry
<Tag
, String
>> getInputs(InputLine inputLine
) {
594 List
<Entry
<Tag
, String
>> inputs
= new ArrayList
<>();
595 if (inputLine
.columns
!= null) {
596 for (InputData inputData
: inputLine
.columns
) {
597 Entry
<Tag
, String
> input
= new SimpleEntry
<>(inputData
.tag
, inputData
.name
);
598 if (!inputs
.contains(input
)) {
603 if (inputLine
.childrenInputs
!= null) {
604 for (InputLine childInputLine
: inputLine
.childrenInputs
) {
605 for (Entry
<Tag
, String
> input
: getInputs(childInputLine
)) {
606 if (!inputs
.contains(input
)) {
615 private void removeLine() {
616 selectedLine
.dispose();
618 lineContainer
.layout();
619 lineScrolledComposite
.setMinSize(lineContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).x
, lineContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).y
- 1);
623 private String
getSelectionText() {
624 if (this.selection
instanceof IStructuredSelection
) {
625 Object sel
= ((IStructuredSelection
) this.selection
).getFirstElement();
626 if (sel
instanceof IFile
) {
627 IFile file
= (IFile
) sel
;
628 BufferedReader reader
= null;
630 reader
= new BufferedReader(new InputStreamReader(file
.getContents()));
631 StringBuilder sb
= new StringBuilder();
633 while ((line
= reader
.readLine()) != null) {
637 return sb
.toString();
638 } catch (CoreException e
) {
639 return ""; //$NON-NLS-1$
640 } catch (IOException e
) {
641 return ""; //$NON-NLS-1$
643 if (reader
!= null) {
646 } catch (IOException e
) {
652 return ""; //$NON-NLS-1$
655 private void updatePreviews() {
656 updatePreviews(false);
659 private void updatePreviews(boolean updateAll
) {
660 if (inputText
== null) {
661 // early update during construction
664 inputText
.setStyleRanges(new StyleRange
[] {});
666 try (Scanner scanner
= new Scanner(inputText
.getText());) {
667 scanner
.useDelimiter("\n"); //$NON-NLS-1$
670 // skip starting delimiters
671 String skip
= scanner
.findWithinHorizon("\\A\n+", 0); //$NON-NLS-1$
673 rawPos
+= skip
.length();
676 timeStampFormat
= null;
677 if (selectedLine
!= null) {
678 for (InputGroup input
: selectedLine
.inputs
) {
679 input
.previewText
.setText(Messages
.CustomTxtParserInputWizardPage_noMathcingLine
);
683 Map
<Object
, String
> data
= new HashMap
<>();
684 int rootLineMatches
= 0;
685 String firstEntryTimeStamp
= null;
686 String firstEntryTimeStampInputFormat
= null;
688 boolean lineIsNull
= true; // needed because of JDT bug with continue at label
689 event
: while (scanner
.hasNext() || !lineIsNull
) {
690 if (rootLineMatches
> 0 && !updateAll
) {
694 line
= scanner
.next();
697 int length
= line
.length();
698 String log
= line
.replaceAll("\r", ""); //$NON-NLS-1$ //$NON-NLS-2$
699 for (InputLine rootInputLine
: definition
.inputs
) {
702 pattern
= rootInputLine
.getPattern();
703 } catch (PatternSyntaxException e
) {
706 Matcher matcher
= pattern
.matcher(log
);
707 if (matcher
.matches()) {
709 inputText
.setStyleRange(new StyleRange(rawPos
, length
,
710 COLOR_BLACK
, COLOR_YELLOW
, SWT
.ITALIC
));
711 data
= new HashMap
<>();
712 timeStampFormat
= null;
713 updatePreviewLine(rootInputLine
, matcher
, data
, rawPos
, rootLineMatches
);
714 if (rootLineMatches
== 1) {
715 firstEntryTimeStamp
= data
.get(Tag
.TIMESTAMP
);
716 firstEntryTimeStampInputFormat
= timeStampFormat
;
718 HashMap
<InputLine
, Integer
> countMap
= new HashMap
<>();
719 InputLine currentInput
= null;
720 if (rootInputLine
.childrenInputs
!= null && rootInputLine
.childrenInputs
.size() > 0) {
721 currentInput
= rootInputLine
.childrenInputs
.get(0);
722 countMap
.put(currentInput
, 0);
724 rawPos
+= length
+ 1; // +1 for \n
725 while (scanner
.hasNext()) {
726 line
= scanner
.next();
727 length
= line
.length();
728 log
= line
.replaceAll("\r", ""); //$NON-NLS-1$ //$NON-NLS-2$
729 boolean processed
= false;
730 if (currentInput
== null) {
731 for (InputLine input
: definition
.inputs
) {
733 matcher
= input
.getPattern().matcher(log
);
734 } catch (PatternSyntaxException e
) {
737 if (matcher
.matches()) {
742 if (checkNotNull(countMap
.get(currentInput
)) >= currentInput
.getMinCount()) {
743 List
<InputLine
> nextInputs
= currentInput
.getNextInputs(countMap
);
744 if (nextInputs
.size() == 0 || nextInputs
.get(nextInputs
.size() - 1).getMinCount() == 0) {
745 for (InputLine input
: definition
.inputs
) {
747 matcher
= input
.getPattern().matcher(log
);
748 } catch (PatternSyntaxException e
) {
751 if (matcher
.matches()) {
756 for (InputLine input
: nextInputs
) {
758 matcher
= input
.getPattern().matcher(log
);
759 } catch (PatternSyntaxException e
) {
762 if (matcher
.matches()) {
763 inputText
.setStyleRange(new StyleRange(rawPos
, length
,
764 COLOR_BLACK
, COLOR_LIGHT_YELLOW
, SWT
.ITALIC
));
765 currentInput
= input
;
766 updatePreviewLine(currentInput
, matcher
, data
, rawPos
, rootLineMatches
);
767 if (countMap
.get(currentInput
) == null) {
768 countMap
.put(currentInput
, 1);
770 countMap
.put(currentInput
, checkNotNull(countMap
.get(currentInput
)) + 1);
772 Iterator
<InputLine
> iter
= countMap
.keySet().iterator();
773 while (iter
.hasNext()) {
774 InputLine inputLine
= iter
.next();
775 if (inputLine
.level
> currentInput
.level
) {
779 if (currentInput
.childrenInputs
!= null && currentInput
.childrenInputs
.size() > 0) {
780 currentInput
= currentInput
.childrenInputs
.get(0);
781 countMap
.put(currentInput
, 0);
783 if (checkNotNull(countMap
.get(currentInput
)) >= currentInput
.getMaxCount()) {
784 if (currentInput
.getNextInputs(countMap
).size() > 0) {
785 currentInput
= currentInput
.getNextInputs(countMap
).get(0);
786 if (countMap
.get(currentInput
) == null) {
787 countMap
.put(currentInput
, 0);
789 iter
= countMap
.keySet().iterator();
790 while (iter
.hasNext()) {
791 InputLine inputLine
= iter
.next();
792 if (inputLine
.level
> currentInput
.level
) {
806 if (!processed
&& currentInput
!= null) {
809 matcher
= currentInput
.getPattern().matcher(log
);
810 } catch (PatternSyntaxException e
) {
812 if (matcher
!= null && matcher
.matches()) {
813 inputText
.setStyleRange(new StyleRange(rawPos
, length
,
814 COLOR_BLACK
, COLOR_LIGHT_YELLOW
, SWT
.ITALIC
));
815 updatePreviewLine(currentInput
, matcher
, data
, rawPos
, rootLineMatches
);
816 countMap
.put(currentInput
, checkNotNull(countMap
.get(currentInput
)) + 1);
817 if (currentInput
.childrenInputs
!= null && currentInput
.childrenInputs
.size() > 0) {
818 currentInput
= currentInput
.childrenInputs
.get(0);
819 countMap
.put(currentInput
, 0);
821 if (checkNotNull(countMap
.get(currentInput
)) >= currentInput
.getMaxCount()) {
822 if (currentInput
.getNextInputs(countMap
).size() > 0) {
823 currentInput
= currentInput
.getNextInputs(countMap
).get(0);
824 if (countMap
.get(currentInput
) == null) {
825 countMap
.put(currentInput
, 0);
827 Iterator
<InputLine
> iter
= countMap
.keySet().iterator();
828 while (iter
.hasNext()) {
829 InputLine inputLine
= iter
.next();
830 if (inputLine
.level
> currentInput
.level
) {
842 rawPos
+= length
+ 1; // +1 for \n
848 rawPos
+= length
+ 1; // +1 for \n
853 if (rootLineMatches
== 1) {
854 firstEntryTimeStamp
= data
.get(Tag
.TIMESTAMP
);
855 firstEntryTimeStampInputFormat
= timeStampFormat
;
857 if (firstEntryTimeStamp
== null) {
858 timestampPreviewText
.setText(Messages
.CustomTxtParserInputWizardPage_noTimestampGroup
);
859 if (selectedLine
!= null) {
860 for (InputGroup group
: selectedLine
.inputs
) {
861 if (group
.tagCombo
.getText().equals(Tag
.TIMESTAMP
.toString())) {
862 timestampPreviewText
.setText(Messages
.CustomTxtParserInputWizardPage_noMatchingTimestamp
);
869 TmfTimestampFormat timestampFormat
= new TmfTimestampFormat(firstEntryTimeStampInputFormat
);
870 long timestamp
= timestampFormat
.parseValue(firstEntryTimeStamp
);
871 timestampFormat
= new TmfTimestampFormat(timestampOutputFormatText
.getText().trim());
872 timestampPreviewText
.setText(timestampFormat
.format(timestamp
));
873 } catch (ParseException e
) {
874 timestampPreviewText
.setText("*parse exception* [" + firstEntryTimeStamp
+ "] <> [" + firstEntryTimeStampInputFormat
+ "]"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
875 } catch (IllegalArgumentException e
) {
876 timestampPreviewText
.setText("*parse exception* [Illegal Argument: " + e
.getMessage() + "]"); //$NON-NLS-1$ //$NON-NLS-2$
883 private void updatePreviewLine(InputLine line
, Matcher matcher
, Map
<Object
, String
> data
, int rawPos
, int rootLineMatches
) {
884 for (int i
= 0; i
< line
.columns
.size(); i
++) {
885 InputData input
= line
.columns
.get(i
);
886 if (i
< matcher
.groupCount() && matcher
.group(i
+ 1) != null) {
887 if (line
.parentInput
== null) {
888 inputText
.setStyleRange(new StyleRange(rawPos
+ matcher
.start(i
+ 1), matcher
.end(i
+ 1) - matcher
.start(i
+ 1),
889 COLOR_BLACK
, COLOR_GREEN
, SWT
.BOLD
));
891 inputText
.setStyleRange(new StyleRange(rawPos
+ matcher
.start(i
+ 1), matcher
.end(i
+ 1) - matcher
.start(i
+ 1),
892 COLOR_BLACK
, COLOR_LIGHT_GREEN
, SWT
.BOLD
));
894 String value
= matcher
.group(i
+ 1).trim();
895 if (selectedLine
!= null && selectedLine
.inputLine
.equals(line
) && rootLineMatches
== 1 &&
896 selectedLine
.inputs
.get(i
).previewText
.getText().equals(Messages
.CustomTxtParserInputWizardPage_noMatchingLine
)) {
897 selectedLine
.inputs
.get(i
).previewText
.setText(value
);
899 if (value
.length() == 0) {
902 Object key
= (input
.tag
.equals(Tag
.OTHER
) ? input
.name
: input
.tag
);
903 if (input
.action
== CustomTraceDefinition
.ACTION_SET
) {
904 data
.put(key
, value
);
905 if (input
.tag
.equals(Tag
.TIMESTAMP
)) {
906 timeStampFormat
= input
.format
;
908 } else if (input
.action
== CustomTraceDefinition
.ACTION_APPEND
) {
909 String s
= data
.get(key
);
911 data
.put(key
, s
+ value
);
913 data
.put(key
, value
);
915 if (input
.tag
.equals(Tag
.TIMESTAMP
)) {
916 if (timeStampFormat
!= null) {
917 timeStampFormat
+= input
.format
;
919 timeStampFormat
= input
.format
;
922 } else if (input
.action
== CustomTraceDefinition
.ACTION_APPEND_WITH_SEPARATOR
) {
923 String s
= data
.get(key
);
925 data
.put(key
, s
+ " | " + value
); //$NON-NLS-1$
927 data
.put(key
, value
);
929 if (input
.tag
.equals(Tag
.TIMESTAMP
)) {
930 if (timeStampFormat
!= null) {
931 timeStampFormat
+= " | " + input
.format
; //$NON-NLS-1$
933 timeStampFormat
= input
.format
;
938 if (selectedLine
!= null && selectedLine
.inputLine
.equals(line
) && rootLineMatches
== 1) {
939 if (selectedLine
.inputs
.get(i
).previewText
.getText().equals(Messages
.CustomTxtParserInputWizardPage_noMatchingLine
)) {
940 selectedLine
.inputs
.get(i
).previewText
.setText(Messages
.CustomTxtParserInputWizardPage_noMatchingGroup
);
945 // highlight the matching groups that have no corresponponding input
946 for (int i
= line
.columns
.size(); i
< matcher
.groupCount(); i
++) {
947 if (matcher
.group(i
+ 1) != null) {
948 if (line
.parentInput
== null) {
949 inputText
.setStyleRange(new StyleRange(rawPos
+ matcher
.start(i
+ 1), matcher
.end(i
+ 1) - matcher
.start(i
+ 1),
950 COLOR_BLACK
, COLOR_MAGENTA
));
952 inputText
.setStyleRange(new StyleRange(rawPos
+ matcher
.start(i
+ 1), matcher
.end(i
+ 1) - matcher
.start(i
+ 1),
953 COLOR_BLACK
, COLOR_LIGHT_MAGENTA
));
959 private void openHelpShell(String url
) {
960 if (helpBrowser
!= null && !helpBrowser
.isDisposed()) {
961 helpBrowser
.getShell().setActive();
962 if (!helpBrowser
.getUrl().equals(url
)) {
963 helpBrowser
.setUrl(url
);
967 final Shell helpShell
= new Shell(getShell(), SWT
.SHELL_TRIM
);
968 helpShell
.setLayout(new FillLayout());
969 helpBrowser
= new Browser(helpShell
, SWT
.NONE
);
970 helpBrowser
.addTitleListener(new TitleListener() {
972 public void changed(TitleEvent event
) {
973 helpShell
.setText(event
.title
);
976 Rectangle r
= container
.getBounds();
977 Point p
= container
.toDisplay(r
.x
, r
.y
);
978 Rectangle trim
= helpShell
.computeTrim(p
.x
+ (r
.width
- 750) / 2, p
.y
+ (r
.height
- 400) / 2, 750, 400);
979 helpShell
.setBounds(trim
);
981 helpBrowser
.setUrl(url
);
984 private void openLegend() {
985 final String cg
= Messages
.CustomTxtParserInputWizardPage_capturedGroup
;
986 final String ucg
= Messages
.CustomTxtParserInputWizardPage_unidentifiedCaptureGroup
;
987 final String ut
= Messages
.CustomTxtParserInputWizardPage_uncapturedText
;
989 String line1
= Messages
.CustomTxtParserInputWizardPage_nonMatchingLine
;
990 int line2start
= line1start
+ line1
.length();
991 String line2
= Messages
.CustomTxtParserInputWizardPage_matchingRootLine
+ ' ' + cg
+ ' ' + ucg
+ ' ' + ut
+ " \n"; //$NON-NLS-1$
992 int line3start
= line2start
+ line2
.length();
993 String line3
= Messages
.CustomTxtParserInputWizardPage_matchingOtherLine
+ ' ' + cg
+ ' ' + ucg
+ ' ' + ut
+ " \n"; //$NON-NLS-1$
994 int line4start
= line3start
+ line3
.length();
995 String line4
= Messages
.CustomTxtParserInputWizardPage_matchingOtherLine
+ ' ' + cg
+ ' ' + ucg
+ ' ' + ut
+ " \n"; //$NON-NLS-1$
996 int line5start
= line4start
+ line4
.length();
997 String line5
= Messages
.CustomTxtParserInputWizardPage_nonMatchingLine
;
998 int line6start
= line5start
+ line5
.length();
999 String line6
= Messages
.CustomTxtParserInputWizardPage_matchingRootLine
+ cg
+ ' ' + ucg
+ ' ' + ut
+ " \n"; //$NON-NLS-1$
1001 final Shell legendShell
= new Shell(getShell(), SWT
.DIALOG_TRIM
);
1002 legendShell
.setLayout(new FillLayout());
1003 StyledText legendText
= new StyledText(legendShell
, SWT
.MULTI
);
1004 legendText
.setFont(fixedFont
);
1005 legendText
.setText(line1
+ line2
+ line3
+ line4
+ line5
+ line6
);
1006 legendText
.setStyleRange(new StyleRange(line2start
, line2
.length(), COLOR_BLACK
, COLOR_YELLOW
, SWT
.ITALIC
));
1007 legendText
.setStyleRange(new StyleRange(line3start
, line3
.length(), COLOR_BLACK
, COLOR_LIGHT_YELLOW
, SWT
.ITALIC
));
1008 legendText
.setStyleRange(new StyleRange(line4start
, line4
.length(), COLOR_BLACK
, COLOR_LIGHT_YELLOW
, SWT
.ITALIC
));
1009 legendText
.setStyleRange(new StyleRange(line6start
, line6
.length(), COLOR_BLACK
, COLOR_YELLOW
, SWT
.ITALIC
));
1010 legendText
.setStyleRange(new StyleRange(line2start
+ line2
.indexOf(cg
), cg
.length(), COLOR_BLACK
, COLOR_GREEN
, SWT
.BOLD
));
1011 legendText
.setStyleRange(new StyleRange(line2start
+ line2
.indexOf(ucg
), ucg
.length(), COLOR_BLACK
, COLOR_MAGENTA
));
1012 legendText
.setStyleRange(new StyleRange(line3start
+ line3
.indexOf(cg
), cg
.length(), COLOR_BLACK
, COLOR_LIGHT_GREEN
, SWT
.BOLD
));
1013 legendText
.setStyleRange(new StyleRange(line3start
+ line3
.indexOf(ucg
), ucg
.length(), COLOR_BLACK
, COLOR_LIGHT_MAGENTA
));
1014 legendText
.setStyleRange(new StyleRange(line4start
+ line4
.indexOf(cg
), cg
.length(), COLOR_BLACK
, COLOR_LIGHT_GREEN
, SWT
.BOLD
));
1015 legendText
.setStyleRange(new StyleRange(line4start
+ line4
.indexOf(ucg
), ucg
.length(), COLOR_BLACK
, COLOR_LIGHT_MAGENTA
));
1016 legendText
.setStyleRange(new StyleRange(line6start
+ line6
.indexOf(cg
), cg
.length(), COLOR_BLACK
, COLOR_GREEN
, SWT
.BOLD
));
1017 legendText
.setStyleRange(new StyleRange(line6start
+ line6
.indexOf(ucg
), ucg
.length(), COLOR_BLACK
, COLOR_MAGENTA
));
1018 legendShell
.setText(Messages
.CustomTxtParserInputWizardPage_previewLegend
);
1023 private class UpdateListener
implements ModifyListener
, SelectionListener
{
1026 public void modifyText(ModifyEvent e
) {
1032 public void widgetDefaultSelected(SelectionEvent e
) {
1038 public void widgetSelected(SelectionEvent e
) {
1045 private class Line
{
1046 private static final String INFINITY_STRING
= "\u221E"; //$NON-NLS-1$
1047 private InputLine inputLine
;
1048 private Group group
;
1049 private Composite labelComposite
;
1050 private Text regexText
;
1051 private Composite cardinalityContainer
;
1052 private Combo cardinalityCombo
;
1053 private Label cardinalityMinLabel
;
1054 private Text cardinalityMinText
;
1055 private Label cardinalityMaxLabel
;
1056 private Text cardinalityMaxText
;
1057 private Button infiniteButton
;
1058 private Button eventTypeButton
;
1059 private Text eventTypeText
;
1060 private List
<InputGroup
> inputs
= new ArrayList
<>();
1061 private Button addGroupButton
;
1062 private Label addGroupLabel
;
1064 public Line(Composite parent
, String name
, InputLine inputLine
) {
1065 this.inputLine
= inputLine
;
1067 group
= new Group(parent
, SWT
.NONE
);
1068 group
.setText(name
);
1069 group
.setLayout(new GridLayout(2, false));
1070 group
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
1072 labelComposite
= new Composite(group
, SWT
.FILL
);
1073 GridLayout labelLayout
= new GridLayout(1, false);
1074 labelLayout
.marginWidth
= 0;
1075 labelLayout
.marginHeight
= 0;
1076 labelComposite
.setLayout(labelLayout
);
1077 labelComposite
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
1079 Label label
= new Label(labelComposite
, SWT
.NULL
);
1080 label
.setText(Messages
.CustomTxtParserInputWizardPage_regularExpression
);
1082 Composite regexContainer
= new Composite(group
, SWT
.NONE
);
1083 GridLayout regexLayout
= new GridLayout(2, false);
1084 regexLayout
.marginHeight
= 0;
1085 regexLayout
.marginWidth
= 0;
1086 regexContainer
.setLayout(regexLayout
);
1087 regexContainer
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
1089 regexText
= new Text(regexContainer
, SWT
.BORDER
| SWT
.SINGLE
);
1090 GridData gd
= new GridData(SWT
.FILL
, SWT
.CENTER
, true, false);
1092 regexText
.setLayoutData(gd
);
1093 regexText
.setText(inputLine
.getRegex());
1094 regexText
.addModifyListener(updateListener
);
1096 Button regexHelpButton
= new Button(regexContainer
, SWT
.PUSH
);
1097 regexHelpButton
.setImage(HELP_IMAGE
);
1098 regexHelpButton
.setToolTipText(Messages
.CustomTxtParserInputWizardPage_regularExpressionHelp
);
1099 regexHelpButton
.addSelectionListener(new SelectionAdapter() {
1101 public void widgetSelected(SelectionEvent e
) {
1102 openHelpShell(PATTERN_URL
);
1106 label
= new Label(group
, SWT
.NONE
);
1107 label
.setText(Messages
.CustomTxtParserInputWizardPage_cardinality
);
1108 label
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
1110 cardinalityContainer
= new Composite(group
, SWT
.NONE
);
1111 GridLayout cardinalityLayout
= new GridLayout(6, false);
1112 cardinalityLayout
.marginHeight
= 0;
1113 cardinalityLayout
.marginWidth
= 0;
1114 cardinalityContainer
.setLayout(cardinalityLayout
);
1115 cardinalityContainer
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
1117 cardinalityCombo
= new Combo(cardinalityContainer
, SWT
.DROP_DOWN
| SWT
.READ_ONLY
);
1118 cardinalityCombo
.setItems(new String
[] {
1119 Cardinality
.ZERO_OR_MORE
.toString(),
1120 Cardinality
.ONE_OR_MORE
.toString(),
1121 Cardinality
.ZERO_OR_ONE
.toString(),
1122 Cardinality
.ONE
.toString(), "(?,?)" }); //$NON-NLS-1$
1123 cardinalityCombo
.addSelectionListener(new SelectionListener() {
1125 public void widgetDefaultSelected(SelectionEvent e
) {
1129 public void widgetSelected(SelectionEvent e
) {
1130 switch (cardinalityCombo
.getSelectionIndex()) {
1132 cardinalityMinLabel
.setVisible(true);
1133 cardinalityMinText
.setVisible(true);
1134 cardinalityMaxLabel
.setVisible(true);
1135 cardinalityMaxText
.setVisible(true);
1136 infiniteButton
.setVisible(true);
1139 cardinalityMinLabel
.setVisible(false);
1140 cardinalityMinText
.setVisible(false);
1141 cardinalityMaxLabel
.setVisible(false);
1142 cardinalityMaxText
.setVisible(false);
1143 infiniteButton
.setVisible(false);
1146 cardinalityContainer
.layout();
1152 cardinalityMinLabel
= new Label(cardinalityContainer
, SWT
.NONE
);
1153 cardinalityMinLabel
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
1154 cardinalityMinLabel
.setText(Messages
.CustomTxtParserInputWizardPage_min
);
1155 cardinalityMinLabel
.setVisible(false);
1157 cardinalityMinText
= new Text(cardinalityContainer
, SWT
.BORDER
| SWT
.SINGLE
);
1158 gd
= new GridData(SWT
.CENTER
, SWT
.CENTER
, false, false);
1160 cardinalityMinText
.setLayoutData(gd
);
1161 cardinalityMinText
.setVisible(false);
1163 cardinalityMaxLabel
= new Label(cardinalityContainer
, SWT
.NONE
);
1164 cardinalityMaxLabel
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
1165 cardinalityMaxLabel
.setText(Messages
.CustomTxtParserInputWizardPage_max
);
1166 cardinalityMaxLabel
.setVisible(false);
1168 cardinalityMaxText
= new Text(cardinalityContainer
, SWT
.BORDER
| SWT
.SINGLE
);
1169 gd
= new GridData(SWT
.CENTER
, SWT
.CENTER
, false, false);
1171 cardinalityMaxText
.setLayoutData(gd
);
1172 cardinalityMaxText
.setVisible(false);
1174 infiniteButton
= new Button(cardinalityContainer
, SWT
.PUSH
);
1175 infiniteButton
.setText(INFINITY_STRING
);
1176 infiniteButton
.setVisible(false);
1177 infiniteButton
.addSelectionListener(new SelectionAdapter() {
1179 public void widgetSelected(SelectionEvent e
) {
1180 cardinalityMaxText
.setText(INFINITY_STRING
);
1184 if (inputLine
.cardinality
.equals(Cardinality
.ZERO_OR_MORE
)) {
1185 cardinalityCombo
.select(0);
1186 } else if (inputLine
.cardinality
.equals(Cardinality
.ONE_OR_MORE
)) {
1187 cardinalityCombo
.select(1);
1188 } else if (inputLine
.cardinality
.equals(Cardinality
.ZERO_OR_ONE
)) {
1189 cardinalityCombo
.select(2);
1190 } else if (inputLine
.cardinality
.equals(Cardinality
.ONE
)) {
1191 cardinalityCombo
.select(3);
1193 cardinalityCombo
.select(4);
1194 cardinalityMinLabel
.setVisible(true);
1195 cardinalityMinText
.setVisible(true);
1196 if (inputLine
.getMinCount() >= 0) {
1197 cardinalityMinText
.setText(Integer
.toString(inputLine
.getMinCount()));
1199 cardinalityMaxLabel
.setVisible(true);
1200 cardinalityMaxText
.setVisible(true);
1201 if (inputLine
.getMaxCount() == Cardinality
.INF
) {
1202 cardinalityMaxText
.setText(INFINITY_STRING
);
1203 } else if (inputLine
.getMaxCount() >= 0) {
1204 cardinalityMaxText
.setText(Integer
.toString(inputLine
.getMaxCount()));
1206 infiniteButton
.setVisible(true);
1209 VerifyListener digitsListener
= new VerifyListener() {
1211 public void verifyText(VerifyEvent e
) {
1212 if (e
.text
.equals(INFINITY_STRING
)) {
1213 e
.doit
= e
.widget
== cardinalityMaxText
&& e
.start
== 0 && e
.end
== ((Text
) e
.widget
).getText().length();
1215 if (((Text
) e
.widget
).getText().equals(INFINITY_STRING
)) {
1216 e
.doit
= e
.start
== 0 && e
.end
== ((Text
) e
.widget
).getText().length();
1218 for (int i
= 0; i
< e
.text
.length(); i
++) {
1219 if (!Character
.isDigit(e
.text
.charAt(i
))) {
1228 cardinalityMinText
.addModifyListener(updateListener
);
1229 cardinalityMaxText
.addModifyListener(updateListener
);
1230 cardinalityMinText
.addVerifyListener(digitsListener
);
1231 cardinalityMaxText
.addVerifyListener(digitsListener
);
1233 eventTypeButton
= new Button(group
, SWT
.CHECK
);
1234 eventTypeButton
.setText(Messages
.CustomTxtParserInputWizardPage_eventType
);
1235 eventTypeButton
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
1236 eventTypeButton
.addSelectionListener(new SelectionAdapter() {
1238 public void widgetSelected(SelectionEvent e
) {
1239 if (eventTypeButton
.getSelection()) {
1240 eventTypeText
.setEnabled(true);
1242 eventTypeText
.setEnabled(false);
1246 eventTypeButton
.addSelectionListener(updateListener
);
1248 eventTypeText
= new Text(group
, SWT
.BORDER
| SWT
.SINGLE
);
1249 gd
= new GridData(SWT
.FILL
, SWT
.CENTER
, true, false);
1251 eventTypeText
.setLayoutData(gd
);
1252 if (inputLine
.eventType
!= null) {
1253 eventTypeText
.setText(inputLine
.eventType
);
1254 eventTypeButton
.setSelection(true);
1256 eventTypeText
.setEnabled(false);
1257 eventTypeButton
.setSelection(false);
1259 eventTypeText
.addModifyListener(updateListener
);
1262 if (inputLine
.columns
!= null) {
1263 for (InputData inputData
: inputLine
.columns
) {
1264 InputGroup inputGroup
= new InputGroup(group
, this, inputs
.size() + 1);
1265 if (inputData
.tag
.equals(Tag
.TIMESTAMP
)) {
1266 inputGroup
.tagCombo
.select(0);
1267 inputGroup
.tagText
.setText(inputData
.format
);
1268 inputGroup
.tagLabel
.setText(Messages
.CustomTxtParserInputWizardPage_format
);
1269 inputGroup
.tagLabel
.setVisible(true);
1270 inputGroup
.tagText
.setVisible(true);
1271 inputGroup
.tagText
.addModifyListener(updateListener
);
1272 } else if (inputData
.tag
.equals(Tag
.EVENT_TYPE
)) {
1273 inputGroup
.tagCombo
.select(1);
1274 } else if (inputData
.tag
.equals(Tag
.MESSAGE
)) {
1275 inputGroup
.tagCombo
.select(2);
1277 inputGroup
.tagCombo
.select(3);
1278 inputGroup
.tagText
.setText(inputData
.name
);
1279 inputGroup
.tagLabel
.setText(Messages
.CustomTxtParserInputWizardPage_name
);
1280 inputGroup
.tagLabel
.setVisible(true);
1281 inputGroup
.tagText
.setVisible(true);
1282 inputGroup
.tagText
.addModifyListener(updateListener
);
1284 inputGroup
.actionCombo
.select(inputData
.action
);
1285 inputs
.add(inputGroup
);
1289 createAddGroupButton();
1292 private void createAddGroupButton() {
1293 addGroupButton
= new Button(group
, SWT
.PUSH
);
1294 addGroupButton
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
1295 addGroupButton
.setImage(ADD_IMAGE
);
1296 addGroupButton
.setToolTipText(Messages
.CustomTxtParserInputWizardPage_addGroup
);
1297 addGroupButton
.addSelectionListener(new SelectionAdapter() {
1299 public void widgetSelected(SelectionEvent e
) {
1300 removeAddGroupButton();
1301 inputs
.add(new InputGroup(group
, Line
.this, inputs
.size() + 1));
1302 createAddGroupButton();
1303 lineContainer
.layout();
1304 lineScrolledComposite
.setMinSize(lineContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).x
, lineContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).y
- 1);
1305 group
.getParent().layout();
1311 addGroupLabel
= new Label(group
, SWT
.NULL
);
1312 addGroupLabel
.setText(Messages
.CustomTxtParserInputWizardPage_newGroup
);
1315 private void removeAddGroupButton() {
1316 addGroupButton
.dispose();
1317 addGroupLabel
.dispose();
1320 private void removeInput(int inputNumber
) {
1321 int nb
= inputNumber
;
1322 if (--nb
< inputs
.size()) {
1323 inputs
.remove(nb
).dispose();
1324 for (int i
= nb
; i
< inputs
.size(); i
++) {
1325 inputs
.get(i
).setInputNumber(i
+ 1);
1327 lineContainer
.layout();
1328 lineScrolledComposite
.setMinSize(lineContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).x
, lineContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).y
- 1);
1329 group
.getParent().layout();
1333 private void dispose() {
1337 private void extractInputs() {
1338 inputLine
.setRegex(selectedLine
.regexText
.getText());
1339 inputLine
.eventType
= selectedLine
.eventTypeButton
.getSelection() ? selectedLine
.eventTypeText
.getText().trim() : null;
1340 switch (cardinalityCombo
.getSelectionIndex()) {
1342 inputLine
.cardinality
= Cardinality
.ZERO_OR_MORE
;
1345 inputLine
.cardinality
= Cardinality
.ONE_OR_MORE
;
1348 inputLine
.cardinality
= Cardinality
.ZERO_OR_ONE
;
1351 inputLine
.cardinality
= Cardinality
.ONE
;
1357 min
= Integer
.parseInt(cardinalityMinText
.getText());
1358 } catch (NumberFormatException e
) {
1362 if (cardinalityMaxText
.getText().equals(INFINITY_STRING
)) {
1363 max
= Cardinality
.INF
;
1365 max
= Integer
.parseInt(cardinalityMaxText
.getText());
1367 } catch (NumberFormatException e
) {
1370 inputLine
.cardinality
= new Cardinality(min
, max
);
1373 inputLine
.cardinality
= Cardinality
.ZERO_OR_MORE
;
1376 inputLine
.columns
= new ArrayList
<>(inputs
.size());
1377 for (int i
= 0; i
< inputs
.size(); i
++) {
1378 InputGroup grp
= inputs
.get(i
);
1379 InputData inputData
= new InputData();
1380 inputData
.tag
= Tag
.fromLabel(grp
.tagCombo
.getText());
1381 if (inputData
.tag
.equals(Tag
.OTHER
)) {
1382 inputData
.name
= grp
.tagText
.getText().trim();
1384 inputData
.name
= inputData
.tag
.toString();
1385 if (inputData
.tag
.equals(Tag
.TIMESTAMP
)) {
1386 inputData
.format
= grp
.tagText
.getText().trim();
1389 inputData
.action
= grp
.actionCombo
.getSelectionIndex();
1390 inputLine
.columns
.add(inputData
);
1395 private class InputGroup
{
1397 private int inputNumber
;
1399 // children of parent (must be disposed)
1400 private Composite labelComposite
;
1401 private Composite tagComposite
;
1402 private Label previewLabel
;
1403 private Text previewText
;
1405 // children of labelComposite
1406 private Label inputLabel
;
1408 // children of tagComposite
1409 private Combo tagCombo
;
1410 private Label tagLabel
;
1411 private Text tagText
;
1412 private Combo actionCombo
;
1414 public InputGroup(Composite parent
, Line line
, int inputNumber
) {
1416 this.inputNumber
= inputNumber
;
1418 labelComposite
= new Composite(parent
, SWT
.FILL
);
1419 GridLayout labelLayout
= new GridLayout(2, false);
1420 labelLayout
.marginWidth
= 0;
1421 labelLayout
.marginHeight
= 0;
1422 labelComposite
.setLayout(labelLayout
);
1423 labelComposite
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
1425 Button deleteButton
= new Button(labelComposite
, SWT
.PUSH
);
1426 deleteButton
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
1427 deleteButton
.setImage(DELETE_IMAGE
);
1428 deleteButton
.setToolTipText(Messages
.CustomTxtParserInputWizardPage_removeGroup
);
1429 deleteButton
.addSelectionListener(new SelectionAdapter() {
1431 public void widgetSelected(SelectionEvent e
) {
1432 InputGroup
.this.line
.removeInput(InputGroup
.this.inputNumber
);
1438 inputLabel
= new Label(labelComposite
, SWT
.NULL
);
1439 inputLabel
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
1440 inputLabel
.setText(NLS
.bind(Messages
.CustomTxtParserInputWizardPage_group
, inputNumber
));
1442 tagComposite
= new Composite(parent
, SWT
.FILL
);
1443 GridLayout tagLayout
= new GridLayout(4, false);
1444 tagLayout
.marginWidth
= 0;
1445 tagLayout
.marginHeight
= 0;
1446 tagComposite
.setLayout(tagLayout
);
1447 tagComposite
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
1449 tagCombo
= new Combo(tagComposite
, SWT
.DROP_DOWN
| SWT
.READ_ONLY
);
1450 tagCombo
.setItems(new String
[] {
1451 Tag
.TIMESTAMP
.toString(),
1452 Tag
.EVENT_TYPE
.toString(),
1453 Tag
.MESSAGE
.toString(),
1454 Tag
.OTHER
.toString()});
1456 tagCombo
.addSelectionListener(new SelectionListener() {
1458 public void widgetDefaultSelected(SelectionEvent e
) {
1462 public void widgetSelected(SelectionEvent e
) {
1463 tagText
.removeModifyListener(updateListener
);
1464 switch (tagCombo
.getSelectionIndex()) {
1465 case 0: // Time Stamp
1466 tagLabel
.setText(Messages
.CustomTxtParserInputWizardPage_format
);
1467 tagLabel
.setVisible(true);
1468 tagText
.setVisible(true);
1469 tagText
.addModifyListener(updateListener
);
1471 case 1: // Event type
1472 tagLabel
.setVisible(false);
1473 tagText
.setVisible(false);
1476 tagLabel
.setVisible(false);
1477 tagText
.setVisible(false);
1480 tagLabel
.setText(Messages
.CustomTxtParserInputWizardPage_name
);
1481 tagLabel
.setVisible(true);
1482 tagText
.setVisible(true);
1483 tagText
.addModifyListener(updateListener
);
1488 tagComposite
.layout();
1494 tagLabel
= new Label(tagComposite
, SWT
.NULL
);
1495 tagLabel
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
1496 tagLabel
.setVisible(false);
1498 tagText
= new Text(tagComposite
, SWT
.BORDER
| SWT
.SINGLE
);
1499 GridData gd
= new GridData(SWT
.FILL
, SWT
.CENTER
, true, false);
1501 tagText
.setLayoutData(gd
);
1502 tagText
.setVisible(false);
1504 actionCombo
= new Combo(tagComposite
, SWT
.DROP_DOWN
| SWT
.READ_ONLY
);
1505 actionCombo
.setItems(new String
[] { Messages
.CustomTxtParserInputWizardPage_set
, Messages
.CustomTxtParserInputWizardPage_append
, Messages
.CustomTxtParserInputWizardPage_appendWith
});
1506 actionCombo
.select(0);
1507 actionCombo
.addSelectionListener(updateListener
);
1509 previewLabel
= new Label(parent
, SWT
.NULL
);
1510 previewLabel
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
1511 previewLabel
.setText(Messages
.CustomTxtParserInputWizardPage_preview
);
1513 previewText
= new Text(parent
, SWT
.BORDER
| SWT
.SINGLE
| SWT
.READ_ONLY
);
1514 gd
= new GridData(SWT
.FILL
, SWT
.CENTER
, true, false);
1516 previewText
.setLayoutData(gd
);
1517 previewText
.setText(Messages
.CustomTxtParserInputWizardPage_noMatch
);
1518 previewText
.setBackground(COLOR_WIDGET_BACKGROUND
);
1521 private void dispose() {
1522 labelComposite
.dispose();
1523 tagComposite
.dispose();
1524 previewLabel
.dispose();
1525 previewText
.dispose();
1528 private void setInputNumber(int inputNumber
) {
1529 this.inputNumber
= inputNumber
;
1530 inputLabel
.setText(NLS
.bind(Messages
.CustomTxtParserInputWizardPage_group
, inputNumber
));
1531 labelComposite
.layout();
1535 private void validate() {
1537 definition
.categoryName
= categoryText
.getText().trim();
1538 definition
.definitionName
= logtypeText
.getText().trim();
1539 definition
.timeStampOutputFormat
= timestampOutputFormatText
.getText().trim();
1541 if (selectedLine
!= null) {
1542 selectedLine
.extractInputs();
1543 treeViewer
.refresh();
1546 StringBuffer errors
= new StringBuffer();
1548 if (definition
.categoryName
.length() == 0) {
1549 errors
.append("Enter a category for the new trace type. "); //$NON-NLS-1$
1550 categoryText
.setBackground(COLOR_LIGHT_RED
);
1551 } else if (definition
.definitionName
.length() == 0) {
1552 errors
.append("Enter a name for the new trace type. "); //$NON-NLS-1$
1553 logtypeText
.setBackground(COLOR_LIGHT_RED
);
1555 categoryText
.setBackground(COLOR_TEXT_BACKGROUND
);
1556 logtypeText
.setBackground(COLOR_TEXT_BACKGROUND
);
1557 if (definition
.categoryName
.indexOf(':') != -1) {
1558 errors
.append("Invalid character ':' in category. "); //$NON-NLS-1$
1559 categoryText
.setBackground(COLOR_LIGHT_RED
);
1561 if (definition
.definitionName
.indexOf(':') != -1) {
1562 errors
.append("Invalid character ':' in trace type. "); //$NON-NLS-1$
1563 logtypeText
.setBackground(COLOR_LIGHT_RED
);
1565 for (TraceTypeHelper helper
: TmfTraceType
.getTraceTypeHelpers()) {
1566 if (definition
.categoryName
.equals(helper
.getCategoryName()) &&
1567 definition
.definitionName
.equals(helper
.getName()) &&
1568 (editDefinitionName
== null || !editDefinitionName
.equals(definition
.definitionName
)) &&
1569 (editCategoryName
== null || !editCategoryName
.equals(definition
.categoryName
))) {
1570 errors
.append("The trace type name already exists. "); //$NON-NLS-1$
1571 logtypeText
.setBackground(COLOR_LIGHT_RED
);
1577 timestampFound
= false;
1578 for (int i
= 0; i
< definition
.inputs
.size(); i
++) {
1580 InputLine inputLine
= definition
.inputs
.get(i
);
1581 String name
= Integer
.toString(i
+ 1);
1582 errors
.append(validateLine(inputLine
, name
));
1584 if (timestampFound
) {
1585 if (definition
.timeStampOutputFormat
.length() == 0) {
1586 errors
.append("Enter the output format for the Time Stamp field. "); //$NON-NLS-1$
1587 timestampOutputFormatText
.setBackground(COLOR_LIGHT_RED
);
1590 new TmfTimestampFormat(definition
.timeStampOutputFormat
);
1591 timestampOutputFormatText
.setBackground(COLOR_TEXT_BACKGROUND
);
1592 } catch (IllegalArgumentException e
) {
1593 errors
.append("Enter a valid output format for the Time Stamp field [" + e
.getMessage() + "]."); //$NON-NLS-1$ //$NON-NLS-2$
1594 timestampOutputFormatText
.setBackground(COLOR_LIGHT_RED
);
1599 timestampOutputFormatText
.setBackground(COLOR_TEXT_BACKGROUND
);
1602 if (errors
.length() == 0) {
1603 setDescription(defaultDescription
);
1604 setPageComplete(true);
1606 setDescription(errors
.toString());
1607 setPageComplete(false);
1612 * Validate an input line.
1615 * The line to clean up
1617 * The name of the line
1618 * @return The cleaned up line
1620 public StringBuffer
validateLine(InputLine inputLine
, String name
) {
1621 StringBuffer errors
= new StringBuffer();
1623 if (selectedLine
!= null && selectedLine
.inputLine
.equals(inputLine
)) {
1624 line
= selectedLine
;
1627 Pattern
.compile(inputLine
.getRegex());
1629 line
.regexText
.setBackground(COLOR_TEXT_BACKGROUND
);
1631 } catch (PatternSyntaxException e
) {
1632 errors
.append("Enter a valid regular expression (Line " + name
+ "). "); //$NON-NLS-1$ //$NON-NLS-2$
1634 line
.regexText
.setBackground(COLOR_LIGHT_RED
);
1637 if (inputLine
.getMinCount() == -1) {
1638 errors
.append("Enter a minimum value for cardinality (Line " + name
+ "). "); //$NON-NLS-1$ //$NON-NLS-2$
1640 line
.cardinalityMinText
.setBackground(COLOR_LIGHT_RED
);
1644 line
.cardinalityMinText
.setBackground(COLOR_TEXT_BACKGROUND
);
1647 if (inputLine
.getMaxCount() == -1) {
1648 errors
.append("Enter a maximum value for cardinality (Line " + name
+ "). "); //$NON-NLS-1$ //$NON-NLS-2$
1650 line
.cardinalityMaxText
.setBackground(COLOR_LIGHT_RED
);
1652 } else if (inputLine
.getMinCount() > inputLine
.getMaxCount()) {
1653 errors
.append("Enter correct (min <= max) values for cardinality (Line " + name
+ "). "); //$NON-NLS-1$ //$NON-NLS-2$
1655 line
.cardinalityMinText
.setBackground(COLOR_LIGHT_RED
);
1658 line
.cardinalityMaxText
.setBackground(COLOR_LIGHT_RED
);
1662 line
.cardinalityMaxText
.setBackground(COLOR_TEXT_BACKGROUND
);
1665 if (inputLine
.eventType
!= null && inputLine
.eventType
.trim().isEmpty()) {
1666 errors
.append("Enter the event type (Line " + name
+ "). "); //$NON-NLS-1$ //$NON-NLS-2$
1668 line
.eventTypeText
.setBackground(COLOR_LIGHT_RED
);
1672 line
.eventTypeText
.setBackground(COLOR_TEXT_BACKGROUND
);
1675 for (int i
= 0; inputLine
.columns
!= null && i
< inputLine
.columns
.size(); i
++) {
1676 InputData inputData
= inputLine
.columns
.get(i
);
1677 InputGroup group
= null;
1679 group
= line
.inputs
.get(i
);
1681 if (inputData
.tag
.equals(Tag
.TIMESTAMP
)) {
1682 timestampFound
= true;
1683 if (inputData
.format
.length() == 0) {
1684 errors
.append("Enter the input format for the Time Stamp (Line " + name
+ " Group " + (i
+ 1) + "). "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
1685 if (group
!= null) {
1686 group
.tagText
.setBackground(COLOR_LIGHT_RED
);
1690 new TmfTimestampFormat(inputData
.format
);
1691 if (group
!= null) {
1692 group
.tagText
.setBackground(COLOR_TEXT_BACKGROUND
);
1694 } catch (IllegalArgumentException e
) {
1695 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$
1696 if (group
!= null) {
1697 group
.tagText
.setBackground(COLOR_LIGHT_RED
);
1701 } else if (inputData
.tag
.equals(Tag
.OTHER
)) {
1702 if (inputData
.name
.isEmpty()) {
1703 errors
.append("Enter a name for the data group (Line " + name
+ " Group " + (i
+ 1) + "). "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
1704 if (group
!= null) {
1705 group
.tagText
.setBackground(COLOR_LIGHT_RED
);
1707 } else if (Tag
.fromLabel(inputData
.name
) != null) {
1708 errors
.append("Cannot use reserved name for the data group (Line " + name
+ " Group " + (i
+ 1) + "). "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
1709 if (group
!= null) {
1710 group
.tagText
.setBackground(COLOR_LIGHT_RED
);
1713 if (group
!= null) {
1714 group
.tagText
.setBackground(COLOR_TEXT_BACKGROUND
);
1718 if (group
!= null) {
1719 group
.tagText
.setBackground(COLOR_TEXT_BACKGROUND
);
1723 for (int i
= 0; inputLine
.childrenInputs
!= null && i
< inputLine
.childrenInputs
.size(); i
++) {
1724 errors
.append(validateLine(inputLine
.childrenInputs
.get(i
), name
+ "." + (i
+ 1))); //$NON-NLS-1$
1730 * Get the trace definition.
1732 * @return The trace definition
1734 public CustomTxtTraceDefinition
getDefinition() {
1739 * Get the raw text of the input.
1741 * @return The raw input text
1743 public char[] getInputText() {
1744 return inputText
.getText().toCharArray();