Search in sources :

Example 21 with DialogDescriptor

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

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

Example 23 with DialogDescriptor

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

the class DataTableTopComponent method configurationButtonActionPerformed.

// GEN-LAST:event_nodesButtonActionPerformed
private void configurationButtonActionPerformed(java.awt.event.ActionEvent evt) {
    // GEN-FIRST:event_configurationButtonActionPerformed
    DialogDescriptor dd = new DialogDescriptor(new ConfigurationPanel(this, graphModel), NbBundle.getMessage(DataTableTopComponent.class, "ConfigurationPanel.title"));
    dd.setOptions(new Object[] { DialogDescriptor.OK_OPTION });
    DialogDisplayer.getDefault().notify(dd);
    // Save preferences:
    NbPreferences.forModule(DataTableTopComponent.class).putBoolean(DATA_LABORATORY_ONLY_VISIBLE, visibleOnly);
    NbPreferences.forModule(DataTableTopComponent.class).putBoolean(DATA_LABORATORY_SPARKLINES, useSparklines);
    NbPreferences.forModule(DataTableTopComponent.class).putBoolean(DATA_LABORATORY_TIME_INTERVAL_GRAPHICS, timeIntervalGraphics);
    NbPreferences.forModule(DataTableTopComponent.class).putBoolean(DATA_LABORATORY_EDGES_NODES_LABELS, showEdgesNodesLabels);
}
Also used : DialogDescriptor(org.openide.DialogDescriptor)

Example 24 with DialogDescriptor

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

the class DesktopImportControllerUI method importWizard.

