Added TMF statistics feature (Bug 360572)
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / tmf / ui / wizards / CustomTxtParserInputWizardPage.java
CommitLineData
c3c5c786
FC
1package org.eclipse.linuxtools.tmf.ui.wizards;\r
2\r
3import java.io.BufferedReader;\r
4import java.io.IOException;\r
5import java.io.InputStreamReader;\r
6import java.text.ParseException;\r
7import java.text.SimpleDateFormat;\r
8import java.util.ArrayList;\r
9import java.util.Arrays;\r
10import java.util.Date;\r
11import java.util.HashMap;\r
12import java.util.Iterator;\r
13import java.util.List;\r
14import java.util.Map;\r
15import java.util.Scanner;\r
16import java.util.regex.Matcher;\r
17import java.util.regex.Pattern;\r
18import java.util.regex.PatternSyntaxException;\r
19\r
20import org.eclipse.core.resources.IFile;\r
21import org.eclipse.core.runtime.CoreException;\r
22import org.eclipse.jface.viewers.ColumnLabelProvider;\r
23import org.eclipse.jface.viewers.ISelection;\r
24import org.eclipse.jface.viewers.ISelectionChangedListener;\r
25import org.eclipse.jface.viewers.IStructuredSelection;\r
26import org.eclipse.jface.viewers.ITreeContentProvider;\r
27import org.eclipse.jface.viewers.SelectionChangedEvent;\r
28import org.eclipse.jface.viewers.StructuredSelection;\r
29import org.eclipse.jface.viewers.TreeViewer;\r
30import org.eclipse.jface.viewers.Viewer;\r
31import org.eclipse.jface.wizard.WizardPage;\r
32import org.eclipse.linuxtools.tmf.ui.TmfUiPlugin;\r
7995b722 33import org.eclipse.linuxtools.tmf.ui.internal.Messages;\r
c3c5c786
FC
34import org.eclipse.linuxtools.tmf.ui.parsers.custom.CustomTxtTraceDefinition;\r
35import org.eclipse.linuxtools.tmf.ui.parsers.custom.CustomTxtTraceDefinition.Cardinality;\r
36import org.eclipse.linuxtools.tmf.ui.parsers.custom.CustomTxtTraceDefinition.InputData;\r
37import org.eclipse.linuxtools.tmf.ui.parsers.custom.CustomTxtTraceDefinition.InputLine;\r
38import org.eclipse.swt.SWT;\r
39import org.eclipse.swt.browser.Browser;\r
40import org.eclipse.swt.browser.TitleEvent;\r
41import org.eclipse.swt.browser.TitleListener;\r
42import org.eclipse.swt.custom.SashForm;\r
43import org.eclipse.swt.custom.ScrolledComposite;\r
44import org.eclipse.swt.custom.StyleRange;\r
45import org.eclipse.swt.custom.StyledText;\r
46import org.eclipse.swt.events.ModifyEvent;\r
47import org.eclipse.swt.events.ModifyListener;\r
48import org.eclipse.swt.events.SelectionAdapter;\r
49import org.eclipse.swt.events.SelectionEvent;\r
50import org.eclipse.swt.events.SelectionListener;\r
51import org.eclipse.swt.events.VerifyEvent;\r
52import org.eclipse.swt.events.VerifyListener;\r
53import org.eclipse.swt.graphics.Color;\r
54import org.eclipse.swt.graphics.Font;\r
55import org.eclipse.swt.graphics.FontData;\r
56import org.eclipse.swt.graphics.Image;\r
57import org.eclipse.swt.layout.FillLayout;\r
58import org.eclipse.swt.layout.GridData;\r
59import org.eclipse.swt.layout.GridLayout;\r
60import org.eclipse.swt.widgets.Button;\r
61import org.eclipse.swt.widgets.Combo;\r
62import org.eclipse.swt.widgets.Composite;\r
63import org.eclipse.swt.widgets.Display;\r
64import org.eclipse.swt.widgets.Group;\r
65import org.eclipse.swt.widgets.Label;\r
66import org.eclipse.swt.widgets.Shell;\r
67import org.eclipse.swt.widgets.Text;\r
68\r
69public class CustomTxtParserInputWizardPage extends WizardPage {\r
70\r
3b38ea61
FC
71 private static final String DEFAULT_REGEX = "\\s*(.*\\S)"; //$NON-NLS-1$\r
72 private static final String DEFAULT_TIMESTAMP_FORMAT = "yyyy-MM-dd HH:mm:ss.SSS"; //$NON-NLS-1$\r
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$\r
74 private static final String PATTERN_URL = "http://java.sun.com/javase/6/docs/api/java/util/regex/Pattern.html#sum"; //$NON-NLS-1$\r
d7fcacc9
FC
75 private static final Image lineImage = TmfUiPlugin.getDefault().getImageFromPath("/icons/elcl16/line_icon.gif"); //$NON-NLS-1$\r
76 private static final Image addImage = TmfUiPlugin.getDefault().getImageFromPath("/icons/elcl16/add_button.gif"); //$NON-NLS-1$\r
77 private static final Image addNextImage = TmfUiPlugin.getDefault().getImageFromPath("/icons/elcl16/addnext_button.gif"); //$NON-NLS-1$\r
78 private static final Image addChildImage = TmfUiPlugin.getDefault().getImageFromPath("/icons/elcl16/addchild_button.gif"); //$NON-NLS-1$\r
79 private static final Image deleteImage = TmfUiPlugin.getDefault().getImageFromPath("/icons/elcl16/delete_button.gif"); //$NON-NLS-1$\r
80 private static final Image moveUpImage = TmfUiPlugin.getDefault().getImageFromPath("/icons/elcl16/moveup_button.gif"); //$NON-NLS-1$\r
81 private static final Image moveDownImage = TmfUiPlugin.getDefault().getImageFromPath("/icons/elcl16/movedown_button.gif"); //$NON-NLS-1$\r
82 private static final Image helpImage = TmfUiPlugin.getDefault().getImageFromPath("/icons/elcl16/help_button.gif"); //$NON-NLS-1$\r
c3c5c786
FC
83 private static final Color COLOR_BLACK = Display.getCurrent().getSystemColor(SWT.COLOR_BLACK);\r
84 private static final Color COLOR_LIGHT_GREEN = new Color(Display.getDefault(), 192, 255, 192);\r
85 private static final Color COLOR_GREEN = Display.getCurrent().getSystemColor(SWT.COLOR_GREEN);\r
86 private static final Color COLOR_LIGHT_YELLOW = new Color(Display.getDefault(), 255, 255, 192);\r
87 private static final Color COLOR_YELLOW = Display.getCurrent().getSystemColor(SWT.COLOR_YELLOW);\r
88 private static final Color COLOR_LIGHT_MAGENTA = new Color(Display.getDefault(), 255, 192, 255);\r
89 private static final Color COLOR_MAGENTA = Display.getCurrent().getSystemColor(SWT.COLOR_MAGENTA);\r
90 private static final Color COLOR_LIGHT_RED = new Color(Display.getDefault(), 255, 192, 192);\r
91 private static final Color COLOR_TEXT_BACKGROUND = Display.getCurrent().getSystemColor(SWT.COLOR_WHITE);\r
92 private static final Color COLOR_WIDGET_BACKGROUND = Display.getCurrent().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND);\r
93\r
94 private ISelection selection;\r
95 private CustomTxtTraceDefinition definition;\r
96 private String editDefinitionName;\r
97 private String defaultDescription;\r
98 private Line selectedLine;\r
99 private Composite container;\r
100 private Text logtypeText;\r
101 private Text timestampOutputFormatText;\r
102 private Text timestampPreviewText;\r
103 private ScrolledComposite treeScrolledComposite;\r
104 private ScrolledComposite lineScrolledComposite;\r
105 private TreeViewer treeViewer;\r
106 private Composite treeContainer;\r
107 private Composite lineContainer;\r
c3c5c786
FC
108 private StyledText inputText;\r
109 private Font fixedFont;\r
110 private UpdateListener updateListener;\r
111 private Browser helpBrowser;\r
112\r
113 // variables used recursively through line traversal\r
c3c5c786
FC
114 private String timeStampFormat;\r
115 private boolean timestampFound;\r
116 \r
117 protected CustomTxtParserInputWizardPage(ISelection selection, CustomTxtTraceDefinition definition) {\r
3b38ea61 118 super("CustomParserWizardPage"); //$NON-NLS-1$\r
c3c5c786 119 if (definition == null) {\r
3b38ea61
FC
120 setTitle(Messages.CustomTxtParserInputWizardPage_windowTitleNew);\r
121 defaultDescription = Messages.CustomTxtParserInputWizardPage_descriptionNew;\r
c3c5c786 122 } else {\r
3b38ea61
FC
123 setTitle(Messages.CustomTxtParserInputWizardPage_windowTitleEdit);\r
124 defaultDescription = Messages.CustomTxtParserInputWizardPage_desccriptionEdit;\r
c3c5c786
FC
125 }\r
126 setDescription(defaultDescription);\r
127 this.selection = selection;\r
128 this.definition = definition;\r
129 if (definition != null) {\r
130 this.editDefinitionName = definition.definitionName;\r
131 }\r
132 }\r
133\r
d4011df2 134 @Override\r
c3c5c786
FC
135 public void createControl(Composite parent) {\r
136 container = new Composite(parent, SWT.NULL);\r
137 container.setLayout(new GridLayout());\r
138\r
139 updateListener = new UpdateListener();\r
140 \r
141 Composite headerComposite = new Composite(container, SWT.FILL);\r
142 GridLayout headerLayout = new GridLayout(5, false);\r
143 headerLayout.marginHeight = 0;\r
144 headerLayout.marginWidth = 0;\r
145 headerComposite.setLayout(headerLayout);\r
146 headerComposite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));\r
147 \r
148 Label logtypeLabel = new Label(headerComposite, SWT.NULL);\r
3b38ea61 149 logtypeLabel.setText(Messages.CustomTxtParserInputWizardPage_logType);\r
c3c5c786
FC
150 \r
151 logtypeText = new Text(headerComposite, SWT.BORDER | SWT.SINGLE);\r
152 logtypeText.setLayoutData(new GridData(120, SWT.DEFAULT));\r
c3c5c786
FC
153 \r
154 Label timestampFormatLabel = new Label(headerComposite, SWT.NULL);\r
3b38ea61 155 timestampFormatLabel.setText(Messages.CustomTxtParserInputWizardPage_timestampFormat);\r
c3c5c786
FC
156 \r
157 timestampOutputFormatText = new Text(headerComposite, SWT.BORDER | SWT.SINGLE);\r
158 timestampOutputFormatText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));\r
159 timestampOutputFormatText.setText(DEFAULT_TIMESTAMP_FORMAT);\r
c3c5c786
FC
160\r
161 Button dateFormatHelpButton = new Button(headerComposite, SWT.PUSH);\r
162 dateFormatHelpButton.setImage(helpImage);\r
3b38ea61 163 dateFormatHelpButton.setToolTipText(Messages.CustomTxtParserInputWizardPage_dateFormatHelp);\r
c3c5c786 164 dateFormatHelpButton.addSelectionListener(new SelectionAdapter() {\r
9ccc6d01
FC
165 @Override\r
166 public void widgetSelected(SelectionEvent e) {\r
c3c5c786
FC
167 openHelpShell(SIMPLE_DATE_FORMAT_URL);\r
168 }\r
169 });\r
170 \r
171 Label timestampPreviewLabel = new Label(headerComposite, SWT.NULL);\r
172 timestampPreviewLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 3, 1));\r
3b38ea61 173 timestampPreviewLabel.setText(Messages.CustomTxtParserInputWizardPage_preview);\r
c3c5c786
FC
174 \r
175 timestampPreviewText = new Text(headerComposite, SWT.BORDER | SWT.SINGLE | SWT.READ_ONLY);\r
176 timestampPreviewText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));\r
3b38ea61 177 timestampPreviewText.setText(Messages.CustomTxtParserInputWizardPage_noMatchingTimestamp);\r
c3c5c786
FC
178\r
179 Composite buttonBar = new Composite(container, SWT.NONE);\r
180 GridLayout buttonBarLayout = new GridLayout(5, false);\r
181 buttonBarLayout.marginHeight = 0;\r
182 buttonBarLayout.marginWidth = 0;\r
183 buttonBar.setLayout(buttonBarLayout);\r
184 \r
185 Button removeButton = new Button(buttonBar, SWT.PUSH);\r
186 removeButton.setImage(deleteImage);\r
3b38ea61 187 removeButton.setToolTipText(Messages.CustomTxtParserInputWizardPage_removeLine);\r
c3c5c786 188 removeButton.addSelectionListener(new SelectionAdapter() {\r
9ccc6d01 189 @Override\r
c3c5c786
FC
190 public void widgetSelected(SelectionEvent e) {\r
191 if (treeViewer.getSelection().isEmpty() || selectedLine == null) return;\r
192 removeLine();\r
193 InputLine inputLine = (InputLine) ((IStructuredSelection) treeViewer.getSelection()).getFirstElement();\r
194 if (inputLine.parentInput == null) {\r
195 definition.inputs.remove(inputLine);\r
196 } else {\r
197 inputLine.parentInput.childrenInputs.remove(inputLine);\r
198 }\r
199 treeViewer.refresh();\r
200 validate();\r
201 updatePreviews();\r
202 }\r
203 });\r
204 Button addNextButton = new Button(buttonBar, SWT.PUSH);\r
205 addNextButton.setImage(addNextImage);\r
3b38ea61 206 addNextButton.setToolTipText(Messages.CustomTxtParserInputWizardPage_addNextLine);\r
c3c5c786 207 addNextButton.addSelectionListener(new SelectionAdapter() {\r
9ccc6d01 208 @Override\r
c3c5c786 209 public void widgetSelected(SelectionEvent e) {\r
3b38ea61 210 InputLine inputLine = new InputLine(Cardinality.ZERO_OR_MORE, "", null); //$NON-NLS-1$\r
c3c5c786
FC
211 if (((List<?>) treeViewer.getInput()).size() == 0) {\r
212 definition.inputs.add(inputLine);\r
213 } else if (treeViewer.getSelection().isEmpty()) {\r
214 return;\r
215 } else {\r
216 InputLine previousInputLine = (InputLine) ((IStructuredSelection) treeViewer.getSelection()).getFirstElement();\r
217 if (previousInputLine.parentInput == null) {\r
218 for (int i = 0; i < definition.inputs.size(); i++) {\r
219 if (definition.inputs.get(i).equals(previousInputLine)) {\r
220 definition.inputs.add(i + 1, inputLine);\r
221 }\r
222 }\r
223 } else {\r
224 previousInputLine.addNext(inputLine);\r
225 }\r
226 }\r
227 treeViewer.refresh();\r
228 treeViewer.setSelection(new StructuredSelection(inputLine), true);\r
229 }\r
230 });\r
231 Button addChildButton = new Button(buttonBar, SWT.PUSH);\r
232 addChildButton.setImage(addChildImage);\r
3b38ea61 233 addChildButton.setToolTipText(Messages.CustomTxtParserInputWizardPage_addChildLine);\r
c3c5c786 234 addChildButton.addSelectionListener(new SelectionAdapter() {\r
9ccc6d01
FC
235 @Override\r
236 public void widgetSelected(SelectionEvent e) {\r
3b38ea61 237 InputLine inputLine = new InputLine(Cardinality.ZERO_OR_MORE, "", null); //$NON-NLS-1$\r
c3c5c786
FC
238 if (((List<?>) treeViewer.getInput()).size() == 0) {\r
239 definition.inputs.add(inputLine);\r
240 } else if (treeViewer.getSelection().isEmpty()) {\r
241 return;\r
242 } else {\r
243 InputLine parentInputLine = (InputLine) ((IStructuredSelection) treeViewer.getSelection()).getFirstElement();\r
244 parentInputLine.addChild(inputLine);\r
245 }\r
246 treeViewer.refresh();\r
247 treeViewer.setSelection(new StructuredSelection(inputLine), true);\r
248 }\r
249 });\r
250 Button moveUpButton = new Button(buttonBar, SWT.PUSH);\r
251 moveUpButton.setImage(moveUpImage);\r
3b38ea61 252 moveUpButton.setToolTipText(Messages.CustomTxtParserInputWizardPage_moveUp);\r
c3c5c786 253 moveUpButton.addSelectionListener(new SelectionAdapter() {\r
9ccc6d01 254 @Override\r
c3c5c786
FC
255 public void widgetSelected(SelectionEvent e) {\r
256 if (treeViewer.getSelection().isEmpty()) return;\r
257 InputLine inputLine = (InputLine) ((IStructuredSelection) treeViewer.getSelection()).getFirstElement();\r
258 if (inputLine.parentInput == null) {\r
259 for (int i = 1; i < definition.inputs.size(); i++) {\r
260 if (definition.inputs.get(i).equals(inputLine)) {\r
261 definition.inputs.add(i - 1 , definition.inputs.remove(i));\r
262 break;\r
263 }\r
264 }\r
265 } else {\r
266 inputLine.moveUp();\r
267 }\r
268 treeViewer.refresh();\r
269 validate();\r
270 updatePreviews();\r
271 }\r
272 });\r
273 Button moveDownButton = new Button(buttonBar, SWT.PUSH);\r
274 moveDownButton.setImage(moveDownImage);\r
3b38ea61 275 moveDownButton.setToolTipText(Messages.CustomTxtParserInputWizardPage_moveDown);\r
c3c5c786 276 moveDownButton.addSelectionListener(new SelectionAdapter() {\r
9ccc6d01 277 @Override\r
c3c5c786
FC
278 public void widgetSelected(SelectionEvent e) {\r
279 if (treeViewer.getSelection().isEmpty()) return;\r
280 InputLine inputLine = (InputLine) ((IStructuredSelection) treeViewer.getSelection()).getFirstElement();\r
281 if (inputLine.parentInput == null) {\r
282 for (int i = 0; i < definition.inputs.size() - 1; i++) {\r
283 if (definition.inputs.get(i).equals(inputLine)) {\r
284 definition.inputs.add(i + 1 , definition.inputs.remove(i));\r
285 break;\r
286 }\r
287 }\r
288 } else {\r
289 inputLine.moveDown();\r
290 }\r
291 treeViewer.refresh();\r
292 validate();\r
293 updatePreviews();\r
294 }\r
295 });\r
296 \r
297 SashForm vSash = new SashForm(container, SWT.VERTICAL);\r
298 vSash.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));\r
299 vSash.setBackground(vSash.getDisplay().getSystemColor(SWT.COLOR_GRAY));\r
300\r
301 SashForm hSash = new SashForm(vSash, SWT.HORIZONTAL);\r
302 hSash.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));\r
303\r
304 treeScrolledComposite = new ScrolledComposite(hSash, SWT.V_SCROLL | SWT.H_SCROLL);\r
305 GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);\r
306 gd.heightHint = 200;\r
307 gd.widthHint = 200;\r
308 treeScrolledComposite.setLayoutData(gd);\r
309 treeContainer = new Composite(treeScrolledComposite, SWT.NONE);\r
310 treeContainer.setLayout(new FillLayout());\r
311 treeScrolledComposite.setContent(treeContainer);\r
312 treeScrolledComposite.setExpandHorizontal(true);\r
313 treeScrolledComposite.setExpandVertical(true);\r
314 \r
315 treeViewer = new TreeViewer(treeContainer, SWT.SINGLE | SWT.BORDER);\r
316 treeViewer.setContentProvider(new InputLineTreeNodeContentProvider());\r
317 treeViewer.setLabelProvider(new InputLineTreeLabelProvider());\r
318 treeViewer.addSelectionChangedListener(new InputLineTreeSelectionChangedListener());\r
319 treeContainer.layout();\r
320 \r
321 treeScrolledComposite.setMinSize(treeContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT).x, treeContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT).y);\r
322 \r
323 lineScrolledComposite = new ScrolledComposite(hSash, SWT.V_SCROLL);\r
324 lineScrolledComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));\r
325 lineContainer = new Composite(lineScrolledComposite, SWT.NONE);\r
326 GridLayout linesLayout = new GridLayout();\r
327 linesLayout.marginHeight = 1;\r
328 linesLayout.marginWidth = 0;\r
329 lineContainer.setLayout(linesLayout);\r
330 lineScrolledComposite.setContent(lineContainer);\r
331 lineScrolledComposite.setExpandHorizontal(true);\r
332 lineScrolledComposite.setExpandVertical(true);\r
333\r
334 if (definition == null) {\r
335 definition = new CustomTxtTraceDefinition();\r
336 definition.inputs.add(new InputLine(Cardinality.ZERO_OR_MORE, DEFAULT_REGEX,\r
337 Arrays.asList(new InputData(CustomTxtTraceDefinition.TAG_MESSAGE, CustomTxtTraceDefinition.ACTION_SET))));\r
338 }\r
339 loadDefinition(definition);\r
340 treeViewer.expandAll();\r
341 lineContainer.layout();\r
342 \r
d7fcacc9
FC
343 logtypeText.addModifyListener(updateListener);\r
344 timestampOutputFormatText.addModifyListener(updateListener);\r
345 \r
c3c5c786
FC
346 lineScrolledComposite.setMinSize(lineContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT).x, lineContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT).y-1);\r
347\r
348 hSash.setWeights(new int[] {1, 2});\r
349 \r
350 Composite sashBottom = new Composite(vSash, SWT.NONE);\r
351 GridLayout sashBottomLayout = new GridLayout(3, false);\r
352 sashBottomLayout.marginHeight = 0;\r
353 sashBottomLayout.marginWidth = 0;\r
354 sashBottom.setLayout(sashBottomLayout);\r
355\r
356 Label previewLabel = new Label(sashBottom, SWT.NULL);\r
3b38ea61 357 previewLabel.setText(Messages.CustomTxtParserInputWizardPage_previewInput);\r
c3c5c786
FC
358 previewLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));\r
359\r
360 Button highlightAllButton = new Button(sashBottom, SWT.PUSH);\r
361 highlightAllButton.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));\r
3b38ea61 362 highlightAllButton.setText(Messages.CustomTxtParserInputWizardPage_highlightAll);\r
c3c5c786 363 highlightAllButton.addSelectionListener(new SelectionAdapter() {\r
9ccc6d01 364 @Override\r
c3c5c786
FC
365 public void widgetSelected(SelectionEvent e) {\r
366 updatePreviews(true);\r
367 }\r
368 });\r
369 \r
370 Button legendButton = new Button(sashBottom, SWT.PUSH);\r
371 legendButton.setImage(helpImage);\r
3b38ea61 372 legendButton.setToolTipText(Messages.CustomTxtParserInputWizardPage_previewLegend);\r
c3c5c786
FC
373 legendButton.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));\r
374 legendButton.addSelectionListener(new SelectionAdapter() {\r
9ccc6d01 375 @Override\r
c3c5c786
FC
376 public void widgetSelected(SelectionEvent e) {\r
377 openLegend();\r
378 }\r
379 });\r
380 \r
381 inputText = new StyledText(sashBottom, SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL);\r
382 if (fixedFont == null) {\r
3b38ea61
FC
383 if (System.getProperty("os.name").contains("Windows")) { //$NON-NLS-1$ //$NON-NLS-2$\r
384 fixedFont = new Font(Display.getCurrent(), new FontData("Courier New", 10, SWT.NORMAL)); //$NON-NLS-1$\r
c3c5c786 385 } else {\r
3b38ea61 386 fixedFont = new Font(Display.getCurrent(), new FontData("Monospace", 10, SWT.NORMAL)); //$NON-NLS-1$\r
c3c5c786
FC
387 }\r
388 }\r
389 inputText.setFont(fixedFont);\r
390 gd = new GridData(SWT.FILL, SWT.FILL, true, true, 3, 1);\r
391 gd.heightHint = inputText.computeSize(SWT.DEFAULT, inputText.getLineHeight() * 4).y;\r
392 gd.widthHint = 800;\r
393 inputText.setLayoutData(gd);\r
394 inputText.setText(getSelectionText());\r
395 inputText.addModifyListener(updateListener);\r
396\r
397 vSash.setWeights(new int[] {hSash.computeSize(SWT.DEFAULT, SWT.DEFAULT).y, sashBottom.computeSize(SWT.DEFAULT, SWT.DEFAULT).y});\r
398 \r
399 setControl(container);\r
400 \r
401 validate();\r
402 updatePreviews();\r
403 }\r
404\r
405 private class InputLineTreeNodeContentProvider implements ITreeContentProvider {\r
406\r
d4011df2 407 @Override\r
c3c5c786
FC
408 public Object[] getElements(Object inputElement) {\r
409 return ((List<?>) inputElement).toArray();\r
410 }\r
411\r
d4011df2 412 @Override\r
c3c5c786
FC
413 public Object[] getChildren(Object parentElement) {\r
414 InputLine inputLine = (InputLine) parentElement;\r
415 if (inputLine.childrenInputs == null) return new InputLine[0];\r
416 return inputLine.childrenInputs.toArray();\r
417 }\r
418\r
d4011df2 419 @Override\r
c3c5c786
FC
420 public boolean hasChildren(Object element) {\r
421 InputLine inputLine = (InputLine) element;\r
422 return (inputLine.childrenInputs != null && inputLine.childrenInputs.size() > 0);\r
423 }\r
424\r
d4011df2 425 @Override\r
c3c5c786
FC
426 public void dispose() {\r
427 }\r
428\r
d4011df2 429 @Override\r
c3c5c786
FC
430 public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {\r
431 }\r
432\r
d4011df2 433 @Override\r
c3c5c786
FC
434 public Object getParent(Object element) {\r
435 InputLine inputLine = (InputLine) element;\r
436 return inputLine.parentInput;\r
437 }\r
438 }\r
439 \r
440 private class InputLineTreeLabelProvider extends ColumnLabelProvider {\r
441\r
442 @Override\r
443 public Image getImage(Object element) {\r
444 return lineImage;\r
445 }\r
446\r
447 @Override\r
448 public String getText(Object element) {\r
449 InputLine inputLine = (InputLine) element;\r
450 if (inputLine.parentInput == null) {\r
3b38ea61 451 return "Root Line " + getName(inputLine) + " " + inputLine.cardinality.toString() + " : " + inputLine.getRegex(); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$\r
c3c5c786 452 } else {\r
3b38ea61 453 return "Line " + getName(inputLine) + " " + inputLine.cardinality.toString() + " : " + inputLine.getRegex(); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$\r
c3c5c786
FC
454 }\r
455 }\r
456 }\r
457\r
458 private class InputLineTreeSelectionChangedListener implements ISelectionChangedListener {\r
d4011df2 459 @Override\r
c3c5c786
FC
460 public void selectionChanged(SelectionChangedEvent event) {\r
461 if (selectedLine != null) {\r
462 selectedLine.dispose();\r
463 }\r
464 if (!(event.getSelection().isEmpty()) && event.getSelection() instanceof IStructuredSelection) {\r
465 IStructuredSelection selection = (IStructuredSelection) event.getSelection();\r
466 InputLine inputLine = (InputLine) selection.getFirstElement();\r
467 selectedLine = new Line(lineContainer, getName(inputLine), inputLine);\r
468 lineContainer.layout();\r
469 lineScrolledComposite.setMinSize(lineContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT).x, lineContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT).y-1);\r
470 container.layout();\r
471 validate();\r
472 updatePreviews();\r
473 }\r
474 }\r
475 }\r
476 \r
477 /* (non-Javadoc)\r
478 * @see org.eclipse.jface.dialogs.DialogPage#dispose()\r
479 */\r
480 @Override\r
481 public void dispose() {\r
482 if (fixedFont != null) {\r
483 fixedFont.dispose();\r
484 fixedFont = null;\r
485 }\r
486 super.dispose();\r
487 }\r
488\r
489 private void loadDefinition(CustomTxtTraceDefinition def) {\r
490 logtypeText.setText(def.definitionName);\r
491 timestampOutputFormatText.setText(def.timeStampOutputFormat);\r
492 treeViewer.setInput(def.inputs);\r
493 if (def.inputs.size() > 0) {\r
494 InputLine inputLine = def.inputs.get(0);\r
495 treeViewer.setSelection(new StructuredSelection(inputLine));\r
496 }\r
497 }\r
498\r
499 private String getName(InputLine inputLine) {\r
500 if (inputLine.parentInput == null) {\r
501 return Integer.toString(definition.inputs.indexOf(inputLine)+1);\r
502 }\r
3b38ea61 503 return getName(inputLine.parentInput) + "." + Integer.toString(inputLine.parentInput.childrenInputs.indexOf(inputLine)+1); //$NON-NLS-1$\r
c3c5c786
FC
504 }\r
505\r
506 public List<String> getInputNames() {\r
507 List<String> inputs = new ArrayList<String>();\r
508 for (InputLine inputLine : definition.inputs) {\r
509 for (String inputName : getInputNames(inputLine)) {\r
510 if (!inputs.contains(inputName)) {\r
511 inputs.add(inputName);\r
512 }\r
513 }\r
514 }\r
515 return inputs;\r
516 }\r
517 \r
518 public List<String> getInputNames(InputLine inputLine) {\r
519 List<String> inputs = new ArrayList<String>();\r
520 if (inputLine.columns != null) {\r
521 for (InputData inputData : inputLine.columns) {\r
522 String inputName = inputData.name;\r
523 if (!inputs.contains(inputName)) {\r
524 inputs.add(inputName);\r
525 }\r
526 }\r
527 }\r
528 if (inputLine.childrenInputs != null) {\r
529 for (InputLine childInputLine : inputLine.childrenInputs) {\r
530 for (String inputName : getInputNames(childInputLine)) {\r
531 if (!inputs.contains(inputName)) {\r
532 inputs.add(inputName);\r
533 }\r
534 }\r
535 }\r
536 }\r
537 return inputs;\r
538 }\r
539 \r
540 private void removeLine() {\r
541 selectedLine.dispose();\r
542 selectedLine = null;\r
543 lineContainer.layout();\r
544 lineScrolledComposite.setMinSize(lineContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT).x, lineContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT).y-1);\r
545 container.layout();\r
546 }\r
547\r
c3c5c786
FC
548 private String getSelectionText() {\r
549 if (this.selection instanceof IStructuredSelection) {\r
550 Object selection = ((IStructuredSelection)this.selection).getFirstElement();\r
551 if (selection instanceof IFile) {\r
552 IFile file = (IFile)selection;\r
553 try {\r
554 BufferedReader reader = new BufferedReader(new InputStreamReader(file.getContents()));\r
555 StringBuilder sb = new StringBuilder();\r
556 String line = null;\r
557 while ((line = reader.readLine()) != null) {\r
3b38ea61 558 sb.append(line + "\n"); //$NON-NLS-1$\r
c3c5c786
FC
559 }\r
560 return sb.toString();\r
561 } catch (CoreException e) {\r
3b38ea61 562 return ""; //$NON-NLS-1$\r
c3c5c786 563 } catch (IOException e) {\r
3b38ea61 564 return ""; //$NON-NLS-1$\r
c3c5c786
FC
565 }\r
566 }\r
567 }\r
3b38ea61 568 return ""; //$NON-NLS-1$\r
c3c5c786
FC
569 }\r
570 \r
571 private void updatePreviews() {\r
572 updatePreviews(false);\r
573 }\r
574\r
575 private void updatePreviews(boolean updateAll) {\r
576 if (inputText == null) {\r
577 // early update during construction\r
578 return;\r
579 }\r
580 inputText.setStyleRanges(new StyleRange[] {});\r
581 \r
582 Scanner scanner = new Scanner(inputText.getText());\r
3b38ea61 583 scanner.useDelimiter("\n"); //$NON-NLS-1$\r
c3c5c786
FC
584 int rawPos = 0;\r
585 String skip; // skip starting delimiters\r
3b38ea61 586 if ((skip = scanner.findWithinHorizon("\\A\n+", 0)) != null) { //$NON-NLS-1$\r
c3c5c786
FC
587 rawPos += skip.length();\r
588 }\r
589 \r
590 timeStampFormat = null;\r
591 if (selectedLine != null) {\r
592 for (InputGroup input : selectedLine.inputs) {\r
3b38ea61 593 input.previewText.setText(Messages.CustomTxtParserInputWizardPage_noMathcingLine);\r
c3c5c786
FC
594 }\r
595 }\r
596 \r
597 Map<String, String> data = new HashMap<String, String>();\r
598 int rootLineMatches = 0;\r
599 String firstEntryTimeStamp = null;\r
600 String firstEntryTimeStampInputFormat = null;\r
601 String log = null;\r
602 event: \r
603 while (log != null || scanner.hasNext()) {\r
604 if (rootLineMatches > 0 && !updateAll) {\r
605 break;\r
606 }\r
607 if (log == null) {\r
608 log = scanner.next();\r
609 }\r
610 int length = log.length();\r
611 for (InputLine rootInputLine : definition.inputs) {\r
612 Pattern pattern;\r
613 try {\r
614 pattern = rootInputLine.getPattern();\r
615 } catch (PatternSyntaxException e) {\r
616 continue;\r
617 }\r
618 Matcher matcher = pattern.matcher(log);\r
619 if (matcher.find()) {\r
620 rootLineMatches++;\r
621 inputText.setStyleRange(new StyleRange(rawPos, length,\r
622 COLOR_BLACK, COLOR_YELLOW, SWT.ITALIC));\r
623 data = new HashMap<String, String>();\r
624 timeStampFormat = null;\r
625 updatePreviewLine(rootInputLine, matcher, data, rawPos, rootLineMatches);\r
626 if (rootLineMatches == 1) {\r
627 firstEntryTimeStamp = data.get(CustomTxtTraceDefinition.TAG_TIMESTAMP);\r
628 firstEntryTimeStampInputFormat = timeStampFormat;\r
629 }\r
630 HashMap<InputLine, Integer> countMap = new HashMap<InputLine, Integer>();\r
631 InputLine currentInput = null;\r
632 if (rootInputLine.childrenInputs != null && rootInputLine.childrenInputs.size() > 0) {\r
633 currentInput = rootInputLine.childrenInputs.get(0);\r
634 countMap.put(currentInput, 0);\r
635 }\r
636 rawPos += length + 1; // +1 for \n\r
637 while (scanner.hasNext()) {\r
638 log = scanner.next();\r
639 length = log.length();\r
640 boolean processed = false;\r
641 if (currentInput == null) {\r
642 for (InputLine input : definition.inputs) {\r
643 matcher = input.getPattern().matcher(log);\r
644 if (matcher.find()) {\r
645 continue event;\r
646 }\r
647 }\r
648 } else {\r
649 if (countMap.get(currentInput) >= currentInput.getMinCount()) {\r
650 List<InputLine> nextInputs = currentInput.getNextInputs(countMap);\r
651 if (nextInputs.size() == 0 || nextInputs.get(nextInputs.size() - 1).getMinCount() == 0) {\r
652 for (InputLine input : definition.inputs) {\r
653 matcher = input.getPattern().matcher(log);\r
654 if (matcher.find()) {\r
655 continue event;\r
656 }\r
657 }\r
658 }\r
659 for (InputLine input : nextInputs) {\r
660 matcher = input.getPattern().matcher(log);\r
661 if (matcher.find()) {\r
662 inputText.setStyleRange(new StyleRange(rawPos, length,\r
663 COLOR_BLACK, COLOR_LIGHT_YELLOW, SWT.ITALIC));\r
664 currentInput = input;\r
665 updatePreviewLine(currentInput, matcher, data, rawPos, rootLineMatches);\r
666 if (countMap.get(currentInput) == null) {\r
667 countMap.put(currentInput, 1);\r
668 } else {\r
669 countMap.put(currentInput, countMap.get(currentInput) + 1);\r
670 }\r
671 Iterator<InputLine> iter = countMap.keySet().iterator();\r
672 while (iter.hasNext()) {\r
673 InputLine inputLine = iter.next();\r
674 if (inputLine.level > currentInput.level) {\r
675 iter.remove();\r
676 }\r
677 }\r
678 if (currentInput.childrenInputs != null && currentInput.childrenInputs.size() > 0) {\r
679 currentInput = currentInput.childrenInputs.get(0);\r
680 countMap.put(currentInput, 0);\r
681 } else {\r
682 if (countMap.get(currentInput) >= currentInput.getMaxCount()) {\r
683 if (currentInput.getNextInputs(countMap).size() > 0) {\r
684 currentInput = currentInput.getNextInputs(countMap).get(0);\r
685 if (countMap.get(currentInput) == null) {\r
686 countMap.put(currentInput, 0);\r
687 }\r
688 iter = countMap.keySet().iterator();\r
689 while (iter.hasNext()) {\r
690 InputLine inputLine = iter.next();\r
691 if (inputLine.level > currentInput.level) {\r
692 iter.remove();\r
693 }\r
694 }\r
695 } else {\r
696 currentInput = null;\r
697 }\r
698 }\r
699 }\r
700 processed = true;\r
701 break;\r
702 }\r
703 }\r
704 }\r
705 if (! processed) {\r
706 matcher = currentInput.getPattern().matcher(log);\r
707 if (matcher.find()) {\r
708 inputText.setStyleRange(new StyleRange(rawPos, length,\r
709 COLOR_BLACK, COLOR_LIGHT_YELLOW, SWT.ITALIC));\r
710 updatePreviewLine(currentInput, matcher, data, rawPos, rootLineMatches);\r
711 countMap.put(currentInput, countMap.get(currentInput) + 1);\r
712 if (currentInput.childrenInputs != null && currentInput.childrenInputs.size() > 0) {\r
713 currentInput = currentInput.childrenInputs.get(0);\r
714 countMap.put(currentInput, 0);\r
715 } else {\r
716 if (countMap.get(currentInput) >= currentInput.getMaxCount()) {\r
717 if (currentInput.getNextInputs(countMap).size() > 0) {\r
718 currentInput = currentInput.getNextInputs(countMap).get(0);\r
719 if (countMap.get(currentInput) == null) {\r
720 countMap.put(currentInput, 0);\r
721 }\r
722 Iterator<InputLine> iter = countMap.keySet().iterator();\r
723 while (iter.hasNext()) {\r
724 InputLine inputLine = iter.next();\r
725 if (inputLine.level > currentInput.level) {\r
726 iter.remove();\r
727 }\r
728 }\r
729 } else {\r
730 currentInput = null;\r
731 }\r
732 }\r
733 }\r
734 }\r
735 }\r
736 }\r
737 rawPos += length + 1; // +1 for \n\r
738 }\r
739\r
740 break;\r
741 }\r
742 }\r
743 rawPos += length + 1; // +1 for \n\r
744 log = null;\r
745 }\r
746 scanner.close();\r
747 if (rootLineMatches == 1) {\r
748 firstEntryTimeStamp = data.get(CustomTxtTraceDefinition.TAG_TIMESTAMP);\r
749 firstEntryTimeStampInputFormat = timeStampFormat;\r
750 }\r
751 if (firstEntryTimeStamp == null) {\r
3b38ea61 752 timestampPreviewText.setText(Messages.CustomTxtParserInputWizardPage_noTimestampGroup);\r
c3c5c786
FC
753 if (selectedLine != null) {\r
754 for (InputGroup group : selectedLine.inputs) {\r
755 if (group.tagCombo.getText().equals(CustomTxtTraceDefinition.TAG_TIMESTAMP)) {\r
3b38ea61 756 timestampPreviewText.setText(Messages.CustomTxtParserInputWizardPage_noMatchingTimestamp);\r
c3c5c786
FC
757 break;\r
758 }\r
759 }\r
760 }\r
761 } else {\r
762 try {\r
763 SimpleDateFormat dateFormat = new SimpleDateFormat(firstEntryTimeStampInputFormat);\r
764 Date date = dateFormat.parse(firstEntryTimeStamp);\r
765 dateFormat = new SimpleDateFormat(timestampOutputFormatText.getText().trim());\r
766 timestampPreviewText.setText(dateFormat.format(date));\r
767 } catch (ParseException e) {\r
b9763f53 768 timestampPreviewText.setText("*parse exception* [" + firstEntryTimeStamp + "] <> [" + firstEntryTimeStampInputFormat + "]"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$\r
c3c5c786 769 } catch (IllegalArgumentException e) {\r
b9763f53 770 timestampPreviewText.setText("*parse exception* [Illegal Argument]"); //$NON-NLS-1$\r
c3c5c786
FC
771 }\r
772\r
773 }\r
774 }\r
775\r
776 private void updatePreviewLine(InputLine line, Matcher matcher, Map<String, String> data, int rawPos, int rootLineMatches) {\r
777 for (int i = 0; i < line.columns.size(); i++) {\r
778 InputData input = line.columns.get(i);\r
779 if (i < matcher.groupCount() && matcher.group(i+1) != null) {\r
780 if (line.parentInput == null) {\r
781 inputText.setStyleRange(new StyleRange(rawPos + matcher.start(i+1), matcher.end(i+1) - matcher.start(i+1),\r
782 COLOR_BLACK, COLOR_GREEN, SWT.BOLD));\r
783 } else {\r
784 inputText.setStyleRange(new StyleRange(rawPos + matcher.start(i+1), matcher.end(i+1) - matcher.start(i+1),\r
785 COLOR_BLACK, COLOR_LIGHT_GREEN, SWT.BOLD));\r
786 }\r
787 String value = matcher.group(i+1).trim();\r
788 if (selectedLine != null && selectedLine.inputLine.equals(line) && rootLineMatches == 1) {\r
3b38ea61 789 if (selectedLine.inputs.get(i).previewText.getText().equals(Messages.CustomTxtParserInputWizardPage_noMatchingLine)) {\r
c3c5c786
FC
790 selectedLine.inputs.get(i).previewText.setText(value);\r
791 }\r
792 }\r
793 if (value.length() == 0) {\r
794 continue;\r
795 }\r
796 if (input.action == CustomTxtTraceDefinition.ACTION_SET) {\r
797 data.put(input.name, value);\r
798 if (input.name.equals(CustomTxtTraceDefinition.TAG_TIMESTAMP)) {\r
799 timeStampFormat = input.format;\r
800 }\r
801 } else if (input.action == CustomTxtTraceDefinition.ACTION_APPEND) {\r
802 String s = data.get(input.name);\r
803 if (s != null) {\r
804 data.put(input.name, s + value);\r
805 } else {\r
806 data.put(input.name, value);\r
807 }\r
808 if (input.name.equals(CustomTxtTraceDefinition.TAG_TIMESTAMP)) {\r
809 if (timeStampFormat != null) {\r
810 timeStampFormat += input.format;\r
811 } else {\r
812 timeStampFormat = input.format;\r
813 }\r
814 }\r
815 } else if (input.action == CustomTxtTraceDefinition.ACTION_APPEND_WITH_SEPARATOR) {\r
816 String s = data.get(input.name);\r
817 if (s != null) {\r
3b38ea61 818 data.put(input.name, s + " | " + value); //$NON-NLS-1$\r
c3c5c786
FC
819 } else {\r
820 data.put(input.name, value);\r
821 }\r
822 if (input.name.equals(CustomTxtTraceDefinition.TAG_TIMESTAMP)) {\r
823 if (timeStampFormat != null) {\r
3b38ea61 824 timeStampFormat += " | " + input.format; //$NON-NLS-1$\r
c3c5c786
FC
825 } else {\r
826 timeStampFormat = input.format;\r
827 }\r
828 }\r
829 }\r
830 } else {\r
831 if (selectedLine != null && selectedLine.inputLine.equals(line) && rootLineMatches == 1) {\r
3b38ea61
FC
832 if (selectedLine.inputs.get(i).previewText.getText().equals(Messages.CustomTxtParserInputWizardPage_noMatchingLine)) {\r
833 selectedLine.inputs.get(i).previewText.setText(Messages.CustomTxtParserInputWizardPage_noMatchingGroup);\r
c3c5c786
FC
834 }\r
835 }\r
836 }\r
837 }\r
838 // highlight the matching groups that have no corresponponding input\r
839 for (int i = line.columns.size(); i < matcher.groupCount(); i++) {\r
840 if (matcher.group(i+1) != null) {\r
841 if (line.parentInput == null) {\r
842 inputText.setStyleRange(new StyleRange(rawPos + matcher.start(i+1), matcher.end(i+1) - matcher.start(i+1),\r
843 COLOR_BLACK, COLOR_MAGENTA));\r
844 } else {\r
845 inputText.setStyleRange(new StyleRange(rawPos + matcher.start(i+1), matcher.end(i+1) - matcher.start(i+1),\r
846 COLOR_BLACK, COLOR_LIGHT_MAGENTA));\r
847 }\r
848 }\r
849 }\r
850 }\r
851 \r
852 private void openHelpShell(String url) {\r
853 if (helpBrowser != null && !helpBrowser.isDisposed()) {\r
854 helpBrowser.getShell().setActive();\r
855 if (!helpBrowser.getUrl().equals(url)) {\r
856 helpBrowser.setUrl(url);\r
857 }\r
858 return;\r
859 }\r
860 final Shell helpShell = new Shell(getShell(), SWT.SHELL_TRIM);\r
861 helpShell.setLayout(new FillLayout());\r
862 helpBrowser = new Browser(helpShell, SWT.NONE);\r
863 helpBrowser.addTitleListener(new TitleListener() {\r
d4011df2 864 @Override\r
c3c5c786
FC
865 public void changed(TitleEvent event) {\r
866 helpShell.setText(event.title);\r
867 }\r
868 });\r
869 helpBrowser.setBounds(0,0,600,400);\r
870 helpShell.pack();\r
871 helpShell.open();\r
872 helpBrowser.setUrl(url);\r
873 }\r
874\r
875 private void openLegend() {\r
3b38ea61
FC
876 final String CG = Messages.CustomTxtParserInputWizardPage_capturedGroup;\r
877 final String UCG = Messages.CustomTxtParserInputWizardPage_unidentifiedCaptureGroup;\r
878 final String UT = Messages.CustomTxtParserInputWizardPage_uncapturedText;\r
c3c5c786 879 int line1start = 0;\r
3b38ea61 880 String line1 = Messages.CustomTxtParserInputWizardPage_nonMatchingLine;\r
c3c5c786 881 int line2start = line1start + line1.length();\r
b9763f53 882 String line2 = Messages.CustomTxtParserInputWizardPage_matchingLineRoot + CG + " " + UCG + " " + UT + " \n"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$\r
c3c5c786 883 int line3start = line2start + line2.length();\r
b9763f53 884 String line3 = Messages.CustomTxtParserInputWizardPage_matchingOtherLine + CG + " " + UCG + " " + UT + " \n"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$\r
c3c5c786 885 int line4start = line3start + line3.length();\r
b9763f53 886 String line4 = Messages.CustomTxtParserInputWizardPage_matchingOtherLine + CG + " " + UCG + " " + UT + " \n"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$\r
c3c5c786 887 int line5start = line4start + line4.length();\r
3b38ea61 888 String line5 = Messages.CustomTxtParserInputWizardPage_nonMatchingLine;\r
c3c5c786 889 int line6start = line5start + line5.length();\r
b9763f53 890 String line6 = Messages.CustomTxtParserInputWizardPage_matchingRootLine + CG + " " + UCG + " " + UT + " \n"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ \r
c3c5c786
FC
891 \r
892 final Shell legendShell = new Shell(getShell(), SWT.DIALOG_TRIM);\r
893 legendShell.setLayout(new FillLayout());\r
894 StyledText legendText = new StyledText(legendShell, SWT.MULTI);\r
895 legendText.setFont(fixedFont);\r
896 legendText.setText(line1 + line2 + line3 + line4 + line5 + line6);\r
897 legendText.setStyleRange(new StyleRange(line2start, line2.length(), COLOR_BLACK, COLOR_YELLOW, SWT.ITALIC));\r
898 legendText.setStyleRange(new StyleRange(line3start, line3.length(), COLOR_BLACK, COLOR_LIGHT_YELLOW, SWT.ITALIC));\r
899 legendText.setStyleRange(new StyleRange(line4start, line4.length(), COLOR_BLACK, COLOR_LIGHT_YELLOW, SWT.ITALIC));\r
900 legendText.setStyleRange(new StyleRange(line6start, line6.length(), COLOR_BLACK, COLOR_YELLOW, SWT.ITALIC));\r
901 legendText.setStyleRange(new StyleRange(line2start + line2.indexOf(CG), CG.length(), COLOR_BLACK, COLOR_GREEN, SWT.BOLD));\r
902 legendText.setStyleRange(new StyleRange(line2start + line2.indexOf(UCG), UCG.length(), COLOR_BLACK, COLOR_MAGENTA));\r
903 legendText.setStyleRange(new StyleRange(line3start + line3.indexOf(CG), CG.length(), COLOR_BLACK, COLOR_LIGHT_GREEN, SWT.BOLD));\r
904 legendText.setStyleRange(new StyleRange(line3start + line3.indexOf(UCG), UCG.length(), COLOR_BLACK, COLOR_LIGHT_MAGENTA));\r
905 legendText.setStyleRange(new StyleRange(line4start + line4.indexOf(CG), CG.length(), COLOR_BLACK, COLOR_LIGHT_GREEN, SWT.BOLD));\r
906 legendText.setStyleRange(new StyleRange(line4start + line4.indexOf(UCG), UCG.length(), COLOR_BLACK, COLOR_LIGHT_MAGENTA));\r
907 legendText.setStyleRange(new StyleRange(line6start + line6.indexOf(CG), CG.length(), COLOR_BLACK, COLOR_GREEN, SWT.BOLD));\r
908 legendText.setStyleRange(new StyleRange(line6start + line6.indexOf(UCG), UCG.length(), COLOR_BLACK, COLOR_MAGENTA));\r
3b38ea61 909 legendShell.setText(Messages.CustomTxtParserInputWizardPage_previewLegend);\r
c3c5c786
FC
910 legendShell.pack();\r
911 legendShell.open();\r
912 }\r
913\r
914 private class UpdateListener implements ModifyListener, SelectionListener {\r
915\r
d4011df2 916 @Override\r
c3c5c786
FC
917 public void modifyText(ModifyEvent e) {\r
918 validate();\r
919 updatePreviews();\r
920 }\r
921\r
d4011df2 922 @Override\r
c3c5c786
FC
923 public void widgetDefaultSelected(SelectionEvent e) {\r
924 validate();\r
925 updatePreviews();\r
926 }\r
927\r
d4011df2 928 @Override\r
c3c5c786
FC
929 public void widgetSelected(SelectionEvent e) {\r
930 validate();\r
931 updatePreviews();\r
932 }\r
933\r
934 }\r
935 \r
936 private class Line {\r
3b38ea61 937 private static final String INFINITY_STRING = "\u221E"; //$NON-NLS-1$\r
c3c5c786
FC
938 @SuppressWarnings("unused")\r
939 String name;\r
940 InputLine inputLine;\r
941 Group group;\r
942 Composite labelComposite;\r
943 Text regexText;\r
944 Composite cardinalityContainer;\r
945 Combo cardinalityCombo;\r
946 Label cardinalityMinLabel;\r
947 Text cardinalityMinText;\r
948 Label cardinalityMaxLabel;\r
949 Text cardinalityMaxText;\r
950 Button infiniteButton;\r
951 ArrayList<InputGroup> inputs = new ArrayList<InputGroup>();\r
952 Button addGroupButton;\r
953 Label addGroupLabel;\r
954 \r
955 public Line(Composite parent, String name, InputLine inputLine) {\r
956 this.name = name;\r
957 this.inputLine = inputLine;\r
958 \r
959 group = new Group(parent, SWT.NONE);\r
960 group.setText(name);\r
961 group.setLayout(new GridLayout(2, false));\r
962 group.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));\r
963 \r
964 labelComposite = new Composite(group, SWT.FILL);\r
965 GridLayout labelLayout = new GridLayout(1, false);\r
966 labelLayout.marginWidth = 0;\r
967 labelLayout.marginHeight = 0;\r
968 labelComposite.setLayout(labelLayout);\r
969 labelComposite.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));\r
970 \r
971 Label label = new Label(labelComposite, SWT.NULL);\r
3b38ea61 972 label.setText(Messages.CustomTxtParserInputWizardPage_regularExpression);\r
c3c5c786
FC
973 \r
974 Composite regexContainer = new Composite(group, SWT.NONE);\r
975 GridLayout regexLayout = new GridLayout(2, false);\r
976 regexLayout.marginHeight = 0;\r
977 regexLayout.marginWidth = 0;\r
978 regexContainer.setLayout(regexLayout);\r
979 regexContainer.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));\r
980 \r
981 regexText = new Text(regexContainer, SWT.BORDER | SWT.SINGLE);\r
982 GridData gd = new GridData(SWT.FILL, SWT.CENTER, true, false);\r
983 gd.widthHint = 0;\r
984 regexText.setLayoutData(gd);\r
985 regexText.setText(inputLine.getRegex());\r
986 regexText.addModifyListener(updateListener);\r
987 \r
988 Button regexHelpButton = new Button(regexContainer, SWT.PUSH);\r
989 regexHelpButton.setImage(helpImage);\r
3b38ea61 990 regexHelpButton.setToolTipText(Messages.CustomTxtParserInputWizardPage_regularExpressionHelp);\r
c3c5c786 991 regexHelpButton.addSelectionListener(new SelectionAdapter() {\r
9ccc6d01
FC
992 @Override\r
993 public void widgetSelected(SelectionEvent e) {\r
c3c5c786
FC
994 openHelpShell(PATTERN_URL);\r
995 }\r
996 });\r
997 \r
998 label = new Label(group, SWT.NONE);\r
3b38ea61 999 label.setText(Messages.CustomTxtParserInputWizardPage_cardinality);\r
c3c5c786
FC
1000 label.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));\r
1001 \r
1002 cardinalityContainer = new Composite(group, SWT.NONE);\r
1003 GridLayout cardinalityLayout = new GridLayout(6, false);\r
1004 cardinalityLayout.marginHeight = 0;\r
1005 cardinalityLayout.marginWidth = 0;\r
1006 cardinalityContainer.setLayout(cardinalityLayout);\r
1007 cardinalityContainer.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));\r
1008\r
1009 cardinalityCombo = new Combo(cardinalityContainer, SWT.DROP_DOWN | SWT.READ_ONLY);\r
1010 cardinalityCombo.setItems(new String[] {\r
1011 Cardinality.ZERO_OR_MORE.toString(),\r
1012 Cardinality.ONE_OR_MORE.toString(),\r
1013 Cardinality.ZERO_OR_ONE.toString(),\r
1014 Cardinality.ONE.toString(),\r
3b38ea61 1015 "(?,?)"}); //$NON-NLS-1$\r
c3c5c786 1016 cardinalityCombo.addSelectionListener(new SelectionListener(){\r
d4011df2 1017 @Override\r
c3c5c786 1018 public void widgetDefaultSelected(SelectionEvent e) {}\r
d4011df2 1019 @Override\r
c3c5c786
FC
1020 public void widgetSelected(SelectionEvent e) {\r
1021 switch (cardinalityCombo.getSelectionIndex()) {\r
1022 case 4: //(?,?)\r
1023 cardinalityMinLabel.setVisible(true);\r
1024 cardinalityMinText.setVisible(true);\r
1025 cardinalityMaxLabel.setVisible(true);\r
1026 cardinalityMaxText.setVisible(true);\r
1027 infiniteButton.setVisible(true);\r
1028 break;\r
1029 default:\r
1030 cardinalityMinLabel.setVisible(false);\r
1031 cardinalityMinText.setVisible(false);\r
1032 cardinalityMaxLabel.setVisible(false);\r
1033 cardinalityMaxText.setVisible(false);\r
1034 infiniteButton.setVisible(false);\r
1035 break;\r
1036 }\r
1037 cardinalityContainer.layout();\r
1038 validate();\r
1039 updatePreviews();\r
1040 }});\r
1041 \r
1042 cardinalityMinLabel = new Label(cardinalityContainer, SWT.NONE);\r
1043 cardinalityMinLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));\r
3b38ea61 1044 cardinalityMinLabel.setText(Messages.CustomTxtParserInputWizardPage_min);\r
c3c5c786
FC
1045 cardinalityMinLabel.setVisible(false);\r
1046 \r
1047 cardinalityMinText = new Text(cardinalityContainer, SWT.BORDER | SWT.SINGLE);\r
1048 gd = new GridData(SWT.CENTER, SWT.CENTER, false, false);\r
1049 gd.widthHint = 20;\r
1050 cardinalityMinText.setLayoutData(gd);\r
1051 cardinalityMinText.setVisible(false);\r
1052 \r
1053 cardinalityMaxLabel = new Label(cardinalityContainer, SWT.NONE);\r
1054 cardinalityMaxLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));\r
3b38ea61 1055 cardinalityMaxLabel.setText(Messages.CustomTxtParserInputWizardPage_max);\r
c3c5c786
FC
1056 cardinalityMaxLabel.setVisible(false);\r
1057 \r
1058 cardinalityMaxText = new Text(cardinalityContainer, SWT.BORDER | SWT.SINGLE);\r
1059 gd = new GridData(SWT.CENTER, SWT.CENTER, false, false);\r
1060 gd.widthHint = 20;\r
1061 cardinalityMaxText.setLayoutData(gd);\r
1062 cardinalityMaxText.setVisible(false);\r
1063\r
1064 infiniteButton = new Button(cardinalityContainer, SWT.PUSH);\r
1065 infiniteButton.setText(INFINITY_STRING);\r
1066 infiniteButton.setVisible(false);\r
1067 infiniteButton.addSelectionListener(new SelectionAdapter(){\r
1068 @Override\r
1069 public void widgetSelected(SelectionEvent e) {\r
1070 cardinalityMaxText.setText(INFINITY_STRING);\r
1071 }});\r
1072\r
1073 if (inputLine.cardinality.equals(Cardinality.ZERO_OR_MORE)) {\r
1074 cardinalityCombo.select(0);\r
1075 } else if (inputLine.cardinality.equals(Cardinality.ONE_OR_MORE)) {\r
1076 cardinalityCombo.select(1);\r
1077 } else if (inputLine.cardinality.equals(Cardinality.ZERO_OR_ONE)) {\r
1078 cardinalityCombo.select(2);\r
1079 } else if (inputLine.cardinality.equals(Cardinality.ONE)) {\r
1080 cardinalityCombo.select(3);\r
1081 } else {\r
1082 cardinalityCombo.select(4);\r
1083 cardinalityMinLabel.setVisible(true);\r
1084 cardinalityMinText.setVisible(true);\r
1085 if (inputLine.getMinCount() >= 0) {\r
1086 cardinalityMinText.setText(Integer.toString(inputLine.getMinCount()));\r
1087 }\r
1088 cardinalityMaxLabel.setVisible(true);\r
1089 cardinalityMaxText.setVisible(true);\r
1090 if (inputLine.getMaxCount() == Cardinality.INF) {\r
1091 cardinalityMaxText.setText(INFINITY_STRING);\r
1092 } else if (inputLine.getMaxCount() >= 0) {\r
1093 cardinalityMaxText.setText(Integer.toString(inputLine.getMaxCount()));\r
1094 }\r
1095 infiniteButton.setVisible(true);\r
1096 }\r
1097 \r
1098 VerifyListener digitsListener = new VerifyListener() {\r
d4011df2 1099 @Override\r
c3c5c786
FC
1100 public void verifyText(VerifyEvent e) {\r
1101 if (e.text.equals(INFINITY_STRING)) {\r
1102 e.doit = e.widget == cardinalityMaxText && e.start == 0 && e.end == ((Text) e.widget).getText().length();\r
1103 } else {\r
1104 if (((Text) e.widget).getText().equals(INFINITY_STRING)) {\r
1105 e.doit = e.start == 0 && e.end == ((Text) e.widget).getText().length();\r
1106 }\r
1107 for (int i = 0; i < e.text.length(); i++) {\r
1108 if (!Character.isDigit(e.text.charAt(i))) {\r
1109 e.doit = false;\r
1110 break;\r
1111 }\r
1112 }\r
1113 }\r
1114 }};\r
1115 \r
1116 cardinalityMinText.addModifyListener(updateListener);\r
1117 cardinalityMaxText.addModifyListener(updateListener);\r
1118 cardinalityMinText.addVerifyListener(digitsListener);\r
1119 cardinalityMaxText.addVerifyListener(digitsListener);\r
1120\r
1121 if (inputLine.columns != null) {\r
1122 for (InputData inputData : inputLine.columns) {\r
1123 InputGroup inputGroup = new InputGroup(group, this, inputs.size()+1);\r
1124 if (inputData.name.equals(CustomTxtTraceDefinition.TAG_TIMESTAMP)) {\r
1125 inputGroup.tagCombo.select(0);\r
1126 inputGroup.tagText.setText(inputData.format);\r
3b38ea61 1127 inputGroup.tagLabel.setText(Messages.CustomTxtParserInputWizardPage_format);\r
c3c5c786
FC
1128 inputGroup.tagLabel.setVisible(true);\r
1129 inputGroup.tagText.setVisible(true);\r
1130 inputGroup.tagText.addModifyListener(updateListener);\r
1131 } else if (inputData.name.equals(CustomTxtTraceDefinition.TAG_MESSAGE)) {\r
1132 inputGroup.tagCombo.select(1);\r
1133 } else {\r
1134 inputGroup.tagCombo.select(2);\r
1135 inputGroup.tagText.setText(inputData.name);\r
3b38ea61 1136 inputGroup.tagLabel.setText(Messages.CustomTxtParserInputWizardPage_name);\r
c3c5c786
FC
1137 inputGroup.tagLabel.setVisible(true);\r
1138 inputGroup.tagText.setVisible(true);\r
1139 inputGroup.tagText.addModifyListener(updateListener);\r
1140 }\r
1141 inputGroup.actionCombo.select(inputData.action);\r
1142 inputs.add(inputGroup);\r
1143 }\r
1144 }\r
1145 \r
1146 createAddGroupButton();\r
1147 }\r
1148\r
1149 private void createAddGroupButton() {\r
1150 addGroupButton = new Button(group, SWT.PUSH);\r
1151 addGroupButton.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));\r
1152 addGroupButton.setImage(addImage);\r
3b38ea61 1153 addGroupButton.setToolTipText(Messages.CustomTxtParserInputWizardPage_addGroup);\r
c3c5c786 1154 addGroupButton.addSelectionListener(new SelectionAdapter() {\r
9ccc6d01 1155 @Override\r
c3c5c786
FC
1156 public void widgetSelected(SelectionEvent e) {\r
1157 removeAddGroupButton();\r
1158 inputs.add(new InputGroup(group, Line.this, inputs.size()+1));\r
1159 createAddGroupButton();\r
1160 lineContainer.layout();\r
1161 lineScrolledComposite.setMinSize(lineContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT).x, lineContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT).y-1);\r
1162 group.getParent().layout();\r
1163 validate();\r
1164 updatePreviews();\r
1165 }\r
1166 });\r
1167 \r
1168 addGroupLabel = new Label(group, SWT.NULL);\r
3b38ea61 1169 addGroupLabel.setText(Messages.CustomTxtParserInputWizardPage_newGroup);\r
c3c5c786
FC
1170 }\r
1171\r
1172 private void removeAddGroupButton() {\r
1173 addGroupButton.dispose();\r
1174 addGroupLabel.dispose();\r
1175 }\r
1176 \r
1177 private void removeInput(int inputNumber) {\r
1178 if (--inputNumber < inputs.size()) {\r
1179 inputs.remove(inputNumber).dispose();\r
1180 for (int i = inputNumber; i < inputs.size(); i++) {\r
1181 inputs.get(i).setInputNumber(i+1);\r
1182 }\r
1183 lineContainer.layout();\r
1184 lineScrolledComposite.setMinSize(lineContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT).x, lineContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT).y-1);\r
1185 group.getParent().layout();\r
1186 }\r
1187 }\r
1188 \r
1189// private void setName(String name) {\r
1190// this.name = name;\r
1191// group.setText("Line " + name);\r
1192// }\r
1193 \r
1194 private void dispose() {\r
1195 group.dispose();\r
1196 }\r
1197 \r
1198 private void extractInputs() {\r
1199 inputLine.setRegex(selectedLine.regexText.getText());\r
1200 switch (cardinalityCombo.getSelectionIndex()) {\r
1201 case 0:\r
1202 inputLine.cardinality = Cardinality.ZERO_OR_MORE;\r
1203 break;\r
1204 case 1:\r
1205 inputLine.cardinality = Cardinality.ONE_OR_MORE;\r
1206 break;\r
1207 case 2:\r
1208 inputLine.cardinality = Cardinality.ZERO_OR_ONE;\r
1209 break;\r
1210 case 3:\r
1211 inputLine.cardinality = Cardinality.ONE;\r
1212 break;\r
1213 case 4: //(?,?)\r
1214 int min, max;\r
1215 try {\r
1216 min = Integer.parseInt(cardinalityMinText.getText());\r
1217 } catch (NumberFormatException e) {\r
1218 min = -1;\r
1219 }\r
1220 try {\r
1221 if (cardinalityMaxText.getText().equals(INFINITY_STRING)) {\r
1222 max = Cardinality.INF;\r
1223 } else {\r
1224 max = Integer.parseInt(cardinalityMaxText.getText());\r
1225 }\r
1226 } catch (NumberFormatException e) {\r
1227 max = -1;\r
1228 }\r
1229 inputLine.cardinality = new Cardinality(min, max);\r
1230 break;\r
1231 default:\r
1232 inputLine.cardinality = Cardinality.ZERO_OR_MORE;\r
1233 break;\r
1234 }\r
1235 inputLine.columns = new ArrayList<InputData>(inputs.size());\r
1236 for (int i = 0; i < inputs.size(); i++) {\r
1237 InputGroup group = inputs.get(i);\r
1238 InputData inputData = new InputData();\r
1239 if (group.tagCombo.getText().equals(CustomTxtTraceDefinition.TAG_OTHER)) {\r
1240 inputData.name = group.tagText.getText().trim();\r
1241 } else {\r
1242 inputData.name = group.tagCombo.getText();\r
1243 if (group.tagCombo.getText().equals(CustomTxtTraceDefinition.TAG_TIMESTAMP)) {\r
1244 inputData.format = group.tagText.getText().trim();\r
1245 }\r
1246 }\r
1247 inputData.action = group.actionCombo.getSelectionIndex();\r
1248 inputLine.columns.add(inputData);\r
1249 }\r
1250 }\r
1251 }\r
1252\r
1253 private class InputGroup {\r
1254 Line line;\r
1255 int inputNumber;\r
1256 \r
1257 // children of parent (must be disposed)\r
1258 Composite labelComposite;\r
1259 Composite tagComposite;\r
1260 Label previewLabel;\r
1261 Text previewText;\r
1262\r
1263 // children of labelComposite\r
1264 Label inputLabel;\r
1265 \r
1266 // children of tagComposite\r
1267 Combo tagCombo;\r
1268 Label tagLabel;\r
1269 Text tagText;\r
1270 Combo actionCombo;\r
1271 \r
1272 public InputGroup(Composite parent, Line line, int inputNumber) {\r
1273 this.line = line;\r
1274 this.inputNumber = inputNumber;\r
1275 \r
1276 labelComposite = new Composite(parent, SWT.FILL);\r
1277 GridLayout labelLayout = new GridLayout(2, false);\r
1278 labelLayout.marginWidth = 0;\r
1279 labelLayout.marginHeight = 0;\r
1280 labelComposite.setLayout(labelLayout);\r
1281 labelComposite.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));\r
1282 \r
1283 Button deleteButton = new Button(labelComposite, SWT.PUSH);\r
1284 deleteButton.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));\r
1285 deleteButton.setImage(deleteImage);\r
3b38ea61 1286 deleteButton.setToolTipText(Messages.CustomTxtParserInputWizardPage_removeGroup);\r
c3c5c786 1287 deleteButton.addSelectionListener(new SelectionAdapter() {\r
9ccc6d01 1288 @Override\r
c3c5c786
FC
1289 public void widgetSelected(SelectionEvent e) {\r
1290 InputGroup.this.line.removeInput(InputGroup.this.inputNumber);\r
1291 validate();\r
1292 updatePreviews();\r
1293 }\r
1294 });\r
1295 \r
1296 inputLabel = new Label(labelComposite, SWT.NULL);\r
1297 inputLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));\r
3b38ea61 1298 inputLabel.setText(Messages.CustomTxtParserInputWizardPage_group + inputNumber + ":"); //$NON-NLS-1$\r
c3c5c786
FC
1299\r
1300 tagComposite = new Composite(parent, SWT.FILL);\r
1301 GridLayout tagLayout = new GridLayout(4, false);\r
1302 tagLayout.marginWidth = 0;\r
1303 tagLayout.marginHeight = 0;\r
1304 tagComposite.setLayout(tagLayout);\r
1305 tagComposite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));\r
1306 \r
1307 tagCombo = new Combo(tagComposite, SWT.DROP_DOWN | SWT.READ_ONLY);\r
1308 tagCombo.setItems(new String[] {CustomTxtTraceDefinition.TAG_TIMESTAMP,\r
1309 CustomTxtTraceDefinition.TAG_MESSAGE,\r
1310 CustomTxtTraceDefinition.TAG_OTHER});\r
1311 tagCombo.select(1);\r
1312 tagCombo.addSelectionListener(new SelectionListener(){\r
d4011df2 1313 @Override\r
c3c5c786 1314 public void widgetDefaultSelected(SelectionEvent e) {}\r
d4011df2 1315 @Override\r
c3c5c786
FC
1316 public void widgetSelected(SelectionEvent e) {\r
1317 tagText.removeModifyListener(updateListener);\r
1318 switch (tagCombo.getSelectionIndex()) {\r
1319 case 0: //Time Stamp\r
3b38ea61 1320 tagLabel.setText(Messages.CustomTxtParserInputWizardPage_format);\r
c3c5c786
FC
1321 tagLabel.setVisible(true);\r
1322 tagText.setVisible(true);\r
1323 tagText.addModifyListener(updateListener);\r
1324 break;\r
1325 case 1: //Message\r
1326 tagLabel.setVisible(false);\r
1327 tagText.setVisible(false);\r
1328 break;\r
1329 case 2: //Other\r
3b38ea61 1330 tagLabel.setText(Messages.CustomTxtParserInputWizardPage_name);\r
c3c5c786
FC
1331 tagLabel.setVisible(true);\r
1332 tagText.setVisible(true);\r
1333 tagText.addModifyListener(updateListener);\r
1334 break;\r
1335 case 3: //Continue\r
1336 tagLabel.setVisible(false);\r
1337 tagText.setVisible(false);\r
1338 break;\r
1339 }\r
1340 tagComposite.layout();\r
1341 validate();\r
1342 updatePreviews();\r
1343 }});\r
1344 \r
1345 tagLabel = new Label(tagComposite, SWT.NULL);\r
1346 tagLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));\r
1347 tagLabel.setVisible(false);\r
1348 \r
1349 tagText = new Text(tagComposite, SWT.BORDER | SWT.SINGLE);\r
1350 GridData gd = new GridData(SWT.FILL, SWT.CENTER, true, false);\r
1351 gd.widthHint = 0;\r
1352 tagText.setLayoutData(gd);\r
1353 tagText.setVisible(false);\r
1354 \r
1355 actionCombo = new Combo(tagComposite, SWT.DROP_DOWN | SWT.READ_ONLY);\r
3b38ea61 1356 actionCombo.setItems(new String[] {Messages.CustomTxtParserInputWizardPage_set, Messages.CustomTxtParserInputWizardPage_append, Messages.CustomTxtParserInputWizardPage_appendWith});\r
c3c5c786
FC
1357 actionCombo.select(0);\r
1358 actionCombo.addSelectionListener(updateListener);\r
1359 \r
1360 previewLabel = new Label(parent, SWT.NULL);\r
1361 previewLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));\r
3b38ea61 1362 previewLabel.setText(Messages.CustomTxtParserInputWizardPage_preview);\r
c3c5c786
FC
1363 \r
1364 previewText = new Text(parent, SWT.BORDER | SWT.SINGLE | SWT.READ_ONLY);\r
1365 gd = new GridData(SWT.FILL, SWT.CENTER, true, false);\r
1366 gd.widthHint = 0;\r
1367 previewText.setLayoutData(gd);\r
3b38ea61 1368 previewText.setText(Messages.CustomTxtParserInputWizardPage_noMatch);\r
c3c5c786
FC
1369 previewText.setBackground(COLOR_WIDGET_BACKGROUND);\r
1370 }\r
1371 \r
1372 private void dispose() {\r
1373 labelComposite.dispose();\r
1374 tagComposite.dispose();\r
1375 previewLabel.dispose();\r
1376 previewText.dispose();\r
1377 }\r
1378 \r
1379 private void setInputNumber(int inputNumber) {\r
1380 this.inputNumber = inputNumber;\r
3b38ea61 1381 inputLabel.setText(Messages.CustomTxtParserInputWizardPage_group + inputNumber + ":"); //$NON-NLS-1$\r
c3c5c786
FC
1382 labelComposite.layout();\r
1383 }\r
1384 }\r
1385\r
1386 private void validate() {\r
1387\r
1388 definition.definitionName = logtypeText.getText().trim();\r
1389 definition.timeStampOutputFormat = timestampOutputFormatText.getText().trim();\r
1390 \r
1391 if (selectedLine != null) {\r
1392 selectedLine.extractInputs();\r
1393 treeViewer.refresh();\r
1394 }\r
1395 \r
1396 StringBuffer errors = new StringBuffer();\r
1397 \r
1398 if (definition.definitionName.length() == 0) {\r
3b38ea61 1399 errors.append("Enter a name for the new log type. "); //$NON-NLS-1$\r
c3c5c786
FC
1400 logtypeText.setBackground(COLOR_LIGHT_RED);\r
1401 } else {\r
1402 logtypeText.setBackground(COLOR_TEXT_BACKGROUND);\r
1403 for (CustomTxtTraceDefinition def : CustomTxtTraceDefinition.loadAll()) {\r
1404 if (definition.definitionName.equals(def.definitionName)) {\r
1405 if (editDefinitionName == null || ! editDefinitionName.equals(definition.definitionName)) {\r
3b38ea61 1406 errors.append("The log type name already exists. "); //$NON-NLS-1$\r
c3c5c786
FC
1407 logtypeText.setBackground(COLOR_LIGHT_RED);\r
1408 break;\r
1409 }\r
1410 }\r
1411 }\r
1412 }\r
1413 \r
1414 timestampFound = false;\r
1415 for (int i = 0; i < definition.inputs.size(); i++) {\r
1416 \r
1417 InputLine inputLine = definition.inputs.get(i);\r
1418 String name = Integer.toString(i+1);\r
1419 errors.append(validateLine(inputLine, name));\r
1420 }\r
1421 if (timestampFound) {\r
1422 if (definition.timeStampOutputFormat.length() == 0) {\r
3b38ea61 1423 errors.append("Enter the output format for the Time Stamp field. "); //$NON-NLS-1$\r
c3c5c786
FC
1424 timestampOutputFormatText.setBackground(COLOR_LIGHT_RED);\r
1425 } else {\r
1426 try {\r
1427 new SimpleDateFormat(definition.timeStampOutputFormat);\r
1428 timestampOutputFormatText.setBackground(COLOR_TEXT_BACKGROUND);\r
1429 } catch (IllegalArgumentException e) {\r
3b38ea61 1430 errors.append("Enter a valid output format for the Time Stamp field. "); //$NON-NLS-1$\r
c3c5c786
FC
1431 timestampOutputFormatText.setBackground(COLOR_LIGHT_RED);\r
1432 }\r
1433 }\r
1434 \r
1435 } else {\r
1436 timestampOutputFormatText.setBackground(COLOR_TEXT_BACKGROUND);\r
1437// timestampPreviewText.setBackground(COLOR_WIDGET_BACKGROUND);\r
1438// errors.append("Identify a Time Stamp group (Line "+name+"). ");\r
1439// timestampPreviewText.setText("*no timestamp group*");\r
1440// timestampPreviewText.setBackground(COLOR_LIGHT_RED);\r
1441 }\r
1442\r
1443 if (errors.length() == 0) {\r
1444 setDescription(defaultDescription);\r
1445 setPageComplete(true);\r
1446 } else {\r
1447 setDescription(errors.toString());\r
1448 setPageComplete(false);\r
1449 }\r
1450 }\r
1451\r
1452 public StringBuffer validateLine(InputLine inputLine, String name) {\r
1453 StringBuffer errors = new StringBuffer();\r
1454 Line line = null;\r
1455 if (selectedLine != null && selectedLine.inputLine.equals(inputLine)) line = selectedLine;\r
1456 try {\r
1457 Pattern.compile(inputLine.getRegex());\r
1458 if (line != null) line.regexText.setBackground(COLOR_TEXT_BACKGROUND);\r
1459 } catch (PatternSyntaxException e) {\r
3b38ea61 1460 errors.append("Enter a valid regular expression (Line "+name+"). "); //$NON-NLS-1$ //$NON-NLS-2$\r
c3c5c786
FC
1461 if (line != null) line.regexText.setBackground(COLOR_LIGHT_RED);\r
1462 }\r
1463 if (inputLine.getMinCount() == -1) {\r
3b38ea61 1464 errors.append("Enter a minimum value for cardinality (Line "+name+"). "); //$NON-NLS-1$ //$NON-NLS-2$\r
c3c5c786
FC
1465 if (line != null) line.cardinalityMinText.setBackground(COLOR_LIGHT_RED);\r
1466 } else {\r
1467 if (line != null) line.cardinalityMinText.setBackground(COLOR_TEXT_BACKGROUND);\r
1468 }\r
1469 if (inputLine.getMaxCount() == -1) {\r
3b38ea61 1470 errors.append("Enter a maximum value for cardinality (Line "+name+"). "); //$NON-NLS-1$ //$NON-NLS-2$\r
c3c5c786
FC
1471 if (line != null) line.cardinalityMaxText.setBackground(COLOR_LIGHT_RED);\r
1472 } else if (inputLine.getMinCount() > inputLine.getMaxCount()) {\r
3b38ea61 1473 errors.append("Enter correct (min <= max) values for cardinality (Line "+name+"). "); //$NON-NLS-1$ //$NON-NLS-2$\r
c3c5c786
FC
1474 if (line != null) line.cardinalityMinText.setBackground(COLOR_LIGHT_RED);\r
1475 if (line != null) line.cardinalityMaxText.setBackground(COLOR_LIGHT_RED);\r
1476 } else {\r
1477 if (line != null) line.cardinalityMaxText.setBackground(COLOR_TEXT_BACKGROUND);\r
1478 }\r
1479 for (int i = 0; inputLine.columns != null && i < inputLine.columns.size(); i++) {\r
1480 InputData inputData = inputLine.columns.get(i);\r
1481 InputGroup group = null;\r
1482 if (line != null) group = line.inputs.get(i);\r
1483 if (inputData.name.equals(CustomTxtTraceDefinition.TAG_TIMESTAMP)) {\r
1484 timestampFound = true;\r
1485 if (inputData.format.length() == 0) {\r
3b38ea61 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$\r
c3c5c786
FC
1487 if (group != null) group.tagText.setBackground(COLOR_LIGHT_RED);\r
1488 } else {\r
1489 try {\r
1490 new SimpleDateFormat(inputData.format);\r
1491 if (group != null) group.tagText.setBackground(COLOR_TEXT_BACKGROUND);\r
1492 } catch (IllegalArgumentException e) {\r
3b38ea61 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$\r
c3c5c786
FC
1494 if (group != null) group.tagText.setBackground(COLOR_LIGHT_RED);\r
1495 }\r
1496 }\r
1497 } else if (inputData.name.length() == 0) {\r
3b38ea61 1498 errors.append("Enter a name for the data group (Line "+name+" Group "+(i+1)+"). "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$\r
c3c5c786
FC
1499 if (group != null) group.tagText.setBackground(COLOR_LIGHT_RED);\r
1500 } else {\r
1501 if (group != null) group.tagText.setBackground(COLOR_TEXT_BACKGROUND);\r
1502 }\r
1503 }\r
1504 for (int i = 0; inputLine.childrenInputs != null && i < inputLine.childrenInputs.size(); i++) {\r
3b38ea61 1505 errors.append(validateLine(inputLine.childrenInputs.get(i), name+"."+(i+1))); //$NON-NLS-1$\r
c3c5c786
FC
1506 }\r
1507 return errors;\r
1508 }\r
1509 \r
1510 public CustomTxtTraceDefinition getDefinition() {\r
1511 return definition;\r
1512 }\r
1513\r
1514 public char[] getInputText() {\r
1515 return inputText.getText().toCharArray();\r
1516 }\r
1517}\r
This page took 0.095528 seconds and 5 git commands to generate.