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