Re-structure LTTng sub-project as per the Linux Tools guidelines
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / tmf / ui / views / filter / FilterViewer.java
1 /*******************************************************************************
2 * Copyright (c) 2010 Ericsson
3 *
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
8 *
9 * Contributors:
10 * Patrick Tasse - Initial API and implementation
11 *******************************************************************************/
12
13 package org.eclipse.linuxtools.tmf.ui.views.filter;
14
15 import java.util.ArrayList;
16 import java.util.LinkedHashMap;
17 import java.util.Map;
18 import java.util.Map.Entry;
19
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;
75
76 class FilterViewer extends Composite {
77
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$
80
81 private TreeViewer fViewer;
82 private Composite fComposite;
83
84 public FilterViewer(Composite parent, int style) {
85 super(parent, style);
86
87 setLayout(new FillLayout());
88 GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
89 setLayoutData(gd);
90
91 final SashForm sash = new SashForm(this, SWT.HORIZONTAL);
92
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());
98
99 // Create the empty filter node properties panel
100 fComposite = new Composite(sash, SWT.NONE);
101 GridLayout gl = new GridLayout();
102 gl.marginHeight = 0;
103 gl.marginWidth = 0;
104 fComposite.setLayout(gl);
105
106 createContextMenu();
107
108 fViewer.addSelectionChangedListener(new ISelectionChangedListener() {
109 @Override
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());
118 } else {
119 updateFilterNodeComposite(null);
120 }
121 }
122 });
123 }
124
125 /**
126 * Create the context menu for the tree viewer
127 */
128 private void createContextMenu() {
129 // Adds root context menu
130 MenuManager menuManager = new MenuManager();
131 menuManager.setRemoveAllWhenShown(true);
132 menuManager.addMenuListener(new IMenuListener() {
133 @Override
134 public void menuAboutToShow(IMenuManager manager) {
135 fillContextMenu(manager);
136 }
137 });
138
139 // Context
140 Menu contextMenu = menuManager.createContextMenu(fViewer.getTree());
141
142 // Publish it
143 fViewer.getTree().setMenu(contextMenu);
144 }
145
146 /**
147 * Fill the context menu for the tree viewer
148 */
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;
156 }
157 }
158
159 final ITmfFilterTreeNode selectedNode = filterTreeNode;
160
161 if (selectedNode != null) {
162
163 fillContextMenuForNode(selectedNode, manager);
164
165 if (selectedNode.getValidChildren().size() > 0) {
166 manager.add(new Separator());
167 }
168
169 Action deleteAction = new Action() {
170 @Override
171 public void run() {
172 selectedNode.remove();
173 fViewer.refresh();
174 }
175 };
176 deleteAction.setText(Messages.FilterViewer_DeleteActionText);
177 manager.add(deleteAction);
178
179 manager.add(new Separator());
180 }
181
182 if (fViewer.getInput() instanceof TmfFilterRootNode || selectedNode == null) {
183 final ITmfFilterTreeNode root = (ITmfFilterTreeNode) fViewer.getInput();
184
185 fillContextMenuForNode(root, manager);
186 }
187 }
188
189 /**
190 * Fill the context menu with the valid children of the provided node
191 */
192 protected void fillContextMenuForNode(final ITmfFilterTreeNode node, IMenuManager manager) {
193 for (final String child : node.getValidChildren()) {
194 final Action action = new Action() {
195 @Override
196 public void run() {
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);
214 }
215 if (newNode != null) {
216 fViewer.refresh();
217 fViewer.setSelection(new StructuredSelection(newNode), true);
218 }
219 }
220 };
221 if (TmfFilterNode.NODE_NAME.equals(child)) {
222 action.setText(Messages.FilterViewer_NewPrefix + " " + child); //$NON-NLS-1$
223 } else {
224 action.setText(child);
225 }
226 manager.add(action);
227 }
228 }
229
230 /**
231 * Create the appropriate filter node properties composite
232 */
233 private void updateFilterNodeComposite(ITmfFilterTreeNode node) {
234 for (Control control : fComposite.getChildren()) {
235 control.dispose();
236 }
237
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);
254 } else {
255 new FilterBaseNodeComposite(fComposite);
256 }
257 fComposite.layout();
258 }
259
260 /**
261 * Highlight the provided tree items
262 */
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));
267 }
268
269 }
270
271 /**
272 * Reset the provided tree items (remove highlight)
273 */
274 private void resetTreeItems(TreeItem[] items) {
275 for (TreeItem item : items) {
276 item.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_BLACK));
277 resetTreeItems(item.getItems());
278 }
279 }
280
281 public void setInput(ITmfFilterTreeNode root) {
282 fViewer.setInput(root);
283 fViewer.expandAll();
284
285 updateFilterNodeComposite(null);
286 }
287
288 public ITmfFilterTreeNode getInput() {
289 return (ITmfFilterTreeNode) fViewer.getInput();
290 }
291
292 public void refresh() {
293 fViewer.refresh();
294 }
295
296 public void setSelection(ITmfFilterTreeNode node, boolean reveal) {
297 fViewer.setSelection(new StructuredSelection(node), reveal);
298 }
299
300 public void setSelection(ITmfFilterTreeNode node) {
301 fViewer.setSelection(new StructuredSelection(node));
302 }
303
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;
311 }
312 }
313
314 final ITmfFilterTreeNode selectedNode = filterTreeNode;
315 return selectedNode;
316 }
317
318 public void addSelectionChangedListener(ISelectionChangedListener listener) {
319 fViewer.addSelectionChangedListener(listener);
320 }
321
322 public void removeSelectionChangedListener(ISelectionChangedListener listener) {
323 fViewer.removeSelectionChangedListener(listener);
324 }
325
326 private class FilterBaseNodeComposite extends Composite {
327
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));
333 }
334
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())) {
342 try {
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);
348 }
349 }
350 } catch (CoreException e) {
351 }
352 return fieldsList.toArray(new String[0]);
353 }
354 }
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);
360 }
361 return fieldsList.toArray(new String[0]);
362 }
363 }
364 }
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);
370 }
371 return fieldsList.toArray(new String[0]);
372 }
373 }
374 }
375 }
376 node = node.getParent();
377 }
378 for (IConfigurationElement ce : TmfTraceType.getTypeElements()) {
379 try {
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);
387 }
388 fieldsList.add(""); //$NON-NLS-1$
389 }
390 } catch (CoreException e) {
391 }
392 }
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);
398 }
399 fieldsList.add(""); //$NON-NLS-1$
400 }
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);
406 }
407 fieldsList.add(""); //$NON-NLS-1$
408 }
409 return fieldsList.toArray(new String[0]);
410 }
411 }
412
413 private class FilterNodeComposite extends FilterBaseNodeComposite {
414 TmfFilterNode fNode;
415 Text fNameText;
416
417 FilterNodeComposite(Composite parent, TmfFilterNode node) {
418 super(parent);
419 fNode = node;
420
421 Label label = new Label(this, SWT.NONE);
422 label.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));
423 label.setText(Messages.FilterViewer_NameLabel);
424
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());
429 } else {
430 fNameText.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_GRAY));
431 fNameText.setText(Messages.FilterViewer_FilterNameHint);
432 }
433 fNameText.addFocusListener(new FocusListener() {
434 @Override
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);
439 }
440 }
441 @Override
442 public void focusGained(FocusEvent e) {
443 if (fNameText.getForeground().equals(Display.getCurrent().getSystemColor(SWT.COLOR_GRAY))) {
444 fNameText.setText(""); //$NON-NLS-1$
445 }
446 fNameText.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_BLACK));
447 }
448 });
449 fNameText.addModifyListener(new ModifyListener() {
450 @Override
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);
455 }
456 }
457 });
458 }
459 }
460
461 private class FilterEventTypeNodeComposite extends FilterBaseNodeComposite {
462 TmfFilterEventTypeNode fNode;
463 Combo fTypeCombo;
464 Map<String, Object> fEventsTypeMap;
465
466 FilterEventTypeNodeComposite(Composite parent, TmfFilterEventTypeNode node) {
467 super(parent);
468 fNode = node;
469 fEventsTypeMap = getEventsTypeMap();
470
471 Label label = new Label(this, SWT.NONE);
472 label.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));
473 label.setText(Messages.FilterViewer_TypeLabel);
474
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());
485 }
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());
491 }
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());
497 }
498 }
499 }
500 }
501 fTypeCombo.addModifyListener(new ModifyListener() {
502 @Override
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);
519 }
520 fViewer.refresh(fNode);
521 break;
522 }
523 }
524 }
525 });
526 }
527
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);
534 }
535 for (CustomTxtTraceDefinition def : CustomTxtTraceDefinition.loadAll()) {
536 String text = CUSTOM_TXT_CATEGORY + " : " + def.definitionName; //$NON-NLS-1$
537 eventsTypeMap.put(text, def);
538 }
539 for (CustomXmlTraceDefinition def : CustomXmlTraceDefinition.loadAll()) {
540 String text = CUSTOM_XML_CATEGORY + " : " + def.definitionName; //$NON-NLS-1$
541 eventsTypeMap.put(text, def);
542 }
543 return eventsTypeMap;
544 }
545 }
546
547 private class FilterAndNodeComposite extends FilterBaseNodeComposite {
548 TmfFilterAndNode fNode;
549 Button fNotButton;
550
551 FilterAndNodeComposite(Composite parent, TmfFilterAndNode node) {
552 super(parent);
553 fNode = node;
554
555 Label label = new Label(this, SWT.NONE);
556 label.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));
557 label.setText(Messages.FilterViewer_NotLabel);
558
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() {
563 @Override
564 public void widgetSelected(SelectionEvent e) {
565 fNode.setNot(fNotButton.getSelection());
566 fViewer.refresh(fNode);
567 }
568 });
569 }
570 }
571
572 private class FilterOrNodeComposite extends FilterBaseNodeComposite {
573 TmfFilterOrNode fNode;
574 Button fNotButton;
575
576 FilterOrNodeComposite(Composite parent, TmfFilterOrNode node) {
577 super(parent);
578 fNode = node;
579
580 Label label = new Label(this, SWT.NONE);
581 label.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));
582 label.setText(Messages.FilterViewer_NotLabel);
583
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() {
588 @Override
589 public void widgetSelected(SelectionEvent e) {
590 fNode.setNot(fNotButton.getSelection());
591 fViewer.refresh(fNode);
592 }
593 });
594 }
595 }
596
597 private class FilterContainsNodeComposite extends FilterBaseNodeComposite {
598 TmfFilterContainsNode fNode;
599 Button fNotButton;
600 Combo fFieldCombo;
601 Text fValueText;
602 Button fIgnoreCaseButton;
603
604 FilterContainsNodeComposite(Composite parent, TmfFilterContainsNode node) {
605 super(parent);
606 fNode = node;
607
608 Label label = new Label(this, SWT.NONE);
609 label.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));
610 label.setText(Messages.FilterViewer_NotLabel);
611
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() {
616 @Override
617 public void widgetSelected(SelectionEvent e) {
618 fNode.setNot(fNotButton.getSelection());
619 fViewer.refresh(fNode);
620 }
621 });
622
623 label = new Label(this, SWT.NONE);
624 label.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));
625 label.setText(Messages.FilterViewer_FieldLabel);
626
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());
632 }
633 fFieldCombo.addModifyListener(new ModifyListener() {
634 @Override
635 public void modifyText(ModifyEvent e) {
636 fNode.setField(fFieldCombo.getText());
637 fViewer.refresh(fNode);
638 }
639 });
640
641 label = new Label(this, SWT.NONE);
642 label.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));
643 label.setText(Messages.FilterViewer_ValueLabel);
644
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());
649 } else {
650 fValueText.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_GRAY));
651 fValueText.setText(Messages.FilterViewer_ValueHint);
652 }
653 fValueText.addFocusListener(new FocusListener() {
654 @Override
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);
659 }
660 }
661 @Override
662 public void focusGained(FocusEvent e) {
663 if (fValueText.getForeground().equals(Display.getCurrent().getSystemColor(SWT.COLOR_GRAY))) {
664 fValueText.setText(""); //$NON-NLS-1$
665 }
666 fValueText.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_BLACK));
667 }
668 });
669 fValueText.addModifyListener(new ModifyListener() {
670 @Override
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);
675 }
676 }
677 });
678
679 label = new Label(this, SWT.NONE);
680 label.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));
681
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() {
687 @Override
688 public void widgetSelected(SelectionEvent e) {
689 fNode.setIgnoreCase(fIgnoreCaseButton.getSelection());
690 fViewer.refresh(fNode);
691 }
692 });
693 }
694 }
695
696 private class FilterEqualsNodeComposite extends FilterBaseNodeComposite {
697 TmfFilterEqualsNode fNode;
698 Button fNotButton;
699 Combo fFieldCombo;
700 Text fValueText;
701 Button fIgnoreCaseButton;
702
703 FilterEqualsNodeComposite(Composite parent, TmfFilterEqualsNode node) {
704 super(parent);
705 fNode = node;
706
707 Label label = new Label(this, SWT.NONE);
708 label.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));
709 label.setText(Messages.FilterViewer_NotLabel);
710
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() {
715 @Override
716 public void widgetSelected(SelectionEvent e) {
717 fNode.setNot(fNotButton.getSelection());
718 fViewer.refresh(fNode);
719 }
720 });
721
722 label = new Label(this, SWT.NONE);
723 label.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));
724 label.setText(Messages.FilterViewer_FieldLabel);
725
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());
731 }
732 fFieldCombo.addModifyListener(new ModifyListener() {
733 @Override
734 public void modifyText(ModifyEvent e) {
735 fNode.setField(fFieldCombo.getText());
736 fViewer.refresh(fNode);
737 }
738 });
739
740 label = new Label(this, SWT.NONE);
741 label.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));
742 label.setText(Messages.FilterViewer_ValueLabel);
743
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());
748 } else {
749 fValueText.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_GRAY));
750 fValueText.setText(Messages.FilterViewer_ValueHint);
751 }
752 fValueText.addFocusListener(new FocusListener() {
753 @Override
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);
758 }
759 }
760 @Override
761 public void focusGained(FocusEvent e) {
762 if (fValueText.getForeground().equals(Display.getCurrent().getSystemColor(SWT.COLOR_GRAY))) {
763 fValueText.setText(""); //$NON-NLS-1$
764 }
765 fValueText.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_BLACK));
766 }
767 });
768 fValueText.addModifyListener(new ModifyListener() {
769 @Override
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);
774 }
775 }
776 });
777
778 label = new Label(this, SWT.NONE);
779 label.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));
780
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() {
786 @Override
787 public void widgetSelected(SelectionEvent e) {
788 fNode.setIgnoreCase(fIgnoreCaseButton.getSelection());
789 fViewer.refresh(fNode);
790 }
791 });
792 }
793 }
794
795 private class FilterMatchesNodeComposite extends FilterBaseNodeComposite {
796 TmfFilterMatchesNode fNode;
797 Button fNotButton;
798 Combo fFieldCombo;
799 Text fRegexText;
800
801 FilterMatchesNodeComposite(Composite parent, TmfFilterMatchesNode node) {
802 super(parent);
803 fNode = node;
804
805 Label label = new Label(this, SWT.NONE);
806 label.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));
807 label.setText(Messages.FilterViewer_NotLabel);
808
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() {
813 @Override
814 public void widgetSelected(SelectionEvent e) {
815 fNode.setNot(fNotButton.getSelection());
816 fViewer.refresh(fNode);
817 }
818 });
819
820 label = new Label(this, SWT.NONE);
821 label.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));
822 label.setText(Messages.FilterViewer_FieldLabel);
823
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());
829 }
830 fFieldCombo.addModifyListener(new ModifyListener() {
831 @Override
832 public void modifyText(ModifyEvent e) {
833 fNode.setField(fFieldCombo.getText());
834 fViewer.refresh(fNode);
835 }
836 });
837
838 label = new Label(this, SWT.NONE);
839 label.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));
840 label.setText(Messages.FilterViewer_RegexLabel);
841
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());
846 } else {
847 fRegexText.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_GRAY));
848 fRegexText.setText(Messages.FilterViewer_RegexHint);
849 }
850 fRegexText.addFocusListener(new FocusListener() {
851 @Override
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);
856 }
857 }
858 @Override
859 public void focusGained(FocusEvent e) {
860 if (fRegexText.getForeground().equals(Display.getCurrent().getSystemColor(SWT.COLOR_GRAY))) {
861 fRegexText.setText(""); //$NON-NLS-1$
862 }
863 fRegexText.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_BLACK));
864 }
865 });
866 fRegexText.addModifyListener(new ModifyListener() {
867 @Override
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);
872 }
873 }
874 });
875 }
876 }
877
878 private class FilterCompareNodeComposite extends FilterBaseNodeComposite {
879 TmfFilterCompareNode fNode;
880 Button fNotButton;
881 Combo fFieldCombo;
882 Text fValueText;
883 Button fLTButton;
884 Button fEQButton;
885 Button fGTButton;
886 Button fNumButton;
887 Button fAlphaButton;
888 Button fTimestampButton;
889
890 FilterCompareNodeComposite(Composite parent, TmfFilterCompareNode node) {
891 super(parent);
892 fNode = node;
893
894 Label label = new Label(this, SWT.NONE);
895 label.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));
896 label.setText(Messages.FilterViewer_NotLabel);
897
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() {
902 @Override
903 public void widgetSelected(SelectionEvent e) {
904 fNode.setNot(fNotButton.getSelection());
905 fViewer.refresh(fNode);
906 }
907 });
908
909 label = new Label(this, SWT.NONE);
910 label.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));
911 label.setText(Messages.FilterViewer_FieldLabel);
912
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());
918 }
919 fFieldCombo.addModifyListener(new ModifyListener() {
920 @Override
921 public void modifyText(ModifyEvent e) {
922 fNode.setField(fFieldCombo.getText());
923 fViewer.refresh(fNode);
924 }
925 });
926
927 label = new Label(this, SWT.NONE);
928 label.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));
929 label.setText(Messages.FilterViewer_ResultLabel);
930
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));
937
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() {
943 @Override
944 public void widgetSelected(SelectionEvent e) {
945 if (fLTButton.getSelection()) {
946 fNode.setResult(-1);
947 }
948 fViewer.refresh(fNode);
949 }
950 });
951
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() {
957 @Override
958 public void widgetSelected(SelectionEvent e) {
959 if (fEQButton.getSelection()) {
960 fNode.setResult(0);
961 }
962 fViewer.refresh(fNode);
963 }
964 });
965
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() {
971 @Override
972 public void widgetSelected(SelectionEvent e) {
973 if (fGTButton.getSelection()) {
974 fNode.setResult(1);
975 }
976 fViewer.refresh(fNode);
977 }
978 });
979
980 label = new Label(this, SWT.NONE);
981 label.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));
982 label.setText(Messages.FilterViewer_TypeLabel);
983
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));
990
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() {
996 @Override
997 public void widgetSelected(SelectionEvent e) {
998 if (fNumButton.getSelection()) {
999 fNode.setType(Type.NUM);
1000 }
1001 fViewer.refresh(fNode);
1002 }
1003 });
1004
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() {
1010 @Override
1011 public void widgetSelected(SelectionEvent e) {
1012 if (fAlphaButton.getSelection()) {
1013 fNode.setType(Type.ALPHA);
1014 }
1015 fViewer.refresh(fNode);
1016 }
1017 });
1018
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() {
1024 @Override
1025 public void widgetSelected(SelectionEvent e) {
1026 if (fTimestampButton.getSelection()) {
1027 fNode.setType(Type.TIMESTAMP);
1028 }
1029 fViewer.refresh(fNode);
1030 }
1031 });
1032
1033 label = new Label(this, SWT.NONE);
1034 label.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));
1035 label.setText(Messages.FilterViewer_ValueLabel);
1036
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());
1041 } else {
1042 fValueText.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_GRAY));
1043 fValueText.setText(Messages.FilterViewer_ValueHint);
1044 }
1045 fValueText.addFocusListener(new FocusListener() {
1046 @Override
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);
1051 }
1052 }
1053 @Override
1054 public void focusGained(FocusEvent e) {
1055 if (fValueText.getForeground().equals(Display.getCurrent().getSystemColor(SWT.COLOR_GRAY))) {
1056 fValueText.setText(""); //$NON-NLS-1$
1057 }
1058 fValueText.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_BLACK));
1059 }
1060 });
1061 fValueText.addModifyListener(new ModifyListener() {
1062 @Override
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);
1067 }
1068 }
1069 });
1070 }
1071 }
1072
1073 }
This page took 0.070127 seconds and 5 git commands to generate.