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