/******************************************************************************* | |
* 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.EMultiplicityKind; | |
import org.eclipse.viatra2.core.IEntity; | |
import org.eclipse.viatra2.core.IModelElement; | |
import org.eclipse.viatra2.core.IRelation; | |
import org.eclipse.viatra2.errors.VPMCoreException; | |
import org.eclipse.viatra2.treeeditor.properties.VPMProperties; | |
/** | |
* Command class for changing VALUE,VIEWINFO,ISAGGREGATION,ISFINALTYPE,MULTIPLICITY properties. | |
* @author Istvan Rath | |
* | |
*/ | |
public class ChangePropertyCommand extends ViatraEditorCommand { | |
IModelElement target; | |
String target_name; | |
VPMProperties kind; | |
String newValue; | |
Integer intValue; | |
public void setIntValue(Integer intValue) { | |
this.intValue = intValue; | |
} | |
public void setNewValue(String oldValue) { | |
this.newValue = oldValue; | |
} | |
public void setTarget(IModelElement target) { | |
this.target = target; | |
target_name = target.getFullyQualifiedName(); | |
} | |
public void setKind(VPMProperties kind) { | |
this.kind = kind; | |
} | |
@Override | |
public void execute() throws VPMCoreException | |
{ | |
target = Lookup(target, target_name); | |
switch (kind) | |
{ | |
case VALUE: | |
iTransactionID = target.getModelSpace().getTransactionManager().beginUndoableTransaction(); | |
target.getModelSpace().getModelManager().setValue((IEntity)target, newValue); | |
target_name = target.getFullyQualifiedName(); | |
target.getModelSpace().getTransactionManager().commitTransaction(); | |
break; | |
case VIEWINFO: | |
iTransactionID = target.getModelSpace().getTransactionManager().beginUndoableTransaction(); | |
target.getModelSpace().getModelManager().setViewInfo(target, newValue); | |
target_name = target.getFullyQualifiedName(); | |
target.getModelSpace().getTransactionManager().commitTransaction(); | |
break; | |
case ISFINALTYPE: | |
iTransactionID = target.getModelSpace().getTransactionManager().beginUndoableTransaction(); | |
target.getModelSpace().getModelManager().setIsFinalType(target, intValue.equals(1)); | |
target_name = target.getFullyQualifiedName(); | |
target.getModelSpace().getTransactionManager().commitTransaction(); | |
break; | |
case ISAGGREGATION: | |
iTransactionID = target.getModelSpace().getTransactionManager().beginUndoableTransaction(); | |
target.getModelSpace().getModelManager().setRelationIsAggregation((IRelation)target, intValue.equals(1)); | |
target_name = target.getFullyQualifiedName(); | |
target.getModelSpace().getTransactionManager().commitTransaction(); | |
break; | |
case MULTIPLICITY: | |
iTransactionID = target.getModelSpace().getTransactionManager().beginUndoableTransaction(); | |
target.getModelSpace().getModelManager().setRelationMultiplicity( | |
(IRelation)target, | |
EMultiplicityKind.values()[intValue]); | |
target_name = target.getFullyQualifiedName(); | |
target.getModelSpace().getTransactionManager().commitTransaction(); | |
break; | |
} | |
} | |
@Override | |
public void undo() throws VPMCoreException { | |
target = Lookup(target, target_name); | |
if (target!=null) | |
{ | |
target.getModelSpace().getTransactionManager().undoTransaction(iTransactionID); | |
target_name = target.getFullyQualifiedName(); | |
} | |
} | |
} |