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