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
.Activator
;
33 import org
.eclipse
.linuxtools
.internal
.tmf
.ui
.Messages
;
34 import org
.eclipse
.linuxtools
.internal
.tmf
.ui
.parsers
.custom
.CustomTraceDefinition
;
35 import org
.eclipse
.linuxtools
.internal
.tmf
.ui
.parsers
.custom
.CustomTxtTraceDefinition
;
36 import org
.eclipse
.linuxtools
.internal
.tmf
.ui
.parsers
.custom
.CustomTxtTraceDefinition
.Cardinality
;
37 import org
.eclipse
.linuxtools
.internal
.tmf
.ui
.parsers
.custom
.CustomTxtTraceDefinition
.InputData
;
38 import org
.eclipse
.linuxtools
.internal
.tmf
.ui
.parsers
.custom
.CustomTxtTraceDefinition
.InputLine
;
39 import org
.eclipse
.swt
.SWT
;
40 import org
.eclipse
.swt
.browser
.Browser
;
41 import org
.eclipse
.swt
.browser
.TitleEvent
;
42 import org
.eclipse
.swt
.browser
.TitleListener
;
43 import org
.eclipse
.swt
.custom
.SashForm
;
44 import org
.eclipse
.swt
.custom
.ScrolledComposite
;
45 import org
.eclipse
.swt
.custom
.StyleRange
;
46 import org
.eclipse
.swt
.custom
.StyledText
;
47 import org
.eclipse
.swt
.events
.ModifyEvent
;
48 import org
.eclipse
.swt
.events
.ModifyListener
;
49 import org
.eclipse
.swt
.events
.SelectionAdapter
;
50 import org
.eclipse
.swt
.events
.SelectionEvent
;
51 import org
.eclipse
.swt
.events
.SelectionListener
;
52 import org
.eclipse
.swt
.events
.VerifyEvent
;
53 import org
.eclipse
.swt
.events
.VerifyListener
;
54 import org
.eclipse
.swt
.graphics
.Color
;
55 import org
.eclipse
.swt
.graphics
.Font
;
56 import org
.eclipse
.swt
.graphics
.FontData
;
57 import org
.eclipse
.swt
.graphics
.Image
;
58 import org
.eclipse
.swt
.layout
.FillLayout
;
59 import org
.eclipse
.swt
.layout
.GridData
;
60 import org
.eclipse
.swt
.layout
.GridLayout
;
61 import org
.eclipse
.swt
.widgets
.Button
;
62 import org
.eclipse
.swt
.widgets
.Combo
;
63 import org
.eclipse
.swt
.widgets
.Composite
;
64 import org
.eclipse
.swt
.widgets
.Display
;
65 import org
.eclipse
.swt
.widgets
.Group
;
66 import org
.eclipse
.swt
.widgets
.Label
;
67 import org
.eclipse
.swt
.widgets
.Shell
;
68 import org
.eclipse
.swt
.widgets
.Text
;
70 public class CustomTxtParserInputWizardPage
extends WizardPage
{
72 private static final String DEFAULT_REGEX
= "\\s*(.*\\S)"; //$NON-NLS-1$
73 private static final String DEFAULT_TIMESTAMP_FORMAT
= "yyyy-MM-dd HH:mm:ss.SSS"; //$NON-NLS-1$
74 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$
75 private static final String PATTERN_URL
= "http://java.sun.com/javase/6/docs/api/java/util/regex/Pattern.html#sum"; //$NON-NLS-1$
76 private static final Image lineImage
= Activator
.getDefault().getImageFromPath("/icons/elcl16/line_icon.gif"); //$NON-NLS-1$
77 private static final Image addImage
= Activator
.getDefault().getImageFromPath("/icons/elcl16/add_button.gif"); //$NON-NLS-1$
78 private static final Image addNextImage
= Activator
.getDefault().getImageFromPath("/icons/elcl16/addnext_button.gif"); //$NON-NLS-1$
79 private static final Image addChildImage
= Activator
.getDefault().getImageFromPath("/icons/elcl16/addchild_button.gif"); //$NON-NLS-1$
80 private static final Image deleteImage
= Activator
.getDefault().getImageFromPath("/icons/elcl16/delete_button.gif"); //$NON-NLS-1$
81 private static final Image moveUpImage
= Activator
.getDefault().getImageFromPath("/icons/elcl16/moveup_button.gif"); //$NON-NLS-1$
82 private static final Image moveDownImage
= Activator
.getDefault().getImageFromPath("/icons/elcl16/movedown_button.gif"); //$NON-NLS-1$
83 private static final Image helpImage
= Activator
.getDefault().getImageFromPath("/icons/elcl16/help_button.gif"); //$NON-NLS-1$
84 private static final Color COLOR_BLACK
= Display
.getCurrent().getSystemColor(SWT
.COLOR_BLACK
);
85 private static final Color COLOR_LIGHT_GREEN
= new Color(Display
.getDefault(), 192, 255, 192);
86 private static final Color COLOR_GREEN
= Display
.getCurrent().getSystemColor(SWT
.COLOR_GREEN
);
87 private static final Color COLOR_LIGHT_YELLOW
= new Color(Display
.getDefault(), 255, 255, 192);
88 private static final Color COLOR_YELLOW
= Display
.getCurrent().getSystemColor(SWT
.COLOR_YELLOW
);
89 private static final Color COLOR_LIGHT_MAGENTA
= new Color(Display
.getDefault(), 255, 192, 255);
90 private static final Color COLOR_MAGENTA
= Display
.getCurrent().getSystemColor(SWT
.COLOR_MAGENTA
);
91 private static final Color COLOR_LIGHT_RED
= new Color(Display
.getDefault(), 255, 192, 192);
92 private static final Color COLOR_TEXT_BACKGROUND
= Display
.getCurrent().getSystemColor(SWT
.COLOR_WHITE
);
93 private static final Color COLOR_WIDGET_BACKGROUND
= Display
.getCurrent().getSystemColor(SWT
.COLOR_WIDGET_BACKGROUND
);
95 private final ISelection selection
;
96 private CustomTxtTraceDefinition definition
;
97 private String editDefinitionName
;
98 private String defaultDescription
;
99 private Line selectedLine
;
100 private Composite container
;
101 private Text logtypeText
;
102 private Text timestampOutputFormatText
;
103 private Text timestampPreviewText
;
104 private ScrolledComposite treeScrolledComposite
;
105 private ScrolledComposite lineScrolledComposite
;
106 private TreeViewer treeViewer
;
107 private Composite treeContainer
;
108 private Composite lineContainer
;
109 private StyledText inputText
;
110 private Font fixedFont
;
111 private UpdateListener updateListener
;
112 private Browser helpBrowser
;
114 // variables used recursively through line traversal
115 private String timeStampFormat
;
116 private boolean timestampFound
;
118 protected CustomTxtParserInputWizardPage(ISelection selection
, CustomTxtTraceDefinition definition
) {
119 super("CustomParserWizardPage"); //$NON-NLS-1$
120 if (definition
== null) {
121 setTitle(Messages
.CustomTxtParserInputWizardPage_windowTitleNew
);
122 defaultDescription
= Messages
.CustomTxtParserInputWizardPage_descriptionNew
;
124 setTitle(Messages
.CustomTxtParserInputWizardPage_windowTitleEdit
);
125 defaultDescription
= Messages
.CustomTxtParserInputWizardPage_desccriptionEdit
;
127 setDescription(defaultDescription
);
128 this.selection
= selection
;
129 this.definition
= definition
;
130 if (definition
!= null) {
131 this.editDefinitionName
= definition
.definitionName
;
136 public void createControl(Composite parent
) {
137 container
= new Composite(parent
, SWT
.NULL
);
138 container
.setLayout(new GridLayout());
140 updateListener
= new UpdateListener();
142 Composite headerComposite
= new Composite(container
, SWT
.FILL
);
143 GridLayout headerLayout
= new GridLayout(5, false);
144 headerLayout
.marginHeight
= 0;
145 headerLayout
.marginWidth
= 0;
146 headerComposite
.setLayout(headerLayout
);
147 headerComposite
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
149 Label logtypeLabel
= new Label(headerComposite
, SWT
.NULL
);
150 logtypeLabel
.setText(Messages
.CustomTxtParserInputWizardPage_logType
);
152 logtypeText
= new Text(headerComposite
, SWT
.BORDER
| SWT
.SINGLE
);
153 logtypeText
.setLayoutData(new GridData(120, SWT
.DEFAULT
));
155 Label timestampFormatLabel
= new Label(headerComposite
, SWT
.NULL
);
156 timestampFormatLabel
.setText(Messages
.CustomTxtParserInputWizardPage_timestampFormat
);
158 timestampOutputFormatText
= new Text(headerComposite
, SWT
.BORDER
| SWT
.SINGLE
);
159 timestampOutputFormatText
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
160 timestampOutputFormatText
.setText(DEFAULT_TIMESTAMP_FORMAT
);
162 Button dateFormatHelpButton
= new Button(headerComposite
, SWT
.PUSH
);
163 dateFormatHelpButton
.setImage(helpImage
);
164 dateFormatHelpButton
.setToolTipText(Messages
.CustomTxtParserInputWizardPage_dateFormatHelp
);
165 dateFormatHelpButton
.addSelectionListener(new SelectionAdapter() {
167 public void widgetSelected(SelectionEvent e
) {
168 openHelpShell(SIMPLE_DATE_FORMAT_URL
);
172 Label timestampPreviewLabel
= new Label(headerComposite
, SWT
.NULL
);
173 timestampPreviewLabel
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false, 3, 1));
174 timestampPreviewLabel
.setText(Messages
.CustomTxtParserInputWizardPage_preview
);
176 timestampPreviewText
= new Text(headerComposite
, SWT
.BORDER
| SWT
.SINGLE
| SWT
.READ_ONLY
);
177 timestampPreviewText
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false, 2, 1));
178 timestampPreviewText
.setText(Messages
.CustomTxtParserInputWizardPage_noMatchingTimestamp
);
180 Composite buttonBar
= new Composite(container
, SWT
.NONE
);
181 GridLayout buttonBarLayout
= new GridLayout(5, false);
182 buttonBarLayout
.marginHeight
= 0;
183 buttonBarLayout
.marginWidth
= 0;
184 buttonBar
.setLayout(buttonBarLayout
);
186 Button removeButton
= new Button(buttonBar
, SWT
.PUSH
);
187 removeButton
.setImage(deleteImage
);
188 removeButton
.setToolTipText(Messages
.CustomTxtParserInputWizardPage_removeLine
);
189 removeButton
.addSelectionListener(new SelectionAdapter() {
191 public void widgetSelected(SelectionEvent e
) {
192 if (treeViewer
.getSelection().isEmpty() || selectedLine
== null) {
196 InputLine inputLine
= (InputLine
) ((IStructuredSelection
) treeViewer
.getSelection()).getFirstElement();
197 if (inputLine
.parentInput
== null) {
198 definition
.inputs
.remove(inputLine
);
200 inputLine
.parentInput
.childrenInputs
.remove(inputLine
);
202 treeViewer
.refresh();
207 Button addNextButton
= new Button(buttonBar
, SWT
.PUSH
);
208 addNextButton
.setImage(addNextImage
);
209 addNextButton
.setToolTipText(Messages
.CustomTxtParserInputWizardPage_addNextLine
);
210 addNextButton
.addSelectionListener(new SelectionAdapter() {
212 public void widgetSelected(SelectionEvent e
) {
213 InputLine inputLine
= new InputLine(Cardinality
.ZERO_OR_MORE
, "", null); //$NON-NLS-1$
214 if (((List
<?
>) treeViewer
.getInput()).size() == 0) {
215 definition
.inputs
.add(inputLine
);
216 } else if (treeViewer
.getSelection().isEmpty()) {
219 InputLine previousInputLine
= (InputLine
) ((IStructuredSelection
) treeViewer
.getSelection()).getFirstElement();
220 if (previousInputLine
.parentInput
== null) {
221 for (int i
= 0; i
< definition
.inputs
.size(); i
++) {
222 if (definition
.inputs
.get(i
).equals(previousInputLine
)) {
223 definition
.inputs
.add(i
+ 1, inputLine
);
227 previousInputLine
.addNext(inputLine
);
230 treeViewer
.refresh();
231 treeViewer
.setSelection(new StructuredSelection(inputLine
), true);
234 Button addChildButton
= new Button(buttonBar
, SWT
.PUSH
);
235 addChildButton
.setImage(addChildImage
);
236 addChildButton
.setToolTipText(Messages
.CustomTxtParserInputWizardPage_addChildLine
);
237 addChildButton
.addSelectionListener(new SelectionAdapter() {
239 public void widgetSelected(SelectionEvent e
) {
240 InputLine inputLine
= new InputLine(Cardinality
.ZERO_OR_MORE
, "", null); //$NON-NLS-1$
241 if (((List
<?
>) treeViewer
.getInput()).size() == 0) {
242 definition
.inputs
.add(inputLine
);
243 } else if (treeViewer
.getSelection().isEmpty()) {
246 InputLine parentInputLine
= (InputLine
) ((IStructuredSelection
) treeViewer
.getSelection()).getFirstElement();
247 parentInputLine
.addChild(inputLine
);
249 treeViewer
.refresh();
250 treeViewer
.setSelection(new StructuredSelection(inputLine
), true);
253 Button moveUpButton
= new Button(buttonBar
, SWT
.PUSH
);
254 moveUpButton
.setImage(moveUpImage
);
255 moveUpButton
.setToolTipText(Messages
.CustomTxtParserInputWizardPage_moveUp
);
256 moveUpButton
.addSelectionListener(new SelectionAdapter() {
258 public void widgetSelected(SelectionEvent e
) {
259 if (treeViewer
.getSelection().isEmpty()) {
262 InputLine inputLine
= (InputLine
) ((IStructuredSelection
) treeViewer
.getSelection()).getFirstElement();
263 if (inputLine
.parentInput
== null) {
264 for (int i
= 1; i
< definition
.inputs
.size(); i
++) {
265 if (definition
.inputs
.get(i
).equals(inputLine
)) {
266 definition
.inputs
.add(i
- 1 , definition
.inputs
.remove(i
));
273 treeViewer
.refresh();
278 Button moveDownButton
= new Button(buttonBar
, SWT
.PUSH
);
279 moveDownButton
.setImage(moveDownImage
);
280 moveDownButton
.setToolTipText(Messages
.CustomTxtParserInputWizardPage_moveDown
);
281 moveDownButton
.addSelectionListener(new SelectionAdapter() {
283 public void widgetSelected(SelectionEvent e
) {
284 if (treeViewer
.getSelection().isEmpty()) {
287 InputLine inputLine
= (InputLine
) ((IStructuredSelection
) treeViewer
.getSelection()).getFirstElement();
288 if (inputLine
.parentInput
== null) {
289 for (int i
= 0; i
< definition
.inputs
.size() - 1; i
++) {
290 if (definition
.inputs
.get(i
).equals(inputLine
)) {
291 definition
.inputs
.add(i
+ 1 , definition
.inputs
.remove(i
));
296 inputLine
.moveDown();
298 treeViewer
.refresh();
304 SashForm vSash
= new SashForm(container
, SWT
.VERTICAL
);
305 vSash
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
306 vSash
.setBackground(vSash
.getDisplay().getSystemColor(SWT
.COLOR_GRAY
));
308 SashForm hSash
= new SashForm(vSash
, SWT
.HORIZONTAL
);
309 hSash
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
311 treeScrolledComposite
= new ScrolledComposite(hSash
, SWT
.V_SCROLL
| SWT
.H_SCROLL
);
312 GridData gd
= new GridData(SWT
.FILL
, SWT
.FILL
, true, true);
315 treeScrolledComposite
.setLayoutData(gd
);
316 treeContainer
= new Composite(treeScrolledComposite
, SWT
.NONE
);
317 treeContainer
.setLayout(new FillLayout());
318 treeScrolledComposite
.setContent(treeContainer
);
319 treeScrolledComposite
.setExpandHorizontal(true);
320 treeScrolledComposite
.setExpandVertical(true);
322 treeViewer
= new TreeViewer(treeContainer
, SWT
.SINGLE
| SWT
.BORDER
);
323 treeViewer
.setContentProvider(new InputLineTreeNodeContentProvider());
324 treeViewer
.setLabelProvider(new InputLineTreeLabelProvider());
325 treeViewer
.addSelectionChangedListener(new InputLineTreeSelectionChangedListener());
326 treeContainer
.layout();
328 treeScrolledComposite
.setMinSize(treeContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).x
, treeContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).y
);
330 lineScrolledComposite
= new ScrolledComposite(hSash
, SWT
.V_SCROLL
);
331 lineScrolledComposite
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
332 lineContainer
= new Composite(lineScrolledComposite
, SWT
.NONE
);
333 GridLayout linesLayout
= new GridLayout();
334 linesLayout
.marginHeight
= 1;
335 linesLayout
.marginWidth
= 0;
336 lineContainer
.setLayout(linesLayout
);
337 lineScrolledComposite
.setContent(lineContainer
);
338 lineScrolledComposite
.setExpandHorizontal(true);
339 lineScrolledComposite
.setExpandVertical(true);
341 if (definition
== null) {
342 definition
= new CustomTxtTraceDefinition();
343 definition
.inputs
.add(new InputLine(Cardinality
.ZERO_OR_MORE
, DEFAULT_REGEX
,
344 Arrays
.asList(new InputData(CustomTraceDefinition
.TAG_MESSAGE
, CustomTraceDefinition
.ACTION_SET
))));
346 loadDefinition(definition
);
347 treeViewer
.expandAll();
348 lineContainer
.layout();
350 logtypeText
.addModifyListener(updateListener
);
351 timestampOutputFormatText
.addModifyListener(updateListener
);
353 lineScrolledComposite
.setMinSize(lineContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).x
, lineContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).y
-1);
355 hSash
.setWeights(new int[] {1, 2});
357 Composite sashBottom
= new Composite(vSash
, SWT
.NONE
);
358 GridLayout sashBottomLayout
= new GridLayout(3, false);
359 sashBottomLayout
.marginHeight
= 0;
360 sashBottomLayout
.marginWidth
= 0;
361 sashBottom
.setLayout(sashBottomLayout
);
363 Label previewLabel
= new Label(sashBottom
, SWT
.NULL
);
364 previewLabel
.setText(Messages
.CustomTxtParserInputWizardPage_previewInput
);
365 previewLabel
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
367 Button highlightAllButton
= new Button(sashBottom
, SWT
.PUSH
);
368 highlightAllButton
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
369 highlightAllButton
.setText(Messages
.CustomTxtParserInputWizardPage_highlightAll
);
370 highlightAllButton
.addSelectionListener(new SelectionAdapter() {
372 public void widgetSelected(SelectionEvent e
) {
373 updatePreviews(true);
377 Button legendButton
= new Button(sashBottom
, SWT
.PUSH
);
378 legendButton
.setImage(helpImage
);
379 legendButton
.setToolTipText(Messages
.CustomTxtParserInputWizardPage_previewLegend
);
380 legendButton
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
381 legendButton
.addSelectionListener(new SelectionAdapter() {
383 public void widgetSelected(SelectionEvent e
) {
388 inputText
= new StyledText(sashBottom
, SWT
.MULTI
| SWT
.V_SCROLL
| SWT
.H_SCROLL
);
389 if (fixedFont
== null) {
390 if (System
.getProperty("os.name").contains("Windows")) { //$NON-NLS-1$ //$NON-NLS-2$
391 fixedFont
= new Font(Display
.getCurrent(), new FontData("Courier New", 10, SWT
.NORMAL
)); //$NON-NLS-1$
393 fixedFont
= new Font(Display
.getCurrent(), new FontData("Monospace", 10, SWT
.NORMAL
)); //$NON-NLS-1$
396 inputText
.setFont(fixedFont
);
397 gd
= new GridData(SWT
.FILL
, SWT
.FILL
, true, true, 3, 1);
398 gd
.heightHint
= inputText
.computeSize(SWT
.DEFAULT
, inputText
.getLineHeight() * 4).y
;
400 inputText
.setLayoutData(gd
);
401 inputText
.setText(getSelectionText());
402 inputText
.addModifyListener(updateListener
);
404 vSash
.setWeights(new int[] {hSash
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).y
, sashBottom
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).y
});
406 setControl(container
);
412 private static class InputLineTreeNodeContentProvider
implements ITreeContentProvider
{
415 public Object
[] getElements(Object inputElement
) {
416 return ((List
<?
>) inputElement
).toArray();
420 public Object
[] getChildren(Object parentElement
) {
421 InputLine inputLine
= (InputLine
) parentElement
;
422 if (inputLine
.childrenInputs
== null) {
423 return new InputLine
[0];
425 return inputLine
.childrenInputs
.toArray();
429 public boolean hasChildren(Object element
) {
430 InputLine inputLine
= (InputLine
) element
;
431 return (inputLine
.childrenInputs
!= null && inputLine
.childrenInputs
.size() > 0);
435 public void dispose() {
439 public void inputChanged(Viewer viewer
, Object oldInput
, Object newInput
) {
443 public Object
getParent(Object element
) {
444 InputLine inputLine
= (InputLine
) element
;
445 return inputLine
.parentInput
;
449 private class InputLineTreeLabelProvider
extends ColumnLabelProvider
{
452 public Image
getImage(Object element
) {
457 public String
getText(Object element
) {
458 InputLine inputLine
= (InputLine
) element
;
459 if (inputLine
.parentInput
== null) {
460 return "Root Line " + getName(inputLine
) + " " + inputLine
.cardinality
.toString() + " : " + inputLine
.getRegex(); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
462 return "Line " + getName(inputLine
) + " " + inputLine
.cardinality
.toString() + " : " + inputLine
.getRegex(); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
466 private class InputLineTreeSelectionChangedListener
implements ISelectionChangedListener
{
468 public void selectionChanged(SelectionChangedEvent event
) {
469 if (selectedLine
!= null) {
470 selectedLine
.dispose();
472 if (!(event
.getSelection().isEmpty()) && event
.getSelection() instanceof IStructuredSelection
) {
473 IStructuredSelection selection
= (IStructuredSelection
) event
.getSelection();
474 InputLine inputLine
= (InputLine
) selection
.getFirstElement();
475 selectedLine
= new Line(lineContainer
, getName(inputLine
), inputLine
);
476 lineContainer
.layout();
477 lineScrolledComposite
.setMinSize(lineContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).x
, lineContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).y
-1);
486 * @see org.eclipse.jface.dialogs.DialogPage#dispose()
489 public void dispose() {
490 if (fixedFont
!= null) {
497 private void loadDefinition(CustomTxtTraceDefinition def
) {
498 logtypeText
.setText(def
.definitionName
);
499 timestampOutputFormatText
.setText(def
.timeStampOutputFormat
);
500 treeViewer
.setInput(def
.inputs
);
501 if (def
.inputs
.size() > 0) {
502 InputLine inputLine
= def
.inputs
.get(0);
503 treeViewer
.setSelection(new StructuredSelection(inputLine
));
507 private String
getName(InputLine inputLine
) {
508 if (inputLine
.parentInput
== null) {
509 return Integer
.toString(definition
.inputs
.indexOf(inputLine
)+1);
511 return getName(inputLine
.parentInput
) + "." + Integer
.toString(inputLine
.parentInput
.childrenInputs
.indexOf(inputLine
)+1); //$NON-NLS-1$
514 public List
<String
> getInputNames() {
515 List
<String
> inputs
= new ArrayList
<String
>();
516 for (InputLine inputLine
: definition
.inputs
) {
517 for (String inputName
: getInputNames(inputLine
)) {
518 if (!inputs
.contains(inputName
)) {
519 inputs
.add(inputName
);
526 public List
<String
> getInputNames(InputLine inputLine
) {
527 List
<String
> inputs
= new ArrayList
<String
>();
528 if (inputLine
.columns
!= null) {
529 for (InputData inputData
: inputLine
.columns
) {
530 String inputName
= inputData
.name
;
531 if (!inputs
.contains(inputName
)) {
532 inputs
.add(inputName
);
536 if (inputLine
.childrenInputs
!= null) {
537 for (InputLine childInputLine
: inputLine
.childrenInputs
) {
538 for (String inputName
: getInputNames(childInputLine
)) {
539 if (!inputs
.contains(inputName
)) {
540 inputs
.add(inputName
);
548 private void removeLine() {
549 selectedLine
.dispose();
551 lineContainer
.layout();
552 lineScrolledComposite
.setMinSize(lineContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).x
, lineContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).y
-1);
556 private String
getSelectionText() {
557 if (this.selection
instanceof IStructuredSelection
) {
558 Object selection
= ((IStructuredSelection
)this.selection
).getFirstElement();
559 if (selection
instanceof IFile
) {
560 IFile file
= (IFile
)selection
;
561 BufferedReader reader
= null;
563 reader
= new BufferedReader(new InputStreamReader(file
.getContents()));
564 StringBuilder sb
= new StringBuilder();
566 while ((line
= reader
.readLine()) != null) {
567 sb
.append(line
+ "\n"); //$NON-NLS-1$
569 return sb
.toString();
570 } catch (CoreException e
) {
571 return ""; //$NON-NLS-1$
572 } catch (IOException e
) {
573 return ""; //$NON-NLS-1$
575 if (reader
!= null) {
578 } catch (IOException e
) {
584 return ""; //$NON-NLS-1$
587 private void updatePreviews() {
588 updatePreviews(false);
591 private void updatePreviews(boolean updateAll
) {
592 if (inputText
== null) {
593 // early update during construction
596 inputText
.setStyleRanges(new StyleRange
[] {});
598 Scanner scanner
= new Scanner(inputText
.getText());
599 scanner
.useDelimiter("\n"); //$NON-NLS-1$
601 String skip
; // skip starting delimiters
602 if ((skip
= scanner
.findWithinHorizon("\\A\n+", 0)) != null) { //$NON-NLS-1$
603 rawPos
+= skip
.length();
606 timeStampFormat
= null;
607 if (selectedLine
!= null) {
608 for (InputGroup input
: selectedLine
.inputs
) {
609 input
.previewText
.setText(Messages
.CustomTxtParserInputWizardPage_noMathcingLine
);
613 Map
<String
, String
> data
= new HashMap
<String
, String
>();
614 int rootLineMatches
= 0;
615 String firstEntryTimeStamp
= null;
616 String firstEntryTimeStampInputFormat
= null;
619 while (scanner
.hasNext()) {
620 if (rootLineMatches
> 0 && !updateAll
) {
624 log
= scanner
.next();
626 int length
= log
.length();
627 for (InputLine rootInputLine
: definition
.inputs
) {
630 pattern
= rootInputLine
.getPattern();
631 } catch (PatternSyntaxException e
) {
634 Matcher matcher
= pattern
.matcher(log
);
635 if (matcher
.find()) {
637 inputText
.setStyleRange(new StyleRange(rawPos
, length
,
638 COLOR_BLACK
, COLOR_YELLOW
, SWT
.ITALIC
));
639 data
= new HashMap
<String
, String
>();
640 timeStampFormat
= null;
641 updatePreviewLine(rootInputLine
, matcher
, data
, rawPos
, rootLineMatches
);
642 if (rootLineMatches
== 1) {
643 firstEntryTimeStamp
= data
.get(CustomTraceDefinition
.TAG_TIMESTAMP
);
644 firstEntryTimeStampInputFormat
= timeStampFormat
;
646 HashMap
<InputLine
, Integer
> countMap
= new HashMap
<InputLine
, Integer
>();
647 InputLine currentInput
= null;
648 if (rootInputLine
.childrenInputs
!= null && rootInputLine
.childrenInputs
.size() > 0) {
649 currentInput
= rootInputLine
.childrenInputs
.get(0);
650 countMap
.put(currentInput
, 0);
652 rawPos
+= length
+ 1; // +1 for \n
653 while (scanner
.hasNext()) {
654 log
= scanner
.next();
655 length
= log
.length();
656 boolean processed
= false;
657 if (currentInput
== null) {
658 for (InputLine input
: definition
.inputs
) {
659 matcher
= input
.getPattern().matcher(log
);
660 if (matcher
.find()) {
665 if (countMap
.get(currentInput
) >= currentInput
.getMinCount()) {
666 List
<InputLine
> nextInputs
= currentInput
.getNextInputs(countMap
);
667 if (nextInputs
.size() == 0 || nextInputs
.get(nextInputs
.size() - 1).getMinCount() == 0) {
668 for (InputLine input
: definition
.inputs
) {
669 matcher
= input
.getPattern().matcher(log
);
670 if (matcher
.find()) {
675 for (InputLine input
: nextInputs
) {
676 matcher
= input
.getPattern().matcher(log
);
677 if (matcher
.find()) {
678 inputText
.setStyleRange(new StyleRange(rawPos
, length
,
679 COLOR_BLACK
, COLOR_LIGHT_YELLOW
, SWT
.ITALIC
));
680 currentInput
= input
;
681 updatePreviewLine(currentInput
, matcher
, data
, rawPos
, rootLineMatches
);
682 if (countMap
.get(currentInput
) == null) {
683 countMap
.put(currentInput
, 1);
685 countMap
.put(currentInput
, countMap
.get(currentInput
) + 1);
687 Iterator
<InputLine
> iter
= countMap
.keySet().iterator();
688 while (iter
.hasNext()) {
689 InputLine inputLine
= iter
.next();
690 if (inputLine
.level
> currentInput
.level
) {
694 if (currentInput
.childrenInputs
!= null && currentInput
.childrenInputs
.size() > 0) {
695 currentInput
= currentInput
.childrenInputs
.get(0);
696 countMap
.put(currentInput
, 0);
698 if (countMap
.get(currentInput
) >= currentInput
.getMaxCount()) {
699 if (currentInput
.getNextInputs(countMap
).size() > 0) {
700 currentInput
= currentInput
.getNextInputs(countMap
).get(0);
701 if (countMap
.get(currentInput
) == null) {
702 countMap
.put(currentInput
, 0);
704 iter
= countMap
.keySet().iterator();
705 while (iter
.hasNext()) {
706 InputLine inputLine
= iter
.next();
707 if (inputLine
.level
> currentInput
.level
) {
722 matcher
= currentInput
.getPattern().matcher(log
);
723 if (matcher
.find()) {
724 inputText
.setStyleRange(new StyleRange(rawPos
, length
,
725 COLOR_BLACK
, COLOR_LIGHT_YELLOW
, SWT
.ITALIC
));
726 updatePreviewLine(currentInput
, matcher
, data
, rawPos
, rootLineMatches
);
727 countMap
.put(currentInput
, countMap
.get(currentInput
) + 1);
728 if (currentInput
.childrenInputs
!= null && currentInput
.childrenInputs
.size() > 0) {
729 currentInput
= currentInput
.childrenInputs
.get(0);
730 countMap
.put(currentInput
, 0);
732 if (countMap
.get(currentInput
) >= currentInput
.getMaxCount()) {
733 if (currentInput
.getNextInputs(countMap
).size() > 0) {
734 currentInput
= currentInput
.getNextInputs(countMap
).get(0);
735 if (countMap
.get(currentInput
) == null) {
736 countMap
.put(currentInput
, 0);
738 Iterator
<InputLine
> iter
= countMap
.keySet().iterator();
739 while (iter
.hasNext()) {
740 InputLine inputLine
= iter
.next();
741 if (inputLine
.level
> currentInput
.level
) {
753 rawPos
+= length
+ 1; // +1 for \n
759 rawPos
+= length
+ 1; // +1 for \n
763 if (rootLineMatches
== 1) {
764 firstEntryTimeStamp
= data
.get(CustomTraceDefinition
.TAG_TIMESTAMP
);
765 firstEntryTimeStampInputFormat
= timeStampFormat
;
767 if (firstEntryTimeStamp
== null) {
768 timestampPreviewText
.setText(Messages
.CustomTxtParserInputWizardPage_noTimestampGroup
);
769 if (selectedLine
!= null) {
770 for (InputGroup group
: selectedLine
.inputs
) {
771 if (group
.tagCombo
.getText().equals(CustomTraceDefinition
.TAG_TIMESTAMP
)) {
772 timestampPreviewText
.setText(Messages
.CustomTxtParserInputWizardPage_noMatchingTimestamp
);
779 SimpleDateFormat dateFormat
= new SimpleDateFormat(firstEntryTimeStampInputFormat
);
780 Date date
= dateFormat
.parse(firstEntryTimeStamp
);
781 dateFormat
= new SimpleDateFormat(timestampOutputFormatText
.getText().trim());
782 timestampPreviewText
.setText(dateFormat
.format(date
));
783 } catch (ParseException e
) {
784 timestampPreviewText
.setText("*parse exception* [" + firstEntryTimeStamp
+ "] <> [" + firstEntryTimeStampInputFormat
+ "]"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
785 } catch (IllegalArgumentException e
) {
786 timestampPreviewText
.setText("*parse exception* [Illegal Argument]"); //$NON-NLS-1$
792 private void updatePreviewLine(InputLine line
, Matcher matcher
, Map
<String
, String
> data
, int rawPos
, int rootLineMatches
) {
793 for (int i
= 0; i
< line
.columns
.size(); i
++) {
794 InputData input
= line
.columns
.get(i
);
795 if (i
< matcher
.groupCount() && matcher
.group(i
+1) != null) {
796 if (line
.parentInput
== null) {
797 inputText
.setStyleRange(new StyleRange(rawPos
+ matcher
.start(i
+1), matcher
.end(i
+1) - matcher
.start(i
+1),
798 COLOR_BLACK
, COLOR_GREEN
, SWT
.BOLD
));
800 inputText
.setStyleRange(new StyleRange(rawPos
+ matcher
.start(i
+1), matcher
.end(i
+1) - matcher
.start(i
+1),
801 COLOR_BLACK
, COLOR_LIGHT_GREEN
, SWT
.BOLD
));
803 String value
= matcher
.group(i
+1).trim();
804 if (selectedLine
!= null && selectedLine
.inputLine
.equals(line
) && rootLineMatches
== 1) {
805 if (selectedLine
.inputs
.get(i
).previewText
.getText().equals(Messages
.CustomTxtParserInputWizardPage_noMatchingLine
)) {
806 selectedLine
.inputs
.get(i
).previewText
.setText(value
);
809 if (value
.length() == 0) {
812 if (input
.action
== CustomTraceDefinition
.ACTION_SET
) {
813 data
.put(input
.name
, value
);
814 if (input
.name
.equals(CustomTraceDefinition
.TAG_TIMESTAMP
)) {
815 timeStampFormat
= input
.format
;
817 } else if (input
.action
== CustomTraceDefinition
.ACTION_APPEND
) {
818 String s
= data
.get(input
.name
);
820 data
.put(input
.name
, s
+ value
);
822 data
.put(input
.name
, value
);
824 if (input
.name
.equals(CustomTraceDefinition
.TAG_TIMESTAMP
)) {
825 if (timeStampFormat
!= null) {
826 timeStampFormat
+= input
.format
;
828 timeStampFormat
= input
.format
;
831 } else if (input
.action
== CustomTraceDefinition
.ACTION_APPEND_WITH_SEPARATOR
) {
832 String s
= data
.get(input
.name
);
834 data
.put(input
.name
, s
+ " | " + value
); //$NON-NLS-1$
836 data
.put(input
.name
, value
);
838 if (input
.name
.equals(CustomTraceDefinition
.TAG_TIMESTAMP
)) {
839 if (timeStampFormat
!= null) {
840 timeStampFormat
+= " | " + input
.format
; //$NON-NLS-1$
842 timeStampFormat
= input
.format
;
847 if (selectedLine
!= null && selectedLine
.inputLine
.equals(line
) && rootLineMatches
== 1) {
848 if (selectedLine
.inputs
.get(i
).previewText
.getText().equals(Messages
.CustomTxtParserInputWizardPage_noMatchingLine
)) {
849 selectedLine
.inputs
.get(i
).previewText
.setText(Messages
.CustomTxtParserInputWizardPage_noMatchingGroup
);
854 // highlight the matching groups that have no corresponponding input
855 for (int i
= line
.columns
.size(); i
< matcher
.groupCount(); i
++) {
856 if (matcher
.group(i
+1) != null) {
857 if (line
.parentInput
== null) {
858 inputText
.setStyleRange(new StyleRange(rawPos
+ matcher
.start(i
+1), matcher
.end(i
+1) - matcher
.start(i
+1),
859 COLOR_BLACK
, COLOR_MAGENTA
));
861 inputText
.setStyleRange(new StyleRange(rawPos
+ matcher
.start(i
+1), matcher
.end(i
+1) - matcher
.start(i
+1),
862 COLOR_BLACK
, COLOR_LIGHT_MAGENTA
));
868 private void openHelpShell(String url
) {
869 if (helpBrowser
!= null && !helpBrowser
.isDisposed()) {
870 helpBrowser
.getShell().setActive();
871 if (!helpBrowser
.getUrl().equals(url
)) {
872 helpBrowser
.setUrl(url
);
876 final Shell helpShell
= new Shell(getShell(), SWT
.SHELL_TRIM
);
877 helpShell
.setLayout(new FillLayout());
878 helpBrowser
= new Browser(helpShell
, SWT
.NONE
);
879 helpBrowser
.addTitleListener(new TitleListener() {
881 public void changed(TitleEvent event
) {
882 helpShell
.setText(event
.title
);
885 helpBrowser
.setBounds(0,0,600,400);
888 helpBrowser
.setUrl(url
);
891 private void openLegend() {
892 final String CG
= Messages
.CustomTxtParserInputWizardPage_capturedGroup
;
893 final String UCG
= Messages
.CustomTxtParserInputWizardPage_unidentifiedCaptureGroup
;
894 final String UT
= Messages
.CustomTxtParserInputWizardPage_uncapturedText
;
896 String line1
= Messages
.CustomTxtParserInputWizardPage_nonMatchingLine
;
897 int line2start
= line1start
+ line1
.length();
898 String line2
= Messages
.CustomTxtParserInputWizardPage_matchingLineRoot
+ CG
+ " " + UCG
+ " " + UT
+ " \n"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
899 int line3start
= line2start
+ line2
.length();
900 String line3
= Messages
.CustomTxtParserInputWizardPage_matchingOtherLine
+ CG
+ " " + UCG
+ " " + UT
+ " \n"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
901 int line4start
= line3start
+ line3
.length();
902 String line4
= Messages
.CustomTxtParserInputWizardPage_matchingOtherLine
+ CG
+ " " + UCG
+ " " + UT
+ " \n"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
903 int line5start
= line4start
+ line4
.length();
904 String line5
= Messages
.CustomTxtParserInputWizardPage_nonMatchingLine
;
905 int line6start
= line5start
+ line5
.length();
906 String line6
= Messages
.CustomTxtParserInputWizardPage_matchingRootLine
+ CG
+ " " + UCG
+ " " + UT
+ " \n"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
908 final Shell legendShell
= new Shell(getShell(), SWT
.DIALOG_TRIM
);
909 legendShell
.setLayout(new FillLayout());
910 StyledText legendText
= new StyledText(legendShell
, SWT
.MULTI
);
911 legendText
.setFont(fixedFont
);
912 legendText
.setText(line1
+ line2
+ line3
+ line4
+ line5
+ line6
);
913 legendText
.setStyleRange(new StyleRange(line2start
, line2
.length(), COLOR_BLACK
, COLOR_YELLOW
, SWT
.ITALIC
));
914 legendText
.setStyleRange(new StyleRange(line3start
, line3
.length(), COLOR_BLACK
, COLOR_LIGHT_YELLOW
, SWT
.ITALIC
));
915 legendText
.setStyleRange(new StyleRange(line4start
, line4
.length(), COLOR_BLACK
, COLOR_LIGHT_YELLOW
, SWT
.ITALIC
));
916 legendText
.setStyleRange(new StyleRange(line6start
, line6
.length(), COLOR_BLACK
, COLOR_YELLOW
, SWT
.ITALIC
));
917 legendText
.setStyleRange(new StyleRange(line2start
+ line2
.indexOf(CG
), CG
.length(), COLOR_BLACK
, COLOR_GREEN
, SWT
.BOLD
));
918 legendText
.setStyleRange(new StyleRange(line2start
+ line2
.indexOf(UCG
), UCG
.length(), COLOR_BLACK
, COLOR_MAGENTA
));
919 legendText
.setStyleRange(new StyleRange(line3start
+ line3
.indexOf(CG
), CG
.length(), COLOR_BLACK
, COLOR_LIGHT_GREEN
, SWT
.BOLD
));
920 legendText
.setStyleRange(new StyleRange(line3start
+ line3
.indexOf(UCG
), UCG
.length(), COLOR_BLACK
, COLOR_LIGHT_MAGENTA
));
921 legendText
.setStyleRange(new StyleRange(line4start
+ line4
.indexOf(CG
), CG
.length(), COLOR_BLACK
, COLOR_LIGHT_GREEN
, SWT
.BOLD
));
922 legendText
.setStyleRange(new StyleRange(line4start
+ line4
.indexOf(UCG
), UCG
.length(), COLOR_BLACK
, COLOR_LIGHT_MAGENTA
));
923 legendText
.setStyleRange(new StyleRange(line6start
+ line6
.indexOf(CG
), CG
.length(), COLOR_BLACK
, COLOR_GREEN
, SWT
.BOLD
));
924 legendText
.setStyleRange(new StyleRange(line6start
+ line6
.indexOf(UCG
), UCG
.length(), COLOR_BLACK
, COLOR_MAGENTA
));
925 legendShell
.setText(Messages
.CustomTxtParserInputWizardPage_previewLegend
);
930 private class UpdateListener
implements ModifyListener
, SelectionListener
{
933 public void modifyText(ModifyEvent e
) {
939 public void widgetDefaultSelected(SelectionEvent e
) {
945 public void widgetSelected(SelectionEvent e
) {
953 private static final String INFINITY_STRING
= "\u221E"; //$NON-NLS-1$
956 Composite labelComposite
;
958 Composite cardinalityContainer
;
959 Combo cardinalityCombo
;
960 Label cardinalityMinLabel
;
961 Text cardinalityMinText
;
962 Label cardinalityMaxLabel
;
963 Text cardinalityMaxText
;
964 Button infiniteButton
;
965 List
<InputGroup
> inputs
= new ArrayList
<InputGroup
>();
966 Button addGroupButton
;
969 public Line(Composite parent
, String name
, InputLine inputLine
) {
970 this.inputLine
= inputLine
;
972 group
= new Group(parent
, SWT
.NONE
);
974 group
.setLayout(new GridLayout(2, false));
975 group
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
977 labelComposite
= new Composite(group
, SWT
.FILL
);
978 GridLayout labelLayout
= new GridLayout(1, false);
979 labelLayout
.marginWidth
= 0;
980 labelLayout
.marginHeight
= 0;
981 labelComposite
.setLayout(labelLayout
);
982 labelComposite
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
984 Label label
= new Label(labelComposite
, SWT
.NULL
);
985 label
.setText(Messages
.CustomTxtParserInputWizardPage_regularExpression
);
987 Composite regexContainer
= new Composite(group
, SWT
.NONE
);
988 GridLayout regexLayout
= new GridLayout(2, false);
989 regexLayout
.marginHeight
= 0;
990 regexLayout
.marginWidth
= 0;
991 regexContainer
.setLayout(regexLayout
);
992 regexContainer
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
994 regexText
= new Text(regexContainer
, SWT
.BORDER
| SWT
.SINGLE
);
995 GridData gd
= new GridData(SWT
.FILL
, SWT
.CENTER
, true, false);
997 regexText
.setLayoutData(gd
);
998 regexText
.setText(inputLine
.getRegex());
999 regexText
.addModifyListener(updateListener
);
1001 Button regexHelpButton
= new Button(regexContainer
, SWT
.PUSH
);
1002 regexHelpButton
.setImage(helpImage
);
1003 regexHelpButton
.setToolTipText(Messages
.CustomTxtParserInputWizardPage_regularExpressionHelp
);
1004 regexHelpButton
.addSelectionListener(new SelectionAdapter() {
1006 public void widgetSelected(SelectionEvent e
) {
1007 openHelpShell(PATTERN_URL
);
1011 label
= new Label(group
, SWT
.NONE
);
1012 label
.setText(Messages
.CustomTxtParserInputWizardPage_cardinality
);
1013 label
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
1015 cardinalityContainer
= new Composite(group
, SWT
.NONE
);
1016 GridLayout cardinalityLayout
= new GridLayout(6, false);
1017 cardinalityLayout
.marginHeight
= 0;
1018 cardinalityLayout
.marginWidth
= 0;
1019 cardinalityContainer
.setLayout(cardinalityLayout
);
1020 cardinalityContainer
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
1022 cardinalityCombo
= new Combo(cardinalityContainer
, SWT
.DROP_DOWN
| SWT
.READ_ONLY
);
1023 cardinalityCombo
.setItems(new String
[] {
1024 Cardinality
.ZERO_OR_MORE
.toString(),
1025 Cardinality
.ONE_OR_MORE
.toString(),
1026 Cardinality
.ZERO_OR_ONE
.toString(),
1027 Cardinality
.ONE
.toString(),
1028 "(?,?)"}); //$NON-NLS-1$
1029 cardinalityCombo
.addSelectionListener(new SelectionListener(){
1031 public void widgetDefaultSelected(SelectionEvent e
) {}
1033 public void widgetSelected(SelectionEvent e
) {
1034 switch (cardinalityCombo
.getSelectionIndex()) {
1036 cardinalityMinLabel
.setVisible(true);
1037 cardinalityMinText
.setVisible(true);
1038 cardinalityMaxLabel
.setVisible(true);
1039 cardinalityMaxText
.setVisible(true);
1040 infiniteButton
.setVisible(true);
1043 cardinalityMinLabel
.setVisible(false);
1044 cardinalityMinText
.setVisible(false);
1045 cardinalityMaxLabel
.setVisible(false);
1046 cardinalityMaxText
.setVisible(false);
1047 infiniteButton
.setVisible(false);
1050 cardinalityContainer
.layout();
1055 cardinalityMinLabel
= new Label(cardinalityContainer
, SWT
.NONE
);
1056 cardinalityMinLabel
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
1057 cardinalityMinLabel
.setText(Messages
.CustomTxtParserInputWizardPage_min
);
1058 cardinalityMinLabel
.setVisible(false);
1060 cardinalityMinText
= new Text(cardinalityContainer
, SWT
.BORDER
| SWT
.SINGLE
);
1061 gd
= new GridData(SWT
.CENTER
, SWT
.CENTER
, false, false);
1063 cardinalityMinText
.setLayoutData(gd
);
1064 cardinalityMinText
.setVisible(false);
1066 cardinalityMaxLabel
= new Label(cardinalityContainer
, SWT
.NONE
);
1067 cardinalityMaxLabel
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
1068 cardinalityMaxLabel
.setText(Messages
.CustomTxtParserInputWizardPage_max
);
1069 cardinalityMaxLabel
.setVisible(false);
1071 cardinalityMaxText
= new Text(cardinalityContainer
, SWT
.BORDER
| SWT
.SINGLE
);
1072 gd
= new GridData(SWT
.CENTER
, SWT
.CENTER
, false, false);
1074 cardinalityMaxText
.setLayoutData(gd
);
1075 cardinalityMaxText
.setVisible(false);
1077 infiniteButton
= new Button(cardinalityContainer
, SWT
.PUSH
);
1078 infiniteButton
.setText(INFINITY_STRING
);
1079 infiniteButton
.setVisible(false);
1080 infiniteButton
.addSelectionListener(new SelectionAdapter(){
1082 public void widgetSelected(SelectionEvent e
) {
1083 cardinalityMaxText
.setText(INFINITY_STRING
);
1086 if (inputLine
.cardinality
.equals(Cardinality
.ZERO_OR_MORE
)) {
1087 cardinalityCombo
.select(0);
1088 } else if (inputLine
.cardinality
.equals(Cardinality
.ONE_OR_MORE
)) {
1089 cardinalityCombo
.select(1);
1090 } else if (inputLine
.cardinality
.equals(Cardinality
.ZERO_OR_ONE
)) {
1091 cardinalityCombo
.select(2);
1092 } else if (inputLine
.cardinality
.equals(Cardinality
.ONE
)) {
1093 cardinalityCombo
.select(3);
1095 cardinalityCombo
.select(4);
1096 cardinalityMinLabel
.setVisible(true);
1097 cardinalityMinText
.setVisible(true);
1098 if (inputLine
.getMinCount() >= 0) {
1099 cardinalityMinText
.setText(Integer
.toString(inputLine
.getMinCount()));
1101 cardinalityMaxLabel
.setVisible(true);
1102 cardinalityMaxText
.setVisible(true);
1103 if (inputLine
.getMaxCount() == Cardinality
.INF
) {
1104 cardinalityMaxText
.setText(INFINITY_STRING
);
1105 } else if (inputLine
.getMaxCount() >= 0) {
1106 cardinalityMaxText
.setText(Integer
.toString(inputLine
.getMaxCount()));
1108 infiniteButton
.setVisible(true);
1111 VerifyListener digitsListener
= new VerifyListener() {
1113 public void verifyText(VerifyEvent e
) {
1114 if (e
.text
.equals(INFINITY_STRING
)) {
1115 e
.doit
= e
.widget
== cardinalityMaxText
&& e
.start
== 0 && e
.end
== ((Text
) e
.widget
).getText().length();
1117 if (((Text
) e
.widget
).getText().equals(INFINITY_STRING
)) {
1118 e
.doit
= e
.start
== 0 && e
.end
== ((Text
) e
.widget
).getText().length();
1120 for (int i
= 0; i
< e
.text
.length(); i
++) {
1121 if (!Character
.isDigit(e
.text
.charAt(i
))) {
1129 cardinalityMinText
.addModifyListener(updateListener
);
1130 cardinalityMaxText
.addModifyListener(updateListener
);
1131 cardinalityMinText
.addVerifyListener(digitsListener
);
1132 cardinalityMaxText
.addVerifyListener(digitsListener
);
1134 if (inputLine
.columns
!= null) {
1135 for (InputData inputData
: inputLine
.columns
) {
1136 InputGroup inputGroup
= new InputGroup(group
, this, inputs
.size()+1);
1137 if (inputData
.name
.equals(CustomTraceDefinition
.TAG_TIMESTAMP
)) {
1138 inputGroup
.tagCombo
.select(0);
1139 inputGroup
.tagText
.setText(inputData
.format
);
1140 inputGroup
.tagLabel
.setText(Messages
.CustomTxtParserInputWizardPage_format
);
1141 inputGroup
.tagLabel
.setVisible(true);
1142 inputGroup
.tagText
.setVisible(true);
1143 inputGroup
.tagText
.addModifyListener(updateListener
);
1144 } else if (inputData
.name
.equals(CustomTraceDefinition
.TAG_MESSAGE
)) {
1145 inputGroup
.tagCombo
.select(1);
1147 inputGroup
.tagCombo
.select(2);
1148 inputGroup
.tagText
.setText(inputData
.name
);
1149 inputGroup
.tagLabel
.setText(Messages
.CustomTxtParserInputWizardPage_name
);
1150 inputGroup
.tagLabel
.setVisible(true);
1151 inputGroup
.tagText
.setVisible(true);
1152 inputGroup
.tagText
.addModifyListener(updateListener
);
1154 inputGroup
.actionCombo
.select(inputData
.action
);
1155 inputs
.add(inputGroup
);
1159 createAddGroupButton();
1162 private void createAddGroupButton() {
1163 addGroupButton
= new Button(group
, SWT
.PUSH
);
1164 addGroupButton
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
1165 addGroupButton
.setImage(addImage
);
1166 addGroupButton
.setToolTipText(Messages
.CustomTxtParserInputWizardPage_addGroup
);
1167 addGroupButton
.addSelectionListener(new SelectionAdapter() {
1169 public void widgetSelected(SelectionEvent e
) {
1170 removeAddGroupButton();
1171 inputs
.add(new InputGroup(group
, Line
.this, inputs
.size()+1));
1172 createAddGroupButton();
1173 lineContainer
.layout();
1174 lineScrolledComposite
.setMinSize(lineContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).x
, lineContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).y
-1);
1175 group
.getParent().layout();
1181 addGroupLabel
= new Label(group
, SWT
.NULL
);
1182 addGroupLabel
.setText(Messages
.CustomTxtParserInputWizardPage_newGroup
);
1185 private void removeAddGroupButton() {
1186 addGroupButton
.dispose();
1187 addGroupLabel
.dispose();
1190 private void removeInput(int inputNumber
) {
1191 if (--inputNumber
< inputs
.size()) {
1192 inputs
.remove(inputNumber
).dispose();
1193 for (int i
= inputNumber
; i
< inputs
.size(); i
++) {
1194 inputs
.get(i
).setInputNumber(i
+1);
1196 lineContainer
.layout();
1197 lineScrolledComposite
.setMinSize(lineContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).x
, lineContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).y
-1);
1198 group
.getParent().layout();
1202 // private void setName(String name) {
1203 // this.name = name;
1204 // group.setText("Line " + name);
1207 private void dispose() {
1211 private void extractInputs() {
1212 inputLine
.setRegex(selectedLine
.regexText
.getText());
1213 switch (cardinalityCombo
.getSelectionIndex()) {
1215 inputLine
.cardinality
= Cardinality
.ZERO_OR_MORE
;
1218 inputLine
.cardinality
= Cardinality
.ONE_OR_MORE
;
1221 inputLine
.cardinality
= Cardinality
.ZERO_OR_ONE
;
1224 inputLine
.cardinality
= Cardinality
.ONE
;
1229 min
= Integer
.parseInt(cardinalityMinText
.getText());
1230 } catch (NumberFormatException e
) {
1234 if (cardinalityMaxText
.getText().equals(INFINITY_STRING
)) {
1235 max
= Cardinality
.INF
;
1237 max
= Integer
.parseInt(cardinalityMaxText
.getText());
1239 } catch (NumberFormatException e
) {
1242 inputLine
.cardinality
= new Cardinality(min
, max
);
1245 inputLine
.cardinality
= Cardinality
.ZERO_OR_MORE
;
1248 inputLine
.columns
= new ArrayList
<InputData
>(inputs
.size());
1249 for (int i
= 0; i
< inputs
.size(); i
++) {
1250 InputGroup group
= inputs
.get(i
);
1251 InputData inputData
= new InputData();
1252 if (group
.tagCombo
.getText().equals(CustomTraceDefinition
.TAG_OTHER
)) {
1253 inputData
.name
= group
.tagText
.getText().trim();
1255 inputData
.name
= group
.tagCombo
.getText();
1256 if (group
.tagCombo
.getText().equals(CustomTraceDefinition
.TAG_TIMESTAMP
)) {
1257 inputData
.format
= group
.tagText
.getText().trim();
1260 inputData
.action
= group
.actionCombo
.getSelectionIndex();
1261 inputLine
.columns
.add(inputData
);
1266 private class InputGroup
{
1270 // children of parent (must be disposed)
1271 Composite labelComposite
;
1272 Composite tagComposite
;
1276 // children of labelComposite
1279 // children of tagComposite
1285 public InputGroup(Composite parent
, Line line
, int inputNumber
) {
1287 this.inputNumber
= inputNumber
;
1289 labelComposite
= new Composite(parent
, SWT
.FILL
);
1290 GridLayout labelLayout
= new GridLayout(2, false);
1291 labelLayout
.marginWidth
= 0;
1292 labelLayout
.marginHeight
= 0;
1293 labelComposite
.setLayout(labelLayout
);
1294 labelComposite
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
1296 Button deleteButton
= new Button(labelComposite
, SWT
.PUSH
);
1297 deleteButton
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
1298 deleteButton
.setImage(deleteImage
);
1299 deleteButton
.setToolTipText(Messages
.CustomTxtParserInputWizardPage_removeGroup
);
1300 deleteButton
.addSelectionListener(new SelectionAdapter() {
1302 public void widgetSelected(SelectionEvent e
) {
1303 InputGroup
.this.line
.removeInput(InputGroup
.this.inputNumber
);
1309 inputLabel
= new Label(labelComposite
, SWT
.NULL
);
1310 inputLabel
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
1311 inputLabel
.setText(Messages
.CustomTxtParserInputWizardPage_group
+ inputNumber
+ ":"); //$NON-NLS-1$
1313 tagComposite
= new Composite(parent
, SWT
.FILL
);
1314 GridLayout tagLayout
= new GridLayout(4, false);
1315 tagLayout
.marginWidth
= 0;
1316 tagLayout
.marginHeight
= 0;
1317 tagComposite
.setLayout(tagLayout
);
1318 tagComposite
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
1320 tagCombo
= new Combo(tagComposite
, SWT
.DROP_DOWN
| SWT
.READ_ONLY
);
1321 tagCombo
.setItems(new String
[] {CustomTraceDefinition
.TAG_TIMESTAMP
,
1322 CustomTraceDefinition
.TAG_MESSAGE
,
1323 CustomTraceDefinition
.TAG_OTHER
});
1325 tagCombo
.addSelectionListener(new SelectionListener(){
1327 public void widgetDefaultSelected(SelectionEvent e
) {}
1329 public void widgetSelected(SelectionEvent e
) {
1330 tagText
.removeModifyListener(updateListener
);
1331 switch (tagCombo
.getSelectionIndex()) {
1332 case 0: //Time Stamp
1333 tagLabel
.setText(Messages
.CustomTxtParserInputWizardPage_format
);
1334 tagLabel
.setVisible(true);
1335 tagText
.setVisible(true);
1336 tagText
.addModifyListener(updateListener
);
1339 tagLabel
.setVisible(false);
1340 tagText
.setVisible(false);
1343 tagLabel
.setText(Messages
.CustomTxtParserInputWizardPage_name
);
1344 tagLabel
.setVisible(true);
1345 tagText
.setVisible(true);
1346 tagText
.addModifyListener(updateListener
);
1349 tagLabel
.setVisible(false);
1350 tagText
.setVisible(false);
1355 tagComposite
.layout();
1360 tagLabel
= new Label(tagComposite
, SWT
.NULL
);
1361 tagLabel
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
1362 tagLabel
.setVisible(false);
1364 tagText
= new Text(tagComposite
, SWT
.BORDER
| SWT
.SINGLE
);
1365 GridData gd
= new GridData(SWT
.FILL
, SWT
.CENTER
, true, false);
1367 tagText
.setLayoutData(gd
);
1368 tagText
.setVisible(false);
1370 actionCombo
= new Combo(tagComposite
, SWT
.DROP_DOWN
| SWT
.READ_ONLY
);
1371 actionCombo
.setItems(new String
[] {Messages
.CustomTxtParserInputWizardPage_set
, Messages
.CustomTxtParserInputWizardPage_append
, Messages
.CustomTxtParserInputWizardPage_appendWith
});
1372 actionCombo
.select(0);
1373 actionCombo
.addSelectionListener(updateListener
);
1375 previewLabel
= new Label(parent
, SWT
.NULL
);
1376 previewLabel
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
1377 previewLabel
.setText(Messages
.CustomTxtParserInputWizardPage_preview
);
1379 previewText
= new Text(parent
, SWT
.BORDER
| SWT
.SINGLE
| SWT
.READ_ONLY
);
1380 gd
= new GridData(SWT
.FILL
, SWT
.CENTER
, true, false);
1382 previewText
.setLayoutData(gd
);
1383 previewText
.setText(Messages
.CustomTxtParserInputWizardPage_noMatch
);
1384 previewText
.setBackground(COLOR_WIDGET_BACKGROUND
);
1387 private void dispose() {
1388 labelComposite
.dispose();
1389 tagComposite
.dispose();
1390 previewLabel
.dispose();
1391 previewText
.dispose();
1394 private void setInputNumber(int inputNumber
) {
1395 this.inputNumber
= inputNumber
;
1396 inputLabel
.setText(Messages
.CustomTxtParserInputWizardPage_group
+ inputNumber
+ ":"); //$NON-NLS-1$
1397 labelComposite
.layout();
1401 private void validate() {
1403 definition
.definitionName
= logtypeText
.getText().trim();
1404 definition
.timeStampOutputFormat
= timestampOutputFormatText
.getText().trim();
1406 if (selectedLine
!= null) {
1407 selectedLine
.extractInputs();
1408 treeViewer
.refresh();
1411 StringBuffer errors
= new StringBuffer();
1413 if (definition
.definitionName
.length() == 0) {
1414 errors
.append("Enter a name for the new log type. "); //$NON-NLS-1$
1415 logtypeText
.setBackground(COLOR_LIGHT_RED
);
1417 logtypeText
.setBackground(COLOR_TEXT_BACKGROUND
);
1418 for (CustomTxtTraceDefinition def
: CustomTxtTraceDefinition
.loadAll()) {
1419 if (definition
.definitionName
.equals(def
.definitionName
)) {
1420 if (editDefinitionName
== null || ! editDefinitionName
.equals(definition
.definitionName
)) {
1421 errors
.append("The log type name already exists. "); //$NON-NLS-1$
1422 logtypeText
.setBackground(COLOR_LIGHT_RED
);
1429 timestampFound
= false;
1430 for (int i
= 0; i
< definition
.inputs
.size(); i
++) {
1432 InputLine inputLine
= definition
.inputs
.get(i
);
1433 String name
= Integer
.toString(i
+1);
1434 errors
.append(validateLine(inputLine
, name
));
1436 if (timestampFound
) {
1437 if (definition
.timeStampOutputFormat
.length() == 0) {
1438 errors
.append("Enter the output format for the Time Stamp field. "); //$NON-NLS-1$
1439 timestampOutputFormatText
.setBackground(COLOR_LIGHT_RED
);
1442 new SimpleDateFormat(definition
.timeStampOutputFormat
);
1443 timestampOutputFormatText
.setBackground(COLOR_TEXT_BACKGROUND
);
1444 } catch (IllegalArgumentException e
) {
1445 errors
.append("Enter a valid output format for the Time Stamp field. "); //$NON-NLS-1$
1446 timestampOutputFormatText
.setBackground(COLOR_LIGHT_RED
);
1451 timestampOutputFormatText
.setBackground(COLOR_TEXT_BACKGROUND
);
1452 // timestampPreviewText.setBackground(COLOR_WIDGET_BACKGROUND);
1453 // errors.append("Identify a Time Stamp group (Line "+name+"). ");
1454 // timestampPreviewText.setText("*no timestamp group*");
1455 // timestampPreviewText.setBackground(COLOR_LIGHT_RED);
1458 if (errors
.length() == 0) {
1459 setDescription(defaultDescription
);
1460 setPageComplete(true);
1462 setDescription(errors
.toString());
1463 setPageComplete(false);
1467 public StringBuffer
validateLine(InputLine inputLine
, String name
) {
1468 StringBuffer errors
= new StringBuffer();
1470 if (selectedLine
!= null && selectedLine
.inputLine
.equals(inputLine
)) {
1471 line
= selectedLine
;
1474 Pattern
.compile(inputLine
.getRegex());
1476 line
.regexText
.setBackground(COLOR_TEXT_BACKGROUND
);
1478 } catch (PatternSyntaxException e
) {
1479 errors
.append("Enter a valid regular expression (Line "+name
+"). "); //$NON-NLS-1$ //$NON-NLS-2$
1481 line
.regexText
.setBackground(COLOR_LIGHT_RED
);
1484 if (inputLine
.getMinCount() == -1) {
1485 errors
.append("Enter a minimum value for cardinality (Line "+name
+"). "); //$NON-NLS-1$ //$NON-NLS-2$
1487 line
.cardinalityMinText
.setBackground(COLOR_LIGHT_RED
);
1491 line
.cardinalityMinText
.setBackground(COLOR_TEXT_BACKGROUND
);
1494 if (inputLine
.getMaxCount() == -1) {
1495 errors
.append("Enter a maximum value for cardinality (Line "+name
+"). "); //$NON-NLS-1$ //$NON-NLS-2$
1497 line
.cardinalityMaxText
.setBackground(COLOR_LIGHT_RED
);
1499 } else if (inputLine
.getMinCount() > inputLine
.getMaxCount()) {
1500 errors
.append("Enter correct (min <= max) values for cardinality (Line "+name
+"). "); //$NON-NLS-1$ //$NON-NLS-2$
1502 line
.cardinalityMinText
.setBackground(COLOR_LIGHT_RED
);
1505 line
.cardinalityMaxText
.setBackground(COLOR_LIGHT_RED
);
1509 line
.cardinalityMaxText
.setBackground(COLOR_TEXT_BACKGROUND
);
1512 for (int i
= 0; inputLine
.columns
!= null && i
< inputLine
.columns
.size(); i
++) {
1513 InputData inputData
= inputLine
.columns
.get(i
);
1514 InputGroup group
= null;
1516 group
= line
.inputs
.get(i
);
1518 if (inputData
.name
.equals(CustomTraceDefinition
.TAG_TIMESTAMP
)) {
1519 timestampFound
= true;
1520 if (inputData
.format
.length() == 0) {
1521 errors
.append("Enter the input format for the Time Stamp (Line "+name
+" Group "+(i
+1)+"). "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
1522 if (group
!= null) {
1523 group
.tagText
.setBackground(COLOR_LIGHT_RED
);
1527 new SimpleDateFormat(inputData
.format
);
1528 if (group
!= null) {
1529 group
.tagText
.setBackground(COLOR_TEXT_BACKGROUND
);
1531 } catch (IllegalArgumentException e
) {
1532 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$
1533 if (group
!= null) {
1534 group
.tagText
.setBackground(COLOR_LIGHT_RED
);
1538 } else if (inputData
.name
.length() == 0) {
1539 errors
.append("Enter a name for the data group (Line "+name
+" Group "+(i
+1)+"). "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
1540 if (group
!= null) {
1541 group
.tagText
.setBackground(COLOR_LIGHT_RED
);
1544 if (group
!= null) {
1545 group
.tagText
.setBackground(COLOR_TEXT_BACKGROUND
);
1549 for (int i
= 0; inputLine
.childrenInputs
!= null && i
< inputLine
.childrenInputs
.size(); i
++) {
1550 errors
.append(validateLine(inputLine
.childrenInputs
.get(i
), name
+"."+(i
+1))); //$NON-NLS-1$
1555 public CustomTxtTraceDefinition
getDefinition() {
1559 public char[] getInputText() {
1560 return inputText
.getText().toCharArray();