Search in sources :

Example 1 with AttributeColumnsManipulatorUI

use of org.gephi.datalab.spi.columns.AttributeColumnsManipulatorUI in project gephi by gephi.

the class DataLaboratoryHelper method executeAttributeColumnsManipulator.

/**
     * Prepares the dialog UI of a AttributeColumnsManipulator 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 AttributeColumnsManipulator
     * @param graphModel Graph model of the table
     * @param table Table of the column
     * @param column Column to manipulate
     */
public void executeAttributeColumnsManipulator(final AttributeColumnsManipulator m, final GraphModel graphModel, final Table table, final Column column) {
    if (m.canManipulateColumn(table, column)) {
        SwingUtilities.invokeLater(new Runnable() {

            @Override
            public void run() {
                final AttributeColumnsManipulatorUI ui = m.getUI(table, column);
                //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, graphModel, table, column, 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();
                                executeAttributeColumnsManipulatorInOtherThread(m, table, column);
                            } 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 {
                    executeAttributeColumnsManipulatorInOtherThread(m, table, column);
                }
            }
        });
    }
}
Also used : JPanel(javax.swing.JPanel) ActionEvent(java.awt.event.ActionEvent) JButton(javax.swing.JButton) WindowAdapter(java.awt.event.WindowAdapter) AttributeColumnsManipulatorUI(org.gephi.datalab.spi.columns.AttributeColumnsManipulatorUI) ActionListener(java.awt.event.ActionListener) Dialog(java.awt.Dialog) WindowEvent(java.awt.event.WindowEvent) DialogDescriptor(org.openide.DialogDescriptor) DialogControls(org.gephi.datalab.spi.DialogControls)

Aggregations

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