/*******************************************************************************
* Copyright (c) 2012 University of Mannheim: Chair for Software Engineering
* 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:
* Ralph Gerbig - initial API and implementation and initial documentation
*******************************************************************************/
package de.uni_mannheim.informatik.swt.mlm.emendation.service.commands;
import java.util.HashSet;
import java.util.Set;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.emf.common.command.Command;
import org.eclipse.emf.common.command.CompoundCommand;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.jface.window.Window;
import org.eclipse.ui.PlatformUI;
import de.uni_mannheim.informatik.swt.mlm.emendation.service.ImpactAnalyzer;
import de.uni_mannheim.informatik.swt.mlm.emendation.service.dialogs.EmendMoveAttributeDialog;
import de.uni_mannheim.informatik.swt.models.plm.PLM.Clabject;
import de.uni_mannheim.informatik.swt.models.plm.PLM.Feature;
public class EmendMoveAttributeCommand{
private Set<EObject> emendedObjects = new HashSet<EObject>();
public Set<EObject> getEmendedObjects(){
return emendedObjects;
}
public CompoundCommand run(Clabject source, Clabject target, Feature movedFeature){
try {
EmendMoveAttributeDialog dialog = showMoveModelElementDialog();
if (dialog == null)
return null;
return runEmendation(source, target, movedFeature);
} catch (ExecutionException e) {
e.printStackTrace();
}
return null;
}
protected EmendMoveAttributeDialog showMoveModelElementDialog() throws ExecutionException{
EmendMoveAttributeDialog dialog = new EmendMoveAttributeDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell());
if (dialog.open() == Window.OK)
return dialog;
else
return null;
}
/**
*
* @param changeOrigin The element on which the original change operation has been performed
* @param traitToChange The EAttribut in the meta-model to change
* @param newValue can bee needed because if emendation request comes from UI it can be already changed in
* the feature
* @param newValue the new value to set
* @param changeOntologicalTypes change ontological types?
* @param changeSubtypes change subtypes?
* @param changeSuperTypes change supertypes?
* @return
*/
protected CompoundCommand runEmendation(Clabject source, Clabject target, Feature movedFeature){
// Set<Clabject> emendedElements = new ImpactAnalyzer().getEffectedModelElementsForAddFeatureOperation(changeOrigin); //(Set<Clabject>)new ImpactAnalyzer().calculateImpactOfChange((Clabject)changeOrigin, traitToChange, changeOntologicalTypes, changeSubtypes, changeSuperTypes);
CompoundCommand emendationCommand = new CompoundCommand("Emendation move feature " + movedFeature.getName() + " from " + source.getName() + " to " + target.getName());
EmendRemoveAttributeCommand removeAttributeCommand = new EmendRemoveAttributeCommand();
Command cmd = removeAttributeCommand.run(source, movedFeature, new ImpactAnalyzer().getEffectedModelElementsForAddFeatureOperation(target, movedFeature, true));
if (cmd != null)
emendationCommand.append(cmd);
EmendAddAttributeCommand addAttributeCommand = new EmendAddAttributeCommand();
emendationCommand.append(addAttributeCommand.run(target, movedFeature));
emendedObjects.addAll(removeAttributeCommand.getEmendedObjects());
emendedObjects.addAll(addAttributeCommand.getEmendedObjects());
return emendationCommand;
}
}