Search in sources :

Example 1 with GeneratorUI

use of org.gephi.io.generator.spi.GeneratorUI in project gephi by gephi.

the class DesktopGeneratorController method generate.

@Override
public void generate(final Generator generator) {
    String title = generator.getName();
    GeneratorUI ui = generator.getUI();
    if (ui != null) {
        ui.setup(generator);
        JPanel panel = ui.getPanel();
        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 != NotifyDescriptor.OK_OPTION) {
            return;
        }
        ui.unsetup();
    }
    final Container container = Lookup.getDefault().lookup(Container.Factory.class).newContainer();
    container.setSource("" + generator.getName());
    container.setReport(new Report());
    String taskname = NbBundle.getMessage(DesktopGeneratorController.class, "DesktopGeneratorController.taskname", generator.getName());
    // Error handler
    LongTaskErrorHandler errorHandler = new LongTaskErrorHandler() {

        @Override
        public void fatalError(Throwable t) {
            Exceptions.printStackTrace(t);
        }
    };
    // Execute
    executor.execute(generator, new Runnable() {

        @Override
        public void run() {
            generator.generate(container.getLoader());
            finishGenerate(container);
        }
    }, taskname, errorHandler);
}
Also used : JPanel(javax.swing.JPanel) Report(org.gephi.io.importer.api.Report) ValidationPanel(org.netbeans.validation.api.ui.ValidationPanel) GeneratorUI(org.gephi.io.generator.spi.GeneratorUI) Container(org.gephi.io.importer.api.Container) ChangeEvent(javax.swing.event.ChangeEvent) DialogDescriptor(org.openide.DialogDescriptor) ChangeListener(javax.swing.event.ChangeListener) LongTaskErrorHandler(org.gephi.utils.longtask.api.LongTaskErrorHandler)

Aggregations

JPanel (javax.swing.JPanel)1 ChangeEvent (javax.swing.event.ChangeEvent)1 ChangeListener (javax.swing.event.ChangeListener)1 GeneratorUI (org.gephi.io.generator.spi.GeneratorUI)1 Container (org.gephi.io.importer.api.Container)1 Report (org.gephi.io.importer.api.Report)1 LongTaskErrorHandler (org.gephi.utils.longtask.api.LongTaskErrorHandler)1 ValidationPanel (org.netbeans.validation.api.ui.ValidationPanel)1 DialogDescriptor (org.openide.DialogDescriptor)1