Search in sources :

Example 1 with TableCellTaskFactory

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);
}
Also used : ActionEvent(java.awt.event.ActionEvent) Point(java.awt.Point) ValidatedObjectAndEditString(org.cytoscape.browser.internal.util.ValidatedObjectAndEditString) CyEdge(org.cytoscape.model.CyEdge) JPopupMenu(javax.swing.JPopupMenu) Point(java.awt.Point) TableCellTaskFactory(org.cytoscape.task.TableCellTaskFactory) JSeparator(javax.swing.JSeparator) CyApplicationManager(org.cytoscape.application.CyApplicationManager) PopupMenuGravityTracker(org.cytoscape.util.swing.PopupMenuGravityTracker) TaskFactory(org.cytoscape.work.TaskFactory) TableColumnTaskFactory(org.cytoscape.task.TableColumnTaskFactory) TableCellTaskFactory(org.cytoscape.task.TableCellTaskFactory) CyNode(org.cytoscape.model.CyNode) JMenuItem(javax.swing.JMenuItem) AbstractAction(javax.swing.AbstractAction) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

Point (java.awt.Point)1 ActionEvent (java.awt.event.ActionEvent)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 AbstractAction (javax.swing.AbstractAction)1 JMenuItem (javax.swing.JMenuItem)1 JPopupMenu (javax.swing.JPopupMenu)1 JSeparator (javax.swing.JSeparator)1 CyApplicationManager (org.cytoscape.application.CyApplicationManager)1 ValidatedObjectAndEditString (org.cytoscape.browser.internal.util.ValidatedObjectAndEditString)1 CyEdge (org.cytoscape.model.CyEdge)1 CyNode (org.cytoscape.model.CyNode)1 TableCellTaskFactory (org.cytoscape.task.TableCellTaskFactory)1 TableColumnTaskFactory (org.cytoscape.task.TableColumnTaskFactory)1 PopupMenuGravityTracker (org.cytoscape.util.swing.PopupMenuGravityTracker)1 TaskFactory (org.cytoscape.work.TaskFactory)1