Search in sources :

Example 1 with NodeViewTaskFactory

use of org.cytoscape.task.NodeViewTaskFactory in project cytoscape-impl by cytoscape.

the class LinkOut method addStaticNodeLinks.

private void addStaticNodeLinks() {
    final Properties props = linkoutProps.getProperties();
    final OpenBrowser browser = registrar.getService(OpenBrowser.class);
    try {
        for (Object pk : props.keySet()) {
            String propKey = pk.toString();
            String url = props.getProperty(propKey);
            Properties dict = createProperties(propKey, NODEMARKER);
            if (url == null || dict == null) {
                logger.debug("Bad URL for propKey: " + propKey);
                continue;
            }
            NodeViewTaskFactory evtf = new NodeLinkoutTaskFactory(browser, url);
            registrar.registerService(evtf, NodeViewTaskFactory.class, dict);
            propKey2NodeVTF.put(propKey, (NodeLinkoutTaskFactory) evtf);
        }
    } catch (Exception e) {
        logger.warn("Problem processing node URLs", e);
    }
}
Also used : OpenBrowser(org.cytoscape.util.swing.OpenBrowser) Properties(java.util.Properties) NodeViewTaskFactory(org.cytoscape.task.NodeViewTaskFactory)

Example 2 with NodeViewTaskFactory

use of org.cytoscape.task.NodeViewTaskFactory in project cytoscape-impl by cytoscape.

the class LinkOut method handleEvent.

