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