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