Search in sources :

Example 6 with Workspace

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

the class SQLiteDatabaseExporterUI method action.

@Override
public void action() {
    //Create exporter
    final SQLiteDatabaseExporter exporter = new SQLiteDatabaseExporter();
    //Create the settings panel
    SQLiteDatabaseSettingsPanel settingPanel = new SQLiteDatabaseSettingsPanel();
    settingPanel.setup(exporter);
    final DialogDescriptor dd = new DialogDescriptor(settingPanel, "SQLite Database Export");
    Object result = DialogDisplayer.getDefault().notify(dd);
    if (result == NotifyDescriptor.OK_OPTION) {
        //This line will write the file path from the panel to the exporter's <code>setPath()<code> method.
        settingPanel.unsetup(true);
        //Create a new executor and execute
        LongTaskExecutor executor = new LongTaskExecutor(true, "SQLite Exporter");
        executor.setDefaultErrorHandler(errorHandler);
        executor.execute(exporter, new Runnable() {

            @Override
            public void run() {
                //Get the current workspace and set it to the exporter
                Workspace currentWorkspace = Lookup.getDefault().lookup(ProjectController.class).getCurrentWorkspace();
                exporter.setWorkspace(currentWorkspace);
                //Execute export
                cancelled = !exporter.execute();
                //If not cancelled, write a status line message
                if (!cancelled) {
                    StatusDisplayer.getDefault().setStatusText("Export to SQLite database completed");
                }
            }
        });
    } else {
        settingPanel.unsetup(false);
    }
}
Also used : DialogDescriptor(org.openide.DialogDescriptor) LongTaskExecutor(org.gephi.utils.longtask.api.LongTaskExecutor) Workspace(org.gephi.project.api.Workspace)

Example 7 with Workspace

use of org.gephi.project.api.Workspace in project gephi by gephi.

the class GraphTopComponent method initToolPanels.

private void initToolPanels() {
    final ToolController tc = Lookup.getDefault().lookup(ToolController.class);
    if (tc != null) {
        if (VizController.getInstance().getVizConfig().isToolbar()) {
            JPanel westPanel = new JPanel(new BorderLayout(0, 0));
            if (UIUtils.isAquaLookAndFeel()) {
                westPanel.setBackground(UIManager.getColor("NbExplorerView.background"));
            }
            toolbar = tc.getToolbar();
            if (toolbar != null) {
                westPanel.add(toolbar, BorderLayout.CENTER);
            }
            selectionToolbar = new SelectionToolbar();
            actionsToolbar = new ActionsToolbar();
            westPanel.add(selectionToolbar, BorderLayout.NORTH);
            westPanel.add(actionsToolbar, BorderLayout.SOUTH);
            add(westPanel, BorderLayout.WEST);
        }
        if (VizController.getInstance().getVizConfig().isPropertiesbar()) {
            propertiesBar = tc.getPropertiesBar();
            if (propertiesBar != null) {
                add(propertiesBar, BorderLayout.NORTH);
            }
        }
    }
    //Workspace events
    ProjectController projectController = Lookup.getDefault().lookup(ProjectController.class);
    projectController.addWorkspaceListener(new WorkspaceListener() {

        @Override
        public void initialize(Workspace workspace) {
        }

        @Override
        public void select(Workspace workspace) {
            if (toolbar != null) {
                toolbar.setEnabled(true);
            }
            if (propertiesBar != null) {
                propertiesBar.setEnabled(true);
            }
            if (actionsToolbar != null) {
                actionsToolbar.setEnabled(true);
            }
            if (selectionToolbar != null) {
                selectionToolbar.setEnabled(true);
            }
        }

        @Override
        public void unselect(Workspace workspace) {
        }

        @Override
        public void close(Workspace workspace) {
        }

        @Override
        public void disable() {
            if (toolbar != null) {
                toolbar.setEnabled(false);
            }
            if (tc != null) {
                //Unselect any selected tool
                tc.select(null);
            }
            if (propertiesBar != null) {
                propertiesBar.setEnabled(false);
            }
            if (actionsToolbar != null) {
                actionsToolbar.setEnabled(false);
            }
            if (selectionToolbar != null) {
                selectionToolbar.setEnabled(false);
            }
        }
    });
    boolean hasWorkspace = projectController.getCurrentWorkspace() != null;
    if (toolbar != null) {
        toolbar.setEnabled(hasWorkspace);
    }
    if (propertiesBar != null) {
        propertiesBar.setEnabled(hasWorkspace);
    }
    if (actionsToolbar != null) {
        actionsToolbar.setEnabled(hasWorkspace);
    }
    if (selectionToolbar != null) {
        selectionToolbar.setEnabled(hasWorkspace);
    }
}
Also used : JPanel(javax.swing.JPanel) WorkspaceListener(org.gephi.project.api.WorkspaceListener) BorderLayout(java.awt.BorderLayout) ToolController(org.gephi.tools.api.ToolController) ProjectController(org.gephi.project.api.ProjectController) Workspace(org.gephi.project.api.Workspace)

Example 8 with Workspace

use of org.gephi.project.api.Workspace in project gephi by gephi.

the class DataTableTopComponent method initEvents.

