1 /*******************************************************************************
2 * Copyright (c) 2010, 2013 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
.linuxtools
.internal
.tmf
.ui
.parsers
.wizards
;
15 import java
.io
.BufferedReader
;
16 import java
.io
.IOException
;
17 import java
.io
.InputStreamReader
;
18 import java
.text
.ParseException
;
19 import java
.text
.SimpleDateFormat
;
20 import java
.util
.ArrayList
;
21 import java
.util
.Arrays
;
22 import java
.util
.Date
;
23 import java
.util
.HashMap
;
24 import java
.util
.Iterator
;
25 import java
.util
.List
;
27 import java
.util
.Scanner
;
28 import java
.util
.regex
.Matcher
;
29 import java
.util
.regex
.Pattern
;
30 import java
.util
.regex
.PatternSyntaxException
;
32 import org
.eclipse
.core
.resources
.IFile
;
33 import org
.eclipse
.core
.runtime
.CoreException
;
34 import org
.eclipse
.jface
.viewers
.ColumnLabelProvider
;
35 import org
.eclipse
.jface
.viewers
.ISelection
;
36 import org
.eclipse
.jface
.viewers
.ISelectionChangedListener
;
37 import org
.eclipse
.jface
.viewers
.IStructuredSelection
;
38 import org
.eclipse
.jface
.viewers
.ITreeContentProvider
;
39 import org
.eclipse
.jface
.viewers
.SelectionChangedEvent
;
40 import org
.eclipse
.jface
.viewers
.StructuredSelection
;
41 import org
.eclipse
.jface
.viewers
.TreeViewer
;
42 import org
.eclipse
.jface
.viewers
.Viewer
;
43 import org
.eclipse
.jface
.wizard
.WizardPage
;
44 import org
.eclipse
.linuxtools
.internal
.tmf
.ui
.Activator
;
45 import org
.eclipse
.linuxtools
.internal
.tmf
.ui
.Messages
;
46 import org
.eclipse
.linuxtools
.internal
.tmf
.ui
.parsers
.custom
.CustomTraceDefinition
;
47 import org
.eclipse
.linuxtools
.internal
.tmf
.ui
.parsers
.custom
.CustomTxtTraceDefinition
;
48 import org
.eclipse
.linuxtools
.internal
.tmf
.ui
.parsers
.custom
.CustomTxtTraceDefinition
.Cardinality
;
49 import org
.eclipse
.linuxtools
.internal
.tmf
.ui
.parsers
.custom
.CustomTxtTraceDefinition
.InputData
;
50 import org
.eclipse
.linuxtools
.internal
.tmf
.ui
.parsers
.custom
.CustomTxtTraceDefinition
.InputLine
;
51 import org
.eclipse
.swt
.SWT
;
52 import org
.eclipse
.swt
.browser
.Browser
;
53 import org
.eclipse
.swt
.browser
.TitleEvent
;
54 import org
.eclipse
.swt
.browser
.TitleListener
;
55 import org
.eclipse
.swt
.custom
.SashForm
;
56 import org
.eclipse
.swt
.custom
.ScrolledComposite
;
57 import org
.eclipse
.swt
.custom
.StyleRange
;
58 import org
.eclipse
.swt
.custom
.StyledText
;
59 import org
.eclipse
.swt
.events
.ModifyEvent
;
60 import org
.eclipse
.swt
.events
.ModifyListener
;
61 import org
.eclipse
.swt
.events
.SelectionAdapter
;
62 import org
.eclipse
.swt
.events
.SelectionEvent
;
63 import org
.eclipse
.swt
.events
.SelectionListener
;
64 import org
.eclipse
.swt
.events
.VerifyEvent
;
65 import org
.eclipse
.swt
.events
.VerifyListener
;
66 import org
.eclipse
.swt
.graphics
.Color
;
67 import org
.eclipse
.swt
.graphics
.Font
;
68 import org
.eclipse
.swt
.graphics
.FontData
;
69 import org
.eclipse
.swt
.graphics
.Image
;
70 import org
.eclipse
.swt
.layout
.FillLayout
;
71 import org
.eclipse
.swt
.layout
.GridData
;
72 import org
.eclipse
.swt
.layout
.GridLayout
;
73 import org
.eclipse
.swt
.widgets
.Button
;
74 import org
.eclipse
.swt
.widgets
.Combo
;
75 import org
.eclipse
.swt
.widgets
.Composite
;
76 import org
.eclipse
.swt
.widgets
.Display
;
77 import org
.eclipse
.swt
.widgets
.Group
;
78 import org
.eclipse
.swt
.widgets
.Label
;
79 import org
.eclipse
.swt
.widgets
.Shell
;
80 import org
.eclipse
.swt
.widgets
.Text
;
83 * Input wizard page for custom text parsers.
85 * @author Patrick Tasse
87 public class CustomTxtParserInputWizardPage
extends WizardPage
{
89 private static final String DEFAULT_REGEX
= "\\s*(.*\\S)"; //$NON-NLS-1$
90 private static final String DEFAULT_TIMESTAMP_FORMAT
= "yyyy-MM-dd HH:mm:ss.SSS"; //$NON-NLS-1$
91 private static final String SIMPLE_DATE_FORMAT_URL
= "http://java.sun.com/javase/6/docs/api/java/text/SimpleDateFormat.html#skip-navbar_top"; //$NON-NLS-1$
92 private static final String PATTERN_URL
= "http://java.sun.com/javase/6/docs/api/java/util/regex/Pattern.html#sum"; //$NON-NLS-1$
93 private static final Image LINE_IMAGE
= Activator
.getDefault().getImageFromPath("/icons/elcl16/line_icon.gif"); //$NON-NLS-1$
94 private static final Image ADD_IMAGE
= Activator
.getDefault().getImageFromPath("/icons/elcl16/add_button.gif"); //$NON-NLS-1$
95 private static final Image ADD_NEXT_IMAGE
= Activator
.getDefault().getImageFromPath("/icons/elcl16/addnext_button.gif"); //$NON-NLS-1$
96 private static final Image ADD_CHILD_IMAGE
= Activator
.getDefault().getImageFromPath("/icons/elcl16/addchild_button.gif"); //$NON-NLS-1$
97 private static final Image DELETE_IMAGE
= Activator
.getDefault().getImageFromPath("/icons/elcl16/delete_button.gif"); //$NON-NLS-1$
98 private static final Image MOVE_UP_IMAGE
= Activator
.getDefault().getImageFromPath("/icons/elcl16/moveup_button.gif"); //$NON-NLS-1$
99 private static final Image MOVE_DOWN_IMAGE
= Activator
.getDefault().getImageFromPath("/icons/elcl16/movedown_button.gif"); //$NON-NLS-1$
100 private static final Image HELP_IMAGE
= Activator
.getDefault().getImageFromPath("/icons/elcl16/help_button.gif"); //$NON-NLS-1$
101 private static final Color COLOR_BLACK
= Display
.getDefault().getSystemColor(SWT
.COLOR_BLACK
);
102 private static final Color COLOR_LIGHT_GREEN
= new Color(Display
.getDefault(), 192, 255, 192);
103 private static final Color COLOR_GREEN
= Display
.getDefault().getSystemColor(SWT
.COLOR_GREEN
);
104 private static final Color COLOR_LIGHT_YELLOW
= new Color(Display
.getDefault(), 255, 255, 192);
105 private static final Color COLOR_YELLOW
= Display
.getDefault().getSystemColor(SWT
.COLOR_YELLOW
);
106 private static final Color COLOR_LIGHT_MAGENTA
= new Color(Display
.getDefault(), 255, 192, 255);
107 private static final Color COLOR_MAGENTA
= Display
.getDefault().getSystemColor(SWT
.COLOR_MAGENTA
);
108 private static final Color COLOR_LIGHT_RED
= new Color(Display
.getDefault(), 255, 192, 192);
109 private static final Color COLOR_TEXT_BACKGROUND
= Display
.getDefault().getSystemColor(SWT
.COLOR_WHITE
);
110 private static final Color COLOR_WIDGET_BACKGROUND
= Display
.getDefault().getSystemColor(SWT
.COLOR_WIDGET_BACKGROUND
);
112 private final ISelection selection
;
113 private CustomTxtTraceDefinition definition
;
114 private String editDefinitionName
;
115 private String defaultDescription
;
116 private Line selectedLine
;
117 private Composite container
;
118 private Text logtypeText
;
119 private Text timestampOutputFormatText
;
120 private Text timestampPreviewText
;
121 private ScrolledComposite lineScrolledComposite
;
122 private TreeViewer treeViewer
;
123 private Composite lineContainer
;
124 private StyledText inputText
;
125 private Font fixedFont
;
126 private UpdateListener updateListener
;
127 private Browser helpBrowser
;
129 // variables used recursively through line traversal
130 private String timeStampFormat
;
131 private boolean timestampFound
;
137 * The Selection object
139 * The trace definition
141 protected CustomTxtParserInputWizardPage(ISelection selection
,
142 CustomTxtTraceDefinition definition
) {
143 super("CustomParserWizardPage"); //$NON-NLS-1$
144 if (definition
== null) {
145 setTitle(Messages
.CustomTxtParserInputWizardPage_windowTitleNew
);
146 defaultDescription
= Messages
.CustomTxtParserInputWizardPage_descriptionNew
;
148 setTitle(Messages
.CustomTxtParserInputWizardPage_windowTitleEdit
);
149 defaultDescription
= Messages
.CustomTxtParserInputWizardPage_desccriptionEdit
;
151 setDescription(defaultDescription
);
152 this.selection
= selection
;
153 this.definition
= definition
;
154 if (definition
!= null) {
155 this.editDefinitionName
= definition
.definitionName
;
160 public void createControl(Composite parent
) {
161 container
= new Composite(parent
, SWT
.NULL
);
162 container
.setLayout(new GridLayout());
164 updateListener
= new UpdateListener();
166 Composite headerComposite
= new Composite(container
, SWT
.FILL
);
167 GridLayout headerLayout
= new GridLayout(5, false);
168 headerLayout
.marginHeight
= 0;
169 headerLayout
.marginWidth
= 0;
170 headerComposite
.setLayout(headerLayout
);
171 headerComposite
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
173 Label logtypeLabel
= new Label(headerComposite
, SWT
.NULL
);
174 logtypeLabel
.setText(Messages
.CustomTxtParserInputWizardPage_logType
);
176 logtypeText
= new Text(headerComposite
, SWT
.BORDER
| SWT
.SINGLE
);
177 logtypeText
.setLayoutData(new GridData(120, SWT
.DEFAULT
));
179 Label timestampFormatLabel
= new Label(headerComposite
, SWT
.NULL
);
180 timestampFormatLabel
.setText(Messages
.CustomTxtParserInputWizardPage_timestampFormat
);
182 timestampOutputFormatText
= new Text(headerComposite
, SWT
.BORDER
| SWT
.SINGLE
);
183 timestampOutputFormatText
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
184 timestampOutputFormatText
.setText(DEFAULT_TIMESTAMP_FORMAT
);
186 Button dateFormatHelpButton
= new Button(headerComposite
, SWT
.PUSH
);
187 dateFormatHelpButton
.setImage(HELP_IMAGE
);
188 dateFormatHelpButton
.setToolTipText(Messages
.CustomTxtParserInputWizardPage_dateFormatHelp
);
189 dateFormatHelpButton
.addSelectionListener(new SelectionAdapter() {
191 public void widgetSelected(SelectionEvent e
) {
192 openHelpShell(SIMPLE_DATE_FORMAT_URL
);
196 Label timestampPreviewLabel
= new Label(headerComposite
, SWT
.NULL
);
197 timestampPreviewLabel
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false, 3, 1));
198 timestampPreviewLabel
.setText(Messages
.CustomTxtParserInputWizardPage_preview
);
200 timestampPreviewText
= new Text(headerComposite
, SWT
.BORDER
| SWT
.SINGLE
| SWT
.READ_ONLY
);
201 timestampPreviewText
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false, 2, 1));
202 timestampPreviewText
.setText(Messages
.CustomTxtParserInputWizardPage_noMatchingTimestamp
);
204 Composite buttonBar
= new Composite(container
, SWT
.NONE
);
205 GridLayout buttonBarLayout
= new GridLayout(5, false);
206 buttonBarLayout
.marginHeight
= 0;
207 buttonBarLayout
.marginWidth
= 0;
208 buttonBar
.setLayout(buttonBarLayout
);
210 Button removeButton
= new Button(buttonBar
, SWT
.PUSH
);
211 removeButton
.setImage(DELETE_IMAGE
);
212 removeButton
.setToolTipText(Messages
.CustomTxtParserInputWizardPage_removeLine
);
213 removeButton
.addSelectionListener(new SelectionAdapter() {
215 public void widgetSelected(SelectionEvent e
) {
216 if (treeViewer
.getSelection().isEmpty() || selectedLine
== null) {
220 InputLine inputLine
= (InputLine
) ((IStructuredSelection
) treeViewer
.getSelection()).getFirstElement();
221 if (inputLine
.parentInput
== null) {
222 definition
.inputs
.remove(inputLine
);
224 inputLine
.parentInput
.childrenInputs
.remove(inputLine
);
226 treeViewer
.refresh();
231 Button addNextButton
= new Button(buttonBar
, SWT
.PUSH
);
232 addNextButton
.setImage(ADD_NEXT_IMAGE
);
233 addNextButton
.setToolTipText(Messages
.CustomTxtParserInputWizardPage_addNextLine
);
234 addNextButton
.addSelectionListener(new SelectionAdapter() {
236 public void widgetSelected(SelectionEvent e
) {
237 InputLine inputLine
= new InputLine(Cardinality
.ZERO_OR_MORE
, "", null); //$NON-NLS-1$
238 if (((List
<?
>) treeViewer
.getInput()).size() == 0) {
239 definition
.inputs
.add(inputLine
);
240 } else if (treeViewer
.getSelection().isEmpty()) {
243 InputLine previousInputLine
= (InputLine
) ((IStructuredSelection
) treeViewer
.getSelection()).getFirstElement();
244 if (previousInputLine
.parentInput
== null) {
245 for (int i
= 0; i
< definition
.inputs
.size(); i
++) {
246 if (definition
.inputs
.get(i
).equals(previousInputLine
)) {
247 definition
.inputs
.add(i
+ 1, inputLine
);
251 previousInputLine
.addNext(inputLine
);
254 treeViewer
.refresh();
255 treeViewer
.setSelection(new StructuredSelection(inputLine
), true);
258 Button addChildButton
= new Button(buttonBar
, SWT
.PUSH
);
259 addChildButton
.setImage(ADD_CHILD_IMAGE
);
260 addChildButton
.setToolTipText(Messages
.CustomTxtParserInputWizardPage_addChildLine
);
261 addChildButton
.addSelectionListener(new SelectionAdapter() {
263 public void widgetSelected(SelectionEvent e
) {
264 InputLine inputLine
= new InputLine(Cardinality
.ZERO_OR_MORE
, "", null); //$NON-NLS-1$
265 if (((List
<?
>) treeViewer
.getInput()).size() == 0) {
266 definition
.inputs
.add(inputLine
);
267 } else if (treeViewer
.getSelection().isEmpty()) {
270 InputLine parentInputLine
= (InputLine
) ((IStructuredSelection
) treeViewer
.getSelection()).getFirstElement();
271 parentInputLine
.addChild(inputLine
);
273 treeViewer
.refresh();
274 treeViewer
.setSelection(new StructuredSelection(inputLine
), true);
277 Button moveUpButton
= new Button(buttonBar
, SWT
.PUSH
);
278 moveUpButton
.setImage(MOVE_UP_IMAGE
);
279 moveUpButton
.setToolTipText(Messages
.CustomTxtParserInputWizardPage_moveUp
);
280 moveUpButton
.addSelectionListener(new SelectionAdapter() {
282 public void widgetSelected(SelectionEvent e
) {
283 if (treeViewer
.getSelection().isEmpty()) {
286 InputLine inputLine
= (InputLine
) ((IStructuredSelection
) treeViewer
.getSelection()).getFirstElement();
287 if (inputLine
.parentInput
== null) {
288 for (int i
= 1; i
< definition
.inputs
.size(); i
++) {
289 if (definition
.inputs
.get(i
).equals(inputLine
)) {
290 definition
.inputs
.add(i
- 1 , definition
.inputs
.remove(i
));
297 treeViewer
.refresh();
302 Button moveDownButton
= new Button(buttonBar
, SWT
.PUSH
);
303 moveDownButton
.setImage(MOVE_DOWN_IMAGE
);
304 moveDownButton
.setToolTipText(Messages
.CustomTxtParserInputWizardPage_moveDown
);
305 moveDownButton
.addSelectionListener(new SelectionAdapter() {
307 public void widgetSelected(SelectionEvent e
) {
308 if (treeViewer
.getSelection().isEmpty()) {
311 InputLine inputLine
= (InputLine
) ((IStructuredSelection
) treeViewer
.getSelection()).getFirstElement();
312 if (inputLine
.parentInput
== null) {
313 for (int i
= 0; i
< definition
.inputs
.size() - 1; i
++) {
314 if (definition
.inputs
.get(i
).equals(inputLine
)) {
315 definition
.inputs
.add(i
+ 1 , definition
.inputs
.remove(i
));
320 inputLine
.moveDown();
322 treeViewer
.refresh();
328 SashForm vSash
= new SashForm(container
, SWT
.VERTICAL
);
329 vSash
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
330 vSash
.setBackground(vSash
.getDisplay().getSystemColor(SWT
.COLOR_GRAY
));
332 SashForm hSash
= new SashForm(vSash
, SWT
.HORIZONTAL
);
333 hSash
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
335 ScrolledComposite treeScrolledComposite
= new ScrolledComposite(hSash
, SWT
.V_SCROLL
| SWT
.H_SCROLL
);
336 GridData gd
= new GridData(SWT
.FILL
, SWT
.FILL
, true, true);
339 treeScrolledComposite
.setLayoutData(gd
);
340 Composite treeContainer
= new Composite(treeScrolledComposite
, SWT
.NONE
);
341 treeContainer
.setLayout(new FillLayout());
342 treeScrolledComposite
.setContent(treeContainer
);
343 treeScrolledComposite
.setExpandHorizontal(true);
344 treeScrolledComposite
.setExpandVertical(true);
346 treeViewer
= new TreeViewer(treeContainer
, SWT
.SINGLE
| SWT
.BORDER
);
347 treeViewer
.setContentProvider(new InputLineTreeNodeContentProvider());
348 treeViewer
.setLabelProvider(new InputLineTreeLabelProvider());
349 treeViewer
.addSelectionChangedListener(new InputLineTreeSelectionChangedListener());
350 treeContainer
.layout();
352 treeScrolledComposite
.setMinSize(treeContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).x
, treeContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).y
);
354 lineScrolledComposite
= new ScrolledComposite(hSash
, SWT
.V_SCROLL
);
355 lineScrolledComposite
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
356 lineContainer
= new Composite(lineScrolledComposite
, SWT
.NONE
);
357 GridLayout linesLayout
= new GridLayout();
358 linesLayout
.marginHeight
= 1;
359 linesLayout
.marginWidth
= 0;
360 lineContainer
.setLayout(linesLayout
);
361 lineScrolledComposite
.setContent(lineContainer
);
362 lineScrolledComposite
.setExpandHorizontal(true);
363 lineScrolledComposite
.setExpandVertical(true);
365 if (definition
== null) {
366 definition
= new CustomTxtTraceDefinition();
367 definition
.inputs
.add(new InputLine(Cardinality
.ZERO_OR_MORE
, DEFAULT_REGEX
,
368 Arrays
.asList(new InputData(CustomTraceDefinition
.TAG_MESSAGE
, CustomTraceDefinition
.ACTION_SET
))));
370 loadDefinition(definition
);
371 treeViewer
.expandAll();
372 lineContainer
.layout();
374 logtypeText
.addModifyListener(updateListener
);
375 timestampOutputFormatText
.addModifyListener(updateListener
);
377 lineScrolledComposite
.setMinSize(lineContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).x
, lineContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).y
-1);
379 hSash
.setWeights(new int[] {1, 2});
381 Composite sashBottom
= new Composite(vSash
, SWT
.NONE
);
382 GridLayout sashBottomLayout
= new GridLayout(3, false);
383 sashBottomLayout
.marginHeight
= 0;
384 sashBottomLayout
.marginWidth
= 0;
385 sashBottom
.setLayout(sashBottomLayout
);
387 Label previewLabel
= new Label(sashBottom
, SWT
.NULL
);
388 previewLabel
.setText(Messages
.CustomTxtParserInputWizardPage_previewInput
);
389 previewLabel
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
391 Button highlightAllButton
= new Button(sashBottom
, SWT
.PUSH
);
392 highlightAllButton
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
393 highlightAllButton
.setText(Messages
.CustomTxtParserInputWizardPage_highlightAll
);
394 highlightAllButton
.addSelectionListener(new SelectionAdapter() {
396 public void widgetSelected(SelectionEvent e
) {
397 updatePreviews(true);
401 Button legendButton
= new Button(sashBottom
, SWT
.PUSH
);
402 legendButton
.setImage(HELP_IMAGE
);
403 legendButton
.setToolTipText(Messages
.CustomTxtParserInputWizardPage_previewLegend
);
404 legendButton
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
405 legendButton
.addSelectionListener(new SelectionAdapter() {
407 public void widgetSelected(SelectionEvent e
) {
412 inputText
= new StyledText(sashBottom
, SWT
.MULTI
| SWT
.V_SCROLL
| SWT
.H_SCROLL
);
413 if (fixedFont
== null) {
414 if (System
.getProperty("os.name").contains("Windows")) { //$NON-NLS-1$ //$NON-NLS-2$
415 fixedFont
= new Font(Display
.getCurrent(), new FontData("Courier New", 10, SWT
.NORMAL
)); //$NON-NLS-1$
417 fixedFont
= new Font(Display
.getCurrent(), new FontData("Monospace", 10, SWT
.NORMAL
)); //$NON-NLS-1$
420 inputText
.setFont(fixedFont
);
421 gd
= new GridData(SWT
.FILL
, SWT
.FILL
, true, true, 3, 1);
422 gd
.heightHint
= inputText
.computeSize(SWT
.DEFAULT
, inputText
.getLineHeight() * 4).y
;
424 inputText
.setLayoutData(gd
);
425 inputText
.setText(getSelectionText());
426 inputText
.addModifyListener(updateListener
);
428 vSash
.setWeights(new int[] {hSash
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).y
, sashBottom
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).y
});
430 setControl(container
);
436 private static class InputLineTreeNodeContentProvider
implements ITreeContentProvider
{
439 public Object
[] getElements(Object inputElement
) {
440 return ((List
<?
>) inputElement
).toArray();
444 public Object
[] getChildren(Object parentElement
) {
445 InputLine inputLine
= (InputLine
) parentElement
;
446 if (inputLine
.childrenInputs
== null) {
447 return new InputLine
[0];
449 return inputLine
.childrenInputs
.toArray();
453 public boolean hasChildren(Object element
) {
454 InputLine inputLine
= (InputLine
) element
;
455 return (inputLine
.childrenInputs
!= null && inputLine
.childrenInputs
.size() > 0);
459 public void dispose() {
463 public void inputChanged(Viewer viewer
, Object oldInput
, Object newInput
) {
467 public Object
getParent(Object element
) {
468 InputLine inputLine
= (InputLine
) element
;
469 return inputLine
.parentInput
;
473 private class InputLineTreeLabelProvider
extends ColumnLabelProvider
{
476 public Image
getImage(Object element
) {
481 public String
getText(Object element
) {
482 InputLine inputLine
= (InputLine
) element
;
483 if (inputLine
.parentInput
== null) {
484 return "Root Line " + getName(inputLine
) + " " + inputLine
.cardinality
.toString() + " : " + inputLine
.getRegex(); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
486 return "Line " + getName(inputLine
) + " " + inputLine
.cardinality
.toString() + " : " + inputLine
.getRegex(); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
490 private class InputLineTreeSelectionChangedListener
implements ISelectionChangedListener
{
492 public void selectionChanged(SelectionChangedEvent event
) {
493 if (selectedLine
!= null) {
494 selectedLine
.dispose();
496 if (!(event
.getSelection().isEmpty()) && event
.getSelection() instanceof IStructuredSelection
) {
497 IStructuredSelection sel
= (IStructuredSelection
) event
.getSelection();
498 InputLine inputLine
= (InputLine
) sel
.getFirstElement();
499 selectedLine
= new Line(lineContainer
, getName(inputLine
), inputLine
);
500 lineContainer
.layout();
501 lineScrolledComposite
.setMinSize(lineContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).x
, lineContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).y
- 1);
510 public void dispose() {
511 if (fixedFont
!= null) {
518 private void loadDefinition(CustomTxtTraceDefinition def
) {
519 logtypeText
.setText(def
.definitionName
);
520 timestampOutputFormatText
.setText(def
.timeStampOutputFormat
);
521 treeViewer
.setInput(def
.inputs
);
522 if (def
.inputs
.size() > 0) {
523 InputLine inputLine
= def
.inputs
.get(0);
524 treeViewer
.setSelection(new StructuredSelection(inputLine
));
528 private String
getName(InputLine inputLine
) {
529 if (inputLine
.parentInput
== null) {
530 return Integer
.toString(definition
.inputs
.indexOf(inputLine
)+1);
532 return getName(inputLine
.parentInput
) + "." + Integer
.toString(inputLine
.parentInput
.childrenInputs
.indexOf(inputLine
)+1); //$NON-NLS-1$
536 * Get the global list of input names.
538 * @return The list of input names
540 public List
<String
> getInputNames() {
541 List
<String
> inputs
= new ArrayList
<>();
542 for (InputLine inputLine
: definition
.inputs
) {
543 for (String inputName
: getInputNames(inputLine
)) {
544 if (!inputs
.contains(inputName
)) {
545 inputs
.add(inputName
);
553 * Get the list of input names for the given input line.
557 * @return The list of input names
559 public List
<String
> getInputNames(InputLine inputLine
) {
560 List
<String
> inputs
= new ArrayList
<>();
561 if (inputLine
.columns
!= null) {
562 for (InputData inputData
: inputLine
.columns
) {
563 String inputName
= inputData
.name
;
564 if (!inputs
.contains(inputName
)) {
565 inputs
.add(inputName
);
569 if (inputLine
.childrenInputs
!= null) {
570 for (InputLine childInputLine
: inputLine
.childrenInputs
) {
571 for (String inputName
: getInputNames(childInputLine
)) {
572 if (!inputs
.contains(inputName
)) {
573 inputs
.add(inputName
);
581 private void removeLine() {
582 selectedLine
.dispose();
584 lineContainer
.layout();
585 lineScrolledComposite
.setMinSize(lineContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).x
, lineContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).y
-1);
589 private String
getSelectionText() {
590 if (this.selection
instanceof IStructuredSelection
) {
591 Object sel
= ((IStructuredSelection
) this.selection
).getFirstElement();
592 if (sel
instanceof IFile
) {
593 IFile file
= (IFile
)sel
;
594 BufferedReader reader
= null;
596 reader
= new BufferedReader(new InputStreamReader(file
.getContents()));
597 StringBuilder sb
= new StringBuilder();
599 while ((line
= reader
.readLine()) != null) {
600 sb
.append(line
+ "\n"); //$NON-NLS-1$
602 return sb
.toString();
603 } catch (CoreException e
) {
604 return ""; //$NON-NLS-1$
605 } catch (IOException e
) {
606 return ""; //$NON-NLS-1$
608 if (reader
!= null) {
611 } catch (IOException e
) {
617 return ""; //$NON-NLS-1$
620 private void updatePreviews() {
621 updatePreviews(false);
624 private void updatePreviews(boolean updateAll
) {
625 if (inputText
== null) {
626 // early update during construction
629 inputText
.setStyleRanges(new StyleRange
[] {});
631 try (Scanner scanner
= new Scanner(inputText
.getText());) {
632 scanner
.useDelimiter("\n"); //$NON-NLS-1$
635 // skip starting delimiters
636 String skip
= scanner
.findWithinHorizon("\\A\n+", 0); //$NON-NLS-1$
638 rawPos
+= skip
.length();
641 timeStampFormat
= null;
642 if (selectedLine
!= null) {
643 for (InputGroup input
: selectedLine
.inputs
) {
644 input
.previewText
.setText(Messages
.CustomTxtParserInputWizardPage_noMathcingLine
);
648 Map
<String
, String
> data
= new HashMap
<>();
649 int rootLineMatches
= 0;
650 String firstEntryTimeStamp
= null;
651 String firstEntryTimeStampInputFormat
= null;
653 event
: while (scanner
.hasNext()) {
654 if (rootLineMatches
> 0 && !updateAll
) {
658 log
= scanner
.next();
660 int length
= log
.length();
661 for (InputLine rootInputLine
: definition
.inputs
) {
664 pattern
= rootInputLine
.getPattern();
665 } catch (PatternSyntaxException e
) {
668 Matcher matcher
= pattern
.matcher(log
);
669 if (matcher
.find()) {
671 inputText
.setStyleRange(new StyleRange(rawPos
, length
,
672 COLOR_BLACK
, COLOR_YELLOW
, SWT
.ITALIC
));
673 data
= new HashMap
<>();
674 timeStampFormat
= null;
675 updatePreviewLine(rootInputLine
, matcher
, data
, rawPos
, rootLineMatches
);
676 if (rootLineMatches
== 1) {
677 firstEntryTimeStamp
= data
.get(CustomTraceDefinition
.TAG_TIMESTAMP
);
678 firstEntryTimeStampInputFormat
= timeStampFormat
;
680 HashMap
<InputLine
, Integer
> countMap
= new HashMap
<>();
681 InputLine currentInput
= null;
682 if (rootInputLine
.childrenInputs
!= null && rootInputLine
.childrenInputs
.size() > 0) {
683 currentInput
= rootInputLine
.childrenInputs
.get(0);
684 countMap
.put(currentInput
, 0);
686 rawPos
+= length
+ 1; // +1 for \n
687 while (scanner
.hasNext()) {
688 log
= scanner
.next();
689 length
= log
.length();
690 boolean processed
= false;
691 if (currentInput
== null) {
692 for (InputLine input
: definition
.inputs
) {
693 matcher
= input
.getPattern().matcher(log
);
694 if (matcher
.find()) {
699 if (countMap
.get(currentInput
) >= currentInput
.getMinCount()) {
700 List
<InputLine
> nextInputs
= currentInput
.getNextInputs(countMap
);
701 if (nextInputs
.size() == 0 || nextInputs
.get(nextInputs
.size() - 1).getMinCount() == 0) {
702 for (InputLine input
: definition
.inputs
) {
703 matcher
= input
.getPattern().matcher(log
);
704 if (matcher
.find()) {
709 for (InputLine input
: nextInputs
) {
710 matcher
= input
.getPattern().matcher(log
);
711 if (matcher
.find()) {
712 inputText
.setStyleRange(new StyleRange(rawPos
, length
,
713 COLOR_BLACK
, COLOR_LIGHT_YELLOW
, SWT
.ITALIC
));
714 currentInput
= input
;
715 updatePreviewLine(currentInput
, matcher
, data
, rawPos
, rootLineMatches
);
716 if (countMap
.get(currentInput
) == null) {
717 countMap
.put(currentInput
, 1);
719 countMap
.put(currentInput
, countMap
.get(currentInput
) + 1);
721 Iterator
<InputLine
> iter
= countMap
.keySet().iterator();
722 while (iter
.hasNext()) {
723 InputLine inputLine
= iter
.next();
724 if (inputLine
.level
> currentInput
.level
) {
728 if (currentInput
.childrenInputs
!= null && currentInput
.childrenInputs
.size() > 0) {
729 currentInput
= currentInput
.childrenInputs
.get(0);
730 countMap
.put(currentInput
, 0);
732 if (countMap
.get(currentInput
) >= currentInput
.getMaxCount()) {
733 if (currentInput
.getNextInputs(countMap
).size() > 0) {
734 currentInput
= currentInput
.getNextInputs(countMap
).get(0);
735 if (countMap
.get(currentInput
) == null) {
736 countMap
.put(currentInput
, 0);
738 iter
= countMap
.keySet().iterator();
739 while (iter
.hasNext()) {
740 InputLine inputLine
= iter
.next();
741 if (inputLine
.level
> currentInput
.level
) {
755 if (!processed
&& currentInput
!= null) {
756 matcher
= currentInput
.getPattern().matcher(log
);
757 if (matcher
.find()) {
758 inputText
.setStyleRange(new StyleRange(rawPos
, length
,
759 COLOR_BLACK
, COLOR_LIGHT_YELLOW
, SWT
.ITALIC
));
760 updatePreviewLine(currentInput
, matcher
, data
, rawPos
, rootLineMatches
);
761 countMap
.put(currentInput
, countMap
.get(currentInput
) + 1);
762 if (currentInput
.childrenInputs
!= null && currentInput
.childrenInputs
.size() > 0) {
763 currentInput
= currentInput
.childrenInputs
.get(0);
764 countMap
.put(currentInput
, 0);
766 if (countMap
.get(currentInput
) >= currentInput
.getMaxCount()) {
767 if (currentInput
.getNextInputs(countMap
).size() > 0) {
768 currentInput
= currentInput
.getNextInputs(countMap
).get(0);
769 if (countMap
.get(currentInput
) == null) {
770 countMap
.put(currentInput
, 0);
772 Iterator
<InputLine
> iter
= countMap
.keySet().iterator();
773 while (iter
.hasNext()) {
774 InputLine inputLine
= iter
.next();
775 if (inputLine
.level
> currentInput
.level
) {
787 rawPos
+= length
+ 1; // +1 for \n
793 rawPos
+= length
+ 1; // +1 for \n
797 if (rootLineMatches
== 1) {
798 firstEntryTimeStamp
= data
.get(CustomTraceDefinition
.TAG_TIMESTAMP
);
799 firstEntryTimeStampInputFormat
= timeStampFormat
;
801 if (firstEntryTimeStamp
== null) {
802 timestampPreviewText
.setText(Messages
.CustomTxtParserInputWizardPage_noTimestampGroup
);
803 if (selectedLine
!= null) {
804 for (InputGroup group
: selectedLine
.inputs
) {
805 if (group
.tagCombo
.getText().equals(CustomTraceDefinition
.TAG_TIMESTAMP
)) {
806 timestampPreviewText
.setText(Messages
.CustomTxtParserInputWizardPage_noMatchingTimestamp
);
813 SimpleDateFormat dateFormat
= new SimpleDateFormat(firstEntryTimeStampInputFormat
);
814 Date date
= dateFormat
.parse(firstEntryTimeStamp
);
815 dateFormat
= new SimpleDateFormat(timestampOutputFormatText
.getText().trim());
816 timestampPreviewText
.setText(dateFormat
.format(date
));
817 } catch (ParseException e
) {
818 timestampPreviewText
.setText("*parse exception* [" + firstEntryTimeStamp
+ "] <> [" + firstEntryTimeStampInputFormat
+ "]"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
819 } catch (IllegalArgumentException e
) {
820 timestampPreviewText
.setText("*parse exception* [Illegal Argument]"); //$NON-NLS-1$
827 private void updatePreviewLine(InputLine line
, Matcher matcher
, Map
<String
, String
> data
, int rawPos
, int rootLineMatches
) {
828 for (int i
= 0; i
< line
.columns
.size(); i
++) {
829 InputData input
= line
.columns
.get(i
);
830 if (i
< matcher
.groupCount() && matcher
.group(i
+1) != null) {
831 if (line
.parentInput
== null) {
832 inputText
.setStyleRange(new StyleRange(rawPos
+ matcher
.start(i
+1), matcher
.end(i
+1) - matcher
.start(i
+1),
833 COLOR_BLACK
, COLOR_GREEN
, SWT
.BOLD
));
835 inputText
.setStyleRange(new StyleRange(rawPos
+ matcher
.start(i
+1), matcher
.end(i
+1) - matcher
.start(i
+1),
836 COLOR_BLACK
, COLOR_LIGHT_GREEN
, SWT
.BOLD
));
838 String value
= matcher
.group(i
+1).trim();
839 if (selectedLine
!= null && selectedLine
.inputLine
.equals(line
) && rootLineMatches
== 1 &&
840 selectedLine
.inputs
.get(i
).previewText
.getText().equals(Messages
.CustomTxtParserInputWizardPage_noMatchingLine
)) {
841 selectedLine
.inputs
.get(i
).previewText
.setText(value
);
843 if (value
.length() == 0) {
846 if (input
.action
== CustomTraceDefinition
.ACTION_SET
) {
847 data
.put(input
.name
, value
);
848 if (input
.name
.equals(CustomTraceDefinition
.TAG_TIMESTAMP
)) {
849 timeStampFormat
= input
.format
;
851 } else if (input
.action
== CustomTraceDefinition
.ACTION_APPEND
) {
852 String s
= data
.get(input
.name
);
854 data
.put(input
.name
, s
+ value
);
856 data
.put(input
.name
, value
);
858 if (input
.name
.equals(CustomTraceDefinition
.TAG_TIMESTAMP
)) {
859 if (timeStampFormat
!= null) {
860 timeStampFormat
+= input
.format
;
862 timeStampFormat
= input
.format
;
865 } else if (input
.action
== CustomTraceDefinition
.ACTION_APPEND_WITH_SEPARATOR
) {
866 String s
= data
.get(input
.name
);
868 data
.put(input
.name
, s
+ " | " + value
); //$NON-NLS-1$
870 data
.put(input
.name
, value
);
872 if (input
.name
.equals(CustomTraceDefinition
.TAG_TIMESTAMP
)) {
873 if (timeStampFormat
!= null) {
874 timeStampFormat
+= " | " + input
.format
; //$NON-NLS-1$
876 timeStampFormat
= input
.format
;
881 if (selectedLine
!= null && selectedLine
.inputLine
.equals(line
) && rootLineMatches
== 1) {
882 if (selectedLine
.inputs
.get(i
).previewText
.getText().equals(Messages
.CustomTxtParserInputWizardPage_noMatchingLine
)) {
883 selectedLine
.inputs
.get(i
).previewText
.setText(Messages
.CustomTxtParserInputWizardPage_noMatchingGroup
);
888 // highlight the matching groups that have no corresponponding input
889 for (int i
= line
.columns
.size(); i
< matcher
.groupCount(); i
++) {
890 if (matcher
.group(i
+1) != null) {
891 if (line
.parentInput
== null) {
892 inputText
.setStyleRange(new StyleRange(rawPos
+ matcher
.start(i
+1), matcher
.end(i
+1) - matcher
.start(i
+1),
893 COLOR_BLACK
, COLOR_MAGENTA
));
895 inputText
.setStyleRange(new StyleRange(rawPos
+ matcher
.start(i
+1), matcher
.end(i
+1) - matcher
.start(i
+1),
896 COLOR_BLACK
, COLOR_LIGHT_MAGENTA
));
902 private void openHelpShell(String url
) {
903 if (helpBrowser
!= null && !helpBrowser
.isDisposed()) {
904 helpBrowser
.getShell().setActive();
905 if (!helpBrowser
.getUrl().equals(url
)) {
906 helpBrowser
.setUrl(url
);
910 final Shell helpShell
= new Shell(getShell(), SWT
.SHELL_TRIM
);
911 helpShell
.setLayout(new FillLayout());
912 helpBrowser
= new Browser(helpShell
, SWT
.NONE
);
913 helpBrowser
.addTitleListener(new TitleListener() {
915 public void changed(TitleEvent event
) {
916 helpShell
.setText(event
.title
);
919 helpBrowser
.setBounds(0, 0, 600, 400);
922 helpBrowser
.setUrl(url
);
925 private void openLegend() {
926 final String cg
= Messages
.CustomTxtParserInputWizardPage_capturedGroup
;
927 final String ucg
= Messages
.CustomTxtParserInputWizardPage_unidentifiedCaptureGroup
;
928 final String ut
= Messages
.CustomTxtParserInputWizardPage_uncapturedText
;
930 String line1
= Messages
.CustomTxtParserInputWizardPage_nonMatchingLine
;
931 int line2start
= line1start
+ line1
.length();
932 String line2
= Messages
.CustomTxtParserInputWizardPage_matchingLineRoot
+ cg
+ ' ' + ucg
+ ' ' + ut
+ " \n"; //$NON-NLS-1$
933 int line3start
= line2start
+ line2
.length();
934 String line3
= Messages
.CustomTxtParserInputWizardPage_matchingOtherLine
+ cg
+ ' ' + ucg
+ ' ' + ut
+ " \n"; //$NON-NLS-1$
935 int line4start
= line3start
+ line3
.length();
936 String line4
= Messages
.CustomTxtParserInputWizardPage_matchingOtherLine
+ cg
+ ' ' + ucg
+ ' ' + ut
+ " \n"; //$NON-NLS-1$
937 int line5start
= line4start
+ line4
.length();
938 String line5
= Messages
.CustomTxtParserInputWizardPage_nonMatchingLine
;
939 int line6start
= line5start
+ line5
.length();
940 String line6
= Messages
.CustomTxtParserInputWizardPage_matchingRootLine
+ cg
+ ' ' + ucg
+ ' ' + ut
+ " \n"; //$NON-NLS-1$
942 final Shell legendShell
= new Shell(getShell(), SWT
.DIALOG_TRIM
);
943 legendShell
.setLayout(new FillLayout());
944 StyledText legendText
= new StyledText(legendShell
, SWT
.MULTI
);
945 legendText
.setFont(fixedFont
);
946 legendText
.setText(line1
+ line2
+ line3
+ line4
+ line5
+ line6
);
947 legendText
.setStyleRange(new StyleRange(line2start
, line2
.length(), COLOR_BLACK
, COLOR_YELLOW
, SWT
.ITALIC
));
948 legendText
.setStyleRange(new StyleRange(line3start
, line3
.length(), COLOR_BLACK
, COLOR_LIGHT_YELLOW
, SWT
.ITALIC
));
949 legendText
.setStyleRange(new StyleRange(line4start
, line4
.length(), COLOR_BLACK
, COLOR_LIGHT_YELLOW
, SWT
.ITALIC
));
950 legendText
.setStyleRange(new StyleRange(line6start
, line6
.length(), COLOR_BLACK
, COLOR_YELLOW
, SWT
.ITALIC
));
951 legendText
.setStyleRange(new StyleRange(line2start
+ line2
.indexOf(cg
), cg
.length(), COLOR_BLACK
, COLOR_GREEN
, SWT
.BOLD
));
952 legendText
.setStyleRange(new StyleRange(line2start
+ line2
.indexOf(ucg
), ucg
.length(), COLOR_BLACK
, COLOR_MAGENTA
));
953 legendText
.setStyleRange(new StyleRange(line3start
+ line3
.indexOf(cg
), cg
.length(), COLOR_BLACK
, COLOR_LIGHT_GREEN
, SWT
.BOLD
));
954 legendText
.setStyleRange(new StyleRange(line3start
+ line3
.indexOf(ucg
), ucg
.length(), COLOR_BLACK
, COLOR_LIGHT_MAGENTA
));
955 legendText
.setStyleRange(new StyleRange(line4start
+ line4
.indexOf(cg
), cg
.length(), COLOR_BLACK
, COLOR_LIGHT_GREEN
, SWT
.BOLD
));
956 legendText
.setStyleRange(new StyleRange(line4start
+ line4
.indexOf(ucg
), ucg
.length(), COLOR_BLACK
, COLOR_LIGHT_MAGENTA
));
957 legendText
.setStyleRange(new StyleRange(line6start
+ line6
.indexOf(cg
), cg
.length(), COLOR_BLACK
, COLOR_GREEN
, SWT
.BOLD
));
958 legendText
.setStyleRange(new StyleRange(line6start
+ line6
.indexOf(ucg
), ucg
.length(), COLOR_BLACK
, COLOR_MAGENTA
));
959 legendShell
.setText(Messages
.CustomTxtParserInputWizardPage_previewLegend
);
964 private class UpdateListener
implements ModifyListener
, SelectionListener
{
967 public void modifyText(ModifyEvent e
) {
973 public void widgetDefaultSelected(SelectionEvent e
) {
979 public void widgetSelected(SelectionEvent e
) {
987 private static final String INFINITY_STRING
= "\u221E"; //$NON-NLS-1$
988 private InputLine inputLine
;
990 private Composite labelComposite
;
991 private Text regexText
;
992 private Composite cardinalityContainer
;
993 private Combo cardinalityCombo
;
994 private Label cardinalityMinLabel
;
995 private Text cardinalityMinText
;
996 private Label cardinalityMaxLabel
;
997 private Text cardinalityMaxText
;
998 private Button infiniteButton
;
999 private List
<InputGroup
> inputs
= new ArrayList
<>();
1000 private Button addGroupButton
;
1001 private Label addGroupLabel
;
1003 public Line(Composite parent
, String name
, InputLine inputLine
) {
1004 this.inputLine
= inputLine
;
1006 group
= new Group(parent
, SWT
.NONE
);
1007 group
.setText(name
);
1008 group
.setLayout(new GridLayout(2, false));
1009 group
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
1011 labelComposite
= new Composite(group
, SWT
.FILL
);
1012 GridLayout labelLayout
= new GridLayout(1, false);
1013 labelLayout
.marginWidth
= 0;
1014 labelLayout
.marginHeight
= 0;
1015 labelComposite
.setLayout(labelLayout
);
1016 labelComposite
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
1018 Label label
= new Label(labelComposite
, SWT
.NULL
);
1019 label
.setText(Messages
.CustomTxtParserInputWizardPage_regularExpression
);
1021 Composite regexContainer
= new Composite(group
, SWT
.NONE
);
1022 GridLayout regexLayout
= new GridLayout(2, false);
1023 regexLayout
.marginHeight
= 0;
1024 regexLayout
.marginWidth
= 0;
1025 regexContainer
.setLayout(regexLayout
);
1026 regexContainer
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
1028 regexText
= new Text(regexContainer
, SWT
.BORDER
| SWT
.SINGLE
);
1029 GridData gd
= new GridData(SWT
.FILL
, SWT
.CENTER
, true, false);
1031 regexText
.setLayoutData(gd
);
1032 regexText
.setText(inputLine
.getRegex());
1033 regexText
.addModifyListener(updateListener
);
1035 Button regexHelpButton
= new Button(regexContainer
, SWT
.PUSH
);
1036 regexHelpButton
.setImage(HELP_IMAGE
);
1037 regexHelpButton
.setToolTipText(Messages
.CustomTxtParserInputWizardPage_regularExpressionHelp
);
1038 regexHelpButton
.addSelectionListener(new SelectionAdapter() {
1040 public void widgetSelected(SelectionEvent e
) {
1041 openHelpShell(PATTERN_URL
);
1045 label
= new Label(group
, SWT
.NONE
);
1046 label
.setText(Messages
.CustomTxtParserInputWizardPage_cardinality
);
1047 label
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
1049 cardinalityContainer
= new Composite(group
, SWT
.NONE
);
1050 GridLayout cardinalityLayout
= new GridLayout(6, false);
1051 cardinalityLayout
.marginHeight
= 0;
1052 cardinalityLayout
.marginWidth
= 0;
1053 cardinalityContainer
.setLayout(cardinalityLayout
);
1054 cardinalityContainer
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
1056 cardinalityCombo
= new Combo(cardinalityContainer
, SWT
.DROP_DOWN
| SWT
.READ_ONLY
);
1057 cardinalityCombo
.setItems(new String
[] {
1058 Cardinality
.ZERO_OR_MORE
.toString(),
1059 Cardinality
.ONE_OR_MORE
.toString(),
1060 Cardinality
.ZERO_OR_ONE
.toString(),
1061 Cardinality
.ONE
.toString(),
1062 "(?,?)"}); //$NON-NLS-1$
1063 cardinalityCombo
.addSelectionListener(new SelectionListener() {
1065 public void widgetDefaultSelected(SelectionEvent e
) {}
1068 public void widgetSelected(SelectionEvent e
) {
1069 switch (cardinalityCombo
.getSelectionIndex()) {
1071 cardinalityMinLabel
.setVisible(true);
1072 cardinalityMinText
.setVisible(true);
1073 cardinalityMaxLabel
.setVisible(true);
1074 cardinalityMaxText
.setVisible(true);
1075 infiniteButton
.setVisible(true);
1078 cardinalityMinLabel
.setVisible(false);
1079 cardinalityMinText
.setVisible(false);
1080 cardinalityMaxLabel
.setVisible(false);
1081 cardinalityMaxText
.setVisible(false);
1082 infiniteButton
.setVisible(false);
1085 cardinalityContainer
.layout();
1091 cardinalityMinLabel
= new Label(cardinalityContainer
, SWT
.NONE
);
1092 cardinalityMinLabel
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
1093 cardinalityMinLabel
.setText(Messages
.CustomTxtParserInputWizardPage_min
);
1094 cardinalityMinLabel
.setVisible(false);
1096 cardinalityMinText
= new Text(cardinalityContainer
, SWT
.BORDER
| SWT
.SINGLE
);
1097 gd
= new GridData(SWT
.CENTER
, SWT
.CENTER
, false, false);
1099 cardinalityMinText
.setLayoutData(gd
);
1100 cardinalityMinText
.setVisible(false);
1102 cardinalityMaxLabel
= new Label(cardinalityContainer
, SWT
.NONE
);
1103 cardinalityMaxLabel
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
1104 cardinalityMaxLabel
.setText(Messages
.CustomTxtParserInputWizardPage_max
);
1105 cardinalityMaxLabel
.setVisible(false);
1107 cardinalityMaxText
= new Text(cardinalityContainer
, SWT
.BORDER
| SWT
.SINGLE
);
1108 gd
= new GridData(SWT
.CENTER
, SWT
.CENTER
, false, false);
1110 cardinalityMaxText
.setLayoutData(gd
);
1111 cardinalityMaxText
.setVisible(false);
1113 infiniteButton
= new Button(cardinalityContainer
, SWT
.PUSH
);
1114 infiniteButton
.setText(INFINITY_STRING
);
1115 infiniteButton
.setVisible(false);
1116 infiniteButton
.addSelectionListener(new SelectionAdapter(){
1118 public void widgetSelected(SelectionEvent e
) {
1119 cardinalityMaxText
.setText(INFINITY_STRING
);
1122 if (inputLine
.cardinality
.equals(Cardinality
.ZERO_OR_MORE
)) {
1123 cardinalityCombo
.select(0);
1124 } else if (inputLine
.cardinality
.equals(Cardinality
.ONE_OR_MORE
)) {
1125 cardinalityCombo
.select(1);
1126 } else if (inputLine
.cardinality
.equals(Cardinality
.ZERO_OR_ONE
)) {
1127 cardinalityCombo
.select(2);
1128 } else if (inputLine
.cardinality
.equals(Cardinality
.ONE
)) {
1129 cardinalityCombo
.select(3);
1131 cardinalityCombo
.select(4);
1132 cardinalityMinLabel
.setVisible(true);
1133 cardinalityMinText
.setVisible(true);
1134 if (inputLine
.getMinCount() >= 0) {
1135 cardinalityMinText
.setText(Integer
.toString(inputLine
.getMinCount()));
1137 cardinalityMaxLabel
.setVisible(true);
1138 cardinalityMaxText
.setVisible(true);
1139 if (inputLine
.getMaxCount() == Cardinality
.INF
) {
1140 cardinalityMaxText
.setText(INFINITY_STRING
);
1141 } else if (inputLine
.getMaxCount() >= 0) {
1142 cardinalityMaxText
.setText(Integer
.toString(inputLine
.getMaxCount()));
1144 infiniteButton
.setVisible(true);
1147 VerifyListener digitsListener
= new VerifyListener() {
1149 public void verifyText(VerifyEvent e
) {
1150 if (e
.text
.equals(INFINITY_STRING
)) {
1151 e
.doit
= e
.widget
== cardinalityMaxText
&& e
.start
== 0 && e
.end
== ((Text
) e
.widget
).getText().length();
1153 if (((Text
) e
.widget
).getText().equals(INFINITY_STRING
)) {
1154 e
.doit
= e
.start
== 0 && e
.end
== ((Text
) e
.widget
).getText().length();
1156 for (int i
= 0; i
< e
.text
.length(); i
++) {
1157 if (!Character
.isDigit(e
.text
.charAt(i
))) {
1165 cardinalityMinText
.addModifyListener(updateListener
);
1166 cardinalityMaxText
.addModifyListener(updateListener
);
1167 cardinalityMinText
.addVerifyListener(digitsListener
);
1168 cardinalityMaxText
.addVerifyListener(digitsListener
);
1170 if (inputLine
.columns
!= null) {
1171 for (InputData inputData
: inputLine
.columns
) {
1172 InputGroup inputGroup
= new InputGroup(group
, this, inputs
.size()+1);
1173 if (inputData
.name
.equals(CustomTraceDefinition
.TAG_TIMESTAMP
)) {
1174 inputGroup
.tagCombo
.select(0);
1175 inputGroup
.tagText
.setText(inputData
.format
);
1176 inputGroup
.tagLabel
.setText(Messages
.CustomTxtParserInputWizardPage_format
);
1177 inputGroup
.tagLabel
.setVisible(true);
1178 inputGroup
.tagText
.setVisible(true);
1179 inputGroup
.tagText
.addModifyListener(updateListener
);
1180 } else if (inputData
.name
.equals(CustomTraceDefinition
.TAG_MESSAGE
)) {
1181 inputGroup
.tagCombo
.select(1);
1183 inputGroup
.tagCombo
.select(2);
1184 inputGroup
.tagText
.setText(inputData
.name
);
1185 inputGroup
.tagLabel
.setText(Messages
.CustomTxtParserInputWizardPage_name
);
1186 inputGroup
.tagLabel
.setVisible(true);
1187 inputGroup
.tagText
.setVisible(true);
1188 inputGroup
.tagText
.addModifyListener(updateListener
);
1190 inputGroup
.actionCombo
.select(inputData
.action
);
1191 inputs
.add(inputGroup
);
1195 createAddGroupButton();
1198 private void createAddGroupButton() {
1199 addGroupButton
= new Button(group
, SWT
.PUSH
);
1200 addGroupButton
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
1201 addGroupButton
.setImage(ADD_IMAGE
);
1202 addGroupButton
.setToolTipText(Messages
.CustomTxtParserInputWizardPage_addGroup
);
1203 addGroupButton
.addSelectionListener(new SelectionAdapter() {
1205 public void widgetSelected(SelectionEvent e
) {
1206 removeAddGroupButton();
1207 inputs
.add(new InputGroup(group
, Line
.this, inputs
.size()+1));
1208 createAddGroupButton();
1209 lineContainer
.layout();
1210 lineScrolledComposite
.setMinSize(lineContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).x
, lineContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).y
-1);
1211 group
.getParent().layout();
1217 addGroupLabel
= new Label(group
, SWT
.NULL
);
1218 addGroupLabel
.setText(Messages
.CustomTxtParserInputWizardPage_newGroup
);
1221 private void removeAddGroupButton() {
1222 addGroupButton
.dispose();
1223 addGroupLabel
.dispose();
1226 private void removeInput(int inputNumber
) {
1227 int nb
= inputNumber
;
1228 if (--nb
< inputs
.size()) {
1229 inputs
.remove(nb
).dispose();
1230 for (int i
= nb
; i
< inputs
.size(); i
++) {
1231 inputs
.get(i
).setInputNumber(i
+1);
1233 lineContainer
.layout();
1234 lineScrolledComposite
.setMinSize(lineContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).x
, lineContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).y
-1);
1235 group
.getParent().layout();
1239 private void dispose() {
1243 private void extractInputs() {
1244 inputLine
.setRegex(selectedLine
.regexText
.getText());
1245 switch (cardinalityCombo
.getSelectionIndex()) {
1247 inputLine
.cardinality
= Cardinality
.ZERO_OR_MORE
;
1250 inputLine
.cardinality
= Cardinality
.ONE_OR_MORE
;
1253 inputLine
.cardinality
= Cardinality
.ZERO_OR_ONE
;
1256 inputLine
.cardinality
= Cardinality
.ONE
;
1261 min
= Integer
.parseInt(cardinalityMinText
.getText());
1262 } catch (NumberFormatException e
) {
1266 if (cardinalityMaxText
.getText().equals(INFINITY_STRING
)) {
1267 max
= Cardinality
.INF
;
1269 max
= Integer
.parseInt(cardinalityMaxText
.getText());
1271 } catch (NumberFormatException e
) {
1274 inputLine
.cardinality
= new Cardinality(min
, max
);
1277 inputLine
.cardinality
= Cardinality
.ZERO_OR_MORE
;
1280 inputLine
.columns
= new ArrayList
<>(inputs
.size());
1281 for (int i
= 0; i
< inputs
.size(); i
++) {
1282 InputGroup grp
= inputs
.get(i
);
1283 InputData inputData
= new InputData();
1284 if (grp
.tagCombo
.getText().equals(CustomTraceDefinition
.TAG_OTHER
)) {
1285 inputData
.name
= grp
.tagText
.getText().trim();
1287 inputData
.name
= grp
.tagCombo
.getText();
1288 if (grp
.tagCombo
.getText().equals(CustomTraceDefinition
.TAG_TIMESTAMP
)) {
1289 inputData
.format
= grp
.tagText
.getText().trim();
1292 inputData
.action
= grp
.actionCombo
.getSelectionIndex();
1293 inputLine
.columns
.add(inputData
);
1298 private class InputGroup
{
1300 private int inputNumber
;
1302 // children of parent (must be disposed)
1303 private Composite labelComposite
;
1304 private Composite tagComposite
;
1305 private Label previewLabel
;
1306 private Text previewText
;
1308 // children of labelComposite
1309 private Label inputLabel
;
1311 // children of tagComposite
1312 private Combo tagCombo
;
1313 private Label tagLabel
;
1314 private Text tagText
;
1315 private Combo actionCombo
;
1317 public InputGroup(Composite parent
, Line line
, int inputNumber
) {
1319 this.inputNumber
= inputNumber
;
1321 labelComposite
= new Composite(parent
, SWT
.FILL
);
1322 GridLayout labelLayout
= new GridLayout(2, false);
1323 labelLayout
.marginWidth
= 0;
1324 labelLayout
.marginHeight
= 0;
1325 labelComposite
.setLayout(labelLayout
);
1326 labelComposite
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
1328 Button deleteButton
= new Button(labelComposite
, SWT
.PUSH
);
1329 deleteButton
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
1330 deleteButton
.setImage(DELETE_IMAGE
);
1331 deleteButton
.setToolTipText(Messages
.CustomTxtParserInputWizardPage_removeGroup
);
1332 deleteButton
.addSelectionListener(new SelectionAdapter() {
1334 public void widgetSelected(SelectionEvent e
) {
1335 InputGroup
.this.line
.removeInput(InputGroup
.this.inputNumber
);
1341 inputLabel
= new Label(labelComposite
, SWT
.NULL
);
1342 inputLabel
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
1343 inputLabel
.setText(Messages
.CustomTxtParserInputWizardPage_group
+ inputNumber
+ ":"); //$NON-NLS-1$
1345 tagComposite
= new Composite(parent
, SWT
.FILL
);
1346 GridLayout tagLayout
= new GridLayout(4, false);
1347 tagLayout
.marginWidth
= 0;
1348 tagLayout
.marginHeight
= 0;
1349 tagComposite
.setLayout(tagLayout
);
1350 tagComposite
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
1352 tagCombo
= new Combo(tagComposite
, SWT
.DROP_DOWN
| SWT
.READ_ONLY
);
1353 tagCombo
.setItems(new String
[] {CustomTraceDefinition
.TAG_TIMESTAMP
,
1354 CustomTraceDefinition
.TAG_MESSAGE
,
1355 CustomTraceDefinition
.TAG_OTHER
});
1357 tagCombo
.addSelectionListener(new SelectionListener(){
1359 public void widgetDefaultSelected(SelectionEvent e
) {}
1361 public void widgetSelected(SelectionEvent e
) {
1362 tagText
.removeModifyListener(updateListener
);
1363 switch (tagCombo
.getSelectionIndex()) {
1364 case 0: //Time Stamp
1365 tagLabel
.setText(Messages
.CustomTxtParserInputWizardPage_format
);
1366 tagLabel
.setVisible(true);
1367 tagText
.setVisible(true);
1368 tagText
.addModifyListener(updateListener
);
1371 tagLabel
.setVisible(false);
1372 tagText
.setVisible(false);
1375 tagLabel
.setText(Messages
.CustomTxtParserInputWizardPage_name
);
1376 tagLabel
.setVisible(true);
1377 tagText
.setVisible(true);
1378 tagText
.addModifyListener(updateListener
);
1381 tagLabel
.setVisible(false);
1382 tagText
.setVisible(false);
1387 tagComposite
.layout();
1392 tagLabel
= new Label(tagComposite
, SWT
.NULL
);
1393 tagLabel
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
1394 tagLabel
.setVisible(false);
1396 tagText
= new Text(tagComposite
, SWT
.BORDER
| SWT
.SINGLE
);
1397 GridData gd
= new GridData(SWT
.FILL
, SWT
.CENTER
, true, false);
1399 tagText
.setLayoutData(gd
);
1400 tagText
.setVisible(false);
1402 actionCombo
= new Combo(tagComposite
, SWT
.DROP_DOWN
| SWT
.READ_ONLY
);
1403 actionCombo
.setItems(new String
[] {Messages
.CustomTxtParserInputWizardPage_set
, Messages
.CustomTxtParserInputWizardPage_append
, Messages
.CustomTxtParserInputWizardPage_appendWith
});
1404 actionCombo
.select(0);
1405 actionCombo
.addSelectionListener(updateListener
);
1407 previewLabel
= new Label(parent
, SWT
.NULL
);
1408 previewLabel
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
1409 previewLabel
.setText(Messages
.CustomTxtParserInputWizardPage_preview
);
1411 previewText
= new Text(parent
, SWT
.BORDER
| SWT
.SINGLE
| SWT
.READ_ONLY
);
1412 gd
= new GridData(SWT
.FILL
, SWT
.CENTER
, true, false);
1414 previewText
.setLayoutData(gd
);
1415 previewText
.setText(Messages
.CustomTxtParserInputWizardPage_noMatch
);
1416 previewText
.setBackground(COLOR_WIDGET_BACKGROUND
);
1419 private void dispose() {
1420 labelComposite
.dispose();
1421 tagComposite
.dispose();
1422 previewLabel
.dispose();
1423 previewText
.dispose();
1426 private void setInputNumber(int inputNumber
) {
1427 this.inputNumber
= inputNumber
;
1428 inputLabel
.setText(Messages
.CustomTxtParserInputWizardPage_group
+ inputNumber
+ ":"); //$NON-NLS-1$
1429 labelComposite
.layout();
1433 private void validate() {
1435 definition
.definitionName
= logtypeText
.getText().trim();
1436 definition
.timeStampOutputFormat
= timestampOutputFormatText
.getText().trim();
1438 if (selectedLine
!= null) {
1439 selectedLine
.extractInputs();
1440 treeViewer
.refresh();
1443 StringBuffer errors
= new StringBuffer();
1445 if (definition
.definitionName
.length() == 0) {
1446 errors
.append("Enter a name for the new log type. "); //$NON-NLS-1$
1447 logtypeText
.setBackground(COLOR_LIGHT_RED
);
1449 logtypeText
.setBackground(COLOR_TEXT_BACKGROUND
);
1450 for (CustomTxtTraceDefinition def
: CustomTxtTraceDefinition
.loadAll()) {
1451 if (definition
.definitionName
.equals(def
.definitionName
) &&
1452 (editDefinitionName
== null || !editDefinitionName
.equals(definition
.definitionName
))) {
1453 errors
.append("The log type name already exists. "); //$NON-NLS-1$
1454 logtypeText
.setBackground(COLOR_LIGHT_RED
);
1460 timestampFound
= false;
1461 for (int i
= 0; i
< definition
.inputs
.size(); i
++) {
1463 InputLine inputLine
= definition
.inputs
.get(i
);
1464 String name
= Integer
.toString(i
+1);
1465 errors
.append(validateLine(inputLine
, name
));
1467 if (timestampFound
) {
1468 if (definition
.timeStampOutputFormat
.length() == 0) {
1469 errors
.append("Enter the output format for the Time Stamp field. "); //$NON-NLS-1$
1470 timestampOutputFormatText
.setBackground(COLOR_LIGHT_RED
);
1473 new SimpleDateFormat(definition
.timeStampOutputFormat
);
1474 timestampOutputFormatText
.setBackground(COLOR_TEXT_BACKGROUND
);
1475 } catch (IllegalArgumentException e
) {
1476 errors
.append("Enter a valid output format for the Time Stamp field. "); //$NON-NLS-1$
1477 timestampOutputFormatText
.setBackground(COLOR_LIGHT_RED
);
1482 timestampOutputFormatText
.setBackground(COLOR_TEXT_BACKGROUND
);
1485 if (errors
.length() == 0) {
1486 setDescription(defaultDescription
);
1487 setPageComplete(true);
1489 setDescription(errors
.toString());
1490 setPageComplete(false);
1495 * Validate an input line.
1498 * The line to clean up
1500 * The name of the line
1501 * @return The cleaned up line
1503 public StringBuffer
validateLine(InputLine inputLine
, String name
) {
1504 StringBuffer errors
= new StringBuffer();
1506 if (selectedLine
!= null && selectedLine
.inputLine
.equals(inputLine
)) {
1507 line
= selectedLine
;
1510 Pattern
.compile(inputLine
.getRegex());
1512 line
.regexText
.setBackground(COLOR_TEXT_BACKGROUND
);
1514 } catch (PatternSyntaxException e
) {
1515 errors
.append("Enter a valid regular expression (Line "+name
+"). "); //$NON-NLS-1$ //$NON-NLS-2$
1517 line
.regexText
.setBackground(COLOR_LIGHT_RED
);
1520 if (inputLine
.getMinCount() == -1) {
1521 errors
.append("Enter a minimum value for cardinality (Line "+name
+"). "); //$NON-NLS-1$ //$NON-NLS-2$
1523 line
.cardinalityMinText
.setBackground(COLOR_LIGHT_RED
);
1527 line
.cardinalityMinText
.setBackground(COLOR_TEXT_BACKGROUND
);
1530 if (inputLine
.getMaxCount() == -1) {
1531 errors
.append("Enter a maximum value for cardinality (Line "+name
+"). "); //$NON-NLS-1$ //$NON-NLS-2$
1533 line
.cardinalityMaxText
.setBackground(COLOR_LIGHT_RED
);
1535 } else if (inputLine
.getMinCount() > inputLine
.getMaxCount()) {
1536 errors
.append("Enter correct (min <= max) values for cardinality (Line "+name
+"). "); //$NON-NLS-1$ //$NON-NLS-2$
1538 line
.cardinalityMinText
.setBackground(COLOR_LIGHT_RED
);
1541 line
.cardinalityMaxText
.setBackground(COLOR_LIGHT_RED
);
1545 line
.cardinalityMaxText
.setBackground(COLOR_TEXT_BACKGROUND
);
1548 for (int i
= 0; inputLine
.columns
!= null && i
< inputLine
.columns
.size(); i
++) {
1549 InputData inputData
= inputLine
.columns
.get(i
);
1550 InputGroup group
= null;
1552 group
= line
.inputs
.get(i
);
1554 if (inputData
.name
.equals(CustomTraceDefinition
.TAG_TIMESTAMP
)) {
1555 timestampFound
= true;
1556 if (inputData
.format
.length() == 0) {
1557 errors
.append("Enter the input format for the Time Stamp (Line "+name
+" Group "+(i
+1)+"). "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
1558 if (group
!= null) {
1559 group
.tagText
.setBackground(COLOR_LIGHT_RED
);
1563 new SimpleDateFormat(inputData
.format
);
1564 if (group
!= null) {
1565 group
.tagText
.setBackground(COLOR_TEXT_BACKGROUND
);
1567 } catch (IllegalArgumentException e
) {
1568 errors
.append("Enter a valid input format for the Time Stamp (Line "+name
+" Group "+(i
+1)+"). "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
1569 if (group
!= null) {
1570 group
.tagText
.setBackground(COLOR_LIGHT_RED
);
1574 } else if (inputData
.name
.length() == 0) {
1575 errors
.append("Enter a name for the data group (Line "+name
+" Group "+(i
+1)+"). "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
1576 if (group
!= null) {
1577 group
.tagText
.setBackground(COLOR_LIGHT_RED
);
1580 if (group
!= null) {
1581 group
.tagText
.setBackground(COLOR_TEXT_BACKGROUND
);
1585 for (int i
= 0; inputLine
.childrenInputs
!= null && i
< inputLine
.childrenInputs
.size(); i
++) {
1586 errors
.append(validateLine(inputLine
.childrenInputs
.get(i
), name
+"."+(i
+1))); //$NON-NLS-1$
1592 * Get the trace definition.
1594 * @return The trace definition
1596 public CustomTxtTraceDefinition
getDefinition() {
1601 * Get the raw text of the input.
1603 * @return The raw input text
1605 public char[] getInputText() {
1606 return inputText
.getText().toCharArray();