Search in sources :

Example 16 with DialogDescriptor

use of org.openide.DialogDescriptor in project gephi-plugins-bootcamp by gephi.

the class TestAction method actionPerformed.

@Override
public void actionPerformed(ActionEvent e) {
    // Do something, display a message
    NotifyDescriptor d = new NotifyDescriptor.Message("Hello...now trying to display a dialog", NotifyDescriptor.INFORMATION_MESSAGE);
    DialogDisplayer.getDefault().notify(d);
    // Do something - for instance display a dialog
    // Dialogs API documentation: http://bits.netbeans.org/dev/javadoc/org-openide-dialogs/index.html?overview-summary.html
    DialogDescriptor dd = new DialogDescriptor(new JPanel(), "My Dialog", false, null);
    DialogDisplayer.getDefault().notify(dd);
}
Also used : NotifyDescriptor(org.openide.NotifyDescriptor) JPanel(javax.swing.JPanel) DialogDescriptor(org.openide.DialogDescriptor)

Example 17 with DialogDescriptor

use of org.openide.DialogDescriptor in project gephi-plugins-bootcamp by gephi.

the class SQLiteDatabaseExporterUI method action.

@Override
public void action() {
    // Create exporter
    final SQLiteDatabaseExporter exporter = new SQLiteDatabaseExporter();
    // Create the settings panel
    SQLiteDatabaseSettingsPanel settingPanel = new SQLiteDatabaseSettingsPanel();
    settingPanel.setup(exporter);
    final DialogDescriptor dd = new DialogDescriptor(settingPanel, "SQLite Database Export");
    Object result = DialogDisplayer.getDefault().notify(dd);
    if (result == NotifyDescriptor.OK_OPTION) {
        // This line will write the file path from the panel to the exporter's <code>setPath()<code> method.
        settingPanel.unsetup(true);
        // Create a new executor and execute
        LongTaskExecutor executor = new LongTaskExecutor(true, "SQLite Exporter");
        executor.setDefaultErrorHandler(errorHandler);
        executor.execute(exporter, new Runnable() {

            @Override
            public void run() {
                // Get the current workspace and set it to the exporter
                Workspace currentWorkspace = Lookup.getDefault().lookup(ProjectController.class).getCurrentWorkspace();
                exporter.setWorkspace(currentWorkspace);
                // Execute export
                cancelled = !exporter.execute();
                // If not cancelled, write a status line message
                if (!cancelled) {
                    StatusDisplayer.getDefault().setStatusText("Export to SQLite database completed");
                }
            }
        });
    } else {
        settingPanel.unsetup(false);
    }
}
Also used : DialogDescriptor(org.openide.DialogDescriptor) LongTaskExecutor(org.gephi.utils.longtask.api.LongTaskExecutor) Workspace(org.gephi.project.api.Workspace)

Example 18 with DialogDescriptor

use of org.openide.DialogDescriptor in project gephi by gephi.

the class DesktopImportControllerUI method importFile.

