1 package org
.eclipse
.linuxtools
.internal
.tmf
.ui
.parsers
.wizards
;
3 import java
.io
.BufferedReader
;
4 import java
.io
.IOException
;
5 import java
.io
.InputStreamReader
;
6 import java
.text
.ParseException
;
7 import java
.text
.SimpleDateFormat
;
8 import java
.util
.ArrayList
;
9 import java
.util
.Arrays
;
10 import java
.util
.Date
;
11 import java
.util
.HashMap
;
12 import java
.util
.Iterator
;
13 import java
.util
.List
;
15 import java
.util
.Scanner
;
16 import java
.util
.regex
.Matcher
;
17 import java
.util
.regex
.Pattern
;
18 import java
.util
.regex
.PatternSyntaxException
;
20 import org
.eclipse
.core
.resources
.IFile
;
21 import org
.eclipse
.core
.runtime
.CoreException
;
22 import org
.eclipse
.jface
.viewers
.ColumnLabelProvider
;
23 import org
.eclipse
.jface
.viewers
.ISelection
;
24 import org
.eclipse
.jface
.viewers
.ISelectionChangedListener
;
25 import org
.eclipse
.jface
.viewers
.IStructuredSelection
;
26 import org
.eclipse
.jface
.viewers
.ITreeContentProvider
;
27 import org
.eclipse
.jface
.viewers
.SelectionChangedEvent
;
28 import org
.eclipse
.jface
.viewers
.StructuredSelection
;
29 import org
.eclipse
.jface
.viewers
.TreeViewer
;
30 import org
.eclipse
.jface
.viewers
.Viewer
;
31 import org
.eclipse
.jface
.wizard
.WizardPage
;
32 import org
.eclipse
.linuxtools
.internal
.tmf
.ui
.Messages
;
33 import org
.eclipse
.linuxtools
.internal
.tmf
.ui
.Activator
;
34 import org
.eclipse
.linuxtools
.internal
.tmf
.ui
.parsers
.custom
.CustomTxtTraceDefinition
;
35 import org
.eclipse
.linuxtools
.internal
.tmf
.ui
.parsers
.custom
.CustomTxtTraceDefinition
.Cardinality
;
36 import org
.eclipse
.linuxtools
.internal
.tmf
.ui
.parsers
.custom
.CustomTxtTraceDefinition
.InputData
;
37 import org
.eclipse
.linuxtools
.internal
.tmf
.ui
.parsers
.custom
.CustomTxtTraceDefinition
.InputLine
;
38 import org
.eclipse
.swt
.SWT
;
39 import org
.eclipse
.swt
.browser
.Browser
;
40 import org
.eclipse
.swt
.browser
.TitleEvent
;
41 import org
.eclipse
.swt
.browser
.TitleListener
;
42 import org
.eclipse
.swt
.custom
.SashForm
;
43 import org
.eclipse
.swt
.custom
.ScrolledComposite
;
44 import org
.eclipse
.swt
.custom
.StyleRange
;
45 import org
.eclipse
.swt
.custom
.StyledText
;
46 import org
.eclipse
.swt
.events
.ModifyEvent
;
47 import org
.eclipse
.swt
.events
.ModifyListener
;
48 import org
.eclipse
.swt
.events
.SelectionAdapter
;
49 import org
.eclipse
.swt
.events
.SelectionEvent
;
50 import org
.eclipse
.swt
.events
.SelectionListener
;
51 import org
.eclipse
.swt
.events
.VerifyEvent
;
52 import org
.eclipse
.swt
.events
.VerifyListener
;
53 import org
.eclipse
.swt
.graphics
.Color
;
54 import org
.eclipse
.swt
.graphics
.Font
;
55 import org
.eclipse
.swt
.graphics
.FontData
;
56 import org
.eclipse
.swt
.graphics
.Image
;
57 import org
.eclipse
.swt
.layout
.FillLayout
;
58 import org
.eclipse
.swt
.layout
.GridData
;
59 import org
.eclipse
.swt
.layout
.GridLayout
;
60 import org
.eclipse
.swt
.widgets
.Button
;
61 import org
.eclipse
.swt
.widgets
.Combo
;
62 import org
.eclipse
.swt
.widgets
.Composite
;
63 import org
.eclipse
.swt
.widgets
.Display
;
64 import org
.eclipse
.swt
.widgets
.Group
;
65 import org
.eclipse
.swt
.widgets
.Label
;
66 import org
.eclipse
.swt
.widgets
.Shell
;
67 import org
.eclipse
.swt
.widgets
.Text
;
69 public class CustomTxtParserInputWizardPage
extends WizardPage
{
71 private static final String DEFAULT_REGEX
= "\\s*(.*\\S)"; //$NON-NLS-1$
72 private static final String DEFAULT_TIMESTAMP_FORMAT
= "yyyy-MM-dd HH:mm:ss.SSS"; //$NON-NLS-1$
73 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$
74 private static final String PATTERN_URL
= "http://java.sun.com/javase/6/docs/api/java/util/regex/Pattern.html#sum"; //$NON-NLS-1$
75 private static final Image lineImage
= Activator
.getDefault().getImageFromPath("/icons/elcl16/line_icon.gif"); //$NON-NLS-1$
76 private static final Image addImage
= Activator
.getDefault().getImageFromPath("/icons/elcl16/add_button.gif"); //$NON-NLS-1$
77 private static final Image addNextImage
= Activator
.getDefault().getImageFromPath("/icons/elcl16/addnext_button.gif"); //$NON-NLS-1$
78 private static final Image addChildImage
= Activator
.getDefault().getImageFromPath("/icons/elcl16/addchild_button.gif"); //$NON-NLS-1$
79 private static final Image deleteImage
= Activator
.getDefault().getImageFromPath("/icons/elcl16/delete_button.gif"); //$NON-NLS-1$
80 private static final Image moveUpImage
= Activator
.getDefault().getImageFromPath("/icons/elcl16/moveup_button.gif"); //$NON-NLS-1$
81 private static final Image moveDownImage
= Activator
.getDefault().getImageFromPath("/icons/elcl16/movedown_button.gif"); //$NON-NLS-1$
82 private static final Image helpImage
= Activator
.getDefault().getImageFromPath("/icons/elcl16/help_button.gif"); //$NON-NLS-1$
83 private static final Color COLOR_BLACK
= Display
.getCurrent().getSystemColor(SWT
.COLOR_BLACK
);
84 private static final Color COLOR_LIGHT_GREEN
= new Color(Display
.getDefault(), 192, 255, 192);
85 private static final Color COLOR_GREEN
= Display
.getCurrent().getSystemColor(SWT
.COLOR_GREEN
);
86 private static final Color COLOR_LIGHT_YELLOW
= new Color(Display
.getDefault(), 255, 255, 192);
87 private static final Color COLOR_YELLOW
= Display
.getCurrent().getSystemColor(SWT
.COLOR_YELLOW
);
88 private static final Color COLOR_LIGHT_MAGENTA
= new Color(Display
.getDefault(), 255, 192, 255);
89 private static final Color COLOR_MAGENTA
= Display
.getCurrent().getSystemColor(SWT
.COLOR_MAGENTA
);
90 private static final Color COLOR_LIGHT_RED
= new Color(Display
.getDefault(), 255, 192, 192);
91 private static final Color COLOR_TEXT_BACKGROUND
= Display
.getCurrent().getSystemColor(SWT
.COLOR_WHITE
);
92 private static final Color COLOR_WIDGET_BACKGROUND
= Display
.getCurrent().getSystemColor(SWT
.COLOR_WIDGET_BACKGROUND
);
94 private ISelection selection
;
95 private CustomTxtTraceDefinition definition
;
96 private String editDefinitionName
;
97 private String defaultDescription
;
98 private Line selectedLine
;
99 private Composite container
;
100 private Text logtypeText
;
101 private Text timestampOutputFormatText
;
102 private Text timestampPreviewText
;
103 private ScrolledComposite treeScrolledComposite
;
104 private ScrolledComposite lineScrolledComposite
;
105 private TreeViewer treeViewer
;
106 private Composite treeContainer
;
107 private Composite lineContainer
;
108 private StyledText inputText
;
109 private Font fixedFont
;
110 private UpdateListener updateListener
;
111 private Browser helpBrowser
;
113 // variables used recursively through line traversal
114 private String timeStampFormat
;
115 private boolean timestampFound
;
117 protected CustomTxtParserInputWizardPage(ISelection selection
, CustomTxtTraceDefinition definition
) {
118 super("CustomParserWizardPage"); //$NON-NLS-1$
119 if (definition
== null) {
120 setTitle(Messages
.CustomTxtParserInputWizardPage_windowTitleNew
);
121 defaultDescription
= Messages
.CustomTxtParserInputWizardPage_descriptionNew
;
123 setTitle(Messages
.CustomTxtParserInputWizardPage_windowTitleEdit
);
124 defaultDescription
= Messages
.CustomTxtParserInputWizardPage_desccriptionEdit
;
126 setDescription(defaultDescription
);
127 this.selection
= selection
;
128 this.definition
= definition
;
129 if (definition
!= null) {
130 this.editDefinitionName
= definition
.definitionName
;
135 public void createControl(Composite parent
) {
136 container
= new Composite(parent
, SWT
.NULL
);
137 container
.setLayout(new GridLayout());
139 updateListener
= new UpdateListener();
141 Composite headerComposite
= new Composite(container
, SWT
.FILL
);
142 GridLayout headerLayout
= new GridLayout(5, false);
143 headerLayout
.marginHeight
= 0;
144 headerLayout
.marginWidth
= 0;
145 headerComposite
.setLayout(headerLayout
);
146 headerComposite
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
148 Label logtypeLabel
= new Label(headerComposite
, SWT
.NULL
);
149 logtypeLabel
.setText(Messages
.CustomTxtParserInputWizardPage_logType
);
151 logtypeText
= new Text(headerComposite
, SWT
.BORDER
| SWT
.SINGLE
);
152 logtypeText
.setLayoutData(new GridData(120, SWT
.DEFAULT
));
154 Label timestampFormatLabel
= new Label(headerComposite
, SWT
.NULL
);
155 timestampFormatLabel
.setText(Messages
.CustomTxtParserInputWizardPage_timestampFormat
);
157 timestampOutputFormatText
= new Text(headerComposite
, SWT
.BORDER
| SWT
.SINGLE
);
158 timestampOutputFormatText
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
159 timestampOutputFormatText
.setText(DEFAULT_TIMESTAMP_FORMAT
);
161 Button dateFormatHelpButton
= new Button(headerComposite
, SWT
.PUSH
);
162 dateFormatHelpButton
.setImage(helpImage
);
163 dateFormatHelpButton
.setToolTipText(Messages
.CustomTxtParserInputWizardPage_dateFormatHelp
);
164 dateFormatHelpButton
.addSelectionListener(new SelectionAdapter() {
166 public void widgetSelected(SelectionEvent e
) {
167 openHelpShell(SIMPLE_DATE_FORMAT_URL
);
171 Label timestampPreviewLabel
= new Label(headerComposite
, SWT
.NULL
);
172 timestampPreviewLabel
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false, 3, 1));
173 timestampPreviewLabel
.setText(Messages
.CustomTxtParserInputWizardPage_preview
);
175 timestampPreviewText
= new Text(headerComposite
, SWT
.BORDER
| SWT
.SINGLE
| SWT
.READ_ONLY
);
176 timestampPreviewText
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false, 2, 1));
177 timestampPreviewText
.setText(Messages
.CustomTxtParserInputWizardPage_noMatchingTimestamp
);
179 Composite buttonBar
= new Composite(container
, SWT
.NONE
);
180 GridLayout buttonBarLayout
= new GridLayout(5, false);
181 buttonBarLayout
.marginHeight
= 0;
182 buttonBarLayout
.marginWidth
= 0;
183 buttonBar
.setLayout(buttonBarLayout
);
185 Button removeButton
= new Button(buttonBar
, SWT
.PUSH
);
186 removeButton
.setImage(deleteImage
);
187 removeButton
.setToolTipText(Messages
.CustomTxtParserInputWizardPage_removeLine
);
188 removeButton
.addSelectionListener(new SelectionAdapter() {
190 public void widgetSelected(SelectionEvent e
) {
191 if (treeViewer
.getSelection().isEmpty() || selectedLine
== null) return;
193 InputLine inputLine
= (InputLine
) ((IStructuredSelection
) treeViewer
.getSelection()).getFirstElement();
194 if (inputLine
.parentInput
== null) {
195 definition
.inputs
.remove(inputLine
);
197 inputLine
.parentInput
.childrenInputs
.remove(inputLine
);
199 treeViewer
.refresh();
204 Button addNextButton
= new Button(buttonBar
, SWT
.PUSH
);
205 addNextButton
.setImage(addNextImage
);
206 addNextButton
.setToolTipText(Messages
.CustomTxtParserInputWizardPage_addNextLine
);
207 addNextButton
.addSelectionListener(new SelectionAdapter() {
209 public void widgetSelected(SelectionEvent e
) {
210 InputLine inputLine
= new InputLine(Cardinality
.ZERO_OR_MORE
, "", null); //$NON-NLS-1$
211 if (((List
<?
>) treeViewer
.getInput()).size() == 0) {
212 definition
.inputs
.add(inputLine
);
213 } else if (treeViewer
.getSelection().isEmpty()) {
216 InputLine previousInputLine
= (InputLine
) ((IStructuredSelection
) treeViewer
.getSelection()).getFirstElement();
217 if (previousInputLine
.parentInput
== null) {
218 for (int i
= 0; i
< definition
.inputs
.size(); i
++) {
219 if (definition
.inputs
.get(i
).equals(previousInputLine
)) {
220 definition
.inputs
.add(i
+ 1, inputLine
);
224 previousInputLine
.addNext(inputLine
);
227 treeViewer
.refresh();
228 treeViewer
.setSelection(new StructuredSelection(inputLine
), true);
231 Button addChildButton
= new Button(buttonBar
, SWT
.PUSH
);
232 addChildButton
.setImage(addChildImage
);
233 addChildButton
.setToolTipText(Messages
.CustomTxtParserInputWizardPage_addChildLine
);
234 addChildButton
.addSelectionListener(new SelectionAdapter() {
236 public void widgetSelected(SelectionEvent e
) {
237 InputLine inputLine
= new InputLine(Cardinality
.ZERO_OR_MORE
, "", null); //$NON-NLS-1$
238 if (((List
<?
>) treeViewer
.getInput()).size() == 0) {
239 definition
.inputs
.add(inputLine
);
240 } else if (treeViewer
.getSelection().isEmpty()) {
243 InputLine parentInputLine
= (InputLine
) ((IStructuredSelection
) treeViewer
.getSelection()).getFirstElement();
244 parentInputLine
.addChild(inputLine
);
246 treeViewer
.refresh();
247 treeViewer
.setSelection(new StructuredSelection(inputLine
), true);
250 Button moveUpButton
= new Button(buttonBar
, SWT
.PUSH
);
251 moveUpButton
.setImage(moveUpImage
);
252 moveUpButton
.setToolTipText(Messages
.CustomTxtParserInputWizardPage_moveUp
);
253 moveUpButton
.addSelectionListener(new SelectionAdapter() {
255 public void widgetSelected(SelectionEvent e
) {
256 if (treeViewer
.getSelection().isEmpty()) return;
257 InputLine inputLine
= (InputLine
) ((IStructuredSelection
) treeViewer
.getSelection()).getFirstElement();
258 if (inputLine
.parentInput
== null) {
259 for (int i
= 1; i
< definition
.inputs
.size(); i
++) {
260 if (definition
.inputs
.get(i
).equals(inputLine
)) {
261 definition
.inputs
.add(i
- 1 , definition
.inputs
.remove(i
));
268 treeViewer
.refresh();
273 Button moveDownButton
= new Button(buttonBar
, SWT
.PUSH
);
274 moveDownButton
.setImage(moveDownImage
);
275 moveDownButton
.setToolTipText(Messages
.CustomTxtParserInputWizardPage_moveDown
);
276 moveDownButton
.addSelectionListener(new SelectionAdapter() {
278 public void widgetSelected(SelectionEvent e
) {
279 if (treeViewer
.getSelection().isEmpty()) return;
280 InputLine inputLine
= (InputLine
) ((IStructuredSelection
) treeViewer
.getSelection()).getFirstElement();
281 if (inputLine
.parentInput
== null) {
282 for (int i
= 0; i
< definition
.inputs
.size() - 1; i
++) {
283 if (definition
.inputs
.get(i
).equals(inputLine
)) {
284 definition
.inputs
.add(i
+ 1 , definition
.inputs
.remove(i
));
289 inputLine
.moveDown();
291 treeViewer
.refresh();
297 SashForm vSash
= new SashForm(container
, SWT
.VERTICAL
);
298 vSash
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
299 vSash
.setBackground(vSash
.getDisplay().getSystemColor(SWT
.COLOR_GRAY
));
301 SashForm hSash
= new SashForm(vSash
, SWT
.HORIZONTAL
);
302 hSash
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
304 treeScrolledComposite
= new ScrolledComposite(hSash
, SWT
.V_SCROLL
| SWT
.H_SCROLL
);
305 GridData gd
= new GridData(SWT
.FILL
, SWT
.FILL
, true, true);
308 treeScrolledComposite
.setLayoutData(gd
);
309 treeContainer
= new Composite(treeScrolledComposite
, SWT
.NONE
);
310 treeContainer
.setLayout(new FillLayout());
311 treeScrolledComposite
.setContent(treeContainer
);
312 treeScrolledComposite
.setExpandHorizontal(true);
313 treeScrolledComposite
.setExpandVertical(true);
315 treeViewer
= new TreeViewer(treeContainer
, SWT
.SINGLE
| SWT
.BORDER
);
316 treeViewer
.setContentProvider(new InputLineTreeNodeContentProvider());
317 treeViewer
.setLabelProvider(new InputLineTreeLabelProvider());
318 treeViewer
.addSelectionChangedListener(new InputLineTreeSelectionChangedListener());
319 treeContainer
.layout();
321 treeScrolledComposite
.setMinSize(treeContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).x
, treeContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).y
);
323 lineScrolledComposite
= new ScrolledComposite(hSash
, SWT
.V_SCROLL
);
324 lineScrolledComposite
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
325 lineContainer
= new Composite(lineScrolledComposite
, SWT
.NONE
);
326 GridLayout linesLayout
= new GridLayout();
327 linesLayout
.marginHeight
= 1;
328 linesLayout
.marginWidth
= 0;
329 lineContainer
.setLayout(linesLayout
);
330 lineScrolledComposite
.setContent(lineContainer
);
331 lineScrolledComposite
.setExpandHorizontal(true);
332 lineScrolledComposite
.setExpandVertical(true);
334 if (definition
== null) {
335 definition
= new CustomTxtTraceDefinition();
336 definition
.inputs
.add(new InputLine(Cardinality
.ZERO_OR_MORE
, DEFAULT_REGEX
,
337 Arrays
.asList(new InputData(CustomTxtTraceDefinition
.TAG_MESSAGE
, CustomTxtTraceDefinition
.ACTION_SET
))));
339 loadDefinition(definition
);
340 treeViewer
.expandAll();
341 lineContainer
.layout();
343 logtypeText
.addModifyListener(updateListener
);
344 timestampOutputFormatText
.addModifyListener(updateListener
);
346 lineScrolledComposite
.setMinSize(lineContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).x
, lineContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).y
-1);
348 hSash
.setWeights(new int[] {1, 2});
350 Composite sashBottom
= new Composite(vSash
, SWT
.NONE
);
351 GridLayout sashBottomLayout
= new GridLayout(3, false);
352 sashBottomLayout
.marginHeight
= 0;
353 sashBottomLayout
.marginWidth
= 0;
354 sashBottom
.setLayout(sashBottomLayout
);
356 Label previewLabel
= new Label(sashBottom
, SWT
.NULL
);
357 previewLabel
.setText(Messages
.CustomTxtParserInputWizardPage_previewInput
);
358 previewLabel
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
360 Button highlightAllButton
= new Button(sashBottom
, SWT
.PUSH
);
361 highlightAllButton
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
362 highlightAllButton
.setText(Messages
.CustomTxtParserInputWizardPage_highlightAll
);
363 highlightAllButton
.addSelectionListener(new SelectionAdapter() {
365 public void widgetSelected(SelectionEvent e
) {
366 updatePreviews(true);
370 Button legendButton
= new Button(sashBottom
, SWT
.PUSH
);
371 legendButton
.setImage(helpImage
);
372 legendButton
.setToolTipText(Messages
.CustomTxtParserInputWizardPage_previewLegend
);
373 legendButton
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
374 legendButton
.addSelectionListener(new SelectionAdapter() {
376 public void widgetSelected(SelectionEvent e
) {
381 inputText
= new StyledText(sashBottom
, SWT
.MULTI
| SWT
.V_SCROLL
| SWT
.H_SCROLL
);
382 if (fixedFont
== null) {
383 if (System
.getProperty("os.name").contains("Windows")) { //$NON-NLS-1$ //$NON-NLS-2$
384 fixedFont
= new Font(Display
.getCurrent(), new FontData("Courier New", 10, SWT
.NORMAL
)); //$NON-NLS-1$
386 fixedFont
= new Font(Display
.getCurrent(), new FontData("Monospace", 10, SWT
.NORMAL
)); //$NON-NLS-1$
389 inputText
.setFont(fixedFont
);
390 gd
= new GridData(SWT
.FILL
, SWT
.FILL
, true, true, 3, 1);
391 gd
.heightHint
= inputText
.computeSize(SWT
.DEFAULT
, inputText
.getLineHeight() * 4).y
;
393 inputText
.setLayoutData(gd
);
394 inputText
.setText(getSelectionText());
395 inputText
.addModifyListener(updateListener
);
397 vSash
.setWeights(new int[] {hSash
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).y
, sashBottom
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).y
});
399 setControl(container
);
405 private static class InputLineTreeNodeContentProvider
implements ITreeContentProvider
{
408 public Object
[] getElements(Object inputElement
) {
409 return ((List
<?
>) inputElement
).toArray();
413 public Object
[] getChildren(Object parentElement
) {
414 InputLine inputLine
= (InputLine
) parentElement
;
415 if (inputLine
.childrenInputs
== null) return new InputLine
[0];
416 return inputLine
.childrenInputs
.toArray();
420 public boolean hasChildren(Object element
) {
421 InputLine inputLine
= (InputLine
) element
;
422 return (inputLine
.childrenInputs
!= null && inputLine
.childrenInputs
.size() > 0);
426 public void dispose() {
430 public void inputChanged(Viewer viewer
, Object oldInput
, Object newInput
) {
434 public Object
getParent(Object element
) {
435 InputLine inputLine
= (InputLine
) element
;
436 return inputLine
.parentInput
;
440 private class InputLineTreeLabelProvider
extends ColumnLabelProvider
{
443 public Image
getImage(Object element
) {
448 public String
getText(Object element
) {
449 InputLine inputLine
= (InputLine
) element
;
450 if (inputLine
.parentInput
== null) {
451 return "Root Line " + getName(inputLine
) + " " + inputLine
.cardinality
.toString() + " : " + inputLine
.getRegex(); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
453 return "Line " + getName(inputLine
) + " " + inputLine
.cardinality
.toString() + " : " + inputLine
.getRegex(); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
458 private class InputLineTreeSelectionChangedListener
implements ISelectionChangedListener
{
460 public void selectionChanged(SelectionChangedEvent event
) {
461 if (selectedLine
!= null) {
462 selectedLine
.dispose();
464 if (!(event
.getSelection().isEmpty()) && event
.getSelection() instanceof IStructuredSelection
) {
465 IStructuredSelection selection
= (IStructuredSelection
) event
.getSelection();
466 InputLine inputLine
= (InputLine
) selection
.getFirstElement();
467 selectedLine
= new Line(lineContainer
, getName(inputLine
), inputLine
);
468 lineContainer
.layout();
469 lineScrolledComposite
.setMinSize(lineContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).x
, lineContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).y
-1);
478 * @see org.eclipse.jface.dialogs.DialogPage#dispose()
481 public void dispose() {
482 if (fixedFont
!= null) {
489 private void loadDefinition(CustomTxtTraceDefinition def
) {
490 logtypeText
.setText(def
.definitionName
);
491 timestampOutputFormatText
.setText(def
.timeStampOutputFormat
);
492 treeViewer
.setInput(def
.inputs
);
493 if (def
.inputs
.size() > 0) {
494 InputLine inputLine
= def
.inputs
.get(0);
495 treeViewer
.setSelection(new StructuredSelection(inputLine
));
499 private String
getName(InputLine inputLine
) {
500 if (inputLine
.parentInput
== null) {
501 return Integer
.toString(definition
.inputs
.indexOf(inputLine
)+1);
503 return getName(inputLine
.parentInput
) + "." + Integer
.toString(inputLine
.parentInput
.childrenInputs
.indexOf(inputLine
)+1); //$NON-NLS-1$
506 public List
<String
> getInputNames() {
507 List
<String
> inputs
= new ArrayList
<String
>();
508 for (InputLine inputLine
: definition
.inputs
) {
509 for (String inputName
: getInputNames(inputLine
)) {
510 if (!inputs
.contains(inputName
)) {
511 inputs
.add(inputName
);
518 public List
<String
> getInputNames(InputLine inputLine
) {
519 List
<String
> inputs
= new ArrayList
<String
>();
520 if (inputLine
.columns
!= null) {
521 for (InputData inputData
: inputLine
.columns
) {
522 String inputName
= inputData
.name
;
523 if (!inputs
.contains(inputName
)) {
524 inputs
.add(inputName
);
528 if (inputLine
.childrenInputs
!= null) {
529 for (InputLine childInputLine
: inputLine
.childrenInputs
) {
530 for (String inputName
: getInputNames(childInputLine
)) {
531 if (!inputs
.contains(inputName
)) {
532 inputs
.add(inputName
);
540 private void removeLine() {
541 selectedLine
.dispose();
543 lineContainer
.layout();
544 lineScrolledComposite
.setMinSize(lineContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).x
, lineContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).y
-1);
548 private String
getSelectionText() {
549 if (this.selection
instanceof IStructuredSelection
) {
550 Object selection
= ((IStructuredSelection
)this.selection
).getFirstElement();
551 if (selection
instanceof IFile
) {
552 IFile file
= (IFile
)selection
;
553 BufferedReader reader
= null;
555 reader
= new BufferedReader(new InputStreamReader(file
.getContents()));
556 StringBuilder sb
= new StringBuilder();
558 while ((line
= reader
.readLine()) != null) {
559 sb
.append(line
+ "\n"); //$NON-NLS-1$
561 return sb
.toString();
562 } catch (CoreException e
) {
563 return ""; //$NON-NLS-1$
564 } catch (IOException e
) {
565 return ""; //$NON-NLS-1$
567 if (reader
!= null) {
570 } catch (IOException e
) {
576 return ""; //$NON-NLS-1$
579 private void updatePreviews() {
580 updatePreviews(false);
583 private void updatePreviews(boolean updateAll
) {
584 if (inputText
== null) {
585 // early update during construction
588 inputText
.setStyleRanges(new StyleRange
[] {});
590 Scanner scanner
= new Scanner(inputText
.getText());
591 scanner
.useDelimiter("\n"); //$NON-NLS-1$
593 String skip
; // skip starting delimiters
594 if ((skip
= scanner
.findWithinHorizon("\\A\n+", 0)) != null) { //$NON-NLS-1$
595 rawPos
+= skip
.length();
598 timeStampFormat
= null;
599 if (selectedLine
!= null) {
600 for (InputGroup input
: selectedLine
.inputs
) {
601 input
.previewText
.setText(Messages
.CustomTxtParserInputWizardPage_noMathcingLine
);
605 Map
<String
, String
> data
= new HashMap
<String
, String
>();
606 int rootLineMatches
= 0;
607 String firstEntryTimeStamp
= null;
608 String firstEntryTimeStampInputFormat
= null;
611 while (log
!= null || scanner
.hasNext()) {
612 if (rootLineMatches
> 0 && !updateAll
) {
616 log
= scanner
.next();
618 int length
= log
.length();
619 for (InputLine rootInputLine
: definition
.inputs
) {
622 pattern
= rootInputLine
.getPattern();
623 } catch (PatternSyntaxException e
) {
626 Matcher matcher
= pattern
.matcher(log
);
627 if (matcher
.find()) {
629 inputText
.setStyleRange(new StyleRange(rawPos
, length
,
630 COLOR_BLACK
, COLOR_YELLOW
, SWT
.ITALIC
));
631 data
= new HashMap
<String
, String
>();
632 timeStampFormat
= null;
633 updatePreviewLine(rootInputLine
, matcher
, data
, rawPos
, rootLineMatches
);
634 if (rootLineMatches
== 1) {
635 firstEntryTimeStamp
= data
.get(CustomTxtTraceDefinition
.TAG_TIMESTAMP
);
636 firstEntryTimeStampInputFormat
= timeStampFormat
;
638 HashMap
<InputLine
, Integer
> countMap
= new HashMap
<InputLine
, Integer
>();
639 InputLine currentInput
= null;
640 if (rootInputLine
.childrenInputs
!= null && rootInputLine
.childrenInputs
.size() > 0) {
641 currentInput
= rootInputLine
.childrenInputs
.get(0);
642 countMap
.put(currentInput
, 0);
644 rawPos
+= length
+ 1; // +1 for \n
645 while (scanner
.hasNext()) {
646 log
= scanner
.next();
647 length
= log
.length();
648 boolean processed
= false;
649 if (currentInput
== null) {
650 for (InputLine input
: definition
.inputs
) {
651 matcher
= input
.getPattern().matcher(log
);
652 if (matcher
.find()) {
657 if (countMap
.get(currentInput
) >= currentInput
.getMinCount()) {
658 List
<InputLine
> nextInputs
= currentInput
.getNextInputs(countMap
);
659 if (nextInputs
.size() == 0 || nextInputs
.get(nextInputs
.size() - 1).getMinCount() == 0) {
660 for (InputLine input
: definition
.inputs
) {
661 matcher
= input
.getPattern().matcher(log
);
662 if (matcher
.find()) {
667 for (InputLine input
: nextInputs
) {
668 matcher
= input
.getPattern().matcher(log
);
669 if (matcher
.find()) {
670 inputText
.setStyleRange(new StyleRange(rawPos
, length
,
671 COLOR_BLACK
, COLOR_LIGHT_YELLOW
, SWT
.ITALIC
));
672 currentInput
= input
;
673 updatePreviewLine(currentInput
, matcher
, data
, rawPos
, rootLineMatches
);
674 if (countMap
.get(currentInput
) == null) {
675 countMap
.put(currentInput
, 1);
677 countMap
.put(currentInput
, countMap
.get(currentInput
) + 1);
679 Iterator
<InputLine
> iter
= countMap
.keySet().iterator();
680 while (iter
.hasNext()) {
681 InputLine inputLine
= iter
.next();
682 if (inputLine
.level
> currentInput
.level
) {
686 if (currentInput
.childrenInputs
!= null && currentInput
.childrenInputs
.size() > 0) {
687 currentInput
= currentInput
.childrenInputs
.get(0);
688 countMap
.put(currentInput
, 0);
690 if (countMap
.get(currentInput
) >= currentInput
.getMaxCount()) {
691 if (currentInput
.getNextInputs(countMap
).size() > 0) {
692 currentInput
= currentInput
.getNextInputs(countMap
).get(0);
693 if (countMap
.get(currentInput
) == null) {
694 countMap
.put(currentInput
, 0);
696 iter
= countMap
.keySet().iterator();
697 while (iter
.hasNext()) {
698 InputLine inputLine
= iter
.next();
699 if (inputLine
.level
> currentInput
.level
) {
714 matcher
= currentInput
.getPattern().matcher(log
);
715 if (matcher
.find()) {
716 inputText
.setStyleRange(new StyleRange(rawPos
, length
,
717 COLOR_BLACK
, COLOR_LIGHT_YELLOW
, SWT
.ITALIC
));
718 updatePreviewLine(currentInput
, matcher
, data
, rawPos
, rootLineMatches
);
719 countMap
.put(currentInput
, countMap
.get(currentInput
) + 1);
720 if (currentInput
.childrenInputs
!= null && currentInput
.childrenInputs
.size() > 0) {
721 currentInput
= currentInput
.childrenInputs
.get(0);
722 countMap
.put(currentInput
, 0);
724 if (countMap
.get(currentInput
) >= currentInput
.getMaxCount()) {
725 if (currentInput
.getNextInputs(countMap
).size() > 0) {
726 currentInput
= currentInput
.getNextInputs(countMap
).get(0);
727 if (countMap
.get(currentInput
) == null) {
728 countMap
.put(currentInput
, 0);
730 Iterator
<InputLine
> iter
= countMap
.keySet().iterator();
731 while (iter
.hasNext()) {
732 InputLine inputLine
= iter
.next();
733 if (inputLine
.level
> currentInput
.level
) {
745 rawPos
+= length
+ 1; // +1 for \n
751 rawPos
+= length
+ 1; // +1 for \n
755 if (rootLineMatches
== 1) {
756 firstEntryTimeStamp
= data
.get(CustomTxtTraceDefinition
.TAG_TIMESTAMP
);
757 firstEntryTimeStampInputFormat
= timeStampFormat
;
759 if (firstEntryTimeStamp
== null) {
760 timestampPreviewText
.setText(Messages
.CustomTxtParserInputWizardPage_noTimestampGroup
);
761 if (selectedLine
!= null) {
762 for (InputGroup group
: selectedLine
.inputs
) {
763 if (group
.tagCombo
.getText().equals(CustomTxtTraceDefinition
.TAG_TIMESTAMP
)) {
764 timestampPreviewText
.setText(Messages
.CustomTxtParserInputWizardPage_noMatchingTimestamp
);
771 SimpleDateFormat dateFormat
= new SimpleDateFormat(firstEntryTimeStampInputFormat
);
772 Date date
= dateFormat
.parse(firstEntryTimeStamp
);
773 dateFormat
= new SimpleDateFormat(timestampOutputFormatText
.getText().trim());
774 timestampPreviewText
.setText(dateFormat
.format(date
));
775 } catch (ParseException e
) {
776 timestampPreviewText
.setText("*parse exception* [" + firstEntryTimeStamp
+ "] <> [" + firstEntryTimeStampInputFormat
+ "]"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
777 } catch (IllegalArgumentException e
) {
778 timestampPreviewText
.setText("*parse exception* [Illegal Argument]"); //$NON-NLS-1$
784 private void updatePreviewLine(InputLine line
, Matcher matcher
, Map
<String
, String
> data
, int rawPos
, int rootLineMatches
) {
785 for (int i
= 0; i
< line
.columns
.size(); i
++) {
786 InputData input
= line
.columns
.get(i
);
787 if (i
< matcher
.groupCount() && matcher
.group(i
+1) != null) {
788 if (line
.parentInput
== null) {
789 inputText
.setStyleRange(new StyleRange(rawPos
+ matcher
.start(i
+1), matcher
.end(i
+1) - matcher
.start(i
+1),
790 COLOR_BLACK
, COLOR_GREEN
, SWT
.BOLD
));
792 inputText
.setStyleRange(new StyleRange(rawPos
+ matcher
.start(i
+1), matcher
.end(i
+1) - matcher
.start(i
+1),
793 COLOR_BLACK
, COLOR_LIGHT_GREEN
, SWT
.BOLD
));
795 String value
= matcher
.group(i
+1).trim();
796 if (selectedLine
!= null && selectedLine
.inputLine
.equals(line
) && rootLineMatches
== 1) {
797 if (selectedLine
.inputs
.get(i
).previewText
.getText().equals(Messages
.CustomTxtParserInputWizardPage_noMatchingLine
)) {
798 selectedLine
.inputs
.get(i
).previewText
.setText(value
);
801 if (value
.length() == 0) {
804 if (input
.action
== CustomTxtTraceDefinition
.ACTION_SET
) {
805 data
.put(input
.name
, value
);
806 if (input
.name
.equals(CustomTxtTraceDefinition
.TAG_TIMESTAMP
)) {
807 timeStampFormat
= input
.format
;
809 } else if (input
.action
== CustomTxtTraceDefinition
.ACTION_APPEND
) {
810 String s
= data
.get(input
.name
);
812 data
.put(input
.name
, s
+ value
);
814 data
.put(input
.name
, value
);
816 if (input
.name
.equals(CustomTxtTraceDefinition
.TAG_TIMESTAMP
)) {
817 if (timeStampFormat
!= null) {
818 timeStampFormat
+= input
.format
;
820 timeStampFormat
= input
.format
;
823 } else if (input
.action
== CustomTxtTraceDefinition
.ACTION_APPEND_WITH_SEPARATOR
) {
824 String s
= data
.get(input
.name
);
826 data
.put(input
.name
, s
+ " | " + value
); //$NON-NLS-1$
828 data
.put(input
.name
, value
);
830 if (input
.name
.equals(CustomTxtTraceDefinition
.TAG_TIMESTAMP
)) {
831 if (timeStampFormat
!= null) {
832 timeStampFormat
+= " | " + input
.format
; //$NON-NLS-1$
834 timeStampFormat
= input
.format
;
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(Messages
.CustomTxtParserInputWizardPage_noMatchingGroup
);
846 // highlight the matching groups that have no corresponponding input
847 for (int i
= line
.columns
.size(); i
< matcher
.groupCount(); i
++) {
848 if (matcher
.group(i
+1) != null) {
849 if (line
.parentInput
== null) {
850 inputText
.setStyleRange(new StyleRange(rawPos
+ matcher
.start(i
+1), matcher
.end(i
+1) - matcher
.start(i
+1),
851 COLOR_BLACK
, COLOR_MAGENTA
));
853 inputText
.setStyleRange(new StyleRange(rawPos
+ matcher
.start(i
+1), matcher
.end(i
+1) - matcher
.start(i
+1),
854 COLOR_BLACK
, COLOR_LIGHT_MAGENTA
));
860 private void openHelpShell(String url
) {
861 if (helpBrowser
!= null && !helpBrowser
.isDisposed()) {
862 helpBrowser
.getShell().setActive();
863 if (!helpBrowser
.getUrl().equals(url
)) {
864 helpBrowser
.setUrl(url
);
868 final Shell helpShell
= new Shell(getShell(), SWT
.SHELL_TRIM
);
869 helpShell
.setLayout(new FillLayout());
870 helpBrowser
= new Browser(helpShell
, SWT
.NONE
);
871 helpBrowser
.addTitleListener(new TitleListener() {
873 public void changed(TitleEvent event
) {
874 helpShell
.setText(event
.title
);
877 helpBrowser
.setBounds(0,0,600,400);
880 helpBrowser
.setUrl(url
);
883 private void openLegend() {
884 final String CG
= Messages
.CustomTxtParserInputWizardPage_capturedGroup
;
885 final String UCG
= Messages
.CustomTxtParserInputWizardPage_unidentifiedCaptureGroup
;
886 final String UT
= Messages
.CustomTxtParserInputWizardPage_uncapturedText
;
888 String line1
= Messages
.CustomTxtParserInputWizardPage_nonMatchingLine
;
889 int line2start
= line1start
+ line1
.length();
890 String line2
= Messages
.CustomTxtParserInputWizardPage_matchingLineRoot
+ CG
+ " " + UCG
+ " " + UT
+ " \n"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
891 int line3start
= line2start
+ line2
.length();
892 String line3
= Messages
.CustomTxtParserInputWizardPage_matchingOtherLine
+ CG
+ " " + UCG
+ " " + UT
+ " \n"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
893 int line4start
= line3start
+ line3
.length();
894 String line4
= Messages
.CustomTxtParserInputWizardPage_matchingOtherLine
+ CG
+ " " + UCG
+ " " + UT
+ " \n"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
895 int line5start
= line4start
+ line4
.length();
896 String line5
= Messages
.CustomTxtParserInputWizardPage_nonMatchingLine
;
897 int line6start
= line5start
+ line5
.length();
898 String line6
= Messages
.CustomTxtParserInputWizardPage_matchingRootLine
+ CG
+ " " + UCG
+ " " + UT
+ " \n"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
900 final Shell legendShell
= new Shell(getShell(), SWT
.DIALOG_TRIM
);
901 legendShell
.setLayout(new FillLayout());
902 StyledText legendText
= new StyledText(legendShell
, SWT
.MULTI
);
903 legendText
.setFont(fixedFont
);
904 legendText
.setText(line1
+ line2
+ line3
+ line4
+ line5
+ line6
);
905 legendText
.setStyleRange(new StyleRange(line2start
, line2
.length(), COLOR_BLACK
, COLOR_YELLOW
, SWT
.ITALIC
));
906 legendText
.setStyleRange(new StyleRange(line3start
, line3
.length(), COLOR_BLACK
, COLOR_LIGHT_YELLOW
, SWT
.ITALIC
));
907 legendText
.setStyleRange(new StyleRange(line4start
, line4
.length(), COLOR_BLACK
, COLOR_LIGHT_YELLOW
, SWT
.ITALIC
));
908 legendText
.setStyleRange(new StyleRange(line6start
, line6
.length(), COLOR_BLACK
, COLOR_YELLOW
, SWT
.ITALIC
));
909 legendText
.setStyleRange(new StyleRange(line2start
+ line2
.indexOf(CG
), CG
.length(), COLOR_BLACK
, COLOR_GREEN
, SWT
.BOLD
));
910 legendText
.setStyleRange(new StyleRange(line2start
+ line2
.indexOf(UCG
), UCG
.length(), COLOR_BLACK
, COLOR_MAGENTA
));
911 legendText
.setStyleRange(new StyleRange(line3start
+ line3
.indexOf(CG
), CG
.length(), COLOR_BLACK
, COLOR_LIGHT_GREEN
, SWT
.BOLD
));
912 legendText
.setStyleRange(new StyleRange(line3start
+ line3
.indexOf(UCG
), UCG
.length(), COLOR_BLACK
, COLOR_LIGHT_MAGENTA
));
913 legendText
.setStyleRange(new StyleRange(line4start
+ line4
.indexOf(CG
), CG
.length(), COLOR_BLACK
, COLOR_LIGHT_GREEN
, SWT
.BOLD
));
914 legendText
.setStyleRange(new StyleRange(line4start
+ line4
.indexOf(UCG
), UCG
.length(), COLOR_BLACK
, COLOR_LIGHT_MAGENTA
));
915 legendText
.setStyleRange(new StyleRange(line6start
+ line6
.indexOf(CG
), CG
.length(), COLOR_BLACK
, COLOR_GREEN
, SWT
.BOLD
));
916 legendText
.setStyleRange(new StyleRange(line6start
+ line6
.indexOf(UCG
), UCG
.length(), COLOR_BLACK
, COLOR_MAGENTA
));
917 legendShell
.setText(Messages
.CustomTxtParserInputWizardPage_previewLegend
);
922 private class UpdateListener
implements ModifyListener
, SelectionListener
{
925 public void modifyText(ModifyEvent e
) {
931 public void widgetDefaultSelected(SelectionEvent e
) {
937 public void widgetSelected(SelectionEvent e
) {
945 private static final String INFINITY_STRING
= "\u221E"; //$NON-NLS-1$
948 Composite labelComposite
;
950 Composite cardinalityContainer
;
951 Combo cardinalityCombo
;
952 Label cardinalityMinLabel
;
953 Text cardinalityMinText
;
954 Label cardinalityMaxLabel
;
955 Text cardinalityMaxText
;
956 Button infiniteButton
;
957 List
<InputGroup
> inputs
= new ArrayList
<InputGroup
>();
958 Button addGroupButton
;
961 public Line(Composite parent
, String name
, InputLine inputLine
) {
962 this.inputLine
= inputLine
;
964 group
= new Group(parent
, SWT
.NONE
);
966 group
.setLayout(new GridLayout(2, false));
967 group
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
969 labelComposite
= new Composite(group
, SWT
.FILL
);
970 GridLayout labelLayout
= new GridLayout(1, false);
971 labelLayout
.marginWidth
= 0;
972 labelLayout
.marginHeight
= 0;
973 labelComposite
.setLayout(labelLayout
);
974 labelComposite
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
976 Label label
= new Label(labelComposite
, SWT
.NULL
);
977 label
.setText(Messages
.CustomTxtParserInputWizardPage_regularExpression
);
979 Composite regexContainer
= new Composite(group
, SWT
.NONE
);
980 GridLayout regexLayout
= new GridLayout(2, false);
981 regexLayout
.marginHeight
= 0;
982 regexLayout
.marginWidth
= 0;
983 regexContainer
.setLayout(regexLayout
);
984 regexContainer
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
986 regexText
= new Text(regexContainer
, SWT
.BORDER
| SWT
.SINGLE
);
987 GridData gd
= new GridData(SWT
.FILL
, SWT
.CENTER
, true, false);
989 regexText
.setLayoutData(gd
);
990 regexText
.setText(inputLine
.getRegex());
991 regexText
.addModifyListener(updateListener
);
993 Button regexHelpButton
= new Button(regexContainer
, SWT
.PUSH
);
994 regexHelpButton
.setImage(helpImage
);
995 regexHelpButton
.setToolTipText(Messages
.CustomTxtParserInputWizardPage_regularExpressionHelp
);
996 regexHelpButton
.addSelectionListener(new SelectionAdapter() {
998 public void widgetSelected(SelectionEvent e
) {
999 openHelpShell(PATTERN_URL
);
1003 label
= new Label(group
, SWT
.NONE
);
1004 label
.setText(Messages
.CustomTxtParserInputWizardPage_cardinality
);
1005 label
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
1007 cardinalityContainer
= new Composite(group
, SWT
.NONE
);
1008 GridLayout cardinalityLayout
= new GridLayout(6, false);
1009 cardinalityLayout
.marginHeight
= 0;
1010 cardinalityLayout
.marginWidth
= 0;
1011 cardinalityContainer
.setLayout(cardinalityLayout
);
1012 cardinalityContainer
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
1014 cardinalityCombo
= new Combo(cardinalityContainer
, SWT
.DROP_DOWN
| SWT
.READ_ONLY
);
1015 cardinalityCombo
.setItems(new String
[] {
1016 Cardinality
.ZERO_OR_MORE
.toString(),
1017 Cardinality
.ONE_OR_MORE
.toString(),
1018 Cardinality
.ZERO_OR_ONE
.toString(),
1019 Cardinality
.ONE
.toString(),
1020 "(?,?)"}); //$NON-NLS-1$
1021 cardinalityCombo
.addSelectionListener(new SelectionListener(){
1023 public void widgetDefaultSelected(SelectionEvent e
) {}
1025 public void widgetSelected(SelectionEvent e
) {
1026 switch (cardinalityCombo
.getSelectionIndex()) {
1028 cardinalityMinLabel
.setVisible(true);
1029 cardinalityMinText
.setVisible(true);
1030 cardinalityMaxLabel
.setVisible(true);
1031 cardinalityMaxText
.setVisible(true);
1032 infiniteButton
.setVisible(true);
1035 cardinalityMinLabel
.setVisible(false);
1036 cardinalityMinText
.setVisible(false);
1037 cardinalityMaxLabel
.setVisible(false);
1038 cardinalityMaxText
.setVisible(false);
1039 infiniteButton
.setVisible(false);
1042 cardinalityContainer
.layout();
1047 cardinalityMinLabel
= new Label(cardinalityContainer
, SWT
.NONE
);
1048 cardinalityMinLabel
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
1049 cardinalityMinLabel
.setText(Messages
.CustomTxtParserInputWizardPage_min
);
1050 cardinalityMinLabel
.setVisible(false);
1052 cardinalityMinText
= new Text(cardinalityContainer
, SWT
.BORDER
| SWT
.SINGLE
);
1053 gd
= new GridData(SWT
.CENTER
, SWT
.CENTER
, false, false);
1055 cardinalityMinText
.setLayoutData(gd
);
1056 cardinalityMinText
.setVisible(false);
1058 cardinalityMaxLabel
= new Label(cardinalityContainer
, SWT
.NONE
);
1059 cardinalityMaxLabel
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
1060 cardinalityMaxLabel
.setText(Messages
.CustomTxtParserInputWizardPage_max
);
1061 cardinalityMaxLabel
.setVisible(false);
1063 cardinalityMaxText
= new Text(cardinalityContainer
, SWT
.BORDER
| SWT
.SINGLE
);
1064 gd
= new GridData(SWT
.CENTER
, SWT
.CENTER
, false, false);
1066 cardinalityMaxText
.setLayoutData(gd
);
1067 cardinalityMaxText
.setVisible(false);
1069 infiniteButton
= new Button(cardinalityContainer
, SWT
.PUSH
);
1070 infiniteButton
.setText(INFINITY_STRING
);
1071 infiniteButton
.setVisible(false);
1072 infiniteButton
.addSelectionListener(new SelectionAdapter(){
1074 public void widgetSelected(SelectionEvent e
) {
1075 cardinalityMaxText
.setText(INFINITY_STRING
);
1078 if (inputLine
.cardinality
.equals(Cardinality
.ZERO_OR_MORE
)) {
1079 cardinalityCombo
.select(0);
1080 } else if (inputLine
.cardinality
.equals(Cardinality
.ONE_OR_MORE
)) {
1081 cardinalityCombo
.select(1);
1082 } else if (inputLine
.cardinality
.equals(Cardinality
.ZERO_OR_ONE
)) {
1083 cardinalityCombo
.select(2);
1084 } else if (inputLine
.cardinality
.equals(Cardinality
.ONE
)) {
1085 cardinalityCombo
.select(3);
1087 cardinalityCombo
.select(4);
1088 cardinalityMinLabel
.setVisible(true);
1089 cardinalityMinText
.setVisible(true);
1090 if (inputLine
.getMinCount() >= 0) {
1091 cardinalityMinText
.setText(Integer
.toString(inputLine
.getMinCount()));
1093 cardinalityMaxLabel
.setVisible(true);
1094 cardinalityMaxText
.setVisible(true);
1095 if (inputLine
.getMaxCount() == Cardinality
.INF
) {
1096 cardinalityMaxText
.setText(INFINITY_STRING
);
1097 } else if (inputLine
.getMaxCount() >= 0) {
1098 cardinalityMaxText
.setText(Integer
.toString(inputLine
.getMaxCount()));
1100 infiniteButton
.setVisible(true);
1103 VerifyListener digitsListener
= new VerifyListener() {
1105 public void verifyText(VerifyEvent e
) {
1106 if (e
.text
.equals(INFINITY_STRING
)) {
1107 e
.doit
= e
.widget
== cardinalityMaxText
&& e
.start
== 0 && e
.end
== ((Text
) e
.widget
).getText().length();
1109 if (((Text
) e
.widget
).getText().equals(INFINITY_STRING
)) {
1110 e
.doit
= e
.start
== 0 && e
.end
== ((Text
) e
.widget
).getText().length();
1112 for (int i
= 0; i
< e
.text
.length(); i
++) {
1113 if (!Character
.isDigit(e
.text
.charAt(i
))) {
1121 cardinalityMinText
.addModifyListener(updateListener
);
1122 cardinalityMaxText
.addModifyListener(updateListener
);
1123 cardinalityMinText
.addVerifyListener(digitsListener
);
1124 cardinalityMaxText
.addVerifyListener(digitsListener
);
1126 if (inputLine
.columns
!= null) {
1127 for (InputData inputData
: inputLine
.columns
) {
1128 InputGroup inputGroup
= new InputGroup(group
, this, inputs
.size()+1);
1129 if (inputData
.name
.equals(CustomTxtTraceDefinition
.TAG_TIMESTAMP
)) {
1130 inputGroup
.tagCombo
.select(0);
1131 inputGroup
.tagText
.setText(inputData
.format
);
1132 inputGroup
.tagLabel
.setText(Messages
.CustomTxtParserInputWizardPage_format
);
1133 inputGroup
.tagLabel
.setVisible(true);
1134 inputGroup
.tagText
.setVisible(true);
1135 inputGroup
.tagText
.addModifyListener(updateListener
);
1136 } else if (inputData
.name
.equals(CustomTxtTraceDefinition
.TAG_MESSAGE
)) {
1137 inputGroup
.tagCombo
.select(1);
1139 inputGroup
.tagCombo
.select(2);
1140 inputGroup
.tagText
.setText(inputData
.name
);
1141 inputGroup
.tagLabel
.setText(Messages
.CustomTxtParserInputWizardPage_name
);
1142 inputGroup
.tagLabel
.setVisible(true);
1143 inputGroup
.tagText
.setVisible(true);
1144 inputGroup
.tagText
.addModifyListener(updateListener
);
1146 inputGroup
.actionCombo
.select(inputData
.action
);
1147 inputs
.add(inputGroup
);
1151 createAddGroupButton();
1154 private void createAddGroupButton() {
1155 addGroupButton
= new Button(group
, SWT
.PUSH
);
1156 addGroupButton
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
1157 addGroupButton
.setImage(addImage
);
1158 addGroupButton
.setToolTipText(Messages
.CustomTxtParserInputWizardPage_addGroup
);
1159 addGroupButton
.addSelectionListener(new SelectionAdapter() {
1161 public void widgetSelected(SelectionEvent e
) {
1162 removeAddGroupButton();
1163 inputs
.add(new InputGroup(group
, Line
.this, inputs
.size()+1));
1164 createAddGroupButton();
1165 lineContainer
.layout();
1166 lineScrolledComposite
.setMinSize(lineContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).x
, lineContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).y
-1);
1167 group
.getParent().layout();
1173 addGroupLabel
= new Label(group
, SWT
.NULL
);
1174 addGroupLabel
.setText(Messages
.CustomTxtParserInputWizardPage_newGroup
);
1177 private void removeAddGroupButton() {
1178 addGroupButton
.dispose();
1179 addGroupLabel
.dispose();
1182 private void removeInput(int inputNumber
) {
1183 if (--inputNumber
< inputs
.size()) {
1184 inputs
.remove(inputNumber
).dispose();
1185 for (int i
= inputNumber
; i
< inputs
.size(); i
++) {
1186 inputs
.get(i
).setInputNumber(i
+1);
1188 lineContainer
.layout();
1189 lineScrolledComposite
.setMinSize(lineContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).x
, lineContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).y
-1);
1190 group
.getParent().layout();
1194 // private void setName(String name) {
1195 // this.name = name;
1196 // group.setText("Line " + name);
1199 private void dispose() {
1203 private void extractInputs() {
1204 inputLine
.setRegex(selectedLine
.regexText
.getText());
1205 switch (cardinalityCombo
.getSelectionIndex()) {
1207 inputLine
.cardinality
= Cardinality
.ZERO_OR_MORE
;
1210 inputLine
.cardinality
= Cardinality
.ONE_OR_MORE
;
1213 inputLine
.cardinality
= Cardinality
.ZERO_OR_ONE
;
1216 inputLine
.cardinality
= Cardinality
.ONE
;
1221 min
= Integer
.parseInt(cardinalityMinText
.getText());
1222 } catch (NumberFormatException e
) {
1226 if (cardinalityMaxText
.getText().equals(INFINITY_STRING
)) {
1227 max
= Cardinality
.INF
;
1229 max
= Integer
.parseInt(cardinalityMaxText
.getText());
1231 } catch (NumberFormatException e
) {
1234 inputLine
.cardinality
= new Cardinality(min
, max
);
1237 inputLine
.cardinality
= Cardinality
.ZERO_OR_MORE
;
1240 inputLine
.columns
= new ArrayList
<InputData
>(inputs
.size());
1241 for (int i
= 0; i
< inputs
.size(); i
++) {
1242 InputGroup group
= inputs
.get(i
);
1243 InputData inputData
= new InputData();
1244 if (group
.tagCombo
.getText().equals(CustomTxtTraceDefinition
.TAG_OTHER
)) {
1245 inputData
.name
= group
.tagText
.getText().trim();
1247 inputData
.name
= group
.tagCombo
.getText();
1248 if (group
.tagCombo
.getText().equals(CustomTxtTraceDefinition
.TAG_TIMESTAMP
)) {
1249 inputData
.format
= group
.tagText
.getText().trim();
1252 inputData
.action
= group
.actionCombo
.getSelectionIndex();
1253 inputLine
.columns
.add(inputData
);
1258 private class InputGroup
{
1262 // children of parent (must be disposed)
1263 Composite labelComposite
;
1264 Composite tagComposite
;
1268 // children of labelComposite
1271 // children of tagComposite
1277 public InputGroup(Composite parent
, Line line
, int inputNumber
) {
1279 this.inputNumber
= inputNumber
;
1281 labelComposite
= new Composite(parent
, SWT
.FILL
);
1282 GridLayout labelLayout
= new GridLayout(2, false);
1283 labelLayout
.marginWidth
= 0;
1284 labelLayout
.marginHeight
= 0;
1285 labelComposite
.setLayout(labelLayout
);
1286 labelComposite
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
1288 Button deleteButton
= new Button(labelComposite
, SWT
.PUSH
);
1289 deleteButton
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
1290 deleteButton
.setImage(deleteImage
);
1291 deleteButton
.setToolTipText(Messages
.CustomTxtParserInputWizardPage_removeGroup
);
1292 deleteButton
.addSelectionListener(new SelectionAdapter() {
1294 public void widgetSelected(SelectionEvent e
) {
1295 InputGroup
.this.line
.removeInput(InputGroup
.this.inputNumber
);
1301 inputLabel
= new Label(labelComposite
, SWT
.NULL
);
1302 inputLabel
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
1303 inputLabel
.setText(Messages
.CustomTxtParserInputWizardPage_group
+ inputNumber
+ ":"); //$NON-NLS-1$
1305 tagComposite
= new Composite(parent
, SWT
.FILL
);
1306 GridLayout tagLayout
= new GridLayout(4, false);
1307 tagLayout
.marginWidth
= 0;
1308 tagLayout
.marginHeight
= 0;
1309 tagComposite
.setLayout(tagLayout
);
1310 tagComposite
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
1312 tagCombo
= new Combo(tagComposite
, SWT
.DROP_DOWN
| SWT
.READ_ONLY
);
1313 tagCombo
.setItems(new String
[] {CustomTxtTraceDefinition
.TAG_TIMESTAMP
,
1314 CustomTxtTraceDefinition
.TAG_MESSAGE
,
1315 CustomTxtTraceDefinition
.TAG_OTHER
});
1317 tagCombo
.addSelectionListener(new SelectionListener(){
1319 public void widgetDefaultSelected(SelectionEvent e
) {}
1321 public void widgetSelected(SelectionEvent e
) {
1322 tagText
.removeModifyListener(updateListener
);
1323 switch (tagCombo
.getSelectionIndex()) {
1324 case 0: //Time Stamp
1325 tagLabel
.setText(Messages
.CustomTxtParserInputWizardPage_format
);
1326 tagLabel
.setVisible(true);
1327 tagText
.setVisible(true);
1328 tagText
.addModifyListener(updateListener
);
1331 tagLabel
.setVisible(false);
1332 tagText
.setVisible(false);
1335 tagLabel
.setText(Messages
.CustomTxtParserInputWizardPage_name
);
1336 tagLabel
.setVisible(true);
1337 tagText
.setVisible(true);
1338 tagText
.addModifyListener(updateListener
);
1341 tagLabel
.setVisible(false);
1342 tagText
.setVisible(false);
1345 tagComposite
.layout();
1350 tagLabel
= new Label(tagComposite
, SWT
.NULL
);
1351 tagLabel
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
1352 tagLabel
.setVisible(false);
1354 tagText
= new Text(tagComposite
, SWT
.BORDER
| SWT
.SINGLE
);
1355 GridData gd
= new GridData(SWT
.FILL
, SWT
.CENTER
, true, false);
1357 tagText
.setLayoutData(gd
);
1358 tagText
.setVisible(false);
1360 actionCombo
= new Combo(tagComposite
, SWT
.DROP_DOWN
| SWT
.READ_ONLY
);
1361 actionCombo
.setItems(new String
[] {Messages
.CustomTxtParserInputWizardPage_set
, Messages
.CustomTxtParserInputWizardPage_append
, Messages
.CustomTxtParserInputWizardPage_appendWith
});
1362 actionCombo
.select(0);
1363 actionCombo
.addSelectionListener(updateListener
);
1365 previewLabel
= new Label(parent
, SWT
.NULL
);
1366 previewLabel
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
1367 previewLabel
.setText(Messages
.CustomTxtParserInputWizardPage_preview
);
1369 previewText
= new Text(parent
, SWT
.BORDER
| SWT
.SINGLE
| SWT
.READ_ONLY
);
1370 gd
= new GridData(SWT
.FILL
, SWT
.CENTER
, true, false);
1372 previewText
.setLayoutData(gd
);
1373 previewText
.setText(Messages
.CustomTxtParserInputWizardPage_noMatch
);
1374 previewText
.setBackground(COLOR_WIDGET_BACKGROUND
);
1377 private void dispose() {
1378 labelComposite
.dispose();
1379 tagComposite
.dispose();
1380 previewLabel
.dispose();
1381 previewText
.dispose();
1384 private void setInputNumber(int inputNumber
) {
1385 this.inputNumber
= inputNumber
;
1386 inputLabel
.setText(Messages
.CustomTxtParserInputWizardPage_group
+ inputNumber
+ ":"); //$NON-NLS-1$
1387 labelComposite
.layout();
1391 private void validate() {
1393 definition
.definitionName
= logtypeText
.getText().trim();
1394 definition
.timeStampOutputFormat
= timestampOutputFormatText
.getText().trim();
1396 if (selectedLine
!= null) {
1397 selectedLine
.extractInputs();
1398 treeViewer
.refresh();
1401 StringBuffer errors
= new StringBuffer();
1403 if (definition
.definitionName
.length() == 0) {
1404 errors
.append("Enter a name for the new log type. "); //$NON-NLS-1$
1405 logtypeText
.setBackground(COLOR_LIGHT_RED
);
1407 logtypeText
.setBackground(COLOR_TEXT_BACKGROUND
);
1408 for (CustomTxtTraceDefinition def
: CustomTxtTraceDefinition
.loadAll()) {
1409 if (definition
.definitionName
.equals(def
.definitionName
)) {
1410 if (editDefinitionName
== null || ! editDefinitionName
.equals(definition
.definitionName
)) {
1411 errors
.append("The log type name already exists. "); //$NON-NLS-1$
1412 logtypeText
.setBackground(COLOR_LIGHT_RED
);
1419 timestampFound
= false;
1420 for (int i
= 0; i
< definition
.inputs
.size(); i
++) {
1422 InputLine inputLine
= definition
.inputs
.get(i
);
1423 String name
= Integer
.toString(i
+1);
1424 errors
.append(validateLine(inputLine
, name
));
1426 if (timestampFound
) {
1427 if (definition
.timeStampOutputFormat
.length() == 0) {
1428 errors
.append("Enter the output format for the Time Stamp field. "); //$NON-NLS-1$
1429 timestampOutputFormatText
.setBackground(COLOR_LIGHT_RED
);
1432 new SimpleDateFormat(definition
.timeStampOutputFormat
);
1433 timestampOutputFormatText
.setBackground(COLOR_TEXT_BACKGROUND
);
1434 } catch (IllegalArgumentException e
) {
1435 errors
.append("Enter a valid output format for the Time Stamp field. "); //$NON-NLS-1$
1436 timestampOutputFormatText
.setBackground(COLOR_LIGHT_RED
);
1441 timestampOutputFormatText
.setBackground(COLOR_TEXT_BACKGROUND
);
1442 // timestampPreviewText.setBackground(COLOR_WIDGET_BACKGROUND);
1443 // errors.append("Identify a Time Stamp group (Line "+name+"). ");
1444 // timestampPreviewText.setText("*no timestamp group*");
1445 // timestampPreviewText.setBackground(COLOR_LIGHT_RED);
1448 if (errors
.length() == 0) {
1449 setDescription(defaultDescription
);
1450 setPageComplete(true);
1452 setDescription(errors
.toString());
1453 setPageComplete(false);
1457 public StringBuffer
validateLine(InputLine inputLine
, String name
) {
1458 StringBuffer errors
= new StringBuffer();
1460 if (selectedLine
!= null && selectedLine
.inputLine
.equals(inputLine
)) line
= selectedLine
;
1462 Pattern
.compile(inputLine
.getRegex());
1463 if (line
!= null) line
.regexText
.setBackground(COLOR_TEXT_BACKGROUND
);
1464 } catch (PatternSyntaxException e
) {
1465 errors
.append("Enter a valid regular expression (Line "+name
+"). "); //$NON-NLS-1$ //$NON-NLS-2$
1466 if (line
!= null) line
.regexText
.setBackground(COLOR_LIGHT_RED
);
1468 if (inputLine
.getMinCount() == -1) {
1469 errors
.append("Enter a minimum value for cardinality (Line "+name
+"). "); //$NON-NLS-1$ //$NON-NLS-2$
1470 if (line
!= null) line
.cardinalityMinText
.setBackground(COLOR_LIGHT_RED
);
1472 if (line
!= null) line
.cardinalityMinText
.setBackground(COLOR_TEXT_BACKGROUND
);
1474 if (inputLine
.getMaxCount() == -1) {
1475 errors
.append("Enter a maximum value for cardinality (Line "+name
+"). "); //$NON-NLS-1$ //$NON-NLS-2$
1476 if (line
!= null) line
.cardinalityMaxText
.setBackground(COLOR_LIGHT_RED
);
1477 } else if (inputLine
.getMinCount() > inputLine
.getMaxCount()) {
1478 errors
.append("Enter correct (min <= max) values for cardinality (Line "+name
+"). "); //$NON-NLS-1$ //$NON-NLS-2$
1479 if (line
!= null) line
.cardinalityMinText
.setBackground(COLOR_LIGHT_RED
);
1480 if (line
!= null) line
.cardinalityMaxText
.setBackground(COLOR_LIGHT_RED
);
1482 if (line
!= null) line
.cardinalityMaxText
.setBackground(COLOR_TEXT_BACKGROUND
);
1484 for (int i
= 0; inputLine
.columns
!= null && i
< inputLine
.columns
.size(); i
++) {
1485 InputData inputData
= inputLine
.columns
.get(i
);
1486 InputGroup group
= null;
1487 if (line
!= null) group
= line
.inputs
.get(i
);
1488 if (inputData
.name
.equals(CustomTxtTraceDefinition
.TAG_TIMESTAMP
)) {
1489 timestampFound
= true;
1490 if (inputData
.format
.length() == 0) {
1491 errors
.append("Enter the input format for the Time Stamp (Line "+name
+" Group "+(i
+1)+"). "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
1492 if (group
!= null) group
.tagText
.setBackground(COLOR_LIGHT_RED
);
1495 new SimpleDateFormat(inputData
.format
);
1496 if (group
!= null) group
.tagText
.setBackground(COLOR_TEXT_BACKGROUND
);
1497 } catch (IllegalArgumentException e
) {
1498 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$
1499 if (group
!= null) group
.tagText
.setBackground(COLOR_LIGHT_RED
);
1502 } else if (inputData
.name
.length() == 0) {
1503 errors
.append("Enter a name for the data group (Line "+name
+" Group "+(i
+1)+"). "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
1504 if (group
!= null) group
.tagText
.setBackground(COLOR_LIGHT_RED
);
1506 if (group
!= null) group
.tagText
.setBackground(COLOR_TEXT_BACKGROUND
);
1509 for (int i
= 0; inputLine
.childrenInputs
!= null && i
< inputLine
.childrenInputs
.size(); i
++) {
1510 errors
.append(validateLine(inputLine
.childrenInputs
.get(i
), name
+"."+(i
+1))); //$NON-NLS-1$
1515 public CustomTxtTraceDefinition
getDefinition() {
1519 public char[] getInputText() {
1520 return inputText
.getText().toCharArray();