use of org.cytoscape.application.swing.CyNodeViewContextMenuFactory 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);
}
}
}
Aggregations