1 /*******************************************************************************
2 * Copyright (c) 2010, 2014 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
.util
.ArrayList
;
20 import java
.util
.Arrays
;
21 import java
.util
.HashMap
;
22 import java
.util
.Iterator
;
23 import java
.util
.List
;
25 import java
.util
.Scanner
;
26 import java
.util
.regex
.Matcher
;
27 import java
.util
.regex
.Pattern
;
28 import java
.util
.regex
.PatternSyntaxException
;
30 import org
.eclipse
.core
.resources
.IFile
;
31 import org
.eclipse
.core
.runtime
.CoreException
;
32 import org
.eclipse
.jface
.viewers
.ColumnLabelProvider
;
33 import org
.eclipse
.jface
.viewers
.ISelection
;
34 import org
.eclipse
.jface
.viewers
.ISelectionChangedListener
;
35 import org
.eclipse
.jface
.viewers
.IStructuredSelection
;
36 import org
.eclipse
.jface
.viewers
.ITreeContentProvider
;
37 import org
.eclipse
.jface
.viewers
.SelectionChangedEvent
;
38 import org
.eclipse
.jface
.viewers
.StructuredSelection
;
39 import org
.eclipse
.jface
.viewers
.TreeViewer
;
40 import org
.eclipse
.jface
.viewers
.Viewer
;
41 import org
.eclipse
.jface
.wizard
.WizardPage
;
42 import org
.eclipse
.linuxtools
.internal
.tmf
.ui
.Activator
;
43 import org
.eclipse
.linuxtools
.internal
.tmf
.ui
.Messages
;
44 import org
.eclipse
.linuxtools
.tmf
.core
.parsers
.custom
.CustomTraceDefinition
;
45 import org
.eclipse
.linuxtools
.tmf
.core
.parsers
.custom
.CustomTxtTraceDefinition
;
46 import org
.eclipse
.linuxtools
.tmf
.core
.parsers
.custom
.CustomTxtTraceDefinition
.Cardinality
;
47 import org
.eclipse
.linuxtools
.tmf
.core
.parsers
.custom
.CustomTxtTraceDefinition
.InputData
;
48 import org
.eclipse
.linuxtools
.tmf
.core
.parsers
.custom
.CustomTxtTraceDefinition
.InputLine
;
49 import org
.eclipse
.linuxtools
.tmf
.core
.timestamp
.TmfTimestampFormat
;
50 import org
.eclipse
.swt
.SWT
;
51 import org
.eclipse
.swt
.browser
.Browser
;
52 import org
.eclipse
.swt
.browser
.TitleEvent
;
53 import org
.eclipse
.swt
.browser
.TitleListener
;
54 import org
.eclipse
.swt
.custom
.SashForm
;
55 import org
.eclipse
.swt
.custom
.ScrolledComposite
;
56 import org
.eclipse
.swt
.custom
.StyleRange
;
57 import org
.eclipse
.swt
.custom
.StyledText
;
58 import org
.eclipse
.swt
.events
.ModifyEvent
;
59 import org
.eclipse
.swt
.events
.ModifyListener
;
60 import org
.eclipse
.swt
.events
.SelectionAdapter
;
61 import org
.eclipse
.swt
.events
.SelectionEvent
;
62 import org
.eclipse
.swt
.events
.SelectionListener
;
63 import org
.eclipse
.swt
.events
.VerifyEvent
;
64 import org
.eclipse
.swt
.events
.VerifyListener
;
65 import org
.eclipse
.swt
.graphics
.Color
;
66 import org
.eclipse
.swt
.graphics
.Font
;
67 import org
.eclipse
.swt
.graphics
.FontData
;
68 import org
.eclipse
.swt
.graphics
.Image
;
69 import org
.eclipse
.swt
.layout
.FillLayout
;
70 import org
.eclipse
.swt
.layout
.GridData
;
71 import org
.eclipse
.swt
.layout
.GridLayout
;
72 import org
.eclipse
.swt
.widgets
.Button
;
73 import org
.eclipse
.swt
.widgets
.Combo
;
74 import org
.eclipse
.swt
.widgets
.Composite
;
75 import org
.eclipse
.swt
.widgets
.Display
;
76 import org
.eclipse
.swt
.widgets
.Group
;
77 import org
.eclipse
.swt
.widgets
.Label
;
78 import org
.eclipse
.swt
.widgets
.Shell
;
79 import org
.eclipse
.swt
.widgets
.Text
;
82 * Input wizard page for custom text parsers.
84 * @author Patrick Tasse
86 public class CustomTxtParserInputWizardPage
extends WizardPage
{
88 private static final String DEFAULT_REGEX
= "\\s*(.*\\S)"; //$NON-NLS-1$
89 private static final String DEFAULT_TIMESTAMP_FORMAT
= "yyyy-MM-dd HH:mm:ss.SSS"; //$NON-NLS-1$
90 private static final String SIMPLE_DATE_FORMAT_URL
= "http://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html#skip-navbar_top"; //$NON-NLS-1$
91 private static final String PATTERN_URL
= "http://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html#sum"; //$NON-NLS-1$
92 private static final Image LINE_IMAGE
= Activator
.getDefault().getImageFromPath("/icons/elcl16/line_icon.gif"); //$NON-NLS-1$
93 private static final Image ADD_IMAGE
= Activator
.getDefault().getImageFromPath("/icons/elcl16/add_button.gif"); //$NON-NLS-1$
94 private static final Image ADD_NEXT_IMAGE
= Activator
.getDefault().getImageFromPath("/icons/elcl16/addnext_button.gif"); //$NON-NLS-1$
95 private static final Image ADD_CHILD_IMAGE
= Activator
.getDefault().getImageFromPath("/icons/elcl16/addchild_button.gif"); //$NON-NLS-1$
96 private static final Image DELETE_IMAGE
= Activator
.getDefault().getImageFromPath("/icons/elcl16/delete_button.gif"); //$NON-NLS-1$
97 private static final Image MOVE_UP_IMAGE
= Activator
.getDefault().getImageFromPath("/icons/elcl16/moveup_button.gif"); //$NON-NLS-1$
98 private static final Image MOVE_DOWN_IMAGE
= Activator
.getDefault().getImageFromPath("/icons/elcl16/movedown_button.gif"); //$NON-NLS-1$
99 private static final Image HELP_IMAGE
= Activator
.getDefault().getImageFromPath("/icons/elcl16/help_button.gif"); //$NON-NLS-1$
100 private static final Color COLOR_BLACK
= Display
.getDefault().getSystemColor(SWT
.COLOR_BLACK
);
101 private static final Color COLOR_LIGHT_GREEN
= new Color(Display
.getDefault(), 192, 255, 192);
102 private static final Color COLOR_GREEN
= Display
.getDefault().getSystemColor(SWT
.COLOR_GREEN
);
103 private static final Color COLOR_LIGHT_YELLOW
= new Color(Display
.getDefault(), 255, 255, 192);
104 private static final Color COLOR_YELLOW
= Display
.getDefault().getSystemColor(SWT
.COLOR_YELLOW
);
105 private static final Color COLOR_LIGHT_MAGENTA
= new Color(Display
.getDefault(), 255, 192, 255);
106 private static final Color COLOR_MAGENTA
= Display
.getDefault().getSystemColor(SWT
.COLOR_MAGENTA
);
107 private static final Color COLOR_LIGHT_RED
= new Color(Display
.getDefault(), 255, 192, 192);
108 private static final Color COLOR_TEXT_BACKGROUND
= Display
.getDefault().getSystemColor(SWT
.COLOR_WHITE
);
109 private static final Color COLOR_WIDGET_BACKGROUND
= Display
.getDefault().getSystemColor(SWT
.COLOR_WIDGET_BACKGROUND
);
111 private final ISelection selection
;
112 private CustomTxtTraceDefinition definition
;
113 private String editDefinitionName
;
114 private String defaultDescription
;
115 private Line selectedLine
;
116 private Composite container
;
117 private Text logtypeText
;
118 private Text timestampOutputFormatText
;
119 private Text timestampPreviewText
;
120 private ScrolledComposite lineScrolledComposite
;
121 private TreeViewer treeViewer
;
122 private Composite lineContainer
;
123 private StyledText inputText
;
124 private Font fixedFont
;
125 private UpdateListener updateListener
;
126 private Browser helpBrowser
;
128 // variables used recursively through line traversal
129 private String timeStampFormat
;
130 private boolean timestampFound
;
136 * The Selection object
138 * The trace definition
140 protected CustomTxtParserInputWizardPage(ISelection selection
,
141 CustomTxtTraceDefinition definition
) {
142 super("CustomParserWizardPage"); //$NON-NLS-1$
143 if (definition
== null) {
144 setTitle(Messages
.CustomTxtParserInputWizardPage_windowTitleNew
);
145 defaultDescription
= Messages
.CustomTxtParserInputWizardPage_descriptionNew
;
147 setTitle(Messages
.CustomTxtParserInputWizardPage_windowTitleEdit
);
148 defaultDescription
= Messages
.CustomTxtParserInputWizardPage_desccriptionEdit
;
150 setDescription(defaultDescription
);
151 this.selection
= selection
;
152 this.definition
= definition
;
153 if (definition
!= null) {
154 this.editDefinitionName
= definition
.definitionName
;
159 public void createControl(Composite parent
) {
160 container
= new Composite(parent
, SWT
.NULL
);
161 container
.setLayout(new GridLayout());
163 updateListener
= new UpdateListener();
165 Composite headerComposite
= new Composite(container
, SWT
.FILL
);
166 GridLayout headerLayout
= new GridLayout(5, false);
167 headerLayout
.marginHeight
= 0;
168 headerLayout
.marginWidth
= 0;
169 headerComposite
.setLayout(headerLayout
);
170 headerComposite
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
172 Label logtypeLabel
= new Label(headerComposite
, SWT
.NULL
);
173 logtypeLabel
.setText(Messages
.CustomTxtParserInputWizardPage_logType
);
175 logtypeText
= new Text(headerComposite
, SWT
.BORDER
| SWT
.SINGLE
);
176 logtypeText
.setLayoutData(new GridData(120, SWT
.DEFAULT
));
178 Label timestampFormatLabel
= new Label(headerComposite
, SWT
.NULL
);
179 timestampFormatLabel
.setText(Messages
.CustomTxtParserInputWizardPage_timestampFormat
);
181 timestampOutputFormatText
= new Text(headerComposite
, SWT
.BORDER
| SWT
.SINGLE
);
182 timestampOutputFormatText
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
183 timestampOutputFormatText
.setText(DEFAULT_TIMESTAMP_FORMAT
);
185 Button dateFormatHelpButton
= new Button(headerComposite
, SWT
.PUSH
);
186 dateFormatHelpButton
.setImage(HELP_IMAGE
);
187 dateFormatHelpButton
.setToolTipText(Messages
.CustomTxtParserInputWizardPage_dateFormatHelp
);
188 dateFormatHelpButton
.addSelectionListener(new SelectionAdapter() {
190 public void widgetSelected(SelectionEvent e
) {
191 openHelpShell(SIMPLE_DATE_FORMAT_URL
);
195 Label timestampPreviewLabel
= new Label(headerComposite
, SWT
.NULL
);
196 timestampPreviewLabel
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false, 3, 1));
197 timestampPreviewLabel
.setText(Messages
.CustomTxtParserInputWizardPage_preview
);
199 timestampPreviewText
= new Text(headerComposite
, SWT
.BORDER
| SWT
.SINGLE
| SWT
.READ_ONLY
);
200 timestampPreviewText
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false, 2, 1));
201 timestampPreviewText
.setText(Messages
.CustomTxtParserInputWizardPage_noMatchingTimestamp
);
203 Composite buttonBar
= new Composite(container
, SWT
.NONE
);
204 GridLayout buttonBarLayout
= new GridLayout(5, false);
205 buttonBarLayout
.marginHeight
= 0;
206 buttonBarLayout
.marginWidth
= 0;
207 buttonBar
.setLayout(buttonBarLayout
);
209 Button removeButton
= new Button(buttonBar
, SWT
.PUSH
);
210 removeButton
.setImage(DELETE_IMAGE
);
211 removeButton
.setToolTipText(Messages
.CustomTxtParserInputWizardPage_removeLine
);
212 removeButton
.addSelectionListener(new SelectionAdapter() {
214 public void widgetSelected(SelectionEvent e
) {
215 if (treeViewer
.getSelection().isEmpty() || selectedLine
== null) {
219 InputLine inputLine
= (InputLine
) ((IStructuredSelection
) treeViewer
.getSelection()).getFirstElement();
220 if (inputLine
.parentInput
== null) {
221 definition
.inputs
.remove(inputLine
);
223 inputLine
.parentInput
.childrenInputs
.remove(inputLine
);
225 treeViewer
.refresh();
230 Button addNextButton
= new Button(buttonBar
, SWT
.PUSH
);
231 addNextButton
.setImage(ADD_NEXT_IMAGE
);
232 addNextButton
.setToolTipText(Messages
.CustomTxtParserInputWizardPage_addNextLine
);
233 addNextButton
.addSelectionListener(new SelectionAdapter() {
235 public void widgetSelected(SelectionEvent e
) {
236 InputLine inputLine
= new InputLine(Cardinality
.ZERO_OR_MORE
, "", null); //$NON-NLS-1$
237 if (((List
<?
>) treeViewer
.getInput()).size() == 0) {
238 definition
.inputs
.add(inputLine
);
239 } else if (treeViewer
.getSelection().isEmpty()) {
242 InputLine previousInputLine
= (InputLine
) ((IStructuredSelection
) treeViewer
.getSelection()).getFirstElement();
243 if (previousInputLine
.parentInput
== null) {
244 for (int i
= 0; i
< definition
.inputs
.size(); i
++) {
245 if (definition
.inputs
.get(i
).equals(previousInputLine
)) {
246 definition
.inputs
.add(i
+ 1, inputLine
);
250 previousInputLine
.addNext(inputLine
);
253 treeViewer
.refresh();
254 treeViewer
.setSelection(new StructuredSelection(inputLine
), true);
257 Button addChildButton
= new Button(buttonBar
, SWT
.PUSH
);
258 addChildButton
.setImage(ADD_CHILD_IMAGE
);
259 addChildButton
.setToolTipText(Messages
.CustomTxtParserInputWizardPage_addChildLine
);
260 addChildButton
.addSelectionListener(new SelectionAdapter() {
262 public void widgetSelected(SelectionEvent e
) {
263 InputLine inputLine
= new InputLine(Cardinality
.ZERO_OR_MORE
, "", null); //$NON-NLS-1$
264 if (((List
<?
>) treeViewer
.getInput()).size() == 0) {
265 definition
.inputs
.add(inputLine
);
266 } else if (treeViewer
.getSelection().isEmpty()) {
269 InputLine parentInputLine
= (InputLine
) ((IStructuredSelection
) treeViewer
.getSelection()).getFirstElement();
270 parentInputLine
.addChild(inputLine
);
272 treeViewer
.refresh();
273 treeViewer
.setSelection(new StructuredSelection(inputLine
), true);
276 Button moveUpButton
= new Button(buttonBar
, SWT
.PUSH
);
277 moveUpButton
.setImage(MOVE_UP_IMAGE
);
278 moveUpButton
.setToolTipText(Messages
.CustomTxtParserInputWizardPage_moveUp
);
279 moveUpButton
.addSelectionListener(new SelectionAdapter() {
281 public void widgetSelected(SelectionEvent e
) {
282 if (treeViewer
.getSelection().isEmpty()) {
285 InputLine inputLine
= (InputLine
) ((IStructuredSelection
) treeViewer
.getSelection()).getFirstElement();
286 if (inputLine
.parentInput
== null) {
287 for (int i
= 1; i
< definition
.inputs
.size(); i
++) {
288 if (definition
.inputs
.get(i
).equals(inputLine
)) {
289 definition
.inputs
.add(i
- 1 , definition
.inputs
.remove(i
));
296 treeViewer
.refresh();
301 Button moveDownButton
= new Button(buttonBar
, SWT
.PUSH
);
302 moveDownButton
.setImage(MOVE_DOWN_IMAGE
);
303 moveDownButton
.setToolTipText(Messages
.CustomTxtParserInputWizardPage_moveDown
);
304 moveDownButton
.addSelectionListener(new SelectionAdapter() {
306 public void widgetSelected(SelectionEvent e
) {
307 if (treeViewer
.getSelection().isEmpty()) {
310 InputLine inputLine
= (InputLine
) ((IStructuredSelection
) treeViewer
.getSelection()).getFirstElement();
311 if (inputLine
.parentInput
== null) {
312 for (int i
= 0; i
< definition
.inputs
.size() - 1; i
++) {
313 if (definition
.inputs
.get(i
).equals(inputLine
)) {
314 definition
.inputs
.add(i
+ 1 , definition
.inputs
.remove(i
));
319 inputLine
.moveDown();
321 treeViewer
.refresh();
327 SashForm vSash
= new SashForm(container
, SWT
.VERTICAL
);
328 vSash
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
329 vSash
.setBackground(vSash
.getDisplay().getSystemColor(SWT
.COLOR_GRAY
));
331 SashForm hSash
= new SashForm(vSash
, SWT
.HORIZONTAL
);
332 hSash
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
334 ScrolledComposite treeScrolledComposite
= new ScrolledComposite(hSash
, SWT
.V_SCROLL
| SWT
.H_SCROLL
);
335 GridData gd
= new GridData(SWT
.FILL
, SWT
.FILL
, true, true);
338 treeScrolledComposite
.setLayoutData(gd
);
339 Composite treeContainer
= new Composite(treeScrolledComposite
, SWT
.NONE
);
340 treeContainer
.setLayout(new FillLayout());
341 treeScrolledComposite
.setContent(treeContainer
);
342 treeScrolledComposite
.setExpandHorizontal(true);
343 treeScrolledComposite
.setExpandVertical(true);
345 treeViewer
= new TreeViewer(treeContainer
, SWT
.SINGLE
| SWT
.BORDER
);
346 treeViewer
.setContentProvider(new InputLineTreeNodeContentProvider());
347 treeViewer
.setLabelProvider(new InputLineTreeLabelProvider());
348 treeViewer
.addSelectionChangedListener(new InputLineTreeSelectionChangedListener());
349 treeContainer
.layout();
351 treeScrolledComposite
.setMinSize(treeContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).x
, treeContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).y
);
353 lineScrolledComposite
= new ScrolledComposite(hSash
, SWT
.V_SCROLL
);
354 lineScrolledComposite
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
355 lineContainer
= new Composite(lineScrolledComposite
, SWT
.NONE
);
356 GridLayout linesLayout
= new GridLayout();
357 linesLayout
.marginHeight
= 1;
358 linesLayout
.marginWidth
= 0;
359 lineContainer
.setLayout(linesLayout
);
360 lineScrolledComposite
.setContent(lineContainer
);
361 lineScrolledComposite
.setExpandHorizontal(true);
362 lineScrolledComposite
.setExpandVertical(true);
364 if (definition
== null) {
365 definition
= new CustomTxtTraceDefinition();
366 definition
.inputs
.add(new InputLine(Cardinality
.ZERO_OR_MORE
, DEFAULT_REGEX
,
367 Arrays
.asList(new InputData(CustomTraceDefinition
.TAG_MESSAGE
, CustomTraceDefinition
.ACTION_SET
))));
369 loadDefinition(definition
);
370 treeViewer
.expandAll();
371 lineContainer
.layout();
373 logtypeText
.addModifyListener(updateListener
);
374 timestampOutputFormatText
.addModifyListener(updateListener
);
376 lineScrolledComposite
.setMinSize(lineContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).x
, lineContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).y
-1);
378 hSash
.setWeights(new int[] {1, 2});
380 Composite sashBottom
= new Composite(vSash
, SWT
.NONE
);
381 GridLayout sashBottomLayout
= new GridLayout(3, false);
382 sashBottomLayout
.marginHeight
= 0;
383 sashBottomLayout
.marginWidth
= 0;
384 sashBottom
.setLayout(sashBottomLayout
);
386 Label previewLabel
= new Label(sashBottom
, SWT
.NULL
);
387 previewLabel
.setText(Messages
.CustomTxtParserInputWizardPage_previewInput
);
388 previewLabel
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
390 Button highlightAllButton
= new Button(sashBottom
, SWT
.PUSH
);
391 highlightAllButton
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
392 highlightAllButton
.setText(Messages
.CustomTxtParserInputWizardPage_highlightAll
);
393 highlightAllButton
.addSelectionListener(new SelectionAdapter() {
395 public void widgetSelected(SelectionEvent e
) {
396 updatePreviews(true);
400 Button legendButton
= new Button(sashBottom
, SWT
.PUSH
);
401 legendButton
.setImage(HELP_IMAGE
);
402 legendButton
.setToolTipText(Messages
.CustomTxtParserInputWizardPage_previewLegend
);
403 legendButton
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
404 legendButton
.addSelectionListener(new SelectionAdapter() {
406 public void widgetSelected(SelectionEvent e
) {
411 inputText
= new StyledText(sashBottom
, SWT
.MULTI
| SWT
.V_SCROLL
| SWT
.H_SCROLL
);
412 if (fixedFont
== null) {
413 if (System
.getProperty("os.name").contains("Windows")) { //$NON-NLS-1$ //$NON-NLS-2$
414 fixedFont
= new Font(Display
.getCurrent(), new FontData("Courier New", 10, SWT
.NORMAL
)); //$NON-NLS-1$
416 fixedFont
= new Font(Display
.getCurrent(), new FontData("Monospace", 10, SWT
.NORMAL
)); //$NON-NLS-1$
419 inputText
.setFont(fixedFont
);
420 gd
= new GridData(SWT
.FILL
, SWT
.FILL
, true, true, 3, 1);
421 gd
.heightHint
= inputText
.computeSize(SWT
.DEFAULT
, inputText
.getLineHeight() * 4).y
;
423 inputText
.setLayoutData(gd
);
424 inputText
.setText(getSelectionText());
425 inputText
.addModifyListener(updateListener
);
427 vSash
.setWeights(new int[] {hSash
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).y
, sashBottom
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).y
});
429 setControl(container
);
435 private static class InputLineTreeNodeContentProvider
implements ITreeContentProvider
{
438 public Object
[] getElements(Object inputElement
) {
439 return ((List
<?
>) inputElement
).toArray();
443 public Object
[] getChildren(Object parentElement
) {
444 InputLine inputLine
= (InputLine
) parentElement
;
445 if (inputLine
.childrenInputs
== null) {
446 return new InputLine
[0];
448 return inputLine
.childrenInputs
.toArray();
452 public boolean hasChildren(Object element
) {
453 InputLine inputLine
= (InputLine
) element
;
454 return (inputLine
.childrenInputs
!= null && inputLine
.childrenInputs
.size() > 0);
458 public void dispose() {
462 public void inputChanged(Viewer viewer
, Object oldInput
, Object newInput
) {
466 public Object
getParent(Object element
) {
467 InputLine inputLine
= (InputLine
) element
;
468 return inputLine
.parentInput
;
472 private class InputLineTreeLabelProvider
extends ColumnLabelProvider
{
475 public Image
getImage(Object element
) {
480 public String
getText(Object element
) {
481 InputLine inputLine
= (InputLine
) element
;
482 if (inputLine
.parentInput
== null) {
483 return "Root Line " + getName(inputLine
) + " " + inputLine
.cardinality
.toString() + " : " + inputLine
.getRegex(); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
485 return "Line " + getName(inputLine
) + " " + inputLine
.cardinality
.toString() + " : " + inputLine
.getRegex(); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
489 private class InputLineTreeSelectionChangedListener
implements ISelectionChangedListener
{
491 public void selectionChanged(SelectionChangedEvent event
) {
492 if (selectedLine
!= null) {
493 selectedLine
.dispose();
495 if (!(event
.getSelection().isEmpty()) && event
.getSelection() instanceof IStructuredSelection
) {
496 IStructuredSelection sel
= (IStructuredSelection
) event
.getSelection();
497 InputLine inputLine
= (InputLine
) sel
.getFirstElement();
498 selectedLine
= new Line(lineContainer
, getName(inputLine
), inputLine
);
499 lineContainer
.layout();
500 lineScrolledComposite
.setMinSize(lineContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).x
, lineContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).y
- 1);
509 public void dispose() {
510 if (fixedFont
!= null) {
517 private void loadDefinition(CustomTxtTraceDefinition def
) {
518 logtypeText
.setText(def
.definitionName
);
519 timestampOutputFormatText
.setText(def
.timeStampOutputFormat
);
520 treeViewer
.setInput(def
.inputs
);
521 if (def
.inputs
.size() > 0) {
522 InputLine inputLine
= def
.inputs
.get(0);
523 treeViewer
.setSelection(new StructuredSelection(inputLine
));
527 private String
getName(InputLine inputLine
) {
528 if (inputLine
.parentInput
== null) {
529 return Integer
.toString(definition
.inputs
.indexOf(inputLine
)+1);
531 return getName(inputLine
.parentInput
) + "." + Integer
.toString(inputLine
.parentInput
.childrenInputs
.indexOf(inputLine
)+1); //$NON-NLS-1$
535 * Get the global list of input names.
537 * @return The list of input names
539 public List
<String
> getInputNames() {
540 List
<String
> inputs
= new ArrayList
<>();
541 for (InputLine inputLine
: definition
.inputs
) {
542 for (String inputName
: getInputNames(inputLine
)) {
543 if (!inputs
.contains(inputName
)) {
544 inputs
.add(inputName
);
552 * Get the list of input names for the given input line.
556 * @return The list of input names
558 public List
<String
> getInputNames(InputLine inputLine
) {
559 List
<String
> inputs
= new ArrayList
<>();
560 if (inputLine
.columns
!= null) {
561 for (InputData inputData
: inputLine
.columns
) {
562 String inputName
= inputData
.name
;
563 if (!inputs
.contains(inputName
)) {
564 inputs
.add(inputName
);
568 if (inputLine
.childrenInputs
!= null) {
569 for (InputLine childInputLine
: inputLine
.childrenInputs
) {
570 for (String inputName
: getInputNames(childInputLine
)) {
571 if (!inputs
.contains(inputName
)) {
572 inputs
.add(inputName
);
580 private void removeLine() {
581 selectedLine
.dispose();
583 lineContainer
.layout();
584 lineScrolledComposite
.setMinSize(lineContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).x
, lineContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).y
-1);
588 private String
getSelectionText() {
589 if (this.selection
instanceof IStructuredSelection
) {
590 Object sel
= ((IStructuredSelection
) this.selection
).getFirstElement();
591 if (sel
instanceof IFile
) {
592 IFile file
= (IFile
)sel
;
593 BufferedReader reader
= null;
595 reader
= new BufferedReader(new InputStreamReader(file
.getContents()));
596 StringBuilder sb
= new StringBuilder();
598 while ((line
= reader
.readLine()) != null) {
599 sb
.append(line
+ "\n"); //$NON-NLS-1$
601 return sb
.toString();
602 } catch (CoreException e
) {
603 return ""; //$NON-NLS-1$
604 } catch (IOException e
) {
605 return ""; //$NON-NLS-1$
607 if (reader
!= null) {
610 } catch (IOException e
) {
616 return ""; //$NON-NLS-1$
619 private void updatePreviews() {
620 updatePreviews(false);
623 private void updatePreviews(boolean updateAll
) {
624 if (inputText
== null) {
625 // early update during construction
628 inputText
.setStyleRanges(new StyleRange
[] {});
630 try (Scanner scanner
= new Scanner(inputText
.getText());) {
631 scanner
.useDelimiter("\n"); //$NON-NLS-1$
634 // skip starting delimiters
635 String skip
= scanner
.findWithinHorizon("\\A\n+", 0); //$NON-NLS-1$
637 rawPos
+= skip
.length();
640 timeStampFormat
= null;
641 if (selectedLine
!= null) {
642 for (InputGroup input
: selectedLine
.inputs
) {
643 input
.previewText
.setText(Messages
.CustomTxtParserInputWizardPage_noMathcingLine
);
647 Map
<String
, String
> data
= new HashMap
<>();
648 int rootLineMatches
= 0;
649 String firstEntryTimeStamp
= null;
650 String firstEntryTimeStampInputFormat
= null;
652 event
: while (scanner
.hasNext()) {
653 if (rootLineMatches
> 0 && !updateAll
) {
657 log
= scanner
.next();
659 int length
= log
.length();
660 for (InputLine rootInputLine
: definition
.inputs
) {
663 pattern
= rootInputLine
.getPattern();
664 } catch (PatternSyntaxException e
) {
667 Matcher matcher
= pattern
.matcher(log
);
668 if (matcher
.find()) {
670 inputText
.setStyleRange(new StyleRange(rawPos
, length
,
671 COLOR_BLACK
, COLOR_YELLOW
, SWT
.ITALIC
));
672 data
= new HashMap
<>();
673 timeStampFormat
= null;
674 updatePreviewLine(rootInputLine
, matcher
, data
, rawPos
, rootLineMatches
);
675 if (rootLineMatches
== 1) {
676 firstEntryTimeStamp
= data
.get(CustomTraceDefinition
.TAG_TIMESTAMP
);
677 firstEntryTimeStampInputFormat
= timeStampFormat
;
679 HashMap
<InputLine
, Integer
> countMap
= new HashMap
<>();
680 InputLine currentInput
= null;
681 if (rootInputLine
.childrenInputs
!= null && rootInputLine
.childrenInputs
.size() > 0) {
682 currentInput
= rootInputLine
.childrenInputs
.get(0);
683 countMap
.put(currentInput
, 0);
685 rawPos
+= length
+ 1; // +1 for \n
686 while (scanner
.hasNext()) {
687 log
= scanner
.next();
688 length
= log
.length();
689 boolean processed
= false;
690 if (currentInput
== null) {
691 for (InputLine input
: definition
.inputs
) {
692 matcher
= input
.getPattern().matcher(log
);
693 if (matcher
.find()) {
698 if (countMap
.get(currentInput
) >= currentInput
.getMinCount()) {
699 List
<InputLine
> nextInputs
= currentInput
.getNextInputs(countMap
);
700 if (nextInputs
.size() == 0 || nextInputs
.get(nextInputs
.size() - 1).getMinCount() == 0) {
701 for (InputLine input
: definition
.inputs
) {
702 matcher
= input
.getPattern().matcher(log
);
703 if (matcher
.find()) {
708 for (InputLine input
: nextInputs
) {
709 matcher
= input
.getPattern().matcher(log
);
710 if (matcher
.find()) {
711 inputText
.setStyleRange(new StyleRange(rawPos
, length
,
712 COLOR_BLACK
, COLOR_LIGHT_YELLOW
, SWT
.ITALIC
));
713 currentInput
= input
;
714 updatePreviewLine(currentInput
, matcher
, data
, rawPos
, rootLineMatches
);
715 if (countMap
.get(currentInput
) == null) {
716 countMap
.put(currentInput
, 1);
718 countMap
.put(currentInput
, countMap
.get(currentInput
) + 1);
720 Iterator
<InputLine
> iter
= countMap
.keySet().iterator();
721 while (iter
.hasNext()) {
722 InputLine inputLine
= iter
.next();
723 if (inputLine
.level
> currentInput
.level
) {
727 if (currentInput
.childrenInputs
!= null && currentInput
.childrenInputs
.size() > 0) {
728 currentInput
= currentInput
.childrenInputs
.get(0);
729 countMap
.put(currentInput
, 0);
731 if (countMap
.get(currentInput
) >= currentInput
.getMaxCount()) {
732 if (currentInput
.getNextInputs(countMap
).size() > 0) {
733 currentInput
= currentInput
.getNextInputs(countMap
).get(0);
734 if (countMap
.get(currentInput
) == null) {
735 countMap
.put(currentInput
, 0);
737 iter
= countMap
.keySet().iterator();
738 while (iter
.hasNext()) {
739 InputLine inputLine
= iter
.next();
740 if (inputLine
.level
> currentInput
.level
) {
754 if (!processed
&& currentInput
!= null) {
755 matcher
= currentInput
.getPattern().matcher(log
);
756 if (matcher
.find()) {
757 inputText
.setStyleRange(new StyleRange(rawPos
, length
,
758 COLOR_BLACK
, COLOR_LIGHT_YELLOW
, SWT
.ITALIC
));
759 updatePreviewLine(currentInput
, matcher
, data
, rawPos
, rootLineMatches
);
760 countMap
.put(currentInput
, countMap
.get(currentInput
) + 1);
761 if (currentInput
.childrenInputs
!= null && currentInput
.childrenInputs
.size() > 0) {
762 currentInput
= currentInput
.childrenInputs
.get(0);
763 countMap
.put(currentInput
, 0);
765 if (countMap
.get(currentInput
) >= currentInput
.getMaxCount()) {
766 if (currentInput
.getNextInputs(countMap
).size() > 0) {
767 currentInput
= currentInput
.getNextInputs(countMap
).get(0);
768 if (countMap
.get(currentInput
) == null) {
769 countMap
.put(currentInput
, 0);
771 Iterator
<InputLine
> iter
= countMap
.keySet().iterator();
772 while (iter
.hasNext()) {
773 InputLine inputLine
= iter
.next();
774 if (inputLine
.level
> currentInput
.level
) {
786 rawPos
+= length
+ 1; // +1 for \n
792 rawPos
+= length
+ 1; // +1 for \n
796 if (rootLineMatches
== 1) {
797 firstEntryTimeStamp
= data
.get(CustomTraceDefinition
.TAG_TIMESTAMP
);
798 firstEntryTimeStampInputFormat
= timeStampFormat
;
800 if (firstEntryTimeStamp
== null) {
801 timestampPreviewText
.setText(Messages
.CustomTxtParserInputWizardPage_noTimestampGroup
);
802 if (selectedLine
!= null) {
803 for (InputGroup group
: selectedLine
.inputs
) {
804 if (group
.tagCombo
.getText().equals(CustomTraceDefinition
.TAG_TIMESTAMP
)) {
805 timestampPreviewText
.setText(Messages
.CustomTxtParserInputWizardPage_noMatchingTimestamp
);
812 TmfTimestampFormat timestampFormat
= new TmfTimestampFormat(firstEntryTimeStampInputFormat
);
813 long timestamp
= timestampFormat
.parseValue(firstEntryTimeStamp
);
814 timestampFormat
= new TmfTimestampFormat(timestampOutputFormatText
.getText().trim());
815 timestampPreviewText
.setText(timestampFormat
.format(timestamp
));
816 } catch (ParseException e
) {
817 timestampPreviewText
.setText("*parse exception* [" + firstEntryTimeStamp
+ "] <> [" + firstEntryTimeStampInputFormat
+ "]"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
818 } catch (IllegalArgumentException e
) {
819 timestampPreviewText
.setText("*parse exception* [Illegal Argument: " + e
.getMessage()+ "]"); //$NON-NLS-1$ //$NON-NLS-2$
826 private void updatePreviewLine(InputLine line
, Matcher matcher
, Map
<String
, String
> data
, int rawPos
, int rootLineMatches
) {
827 for (int i
= 0; i
< line
.columns
.size(); i
++) {
828 InputData input
= line
.columns
.get(i
);
829 if (i
< matcher
.groupCount() && matcher
.group(i
+1) != null) {
830 if (line
.parentInput
== null) {
831 inputText
.setStyleRange(new StyleRange(rawPos
+ matcher
.start(i
+1), matcher
.end(i
+1) - matcher
.start(i
+1),
832 COLOR_BLACK
, COLOR_GREEN
, SWT
.BOLD
));
834 inputText
.setStyleRange(new StyleRange(rawPos
+ matcher
.start(i
+1), matcher
.end(i
+1) - matcher
.start(i
+1),
835 COLOR_BLACK
, COLOR_LIGHT_GREEN
, SWT
.BOLD
));
837 String value
= matcher
.group(i
+1).trim();
838 if (selectedLine
!= null && selectedLine
.inputLine
.equals(line
) && rootLineMatches
== 1 &&
839 selectedLine
.inputs
.get(i
).previewText
.getText().equals(Messages
.CustomTxtParserInputWizardPage_noMatchingLine
)) {
840 selectedLine
.inputs
.get(i
).previewText
.setText(value
);
842 if (value
.length() == 0) {
845 if (input
.action
== CustomTraceDefinition
.ACTION_SET
) {
846 data
.put(input
.name
, value
);
847 if (input
.name
.equals(CustomTraceDefinition
.TAG_TIMESTAMP
)) {
848 timeStampFormat
= input
.format
;
850 } else if (input
.action
== CustomTraceDefinition
.ACTION_APPEND
) {
851 String s
= data
.get(input
.name
);
853 data
.put(input
.name
, s
+ value
);
855 data
.put(input
.name
, value
);
857 if (input
.name
.equals(CustomTraceDefinition
.TAG_TIMESTAMP
)) {
858 if (timeStampFormat
!= null) {
859 timeStampFormat
+= input
.format
;
861 timeStampFormat
= input
.format
;
864 } else if (input
.action
== CustomTraceDefinition
.ACTION_APPEND_WITH_SEPARATOR
) {
865 String s
= data
.get(input
.name
);
867 data
.put(input
.name
, s
+ " | " + value
); //$NON-NLS-1$
869 data
.put(input
.name
, value
);
871 if (input
.name
.equals(CustomTraceDefinition
.TAG_TIMESTAMP
)) {
872 if (timeStampFormat
!= null) {
873 timeStampFormat
+= " | " + input
.format
; //$NON-NLS-1$
875 timeStampFormat
= input
.format
;
880 if (selectedLine
!= null && selectedLine
.inputLine
.equals(line
) && rootLineMatches
== 1) {
881 if (selectedLine
.inputs
.get(i
).previewText
.getText().equals(Messages
.CustomTxtParserInputWizardPage_noMatchingLine
)) {
882 selectedLine
.inputs
.get(i
).previewText
.setText(Messages
.CustomTxtParserInputWizardPage_noMatchingGroup
);
887 // highlight the matching groups that have no corresponponding input
888 for (int i
= line
.columns
.size(); i
< matcher
.groupCount(); i
++) {
889 if (matcher
.group(i
+1) != null) {
890 if (line
.parentInput
== null) {
891 inputText
.setStyleRange(new StyleRange(rawPos
+ matcher
.start(i
+1), matcher
.end(i
+1) - matcher
.start(i
+1),
892 COLOR_BLACK
, COLOR_MAGENTA
));
894 inputText
.setStyleRange(new StyleRange(rawPos
+ matcher
.start(i
+1), matcher
.end(i
+1) - matcher
.start(i
+1),
895 COLOR_BLACK
, COLOR_LIGHT_MAGENTA
));
901 private void openHelpShell(String url
) {
902 if (helpBrowser
!= null && !helpBrowser
.isDisposed()) {
903 helpBrowser
.getShell().setActive();
904 if (!helpBrowser
.getUrl().equals(url
)) {
905 helpBrowser
.setUrl(url
);
909 final Shell helpShell
= new Shell(getShell(), SWT
.SHELL_TRIM
);
910 helpShell
.setLayout(new FillLayout());
911 helpBrowser
= new Browser(helpShell
, SWT
.NONE
);
912 helpBrowser
.addTitleListener(new TitleListener() {
914 public void changed(TitleEvent event
) {
915 helpShell
.setText(event
.title
);
918 helpBrowser
.setBounds(0, 0, 600, 400);
921 helpBrowser
.setUrl(url
);
924 private void openLegend() {
925 final String cg
= Messages
.CustomTxtParserInputWizardPage_capturedGroup
;
926 final String ucg
= Messages
.CustomTxtParserInputWizardPage_unidentifiedCaptureGroup
;
927 final String ut
= Messages
.CustomTxtParserInputWizardPage_uncapturedText
;
929 String line1
= Messages
.CustomTxtParserInputWizardPage_nonMatchingLine
;
930 int line2start
= line1start
+ line1
.length();
931 String line2
= Messages
.CustomTxtParserInputWizardPage_matchingLineRoot
+ cg
+ ' ' + ucg
+ ' ' + ut
+ " \n"; //$NON-NLS-1$
932 int line3start
= line2start
+ line2
.length();
933 String line3
= Messages
.CustomTxtParserInputWizardPage_matchingOtherLine
+ cg
+ ' ' + ucg
+ ' ' + ut
+ " \n"; //$NON-NLS-1$
934 int line4start
= line3start
+ line3
.length();
935 String line4
= Messages
.CustomTxtParserInputWizardPage_matchingOtherLine
+ cg
+ ' ' + ucg
+ ' ' + ut
+ " \n"; //$NON-NLS-1$
936 int line5start
= line4start
+ line4
.length();
937 String line5
= Messages
.CustomTxtParserInputWizardPage_nonMatchingLine
;
938 int line6start
= line5start
+ line5
.length();
939 String line6
= Messages
.CustomTxtParserInputWizardPage_matchingRootLine
+ cg
+ ' ' + ucg
+ ' ' + ut
+ " \n"; //$NON-NLS-1$
941 final Shell legendShell
= new Shell(getShell(), SWT
.DIALOG_TRIM
);
942 legendShell
.setLayout(new FillLayout());
943 StyledText legendText
= new StyledText(legendShell
, SWT
.MULTI
);
944 legendText
.setFont(fixedFont
);
945 legendText
.setText(line1
+ line2
+ line3
+ line4
+ line5
+ line6
);
946 legendText
.setStyleRange(new StyleRange(line2start
, line2
.length(), COLOR_BLACK
, COLOR_YELLOW
, SWT
.ITALIC
));
947 legendText
.setStyleRange(new StyleRange(line3start
, line3
.length(), COLOR_BLACK
, COLOR_LIGHT_YELLOW
, SWT
.ITALIC
));
948 legendText
.setStyleRange(new StyleRange(line4start
, line4
.length(), COLOR_BLACK
, COLOR_LIGHT_YELLOW
, SWT
.ITALIC
));
949 legendText
.setStyleRange(new StyleRange(line6start
, line6
.length(), COLOR_BLACK
, COLOR_YELLOW
, SWT
.ITALIC
));
950 legendText
.setStyleRange(new StyleRange(line2start
+ line2
.indexOf(cg
), cg
.length(), COLOR_BLACK
, COLOR_GREEN
, SWT
.BOLD
));
951 legendText
.setStyleRange(new StyleRange(line2start
+ line2
.indexOf(ucg
), ucg
.length(), COLOR_BLACK
, COLOR_MAGENTA
));
952 legendText
.setStyleRange(new StyleRange(line3start
+ line3
.indexOf(cg
), cg
.length(), COLOR_BLACK
, COLOR_LIGHT_GREEN
, SWT
.BOLD
));
953 legendText
.setStyleRange(new StyleRange(line3start
+ line3
.indexOf(ucg
), ucg
.length(), COLOR_BLACK
, COLOR_LIGHT_MAGENTA
));
954 legendText
.setStyleRange(new StyleRange(line4start
+ line4
.indexOf(cg
), cg
.length(), COLOR_BLACK
, COLOR_LIGHT_GREEN
, SWT
.BOLD
));
955 legendText
.setStyleRange(new StyleRange(line4start
+ line4
.indexOf(ucg
), ucg
.length(), COLOR_BLACK
, COLOR_LIGHT_MAGENTA
));
956 legendText
.setStyleRange(new StyleRange(line6start
+ line6
.indexOf(cg
), cg
.length(), COLOR_BLACK
, COLOR_GREEN
, SWT
.BOLD
));
957 legendText
.setStyleRange(new StyleRange(line6start
+ line6
.indexOf(ucg
), ucg
.length(), COLOR_BLACK
, COLOR_MAGENTA
));
958 legendShell
.setText(Messages
.CustomTxtParserInputWizardPage_previewLegend
);
963 private class UpdateListener
implements ModifyListener
, SelectionListener
{
966 public void modifyText(ModifyEvent e
) {
972 public void widgetDefaultSelected(SelectionEvent e
) {
978 public void widgetSelected(SelectionEvent e
) {
986 private static final String INFINITY_STRING
= "\u221E"; //$NON-NLS-1$
987 private InputLine inputLine
;
989 private Composite labelComposite
;
990 private Text regexText
;
991 private Composite cardinalityContainer
;
992 private Combo cardinalityCombo
;
993 private Label cardinalityMinLabel
;
994 private Text cardinalityMinText
;
995 private Label cardinalityMaxLabel
;
996 private Text cardinalityMaxText
;
997 private Button infiniteButton
;
998 private List
<InputGroup
> inputs
= new ArrayList
<>();
999 private Button addGroupButton
;
1000 private Label addGroupLabel
;
1002 public Line(Composite parent
, String name
, InputLine inputLine
) {
1003 this.inputLine
= inputLine
;
1005 group
= new Group(parent
, SWT
.NONE
);
1006 group
.setText(name
);
1007 group
.setLayout(new GridLayout(2, false));
1008 group
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
1010 labelComposite
= new Composite(group
, SWT
.FILL
);
1011 GridLayout labelLayout
= new GridLayout(1, false);
1012 labelLayout
.marginWidth
= 0;
1013 labelLayout
.marginHeight
= 0;
1014 labelComposite
.setLayout(labelLayout
);
1015 labelComposite
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
1017 Label label
= new Label(labelComposite
, SWT
.NULL
);
1018 label
.setText(Messages
.CustomTxtParserInputWizardPage_regularExpression
);
1020 Composite regexContainer
= new Composite(group
, SWT
.NONE
);
1021 GridLayout regexLayout
= new GridLayout(2, false);
1022 regexLayout
.marginHeight
= 0;
1023 regexLayout
.marginWidth
= 0;
1024 regexContainer
.setLayout(regexLayout
);
1025 regexContainer
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
1027 regexText
= new Text(regexContainer
, SWT
.BORDER
| SWT
.SINGLE
);
1028 GridData gd
= new GridData(SWT
.FILL
, SWT
.CENTER
, true, false);
1030 regexText
.setLayoutData(gd
);
1031 regexText
.setText(inputLine
.getRegex());
1032 regexText
.addModifyListener(updateListener
);
1034 Button regexHelpButton
= new Button(regexContainer
, SWT
.PUSH
);
1035 regexHelpButton
.setImage(HELP_IMAGE
);
1036 regexHelpButton
.setToolTipText(Messages
.CustomTxtParserInputWizardPage_regularExpressionHelp
);
1037 regexHelpButton
.addSelectionListener(new SelectionAdapter() {
1039 public void widgetSelected(SelectionEvent e
) {
1040 openHelpShell(PATTERN_URL
);
1044 label
= new Label(group
, SWT
.NONE
);
1045 label
.setText(Messages
.CustomTxtParserInputWizardPage_cardinality
);
1046 label
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
1048 cardinalityContainer
= new Composite(group
, SWT
.NONE
);
1049 GridLayout cardinalityLayout
= new GridLayout(6, false);
1050 cardinalityLayout
.marginHeight
= 0;
1051 cardinalityLayout
.marginWidth
= 0;
1052 cardinalityContainer
.setLayout(cardinalityLayout
);
1053 cardinalityContainer
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
1055 cardinalityCombo
= new Combo(cardinalityContainer
, SWT
.DROP_DOWN
| SWT
.READ_ONLY
);
1056 cardinalityCombo
.setItems(new String
[] {
1057 Cardinality
.ZERO_OR_MORE
.toString(),
1058 Cardinality
.ONE_OR_MORE
.toString(),
1059 Cardinality
.ZERO_OR_ONE
.toString(),
1060 Cardinality
.ONE
.toString(),
1061 "(?,?)"}); //$NON-NLS-1$
1062 cardinalityCombo
.addSelectionListener(new SelectionListener() {
1064 public void widgetDefaultSelected(SelectionEvent e
) {}
1067 public void widgetSelected(SelectionEvent e
) {
1068 switch (cardinalityCombo
.getSelectionIndex()) {
1070 cardinalityMinLabel
.setVisible(true);
1071 cardinalityMinText
.setVisible(true);
1072 cardinalityMaxLabel
.setVisible(true);
1073 cardinalityMaxText
.setVisible(true);
1074 infiniteButton
.setVisible(true);
1077 cardinalityMinLabel
.setVisible(false);
1078 cardinalityMinText
.setVisible(false);
1079 cardinalityMaxLabel
.setVisible(false);
1080 cardinalityMaxText
.setVisible(false);
1081 infiniteButton
.setVisible(false);
1084 cardinalityContainer
.layout();
1090 cardinalityMinLabel
= new Label(cardinalityContainer
, SWT
.NONE
);
1091 cardinalityMinLabel
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
1092 cardinalityMinLabel
.setText(Messages
.CustomTxtParserInputWizardPage_min
);
1093 cardinalityMinLabel
.setVisible(false);
1095 cardinalityMinText
= new Text(cardinalityContainer
, SWT
.BORDER
| SWT
.SINGLE
);
1096 gd
= new GridData(SWT
.CENTER
, SWT
.CENTER
, false, false);
1098 cardinalityMinText
.setLayoutData(gd
);
1099 cardinalityMinText
.setVisible(false);
1101 cardinalityMaxLabel
= new Label(cardinalityContainer
, SWT
.NONE
);
1102 cardinalityMaxLabel
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
1103 cardinalityMaxLabel
.setText(Messages
.CustomTxtParserInputWizardPage_max
);
1104 cardinalityMaxLabel
.setVisible(false);
1106 cardinalityMaxText
= new Text(cardinalityContainer
, SWT
.BORDER
| SWT
.SINGLE
);
1107 gd
= new GridData(SWT
.CENTER
, SWT
.CENTER
, false, false);
1109 cardinalityMaxText
.setLayoutData(gd
);
1110 cardinalityMaxText
.setVisible(false);
1112 infiniteButton
= new Button(cardinalityContainer
, SWT
.PUSH
);
1113 infiniteButton
.setText(INFINITY_STRING
);
1114 infiniteButton
.setVisible(false);
1115 infiniteButton
.addSelectionListener(new SelectionAdapter(){
1117 public void widgetSelected(SelectionEvent e
) {
1118 cardinalityMaxText
.setText(INFINITY_STRING
);
1121 if (inputLine
.cardinality
.equals(Cardinality
.ZERO_OR_MORE
)) {
1122 cardinalityCombo
.select(0);
1123 } else if (inputLine
.cardinality
.equals(Cardinality
.ONE_OR_MORE
)) {
1124 cardinalityCombo
.select(1);
1125 } else if (inputLine
.cardinality
.equals(Cardinality
.ZERO_OR_ONE
)) {
1126 cardinalityCombo
.select(2);
1127 } else if (inputLine
.cardinality
.equals(Cardinality
.ONE
)) {
1128 cardinalityCombo
.select(3);
1130 cardinalityCombo
.select(4);
1131 cardinalityMinLabel
.setVisible(true);
1132 cardinalityMinText
.setVisible(true);
1133 if (inputLine
.getMinCount() >= 0) {
1134 cardinalityMinText
.setText(Integer
.toString(inputLine
.getMinCount()));
1136 cardinalityMaxLabel
.setVisible(true);
1137 cardinalityMaxText
.setVisible(true);
1138 if (inputLine
.getMaxCount() == Cardinality
.INF
) {
1139 cardinalityMaxText
.setText(INFINITY_STRING
);
1140 } else if (inputLine
.getMaxCount() >= 0) {
1141 cardinalityMaxText
.setText(Integer
.toString(inputLine
.getMaxCount()));
1143 infiniteButton
.setVisible(true);
1146 VerifyListener digitsListener
= new VerifyListener() {
1148 public void verifyText(VerifyEvent e
) {
1149 if (e
.text
.equals(INFINITY_STRING
)) {
1150 e
.doit
= e
.widget
== cardinalityMaxText
&& e
.start
== 0 && e
.end
== ((Text
) e
.widget
).getText().length();
1152 if (((Text
) e
.widget
).getText().equals(INFINITY_STRING
)) {
1153 e
.doit
= e
.start
== 0 && e
.end
== ((Text
) e
.widget
).getText().length();
1155 for (int i
= 0; i
< e
.text
.length(); i
++) {
1156 if (!Character
.isDigit(e
.text
.charAt(i
))) {
1164 cardinalityMinText
.addModifyListener(updateListener
);
1165 cardinalityMaxText
.addModifyListener(updateListener
);
1166 cardinalityMinText
.addVerifyListener(digitsListener
);
1167 cardinalityMaxText
.addVerifyListener(digitsListener
);
1169 if (inputLine
.columns
!= null) {
1170 for (InputData inputData
: inputLine
.columns
) {
1171 InputGroup inputGroup
= new InputGroup(group
, this, inputs
.size()+1);
1172 if (inputData
.name
.equals(CustomTraceDefinition
.TAG_TIMESTAMP
)) {
1173 inputGroup
.tagCombo
.select(0);
1174 inputGroup
.tagText
.setText(inputData
.format
);
1175 inputGroup
.tagLabel
.setText(Messages
.CustomTxtParserInputWizardPage_format
);
1176 inputGroup
.tagLabel
.setVisible(true);
1177 inputGroup
.tagText
.setVisible(true);
1178 inputGroup
.tagText
.addModifyListener(updateListener
);
1179 } else if (inputData
.name
.equals(CustomTraceDefinition
.TAG_MESSAGE
)) {
1180 inputGroup
.tagCombo
.select(1);
1182 inputGroup
.tagCombo
.select(2);
1183 inputGroup
.tagText
.setText(inputData
.name
);
1184 inputGroup
.tagLabel
.setText(Messages
.CustomTxtParserInputWizardPage_name
);
1185 inputGroup
.tagLabel
.setVisible(true);
1186 inputGroup
.tagText
.setVisible(true);
1187 inputGroup
.tagText
.addModifyListener(updateListener
);
1189 inputGroup
.actionCombo
.select(inputData
.action
);
1190 inputs
.add(inputGroup
);
1194 createAddGroupButton();
1197 private void createAddGroupButton() {
1198 addGroupButton
= new Button(group
, SWT
.PUSH
);
1199 addGroupButton
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
1200 addGroupButton
.setImage(ADD_IMAGE
);
1201 addGroupButton
.setToolTipText(Messages
.CustomTxtParserInputWizardPage_addGroup
);
1202 addGroupButton
.addSelectionListener(new SelectionAdapter() {
1204 public void widgetSelected(SelectionEvent e
) {
1205 removeAddGroupButton();
1206 inputs
.add(new InputGroup(group
, Line
.this, inputs
.size()+1));
1207 createAddGroupButton();
1208 lineContainer
.layout();
1209 lineScrolledComposite
.setMinSize(lineContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).x
, lineContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).y
-1);
1210 group
.getParent().layout();
1216 addGroupLabel
= new Label(group
, SWT
.NULL
);
1217 addGroupLabel
.setText(Messages
.CustomTxtParserInputWizardPage_newGroup
);
1220 private void removeAddGroupButton() {
1221 addGroupButton
.dispose();
1222 addGroupLabel
.dispose();
1225 private void removeInput(int inputNumber
) {
1226 int nb
= inputNumber
;
1227 if (--nb
< inputs
.size()) {
1228 inputs
.remove(nb
).dispose();
1229 for (int i
= nb
; i
< inputs
.size(); i
++) {
1230 inputs
.get(i
).setInputNumber(i
+1);
1232 lineContainer
.layout();
1233 lineScrolledComposite
.setMinSize(lineContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).x
, lineContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).y
-1);
1234 group
.getParent().layout();
1238 private void dispose() {
1242 private void extractInputs() {
1243 inputLine
.setRegex(selectedLine
.regexText
.getText());
1244 switch (cardinalityCombo
.getSelectionIndex()) {
1246 inputLine
.cardinality
= Cardinality
.ZERO_OR_MORE
;
1249 inputLine
.cardinality
= Cardinality
.ONE_OR_MORE
;
1252 inputLine
.cardinality
= Cardinality
.ZERO_OR_ONE
;
1255 inputLine
.cardinality
= Cardinality
.ONE
;
1260 min
= Integer
.parseInt(cardinalityMinText
.getText());
1261 } catch (NumberFormatException e
) {
1265 if (cardinalityMaxText
.getText().equals(INFINITY_STRING
)) {
1266 max
= Cardinality
.INF
;
1268 max
= Integer
.parseInt(cardinalityMaxText
.getText());
1270 } catch (NumberFormatException e
) {
1273 inputLine
.cardinality
= new Cardinality(min
, max
);
1276 inputLine
.cardinality
= Cardinality
.ZERO_OR_MORE
;
1279 inputLine
.columns
= new ArrayList
<>(inputs
.size());
1280 for (int i
= 0; i
< inputs
.size(); i
++) {
1281 InputGroup grp
= inputs
.get(i
);
1282 InputData inputData
= new InputData();
1283 if (grp
.tagCombo
.getText().equals(CustomTraceDefinition
.TAG_OTHER
)) {
1284 inputData
.name
= grp
.tagText
.getText().trim();
1286 inputData
.name
= grp
.tagCombo
.getText();
1287 if (grp
.tagCombo
.getText().equals(CustomTraceDefinition
.TAG_TIMESTAMP
)) {
1288 inputData
.format
= grp
.tagText
.getText().trim();
1291 inputData
.action
= grp
.actionCombo
.getSelectionIndex();
1292 inputLine
.columns
.add(inputData
);
1297 private class InputGroup
{
1299 private int inputNumber
;
1301 // children of parent (must be disposed)
1302 private Composite labelComposite
;
1303 private Composite tagComposite
;
1304 private Label previewLabel
;
1305 private Text previewText
;
1307 // children of labelComposite
1308 private Label inputLabel
;
1310 // children of tagComposite
1311 private Combo tagCombo
;
1312 private Label tagLabel
;
1313 private Text tagText
;
1314 private Combo actionCombo
;
1316 public InputGroup(Composite parent
, Line line
, int inputNumber
) {
1318 this.inputNumber
= inputNumber
;
1320 labelComposite
= new Composite(parent
, SWT
.FILL
);
1321 GridLayout labelLayout
= new GridLayout(2, false);
1322 labelLayout
.marginWidth
= 0;
1323 labelLayout
.marginHeight
= 0;
1324 labelComposite
.setLayout(labelLayout
);
1325 labelComposite
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
1327 Button deleteButton
= new Button(labelComposite
, SWT
.PUSH
);
1328 deleteButton
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
1329 deleteButton
.setImage(DELETE_IMAGE
);
1330 deleteButton
.setToolTipText(Messages
.CustomTxtParserInputWizardPage_removeGroup
);
1331 deleteButton
.addSelectionListener(new SelectionAdapter() {
1333 public void widgetSelected(SelectionEvent e
) {
1334 InputGroup
.this.line
.removeInput(InputGroup
.this.inputNumber
);
1340 inputLabel
= new Label(labelComposite
, SWT
.NULL
);
1341 inputLabel
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
1342 inputLabel
.setText(Messages
.CustomTxtParserInputWizardPage_group
+ inputNumber
+ ":"); //$NON-NLS-1$
1344 tagComposite
= new Composite(parent
, SWT
.FILL
);
1345 GridLayout tagLayout
= new GridLayout(4, false);
1346 tagLayout
.marginWidth
= 0;
1347 tagLayout
.marginHeight
= 0;
1348 tagComposite
.setLayout(tagLayout
);
1349 tagComposite
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
1351 tagCombo
= new Combo(tagComposite
, SWT
.DROP_DOWN
| SWT
.READ_ONLY
);
1352 tagCombo
.setItems(new String
[] {CustomTraceDefinition
.TAG_TIMESTAMP
,
1353 CustomTraceDefinition
.TAG_MESSAGE
,
1354 CustomTraceDefinition
.TAG_OTHER
});
1356 tagCombo
.addSelectionListener(new SelectionListener(){
1358 public void widgetDefaultSelected(SelectionEvent e
) {}
1360 public void widgetSelected(SelectionEvent e
) {
1361 tagText
.removeModifyListener(updateListener
);
1362 switch (tagCombo
.getSelectionIndex()) {
1363 case 0: //Time Stamp
1364 tagLabel
.setText(Messages
.CustomTxtParserInputWizardPage_format
);
1365 tagLabel
.setVisible(true);
1366 tagText
.setVisible(true);
1367 tagText
.addModifyListener(updateListener
);
1370 tagLabel
.setVisible(false);
1371 tagText
.setVisible(false);
1374 tagLabel
.setText(Messages
.CustomTxtParserInputWizardPage_name
);
1375 tagLabel
.setVisible(true);
1376 tagText
.setVisible(true);
1377 tagText
.addModifyListener(updateListener
);
1380 tagLabel
.setVisible(false);
1381 tagText
.setVisible(false);
1386 tagComposite
.layout();
1391 tagLabel
= new Label(tagComposite
, SWT
.NULL
);
1392 tagLabel
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
1393 tagLabel
.setVisible(false);
1395 tagText
= new Text(tagComposite
, SWT
.BORDER
| SWT
.SINGLE
);
1396 GridData gd
= new GridData(SWT
.FILL
, SWT
.CENTER
, true, false);
1398 tagText
.setLayoutData(gd
);
1399 tagText
.setVisible(false);
1401 actionCombo
= new Combo(tagComposite
, SWT
.DROP_DOWN
| SWT
.READ_ONLY
);
1402 actionCombo
.setItems(new String
[] {Messages
.CustomTxtParserInputWizardPage_set
, Messages
.CustomTxtParserInputWizardPage_append
, Messages
.CustomTxtParserInputWizardPage_appendWith
});
1403 actionCombo
.select(0);
1404 actionCombo
.addSelectionListener(updateListener
);
1406 previewLabel
= new Label(parent
, SWT
.NULL
);
1407 previewLabel
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
1408 previewLabel
.setText(Messages
.CustomTxtParserInputWizardPage_preview
);
1410 previewText
= new Text(parent
, SWT
.BORDER
| SWT
.SINGLE
| SWT
.READ_ONLY
);
1411 gd
= new GridData(SWT
.FILL
, SWT
.CENTER
, true, false);
1413 previewText
.setLayoutData(gd
);
1414 previewText
.setText(Messages
.CustomTxtParserInputWizardPage_noMatch
);
1415 previewText
.setBackground(COLOR_WIDGET_BACKGROUND
);
1418 private void dispose() {
1419 labelComposite
.dispose();
1420 tagComposite
.dispose();
1421 previewLabel
.dispose();
1422 previewText
.dispose();
1425 private void setInputNumber(int inputNumber
) {
1426 this.inputNumber
= inputNumber
;
1427 inputLabel
.setText(Messages
.CustomTxtParserInputWizardPage_group
+ inputNumber
+ ":"); //$NON-NLS-1$
1428 labelComposite
.layout();
1432 private void validate() {
1434 definition
.definitionName
= logtypeText
.getText().trim();
1435 definition
.timeStampOutputFormat
= timestampOutputFormatText
.getText().trim();
1437 if (selectedLine
!= null) {
1438 selectedLine
.extractInputs();
1439 treeViewer
.refresh();
1442 StringBuffer errors
= new StringBuffer();
1444 if (definition
.definitionName
.length() == 0) {
1445 errors
.append("Enter a name for the new log type. "); //$NON-NLS-1$
1446 logtypeText
.setBackground(COLOR_LIGHT_RED
);
1448 logtypeText
.setBackground(COLOR_TEXT_BACKGROUND
);
1449 for (CustomTxtTraceDefinition def
: CustomTxtTraceDefinition
.loadAll()) {
1450 if (definition
.definitionName
.equals(def
.definitionName
) &&
1451 (editDefinitionName
== null || !editDefinitionName
.equals(definition
.definitionName
))) {
1452 errors
.append("The log type name already exists. "); //$NON-NLS-1$
1453 logtypeText
.setBackground(COLOR_LIGHT_RED
);
1459 timestampFound
= false;
1460 for (int i
= 0; i
< definition
.inputs
.size(); i
++) {
1462 InputLine inputLine
= definition
.inputs
.get(i
);
1463 String name
= Integer
.toString(i
+1);
1464 errors
.append(validateLine(inputLine
, name
));
1466 if (timestampFound
) {
1467 if (definition
.timeStampOutputFormat
.length() == 0) {
1468 errors
.append("Enter the output format for the Time Stamp field. "); //$NON-NLS-1$
1469 timestampOutputFormatText
.setBackground(COLOR_LIGHT_RED
);
1472 new TmfTimestampFormat(definition
.timeStampOutputFormat
);
1473 timestampOutputFormatText
.setBackground(COLOR_TEXT_BACKGROUND
);
1474 } catch (IllegalArgumentException e
) {
1475 errors
.append("Enter a valid output format for the Time Stamp field [" + e
.getMessage() + "]."); //$NON-NLS-1$ //$NON-NLS-2$
1476 timestampOutputFormatText
.setBackground(COLOR_LIGHT_RED
);
1481 timestampOutputFormatText
.setBackground(COLOR_TEXT_BACKGROUND
);
1484 if (errors
.length() == 0) {
1485 setDescription(defaultDescription
);
1486 setPageComplete(true);
1488 setDescription(errors
.toString());
1489 setPageComplete(false);
1494 * Validate an input line.
1497 * The line to clean up
1499 * The name of the line
1500 * @return The cleaned up line
1502 public StringBuffer
validateLine(InputLine inputLine
, String name
) {
1503 StringBuffer errors
= new StringBuffer();
1505 if (selectedLine
!= null && selectedLine
.inputLine
.equals(inputLine
)) {
1506 line
= selectedLine
;
1509 Pattern
.compile(inputLine
.getRegex());
1511 line
.regexText
.setBackground(COLOR_TEXT_BACKGROUND
);
1513 } catch (PatternSyntaxException e
) {
1514 errors
.append("Enter a valid regular expression (Line "+name
+"). "); //$NON-NLS-1$ //$NON-NLS-2$
1516 line
.regexText
.setBackground(COLOR_LIGHT_RED
);
1519 if (inputLine
.getMinCount() == -1) {
1520 errors
.append("Enter a minimum value for cardinality (Line "+name
+"). "); //$NON-NLS-1$ //$NON-NLS-2$
1522 line
.cardinalityMinText
.setBackground(COLOR_LIGHT_RED
);
1526 line
.cardinalityMinText
.setBackground(COLOR_TEXT_BACKGROUND
);
1529 if (inputLine
.getMaxCount() == -1) {
1530 errors
.append("Enter a maximum value for cardinality (Line "+name
+"). "); //$NON-NLS-1$ //$NON-NLS-2$
1532 line
.cardinalityMaxText
.setBackground(COLOR_LIGHT_RED
);
1534 } else if (inputLine
.getMinCount() > inputLine
.getMaxCount()) {
1535 errors
.append("Enter correct (min <= max) values for cardinality (Line "+name
+"). "); //$NON-NLS-1$ //$NON-NLS-2$
1537 line
.cardinalityMinText
.setBackground(COLOR_LIGHT_RED
);
1540 line
.cardinalityMaxText
.setBackground(COLOR_LIGHT_RED
);
1544 line
.cardinalityMaxText
.setBackground(COLOR_TEXT_BACKGROUND
);
1547 for (int i
= 0; inputLine
.columns
!= null && i
< inputLine
.columns
.size(); i
++) {
1548 InputData inputData
= inputLine
.columns
.get(i
);
1549 InputGroup group
= null;
1551 group
= line
.inputs
.get(i
);
1553 if (inputData
.name
.equals(CustomTraceDefinition
.TAG_TIMESTAMP
)) {
1554 timestampFound
= true;
1555 if (inputData
.format
.length() == 0) {
1556 errors
.append("Enter the input format for the Time Stamp (Line "+name
+" Group "+(i
+1)+"). "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
1557 if (group
!= null) {
1558 group
.tagText
.setBackground(COLOR_LIGHT_RED
);
1562 new TmfTimestampFormat(inputData
.format
);
1563 if (group
!= null) {
1564 group
.tagText
.setBackground(COLOR_TEXT_BACKGROUND
);
1566 } catch (IllegalArgumentException e
) {
1567 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$
1568 if (group
!= null) {
1569 group
.tagText
.setBackground(COLOR_LIGHT_RED
);
1573 } else if (inputData
.name
.length() == 0) {
1574 errors
.append("Enter a name for the data group (Line "+name
+" Group "+(i
+1)+"). "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
1575 if (group
!= null) {
1576 group
.tagText
.setBackground(COLOR_LIGHT_RED
);
1579 if (group
!= null) {
1580 group
.tagText
.setBackground(COLOR_TEXT_BACKGROUND
);
1584 for (int i
= 0; inputLine
.childrenInputs
!= null && i
< inputLine
.childrenInputs
.size(); i
++) {
1585 errors
.append(validateLine(inputLine
.childrenInputs
.get(i
), name
+"."+(i
+1))); //$NON-NLS-1$
1591 * Get the trace definition.
1593 * @return The trace definition
1595 public CustomTxtTraceDefinition
getDefinition() {
1600 * Get the raw text of the input.
1602 * @return The raw input text
1604 public char[] getInputText() {
1605 return inputText
.getText().toCharArray();