Search in sources :

Example 1 with ManipulatorUI

use of org.gephi.datalab.spi.ManipulatorUI in project gephi by gephi.

the class DataLaboratoryHelper method executeManipulator.

/**
     * Prepares the dialog UI of a manipulator if it has one and executes the manipulator in a separate
     * Thread when the dialog is accepted or directly if there is no UI.
     * @param m Manipulator to execute
     */
public void executeManipulator(final Manipulator m) {
    if (m.canExecute()) {
        SwingUtilities.invokeLater(new Runnable() {

            @Override
            public void run() {
                final ManipulatorUI ui = m.getUI();
                //Show a dialog for the manipulator UI if it provides one. If not, execute the manipulator directly:
                if (ui != null) {
                    final JButton okButton = new JButton(NbBundle.getMessage(DataLaboratoryHelper.class, "DataLaboratoryHelper.ui.okButton.text"));
                    DialogControls dialogControls = new DialogControlsImpl(okButton);
                    ui.setup(m, dialogControls);
                    JPanel settingsPanel = ui.getSettingsPanel();
                    DialogDescriptor dd = new DialogDescriptor(settingsPanel, NbBundle.getMessage(DataLaboratoryHelper.class, "SettingsPanel.title", ui.getDisplayName()), ui.isModal(), new ActionListener() {

                        @Override
                        public void actionPerformed(ActionEvent e) {
                            if (e.getSource().equals(okButton)) {
                                ui.unSetup();
                                executeManipulatorInOtherThread(m);
                            } else {
                                ui.unSetup();
                            }
                        }
                    });
                    dd.setOptions(new Object[] { okButton, DialogDescriptor.CANCEL_OPTION });
                    //All options close
                    dd.setClosingOptions(null);
                    Dialog dialog = DialogDisplayer.getDefault().createDialog(dd);
                    dialog.addWindowListener(new WindowAdapter() {

                        @Override
                        public void windowClosing(WindowEvent e) {
                            ui.unSetup();
                        }
                    });
                    dialog.setVisible(true);
                } else {
                    executeManipulatorInOtherThread(m);
                }
            }
        });
    }
}
Also used : JPanel(javax.swing.JPanel) ActionEvent(java.awt.event.ActionEvent) JButton(javax.swing.JButton) WindowAdapter(java.awt.event.WindowAdapter) ActionListener(java.awt.event.ActionListener) AttributeColumnsManipulatorUI(org.gephi.datalab.spi.columns.AttributeColumnsManipulatorUI) ManipulatorUI(org.gephi.datalab.spi.ManipulatorUI) Dialog(java.awt.Dialog) WindowEvent(java.awt.event.WindowEvent) DialogDescriptor(org.openide.DialogDescriptor) DialogControls(org.gephi.datalab.spi.DialogControls)

Example 2 with ManipulatorUI

use of org.gephi.datalab.spi.ManipulatorUI in project gephi by gephi.

the class DataLaboratoryHelper method showAttributeRowsMergeStrategyUIDialog.

/**
     * This method shows the UI of an AttributeRowsMergeStrategy if it is provided and the AttributeRowsMergeStrategy can be executed.
     * These UI only configures (calls unSetup) the AttributeRowsMergeStrategy if the dialog is accepted,
     * and it does not execute the AttributeRowsMergeStrategy.
     * @param m AttributeRowsMergeStrategy
     * @return True if the AttributeRowsMergeStrategy UI is provided
     */
public boolean showAttributeRowsMergeStrategyUIDialog(final AttributeRowsMergeStrategy m) {
    final ManipulatorUI ui = m.getUI();
    //Show a dialog for the manipulator UI if it provides one. If not, execute the manipulator directly:
    if (ui != null && m.canExecute()) {
        final JButton okButton = new JButton(NbBundle.getMessage(DataLaboratoryHelper.class, "DataLaboratoryHelper.ui.okButton.text"));
        DialogControls dialogControls = new DialogControlsImpl(okButton);
        ui.setup(m, dialogControls);
        JPanel settingsPanel = ui.getSettingsPanel();
        DialogDescriptor dd = new DialogDescriptor(settingsPanel, NbBundle.getMessage(DataLaboratoryHelper.class, "SettingsPanel.title", ui.getDisplayName()), ui.isModal(), new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                if (e.getSource().equals(okButton)) {
                    ui.unSetup();
                }
            }
        });
        dd.setOptions(new Object[] { okButton, DialogDescriptor.CANCEL_OPTION });
        //All options close
        dd.setClosingOptions(null);
        Dialog dialog = DialogDisplayer.getDefault().createDialog(dd);
        dialog.setVisible(true);
        return true;
    }
    return false;
}
Also used : JPanel(javax.swing.JPanel) ActionListener(java.awt.event.ActionListener) AttributeColumnsManipulatorUI(org.gephi.datalab.spi.columns.AttributeColumnsManipulatorUI) ManipulatorUI(org.gephi.datalab.spi.ManipulatorUI) ActionEvent(java.awt.event.ActionEvent) Dialog(java.awt.Dialog) JButton(javax.swing.JButton) DialogDescriptor(org.openide.DialogDescriptor) DialogControls(org.gephi.datalab.spi.DialogControls)

Aggregations

Dialog (java.awt.Dialog)2 ActionEvent (java.awt.event.ActionEvent)2 ActionListener (java.awt.event.ActionListener)2 JButton (javax.swing.JButton)2 JPanel (javax.swing.JPanel)2 DialogControls (org.gephi.datalab.spi.DialogControls)2 ManipulatorUI (org.gephi.datalab.spi.ManipulatorUI)2 AttributeColumnsManipulatorUI (org.gephi.datalab.spi.columns.AttributeColumnsManipulatorUI)2 DialogDescriptor (org.openide.DialogDescriptor)2 WindowAdapter (java.awt.event.WindowAdapter)1 WindowEvent (java.awt.event.WindowEvent)1