Commit | Line | Data |
---|---|---|
be222f56 | 1 | /******************************************************************************* |
c8422608 | 2 | * Copyright (c) 2010, 2013 Ericsson |
a0a88f65 | 3 | * |
be222f56 PT |
4 | * All rights reserved. This program and the accompanying materials are |
5 | * made available under the terms of the Eclipse Public License v1.0 which | |
6 | * accompanies this distribution, and is available at | |
7 | * http://www.eclipse.org/legal/epl-v10.html | |
a0a88f65 | 8 | * |
be222f56 PT |
9 | * Contributors: |
10 | * Patrick Tasse - Initial API and implementation | |
11 | *******************************************************************************/ | |
12 | ||
13 | package org.eclipse.linuxtools.tmf.ui.views.filter; | |
14 | ||
15 | import java.util.ArrayList; | |
16 | import java.util.LinkedHashMap; | |
17 | import java.util.Map; | |
18 | import java.util.Map.Entry; | |
19 | ||
20 | import org.eclipse.core.runtime.CoreException; | |
21 | import org.eclipse.core.runtime.IConfigurationElement; | |
22 | import org.eclipse.jface.action.Action; | |
23 | import org.eclipse.jface.action.IMenuListener; | |
24 | import org.eclipse.jface.action.IMenuManager; | |
25 | import org.eclipse.jface.action.MenuManager; | |
26 | import org.eclipse.jface.action.Separator; | |
27 | import org.eclipse.jface.viewers.ISelection; | |
28 | import org.eclipse.jface.viewers.ISelectionChangedListener; | |
29 | import org.eclipse.jface.viewers.IStructuredSelection; | |
30 | import org.eclipse.jface.viewers.SelectionChangedEvent; | |
31 | import org.eclipse.jface.viewers.StructuredSelection; | |
32 | import org.eclipse.jface.viewers.TreeViewer; | |
33 | import org.eclipse.linuxtools.internal.tmf.ui.Messages; | |
34 | import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomTraceDefinition.OutputColumn; | |
35 | import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomTxtEvent; | |
36 | import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomTxtTraceDefinition; | |
37 | import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomXmlEvent; | |
38 | import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomXmlTraceDefinition; | |
39 | import org.eclipse.linuxtools.tmf.core.event.ITmfEvent; | |
40 | import org.eclipse.linuxtools.tmf.core.event.ITmfEventType; | |
41 | import org.eclipse.linuxtools.tmf.core.filter.model.ITmfFilterTreeNode; | |
42 | import org.eclipse.linuxtools.tmf.core.filter.model.TmfFilterAndNode; | |
43 | import org.eclipse.linuxtools.tmf.core.filter.model.TmfFilterCompareNode; | |
44 | import org.eclipse.linuxtools.tmf.core.filter.model.TmfFilterCompareNode.Type; | |
45 | import org.eclipse.linuxtools.tmf.core.filter.model.TmfFilterContainsNode; | |
46 | import org.eclipse.linuxtools.tmf.core.filter.model.TmfFilterEqualsNode; | |
47 | import org.eclipse.linuxtools.tmf.core.filter.model.TmfFilterEventTypeNode; | |
48 | import org.eclipse.linuxtools.tmf.core.filter.model.TmfFilterMatchesNode; | |
49 | import org.eclipse.linuxtools.tmf.core.filter.model.TmfFilterNode; | |
50 | import org.eclipse.linuxtools.tmf.core.filter.model.TmfFilterOrNode; | |
51 | import org.eclipse.linuxtools.tmf.core.filter.model.TmfFilterRootNode; | |
52 | import org.eclipse.linuxtools.tmf.core.filter.model.TmfFilterTreeNode; | |
53 | import org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceType; | |
54 | import org.eclipse.swt.SWT; | |
55 | import org.eclipse.swt.custom.SashForm; | |
56 | import org.eclipse.swt.events.FocusEvent; | |
57 | import org.eclipse.swt.events.FocusListener; | |
58 | import org.eclipse.swt.events.ModifyEvent; | |
59 | import org.eclipse.swt.events.ModifyListener; | |
60 | import org.eclipse.swt.events.PaintEvent; | |
61 | import org.eclipse.swt.events.PaintListener; | |
62 | import org.eclipse.swt.events.SelectionAdapter; | |
63 | import org.eclipse.swt.events.SelectionEvent; | |
64 | import org.eclipse.swt.layout.FillLayout; | |
65 | import org.eclipse.swt.layout.GridData; | |
66 | import org.eclipse.swt.layout.GridLayout; | |
67 | import org.eclipse.swt.widgets.Button; | |
68 | import org.eclipse.swt.widgets.Combo; | |
69 | import org.eclipse.swt.widgets.Composite; | |
70 | import org.eclipse.swt.widgets.Control; | |
71 | import org.eclipse.swt.widgets.Display; | |
72 | import org.eclipse.swt.widgets.Label; | |
73 | import org.eclipse.swt.widgets.Menu; | |
74 | import org.eclipse.swt.widgets.Text; | |
75 | import org.eclipse.swt.widgets.TreeItem; | |
76 | ||
77 | class FilterViewer extends Composite { | |
78 | ||
79 | private static final String CUSTOM_TXT_CATEGORY = "Custom Text"; //$NON-NLS-1$ | |
80 | private static final String CUSTOM_XML_CATEGORY = "Custom XML"; //$NON-NLS-1$ | |
81 | ||
82 | private TreeViewer fViewer; | |
83 | private Composite fComposite; | |
a0a88f65 | 84 | |
be222f56 PT |
85 | public FilterViewer(Composite parent, int style) { |
86 | super(parent, style); | |
87 | ||
88 | setLayout(new FillLayout()); | |
89 | GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true); | |
90 | setLayoutData(gd); | |
a0a88f65 | 91 | |
be222f56 PT |
92 | final SashForm sash = new SashForm(this, SWT.HORIZONTAL); |
93 | ||
94 | // Create the tree viewer to display the filter tree | |
95 | fViewer = new TreeViewer(sash, SWT.NONE); | |
96 | fViewer.setContentProvider(new FilterTreeContentProvider()); | |
97 | fViewer.setLabelProvider(new FilterTreeLabelProvider()); | |
98 | fViewer.setInput(new TmfFilterRootNode()); | |
a0a88f65 | 99 | |
be222f56 PT |
100 | // Create the empty filter node properties panel |
101 | fComposite = new Composite(sash, SWT.NONE); | |
102 | GridLayout gl = new GridLayout(); | |
103 | gl.marginHeight = 0; | |
104 | gl.marginWidth = 0; | |
105 | fComposite.setLayout(gl); | |
106 | ||
107 | createContextMenu(); | |
a0a88f65 | 108 | |
be222f56 PT |
109 | fViewer.addSelectionChangedListener(new ISelectionChangedListener() { |
110 | @Override | |
111 | public void selectionChanged(SelectionChangedEvent event) { | |
112 | if (!(event.getSelection().isEmpty()) && event.getSelection() instanceof IStructuredSelection) { | |
113 | // Update the filter node properties panel to the selection | |
114 | IStructuredSelection selection = (IStructuredSelection) event.getSelection(); | |
115 | ITmfFilterTreeNode node = (ITmfFilterTreeNode) selection.getFirstElement(); | |
116 | updateFilterNodeComposite(node); | |
117 | // Highlight the selection's children | |
118 | highlightTreeItems(fViewer.getTree().getSelection()[0].getItems()); | |
119 | } else { | |
120 | updateFilterNodeComposite(null); | |
121 | } | |
122 | } | |
123 | }); | |
124 | ||
125 | fViewer.getTree().addPaintListener(new PaintListener() { | |
126 | @Override | |
127 | public void paintControl(PaintEvent e) { | |
128 | TmfFilterTreeNode root = (TmfFilterTreeNode) fViewer.getInput(); | |
129 | if (root == null || root.getChildrenCount() == 0) { | |
130 | e.gc.setForeground(Display.getDefault().getSystemColor(SWT.COLOR_BLACK)); | |
131 | e.gc.drawText(Messages.FilterViewer_EmptyTreeHintText, 5, 0); | |
132 | } | |
133 | } | |
134 | }); | |
135 | } | |
a0a88f65 | 136 | |
be222f56 PT |
137 | /** |
138 | * Create the context menu for the tree viewer | |
139 | */ | |
140 | private void createContextMenu() { | |
141 | // Adds root context menu | |
142 | MenuManager menuManager = new MenuManager(); | |
143 | menuManager.setRemoveAllWhenShown(true); | |
144 | menuManager.addMenuListener(new IMenuListener() { | |
145 | @Override | |
146 | public void menuAboutToShow(IMenuManager manager) { | |
147 | fillContextMenu(manager); | |
148 | } | |
149 | }); | |
150 | ||
151 | // Context | |
152 | Menu contextMenu = menuManager.createContextMenu(fViewer.getTree()); | |
153 | ||
154 | // Publish it | |
155 | fViewer.getTree().setMenu(contextMenu); | |
156 | } | |
a0a88f65 | 157 | |
be222f56 | 158 | /** |
a0a88f65 AM |
159 | * Fill the context menu for the tree viewer. |
160 | * | |
161 | * @param manager | |
162 | * The menu manager | |
be222f56 PT |
163 | */ |
164 | protected void fillContextMenu(IMenuManager manager) { | |
165 | final ISelection selection = fViewer.getSelection(); | |
166 | ITmfFilterTreeNode filterTreeNode = null; | |
167 | if (selection instanceof StructuredSelection) { | |
168 | Object element = ((StructuredSelection) selection).getFirstElement(); | |
169 | if (element instanceof ITmfFilterTreeNode) { | |
170 | filterTreeNode = (ITmfFilterTreeNode) element; | |
171 | } | |
172 | } | |
173 | ||
174 | final ITmfFilterTreeNode selectedNode = filterTreeNode; | |
a0a88f65 | 175 | |
be222f56 | 176 | if (selectedNode != null) { |
a0a88f65 | 177 | |
be222f56 | 178 | fillContextMenuForNode(selectedNode, manager); |
a0a88f65 | 179 | |
be222f56 PT |
180 | if (selectedNode.getValidChildren().size() > 0) { |
181 | manager.add(new Separator()); | |
182 | } | |
183 | ||
184 | Action deleteAction = new Action() { | |
185 | @Override | |
186 | public void run() { | |
187 | selectedNode.remove(); | |
188 | fViewer.refresh(); | |
189 | } | |
190 | }; | |
191 | deleteAction.setText(Messages.FilterViewer_DeleteActionText); | |
192 | manager.add(deleteAction); | |
a0a88f65 | 193 | |
be222f56 PT |
194 | manager.add(new Separator()); |
195 | } | |
196 | ||
197 | if (fViewer.getInput() instanceof TmfFilterRootNode || selectedNode == null) { | |
198 | final ITmfFilterTreeNode root = (ITmfFilterTreeNode) fViewer.getInput(); | |
a0a88f65 | 199 | |
be222f56 PT |
200 | fillContextMenuForNode(root, manager); |
201 | } | |
202 | } | |
a0a88f65 | 203 | |
be222f56 PT |
204 | /** |
205 | * Fill the context menu with the valid children of the provided node | |
a0a88f65 AM |
206 | * |
207 | * @param node | |
208 | * The target node | |
209 | * @param manager | |
210 | * The menu manager | |
be222f56 PT |
211 | */ |
212 | protected void fillContextMenuForNode(final ITmfFilterTreeNode node, IMenuManager manager) { | |
213 | for (final String child : node.getValidChildren()) { | |
214 | final Action action = new Action() { | |
215 | @Override | |
216 | public void run() { | |
217 | ITmfFilterTreeNode newNode = null; | |
218 | if (TmfFilterNode.NODE_NAME.equals(child)) { | |
219 | newNode = new TmfFilterNode(node, ""); //$NON-NLS-1$ | |
220 | } else if (TmfFilterEventTypeNode.NODE_NAME.equals(child)) { | |
221 | newNode = new TmfFilterEventTypeNode(node); | |
222 | } else if (TmfFilterAndNode.NODE_NAME.equals(child)) { | |
223 | newNode = new TmfFilterAndNode(node); | |
224 | } else if (TmfFilterOrNode.NODE_NAME.equals(child)) { | |
225 | newNode = new TmfFilterOrNode(node); | |
226 | } else if (TmfFilterContainsNode.NODE_NAME.equals(child)) { | |
227 | newNode = new TmfFilterContainsNode(node); | |
228 | } else if (TmfFilterEqualsNode.NODE_NAME.equals(child)) { | |
229 | newNode = new TmfFilterEqualsNode(node); | |
230 | } else if (TmfFilterMatchesNode.NODE_NAME.equals(child)) { | |
231 | newNode = new TmfFilterMatchesNode(node); | |
232 | } else if (TmfFilterCompareNode.NODE_NAME.equals(child)) { | |
233 | newNode = new TmfFilterCompareNode(node); | |
234 | } | |
235 | if (newNode != null) { | |
236 | fViewer.refresh(); | |
237 | fViewer.setSelection(new StructuredSelection(newNode), true); | |
238 | } | |
239 | } | |
240 | }; | |
241 | if (TmfFilterNode.NODE_NAME.equals(child)) { | |
242 | action.setText(Messages.FilterViewer_NewPrefix + " " + child); //$NON-NLS-1$ | |
243 | } else { | |
244 | action.setText(child); | |
245 | } | |
246 | manager.add(action); | |
247 | } | |
248 | } | |
a0a88f65 | 249 | |
be222f56 PT |
250 | /** |
251 | * Create the appropriate filter node properties composite | |
252 | */ | |
253 | private void updateFilterNodeComposite(ITmfFilterTreeNode node) { | |
254 | for (Control control : fComposite.getChildren()) { | |
255 | control.dispose(); | |
256 | } | |
a0a88f65 | 257 | |
be222f56 PT |
258 | if (node instanceof TmfFilterNode) { |
259 | new FilterNodeComposite(fComposite, (TmfFilterNode) node); | |
260 | } else if (node instanceof TmfFilterEventTypeNode) { | |
261 | new FilterEventTypeNodeComposite(fComposite, (TmfFilterEventTypeNode) node); | |
262 | } else if (node instanceof TmfFilterAndNode) { | |
263 | new FilterAndNodeComposite(fComposite, (TmfFilterAndNode) node); | |
264 | } else if (node instanceof TmfFilterOrNode) { | |
265 | new FilterOrNodeComposite(fComposite, (TmfFilterOrNode) node); | |
266 | } else if (node instanceof TmfFilterContainsNode) { | |
267 | new FilterContainsNodeComposite(fComposite, (TmfFilterContainsNode) node); | |
268 | } else if (node instanceof TmfFilterEqualsNode) { | |
269 | new FilterEqualsNodeComposite(fComposite, (TmfFilterEqualsNode) node); | |
270 | } else if (node instanceof TmfFilterMatchesNode) { | |
271 | new FilterMatchesNodeComposite(fComposite, (TmfFilterMatchesNode) node); | |
272 | } else if (node instanceof TmfFilterCompareNode) { | |
273 | new FilterCompareNodeComposite(fComposite, (TmfFilterCompareNode) node); | |
274 | } else { | |
275 | new FilterBaseNodeComposite(fComposite); | |
276 | } | |
277 | fComposite.layout(); | |
278 | } | |
a0a88f65 | 279 | |
be222f56 PT |
280 | /** |
281 | * Highlight the provided tree items | |
282 | */ | |
283 | private void highlightTreeItems(TreeItem[] items) { | |
284 | resetTreeItems(fViewer.getTree().getItems()); | |
285 | for (TreeItem item : items) { | |
286 | item.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_BLUE)); | |
287 | } | |
288 | ||
289 | } | |
a0a88f65 | 290 | |
be222f56 PT |
291 | /** |
292 | * Reset the provided tree items (remove highlight) | |
293 | */ | |
294 | private void resetTreeItems(TreeItem[] items) { | |
295 | for (TreeItem item : items) { | |
296 | item.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_BLACK)); | |
297 | resetTreeItems(item.getItems()); | |
298 | } | |
299 | } | |
a0a88f65 | 300 | |
be222f56 PT |
301 | public void setInput(ITmfFilterTreeNode root) { |
302 | fViewer.setInput(root); | |
303 | fViewer.expandAll(); | |
a0a88f65 | 304 | |
be222f56 PT |
305 | updateFilterNodeComposite(null); |
306 | } | |
a0a88f65 | 307 | |
be222f56 PT |
308 | public ITmfFilterTreeNode getInput() { |
309 | return (ITmfFilterTreeNode) fViewer.getInput(); | |
310 | } | |
a0a88f65 | 311 | |
be222f56 PT |
312 | public void refresh() { |
313 | fViewer.refresh(); | |
314 | } | |
315 | ||
316 | public void setSelection(ITmfFilterTreeNode node, boolean reveal) { | |
317 | fViewer.setSelection(new StructuredSelection(node), reveal); | |
318 | } | |
319 | ||
320 | public void setSelection(ITmfFilterTreeNode node) { | |
321 | fViewer.setSelection(new StructuredSelection(node)); | |
322 | } | |
a0a88f65 | 323 | |
be222f56 PT |
324 | public ITmfFilterTreeNode getSelection() { |
325 | final ISelection selection = fViewer.getSelection(); | |
326 | ITmfFilterTreeNode filterTreeNode = null; | |
327 | if (selection instanceof StructuredSelection) { | |
328 | Object element = ((StructuredSelection) selection).getFirstElement(); | |
329 | if (element instanceof ITmfFilterTreeNode) { | |
330 | filterTreeNode = (ITmfFilterTreeNode) element; | |
331 | } | |
332 | } | |
333 | ||
334 | final ITmfFilterTreeNode selectedNode = filterTreeNode; | |
335 | return selectedNode; | |
336 | } | |
a0a88f65 | 337 | |
be222f56 PT |
338 | public void addSelectionChangedListener(ISelectionChangedListener listener) { |
339 | fViewer.addSelectionChangedListener(listener); | |
340 | } | |
a0a88f65 | 341 | |
be222f56 PT |
342 | public void removeSelectionChangedListener(ISelectionChangedListener listener) { |
343 | fViewer.removeSelectionChangedListener(listener); | |
344 | } | |
a0a88f65 | 345 | |
be222f56 | 346 | private class FilterBaseNodeComposite extends Composite { |
a0a88f65 | 347 | |
be222f56 PT |
348 | FilterBaseNodeComposite(Composite parent) { |
349 | super(parent, SWT.NONE); | |
350 | setLayout(new GridLayout(2, false)); | |
351 | setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); | |
352 | setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE)); | |
353 | } | |
a0a88f65 | 354 | |
be222f56 PT |
355 | protected String[] getFieldsList(ITmfFilterTreeNode node) { |
356 | ArrayList<String> fieldsList = new ArrayList<String>(); | |
41b5c37f AM |
357 | ITmfFilterTreeNode curNode = node; |
358 | while (curNode != null) { | |
359 | if (curNode instanceof TmfFilterEventTypeNode) { | |
360 | TmfFilterEventTypeNode eventTypeNode = (TmfFilterEventTypeNode) curNode; | |
be222f56 PT |
361 | for (IConfigurationElement ce : TmfTraceType.getTypeElements()) { |
362 | if (ce.getAttribute(TmfTraceType.EVENT_TYPE_ATTR).equals(eventTypeNode.getEventType())) { | |
363 | try { | |
364 | ITmfEvent event = (ITmfEvent) ce.createExecutableExtension(TmfTraceType.EVENT_TYPE_ATTR); | |
365 | ITmfEventType eventType = event.getType(); | |
366 | if (eventType != null) { | |
367 | for (String field : eventType.getRootField().getFieldNames()) { | |
368 | fieldsList.add(field); | |
369 | } | |
370 | } | |
371 | } catch (CoreException e) { | |
372 | } | |
373 | if (fieldsList.size() == 0) { | |
374 | fieldsList.add(ITmfEvent.EVENT_FIELD_TIMESTAMP); | |
375 | fieldsList.add(ITmfEvent.EVENT_FIELD_SOURCE); | |
376 | fieldsList.add(ITmfEvent.EVENT_FIELD_TYPE); | |
377 | fieldsList.add(ITmfEvent.EVENT_FIELD_REFERENCE); | |
378 | fieldsList.add(ITmfEvent.EVENT_FIELD_CONTENT); | |
379 | } | |
380 | return fieldsList.toArray(new String[0]); | |
381 | } | |
382 | } | |
383 | if (eventTypeNode.getEventType() != null && eventTypeNode.getEventType().startsWith(CustomTxtEvent.class.getCanonicalName())) { | |
384 | for (CustomTxtTraceDefinition def : CustomTxtTraceDefinition.loadAll()) { | |
385 | if (eventTypeNode.getEventType().equals(CustomTxtEvent.class.getCanonicalName() + ":" + def.definitionName)) { //$NON-NLS-1$ | |
386 | for (OutputColumn output : def.outputs) { | |
387 | fieldsList.add(output.name); | |
388 | } | |
389 | return fieldsList.toArray(new String[0]); | |
390 | } | |
391 | } | |
392 | } | |
393 | if (eventTypeNode.getEventType() != null && eventTypeNode.getEventType().startsWith(CustomXmlEvent.class.getCanonicalName())) { | |
394 | for (CustomXmlTraceDefinition def : CustomXmlTraceDefinition.loadAll()) { | |
395 | if (eventTypeNode.getEventType().equals(CustomXmlEvent.class.getCanonicalName() + ":" + def.definitionName)) { //$NON-NLS-1$ | |
396 | for (OutputColumn output : def.outputs) { | |
397 | fieldsList.add(output.name); | |
398 | } | |
399 | return fieldsList.toArray(new String[0]); | |
400 | } | |
401 | } | |
402 | } | |
403 | } | |
41b5c37f | 404 | curNode = curNode.getParent(); |
be222f56 PT |
405 | } |
406 | ||
407 | fieldsList.add(Messages.FilterViewer_CommonCategory); | |
408 | fieldsList.add(ITmfEvent.EVENT_FIELD_TIMESTAMP); | |
409 | fieldsList.add(ITmfEvent.EVENT_FIELD_SOURCE); | |
410 | fieldsList.add(ITmfEvent.EVENT_FIELD_TYPE); | |
411 | fieldsList.add(ITmfEvent.EVENT_FIELD_REFERENCE); | |
412 | fieldsList.add(ITmfEvent.EVENT_FIELD_CONTENT); | |
413 | fieldsList.add(""); //$NON-NLS-1$ | |
414 | ||
415 | for (IConfigurationElement ce : TmfTraceType.getTypeElements()) { | |
416 | try { | |
417 | ITmfEvent event = (ITmfEvent) ce.createExecutableExtension(TmfTraceType.EVENT_TYPE_ATTR); | |
418 | ITmfEventType eventType = event.getType(); | |
419 | if (eventType != null && eventType.getFieldNames().length > 0) { | |
420 | fieldsList.add("[" + TmfTraceType.getCategoryName(ce.getAttribute(TmfTraceType.CATEGORY_ATTR)) + //$NON-NLS-1$ | |
421 | " : " + ce.getAttribute(TmfTraceType.NAME_ATTR) + "]"); //$NON-NLS-1$ //$NON-NLS-2$ | |
422 | for (String field : eventType.getFieldNames()) { | |
423 | fieldsList.add(field); | |
424 | } | |
425 | fieldsList.add(""); //$NON-NLS-1$ | |
426 | } | |
427 | } catch (CoreException e) { | |
428 | } | |
429 | } | |
430 | for (CustomTxtTraceDefinition def : CustomTxtTraceDefinition.loadAll()) { | |
431 | if (def.outputs.size() > 0) { | |
432 | fieldsList.add("[" + CUSTOM_TXT_CATEGORY + //$NON-NLS-1$ | |
433 | " : " + def.definitionName + "]"); //$NON-NLS-1$ //$NON-NLS-2$ | |
434 | for (OutputColumn output : def.outputs) { | |
435 | fieldsList.add(output.name); | |
436 | } | |
437 | fieldsList.add(""); //$NON-NLS-1$ | |
438 | } | |
439 | } | |
440 | for (CustomXmlTraceDefinition def : CustomXmlTraceDefinition.loadAll()) { | |
441 | if (def.outputs.size() > 0) { | |
442 | fieldsList.add("[" + CUSTOM_XML_CATEGORY + //$NON-NLS-1$ | |
443 | " : " + def.definitionName + "]"); //$NON-NLS-1$ //$NON-NLS-2$ | |
444 | for (OutputColumn output : def.outputs) { | |
445 | fieldsList.add(output.name); | |
446 | } | |
447 | fieldsList.add(""); //$NON-NLS-1$ | |
448 | } | |
449 | } | |
450 | return fieldsList.toArray(new String[0]); | |
451 | } | |
452 | } | |
453 | ||
454 | private class FilterNodeComposite extends FilterBaseNodeComposite { | |
455 | TmfFilterNode fNode; | |
456 | Text fNameText; | |
a0a88f65 | 457 | |
be222f56 PT |
458 | FilterNodeComposite(Composite parent, TmfFilterNode node) { |
459 | super(parent); | |
460 | fNode = node; | |
a0a88f65 | 461 | |
be222f56 PT |
462 | Label label = new Label(this, SWT.NONE); |
463 | label.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE)); | |
464 | label.setText(Messages.FilterViewer_NameLabel); | |
a0a88f65 | 465 | |
be222f56 PT |
466 | fNameText = new Text(this, SWT.BORDER); |
467 | fNameText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); | |
468 | if (node.getFilterName() != null && node.getFilterName().length() > 0) { | |
469 | fNameText.setText(node.getFilterName()); | |
470 | } else { | |
471 | fNameText.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_GRAY)); | |
472 | fNameText.setText(Messages.FilterViewer_FilterNameHint); | |
473 | } | |
474 | fNameText.addFocusListener(new FocusListener() { | |
475 | @Override | |
476 | public void focusLost(FocusEvent e) { | |
477 | if (fNode.getFilterName() == null || fNode.getFilterName().length() == 0) { | |
478 | fNameText.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_GRAY)); | |
479 | fNameText.setText(Messages.FilterViewer_FilterNameHint); | |
480 | } | |
481 | } | |
482 | @Override | |
483 | public void focusGained(FocusEvent e) { | |
484 | if (fNameText.getForeground().equals(Display.getCurrent().getSystemColor(SWT.COLOR_GRAY))) { | |
485 | fNameText.setText(""); //$NON-NLS-1$ | |
486 | } | |
487 | fNameText.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_BLACK)); | |
488 | } | |
489 | }); | |
490 | fNameText.addModifyListener(new ModifyListener() { | |
491 | @Override | |
492 | public void modifyText(ModifyEvent e) { | |
493 | if (! fNameText.getForeground().equals(Display.getCurrent().getSystemColor(SWT.COLOR_GRAY))) { | |
494 | fNode.setFilterName(fNameText.getText()); | |
495 | fViewer.refresh(fNode); | |
496 | } | |
497 | } | |
498 | }); | |
499 | } | |
500 | } | |
501 | ||
502 | private class FilterEventTypeNodeComposite extends FilterBaseNodeComposite { | |
503 | TmfFilterEventTypeNode fNode; | |
504 | Combo fTypeCombo; | |
505 | Map<String, Object> fEventsTypeMap; | |
a0a88f65 | 506 | |
be222f56 PT |
507 | FilterEventTypeNodeComposite(Composite parent, TmfFilterEventTypeNode node) { |
508 | super(parent); | |
509 | fNode = node; | |
510 | fEventsTypeMap = getEventsTypeMap(); | |
511 | ||
512 | Label label = new Label(this, SWT.NONE); | |
513 | label.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE)); | |
514 | label.setText(Messages.FilterViewer_TypeLabel); | |
a0a88f65 | 515 | |
be222f56 PT |
516 | fTypeCombo = new Combo(this, SWT.DROP_DOWN | SWT.READ_ONLY); |
517 | fTypeCombo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); | |
518 | fTypeCombo.setItems(fEventsTypeMap.keySet().toArray(new String[0])); | |
519 | if (fNode.getEventType() != null) { | |
520 | for (Entry <String, Object> eventTypeEntry : fEventsTypeMap.entrySet()) { | |
521 | Object value = eventTypeEntry.getValue(); | |
522 | if (value instanceof IConfigurationElement) { | |
523 | IConfigurationElement ce = (IConfigurationElement) value; | |
524 | if (ce.getAttribute(TmfTraceType.EVENT_TYPE_ATTR).equals(fNode.getEventType())) { | |
525 | fTypeCombo.setText(eventTypeEntry.getKey()); | |
526 | } | |
527 | } else if (value instanceof CustomTxtTraceDefinition) { | |
528 | CustomTxtTraceDefinition def = (CustomTxtTraceDefinition) value; | |
529 | String eventType = CustomTxtEvent.class.getCanonicalName() + ":" + def.definitionName; //$NON-NLS-1$ | |
530 | if (eventType.equals(fNode.getEventType())) { | |
531 | fTypeCombo.setText(eventTypeEntry.getKey()); | |
532 | } | |
533 | } else if (value instanceof CustomXmlTraceDefinition) { | |
534 | CustomXmlTraceDefinition def = (CustomXmlTraceDefinition) value; | |
535 | String eventType = CustomXmlEvent.class.getCanonicalName() + ":" + def.definitionName; //$NON-NLS-1$ | |
536 | if (eventType.equals(fNode.getEventType())) { | |
537 | fTypeCombo.setText(eventTypeEntry.getKey()); | |
538 | } | |
539 | } | |
540 | } | |
541 | } | |
542 | fTypeCombo.addModifyListener(new ModifyListener() { | |
543 | @Override | |
544 | public void modifyText(ModifyEvent e) { | |
545 | for (Entry <String, Object> eventTypeEntry : fEventsTypeMap.entrySet()) { | |
546 | if (eventTypeEntry.getKey().equals(fTypeCombo.getText())) { | |
547 | Object value = eventTypeEntry.getValue(); | |
548 | if (value instanceof IConfigurationElement) { | |
549 | IConfigurationElement ce = (IConfigurationElement) value; | |
550 | fNode.setEventType(ce.getAttribute(TmfTraceType.EVENT_TYPE_ATTR)); | |
551 | fNode.setName(ce.getAttribute(TmfTraceType.NAME_ATTR)); | |
552 | } else if (value instanceof CustomTxtTraceDefinition) { | |
553 | CustomTxtTraceDefinition def = (CustomTxtTraceDefinition) value; | |
554 | fNode.setEventType(CustomTxtEvent.class.getCanonicalName() + ":" + def.definitionName); //$NON-NLS-1$ | |
555 | fNode.setName(def.definitionName); | |
556 | } else if (value instanceof CustomXmlTraceDefinition) { | |
557 | CustomXmlTraceDefinition def = (CustomXmlTraceDefinition) value; | |
558 | fNode.setEventType(CustomXmlEvent.class.getCanonicalName() + ":" + def.definitionName); //$NON-NLS-1$ | |
559 | fNode.setName(def.definitionName); | |
560 | } | |
561 | fViewer.refresh(fNode); | |
562 | break; | |
563 | } | |
564 | } | |
565 | } | |
566 | }); | |
567 | } | |
568 | ||
569 | protected Map<String, Object> getEventsTypeMap() { | |
570 | Map<String, Object> eventsTypeMap = new LinkedHashMap<String, Object>(); | |
571 | for (IConfigurationElement ce : TmfTraceType.getTypeElements()) { | |
572 | String categoryName = TmfTraceType.getCategoryName(ce.getAttribute(TmfTraceType.CATEGORY_ATTR)); | |
573 | String text = categoryName + " : " + ce.getAttribute(TmfTraceType.NAME_ATTR); //$NON-NLS-1$ | |
574 | eventsTypeMap.put(text, ce); | |
575 | } | |
576 | for (CustomTxtTraceDefinition def : CustomTxtTraceDefinition.loadAll()) { | |
577 | String text = CUSTOM_TXT_CATEGORY + " : " + def.definitionName; //$NON-NLS-1$ | |
578 | eventsTypeMap.put(text, def); | |
579 | } | |
580 | for (CustomXmlTraceDefinition def : CustomXmlTraceDefinition.loadAll()) { | |
581 | String text = CUSTOM_XML_CATEGORY + " : " + def.definitionName; //$NON-NLS-1$ | |
582 | eventsTypeMap.put(text, def); | |
583 | } | |
584 | return eventsTypeMap; | |
585 | } | |
586 | } | |
a0a88f65 | 587 | |
be222f56 PT |
588 | private class FilterAndNodeComposite extends FilterBaseNodeComposite { |
589 | TmfFilterAndNode fNode; | |
590 | Button fNotButton; | |
a0a88f65 | 591 | |
be222f56 PT |
592 | FilterAndNodeComposite(Composite parent, TmfFilterAndNode node) { |
593 | super(parent); | |
594 | fNode = node; | |
a0a88f65 | 595 | |
be222f56 PT |
596 | Label label = new Label(this, SWT.NONE); |
597 | label.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE)); | |
598 | label.setText(Messages.FilterViewer_NotLabel); | |
a0a88f65 | 599 | |
be222f56 PT |
600 | fNotButton = new Button(this, SWT.CHECK); |
601 | fNotButton.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE)); | |
602 | fNotButton.setSelection(fNode.isNot()); | |
603 | fNotButton.addSelectionListener(new SelectionAdapter() { | |
604 | @Override | |
605 | public void widgetSelected(SelectionEvent e) { | |
606 | fNode.setNot(fNotButton.getSelection()); | |
607 | fViewer.refresh(fNode); | |
608 | } | |
609 | }); | |
610 | } | |
611 | } | |
612 | ||
613 | private class FilterOrNodeComposite extends FilterBaseNodeComposite { | |
614 | TmfFilterOrNode fNode; | |
615 | Button fNotButton; | |
a0a88f65 | 616 | |
be222f56 PT |
617 | FilterOrNodeComposite(Composite parent, TmfFilterOrNode node) { |
618 | super(parent); | |
619 | fNode = node; | |
a0a88f65 | 620 | |
be222f56 PT |
621 | Label label = new Label(this, SWT.NONE); |
622 | label.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE)); | |
623 | label.setText(Messages.FilterViewer_NotLabel); | |
a0a88f65 | 624 | |
be222f56 PT |
625 | fNotButton = new Button(this, SWT.CHECK); |
626 | fNotButton.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE)); | |
627 | fNotButton.setSelection(fNode.isNot()); | |
628 | fNotButton.addSelectionListener(new SelectionAdapter() { | |
629 | @Override | |
630 | public void widgetSelected(SelectionEvent e) { | |
631 | fNode.setNot(fNotButton.getSelection()); | |
632 | fViewer.refresh(fNode); | |
633 | } | |
634 | }); | |
635 | } | |
636 | } | |
a0a88f65 | 637 | |
be222f56 PT |
638 | private class FilterContainsNodeComposite extends FilterBaseNodeComposite { |
639 | TmfFilterContainsNode fNode; | |
640 | Button fNotButton; | |
641 | Combo fFieldCombo; | |
642 | Text fValueText; | |
643 | Button fIgnoreCaseButton; | |
a0a88f65 | 644 | |
be222f56 PT |
645 | FilterContainsNodeComposite(Composite parent, TmfFilterContainsNode node) { |
646 | super(parent); | |
647 | fNode = node; | |
a0a88f65 | 648 | |
be222f56 PT |
649 | Label label = new Label(this, SWT.NONE); |
650 | label.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE)); | |
651 | label.setText(Messages.FilterViewer_NotLabel); | |
a0a88f65 | 652 | |
be222f56 PT |
653 | fNotButton = new Button(this, SWT.CHECK); |
654 | fNotButton.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE)); | |
655 | fNotButton.setSelection(fNode.isNot()); | |
656 | fNotButton.addSelectionListener(new SelectionAdapter() { | |
657 | @Override | |
658 | public void widgetSelected(SelectionEvent e) { | |
659 | fNode.setNot(fNotButton.getSelection()); | |
660 | fViewer.refresh(fNode); | |
661 | } | |
662 | }); | |
a0a88f65 | 663 | |
be222f56 PT |
664 | label = new Label(this, SWT.NONE); |
665 | label.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE)); | |
666 | label.setText(Messages.FilterViewer_FieldLabel); | |
a0a88f65 | 667 | |
be222f56 PT |
668 | fFieldCombo = new Combo(this, SWT.DROP_DOWN); |
669 | fFieldCombo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); | |
670 | fFieldCombo.setItems(getFieldsList(fNode)); | |
671 | if (fNode.getField() != null) { | |
672 | fFieldCombo.setText(fNode.getField()); | |
673 | } | |
674 | fFieldCombo.addModifyListener(new ModifyListener() { | |
675 | @Override | |
676 | public void modifyText(ModifyEvent e) { | |
677 | fNode.setField(fFieldCombo.getText()); | |
678 | fViewer.refresh(fNode); | |
679 | } | |
680 | }); | |
a0a88f65 | 681 | |
be222f56 PT |
682 | label = new Label(this, SWT.NONE); |
683 | label.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE)); | |
684 | label.setText(Messages.FilterViewer_ValueLabel); | |
a0a88f65 | 685 | |
be222f56 PT |
686 | fValueText = new Text(this, SWT.BORDER); |
687 | fValueText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); | |
688 | if (node.getValue() != null && node.getValue().length() > 0) { | |
689 | fValueText.setText(node.getValue()); | |
690 | } else { | |
691 | fValueText.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_GRAY)); | |
692 | fValueText.setText(Messages.FilterViewer_ValueHint); | |
693 | } | |
694 | fValueText.addFocusListener(new FocusListener() { | |
695 | @Override | |
696 | public void focusLost(FocusEvent e) { | |
697 | if (fNode.getValue() == null || fNode.getValue().length() == 0) { | |
698 | fValueText.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_GRAY)); | |
699 | fValueText.setText(Messages.FilterViewer_ValueHint); | |
700 | } | |
701 | } | |
702 | @Override | |
703 | public void focusGained(FocusEvent e) { | |
704 | if (fValueText.getForeground().equals(Display.getCurrent().getSystemColor(SWT.COLOR_GRAY))) { | |
705 | fValueText.setText(""); //$NON-NLS-1$ | |
706 | } | |
707 | fValueText.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_BLACK)); | |
708 | } | |
709 | }); | |
710 | fValueText.addModifyListener(new ModifyListener() { | |
711 | @Override | |
712 | public void modifyText(ModifyEvent e) { | |
713 | if (! fValueText.getForeground().equals(Display.getCurrent().getSystemColor(SWT.COLOR_GRAY))) { | |
714 | fNode.setValue(fValueText.getText()); | |
715 | fViewer.refresh(fNode); | |
716 | } | |
717 | } | |
718 | }); | |
a0a88f65 | 719 | |
be222f56 PT |
720 | label = new Label(this, SWT.NONE); |
721 | label.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE)); | |
a0a88f65 | 722 | |
be222f56 PT |
723 | fIgnoreCaseButton = new Button(this, SWT.CHECK); |
724 | fIgnoreCaseButton.setSelection(fNode.isIgnoreCase()); | |
725 | fIgnoreCaseButton.setText(Messages.FilterViewer_IgnoreCaseButtonText); | |
726 | fIgnoreCaseButton.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE)); | |
727 | fIgnoreCaseButton.addSelectionListener(new SelectionAdapter() { | |
728 | @Override | |
729 | public void widgetSelected(SelectionEvent e) { | |
730 | fNode.setIgnoreCase(fIgnoreCaseButton.getSelection()); | |
731 | fViewer.refresh(fNode); | |
732 | } | |
733 | }); | |
734 | } | |
735 | } | |
736 | ||
737 | private class FilterEqualsNodeComposite extends FilterBaseNodeComposite { | |
738 | TmfFilterEqualsNode fNode; | |
739 | Button fNotButton; | |
740 | Combo fFieldCombo; | |
741 | Text fValueText; | |
742 | Button fIgnoreCaseButton; | |
a0a88f65 | 743 | |
be222f56 PT |
744 | FilterEqualsNodeComposite(Composite parent, TmfFilterEqualsNode node) { |
745 | super(parent); | |
746 | fNode = node; | |
a0a88f65 | 747 | |
be222f56 PT |
748 | Label label = new Label(this, SWT.NONE); |
749 | label.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE)); | |
750 | label.setText(Messages.FilterViewer_NotLabel); | |
a0a88f65 | 751 | |
be222f56 PT |
752 | fNotButton = new Button(this, SWT.CHECK); |
753 | fNotButton.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE)); | |
754 | fNotButton.setSelection(fNode.isNot()); | |
755 | fNotButton.addSelectionListener(new SelectionAdapter() { | |
756 | @Override | |
757 | public void widgetSelected(SelectionEvent e) { | |
758 | fNode.setNot(fNotButton.getSelection()); | |
759 | fViewer.refresh(fNode); | |
760 | } | |
761 | }); | |
a0a88f65 | 762 | |
be222f56 PT |
763 | label = new Label(this, SWT.NONE); |
764 | label.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE)); | |
765 | label.setText(Messages.FilterViewer_FieldLabel); | |
a0a88f65 | 766 | |
be222f56 PT |
767 | fFieldCombo = new Combo(this, SWT.DROP_DOWN); |
768 | fFieldCombo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); | |
769 | fFieldCombo.setItems(getFieldsList(fNode)); | |
770 | if (fNode.getField() != null) { | |
771 | fFieldCombo.setText(fNode.getField()); | |
772 | } | |
773 | fFieldCombo.addModifyListener(new ModifyListener() { | |
774 | @Override | |
775 | public void modifyText(ModifyEvent e) { | |
776 | fNode.setField(fFieldCombo.getText()); | |
777 | fViewer.refresh(fNode); | |
778 | } | |
779 | }); | |
a0a88f65 | 780 | |
be222f56 PT |
781 | label = new Label(this, SWT.NONE); |
782 | label.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE)); | |
783 | label.setText(Messages.FilterViewer_ValueLabel); | |
a0a88f65 | 784 | |
be222f56 PT |
785 | fValueText = new Text(this, SWT.BORDER); |
786 | fValueText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); | |
787 | if (node.getValue() != null && node.getValue().length() > 0) { | |
788 | fValueText.setText(node.getValue()); | |
789 | } else { | |
790 | fValueText.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_GRAY)); | |
791 | fValueText.setText(Messages.FilterViewer_ValueHint); | |
792 | } | |
793 | fValueText.addFocusListener(new FocusListener() { | |
794 | @Override | |
795 | public void focusLost(FocusEvent e) { | |
796 | if (fNode.getValue() == null || fNode.getValue().length() == 0) { | |
797 | fValueText.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_GRAY)); | |
798 | fValueText.setText(Messages.FilterViewer_ValueHint); | |
799 | } | |
800 | } | |
801 | @Override | |
802 | public void focusGained(FocusEvent e) { | |
803 | if (fValueText.getForeground().equals(Display.getCurrent().getSystemColor(SWT.COLOR_GRAY))) { | |
804 | fValueText.setText(""); //$NON-NLS-1$ | |
805 | } | |
806 | fValueText.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_BLACK)); | |
807 | } | |
808 | }); | |
809 | fValueText.addModifyListener(new ModifyListener() { | |
810 | @Override | |
811 | public void modifyText(ModifyEvent e) { | |
812 | if (! fValueText.getForeground().equals(Display.getCurrent().getSystemColor(SWT.COLOR_GRAY))) { | |
813 | fNode.setValue(fValueText.getText()); | |
814 | fViewer.refresh(fNode); | |
815 | } | |
816 | } | |
817 | }); | |
a0a88f65 | 818 | |
be222f56 PT |
819 | label = new Label(this, SWT.NONE); |
820 | label.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE)); | |
a0a88f65 | 821 | |
be222f56 PT |
822 | fIgnoreCaseButton = new Button(this, SWT.CHECK); |
823 | fIgnoreCaseButton.setSelection(fNode.isIgnoreCase()); | |
824 | fIgnoreCaseButton.setText(Messages.FilterViewer_IgnoreCaseButtonText); | |
825 | fIgnoreCaseButton.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE)); | |
826 | fIgnoreCaseButton.addSelectionListener(new SelectionAdapter() { | |
827 | @Override | |
828 | public void widgetSelected(SelectionEvent e) { | |
829 | fNode.setIgnoreCase(fIgnoreCaseButton.getSelection()); | |
830 | fViewer.refresh(fNode); | |
831 | } | |
832 | }); | |
833 | } | |
834 | } | |
835 | ||
836 | private class FilterMatchesNodeComposite extends FilterBaseNodeComposite { | |
837 | TmfFilterMatchesNode fNode; | |
838 | Button fNotButton; | |
839 | Combo fFieldCombo; | |
840 | Text fRegexText; | |
a0a88f65 | 841 | |
be222f56 PT |
842 | FilterMatchesNodeComposite(Composite parent, TmfFilterMatchesNode node) { |
843 | super(parent); | |
844 | fNode = node; | |
a0a88f65 | 845 | |
be222f56 PT |
846 | Label label = new Label(this, SWT.NONE); |
847 | label.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE)); | |
848 | label.setText(Messages.FilterViewer_NotLabel); | |
a0a88f65 | 849 | |
be222f56 PT |
850 | fNotButton = new Button(this, SWT.CHECK); |
851 | fNotButton.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE)); | |
852 | fNotButton.setSelection(fNode.isNot()); | |
853 | fNotButton.addSelectionListener(new SelectionAdapter() { | |
854 | @Override | |
855 | public void widgetSelected(SelectionEvent e) { | |
856 | fNode.setNot(fNotButton.getSelection()); | |
857 | fViewer.refresh(fNode); | |
858 | } | |
859 | }); | |
a0a88f65 | 860 | |
be222f56 PT |
861 | label = new Label(this, SWT.NONE); |
862 | label.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE)); | |
863 | label.setText(Messages.FilterViewer_FieldLabel); | |
a0a88f65 | 864 | |
be222f56 PT |
865 | fFieldCombo = new Combo(this, SWT.DROP_DOWN); |
866 | fFieldCombo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); | |
867 | fFieldCombo.setItems(getFieldsList(fNode)); | |
868 | if (fNode.getField() != null) { | |
869 | fFieldCombo.setText(fNode.getField()); | |
870 | } | |
871 | fFieldCombo.addModifyListener(new ModifyListener() { | |
872 | @Override | |
873 | public void modifyText(ModifyEvent e) { | |
874 | fNode.setField(fFieldCombo.getText()); | |
875 | fViewer.refresh(fNode); | |
876 | } | |
877 | }); | |
a0a88f65 | 878 | |
be222f56 PT |
879 | label = new Label(this, SWT.NONE); |
880 | label.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE)); | |
881 | label.setText(Messages.FilterViewer_RegexLabel); | |
a0a88f65 | 882 | |
be222f56 PT |
883 | fRegexText = new Text(this, SWT.BORDER); |
884 | fRegexText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); | |
885 | if (node.getRegex() != null && node.getRegex().length() > 0) { | |
886 | fRegexText.setText(node.getRegex()); | |
887 | } else { | |
888 | fRegexText.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_GRAY)); | |
889 | fRegexText.setText(Messages.FilterViewer_RegexHint); | |
890 | } | |
891 | fRegexText.addFocusListener(new FocusListener() { | |
892 | @Override | |
893 | public void focusLost(FocusEvent e) { | |
894 | if (fNode.getRegex() == null || fNode.getRegex().length() == 0) { | |
895 | fRegexText.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_GRAY)); | |
896 | fRegexText.setText(Messages.FilterViewer_RegexHint); | |
897 | } | |
898 | } | |
899 | @Override | |
900 | public void focusGained(FocusEvent e) { | |
901 | if (fRegexText.getForeground().equals(Display.getCurrent().getSystemColor(SWT.COLOR_GRAY))) { | |
902 | fRegexText.setText(""); //$NON-NLS-1$ | |
903 | } | |
904 | fRegexText.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_BLACK)); | |
905 | } | |
906 | }); | |
907 | fRegexText.addModifyListener(new ModifyListener() { | |
908 | @Override | |
909 | public void modifyText(ModifyEvent e) { | |
910 | if (! fRegexText.getForeground().equals(Display.getCurrent().getSystemColor(SWT.COLOR_GRAY))) { | |
911 | fNode.setRegex(fRegexText.getText()); | |
912 | fViewer.refresh(fNode); | |
913 | } | |
914 | } | |
915 | }); | |
916 | } | |
917 | } | |
918 | ||
919 | private class FilterCompareNodeComposite extends FilterBaseNodeComposite { | |
920 | TmfFilterCompareNode fNode; | |
921 | Button fNotButton; | |
922 | Combo fFieldCombo; | |
923 | Text fValueText; | |
924 | Button fLTButton; | |
925 | Button fEQButton; | |
926 | Button fGTButton; | |
927 | Button fNumButton; | |
928 | Button fAlphaButton; | |
929 | Button fTimestampButton; | |
a0a88f65 | 930 | |
be222f56 PT |
931 | FilterCompareNodeComposite(Composite parent, TmfFilterCompareNode node) { |
932 | super(parent); | |
933 | fNode = node; | |
a0a88f65 | 934 | |
be222f56 PT |
935 | Label label = new Label(this, SWT.NONE); |
936 | label.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE)); | |
937 | label.setText(Messages.FilterViewer_NotLabel); | |
a0a88f65 | 938 | |
be222f56 PT |
939 | fNotButton = new Button(this, SWT.CHECK); |
940 | fNotButton.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE)); | |
941 | fNotButton.setSelection(fNode.isNot()); | |
942 | fNotButton.addSelectionListener(new SelectionAdapter() { | |
943 | @Override | |
944 | public void widgetSelected(SelectionEvent e) { | |
945 | fNode.setNot(fNotButton.getSelection()); | |
946 | fViewer.refresh(fNode); | |
947 | } | |
948 | }); | |
a0a88f65 | 949 | |
be222f56 PT |
950 | label = new Label(this, SWT.NONE); |
951 | label.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE)); | |
952 | label.setText(Messages.FilterViewer_FieldLabel); | |
a0a88f65 | 953 | |
be222f56 PT |
954 | fFieldCombo = new Combo(this, SWT.DROP_DOWN); |
955 | fFieldCombo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); | |
956 | fFieldCombo.setItems(getFieldsList(fNode)); | |
957 | if (fNode.getField() != null) { | |
958 | fFieldCombo.setText(fNode.getField()); | |
959 | } | |
960 | fFieldCombo.addModifyListener(new ModifyListener() { | |
961 | @Override | |
962 | public void modifyText(ModifyEvent e) { | |
963 | fNode.setField(fFieldCombo.getText()); | |
964 | fViewer.refresh(fNode); | |
965 | } | |
966 | }); | |
a0a88f65 | 967 | |
be222f56 PT |
968 | label = new Label(this, SWT.NONE); |
969 | label.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE)); | |
970 | label.setText(Messages.FilterViewer_ResultLabel); | |
a0a88f65 | 971 | |
be222f56 PT |
972 | Composite resultGroup = new Composite(this, SWT.NONE); |
973 | GridLayout rggl = new GridLayout(3, true); | |
974 | rggl.marginHeight = 0; | |
975 | rggl.marginWidth = 0; | |
976 | resultGroup.setLayout(rggl); | |
977 | resultGroup.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE)); | |
a0a88f65 | 978 | |
be222f56 PT |
979 | fLTButton = new Button(resultGroup, SWT.RADIO); |
980 | fLTButton.setSelection(fNode.getResult() < 0); | |
981 | fLTButton.setText("<"); //$NON-NLS-1$ | |
982 | fLTButton.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE)); | |
983 | fLTButton.addSelectionListener(new SelectionAdapter() { | |
984 | @Override | |
985 | public void widgetSelected(SelectionEvent e) { | |
986 | if (fLTButton.getSelection()) { | |
987 | fNode.setResult(-1); | |
988 | } | |
989 | fViewer.refresh(fNode); | |
990 | } | |
991 | }); | |
a0a88f65 | 992 | |
be222f56 PT |
993 | fEQButton = new Button(resultGroup, SWT.RADIO); |
994 | fEQButton.setSelection(fNode.getResult() == 0); | |
995 | fEQButton.setText("="); //$NON-NLS-1$ | |
996 | fEQButton.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE)); | |
997 | fEQButton.addSelectionListener(new SelectionAdapter() { | |
998 | @Override | |
999 | public void widgetSelected(SelectionEvent e) { | |
1000 | if (fEQButton.getSelection()) { | |
1001 | fNode.setResult(0); | |
1002 | } | |
1003 | fViewer.refresh(fNode); | |
1004 | } | |
1005 | }); | |
a0a88f65 | 1006 | |
be222f56 PT |
1007 | fGTButton = new Button(resultGroup, SWT.RADIO); |
1008 | fGTButton.setSelection(fNode.getResult() > 0); | |
1009 | fGTButton.setText(">"); //$NON-NLS-1$ | |
1010 | fGTButton.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE)); | |
1011 | fGTButton.addSelectionListener(new SelectionAdapter() { | |
1012 | @Override | |
1013 | public void widgetSelected(SelectionEvent e) { | |
1014 | if (fGTButton.getSelection()) { | |
1015 | fNode.setResult(1); | |
1016 | } | |
1017 | fViewer.refresh(fNode); | |
1018 | } | |
1019 | }); | |
a0a88f65 | 1020 | |
be222f56 PT |
1021 | label = new Label(this, SWT.NONE); |
1022 | label.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE)); | |
1023 | label.setText(Messages.FilterViewer_TypeLabel); | |
a0a88f65 | 1024 | |
be222f56 PT |
1025 | Composite typeGroup = new Composite(this, SWT.NONE); |
1026 | GridLayout tggl = new GridLayout(3, false); | |
1027 | tggl.marginHeight = 0; | |
1028 | tggl.marginWidth = 0; | |
1029 | typeGroup.setLayout(tggl); | |
1030 | typeGroup.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE)); | |
a0a88f65 | 1031 | |
be222f56 PT |
1032 | fNumButton = new Button(typeGroup, SWT.RADIO); |
1033 | fNumButton.setSelection(fNode.getType() == Type.NUM); | |
1034 | fNumButton.setText(Messages.FilterViewer_NumButtonText); | |
1035 | fNumButton.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE)); | |
1036 | fNumButton.addSelectionListener(new SelectionAdapter() { | |
1037 | @Override | |
1038 | public void widgetSelected(SelectionEvent e) { | |
1039 | if (fNumButton.getSelection()) { | |
1040 | fNode.setType(Type.NUM); | |
1041 | } | |
1042 | fViewer.refresh(fNode); | |
1043 | } | |
1044 | }); | |
a0a88f65 | 1045 | |
be222f56 PT |
1046 | fAlphaButton = new Button(typeGroup, SWT.RADIO); |
1047 | fAlphaButton.setSelection(fNode.getType() == Type.ALPHA); | |
1048 | fAlphaButton.setText(Messages.FilterViewer_AlphaButtonText); | |
1049 | fAlphaButton.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE)); | |
1050 | fAlphaButton.addSelectionListener(new SelectionAdapter() { | |
1051 | @Override | |
1052 | public void widgetSelected(SelectionEvent e) { | |
1053 | if (fAlphaButton.getSelection()) { | |
1054 | fNode.setType(Type.ALPHA); | |
1055 | } | |
1056 | fViewer.refresh(fNode); | |
1057 | } | |
1058 | }); | |
a0a88f65 | 1059 | |
be222f56 PT |
1060 | fTimestampButton = new Button(typeGroup, SWT.RADIO); |
1061 | fTimestampButton.setSelection(fNode.getType() == Type.TIMESTAMP); | |
1062 | fTimestampButton.setText(Messages.FilterViewer_TimestampButtonText); | |
1063 | fTimestampButton.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE)); | |
1064 | fTimestampButton.addSelectionListener(new SelectionAdapter() { | |
1065 | @Override | |
1066 | public void widgetSelected(SelectionEvent e) { | |
1067 | if (fTimestampButton.getSelection()) { | |
1068 | fNode.setType(Type.TIMESTAMP); | |
1069 | } | |
1070 | fViewer.refresh(fNode); | |
1071 | } | |
1072 | }); | |
a0a88f65 | 1073 | |
be222f56 PT |
1074 | label = new Label(this, SWT.NONE); |
1075 | label.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE)); | |
1076 | label.setText(Messages.FilterViewer_ValueLabel); | |
a0a88f65 | 1077 | |
be222f56 PT |
1078 | fValueText = new Text(this, SWT.BORDER); |
1079 | fValueText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); | |
1080 | if (node.getValue() != null && node.getValue().length() > 0) { | |
1081 | fValueText.setText(node.getValue()); | |
1082 | } else { | |
1083 | fValueText.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_GRAY)); | |
1084 | fValueText.setText(Messages.FilterViewer_ValueHint); | |
1085 | } | |
1086 | fValueText.addFocusListener(new FocusListener() { | |
1087 | @Override | |
1088 | public void focusLost(FocusEvent e) { | |
1089 | if (fNode.getValue() == null || fNode.getValue().length() == 0) { | |
1090 | fValueText.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_GRAY)); | |
1091 | fValueText.setText(Messages.FilterViewer_ValueHint); | |
1092 | } | |
1093 | } | |
1094 | @Override | |
1095 | public void focusGained(FocusEvent e) { | |
1096 | if (fValueText.getForeground().equals(Display.getCurrent().getSystemColor(SWT.COLOR_GRAY))) { | |
1097 | fValueText.setText(""); //$NON-NLS-1$ | |
1098 | } | |
1099 | fValueText.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_BLACK)); | |
1100 | } | |
1101 | }); | |
1102 | fValueText.addModifyListener(new ModifyListener() { | |
1103 | @Override | |
1104 | public void modifyText(ModifyEvent e) { | |
1105 | if (! fValueText.getForeground().equals(Display.getCurrent().getSystemColor(SWT.COLOR_GRAY))) { | |
1106 | fNode.setValue(fValueText.getText()); | |
1107 | fViewer.refresh(fNode); | |
1108 | } | |
1109 | } | |
1110 | }); | |
1111 | } | |
1112 | } | |
1113 | ||
1114 | } |