Search in sources :

Example 1 with CyEdgeViewContextMenuFactory

use of org.cytoscape.application.swing.CyEdgeViewContextMenuFactory 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

Point (java.awt.Point)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 EdgeViewTaskFactory (org.cytoscape.task.EdgeViewTaskFactory)1 JMenuTracker (org.cytoscape.util.swing.JMenuTracker)1 DialogTaskManager (org.cytoscape.work.swing.DialogTaskManager)1