private void initEvents() {
    //Workspace Listener
    pc.addWorkspaceListener(new WorkspaceListener() {

        @Override
        public void initialize(Workspace workspace) {
            //Prepare DataTablesEvent listener
            Lookup.getDefault().lookup(DataTablesController.class).setDataTablesEventListener(DataTableTopComponent.this);
            if (workspace.getLookup().lookup(DataTablesModel.class) == null) {
                workspace.add(new DataTablesModel(workspace));
            }
        }

        @Override
        public void select(Workspace workspace) {
            activateWorkspace(workspace);
            setAutoRefreshEnabled(true);
        }

        @Override
        public void unselect(Workspace workspace) {
            deactivateAll();
            setAutoRefreshEnabled(false);
        }

        @Override
        public void close(Workspace workspace) {
        }

        @Override
        public void disable() {
            clearAll();
            //No more workspaces active, disable the DataTablesEvent listener
            Lookup.getDefault().lookup(DataTablesController.class).setDataTablesEventListener(null);
            setAutoRefreshEnabled(false);
        }
    });
    if (pc.getCurrentWorkspace() != null) {
        activateWorkspace(pc.getCurrentWorkspace());
        setAutoRefreshEnabled(true);
    }
    observersTimer = new java.util.Timer("DataLaboratoryGraphObservers");
    observersTimer.schedule(new TimerTask() {

        @Override
        public void run() {
            if (!autoRefreshEnabled) {
                return;
            }
            if (dataTablesObservers != null) {
                if (dataTablesObservers.hasChanges()) {
                    //Execute refresh
                    graphChanged();
                }
            }
        }
    }, 0, //Check graph and tables for changes every 100 ms
    AUTO_REFRESH_RATE_MILLISECONDS);
    //Filter
    if (dynamicFiltering) {
        filterTextField.getDocument().addDocumentListener(new DocumentListener() {

            @Override
            public void insertUpdate(DocumentEvent e) {
                refreshAppliedFilter();
            }

            @Override
            public void removeUpdate(DocumentEvent e) {
                refreshAppliedFilter();
            }

            @Override
            public void changedUpdate(DocumentEvent e) {
            }
        });
    } else {
        filterTextField.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                refreshAppliedFilter();
            }
        });
    }
    columnComboBox.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            refreshAppliedFilter();
        }
    });
    initKeyEventContextMenuActionMappings();
}
Also used : DocumentListener(javax.swing.event.DocumentListener) WorkspaceListener(org.gephi.project.api.WorkspaceListener) TimerTask(java.util.TimerTask) ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) DocumentEvent(javax.swing.event.DocumentEvent) Workspace(org.gephi.project.api.Workspace)

Example 9 with Workspace

use of org.gephi.project.api.Workspace in project gephi by gephi.

the class ExportControllerImpl method exportStream.

@Override
public void exportStream(OutputStream stream, ByteExporter byteExporter) {
    if (byteExporter.getWorkspace() == null) {
        ProjectController projectController = Lookup.getDefault().lookup(ProjectController.class);
        Workspace workspace = projectController.getCurrentWorkspace();
        byteExporter.setWorkspace(workspace);
    }
    byteExporter.setOutputStream(stream);
    try {
        byteExporter.execute();
    } catch (Exception ex) {
        try {
            stream.flush();
            stream.close();
        } catch (IOException exe) {
        }
        if (ex instanceof RuntimeException) {
            throw (RuntimeException) ex;
        }
        throw new RuntimeException(ex);
    }
    try {
        stream.flush();
        stream.close();
    } catch (IOException ex) {
    }
}
Also used : IOException(java.io.IOException) ProjectController(org.gephi.project.api.ProjectController) IOException(java.io.IOException) Workspace(org.gephi.project.api.Workspace)

Example 10 with Workspace

use of org.gephi.project.api.Workspace in project gephi by gephi.

the class ExportControllerImpl method exportWriter.

@Override
public void exportWriter(Writer writer, CharacterExporter characterExporter) {
    if (characterExporter.getWorkspace() == null) {
        ProjectController projectController = Lookup.getDefault().lookup(ProjectController.class);
        Workspace workspace = projectController.getCurrentWorkspace();
        characterExporter.setWorkspace(workspace);
    }
    characterExporter.setWriter(writer);
    try {
        characterExporter.execute();
    } catch (Exception ex) {
        try {
            writer.flush();
            writer.close();
        } catch (IOException exe) {
        }
        if (ex instanceof RuntimeException) {
            throw (RuntimeException) ex;
        }
        throw new RuntimeException(ex);
    }
    try {
        writer.flush();
        writer.close();
    } catch (IOException ex) {
    }
}
Also used : IOException(java.io.IOException) ProjectController(org.gephi.project.api.ProjectController) IOException(java.io.IOException) Workspace(org.gephi.project.api.Workspace)

Aggregations

Workspace (org.gephi.project.api.Workspace)21 ProjectController (org.gephi.project.api.ProjectController)12 IOException (java.io.IOException)4 GraphModel (org.gephi.graph.api.GraphModel)3 WorkspaceListener (org.gephi.project.api.WorkspaceListener)3 WorkspaceProvider (org.gephi.project.api.WorkspaceProvider)3 BufferedOutputStream (java.io.BufferedOutputStream)2 FileOutputStream (java.io.FileOutputStream)2 ArrayList (java.util.ArrayList)2 JPanel (javax.swing.JPanel)2 ProjectControllerUI (org.gephi.desktop.project.api.ProjectControllerUI)2 GraphController (org.gephi.graph.api.GraphController)2 WorkspaceInformation (org.gephi.project.api.WorkspaceInformation)2 WorkspaceProviderImpl (org.gephi.project.impl.WorkspaceProviderImpl)2 WorkspaceBytesPersistenceProvider (org.gephi.project.spi.WorkspaceBytesPersistenceProvider)2 WorkspacePersistenceProvider (org.gephi.project.spi.WorkspacePersistenceProvider)2 WorkspaceXMLPersistenceProvider (org.gephi.project.spi.WorkspaceXMLPersistenceProvider)2 DialogDescriptor (org.openide.DialogDescriptor)2 BorderLayout (java.awt.BorderLayout)1 ActionEvent (java.awt.event.ActionEvent)1