1 /*******************************************************************************
2 * Copyright (c) 2010, 2016 Ericsson
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
10 * Patrick Tasse - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.tracecompass
.internal
.tmf
.ui
.parsers
.wizards
;
15 import java
.io
.BufferedReader
;
16 import java
.io
.ByteArrayInputStream
;
17 import java
.io
.IOException
;
18 import java
.io
.InputStream
;
19 import java
.io
.InputStreamReader
;
21 import java
.text
.ParseException
;
22 import java
.util
.AbstractMap
.SimpleEntry
;
23 import java
.util
.ArrayList
;
24 import java
.util
.List
;
25 import java
.util
.Map
.Entry
;
27 import javax
.xml
.parsers
.DocumentBuilder
;
28 import javax
.xml
.parsers
.DocumentBuilderFactory
;
29 import javax
.xml
.parsers
.ParserConfigurationException
;
31 import org
.eclipse
.core
.resources
.IFile
;
32 import org
.eclipse
.core
.runtime
.CoreException
;
33 import org
.eclipse
.core
.runtime
.FileLocator
;
34 import org
.eclipse
.core
.runtime
.IPath
;
35 import org
.eclipse
.core
.runtime
.Path
;
36 import org
.eclipse
.core
.runtime
.Platform
;
37 import org
.eclipse
.jface
.viewers
.AbstractTreeViewer
;
38 import org
.eclipse
.jface
.viewers
.ColumnLabelProvider
;
39 import org
.eclipse
.jface
.viewers
.ISelection
;
40 import org
.eclipse
.jface
.viewers
.ISelectionChangedListener
;
41 import org
.eclipse
.jface
.viewers
.IStructuredSelection
;
42 import org
.eclipse
.jface
.viewers
.ITreeContentProvider
;
43 import org
.eclipse
.jface
.viewers
.SelectionChangedEvent
;
44 import org
.eclipse
.jface
.viewers
.StructuredSelection
;
45 import org
.eclipse
.jface
.viewers
.TreeViewer
;
46 import org
.eclipse
.jface
.viewers
.Viewer
;
47 import org
.eclipse
.jface
.wizard
.WizardPage
;
48 import org
.eclipse
.osgi
.util
.NLS
;
49 import org
.eclipse
.swt
.SWT
;
50 import org
.eclipse
.swt
.browser
.Browser
;
51 import org
.eclipse
.swt
.custom
.SashForm
;
52 import org
.eclipse
.swt
.custom
.ScrolledComposite
;
53 import org
.eclipse
.swt
.custom
.StyleRange
;
54 import org
.eclipse
.swt
.custom
.StyledText
;
55 import org
.eclipse
.swt
.events
.ModifyEvent
;
56 import org
.eclipse
.swt
.events
.ModifyListener
;
57 import org
.eclipse
.swt
.events
.SelectionAdapter
;
58 import org
.eclipse
.swt
.events
.SelectionEvent
;
59 import org
.eclipse
.swt
.events
.SelectionListener
;
60 import org
.eclipse
.swt
.graphics
.Color
;
61 import org
.eclipse
.swt
.graphics
.Font
;
62 import org
.eclipse
.swt
.graphics
.FontData
;
63 import org
.eclipse
.swt
.graphics
.Image
;
64 import org
.eclipse
.swt
.graphics
.Point
;
65 import org
.eclipse
.swt
.graphics
.Rectangle
;
66 import org
.eclipse
.swt
.layout
.FillLayout
;
67 import org
.eclipse
.swt
.layout
.GridData
;
68 import org
.eclipse
.swt
.layout
.GridLayout
;
69 import org
.eclipse
.swt
.widgets
.Button
;
70 import org
.eclipse
.swt
.widgets
.Combo
;
71 import org
.eclipse
.swt
.widgets
.Composite
;
72 import org
.eclipse
.swt
.widgets
.Display
;
73 import org
.eclipse
.swt
.widgets
.Group
;
74 import org
.eclipse
.swt
.widgets
.Label
;
75 import org
.eclipse
.swt
.widgets
.Shell
;
76 import org
.eclipse
.swt
.widgets
.Text
;
77 import org
.eclipse
.tracecompass
.internal
.tmf
.ui
.Activator
;
78 import org
.eclipse
.tracecompass
.internal
.tmf
.ui
.Messages
;
79 import org
.eclipse
.tracecompass
.tmf
.core
.parsers
.custom
.CustomTraceDefinition
;
80 import org
.eclipse
.tracecompass
.tmf
.core
.parsers
.custom
.CustomTraceDefinition
.Tag
;
81 import org
.eclipse
.tracecompass
.tmf
.core
.parsers
.custom
.CustomXmlInputAttribute
;
82 import org
.eclipse
.tracecompass
.tmf
.core
.parsers
.custom
.CustomXmlInputElement
;
83 import org
.eclipse
.tracecompass
.tmf
.core
.parsers
.custom
.CustomXmlTrace
;
84 import org
.eclipse
.tracecompass
.tmf
.core
.parsers
.custom
.CustomXmlTraceDefinition
;
85 import org
.eclipse
.tracecompass
.tmf
.core
.project
.model
.TmfTraceType
;
86 import org
.eclipse
.tracecompass
.tmf
.core
.project
.model
.TraceTypeHelper
;
87 import org
.eclipse
.tracecompass
.tmf
.core
.timestamp
.TmfTimestampFormat
;
88 import org
.osgi
.framework
.Bundle
;
89 import org
.w3c
.dom
.Document
;
90 import org
.w3c
.dom
.Element
;
91 import org
.w3c
.dom
.NamedNodeMap
;
92 import org
.w3c
.dom
.Node
;
93 import org
.w3c
.dom
.NodeList
;
94 import org
.xml
.sax
.EntityResolver
;
95 import org
.xml
.sax
.ErrorHandler
;
96 import org
.xml
.sax
.InputSource
;
97 import org
.xml
.sax
.SAXException
;
98 import org
.xml
.sax
.SAXParseException
;
100 import com
.google
.common
.base
.Joiner
;
103 * Input wizard page for custom XML trace parsers.
105 * @author Patrick Tasse
107 public class CustomXmlParserInputWizardPage
extends WizardPage
{
109 private static final String DEFAULT_TIMESTAMP_FORMAT
= "yyyy-MM-dd HH:mm:ss.SSS"; //$NON-NLS-1$
110 private static final String TIMESTAMP_FORMAT_BUNDLE
= "org.eclipse.tracecompass.doc.user"; //$NON-NLS-1$
111 private static final String TIMESTAMP_FORMAT_PATH
= "reference/api/org/eclipse/tracecompass/tmf/core/timestamp/TmfTimestampFormat.html"; //$NON-NLS-1$
112 private static final Image ELEMENT_IMAGE
= Activator
.getDefault().getImageFromPath("/icons/elcl16/element_icon.gif"); //$NON-NLS-1$
113 private static final Image ADD_IMAGE
= Activator
.getDefault().getImageFromPath("/icons/elcl16/add_button.gif"); //$NON-NLS-1$
114 private static final Image ADD_NEXT_IMAGE
= Activator
.getDefault().getImageFromPath("/icons/elcl16/addnext_button.gif"); //$NON-NLS-1$
115 private static final Image ADD_CHILD_IMAGE
= Activator
.getDefault().getImageFromPath("/icons/elcl16/addchild_button.gif"); //$NON-NLS-1$
116 private static final Image ADD_MANY_IMAGE
= Activator
.getDefault().getImageFromPath("/icons/elcl16/addmany_button.gif"); //$NON-NLS-1$
117 private static final Image DELETE_IMAGE
= Activator
.getDefault().getImageFromPath("/icons/elcl16/delete_button.gif"); //$NON-NLS-1$
118 private static final Image MOVE_UP_IMAGE
= Activator
.getDefault().getImageFromPath("/icons/elcl16/moveup_button.gif"); //$NON-NLS-1$
119 private static final Image MOVE_DOWN_IMAGE
= Activator
.getDefault().getImageFromPath("/icons/elcl16/movedown_button.gif"); //$NON-NLS-1$
120 private static final Image HELP_IMAGE
= Activator
.getDefault().getImageFromPath("/icons/elcl16/help_button.gif"); //$NON-NLS-1$
121 private static final Color COLOR_LIGHT_RED
= new Color(Display
.getDefault(), 255, 192, 192);
122 private static final Color COLOR_TEXT_BACKGROUND
= Display
.getDefault().getSystemColor(SWT
.COLOR_WHITE
);
123 private static final Color COLOR_WIDGET_BACKGROUND
= Display
.getDefault().getSystemColor(SWT
.COLOR_WIDGET_BACKGROUND
);
124 private static final Color COLOR_GRAY
= Display
.getDefault().getSystemColor(SWT
.COLOR_GRAY
);
126 private final ISelection selection
;
127 private CustomXmlTraceDefinition definition
;
128 private String editCategoryName
;
129 private String editDefinitionName
;
130 private String defaultDescription
;
131 private ElementNode selectedElement
;
132 private Composite container
;
133 private Text categoryText
;
134 private Text logtypeText
;
135 private Text timeStampOutputFormatText
;
136 private Text timeStampPreviewText
;
137 private Button removeButton
;
138 private Button addChildButton
;
139 private Button addNextButton
;
140 private Button moveUpButton
;
141 private Button moveDownButton
;
142 private ScrolledComposite elementScrolledComposite
;
143 private TreeViewer treeViewer
;
144 private Composite elementContainer
;
145 private Text errorText
;
146 private StyledText inputText
;
147 private Font fixedFont
;
148 private UpdateListener updateListener
;
149 private Browser helpBrowser
;
150 private Element documentElement
;
152 // variables used recursively through element traversal
153 private String timeStampValue
;
154 private String timeStampFormat
;
155 private boolean timeStampFound
;
156 private int logEntriesCount
;
157 private boolean logEntryFound
;
167 protected CustomXmlParserInputWizardPage(ISelection selection
, CustomXmlTraceDefinition definition
) {
168 super("CustomXmlParserWizardPage"); //$NON-NLS-1$
169 if (definition
== null) {
170 setTitle(Messages
.CustomXmlParserInputWizardPage_titleNew
);
171 defaultDescription
= Messages
.CustomXmlParserInputWizardPage_descriptionNew
;
173 setTitle(Messages
.CustomXmlParserInputWizardPage_titleEdit
);
174 defaultDescription
= Messages
.CustomXmlParserInputWizardPage_descriptionEdit
;
176 setDescription(defaultDescription
);
177 this.selection
= selection
;
178 this.definition
= definition
;
179 if (definition
!= null) {
180 this.editCategoryName
= definition
.categoryName
;
181 this.editDefinitionName
= definition
.definitionName
;
186 public void createControl(Composite parent
) {
187 container
= new Composite(parent
, SWT
.NULL
);
188 container
.setLayout(new GridLayout());
190 updateListener
= new UpdateListener();
192 Composite headerComposite
= new Composite(container
, SWT
.FILL
);
193 GridLayout headerLayout
= new GridLayout(5, false);
194 headerLayout
.marginHeight
= 0;
195 headerLayout
.marginWidth
= 0;
196 headerComposite
.setLayout(headerLayout
);
197 headerComposite
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
199 Label categoryLabel
= new Label(headerComposite
, SWT
.NULL
);
200 categoryLabel
.setText(Messages
.CustomXmlParserInputWizardPage_category
);
202 categoryText
= new Text(headerComposite
, SWT
.BORDER
| SWT
.SINGLE
);
203 categoryText
.setLayoutData(new GridData(120, SWT
.DEFAULT
));
205 Label timeStampFormatLabel
= new Label(headerComposite
, SWT
.NULL
);
206 timeStampFormatLabel
.setText(Messages
.CustomXmlParserInputWizardPage_timestampFormat
);
208 timeStampOutputFormatText
= new Text(headerComposite
, SWT
.BORDER
| SWT
.SINGLE
);
209 timeStampOutputFormatText
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
210 timeStampOutputFormatText
.setText(DEFAULT_TIMESTAMP_FORMAT
);
211 timeStampOutputFormatText
.addPaintListener(e
-> {
212 if (!timeStampOutputFormatText
.isFocusControl() && timeStampOutputFormatText
.getText().trim().isEmpty()) {
213 e
.gc
.setForeground(COLOR_GRAY
);
214 int borderWidth
= timeStampOutputFormatText
.getBorderWidth();
215 e
.gc
.drawText(Messages
.CustomXmlParserInputWizardPage_default
, borderWidth
, borderWidth
);
219 Button timeStampFormatHelpButton
= new Button(headerComposite
, SWT
.PUSH
);
220 timeStampFormatHelpButton
.setImage(HELP_IMAGE
);
221 timeStampFormatHelpButton
.setToolTipText(Messages
.CustomXmlParserInputWizardPage_timestampFormatHelp
);
222 timeStampFormatHelpButton
.addSelectionListener(new SelectionAdapter() {
224 public void widgetSelected(SelectionEvent e
) {
225 Bundle plugin
= Platform
.getBundle(TIMESTAMP_FORMAT_BUNDLE
);
226 IPath path
= new Path(TIMESTAMP_FORMAT_PATH
);
227 URL fileURL
= FileLocator
.find(plugin
, path
, null);
229 URL pageURL
= FileLocator
.toFileURL(fileURL
);
230 openHelpShell(pageURL
.toString());
231 } catch (IOException e1
) {
236 Label logtypeLabel
= new Label(headerComposite
, SWT
.NULL
);
237 logtypeLabel
.setText(Messages
.CustomXmlParserInputWizardPage_logType
);
239 logtypeText
= new Text(headerComposite
, SWT
.BORDER
| SWT
.SINGLE
);
240 logtypeText
.setLayoutData(new GridData(120, SWT
.DEFAULT
));
241 logtypeText
.setFocus();
243 Label timeStampPreviewLabel
= new Label(headerComposite
, SWT
.NULL
);
244 timeStampPreviewLabel
.setText(Messages
.CustomXmlParserInputWizardPage_preview
);
246 timeStampPreviewText
= new Text(headerComposite
, SWT
.BORDER
| SWT
.SINGLE
| SWT
.READ_ONLY
);
247 timeStampPreviewText
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false, 2, 1));
248 timeStampPreviewText
.setText("*no time stamp element or attribute*"); //$NON-NLS-1$
252 SashForm vSash
= new SashForm(container
, SWT
.VERTICAL
);
253 vSash
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
254 vSash
.setBackground(COLOR_GRAY
);
256 SashForm hSash
= new SashForm(vSash
, SWT
.HORIZONTAL
);
257 hSash
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
259 ScrolledComposite treeScrolledComposite
= new ScrolledComposite(hSash
, SWT
.V_SCROLL
| SWT
.H_SCROLL
);
260 treeScrolledComposite
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
261 Composite treeContainer
= new Composite(treeScrolledComposite
, SWT
.NONE
);
262 treeContainer
.setLayout(new FillLayout());
263 treeScrolledComposite
.setContent(treeContainer
);
264 treeScrolledComposite
.setExpandHorizontal(true);
265 treeScrolledComposite
.setExpandVertical(true);
267 treeViewer
= new TreeViewer(treeContainer
, SWT
.SINGLE
| SWT
.BORDER
);
268 treeViewer
.setContentProvider(new InputElementTreeNodeContentProvider());
269 treeViewer
.setLabelProvider(new InputElementTreeLabelProvider());
270 treeViewer
.addSelectionChangedListener(new InputElementTreeSelectionChangedListener());
271 treeContainer
.layout();
273 treeScrolledComposite
274 .setMinSize(treeContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).x
, treeContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).y
);
276 elementScrolledComposite
= new ScrolledComposite(hSash
, SWT
.V_SCROLL
);
277 elementScrolledComposite
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
278 elementContainer
= new Composite(elementScrolledComposite
, SWT
.NONE
);
279 GridLayout gl
= new GridLayout();
282 elementContainer
.setLayout(gl
);
283 elementScrolledComposite
.setContent(elementContainer
);
284 elementScrolledComposite
.setExpandHorizontal(true);
285 elementScrolledComposite
.setExpandVertical(true);
287 if (definition
== null) {
288 definition
= new CustomXmlTraceDefinition();
290 loadDefinition(definition
);
291 treeViewer
.expandAll();
292 elementContainer
.layout();
294 categoryText
.addModifyListener(updateListener
);
295 logtypeText
.addModifyListener(updateListener
);
296 timeStampOutputFormatText
.addModifyListener(updateListener
);
298 elementScrolledComposite
.setMinSize(elementContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).x
,
299 elementContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).y
- 1);
301 hSash
.setWeights(new int[] { 1, 2 });
303 if (definition
.rootInputElement
== null) {
304 removeButton
.setEnabled(false);
305 addChildButton
.setToolTipText(Messages
.CustomXmlParserInputWizardPage_addDocumentElement
);
306 addNextButton
.setEnabled(false);
307 moveUpButton
.setEnabled(false);
308 moveDownButton
.setEnabled(false);
309 } else { // root is selected
310 addNextButton
.setEnabled(false);
313 Composite sashBottom
= new Composite(vSash
, SWT
.NONE
);
314 GridLayout sashBottomLayout
= new GridLayout(2, false);
315 sashBottomLayout
.marginHeight
= 0;
316 sashBottomLayout
.marginWidth
= 0;
317 sashBottom
.setLayout(sashBottomLayout
);
319 Label previewLabel
= new Label(sashBottom
, SWT
.NULL
);
320 previewLabel
.setText(Messages
.CustomXmlParserInputWizardPage_previewInput
);
322 errorText
= new Text(sashBottom
, SWT
.SINGLE
| SWT
.READ_ONLY
);
323 errorText
.setBackground(COLOR_WIDGET_BACKGROUND
);
324 errorText
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
325 errorText
.setVisible(false);
327 inputText
= new StyledText(sashBottom
, SWT
.MULTI
| SWT
.V_SCROLL
| SWT
.H_SCROLL
);
328 if (fixedFont
== null) {
329 if (System
.getProperty("os.name").contains("Windows")) { //$NON-NLS-1$ //$NON-NLS-2$
330 fixedFont
= new Font(Display
.getCurrent(), new FontData("Courier New", 10, SWT
.NORMAL
)); //$NON-NLS-1$
332 fixedFont
= new Font(Display
.getCurrent(), new FontData("Monospace", 10, SWT
.NORMAL
)); //$NON-NLS-1$
335 inputText
.setFont(fixedFont
);
336 GridData gd
= new GridData(SWT
.FILL
, SWT
.FILL
, true, true, 2, 1);
337 gd
.heightHint
= inputText
.computeSize(SWT
.DEFAULT
, inputText
.getLineHeight() * 4).y
;
339 inputText
.setLayoutData(gd
);
340 inputText
.setText(getSelectionText());
341 inputText
.addModifyListener(e
-> parseXmlInput(inputText
.getText()));
342 inputText
.addModifyListener(updateListener
);
344 vSash
.setWeights(new int[] { hSash
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).y
, sashBottom
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).y
});
346 setControl(container
);
349 private void createButtonBar() {
350 Composite buttonBar
= new Composite(container
, SWT
.NONE
);
351 GridLayout buttonBarLayout
= new GridLayout(6, false);
352 buttonBarLayout
.marginHeight
= 0;
353 buttonBarLayout
.marginWidth
= 0;
354 buttonBar
.setLayout(buttonBarLayout
);
356 removeButton
= new Button(buttonBar
, SWT
.PUSH
);
357 removeButton
.setImage(DELETE_IMAGE
);
358 removeButton
.setToolTipText(Messages
.CustomXmlParserInputWizardPage_removeElement
);
359 removeButton
.addSelectionListener(new SelectionAdapter() {
361 public void widgetSelected(SelectionEvent e
) {
362 if (treeViewer
.getSelection().isEmpty() || selectedElement
== null) {
366 CustomXmlInputElement inputElement
= (CustomXmlInputElement
) ((IStructuredSelection
) treeViewer
.getSelection()).getFirstElement();
367 if (inputElement
== definition
.rootInputElement
) {
368 definition
.rootInputElement
= null;
370 inputElement
.getParentElement().getChildElements().remove(inputElement
);
372 treeViewer
.refresh();
375 removeButton
.setEnabled(false);
376 if (definition
.rootInputElement
== null) {
377 addChildButton
.setEnabled(true);
378 addChildButton
.setToolTipText(Messages
.CustomXmlParserInputWizardPage_addDocumentEleemnt
);
380 addChildButton
.setEnabled(false);
382 addNextButton
.setEnabled(false);
383 moveUpButton
.setEnabled(false);
384 moveDownButton
.setEnabled(false);
388 addChildButton
= new Button(buttonBar
, SWT
.PUSH
);
389 addChildButton
.setImage(ADD_CHILD_IMAGE
);
390 addChildButton
.setToolTipText(Messages
.CustomXmlParserInputWizardPage_addChildElement
);
391 addChildButton
.addSelectionListener(new SelectionAdapter() {
393 public void widgetSelected(SelectionEvent e
) {
394 CustomXmlInputElement inputElement
= new CustomXmlInputElement("", false, Tag
.IGNORE
, Tag
.IGNORE
.toString(), 0, "", null); //$NON-NLS-1$ //$NON-NLS-2$
395 if (definition
.rootInputElement
== null) {
396 definition
.rootInputElement
= inputElement
;
397 inputElement
.setElementName(getChildNameSuggestion(null));
398 } else if (treeViewer
.getSelection().isEmpty()) {
401 CustomXmlInputElement parentInputElement
= (CustomXmlInputElement
) ((IStructuredSelection
) treeViewer
.getSelection()).getFirstElement();
402 parentInputElement
.addChild(inputElement
);
403 inputElement
.setElementName(getChildNameSuggestion(parentInputElement
));
405 treeViewer
.refresh();
406 treeViewer
.setSelection(new StructuredSelection(inputElement
), true);
410 addNextButton
= new Button(buttonBar
, SWT
.PUSH
);
411 addNextButton
.setImage(ADD_NEXT_IMAGE
);
412 addNextButton
.setToolTipText(Messages
.CustomXmlParserInputWizardPage_addNextElement
);
413 addNextButton
.addSelectionListener(new SelectionAdapter() {
415 public void widgetSelected(SelectionEvent e
) {
416 CustomXmlInputElement inputElement
= new CustomXmlInputElement("", false, Tag
.IGNORE
, Tag
.IGNORE
.toString(), 0, "", null); //$NON-NLS-1$ //$NON-NLS-2$
417 if (definition
.rootInputElement
== null) {
418 definition
.rootInputElement
= inputElement
;
419 inputElement
.setElementName(getChildNameSuggestion(null));
420 } else if (treeViewer
.getSelection().isEmpty()) {
423 CustomXmlInputElement previousInputElement
= (CustomXmlInputElement
) ((IStructuredSelection
) treeViewer
.getSelection()).getFirstElement();
424 if (previousInputElement
== definition
.rootInputElement
) {
427 previousInputElement
.addNext(inputElement
);
428 inputElement
.setElementName(getChildNameSuggestion(inputElement
.getParentElement()));
430 treeViewer
.refresh();
431 treeViewer
.setSelection(new StructuredSelection(inputElement
), true);
435 Button feelingLuckyButton
= new Button(buttonBar
, SWT
.PUSH
);
436 feelingLuckyButton
.setImage(ADD_MANY_IMAGE
);
437 feelingLuckyButton
.setToolTipText(Messages
.CustomXmlParserInputWizardPage_feelingLucky
);
438 feelingLuckyButton
.addSelectionListener(new SelectionAdapter() {
440 public void widgetSelected(SelectionEvent e
) {
441 CustomXmlInputElement inputElement
= null;
442 if (definition
.rootInputElement
== null) {
443 if (getChildNameSuggestion(null).length() != 0) {
444 inputElement
= new CustomXmlInputElement(getChildNameSuggestion(null), false, Tag
.IGNORE
, Tag
.IGNORE
.toString(), 0, "", null); //$NON-NLS-1$
445 definition
.rootInputElement
= inputElement
;
446 feelingLucky(inputElement
);
450 } else if (treeViewer
.getSelection().isEmpty()) {
453 inputElement
= (CustomXmlInputElement
) ((IStructuredSelection
) treeViewer
.getSelection()).getFirstElement();
454 feelingLucky(inputElement
);
456 treeViewer
.refresh();
457 treeViewer
.setSelection(new StructuredSelection(inputElement
), true);
458 treeViewer
.expandToLevel(inputElement
, AbstractTreeViewer
.ALL_LEVELS
);
462 moveUpButton
= new Button(buttonBar
, SWT
.PUSH
);
463 moveUpButton
.setImage(MOVE_UP_IMAGE
);
464 moveUpButton
.setToolTipText(Messages
.CustomXmlParserInputWizardPage_moveUp
);
465 moveUpButton
.addSelectionListener(new SelectionAdapter() {
467 public void widgetSelected(SelectionEvent e
) {
468 if (treeViewer
.getSelection().isEmpty()) {
471 CustomXmlInputElement inputElement
= (CustomXmlInputElement
) ((IStructuredSelection
) treeViewer
.getSelection()).getFirstElement();
472 if (inputElement
== definition
.rootInputElement
) {
475 inputElement
.moveUp();
476 treeViewer
.refresh();
482 moveDownButton
= new Button(buttonBar
, SWT
.PUSH
);
483 moveDownButton
.setImage(MOVE_DOWN_IMAGE
);
484 moveDownButton
.setToolTipText(Messages
.CustomXmlParserInputWizardPage_moveDown
);
485 moveDownButton
.addSelectionListener(new SelectionAdapter() {
487 public void widgetSelected(SelectionEvent e
) {
488 if (treeViewer
.getSelection().isEmpty()) {
491 CustomXmlInputElement inputElement
= (CustomXmlInputElement
) ((IStructuredSelection
) treeViewer
.getSelection()).getFirstElement();
492 if (inputElement
== definition
.rootInputElement
) {
495 inputElement
.moveDown();
496 treeViewer
.refresh();
503 private void feelingLucky(CustomXmlInputElement inputElement
) {
505 String attributeName
= getAttributeNameSuggestion(inputElement
);
506 if (attributeName
.length() == 0) {
509 CustomXmlInputAttribute attribute
= new CustomXmlInputAttribute(attributeName
, Tag
.OTHER
, attributeName
, 0, ""); //$NON-NLS-1$
510 inputElement
.addAttribute(attribute
);
513 String childName
= getChildNameSuggestion(inputElement
);
514 if (childName
.length() == 0) {
517 CustomXmlInputElement childElement
= new CustomXmlInputElement(childName
, false, Tag
.IGNORE
, Tag
.IGNORE
.toString(), 0, "", null); //$NON-NLS-1$
518 inputElement
.addChild(childElement
);
519 feelingLucky(childElement
);
523 private static class InputElementTreeNodeContentProvider
implements ITreeContentProvider
{
526 public Object
[] getElements(Object inputElement
) {
527 CustomXmlTraceDefinition def
= (CustomXmlTraceDefinition
) inputElement
;
528 if (def
.rootInputElement
!= null) {
529 return new Object
[] { def
.rootInputElement
};
531 return new Object
[0];
535 public Object
[] getChildren(Object parentElement
) {
536 CustomXmlInputElement inputElement
= (CustomXmlInputElement
) parentElement
;
537 if (inputElement
.getChildElements() == null) {
538 return new CustomXmlInputElement
[0];
540 return inputElement
.getChildElements().toArray();
544 public boolean hasChildren(Object element
) {
545 CustomXmlInputElement inputElement
= (CustomXmlInputElement
) element
;
546 return (inputElement
.getChildElements() != null && inputElement
.getChildElements().size() > 0);
550 public void dispose() {
554 public void inputChanged(Viewer viewer
, Object oldInput
, Object newInput
) {
558 public Object
getParent(Object element
) {
559 CustomXmlInputElement inputElement
= (CustomXmlInputElement
) element
;
560 return inputElement
.getParentElement();
564 private static class InputElementTreeLabelProvider
extends ColumnLabelProvider
{
567 public Image
getImage(Object element
) {
568 return ELEMENT_IMAGE
;
572 public String
getText(Object element
) {
573 CustomXmlInputElement inputElement
= (CustomXmlInputElement
) element
;
574 return (inputElement
.getElementName().trim().length() == 0) ?
"?" : inputElement
.getElementName(); //$NON-NLS-1$
578 private class InputElementTreeSelectionChangedListener
implements ISelectionChangedListener
{
580 public void selectionChanged(SelectionChangedEvent event
) {
581 if (selectedElement
!= null) {
582 selectedElement
.dispose();
584 if (!(event
.getSelection().isEmpty()) && event
.getSelection() instanceof IStructuredSelection
) {
585 IStructuredSelection sel
= (IStructuredSelection
) event
.getSelection();
586 CustomXmlInputElement inputElement
= (CustomXmlInputElement
) sel
.getFirstElement();
587 selectedElement
= new ElementNode(elementContainer
, inputElement
);
588 elementContainer
.layout();
589 elementScrolledComposite
.setMinSize(elementContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).x
,
590 elementContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).y
- 1);
594 removeButton
.setEnabled(true);
595 addChildButton
.setEnabled(true);
596 addChildButton
.setToolTipText(Messages
.CustomXmlParserInputWizardPage_addChildElement
);
597 if (definition
.rootInputElement
== inputElement
) {
598 addNextButton
.setEnabled(false);
600 addNextButton
.setEnabled(true);
602 moveUpButton
.setEnabled(true);
603 moveDownButton
.setEnabled(true);
605 removeButton
.setEnabled(false);
606 if (definition
.rootInputElement
== null) {
607 addChildButton
.setEnabled(true);
608 addChildButton
.setToolTipText(Messages
.CustomXmlParserInputWizardPage_addDocumentElement
);
610 addChildButton
.setEnabled(false);
612 addNextButton
.setEnabled(false);
613 moveUpButton
.setEnabled(false);
614 moveDownButton
.setEnabled(false);
620 public void dispose() {
621 if (fixedFont
!= null) {
628 private void loadDefinition(CustomXmlTraceDefinition def
) {
629 categoryText
.setText(def
.categoryName
);
630 logtypeText
.setText(def
.definitionName
);
631 if (def
.timeStampOutputFormat
!= null) {
632 timeStampOutputFormatText
.setText(def
.timeStampOutputFormat
);
634 timeStampOutputFormatText
.setText(""); //$NON-NLS-1$
636 treeViewer
.setInput(def
);
638 if (def
.rootInputElement
!= null) {
639 treeViewer
.setSelection(new StructuredSelection(def
.rootInputElement
));
643 private String
getName(CustomXmlInputElement inputElement
) {
644 String name
= (inputElement
.getElementName().trim().length() == 0) ?
"?" : inputElement
.getElementName().trim(); //$NON-NLS-1$
645 if (inputElement
.getParentElement() == null) {
648 return getName(inputElement
.getParentElement()) + " : " + name
; //$NON-NLS-1$
651 private String
getName(CustomXmlInputAttribute inputAttribute
, CustomXmlInputElement inputElement
) {
652 String name
= (inputAttribute
.getAttributeName().trim().length() == 0) ?
"?" : inputAttribute
.getAttributeName().trim(); //$NON-NLS-1$
653 return getName(inputElement
) + " : " + name
; //$NON-NLS-1$
657 public void setVisible(boolean visible
) {
662 super.setVisible(visible
);
666 * Get the global list of inputs.
668 * @return The list of inputs
670 public List
<Entry
<Tag
, String
>> getInputs() {
671 return getInputs(definition
.rootInputElement
);
675 * Get the list of inputs for a given element, recursively.
677 * @param inputElement
679 * @return The list of inputs
681 public List
<Entry
<Tag
, String
>> getInputs(CustomXmlInputElement inputElement
) {
682 List
<Entry
<Tag
, String
>> inputs
= new ArrayList
<>();
683 if (inputElement
.getInputTag() != null && !inputElement
.getInputTag().equals(Tag
.IGNORE
)) {
684 Entry
<Tag
, String
> input
= new SimpleEntry
<>(inputElement
.getInputTag(), inputElement
.getInputName());
685 if (!inputs
.contains(input
)) {
689 if (inputElement
.getAttributes() != null) {
690 for (CustomXmlInputAttribute attribute
: inputElement
.getAttributes()) {
691 Entry
<Tag
, String
> input
= new SimpleEntry
<>(attribute
.getInputTag(), attribute
.getInputName());
692 if (!inputs
.contains(input
)) {
697 if (inputElement
.getChildElements() != null) {
698 for (CustomXmlInputElement childInputElement
: inputElement
.getChildElements()) {
699 for (Entry
<Tag
, String
> input
: getInputs(childInputElement
)) {
700 if (!inputs
.contains(input
)) {
709 private void removeElement() {
710 selectedElement
.dispose();
711 selectedElement
= null;
712 elementContainer
.layout();
713 elementScrolledComposite
.setMinSize(elementContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).x
,
714 elementContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).y
- 1);
718 private String
getSelectionText() {
719 InputStream inputStream
= null;
720 if (this.selection
instanceof IStructuredSelection
) {
721 Object sel
= ((IStructuredSelection
) this.selection
).getFirstElement();
722 if (sel
instanceof IFile
) {
723 IFile file
= (IFile
) sel
;
725 inputStream
= file
.getContents();
726 } catch (CoreException e
) {
727 return ""; //$NON-NLS-1$
731 if (inputStream
!= null) {
732 try (BufferedReader reader
= new BufferedReader(new InputStreamReader(inputStream
));) {
733 StringBuilder sb
= new StringBuilder();
735 while ((line
= reader
.readLine()) != null) {
739 parseXmlInput(sb
.toString());
740 return sb
.toString();
741 } catch (IOException e
) {
742 return ""; //$NON-NLS-1$
745 return ""; //$NON-NLS-1$
748 private void parseXmlInput(final String string
) {
750 DocumentBuilderFactory dbf
= DocumentBuilderFactory
.newInstance();
751 DocumentBuilder db
= dbf
.newDocumentBuilder();
753 // The following allows xml parsing without access to the dtd
754 EntityResolver resolver
= (publicId
, systemId
) -> {
755 String empty
= ""; //$NON-NLS-1$
756 ByteArrayInputStream bais
= new ByteArrayInputStream(empty
.getBytes());
757 return new InputSource(bais
);
759 db
.setEntityResolver(resolver
);
761 // The following catches xml parsing exceptions
762 db
.setErrorHandler(new ErrorHandler() {
764 public void error(SAXParseException saxparseexception
) throws SAXException
{
768 public void warning(SAXParseException saxparseexception
) throws SAXException
{
772 public void fatalError(SAXParseException saxparseexception
) throws SAXException
{
773 if (string
.trim().length() != 0) {
774 errorText
.setText(saxparseexception
.getMessage());
775 errorText
.setBackground(COLOR_LIGHT_RED
);
776 errorText
.setVisible(true);
778 throw saxparseexception
;
782 errorText
.setVisible(false);
784 doc
= db
.parse(new ByteArrayInputStream(string
.getBytes()));
785 documentElement
= doc
.getDocumentElement();
786 } catch (ParserConfigurationException e
) {
787 Activator
.getDefault().logError("Error pasing XML input string: " + string
, e
); //$NON-NLS-1$
788 documentElement
= null;
789 } catch (SAXException e
) {
790 documentElement
= null;
791 } catch (IOException e
) {
792 Activator
.getDefault().logError("Error pasing XML input string: " + string
, e
); //$NON-NLS-1$
793 documentElement
= null;
797 private void initValues() {
798 timeStampValue
= null;
799 timeStampFormat
= null;
801 logEntryFound
= false;
804 private void updatePreviews() {
805 if (inputText
== null) {
806 // early update during construction
809 inputText
.setStyleRanges(new StyleRange
[] {});
810 if (selectedElement
== null) {
816 selectedElement
.updatePreview();
818 if (timeStampValue
!= null && timeStampFormat
!= null) {
820 TmfTimestampFormat timestampFormat
= new TmfTimestampFormat(timeStampFormat
);
821 long timestamp
= timestampFormat
.parseValue(timeStampValue
);
822 if (timeStampOutputFormatText
.getText().trim().isEmpty()) {
823 timestampFormat
= new TmfTimestampFormat();
825 timestampFormat
= new TmfTimestampFormat(timeStampOutputFormatText
.getText().trim());
827 timeStampPreviewText
.setText(timestampFormat
.format(timestamp
));
828 } catch (ParseException e
) {
829 timeStampPreviewText
.setText("*parse exception* [" + timeStampValue
+ "] <> [" + timeStampFormat
+ "]"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
830 } catch (IllegalArgumentException e
) {
831 timeStampPreviewText
.setText("*parse exception* [Illegal Argument]"); //$NON-NLS-1$
834 timeStampPreviewText
.setText("*no matching time stamp*"); //$NON-NLS-1$
838 private void openHelpShell(String url
) {
839 if (helpBrowser
!= null && !helpBrowser
.isDisposed()) {
840 helpBrowser
.getShell().setActive();
841 if (!helpBrowser
.getUrl().equals(url
)) {
842 helpBrowser
.setUrl(url
);
846 final Shell helpShell
= new Shell(getShell(), SWT
.SHELL_TRIM
);
847 helpShell
.setLayout(new FillLayout());
848 helpBrowser
= new Browser(helpShell
, SWT
.NONE
);
849 helpBrowser
.addTitleListener(event
-> helpShell
.setText(event
.title
));
850 Rectangle r
= container
.getBounds();
851 Point p
= container
.toDisplay(r
.x
, r
.y
);
852 Rectangle trim
= helpShell
.computeTrim(p
.x
+ (r
.width
- 750) / 2, p
.y
+ (r
.height
- 400) / 2, 750, 400);
853 helpShell
.setBounds(trim
);
855 helpBrowser
.setUrl(url
);
858 private class UpdateListener
implements ModifyListener
, SelectionListener
{
861 public void modifyText(ModifyEvent e
) {
867 public void widgetDefaultSelected(SelectionEvent e
) {
873 public void widgetSelected(SelectionEvent e
) {
880 private class ElementNode
{
881 private final CustomXmlInputElement inputElement
;
882 private final Group group
;
883 private List
<Attribute
> attributes
= new ArrayList
<>();
884 private List
<ElementNode
> childElements
= new ArrayList
<>();
885 private Text elementNameText
;
886 private Composite tagComposite
;
887 private Combo tagCombo
;
888 private Label tagLabel
;
889 private Text tagText
;
890 private Combo actionCombo
;
891 private Label previewLabel
;
892 private Text previewText
;
893 private Button logEntryButton
;
894 private Button eventTypeButton
;
895 private Text eventTypeText
;
896 private Label fillerLabel
;
897 private Composite addAttributeComposite
;
898 private Button addAttributeButton
;
899 private Label addAttributeLabel
;
901 public ElementNode(Composite parent
, CustomXmlInputElement inputElement
) {
902 this.inputElement
= inputElement
;
904 group
= new Group(parent
, SWT
.NONE
);
905 GridLayout gl
= new GridLayout(2, false);
908 group
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
909 group
.setText(getName(inputElement
));
911 Label label
= new Label(group
, SWT
.NULL
);
912 label
.setText(Messages
.CustomXmlParserInputWizardPage_elementName
);
913 label
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
915 elementNameText
= new Text(group
, SWT
.BORDER
| SWT
.SINGLE
);
916 GridData gd
= new GridData(SWT
.FILL
, SWT
.CENTER
, true, false);
918 elementNameText
.setLayoutData(gd
);
919 elementNameText
.addModifyListener(e
-> {
920 ElementNode
.this.inputElement
.setElementName(elementNameText
.getText().trim());
921 group
.setText(getName(ElementNode
.this.inputElement
));
923 elementNameText
.setText(inputElement
.getElementName());
924 elementNameText
.addModifyListener(updateListener
);
926 if (inputElement
.getParentElement() != null) {
927 previewLabel
= new Label(group
, SWT
.NULL
);
928 previewLabel
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
929 previewLabel
.setText(Messages
.CustomXmlParserInputWizardPage_preview
);
931 previewText
= new Text(group
, SWT
.BORDER
| SWT
.SINGLE
| SWT
.READ_ONLY
);
932 gd
= new GridData(SWT
.FILL
, SWT
.CENTER
, true, false);
934 previewText
.setLayoutData(gd
);
935 previewText
.setText(Messages
.CustomXmlParserInputWizardPage_noMatchingElement
);
936 previewText
.setBackground(COLOR_WIDGET_BACKGROUND
);
938 logEntryButton
= new Button(group
, SWT
.CHECK
);
939 logEntryButton
.setText(Messages
.CustomXmlParserInputWizardPage_logEntry
);
940 logEntryButton
.setSelection(inputElement
.isLogEntry());
941 logEntryButton
.addSelectionListener(new SelectionListener() {
943 public void widgetDefaultSelected(SelectionEvent e
) {
947 public void widgetSelected(SelectionEvent e
) {
948 CustomXmlInputElement parentElem
= ElementNode
.this.inputElement
.getParentElement();
949 while (parentElem
!= null) {
950 parentElem
.setLogEntry(false);
951 parentElem
= parentElem
.getParentElement();
955 logEntryButton
.addSelectionListener(updateListener
);
957 tagComposite
= new Composite(group
, SWT
.FILL
);
958 GridLayout tagLayout
= new GridLayout(4, false);
959 tagLayout
.marginWidth
= 0;
960 tagLayout
.marginHeight
= 0;
961 tagComposite
.setLayout(tagLayout
);
962 tagComposite
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
964 tagCombo
= new Combo(tagComposite
, SWT
.DROP_DOWN
| SWT
.READ_ONLY
);
965 tagCombo
.setItems(new String
[] {
966 Tag
.IGNORE
.toString(),
967 Tag
.TIMESTAMP
.toString(),
968 Tag
.EVENT_TYPE
.toString(),
969 Tag
.MESSAGE
.toString(),
970 Tag
.EXTRA_FIELD_NAME
.toString(),
971 Tag
.EXTRA_FIELD_VALUE
.toString(),
972 Tag
.OTHER
.toString() });
973 tagCombo
.setVisibleItemCount(tagCombo
.getItemCount());
974 tagCombo
.addSelectionListener(new SelectionListener() {
976 public void widgetDefaultSelected(SelectionEvent e
) {
980 public void widgetSelected(SelectionEvent e
) {
981 tagText
.removeModifyListener(updateListener
);
982 switch (tagCombo
.getSelectionIndex()) {
984 tagLabel
.setVisible(false);
985 tagText
.setVisible(false);
986 actionCombo
.setVisible(false);
988 case 1: // Time Stamp
989 tagLabel
.setText(Messages
.CustomXmlParserInputWizardPage_format
);
990 tagLabel
.setVisible(true);
991 tagText
.setVisible(true);
992 tagText
.addModifyListener(updateListener
);
993 actionCombo
.setVisible(true);
995 case 2: // Event type
996 tagLabel
.setVisible(false);
997 tagText
.setVisible(false);
998 actionCombo
.setVisible(true);
1001 tagLabel
.setVisible(false);
1002 tagText
.setVisible(false);
1003 actionCombo
.setVisible(true);
1005 case 4: // Field names
1006 tagLabel
.setVisible(false);
1007 tagText
.setVisible(false);
1008 actionCombo
.setVisible(false);
1010 case 5: // Field values
1011 tagLabel
.setVisible(false);
1012 tagText
.setVisible(false);
1013 actionCombo
.setVisible(true);
1016 tagLabel
.setText(Messages
.CustomXmlParserInputWizardPage_name
);
1017 tagLabel
.setVisible(true);
1018 if (tagText
.getText().trim().length() == 0) {
1019 tagText
.setText(elementNameText
.getText().trim());
1021 tagText
.setVisible(true);
1022 tagText
.addModifyListener(updateListener
);
1023 actionCombo
.setVisible(true);
1028 tagComposite
.layout();
1034 tagLabel
= new Label(tagComposite
, SWT
.NULL
);
1035 tagLabel
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
1037 tagText
= new Text(tagComposite
, SWT
.BORDER
| SWT
.SINGLE
);
1038 gd
= new GridData(SWT
.FILL
, SWT
.CENTER
, true, false);
1040 tagText
.setLayoutData(gd
);
1042 actionCombo
= new Combo(tagComposite
, SWT
.DROP_DOWN
| SWT
.READ_ONLY
);
1043 actionCombo
.setItems(new String
[] { Messages
.CustomXmlParserInputWizardPage_set
, Messages
.CustomXmlParserInputWizardPage_append
,
1044 Messages
.CustomXmlParserInputWizardPage_appendWith
});
1045 actionCombo
.select(inputElement
.getInputAction());
1046 actionCombo
.addSelectionListener(updateListener
);
1048 if (inputElement
.getInputTag().equals(Tag
.IGNORE
)) {
1050 tagLabel
.setVisible(false);
1051 tagText
.setVisible(false);
1052 actionCombo
.setVisible(false);
1053 } else if (inputElement
.getInputTag().equals(Tag
.TIMESTAMP
)) {
1055 tagLabel
.setText(Messages
.CustomXmlParserInputWizardPage_format
);
1056 tagText
.setText(inputElement
.getInputFormat());
1057 tagText
.addModifyListener(updateListener
);
1058 actionCombo
.setVisible(true);
1059 } else if (inputElement
.getInputTag().equals(Tag
.EVENT_TYPE
)) {
1061 tagLabel
.setVisible(false);
1062 tagText
.setVisible(false);
1063 actionCombo
.setVisible(true);
1064 } else if (inputElement
.getInputTag().equals(Tag
.MESSAGE
)) {
1066 tagLabel
.setVisible(false);
1067 tagText
.setVisible(false);
1068 actionCombo
.setVisible(true);
1069 } else if (inputElement
.getInputTag().equals(Tag
.EXTRA_FIELD_NAME
)) {
1071 tagLabel
.setVisible(false);
1072 tagText
.setVisible(false);
1073 actionCombo
.setVisible(false);
1074 } else if (inputElement
.getInputTag().equals(Tag
.EXTRA_FIELD_VALUE
)) {
1076 tagLabel
.setVisible(false);
1077 tagText
.setVisible(false);
1078 actionCombo
.setVisible(true);
1081 tagLabel
.setText(Messages
.CustomXmlParserInputWizardPage_name
);
1082 tagText
.setText(inputElement
.getInputName());
1083 tagText
.addModifyListener(updateListener
);
1084 actionCombo
.setVisible(true);
1087 eventTypeButton
= new Button(group
, SWT
.CHECK
);
1088 eventTypeButton
.setText(Messages
.CustomTxtParserInputWizardPage_eventType
);
1089 eventTypeButton
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
1090 eventTypeButton
.addSelectionListener(new SelectionAdapter() {
1092 public void widgetSelected(SelectionEvent e
) {
1093 if (eventTypeButton
.getSelection()) {
1094 eventTypeText
.setEnabled(true);
1096 eventTypeText
.setEnabled(false);
1100 eventTypeButton
.addSelectionListener(updateListener
);
1102 eventTypeText
= new Text(group
, SWT
.BORDER
| SWT
.SINGLE
);
1103 gd
= new GridData(SWT
.FILL
, SWT
.CENTER
, true, false);
1105 eventTypeText
.setLayoutData(gd
);
1106 if (inputElement
.getEventType() != null) {
1107 eventTypeText
.setText(inputElement
.getEventType());
1108 eventTypeButton
.setSelection(true);
1110 eventTypeText
.setEnabled(false);
1111 eventTypeButton
.setSelection(false);
1113 eventTypeText
.addModifyListener(updateListener
);
1116 if (inputElement
.getAttributes() != null) {
1117 for (CustomXmlInputAttribute inputAttribute
: inputElement
.getAttributes()) {
1118 Attribute attribute
= new Attribute(group
, this, inputAttribute
, attributes
.size() + 1);
1119 attributes
.add(attribute
);
1126 private void updatePreview() {
1127 Element element
= getPreviewElement(inputElement
);
1128 // no preview text for document element
1129 if (inputElement
.getParentElement() != null) {
1130 previewText
.setText(Messages
.CustomXmlParserInputWizardPage_noMatchingElement
);
1131 if (element
!= null) {
1132 previewText
.setText(CustomXmlTrace
.parseElement(element
, new StringBuffer()).toString());
1133 if (logEntryButton
.getSelection()) {
1134 if (!logEntryFound
) {
1135 logEntryFound
= true;
1138 // remove nested log entry
1139 logEntryButton
.setSelection(false);
1142 if (tagCombo
.getText().equals(Tag
.TIMESTAMP
.toString()) && logEntriesCount
<= 1) {
1143 String value
= previewText
.getText().trim();
1144 if (value
.length() != 0) {
1145 if (actionCombo
.getSelectionIndex() == CustomTraceDefinition
.ACTION_SET
) {
1146 timeStampValue
= value
;
1147 timeStampFormat
= tagText
.getText().trim();
1148 } else if (actionCombo
.getSelectionIndex() == CustomTraceDefinition
.ACTION_APPEND
) {
1149 if (timeStampValue
!= null) {
1150 timeStampValue
+= value
;
1151 timeStampFormat
+= tagText
.getText().trim();
1153 timeStampValue
= value
;
1154 timeStampFormat
= tagText
.getText().trim();
1156 } else if (actionCombo
.getSelectionIndex() == CustomTraceDefinition
.ACTION_APPEND_WITH_SEPARATOR
) {
1157 if (timeStampValue
!= null) {
1158 timeStampValue
+= CustomTraceDefinition
.SEPARATOR
+ value
;
1159 timeStampFormat
+= CustomTraceDefinition
.SEPARATOR
+ tagText
.getText().trim();
1161 timeStampValue
= value
;
1162 timeStampFormat
= tagText
.getText().trim();
1169 for (Attribute attribute
: attributes
) {
1170 if (element
!= null) {
1171 String value
= element
.getAttribute(attribute
.attributeNameText
.getText().trim());
1172 if (value
.length() != 0) {
1173 attribute
.previewText
.setText(value
);
1174 if (attribute
.tagCombo
.getText().equals(Tag
.TIMESTAMP
.toString()) && logEntriesCount
<= 1) {
1175 if (attribute
.actionCombo
.getSelectionIndex() == CustomTraceDefinition
.ACTION_SET
) {
1176 timeStampValue
= value
;
1177 timeStampFormat
= attribute
.tagText
.getText().trim();
1178 } else if (attribute
.actionCombo
.getSelectionIndex() == CustomTraceDefinition
.ACTION_APPEND
) {
1179 if (timeStampValue
!= null) {
1180 timeStampValue
+= value
;
1181 timeStampFormat
+= attribute
.tagText
.getText().trim();
1183 timeStampValue
= value
;
1184 timeStampFormat
= attribute
.tagText
.getText().trim();
1186 } else if (attribute
.actionCombo
.getSelectionIndex() == CustomTraceDefinition
.ACTION_APPEND_WITH_SEPARATOR
) {
1187 if (timeStampValue
!= null) {
1188 timeStampValue
+= " | " + value
; //$NON-NLS-1$
1189 timeStampFormat
+= " | " + attribute
.tagText
.getText().trim(); //$NON-NLS-1$
1191 timeStampValue
= value
;
1192 timeStampFormat
= attribute
.tagText
.getText().trim();
1197 attribute
.previewText
.setText(Messages
.CustomXmlParserInputWizardPage_noMatchingAttribute
);
1200 attribute
.previewText
.setText(Messages
.CustomXmlParserInputWizardPage_noMatchingElement
);
1203 for (ElementNode child
: childElements
) {
1204 child
.updatePreview();
1206 if (logEntryButton
!= null && logEntryButton
.getSelection()) {
1207 logEntryFound
= false;
1211 private void createAddButton() {
1212 fillerLabel
= new Label(group
, SWT
.NONE
);
1214 addAttributeComposite
= new Composite(group
, SWT
.NONE
);
1215 addAttributeComposite
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
1216 GridLayout addAttributeLayout
= new GridLayout(2, false);
1217 addAttributeLayout
.marginHeight
= 0;
1218 addAttributeLayout
.marginWidth
= 0;
1219 addAttributeComposite
.setLayout(addAttributeLayout
);
1221 addAttributeButton
= new Button(addAttributeComposite
, SWT
.PUSH
);
1222 addAttributeButton
.setImage(ADD_IMAGE
);
1223 addAttributeButton
.setToolTipText(Messages
.CustomXmlParserInputWizardPage_addAttribute
);
1224 addAttributeButton
.addSelectionListener(new SelectionAdapter() {
1226 public void widgetSelected(SelectionEvent e
) {
1228 String attributeName
= getAttributeNameSuggestion(inputElement
);
1229 CustomXmlInputAttribute inputAttribute
= new CustomXmlInputAttribute(attributeName
, Tag
.OTHER
, attributeName
, 0, ""); //$NON-NLS-1$
1230 attributes
.add(new Attribute(group
, ElementNode
.this, inputAttribute
, attributes
.size() + 1));
1232 elementContainer
.layout();
1233 elementScrolledComposite
.setMinSize(elementContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).x
,
1234 elementContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).y
- 1);
1235 group
.getParent().layout();
1241 addAttributeLabel
= new Label(addAttributeComposite
, SWT
.NULL
);
1242 addAttributeLabel
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
1243 addAttributeLabel
.setText(Messages
.CustomXmlParserInputWizardPage_newAttibute
);
1246 private void removeAddButton() {
1247 fillerLabel
.dispose();
1248 addAttributeComposite
.dispose();
1251 private void removeAttribute(int attributeNumber
) {
1252 int nb
= attributeNumber
;
1253 if (--nb
< attributes
.size()) {
1254 attributes
.remove(nb
).dispose();
1255 for (int i
= nb
; i
< attributes
.size(); i
++) {
1256 attributes
.get(i
).setAttributeNumber(i
+ 1);
1258 elementContainer
.layout();
1259 elementScrolledComposite
.setMinSize(elementContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).x
,
1260 elementContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).y
- 1);
1261 group
.getParent().layout();
1265 private void dispose() {
1269 private void extractInputs() {
1270 inputElement
.setElementName(elementNameText
.getText().trim());
1271 if (inputElement
.getParentElement() != null) {
1272 inputElement
.setLogEntry(logEntryButton
.getSelection());
1273 inputElement
.setEventType(eventTypeButton
.getSelection() ? eventTypeText
.getText().trim() : null);
1274 Tag inputTag
= Tag
.fromLabel(tagCombo
.getText());
1275 inputElement
.setInputTag(inputTag
);
1276 if (inputTag
.equals(Tag
.OTHER
)) {
1277 inputElement
.setInputName(tagText
.getText().trim());
1279 inputElement
.setInputName(inputTag
.toString());
1280 if (inputTag
.equals(Tag
.TIMESTAMP
)) {
1281 inputElement
.setInputFormat(tagText
.getText().trim());
1284 inputElement
.setInputAction(actionCombo
.getSelectionIndex());
1286 inputElement
.setAttributes(new ArrayList
<CustomXmlInputAttribute
>(attributes
.size()));
1287 for (int i
= 0; i
< attributes
.size(); i
++) {
1288 String inputName
= null;
1289 String inputFormat
= null;
1290 Attribute attribute
= attributes
.get(i
);
1291 String attributeName
= attribute
.attributeNameText
.getText().trim();
1292 Tag inputTag
= Tag
.fromLabel(attribute
.tagCombo
.getText());
1293 if (inputTag
.equals(Tag
.OTHER
)) {
1294 inputName
= attribute
.tagText
.getText().trim();
1296 inputName
= inputTag
.toString();
1297 if (inputTag
.equals(Tag
.TIMESTAMP
)) {
1298 inputFormat
= attribute
.tagText
.getText().trim();
1301 int inputAction
= attribute
.actionCombo
.getSelectionIndex();
1302 inputElement
.addAttribute(new CustomXmlInputAttribute(attributeName
, inputTag
, inputName
, inputAction
, inputFormat
));
1307 private class Attribute
{
1308 private ElementNode element
;
1309 private int attributeNumber
;
1311 // children of parent (must be disposed)
1312 private Composite labelComposite
;
1313 private Composite attributeComposite
;
1314 private Label filler
;
1315 private Composite tagComposite
;
1317 // children of labelComposite
1318 private Label attributeLabel
;
1320 // children of attributeComposite
1321 private Text attributeNameText
;
1322 private Text previewText
;
1324 // children of tagComposite
1325 private Combo tagCombo
;
1326 private Label tagLabel
;
1327 private Text tagText
;
1328 private Combo actionCombo
;
1330 public Attribute(Composite parent
, ElementNode element
, CustomXmlInputAttribute inputAttribute
, int attributeNumber
) {
1331 this.element
= element
;
1332 this.attributeNumber
= attributeNumber
;
1334 labelComposite
= new Composite(parent
, SWT
.FILL
);
1335 GridLayout labelLayout
= new GridLayout(2, false);
1336 labelLayout
.marginWidth
= 0;
1337 labelLayout
.marginHeight
= 0;
1338 labelComposite
.setLayout(labelLayout
);
1339 labelComposite
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
1341 Button deleteButton
= new Button(labelComposite
, SWT
.PUSH
);
1342 deleteButton
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
1343 deleteButton
.setImage(DELETE_IMAGE
);
1344 deleteButton
.setToolTipText(Messages
.CustomXmlParserInputWizardPage_removeAttribute
);
1345 deleteButton
.addSelectionListener(new SelectionAdapter() {
1347 public void widgetSelected(SelectionEvent e
) {
1348 Attribute
.this.element
.removeAttribute(Attribute
.this.attributeNumber
);
1354 attributeLabel
= new Label(labelComposite
, SWT
.NULL
);
1355 attributeLabel
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
1356 attributeLabel
.setText(Messages
.CustomXmlParserInputWizardPage_attibute
);
1358 attributeComposite
= new Composite(parent
, SWT
.FILL
);
1359 GridLayout attributeLayout
= new GridLayout(4, false);
1360 attributeLayout
.marginWidth
= 0;
1361 attributeLayout
.marginHeight
= 0;
1362 attributeComposite
.setLayout(attributeLayout
);
1363 attributeComposite
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
1365 Label nameLabel
= new Label(attributeComposite
, SWT
.NONE
);
1366 nameLabel
.setText(Messages
.CustomXmlParserInputWizardPage_name
);
1368 attributeNameText
= new Text(attributeComposite
, SWT
.BORDER
| SWT
.SINGLE
);
1369 attributeNameText
.setLayoutData(new GridData(120, SWT
.DEFAULT
));
1370 attributeNameText
.setText(inputAttribute
.getAttributeName());
1371 attributeNameText
.addModifyListener(updateListener
);
1373 Label previewLabel
= new Label(attributeComposite
, SWT
.NONE
);
1374 previewLabel
.setText(Messages
.CustomXmlParserInputWizardPage_preview
);
1376 previewText
= new Text(attributeComposite
, SWT
.BORDER
| SWT
.SINGLE
| SWT
.READ_ONLY
);
1377 GridData gd
= new GridData(SWT
.FILL
, SWT
.CENTER
, true, false);
1379 previewText
.setLayoutData(gd
);
1380 previewText
.setText(Messages
.CustomXmlParserInputWizardPage_noMatch
);
1381 previewText
.setBackground(COLOR_WIDGET_BACKGROUND
);
1383 filler
= new Label(parent
, SWT
.NULL
);
1385 tagComposite
= new Composite(parent
, SWT
.FILL
);
1386 GridLayout tagLayout
= new GridLayout(4, false);
1387 tagLayout
.marginWidth
= 0;
1388 tagLayout
.marginHeight
= 0;
1389 tagComposite
.setLayout(tagLayout
);
1390 tagComposite
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
1392 tagCombo
= new Combo(tagComposite
, SWT
.DROP_DOWN
| SWT
.READ_ONLY
);
1393 tagCombo
.setItems(new String
[] {
1394 Tag
.TIMESTAMP
.toString(),
1395 Tag
.EVENT_TYPE
.toString(),
1396 Tag
.MESSAGE
.toString(),
1397 Tag
.EXTRA_FIELD_NAME
.toString(),
1398 Tag
.EXTRA_FIELD_VALUE
.toString(),
1399 Tag
.OTHER
.toString() });
1400 tagCombo
.select(3); // Other
1401 tagCombo
.addSelectionListener(new SelectionListener() {
1403 public void widgetDefaultSelected(SelectionEvent e
) {
1407 public void widgetSelected(SelectionEvent e
) {
1408 tagText
.removeModifyListener(updateListener
);
1409 switch (tagCombo
.getSelectionIndex()) {
1410 case 0: // Time Stamp
1411 tagLabel
.setText(Messages
.CustomXmlParserInputWizardPage_format
);
1412 tagLabel
.setVisible(true);
1413 tagText
.setVisible(true);
1414 tagText
.addModifyListener(updateListener
);
1415 actionCombo
.setVisible(true);
1417 case 1: // Event type
1418 tagLabel
.setVisible(false);
1419 tagText
.setVisible(false);
1420 actionCombo
.setVisible(true);
1423 tagLabel
.setVisible(false);
1424 tagText
.setVisible(false);
1425 actionCombo
.setVisible(true);
1427 case 3: // Field names
1428 tagLabel
.setVisible(false);
1429 tagText
.setVisible(false);
1430 actionCombo
.setVisible(false);
1432 case 4: // Field values
1433 tagLabel
.setVisible(false);
1434 tagText
.setVisible(false);
1435 actionCombo
.setVisible(true);
1438 tagLabel
.setText(Messages
.CustomXmlParserInputWizardPage_name
);
1439 tagLabel
.setVisible(true);
1440 if (tagText
.getText().trim().length() == 0) {
1441 tagText
.setText(attributeNameText
.getText().trim());
1443 tagText
.setVisible(true);
1444 tagText
.addModifyListener(updateListener
);
1445 actionCombo
.setVisible(true);
1450 tagComposite
.layout();
1456 tagLabel
= new Label(tagComposite
, SWT
.NULL
);
1457 tagLabel
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
1459 tagText
= new Text(tagComposite
, SWT
.BORDER
| SWT
.SINGLE
);
1460 gd
= new GridData(SWT
.FILL
, SWT
.CENTER
, true, false);
1462 tagText
.setLayoutData(gd
);
1463 tagText
.setText(attributeNameText
.getText());
1465 actionCombo
= new Combo(tagComposite
, SWT
.DROP_DOWN
| SWT
.READ_ONLY
);
1466 actionCombo
.setItems(new String
[] { Messages
.CustomXmlParserInputWizardPage_set
, Messages
.CustomXmlParserInputWizardPage_append
,
1467 Messages
.CustomXmlParserInputWizardPage_appendWith
});
1468 actionCombo
.select(inputAttribute
.getInputAction());
1469 actionCombo
.addSelectionListener(updateListener
);
1471 if (inputAttribute
.getInputTag().equals(Tag
.TIMESTAMP
)) {
1473 tagLabel
.setText(Messages
.CustomXmlParserInputWizardPage_format
);
1474 tagText
.setText(inputAttribute
.getInputFormat());
1475 tagText
.addModifyListener(updateListener
);
1476 actionCombo
.setVisible(true);
1477 } else if (inputAttribute
.getInputTag().equals(Tag
.EVENT_TYPE
)) {
1479 tagLabel
.setVisible(false);
1480 tagText
.setVisible(false);
1481 actionCombo
.setVisible(true);
1482 } else if (inputAttribute
.getInputTag().equals(Tag
.MESSAGE
)) {
1484 tagLabel
.setVisible(false);
1485 tagText
.setVisible(false);
1486 actionCombo
.setVisible(true);
1487 } else if (inputAttribute
.getInputTag().equals(Tag
.EXTRA_FIELD_NAME
)) {
1489 tagLabel
.setVisible(false);
1490 tagText
.setVisible(false);
1491 actionCombo
.setVisible(false);
1492 } else if (inputAttribute
.getInputTag().equals(Tag
.EXTRA_FIELD_VALUE
)) {
1494 tagLabel
.setVisible(false);
1495 tagText
.setVisible(false);
1496 actionCombo
.setVisible(true);
1499 tagLabel
.setText(Messages
.CustomXmlParserInputWizardPage_name
);
1500 tagText
.setText(inputAttribute
.getInputName());
1501 tagText
.addModifyListener(updateListener
);
1502 actionCombo
.setVisible(true);
1506 private void dispose() {
1507 labelComposite
.dispose();
1508 attributeComposite
.dispose();
1510 tagComposite
.dispose();
1513 private void setAttributeNumber(int attributeNumber
) {
1514 this.attributeNumber
= attributeNumber
;
1515 labelComposite
.layout();
1519 private Element
getPreviewElement(CustomXmlInputElement inputElement
) {
1520 CustomXmlInputElement currentElement
= inputElement
;
1521 Element element
= documentElement
;
1522 if (element
!= null) {
1523 if (!documentElement
.getNodeName().equals(definition
.rootInputElement
.getElementName())) {
1526 ArrayList
<String
> elementNames
= new ArrayList
<>();
1527 while (currentElement
!= null) {
1528 elementNames
.add(currentElement
.getElementName());
1529 currentElement
= currentElement
.getParentElement();
1531 for (int i
= elementNames
.size() - 1; --i
>= 0;) {
1532 NodeList childList
= element
.getChildNodes();
1534 for (int j
= 0; j
< childList
.getLength(); j
++) {
1535 Node child
= childList
.item(j
);
1536 if (child
instanceof Element
&& child
.getNodeName().equals(elementNames
.get(i
))) {
1537 element
= (Element
) child
;
1541 if (element
== null) {
1545 if (element
!= null) {
1552 private String
getChildNameSuggestion(CustomXmlInputElement inputElement
) {
1553 if (inputElement
== null) {
1554 if (documentElement
!= null) {
1555 return documentElement
.getNodeName();
1558 Element element
= getPreviewElement(inputElement
);
1559 if (element
!= null) {
1560 NodeList childNodes
= element
.getChildNodes();
1561 for (int i
= 0; i
< childNodes
.getLength(); i
++) {
1562 Node node
= childNodes
.item(i
);
1563 if (node
instanceof Element
) {
1564 boolean unused
= true;
1565 if (inputElement
.getChildElements() != null) {
1566 for (CustomXmlInputElement child
: inputElement
.getChildElements()) {
1567 if (child
.getElementName().equals(node
.getNodeName())) {
1574 return node
.getNodeName();
1580 return ""; //$NON-NLS-1$
1583 private String
getAttributeNameSuggestion(CustomXmlInputElement inputElement
) {
1584 Element element
= getPreviewElement(inputElement
);
1585 if (element
!= null) {
1586 NamedNodeMap attributeMap
= element
.getAttributes();
1587 for (int i
= 0; i
< attributeMap
.getLength(); i
++) {
1588 Node node
= attributeMap
.item(i
);
1589 boolean unused
= true;
1590 if (inputElement
.getAttributes() != null) {
1591 for (CustomXmlInputAttribute attribute
: inputElement
.getAttributes()) {
1592 if (attribute
.getAttributeName().equals(node
.getNodeName())) {
1599 return node
.getNodeName();
1603 return ""; //$NON-NLS-1$
1606 private void validate() {
1607 definition
.categoryName
= categoryText
.getText().trim();
1608 definition
.definitionName
= logtypeText
.getText().trim();
1609 definition
.timeStampOutputFormat
= timeStampOutputFormatText
.getText().trim();
1611 if (selectedElement
!= null) {
1612 selectedElement
.extractInputs();
1613 treeViewer
.refresh();
1616 List
<String
> errors
= new ArrayList
<>();
1618 if (definition
.categoryName
.length() == 0) {
1619 errors
.add(Messages
.CustomXmlParserInputWizardPage_emptyCategoryError
);
1620 categoryText
.setBackground(COLOR_LIGHT_RED
);
1621 } else if (definition
.definitionName
.length() == 0) {
1622 errors
.add(Messages
.CustomXmlParserInputWizardPage_emptyLogTypeError
);
1623 logtypeText
.setBackground(COLOR_LIGHT_RED
);
1625 categoryText
.setBackground(COLOR_TEXT_BACKGROUND
);
1626 logtypeText
.setBackground(COLOR_TEXT_BACKGROUND
);
1627 if (definition
.categoryName
.indexOf(':') != -1) {
1628 errors
.add(Messages
.CustomXmlParserInputWizardPage_invalidCategoryError
);
1629 categoryText
.setBackground(COLOR_LIGHT_RED
);
1631 if (definition
.definitionName
.indexOf(':') != -1) {
1632 errors
.add(Messages
.CustomXmlParserInputWizardPage_invalidLogTypeError
);
1633 logtypeText
.setBackground(COLOR_LIGHT_RED
);
1635 for (TraceTypeHelper helper
: TmfTraceType
.getTraceTypeHelpers()) {
1636 if (definition
.categoryName
.equals(helper
.getCategoryName()) &&
1637 definition
.definitionName
.equals(helper
.getName()) &&
1638 (editDefinitionName
== null || !editDefinitionName
.equals(definition
.definitionName
)) &&
1639 (editCategoryName
== null || !editCategoryName
.equals(definition
.categoryName
))) {
1640 errors
.add(Messages
.CustomXmlParserInputWizardPage_duplicatelogTypeError
);
1641 logtypeText
.setBackground(COLOR_LIGHT_RED
);
1647 if (definition
.rootInputElement
== null) {
1648 errors
.add(Messages
.CustomXmlParserInputWizardPage_noDocumentError
);
1651 if (definition
.rootInputElement
!= null) {
1652 logEntryFound
= false;
1653 timeStampFound
= false;
1655 errors
.addAll(validateElement(definition
.rootInputElement
));
1657 if ((definition
.rootInputElement
.getAttributes() != null && definition
.rootInputElement
.getAttributes().size() != 0)
1658 || (definition
.rootInputElement
.getChildElements() != null && definition
.rootInputElement
.getChildElements().size() != 0)
1659 || errors
.size() == 0) {
1660 if (!logEntryFound
) {
1661 errors
.add(Messages
.CustomXmlParserInputWizardPage_missingLogEntryError
);
1664 if (timeStampFound
&& !definition
.timeStampOutputFormat
.isEmpty()) {
1666 new TmfTimestampFormat(timeStampOutputFormatText
.getText().trim());
1667 timeStampOutputFormatText
.setBackground(COLOR_TEXT_BACKGROUND
);
1668 } catch (IllegalArgumentException e
) {
1669 errors
.add(Messages
.CustomXmlParserInputWizardPage_elementInvalidTimestampFmtError
);
1670 timeStampOutputFormatText
.setBackground(COLOR_LIGHT_RED
);
1673 timeStampOutputFormatText
.setBackground(COLOR_TEXT_BACKGROUND
);
1674 if (!timeStampFound
) {
1675 timeStampPreviewText
.setText(Messages
.CustomXmlParserInputWizardPage_noTimestampElementOrAttribute
);
1680 timeStampPreviewText
.setText(Messages
.CustomXmlParserInputWizardPage_noTimestampElementOrAttribute
);
1683 if (errors
.size() == 0) {
1684 setDescription(defaultDescription
);
1685 setPageComplete(true);
1687 setDescription(Joiner
.on(' ').join(errors
));
1688 setPageComplete(false);
1693 * Clean up the specified XML element.
1695 * @param inputElement
1696 * The element to clean up
1697 * @return The validated element
1699 public List
<String
> validateElement(CustomXmlInputElement inputElement
) {
1700 List
<String
> errors
= new ArrayList
<>();
1701 ElementNode elementNode
= null;
1702 if (selectedElement
!= null && selectedElement
.inputElement
.equals(inputElement
)) {
1703 elementNode
= selectedElement
;
1705 if (inputElement
== definition
.rootInputElement
) {
1706 if (inputElement
.getElementName().length() == 0) {
1707 errors
.add(Messages
.CustomXmlParserInputWizardPage_missingDocumentElementError
);
1708 if (elementNode
!= null) {
1709 elementNode
.elementNameText
.setBackground(COLOR_LIGHT_RED
);
1712 if (elementNode
!= null) {
1713 elementNode
.elementNameText
.setBackground(COLOR_TEXT_BACKGROUND
);
1717 if (inputElement
!= definition
.rootInputElement
) {
1718 if (inputElement
.isLogEntry()) {
1719 logEntryFound
= true;
1721 if (inputElement
.getInputTag().equals(Tag
.TIMESTAMP
)) {
1722 timeStampFound
= true;
1723 if (inputElement
.getInputFormat().length() == 0) {
1724 errors
.add(NLS
.bind(Messages
.CustomXmlParserInputWizardPage_elementMissingTimestampFmtError
, getName(inputElement
)));
1725 if (elementNode
!= null) {
1726 elementNode
.tagText
.setBackground(COLOR_LIGHT_RED
);
1730 new TmfTimestampFormat(inputElement
.getInputFormat());
1731 if (elementNode
!= null) {
1732 elementNode
.tagText
.setBackground(COLOR_TEXT_BACKGROUND
);
1734 } catch (IllegalArgumentException e
) {
1735 errors
.add(NLS
.bind(Messages
.CustomXmlParserInputWizardPage_elementInvalidTimestampFmtError
, getName(inputElement
)));
1736 if (elementNode
!= null) {
1737 elementNode
.tagText
.setBackground(COLOR_LIGHT_RED
);
1741 } else if (inputElement
.getInputName().length() == 0) {
1742 errors
.add(NLS
.bind(Messages
.CustomXmlParserInputWizardPage_elementMissingInputNameError
, getName(inputElement
)));
1743 if (elementNode
!= null) {
1744 elementNode
.tagText
.setBackground(COLOR_LIGHT_RED
);
1746 } else if (inputElement
.getInputTag().equals(Tag
.OTHER
) && Tag
.fromLabel(inputElement
.getInputName()) != null) {
1747 errors
.add(NLS
.bind(Messages
.CustomXmlParserInputWizardPage_elementReservedInputNameError
, getName(inputElement
)));
1748 if (elementNode
!= null) {
1749 elementNode
.tagText
.setBackground(COLOR_LIGHT_RED
);
1752 if (elementNode
!= null) {
1753 elementNode
.tagText
.setBackground(COLOR_TEXT_BACKGROUND
);
1756 if (inputElement
.getEventType() != null && inputElement
.getEventType().trim().isEmpty()) {
1757 errors
.add(NLS
.bind(Messages
.CustomXmlParserInputWizardPage_emptyEventTypeError
, getName(inputElement
)));
1758 if (elementNode
!= null) {
1759 elementNode
.eventTypeText
.setBackground(COLOR_LIGHT_RED
);
1762 if (elementNode
!= null) {
1763 elementNode
.eventTypeText
.setBackground(COLOR_TEXT_BACKGROUND
);
1767 if (inputElement
.getAttributes() != null) {
1768 if (elementNode
!= null) {
1769 for (Attribute attribute
: elementNode
.attributes
) {
1770 attribute
.attributeNameText
.setBackground(COLOR_TEXT_BACKGROUND
);
1773 for (int i
= 0; i
< inputElement
.getAttributes().size(); i
++) {
1774 CustomXmlInputAttribute attribute
= inputElement
.getAttributes().get(i
);
1775 boolean duplicate
= false;
1776 for (int j
= i
+ 1; j
< inputElement
.getAttributes().size(); j
++) {
1777 CustomXmlInputAttribute otherAttribute
= inputElement
.getAttributes().get(j
);
1778 if (otherAttribute
.getAttributeName().equals(attribute
.getAttributeName())) {
1780 if (elementNode
!= null) {
1781 elementNode
.attributes
.get(j
).attributeNameText
.setBackground(COLOR_LIGHT_RED
);
1785 if (attribute
.getAttributeName().length() == 0) {
1786 errors
.add(NLS
.bind(Messages
.CustomXmlParserInputWizardPage_attributeMissingNameError
, getName(inputElement
)));
1787 if (elementNode
!= null) {
1788 elementNode
.attributes
.get(i
).attributeNameText
.setBackground(COLOR_LIGHT_RED
);
1790 } else if (duplicate
) {
1791 errors
.add(NLS
.bind(Messages
.CustomXmlParserInputWizardPage_attributeDuplicateNameError
, getName(attribute
, inputElement
)));
1792 if (elementNode
!= null) {
1793 elementNode
.attributes
.get(i
).attributeNameText
.setBackground(COLOR_LIGHT_RED
);
1796 if (attribute
.getInputTag().equals(Tag
.TIMESTAMP
)) {
1797 timeStampFound
= true;
1798 if (attribute
.getInputFormat().length() == 0) {
1799 errors
.add(NLS
.bind(Messages
.CustomXmlParserInputWizardPage_attributeMissingTimestampFmtError
, getName(attribute
, inputElement
)));
1800 if (elementNode
!= null) {
1801 elementNode
.attributes
.get(i
).tagText
.setBackground(COLOR_LIGHT_RED
);
1805 new TmfTimestampFormat(attribute
.getInputFormat());
1806 if (elementNode
!= null) {
1807 elementNode
.attributes
.get(i
).tagText
.setBackground(COLOR_TEXT_BACKGROUND
);
1809 } catch (IllegalArgumentException e
) {
1810 errors
.add(NLS
.bind(Messages
.CustomXmlParserInputWizardPage_attributeInvalidTimestampFmtError
, getName(attribute
, inputElement
)));
1811 if (elementNode
!= null) {
1812 elementNode
.attributes
.get(i
).tagText
.setBackground(COLOR_LIGHT_RED
);
1816 } else if (attribute
.getInputName().length() == 0) {
1817 errors
.add(NLS
.bind(Messages
.CustomXmlParserInputWizardPage_attributeMissingInputNameError
, getName(attribute
, inputElement
)));
1818 if (elementNode
!= null) {
1819 elementNode
.attributes
.get(i
).tagText
.setBackground(COLOR_LIGHT_RED
);
1821 } else if (attribute
.getInputTag().equals(Tag
.OTHER
) && Tag
.fromLabel(attribute
.getInputName()) != null) {
1822 errors
.add(NLS
.bind(Messages
.CustomXmlParserInputWizardPage_attributeReservedInputNameError
, getName(attribute
, inputElement
)));
1823 if (elementNode
!= null) {
1824 elementNode
.attributes
.get(i
).tagText
.setBackground(COLOR_LIGHT_RED
);
1827 if (elementNode
!= null) {
1828 elementNode
.attributes
.get(i
).tagText
.setBackground(COLOR_TEXT_BACKGROUND
);
1833 if (inputElement
.getChildElements() != null) {
1834 for (CustomXmlInputElement child
: inputElement
.getChildElements()) {
1835 ElementNode childElementNode
= null;
1836 if (selectedElement
!= null && selectedElement
.inputElement
.equals(child
)) {
1837 childElementNode
= selectedElement
;
1839 if (childElementNode
!= null) {
1840 childElementNode
.elementNameText
.setBackground(COLOR_TEXT_BACKGROUND
);
1843 for (int i
= 0; i
< inputElement
.getChildElements().size(); i
++) {
1844 CustomXmlInputElement child
= inputElement
.getChildElements().get(i
);
1845 ElementNode childElementNode
= null;
1846 if (selectedElement
!= null && selectedElement
.inputElement
.equals(child
)) {
1847 childElementNode
= selectedElement
;
1849 if (child
.getElementName().length() == 0) {
1850 errors
.add(NLS
.bind(Messages
.CustomXmlParserInputWizardPage_elementMissingNameError
, getName(child
)));
1851 if (childElementNode
!= null) {
1852 childElementNode
.elementNameText
.setBackground(COLOR_LIGHT_RED
);
1855 boolean duplicate
= false;
1856 for (int j
= i
+ 1; j
< inputElement
.getChildElements().size(); j
++) {
1857 CustomXmlInputElement otherChild
= inputElement
.getChildElements().get(j
);
1858 if (otherChild
.getElementName().equals(child
.getElementName())) {
1860 ElementNode otherChildElementNode
= null;
1861 if (selectedElement
!= null && selectedElement
.inputElement
.equals(otherChild
)) {
1862 otherChildElementNode
= selectedElement
;
1864 if (otherChildElementNode
!= null) {
1865 otherChildElementNode
.elementNameText
.setBackground(COLOR_LIGHT_RED
);
1870 errors
.add(NLS
.bind(Messages
.CustomXmlParserInputWizardPage_elementDuplicateNameError
, getName(child
)));
1871 if (childElementNode
!= null) {
1872 childElementNode
.elementNameText
.setBackground(COLOR_LIGHT_RED
);
1877 errors
.addAll(validateElement(child
));
1884 * Get the trace definition.
1886 * @return The trace definition
1888 public CustomXmlTraceDefinition
getDefinition() {
1893 * Get the raw text input.
1895 * @return The raw text input.
1897 public char[] getInputText() {
1898 return inputText
.getText().toCharArray();