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