1 /*******************************************************************************
2 * Copyright (c) 2010 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 *******************************************************************************/
13 package org
.eclipse
.linuxtools
.tmf
.ui
.views
.filter
;
15 import java
.util
.ArrayList
;
16 import java
.util
.LinkedHashMap
;
18 import java
.util
.Map
.Entry
;
20 import org
.eclipse
.core
.runtime
.CoreException
;
21 import org
.eclipse
.core
.runtime
.IConfigurationElement
;
22 import org
.eclipse
.jface
.action
.Action
;
23 import org
.eclipse
.jface
.action
.IMenuListener
;
24 import org
.eclipse
.jface
.action
.IMenuManager
;
25 import org
.eclipse
.jface
.action
.MenuManager
;
26 import org
.eclipse
.jface
.action
.Separator
;
27 import org
.eclipse
.jface
.viewers
.ISelection
;
28 import org
.eclipse
.jface
.viewers
.ISelectionChangedListener
;
29 import org
.eclipse
.jface
.viewers
.IStructuredSelection
;
30 import org
.eclipse
.jface
.viewers
.SelectionChangedEvent
;
31 import org
.eclipse
.jface
.viewers
.StructuredSelection
;
32 import org
.eclipse
.jface
.viewers
.TreeViewer
;
33 import org
.eclipse
.linuxtools
.tmf
.core
.event
.ITmfEventType
;
34 import org
.eclipse
.linuxtools
.tmf
.core
.event
.TmfEvent
;
35 import org
.eclipse
.linuxtools
.tmf
.core
.filter
.model
.ITmfFilterTreeNode
;
36 import org
.eclipse
.linuxtools
.tmf
.core
.filter
.model
.TmfFilterAndNode
;
37 import org
.eclipse
.linuxtools
.tmf
.core
.filter
.model
.TmfFilterCompareNode
;
38 import org
.eclipse
.linuxtools
.tmf
.core
.filter
.model
.TmfFilterCompareNode
.Type
;
39 import org
.eclipse
.linuxtools
.tmf
.core
.filter
.model
.TmfFilterContainsNode
;
40 import org
.eclipse
.linuxtools
.tmf
.core
.filter
.model
.TmfFilterEqualsNode
;
41 import org
.eclipse
.linuxtools
.tmf
.core
.filter
.model
.TmfFilterEventTypeNode
;
42 import org
.eclipse
.linuxtools
.tmf
.core
.filter
.model
.TmfFilterMatchesNode
;
43 import org
.eclipse
.linuxtools
.tmf
.core
.filter
.model
.TmfFilterNode
;
44 import org
.eclipse
.linuxtools
.tmf
.core
.filter
.model
.TmfFilterOrNode
;
45 import org
.eclipse
.linuxtools
.tmf
.core
.filter
.model
.TmfFilterRootNode
;
46 import org
.eclipse
.linuxtools
.tmf
.core
.util
.TmfTraceType
;
47 import org
.eclipse
.linuxtools
.tmf
.ui
.internal
.Messages
;
48 import org
.eclipse
.linuxtools
.tmf
.ui
.parsers
.custom
.CustomTraceDefinition
.OutputColumn
;
49 import org
.eclipse
.linuxtools
.tmf
.ui
.parsers
.custom
.CustomTxtEvent
;
50 import org
.eclipse
.linuxtools
.tmf
.ui
.parsers
.custom
.CustomTxtTraceDefinition
;
51 import org
.eclipse
.linuxtools
.tmf
.ui
.parsers
.custom
.CustomXmlEvent
;
52 import org
.eclipse
.linuxtools
.tmf
.ui
.parsers
.custom
.CustomXmlTraceDefinition
;
53 import org
.eclipse
.swt
.SWT
;
54 import org
.eclipse
.swt
.custom
.SashForm
;
55 import org
.eclipse
.swt
.events
.FocusEvent
;
56 import org
.eclipse
.swt
.events
.FocusListener
;
57 import org
.eclipse
.swt
.events
.ModifyEvent
;
58 import org
.eclipse
.swt
.events
.ModifyListener
;
59 import org
.eclipse
.swt
.events
.SelectionAdapter
;
60 import org
.eclipse
.swt
.events
.SelectionEvent
;
61 import org
.eclipse
.swt
.layout
.FillLayout
;
62 import org
.eclipse
.swt
.layout
.GridData
;
63 import org
.eclipse
.swt
.layout
.GridLayout
;
64 import org
.eclipse
.swt
.widgets
.Button
;
65 import org
.eclipse
.swt
.widgets
.Combo
;
66 import org
.eclipse
.swt
.widgets
.Composite
;
67 import org
.eclipse
.swt
.widgets
.Control
;
68 import org
.eclipse
.swt
.widgets
.Display
;
69 import org
.eclipse
.swt
.widgets
.Label
;
70 import org
.eclipse
.swt
.widgets
.Menu
;
71 import org
.eclipse
.swt
.widgets
.Text
;
72 import org
.eclipse
.swt
.widgets
.TreeItem
;
74 class FilterViewer
extends Composite
{
76 private static final String CUSTOM_TXT_CATEGORY
= "Custom Text"; //$NON-NLS-1$
77 private static final String CUSTOM_XML_CATEGORY
= "Custom XML"; //$NON-NLS-1$
79 private TreeViewer fViewer
;
80 private Composite fComposite
;
82 public FilterViewer(Composite parent
, int style
) {
85 setLayout(new FillLayout());
86 GridData gd
= new GridData(SWT
.FILL
, SWT
.FILL
, true, true);
89 final SashForm sash
= new SashForm(this, SWT
.HORIZONTAL
);
91 // Create the tree viewer to display the filter tree
92 fViewer
= new TreeViewer(sash
, SWT
.NONE
);
93 fViewer
.setContentProvider(new FilterTreeContentProvider());
94 fViewer
.setLabelProvider(new FilterTreeLabelProvider());
95 fViewer
.setInput(new TmfFilterRootNode());
97 // Create the empty filter node properties panel
98 fComposite
= new Composite(sash
, SWT
.NONE
);
99 GridLayout gl
= new GridLayout();
102 fComposite
.setLayout(gl
);
106 fViewer
.addSelectionChangedListener(new ISelectionChangedListener() {
108 public void selectionChanged(SelectionChangedEvent event
) {
109 if (!(event
.getSelection().isEmpty()) && event
.getSelection() instanceof IStructuredSelection
) {
110 // Update the filter node properties panel to the selection
111 IStructuredSelection selection
= (IStructuredSelection
) event
.getSelection();
112 ITmfFilterTreeNode node
= (ITmfFilterTreeNode
) selection
.getFirstElement();
113 updateFilterNodeComposite(node
);
114 // Highlight the selection's children
115 highlightTreeItems(fViewer
.getTree().getSelection()[0].getItems());
117 updateFilterNodeComposite(null);
124 * Create the context menu for the tree viewer
126 private void createContextMenu() {
127 // Adds root context menu
128 MenuManager menuManager
= new MenuManager();
129 menuManager
.setRemoveAllWhenShown(true);
130 menuManager
.addMenuListener(new IMenuListener() {
132 public void menuAboutToShow(IMenuManager manager
) {
133 fillContextMenu(manager
);
138 Menu contextMenu
= menuManager
.createContextMenu(fViewer
.getTree());
141 fViewer
.getTree().setMenu(contextMenu
);
145 * Fill the context menu for the tree viewer
147 protected void fillContextMenu(IMenuManager manager
) {
148 final ISelection selection
= fViewer
.getSelection();
149 ITmfFilterTreeNode filterTreeNode
= null;
150 if (selection
instanceof StructuredSelection
) {
151 Object element
= ((StructuredSelection
) selection
).getFirstElement();
152 if (element
instanceof ITmfFilterTreeNode
) {
153 filterTreeNode
= (ITmfFilterTreeNode
) element
;
157 final ITmfFilterTreeNode selectedNode
= filterTreeNode
;
159 if (selectedNode
!= null) {
161 fillContextMenuForNode(selectedNode
, manager
);
163 if (selectedNode
.getValidChildren().size() > 0) {
164 manager
.add(new Separator());
167 Action deleteAction
= new Action() {
170 selectedNode
.remove();
174 deleteAction
.setText(Messages
.FilterViewer_DeleteActionText
);
175 manager
.add(deleteAction
);
177 manager
.add(new Separator());
180 if (fViewer
.getInput() instanceof TmfFilterRootNode
|| selectedNode
== null) {
181 final ITmfFilterTreeNode root
= (ITmfFilterTreeNode
) fViewer
.getInput();
183 fillContextMenuForNode(root
, manager
);
188 * Fill the context menu with the valid children of the provided node
190 protected void fillContextMenuForNode(final ITmfFilterTreeNode node
, IMenuManager manager
) {
191 for (final String child
: node
.getValidChildren()) {
192 final Action action
= new Action() {
195 ITmfFilterTreeNode newNode
= null;
196 if (TmfFilterNode
.NODE_NAME
.equals(child
)) {
197 newNode
= new TmfFilterNode(node
, ""); //$NON-NLS-1$
198 } else if (TmfFilterEventTypeNode
.NODE_NAME
.equals(child
)) {
199 newNode
= new TmfFilterEventTypeNode(node
);
200 } else if (TmfFilterAndNode
.NODE_NAME
.equals(child
)) {
201 newNode
= new TmfFilterAndNode(node
);
202 } else if (TmfFilterOrNode
.NODE_NAME
.equals(child
)) {
203 newNode
= new TmfFilterOrNode(node
);
204 } else if (TmfFilterContainsNode
.NODE_NAME
.equals(child
)) {
205 newNode
= new TmfFilterContainsNode(node
);
206 } else if (TmfFilterEqualsNode
.NODE_NAME
.equals(child
)) {
207 newNode
= new TmfFilterEqualsNode(node
);
208 } else if (TmfFilterMatchesNode
.NODE_NAME
.equals(child
)) {
209 newNode
= new TmfFilterMatchesNode(node
);
210 } else if (TmfFilterCompareNode
.NODE_NAME
.equals(child
)) {
211 newNode
= new TmfFilterCompareNode(node
);
213 if (newNode
!= null) {
215 fViewer
.setSelection(new StructuredSelection(newNode
), true);
219 if (TmfFilterNode
.NODE_NAME
.equals(child
)) {
220 action
.setText(Messages
.FilterViewer_NewPrefix
+ " " + child
); //$NON-NLS-1$
222 action
.setText(child
);
229 * Create the appropriate filter node properties composite
231 private void updateFilterNodeComposite(ITmfFilterTreeNode node
) {
232 for (Control control
: fComposite
.getChildren()) {
236 if (node
instanceof TmfFilterNode
) {
237 new FilterNodeComposite(fComposite
, (TmfFilterNode
) node
);
238 } else if (node
instanceof TmfFilterEventTypeNode
) {
239 new FilterEventTypeNodeComposite(fComposite
, (TmfFilterEventTypeNode
) node
);
240 } else if (node
instanceof TmfFilterAndNode
) {
241 new FilterAndNodeComposite(fComposite
, (TmfFilterAndNode
) node
);
242 } else if (node
instanceof TmfFilterOrNode
) {
243 new FilterOrNodeComposite(fComposite
, (TmfFilterOrNode
) node
);
244 } else if (node
instanceof TmfFilterContainsNode
) {
245 new FilterContainsNodeComposite(fComposite
, (TmfFilterContainsNode
) node
);
246 } else if (node
instanceof TmfFilterEqualsNode
) {
247 new FilterEqualsNodeComposite(fComposite
, (TmfFilterEqualsNode
) node
);
248 } else if (node
instanceof TmfFilterMatchesNode
) {
249 new FilterMatchesNodeComposite(fComposite
, (TmfFilterMatchesNode
) node
);
250 } else if (node
instanceof TmfFilterCompareNode
) {
251 new FilterCompareNodeComposite(fComposite
, (TmfFilterCompareNode
) node
);
253 new FilterBaseNodeComposite(fComposite
);
259 * Highlight the provided tree items
261 private void highlightTreeItems(TreeItem
[] items
) {
262 resetTreeItems(fViewer
.getTree().getItems());
263 for (TreeItem item
: items
) {
264 item
.setForeground(Display
.getCurrent().getSystemColor(SWT
.COLOR_BLUE
));
270 * Reset the provided tree items (remove highlight)
272 private void resetTreeItems(TreeItem
[] items
) {
273 for (TreeItem item
: items
) {
274 item
.setForeground(Display
.getCurrent().getSystemColor(SWT
.COLOR_BLACK
));
275 resetTreeItems(item
.getItems());
279 public void setInput(ITmfFilterTreeNode root
) {
280 fViewer
.setInput(root
);
283 updateFilterNodeComposite(null);
286 public ITmfFilterTreeNode
getInput() {
287 return (ITmfFilterTreeNode
) fViewer
.getInput();
290 public void refresh() {
294 public void setSelection(ITmfFilterTreeNode node
, boolean reveal
) {
295 fViewer
.setSelection(new StructuredSelection(node
), reveal
);
298 public void setSelection(ITmfFilterTreeNode node
) {
299 fViewer
.setSelection(new StructuredSelection(node
));
302 public ITmfFilterTreeNode
getSelection() {
303 final ISelection selection
= fViewer
.getSelection();
304 ITmfFilterTreeNode filterTreeNode
= null;
305 if (selection
instanceof StructuredSelection
) {
306 Object element
= ((StructuredSelection
) selection
).getFirstElement();
307 if (element
instanceof ITmfFilterTreeNode
) {
308 filterTreeNode
= (ITmfFilterTreeNode
) element
;
312 final ITmfFilterTreeNode selectedNode
= filterTreeNode
;
316 public void addSelectionChangedListener(ISelectionChangedListener listener
) {
317 fViewer
.addSelectionChangedListener(listener
);
320 public void removeSelectionChangedListener(ISelectionChangedListener listener
) {
321 fViewer
.removeSelectionChangedListener(listener
);
324 private class FilterBaseNodeComposite
extends Composite
{
326 FilterBaseNodeComposite(Composite parent
) {
327 super(parent
, SWT
.NONE
);
328 setLayout(new GridLayout(2, false));
329 setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
330 setBackground(Display
.getCurrent().getSystemColor(SWT
.COLOR_WHITE
));
333 protected String
[] getFieldsList(ITmfFilterTreeNode node
) {
334 ArrayList
<String
> fieldsList
= new ArrayList
<String
>();
335 while (node
!= null) {
336 if (node
instanceof TmfFilterEventTypeNode
) {
337 TmfFilterEventTypeNode eventTypeNode
= (TmfFilterEventTypeNode
) node
;
338 for (IConfigurationElement ce
: TmfTraceType
.getTypeElements()) {
339 if (ce
.getAttribute(TmfTraceType
.EVENT_TYPE_ATTR
).equals(eventTypeNode
.getEventType())) {
341 TmfEvent event
= (TmfEvent
) ce
.createExecutableExtension(TmfTraceType
.EVENT_TYPE_ATTR
);
342 ITmfEventType eventType
= event
.getType();
343 if (eventType
!= null) {
344 for (String field
: eventType
.getRootField().getFieldNames()) {
345 fieldsList
.add(field
);
348 } catch (CoreException e
) {
350 return fieldsList
.toArray(new String
[0]);
353 if (eventTypeNode
.getEventType().startsWith(CustomTxtEvent
.class.getCanonicalName())) {
354 for (CustomTxtTraceDefinition def
: CustomTxtTraceDefinition
.loadAll()) {
355 if (eventTypeNode
.getEventType().equals(CustomTxtEvent
.class.getCanonicalName() + ":" + def
.definitionName
)) { //$NON-NLS-1$
356 for (OutputColumn output
: def
.outputs
) {
357 fieldsList
.add(output
.name
);
359 return fieldsList
.toArray(new String
[0]);
363 if (eventTypeNode
.getEventType().startsWith(CustomXmlEvent
.class.getCanonicalName())) {
364 for (CustomXmlTraceDefinition def
: CustomXmlTraceDefinition
.loadAll()) {
365 if (eventTypeNode
.getEventType().equals(CustomXmlEvent
.class.getCanonicalName() + ":" + def
.definitionName
)) { //$NON-NLS-1$
366 for (OutputColumn output
: def
.outputs
) {
367 fieldsList
.add(output
.name
);
369 return fieldsList
.toArray(new String
[0]);
374 node
= node
.getParent();
376 for (IConfigurationElement ce
: TmfTraceType
.getTypeElements()) {
378 TmfEvent event
= (TmfEvent
) ce
.createExecutableExtension(TmfTraceType
.EVENT_TYPE_ATTR
);
379 ITmfEventType eventType
= event
.getType();
380 if (eventType
!= null) {
381 fieldsList
.add("[" + TmfTraceType
.getCategoryName(ce
.getAttribute(TmfTraceType
.CATEGORY_ATTR
)) + //$NON-NLS-1$
382 " : " + ce
.getAttribute(TmfTraceType
.NAME_ATTR
) + "]"); //$NON-NLS-1$ //$NON-NLS-2$
383 for (String field
: eventType
.getFieldNames()) {
384 fieldsList
.add(field
);
386 fieldsList
.add(""); //$NON-NLS-1$
388 } catch (CoreException e
) {
391 for (CustomTxtTraceDefinition def
: CustomTxtTraceDefinition
.loadAll()) {
392 fieldsList
.add("[" + CUSTOM_TXT_CATEGORY
+ //$NON-NLS-1$
393 " : " + def
.definitionName
+ "]"); //$NON-NLS-1$ //$NON-NLS-2$
394 for (OutputColumn output
: def
.outputs
) {
395 fieldsList
.add(output
.name
);
397 fieldsList
.add(""); //$NON-NLS-1$
399 for (CustomXmlTraceDefinition def
: CustomXmlTraceDefinition
.loadAll()) {
400 fieldsList
.add("[" + CUSTOM_XML_CATEGORY
+ //$NON-NLS-1$
401 " : " + def
.definitionName
+ "]"); //$NON-NLS-1$ //$NON-NLS-2$
402 for (OutputColumn output
: def
.outputs
) {
403 fieldsList
.add(output
.name
);
405 fieldsList
.add(""); //$NON-NLS-1$
407 return fieldsList
.toArray(new String
[0]);
411 private class FilterNodeComposite
extends FilterBaseNodeComposite
{
415 FilterNodeComposite(Composite parent
, TmfFilterNode node
) {
419 Label label
= new Label(this, SWT
.NONE
);
420 label
.setBackground(Display
.getCurrent().getSystemColor(SWT
.COLOR_WHITE
));
421 label
.setText(Messages
.FilterViewer_NameLabel
);
423 fNameText
= new Text(this, SWT
.BORDER
);
424 fNameText
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
425 if (node
.getFilterName() != null && node
.getFilterName().length() > 0) {
426 fNameText
.setText(node
.getFilterName());
428 fNameText
.setForeground(Display
.getCurrent().getSystemColor(SWT
.COLOR_GRAY
));
429 fNameText
.setText(Messages
.FilterViewer_FilterNameHint
);
431 fNameText
.addFocusListener(new FocusListener() {
433 public void focusLost(FocusEvent e
) {
434 if (fNode
.getFilterName() == null || fNode
.getFilterName().length() == 0) {
435 fNameText
.setForeground(Display
.getCurrent().getSystemColor(SWT
.COLOR_GRAY
));
436 fNameText
.setText(Messages
.FilterViewer_FilterNameHint
);
440 public void focusGained(FocusEvent e
) {
441 if (fNameText
.getForeground().equals(Display
.getCurrent().getSystemColor(SWT
.COLOR_GRAY
))) {
442 fNameText
.setText(""); //$NON-NLS-1$
444 fNameText
.setForeground(Display
.getCurrent().getSystemColor(SWT
.COLOR_BLACK
));
447 fNameText
.addModifyListener(new ModifyListener() {
449 public void modifyText(ModifyEvent e
) {
450 if (! fNameText
.getForeground().equals(Display
.getCurrent().getSystemColor(SWT
.COLOR_GRAY
))) {
451 fNode
.setFilterName(fNameText
.getText());
452 fViewer
.refresh(fNode
);
459 private class FilterEventTypeNodeComposite
extends FilterBaseNodeComposite
{
460 TmfFilterEventTypeNode fNode
;
462 Map
<String
, Object
> fEventsTypeMap
;
464 FilterEventTypeNodeComposite(Composite parent
, TmfFilterEventTypeNode node
) {
467 fEventsTypeMap
= getEventsTypeMap();
469 Label label
= new Label(this, SWT
.NONE
);
470 label
.setBackground(Display
.getCurrent().getSystemColor(SWT
.COLOR_WHITE
));
471 label
.setText(Messages
.FilterViewer_TypeLabel
);
473 fTypeCombo
= new Combo(this, SWT
.DROP_DOWN
| SWT
.READ_ONLY
);
474 fTypeCombo
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
475 fTypeCombo
.setItems(fEventsTypeMap
.keySet().toArray(new String
[0]));
476 if (fNode
.getEventType() != null) {
477 for (Entry
<String
, Object
> eventTypeEntry
: fEventsTypeMap
.entrySet()) {
478 Object value
= eventTypeEntry
.getValue();
479 if (value
instanceof IConfigurationElement
) {
480 IConfigurationElement ce
= (IConfigurationElement
) value
;
481 if (ce
.getAttribute(TmfTraceType
.EVENT_TYPE_ATTR
).equals(fNode
.getEventType())) {
482 fTypeCombo
.setText(eventTypeEntry
.getKey());
484 } else if (value
instanceof CustomTxtTraceDefinition
) {
485 CustomTxtTraceDefinition def
= (CustomTxtTraceDefinition
) value
;
486 String eventType
= CustomTxtEvent
.class.getCanonicalName() + ":" + def
.definitionName
; //$NON-NLS-1$
487 if (eventType
.equals(fNode
.getEventType())) {
488 fTypeCombo
.setText(eventTypeEntry
.getKey());
490 } else if (value
instanceof CustomXmlTraceDefinition
) {
491 CustomXmlTraceDefinition def
= (CustomXmlTraceDefinition
) value
;
492 String eventType
= CustomXmlEvent
.class.getCanonicalName() + ":" + def
.definitionName
; //$NON-NLS-1$
493 if (eventType
.equals(fNode
.getEventType())) {
494 fTypeCombo
.setText(eventTypeEntry
.getKey());
499 fTypeCombo
.addModifyListener(new ModifyListener() {
501 public void modifyText(ModifyEvent e
) {
502 for (Entry
<String
, Object
> eventTypeEntry
: fEventsTypeMap
.entrySet()) {
503 if (eventTypeEntry
.getKey().equals(fTypeCombo
.getText())) {
504 Object value
= eventTypeEntry
.getValue();
505 if (value
instanceof IConfigurationElement
) {
506 IConfigurationElement ce
= (IConfigurationElement
) value
;
507 fNode
.setEventType(ce
.getAttribute(TmfTraceType
.EVENT_TYPE_ATTR
));
508 fNode
.setName(ce
.getAttribute(TmfTraceType
.NAME_ATTR
));
509 } else if (value
instanceof CustomTxtTraceDefinition
) {
510 CustomTxtTraceDefinition def
= (CustomTxtTraceDefinition
) value
;
511 fNode
.setEventType(CustomTxtEvent
.class.getCanonicalName() + ":" + def
.definitionName
); //$NON-NLS-1$
512 fNode
.setName(def
.definitionName
);
513 } else if (value
instanceof CustomXmlTraceDefinition
) {
514 CustomXmlTraceDefinition def
= (CustomXmlTraceDefinition
) value
;
515 fNode
.setEventType(CustomXmlEvent
.class.getCanonicalName() + ":" + def
.definitionName
); //$NON-NLS-1$
516 fNode
.setName(def
.definitionName
);
518 fViewer
.refresh(fNode
);
526 protected Map
<String
, Object
> getEventsTypeMap() {
527 Map
<String
, Object
> eventsTypeMap
= new LinkedHashMap
<String
, Object
>();
528 for (IConfigurationElement ce
: TmfTraceType
.getTypeElements()) {
529 String categoryName
= TmfTraceType
.getCategoryName(ce
.getAttribute(TmfTraceType
.CATEGORY_ATTR
));
530 String text
= categoryName
+ " : " + ce
.getAttribute(TmfTraceType
.NAME_ATTR
); //$NON-NLS-1$
531 eventsTypeMap
.put(text
, ce
);
533 for (CustomTxtTraceDefinition def
: CustomTxtTraceDefinition
.loadAll()) {
534 String text
= CUSTOM_TXT_CATEGORY
+ " : " + def
.definitionName
; //$NON-NLS-1$
535 eventsTypeMap
.put(text
, def
);
537 for (CustomXmlTraceDefinition def
: CustomXmlTraceDefinition
.loadAll()) {
538 String text
= CUSTOM_XML_CATEGORY
+ " : " + def
.definitionName
; //$NON-NLS-1$
539 eventsTypeMap
.put(text
, def
);
541 return eventsTypeMap
;
545 private class FilterAndNodeComposite
extends FilterBaseNodeComposite
{
546 TmfFilterAndNode fNode
;
549 FilterAndNodeComposite(Composite parent
, TmfFilterAndNode node
) {
553 Label label
= new Label(this, SWT
.NONE
);
554 label
.setBackground(Display
.getCurrent().getSystemColor(SWT
.COLOR_WHITE
));
555 label
.setText(Messages
.FilterViewer_NotLabel
);
557 fNotButton
= new Button(this, SWT
.CHECK
);
558 fNotButton
.setBackground(Display
.getCurrent().getSystemColor(SWT
.COLOR_WHITE
));
559 fNotButton
.setSelection(fNode
.isNot());
560 fNotButton
.addSelectionListener(new SelectionAdapter() {
562 public void widgetSelected(SelectionEvent e
) {
563 fNode
.setNot(fNotButton
.getSelection());
564 fViewer
.refresh(fNode
);
570 private class FilterOrNodeComposite
extends FilterBaseNodeComposite
{
571 TmfFilterOrNode fNode
;
574 FilterOrNodeComposite(Composite parent
, TmfFilterOrNode node
) {
578 Label label
= new Label(this, SWT
.NONE
);
579 label
.setBackground(Display
.getCurrent().getSystemColor(SWT
.COLOR_WHITE
));
580 label
.setText(Messages
.FilterViewer_NotLabel
);
582 fNotButton
= new Button(this, SWT
.CHECK
);
583 fNotButton
.setBackground(Display
.getCurrent().getSystemColor(SWT
.COLOR_WHITE
));
584 fNotButton
.setSelection(fNode
.isNot());
585 fNotButton
.addSelectionListener(new SelectionAdapter() {
587 public void widgetSelected(SelectionEvent e
) {
588 fNode
.setNot(fNotButton
.getSelection());
589 fViewer
.refresh(fNode
);
595 private class FilterContainsNodeComposite
extends FilterBaseNodeComposite
{
596 TmfFilterContainsNode fNode
;
600 Button fIgnoreCaseButton
;
602 FilterContainsNodeComposite(Composite parent
, TmfFilterContainsNode node
) {
606 Label label
= new Label(this, SWT
.NONE
);
607 label
.setBackground(Display
.getCurrent().getSystemColor(SWT
.COLOR_WHITE
));
608 label
.setText(Messages
.FilterViewer_NotLabel
);
610 fNotButton
= new Button(this, SWT
.CHECK
);
611 fNotButton
.setBackground(Display
.getCurrent().getSystemColor(SWT
.COLOR_WHITE
));
612 fNotButton
.setSelection(fNode
.isNot());
613 fNotButton
.addSelectionListener(new SelectionAdapter() {
615 public void widgetSelected(SelectionEvent e
) {
616 fNode
.setNot(fNotButton
.getSelection());
617 fViewer
.refresh(fNode
);
621 label
= new Label(this, SWT
.NONE
);
622 label
.setBackground(Display
.getCurrent().getSystemColor(SWT
.COLOR_WHITE
));
623 label
.setText(Messages
.FilterViewer_FieldLabel
);
625 fFieldCombo
= new Combo(this, SWT
.DROP_DOWN
);
626 fFieldCombo
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
627 fFieldCombo
.setItems(getFieldsList(fNode
));
628 if (fNode
.getField() != null) {
629 fFieldCombo
.setText(fNode
.getField());
631 fFieldCombo
.addModifyListener(new ModifyListener() {
633 public void modifyText(ModifyEvent e
) {
634 fNode
.setField(fFieldCombo
.getText());
635 fViewer
.refresh(fNode
);
639 label
= new Label(this, SWT
.NONE
);
640 label
.setBackground(Display
.getCurrent().getSystemColor(SWT
.COLOR_WHITE
));
641 label
.setText(Messages
.FilterViewer_ValueLabel
);
643 fValueText
= new Text(this, SWT
.BORDER
);
644 fValueText
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
645 if (node
.getValue() != null && node
.getValue().length() > 0) {
646 fValueText
.setText(node
.getValue());
648 fValueText
.setForeground(Display
.getCurrent().getSystemColor(SWT
.COLOR_GRAY
));
649 fValueText
.setText(Messages
.FilterViewer_ValueHint
);
651 fValueText
.addFocusListener(new FocusListener() {
653 public void focusLost(FocusEvent e
) {
654 if (fNode
.getValue() == null || fNode
.getValue().length() == 0) {
655 fValueText
.setForeground(Display
.getCurrent().getSystemColor(SWT
.COLOR_GRAY
));
656 fValueText
.setText(Messages
.FilterViewer_ValueHint
);
660 public void focusGained(FocusEvent e
) {
661 if (fValueText
.getForeground().equals(Display
.getCurrent().getSystemColor(SWT
.COLOR_GRAY
))) {
662 fValueText
.setText(""); //$NON-NLS-1$
664 fValueText
.setForeground(Display
.getCurrent().getSystemColor(SWT
.COLOR_BLACK
));
667 fValueText
.addModifyListener(new ModifyListener() {
669 public void modifyText(ModifyEvent e
) {
670 if (! fValueText
.getForeground().equals(Display
.getCurrent().getSystemColor(SWT
.COLOR_GRAY
))) {
671 fNode
.setValue(fValueText
.getText());
672 fViewer
.refresh(fNode
);
677 label
= new Label(this, SWT
.NONE
);
678 label
.setBackground(Display
.getCurrent().getSystemColor(SWT
.COLOR_WHITE
));
680 fIgnoreCaseButton
= new Button(this, SWT
.CHECK
);
681 fIgnoreCaseButton
.setSelection(fNode
.isIgnoreCase());
682 fIgnoreCaseButton
.setText(Messages
.FilterViewer_IgnoreCaseButtonText
);
683 fIgnoreCaseButton
.setBackground(Display
.getCurrent().getSystemColor(SWT
.COLOR_WHITE
));
684 fIgnoreCaseButton
.addSelectionListener(new SelectionAdapter() {
686 public void widgetSelected(SelectionEvent e
) {
687 fNode
.setIgnoreCase(fIgnoreCaseButton
.getSelection());
688 fViewer
.refresh(fNode
);
694 private class FilterEqualsNodeComposite
extends FilterBaseNodeComposite
{
695 TmfFilterEqualsNode fNode
;
699 Button fIgnoreCaseButton
;
701 FilterEqualsNodeComposite(Composite parent
, TmfFilterEqualsNode node
) {
705 Label label
= new Label(this, SWT
.NONE
);
706 label
.setBackground(Display
.getCurrent().getSystemColor(SWT
.COLOR_WHITE
));
707 label
.setText(Messages
.FilterViewer_NotLabel
);
709 fNotButton
= new Button(this, SWT
.CHECK
);
710 fNotButton
.setBackground(Display
.getCurrent().getSystemColor(SWT
.COLOR_WHITE
));
711 fNotButton
.setSelection(fNode
.isNot());
712 fNotButton
.addSelectionListener(new SelectionAdapter() {
714 public void widgetSelected(SelectionEvent e
) {
715 fNode
.setNot(fNotButton
.getSelection());
716 fViewer
.refresh(fNode
);
720 label
= new Label(this, SWT
.NONE
);
721 label
.setBackground(Display
.getCurrent().getSystemColor(SWT
.COLOR_WHITE
));
722 label
.setText(Messages
.FilterViewer_FieldLabel
);
724 fFieldCombo
= new Combo(this, SWT
.DROP_DOWN
);
725 fFieldCombo
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
726 fFieldCombo
.setItems(getFieldsList(fNode
));
727 if (fNode
.getField() != null) {
728 fFieldCombo
.setText(fNode
.getField());
730 fFieldCombo
.addModifyListener(new ModifyListener() {
732 public void modifyText(ModifyEvent e
) {
733 fNode
.setField(fFieldCombo
.getText());
734 fViewer
.refresh(fNode
);
738 label
= new Label(this, SWT
.NONE
);
739 label
.setBackground(Display
.getCurrent().getSystemColor(SWT
.COLOR_WHITE
));
740 label
.setText(Messages
.FilterViewer_ValueLabel
);
742 fValueText
= new Text(this, SWT
.BORDER
);
743 fValueText
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
744 if (node
.getValue() != null && node
.getValue().length() > 0) {
745 fValueText
.setText(node
.getValue());
747 fValueText
.setForeground(Display
.getCurrent().getSystemColor(SWT
.COLOR_GRAY
));
748 fValueText
.setText(Messages
.FilterViewer_ValueHint
);
750 fValueText
.addFocusListener(new FocusListener() {
752 public void focusLost(FocusEvent e
) {
753 if (fNode
.getValue() == null || fNode
.getValue().length() == 0) {
754 fValueText
.setForeground(Display
.getCurrent().getSystemColor(SWT
.COLOR_GRAY
));
755 fValueText
.setText(Messages
.FilterViewer_ValueHint
);
759 public void focusGained(FocusEvent e
) {
760 if (fValueText
.getForeground().equals(Display
.getCurrent().getSystemColor(SWT
.COLOR_GRAY
))) {
761 fValueText
.setText(""); //$NON-NLS-1$
763 fValueText
.setForeground(Display
.getCurrent().getSystemColor(SWT
.COLOR_BLACK
));
766 fValueText
.addModifyListener(new ModifyListener() {
768 public void modifyText(ModifyEvent e
) {
769 if (! fValueText
.getForeground().equals(Display
.getCurrent().getSystemColor(SWT
.COLOR_GRAY
))) {
770 fNode
.setValue(fValueText
.getText());
771 fViewer
.refresh(fNode
);
776 label
= new Label(this, SWT
.NONE
);
777 label
.setBackground(Display
.getCurrent().getSystemColor(SWT
.COLOR_WHITE
));
779 fIgnoreCaseButton
= new Button(this, SWT
.CHECK
);
780 fIgnoreCaseButton
.setSelection(fNode
.isIgnoreCase());
781 fIgnoreCaseButton
.setText(Messages
.FilterViewer_IgnoreCaseButtonText
);
782 fIgnoreCaseButton
.setBackground(Display
.getCurrent().getSystemColor(SWT
.COLOR_WHITE
));
783 fIgnoreCaseButton
.addSelectionListener(new SelectionAdapter() {
785 public void widgetSelected(SelectionEvent e
) {
786 fNode
.setIgnoreCase(fIgnoreCaseButton
.getSelection());
787 fViewer
.refresh(fNode
);
793 private class FilterMatchesNodeComposite
extends FilterBaseNodeComposite
{
794 TmfFilterMatchesNode fNode
;
799 FilterMatchesNodeComposite(Composite parent
, TmfFilterMatchesNode node
) {
803 Label label
= new Label(this, SWT
.NONE
);
804 label
.setBackground(Display
.getCurrent().getSystemColor(SWT
.COLOR_WHITE
));
805 label
.setText(Messages
.FilterViewer_NotLabel
);
807 fNotButton
= new Button(this, SWT
.CHECK
);
808 fNotButton
.setBackground(Display
.getCurrent().getSystemColor(SWT
.COLOR_WHITE
));
809 fNotButton
.setSelection(fNode
.isNot());
810 fNotButton
.addSelectionListener(new SelectionAdapter() {
812 public void widgetSelected(SelectionEvent e
) {
813 fNode
.setNot(fNotButton
.getSelection());
814 fViewer
.refresh(fNode
);
818 label
= new Label(this, SWT
.NONE
);
819 label
.setBackground(Display
.getCurrent().getSystemColor(SWT
.COLOR_WHITE
));
820 label
.setText(Messages
.FilterViewer_FieldLabel
);
822 fFieldCombo
= new Combo(this, SWT
.DROP_DOWN
);
823 fFieldCombo
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
824 fFieldCombo
.setItems(getFieldsList(fNode
));
825 if (fNode
.getField() != null) {
826 fFieldCombo
.setText(fNode
.getField());
828 fFieldCombo
.addModifyListener(new ModifyListener() {
830 public void modifyText(ModifyEvent e
) {
831 fNode
.setField(fFieldCombo
.getText());
832 fViewer
.refresh(fNode
);
836 label
= new Label(this, SWT
.NONE
);
837 label
.setBackground(Display
.getCurrent().getSystemColor(SWT
.COLOR_WHITE
));
838 label
.setText(Messages
.FilterViewer_RegexLabel
);
840 fRegexText
= new Text(this, SWT
.BORDER
);
841 fRegexText
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
842 if (node
.getRegex() != null && node
.getRegex().length() > 0) {
843 fRegexText
.setText(node
.getRegex());
845 fRegexText
.setForeground(Display
.getCurrent().getSystemColor(SWT
.COLOR_GRAY
));
846 fRegexText
.setText(Messages
.FilterViewer_RegexHint
);
848 fRegexText
.addFocusListener(new FocusListener() {
850 public void focusLost(FocusEvent e
) {
851 if (fNode
.getRegex() == null || fNode
.getRegex().length() == 0) {
852 fRegexText
.setForeground(Display
.getCurrent().getSystemColor(SWT
.COLOR_GRAY
));
853 fRegexText
.setText(Messages
.FilterViewer_RegexHint
);
857 public void focusGained(FocusEvent e
) {
858 if (fRegexText
.getForeground().equals(Display
.getCurrent().getSystemColor(SWT
.COLOR_GRAY
))) {
859 fRegexText
.setText(""); //$NON-NLS-1$
861 fRegexText
.setForeground(Display
.getCurrent().getSystemColor(SWT
.COLOR_BLACK
));
864 fRegexText
.addModifyListener(new ModifyListener() {
866 public void modifyText(ModifyEvent e
) {
867 if (! fRegexText
.getForeground().equals(Display
.getCurrent().getSystemColor(SWT
.COLOR_GRAY
))) {
868 fNode
.setRegex(fRegexText
.getText());
869 fViewer
.refresh(fNode
);
876 private class FilterCompareNodeComposite
extends FilterBaseNodeComposite
{
877 TmfFilterCompareNode fNode
;
886 Button fTimestampButton
;
888 FilterCompareNodeComposite(Composite parent
, TmfFilterCompareNode node
) {
892 Label label
= new Label(this, SWT
.NONE
);
893 label
.setBackground(Display
.getCurrent().getSystemColor(SWT
.COLOR_WHITE
));
894 label
.setText(Messages
.FilterViewer_NotLabel
);
896 fNotButton
= new Button(this, SWT
.CHECK
);
897 fNotButton
.setBackground(Display
.getCurrent().getSystemColor(SWT
.COLOR_WHITE
));
898 fNotButton
.setSelection(fNode
.isNot());
899 fNotButton
.addSelectionListener(new SelectionAdapter() {
901 public void widgetSelected(SelectionEvent e
) {
902 fNode
.setNot(fNotButton
.getSelection());
903 fViewer
.refresh(fNode
);
907 label
= new Label(this, SWT
.NONE
);
908 label
.setBackground(Display
.getCurrent().getSystemColor(SWT
.COLOR_WHITE
));
909 label
.setText(Messages
.FilterViewer_FieldLabel
);
911 fFieldCombo
= new Combo(this, SWT
.DROP_DOWN
);
912 fFieldCombo
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
913 fFieldCombo
.setItems(getFieldsList(fNode
));
914 if (fNode
.getField() != null) {
915 fFieldCombo
.setText(fNode
.getField());
917 fFieldCombo
.addModifyListener(new ModifyListener() {
919 public void modifyText(ModifyEvent e
) {
920 fNode
.setField(fFieldCombo
.getText());
921 fViewer
.refresh(fNode
);
925 label
= new Label(this, SWT
.NONE
);
926 label
.setBackground(Display
.getCurrent().getSystemColor(SWT
.COLOR_WHITE
));
927 label
.setText(Messages
.FilterViewer_ResultLabel
);
929 Composite resultGroup
= new Composite(this, SWT
.NONE
);
930 GridLayout rggl
= new GridLayout(3, true);
931 rggl
.marginHeight
= 0;
932 rggl
.marginWidth
= 0;
933 resultGroup
.setLayout(rggl
);
934 resultGroup
.setBackground(Display
.getCurrent().getSystemColor(SWT
.COLOR_WHITE
));
936 fLTButton
= new Button(resultGroup
, SWT
.RADIO
);
937 fLTButton
.setSelection(fNode
.getResult() < 0);
938 fLTButton
.setText("<"); //$NON-NLS-1$
939 fLTButton
.setBackground(Display
.getCurrent().getSystemColor(SWT
.COLOR_WHITE
));
940 fLTButton
.addSelectionListener(new SelectionAdapter() {
942 public void widgetSelected(SelectionEvent e
) {
943 if (fLTButton
.getSelection()) {
946 fViewer
.refresh(fNode
);
950 fEQButton
= new Button(resultGroup
, SWT
.RADIO
);
951 fEQButton
.setSelection(fNode
.getResult() == 0);
952 fEQButton
.setText("="); //$NON-NLS-1$
953 fEQButton
.setBackground(Display
.getCurrent().getSystemColor(SWT
.COLOR_WHITE
));
954 fEQButton
.addSelectionListener(new SelectionAdapter() {
956 public void widgetSelected(SelectionEvent e
) {
957 if (fEQButton
.getSelection()) {
960 fViewer
.refresh(fNode
);
964 fGTButton
= new Button(resultGroup
, SWT
.RADIO
);
965 fGTButton
.setSelection(fNode
.getResult() > 0);
966 fGTButton
.setText(">"); //$NON-NLS-1$
967 fGTButton
.setBackground(Display
.getCurrent().getSystemColor(SWT
.COLOR_WHITE
));
968 fGTButton
.addSelectionListener(new SelectionAdapter() {
970 public void widgetSelected(SelectionEvent e
) {
971 if (fGTButton
.getSelection()) {
974 fViewer
.refresh(fNode
);
978 label
= new Label(this, SWT
.NONE
);
979 label
.setBackground(Display
.getCurrent().getSystemColor(SWT
.COLOR_WHITE
));
980 label
.setText(Messages
.FilterViewer_TypeLabel
);
982 Composite typeGroup
= new Composite(this, SWT
.NONE
);
983 GridLayout tggl
= new GridLayout(3, false);
984 tggl
.marginHeight
= 0;
985 tggl
.marginWidth
= 0;
986 typeGroup
.setLayout(tggl
);
987 typeGroup
.setBackground(Display
.getCurrent().getSystemColor(SWT
.COLOR_WHITE
));
989 fNumButton
= new Button(typeGroup
, SWT
.RADIO
);
990 fNumButton
.setSelection(fNode
.getType() == Type
.NUM
);
991 fNumButton
.setText(Messages
.FilterViewer_NumButtonText
);
992 fNumButton
.setBackground(Display
.getCurrent().getSystemColor(SWT
.COLOR_WHITE
));
993 fNumButton
.addSelectionListener(new SelectionAdapter() {
995 public void widgetSelected(SelectionEvent e
) {
996 if (fNumButton
.getSelection()) {
997 fNode
.setType(Type
.NUM
);
999 fViewer
.refresh(fNode
);
1003 fAlphaButton
= new Button(typeGroup
, SWT
.RADIO
);
1004 fAlphaButton
.setSelection(fNode
.getType() == Type
.ALPHA
);
1005 fAlphaButton
.setText(Messages
.FilterViewer_AlphaButtonText
);
1006 fAlphaButton
.setBackground(Display
.getCurrent().getSystemColor(SWT
.COLOR_WHITE
));
1007 fAlphaButton
.addSelectionListener(new SelectionAdapter() {
1009 public void widgetSelected(SelectionEvent e
) {
1010 if (fAlphaButton
.getSelection()) {
1011 fNode
.setType(Type
.ALPHA
);
1013 fViewer
.refresh(fNode
);
1017 fTimestampButton
= new Button(typeGroup
, SWT
.RADIO
);
1018 fTimestampButton
.setSelection(fNode
.getType() == Type
.TIMESTAMP
);
1019 fTimestampButton
.setText(Messages
.FilterViewer_TimestampButtonText
);
1020 fTimestampButton
.setBackground(Display
.getCurrent().getSystemColor(SWT
.COLOR_WHITE
));
1021 fTimestampButton
.addSelectionListener(new SelectionAdapter() {
1023 public void widgetSelected(SelectionEvent e
) {
1024 if (fTimestampButton
.getSelection()) {
1025 fNode
.setType(Type
.TIMESTAMP
);
1027 fViewer
.refresh(fNode
);
1031 label
= new Label(this, SWT
.NONE
);
1032 label
.setBackground(Display
.getCurrent().getSystemColor(SWT
.COLOR_WHITE
));
1033 label
.setText(Messages
.FilterViewer_ValueLabel
);
1035 fValueText
= new Text(this, SWT
.BORDER
);
1036 fValueText
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
1037 if (node
.getValue() != null && node
.getValue().length() > 0) {
1038 fValueText
.setText(node
.getValue());
1040 fValueText
.setForeground(Display
.getCurrent().getSystemColor(SWT
.COLOR_GRAY
));
1041 fValueText
.setText(Messages
.FilterViewer_ValueHint
);
1043 fValueText
.addFocusListener(new FocusListener() {
1045 public void focusLost(FocusEvent e
) {
1046 if (fNode
.getValue() == null || fNode
.getValue().length() == 0) {
1047 fValueText
.setForeground(Display
.getCurrent().getSystemColor(SWT
.COLOR_GRAY
));
1048 fValueText
.setText(Messages
.FilterViewer_ValueHint
);
1052 public void focusGained(FocusEvent e
) {
1053 if (fValueText
.getForeground().equals(Display
.getCurrent().getSystemColor(SWT
.COLOR_GRAY
))) {
1054 fValueText
.setText(""); //$NON-NLS-1$
1056 fValueText
.setForeground(Display
.getCurrent().getSystemColor(SWT
.COLOR_BLACK
));
1059 fValueText
.addModifyListener(new ModifyListener() {
1061 public void modifyText(ModifyEvent e
) {
1062 if (! fValueText
.getForeground().equals(Display
.getCurrent().getSystemColor(SWT
.COLOR_GRAY
))) {
1063 fNode
.setValue(fValueText
.getText());
1064 fViewer
.refresh(fNode
);