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 selection
= (IStructuredSelection
) event
.getSelection();
500 InputLine inputLine
= (InputLine
) selection
.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 * @see org.eclipse.jface.dialogs.DialogPage#dispose()
515 public void dispose() {
516 if (fixedFont
!= null) {
523 private void loadDefinition(CustomTxtTraceDefinition def
) {
524 logtypeText
.setText(def
.definitionName
);
525 timestampOutputFormatText
.setText(def
.timeStampOutputFormat
);
526 treeViewer
.setInput(def
.inputs
);
527 if (def
.inputs
.size() > 0) {
528 InputLine inputLine
= def
.inputs
.get(0);
529 treeViewer
.setSelection(new StructuredSelection(inputLine
));
533 private String
getName(InputLine inputLine
) {
534 if (inputLine
.parentInput
== null) {
535 return Integer
.toString(definition
.inputs
.indexOf(inputLine
)+1);
537 return getName(inputLine
.parentInput
) + "." + Integer
.toString(inputLine
.parentInput
.childrenInputs
.indexOf(inputLine
)+1); //$NON-NLS-1$
541 * Get the global list of input names.
543 * @return The list of input names
545 public List
<String
> getInputNames() {
546 List
<String
> inputs
= new ArrayList
<String
>();
547 for (InputLine inputLine
: definition
.inputs
) {
548 for (String inputName
: getInputNames(inputLine
)) {
549 if (!inputs
.contains(inputName
)) {
550 inputs
.add(inputName
);
558 * Get the list of input names for the given input line.
562 * @return The list of input names
564 public List
<String
> getInputNames(InputLine inputLine
) {
565 List
<String
> inputs
= new ArrayList
<String
>();
566 if (inputLine
.columns
!= null) {
567 for (InputData inputData
: inputLine
.columns
) {
568 String inputName
= inputData
.name
;
569 if (!inputs
.contains(inputName
)) {
570 inputs
.add(inputName
);
574 if (inputLine
.childrenInputs
!= null) {
575 for (InputLine childInputLine
: inputLine
.childrenInputs
) {
576 for (String inputName
: getInputNames(childInputLine
)) {
577 if (!inputs
.contains(inputName
)) {
578 inputs
.add(inputName
);
586 private void removeLine() {
587 selectedLine
.dispose();
589 lineContainer
.layout();
590 lineScrolledComposite
.setMinSize(lineContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).x
, lineContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).y
-1);
594 private String
getSelectionText() {
595 if (this.selection
instanceof IStructuredSelection
) {
596 Object selection
= ((IStructuredSelection
)this.selection
).getFirstElement();
597 if (selection
instanceof IFile
) {
598 IFile file
= (IFile
)selection
;
599 BufferedReader reader
= null;
601 reader
= new BufferedReader(new InputStreamReader(file
.getContents()));
602 StringBuilder sb
= new StringBuilder();
604 while ((line
= reader
.readLine()) != null) {
605 sb
.append(line
+ "\n"); //$NON-NLS-1$
607 return sb
.toString();
608 } catch (CoreException e
) {
609 return ""; //$NON-NLS-1$
610 } catch (IOException e
) {
611 return ""; //$NON-NLS-1$
613 if (reader
!= null) {
616 } catch (IOException e
) {
622 return ""; //$NON-NLS-1$
625 private void updatePreviews() {
626 updatePreviews(false);
629 private void updatePreviews(boolean updateAll
) {
630 if (inputText
== null) {
631 // early update during construction
634 inputText
.setStyleRanges(new StyleRange
[] {});
636 Scanner scanner
= new Scanner(inputText
.getText());
637 scanner
.useDelimiter("\n"); //$NON-NLS-1$
639 String skip
; // skip starting delimiters
640 if ((skip
= scanner
.findWithinHorizon("\\A\n+", 0)) != null) { //$NON-NLS-1$
641 rawPos
+= skip
.length();
644 timeStampFormat
= null;
645 if (selectedLine
!= null) {
646 for (InputGroup input
: selectedLine
.inputs
) {
647 input
.previewText
.setText(Messages
.CustomTxtParserInputWizardPage_noMathcingLine
);
651 Map
<String
, String
> data
= new HashMap
<String
, String
>();
652 int rootLineMatches
= 0;
653 String firstEntryTimeStamp
= null;
654 String firstEntryTimeStampInputFormat
= null;
657 while (scanner
.hasNext()) {
658 if (rootLineMatches
> 0 && !updateAll
) {
662 log
= scanner
.next();
664 int length
= log
.length();
665 for (InputLine rootInputLine
: definition
.inputs
) {
668 pattern
= rootInputLine
.getPattern();
669 } catch (PatternSyntaxException e
) {
672 Matcher matcher
= pattern
.matcher(log
);
673 if (matcher
.find()) {
675 inputText
.setStyleRange(new StyleRange(rawPos
, length
,
676 COLOR_BLACK
, COLOR_YELLOW
, SWT
.ITALIC
));
677 data
= new HashMap
<String
, String
>();
678 timeStampFormat
= null;
679 updatePreviewLine(rootInputLine
, matcher
, data
, rawPos
, rootLineMatches
);
680 if (rootLineMatches
== 1) {
681 firstEntryTimeStamp
= data
.get(CustomTraceDefinition
.TAG_TIMESTAMP
);
682 firstEntryTimeStampInputFormat
= timeStampFormat
;
684 HashMap
<InputLine
, Integer
> countMap
= new HashMap
<InputLine
, Integer
>();
685 InputLine currentInput
= null;
686 if (rootInputLine
.childrenInputs
!= null && rootInputLine
.childrenInputs
.size() > 0) {
687 currentInput
= rootInputLine
.childrenInputs
.get(0);
688 countMap
.put(currentInput
, 0);
690 rawPos
+= length
+ 1; // +1 for \n
691 while (scanner
.hasNext()) {
692 log
= scanner
.next();
693 length
= log
.length();
694 boolean processed
= false;
695 if (currentInput
== null) {
696 for (InputLine input
: definition
.inputs
) {
697 matcher
= input
.getPattern().matcher(log
);
698 if (matcher
.find()) {
703 if (countMap
.get(currentInput
) >= currentInput
.getMinCount()) {
704 List
<InputLine
> nextInputs
= currentInput
.getNextInputs(countMap
);
705 if (nextInputs
.size() == 0 || nextInputs
.get(nextInputs
.size() - 1).getMinCount() == 0) {
706 for (InputLine input
: definition
.inputs
) {
707 matcher
= input
.getPattern().matcher(log
);
708 if (matcher
.find()) {
713 for (InputLine input
: nextInputs
) {
714 matcher
= input
.getPattern().matcher(log
);
715 if (matcher
.find()) {
716 inputText
.setStyleRange(new StyleRange(rawPos
, length
,
717 COLOR_BLACK
, COLOR_LIGHT_YELLOW
, SWT
.ITALIC
));
718 currentInput
= input
;
719 updatePreviewLine(currentInput
, matcher
, data
, rawPos
, rootLineMatches
);
720 if (countMap
.get(currentInput
) == null) {
721 countMap
.put(currentInput
, 1);
723 countMap
.put(currentInput
, countMap
.get(currentInput
) + 1);
725 Iterator
<InputLine
> iter
= countMap
.keySet().iterator();
726 while (iter
.hasNext()) {
727 InputLine inputLine
= iter
.next();
728 if (inputLine
.level
> currentInput
.level
) {
732 if (currentInput
.childrenInputs
!= null && currentInput
.childrenInputs
.size() > 0) {
733 currentInput
= currentInput
.childrenInputs
.get(0);
734 countMap
.put(currentInput
, 0);
736 if (countMap
.get(currentInput
) >= currentInput
.getMaxCount()) {
737 if (currentInput
.getNextInputs(countMap
).size() > 0) {
738 currentInput
= currentInput
.getNextInputs(countMap
).get(0);
739 if (countMap
.get(currentInput
) == null) {
740 countMap
.put(currentInput
, 0);
742 iter
= countMap
.keySet().iterator();
743 while (iter
.hasNext()) {
744 InputLine inputLine
= iter
.next();
745 if (inputLine
.level
> currentInput
.level
) {
760 matcher
= currentInput
.getPattern().matcher(log
);
761 if (matcher
.find()) {
762 inputText
.setStyleRange(new StyleRange(rawPos
, length
,
763 COLOR_BLACK
, COLOR_LIGHT_YELLOW
, SWT
.ITALIC
));
764 updatePreviewLine(currentInput
, matcher
, data
, rawPos
, rootLineMatches
);
765 countMap
.put(currentInput
, countMap
.get(currentInput
) + 1);
766 if (currentInput
.childrenInputs
!= null && currentInput
.childrenInputs
.size() > 0) {
767 currentInput
= currentInput
.childrenInputs
.get(0);
768 countMap
.put(currentInput
, 0);
770 if (countMap
.get(currentInput
) >= currentInput
.getMaxCount()) {
771 if (currentInput
.getNextInputs(countMap
).size() > 0) {
772 currentInput
= currentInput
.getNextInputs(countMap
).get(0);
773 if (countMap
.get(currentInput
) == null) {
774 countMap
.put(currentInput
, 0);
776 Iterator
<InputLine
> iter
= countMap
.keySet().iterator();
777 while (iter
.hasNext()) {
778 InputLine inputLine
= iter
.next();
779 if (inputLine
.level
> currentInput
.level
) {
791 rawPos
+= length
+ 1; // +1 for \n
797 rawPos
+= length
+ 1; // +1 for \n
801 if (rootLineMatches
== 1) {
802 firstEntryTimeStamp
= data
.get(CustomTraceDefinition
.TAG_TIMESTAMP
);
803 firstEntryTimeStampInputFormat
= timeStampFormat
;
805 if (firstEntryTimeStamp
== null) {
806 timestampPreviewText
.setText(Messages
.CustomTxtParserInputWizardPage_noTimestampGroup
);
807 if (selectedLine
!= null) {
808 for (InputGroup group
: selectedLine
.inputs
) {
809 if (group
.tagCombo
.getText().equals(CustomTraceDefinition
.TAG_TIMESTAMP
)) {
810 timestampPreviewText
.setText(Messages
.CustomTxtParserInputWizardPage_noMatchingTimestamp
);
817 SimpleDateFormat dateFormat
= new SimpleDateFormat(firstEntryTimeStampInputFormat
);
818 Date date
= dateFormat
.parse(firstEntryTimeStamp
);
819 dateFormat
= new SimpleDateFormat(timestampOutputFormatText
.getText().trim());
820 timestampPreviewText
.setText(dateFormat
.format(date
));
821 } catch (ParseException e
) {
822 timestampPreviewText
.setText("*parse exception* [" + firstEntryTimeStamp
+ "] <> [" + firstEntryTimeStampInputFormat
+ "]"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
823 } catch (IllegalArgumentException e
) {
824 timestampPreviewText
.setText("*parse exception* [Illegal Argument]"); //$NON-NLS-1$
830 private void updatePreviewLine(InputLine line
, Matcher matcher
, Map
<String
, String
> data
, int rawPos
, int rootLineMatches
) {
831 for (int i
= 0; i
< line
.columns
.size(); i
++) {
832 InputData input
= line
.columns
.get(i
);
833 if (i
< matcher
.groupCount() && matcher
.group(i
+1) != null) {
834 if (line
.parentInput
== null) {
835 inputText
.setStyleRange(new StyleRange(rawPos
+ matcher
.start(i
+1), matcher
.end(i
+1) - matcher
.start(i
+1),
836 COLOR_BLACK
, COLOR_GREEN
, SWT
.BOLD
));
838 inputText
.setStyleRange(new StyleRange(rawPos
+ matcher
.start(i
+1), matcher
.end(i
+1) - matcher
.start(i
+1),
839 COLOR_BLACK
, COLOR_LIGHT_GREEN
, SWT
.BOLD
));
841 String value
= matcher
.group(i
+1).trim();
842 if (selectedLine
!= null && selectedLine
.inputLine
.equals(line
) && rootLineMatches
== 1) {
843 if (selectedLine
.inputs
.get(i
).previewText
.getText().equals(Messages
.CustomTxtParserInputWizardPage_noMatchingLine
)) {
844 selectedLine
.inputs
.get(i
).previewText
.setText(value
);
847 if (value
.length() == 0) {
850 if (input
.action
== CustomTraceDefinition
.ACTION_SET
) {
851 data
.put(input
.name
, value
);
852 if (input
.name
.equals(CustomTraceDefinition
.TAG_TIMESTAMP
)) {
853 timeStampFormat
= input
.format
;
855 } else if (input
.action
== CustomTraceDefinition
.ACTION_APPEND
) {
856 String s
= data
.get(input
.name
);
858 data
.put(input
.name
, s
+ value
);
860 data
.put(input
.name
, value
);
862 if (input
.name
.equals(CustomTraceDefinition
.TAG_TIMESTAMP
)) {
863 if (timeStampFormat
!= null) {
864 timeStampFormat
+= input
.format
;
866 timeStampFormat
= input
.format
;
869 } else if (input
.action
== CustomTraceDefinition
.ACTION_APPEND_WITH_SEPARATOR
) {
870 String s
= data
.get(input
.name
);
872 data
.put(input
.name
, s
+ " | " + value
); //$NON-NLS-1$
874 data
.put(input
.name
, value
);
876 if (input
.name
.equals(CustomTraceDefinition
.TAG_TIMESTAMP
)) {
877 if (timeStampFormat
!= null) {
878 timeStampFormat
+= " | " + input
.format
; //$NON-NLS-1$
880 timeStampFormat
= input
.format
;
885 if (selectedLine
!= null && selectedLine
.inputLine
.equals(line
) && rootLineMatches
== 1) {
886 if (selectedLine
.inputs
.get(i
).previewText
.getText().equals(Messages
.CustomTxtParserInputWizardPage_noMatchingLine
)) {
887 selectedLine
.inputs
.get(i
).previewText
.setText(Messages
.CustomTxtParserInputWizardPage_noMatchingGroup
);
892 // highlight the matching groups that have no corresponponding input
893 for (int i
= line
.columns
.size(); i
< matcher
.groupCount(); i
++) {
894 if (matcher
.group(i
+1) != null) {
895 if (line
.parentInput
== null) {
896 inputText
.setStyleRange(new StyleRange(rawPos
+ matcher
.start(i
+1), matcher
.end(i
+1) - matcher
.start(i
+1),
897 COLOR_BLACK
, COLOR_MAGENTA
));
899 inputText
.setStyleRange(new StyleRange(rawPos
+ matcher
.start(i
+1), matcher
.end(i
+1) - matcher
.start(i
+1),
900 COLOR_BLACK
, COLOR_LIGHT_MAGENTA
));
906 private void openHelpShell(String url
) {
907 if (helpBrowser
!= null && !helpBrowser
.isDisposed()) {
908 helpBrowser
.getShell().setActive();
909 if (!helpBrowser
.getUrl().equals(url
)) {
910 helpBrowser
.setUrl(url
);
914 final Shell helpShell
= new Shell(getShell(), SWT
.SHELL_TRIM
);
915 helpShell
.setLayout(new FillLayout());
916 helpBrowser
= new Browser(helpShell
, SWT
.NONE
);
917 helpBrowser
.addTitleListener(new TitleListener() {
919 public void changed(TitleEvent event
) {
920 helpShell
.setText(event
.title
);
923 helpBrowser
.setBounds(0, 0, 600, 400);
926 helpBrowser
.setUrl(url
);
929 private void openLegend() {
930 final String CG
= Messages
.CustomTxtParserInputWizardPage_capturedGroup
;
931 final String UCG
= Messages
.CustomTxtParserInputWizardPage_unidentifiedCaptureGroup
;
932 final String UT
= Messages
.CustomTxtParserInputWizardPage_uncapturedText
;
934 String line1
= Messages
.CustomTxtParserInputWizardPage_nonMatchingLine
;
935 int line2start
= line1start
+ line1
.length();
936 String line2
= Messages
.CustomTxtParserInputWizardPage_matchingLineRoot
+ CG
+ " " + UCG
+ " " + UT
+ " \n"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
937 int line3start
= line2start
+ line2
.length();
938 String line3
= Messages
.CustomTxtParserInputWizardPage_matchingOtherLine
+ CG
+ " " + UCG
+ " " + UT
+ " \n"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
939 int line4start
= line3start
+ line3
.length();
940 String line4
= Messages
.CustomTxtParserInputWizardPage_matchingOtherLine
+ CG
+ " " + UCG
+ " " + UT
+ " \n"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
941 int line5start
= line4start
+ line4
.length();
942 String line5
= Messages
.CustomTxtParserInputWizardPage_nonMatchingLine
;
943 int line6start
= line5start
+ line5
.length();
944 String line6
= Messages
.CustomTxtParserInputWizardPage_matchingRootLine
+ CG
+ " " + UCG
+ " " + UT
+ " \n"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
946 final Shell legendShell
= new Shell(getShell(), SWT
.DIALOG_TRIM
);
947 legendShell
.setLayout(new FillLayout());
948 StyledText legendText
= new StyledText(legendShell
, SWT
.MULTI
);
949 legendText
.setFont(fixedFont
);
950 legendText
.setText(line1
+ line2
+ line3
+ line4
+ line5
+ line6
);
951 legendText
.setStyleRange(new StyleRange(line2start
, line2
.length(), COLOR_BLACK
, COLOR_YELLOW
, SWT
.ITALIC
));
952 legendText
.setStyleRange(new StyleRange(line3start
, line3
.length(), COLOR_BLACK
, COLOR_LIGHT_YELLOW
, SWT
.ITALIC
));
953 legendText
.setStyleRange(new StyleRange(line4start
, line4
.length(), COLOR_BLACK
, COLOR_LIGHT_YELLOW
, SWT
.ITALIC
));
954 legendText
.setStyleRange(new StyleRange(line6start
, line6
.length(), COLOR_BLACK
, COLOR_YELLOW
, SWT
.ITALIC
));
955 legendText
.setStyleRange(new StyleRange(line2start
+ line2
.indexOf(CG
), CG
.length(), COLOR_BLACK
, COLOR_GREEN
, SWT
.BOLD
));
956 legendText
.setStyleRange(new StyleRange(line2start
+ line2
.indexOf(UCG
), UCG
.length(), COLOR_BLACK
, COLOR_MAGENTA
));
957 legendText
.setStyleRange(new StyleRange(line3start
+ line3
.indexOf(CG
), CG
.length(), COLOR_BLACK
, COLOR_LIGHT_GREEN
, SWT
.BOLD
));
958 legendText
.setStyleRange(new StyleRange(line3start
+ line3
.indexOf(UCG
), UCG
.length(), COLOR_BLACK
, COLOR_LIGHT_MAGENTA
));
959 legendText
.setStyleRange(new StyleRange(line4start
+ line4
.indexOf(CG
), CG
.length(), COLOR_BLACK
, COLOR_LIGHT_GREEN
, SWT
.BOLD
));
960 legendText
.setStyleRange(new StyleRange(line4start
+ line4
.indexOf(UCG
), UCG
.length(), COLOR_BLACK
, COLOR_LIGHT_MAGENTA
));
961 legendText
.setStyleRange(new StyleRange(line6start
+ line6
.indexOf(CG
), CG
.length(), COLOR_BLACK
, COLOR_GREEN
, SWT
.BOLD
));
962 legendText
.setStyleRange(new StyleRange(line6start
+ line6
.indexOf(UCG
), UCG
.length(), COLOR_BLACK
, COLOR_MAGENTA
));
963 legendShell
.setText(Messages
.CustomTxtParserInputWizardPage_previewLegend
);
968 private class UpdateListener
implements ModifyListener
, SelectionListener
{
971 public void modifyText(ModifyEvent e
) {
977 public void widgetDefaultSelected(SelectionEvent e
) {
983 public void widgetSelected(SelectionEvent e
) {
991 private static final String INFINITY_STRING
= "\u221E"; //$NON-NLS-1$
994 Composite labelComposite
;
996 Composite cardinalityContainer
;
997 Combo cardinalityCombo
;
998 Label cardinalityMinLabel
;
999 Text cardinalityMinText
;
1000 Label cardinalityMaxLabel
;
1001 Text cardinalityMaxText
;
1002 Button infiniteButton
;
1003 List
<InputGroup
> inputs
= new ArrayList
<InputGroup
>();
1004 Button addGroupButton
;
1005 Label addGroupLabel
;
1007 public Line(Composite parent
, String name
, InputLine inputLine
) {
1008 this.inputLine
= inputLine
;
1010 group
= new Group(parent
, SWT
.NONE
);
1011 group
.setText(name
);
1012 group
.setLayout(new GridLayout(2, false));
1013 group
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
1015 labelComposite
= new Composite(group
, SWT
.FILL
);
1016 GridLayout labelLayout
= new GridLayout(1, false);
1017 labelLayout
.marginWidth
= 0;
1018 labelLayout
.marginHeight
= 0;
1019 labelComposite
.setLayout(labelLayout
);
1020 labelComposite
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
1022 Label label
= new Label(labelComposite
, SWT
.NULL
);
1023 label
.setText(Messages
.CustomTxtParserInputWizardPage_regularExpression
);
1025 Composite regexContainer
= new Composite(group
, SWT
.NONE
);
1026 GridLayout regexLayout
= new GridLayout(2, false);
1027 regexLayout
.marginHeight
= 0;
1028 regexLayout
.marginWidth
= 0;
1029 regexContainer
.setLayout(regexLayout
);
1030 regexContainer
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
1032 regexText
= new Text(regexContainer
, SWT
.BORDER
| SWT
.SINGLE
);
1033 GridData gd
= new GridData(SWT
.FILL
, SWT
.CENTER
, true, false);
1035 regexText
.setLayoutData(gd
);
1036 regexText
.setText(inputLine
.getRegex());
1037 regexText
.addModifyListener(updateListener
);
1039 Button regexHelpButton
= new Button(regexContainer
, SWT
.PUSH
);
1040 regexHelpButton
.setImage(helpImage
);
1041 regexHelpButton
.setToolTipText(Messages
.CustomTxtParserInputWizardPage_regularExpressionHelp
);
1042 regexHelpButton
.addSelectionListener(new SelectionAdapter() {
1044 public void widgetSelected(SelectionEvent e
) {
1045 openHelpShell(PATTERN_URL
);
1049 label
= new Label(group
, SWT
.NONE
);
1050 label
.setText(Messages
.CustomTxtParserInputWizardPage_cardinality
);
1051 label
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
1053 cardinalityContainer
= new Composite(group
, SWT
.NONE
);
1054 GridLayout cardinalityLayout
= new GridLayout(6, false);
1055 cardinalityLayout
.marginHeight
= 0;
1056 cardinalityLayout
.marginWidth
= 0;
1057 cardinalityContainer
.setLayout(cardinalityLayout
);
1058 cardinalityContainer
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
1060 cardinalityCombo
= new Combo(cardinalityContainer
, SWT
.DROP_DOWN
| SWT
.READ_ONLY
);
1061 cardinalityCombo
.setItems(new String
[] {
1062 Cardinality
.ZERO_OR_MORE
.toString(),
1063 Cardinality
.ONE_OR_MORE
.toString(),
1064 Cardinality
.ZERO_OR_ONE
.toString(),
1065 Cardinality
.ONE
.toString(),
1066 "(?,?)"}); //$NON-NLS-1$
1067 cardinalityCombo
.addSelectionListener(new SelectionListener() {
1069 public void widgetDefaultSelected(SelectionEvent e
) {}
1072 public void widgetSelected(SelectionEvent e
) {
1073 switch (cardinalityCombo
.getSelectionIndex()) {
1075 cardinalityMinLabel
.setVisible(true);
1076 cardinalityMinText
.setVisible(true);
1077 cardinalityMaxLabel
.setVisible(true);
1078 cardinalityMaxText
.setVisible(true);
1079 infiniteButton
.setVisible(true);
1082 cardinalityMinLabel
.setVisible(false);
1083 cardinalityMinText
.setVisible(false);
1084 cardinalityMaxLabel
.setVisible(false);
1085 cardinalityMaxText
.setVisible(false);
1086 infiniteButton
.setVisible(false);
1089 cardinalityContainer
.layout();
1095 cardinalityMinLabel
= new Label(cardinalityContainer
, SWT
.NONE
);
1096 cardinalityMinLabel
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
1097 cardinalityMinLabel
.setText(Messages
.CustomTxtParserInputWizardPage_min
);
1098 cardinalityMinLabel
.setVisible(false);
1100 cardinalityMinText
= new Text(cardinalityContainer
, SWT
.BORDER
| SWT
.SINGLE
);
1101 gd
= new GridData(SWT
.CENTER
, SWT
.CENTER
, false, false);
1103 cardinalityMinText
.setLayoutData(gd
);
1104 cardinalityMinText
.setVisible(false);
1106 cardinalityMaxLabel
= new Label(cardinalityContainer
, SWT
.NONE
);
1107 cardinalityMaxLabel
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
1108 cardinalityMaxLabel
.setText(Messages
.CustomTxtParserInputWizardPage_max
);
1109 cardinalityMaxLabel
.setVisible(false);
1111 cardinalityMaxText
= new Text(cardinalityContainer
, SWT
.BORDER
| SWT
.SINGLE
);
1112 gd
= new GridData(SWT
.CENTER
, SWT
.CENTER
, false, false);
1114 cardinalityMaxText
.setLayoutData(gd
);
1115 cardinalityMaxText
.setVisible(false);
1117 infiniteButton
= new Button(cardinalityContainer
, SWT
.PUSH
);
1118 infiniteButton
.setText(INFINITY_STRING
);
1119 infiniteButton
.setVisible(false);
1120 infiniteButton
.addSelectionListener(new SelectionAdapter(){
1122 public void widgetSelected(SelectionEvent e
) {
1123 cardinalityMaxText
.setText(INFINITY_STRING
);
1126 if (inputLine
.cardinality
.equals(Cardinality
.ZERO_OR_MORE
)) {
1127 cardinalityCombo
.select(0);
1128 } else if (inputLine
.cardinality
.equals(Cardinality
.ONE_OR_MORE
)) {
1129 cardinalityCombo
.select(1);
1130 } else if (inputLine
.cardinality
.equals(Cardinality
.ZERO_OR_ONE
)) {
1131 cardinalityCombo
.select(2);
1132 } else if (inputLine
.cardinality
.equals(Cardinality
.ONE
)) {
1133 cardinalityCombo
.select(3);
1135 cardinalityCombo
.select(4);
1136 cardinalityMinLabel
.setVisible(true);
1137 cardinalityMinText
.setVisible(true);
1138 if (inputLine
.getMinCount() >= 0) {
1139 cardinalityMinText
.setText(Integer
.toString(inputLine
.getMinCount()));
1141 cardinalityMaxLabel
.setVisible(true);
1142 cardinalityMaxText
.setVisible(true);
1143 if (inputLine
.getMaxCount() == Cardinality
.INF
) {
1144 cardinalityMaxText
.setText(INFINITY_STRING
);
1145 } else if (inputLine
.getMaxCount() >= 0) {
1146 cardinalityMaxText
.setText(Integer
.toString(inputLine
.getMaxCount()));
1148 infiniteButton
.setVisible(true);
1151 VerifyListener digitsListener
= new VerifyListener() {
1153 public void verifyText(VerifyEvent e
) {
1154 if (e
.text
.equals(INFINITY_STRING
)) {
1155 e
.doit
= e
.widget
== cardinalityMaxText
&& e
.start
== 0 && e
.end
== ((Text
) e
.widget
).getText().length();
1157 if (((Text
) e
.widget
).getText().equals(INFINITY_STRING
)) {
1158 e
.doit
= e
.start
== 0 && e
.end
== ((Text
) e
.widget
).getText().length();
1160 for (int i
= 0; i
< e
.text
.length(); i
++) {
1161 if (!Character
.isDigit(e
.text
.charAt(i
))) {
1169 cardinalityMinText
.addModifyListener(updateListener
);
1170 cardinalityMaxText
.addModifyListener(updateListener
);
1171 cardinalityMinText
.addVerifyListener(digitsListener
);
1172 cardinalityMaxText
.addVerifyListener(digitsListener
);
1174 if (inputLine
.columns
!= null) {
1175 for (InputData inputData
: inputLine
.columns
) {
1176 InputGroup inputGroup
= new InputGroup(group
, this, inputs
.size()+1);
1177 if (inputData
.name
.equals(CustomTraceDefinition
.TAG_TIMESTAMP
)) {
1178 inputGroup
.tagCombo
.select(0);
1179 inputGroup
.tagText
.setText(inputData
.format
);
1180 inputGroup
.tagLabel
.setText(Messages
.CustomTxtParserInputWizardPage_format
);
1181 inputGroup
.tagLabel
.setVisible(true);
1182 inputGroup
.tagText
.setVisible(true);
1183 inputGroup
.tagText
.addModifyListener(updateListener
);
1184 } else if (inputData
.name
.equals(CustomTraceDefinition
.TAG_MESSAGE
)) {
1185 inputGroup
.tagCombo
.select(1);
1187 inputGroup
.tagCombo
.select(2);
1188 inputGroup
.tagText
.setText(inputData
.name
);
1189 inputGroup
.tagLabel
.setText(Messages
.CustomTxtParserInputWizardPage_name
);
1190 inputGroup
.tagLabel
.setVisible(true);
1191 inputGroup
.tagText
.setVisible(true);
1192 inputGroup
.tagText
.addModifyListener(updateListener
);
1194 inputGroup
.actionCombo
.select(inputData
.action
);
1195 inputs
.add(inputGroup
);
1199 createAddGroupButton();
1202 private void createAddGroupButton() {
1203 addGroupButton
= new Button(group
, SWT
.PUSH
);
1204 addGroupButton
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
1205 addGroupButton
.setImage(addImage
);
1206 addGroupButton
.setToolTipText(Messages
.CustomTxtParserInputWizardPage_addGroup
);
1207 addGroupButton
.addSelectionListener(new SelectionAdapter() {
1209 public void widgetSelected(SelectionEvent e
) {
1210 removeAddGroupButton();
1211 inputs
.add(new InputGroup(group
, Line
.this, inputs
.size()+1));
1212 createAddGroupButton();
1213 lineContainer
.layout();
1214 lineScrolledComposite
.setMinSize(lineContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).x
, lineContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).y
-1);
1215 group
.getParent().layout();
1221 addGroupLabel
= new Label(group
, SWT
.NULL
);
1222 addGroupLabel
.setText(Messages
.CustomTxtParserInputWizardPage_newGroup
);
1225 private void removeAddGroupButton() {
1226 addGroupButton
.dispose();
1227 addGroupLabel
.dispose();
1230 private void removeInput(int inputNumber
) {
1231 if (--inputNumber
< inputs
.size()) {
1232 inputs
.remove(inputNumber
).dispose();
1233 for (int i
= inputNumber
; i
< inputs
.size(); i
++) {
1234 inputs
.get(i
).setInputNumber(i
+1);
1236 lineContainer
.layout();
1237 lineScrolledComposite
.setMinSize(lineContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).x
, lineContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).y
-1);
1238 group
.getParent().layout();
1242 // private void setName(String name) {
1243 // this.name = name;
1244 // group.setText("Line " + name);
1247 private void dispose() {
1251 private void extractInputs() {
1252 inputLine
.setRegex(selectedLine
.regexText
.getText());
1253 switch (cardinalityCombo
.getSelectionIndex()) {
1255 inputLine
.cardinality
= Cardinality
.ZERO_OR_MORE
;
1258 inputLine
.cardinality
= Cardinality
.ONE_OR_MORE
;
1261 inputLine
.cardinality
= Cardinality
.ZERO_OR_ONE
;
1264 inputLine
.cardinality
= Cardinality
.ONE
;
1269 min
= Integer
.parseInt(cardinalityMinText
.getText());
1270 } catch (NumberFormatException e
) {
1274 if (cardinalityMaxText
.getText().equals(INFINITY_STRING
)) {
1275 max
= Cardinality
.INF
;
1277 max
= Integer
.parseInt(cardinalityMaxText
.getText());
1279 } catch (NumberFormatException e
) {
1282 inputLine
.cardinality
= new Cardinality(min
, max
);
1285 inputLine
.cardinality
= Cardinality
.ZERO_OR_MORE
;
1288 inputLine
.columns
= new ArrayList
<InputData
>(inputs
.size());
1289 for (int i
= 0; i
< inputs
.size(); i
++) {
1290 InputGroup group
= inputs
.get(i
);
1291 InputData inputData
= new InputData();
1292 if (group
.tagCombo
.getText().equals(CustomTraceDefinition
.TAG_OTHER
)) {
1293 inputData
.name
= group
.tagText
.getText().trim();
1295 inputData
.name
= group
.tagCombo
.getText();
1296 if (group
.tagCombo
.getText().equals(CustomTraceDefinition
.TAG_TIMESTAMP
)) {
1297 inputData
.format
= group
.tagText
.getText().trim();
1300 inputData
.action
= group
.actionCombo
.getSelectionIndex();
1301 inputLine
.columns
.add(inputData
);
1306 private class InputGroup
{
1310 // children of parent (must be disposed)
1311 Composite labelComposite
;
1312 Composite tagComposite
;
1316 // children of labelComposite
1319 // children of tagComposite
1325 public InputGroup(Composite parent
, Line line
, int inputNumber
) {
1327 this.inputNumber
= inputNumber
;
1329 labelComposite
= new Composite(parent
, SWT
.FILL
);
1330 GridLayout labelLayout
= new GridLayout(2, false);
1331 labelLayout
.marginWidth
= 0;
1332 labelLayout
.marginHeight
= 0;
1333 labelComposite
.setLayout(labelLayout
);
1334 labelComposite
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
1336 Button deleteButton
= new Button(labelComposite
, SWT
.PUSH
);
1337 deleteButton
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
1338 deleteButton
.setImage(deleteImage
);
1339 deleteButton
.setToolTipText(Messages
.CustomTxtParserInputWizardPage_removeGroup
);
1340 deleteButton
.addSelectionListener(new SelectionAdapter() {
1342 public void widgetSelected(SelectionEvent e
) {
1343 InputGroup
.this.line
.removeInput(InputGroup
.this.inputNumber
);
1349 inputLabel
= new Label(labelComposite
, SWT
.NULL
);
1350 inputLabel
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
1351 inputLabel
.setText(Messages
.CustomTxtParserInputWizardPage_group
+ inputNumber
+ ":"); //$NON-NLS-1$
1353 tagComposite
= new Composite(parent
, SWT
.FILL
);
1354 GridLayout tagLayout
= new GridLayout(4, false);
1355 tagLayout
.marginWidth
= 0;
1356 tagLayout
.marginHeight
= 0;
1357 tagComposite
.setLayout(tagLayout
);
1358 tagComposite
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
1360 tagCombo
= new Combo(tagComposite
, SWT
.DROP_DOWN
| SWT
.READ_ONLY
);
1361 tagCombo
.setItems(new String
[] {CustomTraceDefinition
.TAG_TIMESTAMP
,
1362 CustomTraceDefinition
.TAG_MESSAGE
,
1363 CustomTraceDefinition
.TAG_OTHER
});
1365 tagCombo
.addSelectionListener(new SelectionListener(){
1367 public void widgetDefaultSelected(SelectionEvent e
) {}
1369 public void widgetSelected(SelectionEvent e
) {
1370 tagText
.removeModifyListener(updateListener
);
1371 switch (tagCombo
.getSelectionIndex()) {
1372 case 0: //Time Stamp
1373 tagLabel
.setText(Messages
.CustomTxtParserInputWizardPage_format
);
1374 tagLabel
.setVisible(true);
1375 tagText
.setVisible(true);
1376 tagText
.addModifyListener(updateListener
);
1379 tagLabel
.setVisible(false);
1380 tagText
.setVisible(false);
1383 tagLabel
.setText(Messages
.CustomTxtParserInputWizardPage_name
);
1384 tagLabel
.setVisible(true);
1385 tagText
.setVisible(true);
1386 tagText
.addModifyListener(updateListener
);
1389 tagLabel
.setVisible(false);
1390 tagText
.setVisible(false);
1395 tagComposite
.layout();
1400 tagLabel
= new Label(tagComposite
, SWT
.NULL
);
1401 tagLabel
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
1402 tagLabel
.setVisible(false);
1404 tagText
= new Text(tagComposite
, SWT
.BORDER
| SWT
.SINGLE
);
1405 GridData gd
= new GridData(SWT
.FILL
, SWT
.CENTER
, true, false);
1407 tagText
.setLayoutData(gd
);
1408 tagText
.setVisible(false);
1410 actionCombo
= new Combo(tagComposite
, SWT
.DROP_DOWN
| SWT
.READ_ONLY
);
1411 actionCombo
.setItems(new String
[] {Messages
.CustomTxtParserInputWizardPage_set
, Messages
.CustomTxtParserInputWizardPage_append
, Messages
.CustomTxtParserInputWizardPage_appendWith
});
1412 actionCombo
.select(0);
1413 actionCombo
.addSelectionListener(updateListener
);
1415 previewLabel
= new Label(parent
, SWT
.NULL
);
1416 previewLabel
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
1417 previewLabel
.setText(Messages
.CustomTxtParserInputWizardPage_preview
);
1419 previewText
= new Text(parent
, SWT
.BORDER
| SWT
.SINGLE
| SWT
.READ_ONLY
);
1420 gd
= new GridData(SWT
.FILL
, SWT
.CENTER
, true, false);
1422 previewText
.setLayoutData(gd
);
1423 previewText
.setText(Messages
.CustomTxtParserInputWizardPage_noMatch
);
1424 previewText
.setBackground(COLOR_WIDGET_BACKGROUND
);
1427 private void dispose() {
1428 labelComposite
.dispose();
1429 tagComposite
.dispose();
1430 previewLabel
.dispose();
1431 previewText
.dispose();
1434 private void setInputNumber(int inputNumber
) {
1435 this.inputNumber
= inputNumber
;
1436 inputLabel
.setText(Messages
.CustomTxtParserInputWizardPage_group
+ inputNumber
+ ":"); //$NON-NLS-1$
1437 labelComposite
.layout();
1441 private void validate() {
1443 definition
.definitionName
= logtypeText
.getText().trim();
1444 definition
.timeStampOutputFormat
= timestampOutputFormatText
.getText().trim();
1446 if (selectedLine
!= null) {
1447 selectedLine
.extractInputs();
1448 treeViewer
.refresh();
1451 StringBuffer errors
= new StringBuffer();
1453 if (definition
.definitionName
.length() == 0) {
1454 errors
.append("Enter a name for the new log type. "); //$NON-NLS-1$
1455 logtypeText
.setBackground(COLOR_LIGHT_RED
);
1457 logtypeText
.setBackground(COLOR_TEXT_BACKGROUND
);
1458 for (CustomTxtTraceDefinition def
: CustomTxtTraceDefinition
.loadAll()) {
1459 if (definition
.definitionName
.equals(def
.definitionName
)) {
1460 if (editDefinitionName
== null || ! editDefinitionName
.equals(definition
.definitionName
)) {
1461 errors
.append("The log type name already exists. "); //$NON-NLS-1$
1462 logtypeText
.setBackground(COLOR_LIGHT_RED
);
1469 timestampFound
= false;
1470 for (int i
= 0; i
< definition
.inputs
.size(); i
++) {
1472 InputLine inputLine
= definition
.inputs
.get(i
);
1473 String name
= Integer
.toString(i
+1);
1474 errors
.append(validateLine(inputLine
, name
));
1476 if (timestampFound
) {
1477 if (definition
.timeStampOutputFormat
.length() == 0) {
1478 errors
.append("Enter the output format for the Time Stamp field. "); //$NON-NLS-1$
1479 timestampOutputFormatText
.setBackground(COLOR_LIGHT_RED
);
1482 new SimpleDateFormat(definition
.timeStampOutputFormat
);
1483 timestampOutputFormatText
.setBackground(COLOR_TEXT_BACKGROUND
);
1484 } catch (IllegalArgumentException e
) {
1485 errors
.append("Enter a valid output format for the Time Stamp field. "); //$NON-NLS-1$
1486 timestampOutputFormatText
.setBackground(COLOR_LIGHT_RED
);
1491 timestampOutputFormatText
.setBackground(COLOR_TEXT_BACKGROUND
);
1492 // timestampPreviewText.setBackground(COLOR_WIDGET_BACKGROUND);
1493 // errors.append("Identify a Time Stamp group (Line "+name+"). ");
1494 // timestampPreviewText.setText("*no timestamp group*");
1495 // timestampPreviewText.setBackground(COLOR_LIGHT_RED);
1498 if (errors
.length() == 0) {
1499 setDescription(defaultDescription
);
1500 setPageComplete(true);
1502 setDescription(errors
.toString());
1503 setPageComplete(false);
1508 * Validate an input line.
1511 * The line to clean up
1513 * The name of the line
1514 * @return The cleaned up line
1516 public StringBuffer
validateLine(InputLine inputLine
, String name
) {
1517 StringBuffer errors
= new StringBuffer();
1519 if (selectedLine
!= null && selectedLine
.inputLine
.equals(inputLine
)) {
1520 line
= selectedLine
;
1523 Pattern
.compile(inputLine
.getRegex());
1525 line
.regexText
.setBackground(COLOR_TEXT_BACKGROUND
);
1527 } catch (PatternSyntaxException e
) {
1528 errors
.append("Enter a valid regular expression (Line "+name
+"). "); //$NON-NLS-1$ //$NON-NLS-2$
1530 line
.regexText
.setBackground(COLOR_LIGHT_RED
);
1533 if (inputLine
.getMinCount() == -1) {
1534 errors
.append("Enter a minimum value for cardinality (Line "+name
+"). "); //$NON-NLS-1$ //$NON-NLS-2$
1536 line
.cardinalityMinText
.setBackground(COLOR_LIGHT_RED
);
1540 line
.cardinalityMinText
.setBackground(COLOR_TEXT_BACKGROUND
);
1543 if (inputLine
.getMaxCount() == -1) {
1544 errors
.append("Enter a maximum value for cardinality (Line "+name
+"). "); //$NON-NLS-1$ //$NON-NLS-2$
1546 line
.cardinalityMaxText
.setBackground(COLOR_LIGHT_RED
);
1548 } else if (inputLine
.getMinCount() > inputLine
.getMaxCount()) {
1549 errors
.append("Enter correct (min <= max) values for cardinality (Line "+name
+"). "); //$NON-NLS-1$ //$NON-NLS-2$
1551 line
.cardinalityMinText
.setBackground(COLOR_LIGHT_RED
);
1554 line
.cardinalityMaxText
.setBackground(COLOR_LIGHT_RED
);
1558 line
.cardinalityMaxText
.setBackground(COLOR_TEXT_BACKGROUND
);
1561 for (int i
= 0; inputLine
.columns
!= null && i
< inputLine
.columns
.size(); i
++) {
1562 InputData inputData
= inputLine
.columns
.get(i
);
1563 InputGroup group
= null;
1565 group
= line
.inputs
.get(i
);
1567 if (inputData
.name
.equals(CustomTraceDefinition
.TAG_TIMESTAMP
)) {
1568 timestampFound
= true;
1569 if (inputData
.format
.length() == 0) {
1570 errors
.append("Enter the input format for the Time Stamp (Line "+name
+" Group "+(i
+1)+"). "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
1571 if (group
!= null) {
1572 group
.tagText
.setBackground(COLOR_LIGHT_RED
);
1576 new SimpleDateFormat(inputData
.format
);
1577 if (group
!= null) {
1578 group
.tagText
.setBackground(COLOR_TEXT_BACKGROUND
);
1580 } catch (IllegalArgumentException e
) {
1581 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$
1582 if (group
!= null) {
1583 group
.tagText
.setBackground(COLOR_LIGHT_RED
);
1587 } else if (inputData
.name
.length() == 0) {
1588 errors
.append("Enter a name for the data group (Line "+name
+" Group "+(i
+1)+"). "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
1589 if (group
!= null) {
1590 group
.tagText
.setBackground(COLOR_LIGHT_RED
);
1593 if (group
!= null) {
1594 group
.tagText
.setBackground(COLOR_TEXT_BACKGROUND
);
1598 for (int i
= 0; inputLine
.childrenInputs
!= null && i
< inputLine
.childrenInputs
.size(); i
++) {
1599 errors
.append(validateLine(inputLine
.childrenInputs
.get(i
), name
+"."+(i
+1))); //$NON-NLS-1$
1605 * Get the trace definition.
1607 * @return The trace definition
1609 public CustomTxtTraceDefinition
getDefinition() {
1614 * Get the raw text of the input.
1616 * @return The raw input text
1618 public char[] getInputText() {
1619 return inputText
.getText().toCharArray();