1 package org
.eclipse
.linuxtools
.internal
.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
.internal
.tmf
.ui
.Messages
;
31 import org
.eclipse
.linuxtools
.internal
.tmf
.ui
.Activator
;
32 import org
.eclipse
.linuxtools
.internal
.tmf
.ui
.parsers
.custom
.CustomXmlTrace
;
33 import org
.eclipse
.linuxtools
.internal
.tmf
.ui
.parsers
.custom
.CustomXmlTraceDefinition
;
34 import org
.eclipse
.linuxtools
.internal
.tmf
.ui
.parsers
.custom
.CustomXmlTraceDefinition
.InputAttribute
;
35 import org
.eclipse
.linuxtools
.internal
.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
= Activator
.getDefault().getImageFromPath("/icons/elcl16/element_icon.gif"); //$NON-NLS-1$
80 private static final Image addImage
= Activator
.getDefault().getImageFromPath("/icons/elcl16/add_button.gif"); //$NON-NLS-1$
81 private static final Image addNextImage
= Activator
.getDefault().getImageFromPath("/icons/elcl16/addnext_button.gif"); //$NON-NLS-1$
82 private static final Image addChildImage
= Activator
.getDefault().getImageFromPath("/icons/elcl16/addchild_button.gif"); //$NON-NLS-1$
83 private static final Image addManyImage
= Activator
.getDefault().getImageFromPath("/icons/elcl16/addmany_button.gif"); //$NON-NLS-1$
84 private static final Image deleteImage
= Activator
.getDefault().getImageFromPath("/icons/elcl16/delete_button.gif"); //$NON-NLS-1$
85 private static final Image moveUpImage
= Activator
.getDefault().getImageFromPath("/icons/elcl16/moveup_button.gif"); //$NON-NLS-1$
86 private static final Image moveDownImage
= Activator
.getDefault().getImageFromPath("/icons/elcl16/movedown_button.gif"); //$NON-NLS-1$
87 private static final Image helpImage
= Activator
.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
;
126 protected CustomXmlParserInputWizardPage(ISelection selection
, CustomXmlTraceDefinition definition
) {
127 super("CustomXmlParserWizardPage"); //$NON-NLS-1$
128 if (definition
== null) {
129 setTitle(Messages
.CustomXmlParserInputWizardPage_titleNew
);
130 defaultDescription
= Messages
.CustomXmlParserInputWizardPage_descriptionNew
;
132 setTitle(Messages
.CustomXmlParserInputWizardPage_titleEdit
);
133 defaultDescription
= Messages
.CustomXmlParserInputWizardPage_descriptionEdit
;
135 setDescription(defaultDescription
);
136 this.selection
= selection
;
137 this.definition
= definition
;
138 if (definition
!= null) {
139 this.editDefinitionName
= definition
.definitionName
;
144 public void createControl(Composite parent
) {
145 container
= new Composite(parent
, SWT
.NULL
);
146 container
.setLayout(new GridLayout());
148 updateListener
= new UpdateListener();
150 Composite headerComposite
= new Composite(container
, SWT
.FILL
);
151 GridLayout headerLayout
= new GridLayout(5, false);
152 headerLayout
.marginHeight
= 0;
153 headerLayout
.marginWidth
= 0;
154 headerComposite
.setLayout(headerLayout
);
155 headerComposite
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
157 Label logtypeLabel
= new Label(headerComposite
, SWT
.NULL
);
158 logtypeLabel
.setText(Messages
.CustomXmlParserInputWizardPage_logType
);
160 logtypeText
= new Text(headerComposite
, SWT
.BORDER
| SWT
.SINGLE
);
161 logtypeText
.setLayoutData(new GridData(120, SWT
.DEFAULT
));
163 Label timeStampFormatLabel
= new Label(headerComposite
, SWT
.NULL
);
164 timeStampFormatLabel
.setText(Messages
.CustomXmlParserInputWizardPage_timestampFormat
);
166 timeStampOutputFormatText
= new Text(headerComposite
, SWT
.BORDER
| SWT
.SINGLE
);
167 timeStampOutputFormatText
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
168 timeStampOutputFormatText
.setText(DEFAULT_TIMESTAMP_FORMAT
);
170 Button dateFormatHelpButton
= new Button(headerComposite
, SWT
.PUSH
);
171 dateFormatHelpButton
.setImage(helpImage
);
172 dateFormatHelpButton
.setToolTipText(Messages
.CustomXmlParserInputWizardPage_dateFormatHelp
);
173 dateFormatHelpButton
.addSelectionListener(new SelectionAdapter() {
175 public void widgetSelected(SelectionEvent e
) {
176 openHelpShell(SIMPLE_DATE_FORMAT_URL
);
180 Label timeStampPreviewLabel
= new Label(headerComposite
, SWT
.NULL
);
181 timeStampPreviewLabel
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false, 3, 1));
182 timeStampPreviewLabel
.setText(Messages
.CustomXmlParserInputWizardPage_preview
);
184 timeStampPreviewText
= new Text(headerComposite
, SWT
.BORDER
| SWT
.SINGLE
| SWT
.READ_ONLY
);
185 timeStampPreviewText
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false, 2, 1));
186 timeStampPreviewText
.setText("*no time stamp element or attribute*"); //$NON-NLS-1$
190 SashForm vSash
= new SashForm(container
, SWT
.VERTICAL
);
191 vSash
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
192 vSash
.setBackground(vSash
.getDisplay().getSystemColor(SWT
.COLOR_GRAY
));
194 SashForm hSash
= new SashForm(vSash
, SWT
.HORIZONTAL
);
195 hSash
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
197 treeScrolledComposite
= new ScrolledComposite(hSash
, SWT
.V_SCROLL
| SWT
.H_SCROLL
);
198 treeScrolledComposite
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
199 treeContainer
= new Composite(treeScrolledComposite
, SWT
.NONE
);
200 treeContainer
.setLayout(new FillLayout());
201 treeScrolledComposite
.setContent(treeContainer
);
202 treeScrolledComposite
.setExpandHorizontal(true);
203 treeScrolledComposite
.setExpandVertical(true);
205 treeViewer
= new TreeViewer(treeContainer
, SWT
.SINGLE
| SWT
.BORDER
);
206 treeViewer
.setContentProvider(new InputElementTreeNodeContentProvider());
207 treeViewer
.setLabelProvider(new InputElementTreeLabelProvider());
208 treeViewer
.addSelectionChangedListener(new InputElementTreeSelectionChangedListener());
209 treeContainer
.layout();
211 treeScrolledComposite
212 .setMinSize(treeContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).x
, treeContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).y
);
214 elementScrolledComposite
= new ScrolledComposite(hSash
, SWT
.V_SCROLL
);
215 elementScrolledComposite
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
216 elementContainer
= new Composite(elementScrolledComposite
, SWT
.NONE
);
217 GridLayout gl
= new GridLayout();
220 elementContainer
.setLayout(gl
);
221 elementScrolledComposite
.setContent(elementContainer
);
222 elementScrolledComposite
.setExpandHorizontal(true);
223 elementScrolledComposite
.setExpandVertical(true);
225 if (definition
== null) {
226 definition
= new CustomXmlTraceDefinition();
228 loadDefinition(definition
);
229 treeViewer
.expandAll();
230 elementContainer
.layout();
232 logtypeText
.addModifyListener(updateListener
);
233 timeStampOutputFormatText
.addModifyListener(updateListener
);
235 elementScrolledComposite
.setMinSize(elementContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).x
,
236 elementContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).y
- 1);
238 hSash
.setWeights(new int[] { 1, 2 });
240 if (definition
.rootInputElement
== null) {
241 removeButton
.setEnabled(false);
242 addChildButton
.setToolTipText(Messages
.CustomXmlParserInputWizardPage_addDocumentElement
);
243 addNextButton
.setEnabled(false);
244 moveUpButton
.setEnabled(false);
245 moveDownButton
.setEnabled(false);
246 } else { // root is selected
247 addNextButton
.setEnabled(false);
250 Composite sashBottom
= new Composite(vSash
, SWT
.NONE
);
251 GridLayout sashBottomLayout
= new GridLayout(2, false);
252 sashBottomLayout
.marginHeight
= 0;
253 sashBottomLayout
.marginWidth
= 0;
254 sashBottom
.setLayout(sashBottomLayout
);
256 Label previewLabel
= new Label(sashBottom
, SWT
.NULL
);
257 previewLabel
.setText(Messages
.CustomXmlParserInputWizardPage_previewInput
);
259 errorText
= new Text(sashBottom
, SWT
.SINGLE
| SWT
.READ_ONLY
);
260 errorText
.setBackground(COLOR_WIDGET_BACKGROUND
);
261 errorText
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
262 errorText
.setVisible(false);
264 inputText
= new StyledText(sashBottom
, SWT
.MULTI
| SWT
.V_SCROLL
| SWT
.H_SCROLL
);
265 if (fixedFont
== null) {
266 if (System
.getProperty("os.name").contains("Windows")) { //$NON-NLS-1$ //$NON-NLS-2$
267 fixedFont
= new Font(Display
.getCurrent(), new FontData("Courier New", 10, SWT
.NORMAL
)); //$NON-NLS-1$
269 fixedFont
= new Font(Display
.getCurrent(), new FontData("Monospace", 10, SWT
.NORMAL
)); //$NON-NLS-1$
272 inputText
.setFont(fixedFont
);
273 GridData gd
= new GridData(SWT
.FILL
, SWT
.FILL
, true, true, 2, 1);
274 gd
.heightHint
= inputText
.computeSize(SWT
.DEFAULT
, inputText
.getLineHeight() * 4).y
;
276 inputText
.setLayoutData(gd
);
277 inputText
.setText(getSelectionText());
278 inputText
.addModifyListener(new ModifyListener() {
280 public void modifyText(ModifyEvent e
) {
281 parseXmlInput(inputText
.getText());
284 inputText
.addModifyListener(updateListener
);
286 vSash
.setWeights(new int[] { hSash
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).y
, sashBottom
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).y
});
288 setControl(container
);
291 private void createButtonBar() {
292 Composite buttonBar
= new Composite(container
, SWT
.NONE
);
293 GridLayout buttonBarLayout
= new GridLayout(6, false);
294 buttonBarLayout
.marginHeight
= 0;
295 buttonBarLayout
.marginWidth
= 0;
296 buttonBar
.setLayout(buttonBarLayout
);
298 removeButton
= new Button(buttonBar
, SWT
.PUSH
);
299 removeButton
.setImage(deleteImage
);
300 removeButton
.setToolTipText(Messages
.CustomXmlParserInputWizardPage_removeElement
);
301 removeButton
.addSelectionListener(new SelectionAdapter() {
303 public void widgetSelected(SelectionEvent e
) {
304 if (treeViewer
.getSelection().isEmpty() || selectedElement
== null)
307 InputElement inputElement
= (InputElement
) ((IStructuredSelection
) treeViewer
.getSelection()).getFirstElement();
308 if (inputElement
== definition
.rootInputElement
) {
309 definition
.rootInputElement
= null;
311 inputElement
.parentElement
.childElements
.remove(inputElement
);
313 treeViewer
.refresh();
316 removeButton
.setEnabled(false);
317 if (definition
.rootInputElement
== null) {
318 addChildButton
.setEnabled(true);
319 addChildButton
.setToolTipText(Messages
.CustomXmlParserInputWizardPage_addDocumentEleemnt
);
321 addChildButton
.setEnabled(false);
323 addNextButton
.setEnabled(false);
324 moveUpButton
.setEnabled(false);
325 moveDownButton
.setEnabled(false);
329 addChildButton
= new Button(buttonBar
, SWT
.PUSH
);
330 addChildButton
.setImage(addChildImage
);
331 addChildButton
.setToolTipText(Messages
.CustomXmlParserInputWizardPage_addChildElement
);
332 addChildButton
.addSelectionListener(new SelectionAdapter() {
334 public void widgetSelected(SelectionEvent e
) {
335 InputElement inputElement
= new InputElement("", false, CustomXmlTraceDefinition
.TAG_IGNORE
, 0, "", null); //$NON-NLS-1$ //$NON-NLS-2$
336 if (definition
.rootInputElement
== null) {
337 definition
.rootInputElement
= inputElement
;
338 inputElement
.elementName
= getChildNameSuggestion(null);
339 } else if (treeViewer
.getSelection().isEmpty()) {
342 InputElement parentInputElement
= (InputElement
) ((IStructuredSelection
) treeViewer
.getSelection()).getFirstElement();
343 parentInputElement
.addChild(inputElement
);
344 inputElement
.elementName
= getChildNameSuggestion(parentInputElement
);
346 treeViewer
.refresh();
347 treeViewer
.setSelection(new StructuredSelection(inputElement
), true);
351 addNextButton
= new Button(buttonBar
, SWT
.PUSH
);
352 addNextButton
.setImage(addNextImage
);
353 addNextButton
.setToolTipText(Messages
.CustomXmlParserInputWizardPage_addNextElement
);
354 addNextButton
.addSelectionListener(new SelectionAdapter() {
356 public void widgetSelected(SelectionEvent e
) {
357 InputElement inputElement
= new InputElement("", false, CustomXmlTraceDefinition
.TAG_IGNORE
, 0, "", null); //$NON-NLS-1$ //$NON-NLS-2$
358 if (definition
.rootInputElement
== null) {
359 definition
.rootInputElement
= inputElement
;
360 inputElement
.elementName
= getChildNameSuggestion(null);
361 } else if (treeViewer
.getSelection().isEmpty()) {
364 InputElement previousInputElement
= (InputElement
) ((IStructuredSelection
) treeViewer
.getSelection()).getFirstElement();
365 if (previousInputElement
== definition
.rootInputElement
) {
368 previousInputElement
.addNext(inputElement
);
369 inputElement
.elementName
= getChildNameSuggestion(inputElement
.parentElement
);
372 treeViewer
.refresh();
373 treeViewer
.setSelection(new StructuredSelection(inputElement
), true);
377 feelingLuckyButton
= new Button(buttonBar
, SWT
.PUSH
);
378 feelingLuckyButton
.setImage(addManyImage
);
379 feelingLuckyButton
.setToolTipText(Messages
.CustomXmlParserInputWizardPage_feelingLucky
);
380 feelingLuckyButton
.addSelectionListener(new SelectionAdapter() {
382 public void widgetSelected(SelectionEvent e
) {
383 InputElement inputElement
= null;
384 if (definition
.rootInputElement
== null) {
385 if (getChildNameSuggestion(null).length() != 0) {
386 inputElement
= new InputElement(getChildNameSuggestion(null), false, CustomXmlTraceDefinition
.TAG_IGNORE
, 0, "", null); //$NON-NLS-1$
387 definition
.rootInputElement
= inputElement
;
388 feelingLucky(inputElement
);
392 } else if (treeViewer
.getSelection().isEmpty()) {
395 inputElement
= (InputElement
) ((IStructuredSelection
) treeViewer
.getSelection()).getFirstElement();
396 feelingLucky(inputElement
);
398 treeViewer
.refresh();
399 treeViewer
.setSelection(new StructuredSelection(inputElement
), true);
400 treeViewer
.expandToLevel(inputElement
, TreeViewer
.ALL_LEVELS
);
404 moveUpButton
= new Button(buttonBar
, SWT
.PUSH
);
405 moveUpButton
.setImage(moveUpImage
);
406 moveUpButton
.setToolTipText(Messages
.CustomXmlParserInputWizardPage_moveUp
);
407 moveUpButton
.addSelectionListener(new SelectionAdapter() {
409 public void widgetSelected(SelectionEvent e
) {
410 if (treeViewer
.getSelection().isEmpty())
412 InputElement inputElement
= (InputElement
) ((IStructuredSelection
) treeViewer
.getSelection()).getFirstElement();
413 if (inputElement
== definition
.rootInputElement
) {
416 inputElement
.moveUp();
418 treeViewer
.refresh();
424 moveDownButton
= new Button(buttonBar
, SWT
.PUSH
);
425 moveDownButton
.setImage(moveDownImage
);
426 moveDownButton
.setToolTipText(Messages
.CustomXmlParserInputWizardPage_moveDown
);
427 moveDownButton
.addSelectionListener(new SelectionAdapter() {
429 public void widgetSelected(SelectionEvent e
) {
430 if (treeViewer
.getSelection().isEmpty())
432 InputElement inputElement
= (InputElement
) ((IStructuredSelection
) treeViewer
.getSelection()).getFirstElement();
433 if (inputElement
== definition
.rootInputElement
) {
436 inputElement
.moveDown();
438 treeViewer
.refresh();
445 private void feelingLucky(InputElement inputElement
) {
447 String attributeName
= getAttributeNameSuggestion(inputElement
);
448 if (attributeName
.length() == 0) {
451 InputAttribute attribute
= new InputAttribute(attributeName
, attributeName
, 0, ""); //$NON-NLS-1$
452 inputElement
.addAttribute(attribute
);
456 String childName
= getChildNameSuggestion(inputElement
);
457 if (childName
.length() == 0) {
460 InputElement childElement
= new InputElement(childName
, false, CustomXmlTraceDefinition
.TAG_IGNORE
, 0, "", null); //$NON-NLS-1$
461 inputElement
.addChild(childElement
);
462 feelingLucky(childElement
);
467 private static class InputElementTreeNodeContentProvider
implements ITreeContentProvider
{
470 public Object
[] getElements(Object inputElement
) {
471 CustomXmlTraceDefinition def
= (CustomXmlTraceDefinition
) inputElement
;
472 if (def
.rootInputElement
!= null) {
473 return new Object
[] { def
.rootInputElement
};
475 return new Object
[0];
480 public Object
[] getChildren(Object parentElement
) {
481 InputElement inputElement
= (InputElement
) parentElement
;
482 if (inputElement
.childElements
== null)
483 return new InputElement
[0];
484 return inputElement
.childElements
.toArray();
488 public boolean hasChildren(Object element
) {
489 InputElement inputElement
= (InputElement
) element
;
490 return (inputElement
.childElements
!= null && inputElement
.childElements
.size() > 0);
494 public void dispose() {
498 public void inputChanged(Viewer viewer
, Object oldInput
, Object newInput
) {
502 public Object
getParent(Object element
) {
503 InputElement inputElement
= (InputElement
) element
;
504 return inputElement
.parentElement
;
508 private static class InputElementTreeLabelProvider
extends ColumnLabelProvider
{
511 public Image
getImage(Object element
) {
516 public String
getText(Object element
) {
517 InputElement inputElement
= (InputElement
) element
;
518 return (inputElement
.elementName
.trim().length() == 0) ?
"?" : inputElement
.elementName
; //$NON-NLS-1$
522 private class InputElementTreeSelectionChangedListener
implements ISelectionChangedListener
{
524 public void selectionChanged(SelectionChangedEvent event
) {
525 if (selectedElement
!= null) {
526 selectedElement
.dispose();
528 if (!(event
.getSelection().isEmpty()) && event
.getSelection() instanceof IStructuredSelection
) {
529 IStructuredSelection selection
= (IStructuredSelection
) event
.getSelection();
530 InputElement inputElement
= (InputElement
) selection
.getFirstElement();
531 selectedElement
= new ElementNode(elementContainer
, inputElement
);
532 elementContainer
.layout();
533 elementScrolledComposite
.setMinSize(elementContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).x
,
534 elementContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).y
- 1);
538 removeButton
.setEnabled(true);
539 addChildButton
.setEnabled(true);
540 addChildButton
.setToolTipText(Messages
.CustomXmlParserInputWizardPage_addChildElement
);
541 if (definition
.rootInputElement
== inputElement
) {
542 addNextButton
.setEnabled(false);
544 addNextButton
.setEnabled(true);
546 moveUpButton
.setEnabled(true);
547 moveDownButton
.setEnabled(true);
549 removeButton
.setEnabled(false);
550 if (definition
.rootInputElement
== null) {
551 addChildButton
.setEnabled(true);
552 addChildButton
.setToolTipText(Messages
.CustomXmlParserInputWizardPage_addDocumentElement
);
554 addChildButton
.setEnabled(false);
556 addNextButton
.setEnabled(false);
557 moveUpButton
.setEnabled(false);
558 moveDownButton
.setEnabled(false);
566 * @see org.eclipse.jface.dialogs.DialogPage#dispose()
569 public void dispose() {
570 if (fixedFont
!= null) {
577 private void loadDefinition(CustomXmlTraceDefinition def
) {
578 logtypeText
.setText(def
.definitionName
);
579 timeStampOutputFormatText
.setText(def
.timeStampOutputFormat
);
580 treeViewer
.setInput(def
);
582 if (def
.rootInputElement
!= null) {
583 treeViewer
.setSelection(new StructuredSelection(def
.rootInputElement
));
587 private String
getName(InputElement inputElement
) {
588 String name
= (inputElement
.elementName
.trim().length() == 0) ?
"?" : inputElement
.elementName
.trim(); //$NON-NLS-1$
589 if (inputElement
.parentElement
== null) {
592 return getName(inputElement
.parentElement
) + " : " + name
; //$NON-NLS-1$
595 private String
getName(InputAttribute inputAttribute
, InputElement inputElement
) {
596 String name
= (inputAttribute
.attributeName
.trim().length() == 0) ?
"?" : inputAttribute
.attributeName
.trim(); //$NON-NLS-1$
597 return getName(inputElement
) + " : " + name
; //$NON-NLS-1$
603 * @see org.eclipse.jface.dialogs.DialogPage#setVisible(boolean)
606 public void setVisible(boolean visible
) {
611 super.setVisible(visible
);
614 public List
<String
> getInputNames() {
615 return getInputNames(definition
.rootInputElement
);
618 public List
<String
> getInputNames(InputElement inputElement
) {
619 List
<String
> inputs
= new ArrayList
<String
>();
620 if (inputElement
.inputName
!= null && !inputElement
.inputName
.equals(CustomXmlTraceDefinition
.TAG_IGNORE
)) {
621 String inputName
= inputElement
.inputName
;
622 if (!inputs
.contains(inputName
)) {
623 inputs
.add(inputName
);
626 if (inputElement
.attributes
!= null) {
627 for (InputAttribute attribute
: inputElement
.attributes
) {
628 String inputName
= attribute
.inputName
;
629 if (!inputs
.contains(inputName
)) {
630 inputs
.add(inputName
);
634 if (inputElement
.childElements
!= null) {
635 for (InputElement childInputElement
: inputElement
.childElements
) {
636 for (String inputName
: getInputNames(childInputElement
)) {
637 if (!inputs
.contains(inputName
)) {
638 inputs
.add(inputName
);
646 private void removeElement() {
647 selectedElement
.dispose();
648 selectedElement
= null;
649 elementContainer
.layout();
650 elementScrolledComposite
.setMinSize(elementContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).x
,
651 elementContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).y
- 1);
655 private String
getSelectionText() {
656 InputStream inputStream
= null;
657 if (this.selection
instanceof IStructuredSelection
) {
658 Object selection
= ((IStructuredSelection
) this.selection
).getFirstElement();
659 if (selection
instanceof IFile
) {
660 IFile file
= (IFile
) selection
;
662 inputStream
= file
.getContents();
663 } catch (CoreException e
) {
664 return ""; //$NON-NLS-1$
668 if (inputStream
!= null) {
669 BufferedReader reader
= null;
671 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());
679 return sb
.toString();
680 } catch (IOException e
) {
681 return ""; //$NON-NLS-1$
684 return ""; //$NON-NLS-1$
687 private void parseXmlInput(final String string
) {
689 DocumentBuilderFactory dbf
= DocumentBuilderFactory
.newInstance();
690 DocumentBuilder db
= dbf
.newDocumentBuilder();
692 // The following allows xml parsing without access to the dtd
693 EntityResolver resolver
= new EntityResolver() {
695 public InputSource
resolveEntity(String publicId
, String systemId
) {
696 String empty
= ""; //$NON-NLS-1$
697 ByteArrayInputStream bais
= new ByteArrayInputStream(empty
.getBytes());
698 return new InputSource(bais
);
701 db
.setEntityResolver(resolver
);
703 // The following catches xml parsing exceptions
704 db
.setErrorHandler(new ErrorHandler() {
706 public void error(SAXParseException saxparseexception
) throws SAXException
{
710 public void warning(SAXParseException saxparseexception
) throws SAXException
{
714 public void fatalError(SAXParseException saxparseexception
) throws SAXException
{
715 if (string
.trim().length() != 0) {
716 errorText
.setText(saxparseexception
.getMessage());
717 errorText
.setBackground(COLOR_LIGHT_RED
);
718 errorText
.setVisible(true);
720 throw saxparseexception
;
724 errorText
.setVisible(false);
726 doc
= db
.parse(new ByteArrayInputStream(string
.getBytes()));
727 documentElement
= doc
.getDocumentElement();
728 } catch (ParserConfigurationException e
) {
729 Activator
.getDefault().logError("Error pasing XML input string: " + string
, e
); //$NON-NLS-1$
730 documentElement
= null;
731 } catch (SAXException e
) {
732 documentElement
= null;
733 } catch (IOException e
) {
734 Activator
.getDefault().logError("Error pasing XML input string: " + string
, e
); //$NON-NLS-1$
735 documentElement
= null;
739 private void updatePreviews() {
740 updatePreviews(false);
743 private void initValues() {
744 timeStampValue
= null;
745 timeStampFormat
= null;
747 logEntryFound
= false;
750 private void updatePreviews(boolean updateAll
) {
751 if (inputText
== null) {
752 // early update during construction
755 inputText
.setStyleRanges(new StyleRange
[] {});
756 if (selectedElement
== null) {
762 selectedElement
.updatePreview();
764 if (timeStampValue
!= null && timeStampFormat
!= null) {
766 SimpleDateFormat dateFormat
= new SimpleDateFormat(timeStampFormat
);
767 Date date
= dateFormat
.parse(timeStampValue
);
768 dateFormat
= new SimpleDateFormat(timeStampOutputFormatText
.getText().trim());
769 timeStampPreviewText
.setText(dateFormat
.format(date
));
770 } catch (ParseException e
) {
771 timeStampPreviewText
.setText("*parse exception* [" + timeStampValue
+ "] <> [" + timeStampFormat
+ "]"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
772 } catch (IllegalArgumentException e
) {
773 timeStampPreviewText
.setText("*parse exception* [Illegal Argument]"); //$NON-NLS-1$
776 timeStampPreviewText
.setText("*no matching time stamp*"); //$NON-NLS-1$
780 private void openHelpShell(String url
) {
781 if (helpBrowser
!= null && !helpBrowser
.isDisposed()) {
782 helpBrowser
.getShell().setActive();
783 if (!helpBrowser
.getUrl().equals(url
)) {
784 helpBrowser
.setUrl(url
);
788 final Shell helpShell
= new Shell(getShell(), SWT
.SHELL_TRIM
);
789 helpShell
.setLayout(new FillLayout());
790 helpBrowser
= new Browser(helpShell
, SWT
.NONE
);
791 helpBrowser
.addTitleListener(new TitleListener() {
793 public void changed(TitleEvent event
) {
794 helpShell
.setText(event
.title
);
797 helpBrowser
.setBounds(0, 0, 600, 400);
800 helpBrowser
.setUrl(url
);
803 private class UpdateListener
implements ModifyListener
, SelectionListener
{
806 public void modifyText(ModifyEvent e
) {
812 public void widgetDefaultSelected(SelectionEvent e
) {
818 public void widgetSelected(SelectionEvent e
) {
825 private class ElementNode
{
826 final InputElement inputElement
;
828 List
<Attribute
> attributes
= new ArrayList
<Attribute
>();
829 List
<ElementNode
> childElements
= new ArrayList
<ElementNode
>();
830 Text elementNameText
;
831 Composite tagComposite
;
838 Button logEntryButton
;
840 Composite addAttributeComposite
;
841 Button addAttributeButton
;
842 Label addAttributeLabel
;
844 public ElementNode(Composite parent
, InputElement inputElement
) {
845 this.inputElement
= inputElement
;
847 group
= new Group(parent
, SWT
.NONE
);
848 GridLayout gl
= new GridLayout(2, false);
851 group
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
852 group
.setText(getName(inputElement
));
854 Label label
= new Label(group
, SWT
.NULL
);
855 label
.setText(Messages
.CustomXmlParserInputWizardPage_elementName
);
856 label
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
858 elementNameText
= new Text(group
, SWT
.BORDER
| SWT
.SINGLE
);
859 GridData gd
= new GridData(SWT
.FILL
, SWT
.CENTER
, true, false);
861 elementNameText
.setLayoutData(gd
);
862 elementNameText
.addModifyListener(new ModifyListener() {
864 public void modifyText(ModifyEvent e
) {
865 ElementNode
.this.inputElement
.elementName
= elementNameText
.getText().trim();
866 group
.setText(getName(ElementNode
.this.inputElement
));
869 elementNameText
.setText(inputElement
.elementName
);
870 elementNameText
.addModifyListener(updateListener
);
872 if (inputElement
.parentElement
!= null) {
873 previewLabel
= new Label(group
, SWT
.NULL
);
874 previewLabel
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
875 previewLabel
.setText(Messages
.CustomXmlParserInputWizardPage_preview
);
877 previewText
= new Text(group
, SWT
.BORDER
| SWT
.SINGLE
| SWT
.READ_ONLY
);
878 gd
= new GridData(SWT
.FILL
, SWT
.CENTER
, true, false);
880 previewText
.setLayoutData(gd
);
881 previewText
.setText(Messages
.CustomXmlParserInputWizardPage_noMatchingElement
);
882 previewText
.setBackground(COLOR_WIDGET_BACKGROUND
);
884 logEntryButton
= new Button(group
, SWT
.CHECK
);
885 logEntryButton
.setText(Messages
.CustomXmlParserInputWizardPage_logEntry
);
886 logEntryButton
.setSelection(inputElement
.logEntry
);
887 logEntryButton
.addSelectionListener(new SelectionListener() {
889 public void widgetDefaultSelected(SelectionEvent e
) {
893 public void widgetSelected(SelectionEvent e
) {
894 InputElement parent
= ElementNode
.this.inputElement
.parentElement
;
895 while (parent
!= null) {
896 parent
.logEntry
= false;
897 parent
= parent
.parentElement
;
901 logEntryButton
.addSelectionListener(updateListener
);
903 tagComposite
= new Composite(group
, SWT
.FILL
);
904 GridLayout tagLayout
= new GridLayout(4, false);
905 tagLayout
.marginWidth
= 0;
906 tagLayout
.marginHeight
= 0;
907 tagComposite
.setLayout(tagLayout
);
908 tagComposite
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
910 tagCombo
= new Combo(tagComposite
, SWT
.DROP_DOWN
| SWT
.READ_ONLY
);
911 tagCombo
.setItems(new String
[] { CustomXmlTraceDefinition
.TAG_IGNORE
, CustomXmlTraceDefinition
.TAG_TIMESTAMP
,
912 CustomXmlTraceDefinition
.TAG_MESSAGE
, CustomXmlTraceDefinition
.TAG_OTHER
});
913 tagCombo
.setVisibleItemCount(tagCombo
.getItemCount());
914 tagCombo
.addSelectionListener(new SelectionListener() {
916 public void widgetDefaultSelected(SelectionEvent e
) {
920 public void widgetSelected(SelectionEvent e
) {
921 tagText
.removeModifyListener(updateListener
);
922 switch (tagCombo
.getSelectionIndex()) {
924 tagLabel
.setVisible(false);
925 tagText
.setVisible(false);
926 actionCombo
.setVisible(false);
928 case 1: // Time Stamp
929 tagLabel
.setText(Messages
.CustomXmlParserInputWizardPage_format
);
930 tagLabel
.setVisible(true);
931 tagText
.setVisible(true);
932 tagText
.addModifyListener(updateListener
);
933 actionCombo
.setVisible(true);
936 tagLabel
.setVisible(false);
937 tagText
.setVisible(false);
938 actionCombo
.setVisible(true);
941 tagLabel
.setText(Messages
.CustomXmlParserInputWizardPage_tagName
);
942 tagLabel
.setVisible(true);
943 if (tagText
.getText().trim().length() == 0) {
944 tagText
.setText(elementNameText
.getText().trim());
946 tagText
.setVisible(true);
947 tagText
.addModifyListener(updateListener
);
948 actionCombo
.setVisible(true);
951 tagComposite
.layout();
957 tagLabel
= new Label(tagComposite
, SWT
.NULL
);
958 tagLabel
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
960 tagText
= new Text(tagComposite
, SWT
.BORDER
| SWT
.SINGLE
);
961 gd
= new GridData(SWT
.FILL
, SWT
.CENTER
, true, false);
963 tagText
.setLayoutData(gd
);
965 actionCombo
= new Combo(tagComposite
, SWT
.DROP_DOWN
| SWT
.READ_ONLY
);
966 actionCombo
.setItems(new String
[] { Messages
.CustomXmlParserInputWizardPage_set
, Messages
.CustomXmlParserInputWizardPage_append
,
967 Messages
.CustomXmlParserInputWizardPage_appendWith
});
968 actionCombo
.select(inputElement
.inputAction
);
969 actionCombo
.addSelectionListener(updateListener
);
971 if (inputElement
.inputName
.equals(CustomXmlTraceDefinition
.TAG_IGNORE
)) {
973 tagLabel
.setVisible(false);
974 tagText
.setVisible(false);
975 actionCombo
.setVisible(false);
976 } else if (inputElement
.inputName
.equals(CustomXmlTraceDefinition
.TAG_TIMESTAMP
)) {
978 tagLabel
.setText(Messages
.CustomXmlParserInputWizardPage_format
);
979 tagText
.setText(inputElement
.inputFormat
);
980 tagText
.addModifyListener(updateListener
);
981 } else if (inputElement
.inputName
.equals(CustomXmlTraceDefinition
.TAG_MESSAGE
)) {
983 tagLabel
.setVisible(false);
984 tagText
.setVisible(false);
987 tagLabel
.setText(Messages
.CustomXmlParserInputWizardPage_tagName
);
988 tagText
.setText(inputElement
.inputName
);
989 tagText
.addModifyListener(updateListener
);
993 if (inputElement
.attributes
!= null) {
994 for (InputAttribute inputAttribute
: inputElement
.attributes
) {
995 Attribute attribute
= new Attribute(group
, this, inputAttribute
, attributes
.size() + 1);
996 attributes
.add(attribute
);
1003 private void updatePreview() {
1004 Element element
= getPreviewElement(inputElement
);
1005 if (inputElement
.parentElement
!= null) { // no preview text for
1007 previewText
.setText(Messages
.CustomXmlParserInputWizardPage_noMatchingElement
);
1008 if (element
!= null) {
1009 previewText
.setText(CustomXmlTrace
.parseElement(element
, new StringBuffer()).toString());
1010 if (logEntryButton
.getSelection()) {
1011 if (!logEntryFound
) {
1012 logEntryFound
= true;
1015 logEntryButton
.setSelection(false); // remove nested
1019 if (tagCombo
.getText().equals(CustomXmlTraceDefinition
.TAG_TIMESTAMP
) && logEntriesCount
<= 1) {
1020 String value
= previewText
.getText().trim();
1021 if (value
.length() != 0) {
1022 if (actionCombo
.getSelectionIndex() == CustomXmlTraceDefinition
.ACTION_SET
) {
1023 timeStampValue
= value
;
1024 timeStampFormat
= tagText
.getText().trim();
1025 } else if (actionCombo
.getSelectionIndex() == CustomXmlTraceDefinition
.ACTION_APPEND
) {
1026 if (timeStampValue
!= null) {
1027 timeStampValue
+= value
;
1028 timeStampFormat
+= tagText
.getText().trim();
1030 timeStampValue
= value
;
1031 timeStampFormat
= tagText
.getText().trim();
1033 } else if (actionCombo
.getSelectionIndex() == CustomXmlTraceDefinition
.ACTION_APPEND_WITH_SEPARATOR
) {
1034 if (timeStampValue
!= null) {
1035 timeStampValue
+= " | " + value
; //$NON-NLS-1$
1036 timeStampFormat
+= " | " + tagText
.getText().trim(); //$NON-NLS-1$
1038 timeStampValue
= value
;
1039 timeStampFormat
= tagText
.getText().trim();
1046 for (Attribute attribute
: attributes
) {
1047 if (element
!= null) {
1048 String value
= element
.getAttribute(attribute
.attributeNameText
.getText().trim());
1049 if (value
.length() != 0) {
1050 attribute
.previewText
.setText(value
);
1051 if (attribute
.tagCombo
.getText().equals(CustomXmlTraceDefinition
.TAG_TIMESTAMP
) && logEntriesCount
<= 1) {
1052 if (attribute
.actionCombo
.getSelectionIndex() == CustomXmlTraceDefinition
.ACTION_SET
) {
1053 timeStampValue
= value
;
1054 timeStampFormat
= attribute
.tagText
.getText().trim();
1055 } else if (attribute
.actionCombo
.getSelectionIndex() == CustomXmlTraceDefinition
.ACTION_APPEND
) {
1056 if (timeStampValue
!= null) {
1057 timeStampValue
+= value
;
1058 timeStampFormat
+= attribute
.tagText
.getText().trim();
1060 timeStampValue
= value
;
1061 timeStampFormat
= attribute
.tagText
.getText().trim();
1063 } else if (attribute
.actionCombo
.getSelectionIndex() == CustomXmlTraceDefinition
.ACTION_APPEND_WITH_SEPARATOR
) {
1064 if (timeStampValue
!= null) {
1065 timeStampValue
+= " | " + value
; //$NON-NLS-1$
1066 timeStampFormat
+= " | " + attribute
.tagText
.getText().trim(); //$NON-NLS-1$
1068 timeStampValue
= value
;
1069 timeStampFormat
= attribute
.tagText
.getText().trim();
1074 attribute
.previewText
.setText(Messages
.CustomXmlParserInputWizardPage_noMatchingAttribute
);
1077 attribute
.previewText
.setText(Messages
.CustomXmlParserInputWizardPage_noMatchingElement
);
1080 for (ElementNode child
: childElements
) {
1081 child
.updatePreview();
1083 if (logEntryButton
!= null && logEntryButton
.getSelection()) {
1084 logEntryFound
= false;
1088 private void createAddButton() {
1089 fillerLabel
= new Label(group
, SWT
.NONE
);
1091 addAttributeComposite
= new Composite(group
, SWT
.NONE
);
1092 addAttributeComposite
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
1093 GridLayout addAttributeLayout
= new GridLayout(2, false);
1094 addAttributeLayout
.marginHeight
= 0;
1095 addAttributeLayout
.marginWidth
= 0;
1096 addAttributeComposite
.setLayout(addAttributeLayout
);
1098 addAttributeButton
= new Button(addAttributeComposite
, SWT
.PUSH
);
1099 addAttributeButton
.setImage(addImage
);
1100 addAttributeButton
.setToolTipText(Messages
.CustomXmlParserInputWizardPage_addAttribute
);
1101 addAttributeButton
.addSelectionListener(new SelectionAdapter() {
1103 public void widgetSelected(SelectionEvent e
) {
1105 String attributeName
= getAttributeNameSuggestion(inputElement
);
1106 InputAttribute inputAttribute
= new InputAttribute(attributeName
, attributeName
, 0, ""); //$NON-NLS-1$
1107 attributes
.add(new Attribute(group
, ElementNode
.this, inputAttribute
, attributes
.size() + 1));
1109 elementContainer
.layout();
1110 elementScrolledComposite
.setMinSize(elementContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).x
,
1111 elementContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).y
- 1);
1112 group
.getParent().layout();
1118 addAttributeLabel
= new Label(addAttributeComposite
, SWT
.NULL
);
1119 addAttributeLabel
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
1120 addAttributeLabel
.setText(Messages
.CustomXmlParserInputWizardPage_newAttibute
);
1123 private void removeAddButton() {
1124 fillerLabel
.dispose();
1125 addAttributeComposite
.dispose();
1128 private void removeAttribute(int attributeNumber
) {
1129 if (--attributeNumber
< attributes
.size()) {
1130 attributes
.remove(attributeNumber
).dispose();
1131 for (int i
= attributeNumber
; i
< attributes
.size(); i
++) {
1132 attributes
.get(i
).setAttributeNumber(i
+ 1);
1134 elementContainer
.layout();
1135 elementScrolledComposite
.setMinSize(elementContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).x
,
1136 elementContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).y
- 1);
1137 group
.getParent().layout();
1141 private void dispose() {
1145 private void extractInputs() {
1146 inputElement
.elementName
= elementNameText
.getText().trim();
1147 if (inputElement
.parentElement
!= null) {
1148 inputElement
.logEntry
= logEntryButton
.getSelection();
1149 if (tagCombo
.getText().equals(CustomXmlTraceDefinition
.TAG_OTHER
)) {
1150 inputElement
.inputName
= tagText
.getText().trim();
1152 inputElement
.inputName
= tagCombo
.getText();
1153 if (tagCombo
.getText().equals(CustomXmlTraceDefinition
.TAG_TIMESTAMP
)) {
1154 inputElement
.inputFormat
= tagText
.getText().trim();
1157 inputElement
.inputAction
= actionCombo
.getSelectionIndex();
1159 inputElement
.attributes
= new ArrayList
<InputAttribute
>(attributes
.size());
1160 for (int i
= 0; i
< attributes
.size(); i
++) {
1161 Attribute attribute
= attributes
.get(i
);
1162 InputAttribute inputAttribute
= new InputAttribute();
1163 inputAttribute
.attributeName
= attribute
.attributeNameText
.getText().trim();
1164 if (attribute
.tagCombo
.getText().equals(CustomXmlTraceDefinition
.TAG_OTHER
)) {
1165 inputAttribute
.inputName
= attribute
.tagText
.getText().trim();
1167 inputAttribute
.inputName
= attribute
.tagCombo
.getText();
1168 if (attribute
.tagCombo
.getText().equals(CustomXmlTraceDefinition
.TAG_TIMESTAMP
)) {
1169 inputAttribute
.inputFormat
= attribute
.tagText
.getText().trim();
1172 inputAttribute
.inputAction
= attribute
.actionCombo
.getSelectionIndex();
1173 inputElement
.addAttribute(inputAttribute
);
1178 private class Attribute
{
1179 ElementNode element
;
1180 int attributeNumber
;
1182 // children of parent (must be disposed)
1183 Composite labelComposite
;
1184 Composite attributeComposite
;
1186 Composite tagComposite
;
1188 // children of labelComposite
1189 Label attributeLabel
;
1191 // children of attributeComposite
1192 Text attributeNameText
;
1195 // children of tagComposite
1201 public Attribute(Composite parent
, ElementNode element
, InputAttribute inputAttribute
, int attributeNumber
) {
1202 this.element
= element
;
1203 this.attributeNumber
= attributeNumber
;
1205 labelComposite
= new Composite(parent
, SWT
.FILL
);
1206 GridLayout labelLayout
= new GridLayout(2, false);
1207 labelLayout
.marginWidth
= 0;
1208 labelLayout
.marginHeight
= 0;
1209 labelComposite
.setLayout(labelLayout
);
1210 labelComposite
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
1212 Button deleteButton
= new Button(labelComposite
, SWT
.PUSH
);
1213 deleteButton
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
1214 deleteButton
.setImage(deleteImage
);
1215 deleteButton
.setToolTipText(Messages
.CustomXmlParserInputWizardPage_removeAttribute
);
1216 deleteButton
.addSelectionListener(new SelectionAdapter() {
1218 public void widgetSelected(SelectionEvent e
) {
1219 Attribute
.this.element
.removeAttribute(Attribute
.this.attributeNumber
);
1225 attributeLabel
= new Label(labelComposite
, SWT
.NULL
);
1226 attributeLabel
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
1227 attributeLabel
.setText(Messages
.CustomXmlParserInputWizardPage_attibute
);
1229 attributeComposite
= new Composite(parent
, SWT
.FILL
);
1230 GridLayout attributeLayout
= new GridLayout(4, false);
1231 attributeLayout
.marginWidth
= 0;
1232 attributeLayout
.marginHeight
= 0;
1233 attributeComposite
.setLayout(attributeLayout
);
1234 attributeComposite
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
1236 Label nameLabel
= new Label(attributeComposite
, SWT
.NONE
);
1237 nameLabel
.setText(Messages
.CustomXmlParserInputWizardPage_name
);
1239 attributeNameText
= new Text(attributeComposite
, SWT
.BORDER
| SWT
.SINGLE
);
1240 attributeNameText
.setLayoutData(new GridData(120, SWT
.DEFAULT
));
1241 attributeNameText
.setText(inputAttribute
.attributeName
);
1242 attributeNameText
.addModifyListener(updateListener
);
1244 Label previewLabel
= new Label(attributeComposite
, SWT
.NONE
);
1245 previewLabel
.setText(Messages
.CustomXmlParserInputWizardPage_preview
);
1247 previewText
= new Text(attributeComposite
, SWT
.BORDER
| SWT
.SINGLE
| SWT
.READ_ONLY
);
1248 GridData gd
= new GridData(SWT
.FILL
, SWT
.CENTER
, true, false);
1250 previewText
.setLayoutData(gd
);
1251 previewText
.setText(Messages
.CustomXmlParserInputWizardPage_noMatch
);
1252 previewText
.setBackground(COLOR_WIDGET_BACKGROUND
);
1254 filler
= new Label(parent
, SWT
.NULL
);
1256 tagComposite
= new Composite(parent
, SWT
.FILL
);
1257 GridLayout tagLayout
= new GridLayout(4, false);
1258 tagLayout
.marginWidth
= 0;
1259 tagLayout
.marginHeight
= 0;
1260 tagComposite
.setLayout(tagLayout
);
1261 tagComposite
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
1263 tagCombo
= new Combo(tagComposite
, SWT
.DROP_DOWN
| SWT
.READ_ONLY
);
1264 tagCombo
.setItems(new String
[] { CustomXmlTraceDefinition
.TAG_TIMESTAMP
, CustomXmlTraceDefinition
.TAG_MESSAGE
,
1265 CustomXmlTraceDefinition
.TAG_OTHER
});
1266 tagCombo
.select(2); // Other
1267 tagCombo
.addSelectionListener(new SelectionListener() {
1269 public void widgetDefaultSelected(SelectionEvent e
) {
1273 public void widgetSelected(SelectionEvent e
) {
1274 tagText
.removeModifyListener(updateListener
);
1275 switch (tagCombo
.getSelectionIndex()) {
1276 case 0: // Time Stamp
1277 tagLabel
.setText(Messages
.CustomXmlParserInputWizardPage_format
);
1278 tagLabel
.setVisible(true);
1279 tagText
.setVisible(true);
1280 tagText
.addModifyListener(updateListener
);
1283 tagLabel
.setVisible(false);
1284 tagText
.setVisible(false);
1287 tagLabel
.setText(Messages
.CustomXmlParserInputWizardPage_tagName
);
1288 tagLabel
.setVisible(true);
1289 if (tagText
.getText().trim().length() == 0) {
1290 tagText
.setText(attributeNameText
.getText().trim());
1292 tagText
.setVisible(true);
1293 tagText
.addModifyListener(updateListener
);
1296 tagComposite
.layout();
1302 tagLabel
= new Label(tagComposite
, SWT
.NULL
);
1303 tagLabel
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
1305 tagText
= new Text(tagComposite
, SWT
.BORDER
| SWT
.SINGLE
);
1306 gd
= new GridData(SWT
.FILL
, SWT
.CENTER
, true, false);
1308 tagText
.setLayoutData(gd
);
1309 tagText
.setText(attributeNameText
.getText());
1311 actionCombo
= new Combo(tagComposite
, SWT
.DROP_DOWN
| SWT
.READ_ONLY
);
1312 actionCombo
.setItems(new String
[] { Messages
.CustomXmlParserInputWizardPage_set
, Messages
.CustomXmlParserInputWizardPage_append
,
1313 Messages
.CustomXmlParserInputWizardPage_appendWith
});
1314 actionCombo
.select(inputAttribute
.inputAction
);
1315 actionCombo
.addSelectionListener(updateListener
);
1317 if (inputAttribute
.inputName
.equals(CustomXmlTraceDefinition
.TAG_TIMESTAMP
)) {
1319 tagLabel
.setText(Messages
.CustomXmlParserInputWizardPage_format
);
1320 tagText
.setText(inputAttribute
.inputFormat
);
1321 tagText
.addModifyListener(updateListener
);
1322 } else if (inputAttribute
.inputName
.equals(CustomXmlTraceDefinition
.TAG_MESSAGE
)) {
1324 tagLabel
.setVisible(false);
1325 tagText
.setVisible(false);
1328 tagLabel
.setText(Messages
.CustomXmlParserInputWizardPage_tagName
);
1329 tagText
.setText(inputAttribute
.inputName
);
1330 tagText
.addModifyListener(updateListener
);
1334 private void dispose() {
1335 labelComposite
.dispose();
1336 attributeComposite
.dispose();
1338 tagComposite
.dispose();
1341 private void setAttributeNumber(int attributeNumber
) {
1342 this.attributeNumber
= attributeNumber
;
1343 labelComposite
.layout();
1347 private Element
getPreviewElement(InputElement inputElement
) {
1348 Element element
= documentElement
;
1349 if (element
!= null) {
1350 if (!documentElement
.getNodeName().equals(definition
.rootInputElement
.elementName
)) {
1353 ArrayList
<String
> elementNames
= new ArrayList
<String
>();
1354 while (inputElement
!= null) {
1355 elementNames
.add(inputElement
.elementName
);
1356 inputElement
= inputElement
.parentElement
;
1358 for (int i
= elementNames
.size() - 1; --i
>= 0;) {
1359 NodeList childList
= element
.getChildNodes();
1361 for (int j
= 0; j
< childList
.getLength(); j
++) {
1362 Node child
= childList
.item(j
);
1363 if (child
instanceof Element
&& child
.getNodeName().equals(elementNames
.get(i
))) {
1364 element
= (Element
) child
;
1368 if (element
== null) {
1372 if (element
!= null) {
1379 private String
getChildNameSuggestion(InputElement inputElement
) {
1380 if (inputElement
== null) {
1381 if (documentElement
!= null) {
1382 return documentElement
.getNodeName();
1385 Element element
= getPreviewElement(inputElement
);
1386 if (element
!= null) {
1387 NodeList childNodes
= element
.getChildNodes();
1388 for (int i
= 0; i
< childNodes
.getLength(); i
++) {
1389 Node node
= childNodes
.item(i
);
1390 if (node
instanceof Element
) {
1391 boolean unused
= true;
1392 if (inputElement
.childElements
!= null) {
1393 for (InputElement child
: inputElement
.childElements
) {
1394 if (child
.elementName
.equals(node
.getNodeName())) {
1401 return node
.getNodeName();
1407 return ""; //$NON-NLS-1$
1410 private String
getAttributeNameSuggestion(InputElement inputElement
) {
1411 Element element
= getPreviewElement(inputElement
);
1412 if (element
!= null) {
1413 NamedNodeMap attributeMap
= element
.getAttributes();
1414 for (int i
= 0; i
< attributeMap
.getLength(); i
++) {
1415 Node node
= attributeMap
.item(i
);
1416 boolean unused
= true;
1417 if (inputElement
.attributes
!= null) {
1418 for (InputAttribute attribute
: inputElement
.attributes
) {
1419 if (attribute
.attributeName
.equals(node
.getNodeName())) {
1426 return node
.getNodeName();
1430 return ""; //$NON-NLS-1$
1433 private void validate() {
1434 definition
.definitionName
= logtypeText
.getText().trim();
1435 definition
.timeStampOutputFormat
= timeStampOutputFormatText
.getText().trim();
1437 if (selectedElement
!= null) {
1438 selectedElement
.extractInputs();
1439 treeViewer
.refresh();
1442 StringBuffer errors
= new StringBuffer();
1444 if (definition
.definitionName
.length() == 0) {
1445 errors
.append(Messages
.CustomXmlParserInputWizardPage_emptyLogTypeError
);
1446 logtypeText
.setBackground(COLOR_LIGHT_RED
);
1448 logtypeText
.setBackground(COLOR_TEXT_BACKGROUND
);
1449 for (CustomXmlTraceDefinition def
: CustomXmlTraceDefinition
.loadAll()) {
1450 if (definition
.definitionName
.equals(def
.definitionName
)) {
1451 if (editDefinitionName
== null || !editDefinitionName
.equals(definition
.definitionName
)) {
1452 errors
.append(Messages
.CustomXmlParserInputWizardPage_duplicatelogTypeError
);
1453 logtypeText
.setBackground(COLOR_LIGHT_RED
);
1460 if (definition
.rootInputElement
== null) {
1461 errors
.append(Messages
.CustomXmlParserInputWizardPage_noDocumentError
);
1464 if (definition
.rootInputElement
!= null) {
1465 logEntryFound
= false;
1466 timeStampFound
= false;
1468 errors
.append(validateElement(definition
.rootInputElement
));
1470 if ((definition
.rootInputElement
.attributes
!= null && definition
.rootInputElement
.attributes
.size() != 0)
1471 || (definition
.rootInputElement
.childElements
!= null && definition
.rootInputElement
.childElements
.size() != 0)
1472 || errors
.length() == 0) {
1473 if (!logEntryFound
) {
1474 errors
.append(Messages
.CustomXmlParserInputWizardPage_missingLogEntryError
);
1477 if (timeStampFound
) {
1478 if (timeStampOutputFormatText
.getText().trim().length() == 0) {
1479 errors
.append(Messages
.CustomXmlParserInputWizardPage_missingTimestampFmtError
);
1480 timeStampOutputFormatText
.setBackground(COLOR_LIGHT_RED
);
1483 new SimpleDateFormat(timeStampOutputFormatText
.getText().trim());
1484 timeStampOutputFormatText
.setBackground(COLOR_TEXT_BACKGROUND
);
1485 } catch (IllegalArgumentException e
) {
1486 errors
.append(Messages
.CustomXmlParserInputWizardPage_invalidTimestampFmtError
);
1487 timeStampOutputFormatText
.setBackground(COLOR_LIGHT_RED
);
1491 timeStampPreviewText
.setText(Messages
.CustomXmlParserInputWizardPage_notimestamporAttributeError
);
1495 timeStampPreviewText
.setText(Messages
.CustomXmlParserInputWizardPage_notimestamporAttributeError
);
1498 if (errors
.length() == 0) {
1499 setDescription(defaultDescription
);
1500 setPageComplete(true);
1502 setDescription(errors
.toString());
1503 setPageComplete(false);
1507 public StringBuffer
validateElement(InputElement inputElement
) {
1508 StringBuffer errors
= new StringBuffer();
1509 ElementNode elementNode
= null;
1510 if (selectedElement
!= null && selectedElement
.inputElement
.equals(inputElement
))
1511 elementNode
= selectedElement
;
1512 if (inputElement
== definition
.rootInputElement
) {
1513 if (inputElement
.elementName
.length() == 0) {
1514 errors
.append(Messages
.CustomXmlParserInputWizardPage_missingDocumentElementError
);
1515 if (elementNode
!= null)
1516 elementNode
.elementNameText
.setBackground(COLOR_LIGHT_RED
);
1518 if (elementNode
!= null)
1519 elementNode
.elementNameText
.setBackground(COLOR_TEXT_BACKGROUND
);
1522 if (inputElement
!= definition
.rootInputElement
) {
1523 if (inputElement
.logEntry
) {
1524 logEntryFound
= true;
1526 if (inputElement
.inputName
.equals(CustomXmlTraceDefinition
.TAG_TIMESTAMP
)) {
1527 timeStampFound
= true;
1528 if (inputElement
.inputFormat
.length() == 0) {
1529 errors
.append(Messages
.CustomXmlParserInputWizardPage_timestampFormatPrompt
1530 + " (" + Messages
.CustomXmlParserInputWizardPage_timestampElementPrompt
+ " " + getName(inputElement
) + "). "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
1531 if (elementNode
!= null)
1532 elementNode
.tagText
.setBackground(COLOR_LIGHT_RED
);
1535 new SimpleDateFormat(inputElement
.inputFormat
);
1536 if (elementNode
!= null)
1537 elementNode
.tagText
.setBackground(COLOR_TEXT_BACKGROUND
);
1538 } catch (IllegalArgumentException e
) {
1539 errors
.append(Messages
.CustomXmlParserInputWizardPage_invalidTimestampFmtError
1540 + " (" + Messages
.CustomXmlParserInputWizardPage_timestampElementPrompt
+ " " + getName(inputElement
) + "). "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
1541 if (elementNode
!= null)
1542 elementNode
.tagText
.setBackground(COLOR_LIGHT_RED
);
1545 } else if (inputElement
.inputName
.length() == 0) {
1546 errors
.append(Messages
.CustomXmlParserInputWizardPage_missingInputElementNameError
);
1547 if (elementNode
!= null)
1548 elementNode
.tagText
.setBackground(COLOR_LIGHT_RED
);
1550 if (elementNode
!= null)
1551 elementNode
.tagText
.setBackground(COLOR_TEXT_BACKGROUND
);
1554 if (inputElement
.attributes
!= null) {
1555 if (elementNode
!= null) {
1556 for (Attribute attribute
: elementNode
.attributes
) {
1557 attribute
.attributeNameText
.setBackground(COLOR_TEXT_BACKGROUND
);
1560 for (int i
= 0; i
< inputElement
.attributes
.size(); i
++) {
1561 InputAttribute attribute
= inputElement
.attributes
.get(i
);
1562 boolean duplicate
= false;
1563 for (int j
= i
+ 1; j
< inputElement
.attributes
.size(); j
++) {
1564 InputAttribute otherAttribute
= inputElement
.attributes
.get(j
);
1565 if (otherAttribute
.attributeName
.equals(attribute
.attributeName
)) {
1567 if (elementNode
!= null) {
1568 elementNode
.attributes
.get(j
).attributeNameText
.setBackground(COLOR_LIGHT_RED
);
1572 if (attribute
.attributeName
.length() == 0) {
1573 errors
.append(Messages
.CustomXmlParserInputWizardPage_missingAttribute
1574 + " (" + Messages
.CustomXmlParserInputWizardPage_attributePrompt
+ " " + getName(inputElement
) + ": ?). "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
1575 if (elementNode
!= null)
1576 elementNode
.attributes
.get(i
).attributeNameText
.setBackground(COLOR_LIGHT_RED
);
1577 } else if (duplicate
) {
1578 errors
.append(Messages
.CustomXmlParserInputWizardPage_duplicateAttributeError
1579 + " (" + Messages
.CustomXmlParserInputWizardPage_attributePrompt
+ " " + getName(attribute
, inputElement
) + "). "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
1580 if (elementNode
!= null)
1581 elementNode
.attributes
.get(i
).attributeNameText
.setBackground(COLOR_LIGHT_RED
);
1583 if (attribute
.inputName
.equals(CustomXmlTraceDefinition
.TAG_TIMESTAMP
)) {
1584 timeStampFound
= true;
1585 if (attribute
.inputFormat
.length() == 0) {
1586 errors
.append(Messages
.CustomXmlParserInputWizardPage_missingTimestampInFmtError
1587 + " (" + Messages
.CustomXmlParserInputWizardPage_attributePrompt
+ " " + getName(attribute
, inputElement
) + "). "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
1588 if (elementNode
!= null)
1589 elementNode
.attributes
.get(i
).tagText
.setBackground(COLOR_LIGHT_RED
);
1592 new SimpleDateFormat(attribute
.inputFormat
);
1593 if (elementNode
!= null)
1594 elementNode
.attributes
.get(i
).tagText
.setBackground(COLOR_TEXT_BACKGROUND
);
1595 } catch (IllegalArgumentException e
) {
1596 errors
.append(Messages
.CustomXmlParserInputWizardPage_invalidTimestampInFmtError
1597 + " (" + Messages
.CustomXmlParserInputWizardPage_attributePrompt
+ " " + getName(attribute
, inputElement
) + "). "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
1598 if (elementNode
!= null)
1599 elementNode
.attributes
.get(i
).tagText
.setBackground(COLOR_LIGHT_RED
);
1602 } else if (attribute
.inputName
.length() == 0) {
1603 errors
.append(Messages
.CustomXmlParserInputWizardPage_missingDataGroupNameError
1604 + " (" + Messages
.CustomXmlParserInputWizardPage_attributePrompt
+ " " + getName(attribute
, inputElement
) + "). "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
1605 if (elementNode
!= null)
1606 elementNode
.attributes
.get(i
).tagText
.setBackground(COLOR_LIGHT_RED
);
1608 if (elementNode
!= null)
1609 elementNode
.attributes
.get(i
).tagText
.setBackground(COLOR_TEXT_BACKGROUND
);
1613 if (inputElement
.childElements
!= null) {
1614 for (InputElement child
: inputElement
.childElements
) {
1615 ElementNode childElementNode
= null;
1616 if (selectedElement
!= null && selectedElement
.inputElement
.equals(child
))
1617 childElementNode
= selectedElement
;
1618 if (childElementNode
!= null)
1619 childElementNode
.elementNameText
.setBackground(COLOR_TEXT_BACKGROUND
);
1621 for (int i
= 0; i
< inputElement
.childElements
.size(); i
++) {
1622 InputElement child
= inputElement
.childElements
.get(i
);
1623 ElementNode childElementNode
= null;
1624 if (selectedElement
!= null && selectedElement
.inputElement
.equals(child
))
1625 childElementNode
= selectedElement
;
1626 if (child
.elementName
.length() == 0) {
1627 errors
.append(Messages
.CustomXmlParserInputWizardPage_missingElementNameError
1628 + " (" + Messages
.CustomXmlParserInputWizardPage_attributePrompt
+ " " + getName(child
) + "). "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
1629 if (childElementNode
!= null)
1630 childElementNode
.elementNameText
.setBackground(COLOR_LIGHT_RED
);
1632 boolean duplicate
= false;
1633 for (int j
= i
+ 1; j
< inputElement
.childElements
.size(); j
++) {
1634 InputElement otherChild
= inputElement
.childElements
.get(j
);
1635 if (otherChild
.elementName
.equals(child
.elementName
)) {
1637 ElementNode otherChildElementNode
= null;
1638 if (selectedElement
!= null && selectedElement
.inputElement
.equals(otherChild
))
1639 otherChildElementNode
= selectedElement
;
1640 if (otherChildElementNode
!= null)
1641 otherChildElementNode
.elementNameText
.setBackground(COLOR_LIGHT_RED
);
1645 errors
.append(Messages
.CustomXmlParserInputWizardPage_duplicateElementNameError
1646 + " (" + Messages
.CustomXmlParserInputWizardPage_attributePrompt
+ " " + getName(child
) + "). "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
1647 if (childElementNode
!= null)
1648 childElementNode
.elementNameText
.setBackground(COLOR_LIGHT_RED
);
1652 errors
.append(validateElement(child
));
1658 public CustomXmlTraceDefinition
getDefinition() {
1662 public char[] getInputText() {
1663 return inputText
.getText().toCharArray();