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