Search in sources :

Example 1 with NodesManipulator

use of org.gephi.datalab.spi.nodes.NodesManipulator in project gephi by gephi.

the class DataLaboratoryHelper method getNodesManipulators.

/**
     * <p>Prepares an array with one new instance of every NodesManipulator
     * that has a builder registered and returns it.</p>
     * <p>It also returns the manipulators ordered first by type and then by position.</p>
     * @return Array of all NodesManipulator implementations
     */
public NodesManipulator[] getNodesManipulators() {
    ArrayList<NodesManipulator> nodesManipulators = new ArrayList<>();
    for (NodesManipulatorBuilder nm : Lookup.getDefault().lookupAll(NodesManipulatorBuilder.class)) {
        nodesManipulators.add(nm.getNodesManipulator());
    }
    sortManipulators(nodesManipulators);
    return nodesManipulators.toArray(new NodesManipulator[0]);
}
Also used : NodesManipulatorBuilder(org.gephi.datalab.spi.nodes.NodesManipulatorBuilder) ArrayList(java.util.ArrayList) NodesManipulator(org.gephi.datalab.spi.nodes.NodesManipulator)

Example 2 with NodesManipulator

use of org.gephi.datalab.spi.nodes.NodesManipulator in project gephi by gephi.

the class DataTableTopComponent method eventDispatched.

/**
     * To react to Ctrl+F keys combination calling Search/Replace general action
     * (and nodes/edges context menu mappings)
     *
     * @param event
     */
@Override
public void eventDispatched(AWTEvent event) {
    KeyEvent evt = (KeyEvent) event;
    if (evt.getID() == KeyEvent.KEY_RELEASED && (evt.getModifiersEx() & KeyEvent.CTRL_DOWN_MASK) != 0) {
        DataLaboratoryHelper dlh = DataLaboratoryHelper.getDefault();
        if (evt.getKeyCode() == KeyEvent.VK_F) {
            //Call Search replace with 'F' without general actions key mappings support:
            GeneralActionsManipulator gam = dlh.getGeneralActionsManipulatorByName("SearchReplace");
            if (gam != null) {
                dlh.executeManipulator(gam);
            }
            evt.consume();
        } else {
            //Nodes/edges mappings:
            if (isShowingNodesTable()) {
                final ContextMenuItemManipulator item = nodesActionMappings.get(evt.getKeyCode());
                if (item != null) {
                    Node[] nodes = nodeTable.getElementsFromSelectedRows().toArray(new Node[0]);
                    if (nodes.length > 0) {
                        ((NodesManipulator) item).setup(nodes, nodes[0]);
                        if (item.isAvailable() && item.canExecute()) {
                            DataLaboratoryHelper.getDefault().executeManipulator(item);
                        }
                    }
                    evt.consume();
                }
            } else if (isShowingEdgesTable()) {
                final ContextMenuItemManipulator item = edgesActionMappings.get(evt.getKeyCode());
                if (item != null) {
                    Edge[] edges = edgeTable.getElementsFromSelectedRows().toArray(new Edge[0]);
                    if (edges.length > 0) {
                        ((EdgesManipulator) item).setup(edges, edges[0]);
                        if (item.isAvailable() && item.canExecute()) {
                            DataLaboratoryHelper.getDefault().executeManipulator(item);
                        }
                    }
                    evt.consume();
                }
            }
        }
    }
}
Also used : KeyEvent(java.awt.event.KeyEvent) DataLaboratoryHelper(org.gephi.datalab.api.DataLaboratoryHelper) ContextMenuItemManipulator(org.gephi.datalab.spi.ContextMenuItemManipulator) GeneralActionsManipulator(org.gephi.datalab.spi.general.GeneralActionsManipulator) PluginGeneralActionsManipulator(org.gephi.datalab.spi.general.PluginGeneralActionsManipulator) Node(org.gephi.graph.api.Node) NodesManipulator(org.gephi.datalab.spi.nodes.NodesManipulator) Edge(org.gephi.graph.api.Edge)

Example 3 with NodesManipulator

use of org.gephi.datalab.spi.nodes.NodesManipulator in project gephi by gephi.

the class NodesPopupAdapter method createPopup.

