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