blob: ce68bee51f048393a147da85e085df026a4afe2f [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
* Patrick Tessier (CEA LIST) Patrick.tessier@cea.fr
* Gabriel Pedroza (CEA LIST) gabriel.pedroza@cea.fr
*****************************************************************************/
package org.eclipse.pdp4eng.req.gdprananalysis.internal;
import org.eclipse.emf.transaction.RecordingCommand;
import org.eclipse.emf.transaction.TransactionalEditingDomain;
import org.eclipse.papyrus.requirements.sysml14.common.I_SysMLStereotype;
import org.eclipse.papyrus.requirements.sysml14.common.Utils;
import org.eclipse.uml2.uml.Element;
import org.eclipse.uml2.uml.Package;
import org.eclipse.uml2.uml.Stereotype;
/**
* Creates a new based on the options chosen in the Papyrus Req preferences page.
*
*/
public class BasicRequirementCreateCommand extends RecordingCommand {
protected Element owner;
private String id;
private String text;
protected org.eclipse.uml2.uml.Class requirement;
/**
*
* Constructor.
*
* @param domain
* @param owner never null
* @param id can be null, in this case it is generated
* @param text can be null
*/
public BasicRequirementCreateCommand(TransactionalEditingDomain domain, Element owner, String id,String text) {
super(domain, "PapyrusReqSysMLRequirementCreateCommand");
this.owner = owner;
this.id = id;
this.text = text;
}
protected void createRequirement(org.eclipse.uml2.uml.Package owner, String id,String text) {
requirement = owner.createOwnedClass("tmpName", false);
Stereotype reqStereotype = requirement.getApplicableStereotype(I_SysMLStereotype.REQUIREMENT_STEREOTYPE);
requirement.applyStereotype(reqStereotype);
if( id==null) {
id = Utils.getNewRequirementID(owner);
}
requirement.setName(id);
requirement.setValue(reqStereotype, I_SysMLStereotype.REQUIREMENT_ID_ATT, id);
if( text!=null) {
requirement.setValue(reqStereotype, I_SysMLStereotype.REQUIREMENT_TEXT_ATT, text);
}
}
@Override
protected void doExecute() {
if (owner instanceof Package) {
createRequirement((Package) owner, id, text);
} else if (owner.getNearestPackage() != null) {
createRequirement(owner.getNearestPackage(), id, text);
}
}
}