1 package org
.eclipse
.linuxtools
.tmf
.ui
.parsers
.wizards
;
3 import java
.io
.BufferedReader
;
4 import java
.io
.ByteArrayInputStream
;
5 import java
.io
.IOException
;
6 import java
.io
.InputStream
;
7 import java
.io
.InputStreamReader
;
8 import java
.text
.ParseException
;
9 import java
.text
.SimpleDateFormat
;
10 import java
.util
.ArrayList
;
11 import java
.util
.Date
;
12 import java
.util
.List
;
14 import javax
.xml
.parsers
.DocumentBuilder
;
15 import javax
.xml
.parsers
.DocumentBuilderFactory
;
16 import javax
.xml
.parsers
.ParserConfigurationException
;
18 import org
.eclipse
.core
.resources
.IFile
;
19 import org
.eclipse
.core
.runtime
.CoreException
;
20 import org
.eclipse
.jface
.viewers
.ColumnLabelProvider
;
21 import org
.eclipse
.jface
.viewers
.ISelection
;
22 import org
.eclipse
.jface
.viewers
.ISelectionChangedListener
;
23 import org
.eclipse
.jface
.viewers
.IStructuredSelection
;
24 import org
.eclipse
.jface
.viewers
.ITreeContentProvider
;
25 import org
.eclipse
.jface
.viewers
.SelectionChangedEvent
;
26 import org
.eclipse
.jface
.viewers
.StructuredSelection
;
27 import org
.eclipse
.jface
.viewers
.TreeViewer
;
28 import org
.eclipse
.jface
.viewers
.Viewer
;
29 import org
.eclipse
.jface
.wizard
.WizardPage
;
30 import org
.eclipse
.linuxtools
.tmf
.ui
.TmfUiPlugin
;
31 import org
.eclipse
.linuxtools
.tmf
.ui
.internal
.Messages
;
32 import org
.eclipse
.linuxtools
.tmf
.ui
.parsers
.custom
.CustomXmlTrace
;
33 import org
.eclipse
.linuxtools
.tmf
.ui
.parsers
.custom
.CustomXmlTraceDefinition
;
34 import org
.eclipse
.linuxtools
.tmf
.ui
.parsers
.custom
.CustomXmlTraceDefinition
.InputAttribute
;
35 import org
.eclipse
.linuxtools
.tmf
.ui
.parsers
.custom
.CustomXmlTraceDefinition
.InputElement
;
36 import org
.eclipse
.swt
.SWT
;
37 import org
.eclipse
.swt
.browser
.Browser
;
38 import org
.eclipse
.swt
.browser
.TitleEvent
;
39 import org
.eclipse
.swt
.browser
.TitleListener
;
40 import org
.eclipse
.swt
.custom
.SashForm
;
41 import org
.eclipse
.swt
.custom
.ScrolledComposite
;
42 import org
.eclipse
.swt
.custom
.StyleRange
;
43 import org
.eclipse
.swt
.custom
.StyledText
;
44 import org
.eclipse
.swt
.events
.ModifyEvent
;
45 import org
.eclipse
.swt
.events
.ModifyListener
;
46 import org
.eclipse
.swt
.events
.SelectionAdapter
;
47 import org
.eclipse
.swt
.events
.SelectionEvent
;
48 import org
.eclipse
.swt
.events
.SelectionListener
;
49 import org
.eclipse
.swt
.graphics
.Color
;
50 import org
.eclipse
.swt
.graphics
.Font
;
51 import org
.eclipse
.swt
.graphics
.FontData
;
52 import org
.eclipse
.swt
.graphics
.Image
;
53 import org
.eclipse
.swt
.layout
.FillLayout
;
54 import org
.eclipse
.swt
.layout
.GridData
;
55 import org
.eclipse
.swt
.layout
.GridLayout
;
56 import org
.eclipse
.swt
.widgets
.Button
;
57 import org
.eclipse
.swt
.widgets
.Combo
;
58 import org
.eclipse
.swt
.widgets
.Composite
;
59 import org
.eclipse
.swt
.widgets
.Display
;
60 import org
.eclipse
.swt
.widgets
.Group
;
61 import org
.eclipse
.swt
.widgets
.Label
;
62 import org
.eclipse
.swt
.widgets
.Shell
;
63 import org
.eclipse
.swt
.widgets
.Text
;
64 import org
.w3c
.dom
.Document
;
65 import org
.w3c
.dom
.Element
;
66 import org
.w3c
.dom
.NamedNodeMap
;
67 import org
.w3c
.dom
.Node
;
68 import org
.w3c
.dom
.NodeList
;
69 import org
.xml
.sax
.EntityResolver
;
70 import org
.xml
.sax
.ErrorHandler
;
71 import org
.xml
.sax
.InputSource
;
72 import org
.xml
.sax
.SAXException
;
73 import org
.xml
.sax
.SAXParseException
;
75 public class CustomXmlParserInputWizardPage
extends WizardPage
{
77 private static final String DEFAULT_TIMESTAMP_FORMAT
= "yyyy-MM-dd HH:mm:ss.SSS"; //$NON-NLS-1$
78 private static final String SIMPLE_DATE_FORMAT_URL
= "http://java.sun.com/javase/6/docs/api/java/text/SimpleDateFormat.html#skip-navbar_top"; //$NON-NLS-1$
79 private static final Image elementImage
= TmfUiPlugin
.getDefault().getImageFromPath("/icons/elcl16/element_icon.gif"); //$NON-NLS-1$
80 private static final Image addImage
= TmfUiPlugin
.getDefault().getImageFromPath("/icons/elcl16/add_button.gif"); //$NON-NLS-1$
81 private static final Image addNextImage
= TmfUiPlugin
.getDefault().getImageFromPath("/icons/elcl16/addnext_button.gif"); //$NON-NLS-1$
82 private static final Image addChildImage
= TmfUiPlugin
.getDefault().getImageFromPath("/icons/elcl16/addchild_button.gif"); //$NON-NLS-1$
83 private static final Image addManyImage
= TmfUiPlugin
.getDefault().getImageFromPath("/icons/elcl16/addmany_button.gif"); //$NON-NLS-1$
84 private static final Image deleteImage
= TmfUiPlugin
.getDefault().getImageFromPath("/icons/elcl16/delete_button.gif"); //$NON-NLS-1$
85 private static final Image moveUpImage
= TmfUiPlugin
.getDefault().getImageFromPath("/icons/elcl16/moveup_button.gif"); //$NON-NLS-1$
86 private static final Image moveDownImage
= TmfUiPlugin
.getDefault().getImageFromPath("/icons/elcl16/movedown_button.gif"); //$NON-NLS-1$
87 private static final Image helpImage
= TmfUiPlugin
.getDefault().getImageFromPath("/icons/elcl16/help_button.gif"); //$NON-NLS-1$
88 private static final Color COLOR_LIGHT_RED
= new Color(Display
.getDefault(), 255, 192, 192);
89 private static final Color COLOR_TEXT_BACKGROUND
= Display
.getCurrent().getSystemColor(SWT
.COLOR_WHITE
);
90 private static final Color COLOR_WIDGET_BACKGROUND
= Display
.getCurrent().getSystemColor(SWT
.COLOR_WIDGET_BACKGROUND
);
92 private final ISelection selection
;
93 private CustomXmlTraceDefinition definition
;
94 private String editDefinitionName
;
95 private String defaultDescription
;
96 private ElementNode selectedElement
;
97 private Composite container
;
98 private Text logtypeText
;
99 private Text timeStampOutputFormatText
;
100 private Text timeStampPreviewText
;
101 private Button removeButton
;
102 private Button addChildButton
;
103 private Button addNextButton
;
104 private Button moveUpButton
;
105 private Button moveDownButton
;
106 private Button feelingLuckyButton
;
107 private ScrolledComposite treeScrolledComposite
;
108 private ScrolledComposite elementScrolledComposite
;
109 private TreeViewer treeViewer
;
110 private Composite treeContainer
;
111 private Composite elementContainer
;
112 private Text errorText
;
113 private StyledText inputText
;
114 private Font fixedFont
;
115 private UpdateListener updateListener
;
116 private Browser helpBrowser
;
117 private Element documentElement
;
119 // variables used recursively through element traversal
120 private String timeStampValue
;
121 private String timeStampFormat
;
122 private boolean timeStampFound
;
123 private int logEntriesCount
;
124 private boolean logEntryFound
;
125 private int logEntryNestedCount
;
127 protected CustomXmlParserInputWizardPage(ISelection selection
, CustomXmlTraceDefinition definition
) {
128 super("CustomXmlParserWizardPage"); //$NON-NLS-1$
129 if (definition
== null) {
130 setTitle(Messages
.CustomXmlParserInputWizardPage_titleNew
);
131 defaultDescription
= Messages
.CustomXmlParserInputWizardPage_descriptionNew
;
133 setTitle(Messages
.CustomXmlParserInputWizardPage_titleEdit
);
134 defaultDescription
= Messages
.CustomXmlParserInputWizardPage_descriptionEdit
;
136 setDescription(defaultDescription
);
137 this.selection
= selection
;
138 this.definition
= definition
;
139 if (definition
!= null) {
140 this.editDefinitionName
= definition
.definitionName
;
145 public void createControl(Composite parent
) {
146 container
= new Composite(parent
, SWT
.NULL
);
147 container
.setLayout(new GridLayout());
149 updateListener
= new UpdateListener();
151 Composite headerComposite
= new Composite(container
, SWT
.FILL
);
152 GridLayout headerLayout
= new GridLayout(5, false);
153 headerLayout
.marginHeight
= 0;
154 headerLayout
.marginWidth
= 0;
155 headerComposite
.setLayout(headerLayout
);
156 headerComposite
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
158 Label logtypeLabel
= new Label(headerComposite
, SWT
.NULL
);
159 logtypeLabel
.setText(Messages
.CustomXmlParserInputWizardPage_logType
);
161 logtypeText
= new Text(headerComposite
, SWT
.BORDER
| SWT
.SINGLE
);
162 logtypeText
.setLayoutData(new GridData(120, SWT
.DEFAULT
));
164 Label timeStampFormatLabel
= new Label(headerComposite
, SWT
.NULL
);
165 timeStampFormatLabel
.setText(Messages
.CustomXmlParserInputWizardPage_timestampFormat
);
167 timeStampOutputFormatText
= new Text(headerComposite
, SWT
.BORDER
| SWT
.SINGLE
);
168 timeStampOutputFormatText
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
169 timeStampOutputFormatText
.setText(DEFAULT_TIMESTAMP_FORMAT
);
171 Button dateFormatHelpButton
= new Button(headerComposite
, SWT
.PUSH
);
172 dateFormatHelpButton
.setImage(helpImage
);
173 dateFormatHelpButton
.setToolTipText(Messages
.CustomXmlParserInputWizardPage_dateFormatHelp
);
174 dateFormatHelpButton
.addSelectionListener(new SelectionAdapter() {
176 public void widgetSelected(SelectionEvent e
) {
177 openHelpShell(SIMPLE_DATE_FORMAT_URL
);
181 Label timeStampPreviewLabel
= new Label(headerComposite
, SWT
.NULL
);
182 timeStampPreviewLabel
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false, 3, 1));
183 timeStampPreviewLabel
.setText(Messages
.CustomXmlParserInputWizardPage_preview
);
185 timeStampPreviewText
= new Text(headerComposite
, SWT
.BORDER
| SWT
.SINGLE
| SWT
.READ_ONLY
);
186 timeStampPreviewText
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false, 2, 1));
187 timeStampPreviewText
.setText("*no time stamp element or attribute*"); //$NON-NLS-1$
191 SashForm vSash
= new SashForm(container
, SWT
.VERTICAL
);
192 vSash
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
193 vSash
.setBackground(vSash
.getDisplay().getSystemColor(SWT
.COLOR_GRAY
));
195 SashForm hSash
= new SashForm(vSash
, SWT
.HORIZONTAL
);
196 hSash
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
198 treeScrolledComposite
= new ScrolledComposite(hSash
, SWT
.V_SCROLL
| SWT
.H_SCROLL
);
199 treeScrolledComposite
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
200 treeContainer
= new Composite(treeScrolledComposite
, SWT
.NONE
);
201 treeContainer
.setLayout(new FillLayout());
202 treeScrolledComposite
.setContent(treeContainer
);
203 treeScrolledComposite
.setExpandHorizontal(true);
204 treeScrolledComposite
.setExpandVertical(true);
206 treeViewer
= new TreeViewer(treeContainer
, SWT
.SINGLE
| SWT
.BORDER
);
207 treeViewer
.setContentProvider(new InputElementTreeNodeContentProvider());
208 treeViewer
.setLabelProvider(new InputElementTreeLabelProvider());
209 treeViewer
.addSelectionChangedListener(new InputElementTreeSelectionChangedListener());
210 treeContainer
.layout();
212 treeScrolledComposite
213 .setMinSize(treeContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).x
, treeContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).y
);
215 elementScrolledComposite
= new ScrolledComposite(hSash
, SWT
.V_SCROLL
);
216 elementScrolledComposite
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
217 elementContainer
= new Composite(elementScrolledComposite
, SWT
.NONE
);
218 GridLayout gl
= new GridLayout();
221 elementContainer
.setLayout(gl
);
222 elementScrolledComposite
.setContent(elementContainer
);
223 elementScrolledComposite
.setExpandHorizontal(true);
224 elementScrolledComposite
.setExpandVertical(true);
226 if (definition
== null) {
227 definition
= new CustomXmlTraceDefinition();
229 loadDefinition(definition
);
230 treeViewer
.expandAll();
231 elementContainer
.layout();
233 logtypeText
.addModifyListener(updateListener
);
234 timeStampOutputFormatText
.addModifyListener(updateListener
);
236 elementScrolledComposite
.setMinSize(elementContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).x
,
237 elementContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).y
- 1);
239 hSash
.setWeights(new int[] { 1, 2 });
241 if (definition
.rootInputElement
== null) {
242 removeButton
.setEnabled(false);
243 addChildButton
.setToolTipText(Messages
.CustomXmlParserInputWizardPage_addDocumentElement
);
244 addNextButton
.setEnabled(false);
245 moveUpButton
.setEnabled(false);
246 moveDownButton
.setEnabled(false);
247 } else { // root is selected
248 addNextButton
.setEnabled(false);
251 Composite sashBottom
= new Composite(vSash
, SWT
.NONE
);
252 GridLayout sashBottomLayout
= new GridLayout(2, false);
253 sashBottomLayout
.marginHeight
= 0;
254 sashBottomLayout
.marginWidth
= 0;
255 sashBottom
.setLayout(sashBottomLayout
);
257 Label previewLabel
= new Label(sashBottom
, SWT
.NULL
);
258 previewLabel
.setText(Messages
.CustomXmlParserInputWizardPage_previewInput
);
260 errorText
= new Text(sashBottom
, SWT
.SINGLE
| SWT
.READ_ONLY
);
261 errorText
.setBackground(COLOR_WIDGET_BACKGROUND
);
262 errorText
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
263 errorText
.setVisible(false);
265 inputText
= new StyledText(sashBottom
, SWT
.MULTI
| SWT
.V_SCROLL
| SWT
.H_SCROLL
);
266 if (fixedFont
== null) {
267 if (System
.getProperty("os.name").contains("Windows")) { //$NON-NLS-1$ //$NON-NLS-2$
268 fixedFont
= new Font(Display
.getCurrent(), new FontData("Courier New", 10, SWT
.NORMAL
)); //$NON-NLS-1$
270 fixedFont
= new Font(Display
.getCurrent(), new FontData("Monospace", 10, SWT
.NORMAL
)); //$NON-NLS-1$
273 inputText
.setFont(fixedFont
);
274 GridData gd
= new GridData(SWT
.FILL
, SWT
.FILL
, true, true, 2, 1);
275 gd
.heightHint
= inputText
.computeSize(SWT
.DEFAULT
, inputText
.getLineHeight() * 4).y
;
277 inputText
.setLayoutData(gd
);
278 inputText
.setText(getSelectionText());
279 inputText
.addModifyListener(new ModifyListener() {
281 public void modifyText(ModifyEvent e
) {
282 parseXmlInput(inputText
.getText());
285 inputText
.addModifyListener(updateListener
);
287 vSash
.setWeights(new int[] { hSash
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).y
, sashBottom
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).y
});
289 setControl(container
);
292 private void createButtonBar() {
293 Composite buttonBar
= new Composite(container
, SWT
.NONE
);
294 GridLayout buttonBarLayout
= new GridLayout(6, false);
295 buttonBarLayout
.marginHeight
= 0;
296 buttonBarLayout
.marginWidth
= 0;
297 buttonBar
.setLayout(buttonBarLayout
);
299 removeButton
= new Button(buttonBar
, SWT
.PUSH
);
300 removeButton
.setImage(deleteImage
);
301 removeButton
.setToolTipText(Messages
.CustomXmlParserInputWizardPage_removeElement
);
302 removeButton
.addSelectionListener(new SelectionAdapter() {
304 public void widgetSelected(SelectionEvent e
) {
305 if (treeViewer
.getSelection().isEmpty() || selectedElement
== null)
308 InputElement inputElement
= (InputElement
) ((IStructuredSelection
) treeViewer
.getSelection()).getFirstElement();
309 if (inputElement
== definition
.rootInputElement
) {
310 definition
.rootInputElement
= null;
312 inputElement
.parentElement
.childElements
.remove(inputElement
);
314 treeViewer
.refresh();
317 removeButton
.setEnabled(false);
318 if (definition
.rootInputElement
== null) {
319 addChildButton
.setEnabled(true);
320 addChildButton
.setToolTipText(Messages
.CustomXmlParserInputWizardPage_addDocumentEleemnt
);
322 addChildButton
.setEnabled(false);
324 addNextButton
.setEnabled(false);
325 moveUpButton
.setEnabled(false);
326 moveDownButton
.setEnabled(false);
330 addChildButton
= new Button(buttonBar
, SWT
.PUSH
);
331 addChildButton
.setImage(addChildImage
);
332 addChildButton
.setToolTipText(Messages
.CustomXmlParserInputWizardPage_addChildElement
);
333 addChildButton
.addSelectionListener(new SelectionAdapter() {
335 public void widgetSelected(SelectionEvent e
) {
336 InputElement inputElement
= new InputElement("", false, CustomXmlTraceDefinition
.TAG_IGNORE
, 0, "", null); //$NON-NLS-1$ //$NON-NLS-2$
337 if (definition
.rootInputElement
== null) {
338 definition
.rootInputElement
= inputElement
;
339 inputElement
.elementName
= getChildNameSuggestion(null);
340 } else if (treeViewer
.getSelection().isEmpty()) {
343 InputElement parentInputElement
= (InputElement
) ((IStructuredSelection
) treeViewer
.getSelection()).getFirstElement();
344 parentInputElement
.addChild(inputElement
);
345 inputElement
.elementName
= getChildNameSuggestion(parentInputElement
);
347 treeViewer
.refresh();
348 treeViewer
.setSelection(new StructuredSelection(inputElement
), true);
352 addNextButton
= new Button(buttonBar
, SWT
.PUSH
);
353 addNextButton
.setImage(addNextImage
);
354 addNextButton
.setToolTipText(Messages
.CustomXmlParserInputWizardPage_addNextElement
);
355 addNextButton
.addSelectionListener(new SelectionAdapter() {
357 public void widgetSelected(SelectionEvent e
) {
358 InputElement inputElement
= new InputElement("", false, CustomXmlTraceDefinition
.TAG_IGNORE
, 0, "", null); //$NON-NLS-1$ //$NON-NLS-2$
359 if (definition
.rootInputElement
== null) {
360 definition
.rootInputElement
= inputElement
;
361 inputElement
.elementName
= getChildNameSuggestion(null);
362 } else if (treeViewer
.getSelection().isEmpty()) {
365 InputElement previousInputElement
= (InputElement
) ((IStructuredSelection
) treeViewer
.getSelection()).getFirstElement();
366 if (previousInputElement
== definition
.rootInputElement
) {
369 previousInputElement
.addNext(inputElement
);
370 inputElement
.elementName
= getChildNameSuggestion(inputElement
.parentElement
);
373 treeViewer
.refresh();
374 treeViewer
.setSelection(new StructuredSelection(inputElement
), true);
378 feelingLuckyButton
= new Button(buttonBar
, SWT
.PUSH
);
379 feelingLuckyButton
.setImage(addManyImage
);
380 feelingLuckyButton
.setToolTipText(Messages
.CustomXmlParserInputWizardPage_feelingLucky
);
381 feelingLuckyButton
.addSelectionListener(new SelectionAdapter() {
383 public void widgetSelected(SelectionEvent e
) {
384 InputElement inputElement
= null;
385 if (definition
.rootInputElement
== null) {
386 if (getChildNameSuggestion(null).length() != 0) {
387 inputElement
= new InputElement(getChildNameSuggestion(null), false, CustomXmlTraceDefinition
.TAG_IGNORE
, 0, "", null); //$NON-NLS-1$
388 definition
.rootInputElement
= inputElement
;
389 feelingLucky(inputElement
);
393 } else if (treeViewer
.getSelection().isEmpty()) {
396 inputElement
= (InputElement
) ((IStructuredSelection
) treeViewer
.getSelection()).getFirstElement();
397 feelingLucky(inputElement
);
399 treeViewer
.refresh();
400 treeViewer
.setSelection(new StructuredSelection(inputElement
), true);
401 treeViewer
.expandToLevel(inputElement
, TreeViewer
.ALL_LEVELS
);
405 moveUpButton
= new Button(buttonBar
, SWT
.PUSH
);
406 moveUpButton
.setImage(moveUpImage
);
407 moveUpButton
.setToolTipText(Messages
.CustomXmlParserInputWizardPage_moveUp
);
408 moveUpButton
.addSelectionListener(new SelectionAdapter() {
410 public void widgetSelected(SelectionEvent e
) {
411 if (treeViewer
.getSelection().isEmpty())
413 InputElement inputElement
= (InputElement
) ((IStructuredSelection
) treeViewer
.getSelection()).getFirstElement();
414 if (inputElement
== definition
.rootInputElement
) {
417 inputElement
.moveUp();
419 treeViewer
.refresh();
425 moveDownButton
= new Button(buttonBar
, SWT
.PUSH
);
426 moveDownButton
.setImage(moveDownImage
);
427 moveDownButton
.setToolTipText(Messages
.CustomXmlParserInputWizardPage_moveDown
);
428 moveDownButton
.addSelectionListener(new SelectionAdapter() {
430 public void widgetSelected(SelectionEvent e
) {
431 if (treeViewer
.getSelection().isEmpty())
433 InputElement inputElement
= (InputElement
) ((IStructuredSelection
) treeViewer
.getSelection()).getFirstElement();
434 if (inputElement
== definition
.rootInputElement
) {
437 inputElement
.moveDown();
439 treeViewer
.refresh();
446 private void feelingLucky(InputElement inputElement
) {
448 String attributeName
= getAttributeNameSuggestion(inputElement
);
449 if (attributeName
.length() == 0) {
452 InputAttribute attribute
= new InputAttribute(attributeName
, attributeName
, 0, ""); //$NON-NLS-1$
453 inputElement
.addAttribute(attribute
);
457 String childName
= getChildNameSuggestion(inputElement
);
458 if (childName
.length() == 0) {
461 InputElement childElement
= new InputElement(childName
, false, CustomXmlTraceDefinition
.TAG_IGNORE
, 0, "", null); //$NON-NLS-1$
462 inputElement
.addChild(childElement
);
463 feelingLucky(childElement
);
468 private class InputElementTreeNodeContentProvider
implements ITreeContentProvider
{
471 public Object
[] getElements(Object inputElement
) {
472 CustomXmlTraceDefinition def
= (CustomXmlTraceDefinition
) inputElement
;
473 if (def
.rootInputElement
!= null) {
474 return new Object
[] { def
.rootInputElement
};
476 return new Object
[0];
481 public Object
[] getChildren(Object parentElement
) {
482 InputElement inputElement
= (InputElement
) parentElement
;
483 if (inputElement
.childElements
== null)
484 return new InputElement
[0];
485 return inputElement
.childElements
.toArray();
489 public boolean hasChildren(Object element
) {
490 InputElement inputElement
= (InputElement
) element
;
491 return (inputElement
.childElements
!= null && inputElement
.childElements
.size() > 0);
495 public void dispose() {
499 public void inputChanged(Viewer viewer
, Object oldInput
, Object newInput
) {
503 public Object
getParent(Object element
) {
504 InputElement inputElement
= (InputElement
) element
;
505 return inputElement
.parentElement
;
509 private class InputElementTreeLabelProvider
extends ColumnLabelProvider
{
512 public Image
getImage(Object element
) {
517 public String
getText(Object element
) {
518 InputElement inputElement
= (InputElement
) element
;
519 return (inputElement
.elementName
.trim().length() == 0) ?
"?" : inputElement
.elementName
; //$NON-NLS-1$
523 private class InputElementTreeSelectionChangedListener
implements ISelectionChangedListener
{
525 public void selectionChanged(SelectionChangedEvent event
) {
526 if (selectedElement
!= null) {
527 selectedElement
.dispose();
529 if (!(event
.getSelection().isEmpty()) && event
.getSelection() instanceof IStructuredSelection
) {
530 IStructuredSelection selection
= (IStructuredSelection
) event
.getSelection();
531 InputElement inputElement
= (InputElement
) selection
.getFirstElement();
532 selectedElement
= new ElementNode(elementContainer
, inputElement
);
533 elementContainer
.layout();
534 elementScrolledComposite
.setMinSize(elementContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).x
,
535 elementContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).y
- 1);
539 removeButton
.setEnabled(true);
540 addChildButton
.setEnabled(true);
541 addChildButton
.setToolTipText(Messages
.CustomXmlParserInputWizardPage_addChildElement
);
542 if (definition
.rootInputElement
== inputElement
) {
543 addNextButton
.setEnabled(false);
545 addNextButton
.setEnabled(true);
547 moveUpButton
.setEnabled(true);
548 moveDownButton
.setEnabled(true);
550 removeButton
.setEnabled(false);
551 if (definition
.rootInputElement
== null) {
552 addChildButton
.setEnabled(true);
553 addChildButton
.setToolTipText(Messages
.CustomXmlParserInputWizardPage_addDocumentElement
);
555 addChildButton
.setEnabled(false);
557 addNextButton
.setEnabled(false);
558 moveUpButton
.setEnabled(false);
559 moveDownButton
.setEnabled(false);
567 * @see org.eclipse.jface.dialogs.DialogPage#dispose()
570 public void dispose() {
571 if (fixedFont
!= null) {
578 private void loadDefinition(CustomXmlTraceDefinition def
) {
579 logtypeText
.setText(def
.definitionName
);
580 timeStampOutputFormatText
.setText(def
.timeStampOutputFormat
);
581 treeViewer
.setInput(def
);
583 if (def
.rootInputElement
!= null) {
584 treeViewer
.setSelection(new StructuredSelection(def
.rootInputElement
));
588 private String
getName(InputElement inputElement
) {
589 String name
= (inputElement
.elementName
.trim().length() == 0) ?
"?" : inputElement
.elementName
.trim(); //$NON-NLS-1$
590 if (inputElement
.parentElement
== null) {
593 return getName(inputElement
.parentElement
) + " : " + name
; //$NON-NLS-1$
596 private String
getName(InputAttribute inputAttribute
, InputElement inputElement
) {
597 String name
= (inputAttribute
.attributeName
.trim().length() == 0) ?
"?" : inputAttribute
.attributeName
.trim(); //$NON-NLS-1$
598 return getName(inputElement
) + " : " + name
; //$NON-NLS-1$
604 * @see org.eclipse.jface.dialogs.DialogPage#setVisible(boolean)
607 public void setVisible(boolean visible
) {
612 super.setVisible(visible
);
615 public List
<String
> getInputNames() {
616 return getInputNames(definition
.rootInputElement
);
619 public List
<String
> getInputNames(InputElement inputElement
) {
620 List
<String
> inputs
= new ArrayList
<String
>();
621 if (inputElement
.inputName
!= null && !inputElement
.inputName
.equals(CustomXmlTraceDefinition
.TAG_IGNORE
)) {
622 String inputName
= inputElement
.inputName
;
623 if (!inputs
.contains(inputName
)) {
624 inputs
.add(inputName
);
627 if (inputElement
.attributes
!= null) {
628 for (InputAttribute attribute
: inputElement
.attributes
) {
629 String inputName
= attribute
.inputName
;
630 if (!inputs
.contains(inputName
)) {
631 inputs
.add(inputName
);
635 if (inputElement
.childElements
!= null) {
636 for (InputElement childInputElement
: inputElement
.childElements
) {
637 for (String inputName
: getInputNames(childInputElement
)) {
638 if (!inputs
.contains(inputName
)) {
639 inputs
.add(inputName
);
647 private void removeElement() {
648 selectedElement
.dispose();
649 selectedElement
= null;
650 elementContainer
.layout();
651 elementScrolledComposite
.setMinSize(elementContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).x
,
652 elementContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).y
- 1);
656 private String
getSelectionText() {
657 InputStream inputStream
= null;
658 if (this.selection
instanceof IStructuredSelection
) {
659 Object selection
= ((IStructuredSelection
) this.selection
).getFirstElement();
660 if (selection
instanceof IFile
) {
661 IFile file
= (IFile
) selection
;
663 inputStream
= file
.getContents();
664 } catch (CoreException e
) {
665 return ""; //$NON-NLS-1$
669 if (inputStream
!= null) {
671 BufferedReader reader
= new BufferedReader(new InputStreamReader(inputStream
));
672 StringBuilder sb
= new StringBuilder();
674 while ((line
= reader
.readLine()) != null) {
675 sb
.append(line
+ "\n"); //$NON-NLS-1$
677 parseXmlInput(sb
.toString());
678 return sb
.toString();
679 } catch (IOException e
) {
680 return ""; //$NON-NLS-1$
683 return ""; //$NON-NLS-1$
686 private void parseXmlInput(final String string
) {
688 DocumentBuilderFactory dbf
= DocumentBuilderFactory
.newInstance();
689 DocumentBuilder db
= dbf
.newDocumentBuilder();
691 // The following allows xml parsing without access to the dtd
692 EntityResolver resolver
= new EntityResolver() {
694 public InputSource
resolveEntity(String publicId
, String systemId
) {
695 String empty
= ""; //$NON-NLS-1$
696 ByteArrayInputStream bais
= new ByteArrayInputStream(empty
.getBytes());
697 return new InputSource(bais
);
700 db
.setEntityResolver(resolver
);
702 // The following catches xml parsing exceptions
703 db
.setErrorHandler(new ErrorHandler() {
705 public void error(SAXParseException saxparseexception
) throws SAXException
{
709 public void warning(SAXParseException saxparseexception
) throws SAXException
{
713 public void fatalError(SAXParseException saxparseexception
) throws SAXException
{
714 if (string
.trim().length() != 0) {
715 errorText
.setText(saxparseexception
.getMessage());
716 errorText
.setBackground(COLOR_LIGHT_RED
);
717 errorText
.setVisible(true);
719 throw saxparseexception
;
723 errorText
.setVisible(false);
725 doc
= db
.parse(new ByteArrayInputStream(string
.getBytes()));
726 documentElement
= doc
.getDocumentElement();
727 } catch (ParserConfigurationException e
) {
729 documentElement
= null;
730 } catch (SAXException e
) {
731 documentElement
= null;
732 } catch (IOException e
) {
734 documentElement
= null;
738 private void updatePreviews() {
739 updatePreviews(false);
742 private void updatePreviews(boolean updateAll
) {
743 if (inputText
== null) {
744 // early update during construction
747 inputText
.setStyleRanges(new StyleRange
[] {});
748 if (selectedElement
== null) {
752 timeStampValue
= null;
753 timeStampFormat
= null;
755 logEntryFound
= false;
757 selectedElement
.updatePreview();
759 if (timeStampValue
!= null && timeStampFormat
!= null) {
761 SimpleDateFormat dateFormat
= new SimpleDateFormat(timeStampFormat
);
762 Date date
= dateFormat
.parse(timeStampValue
);
763 dateFormat
= new SimpleDateFormat(timeStampOutputFormatText
.getText().trim());
764 timeStampPreviewText
.setText(dateFormat
.format(date
));
765 } catch (ParseException e
) {
766 timeStampPreviewText
.setText("*parse exception* [" + timeStampValue
+ "] <> [" + timeStampFormat
+ "]"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
767 } catch (IllegalArgumentException e
) {
768 timeStampPreviewText
.setText("*parse exception* [Illegal Argument]"); //$NON-NLS-1$
771 timeStampPreviewText
.setText("*no matching time stamp*"); //$NON-NLS-1$
775 private void openHelpShell(String url
) {
776 if (helpBrowser
!= null && !helpBrowser
.isDisposed()) {
777 helpBrowser
.getShell().setActive();
778 if (!helpBrowser
.getUrl().equals(url
)) {
779 helpBrowser
.setUrl(url
);
783 final Shell helpShell
= new Shell(getShell(), SWT
.SHELL_TRIM
);
784 helpShell
.setLayout(new FillLayout());
785 helpBrowser
= new Browser(helpShell
, SWT
.NONE
);
786 helpBrowser
.addTitleListener(new TitleListener() {
788 public void changed(TitleEvent event
) {
789 helpShell
.setText(event
.title
);
792 helpBrowser
.setBounds(0, 0, 600, 400);
795 helpBrowser
.setUrl(url
);
798 private class UpdateListener
implements ModifyListener
, SelectionListener
{
801 public void modifyText(ModifyEvent e
) {
807 public void widgetDefaultSelected(SelectionEvent e
) {
813 public void widgetSelected(SelectionEvent e
) {
820 private class ElementNode
{
821 final InputElement inputElement
;
823 ArrayList
<Attribute
> attributes
= new ArrayList
<Attribute
>();
824 ArrayList
<ElementNode
> childElements
= new ArrayList
<ElementNode
>();
825 Text elementNameText
;
826 Composite tagComposite
;
833 Button logEntryButton
;
835 Composite addAttributeComposite
;
836 Button addAttributeButton
;
837 Label addAttributeLabel
;
839 public ElementNode(Composite parent
, InputElement inputElement
) {
840 this.inputElement
= inputElement
;
842 group
= new Group(parent
, SWT
.NONE
);
843 GridLayout gl
= new GridLayout(2, false);
846 group
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
847 group
.setText(getName(inputElement
));
849 Label label
= new Label(group
, SWT
.NULL
);
850 label
.setText(Messages
.CustomXmlParserInputWizardPage_elementName
);
851 label
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
853 elementNameText
= new Text(group
, SWT
.BORDER
| SWT
.SINGLE
);
854 GridData gd
= new GridData(SWT
.FILL
, SWT
.CENTER
, true, false);
856 elementNameText
.setLayoutData(gd
);
857 elementNameText
.addModifyListener(new ModifyListener() {
859 public void modifyText(ModifyEvent e
) {
860 ElementNode
.this.inputElement
.elementName
= elementNameText
.getText().trim();
861 group
.setText(getName(ElementNode
.this.inputElement
));
864 elementNameText
.setText(inputElement
.elementName
);
865 elementNameText
.addModifyListener(updateListener
);
867 if (inputElement
.parentElement
!= null) {
868 previewLabel
= new Label(group
, SWT
.NULL
);
869 previewLabel
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
870 previewLabel
.setText(Messages
.CustomXmlParserInputWizardPage_preview
);
872 previewText
= new Text(group
, SWT
.BORDER
| SWT
.SINGLE
| SWT
.READ_ONLY
);
873 gd
= new GridData(SWT
.FILL
, SWT
.CENTER
, true, false);
875 previewText
.setLayoutData(gd
);
876 previewText
.setText(Messages
.CustomXmlParserInputWizardPage_noMatchingElement
);
877 previewText
.setBackground(COLOR_WIDGET_BACKGROUND
);
879 logEntryButton
= new Button(group
, SWT
.CHECK
);
880 logEntryButton
.setText(Messages
.CustomXmlParserInputWizardPage_logEntry
);
881 logEntryButton
.setSelection(inputElement
.logEntry
);
882 logEntryButton
.addSelectionListener(new SelectionListener() {
884 public void widgetDefaultSelected(SelectionEvent e
) {
888 public void widgetSelected(SelectionEvent e
) {
889 InputElement parent
= ElementNode
.this.inputElement
.parentElement
;
890 while (parent
!= null) {
891 parent
.logEntry
= false;
892 parent
= parent
.parentElement
;
896 logEntryButton
.addSelectionListener(updateListener
);
898 tagComposite
= new Composite(group
, SWT
.FILL
);
899 GridLayout tagLayout
= new GridLayout(4, false);
900 tagLayout
.marginWidth
= 0;
901 tagLayout
.marginHeight
= 0;
902 tagComposite
.setLayout(tagLayout
);
903 tagComposite
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
905 tagCombo
= new Combo(tagComposite
, SWT
.DROP_DOWN
| SWT
.READ_ONLY
);
906 tagCombo
.setItems(new String
[] { CustomXmlTraceDefinition
.TAG_IGNORE
, CustomXmlTraceDefinition
.TAG_TIMESTAMP
,
907 CustomXmlTraceDefinition
.TAG_MESSAGE
, CustomXmlTraceDefinition
.TAG_OTHER
});
908 tagCombo
.setVisibleItemCount(tagCombo
.getItemCount());
909 tagCombo
.addSelectionListener(new SelectionListener() {
911 public void widgetDefaultSelected(SelectionEvent e
) {
915 public void widgetSelected(SelectionEvent e
) {
916 tagText
.removeModifyListener(updateListener
);
917 switch (tagCombo
.getSelectionIndex()) {
919 tagLabel
.setVisible(false);
920 tagText
.setVisible(false);
921 actionCombo
.setVisible(false);
923 case 1: // Time Stamp
924 tagLabel
.setText(Messages
.CustomXmlParserInputWizardPage_format
);
925 tagLabel
.setVisible(true);
926 tagText
.setVisible(true);
927 tagText
.addModifyListener(updateListener
);
928 actionCombo
.setVisible(true);
931 tagLabel
.setVisible(false);
932 tagText
.setVisible(false);
933 actionCombo
.setVisible(true);
936 tagLabel
.setText(Messages
.CustomXmlParserInputWizardPage_tagName
);
937 tagLabel
.setVisible(true);
938 if (tagText
.getText().trim().length() == 0) {
939 tagText
.setText(elementNameText
.getText().trim());
941 tagText
.setVisible(true);
942 tagText
.addModifyListener(updateListener
);
943 actionCombo
.setVisible(true);
946 tagComposite
.layout();
952 tagLabel
= new Label(tagComposite
, SWT
.NULL
);
953 tagLabel
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
955 tagText
= new Text(tagComposite
, SWT
.BORDER
| SWT
.SINGLE
);
956 gd
= new GridData(SWT
.FILL
, SWT
.CENTER
, true, false);
958 tagText
.setLayoutData(gd
);
960 actionCombo
= new Combo(tagComposite
, SWT
.DROP_DOWN
| SWT
.READ_ONLY
);
961 actionCombo
.setItems(new String
[] { Messages
.CustomXmlParserInputWizardPage_set
, Messages
.CustomXmlParserInputWizardPage_append
,
962 Messages
.CustomXmlParserInputWizardPage_appendWith
});
963 actionCombo
.select(inputElement
.inputAction
);
964 actionCombo
.addSelectionListener(updateListener
);
966 if (inputElement
.inputName
.equals(CustomXmlTraceDefinition
.TAG_IGNORE
)) {
968 tagLabel
.setVisible(false);
969 tagText
.setVisible(false);
970 actionCombo
.setVisible(false);
971 } else if (inputElement
.inputName
.equals(CustomXmlTraceDefinition
.TAG_TIMESTAMP
)) {
973 tagLabel
.setText(Messages
.CustomXmlParserInputWizardPage_format
);
974 tagText
.setText(inputElement
.inputFormat
);
975 tagText
.addModifyListener(updateListener
);
976 } else if (inputElement
.inputName
.equals(CustomXmlTraceDefinition
.TAG_MESSAGE
)) {
978 tagLabel
.setVisible(false);
979 tagText
.setVisible(false);
982 tagLabel
.setText(Messages
.CustomXmlParserInputWizardPage_tagName
);
983 tagText
.setText(inputElement
.inputName
);
984 tagText
.addModifyListener(updateListener
);
988 if (inputElement
.attributes
!= null) {
989 for (InputAttribute inputAttribute
: inputElement
.attributes
) {
990 Attribute attribute
= new Attribute(group
, this, inputAttribute
, attributes
.size() + 1);
991 attributes
.add(attribute
);
998 private void updatePreview() {
999 Element element
= getPreviewElement(inputElement
);
1000 if (inputElement
.parentElement
!= null) { // no preview text for
1002 previewText
.setText(Messages
.CustomXmlParserInputWizardPage_noMatchingElement
);
1003 if (element
!= null) {
1004 previewText
.setText(CustomXmlTrace
.parseElement(element
, new StringBuffer()).toString());
1005 if (logEntryButton
.getSelection()) {
1006 if (logEntryFound
== false) {
1007 logEntryFound
= true;
1010 logEntryButton
.setSelection(false); // remove nested
1014 if (tagCombo
.getText().equals(CustomXmlTraceDefinition
.TAG_TIMESTAMP
) && logEntriesCount
<= 1) {
1015 String value
= previewText
.getText().trim();
1016 if (value
.length() != 0) {
1017 if (actionCombo
.getSelectionIndex() == CustomXmlTraceDefinition
.ACTION_SET
) {
1018 timeStampValue
= value
;
1019 timeStampFormat
= tagText
.getText().trim();
1020 } else if (actionCombo
.getSelectionIndex() == CustomXmlTraceDefinition
.ACTION_APPEND
) {
1021 if (timeStampValue
!= null) {
1022 timeStampValue
+= value
;
1023 timeStampFormat
+= tagText
.getText().trim();
1025 timeStampValue
= value
;
1026 timeStampFormat
= tagText
.getText().trim();
1028 } else if (actionCombo
.getSelectionIndex() == CustomXmlTraceDefinition
.ACTION_APPEND_WITH_SEPARATOR
) {
1029 if (timeStampValue
!= null) {
1030 timeStampValue
+= " | " + value
; //$NON-NLS-1$
1031 timeStampFormat
+= " | " + tagText
.getText().trim(); //$NON-NLS-1$
1033 timeStampValue
= value
;
1034 timeStampFormat
= tagText
.getText().trim();
1041 for (Attribute attribute
: attributes
) {
1042 if (element
!= null) {
1043 String value
= element
.getAttribute(attribute
.attributeNameText
.getText().trim());
1044 if (value
.length() != 0) {
1045 attribute
.previewText
.setText(value
);
1046 if (attribute
.tagCombo
.getText().equals(CustomXmlTraceDefinition
.TAG_TIMESTAMP
) && logEntriesCount
<= 1) {
1047 if (attribute
.actionCombo
.getSelectionIndex() == CustomXmlTraceDefinition
.ACTION_SET
) {
1048 timeStampValue
= value
;
1049 timeStampFormat
= attribute
.tagText
.getText().trim();
1050 } else if (attribute
.actionCombo
.getSelectionIndex() == CustomXmlTraceDefinition
.ACTION_APPEND
) {
1051 if (timeStampValue
!= null) {
1052 timeStampValue
+= value
;
1053 timeStampFormat
+= attribute
.tagText
.getText().trim();
1055 timeStampValue
= value
;
1056 timeStampFormat
= attribute
.tagText
.getText().trim();
1058 } else if (attribute
.actionCombo
.getSelectionIndex() == CustomXmlTraceDefinition
.ACTION_APPEND_WITH_SEPARATOR
) {
1059 if (timeStampValue
!= null) {
1060 timeStampValue
+= " | " + value
; //$NON-NLS-1$
1061 timeStampFormat
+= " | " + attribute
.tagText
.getText().trim(); //$NON-NLS-1$
1063 timeStampValue
= value
;
1064 timeStampFormat
= attribute
.tagText
.getText().trim();
1069 attribute
.previewText
.setText(Messages
.CustomXmlParserInputWizardPage_noMatchingAttribute
);
1072 attribute
.previewText
.setText(Messages
.CustomXmlParserInputWizardPage_noMatchingElement
);
1075 for (ElementNode child
: childElements
) {
1076 child
.updatePreview();
1078 if (logEntryButton
!= null && logEntryButton
.getSelection()) {
1079 logEntryFound
= false;
1083 private void createAddButton() {
1084 fillerLabel
= new Label(group
, SWT
.NONE
);
1086 addAttributeComposite
= new Composite(group
, SWT
.NONE
);
1087 addAttributeComposite
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
1088 GridLayout addAttributeLayout
= new GridLayout(2, false);
1089 addAttributeLayout
.marginHeight
= 0;
1090 addAttributeLayout
.marginWidth
= 0;
1091 addAttributeComposite
.setLayout(addAttributeLayout
);
1093 addAttributeButton
= new Button(addAttributeComposite
, SWT
.PUSH
);
1094 addAttributeButton
.setImage(addImage
);
1095 addAttributeButton
.setToolTipText(Messages
.CustomXmlParserInputWizardPage_addAttribute
);
1096 addAttributeButton
.addSelectionListener(new SelectionAdapter() {
1098 public void widgetSelected(SelectionEvent e
) {
1100 String attributeName
= getAttributeNameSuggestion(inputElement
);
1101 InputAttribute inputAttribute
= new InputAttribute(attributeName
, attributeName
, 0, ""); //$NON-NLS-1$
1102 attributes
.add(new Attribute(group
, ElementNode
.this, inputAttribute
, attributes
.size() + 1));
1104 elementContainer
.layout();
1105 elementScrolledComposite
.setMinSize(elementContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).x
,
1106 elementContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).y
- 1);
1107 group
.getParent().layout();
1113 addAttributeLabel
= new Label(addAttributeComposite
, SWT
.NULL
);
1114 addAttributeLabel
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
1115 addAttributeLabel
.setText(Messages
.CustomXmlParserInputWizardPage_newAttibute
);
1118 private void removeAddButton() {
1119 fillerLabel
.dispose();
1120 addAttributeComposite
.dispose();
1123 private void removeAttribute(int attributeNumber
) {
1124 if (--attributeNumber
< attributes
.size()) {
1125 attributes
.remove(attributeNumber
).dispose();
1126 for (int i
= attributeNumber
; i
< attributes
.size(); i
++) {
1127 attributes
.get(i
).setAttributeNumber(i
+ 1);
1129 elementContainer
.layout();
1130 elementScrolledComposite
.setMinSize(elementContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).x
,
1131 elementContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).y
- 1);
1132 group
.getParent().layout();
1136 private void dispose() {
1140 private void extractInputs() {
1141 inputElement
.elementName
= elementNameText
.getText().trim();
1142 if (inputElement
.parentElement
!= null) {
1143 inputElement
.logEntry
= logEntryButton
.getSelection();
1144 if (tagCombo
.getText().equals(CustomXmlTraceDefinition
.TAG_OTHER
)) {
1145 inputElement
.inputName
= tagText
.getText().trim();
1147 inputElement
.inputName
= tagCombo
.getText();
1148 if (tagCombo
.getText().equals(CustomXmlTraceDefinition
.TAG_TIMESTAMP
)) {
1149 inputElement
.inputFormat
= tagText
.getText().trim();
1152 inputElement
.inputAction
= actionCombo
.getSelectionIndex();
1154 inputElement
.attributes
= new ArrayList
<InputAttribute
>(attributes
.size());
1155 for (int i
= 0; i
< attributes
.size(); i
++) {
1156 Attribute attribute
= attributes
.get(i
);
1157 InputAttribute inputAttribute
= new InputAttribute();
1158 inputAttribute
.attributeName
= attribute
.attributeNameText
.getText().trim();
1159 if (attribute
.tagCombo
.getText().equals(CustomXmlTraceDefinition
.TAG_OTHER
)) {
1160 inputAttribute
.inputName
= attribute
.tagText
.getText().trim();
1162 inputAttribute
.inputName
= attribute
.tagCombo
.getText();
1163 if (attribute
.tagCombo
.getText().equals(CustomXmlTraceDefinition
.TAG_TIMESTAMP
)) {
1164 inputAttribute
.inputFormat
= attribute
.tagText
.getText().trim();
1167 inputAttribute
.inputAction
= attribute
.actionCombo
.getSelectionIndex();
1168 inputElement
.addAttribute(inputAttribute
);
1173 private class Attribute
{
1174 ElementNode element
;
1175 int attributeNumber
;
1177 // children of parent (must be disposed)
1178 Composite labelComposite
;
1179 Composite attributeComposite
;
1181 Composite tagComposite
;
1183 // children of labelComposite
1184 Label attributeLabel
;
1186 // children of attributeComposite
1187 Text attributeNameText
;
1190 // children of tagComposite
1196 public Attribute(Composite parent
, ElementNode element
, InputAttribute inputAttribute
, int attributeNumber
) {
1197 this.element
= element
;
1198 this.attributeNumber
= attributeNumber
;
1200 labelComposite
= new Composite(parent
, SWT
.FILL
);
1201 GridLayout labelLayout
= new GridLayout(2, false);
1202 labelLayout
.marginWidth
= 0;
1203 labelLayout
.marginHeight
= 0;
1204 labelComposite
.setLayout(labelLayout
);
1205 labelComposite
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
1207 Button deleteButton
= new Button(labelComposite
, SWT
.PUSH
);
1208 deleteButton
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
1209 deleteButton
.setImage(deleteImage
);
1210 deleteButton
.setToolTipText(Messages
.CustomXmlParserInputWizardPage_removeAttribute
);
1211 deleteButton
.addSelectionListener(new SelectionAdapter() {
1213 public void widgetSelected(SelectionEvent e
) {
1214 Attribute
.this.element
.removeAttribute(Attribute
.this.attributeNumber
);
1220 attributeLabel
= new Label(labelComposite
, SWT
.NULL
);
1221 attributeLabel
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
1222 attributeLabel
.setText(Messages
.CustomXmlParserInputWizardPage_attibute
);
1224 attributeComposite
= new Composite(parent
, SWT
.FILL
);
1225 GridLayout attributeLayout
= new GridLayout(4, false);
1226 attributeLayout
.marginWidth
= 0;
1227 attributeLayout
.marginHeight
= 0;
1228 attributeComposite
.setLayout(attributeLayout
);
1229 attributeComposite
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
1231 Label nameLabel
= new Label(attributeComposite
, SWT
.NONE
);
1232 nameLabel
.setText(Messages
.CustomXmlParserInputWizardPage_name
);
1234 attributeNameText
= new Text(attributeComposite
, SWT
.BORDER
| SWT
.SINGLE
);
1235 attributeNameText
.setLayoutData(new GridData(120, SWT
.DEFAULT
));
1236 attributeNameText
.setText(inputAttribute
.attributeName
);
1237 attributeNameText
.addModifyListener(updateListener
);
1239 Label previewLabel
= new Label(attributeComposite
, SWT
.NONE
);
1240 previewLabel
.setText(Messages
.CustomXmlParserInputWizardPage_preview
);
1242 previewText
= new Text(attributeComposite
, SWT
.BORDER
| SWT
.SINGLE
| SWT
.READ_ONLY
);
1243 GridData gd
= new GridData(SWT
.FILL
, SWT
.CENTER
, true, false);
1245 previewText
.setLayoutData(gd
);
1246 previewText
.setText(Messages
.CustomXmlParserInputWizardPage_noMatch
);
1247 previewText
.setBackground(COLOR_WIDGET_BACKGROUND
);
1249 filler
= new Label(parent
, SWT
.NULL
);
1251 tagComposite
= new Composite(parent
, SWT
.FILL
);
1252 GridLayout tagLayout
= new GridLayout(4, false);
1253 tagLayout
.marginWidth
= 0;
1254 tagLayout
.marginHeight
= 0;
1255 tagComposite
.setLayout(tagLayout
);
1256 tagComposite
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
1258 tagCombo
= new Combo(tagComposite
, SWT
.DROP_DOWN
| SWT
.READ_ONLY
);
1259 tagCombo
.setItems(new String
[] { CustomXmlTraceDefinition
.TAG_TIMESTAMP
, CustomXmlTraceDefinition
.TAG_MESSAGE
,
1260 CustomXmlTraceDefinition
.TAG_OTHER
});
1261 tagCombo
.select(2); // Other
1262 tagCombo
.addSelectionListener(new SelectionListener() {
1264 public void widgetDefaultSelected(SelectionEvent e
) {
1268 public void widgetSelected(SelectionEvent e
) {
1269 tagText
.removeModifyListener(updateListener
);
1270 switch (tagCombo
.getSelectionIndex()) {
1271 case 0: // Time Stamp
1272 tagLabel
.setText(Messages
.CustomXmlParserInputWizardPage_format
);
1273 tagLabel
.setVisible(true);
1274 tagText
.setVisible(true);
1275 tagText
.addModifyListener(updateListener
);
1278 tagLabel
.setVisible(false);
1279 tagText
.setVisible(false);
1282 tagLabel
.setText(Messages
.CustomXmlParserInputWizardPage_tagName
);
1283 tagLabel
.setVisible(true);
1284 if (tagText
.getText().trim().length() == 0) {
1285 tagText
.setText(attributeNameText
.getText().trim());
1287 tagText
.setVisible(true);
1288 tagText
.addModifyListener(updateListener
);
1291 tagComposite
.layout();
1297 tagLabel
= new Label(tagComposite
, SWT
.NULL
);
1298 tagLabel
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
1300 tagText
= new Text(tagComposite
, SWT
.BORDER
| SWT
.SINGLE
);
1301 gd
= new GridData(SWT
.FILL
, SWT
.CENTER
, true, false);
1303 tagText
.setLayoutData(gd
);
1304 tagText
.setText(attributeNameText
.getText());
1306 actionCombo
= new Combo(tagComposite
, SWT
.DROP_DOWN
| SWT
.READ_ONLY
);
1307 actionCombo
.setItems(new String
[] { Messages
.CustomXmlParserInputWizardPage_set
, Messages
.CustomXmlParserInputWizardPage_append
,
1308 Messages
.CustomXmlParserInputWizardPage_appendWith
});
1309 actionCombo
.select(inputAttribute
.inputAction
);
1310 actionCombo
.addSelectionListener(updateListener
);
1312 if (inputAttribute
.inputName
.equals(CustomXmlTraceDefinition
.TAG_TIMESTAMP
)) {
1314 tagLabel
.setText(Messages
.CustomXmlParserInputWizardPage_format
);
1315 tagText
.setText(inputAttribute
.inputFormat
);
1316 tagText
.addModifyListener(updateListener
);
1317 } else if (inputAttribute
.inputName
.equals(CustomXmlTraceDefinition
.TAG_MESSAGE
)) {
1319 tagLabel
.setVisible(false);
1320 tagText
.setVisible(false);
1323 tagLabel
.setText(Messages
.CustomXmlParserInputWizardPage_tagName
);
1324 tagText
.setText(inputAttribute
.inputName
);
1325 tagText
.addModifyListener(updateListener
);
1329 private void dispose() {
1330 labelComposite
.dispose();
1331 attributeComposite
.dispose();
1333 tagComposite
.dispose();
1336 private void setAttributeNumber(int attributeNumber
) {
1337 this.attributeNumber
= attributeNumber
;
1338 labelComposite
.layout();
1342 private Element
getPreviewElement(InputElement inputElement
) {
1343 Element element
= documentElement
;
1344 if (element
!= null) {
1345 if (!documentElement
.getNodeName().equals(definition
.rootInputElement
.elementName
)) {
1348 ArrayList
<String
> elementNames
= new ArrayList
<String
>();
1349 while (inputElement
!= null) {
1350 elementNames
.add(inputElement
.elementName
);
1351 inputElement
= inputElement
.parentElement
;
1353 for (int i
= elementNames
.size() - 1; --i
>= 0;) {
1354 NodeList childList
= element
.getChildNodes();
1356 for (int j
= 0; j
< childList
.getLength(); j
++) {
1357 Node child
= childList
.item(j
);
1358 if (child
instanceof Element
&& child
.getNodeName().equals(elementNames
.get(i
))) {
1359 element
= (Element
) child
;
1363 if (element
== null) {
1367 if (element
!= null) {
1374 private String
getChildNameSuggestion(InputElement inputElement
) {
1375 if (inputElement
== null) {
1376 if (documentElement
!= null) {
1377 return documentElement
.getNodeName();
1380 Element element
= getPreviewElement(inputElement
);
1381 if (element
!= null) {
1382 NodeList childNodes
= element
.getChildNodes();
1383 for (int i
= 0; i
< childNodes
.getLength(); i
++) {
1384 Node node
= childNodes
.item(i
);
1385 if (node
instanceof Element
) {
1386 boolean unused
= true;
1387 if (inputElement
.childElements
!= null) {
1388 for (InputElement child
: inputElement
.childElements
) {
1389 if (child
.elementName
.equals(node
.getNodeName())) {
1396 return node
.getNodeName();
1402 return ""; //$NON-NLS-1$
1405 private String
getAttributeNameSuggestion(InputElement inputElement
) {
1406 Element element
= getPreviewElement(inputElement
);
1407 if (element
!= null) {
1408 NamedNodeMap attributeMap
= element
.getAttributes();
1409 for (int i
= 0; i
< attributeMap
.getLength(); i
++) {
1410 Node node
= attributeMap
.item(i
);
1411 boolean unused
= true;
1412 if (inputElement
.attributes
!= null) {
1413 for (InputAttribute attribute
: inputElement
.attributes
) {
1414 if (attribute
.attributeName
.equals(node
.getNodeName())) {
1421 return node
.getNodeName();
1425 return ""; //$NON-NLS-1$
1428 private void validate() {
1429 definition
.definitionName
= logtypeText
.getText().trim();
1430 definition
.timeStampOutputFormat
= timeStampOutputFormatText
.getText().trim();
1432 if (selectedElement
!= null) {
1433 selectedElement
.extractInputs();
1434 treeViewer
.refresh();
1437 StringBuffer errors
= new StringBuffer();
1439 if (definition
.definitionName
.length() == 0) {
1440 errors
.append(Messages
.CustomXmlParserInputWizardPage_emptyLogTypeError
);
1441 logtypeText
.setBackground(COLOR_LIGHT_RED
);
1443 logtypeText
.setBackground(COLOR_TEXT_BACKGROUND
);
1444 for (CustomXmlTraceDefinition def
: CustomXmlTraceDefinition
.loadAll()) {
1445 if (definition
.definitionName
.equals(def
.definitionName
)) {
1446 if (editDefinitionName
== null || !editDefinitionName
.equals(definition
.definitionName
)) {
1447 errors
.append(Messages
.CustomXmlParserInputWizardPage_duplicatelogTypeError
);
1448 logtypeText
.setBackground(COLOR_LIGHT_RED
);
1455 if (definition
.rootInputElement
== null) {
1456 errors
.append(Messages
.CustomXmlParserInputWizardPage_noDocumentError
);
1459 if (definition
.rootInputElement
!= null) {
1460 logEntryFound
= false;
1461 logEntryNestedCount
= 0;
1462 timeStampFound
= false;
1464 errors
.append(validateElement(definition
.rootInputElement
));
1466 if ((definition
.rootInputElement
.attributes
!= null && definition
.rootInputElement
.attributes
.size() != 0)
1467 || (definition
.rootInputElement
.childElements
!= null && definition
.rootInputElement
.childElements
.size() != 0)
1468 || errors
.length() == 0) {
1469 if (!logEntryFound
) {
1470 errors
.append(Messages
.CustomXmlParserInputWizardPage_missingLogEntryError
);
1473 if (timeStampFound
) {
1474 if (timeStampOutputFormatText
.getText().trim().length() == 0) {
1475 errors
.append(Messages
.CustomXmlParserInputWizardPage_missingTimestampFmtError
);
1476 timeStampOutputFormatText
.setBackground(COLOR_LIGHT_RED
);
1479 new SimpleDateFormat(timeStampOutputFormatText
.getText().trim());
1480 timeStampOutputFormatText
.setBackground(COLOR_TEXT_BACKGROUND
);
1481 } catch (IllegalArgumentException e
) {
1482 errors
.append(Messages
.CustomXmlParserInputWizardPage_invalidTimestampFmtError
);
1483 timeStampOutputFormatText
.setBackground(COLOR_LIGHT_RED
);
1487 timeStampPreviewText
.setText(Messages
.CustomXmlParserInputWizardPage_notimestamporAttributeError
);
1491 timeStampPreviewText
.setText(Messages
.CustomXmlParserInputWizardPage_notimestamporAttributeError
);
1494 if (errors
.length() == 0) {
1495 setDescription(defaultDescription
);
1496 setPageComplete(true);
1498 setDescription(errors
.toString());
1499 setPageComplete(false);
1503 public StringBuffer
validateElement(InputElement inputElement
) {
1504 StringBuffer errors
= new StringBuffer();
1505 ElementNode elementNode
= null;
1506 if (selectedElement
!= null && selectedElement
.inputElement
.equals(inputElement
))
1507 elementNode
= selectedElement
;
1508 if (inputElement
== definition
.rootInputElement
) {
1509 if (inputElement
.elementName
.length() == 0) {
1510 errors
.append(Messages
.CustomXmlParserInputWizardPage_missingDocumentElementError
);
1511 if (elementNode
!= null)
1512 elementNode
.elementNameText
.setBackground(COLOR_LIGHT_RED
);
1514 if (elementNode
!= null)
1515 elementNode
.elementNameText
.setBackground(COLOR_TEXT_BACKGROUND
);
1518 if (inputElement
!= definition
.rootInputElement
) {
1519 if (inputElement
.logEntry
) {
1520 logEntryFound
= true;
1521 logEntryNestedCount
++;
1523 if (inputElement
.inputName
.equals(CustomXmlTraceDefinition
.TAG_TIMESTAMP
)) {
1524 timeStampFound
= true;
1525 if (inputElement
.inputFormat
.length() == 0) {
1526 errors
.append(Messages
.CustomXmlParserInputWizardPage_timestampFormatPrompt
1527 + " (" + Messages
.CustomXmlParserInputWizardPage_timestampElementPrompt
+ " " + getName(inputElement
) + "). "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
1528 if (elementNode
!= null)
1529 elementNode
.tagText
.setBackground(COLOR_LIGHT_RED
);
1532 new SimpleDateFormat(inputElement
.inputFormat
);
1533 if (elementNode
!= null)
1534 elementNode
.tagText
.setBackground(COLOR_TEXT_BACKGROUND
);
1535 } catch (IllegalArgumentException e
) {
1536 errors
.append(Messages
.CustomXmlParserInputWizardPage_invalidTimestampFmtError
1537 + " (" + Messages
.CustomXmlParserInputWizardPage_timestampElementPrompt
+ " " + getName(inputElement
) + "). "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
1538 if (elementNode
!= null)
1539 elementNode
.tagText
.setBackground(COLOR_LIGHT_RED
);
1542 } else if (inputElement
.inputName
.length() == 0) {
1543 errors
.append(Messages
.CustomXmlParserInputWizardPage_missingInputElementNameError
);
1544 if (elementNode
!= null)
1545 elementNode
.tagText
.setBackground(COLOR_LIGHT_RED
);
1547 if (elementNode
!= null)
1548 elementNode
.tagText
.setBackground(COLOR_TEXT_BACKGROUND
);
1551 if (inputElement
.attributes
!= null) {
1552 if (elementNode
!= null) {
1553 for (Attribute attribute
: elementNode
.attributes
) {
1554 attribute
.attributeNameText
.setBackground(COLOR_TEXT_BACKGROUND
);
1557 for (int i
= 0; i
< inputElement
.attributes
.size(); i
++) {
1558 InputAttribute attribute
= inputElement
.attributes
.get(i
);
1559 boolean duplicate
= false;
1560 for (int j
= i
+ 1; j
< inputElement
.attributes
.size(); j
++) {
1561 InputAttribute otherAttribute
= inputElement
.attributes
.get(j
);
1562 if (otherAttribute
.attributeName
.equals(attribute
.attributeName
)) {
1564 if (elementNode
!= null) {
1565 elementNode
.attributes
.get(j
).attributeNameText
.setBackground(COLOR_LIGHT_RED
);
1569 if (attribute
.attributeName
.length() == 0) {
1570 errors
.append(Messages
.CustomXmlParserInputWizardPage_missingAttribute
1571 + " (" + Messages
.CustomXmlParserInputWizardPage_attributePrompt
+ " " + getName(inputElement
) + ": ?). "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
1572 if (elementNode
!= null)
1573 elementNode
.attributes
.get(i
).attributeNameText
.setBackground(COLOR_LIGHT_RED
);
1574 } else if (duplicate
) {
1575 errors
.append(Messages
.CustomXmlParserInputWizardPage_duplicateAttributeError
1576 + " (" + Messages
.CustomXmlParserInputWizardPage_attributePrompt
+ " " + getName(attribute
, inputElement
) + "). "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
1577 if (elementNode
!= null)
1578 elementNode
.attributes
.get(i
).attributeNameText
.setBackground(COLOR_LIGHT_RED
);
1580 if (attribute
.inputName
.equals(CustomXmlTraceDefinition
.TAG_TIMESTAMP
)) {
1581 timeStampFound
= true;
1582 if (attribute
.inputFormat
.length() == 0) {
1583 errors
.append(Messages
.CustomXmlParserInputWizardPage_missingTimestampInFmtError
1584 + " (" + Messages
.CustomXmlParserInputWizardPage_attributePrompt
+ " " + getName(attribute
, inputElement
) + "). "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
1585 if (elementNode
!= null)
1586 elementNode
.attributes
.get(i
).tagText
.setBackground(COLOR_LIGHT_RED
);
1589 new SimpleDateFormat(attribute
.inputFormat
);
1590 if (elementNode
!= null)
1591 elementNode
.attributes
.get(i
).tagText
.setBackground(COLOR_TEXT_BACKGROUND
);
1592 } catch (IllegalArgumentException e
) {
1593 errors
.append(Messages
.CustomXmlParserInputWizardPage_invalidTimestampInFmtError
1594 + " (" + Messages
.CustomXmlParserInputWizardPage_attributePrompt
+ " " + getName(attribute
, inputElement
) + "). "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
1595 if (elementNode
!= null)
1596 elementNode
.attributes
.get(i
).tagText
.setBackground(COLOR_LIGHT_RED
);
1599 } else if (attribute
.inputName
.length() == 0) {
1600 errors
.append(Messages
.CustomXmlParserInputWizardPage_missingDataGroupNameError
1601 + " (" + Messages
.CustomXmlParserInputWizardPage_attributePrompt
+ " " + getName(attribute
, inputElement
) + "). "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
1602 if (elementNode
!= null)
1603 elementNode
.attributes
.get(i
).tagText
.setBackground(COLOR_LIGHT_RED
);
1605 if (elementNode
!= null)
1606 elementNode
.attributes
.get(i
).tagText
.setBackground(COLOR_TEXT_BACKGROUND
);
1610 if (inputElement
.childElements
!= null) {
1611 for (InputElement child
: inputElement
.childElements
) {
1612 ElementNode childElementNode
= null;
1613 if (selectedElement
!= null && selectedElement
.inputElement
.equals(child
))
1614 childElementNode
= selectedElement
;
1615 if (childElementNode
!= null)
1616 childElementNode
.elementNameText
.setBackground(COLOR_TEXT_BACKGROUND
);
1618 for (int i
= 0; i
< inputElement
.childElements
.size(); i
++) {
1619 InputElement child
= inputElement
.childElements
.get(i
);
1620 ElementNode childElementNode
= null;
1621 if (selectedElement
!= null && selectedElement
.inputElement
.equals(child
))
1622 childElementNode
= selectedElement
;
1623 if (child
.elementName
.length() == 0) {
1624 errors
.append(Messages
.CustomXmlParserInputWizardPage_missingElementNameError
1625 + " (" + Messages
.CustomXmlParserInputWizardPage_attributePrompt
+ " " + getName(child
) + "). "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
1626 if (childElementNode
!= null)
1627 childElementNode
.elementNameText
.setBackground(COLOR_LIGHT_RED
);
1629 boolean duplicate
= false;
1630 for (int j
= i
+ 1; j
< inputElement
.childElements
.size(); j
++) {
1631 InputElement otherChild
= inputElement
.childElements
.get(j
);
1632 if (otherChild
.elementName
.equals(child
.elementName
)) {
1634 ElementNode otherChildElementNode
= null;
1635 if (selectedElement
!= null && selectedElement
.inputElement
.equals(otherChild
))
1636 otherChildElementNode
= selectedElement
;
1637 if (otherChildElementNode
!= null)
1638 otherChildElementNode
.elementNameText
.setBackground(COLOR_LIGHT_RED
);
1642 errors
.append(Messages
.CustomXmlParserInputWizardPage_duplicateElementNameError
1643 + " (" + Messages
.CustomXmlParserInputWizardPage_attributePrompt
+ " " + getName(child
) + "). "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
1644 if (childElementNode
!= null)
1645 childElementNode
.elementNameText
.setBackground(COLOR_LIGHT_RED
);
1649 errors
.append(validateElement(child
));
1652 if (inputElement
.logEntry
) {
1653 logEntryNestedCount
--;
1658 public CustomXmlTraceDefinition
getDefinition() {
1662 public char[] getInputText() {
1663 return inputText
.getText().toCharArray();