@Override
protected JPopupMenu createPopup(Point p) {
    final List<Node> selectedElements = elementsDataTable.getElementsFromSelectedRows();
    final Node clickedElement = elementsDataTable.getElementFromRow(table.rowAtPoint(p));
    JPopupMenu contextMenu = new JPopupMenu();
    //First add edges manipulators items:
    DataLaboratoryHelper dlh = DataLaboratoryHelper.getDefault();
    Integer lastManipulatorType = null;
    for (NodesManipulator em : dlh.getNodesManipulators()) {
        em.setup(selectedElements.toArray(new Node[0]), clickedElement);
        if (lastManipulatorType == null) {
            lastManipulatorType = em.getType();
        }
        if (lastManipulatorType != em.getType()) {
            contextMenu.addSeparator();
        }
        lastManipulatorType = em.getType();
        if (em.isAvailable()) {
            contextMenu.add(PopupMenuUtils.createMenuItemFromNodesManipulator(em, clickedElement, selectedElements.toArray(new Node[0])));
        }
    }
    //Add AttributeValues manipulators submenu:
    Column column = elementsDataTable.getColumnAtIndex(table.columnAtPoint(p));
    if (column != null) {
        contextMenu.add(PopupMenuUtils.createSubMenuFromRowColumn(clickedElement, column));
    }
    return contextMenu;
}
Also used : DataLaboratoryHelper(org.gephi.datalab.api.DataLaboratoryHelper) Column(org.gephi.graph.api.Column) Node(org.gephi.graph.api.Node) NodesManipulator(org.gephi.datalab.spi.nodes.NodesManipulator) JPopupMenu(javax.swing.JPopupMenu)

Example 4 with NodesManipulator

use of org.gephi.datalab.spi.nodes.NodesManipulator in project gephi by gephi.

the class PopupMenuUtils method createMenuItemFromNodesManipulator.

public static JMenuItem createMenuItemFromNodesManipulator(final NodesManipulator item, final Node clickedNode, final Node[] nodes) {
    ContextMenuItemManipulator[] subItems = item.getSubItems();
    if (subItems != null && item.canExecute()) {
        JMenu subMenu = new JMenu();
        subMenu.setText(item.getName());
        if (item.getDescription() != null && !item.getDescription().isEmpty()) {
            subMenu.setToolTipText(item.getDescription());
        }
        subMenu.setIcon(item.getIcon());
        Integer lastItemType = null;
        for (ContextMenuItemManipulator subItem : subItems) {
            ((NodesManipulator) subItem).setup(nodes, clickedNode);
            if (lastItemType == null) {
                lastItemType = subItem.getType();
            }
            if (lastItemType != subItem.getType()) {
                subMenu.addSeparator();
            }
            lastItemType = subItem.getType();
            if (subItem.isAvailable()) {
                subMenu.add(createMenuItemFromNodesManipulator((NodesManipulator) subItem, clickedNode, nodes));
            }
        }
        if (item.getMnemonicKey() != null) {
            //Mnemonic for opening a sub menu
            subMenu.setMnemonic(item.getMnemonicKey());
        }
        return subMenu;
    } else {
        JMenuItem menuItem = new JMenuItem();
        menuItem.setText(item.getName());
        if (item.getDescription() != null && !item.getDescription().isEmpty()) {
            menuItem.setToolTipText(item.getDescription());
        }
        menuItem.setIcon(item.getIcon());
        if (item.canExecute()) {
            menuItem.addActionListener(new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent e) {
                    new Thread() {

                        @Override
                        public void run() {
                            DataLaboratoryHelper.getDefault().executeManipulator(item);
                        }
                    }.start();
                }
            });
        } else {
            menuItem.setEnabled(false);
        }
        if (item.getMnemonicKey() != null) {
            //Mnemonic for executing the action
            menuItem.setMnemonic(item.getMnemonicKey());
            //And the same key mnemonic + ctrl for executing the action (and as a help display for the user!).
            menuItem.setAccelerator(KeyStroke.getKeyStroke(item.getMnemonicKey(), KeyEvent.CTRL_DOWN_MASK));
        }
        return menuItem;
    }
}
Also used : ContextMenuItemManipulator(org.gephi.datalab.spi.ContextMenuItemManipulator) ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) NodesManipulator(org.gephi.datalab.spi.nodes.NodesManipulator) JMenuItem(javax.swing.JMenuItem) JMenu(javax.swing.JMenu)

Aggregations

NodesManipulator (org.gephi.datalab.spi.nodes.NodesManipulator)4 DataLaboratoryHelper (org.gephi.datalab.api.DataLaboratoryHelper)2 ContextMenuItemManipulator (org.gephi.datalab.spi.ContextMenuItemManipulator)2 Node (org.gephi.graph.api.Node)2 ActionEvent (java.awt.event.ActionEvent)1 ActionListener (java.awt.event.ActionListener)1 KeyEvent (java.awt.event.KeyEvent)1 ArrayList (java.util.ArrayList)1 JMenu (javax.swing.JMenu)1 JMenuItem (javax.swing.JMenuItem)1 JPopupMenu (javax.swing.JPopupMenu)1 GeneralActionsManipulator (org.gephi.datalab.spi.general.GeneralActionsManipulator)1 PluginGeneralActionsManipulator (org.gephi.datalab.spi.general.PluginGeneralActionsManipulator)1 NodesManipulatorBuilder (org.gephi.datalab.spi.nodes.NodesManipulatorBuilder)1 Column (org.gephi.graph.api.Column)1 Edge (org.gephi.graph.api.Edge)1