Search in sources :

Example 1 with EdgeViewTaskFactory

use of org.cytoscape.task.EdgeViewTaskFactory 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 2 with EdgeViewTaskFactory

use of org.cytoscape.task.EdgeViewTaskFactory 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 3 with EdgeViewTaskFactory

use of org.cytoscape.task.EdgeViewTaskFactory 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 4 with EdgeViewTaskFactory

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

the class LinkOut method addStaticEdgeLinks.

private void addStaticEdgeLinks() {
    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, EDGEMARKER);
            if (url == null || dict == null) {
                logger.debug("Bad URL for propKey: " + propKey);
                continue;
            }
            final EdgeViewTaskFactory evtf = new EdgeLinkoutTaskFactory(browser, url);
            registrar.registerService(evtf, EdgeViewTaskFactory.class, dict);
            propKey2EdgeVTF.put(propKey, (EdgeLinkoutTaskFactory) evtf);
        }
    } catch (Exception e) {
        logger.warn("Problem processing edge URLs", e);
    }
}
Also used : OpenBrowser(org.cytoscape.util.swing.OpenBrowser) Properties(java.util.Properties) EdgeViewTaskFactory(org.cytoscape.task.EdgeViewTaskFactory)

Example 5 with EdgeViewTaskFactory

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

the class PopupMenuHelper method createEdgeViewMenu.

/**
 * Creates a menu based on the EdgeView.
 *
 * @param action Acceptable values are "NEW" or "OPEN." Case does not matter.
 */
void createEdgeViewMenu(EdgeView edgeView, int x, int y, String action) {
    if (edgeView != null) {
        Collection<EdgeViewTaskFactory> usableTFs = getPreferredActions(graphView.edgeViewTFs, action);
        Collection<CyEdgeViewContextMenuFactory> usableCMFs = getPreferredActions(graphView.cyEdgeViewContextMenuFactory, action);
        View<CyEdge> ev = (DEdgeView) edgeView;
        // remove TaskFactories that can't be executed from double-click menu
        if (action.equalsIgnoreCase("OPEN")) {
            Iterator<EdgeViewTaskFactory> i = usableTFs.iterator();
            while (i.hasNext()) {
                if (!i.next().isReady(ev, graphView))
                    i.remove();
            }
        }
        int tfCount = usableTFs.size();
        int menuItemCount = usableTFs.size() + usableCMFs.size();
        if (action.equalsIgnoreCase("OPEN") && menuItemCount == 1 && tfCount == 1) {
            EdgeViewTaskFactory tf = usableTFs.iterator().next();
            serviceRegistrar.getService(DialogTaskManager.class).execute(tf.createTaskIterator(ev, graphView));
        } else {
            String edgeLabel = graphView.getModel().getRow(ev.getModel()).get(CyEdge.INTERACTION, String.class);
            JPopupMenu menu = createMenu(edgeLabel);
            JMenuTracker tracker = new JMenuTracker(menu);
            if (!action.equalsIgnoreCase("OPEN")) {
                initializeEdgeTracker(tracker);
                tracker.getGravityTracker(".").addMenuSeparator(-0.1);
                tracker.getGravityTracker(".").addMenuSeparator(999.99);
            }
            for (EdgeViewTaskFactory evtf : usableTFs) {
                Object context = null;
                NamedTaskFactory provisioner = factoryProvisioner.createFor(evtf, ev, graphView);
                addMenuItem(ev, menu, provisioner, context, tracker, graphView.edgeViewTFs.get(evtf));
            }
            for (CyEdgeViewContextMenuFactory edgeCMF : usableCMFs) {
                // menu.add(edgeCMF.createMenuItem(m_view, ev).getMenuItem());
                try {
                    CyMenuItem menuItem = edgeCMF.createMenuItem(graphView, ev);
                    addCyMenuItem(ev, menu, menuItem, tracker, graphView.cyEdgeViewContextMenuFactory.get(edgeCMF));
                } catch (Throwable t) {
                    logger.error("Could not display context menu.", t);
                }
            }
            menu.show(invoker, x, y);
        }
    }
}
Also used : CyMenuItem(org.cytoscape.application.swing.CyMenuItem) CyEdgeViewContextMenuFactory(org.cytoscape.application.swing.CyEdgeViewContextMenuFactory) JMenuTracker(org.cytoscape.util.swing.JMenuTracker) DialogTaskManager(org.cytoscape.work.swing.DialogTaskManager) CyEdge(org.cytoscape.model.CyEdge) Point(java.awt.Point) JPopupMenu(javax.swing.JPopupMenu) EdgeViewTaskFactory(org.cytoscape.task.EdgeViewTaskFactory)

Aggregations

EdgeViewTaskFactory (org.cytoscape.task.EdgeViewTaskFactory)5 Properties (java.util.Properties)4 NodeViewTaskFactory (org.cytoscape.task.NodeViewTaskFactory)3 OpenBrowser (org.cytoscape.util.swing.OpenBrowser)3 Point (java.awt.Point)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 JPopupMenu (javax.swing.JPopupMenu)1 CyEdgeViewContextMenuFactory (org.cytoscape.application.swing.CyEdgeViewContextMenuFactory)1 CyMenuItem (org.cytoscape.application.swing.CyMenuItem)1 CyEdge (org.cytoscape.model.CyEdge)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