diff options
author | ptessier | 2014-10-21 07:35:04 +0000 |
---|---|---|
committer | ptessier | 2014-10-21 07:35:04 +0000 |
commit | a97cb0298cd9e3ddce6890b3c0f289c7ebec4d09 (patch) | |
tree | cfc7fc23596ed9b53fba7149b01e133da1d33ec3 /extraplugins/req/org.eclipse.papyrus.req.reqif | |
parent | 1d4de2dc971c8e6e614fc75d78369bda020b5f4a (diff) | |
download | org.eclipse.papyrus-a97cb0298cd9e3ddce6890b3c0f289c7ebec4d09.tar.gz org.eclipse.papyrus-a97cb0298cd9e3ddce6890b3c0f289c7ebec4d09.tar.xz org.eclipse.papyrus-a97cb0298cd9e3ddce6890b3c0f289c7ebec4d09.zip |
447870: [Papyrus Req] Papyrus shall import or export reqIF file
https://bugs.eclipse.org/bugs/show_bug.cgi?id=447870
Change-Id: I18c991ec58599c2379eced54c2718f236fb02b30
Diffstat (limited to 'extraplugins/req/org.eclipse.papyrus.req.reqif')
7 files changed, 255 insertions, 5 deletions
diff --git a/extraplugins/req/org.eclipse.papyrus.req.reqif/META-INF/MANIFEST.MF b/extraplugins/req/org.eclipse.papyrus.req.reqif/META-INF/MANIFEST.MF index a4978d5bc6f..64a7196dff5 100644 --- a/extraplugins/req/org.eclipse.papyrus.req.reqif/META-INF/MANIFEST.MF +++ b/extraplugins/req/org.eclipse.papyrus.req.reqif/META-INF/MANIFEST.MF @@ -33,7 +33,10 @@ Require-Bundle: org.eclipse.ui, org.eclipse.ui.ide, org.eclipse.rmf.reqif10.xhtml;bundle-version="0.10.0", org.eclipse.rmf.reqif10.pror;bundle-version="0.10.0", - org.eclipse.rmf.reqif10.pror.edit;bundle-version="0.10.0" + org.eclipse.rmf.reqif10.pror.edit;bundle-version="0.10.0", + org.eclipse.papyrus.emf.facet.efacet.core, + org.eclipse.papyrus.emf.facet.efacet.metamodel, + org.eclipse.papyrus.emf.facet.query.java.core Bundle-RequiredExecutionEnvironment: JavaSE-1.6 Bundle-ActivationPolicy: lazy Export-Package: org.eclipse.papyrus.req.reqif.assistant diff --git a/extraplugins/req/org.eclipse.papyrus.req.reqif/build.properties b/extraplugins/req/org.eclipse.papyrus.req.reqif/build.properties index 7691ef79cf6..a6ce45ed911 100644 --- a/extraplugins/req/org.eclipse.papyrus.req.reqif/build.properties +++ b/extraplugins/req/org.eclipse.papyrus.req.reqif/build.properties @@ -2,5 +2,7 @@ source.. = src/ output.. = bin/
bin.includes = META-INF/,\
.,\
- img/
+ img/,\
+ doc/,\
+ resource/
diff --git a/extraplugins/req/org.eclipse.papyrus.req.reqif/plugin.xml b/extraplugins/req/org.eclipse.papyrus.req.reqif/plugin.xml index 8c3df550241..2baa34814b6 100644 --- a/extraplugins/req/org.eclipse.papyrus.req.reqif/plugin.xml +++ b/extraplugins/req/org.eclipse.papyrus.req.reqif/plugin.xml @@ -29,5 +29,10 @@ id="com.cea.darwin.reqif.exportWizard"
name="Export ReqIF">
</wizard>
+
+
+</extension>
+ <extension point="org.eclipse.papyrus.emf.facet.util.emf.core.modeldeclaration">
+ <modeldeclaration file="resource/ReqDisplay.custom"/>
</extension>
</plugin>
diff --git a/extraplugins/req/org.eclipse.papyrus.req.reqif/resource/ReqDisplay.custom b/extraplugins/req/org.eclipse.papyrus.req.reqif/resource/ReqDisplay.custom new file mode 100644 index 00000000000..c9b5b870174 --- /dev/null +++ b/extraplugins/req/org.eclipse.papyrus.req.reqif/resource/ReqDisplay.custom @@ -0,0 +1,15 @@ +<?xml version="1.0" encoding="UTF-8"?>
+<custom:Customization xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:custom="http://www.eclipse.org/papyrus/emf/facet/custom/0.2.incubation/custom" xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" xmlns:efacet="http://www.eclipse.org/papyrus/emf/facet/efacet/0.2.incubation/efacet" xmlns:javaQuery="http://www.eclipse.org/papyrus/emf/facet/query/java/0.2.incubation/javaquery" name="ReqDisplay" documentation="Used to Requirements" mustBeLoadedByDefault="true">
+ <eClassifiers xsi:type="custom:EClassCustomization" name="Element">
+ <extendedMetaclass href="http://www.eclipse.org/uml2/5.0.0/UML#//NamedElement"/>
+ <facetOperations name="DisplayStereotype">
+ <eType xsi:type="ecore:EDataType" href="http://www.eclipse.org/emf/2002/Ecore#//EString"/>
+ <eParameters name="eObject">
+ <eType xsi:type="ecore:EClass" href="http://www.eclipse.org/emf/2002/Ecore#//EObject"/>
+ </eParameters>
+ <query xsi:type="javaQuery:JavaQuery" implementationClassName="org.eclipse.papyrus.req.reqif.queries.GetComplexName"/>
+ <override xsi:type="efacet:FacetOperation" href="../../../plugin/org.eclipse.papyrus.emf.facet.custom.ui/resources/customproperties.efacet#//CustomizedEObject/label"/>
+ </facetOperations>
+ <extendedFacets href="../../../plugin/org.eclipse.papyrus.emf.facet.custom.ui/resources/customproperties.efacet#//CustomizedEObject"/>
+ </eClassifiers>
+</custom:Customization>
diff --git a/extraplugins/req/org.eclipse.papyrus.req.reqif/src/org/eclipse/papyrus/req/reqif/integration/assistant/ChooseAttributeEnumerationDialog.java b/extraplugins/req/org.eclipse.papyrus.req.reqif/src/org/eclipse/papyrus/req/reqif/integration/assistant/ChooseAttributeEnumerationDialog.java new file mode 100644 index 00000000000..a106dab231f --- /dev/null +++ b/extraplugins/req/org.eclipse.papyrus.req.reqif/src/org/eclipse/papyrus/req/reqif/integration/assistant/ChooseAttributeEnumerationDialog.java @@ -0,0 +1,62 @@ +/*****************************************************************************
+ * Copyright (c) 2014 CEA LIST.
+ *
+ *
+ * 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:
+ * Patrick Tessier (CEA LIST) patrick.tessier@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.req.reqif.integration.assistant;
+
+import java.util.Collection;
+
+import org.eclipse.emf.edit.ui.provider.AdapterFactoryLabelProvider;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.papyrus.uml.profile.ui.dialogs.ChooseSetAssistedDialog;
+import org.eclipse.rmf.reqif10.AttributeDefinitionEnumeration;
+import org.eclipse.rmf.reqif10.provider.ReqIF10ItemProviderAdapterFactory;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.widgets.Shell;
+
+/**
+ * Dialog in order to select Type from a ReqIF File
+ *
+ */
+public class ChooseAttributeEnumerationDialog extends ChooseSetAssistedDialog {
+
+ /**
+ *
+ * Constructor.
+ *
+ * @param parentShell a shell in order to launch the dialog
+ * @param spectObjectTypes a list of SpecObjectTypes
+ */
+ public ChooseAttributeEnumerationDialog(Shell parentShell,Collection<AttributeDefinitionEnumeration> attributeDefinitionEnumerations) {
+ super(parentShell, "Enumeration Attribute available", "Selected Enumeration Attribute ");
+ for(AttributeDefinitionEnumeration attDef : attributeDefinitionEnumerations) {
+ possibleElementList.addElement(attDef);
+ }
+
+ ReqIF10ItemProviderAdapterFactory adapterFactory= new ReqIF10ItemProviderAdapterFactory();
+ final AdapterFactoryLabelProvider factoryLabelProvider=new AdapterFactoryLabelProvider(adapterFactory);
+ labelProvider= new LabelProvider(){
+ @Override
+ public Image getImage(Object element) {
+ return factoryLabelProvider.getImage(element);
+ }
+ @Override
+ public String getText(Object element) {
+ return factoryLabelProvider.getText(element);
+ }
+ };
+
+
+
+ }
+
+}
diff --git a/extraplugins/req/org.eclipse.papyrus.req.reqif/src/org/eclipse/papyrus/req/reqif/queries/GetComplexName.java b/extraplugins/req/org.eclipse.papyrus.req.reqif/src/org/eclipse/papyrus/req/reqif/queries/GetComplexName.java new file mode 100644 index 00000000000..90524595efb --- /dev/null +++ b/extraplugins/req/org.eclipse.papyrus.req.reqif/src/org/eclipse/papyrus/req/reqif/queries/GetComplexName.java @@ -0,0 +1,71 @@ +/***************************************************************************** + * Copyright (c) 2010, 2014 CEA LIST and others. + * + * 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: + * CEA LIST - Initial API and implementation + * Christian W. Damus (CEA) - bug 425270 + * + /*****************************************************************************/ +package org.eclipse.papyrus.req.reqif.queries; + +import org.eclipse.emf.ecore.EStructuralFeature; +import org.eclipse.emf.edit.provider.IItemLabelProvider; +import org.eclipse.papyrus.emf.facet.efacet.core.IFacetManager; +import org.eclipse.papyrus.emf.facet.efacet.core.exception.DerivedTypedElementException; +import org.eclipse.papyrus.emf.facet.efacet.metamodel.v0_2_0.efacet.ParameterValue; +import org.eclipse.papyrus.emf.facet.query.java.core.IJavaQuery2; +import org.eclipse.papyrus.emf.facet.query.java.core.IParameterValueList2; +import org.eclipse.papyrus.req.reqif.I_SysMLStereotype; +import org.eclipse.papyrus.uml.tools.providers.DelegatingItemLabelProvider; +import org.eclipse.uml2.uml.NamedElement; +import org.eclipse.uml2.uml.Stereotype; + +/** get the name + the list of applied stereotypes */ +public class GetComplexName implements IJavaQuery2<NamedElement, String> { + + /** + * test if the stereotype is a SysML Requirement Stereotype + * @param stereotype a given stereotype + * @return return true if this is a SysML stereotype or inherits directly or indirectly from requirement + */ + protected boolean isRequirementStereotype(Stereotype stereotype) { + if( I_SysMLStereotype.REQUIREMENT_STEREOTYPE.equals(stereotype.getQualifiedName())){ + return true; + } + for(org.eclipse.uml2.uml.Class superStereotype : stereotype.getSuperClasses()) { + if( superStereotype instanceof Stereotype){ + if(isRequirementStereotype((Stereotype)superStereotype)){ + return true; + } + } + } + return false; + } + + private static final IItemLabelProvider labelProvider = new DelegatingItemLabelProvider(); + + public String evaluate(NamedElement source, IParameterValueList2 parameterValues, IFacetManager facetManager) throws DerivedTypedElementException { + ParameterValue parameterValue = parameterValues.getParameterValueByName("eObject"); //$NON-NLS-1$ + if (parameterValue.getValue() instanceof EStructuralFeature) { + return ((EStructuralFeature) parameterValue.getValue()).getName(); + } + Stereotype stereotypeReq=source.getAppliedStereotype(I_SysMLStereotype.REQUIREMENT_STEREOTYPE); + Stereotype appStereotype=null; + if(source.getAppliedStereotypes().size()>0){ + appStereotype=source.getAppliedStereotypes().get(0); + } + if(stereotypeReq!=null){ + return ""+source.getValue(stereotypeReq, I_SysMLStereotype.REQUIREMENT_ID_ATT)+": "+source.getValue(stereotypeReq, I_SysMLStereotype.REQUIREMENT_TEXT_ATT); + } + if((source instanceof org.eclipse.uml2.uml.Class) &&(appStereotype!=null) && (isRequirementStereotype(appStereotype))){ + return ""+source.getValue(appStereotype, I_SysMLStereotype.REQUIREMENT_ID_ATT)+": "+source.getValue(appStereotype, I_SysMLStereotype.REQUIREMENT_TEXT_ATT); + } + // Delegate to UML2 Edit providers to get localized and inferred names where applicable + return labelProvider.getText(source); + } +} diff --git a/extraplugins/req/org.eclipse.papyrus.req.reqif/src/org/eclipse/papyrus/req/reqif/transformation/ReqIFImporter.java b/extraplugins/req/org.eclipse.papyrus.req.reqif/src/org/eclipse/papyrus/req/reqif/transformation/ReqIFImporter.java index 3600ca8bebe..36bc6d8cc52 100644 --- a/extraplugins/req/org.eclipse.papyrus.req.reqif/src/org/eclipse/papyrus/req/reqif/transformation/ReqIFImporter.java +++ b/extraplugins/req/org.eclipse.papyrus.req.reqif/src/org/eclipse/papyrus/req/reqif/transformation/ReqIFImporter.java @@ -29,11 +29,14 @@ import org.eclipse.emf.common.util.URI; import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.emf.ecore.xmi.XMLResource;
import org.eclipse.emf.ecore.xmi.impl.XMLResourceImpl;
import org.eclipse.emf.transaction.TransactionalEditingDomain;
import org.eclipse.papyrus.req.reqif.I_SysMLStereotype;
import org.eclipse.papyrus.req.reqif.assistant.CreateOrSelectProfilDialog;
+import org.eclipse.papyrus.req.reqif.integration.assistant.ChooseAttributeEnumerationDialog;
+import org.eclipse.papyrus.req.reqif.integration.assistant.ChooseReqIFTypeDialog;
import org.eclipse.papyrus.uml.extensionpoints.utils.Util;
import org.eclipse.rmf.reqif10.AttributeDefinition;
import org.eclipse.rmf.reqif10.AttributeDefinitionBoolean;
@@ -53,6 +56,7 @@ import org.eclipse.rmf.reqif10.DatatypeDefinitionEnumeration; import org.eclipse.rmf.reqif10.EnumValue;
import org.eclipse.rmf.reqif10.Identifiable;
import org.eclipse.rmf.reqif10.ReqIF;
+import org.eclipse.rmf.reqif10.ReqIF10Factory;
import org.eclipse.rmf.reqif10.SpecElementWithAttributes;
import org.eclipse.rmf.reqif10.SpecHierarchy;
import org.eclipse.rmf.reqif10.SpecObject;
@@ -63,6 +67,7 @@ import org.eclipse.rmf.reqif10.SpecType; import org.eclipse.rmf.reqif10.Specification;
import org.eclipse.rmf.reqif10.SpecificationType;
import org.eclipse.rmf.reqif10.XhtmlContent;
+import org.eclipse.rmf.reqif10.common.util.ReqIF10Util;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.uml2.uml.Class;
import org.eclipse.uml2.uml.Comment;
@@ -113,7 +118,19 @@ public abstract class ReqIFImporter extends ReqIFBaseTransformation { * @param reqIFModel
*/
public void preProcess( ReqIF reqIFModel){
- //first make sure that all reqIFelement have a name
+ //1. first make sure that all reqIFelement have a name
+ setANameForTypes(reqIFModel);
+
+
+ //2. patterns, if 1 type, maybe there is an enumeration?
+ transformPatternEnumeration(reqIFModel,null);
+
+ }
+ /**
+ * set a name of all type of the ReqIF model if there is no name
+ * @param reqIFModel
+ */
+ protected void setANameForTypes(ReqIF reqIFModel) {
Iterator<EObject> reqIFElementIterator= reqIFModel.eAllContents();
int index =0;
while(reqIFElementIterator.hasNext()) {
@@ -125,10 +142,82 @@ public abstract class ReqIFImporter extends ReqIFBaseTransformation { index++;
}
}
-
}
}
+ /**
+ * this method transform type with enumeration to set of types
+ * @param reqIFModel
+ * @param attributeEnumeration the name of attribute definition if the type in order to transform. (in this case no UI)
+ */
+ protected void transformPatternEnumeration(ReqIF reqIFModel, String attributeEnumeration) {
+ ArrayList<SpecObjectType> specObjectTypes= new ArrayList<SpecObjectType>();
+
+ if(reqIFModel.getCoreContent().getSpecTypes()!=null&&reqIFModel.getCoreContent().getSpecTypes().size()>0){
+ for(SpecType reqIFType : reqIFModel.getCoreContent().getSpecTypes()) {
+ if(reqIFType instanceof SpecObjectType){
+ specObjectTypes.add( (SpecObjectType) reqIFType);
+ }
+ }
+ }
+
+ //maybe the topology of element is coded by an enumeration
+ if( specObjectTypes.size()==1){
+ SpecObjectType theType=specObjectTypes.get(0);
+ //find enumeration
+ ArrayList<AttributeDefinitionEnumeration> attEnumeration= new ArrayList<AttributeDefinitionEnumeration>();
+ AttributeDefinitionEnumeration patternEnumerationAtt= null;
+ for (AttributeDefinition attDefinition : theType.getSpecAttributes()) {
+ if( attDefinition instanceof AttributeDefinitionEnumeration){
+ attEnumeration.add((AttributeDefinitionEnumeration)attDefinition);
+ if(attributeEnumeration!=null&&attDefinition.getLongName().equals(attributeEnumeration)){
+ patternEnumerationAtt=(AttributeDefinitionEnumeration)attDefinition;
+ }
+ }
+ }
+ if(patternEnumerationAtt==null){
+ if(attEnumeration.size()>1){
+ ChooseAttributeEnumerationDialog assistedDialog= new ChooseAttributeEnumerationDialog(new Shell(), attEnumeration);
+ assistedDialog.open();
+ ArrayList<Object> result=assistedDialog.getSelectedElements();
+ patternEnumerationAtt=(AttributeDefinitionEnumeration) result.get(0);
+ }
+ else{
+ patternEnumerationAtt=attEnumeration.get(0);
+ }
+ }
+ //transform pseudo type from enumeration
+ DatatypeDefinitionEnumeration enumeration= patternEnumerationAtt.getType();
+ HashMap<String, SpecObjectType> newTypes= new HashMap<String, SpecObjectType> ();
+ for (EnumValue enumValue : enumeration.getSpecifiedValues()) {
+ SpecObjectType specObjectType=EcoreUtil.copy(theType);
+ specObjectType.setLongName(enumValue.getLongName());
+ specObjectType.setLastChange((GregorianCalendar)GregorianCalendar.getInstance());
+ reqIFModel.getCoreContent().getSpecTypes().add(specObjectType);
+ newTypes.put(enumValue.getLongName(), specObjectType);
+ }
+ for(SpecObject specObject : reqIFModel.getCoreContent().getSpecObjects()) {
+ //get Attribute Value
+ AttributeValueEnumeration attValue =(AttributeValueEnumeration)getAttributeValue(specObject, patternEnumerationAtt);
+ if(attValue!=null){
+ if( attValue.getValues().size()>0){
+ specObject.setType(newTypes.get(attValue.getValues().get(0).getLongName()));
+ System.err.println(specObject);
+ }
+ }
+ }
+
+ }
+ }
+ public static AttributeValue getAttributeValue(SpecElementWithAttributes specElement, AttributeDefinition attributeDefinition) {
+ for (AttributeValue value : specElement.getValues()) {
+ AttributeDefinition definition = ReqIF10Util.getAttributeDefinition(value);
+ if (attributeDefinition.getLongName().equals(definition.getLongName())) {
+ return value;
+ }
+ }
+ return null;
+ }
/**
* import selected SpecObjectType and their instances into UML Model
@@ -246,7 +335,7 @@ public abstract class ReqIFImporter extends ReqIFBaseTransformation { public void postProcess(Package UMLModel){
}
-
+
/**
* this agoal of this method is do add action before serialize, define and apply profile.
* Pay attention: Make sure that the profile could be define at the end of this action
@@ -612,6 +701,9 @@ public abstract class ReqIFImporter extends ReqIFBaseTransformation { */
protected Element importReqIFSpecObjects(SpecObject reqIFObject, org.eclipse.uml2.uml.Element owner, HashMap<String, Stereotype> reqStereotypes) {
//test of the the specObject could be imported
+ if(reqIFObject==null){
+ return null;
+ }
if(reqStereotypes.get(reqIFObject.getType().getLongName())!=null){
Class reqClass=null;
reqClass = createRequirementClass(owner);
|