1 package org
.eclipse
.linuxtools
.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
.tmf
.ui
.TmfUiPlugin
;
33 import org
.eclipse
.linuxtools
.tmf
.ui
.internal
.Messages
;
34 import org
.eclipse
.linuxtools
.tmf
.ui
.parsers
.custom
.CustomTxtTraceDefinition
;
35 import org
.eclipse
.linuxtools
.tmf
.ui
.parsers
.custom
.CustomTxtTraceDefinition
.Cardinality
;
36 import org
.eclipse
.linuxtools
.tmf
.ui
.parsers
.custom
.CustomTxtTraceDefinition
.InputData
;
37 import org
.eclipse
.linuxtools
.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
= TmfUiPlugin
.getDefault().getImageFromPath("/icons/elcl16/line_icon.gif"); //$NON-NLS-1$
76 private static final Image addImage
= TmfUiPlugin
.getDefault().getImageFromPath("/icons/elcl16/add_button.gif"); //$NON-NLS-1$
77 private static final Image addNextImage
= TmfUiPlugin
.getDefault().getImageFromPath("/icons/elcl16/addnext_button.gif"); //$NON-NLS-1$
78 private static final Image addChildImage
= TmfUiPlugin
.getDefault().getImageFromPath("/icons/elcl16/addchild_button.gif"); //$NON-NLS-1$
79 private static final Image deleteImage
= TmfUiPlugin
.getDefault().getImageFromPath("/icons/elcl16/delete_button.gif"); //$NON-NLS-1$
80 private static final Image moveUpImage
= TmfUiPlugin
.getDefault().getImageFromPath("/icons/elcl16/moveup_button.gif"); //$NON-NLS-1$
81 private static final Image moveDownImage
= TmfUiPlugin
.getDefault().getImageFromPath("/icons/elcl16/movedown_button.gif"); //$NON-NLS-1$
82 private static final Image helpImage
= TmfUiPlugin
.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 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
;
554 BufferedReader reader
= new BufferedReader(new InputStreamReader(file
.getContents()));
555 StringBuilder sb
= new StringBuilder();
557 while ((line
= reader
.readLine()) != null) {
558 sb
.append(line
+ "\n"); //$NON-NLS-1$
560 return sb
.toString();
561 } catch (CoreException e
) {
562 return ""; //$NON-NLS-1$
563 } catch (IOException e
) {
564 return ""; //$NON-NLS-1$
568 return ""; //$NON-NLS-1$
571 private void updatePreviews() {
572 updatePreviews(false);
575 private void updatePreviews(boolean updateAll
) {
576 if (inputText
== null) {
577 // early update during construction
580 inputText
.setStyleRanges(new StyleRange
[] {});
582 Scanner scanner
= new Scanner(inputText
.getText());
583 scanner
.useDelimiter("\n"); //$NON-NLS-1$
585 String skip
; // skip starting delimiters
586 if ((skip
= scanner
.findWithinHorizon("\\A\n+", 0)) != null) { //$NON-NLS-1$
587 rawPos
+= skip
.length();
590 timeStampFormat
= null;
591 if (selectedLine
!= null) {
592 for (InputGroup input
: selectedLine
.inputs
) {
593 input
.previewText
.setText(Messages
.CustomTxtParserInputWizardPage_noMathcingLine
);
597 Map
<String
, String
> data
= new HashMap
<String
, String
>();
598 int rootLineMatches
= 0;
599 String firstEntryTimeStamp
= null;
600 String firstEntryTimeStampInputFormat
= null;
603 while (log
!= null || scanner
.hasNext()) {
604 if (rootLineMatches
> 0 && !updateAll
) {
608 log
= scanner
.next();
610 int length
= log
.length();
611 for (InputLine rootInputLine
: definition
.inputs
) {
614 pattern
= rootInputLine
.getPattern();
615 } catch (PatternSyntaxException e
) {
618 Matcher matcher
= pattern
.matcher(log
);
619 if (matcher
.find()) {
621 inputText
.setStyleRange(new StyleRange(rawPos
, length
,
622 COLOR_BLACK
, COLOR_YELLOW
, SWT
.ITALIC
));
623 data
= new HashMap
<String
, String
>();
624 timeStampFormat
= null;
625 updatePreviewLine(rootInputLine
, matcher
, data
, rawPos
, rootLineMatches
);
626 if (rootLineMatches
== 1) {
627 firstEntryTimeStamp
= data
.get(CustomTxtTraceDefinition
.TAG_TIMESTAMP
);
628 firstEntryTimeStampInputFormat
= timeStampFormat
;
630 HashMap
<InputLine
, Integer
> countMap
= new HashMap
<InputLine
, Integer
>();
631 InputLine currentInput
= null;
632 if (rootInputLine
.childrenInputs
!= null && rootInputLine
.childrenInputs
.size() > 0) {
633 currentInput
= rootInputLine
.childrenInputs
.get(0);
634 countMap
.put(currentInput
, 0);
636 rawPos
+= length
+ 1; // +1 for \n
637 while (scanner
.hasNext()) {
638 log
= scanner
.next();
639 length
= log
.length();
640 boolean processed
= false;
641 if (currentInput
== null) {
642 for (InputLine input
: definition
.inputs
) {
643 matcher
= input
.getPattern().matcher(log
);
644 if (matcher
.find()) {
649 if (countMap
.get(currentInput
) >= currentInput
.getMinCount()) {
650 List
<InputLine
> nextInputs
= currentInput
.getNextInputs(countMap
);
651 if (nextInputs
.size() == 0 || nextInputs
.get(nextInputs
.size() - 1).getMinCount() == 0) {
652 for (InputLine input
: definition
.inputs
) {
653 matcher
= input
.getPattern().matcher(log
);
654 if (matcher
.find()) {
659 for (InputLine input
: nextInputs
) {
660 matcher
= input
.getPattern().matcher(log
);
661 if (matcher
.find()) {
662 inputText
.setStyleRange(new StyleRange(rawPos
, length
,
663 COLOR_BLACK
, COLOR_LIGHT_YELLOW
, SWT
.ITALIC
));
664 currentInput
= input
;
665 updatePreviewLine(currentInput
, matcher
, data
, rawPos
, rootLineMatches
);
666 if (countMap
.get(currentInput
) == null) {
667 countMap
.put(currentInput
, 1);
669 countMap
.put(currentInput
, countMap
.get(currentInput
) + 1);
671 Iterator
<InputLine
> iter
= countMap
.keySet().iterator();
672 while (iter
.hasNext()) {
673 InputLine inputLine
= iter
.next();
674 if (inputLine
.level
> currentInput
.level
) {
678 if (currentInput
.childrenInputs
!= null && currentInput
.childrenInputs
.size() > 0) {
679 currentInput
= currentInput
.childrenInputs
.get(0);
680 countMap
.put(currentInput
, 0);
682 if (countMap
.get(currentInput
) >= currentInput
.getMaxCount()) {
683 if (currentInput
.getNextInputs(countMap
).size() > 0) {
684 currentInput
= currentInput
.getNextInputs(countMap
).get(0);
685 if (countMap
.get(currentInput
) == null) {
686 countMap
.put(currentInput
, 0);
688 iter
= countMap
.keySet().iterator();
689 while (iter
.hasNext()) {
690 InputLine inputLine
= iter
.next();
691 if (inputLine
.level
> currentInput
.level
) {
706 matcher
= currentInput
.getPattern().matcher(log
);
707 if (matcher
.find()) {
708 inputText
.setStyleRange(new StyleRange(rawPos
, length
,
709 COLOR_BLACK
, COLOR_LIGHT_YELLOW
, SWT
.ITALIC
));
710 updatePreviewLine(currentInput
, matcher
, data
, rawPos
, rootLineMatches
);
711 countMap
.put(currentInput
, countMap
.get(currentInput
) + 1);
712 if (currentInput
.childrenInputs
!= null && currentInput
.childrenInputs
.size() > 0) {
713 currentInput
= currentInput
.childrenInputs
.get(0);
714 countMap
.put(currentInput
, 0);
716 if (countMap
.get(currentInput
) >= currentInput
.getMaxCount()) {
717 if (currentInput
.getNextInputs(countMap
).size() > 0) {
718 currentInput
= currentInput
.getNextInputs(countMap
).get(0);
719 if (countMap
.get(currentInput
) == null) {
720 countMap
.put(currentInput
, 0);
722 Iterator
<InputLine
> iter
= countMap
.keySet().iterator();
723 while (iter
.hasNext()) {
724 InputLine inputLine
= iter
.next();
725 if (inputLine
.level
> currentInput
.level
) {
737 rawPos
+= length
+ 1; // +1 for \n
743 rawPos
+= length
+ 1; // +1 for \n
747 if (rootLineMatches
== 1) {
748 firstEntryTimeStamp
= data
.get(CustomTxtTraceDefinition
.TAG_TIMESTAMP
);
749 firstEntryTimeStampInputFormat
= timeStampFormat
;
751 if (firstEntryTimeStamp
== null) {
752 timestampPreviewText
.setText(Messages
.CustomTxtParserInputWizardPage_noTimestampGroup
);
753 if (selectedLine
!= null) {
754 for (InputGroup group
: selectedLine
.inputs
) {
755 if (group
.tagCombo
.getText().equals(CustomTxtTraceDefinition
.TAG_TIMESTAMP
)) {
756 timestampPreviewText
.setText(Messages
.CustomTxtParserInputWizardPage_noMatchingTimestamp
);
763 SimpleDateFormat dateFormat
= new SimpleDateFormat(firstEntryTimeStampInputFormat
);
764 Date date
= dateFormat
.parse(firstEntryTimeStamp
);
765 dateFormat
= new SimpleDateFormat(timestampOutputFormatText
.getText().trim());
766 timestampPreviewText
.setText(dateFormat
.format(date
));
767 } catch (ParseException e
) {
768 timestampPreviewText
.setText("*parse exception* [" + firstEntryTimeStamp
+ "] <> [" + firstEntryTimeStampInputFormat
+ "]"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
769 } catch (IllegalArgumentException e
) {
770 timestampPreviewText
.setText("*parse exception* [Illegal Argument]"); //$NON-NLS-1$
776 private void updatePreviewLine(InputLine line
, Matcher matcher
, Map
<String
, String
> data
, int rawPos
, int rootLineMatches
) {
777 for (int i
= 0; i
< line
.columns
.size(); i
++) {
778 InputData input
= line
.columns
.get(i
);
779 if (i
< matcher
.groupCount() && matcher
.group(i
+1) != null) {
780 if (line
.parentInput
== null) {
781 inputText
.setStyleRange(new StyleRange(rawPos
+ matcher
.start(i
+1), matcher
.end(i
+1) - matcher
.start(i
+1),
782 COLOR_BLACK
, COLOR_GREEN
, SWT
.BOLD
));
784 inputText
.setStyleRange(new StyleRange(rawPos
+ matcher
.start(i
+1), matcher
.end(i
+1) - matcher
.start(i
+1),
785 COLOR_BLACK
, COLOR_LIGHT_GREEN
, SWT
.BOLD
));
787 String value
= matcher
.group(i
+1).trim();
788 if (selectedLine
!= null && selectedLine
.inputLine
.equals(line
) && rootLineMatches
== 1) {
789 if (selectedLine
.inputs
.get(i
).previewText
.getText().equals(Messages
.CustomTxtParserInputWizardPage_noMatchingLine
)) {
790 selectedLine
.inputs
.get(i
).previewText
.setText(value
);
793 if (value
.length() == 0) {
796 if (input
.action
== CustomTxtTraceDefinition
.ACTION_SET
) {
797 data
.put(input
.name
, value
);
798 if (input
.name
.equals(CustomTxtTraceDefinition
.TAG_TIMESTAMP
)) {
799 timeStampFormat
= input
.format
;
801 } else if (input
.action
== CustomTxtTraceDefinition
.ACTION_APPEND
) {
802 String s
= data
.get(input
.name
);
804 data
.put(input
.name
, s
+ value
);
806 data
.put(input
.name
, value
);
808 if (input
.name
.equals(CustomTxtTraceDefinition
.TAG_TIMESTAMP
)) {
809 if (timeStampFormat
!= null) {
810 timeStampFormat
+= input
.format
;
812 timeStampFormat
= input
.format
;
815 } else if (input
.action
== CustomTxtTraceDefinition
.ACTION_APPEND_WITH_SEPARATOR
) {
816 String s
= data
.get(input
.name
);
818 data
.put(input
.name
, s
+ " | " + value
); //$NON-NLS-1$
820 data
.put(input
.name
, value
);
822 if (input
.name
.equals(CustomTxtTraceDefinition
.TAG_TIMESTAMP
)) {
823 if (timeStampFormat
!= null) {
824 timeStampFormat
+= " | " + input
.format
; //$NON-NLS-1$
826 timeStampFormat
= input
.format
;
831 if (selectedLine
!= null && selectedLine
.inputLine
.equals(line
) && rootLineMatches
== 1) {
832 if (selectedLine
.inputs
.get(i
).previewText
.getText().equals(Messages
.CustomTxtParserInputWizardPage_noMatchingLine
)) {
833 selectedLine
.inputs
.get(i
).previewText
.setText(Messages
.CustomTxtParserInputWizardPage_noMatchingGroup
);
838 // highlight the matching groups that have no corresponponding input
839 for (int i
= line
.columns
.size(); i
< matcher
.groupCount(); i
++) {
840 if (matcher
.group(i
+1) != null) {
841 if (line
.parentInput
== null) {
842 inputText
.setStyleRange(new StyleRange(rawPos
+ matcher
.start(i
+1), matcher
.end(i
+1) - matcher
.start(i
+1),
843 COLOR_BLACK
, COLOR_MAGENTA
));
845 inputText
.setStyleRange(new StyleRange(rawPos
+ matcher
.start(i
+1), matcher
.end(i
+1) - matcher
.start(i
+1),
846 COLOR_BLACK
, COLOR_LIGHT_MAGENTA
));
852 private void openHelpShell(String url
) {
853 if (helpBrowser
!= null && !helpBrowser
.isDisposed()) {
854 helpBrowser
.getShell().setActive();
855 if (!helpBrowser
.getUrl().equals(url
)) {
856 helpBrowser
.setUrl(url
);
860 final Shell helpShell
= new Shell(getShell(), SWT
.SHELL_TRIM
);
861 helpShell
.setLayout(new FillLayout());
862 helpBrowser
= new Browser(helpShell
, SWT
.NONE
);
863 helpBrowser
.addTitleListener(new TitleListener() {
865 public void changed(TitleEvent event
) {
866 helpShell
.setText(event
.title
);
869 helpBrowser
.setBounds(0,0,600,400);
872 helpBrowser
.setUrl(url
);
875 private void openLegend() {
876 final String CG
= Messages
.CustomTxtParserInputWizardPage_capturedGroup
;
877 final String UCG
= Messages
.CustomTxtParserInputWizardPage_unidentifiedCaptureGroup
;
878 final String UT
= Messages
.CustomTxtParserInputWizardPage_uncapturedText
;
880 String line1
= Messages
.CustomTxtParserInputWizardPage_nonMatchingLine
;
881 int line2start
= line1start
+ line1
.length();
882 String line2
= Messages
.CustomTxtParserInputWizardPage_matchingLineRoot
+ CG
+ " " + UCG
+ " " + UT
+ " \n"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
883 int line3start
= line2start
+ line2
.length();
884 String line3
= Messages
.CustomTxtParserInputWizardPage_matchingOtherLine
+ CG
+ " " + UCG
+ " " + UT
+ " \n"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
885 int line4start
= line3start
+ line3
.length();
886 String line4
= Messages
.CustomTxtParserInputWizardPage_matchingOtherLine
+ CG
+ " " + UCG
+ " " + UT
+ " \n"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
887 int line5start
= line4start
+ line4
.length();
888 String line5
= Messages
.CustomTxtParserInputWizardPage_nonMatchingLine
;
889 int line6start
= line5start
+ line5
.length();
890 String line6
= Messages
.CustomTxtParserInputWizardPage_matchingRootLine
+ CG
+ " " + UCG
+ " " + UT
+ " \n"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
892 final Shell legendShell
= new Shell(getShell(), SWT
.DIALOG_TRIM
);
893 legendShell
.setLayout(new FillLayout());
894 StyledText legendText
= new StyledText(legendShell
, SWT
.MULTI
);
895 legendText
.setFont(fixedFont
);
896 legendText
.setText(line1
+ line2
+ line3
+ line4
+ line5
+ line6
);
897 legendText
.setStyleRange(new StyleRange(line2start
, line2
.length(), COLOR_BLACK
, COLOR_YELLOW
, SWT
.ITALIC
));
898 legendText
.setStyleRange(new StyleRange(line3start
, line3
.length(), COLOR_BLACK
, COLOR_LIGHT_YELLOW
, SWT
.ITALIC
));
899 legendText
.setStyleRange(new StyleRange(line4start
, line4
.length(), COLOR_BLACK
, COLOR_LIGHT_YELLOW
, SWT
.ITALIC
));
900 legendText
.setStyleRange(new StyleRange(line6start
, line6
.length(), COLOR_BLACK
, COLOR_YELLOW
, SWT
.ITALIC
));
901 legendText
.setStyleRange(new StyleRange(line2start
+ line2
.indexOf(CG
), CG
.length(), COLOR_BLACK
, COLOR_GREEN
, SWT
.BOLD
));
902 legendText
.setStyleRange(new StyleRange(line2start
+ line2
.indexOf(UCG
), UCG
.length(), COLOR_BLACK
, COLOR_MAGENTA
));
903 legendText
.setStyleRange(new StyleRange(line3start
+ line3
.indexOf(CG
), CG
.length(), COLOR_BLACK
, COLOR_LIGHT_GREEN
, SWT
.BOLD
));
904 legendText
.setStyleRange(new StyleRange(line3start
+ line3
.indexOf(UCG
), UCG
.length(), COLOR_BLACK
, COLOR_LIGHT_MAGENTA
));
905 legendText
.setStyleRange(new StyleRange(line4start
+ line4
.indexOf(CG
), CG
.length(), COLOR_BLACK
, COLOR_LIGHT_GREEN
, SWT
.BOLD
));
906 legendText
.setStyleRange(new StyleRange(line4start
+ line4
.indexOf(UCG
), UCG
.length(), COLOR_BLACK
, COLOR_LIGHT_MAGENTA
));
907 legendText
.setStyleRange(new StyleRange(line6start
+ line6
.indexOf(CG
), CG
.length(), COLOR_BLACK
, COLOR_GREEN
, SWT
.BOLD
));
908 legendText
.setStyleRange(new StyleRange(line6start
+ line6
.indexOf(UCG
), UCG
.length(), COLOR_BLACK
, COLOR_MAGENTA
));
909 legendShell
.setText(Messages
.CustomTxtParserInputWizardPage_previewLegend
);
914 private class UpdateListener
implements ModifyListener
, SelectionListener
{
917 public void modifyText(ModifyEvent e
) {
923 public void widgetDefaultSelected(SelectionEvent e
) {
929 public void widgetSelected(SelectionEvent e
) {
937 private static final String INFINITY_STRING
= "\u221E"; //$NON-NLS-1$
938 @SuppressWarnings("unused")
942 Composite labelComposite
;
944 Composite cardinalityContainer
;
945 Combo cardinalityCombo
;
946 Label cardinalityMinLabel
;
947 Text cardinalityMinText
;
948 Label cardinalityMaxLabel
;
949 Text cardinalityMaxText
;
950 Button infiniteButton
;
951 ArrayList
<InputGroup
> inputs
= new ArrayList
<InputGroup
>();
952 Button addGroupButton
;
955 public Line(Composite parent
, String name
, InputLine inputLine
) {
957 this.inputLine
= inputLine
;
959 group
= new Group(parent
, SWT
.NONE
);
961 group
.setLayout(new GridLayout(2, false));
962 group
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
964 labelComposite
= new Composite(group
, SWT
.FILL
);
965 GridLayout labelLayout
= new GridLayout(1, false);
966 labelLayout
.marginWidth
= 0;
967 labelLayout
.marginHeight
= 0;
968 labelComposite
.setLayout(labelLayout
);
969 labelComposite
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
971 Label label
= new Label(labelComposite
, SWT
.NULL
);
972 label
.setText(Messages
.CustomTxtParserInputWizardPage_regularExpression
);
974 Composite regexContainer
= new Composite(group
, SWT
.NONE
);
975 GridLayout regexLayout
= new GridLayout(2, false);
976 regexLayout
.marginHeight
= 0;
977 regexLayout
.marginWidth
= 0;
978 regexContainer
.setLayout(regexLayout
);
979 regexContainer
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
981 regexText
= new Text(regexContainer
, SWT
.BORDER
| SWT
.SINGLE
);
982 GridData gd
= new GridData(SWT
.FILL
, SWT
.CENTER
, true, false);
984 regexText
.setLayoutData(gd
);
985 regexText
.setText(inputLine
.getRegex());
986 regexText
.addModifyListener(updateListener
);
988 Button regexHelpButton
= new Button(regexContainer
, SWT
.PUSH
);
989 regexHelpButton
.setImage(helpImage
);
990 regexHelpButton
.setToolTipText(Messages
.CustomTxtParserInputWizardPage_regularExpressionHelp
);
991 regexHelpButton
.addSelectionListener(new SelectionAdapter() {
993 public void widgetSelected(SelectionEvent e
) {
994 openHelpShell(PATTERN_URL
);
998 label
= new Label(group
, SWT
.NONE
);
999 label
.setText(Messages
.CustomTxtParserInputWizardPage_cardinality
);
1000 label
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
1002 cardinalityContainer
= new Composite(group
, SWT
.NONE
);
1003 GridLayout cardinalityLayout
= new GridLayout(6, false);
1004 cardinalityLayout
.marginHeight
= 0;
1005 cardinalityLayout
.marginWidth
= 0;
1006 cardinalityContainer
.setLayout(cardinalityLayout
);
1007 cardinalityContainer
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
1009 cardinalityCombo
= new Combo(cardinalityContainer
, SWT
.DROP_DOWN
| SWT
.READ_ONLY
);
1010 cardinalityCombo
.setItems(new String
[] {
1011 Cardinality
.ZERO_OR_MORE
.toString(),
1012 Cardinality
.ONE_OR_MORE
.toString(),
1013 Cardinality
.ZERO_OR_ONE
.toString(),
1014 Cardinality
.ONE
.toString(),
1015 "(?,?)"}); //$NON-NLS-1$
1016 cardinalityCombo
.addSelectionListener(new SelectionListener(){
1018 public void widgetDefaultSelected(SelectionEvent e
) {}
1020 public void widgetSelected(SelectionEvent e
) {
1021 switch (cardinalityCombo
.getSelectionIndex()) {
1023 cardinalityMinLabel
.setVisible(true);
1024 cardinalityMinText
.setVisible(true);
1025 cardinalityMaxLabel
.setVisible(true);
1026 cardinalityMaxText
.setVisible(true);
1027 infiniteButton
.setVisible(true);
1030 cardinalityMinLabel
.setVisible(false);
1031 cardinalityMinText
.setVisible(false);
1032 cardinalityMaxLabel
.setVisible(false);
1033 cardinalityMaxText
.setVisible(false);
1034 infiniteButton
.setVisible(false);
1037 cardinalityContainer
.layout();
1042 cardinalityMinLabel
= new Label(cardinalityContainer
, SWT
.NONE
);
1043 cardinalityMinLabel
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
1044 cardinalityMinLabel
.setText(Messages
.CustomTxtParserInputWizardPage_min
);
1045 cardinalityMinLabel
.setVisible(false);
1047 cardinalityMinText
= new Text(cardinalityContainer
, SWT
.BORDER
| SWT
.SINGLE
);
1048 gd
= new GridData(SWT
.CENTER
, SWT
.CENTER
, false, false);
1050 cardinalityMinText
.setLayoutData(gd
);
1051 cardinalityMinText
.setVisible(false);
1053 cardinalityMaxLabel
= new Label(cardinalityContainer
, SWT
.NONE
);
1054 cardinalityMaxLabel
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
1055 cardinalityMaxLabel
.setText(Messages
.CustomTxtParserInputWizardPage_max
);
1056 cardinalityMaxLabel
.setVisible(false);
1058 cardinalityMaxText
= new Text(cardinalityContainer
, SWT
.BORDER
| SWT
.SINGLE
);
1059 gd
= new GridData(SWT
.CENTER
, SWT
.CENTER
, false, false);
1061 cardinalityMaxText
.setLayoutData(gd
);
1062 cardinalityMaxText
.setVisible(false);
1064 infiniteButton
= new Button(cardinalityContainer
, SWT
.PUSH
);
1065 infiniteButton
.setText(INFINITY_STRING
);
1066 infiniteButton
.setVisible(false);
1067 infiniteButton
.addSelectionListener(new SelectionAdapter(){
1069 public void widgetSelected(SelectionEvent e
) {
1070 cardinalityMaxText
.setText(INFINITY_STRING
);
1073 if (inputLine
.cardinality
.equals(Cardinality
.ZERO_OR_MORE
)) {
1074 cardinalityCombo
.select(0);
1075 } else if (inputLine
.cardinality
.equals(Cardinality
.ONE_OR_MORE
)) {
1076 cardinalityCombo
.select(1);
1077 } else if (inputLine
.cardinality
.equals(Cardinality
.ZERO_OR_ONE
)) {
1078 cardinalityCombo
.select(2);
1079 } else if (inputLine
.cardinality
.equals(Cardinality
.ONE
)) {
1080 cardinalityCombo
.select(3);
1082 cardinalityCombo
.select(4);
1083 cardinalityMinLabel
.setVisible(true);
1084 cardinalityMinText
.setVisible(true);
1085 if (inputLine
.getMinCount() >= 0) {
1086 cardinalityMinText
.setText(Integer
.toString(inputLine
.getMinCount()));
1088 cardinalityMaxLabel
.setVisible(true);
1089 cardinalityMaxText
.setVisible(true);
1090 if (inputLine
.getMaxCount() == Cardinality
.INF
) {
1091 cardinalityMaxText
.setText(INFINITY_STRING
);
1092 } else if (inputLine
.getMaxCount() >= 0) {
1093 cardinalityMaxText
.setText(Integer
.toString(inputLine
.getMaxCount()));
1095 infiniteButton
.setVisible(true);
1098 VerifyListener digitsListener
= new VerifyListener() {
1100 public void verifyText(VerifyEvent e
) {
1101 if (e
.text
.equals(INFINITY_STRING
)) {
1102 e
.doit
= e
.widget
== cardinalityMaxText
&& e
.start
== 0 && e
.end
== ((Text
) e
.widget
).getText().length();
1104 if (((Text
) e
.widget
).getText().equals(INFINITY_STRING
)) {
1105 e
.doit
= e
.start
== 0 && e
.end
== ((Text
) e
.widget
).getText().length();
1107 for (int i
= 0; i
< e
.text
.length(); i
++) {
1108 if (!Character
.isDigit(e
.text
.charAt(i
))) {
1116 cardinalityMinText
.addModifyListener(updateListener
);
1117 cardinalityMaxText
.addModifyListener(updateListener
);
1118 cardinalityMinText
.addVerifyListener(digitsListener
);
1119 cardinalityMaxText
.addVerifyListener(digitsListener
);
1121 if (inputLine
.columns
!= null) {
1122 for (InputData inputData
: inputLine
.columns
) {
1123 InputGroup inputGroup
= new InputGroup(group
, this, inputs
.size()+1);
1124 if (inputData
.name
.equals(CustomTxtTraceDefinition
.TAG_TIMESTAMP
)) {
1125 inputGroup
.tagCombo
.select(0);
1126 inputGroup
.tagText
.setText(inputData
.format
);
1127 inputGroup
.tagLabel
.setText(Messages
.CustomTxtParserInputWizardPage_format
);
1128 inputGroup
.tagLabel
.setVisible(true);
1129 inputGroup
.tagText
.setVisible(true);
1130 inputGroup
.tagText
.addModifyListener(updateListener
);
1131 } else if (inputData
.name
.equals(CustomTxtTraceDefinition
.TAG_MESSAGE
)) {
1132 inputGroup
.tagCombo
.select(1);
1134 inputGroup
.tagCombo
.select(2);
1135 inputGroup
.tagText
.setText(inputData
.name
);
1136 inputGroup
.tagLabel
.setText(Messages
.CustomTxtParserInputWizardPage_name
);
1137 inputGroup
.tagLabel
.setVisible(true);
1138 inputGroup
.tagText
.setVisible(true);
1139 inputGroup
.tagText
.addModifyListener(updateListener
);
1141 inputGroup
.actionCombo
.select(inputData
.action
);
1142 inputs
.add(inputGroup
);
1146 createAddGroupButton();
1149 private void createAddGroupButton() {
1150 addGroupButton
= new Button(group
, SWT
.PUSH
);
1151 addGroupButton
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
1152 addGroupButton
.setImage(addImage
);
1153 addGroupButton
.setToolTipText(Messages
.CustomTxtParserInputWizardPage_addGroup
);
1154 addGroupButton
.addSelectionListener(new SelectionAdapter() {
1156 public void widgetSelected(SelectionEvent e
) {
1157 removeAddGroupButton();
1158 inputs
.add(new InputGroup(group
, Line
.this, inputs
.size()+1));
1159 createAddGroupButton();
1160 lineContainer
.layout();
1161 lineScrolledComposite
.setMinSize(lineContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).x
, lineContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).y
-1);
1162 group
.getParent().layout();
1168 addGroupLabel
= new Label(group
, SWT
.NULL
);
1169 addGroupLabel
.setText(Messages
.CustomTxtParserInputWizardPage_newGroup
);
1172 private void removeAddGroupButton() {
1173 addGroupButton
.dispose();
1174 addGroupLabel
.dispose();
1177 private void removeInput(int inputNumber
) {
1178 if (--inputNumber
< inputs
.size()) {
1179 inputs
.remove(inputNumber
).dispose();
1180 for (int i
= inputNumber
; i
< inputs
.size(); i
++) {
1181 inputs
.get(i
).setInputNumber(i
+1);
1183 lineContainer
.layout();
1184 lineScrolledComposite
.setMinSize(lineContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).x
, lineContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).y
-1);
1185 group
.getParent().layout();
1189 // private void setName(String name) {
1190 // this.name = name;
1191 // group.setText("Line " + name);
1194 private void dispose() {
1198 private void extractInputs() {
1199 inputLine
.setRegex(selectedLine
.regexText
.getText());
1200 switch (cardinalityCombo
.getSelectionIndex()) {
1202 inputLine
.cardinality
= Cardinality
.ZERO_OR_MORE
;
1205 inputLine
.cardinality
= Cardinality
.ONE_OR_MORE
;
1208 inputLine
.cardinality
= Cardinality
.ZERO_OR_ONE
;
1211 inputLine
.cardinality
= Cardinality
.ONE
;
1216 min
= Integer
.parseInt(cardinalityMinText
.getText());
1217 } catch (NumberFormatException e
) {
1221 if (cardinalityMaxText
.getText().equals(INFINITY_STRING
)) {
1222 max
= Cardinality
.INF
;
1224 max
= Integer
.parseInt(cardinalityMaxText
.getText());
1226 } catch (NumberFormatException e
) {
1229 inputLine
.cardinality
= new Cardinality(min
, max
);
1232 inputLine
.cardinality
= Cardinality
.ZERO_OR_MORE
;
1235 inputLine
.columns
= new ArrayList
<InputData
>(inputs
.size());
1236 for (int i
= 0; i
< inputs
.size(); i
++) {
1237 InputGroup group
= inputs
.get(i
);
1238 InputData inputData
= new InputData();
1239 if (group
.tagCombo
.getText().equals(CustomTxtTraceDefinition
.TAG_OTHER
)) {
1240 inputData
.name
= group
.tagText
.getText().trim();
1242 inputData
.name
= group
.tagCombo
.getText();
1243 if (group
.tagCombo
.getText().equals(CustomTxtTraceDefinition
.TAG_TIMESTAMP
)) {
1244 inputData
.format
= group
.tagText
.getText().trim();
1247 inputData
.action
= group
.actionCombo
.getSelectionIndex();
1248 inputLine
.columns
.add(inputData
);
1253 private class InputGroup
{
1257 // children of parent (must be disposed)
1258 Composite labelComposite
;
1259 Composite tagComposite
;
1263 // children of labelComposite
1266 // children of tagComposite
1272 public InputGroup(Composite parent
, Line line
, int inputNumber
) {
1274 this.inputNumber
= inputNumber
;
1276 labelComposite
= new Composite(parent
, SWT
.FILL
);
1277 GridLayout labelLayout
= new GridLayout(2, false);
1278 labelLayout
.marginWidth
= 0;
1279 labelLayout
.marginHeight
= 0;
1280 labelComposite
.setLayout(labelLayout
);
1281 labelComposite
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
1283 Button deleteButton
= new Button(labelComposite
, SWT
.PUSH
);
1284 deleteButton
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
1285 deleteButton
.setImage(deleteImage
);
1286 deleteButton
.setToolTipText(Messages
.CustomTxtParserInputWizardPage_removeGroup
);
1287 deleteButton
.addSelectionListener(new SelectionAdapter() {
1289 public void widgetSelected(SelectionEvent e
) {
1290 InputGroup
.this.line
.removeInput(InputGroup
.this.inputNumber
);
1296 inputLabel
= new Label(labelComposite
, SWT
.NULL
);
1297 inputLabel
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
1298 inputLabel
.setText(Messages
.CustomTxtParserInputWizardPage_group
+ inputNumber
+ ":"); //$NON-NLS-1$
1300 tagComposite
= new Composite(parent
, SWT
.FILL
);
1301 GridLayout tagLayout
= new GridLayout(4, false);
1302 tagLayout
.marginWidth
= 0;
1303 tagLayout
.marginHeight
= 0;
1304 tagComposite
.setLayout(tagLayout
);
1305 tagComposite
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
1307 tagCombo
= new Combo(tagComposite
, SWT
.DROP_DOWN
| SWT
.READ_ONLY
);
1308 tagCombo
.setItems(new String
[] {CustomTxtTraceDefinition
.TAG_TIMESTAMP
,
1309 CustomTxtTraceDefinition
.TAG_MESSAGE
,
1310 CustomTxtTraceDefinition
.TAG_OTHER
});
1312 tagCombo
.addSelectionListener(new SelectionListener(){
1314 public void widgetDefaultSelected(SelectionEvent e
) {}
1316 public void widgetSelected(SelectionEvent e
) {
1317 tagText
.removeModifyListener(updateListener
);
1318 switch (tagCombo
.getSelectionIndex()) {
1319 case 0: //Time Stamp
1320 tagLabel
.setText(Messages
.CustomTxtParserInputWizardPage_format
);
1321 tagLabel
.setVisible(true);
1322 tagText
.setVisible(true);
1323 tagText
.addModifyListener(updateListener
);
1326 tagLabel
.setVisible(false);
1327 tagText
.setVisible(false);
1330 tagLabel
.setText(Messages
.CustomTxtParserInputWizardPage_name
);
1331 tagLabel
.setVisible(true);
1332 tagText
.setVisible(true);
1333 tagText
.addModifyListener(updateListener
);
1336 tagLabel
.setVisible(false);
1337 tagText
.setVisible(false);
1340 tagComposite
.layout();
1345 tagLabel
= new Label(tagComposite
, SWT
.NULL
);
1346 tagLabel
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
1347 tagLabel
.setVisible(false);
1349 tagText
= new Text(tagComposite
, SWT
.BORDER
| SWT
.SINGLE
);
1350 GridData gd
= new GridData(SWT
.FILL
, SWT
.CENTER
, true, false);
1352 tagText
.setLayoutData(gd
);
1353 tagText
.setVisible(false);
1355 actionCombo
= new Combo(tagComposite
, SWT
.DROP_DOWN
| SWT
.READ_ONLY
);
1356 actionCombo
.setItems(new String
[] {Messages
.CustomTxtParserInputWizardPage_set
, Messages
.CustomTxtParserInputWizardPage_append
, Messages
.CustomTxtParserInputWizardPage_appendWith
});
1357 actionCombo
.select(0);
1358 actionCombo
.addSelectionListener(updateListener
);
1360 previewLabel
= new Label(parent
, SWT
.NULL
);
1361 previewLabel
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
1362 previewLabel
.setText(Messages
.CustomTxtParserInputWizardPage_preview
);
1364 previewText
= new Text(parent
, SWT
.BORDER
| SWT
.SINGLE
| SWT
.READ_ONLY
);
1365 gd
= new GridData(SWT
.FILL
, SWT
.CENTER
, true, false);
1367 previewText
.setLayoutData(gd
);
1368 previewText
.setText(Messages
.CustomTxtParserInputWizardPage_noMatch
);
1369 previewText
.setBackground(COLOR_WIDGET_BACKGROUND
);
1372 private void dispose() {
1373 labelComposite
.dispose();
1374 tagComposite
.dispose();
1375 previewLabel
.dispose();
1376 previewText
.dispose();
1379 private void setInputNumber(int inputNumber
) {
1380 this.inputNumber
= inputNumber
;
1381 inputLabel
.setText(Messages
.CustomTxtParserInputWizardPage_group
+ inputNumber
+ ":"); //$NON-NLS-1$
1382 labelComposite
.layout();
1386 private void validate() {
1388 definition
.definitionName
= logtypeText
.getText().trim();
1389 definition
.timeStampOutputFormat
= timestampOutputFormatText
.getText().trim();
1391 if (selectedLine
!= null) {
1392 selectedLine
.extractInputs();
1393 treeViewer
.refresh();
1396 StringBuffer errors
= new StringBuffer();
1398 if (definition
.definitionName
.length() == 0) {
1399 errors
.append("Enter a name for the new log type. "); //$NON-NLS-1$
1400 logtypeText
.setBackground(COLOR_LIGHT_RED
);
1402 logtypeText
.setBackground(COLOR_TEXT_BACKGROUND
);
1403 for (CustomTxtTraceDefinition def
: CustomTxtTraceDefinition
.loadAll()) {
1404 if (definition
.definitionName
.equals(def
.definitionName
)) {
1405 if (editDefinitionName
== null || ! editDefinitionName
.equals(definition
.definitionName
)) {
1406 errors
.append("The log type name already exists. "); //$NON-NLS-1$
1407 logtypeText
.setBackground(COLOR_LIGHT_RED
);
1414 timestampFound
= false;
1415 for (int i
= 0; i
< definition
.inputs
.size(); i
++) {
1417 InputLine inputLine
= definition
.inputs
.get(i
);
1418 String name
= Integer
.toString(i
+1);
1419 errors
.append(validateLine(inputLine
, name
));
1421 if (timestampFound
) {
1422 if (definition
.timeStampOutputFormat
.length() == 0) {
1423 errors
.append("Enter the output format for the Time Stamp field. "); //$NON-NLS-1$
1424 timestampOutputFormatText
.setBackground(COLOR_LIGHT_RED
);
1427 new SimpleDateFormat(definition
.timeStampOutputFormat
);
1428 timestampOutputFormatText
.setBackground(COLOR_TEXT_BACKGROUND
);
1429 } catch (IllegalArgumentException e
) {
1430 errors
.append("Enter a valid output format for the Time Stamp field. "); //$NON-NLS-1$
1431 timestampOutputFormatText
.setBackground(COLOR_LIGHT_RED
);
1436 timestampOutputFormatText
.setBackground(COLOR_TEXT_BACKGROUND
);
1437 // timestampPreviewText.setBackground(COLOR_WIDGET_BACKGROUND);
1438 // errors.append("Identify a Time Stamp group (Line "+name+"). ");
1439 // timestampPreviewText.setText("*no timestamp group*");
1440 // timestampPreviewText.setBackground(COLOR_LIGHT_RED);
1443 if (errors
.length() == 0) {
1444 setDescription(defaultDescription
);
1445 setPageComplete(true);
1447 setDescription(errors
.toString());
1448 setPageComplete(false);
1452 public StringBuffer
validateLine(InputLine inputLine
, String name
) {
1453 StringBuffer errors
= new StringBuffer();
1455 if (selectedLine
!= null && selectedLine
.inputLine
.equals(inputLine
)) line
= selectedLine
;
1457 Pattern
.compile(inputLine
.getRegex());
1458 if (line
!= null) line
.regexText
.setBackground(COLOR_TEXT_BACKGROUND
);
1459 } catch (PatternSyntaxException e
) {
1460 errors
.append("Enter a valid regular expression (Line "+name
+"). "); //$NON-NLS-1$ //$NON-NLS-2$
1461 if (line
!= null) line
.regexText
.setBackground(COLOR_LIGHT_RED
);
1463 if (inputLine
.getMinCount() == -1) {
1464 errors
.append("Enter a minimum value for cardinality (Line "+name
+"). "); //$NON-NLS-1$ //$NON-NLS-2$
1465 if (line
!= null) line
.cardinalityMinText
.setBackground(COLOR_LIGHT_RED
);
1467 if (line
!= null) line
.cardinalityMinText
.setBackground(COLOR_TEXT_BACKGROUND
);
1469 if (inputLine
.getMaxCount() == -1) {
1470 errors
.append("Enter a maximum value for cardinality (Line "+name
+"). "); //$NON-NLS-1$ //$NON-NLS-2$
1471 if (line
!= null) line
.cardinalityMaxText
.setBackground(COLOR_LIGHT_RED
);
1472 } else if (inputLine
.getMinCount() > inputLine
.getMaxCount()) {
1473 errors
.append("Enter correct (min <= max) values for cardinality (Line "+name
+"). "); //$NON-NLS-1$ //$NON-NLS-2$
1474 if (line
!= null) line
.cardinalityMinText
.setBackground(COLOR_LIGHT_RED
);
1475 if (line
!= null) line
.cardinalityMaxText
.setBackground(COLOR_LIGHT_RED
);
1477 if (line
!= null) line
.cardinalityMaxText
.setBackground(COLOR_TEXT_BACKGROUND
);
1479 for (int i
= 0; inputLine
.columns
!= null && i
< inputLine
.columns
.size(); i
++) {
1480 InputData inputData
= inputLine
.columns
.get(i
);
1481 InputGroup group
= null;
1482 if (line
!= null) group
= line
.inputs
.get(i
);
1483 if (inputData
.name
.equals(CustomTxtTraceDefinition
.TAG_TIMESTAMP
)) {
1484 timestampFound
= true;
1485 if (inputData
.format
.length() == 0) {
1486 errors
.append("Enter the input format for the Time Stamp (Line "+name
+" Group "+(i
+1)+"). "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
1487 if (group
!= null) group
.tagText
.setBackground(COLOR_LIGHT_RED
);
1490 new SimpleDateFormat(inputData
.format
);
1491 if (group
!= null) group
.tagText
.setBackground(COLOR_TEXT_BACKGROUND
);
1492 } catch (IllegalArgumentException e
) {
1493 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$
1494 if (group
!= null) group
.tagText
.setBackground(COLOR_LIGHT_RED
);
1497 } else if (inputData
.name
.length() == 0) {
1498 errors
.append("Enter a name for the data group (Line "+name
+" Group "+(i
+1)+"). "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
1499 if (group
!= null) group
.tagText
.setBackground(COLOR_LIGHT_RED
);
1501 if (group
!= null) group
.tagText
.setBackground(COLOR_TEXT_BACKGROUND
);
1504 for (int i
= 0; inputLine
.childrenInputs
!= null && i
< inputLine
.childrenInputs
.size(); i
++) {
1505 errors
.append(validateLine(inputLine
.childrenInputs
.get(i
), name
+"."+(i
+1))); //$NON-NLS-1$
1510 public CustomTxtTraceDefinition
getDefinition() {
1514 public char[] getInputText() {
1515 return inputText
.getText().toCharArray();