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.IOException;\r | |
5 | import java.io.InputStreamReader;\r | |
6 | import java.text.ParseException;\r | |
7 | import java.text.SimpleDateFormat;\r | |
8 | import java.util.ArrayList;\r | |
9 | import java.util.Arrays;\r | |
10 | import java.util.Date;\r | |
11 | import java.util.HashMap;\r | |
12 | import java.util.Iterator;\r | |
13 | import java.util.List;\r | |
14 | import java.util.Map;\r | |
15 | import java.util.Scanner;\r | |
16 | import java.util.regex.Matcher;\r | |
17 | import java.util.regex.Pattern;\r | |
18 | import java.util.regex.PatternSyntaxException;\r | |
19 | \r | |
20 | import org.eclipse.core.resources.IFile;\r | |
21 | import org.eclipse.core.runtime.CoreException;\r | |
22 | import org.eclipse.jface.viewers.ColumnLabelProvider;\r | |
23 | import org.eclipse.jface.viewers.ISelection;\r | |
24 | import org.eclipse.jface.viewers.ISelectionChangedListener;\r | |
25 | import org.eclipse.jface.viewers.IStructuredSelection;\r | |
26 | import org.eclipse.jface.viewers.ITreeContentProvider;\r | |
27 | import org.eclipse.jface.viewers.SelectionChangedEvent;\r | |
28 | import org.eclipse.jface.viewers.StructuredSelection;\r | |
29 | import org.eclipse.jface.viewers.TreeViewer;\r | |
30 | import org.eclipse.jface.viewers.Viewer;\r | |
31 | import org.eclipse.jface.wizard.WizardPage;\r | |
32 | import org.eclipse.linuxtools.tmf.ui.TmfUiPlugin;\r | |
7995b722 | 33 | import org.eclipse.linuxtools.tmf.ui.internal.Messages;\r |
c3c5c786 FC |
34 | import org.eclipse.linuxtools.tmf.ui.parsers.custom.CustomTxtTraceDefinition;\r |
35 | import org.eclipse.linuxtools.tmf.ui.parsers.custom.CustomTxtTraceDefinition.Cardinality;\r | |
36 | import org.eclipse.linuxtools.tmf.ui.parsers.custom.CustomTxtTraceDefinition.InputData;\r | |
37 | import org.eclipse.linuxtools.tmf.ui.parsers.custom.CustomTxtTraceDefinition.InputLine;\r | |
38 | import org.eclipse.swt.SWT;\r | |
39 | import org.eclipse.swt.browser.Browser;\r | |
40 | import org.eclipse.swt.browser.TitleEvent;\r | |
41 | import org.eclipse.swt.browser.TitleListener;\r | |
42 | import org.eclipse.swt.custom.SashForm;\r | |
43 | import org.eclipse.swt.custom.ScrolledComposite;\r | |
44 | import org.eclipse.swt.custom.StyleRange;\r | |
45 | import org.eclipse.swt.custom.StyledText;\r | |
46 | import org.eclipse.swt.events.ModifyEvent;\r | |
47 | import org.eclipse.swt.events.ModifyListener;\r | |
48 | import org.eclipse.swt.events.SelectionAdapter;\r | |
49 | import org.eclipse.swt.events.SelectionEvent;\r | |
50 | import org.eclipse.swt.events.SelectionListener;\r | |
51 | import org.eclipse.swt.events.VerifyEvent;\r | |
52 | import org.eclipse.swt.events.VerifyListener;\r | |
53 | import org.eclipse.swt.graphics.Color;\r | |
54 | import org.eclipse.swt.graphics.Font;\r | |
55 | import org.eclipse.swt.graphics.FontData;\r | |
56 | import org.eclipse.swt.graphics.Image;\r | |
57 | import org.eclipse.swt.layout.FillLayout;\r | |
58 | import org.eclipse.swt.layout.GridData;\r | |
59 | import org.eclipse.swt.layout.GridLayout;\r | |
60 | import org.eclipse.swt.widgets.Button;\r | |
61 | import org.eclipse.swt.widgets.Combo;\r | |
62 | import org.eclipse.swt.widgets.Composite;\r | |
63 | import org.eclipse.swt.widgets.Display;\r | |
64 | import org.eclipse.swt.widgets.Group;\r | |
65 | import org.eclipse.swt.widgets.Label;\r | |
66 | import org.eclipse.swt.widgets.Shell;\r | |
67 | import org.eclipse.swt.widgets.Text;\r | |
68 | \r | |
69 | public class CustomTxtParserInputWizardPage extends WizardPage {\r | |
70 | \r | |
3b38ea61 FC |
71 | private static final String DEFAULT_REGEX = "\\s*(.*\\S)"; //$NON-NLS-1$\r |
72 | private static final String DEFAULT_TIMESTAMP_FORMAT = "yyyy-MM-dd HH:mm:ss.SSS"; //$NON-NLS-1$\r | |
73 | 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 | |
74 | private static final String PATTERN_URL = "http://java.sun.com/javase/6/docs/api/java/util/regex/Pattern.html#sum"; //$NON-NLS-1$\r | |
d7fcacc9 FC |
75 | private static final Image lineImage = TmfUiPlugin.getDefault().getImageFromPath("/icons/elcl16/line_icon.gif"); //$NON-NLS-1$\r |
76 | private static final Image addImage = TmfUiPlugin.getDefault().getImageFromPath("/icons/elcl16/add_button.gif"); //$NON-NLS-1$\r | |
77 | private static final Image addNextImage = TmfUiPlugin.getDefault().getImageFromPath("/icons/elcl16/addnext_button.gif"); //$NON-NLS-1$\r | |
78 | private static final Image addChildImage = TmfUiPlugin.getDefault().getImageFromPath("/icons/elcl16/addchild_button.gif"); //$NON-NLS-1$\r | |
79 | private static final Image deleteImage = TmfUiPlugin.getDefault().getImageFromPath("/icons/elcl16/delete_button.gif"); //$NON-NLS-1$\r | |
80 | private static final Image moveUpImage = TmfUiPlugin.getDefault().getImageFromPath("/icons/elcl16/moveup_button.gif"); //$NON-NLS-1$\r | |
81 | private static final Image moveDownImage = TmfUiPlugin.getDefault().getImageFromPath("/icons/elcl16/movedown_button.gif"); //$NON-NLS-1$\r | |
82 | private static final Image helpImage = TmfUiPlugin.getDefault().getImageFromPath("/icons/elcl16/help_button.gif"); //$NON-NLS-1$\r | |
c3c5c786 FC |
83 | private static final Color COLOR_BLACK = Display.getCurrent().getSystemColor(SWT.COLOR_BLACK);\r |
84 | private static final Color COLOR_LIGHT_GREEN = new Color(Display.getDefault(), 192, 255, 192);\r | |
85 | private static final Color COLOR_GREEN = Display.getCurrent().getSystemColor(SWT.COLOR_GREEN);\r | |
86 | private static final Color COLOR_LIGHT_YELLOW = new Color(Display.getDefault(), 255, 255, 192);\r | |
87 | private static final Color COLOR_YELLOW = Display.getCurrent().getSystemColor(SWT.COLOR_YELLOW);\r | |
88 | private static final Color COLOR_LIGHT_MAGENTA = new Color(Display.getDefault(), 255, 192, 255);\r | |
89 | private static final Color COLOR_MAGENTA = Display.getCurrent().getSystemColor(SWT.COLOR_MAGENTA);\r | |
90 | private static final Color COLOR_LIGHT_RED = new Color(Display.getDefault(), 255, 192, 192);\r | |
91 | private static final Color COLOR_TEXT_BACKGROUND = Display.getCurrent().getSystemColor(SWT.COLOR_WHITE);\r | |
92 | private static final Color COLOR_WIDGET_BACKGROUND = Display.getCurrent().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND);\r | |
93 | \r | |
94 | private ISelection selection;\r | |
95 | private CustomTxtTraceDefinition definition;\r | |
96 | private String editDefinitionName;\r | |
97 | private String defaultDescription;\r | |
98 | private Line selectedLine;\r | |
99 | private Composite container;\r | |
100 | private Text logtypeText;\r | |
101 | private Text timestampOutputFormatText;\r | |
102 | private Text timestampPreviewText;\r | |
103 | private ScrolledComposite treeScrolledComposite;\r | |
104 | private ScrolledComposite lineScrolledComposite;\r | |
105 | private TreeViewer treeViewer;\r | |
106 | private Composite treeContainer;\r | |
107 | private Composite lineContainer;\r | |
c3c5c786 FC |
108 | private StyledText inputText;\r |
109 | private Font fixedFont;\r | |
110 | private UpdateListener updateListener;\r | |
111 | private Browser helpBrowser;\r | |
112 | \r | |
113 | // variables used recursively through line traversal\r | |
c3c5c786 FC |
114 | private String timeStampFormat;\r |
115 | private boolean timestampFound;\r | |
116 | \r | |
117 | protected CustomTxtParserInputWizardPage(ISelection selection, CustomTxtTraceDefinition definition) {\r | |
3b38ea61 | 118 | super("CustomParserWizardPage"); //$NON-NLS-1$\r |
c3c5c786 | 119 | if (definition == null) {\r |
3b38ea61 FC |
120 | setTitle(Messages.CustomTxtParserInputWizardPage_windowTitleNew);\r |
121 | defaultDescription = Messages.CustomTxtParserInputWizardPage_descriptionNew;\r | |
c3c5c786 | 122 | } else {\r |
3b38ea61 FC |
123 | setTitle(Messages.CustomTxtParserInputWizardPage_windowTitleEdit);\r |
124 | defaultDescription = Messages.CustomTxtParserInputWizardPage_desccriptionEdit;\r | |
c3c5c786 FC |
125 | }\r |
126 | setDescription(defaultDescription);\r | |
127 | this.selection = selection;\r | |
128 | this.definition = definition;\r | |
129 | if (definition != null) {\r | |
130 | this.editDefinitionName = definition.definitionName;\r | |
131 | }\r | |
132 | }\r | |
133 | \r | |
d4011df2 | 134 | @Override\r |
c3c5c786 FC |
135 | public void createControl(Composite parent) {\r |
136 | container = new Composite(parent, SWT.NULL);\r | |
137 | container.setLayout(new GridLayout());\r | |
138 | \r | |
139 | updateListener = new UpdateListener();\r | |
140 | \r | |
141 | Composite headerComposite = new Composite(container, SWT.FILL);\r | |
142 | GridLayout headerLayout = new GridLayout(5, false);\r | |
143 | headerLayout.marginHeight = 0;\r | |
144 | headerLayout.marginWidth = 0;\r | |
145 | headerComposite.setLayout(headerLayout);\r | |
146 | headerComposite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));\r | |
147 | \r | |
148 | Label logtypeLabel = new Label(headerComposite, SWT.NULL);\r | |
3b38ea61 | 149 | logtypeLabel.setText(Messages.CustomTxtParserInputWizardPage_logType);\r |
c3c5c786 FC |
150 | \r |
151 | logtypeText = new Text(headerComposite, SWT.BORDER | SWT.SINGLE);\r | |
152 | logtypeText.setLayoutData(new GridData(120, SWT.DEFAULT));\r | |
c3c5c786 FC |
153 | \r |
154 | Label timestampFormatLabel = new Label(headerComposite, SWT.NULL);\r | |
3b38ea61 | 155 | timestampFormatLabel.setText(Messages.CustomTxtParserInputWizardPage_timestampFormat);\r |
c3c5c786 FC |
156 | \r |
157 | timestampOutputFormatText = new Text(headerComposite, SWT.BORDER | SWT.SINGLE);\r | |
158 | timestampOutputFormatText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));\r | |
159 | timestampOutputFormatText.setText(DEFAULT_TIMESTAMP_FORMAT);\r | |
c3c5c786 FC |
160 | \r |
161 | Button dateFormatHelpButton = new Button(headerComposite, SWT.PUSH);\r | |
162 | dateFormatHelpButton.setImage(helpImage);\r | |
3b38ea61 | 163 | dateFormatHelpButton.setToolTipText(Messages.CustomTxtParserInputWizardPage_dateFormatHelp);\r |
c3c5c786 | 164 | dateFormatHelpButton.addSelectionListener(new SelectionAdapter() {\r |
9ccc6d01 FC |
165 | @Override\r |
166 | public void widgetSelected(SelectionEvent e) {\r | |
c3c5c786 FC |
167 | openHelpShell(SIMPLE_DATE_FORMAT_URL);\r |
168 | }\r | |
169 | });\r | |
170 | \r | |
171 | Label timestampPreviewLabel = new Label(headerComposite, SWT.NULL);\r | |
172 | timestampPreviewLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 3, 1));\r | |
3b38ea61 | 173 | timestampPreviewLabel.setText(Messages.CustomTxtParserInputWizardPage_preview);\r |
c3c5c786 FC |
174 | \r |
175 | timestampPreviewText = new Text(headerComposite, SWT.BORDER | SWT.SINGLE | SWT.READ_ONLY);\r | |
176 | timestampPreviewText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));\r | |
3b38ea61 | 177 | timestampPreviewText.setText(Messages.CustomTxtParserInputWizardPage_noMatchingTimestamp);\r |
c3c5c786 FC |
178 | \r |
179 | Composite buttonBar = new Composite(container, SWT.NONE);\r | |
180 | GridLayout buttonBarLayout = new GridLayout(5, false);\r | |
181 | buttonBarLayout.marginHeight = 0;\r | |
182 | buttonBarLayout.marginWidth = 0;\r | |
183 | buttonBar.setLayout(buttonBarLayout);\r | |
184 | \r | |
185 | Button removeButton = new Button(buttonBar, SWT.PUSH);\r | |
186 | removeButton.setImage(deleteImage);\r | |
3b38ea61 | 187 | removeButton.setToolTipText(Messages.CustomTxtParserInputWizardPage_removeLine);\r |
c3c5c786 | 188 | removeButton.addSelectionListener(new SelectionAdapter() {\r |
9ccc6d01 | 189 | @Override\r |
c3c5c786 FC |
190 | public void widgetSelected(SelectionEvent e) {\r |
191 | if (treeViewer.getSelection().isEmpty() || selectedLine == null) return;\r | |
192 | removeLine();\r | |
193 | InputLine inputLine = (InputLine) ((IStructuredSelection) treeViewer.getSelection()).getFirstElement();\r | |
194 | if (inputLine.parentInput == null) {\r | |
195 | definition.inputs.remove(inputLine);\r | |
196 | } else {\r | |
197 | inputLine.parentInput.childrenInputs.remove(inputLine);\r | |
198 | }\r | |
199 | treeViewer.refresh();\r | |
200 | validate();\r | |
201 | updatePreviews();\r | |
202 | }\r | |
203 | });\r | |
204 | Button addNextButton = new Button(buttonBar, SWT.PUSH);\r | |
205 | addNextButton.setImage(addNextImage);\r | |
3b38ea61 | 206 | addNextButton.setToolTipText(Messages.CustomTxtParserInputWizardPage_addNextLine);\r |
c3c5c786 | 207 | addNextButton.addSelectionListener(new SelectionAdapter() {\r |
9ccc6d01 | 208 | @Override\r |
c3c5c786 | 209 | public void widgetSelected(SelectionEvent e) {\r |
3b38ea61 | 210 | InputLine inputLine = new InputLine(Cardinality.ZERO_OR_MORE, "", null); //$NON-NLS-1$\r |
c3c5c786 FC |
211 | if (((List<?>) treeViewer.getInput()).size() == 0) {\r |
212 | definition.inputs.add(inputLine);\r | |
213 | } else if (treeViewer.getSelection().isEmpty()) {\r | |
214 | return;\r | |
215 | } else {\r | |
216 | InputLine previousInputLine = (InputLine) ((IStructuredSelection) treeViewer.getSelection()).getFirstElement();\r | |
217 | if (previousInputLine.parentInput == null) {\r | |
218 | for (int i = 0; i < definition.inputs.size(); i++) {\r | |
219 | if (definition.inputs.get(i).equals(previousInputLine)) {\r | |
220 | definition.inputs.add(i + 1, inputLine);\r | |
221 | }\r | |
222 | }\r | |
223 | } else {\r | |
224 | previousInputLine.addNext(inputLine);\r | |
225 | }\r | |
226 | }\r | |
227 | treeViewer.refresh();\r | |
228 | treeViewer.setSelection(new StructuredSelection(inputLine), true);\r | |
229 | }\r | |
230 | });\r | |
231 | Button addChildButton = new Button(buttonBar, SWT.PUSH);\r | |
232 | addChildButton.setImage(addChildImage);\r | |
3b38ea61 | 233 | addChildButton.setToolTipText(Messages.CustomTxtParserInputWizardPage_addChildLine);\r |
c3c5c786 | 234 | addChildButton.addSelectionListener(new SelectionAdapter() {\r |
9ccc6d01 FC |
235 | @Override\r |
236 | public void widgetSelected(SelectionEvent e) {\r | |
3b38ea61 | 237 | InputLine inputLine = new InputLine(Cardinality.ZERO_OR_MORE, "", null); //$NON-NLS-1$\r |
c3c5c786 FC |
238 | if (((List<?>) treeViewer.getInput()).size() == 0) {\r |
239 | definition.inputs.add(inputLine);\r | |
240 | } else if (treeViewer.getSelection().isEmpty()) {\r | |
241 | return;\r | |
242 | } else {\r | |
243 | InputLine parentInputLine = (InputLine) ((IStructuredSelection) treeViewer.getSelection()).getFirstElement();\r | |
244 | parentInputLine.addChild(inputLine);\r | |
245 | }\r | |
246 | treeViewer.refresh();\r | |
247 | treeViewer.setSelection(new StructuredSelection(inputLine), true);\r | |
248 | }\r | |
249 | });\r | |
250 | Button moveUpButton = new Button(buttonBar, SWT.PUSH);\r | |
251 | moveUpButton.setImage(moveUpImage);\r | |
3b38ea61 | 252 | moveUpButton.setToolTipText(Messages.CustomTxtParserInputWizardPage_moveUp);\r |
c3c5c786 | 253 | moveUpButton.addSelectionListener(new SelectionAdapter() {\r |
9ccc6d01 | 254 | @Override\r |
c3c5c786 FC |
255 | public void widgetSelected(SelectionEvent e) {\r |
256 | if (treeViewer.getSelection().isEmpty()) return;\r | |
257 | InputLine inputLine = (InputLine) ((IStructuredSelection) treeViewer.getSelection()).getFirstElement();\r | |
258 | if (inputLine.parentInput == null) {\r | |
259 | for (int i = 1; i < definition.inputs.size(); i++) {\r | |
260 | if (definition.inputs.get(i).equals(inputLine)) {\r | |
261 | definition.inputs.add(i - 1 , definition.inputs.remove(i));\r | |
262 | break;\r | |
263 | }\r | |
264 | }\r | |
265 | } else {\r | |
266 | inputLine.moveUp();\r | |
267 | }\r | |
268 | treeViewer.refresh();\r | |
269 | validate();\r | |
270 | updatePreviews();\r | |
271 | }\r | |
272 | });\r | |
273 | Button moveDownButton = new Button(buttonBar, SWT.PUSH);\r | |
274 | moveDownButton.setImage(moveDownImage);\r | |
3b38ea61 | 275 | moveDownButton.setToolTipText(Messages.CustomTxtParserInputWizardPage_moveDown);\r |
c3c5c786 | 276 | moveDownButton.addSelectionListener(new SelectionAdapter() {\r |
9ccc6d01 | 277 | @Override\r |
c3c5c786 FC |
278 | public void widgetSelected(SelectionEvent e) {\r |
279 | if (treeViewer.getSelection().isEmpty()) return;\r | |
280 | InputLine inputLine = (InputLine) ((IStructuredSelection) treeViewer.getSelection()).getFirstElement();\r | |
281 | if (inputLine.parentInput == null) {\r | |
282 | for (int i = 0; i < definition.inputs.size() - 1; i++) {\r | |
283 | if (definition.inputs.get(i).equals(inputLine)) {\r | |
284 | definition.inputs.add(i + 1 , definition.inputs.remove(i));\r | |
285 | break;\r | |
286 | }\r | |
287 | }\r | |
288 | } else {\r | |
289 | inputLine.moveDown();\r | |
290 | }\r | |
291 | treeViewer.refresh();\r | |
292 | validate();\r | |
293 | updatePreviews();\r | |
294 | }\r | |
295 | });\r | |
296 | \r | |
297 | SashForm vSash = new SashForm(container, SWT.VERTICAL);\r | |
298 | vSash.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));\r | |
299 | vSash.setBackground(vSash.getDisplay().getSystemColor(SWT.COLOR_GRAY));\r | |
300 | \r | |
301 | SashForm hSash = new SashForm(vSash, SWT.HORIZONTAL);\r | |
302 | hSash.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));\r | |
303 | \r | |
304 | treeScrolledComposite = new ScrolledComposite(hSash, SWT.V_SCROLL | SWT.H_SCROLL);\r | |
305 | GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);\r | |
306 | gd.heightHint = 200;\r | |
307 | gd.widthHint = 200;\r | |
308 | treeScrolledComposite.setLayoutData(gd);\r | |
309 | treeContainer = new Composite(treeScrolledComposite, SWT.NONE);\r | |
310 | treeContainer.setLayout(new FillLayout());\r | |
311 | treeScrolledComposite.setContent(treeContainer);\r | |
312 | treeScrolledComposite.setExpandHorizontal(true);\r | |
313 | treeScrolledComposite.setExpandVertical(true);\r | |
314 | \r | |
315 | treeViewer = new TreeViewer(treeContainer, SWT.SINGLE | SWT.BORDER);\r | |
316 | treeViewer.setContentProvider(new InputLineTreeNodeContentProvider());\r | |
317 | treeViewer.setLabelProvider(new InputLineTreeLabelProvider());\r | |
318 | treeViewer.addSelectionChangedListener(new InputLineTreeSelectionChangedListener());\r | |
319 | treeContainer.layout();\r | |
320 | \r | |
321 | treeScrolledComposite.setMinSize(treeContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT).x, treeContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT).y);\r | |
322 | \r | |
323 | lineScrolledComposite = new ScrolledComposite(hSash, SWT.V_SCROLL);\r | |
324 | lineScrolledComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));\r | |
325 | lineContainer = new Composite(lineScrolledComposite, SWT.NONE);\r | |
326 | GridLayout linesLayout = new GridLayout();\r | |
327 | linesLayout.marginHeight = 1;\r | |
328 | linesLayout.marginWidth = 0;\r | |
329 | lineContainer.setLayout(linesLayout);\r | |
330 | lineScrolledComposite.setContent(lineContainer);\r | |
331 | lineScrolledComposite.setExpandHorizontal(true);\r | |
332 | lineScrolledComposite.setExpandVertical(true);\r | |
333 | \r | |
334 | if (definition == null) {\r | |
335 | definition = new CustomTxtTraceDefinition();\r | |
336 | definition.inputs.add(new InputLine(Cardinality.ZERO_OR_MORE, DEFAULT_REGEX,\r | |
337 | Arrays.asList(new InputData(CustomTxtTraceDefinition.TAG_MESSAGE, CustomTxtTraceDefinition.ACTION_SET))));\r | |
338 | }\r | |
339 | loadDefinition(definition);\r | |
340 | treeViewer.expandAll();\r | |
341 | lineContainer.layout();\r | |
342 | \r | |
d7fcacc9 FC |
343 | logtypeText.addModifyListener(updateListener);\r |
344 | timestampOutputFormatText.addModifyListener(updateListener);\r | |
345 | \r | |
c3c5c786 FC |
346 | lineScrolledComposite.setMinSize(lineContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT).x, lineContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT).y-1);\r |
347 | \r | |
348 | hSash.setWeights(new int[] {1, 2});\r | |
349 | \r | |
350 | Composite sashBottom = new Composite(vSash, SWT.NONE);\r | |
351 | GridLayout sashBottomLayout = new GridLayout(3, false);\r | |
352 | sashBottomLayout.marginHeight = 0;\r | |
353 | sashBottomLayout.marginWidth = 0;\r | |
354 | sashBottom.setLayout(sashBottomLayout);\r | |
355 | \r | |
356 | Label previewLabel = new Label(sashBottom, SWT.NULL);\r | |
3b38ea61 | 357 | previewLabel.setText(Messages.CustomTxtParserInputWizardPage_previewInput);\r |
c3c5c786 FC |
358 | previewLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));\r |
359 | \r | |
360 | Button highlightAllButton = new Button(sashBottom, SWT.PUSH);\r | |
361 | highlightAllButton.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));\r | |
3b38ea61 | 362 | highlightAllButton.setText(Messages.CustomTxtParserInputWizardPage_highlightAll);\r |
c3c5c786 | 363 | highlightAllButton.addSelectionListener(new SelectionAdapter() {\r |
9ccc6d01 | 364 | @Override\r |
c3c5c786 FC |
365 | public void widgetSelected(SelectionEvent e) {\r |
366 | updatePreviews(true);\r | |
367 | }\r | |
368 | });\r | |
369 | \r | |
370 | Button legendButton = new Button(sashBottom, SWT.PUSH);\r | |
371 | legendButton.setImage(helpImage);\r | |
3b38ea61 | 372 | legendButton.setToolTipText(Messages.CustomTxtParserInputWizardPage_previewLegend);\r |
c3c5c786 FC |
373 | legendButton.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));\r |
374 | legendButton.addSelectionListener(new SelectionAdapter() {\r | |
9ccc6d01 | 375 | @Override\r |
c3c5c786 FC |
376 | public void widgetSelected(SelectionEvent e) {\r |
377 | openLegend();\r | |
378 | }\r | |
379 | });\r | |
380 | \r | |
381 | inputText = new StyledText(sashBottom, SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL);\r | |
382 | if (fixedFont == null) {\r | |
3b38ea61 FC |
383 | if (System.getProperty("os.name").contains("Windows")) { //$NON-NLS-1$ //$NON-NLS-2$\r |
384 | fixedFont = new Font(Display.getCurrent(), new FontData("Courier New", 10, SWT.NORMAL)); //$NON-NLS-1$\r | |
c3c5c786 | 385 | } else {\r |
3b38ea61 | 386 | fixedFont = new Font(Display.getCurrent(), new FontData("Monospace", 10, SWT.NORMAL)); //$NON-NLS-1$\r |
c3c5c786 FC |
387 | }\r |
388 | }\r | |
389 | inputText.setFont(fixedFont);\r | |
390 | gd = new GridData(SWT.FILL, SWT.FILL, true, true, 3, 1);\r | |
391 | gd.heightHint = inputText.computeSize(SWT.DEFAULT, inputText.getLineHeight() * 4).y;\r | |
392 | gd.widthHint = 800;\r | |
393 | inputText.setLayoutData(gd);\r | |
394 | inputText.setText(getSelectionText());\r | |
395 | inputText.addModifyListener(updateListener);\r | |
396 | \r | |
397 | vSash.setWeights(new int[] {hSash.computeSize(SWT.DEFAULT, SWT.DEFAULT).y, sashBottom.computeSize(SWT.DEFAULT, SWT.DEFAULT).y});\r | |
398 | \r | |
399 | setControl(container);\r | |
400 | \r | |
401 | validate();\r | |
402 | updatePreviews();\r | |
403 | }\r | |
404 | \r | |
f4c52cea | 405 | private static class InputLineTreeNodeContentProvider implements ITreeContentProvider {\r |
c3c5c786 | 406 | \r |
d4011df2 | 407 | @Override\r |
c3c5c786 FC |
408 | public Object[] getElements(Object inputElement) {\r |
409 | return ((List<?>) inputElement).toArray();\r | |
410 | }\r | |
411 | \r | |
d4011df2 | 412 | @Override\r |
c3c5c786 FC |
413 | public Object[] getChildren(Object parentElement) {\r |
414 | InputLine inputLine = (InputLine) parentElement;\r | |
415 | if (inputLine.childrenInputs == null) return new InputLine[0];\r | |
416 | return inputLine.childrenInputs.toArray();\r | |
417 | }\r | |
418 | \r | |
d4011df2 | 419 | @Override\r |
c3c5c786 FC |
420 | public boolean hasChildren(Object element) {\r |
421 | InputLine inputLine = (InputLine) element;\r | |
422 | return (inputLine.childrenInputs != null && inputLine.childrenInputs.size() > 0);\r | |
423 | }\r | |
424 | \r | |
d4011df2 | 425 | @Override\r |
c3c5c786 FC |
426 | public void dispose() {\r |
427 | }\r | |
428 | \r | |
d4011df2 | 429 | @Override\r |
c3c5c786 FC |
430 | public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {\r |
431 | }\r | |
432 | \r | |
d4011df2 | 433 | @Override\r |
c3c5c786 FC |
434 | public Object getParent(Object element) {\r |
435 | InputLine inputLine = (InputLine) element;\r | |
436 | return inputLine.parentInput;\r | |
437 | }\r | |
438 | }\r | |
439 | \r | |
440 | private class InputLineTreeLabelProvider extends ColumnLabelProvider {\r | |
441 | \r | |
442 | @Override\r | |
443 | public Image getImage(Object element) {\r | |
444 | return lineImage;\r | |
445 | }\r | |
446 | \r | |
447 | @Override\r | |
448 | public String getText(Object element) {\r | |
449 | InputLine inputLine = (InputLine) element;\r | |
450 | if (inputLine.parentInput == null) {\r | |
3b38ea61 | 451 | return "Root Line " + getName(inputLine) + " " + inputLine.cardinality.toString() + " : " + inputLine.getRegex(); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$\r |
c3c5c786 | 452 | } else {\r |
3b38ea61 | 453 | return "Line " + getName(inputLine) + " " + inputLine.cardinality.toString() + " : " + inputLine.getRegex(); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$\r |
c3c5c786 FC |
454 | }\r |
455 | }\r | |
456 | }\r | |
457 | \r | |
458 | private class InputLineTreeSelectionChangedListener implements ISelectionChangedListener {\r | |
d4011df2 | 459 | @Override\r |
c3c5c786 FC |
460 | public void selectionChanged(SelectionChangedEvent event) {\r |
461 | if (selectedLine != null) {\r | |
462 | selectedLine.dispose();\r | |
463 | }\r | |
464 | if (!(event.getSelection().isEmpty()) && event.getSelection() instanceof IStructuredSelection) {\r | |
465 | IStructuredSelection selection = (IStructuredSelection) event.getSelection();\r | |
466 | InputLine inputLine = (InputLine) selection.getFirstElement();\r | |
467 | selectedLine = new Line(lineContainer, getName(inputLine), inputLine);\r | |
468 | lineContainer.layout();\r | |
469 | lineScrolledComposite.setMinSize(lineContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT).x, lineContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT).y-1);\r | |
470 | container.layout();\r | |
471 | validate();\r | |
472 | updatePreviews();\r | |
473 | }\r | |
474 | }\r | |
475 | }\r | |
476 | \r | |
477 | /* (non-Javadoc)\r | |
478 | * @see org.eclipse.jface.dialogs.DialogPage#dispose()\r | |
479 | */\r | |
480 | @Override\r | |
481 | public void dispose() {\r | |
482 | if (fixedFont != null) {\r | |
483 | fixedFont.dispose();\r | |
484 | fixedFont = null;\r | |
485 | }\r | |
486 | super.dispose();\r | |
487 | }\r | |
488 | \r | |
489 | private void loadDefinition(CustomTxtTraceDefinition def) {\r | |
490 | logtypeText.setText(def.definitionName);\r | |
491 | timestampOutputFormatText.setText(def.timeStampOutputFormat);\r | |
492 | treeViewer.setInput(def.inputs);\r | |
493 | if (def.inputs.size() > 0) {\r | |
494 | InputLine inputLine = def.inputs.get(0);\r | |
495 | treeViewer.setSelection(new StructuredSelection(inputLine));\r | |
496 | }\r | |
497 | }\r | |
498 | \r | |
499 | private String getName(InputLine inputLine) {\r | |
500 | if (inputLine.parentInput == null) {\r | |
501 | return Integer.toString(definition.inputs.indexOf(inputLine)+1);\r | |
502 | }\r | |
3b38ea61 | 503 | return getName(inputLine.parentInput) + "." + Integer.toString(inputLine.parentInput.childrenInputs.indexOf(inputLine)+1); //$NON-NLS-1$\r |
c3c5c786 FC |
504 | }\r |
505 | \r | |
506 | public List<String> getInputNames() {\r | |
507 | List<String> inputs = new ArrayList<String>();\r | |
508 | for (InputLine inputLine : definition.inputs) {\r | |
509 | for (String inputName : getInputNames(inputLine)) {\r | |
510 | if (!inputs.contains(inputName)) {\r | |
511 | inputs.add(inputName);\r | |
512 | }\r | |
513 | }\r | |
514 | }\r | |
515 | return inputs;\r | |
516 | }\r | |
517 | \r | |
518 | public List<String> getInputNames(InputLine inputLine) {\r | |
519 | List<String> inputs = new ArrayList<String>();\r | |
520 | if (inputLine.columns != null) {\r | |
521 | for (InputData inputData : inputLine.columns) {\r | |
522 | String inputName = inputData.name;\r | |
523 | if (!inputs.contains(inputName)) {\r | |
524 | inputs.add(inputName);\r | |
525 | }\r | |
526 | }\r | |
527 | }\r | |
528 | if (inputLine.childrenInputs != null) {\r | |
529 | for (InputLine childInputLine : inputLine.childrenInputs) {\r | |
530 | for (String inputName : getInputNames(childInputLine)) {\r | |
531 | if (!inputs.contains(inputName)) {\r | |
532 | inputs.add(inputName);\r | |
533 | }\r | |
534 | }\r | |
535 | }\r | |
536 | }\r | |
537 | return inputs;\r | |
538 | }\r | |
539 | \r | |
540 | private void removeLine() {\r | |
541 | selectedLine.dispose();\r | |
542 | selectedLine = null;\r | |
543 | lineContainer.layout();\r | |
544 | lineScrolledComposite.setMinSize(lineContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT).x, lineContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT).y-1);\r | |
545 | container.layout();\r | |
546 | }\r | |
547 | \r | |
c3c5c786 FC |
548 | private String getSelectionText() {\r |
549 | if (this.selection instanceof IStructuredSelection) {\r | |
550 | Object selection = ((IStructuredSelection)this.selection).getFirstElement();\r | |
551 | if (selection instanceof IFile) {\r | |
552 | IFile file = (IFile)selection;\r | |
f4c52cea | 553 | BufferedReader reader = null;\r |
c3c5c786 | 554 | try {\r |
f4c52cea | 555 | reader = new BufferedReader(new InputStreamReader(file.getContents()));\r |
c3c5c786 FC |
556 | StringBuilder sb = new StringBuilder();\r |
557 | String line = null;\r | |
558 | while ((line = reader.readLine()) != null) {\r | |
3b38ea61 | 559 | sb.append(line + "\n"); //$NON-NLS-1$\r |
c3c5c786 FC |
560 | }\r |
561 | return sb.toString();\r | |
562 | } catch (CoreException e) {\r | |
3b38ea61 | 563 | return ""; //$NON-NLS-1$\r |
c3c5c786 | 564 | } catch (IOException e) {\r |
3b38ea61 | 565 | return ""; //$NON-NLS-1$\r |
f4c52cea | 566 | } finally {\r |
567 | if (reader != null) {\r | |
568 | try {\r | |
569 | reader.close();\r | |
570 | } catch (IOException e) {\r | |
571 | }\r | |
572 | }\r | |
c3c5c786 FC |
573 | }\r |
574 | }\r | |
575 | }\r | |
3b38ea61 | 576 | return ""; //$NON-NLS-1$\r |
c3c5c786 FC |
577 | }\r |
578 | \r | |
579 | private void updatePreviews() {\r | |
580 | updatePreviews(false);\r | |
581 | }\r | |
582 | \r | |
583 | private void updatePreviews(boolean updateAll) {\r | |
584 | if (inputText == null) {\r | |
585 | // early update during construction\r | |
586 | return;\r | |
587 | }\r | |
588 | inputText.setStyleRanges(new StyleRange[] {});\r | |
589 | \r | |
590 | Scanner scanner = new Scanner(inputText.getText());\r | |
3b38ea61 | 591 | scanner.useDelimiter("\n"); //$NON-NLS-1$\r |
c3c5c786 FC |
592 | int rawPos = 0;\r |
593 | String skip; // skip starting delimiters\r | |
3b38ea61 | 594 | if ((skip = scanner.findWithinHorizon("\\A\n+", 0)) != null) { //$NON-NLS-1$\r |
c3c5c786 FC |
595 | rawPos += skip.length();\r |
596 | }\r | |
597 | \r | |
598 | timeStampFormat = null;\r | |
599 | if (selectedLine != null) {\r | |
600 | for (InputGroup input : selectedLine.inputs) {\r | |
3b38ea61 | 601 | input.previewText.setText(Messages.CustomTxtParserInputWizardPage_noMathcingLine);\r |
c3c5c786 FC |
602 | }\r |
603 | }\r | |
604 | \r | |
605 | Map<String, String> data = new HashMap<String, String>();\r | |
606 | int rootLineMatches = 0;\r | |
607 | String firstEntryTimeStamp = null;\r | |
608 | String firstEntryTimeStampInputFormat = null;\r | |
609 | String log = null;\r | |
610 | event: \r | |
611 | while (log != null || scanner.hasNext()) {\r | |
612 | if (rootLineMatches > 0 && !updateAll) {\r | |
613 | break;\r | |
614 | }\r | |
615 | if (log == null) {\r | |
616 | log = scanner.next();\r | |
617 | }\r | |
618 | int length = log.length();\r | |
619 | for (InputLine rootInputLine : definition.inputs) {\r | |
620 | Pattern pattern;\r | |
621 | try {\r | |
622 | pattern = rootInputLine.getPattern();\r | |
623 | } catch (PatternSyntaxException e) {\r | |
624 | continue;\r | |
625 | }\r | |
626 | Matcher matcher = pattern.matcher(log);\r | |
627 | if (matcher.find()) {\r | |
628 | rootLineMatches++;\r | |
629 | inputText.setStyleRange(new StyleRange(rawPos, length,\r | |
630 | COLOR_BLACK, COLOR_YELLOW, SWT.ITALIC));\r | |
631 | data = new HashMap<String, String>();\r | |
632 | timeStampFormat = null;\r | |
633 | updatePreviewLine(rootInputLine, matcher, data, rawPos, rootLineMatches);\r | |
634 | if (rootLineMatches == 1) {\r | |
635 | firstEntryTimeStamp = data.get(CustomTxtTraceDefinition.TAG_TIMESTAMP);\r | |
636 | firstEntryTimeStampInputFormat = timeStampFormat;\r | |
637 | }\r | |
638 | HashMap<InputLine, Integer> countMap = new HashMap<InputLine, Integer>();\r | |
639 | InputLine currentInput = null;\r | |
640 | if (rootInputLine.childrenInputs != null && rootInputLine.childrenInputs.size() > 0) {\r | |
641 | currentInput = rootInputLine.childrenInputs.get(0);\r | |
642 | countMap.put(currentInput, 0);\r | |
643 | }\r | |
644 | rawPos += length + 1; // +1 for \n\r | |
645 | while (scanner.hasNext()) {\r | |
646 | log = scanner.next();\r | |
647 | length = log.length();\r | |
648 | boolean processed = false;\r | |
649 | if (currentInput == null) {\r | |
650 | for (InputLine input : definition.inputs) {\r | |
651 | matcher = input.getPattern().matcher(log);\r | |
652 | if (matcher.find()) {\r | |
653 | continue event;\r | |
654 | }\r | |
655 | }\r | |
656 | } else {\r | |
657 | if (countMap.get(currentInput) >= currentInput.getMinCount()) {\r | |
658 | List<InputLine> nextInputs = currentInput.getNextInputs(countMap);\r | |
659 | if (nextInputs.size() == 0 || nextInputs.get(nextInputs.size() - 1).getMinCount() == 0) {\r | |
660 | for (InputLine input : definition.inputs) {\r | |
661 | matcher = input.getPattern().matcher(log);\r | |
662 | if (matcher.find()) {\r | |
663 | continue event;\r | |
664 | }\r | |
665 | }\r | |
666 | }\r | |
667 | for (InputLine input : nextInputs) {\r | |
668 | matcher = input.getPattern().matcher(log);\r | |
669 | if (matcher.find()) {\r | |
670 | inputText.setStyleRange(new StyleRange(rawPos, length,\r | |
671 | COLOR_BLACK, COLOR_LIGHT_YELLOW, SWT.ITALIC));\r | |
672 | currentInput = input;\r | |
673 | updatePreviewLine(currentInput, matcher, data, rawPos, rootLineMatches);\r | |
674 | if (countMap.get(currentInput) == null) {\r | |
675 | countMap.put(currentInput, 1);\r | |
676 | } else {\r | |
677 | countMap.put(currentInput, countMap.get(currentInput) + 1);\r | |
678 | }\r | |
679 | Iterator<InputLine> iter = countMap.keySet().iterator();\r | |
680 | while (iter.hasNext()) {\r | |
681 | InputLine inputLine = iter.next();\r | |
682 | if (inputLine.level > currentInput.level) {\r | |
683 | iter.remove();\r | |
684 | }\r | |
685 | }\r | |
686 | if (currentInput.childrenInputs != null && currentInput.childrenInputs.size() > 0) {\r | |
687 | currentInput = currentInput.childrenInputs.get(0);\r | |
688 | countMap.put(currentInput, 0);\r | |
689 | } else {\r | |
690 | if (countMap.get(currentInput) >= currentInput.getMaxCount()) {\r | |
691 | if (currentInput.getNextInputs(countMap).size() > 0) {\r | |
692 | currentInput = currentInput.getNextInputs(countMap).get(0);\r | |
693 | if (countMap.get(currentInput) == null) {\r | |
694 | countMap.put(currentInput, 0);\r | |
695 | }\r | |
696 | iter = countMap.keySet().iterator();\r | |
697 | while (iter.hasNext()) {\r | |
698 | InputLine inputLine = iter.next();\r | |
699 | if (inputLine.level > currentInput.level) {\r | |
700 | iter.remove();\r | |
701 | }\r | |
702 | }\r | |
703 | } else {\r | |
704 | currentInput = null;\r | |
705 | }\r | |
706 | }\r | |
707 | }\r | |
708 | processed = true;\r | |
709 | break;\r | |
710 | }\r | |
711 | }\r | |
712 | }\r | |
713 | if (! processed) {\r | |
714 | matcher = currentInput.getPattern().matcher(log);\r | |
715 | if (matcher.find()) {\r | |
716 | inputText.setStyleRange(new StyleRange(rawPos, length,\r | |
717 | COLOR_BLACK, COLOR_LIGHT_YELLOW, SWT.ITALIC));\r | |
718 | updatePreviewLine(currentInput, matcher, data, rawPos, rootLineMatches);\r | |
719 | countMap.put(currentInput, countMap.get(currentInput) + 1);\r | |
720 | if (currentInput.childrenInputs != null && currentInput.childrenInputs.size() > 0) {\r | |
721 | currentInput = currentInput.childrenInputs.get(0);\r | |
722 | countMap.put(currentInput, 0);\r | |
723 | } else {\r | |
724 | if (countMap.get(currentInput) >= currentInput.getMaxCount()) {\r | |
725 | if (currentInput.getNextInputs(countMap).size() > 0) {\r | |
726 | currentInput = currentInput.getNextInputs(countMap).get(0);\r | |
727 | if (countMap.get(currentInput) == null) {\r | |
728 | countMap.put(currentInput, 0);\r | |
729 | }\r | |
730 | Iterator<InputLine> iter = countMap.keySet().iterator();\r | |
731 | while (iter.hasNext()) {\r | |
732 | InputLine inputLine = iter.next();\r | |
733 | if (inputLine.level > currentInput.level) {\r | |
734 | iter.remove();\r | |
735 | }\r | |
736 | }\r | |
737 | } else {\r | |
738 | currentInput = null;\r | |
739 | }\r | |
740 | }\r | |
741 | }\r | |
742 | }\r | |
743 | }\r | |
744 | }\r | |
745 | rawPos += length + 1; // +1 for \n\r | |
746 | }\r | |
747 | \r | |
748 | break;\r | |
749 | }\r | |
750 | }\r | |
751 | rawPos += length + 1; // +1 for \n\r | |
752 | log = null;\r | |
753 | }\r | |
754 | scanner.close();\r | |
755 | if (rootLineMatches == 1) {\r | |
756 | firstEntryTimeStamp = data.get(CustomTxtTraceDefinition.TAG_TIMESTAMP);\r | |
757 | firstEntryTimeStampInputFormat = timeStampFormat;\r | |
758 | }\r | |
759 | if (firstEntryTimeStamp == null) {\r | |
3b38ea61 | 760 | timestampPreviewText.setText(Messages.CustomTxtParserInputWizardPage_noTimestampGroup);\r |
c3c5c786 FC |
761 | if (selectedLine != null) {\r |
762 | for (InputGroup group : selectedLine.inputs) {\r | |
763 | if (group.tagCombo.getText().equals(CustomTxtTraceDefinition.TAG_TIMESTAMP)) {\r | |
3b38ea61 | 764 | timestampPreviewText.setText(Messages.CustomTxtParserInputWizardPage_noMatchingTimestamp);\r |
c3c5c786 FC |
765 | break;\r |
766 | }\r | |
767 | }\r | |
768 | }\r | |
769 | } else {\r | |
770 | try {\r | |
771 | SimpleDateFormat dateFormat = new SimpleDateFormat(firstEntryTimeStampInputFormat);\r | |
772 | Date date = dateFormat.parse(firstEntryTimeStamp);\r | |
773 | dateFormat = new SimpleDateFormat(timestampOutputFormatText.getText().trim());\r | |
774 | timestampPreviewText.setText(dateFormat.format(date));\r | |
775 | } catch (ParseException e) {\r | |
b9763f53 | 776 | timestampPreviewText.setText("*parse exception* [" + firstEntryTimeStamp + "] <> [" + firstEntryTimeStampInputFormat + "]"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$\r |
c3c5c786 | 777 | } catch (IllegalArgumentException e) {\r |
b9763f53 | 778 | timestampPreviewText.setText("*parse exception* [Illegal Argument]"); //$NON-NLS-1$\r |
c3c5c786 FC |
779 | }\r |
780 | \r | |
781 | }\r | |
782 | }\r | |
783 | \r | |
784 | private void updatePreviewLine(InputLine line, Matcher matcher, Map<String, String> data, int rawPos, int rootLineMatches) {\r | |
785 | for (int i = 0; i < line.columns.size(); i++) {\r | |
786 | InputData input = line.columns.get(i);\r | |
787 | if (i < matcher.groupCount() && matcher.group(i+1) != null) {\r | |
788 | if (line.parentInput == null) {\r | |
789 | inputText.setStyleRange(new StyleRange(rawPos + matcher.start(i+1), matcher.end(i+1) - matcher.start(i+1),\r | |
790 | COLOR_BLACK, COLOR_GREEN, SWT.BOLD));\r | |
791 | } else {\r | |
792 | inputText.setStyleRange(new StyleRange(rawPos + matcher.start(i+1), matcher.end(i+1) - matcher.start(i+1),\r | |
793 | COLOR_BLACK, COLOR_LIGHT_GREEN, SWT.BOLD));\r | |
794 | }\r | |
795 | String value = matcher.group(i+1).trim();\r | |
796 | if (selectedLine != null && selectedLine.inputLine.equals(line) && rootLineMatches == 1) {\r | |
3b38ea61 | 797 | if (selectedLine.inputs.get(i).previewText.getText().equals(Messages.CustomTxtParserInputWizardPage_noMatchingLine)) {\r |
c3c5c786 FC |
798 | selectedLine.inputs.get(i).previewText.setText(value);\r |
799 | }\r | |
800 | }\r | |
801 | if (value.length() == 0) {\r | |
802 | continue;\r | |
803 | }\r | |
804 | if (input.action == CustomTxtTraceDefinition.ACTION_SET) {\r | |
805 | data.put(input.name, value);\r | |
806 | if (input.name.equals(CustomTxtTraceDefinition.TAG_TIMESTAMP)) {\r | |
807 | timeStampFormat = input.format;\r | |
808 | }\r | |
809 | } else if (input.action == CustomTxtTraceDefinition.ACTION_APPEND) {\r | |
810 | String s = data.get(input.name);\r | |
811 | if (s != null) {\r | |
812 | data.put(input.name, s + value);\r | |
813 | } else {\r | |
814 | data.put(input.name, value);\r | |
815 | }\r | |
816 | if (input.name.equals(CustomTxtTraceDefinition.TAG_TIMESTAMP)) {\r | |
817 | if (timeStampFormat != null) {\r | |
818 | timeStampFormat += input.format;\r | |
819 | } else {\r | |
820 | timeStampFormat = input.format;\r | |
821 | }\r | |
822 | }\r | |
823 | } else if (input.action == CustomTxtTraceDefinition.ACTION_APPEND_WITH_SEPARATOR) {\r | |
824 | String s = data.get(input.name);\r | |
825 | if (s != null) {\r | |
3b38ea61 | 826 | data.put(input.name, s + " | " + value); //$NON-NLS-1$\r |
c3c5c786 FC |
827 | } else {\r |
828 | data.put(input.name, value);\r | |
829 | }\r | |
830 | if (input.name.equals(CustomTxtTraceDefinition.TAG_TIMESTAMP)) {\r | |
831 | if (timeStampFormat != null) {\r | |
3b38ea61 | 832 | timeStampFormat += " | " + input.format; //$NON-NLS-1$\r |
c3c5c786 FC |
833 | } else {\r |
834 | timeStampFormat = input.format;\r | |
835 | }\r | |
836 | }\r | |
837 | }\r | |
838 | } else {\r | |
839 | if (selectedLine != null && selectedLine.inputLine.equals(line) && rootLineMatches == 1) {\r | |
3b38ea61 FC |
840 | if (selectedLine.inputs.get(i).previewText.getText().equals(Messages.CustomTxtParserInputWizardPage_noMatchingLine)) {\r |
841 | selectedLine.inputs.get(i).previewText.setText(Messages.CustomTxtParserInputWizardPage_noMatchingGroup);\r | |
c3c5c786 FC |
842 | }\r |
843 | }\r | |
844 | }\r | |
845 | }\r | |
846 | // highlight the matching groups that have no corresponponding input\r | |
847 | for (int i = line.columns.size(); i < matcher.groupCount(); i++) {\r | |
848 | if (matcher.group(i+1) != null) {\r | |
849 | if (line.parentInput == null) {\r | |
850 | inputText.setStyleRange(new StyleRange(rawPos + matcher.start(i+1), matcher.end(i+1) - matcher.start(i+1),\r | |
851 | COLOR_BLACK, COLOR_MAGENTA));\r | |
852 | } else {\r | |
853 | inputText.setStyleRange(new StyleRange(rawPos + matcher.start(i+1), matcher.end(i+1) - matcher.start(i+1),\r | |
854 | COLOR_BLACK, COLOR_LIGHT_MAGENTA));\r | |
855 | }\r | |
856 | }\r | |
857 | }\r | |
858 | }\r | |
859 | \r | |
860 | private void openHelpShell(String url) {\r | |
861 | if (helpBrowser != null && !helpBrowser.isDisposed()) {\r | |
862 | helpBrowser.getShell().setActive();\r | |
863 | if (!helpBrowser.getUrl().equals(url)) {\r | |
864 | helpBrowser.setUrl(url);\r | |
865 | }\r | |
866 | return;\r | |
867 | }\r | |
868 | final Shell helpShell = new Shell(getShell(), SWT.SHELL_TRIM);\r | |
869 | helpShell.setLayout(new FillLayout());\r | |
870 | helpBrowser = new Browser(helpShell, SWT.NONE);\r | |
871 | helpBrowser.addTitleListener(new TitleListener() {\r | |
d4011df2 | 872 | @Override\r |
c3c5c786 FC |
873 | public void changed(TitleEvent event) {\r |
874 | helpShell.setText(event.title);\r | |
875 | }\r | |
876 | });\r | |
877 | helpBrowser.setBounds(0,0,600,400);\r | |
878 | helpShell.pack();\r | |
879 | helpShell.open();\r | |
880 | helpBrowser.setUrl(url);\r | |
881 | }\r | |
882 | \r | |
883 | private void openLegend() {\r | |
3b38ea61 FC |
884 | final String CG = Messages.CustomTxtParserInputWizardPage_capturedGroup;\r |
885 | final String UCG = Messages.CustomTxtParserInputWizardPage_unidentifiedCaptureGroup;\r | |
886 | final String UT = Messages.CustomTxtParserInputWizardPage_uncapturedText;\r | |
c3c5c786 | 887 | int line1start = 0;\r |
3b38ea61 | 888 | String line1 = Messages.CustomTxtParserInputWizardPage_nonMatchingLine;\r |
c3c5c786 | 889 | int line2start = line1start + line1.length();\r |
b9763f53 | 890 | String line2 = Messages.CustomTxtParserInputWizardPage_matchingLineRoot + CG + " " + UCG + " " + UT + " \n"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$\r |
c3c5c786 | 891 | int line3start = line2start + line2.length();\r |
b9763f53 | 892 | String line3 = Messages.CustomTxtParserInputWizardPage_matchingOtherLine + CG + " " + UCG + " " + UT + " \n"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$\r |
c3c5c786 | 893 | int line4start = line3start + line3.length();\r |
b9763f53 | 894 | String line4 = Messages.CustomTxtParserInputWizardPage_matchingOtherLine + CG + " " + UCG + " " + UT + " \n"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$\r |
c3c5c786 | 895 | int line5start = line4start + line4.length();\r |
3b38ea61 | 896 | String line5 = Messages.CustomTxtParserInputWizardPage_nonMatchingLine;\r |
c3c5c786 | 897 | int line6start = line5start + line5.length();\r |
b9763f53 | 898 | String line6 = Messages.CustomTxtParserInputWizardPage_matchingRootLine + CG + " " + UCG + " " + UT + " \n"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ \r |
c3c5c786 FC |
899 | \r |
900 | final Shell legendShell = new Shell(getShell(), SWT.DIALOG_TRIM);\r | |
901 | legendShell.setLayout(new FillLayout());\r | |
902 | StyledText legendText = new StyledText(legendShell, SWT.MULTI);\r | |
903 | legendText.setFont(fixedFont);\r | |
904 | legendText.setText(line1 + line2 + line3 + line4 + line5 + line6);\r | |
905 | legendText.setStyleRange(new StyleRange(line2start, line2.length(), COLOR_BLACK, COLOR_YELLOW, SWT.ITALIC));\r | |
906 | legendText.setStyleRange(new StyleRange(line3start, line3.length(), COLOR_BLACK, COLOR_LIGHT_YELLOW, SWT.ITALIC));\r | |
907 | legendText.setStyleRange(new StyleRange(line4start, line4.length(), COLOR_BLACK, COLOR_LIGHT_YELLOW, SWT.ITALIC));\r | |
908 | legendText.setStyleRange(new StyleRange(line6start, line6.length(), COLOR_BLACK, COLOR_YELLOW, SWT.ITALIC));\r | |
909 | legendText.setStyleRange(new StyleRange(line2start + line2.indexOf(CG), CG.length(), COLOR_BLACK, COLOR_GREEN, SWT.BOLD));\r | |
910 | legendText.setStyleRange(new StyleRange(line2start + line2.indexOf(UCG), UCG.length(), COLOR_BLACK, COLOR_MAGENTA));\r | |
911 | legendText.setStyleRange(new StyleRange(line3start + line3.indexOf(CG), CG.length(), COLOR_BLACK, COLOR_LIGHT_GREEN, SWT.BOLD));\r | |
912 | legendText.setStyleRange(new StyleRange(line3start + line3.indexOf(UCG), UCG.length(), COLOR_BLACK, COLOR_LIGHT_MAGENTA));\r | |
913 | legendText.setStyleRange(new StyleRange(line4start + line4.indexOf(CG), CG.length(), COLOR_BLACK, COLOR_LIGHT_GREEN, SWT.BOLD));\r | |
914 | legendText.setStyleRange(new StyleRange(line4start + line4.indexOf(UCG), UCG.length(), COLOR_BLACK, COLOR_LIGHT_MAGENTA));\r | |
915 | legendText.setStyleRange(new StyleRange(line6start + line6.indexOf(CG), CG.length(), COLOR_BLACK, COLOR_GREEN, SWT.BOLD));\r | |
916 | legendText.setStyleRange(new StyleRange(line6start + line6.indexOf(UCG), UCG.length(), COLOR_BLACK, COLOR_MAGENTA));\r | |
3b38ea61 | 917 | legendShell.setText(Messages.CustomTxtParserInputWizardPage_previewLegend);\r |
c3c5c786 FC |
918 | legendShell.pack();\r |
919 | legendShell.open();\r | |
920 | }\r | |
921 | \r | |
922 | private class UpdateListener implements ModifyListener, SelectionListener {\r | |
923 | \r | |
d4011df2 | 924 | @Override\r |
c3c5c786 FC |
925 | public void modifyText(ModifyEvent e) {\r |
926 | validate();\r | |
927 | updatePreviews();\r | |
928 | }\r | |
929 | \r | |
d4011df2 | 930 | @Override\r |
c3c5c786 FC |
931 | public void widgetDefaultSelected(SelectionEvent e) {\r |
932 | validate();\r | |
933 | updatePreviews();\r | |
934 | }\r | |
935 | \r | |
d4011df2 | 936 | @Override\r |
c3c5c786 FC |
937 | public void widgetSelected(SelectionEvent e) {\r |
938 | validate();\r | |
939 | updatePreviews();\r | |
940 | }\r | |
941 | \r | |
942 | }\r | |
943 | \r | |
944 | private class Line {\r | |
3b38ea61 | 945 | private static final String INFINITY_STRING = "\u221E"; //$NON-NLS-1$\r |
c3c5c786 FC |
946 | InputLine inputLine;\r |
947 | Group group;\r | |
948 | Composite labelComposite;\r | |
949 | Text regexText;\r | |
950 | Composite cardinalityContainer;\r | |
951 | Combo cardinalityCombo;\r | |
952 | Label cardinalityMinLabel;\r | |
953 | Text cardinalityMinText;\r | |
954 | Label cardinalityMaxLabel;\r | |
955 | Text cardinalityMaxText;\r | |
956 | Button infiniteButton;\r | |
957 | ArrayList<InputGroup> inputs = new ArrayList<InputGroup>();\r | |
958 | Button addGroupButton;\r | |
959 | Label addGroupLabel;\r | |
960 | \r | |
961 | public Line(Composite parent, String name, InputLine inputLine) {\r | |
c3c5c786 FC |
962 | this.inputLine = inputLine;\r |
963 | \r | |
964 | group = new Group(parent, SWT.NONE);\r | |
965 | group.setText(name);\r | |
966 | group.setLayout(new GridLayout(2, false));\r | |
967 | group.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));\r | |
968 | \r | |
969 | labelComposite = new Composite(group, SWT.FILL);\r | |
970 | GridLayout labelLayout = new GridLayout(1, false);\r | |
971 | labelLayout.marginWidth = 0;\r | |
972 | labelLayout.marginHeight = 0;\r | |
973 | labelComposite.setLayout(labelLayout);\r | |
974 | labelComposite.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));\r | |
975 | \r | |
976 | Label label = new Label(labelComposite, SWT.NULL);\r | |
3b38ea61 | 977 | label.setText(Messages.CustomTxtParserInputWizardPage_regularExpression);\r |
c3c5c786 FC |
978 | \r |
979 | Composite regexContainer = new Composite(group, SWT.NONE);\r | |
980 | GridLayout regexLayout = new GridLayout(2, false);\r | |
981 | regexLayout.marginHeight = 0;\r | |
982 | regexLayout.marginWidth = 0;\r | |
983 | regexContainer.setLayout(regexLayout);\r | |
984 | regexContainer.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));\r | |
985 | \r | |
986 | regexText = new Text(regexContainer, SWT.BORDER | SWT.SINGLE);\r | |
987 | GridData gd = new GridData(SWT.FILL, SWT.CENTER, true, false);\r | |
988 | gd.widthHint = 0;\r | |
989 | regexText.setLayoutData(gd);\r | |
990 | regexText.setText(inputLine.getRegex());\r | |
991 | regexText.addModifyListener(updateListener);\r | |
992 | \r | |
993 | Button regexHelpButton = new Button(regexContainer, SWT.PUSH);\r | |
994 | regexHelpButton.setImage(helpImage);\r | |
3b38ea61 | 995 | regexHelpButton.setToolTipText(Messages.CustomTxtParserInputWizardPage_regularExpressionHelp);\r |
c3c5c786 | 996 | regexHelpButton.addSelectionListener(new SelectionAdapter() {\r |
9ccc6d01 FC |
997 | @Override\r |
998 | public void widgetSelected(SelectionEvent e) {\r | |
c3c5c786 FC |
999 | openHelpShell(PATTERN_URL);\r |
1000 | }\r | |
1001 | });\r | |
1002 | \r | |
1003 | label = new Label(group, SWT.NONE);\r | |
3b38ea61 | 1004 | label.setText(Messages.CustomTxtParserInputWizardPage_cardinality);\r |
c3c5c786 FC |
1005 | label.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));\r |
1006 | \r | |
1007 | cardinalityContainer = new Composite(group, SWT.NONE);\r | |
1008 | GridLayout cardinalityLayout = new GridLayout(6, false);\r | |
1009 | cardinalityLayout.marginHeight = 0;\r | |
1010 | cardinalityLayout.marginWidth = 0;\r | |
1011 | cardinalityContainer.setLayout(cardinalityLayout);\r | |
1012 | cardinalityContainer.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));\r | |
1013 | \r | |
1014 | cardinalityCombo = new Combo(cardinalityContainer, SWT.DROP_DOWN | SWT.READ_ONLY);\r | |
1015 | cardinalityCombo.setItems(new String[] {\r | |
1016 | Cardinality.ZERO_OR_MORE.toString(),\r | |
1017 | Cardinality.ONE_OR_MORE.toString(),\r | |
1018 | Cardinality.ZERO_OR_ONE.toString(),\r | |
1019 | Cardinality.ONE.toString(),\r | |
3b38ea61 | 1020 | "(?,?)"}); //$NON-NLS-1$\r |
c3c5c786 | 1021 | cardinalityCombo.addSelectionListener(new SelectionListener(){\r |
d4011df2 | 1022 | @Override\r |
c3c5c786 | 1023 | public void widgetDefaultSelected(SelectionEvent e) {}\r |
d4011df2 | 1024 | @Override\r |
c3c5c786 FC |
1025 | public void widgetSelected(SelectionEvent e) {\r |
1026 | switch (cardinalityCombo.getSelectionIndex()) {\r | |
1027 | case 4: //(?,?)\r | |
1028 | cardinalityMinLabel.setVisible(true);\r | |
1029 | cardinalityMinText.setVisible(true);\r | |
1030 | cardinalityMaxLabel.setVisible(true);\r | |
1031 | cardinalityMaxText.setVisible(true);\r | |
1032 | infiniteButton.setVisible(true);\r | |
1033 | break;\r | |
1034 | default:\r | |
1035 | cardinalityMinLabel.setVisible(false);\r | |
1036 | cardinalityMinText.setVisible(false);\r | |
1037 | cardinalityMaxLabel.setVisible(false);\r | |
1038 | cardinalityMaxText.setVisible(false);\r | |
1039 | infiniteButton.setVisible(false);\r | |
1040 | break;\r | |
1041 | }\r | |
1042 | cardinalityContainer.layout();\r | |
1043 | validate();\r | |
1044 | updatePreviews();\r | |
1045 | }});\r | |
1046 | \r | |
1047 | cardinalityMinLabel = new Label(cardinalityContainer, SWT.NONE);\r | |
1048 | cardinalityMinLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));\r | |
3b38ea61 | 1049 | cardinalityMinLabel.setText(Messages.CustomTxtParserInputWizardPage_min);\r |
c3c5c786 FC |
1050 | cardinalityMinLabel.setVisible(false);\r |
1051 | \r | |
1052 | cardinalityMinText = new Text(cardinalityContainer, SWT.BORDER | SWT.SINGLE);\r | |
1053 | gd = new GridData(SWT.CENTER, SWT.CENTER, false, false);\r | |
1054 | gd.widthHint = 20;\r | |
1055 | cardinalityMinText.setLayoutData(gd);\r | |
1056 | cardinalityMinText.setVisible(false);\r | |
1057 | \r | |
1058 | cardinalityMaxLabel = new Label(cardinalityContainer, SWT.NONE);\r | |
1059 | cardinalityMaxLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));\r | |
3b38ea61 | 1060 | cardinalityMaxLabel.setText(Messages.CustomTxtParserInputWizardPage_max);\r |
c3c5c786 FC |
1061 | cardinalityMaxLabel.setVisible(false);\r |
1062 | \r | |
1063 | cardinalityMaxText = new Text(cardinalityContainer, SWT.BORDER | SWT.SINGLE);\r | |
1064 | gd = new GridData(SWT.CENTER, SWT.CENTER, false, false);\r | |
1065 | gd.widthHint = 20;\r | |
1066 | cardinalityMaxText.setLayoutData(gd);\r | |
1067 | cardinalityMaxText.setVisible(false);\r | |
1068 | \r | |
1069 | infiniteButton = new Button(cardinalityContainer, SWT.PUSH);\r | |
1070 | infiniteButton.setText(INFINITY_STRING);\r | |
1071 | infiniteButton.setVisible(false);\r | |
1072 | infiniteButton.addSelectionListener(new SelectionAdapter(){\r | |
1073 | @Override\r | |
1074 | public void widgetSelected(SelectionEvent e) {\r | |
1075 | cardinalityMaxText.setText(INFINITY_STRING);\r | |
1076 | }});\r | |
1077 | \r | |
1078 | if (inputLine.cardinality.equals(Cardinality.ZERO_OR_MORE)) {\r | |
1079 | cardinalityCombo.select(0);\r | |
1080 | } else if (inputLine.cardinality.equals(Cardinality.ONE_OR_MORE)) {\r | |
1081 | cardinalityCombo.select(1);\r | |
1082 | } else if (inputLine.cardinality.equals(Cardinality.ZERO_OR_ONE)) {\r | |
1083 | cardinalityCombo.select(2);\r | |
1084 | } else if (inputLine.cardinality.equals(Cardinality.ONE)) {\r | |
1085 | cardinalityCombo.select(3);\r | |
1086 | } else {\r | |
1087 | cardinalityCombo.select(4);\r | |
1088 | cardinalityMinLabel.setVisible(true);\r | |
1089 | cardinalityMinText.setVisible(true);\r | |
1090 | if (inputLine.getMinCount() >= 0) {\r | |
1091 | cardinalityMinText.setText(Integer.toString(inputLine.getMinCount()));\r | |
1092 | }\r | |
1093 | cardinalityMaxLabel.setVisible(true);\r | |
1094 | cardinalityMaxText.setVisible(true);\r | |
1095 | if (inputLine.getMaxCount() == Cardinality.INF) {\r | |
1096 | cardinalityMaxText.setText(INFINITY_STRING);\r | |
1097 | } else if (inputLine.getMaxCount() >= 0) {\r | |
1098 | cardinalityMaxText.setText(Integer.toString(inputLine.getMaxCount()));\r | |
1099 | }\r | |
1100 | infiniteButton.setVisible(true);\r | |
1101 | }\r | |
1102 | \r | |
1103 | VerifyListener digitsListener = new VerifyListener() {\r | |
d4011df2 | 1104 | @Override\r |
c3c5c786 FC |
1105 | public void verifyText(VerifyEvent e) {\r |
1106 | if (e.text.equals(INFINITY_STRING)) {\r | |
1107 | e.doit = e.widget == cardinalityMaxText && e.start == 0 && e.end == ((Text) e.widget).getText().length();\r | |
1108 | } else {\r | |
1109 | if (((Text) e.widget).getText().equals(INFINITY_STRING)) {\r | |
1110 | e.doit = e.start == 0 && e.end == ((Text) e.widget).getText().length();\r | |
1111 | }\r | |
1112 | for (int i = 0; i < e.text.length(); i++) {\r | |
1113 | if (!Character.isDigit(e.text.charAt(i))) {\r | |
1114 | e.doit = false;\r | |
1115 | break;\r | |
1116 | }\r | |
1117 | }\r | |
1118 | }\r | |
1119 | }};\r | |
1120 | \r | |
1121 | cardinalityMinText.addModifyListener(updateListener);\r | |
1122 | cardinalityMaxText.addModifyListener(updateListener);\r | |
1123 | cardinalityMinText.addVerifyListener(digitsListener);\r | |
1124 | cardinalityMaxText.addVerifyListener(digitsListener);\r | |
1125 | \r | |
1126 | if (inputLine.columns != null) {\r | |
1127 | for (InputData inputData : inputLine.columns) {\r | |
1128 | InputGroup inputGroup = new InputGroup(group, this, inputs.size()+1);\r | |
1129 | if (inputData.name.equals(CustomTxtTraceDefinition.TAG_TIMESTAMP)) {\r | |
1130 | inputGroup.tagCombo.select(0);\r | |
1131 | inputGroup.tagText.setText(inputData.format);\r | |
3b38ea61 | 1132 | inputGroup.tagLabel.setText(Messages.CustomTxtParserInputWizardPage_format);\r |
c3c5c786 FC |
1133 | inputGroup.tagLabel.setVisible(true);\r |
1134 | inputGroup.tagText.setVisible(true);\r | |
1135 | inputGroup.tagText.addModifyListener(updateListener);\r | |
1136 | } else if (inputData.name.equals(CustomTxtTraceDefinition.TAG_MESSAGE)) {\r | |
1137 | inputGroup.tagCombo.select(1);\r | |
1138 | } else {\r | |
1139 | inputGroup.tagCombo.select(2);\r | |
1140 | inputGroup.tagText.setText(inputData.name);\r | |
3b38ea61 | 1141 | inputGroup.tagLabel.setText(Messages.CustomTxtParserInputWizardPage_name);\r |
c3c5c786 FC |
1142 | inputGroup.tagLabel.setVisible(true);\r |
1143 | inputGroup.tagText.setVisible(true);\r | |
1144 | inputGroup.tagText.addModifyListener(updateListener);\r | |
1145 | }\r | |
1146 | inputGroup.actionCombo.select(inputData.action);\r | |
1147 | inputs.add(inputGroup);\r | |
1148 | }\r | |
1149 | }\r | |
1150 | \r | |
1151 | createAddGroupButton();\r | |
1152 | }\r | |
1153 | \r | |
1154 | private void createAddGroupButton() {\r | |
1155 | addGroupButton = new Button(group, SWT.PUSH);\r | |
1156 | addGroupButton.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));\r | |
1157 | addGroupButton.setImage(addImage);\r | |
3b38ea61 | 1158 | addGroupButton.setToolTipText(Messages.CustomTxtParserInputWizardPage_addGroup);\r |
c3c5c786 | 1159 | addGroupButton.addSelectionListener(new SelectionAdapter() {\r |
9ccc6d01 | 1160 | @Override\r |
c3c5c786 FC |
1161 | public void widgetSelected(SelectionEvent e) {\r |
1162 | removeAddGroupButton();\r | |
1163 | inputs.add(new InputGroup(group, Line.this, inputs.size()+1));\r | |
1164 | createAddGroupButton();\r | |
1165 | lineContainer.layout();\r | |
1166 | lineScrolledComposite.setMinSize(lineContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT).x, lineContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT).y-1);\r | |
1167 | group.getParent().layout();\r | |
1168 | validate();\r | |
1169 | updatePreviews();\r | |
1170 | }\r | |
1171 | });\r | |
1172 | \r | |
1173 | addGroupLabel = new Label(group, SWT.NULL);\r | |
3b38ea61 | 1174 | addGroupLabel.setText(Messages.CustomTxtParserInputWizardPage_newGroup);\r |
c3c5c786 FC |
1175 | }\r |
1176 | \r | |
1177 | private void removeAddGroupButton() {\r | |
1178 | addGroupButton.dispose();\r | |
1179 | addGroupLabel.dispose();\r | |
1180 | }\r | |
1181 | \r | |
1182 | private void removeInput(int inputNumber) {\r | |
1183 | if (--inputNumber < inputs.size()) {\r | |
1184 | inputs.remove(inputNumber).dispose();\r | |
1185 | for (int i = inputNumber; i < inputs.size(); i++) {\r | |
1186 | inputs.get(i).setInputNumber(i+1);\r | |
1187 | }\r | |
1188 | lineContainer.layout();\r | |
1189 | lineScrolledComposite.setMinSize(lineContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT).x, lineContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT).y-1);\r | |
1190 | group.getParent().layout();\r | |
1191 | }\r | |
1192 | }\r | |
1193 | \r | |
1194 | // private void setName(String name) {\r | |
1195 | // this.name = name;\r | |
1196 | // group.setText("Line " + name);\r | |
1197 | // }\r | |
1198 | \r | |
1199 | private void dispose() {\r | |
1200 | group.dispose();\r | |
1201 | }\r | |
1202 | \r | |
1203 | private void extractInputs() {\r | |
1204 | inputLine.setRegex(selectedLine.regexText.getText());\r | |
1205 | switch (cardinalityCombo.getSelectionIndex()) {\r | |
1206 | case 0:\r | |
1207 | inputLine.cardinality = Cardinality.ZERO_OR_MORE;\r | |
1208 | break;\r | |
1209 | case 1:\r | |
1210 | inputLine.cardinality = Cardinality.ONE_OR_MORE;\r | |
1211 | break;\r | |
1212 | case 2:\r | |
1213 | inputLine.cardinality = Cardinality.ZERO_OR_ONE;\r | |
1214 | break;\r | |
1215 | case 3:\r | |
1216 | inputLine.cardinality = Cardinality.ONE;\r | |
1217 | break;\r | |
1218 | case 4: //(?,?)\r | |
1219 | int min, max;\r | |
1220 | try {\r | |
1221 | min = Integer.parseInt(cardinalityMinText.getText());\r | |
1222 | } catch (NumberFormatException e) {\r | |
1223 | min = -1;\r | |
1224 | }\r | |
1225 | try {\r | |
1226 | if (cardinalityMaxText.getText().equals(INFINITY_STRING)) {\r | |
1227 | max = Cardinality.INF;\r | |
1228 | } else {\r | |
1229 | max = Integer.parseInt(cardinalityMaxText.getText());\r | |
1230 | }\r | |
1231 | } catch (NumberFormatException e) {\r | |
1232 | max = -1;\r | |
1233 | }\r | |
1234 | inputLine.cardinality = new Cardinality(min, max);\r | |
1235 | break;\r | |
1236 | default:\r | |
1237 | inputLine.cardinality = Cardinality.ZERO_OR_MORE;\r | |
1238 | break;\r | |
1239 | }\r | |
1240 | inputLine.columns = new ArrayList<InputData>(inputs.size());\r | |
1241 | for (int i = 0; i < inputs.size(); i++) {\r | |
1242 | InputGroup group = inputs.get(i);\r | |
1243 | InputData inputData = new InputData();\r | |
1244 | if (group.tagCombo.getText().equals(CustomTxtTraceDefinition.TAG_OTHER)) {\r | |
1245 | inputData.name = group.tagText.getText().trim();\r | |
1246 | } else {\r | |
1247 | inputData.name = group.tagCombo.getText();\r | |
1248 | if (group.tagCombo.getText().equals(CustomTxtTraceDefinition.TAG_TIMESTAMP)) {\r | |
1249 | inputData.format = group.tagText.getText().trim();\r | |
1250 | }\r | |
1251 | }\r | |
1252 | inputData.action = group.actionCombo.getSelectionIndex();\r | |
1253 | inputLine.columns.add(inputData);\r | |
1254 | }\r | |
1255 | }\r | |
1256 | }\r | |
1257 | \r | |
1258 | private class InputGroup {\r | |
1259 | Line line;\r | |
1260 | int inputNumber;\r | |
1261 | \r | |
1262 | // children of parent (must be disposed)\r | |
1263 | Composite labelComposite;\r | |
1264 | Composite tagComposite;\r | |
1265 | Label previewLabel;\r | |
1266 | Text previewText;\r | |
1267 | \r | |
1268 | // children of labelComposite\r | |
1269 | Label inputLabel;\r | |
1270 | \r | |
1271 | // children of tagComposite\r | |
1272 | Combo tagCombo;\r | |
1273 | Label tagLabel;\r | |
1274 | Text tagText;\r | |
1275 | Combo actionCombo;\r | |
1276 | \r | |
1277 | public InputGroup(Composite parent, Line line, int inputNumber) {\r | |
1278 | this.line = line;\r | |
1279 | this.inputNumber = inputNumber;\r | |
1280 | \r | |
1281 | labelComposite = new Composite(parent, SWT.FILL);\r | |
1282 | GridLayout labelLayout = new GridLayout(2, false);\r | |
1283 | labelLayout.marginWidth = 0;\r | |
1284 | labelLayout.marginHeight = 0;\r | |
1285 | labelComposite.setLayout(labelLayout);\r | |
1286 | labelComposite.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));\r | |
1287 | \r | |
1288 | Button deleteButton = new Button(labelComposite, SWT.PUSH);\r | |
1289 | deleteButton.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));\r | |
1290 | deleteButton.setImage(deleteImage);\r | |
3b38ea61 | 1291 | deleteButton.setToolTipText(Messages.CustomTxtParserInputWizardPage_removeGroup);\r |
c3c5c786 | 1292 | deleteButton.addSelectionListener(new SelectionAdapter() {\r |
9ccc6d01 | 1293 | @Override\r |
c3c5c786 FC |
1294 | public void widgetSelected(SelectionEvent e) {\r |
1295 | InputGroup.this.line.removeInput(InputGroup.this.inputNumber);\r | |
1296 | validate();\r | |
1297 | updatePreviews();\r | |
1298 | }\r | |
1299 | });\r | |
1300 | \r | |
1301 | inputLabel = new Label(labelComposite, SWT.NULL);\r | |
1302 | inputLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));\r | |
3b38ea61 | 1303 | inputLabel.setText(Messages.CustomTxtParserInputWizardPage_group + inputNumber + ":"); //$NON-NLS-1$\r |
c3c5c786 FC |
1304 | \r |
1305 | tagComposite = new Composite(parent, SWT.FILL);\r | |
1306 | GridLayout tagLayout = new GridLayout(4, false);\r | |
1307 | tagLayout.marginWidth = 0;\r | |
1308 | tagLayout.marginHeight = 0;\r | |
1309 | tagComposite.setLayout(tagLayout);\r | |
1310 | tagComposite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));\r | |
1311 | \r | |
1312 | tagCombo = new Combo(tagComposite, SWT.DROP_DOWN | SWT.READ_ONLY);\r | |
1313 | tagCombo.setItems(new String[] {CustomTxtTraceDefinition.TAG_TIMESTAMP,\r | |
1314 | CustomTxtTraceDefinition.TAG_MESSAGE,\r | |
1315 | CustomTxtTraceDefinition.TAG_OTHER});\r | |
1316 | tagCombo.select(1);\r | |
1317 | tagCombo.addSelectionListener(new SelectionListener(){\r | |
d4011df2 | 1318 | @Override\r |
c3c5c786 | 1319 | public void widgetDefaultSelected(SelectionEvent e) {}\r |
d4011df2 | 1320 | @Override\r |
c3c5c786 FC |
1321 | public void widgetSelected(SelectionEvent e) {\r |
1322 | tagText.removeModifyListener(updateListener);\r | |
1323 | switch (tagCombo.getSelectionIndex()) {\r | |
1324 | case 0: //Time Stamp\r | |
3b38ea61 | 1325 | tagLabel.setText(Messages.CustomTxtParserInputWizardPage_format);\r |
c3c5c786 FC |
1326 | tagLabel.setVisible(true);\r |
1327 | tagText.setVisible(true);\r | |
1328 | tagText.addModifyListener(updateListener);\r | |
1329 | break;\r | |
1330 | case 1: //Message\r | |
1331 | tagLabel.setVisible(false);\r | |
1332 | tagText.setVisible(false);\r | |
1333 | break;\r | |
1334 | case 2: //Other\r | |
3b38ea61 | 1335 | tagLabel.setText(Messages.CustomTxtParserInputWizardPage_name);\r |
c3c5c786 FC |
1336 | tagLabel.setVisible(true);\r |
1337 | tagText.setVisible(true);\r | |
1338 | tagText.addModifyListener(updateListener);\r | |
1339 | break;\r | |
1340 | case 3: //Continue\r | |
1341 | tagLabel.setVisible(false);\r | |
1342 | tagText.setVisible(false);\r | |
1343 | break;\r | |
1344 | }\r | |
1345 | tagComposite.layout();\r | |
1346 | validate();\r | |
1347 | updatePreviews();\r | |
1348 | }});\r | |
1349 | \r | |
1350 | tagLabel = new Label(tagComposite, SWT.NULL);\r | |
1351 | tagLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));\r | |
1352 | tagLabel.setVisible(false);\r | |
1353 | \r | |
1354 | tagText = new Text(tagComposite, SWT.BORDER | SWT.SINGLE);\r | |
1355 | GridData gd = new GridData(SWT.FILL, SWT.CENTER, true, false);\r | |
1356 | gd.widthHint = 0;\r | |
1357 | tagText.setLayoutData(gd);\r | |
1358 | tagText.setVisible(false);\r | |
1359 | \r | |
1360 | actionCombo = new Combo(tagComposite, SWT.DROP_DOWN | SWT.READ_ONLY);\r | |
3b38ea61 | 1361 | actionCombo.setItems(new String[] {Messages.CustomTxtParserInputWizardPage_set, Messages.CustomTxtParserInputWizardPage_append, Messages.CustomTxtParserInputWizardPage_appendWith});\r |
c3c5c786 FC |
1362 | actionCombo.select(0);\r |
1363 | actionCombo.addSelectionListener(updateListener);\r | |
1364 | \r | |
1365 | previewLabel = new Label(parent, SWT.NULL);\r | |
1366 | previewLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));\r | |
3b38ea61 | 1367 | previewLabel.setText(Messages.CustomTxtParserInputWizardPage_preview);\r |
c3c5c786 FC |
1368 | \r |
1369 | previewText = new Text(parent, SWT.BORDER | SWT.SINGLE | SWT.READ_ONLY);\r | |
1370 | gd = new GridData(SWT.FILL, SWT.CENTER, true, false);\r | |
1371 | gd.widthHint = 0;\r | |
1372 | previewText.setLayoutData(gd);\r | |
3b38ea61 | 1373 | previewText.setText(Messages.CustomTxtParserInputWizardPage_noMatch);\r |
c3c5c786 FC |
1374 | previewText.setBackground(COLOR_WIDGET_BACKGROUND);\r |
1375 | }\r | |
1376 | \r | |
1377 | private void dispose() {\r | |
1378 | labelComposite.dispose();\r | |
1379 | tagComposite.dispose();\r | |
1380 | previewLabel.dispose();\r | |
1381 | previewText.dispose();\r | |
1382 | }\r | |
1383 | \r | |
1384 | private void setInputNumber(int inputNumber) {\r | |
1385 | this.inputNumber = inputNumber;\r | |
3b38ea61 | 1386 | inputLabel.setText(Messages.CustomTxtParserInputWizardPage_group + inputNumber + ":"); //$NON-NLS-1$\r |
c3c5c786 FC |
1387 | labelComposite.layout();\r |
1388 | }\r | |
1389 | }\r | |
1390 | \r | |
1391 | private void validate() {\r | |
1392 | \r | |
1393 | definition.definitionName = logtypeText.getText().trim();\r | |
1394 | definition.timeStampOutputFormat = timestampOutputFormatText.getText().trim();\r | |
1395 | \r | |
1396 | if (selectedLine != null) {\r | |
1397 | selectedLine.extractInputs();\r | |
1398 | treeViewer.refresh();\r | |
1399 | }\r | |
1400 | \r | |
1401 | StringBuffer errors = new StringBuffer();\r | |
1402 | \r | |
1403 | if (definition.definitionName.length() == 0) {\r | |
3b38ea61 | 1404 | errors.append("Enter a name for the new log type. "); //$NON-NLS-1$\r |
c3c5c786 FC |
1405 | logtypeText.setBackground(COLOR_LIGHT_RED);\r |
1406 | } else {\r | |
1407 | logtypeText.setBackground(COLOR_TEXT_BACKGROUND);\r | |
1408 | for (CustomTxtTraceDefinition def : CustomTxtTraceDefinition.loadAll()) {\r | |
1409 | if (definition.definitionName.equals(def.definitionName)) {\r | |
1410 | if (editDefinitionName == null || ! editDefinitionName.equals(definition.definitionName)) {\r | |
3b38ea61 | 1411 | errors.append("The log type name already exists. "); //$NON-NLS-1$\r |
c3c5c786 FC |
1412 | logtypeText.setBackground(COLOR_LIGHT_RED);\r |
1413 | break;\r | |
1414 | }\r | |
1415 | }\r | |
1416 | }\r | |
1417 | }\r | |
1418 | \r | |
1419 | timestampFound = false;\r | |
1420 | for (int i = 0; i < definition.inputs.size(); i++) {\r | |
1421 | \r | |
1422 | InputLine inputLine = definition.inputs.get(i);\r | |
1423 | String name = Integer.toString(i+1);\r | |
1424 | errors.append(validateLine(inputLine, name));\r | |
1425 | }\r | |
1426 | if (timestampFound) {\r | |
1427 | if (definition.timeStampOutputFormat.length() == 0) {\r | |
3b38ea61 | 1428 | errors.append("Enter the output format for the Time Stamp field. "); //$NON-NLS-1$\r |
c3c5c786 FC |
1429 | timestampOutputFormatText.setBackground(COLOR_LIGHT_RED);\r |
1430 | } else {\r | |
1431 | try {\r | |
1432 | new SimpleDateFormat(definition.timeStampOutputFormat);\r | |
1433 | timestampOutputFormatText.setBackground(COLOR_TEXT_BACKGROUND);\r | |
1434 | } catch (IllegalArgumentException e) {\r | |
3b38ea61 | 1435 | errors.append("Enter a valid output format for the Time Stamp field. "); //$NON-NLS-1$\r |
c3c5c786 FC |
1436 | timestampOutputFormatText.setBackground(COLOR_LIGHT_RED);\r |
1437 | }\r | |
1438 | }\r | |
1439 | \r | |
1440 | } else {\r | |
1441 | timestampOutputFormatText.setBackground(COLOR_TEXT_BACKGROUND);\r | |
1442 | // timestampPreviewText.setBackground(COLOR_WIDGET_BACKGROUND);\r | |
1443 | // errors.append("Identify a Time Stamp group (Line "+name+"). ");\r | |
1444 | // timestampPreviewText.setText("*no timestamp group*");\r | |
1445 | // timestampPreviewText.setBackground(COLOR_LIGHT_RED);\r | |
1446 | }\r | |
1447 | \r | |
1448 | if (errors.length() == 0) {\r | |
1449 | setDescription(defaultDescription);\r | |
1450 | setPageComplete(true);\r | |
1451 | } else {\r | |
1452 | setDescription(errors.toString());\r | |
1453 | setPageComplete(false);\r | |
1454 | }\r | |
1455 | }\r | |
1456 | \r | |
1457 | public StringBuffer validateLine(InputLine inputLine, String name) {\r | |
1458 | StringBuffer errors = new StringBuffer();\r | |
1459 | Line line = null;\r | |
1460 | if (selectedLine != null && selectedLine.inputLine.equals(inputLine)) line = selectedLine;\r | |
1461 | try {\r | |
1462 | Pattern.compile(inputLine.getRegex());\r | |
1463 | if (line != null) line.regexText.setBackground(COLOR_TEXT_BACKGROUND);\r | |
1464 | } catch (PatternSyntaxException e) {\r | |
3b38ea61 | 1465 | errors.append("Enter a valid regular expression (Line "+name+"). "); //$NON-NLS-1$ //$NON-NLS-2$\r |
c3c5c786 FC |
1466 | if (line != null) line.regexText.setBackground(COLOR_LIGHT_RED);\r |
1467 | }\r | |
1468 | if (inputLine.getMinCount() == -1) {\r | |
3b38ea61 | 1469 | errors.append("Enter a minimum value for cardinality (Line "+name+"). "); //$NON-NLS-1$ //$NON-NLS-2$\r |
c3c5c786 FC |
1470 | if (line != null) line.cardinalityMinText.setBackground(COLOR_LIGHT_RED);\r |
1471 | } else {\r | |
1472 | if (line != null) line.cardinalityMinText.setBackground(COLOR_TEXT_BACKGROUND);\r | |
1473 | }\r | |
1474 | if (inputLine.getMaxCount() == -1) {\r | |
3b38ea61 | 1475 | errors.append("Enter a maximum value for cardinality (Line "+name+"). "); //$NON-NLS-1$ //$NON-NLS-2$\r |
c3c5c786 FC |
1476 | if (line != null) line.cardinalityMaxText.setBackground(COLOR_LIGHT_RED);\r |
1477 | } else if (inputLine.getMinCount() > inputLine.getMaxCount()) {\r | |
3b38ea61 | 1478 | errors.append("Enter correct (min <= max) values for cardinality (Line "+name+"). "); //$NON-NLS-1$ //$NON-NLS-2$\r |
c3c5c786 FC |
1479 | if (line != null) line.cardinalityMinText.setBackground(COLOR_LIGHT_RED);\r |
1480 | if (line != null) line.cardinalityMaxText.setBackground(COLOR_LIGHT_RED);\r | |
1481 | } else {\r | |
1482 | if (line != null) line.cardinalityMaxText.setBackground(COLOR_TEXT_BACKGROUND);\r | |
1483 | }\r | |
1484 | for (int i = 0; inputLine.columns != null && i < inputLine.columns.size(); i++) {\r | |
1485 | InputData inputData = inputLine.columns.get(i);\r | |
1486 | InputGroup group = null;\r | |
1487 | if (line != null) group = line.inputs.get(i);\r | |
1488 | if (inputData.name.equals(CustomTxtTraceDefinition.TAG_TIMESTAMP)) {\r | |
1489 | timestampFound = true;\r | |
1490 | if (inputData.format.length() == 0) {\r | |
3b38ea61 | 1491 | errors.append("Enter the input format for the Time Stamp (Line "+name+" Group "+(i+1)+"). "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$\r |
c3c5c786 FC |
1492 | if (group != null) group.tagText.setBackground(COLOR_LIGHT_RED);\r |
1493 | } else {\r | |
1494 | try {\r | |
1495 | new SimpleDateFormat(inputData.format);\r | |
1496 | if (group != null) group.tagText.setBackground(COLOR_TEXT_BACKGROUND);\r | |
1497 | } catch (IllegalArgumentException e) {\r | |
3b38ea61 | 1498 | errors.append("Enter a valid input format for the Time Stamp (Line "+name+" Group "+(i+1)+"). "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$\r |
c3c5c786 FC |
1499 | if (group != null) group.tagText.setBackground(COLOR_LIGHT_RED);\r |
1500 | }\r | |
1501 | }\r | |
1502 | } else if (inputData.name.length() == 0) {\r | |
3b38ea61 | 1503 | errors.append("Enter a name for the data group (Line "+name+" Group "+(i+1)+"). "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$\r |
c3c5c786 FC |
1504 | if (group != null) group.tagText.setBackground(COLOR_LIGHT_RED);\r |
1505 | } else {\r | |
1506 | if (group != null) group.tagText.setBackground(COLOR_TEXT_BACKGROUND);\r | |
1507 | }\r | |
1508 | }\r | |
1509 | for (int i = 0; inputLine.childrenInputs != null && i < inputLine.childrenInputs.size(); i++) {\r | |
3b38ea61 | 1510 | errors.append(validateLine(inputLine.childrenInputs.get(i), name+"."+(i+1))); //$NON-NLS-1$\r |
c3c5c786 FC |
1511 | }\r |
1512 | return errors;\r | |
1513 | }\r | |
1514 | \r | |
1515 | public CustomTxtTraceDefinition getDefinition() {\r | |
1516 | return definition;\r | |
1517 | }\r | |
1518 | \r | |
1519 | public char[] getInputText() {\r | |
1520 | return inputText.getText().toCharArray();\r | |
1521 | }\r | |
1522 | }\r |