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