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