Search in sources :

Example 1 with PluginGeneralActionsManipulator

use of org.gephi.datalab.spi.general.PluginGeneralActionsManipulator 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)

Aggregations

Dimension (java.awt.Dimension)1 ActionEvent (java.awt.event.ActionEvent)1 ActionListener (java.awt.event.ActionListener)1 JButton (javax.swing.JButton)1 DataLaboratoryHelper (org.gephi.datalab.api.DataLaboratoryHelper)1 GeneralActionsManipulator (org.gephi.datalab.spi.general.GeneralActionsManipulator)1 PluginGeneralActionsManipulator (org.gephi.datalab.spi.general.PluginGeneralActionsManipulator)1 JCommandButton (org.pushingpixels.flamingo.api.common.JCommandButton)1 JCommandButtonPanel (org.pushingpixels.flamingo.api.common.JCommandButtonPanel)1 JCommandPopupMenu (org.pushingpixels.flamingo.api.common.popup.JCommandPopupMenu)1 JPopupPanel (org.pushingpixels.flamingo.api.common.popup.JPopupPanel)1 PopupPanelCallback (org.pushingpixels.flamingo.api.common.popup.PopupPanelCallback)1