@Override
public void handleEvent(final PropertyUpdatedEvent e) {
    if (e.getSource() == null || e.getSource().getName() == null)
        return;
    SwingUtilities.invokeLater(new Runnable() {

        @Override
        public void run() {
            final OpenBrowser browser = registrar.getService(OpenBrowser.class);
            if (// when linkout prop is changed
            e.getSource().getName().equals("linkout")) {
                final Properties props = (Properties) e.getSource().getProperties();
                List<String> removedLinks = new ArrayList<>();
                for (String propKey : propKey2EdgeVTF.keySet()) {
                    if (props.keySet().contains(propKey)) {
                        String url = props.getProperty(propKey);
                        EdgeLinkoutTaskFactory eltf = propKey2EdgeVTF.get(propKey);
                        if (!url.equals(eltf.getLink())) {
                            // linkout is modified
                            eltf.setLink(url);
                            propKey2EdgeVTF.put(propKey, eltf);
                        }
                    } else {
                        // linkout is removed
                        EdgeLinkoutTaskFactory eltf = propKey2EdgeVTF.get(propKey);
                        registrar.unregisterService(eltf, EdgeViewTaskFactory.class);
                        removedLinks.add(propKey);
                    }
                }
                for (String propKey : propKey2NodeVTF.keySet()) {
                    if (props.keySet().contains(propKey)) {
                        String url = props.getProperty(propKey);
                        NodeLinkoutTaskFactory nltf = propKey2NodeVTF.get(propKey);
                        if (!url.equals(nltf.getLink())) {
                            // linkout is modified
                            nltf.setLink(url);
                            propKey2NodeVTF.put(propKey, nltf);
                        }
                    } else {
                        // linkout is removed
                        NodeLinkoutTaskFactory nltf = propKey2NodeVTF.get(propKey);
                        registrar.unregisterService((NodeViewTaskFactory) nltf, NodeViewTaskFactory.class);
                        removedLinks.add(propKey);
                    }
                }
                for (String propkey : removedLinks) {
                    propKey2EdgeVTF.remove(propkey);
                    propKey2NodeVTF.remove(propkey);
                }
                try {
                    for (Object pk : props.keySet()) {
                        // added edge linkouts
                        String propKey = pk.toString();
                        if (propKey2EdgeVTF.containsKey(propKey))
                            continue;
                        String url = props.getProperty(propKey);
                        Properties dict = createProperties(propKey, EDGEMARKER);
                        if (url == null || dict == null) {
                            logger.debug("Bad URL for propKey: " + propKey);
                            continue;
                        }
                        EdgeViewTaskFactory evtf = new EdgeLinkoutTaskFactory(browser, url);
                        registrar.registerService(evtf, EdgeViewTaskFactory.class, dict);
                        propKey2EdgeVTF.put(propKey, (EdgeLinkoutTaskFactory) evtf);
                    }
                    for (Object pk : props.keySet()) {
                        // added node linkouts
                        String propKey = pk.toString();
                        if (propKey2NodeVTF.containsKey(propKey))
                            continue;
                        String url = props.getProperty(propKey);
                        Properties dict = createProperties(propKey, NODEMARKER);
                        if (url == null || dict == null) {
                            logger.debug("Bad URL for propKey: " + propKey);
                            continue;
                        }
                        NodeViewTaskFactory nvtf = new NodeLinkoutTaskFactory(browser, url);
                        registrar.registerService(nvtf, NodeViewTaskFactory.class, dict);
                        propKey2NodeVTF.put(propKey, (NodeLinkoutTaskFactory) nvtf);
                    }
                } catch (Exception ex) {
                    logger.warn("Problem processing node URLs", ex);
                }
            } else if (e.getSource().getName().equals("commandline")) {
                // when commandline linkout prop is changed
                final Properties props = (Properties) e.getSource().getProperties();
                List<String> removedLinks = new ArrayList<>();
                for (String propKey : cpropKey2EdgeVTF.keySet()) {
                    if (props.keySet().contains(propKey)) {
                        String url = props.getProperty(propKey);
                        EdgeLinkoutTaskFactory eltf = cpropKey2EdgeVTF.get(propKey);
                        if (!url.equals(eltf.getLink())) {
                            // linkout is modified
                            eltf.setLink(url);
                            cpropKey2EdgeVTF.put(propKey, eltf);
                        }
                    } else {
                        // linkout is removed
                        EdgeLinkoutTaskFactory eltf = cpropKey2EdgeVTF.get(propKey);
                        registrar.unregisterService(eltf, EdgeViewTaskFactory.class);
                        removedLinks.add(propKey);
                    }
                }
                for (String propKey : cpropKey2NodeVTF.keySet()) {
                    if (props.keySet().contains(propKey)) {
                        String url = props.getProperty(propKey);
                        NodeLinkoutTaskFactory nltf = cpropKey2NodeVTF.get(propKey);
                        if (!url.equals(nltf.getLink())) {
                            // linkout is modified
                            nltf.setLink(url);
                            cpropKey2NodeVTF.put(propKey, nltf);
                        }
                    } else {
                        // linkout is removed
                        NodeLinkoutTaskFactory nltf = cpropKey2NodeVTF.get(propKey);
                        registrar.unregisterService((NodeViewTaskFactory) nltf, NodeViewTaskFactory.class);
                        removedLinks.add(propKey);
                    }
                }
                for (String propkey : removedLinks) {
                    cpropKey2EdgeVTF.remove(propkey);
                    cpropKey2NodeVTF.remove(propkey);
                }
                try {
                    for (Object pk : props.keySet()) {
                        // added edge linkouts
                        String propKey = pk.toString();
                        if (cpropKey2EdgeVTF.containsKey(propKey))
                            continue;
                        String url = props.getProperty(propKey);
                        Properties dict = createProperties(propKey, EDGEMARKER);
                        if (url == null || dict == null) {
                            logger.debug("Bad URL for propKey: " + propKey);
                            continue;
                        }
                        EdgeViewTaskFactory evtf = new EdgeLinkoutTaskFactory(browser, url);
                        registrar.registerService(evtf, EdgeViewTaskFactory.class, dict);
                        cpropKey2EdgeVTF.put(propKey, (EdgeLinkoutTaskFactory) evtf);
                    }
                    for (Object pk : props.keySet()) {
                        // added node linkouts
                        String propKey = pk.toString();
                        if (cpropKey2NodeVTF.containsKey(propKey))
                            continue;
                        String url = props.getProperty(propKey);
                        Properties dict = createProperties(propKey, NODEMARKER);
                        if (url == null || dict == null) {
                            logger.debug("Bad URL for propKey: " + propKey);
                            continue;
                        }
                        NodeViewTaskFactory nvtf = new NodeLinkoutTaskFactory(browser, url);
                        registrar.registerService(nvtf, NodeViewTaskFactory.class, dict);
                        cpropKey2NodeVTF.put(propKey, (NodeLinkoutTaskFactory) nvtf);
                    }
                } catch (Exception ex) {
                    logger.warn("Problem processing node URLs", ex);
                }
            }
        }
    });
}
Also used : ArrayList(java.util.ArrayList) Properties(java.util.Properties) OpenBrowser(org.cytoscape.util.swing.OpenBrowser) ArrayList(java.util.ArrayList) List(java.util.List) NodeViewTaskFactory(org.cytoscape.task.NodeViewTaskFactory) EdgeViewTaskFactory(org.cytoscape.task.EdgeViewTaskFactory)

