Search in sources :

Example 1 with DataLaboratoryHelper

use of org.gephi.datalab.api.DataLaboratoryHelper in project gephi by gephi.

the class ImportSpreadsheet method actionPerformed.

@Override
public void actionPerformed(ActionEvent e) {
    DataLaboratoryHelper dlh = Lookup.getDefault().lookup(DataLaboratoryHelper.class);
    GeneralActionsManipulator m = dlh.getGeneralActionsManipulatorByName("ImportCSV");
    if (m != null) {
        ProjectControllerUI pc = Lookup.getDefault().lookup(ProjectControllerUI.class);
        if (pc.getCurrentProject() == null) {
            //Make sure to have an active project for import
            pc.newProject();
        }
        dlh.executeManipulator(m);
    } else {
        throw new UnsupportedOperationException();
    }
}
Also used : DataLaboratoryHelper(org.gephi.datalab.api.DataLaboratoryHelper) GeneralActionsManipulator(org.gephi.datalab.spi.general.GeneralActionsManipulator) ProjectControllerUI(org.gephi.desktop.project.api.ProjectControllerUI)

Example 2 with DataLaboratoryHelper

use of org.gephi.datalab.api.DataLaboratoryHelper in project gephi by gephi.

the class PopupMenuUtils method createSubMenuFromRowColumn.

public static JMenu createSubMenuFromRowColumn(Element row, Column column) {
    DataLaboratoryHelper dlh = DataLaboratoryHelper.getDefault();
    JMenu subMenu = new JMenu(NbBundle.getMessage(PopupMenuUtils.class, "Cell.Popup.subMenu.text"));
    subMenu.setIcon(ImageUtilities.loadImageIcon("org/gephi/desktop/datalab/resources/table-select.png", true));
    Integer lastManipulatorType = null;
    for (AttributeValueManipulator am : dlh.getAttributeValueManipulators()) {
        am.setup(row, column);
        if (lastManipulatorType == null) {
            lastManipulatorType = am.getType();
        }
        if (lastManipulatorType != am.getType()) {
            subMenu.addSeparator();
        }
        lastManipulatorType = am.getType();
        subMenu.add(PopupMenuUtils.createMenuItemFromManipulator(am));
    }
    if (subMenu.getMenuComponentCount() == 0) {
        subMenu.setEnabled(false);
    }
    return subMenu;
}
Also used : DataLaboratoryHelper(org.gephi.datalab.api.DataLaboratoryHelper) AttributeValueManipulator(org.gephi.datalab.spi.values.AttributeValueManipulator) JMenu(javax.swing.JMenu)

Example 3 with DataLaboratoryHelper

use of org.gephi.datalab.api.DataLaboratoryHelper in project gephi by gephi.

the class DataTableTopComponent method prepareColumnManipulatorsButtons.

/**
     * Creates the buttons that call the AttributeColumnManipulators.
     */
private void prepareColumnManipulatorsButtons() {
    Table table;
    Column[] columns;
    if (isShowingNodesTable()) {
        table = graphModel.getNodeTable();
    } else {
        table = graphModel.getEdgeTable();
    }
    columns = getTableAvailableColumnsModel(table).getAvailableColumns();
    DataLaboratoryHelper dlh = DataLaboratoryHelper.getDefault();
    AttributeColumnsManipulator[] manipulators = dlh.getAttributeColumnsManipulators();
    JCommandButtonStrip currentButtonGroup = new JCommandButtonStrip(JCommandButtonStrip.StripOrientation.HORIZONTAL);
    currentButtonGroup.setDisplayState(CommandButtonDisplayState.BIG);
    Integer lastManipulatorType = null;
    for (AttributeColumnsManipulator acm : manipulators) {
        if (lastManipulatorType == null) {
            lastManipulatorType = acm.getType();
        }
        if (lastManipulatorType != acm.getType()) {
            columnManipulatorsPanel.add(currentButtonGroup);
            currentButtonGroup = new JCommandButtonStrip(JCommandButtonStrip.StripOrientation.HORIZONTAL);
            currentButtonGroup.setDisplayState(CommandButtonDisplayState.BIG);
        }
        lastManipulatorType = acm.getType();
        currentButtonGroup.add(prepareJCommandButton(graphModel, table, columns, acm));
    }
    columnManipulatorsPanel.add(currentButtonGroup);
}
Also used : DataLaboratoryHelper(org.gephi.datalab.api.DataLaboratoryHelper) NodesDataTable(org.gephi.desktop.datalab.tables.NodesDataTable) Table(org.gephi.graph.api.Table) EdgesDataTable(org.gephi.desktop.datalab.tables.EdgesDataTable) Column(org.gephi.graph.api.Column) AttributeColumnsManipulator(org.gephi.datalab.spi.columns.AttributeColumnsManipulator) JCommandButtonStrip(org.pushingpixels.flamingo.api.common.JCommandButtonStrip)

Example 4 with DataLaboratoryHelper

use of org.gephi.datalab.api.DataLaboratoryHelper in project gephi by gephi.

the class DataTableTopComponent method prepareGeneralActionsButtons.

/**
     * Adds the buttons for the GeneralActionsManipulators.
     */
