1 /*******************************************************************************
2 * Copyright (c) 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 Tassé - 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 Tassé
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 lineImage
= Activator
.getDefault().getImageFromPath("/icons/elcl16/line_icon.gif"); //$NON-NLS-1$
94 private static final Image addImage
= Activator
.getDefault().getImageFromPath("/icons/elcl16/add_button.gif"); //$NON-NLS-1$
95 private static final Image addNextImage
= Activator
.getDefault().getImageFromPath("/icons/elcl16/addnext_button.gif"); //$NON-NLS-1$
96 private static final Image addChildImage
= Activator
.getDefault().getImageFromPath("/icons/elcl16/addchild_button.gif"); //$NON-NLS-1$
97 private static final Image deleteImage
= Activator
.getDefault().getImageFromPath("/icons/elcl16/delete_button.gif"); //$NON-NLS-1$
98 private static final Image moveUpImage
= Activator
.getDefault().getImageFromPath("/icons/elcl16/moveup_button.gif"); //$NON-NLS-1$
99 private static final Image moveDownImage
= Activator
.getDefault().getImageFromPath("/icons/elcl16/movedown_button.gif"); //$NON-NLS-1$
100 private static final Image helpImage
= Activator
.getDefault().getImageFromPath("/icons/elcl16/help_button.gif"); //$NON-NLS-1$
101 private static final Color COLOR_BLACK
= Display
.getCurrent().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
.getCurrent().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
.getCurrent().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
.getCurrent().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
.getCurrent().getSystemColor(SWT
.COLOR_WHITE
);
110 private static final Color COLOR_WIDGET_BACKGROUND
= Display
.getCurrent().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 treeScrolledComposite
;
122 private ScrolledComposite lineScrolledComposite
;
123 private TreeViewer treeViewer
;
124 private Composite treeContainer
;
125 private Composite lineContainer
;
126 private StyledText inputText
;
127 private Font fixedFont
;
128 private UpdateListener updateListener
;
129 private Browser helpBrowser
;
131 // variables used recursively through line traversal
132 private String timeStampFormat
;
133 private boolean timestampFound
;
139 * The Selection object
141 * The trace definition
143 protected CustomTxtParserInputWizardPage(ISelection selection
,
144 CustomTxtTraceDefinition definition
) {
145 super("CustomParserWizardPage"); //$NON-NLS-1$
146 if (definition
== null) {
147 setTitle(Messages
.CustomTxtParserInputWizardPage_windowTitleNew
);
148 defaultDescription
= Messages
.CustomTxtParserInputWizardPage_descriptionNew
;
150 setTitle(Messages
.CustomTxtParserInputWizardPage_windowTitleEdit
);
151 defaultDescription
= Messages
.CustomTxtParserInputWizardPage_desccriptionEdit
;
153 setDescription(defaultDescription
);
154 this.selection
= selection
;
155 this.definition
= definition
;
156 if (definition
!= null) {
157 this.editDefinitionName
= definition
.definitionName
;
162 public void createControl(Composite parent
) {
163 container
= new Composite(parent
, SWT
.NULL
);
164 container
.setLayout(new GridLayout());
166 updateListener
= new UpdateListener();
168 Composite headerComposite
= new Composite(container
, SWT
.FILL
);
169 GridLayout headerLayout
= new GridLayout(5, false);
170 headerLayout
.marginHeight
= 0;
171 headerLayout
.marginWidth
= 0;
172 headerComposite
.setLayout(headerLayout
);
173 headerComposite
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
175 Label logtypeLabel
= new Label(headerComposite
, SWT
.NULL
);
176 logtypeLabel
.setText(Messages
.CustomTxtParserInputWizardPage_logType
);
178 logtypeText
= new Text(headerComposite
, SWT
.BORDER
| SWT
.SINGLE
);
179 logtypeText
.setLayoutData(new GridData(120, SWT
.DEFAULT
));
181 Label timestampFormatLabel
= new Label(headerComposite
, SWT
.NULL
);
182 timestampFormatLabel
.setText(Messages
.CustomTxtParserInputWizardPage_timestampFormat
);
184 timestampOutputFormatText
= new Text(headerComposite
, SWT
.BORDER
| SWT
.SINGLE
);
185 timestampOutputFormatText
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
186 timestampOutputFormatText
.setText(DEFAULT_TIMESTAMP_FORMAT
);
188 Button dateFormatHelpButton
= new Button(headerComposite
, SWT
.PUSH
);
189 dateFormatHelpButton
.setImage(helpImage
);
190 dateFormatHelpButton
.setToolTipText(Messages
.CustomTxtParserInputWizardPage_dateFormatHelp
);
191 dateFormatHelpButton
.addSelectionListener(new SelectionAdapter() {
193 public void widgetSelected(SelectionEvent e
) {
194 openHelpShell(SIMPLE_DATE_FORMAT_URL
);
198 Label timestampPreviewLabel
= new Label(headerComposite
, SWT
.NULL
);
199 timestampPreviewLabel
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false, 3, 1));
200 timestampPreviewLabel
.setText(Messages
.CustomTxtParserInputWizardPage_preview
);
202 timestampPreviewText
= new Text(headerComposite
, SWT
.BORDER
| SWT
.SINGLE
| SWT
.READ_ONLY
);
203 timestampPreviewText
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false, 2, 1));
204 timestampPreviewText
.setText(Messages
.CustomTxtParserInputWizardPage_noMatchingTimestamp
);
206 Composite buttonBar
= new Composite(container
, SWT
.NONE
);
207 GridLayout buttonBarLayout
= new GridLayout(5, false);
208 buttonBarLayout
.marginHeight
= 0;
209 buttonBarLayout
.marginWidth
= 0;
210 buttonBar
.setLayout(buttonBarLayout
);
212 Button removeButton
= new Button(buttonBar
, SWT
.PUSH
);
213 removeButton
.setImage(deleteImage
);
214 removeButton
.setToolTipText(Messages
.CustomTxtParserInputWizardPage_removeLine
);
215 removeButton
.addSelectionListener(new SelectionAdapter() {
217 public void widgetSelected(SelectionEvent e
) {
218 if (treeViewer
.getSelection().isEmpty() || selectedLine
== null) {
222 InputLine inputLine
= (InputLine
) ((IStructuredSelection
) treeViewer
.getSelection()).getFirstElement();
223 if (inputLine
.parentInput
== null) {
224 definition
.inputs
.remove(inputLine
);
226 inputLine
.parentInput
.childrenInputs
.remove(inputLine
);
228 treeViewer
.refresh();
233 Button addNextButton
= new Button(buttonBar
, SWT
.PUSH
);
234 addNextButton
.setImage(addNextImage
);
235 addNextButton
.setToolTipText(Messages
.CustomTxtParserInputWizardPage_addNextLine
);
236 addNextButton
.addSelectionListener(new SelectionAdapter() {
238 public void widgetSelected(SelectionEvent e
) {
239 InputLine inputLine
= new InputLine(Cardinality
.ZERO_OR_MORE
, "", null); //$NON-NLS-1$
240 if (((List
<?
>) treeViewer
.getInput()).size() == 0) {
241 definition
.inputs
.add(inputLine
);
242 } else if (treeViewer
.getSelection().isEmpty()) {
245 InputLine previousInputLine
= (InputLine
) ((IStructuredSelection
) treeViewer
.getSelection()).getFirstElement();
246 if (previousInputLine
.parentInput
== null) {
247 for (int i
= 0; i
< definition
.inputs
.size(); i
++) {
248 if (definition
.inputs
.get(i
).equals(previousInputLine
)) {
249 definition
.inputs
.add(i
+ 1, inputLine
);
253 previousInputLine
.addNext(inputLine
);
256 treeViewer
.refresh();
257 treeViewer
.setSelection(new StructuredSelection(inputLine
), true);
260 Button addChildButton
= new Button(buttonBar
, SWT
.PUSH
);
261 addChildButton
.setImage(addChildImage
);
262 addChildButton
.setToolTipText(Messages
.CustomTxtParserInputWizardPage_addChildLine
);
263 addChildButton
.addSelectionListener(new SelectionAdapter() {
265 public void widgetSelected(SelectionEvent e
) {
266 InputLine inputLine
= new InputLine(Cardinality
.ZERO_OR_MORE
, "", null); //$NON-NLS-1$
267 if (((List
<?
>) treeViewer
.getInput()).size() == 0) {
268 definition
.inputs
.add(inputLine
);
269 } else if (treeViewer
.getSelection().isEmpty()) {
272 InputLine parentInputLine
= (InputLine
) ((IStructuredSelection
) treeViewer
.getSelection()).getFirstElement();
273 parentInputLine
.addChild(inputLine
);
275 treeViewer
.refresh();
276 treeViewer
.setSelection(new StructuredSelection(inputLine
), true);
279 Button moveUpButton
= new Button(buttonBar
, SWT
.PUSH
);
280 moveUpButton
.setImage(moveUpImage
);
281 moveUpButton
.setToolTipText(Messages
.CustomTxtParserInputWizardPage_moveUp
);
282 moveUpButton
.addSelectionListener(new SelectionAdapter() {
284 public void widgetSelected(SelectionEvent e
) {
285 if (treeViewer
.getSelection().isEmpty()) {
288 InputLine inputLine
= (InputLine
) ((IStructuredSelection
) treeViewer
.getSelection()).getFirstElement();
289 if (inputLine
.parentInput
== null) {
290 for (int i
= 1; i
< definition
.inputs
.size(); i
++) {
291 if (definition
.inputs
.get(i
).equals(inputLine
)) {
292 definition
.inputs
.add(i
- 1 , definition
.inputs
.remove(i
));
299 treeViewer
.refresh();
304 Button moveDownButton
= new Button(buttonBar
, SWT
.PUSH
);
305 moveDownButton
.setImage(moveDownImage
);
306 moveDownButton
.setToolTipText(Messages
.CustomTxtParserInputWizardPage_moveDown
);
307 moveDownButton
.addSelectionListener(new SelectionAdapter() {
309 public void widgetSelected(SelectionEvent e
) {
310 if (treeViewer
.getSelection().isEmpty()) {
313 InputLine inputLine
= (InputLine
) ((IStructuredSelection
) treeViewer
.getSelection()).getFirstElement();
314 if (inputLine
.parentInput
== null) {
315 for (int i
= 0; i
< definition
.inputs
.size() - 1; i
++) {
316 if (definition
.inputs
.get(i
).equals(inputLine
)) {
317 definition
.inputs
.add(i
+ 1 , definition
.inputs
.remove(i
));
322 inputLine
.moveDown();
324 treeViewer
.refresh();
330 SashForm vSash
= new SashForm(container
, SWT
.VERTICAL
);
331 vSash
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
332 vSash
.setBackground(vSash
.getDisplay().getSystemColor(SWT
.COLOR_GRAY
));
334 SashForm hSash
= new SashForm(vSash
, SWT
.HORIZONTAL
);
335 hSash
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
337 treeScrolledComposite
= new ScrolledComposite(hSash
, SWT
.V_SCROLL
| SWT
.H_SCROLL
);
338 GridData gd
= new GridData(SWT
.FILL
, SWT
.FILL
, true, true);
341 treeScrolledComposite
.setLayoutData(gd
);
342 treeContainer
= new Composite(treeScrolledComposite
, SWT
.NONE
);
343 treeContainer
.setLayout(new FillLayout());
344 treeScrolledComposite
.setContent(treeContainer
);
345 treeScrolledComposite
.setExpandHorizontal(true);
346 treeScrolledComposite
.setExpandVertical(true);
348 treeViewer
= new TreeViewer(treeContainer
, SWT
.SINGLE
| SWT
.BORDER
);
349 treeViewer
.setContentProvider(new InputLineTreeNodeContentProvider());
350 treeViewer
.setLabelProvider(new InputLineTreeLabelProvider());
351 treeViewer
.addSelectionChangedListener(new InputLineTreeSelectionChangedListener());
352 treeContainer
.layout();
354 treeScrolledComposite
.setMinSize(treeContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).x
, treeContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).y
);
356 lineScrolledComposite
= new ScrolledComposite(hSash
, SWT
.V_SCROLL
);
357 lineScrolledComposite
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
358 lineContainer
= new Composite(lineScrolledComposite
, SWT
.NONE
);
359 GridLayout linesLayout
= new GridLayout();
360 linesLayout
.marginHeight
= 1;
361 linesLayout
.marginWidth
= 0;
362 lineContainer
.setLayout(linesLayout
);
363 lineScrolledComposite
.setContent(lineContainer
);
364 lineScrolledComposite
.setExpandHorizontal(true);
365 lineScrolledComposite
.setExpandVertical(true);
367 if (definition
== null) {
368 definition
= new CustomTxtTraceDefinition();
369 definition
.inputs
.add(new InputLine(Cardinality
.ZERO_OR_MORE
, DEFAULT_REGEX
,
370 Arrays
.asList(new InputData(CustomTraceDefinition
.TAG_MESSAGE
, CustomTraceDefinition
.ACTION_SET
))));
372 loadDefinition(definition
);
373 treeViewer
.expandAll();
374 lineContainer
.layout();
376 logtypeText
.addModifyListener(updateListener
);
377 timestampOutputFormatText
.addModifyListener(updateListener
);
379 lineScrolledComposite
.setMinSize(lineContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).x
, lineContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).y
-1);
381 hSash
.setWeights(new int[] {1, 2});
383 Composite sashBottom
= new Composite(vSash
, SWT
.NONE
);
384 GridLayout sashBottomLayout
= new GridLayout(3, false);
385 sashBottomLayout
.marginHeight
= 0;
386 sashBottomLayout
.marginWidth
= 0;
387 sashBottom
.setLayout(sashBottomLayout
);
389 Label previewLabel
= new Label(sashBottom
, SWT
.NULL
);
390 previewLabel
.setText(Messages
.CustomTxtParserInputWizardPage_previewInput
);
391 previewLabel
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
393 Button highlightAllButton
= new Button(sashBottom
, SWT
.PUSH
);
394 highlightAllButton
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
395 highlightAllButton
.setText(Messages
.CustomTxtParserInputWizardPage_highlightAll
);
396 highlightAllButton
.addSelectionListener(new SelectionAdapter() {
398 public void widgetSelected(SelectionEvent e
) {
399 updatePreviews(true);
403 Button legendButton
= new Button(sashBottom
, SWT
.PUSH
);
404 legendButton
.setImage(helpImage
);
405 legendButton
.setToolTipText(Messages
.CustomTxtParserInputWizardPage_previewLegend
);
406 legendButton
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
407 legendButton
.addSelectionListener(new SelectionAdapter() {
409 public void widgetSelected(SelectionEvent e
) {
414 inputText
= new StyledText(sashBottom
, SWT
.MULTI
| SWT
.V_SCROLL
| SWT
.H_SCROLL
);
415 if (fixedFont
== null) {
416 if (System
.getProperty("os.name").contains("Windows")) { //$NON-NLS-1$ //$NON-NLS-2$
417 fixedFont
= new Font(Display
.getCurrent(), new FontData("Courier New", 10, SWT
.NORMAL
)); //$NON-NLS-1$
419 fixedFont
= new Font(Display
.getCurrent(), new FontData("Monospace", 10, SWT
.NORMAL
)); //$NON-NLS-1$
422 inputText
.setFont(fixedFont
);
423 gd
= new GridData(SWT
.FILL
, SWT
.FILL
, true, true, 3, 1);
424 gd
.heightHint
= inputText
.computeSize(SWT
.DEFAULT
, inputText
.getLineHeight() * 4).y
;
426 inputText
.setLayoutData(gd
);
427 inputText
.setText(getSelectionText());
428 inputText
.addModifyListener(updateListener
);
430 vSash
.setWeights(new int[] {hSash
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).y
, sashBottom
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).y
});
432 setControl(container
);
438 private static class InputLineTreeNodeContentProvider
implements ITreeContentProvider
{
441 public Object
[] getElements(Object inputElement
) {
442 return ((List
<?
>) inputElement
).toArray();
446 public Object
[] getChildren(Object parentElement
) {
447 InputLine inputLine
= (InputLine
) parentElement
;
448 if (inputLine
.childrenInputs
== null) {
449 return new InputLine
[0];
451 return inputLine
.childrenInputs
.toArray();
455 public boolean hasChildren(Object element
) {
456 InputLine inputLine
= (InputLine
) element
;
457 return (inputLine
.childrenInputs
!= null && inputLine
.childrenInputs
.size() > 0);
461 public void dispose() {
465 public void inputChanged(Viewer viewer
, Object oldInput
, Object newInput
) {
469 public Object
getParent(Object element
) {
470 InputLine inputLine
= (InputLine
) element
;
471 return inputLine
.parentInput
;
475 private class InputLineTreeLabelProvider
extends ColumnLabelProvider
{
478 public Image
getImage(Object element
) {
483 public String
getText(Object element
) {
484 InputLine inputLine
= (InputLine
) element
;
485 if (inputLine
.parentInput
== null) {
486 return "Root Line " + getName(inputLine
) + " " + inputLine
.cardinality
.toString() + " : " + inputLine
.getRegex(); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
488 return "Line " + getName(inputLine
) + " " + inputLine
.cardinality
.toString() + " : " + inputLine
.getRegex(); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
492 private class InputLineTreeSelectionChangedListener
implements ISelectionChangedListener
{
494 public void selectionChanged(SelectionChangedEvent event
) {
495 if (selectedLine
!= null) {
496 selectedLine
.dispose();
498 if (!(event
.getSelection().isEmpty()) && event
.getSelection() instanceof IStructuredSelection
) {
499 IStructuredSelection sel
= (IStructuredSelection
) event
.getSelection();
500 InputLine inputLine
= (InputLine
) sel
.getFirstElement();
501 selectedLine
= new Line(lineContainer
, getName(inputLine
), inputLine
);
502 lineContainer
.layout();
503 lineScrolledComposite
.setMinSize(lineContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).x
, lineContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).y
- 1);
512 public void dispose() {
513 if (fixedFont
!= null) {
520 private void loadDefinition(CustomTxtTraceDefinition def
) {
521 logtypeText
.setText(def
.definitionName
);
522 timestampOutputFormatText
.setText(def
.timeStampOutputFormat
);
523 treeViewer
.setInput(def
.inputs
);
524 if (def
.inputs
.size() > 0) {
525 InputLine inputLine
= def
.inputs
.get(0);
526 treeViewer
.setSelection(new StructuredSelection(inputLine
));
530 private String
getName(InputLine inputLine
) {
531 if (inputLine
.parentInput
== null) {
532 return Integer
.toString(definition
.inputs
.indexOf(inputLine
)+1);
534 return getName(inputLine
.parentInput
) + "." + Integer
.toString(inputLine
.parentInput
.childrenInputs
.indexOf(inputLine
)+1); //$NON-NLS-1$
538 * Get the global list of input names.
540 * @return The list of input names
542 public List
<String
> getInputNames() {
543 List
<String
> inputs
= new ArrayList
<String
>();
544 for (InputLine inputLine
: definition
.inputs
) {
545 for (String inputName
: getInputNames(inputLine
)) {
546 if (!inputs
.contains(inputName
)) {
547 inputs
.add(inputName
);
555 * Get the list of input names for the given input line.
559 * @return The list of input names
561 public List
<String
> getInputNames(InputLine inputLine
) {
562 List
<String
> inputs
= new ArrayList
<String
>();
563 if (inputLine
.columns
!= null) {
564 for (InputData inputData
: inputLine
.columns
) {
565 String inputName
= inputData
.name
;
566 if (!inputs
.contains(inputName
)) {
567 inputs
.add(inputName
);
571 if (inputLine
.childrenInputs
!= null) {
572 for (InputLine childInputLine
: inputLine
.childrenInputs
) {
573 for (String inputName
: getInputNames(childInputLine
)) {
574 if (!inputs
.contains(inputName
)) {
575 inputs
.add(inputName
);
583 private void removeLine() {
584 selectedLine
.dispose();
586 lineContainer
.layout();
587 lineScrolledComposite
.setMinSize(lineContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).x
, lineContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).y
-1);
591 private String
getSelectionText() {
592 if (this.selection
instanceof IStructuredSelection
) {
593 Object sel
= ((IStructuredSelection
) this.selection
).getFirstElement();
594 if (sel
instanceof IFile
) {
595 IFile file
= (IFile
)sel
;
596 BufferedReader reader
= null;
598 reader
= new BufferedReader(new InputStreamReader(file
.getContents()));
599 StringBuilder sb
= new StringBuilder();
601 while ((line
= reader
.readLine()) != null) {
602 sb
.append(line
+ "\n"); //$NON-NLS-1$
604 return sb
.toString();
605 } catch (CoreException e
) {
606 return ""; //$NON-NLS-1$
607 } catch (IOException e
) {
608 return ""; //$NON-NLS-1$
610 if (reader
!= null) {
613 } catch (IOException e
) {
619 return ""; //$NON-NLS-1$
622 private void updatePreviews() {
623 updatePreviews(false);
626 private void updatePreviews(boolean updateAll
) {
627 if (inputText
== null) {
628 // early update during construction
631 inputText
.setStyleRanges(new StyleRange
[] {});
633 Scanner scanner
= new Scanner(inputText
.getText());
634 scanner
.useDelimiter("\n"); //$NON-NLS-1$
636 String skip
; // skip starting delimiters
637 if ((skip
= scanner
.findWithinHorizon("\\A\n+", 0)) != null) { //$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
<String
, String
>();
649 int rootLineMatches
= 0;
650 String firstEntryTimeStamp
= null;
651 String firstEntryTimeStampInputFormat
= null;
654 while (scanner
.hasNext()) {
655 if (rootLineMatches
> 0 && !updateAll
) {
659 log
= scanner
.next();
661 int length
= log
.length();
662 for (InputLine rootInputLine
: definition
.inputs
) {
665 pattern
= rootInputLine
.getPattern();
666 } catch (PatternSyntaxException e
) {
669 Matcher matcher
= pattern
.matcher(log
);
670 if (matcher
.find()) {
672 inputText
.setStyleRange(new StyleRange(rawPos
, length
,
673 COLOR_BLACK
, COLOR_YELLOW
, SWT
.ITALIC
));
674 data
= new HashMap
<String
, String
>();
675 timeStampFormat
= null;
676 updatePreviewLine(rootInputLine
, matcher
, data
, rawPos
, rootLineMatches
);
677 if (rootLineMatches
== 1) {
678 firstEntryTimeStamp
= data
.get(CustomTraceDefinition
.TAG_TIMESTAMP
);
679 firstEntryTimeStampInputFormat
= timeStampFormat
;
681 HashMap
<InputLine
, Integer
> countMap
= new HashMap
<InputLine
, Integer
>();
682 InputLine currentInput
= null;
683 if (rootInputLine
.childrenInputs
!= null && rootInputLine
.childrenInputs
.size() > 0) {
684 currentInput
= rootInputLine
.childrenInputs
.get(0);
685 countMap
.put(currentInput
, 0);
687 rawPos
+= length
+ 1; // +1 for \n
688 while (scanner
.hasNext()) {
689 log
= scanner
.next();
690 length
= log
.length();
691 boolean processed
= false;
692 if (currentInput
== null) {
693 for (InputLine input
: definition
.inputs
) {
694 matcher
= input
.getPattern().matcher(log
);
695 if (matcher
.find()) {
700 if (countMap
.get(currentInput
) >= currentInput
.getMinCount()) {
701 List
<InputLine
> nextInputs
= currentInput
.getNextInputs(countMap
);
702 if (nextInputs
.size() == 0 || nextInputs
.get(nextInputs
.size() - 1).getMinCount() == 0) {
703 for (InputLine input
: definition
.inputs
) {
704 matcher
= input
.getPattern().matcher(log
);
705 if (matcher
.find()) {
710 for (InputLine input
: nextInputs
) {
711 matcher
= input
.getPattern().matcher(log
);
712 if (matcher
.find()) {
713 inputText
.setStyleRange(new StyleRange(rawPos
, length
,
714 COLOR_BLACK
, COLOR_LIGHT_YELLOW
, SWT
.ITALIC
));
715 currentInput
= input
;
716 updatePreviewLine(currentInput
, matcher
, data
, rawPos
, rootLineMatches
);
717 if (countMap
.get(currentInput
) == null) {
718 countMap
.put(currentInput
, 1);
720 countMap
.put(currentInput
, countMap
.get(currentInput
) + 1);
722 Iterator
<InputLine
> iter
= countMap
.keySet().iterator();
723 while (iter
.hasNext()) {
724 InputLine inputLine
= iter
.next();
725 if (inputLine
.level
> currentInput
.level
) {
729 if (currentInput
.childrenInputs
!= null && currentInput
.childrenInputs
.size() > 0) {
730 currentInput
= currentInput
.childrenInputs
.get(0);
731 countMap
.put(currentInput
, 0);
733 if (countMap
.get(currentInput
) >= currentInput
.getMaxCount()) {
734 if (currentInput
.getNextInputs(countMap
).size() > 0) {
735 currentInput
= currentInput
.getNextInputs(countMap
).get(0);
736 if (countMap
.get(currentInput
) == null) {
737 countMap
.put(currentInput
, 0);
739 iter
= countMap
.keySet().iterator();
740 while (iter
.hasNext()) {
741 InputLine inputLine
= iter
.next();
742 if (inputLine
.level
> currentInput
.level
) {
756 if (!processed
&& currentInput
!= null) {
757 matcher
= currentInput
.getPattern().matcher(log
);
758 if (matcher
.find()) {
759 inputText
.setStyleRange(new StyleRange(rawPos
, length
,
760 COLOR_BLACK
, COLOR_LIGHT_YELLOW
, SWT
.ITALIC
));
761 updatePreviewLine(currentInput
, matcher
, data
, rawPos
, rootLineMatches
);
762 countMap
.put(currentInput
, countMap
.get(currentInput
) + 1);
763 if (currentInput
.childrenInputs
!= null && currentInput
.childrenInputs
.size() > 0) {
764 currentInput
= currentInput
.childrenInputs
.get(0);
765 countMap
.put(currentInput
, 0);
767 if (countMap
.get(currentInput
) >= currentInput
.getMaxCount()) {
768 if (currentInput
.getNextInputs(countMap
).size() > 0) {
769 currentInput
= currentInput
.getNextInputs(countMap
).get(0);
770 if (countMap
.get(currentInput
) == null) {
771 countMap
.put(currentInput
, 0);
773 Iterator
<InputLine
> iter
= countMap
.keySet().iterator();
774 while (iter
.hasNext()) {
775 InputLine inputLine
= iter
.next();
776 if (inputLine
.level
> currentInput
.level
) {
788 rawPos
+= length
+ 1; // +1 for \n
794 rawPos
+= length
+ 1; // +1 for \n
798 if (rootLineMatches
== 1) {
799 firstEntryTimeStamp
= data
.get(CustomTraceDefinition
.TAG_TIMESTAMP
);
800 firstEntryTimeStampInputFormat
= timeStampFormat
;
802 if (firstEntryTimeStamp
== null) {
803 timestampPreviewText
.setText(Messages
.CustomTxtParserInputWizardPage_noTimestampGroup
);
804 if (selectedLine
!= null) {
805 for (InputGroup group
: selectedLine
.inputs
) {
806 if (group
.tagCombo
.getText().equals(CustomTraceDefinition
.TAG_TIMESTAMP
)) {
807 timestampPreviewText
.setText(Messages
.CustomTxtParserInputWizardPage_noMatchingTimestamp
);
814 SimpleDateFormat dateFormat
= new SimpleDateFormat(firstEntryTimeStampInputFormat
);
815 Date date
= dateFormat
.parse(firstEntryTimeStamp
);
816 dateFormat
= new SimpleDateFormat(timestampOutputFormatText
.getText().trim());
817 timestampPreviewText
.setText(dateFormat
.format(date
));
818 } catch (ParseException e
) {
819 timestampPreviewText
.setText("*parse exception* [" + firstEntryTimeStamp
+ "] <> [" + firstEntryTimeStampInputFormat
+ "]"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
820 } catch (IllegalArgumentException e
) {
821 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 if (selectedLine
.inputs
.get(i
).previewText
.getText().equals(Messages
.CustomTxtParserInputWizardPage_noMatchingLine
)) {
841 selectedLine
.inputs
.get(i
).previewText
.setText(value
);
844 if (value
.length() == 0) {
847 if (input
.action
== CustomTraceDefinition
.ACTION_SET
) {
848 data
.put(input
.name
, value
);
849 if (input
.name
.equals(CustomTraceDefinition
.TAG_TIMESTAMP
)) {
850 timeStampFormat
= input
.format
;
852 } else if (input
.action
== CustomTraceDefinition
.ACTION_APPEND
) {
853 String s
= data
.get(input
.name
);
855 data
.put(input
.name
, s
+ value
);
857 data
.put(input
.name
, value
);
859 if (input
.name
.equals(CustomTraceDefinition
.TAG_TIMESTAMP
)) {
860 if (timeStampFormat
!= null) {
861 timeStampFormat
+= input
.format
;
863 timeStampFormat
= input
.format
;
866 } else if (input
.action
== CustomTraceDefinition
.ACTION_APPEND_WITH_SEPARATOR
) {
867 String s
= data
.get(input
.name
);
869 data
.put(input
.name
, s
+ " | " + value
); //$NON-NLS-1$
871 data
.put(input
.name
, value
);
873 if (input
.name
.equals(CustomTraceDefinition
.TAG_TIMESTAMP
)) {
874 if (timeStampFormat
!= null) {
875 timeStampFormat
+= " | " + input
.format
; //$NON-NLS-1$
877 timeStampFormat
= input
.format
;
882 if (selectedLine
!= null && selectedLine
.inputLine
.equals(line
) && rootLineMatches
== 1) {
883 if (selectedLine
.inputs
.get(i
).previewText
.getText().equals(Messages
.CustomTxtParserInputWizardPage_noMatchingLine
)) {
884 selectedLine
.inputs
.get(i
).previewText
.setText(Messages
.CustomTxtParserInputWizardPage_noMatchingGroup
);
889 // highlight the matching groups that have no corresponponding input
890 for (int i
= line
.columns
.size(); i
< matcher
.groupCount(); i
++) {
891 if (matcher
.group(i
+1) != null) {
892 if (line
.parentInput
== null) {
893 inputText
.setStyleRange(new StyleRange(rawPos
+ matcher
.start(i
+1), matcher
.end(i
+1) - matcher
.start(i
+1),
894 COLOR_BLACK
, COLOR_MAGENTA
));
896 inputText
.setStyleRange(new StyleRange(rawPos
+ matcher
.start(i
+1), matcher
.end(i
+1) - matcher
.start(i
+1),
897 COLOR_BLACK
, COLOR_LIGHT_MAGENTA
));
903 private void openHelpShell(String url
) {
904 if (helpBrowser
!= null && !helpBrowser
.isDisposed()) {
905 helpBrowser
.getShell().setActive();
906 if (!helpBrowser
.getUrl().equals(url
)) {
907 helpBrowser
.setUrl(url
);
911 final Shell helpShell
= new Shell(getShell(), SWT
.SHELL_TRIM
);
912 helpShell
.setLayout(new FillLayout());
913 helpBrowser
= new Browser(helpShell
, SWT
.NONE
);
914 helpBrowser
.addTitleListener(new TitleListener() {
916 public void changed(TitleEvent event
) {
917 helpShell
.setText(event
.title
);
920 helpBrowser
.setBounds(0, 0, 600, 400);
923 helpBrowser
.setUrl(url
);
926 private void openLegend() {
927 final String CG
= Messages
.CustomTxtParserInputWizardPage_capturedGroup
;
928 final String UCG
= Messages
.CustomTxtParserInputWizardPage_unidentifiedCaptureGroup
;
929 final String UT
= Messages
.CustomTxtParserInputWizardPage_uncapturedText
;
931 String line1
= Messages
.CustomTxtParserInputWizardPage_nonMatchingLine
;
932 int line2start
= line1start
+ line1
.length();
933 String line2
= Messages
.CustomTxtParserInputWizardPage_matchingLineRoot
+ CG
+ " " + UCG
+ " " + UT
+ " \n"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
934 int line3start
= line2start
+ line2
.length();
935 String line3
= Messages
.CustomTxtParserInputWizardPage_matchingOtherLine
+ CG
+ " " + UCG
+ " " + UT
+ " \n"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
936 int line4start
= line3start
+ line3
.length();
937 String line4
= Messages
.CustomTxtParserInputWizardPage_matchingOtherLine
+ CG
+ " " + UCG
+ " " + UT
+ " \n"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
938 int line5start
= line4start
+ line4
.length();
939 String line5
= Messages
.CustomTxtParserInputWizardPage_nonMatchingLine
;
940 int line6start
= line5start
+ line5
.length();
941 String line6
= Messages
.CustomTxtParserInputWizardPage_matchingRootLine
+ CG
+ " " + UCG
+ " " + UT
+ " \n"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
943 final Shell legendShell
= new Shell(getShell(), SWT
.DIALOG_TRIM
);
944 legendShell
.setLayout(new FillLayout());
945 StyledText legendText
= new StyledText(legendShell
, SWT
.MULTI
);
946 legendText
.setFont(fixedFont
);
947 legendText
.setText(line1
+ line2
+ line3
+ line4
+ line5
+ line6
);
948 legendText
.setStyleRange(new StyleRange(line2start
, line2
.length(), COLOR_BLACK
, COLOR_YELLOW
, SWT
.ITALIC
));
949 legendText
.setStyleRange(new StyleRange(line3start
, line3
.length(), COLOR_BLACK
, COLOR_LIGHT_YELLOW
, SWT
.ITALIC
));
950 legendText
.setStyleRange(new StyleRange(line4start
, line4
.length(), COLOR_BLACK
, COLOR_LIGHT_YELLOW
, SWT
.ITALIC
));
951 legendText
.setStyleRange(new StyleRange(line6start
, line6
.length(), COLOR_BLACK
, COLOR_YELLOW
, SWT
.ITALIC
));
952 legendText
.setStyleRange(new StyleRange(line2start
+ line2
.indexOf(CG
), CG
.length(), COLOR_BLACK
, COLOR_GREEN
, SWT
.BOLD
));
953 legendText
.setStyleRange(new StyleRange(line2start
+ line2
.indexOf(UCG
), UCG
.length(), COLOR_BLACK
, COLOR_MAGENTA
));
954 legendText
.setStyleRange(new StyleRange(line3start
+ line3
.indexOf(CG
), CG
.length(), COLOR_BLACK
, COLOR_LIGHT_GREEN
, SWT
.BOLD
));
955 legendText
.setStyleRange(new StyleRange(line3start
+ line3
.indexOf(UCG
), UCG
.length(), COLOR_BLACK
, COLOR_LIGHT_MAGENTA
));
956 legendText
.setStyleRange(new StyleRange(line4start
+ line4
.indexOf(CG
), CG
.length(), COLOR_BLACK
, COLOR_LIGHT_GREEN
, SWT
.BOLD
));
957 legendText
.setStyleRange(new StyleRange(line4start
+ line4
.indexOf(UCG
), UCG
.length(), COLOR_BLACK
, COLOR_LIGHT_MAGENTA
));
958 legendText
.setStyleRange(new StyleRange(line6start
+ line6
.indexOf(CG
), CG
.length(), COLOR_BLACK
, COLOR_GREEN
, SWT
.BOLD
));
959 legendText
.setStyleRange(new StyleRange(line6start
+ line6
.indexOf(UCG
), UCG
.length(), COLOR_BLACK
, COLOR_MAGENTA
));
960 legendShell
.setText(Messages
.CustomTxtParserInputWizardPage_previewLegend
);
965 private class UpdateListener
implements ModifyListener
, SelectionListener
{
968 public void modifyText(ModifyEvent e
) {
974 public void widgetDefaultSelected(SelectionEvent e
) {
980 public void widgetSelected(SelectionEvent e
) {
988 private static final String INFINITY_STRING
= "\u221E"; //$NON-NLS-1$
991 Composite labelComposite
;
993 Composite cardinalityContainer
;
994 Combo cardinalityCombo
;
995 Label cardinalityMinLabel
;
996 Text cardinalityMinText
;
997 Label cardinalityMaxLabel
;
998 Text cardinalityMaxText
;
999 Button infiniteButton
;
1000 List
<InputGroup
> inputs
= new ArrayList
<InputGroup
>();
1001 Button addGroupButton
;
1002 Label addGroupLabel
;
1004 public Line(Composite parent
, String name
, InputLine inputLine
) {
1005 this.inputLine
= inputLine
;
1007 group
= new Group(parent
, SWT
.NONE
);
1008 group
.setText(name
);
1009 group
.setLayout(new GridLayout(2, false));
1010 group
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
1012 labelComposite
= new Composite(group
, SWT
.FILL
);
1013 GridLayout labelLayout
= new GridLayout(1, false);
1014 labelLayout
.marginWidth
= 0;
1015 labelLayout
.marginHeight
= 0;
1016 labelComposite
.setLayout(labelLayout
);
1017 labelComposite
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
1019 Label label
= new Label(labelComposite
, SWT
.NULL
);
1020 label
.setText(Messages
.CustomTxtParserInputWizardPage_regularExpression
);
1022 Composite regexContainer
= new Composite(group
, SWT
.NONE
);
1023 GridLayout regexLayout
= new GridLayout(2, false);
1024 regexLayout
.marginHeight
= 0;
1025 regexLayout
.marginWidth
= 0;
1026 regexContainer
.setLayout(regexLayout
);
1027 regexContainer
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
1029 regexText
= new Text(regexContainer
, SWT
.BORDER
| SWT
.SINGLE
);
1030 GridData gd
= new GridData(SWT
.FILL
, SWT
.CENTER
, true, false);
1032 regexText
.setLayoutData(gd
);
1033 regexText
.setText(inputLine
.getRegex());
1034 regexText
.addModifyListener(updateListener
);
1036 Button regexHelpButton
= new Button(regexContainer
, SWT
.PUSH
);
1037 regexHelpButton
.setImage(helpImage
);
1038 regexHelpButton
.setToolTipText(Messages
.CustomTxtParserInputWizardPage_regularExpressionHelp
);
1039 regexHelpButton
.addSelectionListener(new SelectionAdapter() {
1041 public void widgetSelected(SelectionEvent e
) {
1042 openHelpShell(PATTERN_URL
);
1046 label
= new Label(group
, SWT
.NONE
);
1047 label
.setText(Messages
.CustomTxtParserInputWizardPage_cardinality
);
1048 label
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
1050 cardinalityContainer
= new Composite(group
, SWT
.NONE
);
1051 GridLayout cardinalityLayout
= new GridLayout(6, false);
1052 cardinalityLayout
.marginHeight
= 0;
1053 cardinalityLayout
.marginWidth
= 0;
1054 cardinalityContainer
.setLayout(cardinalityLayout
);
1055 cardinalityContainer
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
1057 cardinalityCombo
= new Combo(cardinalityContainer
, SWT
.DROP_DOWN
| SWT
.READ_ONLY
);
1058 cardinalityCombo
.setItems(new String
[] {
1059 Cardinality
.ZERO_OR_MORE
.toString(),
1060 Cardinality
.ONE_OR_MORE
.toString(),
1061 Cardinality
.ZERO_OR_ONE
.toString(),
1062 Cardinality
.ONE
.toString(),
1063 "(?,?)"}); //$NON-NLS-1$
1064 cardinalityCombo
.addSelectionListener(new SelectionListener() {
1066 public void widgetDefaultSelected(SelectionEvent e
) {}
1069 public void widgetSelected(SelectionEvent e
) {
1070 switch (cardinalityCombo
.getSelectionIndex()) {
1072 cardinalityMinLabel
.setVisible(true);
1073 cardinalityMinText
.setVisible(true);
1074 cardinalityMaxLabel
.setVisible(true);
1075 cardinalityMaxText
.setVisible(true);
1076 infiniteButton
.setVisible(true);
1079 cardinalityMinLabel
.setVisible(false);
1080 cardinalityMinText
.setVisible(false);
1081 cardinalityMaxLabel
.setVisible(false);
1082 cardinalityMaxText
.setVisible(false);
1083 infiniteButton
.setVisible(false);
1086 cardinalityContainer
.layout();
1092 cardinalityMinLabel
= new Label(cardinalityContainer
, SWT
.NONE
);
1093 cardinalityMinLabel
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
1094 cardinalityMinLabel
.setText(Messages
.CustomTxtParserInputWizardPage_min
);
1095 cardinalityMinLabel
.setVisible(false);
1097 cardinalityMinText
= new Text(cardinalityContainer
, SWT
.BORDER
| SWT
.SINGLE
);
1098 gd
= new GridData(SWT
.CENTER
, SWT
.CENTER
, false, false);
1100 cardinalityMinText
.setLayoutData(gd
);
1101 cardinalityMinText
.setVisible(false);
1103 cardinalityMaxLabel
= new Label(cardinalityContainer
, SWT
.NONE
);
1104 cardinalityMaxLabel
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
1105 cardinalityMaxLabel
.setText(Messages
.CustomTxtParserInputWizardPage_max
);
1106 cardinalityMaxLabel
.setVisible(false);
1108 cardinalityMaxText
= new Text(cardinalityContainer
, SWT
.BORDER
| SWT
.SINGLE
);
1109 gd
= new GridData(SWT
.CENTER
, SWT
.CENTER
, false, false);
1111 cardinalityMaxText
.setLayoutData(gd
);
1112 cardinalityMaxText
.setVisible(false);
1114 infiniteButton
= new Button(cardinalityContainer
, SWT
.PUSH
);
1115 infiniteButton
.setText(INFINITY_STRING
);
1116 infiniteButton
.setVisible(false);
1117 infiniteButton
.addSelectionListener(new SelectionAdapter(){
1119 public void widgetSelected(SelectionEvent e
) {
1120 cardinalityMaxText
.setText(INFINITY_STRING
);
1123 if (inputLine
.cardinality
.equals(Cardinality
.ZERO_OR_MORE
)) {
1124 cardinalityCombo
.select(0);
1125 } else if (inputLine
.cardinality
.equals(Cardinality
.ONE_OR_MORE
)) {
1126 cardinalityCombo
.select(1);
1127 } else if (inputLine
.cardinality
.equals(Cardinality
.ZERO_OR_ONE
)) {
1128 cardinalityCombo
.select(2);
1129 } else if (inputLine
.cardinality
.equals(Cardinality
.ONE
)) {
1130 cardinalityCombo
.select(3);
1132 cardinalityCombo
.select(4);
1133 cardinalityMinLabel
.setVisible(true);
1134 cardinalityMinText
.setVisible(true);
1135 if (inputLine
.getMinCount() >= 0) {
1136 cardinalityMinText
.setText(Integer
.toString(inputLine
.getMinCount()));
1138 cardinalityMaxLabel
.setVisible(true);
1139 cardinalityMaxText
.setVisible(true);
1140 if (inputLine
.getMaxCount() == Cardinality
.INF
) {
1141 cardinalityMaxText
.setText(INFINITY_STRING
);
1142 } else if (inputLine
.getMaxCount() >= 0) {
1143 cardinalityMaxText
.setText(Integer
.toString(inputLine
.getMaxCount()));
1145 infiniteButton
.setVisible(true);
1148 VerifyListener digitsListener
= new VerifyListener() {
1150 public void verifyText(VerifyEvent e
) {
1151 if (e
.text
.equals(INFINITY_STRING
)) {
1152 e
.doit
= e
.widget
== cardinalityMaxText
&& e
.start
== 0 && e
.end
== ((Text
) e
.widget
).getText().length();
1154 if (((Text
) e
.widget
).getText().equals(INFINITY_STRING
)) {
1155 e
.doit
= e
.start
== 0 && e
.end
== ((Text
) e
.widget
).getText().length();
1157 for (int i
= 0; i
< e
.text
.length(); i
++) {
1158 if (!Character
.isDigit(e
.text
.charAt(i
))) {
1166 cardinalityMinText
.addModifyListener(updateListener
);
1167 cardinalityMaxText
.addModifyListener(updateListener
);
1168 cardinalityMinText
.addVerifyListener(digitsListener
);
1169 cardinalityMaxText
.addVerifyListener(digitsListener
);
1171 if (inputLine
.columns
!= null) {
1172 for (InputData inputData
: inputLine
.columns
) {
1173 InputGroup inputGroup
= new InputGroup(group
, this, inputs
.size()+1);
1174 if (inputData
.name
.equals(CustomTraceDefinition
.TAG_TIMESTAMP
)) {
1175 inputGroup
.tagCombo
.select(0);
1176 inputGroup
.tagText
.setText(inputData
.format
);
1177 inputGroup
.tagLabel
.setText(Messages
.CustomTxtParserInputWizardPage_format
);
1178 inputGroup
.tagLabel
.setVisible(true);
1179 inputGroup
.tagText
.setVisible(true);
1180 inputGroup
.tagText
.addModifyListener(updateListener
);
1181 } else if (inputData
.name
.equals(CustomTraceDefinition
.TAG_MESSAGE
)) {
1182 inputGroup
.tagCombo
.select(1);
1184 inputGroup
.tagCombo
.select(2);
1185 inputGroup
.tagText
.setText(inputData
.name
);
1186 inputGroup
.tagLabel
.setText(Messages
.CustomTxtParserInputWizardPage_name
);
1187 inputGroup
.tagLabel
.setVisible(true);
1188 inputGroup
.tagText
.setVisible(true);
1189 inputGroup
.tagText
.addModifyListener(updateListener
);
1191 inputGroup
.actionCombo
.select(inputData
.action
);
1192 inputs
.add(inputGroup
);
1196 createAddGroupButton();
1199 private void createAddGroupButton() {
1200 addGroupButton
= new Button(group
, SWT
.PUSH
);
1201 addGroupButton
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
1202 addGroupButton
.setImage(addImage
);
1203 addGroupButton
.setToolTipText(Messages
.CustomTxtParserInputWizardPage_addGroup
);
1204 addGroupButton
.addSelectionListener(new SelectionAdapter() {
1206 public void widgetSelected(SelectionEvent e
) {
1207 removeAddGroupButton();
1208 inputs
.add(new InputGroup(group
, Line
.this, inputs
.size()+1));
1209 createAddGroupButton();
1210 lineContainer
.layout();
1211 lineScrolledComposite
.setMinSize(lineContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).x
, lineContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).y
-1);
1212 group
.getParent().layout();
1218 addGroupLabel
= new Label(group
, SWT
.NULL
);
1219 addGroupLabel
.setText(Messages
.CustomTxtParserInputWizardPage_newGroup
);
1222 private void removeAddGroupButton() {
1223 addGroupButton
.dispose();
1224 addGroupLabel
.dispose();
1227 private void removeInput(int inputNumber
) {
1228 int nb
= inputNumber
;
1229 if (--nb
< inputs
.size()) {
1230 inputs
.remove(nb
).dispose();
1231 for (int i
= nb
; i
< inputs
.size(); i
++) {
1232 inputs
.get(i
).setInputNumber(i
+1);
1234 lineContainer
.layout();
1235 lineScrolledComposite
.setMinSize(lineContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).x
, lineContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).y
-1);
1236 group
.getParent().layout();
1240 // private void setName(String name) {
1241 // this.name = name;
1242 // group.setText("Line " + name);
1245 private void dispose() {
1249 private void extractInputs() {
1250 inputLine
.setRegex(selectedLine
.regexText
.getText());
1251 switch (cardinalityCombo
.getSelectionIndex()) {
1253 inputLine
.cardinality
= Cardinality
.ZERO_OR_MORE
;
1256 inputLine
.cardinality
= Cardinality
.ONE_OR_MORE
;
1259 inputLine
.cardinality
= Cardinality
.ZERO_OR_ONE
;
1262 inputLine
.cardinality
= Cardinality
.ONE
;
1267 min
= Integer
.parseInt(cardinalityMinText
.getText());
1268 } catch (NumberFormatException e
) {
1272 if (cardinalityMaxText
.getText().equals(INFINITY_STRING
)) {
1273 max
= Cardinality
.INF
;
1275 max
= Integer
.parseInt(cardinalityMaxText
.getText());
1277 } catch (NumberFormatException e
) {
1280 inputLine
.cardinality
= new Cardinality(min
, max
);
1283 inputLine
.cardinality
= Cardinality
.ZERO_OR_MORE
;
1286 inputLine
.columns
= new ArrayList
<InputData
>(inputs
.size());
1287 for (int i
= 0; i
< inputs
.size(); i
++) {
1288 InputGroup grp
= inputs
.get(i
);
1289 InputData inputData
= new InputData();
1290 if (grp
.tagCombo
.getText().equals(CustomTraceDefinition
.TAG_OTHER
)) {
1291 inputData
.name
= grp
.tagText
.getText().trim();
1293 inputData
.name
= grp
.tagCombo
.getText();
1294 if (grp
.tagCombo
.getText().equals(CustomTraceDefinition
.TAG_TIMESTAMP
)) {
1295 inputData
.format
= grp
.tagText
.getText().trim();
1298 inputData
.action
= grp
.actionCombo
.getSelectionIndex();
1299 inputLine
.columns
.add(inputData
);
1304 private class InputGroup
{
1308 // children of parent (must be disposed)
1309 Composite labelComposite
;
1310 Composite tagComposite
;
1314 // children of labelComposite
1317 // children of tagComposite
1323 public InputGroup(Composite parent
, Line line
, int inputNumber
) {
1325 this.inputNumber
= inputNumber
;
1327 labelComposite
= new Composite(parent
, SWT
.FILL
);
1328 GridLayout labelLayout
= new GridLayout(2, false);
1329 labelLayout
.marginWidth
= 0;
1330 labelLayout
.marginHeight
= 0;
1331 labelComposite
.setLayout(labelLayout
);
1332 labelComposite
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
1334 Button deleteButton
= new Button(labelComposite
, SWT
.PUSH
);
1335 deleteButton
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
1336 deleteButton
.setImage(deleteImage
);
1337 deleteButton
.setToolTipText(Messages
.CustomTxtParserInputWizardPage_removeGroup
);
1338 deleteButton
.addSelectionListener(new SelectionAdapter() {
1340 public void widgetSelected(SelectionEvent e
) {
1341 InputGroup
.this.line
.removeInput(InputGroup
.this.inputNumber
);
1347 inputLabel
= new Label(labelComposite
, SWT
.NULL
);
1348 inputLabel
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
1349 inputLabel
.setText(Messages
.CustomTxtParserInputWizardPage_group
+ inputNumber
+ ":"); //$NON-NLS-1$
1351 tagComposite
= new Composite(parent
, SWT
.FILL
);
1352 GridLayout tagLayout
= new GridLayout(4, false);
1353 tagLayout
.marginWidth
= 0;
1354 tagLayout
.marginHeight
= 0;
1355 tagComposite
.setLayout(tagLayout
);
1356 tagComposite
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
1358 tagCombo
= new Combo(tagComposite
, SWT
.DROP_DOWN
| SWT
.READ_ONLY
);
1359 tagCombo
.setItems(new String
[] {CustomTraceDefinition
.TAG_TIMESTAMP
,
1360 CustomTraceDefinition
.TAG_MESSAGE
,
1361 CustomTraceDefinition
.TAG_OTHER
});
1363 tagCombo
.addSelectionListener(new SelectionListener(){
1365 public void widgetDefaultSelected(SelectionEvent e
) {}
1367 public void widgetSelected(SelectionEvent e
) {
1368 tagText
.removeModifyListener(updateListener
);
1369 switch (tagCombo
.getSelectionIndex()) {
1370 case 0: //Time Stamp
1371 tagLabel
.setText(Messages
.CustomTxtParserInputWizardPage_format
);
1372 tagLabel
.setVisible(true);
1373 tagText
.setVisible(true);
1374 tagText
.addModifyListener(updateListener
);
1377 tagLabel
.setVisible(false);
1378 tagText
.setVisible(false);
1381 tagLabel
.setText(Messages
.CustomTxtParserInputWizardPage_name
);
1382 tagLabel
.setVisible(true);
1383 tagText
.setVisible(true);
1384 tagText
.addModifyListener(updateListener
);
1387 tagLabel
.setVisible(false);
1388 tagText
.setVisible(false);
1393 tagComposite
.layout();
1398 tagLabel
= new Label(tagComposite
, SWT
.NULL
);
1399 tagLabel
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
1400 tagLabel
.setVisible(false);
1402 tagText
= new Text(tagComposite
, SWT
.BORDER
| SWT
.SINGLE
);
1403 GridData gd
= new GridData(SWT
.FILL
, SWT
.CENTER
, true, false);
1405 tagText
.setLayoutData(gd
);
1406 tagText
.setVisible(false);
1408 actionCombo
= new Combo(tagComposite
, SWT
.DROP_DOWN
| SWT
.READ_ONLY
);
1409 actionCombo
.setItems(new String
[] {Messages
.CustomTxtParserInputWizardPage_set
, Messages
.CustomTxtParserInputWizardPage_append
, Messages
.CustomTxtParserInputWizardPage_appendWith
});
1410 actionCombo
.select(0);
1411 actionCombo
.addSelectionListener(updateListener
);
1413 previewLabel
= new Label(parent
, SWT
.NULL
);
1414 previewLabel
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
1415 previewLabel
.setText(Messages
.CustomTxtParserInputWizardPage_preview
);
1417 previewText
= new Text(parent
, SWT
.BORDER
| SWT
.SINGLE
| SWT
.READ_ONLY
);
1418 gd
= new GridData(SWT
.FILL
, SWT
.CENTER
, true, false);
1420 previewText
.setLayoutData(gd
);
1421 previewText
.setText(Messages
.CustomTxtParserInputWizardPage_noMatch
);
1422 previewText
.setBackground(COLOR_WIDGET_BACKGROUND
);
1425 private void dispose() {
1426 labelComposite
.dispose();
1427 tagComposite
.dispose();
1428 previewLabel
.dispose();
1429 previewText
.dispose();
1432 private void setInputNumber(int inputNumber
) {
1433 this.inputNumber
= inputNumber
;
1434 inputLabel
.setText(Messages
.CustomTxtParserInputWizardPage_group
+ inputNumber
+ ":"); //$NON-NLS-1$
1435 labelComposite
.layout();
1439 private void validate() {
1441 definition
.definitionName
= logtypeText
.getText().trim();
1442 definition
.timeStampOutputFormat
= timestampOutputFormatText
.getText().trim();
1444 if (selectedLine
!= null) {
1445 selectedLine
.extractInputs();
1446 treeViewer
.refresh();
1449 StringBuffer errors
= new StringBuffer();
1451 if (definition
.definitionName
.length() == 0) {
1452 errors
.append("Enter a name for the new log type. "); //$NON-NLS-1$
1453 logtypeText
.setBackground(COLOR_LIGHT_RED
);
1455 logtypeText
.setBackground(COLOR_TEXT_BACKGROUND
);
1456 for (CustomTxtTraceDefinition def
: CustomTxtTraceDefinition
.loadAll()) {
1457 if (definition
.definitionName
.equals(def
.definitionName
)) {
1458 if (editDefinitionName
== null || ! editDefinitionName
.equals(definition
.definitionName
)) {
1459 errors
.append("The log type name already exists. "); //$NON-NLS-1$
1460 logtypeText
.setBackground(COLOR_LIGHT_RED
);
1467 timestampFound
= false;
1468 for (int i
= 0; i
< definition
.inputs
.size(); i
++) {
1470 InputLine inputLine
= definition
.inputs
.get(i
);
1471 String name
= Integer
.toString(i
+1);
1472 errors
.append(validateLine(inputLine
, name
));
1474 if (timestampFound
) {
1475 if (definition
.timeStampOutputFormat
.length() == 0) {
1476 errors
.append("Enter the output format for the Time Stamp field. "); //$NON-NLS-1$
1477 timestampOutputFormatText
.setBackground(COLOR_LIGHT_RED
);
1480 new SimpleDateFormat(definition
.timeStampOutputFormat
);
1481 timestampOutputFormatText
.setBackground(COLOR_TEXT_BACKGROUND
);
1482 } catch (IllegalArgumentException e
) {
1483 errors
.append("Enter a valid output format for the Time Stamp field. "); //$NON-NLS-1$
1484 timestampOutputFormatText
.setBackground(COLOR_LIGHT_RED
);
1489 timestampOutputFormatText
.setBackground(COLOR_TEXT_BACKGROUND
);
1490 // timestampPreviewText.setBackground(COLOR_WIDGET_BACKGROUND);
1491 // errors.append("Identify a Time Stamp group (Line "+name+"). ");
1492 // timestampPreviewText.setText("*no timestamp group*");
1493 // timestampPreviewText.setBackground(COLOR_LIGHT_RED);
1496 if (errors
.length() == 0) {
1497 setDescription(defaultDescription
);
1498 setPageComplete(true);
1500 setDescription(errors
.toString());
1501 setPageComplete(false);
1506 * Validate an input line.
1509 * The line to clean up
1511 * The name of the line
1512 * @return The cleaned up line
1514 public StringBuffer
validateLine(InputLine inputLine
, String name
) {
1515 StringBuffer errors
= new StringBuffer();
1517 if (selectedLine
!= null && selectedLine
.inputLine
.equals(inputLine
)) {
1518 line
= selectedLine
;
1521 Pattern
.compile(inputLine
.getRegex());
1523 line
.regexText
.setBackground(COLOR_TEXT_BACKGROUND
);
1525 } catch (PatternSyntaxException e
) {
1526 errors
.append("Enter a valid regular expression (Line "+name
+"). "); //$NON-NLS-1$ //$NON-NLS-2$
1528 line
.regexText
.setBackground(COLOR_LIGHT_RED
);
1531 if (inputLine
.getMinCount() == -1) {
1532 errors
.append("Enter a minimum value for cardinality (Line "+name
+"). "); //$NON-NLS-1$ //$NON-NLS-2$
1534 line
.cardinalityMinText
.setBackground(COLOR_LIGHT_RED
);
1538 line
.cardinalityMinText
.setBackground(COLOR_TEXT_BACKGROUND
);
1541 if (inputLine
.getMaxCount() == -1) {
1542 errors
.append("Enter a maximum value for cardinality (Line "+name
+"). "); //$NON-NLS-1$ //$NON-NLS-2$
1544 line
.cardinalityMaxText
.setBackground(COLOR_LIGHT_RED
);
1546 } else if (inputLine
.getMinCount() > inputLine
.getMaxCount()) {
1547 errors
.append("Enter correct (min <= max) values for cardinality (Line "+name
+"). "); //$NON-NLS-1$ //$NON-NLS-2$
1549 line
.cardinalityMinText
.setBackground(COLOR_LIGHT_RED
);
1552 line
.cardinalityMaxText
.setBackground(COLOR_LIGHT_RED
);
1556 line
.cardinalityMaxText
.setBackground(COLOR_TEXT_BACKGROUND
);
1559 for (int i
= 0; inputLine
.columns
!= null && i
< inputLine
.columns
.size(); i
++) {
1560 InputData inputData
= inputLine
.columns
.get(i
);
1561 InputGroup group
= null;
1563 group
= line
.inputs
.get(i
);
1565 if (inputData
.name
.equals(CustomTraceDefinition
.TAG_TIMESTAMP
)) {
1566 timestampFound
= true;
1567 if (inputData
.format
.length() == 0) {
1568 errors
.append("Enter the 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 new SimpleDateFormat(inputData
.format
);
1575 if (group
!= null) {
1576 group
.tagText
.setBackground(COLOR_TEXT_BACKGROUND
);
1578 } catch (IllegalArgumentException e
) {
1579 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$
1580 if (group
!= null) {
1581 group
.tagText
.setBackground(COLOR_LIGHT_RED
);
1585 } else if (inputData
.name
.length() == 0) {
1586 errors
.append("Enter a name for the data group (Line "+name
+" Group "+(i
+1)+"). "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
1587 if (group
!= null) {
1588 group
.tagText
.setBackground(COLOR_LIGHT_RED
);
1591 if (group
!= null) {
1592 group
.tagText
.setBackground(COLOR_TEXT_BACKGROUND
);
1596 for (int i
= 0; inputLine
.childrenInputs
!= null && i
< inputLine
.childrenInputs
.size(); i
++) {
1597 errors
.append(validateLine(inputLine
.childrenInputs
.get(i
), name
+"."+(i
+1))); //$NON-NLS-1$
1603 * Get the trace definition.
1605 * @return The trace definition
1607 public CustomTxtTraceDefinition
getDefinition() {
1612 * Get the raw text of the input.
1614 * @return The raw input text
1616 public char[] getInputText() {
1617 return inputText
.getText().toCharArray();