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