Example 3 with NodeViewTaskFactory

use of org.cytoscape.task.NodeViewTaskFactory in project cytoscape-impl by cytoscape.

the class CyActivator method start.

@Override
public void start(BundleContext bc) {
    final CyServiceRegistrar serviceRegistrar = getService(bc, CyServiceRegistrar.class);
    {
        // NetworkView (empty space) context menus
        SIFInterpreterTaskFactory factory = new SIFInterpreterTaskFactory(serviceRegistrar);
        Properties props = new Properties();
        props.setProperty(ENABLE_FOR, "networkAndView");
        props.setProperty(PREFERRED_ACTION, "NEW");
        props.setProperty(PREFERRED_MENU, NETWORK_ADD_MENU);
        props.setProperty(MENU_GRAVITY, "1.0");
        props.setProperty(IN_MENU_BAR, "false");
        props.setProperty(TITLE, "Edge (and possibly Nodes) using SIF...");
        registerService(bc, factory, NetworkViewTaskFactory.class, props);
    }
    {
        NetworkViewLocationTaskFactory factory = new AddNodeTaskFactory(serviceRegistrar);
        Properties props = new Properties();
        props.setProperty(PREFERRED_ACTION, "NEW");
        props.setProperty(PREFERRED_MENU, NETWORK_ADD_MENU);
        props.setProperty(MENU_GRAVITY, "1.1");
        props.setProperty(TITLE, "Node");
        registerService(bc, factory, NetworkViewLocationTaskFactory.class, props);
    }
    // We need a place to hold the objects themselves
    ClipboardManagerImpl clipboardManager = new ClipboardManagerImpl(serviceRegistrar);
    {
        // Copy node
        NetworkViewTaskFactory factory = new CopyTaskFactory(clipboardManager);
        Properties props = new Properties();
        props.setProperty(ENABLE_FOR, "networkAndView");
        props.setProperty(PREFERRED_ACTION, "NEW");
        props.setProperty(PREFERRED_MENU, NETWORK_EDIT_MENU);
        props.setProperty(ACCELERATOR, "cmd c");
        props.setProperty(TITLE, "Copy");
        props.setProperty(MENU_GRAVITY, "0.0f");
        registerService(bc, factory, NetworkViewTaskFactory.class, props);
    }
    {
        // Cut node
        NetworkViewTaskFactory factory = new CutTaskFactory(clipboardManager, serviceRegistrar);
        Properties props = new Properties();
        props.setProperty(ENABLE_FOR, "networkAndView");
        props.setProperty(PREFERRED_ACTION, "NEW");
        props.setProperty(PREFERRED_MENU, NETWORK_EDIT_MENU);
        props.setProperty(ACCELERATOR, "cmd x");
        props.setProperty(MENU_GRAVITY, "0.1f");
        props.setProperty(TITLE, "Cut");
        registerService(bc, factory, NetworkViewTaskFactory.class, props);
    }
    {
        // Paste node
        NetworkViewLocationTaskFactory pasteTaskFactory = new PasteTaskFactory(clipboardManager, serviceRegistrar);
        Properties props = new Properties();
        props.setProperty(ENABLE_FOR, "networkAndView");
        props.setProperty(PREFERRED_ACTION, "NEW");
        props.setProperty(PREFERRED_MENU, NETWORK_EDIT_MENU);
        props.setProperty(TITLE, "Paste");
        props.setProperty(MENU_GRAVITY, "0.2f");
        props.setProperty(ACCELERATOR, "cmd v");
        props.setProperty(IN_MENU_BAR, "true");
        registerService(bc, pasteTaskFactory, NetworkViewLocationTaskFactory.class, props);
    }
    // At some point, add Paste Special.  Paste special would allow paste node only, paste copy, etc.
    // NodeView context menus
    {
        // Copy node
        NodeViewTaskFactory factory = new CopyNodeTaskFactory(clipboardManager);
        Properties props = new Properties();
        props.setProperty(PREFERRED_ACTION, "NEW");
        props.setProperty(PREFERRED_MENU, NODE_EDIT_MENU);
        props.setProperty(ACCELERATOR, "cmd c");
        props.setProperty(MENU_GRAVITY, "0.0f");
        props.setProperty(TITLE, "Copy");
        registerService(bc, factory, NodeViewTaskFactory.class, props);
    }
    {
        // Cut node
        NodeViewTaskFactory factory = new CutNodeTaskFactory(clipboardManager, serviceRegistrar);
        Properties props = new Properties();
        props.setProperty(PREFERRED_ACTION, "NEW");
        props.setProperty(PREFERRED_MENU, NODE_EDIT_MENU);
        props.setProperty(ACCELERATOR, "cmd x");
        props.setProperty(MENU_GRAVITY, "0.1f");
        props.setProperty(TITLE, "Cut");
        registerService(bc, factory, NodeViewTaskFactory.class, props);
    }
    {
        // Rename node
        NodeViewTaskFactory factory = new RenameNodeTaskFactory(serviceRegistrar);
        Properties props = new Properties();
        props.setProperty(PREFERRED_ACTION, "NEW");
        props.setProperty(PREFERRED_MENU, NODE_EDIT_MENU);
        props.setProperty(INSERT_SEPARATOR_AFTER, "true");
        props.setProperty(MENU_GRAVITY, "0.2f");
        props.setProperty(TITLE, "Rename Node");
        registerService(bc, factory, NodeViewTaskFactory.class, props);
    }
    {
        NodeViewTaskFactory factory = new AddNestedNetworkTaskFactory(serviceRegistrar);
        Properties props = new Properties();
        props.setProperty(PREFERRED_ACTION, "NEW");
        props.setProperty(PREFERRED_MENU, NODE_NESTED_NETWORKS_MENU);
        props.setProperty(MENU_GRAVITY, "0.1f");
        props.setProperty(TITLE, "Add Nested Network");
        registerService(bc, factory, NodeViewTaskFactory.class, props);
    }
    {
        NodeViewTaskFactory factory = new DeleteNestedNetworkTaskFactory(serviceRegistrar);
        Properties props = new Properties();
        props.setProperty(PREFERRED_ACTION, "NEW");
        props.setProperty(PREFERRED_MENU, NODE_NESTED_NETWORKS_MENU);
        props.setProperty(MENU_GRAVITY, "0.2f");
        props.setProperty(TITLE, "Remove Nested Network");
        registerService(bc, factory, NodeViewTaskFactory.class, props);
    }
    {
        NodeViewTaskFactory factory = new GoToNestedNetworkTaskFactory(serviceRegistrar);
        Properties props = new Properties();
        props.setProperty(PREFERRED_ACTION, "NEW");
        props.setProperty(PREFERRED_MENU, NODE_NESTED_NETWORKS_MENU);
        props.setProperty(MENU_GRAVITY, "0.3f");
        props.setProperty(TITLE, "Go to Nested Network");
        registerService(bc, factory, NodeViewTaskFactory.class, props);
    }
    // EdgeView context menus
    {
        // Copy node
        EdgeViewTaskFactory factory = new CopyEdgeTaskFactory(clipboardManager);
        Properties props = new Properties();
        props.setProperty(PREFERRED_ACTION, "NEW");
        props.setProperty(PREFERRED_MENU, EDGE_EDIT_MENU);
        props.setProperty(ACCELERATOR, "cmd c");
        props.setProperty(MENU_GRAVITY, "0.0f");
        props.setProperty(TITLE, "Copy");
        registerService(bc, factory, EdgeViewTaskFactory.class, props);
    }
    {
        // Cut edge
        EdgeViewTaskFactory factory = new CutEdgeTaskFactory(clipboardManager, serviceRegistrar);
        Properties props = new Properties();
        props.setProperty(PREFERRED_ACTION, "NEW");
        props.setProperty(PREFERRED_MENU, EDGE_EDIT_MENU);
        props.setProperty(ACCELERATOR, "cmd x");
        props.setProperty(MENU_GRAVITY, "0.1f");
        props.setProperty(TITLE, "Cut");
        registerService(bc, factory, EdgeViewTaskFactory.class, props);
    }
}
Also used : NetworkViewLocationTaskFactory(org.cytoscape.task.NetworkViewLocationTaskFactory) Properties(java.util.Properties) CyServiceRegistrar(org.cytoscape.service.util.CyServiceRegistrar) NetworkViewTaskFactory(org.cytoscape.task.NetworkViewTaskFactory) NodeViewTaskFactory(org.cytoscape.task.NodeViewTaskFactory) EdgeViewTaskFactory(org.cytoscape.task.EdgeViewTaskFactory)

