Search in sources :

Example 26 with UndoSupport

use of org.cytoscape.work.undo.UndoSupport in project cytoscape-impl by cytoscape.

the class CutTask method run.

@Override
public void run(TaskMonitor tm) throws Exception {
    final VisualMappingManager vmMgr = serviceRegistrar.getService(VisualMappingManager.class);
    final VisualLexicon lexicon = vmMgr.getAllVisualLexicon().iterator().next();
    final Collection<VisualProperty<?>> edgeProps = lexicon.getAllDescendants(BasicVisualLexicon.EDGE);
    tm.setTitle("Cut Task");
    // so they can be restored later on undo
    for (CyNode node : selNodes) {
        List<CyEdge> adjacentEdgeList = netView.getModel().getAdjacentEdgeList(node, CyEdge.Type.ANY);
        for (CyEdge edge : adjacentEdgeList) {
            if (!selEdges.contains(edge)) {
                deletedEdges.put(edge, new HashMap<VisualProperty<?>, Object>());
                // Save the bypass values for this edge
                View<CyEdge> edgeView = netView.getEdgeView(edge);
                if (edgeView != null)
                    ClipboardImpl.saveLockedValues(edgeView, edgeProps, deletedEdges);
            }
        }
    }
    clipMgr.cut(netView, selNodes, selEdges);
    tm.setStatusMessage("Cut " + selNodes.size() + " nodes and " + selEdges.size() + " edges and copied them to the clipboard");
    final UndoSupport undoSupport = serviceRegistrar.getService(UndoSupport.class);
    undoSupport.postEdit(new CutEdit());
}
Also used : BasicVisualLexicon(org.cytoscape.view.presentation.property.BasicVisualLexicon) VisualLexicon(org.cytoscape.view.model.VisualLexicon) VisualProperty(org.cytoscape.view.model.VisualProperty) CyNode(org.cytoscape.model.CyNode) VisualMappingManager(org.cytoscape.view.vizmap.VisualMappingManager) CyEdge(org.cytoscape.model.CyEdge) UndoSupport(org.cytoscape.work.undo.UndoSupport)

Example 27 with UndoSupport

use of org.cytoscape.work.undo.UndoSupport in project cytoscape-impl by cytoscape.

the class SetLockedValuesTask method run.

// ==[ PUBLIC METHODS ]=============================================================================================
@Override
public void run(final TaskMonitor taskMonitor) throws Exception {
    if (values != null && views != null && netView != null) {
        final boolean removed = setLockedValues(true);
        if (removed) {
            final UndoSupport undo = servicesUtil.get(UndoSupport.class);
            undo.postEdit(new SetLockedValuesEdit());
        }
    }
}
Also used : UndoSupport(org.cytoscape.work.undo.UndoSupport)

Example 28 with UndoSupport

use of org.cytoscape.work.undo.UndoSupport in project cytoscape-impl by cytoscape.

the class CopyVisualStyleTask method run.

@Override
public void run(final TaskMonitor monitor) throws Exception {
    if (vsName != null && originalStyle != null) {
        copyVisualStyle();
        final UndoSupport undo = servicesUtil.get(UndoSupport.class);
        undo.postEdit(new CopyVisualStyleEdit());
    }
}
Also used : UndoSupport(org.cytoscape.work.undo.UndoSupport)

Example 29 with UndoSupport

use of org.cytoscape.work.undo.UndoSupport in project cytoscape-impl by cytoscape.

the class CreateNewVisualStyleTask method run.

@Override
public void run(final TaskMonitor tm) {
    if (vsName != null) {
        createVisualStyle();
        final UndoSupport undo = servicesUtil.get(UndoSupport.class);
        undo.postEdit(new CreateNewVisualStyleEdit());
    }
}
Also used : UndoSupport(org.cytoscape.work.undo.UndoSupport)

Example 30 with UndoSupport

use of org.cytoscape.work.undo.UndoSupport in project cytoscape-impl by cytoscape.

the class VizMapperMediator method onSelectedVisualStyleChanged.

private void onSelectedVisualStyleChanged(final PropertyChangeEvent e) {
    final VisualStyle newStyle = (VisualStyle) e.getNewValue();
    final VisualStyle oldStyle = vmProxy.getCurrentVisualStyle();
    if (!ignoreVisualStyleSelectedEvents && newStyle != null && !newStyle.equals(oldStyle)) {
        // Update proxy
        vmProxy.setCurrentVisualStyle(newStyle);
        // Undo support
        final UndoSupport undo = servicesUtil.get(UndoSupport.class);
        undo.postEdit(new AbstractCyEdit("Set Current Style") {

            @Override
            public void undo() {
                vmProxy.setCurrentVisualStyle(oldStyle);
            }

            @Override
            public void redo() {
                vmProxy.setCurrentVisualStyle(newStyle);
            }
        });
    }
}
Also used : VisualStyle(org.cytoscape.view.vizmap.VisualStyle) UndoSupport(org.cytoscape.work.undo.UndoSupport) AbstractCyEdit(org.cytoscape.work.undo.AbstractCyEdit)

Aggregations

UndoSupport (org.cytoscape.work.undo.UndoSupport)50 Test (org.junit.Test)21 Task (org.cytoscape.work.Task)19 CyEventHelper (org.cytoscape.event.CyEventHelper)15 VisualMappingManager (org.cytoscape.view.vizmap.VisualMappingManager)15 CyServiceRegistrar (org.cytoscape.service.util.CyServiceRegistrar)12 HashSet (java.util.HashSet)10 TaskIterator (org.cytoscape.work.TaskIterator)10 CyNode (org.cytoscape.model.CyNode)9 ArrayList (java.util.ArrayList)8 CyEdge (org.cytoscape.model.CyEdge)7 CyNetwork (org.cytoscape.model.CyNetwork)7 CyNetworkView (org.cytoscape.view.model.CyNetworkView)7 CyRow (org.cytoscape.model.CyRow)6 CyNetworkViewManager (org.cytoscape.view.model.CyNetworkViewManager)6 Properties (java.util.Properties)5 CyNetworkManager (org.cytoscape.model.CyNetworkManager)5 CyApplicationManager (org.cytoscape.application.CyApplicationManager)4 CyGroupManager (org.cytoscape.group.CyGroupManager)4 CyNetworkFactory (org.cytoscape.model.CyNetworkFactory)4