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