Search in sources :

Example 1 with Node

use of org.openide.nodes.Node in project gephi by gephi.

the class QueryExplorer method propertyChange.

@Override
public void propertyChange(PropertyChangeEvent evt) {
    if (evt.getPropertyName().equals(ExplorerManager.PROP_SELECTED_NODES)) {
        if (uiModel == null) {
            return;
        }
        Node[] nodeArray = (Node[]) evt.getNewValue();
        if (nodeArray.length > 0) {
            Node node = ((Node[]) evt.getNewValue())[0];
            if (node instanceof RootNode) {
                uiModel.setSelectedQuery(null);
                filterController.setCurrentQuery(null);
                return;
            }
            while (!(node instanceof QueryNode)) {
                node = node.getParentNode();
                if (node.getParentNode() == null) {
                    uiModel.setSelectedQuery(null);
                    filterController.setCurrentQuery(null);
                    return;
                }
            }
            QueryNode queryNode = (QueryNode) node;
            final Query query = queryNode.getQuery();
            new Thread(new Runnable() {

                @Override
                public void run() {
                    uiModel.setSelectedQuery(query);
                    model.removeChangeListener(QueryExplorer.this);
                    filterController.setCurrentQuery(uiModel.getSelectedRoot());
                    model.addChangeListener(QueryExplorer.this);
                }
            }).start();
        }
    }
}
Also used : Query(org.gephi.filters.api.Query) Node(org.openide.nodes.Node) AbstractNode(org.openide.nodes.AbstractNode)

Example 2 with Node

use of org.openide.nodes.Node in project ACS by ACS-Community.

the class MultiListExplorer method selectNthChildren.

protected static void selectNthChildren(ExplorerManager explorerManager, int n) {
    Node exploredNode = explorerManager.getExploredContext();
    if (exploredNode == null)
        return;
    Children children = exploredNode.getChildren();
    try {
        if (children == null || children.getNodesCount() == 0) {
            explorerManager.setSelectedNodes(new Node[0]);
        } else {
            if (n >= children.getNodesCount()) {
                explorerManager.setSelectedNodes(new Node[] { children.getNodes()[0] });
            } else {
                explorerManager.setSelectedNodes(new Node[] { children.getNodes()[n] });
            }
        }
    } catch (java.beans.PropertyVetoException e) {
        GPManager.notify(GPManager.WARNING, e);
    }
}
Also used : GPNode(cern.gp.nodes.GPNode) Node(org.openide.nodes.Node) Children(org.openide.nodes.Children)

Example 3 with Node

use of org.openide.nodes.Node in project ACS by ACS-Community.

the class MoveUpActionCopiedFromNetbeans method enable.

/* Manages enable - disable logic of this action */
protected boolean enable(Node[] activatedNodes) {
    initErr();
    if (err != null) {
        err.log(ErrorManager.UNKNOWN, "enable; activatedNodes=" + (activatedNodes == null ? null : Arrays.asList(activatedNodes)));
    }
    // remove old listener, if any
    Index idx = getCurIndexCookie();
    if (idx != null) {
        idx.removeChangeListener((ChangeListener) getProperty(PROP_ORDER_LISTENER));
    }
    Index cookie = getIndexCookie(activatedNodes);
    if (err != null) {
        err.log(ErrorManager.UNKNOWN, "enable; cookie=" + cookie);
    }
    if (cookie == null)
        return false;
    // now start listening to reordering changes
    cookie.addChangeListener((OrderingListener) getProperty(PROP_ORDER_LISTENER));
    curIndexCookie = new WeakReference(cookie);
    int index = cookie.indexOf(activatedNodes[0]);
    if (err != null) {
        err.log(ErrorManager.UNKNOWN, "enable; index=" + index);
        if (index == -1) {
            Node parent = activatedNodes[0].getParentNode();
            err.log(ErrorManager.UNKNOWN, "enable; parent=" + parent + "; parent.children=" + Arrays.asList(parent.getChildren().getNodes()));
        }
    }
    return index > 0;
}
Also used : WeakReference(java.lang.ref.WeakReference) Node(org.openide.nodes.Node) Index(org.openide.nodes.Index)

Example 4 with Node

use of org.openide.nodes.Node in project gephi by gephi.

the class CategoryNode method getDropType.

