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