Package org.jbpm.ui.common.command

Source Code of org.jbpm.ui.common.command.NodeDeleteCommand

package org.jbpm.ui.common.command;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.eclipse.gef.commands.Command;
import org.jbpm.ui.common.model.Node;
import org.jbpm.ui.common.model.ProcessDefinition;
import org.jbpm.ui.common.model.Transition;

public class NodeDeleteCommand extends Command {

    private Node node;

    private ProcessDefinition definition;

    private Map<Transition, Node> transitionSources;

    public void setNode(Node node) {
        this.node = node;
    }

    private void detachTransitions(List<Transition> transitions) {
      for (Transition transition : transitions) {
            detachTransition(transition);
    }
    }

    private void reattachTransitions() {
        if (transitionSources != null) {
            for (Transition transition : transitionSources.keySet()) {
                reattachTransition(transition);
            }
        }
    }

    private void detachTransition(Transition transition) {
        transitionSources.put(transition, transition.getSource());
        transition.getSource().removeLeavingTransition(transition);
    }

    private void reattachTransition(Transition transition) {
        Node source = transitionSources.get(transition);
        source.addLeavingTransition(transition);
    }

    @Override
    public void execute() {
        definition = node.getProcessDefinition();
        transitionSources = new HashMap<Transition, Node>();
        detachTransitions(node.getLeavingTransitions());
        detachTransitions(node.getArrivingTransitions());
        definition.removeChild(node);
    }

    @Override
    public void undo() {
        definition.addChild(node);
        reattachTransitions();
    }

}
TOP

Related Classes of org.jbpm.ui.common.command.NodeDeleteCommand

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.