Search in sources :

Example 21 with ITmfFilterTreeNode

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

the class FilterView method addFilter.

/**
 * Add a filter to the FilterView and select it. This does not modify the
 * XML, which must be done manually. If an equivalent filter is already in
 * the FilterView, it is not added.
 *
 * @param filter
 *            The filter to add.
 */
public void addFilter(ITmfFilterTreeNode filter) {
    if (filter == null) {
        return;
    }
    ITmfFilterTreeNode root = fViewer.getInput();
    for (ITmfFilterTreeNode node : root.getChildren()) {
        // Use toString(explicit) equality because equals() is not implemented
        if (node.toString(true).equals(filter.toString(true))) {
            fViewer.setSelection(node);
            return;
        }
    }
    root.addChild(filter.clone());
    fViewer.setInput(root);
    fViewer.setSelection(filter);
}
Also used : ITmfFilterTreeNode(org.eclipse.tracecompass.tmf.core.filter.model.ITmfFilterTreeNode)

Example 22 with ITmfFilterTreeNode

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

the class FilterViewer method fillContextMenu.

/**
 * Fill the context menu for the tree viewer.
 *
 * @param manager
 *            The menu manager
 */
protected void fillContextMenu(IMenuManager manager) {
    final ISelection selection = fViewer.getSelection();
    ITmfFilterTreeNode filterTreeNode = null;
    if (selection instanceof StructuredSelection) {
        Object element = ((StructuredSelection) selection).getFirstElement();
        if (element instanceof ITmfFilterTreeNode) {
            filterTreeNode = (ITmfFilterTreeNode) element;
        }
    }
    final ITmfFilterTreeNode selectedNode = filterTreeNode;
    if (selectedNode != null) {
        fillContextMenuForNode(selectedNode, manager);
    }
    // $NON-NLS-1$
    manager.add(new Separator("delete"));
    if (fIsDialog && (selectedNode != null)) {
        Action deleteAction = new Action(Messages.FilterViewer_DeleteActionText) {

            @Override
            public void run() {
                selectedNode.remove();
                fViewer.refresh();
            }
        };
        deleteAction.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_TOOL_DELETE));
        manager.add(deleteAction);
    }
    // $NON-NLS-1$
    manager.add(new Separator("edit"));
    if (fViewer.getInput() instanceof TmfFilterRootNode || filterTreeNode == null) {
        manager.add(new Separator());
        ITmfFilterTreeNode root = (ITmfFilterTreeNode) fViewer.getInput();
        fillContextMenuForNode(root, manager);
    }
}
Also used : ITmfFilterTreeNode(org.eclipse.tracecompass.tmf.core.filter.model.ITmfFilterTreeNode) Action(org.eclipse.jface.action.Action) ISelection(org.eclipse.jface.viewers.ISelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) TmfFilterRootNode(org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterRootNode) Separator(org.eclipse.jface.action.Separator)

Example 23 with ITmfFilterTreeNode

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

the class FilterViewer method getSelection.

public ITmfFilterTreeNode getSelection() {
    final ISelection selection = fViewer.getSelection();
    ITmfFilterTreeNode filterTreeNode = null;
    if (selection instanceof StructuredSelection) {
        Object element = ((StructuredSelection) selection).getFirstElement();
        if (element instanceof ITmfFilterTreeNode) {
            filterTreeNode = (ITmfFilterTreeNode) element;
        }
    }
    final ITmfFilterTreeNode selectedNode = filterTreeNode;
    return selectedNode;
}
Also used : ITmfFilterTreeNode(org.eclipse.tracecompass.tmf.core.filter.model.ITmfFilterTreeNode) ISelection(org.eclipse.jface.viewers.ISelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection)

Example 24 with ITmfFilterTreeNode

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

the class PasteHandler method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    // Check if we are closing down
    IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    if (window == null) {
        return null;
    }
    // Get the selection
    IWorkbenchPage page = window.getActivePage();
    IWorkbenchPart part = page.getActivePart();
    if (!(part instanceof FilterView)) {
        return null;
    }
    FilterView v = (FilterView) part;
    ITmfFilterTreeNode objectToPaste = FilterEditUtils.getTransferredTreeNode();
    objectToPaste = objectToPaste.clone();
    ITmfFilterTreeNode sel = v.getSelection();
    if (sel == null || TmfFilterNode.NODE_NAME.equals(objectToPaste.getNodeName())) {
        sel = v.getFilterRoot();
    }
    sel.addChild(objectToPaste);
    v.refresh();
    v.setSelection(objectToPaste);
    return null;
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) ITmfFilterTreeNode(org.eclipse.tracecompass.tmf.core.filter.model.ITmfFilterTreeNode) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage)

Example 25 with ITmfFilterTreeNode

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

the class PasteHandler method isEnabled.

@Override
public boolean isEnabled() {
    // Check if we are closing down
    IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    if (window == null) {
        return false;
    }
    // Get the selection
    IWorkbenchPage page = window.getActivePage();
    IWorkbenchPart part = page.getActivePart();
    if (!(part instanceof FilterView)) {
        return false;
    }
    FilterView v = (FilterView) part;
    ITmfFilterTreeNode sel = v.getSelection();
    if (sel == null) {
        sel = v.getFilterRoot();
    }
    ITmfFilterTreeNode objectToPaste = FilterEditUtils.getTransferredTreeNode();
    return (v.isTreeInFocus() && objectToPaste != null && (sel.getValidChildren().contains(objectToPaste.getNodeName()) || TmfFilterNode.NODE_NAME.equals(objectToPaste.getNodeName())));
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) ITmfFilterTreeNode(org.eclipse.tracecompass.tmf.core.filter.model.ITmfFilterTreeNode) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage)

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