Search in sources :

Example 26 with ITmfFilterTreeNode

use of org.eclipse.tracecompass.tmf.core.filter.model.ITmfFilterTreeNode in project tracecompass by tracecompass.

the class FilterViewer method fillContextMenuForNode.

/**
 * Fill the context menu with the valid children of the provided node
 *
 * @param node
 *            The target node
 * @param manager
 *            The menu manager
 */
protected void fillContextMenuForNode(final ITmfFilterTreeNode node, IMenuManager manager) {
    for (final String child : node.getValidChildren()) {
        final Action action = new Action() {

            @Override
            public void run() {
                ITmfFilterTreeNode newNode = null;
                if (TmfFilterNode.NODE_NAME.equals(child)) {
                    // $NON-NLS-1$
                    newNode = new TmfFilterNode(node, "");
                } else if (TmfFilterTraceTypeNode.NODE_NAME.equals(child)) {
                    newNode = new TmfFilterTraceTypeNode(node);
                } else if (TmfFilterAndNode.NODE_NAME.equals(child)) {
                    newNode = new TmfFilterAndNode(node);
                } else if (TmfFilterOrNode.NODE_NAME.equals(child)) {
                    newNode = new TmfFilterOrNode(node);
                } else if (TmfFilterContainsNode.NODE_NAME.equals(child)) {
                    newNode = new TmfFilterContainsNode(node);
                } else if (TmfFilterEqualsNode.NODE_NAME.equals(child)) {
                    newNode = new TmfFilterEqualsNode(node);
                } else if (TmfFilterMatchesNode.NODE_NAME.equals(child)) {
                    newNode = new TmfFilterMatchesNode(node);
                } else if (TmfFilterCompareNode.NODE_NAME.equals(child)) {
                    newNode = new TmfFilterCompareNode(node);
                }
                if (newNode != null) {
                    fViewer.refresh();
                    fViewer.setSelection(new StructuredSelection(newNode), true);
                }
            }
        };
        if (TmfFilterNode.NODE_NAME.equals(child)) {
            // $NON-NLS-1$
            action.setText(Messages.FilterViewer_NewPrefix + " " + child);
        } else {
            action.setText(child);
        }
        manager.add(action);
    }
}
Also used : ITmfFilterTreeNode(org.eclipse.tracecompass.tmf.core.filter.model.ITmfFilterTreeNode) Action(org.eclipse.jface.action.Action) TmfFilterOrNode(org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterOrNode) TmfFilterAndNode(org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterAndNode) TmfFilterContainsNode(org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterContainsNode) TmfFilterEqualsNode(org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterEqualsNode) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) TmfFilterNode(org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterNode) TmfFilterMatchesNode(org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterMatchesNode) TmfFilterTraceTypeNode(org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterTraceTypeNode) TmfFilterCompareNode(org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterCompareNode)

Example 27 with ITmfFilterTreeNode

use of org.eclipse.tracecompass.tmf.core.filter.model.ITmfFilterTreeNode in project tracecompass by tracecompass.

the class FilterDragSourceAdapter method dragFinished.

@Override
public void dragFinished(DragSourceEvent event) {
    if (event.detail == DND.DROP_MOVE) {
        IStructuredSelection selection = (IStructuredSelection) LocalSelectionTransfer.getTransfer().getSelection();
        for (Object data : selection.toList()) {
            if (data instanceof ITmfFilterTreeNode) {
                ITmfFilterTreeNode e = (ITmfFilterTreeNode) data;
                e.remove();
                fViewer.refresh();
            }
        }
    }
    LocalSelectionTransfer.getTransfer().setSelection(null);
    LocalSelectionTransfer.getTransfer().setSelectionSetTime(0);
}
Also used : ITmfFilterTreeNode(org.eclipse.tracecompass.tmf.core.filter.model.ITmfFilterTreeNode) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection)

Example 28 with ITmfFilterTreeNode

use of org.eclipse.tracecompass.tmf.core.filter.model.ITmfFilterTreeNode in project tracecompass by tracecompass.

the class FilterDropTargetAdapter method drop.

