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