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