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