blob: d624f23ffa62c4e37c38ce8ef6b1cce357c49b92 [file] [log] [blame]
/**
* Copyright (c)2020 CEA LIST, Committer Name, and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* CEA LIST - Initial API and implementation
* Gabriel Pedroza (CEA LIST) gabriel.pedroza@cea.fr
*
*/
package org.eclipse.papyrus.pdp4eng.designer.controller.internal;
import java.util.Iterator;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.transaction.RecordingCommand;
import org.eclipse.emf.transaction.TransactionalEditingDomain;
import org.eclipse.papyrus.pdp4eng.designer.utils.ModelProfileNames;
import org.eclipse.uml2.uml.Action;
import org.eclipse.uml2.uml.Activity;
import org.eclipse.uml2.uml.CallBehaviorAction;
import org.eclipse.uml2.uml.Element;
import org.eclipse.uml2.uml.OpaqueAction;
import org.eclipse.uml2.uml.Profile;
import org.eclipse.uml2.uml.ProfileApplication;
/**
* Creates an abstraction from Data.
*
*/
public class AllCallProcessToProcessCommand extends RecordingCommand {
protected Activity activityDFD;
protected TransactionalEditingDomain domain;
public AllCallProcessToProcessCommand(TransactionalEditingDomain domain, Activity activityDFD) {
super(domain, "Transform each call process (OpaqueAction or CallBehaviorAction) within the Activity into a process");
this.activityDFD = activityDFD;
this.domain=domain;
}
@Override
protected void doExecute() {
EList<Profile> profileList = this.activityDFD.getModel().getAppliedProfiles();
if (verifyProfilesApplied(profileList)) {
Profile PDPbDprofile = getProfile(ModelProfileNames.PDPbDProfileName);
EList<Element> elementList = this.activityDFD.getNearestPackage().allOwnedElements();
if (elementList!=null && PDPbDprofile!=null) {
for (Iterator<Element> elementListIt = elementList.iterator(); elementListIt.hasNext();) {
Element element = elementListIt.next();
EClass elementClass = element.eClass();
System.out.printf("===>"+elementClass.getName()+"\n");
if (elementClass!=null ) {
String className = elementClass.getName();
switch (className){
case "CallBehaviorAction":
if (element instanceof CallBehaviorAction) {
if (element != null) {
ActionCallProcessToProcessCommand command = new ActionCallProcessToProcessCommand(domain, ((Action) element));
if (command.canExecute()) {
command.execute();
}
}
}
break;
case "OpaqueAction":
if (element instanceof OpaqueAction) {
if (element != null) {
ActionCallProcessToProcessCommand command = new ActionCallProcessToProcessCommand(domain, ((Action) element));
if (command.canExecute()) {
command.execute();
}
}
}
break;
}
}
}
}
}
}
/**
* Verify whether the needed profiles have been already loaded in the model
* @param profileList
* @return
*/
public boolean verifyProfilesApplied(EList<Profile> profileList) {
boolean found = false;
int noProfiles = 0;
for (Iterator<Profile> profileListIt = profileList.iterator(); profileListIt.hasNext() && noProfiles!=2;) {
Profile profile = profileListIt.next();
if (profile!=null) {
String profileName = profile.getName();
switch (profileName) {
case "pdp4engDesign":
noProfiles++;
break;
case "pdp4engCommonGDPR":
noProfiles++;
break;
}
}
}
if (noProfiles==2) {
found=true;
}
return found;
}
/**
* Return the profile with the given name or null elsewhere
* @param profileName
* @return
*/
public Profile getProfile(String profileName) {
Profile profile = null;
for (ProfileApplication profileApplication : this.activityDFD.getModel().getProfileApplications()) {
profile = profileApplication.getAppliedProfile();
if (profile.getName().equals(profileName)){
return profile;
}
}
return profile;
}
}