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