Search in sources :

Example 6 with DialogDescriptor

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

the class DesktopImportControllerUI method importDatabase.

@Override
public void importDatabase(Database database, final DatabaseImporter 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;
        }
        ImporterUI ui = controller.getUI(importer);
        if (ui != null) {
            String title = NbBundle.getMessage(DesktopImportControllerUI.class, "DesktopImportControllerUI.database.ui.dialog.title");
            JPanel panel = ui.getPanel();
            ui.setup(new DatabaseImporter[] { 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);
            if (database == null) {
                database = importer.getDatabase();
            }
        }
        LongTask task = null;
        if (importer instanceof LongTask) {
            task = (LongTask) importer;
        }
        // Execute task
        final String containerSource = database != null ? database.getName() : (ui != null ? ui.getDisplayName() : importer.getClass().getSimpleName());
        final Database db = database;
        String taskName = NbBundle.getMessage(DesktopImportControllerUI.class, "DesktopImportControllerUI.taskName", containerSource);
        executor.execute(task, new Runnable() {

            @Override
            public void run() {
                try {
                    Container container = controller.importDatabase(db, 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) JPanel(javax.swing.JPanel) 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) Database(org.gephi.io.importer.api.Database) DialogDescriptor(org.openide.DialogDescriptor) ChangeListener(javax.swing.event.ChangeListener) FileObject(org.openide.filesystems.FileObject)

Example 7 with DialogDescriptor

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

the class DesktopImportControllerUI method showProcessorIssues.

private void showProcessorIssues(Report report) {
    ProcessorIssuesReportPanel issuesReport = new ProcessorIssuesReportPanel();
    issuesReport.setData(report);
    DialogDescriptor dd = new DialogDescriptor(issuesReport, NbBundle.getMessage(DesktopImportControllerUI.class, "ProcessorIssuesReportPanel.title"));
    dd.setOptions(new Object[] { NbBundle.getMessage(DesktopImportControllerUI.class, "ProcessorIssuesReportPanel.close") });
    DialogDisplayer.getDefault().notify(dd);
    issuesReport.destroy();
}
Also used : DialogDescriptor(org.openide.DialogDescriptor)

Example 8 with DialogDescriptor

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

the class DesktopImportControllerUI method finishImport.

private void finishImport(Container[] containers) {
    Report finalReport = new Report();
    for (Container container : containers) {
        if (container.verify()) {
            Report report = container.getReport();
            report.close();
            finalReport.append(report);
        } else {
        // TODO
        }
    }
    finalReport.close();
    // Report panel
    ReportPanel reportPanel = new ReportPanel();
    reportPanel.setData(finalReport, containers);
    DialogDescriptor dd = new DialogDescriptor(reportPanel, NbBundle.getMessage(DesktopImportControllerUI.class, "ReportPanel.title"));
    Object response = DialogDisplayer.getDefault().notify(dd);
    reportPanel.destroy();
    finalReport.clean();
    for (Container c : containers) {
        c.getReport().clean();
    }
    if (!response.equals(NotifyDescriptor.OK_OPTION)) {
        return;
    }
    final Processor processor = reportPanel.getProcessor();
    // Project
    Workspace workspace = null;
    ProjectController pc = Lookup.getDefault().lookup(ProjectController.class);
    ProjectControllerUI pcui = Lookup.getDefault().lookup(ProjectControllerUI.class);
    if (pc.getCurrentProject() == null) {
        pcui.newProject();
        workspace = pc.getCurrentWorkspace();
    }
    // Process
    final ProcessorUI pui = getProcessorUI(processor);
    final ValidResult validResult = new ValidResult();
    if (pui != null) {
        try {
            final JPanel panel = pui.getPanel();
            if (panel != null) {
                SwingUtilities.invokeAndWait(new Runnable() {

                    @Override
                    public void run() {
                        String title = NbBundle.getMessage(DesktopImportControllerUI.class, "DesktopImportControllerUI.processor.ui.dialog.title");
                        pui.setup(processor);
                        final DialogDescriptor dd2 = new DialogDescriptor(panel, title);
                        if (panel instanceof ValidationPanel) {
                            ValidationPanel vp = (ValidationPanel) panel;
                            vp.addChangeListener(new ChangeListener() {

                                @Override
                                public void stateChanged(ChangeEvent e) {
                                    dd2.setValid(!((ValidationPanel) e.getSource()).isProblem());
                                }
                            });
                            dd2.setValid(!vp.isProblem());
                        }
                        Object result = DialogDisplayer.getDefault().notify(dd2);
                        if (result.equals(NotifyDescriptor.CANCEL_OPTION) || result.equals(NotifyDescriptor.CLOSED_OPTION)) {
                            validResult.setResult(false);
                        } else {
                            // true
                            pui.unsetup();
                            validResult.setResult(true);
                        }
                    }
                });
            }
        } catch (InterruptedException | InvocationTargetException ex) {
            Exceptions.printStackTrace(ex);
        }
    }
    if (validResult.isResult()) {
        controller.process(containers, processor, workspace);
        Report report = processor.getReport();
        if (report != null && !report.isEmpty()) {
            showProcessorIssues(report);
        }
        // StatusLine notify
        StatusDisplayer.getDefault().setStatusText(NbBundle.getMessage(DesktopImportControllerUI.class, "DesktopImportControllerUI.status.multiImportSuccess", containers.length));
    }
}
Also used : JPanel(javax.swing.JPanel) Processor(org.gephi.io.processor.spi.Processor) Report(org.gephi.io.importer.api.Report) ValidationPanel(org.netbeans.validation.api.ui.ValidationPanel) ProjectController(org.gephi.project.api.ProjectController) ProcessorUI(org.gephi.io.processor.spi.ProcessorUI) InvocationTargetException(java.lang.reflect.InvocationTargetException) Container(org.gephi.io.importer.api.Container) ChangeEvent(javax.swing.event.ChangeEvent) DialogDescriptor(org.openide.DialogDescriptor) FileObject(org.openide.filesystems.FileObject) ChangeListener(javax.swing.event.ChangeListener) Workspace(org.gephi.project.api.Workspace) ProjectControllerUI(org.gephi.desktop.project.api.ProjectControllerUI)

Example 9 with DialogDescriptor

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

the class StatisticsFrontEnd method run.

private void run() {
    GraphController graphController = Lookup.getDefault().lookup(GraphController.class);
    GraphModel graphModel = graphController.getGraphModel();
    // Create Statistics
    StatisticsController controller = Lookup.getDefault().lookup(StatisticsController.class);
    StatisticsControllerUI controllerUI = Lookup.getDefault().lookup(StatisticsControllerUI.class);
    StatisticsBuilder builder = controller.getBuilder(statisticsUI.getStatisticsClass());
    currentStatistics = builder.getStatistics();
    if (currentStatistics != null) {
        if (currentStatistics instanceof DynamicStatistics && !graphModel.isDynamic()) {
            DialogDisplayer.getDefault().notifyLater(new NotifyDescriptor.Message(NbBundle.getMessage(StatisticsFrontEnd.class, "StatisticsFrontEnd.notDynamicGraph"), NotifyDescriptor.WARNING_MESSAGE));
            return;
        }
        LongTaskListener listener = new LongTaskListener() {

            @Override
            public void taskFinished(LongTask task) {
                showReport();
            }
        };
        JPanel settingsPanel = statisticsUI.getSettingsPanel();
        if (currentStatistics instanceof DynamicStatistics) {
            DynamicSettingsPanel dynamicPanel = new DynamicSettingsPanel();
            statisticsUI.setup(currentStatistics);
            dynamicPanel.setup((DynamicStatistics) currentStatistics);
            JPanel dynamicSettingsPanel = DynamicSettingsPanel.createCounpoundPanel(dynamicPanel, settingsPanel);
            final DialogDescriptor dd = new DialogDescriptor(dynamicSettingsPanel, NbBundle.getMessage(StatisticsTopComponent.class, "StatisticsFrontEnd.settingsPanel.title", builder.getName()));
            if (dynamicSettingsPanel instanceof ValidationPanel) {
                ValidationPanel vp = (ValidationPanel) dynamicSettingsPanel;
                vp.addChangeListener(new ChangeListener() {

                    @Override
                    public void stateChanged(ChangeEvent e) {
                        dd.setValid(!((ValidationPanel) e.getSource()).isProblem());
                    }
                });
            }
            if (DialogDisplayer.getDefault().notify(dd).equals(NotifyDescriptor.OK_OPTION)) {
                dynamicPanel.unsetup((DynamicStatistics) currentStatistics);
                statisticsUI.unsetup();
                controllerUI.execute(currentStatistics, listener);
            }
        } else if (settingsPanel != null) {
            statisticsUI.setup(currentStatistics);
            final DialogDescriptor dd = new DialogDescriptor(settingsPanel, NbBundle.getMessage(StatisticsTopComponent.class, "StatisticsFrontEnd.settingsPanel.title", builder.getName()));
            if (settingsPanel instanceof ValidationPanel) {
                ValidationPanel vp = (ValidationPanel) settingsPanel;
                vp.addChangeListener(new ChangeListener() {

                    @Override
                    public void stateChanged(ChangeEvent e) {
                        dd.setValid(!((ValidationPanel) e.getSource()).isProblem());
                    }
                });
            }
            if (DialogDisplayer.getDefault().notify(dd).equals(NotifyDescriptor.OK_OPTION)) {
                statisticsUI.unsetup();
                controllerUI.execute(currentStatistics, listener);
            }
        } else {
            statisticsUI.setup(currentStatistics);
            controllerUI.execute(currentStatistics, listener);
        }
    }
}
Also used : JPanel(javax.swing.JPanel) LongTaskListener(org.gephi.utils.longtask.api.LongTaskListener) DynamicStatistics(org.gephi.statistics.spi.DynamicStatistics) StatisticsBuilder(org.gephi.statistics.spi.StatisticsBuilder) ValidationPanel(org.netbeans.validation.api.ui.ValidationPanel) NotifyDescriptor(org.openide.NotifyDescriptor) StatisticsController(org.gephi.statistics.api.StatisticsController) LongTask(org.gephi.utils.longtask.spi.LongTask) ChangeEvent(javax.swing.event.ChangeEvent) GraphModel(org.gephi.graph.api.GraphModel) DialogDescriptor(org.openide.DialogDescriptor) ChangeListener(javax.swing.event.ChangeListener) GraphController(org.gephi.graph.api.GraphController) StatisticsControllerUI(org.gephi.desktop.statistics.api.StatisticsControllerUI)

Example 10 with DialogDescriptor

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

the class SearchReplace method execute.

@Override
public void execute() {
    SearchReplaceUI ui = Lookup.getDefault().lookup(SearchReplaceUI.class);
    if (ui.isActive()) {
        // Do not open more than one Search/Replace dialog
        return;
    }
    if (Lookup.getDefault().lookup(DataTablesController.class).isNodeTableMode()) {
        ui.setMode(SearchReplaceUI.Mode.NODES_TABLE);
    } else {
        ui.setMode(SearchReplaceUI.Mode.EDGES_TABLE);
    }
    DialogDescriptor dd = new DialogDescriptor(ui, getName());
    dd.setModal(true);
    dd.setOptions(new Object[] { NbBundle.getMessage(SearchReplace.class, "SearchReplace.window.close") });
    ui.setActive(true);
    DialogDisplayer.getDefault().notify(dd);
    ui.setActive(false);
}
Also used : SearchReplaceUI(org.gephi.datalab.plugin.manipulators.general.ui.SearchReplaceUI) DialogDescriptor(org.openide.DialogDescriptor) DataTablesController(org.gephi.datalab.api.datatables.DataTablesController)

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