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