lttng/tmf: Enable and fix parameter assignment warnings
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / internal / tmf / ui / parsers / wizards / CustomXmlParserInputWizardPage.java
CommitLineData
a0a88f65
AM
1/*******************************************************************************
2 * Copyright (c) 2013 Ericsson
3 *
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
8 *
9 * Contributors:
10 * Patrick Tassé - Initial API and implementation
11 *******************************************************************************/
12
be222f56
PT
13package org.eclipse.linuxtools.internal.tmf.ui.parsers.wizards;
14
15import java.io.BufferedReader;
16import java.io.ByteArrayInputStream;
17import java.io.IOException;
18import java.io.InputStream;
19import java.io.InputStreamReader;
20import java.text.ParseException;
21import java.text.SimpleDateFormat;
22import java.util.ArrayList;
23import java.util.Date;
24import java.util.List;
25
26import javax.xml.parsers.DocumentBuilder;
27import javax.xml.parsers.DocumentBuilderFactory;
28import javax.xml.parsers.ParserConfigurationException;
29
30import org.eclipse.core.resources.IFile;
31import org.eclipse.core.runtime.CoreException;
32import org.eclipse.jface.viewers.AbstractTreeViewer;
33import org.eclipse.jface.viewers.ColumnLabelProvider;
34import org.eclipse.jface.viewers.ISelection;
35import org.eclipse.jface.viewers.ISelectionChangedListener;
36import org.eclipse.jface.viewers.IStructuredSelection;
37import org.eclipse.jface.viewers.ITreeContentProvider;
38import org.eclipse.jface.viewers.SelectionChangedEvent;
39import org.eclipse.jface.viewers.StructuredSelection;
40import org.eclipse.jface.viewers.TreeViewer;
41import org.eclipse.jface.viewers.Viewer;
42import org.eclipse.jface.wizard.WizardPage;
43import org.eclipse.linuxtools.internal.tmf.ui.Activator;
44import org.eclipse.linuxtools.internal.tmf.ui.Messages;
45import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomTraceDefinition;
46import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomXmlTrace;
47import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomXmlTraceDefinition;
48import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomXmlTraceDefinition.InputAttribute;
49import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomXmlTraceDefinition.InputElement;
50import org.eclipse.swt.SWT;
51import org.eclipse.swt.browser.Browser;
52import org.eclipse.swt.browser.TitleEvent;
53import org.eclipse.swt.browser.TitleListener;
54import org.eclipse.swt.custom.SashForm;
55import org.eclipse.swt.custom.ScrolledComposite;
56import org.eclipse.swt.custom.StyleRange;
57import org.eclipse.swt.custom.StyledText;
58import org.eclipse.swt.events.ModifyEvent;
59import org.eclipse.swt.events.ModifyListener;
60import org.eclipse.swt.events.SelectionAdapter;
61import org.eclipse.swt.events.SelectionEvent;
62import org.eclipse.swt.events.SelectionListener;
63import org.eclipse.swt.graphics.Color;
64import org.eclipse.swt.graphics.Font;
65import org.eclipse.swt.graphics.FontData;
66import org.eclipse.swt.graphics.Image;
67import org.eclipse.swt.layout.FillLayout;
68import org.eclipse.swt.layout.GridData;
69import org.eclipse.swt.layout.GridLayout;
70import org.eclipse.swt.widgets.Button;
71import org.eclipse.swt.widgets.Combo;
72import org.eclipse.swt.widgets.Composite;
73import org.eclipse.swt.widgets.Display;
74import org.eclipse.swt.widgets.Group;
75import org.eclipse.swt.widgets.Label;
76import org.eclipse.swt.widgets.Shell;
77import org.eclipse.swt.widgets.Text;
78import org.w3c.dom.Document;
79import org.w3c.dom.Element;
80import org.w3c.dom.NamedNodeMap;
81import org.w3c.dom.Node;
82import org.w3c.dom.NodeList;
83import org.xml.sax.EntityResolver;
84import org.xml.sax.ErrorHandler;
85import org.xml.sax.InputSource;
86import org.xml.sax.SAXException;
87import org.xml.sax.SAXParseException;
88
a0a88f65
AM
89/**
90 * Input wizard page for custom XML trace parsers.
91 *
92 * @author Patrick Tassé
93 */
be222f56
PT
94public class CustomXmlParserInputWizardPage extends WizardPage {
95
96 private static final String DEFAULT_TIMESTAMP_FORMAT = "yyyy-MM-dd HH:mm:ss.SSS"; //$NON-NLS-1$
97 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$
98 private static final Image elementImage = Activator.getDefault().getImageFromPath("/icons/elcl16/element_icon.gif"); //$NON-NLS-1$
99 private static final Image addImage = Activator.getDefault().getImageFromPath("/icons/elcl16/add_button.gif"); //$NON-NLS-1$
100 private static final Image addNextImage = Activator.getDefault().getImageFromPath("/icons/elcl16/addnext_button.gif"); //$NON-NLS-1$
101 private static final Image addChildImage = Activator.getDefault().getImageFromPath("/icons/elcl16/addchild_button.gif"); //$NON-NLS-1$
102 private static final Image addManyImage = Activator.getDefault().getImageFromPath("/icons/elcl16/addmany_button.gif"); //$NON-NLS-1$
103 private static final Image deleteImage = Activator.getDefault().getImageFromPath("/icons/elcl16/delete_button.gif"); //$NON-NLS-1$
104 private static final Image moveUpImage = Activator.getDefault().getImageFromPath("/icons/elcl16/moveup_button.gif"); //$NON-NLS-1$
105 private static final Image moveDownImage = Activator.getDefault().getImageFromPath("/icons/elcl16/movedown_button.gif"); //$NON-NLS-1$
106 private static final Image helpImage = Activator.getDefault().getImageFromPath("/icons/elcl16/help_button.gif"); //$NON-NLS-1$
107 private static final Color COLOR_LIGHT_RED = new Color(Display.getDefault(), 255, 192, 192);
108 private static final Color COLOR_TEXT_BACKGROUND = Display.getCurrent().getSystemColor(SWT.COLOR_WHITE);
109 private static final Color COLOR_WIDGET_BACKGROUND = Display.getCurrent().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND);
110
111 private final ISelection selection;
112 private CustomXmlTraceDefinition definition;
113 private String editDefinitionName;
114 private String defaultDescription;
115 private ElementNode selectedElement;
116 private Composite container;
117 private Text logtypeText;
118 private Text timeStampOutputFormatText;
119 private Text timeStampPreviewText;
120 private Button removeButton;
121 private Button addChildButton;
122 private Button addNextButton;
123 private Button moveUpButton;
124 private Button moveDownButton;
125 private Button feelingLuckyButton;
126 private ScrolledComposite treeScrolledComposite;
127 private ScrolledComposite elementScrolledComposite;
128 private TreeViewer treeViewer;
129 private Composite treeContainer;
130 private Composite elementContainer;
131 private Text errorText;
132 private StyledText inputText;
133 private Font fixedFont;
134 private UpdateListener updateListener;
135 private Browser helpBrowser;
136 private Element documentElement;
137
138 // variables used recursively through element traversal
139 private String timeStampValue;
140 private String timeStampFormat;
141 private boolean timeStampFound;
142 private int logEntriesCount;
143 private boolean logEntryFound;
144
a0a88f65
AM
145 /**
146 * Constructor
147 *
148 * @param selection
149 * Selection object
150 * @param definition
151 * Trace definition
152 */
be222f56
PT
153 protected CustomXmlParserInputWizardPage(ISelection selection, CustomXmlTraceDefinition definition) {
154 super("CustomXmlParserWizardPage"); //$NON-NLS-1$
155 if (definition == null) {
156 setTitle(Messages.CustomXmlParserInputWizardPage_titleNew);
157 defaultDescription = Messages.CustomXmlParserInputWizardPage_descriptionNew;
158 } else {
159 setTitle(Messages.CustomXmlParserInputWizardPage_titleEdit);
160 defaultDescription = Messages.CustomXmlParserInputWizardPage_descriptionEdit;
161 }
162 setDescription(defaultDescription);
163 this.selection = selection;
164 this.definition = definition;
165 if (definition != null) {
166 this.editDefinitionName = definition.definitionName;
167 }
168 }
169
170 @Override
171 public void createControl(Composite parent) {
172 container = new Composite(parent, SWT.NULL);
173 container.setLayout(new GridLayout());
174
175 updateListener = new UpdateListener();
176
177 Composite headerComposite = new Composite(container, SWT.FILL);
178 GridLayout headerLayout = new GridLayout(5, false);
179 headerLayout.marginHeight = 0;
180 headerLayout.marginWidth = 0;
181 headerComposite.setLayout(headerLayout);
182 headerComposite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
183
184 Label logtypeLabel = new Label(headerComposite, SWT.NULL);
185 logtypeLabel.setText(Messages.CustomXmlParserInputWizardPage_logType);
186
187 logtypeText = new Text(headerComposite, SWT.BORDER | SWT.SINGLE);
188 logtypeText.setLayoutData(new GridData(120, SWT.DEFAULT));
189
190 Label timeStampFormatLabel = new Label(headerComposite, SWT.NULL);
191 timeStampFormatLabel.setText(Messages.CustomXmlParserInputWizardPage_timestampFormat);
192
193 timeStampOutputFormatText = new Text(headerComposite, SWT.BORDER | SWT.SINGLE);
194 timeStampOutputFormatText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
195 timeStampOutputFormatText.setText(DEFAULT_TIMESTAMP_FORMAT);
196
197 Button dateFormatHelpButton = new Button(headerComposite, SWT.PUSH);
198 dateFormatHelpButton.setImage(helpImage);
199 dateFormatHelpButton.setToolTipText(Messages.CustomXmlParserInputWizardPage_dateFormatHelp);
200 dateFormatHelpButton.addSelectionListener(new SelectionAdapter() {
201 @Override
202 public void widgetSelected(SelectionEvent e) {
203 openHelpShell(SIMPLE_DATE_FORMAT_URL);
204 }
205 });
206
207 Label timeStampPreviewLabel = new Label(headerComposite, SWT.NULL);
208 timeStampPreviewLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 3, 1));
209 timeStampPreviewLabel.setText(Messages.CustomXmlParserInputWizardPage_preview);
210
211 timeStampPreviewText = new Text(headerComposite, SWT.BORDER | SWT.SINGLE | SWT.READ_ONLY);
212 timeStampPreviewText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));
213 timeStampPreviewText.setText("*no time stamp element or attribute*"); //$NON-NLS-1$
214
215 createButtonBar();
216
217 SashForm vSash = new SashForm(container, SWT.VERTICAL);
218 vSash.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
219 vSash.setBackground(vSash.getDisplay().getSystemColor(SWT.COLOR_GRAY));
220
221 SashForm hSash = new SashForm(vSash, SWT.HORIZONTAL);
222 hSash.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
223
224 treeScrolledComposite = new ScrolledComposite(hSash, SWT.V_SCROLL | SWT.H_SCROLL);
225 treeScrolledComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
226 treeContainer = new Composite(treeScrolledComposite, SWT.NONE);
227 treeContainer.setLayout(new FillLayout());
228 treeScrolledComposite.setContent(treeContainer);
229 treeScrolledComposite.setExpandHorizontal(true);
230 treeScrolledComposite.setExpandVertical(true);
231
232 treeViewer = new TreeViewer(treeContainer, SWT.SINGLE | SWT.BORDER);
233 treeViewer.setContentProvider(new InputElementTreeNodeContentProvider());
234 treeViewer.setLabelProvider(new InputElementTreeLabelProvider());
235 treeViewer.addSelectionChangedListener(new InputElementTreeSelectionChangedListener());
236 treeContainer.layout();
237
238 treeScrolledComposite
239 .setMinSize(treeContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT).x, treeContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT).y);
240
241 elementScrolledComposite = new ScrolledComposite(hSash, SWT.V_SCROLL);
242 elementScrolledComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
243 elementContainer = new Composite(elementScrolledComposite, SWT.NONE);
244 GridLayout gl = new GridLayout();
245 gl.marginHeight = 1;
246 gl.marginWidth = 0;
247 elementContainer.setLayout(gl);
248 elementScrolledComposite.setContent(elementContainer);
249 elementScrolledComposite.setExpandHorizontal(true);
250 elementScrolledComposite.setExpandVertical(true);
251
252 if (definition == null) {
253 definition = new CustomXmlTraceDefinition();
254 }
255 loadDefinition(definition);
256 treeViewer.expandAll();
257 elementContainer.layout();
258
259 logtypeText.addModifyListener(updateListener);
260 timeStampOutputFormatText.addModifyListener(updateListener);
261
262 elementScrolledComposite.setMinSize(elementContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT).x,
263 elementContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT).y - 1);
264
265 hSash.setWeights(new int[] { 1, 2 });
266
267 if (definition.rootInputElement == null) {
268 removeButton.setEnabled(false);
269 addChildButton.setToolTipText(Messages.CustomXmlParserInputWizardPage_addDocumentElement);
270 addNextButton.setEnabled(false);
271 moveUpButton.setEnabled(false);
272 moveDownButton.setEnabled(false);
273 } else { // root is selected
274 addNextButton.setEnabled(false);
275 }
276
277 Composite sashBottom = new Composite(vSash, SWT.NONE);
278 GridLayout sashBottomLayout = new GridLayout(2, false);
279 sashBottomLayout.marginHeight = 0;
280 sashBottomLayout.marginWidth = 0;
281 sashBottom.setLayout(sashBottomLayout);
282
283 Label previewLabel = new Label(sashBottom, SWT.NULL);
284 previewLabel.setText(Messages.CustomXmlParserInputWizardPage_previewInput);
285
286 errorText = new Text(sashBottom, SWT.SINGLE | SWT.READ_ONLY);
287 errorText.setBackground(COLOR_WIDGET_BACKGROUND);
288 errorText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
289 errorText.setVisible(false);
290
291 inputText = new StyledText(sashBottom, SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL);
292 if (fixedFont == null) {
293 if (System.getProperty("os.name").contains("Windows")) { //$NON-NLS-1$ //$NON-NLS-2$
294 fixedFont = new Font(Display.getCurrent(), new FontData("Courier New", 10, SWT.NORMAL)); //$NON-NLS-1$
295 } else {
296 fixedFont = new Font(Display.getCurrent(), new FontData("Monospace", 10, SWT.NORMAL)); //$NON-NLS-1$
297 }
298 }
299 inputText.setFont(fixedFont);
300 GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1);
301 gd.heightHint = inputText.computeSize(SWT.DEFAULT, inputText.getLineHeight() * 4).y;
302 gd.widthHint = 800;
303 inputText.setLayoutData(gd);
304 inputText.setText(getSelectionText());
305 inputText.addModifyListener(new ModifyListener() {
306 @Override
307 public void modifyText(ModifyEvent e) {
308 parseXmlInput(inputText.getText());
309 }
310 });
311 inputText.addModifyListener(updateListener);
312
313 vSash.setWeights(new int[] { hSash.computeSize(SWT.DEFAULT, SWT.DEFAULT).y, sashBottom.computeSize(SWT.DEFAULT, SWT.DEFAULT).y });
314
315 setControl(container);
316 }
317
318 private void createButtonBar() {
319 Composite buttonBar = new Composite(container, SWT.NONE);
320 GridLayout buttonBarLayout = new GridLayout(6, false);
321 buttonBarLayout.marginHeight = 0;
322 buttonBarLayout.marginWidth = 0;
323 buttonBar.setLayout(buttonBarLayout);
324
325 removeButton = new Button(buttonBar, SWT.PUSH);
326 removeButton.setImage(deleteImage);
327 removeButton.setToolTipText(Messages.CustomXmlParserInputWizardPage_removeElement);
328 removeButton.addSelectionListener(new SelectionAdapter() {
329 @Override
330 public void widgetSelected(SelectionEvent e) {
331 if (treeViewer.getSelection().isEmpty() || selectedElement == null) {
332 return;
333 }
334 removeElement();
335 InputElement inputElement = (InputElement) ((IStructuredSelection) treeViewer.getSelection()).getFirstElement();
336 if (inputElement == definition.rootInputElement) {
337 definition.rootInputElement = null;
338 } else {
339 inputElement.parentElement.childElements.remove(inputElement);
340 }
341 treeViewer.refresh();
342 validate();
343 updatePreviews();
344 removeButton.setEnabled(false);
345 if (definition.rootInputElement == null) {
346 addChildButton.setEnabled(true);
347 addChildButton.setToolTipText(Messages.CustomXmlParserInputWizardPage_addDocumentEleemnt);
348 } else {
349 addChildButton.setEnabled(false);
350 }
351 addNextButton.setEnabled(false);
352 moveUpButton.setEnabled(false);
353 moveDownButton.setEnabled(false);
354 }
355 });
356
357 addChildButton = new Button(buttonBar, SWT.PUSH);
358 addChildButton.setImage(addChildImage);
359 addChildButton.setToolTipText(Messages.CustomXmlParserInputWizardPage_addChildElement);
360 addChildButton.addSelectionListener(new SelectionAdapter() {
361 @Override
362 public void widgetSelected(SelectionEvent e) {
363 InputElement inputElement = new InputElement("", false, CustomXmlTraceDefinition.TAG_IGNORE, 0, "", null); //$NON-NLS-1$ //$NON-NLS-2$
364 if (definition.rootInputElement == null) {
365 definition.rootInputElement = inputElement;
366 inputElement.elementName = getChildNameSuggestion(null);
367 } else if (treeViewer.getSelection().isEmpty()) {
368 return;
369 } else {
370 InputElement parentInputElement = (InputElement) ((IStructuredSelection) treeViewer.getSelection()).getFirstElement();
371 parentInputElement.addChild(inputElement);
372 inputElement.elementName = getChildNameSuggestion(parentInputElement);
373 }
374 treeViewer.refresh();
375 treeViewer.setSelection(new StructuredSelection(inputElement), true);
376 }
377 });
378
379 addNextButton = new Button(buttonBar, SWT.PUSH);
380 addNextButton.setImage(addNextImage);
381 addNextButton.setToolTipText(Messages.CustomXmlParserInputWizardPage_addNextElement);
382 addNextButton.addSelectionListener(new SelectionAdapter() {
383 @Override
384 public void widgetSelected(SelectionEvent e) {
385 InputElement inputElement = new InputElement("", false, CustomXmlTraceDefinition.TAG_IGNORE, 0, "", null); //$NON-NLS-1$ //$NON-NLS-2$
386 if (definition.rootInputElement == null) {
387 definition.rootInputElement = inputElement;
388 inputElement.elementName = getChildNameSuggestion(null);
389 } else if (treeViewer.getSelection().isEmpty()) {
390 return;
391 } else {
392 InputElement previousInputElement = (InputElement) ((IStructuredSelection) treeViewer.getSelection()).getFirstElement();
393 if (previousInputElement == definition.rootInputElement) {
394 return;
395 }
396 previousInputElement.addNext(inputElement);
397 inputElement.elementName = getChildNameSuggestion(inputElement.parentElement);
398 }
399 treeViewer.refresh();
400 treeViewer.setSelection(new StructuredSelection(inputElement), true);
401 }
402 });
403
404 feelingLuckyButton = new Button(buttonBar, SWT.PUSH);
405 feelingLuckyButton.setImage(addManyImage);
406 feelingLuckyButton.setToolTipText(Messages.CustomXmlParserInputWizardPage_feelingLucky);
407 feelingLuckyButton.addSelectionListener(new SelectionAdapter() {
408 @Override
409 public void widgetSelected(SelectionEvent e) {
410 InputElement inputElement = null;
411 if (definition.rootInputElement == null) {
412 if (getChildNameSuggestion(null).length() != 0) {
413 inputElement = new InputElement(getChildNameSuggestion(null), false, CustomXmlTraceDefinition.TAG_IGNORE, 0, "", null); //$NON-NLS-1$
414 definition.rootInputElement = inputElement;
415 feelingLucky(inputElement);
416 } else {
417 return;
418 }
419 } else if (treeViewer.getSelection().isEmpty()) {
420 return;
421 } else {
422 inputElement = (InputElement) ((IStructuredSelection) treeViewer.getSelection()).getFirstElement();
423 feelingLucky(inputElement);
424 }
425 treeViewer.refresh();
426 treeViewer.setSelection(new StructuredSelection(inputElement), true);
427 treeViewer.expandToLevel(inputElement, AbstractTreeViewer.ALL_LEVELS);
428 }
429 });
430
431 moveUpButton = new Button(buttonBar, SWT.PUSH);
432 moveUpButton.setImage(moveUpImage);
433 moveUpButton.setToolTipText(Messages.CustomXmlParserInputWizardPage_moveUp);
434 moveUpButton.addSelectionListener(new SelectionAdapter() {
435 @Override
436 public void widgetSelected(SelectionEvent e) {
437 if (treeViewer.getSelection().isEmpty()) {
438 return;
439 }
440 InputElement inputElement = (InputElement) ((IStructuredSelection) treeViewer.getSelection()).getFirstElement();
441 if (inputElement == definition.rootInputElement) {
442 return;
443 }
444 inputElement.moveUp();
445 treeViewer.refresh();
446 validate();
447 updatePreviews();
448 }
449 });
450
451 moveDownButton = new Button(buttonBar, SWT.PUSH);
452 moveDownButton.setImage(moveDownImage);
453 moveDownButton.setToolTipText(Messages.CustomXmlParserInputWizardPage_moveDown);
454 moveDownButton.addSelectionListener(new SelectionAdapter() {
455 @Override
456 public void widgetSelected(SelectionEvent e) {
457 if (treeViewer.getSelection().isEmpty()) {
458 return;
459 }
460 InputElement inputElement = (InputElement) ((IStructuredSelection) treeViewer.getSelection()).getFirstElement();
461 if (inputElement == definition.rootInputElement) {
462 return;
463 }
464 inputElement.moveDown();
465 treeViewer.refresh();
466 validate();
467 updatePreviews();
468 }
469 });
470 }
471
472 private void feelingLucky(InputElement inputElement) {
473 while (true) {
474 String attributeName = getAttributeNameSuggestion(inputElement);
475 if (attributeName.length() == 0) {
476 break;
477 }
478 InputAttribute attribute = new InputAttribute(attributeName, attributeName, 0, ""); //$NON-NLS-1$
479 inputElement.addAttribute(attribute);
480 }
481 while (true) {
482 String childName = getChildNameSuggestion(inputElement);
483 if (childName.length() == 0) {
484 break;
485 }
486 InputElement childElement = new InputElement(childName, false, CustomXmlTraceDefinition.TAG_IGNORE, 0, "", null); //$NON-NLS-1$
487 inputElement.addChild(childElement);
488 feelingLucky(childElement);
489 }
490 }
491
492 private static class InputElementTreeNodeContentProvider implements ITreeContentProvider {
493
494 @Override
495 public Object[] getElements(Object inputElement) {
496 CustomXmlTraceDefinition def = (CustomXmlTraceDefinition) inputElement;
497 if (def.rootInputElement != null) {
498 return new Object[] { def.rootInputElement };
499 }
500 return new Object[0];
501 }
502
503 @Override
504 public Object[] getChildren(Object parentElement) {
505 InputElement inputElement = (InputElement) parentElement;
506 if (inputElement.childElements == null) {
507 return new InputElement[0];
508 }
509 return inputElement.childElements.toArray();
510 }
511
512 @Override
513 public boolean hasChildren(Object element) {
514 InputElement inputElement = (InputElement) element;
515 return (inputElement.childElements != null && inputElement.childElements.size() > 0);
516 }
517
518 @Override
519 public void dispose() {
520 }
521
522 @Override
523 public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
524 }
525
526 @Override
527 public Object getParent(Object element) {
528 InputElement inputElement = (InputElement) element;
529 return inputElement.parentElement;
530 }
531 }
532
533 private static class InputElementTreeLabelProvider extends ColumnLabelProvider {
534
535 @Override
536 public Image getImage(Object element) {
537 return elementImage;
538 }
539
540 @Override
541 public String getText(Object element) {
542 InputElement inputElement = (InputElement) element;
543 return (inputElement.elementName.trim().length() == 0) ? "?" : inputElement.elementName; //$NON-NLS-1$
544 }
545 }
546
547 private class InputElementTreeSelectionChangedListener implements ISelectionChangedListener {
548 @Override
549 public void selectionChanged(SelectionChangedEvent event) {
550 if (selectedElement != null) {
551 selectedElement.dispose();
552 }
553 if (!(event.getSelection().isEmpty()) && event.getSelection() instanceof IStructuredSelection) {
3dca7aa5
AM
554 IStructuredSelection sel = (IStructuredSelection) event.getSelection();
555 InputElement inputElement = (InputElement) sel.getFirstElement();
be222f56
PT
556 selectedElement = new ElementNode(elementContainer, inputElement);
557 elementContainer.layout();
558 elementScrolledComposite.setMinSize(elementContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT).x,
559 elementContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT).y - 1);
560 container.layout();
561 validate();
562 updatePreviews();
563 removeButton.setEnabled(true);
564 addChildButton.setEnabled(true);
565 addChildButton.setToolTipText(Messages.CustomXmlParserInputWizardPage_addChildElement);
566 if (definition.rootInputElement == inputElement) {
567 addNextButton.setEnabled(false);
568 } else {
569 addNextButton.setEnabled(true);
570 }
571 moveUpButton.setEnabled(true);
572 moveDownButton.setEnabled(true);
573 } else {
574 removeButton.setEnabled(false);
575 if (definition.rootInputElement == null) {
576 addChildButton.setEnabled(true);
577 addChildButton.setToolTipText(Messages.CustomXmlParserInputWizardPage_addDocumentElement);
578 } else {
579 addChildButton.setEnabled(false);
580 }
581 addNextButton.setEnabled(false);
582 moveUpButton.setEnabled(false);
583 moveDownButton.setEnabled(false);
584 }
585 }
586 }
587
588 /*
589 * (non-Javadoc)
590 *
591 * @see org.eclipse.jface.dialogs.DialogPage#dispose()
592 */
593 @Override
594 public void dispose() {
595 if (fixedFont != null) {
596 fixedFont.dispose();
597 fixedFont = null;
598 }
599 super.dispose();
600 }
601
602 private void loadDefinition(CustomXmlTraceDefinition def) {
603 logtypeText.setText(def.definitionName);
604 timeStampOutputFormatText.setText(def.timeStampOutputFormat);
605 treeViewer.setInput(def);
606
607 if (def.rootInputElement != null) {
608 treeViewer.setSelection(new StructuredSelection(def.rootInputElement));
609 }
610 }
611
612 private String getName(InputElement inputElement) {
613 String name = (inputElement.elementName.trim().length() == 0) ? "?" : inputElement.elementName.trim(); //$NON-NLS-1$
614 if (inputElement.parentElement == null) {
615 return name;
616 }
617 return getName(inputElement.parentElement) + " : " + name; //$NON-NLS-1$
618 }
619
620 private String getName(InputAttribute inputAttribute, InputElement inputElement) {
621 String name = (inputAttribute.attributeName.trim().length() == 0) ? "?" : inputAttribute.attributeName.trim(); //$NON-NLS-1$
622 return getName(inputElement) + " : " + name; //$NON-NLS-1$
623 }
624
625 /*
626 * (non-Javadoc)
627 *
628 * @see org.eclipse.jface.dialogs.DialogPage#setVisible(boolean)
629 */
630 @Override
631 public void setVisible(boolean visible) {
632 if (visible) {
633 validate();
634 updatePreviews();
635 }
636 super.setVisible(visible);
637 }
638
a0a88f65
AM
639 /**
640 * Get the global list of input names.
641 *
642 * @return The list of input names
643 */
be222f56
PT
644 public List<String> getInputNames() {
645 return getInputNames(definition.rootInputElement);
646 }
647
a0a88f65
AM
648 /**
649 * Get the list of input names for a given element.
650 *
651 * @param inputElement
652 * The element
653 * @return The input names for this element
654 */
be222f56
PT
655 public List<String> getInputNames(InputElement inputElement) {
656 List<String> inputs = new ArrayList<String>();
657 if (inputElement.inputName != null && !inputElement.inputName.equals(CustomXmlTraceDefinition.TAG_IGNORE)) {
658 String inputName = inputElement.inputName;
659 if (!inputs.contains(inputName)) {
660 inputs.add(inputName);
661 }
662 }
663 if (inputElement.attributes != null) {
664 for (InputAttribute attribute : inputElement.attributes) {
665 String inputName = attribute.inputName;
666 if (!inputs.contains(inputName)) {
667 inputs.add(inputName);
668 }
669 }
670 }
671 if (inputElement.childElements != null) {
672 for (InputElement childInputElement : inputElement.childElements) {
673 for (String inputName : getInputNames(childInputElement)) {
674 if (!inputs.contains(inputName)) {
675 inputs.add(inputName);
676 }
677 }
678 }
679 }
680 return inputs;
681 }
682
683 private void removeElement() {
684 selectedElement.dispose();
685 selectedElement = null;
686 elementContainer.layout();
687 elementScrolledComposite.setMinSize(elementContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT).x,
688 elementContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT).y - 1);
689 container.layout();
690 }
691
692 private String getSelectionText() {
693 InputStream inputStream = null;
694 if (this.selection instanceof IStructuredSelection) {
3dca7aa5
AM
695 Object sel = ((IStructuredSelection) this.selection).getFirstElement();
696 if (sel instanceof IFile) {
697 IFile file = (IFile) sel;
be222f56
PT
698 try {
699 inputStream = file.getContents();
700 } catch (CoreException e) {
701 return ""; //$NON-NLS-1$
702 }
703 }
704 }
705 if (inputStream != null) {
706 BufferedReader reader = null;
707 try {
708 reader = new BufferedReader(new InputStreamReader(inputStream));
709 StringBuilder sb = new StringBuilder();
710 String line = null;
711 while ((line = reader.readLine()) != null) {
712 sb.append(line + "\n"); //$NON-NLS-1$
713 }
714 parseXmlInput(sb.toString());
715 reader.close();
716 return sb.toString();
717 } catch (IOException e) {
718 return ""; //$NON-NLS-1$
719 }
720 }
721 return ""; //$NON-NLS-1$
722 }
723
724 private void parseXmlInput(final String string) {
725 try {
726 DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
727 DocumentBuilder db = dbf.newDocumentBuilder();
728
729 // The following allows xml parsing without access to the dtd
730 EntityResolver resolver = new EntityResolver() {
731 @Override
732 public InputSource resolveEntity(String publicId, String systemId) {
733 String empty = ""; //$NON-NLS-1$
734 ByteArrayInputStream bais = new ByteArrayInputStream(empty.getBytes());
735 return new InputSource(bais);
736 }
737 };
738 db.setEntityResolver(resolver);
739
740 // The following catches xml parsing exceptions
741 db.setErrorHandler(new ErrorHandler() {
742 @Override
743 public void error(SAXParseException saxparseexception) throws SAXException {
744 }
745
746 @Override
747 public void warning(SAXParseException saxparseexception) throws SAXException {
748 }
749
750 @Override
751 public void fatalError(SAXParseException saxparseexception) throws SAXException {
752 if (string.trim().length() != 0) {
753 errorText.setText(saxparseexception.getMessage());
754 errorText.setBackground(COLOR_LIGHT_RED);
755 errorText.setVisible(true);
756 }
757 throw saxparseexception;
758 }
759 });
760
761 errorText.setVisible(false);
762 Document doc = null;
763 doc = db.parse(new ByteArrayInputStream(string.getBytes()));
764 documentElement = doc.getDocumentElement();
765 } catch (ParserConfigurationException e) {
766 Activator.getDefault().logError("Error pasing XML input string: " + string, e); //$NON-NLS-1$
767 documentElement = null;
768 } catch (SAXException e) {
769 documentElement = null;
770 } catch (IOException e) {
771 Activator.getDefault().logError("Error pasing XML input string: " + string, e); //$NON-NLS-1$
772 documentElement = null;
773 }
774 }
775
be222f56
PT
776 private void initValues() {
777 timeStampValue = null;
778 timeStampFormat = null;
779 logEntriesCount = 0;
780 logEntryFound = false;
781 }
782
3dca7aa5 783 private void updatePreviews() {
be222f56
PT
784 if (inputText == null) {
785 // early update during construction
786 return;
787 }
788 inputText.setStyleRanges(new StyleRange[] {});
789 if (selectedElement == null) {
790 return;
791 }
792
793 initValues();
794
795 selectedElement.updatePreview();
796
797 if (timeStampValue != null && timeStampFormat != null) {
798 try {
799 SimpleDateFormat dateFormat = new SimpleDateFormat(timeStampFormat);
800 Date date = dateFormat.parse(timeStampValue);
801 dateFormat = new SimpleDateFormat(timeStampOutputFormatText.getText().trim());
802 timeStampPreviewText.setText(dateFormat.format(date));
803 } catch (ParseException e) {
804 timeStampPreviewText.setText("*parse exception* [" + timeStampValue + "] <> [" + timeStampFormat + "]"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
805 } catch (IllegalArgumentException e) {
806 timeStampPreviewText.setText("*parse exception* [Illegal Argument]"); //$NON-NLS-1$
807 }
808 } else {
809 timeStampPreviewText.setText("*no matching time stamp*"); //$NON-NLS-1$
810 }
811 }
812
813 private void openHelpShell(String url) {
814 if (helpBrowser != null && !helpBrowser.isDisposed()) {
815 helpBrowser.getShell().setActive();
816 if (!helpBrowser.getUrl().equals(url)) {
817 helpBrowser.setUrl(url);
818 }
819 return;
820 }
821 final Shell helpShell = new Shell(getShell(), SWT.SHELL_TRIM);
822 helpShell.setLayout(new FillLayout());
823 helpBrowser = new Browser(helpShell, SWT.NONE);
824 helpBrowser.addTitleListener(new TitleListener() {
825 @Override
826 public void changed(TitleEvent event) {
827 helpShell.setText(event.title);
828 }
829 });
830 helpBrowser.setBounds(0, 0, 600, 400);
831 helpShell.pack();
832 helpShell.open();
833 helpBrowser.setUrl(url);
834 }
835
836 private class UpdateListener implements ModifyListener, SelectionListener {
837
838 @Override
839 public void modifyText(ModifyEvent e) {
840 validate();
841 updatePreviews();
842 }
843
844 @Override
845 public void widgetDefaultSelected(SelectionEvent e) {
846 validate();
847 updatePreviews();
848 }
849
850 @Override
851 public void widgetSelected(SelectionEvent e) {
852 validate();
853 updatePreviews();
854 }
855
856 }
857
858 private class ElementNode {
859 final InputElement inputElement;
860 final Group group;
861 List<Attribute> attributes = new ArrayList<Attribute>();
862 List<ElementNode> childElements = new ArrayList<ElementNode>();
863 Text elementNameText;
864 Composite tagComposite;
865 Combo tagCombo;
866 Label tagLabel;
867 Text tagText;
868 Combo actionCombo;
869 Label previewLabel;
870 Text previewText;
871 Button logEntryButton;
872 Label fillerLabel;
873 Composite addAttributeComposite;
874 Button addAttributeButton;
875 Label addAttributeLabel;
876
877 public ElementNode(Composite parent, InputElement inputElement) {
878 this.inputElement = inputElement;
879
880 group = new Group(parent, SWT.NONE);
881 GridLayout gl = new GridLayout(2, false);
882 gl.marginHeight = 0;
883 group.setLayout(gl);
884 group.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
885 group.setText(getName(inputElement));
886
887 Label label = new Label(group, SWT.NULL);
888 label.setText(Messages.CustomXmlParserInputWizardPage_elementName);
889 label.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
890
891 elementNameText = new Text(group, SWT.BORDER | SWT.SINGLE);
892 GridData gd = new GridData(SWT.FILL, SWT.CENTER, true, false);
893 gd.widthHint = 0;
894 elementNameText.setLayoutData(gd);
895 elementNameText.addModifyListener(new ModifyListener() {
896 @Override
897 public void modifyText(ModifyEvent e) {
898 ElementNode.this.inputElement.elementName = elementNameText.getText().trim();
899 group.setText(getName(ElementNode.this.inputElement));
900 }
901 });
902 elementNameText.setText(inputElement.elementName);
903 elementNameText.addModifyListener(updateListener);
904
905 if (inputElement.parentElement != null) {
906 previewLabel = new Label(group, SWT.NULL);
907 previewLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
908 previewLabel.setText(Messages.CustomXmlParserInputWizardPage_preview);
909
910 previewText = new Text(group, SWT.BORDER | SWT.SINGLE | SWT.READ_ONLY);
911 gd = new GridData(SWT.FILL, SWT.CENTER, true, false);
912 gd.widthHint = 0;
913 previewText.setLayoutData(gd);
914 previewText.setText(Messages.CustomXmlParserInputWizardPage_noMatchingElement);
915 previewText.setBackground(COLOR_WIDGET_BACKGROUND);
916
917 logEntryButton = new Button(group, SWT.CHECK);
918 logEntryButton.setText(Messages.CustomXmlParserInputWizardPage_logEntry);
919 logEntryButton.setSelection(inputElement.logEntry);
920 logEntryButton.addSelectionListener(new SelectionListener() {
921 @Override
922 public void widgetDefaultSelected(SelectionEvent e) {
923 }
924
925 @Override
926 public void widgetSelected(SelectionEvent e) {
3dca7aa5
AM
927 InputElement parentElem = ElementNode.this.inputElement.parentElement;
928 while (parentElem != null) {
929 parentElem.logEntry = false;
930 parentElem = parentElem.parentElement;
be222f56
PT
931 }
932 }
933 });
934 logEntryButton.addSelectionListener(updateListener);
935
936 tagComposite = new Composite(group, SWT.FILL);
937 GridLayout tagLayout = new GridLayout(4, false);
938 tagLayout.marginWidth = 0;
939 tagLayout.marginHeight = 0;
940 tagComposite.setLayout(tagLayout);
941 tagComposite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
942
943 tagCombo = new Combo(tagComposite, SWT.DROP_DOWN | SWT.READ_ONLY);
944 tagCombo.setItems(new String[] { CustomXmlTraceDefinition.TAG_IGNORE, CustomTraceDefinition.TAG_TIMESTAMP,
945 CustomTraceDefinition.TAG_MESSAGE, CustomTraceDefinition.TAG_OTHER });
946 tagCombo.setVisibleItemCount(tagCombo.getItemCount());
947 tagCombo.addSelectionListener(new SelectionListener() {
948 @Override
949 public void widgetDefaultSelected(SelectionEvent e) {
950 }
951
952 @Override
953 public void widgetSelected(SelectionEvent e) {
954 tagText.removeModifyListener(updateListener);
955 switch (tagCombo.getSelectionIndex()) {
956 case 0: // Ignore
957 tagLabel.setVisible(false);
958 tagText.setVisible(false);
959 actionCombo.setVisible(false);
960 break;
961 case 1: // Time Stamp
962 tagLabel.setText(Messages.CustomXmlParserInputWizardPage_format);
963 tagLabel.setVisible(true);
964 tagText.setVisible(true);
965 tagText.addModifyListener(updateListener);
966 actionCombo.setVisible(true);
967 break;
968 case 2: // Message
969 tagLabel.setVisible(false);
970 tagText.setVisible(false);
971 actionCombo.setVisible(true);
972 break;
973 case 3: // Other
974 tagLabel.setText(Messages.CustomXmlParserInputWizardPage_tagName);
975 tagLabel.setVisible(true);
976 if (tagText.getText().trim().length() == 0) {
977 tagText.setText(elementNameText.getText().trim());
978 }
979 tagText.setVisible(true);
980 tagText.addModifyListener(updateListener);
981 actionCombo.setVisible(true);
982 break;
983 default:
984 break;
985 }
986 tagComposite.layout();
987 validate();
988 updatePreviews();
989 }
990 });
991
992 tagLabel = new Label(tagComposite, SWT.NULL);
993 tagLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
994
995 tagText = new Text(tagComposite, SWT.BORDER | SWT.SINGLE);
996 gd = new GridData(SWT.FILL, SWT.CENTER, true, false);
997 gd.widthHint = 0;
998 tagText.setLayoutData(gd);
999
1000 actionCombo = new Combo(tagComposite, SWT.DROP_DOWN | SWT.READ_ONLY);
1001 actionCombo.setItems(new String[] { Messages.CustomXmlParserInputWizardPage_set, Messages.CustomXmlParserInputWizardPage_append,
1002 Messages.CustomXmlParserInputWizardPage_appendWith });
1003 actionCombo.select(inputElement.inputAction);
1004 actionCombo.addSelectionListener(updateListener);
1005
1006 if (inputElement.inputName.equals(CustomXmlTraceDefinition.TAG_IGNORE)) {
1007 tagCombo.select(0);
1008 tagLabel.setVisible(false);
1009 tagText.setVisible(false);
1010 actionCombo.setVisible(false);
1011 } else if (inputElement.inputName.equals(CustomTraceDefinition.TAG_TIMESTAMP)) {
1012 tagCombo.select(1);
1013 tagLabel.setText(Messages.CustomXmlParserInputWizardPage_format);
1014 tagText.setText(inputElement.inputFormat);
1015 tagText.addModifyListener(updateListener);
1016 } else if (inputElement.inputName.equals(CustomTraceDefinition.TAG_MESSAGE)) {
1017 tagCombo.select(2);
1018 tagLabel.setVisible(false);
1019 tagText.setVisible(false);
1020 } else {
1021 tagCombo.select(3);
1022 tagLabel.setText(Messages.CustomXmlParserInputWizardPage_tagName);
1023 tagText.setText(inputElement.inputName);
1024 tagText.addModifyListener(updateListener);
1025 }
1026 }
1027
1028 if (inputElement.attributes != null) {
1029 for (InputAttribute inputAttribute : inputElement.attributes) {
1030 Attribute attribute = new Attribute(group, this, inputAttribute, attributes.size() + 1);
1031 attributes.add(attribute);
1032 }
1033 }
1034
1035 createAddButton();
1036 }
1037
1038 private void updatePreview() {
1039 Element element = getPreviewElement(inputElement);
1040 if (inputElement.parentElement != null) { // no preview text for
1041 // document element
1042 previewText.setText(Messages.CustomXmlParserInputWizardPage_noMatchingElement);
1043 if (element != null) {
1044 previewText.setText(CustomXmlTrace.parseElement(element, new StringBuffer()).toString());
1045 if (logEntryButton.getSelection()) {
1046 if (!logEntryFound) {
1047 logEntryFound = true;
1048 logEntriesCount++;
1049 } else {
1050 logEntryButton.setSelection(false); // remove nested
1051 // log entry
1052 }
1053 }
1054 if (tagCombo.getText().equals(CustomTraceDefinition.TAG_TIMESTAMP) && logEntriesCount <= 1) {
1055 String value = previewText.getText().trim();
1056 if (value.length() != 0) {
1057 if (actionCombo.getSelectionIndex() == CustomTraceDefinition.ACTION_SET) {
1058 timeStampValue = value;
1059 timeStampFormat = tagText.getText().trim();
1060 } else if (actionCombo.getSelectionIndex() == CustomTraceDefinition.ACTION_APPEND) {
1061 if (timeStampValue != null) {
1062 timeStampValue += value;
1063 timeStampFormat += tagText.getText().trim();
1064 } else {
1065 timeStampValue = value;
1066 timeStampFormat = tagText.getText().trim();
1067 }
1068 } else if (actionCombo.getSelectionIndex() == CustomTraceDefinition.ACTION_APPEND_WITH_SEPARATOR) {
1069 if (timeStampValue != null) {
1070 timeStampValue += " | " + value; //$NON-NLS-1$
1071 timeStampFormat += " | " + tagText.getText().trim(); //$NON-NLS-1$
1072 } else {
1073 timeStampValue = value;
1074 timeStampFormat = tagText.getText().trim();
1075 }
1076 }
1077 }
1078 }
1079 }
1080 }
1081 for (Attribute attribute : attributes) {
1082 if (element != null) {
1083 String value = element.getAttribute(attribute.attributeNameText.getText().trim());
1084 if (value.length() != 0) {
1085 attribute.previewText.setText(value);
1086 if (attribute.tagCombo.getText().equals(CustomTraceDefinition.TAG_TIMESTAMP) && logEntriesCount <= 1) {
1087 if (attribute.actionCombo.getSelectionIndex() == CustomTraceDefinition.ACTION_SET) {
1088 timeStampValue = value;
1089 timeStampFormat = attribute.tagText.getText().trim();
1090 } else if (attribute.actionCombo.getSelectionIndex() == CustomTraceDefinition.ACTION_APPEND) {
1091 if (timeStampValue != null) {
1092 timeStampValue += value;
1093 timeStampFormat += attribute.tagText.getText().trim();
1094 } else {
1095 timeStampValue = value;
1096 timeStampFormat = attribute.tagText.getText().trim();
1097 }
1098 } else if (attribute.actionCombo.getSelectionIndex() == CustomTraceDefinition.ACTION_APPEND_WITH_SEPARATOR) {
1099 if (timeStampValue != null) {
1100 timeStampValue += " | " + value; //$NON-NLS-1$
1101 timeStampFormat += " | " + attribute.tagText.getText().trim(); //$NON-NLS-1$
1102 } else {
1103 timeStampValue = value;
1104 timeStampFormat = attribute.tagText.getText().trim();
1105 }
1106 }
1107 }
1108 } else {
1109 attribute.previewText.setText(Messages.CustomXmlParserInputWizardPage_noMatchingAttribute);
1110 }
1111 } else {
1112 attribute.previewText.setText(Messages.CustomXmlParserInputWizardPage_noMatchingElement);
1113 }
1114 }
1115 for (ElementNode child : childElements) {
1116 child.updatePreview();
1117 }
1118 if (logEntryButton != null && logEntryButton.getSelection()) {
1119 logEntryFound = false;
1120 }
1121 }
1122
1123 private void createAddButton() {
1124 fillerLabel = new Label(group, SWT.NONE);
1125
1126 addAttributeComposite = new Composite(group, SWT.NONE);
1127 addAttributeComposite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
1128 GridLayout addAttributeLayout = new GridLayout(2, false);
1129 addAttributeLayout.marginHeight = 0;
1130 addAttributeLayout.marginWidth = 0;
1131 addAttributeComposite.setLayout(addAttributeLayout);
1132
1133 addAttributeButton = new Button(addAttributeComposite, SWT.PUSH);
1134 addAttributeButton.setImage(addImage);
1135 addAttributeButton.setToolTipText(Messages.CustomXmlParserInputWizardPage_addAttribute);
1136 addAttributeButton.addSelectionListener(new SelectionAdapter() {
1137 @Override
1138 public void widgetSelected(SelectionEvent e) {
1139 removeAddButton();
1140 String attributeName = getAttributeNameSuggestion(inputElement);
1141 InputAttribute inputAttribute = new InputAttribute(attributeName, attributeName, 0, ""); //$NON-NLS-1$
1142 attributes.add(new Attribute(group, ElementNode.this, inputAttribute, attributes.size() + 1));
1143 createAddButton();
1144 elementContainer.layout();
1145 elementScrolledComposite.setMinSize(elementContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT).x,
1146 elementContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT).y - 1);
1147 group.getParent().layout();
1148 validate();
1149 updatePreviews();
1150 }
1151 });
1152
1153 addAttributeLabel = new Label(addAttributeComposite, SWT.NULL);
1154 addAttributeLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
1155 addAttributeLabel.setText(Messages.CustomXmlParserInputWizardPage_newAttibute);
1156 }
1157
1158 private void removeAddButton() {
1159 fillerLabel.dispose();
1160 addAttributeComposite.dispose();
1161 }
1162
1163 private void removeAttribute(int attributeNumber) {
41b5c37f
AM
1164 int nb = attributeNumber;
1165 if (--nb < attributes.size()) {
1166 attributes.remove(nb).dispose();
1167 for (int i = nb; i < attributes.size(); i++) {
be222f56
PT
1168 attributes.get(i).setAttributeNumber(i + 1);
1169 }
1170 elementContainer.layout();
1171 elementScrolledComposite.setMinSize(elementContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT).x,
1172 elementContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT).y - 1);
1173 group.getParent().layout();
1174 }
1175 }
1176
1177 private void dispose() {
1178 group.dispose();
1179 }
1180
1181 private void extractInputs() {
1182 inputElement.elementName = elementNameText.getText().trim();
1183 if (inputElement.parentElement != null) {
1184 inputElement.logEntry = logEntryButton.getSelection();
1185 if (tagCombo.getText().equals(CustomTraceDefinition.TAG_OTHER)) {
1186 inputElement.inputName = tagText.getText().trim();
1187 } else {
1188 inputElement.inputName = tagCombo.getText();
1189 if (tagCombo.getText().equals(CustomTraceDefinition.TAG_TIMESTAMP)) {
1190 inputElement.inputFormat = tagText.getText().trim();
1191 }
1192 }
1193 inputElement.inputAction = actionCombo.getSelectionIndex();
1194 }
1195 inputElement.attributes = new ArrayList<InputAttribute>(attributes.size());
1196 for (int i = 0; i < attributes.size(); i++) {
1197 Attribute attribute = attributes.get(i);
1198 InputAttribute inputAttribute = new InputAttribute();
1199 inputAttribute.attributeName = attribute.attributeNameText.getText().trim();
1200 if (attribute.tagCombo.getText().equals(CustomTraceDefinition.TAG_OTHER)) {
1201 inputAttribute.inputName = attribute.tagText.getText().trim();
1202 } else {
1203 inputAttribute.inputName = attribute.tagCombo.getText();
1204 if (attribute.tagCombo.getText().equals(CustomTraceDefinition.TAG_TIMESTAMP)) {
1205 inputAttribute.inputFormat = attribute.tagText.getText().trim();
1206 }
1207 }
1208 inputAttribute.inputAction = attribute.actionCombo.getSelectionIndex();
1209 inputElement.addAttribute(inputAttribute);
1210 }
1211 }
1212 }
1213
1214 private class Attribute {
1215 ElementNode element;
1216 int attributeNumber;
1217
1218 // children of parent (must be disposed)
1219 Composite labelComposite;
1220 Composite attributeComposite;
1221 Label filler;
1222 Composite tagComposite;
1223
1224 // children of labelComposite
1225 Label attributeLabel;
1226
1227 // children of attributeComposite
1228 Text attributeNameText;
1229 Text previewText;
1230
1231 // children of tagComposite
1232 Combo tagCombo;
1233 Label tagLabel;
1234 Text tagText;
1235 Combo actionCombo;
1236
1237 public Attribute(Composite parent, ElementNode element, InputAttribute inputAttribute, int attributeNumber) {
1238 this.element = element;
1239 this.attributeNumber = attributeNumber;
1240
1241 labelComposite = new Composite(parent, SWT.FILL);
1242 GridLayout labelLayout = new GridLayout(2, false);
1243 labelLayout.marginWidth = 0;
1244 labelLayout.marginHeight = 0;
1245 labelComposite.setLayout(labelLayout);
1246 labelComposite.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
1247
1248 Button deleteButton = new Button(labelComposite, SWT.PUSH);
1249 deleteButton.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
1250 deleteButton.setImage(deleteImage);
1251 deleteButton.setToolTipText(Messages.CustomXmlParserInputWizardPage_removeAttribute);
1252 deleteButton.addSelectionListener(new SelectionAdapter() {
1253 @Override
1254 public void widgetSelected(SelectionEvent e) {
1255 Attribute.this.element.removeAttribute(Attribute.this.attributeNumber);
1256 validate();
1257 updatePreviews();
1258 }
1259 });
1260
1261 attributeLabel = new Label(labelComposite, SWT.NULL);
1262 attributeLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
1263 attributeLabel.setText(Messages.CustomXmlParserInputWizardPage_attibute);
1264
1265 attributeComposite = new Composite(parent, SWT.FILL);
1266 GridLayout attributeLayout = new GridLayout(4, false);
1267 attributeLayout.marginWidth = 0;
1268 attributeLayout.marginHeight = 0;
1269 attributeComposite.setLayout(attributeLayout);
1270 attributeComposite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
1271
1272 Label nameLabel = new Label(attributeComposite, SWT.NONE);
1273 nameLabel.setText(Messages.CustomXmlParserInputWizardPage_name);
1274
1275 attributeNameText = new Text(attributeComposite, SWT.BORDER | SWT.SINGLE);
1276 attributeNameText.setLayoutData(new GridData(120, SWT.DEFAULT));
1277 attributeNameText.setText(inputAttribute.attributeName);
1278 attributeNameText.addModifyListener(updateListener);
1279
1280 Label previewLabel = new Label(attributeComposite, SWT.NONE);
1281 previewLabel.setText(Messages.CustomXmlParserInputWizardPage_preview);
1282
1283 previewText = new Text(attributeComposite, SWT.BORDER | SWT.SINGLE | SWT.READ_ONLY);
1284 GridData gd = new GridData(SWT.FILL, SWT.CENTER, true, false);
1285 gd.widthHint = 0;
1286 previewText.setLayoutData(gd);
1287 previewText.setText(Messages.CustomXmlParserInputWizardPage_noMatch);
1288 previewText.setBackground(COLOR_WIDGET_BACKGROUND);
1289
1290 filler = new Label(parent, SWT.NULL);
1291
1292 tagComposite = new Composite(parent, SWT.FILL);
1293 GridLayout tagLayout = new GridLayout(4, false);
1294 tagLayout.marginWidth = 0;
1295 tagLayout.marginHeight = 0;
1296 tagComposite.setLayout(tagLayout);
1297 tagComposite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
1298
1299 tagCombo = new Combo(tagComposite, SWT.DROP_DOWN | SWT.READ_ONLY);
1300 tagCombo.setItems(new String[] { CustomTraceDefinition.TAG_TIMESTAMP, CustomTraceDefinition.TAG_MESSAGE,
1301 CustomTraceDefinition.TAG_OTHER });
1302 tagCombo.select(2); // Other
1303 tagCombo.addSelectionListener(new SelectionListener() {
1304 @Override
1305 public void widgetDefaultSelected(SelectionEvent e) {
1306 }
1307
1308 @Override
1309 public void widgetSelected(SelectionEvent e) {
1310 tagText.removeModifyListener(updateListener);
1311 switch (tagCombo.getSelectionIndex()) {
1312 case 0: // Time Stamp
1313 tagLabel.setText(Messages.CustomXmlParserInputWizardPage_format);
1314 tagLabel.setVisible(true);
1315 tagText.setVisible(true);
1316 tagText.addModifyListener(updateListener);
1317 break;
1318 case 1: // Message
1319 tagLabel.setVisible(false);
1320 tagText.setVisible(false);
1321 break;
1322 case 2: // Other
1323 tagLabel.setText(Messages.CustomXmlParserInputWizardPage_tagName);
1324 tagLabel.setVisible(true);
1325 if (tagText.getText().trim().length() == 0) {
1326 tagText.setText(attributeNameText.getText().trim());
1327 }
1328 tagText.setVisible(true);
1329 tagText.addModifyListener(updateListener);
1330 break;
1331 default:
1332 break;
1333 }
1334 tagComposite.layout();
1335 validate();
1336 updatePreviews();
1337 }
1338 });
1339
1340 tagLabel = new Label(tagComposite, SWT.NULL);
1341 tagLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
1342
1343 tagText = new Text(tagComposite, SWT.BORDER | SWT.SINGLE);
1344 gd = new GridData(SWT.FILL, SWT.CENTER, true, false);
1345 gd.widthHint = 0;
1346 tagText.setLayoutData(gd);
1347 tagText.setText(attributeNameText.getText());
1348
1349 actionCombo = new Combo(tagComposite, SWT.DROP_DOWN | SWT.READ_ONLY);
1350 actionCombo.setItems(new String[] { Messages.CustomXmlParserInputWizardPage_set, Messages.CustomXmlParserInputWizardPage_append,
1351 Messages.CustomXmlParserInputWizardPage_appendWith });
1352 actionCombo.select(inputAttribute.inputAction);
1353 actionCombo.addSelectionListener(updateListener);
1354
1355 if (inputAttribute.inputName.equals(CustomTraceDefinition.TAG_TIMESTAMP)) {
1356 tagCombo.select(0);
1357 tagLabel.setText(Messages.CustomXmlParserInputWizardPage_format);
1358 tagText.setText(inputAttribute.inputFormat);
1359 tagText.addModifyListener(updateListener);
1360 } else if (inputAttribute.inputName.equals(CustomTraceDefinition.TAG_MESSAGE)) {
1361 tagCombo.select(1);
1362 tagLabel.setVisible(false);
1363 tagText.setVisible(false);
1364 } else {
1365 tagCombo.select(2);
1366 tagLabel.setText(Messages.CustomXmlParserInputWizardPage_tagName);
1367 tagText.setText(inputAttribute.inputName);
1368 tagText.addModifyListener(updateListener);
1369 }
1370 }
1371
1372 private void dispose() {
1373 labelComposite.dispose();
1374 attributeComposite.dispose();
1375 filler.dispose();
1376 tagComposite.dispose();
1377 }
1378
1379 private void setAttributeNumber(int attributeNumber) {
1380 this.attributeNumber = attributeNumber;
1381 labelComposite.layout();
1382 }
1383 }
1384
1385 private Element getPreviewElement(InputElement inputElement) {
41b5c37f 1386 InputElement currentElement = inputElement;
be222f56
PT
1387 Element element = documentElement;
1388 if (element != null) {
1389 if (!documentElement.getNodeName().equals(definition.rootInputElement.elementName)) {
1390 return null;
1391 }
1392 ArrayList<String> elementNames = new ArrayList<String>();
41b5c37f
AM
1393 while (currentElement != null) {
1394 elementNames.add(currentElement.elementName);
1395 currentElement = currentElement.parentElement;
be222f56
PT
1396 }
1397 for (int i = elementNames.size() - 1; --i >= 0;) {
1398 NodeList childList = element.getChildNodes();
1399 element = null;
1400 for (int j = 0; j < childList.getLength(); j++) {
1401 Node child = childList.item(j);
1402 if (child instanceof Element && child.getNodeName().equals(elementNames.get(i))) {
1403 element = (Element) child;
1404 break;
1405 }
1406 }
1407 if (element == null) {
1408 break;
1409 }
1410 }
1411 if (element != null) {
1412 return element;
1413 }
1414 }
1415 return null;
1416 }
1417
1418 private String getChildNameSuggestion(InputElement inputElement) {
1419 if (inputElement == null) {
1420 if (documentElement != null) {
1421 return documentElement.getNodeName();
1422 }
1423 } else {
1424 Element element = getPreviewElement(inputElement);
1425 if (element != null) {
1426 NodeList childNodes = element.getChildNodes();
1427 for (int i = 0; i < childNodes.getLength(); i++) {
1428 Node node = childNodes.item(i);
1429 if (node instanceof Element) {
1430 boolean unused = true;
1431 if (inputElement.childElements != null) {
1432 for (InputElement child : inputElement.childElements) {
1433 if (child.elementName.equals(node.getNodeName())) {
1434 unused = false;
1435 break;
1436 }
1437 }
1438 }
1439 if (unused) {
1440 return node.getNodeName();
1441 }
1442 }
1443 }
1444 }
1445 }
1446 return ""; //$NON-NLS-1$
1447 }
1448
1449 private String getAttributeNameSuggestion(InputElement inputElement) {
1450 Element element = getPreviewElement(inputElement);
1451 if (element != null) {
1452 NamedNodeMap attributeMap = element.getAttributes();
1453 for (int i = 0; i < attributeMap.getLength(); i++) {
1454 Node node = attributeMap.item(i);
1455 boolean unused = true;
1456 if (inputElement.attributes != null) {
1457 for (InputAttribute attribute : inputElement.attributes) {
1458 if (attribute.attributeName.equals(node.getNodeName())) {
1459 unused = false;
1460 break;
1461 }
1462 }
1463 }
1464 if (unused) {
1465 return node.getNodeName();
1466 }
1467 }
1468 }
1469 return ""; //$NON-NLS-1$
1470 }
1471
1472 private void validate() {
1473 definition.definitionName = logtypeText.getText().trim();
1474 definition.timeStampOutputFormat = timeStampOutputFormatText.getText().trim();
1475
1476 if (selectedElement != null) {
1477 selectedElement.extractInputs();
1478 treeViewer.refresh();
1479 }
1480
1481 StringBuffer errors = new StringBuffer();
1482
1483 if (definition.definitionName.length() == 0) {
1484 errors.append(Messages.CustomXmlParserInputWizardPage_emptyLogTypeError);
1485 logtypeText.setBackground(COLOR_LIGHT_RED);
1486 } else {
1487 logtypeText.setBackground(COLOR_TEXT_BACKGROUND);
1488 for (CustomXmlTraceDefinition def : CustomXmlTraceDefinition.loadAll()) {
1489 if (definition.definitionName.equals(def.definitionName)) {
1490 if (editDefinitionName == null || !editDefinitionName.equals(definition.definitionName)) {
1491 errors.append(Messages.CustomXmlParserInputWizardPage_duplicatelogTypeError);
1492 logtypeText.setBackground(COLOR_LIGHT_RED);
1493 break;
1494 }
1495 }
1496 }
1497 }
1498
1499 if (definition.rootInputElement == null) {
1500 errors.append(Messages.CustomXmlParserInputWizardPage_noDocumentError);
1501 }
1502
1503 if (definition.rootInputElement != null) {
1504 logEntryFound = false;
1505 timeStampFound = false;
1506
1507 errors.append(validateElement(definition.rootInputElement));
1508
1509 if ((definition.rootInputElement.attributes != null && definition.rootInputElement.attributes.size() != 0)
1510 || (definition.rootInputElement.childElements != null && definition.rootInputElement.childElements.size() != 0)
1511 || errors.length() == 0) {
1512 if (!logEntryFound) {
1513 errors.append(Messages.CustomXmlParserInputWizardPage_missingLogEntryError);
1514 }
1515
1516 if (timeStampFound) {
1517 if (timeStampOutputFormatText.getText().trim().length() == 0) {
1518 errors.append(Messages.CustomXmlParserInputWizardPage_missingTimestampFmtError);
1519 timeStampOutputFormatText.setBackground(COLOR_LIGHT_RED);
1520 } else {
1521 try {
1522 new SimpleDateFormat(timeStampOutputFormatText.getText().trim());
1523 timeStampOutputFormatText.setBackground(COLOR_TEXT_BACKGROUND);
1524 } catch (IllegalArgumentException e) {
1525 errors.append(Messages.CustomXmlParserInputWizardPage_invalidTimestampFmtError);
1526 timeStampOutputFormatText.setBackground(COLOR_LIGHT_RED);
1527 }
1528 }
1529 } else {
1530 timeStampPreviewText.setText(Messages.CustomXmlParserInputWizardPage_notimestamporAttributeError);
1531 }
1532 }
1533 } else {
1534 timeStampPreviewText.setText(Messages.CustomXmlParserInputWizardPage_notimestamporAttributeError);
1535 }
1536
1537 if (errors.length() == 0) {
1538 setDescription(defaultDescription);
1539 setPageComplete(true);
1540 } else {
1541 setDescription(errors.toString());
1542 setPageComplete(false);
1543 }
1544 }
1545
a0a88f65
AM
1546 /**
1547 * Clean up the specified XML element.
1548 *
1549 * @param inputElement
1550 * The element to clean up
1551 * @return The validated element
1552 */
be222f56
PT
1553 public StringBuffer validateElement(InputElement inputElement) {
1554 StringBuffer errors = new StringBuffer();
1555 ElementNode elementNode = null;
1556 if (selectedElement != null && selectedElement.inputElement.equals(inputElement)) {
1557 elementNode = selectedElement;
1558 }
1559 if (inputElement == definition.rootInputElement) {
1560 if (inputElement.elementName.length() == 0) {
1561 errors.append(Messages.CustomXmlParserInputWizardPage_missingDocumentElementError);
1562 if (elementNode != null) {
1563 elementNode.elementNameText.setBackground(COLOR_LIGHT_RED);
1564 }
1565 } else {
1566 if (elementNode != null) {
1567 elementNode.elementNameText.setBackground(COLOR_TEXT_BACKGROUND);
1568 }
1569 }
1570 }
1571 if (inputElement != definition.rootInputElement) {
1572 if (inputElement.logEntry) {
1573 logEntryFound = true;
1574 }
1575 if (inputElement.inputName.equals(CustomTraceDefinition.TAG_TIMESTAMP)) {
1576 timeStampFound = true;
1577 if (inputElement.inputFormat.length() == 0) {
1578 errors.append(Messages.CustomXmlParserInputWizardPage_timestampFormatPrompt
1579 + " (" + Messages.CustomXmlParserInputWizardPage_timestampElementPrompt + " " + getName(inputElement) + "). "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
1580 if (elementNode != null) {
1581 elementNode.tagText.setBackground(COLOR_LIGHT_RED);
1582 }
1583 } else {
1584 try {
1585 new SimpleDateFormat(inputElement.inputFormat);
1586 if (elementNode != null) {
1587 elementNode.tagText.setBackground(COLOR_TEXT_BACKGROUND);
1588 }
1589 } catch (IllegalArgumentException e) {
1590 errors.append(Messages.CustomXmlParserInputWizardPage_invalidTimestampFmtError
1591 + " (" + Messages.CustomXmlParserInputWizardPage_timestampElementPrompt + " " + getName(inputElement) + "). "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
1592 if (elementNode != null) {
1593 elementNode.tagText.setBackground(COLOR_LIGHT_RED);
1594 }
1595 }
1596 }
1597 } else if (inputElement.inputName.length() == 0) {
1598 errors.append(Messages.CustomXmlParserInputWizardPage_missingInputElementNameError);
1599 if (elementNode != null) {
1600 elementNode.tagText.setBackground(COLOR_LIGHT_RED);
1601 }
1602 } else {
1603 if (elementNode != null) {
1604 elementNode.tagText.setBackground(COLOR_TEXT_BACKGROUND);
1605 }
1606 }
1607 }
1608 if (inputElement.attributes != null) {
1609 if (elementNode != null) {
1610 for (Attribute attribute : elementNode.attributes) {
1611 attribute.attributeNameText.setBackground(COLOR_TEXT_BACKGROUND);
1612 }
1613 }
1614 for (int i = 0; i < inputElement.attributes.size(); i++) {
1615 InputAttribute attribute = inputElement.attributes.get(i);
1616 boolean duplicate = false;
1617 for (int j = i + 1; j < inputElement.attributes.size(); j++) {
1618 InputAttribute otherAttribute = inputElement.attributes.get(j);
1619 if (otherAttribute.attributeName.equals(attribute.attributeName)) {
1620 duplicate = true;
1621 if (elementNode != null) {
1622 elementNode.attributes.get(j).attributeNameText.setBackground(COLOR_LIGHT_RED);
1623 }
1624 }
1625 }
1626 if (attribute.attributeName.length() == 0) {
1627 errors.append(Messages.CustomXmlParserInputWizardPage_missingAttribute
1628 + " (" + Messages.CustomXmlParserInputWizardPage_attributePrompt + " " + getName(inputElement) + ": ?). "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
1629 if (elementNode != null) {
1630 elementNode.attributes.get(i).attributeNameText.setBackground(COLOR_LIGHT_RED);
1631 }
1632 } else if (duplicate) {
1633 errors.append(Messages.CustomXmlParserInputWizardPage_duplicateAttributeError
1634 + " (" + Messages.CustomXmlParserInputWizardPage_attributePrompt + " " + getName(attribute, inputElement) + "). "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
1635 if (elementNode != null) {
1636 elementNode.attributes.get(i).attributeNameText.setBackground(COLOR_LIGHT_RED);
1637 }
1638 }
1639 if (attribute.inputName.equals(CustomTraceDefinition.TAG_TIMESTAMP)) {
1640 timeStampFound = true;
1641 if (attribute.inputFormat.length() == 0) {
1642 errors.append(Messages.CustomXmlParserInputWizardPage_missingTimestampInFmtError
1643 + " (" + Messages.CustomXmlParserInputWizardPage_attributePrompt + " " + getName(attribute, inputElement) + "). "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
1644 if (elementNode != null) {
1645 elementNode.attributes.get(i).tagText.setBackground(COLOR_LIGHT_RED);
1646 }
1647 } else {
1648 try {
1649 new SimpleDateFormat(attribute.inputFormat);
1650 if (elementNode != null) {
1651 elementNode.attributes.get(i).tagText.setBackground(COLOR_TEXT_BACKGROUND);
1652 }
1653 } catch (IllegalArgumentException e) {
1654 errors.append(Messages.CustomXmlParserInputWizardPage_invalidTimestampInFmtError
1655 + " (" + Messages.CustomXmlParserInputWizardPage_attributePrompt + " " + getName(attribute, inputElement) + "). "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
1656 if (elementNode != null) {
1657 elementNode.attributes.get(i).tagText.setBackground(COLOR_LIGHT_RED);
1658 }
1659 }
1660 }
1661 } else if (attribute.inputName.length() == 0) {
1662 errors.append(Messages.CustomXmlParserInputWizardPage_missingDataGroupNameError
1663 + " (" + Messages.CustomXmlParserInputWizardPage_attributePrompt + " " + getName(attribute, inputElement) + "). "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
1664 if (elementNode != null) {
1665 elementNode.attributes.get(i).tagText.setBackground(COLOR_LIGHT_RED);
1666 }
1667 } else {
1668 if (elementNode != null) {
1669 elementNode.attributes.get(i).tagText.setBackground(COLOR_TEXT_BACKGROUND);
1670 }
1671 }
1672 }
1673 }
1674 if (inputElement.childElements != null) {
1675 for (InputElement child : inputElement.childElements) {
1676 ElementNode childElementNode = null;
1677 if (selectedElement != null && selectedElement.inputElement.equals(child)) {
1678 childElementNode = selectedElement;
1679 }
1680 if (childElementNode != null) {
1681 childElementNode.elementNameText.setBackground(COLOR_TEXT_BACKGROUND);
1682 }
1683 }
1684 for (int i = 0; i < inputElement.childElements.size(); i++) {
1685 InputElement child = inputElement.childElements.get(i);
1686 ElementNode childElementNode = null;
1687 if (selectedElement != null && selectedElement.inputElement.equals(child)) {
1688 childElementNode = selectedElement;
1689 }
1690 if (child.elementName.length() == 0) {
1691 errors.append(Messages.CustomXmlParserInputWizardPage_missingElementNameError
1692 + " (" + Messages.CustomXmlParserInputWizardPage_attributePrompt + " " + getName(child) + "). "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
1693 if (childElementNode != null) {
1694 childElementNode.elementNameText.setBackground(COLOR_LIGHT_RED);
1695 }
1696 } else {
1697 boolean duplicate = false;
1698 for (int j = i + 1; j < inputElement.childElements.size(); j++) {
1699 InputElement otherChild = inputElement.childElements.get(j);
1700 if (otherChild.elementName.equals(child.elementName)) {
1701 duplicate = true;
1702 ElementNode otherChildElementNode = null;
1703 if (selectedElement != null && selectedElement.inputElement.equals(otherChild)) {
1704 otherChildElementNode = selectedElement;
1705 }
1706 if (otherChildElementNode != null) {
1707 otherChildElementNode.elementNameText.setBackground(COLOR_LIGHT_RED);
1708 }
1709 }
1710 }
1711 if (duplicate) {
1712 errors.append(Messages.CustomXmlParserInputWizardPage_duplicateElementNameError
1713 + " (" + Messages.CustomXmlParserInputWizardPage_attributePrompt + " " + getName(child) + "). "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
1714 if (childElementNode != null) {
1715 childElementNode.elementNameText.setBackground(COLOR_LIGHT_RED);
1716 }
1717 }
1718 }
1719
1720 errors.append(validateElement(child));
1721 }
1722 }
1723 return errors;
1724 }
1725
a0a88f65
AM
1726 /**
1727 * Get the trace definition.
1728 *
1729 * @return The trace definition
1730 */
be222f56
PT
1731 public CustomXmlTraceDefinition getDefinition() {
1732 return definition;
1733 }
1734
a0a88f65
AM
1735 /**
1736 * Get the raw text input.
1737 *
1738 * @return The raw text input.
1739 */
be222f56
PT
1740 public char[] getInputText() {
1741 return inputText.getText().toCharArray();
1742 }
1743}
This page took 0.099396 seconds and 5 git commands to generate.