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));
}
}
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();
}
}
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();
}
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);
}
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();
}
});
}
Aggregations