1 package org
.eclipse
.linuxtools
.tmf
.ui
.wizards
;
3 import java
.io
.BufferedReader
;
4 import java
.io
.ByteArrayInputStream
;
5 import java
.io
.IOException
;
6 import java
.io
.InputStream
;
7 import java
.io
.InputStreamReader
;
8 import java
.text
.ParseException
;
9 import java
.text
.SimpleDateFormat
;
10 import java
.util
.ArrayList
;
11 import java
.util
.Date
;
12 import java
.util
.List
;
14 import javax
.xml
.parsers
.DocumentBuilder
;
15 import javax
.xml
.parsers
.DocumentBuilderFactory
;
16 import javax
.xml
.parsers
.ParserConfigurationException
;
18 import org
.eclipse
.core
.resources
.IFile
;
19 import org
.eclipse
.core
.runtime
.CoreException
;
20 import org
.eclipse
.jface
.viewers
.ColumnLabelProvider
;
21 import org
.eclipse
.jface
.viewers
.ISelection
;
22 import org
.eclipse
.jface
.viewers
.ISelectionChangedListener
;
23 import org
.eclipse
.jface
.viewers
.IStructuredSelection
;
24 import org
.eclipse
.jface
.viewers
.ITreeContentProvider
;
25 import org
.eclipse
.jface
.viewers
.SelectionChangedEvent
;
26 import org
.eclipse
.jface
.viewers
.StructuredSelection
;
27 import org
.eclipse
.jface
.viewers
.TreeViewer
;
28 import org
.eclipse
.jface
.viewers
.Viewer
;
29 import org
.eclipse
.jface
.wizard
.WizardPage
;
30 import org
.eclipse
.linuxtools
.tmf
.ui
.TmfUiPlugin
;
31 import org
.eclipse
.linuxtools
.tmf
.ui
.parsers
.custom
.CustomXmlTrace
;
32 import org
.eclipse
.linuxtools
.tmf
.ui
.parsers
.custom
.CustomXmlTraceDefinition
;
33 import org
.eclipse
.linuxtools
.tmf
.ui
.parsers
.custom
.CustomXmlTraceDefinition
.InputAttribute
;
34 import org
.eclipse
.linuxtools
.tmf
.ui
.parsers
.custom
.CustomXmlTraceDefinition
.InputElement
;
35 import org
.eclipse
.swt
.SWT
;
36 import org
.eclipse
.swt
.browser
.Browser
;
37 import org
.eclipse
.swt
.browser
.TitleEvent
;
38 import org
.eclipse
.swt
.browser
.TitleListener
;
39 import org
.eclipse
.swt
.custom
.SashForm
;
40 import org
.eclipse
.swt
.custom
.ScrolledComposite
;
41 import org
.eclipse
.swt
.custom
.StyleRange
;
42 import org
.eclipse
.swt
.custom
.StyledText
;
43 import org
.eclipse
.swt
.events
.ModifyEvent
;
44 import org
.eclipse
.swt
.events
.ModifyListener
;
45 import org
.eclipse
.swt
.events
.SelectionAdapter
;
46 import org
.eclipse
.swt
.events
.SelectionEvent
;
47 import org
.eclipse
.swt
.events
.SelectionListener
;
48 import org
.eclipse
.swt
.graphics
.Color
;
49 import org
.eclipse
.swt
.graphics
.Font
;
50 import org
.eclipse
.swt
.graphics
.FontData
;
51 import org
.eclipse
.swt
.graphics
.Image
;
52 import org
.eclipse
.swt
.layout
.FillLayout
;
53 import org
.eclipse
.swt
.layout
.GridData
;
54 import org
.eclipse
.swt
.layout
.GridLayout
;
55 import org
.eclipse
.swt
.widgets
.Button
;
56 import org
.eclipse
.swt
.widgets
.Combo
;
57 import org
.eclipse
.swt
.widgets
.Composite
;
58 import org
.eclipse
.swt
.widgets
.Display
;
59 import org
.eclipse
.swt
.widgets
.Group
;
60 import org
.eclipse
.swt
.widgets
.Label
;
61 import org
.eclipse
.swt
.widgets
.Shell
;
62 import org
.eclipse
.swt
.widgets
.Text
;
63 import org
.w3c
.dom
.Document
;
64 import org
.w3c
.dom
.Element
;
65 import org
.w3c
.dom
.NamedNodeMap
;
66 import org
.w3c
.dom
.Node
;
67 import org
.w3c
.dom
.NodeList
;
68 import org
.xml
.sax
.EntityResolver
;
69 import org
.xml
.sax
.ErrorHandler
;
70 import org
.xml
.sax
.InputSource
;
71 import org
.xml
.sax
.SAXException
;
72 import org
.xml
.sax
.SAXParseException
;
74 public class CustomXmlParserInputWizardPage
extends WizardPage
{
76 private static final String DEFAULT_TIMESTAMP_FORMAT
= "yyyy-MM-dd HH:mm:ss.SSS"; //$NON-NLS-1$
77 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$
78 private static final Image elementImage
= TmfUiPlugin
.getDefault().getImageFromPath("/icons/element_icon.gif"); //$NON-NLS-1$
79 private static final Image addImage
= TmfUiPlugin
.getDefault().getImageFromPath("/icons/add_button.gif"); //$NON-NLS-1$
80 private static final Image addNextImage
= TmfUiPlugin
.getDefault().getImageFromPath("/icons/addnext_button.gif"); //$NON-NLS-1$
81 private static final Image addChildImage
= TmfUiPlugin
.getDefault().getImageFromPath("/icons/addchild_button.gif"); //$NON-NLS-1$
82 private static final Image addManyImage
= TmfUiPlugin
.getDefault().getImageFromPath("/icons/addmany_button.gif"); //$NON-NLS-1$
83 private static final Image deleteImage
= TmfUiPlugin
.getDefault().getImageFromPath("/icons/delete_button.gif"); //$NON-NLS-1$
84 private static final Image moveUpImage
= TmfUiPlugin
.getDefault().getImageFromPath("/icons/moveup_button.gif"); //$NON-NLS-1$
85 private static final Image moveDownImage
= TmfUiPlugin
.getDefault().getImageFromPath("/icons/movedown_button.gif"); //$NON-NLS-1$
86 private static final Image helpImage
= TmfUiPlugin
.getDefault().getImageFromPath("/icons/help_button.gif"); //$NON-NLS-1$
87 private static final Color COLOR_LIGHT_RED
= new Color(Display
.getDefault(), 255, 192, 192);
88 private static final Color COLOR_TEXT_BACKGROUND
= Display
.getCurrent().getSystemColor(SWT
.COLOR_WHITE
);
89 private static final Color COLOR_WIDGET_BACKGROUND
= Display
.getCurrent().getSystemColor(SWT
.COLOR_WIDGET_BACKGROUND
);
91 private ISelection selection
;
92 private CustomXmlTraceDefinition definition
;
93 private String editDefinitionName
;
94 private String defaultDescription
;
95 private ElementNode selectedElement
;
96 private Composite container
;
97 private Text logtypeText
;
98 private Text timeStampOutputFormatText
;
99 private Text timeStampPreviewText
;
100 private Button removeButton
;
101 private Button addChildButton
;
102 private Button addNextButton
;
103 private Button moveUpButton
;
104 private Button moveDownButton
;
105 private Button feelingLuckyButton
;
106 private ScrolledComposite treeScrolledComposite
;
107 private ScrolledComposite elementScrolledComposite
;
108 private TreeViewer treeViewer
;
109 private Composite treeContainer
;
110 private Composite elementContainer
;
111 private Text errorText
;
112 private StyledText inputText
;
113 private Font fixedFont
;
114 private UpdateListener updateListener
;
115 private Browser helpBrowser
;
116 private Element documentElement
;
118 // variables used recursively through element traversal
119 private String timeStampValue
;
120 private String timeStampFormat
;
121 private boolean timeStampFound
;
122 private int logEntriesCount
;
123 private boolean logEntryFound
;
124 private int logEntryNestedCount
;
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
));
162 logtypeText
.addModifyListener(updateListener
);
164 Label timeStampFormatLabel
= new Label(headerComposite
, SWT
.NULL
);
165 timeStampFormatLabel
.setText(Messages
.CustomXmlParserInputWizardPage_timestampFormat
);
167 timeStampOutputFormatText
= new Text(headerComposite
, SWT
.BORDER
| SWT
.SINGLE
);
168 timeStampOutputFormatText
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
169 timeStampOutputFormatText
.setText(DEFAULT_TIMESTAMP_FORMAT
);
170 timeStampOutputFormatText
.addModifyListener(updateListener
);
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
.setMinSize(treeContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).x
, treeContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).y
);
215 elementScrolledComposite
= new ScrolledComposite(hSash
, SWT
.V_SCROLL
);
216 elementScrolledComposite
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
217 elementContainer
= new Composite(elementScrolledComposite
, SWT
.NONE
);
218 GridLayout gl
= new GridLayout();
221 elementContainer
.setLayout(gl
);
222 elementScrolledComposite
.setContent(elementContainer
);
223 elementScrolledComposite
.setExpandHorizontal(true);
224 elementScrolledComposite
.setExpandVertical(true);
226 if (definition
== null) {
227 definition
= new CustomXmlTraceDefinition();
229 loadDefinition(definition
);
230 treeViewer
.expandAll();
231 elementContainer
.layout();
233 elementScrolledComposite
.setMinSize(elementContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).x
, elementContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).y
-1);
235 hSash
.setWeights(new int[] {1, 2});
237 if (definition
.rootInputElement
== null) {
238 removeButton
.setEnabled(false);
239 addChildButton
.setToolTipText(Messages
.CustomXmlParserInputWizardPage_addDocumentElement
);
240 addNextButton
.setEnabled(false);
241 moveUpButton
.setEnabled(false);
242 moveDownButton
.setEnabled(false);
243 } else { // root is selected
244 addNextButton
.setEnabled(false);
247 Composite sashBottom
= new Composite(vSash
, SWT
.NONE
);
248 GridLayout sashBottomLayout
= new GridLayout(2, false);
249 sashBottomLayout
.marginHeight
= 0;
250 sashBottomLayout
.marginWidth
= 0;
251 sashBottom
.setLayout(sashBottomLayout
);
253 Label previewLabel
= new Label(sashBottom
, SWT
.NULL
);
254 previewLabel
.setText(Messages
.CustomXmlParserInputWizardPage_previewInput
);
256 errorText
= new Text(sashBottom
, SWT
.SINGLE
| SWT
.READ_ONLY
);
257 errorText
.setBackground(COLOR_WIDGET_BACKGROUND
);
258 errorText
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
259 errorText
.setVisible(false);
261 inputText
= new StyledText(sashBottom
, SWT
.MULTI
| SWT
.V_SCROLL
| SWT
.H_SCROLL
);
262 if (fixedFont
== null) {
263 if (System
.getProperty("os.name").contains("Windows")) { //$NON-NLS-1$ //$NON-NLS-2$
264 fixedFont
= new Font(Display
.getCurrent(), new FontData("Courier New", 10, SWT
.NORMAL
)); //$NON-NLS-1$
266 fixedFont
= new Font(Display
.getCurrent(), new FontData("Monospace", 10, SWT
.NORMAL
)); //$NON-NLS-1$
269 inputText
.setFont(fixedFont
);
270 GridData gd
= new GridData(SWT
.FILL
, SWT
.FILL
, true, true, 2, 1);
271 gd
.heightHint
= inputText
.computeSize(SWT
.DEFAULT
, inputText
.getLineHeight() * 4).y
;
273 inputText
.setLayoutData(gd
);
274 inputText
.setText(getSelectionText());
275 inputText
.addModifyListener(new ModifyListener(){
277 public void modifyText(ModifyEvent e
) {
278 parseXmlInput(inputText
.getText());
280 inputText
.addModifyListener(updateListener
);
282 vSash
.setWeights(new int[] {hSash
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).y
, sashBottom
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).y
});
284 setControl(container
);
287 private void createButtonBar() {
288 Composite buttonBar
= new Composite(container
, SWT
.NONE
);
289 GridLayout buttonBarLayout
= new GridLayout(6, false);
290 buttonBarLayout
.marginHeight
= 0;
291 buttonBarLayout
.marginWidth
= 0;
292 buttonBar
.setLayout(buttonBarLayout
);
294 removeButton
= new Button(buttonBar
, SWT
.PUSH
);
295 removeButton
.setImage(deleteImage
);
296 removeButton
.setToolTipText(Messages
.CustomXmlParserInputWizardPage_removeElement
);
297 removeButton
.addSelectionListener(new SelectionAdapter() {
299 public void widgetSelected(SelectionEvent e
) {
300 if (treeViewer
.getSelection().isEmpty() || selectedElement
== null) return;
302 InputElement inputElement
= (InputElement
) ((IStructuredSelection
) treeViewer
.getSelection()).getFirstElement();
303 if (inputElement
== definition
.rootInputElement
) {
304 definition
.rootInputElement
= null;
306 inputElement
.parentElement
.childElements
.remove(inputElement
);
308 treeViewer
.refresh();
311 removeButton
.setEnabled(false);
312 if (definition
.rootInputElement
== null) {
313 addChildButton
.setEnabled(true);
314 addChildButton
.setToolTipText(Messages
.CustomXmlParserInputWizardPage_addDocumentEleemnt
);
316 addChildButton
.setEnabled(false);
318 addNextButton
.setEnabled(false);
319 moveUpButton
.setEnabled(false);
320 moveDownButton
.setEnabled(false);
324 addChildButton
= new Button(buttonBar
, SWT
.PUSH
);
325 addChildButton
.setImage(addChildImage
);
326 addChildButton
.setToolTipText(Messages
.CustomXmlParserInputWizardPage_addChildElement
);
327 addChildButton
.addSelectionListener(new SelectionAdapter() {
329 public void widgetSelected(SelectionEvent e
) {
330 InputElement inputElement
= new InputElement("", false, CustomXmlTraceDefinition
.TAG_IGNORE
, 0, "", null); //$NON-NLS-1$ //$NON-NLS-2$
331 if (definition
.rootInputElement
== null) {
332 definition
.rootInputElement
= inputElement
;
333 inputElement
.elementName
= getChildNameSuggestion(null);
334 } else if (treeViewer
.getSelection().isEmpty()) {
337 InputElement parentInputElement
= (InputElement
) ((IStructuredSelection
) treeViewer
.getSelection()).getFirstElement();
338 parentInputElement
.addChild(inputElement
);
339 inputElement
.elementName
= getChildNameSuggestion(parentInputElement
);
341 treeViewer
.refresh();
342 treeViewer
.setSelection(new StructuredSelection(inputElement
), true);
346 addNextButton
= new Button(buttonBar
, SWT
.PUSH
);
347 addNextButton
.setImage(addNextImage
);
348 addNextButton
.setToolTipText(Messages
.CustomXmlParserInputWizardPage_addNextElement
);
349 addNextButton
.addSelectionListener(new SelectionAdapter() {
351 public void widgetSelected(SelectionEvent e
) {
352 InputElement inputElement
= new InputElement("", false, CustomXmlTraceDefinition
.TAG_IGNORE
, 0, "", null); //$NON-NLS-1$ //$NON-NLS-2$
353 if (definition
.rootInputElement
== null) {
354 definition
.rootInputElement
= inputElement
;
355 inputElement
.elementName
= getChildNameSuggestion(null);
356 } else if (treeViewer
.getSelection().isEmpty()) {
359 InputElement previousInputElement
= (InputElement
) ((IStructuredSelection
) treeViewer
.getSelection()).getFirstElement();
360 if (previousInputElement
== definition
.rootInputElement
) {
363 previousInputElement
.addNext(inputElement
);
364 inputElement
.elementName
= getChildNameSuggestion(inputElement
.parentElement
);
367 treeViewer
.refresh();
368 treeViewer
.setSelection(new StructuredSelection(inputElement
), true);
372 feelingLuckyButton
= new Button(buttonBar
, SWT
.PUSH
);
373 feelingLuckyButton
.setImage(addManyImage
);
374 feelingLuckyButton
.setToolTipText(Messages
.CustomXmlParserInputWizardPage_feelingLucky
);
375 feelingLuckyButton
.addSelectionListener(new SelectionAdapter() {
377 public void widgetSelected(SelectionEvent e
) {
378 InputElement inputElement
= null;
379 if (definition
.rootInputElement
== null) {
380 if (getChildNameSuggestion(null).length() != 0) {
381 inputElement
= new InputElement(getChildNameSuggestion(null), false, CustomXmlTraceDefinition
.TAG_IGNORE
, 0, "", null); //$NON-NLS-1$
382 definition
.rootInputElement
= inputElement
;
383 feelingLucky(inputElement
);
385 } else if (treeViewer
.getSelection().isEmpty()) {
388 inputElement
= (InputElement
) ((IStructuredSelection
) treeViewer
.getSelection()).getFirstElement();
389 feelingLucky(inputElement
);
391 treeViewer
.refresh();
392 treeViewer
.setSelection(new StructuredSelection(inputElement
), true);
393 treeViewer
.expandToLevel(inputElement
, TreeViewer
.ALL_LEVELS
);
397 moveUpButton
= new Button(buttonBar
, SWT
.PUSH
);
398 moveUpButton
.setImage(moveUpImage
);
399 moveUpButton
.setToolTipText(Messages
.CustomXmlParserInputWizardPage_moveUp
);
400 moveUpButton
.addSelectionListener(new SelectionAdapter() {
402 public void widgetSelected(SelectionEvent e
) {
403 if (treeViewer
.getSelection().isEmpty()) return;
404 InputElement inputElement
= (InputElement
) ((IStructuredSelection
) treeViewer
.getSelection()).getFirstElement();
405 if (inputElement
== definition
.rootInputElement
) {
408 inputElement
.moveUp();
410 treeViewer
.refresh();
416 moveDownButton
= new Button(buttonBar
, SWT
.PUSH
);
417 moveDownButton
.setImage(moveDownImage
);
418 moveDownButton
.setToolTipText(Messages
.CustomXmlParserInputWizardPage_moveDown
);
419 moveDownButton
.addSelectionListener(new SelectionAdapter() {
421 public void widgetSelected(SelectionEvent e
) {
422 if (treeViewer
.getSelection().isEmpty()) return;
423 InputElement inputElement
= (InputElement
) ((IStructuredSelection
) treeViewer
.getSelection()).getFirstElement();
424 if (inputElement
== definition
.rootInputElement
) {
427 inputElement
.moveDown();
429 treeViewer
.refresh();
436 private void feelingLucky(InputElement inputElement
) {
438 String attributeName
= getAttributeNameSuggestion(inputElement
);
439 if (attributeName
.length() == 0) {
442 InputAttribute attribute
= new InputAttribute(attributeName
, attributeName
, 0, ""); //$NON-NLS-1$
443 inputElement
.addAttribute(attribute
);
447 String childName
= getChildNameSuggestion(inputElement
);
448 if (childName
.length() == 0) {
451 InputElement childElement
= new InputElement(childName
, false, CustomXmlTraceDefinition
.TAG_IGNORE
, 0, "", null); //$NON-NLS-1$
452 inputElement
.addChild(childElement
);
453 feelingLucky(childElement
);
458 private class InputElementTreeNodeContentProvider
implements ITreeContentProvider
{
461 public Object
[] getElements(Object inputElement
) {
462 CustomXmlTraceDefinition def
= (CustomXmlTraceDefinition
) inputElement
;
463 if (def
.rootInputElement
!= null) {
464 return new Object
[] {def
.rootInputElement
};
466 return new Object
[0];
471 public Object
[] getChildren(Object parentElement
) {
472 InputElement inputElement
= (InputElement
) parentElement
;
473 if (inputElement
.childElements
== null) return new InputElement
[0];
474 return inputElement
.childElements
.toArray();
478 public boolean hasChildren(Object element
) {
479 InputElement inputElement
= (InputElement
) element
;
480 return (inputElement
.childElements
!= null && inputElement
.childElements
.size() > 0);
484 public void dispose() {
488 public void inputChanged(Viewer viewer
, Object oldInput
, Object newInput
) {
492 public Object
getParent(Object element
) {
493 InputElement inputElement
= (InputElement
) element
;
494 return inputElement
.parentElement
;
498 private class InputElementTreeLabelProvider
extends ColumnLabelProvider
{
501 public Image
getImage(Object element
) {
506 public String
getText(Object element
) {
507 InputElement inputElement
= (InputElement
) element
;
508 return (inputElement
.elementName
.trim().length() == 0) ?
"?" : inputElement
.elementName
; //$NON-NLS-1$
512 private class InputElementTreeSelectionChangedListener
implements ISelectionChangedListener
{
514 public void selectionChanged(SelectionChangedEvent event
) {
515 if (selectedElement
!= null) {
516 selectedElement
.dispose();
518 if (!(event
.getSelection().isEmpty()) && event
.getSelection() instanceof IStructuredSelection
) {
519 IStructuredSelection selection
= (IStructuredSelection
) event
.getSelection();
520 InputElement inputElement
= (InputElement
) selection
.getFirstElement();
521 selectedElement
= new ElementNode(elementContainer
, inputElement
);
522 elementContainer
.layout();
523 elementScrolledComposite
.setMinSize(elementContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).x
, elementContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).y
-1);
527 removeButton
.setEnabled(true);
528 addChildButton
.setEnabled(true);
529 addChildButton
.setToolTipText(Messages
.CustomXmlParserInputWizardPage_addChildElement
);
530 if (definition
.rootInputElement
== inputElement
) {
531 addNextButton
.setEnabled(false);
533 addNextButton
.setEnabled(true);
535 moveUpButton
.setEnabled(true);
536 moveDownButton
.setEnabled(true);
538 removeButton
.setEnabled(false);
539 if (definition
.rootInputElement
== null) {
540 addChildButton
.setEnabled(true);
541 addChildButton
.setToolTipText(Messages
.CustomXmlParserInputWizardPage_addDocumentElement
);
543 addChildButton
.setEnabled(false);
545 addNextButton
.setEnabled(false);
546 moveUpButton
.setEnabled(false);
547 moveDownButton
.setEnabled(false);
553 * @see org.eclipse.jface.dialogs.DialogPage#dispose()
556 public void dispose() {
557 if (fixedFont
!= null) {
564 private void loadDefinition(CustomXmlTraceDefinition def
) {
565 logtypeText
.setText(def
.definitionName
);
566 timeStampOutputFormatText
.setText(def
.timeStampOutputFormat
);
567 treeViewer
.setInput(def
);
569 if (def
.rootInputElement
!= null) {
570 treeViewer
.setSelection(new StructuredSelection(def
.rootInputElement
));
574 private String
getName(InputElement inputElement
) {
575 String name
= (inputElement
.elementName
.trim().length() == 0) ?
"?" : inputElement
.elementName
.trim(); //$NON-NLS-1$
576 if (inputElement
.parentElement
== null) {
579 return getName(inputElement
.parentElement
) + " : " + name
; //$NON-NLS-1$
582 private String
getName(InputAttribute inputAttribute
, InputElement inputElement
) {
583 String name
= (inputAttribute
.attributeName
.trim().length() == 0) ?
"?" : inputAttribute
.attributeName
.trim(); //$NON-NLS-1$
584 return getName(inputElement
) + " : " + name
; //$NON-NLS-1$
588 * @see org.eclipse.jface.dialogs.DialogPage#setVisible(boolean)
591 public void setVisible(boolean visible
) {
596 super.setVisible(visible
);
599 public List
<String
> getInputNames() {
600 return getInputNames(definition
.rootInputElement
);
603 public List
<String
> getInputNames(InputElement inputElement
) {
604 List
<String
> inputs
= new ArrayList
<String
>();
605 if (inputElement
.inputName
!= null && !inputElement
.inputName
.equals(CustomXmlTraceDefinition
.TAG_IGNORE
)) {
606 String inputName
= inputElement
.inputName
;
607 if (!inputs
.contains(inputName
)) {
608 inputs
.add(inputName
);
611 if (inputElement
.attributes
!= null) {
612 for (InputAttribute attribute
: inputElement
.attributes
) {
613 String inputName
= attribute
.inputName
;
614 if (!inputs
.contains(inputName
)) {
615 inputs
.add(inputName
);
619 if (inputElement
.childElements
!= null) {
620 for (InputElement childInputElement
: inputElement
.childElements
) {
621 for (String inputName
: getInputNames(childInputElement
)) {
622 if (!inputs
.contains(inputName
)) {
623 inputs
.add(inputName
);
631 private void removeElement() {
632 selectedElement
.dispose();
633 selectedElement
= null;
634 elementContainer
.layout();
635 elementScrolledComposite
.setMinSize(elementContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).x
, elementContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).y
-1);
639 private String
getSelectionText() {
640 InputStream inputStream
= null;
641 if (this.selection
instanceof IStructuredSelection
) {
642 Object selection
= ((IStructuredSelection
)this.selection
).getFirstElement();
643 if (selection
instanceof IFile
) {
644 IFile file
= (IFile
)selection
;
646 inputStream
= file
.getContents();
647 } catch (CoreException e
) {
648 return ""; //$NON-NLS-1$
652 if (inputStream
!= null) {
654 BufferedReader reader
= new BufferedReader(new InputStreamReader(inputStream
));
655 StringBuilder sb
= new StringBuilder();
657 while ((line
= reader
.readLine()) != null) {
658 sb
.append(line
+ "\n"); //$NON-NLS-1$
660 parseXmlInput(sb
.toString());
661 return sb
.toString();
662 } catch (IOException e
) {
663 return ""; //$NON-NLS-1$
666 return ""; //$NON-NLS-1$
669 private void parseXmlInput(final String string
) {
671 DocumentBuilderFactory dbf
= DocumentBuilderFactory
.newInstance();
672 DocumentBuilder db
= dbf
.newDocumentBuilder();
674 // The following allows xml parsing without access to the dtd
675 EntityResolver resolver
= new EntityResolver () {
677 public InputSource
resolveEntity (String publicId
, String systemId
) {
678 String empty
= ""; //$NON-NLS-1$
679 ByteArrayInputStream bais
= new ByteArrayInputStream(empty
.getBytes());
680 return new InputSource(bais
);
683 db
.setEntityResolver(resolver
);
685 // The following catches xml parsing exceptions
686 db
.setErrorHandler(new ErrorHandler(){
688 public void error(SAXParseException saxparseexception
) throws SAXException
{}
690 public void warning(SAXParseException saxparseexception
) throws SAXException
{}
692 public void fatalError(SAXParseException saxparseexception
) throws SAXException
{
693 if (string
.trim().length() != 0) {
694 errorText
.setText(saxparseexception
.getMessage());
695 errorText
.setBackground(COLOR_LIGHT_RED
);
696 errorText
.setVisible(true);
698 throw saxparseexception
;
701 errorText
.setVisible(false);
703 doc
= db
.parse(new ByteArrayInputStream(string
.getBytes()));
704 documentElement
= doc
.getDocumentElement();
705 } catch (ParserConfigurationException e
) {
707 documentElement
= null;
708 } catch (SAXException e
) {
709 documentElement
= null;
710 } catch (IOException e
) {
712 documentElement
= null;
716 private void updatePreviews() {
717 updatePreviews(false);
720 private void updatePreviews(boolean updateAll
) {
721 if (inputText
== null) {
722 // early update during construction
725 inputText
.setStyleRanges(new StyleRange
[] {});
726 if (selectedElement
== null) {
730 timeStampValue
= null;
731 timeStampFormat
= null;
733 logEntryFound
= false;
735 selectedElement
.updatePreview();
737 if (timeStampValue
!= null && timeStampFormat
!= null) {
739 SimpleDateFormat dateFormat
= new SimpleDateFormat(timeStampFormat
);
740 Date date
= dateFormat
.parse(timeStampValue
);
741 dateFormat
= new SimpleDateFormat(timeStampOutputFormatText
.getText().trim());
742 timeStampPreviewText
.setText(dateFormat
.format(date
));
743 } catch (ParseException e
) {
744 timeStampPreviewText
.setText("*parse exception* [" + timeStampValue
+ "] <> [" + timeStampFormat
+ "]"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
745 } catch (IllegalArgumentException e
) {
746 timeStampPreviewText
.setText("*parse exception* [Illegal Argument]"); //$NON-NLS-1$
749 timeStampPreviewText
.setText("*no matching time stamp*"); //$NON-NLS-1$
753 private void openHelpShell(String url
) {
754 if (helpBrowser
!= null && !helpBrowser
.isDisposed()) {
755 helpBrowser
.getShell().setActive();
756 if (!helpBrowser
.getUrl().equals(url
)) {
757 helpBrowser
.setUrl(url
);
761 final Shell helpShell
= new Shell(getShell(), SWT
.SHELL_TRIM
);
762 helpShell
.setLayout(new FillLayout());
763 helpBrowser
= new Browser(helpShell
, SWT
.NONE
);
764 helpBrowser
.addTitleListener(new TitleListener() {
766 public void changed(TitleEvent event
) {
767 helpShell
.setText(event
.title
);
770 helpBrowser
.setBounds(0,0,600,400);
773 helpBrowser
.setUrl(url
);
776 private class UpdateListener
implements ModifyListener
, SelectionListener
{
779 public void modifyText(ModifyEvent e
) {
785 public void widgetDefaultSelected(SelectionEvent e
) {
791 public void widgetSelected(SelectionEvent e
) {
798 private class ElementNode
{
799 final InputElement inputElement
;
801 ArrayList
<Attribute
> attributes
= new ArrayList
<Attribute
>();
802 ArrayList
<ElementNode
> childElements
= new ArrayList
<ElementNode
>();
803 Text elementNameText
;
804 Composite tagComposite
;
811 Button logEntryButton
;
813 Composite addAttributeComposite
;
814 Button addAttributeButton
;
815 Label addAttributeLabel
;
817 public ElementNode(Composite parent
, InputElement inputElement
) {
818 this.inputElement
= inputElement
;
820 group
= new Group(parent
, SWT
.NONE
);
821 GridLayout gl
= new GridLayout(2, false);
824 group
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
825 group
.setText(getName(inputElement
));
827 Label label
= new Label(group
, SWT
.NULL
);
828 label
.setText(Messages
.CustomXmlParserInputWizardPage_elementName
);
829 label
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
831 elementNameText
= new Text(group
, SWT
.BORDER
| SWT
.SINGLE
);
832 GridData gd
= new GridData(SWT
.FILL
, SWT
.CENTER
, true, false);
834 elementNameText
.setLayoutData(gd
);
835 elementNameText
.addModifyListener(new ModifyListener(){
837 public void modifyText(ModifyEvent e
) {
838 ElementNode
.this.inputElement
.elementName
= elementNameText
.getText().trim();
839 group
.setText(getName(ElementNode
.this.inputElement
));
841 elementNameText
.setText(inputElement
.elementName
);
842 elementNameText
.addModifyListener(updateListener
);
844 if (inputElement
.parentElement
!= null) {
845 previewLabel
= new Label(group
, SWT
.NULL
);
846 previewLabel
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
847 previewLabel
.setText(Messages
.CustomXmlParserInputWizardPage_preview
);
849 previewText
= new Text(group
, SWT
.BORDER
| SWT
.SINGLE
| SWT
.READ_ONLY
);
850 gd
= new GridData(SWT
.FILL
, SWT
.CENTER
, true, false);
852 previewText
.setLayoutData(gd
);
853 previewText
.setText(Messages
.CustomXmlParserInputWizardPage_noMatchingElement
);
854 previewText
.setBackground(COLOR_WIDGET_BACKGROUND
);
856 logEntryButton
= new Button(group
, SWT
.CHECK
);
857 logEntryButton
.setText(Messages
.CustomXmlParserInputWizardPage_logEntry
);
858 logEntryButton
.setSelection(inputElement
.logEntry
);
859 logEntryButton
.addSelectionListener(new SelectionListener(){
861 public void widgetDefaultSelected(SelectionEvent e
) {}
863 public void widgetSelected(SelectionEvent e
) {
864 InputElement parent
= ElementNode
.this.inputElement
.parentElement
;
865 while (parent
!= null) {
866 parent
.logEntry
= false;
867 parent
= parent
.parentElement
;
870 logEntryButton
.addSelectionListener(updateListener
);
872 tagComposite
= new Composite(group
, SWT
.FILL
);
873 GridLayout tagLayout
= new GridLayout(4, false);
874 tagLayout
.marginWidth
= 0;
875 tagLayout
.marginHeight
= 0;
876 tagComposite
.setLayout(tagLayout
);
877 tagComposite
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
879 tagCombo
= new Combo(tagComposite
, SWT
.DROP_DOWN
| SWT
.READ_ONLY
);
880 tagCombo
.setItems(new String
[] {CustomXmlTraceDefinition
.TAG_IGNORE
,
881 CustomXmlTraceDefinition
.TAG_TIMESTAMP
,
882 CustomXmlTraceDefinition
.TAG_MESSAGE
,
883 CustomXmlTraceDefinition
.TAG_OTHER
});
884 tagCombo
.setVisibleItemCount(tagCombo
.getItemCount());
885 tagCombo
.addSelectionListener(new SelectionListener(){
887 public void widgetDefaultSelected(SelectionEvent e
) {}
889 public void widgetSelected(SelectionEvent e
) {
890 tagText
.removeModifyListener(updateListener
);
891 switch (tagCombo
.getSelectionIndex()) {
893 tagLabel
.setVisible(false);
894 tagText
.setVisible(false);
895 actionCombo
.setVisible(false);
898 tagLabel
.setText(Messages
.CustomXmlParserInputWizardPage_format
);
899 tagLabel
.setVisible(true);
900 tagText
.setVisible(true);
901 tagText
.addModifyListener(updateListener
);
902 actionCombo
.setVisible(true);
905 tagLabel
.setVisible(false);
906 tagText
.setVisible(false);
907 actionCombo
.setVisible(true);
910 tagLabel
.setText(Messages
.CustomXmlParserInputWizardPage_tagName
);
911 tagLabel
.setVisible(true);
912 if (tagText
.getText().trim().length() == 0) {
913 tagText
.setText(elementNameText
.getText().trim());
915 tagText
.setVisible(true);
916 tagText
.addModifyListener(updateListener
);
917 actionCombo
.setVisible(true);
920 tagComposite
.layout();
925 tagLabel
= new Label(tagComposite
, SWT
.NULL
);
926 tagLabel
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
928 tagText
= new Text(tagComposite
, SWT
.BORDER
| SWT
.SINGLE
);
929 gd
= new GridData(SWT
.FILL
, SWT
.CENTER
, true, false);
931 tagText
.setLayoutData(gd
);
933 actionCombo
= new Combo(tagComposite
, SWT
.DROP_DOWN
| SWT
.READ_ONLY
);
934 actionCombo
.setItems(new String
[] {Messages
.CustomXmlParserInputWizardPage_set
, Messages
.CustomXmlParserInputWizardPage_append
, Messages
.CustomXmlParserInputWizardPage_appendWith
});
935 actionCombo
.select(inputElement
.inputAction
);
936 actionCombo
.addSelectionListener(updateListener
);
938 if (inputElement
.inputName
.equals(CustomXmlTraceDefinition
.TAG_IGNORE
)) {
940 tagLabel
.setVisible(false);
941 tagText
.setVisible(false);
942 actionCombo
.setVisible(false);
943 } else if (inputElement
.inputName
.equals(CustomXmlTraceDefinition
.TAG_TIMESTAMP
)) {
945 tagLabel
.setText(Messages
.CustomXmlParserInputWizardPage_format
);
946 tagText
.setText(inputElement
.inputFormat
);
947 tagText
.addModifyListener(updateListener
);
948 } else if (inputElement
.inputName
.equals(CustomXmlTraceDefinition
.TAG_MESSAGE
)) {
950 tagLabel
.setVisible(false);
951 tagText
.setVisible(false);
954 tagLabel
.setText(Messages
.CustomXmlParserInputWizardPage_tagName
);
955 tagText
.setText(inputElement
.inputName
);
956 tagText
.addModifyListener(updateListener
);
960 if (inputElement
.attributes
!= null) {
961 for (InputAttribute inputAttribute
: inputElement
.attributes
) {
962 Attribute attribute
= new Attribute(group
, this, inputAttribute
, attributes
.size()+1);
963 attributes
.add(attribute
);
970 private void updatePreview() {
971 Element element
= getPreviewElement(inputElement
);
972 if (inputElement
.parentElement
!= null) { // no preview text for document element
973 previewText
.setText(Messages
.CustomXmlParserInputWizardPage_noMatchingElement
);
974 if (element
!= null) {
975 previewText
.setText(CustomXmlTrace
.parseElement(element
, new StringBuffer()).toString());
976 if (logEntryButton
.getSelection()) {
977 if (logEntryFound
== false) {
978 logEntryFound
= true;
981 logEntryButton
.setSelection(false); // remove nested log entry
984 if (tagCombo
.getText().equals(CustomXmlTraceDefinition
.TAG_TIMESTAMP
) && logEntriesCount
<= 1) {
985 String value
= previewText
.getText().trim();
986 if (value
.length() != 0) {
987 if (actionCombo
.getSelectionIndex() == CustomXmlTraceDefinition
.ACTION_SET
) {
988 timeStampValue
= value
;
989 timeStampFormat
= tagText
.getText().trim();
990 } else if (actionCombo
.getSelectionIndex() == CustomXmlTraceDefinition
.ACTION_APPEND
) {
991 if (timeStampValue
!= null) {
992 timeStampValue
+= value
;
993 timeStampFormat
+= tagText
.getText().trim();
995 timeStampValue
= value
;
996 timeStampFormat
= tagText
.getText().trim();
998 } else if (actionCombo
.getSelectionIndex() == CustomXmlTraceDefinition
.ACTION_APPEND_WITH_SEPARATOR
) {
999 if (timeStampValue
!= null) {
1000 timeStampValue
+= " | " + value
; //$NON-NLS-1$
1001 timeStampFormat
+= " | " + tagText
.getText().trim(); //$NON-NLS-1$
1003 timeStampValue
= value
;
1004 timeStampFormat
= tagText
.getText().trim();
1011 for (Attribute attribute
: attributes
) {
1012 if (element
!= null) {
1013 String value
= element
.getAttribute(attribute
.attributeNameText
.getText().trim());
1014 if (value
.length() != 0) {
1015 attribute
.previewText
.setText(value
);
1016 if (attribute
.tagCombo
.getText().equals(CustomXmlTraceDefinition
.TAG_TIMESTAMP
) && logEntriesCount
<= 1) {
1017 if (attribute
.actionCombo
.getSelectionIndex() == CustomXmlTraceDefinition
.ACTION_SET
) {
1018 timeStampValue
= value
;
1019 timeStampFormat
= attribute
.tagText
.getText().trim();
1020 } else if (attribute
.actionCombo
.getSelectionIndex() == CustomXmlTraceDefinition
.ACTION_APPEND
) {
1021 if (timeStampValue
!= null) {
1022 timeStampValue
+= value
;
1023 timeStampFormat
+= attribute
.tagText
.getText().trim();
1025 timeStampValue
= value
;
1026 timeStampFormat
= attribute
.tagText
.getText().trim();
1028 } else if (attribute
.actionCombo
.getSelectionIndex() == CustomXmlTraceDefinition
.ACTION_APPEND_WITH_SEPARATOR
) {
1029 if (timeStampValue
!= null) {
1030 timeStampValue
+= " | " + value
; //$NON-NLS-1$
1031 timeStampFormat
+= " | " + attribute
.tagText
.getText().trim(); //$NON-NLS-1$
1033 timeStampValue
= value
;
1034 timeStampFormat
= attribute
.tagText
.getText().trim();
1039 attribute
.previewText
.setText(Messages
.CustomXmlParserInputWizardPage_noMatchingAttribute
);
1042 attribute
.previewText
.setText(Messages
.CustomXmlParserInputWizardPage_noMatchingElement
);
1045 for (ElementNode child
: childElements
) {
1046 child
.updatePreview();
1048 if (logEntryButton
!= null && logEntryButton
.getSelection()) {
1049 logEntryFound
= false;
1053 private void createAddButton() {
1054 fillerLabel
= new Label(group
, SWT
.NONE
);
1056 addAttributeComposite
= new Composite(group
, SWT
.NONE
);
1057 addAttributeComposite
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
1058 GridLayout addAttributeLayout
= new GridLayout(2, false);
1059 addAttributeLayout
.marginHeight
= 0;
1060 addAttributeLayout
.marginWidth
= 0;
1061 addAttributeComposite
.setLayout(addAttributeLayout
);
1063 addAttributeButton
= new Button(addAttributeComposite
, SWT
.PUSH
);
1064 addAttributeButton
.setImage(addImage
);
1065 addAttributeButton
.setToolTipText(Messages
.CustomXmlParserInputWizardPage_addAttribute
);
1066 addAttributeButton
.addSelectionListener(new SelectionAdapter() {
1068 public void widgetSelected(SelectionEvent e
) {
1070 String attributeName
= getAttributeNameSuggestion(inputElement
);
1071 InputAttribute inputAttribute
= new InputAttribute(attributeName
, attributeName
, 0, ""); //$NON-NLS-1$
1072 attributes
.add(new Attribute(group
, ElementNode
.this, inputAttribute
, attributes
.size()+1));
1074 elementContainer
.layout();
1075 elementScrolledComposite
.setMinSize(elementContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).x
, elementContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).y
-1);
1076 group
.getParent().layout();
1082 addAttributeLabel
= new Label(addAttributeComposite
, SWT
.NULL
);
1083 addAttributeLabel
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
1084 addAttributeLabel
.setText(Messages
.CustomXmlParserInputWizardPage_newAttibute
);
1087 private void removeAddButton() {
1088 fillerLabel
.dispose();
1089 addAttributeComposite
.dispose();
1092 private void removeAttribute(int attributeNumber
) {
1093 if (--attributeNumber
< attributes
.size()) {
1094 attributes
.remove(attributeNumber
).dispose();
1095 for (int i
= attributeNumber
; i
< attributes
.size(); i
++) {
1096 attributes
.get(i
).setAttributeNumber(i
+1);
1098 elementContainer
.layout();
1099 elementScrolledComposite
.setMinSize(elementContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).x
, elementContainer
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
).y
-1);
1100 group
.getParent().layout();
1104 private void dispose() {
1108 private void extractInputs() {
1109 inputElement
.elementName
= elementNameText
.getText().trim();
1110 if (inputElement
.parentElement
!= null) {
1111 inputElement
.logEntry
= logEntryButton
.getSelection();
1112 if (tagCombo
.getText().equals(CustomXmlTraceDefinition
.TAG_OTHER
)) {
1113 inputElement
.inputName
= tagText
.getText().trim();
1115 inputElement
.inputName
= tagCombo
.getText();
1116 if (tagCombo
.getText().equals(CustomXmlTraceDefinition
.TAG_TIMESTAMP
)) {
1117 inputElement
.inputFormat
= tagText
.getText().trim();
1120 inputElement
.inputAction
= actionCombo
.getSelectionIndex();
1122 inputElement
.attributes
= new ArrayList
<InputAttribute
>(attributes
.size());
1123 for (int i
= 0; i
< attributes
.size(); i
++) {
1124 Attribute attribute
= attributes
.get(i
);
1125 InputAttribute inputAttribute
= new InputAttribute();
1126 inputAttribute
.attributeName
= attribute
.attributeNameText
.getText().trim();
1127 if (attribute
.tagCombo
.getText().equals(CustomXmlTraceDefinition
.TAG_OTHER
)) {
1128 inputAttribute
.inputName
= attribute
.tagText
.getText().trim();
1130 inputAttribute
.inputName
= attribute
.tagCombo
.getText();
1131 if (attribute
.tagCombo
.getText().equals(CustomXmlTraceDefinition
.TAG_TIMESTAMP
)) {
1132 inputAttribute
.inputFormat
= attribute
.tagText
.getText().trim();
1135 inputAttribute
.inputAction
= attribute
.actionCombo
.getSelectionIndex();
1136 inputElement
.addAttribute(inputAttribute
);
1141 private class Attribute
{
1142 ElementNode element
;
1143 int attributeNumber
;
1145 // children of parent (must be disposed)
1146 Composite labelComposite
;
1147 Composite attributeComposite
;
1149 Composite tagComposite
;
1151 // children of labelComposite
1152 Label attributeLabel
;
1154 // children of attributeComposite
1155 Text attributeNameText
;
1158 // children of tagComposite
1164 public Attribute(Composite parent
, ElementNode element
, InputAttribute inputAttribute
, int attributeNumber
) {
1165 this.element
= element
;
1166 this.attributeNumber
= attributeNumber
;
1168 labelComposite
= new Composite(parent
, SWT
.FILL
);
1169 GridLayout labelLayout
= new GridLayout(2, false);
1170 labelLayout
.marginWidth
= 0;
1171 labelLayout
.marginHeight
= 0;
1172 labelComposite
.setLayout(labelLayout
);
1173 labelComposite
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
1175 Button deleteButton
= new Button(labelComposite
, SWT
.PUSH
);
1176 deleteButton
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
1177 deleteButton
.setImage(deleteImage
);
1178 deleteButton
.setToolTipText(Messages
.CustomXmlParserInputWizardPage_removeAttribute
);
1179 deleteButton
.addSelectionListener(new SelectionAdapter() {
1181 public void widgetSelected(SelectionEvent e
) {
1182 Attribute
.this.element
.removeAttribute(Attribute
.this.attributeNumber
);
1188 attributeLabel
= new Label(labelComposite
, SWT
.NULL
);
1189 attributeLabel
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
1190 attributeLabel
.setText(Messages
.CustomXmlParserInputWizardPage_attibute
);
1192 attributeComposite
= new Composite(parent
, SWT
.FILL
);
1193 GridLayout attributeLayout
= new GridLayout(4, false);
1194 attributeLayout
.marginWidth
= 0;
1195 attributeLayout
.marginHeight
= 0;
1196 attributeComposite
.setLayout(attributeLayout
);
1197 attributeComposite
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
1199 Label nameLabel
= new Label(attributeComposite
, SWT
.NONE
);
1200 nameLabel
.setText(Messages
.CustomXmlParserInputWizardPage_name
);
1202 attributeNameText
= new Text(attributeComposite
, SWT
.BORDER
| SWT
.SINGLE
);
1203 attributeNameText
.setLayoutData(new GridData(120, SWT
.DEFAULT
));
1204 attributeNameText
.setText(inputAttribute
.attributeName
);
1205 attributeNameText
.addModifyListener(updateListener
);
1207 Label previewLabel
= new Label(attributeComposite
, SWT
.NONE
);
1208 previewLabel
.setText(Messages
.CustomXmlParserInputWizardPage_preview
);
1210 previewText
= new Text(attributeComposite
, SWT
.BORDER
| SWT
.SINGLE
| SWT
.READ_ONLY
);
1211 GridData gd
= new GridData(SWT
.FILL
, SWT
.CENTER
, true, false);
1213 previewText
.setLayoutData(gd
);
1214 previewText
.setText(Messages
.CustomXmlParserInputWizardPage_noMatch
);
1215 previewText
.setBackground(COLOR_WIDGET_BACKGROUND
);
1217 filler
= new Label(parent
, SWT
.NULL
);
1219 tagComposite
= new Composite(parent
, SWT
.FILL
);
1220 GridLayout tagLayout
= new GridLayout(4, false);
1221 tagLayout
.marginWidth
= 0;
1222 tagLayout
.marginHeight
= 0;
1223 tagComposite
.setLayout(tagLayout
);
1224 tagComposite
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
1226 tagCombo
= new Combo(tagComposite
, SWT
.DROP_DOWN
| SWT
.READ_ONLY
);
1227 tagCombo
.setItems(new String
[] {CustomXmlTraceDefinition
.TAG_TIMESTAMP
,
1228 CustomXmlTraceDefinition
.TAG_MESSAGE
,
1229 CustomXmlTraceDefinition
.TAG_OTHER
});
1230 tagCombo
.select(2); //Other
1231 tagCombo
.addSelectionListener(new SelectionListener(){
1233 public void widgetDefaultSelected(SelectionEvent e
) {}
1235 public void widgetSelected(SelectionEvent e
) {
1236 tagText
.removeModifyListener(updateListener
);
1237 switch (tagCombo
.getSelectionIndex()) {
1238 case 0: //Time Stamp
1239 tagLabel
.setText(Messages
.CustomXmlParserInputWizardPage_format
);
1240 tagLabel
.setVisible(true);
1241 tagText
.setVisible(true);
1242 tagText
.addModifyListener(updateListener
);
1245 tagLabel
.setVisible(false);
1246 tagText
.setVisible(false);
1249 tagLabel
.setText(Messages
.CustomXmlParserInputWizardPage_tagName
);
1250 tagLabel
.setVisible(true);
1251 if (tagText
.getText().trim().length() == 0) {
1252 tagText
.setText(attributeNameText
.getText().trim());
1254 tagText
.setVisible(true);
1255 tagText
.addModifyListener(updateListener
);
1258 tagComposite
.layout();
1263 tagLabel
= new Label(tagComposite
, SWT
.NULL
);
1264 tagLabel
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
1266 tagText
= new Text(tagComposite
, SWT
.BORDER
| SWT
.SINGLE
);
1267 gd
= new GridData(SWT
.FILL
, SWT
.CENTER
, true, false);
1269 tagText
.setLayoutData(gd
);
1270 tagText
.setText(attributeNameText
.getText());
1272 actionCombo
= new Combo(tagComposite
, SWT
.DROP_DOWN
| SWT
.READ_ONLY
);
1273 actionCombo
.setItems(new String
[] {Messages
.CustomXmlParserInputWizardPage_set
, Messages
.CustomXmlParserInputWizardPage_append
, Messages
.CustomXmlParserInputWizardPage_appendWith
});
1274 actionCombo
.select(inputAttribute
.inputAction
);
1275 actionCombo
.addSelectionListener(updateListener
);
1277 if (inputAttribute
.inputName
.equals(CustomXmlTraceDefinition
.TAG_TIMESTAMP
)) {
1279 tagLabel
.setText(Messages
.CustomXmlParserInputWizardPage_format
);
1280 tagText
.setText(inputAttribute
.inputFormat
);
1281 tagText
.addModifyListener(updateListener
);
1282 } else if (inputAttribute
.inputName
.equals(CustomXmlTraceDefinition
.TAG_MESSAGE
)) {
1284 tagLabel
.setVisible(false);
1285 tagText
.setVisible(false);
1288 tagLabel
.setText(Messages
.CustomXmlParserInputWizardPage_tagName
);
1289 tagText
.setText(inputAttribute
.inputName
);
1290 tagText
.addModifyListener(updateListener
);
1294 private void dispose() {
1295 labelComposite
.dispose();
1296 attributeComposite
.dispose();
1298 tagComposite
.dispose();
1301 private void setAttributeNumber(int attributeNumber
) {
1302 this.attributeNumber
= attributeNumber
;
1303 labelComposite
.layout();
1307 private Element
getPreviewElement(InputElement inputElement
) {
1308 Element element
= documentElement
;
1309 if (element
!= null) {
1310 if (!documentElement
.getNodeName().equals(definition
.rootInputElement
.elementName
)) {
1313 ArrayList
<String
> elementNames
= new ArrayList
<String
>();
1314 while (inputElement
!= null) {
1315 elementNames
.add(inputElement
.elementName
);
1316 inputElement
= inputElement
.parentElement
;
1318 for (int i
= elementNames
.size() - 1; --i
>= 0;) {
1319 NodeList childList
= element
.getChildNodes();
1321 for (int j
= 0; j
< childList
.getLength(); j
++) {
1322 Node child
= childList
.item(j
);
1323 if (child
instanceof Element
&& child
.getNodeName().equals(elementNames
.get(i
))) {
1324 element
= (Element
)child
;
1328 if (element
== null) {
1332 if (element
!= null) {
1339 private String
getChildNameSuggestion(InputElement inputElement
) {
1340 if (inputElement
== null) {
1341 if (documentElement
!= null) {
1342 return documentElement
.getNodeName();
1345 Element element
= getPreviewElement(inputElement
);
1346 if (element
!= null) {
1347 NodeList childNodes
= element
.getChildNodes();
1348 for (int i
= 0; i
< childNodes
.getLength(); i
++) {
1349 Node node
= childNodes
.item(i
);
1350 if (node
instanceof Element
) {
1351 boolean unused
= true;
1352 if (inputElement
.childElements
!= null) {
1353 for (InputElement child
: inputElement
.childElements
) {
1354 if (child
.elementName
.equals(node
.getNodeName())) {
1361 return node
.getNodeName();
1367 return ""; //$NON-NLS-1$
1370 private String
getAttributeNameSuggestion(InputElement inputElement
) {
1371 Element element
= getPreviewElement(inputElement
);
1372 if (element
!= null) {
1373 NamedNodeMap attributeMap
= element
.getAttributes();
1374 for (int i
= 0; i
< attributeMap
.getLength(); i
++) {
1375 Node node
= attributeMap
.item(i
);
1376 boolean unused
= true;
1377 if (inputElement
.attributes
!= null) {
1378 for (InputAttribute attribute
: inputElement
.attributes
) {
1379 if (attribute
.attributeName
.equals(node
.getNodeName())) {
1386 return node
.getNodeName();
1390 return ""; //$NON-NLS-1$
1393 private void validate() {
1394 definition
.definitionName
= logtypeText
.getText().trim();
1395 definition
.timeStampOutputFormat
= timeStampOutputFormatText
.getText().trim();
1397 if (selectedElement
!= null) {
1398 selectedElement
.extractInputs();
1399 treeViewer
.refresh();
1402 StringBuffer errors
= new StringBuffer();
1404 if (definition
.definitionName
.length() == 0) {
1405 errors
.append(Messages
.CustomXmlParserInputWizardPage_emptyLogTypeError
);
1406 logtypeText
.setBackground(COLOR_LIGHT_RED
);
1408 logtypeText
.setBackground(COLOR_TEXT_BACKGROUND
);
1409 for (CustomXmlTraceDefinition def
: CustomXmlTraceDefinition
.loadAll()) {
1410 if (definition
.definitionName
.equals(def
.definitionName
)) {
1411 if (editDefinitionName
== null || ! editDefinitionName
.equals(definition
.definitionName
)) {
1412 errors
.append(Messages
.CustomXmlParserInputWizardPage_duplicatelogTypeError
);
1413 logtypeText
.setBackground(COLOR_LIGHT_RED
);
1420 if (definition
.rootInputElement
== null) {
1421 errors
.append(Messages
.CustomXmlParserInputWizardPage_noDocumentError
);
1424 if (definition
.rootInputElement
!= null) {
1425 logEntryFound
= false;
1426 logEntryNestedCount
= 0;
1427 timeStampFound
= false;
1429 errors
.append(validateElement(definition
.rootInputElement
));
1431 if ((definition
.rootInputElement
.attributes
!= null && definition
.rootInputElement
.attributes
.size() != 0) ||
1432 (definition
.rootInputElement
.childElements
!= null && definition
.rootInputElement
.childElements
.size() != 0) || errors
.length() == 0) {
1433 if (!logEntryFound
) {
1434 errors
.append(Messages
.CustomXmlParserInputWizardPage_missingLogEntryError
);
1437 if (timeStampFound
) {
1438 if (timeStampOutputFormatText
.getText().trim().length() == 0) {
1439 errors
.append(Messages
.CustomXmlParserInputWizardPage_missingTimestampFmtError
);
1440 timeStampOutputFormatText
.setBackground(COLOR_LIGHT_RED
);
1443 new SimpleDateFormat(timeStampOutputFormatText
.getText().trim());
1444 timeStampOutputFormatText
.setBackground(COLOR_TEXT_BACKGROUND
);
1445 } catch (IllegalArgumentException e
) {
1446 errors
.append(Messages
.CustomXmlParserInputWizardPage_invalidTimestampFmtError
);
1447 timeStampOutputFormatText
.setBackground(COLOR_LIGHT_RED
);
1451 timeStampPreviewText
.setText(Messages
.CustomXmlParserInputWizardPage_notimestamporAttributeError
);
1455 timeStampPreviewText
.setText(Messages
.CustomXmlParserInputWizardPage_notimestamporAttributeError
);
1458 if (errors
.length() == 0) {
1459 setDescription(defaultDescription
);
1460 setPageComplete(true);
1462 setDescription(errors
.toString());
1463 setPageComplete(false);
1467 public StringBuffer
validateElement(InputElement inputElement
) {
1468 StringBuffer errors
= new StringBuffer();
1469 ElementNode elementNode
= null;
1470 if (selectedElement
!= null && selectedElement
.inputElement
.equals(inputElement
)) elementNode
= selectedElement
;
1471 if (inputElement
== definition
.rootInputElement
) {
1472 if (inputElement
.elementName
.length() == 0) {
1473 errors
.append(Messages
.CustomXmlParserInputWizardPage_missingDocumentElementError
);
1474 if (elementNode
!= null) elementNode
.elementNameText
.setBackground(COLOR_LIGHT_RED
);
1476 if (elementNode
!= null) elementNode
.elementNameText
.setBackground(COLOR_TEXT_BACKGROUND
);
1479 if (inputElement
!= definition
.rootInputElement
) {
1480 if (inputElement
.logEntry
) {
1481 logEntryFound
= true;
1482 logEntryNestedCount
++;
1484 if (inputElement
.inputName
.equals(CustomXmlTraceDefinition
.TAG_TIMESTAMP
)) {
1485 timeStampFound
= true;
1486 if (inputElement
.inputFormat
.length() == 0) {
1487 errors
.append(Messages
.CustomXmlParserInputWizardPage_timestampFormatPrompt
+
1488 " (" + Messages
.CustomXmlParserInputWizardPage_timestampElementPrompt
+ " " + getName(inputElement
) + "). "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
1489 if (elementNode
!= null) elementNode
.tagText
.setBackground(COLOR_LIGHT_RED
);
1492 new SimpleDateFormat(inputElement
.inputFormat
);
1493 if (elementNode
!= null) elementNode
.tagText
.setBackground(COLOR_TEXT_BACKGROUND
);
1494 } catch (IllegalArgumentException e
) {
1495 errors
.append(Messages
.CustomXmlParserInputWizardPage_invalidTimestampFmtError
+
1496 " (" + Messages
.CustomXmlParserInputWizardPage_timestampElementPrompt
+ " " + getName(inputElement
) + "). "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
1497 if (elementNode
!= null) elementNode
.tagText
.setBackground(COLOR_LIGHT_RED
);
1500 } else if (inputElement
.inputName
.length() == 0) {
1501 errors
.append(Messages
.CustomXmlParserInputWizardPage_missingInputElementNameError
);
1502 if (elementNode
!= null) elementNode
.tagText
.setBackground(COLOR_LIGHT_RED
);
1504 if (elementNode
!= null) elementNode
.tagText
.setBackground(COLOR_TEXT_BACKGROUND
);
1507 if (inputElement
.attributes
!= null) {
1508 if (elementNode
!= null) {
1509 for (Attribute attribute
: elementNode
.attributes
) {
1510 attribute
.attributeNameText
.setBackground(COLOR_TEXT_BACKGROUND
);
1513 for (int i
= 0; i
< inputElement
.attributes
.size(); i
++) {
1514 InputAttribute attribute
= inputElement
.attributes
.get(i
);
1515 boolean duplicate
= false;
1516 for (int j
= i
+ 1; j
< inputElement
.attributes
.size(); j
++) {
1517 InputAttribute otherAttribute
= inputElement
.attributes
.get(j
);
1518 if (otherAttribute
.attributeName
.equals(attribute
.attributeName
)) {
1520 if (elementNode
!= null) {
1521 elementNode
.attributes
.get(j
).attributeNameText
.setBackground(COLOR_LIGHT_RED
);
1525 if (attribute
.attributeName
.length() == 0) {
1526 errors
.append(Messages
.CustomXmlParserInputWizardPage_missingAttribute
+
1527 " (" + Messages
.CustomXmlParserInputWizardPage_attributePrompt
+ " " + getName(inputElement
) + ": ?). "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
1528 if (elementNode
!= null) elementNode
.attributes
.get(i
).attributeNameText
.setBackground(COLOR_LIGHT_RED
);
1529 } else if (duplicate
) {
1530 errors
.append(Messages
.CustomXmlParserInputWizardPage_duplicateAttributeError
+
1531 " (" + Messages
.CustomXmlParserInputWizardPage_attributePrompt
+ " " + getName(attribute
, inputElement
) +"). "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
1532 if (elementNode
!= null) elementNode
.attributes
.get(i
).attributeNameText
.setBackground(COLOR_LIGHT_RED
);
1534 if (attribute
.inputName
.equals(CustomXmlTraceDefinition
.TAG_TIMESTAMP
)) {
1535 timeStampFound
= true;
1536 if (attribute
.inputFormat
.length() == 0) {
1537 errors
.append(Messages
.CustomXmlParserInputWizardPage_missingTimestampInFmtError
+
1538 " (" + Messages
.CustomXmlParserInputWizardPage_attributePrompt
+ " " + getName(attribute
, inputElement
) +"). "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
1539 if (elementNode
!= null) elementNode
.attributes
.get(i
).tagText
.setBackground(COLOR_LIGHT_RED
);
1542 new SimpleDateFormat(attribute
.inputFormat
);
1543 if (elementNode
!= null) elementNode
.attributes
.get(i
).tagText
.setBackground(COLOR_TEXT_BACKGROUND
);
1544 } catch (IllegalArgumentException e
) {
1545 errors
.append(Messages
.CustomXmlParserInputWizardPage_invalidTimestampInFmtError
+
1546 " (" + Messages
.CustomXmlParserInputWizardPage_attributePrompt
+ " " + getName(attribute
, inputElement
) +"). "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
1547 if (elementNode
!= null) elementNode
.attributes
.get(i
).tagText
.setBackground(COLOR_LIGHT_RED
);
1550 } else if (attribute
.inputName
.length() == 0) {
1551 errors
.append(Messages
.CustomXmlParserInputWizardPage_missingDataGroupNameError
+
1552 " (" + Messages
.CustomXmlParserInputWizardPage_attributePrompt
+ " " + getName(attribute
, inputElement
) +"). "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
1553 if (elementNode
!= null) elementNode
.attributes
.get(i
).tagText
.setBackground(COLOR_LIGHT_RED
);
1555 if (elementNode
!= null) elementNode
.attributes
.get(i
).tagText
.setBackground(COLOR_TEXT_BACKGROUND
);
1559 if (inputElement
.childElements
!= null) {
1560 for (InputElement child
: inputElement
.childElements
) {
1561 ElementNode childElementNode
= null;
1562 if (selectedElement
!= null && selectedElement
.inputElement
.equals(child
)) childElementNode
= selectedElement
;
1563 if (childElementNode
!= null) childElementNode
.elementNameText
.setBackground(COLOR_TEXT_BACKGROUND
);
1565 for (int i
= 0; i
< inputElement
.childElements
.size(); i
++) {
1566 InputElement child
= inputElement
.childElements
.get(i
);
1567 ElementNode childElementNode
= null;
1568 if (selectedElement
!= null && selectedElement
.inputElement
.equals(child
)) childElementNode
= selectedElement
;
1569 if (child
.elementName
.length() == 0) {
1570 errors
.append(Messages
.CustomXmlParserInputWizardPage_missingElementNameError
+
1571 " (" + Messages
.CustomXmlParserInputWizardPage_attributePrompt
+ " " + getName(child
) + "). "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
1572 if (childElementNode
!= null) childElementNode
.elementNameText
.setBackground(COLOR_LIGHT_RED
);
1574 boolean duplicate
= false;
1575 for (int j
= i
+ 1; j
< inputElement
.childElements
.size(); j
++) {
1576 InputElement otherChild
= inputElement
.childElements
.get(j
);
1577 if (otherChild
.elementName
.equals(child
.elementName
)) {
1579 ElementNode otherChildElementNode
= null;
1580 if (selectedElement
!= null && selectedElement
.inputElement
.equals(otherChild
)) otherChildElementNode
= selectedElement
;
1581 if (otherChildElementNode
!= null) otherChildElementNode
.elementNameText
.setBackground(COLOR_LIGHT_RED
);
1585 errors
.append(Messages
.CustomXmlParserInputWizardPage_duplicateElementNameError
+
1586 " (" + Messages
.CustomXmlParserInputWizardPage_attributePrompt
+ " " + getName(child
) + "). "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
1587 if (childElementNode
!= null) childElementNode
.elementNameText
.setBackground(COLOR_LIGHT_RED
);
1591 errors
.append(validateElement(child
));
1594 if (inputElement
.logEntry
) {
1595 logEntryNestedCount
--;
1600 public CustomXmlTraceDefinition
getDefinition() {
1604 public char[] getInputText() {
1605 return inputText
.getText().toCharArray();