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