@Override
public PasteType getDropType(final Transferable t, int action, int index) {
    if (category == null || !category.equals(FiltersExplorer.QUERIES)) {
        return null;
    }
    final Node dropNode = NodeTransfer.node(t, DnDConstants.ACTION_COPY_OR_MOVE);
    if (dropNode != null && dropNode instanceof QueryNode) {
        return new PasteType() {

            @Override
            public Transferable paste() throws IOException {
                QueryNode queryNode = (QueryNode) dropNode;
                FilterController filterController = Lookup.getDefault().lookup(FilterController.class);
                FilterLibrary library = filterController.getModel().getLibrary();
                library.saveQuery(queryNode.getQuery());
                return null;
            }
        };
    }
    return null;
}
Also used : QueryNode(org.gephi.desktop.filters.query.QueryNode) Node(org.openide.nodes.Node) QueryNode(org.gephi.desktop.filters.query.QueryNode) AbstractNode(org.openide.nodes.AbstractNode) PasteType(org.openide.util.datatransfer.PasteType) FilterLibrary(org.gephi.filters.api.FilterLibrary) FilterController(org.gephi.filters.api.FilterController)

Example 5 with Node

use of org.openide.nodes.Node in project gephi by gephi.

the class RootNode method getDropType.

@Override
public PasteType getDropType(Transferable t, int action, int index) {
    final Node dropNode = NodeTransfer.node(t, DnDConstants.ACTION_COPY_OR_MOVE);
    if (t.isDataFlavorSupported(FilterBuilderNode.DATA_FLAVOR)) {
        try {
            final FilterBuilder fb = (FilterBuilder) t.getTransferData(FilterBuilderNode.DATA_FLAVOR);
            return new PasteType() {

                @Override
                public Transferable paste() throws IOException {
                    FilterController filterController = Lookup.getDefault().lookup(FilterController.class);
                    Query f = filterController.createQuery(fb);
                    filterController.add(f);
                    return null;
                }
            };
        } catch (UnsupportedFlavorException ex) {
            ex.printStackTrace();
        } catch (IOException ex) {
            ex.printStackTrace();
        }
    } else if (dropNode != null && dropNode instanceof SavedQueryNode) {
        return new PasteType() {

            @Override
            public Transferable paste() throws IOException {
                SavedQueryNode node = (SavedQueryNode) dropNode;
                FilterController filterController = Lookup.getDefault().lookup(FilterController.class);
                filterController.add(node.getQuery());
                return null;
            }
        };
    } else if (dropNode != null && dropNode instanceof QueryNode && ((QueryNode) dropNode).getQuery().getParent() != null) {
        return new PasteType() {

            @Override
            public Transferable paste() throws IOException {
                QueryNode queryNode = (QueryNode) dropNode;
                FilterController filterController = Lookup.getDefault().lookup(FilterController.class);
                filterController.removeSubQuery(queryNode.getQuery(), queryNode.getQuery().getParent());
                filterController.add(queryNode.getQuery());
                return null;
            }
        };
    }
    return null;
}
Also used : Query(org.gephi.filters.api.Query) SavedQueryNode(org.gephi.desktop.filters.library.SavedQueryNode) FilterBuilder(org.gephi.filters.spi.FilterBuilder) SavedQueryNode(org.gephi.desktop.filters.library.SavedQueryNode) Node(org.openide.nodes.Node) SavedQueryNode(org.gephi.desktop.filters.library.SavedQueryNode) FilterBuilderNode(org.gephi.desktop.filters.library.FilterBuilderNode) AbstractNode(org.openide.nodes.AbstractNode) PasteType(org.openide.util.datatransfer.PasteType) Transferable(java.awt.datatransfer.Transferable) FilterController(org.gephi.filters.api.FilterController) IOException(java.io.IOException) UnsupportedFlavorException(java.awt.datatransfer.UnsupportedFlavorException)

Aggregations

Node (org.openide.nodes.Node)7 AbstractNode (org.openide.nodes.AbstractNode)4 FilterController (org.gephi.filters.api.FilterController)3 Query (org.gephi.filters.api.Query)3 PasteType (org.openide.util.datatransfer.PasteType)3 GPNode (cern.gp.nodes.GPNode)2 Transferable (java.awt.datatransfer.Transferable)2 UnsupportedFlavorException (java.awt.datatransfer.UnsupportedFlavorException)2 IOException (java.io.IOException)2 FilterBuilderNode (org.gephi.desktop.filters.library.FilterBuilderNode)2 FilterBuilder (org.gephi.filters.spi.FilterBuilder)2 WeakReference (java.lang.ref.WeakReference)1 ArrayList (java.util.ArrayList)1 SavedQueryNode (org.gephi.desktop.filters.library.SavedQueryNode)1 QueryNode (org.gephi.desktop.filters.query.QueryNode)1 FilterLibrary (org.gephi.filters.api.FilterLibrary)1 Children (org.openide.nodes.Children)1 Index (org.openide.nodes.Index)1 Property (org.openide.nodes.Node.Property)1 PropertySet (org.openide.nodes.Node.PropertySet)1