@Override
public void importFile(FileObject fileObject) {
    try {
        final FileImporter importer = controller.getFileImporter(FileUtil.toFile(fileObject));
        if (importer == null) {
            NotifyDescriptor.Message msg = new NotifyDescriptor.Message(NbBundle.getMessage(getClass(), "DesktopImportControllerUI.error_no_matching_file_importer"), NotifyDescriptor.WARNING_MESSAGE);
            DialogDisplayer.getDefault().notify(msg);
            return;
        }
        //MRU
        MostRecentFiles mostRecentFiles = Lookup.getDefault().lookup(MostRecentFiles.class);
        mostRecentFiles.addFile(fileObject.getPath());
        ImporterUI ui = controller.getUI(importer);
        if (ui != null) {
            String title = NbBundle.getMessage(DesktopImportControllerUI.class, "DesktopImportControllerUI.file.ui.dialog.title", ui.getDisplayName());
            JPanel panel = ui.getPanel();
            FileImporter[] fi = (FileImporter[]) Array.newInstance(importer.getClass(), 1);
            fi[0] = importer;
            ui.setup(fi);
            final DialogDescriptor dd = new DialogDescriptor(panel, title);
            if (panel instanceof ValidationPanel) {
                ValidationPanel vp = (ValidationPanel) panel;
                vp.addChangeListener(new ChangeListener() {

                    @Override
                    public void stateChanged(ChangeEvent e) {
                        dd.setValid(!((ValidationPanel) e.getSource()).isProblem());
                    }
                });
            }
            Object result = DialogDisplayer.getDefault().notify(dd);
            if (!result.equals(NotifyDescriptor.OK_OPTION)) {
                ui.unsetup(false);
                return;
            }
            ui.unsetup(true);
        }
        LongTask task = null;
        if (importer instanceof LongTask) {
            task = (LongTask) importer;
        }
        //Execute task
        fileObject = getArchivedFile(fileObject);
        final String containerSource = fileObject.getNameExt();
        final InputStream stream = fileObject.getInputStream();
        String taskName = NbBundle.getMessage(DesktopImportControllerUI.class, "DesktopImportControllerUI.taskName", containerSource);
        executor.execute(task, new Runnable() {

            @Override
            public void run() {
                try {
                    Container container = controller.importFile(stream, importer);
                    if (container != null) {
                        container.setSource(containerSource);
                        finishImport(container);
                    }
                } catch (Exception ex) {
                    throw new RuntimeException(ex);
                }
            }
        }, taskName, errorHandler);
    } catch (Exception ex) {
        Logger.getLogger("").log(Level.WARNING, "", ex);
    }
}
Also used : ImporterUI(org.gephi.io.importer.spi.ImporterUI) MostRecentFiles(org.gephi.desktop.mrufiles.api.MostRecentFiles) JPanel(javax.swing.JPanel) GZIPInputStream(java.util.zip.GZIPInputStream) BZip2CompressorInputStream(org.apache.commons.compress.compressors.bzip2.BZip2CompressorInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) FileImporter(org.gephi.io.importer.spi.FileImporter) ValidationPanel(org.netbeans.validation.api.ui.ValidationPanel) InvocationTargetException(java.lang.reflect.InvocationTargetException) IOException(java.io.IOException) NotifyDescriptor(org.openide.NotifyDescriptor) Container(org.gephi.io.importer.api.Container) ChangeEvent(javax.swing.event.ChangeEvent) LongTask(org.gephi.utils.longtask.spi.LongTask) DialogDescriptor(org.openide.DialogDescriptor) ChangeListener(javax.swing.event.ChangeListener) FileObject(org.openide.filesystems.FileObject)

Example 19 with DialogDescriptor

use of org.openide.DialogDescriptor in project gephi by gephi.

the class ProjectControllerUIImpl method projectProperties.

@Override
public void projectProperties() {
    Project project = controller.getCurrentProject();
    ProjectPropertiesUI ui = Lookup.getDefault().lookup(ProjectPropertiesUI.class);
    if (ui != null) {
        JPanel panel = ui.getPanel();
        ui.setup(project);
        DialogDescriptor dd = new DialogDescriptor(panel, NbBundle.getMessage(ProjectControllerUIImpl.class, "ProjectProperties_dialog_title"));
        Object result = DialogDisplayer.getDefault().notify(dd);
        if (result == NotifyDescriptor.OK_OPTION) {
            ui.unsetup(project);
        }
    }
}
Also used : Project(org.gephi.project.api.Project) ProjectPropertiesUI(org.gephi.project.spi.ProjectPropertiesUI) JPanel(javax.swing.JPanel) DialogDescriptor(org.openide.DialogDescriptor) FileObject(org.openide.filesystems.FileObject)

Example 20 with DialogDescriptor

use of org.openide.DialogDescriptor 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

DialogDescriptor (org.openide.DialogDescriptor)27 JPanel (javax.swing.JPanel)15 FileObject (org.openide.filesystems.FileObject)9 JButton (javax.swing.JButton)8 ChangeEvent (javax.swing.event.ChangeEvent)8 ChangeListener (javax.swing.event.ChangeListener)8 ActionEvent (java.awt.event.ActionEvent)7 ActionListener (java.awt.event.ActionListener)7 ValidationPanel (org.netbeans.validation.api.ui.ValidationPanel)7 Container (org.gephi.io.importer.api.Container)6 InvocationTargetException (java.lang.reflect.InvocationTargetException)5 NotifyDescriptor (org.openide.NotifyDescriptor)5 PropertyChangeEvent (java.beans.PropertyChangeEvent)4 PropertyChangeListener (java.beans.PropertyChangeListener)4 File (java.io.File)4 IOException (java.io.IOException)4 LongTask (org.gephi.utils.longtask.spi.LongTask)4 BorderLayout (java.awt.BorderLayout)3 Component (java.awt.Component)3 Dialog (java.awt.Dialog)3