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);
}
}
}
Aggregations