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