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