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