| /******************************************************************************* |
| * Copyright (c) 2013 IBM Corporation and others. |
| * All rights reserved. This program and the accompanying materials |
| * are made available under the terms of the Eclipse Public License v1.0 |
| * which accompanies this distribution, and is available at |
| * http://www.eclipse.org/legal/epl-v10.html |
| * |
| * Contributors: |
| * IBM Corporation - initial API and implementation |
| *******************************************************************************/ |
| package org.eclipse.stem.model.ui.editor.commands; |
| |
| import org.eclipse.gef.commands.Command; |
| import org.eclipse.stem.model.ui.editor.vismodel.ModelElement; |
| import org.eclipse.stem.model.ui.editor.vismodel.TransitionElement; |
| |
| /** |
| * Delete Transition from list of transitions for this model |
| * - Remove TransitionElement from ModelElement list |
| * - Remove Transition from Model transitions |
| * |
| */ |
| public class TransitionDeleteCommand extends Command { |
| |
| private final TransitionElement transition; |
| |
| public TransitionDeleteCommand(TransitionElement transition) { |
| if (transition == null) { |
| throw new IllegalArgumentException(); |
| } |
| setLabel("Delete Transition"); |
| this.transition = transition; |
| } |
| |
| public void execute() { |
| redo(); |
| } |
| |
| public void redo() { |
| ModelElement me = transition.getSource().getModelElement(); |
| me.getTransitionElements().remove(transition); |
| me.getModel().getTransitions().remove(transition.getTransition()); |
| |
| transition.getSource().eNotify(null); |
| transition.getTarget().eNotify(null); |
| } |
| |
| public void undo() { |
| ModelElement me = transition.getSource().getModelElement(); |
| me.getModel().getTransitions().add(transition.getTransition()); |
| me.getTransitionElements().add(transition); |
| |
| transition.getSource().eNotify(null); |
| transition.getTarget().eNotify(null); |
| } |
| } |