/******************************************************************************* | |
* Copyright (c) 2004-2008 Istvan Rath and Daniel Varro | |
* 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: | |
* Istvan Rath - initial API and implementation | |
*******************************************************************************/ | |
package org.eclipse.viatra2.treeeditor.commands; | |
import org.eclipse.viatra2.core.IModelElement; | |
import org.eclipse.viatra2.core.IRelation; | |
import org.eclipse.viatra2.errors.VPMCoreException; | |
public class RetargetRelationCommand extends ViatraEditorCommand { | |
private IModelElement newtarget, oldtarget; | |
private IRelation relation; | |
private String newtarget_name, oldtarget_name, relation_name, | |
relation_oldname; | |
public void setRelation(IRelation aRel, IModelElement aNewTarget) { | |
relation = aRel; | |
oldtarget = relation.getTo(); | |
newtarget = aNewTarget; | |
relation_name = relation.getFullyQualifiedName(); | |
if (oldtarget!=null) { | |
oldtarget_name = oldtarget.getFullyQualifiedName(); | |
} | |
else { | |
oldtarget_name = ".illegal."; | |
} | |
if (newtarget!=null) { | |
newtarget_name = newtarget.getFullyQualifiedName(); | |
} | |
else { | |
newtarget_name = ".illegal."; | |
} | |
} | |
public void execute() throws VPMCoreException { | |
newtarget = Lookup(newtarget, newtarget_name); | |
oldtarget = Lookup(oldtarget, oldtarget_name); | |
relation = (IRelation) Lookup(relation, relation_name); | |
if (relation != null && oldtarget != null && newtarget != null) { | |
// we're retargeting a relation | |
iTransactionID = relation.getModelSpace().getTransactionManager().beginUndoableTransaction(); | |
//relation.getModelSpace().getUndoManager().nextUndoBlock("vte_retarget"); | |
relation.getModelSpace().getModelManager().setRelationTo(relation, newtarget); | |
relation_oldname = relation_name; | |
relation_name = relation.getFullyQualifiedName(); | |
relation.getModelSpace().getTransactionManager().commitTransaction(); | |
} | |
} | |
public void undo() { | |
newtarget = Lookup(newtarget, newtarget_name); | |
oldtarget = Lookup(oldtarget, oldtarget_name); | |
relation = (IRelation) Lookup(relation, relation_name); | |
if (relation != null && oldtarget != null && newtarget != null) { | |
relation.getModelSpace().getTransactionManager().undoTransaction(iTransactionID); | |
//relation.getModelSpace().getUndoManager().undo("vte_retarget"); | |
relation_name = relation_oldname; | |
} | |
} | |
} |