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
.AbstractTreeViewer
;
21 import org
.eclipse
.jface
.viewers
.ColumnLabelProvider
;
22 import org
.eclipse
.jface
.viewers
.ISelection
;
23 import org
.eclipse
.jface
.viewers
.ISelectionChangedListener
;
24 import org
.eclipse
.jface
.viewers
.IStructuredSelection
;
25 import org
.eclipse
.jface
.viewers
.ITreeContentProvider
;
26 import org
.eclipse
.jface
.viewers
.SelectionChangedEvent
;
27 import org
.eclipse
.jface
.viewers
.StructuredSelection
;
28 import org
.eclipse
.jface
.viewers
.TreeViewer
;
29 import org
.eclipse
.jface
.viewers
.Viewer
;
30 import org
.eclipse
.jface
.wizard
.WizardPage
;
31 import org
.eclipse
.linuxtools
.internal
.tmf
.ui
.Activator
;
32 import org
.eclipse
.linuxtools
.internal
.tmf
.ui
.Messages
;
33 import org
.eclipse
.linuxtools
.internal
.tmf
.ui
.parsers
.custom
.CustomTraceDefinition
;
34 import org
.eclipse
.linuxtools
.internal
.tmf
.ui
.parsers
.custom
.CustomXmlTrace
;
35 import org
.eclipse
.linuxtools
.internal
.tmf
.ui
.parsers
.custom
.CustomXmlTraceDefinition
;
36 import org
.eclipse
.linuxtools
.internal
.tmf
.ui
.parsers
.custom
.CustomXmlTraceDefinition
.InputAttribute
;
37 import org
.eclipse
.linuxtools
.internal
.tmf
.ui
.parsers
.custom
.CustomXmlTraceDefinition
.InputElement
;
38 import org
.eclipse
.swt
.SWT
;
39 import org
.eclipse
.swt
.browser
.Browser
;
40 import org
.eclipse
.swt
.browser
.TitleEvent
;
41 import org
.eclipse
.swt
.browser
.TitleListener
;
42 import org
.eclipse
.swt
.custom
.SashForm
;
43 import org
.eclipse
.swt
.custom
.ScrolledComposite
;
44 import org
.eclipse
.swt
.custom
.StyleRange
;
45 import org
.eclipse
.swt
.custom
.StyledText
;
46 import org
.eclipse
.swt
.events
.ModifyEvent
;
47 import org
.eclipse
.swt
.events
.ModifyListener
;
48 import org
.eclipse
.swt
.events
.SelectionAdapter
;
49 import org
.eclipse
.swt
.events
.SelectionEvent
;
50 import org
.eclipse
.swt
.events
.SelectionListener
;
51 import org
.eclipse
.swt
.graphics
.Color
;
52 import org
.eclipse
.swt
.graphics
.Font
;
53 import org
.eclipse
.swt
.graphics
.FontData
;
54 import org
.eclipse
.swt
.graphics
.Image
;
55 import org
.eclipse
.swt
.layout
.FillLayout
;
56 import org
.eclipse
.swt
.layout
.GridData
;
57 import org
.eclipse
.swt
.layout
.GridLayout
;
58 import org
.eclipse
.swt
.widgets
.Button
;
59 import org
.eclipse
.swt
.widgets
.Combo
;
60 import org
.eclipse
.swt
.widgets
.Composite
;
61 import org
.eclipse
.swt
.widgets
.Display
;
62 import org
.eclipse
.swt
.widgets
.Group
;
63 import org
.eclipse
.swt
.widgets
.Label
;
64 import org
.eclipse
.swt
.widgets
.Shell
;
65 import org
.eclipse
.swt
.widgets
.Text
;
66 import org
.w3c
.dom
.Document
;
67 import org
.w3c
.dom
.Element
;
68 import org
.w3c
.dom
.NamedNodeMap
;
69 import org
.w3c
.dom
.Node
;
70 import org
.w3c
.dom
.NodeList
;
71 import org
.xml
.sax
.EntityResolver
;
72 import org
.xml
.sax
.ErrorHandler
;
73 import org
.xml
.sax
.InputSource
;
74 import org
.xml
.sax
.SAXException
;
75 import org
.xml
.sax
.SAXParseException
;
77 public class CustomXmlParserInputWizardPage
extends WizardPage
{
79 private static final String DEFAULT_TIMESTAMP_FORMAT
= "yyyy-MM-dd HH:mm:ss.SSS"; //$NON-NLS-1$
80 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$
81 private static final Image elementImage
= Activator
.getDefault().getImageFromPath("/icons/elcl16/element_icon.gif"); //$NON-NLS-1$
82 private static final Image addImage
= Activator
.getDefault().getImageFromPath("/icons/elcl16/add_button.gif"); //$NON-NLS-1$
83 private static final Image addNextImage
= Activator
.getDefault().getImageFromPath("/icons/elcl16/addnext_button.gif"); //$NON-NLS-1$
84 private static final Image addChildImage
= Activator
.getDefault().getImageFromPath("/icons/elcl16/addchild_button.gif"); //$NON-NLS-1$
85 private static final Image addManyImage
= Activator
.getDefault().getImageFromPath("/icons/elcl16/addmany_button.gif"); //$NON-NLS-1$
86 private static final Image deleteImage
= Activator
.getDefault().getImageFromPath("/icons/elcl16/delete_button.gif"); //$NON-NLS-1$
87 private static final Image moveUpImage
= Activator
.getDefault().getImageFromPath("/icons/elcl16/moveup_button.gif"); //$NON-NLS-1$
88 private static final Image moveDownImage
= Activator
.getDefault().getImageFromPath("/icons/elcl16/movedown_button.gif"); //$NON-NLS-1$
89 private static final Image helpImage
= Activator
.getDefault().getImageFromPath("/icons/elcl16/help_button.gif"); //$NON-NLS-1$
90 private static final Color COLOR_LIGHT_RED
= new Color(Display
.getDefault(), 255, 192, 192);
91 private static final Color COLOR_TEXT_BACKGROUND
= Display
.getCurrent().getSystemColor(SWT
.COLOR_WHITE
);
92 private static final Color COLOR_WIDGET_BACKGROUND
= Display
.getCurrent().getSystemColor(SWT
.COLOR_WIDGET_BACKGROUND
);
94 private final ISelection selection
;
95 private CustomXmlTraceDefinition definition
;
96 private String editDefinitionName
;
97 private String defaultDescription
;
98 private ElementNode selectedElement
;
99 private Composite container
;
100 private Text logtypeText
;
101 private Text timeStampOutputFormatText
;
102 private Text timeStampPreviewText
;
103 private Button removeButton
;
104 private Button addChildButton
;
105 private Button addNextButton
;
106 private Button moveUpButton
;
107 private Button moveDownButton
;
108 private Button feelingLuckyButton
;
109 private ScrolledComposite treeScrolledComposite
;
110 private ScrolledComposite elementScrolledComposite
;
111 private TreeViewer treeViewer
;
112 private Composite treeContainer
;
113 private Composite elementContainer
;
114 private Text errorText
;
115 private StyledText inputText
;
116 private Font fixedFont
;
117 private UpdateListener updateListener
;
118 private Browser helpBrowser
;
119 private Element documentElement
;
121 // variables used recursively through element traversal
122 private String timeStampValue
;
123 private String timeStampFormat
;
124 private boolean timeStampFound
;
125 private int logEntriesCount
;
126 private boolean logEntryFound
;
128 protected CustomXmlParserInputWizardPage(ISelection selection
, CustomXmlTraceDefinition definition
) {
129 super("CustomXmlParserWizardPage"); //$NON-NLS-1$
130 if (definition
== null) {
131 setTitle(Messages
.CustomXmlParserInputWizardPage_titleNew
);
132 defaultDescription
= Messages
.CustomXmlParserInputWizardPage_descriptionNew
;
134 setTitle(Messages
.CustomXmlParserInputWizardPage_titleEdit
);
135 defaultDescription
= Messages
.CustomXmlParserInputWizardPage_descriptionEdit
;
137 setDescription(defaultDescription
);
138 this.selection
= selection
;
139 this.definition
= definition
;
140 if (definition
!= null) {
141 this.editDefinitionName
= definition
.definitionName
;
146 public void createControl(Composite parent
) {
147 container
= new Composite(parent
, SWT
.NULL
);
148 container
.setLayout(new GridLayout());
150 updateListener
= new UpdateListener();
152 Composite headerComposite
= new Composite(container
, SWT
.FILL
);
153 GridLayout headerLayout
= new GridLayout(5, false);
154 headerLayout
.marginHeight
= 0;
155 headerLayout
.marginWidth
= 0;
156 headerComposite
.setLayout(headerLayout
);
157 headerComposite
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
159 Label logtypeLabel
= new Label(headerComposite
, SWT
.NULL
);
160 logtypeLabel
.setText(Messages
.CustomXmlParserInputWizardPage_logType
);
162 logtypeText
= new Text(headerComposite
, SWT
.BORDER
| SWT
.SINGLE
);
163 logtypeText
.setLayoutData(new GridData(120, SWT
.DEFAULT
));
165 Label timeStampFormatLabel
= new Label(headerComposite
, SWT
.NULL
);
166 timeStampFormatLabel
.setText(Messages
.CustomXmlParserInputWizardPage_timestampFormat
);
168 timeStampOutputFormatText
= new Text(headerComposite
, SWT
.BORDER
| SWT
.SINGLE
);
169 timeStampOutputFormatText
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
170 timeStampOutputFormatText
.setText(DEFAULT_TIMESTAMP_FORMAT
);
172 Button dateFormatHelpButton
= new Button(headerComposite
, SWT
.PUSH
);
173 dateFormatHelpButton
.setImage(helpImage
);
174 dateFormatHelpButton
.setToolTipText(Messages
.CustomXmlParserInputWizardPage_dateFormatHelp
);
175 dateFormatHelpButton
.addSelectionListener(new SelectionAdapter() {
177 public void widgetSelected(SelectionEvent e
) {
178 openHelpShell(SIMPLE_DATE_FORMAT_URL
);
182 Label timeStampPreviewLabel
= new Label(headerComposite
, SWT
.NULL
);
183 timeStampPreviewLabel
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false, 3, 1));
184 timeStampPreviewLabel
.setText(Messages
.CustomXmlParserInputWizardPage_preview
);
186 timeStampPreviewText
= new Text(headerComposite
, SWT
.BORDER
| SWT
.SINGLE
| SWT
.READ_ONLY
);
187 timeStampPreviewText
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false, 2, 1));
188 timeStampPreviewText
.setText("*no time stamp element or attribute*"); //$NON-NLS-1$
192 SashForm vSash
= new SashForm(container
, SWT
.VERTICAL
);
193 vSash
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
194 vSash
.setBackground(vSash
.getDisplay().getSystemColor(SWT
.COLOR_GRAY
));
196 SashForm hSash
= new SashForm(vSash
, SWT
.HORIZONTAL
);
197 hSash
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
199 treeScrolledComposite
= new ScrolledComposite(hSash
, SWT
.V_SCROLL
| SWT
.H_SCROLL
);
200 treeScrolledComposite
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
201 treeContainer
= new Composite(treeScrolledComposite
, SWT
.NONE
);
202 treeContainer
.setLayout(new FillLayout());
203 treeScrolledComposite
.setContent(treeContainer
);
204 treeScrolledComposite
.setExpandHorizontal(true);
205 treeScrolledComposite
.setExpandVertical(true);
207 treeViewer
= new TreeViewer(treeContainer
, SWT
.SINGLE
| SWT
.BORDER
);
208 treeViewer
.setContentProvider(new InputElementTreeNodeContentProvider());
209 treeViewer
.setLabelProvider(new InputElementTreeLabelProvider());
210 treeViewer
.addSelectionChangedListener(new InputElementTreeSelectionChangedListener());
211 treeContainer
.layout();
213 treeScrolledComposite
214 .setMinSize(treeContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).x
, treeContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).y
);
216 elementScrolledComposite
= new ScrolledComposite(hSash
, SWT
.V_SCROLL
);
217 elementScrolledComposite
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
218 elementContainer
= new Composite(elementScrolledComposite
, SWT
.NONE
);
219 GridLayout gl
= new GridLayout();
222 elementContainer
.setLayout(gl
);
223 elementScrolledComposite
.setContent(elementContainer
);
224 elementScrolledComposite
.setExpandHorizontal(true);
225 elementScrolledComposite
.setExpandVertical(true);
227 if (definition
== null) {
228 definition
= new CustomXmlTraceDefinition();
230 loadDefinition(definition
);
231 treeViewer
.expandAll();
232 elementContainer
.layout();
234 logtypeText
.addModifyListener(updateListener
);
235 timeStampOutputFormatText
.addModifyListener(updateListener
);
237 elementScrolledComposite
.setMinSize(elementContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).x
,
238 elementContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).y
- 1);
240 hSash
.setWeights(new int[] { 1, 2 });
242 if (definition
.rootInputElement
== null) {
243 removeButton
.setEnabled(false);
244 addChildButton
.setToolTipText(Messages
.CustomXmlParserInputWizardPage_addDocumentElement
);
245 addNextButton
.setEnabled(false);
246 moveUpButton
.setEnabled(false);
247 moveDownButton
.setEnabled(false);
248 } else { // root is selected
249 addNextButton
.setEnabled(false);
252 Composite sashBottom
= new Composite(vSash
, SWT
.NONE
);
253 GridLayout sashBottomLayout
= new GridLayout(2, false);
254 sashBottomLayout
.marginHeight
= 0;
255 sashBottomLayout
.marginWidth
= 0;
256 sashBottom
.setLayout(sashBottomLayout
);
258 Label previewLabel
= new Label(sashBottom
, SWT
.NULL
);
259 previewLabel
.setText(Messages
.CustomXmlParserInputWizardPage_previewInput
);
261 errorText
= new Text(sashBottom
, SWT
.SINGLE
| SWT
.READ_ONLY
);
262 errorText
.setBackground(COLOR_WIDGET_BACKGROUND
);
263 errorText
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
264 errorText
.setVisible(false);
266 inputText
= new StyledText(sashBottom
, SWT
.MULTI
| SWT
.V_SCROLL
| SWT
.H_SCROLL
);
267 if (fixedFont
== null) {
268 if (System
.getProperty("os.name").contains("Windows")) { //$NON-NLS-1$ //$NON-NLS-2$
269 fixedFont
= new Font(Display
.getCurrent(), new FontData("Courier New", 10, SWT
.NORMAL
)); //$NON-NLS-1$
271 fixedFont
= new Font(Display
.getCurrent(), new FontData("Monospace", 10, SWT
.NORMAL
)); //$NON-NLS-1$
274 inputText
.setFont(fixedFont
);
275 GridData gd
= new GridData(SWT
.FILL
, SWT
.FILL
, true, true, 2, 1);
276 gd
.heightHint
= inputText
.computeSize(SWT
.DEFAULT
, inputText
.getLineHeight() * 4).y
;
278 inputText
.setLayoutData(gd
);
279 inputText
.setText(getSelectionText());
280 inputText
.addModifyListener(new ModifyListener() {
282 public void modifyText(ModifyEvent e
) {
283 parseXmlInput(inputText
.getText());
286 inputText
.addModifyListener(updateListener
);
288 vSash
.setWeights(new int[] { hSash
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).y
, sashBottom
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).y
});
290 setControl(container
);
293 private void createButtonBar() {
294 Composite buttonBar
= new Composite(container
, SWT
.NONE
);
295 GridLayout buttonBarLayout
= new GridLayout(6, false);
296 buttonBarLayout
.marginHeight
= 0;
297 buttonBarLayout
.marginWidth
= 0;
298 buttonBar
.setLayout(buttonBarLayout
);
300 removeButton
= new Button(buttonBar
, SWT
.PUSH
);
301 removeButton
.setImage(deleteImage
);
302 removeButton
.setToolTipText(Messages
.CustomXmlParserInputWizardPage_removeElement
);
303 removeButton
.addSelectionListener(new SelectionAdapter() {
305 public void widgetSelected(SelectionEvent e
) {
306 if (treeViewer
.getSelection().isEmpty() || selectedElement
== null) {
310 InputElement inputElement
= (InputElement
) ((IStructuredSelection
) treeViewer
.getSelection()).getFirstElement();
311 if (inputElement
== definition
.rootInputElement
) {
312 definition
.rootInputElement
= null;
314 inputElement
.parentElement
.childElements
.remove(inputElement
);
316 treeViewer
.refresh();
319 removeButton
.setEnabled(false);
320 if (definition
.rootInputElement
== null) {
321 addChildButton
.setEnabled(true);
322 addChildButton
.setToolTipText(Messages
.CustomXmlParserInputWizardPage_addDocumentEleemnt
);
324 addChildButton
.setEnabled(false);
326 addNextButton
.setEnabled(false);
327 moveUpButton
.setEnabled(false);
328 moveDownButton
.setEnabled(false);
332 addChildButton
= new Button(buttonBar
, SWT
.PUSH
);
333 addChildButton
.setImage(addChildImage
);
334 addChildButton
.setToolTipText(Messages
.CustomXmlParserInputWizardPage_addChildElement
);
335 addChildButton
.addSelectionListener(new SelectionAdapter() {
337 public void widgetSelected(SelectionEvent e
) {
338 InputElement inputElement
= new InputElement("", false, CustomXmlTraceDefinition
.TAG_IGNORE
, 0, "", null); //$NON-NLS-1$ //$NON-NLS-2$
339 if (definition
.rootInputElement
== null) {
340 definition
.rootInputElement
= inputElement
;
341 inputElement
.elementName
= getChildNameSuggestion(null);
342 } else if (treeViewer
.getSelection().isEmpty()) {
345 InputElement parentInputElement
= (InputElement
) ((IStructuredSelection
) treeViewer
.getSelection()).getFirstElement();
346 parentInputElement
.addChild(inputElement
);
347 inputElement
.elementName
= getChildNameSuggestion(parentInputElement
);
349 treeViewer
.refresh();
350 treeViewer
.setSelection(new StructuredSelection(inputElement
), true);
354 addNextButton
= new Button(buttonBar
, SWT
.PUSH
);
355 addNextButton
.setImage(addNextImage
);
356 addNextButton
.setToolTipText(Messages
.CustomXmlParserInputWizardPage_addNextElement
);
357 addNextButton
.addSelectionListener(new SelectionAdapter() {
359 public void widgetSelected(SelectionEvent e
) {
360 InputElement inputElement
= new InputElement("", false, CustomXmlTraceDefinition
.TAG_IGNORE
, 0, "", null); //$NON-NLS-1$ //$NON-NLS-2$
361 if (definition
.rootInputElement
== null) {
362 definition
.rootInputElement
= inputElement
;
363 inputElement
.elementName
= getChildNameSuggestion(null);
364 } else if (treeViewer
.getSelection().isEmpty()) {
367 InputElement previousInputElement
= (InputElement
) ((IStructuredSelection
) treeViewer
.getSelection()).getFirstElement();
368 if (previousInputElement
== definition
.rootInputElement
) {
371 previousInputElement
.addNext(inputElement
);
372 inputElement
.elementName
= getChildNameSuggestion(inputElement
.parentElement
);
374 treeViewer
.refresh();
375 treeViewer
.setSelection(new StructuredSelection(inputElement
), true);
379 feelingLuckyButton
= new Button(buttonBar
, SWT
.PUSH
);
380 feelingLuckyButton
.setImage(addManyImage
);
381 feelingLuckyButton
.setToolTipText(Messages
.CustomXmlParserInputWizardPage_feelingLucky
);
382 feelingLuckyButton
.addSelectionListener(new SelectionAdapter() {
384 public void widgetSelected(SelectionEvent e
) {
385 InputElement inputElement
= null;
386 if (definition
.rootInputElement
== null) {
387 if (getChildNameSuggestion(null).length() != 0) {
388 inputElement
= new InputElement(getChildNameSuggestion(null), false, CustomXmlTraceDefinition
.TAG_IGNORE
, 0, "", null); //$NON-NLS-1$
389 definition
.rootInputElement
= inputElement
;
390 feelingLucky(inputElement
);
394 } else if (treeViewer
.getSelection().isEmpty()) {
397 inputElement
= (InputElement
) ((IStructuredSelection
) treeViewer
.getSelection()).getFirstElement();
398 feelingLucky(inputElement
);
400 treeViewer
.refresh();
401 treeViewer
.setSelection(new StructuredSelection(inputElement
), true);
402 treeViewer
.expandToLevel(inputElement
, AbstractTreeViewer
.ALL_LEVELS
);
406 moveUpButton
= new Button(buttonBar
, SWT
.PUSH
);
407 moveUpButton
.setImage(moveUpImage
);
408 moveUpButton
.setToolTipText(Messages
.CustomXmlParserInputWizardPage_moveUp
);
409 moveUpButton
.addSelectionListener(new SelectionAdapter() {
411 public void widgetSelected(SelectionEvent e
) {
412 if (treeViewer
.getSelection().isEmpty()) {
415 InputElement inputElement
= (InputElement
) ((IStructuredSelection
) treeViewer
.getSelection()).getFirstElement();
416 if (inputElement
== definition
.rootInputElement
) {
419 inputElement
.moveUp();
420 treeViewer
.refresh();
426 moveDownButton
= new Button(buttonBar
, SWT
.PUSH
);
427 moveDownButton
.setImage(moveDownImage
);
428 moveDownButton
.setToolTipText(Messages
.CustomXmlParserInputWizardPage_moveDown
);
429 moveDownButton
.addSelectionListener(new SelectionAdapter() {
431 public void widgetSelected(SelectionEvent e
) {
432 if (treeViewer
.getSelection().isEmpty()) {
435 InputElement inputElement
= (InputElement
) ((IStructuredSelection
) treeViewer
.getSelection()).getFirstElement();
436 if (inputElement
== definition
.rootInputElement
) {
439 inputElement
.moveDown();
440 treeViewer
.refresh();
447 private void feelingLucky(InputElement inputElement
) {
449 String attributeName
= getAttributeNameSuggestion(inputElement
);
450 if (attributeName
.length() == 0) {
453 InputAttribute attribute
= new InputAttribute(attributeName
, attributeName
, 0, ""); //$NON-NLS-1$
454 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
);
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];
479 public Object
[] getChildren(Object parentElement
) {
480 InputElement inputElement
= (InputElement
) parentElement
;
481 if (inputElement
.childElements
== null) {
482 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
, CustomTraceDefinition
.TAG_TIMESTAMP
,
912 CustomTraceDefinition
.TAG_MESSAGE
, CustomTraceDefinition
.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);
953 tagComposite
.layout();
959 tagLabel
= new Label(tagComposite
, SWT
.NULL
);
960 tagLabel
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
962 tagText
= new Text(tagComposite
, SWT
.BORDER
| SWT
.SINGLE
);
963 gd
= new GridData(SWT
.FILL
, SWT
.CENTER
, true, false);
965 tagText
.setLayoutData(gd
);
967 actionCombo
= new Combo(tagComposite
, SWT
.DROP_DOWN
| SWT
.READ_ONLY
);
968 actionCombo
.setItems(new String
[] { Messages
.CustomXmlParserInputWizardPage_set
, Messages
.CustomXmlParserInputWizardPage_append
,
969 Messages
.CustomXmlParserInputWizardPage_appendWith
});
970 actionCombo
.select(inputElement
.inputAction
);
971 actionCombo
.addSelectionListener(updateListener
);
973 if (inputElement
.inputName
.equals(CustomXmlTraceDefinition
.TAG_IGNORE
)) {
975 tagLabel
.setVisible(false);
976 tagText
.setVisible(false);
977 actionCombo
.setVisible(false);
978 } else if (inputElement
.inputName
.equals(CustomTraceDefinition
.TAG_TIMESTAMP
)) {
980 tagLabel
.setText(Messages
.CustomXmlParserInputWizardPage_format
);
981 tagText
.setText(inputElement
.inputFormat
);
982 tagText
.addModifyListener(updateListener
);
983 } else if (inputElement
.inputName
.equals(CustomTraceDefinition
.TAG_MESSAGE
)) {
985 tagLabel
.setVisible(false);
986 tagText
.setVisible(false);
989 tagLabel
.setText(Messages
.CustomXmlParserInputWizardPage_tagName
);
990 tagText
.setText(inputElement
.inputName
);
991 tagText
.addModifyListener(updateListener
);
995 if (inputElement
.attributes
!= null) {
996 for (InputAttribute inputAttribute
: inputElement
.attributes
) {
997 Attribute attribute
= new Attribute(group
, this, inputAttribute
, attributes
.size() + 1);
998 attributes
.add(attribute
);
1005 private void updatePreview() {
1006 Element element
= getPreviewElement(inputElement
);
1007 if (inputElement
.parentElement
!= null) { // no preview text for
1009 previewText
.setText(Messages
.CustomXmlParserInputWizardPage_noMatchingElement
);
1010 if (element
!= null) {
1011 previewText
.setText(CustomXmlTrace
.parseElement(element
, new StringBuffer()).toString());
1012 if (logEntryButton
.getSelection()) {
1013 if (!logEntryFound
) {
1014 logEntryFound
= true;
1017 logEntryButton
.setSelection(false); // remove nested
1021 if (tagCombo
.getText().equals(CustomTraceDefinition
.TAG_TIMESTAMP
) && logEntriesCount
<= 1) {
1022 String value
= previewText
.getText().trim();
1023 if (value
.length() != 0) {
1024 if (actionCombo
.getSelectionIndex() == CustomTraceDefinition
.ACTION_SET
) {
1025 timeStampValue
= value
;
1026 timeStampFormat
= tagText
.getText().trim();
1027 } else if (actionCombo
.getSelectionIndex() == CustomTraceDefinition
.ACTION_APPEND
) {
1028 if (timeStampValue
!= null) {
1029 timeStampValue
+= value
;
1030 timeStampFormat
+= tagText
.getText().trim();
1032 timeStampValue
= value
;
1033 timeStampFormat
= tagText
.getText().trim();
1035 } else if (actionCombo
.getSelectionIndex() == CustomTraceDefinition
.ACTION_APPEND_WITH_SEPARATOR
) {
1036 if (timeStampValue
!= null) {
1037 timeStampValue
+= " | " + value
; //$NON-NLS-1$
1038 timeStampFormat
+= " | " + tagText
.getText().trim(); //$NON-NLS-1$
1040 timeStampValue
= value
;
1041 timeStampFormat
= tagText
.getText().trim();
1048 for (Attribute attribute
: attributes
) {
1049 if (element
!= null) {
1050 String value
= element
.getAttribute(attribute
.attributeNameText
.getText().trim());
1051 if (value
.length() != 0) {
1052 attribute
.previewText
.setText(value
);
1053 if (attribute
.tagCombo
.getText().equals(CustomTraceDefinition
.TAG_TIMESTAMP
) && logEntriesCount
<= 1) {
1054 if (attribute
.actionCombo
.getSelectionIndex() == CustomTraceDefinition
.ACTION_SET
) {
1055 timeStampValue
= value
;
1056 timeStampFormat
= attribute
.tagText
.getText().trim();
1057 } else if (attribute
.actionCombo
.getSelectionIndex() == CustomTraceDefinition
.ACTION_APPEND
) {
1058 if (timeStampValue
!= null) {
1059 timeStampValue
+= value
;
1060 timeStampFormat
+= attribute
.tagText
.getText().trim();
1062 timeStampValue
= value
;
1063 timeStampFormat
= attribute
.tagText
.getText().trim();
1065 } else if (attribute
.actionCombo
.getSelectionIndex() == CustomTraceDefinition
.ACTION_APPEND_WITH_SEPARATOR
) {
1066 if (timeStampValue
!= null) {
1067 timeStampValue
+= " | " + value
; //$NON-NLS-1$
1068 timeStampFormat
+= " | " + attribute
.tagText
.getText().trim(); //$NON-NLS-1$
1070 timeStampValue
= value
;
1071 timeStampFormat
= attribute
.tagText
.getText().trim();
1076 attribute
.previewText
.setText(Messages
.CustomXmlParserInputWizardPage_noMatchingAttribute
);
1079 attribute
.previewText
.setText(Messages
.CustomXmlParserInputWizardPage_noMatchingElement
);
1082 for (ElementNode child
: childElements
) {
1083 child
.updatePreview();
1085 if (logEntryButton
!= null && logEntryButton
.getSelection()) {
1086 logEntryFound
= false;
1090 private void createAddButton() {
1091 fillerLabel
= new Label(group
, SWT
.NONE
);
1093 addAttributeComposite
= new Composite(group
, SWT
.NONE
);
1094 addAttributeComposite
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
1095 GridLayout addAttributeLayout
= new GridLayout(2, false);
1096 addAttributeLayout
.marginHeight
= 0;
1097 addAttributeLayout
.marginWidth
= 0;
1098 addAttributeComposite
.setLayout(addAttributeLayout
);
1100 addAttributeButton
= new Button(addAttributeComposite
, SWT
.PUSH
);
1101 addAttributeButton
.setImage(addImage
);
1102 addAttributeButton
.setToolTipText(Messages
.CustomXmlParserInputWizardPage_addAttribute
);
1103 addAttributeButton
.addSelectionListener(new SelectionAdapter() {
1105 public void widgetSelected(SelectionEvent e
) {
1107 String attributeName
= getAttributeNameSuggestion(inputElement
);
1108 InputAttribute inputAttribute
= new InputAttribute(attributeName
, attributeName
, 0, ""); //$NON-NLS-1$
1109 attributes
.add(new Attribute(group
, ElementNode
.this, inputAttribute
, attributes
.size() + 1));
1111 elementContainer
.layout();
1112 elementScrolledComposite
.setMinSize(elementContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).x
,
1113 elementContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).y
- 1);
1114 group
.getParent().layout();
1120 addAttributeLabel
= new Label(addAttributeComposite
, SWT
.NULL
);
1121 addAttributeLabel
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
1122 addAttributeLabel
.setText(Messages
.CustomXmlParserInputWizardPage_newAttibute
);
1125 private void removeAddButton() {
1126 fillerLabel
.dispose();
1127 addAttributeComposite
.dispose();
1130 private void removeAttribute(int attributeNumber
) {
1131 if (--attributeNumber
< attributes
.size()) {
1132 attributes
.remove(attributeNumber
).dispose();
1133 for (int i
= attributeNumber
; i
< attributes
.size(); i
++) {
1134 attributes
.get(i
).setAttributeNumber(i
+ 1);
1136 elementContainer
.layout();
1137 elementScrolledComposite
.setMinSize(elementContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).x
,
1138 elementContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).y
- 1);
1139 group
.getParent().layout();
1143 private void dispose() {
1147 private void extractInputs() {
1148 inputElement
.elementName
= elementNameText
.getText().trim();
1149 if (inputElement
.parentElement
!= null) {
1150 inputElement
.logEntry
= logEntryButton
.getSelection();
1151 if (tagCombo
.getText().equals(CustomTraceDefinition
.TAG_OTHER
)) {
1152 inputElement
.inputName
= tagText
.getText().trim();
1154 inputElement
.inputName
= tagCombo
.getText();
1155 if (tagCombo
.getText().equals(CustomTraceDefinition
.TAG_TIMESTAMP
)) {
1156 inputElement
.inputFormat
= tagText
.getText().trim();
1159 inputElement
.inputAction
= actionCombo
.getSelectionIndex();
1161 inputElement
.attributes
= new ArrayList
<InputAttribute
>(attributes
.size());
1162 for (int i
= 0; i
< attributes
.size(); i
++) {
1163 Attribute attribute
= attributes
.get(i
);
1164 InputAttribute inputAttribute
= new InputAttribute();
1165 inputAttribute
.attributeName
= attribute
.attributeNameText
.getText().trim();
1166 if (attribute
.tagCombo
.getText().equals(CustomTraceDefinition
.TAG_OTHER
)) {
1167 inputAttribute
.inputName
= attribute
.tagText
.getText().trim();
1169 inputAttribute
.inputName
= attribute
.tagCombo
.getText();
1170 if (attribute
.tagCombo
.getText().equals(CustomTraceDefinition
.TAG_TIMESTAMP
)) {
1171 inputAttribute
.inputFormat
= attribute
.tagText
.getText().trim();
1174 inputAttribute
.inputAction
= attribute
.actionCombo
.getSelectionIndex();
1175 inputElement
.addAttribute(inputAttribute
);
1180 private class Attribute
{
1181 ElementNode element
;
1182 int attributeNumber
;
1184 // children of parent (must be disposed)
1185 Composite labelComposite
;
1186 Composite attributeComposite
;
1188 Composite tagComposite
;
1190 // children of labelComposite
1191 Label attributeLabel
;
1193 // children of attributeComposite
1194 Text attributeNameText
;
1197 // children of tagComposite
1203 public Attribute(Composite parent
, ElementNode element
, InputAttribute inputAttribute
, int attributeNumber
) {
1204 this.element
= element
;
1205 this.attributeNumber
= attributeNumber
;
1207 labelComposite
= new Composite(parent
, SWT
.FILL
);
1208 GridLayout labelLayout
= new GridLayout(2, false);
1209 labelLayout
.marginWidth
= 0;
1210 labelLayout
.marginHeight
= 0;
1211 labelComposite
.setLayout(labelLayout
);
1212 labelComposite
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
1214 Button deleteButton
= new Button(labelComposite
, SWT
.PUSH
);
1215 deleteButton
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
1216 deleteButton
.setImage(deleteImage
);
1217 deleteButton
.setToolTipText(Messages
.CustomXmlParserInputWizardPage_removeAttribute
);
1218 deleteButton
.addSelectionListener(new SelectionAdapter() {
1220 public void widgetSelected(SelectionEvent e
) {
1221 Attribute
.this.element
.removeAttribute(Attribute
.this.attributeNumber
);
1227 attributeLabel
= new Label(labelComposite
, SWT
.NULL
);
1228 attributeLabel
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
1229 attributeLabel
.setText(Messages
.CustomXmlParserInputWizardPage_attibute
);
1231 attributeComposite
= new Composite(parent
, SWT
.FILL
);
1232 GridLayout attributeLayout
= new GridLayout(4, false);
1233 attributeLayout
.marginWidth
= 0;
1234 attributeLayout
.marginHeight
= 0;
1235 attributeComposite
.setLayout(attributeLayout
);
1236 attributeComposite
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
1238 Label nameLabel
= new Label(attributeComposite
, SWT
.NONE
);
1239 nameLabel
.setText(Messages
.CustomXmlParserInputWizardPage_name
);
1241 attributeNameText
= new Text(attributeComposite
, SWT
.BORDER
| SWT
.SINGLE
);
1242 attributeNameText
.setLayoutData(new GridData(120, SWT
.DEFAULT
));
1243 attributeNameText
.setText(inputAttribute
.attributeName
);
1244 attributeNameText
.addModifyListener(updateListener
);
1246 Label previewLabel
= new Label(attributeComposite
, SWT
.NONE
);
1247 previewLabel
.setText(Messages
.CustomXmlParserInputWizardPage_preview
);
1249 previewText
= new Text(attributeComposite
, SWT
.BORDER
| SWT
.SINGLE
| SWT
.READ_ONLY
);
1250 GridData gd
= new GridData(SWT
.FILL
, SWT
.CENTER
, true, false);
1252 previewText
.setLayoutData(gd
);
1253 previewText
.setText(Messages
.CustomXmlParserInputWizardPage_noMatch
);
1254 previewText
.setBackground(COLOR_WIDGET_BACKGROUND
);
1256 filler
= new Label(parent
, SWT
.NULL
);
1258 tagComposite
= new Composite(parent
, SWT
.FILL
);
1259 GridLayout tagLayout
= new GridLayout(4, false);
1260 tagLayout
.marginWidth
= 0;
1261 tagLayout
.marginHeight
= 0;
1262 tagComposite
.setLayout(tagLayout
);
1263 tagComposite
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
1265 tagCombo
= new Combo(tagComposite
, SWT
.DROP_DOWN
| SWT
.READ_ONLY
);
1266 tagCombo
.setItems(new String
[] { CustomTraceDefinition
.TAG_TIMESTAMP
, CustomTraceDefinition
.TAG_MESSAGE
,
1267 CustomTraceDefinition
.TAG_OTHER
});
1268 tagCombo
.select(2); // Other
1269 tagCombo
.addSelectionListener(new SelectionListener() {
1271 public void widgetDefaultSelected(SelectionEvent e
) {
1275 public void widgetSelected(SelectionEvent e
) {
1276 tagText
.removeModifyListener(updateListener
);
1277 switch (tagCombo
.getSelectionIndex()) {
1278 case 0: // Time Stamp
1279 tagLabel
.setText(Messages
.CustomXmlParserInputWizardPage_format
);
1280 tagLabel
.setVisible(true);
1281 tagText
.setVisible(true);
1282 tagText
.addModifyListener(updateListener
);
1285 tagLabel
.setVisible(false);
1286 tagText
.setVisible(false);
1289 tagLabel
.setText(Messages
.CustomXmlParserInputWizardPage_tagName
);
1290 tagLabel
.setVisible(true);
1291 if (tagText
.getText().trim().length() == 0) {
1292 tagText
.setText(attributeNameText
.getText().trim());
1294 tagText
.setVisible(true);
1295 tagText
.addModifyListener(updateListener
);
1300 tagComposite
.layout();
1306 tagLabel
= new Label(tagComposite
, SWT
.NULL
);
1307 tagLabel
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
1309 tagText
= new Text(tagComposite
, SWT
.BORDER
| SWT
.SINGLE
);
1310 gd
= new GridData(SWT
.FILL
, SWT
.CENTER
, true, false);
1312 tagText
.setLayoutData(gd
);
1313 tagText
.setText(attributeNameText
.getText());
1315 actionCombo
= new Combo(tagComposite
, SWT
.DROP_DOWN
| SWT
.READ_ONLY
);
1316 actionCombo
.setItems(new String
[] { Messages
.CustomXmlParserInputWizardPage_set
, Messages
.CustomXmlParserInputWizardPage_append
,
1317 Messages
.CustomXmlParserInputWizardPage_appendWith
});
1318 actionCombo
.select(inputAttribute
.inputAction
);
1319 actionCombo
.addSelectionListener(updateListener
);
1321 if (inputAttribute
.inputName
.equals(CustomTraceDefinition
.TAG_TIMESTAMP
)) {
1323 tagLabel
.setText(Messages
.CustomXmlParserInputWizardPage_format
);
1324 tagText
.setText(inputAttribute
.inputFormat
);
1325 tagText
.addModifyListener(updateListener
);
1326 } else if (inputAttribute
.inputName
.equals(CustomTraceDefinition
.TAG_MESSAGE
)) {
1328 tagLabel
.setVisible(false);
1329 tagText
.setVisible(false);
1332 tagLabel
.setText(Messages
.CustomXmlParserInputWizardPage_tagName
);
1333 tagText
.setText(inputAttribute
.inputName
);
1334 tagText
.addModifyListener(updateListener
);
1338 private void dispose() {
1339 labelComposite
.dispose();
1340 attributeComposite
.dispose();
1342 tagComposite
.dispose();
1345 private void setAttributeNumber(int attributeNumber
) {
1346 this.attributeNumber
= attributeNumber
;
1347 labelComposite
.layout();
1351 private Element
getPreviewElement(InputElement inputElement
) {
1352 Element element
= documentElement
;
1353 if (element
!= null) {
1354 if (!documentElement
.getNodeName().equals(definition
.rootInputElement
.elementName
)) {
1357 ArrayList
<String
> elementNames
= new ArrayList
<String
>();
1358 while (inputElement
!= null) {
1359 elementNames
.add(inputElement
.elementName
);
1360 inputElement
= inputElement
.parentElement
;
1362 for (int i
= elementNames
.size() - 1; --i
>= 0;) {
1363 NodeList childList
= element
.getChildNodes();
1365 for (int j
= 0; j
< childList
.getLength(); j
++) {
1366 Node child
= childList
.item(j
);
1367 if (child
instanceof Element
&& child
.getNodeName().equals(elementNames
.get(i
))) {
1368 element
= (Element
) child
;
1372 if (element
== null) {
1376 if (element
!= null) {
1383 private String
getChildNameSuggestion(InputElement inputElement
) {
1384 if (inputElement
== null) {
1385 if (documentElement
!= null) {
1386 return documentElement
.getNodeName();
1389 Element element
= getPreviewElement(inputElement
);
1390 if (element
!= null) {
1391 NodeList childNodes
= element
.getChildNodes();
1392 for (int i
= 0; i
< childNodes
.getLength(); i
++) {
1393 Node node
= childNodes
.item(i
);
1394 if (node
instanceof Element
) {
1395 boolean unused
= true;
1396 if (inputElement
.childElements
!= null) {
1397 for (InputElement child
: inputElement
.childElements
) {
1398 if (child
.elementName
.equals(node
.getNodeName())) {
1405 return node
.getNodeName();
1411 return ""; //$NON-NLS-1$
1414 private String
getAttributeNameSuggestion(InputElement inputElement
) {
1415 Element element
= getPreviewElement(inputElement
);
1416 if (element
!= null) {
1417 NamedNodeMap attributeMap
= element
.getAttributes();
1418 for (int i
= 0; i
< attributeMap
.getLength(); i
++) {
1419 Node node
= attributeMap
.item(i
);
1420 boolean unused
= true;
1421 if (inputElement
.attributes
!= null) {
1422 for (InputAttribute attribute
: inputElement
.attributes
) {
1423 if (attribute
.attributeName
.equals(node
.getNodeName())) {
1430 return node
.getNodeName();
1434 return ""; //$NON-NLS-1$
1437 private void validate() {
1438 definition
.definitionName
= logtypeText
.getText().trim();
1439 definition
.timeStampOutputFormat
= timeStampOutputFormatText
.getText().trim();
1441 if (selectedElement
!= null) {
1442 selectedElement
.extractInputs();
1443 treeViewer
.refresh();
1446 StringBuffer errors
= new StringBuffer();
1448 if (definition
.definitionName
.length() == 0) {
1449 errors
.append(Messages
.CustomXmlParserInputWizardPage_emptyLogTypeError
);
1450 logtypeText
.setBackground(COLOR_LIGHT_RED
);
1452 logtypeText
.setBackground(COLOR_TEXT_BACKGROUND
);
1453 for (CustomXmlTraceDefinition def
: CustomXmlTraceDefinition
.loadAll()) {
1454 if (definition
.definitionName
.equals(def
.definitionName
)) {
1455 if (editDefinitionName
== null || !editDefinitionName
.equals(definition
.definitionName
)) {
1456 errors
.append(Messages
.CustomXmlParserInputWizardPage_duplicatelogTypeError
);
1457 logtypeText
.setBackground(COLOR_LIGHT_RED
);
1464 if (definition
.rootInputElement
== null) {
1465 errors
.append(Messages
.CustomXmlParserInputWizardPage_noDocumentError
);
1468 if (definition
.rootInputElement
!= null) {
1469 logEntryFound
= false;
1470 timeStampFound
= false;
1472 errors
.append(validateElement(definition
.rootInputElement
));
1474 if ((definition
.rootInputElement
.attributes
!= null && definition
.rootInputElement
.attributes
.size() != 0)
1475 || (definition
.rootInputElement
.childElements
!= null && definition
.rootInputElement
.childElements
.size() != 0)
1476 || errors
.length() == 0) {
1477 if (!logEntryFound
) {
1478 errors
.append(Messages
.CustomXmlParserInputWizardPage_missingLogEntryError
);
1481 if (timeStampFound
) {
1482 if (timeStampOutputFormatText
.getText().trim().length() == 0) {
1483 errors
.append(Messages
.CustomXmlParserInputWizardPage_missingTimestampFmtError
);
1484 timeStampOutputFormatText
.setBackground(COLOR_LIGHT_RED
);
1487 new SimpleDateFormat(timeStampOutputFormatText
.getText().trim());
1488 timeStampOutputFormatText
.setBackground(COLOR_TEXT_BACKGROUND
);
1489 } catch (IllegalArgumentException e
) {
1490 errors
.append(Messages
.CustomXmlParserInputWizardPage_invalidTimestampFmtError
);
1491 timeStampOutputFormatText
.setBackground(COLOR_LIGHT_RED
);
1495 timeStampPreviewText
.setText(Messages
.CustomXmlParserInputWizardPage_notimestamporAttributeError
);
1499 timeStampPreviewText
.setText(Messages
.CustomXmlParserInputWizardPage_notimestamporAttributeError
);
1502 if (errors
.length() == 0) {
1503 setDescription(defaultDescription
);
1504 setPageComplete(true);
1506 setDescription(errors
.toString());
1507 setPageComplete(false);
1511 public StringBuffer
validateElement(InputElement inputElement
) {
1512 StringBuffer errors
= new StringBuffer();
1513 ElementNode elementNode
= null;
1514 if (selectedElement
!= null && selectedElement
.inputElement
.equals(inputElement
)) {
1515 elementNode
= selectedElement
;
1517 if (inputElement
== definition
.rootInputElement
) {
1518 if (inputElement
.elementName
.length() == 0) {
1519 errors
.append(Messages
.CustomXmlParserInputWizardPage_missingDocumentElementError
);
1520 if (elementNode
!= null) {
1521 elementNode
.elementNameText
.setBackground(COLOR_LIGHT_RED
);
1524 if (elementNode
!= null) {
1525 elementNode
.elementNameText
.setBackground(COLOR_TEXT_BACKGROUND
);
1529 if (inputElement
!= definition
.rootInputElement
) {
1530 if (inputElement
.logEntry
) {
1531 logEntryFound
= true;
1533 if (inputElement
.inputName
.equals(CustomTraceDefinition
.TAG_TIMESTAMP
)) {
1534 timeStampFound
= true;
1535 if (inputElement
.inputFormat
.length() == 0) {
1536 errors
.append(Messages
.CustomXmlParserInputWizardPage_timestampFormatPrompt
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
);
1543 new SimpleDateFormat(inputElement
.inputFormat
);
1544 if (elementNode
!= null) {
1545 elementNode
.tagText
.setBackground(COLOR_TEXT_BACKGROUND
);
1547 } catch (IllegalArgumentException e
) {
1548 errors
.append(Messages
.CustomXmlParserInputWizardPage_invalidTimestampFmtError
1549 + " (" + Messages
.CustomXmlParserInputWizardPage_timestampElementPrompt
+ " " + getName(inputElement
) + "). "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
1550 if (elementNode
!= null) {
1551 elementNode
.tagText
.setBackground(COLOR_LIGHT_RED
);
1555 } else if (inputElement
.inputName
.length() == 0) {
1556 errors
.append(Messages
.CustomXmlParserInputWizardPage_missingInputElementNameError
);
1557 if (elementNode
!= null) {
1558 elementNode
.tagText
.setBackground(COLOR_LIGHT_RED
);
1561 if (elementNode
!= null) {
1562 elementNode
.tagText
.setBackground(COLOR_TEXT_BACKGROUND
);
1566 if (inputElement
.attributes
!= null) {
1567 if (elementNode
!= null) {
1568 for (Attribute attribute
: elementNode
.attributes
) {
1569 attribute
.attributeNameText
.setBackground(COLOR_TEXT_BACKGROUND
);
1572 for (int i
= 0; i
< inputElement
.attributes
.size(); i
++) {
1573 InputAttribute attribute
= inputElement
.attributes
.get(i
);
1574 boolean duplicate
= false;
1575 for (int j
= i
+ 1; j
< inputElement
.attributes
.size(); j
++) {
1576 InputAttribute otherAttribute
= inputElement
.attributes
.get(j
);
1577 if (otherAttribute
.attributeName
.equals(attribute
.attributeName
)) {
1579 if (elementNode
!= null) {
1580 elementNode
.attributes
.get(j
).attributeNameText
.setBackground(COLOR_LIGHT_RED
);
1584 if (attribute
.attributeName
.length() == 0) {
1585 errors
.append(Messages
.CustomXmlParserInputWizardPage_missingAttribute
1586 + " (" + Messages
.CustomXmlParserInputWizardPage_attributePrompt
+ " " + getName(inputElement
) + ": ?). "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
1587 if (elementNode
!= null) {
1588 elementNode
.attributes
.get(i
).attributeNameText
.setBackground(COLOR_LIGHT_RED
);
1590 } else if (duplicate
) {
1591 errors
.append(Messages
.CustomXmlParserInputWizardPage_duplicateAttributeError
1592 + " (" + Messages
.CustomXmlParserInputWizardPage_attributePrompt
+ " " + getName(attribute
, inputElement
) + "). "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
1593 if (elementNode
!= null) {
1594 elementNode
.attributes
.get(i
).attributeNameText
.setBackground(COLOR_LIGHT_RED
);
1597 if (attribute
.inputName
.equals(CustomTraceDefinition
.TAG_TIMESTAMP
)) {
1598 timeStampFound
= true;
1599 if (attribute
.inputFormat
.length() == 0) {
1600 errors
.append(Messages
.CustomXmlParserInputWizardPage_missingTimestampInFmtError
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
);
1607 new SimpleDateFormat(attribute
.inputFormat
);
1608 if (elementNode
!= null) {
1609 elementNode
.attributes
.get(i
).tagText
.setBackground(COLOR_TEXT_BACKGROUND
);
1611 } catch (IllegalArgumentException e
) {
1612 errors
.append(Messages
.CustomXmlParserInputWizardPage_invalidTimestampInFmtError
1613 + " (" + Messages
.CustomXmlParserInputWizardPage_attributePrompt
+ " " + getName(attribute
, inputElement
) + "). "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
1614 if (elementNode
!= null) {
1615 elementNode
.attributes
.get(i
).tagText
.setBackground(COLOR_LIGHT_RED
);
1619 } else if (attribute
.inputName
.length() == 0) {
1620 errors
.append(Messages
.CustomXmlParserInputWizardPage_missingDataGroupNameError
1621 + " (" + Messages
.CustomXmlParserInputWizardPage_attributePrompt
+ " " + getName(attribute
, inputElement
) + "). "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
1622 if (elementNode
!= null) {
1623 elementNode
.attributes
.get(i
).tagText
.setBackground(COLOR_LIGHT_RED
);
1626 if (elementNode
!= null) {
1627 elementNode
.attributes
.get(i
).tagText
.setBackground(COLOR_TEXT_BACKGROUND
);
1632 if (inputElement
.childElements
!= null) {
1633 for (InputElement child
: inputElement
.childElements
) {
1634 ElementNode childElementNode
= null;
1635 if (selectedElement
!= null && selectedElement
.inputElement
.equals(child
)) {
1636 childElementNode
= selectedElement
;
1638 if (childElementNode
!= null) {
1639 childElementNode
.elementNameText
.setBackground(COLOR_TEXT_BACKGROUND
);
1642 for (int i
= 0; i
< inputElement
.childElements
.size(); i
++) {
1643 InputElement child
= inputElement
.childElements
.get(i
);
1644 ElementNode childElementNode
= null;
1645 if (selectedElement
!= null && selectedElement
.inputElement
.equals(child
)) {
1646 childElementNode
= selectedElement
;
1648 if (child
.elementName
.length() == 0) {
1649 errors
.append(Messages
.CustomXmlParserInputWizardPage_missingElementNameError
1650 + " (" + Messages
.CustomXmlParserInputWizardPage_attributePrompt
+ " " + getName(child
) + "). "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
1651 if (childElementNode
!= null) {
1652 childElementNode
.elementNameText
.setBackground(COLOR_LIGHT_RED
);
1655 boolean duplicate
= false;
1656 for (int j
= i
+ 1; j
< inputElement
.childElements
.size(); j
++) {
1657 InputElement otherChild
= inputElement
.childElements
.get(j
);
1658 if (otherChild
.elementName
.equals(child
.elementName
)) {
1660 ElementNode otherChildElementNode
= null;
1661 if (selectedElement
!= null && selectedElement
.inputElement
.equals(otherChild
)) {
1662 otherChildElementNode
= selectedElement
;
1664 if (otherChildElementNode
!= null) {
1665 otherChildElementNode
.elementNameText
.setBackground(COLOR_LIGHT_RED
);
1670 errors
.append(Messages
.CustomXmlParserInputWizardPage_duplicateElementNameError
1671 + " (" + Messages
.CustomXmlParserInputWizardPage_attributePrompt
+ " " + getName(child
) + "). "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
1672 if (childElementNode
!= null) {
1673 childElementNode
.elementNameText
.setBackground(COLOR_LIGHT_RED
);
1678 errors
.append(validateElement(child
));
1684 public CustomXmlTraceDefinition
getDefinition() {
1688 public char[] getInputText() {
1689 return inputText
.getText().toCharArray();