/******************************************************************************* * 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.CompoundCommand; import org.eclipse.emf.edit.command.DeleteCommand; import org.eclipse.emf.transaction.TransactionalEditingDomain; import org.eclipse.emf.transaction.util.TransactionUtil; 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.EmendRemoveAttributeDialog; import de.uni_mannheim.informatik.swt.models.plm.PLM.Clabject; import de.uni_mannheim.informatik.swt.models.plm.PLM.Feature; public class EmendRemoveAttributeCommand{ Set<Feature> emendedElements; public Set<Feature> getEmendedObjects() { return (Set<Feature>)emendedElements; } public CompoundCommand run(Clabject changeOrigin, Feature featureToDelete){ return run(changeOrigin, featureToDelete, new HashSet<Clabject>()); } public CompoundCommand run(Clabject changeOrigin, Feature featureToDelete, Set<Clabject> exclude){ try { EmendRemoveAttributeDialog dialog = showRemoveModelElementDialog(); if (dialog == null) return null; return runEmendation(changeOrigin, featureToDelete, exclude); } catch (ExecutionException e) { e.printStackTrace(); } return null; } protected EmendRemoveAttributeDialog showRemoveModelElementDialog() throws ExecutionException{ EmendRemoveAttributeDialog dialog = new EmendRemoveAttributeDialog(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 changeOrigin, Feature featureToDelete, Set<Clabject> exclude){ emendedElements = new ImpactAnalyzer().getEffectedModelElementsForDeleteFeatureOperation(featureToDelete, changeOrigin);//(Set<Feature>)new ImpactAnalyzer<Feature>().calculateImpactOfChange((Feature)featureToDelete, String.valueOf(featureToDelete.getDurability()), PLMPackage.eINSTANCE.getFeature_Durability(), changeOntologicalTypes, changeSubtypes, changeSuperTypes); //*************************************************************** //Execute change operation //*************************************************************** final CompoundCommand emendationCommand = new CompoundCommand("Emendation - Delete " + changeOrigin.getName()); TransactionalEditingDomain domain = TransactionUtil.getEditingDomain(changeOrigin); for (Feature element : emendedElements) if (!exclude.contains(element.getClabject())) emendationCommand.append(DeleteCommand.create(domain, element)); //This is needed because if we place an empty compound command in a compound command //this makes problems during execution of following commands. e.g. EmmendMoveCommand if (emendationCommand.getCommandList().size() == 0) return null; return emendationCommand; } }