1 /*******************************************************************************
2 * Copyright (c) 2010, 2014 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
.linuxtools
.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
.ArrayList
;
23 import java
.util
.List
;
25 import javax
.xml
.parsers
.DocumentBuilder
;
26 import javax
.xml
.parsers
.DocumentBuilderFactory
;
27 import javax
.xml
.parsers
.ParserConfigurationException
;
29 import org
.eclipse
.core
.resources
.IFile
;
30 import org
.eclipse
.core
.runtime
.CoreException
;
31 import org
.eclipse
.core
.runtime
.FileLocator
;
32 import org
.eclipse
.core
.runtime
.IPath
;
33 import org
.eclipse
.core
.runtime
.Path
;
34 import org
.eclipse
.core
.runtime
.Platform
;
35 import org
.eclipse
.jface
.viewers
.AbstractTreeViewer
;
36 import org
.eclipse
.jface
.viewers
.ColumnLabelProvider
;
37 import org
.eclipse
.jface
.viewers
.ISelection
;
38 import org
.eclipse
.jface
.viewers
.ISelectionChangedListener
;
39 import org
.eclipse
.jface
.viewers
.IStructuredSelection
;
40 import org
.eclipse
.jface
.viewers
.ITreeContentProvider
;
41 import org
.eclipse
.jface
.viewers
.SelectionChangedEvent
;
42 import org
.eclipse
.jface
.viewers
.StructuredSelection
;
43 import org
.eclipse
.jface
.viewers
.TreeViewer
;
44 import org
.eclipse
.jface
.viewers
.Viewer
;
45 import org
.eclipse
.jface
.wizard
.WizardPage
;
46 import org
.eclipse
.linuxtools
.internal
.tmf
.ui
.Activator
;
47 import org
.eclipse
.linuxtools
.internal
.tmf
.ui
.Messages
;
48 import org
.eclipse
.linuxtools
.tmf
.core
.parsers
.custom
.CustomTraceDefinition
;
49 import org
.eclipse
.linuxtools
.tmf
.core
.parsers
.custom
.CustomXmlTrace
;
50 import org
.eclipse
.linuxtools
.tmf
.core
.parsers
.custom
.CustomXmlTraceDefinition
;
51 import org
.eclipse
.linuxtools
.tmf
.core
.parsers
.custom
.CustomXmlTraceDefinition
.InputAttribute
;
52 import org
.eclipse
.linuxtools
.tmf
.core
.parsers
.custom
.CustomXmlTraceDefinition
.InputElement
;
53 import org
.eclipse
.linuxtools
.tmf
.core
.project
.model
.TmfTraceType
;
54 import org
.eclipse
.linuxtools
.tmf
.core
.project
.model
.TraceTypeHelper
;
55 import org
.eclipse
.linuxtools
.tmf
.core
.timestamp
.TmfTimestampFormat
;
56 import org
.eclipse
.osgi
.util
.NLS
;
57 import org
.eclipse
.swt
.SWT
;
58 import org
.eclipse
.swt
.browser
.Browser
;
59 import org
.eclipse
.swt
.browser
.TitleEvent
;
60 import org
.eclipse
.swt
.browser
.TitleListener
;
61 import org
.eclipse
.swt
.custom
.SashForm
;
62 import org
.eclipse
.swt
.custom
.ScrolledComposite
;
63 import org
.eclipse
.swt
.custom
.StyleRange
;
64 import org
.eclipse
.swt
.custom
.StyledText
;
65 import org
.eclipse
.swt
.events
.ModifyEvent
;
66 import org
.eclipse
.swt
.events
.ModifyListener
;
67 import org
.eclipse
.swt
.events
.SelectionAdapter
;
68 import org
.eclipse
.swt
.events
.SelectionEvent
;
69 import org
.eclipse
.swt
.events
.SelectionListener
;
70 import org
.eclipse
.swt
.graphics
.Color
;
71 import org
.eclipse
.swt
.graphics
.Font
;
72 import org
.eclipse
.swt
.graphics
.FontData
;
73 import org
.eclipse
.swt
.graphics
.Image
;
74 import org
.eclipse
.swt
.graphics
.Point
;
75 import org
.eclipse
.swt
.graphics
.Rectangle
;
76 import org
.eclipse
.swt
.layout
.FillLayout
;
77 import org
.eclipse
.swt
.layout
.GridData
;
78 import org
.eclipse
.swt
.layout
.GridLayout
;
79 import org
.eclipse
.swt
.widgets
.Button
;
80 import org
.eclipse
.swt
.widgets
.Combo
;
81 import org
.eclipse
.swt
.widgets
.Composite
;
82 import org
.eclipse
.swt
.widgets
.Display
;
83 import org
.eclipse
.swt
.widgets
.Group
;
84 import org
.eclipse
.swt
.widgets
.Label
;
85 import org
.eclipse
.swt
.widgets
.Shell
;
86 import org
.eclipse
.swt
.widgets
.Text
;
87 import org
.osgi
.framework
.Bundle
;
88 import org
.w3c
.dom
.Document
;
89 import org
.w3c
.dom
.Element
;
90 import org
.w3c
.dom
.NamedNodeMap
;
91 import org
.w3c
.dom
.Node
;
92 import org
.w3c
.dom
.NodeList
;
93 import org
.xml
.sax
.EntityResolver
;
94 import org
.xml
.sax
.ErrorHandler
;
95 import org
.xml
.sax
.InputSource
;
96 import org
.xml
.sax
.SAXException
;
97 import org
.xml
.sax
.SAXParseException
;
99 import com
.google
.common
.base
.Joiner
;
102 * Input wizard page for custom XML trace parsers.
104 * @author Patrick Tasse
106 public class CustomXmlParserInputWizardPage
extends WizardPage
{
108 private static final String DEFAULT_TIMESTAMP_FORMAT
= "yyyy-MM-dd HH:mm:ss.SSS"; //$NON-NLS-1$
109 private static final String TIMESTAMP_FORMAT_BUNDLE
= "org.eclipse.linuxtools.lttng.help"; //$NON-NLS-1$
110 private static final String TIMESTAMP_FORMAT_PATH
= "reference/api/org/eclipse/linuxtools/tmf/core/timestamp/TmfTimestampFormat.html"; //$NON-NLS-1$
111 private static final Image ELEMENT_IMAGE
= Activator
.getDefault().getImageFromPath("/icons/elcl16/element_icon.gif"); //$NON-NLS-1$
112 private static final Image ADD_IMAGE
= Activator
.getDefault().getImageFromPath("/icons/elcl16/add_button.gif"); //$NON-NLS-1$
113 private static final Image ADD_NEXT_IMAGE
= Activator
.getDefault().getImageFromPath("/icons/elcl16/addnext_button.gif"); //$NON-NLS-1$
114 private static final Image ADD_CHILD_IMAGE
= Activator
.getDefault().getImageFromPath("/icons/elcl16/addchild_button.gif"); //$NON-NLS-1$
115 private static final Image ADD_MANY_IMAGE
= Activator
.getDefault().getImageFromPath("/icons/elcl16/addmany_button.gif"); //$NON-NLS-1$
116 private static final Image DELETE_IMAGE
= Activator
.getDefault().getImageFromPath("/icons/elcl16/delete_button.gif"); //$NON-NLS-1$
117 private static final Image MOVE_UP_IMAGE
= Activator
.getDefault().getImageFromPath("/icons/elcl16/moveup_button.gif"); //$NON-NLS-1$
118 private static final Image MOVE_DOWN_IMAGE
= Activator
.getDefault().getImageFromPath("/icons/elcl16/movedown_button.gif"); //$NON-NLS-1$
119 private static final Image HELP_IMAGE
= Activator
.getDefault().getImageFromPath("/icons/elcl16/help_button.gif"); //$NON-NLS-1$
120 private static final Color COLOR_LIGHT_RED
= new Color(Display
.getDefault(), 255, 192, 192);
121 private static final Color COLOR_TEXT_BACKGROUND
= Display
.getDefault().getSystemColor(SWT
.COLOR_WHITE
);
122 private static final Color COLOR_WIDGET_BACKGROUND
= Display
.getDefault().getSystemColor(SWT
.COLOR_WIDGET_BACKGROUND
);
124 private final ISelection selection
;
125 private CustomXmlTraceDefinition definition
;
126 private String editCategoryName
;
127 private String editDefinitionName
;
128 private String defaultDescription
;
129 private ElementNode selectedElement
;
130 private Composite container
;
131 private Text categoryText
;
132 private Text logtypeText
;
133 private Text timeStampOutputFormatText
;
134 private Text timeStampPreviewText
;
135 private Button removeButton
;
136 private Button addChildButton
;
137 private Button addNextButton
;
138 private Button moveUpButton
;
139 private Button moveDownButton
;
140 private ScrolledComposite elementScrolledComposite
;
141 private TreeViewer treeViewer
;
142 private Composite elementContainer
;
143 private Text errorText
;
144 private StyledText inputText
;
145 private Font fixedFont
;
146 private UpdateListener updateListener
;
147 private Browser helpBrowser
;
148 private Element documentElement
;
150 // variables used recursively through element traversal
151 private String timeStampValue
;
152 private String timeStampFormat
;
153 private boolean timeStampFound
;
154 private int logEntriesCount
;
155 private boolean logEntryFound
;
165 protected CustomXmlParserInputWizardPage(ISelection selection
, CustomXmlTraceDefinition definition
) {
166 super("CustomXmlParserWizardPage"); //$NON-NLS-1$
167 if (definition
== null) {
168 setTitle(Messages
.CustomXmlParserInputWizardPage_titleNew
);
169 defaultDescription
= Messages
.CustomXmlParserInputWizardPage_descriptionNew
;
171 setTitle(Messages
.CustomXmlParserInputWizardPage_titleEdit
);
172 defaultDescription
= Messages
.CustomXmlParserInputWizardPage_descriptionEdit
;
174 setDescription(defaultDescription
);
175 this.selection
= selection
;
176 this.definition
= definition
;
177 if (definition
!= null) {
178 this.editCategoryName
= definition
.categoryName
;
179 this.editDefinitionName
= definition
.definitionName
;
184 public void createControl(Composite parent
) {
185 container
= new Composite(parent
, SWT
.NULL
);
186 container
.setLayout(new GridLayout());
188 updateListener
= new UpdateListener();
190 Composite headerComposite
= new Composite(container
, SWT
.FILL
);
191 GridLayout headerLayout
= new GridLayout(5, false);
192 headerLayout
.marginHeight
= 0;
193 headerLayout
.marginWidth
= 0;
194 headerComposite
.setLayout(headerLayout
);
195 headerComposite
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
197 Label categoryLabel
= new Label(headerComposite
, SWT
.NULL
);
198 categoryLabel
.setText(Messages
.CustomXmlParserInputWizardPage_category
);
200 categoryText
= new Text(headerComposite
, SWT
.BORDER
| SWT
.SINGLE
);
201 categoryText
.setLayoutData(new GridData(120, SWT
.DEFAULT
));
203 Label timeStampFormatLabel
= new Label(headerComposite
, SWT
.NULL
);
204 timeStampFormatLabel
.setText(Messages
.CustomXmlParserInputWizardPage_timestampFormat
);
206 timeStampOutputFormatText
= new Text(headerComposite
, SWT
.BORDER
| SWT
.SINGLE
);
207 timeStampOutputFormatText
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
208 timeStampOutputFormatText
.setText(DEFAULT_TIMESTAMP_FORMAT
);
210 Button timeStampFormatHelpButton
= new Button(headerComposite
, SWT
.PUSH
);
211 timeStampFormatHelpButton
.setImage(HELP_IMAGE
);
212 timeStampFormatHelpButton
.setToolTipText(Messages
.CustomXmlParserInputWizardPage_timestampFormatHelp
);
213 timeStampFormatHelpButton
.addSelectionListener(new SelectionAdapter() {
215 public void widgetSelected(SelectionEvent e
) {
216 Bundle plugin
= Platform
.getBundle(TIMESTAMP_FORMAT_BUNDLE
);
217 IPath path
= new Path(TIMESTAMP_FORMAT_PATH
);
218 URL fileURL
= FileLocator
.find(plugin
, path
, null);
220 URL pageURL
= FileLocator
.toFileURL(fileURL
);
221 openHelpShell(pageURL
.toString());
222 } catch (IOException e1
) {
227 Label logtypeLabel
= new Label(headerComposite
, SWT
.NULL
);
228 logtypeLabel
.setText(Messages
.CustomXmlParserInputWizardPage_logType
);
230 logtypeText
= new Text(headerComposite
, SWT
.BORDER
| SWT
.SINGLE
);
231 logtypeText
.setLayoutData(new GridData(120, SWT
.DEFAULT
));
232 logtypeText
.setFocus();
234 Label timeStampPreviewLabel
= new Label(headerComposite
, SWT
.NULL
);
235 timeStampPreviewLabel
.setText(Messages
.CustomXmlParserInputWizardPage_preview
);
237 timeStampPreviewText
= new Text(headerComposite
, SWT
.BORDER
| SWT
.SINGLE
| SWT
.READ_ONLY
);
238 timeStampPreviewText
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false, 2, 1));
239 timeStampPreviewText
.setText("*no time stamp element or attribute*"); //$NON-NLS-1$
243 SashForm vSash
= new SashForm(container
, SWT
.VERTICAL
);
244 vSash
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
245 vSash
.setBackground(vSash
.getDisplay().getSystemColor(SWT
.COLOR_GRAY
));
247 SashForm hSash
= new SashForm(vSash
, SWT
.HORIZONTAL
);
248 hSash
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
250 ScrolledComposite treeScrolledComposite
= new ScrolledComposite(hSash
, SWT
.V_SCROLL
| SWT
.H_SCROLL
);
251 treeScrolledComposite
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
252 Composite treeContainer
= new Composite(treeScrolledComposite
, SWT
.NONE
);
253 treeContainer
.setLayout(new FillLayout());
254 treeScrolledComposite
.setContent(treeContainer
);
255 treeScrolledComposite
.setExpandHorizontal(true);
256 treeScrolledComposite
.setExpandVertical(true);
258 treeViewer
= new TreeViewer(treeContainer
, SWT
.SINGLE
| SWT
.BORDER
);
259 treeViewer
.setContentProvider(new InputElementTreeNodeContentProvider());
260 treeViewer
.setLabelProvider(new InputElementTreeLabelProvider());
261 treeViewer
.addSelectionChangedListener(new InputElementTreeSelectionChangedListener());
262 treeContainer
.layout();
264 treeScrolledComposite
265 .setMinSize(treeContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).x
, treeContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).y
);
267 elementScrolledComposite
= new ScrolledComposite(hSash
, SWT
.V_SCROLL
);
268 elementScrolledComposite
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
269 elementContainer
= new Composite(elementScrolledComposite
, SWT
.NONE
);
270 GridLayout gl
= new GridLayout();
273 elementContainer
.setLayout(gl
);
274 elementScrolledComposite
.setContent(elementContainer
);
275 elementScrolledComposite
.setExpandHorizontal(true);
276 elementScrolledComposite
.setExpandVertical(true);
278 if (definition
== null) {
279 definition
= new CustomXmlTraceDefinition();
281 loadDefinition(definition
);
282 treeViewer
.expandAll();
283 elementContainer
.layout();
285 categoryText
.addModifyListener(updateListener
);
286 logtypeText
.addModifyListener(updateListener
);
287 timeStampOutputFormatText
.addModifyListener(updateListener
);
289 elementScrolledComposite
.setMinSize(elementContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).x
,
290 elementContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).y
- 1);
292 hSash
.setWeights(new int[] { 1, 2 });
294 if (definition
.rootInputElement
== null) {
295 removeButton
.setEnabled(false);
296 addChildButton
.setToolTipText(Messages
.CustomXmlParserInputWizardPage_addDocumentElement
);
297 addNextButton
.setEnabled(false);
298 moveUpButton
.setEnabled(false);
299 moveDownButton
.setEnabled(false);
300 } else { // root is selected
301 addNextButton
.setEnabled(false);
304 Composite sashBottom
= new Composite(vSash
, SWT
.NONE
);
305 GridLayout sashBottomLayout
= new GridLayout(2, false);
306 sashBottomLayout
.marginHeight
= 0;
307 sashBottomLayout
.marginWidth
= 0;
308 sashBottom
.setLayout(sashBottomLayout
);
310 Label previewLabel
= new Label(sashBottom
, SWT
.NULL
);
311 previewLabel
.setText(Messages
.CustomXmlParserInputWizardPage_previewInput
);
313 errorText
= new Text(sashBottom
, SWT
.SINGLE
| SWT
.READ_ONLY
);
314 errorText
.setBackground(COLOR_WIDGET_BACKGROUND
);
315 errorText
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
316 errorText
.setVisible(false);
318 inputText
= new StyledText(sashBottom
, SWT
.MULTI
| SWT
.V_SCROLL
| SWT
.H_SCROLL
);
319 if (fixedFont
== null) {
320 if (System
.getProperty("os.name").contains("Windows")) { //$NON-NLS-1$ //$NON-NLS-2$
321 fixedFont
= new Font(Display
.getCurrent(), new FontData("Courier New", 10, SWT
.NORMAL
)); //$NON-NLS-1$
323 fixedFont
= new Font(Display
.getCurrent(), new FontData("Monospace", 10, SWT
.NORMAL
)); //$NON-NLS-1$
326 inputText
.setFont(fixedFont
);
327 GridData gd
= new GridData(SWT
.FILL
, SWT
.FILL
, true, true, 2, 1);
328 gd
.heightHint
= inputText
.computeSize(SWT
.DEFAULT
, inputText
.getLineHeight() * 4).y
;
330 inputText
.setLayoutData(gd
);
331 inputText
.setText(getSelectionText());
332 inputText
.addModifyListener(new ModifyListener() {
334 public void modifyText(ModifyEvent e
) {
335 parseXmlInput(inputText
.getText());
338 inputText
.addModifyListener(updateListener
);
340 vSash
.setWeights(new int[] { hSash
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).y
, sashBottom
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).y
});
342 setControl(container
);
345 private void createButtonBar() {
346 Composite buttonBar
= new Composite(container
, SWT
.NONE
);
347 GridLayout buttonBarLayout
= new GridLayout(6, false);
348 buttonBarLayout
.marginHeight
= 0;
349 buttonBarLayout
.marginWidth
= 0;
350 buttonBar
.setLayout(buttonBarLayout
);
352 removeButton
= new Button(buttonBar
, SWT
.PUSH
);
353 removeButton
.setImage(DELETE_IMAGE
);
354 removeButton
.setToolTipText(Messages
.CustomXmlParserInputWizardPage_removeElement
);
355 removeButton
.addSelectionListener(new SelectionAdapter() {
357 public void widgetSelected(SelectionEvent e
) {
358 if (treeViewer
.getSelection().isEmpty() || selectedElement
== null) {
362 InputElement inputElement
= (InputElement
) ((IStructuredSelection
) treeViewer
.getSelection()).getFirstElement();
363 if (inputElement
== definition
.rootInputElement
) {
364 definition
.rootInputElement
= null;
366 inputElement
.parentElement
.childElements
.remove(inputElement
);
368 treeViewer
.refresh();
371 removeButton
.setEnabled(false);
372 if (definition
.rootInputElement
== null) {
373 addChildButton
.setEnabled(true);
374 addChildButton
.setToolTipText(Messages
.CustomXmlParserInputWizardPage_addDocumentEleemnt
);
376 addChildButton
.setEnabled(false);
378 addNextButton
.setEnabled(false);
379 moveUpButton
.setEnabled(false);
380 moveDownButton
.setEnabled(false);
384 addChildButton
= new Button(buttonBar
, SWT
.PUSH
);
385 addChildButton
.setImage(ADD_CHILD_IMAGE
);
386 addChildButton
.setToolTipText(Messages
.CustomXmlParserInputWizardPage_addChildElement
);
387 addChildButton
.addSelectionListener(new SelectionAdapter() {
389 public void widgetSelected(SelectionEvent e
) {
390 InputElement inputElement
= new InputElement("", false, CustomXmlTraceDefinition
.TAG_IGNORE
, 0, "", null); //$NON-NLS-1$ //$NON-NLS-2$
391 if (definition
.rootInputElement
== null) {
392 definition
.rootInputElement
= inputElement
;
393 inputElement
.elementName
= getChildNameSuggestion(null);
394 } else if (treeViewer
.getSelection().isEmpty()) {
397 InputElement parentInputElement
= (InputElement
) ((IStructuredSelection
) treeViewer
.getSelection()).getFirstElement();
398 parentInputElement
.addChild(inputElement
);
399 inputElement
.elementName
= getChildNameSuggestion(parentInputElement
);
401 treeViewer
.refresh();
402 treeViewer
.setSelection(new StructuredSelection(inputElement
), true);
406 addNextButton
= new Button(buttonBar
, SWT
.PUSH
);
407 addNextButton
.setImage(ADD_NEXT_IMAGE
);
408 addNextButton
.setToolTipText(Messages
.CustomXmlParserInputWizardPage_addNextElement
);
409 addNextButton
.addSelectionListener(new SelectionAdapter() {
411 public void widgetSelected(SelectionEvent e
) {
412 InputElement inputElement
= new InputElement("", false, CustomXmlTraceDefinition
.TAG_IGNORE
, 0, "", null); //$NON-NLS-1$ //$NON-NLS-2$
413 if (definition
.rootInputElement
== null) {
414 definition
.rootInputElement
= inputElement
;
415 inputElement
.elementName
= getChildNameSuggestion(null);
416 } else if (treeViewer
.getSelection().isEmpty()) {
419 InputElement previousInputElement
= (InputElement
) ((IStructuredSelection
) treeViewer
.getSelection()).getFirstElement();
420 if (previousInputElement
== definition
.rootInputElement
) {
423 previousInputElement
.addNext(inputElement
);
424 inputElement
.elementName
= getChildNameSuggestion(inputElement
.parentElement
);
426 treeViewer
.refresh();
427 treeViewer
.setSelection(new StructuredSelection(inputElement
), true);
431 Button feelingLuckyButton
= new Button(buttonBar
, SWT
.PUSH
);
432 feelingLuckyButton
.setImage(ADD_MANY_IMAGE
);
433 feelingLuckyButton
.setToolTipText(Messages
.CustomXmlParserInputWizardPage_feelingLucky
);
434 feelingLuckyButton
.addSelectionListener(new SelectionAdapter() {
436 public void widgetSelected(SelectionEvent e
) {
437 InputElement inputElement
= null;
438 if (definition
.rootInputElement
== null) {
439 if (getChildNameSuggestion(null).length() != 0) {
440 inputElement
= new InputElement(getChildNameSuggestion(null), false, CustomXmlTraceDefinition
.TAG_IGNORE
, 0, "", null); //$NON-NLS-1$
441 definition
.rootInputElement
= inputElement
;
442 feelingLucky(inputElement
);
446 } else if (treeViewer
.getSelection().isEmpty()) {
449 inputElement
= (InputElement
) ((IStructuredSelection
) treeViewer
.getSelection()).getFirstElement();
450 feelingLucky(inputElement
);
452 treeViewer
.refresh();
453 treeViewer
.setSelection(new StructuredSelection(inputElement
), true);
454 treeViewer
.expandToLevel(inputElement
, AbstractTreeViewer
.ALL_LEVELS
);
458 moveUpButton
= new Button(buttonBar
, SWT
.PUSH
);
459 moveUpButton
.setImage(MOVE_UP_IMAGE
);
460 moveUpButton
.setToolTipText(Messages
.CustomXmlParserInputWizardPage_moveUp
);
461 moveUpButton
.addSelectionListener(new SelectionAdapter() {
463 public void widgetSelected(SelectionEvent e
) {
464 if (treeViewer
.getSelection().isEmpty()) {
467 InputElement inputElement
= (InputElement
) ((IStructuredSelection
) treeViewer
.getSelection()).getFirstElement();
468 if (inputElement
== definition
.rootInputElement
) {
471 inputElement
.moveUp();
472 treeViewer
.refresh();
478 moveDownButton
= new Button(buttonBar
, SWT
.PUSH
);
479 moveDownButton
.setImage(MOVE_DOWN_IMAGE
);
480 moveDownButton
.setToolTipText(Messages
.CustomXmlParserInputWizardPage_moveDown
);
481 moveDownButton
.addSelectionListener(new SelectionAdapter() {
483 public void widgetSelected(SelectionEvent e
) {
484 if (treeViewer
.getSelection().isEmpty()) {
487 InputElement inputElement
= (InputElement
) ((IStructuredSelection
) treeViewer
.getSelection()).getFirstElement();
488 if (inputElement
== definition
.rootInputElement
) {
491 inputElement
.moveDown();
492 treeViewer
.refresh();
499 private void feelingLucky(InputElement inputElement
) {
501 String attributeName
= getAttributeNameSuggestion(inputElement
);
502 if (attributeName
.length() == 0) {
505 InputAttribute attribute
= new InputAttribute(attributeName
, attributeName
, 0, ""); //$NON-NLS-1$
506 inputElement
.addAttribute(attribute
);
509 String childName
= getChildNameSuggestion(inputElement
);
510 if (childName
.length() == 0) {
513 InputElement childElement
= new InputElement(childName
, false, CustomXmlTraceDefinition
.TAG_IGNORE
, 0, "", null); //$NON-NLS-1$
514 inputElement
.addChild(childElement
);
515 feelingLucky(childElement
);
519 private static class InputElementTreeNodeContentProvider
implements ITreeContentProvider
{
522 public Object
[] getElements(Object inputElement
) {
523 CustomXmlTraceDefinition def
= (CustomXmlTraceDefinition
) inputElement
;
524 if (def
.rootInputElement
!= null) {
525 return new Object
[] { def
.rootInputElement
};
527 return new Object
[0];
531 public Object
[] getChildren(Object parentElement
) {
532 InputElement inputElement
= (InputElement
) parentElement
;
533 if (inputElement
.childElements
== null) {
534 return new InputElement
[0];
536 return inputElement
.childElements
.toArray();
540 public boolean hasChildren(Object element
) {
541 InputElement inputElement
= (InputElement
) element
;
542 return (inputElement
.childElements
!= null && inputElement
.childElements
.size() > 0);
546 public void dispose() {
550 public void inputChanged(Viewer viewer
, Object oldInput
, Object newInput
) {
554 public Object
getParent(Object element
) {
555 InputElement inputElement
= (InputElement
) element
;
556 return inputElement
.parentElement
;
560 private static class InputElementTreeLabelProvider
extends ColumnLabelProvider
{
563 public Image
getImage(Object element
) {
564 return ELEMENT_IMAGE
;
568 public String
getText(Object element
) {
569 InputElement inputElement
= (InputElement
) element
;
570 return (inputElement
.elementName
.trim().length() == 0) ?
"?" : inputElement
.elementName
; //$NON-NLS-1$
574 private class InputElementTreeSelectionChangedListener
implements ISelectionChangedListener
{
576 public void selectionChanged(SelectionChangedEvent event
) {
577 if (selectedElement
!= null) {
578 selectedElement
.dispose();
580 if (!(event
.getSelection().isEmpty()) && event
.getSelection() instanceof IStructuredSelection
) {
581 IStructuredSelection sel
= (IStructuredSelection
) event
.getSelection();
582 InputElement inputElement
= (InputElement
) sel
.getFirstElement();
583 selectedElement
= new ElementNode(elementContainer
, inputElement
);
584 elementContainer
.layout();
585 elementScrolledComposite
.setMinSize(elementContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).x
,
586 elementContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).y
- 1);
590 removeButton
.setEnabled(true);
591 addChildButton
.setEnabled(true);
592 addChildButton
.setToolTipText(Messages
.CustomXmlParserInputWizardPage_addChildElement
);
593 if (definition
.rootInputElement
== inputElement
) {
594 addNextButton
.setEnabled(false);
596 addNextButton
.setEnabled(true);
598 moveUpButton
.setEnabled(true);
599 moveDownButton
.setEnabled(true);
601 removeButton
.setEnabled(false);
602 if (definition
.rootInputElement
== null) {
603 addChildButton
.setEnabled(true);
604 addChildButton
.setToolTipText(Messages
.CustomXmlParserInputWizardPage_addDocumentElement
);
606 addChildButton
.setEnabled(false);
608 addNextButton
.setEnabled(false);
609 moveUpButton
.setEnabled(false);
610 moveDownButton
.setEnabled(false);
616 public void dispose() {
617 if (fixedFont
!= null) {
624 private void loadDefinition(CustomXmlTraceDefinition def
) {
625 categoryText
.setText(def
.categoryName
);
626 logtypeText
.setText(def
.definitionName
);
627 timeStampOutputFormatText
.setText(def
.timeStampOutputFormat
);
628 treeViewer
.setInput(def
);
630 if (def
.rootInputElement
!= null) {
631 treeViewer
.setSelection(new StructuredSelection(def
.rootInputElement
));
635 private String
getName(InputElement inputElement
) {
636 String name
= (inputElement
.elementName
.trim().length() == 0) ?
"?" : inputElement
.elementName
.trim(); //$NON-NLS-1$
637 if (inputElement
.parentElement
== null) {
640 return getName(inputElement
.parentElement
) + " : " + name
; //$NON-NLS-1$
643 private String
getName(InputAttribute inputAttribute
, InputElement inputElement
) {
644 String name
= (inputAttribute
.attributeName
.trim().length() == 0) ?
"?" : inputAttribute
.attributeName
.trim(); //$NON-NLS-1$
645 return getName(inputElement
) + " : " + name
; //$NON-NLS-1$
649 public void setVisible(boolean visible
) {
654 super.setVisible(visible
);
658 * Get the global list of input names.
660 * @return The list of input names
662 public List
<String
> getInputNames() {
663 return getInputNames(definition
.rootInputElement
);
667 * Get the list of input names for a given element.
669 * @param inputElement
671 * @return The input names for this element
673 public List
<String
> getInputNames(InputElement inputElement
) {
674 List
<String
> inputs
= new ArrayList
<>();
675 if (inputElement
.inputName
!= null && !inputElement
.inputName
.equals(CustomXmlTraceDefinition
.TAG_IGNORE
)) {
676 String inputName
= inputElement
.inputName
;
677 if (!inputs
.contains(inputName
)) {
678 inputs
.add(inputName
);
681 if (inputElement
.attributes
!= null) {
682 for (InputAttribute attribute
: inputElement
.attributes
) {
683 String inputName
= attribute
.inputName
;
684 if (!inputs
.contains(inputName
)) {
685 inputs
.add(inputName
);
689 if (inputElement
.childElements
!= null) {
690 for (InputElement childInputElement
: inputElement
.childElements
) {
691 for (String inputName
: getInputNames(childInputElement
)) {
692 if (!inputs
.contains(inputName
)) {
693 inputs
.add(inputName
);
701 private void removeElement() {
702 selectedElement
.dispose();
703 selectedElement
= null;
704 elementContainer
.layout();
705 elementScrolledComposite
.setMinSize(elementContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).x
,
706 elementContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).y
- 1);
710 private String
getSelectionText() {
711 InputStream inputStream
= null;
712 if (this.selection
instanceof IStructuredSelection
) {
713 Object sel
= ((IStructuredSelection
) this.selection
).getFirstElement();
714 if (sel
instanceof IFile
) {
715 IFile file
= (IFile
) sel
;
717 inputStream
= file
.getContents();
718 } catch (CoreException e
) {
719 return ""; //$NON-NLS-1$
723 if (inputStream
!= null) {
724 try (BufferedReader reader
= new BufferedReader(new InputStreamReader(inputStream
));) {
725 StringBuilder sb
= new StringBuilder();
727 while ((line
= reader
.readLine()) != null) {
728 sb
.append(line
+ "\n"); //$NON-NLS-1$
730 parseXmlInput(sb
.toString());
731 return sb
.toString();
732 } catch (IOException e
) {
733 return ""; //$NON-NLS-1$
736 return ""; //$NON-NLS-1$
739 private void parseXmlInput(final String string
) {
741 DocumentBuilderFactory dbf
= DocumentBuilderFactory
.newInstance();
742 DocumentBuilder db
= dbf
.newDocumentBuilder();
744 // The following allows xml parsing without access to the dtd
745 EntityResolver resolver
= new EntityResolver() {
747 public InputSource
resolveEntity(String publicId
, String systemId
) {
748 String empty
= ""; //$NON-NLS-1$
749 ByteArrayInputStream bais
= new ByteArrayInputStream(empty
.getBytes());
750 return new InputSource(bais
);
753 db
.setEntityResolver(resolver
);
755 // The following catches xml parsing exceptions
756 db
.setErrorHandler(new ErrorHandler() {
758 public void error(SAXParseException saxparseexception
) throws SAXException
{
762 public void warning(SAXParseException saxparseexception
) throws SAXException
{
766 public void fatalError(SAXParseException saxparseexception
) throws SAXException
{
767 if (string
.trim().length() != 0) {
768 errorText
.setText(saxparseexception
.getMessage());
769 errorText
.setBackground(COLOR_LIGHT_RED
);
770 errorText
.setVisible(true);
772 throw saxparseexception
;
776 errorText
.setVisible(false);
778 doc
= db
.parse(new ByteArrayInputStream(string
.getBytes()));
779 documentElement
= doc
.getDocumentElement();
780 } catch (ParserConfigurationException e
) {
781 Activator
.getDefault().logError("Error pasing XML input string: " + string
, e
); //$NON-NLS-1$
782 documentElement
= null;
783 } catch (SAXException e
) {
784 documentElement
= null;
785 } catch (IOException e
) {
786 Activator
.getDefault().logError("Error pasing XML input string: " + string
, e
); //$NON-NLS-1$
787 documentElement
= null;
791 private void initValues() {
792 timeStampValue
= null;
793 timeStampFormat
= null;
795 logEntryFound
= false;
798 private void updatePreviews() {
799 if (inputText
== null) {
800 // early update during construction
803 inputText
.setStyleRanges(new StyleRange
[] {});
804 if (selectedElement
== null) {
810 selectedElement
.updatePreview();
812 if (timeStampValue
!= null && timeStampFormat
!= null) {
814 TmfTimestampFormat timestampFormat
= new TmfTimestampFormat(timeStampFormat
);
815 long timestamp
= timestampFormat
.parseValue(timeStampValue
);
816 timestampFormat
= new TmfTimestampFormat(timeStampOutputFormatText
.getText().trim());
817 timeStampPreviewText
.setText(timestampFormat
.format(timestamp
));
818 } catch (ParseException e
) {
819 timeStampPreviewText
.setText("*parse exception* [" + timeStampValue
+ "] <> [" + timeStampFormat
+ "]"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
820 } catch (IllegalArgumentException e
) {
821 timeStampPreviewText
.setText("*parse exception* [Illegal Argument]"); //$NON-NLS-1$
824 timeStampPreviewText
.setText("*no matching time stamp*"); //$NON-NLS-1$
828 private void openHelpShell(String url
) {
829 if (helpBrowser
!= null && !helpBrowser
.isDisposed()) {
830 helpBrowser
.getShell().setActive();
831 if (!helpBrowser
.getUrl().equals(url
)) {
832 helpBrowser
.setUrl(url
);
836 final Shell helpShell
= new Shell(getShell(), SWT
.SHELL_TRIM
);
837 helpShell
.setLayout(new FillLayout());
838 helpBrowser
= new Browser(helpShell
, SWT
.NONE
);
839 helpBrowser
.addTitleListener(new TitleListener() {
841 public void changed(TitleEvent event
) {
842 helpShell
.setText(event
.title
);
845 Rectangle r
= container
.getBounds();
846 Point p
= container
.toDisplay(r
.x
, r
.y
);
847 Rectangle trim
= helpShell
.computeTrim(p
.x
+ (r
.width
- 750) / 2, p
.y
+ (r
.height
- 400) / 2, 750, 400);
848 helpShell
.setBounds(trim
);
850 helpBrowser
.setUrl(url
);
853 private class UpdateListener
implements ModifyListener
, SelectionListener
{
856 public void modifyText(ModifyEvent e
) {
862 public void widgetDefaultSelected(SelectionEvent e
) {
868 public void widgetSelected(SelectionEvent e
) {
875 private class ElementNode
{
876 private final InputElement inputElement
;
877 private final Group group
;
878 private List
<Attribute
> attributes
= new ArrayList
<>();
879 private List
<ElementNode
> childElements
= new ArrayList
<>();
880 private Text elementNameText
;
881 private Composite tagComposite
;
882 private Combo tagCombo
;
883 private Label tagLabel
;
884 private Text tagText
;
885 private Combo actionCombo
;
886 private Label previewLabel
;
887 private Text previewText
;
888 private Button logEntryButton
;
889 private Label fillerLabel
;
890 private Composite addAttributeComposite
;
891 private Button addAttributeButton
;
892 private Label addAttributeLabel
;
894 public ElementNode(Composite parent
, InputElement inputElement
) {
895 this.inputElement
= inputElement
;
897 group
= new Group(parent
, SWT
.NONE
);
898 GridLayout gl
= new GridLayout(2, false);
901 group
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
902 group
.setText(getName(inputElement
));
904 Label label
= new Label(group
, SWT
.NULL
);
905 label
.setText(Messages
.CustomXmlParserInputWizardPage_elementName
);
906 label
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
908 elementNameText
= new Text(group
, SWT
.BORDER
| SWT
.SINGLE
);
909 GridData gd
= new GridData(SWT
.FILL
, SWT
.CENTER
, true, false);
911 elementNameText
.setLayoutData(gd
);
912 elementNameText
.addModifyListener(new ModifyListener() {
914 public void modifyText(ModifyEvent e
) {
915 ElementNode
.this.inputElement
.elementName
= elementNameText
.getText().trim();
916 group
.setText(getName(ElementNode
.this.inputElement
));
919 elementNameText
.setText(inputElement
.elementName
);
920 elementNameText
.addModifyListener(updateListener
);
922 if (inputElement
.parentElement
!= null) {
923 previewLabel
= new Label(group
, SWT
.NULL
);
924 previewLabel
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
925 previewLabel
.setText(Messages
.CustomXmlParserInputWizardPage_preview
);
927 previewText
= new Text(group
, SWT
.BORDER
| SWT
.SINGLE
| SWT
.READ_ONLY
);
928 gd
= new GridData(SWT
.FILL
, SWT
.CENTER
, true, false);
930 previewText
.setLayoutData(gd
);
931 previewText
.setText(Messages
.CustomXmlParserInputWizardPage_noMatchingElement
);
932 previewText
.setBackground(COLOR_WIDGET_BACKGROUND
);
934 logEntryButton
= new Button(group
, SWT
.CHECK
);
935 logEntryButton
.setText(Messages
.CustomXmlParserInputWizardPage_logEntry
);
936 logEntryButton
.setSelection(inputElement
.logEntry
);
937 logEntryButton
.addSelectionListener(new SelectionListener() {
939 public void widgetDefaultSelected(SelectionEvent e
) {
943 public void widgetSelected(SelectionEvent e
) {
944 InputElement parentElem
= ElementNode
.this.inputElement
.parentElement
;
945 while (parentElem
!= null) {
946 parentElem
.logEntry
= false;
947 parentElem
= parentElem
.parentElement
;
951 logEntryButton
.addSelectionListener(updateListener
);
953 tagComposite
= new Composite(group
, SWT
.FILL
);
954 GridLayout tagLayout
= new GridLayout(4, false);
955 tagLayout
.marginWidth
= 0;
956 tagLayout
.marginHeight
= 0;
957 tagComposite
.setLayout(tagLayout
);
958 tagComposite
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
960 tagCombo
= new Combo(tagComposite
, SWT
.DROP_DOWN
| SWT
.READ_ONLY
);
961 tagCombo
.setItems(new String
[] { CustomXmlTraceDefinition
.TAG_IGNORE
, CustomTraceDefinition
.TAG_TIMESTAMP
,
962 CustomTraceDefinition
.TAG_MESSAGE
, CustomTraceDefinition
.TAG_OTHER
});
963 tagCombo
.setVisibleItemCount(tagCombo
.getItemCount());
964 tagCombo
.addSelectionListener(new SelectionListener() {
966 public void widgetDefaultSelected(SelectionEvent e
) {
970 public void widgetSelected(SelectionEvent e
) {
971 tagText
.removeModifyListener(updateListener
);
972 switch (tagCombo
.getSelectionIndex()) {
974 tagLabel
.setVisible(false);
975 tagText
.setVisible(false);
976 actionCombo
.setVisible(false);
978 case 1: // Time Stamp
979 tagLabel
.setText(Messages
.CustomXmlParserInputWizardPage_format
);
980 tagLabel
.setVisible(true);
981 tagText
.setVisible(true);
982 tagText
.addModifyListener(updateListener
);
983 actionCombo
.setVisible(true);
986 tagLabel
.setVisible(false);
987 tagText
.setVisible(false);
988 actionCombo
.setVisible(true);
991 tagLabel
.setText(Messages
.CustomXmlParserInputWizardPage_tagName
);
992 tagLabel
.setVisible(true);
993 if (tagText
.getText().trim().length() == 0) {
994 tagText
.setText(elementNameText
.getText().trim());
996 tagText
.setVisible(true);
997 tagText
.addModifyListener(updateListener
);
998 actionCombo
.setVisible(true);
1003 tagComposite
.layout();
1009 tagLabel
= new Label(tagComposite
, SWT
.NULL
);
1010 tagLabel
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
1012 tagText
= new Text(tagComposite
, SWT
.BORDER
| SWT
.SINGLE
);
1013 gd
= new GridData(SWT
.FILL
, SWT
.CENTER
, true, false);
1015 tagText
.setLayoutData(gd
);
1017 actionCombo
= new Combo(tagComposite
, SWT
.DROP_DOWN
| SWT
.READ_ONLY
);
1018 actionCombo
.setItems(new String
[] { Messages
.CustomXmlParserInputWizardPage_set
, Messages
.CustomXmlParserInputWizardPage_append
,
1019 Messages
.CustomXmlParserInputWizardPage_appendWith
});
1020 actionCombo
.select(inputElement
.inputAction
);
1021 actionCombo
.addSelectionListener(updateListener
);
1023 if (inputElement
.inputName
.equals(CustomXmlTraceDefinition
.TAG_IGNORE
)) {
1025 tagLabel
.setVisible(false);
1026 tagText
.setVisible(false);
1027 actionCombo
.setVisible(false);
1028 } else if (inputElement
.inputName
.equals(CustomTraceDefinition
.TAG_TIMESTAMP
)) {
1030 tagLabel
.setText(Messages
.CustomXmlParserInputWizardPage_format
);
1031 tagText
.setText(inputElement
.inputFormat
);
1032 tagText
.addModifyListener(updateListener
);
1033 } else if (inputElement
.inputName
.equals(CustomTraceDefinition
.TAG_MESSAGE
)) {
1035 tagLabel
.setVisible(false);
1036 tagText
.setVisible(false);
1039 tagLabel
.setText(Messages
.CustomXmlParserInputWizardPage_tagName
);
1040 tagText
.setText(inputElement
.inputName
);
1041 tagText
.addModifyListener(updateListener
);
1045 if (inputElement
.attributes
!= null) {
1046 for (InputAttribute inputAttribute
: inputElement
.attributes
) {
1047 Attribute attribute
= new Attribute(group
, this, inputAttribute
, attributes
.size() + 1);
1048 attributes
.add(attribute
);
1055 private void updatePreview() {
1056 Element element
= getPreviewElement(inputElement
);
1057 if (inputElement
.parentElement
!= null) { // no preview text for
1059 previewText
.setText(Messages
.CustomXmlParserInputWizardPage_noMatchingElement
);
1060 if (element
!= null) {
1061 previewText
.setText(CustomXmlTrace
.parseElement(element
, new StringBuffer()).toString());
1062 if (logEntryButton
.getSelection()) {
1063 if (!logEntryFound
) {
1064 logEntryFound
= true;
1067 logEntryButton
.setSelection(false); // remove nested
1071 if (tagCombo
.getText().equals(CustomTraceDefinition
.TAG_TIMESTAMP
) && logEntriesCount
<= 1) {
1072 String value
= previewText
.getText().trim();
1073 if (value
.length() != 0) {
1074 if (actionCombo
.getSelectionIndex() == CustomTraceDefinition
.ACTION_SET
) {
1075 timeStampValue
= value
;
1076 timeStampFormat
= tagText
.getText().trim();
1077 } else if (actionCombo
.getSelectionIndex() == CustomTraceDefinition
.ACTION_APPEND
) {
1078 if (timeStampValue
!= null) {
1079 timeStampValue
+= value
;
1080 timeStampFormat
+= tagText
.getText().trim();
1082 timeStampValue
= value
;
1083 timeStampFormat
= tagText
.getText().trim();
1085 } else if (actionCombo
.getSelectionIndex() == CustomTraceDefinition
.ACTION_APPEND_WITH_SEPARATOR
) {
1086 if (timeStampValue
!= null) {
1087 timeStampValue
+= " | " + value
; //$NON-NLS-1$
1088 timeStampFormat
+= " | " + tagText
.getText().trim(); //$NON-NLS-1$
1090 timeStampValue
= value
;
1091 timeStampFormat
= tagText
.getText().trim();
1098 for (Attribute attribute
: attributes
) {
1099 if (element
!= null) {
1100 String value
= element
.getAttribute(attribute
.attributeNameText
.getText().trim());
1101 if (value
.length() != 0) {
1102 attribute
.previewText
.setText(value
);
1103 if (attribute
.tagCombo
.getText().equals(CustomTraceDefinition
.TAG_TIMESTAMP
) && logEntriesCount
<= 1) {
1104 if (attribute
.actionCombo
.getSelectionIndex() == CustomTraceDefinition
.ACTION_SET
) {
1105 timeStampValue
= value
;
1106 timeStampFormat
= attribute
.tagText
.getText().trim();
1107 } else if (attribute
.actionCombo
.getSelectionIndex() == CustomTraceDefinition
.ACTION_APPEND
) {
1108 if (timeStampValue
!= null) {
1109 timeStampValue
+= value
;
1110 timeStampFormat
+= attribute
.tagText
.getText().trim();
1112 timeStampValue
= value
;
1113 timeStampFormat
= attribute
.tagText
.getText().trim();
1115 } else if (attribute
.actionCombo
.getSelectionIndex() == CustomTraceDefinition
.ACTION_APPEND_WITH_SEPARATOR
) {
1116 if (timeStampValue
!= null) {
1117 timeStampValue
+= " | " + value
; //$NON-NLS-1$
1118 timeStampFormat
+= " | " + attribute
.tagText
.getText().trim(); //$NON-NLS-1$
1120 timeStampValue
= value
;
1121 timeStampFormat
= attribute
.tagText
.getText().trim();
1126 attribute
.previewText
.setText(Messages
.CustomXmlParserInputWizardPage_noMatchingAttribute
);
1129 attribute
.previewText
.setText(Messages
.CustomXmlParserInputWizardPage_noMatchingElement
);
1132 for (ElementNode child
: childElements
) {
1133 child
.updatePreview();
1135 if (logEntryButton
!= null && logEntryButton
.getSelection()) {
1136 logEntryFound
= false;
1140 private void createAddButton() {
1141 fillerLabel
= new Label(group
, SWT
.NONE
);
1143 addAttributeComposite
= new Composite(group
, SWT
.NONE
);
1144 addAttributeComposite
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
1145 GridLayout addAttributeLayout
= new GridLayout(2, false);
1146 addAttributeLayout
.marginHeight
= 0;
1147 addAttributeLayout
.marginWidth
= 0;
1148 addAttributeComposite
.setLayout(addAttributeLayout
);
1150 addAttributeButton
= new Button(addAttributeComposite
, SWT
.PUSH
);
1151 addAttributeButton
.setImage(ADD_IMAGE
);
1152 addAttributeButton
.setToolTipText(Messages
.CustomXmlParserInputWizardPage_addAttribute
);
1153 addAttributeButton
.addSelectionListener(new SelectionAdapter() {
1155 public void widgetSelected(SelectionEvent e
) {
1157 String attributeName
= getAttributeNameSuggestion(inputElement
);
1158 InputAttribute inputAttribute
= new InputAttribute(attributeName
, attributeName
, 0, ""); //$NON-NLS-1$
1159 attributes
.add(new Attribute(group
, ElementNode
.this, inputAttribute
, attributes
.size() + 1));
1161 elementContainer
.layout();
1162 elementScrolledComposite
.setMinSize(elementContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).x
,
1163 elementContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).y
- 1);
1164 group
.getParent().layout();
1170 addAttributeLabel
= new Label(addAttributeComposite
, SWT
.NULL
);
1171 addAttributeLabel
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
1172 addAttributeLabel
.setText(Messages
.CustomXmlParserInputWizardPage_newAttibute
);
1175 private void removeAddButton() {
1176 fillerLabel
.dispose();
1177 addAttributeComposite
.dispose();
1180 private void removeAttribute(int attributeNumber
) {
1181 int nb
= attributeNumber
;
1182 if (--nb
< attributes
.size()) {
1183 attributes
.remove(nb
).dispose();
1184 for (int i
= nb
; i
< attributes
.size(); i
++) {
1185 attributes
.get(i
).setAttributeNumber(i
+ 1);
1187 elementContainer
.layout();
1188 elementScrolledComposite
.setMinSize(elementContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).x
,
1189 elementContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).y
- 1);
1190 group
.getParent().layout();
1194 private void dispose() {
1198 private void extractInputs() {
1199 inputElement
.elementName
= elementNameText
.getText().trim();
1200 if (inputElement
.parentElement
!= null) {
1201 inputElement
.logEntry
= logEntryButton
.getSelection();
1202 if (tagCombo
.getText().equals(CustomTraceDefinition
.TAG_OTHER
)) {
1203 inputElement
.inputName
= tagText
.getText().trim();
1205 inputElement
.inputName
= tagCombo
.getText();
1206 if (tagCombo
.getText().equals(CustomTraceDefinition
.TAG_TIMESTAMP
)) {
1207 inputElement
.inputFormat
= tagText
.getText().trim();
1210 inputElement
.inputAction
= actionCombo
.getSelectionIndex();
1212 inputElement
.attributes
= new ArrayList
<>(attributes
.size());
1213 for (int i
= 0; i
< attributes
.size(); i
++) {
1214 Attribute attribute
= attributes
.get(i
);
1215 InputAttribute inputAttribute
= new InputAttribute();
1216 inputAttribute
.attributeName
= attribute
.attributeNameText
.getText().trim();
1217 if (attribute
.tagCombo
.getText().equals(CustomTraceDefinition
.TAG_OTHER
)) {
1218 inputAttribute
.inputName
= attribute
.tagText
.getText().trim();
1220 inputAttribute
.inputName
= attribute
.tagCombo
.getText();
1221 if (attribute
.tagCombo
.getText().equals(CustomTraceDefinition
.TAG_TIMESTAMP
)) {
1222 inputAttribute
.inputFormat
= attribute
.tagText
.getText().trim();
1225 inputAttribute
.inputAction
= attribute
.actionCombo
.getSelectionIndex();
1226 inputElement
.addAttribute(inputAttribute
);
1231 private class Attribute
{
1232 private ElementNode element
;
1233 private int attributeNumber
;
1235 // children of parent (must be disposed)
1236 private Composite labelComposite
;
1237 private Composite attributeComposite
;
1238 private Label filler
;
1239 private Composite tagComposite
;
1241 // children of labelComposite
1242 private Label attributeLabel
;
1244 // children of attributeComposite
1245 private Text attributeNameText
;
1246 private Text previewText
;
1248 // children of tagComposite
1249 private Combo tagCombo
;
1250 private Label tagLabel
;
1251 private Text tagText
;
1252 private Combo actionCombo
;
1254 public Attribute(Composite parent
, ElementNode element
, InputAttribute inputAttribute
, int attributeNumber
) {
1255 this.element
= element
;
1256 this.attributeNumber
= attributeNumber
;
1258 labelComposite
= new Composite(parent
, SWT
.FILL
);
1259 GridLayout labelLayout
= new GridLayout(2, false);
1260 labelLayout
.marginWidth
= 0;
1261 labelLayout
.marginHeight
= 0;
1262 labelComposite
.setLayout(labelLayout
);
1263 labelComposite
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
1265 Button deleteButton
= new Button(labelComposite
, SWT
.PUSH
);
1266 deleteButton
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
1267 deleteButton
.setImage(DELETE_IMAGE
);
1268 deleteButton
.setToolTipText(Messages
.CustomXmlParserInputWizardPage_removeAttribute
);
1269 deleteButton
.addSelectionListener(new SelectionAdapter() {
1271 public void widgetSelected(SelectionEvent e
) {
1272 Attribute
.this.element
.removeAttribute(Attribute
.this.attributeNumber
);
1278 attributeLabel
= new Label(labelComposite
, SWT
.NULL
);
1279 attributeLabel
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
1280 attributeLabel
.setText(Messages
.CustomXmlParserInputWizardPage_attibute
);
1282 attributeComposite
= new Composite(parent
, SWT
.FILL
);
1283 GridLayout attributeLayout
= new GridLayout(4, false);
1284 attributeLayout
.marginWidth
= 0;
1285 attributeLayout
.marginHeight
= 0;
1286 attributeComposite
.setLayout(attributeLayout
);
1287 attributeComposite
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
1289 Label nameLabel
= new Label(attributeComposite
, SWT
.NONE
);
1290 nameLabel
.setText(Messages
.CustomXmlParserInputWizardPage_name
);
1292 attributeNameText
= new Text(attributeComposite
, SWT
.BORDER
| SWT
.SINGLE
);
1293 attributeNameText
.setLayoutData(new GridData(120, SWT
.DEFAULT
));
1294 attributeNameText
.setText(inputAttribute
.attributeName
);
1295 attributeNameText
.addModifyListener(updateListener
);
1297 Label previewLabel
= new Label(attributeComposite
, SWT
.NONE
);
1298 previewLabel
.setText(Messages
.CustomXmlParserInputWizardPage_preview
);
1300 previewText
= new Text(attributeComposite
, SWT
.BORDER
| SWT
.SINGLE
| SWT
.READ_ONLY
);
1301 GridData gd
= new GridData(SWT
.FILL
, SWT
.CENTER
, true, false);
1303 previewText
.setLayoutData(gd
);
1304 previewText
.setText(Messages
.CustomXmlParserInputWizardPage_noMatch
);
1305 previewText
.setBackground(COLOR_WIDGET_BACKGROUND
);
1307 filler
= new Label(parent
, SWT
.NULL
);
1309 tagComposite
= new Composite(parent
, SWT
.FILL
);
1310 GridLayout tagLayout
= new GridLayout(4, false);
1311 tagLayout
.marginWidth
= 0;
1312 tagLayout
.marginHeight
= 0;
1313 tagComposite
.setLayout(tagLayout
);
1314 tagComposite
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
1316 tagCombo
= new Combo(tagComposite
, SWT
.DROP_DOWN
| SWT
.READ_ONLY
);
1317 tagCombo
.setItems(new String
[] { CustomTraceDefinition
.TAG_TIMESTAMP
, CustomTraceDefinition
.TAG_MESSAGE
,
1318 CustomTraceDefinition
.TAG_OTHER
});
1319 tagCombo
.select(2); // Other
1320 tagCombo
.addSelectionListener(new SelectionListener() {
1322 public void widgetDefaultSelected(SelectionEvent e
) {
1326 public void widgetSelected(SelectionEvent e
) {
1327 tagText
.removeModifyListener(updateListener
);
1328 switch (tagCombo
.getSelectionIndex()) {
1329 case 0: // Time Stamp
1330 tagLabel
.setText(Messages
.CustomXmlParserInputWizardPage_format
);
1331 tagLabel
.setVisible(true);
1332 tagText
.setVisible(true);
1333 tagText
.addModifyListener(updateListener
);
1336 tagLabel
.setVisible(false);
1337 tagText
.setVisible(false);
1340 tagLabel
.setText(Messages
.CustomXmlParserInputWizardPage_tagName
);
1341 tagLabel
.setVisible(true);
1342 if (tagText
.getText().trim().length() == 0) {
1343 tagText
.setText(attributeNameText
.getText().trim());
1345 tagText
.setVisible(true);
1346 tagText
.addModifyListener(updateListener
);
1351 tagComposite
.layout();
1357 tagLabel
= new Label(tagComposite
, SWT
.NULL
);
1358 tagLabel
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
1360 tagText
= new Text(tagComposite
, SWT
.BORDER
| SWT
.SINGLE
);
1361 gd
= new GridData(SWT
.FILL
, SWT
.CENTER
, true, false);
1363 tagText
.setLayoutData(gd
);
1364 tagText
.setText(attributeNameText
.getText());
1366 actionCombo
= new Combo(tagComposite
, SWT
.DROP_DOWN
| SWT
.READ_ONLY
);
1367 actionCombo
.setItems(new String
[] { Messages
.CustomXmlParserInputWizardPage_set
, Messages
.CustomXmlParserInputWizardPage_append
,
1368 Messages
.CustomXmlParserInputWizardPage_appendWith
});
1369 actionCombo
.select(inputAttribute
.inputAction
);
1370 actionCombo
.addSelectionListener(updateListener
);
1372 if (inputAttribute
.inputName
.equals(CustomTraceDefinition
.TAG_TIMESTAMP
)) {
1374 tagLabel
.setText(Messages
.CustomXmlParserInputWizardPage_format
);
1375 tagText
.setText(inputAttribute
.inputFormat
);
1376 tagText
.addModifyListener(updateListener
);
1377 } else if (inputAttribute
.inputName
.equals(CustomTraceDefinition
.TAG_MESSAGE
)) {
1379 tagLabel
.setVisible(false);
1380 tagText
.setVisible(false);
1383 tagLabel
.setText(Messages
.CustomXmlParserInputWizardPage_tagName
);
1384 tagText
.setText(inputAttribute
.inputName
);
1385 tagText
.addModifyListener(updateListener
);
1389 private void dispose() {
1390 labelComposite
.dispose();
1391 attributeComposite
.dispose();
1393 tagComposite
.dispose();
1396 private void setAttributeNumber(int attributeNumber
) {
1397 this.attributeNumber
= attributeNumber
;
1398 labelComposite
.layout();
1402 private Element
getPreviewElement(InputElement inputElement
) {
1403 InputElement currentElement
= inputElement
;
1404 Element element
= documentElement
;
1405 if (element
!= null) {
1406 if (!documentElement
.getNodeName().equals(definition
.rootInputElement
.elementName
)) {
1409 ArrayList
<String
> elementNames
= new ArrayList
<>();
1410 while (currentElement
!= null) {
1411 elementNames
.add(currentElement
.elementName
);
1412 currentElement
= currentElement
.parentElement
;
1414 for (int i
= elementNames
.size() - 1; --i
>= 0;) {
1415 NodeList childList
= element
.getChildNodes();
1417 for (int j
= 0; j
< childList
.getLength(); j
++) {
1418 Node child
= childList
.item(j
);
1419 if (child
instanceof Element
&& child
.getNodeName().equals(elementNames
.get(i
))) {
1420 element
= (Element
) child
;
1424 if (element
== null) {
1428 if (element
!= null) {
1435 private String
getChildNameSuggestion(InputElement inputElement
) {
1436 if (inputElement
== null) {
1437 if (documentElement
!= null) {
1438 return documentElement
.getNodeName();
1441 Element element
= getPreviewElement(inputElement
);
1442 if (element
!= null) {
1443 NodeList childNodes
= element
.getChildNodes();
1444 for (int i
= 0; i
< childNodes
.getLength(); i
++) {
1445 Node node
= childNodes
.item(i
);
1446 if (node
instanceof Element
) {
1447 boolean unused
= true;
1448 if (inputElement
.childElements
!= null) {
1449 for (InputElement child
: inputElement
.childElements
) {
1450 if (child
.elementName
.equals(node
.getNodeName())) {
1457 return node
.getNodeName();
1463 return ""; //$NON-NLS-1$
1466 private String
getAttributeNameSuggestion(InputElement inputElement
) {
1467 Element element
= getPreviewElement(inputElement
);
1468 if (element
!= null) {
1469 NamedNodeMap attributeMap
= element
.getAttributes();
1470 for (int i
= 0; i
< attributeMap
.getLength(); i
++) {
1471 Node node
= attributeMap
.item(i
);
1472 boolean unused
= true;
1473 if (inputElement
.attributes
!= null) {
1474 for (InputAttribute attribute
: inputElement
.attributes
) {
1475 if (attribute
.attributeName
.equals(node
.getNodeName())) {
1482 return node
.getNodeName();
1486 return ""; //$NON-NLS-1$
1489 private void validate() {
1490 definition
.categoryName
= categoryText
.getText().trim();
1491 definition
.definitionName
= logtypeText
.getText().trim();
1492 definition
.timeStampOutputFormat
= timeStampOutputFormatText
.getText().trim();
1494 if (selectedElement
!= null) {
1495 selectedElement
.extractInputs();
1496 treeViewer
.refresh();
1499 List
<String
> errors
= new ArrayList
<>();
1501 if (definition
.categoryName
.length() == 0) {
1502 errors
.add(Messages
.CustomXmlParserInputWizardPage_emptyCategoryError
);
1503 categoryText
.setBackground(COLOR_LIGHT_RED
);
1504 } else if (definition
.definitionName
.length() == 0) {
1505 errors
.add(Messages
.CustomXmlParserInputWizardPage_emptyLogTypeError
);
1506 logtypeText
.setBackground(COLOR_LIGHT_RED
);
1508 categoryText
.setBackground(COLOR_TEXT_BACKGROUND
);
1509 logtypeText
.setBackground(COLOR_TEXT_BACKGROUND
);
1510 if (definition
.categoryName
.indexOf(':') != -1) {
1511 errors
.add(Messages
.CustomXmlParserInputWizardPage_invalidCategoryError
);
1512 categoryText
.setBackground(COLOR_LIGHT_RED
);
1514 if (definition
.definitionName
.indexOf(':') != -1) {
1515 errors
.add(Messages
.CustomXmlParserInputWizardPage_invalidLogTypeError
);
1516 logtypeText
.setBackground(COLOR_LIGHT_RED
);
1518 for (TraceTypeHelper helper
: TmfTraceType
.getTraceTypeHelpers()) {
1519 if (definition
.categoryName
.equals(helper
.getCategoryName()) &&
1520 definition
.definitionName
.equals(helper
.getName()) &&
1521 (editDefinitionName
== null || !editDefinitionName
.equals(definition
.definitionName
)) &&
1522 (editCategoryName
== null || !editCategoryName
.equals(definition
.categoryName
))) {
1523 errors
.add(Messages
.CustomXmlParserInputWizardPage_duplicatelogTypeError
);
1524 logtypeText
.setBackground(COLOR_LIGHT_RED
);
1530 if (definition
.rootInputElement
== null) {
1531 errors
.add(Messages
.CustomXmlParserInputWizardPage_noDocumentError
);
1534 if (definition
.rootInputElement
!= null) {
1535 logEntryFound
= false;
1536 timeStampFound
= false;
1538 errors
.addAll(validateElement(definition
.rootInputElement
));
1540 if ((definition
.rootInputElement
.attributes
!= null && definition
.rootInputElement
.attributes
.size() != 0)
1541 || (definition
.rootInputElement
.childElements
!= null && definition
.rootInputElement
.childElements
.size() != 0)
1542 || errors
.size() == 0) {
1543 if (!logEntryFound
) {
1544 errors
.add(Messages
.CustomXmlParserInputWizardPage_missingLogEntryError
);
1547 if (timeStampFound
) {
1548 if (timeStampOutputFormatText
.getText().trim().length() == 0) {
1549 errors
.add(Messages
.CustomXmlParserInputWizardPage_missingTimestampFmtError
);
1550 timeStampOutputFormatText
.setBackground(COLOR_LIGHT_RED
);
1553 new TmfTimestampFormat(timeStampOutputFormatText
.getText().trim());
1554 timeStampOutputFormatText
.setBackground(COLOR_TEXT_BACKGROUND
);
1555 } catch (IllegalArgumentException e
) {
1556 errors
.add(Messages
.CustomXmlParserInputWizardPage_elementInvalidTimestampFmtError
);
1557 timeStampOutputFormatText
.setBackground(COLOR_LIGHT_RED
);
1561 timeStampPreviewText
.setText(Messages
.CustomXmlParserInputWizardPage_noTimestampElementOrAttribute
);
1565 timeStampPreviewText
.setText(Messages
.CustomXmlParserInputWizardPage_noTimestampElementOrAttribute
);
1568 if (errors
.size() == 0) {
1569 setDescription(defaultDescription
);
1570 setPageComplete(true);
1572 setDescription(Joiner
.on(' ').join(errors
));
1573 setPageComplete(false);
1578 * Clean up the specified XML element.
1580 * @param inputElement
1581 * The element to clean up
1582 * @return The validated element
1584 public List
<String
> validateElement(InputElement inputElement
) {
1585 List
<String
> errors
= new ArrayList
<>();
1586 ElementNode elementNode
= null;
1587 if (selectedElement
!= null && selectedElement
.inputElement
.equals(inputElement
)) {
1588 elementNode
= selectedElement
;
1590 if (inputElement
== definition
.rootInputElement
) {
1591 if (inputElement
.elementName
.length() == 0) {
1592 errors
.add(Messages
.CustomXmlParserInputWizardPage_missingDocumentElementError
);
1593 if (elementNode
!= null) {
1594 elementNode
.elementNameText
.setBackground(COLOR_LIGHT_RED
);
1597 if (elementNode
!= null) {
1598 elementNode
.elementNameText
.setBackground(COLOR_TEXT_BACKGROUND
);
1602 if (inputElement
!= definition
.rootInputElement
) {
1603 if (inputElement
.logEntry
) {
1604 logEntryFound
= true;
1606 if (inputElement
.inputName
.equals(CustomTraceDefinition
.TAG_TIMESTAMP
)) {
1607 timeStampFound
= true;
1608 if (inputElement
.inputFormat
.length() == 0) {
1609 errors
.add(NLS
.bind(Messages
.CustomXmlParserInputWizardPage_elementMissingTimestampFmtError
, getName(inputElement
)));
1610 if (elementNode
!= null) {
1611 elementNode
.tagText
.setBackground(COLOR_LIGHT_RED
);
1615 new TmfTimestampFormat(inputElement
.inputFormat
);
1616 if (elementNode
!= null) {
1617 elementNode
.tagText
.setBackground(COLOR_TEXT_BACKGROUND
);
1619 } catch (IllegalArgumentException e
) {
1620 errors
.add(NLS
.bind(Messages
.CustomXmlParserInputWizardPage_elementInvalidTimestampFmtError
, getName(inputElement
)));
1621 if (elementNode
!= null) {
1622 elementNode
.tagText
.setBackground(COLOR_LIGHT_RED
);
1626 } else if (inputElement
.inputName
.length() == 0) {
1627 errors
.add(NLS
.bind(Messages
.CustomXmlParserInputWizardPage_elementMissingInputNameError
, getName(inputElement
)));
1628 if (elementNode
!= null) {
1629 elementNode
.tagText
.setBackground(COLOR_LIGHT_RED
);
1632 if (elementNode
!= null) {
1633 elementNode
.tagText
.setBackground(COLOR_TEXT_BACKGROUND
);
1637 if (inputElement
.attributes
!= null) {
1638 if (elementNode
!= null) {
1639 for (Attribute attribute
: elementNode
.attributes
) {
1640 attribute
.attributeNameText
.setBackground(COLOR_TEXT_BACKGROUND
);
1643 for (int i
= 0; i
< inputElement
.attributes
.size(); i
++) {
1644 InputAttribute attribute
= inputElement
.attributes
.get(i
);
1645 boolean duplicate
= false;
1646 for (int j
= i
+ 1; j
< inputElement
.attributes
.size(); j
++) {
1647 InputAttribute otherAttribute
= inputElement
.attributes
.get(j
);
1648 if (otherAttribute
.attributeName
.equals(attribute
.attributeName
)) {
1650 if (elementNode
!= null) {
1651 elementNode
.attributes
.get(j
).attributeNameText
.setBackground(COLOR_LIGHT_RED
);
1655 if (attribute
.attributeName
.length() == 0) {
1656 errors
.add(NLS
.bind(Messages
.CustomXmlParserInputWizardPage_attributeMissingNameError
, getName(inputElement
)));
1657 if (elementNode
!= null) {
1658 elementNode
.attributes
.get(i
).attributeNameText
.setBackground(COLOR_LIGHT_RED
);
1660 } else if (duplicate
) {
1661 errors
.add(NLS
.bind(Messages
.CustomXmlParserInputWizardPage_attributeDuplicateNameError
, getName(attribute
, inputElement
)));
1662 if (elementNode
!= null) {
1663 elementNode
.attributes
.get(i
).attributeNameText
.setBackground(COLOR_LIGHT_RED
);
1666 if (attribute
.inputName
.equals(CustomTraceDefinition
.TAG_TIMESTAMP
)) {
1667 timeStampFound
= true;
1668 if (attribute
.inputFormat
.length() == 0) {
1669 errors
.add(NLS
.bind(Messages
.CustomXmlParserInputWizardPage_attributeMissingTimestampFmtError
, getName(attribute
, inputElement
)));
1670 if (elementNode
!= null) {
1671 elementNode
.attributes
.get(i
).tagText
.setBackground(COLOR_LIGHT_RED
);
1675 new TmfTimestampFormat(attribute
.inputFormat
);
1676 if (elementNode
!= null) {
1677 elementNode
.attributes
.get(i
).tagText
.setBackground(COLOR_TEXT_BACKGROUND
);
1679 } catch (IllegalArgumentException e
) {
1680 errors
.add(NLS
.bind(Messages
.CustomXmlParserInputWizardPage_attributeInvalidTimestampFmtError
, getName(attribute
, inputElement
)));
1681 if (elementNode
!= null) {
1682 elementNode
.attributes
.get(i
).tagText
.setBackground(COLOR_LIGHT_RED
);
1686 } else if (attribute
.inputName
.length() == 0) {
1687 errors
.add(NLS
.bind(Messages
.CustomXmlParserInputWizardPage_attributeMissingInputNameError
, getName(attribute
, inputElement
)));
1688 if (elementNode
!= null) {
1689 elementNode
.attributes
.get(i
).tagText
.setBackground(COLOR_LIGHT_RED
);
1692 if (elementNode
!= null) {
1693 elementNode
.attributes
.get(i
).tagText
.setBackground(COLOR_TEXT_BACKGROUND
);
1698 if (inputElement
.childElements
!= null) {
1699 for (InputElement child
: inputElement
.childElements
) {
1700 ElementNode childElementNode
= null;
1701 if (selectedElement
!= null && selectedElement
.inputElement
.equals(child
)) {
1702 childElementNode
= selectedElement
;
1704 if (childElementNode
!= null) {
1705 childElementNode
.elementNameText
.setBackground(COLOR_TEXT_BACKGROUND
);
1708 for (int i
= 0; i
< inputElement
.childElements
.size(); i
++) {
1709 InputElement child
= inputElement
.childElements
.get(i
);
1710 ElementNode childElementNode
= null;
1711 if (selectedElement
!= null && selectedElement
.inputElement
.equals(child
)) {
1712 childElementNode
= selectedElement
;
1714 if (child
.elementName
.length() == 0) {
1715 errors
.add(NLS
.bind(Messages
.CustomXmlParserInputWizardPage_elementMissingNameError
, getName(child
)));
1716 if (childElementNode
!= null) {
1717 childElementNode
.elementNameText
.setBackground(COLOR_LIGHT_RED
);
1720 boolean duplicate
= false;
1721 for (int j
= i
+ 1; j
< inputElement
.childElements
.size(); j
++) {
1722 InputElement otherChild
= inputElement
.childElements
.get(j
);
1723 if (otherChild
.elementName
.equals(child
.elementName
)) {
1725 ElementNode otherChildElementNode
= null;
1726 if (selectedElement
!= null && selectedElement
.inputElement
.equals(otherChild
)) {
1727 otherChildElementNode
= selectedElement
;
1729 if (otherChildElementNode
!= null) {
1730 otherChildElementNode
.elementNameText
.setBackground(COLOR_LIGHT_RED
);
1735 errors
.add(NLS
.bind(Messages
.CustomXmlParserInputWizardPage_elementDuplicateNameError
, getName(child
)));
1736 if (childElementNode
!= null) {
1737 childElementNode
.elementNameText
.setBackground(COLOR_LIGHT_RED
);
1742 errors
.addAll(validateElement(child
));
1749 * Get the trace definition.
1751 * @return The trace definition
1753 public CustomXmlTraceDefinition
getDefinition() {
1758 * Get the raw text input.
1760 * @return The raw text input.
1762 public char[] getInputText() {
1763 return inputText
.getText().toCharArray();