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