tmf: Add missing Javadoc to tmf.ui
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / internal / tmf / ui / parsers / wizards / CustomXmlParserInputWizardPage.java
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
13 package org.eclipse.linuxtools.internal.tmf.ui.parsers.wizards;
14
15 import java.io.BufferedReader;
16 import java.io.ByteArrayInputStream;
17 import java.io.IOException;
18 import java.io.InputStream;
19 import java.io.InputStreamReader;
20 import java.text.ParseException;
21 import java.text.SimpleDateFormat;
22 import java.util.ArrayList;
23 import java.util.Date;
24 import java.util.List;
25
26 import javax.xml.parsers.DocumentBuilder;
27 import javax.xml.parsers.DocumentBuilderFactory;
28 import javax.xml.parsers.ParserConfigurationException;
29
30 import org.eclipse.core.resources.IFile;
31 import org.eclipse.core.runtime.CoreException;
32 import org.eclipse.jface.viewers.AbstractTreeViewer;
33 import org.eclipse.jface.viewers.ColumnLabelProvider;
34 import org.eclipse.jface.viewers.ISelection;
35 import org.eclipse.jface.viewers.ISelectionChangedListener;
36 import org.eclipse.jface.viewers.IStructuredSelection;
37 import org.eclipse.jface.viewers.ITreeContentProvider;
38 import org.eclipse.jface.viewers.SelectionChangedEvent;
39 import org.eclipse.jface.viewers.StructuredSelection;
40 import org.eclipse.jface.viewers.TreeViewer;
41 import org.eclipse.jface.viewers.Viewer;
42 import org.eclipse.jface.wizard.WizardPage;
43 import org.eclipse.linuxtools.internal.tmf.ui.Activator;
44 import org.eclipse.linuxtools.internal.tmf.ui.Messages;
45 import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomTraceDefinition;
46 import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomXmlTrace;
47 import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomXmlTraceDefinition;
48 import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomXmlTraceDefinition.InputAttribute;
49 import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomXmlTraceDefinition.InputElement;
50 import org.eclipse.swt.SWT;
51 import org.eclipse.swt.browser.Browser;
52 import org.eclipse.swt.browser.TitleEvent;
53 import org.eclipse.swt.browser.TitleListener;
54 import org.eclipse.swt.custom.SashForm;
55 import org.eclipse.swt.custom.ScrolledComposite;
56 import org.eclipse.swt.custom.StyleRange;
57 import org.eclipse.swt.custom.StyledText;
58 import org.eclipse.swt.events.ModifyEvent;
59 import org.eclipse.swt.events.ModifyListener;
60 import org.eclipse.swt.events.SelectionAdapter;
61 import org.eclipse.swt.events.SelectionEvent;
62 import org.eclipse.swt.events.SelectionListener;
63 import org.eclipse.swt.graphics.Color;
64 import org.eclipse.swt.graphics.Font;
65 import org.eclipse.swt.graphics.FontData;
66 import org.eclipse.swt.graphics.Image;
67 import org.eclipse.swt.layout.FillLayout;
68 import org.eclipse.swt.layout.GridData;
69 import org.eclipse.swt.layout.GridLayout;
70 import org.eclipse.swt.widgets.Button;
71 import org.eclipse.swt.widgets.Combo;
72 import org.eclipse.swt.widgets.Composite;
73 import org.eclipse.swt.widgets.Display;
74 import org.eclipse.swt.widgets.Group;
75 import org.eclipse.swt.widgets.Label;
76 import org.eclipse.swt.widgets.Shell;
77 import org.eclipse.swt.widgets.Text;
78 import org.w3c.dom.Document;
79 import org.w3c.dom.Element;
80 import org.w3c.dom.NamedNodeMap;
81 import org.w3c.dom.Node;
82 import org.w3c.dom.NodeList;
83 import org.xml.sax.EntityResolver;
84 import org.xml.sax.ErrorHandler;
85 import org.xml.sax.InputSource;
86 import org.xml.sax.SAXException;
87 import org.xml.sax.SAXParseException;
88
89 /**
90 * Input wizard page for custom XML trace parsers.
91 *
92 * @author Patrick Tassé
93 */
94 public 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
145 /**
146 * Constructor
147 *
148 * @param selection
149 * Selection object
150 * @param definition
151 * Trace definition
152 */
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) {
554 IStructuredSelection selection = (IStructuredSelection) event.getSelection();
555 InputElement inputElement = (InputElement) selection.getFirstElement();
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
639 /**
640 * Get the global list of input names.
641 *
642 * @return The list of input names
643 */
644 public List<String> getInputNames() {
645 return getInputNames(definition.rootInputElement);
646 }
647
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 */
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) {
695 Object selection = ((IStructuredSelection) this.selection).getFirstElement();
696 if (selection instanceof IFile) {
697 IFile file = (IFile) selection;
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
776 private void updatePreviews() {
777 updatePreviews(false);
778 }
779
780 private void initValues() {
781 timeStampValue = null;
782 timeStampFormat = null;
783 logEntriesCount = 0;
784 logEntryFound = false;
785 }
786
787 private void updatePreviews(boolean updateAll) {
788 if (inputText == null) {
789 // early update during construction
790 return;
791 }
792 inputText.setStyleRanges(new StyleRange[] {});
793 if (selectedElement == null) {
794 return;
795 }
796
797 initValues();
798
799 selectedElement.updatePreview();
800
801 if (timeStampValue != null && timeStampFormat != null) {
802 try {
803 SimpleDateFormat dateFormat = new SimpleDateFormat(timeStampFormat);
804 Date date = dateFormat.parse(timeStampValue);
805 dateFormat = new SimpleDateFormat(timeStampOutputFormatText.getText().trim());
806 timeStampPreviewText.setText(dateFormat.format(date));
807 } catch (ParseException e) {
808 timeStampPreviewText.setText("*parse exception* [" + timeStampValue + "] <> [" + timeStampFormat + "]"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
809 } catch (IllegalArgumentException e) {
810 timeStampPreviewText.setText("*parse exception* [Illegal Argument]"); //$NON-NLS-1$
811 }
812 } else {
813 timeStampPreviewText.setText("*no matching time stamp*"); //$NON-NLS-1$
814 }
815 }
816
817 private void openHelpShell(String url) {
818 if (helpBrowser != null && !helpBrowser.isDisposed()) {
819 helpBrowser.getShell().setActive();
820 if (!helpBrowser.getUrl().equals(url)) {
821 helpBrowser.setUrl(url);
822 }
823 return;
824 }
825 final Shell helpShell = new Shell(getShell(), SWT.SHELL_TRIM);
826 helpShell.setLayout(new FillLayout());
827 helpBrowser = new Browser(helpShell, SWT.NONE);
828 helpBrowser.addTitleListener(new TitleListener() {
829 @Override
830 public void changed(TitleEvent event) {
831 helpShell.setText(event.title);
832 }
833 });
834 helpBrowser.setBounds(0, 0, 600, 400);
835 helpShell.pack();
836 helpShell.open();
837 helpBrowser.setUrl(url);
838 }
839
840 private class UpdateListener implements ModifyListener, SelectionListener {
841
842 @Override
843 public void modifyText(ModifyEvent e) {
844 validate();
845 updatePreviews();
846 }
847
848 @Override
849 public void widgetDefaultSelected(SelectionEvent e) {
850 validate();
851 updatePreviews();
852 }
853
854 @Override
855 public void widgetSelected(SelectionEvent e) {
856 validate();
857 updatePreviews();
858 }
859
860 }
861
862 private class ElementNode {
863 final InputElement inputElement;
864 final Group group;
865 List<Attribute> attributes = new ArrayList<Attribute>();
866 List<ElementNode> childElements = new ArrayList<ElementNode>();
867 Text elementNameText;
868 Composite tagComposite;
869 Combo tagCombo;
870 Label tagLabel;
871 Text tagText;
872 Combo actionCombo;
873 Label previewLabel;
874 Text previewText;
875 Button logEntryButton;
876 Label fillerLabel;
877 Composite addAttributeComposite;
878 Button addAttributeButton;
879 Label addAttributeLabel;
880
881 public ElementNode(Composite parent, InputElement inputElement) {
882 this.inputElement = inputElement;
883
884 group = new Group(parent, SWT.NONE);
885 GridLayout gl = new GridLayout(2, false);
886 gl.marginHeight = 0;
887 group.setLayout(gl);
888 group.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
889 group.setText(getName(inputElement));
890
891 Label label = new Label(group, SWT.NULL);
892 label.setText(Messages.CustomXmlParserInputWizardPage_elementName);
893 label.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
894
895 elementNameText = new Text(group, SWT.BORDER | SWT.SINGLE);
896 GridData gd = new GridData(SWT.FILL, SWT.CENTER, true, false);
897 gd.widthHint = 0;
898 elementNameText.setLayoutData(gd);
899 elementNameText.addModifyListener(new ModifyListener() {
900 @Override
901 public void modifyText(ModifyEvent e) {
902 ElementNode.this.inputElement.elementName = elementNameText.getText().trim();
903 group.setText(getName(ElementNode.this.inputElement));
904 }
905 });
906 elementNameText.setText(inputElement.elementName);
907 elementNameText.addModifyListener(updateListener);
908
909 if (inputElement.parentElement != null) {
910 previewLabel = new Label(group, SWT.NULL);
911 previewLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
912 previewLabel.setText(Messages.CustomXmlParserInputWizardPage_preview);
913
914 previewText = new Text(group, SWT.BORDER | SWT.SINGLE | SWT.READ_ONLY);
915 gd = new GridData(SWT.FILL, SWT.CENTER, true, false);
916 gd.widthHint = 0;
917 previewText.setLayoutData(gd);
918 previewText.setText(Messages.CustomXmlParserInputWizardPage_noMatchingElement);
919 previewText.setBackground(COLOR_WIDGET_BACKGROUND);
920
921 logEntryButton = new Button(group, SWT.CHECK);
922 logEntryButton.setText(Messages.CustomXmlParserInputWizardPage_logEntry);
923 logEntryButton.setSelection(inputElement.logEntry);
924 logEntryButton.addSelectionListener(new SelectionListener() {
925 @Override
926 public void widgetDefaultSelected(SelectionEvent e) {
927 }
928
929 @Override
930 public void widgetSelected(SelectionEvent e) {
931 InputElement parent = ElementNode.this.inputElement.parentElement;
932 while (parent != null) {
933 parent.logEntry = false;
934 parent = parent.parentElement;
935 }
936 }
937 });
938 logEntryButton.addSelectionListener(updateListener);
939
940 tagComposite = new Composite(group, SWT.FILL);
941 GridLayout tagLayout = new GridLayout(4, false);
942 tagLayout.marginWidth = 0;
943 tagLayout.marginHeight = 0;
944 tagComposite.setLayout(tagLayout);
945 tagComposite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
946
947 tagCombo = new Combo(tagComposite, SWT.DROP_DOWN | SWT.READ_ONLY);
948 tagCombo.setItems(new String[] { CustomXmlTraceDefinition.TAG_IGNORE, CustomTraceDefinition.TAG_TIMESTAMP,
949 CustomTraceDefinition.TAG_MESSAGE, CustomTraceDefinition.TAG_OTHER });
950 tagCombo.setVisibleItemCount(tagCombo.getItemCount());
951 tagCombo.addSelectionListener(new SelectionListener() {
952 @Override
953 public void widgetDefaultSelected(SelectionEvent e) {
954 }
955
956 @Override
957 public void widgetSelected(SelectionEvent e) {
958 tagText.removeModifyListener(updateListener);
959 switch (tagCombo.getSelectionIndex()) {
960 case 0: // Ignore
961 tagLabel.setVisible(false);
962 tagText.setVisible(false);
963 actionCombo.setVisible(false);
964 break;
965 case 1: // Time Stamp
966 tagLabel.setText(Messages.CustomXmlParserInputWizardPage_format);
967 tagLabel.setVisible(true);
968 tagText.setVisible(true);
969 tagText.addModifyListener(updateListener);
970 actionCombo.setVisible(true);
971 break;
972 case 2: // Message
973 tagLabel.setVisible(false);
974 tagText.setVisible(false);
975 actionCombo.setVisible(true);
976 break;
977 case 3: // Other
978 tagLabel.setText(Messages.CustomXmlParserInputWizardPage_tagName);
979 tagLabel.setVisible(true);
980 if (tagText.getText().trim().length() == 0) {
981 tagText.setText(elementNameText.getText().trim());
982 }
983 tagText.setVisible(true);
984 tagText.addModifyListener(updateListener);
985 actionCombo.setVisible(true);
986 break;
987 default:
988 break;
989 }
990 tagComposite.layout();
991 validate();
992 updatePreviews();
993 }
994 });
995
996 tagLabel = new Label(tagComposite, SWT.NULL);
997 tagLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
998
999 tagText = new Text(tagComposite, SWT.BORDER | SWT.SINGLE);
1000 gd = new GridData(SWT.FILL, SWT.CENTER, true, false);
1001 gd.widthHint = 0;
1002 tagText.setLayoutData(gd);
1003
1004 actionCombo = new Combo(tagComposite, SWT.DROP_DOWN | SWT.READ_ONLY);
1005 actionCombo.setItems(new String[] { Messages.CustomXmlParserInputWizardPage_set, Messages.CustomXmlParserInputWizardPage_append,
1006 Messages.CustomXmlParserInputWizardPage_appendWith });
1007 actionCombo.select(inputElement.inputAction);
1008 actionCombo.addSelectionListener(updateListener);
1009
1010 if (inputElement.inputName.equals(CustomXmlTraceDefinition.TAG_IGNORE)) {
1011 tagCombo.select(0);
1012 tagLabel.setVisible(false);
1013 tagText.setVisible(false);
1014 actionCombo.setVisible(false);
1015 } else if (inputElement.inputName.equals(CustomTraceDefinition.TAG_TIMESTAMP)) {
1016 tagCombo.select(1);
1017 tagLabel.setText(Messages.CustomXmlParserInputWizardPage_format);
1018 tagText.setText(inputElement.inputFormat);
1019 tagText.addModifyListener(updateListener);
1020 } else if (inputElement.inputName.equals(CustomTraceDefinition.TAG_MESSAGE)) {
1021 tagCombo.select(2);
1022 tagLabel.setVisible(false);
1023 tagText.setVisible(false);
1024 } else {
1025 tagCombo.select(3);
1026 tagLabel.setText(Messages.CustomXmlParserInputWizardPage_tagName);
1027 tagText.setText(inputElement.inputName);
1028 tagText.addModifyListener(updateListener);
1029 }
1030 }
1031
1032 if (inputElement.attributes != null) {
1033 for (InputAttribute inputAttribute : inputElement.attributes) {
1034 Attribute attribute = new Attribute(group, this, inputAttribute, attributes.size() + 1);
1035 attributes.add(attribute);
1036 }
1037 }
1038
1039 createAddButton();
1040 }
1041
1042 private void updatePreview() {
1043 Element element = getPreviewElement(inputElement);
1044 if (inputElement.parentElement != null) { // no preview text for
1045 // document element
1046 previewText.setText(Messages.CustomXmlParserInputWizardPage_noMatchingElement);
1047 if (element != null) {
1048 previewText.setText(CustomXmlTrace.parseElement(element, new StringBuffer()).toString());
1049 if (logEntryButton.getSelection()) {
1050 if (!logEntryFound) {
1051 logEntryFound = true;
1052 logEntriesCount++;
1053 } else {
1054 logEntryButton.setSelection(false); // remove nested
1055 // log entry
1056 }
1057 }
1058 if (tagCombo.getText().equals(CustomTraceDefinition.TAG_TIMESTAMP) && logEntriesCount <= 1) {
1059 String value = previewText.getText().trim();
1060 if (value.length() != 0) {
1061 if (actionCombo.getSelectionIndex() == CustomTraceDefinition.ACTION_SET) {
1062 timeStampValue = value;
1063 timeStampFormat = tagText.getText().trim();
1064 } else if (actionCombo.getSelectionIndex() == CustomTraceDefinition.ACTION_APPEND) {
1065 if (timeStampValue != null) {
1066 timeStampValue += value;
1067 timeStampFormat += tagText.getText().trim();
1068 } else {
1069 timeStampValue = value;
1070 timeStampFormat = tagText.getText().trim();
1071 }
1072 } else if (actionCombo.getSelectionIndex() == CustomTraceDefinition.ACTION_APPEND_WITH_SEPARATOR) {
1073 if (timeStampValue != null) {
1074 timeStampValue += " | " + value; //$NON-NLS-1$
1075 timeStampFormat += " | " + tagText.getText().trim(); //$NON-NLS-1$
1076 } else {
1077 timeStampValue = value;
1078 timeStampFormat = tagText.getText().trim();
1079 }
1080 }
1081 }
1082 }
1083 }
1084 }
1085 for (Attribute attribute : attributes) {
1086 if (element != null) {
1087 String value = element.getAttribute(attribute.attributeNameText.getText().trim());
1088 if (value.length() != 0) {
1089 attribute.previewText.setText(value);
1090 if (attribute.tagCombo.getText().equals(CustomTraceDefinition.TAG_TIMESTAMP) && logEntriesCount <= 1) {
1091 if (attribute.actionCombo.getSelectionIndex() == CustomTraceDefinition.ACTION_SET) {
1092 timeStampValue = value;
1093 timeStampFormat = attribute.tagText.getText().trim();
1094 } else if (attribute.actionCombo.getSelectionIndex() == CustomTraceDefinition.ACTION_APPEND) {
1095 if (timeStampValue != null) {
1096 timeStampValue += value;
1097 timeStampFormat += attribute.tagText.getText().trim();
1098 } else {
1099 timeStampValue = value;
1100 timeStampFormat = attribute.tagText.getText().trim();
1101 }
1102 } else if (attribute.actionCombo.getSelectionIndex() == CustomTraceDefinition.ACTION_APPEND_WITH_SEPARATOR) {
1103 if (timeStampValue != null) {
1104 timeStampValue += " | " + value; //$NON-NLS-1$
1105 timeStampFormat += " | " + attribute.tagText.getText().trim(); //$NON-NLS-1$
1106 } else {
1107 timeStampValue = value;
1108 timeStampFormat = attribute.tagText.getText().trim();
1109 }
1110 }
1111 }
1112 } else {
1113 attribute.previewText.setText(Messages.CustomXmlParserInputWizardPage_noMatchingAttribute);
1114 }
1115 } else {
1116 attribute.previewText.setText(Messages.CustomXmlParserInputWizardPage_noMatchingElement);
1117 }
1118 }
1119 for (ElementNode child : childElements) {
1120 child.updatePreview();
1121 }
1122 if (logEntryButton != null && logEntryButton.getSelection()) {
1123 logEntryFound = false;
1124 }
1125 }
1126
1127 private void createAddButton() {
1128 fillerLabel = new Label(group, SWT.NONE);
1129
1130 addAttributeComposite = new Composite(group, SWT.NONE);
1131 addAttributeComposite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
1132 GridLayout addAttributeLayout = new GridLayout(2, false);
1133 addAttributeLayout.marginHeight = 0;
1134 addAttributeLayout.marginWidth = 0;
1135 addAttributeComposite.setLayout(addAttributeLayout);
1136
1137 addAttributeButton = new Button(addAttributeComposite, SWT.PUSH);
1138 addAttributeButton.setImage(addImage);
1139 addAttributeButton.setToolTipText(Messages.CustomXmlParserInputWizardPage_addAttribute);
1140 addAttributeButton.addSelectionListener(new SelectionAdapter() {
1141 @Override
1142 public void widgetSelected(SelectionEvent e) {
1143 removeAddButton();
1144 String attributeName = getAttributeNameSuggestion(inputElement);
1145 InputAttribute inputAttribute = new InputAttribute(attributeName, attributeName, 0, ""); //$NON-NLS-1$
1146 attributes.add(new Attribute(group, ElementNode.this, inputAttribute, attributes.size() + 1));
1147 createAddButton();
1148 elementContainer.layout();
1149 elementScrolledComposite.setMinSize(elementContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT).x,
1150 elementContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT).y - 1);
1151 group.getParent().layout();
1152 validate();
1153 updatePreviews();
1154 }
1155 });
1156
1157 addAttributeLabel = new Label(addAttributeComposite, SWT.NULL);
1158 addAttributeLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
1159 addAttributeLabel.setText(Messages.CustomXmlParserInputWizardPage_newAttibute);
1160 }
1161
1162 private void removeAddButton() {
1163 fillerLabel.dispose();
1164 addAttributeComposite.dispose();
1165 }
1166
1167 private void removeAttribute(int attributeNumber) {
1168 if (--attributeNumber < attributes.size()) {
1169 attributes.remove(attributeNumber).dispose();
1170 for (int i = attributeNumber; i < attributes.size(); i++) {
1171 attributes.get(i).setAttributeNumber(i + 1);
1172 }
1173 elementContainer.layout();
1174 elementScrolledComposite.setMinSize(elementContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT).x,
1175 elementContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT).y - 1);
1176 group.getParent().layout();
1177 }
1178 }
1179
1180 private void dispose() {
1181 group.dispose();
1182 }
1183
1184 private void extractInputs() {
1185 inputElement.elementName = elementNameText.getText().trim();
1186 if (inputElement.parentElement != null) {
1187 inputElement.logEntry = logEntryButton.getSelection();
1188 if (tagCombo.getText().equals(CustomTraceDefinition.TAG_OTHER)) {
1189 inputElement.inputName = tagText.getText().trim();
1190 } else {
1191 inputElement.inputName = tagCombo.getText();
1192 if (tagCombo.getText().equals(CustomTraceDefinition.TAG_TIMESTAMP)) {
1193 inputElement.inputFormat = tagText.getText().trim();
1194 }
1195 }
1196 inputElement.inputAction = actionCombo.getSelectionIndex();
1197 }
1198 inputElement.attributes = new ArrayList<InputAttribute>(attributes.size());
1199 for (int i = 0; i < attributes.size(); i++) {
1200 Attribute attribute = attributes.get(i);
1201 InputAttribute inputAttribute = new InputAttribute();
1202 inputAttribute.attributeName = attribute.attributeNameText.getText().trim();
1203 if (attribute.tagCombo.getText().equals(CustomTraceDefinition.TAG_OTHER)) {
1204 inputAttribute.inputName = attribute.tagText.getText().trim();
1205 } else {
1206 inputAttribute.inputName = attribute.tagCombo.getText();
1207 if (attribute.tagCombo.getText().equals(CustomTraceDefinition.TAG_TIMESTAMP)) {
1208 inputAttribute.inputFormat = attribute.tagText.getText().trim();
1209 }
1210 }
1211 inputAttribute.inputAction = attribute.actionCombo.getSelectionIndex();
1212 inputElement.addAttribute(inputAttribute);
1213 }
1214 }
1215 }
1216
1217 private class Attribute {
1218 ElementNode element;
1219 int attributeNumber;
1220
1221 // children of parent (must be disposed)
1222 Composite labelComposite;
1223 Composite attributeComposite;
1224 Label filler;
1225 Composite tagComposite;
1226
1227 // children of labelComposite
1228 Label attributeLabel;
1229
1230 // children of attributeComposite
1231 Text attributeNameText;
1232 Text previewText;
1233
1234 // children of tagComposite
1235 Combo tagCombo;
1236 Label tagLabel;
1237 Text tagText;
1238 Combo actionCombo;
1239
1240 public Attribute(Composite parent, ElementNode element, InputAttribute inputAttribute, int attributeNumber) {
1241 this.element = element;
1242 this.attributeNumber = attributeNumber;
1243
1244 labelComposite = new Composite(parent, SWT.FILL);
1245 GridLayout labelLayout = new GridLayout(2, false);
1246 labelLayout.marginWidth = 0;
1247 labelLayout.marginHeight = 0;
1248 labelComposite.setLayout(labelLayout);
1249 labelComposite.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
1250
1251 Button deleteButton = new Button(labelComposite, SWT.PUSH);
1252 deleteButton.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
1253 deleteButton.setImage(deleteImage);
1254 deleteButton.setToolTipText(Messages.CustomXmlParserInputWizardPage_removeAttribute);
1255 deleteButton.addSelectionListener(new SelectionAdapter() {
1256 @Override
1257 public void widgetSelected(SelectionEvent e) {
1258 Attribute.this.element.removeAttribute(Attribute.this.attributeNumber);
1259 validate();
1260 updatePreviews();
1261 }
1262 });
1263
1264 attributeLabel = new Label(labelComposite, SWT.NULL);
1265 attributeLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
1266 attributeLabel.setText(Messages.CustomXmlParserInputWizardPage_attibute);
1267
1268 attributeComposite = new Composite(parent, SWT.FILL);
1269 GridLayout attributeLayout = new GridLayout(4, false);
1270 attributeLayout.marginWidth = 0;
1271 attributeLayout.marginHeight = 0;
1272 attributeComposite.setLayout(attributeLayout);
1273 attributeComposite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
1274
1275 Label nameLabel = new Label(attributeComposite, SWT.NONE);
1276 nameLabel.setText(Messages.CustomXmlParserInputWizardPage_name);
1277
1278 attributeNameText = new Text(attributeComposite, SWT.BORDER | SWT.SINGLE);
1279 attributeNameText.setLayoutData(new GridData(120, SWT.DEFAULT));
1280 attributeNameText.setText(inputAttribute.attributeName);
1281 attributeNameText.addModifyListener(updateListener);
1282
1283 Label previewLabel = new Label(attributeComposite, SWT.NONE);
1284 previewLabel.setText(Messages.CustomXmlParserInputWizardPage_preview);
1285
1286 previewText = new Text(attributeComposite, SWT.BORDER | SWT.SINGLE | SWT.READ_ONLY);
1287 GridData gd = new GridData(SWT.FILL, SWT.CENTER, true, false);
1288 gd.widthHint = 0;
1289 previewText.setLayoutData(gd);
1290 previewText.setText(Messages.CustomXmlParserInputWizardPage_noMatch);
1291 previewText.setBackground(COLOR_WIDGET_BACKGROUND);
1292
1293 filler = new Label(parent, SWT.NULL);
1294
1295 tagComposite = new Composite(parent, SWT.FILL);
1296 GridLayout tagLayout = new GridLayout(4, false);
1297 tagLayout.marginWidth = 0;
1298 tagLayout.marginHeight = 0;
1299 tagComposite.setLayout(tagLayout);
1300 tagComposite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
1301
1302 tagCombo = new Combo(tagComposite, SWT.DROP_DOWN | SWT.READ_ONLY);
1303 tagCombo.setItems(new String[] { CustomTraceDefinition.TAG_TIMESTAMP, CustomTraceDefinition.TAG_MESSAGE,
1304 CustomTraceDefinition.TAG_OTHER });
1305 tagCombo.select(2); // Other
1306 tagCombo.addSelectionListener(new SelectionListener() {
1307 @Override
1308 public void widgetDefaultSelected(SelectionEvent e) {
1309 }
1310
1311 @Override
1312 public void widgetSelected(SelectionEvent e) {
1313 tagText.removeModifyListener(updateListener);
1314 switch (tagCombo.getSelectionIndex()) {
1315 case 0: // Time Stamp
1316 tagLabel.setText(Messages.CustomXmlParserInputWizardPage_format);
1317 tagLabel.setVisible(true);
1318 tagText.setVisible(true);
1319 tagText.addModifyListener(updateListener);
1320 break;
1321 case 1: // Message
1322 tagLabel.setVisible(false);
1323 tagText.setVisible(false);
1324 break;
1325 case 2: // Other
1326 tagLabel.setText(Messages.CustomXmlParserInputWizardPage_tagName);
1327 tagLabel.setVisible(true);
1328 if (tagText.getText().trim().length() == 0) {
1329 tagText.setText(attributeNameText.getText().trim());
1330 }
1331 tagText.setVisible(true);
1332 tagText.addModifyListener(updateListener);
1333 break;
1334 default:
1335 break;
1336 }
1337 tagComposite.layout();
1338 validate();
1339 updatePreviews();
1340 }
1341 });
1342
1343 tagLabel = new Label(tagComposite, SWT.NULL);
1344 tagLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
1345
1346 tagText = new Text(tagComposite, SWT.BORDER | SWT.SINGLE);
1347 gd = new GridData(SWT.FILL, SWT.CENTER, true, false);
1348 gd.widthHint = 0;
1349 tagText.setLayoutData(gd);
1350 tagText.setText(attributeNameText.getText());
1351
1352 actionCombo = new Combo(tagComposite, SWT.DROP_DOWN | SWT.READ_ONLY);
1353 actionCombo.setItems(new String[] { Messages.CustomXmlParserInputWizardPage_set, Messages.CustomXmlParserInputWizardPage_append,
1354 Messages.CustomXmlParserInputWizardPage_appendWith });
1355 actionCombo.select(inputAttribute.inputAction);
1356 actionCombo.addSelectionListener(updateListener);
1357
1358 if (inputAttribute.inputName.equals(CustomTraceDefinition.TAG_TIMESTAMP)) {
1359 tagCombo.select(0);
1360 tagLabel.setText(Messages.CustomXmlParserInputWizardPage_format);
1361 tagText.setText(inputAttribute.inputFormat);
1362 tagText.addModifyListener(updateListener);
1363 } else if (inputAttribute.inputName.equals(CustomTraceDefinition.TAG_MESSAGE)) {
1364 tagCombo.select(1);
1365 tagLabel.setVisible(false);
1366 tagText.setVisible(false);
1367 } else {
1368 tagCombo.select(2);
1369 tagLabel.setText(Messages.CustomXmlParserInputWizardPage_tagName);
1370 tagText.setText(inputAttribute.inputName);
1371 tagText.addModifyListener(updateListener);
1372 }
1373 }
1374
1375 private void dispose() {
1376 labelComposite.dispose();
1377 attributeComposite.dispose();
1378 filler.dispose();
1379 tagComposite.dispose();
1380 }
1381
1382 private void setAttributeNumber(int attributeNumber) {
1383 this.attributeNumber = attributeNumber;
1384 labelComposite.layout();
1385 }
1386 }
1387
1388 private Element getPreviewElement(InputElement inputElement) {
1389 Element element = documentElement;
1390 if (element != null) {
1391 if (!documentElement.getNodeName().equals(definition.rootInputElement.elementName)) {
1392 return null;
1393 }
1394 ArrayList<String> elementNames = new ArrayList<String>();
1395 while (inputElement != null) {
1396 elementNames.add(inputElement.elementName);
1397 inputElement = inputElement.parentElement;
1398 }
1399 for (int i = elementNames.size() - 1; --i >= 0;) {
1400 NodeList childList = element.getChildNodes();
1401 element = null;
1402 for (int j = 0; j < childList.getLength(); j++) {
1403 Node child = childList.item(j);
1404 if (child instanceof Element && child.getNodeName().equals(elementNames.get(i))) {
1405 element = (Element) child;
1406 break;
1407 }
1408 }
1409 if (element == null) {
1410 break;
1411 }
1412 }
1413 if (element != null) {
1414 return element;
1415 }
1416 }
1417 return null;
1418 }
1419
1420 private String getChildNameSuggestion(InputElement inputElement) {
1421 if (inputElement == null) {
1422 if (documentElement != null) {
1423 return documentElement.getNodeName();
1424 }
1425 } else {
1426 Element element = getPreviewElement(inputElement);
1427 if (element != null) {
1428 NodeList childNodes = element.getChildNodes();
1429 for (int i = 0; i < childNodes.getLength(); i++) {
1430 Node node = childNodes.item(i);
1431 if (node instanceof Element) {
1432 boolean unused = true;
1433 if (inputElement.childElements != null) {
1434 for (InputElement child : inputElement.childElements) {
1435 if (child.elementName.equals(node.getNodeName())) {
1436 unused = false;
1437 break;
1438 }
1439 }
1440 }
1441 if (unused) {
1442 return node.getNodeName();
1443 }
1444 }
1445 }
1446 }
1447 }
1448 return ""; //$NON-NLS-1$
1449 }
1450
1451 private String getAttributeNameSuggestion(InputElement inputElement) {
1452 Element element = getPreviewElement(inputElement);
1453 if (element != null) {
1454 NamedNodeMap attributeMap = element.getAttributes();
1455 for (int i = 0; i < attributeMap.getLength(); i++) {
1456 Node node = attributeMap.item(i);
1457 boolean unused = true;
1458 if (inputElement.attributes != null) {
1459 for (InputAttribute attribute : inputElement.attributes) {
1460 if (attribute.attributeName.equals(node.getNodeName())) {
1461 unused = false;
1462 break;
1463 }
1464 }
1465 }
1466 if (unused) {
1467 return node.getNodeName();
1468 }
1469 }
1470 }
1471 return ""; //$NON-NLS-1$
1472 }
1473
1474 private void validate() {
1475 definition.definitionName = logtypeText.getText().trim();
1476 definition.timeStampOutputFormat = timeStampOutputFormatText.getText().trim();
1477
1478 if (selectedElement != null) {
1479 selectedElement.extractInputs();
1480 treeViewer.refresh();
1481 }
1482
1483 StringBuffer errors = new StringBuffer();
1484
1485 if (definition.definitionName.length() == 0) {
1486 errors.append(Messages.CustomXmlParserInputWizardPage_emptyLogTypeError);
1487 logtypeText.setBackground(COLOR_LIGHT_RED);
1488 } else {
1489 logtypeText.setBackground(COLOR_TEXT_BACKGROUND);
1490 for (CustomXmlTraceDefinition def : CustomXmlTraceDefinition.loadAll()) {
1491 if (definition.definitionName.equals(def.definitionName)) {
1492 if (editDefinitionName == null || !editDefinitionName.equals(definition.definitionName)) {
1493 errors.append(Messages.CustomXmlParserInputWizardPage_duplicatelogTypeError);
1494 logtypeText.setBackground(COLOR_LIGHT_RED);
1495 break;
1496 }
1497 }
1498 }
1499 }
1500
1501 if (definition.rootInputElement == null) {
1502 errors.append(Messages.CustomXmlParserInputWizardPage_noDocumentError);
1503 }
1504
1505 if (definition.rootInputElement != null) {
1506 logEntryFound = false;
1507 timeStampFound = false;
1508
1509 errors.append(validateElement(definition.rootInputElement));
1510
1511 if ((definition.rootInputElement.attributes != null && definition.rootInputElement.attributes.size() != 0)
1512 || (definition.rootInputElement.childElements != null && definition.rootInputElement.childElements.size() != 0)
1513 || errors.length() == 0) {
1514 if (!logEntryFound) {
1515 errors.append(Messages.CustomXmlParserInputWizardPage_missingLogEntryError);
1516 }
1517
1518 if (timeStampFound) {
1519 if (timeStampOutputFormatText.getText().trim().length() == 0) {
1520 errors.append(Messages.CustomXmlParserInputWizardPage_missingTimestampFmtError);
1521 timeStampOutputFormatText.setBackground(COLOR_LIGHT_RED);
1522 } else {
1523 try {
1524 new SimpleDateFormat(timeStampOutputFormatText.getText().trim());
1525 timeStampOutputFormatText.setBackground(COLOR_TEXT_BACKGROUND);
1526 } catch (IllegalArgumentException e) {
1527 errors.append(Messages.CustomXmlParserInputWizardPage_invalidTimestampFmtError);
1528 timeStampOutputFormatText.setBackground(COLOR_LIGHT_RED);
1529 }
1530 }
1531 } else {
1532 timeStampPreviewText.setText(Messages.CustomXmlParserInputWizardPage_notimestamporAttributeError);
1533 }
1534 }
1535 } else {
1536 timeStampPreviewText.setText(Messages.CustomXmlParserInputWizardPage_notimestamporAttributeError);
1537 }
1538
1539 if (errors.length() == 0) {
1540 setDescription(defaultDescription);
1541 setPageComplete(true);
1542 } else {
1543 setDescription(errors.toString());
1544 setPageComplete(false);
1545 }
1546 }
1547
1548 /**
1549 * Clean up the specified XML element.
1550 *
1551 * @param inputElement
1552 * The element to clean up
1553 * @return The validated element
1554 */
1555 public StringBuffer validateElement(InputElement inputElement) {
1556 StringBuffer errors = new StringBuffer();
1557 ElementNode elementNode = null;
1558 if (selectedElement != null && selectedElement.inputElement.equals(inputElement)) {
1559 elementNode = selectedElement;
1560 }
1561 if (inputElement == definition.rootInputElement) {
1562 if (inputElement.elementName.length() == 0) {
1563 errors.append(Messages.CustomXmlParserInputWizardPage_missingDocumentElementError);
1564 if (elementNode != null) {
1565 elementNode.elementNameText.setBackground(COLOR_LIGHT_RED);
1566 }
1567 } else {
1568 if (elementNode != null) {
1569 elementNode.elementNameText.setBackground(COLOR_TEXT_BACKGROUND);
1570 }
1571 }
1572 }
1573 if (inputElement != definition.rootInputElement) {
1574 if (inputElement.logEntry) {
1575 logEntryFound = true;
1576 }
1577 if (inputElement.inputName.equals(CustomTraceDefinition.TAG_TIMESTAMP)) {
1578 timeStampFound = true;
1579 if (inputElement.inputFormat.length() == 0) {
1580 errors.append(Messages.CustomXmlParserInputWizardPage_timestampFormatPrompt
1581 + " (" + Messages.CustomXmlParserInputWizardPage_timestampElementPrompt + " " + getName(inputElement) + "). "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
1582 if (elementNode != null) {
1583 elementNode.tagText.setBackground(COLOR_LIGHT_RED);
1584 }
1585 } else {
1586 try {
1587 new SimpleDateFormat(inputElement.inputFormat);
1588 if (elementNode != null) {
1589 elementNode.tagText.setBackground(COLOR_TEXT_BACKGROUND);
1590 }
1591 } catch (IllegalArgumentException e) {
1592 errors.append(Messages.CustomXmlParserInputWizardPage_invalidTimestampFmtError
1593 + " (" + Messages.CustomXmlParserInputWizardPage_timestampElementPrompt + " " + getName(inputElement) + "). "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
1594 if (elementNode != null) {
1595 elementNode.tagText.setBackground(COLOR_LIGHT_RED);
1596 }
1597 }
1598 }
1599 } else if (inputElement.inputName.length() == 0) {
1600 errors.append(Messages.CustomXmlParserInputWizardPage_missingInputElementNameError);
1601 if (elementNode != null) {
1602 elementNode.tagText.setBackground(COLOR_LIGHT_RED);
1603 }
1604 } else {
1605 if (elementNode != null) {
1606 elementNode.tagText.setBackground(COLOR_TEXT_BACKGROUND);
1607 }
1608 }
1609 }
1610 if (inputElement.attributes != null) {
1611 if (elementNode != null) {
1612 for (Attribute attribute : elementNode.attributes) {
1613 attribute.attributeNameText.setBackground(COLOR_TEXT_BACKGROUND);
1614 }
1615 }
1616 for (int i = 0; i < inputElement.attributes.size(); i++) {
1617 InputAttribute attribute = inputElement.attributes.get(i);
1618 boolean duplicate = false;
1619 for (int j = i + 1; j < inputElement.attributes.size(); j++) {
1620 InputAttribute otherAttribute = inputElement.attributes.get(j);
1621 if (otherAttribute.attributeName.equals(attribute.attributeName)) {
1622 duplicate = true;
1623 if (elementNode != null) {
1624 elementNode.attributes.get(j).attributeNameText.setBackground(COLOR_LIGHT_RED);
1625 }
1626 }
1627 }
1628 if (attribute.attributeName.length() == 0) {
1629 errors.append(Messages.CustomXmlParserInputWizardPage_missingAttribute
1630 + " (" + Messages.CustomXmlParserInputWizardPage_attributePrompt + " " + getName(inputElement) + ": ?). "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
1631 if (elementNode != null) {
1632 elementNode.attributes.get(i).attributeNameText.setBackground(COLOR_LIGHT_RED);
1633 }
1634 } else if (duplicate) {
1635 errors.append(Messages.CustomXmlParserInputWizardPage_duplicateAttributeError
1636 + " (" + Messages.CustomXmlParserInputWizardPage_attributePrompt + " " + getName(attribute, inputElement) + "). "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
1637 if (elementNode != null) {
1638 elementNode.attributes.get(i).attributeNameText.setBackground(COLOR_LIGHT_RED);
1639 }
1640 }
1641 if (attribute.inputName.equals(CustomTraceDefinition.TAG_TIMESTAMP)) {
1642 timeStampFound = true;
1643 if (attribute.inputFormat.length() == 0) {
1644 errors.append(Messages.CustomXmlParserInputWizardPage_missingTimestampInFmtError
1645 + " (" + Messages.CustomXmlParserInputWizardPage_attributePrompt + " " + getName(attribute, inputElement) + "). "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
1646 if (elementNode != null) {
1647 elementNode.attributes.get(i).tagText.setBackground(COLOR_LIGHT_RED);
1648 }
1649 } else {
1650 try {
1651 new SimpleDateFormat(attribute.inputFormat);
1652 if (elementNode != null) {
1653 elementNode.attributes.get(i).tagText.setBackground(COLOR_TEXT_BACKGROUND);
1654 }
1655 } catch (IllegalArgumentException e) {
1656 errors.append(Messages.CustomXmlParserInputWizardPage_invalidTimestampInFmtError
1657 + " (" + Messages.CustomXmlParserInputWizardPage_attributePrompt + " " + getName(attribute, inputElement) + "). "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
1658 if (elementNode != null) {
1659 elementNode.attributes.get(i).tagText.setBackground(COLOR_LIGHT_RED);
1660 }
1661 }
1662 }
1663 } else if (attribute.inputName.length() == 0) {
1664 errors.append(Messages.CustomXmlParserInputWizardPage_missingDataGroupNameError
1665 + " (" + Messages.CustomXmlParserInputWizardPage_attributePrompt + " " + getName(attribute, inputElement) + "). "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
1666 if (elementNode != null) {
1667 elementNode.attributes.get(i).tagText.setBackground(COLOR_LIGHT_RED);
1668 }
1669 } else {
1670 if (elementNode != null) {
1671 elementNode.attributes.get(i).tagText.setBackground(COLOR_TEXT_BACKGROUND);
1672 }
1673 }
1674 }
1675 }
1676 if (inputElement.childElements != null) {
1677 for (InputElement child : inputElement.childElements) {
1678 ElementNode childElementNode = null;
1679 if (selectedElement != null && selectedElement.inputElement.equals(child)) {
1680 childElementNode = selectedElement;
1681 }
1682 if (childElementNode != null) {
1683 childElementNode.elementNameText.setBackground(COLOR_TEXT_BACKGROUND);
1684 }
1685 }
1686 for (int i = 0; i < inputElement.childElements.size(); i++) {
1687 InputElement child = inputElement.childElements.get(i);
1688 ElementNode childElementNode = null;
1689 if (selectedElement != null && selectedElement.inputElement.equals(child)) {
1690 childElementNode = selectedElement;
1691 }
1692 if (child.elementName.length() == 0) {
1693 errors.append(Messages.CustomXmlParserInputWizardPage_missingElementNameError
1694 + " (" + Messages.CustomXmlParserInputWizardPage_attributePrompt + " " + getName(child) + "). "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
1695 if (childElementNode != null) {
1696 childElementNode.elementNameText.setBackground(COLOR_LIGHT_RED);
1697 }
1698 } else {
1699 boolean duplicate = false;
1700 for (int j = i + 1; j < inputElement.childElements.size(); j++) {
1701 InputElement otherChild = inputElement.childElements.get(j);
1702 if (otherChild.elementName.equals(child.elementName)) {
1703 duplicate = true;
1704 ElementNode otherChildElementNode = null;
1705 if (selectedElement != null && selectedElement.inputElement.equals(otherChild)) {
1706 otherChildElementNode = selectedElement;
1707 }
1708 if (otherChildElementNode != null) {
1709 otherChildElementNode.elementNameText.setBackground(COLOR_LIGHT_RED);
1710 }
1711 }
1712 }
1713 if (duplicate) {
1714 errors.append(Messages.CustomXmlParserInputWizardPage_duplicateElementNameError
1715 + " (" + Messages.CustomXmlParserInputWizardPage_attributePrompt + " " + getName(child) + "). "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
1716 if (childElementNode != null) {
1717 childElementNode.elementNameText.setBackground(COLOR_LIGHT_RED);
1718 }
1719 }
1720 }
1721
1722 errors.append(validateElement(child));
1723 }
1724 }
1725 return errors;
1726 }
1727
1728 /**
1729 * Get the trace definition.
1730 *
1731 * @return The trace definition
1732 */
1733 public CustomXmlTraceDefinition getDefinition() {
1734 return definition;
1735 }
1736
1737 /**
1738 * Get the raw text input.
1739 *
1740 * @return The raw text input.
1741 */
1742 public char[] getInputText() {
1743 return inputText.getText().toCharArray();
1744 }
1745 }
This page took 0.074286 seconds and 5 git commands to generate.