Implement the new TMF Event Model
[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.ITmfEventType;
34 import org.eclipse.linuxtools.tmf.core.event.TmfEvent;
35 import org.eclipse.linuxtools.tmf.core.filter.model.ITmfFilterTreeNode;
36 import org.eclipse.linuxtools.tmf.core.filter.model.TmfFilterAndNode;
37 import org.eclipse.linuxtools.tmf.core.filter.model.TmfFilterCompareNode;
38 import org.eclipse.linuxtools.tmf.core.filter.model.TmfFilterCompareNode.Type;
39 import org.eclipse.linuxtools.tmf.core.filter.model.TmfFilterContainsNode;
40 import org.eclipse.linuxtools.tmf.core.filter.model.TmfFilterEqualsNode;
41 import org.eclipse.linuxtools.tmf.core.filter.model.TmfFilterEventTypeNode;
42 import org.eclipse.linuxtools.tmf.core.filter.model.TmfFilterMatchesNode;
43 import org.eclipse.linuxtools.tmf.core.filter.model.TmfFilterNode;
44 import org.eclipse.linuxtools.tmf.core.filter.model.TmfFilterOrNode;
45 import org.eclipse.linuxtools.tmf.core.filter.model.TmfFilterRootNode;
46 import org.eclipse.linuxtools.tmf.core.util.TmfTraceType;
47 import org.eclipse.linuxtools.tmf.ui.internal.Messages;
48 import org.eclipse.linuxtools.tmf.ui.parsers.custom.CustomTraceDefinition.OutputColumn;
49 import org.eclipse.linuxtools.tmf.ui.parsers.custom.CustomTxtEvent;
50 import org.eclipse.linuxtools.tmf.ui.parsers.custom.CustomTxtTraceDefinition;
51 import org.eclipse.linuxtools.tmf.ui.parsers.custom.CustomXmlEvent;
52 import org.eclipse.linuxtools.tmf.ui.parsers.custom.CustomXmlTraceDefinition;
53 import org.eclipse.swt.SWT;
54 import org.eclipse.swt.custom.SashForm;
55 import org.eclipse.swt.events.FocusEvent;
56 import org.eclipse.swt.events.FocusListener;
57 import org.eclipse.swt.events.ModifyEvent;
58 import org.eclipse.swt.events.ModifyListener;
59 import org.eclipse.swt.events.SelectionAdapter;
60 import org.eclipse.swt.events.SelectionEvent;
61 import org.eclipse.swt.layout.FillLayout;
62 import org.eclipse.swt.layout.GridData;
63 import org.eclipse.swt.layout.GridLayout;
64 import org.eclipse.swt.widgets.Button;
65 import org.eclipse.swt.widgets.Combo;
66 import org.eclipse.swt.widgets.Composite;
67 import org.eclipse.swt.widgets.Control;
68 import org.eclipse.swt.widgets.Display;
69 import org.eclipse.swt.widgets.Label;
70 import org.eclipse.swt.widgets.Menu;
71 import org.eclipse.swt.widgets.Text;
72 import org.eclipse.swt.widgets.TreeItem;
73
74 class FilterViewer extends Composite {
75
76 private static final String CUSTOM_TXT_CATEGORY = "Custom Text"; //$NON-NLS-1$
77 private static final String CUSTOM_XML_CATEGORY = "Custom XML"; //$NON-NLS-1$
78
79 private TreeViewer fViewer;
80 private Composite fComposite;
81
82 public FilterViewer(Composite parent, int style) {
83 super(parent, style);
84
85 setLayout(new FillLayout());
86 GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
87 setLayoutData(gd);
88
89 final SashForm sash = new SashForm(this, SWT.HORIZONTAL);
90
91 // Create the tree viewer to display the filter tree
92 fViewer = new TreeViewer(sash, SWT.NONE);
93 fViewer.setContentProvider(new FilterTreeContentProvider());
94 fViewer.setLabelProvider(new FilterTreeLabelProvider());
95 fViewer.setInput(new TmfFilterRootNode());
96
97 // Create the empty filter node properties panel
98 fComposite = new Composite(sash, SWT.NONE);
99 GridLayout gl = new GridLayout();
100 gl.marginHeight = 0;
101 gl.marginWidth = 0;
102 fComposite.setLayout(gl);
103
104 createContextMenu();
105
106 fViewer.addSelectionChangedListener(new ISelectionChangedListener() {
107 @Override
108 public void selectionChanged(SelectionChangedEvent event) {
109 if (!(event.getSelection().isEmpty()) && event.getSelection() instanceof IStructuredSelection) {
110 // Update the filter node properties panel to the selection
111 IStructuredSelection selection = (IStructuredSelection) event.getSelection();
112 ITmfFilterTreeNode node = (ITmfFilterTreeNode) selection.getFirstElement();
113 updateFilterNodeComposite(node);
114 // Highlight the selection's children
115 highlightTreeItems(fViewer.getTree().getSelection()[0].getItems());
116 } else {
117 updateFilterNodeComposite(null);
118 }
119 }
120 });
121 }
122
123 /**
124 * Create the context menu for the tree viewer
125 */
126 private void createContextMenu() {
127 // Adds root context menu
128 MenuManager menuManager = new MenuManager();
129 menuManager.setRemoveAllWhenShown(true);
130 menuManager.addMenuListener(new IMenuListener() {
131 @Override
132 public void menuAboutToShow(IMenuManager manager) {
133 fillContextMenu(manager);
134 }
135 });
136
137 // Context
138 Menu contextMenu = menuManager.createContextMenu(fViewer.getTree());
139
140 // Publish it
141 fViewer.getTree().setMenu(contextMenu);
142 }
143
144 /**
145 * Fill the context menu for the tree viewer
146 */
147 protected void fillContextMenu(IMenuManager manager) {
148 final ISelection selection = fViewer.getSelection();
149 ITmfFilterTreeNode filterTreeNode = null;
150 if (selection instanceof StructuredSelection) {
151 Object element = ((StructuredSelection) selection).getFirstElement();
152 if (element instanceof ITmfFilterTreeNode) {
153 filterTreeNode = (ITmfFilterTreeNode) element;
154 }
155 }
156
157 final ITmfFilterTreeNode selectedNode = filterTreeNode;
158
159 if (selectedNode != null) {
160
161 fillContextMenuForNode(selectedNode, manager);
162
163 if (selectedNode.getValidChildren().size() > 0) {
164 manager.add(new Separator());
165 }
166
167 Action deleteAction = new Action() {
168 @Override
169 public void run() {
170 selectedNode.remove();
171 fViewer.refresh();
172 }
173 };
174 deleteAction.setText(Messages.FilterViewer_DeleteActionText);
175 manager.add(deleteAction);
176
177 manager.add(new Separator());
178 }
179
180 if (fViewer.getInput() instanceof TmfFilterRootNode || selectedNode == null) {
181 final ITmfFilterTreeNode root = (ITmfFilterTreeNode) fViewer.getInput();
182
183 fillContextMenuForNode(root, manager);
184 }
185 }
186
187 /**
188 * Fill the context menu with the valid children of the provided node
189 */
190 protected void fillContextMenuForNode(final ITmfFilterTreeNode node, IMenuManager manager) {
191 for (final String child : node.getValidChildren()) {
192 final Action action = new Action() {
193 @Override
194 public void run() {
195 ITmfFilterTreeNode newNode = null;
196 if (TmfFilterNode.NODE_NAME.equals(child)) {
197 newNode = new TmfFilterNode(node, ""); //$NON-NLS-1$
198 } else if (TmfFilterEventTypeNode.NODE_NAME.equals(child)) {
199 newNode = new TmfFilterEventTypeNode(node);
200 } else if (TmfFilterAndNode.NODE_NAME.equals(child)) {
201 newNode = new TmfFilterAndNode(node);
202 } else if (TmfFilterOrNode.NODE_NAME.equals(child)) {
203 newNode = new TmfFilterOrNode(node);
204 } else if (TmfFilterContainsNode.NODE_NAME.equals(child)) {
205 newNode = new TmfFilterContainsNode(node);
206 } else if (TmfFilterEqualsNode.NODE_NAME.equals(child)) {
207 newNode = new TmfFilterEqualsNode(node);
208 } else if (TmfFilterMatchesNode.NODE_NAME.equals(child)) {
209 newNode = new TmfFilterMatchesNode(node);
210 } else if (TmfFilterCompareNode.NODE_NAME.equals(child)) {
211 newNode = new TmfFilterCompareNode(node);
212 }
213 if (newNode != null) {
214 fViewer.refresh();
215 fViewer.setSelection(new StructuredSelection(newNode), true);
216 }
217 }
218 };
219 if (TmfFilterNode.NODE_NAME.equals(child)) {
220 action.setText(Messages.FilterViewer_NewPrefix + " " + child); //$NON-NLS-1$
221 } else {
222 action.setText(child);
223 }
224 manager.add(action);
225 }
226 }
227
228 /**
229 * Create the appropriate filter node properties composite
230 */
231 private void updateFilterNodeComposite(ITmfFilterTreeNode node) {
232 for (Control control : fComposite.getChildren()) {
233 control.dispose();
234 }
235
236 if (node instanceof TmfFilterNode) {
237 new FilterNodeComposite(fComposite, (TmfFilterNode) node);
238 } else if (node instanceof TmfFilterEventTypeNode) {
239 new FilterEventTypeNodeComposite(fComposite, (TmfFilterEventTypeNode) node);
240 } else if (node instanceof TmfFilterAndNode) {
241 new FilterAndNodeComposite(fComposite, (TmfFilterAndNode) node);
242 } else if (node instanceof TmfFilterOrNode) {
243 new FilterOrNodeComposite(fComposite, (TmfFilterOrNode) node);
244 } else if (node instanceof TmfFilterContainsNode) {
245 new FilterContainsNodeComposite(fComposite, (TmfFilterContainsNode) node);
246 } else if (node instanceof TmfFilterEqualsNode) {
247 new FilterEqualsNodeComposite(fComposite, (TmfFilterEqualsNode) node);
248 } else if (node instanceof TmfFilterMatchesNode) {
249 new FilterMatchesNodeComposite(fComposite, (TmfFilterMatchesNode) node);
250 } else if (node instanceof TmfFilterCompareNode) {
251 new FilterCompareNodeComposite(fComposite, (TmfFilterCompareNode) node);
252 } else {
253 new FilterBaseNodeComposite(fComposite);
254 }
255 fComposite.layout();
256 }
257
258 /**
259 * Highlight the provided tree items
260 */
261 private void highlightTreeItems(TreeItem[] items) {
262 resetTreeItems(fViewer.getTree().getItems());
263 for (TreeItem item : items) {
264 item.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_BLUE));
265 }
266
267 }
268
269 /**
270 * Reset the provided tree items (remove highlight)
271 */
272 private void resetTreeItems(TreeItem[] items) {
273 for (TreeItem item : items) {
274 item.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_BLACK));
275 resetTreeItems(item.getItems());
276 }
277 }
278
279 public void setInput(ITmfFilterTreeNode root) {
280 fViewer.setInput(root);
281 fViewer.expandAll();
282
283 updateFilterNodeComposite(null);
284 }
285
286 public ITmfFilterTreeNode getInput() {
287 return (ITmfFilterTreeNode) fViewer.getInput();
288 }
289
290 public void refresh() {
291 fViewer.refresh();
292 }
293
294 public void setSelection(ITmfFilterTreeNode node, boolean reveal) {
295 fViewer.setSelection(new StructuredSelection(node), reveal);
296 }
297
298 public void setSelection(ITmfFilterTreeNode node) {
299 fViewer.setSelection(new StructuredSelection(node));
300 }
301
302 public ITmfFilterTreeNode getSelection() {
303 final ISelection selection = fViewer.getSelection();
304 ITmfFilterTreeNode filterTreeNode = null;
305 if (selection instanceof StructuredSelection) {
306 Object element = ((StructuredSelection) selection).getFirstElement();
307 if (element instanceof ITmfFilterTreeNode) {
308 filterTreeNode = (ITmfFilterTreeNode) element;
309 }
310 }
311
312 final ITmfFilterTreeNode selectedNode = filterTreeNode;
313 return selectedNode;
314 }
315
316 public void addSelectionChangedListener(ISelectionChangedListener listener) {
317 fViewer.addSelectionChangedListener(listener);
318 }
319
320 public void removeSelectionChangedListener(ISelectionChangedListener listener) {
321 fViewer.removeSelectionChangedListener(listener);
322 }
323
324 private class FilterBaseNodeComposite extends Composite {
325
326 FilterBaseNodeComposite(Composite parent) {
327 super(parent, SWT.NONE);
328 setLayout(new GridLayout(2, false));
329 setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
330 setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));
331 }
332
333 protected String[] getFieldsList(ITmfFilterTreeNode node) {
334 ArrayList<String> fieldsList = new ArrayList<String>();
335 while (node != null) {
336 if (node instanceof TmfFilterEventTypeNode) {
337 TmfFilterEventTypeNode eventTypeNode = (TmfFilterEventTypeNode) node;
338 for (IConfigurationElement ce : TmfTraceType.getTypeElements()) {
339 if (ce.getAttribute(TmfTraceType.EVENT_TYPE_ATTR).equals(eventTypeNode.getEventType())) {
340 try {
341 TmfEvent event = (TmfEvent) ce.createExecutableExtension(TmfTraceType.EVENT_TYPE_ATTR);
342 ITmfEventType eventType = event.getType();
343 if (eventType != null) {
344 for (String field : eventType.getRootField().getFieldNames()) {
345 fieldsList.add(field);
346 }
347 }
348 } catch (CoreException e) {
349 }
350 return fieldsList.toArray(new String[0]);
351 }
352 }
353 if (eventTypeNode.getEventType().startsWith(CustomTxtEvent.class.getCanonicalName())) {
354 for (CustomTxtTraceDefinition def : CustomTxtTraceDefinition.loadAll()) {
355 if (eventTypeNode.getEventType().equals(CustomTxtEvent.class.getCanonicalName() + ":" + def.definitionName)) { //$NON-NLS-1$
356 for (OutputColumn output : def.outputs) {
357 fieldsList.add(output.name);
358 }
359 return fieldsList.toArray(new String[0]);
360 }
361 }
362 }
363 if (eventTypeNode.getEventType().startsWith(CustomXmlEvent.class.getCanonicalName())) {
364 for (CustomXmlTraceDefinition def : CustomXmlTraceDefinition.loadAll()) {
365 if (eventTypeNode.getEventType().equals(CustomXmlEvent.class.getCanonicalName() + ":" + def.definitionName)) { //$NON-NLS-1$
366 for (OutputColumn output : def.outputs) {
367 fieldsList.add(output.name);
368 }
369 return fieldsList.toArray(new String[0]);
370 }
371 }
372 }
373 }
374 node = node.getParent();
375 }
376 for (IConfigurationElement ce : TmfTraceType.getTypeElements()) {
377 try {
378 TmfEvent event = (TmfEvent) ce.createExecutableExtension(TmfTraceType.EVENT_TYPE_ATTR);
379 ITmfEventType eventType = event.getType();
380 if (eventType != null) {
381 fieldsList.add("[" + TmfTraceType.getCategoryName(ce.getAttribute(TmfTraceType.CATEGORY_ATTR)) + //$NON-NLS-1$
382 " : " + ce.getAttribute(TmfTraceType.NAME_ATTR) + "]"); //$NON-NLS-1$ //$NON-NLS-2$
383 for (String field : eventType.getFieldNames()) {
384 fieldsList.add(field);
385 }
386 fieldsList.add(""); //$NON-NLS-1$
387 }
388 } catch (CoreException e) {
389 }
390 }
391 for (CustomTxtTraceDefinition def : CustomTxtTraceDefinition.loadAll()) {
392 fieldsList.add("[" + CUSTOM_TXT_CATEGORY + //$NON-NLS-1$
393 " : " + def.definitionName + "]"); //$NON-NLS-1$ //$NON-NLS-2$
394 for (OutputColumn output : def.outputs) {
395 fieldsList.add(output.name);
396 }
397 fieldsList.add(""); //$NON-NLS-1$
398 }
399 for (CustomXmlTraceDefinition def : CustomXmlTraceDefinition.loadAll()) {
400 fieldsList.add("[" + CUSTOM_XML_CATEGORY + //$NON-NLS-1$
401 " : " + def.definitionName + "]"); //$NON-NLS-1$ //$NON-NLS-2$
402 for (OutputColumn output : def.outputs) {
403 fieldsList.add(output.name);
404 }
405 fieldsList.add(""); //$NON-NLS-1$
406 }
407 return fieldsList.toArray(new String[0]);
408 }
409 }
410
411 private class FilterNodeComposite extends FilterBaseNodeComposite {
412 TmfFilterNode fNode;
413 Text fNameText;
414
415 FilterNodeComposite(Composite parent, TmfFilterNode node) {
416 super(parent);
417 fNode = node;
418
419 Label label = new Label(this, SWT.NONE);
420 label.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));
421 label.setText(Messages.FilterViewer_NameLabel);
422
423 fNameText = new Text(this, SWT.BORDER);
424 fNameText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
425 if (node.getFilterName() != null && node.getFilterName().length() > 0) {
426 fNameText.setText(node.getFilterName());
427 } else {
428 fNameText.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_GRAY));
429 fNameText.setText(Messages.FilterViewer_FilterNameHint);
430 }
431 fNameText.addFocusListener(new FocusListener() {
432 @Override
433 public void focusLost(FocusEvent e) {
434 if (fNode.getFilterName() == null || fNode.getFilterName().length() == 0) {
435 fNameText.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_GRAY));
436 fNameText.setText(Messages.FilterViewer_FilterNameHint);
437 }
438 }
439 @Override
440 public void focusGained(FocusEvent e) {
441 if (fNameText.getForeground().equals(Display.getCurrent().getSystemColor(SWT.COLOR_GRAY))) {
442 fNameText.setText(""); //$NON-NLS-1$
443 }
444 fNameText.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_BLACK));
445 }
446 });
447 fNameText.addModifyListener(new ModifyListener() {
448 @Override
449 public void modifyText(ModifyEvent e) {
450 if (! fNameText.getForeground().equals(Display.getCurrent().getSystemColor(SWT.COLOR_GRAY))) {
451 fNode.setFilterName(fNameText.getText());
452 fViewer.refresh(fNode);
453 }
454 }
455 });
456 }
457 }
458
459 private class FilterEventTypeNodeComposite extends FilterBaseNodeComposite {
460 TmfFilterEventTypeNode fNode;
461 Combo fTypeCombo;
462 Map<String, Object> fEventsTypeMap;
463
464 FilterEventTypeNodeComposite(Composite parent, TmfFilterEventTypeNode node) {
465 super(parent);
466 fNode = node;
467 fEventsTypeMap = getEventsTypeMap();
468
469 Label label = new Label(this, SWT.NONE);
470 label.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));
471 label.setText(Messages.FilterViewer_TypeLabel);
472
473 fTypeCombo = new Combo(this, SWT.DROP_DOWN | SWT.READ_ONLY);
474 fTypeCombo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
475 fTypeCombo.setItems(fEventsTypeMap.keySet().toArray(new String[0]));
476 if (fNode.getEventType() != null) {
477 for (Entry <String, Object> eventTypeEntry : fEventsTypeMap.entrySet()) {
478 Object value = eventTypeEntry.getValue();
479 if (value instanceof IConfigurationElement) {
480 IConfigurationElement ce = (IConfigurationElement) value;
481 if (ce.getAttribute(TmfTraceType.EVENT_TYPE_ATTR).equals(fNode.getEventType())) {
482 fTypeCombo.setText(eventTypeEntry.getKey());
483 }
484 } else if (value instanceof CustomTxtTraceDefinition) {
485 CustomTxtTraceDefinition def = (CustomTxtTraceDefinition) value;
486 String eventType = CustomTxtEvent.class.getCanonicalName() + ":" + def.definitionName; //$NON-NLS-1$
487 if (eventType.equals(fNode.getEventType())) {
488 fTypeCombo.setText(eventTypeEntry.getKey());
489 }
490 } else if (value instanceof CustomXmlTraceDefinition) {
491 CustomXmlTraceDefinition def = (CustomXmlTraceDefinition) value;
492 String eventType = CustomXmlEvent.class.getCanonicalName() + ":" + def.definitionName; //$NON-NLS-1$
493 if (eventType.equals(fNode.getEventType())) {
494 fTypeCombo.setText(eventTypeEntry.getKey());
495 }
496 }
497 }
498 }
499 fTypeCombo.addModifyListener(new ModifyListener() {
500 @Override
501 public void modifyText(ModifyEvent e) {
502 for (Entry <String, Object> eventTypeEntry : fEventsTypeMap.entrySet()) {
503 if (eventTypeEntry.getKey().equals(fTypeCombo.getText())) {
504 Object value = eventTypeEntry.getValue();
505 if (value instanceof IConfigurationElement) {
506 IConfigurationElement ce = (IConfigurationElement) value;
507 fNode.setEventType(ce.getAttribute(TmfTraceType.EVENT_TYPE_ATTR));
508 fNode.setName(ce.getAttribute(TmfTraceType.NAME_ATTR));
509 } else if (value instanceof CustomTxtTraceDefinition) {
510 CustomTxtTraceDefinition def = (CustomTxtTraceDefinition) value;
511 fNode.setEventType(CustomTxtEvent.class.getCanonicalName() + ":" + def.definitionName); //$NON-NLS-1$
512 fNode.setName(def.definitionName);
513 } else if (value instanceof CustomXmlTraceDefinition) {
514 CustomXmlTraceDefinition def = (CustomXmlTraceDefinition) value;
515 fNode.setEventType(CustomXmlEvent.class.getCanonicalName() + ":" + def.definitionName); //$NON-NLS-1$
516 fNode.setName(def.definitionName);
517 }
518 fViewer.refresh(fNode);
519 break;
520 }
521 }
522 }
523 });
524 }
525
526 protected Map<String, Object> getEventsTypeMap() {
527 Map<String, Object> eventsTypeMap = new LinkedHashMap<String, Object>();
528 for (IConfigurationElement ce : TmfTraceType.getTypeElements()) {
529 String categoryName = TmfTraceType.getCategoryName(ce.getAttribute(TmfTraceType.CATEGORY_ATTR));
530 String text = categoryName + " : " + ce.getAttribute(TmfTraceType.NAME_ATTR); //$NON-NLS-1$
531 eventsTypeMap.put(text, ce);
532 }
533 for (CustomTxtTraceDefinition def : CustomTxtTraceDefinition.loadAll()) {
534 String text = CUSTOM_TXT_CATEGORY + " : " + def.definitionName; //$NON-NLS-1$
535 eventsTypeMap.put(text, def);
536 }
537 for (CustomXmlTraceDefinition def : CustomXmlTraceDefinition.loadAll()) {
538 String text = CUSTOM_XML_CATEGORY + " : " + def.definitionName; //$NON-NLS-1$
539 eventsTypeMap.put(text, def);
540 }
541 return eventsTypeMap;
542 }
543 }
544
545 private class FilterAndNodeComposite extends FilterBaseNodeComposite {
546 TmfFilterAndNode fNode;
547 Button fNotButton;
548
549 FilterAndNodeComposite(Composite parent, TmfFilterAndNode node) {
550 super(parent);
551 fNode = node;
552
553 Label label = new Label(this, SWT.NONE);
554 label.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));
555 label.setText(Messages.FilterViewer_NotLabel);
556
557 fNotButton = new Button(this, SWT.CHECK);
558 fNotButton.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));
559 fNotButton.setSelection(fNode.isNot());
560 fNotButton.addSelectionListener(new SelectionAdapter() {
561 @Override
562 public void widgetSelected(SelectionEvent e) {
563 fNode.setNot(fNotButton.getSelection());
564 fViewer.refresh(fNode);
565 }
566 });
567 }
568 }
569
570 private class FilterOrNodeComposite extends FilterBaseNodeComposite {
571 TmfFilterOrNode fNode;
572 Button fNotButton;
573
574 FilterOrNodeComposite(Composite parent, TmfFilterOrNode node) {
575 super(parent);
576 fNode = node;
577
578 Label label = new Label(this, SWT.NONE);
579 label.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));
580 label.setText(Messages.FilterViewer_NotLabel);
581
582 fNotButton = new Button(this, SWT.CHECK);
583 fNotButton.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));
584 fNotButton.setSelection(fNode.isNot());
585 fNotButton.addSelectionListener(new SelectionAdapter() {
586 @Override
587 public void widgetSelected(SelectionEvent e) {
588 fNode.setNot(fNotButton.getSelection());
589 fViewer.refresh(fNode);
590 }
591 });
592 }
593 }
594
595 private class FilterContainsNodeComposite extends FilterBaseNodeComposite {
596 TmfFilterContainsNode fNode;
597 Button fNotButton;
598 Combo fFieldCombo;
599 Text fValueText;
600 Button fIgnoreCaseButton;
601
602 FilterContainsNodeComposite(Composite parent, TmfFilterContainsNode node) {
603 super(parent);
604 fNode = node;
605
606 Label label = new Label(this, SWT.NONE);
607 label.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));
608 label.setText(Messages.FilterViewer_NotLabel);
609
610 fNotButton = new Button(this, SWT.CHECK);
611 fNotButton.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));
612 fNotButton.setSelection(fNode.isNot());
613 fNotButton.addSelectionListener(new SelectionAdapter() {
614 @Override
615 public void widgetSelected(SelectionEvent e) {
616 fNode.setNot(fNotButton.getSelection());
617 fViewer.refresh(fNode);
618 }
619 });
620
621 label = new Label(this, SWT.NONE);
622 label.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));
623 label.setText(Messages.FilterViewer_FieldLabel);
624
625 fFieldCombo = new Combo(this, SWT.DROP_DOWN);
626 fFieldCombo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
627 fFieldCombo.setItems(getFieldsList(fNode));
628 if (fNode.getField() != null) {
629 fFieldCombo.setText(fNode.getField());
630 }
631 fFieldCombo.addModifyListener(new ModifyListener() {
632 @Override
633 public void modifyText(ModifyEvent e) {
634 fNode.setField(fFieldCombo.getText());
635 fViewer.refresh(fNode);
636 }
637 });
638
639 label = new Label(this, SWT.NONE);
640 label.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));
641 label.setText(Messages.FilterViewer_ValueLabel);
642
643 fValueText = new Text(this, SWT.BORDER);
644 fValueText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
645 if (node.getValue() != null && node.getValue().length() > 0) {
646 fValueText.setText(node.getValue());
647 } else {
648 fValueText.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_GRAY));
649 fValueText.setText(Messages.FilterViewer_ValueHint);
650 }
651 fValueText.addFocusListener(new FocusListener() {
652 @Override
653 public void focusLost(FocusEvent e) {
654 if (fNode.getValue() == null || fNode.getValue().length() == 0) {
655 fValueText.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_GRAY));
656 fValueText.setText(Messages.FilterViewer_ValueHint);
657 }
658 }
659 @Override
660 public void focusGained(FocusEvent e) {
661 if (fValueText.getForeground().equals(Display.getCurrent().getSystemColor(SWT.COLOR_GRAY))) {
662 fValueText.setText(""); //$NON-NLS-1$
663 }
664 fValueText.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_BLACK));
665 }
666 });
667 fValueText.addModifyListener(new ModifyListener() {
668 @Override
669 public void modifyText(ModifyEvent e) {
670 if (! fValueText.getForeground().equals(Display.getCurrent().getSystemColor(SWT.COLOR_GRAY))) {
671 fNode.setValue(fValueText.getText());
672 fViewer.refresh(fNode);
673 }
674 }
675 });
676
677 label = new Label(this, SWT.NONE);
678 label.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));
679
680 fIgnoreCaseButton = new Button(this, SWT.CHECK);
681 fIgnoreCaseButton.setSelection(fNode.isIgnoreCase());
682 fIgnoreCaseButton.setText(Messages.FilterViewer_IgnoreCaseButtonText);
683 fIgnoreCaseButton.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));
684 fIgnoreCaseButton.addSelectionListener(new SelectionAdapter() {
685 @Override
686 public void widgetSelected(SelectionEvent e) {
687 fNode.setIgnoreCase(fIgnoreCaseButton.getSelection());
688 fViewer.refresh(fNode);
689 }
690 });
691 }
692 }
693
694 private class FilterEqualsNodeComposite extends FilterBaseNodeComposite {
695 TmfFilterEqualsNode fNode;
696 Button fNotButton;
697 Combo fFieldCombo;
698 Text fValueText;
699 Button fIgnoreCaseButton;
700
701 FilterEqualsNodeComposite(Composite parent, TmfFilterEqualsNode node) {
702 super(parent);
703 fNode = node;
704
705 Label label = new Label(this, SWT.NONE);
706 label.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));
707 label.setText(Messages.FilterViewer_NotLabel);
708
709 fNotButton = new Button(this, SWT.CHECK);
710 fNotButton.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));
711 fNotButton.setSelection(fNode.isNot());
712 fNotButton.addSelectionListener(new SelectionAdapter() {
713 @Override
714 public void widgetSelected(SelectionEvent e) {
715 fNode.setNot(fNotButton.getSelection());
716 fViewer.refresh(fNode);
717 }
718 });
719
720 label = new Label(this, SWT.NONE);
721 label.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));
722 label.setText(Messages.FilterViewer_FieldLabel);
723
724 fFieldCombo = new Combo(this, SWT.DROP_DOWN);
725 fFieldCombo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
726 fFieldCombo.setItems(getFieldsList(fNode));
727 if (fNode.getField() != null) {
728 fFieldCombo.setText(fNode.getField());
729 }
730 fFieldCombo.addModifyListener(new ModifyListener() {
731 @Override
732 public void modifyText(ModifyEvent e) {
733 fNode.setField(fFieldCombo.getText());
734 fViewer.refresh(fNode);
735 }
736 });
737
738 label = new Label(this, SWT.NONE);
739 label.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));
740 label.setText(Messages.FilterViewer_ValueLabel);
741
742 fValueText = new Text(this, SWT.BORDER);
743 fValueText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
744 if (node.getValue() != null && node.getValue().length() > 0) {
745 fValueText.setText(node.getValue());
746 } else {
747 fValueText.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_GRAY));
748 fValueText.setText(Messages.FilterViewer_ValueHint);
749 }
750 fValueText.addFocusListener(new FocusListener() {
751 @Override
752 public void focusLost(FocusEvent e) {
753 if (fNode.getValue() == null || fNode.getValue().length() == 0) {
754 fValueText.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_GRAY));
755 fValueText.setText(Messages.FilterViewer_ValueHint);
756 }
757 }
758 @Override
759 public void focusGained(FocusEvent e) {
760 if (fValueText.getForeground().equals(Display.getCurrent().getSystemColor(SWT.COLOR_GRAY))) {
761 fValueText.setText(""); //$NON-NLS-1$
762 }
763 fValueText.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_BLACK));
764 }
765 });
766 fValueText.addModifyListener(new ModifyListener() {
767 @Override
768 public void modifyText(ModifyEvent e) {
769 if (! fValueText.getForeground().equals(Display.getCurrent().getSystemColor(SWT.COLOR_GRAY))) {
770 fNode.setValue(fValueText.getText());
771 fViewer.refresh(fNode);
772 }
773 }
774 });
775
776 label = new Label(this, SWT.NONE);
777 label.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));
778
779 fIgnoreCaseButton = new Button(this, SWT.CHECK);
780 fIgnoreCaseButton.setSelection(fNode.isIgnoreCase());
781 fIgnoreCaseButton.setText(Messages.FilterViewer_IgnoreCaseButtonText);
782 fIgnoreCaseButton.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));
783 fIgnoreCaseButton.addSelectionListener(new SelectionAdapter() {
784 @Override
785 public void widgetSelected(SelectionEvent e) {
786 fNode.setIgnoreCase(fIgnoreCaseButton.getSelection());
787 fViewer.refresh(fNode);
788 }
789 });
790 }
791 }
792
793 private class FilterMatchesNodeComposite extends FilterBaseNodeComposite {
794 TmfFilterMatchesNode fNode;
795 Button fNotButton;
796 Combo fFieldCombo;
797 Text fRegexText;
798
799 FilterMatchesNodeComposite(Composite parent, TmfFilterMatchesNode node) {
800 super(parent);
801 fNode = node;
802
803 Label label = new Label(this, SWT.NONE);
804 label.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));
805 label.setText(Messages.FilterViewer_NotLabel);
806
807 fNotButton = new Button(this, SWT.CHECK);
808 fNotButton.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));
809 fNotButton.setSelection(fNode.isNot());
810 fNotButton.addSelectionListener(new SelectionAdapter() {
811 @Override
812 public void widgetSelected(SelectionEvent e) {
813 fNode.setNot(fNotButton.getSelection());
814 fViewer.refresh(fNode);
815 }
816 });
817
818 label = new Label(this, SWT.NONE);
819 label.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));
820 label.setText(Messages.FilterViewer_FieldLabel);
821
822 fFieldCombo = new Combo(this, SWT.DROP_DOWN);
823 fFieldCombo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
824 fFieldCombo.setItems(getFieldsList(fNode));
825 if (fNode.getField() != null) {
826 fFieldCombo.setText(fNode.getField());
827 }
828 fFieldCombo.addModifyListener(new ModifyListener() {
829 @Override
830 public void modifyText(ModifyEvent e) {
831 fNode.setField(fFieldCombo.getText());
832 fViewer.refresh(fNode);
833 }
834 });
835
836 label = new Label(this, SWT.NONE);
837 label.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));
838 label.setText(Messages.FilterViewer_RegexLabel);
839
840 fRegexText = new Text(this, SWT.BORDER);
841 fRegexText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
842 if (node.getRegex() != null && node.getRegex().length() > 0) {
843 fRegexText.setText(node.getRegex());
844 } else {
845 fRegexText.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_GRAY));
846 fRegexText.setText(Messages.FilterViewer_RegexHint);
847 }
848 fRegexText.addFocusListener(new FocusListener() {
849 @Override
850 public void focusLost(FocusEvent e) {
851 if (fNode.getRegex() == null || fNode.getRegex().length() == 0) {
852 fRegexText.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_GRAY));
853 fRegexText.setText(Messages.FilterViewer_RegexHint);
854 }
855 }
856 @Override
857 public void focusGained(FocusEvent e) {
858 if (fRegexText.getForeground().equals(Display.getCurrent().getSystemColor(SWT.COLOR_GRAY))) {
859 fRegexText.setText(""); //$NON-NLS-1$
860 }
861 fRegexText.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_BLACK));
862 }
863 });
864 fRegexText.addModifyListener(new ModifyListener() {
865 @Override
866 public void modifyText(ModifyEvent e) {
867 if (! fRegexText.getForeground().equals(Display.getCurrent().getSystemColor(SWT.COLOR_GRAY))) {
868 fNode.setRegex(fRegexText.getText());
869 fViewer.refresh(fNode);
870 }
871 }
872 });
873 }
874 }
875
876 private class FilterCompareNodeComposite extends FilterBaseNodeComposite {
877 TmfFilterCompareNode fNode;
878 Button fNotButton;
879 Combo fFieldCombo;
880 Text fValueText;
881 Button fLTButton;
882 Button fEQButton;
883 Button fGTButton;
884 Button fNumButton;
885 Button fAlphaButton;
886 Button fTimestampButton;
887
888 FilterCompareNodeComposite(Composite parent, TmfFilterCompareNode node) {
889 super(parent);
890 fNode = node;
891
892 Label label = new Label(this, SWT.NONE);
893 label.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));
894 label.setText(Messages.FilterViewer_NotLabel);
895
896 fNotButton = new Button(this, SWT.CHECK);
897 fNotButton.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));
898 fNotButton.setSelection(fNode.isNot());
899 fNotButton.addSelectionListener(new SelectionAdapter() {
900 @Override
901 public void widgetSelected(SelectionEvent e) {
902 fNode.setNot(fNotButton.getSelection());
903 fViewer.refresh(fNode);
904 }
905 });
906
907 label = new Label(this, SWT.NONE);
908 label.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));
909 label.setText(Messages.FilterViewer_FieldLabel);
910
911 fFieldCombo = new Combo(this, SWT.DROP_DOWN);
912 fFieldCombo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
913 fFieldCombo.setItems(getFieldsList(fNode));
914 if (fNode.getField() != null) {
915 fFieldCombo.setText(fNode.getField());
916 }
917 fFieldCombo.addModifyListener(new ModifyListener() {
918 @Override
919 public void modifyText(ModifyEvent e) {
920 fNode.setField(fFieldCombo.getText());
921 fViewer.refresh(fNode);
922 }
923 });
924
925 label = new Label(this, SWT.NONE);
926 label.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));
927 label.setText(Messages.FilterViewer_ResultLabel);
928
929 Composite resultGroup = new Composite(this, SWT.NONE);
930 GridLayout rggl = new GridLayout(3, true);
931 rggl.marginHeight = 0;
932 rggl.marginWidth = 0;
933 resultGroup.setLayout(rggl);
934 resultGroup.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));
935
936 fLTButton = new Button(resultGroup, SWT.RADIO);
937 fLTButton.setSelection(fNode.getResult() < 0);
938 fLTButton.setText("<"); //$NON-NLS-1$
939 fLTButton.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));
940 fLTButton.addSelectionListener(new SelectionAdapter() {
941 @Override
942 public void widgetSelected(SelectionEvent e) {
943 if (fLTButton.getSelection()) {
944 fNode.setResult(-1);
945 }
946 fViewer.refresh(fNode);
947 }
948 });
949
950 fEQButton = new Button(resultGroup, SWT.RADIO);
951 fEQButton.setSelection(fNode.getResult() == 0);
952 fEQButton.setText("="); //$NON-NLS-1$
953 fEQButton.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));
954 fEQButton.addSelectionListener(new SelectionAdapter() {
955 @Override
956 public void widgetSelected(SelectionEvent e) {
957 if (fEQButton.getSelection()) {
958 fNode.setResult(0);
959 }
960 fViewer.refresh(fNode);
961 }
962 });
963
964 fGTButton = new Button(resultGroup, SWT.RADIO);
965 fGTButton.setSelection(fNode.getResult() > 0);
966 fGTButton.setText(">"); //$NON-NLS-1$
967 fGTButton.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));
968 fGTButton.addSelectionListener(new SelectionAdapter() {
969 @Override
970 public void widgetSelected(SelectionEvent e) {
971 if (fGTButton.getSelection()) {
972 fNode.setResult(1);
973 }
974 fViewer.refresh(fNode);
975 }
976 });
977
978 label = new Label(this, SWT.NONE);
979 label.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));
980 label.setText(Messages.FilterViewer_TypeLabel);
981
982 Composite typeGroup = new Composite(this, SWT.NONE);
983 GridLayout tggl = new GridLayout(3, false);
984 tggl.marginHeight = 0;
985 tggl.marginWidth = 0;
986 typeGroup.setLayout(tggl);
987 typeGroup.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));
988
989 fNumButton = new Button(typeGroup, SWT.RADIO);
990 fNumButton.setSelection(fNode.getType() == Type.NUM);
991 fNumButton.setText(Messages.FilterViewer_NumButtonText);
992 fNumButton.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));
993 fNumButton.addSelectionListener(new SelectionAdapter() {
994 @Override
995 public void widgetSelected(SelectionEvent e) {
996 if (fNumButton.getSelection()) {
997 fNode.setType(Type.NUM);
998 }
999 fViewer.refresh(fNode);
1000 }
1001 });
1002
1003 fAlphaButton = new Button(typeGroup, SWT.RADIO);
1004 fAlphaButton.setSelection(fNode.getType() == Type.ALPHA);
1005 fAlphaButton.setText(Messages.FilterViewer_AlphaButtonText);
1006 fAlphaButton.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));
1007 fAlphaButton.addSelectionListener(new SelectionAdapter() {
1008 @Override
1009 public void widgetSelected(SelectionEvent e) {
1010 if (fAlphaButton.getSelection()) {
1011 fNode.setType(Type.ALPHA);
1012 }
1013 fViewer.refresh(fNode);
1014 }
1015 });
1016
1017 fTimestampButton = new Button(typeGroup, SWT.RADIO);
1018 fTimestampButton.setSelection(fNode.getType() == Type.TIMESTAMP);
1019 fTimestampButton.setText(Messages.FilterViewer_TimestampButtonText);
1020 fTimestampButton.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));
1021 fTimestampButton.addSelectionListener(new SelectionAdapter() {
1022 @Override
1023 public void widgetSelected(SelectionEvent e) {
1024 if (fTimestampButton.getSelection()) {
1025 fNode.setType(Type.TIMESTAMP);
1026 }
1027 fViewer.refresh(fNode);
1028 }
1029 });
1030
1031 label = new Label(this, SWT.NONE);
1032 label.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));
1033 label.setText(Messages.FilterViewer_ValueLabel);
1034
1035 fValueText = new Text(this, SWT.BORDER);
1036 fValueText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
1037 if (node.getValue() != null && node.getValue().length() > 0) {
1038 fValueText.setText(node.getValue());
1039 } else {
1040 fValueText.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_GRAY));
1041 fValueText.setText(Messages.FilterViewer_ValueHint);
1042 }
1043 fValueText.addFocusListener(new FocusListener() {
1044 @Override
1045 public void focusLost(FocusEvent e) {
1046 if (fNode.getValue() == null || fNode.getValue().length() == 0) {
1047 fValueText.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_GRAY));
1048 fValueText.setText(Messages.FilterViewer_ValueHint);
1049 }
1050 }
1051 @Override
1052 public void focusGained(FocusEvent e) {
1053 if (fValueText.getForeground().equals(Display.getCurrent().getSystemColor(SWT.COLOR_GRAY))) {
1054 fValueText.setText(""); //$NON-NLS-1$
1055 }
1056 fValueText.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_BLACK));
1057 }
1058 });
1059 fValueText.addModifyListener(new ModifyListener() {
1060 @Override
1061 public void modifyText(ModifyEvent e) {
1062 if (! fValueText.getForeground().equals(Display.getCurrent().getSystemColor(SWT.COLOR_GRAY))) {
1063 fNode.setValue(fValueText.getText());
1064 fViewer.refresh(fNode);
1065 }
1066 }
1067 });
1068 }
1069 }
1070
1071 }
This page took 0.0559 seconds and 5 git commands to generate.