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