@Override
public void drop(DropTargetEvent event) {
    ITmfFilterTreeNode treeNodeToDrop = FilterEditUtils.getTransferredTreeNode();
    if (event.item instanceof TreeItem) {
        Object data = event.item.getData();
        if (data instanceof ITmfFilterTreeNode) {
            ITmfFilterTreeNode node = (ITmfFilterTreeNode) data;
            if (node.getValidChildren().contains(treeNodeToDrop.getNodeName())) {
                treeNodeToDrop = treeNodeToDrop.clone();
                node.addChild(treeNodeToDrop);
                fViewer.refresh();
                fViewer.setSelection(treeNodeToDrop, true);
                return;
            }
        }
    } else {
        // accept only TmfFilterNode
        if (TmfFilterNode.NODE_NAME.equals(treeNodeToDrop.getNodeName())) {
            ITmfFilterTreeNode root = fViewer.getInput();
            treeNodeToDrop = treeNodeToDrop.clone();
            root.addChild(treeNodeToDrop);
            fViewer.refresh();
            fViewer.setSelection(treeNodeToDrop, true);
            return;
        }
    }
}
Also used : ITmfFilterTreeNode(org.eclipse.tracecompass.tmf.core.filter.model.ITmfFilterTreeNode) TreeItem(org.eclipse.swt.widgets.TreeItem)

Example 29 with ITmfFilterTreeNode

use of org.eclipse.tracecompass.tmf.core.filter.model.ITmfFilterTreeNode in project tracecompass by tracecompass.

the class FilterEditUtils method getTransferredTreeNode.

/**
 * Gets the ITmfFilterTreeNode in LocalSelectionTransfer, if any
 * @return a ITmfFilterTreeNode or <code>null</code>
 */
public static ITmfFilterTreeNode getTransferredTreeNode() {
    ITmfFilterTreeNode treeNodeToDrop = null;
    ISelection sel = LocalSelectionTransfer.getTransfer().getSelection();
    if (sel instanceof IStructuredSelection) {
        IStructuredSelection selection = (IStructuredSelection) sel;
        for (Object data : selection.toList()) {
            if (!(data instanceof ITmfFilterTreeNode)) {
                return null;
            } else if (treeNodeToDrop != null) {
                // should never occur, since tree has SWT.SINGLE style
                return null;
            } else {
                treeNodeToDrop = (ITmfFilterTreeNode) data;
            }
        }
    }
    return treeNodeToDrop;
}
Also used : ITmfFilterTreeNode(org.eclipse.tracecompass.tmf.core.filter.model.ITmfFilterTreeNode) ISelection(org.eclipse.jface.viewers.ISelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection)

Example 30 with ITmfFilterTreeNode

use of org.eclipse.tracecompass.tmf.core.filter.model.ITmfFilterTreeNode in project tracecompass by tracecompass.

the class TmfFilterTreeNodeTestBase method testClone.

@Test
public void testClone() {
    ITmfFilterTreeNode clone = fFilterNode.clone();
    assertFalse("clone().equals()", fFilterNode.equals(clone));
    assertFalse("clone() ==", fFilterNode == clone);
    assertEquals("clone().toString.equals()", fFilterNode.toString(), clone.toString());
    assertNull("clone().getParent()", clone.getParent());
}
Also used : ITmfFilterTreeNode(org.eclipse.tracecompass.tmf.core.filter.model.ITmfFilterTreeNode) Test(org.junit.Test)

Aggregations

ITmfFilterTreeNode (org.eclipse.tracecompass.tmf.core.filter.model.ITmfFilterTreeNode)46 TmfFilterRootNode (org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterRootNode)18 Test (org.junit.Test)15 ITmfFilter (org.eclipse.tracecompass.tmf.core.filter.ITmfFilter)11 TmfFilterMatchesNode (org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterMatchesNode)10 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)7 ISelection (org.eclipse.jface.viewers.ISelection)5 TmfFilterAndNode (org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterAndNode)5 TmfFilterNode (org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterNode)5 TmfFilterOrNode (org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterOrNode)5 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)4 TmfFilterContainsNode (org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterContainsNode)4 TmfFilterEqualsNode (org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterEqualsNode)4 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)4 Action (org.eclipse.jface.action.Action)3 Point (org.eclipse.swt.graphics.Point)3 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)3 HashMap (java.util.HashMap)2 PatternSyntaxException (java.util.regex.PatternSyntaxException)2 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)2