Commit | Line | Data |
---|---|---|
be222f56 PT |
1 | package org.eclipse.linuxtools.internal.tmf.ui.parsers.wizards; |
2 | ||
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; | |
13 | ||
14 | import javax.xml.parsers.DocumentBuilder; | |
15 | import javax.xml.parsers.DocumentBuilderFactory; | |
16 | import javax.xml.parsers.ParserConfigurationException; | |
17 | ||
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; | |
76 | ||
77 | public class CustomXmlParserInputWizardPage extends WizardPage { | |
78 | ||
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); | |
93 | ||
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; | |
120 | ||
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; | |
127 | ||
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; | |
133 | } else { | |
134 | setTitle(Messages.CustomXmlParserInputWizardPage_titleEdit); | |
135 | defaultDescription = Messages.CustomXmlParserInputWizardPage_descriptionEdit; | |
136 | } | |
137 | setDescription(defaultDescription); | |
138 | this.selection = selection; | |
139 | this.definition = definition; | |
140 | if (definition != null) { | |
141 | this.editDefinitionName = definition.definitionName; | |
142 | } | |
143 | } | |
144 | ||
145 | @Override | |
146 | public void createControl(Composite parent) { | |
147 | container = new Composite(parent, SWT.NULL); | |
148 | container.setLayout(new GridLayout()); | |
149 | ||
150 | updateListener = new UpdateListener(); | |
151 | ||
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)); | |
158 | ||
159 | Label logtypeLabel = new Label(headerComposite, SWT.NULL); | |
160 | logtypeLabel.setText(Messages.CustomXmlParserInputWizardPage_logType); | |
161 | ||
162 | logtypeText = new Text(headerComposite, SWT.BORDER | SWT.SINGLE); | |
163 | logtypeText.setLayoutData(new GridData(120, SWT.DEFAULT)); | |
164 | ||
165 | Label timeStampFormatLabel = new Label(headerComposite, SWT.NULL); | |
166 | timeStampFormatLabel.setText(Messages.CustomXmlParserInputWizardPage_timestampFormat); | |
167 | ||
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); | |
171 | ||
172 | Button dateFormatHelpButton = new Button(headerComposite, SWT.PUSH); | |
173 | dateFormatHelpButton.setImage(helpImage); | |
174 | dateFormatHelpButton.setToolTipText(Messages.CustomXmlParserInputWizardPage_dateFormatHelp); | |
175 | dateFormatHelpButton.addSelectionListener(new SelectionAdapter() { | |
176 | @Override | |
177 | public void widgetSelected(SelectionEvent e) { | |
178 | openHelpShell(SIMPLE_DATE_FORMAT_URL); | |
179 | } | |
180 | }); | |
181 | ||
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); | |
185 | ||
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$ | |
189 | ||
190 | createButtonBar(); | |
191 | ||
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)); | |
195 | ||
196 | SashForm hSash = new SashForm(vSash, SWT.HORIZONTAL); | |
197 | hSash.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); | |
198 | ||
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); | |
206 | ||
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(); | |
212 | ||
213 | treeScrolledComposite | |
214 | .setMinSize(treeContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT).x, treeContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT).y); | |
215 | ||
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(); | |
220 | gl.marginHeight = 1; | |
221 | gl.marginWidth = 0; | |
222 | elementContainer.setLayout(gl); | |
223 | elementScrolledComposite.setContent(elementContainer); | |
224 | elementScrolledComposite.setExpandHorizontal(true); | |
225 | elementScrolledComposite.setExpandVertical(true); | |
226 | ||
227 | if (definition == null) { | |
228 | definition = new CustomXmlTraceDefinition(); | |
229 | } | |
230 | loadDefinition(definition); | |
231 | treeViewer.expandAll(); | |
232 | elementContainer.layout(); | |
233 | ||
234 | logtypeText.addModifyListener(updateListener); | |
235 | timeStampOutputFormatText.addModifyListener(updateListener); | |
236 | ||
237 | elementScrolledComposite.setMinSize(elementContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT).x, | |
238 | elementContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT).y - 1); | |
239 | ||
240 | hSash.setWeights(new int[] { 1, 2 }); | |
241 | ||
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); | |
250 | } | |
251 | ||
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); | |
257 | ||
258 | Label previewLabel = new Label(sashBottom, SWT.NULL); | |
259 | previewLabel.setText(Messages.CustomXmlParserInputWizardPage_previewInput); | |
260 | ||
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); | |
265 | ||
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$ | |
270 | } else { | |
271 | fixedFont = new Font(Display.getCurrent(), new FontData("Monospace", 10, SWT.NORMAL)); //$NON-NLS-1$ | |
272 | } | |
273 | } | |
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; | |
277 | gd.widthHint = 800; | |
278 | inputText.setLayoutData(gd); | |
279 | inputText.setText(getSelectionText()); | |
280 | inputText.addModifyListener(new ModifyListener() { | |
281 | @Override | |
282 | public void modifyText(ModifyEvent e) { | |
283 | parseXmlInput(inputText.getText()); | |
284 | } | |
285 | }); | |
286 | inputText.addModifyListener(updateListener); | |
287 | ||
288 | vSash.setWeights(new int[] { hSash.computeSize(SWT.DEFAULT, SWT.DEFAULT).y, sashBottom.computeSize(SWT.DEFAULT, SWT.DEFAULT).y }); | |
289 | ||
290 | setControl(container); | |
291 | } | |
292 | ||
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); | |
299 | ||
300 | removeButton = new Button(buttonBar, SWT.PUSH); | |
301 | removeButton.setImage(deleteImage); | |
302 | removeButton.setToolTipText(Messages.CustomXmlParserInputWizardPage_removeElement); | |
303 | removeButton.addSelectionListener(new SelectionAdapter() { | |
304 | @Override | |
305 | public void widgetSelected(SelectionEvent e) { | |
306 | if (treeViewer.getSelection().isEmpty() || selectedElement == null) { | |
307 | return; | |
308 | } | |
309 | removeElement(); | |
310 | InputElement inputElement = (InputElement) ((IStructuredSelection) treeViewer.getSelection()).getFirstElement(); | |
311 | if (inputElement == definition.rootInputElement) { | |
312 | definition.rootInputElement = null; | |
313 | } else { | |
314 | inputElement.parentElement.childElements.remove(inputElement); | |
315 | } | |
316 | treeViewer.refresh(); | |
317 | validate(); | |
318 | updatePreviews(); | |
319 | removeButton.setEnabled(false); | |
320 | if (definition.rootInputElement == null) { | |
321 | addChildButton.setEnabled(true); | |
322 | addChildButton.setToolTipText(Messages.CustomXmlParserInputWizardPage_addDocumentEleemnt); | |
323 | } else { | |
324 | addChildButton.setEnabled(false); | |
325 | } | |
326 | addNextButton.setEnabled(false); | |
327 | moveUpButton.setEnabled(false); | |
328 | moveDownButton.setEnabled(false); | |
329 | } | |
330 | }); | |
331 | ||
332 | addChildButton = new Button(buttonBar, SWT.PUSH); | |
333 | addChildButton.setImage(addChildImage); | |
334 | addChildButton.setToolTipText(Messages.CustomXmlParserInputWizardPage_addChildElement); | |
335 | addChildButton.addSelectionListener(new SelectionAdapter() { | |
336 | @Override | |
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()) { | |
343 | return; | |
344 | } else { | |
345 | InputElement parentInputElement = (InputElement) ((IStructuredSelection) treeViewer.getSelection()).getFirstElement(); | |
346 | parentInputElement.addChild(inputElement); | |
347 | inputElement.elementName = getChildNameSuggestion(parentInputElement); | |
348 | } | |
349 | treeViewer.refresh(); | |
350 | treeViewer.setSelection(new StructuredSelection(inputElement), true); | |
351 | } | |
352 | }); | |
353 | ||
354 | addNextButton = new Button(buttonBar, SWT.PUSH); | |
355 | addNextButton.setImage(addNextImage); | |
356 | addNextButton.setToolTipText(Messages.CustomXmlParserInputWizardPage_addNextElement); | |
357 | addNextButton.addSelectionListener(new SelectionAdapter() { | |
358 | @Override | |
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()) { | |
365 | return; | |
366 | } else { | |
367 | InputElement previousInputElement = (InputElement) ((IStructuredSelection) treeViewer.getSelection()).getFirstElement(); | |
368 | if (previousInputElement == definition.rootInputElement) { | |
369 | return; | |
370 | } | |
371 | previousInputElement.addNext(inputElement); | |
372 | inputElement.elementName = getChildNameSuggestion(inputElement.parentElement); | |
373 | } | |
374 | treeViewer.refresh(); | |
375 | treeViewer.setSelection(new StructuredSelection(inputElement), true); | |
376 | } | |
377 | }); | |
378 | ||
379 | feelingLuckyButton = new Button(buttonBar, SWT.PUSH); | |
380 | feelingLuckyButton.setImage(addManyImage); | |
381 | feelingLuckyButton.setToolTipText(Messages.CustomXmlParserInputWizardPage_feelingLucky); | |
382 | feelingLuckyButton.addSelectionListener(new SelectionAdapter() { | |
383 | @Override | |
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); | |
391 | } else { | |
392 | return; | |
393 | } | |
394 | } else if (treeViewer.getSelection().isEmpty()) { | |
395 | return; | |
396 | } else { | |
397 | inputElement = (InputElement) ((IStructuredSelection) treeViewer.getSelection()).getFirstElement(); | |
398 | feelingLucky(inputElement); | |
399 | } | |
400 | treeViewer.refresh(); | |
401 | treeViewer.setSelection(new StructuredSelection(inputElement), true); | |
402 | treeViewer.expandToLevel(inputElement, AbstractTreeViewer.ALL_LEVELS); | |
403 | } | |
404 | }); | |
405 | ||
406 | moveUpButton = new Button(buttonBar, SWT.PUSH); | |
407 | moveUpButton.setImage(moveUpImage); | |
408 | moveUpButton.setToolTipText(Messages.CustomXmlParserInputWizardPage_moveUp); | |
409 | moveUpButton.addSelectionListener(new SelectionAdapter() { | |
410 | @Override | |
411 | public void widgetSelected(SelectionEvent e) { | |
412 | if (treeViewer.getSelection().isEmpty()) { | |
413 | return; | |
414 | } | |
415 | InputElement inputElement = (InputElement) ((IStructuredSelection) treeViewer.getSelection()).getFirstElement(); | |
416 | if (inputElement == definition.rootInputElement) { | |
417 | return; | |
418 | } | |
419 | inputElement.moveUp(); | |
420 | treeViewer.refresh(); | |
421 | validate(); | |
422 | updatePreviews(); | |
423 | } | |
424 | }); | |
425 | ||
426 | moveDownButton = new Button(buttonBar, SWT.PUSH); | |
427 | moveDownButton.setImage(moveDownImage); | |
428 | moveDownButton.setToolTipText(Messages.CustomXmlParserInputWizardPage_moveDown); | |
429 | moveDownButton.addSelectionListener(new SelectionAdapter() { | |
430 | @Override | |
431 | public void widgetSelected(SelectionEvent e) { | |
432 | if (treeViewer.getSelection().isEmpty()) { | |
433 | return; | |
434 | } | |
435 | InputElement inputElement = (InputElement) ((IStructuredSelection) treeViewer.getSelection()).getFirstElement(); | |
436 | if (inputElement == definition.rootInputElement) { | |
437 | return; | |
438 | } | |
439 | inputElement.moveDown(); | |
440 | treeViewer.refresh(); | |
441 | validate(); | |
442 | updatePreviews(); | |
443 | } | |
444 | }); | |
445 | } | |
446 | ||
447 | private void feelingLucky(InputElement inputElement) { | |
448 | while (true) { | |
449 | String attributeName = getAttributeNameSuggestion(inputElement); | |
450 | if (attributeName.length() == 0) { | |
451 | break; | |
452 | } | |
453 | InputAttribute attribute = new InputAttribute(attributeName, attributeName, 0, ""); //$NON-NLS-1$ | |
454 | inputElement.addAttribute(attribute); | |
455 | } | |
456 | while (true) { | |
457 | String childName = getChildNameSuggestion(inputElement); | |
458 | if (childName.length() == 0) { | |
459 | break; | |
460 | } | |
461 | InputElement childElement = new InputElement(childName, false, CustomXmlTraceDefinition.TAG_IGNORE, 0, "", null); //$NON-NLS-1$ | |
462 | inputElement.addChild(childElement); | |
463 | feelingLucky(childElement); | |
464 | } | |
465 | } | |
466 | ||
467 | private static class InputElementTreeNodeContentProvider implements ITreeContentProvider { | |
468 | ||
469 | @Override | |
470 | public Object[] getElements(Object inputElement) { | |
471 | CustomXmlTraceDefinition def = (CustomXmlTraceDefinition) inputElement; | |
472 | if (def.rootInputElement != null) { | |
473 | return new Object[] { def.rootInputElement }; | |
474 | } | |
475 | return new Object[0]; | |
476 | } | |
477 | ||
478 | @Override | |
479 | public Object[] getChildren(Object parentElement) { | |
480 | InputElement inputElement = (InputElement) parentElement; | |
481 | if (inputElement.childElements == null) { | |
482 | return new InputElement[0]; | |
483 | } | |
484 | return inputElement.childElements.toArray(); | |
485 | } | |
486 | ||
487 | @Override | |
488 | public boolean hasChildren(Object element) { | |
489 | InputElement inputElement = (InputElement) element; | |
490 | return (inputElement.childElements != null && inputElement.childElements.size() > 0); | |
491 | } | |
492 | ||
493 | @Override | |
494 | public void dispose() { | |
495 | } | |
496 | ||
497 | @Override | |
498 | public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { | |
499 | } | |
500 | ||
501 | @Override | |
502 | public Object getParent(Object element) { | |
503 | InputElement inputElement = (InputElement) element; | |
504 | return inputElement.parentElement; | |
505 | } | |
506 | } | |
507 | ||
508 | private static class InputElementTreeLabelProvider extends ColumnLabelProvider { | |
509 | ||
510 | @Override | |
511 | public Image getImage(Object element) { | |
512 | return elementImage; | |
513 | } | |
514 | ||
515 | @Override | |
516 | public String getText(Object element) { | |
517 | InputElement inputElement = (InputElement) element; | |
518 | return (inputElement.elementName.trim().length() == 0) ? "?" : inputElement.elementName; //$NON-NLS-1$ | |
519 | } | |
520 | } | |
521 | ||
522 | private class InputElementTreeSelectionChangedListener implements ISelectionChangedListener { | |
523 | @Override | |
524 | public void selectionChanged(SelectionChangedEvent event) { | |
525 | if (selectedElement != null) { | |
526 | selectedElement.dispose(); | |
527 | } | |
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); | |
535 | container.layout(); | |
536 | validate(); | |
537 | updatePreviews(); | |
538 | removeButton.setEnabled(true); | |
539 | addChildButton.setEnabled(true); | |
540 | addChildButton.setToolTipText(Messages.CustomXmlParserInputWizardPage_addChildElement); | |
541 | if (definition.rootInputElement == inputElement) { | |
542 | addNextButton.setEnabled(false); | |
543 | } else { | |
544 | addNextButton.setEnabled(true); | |
545 | } | |
546 | moveUpButton.setEnabled(true); | |
547 | moveDownButton.setEnabled(true); | |
548 | } else { | |
549 | removeButton.setEnabled(false); | |
550 | if (definition.rootInputElement == null) { | |
551 | addChildButton.setEnabled(true); | |
552 | addChildButton.setToolTipText(Messages.CustomXmlParserInputWizardPage_addDocumentElement); | |
553 | } else { | |
554 | addChildButton.setEnabled(false); | |
555 | } | |
556 | addNextButton.setEnabled(false); | |
557 | moveUpButton.setEnabled(false); | |
558 | moveDownButton.setEnabled(false); | |
559 | } | |
560 | } | |
561 | } | |
562 | ||
563 | /* | |
564 | * (non-Javadoc) | |
565 | * | |
566 | * @see org.eclipse.jface.dialogs.DialogPage#dispose() | |
567 | */ | |
568 | @Override | |
569 | public void dispose() { | |
570 | if (fixedFont != null) { | |
571 | fixedFont.dispose(); | |
572 | fixedFont = null; | |
573 | } | |
574 | super.dispose(); | |
575 | } | |
576 | ||
577 | private void loadDefinition(CustomXmlTraceDefinition def) { | |
578 | logtypeText.setText(def.definitionName); | |
579 | timeStampOutputFormatText.setText(def.timeStampOutputFormat); | |
580 | treeViewer.setInput(def); | |
581 | ||
582 | if (def.rootInputElement != null) { | |
583 | treeViewer.setSelection(new StructuredSelection(def.rootInputElement)); | |
584 | } | |
585 | } | |
586 | ||
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) { | |
590 | return name; | |
591 | } | |
592 | return getName(inputElement.parentElement) + " : " + name; //$NON-NLS-1$ | |
593 | } | |
594 | ||
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$ | |
598 | } | |
599 | ||
600 | /* | |
601 | * (non-Javadoc) | |
602 | * | |
603 | * @see org.eclipse.jface.dialogs.DialogPage#setVisible(boolean) | |
604 | */ | |
605 | @Override | |
606 | public void setVisible(boolean visible) { | |
607 | if (visible) { | |
608 | validate(); | |
609 | updatePreviews(); | |
610 | } | |
611 | super.setVisible(visible); | |
612 | } | |
613 | ||
614 | public List<String> getInputNames() { | |
615 | return getInputNames(definition.rootInputElement); | |
616 | } | |
617 | ||
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); | |
624 | } | |
625 | } | |
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); | |
631 | } | |
632 | } | |
633 | } | |
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); | |
639 | } | |
640 | } | |
641 | } | |
642 | } | |
643 | return inputs; | |
644 | } | |
645 | ||
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); | |
652 | container.layout(); | |
653 | } | |
654 | ||
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; | |
661 | try { | |
662 | inputStream = file.getContents(); | |
663 | } catch (CoreException e) { | |
664 | return ""; //$NON-NLS-1$ | |
665 | } | |
666 | } | |
667 | } | |
668 | if (inputStream != null) { | |
669 | BufferedReader reader = null; | |
670 | try { | |
671 | reader = new BufferedReader(new InputStreamReader(inputStream)); | |
672 | StringBuilder sb = new StringBuilder(); | |
673 | String line = null; | |
674 | while ((line = reader.readLine()) != null) { | |
675 | sb.append(line + "\n"); //$NON-NLS-1$ | |
676 | } | |
677 | parseXmlInput(sb.toString()); | |
678 | reader.close(); | |
679 | return sb.toString(); | |
680 | } catch (IOException e) { | |
681 | return ""; //$NON-NLS-1$ | |
682 | } | |
683 | } | |
684 | return ""; //$NON-NLS-1$ | |
685 | } | |
686 | ||
687 | private void parseXmlInput(final String string) { | |
688 | try { | |
689 | DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); | |
690 | DocumentBuilder db = dbf.newDocumentBuilder(); | |
691 | ||
692 | // The following allows xml parsing without access to the dtd | |
693 | EntityResolver resolver = new EntityResolver() { | |
694 | @Override | |
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); | |
699 | } | |
700 | }; | |
701 | db.setEntityResolver(resolver); | |
702 | ||
703 | // The following catches xml parsing exceptions | |
704 | db.setErrorHandler(new ErrorHandler() { | |
705 | @Override | |
706 | public void error(SAXParseException saxparseexception) throws SAXException { | |
707 | } | |
708 | ||
709 | @Override | |
710 | public void warning(SAXParseException saxparseexception) throws SAXException { | |
711 | } | |
712 | ||
713 | @Override | |
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); | |
719 | } | |
720 | throw saxparseexception; | |
721 | } | |
722 | }); | |
723 | ||
724 | errorText.setVisible(false); | |
725 | Document doc = null; | |
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; | |
736 | } | |
737 | } | |
738 | ||
739 | private void updatePreviews() { | |
740 | updatePreviews(false); | |
741 | } | |
742 | ||
743 | private void initValues() { | |
744 | timeStampValue = null; | |
745 | timeStampFormat = null; | |
746 | logEntriesCount = 0; | |
747 | logEntryFound = false; | |
748 | } | |
749 | ||
750 | private void updatePreviews(boolean updateAll) { | |
751 | if (inputText == null) { | |
752 | // early update during construction | |
753 | return; | |
754 | } | |
755 | inputText.setStyleRanges(new StyleRange[] {}); | |
756 | if (selectedElement == null) { | |
757 | return; | |
758 | } | |
759 | ||
760 | initValues(); | |
761 | ||
762 | selectedElement.updatePreview(); | |
763 | ||
764 | if (timeStampValue != null && timeStampFormat != null) { | |
765 | try { | |
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$ | |
774 | } | |
775 | } else { | |
776 | timeStampPreviewText.setText("*no matching time stamp*"); //$NON-NLS-1$ | |
777 | } | |
778 | } | |
779 | ||
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); | |
785 | } | |
786 | return; | |
787 | } | |
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() { | |
792 | @Override | |
793 | public void changed(TitleEvent event) { | |
794 | helpShell.setText(event.title); | |
795 | } | |
796 | }); | |
797 | helpBrowser.setBounds(0, 0, 600, 400); | |
798 | helpShell.pack(); | |
799 | helpShell.open(); | |
800 | helpBrowser.setUrl(url); | |
801 | } | |
802 | ||
803 | private class UpdateListener implements ModifyListener, SelectionListener { | |
804 | ||
805 | @Override | |
806 | public void modifyText(ModifyEvent e) { | |
807 | validate(); | |
808 | updatePreviews(); | |
809 | } | |
810 | ||
811 | @Override | |
812 | public void widgetDefaultSelected(SelectionEvent e) { | |
813 | validate(); | |
814 | updatePreviews(); | |
815 | } | |
816 | ||
817 | @Override | |
818 | public void widgetSelected(SelectionEvent e) { | |
819 | validate(); | |
820 | updatePreviews(); | |
821 | } | |
822 | ||
823 | } | |
824 | ||
825 | private class ElementNode { | |
826 | final InputElement inputElement; | |
827 | final Group group; | |
828 | List<Attribute> attributes = new ArrayList<Attribute>(); | |
829 | List<ElementNode> childElements = new ArrayList<ElementNode>(); | |
830 | Text elementNameText; | |
831 | Composite tagComposite; | |
832 | Combo tagCombo; | |
833 | Label tagLabel; | |
834 | Text tagText; | |
835 | Combo actionCombo; | |
836 | Label previewLabel; | |
837 | Text previewText; | |
838 | Button logEntryButton; | |
839 | Label fillerLabel; | |
840 | Composite addAttributeComposite; | |
841 | Button addAttributeButton; | |
842 | Label addAttributeLabel; | |
843 | ||
844 | public ElementNode(Composite parent, InputElement inputElement) { | |
845 | this.inputElement = inputElement; | |
846 | ||
847 | group = new Group(parent, SWT.NONE); | |
848 | GridLayout gl = new GridLayout(2, false); | |
849 | gl.marginHeight = 0; | |
850 | group.setLayout(gl); | |
851 | group.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); | |
852 | group.setText(getName(inputElement)); | |
853 | ||
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)); | |
857 | ||
858 | elementNameText = new Text(group, SWT.BORDER | SWT.SINGLE); | |
859 | GridData gd = new GridData(SWT.FILL, SWT.CENTER, true, false); | |
860 | gd.widthHint = 0; | |
861 | elementNameText.setLayoutData(gd); | |
862 | elementNameText.addModifyListener(new ModifyListener() { | |
863 | @Override | |
864 | public void modifyText(ModifyEvent e) { | |
865 | ElementNode.this.inputElement.elementName = elementNameText.getText().trim(); | |
866 | group.setText(getName(ElementNode.this.inputElement)); | |
867 | } | |
868 | }); | |
869 | elementNameText.setText(inputElement.elementName); | |
870 | elementNameText.addModifyListener(updateListener); | |
871 | ||
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); | |
876 | ||
877 | previewText = new Text(group, SWT.BORDER | SWT.SINGLE | SWT.READ_ONLY); | |
878 | gd = new GridData(SWT.FILL, SWT.CENTER, true, false); | |
879 | gd.widthHint = 0; | |
880 | previewText.setLayoutData(gd); | |
881 | previewText.setText(Messages.CustomXmlParserInputWizardPage_noMatchingElement); | |
882 | previewText.setBackground(COLOR_WIDGET_BACKGROUND); | |
883 | ||
884 | logEntryButton = new Button(group, SWT.CHECK); | |
885 | logEntryButton.setText(Messages.CustomXmlParserInputWizardPage_logEntry); | |
886 | logEntryButton.setSelection(inputElement.logEntry); | |
887 | logEntryButton.addSelectionListener(new SelectionListener() { | |
888 | @Override | |
889 | public void widgetDefaultSelected(SelectionEvent e) { | |
890 | } | |
891 | ||
892 | @Override | |
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; | |
898 | } | |
899 | } | |
900 | }); | |
901 | logEntryButton.addSelectionListener(updateListener); | |
902 | ||
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)); | |
909 | ||
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() { | |
915 | @Override | |
916 | public void widgetDefaultSelected(SelectionEvent e) { | |
917 | } | |
918 | ||
919 | @Override | |
920 | public void widgetSelected(SelectionEvent e) { | |
921 | tagText.removeModifyListener(updateListener); | |
922 | switch (tagCombo.getSelectionIndex()) { | |
923 | case 0: // Ignore | |
924 | tagLabel.setVisible(false); | |
925 | tagText.setVisible(false); | |
926 | actionCombo.setVisible(false); | |
927 | break; | |
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); | |
934 | break; | |
935 | case 2: // Message | |
936 | tagLabel.setVisible(false); | |
937 | tagText.setVisible(false); | |
938 | actionCombo.setVisible(true); | |
939 | break; | |
940 | case 3: // Other | |
941 | tagLabel.setText(Messages.CustomXmlParserInputWizardPage_tagName); | |
942 | tagLabel.setVisible(true); | |
943 | if (tagText.getText().trim().length() == 0) { | |
944 | tagText.setText(elementNameText.getText().trim()); | |
945 | } | |
946 | tagText.setVisible(true); | |
947 | tagText.addModifyListener(updateListener); | |
948 | actionCombo.setVisible(true); | |
949 | break; | |
950 | default: | |
951 | break; | |
952 | } | |
953 | tagComposite.layout(); | |
954 | validate(); | |
955 | updatePreviews(); | |
956 | } | |
957 | }); | |
958 | ||
959 | tagLabel = new Label(tagComposite, SWT.NULL); | |
960 | tagLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false)); | |
961 | ||
962 | tagText = new Text(tagComposite, SWT.BORDER | SWT.SINGLE); | |
963 | gd = new GridData(SWT.FILL, SWT.CENTER, true, false); | |
964 | gd.widthHint = 0; | |
965 | tagText.setLayoutData(gd); | |
966 | ||
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); | |
972 | ||
973 | if (inputElement.inputName.equals(CustomXmlTraceDefinition.TAG_IGNORE)) { | |
974 | tagCombo.select(0); | |
975 | tagLabel.setVisible(false); | |
976 | tagText.setVisible(false); | |
977 | actionCombo.setVisible(false); | |
978 | } else if (inputElement.inputName.equals(CustomTraceDefinition.TAG_TIMESTAMP)) { | |
979 | tagCombo.select(1); | |
980 | tagLabel.setText(Messages.CustomXmlParserInputWizardPage_format); | |
981 | tagText.setText(inputElement.inputFormat); | |
982 | tagText.addModifyListener(updateListener); | |
983 | } else if (inputElement.inputName.equals(CustomTraceDefinition.TAG_MESSAGE)) { | |
984 | tagCombo.select(2); | |
985 | tagLabel.setVisible(false); | |
986 | tagText.setVisible(false); | |
987 | } else { | |
988 | tagCombo.select(3); | |
989 | tagLabel.setText(Messages.CustomXmlParserInputWizardPage_tagName); | |
990 | tagText.setText(inputElement.inputName); | |
991 | tagText.addModifyListener(updateListener); | |
992 | } | |
993 | } | |
994 | ||
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); | |
999 | } | |
1000 | } | |
1001 | ||
1002 | createAddButton(); | |
1003 | } | |
1004 | ||
1005 | private void updatePreview() { | |
1006 | Element element = getPreviewElement(inputElement); | |
1007 | if (inputElement.parentElement != null) { // no preview text for | |
1008 | // document element | |
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; | |
1015 | logEntriesCount++; | |
1016 | } else { | |
1017 | logEntryButton.setSelection(false); // remove nested | |
1018 | // log entry | |
1019 | } | |
1020 | } | |
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(); | |
1031 | } else { | |
1032 | timeStampValue = value; | |
1033 | timeStampFormat = tagText.getText().trim(); | |
1034 | } | |
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$ | |
1039 | } else { | |
1040 | timeStampValue = value; | |
1041 | timeStampFormat = tagText.getText().trim(); | |
1042 | } | |
1043 | } | |
1044 | } | |
1045 | } | |
1046 | } | |
1047 | } | |
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(); | |
1061 | } else { | |
1062 | timeStampValue = value; | |
1063 | timeStampFormat = attribute.tagText.getText().trim(); | |
1064 | } | |
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$ | |
1069 | } else { | |
1070 | timeStampValue = value; | |
1071 | timeStampFormat = attribute.tagText.getText().trim(); | |
1072 | } | |
1073 | } | |
1074 | } | |
1075 | } else { | |
1076 | attribute.previewText.setText(Messages.CustomXmlParserInputWizardPage_noMatchingAttribute); | |
1077 | } | |
1078 | } else { | |
1079 | attribute.previewText.setText(Messages.CustomXmlParserInputWizardPage_noMatchingElement); | |
1080 | } | |
1081 | } | |
1082 | for (ElementNode child : childElements) { | |
1083 | child.updatePreview(); | |
1084 | } | |
1085 | if (logEntryButton != null && logEntryButton.getSelection()) { | |
1086 | logEntryFound = false; | |
1087 | } | |
1088 | } | |
1089 | ||
1090 | private void createAddButton() { | |
1091 | fillerLabel = new Label(group, SWT.NONE); | |
1092 | ||
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); | |
1099 | ||
1100 | addAttributeButton = new Button(addAttributeComposite, SWT.PUSH); | |
1101 | addAttributeButton.setImage(addImage); | |
1102 | addAttributeButton.setToolTipText(Messages.CustomXmlParserInputWizardPage_addAttribute); | |
1103 | addAttributeButton.addSelectionListener(new SelectionAdapter() { | |
1104 | @Override | |
1105 | public void widgetSelected(SelectionEvent e) { | |
1106 | removeAddButton(); | |
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)); | |
1110 | createAddButton(); | |
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(); | |
1115 | validate(); | |
1116 | updatePreviews(); | |
1117 | } | |
1118 | }); | |
1119 | ||
1120 | addAttributeLabel = new Label(addAttributeComposite, SWT.NULL); | |
1121 | addAttributeLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); | |
1122 | addAttributeLabel.setText(Messages.CustomXmlParserInputWizardPage_newAttibute); | |
1123 | } | |
1124 | ||
1125 | private void removeAddButton() { | |
1126 | fillerLabel.dispose(); | |
1127 | addAttributeComposite.dispose(); | |
1128 | } | |
1129 | ||
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); | |
1135 | } | |
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(); | |
1140 | } | |
1141 | } | |
1142 | ||
1143 | private void dispose() { | |
1144 | group.dispose(); | |
1145 | } | |
1146 | ||
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(); | |
1153 | } else { | |
1154 | inputElement.inputName = tagCombo.getText(); | |
1155 | if (tagCombo.getText().equals(CustomTraceDefinition.TAG_TIMESTAMP)) { | |
1156 | inputElement.inputFormat = tagText.getText().trim(); | |
1157 | } | |
1158 | } | |
1159 | inputElement.inputAction = actionCombo.getSelectionIndex(); | |
1160 | } | |
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(); | |
1168 | } else { | |
1169 | inputAttribute.inputName = attribute.tagCombo.getText(); | |
1170 | if (attribute.tagCombo.getText().equals(CustomTraceDefinition.TAG_TIMESTAMP)) { | |
1171 | inputAttribute.inputFormat = attribute.tagText.getText().trim(); | |
1172 | } | |
1173 | } | |
1174 | inputAttribute.inputAction = attribute.actionCombo.getSelectionIndex(); | |
1175 | inputElement.addAttribute(inputAttribute); | |
1176 | } | |
1177 | } | |
1178 | } | |
1179 | ||
1180 | private class Attribute { | |
1181 | ElementNode element; | |
1182 | int attributeNumber; | |
1183 | ||
1184 | // children of parent (must be disposed) | |
1185 | Composite labelComposite; | |
1186 | Composite attributeComposite; | |
1187 | Label filler; | |
1188 | Composite tagComposite; | |
1189 | ||
1190 | // children of labelComposite | |
1191 | Label attributeLabel; | |
1192 | ||
1193 | // children of attributeComposite | |
1194 | Text attributeNameText; | |
1195 | Text previewText; | |
1196 | ||
1197 | // children of tagComposite | |
1198 | Combo tagCombo; | |
1199 | Label tagLabel; | |
1200 | Text tagText; | |
1201 | Combo actionCombo; | |
1202 | ||
1203 | public Attribute(Composite parent, ElementNode element, InputAttribute inputAttribute, int attributeNumber) { | |
1204 | this.element = element; | |
1205 | this.attributeNumber = attributeNumber; | |
1206 | ||
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)); | |
1213 | ||
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() { | |
1219 | @Override | |
1220 | public void widgetSelected(SelectionEvent e) { | |
1221 | Attribute.this.element.removeAttribute(Attribute.this.attributeNumber); | |
1222 | validate(); | |
1223 | updatePreviews(); | |
1224 | } | |
1225 | }); | |
1226 | ||
1227 | attributeLabel = new Label(labelComposite, SWT.NULL); | |
1228 | attributeLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false)); | |
1229 | attributeLabel.setText(Messages.CustomXmlParserInputWizardPage_attibute); | |
1230 | ||
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)); | |
1237 | ||
1238 | Label nameLabel = new Label(attributeComposite, SWT.NONE); | |
1239 | nameLabel.setText(Messages.CustomXmlParserInputWizardPage_name); | |
1240 | ||
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); | |
1245 | ||
1246 | Label previewLabel = new Label(attributeComposite, SWT.NONE); | |
1247 | previewLabel.setText(Messages.CustomXmlParserInputWizardPage_preview); | |
1248 | ||
1249 | previewText = new Text(attributeComposite, SWT.BORDER | SWT.SINGLE | SWT.READ_ONLY); | |
1250 | GridData gd = new GridData(SWT.FILL, SWT.CENTER, true, false); | |
1251 | gd.widthHint = 0; | |
1252 | previewText.setLayoutData(gd); | |
1253 | previewText.setText(Messages.CustomXmlParserInputWizardPage_noMatch); | |
1254 | previewText.setBackground(COLOR_WIDGET_BACKGROUND); | |
1255 | ||
1256 | filler = new Label(parent, SWT.NULL); | |
1257 | ||
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)); | |
1264 | ||
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() { | |
1270 | @Override | |
1271 | public void widgetDefaultSelected(SelectionEvent e) { | |
1272 | } | |
1273 | ||
1274 | @Override | |
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); | |
1283 | break; | |
1284 | case 1: // Message | |
1285 | tagLabel.setVisible(false); | |
1286 | tagText.setVisible(false); | |
1287 | break; | |
1288 | case 2: // Other | |
1289 | tagLabel.setText(Messages.CustomXmlParserInputWizardPage_tagName); | |
1290 | tagLabel.setVisible(true); | |
1291 | if (tagText.getText().trim().length() == 0) { | |
1292 | tagText.setText(attributeNameText.getText().trim()); | |
1293 | } | |
1294 | tagText.setVisible(true); | |
1295 | tagText.addModifyListener(updateListener); | |
1296 | break; | |
1297 | default: | |
1298 | break; | |
1299 | } | |
1300 | tagComposite.layout(); | |
1301 | validate(); | |
1302 | updatePreviews(); | |
1303 | } | |
1304 | }); | |
1305 | ||
1306 | tagLabel = new Label(tagComposite, SWT.NULL); | |
1307 | tagLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false)); | |
1308 | ||
1309 | tagText = new Text(tagComposite, SWT.BORDER | SWT.SINGLE); | |
1310 | gd = new GridData(SWT.FILL, SWT.CENTER, true, false); | |
1311 | gd.widthHint = 0; | |
1312 | tagText.setLayoutData(gd); | |
1313 | tagText.setText(attributeNameText.getText()); | |
1314 | ||
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); | |
1320 | ||
1321 | if (inputAttribute.inputName.equals(CustomTraceDefinition.TAG_TIMESTAMP)) { | |
1322 | tagCombo.select(0); | |
1323 | tagLabel.setText(Messages.CustomXmlParserInputWizardPage_format); | |
1324 | tagText.setText(inputAttribute.inputFormat); | |
1325 | tagText.addModifyListener(updateListener); | |
1326 | } else if (inputAttribute.inputName.equals(CustomTraceDefinition.TAG_MESSAGE)) { | |
1327 | tagCombo.select(1); | |
1328 | tagLabel.setVisible(false); | |
1329 | tagText.setVisible(false); | |
1330 | } else { | |
1331 | tagCombo.select(2); | |
1332 | tagLabel.setText(Messages.CustomXmlParserInputWizardPage_tagName); | |
1333 | tagText.setText(inputAttribute.inputName); | |
1334 | tagText.addModifyListener(updateListener); | |
1335 | } | |
1336 | } | |
1337 | ||
1338 | private void dispose() { | |
1339 | labelComposite.dispose(); | |
1340 | attributeComposite.dispose(); | |
1341 | filler.dispose(); | |
1342 | tagComposite.dispose(); | |
1343 | } | |
1344 | ||
1345 | private void setAttributeNumber(int attributeNumber) { | |
1346 | this.attributeNumber = attributeNumber; | |
1347 | labelComposite.layout(); | |
1348 | } | |
1349 | } | |
1350 | ||
1351 | private Element getPreviewElement(InputElement inputElement) { | |
1352 | Element element = documentElement; | |
1353 | if (element != null) { | |
1354 | if (!documentElement.getNodeName().equals(definition.rootInputElement.elementName)) { | |
1355 | return null; | |
1356 | } | |
1357 | ArrayList<String> elementNames = new ArrayList<String>(); | |
1358 | while (inputElement != null) { | |
1359 | elementNames.add(inputElement.elementName); | |
1360 | inputElement = inputElement.parentElement; | |
1361 | } | |
1362 | for (int i = elementNames.size() - 1; --i >= 0;) { | |
1363 | NodeList childList = element.getChildNodes(); | |
1364 | element = null; | |
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; | |
1369 | break; | |
1370 | } | |
1371 | } | |
1372 | if (element == null) { | |
1373 | break; | |
1374 | } | |
1375 | } | |
1376 | if (element != null) { | |
1377 | return element; | |
1378 | } | |
1379 | } | |
1380 | return null; | |
1381 | } | |
1382 | ||
1383 | private String getChildNameSuggestion(InputElement inputElement) { | |
1384 | if (inputElement == null) { | |
1385 | if (documentElement != null) { | |
1386 | return documentElement.getNodeName(); | |
1387 | } | |
1388 | } else { | |
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())) { | |
1399 | unused = false; | |
1400 | break; | |
1401 | } | |
1402 | } | |
1403 | } | |
1404 | if (unused) { | |
1405 | return node.getNodeName(); | |
1406 | } | |
1407 | } | |
1408 | } | |
1409 | } | |
1410 | } | |
1411 | return ""; //$NON-NLS-1$ | |
1412 | } | |
1413 | ||
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())) { | |
1424 | unused = false; | |
1425 | break; | |
1426 | } | |
1427 | } | |
1428 | } | |
1429 | if (unused) { | |
1430 | return node.getNodeName(); | |
1431 | } | |
1432 | } | |
1433 | } | |
1434 | return ""; //$NON-NLS-1$ | |
1435 | } | |
1436 | ||
1437 | private void validate() { | |
1438 | definition.definitionName = logtypeText.getText().trim(); | |
1439 | definition.timeStampOutputFormat = timeStampOutputFormatText.getText().trim(); | |
1440 | ||
1441 | if (selectedElement != null) { | |
1442 | selectedElement.extractInputs(); | |
1443 | treeViewer.refresh(); | |
1444 | } | |
1445 | ||
1446 | StringBuffer errors = new StringBuffer(); | |
1447 | ||
1448 | if (definition.definitionName.length() == 0) { | |
1449 | errors.append(Messages.CustomXmlParserInputWizardPage_emptyLogTypeError); | |
1450 | logtypeText.setBackground(COLOR_LIGHT_RED); | |
1451 | } else { | |
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); | |
1458 | break; | |
1459 | } | |
1460 | } | |
1461 | } | |
1462 | } | |
1463 | ||
1464 | if (definition.rootInputElement == null) { | |
1465 | errors.append(Messages.CustomXmlParserInputWizardPage_noDocumentError); | |
1466 | } | |
1467 | ||
1468 | if (definition.rootInputElement != null) { | |
1469 | logEntryFound = false; | |
1470 | timeStampFound = false; | |
1471 | ||
1472 | errors.append(validateElement(definition.rootInputElement)); | |
1473 | ||
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); | |
1479 | } | |
1480 | ||
1481 | if (timeStampFound) { | |
1482 | if (timeStampOutputFormatText.getText().trim().length() == 0) { | |
1483 | errors.append(Messages.CustomXmlParserInputWizardPage_missingTimestampFmtError); | |
1484 | timeStampOutputFormatText.setBackground(COLOR_LIGHT_RED); | |
1485 | } else { | |
1486 | try { | |
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); | |
1492 | } | |
1493 | } | |
1494 | } else { | |
1495 | timeStampPreviewText.setText(Messages.CustomXmlParserInputWizardPage_notimestamporAttributeError); | |
1496 | } | |
1497 | } | |
1498 | } else { | |
1499 | timeStampPreviewText.setText(Messages.CustomXmlParserInputWizardPage_notimestamporAttributeError); | |
1500 | } | |
1501 | ||
1502 | if (errors.length() == 0) { | |
1503 | setDescription(defaultDescription); | |
1504 | setPageComplete(true); | |
1505 | } else { | |
1506 | setDescription(errors.toString()); | |
1507 | setPageComplete(false); | |
1508 | } | |
1509 | } | |
1510 | ||
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; | |
1516 | } | |
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); | |
1522 | } | |
1523 | } else { | |
1524 | if (elementNode != null) { | |
1525 | elementNode.elementNameText.setBackground(COLOR_TEXT_BACKGROUND); | |
1526 | } | |
1527 | } | |
1528 | } | |
1529 | if (inputElement != definition.rootInputElement) { | |
1530 | if (inputElement.logEntry) { | |
1531 | logEntryFound = true; | |
1532 | } | |
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); | |
1540 | } | |
1541 | } else { | |
1542 | try { | |
1543 | new SimpleDateFormat(inputElement.inputFormat); | |
1544 | if (elementNode != null) { | |
1545 | elementNode.tagText.setBackground(COLOR_TEXT_BACKGROUND); | |
1546 | } | |
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); | |
1552 | } | |
1553 | } | |
1554 | } | |
1555 | } else if (inputElement.inputName.length() == 0) { | |
1556 | errors.append(Messages.CustomXmlParserInputWizardPage_missingInputElementNameError); | |
1557 | if (elementNode != null) { | |
1558 | elementNode.tagText.setBackground(COLOR_LIGHT_RED); | |
1559 | } | |
1560 | } else { | |
1561 | if (elementNode != null) { | |
1562 | elementNode.tagText.setBackground(COLOR_TEXT_BACKGROUND); | |
1563 | } | |
1564 | } | |
1565 | } | |
1566 | if (inputElement.attributes != null) { | |
1567 | if (elementNode != null) { | |
1568 | for (Attribute attribute : elementNode.attributes) { | |
1569 | attribute.attributeNameText.setBackground(COLOR_TEXT_BACKGROUND); | |
1570 | } | |
1571 | } | |
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)) { | |
1578 | duplicate = true; | |
1579 | if (elementNode != null) { | |
1580 | elementNode.attributes.get(j).attributeNameText.setBackground(COLOR_LIGHT_RED); | |
1581 | } | |
1582 | } | |
1583 | } | |
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); | |
1589 | } | |
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); | |
1595 | } | |
1596 | } | |
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); | |
1604 | } | |
1605 | } else { | |
1606 | try { | |
1607 | new SimpleDateFormat(attribute.inputFormat); | |
1608 | if (elementNode != null) { | |
1609 | elementNode.attributes.get(i).tagText.setBackground(COLOR_TEXT_BACKGROUND); | |
1610 | } | |
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); | |
1616 | } | |
1617 | } | |
1618 | } | |
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); | |
1624 | } | |
1625 | } else { | |
1626 | if (elementNode != null) { | |
1627 | elementNode.attributes.get(i).tagText.setBackground(COLOR_TEXT_BACKGROUND); | |
1628 | } | |
1629 | } | |
1630 | } | |
1631 | } | |
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; | |
1637 | } | |
1638 | if (childElementNode != null) { | |
1639 | childElementNode.elementNameText.setBackground(COLOR_TEXT_BACKGROUND); | |
1640 | } | |
1641 | } | |
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; | |
1647 | } | |
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); | |
1653 | } | |
1654 | } else { | |
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)) { | |
1659 | duplicate = true; | |
1660 | ElementNode otherChildElementNode = null; | |
1661 | if (selectedElement != null && selectedElement.inputElement.equals(otherChild)) { | |
1662 | otherChildElementNode = selectedElement; | |
1663 | } | |
1664 | if (otherChildElementNode != null) { | |
1665 | otherChildElementNode.elementNameText.setBackground(COLOR_LIGHT_RED); | |
1666 | } | |
1667 | } | |
1668 | } | |
1669 | if (duplicate) { | |
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); | |
1674 | } | |
1675 | } | |
1676 | } | |
1677 | ||
1678 | errors.append(validateElement(child)); | |
1679 | } | |
1680 | } | |
1681 | return errors; | |
1682 | } | |
1683 | ||
1684 | public CustomXmlTraceDefinition getDefinition() { | |
1685 | return definition; | |
1686 | } | |
1687 | ||
1688 | public char[] getInputText() { | |
1689 | return inputText.getText().toCharArray(); | |
1690 | } | |
1691 | } |