/******************************************************************************* | |
* 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.errors.VPMCoreException; | |
public class AddModelElementCommand extends ViatraEditorCommand { | |
private IEntity parent; | |
private String parent_name; | |
private IModelElement source; | |
private String source_name; | |
public void setParent(IEntity aPar) { | |
parent = aPar; | |
parent_name = parent.getFullyQualifiedName(); | |
source = null; | |
source_name = null; | |
} | |
public void setSource(IModelElement aS) { | |
source = aS; | |
source_name = source.getFullyQualifiedName(); | |
parent = null; | |
parent_name = null; | |
} | |
public void execute() throws VPMCoreException { | |
parent = (IEntity) Lookup(parent, parent_name); | |
source = Lookup(source, source_name); | |
if (parent != null) { | |
// we are in add entity mode | |
iTransactionID = parent.getModelSpace().getTransactionManager().beginUndoableTransaction(); | |
//parent.getModelSpace().getUndoManager().nextUndoBlock( | |
// "vte_newent"); | |
parent.getModelSpace().getModelManager().newEntity(parent); | |
parent.getModelSpace().getTransactionManager().commitTransaction(); | |
} else if (source != null) { | |
iTransactionID = source.getModelSpace().getTransactionManager().beginUndoableTransaction(); | |
// we are in add relation mode | |
//source.getModelSpace().getUndoManager().nextUndoBlock( | |
// "vte_newrel"); | |
source.getModelSpace().getModelManager().newRelation(source,source); | |
source.getModelSpace().getTransactionManager().commitTransaction(); | |
} | |
} | |
public void undo() { | |
parent = (IEntity) Lookup(parent, parent_name); | |
source = Lookup(source, source_name); | |
if (parent != null) { | |
//parent.getModelSpace().getUndoManager().undo("vte_newent"); | |
parent.getModelSpace().getTransactionManager().undoTransaction(iTransactionID); | |
} else if (source != null) { | |
source.getModelSpace().getTransactionManager().undoTransaction(iTransactionID); | |
//source.getModelSpace().getUndoManager().undo("vte_newrel"); | |
} | |
} | |
} |