Search in sources :

Example 1 with ProgressTicketProvider

use of org.gephi.utils.progress.ProgressTicketProvider in project gephi by gephi.

the class FilterThread method run.

@Override
public void run() {
    while (running) {
        AbstractQueryImpl q;
        while ((q = rootQuery.getAndSet(null)) == null && running) {
            try {
                synchronized (this.lock) {
                    lock.wait();
                }
            } catch (InterruptedException ex) {
                Exceptions.printStackTrace(ex);
            }
        }
        if (!running) {
            return;
        }
        Query modifiedQuery = null;
        for (Iterator<PropertyModifier> itr = modifiersMap.values().iterator(); itr.hasNext(); ) {
            PropertyModifier pm = itr.next();
            itr.remove();
            pm.callback.setValue(pm.value);
            modifiedQuery = pm.query;
        }
        if (modifiedQuery != null) {
            model.updateParameters(modifiedQuery);
        }
        // Progress
        ProgressTicket progressTicket = null;
        ProgressTicketProvider progressTicketProvider = Lookup.getDefault().lookup(ProgressTicketProvider.class);
        if (progressTicketProvider != null) {
            String msg = NbBundle.getMessage(FilterThread.class, "FilterThread.progress.taskName", q.getName());
            progressTicket = progressTicketProvider.createTicket(msg, null);
            Progress.start(progressTicket);
        }
        if (filtering) {
            filter(q);
        } else {
            select(q);
        }
        Progress.finish(progressTicket);
    /*try {
            //System.out.println("filter query " + q.getName());
            Thread.sleep(5000);
            } catch (InterruptedException ex) {
            Exceptions.printStackTrace(ex);
            }*/
    }
    // clear map
    Query q = null;
    for (PropertyModifier pm : modifiersMap.values()) {
        pm.callback.setValue(pm.value);
        q = pm.query;
    }
    modifiersMap.clear();
    if (q != null) {
        model.updateParameters(q);
    }
}
Also used : ProgressTicketProvider(org.gephi.utils.progress.ProgressTicketProvider) Query(org.gephi.filters.api.Query) ProgressTicket(org.gephi.utils.progress.ProgressTicket)

Example 2 with ProgressTicketProvider

use of org.gephi.utils.progress.ProgressTicketProvider in project gephi by gephi.

the class FilterControllerImpl method exportToNewWorkspace.

@Override
public void exportToNewWorkspace(Query query) {
    Graph result;
    if (model.getCurrentQuery() == query) {
        GraphView view = model.getCurrentResult();
        if (view == null) {
            return;
        }
        result = model.getGraphModel().getGraph(view);
    } else {
        FilterProcessor processor = new FilterProcessor();
        GraphModel graphModel = model.getGraphModel();
        result = (Graph) processor.process((AbstractQueryImpl) query, graphModel);
    }
    final Graph graphView = result;
    new Thread(new Runnable() {

        @Override
        public void run() {
            ProgressTicketProvider progressProvider = Lookup.getDefault().lookup(ProgressTicketProvider.class);
            ProgressTicket ticket = null;
            if (progressProvider != null) {
                String msg = NbBundle.getMessage(FilterControllerImpl.class, "FilterController.exportToNewWorkspace.task");
                ticket = progressProvider.createTicket(msg, null);
            }
            Progress.start(ticket);
            ProjectController pc = Lookup.getDefault().lookup(ProjectController.class);
            Workspace newWorkspace = pc.newWorkspace(pc.getCurrentProject());
            GraphModel graphModel = Lookup.getDefault().lookup(GraphController.class).getGraphModel(newWorkspace);
            graphModel.bridge().copyNodes(graphView.getNodes().toArray());
            Graph graph = graphModel.getGraph();
            List<Edge> edgesToRemove = new ArrayList<>();
            for (Edge edge : graph.getEdges()) {
                if (!graphView.hasEdge(edge.getId())) {
                    edgesToRemove.add(edge);
                }
            }
            if (!edgesToRemove.isEmpty()) {
                graph.removeAllEdges(edgesToRemove);
            }
            Progress.finish(ticket);
            String workspaceName = newWorkspace.getLookup().lookup(WorkspaceInformation.class).getName();
        // StatusDisplayer.getDefault().setStatusText(NbBundle.getMessage(FilterControllerImpl.class, "FilterController.exportToNewWorkspace.status", workspaceName));
        }
    }, "Export filter to workspace").start();
}
Also used : ArrayList(java.util.ArrayList) GraphView(org.gephi.graph.api.GraphView) ProjectController(org.gephi.project.api.ProjectController) WorkspaceInformation(org.gephi.project.api.WorkspaceInformation) ProgressTicketProvider(org.gephi.utils.progress.ProgressTicketProvider) Graph(org.gephi.graph.api.Graph) GraphModel(org.gephi.graph.api.GraphModel) Edge(org.gephi.graph.api.Edge) ProgressTicket(org.gephi.utils.progress.ProgressTicket) GraphController(org.gephi.graph.api.GraphController) Workspace(org.gephi.project.api.Workspace)

Aggregations

ProgressTicket (org.gephi.utils.progress.ProgressTicket)2 ProgressTicketProvider (org.gephi.utils.progress.ProgressTicketProvider)2 ArrayList (java.util.ArrayList)1 Query (org.gephi.filters.api.Query)1 Edge (org.gephi.graph.api.Edge)1 Graph (org.gephi.graph.api.Graph)1 GraphController (org.gephi.graph.api.GraphController)1 GraphModel (org.gephi.graph.api.GraphModel)1 GraphView (org.gephi.graph.api.GraphView)1 ProjectController (org.gephi.project.api.ProjectController)1 Workspace (org.gephi.project.api.Workspace)1 WorkspaceInformation (org.gephi.project.api.WorkspaceInformation)1