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