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