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