Example 4 with NodeViewTaskFactory

use of org.cytoscape.task.NodeViewTaskFactory in project cytoscape-impl by cytoscape.

the class LinkOut method addCommanLineLinkOut.

public void addCommanLineLinkOut(CyProperty<Properties> commandline, Map<?, ?> p) {
    if (!"commandline.props".equals(p.get("cyPropertyName")))
        return;
    Properties props = commandline.getProperties();
    final OpenBrowser browser = registrar.getService(OpenBrowser.class);
    try {
        for (Object pk : props.keySet()) {
            String propKey = pk.toString();
            String url = props.getProperty(propKey);
            Properties dict = createProperties(propKey, EDGEMARKER);
            if (url == null || dict == null) {
                logger.debug("Bad URL for propKey: " + propKey);
                continue;
            }
            EdgeViewTaskFactory evtf = new EdgeLinkoutTaskFactory(browser, url);
            registrar.registerService(evtf, EdgeViewTaskFactory.class, dict);
            cpropKey2EdgeVTF.put(propKey, (EdgeLinkoutTaskFactory) evtf);
        }
    } catch (Exception e) {
        logger.warn("Problem processing edge URLs", e);
    }
    try {
        for (Object pk : props.keySet()) {
            String propKey = pk.toString();
            String url = props.getProperty(propKey);
            Properties dict = createProperties(propKey, NODEMARKER);
            if (url == null || dict == null) {
                logger.debug("Bad URL for propKey: " + propKey);
                continue;
            }
            NodeViewTaskFactory evtf = new NodeLinkoutTaskFactory(browser, url);
            registrar.registerService(evtf, NodeViewTaskFactory.class, dict);
            cpropKey2NodeVTF.put(propKey, (NodeLinkoutTaskFactory) evtf);
        }
    } catch (Exception e) {
        logger.warn("Problem processing node URLs", e);
    }
}
Also used : OpenBrowser(org.cytoscape.util.swing.OpenBrowser) Properties(java.util.Properties) NodeViewTaskFactory(org.cytoscape.task.NodeViewTaskFactory) EdgeViewTaskFactory(org.cytoscape.task.EdgeViewTaskFactory)

