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