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 | ||
511 | /* (non-Javadoc) | |
512 | * @see org.eclipse.jface.dialogs.DialogPage#dispose() | |
513 | */ | |
514 | @Override | |
515 | public void dispose() { | |
516 | if (fixedFont != null) { | |
517 | fixedFont.dispose(); | |
518 | fixedFont = null; | |
519 | } | |
520 | super.dispose(); | |
521 | } | |
522 | ||
523 | private void loadDefinition(CustomTxtTraceDefinition def) { | |
524 | logtypeText.setText(def.definitionName); | |
525 | timestampOutputFormatText.setText(def.timeStampOutputFormat); | |
526 | treeViewer.setInput(def.inputs); | |
527 | if (def.inputs.size() > 0) { | |
528 | InputLine inputLine = def.inputs.get(0); | |
529 | treeViewer.setSelection(new StructuredSelection(inputLine)); | |
530 | } | |
531 | } | |
532 | ||
533 | private String getName(InputLine inputLine) { | |
534 | if (inputLine.parentInput == null) { | |
535 | return Integer.toString(definition.inputs.indexOf(inputLine)+1); | |
536 | } | |
537 | return getName(inputLine.parentInput) + "." + Integer.toString(inputLine.parentInput.childrenInputs.indexOf(inputLine)+1); //$NON-NLS-1$ | |
538 | } | |
539 | ||
a0a88f65 AM |
540 | /** |
541 | * Get the global list of input names. | |
542 | * | |
543 | * @return The list of input names | |
544 | */ | |
be222f56 PT |
545 | public List<String> getInputNames() { |
546 | List<String> inputs = new ArrayList<String>(); | |
547 | for (InputLine inputLine : definition.inputs) { | |
548 | for (String inputName : getInputNames(inputLine)) { | |
549 | if (!inputs.contains(inputName)) { | |
550 | inputs.add(inputName); | |
551 | } | |
552 | } | |
553 | } | |
554 | return inputs; | |
555 | } | |
556 | ||
a0a88f65 AM |
557 | /** |
558 | * Get the list of input names for the given input line. | |
559 | * | |
560 | * @param inputLine | |
561 | * The input line | |
562 | * @return The list of input names | |
563 | */ | |
be222f56 PT |
564 | public List<String> getInputNames(InputLine inputLine) { |
565 | List<String> inputs = new ArrayList<String>(); | |
566 | if (inputLine.columns != null) { | |
567 | for (InputData inputData : inputLine.columns) { | |
568 | String inputName = inputData.name; | |
569 | if (!inputs.contains(inputName)) { | |
570 | inputs.add(inputName); | |
571 | } | |
572 | } | |
573 | } | |
574 | if (inputLine.childrenInputs != null) { | |
575 | for (InputLine childInputLine : inputLine.childrenInputs) { | |
576 | for (String inputName : getInputNames(childInputLine)) { | |
577 | if (!inputs.contains(inputName)) { | |
578 | inputs.add(inputName); | |
579 | } | |
580 | } | |
581 | } | |
582 | } | |
583 | return inputs; | |
584 | } | |
585 | ||
586 | private void removeLine() { | |
587 | selectedLine.dispose(); | |
588 | selectedLine = null; | |
589 | lineContainer.layout(); | |
590 | lineScrolledComposite.setMinSize(lineContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT).x, lineContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT).y-1); | |
591 | container.layout(); | |
592 | } | |
593 | ||
594 | private String getSelectionText() { | |
595 | if (this.selection instanceof IStructuredSelection) { | |
3dca7aa5 AM |
596 | Object sel = ((IStructuredSelection) this.selection).getFirstElement(); |
597 | if (sel instanceof IFile) { | |
598 | IFile file = (IFile)sel; | |
be222f56 PT |
599 | BufferedReader reader = null; |
600 | try { | |
601 | reader = new BufferedReader(new InputStreamReader(file.getContents())); | |
602 | StringBuilder sb = new StringBuilder(); | |
603 | String line = null; | |
604 | while ((line = reader.readLine()) != null) { | |
605 | sb.append(line + "\n"); //$NON-NLS-1$ | |
606 | } | |
607 | return sb.toString(); | |
608 | } catch (CoreException e) { | |
609 | return ""; //$NON-NLS-1$ | |
610 | } catch (IOException e) { | |
611 | return ""; //$NON-NLS-1$ | |
612 | } finally { | |
613 | if (reader != null) { | |
614 | try { | |
615 | reader.close(); | |
616 | } catch (IOException e) { | |
617 | } | |
618 | } | |
619 | } | |
620 | } | |
621 | } | |
622 | return ""; //$NON-NLS-1$ | |
623 | } | |
624 | ||
625 | private void updatePreviews() { | |
626 | updatePreviews(false); | |
627 | } | |
628 | ||
629 | private void updatePreviews(boolean updateAll) { | |
630 | if (inputText == null) { | |
631 | // early update during construction | |
632 | return; | |
633 | } | |
634 | inputText.setStyleRanges(new StyleRange[] {}); | |
635 | ||
636 | Scanner scanner = new Scanner(inputText.getText()); | |
637 | scanner.useDelimiter("\n"); //$NON-NLS-1$ | |
638 | int rawPos = 0; | |
639 | String skip; // skip starting delimiters | |
640 | if ((skip = scanner.findWithinHorizon("\\A\n+", 0)) != null) { //$NON-NLS-1$ | |
641 | rawPos += skip.length(); | |
642 | } | |
643 | ||
644 | timeStampFormat = null; | |
645 | if (selectedLine != null) { | |
646 | for (InputGroup input : selectedLine.inputs) { | |
647 | input.previewText.setText(Messages.CustomTxtParserInputWizardPage_noMathcingLine); | |
648 | } | |
649 | } | |
650 | ||
651 | Map<String, String> data = new HashMap<String, String>(); | |
652 | int rootLineMatches = 0; | |
653 | String firstEntryTimeStamp = null; | |
654 | String firstEntryTimeStampInputFormat = null; | |
655 | String log = null; | |
656 | event: | |
657 | while (scanner.hasNext()) { | |
658 | if (rootLineMatches > 0 && !updateAll) { | |
659 | break; | |
660 | } | |
661 | if (log == null) { | |
662 | log = scanner.next(); | |
663 | } | |
664 | int length = log.length(); | |
665 | for (InputLine rootInputLine : definition.inputs) { | |
666 | Pattern pattern; | |
667 | try { | |
668 | pattern = rootInputLine.getPattern(); | |
669 | } catch (PatternSyntaxException e) { | |
670 | continue; | |
671 | } | |
672 | Matcher matcher = pattern.matcher(log); | |
673 | if (matcher.find()) { | |
674 | rootLineMatches++; | |
675 | inputText.setStyleRange(new StyleRange(rawPos, length, | |
676 | COLOR_BLACK, COLOR_YELLOW, SWT.ITALIC)); | |
677 | data = new HashMap<String, String>(); | |
678 | timeStampFormat = null; | |
679 | updatePreviewLine(rootInputLine, matcher, data, rawPos, rootLineMatches); | |
680 | if (rootLineMatches == 1) { | |
681 | firstEntryTimeStamp = data.get(CustomTraceDefinition.TAG_TIMESTAMP); | |
682 | firstEntryTimeStampInputFormat = timeStampFormat; | |
683 | } | |
684 | HashMap<InputLine, Integer> countMap = new HashMap<InputLine, Integer>(); | |
685 | InputLine currentInput = null; | |
686 | if (rootInputLine.childrenInputs != null && rootInputLine.childrenInputs.size() > 0) { | |
687 | currentInput = rootInputLine.childrenInputs.get(0); | |
688 | countMap.put(currentInput, 0); | |
689 | } | |
690 | rawPos += length + 1; // +1 for \n | |
691 | while (scanner.hasNext()) { | |
692 | log = scanner.next(); | |
693 | length = log.length(); | |
694 | boolean processed = false; | |
695 | if (currentInput == null) { | |
696 | for (InputLine input : definition.inputs) { | |
697 | matcher = input.getPattern().matcher(log); | |
698 | if (matcher.find()) { | |
699 | continue event; | |
700 | } | |
701 | } | |
702 | } else { | |
703 | if (countMap.get(currentInput) >= currentInput.getMinCount()) { | |
704 | List<InputLine> nextInputs = currentInput.getNextInputs(countMap); | |
705 | if (nextInputs.size() == 0 || nextInputs.get(nextInputs.size() - 1).getMinCount() == 0) { | |
706 | for (InputLine input : definition.inputs) { | |
707 | matcher = input.getPattern().matcher(log); | |
708 | if (matcher.find()) { | |
709 | continue event; | |
710 | } | |
711 | } | |
712 | } | |
713 | for (InputLine input : nextInputs) { | |
714 | matcher = input.getPattern().matcher(log); | |
715 | if (matcher.find()) { | |
716 | inputText.setStyleRange(new StyleRange(rawPos, length, | |
717 | COLOR_BLACK, COLOR_LIGHT_YELLOW, SWT.ITALIC)); | |
718 | currentInput = input; | |
719 | updatePreviewLine(currentInput, matcher, data, rawPos, rootLineMatches); | |
720 | if (countMap.get(currentInput) == null) { | |
721 | countMap.put(currentInput, 1); | |
722 | } else { | |
723 | countMap.put(currentInput, countMap.get(currentInput) + 1); | |
724 | } | |
725 | Iterator<InputLine> iter = countMap.keySet().iterator(); | |
726 | while (iter.hasNext()) { | |
727 | InputLine inputLine = iter.next(); | |
728 | if (inputLine.level > currentInput.level) { | |
729 | iter.remove(); | |
730 | } | |
731 | } | |
732 | if (currentInput.childrenInputs != null && currentInput.childrenInputs.size() > 0) { | |
733 | currentInput = currentInput.childrenInputs.get(0); | |
734 | countMap.put(currentInput, 0); | |
735 | } else { | |
736 | if (countMap.get(currentInput) >= currentInput.getMaxCount()) { | |
737 | if (currentInput.getNextInputs(countMap).size() > 0) { | |
738 | currentInput = currentInput.getNextInputs(countMap).get(0); | |
739 | if (countMap.get(currentInput) == null) { | |
740 | countMap.put(currentInput, 0); | |
741 | } | |
742 | iter = countMap.keySet().iterator(); | |
743 | while (iter.hasNext()) { | |
744 | InputLine inputLine = iter.next(); | |
745 | if (inputLine.level > currentInput.level) { | |
746 | iter.remove(); | |
747 | } | |
748 | } | |
749 | } else { | |
750 | currentInput = null; | |
751 | } | |
752 | } | |
753 | } | |
754 | processed = true; | |
755 | break; | |
756 | } | |
757 | } | |
758 | } | |
3dca7aa5 | 759 | if (!processed && currentInput != null) { |
be222f56 PT |
760 | matcher = currentInput.getPattern().matcher(log); |
761 | if (matcher.find()) { | |
762 | inputText.setStyleRange(new StyleRange(rawPos, length, | |
763 | COLOR_BLACK, COLOR_LIGHT_YELLOW, SWT.ITALIC)); | |
764 | updatePreviewLine(currentInput, matcher, data, rawPos, rootLineMatches); | |
765 | countMap.put(currentInput, countMap.get(currentInput) + 1); | |
766 | if (currentInput.childrenInputs != null && currentInput.childrenInputs.size() > 0) { | |
767 | currentInput = currentInput.childrenInputs.get(0); | |
768 | countMap.put(currentInput, 0); | |
769 | } else { | |
770 | if (countMap.get(currentInput) >= currentInput.getMaxCount()) { | |
771 | if (currentInput.getNextInputs(countMap).size() > 0) { | |
772 | currentInput = currentInput.getNextInputs(countMap).get(0); | |
773 | if (countMap.get(currentInput) == null) { | |
774 | countMap.put(currentInput, 0); | |
775 | } | |
776 | Iterator<InputLine> iter = countMap.keySet().iterator(); | |
777 | while (iter.hasNext()) { | |
778 | InputLine inputLine = iter.next(); | |
779 | if (inputLine.level > currentInput.level) { | |
780 | iter.remove(); | |
781 | } | |
782 | } | |
783 | } else { | |
784 | currentInput = null; | |
785 | } | |
786 | } | |
787 | } | |
788 | } | |
789 | } | |
790 | } | |
791 | rawPos += length + 1; // +1 for \n | |
792 | } | |
793 | ||
794 | break; | |
795 | } | |
796 | } | |
797 | rawPos += length + 1; // +1 for \n | |
798 | log = null; | |
799 | } | |
800 | scanner.close(); | |
801 | if (rootLineMatches == 1) { | |
802 | firstEntryTimeStamp = data.get(CustomTraceDefinition.TAG_TIMESTAMP); | |
803 | firstEntryTimeStampInputFormat = timeStampFormat; | |
804 | } | |
805 | if (firstEntryTimeStamp == null) { | |
806 | timestampPreviewText.setText(Messages.CustomTxtParserInputWizardPage_noTimestampGroup); | |
807 | if (selectedLine != null) { | |
808 | for (InputGroup group : selectedLine.inputs) { | |
809 | if (group.tagCombo.getText().equals(CustomTraceDefinition.TAG_TIMESTAMP)) { | |
810 | timestampPreviewText.setText(Messages.CustomTxtParserInputWizardPage_noMatchingTimestamp); | |
811 | break; | |
812 | } | |
813 | } | |
814 | } | |
815 | } else { | |
816 | try { | |
817 | SimpleDateFormat dateFormat = new SimpleDateFormat(firstEntryTimeStampInputFormat); | |
818 | Date date = dateFormat.parse(firstEntryTimeStamp); | |
819 | dateFormat = new SimpleDateFormat(timestampOutputFormatText.getText().trim()); | |
820 | timestampPreviewText.setText(dateFormat.format(date)); | |
821 | } catch (ParseException e) { | |
822 | timestampPreviewText.setText("*parse exception* [" + firstEntryTimeStamp + "] <> [" + firstEntryTimeStampInputFormat + "]"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ | |
823 | } catch (IllegalArgumentException e) { | |
824 | timestampPreviewText.setText("*parse exception* [Illegal Argument]"); //$NON-NLS-1$ | |
825 | } | |
826 | ||
827 | } | |
828 | } | |
829 | ||
830 | private void updatePreviewLine(InputLine line, Matcher matcher, Map<String, String> data, int rawPos, int rootLineMatches) { | |
831 | for (int i = 0; i < line.columns.size(); i++) { | |
832 | InputData input = line.columns.get(i); | |
833 | if (i < matcher.groupCount() && matcher.group(i+1) != null) { | |
834 | if (line.parentInput == null) { | |
835 | inputText.setStyleRange(new StyleRange(rawPos + matcher.start(i+1), matcher.end(i+1) - matcher.start(i+1), | |
836 | COLOR_BLACK, COLOR_GREEN, SWT.BOLD)); | |
837 | } else { | |
838 | inputText.setStyleRange(new StyleRange(rawPos + matcher.start(i+1), matcher.end(i+1) - matcher.start(i+1), | |
839 | COLOR_BLACK, COLOR_LIGHT_GREEN, SWT.BOLD)); | |
840 | } | |
841 | String value = matcher.group(i+1).trim(); | |
842 | if (selectedLine != null && selectedLine.inputLine.equals(line) && rootLineMatches == 1) { | |
843 | if (selectedLine.inputs.get(i).previewText.getText().equals(Messages.CustomTxtParserInputWizardPage_noMatchingLine)) { | |
844 | selectedLine.inputs.get(i).previewText.setText(value); | |
845 | } | |
846 | } | |
847 | if (value.length() == 0) { | |
848 | continue; | |
849 | } | |
850 | if (input.action == CustomTraceDefinition.ACTION_SET) { | |
851 | data.put(input.name, value); | |
852 | if (input.name.equals(CustomTraceDefinition.TAG_TIMESTAMP)) { | |
853 | timeStampFormat = input.format; | |
854 | } | |
855 | } else if (input.action == CustomTraceDefinition.ACTION_APPEND) { | |
856 | String s = data.get(input.name); | |
857 | if (s != null) { | |
858 | data.put(input.name, s + value); | |
859 | } else { | |
860 | data.put(input.name, value); | |
861 | } | |
862 | if (input.name.equals(CustomTraceDefinition.TAG_TIMESTAMP)) { | |
863 | if (timeStampFormat != null) { | |
864 | timeStampFormat += input.format; | |
865 | } else { | |
866 | timeStampFormat = input.format; | |
867 | } | |
868 | } | |
869 | } else if (input.action == CustomTraceDefinition.ACTION_APPEND_WITH_SEPARATOR) { | |
870 | String s = data.get(input.name); | |
871 | if (s != null) { | |
872 | data.put(input.name, s + " | " + value); //$NON-NLS-1$ | |
873 | } else { | |
874 | data.put(input.name, value); | |
875 | } | |
876 | if (input.name.equals(CustomTraceDefinition.TAG_TIMESTAMP)) { | |
877 | if (timeStampFormat != null) { | |
878 | timeStampFormat += " | " + input.format; //$NON-NLS-1$ | |
879 | } else { | |
880 | timeStampFormat = input.format; | |
881 | } | |
882 | } | |
883 | } | |
884 | } else { | |
885 | if (selectedLine != null && selectedLine.inputLine.equals(line) && rootLineMatches == 1) { | |
886 | if (selectedLine.inputs.get(i).previewText.getText().equals(Messages.CustomTxtParserInputWizardPage_noMatchingLine)) { | |
887 | selectedLine.inputs.get(i).previewText.setText(Messages.CustomTxtParserInputWizardPage_noMatchingGroup); | |
888 | } | |
889 | } | |
890 | } | |
891 | } | |
892 | // highlight the matching groups that have no corresponponding input | |
893 | for (int i = line.columns.size(); i < matcher.groupCount(); i++) { | |
894 | if (matcher.group(i+1) != null) { | |
895 | if (line.parentInput == null) { | |
896 | inputText.setStyleRange(new StyleRange(rawPos + matcher.start(i+1), matcher.end(i+1) - matcher.start(i+1), | |
897 | COLOR_BLACK, COLOR_MAGENTA)); | |
898 | } else { | |
899 | inputText.setStyleRange(new StyleRange(rawPos + matcher.start(i+1), matcher.end(i+1) - matcher.start(i+1), | |
900 | COLOR_BLACK, COLOR_LIGHT_MAGENTA)); | |
901 | } | |
902 | } | |
903 | } | |
904 | } | |
905 | ||
906 | private void openHelpShell(String url) { | |
907 | if (helpBrowser != null && !helpBrowser.isDisposed()) { | |
908 | helpBrowser.getShell().setActive(); | |
909 | if (!helpBrowser.getUrl().equals(url)) { | |
910 | helpBrowser.setUrl(url); | |
911 | } | |
912 | return; | |
913 | } | |
914 | final Shell helpShell = new Shell(getShell(), SWT.SHELL_TRIM); | |
915 | helpShell.setLayout(new FillLayout()); | |
916 | helpBrowser = new Browser(helpShell, SWT.NONE); | |
917 | helpBrowser.addTitleListener(new TitleListener() { | |
a0a88f65 AM |
918 | @Override |
919 | public void changed(TitleEvent event) { | |
920 | helpShell.setText(event.title); | |
921 | } | |
be222f56 | 922 | }); |
a0a88f65 | 923 | helpBrowser.setBounds(0, 0, 600, 400); |
be222f56 PT |
924 | helpShell.pack(); |
925 | helpShell.open(); | |
926 | helpBrowser.setUrl(url); | |
927 | } | |
928 | ||
929 | private void openLegend() { | |
930 | final String CG = Messages.CustomTxtParserInputWizardPage_capturedGroup; | |
931 | final String UCG = Messages.CustomTxtParserInputWizardPage_unidentifiedCaptureGroup; | |
932 | final String UT = Messages.CustomTxtParserInputWizardPage_uncapturedText; | |
933 | int line1start = 0; | |
934 | String line1 = Messages.CustomTxtParserInputWizardPage_nonMatchingLine; | |
935 | int line2start = line1start + line1.length(); | |
936 | String line2 = Messages.CustomTxtParserInputWizardPage_matchingLineRoot + CG + " " + UCG + " " + UT + " \n"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ | |
937 | int line3start = line2start + line2.length(); | |
938 | String line3 = Messages.CustomTxtParserInputWizardPage_matchingOtherLine + CG + " " + UCG + " " + UT + " \n"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ | |
939 | int line4start = line3start + line3.length(); | |
940 | String line4 = Messages.CustomTxtParserInputWizardPage_matchingOtherLine + CG + " " + UCG + " " + UT + " \n"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ | |
941 | int line5start = line4start + line4.length(); | |
942 | String line5 = Messages.CustomTxtParserInputWizardPage_nonMatchingLine; | |
943 | int line6start = line5start + line5.length(); | |
944 | String line6 = Messages.CustomTxtParserInputWizardPage_matchingRootLine + CG + " " + UCG + " " + UT + " \n"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ | |
945 | ||
946 | final Shell legendShell = new Shell(getShell(), SWT.DIALOG_TRIM); | |
947 | legendShell.setLayout(new FillLayout()); | |
948 | StyledText legendText = new StyledText(legendShell, SWT.MULTI); | |
949 | legendText.setFont(fixedFont); | |
950 | legendText.setText(line1 + line2 + line3 + line4 + line5 + line6); | |
951 | legendText.setStyleRange(new StyleRange(line2start, line2.length(), COLOR_BLACK, COLOR_YELLOW, SWT.ITALIC)); | |
952 | legendText.setStyleRange(new StyleRange(line3start, line3.length(), COLOR_BLACK, COLOR_LIGHT_YELLOW, SWT.ITALIC)); | |
953 | legendText.setStyleRange(new StyleRange(line4start, line4.length(), COLOR_BLACK, COLOR_LIGHT_YELLOW, SWT.ITALIC)); | |
954 | legendText.setStyleRange(new StyleRange(line6start, line6.length(), COLOR_BLACK, COLOR_YELLOW, SWT.ITALIC)); | |
955 | legendText.setStyleRange(new StyleRange(line2start + line2.indexOf(CG), CG.length(), COLOR_BLACK, COLOR_GREEN, SWT.BOLD)); | |
956 | legendText.setStyleRange(new StyleRange(line2start + line2.indexOf(UCG), UCG.length(), COLOR_BLACK, COLOR_MAGENTA)); | |
957 | legendText.setStyleRange(new StyleRange(line3start + line3.indexOf(CG), CG.length(), COLOR_BLACK, COLOR_LIGHT_GREEN, SWT.BOLD)); | |
958 | legendText.setStyleRange(new StyleRange(line3start + line3.indexOf(UCG), UCG.length(), COLOR_BLACK, COLOR_LIGHT_MAGENTA)); | |
959 | legendText.setStyleRange(new StyleRange(line4start + line4.indexOf(CG), CG.length(), COLOR_BLACK, COLOR_LIGHT_GREEN, SWT.BOLD)); | |
960 | legendText.setStyleRange(new StyleRange(line4start + line4.indexOf(UCG), UCG.length(), COLOR_BLACK, COLOR_LIGHT_MAGENTA)); | |
961 | legendText.setStyleRange(new StyleRange(line6start + line6.indexOf(CG), CG.length(), COLOR_BLACK, COLOR_GREEN, SWT.BOLD)); | |
962 | legendText.setStyleRange(new StyleRange(line6start + line6.indexOf(UCG), UCG.length(), COLOR_BLACK, COLOR_MAGENTA)); | |
963 | legendShell.setText(Messages.CustomTxtParserInputWizardPage_previewLegend); | |
964 | legendShell.pack(); | |
965 | legendShell.open(); | |
966 | } | |
967 | ||
968 | private class UpdateListener implements ModifyListener, SelectionListener { | |
969 | ||
a0a88f65 | 970 | @Override |
be222f56 PT |
971 | public void modifyText(ModifyEvent e) { |
972 | validate(); | |
973 | updatePreviews(); | |
974 | } | |
975 | ||
a0a88f65 | 976 | @Override |
be222f56 PT |
977 | public void widgetDefaultSelected(SelectionEvent e) { |
978 | validate(); | |
979 | updatePreviews(); | |
980 | } | |
981 | ||
a0a88f65 | 982 | @Override |
be222f56 PT |
983 | public void widgetSelected(SelectionEvent e) { |
984 | validate(); | |
985 | updatePreviews(); | |
986 | } | |
987 | ||
988 | } | |
989 | ||
990 | private class Line { | |
991 | private static final String INFINITY_STRING = "\u221E"; //$NON-NLS-1$ | |
992 | InputLine inputLine; | |
993 | Group group; | |
994 | Composite labelComposite; | |
995 | Text regexText; | |
996 | Composite cardinalityContainer; | |
997 | Combo cardinalityCombo; | |
998 | Label cardinalityMinLabel; | |
999 | Text cardinalityMinText; | |
1000 | Label cardinalityMaxLabel; | |
1001 | Text cardinalityMaxText; | |
1002 | Button infiniteButton; | |
1003 | List<InputGroup> inputs = new ArrayList<InputGroup>(); | |
1004 | Button addGroupButton; | |
1005 | Label addGroupLabel; | |
1006 | ||
1007 | public Line(Composite parent, String name, InputLine inputLine) { | |
1008 | this.inputLine = inputLine; | |
1009 | ||
1010 | group = new Group(parent, SWT.NONE); | |
1011 | group.setText(name); | |
1012 | group.setLayout(new GridLayout(2, false)); | |
1013 | group.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); | |
1014 | ||
1015 | labelComposite = new Composite(group, SWT.FILL); | |
1016 | GridLayout labelLayout = new GridLayout(1, false); | |
1017 | labelLayout.marginWidth = 0; | |
1018 | labelLayout.marginHeight = 0; | |
1019 | labelComposite.setLayout(labelLayout); | |
1020 | labelComposite.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false)); | |
1021 | ||
1022 | Label label = new Label(labelComposite, SWT.NULL); | |
1023 | label.setText(Messages.CustomTxtParserInputWizardPage_regularExpression); | |
1024 | ||
1025 | Composite regexContainer = new Composite(group, SWT.NONE); | |
1026 | GridLayout regexLayout = new GridLayout(2, false); | |
1027 | regexLayout.marginHeight = 0; | |
1028 | regexLayout.marginWidth = 0; | |
1029 | regexContainer.setLayout(regexLayout); | |
1030 | regexContainer.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); | |
1031 | ||
1032 | regexText = new Text(regexContainer, SWT.BORDER | SWT.SINGLE); | |
1033 | GridData gd = new GridData(SWT.FILL, SWT.CENTER, true, false); | |
1034 | gd.widthHint = 0; | |
1035 | regexText.setLayoutData(gd); | |
1036 | regexText.setText(inputLine.getRegex()); | |
1037 | regexText.addModifyListener(updateListener); | |
1038 | ||
1039 | Button regexHelpButton = new Button(regexContainer, SWT.PUSH); | |
1040 | regexHelpButton.setImage(helpImage); | |
1041 | regexHelpButton.setToolTipText(Messages.CustomTxtParserInputWizardPage_regularExpressionHelp); | |
1042 | regexHelpButton.addSelectionListener(new SelectionAdapter() { | |
a0a88f65 AM |
1043 | @Override |
1044 | public void widgetSelected(SelectionEvent e) { | |
be222f56 PT |
1045 | openHelpShell(PATTERN_URL); |
1046 | } | |
1047 | }); | |
1048 | ||
1049 | label = new Label(group, SWT.NONE); | |
1050 | label.setText(Messages.CustomTxtParserInputWizardPage_cardinality); | |
1051 | label.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false)); | |
1052 | ||
1053 | cardinalityContainer = new Composite(group, SWT.NONE); | |
1054 | GridLayout cardinalityLayout = new GridLayout(6, false); | |
1055 | cardinalityLayout.marginHeight = 0; | |
1056 | cardinalityLayout.marginWidth = 0; | |
1057 | cardinalityContainer.setLayout(cardinalityLayout); | |
1058 | cardinalityContainer.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); | |
1059 | ||
1060 | cardinalityCombo = new Combo(cardinalityContainer, SWT.DROP_DOWN | SWT.READ_ONLY); | |
1061 | cardinalityCombo.setItems(new String[] { | |
1062 | Cardinality.ZERO_OR_MORE.toString(), | |
1063 | Cardinality.ONE_OR_MORE.toString(), | |
1064 | Cardinality.ZERO_OR_ONE.toString(), | |
1065 | Cardinality.ONE.toString(), | |
1066 | "(?,?)"}); //$NON-NLS-1$ | |
a0a88f65 AM |
1067 | cardinalityCombo.addSelectionListener(new SelectionListener() { |
1068 | @Override | |
be222f56 | 1069 | public void widgetDefaultSelected(SelectionEvent e) {} |
a0a88f65 AM |
1070 | |
1071 | @Override | |
be222f56 PT |
1072 | public void widgetSelected(SelectionEvent e) { |
1073 | switch (cardinalityCombo.getSelectionIndex()) { | |
a0a88f65 | 1074 | case 4: // (?,?) |
be222f56 PT |
1075 | cardinalityMinLabel.setVisible(true); |
1076 | cardinalityMinText.setVisible(true); | |
1077 | cardinalityMaxLabel.setVisible(true); | |
1078 | cardinalityMaxText.setVisible(true); | |
1079 | infiniteButton.setVisible(true); | |
1080 | break; | |
1081 | default: | |
1082 | cardinalityMinLabel.setVisible(false); | |
1083 | cardinalityMinText.setVisible(false); | |
1084 | cardinalityMaxLabel.setVisible(false); | |
1085 | cardinalityMaxText.setVisible(false); | |
1086 | infiniteButton.setVisible(false); | |
1087 | break; | |
1088 | } | |
1089 | cardinalityContainer.layout(); | |
1090 | validate(); | |
1091 | updatePreviews(); | |
a0a88f65 AM |
1092 | } |
1093 | }); | |
be222f56 PT |
1094 | |
1095 | cardinalityMinLabel = new Label(cardinalityContainer, SWT.NONE); | |
1096 | cardinalityMinLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false)); | |
1097 | cardinalityMinLabel.setText(Messages.CustomTxtParserInputWizardPage_min); | |
1098 | cardinalityMinLabel.setVisible(false); | |
1099 | ||
1100 | cardinalityMinText = new Text(cardinalityContainer, SWT.BORDER | SWT.SINGLE); | |
1101 | gd = new GridData(SWT.CENTER, SWT.CENTER, false, false); | |
1102 | gd.widthHint = 20; | |
1103 | cardinalityMinText.setLayoutData(gd); | |
1104 | cardinalityMinText.setVisible(false); | |
1105 | ||
1106 | cardinalityMaxLabel = new Label(cardinalityContainer, SWT.NONE); | |
1107 | cardinalityMaxLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false)); | |
1108 | cardinalityMaxLabel.setText(Messages.CustomTxtParserInputWizardPage_max); | |
1109 | cardinalityMaxLabel.setVisible(false); | |
1110 | ||
1111 | cardinalityMaxText = new Text(cardinalityContainer, SWT.BORDER | SWT.SINGLE); | |
1112 | gd = new GridData(SWT.CENTER, SWT.CENTER, false, false); | |
1113 | gd.widthHint = 20; | |
1114 | cardinalityMaxText.setLayoutData(gd); | |
1115 | cardinalityMaxText.setVisible(false); | |
1116 | ||
1117 | infiniteButton = new Button(cardinalityContainer, SWT.PUSH); | |
1118 | infiniteButton.setText(INFINITY_STRING); | |
1119 | infiniteButton.setVisible(false); | |
1120 | infiniteButton.addSelectionListener(new SelectionAdapter(){ | |
1121 | @Override | |
1122 | public void widgetSelected(SelectionEvent e) { | |
1123 | cardinalityMaxText.setText(INFINITY_STRING); | |
1124 | }}); | |
1125 | ||
1126 | if (inputLine.cardinality.equals(Cardinality.ZERO_OR_MORE)) { | |
1127 | cardinalityCombo.select(0); | |
1128 | } else if (inputLine.cardinality.equals(Cardinality.ONE_OR_MORE)) { | |
1129 | cardinalityCombo.select(1); | |
1130 | } else if (inputLine.cardinality.equals(Cardinality.ZERO_OR_ONE)) { | |
1131 | cardinalityCombo.select(2); | |
1132 | } else if (inputLine.cardinality.equals(Cardinality.ONE)) { | |
1133 | cardinalityCombo.select(3); | |
1134 | } else { | |
1135 | cardinalityCombo.select(4); | |
1136 | cardinalityMinLabel.setVisible(true); | |
1137 | cardinalityMinText.setVisible(true); | |
1138 | if (inputLine.getMinCount() >= 0) { | |
1139 | cardinalityMinText.setText(Integer.toString(inputLine.getMinCount())); | |
1140 | } | |
1141 | cardinalityMaxLabel.setVisible(true); | |
1142 | cardinalityMaxText.setVisible(true); | |
1143 | if (inputLine.getMaxCount() == Cardinality.INF) { | |
1144 | cardinalityMaxText.setText(INFINITY_STRING); | |
1145 | } else if (inputLine.getMaxCount() >= 0) { | |
1146 | cardinalityMaxText.setText(Integer.toString(inputLine.getMaxCount())); | |
1147 | } | |
1148 | infiniteButton.setVisible(true); | |
1149 | } | |
1150 | ||
1151 | VerifyListener digitsListener = new VerifyListener() { | |
1152 | @Override | |
1153 | public void verifyText(VerifyEvent e) { | |
1154 | if (e.text.equals(INFINITY_STRING)) { | |
1155 | e.doit = e.widget == cardinalityMaxText && e.start == 0 && e.end == ((Text) e.widget).getText().length(); | |
1156 | } else { | |
1157 | if (((Text) e.widget).getText().equals(INFINITY_STRING)) { | |
1158 | e.doit = e.start == 0 && e.end == ((Text) e.widget).getText().length(); | |
1159 | } | |
1160 | for (int i = 0; i < e.text.length(); i++) { | |
1161 | if (!Character.isDigit(e.text.charAt(i))) { | |
1162 | e.doit = false; | |
1163 | break; | |
1164 | } | |
1165 | } | |
1166 | } | |
1167 | }}; | |
1168 | ||
1169 | cardinalityMinText.addModifyListener(updateListener); | |
1170 | cardinalityMaxText.addModifyListener(updateListener); | |
1171 | cardinalityMinText.addVerifyListener(digitsListener); | |
1172 | cardinalityMaxText.addVerifyListener(digitsListener); | |
1173 | ||
1174 | if (inputLine.columns != null) { | |
1175 | for (InputData inputData : inputLine.columns) { | |
1176 | InputGroup inputGroup = new InputGroup(group, this, inputs.size()+1); | |
1177 | if (inputData.name.equals(CustomTraceDefinition.TAG_TIMESTAMP)) { | |
1178 | inputGroup.tagCombo.select(0); | |
1179 | inputGroup.tagText.setText(inputData.format); | |
1180 | inputGroup.tagLabel.setText(Messages.CustomTxtParserInputWizardPage_format); | |
1181 | inputGroup.tagLabel.setVisible(true); | |
1182 | inputGroup.tagText.setVisible(true); | |
1183 | inputGroup.tagText.addModifyListener(updateListener); | |
1184 | } else if (inputData.name.equals(CustomTraceDefinition.TAG_MESSAGE)) { | |
1185 | inputGroup.tagCombo.select(1); | |
1186 | } else { | |
1187 | inputGroup.tagCombo.select(2); | |
1188 | inputGroup.tagText.setText(inputData.name); | |
1189 | inputGroup.tagLabel.setText(Messages.CustomTxtParserInputWizardPage_name); | |
1190 | inputGroup.tagLabel.setVisible(true); | |
1191 | inputGroup.tagText.setVisible(true); | |
1192 | inputGroup.tagText.addModifyListener(updateListener); | |
1193 | } | |
1194 | inputGroup.actionCombo.select(inputData.action); | |
1195 | inputs.add(inputGroup); | |
1196 | } | |
1197 | } | |
1198 | ||
1199 | createAddGroupButton(); | |
1200 | } | |
1201 | ||
1202 | private void createAddGroupButton() { | |
1203 | addGroupButton = new Button(group, SWT.PUSH); | |
1204 | addGroupButton.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false)); | |
1205 | addGroupButton.setImage(addImage); | |
1206 | addGroupButton.setToolTipText(Messages.CustomTxtParserInputWizardPage_addGroup); | |
1207 | addGroupButton.addSelectionListener(new SelectionAdapter() { | |
1208 | @Override | |
1209 | public void widgetSelected(SelectionEvent e) { | |
1210 | removeAddGroupButton(); | |
1211 | inputs.add(new InputGroup(group, Line.this, inputs.size()+1)); | |
1212 | createAddGroupButton(); | |
1213 | lineContainer.layout(); | |
1214 | lineScrolledComposite.setMinSize(lineContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT).x, lineContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT).y-1); | |
1215 | group.getParent().layout(); | |
1216 | validate(); | |
1217 | updatePreviews(); | |
1218 | } | |
1219 | }); | |
1220 | ||
1221 | addGroupLabel = new Label(group, SWT.NULL); | |
1222 | addGroupLabel.setText(Messages.CustomTxtParserInputWizardPage_newGroup); | |
1223 | } | |
1224 | ||
1225 | private void removeAddGroupButton() { | |
1226 | addGroupButton.dispose(); | |
1227 | addGroupLabel.dispose(); | |
1228 | } | |
1229 | ||
1230 | private void removeInput(int inputNumber) { | |
41b5c37f AM |
1231 | int nb = inputNumber; |
1232 | if (--nb < inputs.size()) { | |
1233 | inputs.remove(nb).dispose(); | |
1234 | for (int i = nb; i < inputs.size(); i++) { | |
be222f56 PT |
1235 | inputs.get(i).setInputNumber(i+1); |
1236 | } | |
1237 | lineContainer.layout(); | |
1238 | lineScrolledComposite.setMinSize(lineContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT).x, lineContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT).y-1); | |
1239 | group.getParent().layout(); | |
1240 | } | |
1241 | } | |
1242 | ||
1243 | // private void setName(String name) { | |
1244 | // this.name = name; | |
1245 | // group.setText("Line " + name); | |
1246 | // } | |
1247 | ||
1248 | private void dispose() { | |
1249 | group.dispose(); | |
1250 | } | |
1251 | ||
1252 | private void extractInputs() { | |
1253 | inputLine.setRegex(selectedLine.regexText.getText()); | |
1254 | switch (cardinalityCombo.getSelectionIndex()) { | |
1255 | case 0: | |
1256 | inputLine.cardinality = Cardinality.ZERO_OR_MORE; | |
1257 | break; | |
1258 | case 1: | |
1259 | inputLine.cardinality = Cardinality.ONE_OR_MORE; | |
1260 | break; | |
1261 | case 2: | |
1262 | inputLine.cardinality = Cardinality.ZERO_OR_ONE; | |
1263 | break; | |
1264 | case 3: | |
1265 | inputLine.cardinality = Cardinality.ONE; | |
1266 | break; | |
1267 | case 4: //(?,?) | |
1268 | int min, max; | |
1269 | try { | |
1270 | min = Integer.parseInt(cardinalityMinText.getText()); | |
1271 | } catch (NumberFormatException e) { | |
1272 | min = -1; | |
1273 | } | |
1274 | try { | |
1275 | if (cardinalityMaxText.getText().equals(INFINITY_STRING)) { | |
1276 | max = Cardinality.INF; | |
1277 | } else { | |
1278 | max = Integer.parseInt(cardinalityMaxText.getText()); | |
1279 | } | |
1280 | } catch (NumberFormatException e) { | |
1281 | max = -1; | |
1282 | } | |
1283 | inputLine.cardinality = new Cardinality(min, max); | |
1284 | break; | |
1285 | default: | |
1286 | inputLine.cardinality = Cardinality.ZERO_OR_MORE; | |
1287 | break; | |
1288 | } | |
1289 | inputLine.columns = new ArrayList<InputData>(inputs.size()); | |
1290 | for (int i = 0; i < inputs.size(); i++) { | |
3dca7aa5 | 1291 | InputGroup grp = inputs.get(i); |
be222f56 | 1292 | InputData inputData = new InputData(); |
3dca7aa5 AM |
1293 | if (grp.tagCombo.getText().equals(CustomTraceDefinition.TAG_OTHER)) { |
1294 | inputData.name = grp.tagText.getText().trim(); | |
be222f56 | 1295 | } else { |
3dca7aa5 AM |
1296 | inputData.name = grp.tagCombo.getText(); |
1297 | if (grp.tagCombo.getText().equals(CustomTraceDefinition.TAG_TIMESTAMP)) { | |
1298 | inputData.format = grp.tagText.getText().trim(); | |
be222f56 PT |
1299 | } |
1300 | } | |
3dca7aa5 | 1301 | inputData.action = grp.actionCombo.getSelectionIndex(); |
be222f56 PT |
1302 | inputLine.columns.add(inputData); |
1303 | } | |
1304 | } | |
1305 | } | |
1306 | ||
1307 | private class InputGroup { | |
1308 | Line line; | |
1309 | int inputNumber; | |
1310 | ||
1311 | // children of parent (must be disposed) | |
1312 | Composite labelComposite; | |
1313 | Composite tagComposite; | |
1314 | Label previewLabel; | |
1315 | Text previewText; | |
1316 | ||
1317 | // children of labelComposite | |
1318 | Label inputLabel; | |
1319 | ||
1320 | // children of tagComposite | |
1321 | Combo tagCombo; | |
1322 | Label tagLabel; | |
1323 | Text tagText; | |
1324 | Combo actionCombo; | |
1325 | ||
1326 | public InputGroup(Composite parent, Line line, int inputNumber) { | |
1327 | this.line = line; | |
1328 | this.inputNumber = inputNumber; | |
1329 | ||
1330 | labelComposite = new Composite(parent, SWT.FILL); | |
1331 | GridLayout labelLayout = new GridLayout(2, false); | |
1332 | labelLayout.marginWidth = 0; | |
1333 | labelLayout.marginHeight = 0; | |
1334 | labelComposite.setLayout(labelLayout); | |
1335 | labelComposite.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false)); | |
1336 | ||
1337 | Button deleteButton = new Button(labelComposite, SWT.PUSH); | |
1338 | deleteButton.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false)); | |
1339 | deleteButton.setImage(deleteImage); | |
1340 | deleteButton.setToolTipText(Messages.CustomTxtParserInputWizardPage_removeGroup); | |
1341 | deleteButton.addSelectionListener(new SelectionAdapter() { | |
1342 | @Override | |
1343 | public void widgetSelected(SelectionEvent e) { | |
1344 | InputGroup.this.line.removeInput(InputGroup.this.inputNumber); | |
1345 | validate(); | |
1346 | updatePreviews(); | |
1347 | } | |
1348 | }); | |
1349 | ||
1350 | inputLabel = new Label(labelComposite, SWT.NULL); | |
1351 | inputLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false)); | |
1352 | inputLabel.setText(Messages.CustomTxtParserInputWizardPage_group + inputNumber + ":"); //$NON-NLS-1$ | |
1353 | ||
1354 | tagComposite = new Composite(parent, SWT.FILL); | |
1355 | GridLayout tagLayout = new GridLayout(4, false); | |
1356 | tagLayout.marginWidth = 0; | |
1357 | tagLayout.marginHeight = 0; | |
1358 | tagComposite.setLayout(tagLayout); | |
1359 | tagComposite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); | |
1360 | ||
1361 | tagCombo = new Combo(tagComposite, SWT.DROP_DOWN | SWT.READ_ONLY); | |
1362 | tagCombo.setItems(new String[] {CustomTraceDefinition.TAG_TIMESTAMP, | |
1363 | CustomTraceDefinition.TAG_MESSAGE, | |
1364 | CustomTraceDefinition.TAG_OTHER}); | |
1365 | tagCombo.select(1); | |
1366 | tagCombo.addSelectionListener(new SelectionListener(){ | |
1367 | @Override | |
1368 | public void widgetDefaultSelected(SelectionEvent e) {} | |
1369 | @Override | |
1370 | public void widgetSelected(SelectionEvent e) { | |
1371 | tagText.removeModifyListener(updateListener); | |
1372 | switch (tagCombo.getSelectionIndex()) { | |
1373 | case 0: //Time Stamp | |
1374 | tagLabel.setText(Messages.CustomTxtParserInputWizardPage_format); | |
1375 | tagLabel.setVisible(true); | |
1376 | tagText.setVisible(true); | |
1377 | tagText.addModifyListener(updateListener); | |
1378 | break; | |
1379 | case 1: //Message | |
1380 | tagLabel.setVisible(false); | |
1381 | tagText.setVisible(false); | |
1382 | break; | |
1383 | case 2: //Other | |
1384 | tagLabel.setText(Messages.CustomTxtParserInputWizardPage_name); | |
1385 | tagLabel.setVisible(true); | |
1386 | tagText.setVisible(true); | |
1387 | tagText.addModifyListener(updateListener); | |
1388 | break; | |
1389 | case 3: //Continue | |
1390 | tagLabel.setVisible(false); | |
1391 | tagText.setVisible(false); | |
1392 | break; | |
1393 | default: | |
1394 | break; | |
1395 | } | |
1396 | tagComposite.layout(); | |
1397 | validate(); | |
1398 | updatePreviews(); | |
1399 | }}); | |
1400 | ||
1401 | tagLabel = new Label(tagComposite, SWT.NULL); | |
1402 | tagLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false)); | |
1403 | tagLabel.setVisible(false); | |
1404 | ||
1405 | tagText = new Text(tagComposite, SWT.BORDER | SWT.SINGLE); | |
1406 | GridData gd = new GridData(SWT.FILL, SWT.CENTER, true, false); | |
1407 | gd.widthHint = 0; | |
1408 | tagText.setLayoutData(gd); | |
1409 | tagText.setVisible(false); | |
1410 | ||
1411 | actionCombo = new Combo(tagComposite, SWT.DROP_DOWN | SWT.READ_ONLY); | |
1412 | actionCombo.setItems(new String[] {Messages.CustomTxtParserInputWizardPage_set, Messages.CustomTxtParserInputWizardPage_append, Messages.CustomTxtParserInputWizardPage_appendWith}); | |
1413 | actionCombo.select(0); | |
1414 | actionCombo.addSelectionListener(updateListener); | |
1415 | ||
1416 | previewLabel = new Label(parent, SWT.NULL); | |
1417 | previewLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false)); | |
1418 | previewLabel.setText(Messages.CustomTxtParserInputWizardPage_preview); | |
1419 | ||
1420 | previewText = new Text(parent, SWT.BORDER | SWT.SINGLE | SWT.READ_ONLY); | |
1421 | gd = new GridData(SWT.FILL, SWT.CENTER, true, false); | |
1422 | gd.widthHint = 0; | |
1423 | previewText.setLayoutData(gd); | |
1424 | previewText.setText(Messages.CustomTxtParserInputWizardPage_noMatch); | |
1425 | previewText.setBackground(COLOR_WIDGET_BACKGROUND); | |
1426 | } | |
1427 | ||
1428 | private void dispose() { | |
1429 | labelComposite.dispose(); | |
1430 | tagComposite.dispose(); | |
1431 | previewLabel.dispose(); | |
1432 | previewText.dispose(); | |
1433 | } | |
1434 | ||
1435 | private void setInputNumber(int inputNumber) { | |
1436 | this.inputNumber = inputNumber; | |
1437 | inputLabel.setText(Messages.CustomTxtParserInputWizardPage_group + inputNumber + ":"); //$NON-NLS-1$ | |
1438 | labelComposite.layout(); | |
1439 | } | |
1440 | } | |
1441 | ||
1442 | private void validate() { | |
1443 | ||
1444 | definition.definitionName = logtypeText.getText().trim(); | |
1445 | definition.timeStampOutputFormat = timestampOutputFormatText.getText().trim(); | |
1446 | ||
1447 | if (selectedLine != null) { | |
1448 | selectedLine.extractInputs(); | |
1449 | treeViewer.refresh(); | |
1450 | } | |
1451 | ||
1452 | StringBuffer errors = new StringBuffer(); | |
1453 | ||
1454 | if (definition.definitionName.length() == 0) { | |
1455 | errors.append("Enter a name for the new log type. "); //$NON-NLS-1$ | |
1456 | logtypeText.setBackground(COLOR_LIGHT_RED); | |
1457 | } else { | |
1458 | logtypeText.setBackground(COLOR_TEXT_BACKGROUND); | |
1459 | for (CustomTxtTraceDefinition def : CustomTxtTraceDefinition.loadAll()) { | |
1460 | if (definition.definitionName.equals(def.definitionName)) { | |
1461 | if (editDefinitionName == null || ! editDefinitionName.equals(definition.definitionName)) { | |
1462 | errors.append("The log type name already exists. "); //$NON-NLS-1$ | |
1463 | logtypeText.setBackground(COLOR_LIGHT_RED); | |
1464 | break; | |
1465 | } | |
1466 | } | |
1467 | } | |
1468 | } | |
1469 | ||
1470 | timestampFound = false; | |
1471 | for (int i = 0; i < definition.inputs.size(); i++) { | |
1472 | ||
1473 | InputLine inputLine = definition.inputs.get(i); | |
1474 | String name = Integer.toString(i+1); | |
1475 | errors.append(validateLine(inputLine, name)); | |
1476 | } | |
1477 | if (timestampFound) { | |
1478 | if (definition.timeStampOutputFormat.length() == 0) { | |
1479 | errors.append("Enter the output format for the Time Stamp field. "); //$NON-NLS-1$ | |
1480 | timestampOutputFormatText.setBackground(COLOR_LIGHT_RED); | |
1481 | } else { | |
1482 | try { | |
1483 | new SimpleDateFormat(definition.timeStampOutputFormat); | |
1484 | timestampOutputFormatText.setBackground(COLOR_TEXT_BACKGROUND); | |
1485 | } catch (IllegalArgumentException e) { | |
1486 | errors.append("Enter a valid output format for the Time Stamp field. "); //$NON-NLS-1$ | |
1487 | timestampOutputFormatText.setBackground(COLOR_LIGHT_RED); | |
1488 | } | |
1489 | } | |
1490 | ||
1491 | } else { | |
1492 | timestampOutputFormatText.setBackground(COLOR_TEXT_BACKGROUND); | |
1493 | // timestampPreviewText.setBackground(COLOR_WIDGET_BACKGROUND); | |
1494 | // errors.append("Identify a Time Stamp group (Line "+name+"). "); | |
1495 | // timestampPreviewText.setText("*no timestamp group*"); | |
1496 | // timestampPreviewText.setBackground(COLOR_LIGHT_RED); | |
1497 | } | |
1498 | ||
1499 | if (errors.length() == 0) { | |
1500 | setDescription(defaultDescription); | |
1501 | setPageComplete(true); | |
1502 | } else { | |
1503 | setDescription(errors.toString()); | |
1504 | setPageComplete(false); | |
1505 | } | |
1506 | } | |
1507 | ||
a0a88f65 AM |
1508 | /** |
1509 | * Validate an input line. | |
1510 | * | |
1511 | * @param inputLine | |
1512 | * The line to clean up | |
1513 | * @param name | |
1514 | * The name of the line | |
1515 | * @return The cleaned up line | |
1516 | */ | |
be222f56 PT |
1517 | public StringBuffer validateLine(InputLine inputLine, String name) { |
1518 | StringBuffer errors = new StringBuffer(); | |
1519 | Line line = null; | |
1520 | if (selectedLine != null && selectedLine.inputLine.equals(inputLine)) { | |
1521 | line = selectedLine; | |
1522 | } | |
1523 | try { | |
1524 | Pattern.compile(inputLine.getRegex()); | |
1525 | if (line != null) { | |
1526 | line.regexText.setBackground(COLOR_TEXT_BACKGROUND); | |
1527 | } | |
1528 | } catch (PatternSyntaxException e) { | |
1529 | errors.append("Enter a valid regular expression (Line "+name+"). "); //$NON-NLS-1$ //$NON-NLS-2$ | |
1530 | if (line != null) { | |
1531 | line.regexText.setBackground(COLOR_LIGHT_RED); | |
1532 | } | |
1533 | } | |
1534 | if (inputLine.getMinCount() == -1) { | |
1535 | errors.append("Enter a minimum value for cardinality (Line "+name+"). "); //$NON-NLS-1$ //$NON-NLS-2$ | |
1536 | if (line != null) { | |
1537 | line.cardinalityMinText.setBackground(COLOR_LIGHT_RED); | |
1538 | } | |
1539 | } else { | |
1540 | if (line != null) { | |
1541 | line.cardinalityMinText.setBackground(COLOR_TEXT_BACKGROUND); | |
1542 | } | |
1543 | } | |
1544 | if (inputLine.getMaxCount() == -1) { | |
1545 | errors.append("Enter a maximum value for cardinality (Line "+name+"). "); //$NON-NLS-1$ //$NON-NLS-2$ | |
1546 | if (line != null) { | |
1547 | line.cardinalityMaxText.setBackground(COLOR_LIGHT_RED); | |
1548 | } | |
1549 | } else if (inputLine.getMinCount() > inputLine.getMaxCount()) { | |
1550 | errors.append("Enter correct (min <= max) values for cardinality (Line "+name+"). "); //$NON-NLS-1$ //$NON-NLS-2$ | |
1551 | if (line != null) { | |
1552 | line.cardinalityMinText.setBackground(COLOR_LIGHT_RED); | |
1553 | } | |
1554 | if (line != null) { | |
1555 | line.cardinalityMaxText.setBackground(COLOR_LIGHT_RED); | |
1556 | } | |
1557 | } else { | |
1558 | if (line != null) { | |
1559 | line.cardinalityMaxText.setBackground(COLOR_TEXT_BACKGROUND); | |
1560 | } | |
1561 | } | |
1562 | for (int i = 0; inputLine.columns != null && i < inputLine.columns.size(); i++) { | |
1563 | InputData inputData = inputLine.columns.get(i); | |
1564 | InputGroup group = null; | |
1565 | if (line != null) { | |
1566 | group = line.inputs.get(i); | |
1567 | } | |
1568 | if (inputData.name.equals(CustomTraceDefinition.TAG_TIMESTAMP)) { | |
1569 | timestampFound = true; | |
1570 | if (inputData.format.length() == 0) { | |
1571 | errors.append("Enter the input format for the Time Stamp (Line "+name+" Group "+(i+1)+"). "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ | |
1572 | if (group != null) { | |
1573 | group.tagText.setBackground(COLOR_LIGHT_RED); | |
1574 | } | |
1575 | } else { | |
1576 | try { | |
1577 | new SimpleDateFormat(inputData.format); | |
1578 | if (group != null) { | |
1579 | group.tagText.setBackground(COLOR_TEXT_BACKGROUND); | |
1580 | } | |
1581 | } catch (IllegalArgumentException e) { | |
1582 | 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$ | |
1583 | if (group != null) { | |
1584 | group.tagText.setBackground(COLOR_LIGHT_RED); | |
1585 | } | |
1586 | } | |
1587 | } | |
1588 | } else if (inputData.name.length() == 0) { | |
1589 | errors.append("Enter a name for the data group (Line "+name+" Group "+(i+1)+"). "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ | |
1590 | if (group != null) { | |
1591 | group.tagText.setBackground(COLOR_LIGHT_RED); | |
1592 | } | |
1593 | } else { | |
1594 | if (group != null) { | |
1595 | group.tagText.setBackground(COLOR_TEXT_BACKGROUND); | |
1596 | } | |
1597 | } | |
1598 | } | |
1599 | for (int i = 0; inputLine.childrenInputs != null && i < inputLine.childrenInputs.size(); i++) { | |
1600 | errors.append(validateLine(inputLine.childrenInputs.get(i), name+"."+(i+1))); //$NON-NLS-1$ | |
1601 | } | |
1602 | return errors; | |
1603 | } | |
1604 | ||
a0a88f65 AM |
1605 | /** |
1606 | * Get the trace definition. | |
1607 | * | |
1608 | * @return The trace definition | |
1609 | */ | |
be222f56 PT |
1610 | public CustomTxtTraceDefinition getDefinition() { |
1611 | return definition; | |
1612 | } | |
1613 | ||
a0a88f65 AM |
1614 | /** |
1615 | * Get the raw text of the input. | |
1616 | * | |
1617 | * @return The raw input text | |
1618 | */ | |
be222f56 PT |
1619 | public char[] getInputText() { |
1620 | return inputText.getText().toCharArray(); | |
1621 | } | |
1622 | } |