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; | |
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; | |
313a5081 PT |
64 | import org.eclipse.swt.graphics.Point; |
65 | import org.eclipse.swt.graphics.Rectangle; | |
be222f56 PT |
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; | |
2bdf0193 AM |
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; | |
a7418109 | 80 | import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomXmlInputElement; |
2bdf0193 AM |
81 | import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomXmlTrace; |
82 | import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomXmlTraceDefinition; | |
a7418109 | 83 | import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomXmlInputAttribute; |
2bdf0193 AM |
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; | |
313a5081 | 87 | import org.osgi.framework.Bundle; |
be222f56 PT |
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 | ||
89151d6a PT |
99 | import com.google.common.base.Joiner; |
100 | ||
a0a88f65 AM |
101 | /** |
102 | * Input wizard page for custom XML trace parsers. | |
103 | * | |
f6aa55e2 | 104 | * @author Patrick Tasse |
a0a88f65 | 105 | */ |
be222f56 PT |
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$ | |
73cc4ccf PT |
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$ | |
f6aa55e2 PT |
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$ | |
be222f56 | 120 | private static final Color COLOR_LIGHT_RED = new Color(Display.getDefault(), 255, 192, 192); |
f6aa55e2 PT |
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); | |
be222f56 PT |
123 | |
124 | private final ISelection selection; | |
125 | private CustomXmlTraceDefinition definition; | |
c22ca172 | 126 | private String editCategoryName; |
be222f56 PT |
127 | private String editDefinitionName; |
128 | private String defaultDescription; | |
129 | private ElementNode selectedElement; | |
130 | private Composite container; | |
c22ca172 | 131 | private Text categoryText; |
be222f56 PT |
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; | |
be222f56 PT |
140 | private ScrolledComposite elementScrolledComposite; |
141 | private TreeViewer treeViewer; | |
be222f56 PT |
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 | ||
a0a88f65 AM |
157 | /** |
158 | * Constructor | |
159 | * | |
160 | * @param selection | |
161 | * Selection object | |
162 | * @param definition | |
163 | * Trace definition | |
164 | */ | |
be222f56 PT |
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) { | |
c22ca172 | 178 | this.editCategoryName = definition.categoryName; |
be222f56 PT |
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 | ||
c22ca172 PT |
197 | Label categoryLabel = new Label(headerComposite, SWT.NULL); |
198 | categoryLabel.setText(Messages.CustomXmlParserInputWizardPage_category); | |
be222f56 | 199 | |
c22ca172 PT |
200 | categoryText = new Text(headerComposite, SWT.BORDER | SWT.SINGLE); |
201 | categoryText.setLayoutData(new GridData(120, SWT.DEFAULT)); | |
be222f56 PT |
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 | ||
313a5081 PT |
210 | Button timeStampFormatHelpButton = new Button(headerComposite, SWT.PUSH); |
211 | timeStampFormatHelpButton.setImage(HELP_IMAGE); | |
212 | timeStampFormatHelpButton.setToolTipText(Messages.CustomXmlParserInputWizardPage_timestampFormatHelp); | |
213 | timeStampFormatHelpButton.addSelectionListener(new SelectionAdapter() { | |
be222f56 PT |
214 | @Override |
215 | public void widgetSelected(SelectionEvent e) { | |
313a5081 PT |
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 | } | |
be222f56 PT |
224 | } |
225 | }); | |
226 | ||
c22ca172 PT |
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 | ||
be222f56 | 234 | Label timeStampPreviewLabel = new Label(headerComposite, SWT.NULL); |
be222f56 PT |
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 | ||
f6aa55e2 | 250 | ScrolledComposite treeScrolledComposite = new ScrolledComposite(hSash, SWT.V_SCROLL | SWT.H_SCROLL); |
be222f56 | 251 | treeScrolledComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); |
f6aa55e2 | 252 | Composite treeContainer = new Composite(treeScrolledComposite, SWT.NONE); |
be222f56 PT |
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 | ||
c22ca172 | 285 | categoryText.addModifyListener(updateListener); |
be222f56 PT |
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); | |
f6aa55e2 | 353 | removeButton.setImage(DELETE_IMAGE); |
be222f56 PT |
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(); | |
a7418109 | 362 | CustomXmlInputElement inputElement = (CustomXmlInputElement) ((IStructuredSelection) treeViewer.getSelection()).getFirstElement(); |
be222f56 PT |
363 | if (inputElement == definition.rootInputElement) { |
364 | definition.rootInputElement = null; | |
365 | } else { | |
a7418109 | 366 | inputElement.getParentElement().getChildElements().remove(inputElement); |
be222f56 PT |
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); | |
f6aa55e2 | 385 | addChildButton.setImage(ADD_CHILD_IMAGE); |
be222f56 PT |
386 | addChildButton.setToolTipText(Messages.CustomXmlParserInputWizardPage_addChildElement); |
387 | addChildButton.addSelectionListener(new SelectionAdapter() { | |
388 | @Override | |
389 | public void widgetSelected(SelectionEvent e) { | |
a7418109 | 390 | CustomXmlInputElement inputElement = new CustomXmlInputElement("", false, CustomXmlTraceDefinition.TAG_IGNORE, 0, "", null); //$NON-NLS-1$ //$NON-NLS-2$ |
be222f56 PT |
391 | if (definition.rootInputElement == null) { |
392 | definition.rootInputElement = inputElement; | |
a7418109 | 393 | inputElement.setElementName(getChildNameSuggestion(null)); |
be222f56 PT |
394 | } else if (treeViewer.getSelection().isEmpty()) { |
395 | return; | |
396 | } else { | |
a7418109 | 397 | CustomXmlInputElement parentInputElement = (CustomXmlInputElement) ((IStructuredSelection) treeViewer.getSelection()).getFirstElement(); |
be222f56 | 398 | parentInputElement.addChild(inputElement); |
a7418109 | 399 | inputElement.setElementName(getChildNameSuggestion(parentInputElement)); |
be222f56 PT |
400 | } |
401 | treeViewer.refresh(); | |
402 | treeViewer.setSelection(new StructuredSelection(inputElement), true); | |
403 | } | |
404 | }); | |
405 | ||
406 | addNextButton = new Button(buttonBar, SWT.PUSH); | |
f6aa55e2 | 407 | addNextButton.setImage(ADD_NEXT_IMAGE); |
be222f56 PT |
408 | addNextButton.setToolTipText(Messages.CustomXmlParserInputWizardPage_addNextElement); |
409 | addNextButton.addSelectionListener(new SelectionAdapter() { | |
410 | @Override | |
411 | public void widgetSelected(SelectionEvent e) { | |
a7418109 | 412 | CustomXmlInputElement inputElement = new CustomXmlInputElement("", false, CustomXmlTraceDefinition.TAG_IGNORE, 0, "", null); //$NON-NLS-1$ //$NON-NLS-2$ |
be222f56 PT |
413 | if (definition.rootInputElement == null) { |
414 | definition.rootInputElement = inputElement; | |
a7418109 | 415 | inputElement.setElementName(getChildNameSuggestion(null)); |
be222f56 PT |
416 | } else if (treeViewer.getSelection().isEmpty()) { |
417 | return; | |
418 | } else { | |
a7418109 | 419 | CustomXmlInputElement previousInputElement = (CustomXmlInputElement) ((IStructuredSelection) treeViewer.getSelection()).getFirstElement(); |
be222f56 PT |
420 | if (previousInputElement == definition.rootInputElement) { |
421 | return; | |
422 | } | |
423 | previousInputElement.addNext(inputElement); | |
a7418109 | 424 | inputElement.setElementName(getChildNameSuggestion(inputElement.getParentElement())); |
be222f56 PT |
425 | } |
426 | treeViewer.refresh(); | |
427 | treeViewer.setSelection(new StructuredSelection(inputElement), true); | |
428 | } | |
429 | }); | |
430 | ||
f6aa55e2 PT |
431 | Button feelingLuckyButton = new Button(buttonBar, SWT.PUSH); |
432 | feelingLuckyButton.setImage(ADD_MANY_IMAGE); | |
be222f56 PT |
433 | feelingLuckyButton.setToolTipText(Messages.CustomXmlParserInputWizardPage_feelingLucky); |
434 | feelingLuckyButton.addSelectionListener(new SelectionAdapter() { | |
435 | @Override | |
436 | public void widgetSelected(SelectionEvent e) { | |
a7418109 | 437 | CustomXmlInputElement inputElement = null; |
be222f56 PT |
438 | if (definition.rootInputElement == null) { |
439 | if (getChildNameSuggestion(null).length() != 0) { | |
a7418109 | 440 | inputElement = new CustomXmlInputElement(getChildNameSuggestion(null), false, CustomXmlTraceDefinition.TAG_IGNORE, 0, "", null); //$NON-NLS-1$ |
be222f56 PT |
441 | definition.rootInputElement = inputElement; |
442 | feelingLucky(inputElement); | |
443 | } else { | |
444 | return; | |
445 | } | |
446 | } else if (treeViewer.getSelection().isEmpty()) { | |
447 | return; | |
448 | } else { | |
a7418109 | 449 | inputElement = (CustomXmlInputElement) ((IStructuredSelection) treeViewer.getSelection()).getFirstElement(); |
be222f56 PT |
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); | |
f6aa55e2 | 459 | moveUpButton.setImage(MOVE_UP_IMAGE); |
be222f56 PT |
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 | } | |
a7418109 | 467 | CustomXmlInputElement inputElement = (CustomXmlInputElement) ((IStructuredSelection) treeViewer.getSelection()).getFirstElement(); |
be222f56 PT |
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); | |
f6aa55e2 | 479 | moveDownButton.setImage(MOVE_DOWN_IMAGE); |
be222f56 PT |
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 | } | |
a7418109 | 487 | CustomXmlInputElement inputElement = (CustomXmlInputElement) ((IStructuredSelection) treeViewer.getSelection()).getFirstElement(); |
be222f56 PT |
488 | if (inputElement == definition.rootInputElement) { |
489 | return; | |
490 | } | |
491 | inputElement.moveDown(); | |
492 | treeViewer.refresh(); | |
493 | validate(); | |
494 | updatePreviews(); | |
495 | } | |
496 | }); | |
497 | } | |
498 | ||
a7418109 | 499 | private void feelingLucky(CustomXmlInputElement inputElement) { |
be222f56 PT |
500 | while (true) { |
501 | String attributeName = getAttributeNameSuggestion(inputElement); | |
502 | if (attributeName.length() == 0) { | |
503 | break; | |
504 | } | |
a7418109 | 505 | CustomXmlInputAttribute attribute = new CustomXmlInputAttribute(attributeName, attributeName, 0, ""); //$NON-NLS-1$ |
be222f56 PT |
506 | inputElement.addAttribute(attribute); |
507 | } | |
508 | while (true) { | |
509 | String childName = getChildNameSuggestion(inputElement); | |
510 | if (childName.length() == 0) { | |
511 | break; | |
512 | } | |
a7418109 | 513 | CustomXmlInputElement childElement = new CustomXmlInputElement(childName, false, CustomXmlTraceDefinition.TAG_IGNORE, 0, "", null); //$NON-NLS-1$ |
be222f56 PT |
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) { | |
a7418109 MK |
532 | CustomXmlInputElement inputElement = (CustomXmlInputElement) parentElement; |
533 | if (inputElement.getChildElements() == null) { | |
534 | return new CustomXmlInputElement[0]; | |
be222f56 | 535 | } |
a7418109 | 536 | return inputElement.getChildElements().toArray(); |
be222f56 PT |
537 | } |
538 | ||
539 | @Override | |
540 | public boolean hasChildren(Object element) { | |
a7418109 MK |
541 | CustomXmlInputElement inputElement = (CustomXmlInputElement) element; |
542 | return (inputElement.getChildElements() != null && inputElement.getChildElements().size() > 0); | |
be222f56 PT |
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) { | |
a7418109 MK |
555 | CustomXmlInputElement inputElement = (CustomXmlInputElement) element; |
556 | return inputElement.getParentElement(); | |
be222f56 PT |
557 | } |
558 | } | |
559 | ||
560 | private static class InputElementTreeLabelProvider extends ColumnLabelProvider { | |
561 | ||
562 | @Override | |
563 | public Image getImage(Object element) { | |
f6aa55e2 | 564 | return ELEMENT_IMAGE; |
be222f56 PT |
565 | } |
566 | ||
567 | @Override | |
568 | public String getText(Object element) { | |
a7418109 MK |
569 | CustomXmlInputElement inputElement = (CustomXmlInputElement) element; |
570 | return (inputElement.getElementName().trim().length() == 0) ? "?" : inputElement.getElementName(); //$NON-NLS-1$ | |
be222f56 PT |
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) { | |
3dca7aa5 | 581 | IStructuredSelection sel = (IStructuredSelection) event.getSelection(); |
a7418109 | 582 | CustomXmlInputElement inputElement = (CustomXmlInputElement) sel.getFirstElement(); |
be222f56 PT |
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 | ||
be222f56 PT |
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) { | |
c22ca172 | 625 | categoryText.setText(def.categoryName); |
be222f56 PT |
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 | ||
a7418109 MK |
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) { | |
be222f56 PT |
638 | return name; |
639 | } | |
a7418109 | 640 | return getName(inputElement.getParentElement()) + " : " + name; //$NON-NLS-1$ |
be222f56 PT |
641 | } |
642 | ||
a7418109 MK |
643 | private String getName(CustomXmlInputAttribute inputAttribute, CustomXmlInputElement inputElement) { |
644 | String name = (inputAttribute.getAttributeName().trim().length() == 0) ? "?" : inputAttribute.getAttributeName().trim(); //$NON-NLS-1$ | |
be222f56 PT |
645 | return getName(inputElement) + " : " + name; //$NON-NLS-1$ |
646 | } | |
647 | ||
be222f56 PT |
648 | @Override |
649 | public void setVisible(boolean visible) { | |
650 | if (visible) { | |
651 | validate(); | |
652 | updatePreviews(); | |
653 | } | |
654 | super.setVisible(visible); | |
655 | } | |
656 | ||
a0a88f65 AM |
657 | /** |
658 | * Get the global list of input names. | |
659 | * | |
660 | * @return The list of input names | |
661 | */ | |
be222f56 PT |
662 | public List<String> getInputNames() { |
663 | return getInputNames(definition.rootInputElement); | |
664 | } | |
665 | ||
a0a88f65 AM |
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 | */ | |
a7418109 | 673 | public List<String> getInputNames(CustomXmlInputElement inputElement) { |
507b1336 | 674 | List<String> inputs = new ArrayList<>(); |
a7418109 MK |
675 | if (inputElement.getInputName() != null && !inputElement.getInputName().equals(CustomXmlTraceDefinition.TAG_IGNORE)) { |
676 | String inputName = inputElement.getInputName(); | |
be222f56 PT |
677 | if (!inputs.contains(inputName)) { |
678 | inputs.add(inputName); | |
679 | } | |
680 | } | |
a7418109 MK |
681 | if (inputElement.getAttributes() != null) { |
682 | for (CustomXmlInputAttribute attribute : inputElement.getAttributes()) { | |
683 | String inputName = attribute.getInputName(); | |
be222f56 PT |
684 | if (!inputs.contains(inputName)) { |
685 | inputs.add(inputName); | |
686 | } | |
687 | } | |
688 | } | |
a7418109 MK |
689 | if (inputElement.getChildElements() != null) { |
690 | for (CustomXmlInputElement childInputElement : inputElement.getChildElements()) { | |
be222f56 PT |
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) { | |
3dca7aa5 AM |
713 | Object sel = ((IStructuredSelection) this.selection).getFirstElement(); |
714 | if (sel instanceof IFile) { | |
715 | IFile file = (IFile) sel; | |
be222f56 PT |
716 | try { |
717 | inputStream = file.getContents(); | |
718 | } catch (CoreException e) { | |
719 | return ""; //$NON-NLS-1$ | |
720 | } | |
721 | } | |
722 | } | |
723 | if (inputStream != null) { | |
507b1336 | 724 | try (BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));) { |
be222f56 PT |
725 | StringBuilder sb = new StringBuilder(); |
726 | String line = null; | |
727 | while ((line = reader.readLine()) != null) { | |
5e1ee19a JCK |
728 | sb.append(line); |
729 | sb.append('\n'); | |
be222f56 PT |
730 | } |
731 | parseXmlInput(sb.toString()); | |
be222f56 PT |
732 | return sb.toString(); |
733 | } catch (IOException e) { | |
734 | return ""; //$NON-NLS-1$ | |
735 | } | |
736 | } | |
737 | return ""; //$NON-NLS-1$ | |
738 | } | |
739 | ||
740 | private void parseXmlInput(final String string) { | |
741 | try { | |
742 | DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); | |
743 | DocumentBuilder db = dbf.newDocumentBuilder(); | |
744 | ||
745 | // The following allows xml parsing without access to the dtd | |
746 | EntityResolver resolver = new EntityResolver() { | |
747 | @Override | |
748 | public InputSource resolveEntity(String publicId, String systemId) { | |
749 | String empty = ""; //$NON-NLS-1$ | |
750 | ByteArrayInputStream bais = new ByteArrayInputStream(empty.getBytes()); | |
751 | return new InputSource(bais); | |
752 | } | |
753 | }; | |
754 | db.setEntityResolver(resolver); | |
755 | ||
756 | // The following catches xml parsing exceptions | |
757 | db.setErrorHandler(new ErrorHandler() { | |
758 | @Override | |
759 | public void error(SAXParseException saxparseexception) throws SAXException { | |
760 | } | |
761 | ||
762 | @Override | |
763 | public void warning(SAXParseException saxparseexception) throws SAXException { | |
764 | } | |
765 | ||
766 | @Override | |
767 | public void fatalError(SAXParseException saxparseexception) throws SAXException { | |
768 | if (string.trim().length() != 0) { | |
769 | errorText.setText(saxparseexception.getMessage()); | |
770 | errorText.setBackground(COLOR_LIGHT_RED); | |
771 | errorText.setVisible(true); | |
772 | } | |
773 | throw saxparseexception; | |
774 | } | |
775 | }); | |
776 | ||
777 | errorText.setVisible(false); | |
778 | Document doc = null; | |
779 | doc = db.parse(new ByteArrayInputStream(string.getBytes())); | |
780 | documentElement = doc.getDocumentElement(); | |
781 | } catch (ParserConfigurationException e) { | |
782 | Activator.getDefault().logError("Error pasing XML input string: " + string, e); //$NON-NLS-1$ | |
783 | documentElement = null; | |
784 | } catch (SAXException e) { | |
785 | documentElement = null; | |
786 | } catch (IOException e) { | |
787 | Activator.getDefault().logError("Error pasing XML input string: " + string, e); //$NON-NLS-1$ | |
788 | documentElement = null; | |
789 | } | |
790 | } | |
791 | ||
be222f56 PT |
792 | private void initValues() { |
793 | timeStampValue = null; | |
794 | timeStampFormat = null; | |
795 | logEntriesCount = 0; | |
796 | logEntryFound = false; | |
797 | } | |
798 | ||
3dca7aa5 | 799 | private void updatePreviews() { |
be222f56 PT |
800 | if (inputText == null) { |
801 | // early update during construction | |
802 | return; | |
803 | } | |
804 | inputText.setStyleRanges(new StyleRange[] {}); | |
805 | if (selectedElement == null) { | |
806 | return; | |
807 | } | |
808 | ||
809 | initValues(); | |
810 | ||
811 | selectedElement.updatePreview(); | |
812 | ||
813 | if (timeStampValue != null && timeStampFormat != null) { | |
814 | try { | |
738beb68 PT |
815 | TmfTimestampFormat timestampFormat = new TmfTimestampFormat(timeStampFormat); |
816 | long timestamp = timestampFormat.parseValue(timeStampValue); | |
817 | timestampFormat = new TmfTimestampFormat(timeStampOutputFormatText.getText().trim()); | |
818 | timeStampPreviewText.setText(timestampFormat.format(timestamp)); | |
be222f56 PT |
819 | } catch (ParseException e) { |
820 | timeStampPreviewText.setText("*parse exception* [" + timeStampValue + "] <> [" + timeStampFormat + "]"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ | |
821 | } catch (IllegalArgumentException e) { | |
822 | timeStampPreviewText.setText("*parse exception* [Illegal Argument]"); //$NON-NLS-1$ | |
823 | } | |
824 | } else { | |
825 | timeStampPreviewText.setText("*no matching time stamp*"); //$NON-NLS-1$ | |
826 | } | |
827 | } | |
828 | ||
829 | private void openHelpShell(String url) { | |
830 | if (helpBrowser != null && !helpBrowser.isDisposed()) { | |
831 | helpBrowser.getShell().setActive(); | |
832 | if (!helpBrowser.getUrl().equals(url)) { | |
833 | helpBrowser.setUrl(url); | |
834 | } | |
835 | return; | |
836 | } | |
837 | final Shell helpShell = new Shell(getShell(), SWT.SHELL_TRIM); | |
838 | helpShell.setLayout(new FillLayout()); | |
839 | helpBrowser = new Browser(helpShell, SWT.NONE); | |
840 | helpBrowser.addTitleListener(new TitleListener() { | |
841 | @Override | |
842 | public void changed(TitleEvent event) { | |
843 | helpShell.setText(event.title); | |
844 | } | |
845 | }); | |
313a5081 PT |
846 | Rectangle r = container.getBounds(); |
847 | Point p = container.toDisplay(r.x, r.y); | |
848 | Rectangle trim = helpShell.computeTrim(p.x + (r.width - 750) / 2, p.y + (r.height - 400) / 2, 750, 400); | |
849 | helpShell.setBounds(trim); | |
be222f56 PT |
850 | helpShell.open(); |
851 | helpBrowser.setUrl(url); | |
852 | } | |
853 | ||
854 | private class UpdateListener implements ModifyListener, SelectionListener { | |
855 | ||
856 | @Override | |
857 | public void modifyText(ModifyEvent e) { | |
858 | validate(); | |
859 | updatePreviews(); | |
860 | } | |
861 | ||
862 | @Override | |
863 | public void widgetDefaultSelected(SelectionEvent e) { | |
864 | validate(); | |
865 | updatePreviews(); | |
866 | } | |
867 | ||
868 | @Override | |
869 | public void widgetSelected(SelectionEvent e) { | |
870 | validate(); | |
871 | updatePreviews(); | |
872 | } | |
873 | ||
874 | } | |
875 | ||
876 | private class ElementNode { | |
a7418109 | 877 | private final CustomXmlInputElement inputElement; |
f6aa55e2 | 878 | private final Group group; |
507b1336 AM |
879 | private List<Attribute> attributes = new ArrayList<>(); |
880 | private List<ElementNode> childElements = new ArrayList<>(); | |
f6aa55e2 PT |
881 | private Text elementNameText; |
882 | private Composite tagComposite; | |
883 | private Combo tagCombo; | |
884 | private Label tagLabel; | |
885 | private Text tagText; | |
886 | private Combo actionCombo; | |
887 | private Label previewLabel; | |
888 | private Text previewText; | |
889 | private Button logEntryButton; | |
890 | private Label fillerLabel; | |
891 | private Composite addAttributeComposite; | |
892 | private Button addAttributeButton; | |
893 | private Label addAttributeLabel; | |
be222f56 | 894 | |
a7418109 | 895 | public ElementNode(Composite parent, CustomXmlInputElement inputElement) { |
be222f56 PT |
896 | this.inputElement = inputElement; |
897 | ||
898 | group = new Group(parent, SWT.NONE); | |
899 | GridLayout gl = new GridLayout(2, false); | |
900 | gl.marginHeight = 0; | |
901 | group.setLayout(gl); | |
902 | group.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); | |
903 | group.setText(getName(inputElement)); | |
904 | ||
905 | Label label = new Label(group, SWT.NULL); | |
906 | label.setText(Messages.CustomXmlParserInputWizardPage_elementName); | |
907 | label.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false)); | |
908 | ||
909 | elementNameText = new Text(group, SWT.BORDER | SWT.SINGLE); | |
910 | GridData gd = new GridData(SWT.FILL, SWT.CENTER, true, false); | |
911 | gd.widthHint = 0; | |
912 | elementNameText.setLayoutData(gd); | |
913 | elementNameText.addModifyListener(new ModifyListener() { | |
914 | @Override | |
915 | public void modifyText(ModifyEvent e) { | |
a7418109 | 916 | ElementNode.this.inputElement.setElementName(elementNameText.getText().trim()); |
be222f56 PT |
917 | group.setText(getName(ElementNode.this.inputElement)); |
918 | } | |
919 | }); | |
a7418109 | 920 | elementNameText.setText(inputElement.getElementName()); |
be222f56 PT |
921 | elementNameText.addModifyListener(updateListener); |
922 | ||
a7418109 | 923 | if (inputElement.getParentElement() != null) { |
be222f56 PT |
924 | previewLabel = new Label(group, SWT.NULL); |
925 | previewLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false)); | |
926 | previewLabel.setText(Messages.CustomXmlParserInputWizardPage_preview); | |
927 | ||
928 | previewText = new Text(group, SWT.BORDER | SWT.SINGLE | SWT.READ_ONLY); | |
929 | gd = new GridData(SWT.FILL, SWT.CENTER, true, false); | |
930 | gd.widthHint = 0; | |
931 | previewText.setLayoutData(gd); | |
932 | previewText.setText(Messages.CustomXmlParserInputWizardPage_noMatchingElement); | |
933 | previewText.setBackground(COLOR_WIDGET_BACKGROUND); | |
934 | ||
935 | logEntryButton = new Button(group, SWT.CHECK); | |
936 | logEntryButton.setText(Messages.CustomXmlParserInputWizardPage_logEntry); | |
a7418109 | 937 | logEntryButton.setSelection(inputElement.isLogEntry()); |
be222f56 PT |
938 | logEntryButton.addSelectionListener(new SelectionListener() { |
939 | @Override | |
940 | public void widgetDefaultSelected(SelectionEvent e) { | |
941 | } | |
942 | ||
943 | @Override | |
944 | public void widgetSelected(SelectionEvent e) { | |
a7418109 | 945 | CustomXmlInputElement parentElem = ElementNode.this.inputElement.getParentElement(); |
3dca7aa5 | 946 | while (parentElem != null) { |
a7418109 MK |
947 | parentElem.setLogEntry(false); |
948 | parentElem = parentElem.getParentElement(); | |
be222f56 PT |
949 | } |
950 | } | |
951 | }); | |
952 | logEntryButton.addSelectionListener(updateListener); | |
953 | ||
954 | tagComposite = new Composite(group, SWT.FILL); | |
955 | GridLayout tagLayout = new GridLayout(4, false); | |
956 | tagLayout.marginWidth = 0; | |
957 | tagLayout.marginHeight = 0; | |
958 | tagComposite.setLayout(tagLayout); | |
959 | tagComposite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); | |
960 | ||
961 | tagCombo = new Combo(tagComposite, SWT.DROP_DOWN | SWT.READ_ONLY); | |
962 | tagCombo.setItems(new String[] { CustomXmlTraceDefinition.TAG_IGNORE, CustomTraceDefinition.TAG_TIMESTAMP, | |
963 | CustomTraceDefinition.TAG_MESSAGE, CustomTraceDefinition.TAG_OTHER }); | |
964 | tagCombo.setVisibleItemCount(tagCombo.getItemCount()); | |
965 | tagCombo.addSelectionListener(new SelectionListener() { | |
966 | @Override | |
967 | public void widgetDefaultSelected(SelectionEvent e) { | |
968 | } | |
969 | ||
970 | @Override | |
971 | public void widgetSelected(SelectionEvent e) { | |
972 | tagText.removeModifyListener(updateListener); | |
973 | switch (tagCombo.getSelectionIndex()) { | |
974 | case 0: // Ignore | |
975 | tagLabel.setVisible(false); | |
976 | tagText.setVisible(false); | |
977 | actionCombo.setVisible(false); | |
978 | break; | |
979 | case 1: // Time Stamp | |
980 | tagLabel.setText(Messages.CustomXmlParserInputWizardPage_format); | |
981 | tagLabel.setVisible(true); | |
982 | tagText.setVisible(true); | |
983 | tagText.addModifyListener(updateListener); | |
984 | actionCombo.setVisible(true); | |
985 | break; | |
986 | case 2: // Message | |
987 | tagLabel.setVisible(false); | |
988 | tagText.setVisible(false); | |
989 | actionCombo.setVisible(true); | |
990 | break; | |
991 | case 3: // Other | |
992 | tagLabel.setText(Messages.CustomXmlParserInputWizardPage_tagName); | |
993 | tagLabel.setVisible(true); | |
994 | if (tagText.getText().trim().length() == 0) { | |
995 | tagText.setText(elementNameText.getText().trim()); | |
996 | } | |
997 | tagText.setVisible(true); | |
998 | tagText.addModifyListener(updateListener); | |
999 | actionCombo.setVisible(true); | |
1000 | break; | |
1001 | default: | |
1002 | break; | |
1003 | } | |
1004 | tagComposite.layout(); | |
1005 | validate(); | |
1006 | updatePreviews(); | |
1007 | } | |
1008 | }); | |
1009 | ||
1010 | tagLabel = new Label(tagComposite, SWT.NULL); | |
1011 | tagLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false)); | |
1012 | ||
1013 | tagText = new Text(tagComposite, SWT.BORDER | SWT.SINGLE); | |
1014 | gd = new GridData(SWT.FILL, SWT.CENTER, true, false); | |
1015 | gd.widthHint = 0; | |
1016 | tagText.setLayoutData(gd); | |
1017 | ||
1018 | actionCombo = new Combo(tagComposite, SWT.DROP_DOWN | SWT.READ_ONLY); | |
1019 | actionCombo.setItems(new String[] { Messages.CustomXmlParserInputWizardPage_set, Messages.CustomXmlParserInputWizardPage_append, | |
1020 | Messages.CustomXmlParserInputWizardPage_appendWith }); | |
a7418109 | 1021 | actionCombo.select(inputElement.getInputAction()); |
be222f56 PT |
1022 | actionCombo.addSelectionListener(updateListener); |
1023 | ||
a7418109 | 1024 | if (inputElement.getInputName().equals(CustomXmlTraceDefinition.TAG_IGNORE)) { |
be222f56 PT |
1025 | tagCombo.select(0); |
1026 | tagLabel.setVisible(false); | |
1027 | tagText.setVisible(false); | |
1028 | actionCombo.setVisible(false); | |
a7418109 | 1029 | } else if (inputElement.getInputName().equals(CustomTraceDefinition.TAG_TIMESTAMP)) { |
be222f56 PT |
1030 | tagCombo.select(1); |
1031 | tagLabel.setText(Messages.CustomXmlParserInputWizardPage_format); | |
a7418109 | 1032 | tagText.setText(inputElement.getInputFormat()); |
be222f56 | 1033 | tagText.addModifyListener(updateListener); |
a7418109 | 1034 | } else if (inputElement.getInputName().equals(CustomTraceDefinition.TAG_MESSAGE)) { |
be222f56 PT |
1035 | tagCombo.select(2); |
1036 | tagLabel.setVisible(false); | |
1037 | tagText.setVisible(false); | |
1038 | } else { | |
1039 | tagCombo.select(3); | |
1040 | tagLabel.setText(Messages.CustomXmlParserInputWizardPage_tagName); | |
a7418109 | 1041 | tagText.setText(inputElement.getInputName()); |
be222f56 PT |
1042 | tagText.addModifyListener(updateListener); |
1043 | } | |
1044 | } | |
1045 | ||
a7418109 MK |
1046 | if (inputElement.getAttributes() != null) { |
1047 | for (CustomXmlInputAttribute inputAttribute : inputElement.getAttributes()) { | |
be222f56 PT |
1048 | Attribute attribute = new Attribute(group, this, inputAttribute, attributes.size() + 1); |
1049 | attributes.add(attribute); | |
1050 | } | |
1051 | } | |
1052 | ||
1053 | createAddButton(); | |
1054 | } | |
1055 | ||
1056 | private void updatePreview() { | |
1057 | Element element = getPreviewElement(inputElement); | |
a7418109 | 1058 | if (inputElement.getParentElement() != null) { // no preview text for |
be222f56 PT |
1059 | // document element |
1060 | previewText.setText(Messages.CustomXmlParserInputWizardPage_noMatchingElement); | |
1061 | if (element != null) { | |
1062 | previewText.setText(CustomXmlTrace.parseElement(element, new StringBuffer()).toString()); | |
1063 | if (logEntryButton.getSelection()) { | |
1064 | if (!logEntryFound) { | |
1065 | logEntryFound = true; | |
1066 | logEntriesCount++; | |
1067 | } else { | |
1068 | logEntryButton.setSelection(false); // remove nested | |
1069 | // log entry | |
1070 | } | |
1071 | } | |
1072 | if (tagCombo.getText().equals(CustomTraceDefinition.TAG_TIMESTAMP) && logEntriesCount <= 1) { | |
1073 | String value = previewText.getText().trim(); | |
1074 | if (value.length() != 0) { | |
1075 | if (actionCombo.getSelectionIndex() == CustomTraceDefinition.ACTION_SET) { | |
1076 | timeStampValue = value; | |
1077 | timeStampFormat = tagText.getText().trim(); | |
1078 | } else if (actionCombo.getSelectionIndex() == CustomTraceDefinition.ACTION_APPEND) { | |
1079 | if (timeStampValue != null) { | |
1080 | timeStampValue += value; | |
1081 | timeStampFormat += tagText.getText().trim(); | |
1082 | } else { | |
1083 | timeStampValue = value; | |
1084 | timeStampFormat = tagText.getText().trim(); | |
1085 | } | |
1086 | } else if (actionCombo.getSelectionIndex() == CustomTraceDefinition.ACTION_APPEND_WITH_SEPARATOR) { | |
1087 | if (timeStampValue != null) { | |
1088 | timeStampValue += " | " + value; //$NON-NLS-1$ | |
1089 | timeStampFormat += " | " + tagText.getText().trim(); //$NON-NLS-1$ | |
1090 | } else { | |
1091 | timeStampValue = value; | |
1092 | timeStampFormat = tagText.getText().trim(); | |
1093 | } | |
1094 | } | |
1095 | } | |
1096 | } | |
1097 | } | |
1098 | } | |
1099 | for (Attribute attribute : attributes) { | |
1100 | if (element != null) { | |
1101 | String value = element.getAttribute(attribute.attributeNameText.getText().trim()); | |
1102 | if (value.length() != 0) { | |
1103 | attribute.previewText.setText(value); | |
1104 | if (attribute.tagCombo.getText().equals(CustomTraceDefinition.TAG_TIMESTAMP) && logEntriesCount <= 1) { | |
1105 | if (attribute.actionCombo.getSelectionIndex() == CustomTraceDefinition.ACTION_SET) { | |
1106 | timeStampValue = value; | |
1107 | timeStampFormat = attribute.tagText.getText().trim(); | |
1108 | } else if (attribute.actionCombo.getSelectionIndex() == CustomTraceDefinition.ACTION_APPEND) { | |
1109 | if (timeStampValue != null) { | |
1110 | timeStampValue += value; | |
1111 | timeStampFormat += attribute.tagText.getText().trim(); | |
1112 | } else { | |
1113 | timeStampValue = value; | |
1114 | timeStampFormat = attribute.tagText.getText().trim(); | |
1115 | } | |
1116 | } else if (attribute.actionCombo.getSelectionIndex() == CustomTraceDefinition.ACTION_APPEND_WITH_SEPARATOR) { | |
1117 | if (timeStampValue != null) { | |
1118 | timeStampValue += " | " + value; //$NON-NLS-1$ | |
1119 | timeStampFormat += " | " + attribute.tagText.getText().trim(); //$NON-NLS-1$ | |
1120 | } else { | |
1121 | timeStampValue = value; | |
1122 | timeStampFormat = attribute.tagText.getText().trim(); | |
1123 | } | |
1124 | } | |
1125 | } | |
1126 | } else { | |
1127 | attribute.previewText.setText(Messages.CustomXmlParserInputWizardPage_noMatchingAttribute); | |
1128 | } | |
1129 | } else { | |
1130 | attribute.previewText.setText(Messages.CustomXmlParserInputWizardPage_noMatchingElement); | |
1131 | } | |
1132 | } | |
1133 | for (ElementNode child : childElements) { | |
1134 | child.updatePreview(); | |
1135 | } | |
1136 | if (logEntryButton != null && logEntryButton.getSelection()) { | |
1137 | logEntryFound = false; | |
1138 | } | |
1139 | } | |
1140 | ||
1141 | private void createAddButton() { | |
1142 | fillerLabel = new Label(group, SWT.NONE); | |
1143 | ||
1144 | addAttributeComposite = new Composite(group, SWT.NONE); | |
1145 | addAttributeComposite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); | |
1146 | GridLayout addAttributeLayout = new GridLayout(2, false); | |
1147 | addAttributeLayout.marginHeight = 0; | |
1148 | addAttributeLayout.marginWidth = 0; | |
1149 | addAttributeComposite.setLayout(addAttributeLayout); | |
1150 | ||
1151 | addAttributeButton = new Button(addAttributeComposite, SWT.PUSH); | |
f6aa55e2 | 1152 | addAttributeButton.setImage(ADD_IMAGE); |
be222f56 PT |
1153 | addAttributeButton.setToolTipText(Messages.CustomXmlParserInputWizardPage_addAttribute); |
1154 | addAttributeButton.addSelectionListener(new SelectionAdapter() { | |
1155 | @Override | |
1156 | public void widgetSelected(SelectionEvent e) { | |
1157 | removeAddButton(); | |
1158 | String attributeName = getAttributeNameSuggestion(inputElement); | |
a7418109 | 1159 | CustomXmlInputAttribute inputAttribute = new CustomXmlInputAttribute(attributeName, attributeName, 0, ""); //$NON-NLS-1$ |
be222f56 PT |
1160 | attributes.add(new Attribute(group, ElementNode.this, inputAttribute, attributes.size() + 1)); |
1161 | createAddButton(); | |
1162 | elementContainer.layout(); | |
1163 | elementScrolledComposite.setMinSize(elementContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT).x, | |
1164 | elementContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT).y - 1); | |
1165 | group.getParent().layout(); | |
1166 | validate(); | |
1167 | updatePreviews(); | |
1168 | } | |
1169 | }); | |
1170 | ||
1171 | addAttributeLabel = new Label(addAttributeComposite, SWT.NULL); | |
1172 | addAttributeLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); | |
1173 | addAttributeLabel.setText(Messages.CustomXmlParserInputWizardPage_newAttibute); | |
1174 | } | |
1175 | ||
1176 | private void removeAddButton() { | |
1177 | fillerLabel.dispose(); | |
1178 | addAttributeComposite.dispose(); | |
1179 | } | |
1180 | ||
1181 | private void removeAttribute(int attributeNumber) { | |
41b5c37f AM |
1182 | int nb = attributeNumber; |
1183 | if (--nb < attributes.size()) { | |
1184 | attributes.remove(nb).dispose(); | |
1185 | for (int i = nb; i < attributes.size(); i++) { | |
be222f56 PT |
1186 | attributes.get(i).setAttributeNumber(i + 1); |
1187 | } | |
1188 | elementContainer.layout(); | |
1189 | elementScrolledComposite.setMinSize(elementContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT).x, | |
1190 | elementContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT).y - 1); | |
1191 | group.getParent().layout(); | |
1192 | } | |
1193 | } | |
1194 | ||
1195 | private void dispose() { | |
1196 | group.dispose(); | |
1197 | } | |
1198 | ||
1199 | private void extractInputs() { | |
a7418109 MK |
1200 | inputElement.setElementName(elementNameText.getText().trim()); |
1201 | if (inputElement.getParentElement() != null) { | |
1202 | inputElement.setLogEntry(logEntryButton.getSelection()); | |
be222f56 | 1203 | if (tagCombo.getText().equals(CustomTraceDefinition.TAG_OTHER)) { |
a7418109 | 1204 | inputElement.setInputName(tagText.getText().trim()); |
be222f56 | 1205 | } else { |
a7418109 | 1206 | inputElement.setInputName(tagCombo.getText()); |
be222f56 | 1207 | if (tagCombo.getText().equals(CustomTraceDefinition.TAG_TIMESTAMP)) { |
a7418109 | 1208 | inputElement.setInputFormat(tagText.getText().trim()); |
be222f56 PT |
1209 | } |
1210 | } | |
a7418109 | 1211 | inputElement.setInputAction(actionCombo.getSelectionIndex()); |
be222f56 | 1212 | } |
a7418109 | 1213 | inputElement.setAttributes(new ArrayList<CustomXmlInputAttribute>(attributes.size())); |
be222f56 | 1214 | for (int i = 0; i < attributes.size(); i++) { |
a7418109 MK |
1215 | String inputName = null; |
1216 | String inputFormat = null; | |
be222f56 | 1217 | Attribute attribute = attributes.get(i); |
a7418109 | 1218 | String attributeName = attribute.attributeNameText.getText().trim(); |
be222f56 | 1219 | if (attribute.tagCombo.getText().equals(CustomTraceDefinition.TAG_OTHER)) { |
a7418109 | 1220 | inputName = attribute.tagText.getText().trim(); |
be222f56 | 1221 | } else { |
a7418109 | 1222 | inputName = attribute.tagCombo.getText(); |
be222f56 | 1223 | if (attribute.tagCombo.getText().equals(CustomTraceDefinition.TAG_TIMESTAMP)) { |
a7418109 | 1224 | inputFormat = attribute.tagText.getText().trim(); |
be222f56 PT |
1225 | } |
1226 | } | |
a7418109 MK |
1227 | int inputAction = attribute.actionCombo.getSelectionIndex(); |
1228 | inputElement.addAttribute(new CustomXmlInputAttribute(attributeName, inputName, inputAction, inputFormat)); | |
be222f56 PT |
1229 | } |
1230 | } | |
1231 | } | |
1232 | ||
1233 | private class Attribute { | |
f6aa55e2 PT |
1234 | private ElementNode element; |
1235 | private int attributeNumber; | |
be222f56 PT |
1236 | |
1237 | // children of parent (must be disposed) | |
f6aa55e2 PT |
1238 | private Composite labelComposite; |
1239 | private Composite attributeComposite; | |
1240 | private Label filler; | |
1241 | private Composite tagComposite; | |
be222f56 PT |
1242 | |
1243 | // children of labelComposite | |
f6aa55e2 | 1244 | private Label attributeLabel; |
be222f56 PT |
1245 | |
1246 | // children of attributeComposite | |
f6aa55e2 PT |
1247 | private Text attributeNameText; |
1248 | private Text previewText; | |
be222f56 PT |
1249 | |
1250 | // children of tagComposite | |
f6aa55e2 PT |
1251 | private Combo tagCombo; |
1252 | private Label tagLabel; | |
1253 | private Text tagText; | |
1254 | private Combo actionCombo; | |
be222f56 | 1255 | |
a7418109 | 1256 | public Attribute(Composite parent, ElementNode element, CustomXmlInputAttribute inputAttribute, int attributeNumber) { |
be222f56 PT |
1257 | this.element = element; |
1258 | this.attributeNumber = attributeNumber; | |
1259 | ||
1260 | labelComposite = new Composite(parent, SWT.FILL); | |
1261 | GridLayout labelLayout = new GridLayout(2, false); | |
1262 | labelLayout.marginWidth = 0; | |
1263 | labelLayout.marginHeight = 0; | |
1264 | labelComposite.setLayout(labelLayout); | |
1265 | labelComposite.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false)); | |
1266 | ||
1267 | Button deleteButton = new Button(labelComposite, SWT.PUSH); | |
1268 | deleteButton.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false)); | |
f6aa55e2 | 1269 | deleteButton.setImage(DELETE_IMAGE); |
be222f56 PT |
1270 | deleteButton.setToolTipText(Messages.CustomXmlParserInputWizardPage_removeAttribute); |
1271 | deleteButton.addSelectionListener(new SelectionAdapter() { | |
1272 | @Override | |
1273 | public void widgetSelected(SelectionEvent e) { | |
1274 | Attribute.this.element.removeAttribute(Attribute.this.attributeNumber); | |
1275 | validate(); | |
1276 | updatePreviews(); | |
1277 | } | |
1278 | }); | |
1279 | ||
1280 | attributeLabel = new Label(labelComposite, SWT.NULL); | |
1281 | attributeLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false)); | |
1282 | attributeLabel.setText(Messages.CustomXmlParserInputWizardPage_attibute); | |
1283 | ||
1284 | attributeComposite = new Composite(parent, SWT.FILL); | |
1285 | GridLayout attributeLayout = new GridLayout(4, false); | |
1286 | attributeLayout.marginWidth = 0; | |
1287 | attributeLayout.marginHeight = 0; | |
1288 | attributeComposite.setLayout(attributeLayout); | |
1289 | attributeComposite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); | |
1290 | ||
1291 | Label nameLabel = new Label(attributeComposite, SWT.NONE); | |
1292 | nameLabel.setText(Messages.CustomXmlParserInputWizardPage_name); | |
1293 | ||
1294 | attributeNameText = new Text(attributeComposite, SWT.BORDER | SWT.SINGLE); | |
1295 | attributeNameText.setLayoutData(new GridData(120, SWT.DEFAULT)); | |
a7418109 | 1296 | attributeNameText.setText(inputAttribute.getAttributeName()); |
be222f56 PT |
1297 | attributeNameText.addModifyListener(updateListener); |
1298 | ||
1299 | Label previewLabel = new Label(attributeComposite, SWT.NONE); | |
1300 | previewLabel.setText(Messages.CustomXmlParserInputWizardPage_preview); | |
1301 | ||
1302 | previewText = new Text(attributeComposite, SWT.BORDER | SWT.SINGLE | SWT.READ_ONLY); | |
1303 | GridData gd = new GridData(SWT.FILL, SWT.CENTER, true, false); | |
1304 | gd.widthHint = 0; | |
1305 | previewText.setLayoutData(gd); | |
1306 | previewText.setText(Messages.CustomXmlParserInputWizardPage_noMatch); | |
1307 | previewText.setBackground(COLOR_WIDGET_BACKGROUND); | |
1308 | ||
1309 | filler = new Label(parent, SWT.NULL); | |
1310 | ||
1311 | tagComposite = new Composite(parent, SWT.FILL); | |
1312 | GridLayout tagLayout = new GridLayout(4, false); | |
1313 | tagLayout.marginWidth = 0; | |
1314 | tagLayout.marginHeight = 0; | |
1315 | tagComposite.setLayout(tagLayout); | |
1316 | tagComposite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); | |
1317 | ||
1318 | tagCombo = new Combo(tagComposite, SWT.DROP_DOWN | SWT.READ_ONLY); | |
1319 | tagCombo.setItems(new String[] { CustomTraceDefinition.TAG_TIMESTAMP, CustomTraceDefinition.TAG_MESSAGE, | |
1320 | CustomTraceDefinition.TAG_OTHER }); | |
1321 | tagCombo.select(2); // Other | |
1322 | tagCombo.addSelectionListener(new SelectionListener() { | |
1323 | @Override | |
1324 | public void widgetDefaultSelected(SelectionEvent e) { | |
1325 | } | |
1326 | ||
1327 | @Override | |
1328 | public void widgetSelected(SelectionEvent e) { | |
1329 | tagText.removeModifyListener(updateListener); | |
1330 | switch (tagCombo.getSelectionIndex()) { | |
1331 | case 0: // Time Stamp | |
1332 | tagLabel.setText(Messages.CustomXmlParserInputWizardPage_format); | |
1333 | tagLabel.setVisible(true); | |
1334 | tagText.setVisible(true); | |
1335 | tagText.addModifyListener(updateListener); | |
1336 | break; | |
1337 | case 1: // Message | |
1338 | tagLabel.setVisible(false); | |
1339 | tagText.setVisible(false); | |
1340 | break; | |
1341 | case 2: // Other | |
1342 | tagLabel.setText(Messages.CustomXmlParserInputWizardPage_tagName); | |
1343 | tagLabel.setVisible(true); | |
1344 | if (tagText.getText().trim().length() == 0) { | |
1345 | tagText.setText(attributeNameText.getText().trim()); | |
1346 | } | |
1347 | tagText.setVisible(true); | |
1348 | tagText.addModifyListener(updateListener); | |
1349 | break; | |
1350 | default: | |
1351 | break; | |
1352 | } | |
1353 | tagComposite.layout(); | |
1354 | validate(); | |
1355 | updatePreviews(); | |
1356 | } | |
1357 | }); | |
1358 | ||
1359 | tagLabel = new Label(tagComposite, SWT.NULL); | |
1360 | tagLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false)); | |
1361 | ||
1362 | tagText = new Text(tagComposite, SWT.BORDER | SWT.SINGLE); | |
1363 | gd = new GridData(SWT.FILL, SWT.CENTER, true, false); | |
1364 | gd.widthHint = 0; | |
1365 | tagText.setLayoutData(gd); | |
1366 | tagText.setText(attributeNameText.getText()); | |
1367 | ||
1368 | actionCombo = new Combo(tagComposite, SWT.DROP_DOWN | SWT.READ_ONLY); | |
1369 | actionCombo.setItems(new String[] { Messages.CustomXmlParserInputWizardPage_set, Messages.CustomXmlParserInputWizardPage_append, | |
1370 | Messages.CustomXmlParserInputWizardPage_appendWith }); | |
a7418109 | 1371 | actionCombo.select(inputAttribute.getInputAction()); |
be222f56 PT |
1372 | actionCombo.addSelectionListener(updateListener); |
1373 | ||
a7418109 | 1374 | if (inputAttribute.getInputName().equals(CustomTraceDefinition.TAG_TIMESTAMP)) { |
be222f56 PT |
1375 | tagCombo.select(0); |
1376 | tagLabel.setText(Messages.CustomXmlParserInputWizardPage_format); | |
a7418109 | 1377 | tagText.setText(inputAttribute.getInputFormat()); |
be222f56 | 1378 | tagText.addModifyListener(updateListener); |
a7418109 | 1379 | } else if (inputAttribute.getInputName().equals(CustomTraceDefinition.TAG_MESSAGE)) { |
be222f56 PT |
1380 | tagCombo.select(1); |
1381 | tagLabel.setVisible(false); | |
1382 | tagText.setVisible(false); | |
1383 | } else { | |
1384 | tagCombo.select(2); | |
1385 | tagLabel.setText(Messages.CustomXmlParserInputWizardPage_tagName); | |
a7418109 | 1386 | tagText.setText(inputAttribute.getInputName()); |
be222f56 PT |
1387 | tagText.addModifyListener(updateListener); |
1388 | } | |
1389 | } | |
1390 | ||
1391 | private void dispose() { | |
1392 | labelComposite.dispose(); | |
1393 | attributeComposite.dispose(); | |
1394 | filler.dispose(); | |
1395 | tagComposite.dispose(); | |
1396 | } | |
1397 | ||
1398 | private void setAttributeNumber(int attributeNumber) { | |
1399 | this.attributeNumber = attributeNumber; | |
1400 | labelComposite.layout(); | |
1401 | } | |
1402 | } | |
1403 | ||
a7418109 MK |
1404 | private Element getPreviewElement(CustomXmlInputElement inputElement) { |
1405 | CustomXmlInputElement currentElement = inputElement; | |
be222f56 PT |
1406 | Element element = documentElement; |
1407 | if (element != null) { | |
a7418109 | 1408 | if (!documentElement.getNodeName().equals(definition.rootInputElement.getElementName())) { |
be222f56 PT |
1409 | return null; |
1410 | } | |
507b1336 | 1411 | ArrayList<String> elementNames = new ArrayList<>(); |
41b5c37f | 1412 | while (currentElement != null) { |
a7418109 MK |
1413 | elementNames.add(currentElement.getElementName()); |
1414 | currentElement = currentElement.getParentElement(); | |
be222f56 PT |
1415 | } |
1416 | for (int i = elementNames.size() - 1; --i >= 0;) { | |
1417 | NodeList childList = element.getChildNodes(); | |
1418 | element = null; | |
1419 | for (int j = 0; j < childList.getLength(); j++) { | |
1420 | Node child = childList.item(j); | |
1421 | if (child instanceof Element && child.getNodeName().equals(elementNames.get(i))) { | |
1422 | element = (Element) child; | |
1423 | break; | |
1424 | } | |
1425 | } | |
1426 | if (element == null) { | |
1427 | break; | |
1428 | } | |
1429 | } | |
1430 | if (element != null) { | |
1431 | return element; | |
1432 | } | |
1433 | } | |
1434 | return null; | |
1435 | } | |
1436 | ||
a7418109 | 1437 | private String getChildNameSuggestion(CustomXmlInputElement inputElement) { |
be222f56 PT |
1438 | if (inputElement == null) { |
1439 | if (documentElement != null) { | |
1440 | return documentElement.getNodeName(); | |
1441 | } | |
1442 | } else { | |
1443 | Element element = getPreviewElement(inputElement); | |
1444 | if (element != null) { | |
1445 | NodeList childNodes = element.getChildNodes(); | |
1446 | for (int i = 0; i < childNodes.getLength(); i++) { | |
1447 | Node node = childNodes.item(i); | |
1448 | if (node instanceof Element) { | |
1449 | boolean unused = true; | |
a7418109 MK |
1450 | if (inputElement.getChildElements() != null) { |
1451 | for (CustomXmlInputElement child : inputElement.getChildElements()) { | |
1452 | if (child.getElementName().equals(node.getNodeName())) { | |
be222f56 PT |
1453 | unused = false; |
1454 | break; | |
1455 | } | |
1456 | } | |
1457 | } | |
1458 | if (unused) { | |
1459 | return node.getNodeName(); | |
1460 | } | |
1461 | } | |
1462 | } | |
1463 | } | |
1464 | } | |
1465 | return ""; //$NON-NLS-1$ | |
1466 | } | |
1467 | ||
a7418109 | 1468 | private String getAttributeNameSuggestion(CustomXmlInputElement inputElement) { |
be222f56 PT |
1469 | Element element = getPreviewElement(inputElement); |
1470 | if (element != null) { | |
1471 | NamedNodeMap attributeMap = element.getAttributes(); | |
1472 | for (int i = 0; i < attributeMap.getLength(); i++) { | |
1473 | Node node = attributeMap.item(i); | |
1474 | boolean unused = true; | |
a7418109 MK |
1475 | if (inputElement.getAttributes() != null) { |
1476 | for (CustomXmlInputAttribute attribute : inputElement.getAttributes()) { | |
1477 | if (attribute.getAttributeName().equals(node.getNodeName())) { | |
be222f56 PT |
1478 | unused = false; |
1479 | break; | |
1480 | } | |
1481 | } | |
1482 | } | |
1483 | if (unused) { | |
1484 | return node.getNodeName(); | |
1485 | } | |
1486 | } | |
1487 | } | |
1488 | return ""; //$NON-NLS-1$ | |
1489 | } | |
1490 | ||
1491 | private void validate() { | |
c22ca172 | 1492 | definition.categoryName = categoryText.getText().trim(); |
be222f56 PT |
1493 | definition.definitionName = logtypeText.getText().trim(); |
1494 | definition.timeStampOutputFormat = timeStampOutputFormatText.getText().trim(); | |
1495 | ||
1496 | if (selectedElement != null) { | |
1497 | selectedElement.extractInputs(); | |
1498 | treeViewer.refresh(); | |
1499 | } | |
1500 | ||
89151d6a | 1501 | List<String> errors = new ArrayList<>(); |
be222f56 | 1502 | |
c22ca172 | 1503 | if (definition.categoryName.length() == 0) { |
89151d6a | 1504 | errors.add(Messages.CustomXmlParserInputWizardPage_emptyCategoryError); |
c22ca172 PT |
1505 | categoryText.setBackground(COLOR_LIGHT_RED); |
1506 | } else if (definition.definitionName.length() == 0) { | |
89151d6a | 1507 | errors.add(Messages.CustomXmlParserInputWizardPage_emptyLogTypeError); |
be222f56 PT |
1508 | logtypeText.setBackground(COLOR_LIGHT_RED); |
1509 | } else { | |
c22ca172 | 1510 | categoryText.setBackground(COLOR_TEXT_BACKGROUND); |
be222f56 | 1511 | logtypeText.setBackground(COLOR_TEXT_BACKGROUND); |
c22ca172 | 1512 | if (definition.categoryName.indexOf(':') != -1) { |
89151d6a | 1513 | errors.add(Messages.CustomXmlParserInputWizardPage_invalidCategoryError); |
c22ca172 PT |
1514 | categoryText.setBackground(COLOR_LIGHT_RED); |
1515 | } | |
1516 | if (definition.definitionName.indexOf(':') != -1) { | |
89151d6a | 1517 | errors.add(Messages.CustomXmlParserInputWizardPage_invalidLogTypeError); |
c22ca172 PT |
1518 | logtypeText.setBackground(COLOR_LIGHT_RED); |
1519 | } | |
1520 | for (TraceTypeHelper helper : TmfTraceType.getTraceTypeHelpers()) { | |
1521 | if (definition.categoryName.equals(helper.getCategoryName()) && | |
1522 | definition.definitionName.equals(helper.getName()) && | |
1523 | (editDefinitionName == null || !editDefinitionName.equals(definition.definitionName)) && | |
1524 | (editCategoryName == null || !editCategoryName.equals(definition.categoryName))) { | |
89151d6a | 1525 | errors.add(Messages.CustomXmlParserInputWizardPage_duplicatelogTypeError); |
f6aa55e2 PT |
1526 | logtypeText.setBackground(COLOR_LIGHT_RED); |
1527 | break; | |
be222f56 PT |
1528 | } |
1529 | } | |
1530 | } | |
1531 | ||
1532 | if (definition.rootInputElement == null) { | |
89151d6a | 1533 | errors.add(Messages.CustomXmlParserInputWizardPage_noDocumentError); |
be222f56 PT |
1534 | } |
1535 | ||
1536 | if (definition.rootInputElement != null) { | |
1537 | logEntryFound = false; | |
1538 | timeStampFound = false; | |
1539 | ||
89151d6a | 1540 | errors.addAll(validateElement(definition.rootInputElement)); |
be222f56 | 1541 | |
a7418109 MK |
1542 | if ((definition.rootInputElement.getAttributes() != null && definition.rootInputElement.getAttributes().size() != 0) |
1543 | || (definition.rootInputElement.getChildElements() != null && definition.rootInputElement.getChildElements().size() != 0) | |
89151d6a | 1544 | || errors.size() == 0) { |
be222f56 | 1545 | if (!logEntryFound) { |
89151d6a | 1546 | errors.add(Messages.CustomXmlParserInputWizardPage_missingLogEntryError); |
be222f56 PT |
1547 | } |
1548 | ||
1549 | if (timeStampFound) { | |
1550 | if (timeStampOutputFormatText.getText().trim().length() == 0) { | |
89151d6a | 1551 | errors.add(Messages.CustomXmlParserInputWizardPage_missingTimestampFmtError); |
be222f56 PT |
1552 | timeStampOutputFormatText.setBackground(COLOR_LIGHT_RED); |
1553 | } else { | |
1554 | try { | |
738beb68 | 1555 | new TmfTimestampFormat(timeStampOutputFormatText.getText().trim()); |
be222f56 PT |
1556 | timeStampOutputFormatText.setBackground(COLOR_TEXT_BACKGROUND); |
1557 | } catch (IllegalArgumentException e) { | |
89151d6a | 1558 | errors.add(Messages.CustomXmlParserInputWizardPage_elementInvalidTimestampFmtError); |
be222f56 PT |
1559 | timeStampOutputFormatText.setBackground(COLOR_LIGHT_RED); |
1560 | } | |
1561 | } | |
1562 | } else { | |
89151d6a | 1563 | timeStampPreviewText.setText(Messages.CustomXmlParserInputWizardPage_noTimestampElementOrAttribute); |
be222f56 PT |
1564 | } |
1565 | } | |
1566 | } else { | |
89151d6a | 1567 | timeStampPreviewText.setText(Messages.CustomXmlParserInputWizardPage_noTimestampElementOrAttribute); |
be222f56 PT |
1568 | } |
1569 | ||
89151d6a | 1570 | if (errors.size() == 0) { |
be222f56 PT |
1571 | setDescription(defaultDescription); |
1572 | setPageComplete(true); | |
1573 | } else { | |
89151d6a | 1574 | setDescription(Joiner.on(' ').join(errors)); |
be222f56 PT |
1575 | setPageComplete(false); |
1576 | } | |
1577 | } | |
1578 | ||
a0a88f65 AM |
1579 | /** |
1580 | * Clean up the specified XML element. | |
1581 | * | |
1582 | * @param inputElement | |
1583 | * The element to clean up | |
1584 | * @return The validated element | |
1585 | */ | |
a7418109 | 1586 | public List<String> validateElement(CustomXmlInputElement inputElement) { |
89151d6a | 1587 | List<String> errors = new ArrayList<>(); |
be222f56 PT |
1588 | ElementNode elementNode = null; |
1589 | if (selectedElement != null && selectedElement.inputElement.equals(inputElement)) { | |
1590 | elementNode = selectedElement; | |
1591 | } | |
1592 | if (inputElement == definition.rootInputElement) { | |
a7418109 | 1593 | if (inputElement.getElementName().length() == 0) { |
89151d6a | 1594 | errors.add(Messages.CustomXmlParserInputWizardPage_missingDocumentElementError); |
be222f56 PT |
1595 | if (elementNode != null) { |
1596 | elementNode.elementNameText.setBackground(COLOR_LIGHT_RED); | |
1597 | } | |
1598 | } else { | |
1599 | if (elementNode != null) { | |
1600 | elementNode.elementNameText.setBackground(COLOR_TEXT_BACKGROUND); | |
1601 | } | |
1602 | } | |
1603 | } | |
1604 | if (inputElement != definition.rootInputElement) { | |
a7418109 | 1605 | if (inputElement.isLogEntry()) { |
be222f56 PT |
1606 | logEntryFound = true; |
1607 | } | |
a7418109 | 1608 | if (inputElement.getInputName().equals(CustomTraceDefinition.TAG_TIMESTAMP)) { |
be222f56 | 1609 | timeStampFound = true; |
a7418109 | 1610 | if (inputElement.getInputFormat().length() == 0) { |
89151d6a | 1611 | errors.add(NLS.bind(Messages.CustomXmlParserInputWizardPage_elementMissingTimestampFmtError, getName(inputElement))); |
be222f56 PT |
1612 | if (elementNode != null) { |
1613 | elementNode.tagText.setBackground(COLOR_LIGHT_RED); | |
1614 | } | |
1615 | } else { | |
1616 | try { | |
a7418109 | 1617 | new TmfTimestampFormat(inputElement.getInputFormat()); |
be222f56 PT |
1618 | if (elementNode != null) { |
1619 | elementNode.tagText.setBackground(COLOR_TEXT_BACKGROUND); | |
1620 | } | |
1621 | } catch (IllegalArgumentException e) { | |
89151d6a | 1622 | errors.add(NLS.bind(Messages.CustomXmlParserInputWizardPage_elementInvalidTimestampFmtError, getName(inputElement))); |
be222f56 PT |
1623 | if (elementNode != null) { |
1624 | elementNode.tagText.setBackground(COLOR_LIGHT_RED); | |
1625 | } | |
1626 | } | |
1627 | } | |
a7418109 | 1628 | } else if (inputElement.getInputName().length() == 0) { |
89151d6a | 1629 | errors.add(NLS.bind(Messages.CustomXmlParserInputWizardPage_elementMissingInputNameError, getName(inputElement))); |
be222f56 PT |
1630 | if (elementNode != null) { |
1631 | elementNode.tagText.setBackground(COLOR_LIGHT_RED); | |
1632 | } | |
1633 | } else { | |
1634 | if (elementNode != null) { | |
1635 | elementNode.tagText.setBackground(COLOR_TEXT_BACKGROUND); | |
1636 | } | |
1637 | } | |
1638 | } | |
a7418109 | 1639 | if (inputElement.getAttributes() != null) { |
be222f56 PT |
1640 | if (elementNode != null) { |
1641 | for (Attribute attribute : elementNode.attributes) { | |
1642 | attribute.attributeNameText.setBackground(COLOR_TEXT_BACKGROUND); | |
1643 | } | |
1644 | } | |
a7418109 MK |
1645 | for (int i = 0; i < inputElement.getAttributes().size(); i++) { |
1646 | CustomXmlInputAttribute attribute = inputElement.getAttributes().get(i); | |
be222f56 | 1647 | boolean duplicate = false; |
a7418109 MK |
1648 | for (int j = i + 1; j < inputElement.getAttributes().size(); j++) { |
1649 | CustomXmlInputAttribute otherAttribute = inputElement.getAttributes().get(j); | |
1650 | if (otherAttribute.getAttributeName().equals(attribute.getAttributeName())) { | |
be222f56 PT |
1651 | duplicate = true; |
1652 | if (elementNode != null) { | |
1653 | elementNode.attributes.get(j).attributeNameText.setBackground(COLOR_LIGHT_RED); | |
1654 | } | |
1655 | } | |
1656 | } | |
a7418109 | 1657 | if (attribute.getAttributeName().length() == 0) { |
89151d6a | 1658 | errors.add(NLS.bind(Messages.CustomXmlParserInputWizardPage_attributeMissingNameError, getName(inputElement))); |
be222f56 PT |
1659 | if (elementNode != null) { |
1660 | elementNode.attributes.get(i).attributeNameText.setBackground(COLOR_LIGHT_RED); | |
1661 | } | |
1662 | } else if (duplicate) { | |
89151d6a | 1663 | errors.add(NLS.bind(Messages.CustomXmlParserInputWizardPage_attributeDuplicateNameError, getName(attribute, inputElement))); |
be222f56 PT |
1664 | if (elementNode != null) { |
1665 | elementNode.attributes.get(i).attributeNameText.setBackground(COLOR_LIGHT_RED); | |
1666 | } | |
1667 | } | |
a7418109 | 1668 | if (attribute.getInputName().equals(CustomTraceDefinition.TAG_TIMESTAMP)) { |
be222f56 | 1669 | timeStampFound = true; |
a7418109 | 1670 | if (attribute.getInputFormat().length() == 0) { |
89151d6a | 1671 | errors.add(NLS.bind(Messages.CustomXmlParserInputWizardPage_attributeMissingTimestampFmtError, getName(attribute, inputElement))); |
be222f56 PT |
1672 | if (elementNode != null) { |
1673 | elementNode.attributes.get(i).tagText.setBackground(COLOR_LIGHT_RED); | |
1674 | } | |
1675 | } else { | |
1676 | try { | |
a7418109 | 1677 | new TmfTimestampFormat(attribute.getInputFormat()); |
be222f56 PT |
1678 | if (elementNode != null) { |
1679 | elementNode.attributes.get(i).tagText.setBackground(COLOR_TEXT_BACKGROUND); | |
1680 | } | |
1681 | } catch (IllegalArgumentException e) { | |
89151d6a | 1682 | errors.add(NLS.bind(Messages.CustomXmlParserInputWizardPage_attributeInvalidTimestampFmtError, getName(attribute, inputElement))); |
be222f56 PT |
1683 | if (elementNode != null) { |
1684 | elementNode.attributes.get(i).tagText.setBackground(COLOR_LIGHT_RED); | |
1685 | } | |
1686 | } | |
1687 | } | |
a7418109 | 1688 | } else if (attribute.getInputName().length() == 0) { |
89151d6a | 1689 | errors.add(NLS.bind(Messages.CustomXmlParserInputWizardPage_attributeMissingInputNameError, getName(attribute, inputElement))); |
be222f56 PT |
1690 | if (elementNode != null) { |
1691 | elementNode.attributes.get(i).tagText.setBackground(COLOR_LIGHT_RED); | |
1692 | } | |
1693 | } else { | |
1694 | if (elementNode != null) { | |
1695 | elementNode.attributes.get(i).tagText.setBackground(COLOR_TEXT_BACKGROUND); | |
1696 | } | |
1697 | } | |
1698 | } | |
1699 | } | |
a7418109 MK |
1700 | if (inputElement.getChildElements() != null) { |
1701 | for (CustomXmlInputElement child : inputElement.getChildElements()) { | |
be222f56 PT |
1702 | ElementNode childElementNode = null; |
1703 | if (selectedElement != null && selectedElement.inputElement.equals(child)) { | |
1704 | childElementNode = selectedElement; | |
1705 | } | |
1706 | if (childElementNode != null) { | |
1707 | childElementNode.elementNameText.setBackground(COLOR_TEXT_BACKGROUND); | |
1708 | } | |
1709 | } | |
a7418109 MK |
1710 | for (int i = 0; i < inputElement.getChildElements().size(); i++) { |
1711 | CustomXmlInputElement child = inputElement.getChildElements().get(i); | |
be222f56 PT |
1712 | ElementNode childElementNode = null; |
1713 | if (selectedElement != null && selectedElement.inputElement.equals(child)) { | |
1714 | childElementNode = selectedElement; | |
1715 | } | |
a7418109 | 1716 | if (child.getElementName().length() == 0) { |
89151d6a | 1717 | errors.add(NLS.bind(Messages.CustomXmlParserInputWizardPage_elementMissingNameError, getName(child))); |
be222f56 PT |
1718 | if (childElementNode != null) { |
1719 | childElementNode.elementNameText.setBackground(COLOR_LIGHT_RED); | |
1720 | } | |
1721 | } else { | |
1722 | boolean duplicate = false; | |
a7418109 MK |
1723 | for (int j = i + 1; j < inputElement.getChildElements().size(); j++) { |
1724 | CustomXmlInputElement otherChild = inputElement.getChildElements().get(j); | |
1725 | if (otherChild.getElementName().equals(child.getElementName())) { | |
be222f56 PT |
1726 | duplicate = true; |
1727 | ElementNode otherChildElementNode = null; | |
1728 | if (selectedElement != null && selectedElement.inputElement.equals(otherChild)) { | |
1729 | otherChildElementNode = selectedElement; | |
1730 | } | |
1731 | if (otherChildElementNode != null) { | |
1732 | otherChildElementNode.elementNameText.setBackground(COLOR_LIGHT_RED); | |
1733 | } | |
1734 | } | |
1735 | } | |
1736 | if (duplicate) { | |
89151d6a | 1737 | errors.add(NLS.bind(Messages.CustomXmlParserInputWizardPage_elementDuplicateNameError, getName(child))); |
be222f56 PT |
1738 | if (childElementNode != null) { |
1739 | childElementNode.elementNameText.setBackground(COLOR_LIGHT_RED); | |
1740 | } | |
1741 | } | |
1742 | } | |
1743 | ||
89151d6a | 1744 | errors.addAll(validateElement(child)); |
be222f56 PT |
1745 | } |
1746 | } | |
1747 | return errors; | |
1748 | } | |
1749 | ||
a0a88f65 AM |
1750 | /** |
1751 | * Get the trace definition. | |
1752 | * | |
1753 | * @return The trace definition | |
1754 | */ | |
be222f56 PT |
1755 | public CustomXmlTraceDefinition getDefinition() { |
1756 | return definition; | |
1757 | } | |
1758 | ||
a0a88f65 AM |
1759 | /** |
1760 | * Get the raw text input. | |
1761 | * | |
1762 | * @return The raw text input. | |
1763 | */ | |
be222f56 PT |
1764 | public char[] getInputText() { |
1765 | return inputText.getText().toCharArray(); | |
1766 | } | |
1767 | } |