Search in sources :

Example 1 with ProjectControllerUI

use of org.gephi.desktop.project.api.ProjectControllerUI 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 ex) {
            Exceptions.printStackTrace(ex);
        } catch (InvocationTargetException ex) {
            Exceptions.printStackTrace(ex);
        }
    }
    if (validResult.isResult()) {
        controller.process(containers, processor, workspace);
        //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 2 with ProjectControllerUI

use of org.gephi.desktop.project.api.ProjectControllerUI in project gephi by gephi.

the class ImportSpreadsheet method actionPerformed.

@Override
public void actionPerformed(ActionEvent e) {
    DataLaboratoryHelper dlh = Lookup.getDefault().lookup(DataLaboratoryHelper.class);
    GeneralActionsManipulator m = dlh.getGeneralActionsManipulatorByName("ImportCSV");
    if (m != null) {
        ProjectControllerUI pc = Lookup.getDefault().lookup(ProjectControllerUI.class);
        if (pc.getCurrentProject() == null) {
            //Make sure to have an active project for import
            pc.newProject();
        }
        dlh.executeManipulator(m);
    } else {
        throw new UnsupportedOperationException();
    }
}
Also used : DataLaboratoryHelper(org.gephi.datalab.api.DataLaboratoryHelper) GeneralActionsManipulator(org.gephi.datalab.spi.general.GeneralActionsManipulator) ProjectControllerUI(org.gephi.desktop.project.api.ProjectControllerUI)

Example 3 with ProjectControllerUI

use of org.gephi.desktop.project.api.ProjectControllerUI in project gephi by gephi.

the class DesktopGeneratorController method finishGenerate.

private void finishGenerate(Container container) {
    ProjectController pc = Lookup.getDefault().lookup(ProjectController.class);
    ProjectControllerUI pcui = Lookup.getDefault().lookup(ProjectControllerUI.class);
    Workspace workspace;
    if (pc.getCurrentProject() == null) {
        pcui.newProject();
        workspace = pc.getCurrentWorkspace();
    } else {
        workspace = pc.newWorkspace(pc.getCurrentProject());
        pc.openWorkspace(workspace);
    }
    if (container.getSource() != null) {
        pc.setSource(workspace, container.getSource());
    }
    container.closeLoader();
    DefaultProcessor defaultProcessor = new DefaultProcessor();
    defaultProcessor.setContainers(new ContainerUnloader[] { container.getUnloader() });
    defaultProcessor.setWorkspace(workspace);
    defaultProcessor.process();
}
Also used : DefaultProcessor(org.gephi.io.processor.plugin.DefaultProcessor) ProjectController(org.gephi.project.api.ProjectController) ProjectControllerUI(org.gephi.desktop.project.api.ProjectControllerUI) Workspace(org.gephi.project.api.Workspace)

Example 4 with ProjectControllerUI

use of org.gephi.desktop.project.api.ProjectControllerUI in project gephi-plugins-bootcamp by gephi.

the class StreamingDynamicGraph method generate.

@Override
public void generate(ContainerLoader container) {
    //Reset cancel
    cancel = false;
    //Start progress
    Progress.start(progressTicket);
    //Project
    ProjectController projectController = Lookup.getDefault().lookup(ProjectController.class);
    ProjectControllerUI projectControllerUI = Lookup.getDefault().lookup(ProjectControllerUI.class);
    if (projectController.getCurrentProject() == null) {
        projectControllerUI.newProject();
    }
    //Get current graph
    GraphController graphController = Lookup.getDefault().lookup(GraphController.class);
    GraphModel graphModel = graphController.getGraphModel();
    Graph graph = graphModel.getGraph();
    //Create list of nodes and a random obj
    List<Node> nodes = new ArrayList<Node>();
    Random random = new Random(232323);
    //Create nodes and edges until cancelled
    while (!cancel) {
        //Create a new node and assign random position
        Node n = graphModel.factory().newNode();
        n.setX(random.nextInt(2000) - 1000);
        n.setY(random.nextInt(2000) - 1000);
        //Create a new random time interval and set it to the node
        //Min value is 100
        double min = random.nextInt(2000) + 100;
        //Max value is 2099
        double max = random.nextInt(2000) + 100;
        Interval timeInterval = new Interval(min < max ? min : max, max > min ? max : min);
        n.addInterval(timeInterval);
        //Add the node to the graph
        graph.addNode(n);
        //Add a random number of edges between 0 and 3
        int nbedges = random.nextInt(4);
        for (int i = 0; i < nbedges; i++) {
            //Shuffle an index in the list of nodes 
            int index = random.nextInt(nodes.size() + 1);
            if (index < nodes.size()) {
                //Add an edge if not already exist
                Node m = nodes.get(index);
                if (n != m && graph.getEdge(n, m) == null) {
                    Edge e = graphModel.factory().newEdge(n, m);
                    graph.addEdge(e);
                }
            }
        }
        //Add the node to the list of nodes
        nodes.add(n);
        //Sleep some time
        try {
            Thread.sleep(delay);
        } catch (InterruptedException ex) {
            Exceptions.printStackTrace(ex);
        }
    }
    Progress.finish(progressTicket);
}
Also used : ArrayList(java.util.ArrayList) ProjectController(org.gephi.project.api.ProjectController) Random(java.util.Random) ProjectControllerUI(org.gephi.desktop.project.api.ProjectControllerUI)

Example 5 with ProjectControllerUI

use of org.gephi.desktop.project.api.ProjectControllerUI in project gephi by gephi.

the class WelcomeTopComponent method initAction.

private void initAction() {
    openAction = new AbstractAction("", ImageUtilities.loadImageIcon("org/gephi/desktop/welcome/resources/gephifile20.png", false)) {

        @Override
        public void actionPerformed(ActionEvent e) {
            JXHyperlink link = (JXHyperlink) e.getSource();
            File file = (File) link.getClientProperty(LINK_PATH);
            FileObject fileObject = FileUtil.toFileObject(file);
            if (fileObject.hasExt(GEPHI_EXTENSION)) {
                ProjectControllerUI pc = Lookup.getDefault().lookup(ProjectControllerUI.class);
                try {
                    pc.openProject(file);
                } catch (Exception ex) {
                    ex.printStackTrace();
                    NotifyDescriptor.Message msg = new NotifyDescriptor.Message(NbBundle.getMessage(WelcomeTopComponent.class, "WelcomeTopComponent.openGephiError"), NotifyDescriptor.WARNING_MESSAGE);
                    DialogDisplayer.getDefault().notify(msg);
                }
            } else {
                ImportControllerUI importController = Lookup.getDefault().lookup(ImportControllerUI.class);
                if (importController.getImportController().isFileSupported(FileUtil.toFile(fileObject))) {
                    importController.importFile(fileObject);
                }
            }
            closeDialog();
        }
    };
    newProjectLink.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            ProjectControllerUI pc = Lookup.getDefault().lookup(ProjectControllerUI.class);
            pc.newProject();
            closeDialog();
        }
    });
    openFileLink.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            ProjectControllerUI pc = Lookup.getDefault().lookup(ProjectControllerUI.class);
            pc.openFile();
            closeDialog();
        }
    });
}
Also used : ActionEvent(java.awt.event.ActionEvent) JXHyperlink(org.jdesktop.swingx.JXHyperlink) NotifyDescriptor(org.openide.NotifyDescriptor) ActionListener(java.awt.event.ActionListener) ImportControllerUI(org.gephi.desktop.importer.api.ImportControllerUI) FileObject(org.openide.filesystems.FileObject) AbstractAction(javax.swing.AbstractAction) File(java.io.File) ProjectControllerUI(org.gephi.desktop.project.api.ProjectControllerUI)

Aggregations

ProjectControllerUI (org.gephi.desktop.project.api.ProjectControllerUI)9 FileObject (org.openide.filesystems.FileObject)5 File (java.io.File)4 ImportControllerUI (org.gephi.desktop.importer.api.ImportControllerUI)4 ProjectController (org.gephi.project.api.ProjectController)3 NotifyDescriptor (org.openide.NotifyDescriptor)3 ActionEvent (java.awt.event.ActionEvent)2 ArrayList (java.util.ArrayList)2 AbstractAction (javax.swing.AbstractAction)2 Workspace (org.gephi.project.api.Workspace)2 UnsupportedFlavorException (java.awt.datatransfer.UnsupportedFlavorException)1 ActionListener (java.awt.event.ActionListener)1 IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 List (java.util.List)1 Random (java.util.Random)1 JFrame (javax.swing.JFrame)1 JMenu (javax.swing.JMenu)1 JMenuItem (javax.swing.JMenuItem)1 JPanel (javax.swing.JPanel)1