final TransactionalEditingDomain domain = tempDomain;
//open a command do allow undo of all command in one undo
RecordingCommand CompleteCMD = new RecordingCommand(domain) {
protected void doExecute() {
//get top package
org.eclipse.uml2.uml.Package topPackage = UmlElement.getNearestPackage();
while (topPackage.getOwner() instanceof Package){
topPackage = (Package)topPackage.getOwner();
//recursively take nearest package until reaching the top
}
final org.eclipse.uml2.uml.Package finalTopPackage = topPackage;
//test the presence of the "ProxyRequirement" Package
Package proxyPackage = (Package)topPackage.getPackagedElement(PROXY_PACKAGE_NAME);
//test if already present, if not need creation
if (proxyPackage == null){
//means that the package have to be created
RecordingCommand PackCMD = new RecordingCommand(domain) {
@Override
protected void doExecute() {
org.eclipse.uml2.uml.Package tempPackage = UMLFactory.eINSTANCE.createPackage();
tempPackage.setName(PROXY_PACKAGE_NAME);
finalTopPackage.getPackagedElements().add(tempPackage);
}
};
domain.getCommandStack().execute(PackCMD);
}
final Package finalProxyPackage = (Package)topPackage.getPackagedElement(PROXY_PACKAGE_NAME);
RecordingCommand ReqCMD = new RequirementCreateCommand(domain, finalProxyPackage, requirement.getIdentifier(), requirement.getDesc());
domain.getCommandStack().execute(ReqCMD);
org.eclipse.uml2.uml.Class proxyreq = (org.eclipse.uml2.uml.Class)finalProxyPackage.getPackagedElement(requirement.getIdentifier());
RecordingCommand SatCMD = new SatisfyCreateCommand(domain, (NamedElement)UmlElement, (NamedElement)proxyreq, trace.getIdentifier());
domain.getCommandStack().execute(SatCMD);
System.out.println("Link between");
System.out.println(" Requirement: " + requirement);