use of org.cytoscape.task.TableCellTaskFactory in project cytoscape-impl by cytoscape.
the class PopupMenuHelper method createTableCellMenu.
@SuppressWarnings("serial")
public void createTableCellMenu(final CyColumn column, final Object primaryKeyValue, final Class<? extends CyIdentifiable> tableType, final Component invoker, final int x, final int y, final JTable table) {
final JPopupMenu menu = new JPopupMenu();
// Add preset menu items
menu.add(new JMenuItem(new AbstractAction("Edit") {
@Override
public void actionPerformed(ActionEvent e) {
Point point = new Point(x, y);
int row = table.rowAtPoint(point);
int column = table.columnAtPoint(point);
table.editCellAt(row, column);
table.transferFocus();
}
}));
final Object value = column.getTable().getRow(primaryKeyValue).get(column.getName(), column.getType());
if (value != null) {
String urlString = value.toString();
if (urlString != null && (urlString.startsWith("http:") || urlString.startsWith("https:")))
menu.add(getOpenLinkMenu(value.toString()));
}
final PopupMenuGravityTracker tracker = new PopupMenuGravityTracker(menu);
for (final Map.Entry<TableCellTaskFactory, Map<?, ?>> mapEntry : tableCellFactoryMap.entrySet()) {
TableCellTaskFactory taskFactory = mapEntry.getKey();
TaskFactory provisioner = factoryProvisioner.createFor(taskFactory, column, primaryKeyValue);
createMenuItem(provisioner, tracker, mapEntry.getValue(), tableType);
}
if (tableType == CyNode.class || tableType == CyEdge.class) {
menu.add(new JSeparator());
final String name = String.format("Select %s from selected rows", tableType == CyNode.class ? "nodes" : "edges");
final JMenuItem mi = new JMenuItem(new AbstractAction(name) {
@Override
public void actionPerformed(ActionEvent e) {
selectElementsFromSelectedRows(table, tableType);
}
@Override
public boolean isEnabled() {
final CyApplicationManager applicationManager = serviceRegistrar.getService(CyApplicationManager.class);
return table.getSelectedRowCount() > 0 && applicationManager.getCurrentNetwork() != null;
}
});
menu.add(mi);
}
if (menu.getSubElements().length > 0)
menu.show(invoker, x, y);
}
Aggregations