public void prepareGeneralActionsButtons() {
    //Figure out the index to place the buttons, in order to put them between separator 2 and the boxGlue.
    int index = controlToolbar.getComponentIndex(boxGlue);
    final DataLaboratoryHelper dlh = DataLaboratoryHelper.getDefault();
    JButton button;
    for (final GeneralActionsManipulator m : dlh.getGeneralActionsManipulators()) {
        button = new JButton(m.getName(), m.getIcon());
        if (m.getDescription() != null && !m.getDescription().isEmpty()) {
            button.setToolTipText(m.getDescription());
        }
        if (m.canExecute()) {
            button.addActionListener(new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent e) {
                    dlh.executeManipulator(m);
                }
            });
        } else {
            button.setEnabled(false);
        }
        controlToolbar.add(button, index);
        index++;
        generalActionsButtons.add(button);
    }
    //Add plugin general actions as a drop down list:
    final PluginGeneralActionsManipulator[] plugins = dlh.getPluginGeneralActionsManipulators();
    if (plugins != null && plugins.length > 0) {
        JCommandButton pluginsButton = new JCommandButton(NbBundle.getMessage(DataTableTopComponent.class, "DataTableTopComponent.general.actions.plugins.button.text"), ImageWrapperResizableIcon.getIcon(ImageUtilities.loadImage("org/gephi/desktop/datalab/resources/puzzle--arrow.png", true), new Dimension(16, 16)));
        pluginsButton.setDisplayState(CommandButtonDisplayState.MEDIUM);
        pluginsButton.setCommandButtonKind(JCommandButton.CommandButtonKind.POPUP_ONLY);
        pluginsButton.setPopupCallback(new PopupPanelCallback() {

            @Override
            public JPopupPanel getPopupPanel(JCommandButton jcb) {
                JCommandButtonPanel pluginsPanel = new JCommandButtonPanel(CommandButtonDisplayState.BIG);
                Integer lastManipulatorType = null;
                int group = 1;
                pluginsPanel.addButtonGroup(NbBundle.getMessage(DataTableTopComponent.class, "DataTableTopComponent.general.actions.plugins.group.name", group));
                for (final PluginGeneralActionsManipulator m : plugins) {
                    if (lastManipulatorType == null) {
                        lastManipulatorType = m.getType();
                    }
                    if (lastManipulatorType != m.getType()) {
                        group++;
                        pluginsPanel.addButtonGroup(NbBundle.getMessage(DataTableTopComponent.class, "DataTableTopComponent.general.actions.plugins.group.name", group));
                    }
                    lastManipulatorType = m.getType();
                    pluginsPanel.addButtonToLastGroup(preparePluginGeneralActionsButton(m));
                }
                JCommandPopupMenu popup = new JCommandPopupMenu(pluginsPanel, 4, 20);
                return popup;
            }
        });
        controlToolbar.add(pluginsButton, index);
        generalActionsButtons.add(pluginsButton);
    }
    controlToolbar.updateUI();
}
Also used : ActionEvent(java.awt.event.ActionEvent) GeneralActionsManipulator(org.gephi.datalab.spi.general.GeneralActionsManipulator) PluginGeneralActionsManipulator(org.gephi.datalab.spi.general.PluginGeneralActionsManipulator) JButton(javax.swing.JButton) PopupPanelCallback(org.pushingpixels.flamingo.api.common.popup.PopupPanelCallback) JPopupPanel(org.pushingpixels.flamingo.api.common.popup.JPopupPanel) JCommandButton(org.pushingpixels.flamingo.api.common.JCommandButton) Dimension(java.awt.Dimension) DataLaboratoryHelper(org.gephi.datalab.api.DataLaboratoryHelper) PluginGeneralActionsManipulator(org.gephi.datalab.spi.general.PluginGeneralActionsManipulator) ActionListener(java.awt.event.ActionListener) JCommandButtonPanel(org.pushingpixels.flamingo.api.common.JCommandButtonPanel) JCommandPopupMenu(org.pushingpixels.flamingo.api.common.popup.JCommandPopupMenu)

Example 5 with DataLaboratoryHelper

use of org.gephi.datalab.api.DataLaboratoryHelper 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)

Aggregations

DataLaboratoryHelper (org.gephi.datalab.api.DataLaboratoryHelper)8 GeneralActionsManipulator (org.gephi.datalab.spi.general.GeneralActionsManipulator)3 Column (org.gephi.graph.api.Column)3 ActionEvent (java.awt.event.ActionEvent)2 ActionListener (java.awt.event.ActionListener)2 JPopupMenu (javax.swing.JPopupMenu)2 PluginGeneralActionsManipulator (org.gephi.datalab.spi.general.PluginGeneralActionsManipulator)2 NodesManipulator (org.gephi.datalab.spi.nodes.NodesManipulator)2 Edge (org.gephi.graph.api.Edge)2 Node (org.gephi.graph.api.Node)2 Dimension (java.awt.Dimension)1 KeyEvent (java.awt.event.KeyEvent)1 JButton (javax.swing.JButton)1 JMenu (javax.swing.JMenu)1 JMenuItem (javax.swing.JMenuItem)1 ContextMenuItemManipulator (org.gephi.datalab.spi.ContextMenuItemManipulator)1 AttributeColumnsManipulator (org.gephi.datalab.spi.columns.AttributeColumnsManipulator)1 EdgesManipulator (org.gephi.datalab.spi.edges.EdgesManipulator)1 AttributeValueManipulator (org.gephi.datalab.spi.values.AttributeValueManipulator)1 EdgesDataTable (org.gephi.desktop.datalab.tables.EdgesDataTable)1