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