1 /*******************************************************************************
2 * Copyright (c) 2010, 2015 Ericsson
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
10 * Patrick Tasse - Initial API and implementation
11 * Xavier Raynaud - add cut/copy/paste/dnd support
12 * Vincent Perot - Add subfield filtering
13 *******************************************************************************/
15 package org
.eclipse
.tracecompass
.tmf
.ui
.views
.filter
;
17 import java
.util
.ArrayList
;
19 import java
.util
.Map
.Entry
;
20 import java
.util
.TreeMap
;
22 import org
.eclipse
.core
.runtime
.CoreException
;
23 import org
.eclipse
.core
.runtime
.IConfigurationElement
;
24 import org
.eclipse
.jface
.action
.Action
;
25 import org
.eclipse
.jface
.action
.IMenuListener
;
26 import org
.eclipse
.jface
.action
.IMenuManager
;
27 import org
.eclipse
.jface
.action
.MenuManager
;
28 import org
.eclipse
.jface
.action
.Separator
;
29 import org
.eclipse
.jface
.util
.LocalSelectionTransfer
;
30 import org
.eclipse
.jface
.viewers
.ISelection
;
31 import org
.eclipse
.jface
.viewers
.ISelectionChangedListener
;
32 import org
.eclipse
.jface
.viewers
.IStructuredSelection
;
33 import org
.eclipse
.jface
.viewers
.SelectionChangedEvent
;
34 import org
.eclipse
.jface
.viewers
.StructuredSelection
;
35 import org
.eclipse
.jface
.viewers
.TreeViewer
;
36 import org
.eclipse
.swt
.SWT
;
37 import org
.eclipse
.swt
.custom
.SashForm
;
38 import org
.eclipse
.swt
.dnd
.DND
;
39 import org
.eclipse
.swt
.dnd
.DragSource
;
40 import org
.eclipse
.swt
.dnd
.DropTarget
;
41 import org
.eclipse
.swt
.dnd
.Transfer
;
42 import org
.eclipse
.swt
.events
.FocusEvent
;
43 import org
.eclipse
.swt
.events
.FocusListener
;
44 import org
.eclipse
.swt
.events
.ModifyEvent
;
45 import org
.eclipse
.swt
.events
.ModifyListener
;
46 import org
.eclipse
.swt
.events
.PaintEvent
;
47 import org
.eclipse
.swt
.events
.PaintListener
;
48 import org
.eclipse
.swt
.events
.SelectionAdapter
;
49 import org
.eclipse
.swt
.events
.SelectionEvent
;
50 import org
.eclipse
.swt
.layout
.FillLayout
;
51 import org
.eclipse
.swt
.layout
.GridData
;
52 import org
.eclipse
.swt
.layout
.GridLayout
;
53 import org
.eclipse
.swt
.widgets
.Button
;
54 import org
.eclipse
.swt
.widgets
.Combo
;
55 import org
.eclipse
.swt
.widgets
.Composite
;
56 import org
.eclipse
.swt
.widgets
.Control
;
57 import org
.eclipse
.swt
.widgets
.Display
;
58 import org
.eclipse
.swt
.widgets
.Label
;
59 import org
.eclipse
.swt
.widgets
.Menu
;
60 import org
.eclipse
.swt
.widgets
.Text
;
61 import org
.eclipse
.swt
.widgets
.TreeItem
;
62 import org
.eclipse
.tracecompass
.internal
.tmf
.ui
.Messages
;
63 import org
.eclipse
.tracecompass
.tmf
.core
.event
.ITmfEvent
;
64 import org
.eclipse
.tracecompass
.tmf
.core
.event
.ITmfEventType
;
65 import org
.eclipse
.tracecompass
.tmf
.core
.filter
.model
.ITmfFilterTreeNode
;
66 import org
.eclipse
.tracecompass
.tmf
.core
.filter
.model
.TmfFilterAndNode
;
67 import org
.eclipse
.tracecompass
.tmf
.core
.filter
.model
.TmfFilterCompareNode
;
68 import org
.eclipse
.tracecompass
.tmf
.core
.filter
.model
.TmfFilterCompareNode
.Type
;
69 import org
.eclipse
.tracecompass
.tmf
.core
.filter
.model
.TmfFilterContainsNode
;
70 import org
.eclipse
.tracecompass
.tmf
.core
.filter
.model
.TmfFilterEqualsNode
;
71 import org
.eclipse
.tracecompass
.tmf
.core
.filter
.model
.TmfFilterMatchesFieldNode
;
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
;
75 import org
.eclipse
.tracecompass
.tmf
.core
.filter
.model
.TmfFilterTraceTypeNode
;
76 import org
.eclipse
.tracecompass
.tmf
.core
.filter
.model
.TmfFilterTreeNode
;
77 import org
.eclipse
.tracecompass
.tmf
.core
.parsers
.custom
.CustomTraceDefinition
;
78 import org
.eclipse
.tracecompass
.tmf
.core
.parsers
.custom
.CustomTraceDefinition
.OutputColumn
;
79 import org
.eclipse
.tracecompass
.tmf
.core
.parsers
.custom
.CustomTxtTraceDefinition
;
80 import org
.eclipse
.tracecompass
.tmf
.core
.parsers
.custom
.CustomXmlTraceDefinition
;
81 import org
.eclipse
.tracecompass
.tmf
.core
.project
.model
.TmfTraceType
;
82 import org
.eclipse
.tracecompass
.tmf
.core
.project
.model
.TraceTypeHelper
;
84 class FilterViewer
extends Composite
{
86 private static final String SEP
= " : "; //$NON-NLS-1$
88 private TreeViewer fViewer
;
90 private Composite fComposite
;
91 private MenuManager fMenuManager
;
93 public FilterViewer(Composite parent
, int style
) {
96 setLayout(new FillLayout());
97 GridData gd
= new GridData(SWT
.FILL
, SWT
.FILL
, true, true);
100 final SashForm sash
= new SashForm(this, SWT
.HORIZONTAL
);
102 // Create the tree viewer to display the filter tree
103 fViewer
= new TreeViewer(sash
, SWT
.NONE
);
104 fViewer
.setContentProvider(new FilterTreeContentProvider());
105 fViewer
.setLabelProvider(new FilterTreeLabelProvider());
106 fViewer
.setInput(new TmfFilterRootNode());
108 // Create the empty filter node properties panel
109 fComposite
= new Composite(sash
, SWT
.NONE
);
110 GridLayout gl
= new GridLayout();
113 fComposite
.setLayout(gl
);
117 fViewer
.addSelectionChangedListener(new ISelectionChangedListener() {
119 public void selectionChanged(SelectionChangedEvent event
) {
120 if (!(event
.getSelection().isEmpty()) && event
.getSelection() instanceof IStructuredSelection
) {
121 // Update the filter node properties panel to the selection
122 IStructuredSelection selection
= (IStructuredSelection
) event
.getSelection();
123 ITmfFilterTreeNode node
= (ITmfFilterTreeNode
) selection
.getFirstElement();
124 updateFilterNodeComposite(node
);
125 // Highlight the selection's children
126 highlightTreeItems(fViewer
.getTree().getSelection()[0].getItems());
128 updateFilterNodeComposite(null);
133 fViewer
.getTree().addPaintListener(new PaintListener() {
135 public void paintControl(PaintEvent e
) {
136 TmfFilterTreeNode root
= (TmfFilterTreeNode
) fViewer
.getInput();
137 if (root
== null || root
.getChildrenCount() == 0) {
138 e
.gc
.setForeground(Display
.getDefault().getSystemColor(SWT
.COLOR_BLACK
));
139 e
.gc
.drawText(Messages
.FilterViewer_EmptyTreeHintText
, 5, 0);
144 int operations
= DND
.DROP_MOVE
| DND
.DROP_COPY
;
145 DragSource dragSource
= new org
.eclipse
.swt
.dnd
.DragSource(fViewer
.getTree(), operations
);
146 dragSource
.setTransfer(new Transfer
[] { LocalSelectionTransfer
.getTransfer() });
147 dragSource
.addDragListener(new FilterDragSourceAdapter(this));
148 DropTarget dropTarget
= new DropTarget(fViewer
.getTree(), operations
);
149 dropTarget
.setTransfer(new Transfer
[] { LocalSelectionTransfer
.getTransfer() });
150 dropTarget
.addDropListener(new FilterDropTargetAdapter(this));
154 * Create the context menu for the tree viewer
156 private void createContextMenu() {
157 // Adds root context menu
158 fMenuManager
= new MenuManager();
159 fMenuManager
.setRemoveAllWhenShown(true);
160 fMenuManager
.addMenuListener(new IMenuListener() {
162 public void menuAboutToShow(IMenuManager manager
) {
163 fillContextMenu(manager
);
168 Menu contextMenu
= fMenuManager
.createContextMenu(fViewer
.getTree());
171 fViewer
.getTree().setMenu(contextMenu
);
174 public MenuManager
getMenuManager() {
179 * Fill the context menu for the tree viewer.
184 protected void fillContextMenu(IMenuManager manager
) {
185 final ISelection selection
= fViewer
.getSelection();
186 ITmfFilterTreeNode filterTreeNode
= null;
187 if (selection
instanceof StructuredSelection
) {
188 Object element
= ((StructuredSelection
) selection
).getFirstElement();
189 if (element
instanceof ITmfFilterTreeNode
) {
190 filterTreeNode
= (ITmfFilterTreeNode
) element
;
194 if (filterTreeNode
!= null) {
195 fillContextMenuForNode(filterTreeNode
, manager
);
197 manager
.add(new Separator("delete")); //$NON-NLS-1$
198 manager
.add(new Separator("edit")); //$NON-NLS-1$
200 if (fViewer
.getInput() instanceof TmfFilterRootNode
|| filterTreeNode
== null) {
201 manager
.add(new Separator());
202 ITmfFilterTreeNode root
= (ITmfFilterTreeNode
) fViewer
.getInput();
203 fillContextMenuForNode(root
, manager
);
208 * Fill the context menu with the valid children of the provided node
215 protected void fillContextMenuForNode(final ITmfFilterTreeNode node
, IMenuManager manager
) {
216 for (final String child
: node
.getValidChildren()) {
217 final Action action
= new Action() {
220 ITmfFilterTreeNode newNode
= null;
221 if (TmfFilterNode
.NODE_NAME
.equals(child
)) {
222 newNode
= new TmfFilterNode(node
, ""); //$NON-NLS-1$
223 } else if (TmfFilterTraceTypeNode
.NODE_NAME
.equals(child
)) {
224 newNode
= new TmfFilterTraceTypeNode(node
);
225 } else if (TmfFilterAndNode
.NODE_NAME
.equals(child
)) {
226 newNode
= new TmfFilterAndNode(node
);
227 } else if (TmfFilterOrNode
.NODE_NAME
.equals(child
)) {
228 newNode
= new TmfFilterOrNode(node
);
229 } else if (TmfFilterContainsNode
.NODE_NAME
.equals(child
)) {
230 newNode
= new TmfFilterContainsNode(node
);
231 } else if (TmfFilterEqualsNode
.NODE_NAME
.equals(child
)) {
232 newNode
= new TmfFilterEqualsNode(node
);
233 } else if (TmfFilterMatchesFieldNode
.NODE_NAME
.equals(child
)) {
234 newNode
= new TmfFilterMatchesFieldNode(node
);
235 } else if (TmfFilterCompareNode
.NODE_NAME
.equals(child
)) {
236 newNode
= new TmfFilterCompareNode(node
);
238 if (newNode
!= null) {
240 fViewer
.setSelection(new StructuredSelection(newNode
), true);
244 if (TmfFilterNode
.NODE_NAME
.equals(child
)) {
245 action
.setText(Messages
.FilterViewer_NewPrefix
+ " " + child
); //$NON-NLS-1$
247 action
.setText(child
);
254 * Create the appropriate filter node properties composite
256 private void updateFilterNodeComposite(ITmfFilterTreeNode node
) {
257 for (Control control
: fComposite
.getChildren()) {
261 if (node
instanceof TmfFilterNode
) {
262 new FilterNodeComposite(fComposite
, (TmfFilterNode
) node
);
263 } else if (node
instanceof TmfFilterTraceTypeNode
) {
264 new FilterTraceTypeNodeComposite(fComposite
, (TmfFilterTraceTypeNode
) node
);
265 } else if (node
instanceof TmfFilterAndNode
) {
266 new FilterAndNodeComposite(fComposite
, (TmfFilterAndNode
) node
);
267 } else if (node
instanceof TmfFilterOrNode
) {
268 new FilterOrNodeComposite(fComposite
, (TmfFilterOrNode
) node
);
269 } else if (node
instanceof TmfFilterContainsNode
) {
270 new FilterContainsNodeComposite(fComposite
, (TmfFilterContainsNode
) node
);
271 } else if (node
instanceof TmfFilterEqualsNode
) {
272 new FilterEqualsNodeComposite(fComposite
, (TmfFilterEqualsNode
) node
);
273 } else if (node
instanceof TmfFilterMatchesFieldNode
) {
274 new FilterMatchesNodeComposite(fComposite
, (TmfFilterMatchesFieldNode
) node
);
275 } else if (node
instanceof TmfFilterCompareNode
) {
276 new FilterCompareNodeComposite(fComposite
, (TmfFilterCompareNode
) node
);
278 new FilterBaseNodeComposite(fComposite
);
284 * Highlight the provided tree items
286 private void highlightTreeItems(TreeItem
[] items
) {
287 resetTreeItems(fViewer
.getTree().getItems());
288 for (TreeItem item
: items
) {
289 item
.setForeground(Display
.getCurrent().getSystemColor(SWT
.COLOR_BLUE
));
295 * Reset the provided tree items (remove highlight)
297 private void resetTreeItems(TreeItem
[] items
) {
298 for (TreeItem item
: items
) {
299 item
.setForeground(Display
.getCurrent().getSystemColor(SWT
.COLOR_BLACK
));
300 resetTreeItems(item
.getItems());
304 public void setInput(ITmfFilterTreeNode root
) {
305 fViewer
.setInput(root
);
308 updateFilterNodeComposite(null);
311 public ITmfFilterTreeNode
getInput() {
312 return (ITmfFilterTreeNode
) fViewer
.getInput();
315 public void refresh() {
319 public void setSelection(ITmfFilterTreeNode node
, boolean reveal
) {
320 fViewer
.setSelection(new StructuredSelection(node
), reveal
);
323 public void setSelection(ITmfFilterTreeNode node
) {
324 fViewer
.setSelection(new StructuredSelection(node
));
327 public ITmfFilterTreeNode
getSelection() {
328 final ISelection selection
= fViewer
.getSelection();
329 ITmfFilterTreeNode filterTreeNode
= null;
330 if (selection
instanceof StructuredSelection
) {
331 Object element
= ((StructuredSelection
) selection
).getFirstElement();
332 if (element
instanceof ITmfFilterTreeNode
) {
333 filterTreeNode
= (ITmfFilterTreeNode
) element
;
337 final ITmfFilterTreeNode selectedNode
= filterTreeNode
;
341 public void addSelectionChangedListener(ISelectionChangedListener listener
) {
342 fViewer
.addSelectionChangedListener(listener
);
345 public void removeSelectionChangedListener(ISelectionChangedListener listener
) {
346 fViewer
.removeSelectionChangedListener(listener
);
350 * Gets the TreeViewer displaying filters
352 * @return a {@link TreeViewer}
354 TreeViewer
getTreeViewer() {
358 private class FilterBaseNodeComposite
extends Composite
{
360 FilterBaseNodeComposite(Composite parent
) {
361 super(parent
, SWT
.NONE
);
362 setLayout(new GridLayout(2, false));
363 setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
364 setBackground(Display
.getCurrent().getSystemColor(SWT
.COLOR_WHITE
));
367 protected Map
<String
, Object
> getEventsTypeMap() {
368 Map
<String
, Object
> eventsTypeMap
= new TreeMap
<>();
369 for (IConfigurationElement ce
: TmfTraceType
.getTypeElements()) {
370 String categoryPrefix
= ""; //$NON-NLS-1$
371 String categoryId
= ce
.getAttribute(TmfTraceType
.CATEGORY_ATTR
);
372 if (categoryId
!= null) {
373 categoryPrefix
= TmfTraceType
.getCategoryName(categoryId
) + SEP
;
375 String text
= categoryPrefix
+ ce
.getAttribute(TmfTraceType
.NAME_ATTR
);
376 eventsTypeMap
.put(text
, ce
);
378 for (CustomTxtTraceDefinition def
: CustomTxtTraceDefinition
.loadAll()) {
379 String text
= def
.categoryName
+ SEP
+ def
.definitionName
;
380 eventsTypeMap
.put(text
, def
);
382 for (CustomXmlTraceDefinition def
: CustomXmlTraceDefinition
.loadAll()) {
383 String text
= def
.categoryName
+ SEP
+ def
.definitionName
;
384 eventsTypeMap
.put(text
, def
);
386 return eventsTypeMap
;
389 protected Map
<String
, TraceTypeHelper
> getTraceTypeMap() {
390 Map
<String
, TraceTypeHelper
> traceTypeMap
= new TreeMap
<>();
391 for (TraceTypeHelper helper
: TmfTraceType
.getTraceTypeHelpers()) {
392 String text
= helper
.getCategoryName() + SEP
+ helper
.getName();
393 traceTypeMap
.put(text
, helper
);
398 protected String
[] getFieldsList() {
399 ArrayList
<String
> fieldsList
= new ArrayList
<>();
400 fieldsList
.add(Messages
.FilterViewer_CommonCategory
);
401 fieldsList
.add(ITmfEvent
.EVENT_FIELD_TIMESTAMP
);
402 fieldsList
.add(ITmfEvent
.EVENT_FIELD_SOURCE
);
403 fieldsList
.add(ITmfEvent
.EVENT_FIELD_TYPE
);
404 fieldsList
.add(ITmfEvent
.EVENT_FIELD_REFERENCE
);
405 fieldsList
.add(ITmfEvent
.EVENT_FIELD_CONTENT
);
406 fieldsList
.add(""); //$NON-NLS-1$
408 for (Entry
<String
, Object
> eventTypeEntry
: getEventsTypeMap().entrySet()) {
409 Object value
= eventTypeEntry
.getValue();
410 if (value
instanceof IConfigurationElement
) {
411 IConfigurationElement ce
= (IConfigurationElement
) value
;
413 ITmfEvent event
= (ITmfEvent
) ce
.createExecutableExtension(TmfTraceType
.EVENT_TYPE_ATTR
);
414 ITmfEventType eventType
= event
.getType();
415 if (eventType
!= null && eventType
.getFieldNames().size() > 0) {
416 String categoryId
= ce
.getAttribute(TmfTraceType
.CATEGORY_ATTR
);
417 if (categoryId
!= null) {
418 fieldsList
.add('[' + TmfTraceType
.getCategoryName(categoryId
) + SEP
419 + ce
.getAttribute(TmfTraceType
.NAME_ATTR
) + ']');
421 fieldsList
.add('[' + ce
.getAttribute(TmfTraceType
.NAME_ATTR
) + ']');
423 for (String field
: eventType
.getFieldNames()) {
424 fieldsList
.add(field
);
426 fieldsList
.add(""); //$NON-NLS-1$
428 } catch (CoreException e
) {
430 } else if (value
instanceof CustomTraceDefinition
) {
431 CustomTraceDefinition def
= (CustomTraceDefinition
) value
;
432 if (def
.outputs
.size() > 0) {
433 fieldsList
.add('[' + def
.categoryName
+ SEP
+ def
.definitionName
+ ']');
434 for (OutputColumn output
: def
.outputs
) {
435 fieldsList
.add(output
.name
);
437 fieldsList
.add(""); //$NON-NLS-1$
441 return fieldsList
.toArray(new String
[0]);
445 private class FilterNodeComposite
extends FilterBaseNodeComposite
{
449 FilterNodeComposite(Composite parent
, TmfFilterNode node
) {
453 Label label
= new Label(this, SWT
.NONE
);
454 label
.setBackground(Display
.getCurrent().getSystemColor(SWT
.COLOR_WHITE
));
455 label
.setText(Messages
.FilterViewer_NameLabel
);
457 fNameText
= new Text(this, SWT
.BORDER
);
458 fNameText
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
459 if (node
.getFilterName() != null && node
.getFilterName().length() > 0) {
460 fNameText
.setText(node
.getFilterName());
462 fNameText
.setForeground(Display
.getCurrent().getSystemColor(SWT
.COLOR_GRAY
));
463 fNameText
.setText(Messages
.FilterViewer_FilterNameHint
);
465 fNameText
.addFocusListener(new FocusListener() {
467 public void focusLost(FocusEvent e
) {
468 if (fNode
.getFilterName() == null || fNode
.getFilterName().length() == 0) {
469 fNameText
.setForeground(Display
.getCurrent().getSystemColor(SWT
.COLOR_GRAY
));
470 fNameText
.setText(Messages
.FilterViewer_FilterNameHint
);
475 public void focusGained(FocusEvent e
) {
476 if (fNameText
.getForeground().equals(Display
.getCurrent().getSystemColor(SWT
.COLOR_GRAY
))) {
477 fNameText
.setText(""); //$NON-NLS-1$
479 fNameText
.setForeground(Display
.getCurrent().getSystemColor(SWT
.COLOR_BLACK
));
482 fNameText
.addModifyListener(new ModifyListener() {
484 public void modifyText(ModifyEvent e
) {
485 if (!fNameText
.getForeground().equals(Display
.getCurrent().getSystemColor(SWT
.COLOR_GRAY
))) {
486 fNode
.setFilterName(fNameText
.getText());
487 fViewer
.refresh(fNode
);
494 private class FilterTraceTypeNodeComposite
extends FilterBaseNodeComposite
{
495 TmfFilterTraceTypeNode fNode
;
497 Map
<String
, TraceTypeHelper
> fTraceTypeMap
;
499 FilterTraceTypeNodeComposite(Composite parent
, TmfFilterTraceTypeNode node
) {
502 fTraceTypeMap
= getTraceTypeMap();
504 Label label
= new Label(this, SWT
.NONE
);
505 label
.setBackground(Display
.getCurrent().getSystemColor(SWT
.COLOR_WHITE
));
506 label
.setText(Messages
.FilterViewer_TypeLabel
);
508 fTypeCombo
= new Combo(this, SWT
.DROP_DOWN
| SWT
.READ_ONLY
);
509 fTypeCombo
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
510 fTypeCombo
.setItems(fTraceTypeMap
.keySet().toArray(new String
[0]));
511 if (fNode
.getTraceTypeId() != null) {
512 fTypeCombo
.setText(fNode
.getName());
514 fTypeCombo
.addModifyListener(new ModifyListener() {
516 public void modifyText(ModifyEvent e
) {
517 TraceTypeHelper helper
= fTraceTypeMap
.get(fTypeCombo
.getText());
518 fNode
.setTraceTypeId(helper
.getTraceTypeId());
519 fNode
.setTraceClass(helper
.getTraceClass());
520 fNode
.setName(fTypeCombo
.getText());
521 fViewer
.refresh(fNode
);
527 private class FilterAndNodeComposite
extends FilterBaseNodeComposite
{
528 TmfFilterAndNode fNode
;
531 FilterAndNodeComposite(Composite parent
, TmfFilterAndNode node
) {
535 Label label
= new Label(this, SWT
.NONE
);
536 label
.setBackground(Display
.getCurrent().getSystemColor(SWT
.COLOR_WHITE
));
537 label
.setText(Messages
.FilterViewer_NotLabel
);
539 fNotButton
= new Button(this, SWT
.CHECK
);
540 fNotButton
.setBackground(Display
.getCurrent().getSystemColor(SWT
.COLOR_WHITE
));
541 fNotButton
.setSelection(fNode
.isNot());
542 fNotButton
.addSelectionListener(new SelectionAdapter() {
544 public void widgetSelected(SelectionEvent e
) {
545 fNode
.setNot(fNotButton
.getSelection());
546 fViewer
.refresh(fNode
);
552 private class FilterOrNodeComposite
extends FilterBaseNodeComposite
{
553 TmfFilterOrNode fNode
;
556 FilterOrNodeComposite(Composite parent
, TmfFilterOrNode node
) {
560 Label label
= new Label(this, SWT
.NONE
);
561 label
.setBackground(Display
.getCurrent().getSystemColor(SWT
.COLOR_WHITE
));
562 label
.setText(Messages
.FilterViewer_NotLabel
);
564 fNotButton
= new Button(this, SWT
.CHECK
);
565 fNotButton
.setBackground(Display
.getCurrent().getSystemColor(SWT
.COLOR_WHITE
));
566 fNotButton
.setSelection(fNode
.isNot());
567 fNotButton
.addSelectionListener(new SelectionAdapter() {
569 public void widgetSelected(SelectionEvent e
) {
570 fNode
.setNot(fNotButton
.getSelection());
571 fViewer
.refresh(fNode
);
577 private class FilterContainsNodeComposite
extends FilterBaseNodeComposite
{
578 TmfFilterContainsNode fNode
;
582 Button fIgnoreCaseButton
;
584 FilterContainsNodeComposite(Composite parent
, TmfFilterContainsNode node
) {
588 Label label
= new Label(this, SWT
.NONE
);
589 label
.setBackground(Display
.getCurrent().getSystemColor(SWT
.COLOR_WHITE
));
590 label
.setText(Messages
.FilterViewer_NotLabel
);
592 fNotButton
= new Button(this, SWT
.CHECK
);
593 fNotButton
.setBackground(Display
.getCurrent().getSystemColor(SWT
.COLOR_WHITE
));
594 fNotButton
.setSelection(fNode
.isNot());
595 fNotButton
.addSelectionListener(new SelectionAdapter() {
597 public void widgetSelected(SelectionEvent e
) {
598 fNode
.setNot(fNotButton
.getSelection());
599 fViewer
.refresh(fNode
);
603 label
= new Label(this, SWT
.NONE
);
604 label
.setBackground(Display
.getCurrent().getSystemColor(SWT
.COLOR_WHITE
));
605 label
.setText(Messages
.FilterViewer_FieldLabel
);
607 fFieldCombo
= new Combo(this, SWT
.DROP_DOWN
);
608 fFieldCombo
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
609 fFieldCombo
.setItems(getFieldsList());
610 fFieldCombo
.setToolTipText(Messages
.FilterViewer_Subfilter_ToolTip
);
611 if (fNode
.getField() != null) {
612 fFieldCombo
.setText(fNode
.getField());
614 fFieldCombo
.addModifyListener(new ModifyListener() {
616 public void modifyText(ModifyEvent e
) {
617 fNode
.setField(fFieldCombo
.getText());
618 fViewer
.refresh(fNode
);
622 label
= new Label(this, SWT
.NONE
);
623 label
.setBackground(Display
.getCurrent().getSystemColor(SWT
.COLOR_WHITE
));
624 label
.setText(Messages
.FilterViewer_ValueLabel
);
626 fValueText
= new Text(this, SWT
.BORDER
);
627 fValueText
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
628 if (node
.getValue() != null && node
.getValue().length() > 0) {
629 fValueText
.setText(node
.getValue());
631 fValueText
.setForeground(Display
.getCurrent().getSystemColor(SWT
.COLOR_GRAY
));
632 fValueText
.setText(Messages
.FilterViewer_ValueHint
);
634 fValueText
.addFocusListener(new FocusListener() {
636 public void focusLost(FocusEvent e
) {
637 if (fNode
.getValue() == null || fNode
.getValue().length() == 0) {
638 fValueText
.setForeground(Display
.getCurrent().getSystemColor(SWT
.COLOR_GRAY
));
639 fValueText
.setText(Messages
.FilterViewer_ValueHint
);
644 public void focusGained(FocusEvent e
) {
645 if (fValueText
.getForeground().equals(Display
.getCurrent().getSystemColor(SWT
.COLOR_GRAY
))) {
646 fValueText
.setText(""); //$NON-NLS-1$
648 fValueText
.setForeground(Display
.getCurrent().getSystemColor(SWT
.COLOR_BLACK
));
651 fValueText
.addModifyListener(new ModifyListener() {
653 public void modifyText(ModifyEvent e
) {
654 if (!fValueText
.getForeground().equals(Display
.getCurrent().getSystemColor(SWT
.COLOR_GRAY
))) {
655 fNode
.setValue(fValueText
.getText());
656 fViewer
.refresh(fNode
);
661 label
= new Label(this, SWT
.NONE
);
662 label
.setBackground(Display
.getCurrent().getSystemColor(SWT
.COLOR_WHITE
));
664 fIgnoreCaseButton
= new Button(this, SWT
.CHECK
);
665 fIgnoreCaseButton
.setSelection(fNode
.isIgnoreCase());
666 fIgnoreCaseButton
.setText(Messages
.FilterViewer_IgnoreCaseButtonText
);
667 fIgnoreCaseButton
.setBackground(Display
.getCurrent().getSystemColor(SWT
.COLOR_WHITE
));
668 fIgnoreCaseButton
.addSelectionListener(new SelectionAdapter() {
670 public void widgetSelected(SelectionEvent e
) {
671 fNode
.setIgnoreCase(fIgnoreCaseButton
.getSelection());
672 fViewer
.refresh(fNode
);
678 private class FilterEqualsNodeComposite
extends FilterBaseNodeComposite
{
679 TmfFilterEqualsNode fNode
;
683 Button fIgnoreCaseButton
;
685 FilterEqualsNodeComposite(Composite parent
, TmfFilterEqualsNode node
) {
689 Label label
= new Label(this, SWT
.NONE
);
690 label
.setBackground(Display
.getCurrent().getSystemColor(SWT
.COLOR_WHITE
));
691 label
.setText(Messages
.FilterViewer_NotLabel
);
693 fNotButton
= new Button(this, SWT
.CHECK
);
694 fNotButton
.setBackground(Display
.getCurrent().getSystemColor(SWT
.COLOR_WHITE
));
695 fNotButton
.setSelection(fNode
.isNot());
696 fNotButton
.addSelectionListener(new SelectionAdapter() {
698 public void widgetSelected(SelectionEvent e
) {
699 fNode
.setNot(fNotButton
.getSelection());
700 fViewer
.refresh(fNode
);
704 label
= new Label(this, SWT
.NONE
);
705 label
.setBackground(Display
.getCurrent().getSystemColor(SWT
.COLOR_WHITE
));
706 label
.setText(Messages
.FilterViewer_FieldLabel
);
708 fFieldCombo
= new Combo(this, SWT
.DROP_DOWN
);
709 fFieldCombo
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
710 fFieldCombo
.setItems(getFieldsList());
711 fFieldCombo
.setToolTipText(Messages
.FilterViewer_Subfilter_ToolTip
);
712 if (fNode
.getField() != null) {
713 fFieldCombo
.setText(fNode
.getField());
715 fFieldCombo
.addModifyListener(new ModifyListener() {
717 public void modifyText(ModifyEvent e
) {
718 fNode
.setField(fFieldCombo
.getText());
719 fViewer
.refresh(fNode
);
723 label
= new Label(this, SWT
.NONE
);
724 label
.setBackground(Display
.getCurrent().getSystemColor(SWT
.COLOR_WHITE
));
725 label
.setText(Messages
.FilterViewer_ValueLabel
);
727 fValueText
= new Text(this, SWT
.BORDER
);
728 fValueText
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
729 if (node
.getValue() != null && node
.getValue().length() > 0) {
730 fValueText
.setText(node
.getValue());
732 fValueText
.setForeground(Display
.getCurrent().getSystemColor(SWT
.COLOR_GRAY
));
733 fValueText
.setText(Messages
.FilterViewer_ValueHint
);
735 fValueText
.addFocusListener(new FocusListener() {
737 public void focusLost(FocusEvent e
) {
738 if (fNode
.getValue() == null || fNode
.getValue().length() == 0) {
739 fValueText
.setForeground(Display
.getCurrent().getSystemColor(SWT
.COLOR_GRAY
));
740 fValueText
.setText(Messages
.FilterViewer_ValueHint
);
745 public void focusGained(FocusEvent e
) {
746 if (fValueText
.getForeground().equals(Display
.getCurrent().getSystemColor(SWT
.COLOR_GRAY
))) {
747 fValueText
.setText(""); //$NON-NLS-1$
749 fValueText
.setForeground(Display
.getCurrent().getSystemColor(SWT
.COLOR_BLACK
));
752 fValueText
.addModifyListener(new ModifyListener() {
754 public void modifyText(ModifyEvent e
) {
755 if (!fValueText
.getForeground().equals(Display
.getCurrent().getSystemColor(SWT
.COLOR_GRAY
))) {
756 fNode
.setValue(fValueText
.getText());
757 fViewer
.refresh(fNode
);
762 label
= new Label(this, SWT
.NONE
);
763 label
.setBackground(Display
.getCurrent().getSystemColor(SWT
.COLOR_WHITE
));
765 fIgnoreCaseButton
= new Button(this, SWT
.CHECK
);
766 fIgnoreCaseButton
.setSelection(fNode
.isIgnoreCase());
767 fIgnoreCaseButton
.setText(Messages
.FilterViewer_IgnoreCaseButtonText
);
768 fIgnoreCaseButton
.setBackground(Display
.getCurrent().getSystemColor(SWT
.COLOR_WHITE
));
769 fIgnoreCaseButton
.addSelectionListener(new SelectionAdapter() {
771 public void widgetSelected(SelectionEvent e
) {
772 fNode
.setIgnoreCase(fIgnoreCaseButton
.getSelection());
773 fViewer
.refresh(fNode
);
779 private class FilterMatchesNodeComposite
extends FilterBaseNodeComposite
{
780 TmfFilterMatchesFieldNode fNode
;
785 FilterMatchesNodeComposite(Composite parent
, TmfFilterMatchesFieldNode node
) {
789 Label label
= new Label(this, SWT
.NONE
);
790 label
.setBackground(Display
.getCurrent().getSystemColor(SWT
.COLOR_WHITE
));
791 label
.setText(Messages
.FilterViewer_NotLabel
);
793 fNotButton
= new Button(this, SWT
.CHECK
);
794 fNotButton
.setBackground(Display
.getCurrent().getSystemColor(SWT
.COLOR_WHITE
));
795 fNotButton
.setSelection(fNode
.isNot());
796 fNotButton
.addSelectionListener(new SelectionAdapter() {
798 public void widgetSelected(SelectionEvent e
) {
799 fNode
.setNot(fNotButton
.getSelection());
800 fViewer
.refresh(fNode
);
804 label
= new Label(this, SWT
.NONE
);
805 label
.setBackground(Display
.getCurrent().getSystemColor(SWT
.COLOR_WHITE
));
806 label
.setText(Messages
.FilterViewer_FieldLabel
);
808 fFieldCombo
= new Combo(this, SWT
.DROP_DOWN
);
809 fFieldCombo
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
810 fFieldCombo
.setItems(getFieldsList());
811 fFieldCombo
.setToolTipText(Messages
.FilterViewer_Subfilter_ToolTip
);
812 if (fNode
.getField() != null) {
813 fFieldCombo
.setText(fNode
.getField());
815 fFieldCombo
.addModifyListener(new ModifyListener() {
817 public void modifyText(ModifyEvent e
) {
818 fNode
.setField(fFieldCombo
.getText());
819 fViewer
.refresh(fNode
);
823 label
= new Label(this, SWT
.NONE
);
824 label
.setBackground(Display
.getCurrent().getSystemColor(SWT
.COLOR_WHITE
));
825 label
.setText(Messages
.FilterViewer_RegexLabel
);
827 fRegexText
= new Text(this, SWT
.BORDER
);
828 fRegexText
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
829 if (node
.getRegex() != null && node
.getRegex().length() > 0) {
830 fRegexText
.setText(node
.getRegex());
832 fRegexText
.setForeground(Display
.getCurrent().getSystemColor(SWT
.COLOR_GRAY
));
833 fRegexText
.setText(Messages
.FilterViewer_RegexHint
);
835 fRegexText
.addFocusListener(new FocusListener() {
837 public void focusLost(FocusEvent e
) {
838 if (fNode
.getRegex() == null || fNode
.getRegex().length() == 0) {
839 fRegexText
.setForeground(Display
.getCurrent().getSystemColor(SWT
.COLOR_GRAY
));
840 fRegexText
.setText(Messages
.FilterViewer_RegexHint
);
845 public void focusGained(FocusEvent e
) {
846 if (fRegexText
.getForeground().equals(Display
.getCurrent().getSystemColor(SWT
.COLOR_GRAY
))) {
847 fRegexText
.setText(""); //$NON-NLS-1$
849 fRegexText
.setForeground(Display
.getCurrent().getSystemColor(SWT
.COLOR_BLACK
));
852 fRegexText
.addModifyListener(new ModifyListener() {
854 public void modifyText(ModifyEvent e
) {
855 if (!fRegexText
.getForeground().equals(Display
.getCurrent().getSystemColor(SWT
.COLOR_GRAY
))) {
856 fNode
.setRegex(fRegexText
.getText());
857 fViewer
.refresh(fNode
);
864 private class FilterCompareNodeComposite
extends FilterBaseNodeComposite
{
865 TmfFilterCompareNode fNode
;
874 Button fTimestampButton
;
876 FilterCompareNodeComposite(Composite parent
, TmfFilterCompareNode node
) {
880 Label label
= new Label(this, SWT
.NONE
);
881 label
.setBackground(Display
.getCurrent().getSystemColor(SWT
.COLOR_WHITE
));
882 label
.setText(Messages
.FilterViewer_NotLabel
);
884 fNotButton
= new Button(this, SWT
.CHECK
);
885 fNotButton
.setBackground(Display
.getCurrent().getSystemColor(SWT
.COLOR_WHITE
));
886 fNotButton
.setSelection(fNode
.isNot());
887 fNotButton
.addSelectionListener(new SelectionAdapter() {
889 public void widgetSelected(SelectionEvent e
) {
890 fNode
.setNot(fNotButton
.getSelection());
891 fViewer
.refresh(fNode
);
895 label
= new Label(this, SWT
.NONE
);
896 label
.setBackground(Display
.getCurrent().getSystemColor(SWT
.COLOR_WHITE
));
897 label
.setText(Messages
.FilterViewer_FieldLabel
);
899 fFieldCombo
= new Combo(this, SWT
.DROP_DOWN
);
900 fFieldCombo
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
901 fFieldCombo
.setItems(getFieldsList());
902 fFieldCombo
.setToolTipText(Messages
.FilterViewer_Subfilter_ToolTip
);
903 if (fNode
.getField() != null) {
904 fFieldCombo
.setText(fNode
.getField());
906 fFieldCombo
.addModifyListener(new ModifyListener() {
908 public void modifyText(ModifyEvent e
) {
909 fNode
.setField(fFieldCombo
.getText());
910 fViewer
.refresh(fNode
);
914 label
= new Label(this, SWT
.NONE
);
915 label
.setBackground(Display
.getCurrent().getSystemColor(SWT
.COLOR_WHITE
));
916 label
.setText(Messages
.FilterViewer_ResultLabel
);
918 Composite resultGroup
= new Composite(this, SWT
.NONE
);
919 GridLayout rggl
= new GridLayout(3, true);
920 rggl
.marginHeight
= 0;
921 rggl
.marginWidth
= 0;
922 resultGroup
.setLayout(rggl
);
923 resultGroup
.setBackground(Display
.getCurrent().getSystemColor(SWT
.COLOR_WHITE
));
925 fLTButton
= new Button(resultGroup
, SWT
.RADIO
);
926 fLTButton
.setSelection(fNode
.getResult() < 0);
927 fLTButton
.setText("<"); //$NON-NLS-1$
928 fLTButton
.setBackground(Display
.getCurrent().getSystemColor(SWT
.COLOR_WHITE
));
929 fLTButton
.addSelectionListener(new SelectionAdapter() {
931 public void widgetSelected(SelectionEvent e
) {
932 if (fLTButton
.getSelection()) {
935 fViewer
.refresh(fNode
);
939 fEQButton
= new Button(resultGroup
, SWT
.RADIO
);
940 fEQButton
.setSelection(fNode
.getResult() == 0);
941 fEQButton
.setText("="); //$NON-NLS-1$
942 fEQButton
.setBackground(Display
.getCurrent().getSystemColor(SWT
.COLOR_WHITE
));
943 fEQButton
.addSelectionListener(new SelectionAdapter() {
945 public void widgetSelected(SelectionEvent e
) {
946 if (fEQButton
.getSelection()) {
949 fViewer
.refresh(fNode
);
953 fGTButton
= new Button(resultGroup
, SWT
.RADIO
);
954 fGTButton
.setSelection(fNode
.getResult() > 0);
955 fGTButton
.setText(">"); //$NON-NLS-1$
956 fGTButton
.setBackground(Display
.getCurrent().getSystemColor(SWT
.COLOR_WHITE
));
957 fGTButton
.addSelectionListener(new SelectionAdapter() {
959 public void widgetSelected(SelectionEvent e
) {
960 if (fGTButton
.getSelection()) {
963 fViewer
.refresh(fNode
);
967 label
= new Label(this, SWT
.NONE
);
968 label
.setBackground(Display
.getCurrent().getSystemColor(SWT
.COLOR_WHITE
));
969 label
.setText(Messages
.FilterViewer_TypeLabel
);
971 Composite typeGroup
= new Composite(this, SWT
.NONE
);
972 GridLayout tggl
= new GridLayout(3, false);
973 tggl
.marginHeight
= 0;
974 tggl
.marginWidth
= 0;
975 typeGroup
.setLayout(tggl
);
976 typeGroup
.setBackground(Display
.getCurrent().getSystemColor(SWT
.COLOR_WHITE
));
978 fNumButton
= new Button(typeGroup
, SWT
.RADIO
);
979 fNumButton
.setSelection(fNode
.getType() == Type
.NUM
);
980 fNumButton
.setText(Messages
.FilterViewer_NumButtonText
);
981 fNumButton
.setBackground(Display
.getCurrent().getSystemColor(SWT
.COLOR_WHITE
));
982 fNumButton
.addSelectionListener(new SelectionAdapter() {
984 public void widgetSelected(SelectionEvent e
) {
985 if (fNumButton
.getSelection()) {
986 fNode
.setType(Type
.NUM
);
988 fViewer
.refresh(fNode
);
992 fAlphaButton
= new Button(typeGroup
, SWT
.RADIO
);
993 fAlphaButton
.setSelection(fNode
.getType() == Type
.ALPHA
);
994 fAlphaButton
.setText(Messages
.FilterViewer_AlphaButtonText
);
995 fAlphaButton
.setBackground(Display
.getCurrent().getSystemColor(SWT
.COLOR_WHITE
));
996 fAlphaButton
.addSelectionListener(new SelectionAdapter() {
998 public void widgetSelected(SelectionEvent e
) {
999 if (fAlphaButton
.getSelection()) {
1000 fNode
.setType(Type
.ALPHA
);
1002 fViewer
.refresh(fNode
);
1006 fTimestampButton
= new Button(typeGroup
, SWT
.RADIO
);
1007 fTimestampButton
.setSelection(fNode
.getType() == Type
.TIMESTAMP
);
1008 fTimestampButton
.setText(Messages
.FilterViewer_TimestampButtonText
);
1009 fTimestampButton
.setBackground(Display
.getCurrent().getSystemColor(SWT
.COLOR_WHITE
));
1010 fTimestampButton
.addSelectionListener(new SelectionAdapter() {
1012 public void widgetSelected(SelectionEvent e
) {
1013 if (fTimestampButton
.getSelection()) {
1014 fNode
.setType(Type
.TIMESTAMP
);
1016 fViewer
.refresh(fNode
);
1020 label
= new Label(this, SWT
.NONE
);
1021 label
.setBackground(Display
.getCurrent().getSystemColor(SWT
.COLOR_WHITE
));
1022 label
.setText(Messages
.FilterViewer_ValueLabel
);
1024 fValueText
= new Text(this, SWT
.BORDER
);
1025 fValueText
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
1026 if (node
.getValue() != null && node
.getValue().length() > 0) {
1027 fValueText
.setText(node
.getValue());
1029 fValueText
.setForeground(Display
.getCurrent().getSystemColor(SWT
.COLOR_GRAY
));
1030 fValueText
.setText(Messages
.FilterViewer_ValueHint
);
1032 fValueText
.addFocusListener(new FocusListener() {
1034 public void focusLost(FocusEvent e
) {
1035 if (fNode
.getValue() == null || fNode
.getValue().length() == 0) {
1036 fValueText
.setForeground(Display
.getCurrent().getSystemColor(SWT
.COLOR_GRAY
));
1037 fValueText
.setText(Messages
.FilterViewer_ValueHint
);
1042 public void focusGained(FocusEvent e
) {
1043 if (fValueText
.getForeground().equals(Display
.getCurrent().getSystemColor(SWT
.COLOR_GRAY
))) {
1044 fValueText
.setText(""); //$NON-NLS-1$
1046 fValueText
.setForeground(Display
.getCurrent().getSystemColor(SWT
.COLOR_BLACK
));
1049 fValueText
.addModifyListener(new ModifyListener() {
1051 public void modifyText(ModifyEvent e
) {
1052 if (!fValueText
.getForeground().equals(Display
.getCurrent().getSystemColor(SWT
.COLOR_GRAY
))) {
1053 fNode
.setValue(fValueText
.getText());
1054 fViewer
.refresh(fNode
);