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
.internal
.tmf
.ui
.Messages
;
34 import org
.eclipse
.linuxtools
.internal
.tmf
.ui
.parsers
.custom
.CustomTxtEvent
;
35 import org
.eclipse
.linuxtools
.internal
.tmf
.ui
.parsers
.custom
.CustomTxtTraceDefinition
;
36 import org
.eclipse
.linuxtools
.internal
.tmf
.ui
.parsers
.custom
.CustomXmlEvent
;
37 import org
.eclipse
.linuxtools
.internal
.tmf
.ui
.parsers
.custom
.CustomXmlTraceDefinition
;
38 import org
.eclipse
.linuxtools
.internal
.tmf
.ui
.parsers
.custom
.CustomTraceDefinition
.OutputColumn
;
39 import org
.eclipse
.linuxtools
.tmf
.core
.event
.ITmfEvent
;
40 import org
.eclipse
.linuxtools
.tmf
.core
.event
.ITmfEventType
;
41 import org
.eclipse
.linuxtools
.tmf
.core
.event
.TmfEvent
;
42 import org
.eclipse
.linuxtools
.tmf
.core
.filter
.model
.ITmfFilterTreeNode
;
43 import org
.eclipse
.linuxtools
.tmf
.core
.filter
.model
.TmfFilterAndNode
;
44 import org
.eclipse
.linuxtools
.tmf
.core
.filter
.model
.TmfFilterCompareNode
;
45 import org
.eclipse
.linuxtools
.tmf
.core
.filter
.model
.TmfFilterCompareNode
.Type
;
46 import org
.eclipse
.linuxtools
.tmf
.core
.filter
.model
.TmfFilterContainsNode
;
47 import org
.eclipse
.linuxtools
.tmf
.core
.filter
.model
.TmfFilterEqualsNode
;
48 import org
.eclipse
.linuxtools
.tmf
.core
.filter
.model
.TmfFilterEventTypeNode
;
49 import org
.eclipse
.linuxtools
.tmf
.core
.filter
.model
.TmfFilterMatchesNode
;
50 import org
.eclipse
.linuxtools
.tmf
.core
.filter
.model
.TmfFilterNode
;
51 import org
.eclipse
.linuxtools
.tmf
.core
.filter
.model
.TmfFilterOrNode
;
52 import org
.eclipse
.linuxtools
.tmf
.core
.filter
.model
.TmfFilterRootNode
;
53 import org
.eclipse
.linuxtools
.tmf
.ui
.project
.model
.TmfTraceType
;
54 import org
.eclipse
.swt
.SWT
;
55 import org
.eclipse
.swt
.custom
.SashForm
;
56 import org
.eclipse
.swt
.events
.FocusEvent
;
57 import org
.eclipse
.swt
.events
.FocusListener
;
58 import org
.eclipse
.swt
.events
.ModifyEvent
;
59 import org
.eclipse
.swt
.events
.ModifyListener
;
60 import org
.eclipse
.swt
.events
.SelectionAdapter
;
61 import org
.eclipse
.swt
.events
.SelectionEvent
;
62 import org
.eclipse
.swt
.layout
.FillLayout
;
63 import org
.eclipse
.swt
.layout
.GridData
;
64 import org
.eclipse
.swt
.layout
.GridLayout
;
65 import org
.eclipse
.swt
.widgets
.Button
;
66 import org
.eclipse
.swt
.widgets
.Combo
;
67 import org
.eclipse
.swt
.widgets
.Composite
;
68 import org
.eclipse
.swt
.widgets
.Control
;
69 import org
.eclipse
.swt
.widgets
.Display
;
70 import org
.eclipse
.swt
.widgets
.Label
;
71 import org
.eclipse
.swt
.widgets
.Menu
;
72 import org
.eclipse
.swt
.widgets
.Text
;
73 import org
.eclipse
.swt
.widgets
.TreeItem
;
75 class FilterViewer
extends Composite
{
77 private static final String CUSTOM_TXT_CATEGORY
= "Custom Text"; //$NON-NLS-1$
78 private static final String CUSTOM_XML_CATEGORY
= "Custom XML"; //$NON-NLS-1$
80 private TreeViewer fViewer
;
81 private Composite fComposite
;
83 public FilterViewer(Composite parent
, int style
) {
86 setLayout(new FillLayout());
87 GridData gd
= new GridData(SWT
.FILL
, SWT
.FILL
, true, true);
90 final SashForm sash
= new SashForm(this, SWT
.HORIZONTAL
);
92 // Create the tree viewer to display the filter tree
93 fViewer
= new TreeViewer(sash
, SWT
.NONE
);
94 fViewer
.setContentProvider(new FilterTreeContentProvider());
95 fViewer
.setLabelProvider(new FilterTreeLabelProvider());
96 fViewer
.setInput(new TmfFilterRootNode());
98 // Create the empty filter node properties panel
99 fComposite
= new Composite(sash
, SWT
.NONE
);
100 GridLayout gl
= new GridLayout();
103 fComposite
.setLayout(gl
);
107 fViewer
.addSelectionChangedListener(new ISelectionChangedListener() {
109 public void selectionChanged(SelectionChangedEvent event
) {
110 if (!(event
.getSelection().isEmpty()) && event
.getSelection() instanceof IStructuredSelection
) {
111 // Update the filter node properties panel to the selection
112 IStructuredSelection selection
= (IStructuredSelection
) event
.getSelection();
113 ITmfFilterTreeNode node
= (ITmfFilterTreeNode
) selection
.getFirstElement();
114 updateFilterNodeComposite(node
);
115 // Highlight the selection's children
116 highlightTreeItems(fViewer
.getTree().getSelection()[0].getItems());
118 updateFilterNodeComposite(null);
125 * Create the context menu for the tree viewer
127 private void createContextMenu() {
128 // Adds root context menu
129 MenuManager menuManager
= new MenuManager();
130 menuManager
.setRemoveAllWhenShown(true);
131 menuManager
.addMenuListener(new IMenuListener() {
133 public void menuAboutToShow(IMenuManager manager
) {
134 fillContextMenu(manager
);
139 Menu contextMenu
= menuManager
.createContextMenu(fViewer
.getTree());
142 fViewer
.getTree().setMenu(contextMenu
);
146 * Fill the context menu for the tree viewer
148 protected void fillContextMenu(IMenuManager manager
) {
149 final ISelection selection
= fViewer
.getSelection();
150 ITmfFilterTreeNode filterTreeNode
= null;
151 if (selection
instanceof StructuredSelection
) {
152 Object element
= ((StructuredSelection
) selection
).getFirstElement();
153 if (element
instanceof ITmfFilterTreeNode
) {
154 filterTreeNode
= (ITmfFilterTreeNode
) element
;
158 final ITmfFilterTreeNode selectedNode
= filterTreeNode
;
160 if (selectedNode
!= null) {
162 fillContextMenuForNode(selectedNode
, manager
);
164 if (selectedNode
.getValidChildren().size() > 0) {
165 manager
.add(new Separator());
168 Action deleteAction
= new Action() {
171 selectedNode
.remove();
175 deleteAction
.setText(Messages
.FilterViewer_DeleteActionText
);
176 manager
.add(deleteAction
);
178 manager
.add(new Separator());
181 if (fViewer
.getInput() instanceof TmfFilterRootNode
|| selectedNode
== null) {
182 final ITmfFilterTreeNode root
= (ITmfFilterTreeNode
) fViewer
.getInput();
184 fillContextMenuForNode(root
, manager
);
189 * Fill the context menu with the valid children of the provided node
191 protected void fillContextMenuForNode(final ITmfFilterTreeNode node
, IMenuManager manager
) {
192 for (final String child
: node
.getValidChildren()) {
193 final Action action
= new Action() {
196 ITmfFilterTreeNode newNode
= null;
197 if (TmfFilterNode
.NODE_NAME
.equals(child
)) {
198 newNode
= new TmfFilterNode(node
, ""); //$NON-NLS-1$
199 } else if (TmfFilterEventTypeNode
.NODE_NAME
.equals(child
)) {
200 newNode
= new TmfFilterEventTypeNode(node
);
201 } else if (TmfFilterAndNode
.NODE_NAME
.equals(child
)) {
202 newNode
= new TmfFilterAndNode(node
);
203 } else if (TmfFilterOrNode
.NODE_NAME
.equals(child
)) {
204 newNode
= new TmfFilterOrNode(node
);
205 } else if (TmfFilterContainsNode
.NODE_NAME
.equals(child
)) {
206 newNode
= new TmfFilterContainsNode(node
);
207 } else if (TmfFilterEqualsNode
.NODE_NAME
.equals(child
)) {
208 newNode
= new TmfFilterEqualsNode(node
);
209 } else if (TmfFilterMatchesNode
.NODE_NAME
.equals(child
)) {
210 newNode
= new TmfFilterMatchesNode(node
);
211 } else if (TmfFilterCompareNode
.NODE_NAME
.equals(child
)) {
212 newNode
= new TmfFilterCompareNode(node
);
214 if (newNode
!= null) {
216 fViewer
.setSelection(new StructuredSelection(newNode
), true);
220 if (TmfFilterNode
.NODE_NAME
.equals(child
)) {
221 action
.setText(Messages
.FilterViewer_NewPrefix
+ " " + child
); //$NON-NLS-1$
223 action
.setText(child
);
230 * Create the appropriate filter node properties composite
232 private void updateFilterNodeComposite(ITmfFilterTreeNode node
) {
233 for (Control control
: fComposite
.getChildren()) {
237 if (node
instanceof TmfFilterNode
) {
238 new FilterNodeComposite(fComposite
, (TmfFilterNode
) node
);
239 } else if (node
instanceof TmfFilterEventTypeNode
) {
240 new FilterEventTypeNodeComposite(fComposite
, (TmfFilterEventTypeNode
) node
);
241 } else if (node
instanceof TmfFilterAndNode
) {
242 new FilterAndNodeComposite(fComposite
, (TmfFilterAndNode
) node
);
243 } else if (node
instanceof TmfFilterOrNode
) {
244 new FilterOrNodeComposite(fComposite
, (TmfFilterOrNode
) node
);
245 } else if (node
instanceof TmfFilterContainsNode
) {
246 new FilterContainsNodeComposite(fComposite
, (TmfFilterContainsNode
) node
);
247 } else if (node
instanceof TmfFilterEqualsNode
) {
248 new FilterEqualsNodeComposite(fComposite
, (TmfFilterEqualsNode
) node
);
249 } else if (node
instanceof TmfFilterMatchesNode
) {
250 new FilterMatchesNodeComposite(fComposite
, (TmfFilterMatchesNode
) node
);
251 } else if (node
instanceof TmfFilterCompareNode
) {
252 new FilterCompareNodeComposite(fComposite
, (TmfFilterCompareNode
) node
);
254 new FilterBaseNodeComposite(fComposite
);
260 * Highlight the provided tree items
262 private void highlightTreeItems(TreeItem
[] items
) {
263 resetTreeItems(fViewer
.getTree().getItems());
264 for (TreeItem item
: items
) {
265 item
.setForeground(Display
.getCurrent().getSystemColor(SWT
.COLOR_BLUE
));
271 * Reset the provided tree items (remove highlight)
273 private void resetTreeItems(TreeItem
[] items
) {
274 for (TreeItem item
: items
) {
275 item
.setForeground(Display
.getCurrent().getSystemColor(SWT
.COLOR_BLACK
));
276 resetTreeItems(item
.getItems());
280 public void setInput(ITmfFilterTreeNode root
) {
281 fViewer
.setInput(root
);
284 updateFilterNodeComposite(null);
287 public ITmfFilterTreeNode
getInput() {
288 return (ITmfFilterTreeNode
) fViewer
.getInput();
291 public void refresh() {
295 public void setSelection(ITmfFilterTreeNode node
, boolean reveal
) {
296 fViewer
.setSelection(new StructuredSelection(node
), reveal
);
299 public void setSelection(ITmfFilterTreeNode node
) {
300 fViewer
.setSelection(new StructuredSelection(node
));
303 public ITmfFilterTreeNode
getSelection() {
304 final ISelection selection
= fViewer
.getSelection();
305 ITmfFilterTreeNode filterTreeNode
= null;
306 if (selection
instanceof StructuredSelection
) {
307 Object element
= ((StructuredSelection
) selection
).getFirstElement();
308 if (element
instanceof ITmfFilterTreeNode
) {
309 filterTreeNode
= (ITmfFilterTreeNode
) element
;
313 final ITmfFilterTreeNode selectedNode
= filterTreeNode
;
317 public void addSelectionChangedListener(ISelectionChangedListener listener
) {
318 fViewer
.addSelectionChangedListener(listener
);
321 public void removeSelectionChangedListener(ISelectionChangedListener listener
) {
322 fViewer
.removeSelectionChangedListener(listener
);
325 private class FilterBaseNodeComposite
extends Composite
{
327 FilterBaseNodeComposite(Composite parent
) {
328 super(parent
, SWT
.NONE
);
329 setLayout(new GridLayout(2, false));
330 setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
331 setBackground(Display
.getCurrent().getSystemColor(SWT
.COLOR_WHITE
));
334 protected String
[] getFieldsList(ITmfFilterTreeNode node
) {
335 ArrayList
<String
> fieldsList
= new ArrayList
<String
>();
336 while (node
!= null) {
337 if (node
instanceof TmfFilterEventTypeNode
) {
338 TmfFilterEventTypeNode eventTypeNode
= (TmfFilterEventTypeNode
) node
;
339 for (IConfigurationElement ce
: TmfTraceType
.getTypeElements()) {
340 if (ce
.getAttribute(TmfTraceType
.EVENT_TYPE_ATTR
).equals(eventTypeNode
.getEventType())) {
342 ITmfEvent event
= (TmfEvent
) ce
.createExecutableExtension(TmfTraceType
.EVENT_TYPE_ATTR
);
343 ITmfEventType eventType
= event
.getType();
344 if (eventType
!= null) {
345 for (String field
: eventType
.getRootField().getFieldNames()) {
346 fieldsList
.add(field
);
349 } catch (CoreException e
) {
351 return fieldsList
.toArray(new String
[0]);
354 if (eventTypeNode
.getEventType().startsWith(CustomTxtEvent
.class.getCanonicalName())) {
355 for (CustomTxtTraceDefinition def
: CustomTxtTraceDefinition
.loadAll()) {
356 if (eventTypeNode
.getEventType().equals(CustomTxtEvent
.class.getCanonicalName() + ":" + def
.definitionName
)) { //$NON-NLS-1$
357 for (OutputColumn output
: def
.outputs
) {
358 fieldsList
.add(output
.name
);
360 return fieldsList
.toArray(new String
[0]);
364 if (eventTypeNode
.getEventType().startsWith(CustomXmlEvent
.class.getCanonicalName())) {
365 for (CustomXmlTraceDefinition def
: CustomXmlTraceDefinition
.loadAll()) {
366 if (eventTypeNode
.getEventType().equals(CustomXmlEvent
.class.getCanonicalName() + ":" + def
.definitionName
)) { //$NON-NLS-1$
367 for (OutputColumn output
: def
.outputs
) {
368 fieldsList
.add(output
.name
);
370 return fieldsList
.toArray(new String
[0]);
375 node
= node
.getParent();
377 for (IConfigurationElement ce
: TmfTraceType
.getTypeElements()) {
379 TmfEvent event
= (TmfEvent
) ce
.createExecutableExtension(TmfTraceType
.EVENT_TYPE_ATTR
);
380 ITmfEventType eventType
= event
.getType();
381 if (eventType
!= null) {
382 fieldsList
.add("[" + TmfTraceType
.getCategoryName(ce
.getAttribute(TmfTraceType
.CATEGORY_ATTR
)) + //$NON-NLS-1$
383 " : " + ce
.getAttribute(TmfTraceType
.NAME_ATTR
) + "]"); //$NON-NLS-1$ //$NON-NLS-2$
384 for (String field
: eventType
.getFieldNames()) {
385 fieldsList
.add(field
);
387 fieldsList
.add(""); //$NON-NLS-1$
389 } catch (CoreException e
) {
392 for (CustomTxtTraceDefinition def
: CustomTxtTraceDefinition
.loadAll()) {
393 fieldsList
.add("[" + CUSTOM_TXT_CATEGORY
+ //$NON-NLS-1$
394 " : " + def
.definitionName
+ "]"); //$NON-NLS-1$ //$NON-NLS-2$
395 for (OutputColumn output
: def
.outputs
) {
396 fieldsList
.add(output
.name
);
398 fieldsList
.add(""); //$NON-NLS-1$
400 for (CustomXmlTraceDefinition def
: CustomXmlTraceDefinition
.loadAll()) {
401 fieldsList
.add("[" + CUSTOM_XML_CATEGORY
+ //$NON-NLS-1$
402 " : " + def
.definitionName
+ "]"); //$NON-NLS-1$ //$NON-NLS-2$
403 for (OutputColumn output
: def
.outputs
) {
404 fieldsList
.add(output
.name
);
406 fieldsList
.add(""); //$NON-NLS-1$
408 return fieldsList
.toArray(new String
[0]);
412 private class FilterNodeComposite
extends FilterBaseNodeComposite
{
416 FilterNodeComposite(Composite parent
, TmfFilterNode node
) {
420 Label label
= new Label(this, SWT
.NONE
);
421 label
.setBackground(Display
.getCurrent().getSystemColor(SWT
.COLOR_WHITE
));
422 label
.setText(Messages
.FilterViewer_NameLabel
);
424 fNameText
= new Text(this, SWT
.BORDER
);
425 fNameText
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
426 if (node
.getFilterName() != null && node
.getFilterName().length() > 0) {
427 fNameText
.setText(node
.getFilterName());
429 fNameText
.setForeground(Display
.getCurrent().getSystemColor(SWT
.COLOR_GRAY
));
430 fNameText
.setText(Messages
.FilterViewer_FilterNameHint
);
432 fNameText
.addFocusListener(new FocusListener() {
434 public void focusLost(FocusEvent e
) {
435 if (fNode
.getFilterName() == null || fNode
.getFilterName().length() == 0) {
436 fNameText
.setForeground(Display
.getCurrent().getSystemColor(SWT
.COLOR_GRAY
));
437 fNameText
.setText(Messages
.FilterViewer_FilterNameHint
);
441 public void focusGained(FocusEvent e
) {
442 if (fNameText
.getForeground().equals(Display
.getCurrent().getSystemColor(SWT
.COLOR_GRAY
))) {
443 fNameText
.setText(""); //$NON-NLS-1$
445 fNameText
.setForeground(Display
.getCurrent().getSystemColor(SWT
.COLOR_BLACK
));
448 fNameText
.addModifyListener(new ModifyListener() {
450 public void modifyText(ModifyEvent e
) {
451 if (! fNameText
.getForeground().equals(Display
.getCurrent().getSystemColor(SWT
.COLOR_GRAY
))) {
452 fNode
.setFilterName(fNameText
.getText());
453 fViewer
.refresh(fNode
);
460 private class FilterEventTypeNodeComposite
extends FilterBaseNodeComposite
{
461 TmfFilterEventTypeNode fNode
;
463 Map
<String
, Object
> fEventsTypeMap
;
465 FilterEventTypeNodeComposite(Composite parent
, TmfFilterEventTypeNode node
) {
468 fEventsTypeMap
= getEventsTypeMap();
470 Label label
= new Label(this, SWT
.NONE
);
471 label
.setBackground(Display
.getCurrent().getSystemColor(SWT
.COLOR_WHITE
));
472 label
.setText(Messages
.FilterViewer_TypeLabel
);
474 fTypeCombo
= new Combo(this, SWT
.DROP_DOWN
| SWT
.READ_ONLY
);
475 fTypeCombo
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
476 fTypeCombo
.setItems(fEventsTypeMap
.keySet().toArray(new String
[0]));
477 if (fNode
.getEventType() != null) {
478 for (Entry
<String
, Object
> eventTypeEntry
: fEventsTypeMap
.entrySet()) {
479 Object value
= eventTypeEntry
.getValue();
480 if (value
instanceof IConfigurationElement
) {
481 IConfigurationElement ce
= (IConfigurationElement
) value
;
482 if (ce
.getAttribute(TmfTraceType
.EVENT_TYPE_ATTR
).equals(fNode
.getEventType())) {
483 fTypeCombo
.setText(eventTypeEntry
.getKey());
485 } else if (value
instanceof CustomTxtTraceDefinition
) {
486 CustomTxtTraceDefinition def
= (CustomTxtTraceDefinition
) value
;
487 String eventType
= CustomTxtEvent
.class.getCanonicalName() + ":" + def
.definitionName
; //$NON-NLS-1$
488 if (eventType
.equals(fNode
.getEventType())) {
489 fTypeCombo
.setText(eventTypeEntry
.getKey());
491 } else if (value
instanceof CustomXmlTraceDefinition
) {
492 CustomXmlTraceDefinition def
= (CustomXmlTraceDefinition
) value
;
493 String eventType
= CustomXmlEvent
.class.getCanonicalName() + ":" + def
.definitionName
; //$NON-NLS-1$
494 if (eventType
.equals(fNode
.getEventType())) {
495 fTypeCombo
.setText(eventTypeEntry
.getKey());
500 fTypeCombo
.addModifyListener(new ModifyListener() {
502 public void modifyText(ModifyEvent e
) {
503 for (Entry
<String
, Object
> eventTypeEntry
: fEventsTypeMap
.entrySet()) {
504 if (eventTypeEntry
.getKey().equals(fTypeCombo
.getText())) {
505 Object value
= eventTypeEntry
.getValue();
506 if (value
instanceof IConfigurationElement
) {
507 IConfigurationElement ce
= (IConfigurationElement
) value
;
508 fNode
.setEventType(ce
.getAttribute(TmfTraceType
.EVENT_TYPE_ATTR
));
509 fNode
.setName(ce
.getAttribute(TmfTraceType
.NAME_ATTR
));
510 } else if (value
instanceof CustomTxtTraceDefinition
) {
511 CustomTxtTraceDefinition def
= (CustomTxtTraceDefinition
) value
;
512 fNode
.setEventType(CustomTxtEvent
.class.getCanonicalName() + ":" + def
.definitionName
); //$NON-NLS-1$
513 fNode
.setName(def
.definitionName
);
514 } else if (value
instanceof CustomXmlTraceDefinition
) {
515 CustomXmlTraceDefinition def
= (CustomXmlTraceDefinition
) value
;
516 fNode
.setEventType(CustomXmlEvent
.class.getCanonicalName() + ":" + def
.definitionName
); //$NON-NLS-1$
517 fNode
.setName(def
.definitionName
);
519 fViewer
.refresh(fNode
);
527 protected Map
<String
, Object
> getEventsTypeMap() {
528 Map
<String
, Object
> eventsTypeMap
= new LinkedHashMap
<String
, Object
>();
529 for (IConfigurationElement ce
: TmfTraceType
.getTypeElements()) {
530 String categoryName
= TmfTraceType
.getCategoryName(ce
.getAttribute(TmfTraceType
.CATEGORY_ATTR
));
531 String text
= categoryName
+ " : " + ce
.getAttribute(TmfTraceType
.NAME_ATTR
); //$NON-NLS-1$
532 eventsTypeMap
.put(text
, ce
);
534 for (CustomTxtTraceDefinition def
: CustomTxtTraceDefinition
.loadAll()) {
535 String text
= CUSTOM_TXT_CATEGORY
+ " : " + def
.definitionName
; //$NON-NLS-1$
536 eventsTypeMap
.put(text
, def
);
538 for (CustomXmlTraceDefinition def
: CustomXmlTraceDefinition
.loadAll()) {
539 String text
= CUSTOM_XML_CATEGORY
+ " : " + def
.definitionName
; //$NON-NLS-1$
540 eventsTypeMap
.put(text
, def
);
542 return eventsTypeMap
;
546 private class FilterAndNodeComposite
extends FilterBaseNodeComposite
{
547 TmfFilterAndNode fNode
;
550 FilterAndNodeComposite(Composite parent
, TmfFilterAndNode node
) {
554 Label label
= new Label(this, SWT
.NONE
);
555 label
.setBackground(Display
.getCurrent().getSystemColor(SWT
.COLOR_WHITE
));
556 label
.setText(Messages
.FilterViewer_NotLabel
);
558 fNotButton
= new Button(this, SWT
.CHECK
);
559 fNotButton
.setBackground(Display
.getCurrent().getSystemColor(SWT
.COLOR_WHITE
));
560 fNotButton
.setSelection(fNode
.isNot());
561 fNotButton
.addSelectionListener(new SelectionAdapter() {
563 public void widgetSelected(SelectionEvent e
) {
564 fNode
.setNot(fNotButton
.getSelection());
565 fViewer
.refresh(fNode
);
571 private class FilterOrNodeComposite
extends FilterBaseNodeComposite
{
572 TmfFilterOrNode fNode
;
575 FilterOrNodeComposite(Composite parent
, TmfFilterOrNode node
) {
579 Label label
= new Label(this, SWT
.NONE
);
580 label
.setBackground(Display
.getCurrent().getSystemColor(SWT
.COLOR_WHITE
));
581 label
.setText(Messages
.FilterViewer_NotLabel
);
583 fNotButton
= new Button(this, SWT
.CHECK
);
584 fNotButton
.setBackground(Display
.getCurrent().getSystemColor(SWT
.COLOR_WHITE
));
585 fNotButton
.setSelection(fNode
.isNot());
586 fNotButton
.addSelectionListener(new SelectionAdapter() {
588 public void widgetSelected(SelectionEvent e
) {
589 fNode
.setNot(fNotButton
.getSelection());
590 fViewer
.refresh(fNode
);
596 private class FilterContainsNodeComposite
extends FilterBaseNodeComposite
{
597 TmfFilterContainsNode fNode
;
601 Button fIgnoreCaseButton
;
603 FilterContainsNodeComposite(Composite parent
, TmfFilterContainsNode node
) {
607 Label label
= new Label(this, SWT
.NONE
);
608 label
.setBackground(Display
.getCurrent().getSystemColor(SWT
.COLOR_WHITE
));
609 label
.setText(Messages
.FilterViewer_NotLabel
);
611 fNotButton
= new Button(this, SWT
.CHECK
);
612 fNotButton
.setBackground(Display
.getCurrent().getSystemColor(SWT
.COLOR_WHITE
));
613 fNotButton
.setSelection(fNode
.isNot());
614 fNotButton
.addSelectionListener(new SelectionAdapter() {
616 public void widgetSelected(SelectionEvent e
) {
617 fNode
.setNot(fNotButton
.getSelection());
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_FieldLabel
);
626 fFieldCombo
= new Combo(this, SWT
.DROP_DOWN
);
627 fFieldCombo
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
628 fFieldCombo
.setItems(getFieldsList(fNode
));
629 if (fNode
.getField() != null) {
630 fFieldCombo
.setText(fNode
.getField());
632 fFieldCombo
.addModifyListener(new ModifyListener() {
634 public void modifyText(ModifyEvent e
) {
635 fNode
.setField(fFieldCombo
.getText());
636 fViewer
.refresh(fNode
);
640 label
= new Label(this, SWT
.NONE
);
641 label
.setBackground(Display
.getCurrent().getSystemColor(SWT
.COLOR_WHITE
));
642 label
.setText(Messages
.FilterViewer_ValueLabel
);
644 fValueText
= new Text(this, SWT
.BORDER
);
645 fValueText
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
646 if (node
.getValue() != null && node
.getValue().length() > 0) {
647 fValueText
.setText(node
.getValue());
649 fValueText
.setForeground(Display
.getCurrent().getSystemColor(SWT
.COLOR_GRAY
));
650 fValueText
.setText(Messages
.FilterViewer_ValueHint
);
652 fValueText
.addFocusListener(new FocusListener() {
654 public void focusLost(FocusEvent e
) {
655 if (fNode
.getValue() == null || fNode
.getValue().length() == 0) {
656 fValueText
.setForeground(Display
.getCurrent().getSystemColor(SWT
.COLOR_GRAY
));
657 fValueText
.setText(Messages
.FilterViewer_ValueHint
);
661 public void focusGained(FocusEvent e
) {
662 if (fValueText
.getForeground().equals(Display
.getCurrent().getSystemColor(SWT
.COLOR_GRAY
))) {
663 fValueText
.setText(""); //$NON-NLS-1$
665 fValueText
.setForeground(Display
.getCurrent().getSystemColor(SWT
.COLOR_BLACK
));
668 fValueText
.addModifyListener(new ModifyListener() {
670 public void modifyText(ModifyEvent e
) {
671 if (! fValueText
.getForeground().equals(Display
.getCurrent().getSystemColor(SWT
.COLOR_GRAY
))) {
672 fNode
.setValue(fValueText
.getText());
673 fViewer
.refresh(fNode
);
678 label
= new Label(this, SWT
.NONE
);
679 label
.setBackground(Display
.getCurrent().getSystemColor(SWT
.COLOR_WHITE
));
681 fIgnoreCaseButton
= new Button(this, SWT
.CHECK
);
682 fIgnoreCaseButton
.setSelection(fNode
.isIgnoreCase());
683 fIgnoreCaseButton
.setText(Messages
.FilterViewer_IgnoreCaseButtonText
);
684 fIgnoreCaseButton
.setBackground(Display
.getCurrent().getSystemColor(SWT
.COLOR_WHITE
));
685 fIgnoreCaseButton
.addSelectionListener(new SelectionAdapter() {
687 public void widgetSelected(SelectionEvent e
) {
688 fNode
.setIgnoreCase(fIgnoreCaseButton
.getSelection());
689 fViewer
.refresh(fNode
);
695 private class FilterEqualsNodeComposite
extends FilterBaseNodeComposite
{
696 TmfFilterEqualsNode fNode
;
700 Button fIgnoreCaseButton
;
702 FilterEqualsNodeComposite(Composite parent
, TmfFilterEqualsNode node
) {
706 Label label
= new Label(this, SWT
.NONE
);
707 label
.setBackground(Display
.getCurrent().getSystemColor(SWT
.COLOR_WHITE
));
708 label
.setText(Messages
.FilterViewer_NotLabel
);
710 fNotButton
= new Button(this, SWT
.CHECK
);
711 fNotButton
.setBackground(Display
.getCurrent().getSystemColor(SWT
.COLOR_WHITE
));
712 fNotButton
.setSelection(fNode
.isNot());
713 fNotButton
.addSelectionListener(new SelectionAdapter() {
715 public void widgetSelected(SelectionEvent e
) {
716 fNode
.setNot(fNotButton
.getSelection());
717 fViewer
.refresh(fNode
);
721 label
= new Label(this, SWT
.NONE
);
722 label
.setBackground(Display
.getCurrent().getSystemColor(SWT
.COLOR_WHITE
));
723 label
.setText(Messages
.FilterViewer_FieldLabel
);
725 fFieldCombo
= new Combo(this, SWT
.DROP_DOWN
);
726 fFieldCombo
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
727 fFieldCombo
.setItems(getFieldsList(fNode
));
728 if (fNode
.getField() != null) {
729 fFieldCombo
.setText(fNode
.getField());
731 fFieldCombo
.addModifyListener(new ModifyListener() {
733 public void modifyText(ModifyEvent e
) {
734 fNode
.setField(fFieldCombo
.getText());
735 fViewer
.refresh(fNode
);
739 label
= new Label(this, SWT
.NONE
);
740 label
.setBackground(Display
.getCurrent().getSystemColor(SWT
.COLOR_WHITE
));
741 label
.setText(Messages
.FilterViewer_ValueLabel
);
743 fValueText
= new Text(this, SWT
.BORDER
);
744 fValueText
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
745 if (node
.getValue() != null && node
.getValue().length() > 0) {
746 fValueText
.setText(node
.getValue());
748 fValueText
.setForeground(Display
.getCurrent().getSystemColor(SWT
.COLOR_GRAY
));
749 fValueText
.setText(Messages
.FilterViewer_ValueHint
);
751 fValueText
.addFocusListener(new FocusListener() {
753 public void focusLost(FocusEvent e
) {
754 if (fNode
.getValue() == null || fNode
.getValue().length() == 0) {
755 fValueText
.setForeground(Display
.getCurrent().getSystemColor(SWT
.COLOR_GRAY
));
756 fValueText
.setText(Messages
.FilterViewer_ValueHint
);
760 public void focusGained(FocusEvent e
) {
761 if (fValueText
.getForeground().equals(Display
.getCurrent().getSystemColor(SWT
.COLOR_GRAY
))) {
762 fValueText
.setText(""); //$NON-NLS-1$
764 fValueText
.setForeground(Display
.getCurrent().getSystemColor(SWT
.COLOR_BLACK
));
767 fValueText
.addModifyListener(new ModifyListener() {
769 public void modifyText(ModifyEvent e
) {
770 if (! fValueText
.getForeground().equals(Display
.getCurrent().getSystemColor(SWT
.COLOR_GRAY
))) {
771 fNode
.setValue(fValueText
.getText());
772 fViewer
.refresh(fNode
);
777 label
= new Label(this, SWT
.NONE
);
778 label
.setBackground(Display
.getCurrent().getSystemColor(SWT
.COLOR_WHITE
));
780 fIgnoreCaseButton
= new Button(this, SWT
.CHECK
);
781 fIgnoreCaseButton
.setSelection(fNode
.isIgnoreCase());
782 fIgnoreCaseButton
.setText(Messages
.FilterViewer_IgnoreCaseButtonText
);
783 fIgnoreCaseButton
.setBackground(Display
.getCurrent().getSystemColor(SWT
.COLOR_WHITE
));
784 fIgnoreCaseButton
.addSelectionListener(new SelectionAdapter() {
786 public void widgetSelected(SelectionEvent e
) {
787 fNode
.setIgnoreCase(fIgnoreCaseButton
.getSelection());
788 fViewer
.refresh(fNode
);
794 private class FilterMatchesNodeComposite
extends FilterBaseNodeComposite
{
795 TmfFilterMatchesNode fNode
;
800 FilterMatchesNodeComposite(Composite parent
, TmfFilterMatchesNode node
) {
804 Label label
= new Label(this, SWT
.NONE
);
805 label
.setBackground(Display
.getCurrent().getSystemColor(SWT
.COLOR_WHITE
));
806 label
.setText(Messages
.FilterViewer_NotLabel
);
808 fNotButton
= new Button(this, SWT
.CHECK
);
809 fNotButton
.setBackground(Display
.getCurrent().getSystemColor(SWT
.COLOR_WHITE
));
810 fNotButton
.setSelection(fNode
.isNot());
811 fNotButton
.addSelectionListener(new SelectionAdapter() {
813 public void widgetSelected(SelectionEvent e
) {
814 fNode
.setNot(fNotButton
.getSelection());
815 fViewer
.refresh(fNode
);
819 label
= new Label(this, SWT
.NONE
);
820 label
.setBackground(Display
.getCurrent().getSystemColor(SWT
.COLOR_WHITE
));
821 label
.setText(Messages
.FilterViewer_FieldLabel
);
823 fFieldCombo
= new Combo(this, SWT
.DROP_DOWN
);
824 fFieldCombo
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
825 fFieldCombo
.setItems(getFieldsList(fNode
));
826 if (fNode
.getField() != null) {
827 fFieldCombo
.setText(fNode
.getField());
829 fFieldCombo
.addModifyListener(new ModifyListener() {
831 public void modifyText(ModifyEvent e
) {
832 fNode
.setField(fFieldCombo
.getText());
833 fViewer
.refresh(fNode
);
837 label
= new Label(this, SWT
.NONE
);
838 label
.setBackground(Display
.getCurrent().getSystemColor(SWT
.COLOR_WHITE
));
839 label
.setText(Messages
.FilterViewer_RegexLabel
);
841 fRegexText
= new Text(this, SWT
.BORDER
);
842 fRegexText
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
843 if (node
.getRegex() != null && node
.getRegex().length() > 0) {
844 fRegexText
.setText(node
.getRegex());
846 fRegexText
.setForeground(Display
.getCurrent().getSystemColor(SWT
.COLOR_GRAY
));
847 fRegexText
.setText(Messages
.FilterViewer_RegexHint
);
849 fRegexText
.addFocusListener(new FocusListener() {
851 public void focusLost(FocusEvent e
) {
852 if (fNode
.getRegex() == null || fNode
.getRegex().length() == 0) {
853 fRegexText
.setForeground(Display
.getCurrent().getSystemColor(SWT
.COLOR_GRAY
));
854 fRegexText
.setText(Messages
.FilterViewer_RegexHint
);
858 public void focusGained(FocusEvent e
) {
859 if (fRegexText
.getForeground().equals(Display
.getCurrent().getSystemColor(SWT
.COLOR_GRAY
))) {
860 fRegexText
.setText(""); //$NON-NLS-1$
862 fRegexText
.setForeground(Display
.getCurrent().getSystemColor(SWT
.COLOR_BLACK
));
865 fRegexText
.addModifyListener(new ModifyListener() {
867 public void modifyText(ModifyEvent e
) {
868 if (! fRegexText
.getForeground().equals(Display
.getCurrent().getSystemColor(SWT
.COLOR_GRAY
))) {
869 fNode
.setRegex(fRegexText
.getText());
870 fViewer
.refresh(fNode
);
877 private class FilterCompareNodeComposite
extends FilterBaseNodeComposite
{
878 TmfFilterCompareNode fNode
;
887 Button fTimestampButton
;
889 FilterCompareNodeComposite(Composite parent
, TmfFilterCompareNode node
) {
893 Label label
= new Label(this, SWT
.NONE
);
894 label
.setBackground(Display
.getCurrent().getSystemColor(SWT
.COLOR_WHITE
));
895 label
.setText(Messages
.FilterViewer_NotLabel
);
897 fNotButton
= new Button(this, SWT
.CHECK
);
898 fNotButton
.setBackground(Display
.getCurrent().getSystemColor(SWT
.COLOR_WHITE
));
899 fNotButton
.setSelection(fNode
.isNot());
900 fNotButton
.addSelectionListener(new SelectionAdapter() {
902 public void widgetSelected(SelectionEvent e
) {
903 fNode
.setNot(fNotButton
.getSelection());
904 fViewer
.refresh(fNode
);
908 label
= new Label(this, SWT
.NONE
);
909 label
.setBackground(Display
.getCurrent().getSystemColor(SWT
.COLOR_WHITE
));
910 label
.setText(Messages
.FilterViewer_FieldLabel
);
912 fFieldCombo
= new Combo(this, SWT
.DROP_DOWN
);
913 fFieldCombo
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
914 fFieldCombo
.setItems(getFieldsList(fNode
));
915 if (fNode
.getField() != null) {
916 fFieldCombo
.setText(fNode
.getField());
918 fFieldCombo
.addModifyListener(new ModifyListener() {
920 public void modifyText(ModifyEvent e
) {
921 fNode
.setField(fFieldCombo
.getText());
922 fViewer
.refresh(fNode
);
926 label
= new Label(this, SWT
.NONE
);
927 label
.setBackground(Display
.getCurrent().getSystemColor(SWT
.COLOR_WHITE
));
928 label
.setText(Messages
.FilterViewer_ResultLabel
);
930 Composite resultGroup
= new Composite(this, SWT
.NONE
);
931 GridLayout rggl
= new GridLayout(3, true);
932 rggl
.marginHeight
= 0;
933 rggl
.marginWidth
= 0;
934 resultGroup
.setLayout(rggl
);
935 resultGroup
.setBackground(Display
.getCurrent().getSystemColor(SWT
.COLOR_WHITE
));
937 fLTButton
= new Button(resultGroup
, SWT
.RADIO
);
938 fLTButton
.setSelection(fNode
.getResult() < 0);
939 fLTButton
.setText("<"); //$NON-NLS-1$
940 fLTButton
.setBackground(Display
.getCurrent().getSystemColor(SWT
.COLOR_WHITE
));
941 fLTButton
.addSelectionListener(new SelectionAdapter() {
943 public void widgetSelected(SelectionEvent e
) {
944 if (fLTButton
.getSelection()) {
947 fViewer
.refresh(fNode
);
951 fEQButton
= new Button(resultGroup
, SWT
.RADIO
);
952 fEQButton
.setSelection(fNode
.getResult() == 0);
953 fEQButton
.setText("="); //$NON-NLS-1$
954 fEQButton
.setBackground(Display
.getCurrent().getSystemColor(SWT
.COLOR_WHITE
));
955 fEQButton
.addSelectionListener(new SelectionAdapter() {
957 public void widgetSelected(SelectionEvent e
) {
958 if (fEQButton
.getSelection()) {
961 fViewer
.refresh(fNode
);
965 fGTButton
= new Button(resultGroup
, SWT
.RADIO
);
966 fGTButton
.setSelection(fNode
.getResult() > 0);
967 fGTButton
.setText(">"); //$NON-NLS-1$
968 fGTButton
.setBackground(Display
.getCurrent().getSystemColor(SWT
.COLOR_WHITE
));
969 fGTButton
.addSelectionListener(new SelectionAdapter() {
971 public void widgetSelected(SelectionEvent e
) {
972 if (fGTButton
.getSelection()) {
975 fViewer
.refresh(fNode
);
979 label
= new Label(this, SWT
.NONE
);
980 label
.setBackground(Display
.getCurrent().getSystemColor(SWT
.COLOR_WHITE
));
981 label
.setText(Messages
.FilterViewer_TypeLabel
);
983 Composite typeGroup
= new Composite(this, SWT
.NONE
);
984 GridLayout tggl
= new GridLayout(3, false);
985 tggl
.marginHeight
= 0;
986 tggl
.marginWidth
= 0;
987 typeGroup
.setLayout(tggl
);
988 typeGroup
.setBackground(Display
.getCurrent().getSystemColor(SWT
.COLOR_WHITE
));
990 fNumButton
= new Button(typeGroup
, SWT
.RADIO
);
991 fNumButton
.setSelection(fNode
.getType() == Type
.NUM
);
992 fNumButton
.setText(Messages
.FilterViewer_NumButtonText
);
993 fNumButton
.setBackground(Display
.getCurrent().getSystemColor(SWT
.COLOR_WHITE
));
994 fNumButton
.addSelectionListener(new SelectionAdapter() {
996 public void widgetSelected(SelectionEvent e
) {
997 if (fNumButton
.getSelection()) {
998 fNode
.setType(Type
.NUM
);
1000 fViewer
.refresh(fNode
);
1004 fAlphaButton
= new Button(typeGroup
, SWT
.RADIO
);
1005 fAlphaButton
.setSelection(fNode
.getType() == Type
.ALPHA
);
1006 fAlphaButton
.setText(Messages
.FilterViewer_AlphaButtonText
);
1007 fAlphaButton
.setBackground(Display
.getCurrent().getSystemColor(SWT
.COLOR_WHITE
));
1008 fAlphaButton
.addSelectionListener(new SelectionAdapter() {
1010 public void widgetSelected(SelectionEvent e
) {
1011 if (fAlphaButton
.getSelection()) {
1012 fNode
.setType(Type
.ALPHA
);
1014 fViewer
.refresh(fNode
);
1018 fTimestampButton
= new Button(typeGroup
, SWT
.RADIO
);
1019 fTimestampButton
.setSelection(fNode
.getType() == Type
.TIMESTAMP
);
1020 fTimestampButton
.setText(Messages
.FilterViewer_TimestampButtonText
);
1021 fTimestampButton
.setBackground(Display
.getCurrent().getSystemColor(SWT
.COLOR_WHITE
));
1022 fTimestampButton
.addSelectionListener(new SelectionAdapter() {
1024 public void widgetSelected(SelectionEvent e
) {
1025 if (fTimestampButton
.getSelection()) {
1026 fNode
.setType(Type
.TIMESTAMP
);
1028 fViewer
.refresh(fNode
);
1032 label
= new Label(this, SWT
.NONE
);
1033 label
.setBackground(Display
.getCurrent().getSystemColor(SWT
.COLOR_WHITE
));
1034 label
.setText(Messages
.FilterViewer_ValueLabel
);
1036 fValueText
= new Text(this, SWT
.BORDER
);
1037 fValueText
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
1038 if (node
.getValue() != null && node
.getValue().length() > 0) {
1039 fValueText
.setText(node
.getValue());
1041 fValueText
.setForeground(Display
.getCurrent().getSystemColor(SWT
.COLOR_GRAY
));
1042 fValueText
.setText(Messages
.FilterViewer_ValueHint
);
1044 fValueText
.addFocusListener(new FocusListener() {
1046 public void focusLost(FocusEvent e
) {
1047 if (fNode
.getValue() == null || fNode
.getValue().length() == 0) {
1048 fValueText
.setForeground(Display
.getCurrent().getSystemColor(SWT
.COLOR_GRAY
));
1049 fValueText
.setText(Messages
.FilterViewer_ValueHint
);
1053 public void focusGained(FocusEvent e
) {
1054 if (fValueText
.getForeground().equals(Display
.getCurrent().getSystemColor(SWT
.COLOR_GRAY
))) {
1055 fValueText
.setText(""); //$NON-NLS-1$
1057 fValueText
.setForeground(Display
.getCurrent().getSystemColor(SWT
.COLOR_BLACK
));
1060 fValueText
.addModifyListener(new ModifyListener() {
1062 public void modifyText(ModifyEvent e
) {
1063 if (! fValueText
.getForeground().equals(Display
.getCurrent().getSystemColor(SWT
.COLOR_GRAY
))) {
1064 fNode
.setValue(fValueText
.getText());
1065 fViewer
.refresh(fNode
);