Search in sources :

Example 16 with ITmfFilterTreeNode

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

the class ColorSettingsXML method save.

/**
 * Saves the given color settings to file.
 *
 * @param pathName
 *            A file name with path
 * @param colorSettings
 *            An array of color settings to save.
 */
public static void save(String pathName, ColorSetting[] colorSettings) {
    try {
        DocumentBuilder documentBuilder = XmlUtils.newSafeDocumentBuilderFactory().newDocumentBuilder();
        Document document = documentBuilder.newDocument();
        Element rootElement = document.createElement(COLOR_SETTINGS_TAG);
        document.appendChild(rootElement);
        for (ColorSetting colorSetting : colorSettings) {
            Element colorSettingElement = document.createElement(COLOR_SETTING_TAG);
            rootElement.appendChild(colorSettingElement);
            RGB foreground = colorSetting.getForegroundRGB();
            if (foreground != null) {
                Element fgElement = document.createElement(FG_TAG);
                colorSettingElement.appendChild(fgElement);
                setElementColor(fgElement, foreground);
            }
            RGB background = colorSetting.getBackgroundRGB();
            if (background != null) {
                Element bgElement = document.createElement(BG_TAG);
                colorSettingElement.appendChild(bgElement);
                setElementColor(bgElement, background);
            }
            Element tickColorElement = document.createElement(TICK_TAG);
            colorSettingElement.appendChild(tickColorElement);
            RGB tickColor = colorSetting.getTickColorRGB();
            setElementColor(tickColorElement, tickColor);
            ITmfFilterTreeNode filter = colorSetting.getFilter();
            if (filter != null) {
                Element filterElement = document.createElement(FILTER_TAG);
                colorSettingElement.appendChild(filterElement);
                TmfFilterXMLWriter.buildXMLTree(document, filter, filterElement);
            }
        }
        Transformer transformer = XmlUtils.newSecureTransformer();
        DOMSource source = new DOMSource(document);
        StreamResult result = new StreamResult(new File(pathName));
        transformer.transform(source, result);
    } catch (ParserConfigurationException | TransformerException e) {
        // $NON-NLS-1$
        Activator.getDefault().logError("Error saving color xml file: " + pathName, e);
    }
}
Also used : ITmfFilterTreeNode(org.eclipse.tracecompass.tmf.core.filter.model.ITmfFilterTreeNode) DOMSource(javax.xml.transform.dom.DOMSource) Transformer(javax.xml.transform.Transformer) StreamResult(javax.xml.transform.stream.StreamResult) Element(org.w3c.dom.Element) Document(org.w3c.dom.Document) RGB(org.eclipse.swt.graphics.RGB) DocumentBuilder(javax.xml.parsers.DocumentBuilder) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) File(java.io.File) TransformerException(javax.xml.transform.TransformerException)

Example 17 with ITmfFilterTreeNode

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

the class CutHandler method getSelection.

@Override
protected ISelection getSelection(FilterView tcv) {
    ISelection sel = super.getSelection(tcv);
    if (sel instanceof IStructuredSelection) {
        IStructuredSelection selection = (IStructuredSelection) sel;
        Object o = selection.getFirstElement();
        if (o instanceof ITmfFilterTreeNode) {
            ITmfFilterTreeNode node = (ITmfFilterTreeNode) o;
            node = node.remove();
            tcv.refresh();
            return new StructuredSelection(node);
        }
    }
    return sel;
}
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) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection)

Example 18 with ITmfFilterTreeNode

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

the class DeleteHandler 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;
    }
    IWorkbenchPage page = window.getActivePage();
    FilterView part = (FilterView) page.getActivePart();
    ISelection sel = part.getViewSite().getSelectionProvider().getSelection();
    if (sel instanceof IStructuredSelection) {
        IStructuredSelection selection = (IStructuredSelection) sel;
        Object o = selection.getFirstElement();
        if (o instanceof ITmfFilterTreeNode) {
            ITmfFilterTreeNode node = (ITmfFilterTreeNode) o;
            node.remove();
            part.refresh();
        }
    }
    return null;
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) ITmfFilterTreeNode(org.eclipse.tracecompass.tmf.core.filter.model.ITmfFilterTreeNode) ISelection(org.eclipse.jface.viewers.ISelection) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection)

Example 19 with ITmfFilterTreeNode

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

the class FilterDropTargetAdapter method isAncestor.

/**
 * Returns <code>true</code> if droppedNode is an ancestor of node.
 *
 * @param droppedNode
 *            the ITmfFilterTreeNode to drop or paste
 * @param node
 *            the ITmfFilterTreeNode receiving a new child
 * @return <code>true</code> if droppedNode is and ancestor of node,
 *         <code>false</code> otherwise.
 */
private static boolean isAncestor(ITmfFilterTreeNode droppedNode, ITmfFilterTreeNode node) {
    ITmfFilterTreeNode tmp = node;
    while (tmp != null) {
        ITmfFilterTreeNode n = tmp.getParent();
        if (n == droppedNode) {
            return true;
        }
        tmp = n;
    }
    return false;
}
Also used : ITmfFilterTreeNode(org.eclipse.tracecompass.tmf.core.filter.model.ITmfFilterTreeNode)

Example 20 with ITmfFilterTreeNode

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

the class FilterDropTargetAdapter method dropAccept.

@Override
public void dropAccept(DropTargetEvent event) {
    ITmfFilterTreeNode treeNodeToDrop = null;
    if (LocalSelectionTransfer.getTransfer().isSupportedType(event.currentDataType)) {
        treeNodeToDrop = FilterEditUtils.getTransferredTreeNode();
    }
    if (treeNodeToDrop == null) {
        // should never occur
        event.detail = DND.DROP_NONE;
        return;
    }
    if (event.item instanceof TreeItem) {
        Object data = event.item.getData();
        if (data instanceof ITmfFilterTreeNode) {
            ITmfFilterTreeNode node = (ITmfFilterTreeNode) data;
            if (node.getValidChildren().contains(treeNodeToDrop.getNodeName())) {
                if (isAncestor(treeNodeToDrop, node) && event.detail != DND.DROP_COPY) {
                    // do nothing in this case
                    event.detail = DND.DROP_NONE;
                }
                return;
            }
        }
    } else {
        // accept only TmfFilterNode
        if (!TmfFilterNode.NODE_NAME.equals(treeNodeToDrop.getNodeName())) {
            event.detail = DND.DROP_NONE;
        }
        return;
    }
    event.detail = DND.DROP_NONE;
    return;
}
Also used : ITmfFilterTreeNode(org.eclipse.tracecompass.tmf.core.filter.model.ITmfFilterTreeNode) TreeItem(org.eclipse.swt.widgets.TreeItem)

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