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
.TmfEvent
;
34 import org
.eclipse
.linuxtools
.tmf
.core
.event
.TmfEventType
;
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
.TmfFilterContainsNode
;
39 import org
.eclipse
.linuxtools
.tmf
.core
.filter
.model
.TmfFilterEqualsNode
;
40 import org
.eclipse
.linuxtools
.tmf
.core
.filter
.model
.TmfFilterEventTypeNode
;
41 import org
.eclipse
.linuxtools
.tmf
.core
.filter
.model
.TmfFilterMatchesNode
;
42 import org
.eclipse
.linuxtools
.tmf
.core
.filter
.model
.TmfFilterNode
;
43 import org
.eclipse
.linuxtools
.tmf
.core
.filter
.model
.TmfFilterOrNode
;
44 import org
.eclipse
.linuxtools
.tmf
.core
.filter
.model
.TmfFilterRootNode
;
45 import org
.eclipse
.linuxtools
.tmf
.core
.filter
.model
.TmfFilterCompareNode
.Type
;
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
.CustomTxtTrace
;
51 import org
.eclipse
.linuxtools
.tmf
.ui
.parsers
.custom
.CustomTxtTraceDefinition
;
52 import org
.eclipse
.linuxtools
.tmf
.ui
.parsers
.custom
.CustomXmlEvent
;
53 import org
.eclipse
.linuxtools
.tmf
.ui
.parsers
.custom
.CustomXmlTrace
;
54 import org
.eclipse
.linuxtools
.tmf
.ui
.parsers
.custom
.CustomXmlTraceDefinition
;
55 import org
.eclipse
.swt
.SWT
;
56 import org
.eclipse
.swt
.custom
.SashForm
;
57 import org
.eclipse
.swt
.events
.FocusEvent
;
58 import org
.eclipse
.swt
.events
.FocusListener
;
59 import org
.eclipse
.swt
.events
.ModifyEvent
;
60 import org
.eclipse
.swt
.events
.ModifyListener
;
61 import org
.eclipse
.swt
.events
.SelectionAdapter
;
62 import org
.eclipse
.swt
.events
.SelectionEvent
;
63 import org
.eclipse
.swt
.layout
.FillLayout
;
64 import org
.eclipse
.swt
.layout
.GridData
;
65 import org
.eclipse
.swt
.layout
.GridLayout
;
66 import org
.eclipse
.swt
.widgets
.Button
;
67 import org
.eclipse
.swt
.widgets
.Combo
;
68 import org
.eclipse
.swt
.widgets
.Composite
;
69 import org
.eclipse
.swt
.widgets
.Control
;
70 import org
.eclipse
.swt
.widgets
.Display
;
71 import org
.eclipse
.swt
.widgets
.Label
;
72 import org
.eclipse
.swt
.widgets
.Menu
;
73 import org
.eclipse
.swt
.widgets
.Text
;
74 import org
.eclipse
.swt
.widgets
.TreeItem
;
76 class FilterViewer
extends Composite
{
78 private static final String CUSTOM_TXT_CATEGORY
= "Custom Text"; //$NON-NLS-1$
79 private static final String CUSTOM_XML_CATEGORY
= "Custom XML"; //$NON-NLS-1$
81 private TreeViewer fViewer
;
82 private Composite fComposite
;
84 public FilterViewer(Composite parent
, int style
) {
87 setLayout(new FillLayout());
88 GridData gd
= new GridData(SWT
.FILL
, SWT
.FILL
, true, true);
91 final SashForm sash
= new SashForm(this, SWT
.HORIZONTAL
);
93 // Create the tree viewer to display the filter tree
94 fViewer
= new TreeViewer(sash
, SWT
.NONE
);
95 fViewer
.setContentProvider(new FilterTreeContentProvider());
96 fViewer
.setLabelProvider(new FilterTreeLabelProvider());
97 fViewer
.setInput(new TmfFilterRootNode());
99 // Create the empty filter node properties panel
100 fComposite
= new Composite(sash
, SWT
.NONE
);
101 GridLayout gl
= new GridLayout();
104 fComposite
.setLayout(gl
);
108 fViewer
.addSelectionChangedListener(new ISelectionChangedListener() {
110 public void selectionChanged(SelectionChangedEvent event
) {
111 if (!(event
.getSelection().isEmpty()) && event
.getSelection() instanceof IStructuredSelection
) {
112 // Update the filter node properties panel to the selection
113 IStructuredSelection selection
= (IStructuredSelection
) event
.getSelection();
114 ITmfFilterTreeNode node
= (ITmfFilterTreeNode
) selection
.getFirstElement();
115 updateFilterNodeComposite(node
);
116 // Highlight the selection's children
117 highlightTreeItems(fViewer
.getTree().getSelection()[0].getItems());
119 updateFilterNodeComposite(null);
126 * Create the context menu for the tree viewer
128 private void createContextMenu() {
129 // Adds root context menu
130 MenuManager menuManager
= new MenuManager();
131 menuManager
.setRemoveAllWhenShown(true);
132 menuManager
.addMenuListener(new IMenuListener() {
134 public void menuAboutToShow(IMenuManager manager
) {
135 fillContextMenu(manager
);
140 Menu contextMenu
= menuManager
.createContextMenu(fViewer
.getTree());
143 fViewer
.getTree().setMenu(contextMenu
);
147 * Fill the context menu for the tree viewer
149 protected void fillContextMenu(IMenuManager manager
) {
150 final ISelection selection
= fViewer
.getSelection();
151 ITmfFilterTreeNode filterTreeNode
= null;
152 if (selection
instanceof StructuredSelection
) {
153 Object element
= ((StructuredSelection
) selection
).getFirstElement();
154 if (element
instanceof ITmfFilterTreeNode
) {
155 filterTreeNode
= (ITmfFilterTreeNode
) element
;
159 final ITmfFilterTreeNode selectedNode
= filterTreeNode
;
161 if (selectedNode
!= null) {
163 fillContextMenuForNode(selectedNode
, manager
);
165 if (selectedNode
.getValidChildren().size() > 0) {
166 manager
.add(new Separator());
169 Action deleteAction
= new Action() {
172 selectedNode
.remove();
176 deleteAction
.setText(Messages
.FilterViewer_DeleteActionText
);
177 manager
.add(deleteAction
);
179 manager
.add(new Separator());
182 if (fViewer
.getInput() instanceof TmfFilterRootNode
|| selectedNode
== null) {
183 final ITmfFilterTreeNode root
= (ITmfFilterTreeNode
) fViewer
.getInput();
185 fillContextMenuForNode(root
, manager
);
190 * Fill the context menu with the valid children of the provided node
192 protected void fillContextMenuForNode(final ITmfFilterTreeNode node
, IMenuManager manager
) {
193 for (final String child
: node
.getValidChildren()) {
194 final Action action
= new Action() {
197 ITmfFilterTreeNode newNode
= null;
198 if (TmfFilterNode
.NODE_NAME
.equals(child
)) {
199 newNode
= new TmfFilterNode(node
, ""); //$NON-NLS-1$
200 } else if (TmfFilterEventTypeNode
.NODE_NAME
.equals(child
)) {
201 newNode
= new TmfFilterEventTypeNode(node
);
202 } else if (TmfFilterAndNode
.NODE_NAME
.equals(child
)) {
203 newNode
= new TmfFilterAndNode(node
);
204 } else if (TmfFilterOrNode
.NODE_NAME
.equals(child
)) {
205 newNode
= new TmfFilterOrNode(node
);
206 } else if (TmfFilterContainsNode
.NODE_NAME
.equals(child
)) {
207 newNode
= new TmfFilterContainsNode(node
);
208 } else if (TmfFilterEqualsNode
.NODE_NAME
.equals(child
)) {
209 newNode
= new TmfFilterEqualsNode(node
);
210 } else if (TmfFilterMatchesNode
.NODE_NAME
.equals(child
)) {
211 newNode
= new TmfFilterMatchesNode(node
);
212 } else if (TmfFilterCompareNode
.NODE_NAME
.equals(child
)) {
213 newNode
= new TmfFilterCompareNode(node
);
215 if (newNode
!= null) {
217 fViewer
.setSelection(new StructuredSelection(newNode
), true);
221 if (TmfFilterNode
.NODE_NAME
.equals(child
)) {
222 action
.setText(Messages
.FilterViewer_NewPrefix
+ " " + child
); //$NON-NLS-1$
224 action
.setText(child
);
231 * Create the appropriate filter node properties composite
233 private void updateFilterNodeComposite(ITmfFilterTreeNode node
) {
234 for (Control control
: fComposite
.getChildren()) {
238 if (node
instanceof TmfFilterNode
) {
239 new FilterNodeComposite(fComposite
, (TmfFilterNode
) node
);
240 } else if (node
instanceof TmfFilterEventTypeNode
) {
241 new FilterEventTypeNodeComposite(fComposite
, (TmfFilterEventTypeNode
) node
);
242 } else if (node
instanceof TmfFilterAndNode
) {
243 new FilterAndNodeComposite(fComposite
, (TmfFilterAndNode
) node
);
244 } else if (node
instanceof TmfFilterOrNode
) {
245 new FilterOrNodeComposite(fComposite
, (TmfFilterOrNode
) node
);
246 } else if (node
instanceof TmfFilterContainsNode
) {
247 new FilterContainsNodeComposite(fComposite
, (TmfFilterContainsNode
) node
);
248 } else if (node
instanceof TmfFilterEqualsNode
) {
249 new FilterEqualsNodeComposite(fComposite
, (TmfFilterEqualsNode
) node
);
250 } else if (node
instanceof TmfFilterMatchesNode
) {
251 new FilterMatchesNodeComposite(fComposite
, (TmfFilterMatchesNode
) node
);
252 } else if (node
instanceof TmfFilterCompareNode
) {
253 new FilterCompareNodeComposite(fComposite
, (TmfFilterCompareNode
) node
);
255 new FilterBaseNodeComposite(fComposite
);
261 * Highlight the provided tree items
263 private void highlightTreeItems(TreeItem
[] items
) {
264 resetTreeItems(fViewer
.getTree().getItems());
265 for (TreeItem item
: items
) {
266 item
.setForeground(Display
.getCurrent().getSystemColor(SWT
.COLOR_BLUE
));
272 * Reset the provided tree items (remove highlight)
274 private void resetTreeItems(TreeItem
[] items
) {
275 for (TreeItem item
: items
) {
276 item
.setForeground(Display
.getCurrent().getSystemColor(SWT
.COLOR_BLACK
));
277 resetTreeItems(item
.getItems());
281 public void setInput(ITmfFilterTreeNode root
) {
282 fViewer
.setInput(root
);
285 updateFilterNodeComposite(null);
288 public ITmfFilterTreeNode
getInput() {
289 return (ITmfFilterTreeNode
) fViewer
.getInput();
292 public void refresh() {
296 public void setSelection(ITmfFilterTreeNode node
, boolean reveal
) {
297 fViewer
.setSelection(new StructuredSelection(node
), reveal
);
300 public void setSelection(ITmfFilterTreeNode node
) {
301 fViewer
.setSelection(new StructuredSelection(node
));
304 public ITmfFilterTreeNode
getSelection() {
305 final ISelection selection
= fViewer
.getSelection();
306 ITmfFilterTreeNode filterTreeNode
= null;
307 if (selection
instanceof StructuredSelection
) {
308 Object element
= ((StructuredSelection
) selection
).getFirstElement();
309 if (element
instanceof ITmfFilterTreeNode
) {
310 filterTreeNode
= (ITmfFilterTreeNode
) element
;
314 final ITmfFilterTreeNode selectedNode
= filterTreeNode
;
318 public void addSelectionChangedListener(ISelectionChangedListener listener
) {
319 fViewer
.addSelectionChangedListener(listener
);
322 public void removeSelectionChangedListener(ISelectionChangedListener listener
) {
323 fViewer
.removeSelectionChangedListener(listener
);
326 private class FilterBaseNodeComposite
extends Composite
{
328 FilterBaseNodeComposite(Composite parent
) {
329 super(parent
, SWT
.NONE
);
330 setLayout(new GridLayout(2, false));
331 setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
332 setBackground(Display
.getCurrent().getSystemColor(SWT
.COLOR_WHITE
));
335 protected String
[] getFieldsList(ITmfFilterTreeNode node
) {
336 ArrayList
<String
> fieldsList
= new ArrayList
<String
>();
337 while (node
!= null) {
338 if (node
instanceof TmfFilterEventTypeNode
) {
339 TmfFilterEventTypeNode eventTypeNode
= (TmfFilterEventTypeNode
) node
;
340 for (IConfigurationElement ce
: TmfTraceType
.getTypeElements()) {
341 if (ce
.getAttribute(TmfTraceType
.EVENT_TYPE_ATTR
).equals(eventTypeNode
.getEventType())) {
343 TmfEvent event
= (TmfEvent
) ce
.createExecutableExtension(TmfTraceType
.EVENT_TYPE_ATTR
);
344 TmfEventType eventType
= event
.getType();
345 if (eventType
!= null) {
346 for (String field
: eventType
.getLabels()) {
347 fieldsList
.add(field
);
350 } catch (CoreException e
) {
352 return fieldsList
.toArray(new String
[0]);
355 if (eventTypeNode
.getEventType().startsWith(CustomTxtEvent
.class.getCanonicalName())) {
356 for (CustomTxtTraceDefinition def
: CustomTxtTraceDefinition
.loadAll()) {
357 if (eventTypeNode
.getEventType().equals(CustomTxtEvent
.class.getCanonicalName() + ":" + def
.definitionName
)) { //$NON-NLS-1$
358 for (OutputColumn output
: def
.outputs
) {
359 fieldsList
.add(output
.name
);
361 return fieldsList
.toArray(new String
[0]);
365 if (eventTypeNode
.getEventType().startsWith(CustomXmlEvent
.class.getCanonicalName())) {
366 for (CustomXmlTraceDefinition def
: CustomXmlTraceDefinition
.loadAll()) {
367 if (eventTypeNode
.getEventType().equals(CustomXmlEvent
.class.getCanonicalName() + ":" + def
.definitionName
)) { //$NON-NLS-1$
368 for (OutputColumn output
: def
.outputs
) {
369 fieldsList
.add(output
.name
);
371 return fieldsList
.toArray(new String
[0]);
376 node
= node
.getParent();
378 for (IConfigurationElement ce
: TmfTraceType
.getTypeElements()) {
380 TmfEvent event
= (TmfEvent
) ce
.createExecutableExtension(TmfTraceType
.EVENT_TYPE_ATTR
);
381 TmfEventType eventType
= event
.getType();
382 if (eventType
!= null) {
383 fieldsList
.add("[" + TmfTraceType
.getCategoryName(ce
.getAttribute(TmfTraceType
.CATEGORY_ATTR
)) + //$NON-NLS-1$
384 " : " + ce
.getAttribute(TmfTraceType
.NAME_ATTR
) + "]"); //$NON-NLS-1$ //$NON-NLS-2$
385 for (String field
: eventType
.getLabels()) {
386 fieldsList
.add(field
);
388 fieldsList
.add(""); //$NON-NLS-1$
390 } catch (CoreException e
) {
393 for (CustomTxtTraceDefinition def
: CustomTxtTraceDefinition
.loadAll()) {
394 fieldsList
.add("[" + CUSTOM_TXT_CATEGORY
+ //$NON-NLS-1$
395 " : " + def
.definitionName
+ "]"); //$NON-NLS-1$ //$NON-NLS-2$
396 for (OutputColumn output
: def
.outputs
) {
397 fieldsList
.add(output
.name
);
399 fieldsList
.add(""); //$NON-NLS-1$
401 for (CustomXmlTraceDefinition def
: CustomXmlTraceDefinition
.loadAll()) {
402 fieldsList
.add("[" + CUSTOM_XML_CATEGORY
+ //$NON-NLS-1$
403 " : " + def
.definitionName
+ "]"); //$NON-NLS-1$ //$NON-NLS-2$
404 for (OutputColumn output
: def
.outputs
) {
405 fieldsList
.add(output
.name
);
407 fieldsList
.add(""); //$NON-NLS-1$
409 return fieldsList
.toArray(new String
[0]);
413 private class FilterNodeComposite
extends FilterBaseNodeComposite
{
417 FilterNodeComposite(Composite parent
, TmfFilterNode node
) {
421 Label label
= new Label(this, SWT
.NONE
);
422 label
.setBackground(Display
.getCurrent().getSystemColor(SWT
.COLOR_WHITE
));
423 label
.setText(Messages
.FilterViewer_NameLabel
);
425 fNameText
= new Text(this, SWT
.BORDER
);
426 fNameText
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
427 if (node
.getFilterName() != null && node
.getFilterName().length() > 0) {
428 fNameText
.setText(node
.getFilterName());
430 fNameText
.setForeground(Display
.getCurrent().getSystemColor(SWT
.COLOR_GRAY
));
431 fNameText
.setText(Messages
.FilterViewer_FilterNameHint
);
433 fNameText
.addFocusListener(new FocusListener() {
435 public void focusLost(FocusEvent e
) {
436 if (fNode
.getFilterName() == null || fNode
.getFilterName().length() == 0) {
437 fNameText
.setForeground(Display
.getCurrent().getSystemColor(SWT
.COLOR_GRAY
));
438 fNameText
.setText(Messages
.FilterViewer_FilterNameHint
);
442 public void focusGained(FocusEvent e
) {
443 if (fNameText
.getForeground().equals(Display
.getCurrent().getSystemColor(SWT
.COLOR_GRAY
))) {
444 fNameText
.setText(""); //$NON-NLS-1$
446 fNameText
.setForeground(Display
.getCurrent().getSystemColor(SWT
.COLOR_BLACK
));
449 fNameText
.addModifyListener(new ModifyListener() {
451 public void modifyText(ModifyEvent e
) {
452 if (! fNameText
.getForeground().equals(Display
.getCurrent().getSystemColor(SWT
.COLOR_GRAY
))) {
453 fNode
.setFilterName(fNameText
.getText());
454 fViewer
.refresh(fNode
);
461 private class FilterEventTypeNodeComposite
extends FilterBaseNodeComposite
{
462 TmfFilterEventTypeNode fNode
;
464 Map
<String
, Object
> fEventsTypeMap
;
466 FilterEventTypeNodeComposite(Composite parent
, TmfFilterEventTypeNode node
) {
469 fEventsTypeMap
= getEventsTypeMap();
471 Label label
= new Label(this, SWT
.NONE
);
472 label
.setBackground(Display
.getCurrent().getSystemColor(SWT
.COLOR_WHITE
));
473 label
.setText(Messages
.FilterViewer_TypeLabel
);
475 fTypeCombo
= new Combo(this, SWT
.DROP_DOWN
| SWT
.READ_ONLY
);
476 fTypeCombo
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
477 fTypeCombo
.setItems(fEventsTypeMap
.keySet().toArray(new String
[0]));
478 if (fNode
.getEventType() != null) {
479 for (Entry
<String
, Object
> eventTypeEntry
: fEventsTypeMap
.entrySet()) {
480 Object value
= eventTypeEntry
.getValue();
481 if (value
instanceof IConfigurationElement
) {
482 IConfigurationElement ce
= (IConfigurationElement
) value
;
483 if (ce
.getAttribute(TmfTraceType
.EVENT_TYPE_ATTR
).equals(fNode
.getEventType())) {
484 fTypeCombo
.setText(eventTypeEntry
.getKey());
486 } else if (value
instanceof CustomTxtTraceDefinition
) {
487 CustomTxtTraceDefinition def
= (CustomTxtTraceDefinition
) value
;
488 String eventType
= CustomTxtEvent
.class.getCanonicalName() + ":" + def
.definitionName
; //$NON-NLS-1$
489 if (eventType
.equals(fNode
.getEventType())) {
490 fTypeCombo
.setText(eventTypeEntry
.getKey());
492 } else if (value
instanceof CustomXmlTraceDefinition
) {
493 CustomXmlTraceDefinition def
= (CustomXmlTraceDefinition
) value
;
494 String eventType
= CustomXmlEvent
.class.getCanonicalName() + ":" + def
.definitionName
; //$NON-NLS-1$
495 if (eventType
.equals(fNode
.getEventType())) {
496 fTypeCombo
.setText(eventTypeEntry
.getKey());
501 fTypeCombo
.addModifyListener(new ModifyListener() {
503 public void modifyText(ModifyEvent e
) {
504 for (Entry
<String
, Object
> eventTypeEntry
: fEventsTypeMap
.entrySet()) {
505 if (eventTypeEntry
.getKey().equals(fTypeCombo
.getText())) {
506 Object value
= eventTypeEntry
.getValue();
507 if (value
instanceof IConfigurationElement
) {
508 IConfigurationElement ce
= (IConfigurationElement
) value
;
509 fNode
.setEventType(ce
.getAttribute(TmfTraceType
.EVENT_TYPE_ATTR
));
510 fNode
.setName(ce
.getAttribute(TmfTraceType
.NAME_ATTR
));
511 } else if (value
instanceof CustomTxtTraceDefinition
) {
512 CustomTxtTraceDefinition def
= (CustomTxtTraceDefinition
) value
;
513 fNode
.setEventType(CustomTxtEvent
.class.getCanonicalName() + ":" + def
.definitionName
); //$NON-NLS-1$
514 fNode
.setName(def
.definitionName
);
515 } else if (value
instanceof CustomXmlTraceDefinition
) {
516 CustomXmlTraceDefinition def
= (CustomXmlTraceDefinition
) value
;
517 fNode
.setEventType(CustomXmlEvent
.class.getCanonicalName() + ":" + def
.definitionName
); //$NON-NLS-1$
518 fNode
.setName(def
.definitionName
);
520 fViewer
.refresh(fNode
);
528 protected Map
<String
, Object
> getEventsTypeMap() {
529 Map
<String
, Object
> eventsTypeMap
= new LinkedHashMap
<String
, Object
>();
530 for (IConfigurationElement ce
: TmfTraceType
.getTypeElements()) {
531 String categoryName
= TmfTraceType
.getCategoryName(ce
.getAttribute(TmfTraceType
.CATEGORY_ATTR
));
532 String text
= categoryName
+ " : " + ce
.getAttribute(TmfTraceType
.NAME_ATTR
); //$NON-NLS-1$
533 eventsTypeMap
.put(text
, ce
);
535 for (CustomTxtTraceDefinition def
: CustomTxtTraceDefinition
.loadAll()) {
536 String text
= CUSTOM_TXT_CATEGORY
+ " : " + def
.definitionName
; //$NON-NLS-1$
537 eventsTypeMap
.put(text
, def
);
539 for (CustomXmlTraceDefinition def
: CustomXmlTraceDefinition
.loadAll()) {
540 String text
= CUSTOM_XML_CATEGORY
+ " : " + def
.definitionName
; //$NON-NLS-1$
541 eventsTypeMap
.put(text
, def
);
543 return eventsTypeMap
;
547 private class FilterAndNodeComposite
extends FilterBaseNodeComposite
{
548 TmfFilterAndNode fNode
;
551 FilterAndNodeComposite(Composite parent
, TmfFilterAndNode node
) {
555 Label label
= new Label(this, SWT
.NONE
);
556 label
.setBackground(Display
.getCurrent().getSystemColor(SWT
.COLOR_WHITE
));
557 label
.setText(Messages
.FilterViewer_NotLabel
);
559 fNotButton
= new Button(this, SWT
.CHECK
);
560 fNotButton
.setBackground(Display
.getCurrent().getSystemColor(SWT
.COLOR_WHITE
));
561 fNotButton
.setSelection(fNode
.isNot());
562 fNotButton
.addSelectionListener(new SelectionAdapter() {
564 public void widgetSelected(SelectionEvent e
) {
565 fNode
.setNot(fNotButton
.getSelection());
566 fViewer
.refresh(fNode
);
572 private class FilterOrNodeComposite
extends FilterBaseNodeComposite
{
573 TmfFilterOrNode fNode
;
576 FilterOrNodeComposite(Composite parent
, TmfFilterOrNode node
) {
580 Label label
= new Label(this, SWT
.NONE
);
581 label
.setBackground(Display
.getCurrent().getSystemColor(SWT
.COLOR_WHITE
));
582 label
.setText(Messages
.FilterViewer_NotLabel
);
584 fNotButton
= new Button(this, SWT
.CHECK
);
585 fNotButton
.setBackground(Display
.getCurrent().getSystemColor(SWT
.COLOR_WHITE
));
586 fNotButton
.setSelection(fNode
.isNot());
587 fNotButton
.addSelectionListener(new SelectionAdapter() {
589 public void widgetSelected(SelectionEvent e
) {
590 fNode
.setNot(fNotButton
.getSelection());
591 fViewer
.refresh(fNode
);
597 private class FilterContainsNodeComposite
extends FilterBaseNodeComposite
{
598 TmfFilterContainsNode fNode
;
602 Button fIgnoreCaseButton
;
604 FilterContainsNodeComposite(Composite parent
, TmfFilterContainsNode node
) {
608 Label label
= new Label(this, SWT
.NONE
);
609 label
.setBackground(Display
.getCurrent().getSystemColor(SWT
.COLOR_WHITE
));
610 label
.setText(Messages
.FilterViewer_NotLabel
);
612 fNotButton
= new Button(this, SWT
.CHECK
);
613 fNotButton
.setBackground(Display
.getCurrent().getSystemColor(SWT
.COLOR_WHITE
));
614 fNotButton
.setSelection(fNode
.isNot());
615 fNotButton
.addSelectionListener(new SelectionAdapter() {
617 public void widgetSelected(SelectionEvent e
) {
618 fNode
.setNot(fNotButton
.getSelection());
619 fViewer
.refresh(fNode
);
623 label
= new Label(this, SWT
.NONE
);
624 label
.setBackground(Display
.getCurrent().getSystemColor(SWT
.COLOR_WHITE
));
625 label
.setText(Messages
.FilterViewer_FieldLabel
);
627 fFieldCombo
= new Combo(this, SWT
.DROP_DOWN
);
628 fFieldCombo
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
629 fFieldCombo
.setItems(getFieldsList(fNode
));
630 if (fNode
.getField() != null) {
631 fFieldCombo
.setText(fNode
.getField());
633 fFieldCombo
.addModifyListener(new ModifyListener() {
635 public void modifyText(ModifyEvent e
) {
636 fNode
.setField(fFieldCombo
.getText());
637 fViewer
.refresh(fNode
);
641 label
= new Label(this, SWT
.NONE
);
642 label
.setBackground(Display
.getCurrent().getSystemColor(SWT
.COLOR_WHITE
));
643 label
.setText(Messages
.FilterViewer_ValueLabel
);
645 fValueText
= new Text(this, SWT
.BORDER
);
646 fValueText
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
647 if (node
.getValue() != null && node
.getValue().length() > 0) {
648 fValueText
.setText(node
.getValue());
650 fValueText
.setForeground(Display
.getCurrent().getSystemColor(SWT
.COLOR_GRAY
));
651 fValueText
.setText(Messages
.FilterViewer_ValueHint
);
653 fValueText
.addFocusListener(new FocusListener() {
655 public void focusLost(FocusEvent e
) {
656 if (fNode
.getValue() == null || fNode
.getValue().length() == 0) {
657 fValueText
.setForeground(Display
.getCurrent().getSystemColor(SWT
.COLOR_GRAY
));
658 fValueText
.setText(Messages
.FilterViewer_ValueHint
);
662 public void focusGained(FocusEvent e
) {
663 if (fValueText
.getForeground().equals(Display
.getCurrent().getSystemColor(SWT
.COLOR_GRAY
))) {
664 fValueText
.setText(""); //$NON-NLS-1$
666 fValueText
.setForeground(Display
.getCurrent().getSystemColor(SWT
.COLOR_BLACK
));
669 fValueText
.addModifyListener(new ModifyListener() {
671 public void modifyText(ModifyEvent e
) {
672 if (! fValueText
.getForeground().equals(Display
.getCurrent().getSystemColor(SWT
.COLOR_GRAY
))) {
673 fNode
.setValue(fValueText
.getText());
674 fViewer
.refresh(fNode
);
679 label
= new Label(this, SWT
.NONE
);
680 label
.setBackground(Display
.getCurrent().getSystemColor(SWT
.COLOR_WHITE
));
682 fIgnoreCaseButton
= new Button(this, SWT
.CHECK
);
683 fIgnoreCaseButton
.setSelection(fNode
.isIgnoreCase());
684 fIgnoreCaseButton
.setText(Messages
.FilterViewer_IgnoreCaseButtonText
);
685 fIgnoreCaseButton
.setBackground(Display
.getCurrent().getSystemColor(SWT
.COLOR_WHITE
));
686 fIgnoreCaseButton
.addSelectionListener(new SelectionAdapter() {
688 public void widgetSelected(SelectionEvent e
) {
689 fNode
.setIgnoreCase(fIgnoreCaseButton
.getSelection());
690 fViewer
.refresh(fNode
);
696 private class FilterEqualsNodeComposite
extends FilterBaseNodeComposite
{
697 TmfFilterEqualsNode fNode
;
701 Button fIgnoreCaseButton
;
703 FilterEqualsNodeComposite(Composite parent
, TmfFilterEqualsNode node
) {
707 Label label
= new Label(this, SWT
.NONE
);
708 label
.setBackground(Display
.getCurrent().getSystemColor(SWT
.COLOR_WHITE
));
709 label
.setText(Messages
.FilterViewer_NotLabel
);
711 fNotButton
= new Button(this, SWT
.CHECK
);
712 fNotButton
.setBackground(Display
.getCurrent().getSystemColor(SWT
.COLOR_WHITE
));
713 fNotButton
.setSelection(fNode
.isNot());
714 fNotButton
.addSelectionListener(new SelectionAdapter() {
716 public void widgetSelected(SelectionEvent e
) {
717 fNode
.setNot(fNotButton
.getSelection());
718 fViewer
.refresh(fNode
);
722 label
= new Label(this, SWT
.NONE
);
723 label
.setBackground(Display
.getCurrent().getSystemColor(SWT
.COLOR_WHITE
));
724 label
.setText(Messages
.FilterViewer_FieldLabel
);
726 fFieldCombo
= new Combo(this, SWT
.DROP_DOWN
);
727 fFieldCombo
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
728 fFieldCombo
.setItems(getFieldsList(fNode
));
729 if (fNode
.getField() != null) {
730 fFieldCombo
.setText(fNode
.getField());
732 fFieldCombo
.addModifyListener(new ModifyListener() {
734 public void modifyText(ModifyEvent e
) {
735 fNode
.setField(fFieldCombo
.getText());
736 fViewer
.refresh(fNode
);
740 label
= new Label(this, SWT
.NONE
);
741 label
.setBackground(Display
.getCurrent().getSystemColor(SWT
.COLOR_WHITE
));
742 label
.setText(Messages
.FilterViewer_ValueLabel
);
744 fValueText
= new Text(this, SWT
.BORDER
);
745 fValueText
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
746 if (node
.getValue() != null && node
.getValue().length() > 0) {
747 fValueText
.setText(node
.getValue());
749 fValueText
.setForeground(Display
.getCurrent().getSystemColor(SWT
.COLOR_GRAY
));
750 fValueText
.setText(Messages
.FilterViewer_ValueHint
);
752 fValueText
.addFocusListener(new FocusListener() {
754 public void focusLost(FocusEvent e
) {
755 if (fNode
.getValue() == null || fNode
.getValue().length() == 0) {
756 fValueText
.setForeground(Display
.getCurrent().getSystemColor(SWT
.COLOR_GRAY
));
757 fValueText
.setText(Messages
.FilterViewer_ValueHint
);
761 public void focusGained(FocusEvent e
) {
762 if (fValueText
.getForeground().equals(Display
.getCurrent().getSystemColor(SWT
.COLOR_GRAY
))) {
763 fValueText
.setText(""); //$NON-NLS-1$
765 fValueText
.setForeground(Display
.getCurrent().getSystemColor(SWT
.COLOR_BLACK
));
768 fValueText
.addModifyListener(new ModifyListener() {
770 public void modifyText(ModifyEvent e
) {
771 if (! fValueText
.getForeground().equals(Display
.getCurrent().getSystemColor(SWT
.COLOR_GRAY
))) {
772 fNode
.setValue(fValueText
.getText());
773 fViewer
.refresh(fNode
);
778 label
= new Label(this, SWT
.NONE
);
779 label
.setBackground(Display
.getCurrent().getSystemColor(SWT
.COLOR_WHITE
));
781 fIgnoreCaseButton
= new Button(this, SWT
.CHECK
);
782 fIgnoreCaseButton
.setSelection(fNode
.isIgnoreCase());
783 fIgnoreCaseButton
.setText(Messages
.FilterViewer_IgnoreCaseButtonText
);
784 fIgnoreCaseButton
.setBackground(Display
.getCurrent().getSystemColor(SWT
.COLOR_WHITE
));
785 fIgnoreCaseButton
.addSelectionListener(new SelectionAdapter() {
787 public void widgetSelected(SelectionEvent e
) {
788 fNode
.setIgnoreCase(fIgnoreCaseButton
.getSelection());
789 fViewer
.refresh(fNode
);
795 private class FilterMatchesNodeComposite
extends FilterBaseNodeComposite
{
796 TmfFilterMatchesNode fNode
;
801 FilterMatchesNodeComposite(Composite parent
, TmfFilterMatchesNode node
) {
805 Label label
= new Label(this, SWT
.NONE
);
806 label
.setBackground(Display
.getCurrent().getSystemColor(SWT
.COLOR_WHITE
));
807 label
.setText(Messages
.FilterViewer_NotLabel
);
809 fNotButton
= new Button(this, SWT
.CHECK
);
810 fNotButton
.setBackground(Display
.getCurrent().getSystemColor(SWT
.COLOR_WHITE
));
811 fNotButton
.setSelection(fNode
.isNot());
812 fNotButton
.addSelectionListener(new SelectionAdapter() {
814 public void widgetSelected(SelectionEvent e
) {
815 fNode
.setNot(fNotButton
.getSelection());
816 fViewer
.refresh(fNode
);
820 label
= new Label(this, SWT
.NONE
);
821 label
.setBackground(Display
.getCurrent().getSystemColor(SWT
.COLOR_WHITE
));
822 label
.setText(Messages
.FilterViewer_FieldLabel
);
824 fFieldCombo
= new Combo(this, SWT
.DROP_DOWN
);
825 fFieldCombo
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
826 fFieldCombo
.setItems(getFieldsList(fNode
));
827 if (fNode
.getField() != null) {
828 fFieldCombo
.setText(fNode
.getField());
830 fFieldCombo
.addModifyListener(new ModifyListener() {
832 public void modifyText(ModifyEvent e
) {
833 fNode
.setField(fFieldCombo
.getText());
834 fViewer
.refresh(fNode
);
838 label
= new Label(this, SWT
.NONE
);
839 label
.setBackground(Display
.getCurrent().getSystemColor(SWT
.COLOR_WHITE
));
840 label
.setText(Messages
.FilterViewer_RegexLabel
);
842 fRegexText
= new Text(this, SWT
.BORDER
);
843 fRegexText
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
844 if (node
.getRegex() != null && node
.getRegex().length() > 0) {
845 fRegexText
.setText(node
.getRegex());
847 fRegexText
.setForeground(Display
.getCurrent().getSystemColor(SWT
.COLOR_GRAY
));
848 fRegexText
.setText(Messages
.FilterViewer_RegexHint
);
850 fRegexText
.addFocusListener(new FocusListener() {
852 public void focusLost(FocusEvent e
) {
853 if (fNode
.getRegex() == null || fNode
.getRegex().length() == 0) {
854 fRegexText
.setForeground(Display
.getCurrent().getSystemColor(SWT
.COLOR_GRAY
));
855 fRegexText
.setText(Messages
.FilterViewer_RegexHint
);
859 public void focusGained(FocusEvent e
) {
860 if (fRegexText
.getForeground().equals(Display
.getCurrent().getSystemColor(SWT
.COLOR_GRAY
))) {
861 fRegexText
.setText(""); //$NON-NLS-1$
863 fRegexText
.setForeground(Display
.getCurrent().getSystemColor(SWT
.COLOR_BLACK
));
866 fRegexText
.addModifyListener(new ModifyListener() {
868 public void modifyText(ModifyEvent e
) {
869 if (! fRegexText
.getForeground().equals(Display
.getCurrent().getSystemColor(SWT
.COLOR_GRAY
))) {
870 fNode
.setRegex(fRegexText
.getText());
871 fViewer
.refresh(fNode
);
878 private class FilterCompareNodeComposite
extends FilterBaseNodeComposite
{
879 TmfFilterCompareNode fNode
;
888 Button fTimestampButton
;
890 FilterCompareNodeComposite(Composite parent
, TmfFilterCompareNode node
) {
894 Label label
= new Label(this, SWT
.NONE
);
895 label
.setBackground(Display
.getCurrent().getSystemColor(SWT
.COLOR_WHITE
));
896 label
.setText(Messages
.FilterViewer_NotLabel
);
898 fNotButton
= new Button(this, SWT
.CHECK
);
899 fNotButton
.setBackground(Display
.getCurrent().getSystemColor(SWT
.COLOR_WHITE
));
900 fNotButton
.setSelection(fNode
.isNot());
901 fNotButton
.addSelectionListener(new SelectionAdapter() {
903 public void widgetSelected(SelectionEvent e
) {
904 fNode
.setNot(fNotButton
.getSelection());
905 fViewer
.refresh(fNode
);
909 label
= new Label(this, SWT
.NONE
);
910 label
.setBackground(Display
.getCurrent().getSystemColor(SWT
.COLOR_WHITE
));
911 label
.setText(Messages
.FilterViewer_FieldLabel
);
913 fFieldCombo
= new Combo(this, SWT
.DROP_DOWN
);
914 fFieldCombo
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
915 fFieldCombo
.setItems(getFieldsList(fNode
));
916 if (fNode
.getField() != null) {
917 fFieldCombo
.setText(fNode
.getField());
919 fFieldCombo
.addModifyListener(new ModifyListener() {
921 public void modifyText(ModifyEvent e
) {
922 fNode
.setField(fFieldCombo
.getText());
923 fViewer
.refresh(fNode
);
927 label
= new Label(this, SWT
.NONE
);
928 label
.setBackground(Display
.getCurrent().getSystemColor(SWT
.COLOR_WHITE
));
929 label
.setText(Messages
.FilterViewer_ResultLabel
);
931 Composite resultGroup
= new Composite(this, SWT
.NONE
);
932 GridLayout rggl
= new GridLayout(3, true);
933 rggl
.marginHeight
= 0;
934 rggl
.marginWidth
= 0;
935 resultGroup
.setLayout(rggl
);
936 resultGroup
.setBackground(Display
.getCurrent().getSystemColor(SWT
.COLOR_WHITE
));
938 fLTButton
= new Button(resultGroup
, SWT
.RADIO
);
939 fLTButton
.setSelection(fNode
.getResult() < 0);
940 fLTButton
.setText("<"); //$NON-NLS-1$
941 fLTButton
.setBackground(Display
.getCurrent().getSystemColor(SWT
.COLOR_WHITE
));
942 fLTButton
.addSelectionListener(new SelectionAdapter() {
944 public void widgetSelected(SelectionEvent e
) {
945 if (fLTButton
.getSelection()) {
948 fViewer
.refresh(fNode
);
952 fEQButton
= new Button(resultGroup
, SWT
.RADIO
);
953 fEQButton
.setSelection(fNode
.getResult() == 0);
954 fEQButton
.setText("="); //$NON-NLS-1$
955 fEQButton
.setBackground(Display
.getCurrent().getSystemColor(SWT
.COLOR_WHITE
));
956 fEQButton
.addSelectionListener(new SelectionAdapter() {
958 public void widgetSelected(SelectionEvent e
) {
959 if (fEQButton
.getSelection()) {
962 fViewer
.refresh(fNode
);
966 fGTButton
= new Button(resultGroup
, SWT
.RADIO
);
967 fGTButton
.setSelection(fNode
.getResult() > 0);
968 fGTButton
.setText(">"); //$NON-NLS-1$
969 fGTButton
.setBackground(Display
.getCurrent().getSystemColor(SWT
.COLOR_WHITE
));
970 fGTButton
.addSelectionListener(new SelectionAdapter() {
972 public void widgetSelected(SelectionEvent e
) {
973 if (fGTButton
.getSelection()) {
976 fViewer
.refresh(fNode
);
980 label
= new Label(this, SWT
.NONE
);
981 label
.setBackground(Display
.getCurrent().getSystemColor(SWT
.COLOR_WHITE
));
982 label
.setText(Messages
.FilterViewer_TypeLabel
);
984 Composite typeGroup
= new Composite(this, SWT
.NONE
);
985 GridLayout tggl
= new GridLayout(3, false);
986 tggl
.marginHeight
= 0;
987 tggl
.marginWidth
= 0;
988 typeGroup
.setLayout(tggl
);
989 typeGroup
.setBackground(Display
.getCurrent().getSystemColor(SWT
.COLOR_WHITE
));
991 fNumButton
= new Button(typeGroup
, SWT
.RADIO
);
992 fNumButton
.setSelection(fNode
.getType() == Type
.NUM
);
993 fNumButton
.setText(Messages
.FilterViewer_NumButtonText
);
994 fNumButton
.setBackground(Display
.getCurrent().getSystemColor(SWT
.COLOR_WHITE
));
995 fNumButton
.addSelectionListener(new SelectionAdapter() {
997 public void widgetSelected(SelectionEvent e
) {
998 if (fNumButton
.getSelection()) {
999 fNode
.setType(Type
.NUM
);
1001 fViewer
.refresh(fNode
);
1005 fAlphaButton
= new Button(typeGroup
, SWT
.RADIO
);
1006 fAlphaButton
.setSelection(fNode
.getType() == Type
.ALPHA
);
1007 fAlphaButton
.setText(Messages
.FilterViewer_AlphaButtonText
);
1008 fAlphaButton
.setBackground(Display
.getCurrent().getSystemColor(SWT
.COLOR_WHITE
));
1009 fAlphaButton
.addSelectionListener(new SelectionAdapter() {
1011 public void widgetSelected(SelectionEvent e
) {
1012 if (fAlphaButton
.getSelection()) {
1013 fNode
.setType(Type
.ALPHA
);
1015 fViewer
.refresh(fNode
);
1019 fTimestampButton
= new Button(typeGroup
, SWT
.RADIO
);
1020 fTimestampButton
.setSelection(fNode
.getType() == Type
.TIMESTAMP
);
1021 fTimestampButton
.setText(Messages
.FilterViewer_TimestampButtonText
);
1022 fTimestampButton
.setBackground(Display
.getCurrent().getSystemColor(SWT
.COLOR_WHITE
));
1023 fTimestampButton
.addSelectionListener(new SelectionAdapter() {
1025 public void widgetSelected(SelectionEvent e
) {
1026 if (fTimestampButton
.getSelection()) {
1027 fNode
.setType(Type
.TIMESTAMP
);
1029 fViewer
.refresh(fNode
);
1033 label
= new Label(this, SWT
.NONE
);
1034 label
.setBackground(Display
.getCurrent().getSystemColor(SWT
.COLOR_WHITE
));
1035 label
.setText(Messages
.FilterViewer_ValueLabel
);
1037 fValueText
= new Text(this, SWT
.BORDER
);
1038 fValueText
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
1039 if (node
.getValue() != null && node
.getValue().length() > 0) {
1040 fValueText
.setText(node
.getValue());
1042 fValueText
.setForeground(Display
.getCurrent().getSystemColor(SWT
.COLOR_GRAY
));
1043 fValueText
.setText(Messages
.FilterViewer_ValueHint
);
1045 fValueText
.addFocusListener(new FocusListener() {
1047 public void focusLost(FocusEvent e
) {
1048 if (fNode
.getValue() == null || fNode
.getValue().length() == 0) {
1049 fValueText
.setForeground(Display
.getCurrent().getSystemColor(SWT
.COLOR_GRAY
));
1050 fValueText
.setText(Messages
.FilterViewer_ValueHint
);
1054 public void focusGained(FocusEvent e
) {
1055 if (fValueText
.getForeground().equals(Display
.getCurrent().getSystemColor(SWT
.COLOR_GRAY
))) {
1056 fValueText
.setText(""); //$NON-NLS-1$
1058 fValueText
.setForeground(Display
.getCurrent().getSystemColor(SWT
.COLOR_BLACK
));
1061 fValueText
.addModifyListener(new ModifyListener() {
1063 public void modifyText(ModifyEvent e
) {
1064 if (! fValueText
.getForeground().equals(Display
.getCurrent().getSystemColor(SWT
.COLOR_GRAY
))) {
1065 fNode
.setValue(fValueText
.getText());
1066 fViewer
.refresh(fNode
);