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
.OTHER
.toString() });
971 tagCombo
.setVisibleItemCount(tagCombo
.getItemCount());
972 tagCombo
.addSelectionListener(new SelectionListener() {
974 public void widgetDefaultSelected(SelectionEvent e
) {
978 public void widgetSelected(SelectionEvent e
) {
979 tagText
.removeModifyListener(updateListener
);
980 switch (tagCombo
.getSelectionIndex()) {
982 tagLabel
.setVisible(false);
983 tagText
.setVisible(false);
984 actionCombo
.setVisible(false);
986 case 1: // Time Stamp
987 tagLabel
.setText(Messages
.CustomXmlParserInputWizardPage_format
);
988 tagLabel
.setVisible(true);
989 tagText
.setVisible(true);
990 tagText
.addModifyListener(updateListener
);
991 actionCombo
.setVisible(true);
993 case 2: // Event type
994 tagLabel
.setVisible(false);
995 tagText
.setVisible(false);
996 actionCombo
.setVisible(true);
999 tagLabel
.setVisible(false);
1000 tagText
.setVisible(false);
1001 actionCombo
.setVisible(true);
1004 tagLabel
.setText(Messages
.CustomXmlParserInputWizardPage_name
);
1005 tagLabel
.setVisible(true);
1006 if (tagText
.getText().trim().length() == 0) {
1007 tagText
.setText(elementNameText
.getText().trim());
1009 tagText
.setVisible(true);
1010 tagText
.addModifyListener(updateListener
);
1011 actionCombo
.setVisible(true);
1016 tagComposite
.layout();
1022 tagLabel
= new Label(tagComposite
, SWT
.NULL
);
1023 tagLabel
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
1025 tagText
= new Text(tagComposite
, SWT
.BORDER
| SWT
.SINGLE
);
1026 gd
= new GridData(SWT
.FILL
, SWT
.CENTER
, true, false);
1028 tagText
.setLayoutData(gd
);
1030 actionCombo
= new Combo(tagComposite
, SWT
.DROP_DOWN
| SWT
.READ_ONLY
);
1031 actionCombo
.setItems(new String
[] { Messages
.CustomXmlParserInputWizardPage_set
, Messages
.CustomXmlParserInputWizardPage_append
,
1032 Messages
.CustomXmlParserInputWizardPage_appendWith
});
1033 actionCombo
.select(inputElement
.getInputAction());
1034 actionCombo
.addSelectionListener(updateListener
);
1036 if (inputElement
.getInputTag().equals(Tag
.IGNORE
)) {
1038 tagLabel
.setVisible(false);
1039 tagText
.setVisible(false);
1040 actionCombo
.setVisible(false);
1041 } else if (inputElement
.getInputTag().equals(Tag
.TIMESTAMP
)) {
1043 tagLabel
.setText(Messages
.CustomXmlParserInputWizardPage_format
);
1044 tagText
.setText(inputElement
.getInputFormat());
1045 tagText
.addModifyListener(updateListener
);
1046 } else if (inputElement
.getInputTag().equals(Tag
.EVENT_TYPE
)) {
1048 tagLabel
.setVisible(false);
1049 tagText
.setVisible(false);
1050 } else if (inputElement
.getInputTag().equals(Tag
.MESSAGE
)) {
1052 tagLabel
.setVisible(false);
1053 tagText
.setVisible(false);
1056 tagLabel
.setText(Messages
.CustomXmlParserInputWizardPage_name
);
1057 tagText
.setText(inputElement
.getInputName());
1058 tagText
.addModifyListener(updateListener
);
1061 eventTypeButton
= new Button(group
, SWT
.CHECK
);
1062 eventTypeButton
.setText(Messages
.CustomTxtParserInputWizardPage_eventType
);
1063 eventTypeButton
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
1064 eventTypeButton
.addSelectionListener(new SelectionAdapter() {
1066 public void widgetSelected(SelectionEvent e
) {
1067 if (eventTypeButton
.getSelection()) {
1068 eventTypeText
.setEnabled(true);
1070 eventTypeText
.setEnabled(false);
1074 eventTypeButton
.addSelectionListener(updateListener
);
1076 eventTypeText
= new Text(group
, SWT
.BORDER
| SWT
.SINGLE
);
1077 gd
= new GridData(SWT
.FILL
, SWT
.CENTER
, true, false);
1079 eventTypeText
.setLayoutData(gd
);
1080 if (inputElement
.getEventType() != null) {
1081 eventTypeText
.setText(inputElement
.getEventType());
1082 eventTypeButton
.setSelection(true);
1084 eventTypeText
.setEnabled(false);
1085 eventTypeButton
.setSelection(false);
1087 eventTypeText
.addModifyListener(updateListener
);
1090 if (inputElement
.getAttributes() != null) {
1091 for (CustomXmlInputAttribute inputAttribute
: inputElement
.getAttributes()) {
1092 Attribute attribute
= new Attribute(group
, this, inputAttribute
, attributes
.size() + 1);
1093 attributes
.add(attribute
);
1100 private void updatePreview() {
1101 Element element
= getPreviewElement(inputElement
);
1102 // no preview text for document element
1103 if (inputElement
.getParentElement() != null) {
1104 previewText
.setText(Messages
.CustomXmlParserInputWizardPage_noMatchingElement
);
1105 if (element
!= null) {
1106 previewText
.setText(CustomXmlTrace
.parseElement(element
, new StringBuffer()).toString());
1107 if (logEntryButton
.getSelection()) {
1108 if (!logEntryFound
) {
1109 logEntryFound
= true;
1112 // remove nested log entry
1113 logEntryButton
.setSelection(false);
1116 if (tagCombo
.getText().equals(Tag
.TIMESTAMP
.toString()) && logEntriesCount
<= 1) {
1117 String value
= previewText
.getText().trim();
1118 if (value
.length() != 0) {
1119 if (actionCombo
.getSelectionIndex() == CustomTraceDefinition
.ACTION_SET
) {
1120 timeStampValue
= value
;
1121 timeStampFormat
= tagText
.getText().trim();
1122 } else if (actionCombo
.getSelectionIndex() == CustomTraceDefinition
.ACTION_APPEND
) {
1123 if (timeStampValue
!= null) {
1124 timeStampValue
+= value
;
1125 timeStampFormat
+= tagText
.getText().trim();
1127 timeStampValue
= value
;
1128 timeStampFormat
= tagText
.getText().trim();
1130 } else if (actionCombo
.getSelectionIndex() == CustomTraceDefinition
.ACTION_APPEND_WITH_SEPARATOR
) {
1131 if (timeStampValue
!= null) {
1132 timeStampValue
+= " | " + value
; //$NON-NLS-1$
1133 timeStampFormat
+= " | " + tagText
.getText().trim(); //$NON-NLS-1$
1135 timeStampValue
= value
;
1136 timeStampFormat
= tagText
.getText().trim();
1143 for (Attribute attribute
: attributes
) {
1144 if (element
!= null) {
1145 String value
= element
.getAttribute(attribute
.attributeNameText
.getText().trim());
1146 if (value
.length() != 0) {
1147 attribute
.previewText
.setText(value
);
1148 if (attribute
.tagCombo
.getText().equals(Tag
.TIMESTAMP
.toString()) && logEntriesCount
<= 1) {
1149 if (attribute
.actionCombo
.getSelectionIndex() == CustomTraceDefinition
.ACTION_SET
) {
1150 timeStampValue
= value
;
1151 timeStampFormat
= attribute
.tagText
.getText().trim();
1152 } else if (attribute
.actionCombo
.getSelectionIndex() == CustomTraceDefinition
.ACTION_APPEND
) {
1153 if (timeStampValue
!= null) {
1154 timeStampValue
+= value
;
1155 timeStampFormat
+= attribute
.tagText
.getText().trim();
1157 timeStampValue
= value
;
1158 timeStampFormat
= attribute
.tagText
.getText().trim();
1160 } else if (attribute
.actionCombo
.getSelectionIndex() == CustomTraceDefinition
.ACTION_APPEND_WITH_SEPARATOR
) {
1161 if (timeStampValue
!= null) {
1162 timeStampValue
+= " | " + value
; //$NON-NLS-1$
1163 timeStampFormat
+= " | " + attribute
.tagText
.getText().trim(); //$NON-NLS-1$
1165 timeStampValue
= value
;
1166 timeStampFormat
= attribute
.tagText
.getText().trim();
1171 attribute
.previewText
.setText(Messages
.CustomXmlParserInputWizardPage_noMatchingAttribute
);
1174 attribute
.previewText
.setText(Messages
.CustomXmlParserInputWizardPage_noMatchingElement
);
1177 for (ElementNode child
: childElements
) {
1178 child
.updatePreview();
1180 if (logEntryButton
!= null && logEntryButton
.getSelection()) {
1181 logEntryFound
= false;
1185 private void createAddButton() {
1186 fillerLabel
= new Label(group
, SWT
.NONE
);
1188 addAttributeComposite
= new Composite(group
, SWT
.NONE
);
1189 addAttributeComposite
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
1190 GridLayout addAttributeLayout
= new GridLayout(2, false);
1191 addAttributeLayout
.marginHeight
= 0;
1192 addAttributeLayout
.marginWidth
= 0;
1193 addAttributeComposite
.setLayout(addAttributeLayout
);
1195 addAttributeButton
= new Button(addAttributeComposite
, SWT
.PUSH
);
1196 addAttributeButton
.setImage(ADD_IMAGE
);
1197 addAttributeButton
.setToolTipText(Messages
.CustomXmlParserInputWizardPage_addAttribute
);
1198 addAttributeButton
.addSelectionListener(new SelectionAdapter() {
1200 public void widgetSelected(SelectionEvent e
) {
1202 String attributeName
= getAttributeNameSuggestion(inputElement
);
1203 CustomXmlInputAttribute inputAttribute
= new CustomXmlInputAttribute(attributeName
, Tag
.OTHER
, attributeName
, 0, ""); //$NON-NLS-1$
1204 attributes
.add(new Attribute(group
, ElementNode
.this, inputAttribute
, attributes
.size() + 1));
1206 elementContainer
.layout();
1207 elementScrolledComposite
.setMinSize(elementContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).x
,
1208 elementContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).y
- 1);
1209 group
.getParent().layout();
1215 addAttributeLabel
= new Label(addAttributeComposite
, SWT
.NULL
);
1216 addAttributeLabel
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
1217 addAttributeLabel
.setText(Messages
.CustomXmlParserInputWizardPage_newAttibute
);
1220 private void removeAddButton() {
1221 fillerLabel
.dispose();
1222 addAttributeComposite
.dispose();
1225 private void removeAttribute(int attributeNumber
) {
1226 int nb
= attributeNumber
;
1227 if (--nb
< attributes
.size()) {
1228 attributes
.remove(nb
).dispose();
1229 for (int i
= nb
; i
< attributes
.size(); i
++) {
1230 attributes
.get(i
).setAttributeNumber(i
+ 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();
1239 private void dispose() {
1243 private void extractInputs() {
1244 inputElement
.setElementName(elementNameText
.getText().trim());
1245 if (inputElement
.getParentElement() != null) {
1246 inputElement
.setLogEntry(logEntryButton
.getSelection());
1247 inputElement
.setEventType(eventTypeButton
.getSelection() ? eventTypeText
.getText().trim() : null);
1248 Tag inputTag
= Tag
.fromLabel(tagCombo
.getText());
1249 inputElement
.setInputTag(inputTag
);
1250 if (inputTag
.equals(Tag
.OTHER
)) {
1251 inputElement
.setInputName(tagText
.getText().trim());
1253 inputElement
.setInputName(inputTag
.toString());
1254 if (inputTag
.equals(Tag
.TIMESTAMP
)) {
1255 inputElement
.setInputFormat(tagText
.getText().trim());
1258 inputElement
.setInputAction(actionCombo
.getSelectionIndex());
1260 inputElement
.setAttributes(new ArrayList
<CustomXmlInputAttribute
>(attributes
.size()));
1261 for (int i
= 0; i
< attributes
.size(); i
++) {
1262 String inputName
= null;
1263 String inputFormat
= null;
1264 Attribute attribute
= attributes
.get(i
);
1265 String attributeName
= attribute
.attributeNameText
.getText().trim();
1266 Tag inputTag
= Tag
.fromLabel(attribute
.tagCombo
.getText());
1267 if (inputTag
.equals(Tag
.OTHER
)) {
1268 inputName
= attribute
.tagText
.getText().trim();
1270 inputName
= inputTag
.toString();
1271 if (inputTag
.equals(Tag
.TIMESTAMP
)) {
1272 inputFormat
= attribute
.tagText
.getText().trim();
1275 int inputAction
= attribute
.actionCombo
.getSelectionIndex();
1276 inputElement
.addAttribute(new CustomXmlInputAttribute(attributeName
, inputTag
, inputName
, inputAction
, inputFormat
));
1281 private class Attribute
{
1282 private ElementNode element
;
1283 private int attributeNumber
;
1285 // children of parent (must be disposed)
1286 private Composite labelComposite
;
1287 private Composite attributeComposite
;
1288 private Label filler
;
1289 private Composite tagComposite
;
1291 // children of labelComposite
1292 private Label attributeLabel
;
1294 // children of attributeComposite
1295 private Text attributeNameText
;
1296 private Text previewText
;
1298 // children of tagComposite
1299 private Combo tagCombo
;
1300 private Label tagLabel
;
1301 private Text tagText
;
1302 private Combo actionCombo
;
1304 public Attribute(Composite parent
, ElementNode element
, CustomXmlInputAttribute inputAttribute
, int attributeNumber
) {
1305 this.element
= element
;
1306 this.attributeNumber
= attributeNumber
;
1308 labelComposite
= new Composite(parent
, SWT
.FILL
);
1309 GridLayout labelLayout
= new GridLayout(2, false);
1310 labelLayout
.marginWidth
= 0;
1311 labelLayout
.marginHeight
= 0;
1312 labelComposite
.setLayout(labelLayout
);
1313 labelComposite
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
1315 Button deleteButton
= new Button(labelComposite
, SWT
.PUSH
);
1316 deleteButton
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
1317 deleteButton
.setImage(DELETE_IMAGE
);
1318 deleteButton
.setToolTipText(Messages
.CustomXmlParserInputWizardPage_removeAttribute
);
1319 deleteButton
.addSelectionListener(new SelectionAdapter() {
1321 public void widgetSelected(SelectionEvent e
) {
1322 Attribute
.this.element
.removeAttribute(Attribute
.this.attributeNumber
);
1328 attributeLabel
= new Label(labelComposite
, SWT
.NULL
);
1329 attributeLabel
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
1330 attributeLabel
.setText(Messages
.CustomXmlParserInputWizardPage_attibute
);
1332 attributeComposite
= new Composite(parent
, SWT
.FILL
);
1333 GridLayout attributeLayout
= new GridLayout(4, false);
1334 attributeLayout
.marginWidth
= 0;
1335 attributeLayout
.marginHeight
= 0;
1336 attributeComposite
.setLayout(attributeLayout
);
1337 attributeComposite
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
1339 Label nameLabel
= new Label(attributeComposite
, SWT
.NONE
);
1340 nameLabel
.setText(Messages
.CustomXmlParserInputWizardPage_name
);
1342 attributeNameText
= new Text(attributeComposite
, SWT
.BORDER
| SWT
.SINGLE
);
1343 attributeNameText
.setLayoutData(new GridData(120, SWT
.DEFAULT
));
1344 attributeNameText
.setText(inputAttribute
.getAttributeName());
1345 attributeNameText
.addModifyListener(updateListener
);
1347 Label previewLabel
= new Label(attributeComposite
, SWT
.NONE
);
1348 previewLabel
.setText(Messages
.CustomXmlParserInputWizardPage_preview
);
1350 previewText
= new Text(attributeComposite
, SWT
.BORDER
| SWT
.SINGLE
| SWT
.READ_ONLY
);
1351 GridData gd
= new GridData(SWT
.FILL
, SWT
.CENTER
, true, false);
1353 previewText
.setLayoutData(gd
);
1354 previewText
.setText(Messages
.CustomXmlParserInputWizardPage_noMatch
);
1355 previewText
.setBackground(COLOR_WIDGET_BACKGROUND
);
1357 filler
= new Label(parent
, SWT
.NULL
);
1359 tagComposite
= new Composite(parent
, SWT
.FILL
);
1360 GridLayout tagLayout
= new GridLayout(4, false);
1361 tagLayout
.marginWidth
= 0;
1362 tagLayout
.marginHeight
= 0;
1363 tagComposite
.setLayout(tagLayout
);
1364 tagComposite
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
1366 tagCombo
= new Combo(tagComposite
, SWT
.DROP_DOWN
| SWT
.READ_ONLY
);
1367 tagCombo
.setItems(new String
[] {
1368 Tag
.TIMESTAMP
.toString(),
1369 Tag
.EVENT_TYPE
.toString(),
1370 Tag
.MESSAGE
.toString(),
1371 Tag
.OTHER
.toString() });
1372 tagCombo
.select(3); // Other
1373 tagCombo
.addSelectionListener(new SelectionListener() {
1375 public void widgetDefaultSelected(SelectionEvent e
) {
1379 public void widgetSelected(SelectionEvent e
) {
1380 tagText
.removeModifyListener(updateListener
);
1381 switch (tagCombo
.getSelectionIndex()) {
1382 case 0: // Time Stamp
1383 tagLabel
.setText(Messages
.CustomXmlParserInputWizardPage_format
);
1384 tagLabel
.setVisible(true);
1385 tagText
.setVisible(true);
1386 tagText
.addModifyListener(updateListener
);
1388 case 1: // Event type
1389 tagLabel
.setVisible(false);
1390 tagText
.setVisible(false);
1393 tagLabel
.setVisible(false);
1394 tagText
.setVisible(false);
1397 tagLabel
.setText(Messages
.CustomXmlParserInputWizardPage_name
);
1398 tagLabel
.setVisible(true);
1399 if (tagText
.getText().trim().length() == 0) {
1400 tagText
.setText(attributeNameText
.getText().trim());
1402 tagText
.setVisible(true);
1403 tagText
.addModifyListener(updateListener
);
1408 tagComposite
.layout();
1414 tagLabel
= new Label(tagComposite
, SWT
.NULL
);
1415 tagLabel
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
1417 tagText
= new Text(tagComposite
, SWT
.BORDER
| SWT
.SINGLE
);
1418 gd
= new GridData(SWT
.FILL
, SWT
.CENTER
, true, false);
1420 tagText
.setLayoutData(gd
);
1421 tagText
.setText(attributeNameText
.getText());
1423 actionCombo
= new Combo(tagComposite
, SWT
.DROP_DOWN
| SWT
.READ_ONLY
);
1424 actionCombo
.setItems(new String
[] { Messages
.CustomXmlParserInputWizardPage_set
, Messages
.CustomXmlParserInputWizardPage_append
,
1425 Messages
.CustomXmlParserInputWizardPage_appendWith
});
1426 actionCombo
.select(inputAttribute
.getInputAction());
1427 actionCombo
.addSelectionListener(updateListener
);
1429 if (inputAttribute
.getInputTag().equals(Tag
.TIMESTAMP
)) {
1431 tagLabel
.setText(Messages
.CustomXmlParserInputWizardPage_format
);
1432 tagText
.setText(inputAttribute
.getInputFormat());
1433 tagText
.addModifyListener(updateListener
);
1434 } else if (inputAttribute
.getInputTag().equals(Tag
.EVENT_TYPE
)) {
1436 tagLabel
.setVisible(false);
1437 tagText
.setVisible(false);
1438 } else if (inputAttribute
.getInputTag().equals(Tag
.MESSAGE
)) {
1440 tagLabel
.setVisible(false);
1441 tagText
.setVisible(false);
1444 tagLabel
.setText(Messages
.CustomXmlParserInputWizardPage_name
);
1445 tagText
.setText(inputAttribute
.getInputName());
1446 tagText
.addModifyListener(updateListener
);
1450 private void dispose() {
1451 labelComposite
.dispose();
1452 attributeComposite
.dispose();
1454 tagComposite
.dispose();
1457 private void setAttributeNumber(int attributeNumber
) {
1458 this.attributeNumber
= attributeNumber
;
1459 labelComposite
.layout();
1463 private Element
getPreviewElement(CustomXmlInputElement inputElement
) {
1464 CustomXmlInputElement currentElement
= inputElement
;
1465 Element element
= documentElement
;
1466 if (element
!= null) {
1467 if (!documentElement
.getNodeName().equals(definition
.rootInputElement
.getElementName())) {
1470 ArrayList
<String
> elementNames
= new ArrayList
<>();
1471 while (currentElement
!= null) {
1472 elementNames
.add(currentElement
.getElementName());
1473 currentElement
= currentElement
.getParentElement();
1475 for (int i
= elementNames
.size() - 1; --i
>= 0;) {
1476 NodeList childList
= element
.getChildNodes();
1478 for (int j
= 0; j
< childList
.getLength(); j
++) {
1479 Node child
= childList
.item(j
);
1480 if (child
instanceof Element
&& child
.getNodeName().equals(elementNames
.get(i
))) {
1481 element
= (Element
) child
;
1485 if (element
== null) {
1489 if (element
!= null) {
1496 private String
getChildNameSuggestion(CustomXmlInputElement inputElement
) {
1497 if (inputElement
== null) {
1498 if (documentElement
!= null) {
1499 return documentElement
.getNodeName();
1502 Element element
= getPreviewElement(inputElement
);
1503 if (element
!= null) {
1504 NodeList childNodes
= element
.getChildNodes();
1505 for (int i
= 0; i
< childNodes
.getLength(); i
++) {
1506 Node node
= childNodes
.item(i
);
1507 if (node
instanceof Element
) {
1508 boolean unused
= true;
1509 if (inputElement
.getChildElements() != null) {
1510 for (CustomXmlInputElement child
: inputElement
.getChildElements()) {
1511 if (child
.getElementName().equals(node
.getNodeName())) {
1518 return node
.getNodeName();
1524 return ""; //$NON-NLS-1$
1527 private String
getAttributeNameSuggestion(CustomXmlInputElement inputElement
) {
1528 Element element
= getPreviewElement(inputElement
);
1529 if (element
!= null) {
1530 NamedNodeMap attributeMap
= element
.getAttributes();
1531 for (int i
= 0; i
< attributeMap
.getLength(); i
++) {
1532 Node node
= attributeMap
.item(i
);
1533 boolean unused
= true;
1534 if (inputElement
.getAttributes() != null) {
1535 for (CustomXmlInputAttribute attribute
: inputElement
.getAttributes()) {
1536 if (attribute
.getAttributeName().equals(node
.getNodeName())) {
1543 return node
.getNodeName();
1547 return ""; //$NON-NLS-1$
1550 private void validate() {
1551 definition
.categoryName
= categoryText
.getText().trim();
1552 definition
.definitionName
= logtypeText
.getText().trim();
1553 definition
.timeStampOutputFormat
= timeStampOutputFormatText
.getText().trim();
1555 if (selectedElement
!= null) {
1556 selectedElement
.extractInputs();
1557 treeViewer
.refresh();
1560 List
<String
> errors
= new ArrayList
<>();
1562 if (definition
.categoryName
.length() == 0) {
1563 errors
.add(Messages
.CustomXmlParserInputWizardPage_emptyCategoryError
);
1564 categoryText
.setBackground(COLOR_LIGHT_RED
);
1565 } else if (definition
.definitionName
.length() == 0) {
1566 errors
.add(Messages
.CustomXmlParserInputWizardPage_emptyLogTypeError
);
1567 logtypeText
.setBackground(COLOR_LIGHT_RED
);
1569 categoryText
.setBackground(COLOR_TEXT_BACKGROUND
);
1570 logtypeText
.setBackground(COLOR_TEXT_BACKGROUND
);
1571 if (definition
.categoryName
.indexOf(':') != -1) {
1572 errors
.add(Messages
.CustomXmlParserInputWizardPage_invalidCategoryError
);
1573 categoryText
.setBackground(COLOR_LIGHT_RED
);
1575 if (definition
.definitionName
.indexOf(':') != -1) {
1576 errors
.add(Messages
.CustomXmlParserInputWizardPage_invalidLogTypeError
);
1577 logtypeText
.setBackground(COLOR_LIGHT_RED
);
1579 for (TraceTypeHelper helper
: TmfTraceType
.getTraceTypeHelpers()) {
1580 if (definition
.categoryName
.equals(helper
.getCategoryName()) &&
1581 definition
.definitionName
.equals(helper
.getName()) &&
1582 (editDefinitionName
== null || !editDefinitionName
.equals(definition
.definitionName
)) &&
1583 (editCategoryName
== null || !editCategoryName
.equals(definition
.categoryName
))) {
1584 errors
.add(Messages
.CustomXmlParserInputWizardPage_duplicatelogTypeError
);
1585 logtypeText
.setBackground(COLOR_LIGHT_RED
);
1591 if (definition
.rootInputElement
== null) {
1592 errors
.add(Messages
.CustomXmlParserInputWizardPage_noDocumentError
);
1595 if (definition
.rootInputElement
!= null) {
1596 logEntryFound
= false;
1597 timeStampFound
= false;
1599 errors
.addAll(validateElement(definition
.rootInputElement
));
1601 if ((definition
.rootInputElement
.getAttributes() != null && definition
.rootInputElement
.getAttributes().size() != 0)
1602 || (definition
.rootInputElement
.getChildElements() != null && definition
.rootInputElement
.getChildElements().size() != 0)
1603 || errors
.size() == 0) {
1604 if (!logEntryFound
) {
1605 errors
.add(Messages
.CustomXmlParserInputWizardPage_missingLogEntryError
);
1608 if (timeStampFound
&& !definition
.timeStampOutputFormat
.isEmpty()) {
1610 new TmfTimestampFormat(timeStampOutputFormatText
.getText().trim());
1611 timeStampOutputFormatText
.setBackground(COLOR_TEXT_BACKGROUND
);
1612 } catch (IllegalArgumentException e
) {
1613 errors
.add(Messages
.CustomXmlParserInputWizardPage_elementInvalidTimestampFmtError
);
1614 timeStampOutputFormatText
.setBackground(COLOR_LIGHT_RED
);
1617 timeStampOutputFormatText
.setBackground(COLOR_TEXT_BACKGROUND
);
1618 if (!timeStampFound
) {
1619 timeStampPreviewText
.setText(Messages
.CustomXmlParserInputWizardPage_noTimestampElementOrAttribute
);
1624 timeStampPreviewText
.setText(Messages
.CustomXmlParserInputWizardPage_noTimestampElementOrAttribute
);
1627 if (errors
.size() == 0) {
1628 setDescription(defaultDescription
);
1629 setPageComplete(true);
1631 setDescription(Joiner
.on(' ').join(errors
));
1632 setPageComplete(false);
1637 * Clean up the specified XML element.
1639 * @param inputElement
1640 * The element to clean up
1641 * @return The validated element
1643 public List
<String
> validateElement(CustomXmlInputElement inputElement
) {
1644 List
<String
> errors
= new ArrayList
<>();
1645 ElementNode elementNode
= null;
1646 if (selectedElement
!= null && selectedElement
.inputElement
.equals(inputElement
)) {
1647 elementNode
= selectedElement
;
1649 if (inputElement
== definition
.rootInputElement
) {
1650 if (inputElement
.getElementName().length() == 0) {
1651 errors
.add(Messages
.CustomXmlParserInputWizardPage_missingDocumentElementError
);
1652 if (elementNode
!= null) {
1653 elementNode
.elementNameText
.setBackground(COLOR_LIGHT_RED
);
1656 if (elementNode
!= null) {
1657 elementNode
.elementNameText
.setBackground(COLOR_TEXT_BACKGROUND
);
1661 if (inputElement
!= definition
.rootInputElement
) {
1662 if (inputElement
.isLogEntry()) {
1663 logEntryFound
= true;
1665 if (inputElement
.getInputTag().equals(Tag
.TIMESTAMP
)) {
1666 timeStampFound
= true;
1667 if (inputElement
.getInputFormat().length() == 0) {
1668 errors
.add(NLS
.bind(Messages
.CustomXmlParserInputWizardPage_elementMissingTimestampFmtError
, getName(inputElement
)));
1669 if (elementNode
!= null) {
1670 elementNode
.tagText
.setBackground(COLOR_LIGHT_RED
);
1674 new TmfTimestampFormat(inputElement
.getInputFormat());
1675 if (elementNode
!= null) {
1676 elementNode
.tagText
.setBackground(COLOR_TEXT_BACKGROUND
);
1678 } catch (IllegalArgumentException e
) {
1679 errors
.add(NLS
.bind(Messages
.CustomXmlParserInputWizardPage_elementInvalidTimestampFmtError
, getName(inputElement
)));
1680 if (elementNode
!= null) {
1681 elementNode
.tagText
.setBackground(COLOR_LIGHT_RED
);
1685 } else if (inputElement
.getInputName().length() == 0) {
1686 errors
.add(NLS
.bind(Messages
.CustomXmlParserInputWizardPage_elementMissingInputNameError
, getName(inputElement
)));
1687 if (elementNode
!= null) {
1688 elementNode
.tagText
.setBackground(COLOR_LIGHT_RED
);
1690 } else if (inputElement
.getInputTag().equals(Tag
.OTHER
) && Tag
.fromLabel(inputElement
.getInputName()) != null) {
1691 errors
.add(NLS
.bind(Messages
.CustomXmlParserInputWizardPage_elementReservedInputNameError
, getName(inputElement
)));
1692 if (elementNode
!= null) {
1693 elementNode
.tagText
.setBackground(COLOR_LIGHT_RED
);
1696 if (elementNode
!= null) {
1697 elementNode
.tagText
.setBackground(COLOR_TEXT_BACKGROUND
);
1700 if (inputElement
.getEventType() != null && inputElement
.getEventType().trim().isEmpty()) {
1701 errors
.add(NLS
.bind(Messages
.CustomXmlParserInputWizardPage_emptyEventTypeError
, getName(inputElement
)));
1702 if (elementNode
!= null) {
1703 elementNode
.eventTypeText
.setBackground(COLOR_LIGHT_RED
);
1706 if (elementNode
!= null) {
1707 elementNode
.eventTypeText
.setBackground(COLOR_TEXT_BACKGROUND
);
1711 if (inputElement
.getAttributes() != null) {
1712 if (elementNode
!= null) {
1713 for (Attribute attribute
: elementNode
.attributes
) {
1714 attribute
.attributeNameText
.setBackground(COLOR_TEXT_BACKGROUND
);
1717 for (int i
= 0; i
< inputElement
.getAttributes().size(); i
++) {
1718 CustomXmlInputAttribute attribute
= inputElement
.getAttributes().get(i
);
1719 boolean duplicate
= false;
1720 for (int j
= i
+ 1; j
< inputElement
.getAttributes().size(); j
++) {
1721 CustomXmlInputAttribute otherAttribute
= inputElement
.getAttributes().get(j
);
1722 if (otherAttribute
.getAttributeName().equals(attribute
.getAttributeName())) {
1724 if (elementNode
!= null) {
1725 elementNode
.attributes
.get(j
).attributeNameText
.setBackground(COLOR_LIGHT_RED
);
1729 if (attribute
.getAttributeName().length() == 0) {
1730 errors
.add(NLS
.bind(Messages
.CustomXmlParserInputWizardPage_attributeMissingNameError
, getName(inputElement
)));
1731 if (elementNode
!= null) {
1732 elementNode
.attributes
.get(i
).attributeNameText
.setBackground(COLOR_LIGHT_RED
);
1734 } else if (duplicate
) {
1735 errors
.add(NLS
.bind(Messages
.CustomXmlParserInputWizardPage_attributeDuplicateNameError
, getName(attribute
, inputElement
)));
1736 if (elementNode
!= null) {
1737 elementNode
.attributes
.get(i
).attributeNameText
.setBackground(COLOR_LIGHT_RED
);
1740 if (attribute
.getInputTag().equals(Tag
.TIMESTAMP
)) {
1741 timeStampFound
= true;
1742 if (attribute
.getInputFormat().length() == 0) {
1743 errors
.add(NLS
.bind(Messages
.CustomXmlParserInputWizardPage_attributeMissingTimestampFmtError
, getName(attribute
, inputElement
)));
1744 if (elementNode
!= null) {
1745 elementNode
.attributes
.get(i
).tagText
.setBackground(COLOR_LIGHT_RED
);
1749 new TmfTimestampFormat(attribute
.getInputFormat());
1750 if (elementNode
!= null) {
1751 elementNode
.attributes
.get(i
).tagText
.setBackground(COLOR_TEXT_BACKGROUND
);
1753 } catch (IllegalArgumentException e
) {
1754 errors
.add(NLS
.bind(Messages
.CustomXmlParserInputWizardPage_attributeInvalidTimestampFmtError
, getName(attribute
, inputElement
)));
1755 if (elementNode
!= null) {
1756 elementNode
.attributes
.get(i
).tagText
.setBackground(COLOR_LIGHT_RED
);
1760 } else if (attribute
.getInputName().length() == 0) {
1761 errors
.add(NLS
.bind(Messages
.CustomXmlParserInputWizardPage_attributeMissingInputNameError
, getName(attribute
, inputElement
)));
1762 if (elementNode
!= null) {
1763 elementNode
.attributes
.get(i
).tagText
.setBackground(COLOR_LIGHT_RED
);
1765 } else if (attribute
.getInputTag().equals(Tag
.OTHER
) && Tag
.fromLabel(attribute
.getInputName()) != null) {
1766 errors
.add(NLS
.bind(Messages
.CustomXmlParserInputWizardPage_attributeReservedInputNameError
, getName(attribute
, inputElement
)));
1767 if (elementNode
!= null) {
1768 elementNode
.attributes
.get(i
).tagText
.setBackground(COLOR_LIGHT_RED
);
1771 if (elementNode
!= null) {
1772 elementNode
.attributes
.get(i
).tagText
.setBackground(COLOR_TEXT_BACKGROUND
);
1777 if (inputElement
.getChildElements() != null) {
1778 for (CustomXmlInputElement child
: inputElement
.getChildElements()) {
1779 ElementNode childElementNode
= null;
1780 if (selectedElement
!= null && selectedElement
.inputElement
.equals(child
)) {
1781 childElementNode
= selectedElement
;
1783 if (childElementNode
!= null) {
1784 childElementNode
.elementNameText
.setBackground(COLOR_TEXT_BACKGROUND
);
1787 for (int i
= 0; i
< inputElement
.getChildElements().size(); i
++) {
1788 CustomXmlInputElement child
= inputElement
.getChildElements().get(i
);
1789 ElementNode childElementNode
= null;
1790 if (selectedElement
!= null && selectedElement
.inputElement
.equals(child
)) {
1791 childElementNode
= selectedElement
;
1793 if (child
.getElementName().length() == 0) {
1794 errors
.add(NLS
.bind(Messages
.CustomXmlParserInputWizardPage_elementMissingNameError
, getName(child
)));
1795 if (childElementNode
!= null) {
1796 childElementNode
.elementNameText
.setBackground(COLOR_LIGHT_RED
);
1799 boolean duplicate
= false;
1800 for (int j
= i
+ 1; j
< inputElement
.getChildElements().size(); j
++) {
1801 CustomXmlInputElement otherChild
= inputElement
.getChildElements().get(j
);
1802 if (otherChild
.getElementName().equals(child
.getElementName())) {
1804 ElementNode otherChildElementNode
= null;
1805 if (selectedElement
!= null && selectedElement
.inputElement
.equals(otherChild
)) {
1806 otherChildElementNode
= selectedElement
;
1808 if (otherChildElementNode
!= null) {
1809 otherChildElementNode
.elementNameText
.setBackground(COLOR_LIGHT_RED
);
1814 errors
.add(NLS
.bind(Messages
.CustomXmlParserInputWizardPage_elementDuplicateNameError
, getName(child
)));
1815 if (childElementNode
!= null) {
1816 childElementNode
.elementNameText
.setBackground(COLOR_LIGHT_RED
);
1821 errors
.addAll(validateElement(child
));
1828 * Get the trace definition.
1830 * @return The trace definition
1832 public CustomXmlTraceDefinition
getDefinition() {
1837 * Get the raw text input.
1839 * @return The raw text input.
1841 public char[] getInputText() {
1842 return inputText
.getText().toCharArray();