| /***************************************************************************** |
| * 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.pdp4eng.req.profile.pdp4engReqGDPR.ProcessRequirement; |
| 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 BasicGDPRRequirementCreateCommand extends RecordingCommand { |
| protected Element owner; |
| private String id; |
| private String text; |
| protected org.eclipse.uml2.uml.Class requirement; |
| protected ProcessRequirement processRequirement; |
| protected TransactionalEditingDomain domain; |
| |
| /** |
| * |
| * Constructor. |
| * |
| * @param domain |
| * @param owner never null |
| * @param id can be null, in this case it is generated |
| * @param text can be null |
| */ |
| public BasicGDPRRequirementCreateCommand(TransactionalEditingDomain domain, Element owner, String id,String text, ProcessRequirement processRequirement) { |
| super(domain, "PapyrusReqSysMLRequirementCreateCommand"); |
| this.owner = owner; |
| this.id = id; |
| this.text = text; |
| this.processRequirement= processRequirement; |
| this.domain= domain; |
| } |
| |
| 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); |
| } |
| } |
| } |