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