Example 5 with NodeViewTaskFactory

use of org.cytoscape.task.NodeViewTaskFactory in project cytoscape-impl by cytoscape.

the class PopupMenuHelper method createNodeViewMenu.

/**
 * Creates a menu based on the NodeView.
 *
 * @param action Acceptable values are "NEW", "OPEN", or "EDGE". Case does not matter.
 */
void createNodeViewMenu(NodeView nview, int x, int y, String action) {
    if (nview != null) {
        Collection<NodeViewTaskFactory> usableTFs = getPreferredActions(graphView.nodeViewTFs, action);
        Collection<CyNodeViewContextMenuFactory> usableCMFs = getPreferredActions(graphView.cyNodeViewContextMenuFactory, action);
        View<CyNode> nv = (DNodeView) nview;
        // If the action is NEW, we should also include the Edge Actions
        if (action.equalsIgnoreCase("NEW")) {
            usableTFs.addAll(getPreferredActions(graphView.nodeViewTFs, "Edge"));
            usableCMFs.addAll(getPreferredActions(graphView.cyNodeViewContextMenuFactory, "Edge"));
        } else // remove TaskFactories that can't be executed from double-click menu
        if (action.equalsIgnoreCase("OPEN")) {
            Iterator<NodeViewTaskFactory> i = usableTFs.iterator();
            while (i.hasNext()) {
                if (!i.next().isReady(nv, graphView))
                    i.remove();
            }
        }
        int menuItemCount = usableTFs.size() + usableCMFs.size();
        int tfCount = usableTFs.size();
        if ((action.equalsIgnoreCase("OPEN") || action.equalsIgnoreCase("Edge")) && menuItemCount == 1 && tfCount == 1) {
            NodeViewTaskFactory tf = usableTFs.iterator().next();
            serviceRegistrar.getService(DialogTaskManager.class).execute(tf.createTaskIterator(nv, graphView));
        } else {
            String nodeLabel = graphView.getModel().getRow(nv.getModel()).get(CyNetwork.NAME, String.class);
            JPopupMenu menu = createMenu(nodeLabel);
            JMenuTracker tracker = new JMenuTracker(menu);
            if (!action.equalsIgnoreCase("OPEN")) {
                initializeNodeTracker(tracker);
                tracker.getGravityTracker(".").addMenuSeparator(-0.1);
                tracker.getGravityTracker(".").addMenuSeparator(999.99);
            }
            for (NodeViewTaskFactory nvtf : usableTFs) {
                Object context = null;
                NamedTaskFactory provisioner = factoryProvisioner.createFor(nvtf, nv, graphView);
                addMenuItem(nv, menu, provisioner, context, tracker, graphView.nodeViewTFs.get(nvtf));
            }
            for (CyNodeViewContextMenuFactory nodeCMF : usableCMFs) {
                // menu.add(nodeVMF.createMenuItem(m_view,  nv).getMenuItem());
                try {
                    CyMenuItem menuItem = nodeCMF.createMenuItem(graphView, nv);
                    addCyMenuItem(nv, menu, menuItem, tracker, graphView.cyNodeViewContextMenuFactory.get(nodeCMF));
                } catch (Throwable t) {
                    logger.error("Could not display context menu.", t);
                }
            }
            menu.show(invoker, x, y);
        }
    }
}
Also used : CyMenuItem(org.cytoscape.application.swing.CyMenuItem) JMenuTracker(org.cytoscape.util.swing.JMenuTracker) DialogTaskManager(org.cytoscape.work.swing.DialogTaskManager) Point(java.awt.Point) JPopupMenu(javax.swing.JPopupMenu) Iterator(java.util.Iterator) CyNode(org.cytoscape.model.CyNode) NodeViewTaskFactory(org.cytoscape.task.NodeViewTaskFactory) CyNodeViewContextMenuFactory(org.cytoscape.application.swing.CyNodeViewContextMenuFactory)

Aggregations

NodeViewTaskFactory (org.cytoscape.task.NodeViewTaskFactory)5 Properties (java.util.Properties)4 EdgeViewTaskFactory (org.cytoscape.task.EdgeViewTaskFactory)3 OpenBrowser (org.cytoscape.util.swing.OpenBrowser)3 Point (java.awt.Point)1 ArrayList (java.util.ArrayList)1 Iterator (java.util.Iterator)1 List (java.util.List)1 JPopupMenu (javax.swing.JPopupMenu)1 CyMenuItem (org.cytoscape.application.swing.CyMenuItem)1 CyNodeViewContextMenuFactory (org.cytoscape.application.swing.CyNodeViewContextMenuFactory)1 CyNode (org.cytoscape.model.CyNode)1 CyServiceRegistrar (org.cytoscape.service.util.CyServiceRegistrar)1 NetworkViewLocationTaskFactory (org.cytoscape.task.NetworkViewLocationTaskFactory)1 NetworkViewTaskFactory (org.cytoscape.task.NetworkViewTaskFactory)1 JMenuTracker (org.cytoscape.util.swing.JMenuTracker)1 DialogTaskManager (org.cytoscape.work.swing.DialogTaskManager)1