Commit | Line | Data |
---|---|---|
12c155f5 | 1 | package org.eclipse.linuxtools.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 | |
30 | import org.eclipse.linuxtools.tmf.ui.TmfUiPlugin;\r | |
7995b722 | 31 | import org.eclipse.linuxtools.tmf.ui.internal.Messages;\r |
c3c5c786 FC |
32 | import org.eclipse.linuxtools.tmf.ui.parsers.custom.CustomXmlTrace;\r |
33 | import org.eclipse.linuxtools.tmf.ui.parsers.custom.CustomXmlTraceDefinition;\r | |
34 | import org.eclipse.linuxtools.tmf.ui.parsers.custom.CustomXmlTraceDefinition.InputAttribute;\r | |
35 | import org.eclipse.linuxtools.tmf.ui.parsers.custom.CustomXmlTraceDefinition.InputElement;\r | |
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 | |
d7fcacc9 FC |
79 | private static final Image elementImage = TmfUiPlugin.getDefault().getImageFromPath("/icons/elcl16/element_icon.gif"); //$NON-NLS-1$\r |
80 | private static final Image addImage = TmfUiPlugin.getDefault().getImageFromPath("/icons/elcl16/add_button.gif"); //$NON-NLS-1$\r | |
81 | private static final Image addNextImage = TmfUiPlugin.getDefault().getImageFromPath("/icons/elcl16/addnext_button.gif"); //$NON-NLS-1$\r | |
82 | private static final Image addChildImage = TmfUiPlugin.getDefault().getImageFromPath("/icons/elcl16/addchild_button.gif"); //$NON-NLS-1$\r | |
83 | private static final Image addManyImage = TmfUiPlugin.getDefault().getImageFromPath("/icons/elcl16/addmany_button.gif"); //$NON-NLS-1$\r | |
84 | private static final Image deleteImage = TmfUiPlugin.getDefault().getImageFromPath("/icons/elcl16/delete_button.gif"); //$NON-NLS-1$\r | |
85 | private static final Image moveUpImage = TmfUiPlugin.getDefault().getImageFromPath("/icons/elcl16/moveup_button.gif"); //$NON-NLS-1$\r | |
86 | private static final Image moveDownImage = TmfUiPlugin.getDefault().getImageFromPath("/icons/elcl16/movedown_button.gif"); //$NON-NLS-1$\r | |
87 | private static final Image helpImage = TmfUiPlugin.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 |
c3c5c786 FC |
467 | private class InputElementTreeNodeContentProvider implements ITreeContentProvider {\r |
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 |
c3c5c786 FC |
508 | private class InputElementTreeLabelProvider extends ColumnLabelProvider {\r |
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 | |
669 | try {\r | |
670 | BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));\r | |
671 | StringBuilder sb = new StringBuilder();\r | |
672 | String line = null;\r | |
673 | while ((line = reader.readLine()) != null) {\r | |
3b38ea61 | 674 | sb.append(line + "\n"); //$NON-NLS-1$\r |
c3c5c786 FC |
675 | }\r |
676 | parseXmlInput(sb.toString());\r | |
677 | return sb.toString();\r | |
678 | } catch (IOException e) {\r | |
3b38ea61 | 679 | return ""; //$NON-NLS-1$\r |
c3c5c786 FC |
680 | }\r |
681 | }\r | |
3b38ea61 | 682 | return ""; //$NON-NLS-1$\r |
c3c5c786 | 683 | }\r |
a1d78b76 | 684 | \r |
c3c5c786 FC |
685 | private void parseXmlInput(final String string) {\r |
686 | try {\r | |
687 | DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();\r | |
688 | DocumentBuilder db = dbf.newDocumentBuilder();\r | |
689 | \r | |
690 | // The following allows xml parsing without access to the dtd\r | |
a1d78b76 FC |
691 | EntityResolver resolver = new EntityResolver() {\r |
692 | @Override\r | |
693 | public InputSource resolveEntity(String publicId, String systemId) {\r | |
3b38ea61 | 694 | String empty = ""; //$NON-NLS-1$\r |
c3c5c786 FC |
695 | ByteArrayInputStream bais = new ByteArrayInputStream(empty.getBytes());\r |
696 | return new InputSource(bais);\r | |
697 | }\r | |
698 | };\r | |
699 | db.setEntityResolver(resolver);\r | |
700 | \r | |
701 | // The following catches xml parsing exceptions\r | |
a1d78b76 FC |
702 | db.setErrorHandler(new ErrorHandler() {\r |
703 | @Override\r | |
704 | public void error(SAXParseException saxparseexception) throws SAXException {\r | |
705 | }\r | |
706 | \r | |
707 | @Override\r | |
708 | public void warning(SAXParseException saxparseexception) throws SAXException {\r | |
709 | }\r | |
710 | \r | |
711 | @Override\r | |
c3c5c786 FC |
712 | public void fatalError(SAXParseException saxparseexception) throws SAXException {\r |
713 | if (string.trim().length() != 0) {\r | |
714 | errorText.setText(saxparseexception.getMessage());\r | |
715 | errorText.setBackground(COLOR_LIGHT_RED);\r | |
716 | errorText.setVisible(true);\r | |
717 | }\r | |
718 | throw saxparseexception;\r | |
a1d78b76 FC |
719 | }\r |
720 | });\r | |
721 | \r | |
c3c5c786 FC |
722 | errorText.setVisible(false);\r |
723 | Document doc = null;\r | |
724 | doc = db.parse(new ByteArrayInputStream(string.getBytes()));\r | |
725 | documentElement = doc.getDocumentElement();\r | |
726 | } catch (ParserConfigurationException e) {\r | |
727 | e.printStackTrace();\r | |
728 | documentElement = null;\r | |
729 | } catch (SAXException e) {\r | |
730 | documentElement = null;\r | |
731 | } catch (IOException e) {\r | |
732 | e.printStackTrace();\r | |
733 | documentElement = null;\r | |
734 | }\r | |
735 | }\r | |
736 | \r | |
737 | private void updatePreviews() {\r | |
738 | updatePreviews(false);\r | |
739 | }\r | |
740 | \r | |
741 | private void updatePreviews(boolean updateAll) {\r | |
742 | if (inputText == null) {\r | |
743 | // early update during construction\r | |
744 | return;\r | |
745 | }\r | |
746 | inputText.setStyleRanges(new StyleRange[] {});\r | |
747 | if (selectedElement == null) {\r | |
748 | return;\r | |
749 | }\r | |
a1d78b76 | 750 | \r |
c3c5c786 FC |
751 | timeStampValue = null;\r |
752 | timeStampFormat = null;\r | |
753 | logEntriesCount = 0;\r | |
754 | logEntryFound = false;\r | |
a1d78b76 | 755 | \r |
c3c5c786 FC |
756 | selectedElement.updatePreview();\r |
757 | \r | |
758 | if (timeStampValue != null && timeStampFormat != null) {\r | |
759 | try {\r | |
760 | SimpleDateFormat dateFormat = new SimpleDateFormat(timeStampFormat);\r | |
761 | Date date = dateFormat.parse(timeStampValue);\r | |
762 | dateFormat = new SimpleDateFormat(timeStampOutputFormatText.getText().trim());\r | |
763 | timeStampPreviewText.setText(dateFormat.format(date));\r | |
764 | } catch (ParseException e) {\r | |
3b38ea61 | 765 | timeStampPreviewText.setText("*parse exception* [" + timeStampValue + "] <> [" + timeStampFormat + "]"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$\r |
c3c5c786 | 766 | } catch (IllegalArgumentException e) {\r |
3b38ea61 | 767 | timeStampPreviewText.setText("*parse exception* [Illegal Argument]"); //$NON-NLS-1$\r |
c3c5c786 FC |
768 | }\r |
769 | } else {\r | |
3b38ea61 | 770 | timeStampPreviewText.setText("*no matching time stamp*"); //$NON-NLS-1$\r |
c3c5c786 FC |
771 | }\r |
772 | }\r | |
773 | \r | |
774 | private void openHelpShell(String url) {\r | |
775 | if (helpBrowser != null && !helpBrowser.isDisposed()) {\r | |
776 | helpBrowser.getShell().setActive();\r | |
777 | if (!helpBrowser.getUrl().equals(url)) {\r | |
778 | helpBrowser.setUrl(url);\r | |
779 | }\r | |
780 | return;\r | |
781 | }\r | |
782 | final Shell helpShell = new Shell(getShell(), SWT.SHELL_TRIM);\r | |
783 | helpShell.setLayout(new FillLayout());\r | |
784 | helpBrowser = new Browser(helpShell, SWT.NONE);\r | |
785 | helpBrowser.addTitleListener(new TitleListener() {\r | |
a1d78b76 FC |
786 | @Override\r |
787 | public void changed(TitleEvent event) {\r | |
788 | helpShell.setText(event.title);\r | |
789 | }\r | |
c3c5c786 | 790 | });\r |
a1d78b76 | 791 | helpBrowser.setBounds(0, 0, 600, 400);\r |
c3c5c786 FC |
792 | helpShell.pack();\r |
793 | helpShell.open();\r | |
794 | helpBrowser.setUrl(url);\r | |
795 | }\r | |
796 | \r | |
797 | private class UpdateListener implements ModifyListener, SelectionListener {\r | |
798 | \r | |
a1d78b76 | 799 | @Override\r |
c3c5c786 FC |
800 | public void modifyText(ModifyEvent e) {\r |
801 | validate();\r | |
802 | updatePreviews();\r | |
803 | }\r | |
804 | \r | |
a1d78b76 | 805 | @Override\r |
c3c5c786 FC |
806 | public void widgetDefaultSelected(SelectionEvent e) {\r |
807 | validate();\r | |
808 | updatePreviews();\r | |
809 | }\r | |
810 | \r | |
a1d78b76 | 811 | @Override\r |
c3c5c786 FC |
812 | public void widgetSelected(SelectionEvent e) {\r |
813 | validate();\r | |
814 | updatePreviews();\r | |
815 | }\r | |
816 | \r | |
817 | }\r | |
a1d78b76 | 818 | \r |
c3c5c786 FC |
819 | private class ElementNode {\r |
820 | final InputElement inputElement;\r | |
821 | final Group group;\r | |
822 | ArrayList<Attribute> attributes = new ArrayList<Attribute>();\r | |
823 | ArrayList<ElementNode> childElements = new ArrayList<ElementNode>();\r | |
824 | Text elementNameText;\r | |
825 | Composite tagComposite;\r | |
826 | Combo tagCombo;\r | |
827 | Label tagLabel;\r | |
828 | Text tagText;\r | |
829 | Combo actionCombo;\r | |
830 | Label previewLabel;\r | |
831 | Text previewText;\r | |
832 | Button logEntryButton;\r | |
833 | Label fillerLabel;\r | |
834 | Composite addAttributeComposite;\r | |
835 | Button addAttributeButton;\r | |
836 | Label addAttributeLabel;\r | |
a1d78b76 | 837 | \r |
c3c5c786 FC |
838 | public ElementNode(Composite parent, InputElement inputElement) {\r |
839 | this.inputElement = inputElement;\r | |
a1d78b76 | 840 | \r |
c3c5c786 FC |
841 | group = new Group(parent, SWT.NONE);\r |
842 | GridLayout gl = new GridLayout(2, false);\r | |
843 | gl.marginHeight = 0;\r | |
844 | group.setLayout(gl);\r | |
845 | group.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));\r | |
846 | group.setText(getName(inputElement));\r | |
a1d78b76 | 847 | \r |
c3c5c786 | 848 | Label label = new Label(group, SWT.NULL);\r |
3b38ea61 | 849 | label.setText(Messages.CustomXmlParserInputWizardPage_elementName);\r |
c3c5c786 | 850 | label.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));\r |
a1d78b76 | 851 | \r |
c3c5c786 FC |
852 | elementNameText = new Text(group, SWT.BORDER | SWT.SINGLE);\r |
853 | GridData gd = new GridData(SWT.FILL, SWT.CENTER, true, false);\r | |
854 | gd.widthHint = 0;\r | |
855 | elementNameText.setLayoutData(gd);\r | |
a1d78b76 FC |
856 | elementNameText.addModifyListener(new ModifyListener() {\r |
857 | @Override\r | |
c3c5c786 FC |
858 | public void modifyText(ModifyEvent e) {\r |
859 | ElementNode.this.inputElement.elementName = elementNameText.getText().trim();\r | |
860 | group.setText(getName(ElementNode.this.inputElement));\r | |
a1d78b76 FC |
861 | }\r |
862 | });\r | |
c3c5c786 FC |
863 | elementNameText.setText(inputElement.elementName);\r |
864 | elementNameText.addModifyListener(updateListener);\r | |
865 | \r | |
866 | if (inputElement.parentElement != null) {\r | |
867 | previewLabel = new Label(group, SWT.NULL);\r | |
868 | previewLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));\r | |
3b38ea61 | 869 | previewLabel.setText(Messages.CustomXmlParserInputWizardPage_preview);\r |
a1d78b76 | 870 | \r |
c3c5c786 FC |
871 | previewText = new Text(group, SWT.BORDER | SWT.SINGLE | SWT.READ_ONLY);\r |
872 | gd = new GridData(SWT.FILL, SWT.CENTER, true, false);\r | |
873 | gd.widthHint = 0;\r | |
874 | previewText.setLayoutData(gd);\r | |
3b38ea61 | 875 | previewText.setText(Messages.CustomXmlParserInputWizardPage_noMatchingElement);\r |
c3c5c786 | 876 | previewText.setBackground(COLOR_WIDGET_BACKGROUND);\r |
a1d78b76 | 877 | \r |
c3c5c786 | 878 | logEntryButton = new Button(group, SWT.CHECK);\r |
3b38ea61 | 879 | logEntryButton.setText(Messages.CustomXmlParserInputWizardPage_logEntry);\r |
c3c5c786 | 880 | logEntryButton.setSelection(inputElement.logEntry);\r |
a1d78b76 FC |
881 | logEntryButton.addSelectionListener(new SelectionListener() {\r |
882 | @Override\r | |
883 | public void widgetDefaultSelected(SelectionEvent e) {\r | |
884 | }\r | |
885 | \r | |
886 | @Override\r | |
c3c5c786 FC |
887 | public void widgetSelected(SelectionEvent e) {\r |
888 | InputElement parent = ElementNode.this.inputElement.parentElement;\r | |
889 | while (parent != null) {\r | |
890 | parent.logEntry = false;\r | |
891 | parent = parent.parentElement;\r | |
892 | }\r | |
a1d78b76 FC |
893 | }\r |
894 | });\r | |
c3c5c786 | 895 | logEntryButton.addSelectionListener(updateListener);\r |
a1d78b76 | 896 | \r |
c3c5c786 FC |
897 | tagComposite = new Composite(group, SWT.FILL);\r |
898 | GridLayout tagLayout = new GridLayout(4, false);\r | |
899 | tagLayout.marginWidth = 0;\r | |
900 | tagLayout.marginHeight = 0;\r | |
901 | tagComposite.setLayout(tagLayout);\r | |
902 | tagComposite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));\r | |
a1d78b76 | 903 | \r |
c3c5c786 | 904 | tagCombo = new Combo(tagComposite, SWT.DROP_DOWN | SWT.READ_ONLY);\r |
a1d78b76 FC |
905 | tagCombo.setItems(new String[] { CustomXmlTraceDefinition.TAG_IGNORE, CustomXmlTraceDefinition.TAG_TIMESTAMP,\r |
906 | CustomXmlTraceDefinition.TAG_MESSAGE, CustomXmlTraceDefinition.TAG_OTHER });\r | |
c3c5c786 | 907 | tagCombo.setVisibleItemCount(tagCombo.getItemCount());\r |
a1d78b76 FC |
908 | tagCombo.addSelectionListener(new SelectionListener() {\r |
909 | @Override\r | |
910 | public void widgetDefaultSelected(SelectionEvent e) {\r | |
911 | }\r | |
912 | \r | |
913 | @Override\r | |
c3c5c786 FC |
914 | public void widgetSelected(SelectionEvent e) {\r |
915 | tagText.removeModifyListener(updateListener);\r | |
916 | switch (tagCombo.getSelectionIndex()) {\r | |
a1d78b76 FC |
917 | case 0: // Ignore\r |
918 | tagLabel.setVisible(false);\r | |
919 | tagText.setVisible(false);\r | |
920 | actionCombo.setVisible(false);\r | |
921 | break;\r | |
922 | case 1: // Time Stamp\r | |
923 | tagLabel.setText(Messages.CustomXmlParserInputWizardPage_format);\r | |
924 | tagLabel.setVisible(true);\r | |
925 | tagText.setVisible(true);\r | |
926 | tagText.addModifyListener(updateListener);\r | |
927 | actionCombo.setVisible(true);\r | |
928 | break;\r | |
929 | case 2: // Message\r | |
930 | tagLabel.setVisible(false);\r | |
931 | tagText.setVisible(false);\r | |
932 | actionCombo.setVisible(true);\r | |
933 | break;\r | |
934 | case 3: // Other\r | |
935 | tagLabel.setText(Messages.CustomXmlParserInputWizardPage_tagName);\r | |
936 | tagLabel.setVisible(true);\r | |
937 | if (tagText.getText().trim().length() == 0) {\r | |
938 | tagText.setText(elementNameText.getText().trim());\r | |
939 | }\r | |
940 | tagText.setVisible(true);\r | |
941 | tagText.addModifyListener(updateListener);\r | |
942 | actionCombo.setVisible(true);\r | |
943 | break;\r | |
c3c5c786 FC |
944 | }\r |
945 | tagComposite.layout();\r | |
946 | validate();\r | |
947 | updatePreviews();\r | |
a1d78b76 FC |
948 | }\r |
949 | });\r | |
950 | \r | |
c3c5c786 FC |
951 | tagLabel = new Label(tagComposite, SWT.NULL);\r |
952 | tagLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));\r | |
a1d78b76 | 953 | \r |
c3c5c786 FC |
954 | tagText = new Text(tagComposite, SWT.BORDER | SWT.SINGLE);\r |
955 | gd = new GridData(SWT.FILL, SWT.CENTER, true, false);\r | |
956 | gd.widthHint = 0;\r | |
957 | tagText.setLayoutData(gd);\r | |
a1d78b76 | 958 | \r |
c3c5c786 | 959 | actionCombo = new Combo(tagComposite, SWT.DROP_DOWN | SWT.READ_ONLY);\r |
a1d78b76 FC |
960 | actionCombo.setItems(new String[] { Messages.CustomXmlParserInputWizardPage_set, Messages.CustomXmlParserInputWizardPage_append,\r |
961 | Messages.CustomXmlParserInputWizardPage_appendWith });\r | |
c3c5c786 FC |
962 | actionCombo.select(inputElement.inputAction);\r |
963 | actionCombo.addSelectionListener(updateListener);\r | |
a1d78b76 | 964 | \r |
c3c5c786 FC |
965 | if (inputElement.inputName.equals(CustomXmlTraceDefinition.TAG_IGNORE)) {\r |
966 | tagCombo.select(0);\r | |
967 | tagLabel.setVisible(false);\r | |
968 | tagText.setVisible(false);\r | |
969 | actionCombo.setVisible(false);\r | |
970 | } else if (inputElement.inputName.equals(CustomXmlTraceDefinition.TAG_TIMESTAMP)) {\r | |
971 | tagCombo.select(1);\r | |
3b38ea61 | 972 | tagLabel.setText(Messages.CustomXmlParserInputWizardPage_format);\r |
c3c5c786 FC |
973 | tagText.setText(inputElement.inputFormat);\r |
974 | tagText.addModifyListener(updateListener);\r | |
975 | } else if (inputElement.inputName.equals(CustomXmlTraceDefinition.TAG_MESSAGE)) {\r | |
976 | tagCombo.select(2);\r | |
977 | tagLabel.setVisible(false);\r | |
978 | tagText.setVisible(false);\r | |
979 | } else {\r | |
980 | tagCombo.select(3);\r | |
3b38ea61 | 981 | tagLabel.setText(Messages.CustomXmlParserInputWizardPage_tagName);\r |
c3c5c786 FC |
982 | tagText.setText(inputElement.inputName);\r |
983 | tagText.addModifyListener(updateListener);\r | |
984 | }\r | |
985 | }\r | |
986 | \r | |
987 | if (inputElement.attributes != null) {\r | |
988 | for (InputAttribute inputAttribute : inputElement.attributes) {\r | |
a1d78b76 | 989 | Attribute attribute = new Attribute(group, this, inputAttribute, attributes.size() + 1);\r |
c3c5c786 FC |
990 | attributes.add(attribute);\r |
991 | }\r | |
992 | }\r | |
a1d78b76 | 993 | \r |
c3c5c786 FC |
994 | createAddButton();\r |
995 | }\r | |
a1d78b76 | 996 | \r |
c3c5c786 FC |
997 | private void updatePreview() {\r |
998 | Element element = getPreviewElement(inputElement);\r | |
a1d78b76 FC |
999 | if (inputElement.parentElement != null) { // no preview text for\r |
1000 | // document element\r | |
3b38ea61 | 1001 | previewText.setText(Messages.CustomXmlParserInputWizardPage_noMatchingElement);\r |
c3c5c786 FC |
1002 | if (element != null) {\r |
1003 | previewText.setText(CustomXmlTrace.parseElement(element, new StringBuffer()).toString());\r | |
1004 | if (logEntryButton.getSelection()) {\r | |
1005 | if (logEntryFound == false) {\r | |
1006 | logEntryFound = true;\r | |
1007 | logEntriesCount++;\r | |
1008 | } else {\r | |
a1d78b76 FC |
1009 | logEntryButton.setSelection(false); // remove nested\r |
1010 | // log entry\r | |
c3c5c786 FC |
1011 | }\r |
1012 | }\r | |
1013 | if (tagCombo.getText().equals(CustomXmlTraceDefinition.TAG_TIMESTAMP) && logEntriesCount <= 1) {\r | |
1014 | String value = previewText.getText().trim();\r | |
1015 | if (value.length() != 0) {\r | |
1016 | if (actionCombo.getSelectionIndex() == CustomXmlTraceDefinition.ACTION_SET) {\r | |
1017 | timeStampValue = value;\r | |
1018 | timeStampFormat = tagText.getText().trim();\r | |
1019 | } else if (actionCombo.getSelectionIndex() == CustomXmlTraceDefinition.ACTION_APPEND) {\r | |
1020 | if (timeStampValue != null) {\r | |
1021 | timeStampValue += value;\r | |
1022 | timeStampFormat += tagText.getText().trim();\r | |
1023 | } else {\r | |
1024 | timeStampValue = value;\r | |
1025 | timeStampFormat = tagText.getText().trim();\r | |
1026 | }\r | |
1027 | } else if (actionCombo.getSelectionIndex() == CustomXmlTraceDefinition.ACTION_APPEND_WITH_SEPARATOR) {\r | |
1028 | if (timeStampValue != null) {\r | |
3b38ea61 FC |
1029 | timeStampValue += " | " + value; //$NON-NLS-1$\r |
1030 | timeStampFormat += " | " + tagText.getText().trim(); //$NON-NLS-1$\r | |
c3c5c786 FC |
1031 | } else {\r |
1032 | timeStampValue = value;\r | |
1033 | timeStampFormat = tagText.getText().trim();\r | |
1034 | }\r | |
1035 | }\r | |
1036 | }\r | |
1037 | }\r | |
1038 | }\r | |
1039 | }\r | |
1040 | for (Attribute attribute : attributes) {\r | |
1041 | if (element != null) {\r | |
1042 | String value = element.getAttribute(attribute.attributeNameText.getText().trim());\r | |
1043 | if (value.length() != 0) {\r | |
1044 | attribute.previewText.setText(value);\r | |
1045 | if (attribute.tagCombo.getText().equals(CustomXmlTraceDefinition.TAG_TIMESTAMP) && logEntriesCount <= 1) {\r | |
1046 | if (attribute.actionCombo.getSelectionIndex() == CustomXmlTraceDefinition.ACTION_SET) {\r | |
1047 | timeStampValue = value;\r | |
1048 | timeStampFormat = attribute.tagText.getText().trim();\r | |
1049 | } else if (attribute.actionCombo.getSelectionIndex() == CustomXmlTraceDefinition.ACTION_APPEND) {\r | |
1050 | if (timeStampValue != null) {\r | |
1051 | timeStampValue += value;\r | |
1052 | timeStampFormat += attribute.tagText.getText().trim();\r | |
1053 | } else {\r | |
1054 | timeStampValue = value;\r | |
1055 | timeStampFormat = attribute.tagText.getText().trim();\r | |
1056 | }\r | |
1057 | } else if (attribute.actionCombo.getSelectionIndex() == CustomXmlTraceDefinition.ACTION_APPEND_WITH_SEPARATOR) {\r | |
1058 | if (timeStampValue != null) {\r | |
3b38ea61 FC |
1059 | timeStampValue += " | " + value; //$NON-NLS-1$\r |
1060 | timeStampFormat += " | " + attribute.tagText.getText().trim(); //$NON-NLS-1$\r | |
c3c5c786 FC |
1061 | } else {\r |
1062 | timeStampValue = value;\r | |
1063 | timeStampFormat = attribute.tagText.getText().trim();\r | |
1064 | }\r | |
1065 | }\r | |
1066 | }\r | |
1067 | } else {\r | |
3b38ea61 | 1068 | attribute.previewText.setText(Messages.CustomXmlParserInputWizardPage_noMatchingAttribute);\r |
c3c5c786 FC |
1069 | }\r |
1070 | } else {\r | |
3b38ea61 | 1071 | attribute.previewText.setText(Messages.CustomXmlParserInputWizardPage_noMatchingElement);\r |
c3c5c786 FC |
1072 | }\r |
1073 | }\r | |
1074 | for (ElementNode child : childElements) {\r | |
1075 | child.updatePreview();\r | |
1076 | }\r | |
1077 | if (logEntryButton != null && logEntryButton.getSelection()) {\r | |
1078 | logEntryFound = false;\r | |
1079 | }\r | |
1080 | }\r | |
1081 | \r | |
1082 | private void createAddButton() {\r | |
1083 | fillerLabel = new Label(group, SWT.NONE);\r | |
a1d78b76 | 1084 | \r |
c3c5c786 FC |
1085 | addAttributeComposite = new Composite(group, SWT.NONE);\r |
1086 | addAttributeComposite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));\r | |
1087 | GridLayout addAttributeLayout = new GridLayout(2, false);\r | |
1088 | addAttributeLayout.marginHeight = 0;\r | |
1089 | addAttributeLayout.marginWidth = 0;\r | |
1090 | addAttributeComposite.setLayout(addAttributeLayout);\r | |
a1d78b76 | 1091 | \r |
c3c5c786 FC |
1092 | addAttributeButton = new Button(addAttributeComposite, SWT.PUSH);\r |
1093 | addAttributeButton.setImage(addImage);\r | |
3b38ea61 | 1094 | addAttributeButton.setToolTipText(Messages.CustomXmlParserInputWizardPage_addAttribute);\r |
c3c5c786 | 1095 | addAttributeButton.addSelectionListener(new SelectionAdapter() {\r |
a1d78b76 | 1096 | @Override\r |
c3c5c786 FC |
1097 | public void widgetSelected(SelectionEvent e) {\r |
1098 | removeAddButton();\r | |
1099 | String attributeName = getAttributeNameSuggestion(inputElement);\r | |
3b38ea61 | 1100 | InputAttribute inputAttribute = new InputAttribute(attributeName, attributeName, 0, ""); //$NON-NLS-1$\r |
a1d78b76 | 1101 | attributes.add(new Attribute(group, ElementNode.this, inputAttribute, attributes.size() + 1));\r |
c3c5c786 FC |
1102 | createAddButton();\r |
1103 | elementContainer.layout();\r | |
a1d78b76 FC |
1104 | elementScrolledComposite.setMinSize(elementContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT).x,\r |
1105 | elementContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT).y - 1);\r | |
c3c5c786 FC |
1106 | group.getParent().layout();\r |
1107 | validate();\r | |
1108 | updatePreviews();\r | |
1109 | }\r | |
1110 | });\r | |
a1d78b76 | 1111 | \r |
c3c5c786 FC |
1112 | addAttributeLabel = new Label(addAttributeComposite, SWT.NULL);\r |
1113 | addAttributeLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));\r | |
3b38ea61 | 1114 | addAttributeLabel.setText(Messages.CustomXmlParserInputWizardPage_newAttibute);\r |
c3c5c786 FC |
1115 | }\r |
1116 | \r | |
1117 | private void removeAddButton() {\r | |
1118 | fillerLabel.dispose();\r | |
1119 | addAttributeComposite.dispose();\r | |
1120 | }\r | |
a1d78b76 | 1121 | \r |
c3c5c786 FC |
1122 | private void removeAttribute(int attributeNumber) {\r |
1123 | if (--attributeNumber < attributes.size()) {\r | |
1124 | attributes.remove(attributeNumber).dispose();\r | |
1125 | for (int i = attributeNumber; i < attributes.size(); i++) {\r | |
a1d78b76 | 1126 | attributes.get(i).setAttributeNumber(i + 1);\r |
c3c5c786 FC |
1127 | }\r |
1128 | elementContainer.layout();\r | |
a1d78b76 FC |
1129 | elementScrolledComposite.setMinSize(elementContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT).x,\r |
1130 | elementContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT).y - 1);\r | |
c3c5c786 FC |
1131 | group.getParent().layout();\r |
1132 | }\r | |
1133 | }\r | |
a1d78b76 | 1134 | \r |
c3c5c786 FC |
1135 | private void dispose() {\r |
1136 | group.dispose();\r | |
1137 | }\r | |
1138 | \r | |
1139 | private void extractInputs() {\r | |
1140 | inputElement.elementName = elementNameText.getText().trim();\r | |
1141 | if (inputElement.parentElement != null) {\r | |
1142 | inputElement.logEntry = logEntryButton.getSelection();\r | |
1143 | if (tagCombo.getText().equals(CustomXmlTraceDefinition.TAG_OTHER)) {\r | |
1144 | inputElement.inputName = tagText.getText().trim();\r | |
1145 | } else {\r | |
1146 | inputElement.inputName = tagCombo.getText();\r | |
1147 | if (tagCombo.getText().equals(CustomXmlTraceDefinition.TAG_TIMESTAMP)) {\r | |
1148 | inputElement.inputFormat = tagText.getText().trim();\r | |
1149 | }\r | |
1150 | }\r | |
1151 | inputElement.inputAction = actionCombo.getSelectionIndex();\r | |
1152 | }\r | |
1153 | inputElement.attributes = new ArrayList<InputAttribute>(attributes.size());\r | |
1154 | for (int i = 0; i < attributes.size(); i++) {\r | |
1155 | Attribute attribute = attributes.get(i);\r | |
1156 | InputAttribute inputAttribute = new InputAttribute();\r | |
1157 | inputAttribute.attributeName = attribute.attributeNameText.getText().trim();\r | |
1158 | if (attribute.tagCombo.getText().equals(CustomXmlTraceDefinition.TAG_OTHER)) {\r | |
1159 | inputAttribute.inputName = attribute.tagText.getText().trim();\r | |
1160 | } else {\r | |
1161 | inputAttribute.inputName = attribute.tagCombo.getText();\r | |
1162 | if (attribute.tagCombo.getText().equals(CustomXmlTraceDefinition.TAG_TIMESTAMP)) {\r | |
1163 | inputAttribute.inputFormat = attribute.tagText.getText().trim();\r | |
1164 | }\r | |
1165 | }\r | |
1166 | inputAttribute.inputAction = attribute.actionCombo.getSelectionIndex();\r | |
1167 | inputElement.addAttribute(inputAttribute);\r | |
1168 | }\r | |
1169 | }\r | |
1170 | }\r | |
1171 | \r | |
1172 | private class Attribute {\r | |
1173 | ElementNode element;\r | |
1174 | int attributeNumber;\r | |
a1d78b76 | 1175 | \r |
c3c5c786 FC |
1176 | // children of parent (must be disposed)\r |
1177 | Composite labelComposite;\r | |
1178 | Composite attributeComposite;\r | |
1179 | Label filler;\r | |
1180 | Composite tagComposite;\r | |
1181 | \r | |
1182 | // children of labelComposite\r | |
1183 | Label attributeLabel;\r | |
a1d78b76 | 1184 | \r |
c3c5c786 FC |
1185 | // children of attributeComposite\r |
1186 | Text attributeNameText;\r | |
1187 | Text previewText;\r | |
a1d78b76 | 1188 | \r |
c3c5c786 FC |
1189 | // children of tagComposite\r |
1190 | Combo tagCombo;\r | |
1191 | Label tagLabel;\r | |
1192 | Text tagText;\r | |
1193 | Combo actionCombo;\r | |
a1d78b76 | 1194 | \r |
c3c5c786 FC |
1195 | public Attribute(Composite parent, ElementNode element, InputAttribute inputAttribute, int attributeNumber) {\r |
1196 | this.element = element;\r | |
1197 | this.attributeNumber = attributeNumber;\r | |
a1d78b76 | 1198 | \r |
c3c5c786 FC |
1199 | labelComposite = new Composite(parent, SWT.FILL);\r |
1200 | GridLayout labelLayout = new GridLayout(2, false);\r | |
1201 | labelLayout.marginWidth = 0;\r | |
1202 | labelLayout.marginHeight = 0;\r | |
1203 | labelComposite.setLayout(labelLayout);\r | |
1204 | labelComposite.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));\r | |
a1d78b76 | 1205 | \r |
c3c5c786 FC |
1206 | Button deleteButton = new Button(labelComposite, SWT.PUSH);\r |
1207 | deleteButton.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));\r | |
1208 | deleteButton.setImage(deleteImage);\r | |
3b38ea61 | 1209 | deleteButton.setToolTipText(Messages.CustomXmlParserInputWizardPage_removeAttribute);\r |
c3c5c786 | 1210 | deleteButton.addSelectionListener(new SelectionAdapter() {\r |
a1d78b76 | 1211 | @Override\r |
c3c5c786 FC |
1212 | public void widgetSelected(SelectionEvent e) {\r |
1213 | Attribute.this.element.removeAttribute(Attribute.this.attributeNumber);\r | |
1214 | validate();\r | |
1215 | updatePreviews();\r | |
1216 | }\r | |
1217 | });\r | |
a1d78b76 | 1218 | \r |
c3c5c786 FC |
1219 | attributeLabel = new Label(labelComposite, SWT.NULL);\r |
1220 | attributeLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));\r | |
3b38ea61 | 1221 | attributeLabel.setText(Messages.CustomXmlParserInputWizardPage_attibute);\r |
a1d78b76 | 1222 | \r |
c3c5c786 FC |
1223 | attributeComposite = new Composite(parent, SWT.FILL);\r |
1224 | GridLayout attributeLayout = new GridLayout(4, false);\r | |
1225 | attributeLayout.marginWidth = 0;\r | |
1226 | attributeLayout.marginHeight = 0;\r | |
1227 | attributeComposite.setLayout(attributeLayout);\r | |
1228 | attributeComposite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));\r | |
1229 | \r | |
1230 | Label nameLabel = new Label(attributeComposite, SWT.NONE);\r | |
3b38ea61 | 1231 | nameLabel.setText(Messages.CustomXmlParserInputWizardPage_name);\r |
a1d78b76 | 1232 | \r |
c3c5c786 FC |
1233 | attributeNameText = new Text(attributeComposite, SWT.BORDER | SWT.SINGLE);\r |
1234 | attributeNameText.setLayoutData(new GridData(120, SWT.DEFAULT));\r | |
1235 | attributeNameText.setText(inputAttribute.attributeName);\r | |
1236 | attributeNameText.addModifyListener(updateListener);\r | |
a1d78b76 | 1237 | \r |
c3c5c786 | 1238 | Label previewLabel = new Label(attributeComposite, SWT.NONE);\r |
3b38ea61 | 1239 | previewLabel.setText(Messages.CustomXmlParserInputWizardPage_preview);\r |
a1d78b76 | 1240 | \r |
c3c5c786 FC |
1241 | previewText = new Text(attributeComposite, SWT.BORDER | SWT.SINGLE | SWT.READ_ONLY);\r |
1242 | GridData gd = new GridData(SWT.FILL, SWT.CENTER, true, false);\r | |
1243 | gd.widthHint = 0;\r | |
1244 | previewText.setLayoutData(gd);\r | |
3b38ea61 | 1245 | previewText.setText(Messages.CustomXmlParserInputWizardPage_noMatch);\r |
c3c5c786 FC |
1246 | previewText.setBackground(COLOR_WIDGET_BACKGROUND);\r |
1247 | \r | |
1248 | filler = new Label(parent, SWT.NULL);\r | |
a1d78b76 | 1249 | \r |
c3c5c786 FC |
1250 | tagComposite = new Composite(parent, SWT.FILL);\r |
1251 | GridLayout tagLayout = new GridLayout(4, false);\r | |
1252 | tagLayout.marginWidth = 0;\r | |
1253 | tagLayout.marginHeight = 0;\r | |
1254 | tagComposite.setLayout(tagLayout);\r | |
1255 | tagComposite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));\r | |
a1d78b76 | 1256 | \r |
c3c5c786 | 1257 | tagCombo = new Combo(tagComposite, SWT.DROP_DOWN | SWT.READ_ONLY);\r |
a1d78b76 FC |
1258 | tagCombo.setItems(new String[] { CustomXmlTraceDefinition.TAG_TIMESTAMP, CustomXmlTraceDefinition.TAG_MESSAGE,\r |
1259 | CustomXmlTraceDefinition.TAG_OTHER });\r | |
1260 | tagCombo.select(2); // Other\r | |
1261 | tagCombo.addSelectionListener(new SelectionListener() {\r | |
1262 | @Override\r | |
1263 | public void widgetDefaultSelected(SelectionEvent e) {\r | |
1264 | }\r | |
1265 | \r | |
1266 | @Override\r | |
c3c5c786 FC |
1267 | public void widgetSelected(SelectionEvent e) {\r |
1268 | tagText.removeModifyListener(updateListener);\r | |
1269 | switch (tagCombo.getSelectionIndex()) {\r | |
a1d78b76 FC |
1270 | case 0: // Time Stamp\r |
1271 | tagLabel.setText(Messages.CustomXmlParserInputWizardPage_format);\r | |
1272 | tagLabel.setVisible(true);\r | |
1273 | tagText.setVisible(true);\r | |
1274 | tagText.addModifyListener(updateListener);\r | |
1275 | break;\r | |
1276 | case 1: // Message\r | |
1277 | tagLabel.setVisible(false);\r | |
1278 | tagText.setVisible(false);\r | |
1279 | break;\r | |
1280 | case 2: // Other\r | |
1281 | tagLabel.setText(Messages.CustomXmlParserInputWizardPage_tagName);\r | |
1282 | tagLabel.setVisible(true);\r | |
1283 | if (tagText.getText().trim().length() == 0) {\r | |
1284 | tagText.setText(attributeNameText.getText().trim());\r | |
1285 | }\r | |
1286 | tagText.setVisible(true);\r | |
1287 | tagText.addModifyListener(updateListener);\r | |
1288 | break;\r | |
c3c5c786 FC |
1289 | }\r |
1290 | tagComposite.layout();\r | |
1291 | validate();\r | |
1292 | updatePreviews();\r | |
a1d78b76 FC |
1293 | }\r |
1294 | });\r | |
1295 | \r | |
c3c5c786 FC |
1296 | tagLabel = new Label(tagComposite, SWT.NULL);\r |
1297 | tagLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));\r | |
a1d78b76 | 1298 | \r |
c3c5c786 FC |
1299 | tagText = new Text(tagComposite, SWT.BORDER | SWT.SINGLE);\r |
1300 | gd = new GridData(SWT.FILL, SWT.CENTER, true, false);\r | |
1301 | gd.widthHint = 0;\r | |
1302 | tagText.setLayoutData(gd);\r | |
1303 | tagText.setText(attributeNameText.getText());\r | |
a1d78b76 | 1304 | \r |
c3c5c786 | 1305 | actionCombo = new Combo(tagComposite, SWT.DROP_DOWN | SWT.READ_ONLY);\r |
a1d78b76 FC |
1306 | actionCombo.setItems(new String[] { Messages.CustomXmlParserInputWizardPage_set, Messages.CustomXmlParserInputWizardPage_append,\r |
1307 | Messages.CustomXmlParserInputWizardPage_appendWith });\r | |
c3c5c786 FC |
1308 | actionCombo.select(inputAttribute.inputAction);\r |
1309 | actionCombo.addSelectionListener(updateListener);\r | |
a1d78b76 | 1310 | \r |
c3c5c786 FC |
1311 | if (inputAttribute.inputName.equals(CustomXmlTraceDefinition.TAG_TIMESTAMP)) {\r |
1312 | tagCombo.select(0);\r | |
3b38ea61 | 1313 | tagLabel.setText(Messages.CustomXmlParserInputWizardPage_format);\r |
c3c5c786 FC |
1314 | tagText.setText(inputAttribute.inputFormat);\r |
1315 | tagText.addModifyListener(updateListener);\r | |
1316 | } else if (inputAttribute.inputName.equals(CustomXmlTraceDefinition.TAG_MESSAGE)) {\r | |
1317 | tagCombo.select(1);\r | |
1318 | tagLabel.setVisible(false);\r | |
1319 | tagText.setVisible(false);\r | |
1320 | } else {\r | |
1321 | tagCombo.select(2);\r | |
3b38ea61 | 1322 | tagLabel.setText(Messages.CustomXmlParserInputWizardPage_tagName);\r |
c3c5c786 FC |
1323 | tagText.setText(inputAttribute.inputName);\r |
1324 | tagText.addModifyListener(updateListener);\r | |
1325 | }\r | |
1326 | }\r | |
a1d78b76 | 1327 | \r |
c3c5c786 FC |
1328 | private void dispose() {\r |
1329 | labelComposite.dispose();\r | |
1330 | attributeComposite.dispose();\r | |
1331 | filler.dispose();\r | |
1332 | tagComposite.dispose();\r | |
1333 | }\r | |
a1d78b76 | 1334 | \r |
c3c5c786 FC |
1335 | private void setAttributeNumber(int attributeNumber) {\r |
1336 | this.attributeNumber = attributeNumber;\r | |
1337 | labelComposite.layout();\r | |
1338 | }\r | |
1339 | }\r | |
1340 | \r | |
1341 | private Element getPreviewElement(InputElement inputElement) {\r | |
1342 | Element element = documentElement;\r | |
1343 | if (element != null) {\r | |
1344 | if (!documentElement.getNodeName().equals(definition.rootInputElement.elementName)) {\r | |
1345 | return null;\r | |
1346 | }\r | |
1347 | ArrayList<String> elementNames = new ArrayList<String>();\r | |
1348 | while (inputElement != null) {\r | |
1349 | elementNames.add(inputElement.elementName);\r | |
1350 | inputElement = inputElement.parentElement;\r | |
1351 | }\r | |
1352 | for (int i = elementNames.size() - 1; --i >= 0;) {\r | |
1353 | NodeList childList = element.getChildNodes();\r | |
1354 | element = null;\r | |
1355 | for (int j = 0; j < childList.getLength(); j++) {\r | |
1356 | Node child = childList.item(j);\r | |
1357 | if (child instanceof Element && child.getNodeName().equals(elementNames.get(i))) {\r | |
a1d78b76 | 1358 | element = (Element) child;\r |
c3c5c786 FC |
1359 | break;\r |
1360 | }\r | |
1361 | }\r | |
1362 | if (element == null) {\r | |
1363 | break;\r | |
1364 | }\r | |
1365 | }\r | |
1366 | if (element != null) {\r | |
1367 | return element;\r | |
1368 | }\r | |
1369 | }\r | |
1370 | return null;\r | |
1371 | }\r | |
a1d78b76 | 1372 | \r |
c3c5c786 FC |
1373 | private String getChildNameSuggestion(InputElement inputElement) {\r |
1374 | if (inputElement == null) {\r | |
1375 | if (documentElement != null) {\r | |
1376 | return documentElement.getNodeName();\r | |
1377 | }\r | |
1378 | } else {\r | |
1379 | Element element = getPreviewElement(inputElement);\r | |
1380 | if (element != null) {\r | |
1381 | NodeList childNodes = element.getChildNodes();\r | |
1382 | for (int i = 0; i < childNodes.getLength(); i++) {\r | |
1383 | Node node = childNodes.item(i);\r | |
1384 | if (node instanceof Element) {\r | |
1385 | boolean unused = true;\r | |
1386 | if (inputElement.childElements != null) {\r | |
1387 | for (InputElement child : inputElement.childElements) {\r | |
1388 | if (child.elementName.equals(node.getNodeName())) {\r | |
1389 | unused = false;\r | |
1390 | break;\r | |
1391 | }\r | |
1392 | }\r | |
1393 | }\r | |
1394 | if (unused) {\r | |
1395 | return node.getNodeName();\r | |
1396 | }\r | |
1397 | }\r | |
1398 | }\r | |
1399 | }\r | |
1400 | }\r | |
3b38ea61 | 1401 | return ""; //$NON-NLS-1$\r |
c3c5c786 | 1402 | }\r |
a1d78b76 | 1403 | \r |
c3c5c786 FC |
1404 | private String getAttributeNameSuggestion(InputElement inputElement) {\r |
1405 | Element element = getPreviewElement(inputElement);\r | |
1406 | if (element != null) {\r | |
1407 | NamedNodeMap attributeMap = element.getAttributes();\r | |
1408 | for (int i = 0; i < attributeMap.getLength(); i++) {\r | |
1409 | Node node = attributeMap.item(i);\r | |
1410 | boolean unused = true;\r | |
1411 | if (inputElement.attributes != null) {\r | |
1412 | for (InputAttribute attribute : inputElement.attributes) {\r | |
1413 | if (attribute.attributeName.equals(node.getNodeName())) {\r | |
1414 | unused = false;\r | |
1415 | break;\r | |
1416 | }\r | |
1417 | }\r | |
1418 | }\r | |
1419 | if (unused) {\r | |
1420 | return node.getNodeName();\r | |
1421 | }\r | |
1422 | }\r | |
1423 | }\r | |
3b38ea61 | 1424 | return ""; //$NON-NLS-1$\r |
c3c5c786 FC |
1425 | }\r |
1426 | \r | |
1427 | private void validate() {\r | |
1428 | definition.definitionName = logtypeText.getText().trim();\r | |
1429 | definition.timeStampOutputFormat = timeStampOutputFormatText.getText().trim();\r | |
a1d78b76 | 1430 | \r |
c3c5c786 FC |
1431 | if (selectedElement != null) {\r |
1432 | selectedElement.extractInputs();\r | |
1433 | treeViewer.refresh();\r | |
1434 | }\r | |
a1d78b76 | 1435 | \r |
c3c5c786 FC |
1436 | StringBuffer errors = new StringBuffer();\r |
1437 | \r | |
1438 | if (definition.definitionName.length() == 0) {\r | |
b9763f53 | 1439 | errors.append(Messages.CustomXmlParserInputWizardPage_emptyLogTypeError);\r |
c3c5c786 FC |
1440 | logtypeText.setBackground(COLOR_LIGHT_RED);\r |
1441 | } else {\r | |
1442 | logtypeText.setBackground(COLOR_TEXT_BACKGROUND);\r | |
1443 | for (CustomXmlTraceDefinition def : CustomXmlTraceDefinition.loadAll()) {\r | |
1444 | if (definition.definitionName.equals(def.definitionName)) {\r | |
a1d78b76 | 1445 | if (editDefinitionName == null || !editDefinitionName.equals(definition.definitionName)) {\r |
b9763f53 | 1446 | errors.append(Messages.CustomXmlParserInputWizardPage_duplicatelogTypeError);\r |
c3c5c786 FC |
1447 | logtypeText.setBackground(COLOR_LIGHT_RED);\r |
1448 | break;\r | |
1449 | }\r | |
1450 | }\r | |
1451 | }\r | |
1452 | }\r | |
a1d78b76 | 1453 | \r |
c3c5c786 | 1454 | if (definition.rootInputElement == null) {\r |
b9763f53 | 1455 | errors.append(Messages.CustomXmlParserInputWizardPage_noDocumentError);\r |
c3c5c786 | 1456 | }\r |
a1d78b76 | 1457 | \r |
c3c5c786 FC |
1458 | if (definition.rootInputElement != null) {\r |
1459 | logEntryFound = false;\r | |
c3c5c786 | 1460 | timeStampFound = false;\r |
a1d78b76 | 1461 | \r |
c3c5c786 FC |
1462 | errors.append(validateElement(definition.rootInputElement));\r |
1463 | \r | |
a1d78b76 FC |
1464 | if ((definition.rootInputElement.attributes != null && definition.rootInputElement.attributes.size() != 0)\r |
1465 | || (definition.rootInputElement.childElements != null && definition.rootInputElement.childElements.size() != 0)\r | |
1466 | || errors.length() == 0) {\r | |
c3c5c786 | 1467 | if (!logEntryFound) {\r |
b9763f53 | 1468 | errors.append(Messages.CustomXmlParserInputWizardPage_missingLogEntryError);\r |
c3c5c786 FC |
1469 | }\r |
1470 | \r | |
1471 | if (timeStampFound) {\r | |
1472 | if (timeStampOutputFormatText.getText().trim().length() == 0) {\r | |
b9763f53 | 1473 | errors.append(Messages.CustomXmlParserInputWizardPage_missingTimestampFmtError);\r |
c3c5c786 FC |
1474 | timeStampOutputFormatText.setBackground(COLOR_LIGHT_RED);\r |
1475 | } else {\r | |
1476 | try {\r | |
1477 | new SimpleDateFormat(timeStampOutputFormatText.getText().trim());\r | |
1478 | timeStampOutputFormatText.setBackground(COLOR_TEXT_BACKGROUND);\r | |
1479 | } catch (IllegalArgumentException e) {\r | |
b9763f53 | 1480 | errors.append(Messages.CustomXmlParserInputWizardPage_invalidTimestampFmtError);\r |
c3c5c786 FC |
1481 | timeStampOutputFormatText.setBackground(COLOR_LIGHT_RED);\r |
1482 | }\r | |
1483 | }\r | |
1484 | } else {\r | |
b9763f53 | 1485 | timeStampPreviewText.setText(Messages.CustomXmlParserInputWizardPage_notimestamporAttributeError);\r |
c3c5c786 FC |
1486 | }\r |
1487 | }\r | |
1488 | } else {\r | |
b9763f53 | 1489 | timeStampPreviewText.setText(Messages.CustomXmlParserInputWizardPage_notimestamporAttributeError);\r |
c3c5c786 | 1490 | }\r |
a1d78b76 | 1491 | \r |
c3c5c786 FC |
1492 | if (errors.length() == 0) {\r |
1493 | setDescription(defaultDescription);\r | |
1494 | setPageComplete(true);\r | |
1495 | } else {\r | |
1496 | setDescription(errors.toString());\r | |
1497 | setPageComplete(false);\r | |
1498 | }\r | |
1499 | }\r | |
a1d78b76 | 1500 | \r |
c3c5c786 FC |
1501 | public StringBuffer validateElement(InputElement inputElement) {\r |
1502 | StringBuffer errors = new StringBuffer();\r | |
1503 | ElementNode elementNode = null;\r | |
a1d78b76 FC |
1504 | if (selectedElement != null && selectedElement.inputElement.equals(inputElement))\r |
1505 | elementNode = selectedElement;\r | |
c3c5c786 FC |
1506 | if (inputElement == definition.rootInputElement) {\r |
1507 | if (inputElement.elementName.length() == 0) {\r | |
b9763f53 | 1508 | errors.append(Messages.CustomXmlParserInputWizardPage_missingDocumentElementError);\r |
a1d78b76 FC |
1509 | if (elementNode != null)\r |
1510 | elementNode.elementNameText.setBackground(COLOR_LIGHT_RED);\r | |
c3c5c786 | 1511 | } else {\r |
a1d78b76 FC |
1512 | if (elementNode != null)\r |
1513 | elementNode.elementNameText.setBackground(COLOR_TEXT_BACKGROUND);\r | |
c3c5c786 FC |
1514 | }\r |
1515 | }\r | |
1516 | if (inputElement != definition.rootInputElement) {\r | |
1517 | if (inputElement.logEntry) {\r | |
1518 | logEntryFound = true;\r | |
c3c5c786 FC |
1519 | }\r |
1520 | if (inputElement.inputName.equals(CustomXmlTraceDefinition.TAG_TIMESTAMP)) {\r | |
1521 | timeStampFound = true;\r | |
1522 | if (inputElement.inputFormat.length() == 0) {\r | |
a1d78b76 FC |
1523 | errors.append(Messages.CustomXmlParserInputWizardPage_timestampFormatPrompt\r |
1524 | + " (" + Messages.CustomXmlParserInputWizardPage_timestampElementPrompt + " " + getName(inputElement) + "). "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$\r | |
1525 | if (elementNode != null)\r | |
1526 | elementNode.tagText.setBackground(COLOR_LIGHT_RED);\r | |
c3c5c786 FC |
1527 | } else {\r |
1528 | try {\r | |
1529 | new SimpleDateFormat(inputElement.inputFormat);\r | |
a1d78b76 FC |
1530 | if (elementNode != null)\r |
1531 | elementNode.tagText.setBackground(COLOR_TEXT_BACKGROUND);\r | |
c3c5c786 | 1532 | } catch (IllegalArgumentException e) {\r |
a1d78b76 FC |
1533 | errors.append(Messages.CustomXmlParserInputWizardPage_invalidTimestampFmtError\r |
1534 | + " (" + Messages.CustomXmlParserInputWizardPage_timestampElementPrompt + " " + getName(inputElement) + "). "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$\r | |
1535 | if (elementNode != null)\r | |
1536 | elementNode.tagText.setBackground(COLOR_LIGHT_RED);\r | |
c3c5c786 FC |
1537 | }\r |
1538 | }\r | |
1539 | } else if (inputElement.inputName.length() == 0) {\r | |
b9763f53 | 1540 | errors.append(Messages.CustomXmlParserInputWizardPage_missingInputElementNameError);\r |
a1d78b76 FC |
1541 | if (elementNode != null)\r |
1542 | elementNode.tagText.setBackground(COLOR_LIGHT_RED);\r | |
c3c5c786 | 1543 | } else {\r |
a1d78b76 FC |
1544 | if (elementNode != null)\r |
1545 | elementNode.tagText.setBackground(COLOR_TEXT_BACKGROUND);\r | |
c3c5c786 FC |
1546 | }\r |
1547 | }\r | |
1548 | if (inputElement.attributes != null) {\r | |
1549 | if (elementNode != null) {\r | |
1550 | for (Attribute attribute : elementNode.attributes) {\r | |
1551 | attribute.attributeNameText.setBackground(COLOR_TEXT_BACKGROUND);\r | |
1552 | }\r | |
1553 | }\r | |
1554 | for (int i = 0; i < inputElement.attributes.size(); i++) {\r | |
1555 | InputAttribute attribute = inputElement.attributes.get(i);\r | |
1556 | boolean duplicate = false;\r | |
1557 | for (int j = i + 1; j < inputElement.attributes.size(); j++) {\r | |
1558 | InputAttribute otherAttribute = inputElement.attributes.get(j);\r | |
1559 | if (otherAttribute.attributeName.equals(attribute.attributeName)) {\r | |
1560 | duplicate = true;\r | |
1561 | if (elementNode != null) {\r | |
1562 | elementNode.attributes.get(j).attributeNameText.setBackground(COLOR_LIGHT_RED);\r | |
1563 | }\r | |
1564 | }\r | |
1565 | }\r | |
1566 | if (attribute.attributeName.length() == 0) {\r | |
a1d78b76 FC |
1567 | errors.append(Messages.CustomXmlParserInputWizardPage_missingAttribute\r |
1568 | + " (" + Messages.CustomXmlParserInputWizardPage_attributePrompt + " " + getName(inputElement) + ": ?). "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$\r | |
1569 | if (elementNode != null)\r | |
1570 | elementNode.attributes.get(i).attributeNameText.setBackground(COLOR_LIGHT_RED);\r | |
c3c5c786 | 1571 | } else if (duplicate) {\r |
a1d78b76 FC |
1572 | errors.append(Messages.CustomXmlParserInputWizardPage_duplicateAttributeError\r |
1573 | + " (" + Messages.CustomXmlParserInputWizardPage_attributePrompt + " " + getName(attribute, inputElement) + "). "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$\r | |
1574 | if (elementNode != null)\r | |
1575 | elementNode.attributes.get(i).attributeNameText.setBackground(COLOR_LIGHT_RED);\r | |
c3c5c786 FC |
1576 | }\r |
1577 | if (attribute.inputName.equals(CustomXmlTraceDefinition.TAG_TIMESTAMP)) {\r | |
1578 | timeStampFound = true;\r | |
1579 | if (attribute.inputFormat.length() == 0) {\r | |
a1d78b76 FC |
1580 | errors.append(Messages.CustomXmlParserInputWizardPage_missingTimestampInFmtError\r |
1581 | + " (" + Messages.CustomXmlParserInputWizardPage_attributePrompt + " " + getName(attribute, inputElement) + "). "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$\r | |
1582 | if (elementNode != null)\r | |
1583 | elementNode.attributes.get(i).tagText.setBackground(COLOR_LIGHT_RED);\r | |
c3c5c786 FC |
1584 | } else {\r |
1585 | try {\r | |
1586 | new SimpleDateFormat(attribute.inputFormat);\r | |
a1d78b76 FC |
1587 | if (elementNode != null)\r |
1588 | elementNode.attributes.get(i).tagText.setBackground(COLOR_TEXT_BACKGROUND);\r | |
c3c5c786 | 1589 | } catch (IllegalArgumentException e) {\r |
a1d78b76 FC |
1590 | errors.append(Messages.CustomXmlParserInputWizardPage_invalidTimestampInFmtError\r |
1591 | + " (" + Messages.CustomXmlParserInputWizardPage_attributePrompt + " " + getName(attribute, inputElement) + "). "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$\r | |
1592 | if (elementNode != null)\r | |
1593 | elementNode.attributes.get(i).tagText.setBackground(COLOR_LIGHT_RED);\r | |
c3c5c786 FC |
1594 | }\r |
1595 | }\r | |
1596 | } else if (attribute.inputName.length() == 0) {\r | |
a1d78b76 FC |
1597 | errors.append(Messages.CustomXmlParserInputWizardPage_missingDataGroupNameError\r |
1598 | + " (" + Messages.CustomXmlParserInputWizardPage_attributePrompt + " " + getName(attribute, inputElement) + "). "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$\r | |
1599 | if (elementNode != null)\r | |
1600 | elementNode.attributes.get(i).tagText.setBackground(COLOR_LIGHT_RED);\r | |
c3c5c786 | 1601 | } else {\r |
a1d78b76 FC |
1602 | if (elementNode != null)\r |
1603 | elementNode.attributes.get(i).tagText.setBackground(COLOR_TEXT_BACKGROUND);\r | |
c3c5c786 FC |
1604 | }\r |
1605 | }\r | |
1606 | }\r | |
1607 | if (inputElement.childElements != null) {\r | |
1608 | for (InputElement child : inputElement.childElements) {\r | |
1609 | ElementNode childElementNode = null;\r | |
a1d78b76 FC |
1610 | if (selectedElement != null && selectedElement.inputElement.equals(child))\r |
1611 | childElementNode = selectedElement;\r | |
1612 | if (childElementNode != null)\r | |
1613 | childElementNode.elementNameText.setBackground(COLOR_TEXT_BACKGROUND);\r | |
c3c5c786 FC |
1614 | }\r |
1615 | for (int i = 0; i < inputElement.childElements.size(); i++) {\r | |
1616 | InputElement child = inputElement.childElements.get(i);\r | |
1617 | ElementNode childElementNode = null;\r | |
a1d78b76 FC |
1618 | if (selectedElement != null && selectedElement.inputElement.equals(child))\r |
1619 | childElementNode = selectedElement;\r | |
c3c5c786 | 1620 | if (child.elementName.length() == 0) {\r |
a1d78b76 FC |
1621 | errors.append(Messages.CustomXmlParserInputWizardPage_missingElementNameError\r |
1622 | + " (" + Messages.CustomXmlParserInputWizardPage_attributePrompt + " " + getName(child) + "). "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$\r | |
1623 | if (childElementNode != null)\r | |
1624 | childElementNode.elementNameText.setBackground(COLOR_LIGHT_RED);\r | |
c3c5c786 FC |
1625 | } else {\r |
1626 | boolean duplicate = false;\r | |
1627 | for (int j = i + 1; j < inputElement.childElements.size(); j++) {\r | |
1628 | InputElement otherChild = inputElement.childElements.get(j);\r | |
1629 | if (otherChild.elementName.equals(child.elementName)) {\r | |
1630 | duplicate = true;\r | |
1631 | ElementNode otherChildElementNode = null;\r | |
a1d78b76 FC |
1632 | if (selectedElement != null && selectedElement.inputElement.equals(otherChild))\r |
1633 | otherChildElementNode = selectedElement;\r | |
1634 | if (otherChildElementNode != null)\r | |
1635 | otherChildElementNode.elementNameText.setBackground(COLOR_LIGHT_RED);\r | |
c3c5c786 FC |
1636 | }\r |
1637 | }\r | |
1638 | if (duplicate) {\r | |
a1d78b76 FC |
1639 | errors.append(Messages.CustomXmlParserInputWizardPage_duplicateElementNameError\r |
1640 | + " (" + Messages.CustomXmlParserInputWizardPage_attributePrompt + " " + getName(child) + "). "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$\r | |
1641 | if (childElementNode != null)\r | |
1642 | childElementNode.elementNameText.setBackground(COLOR_LIGHT_RED);\r | |
c3c5c786 FC |
1643 | }\r |
1644 | }\r | |
a1d78b76 | 1645 | \r |
c3c5c786 FC |
1646 | errors.append(validateElement(child));\r |
1647 | }\r | |
1648 | }\r | |
c3c5c786 FC |
1649 | return errors;\r |
1650 | }\r | |
a1d78b76 | 1651 | \r |
c3c5c786 FC |
1652 | public CustomXmlTraceDefinition getDefinition() {\r |
1653 | return definition;\r | |
1654 | }\r | |
1655 | \r | |
1656 | public char[] getInputText() {\r | |
1657 | return inputText.getText().toCharArray();\r | |
1658 | }\r | |
1659 | }\r |