@Override
public void importWizard(final WizardImporter importer) {
    try {
        if (importer == null) {
            NotifyDescriptor.Message msg = new NotifyDescriptor.Message(NbBundle.getMessage(DesktopImportControllerUI.class, "DesktopImportControllerUI.error_no_matching_db_importer"), NotifyDescriptor.WARNING_MESSAGE);
            DialogDisplayer.getDefault().notify(msg);
            return;
        }
        String containerSource = NbBundle.getMessage(DesktopImportControllerUI.class, "DesktopImportControllerUI.wizardSource", "");
        ImporterUI ui = controller.getUI(importer);
        if (ui != null) {
            String title = NbBundle.getMessage(DesktopImportControllerUI.class, "DesktopImportControllerUI.wizard.ui.dialog.title", ui.getDisplayName());
            JPanel panel = ui.getPanel();
            ui.setup(new WizardImporter[] { importer });
            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.CANCEL_OPTION) || result.equals(NotifyDescriptor.CLOSED_OPTION)) {
                ui.unsetup(false);
                return;
            }
            ui.unsetup(true);
            containerSource = ui.getDisplayName();
        }
        ImporterWizardUI wizardUI = controller.getWizardUI(importer);
        if (wizardUI != null) {
            containerSource = wizardUI.getCategory() + ":" + wizardUI.getDisplayName();
        }
        LongTask task = null;
        if (importer instanceof LongTask) {
            task = (LongTask) importer;
        }
        // Execute task
        final String source = containerSource;
        String taskName = NbBundle.getMessage(DesktopImportControllerUI.class, "DesktopImportControllerUI.taskName", containerSource);
        executor.execute(task, new Runnable() {

            @Override
            public void run() {
                try {
                    Container container = controller.importWizard(importer);
                    if (container != null) {
                        container.setSource(source);
                        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) JPanel(javax.swing.JPanel) ValidationPanel(org.netbeans.validation.api.ui.ValidationPanel) ImporterWizardUI(org.gephi.io.importer.spi.ImporterWizardUI) 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 25 with DialogDescriptor

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

the class DesktopImportControllerUI method importFiles.

private void importFiles(final Reader[] readers, final FileImporter[] importers, FileObject[] fileObjects) {
    try {
        File[] files = new File[readers.length];
        Map<ImporterUI, List<FileImporter>> importerUIs = new HashMap<>();
        for (int i = 0; i < importers.length; i++) {
            FileImporter importer = importers[i];
            ImporterUI ui = controller.getUI(importer);
            if (ui != null) {
                List<FileImporter> l = importerUIs.get(ui);
                if (l == null) {
                    l = new ArrayList<>();
                    importerUIs.put(ui, l);
                }
                l.add(importer);
            }
            if (importer instanceof FileImporter.FileAware) {
                try (Reader reader = readers[i]) {
                    File file = null;
                    if (fileObjects != null) {
                        file = FileUtil.toFile(fileObjects[i]);
                    }
                    if (file == null) {
                        // There is no source file but the importer needs it, create temporary copy:
                        String fileName = "tmp_file" + 1;
                        String charset = "UTF-8";
                        if (fileObjects != null && fileObjects[i] != null) {
                            // Netbeans FileUtil.toFile bug returning null?? Try to recover:
                            fileName = fileObjects[i].getNameExt();
                            CharsetToolkit charsetToolkit = new CharsetToolkit(fileObjects[i].getInputStream());
                            charset = charsetToolkit.getCharset().name();
                        }
                        file = TempDirUtils.createTempDir().createFile(fileName);
                        try (FileOutputStream fos = new FileOutputStream(file)) {
                            FileUtil.copy(new ReaderInputStream(reader, charset), fos);
                        }
                    }
                    files[i] = file;
                    ((FileImporter.FileAware) importer).setFile(file);
                }
            }
        }
        for (Map.Entry<ImporterUI, List<FileImporter>> entry : importerUIs.entrySet()) {
            ImporterUI ui = entry.getKey();
            String title = NbBundle.getMessage(DesktopImportControllerUI.class, "DesktopImportControllerUI.file.ui.dialog.title", ui.getDisplayName());
            JPanel panel = ui.getPanel();
            FileImporter[] fi = (FileImporter[]) entry.getValue().toArray((FileImporter[]) Array.newInstance(entry.getValue().get(0).getClass(), 0));
            ui.setup(fi);
            if (panel != null) {
                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;
                }
            }
            if (ui instanceof ImporterUI.WithWizard) {
                boolean finishedOk = showWizard(ui, ((ImporterUI.WithWizard) ui).getWizardDescriptor());
                if (!finishedOk) {
                    ui.unsetup(false);
                    return;
                }
            }
            ui.unsetup(true);
        }
        final List<Container> results = new ArrayList<>();
        for (int i = 0; i < importers.length; i++) {
            doImport(results, readers[i], files[i], importers[i]);
        }
        executor.execute(null, new Runnable() {

            @Override
            public void run() {
                if (!results.isEmpty()) {
                    finishImport(results.toArray(new Container[0]));
                }
            }
        });
    } catch (Exception ex) {
        Exceptions.printStackTrace(ex);
    }
}
Also used : ImporterUI(org.gephi.io.importer.spi.ImporterUI) JPanel(javax.swing.JPanel) HashMap(java.util.HashMap) CharsetToolkit(org.gephi.utils.CharsetToolkit) FileImporter(org.gephi.io.importer.spi.FileImporter) ArrayList(java.util.ArrayList) Reader(java.io.Reader) Container(org.gephi.io.importer.api.Container) List(java.util.List) ArrayList(java.util.ArrayList) ChangeListener(javax.swing.event.ChangeListener) ValidationPanel(org.netbeans.validation.api.ui.ValidationPanel) InvocationTargetException(java.lang.reflect.InvocationTargetException) IOException(java.io.IOException) ReaderInputStream(org.openide.util.io.ReaderInputStream) ChangeEvent(javax.swing.event.ChangeEvent) FileOutputStream(java.io.FileOutputStream) DialogDescriptor(org.openide.DialogDescriptor) FileObject(org.openide.filesystems.FileObject) File(java.io.File) Map(java.util.Map) HashMap(java.util.HashMap)

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