| 1 | /******************************************************************************* |
| 2 | * Copyright (c) 2010, 2013 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 | ITmfFilterTreeNode curNode = node; |
| 358 | while (curNode != null) { |
| 359 | if (curNode instanceof TmfFilterEventTypeNode) { |
| 360 | TmfFilterEventTypeNode eventTypeNode = (TmfFilterEventTypeNode) curNode; |
| 361 | for (IConfigurationElement ce : TmfTraceType.getTypeElements()) { |
| 362 | if (ce.getAttribute(TmfTraceType.EVENT_TYPE_ATTR).equals(eventTypeNode.getEventType())) { |
| 363 | try { |
| 364 | ITmfEvent event = (ITmfEvent) ce.createExecutableExtension(TmfTraceType.EVENT_TYPE_ATTR); |
| 365 | ITmfEventType eventType = event.getType(); |
| 366 | if (eventType != null) { |
| 367 | for (String field : eventType.getRootField().getFieldNames()) { |
| 368 | fieldsList.add(field); |
| 369 | } |
| 370 | } |
| 371 | } catch (CoreException e) { |
| 372 | } |
| 373 | if (fieldsList.size() == 0) { |
| 374 | fieldsList.add(ITmfEvent.EVENT_FIELD_TIMESTAMP); |
| 375 | fieldsList.add(ITmfEvent.EVENT_FIELD_SOURCE); |
| 376 | fieldsList.add(ITmfEvent.EVENT_FIELD_TYPE); |
| 377 | fieldsList.add(ITmfEvent.EVENT_FIELD_REFERENCE); |
| 378 | fieldsList.add(ITmfEvent.EVENT_FIELD_CONTENT); |
| 379 | } |
| 380 | return fieldsList.toArray(new String[0]); |
| 381 | } |
| 382 | } |
| 383 | if (eventTypeNode.getEventType() != null && eventTypeNode.getEventType().startsWith(CustomTxtEvent.class.getCanonicalName())) { |
| 384 | for (CustomTxtTraceDefinition def : CustomTxtTraceDefinition.loadAll()) { |
| 385 | if (eventTypeNode.getEventType().equals(CustomTxtEvent.class.getCanonicalName() + ":" + def.definitionName)) { //$NON-NLS-1$ |
| 386 | for (OutputColumn output : def.outputs) { |
| 387 | fieldsList.add(output.name); |
| 388 | } |
| 389 | return fieldsList.toArray(new String[0]); |
| 390 | } |
| 391 | } |
| 392 | } |
| 393 | if (eventTypeNode.getEventType() != null && eventTypeNode.getEventType().startsWith(CustomXmlEvent.class.getCanonicalName())) { |
| 394 | for (CustomXmlTraceDefinition def : CustomXmlTraceDefinition.loadAll()) { |
| 395 | if (eventTypeNode.getEventType().equals(CustomXmlEvent.class.getCanonicalName() + ":" + def.definitionName)) { //$NON-NLS-1$ |
| 396 | for (OutputColumn output : def.outputs) { |
| 397 | fieldsList.add(output.name); |
| 398 | } |
| 399 | return fieldsList.toArray(new String[0]); |
| 400 | } |
| 401 | } |
| 402 | } |
| 403 | } |
| 404 | curNode = curNode.getParent(); |
| 405 | } |
| 406 | |
| 407 | fieldsList.add(Messages.FilterViewer_CommonCategory); |
| 408 | fieldsList.add(ITmfEvent.EVENT_FIELD_TIMESTAMP); |
| 409 | fieldsList.add(ITmfEvent.EVENT_FIELD_SOURCE); |
| 410 | fieldsList.add(ITmfEvent.EVENT_FIELD_TYPE); |
| 411 | fieldsList.add(ITmfEvent.EVENT_FIELD_REFERENCE); |
| 412 | fieldsList.add(ITmfEvent.EVENT_FIELD_CONTENT); |
| 413 | fieldsList.add(""); //$NON-NLS-1$ |
| 414 | |
| 415 | for (IConfigurationElement ce : TmfTraceType.getTypeElements()) { |
| 416 | try { |
| 417 | ITmfEvent event = (ITmfEvent) ce.createExecutableExtension(TmfTraceType.EVENT_TYPE_ATTR); |
| 418 | ITmfEventType eventType = event.getType(); |
| 419 | if (eventType != null && eventType.getFieldNames().length > 0) { |
| 420 | fieldsList.add("[" + TmfTraceType.getCategoryName(ce.getAttribute(TmfTraceType.CATEGORY_ATTR)) + //$NON-NLS-1$ |
| 421 | " : " + ce.getAttribute(TmfTraceType.NAME_ATTR) + "]"); //$NON-NLS-1$ //$NON-NLS-2$ |
| 422 | for (String field : eventType.getFieldNames()) { |
| 423 | fieldsList.add(field); |
| 424 | } |
| 425 | fieldsList.add(""); //$NON-NLS-1$ |
| 426 | } |
| 427 | } catch (CoreException e) { |
| 428 | } |
| 429 | } |
| 430 | for (CustomTxtTraceDefinition def : CustomTxtTraceDefinition.loadAll()) { |
| 431 | if (def.outputs.size() > 0) { |
| 432 | fieldsList.add("[" + CUSTOM_TXT_CATEGORY + //$NON-NLS-1$ |
| 433 | " : " + def.definitionName + "]"); //$NON-NLS-1$ //$NON-NLS-2$ |
| 434 | for (OutputColumn output : def.outputs) { |
| 435 | fieldsList.add(output.name); |
| 436 | } |
| 437 | fieldsList.add(""); //$NON-NLS-1$ |
| 438 | } |
| 439 | } |
| 440 | for (CustomXmlTraceDefinition def : CustomXmlTraceDefinition.loadAll()) { |
| 441 | if (def.outputs.size() > 0) { |
| 442 | fieldsList.add("[" + CUSTOM_XML_CATEGORY + //$NON-NLS-1$ |
| 443 | " : " + def.definitionName + "]"); //$NON-NLS-1$ //$NON-NLS-2$ |
| 444 | for (OutputColumn output : def.outputs) { |
| 445 | fieldsList.add(output.name); |
| 446 | } |
| 447 | fieldsList.add(""); //$NON-NLS-1$ |
| 448 | } |
| 449 | } |
| 450 | return fieldsList.toArray(new String[0]); |
| 451 | } |
| 452 | } |
| 453 | |
| 454 | private class FilterNodeComposite extends FilterBaseNodeComposite { |
| 455 | TmfFilterNode fNode; |
| 456 | Text fNameText; |
| 457 | |
| 458 | FilterNodeComposite(Composite parent, TmfFilterNode node) { |
| 459 | super(parent); |
| 460 | fNode = node; |
| 461 | |
| 462 | Label label = new Label(this, SWT.NONE); |
| 463 | label.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE)); |
| 464 | label.setText(Messages.FilterViewer_NameLabel); |
| 465 | |
| 466 | fNameText = new Text(this, SWT.BORDER); |
| 467 | fNameText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); |
| 468 | if (node.getFilterName() != null && node.getFilterName().length() > 0) { |
| 469 | fNameText.setText(node.getFilterName()); |
| 470 | } else { |
| 471 | fNameText.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_GRAY)); |
| 472 | fNameText.setText(Messages.FilterViewer_FilterNameHint); |
| 473 | } |
| 474 | fNameText.addFocusListener(new FocusListener() { |
| 475 | @Override |
| 476 | public void focusLost(FocusEvent e) { |
| 477 | if (fNode.getFilterName() == null || fNode.getFilterName().length() == 0) { |
| 478 | fNameText.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_GRAY)); |
| 479 | fNameText.setText(Messages.FilterViewer_FilterNameHint); |
| 480 | } |
| 481 | } |
| 482 | @Override |
| 483 | public void focusGained(FocusEvent e) { |
| 484 | if (fNameText.getForeground().equals(Display.getCurrent().getSystemColor(SWT.COLOR_GRAY))) { |
| 485 | fNameText.setText(""); //$NON-NLS-1$ |
| 486 | } |
| 487 | fNameText.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_BLACK)); |
| 488 | } |
| 489 | }); |
| 490 | fNameText.addModifyListener(new ModifyListener() { |
| 491 | @Override |
| 492 | public void modifyText(ModifyEvent e) { |
| 493 | if (! fNameText.getForeground().equals(Display.getCurrent().getSystemColor(SWT.COLOR_GRAY))) { |
| 494 | fNode.setFilterName(fNameText.getText()); |
| 495 | fViewer.refresh(fNode); |
| 496 | } |
| 497 | } |
| 498 | }); |
| 499 | } |
| 500 | } |
| 501 | |
| 502 | private class FilterEventTypeNodeComposite extends FilterBaseNodeComposite { |
| 503 | TmfFilterEventTypeNode fNode; |
| 504 | Combo fTypeCombo; |
| 505 | Map<String, Object> fEventsTypeMap; |
| 506 | |
| 507 | FilterEventTypeNodeComposite(Composite parent, TmfFilterEventTypeNode node) { |
| 508 | super(parent); |
| 509 | fNode = node; |
| 510 | fEventsTypeMap = getEventsTypeMap(); |
| 511 | |
| 512 | Label label = new Label(this, SWT.NONE); |
| 513 | label.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE)); |
| 514 | label.setText(Messages.FilterViewer_TypeLabel); |
| 515 | |
| 516 | fTypeCombo = new Combo(this, SWT.DROP_DOWN | SWT.READ_ONLY); |
| 517 | fTypeCombo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); |
| 518 | fTypeCombo.setItems(fEventsTypeMap.keySet().toArray(new String[0])); |
| 519 | if (fNode.getEventType() != null) { |
| 520 | for (Entry <String, Object> eventTypeEntry : fEventsTypeMap.entrySet()) { |
| 521 | Object value = eventTypeEntry.getValue(); |
| 522 | if (value instanceof IConfigurationElement) { |
| 523 | IConfigurationElement ce = (IConfigurationElement) value; |
| 524 | if (ce.getAttribute(TmfTraceType.EVENT_TYPE_ATTR).equals(fNode.getEventType())) { |
| 525 | fTypeCombo.setText(eventTypeEntry.getKey()); |
| 526 | } |
| 527 | } else if (value instanceof CustomTxtTraceDefinition) { |
| 528 | CustomTxtTraceDefinition def = (CustomTxtTraceDefinition) value; |
| 529 | String eventType = CustomTxtEvent.class.getCanonicalName() + ":" + def.definitionName; //$NON-NLS-1$ |
| 530 | if (eventType.equals(fNode.getEventType())) { |
| 531 | fTypeCombo.setText(eventTypeEntry.getKey()); |
| 532 | } |
| 533 | } else if (value instanceof CustomXmlTraceDefinition) { |
| 534 | CustomXmlTraceDefinition def = (CustomXmlTraceDefinition) value; |
| 535 | String eventType = CustomXmlEvent.class.getCanonicalName() + ":" + def.definitionName; //$NON-NLS-1$ |
| 536 | if (eventType.equals(fNode.getEventType())) { |
| 537 | fTypeCombo.setText(eventTypeEntry.getKey()); |
| 538 | } |
| 539 | } |
| 540 | } |
| 541 | } |
| 542 | fTypeCombo.addModifyListener(new ModifyListener() { |
| 543 | @Override |
| 544 | public void modifyText(ModifyEvent e) { |
| 545 | for (Entry <String, Object> eventTypeEntry : fEventsTypeMap.entrySet()) { |
| 546 | if (eventTypeEntry.getKey().equals(fTypeCombo.getText())) { |
| 547 | Object value = eventTypeEntry.getValue(); |
| 548 | if (value instanceof IConfigurationElement) { |
| 549 | IConfigurationElement ce = (IConfigurationElement) value; |
| 550 | fNode.setEventType(ce.getAttribute(TmfTraceType.EVENT_TYPE_ATTR)); |
| 551 | fNode.setName(ce.getAttribute(TmfTraceType.NAME_ATTR)); |
| 552 | } else if (value instanceof CustomTxtTraceDefinition) { |
| 553 | CustomTxtTraceDefinition def = (CustomTxtTraceDefinition) value; |
| 554 | fNode.setEventType(CustomTxtEvent.class.getCanonicalName() + ":" + def.definitionName); //$NON-NLS-1$ |
| 555 | fNode.setName(def.definitionName); |
| 556 | } else if (value instanceof CustomXmlTraceDefinition) { |
| 557 | CustomXmlTraceDefinition def = (CustomXmlTraceDefinition) value; |
| 558 | fNode.setEventType(CustomXmlEvent.class.getCanonicalName() + ":" + def.definitionName); //$NON-NLS-1$ |
| 559 | fNode.setName(def.definitionName); |
| 560 | } |
| 561 | fViewer.refresh(fNode); |
| 562 | break; |
| 563 | } |
| 564 | } |
| 565 | } |
| 566 | }); |
| 567 | } |
| 568 | |
| 569 | protected Map<String, Object> getEventsTypeMap() { |
| 570 | Map<String, Object> eventsTypeMap = new LinkedHashMap<String, Object>(); |
| 571 | for (IConfigurationElement ce : TmfTraceType.getTypeElements()) { |
| 572 | String categoryName = TmfTraceType.getCategoryName(ce.getAttribute(TmfTraceType.CATEGORY_ATTR)); |
| 573 | String text = categoryName + " : " + ce.getAttribute(TmfTraceType.NAME_ATTR); //$NON-NLS-1$ |
| 574 | eventsTypeMap.put(text, ce); |
| 575 | } |
| 576 | for (CustomTxtTraceDefinition def : CustomTxtTraceDefinition.loadAll()) { |
| 577 | String text = CUSTOM_TXT_CATEGORY + " : " + def.definitionName; //$NON-NLS-1$ |
| 578 | eventsTypeMap.put(text, def); |
| 579 | } |
| 580 | for (CustomXmlTraceDefinition def : CustomXmlTraceDefinition.loadAll()) { |
| 581 | String text = CUSTOM_XML_CATEGORY + " : " + def.definitionName; //$NON-NLS-1$ |
| 582 | eventsTypeMap.put(text, def); |
| 583 | } |
| 584 | return eventsTypeMap; |
| 585 | } |
| 586 | } |
| 587 | |
| 588 | private class FilterAndNodeComposite extends FilterBaseNodeComposite { |
| 589 | TmfFilterAndNode fNode; |
| 590 | Button fNotButton; |
| 591 | |
| 592 | FilterAndNodeComposite(Composite parent, TmfFilterAndNode node) { |
| 593 | super(parent); |
| 594 | fNode = node; |
| 595 | |
| 596 | Label label = new Label(this, SWT.NONE); |
| 597 | label.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE)); |
| 598 | label.setText(Messages.FilterViewer_NotLabel); |
| 599 | |
| 600 | fNotButton = new Button(this, SWT.CHECK); |
| 601 | fNotButton.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE)); |
| 602 | fNotButton.setSelection(fNode.isNot()); |
| 603 | fNotButton.addSelectionListener(new SelectionAdapter() { |
| 604 | @Override |
| 605 | public void widgetSelected(SelectionEvent e) { |
| 606 | fNode.setNot(fNotButton.getSelection()); |
| 607 | fViewer.refresh(fNode); |
| 608 | } |
| 609 | }); |
| 610 | } |
| 611 | } |
| 612 | |
| 613 | private class FilterOrNodeComposite extends FilterBaseNodeComposite { |
| 614 | TmfFilterOrNode fNode; |
| 615 | Button fNotButton; |
| 616 | |
| 617 | FilterOrNodeComposite(Composite parent, TmfFilterOrNode node) { |
| 618 | super(parent); |
| 619 | fNode = node; |
| 620 | |
| 621 | Label label = new Label(this, SWT.NONE); |
| 622 | label.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE)); |
| 623 | label.setText(Messages.FilterViewer_NotLabel); |
| 624 | |
| 625 | fNotButton = new Button(this, SWT.CHECK); |
| 626 | fNotButton.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE)); |
| 627 | fNotButton.setSelection(fNode.isNot()); |
| 628 | fNotButton.addSelectionListener(new SelectionAdapter() { |
| 629 | @Override |
| 630 | public void widgetSelected(SelectionEvent e) { |
| 631 | fNode.setNot(fNotButton.getSelection()); |
| 632 | fViewer.refresh(fNode); |
| 633 | } |
| 634 | }); |
| 635 | } |
| 636 | } |
| 637 | |
| 638 | private class FilterContainsNodeComposite extends FilterBaseNodeComposite { |
| 639 | TmfFilterContainsNode fNode; |
| 640 | Button fNotButton; |
| 641 | Combo fFieldCombo; |
| 642 | Text fValueText; |
| 643 | Button fIgnoreCaseButton; |
| 644 | |
| 645 | FilterContainsNodeComposite(Composite parent, TmfFilterContainsNode node) { |
| 646 | super(parent); |
| 647 | fNode = node; |
| 648 | |
| 649 | Label label = new Label(this, SWT.NONE); |
| 650 | label.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE)); |
| 651 | label.setText(Messages.FilterViewer_NotLabel); |
| 652 | |
| 653 | fNotButton = new Button(this, SWT.CHECK); |
| 654 | fNotButton.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE)); |
| 655 | fNotButton.setSelection(fNode.isNot()); |
| 656 | fNotButton.addSelectionListener(new SelectionAdapter() { |
| 657 | @Override |
| 658 | public void widgetSelected(SelectionEvent e) { |
| 659 | fNode.setNot(fNotButton.getSelection()); |
| 660 | fViewer.refresh(fNode); |
| 661 | } |
| 662 | }); |
| 663 | |
| 664 | label = new Label(this, SWT.NONE); |
| 665 | label.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE)); |
| 666 | label.setText(Messages.FilterViewer_FieldLabel); |
| 667 | |
| 668 | fFieldCombo = new Combo(this, SWT.DROP_DOWN); |
| 669 | fFieldCombo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); |
| 670 | fFieldCombo.setItems(getFieldsList(fNode)); |
| 671 | if (fNode.getField() != null) { |
| 672 | fFieldCombo.setText(fNode.getField()); |
| 673 | } |
| 674 | fFieldCombo.addModifyListener(new ModifyListener() { |
| 675 | @Override |
| 676 | public void modifyText(ModifyEvent e) { |
| 677 | fNode.setField(fFieldCombo.getText()); |
| 678 | fViewer.refresh(fNode); |
| 679 | } |
| 680 | }); |
| 681 | |
| 682 | label = new Label(this, SWT.NONE); |
| 683 | label.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE)); |
| 684 | label.setText(Messages.FilterViewer_ValueLabel); |
| 685 | |
| 686 | fValueText = new Text(this, SWT.BORDER); |
| 687 | fValueText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); |
| 688 | if (node.getValue() != null && node.getValue().length() > 0) { |
| 689 | fValueText.setText(node.getValue()); |
| 690 | } else { |
| 691 | fValueText.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_GRAY)); |
| 692 | fValueText.setText(Messages.FilterViewer_ValueHint); |
| 693 | } |
| 694 | fValueText.addFocusListener(new FocusListener() { |
| 695 | @Override |
| 696 | public void focusLost(FocusEvent e) { |
| 697 | if (fNode.getValue() == null || fNode.getValue().length() == 0) { |
| 698 | fValueText.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_GRAY)); |
| 699 | fValueText.setText(Messages.FilterViewer_ValueHint); |
| 700 | } |
| 701 | } |
| 702 | @Override |
| 703 | public void focusGained(FocusEvent e) { |
| 704 | if (fValueText.getForeground().equals(Display.getCurrent().getSystemColor(SWT.COLOR_GRAY))) { |
| 705 | fValueText.setText(""); //$NON-NLS-1$ |
| 706 | } |
| 707 | fValueText.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_BLACK)); |
| 708 | } |
| 709 | }); |
| 710 | fValueText.addModifyListener(new ModifyListener() { |
| 711 | @Override |
| 712 | public void modifyText(ModifyEvent e) { |
| 713 | if (! fValueText.getForeground().equals(Display.getCurrent().getSystemColor(SWT.COLOR_GRAY))) { |
| 714 | fNode.setValue(fValueText.getText()); |
| 715 | fViewer.refresh(fNode); |
| 716 | } |
| 717 | } |
| 718 | }); |
| 719 | |
| 720 | label = new Label(this, SWT.NONE); |
| 721 | label.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE)); |
| 722 | |
| 723 | fIgnoreCaseButton = new Button(this, SWT.CHECK); |
| 724 | fIgnoreCaseButton.setSelection(fNode.isIgnoreCase()); |
| 725 | fIgnoreCaseButton.setText(Messages.FilterViewer_IgnoreCaseButtonText); |
| 726 | fIgnoreCaseButton.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE)); |
| 727 | fIgnoreCaseButton.addSelectionListener(new SelectionAdapter() { |
| 728 | @Override |
| 729 | public void widgetSelected(SelectionEvent e) { |
| 730 | fNode.setIgnoreCase(fIgnoreCaseButton.getSelection()); |
| 731 | fViewer.refresh(fNode); |
| 732 | } |
| 733 | }); |
| 734 | } |
| 735 | } |
| 736 | |
| 737 | private class FilterEqualsNodeComposite extends FilterBaseNodeComposite { |
| 738 | TmfFilterEqualsNode fNode; |
| 739 | Button fNotButton; |
| 740 | Combo fFieldCombo; |
| 741 | Text fValueText; |
| 742 | Button fIgnoreCaseButton; |
| 743 | |
| 744 | FilterEqualsNodeComposite(Composite parent, TmfFilterEqualsNode node) { |
| 745 | super(parent); |
| 746 | fNode = node; |
| 747 | |
| 748 | Label label = new Label(this, SWT.NONE); |
| 749 | label.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE)); |
| 750 | label.setText(Messages.FilterViewer_NotLabel); |
| 751 | |
| 752 | fNotButton = new Button(this, SWT.CHECK); |
| 753 | fNotButton.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE)); |
| 754 | fNotButton.setSelection(fNode.isNot()); |
| 755 | fNotButton.addSelectionListener(new SelectionAdapter() { |
| 756 | @Override |
| 757 | public void widgetSelected(SelectionEvent e) { |
| 758 | fNode.setNot(fNotButton.getSelection()); |
| 759 | fViewer.refresh(fNode); |
| 760 | } |
| 761 | }); |
| 762 | |
| 763 | label = new Label(this, SWT.NONE); |
| 764 | label.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE)); |
| 765 | label.setText(Messages.FilterViewer_FieldLabel); |
| 766 | |
| 767 | fFieldCombo = new Combo(this, SWT.DROP_DOWN); |
| 768 | fFieldCombo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); |
| 769 | fFieldCombo.setItems(getFieldsList(fNode)); |
| 770 | if (fNode.getField() != null) { |
| 771 | fFieldCombo.setText(fNode.getField()); |
| 772 | } |
| 773 | fFieldCombo.addModifyListener(new ModifyListener() { |
| 774 | @Override |
| 775 | public void modifyText(ModifyEvent e) { |
| 776 | fNode.setField(fFieldCombo.getText()); |
| 777 | fViewer.refresh(fNode); |
| 778 | } |
| 779 | }); |
| 780 | |
| 781 | label = new Label(this, SWT.NONE); |
| 782 | label.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE)); |
| 783 | label.setText(Messages.FilterViewer_ValueLabel); |
| 784 | |
| 785 | fValueText = new Text(this, SWT.BORDER); |
| 786 | fValueText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); |
| 787 | if (node.getValue() != null && node.getValue().length() > 0) { |
| 788 | fValueText.setText(node.getValue()); |
| 789 | } else { |
| 790 | fValueText.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_GRAY)); |
| 791 | fValueText.setText(Messages.FilterViewer_ValueHint); |
| 792 | } |
| 793 | fValueText.addFocusListener(new FocusListener() { |
| 794 | @Override |
| 795 | public void focusLost(FocusEvent e) { |
| 796 | if (fNode.getValue() == null || fNode.getValue().length() == 0) { |
| 797 | fValueText.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_GRAY)); |
| 798 | fValueText.setText(Messages.FilterViewer_ValueHint); |
| 799 | } |
| 800 | } |
| 801 | @Override |
| 802 | public void focusGained(FocusEvent e) { |
| 803 | if (fValueText.getForeground().equals(Display.getCurrent().getSystemColor(SWT.COLOR_GRAY))) { |
| 804 | fValueText.setText(""); //$NON-NLS-1$ |
| 805 | } |
| 806 | fValueText.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_BLACK)); |
| 807 | } |
| 808 | }); |
| 809 | fValueText.addModifyListener(new ModifyListener() { |
| 810 | @Override |
| 811 | public void modifyText(ModifyEvent e) { |
| 812 | if (! fValueText.getForeground().equals(Display.getCurrent().getSystemColor(SWT.COLOR_GRAY))) { |
| 813 | fNode.setValue(fValueText.getText()); |
| 814 | fViewer.refresh(fNode); |
| 815 | } |
| 816 | } |
| 817 | }); |
| 818 | |
| 819 | label = new Label(this, SWT.NONE); |
| 820 | label.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE)); |
| 821 | |
| 822 | fIgnoreCaseButton = new Button(this, SWT.CHECK); |
| 823 | fIgnoreCaseButton.setSelection(fNode.isIgnoreCase()); |
| 824 | fIgnoreCaseButton.setText(Messages.FilterViewer_IgnoreCaseButtonText); |
| 825 | fIgnoreCaseButton.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE)); |
| 826 | fIgnoreCaseButton.addSelectionListener(new SelectionAdapter() { |
| 827 | @Override |
| 828 | public void widgetSelected(SelectionEvent e) { |
| 829 | fNode.setIgnoreCase(fIgnoreCaseButton.getSelection()); |
| 830 | fViewer.refresh(fNode); |
| 831 | } |
| 832 | }); |
| 833 | } |
| 834 | } |
| 835 | |
| 836 | private class FilterMatchesNodeComposite extends FilterBaseNodeComposite { |
| 837 | TmfFilterMatchesNode fNode; |
| 838 | Button fNotButton; |
| 839 | Combo fFieldCombo; |
| 840 | Text fRegexText; |
| 841 | |
| 842 | FilterMatchesNodeComposite(Composite parent, TmfFilterMatchesNode node) { |
| 843 | super(parent); |
| 844 | fNode = node; |
| 845 | |
| 846 | Label label = new Label(this, SWT.NONE); |
| 847 | label.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE)); |
| 848 | label.setText(Messages.FilterViewer_NotLabel); |
| 849 | |
| 850 | fNotButton = new Button(this, SWT.CHECK); |
| 851 | fNotButton.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE)); |
| 852 | fNotButton.setSelection(fNode.isNot()); |
| 853 | fNotButton.addSelectionListener(new SelectionAdapter() { |
| 854 | @Override |
| 855 | public void widgetSelected(SelectionEvent e) { |
| 856 | fNode.setNot(fNotButton.getSelection()); |
| 857 | fViewer.refresh(fNode); |
| 858 | } |
| 859 | }); |
| 860 | |
| 861 | label = new Label(this, SWT.NONE); |
| 862 | label.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE)); |
| 863 | label.setText(Messages.FilterViewer_FieldLabel); |
| 864 | |
| 865 | fFieldCombo = new Combo(this, SWT.DROP_DOWN); |
| 866 | fFieldCombo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); |
| 867 | fFieldCombo.setItems(getFieldsList(fNode)); |
| 868 | if (fNode.getField() != null) { |
| 869 | fFieldCombo.setText(fNode.getField()); |
| 870 | } |
| 871 | fFieldCombo.addModifyListener(new ModifyListener() { |
| 872 | @Override |
| 873 | public void modifyText(ModifyEvent e) { |
| 874 | fNode.setField(fFieldCombo.getText()); |
| 875 | fViewer.refresh(fNode); |
| 876 | } |
| 877 | }); |
| 878 | |
| 879 | label = new Label(this, SWT.NONE); |
| 880 | label.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE)); |
| 881 | label.setText(Messages.FilterViewer_RegexLabel); |
| 882 | |
| 883 | fRegexText = new Text(this, SWT.BORDER); |
| 884 | fRegexText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); |
| 885 | if (node.getRegex() != null && node.getRegex().length() > 0) { |
| 886 | fRegexText.setText(node.getRegex()); |
| 887 | } else { |
| 888 | fRegexText.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_GRAY)); |
| 889 | fRegexText.setText(Messages.FilterViewer_RegexHint); |
| 890 | } |
| 891 | fRegexText.addFocusListener(new FocusListener() { |
| 892 | @Override |
| 893 | public void focusLost(FocusEvent e) { |
| 894 | if (fNode.getRegex() == null || fNode.getRegex().length() == 0) { |
| 895 | fRegexText.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_GRAY)); |
| 896 | fRegexText.setText(Messages.FilterViewer_RegexHint); |
| 897 | } |
| 898 | } |
| 899 | @Override |
| 900 | public void focusGained(FocusEvent e) { |
| 901 | if (fRegexText.getForeground().equals(Display.getCurrent().getSystemColor(SWT.COLOR_GRAY))) { |
| 902 | fRegexText.setText(""); //$NON-NLS-1$ |
| 903 | } |
| 904 | fRegexText.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_BLACK)); |
| 905 | } |
| 906 | }); |
| 907 | fRegexText.addModifyListener(new ModifyListener() { |
| 908 | @Override |
| 909 | public void modifyText(ModifyEvent e) { |
| 910 | if (! fRegexText.getForeground().equals(Display.getCurrent().getSystemColor(SWT.COLOR_GRAY))) { |
| 911 | fNode.setRegex(fRegexText.getText()); |
| 912 | fViewer.refresh(fNode); |
| 913 | } |
| 914 | } |
| 915 | }); |
| 916 | } |
| 917 | } |
| 918 | |
| 919 | private class FilterCompareNodeComposite extends FilterBaseNodeComposite { |
| 920 | TmfFilterCompareNode fNode; |
| 921 | Button fNotButton; |
| 922 | Combo fFieldCombo; |
| 923 | Text fValueText; |
| 924 | Button fLTButton; |
| 925 | Button fEQButton; |
| 926 | Button fGTButton; |
| 927 | Button fNumButton; |
| 928 | Button fAlphaButton; |
| 929 | Button fTimestampButton; |
| 930 | |
| 931 | FilterCompareNodeComposite(Composite parent, TmfFilterCompareNode node) { |
| 932 | super(parent); |
| 933 | fNode = node; |
| 934 | |
| 935 | Label label = new Label(this, SWT.NONE); |
| 936 | label.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE)); |
| 937 | label.setText(Messages.FilterViewer_NotLabel); |
| 938 | |
| 939 | fNotButton = new Button(this, SWT.CHECK); |
| 940 | fNotButton.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE)); |
| 941 | fNotButton.setSelection(fNode.isNot()); |
| 942 | fNotButton.addSelectionListener(new SelectionAdapter() { |
| 943 | @Override |
| 944 | public void widgetSelected(SelectionEvent e) { |
| 945 | fNode.setNot(fNotButton.getSelection()); |
| 946 | fViewer.refresh(fNode); |
| 947 | } |
| 948 | }); |
| 949 | |
| 950 | label = new Label(this, SWT.NONE); |
| 951 | label.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE)); |
| 952 | label.setText(Messages.FilterViewer_FieldLabel); |
| 953 | |
| 954 | fFieldCombo = new Combo(this, SWT.DROP_DOWN); |
| 955 | fFieldCombo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); |
| 956 | fFieldCombo.setItems(getFieldsList(fNode)); |
| 957 | if (fNode.getField() != null) { |
| 958 | fFieldCombo.setText(fNode.getField()); |
| 959 | } |
| 960 | fFieldCombo.addModifyListener(new ModifyListener() { |
| 961 | @Override |
| 962 | public void modifyText(ModifyEvent e) { |
| 963 | fNode.setField(fFieldCombo.getText()); |
| 964 | fViewer.refresh(fNode); |
| 965 | } |
| 966 | }); |
| 967 | |
| 968 | label = new Label(this, SWT.NONE); |
| 969 | label.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE)); |
| 970 | label.setText(Messages.FilterViewer_ResultLabel); |
| 971 | |
| 972 | Composite resultGroup = new Composite(this, SWT.NONE); |
| 973 | GridLayout rggl = new GridLayout(3, true); |
| 974 | rggl.marginHeight = 0; |
| 975 | rggl.marginWidth = 0; |
| 976 | resultGroup.setLayout(rggl); |
| 977 | resultGroup.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE)); |
| 978 | |
| 979 | fLTButton = new Button(resultGroup, SWT.RADIO); |
| 980 | fLTButton.setSelection(fNode.getResult() < 0); |
| 981 | fLTButton.setText("<"); //$NON-NLS-1$ |
| 982 | fLTButton.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE)); |
| 983 | fLTButton.addSelectionListener(new SelectionAdapter() { |
| 984 | @Override |
| 985 | public void widgetSelected(SelectionEvent e) { |
| 986 | if (fLTButton.getSelection()) { |
| 987 | fNode.setResult(-1); |
| 988 | } |
| 989 | fViewer.refresh(fNode); |
| 990 | } |
| 991 | }); |
| 992 | |
| 993 | fEQButton = new Button(resultGroup, SWT.RADIO); |
| 994 | fEQButton.setSelection(fNode.getResult() == 0); |
| 995 | fEQButton.setText("="); //$NON-NLS-1$ |
| 996 | fEQButton.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE)); |
| 997 | fEQButton.addSelectionListener(new SelectionAdapter() { |
| 998 | @Override |
| 999 | public void widgetSelected(SelectionEvent e) { |
| 1000 | if (fEQButton.getSelection()) { |
| 1001 | fNode.setResult(0); |
| 1002 | } |
| 1003 | fViewer.refresh(fNode); |
| 1004 | } |
| 1005 | }); |
| 1006 | |
| 1007 | fGTButton = new Button(resultGroup, SWT.RADIO); |
| 1008 | fGTButton.setSelection(fNode.getResult() > 0); |
| 1009 | fGTButton.setText(">"); //$NON-NLS-1$ |
| 1010 | fGTButton.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE)); |
| 1011 | fGTButton.addSelectionListener(new SelectionAdapter() { |
| 1012 | @Override |
| 1013 | public void widgetSelected(SelectionEvent e) { |
| 1014 | if (fGTButton.getSelection()) { |
| 1015 | fNode.setResult(1); |
| 1016 | } |
| 1017 | fViewer.refresh(fNode); |
| 1018 | } |
| 1019 | }); |
| 1020 | |
| 1021 | label = new Label(this, SWT.NONE); |
| 1022 | label.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE)); |
| 1023 | label.setText(Messages.FilterViewer_TypeLabel); |
| 1024 | |
| 1025 | Composite typeGroup = new Composite(this, SWT.NONE); |
| 1026 | GridLayout tggl = new GridLayout(3, false); |
| 1027 | tggl.marginHeight = 0; |
| 1028 | tggl.marginWidth = 0; |
| 1029 | typeGroup.setLayout(tggl); |
| 1030 | typeGroup.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE)); |
| 1031 | |
| 1032 | fNumButton = new Button(typeGroup, SWT.RADIO); |
| 1033 | fNumButton.setSelection(fNode.getType() == Type.NUM); |
| 1034 | fNumButton.setText(Messages.FilterViewer_NumButtonText); |
| 1035 | fNumButton.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE)); |
| 1036 | fNumButton.addSelectionListener(new SelectionAdapter() { |
| 1037 | @Override |
| 1038 | public void widgetSelected(SelectionEvent e) { |
| 1039 | if (fNumButton.getSelection()) { |
| 1040 | fNode.setType(Type.NUM); |
| 1041 | } |
| 1042 | fViewer.refresh(fNode); |
| 1043 | } |
| 1044 | }); |
| 1045 | |
| 1046 | fAlphaButton = new Button(typeGroup, SWT.RADIO); |
| 1047 | fAlphaButton.setSelection(fNode.getType() == Type.ALPHA); |
| 1048 | fAlphaButton.setText(Messages.FilterViewer_AlphaButtonText); |
| 1049 | fAlphaButton.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE)); |
| 1050 | fAlphaButton.addSelectionListener(new SelectionAdapter() { |
| 1051 | @Override |
| 1052 | public void widgetSelected(SelectionEvent e) { |
| 1053 | if (fAlphaButton.getSelection()) { |
| 1054 | fNode.setType(Type.ALPHA); |
| 1055 | } |
| 1056 | fViewer.refresh(fNode); |
| 1057 | } |
| 1058 | }); |
| 1059 | |
| 1060 | fTimestampButton = new Button(typeGroup, SWT.RADIO); |
| 1061 | fTimestampButton.setSelection(fNode.getType() == Type.TIMESTAMP); |
| 1062 | fTimestampButton.setText(Messages.FilterViewer_TimestampButtonText); |
| 1063 | fTimestampButton.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE)); |
| 1064 | fTimestampButton.addSelectionListener(new SelectionAdapter() { |
| 1065 | @Override |
| 1066 | public void widgetSelected(SelectionEvent e) { |
| 1067 | if (fTimestampButton.getSelection()) { |
| 1068 | fNode.setType(Type.TIMESTAMP); |
| 1069 | } |
| 1070 | fViewer.refresh(fNode); |
| 1071 | } |
| 1072 | }); |
| 1073 | |
| 1074 | label = new Label(this, SWT.NONE); |
| 1075 | label.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE)); |
| 1076 | label.setText(Messages.FilterViewer_ValueLabel); |
| 1077 | |
| 1078 | fValueText = new Text(this, SWT.BORDER); |
| 1079 | fValueText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); |
| 1080 | if (node.getValue() != null && node.getValue().length() > 0) { |
| 1081 | fValueText.setText(node.getValue()); |
| 1082 | } else { |
| 1083 | fValueText.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_GRAY)); |
| 1084 | fValueText.setText(Messages.FilterViewer_ValueHint); |
| 1085 | } |
| 1086 | fValueText.addFocusListener(new FocusListener() { |
| 1087 | @Override |
| 1088 | public void focusLost(FocusEvent e) { |
| 1089 | if (fNode.getValue() == null || fNode.getValue().length() == 0) { |
| 1090 | fValueText.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_GRAY)); |
| 1091 | fValueText.setText(Messages.FilterViewer_ValueHint); |
| 1092 | } |
| 1093 | } |
| 1094 | @Override |
| 1095 | public void focusGained(FocusEvent e) { |
| 1096 | if (fValueText.getForeground().equals(Display.getCurrent().getSystemColor(SWT.COLOR_GRAY))) { |
| 1097 | fValueText.setText(""); //$NON-NLS-1$ |
| 1098 | } |
| 1099 | fValueText.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_BLACK)); |
| 1100 | } |
| 1101 | }); |
| 1102 | fValueText.addModifyListener(new ModifyListener() { |
| 1103 | @Override |
| 1104 | public void modifyText(ModifyEvent e) { |
| 1105 | if (! fValueText.getForeground().equals(Display.getCurrent().getSystemColor(SWT.COLOR_GRAY))) { |
| 1106 | fNode.setValue(fValueText.getText()); |
| 1107 | fViewer.refresh(fNode); |
| 1108 | } |
| 1109 | } |
| 1110 | }); |
| 1111 | } |
| 1112 | } |
| 1113 | |
| 1114 | } |