/******************************************************************************* | |
* 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.IEntity; | |
import org.eclipse.viatra2.core.IModelElement; | |
import org.eclipse.viatra2.core.IRelation; | |
import org.eclipse.viatra2.errors.VPMCoreException; | |
public class MoveModelElementCommand extends ViatraEditorCommand { | |
private IEntity newparent, oldparent, child; | |
private String newparent_name, oldparent_name, child_name, child_oldname; | |
private IModelElement newsource, oldsource; | |
private IRelation relation; | |
private String newsource_name, oldsource_name, relation_name, | |
relation_oldname; | |
public void setEntity(IEntity aChld, IEntity aNewParent) { | |
child = aChld; | |
oldparent = child.getParent(); | |
newparent = aNewParent; | |
child_name = child.getFullyQualifiedName(); | |
oldparent_name = oldparent.getFullyQualifiedName(); | |
newparent_name = newparent.getFullyQualifiedName(); | |
newsource = oldsource = relation = null; | |
newsource_name = oldsource_name = relation_name = relation_oldname = null; | |
} | |
public void setRelation(IRelation aRel, IModelElement aNewSource) { | |
relation = aRel; | |
oldsource = relation.getFrom(); | |
newsource = aNewSource; | |
relation_name = relation.getFullyQualifiedName(); | |
oldsource_name = oldsource.getFullyQualifiedName(); | |
newsource_name = newsource.getFullyQualifiedName(); | |
newparent = oldparent = child = null; | |
newparent_name = oldparent_name = child_name = child_oldname = null; | |
} | |
public void execute() throws VPMCoreException { | |
newparent = (IEntity) Lookup(newparent, newparent_name); | |
oldparent = (IEntity) Lookup(oldparent, oldparent_name); | |
child = (IEntity) Lookup(child, child_name); | |
newsource = Lookup(newsource, newsource_name); | |
oldsource = Lookup(oldsource, oldsource_name); | |
relation = (IRelation) Lookup(relation, relation_name); | |
if (child != null && oldparent != null && newparent != null) { | |
// we're repareting an entity | |
iTransactionID = child.getModelSpace().getTransactionManager().beginUndoableTransaction(); | |
// child.getModelSpace().getUndoManager().nextUndoBlock("vte_moveent"); | |
child.getModelSpace().getModelManager().moveEntityTo(child, newparent); | |
child_oldname = child_name; | |
child_name = child.getFullyQualifiedName(); | |
child.getModelSpace().getTransactionManager().commitTransaction(); | |
} else if (relation != null && oldsource != null && newsource != null) { | |
// we're resourcing a relation | |
iTransactionID = relation.getModelSpace().getTransactionManager().beginUndoableTransaction(); | |
//relation.getModelSpace().getUndoManager().nextUndoBlock("vte_moverel"); | |
relation.getModelSpace().getModelManager().setRelationFrom(relation, newsource); | |
relation_oldname = relation_name; | |
relation_name = relation.getFullyQualifiedName(); | |
relation.getModelSpace().getTransactionManager().commitTransaction(); | |
} | |
} | |
public void undo() { | |
newparent = (IEntity) Lookup(newparent, newparent_name); | |
oldparent = (IEntity) Lookup(oldparent, oldparent_name); | |
child = (IEntity) Lookup(child, child_name); | |
newsource = Lookup(newsource, newsource_name); | |
oldsource = Lookup(oldsource, oldsource_name); | |
relation = (IRelation) Lookup(relation, relation_name); | |
if (child != null && newparent != null && oldparent != null) { | |
child.getModelSpace().getTransactionManager().undoTransaction(iTransactionID); | |
//child.getModelSpace().getUndoManager().undo("vte_moveent"); | |
child_name = child_oldname; | |
/* String t = newparent_name; | |
newparent_name = oldparent_name; | |
oldparent_name = t; | |
*/ | |
} else if (relation != null && oldsource != null && newsource != null) { | |
relation.getModelSpace().getTransactionManager().undoTransaction(iTransactionID); | |
//relation.getModelSpace().getUndoManager().undo("vte_moverel"); | |
relation_name = relation_oldname; | |
/* String t = newsource_name; | |
newsource_name = oldsource_name; | |
oldsource_name = t; | |
*/ | |
} | |
} | |
} |