Search in sources :

Example 1 with StatisticsController

use of org.gephi.statistics.api.StatisticsController in project gephi by gephi.

the class StatisticsControllerUIImpl method execute.

@Override
public void execute(final Statistics statistics) {
    StatisticsController controller = Lookup.getDefault().lookup(StatisticsController.class);
    final StatisticsUI[] uis = getUI(statistics);
    for (StatisticsUI s : uis) {
        s.setup(statistics);
    }
    model.setRunning(statistics, true);
    controller.execute(statistics, new LongTaskListener() {

        @Override
        public void taskFinished(LongTask task) {
            model.setRunning(statistics, false);
            for (StatisticsUI s : uis) {
                model.addResult(s);
                s.unsetup();
            }
        }
    });
}
Also used : StatisticsController(org.gephi.statistics.api.StatisticsController) LongTaskListener(org.gephi.utils.longtask.api.LongTaskListener) LongTask(org.gephi.utils.longtask.spi.LongTask) StatisticsUI(org.gephi.statistics.spi.StatisticsUI)

Example 2 with StatisticsController

use of org.gephi.statistics.api.StatisticsController in project gephi by gephi.

the class StatisticsControllerUIImpl method execute.

@Override
public void execute(final Statistics statistics, final LongTaskListener listener) {
    StatisticsController controller = Lookup.getDefault().lookup(StatisticsController.class);
    final StatisticsUI[] uis = getUI(statistics);
    for (StatisticsUI s : uis) {
        s.setup(statistics);
    }
    model.setRunning(statistics, true);
    controller.execute(statistics, new LongTaskListener() {

        @Override
        public void taskFinished(LongTask task) {
            model.setRunning(statistics, false);
            for (StatisticsUI s : uis) {
                model.addResult(s);
                s.unsetup();
            }
            if (listener != null) {
                listener.taskFinished(statistics instanceof LongTask ? (LongTask) statistics : null);
            }
        }
    });
}
Also used : StatisticsController(org.gephi.statistics.api.StatisticsController) LongTaskListener(org.gephi.utils.longtask.api.LongTaskListener) LongTask(org.gephi.utils.longtask.spi.LongTask) StatisticsUI(org.gephi.statistics.spi.StatisticsUI)

Example 3 with StatisticsController

use of org.gephi.statistics.api.StatisticsController 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)

Aggregations

StatisticsController (org.gephi.statistics.api.StatisticsController)3 LongTaskListener (org.gephi.utils.longtask.api.LongTaskListener)3 LongTask (org.gephi.utils.longtask.spi.LongTask)3 StatisticsUI (org.gephi.statistics.spi.StatisticsUI)2 JPanel (javax.swing.JPanel)1 ChangeEvent (javax.swing.event.ChangeEvent)1 ChangeListener (javax.swing.event.ChangeListener)1 StatisticsControllerUI (org.gephi.desktop.statistics.api.StatisticsControllerUI)1 GraphController (org.gephi.graph.api.GraphController)1 GraphModel (org.gephi.graph.api.GraphModel)1 DynamicStatistics (org.gephi.statistics.spi.DynamicStatistics)1 StatisticsBuilder (org.gephi.statistics.spi.StatisticsBuilder)1 ValidationPanel (org.netbeans.validation.api.ui.ValidationPanel)1 DialogDescriptor (org.openide.DialogDescriptor)1 NotifyDescriptor (org.openide.NotifyDescriptor)1