summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBenoit Maggi2014-02-04 09:31:14 (EST)
committerBenoit Maggi2014-02-04 09:31:14 (EST)
commitf86c1d8b36eb37cee0122e4de920ed71a6f952bc (patch)
treef34faf9d595f060daf0a1a3dc0724893776610ad
parent2517e976f59d716abeb5f73df1ed0995ecc11eb6 (diff)
downloadorg.eclipse.papyrus-f86c1d8b36eb37cee0122e4de920ed71a6f952bc.zip
org.eclipse.papyrus-f86c1d8b36eb37cee0122e4de920ed71a6f952bc.tar.gz
org.eclipse.papyrus-f86c1d8b36eb37cee0122e4de920ed71a6f952bc.tar.bz2
Bug 406290 - [SysML IBD] When the type of a part or a reference changes
the nestedConnectors linked to an internal component of the part/refrence are hidden but are not deleted from the model. When destroying a part or changing its type, destroying all connectors that reference this part in NestedConnectorEnd. Change-Id: I47d8ff0a3a26ac5b9b74495303c6b154ea924c40 Signed-off-by: Benoit Maggi <benoit.maggi@cea.fr>
-rw-r--r--plugins/sysml/org.eclipse.papyrus.sysml.service.types/META-INF/MANIFEST.MF3
-rw-r--r--plugins/sysml/org.eclipse.papyrus.sysml.service.types/src/org/eclipse/papyrus/sysml/service/types/helper/advice/PropertyEditHelperAdvice.java676
-rw-r--r--plugins/sysml/org.eclipse.papyrus.sysml.service.types/src/org/eclipse/papyrus/sysml/service/types/utils/ConnectorUtils.java30
-rw-r--r--plugins/sysml/org.eclipse.papyrus.sysml/src/org/eclipse/papyrus/sysml/util/SysmlResource.java433
-rw-r--r--plugins/uml/tools/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/ElementUtil.java57
5 files changed, 656 insertions, 543 deletions
diff --git a/plugins/sysml/org.eclipse.papyrus.sysml.service.types/META-INF/MANIFEST.MF b/plugins/sysml/org.eclipse.papyrus.sysml.service.types/META-INF/MANIFEST.MF
index 302abc6..a27c5c3 100644
--- a/plugins/sysml/org.eclipse.papyrus.sysml.service.types/META-INF/MANIFEST.MF
+++ b/plugins/sysml/org.eclipse.papyrus.sysml.service.types/META-INF/MANIFEST.MF
@@ -11,7 +11,8 @@ Require-Bundle: org.eclipse.ui,
org.eclipse.uml2.uml.profile.l2;bundle-version="1.0.0",
org.eclipse.core.expressions,
org.eclipse.papyrus.infra.tools;bundle-version="0.10.1",
- org.eclipse.papyrus.uml.diagram.common
+ org.eclipse.papyrus.uml.diagram.common,
+ org.eclipse.papyrus.uml.tools.utils;bundle-version="0.10.1"
Export-Package: org.eclipse.papyrus.sysml.service.types,
org.eclipse.papyrus.sysml.service.types.command,
org.eclipse.papyrus.sysml.service.types.element,
diff --git a/plugins/sysml/org.eclipse.papyrus.sysml.service.types/src/org/eclipse/papyrus/sysml/service/types/helper/advice/PropertyEditHelperAdvice.java b/plugins/sysml/org.eclipse.papyrus.sysml.service.types/src/org/eclipse/papyrus/sysml/service/types/helper/advice/PropertyEditHelperAdvice.java
index 5c174e5..316f82f 100644
--- a/plugins/sysml/org.eclipse.papyrus.sysml.service.types/src/org/eclipse/papyrus/sysml/service/types/helper/advice/PropertyEditHelperAdvice.java
+++ b/plugins/sysml/org.eclipse.papyrus.sysml.service.types/src/org/eclipse/papyrus/sysml/service/types/helper/advice/PropertyEditHelperAdvice.java
@@ -1,316 +1,360 @@
-/*****************************************************************************
- * Copyright (c) 2011-2012 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:
- *
- * CEA LIST - Initial API and implementation
- *
- *****************************************************************************/
-package org.eclipse.papyrus.sysml.service.types.helper.advice;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-import java.util.Set;
-
-import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.core.runtime.IAdaptable;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.gmf.runtime.common.core.command.AbstractCommand;
-import org.eclipse.gmf.runtime.common.core.command.CommandResult;
-import org.eclipse.gmf.runtime.common.core.command.CompositeCommand;
-import org.eclipse.gmf.runtime.common.core.command.ICommand;
-import org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand;
-import org.eclipse.gmf.runtime.emf.core.util.EMFCoreUtil;
-import org.eclipse.gmf.runtime.emf.type.core.ISpecializationType;
-import org.eclipse.gmf.runtime.emf.type.core.edithelper.AbstractEditHelperAdvice;
-import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyElementRequest;
-import org.eclipse.gmf.runtime.emf.type.core.requests.ReorientRelationshipRequest;
-import org.eclipse.gmf.runtime.emf.type.core.requests.SetRequest;
-import org.eclipse.gmf.runtime.notation.View;
-import org.eclipse.jface.dialogs.MessageDialogWithToggle;
-import org.eclipse.jface.preference.IPreferenceStore;
-import org.eclipse.papyrus.infra.services.edit.service.ElementEditServiceUtils;
-import org.eclipse.papyrus.infra.services.edit.service.IElementEditService;
-import org.eclipse.papyrus.infra.services.edit.utils.RequestParameterConstants;
-import org.eclipse.papyrus.sysml.constraints.ConstraintBlock;
-import org.eclipse.papyrus.sysml.constraints.ConstraintProperty;
-import org.eclipse.papyrus.sysml.constraints.ConstraintsPackage;
-import org.eclipse.papyrus.sysml.service.types.Activator;
-import org.eclipse.papyrus.sysml.service.types.element.SysMLElementTypes;
-import org.eclipse.papyrus.uml.diagram.common.util.CrossReferencerUtil;
-import org.eclipse.papyrus.uml.service.types.utils.ElementUtil;
-import org.eclipse.papyrus.uml.service.types.utils.NamedElementHelper;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.uml2.uml.Association;
-import org.eclipse.uml2.uml.Element;
-import org.eclipse.uml2.uml.Port;
-import org.eclipse.uml2.uml.Property;
-import org.eclipse.uml2.uml.Type;
-import org.eclipse.uml2.uml.UMLFactory;
-import org.eclipse.uml2.uml.UMLPackage;
-import org.eclipse.uml2.uml.util.UMLUtil;
-import org.eclipse.uml2.uml.util.UMLUtil.StereotypeApplicationHelper;
-
-/**
- * <pre>
- * This HelperAdvice completes {@link Property} edit commands with:
- * - possibly required (sysML) association re-factor command.
- * </pre>
- */
-public class PropertyEditHelperAdvice extends AbstractEditHelperAdvice {
-
- /**
- * <pre>
- * {@inheritDoc}
- *
- * While setting {@link Property} (excluding {@link Port} and {@link ConstraintParameter} type:
- * - add possibly required (sysML) association re-factor command when needed.
- * - add/remove possibly required ConstraintProperty stereotype when needed.
- * </pre>
- */
- @SuppressWarnings("unchecked")
- @Override
- protected ICommand getBeforeSetCommand(SetRequest request) {
- ICommand gmfCommand = super.getBeforeSetCommand(request);
-
- EObject elementToEdit = request.getElementToEdit();
- if((elementToEdit instanceof Property) && !(elementToEdit instanceof Port) &&
- (request.getFeature() == UMLPackage.eINSTANCE.getTypedElement_Type()) && (request.getValue() instanceof Type)) {
-
- Property propertyToEdit = (Property)elementToEdit;
-
- // SysML specification : all property typed by a ConstraintBlock must have a ContraintProperty stereotype applied
- if (request.getValue() instanceof org.eclipse.uml2.uml.Class) {
- ICommand stereotypeApplicationCommand = getConstraintPropertyStereotypeApplicationCommand(propertyToEdit, (org.eclipse.uml2.uml.Class)request.getValue(), request);
- gmfCommand = CompositeCommand.compose(gmfCommand, stereotypeApplicationCommand);
- }
-
- // Exclude ConstraintParameter (simple property without ConstraintProperty stereotype owned by a ConstraintBlock)
- if (propertyToEdit.eContainer() instanceof org.eclipse.uml2.uml.Class && UMLUtil.getStereotypeApplication((Element)propertyToEdit.eContainer(), ConstraintBlock.class) != null) {
- if (UMLUtil.getStereotypeApplication(propertyToEdit, ConstraintProperty.class) == null) {
- return gmfCommand;
- }
- }
-
- Association relatedAssociation = propertyToEdit.getAssociation();
-
- // The edited property has to be related to a SysML association
- if((relatedAssociation == null) || !(ElementUtil.hasNature(relatedAssociation, SysMLElementTypes.SYSML_NATURE))) {
-
- // If no association exist and the new type is a Block
- // (not a ConstraintBlock => a property typed by a ConstraintBlock is a ConstraintProperty, not a Part neither a Reference),
- // add the association
- if ((relatedAssociation == null)
- && ((ISpecializationType) SysMLElementTypes.BLOCK).getMatcher().matches((Type) request.getValue())
- && !((ISpecializationType) SysMLElementTypes.CONSTRAINT_BLOCK).getMatcher().matches((Type) request.getValue())
- && ((ISpecializationType) SysMLElementTypes.BLOCK).getMatcher().matches(propertyToEdit.eContainer())) {
-
- ICommand addAssociationCommand = getCreatePartAssociationCommand((org.eclipse.uml2.uml.Class)propertyToEdit.eContainer(), propertyToEdit, (org.eclipse.uml2.uml.Class)request.getValue());
- gmfCommand = CompositeCommand.compose(gmfCommand, addAssociationCommand);
- }
-
- return gmfCommand;
- }
-
- // Setting new type can be related to an association re-orient (or trigger the association re-orient)
- // Retrieve elements already under re-factor.
- List<EObject> currentlyRefactoredElements = (request.getParameter(RequestParameterConstants.ASSOCIATION_REFACTORED_ELEMENTS) != null) ? (List<EObject>)request.getParameter(RequestParameterConstants.ASSOCIATION_REFACTORED_ELEMENTS) : new ArrayList<EObject>();
- if(!currentlyRefactoredElements.contains(propertyToEdit)) {
- currentlyRefactoredElements.add(propertyToEdit);
- request.getParameters().put(RequestParameterConstants.ASSOCIATION_REFACTORED_ELEMENTS, currentlyRefactoredElements);
-
- // Current association already under re-factor ?
- if(currentlyRefactoredElements.contains(relatedAssociation)) {
- return gmfCommand;
- }
- }
-
- // If the new type is not a block, destroy related association
- // This must be done only if the setting of the property type is not part of an association re-orient (hence after the previous code-block),
- // otherwise there is no legitimate reason to destroy the existing association while re-orienting it.
- if (!((ISpecializationType) SysMLElementTypes.BLOCK).getMatcher().matches((Type) request.getValue()) && propertyToEdit.getType() != null) {
- ICommand destroyCommand = getDestroyPartAssociationCommand(relatedAssociation, propertyToEdit);
- gmfCommand = CompositeCommand.compose(gmfCommand, destroyCommand);
-
- return gmfCommand;
- }
-
- ICommand refactorCommand = getAssociationRefactoringCommand(propertyToEdit, relatedAssociation, request);
- gmfCommand = CompositeCommand.compose(gmfCommand, refactorCommand);
- }
-
- if(gmfCommand != null) {
- gmfCommand = gmfCommand.reduce();
- }
-
- return gmfCommand;
- }
-
- /**
- * Create a re-factoring command related to a Property move.
- *
- * @param setProperty
- * the property which type is set
- * @param associationToRefactor
- * the association to re-factor (re-orient action)
- * @param request
- * the original set request
- * @return the re-factoring command
- */
- private ICommand getAssociationRefactoringCommand(Property setProperty, Association associationToRefactor, SetRequest request) {
-
- Association relatedAssociation = setProperty.getAssociation(); // Should not be null, test before calling method.
-
- if (associationToRefactor.getMemberEnds().size() >= 2) {
- // Re-orient the related association (do not use edit service to avoid infinite loop here)
- int direction = ReorientRelationshipRequest.REORIENT_TARGET;
- if(setProperty == associationToRefactor.getMemberEnds().get(1)) {
- direction = ReorientRelationshipRequest.REORIENT_SOURCE;
- }
-
- ReorientRelationshipRequest reorientRequest = new ReorientRelationshipRequest(relatedAssociation, (Type)request.getValue(), setProperty.eContainer(), direction);
- reorientRequest.addParameters(request.getParameters());
-
- IElementEditService provider = ElementEditServiceUtils.getCommandProvider(relatedAssociation);
- if(provider != null) {
- return provider.getEditCommand(reorientRequest);
- }
- }
-
- return null;
- }
-
- /**
- * Create a part association creation command.
- *
- * @return the part association creation command
- */
- private ICommand getCreatePartAssociationCommand(final org.eclipse.uml2.uml.Class sourceBlock, final Property sourceProperty, final org.eclipse.uml2.uml.Class targetBlock) {
-
- return new AbstractCommand("Create part association") {
-
- @Override
- protected CommandResult doUndoWithResult(IProgressMonitor progressMonitor, IAdaptable info) throws ExecutionException {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- protected CommandResult doRedoWithResult(IProgressMonitor progressMonitor, IAdaptable info) throws ExecutionException {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- protected CommandResult doExecuteWithResult(IProgressMonitor progressMonitor, IAdaptable info) throws ExecutionException {
- Association association = UMLFactory.eINSTANCE.createAssociation();
-
- // Add the association in the model
- org.eclipse.uml2.uml.Package container = (org.eclipse.uml2.uml.Package)EMFCoreUtil.getLeastCommonContainer(Arrays.asList(new EObject[]{sourceBlock, targetBlock}), UMLPackage.eINSTANCE.getPackage());
- container.getPackagedElements().add(association);
-
- // Use existing Property as source...
- association.getMemberEnds().add(sourceProperty);
- // ... and create the opposite (unnamed) Property
- Property targetProperty = UMLFactory.eINSTANCE.createProperty();
- association.getOwnedEnds().add(targetProperty);
-
- // Set Association name
- // Initialize the element name based on the created IElementType
- String initializedName = NamedElementHelper.getDefaultNameWithIncrementFromBase(UMLPackage.eINSTANCE.getAssociation().getName(), association.eContainer().eContents());
- association.setName(initializedName);
-
- // Add SysML Nature on the new Association
- ElementUtil.addNature(association, SysMLElementTypes.SYSML_NATURE);
-
- return CommandResult.newOKCommandResult(association) ;
- }
- };
-
- }
-
- /**
- * Apply/remove the ConstraintProperty stereotype application
- *
- * @return the ConstraintProperty stereotype application command
- */
- private ICommand getConstraintPropertyStereotypeApplicationCommand(final Property sourceProperty, final org.eclipse.uml2.uml.Class targetBlock, final SetRequest request) {
-
- return new AbstractTransactionalCommand(request.getEditingDomain(), "Apply/Remove ConstraintProperty Stereotype", null) {
-
- @Override
- protected CommandResult doExecuteWithResult(IProgressMonitor progressMonitor, IAdaptable info) throws ExecutionException {
- // SysML specification : all property typed by a ConstraintBlock must have a ContraintProperty stereotype applied
- ConstraintProperty constraintPropertyApplication = UMLUtil.getStereotypeApplication(sourceProperty, ConstraintProperty.class);
- if (UMLUtil.getStereotypeApplication(targetBlock, ConstraintBlock.class) != null) {
- if (constraintPropertyApplication == null) {
- StereotypeApplicationHelper.INSTANCE.applyStereotype(sourceProperty, ConstraintsPackage.eINSTANCE.getConstraintProperty());
- final String diagramType = null;
- // Remove representations
- Set<View> memberViewsToDestroy = CrossReferencerUtil.getCrossReferencingViews(sourceProperty, diagramType);
- if (memberViewsToDestroy.size() != 0) {
- final IPreferenceStore store = Activator.getDefault().getPreferenceStore();
- final String DISPLAY_MESSAGE_FOR_TYPING_ACTION_PREFERENCE_KEY = "displayMessageForTypingActionPreferenceKey";
- boolean contains = store.contains(DISPLAY_MESSAGE_FOR_TYPING_ACTION_PREFERENCE_KEY);
- if(!contains) {
- store.setValue(DISPLAY_MESSAGE_FOR_TYPING_ACTION_PREFERENCE_KEY, MessageDialogWithToggle.NEVER);
- store.setDefault(DISPLAY_MESSAGE_FOR_TYPING_ACTION_PREFERENCE_KEY, MessageDialogWithToggle.NEVER);
- }
- final String hideValue = store.getString(DISPLAY_MESSAGE_FOR_TYPING_ACTION_PREFERENCE_KEY);
- if(!hideValue.equals(MessageDialogWithToggle.ALWAYS)) {
- int size = memberViewsToDestroy.size();
- MessageDialogWithToggle.openInformation(Display.getDefault().getActiveShell(),
- "Change Type Action",
- "WARNING! Typing a Property by a ConstraintBlock make this property become a ConstraintProperty. ConstraintProperty have a specific representation. "
- + "\nSo all representations of this property will be removed from the model (" + size + " occurence" + ((size > 1) ? "s" : "") + ")."
- , "Don't show this dialog the next time",
- false, store, DISPLAY_MESSAGE_FOR_TYPING_ACTION_PREFERENCE_KEY);
- }
-
- }
- for (View view : memberViewsToDestroy) {
- final DestroyElementRequest destroyRequest = new DestroyElementRequest(request.getEditingDomain(), view, false);
- final IElementEditService commandProvider = ElementEditServiceUtils.getCommandProvider(view);
- ICommand editCommand = commandProvider.getEditCommand(destroyRequest);
- editCommand.execute(progressMonitor, info);
- }
- }
- }
- else {
- if (constraintPropertyApplication != null) {
- StereotypeApplicationHelper.INSTANCE.removeFromContainmentList(sourceProperty, constraintPropertyApplication);
- }
- }
- return CommandResult.newOKCommandResult(sourceProperty) ;
- }
- };
- }
-
- /**
- * Create a part association destroy command.
- *
- * @return the part association destroy command
- */
- @SuppressWarnings("unchecked")
- private ICommand getDestroyPartAssociationCommand(Association partAssociation, Property propertyToEdit) {
-
- DestroyElementRequest request = new DestroyElementRequest(partAssociation, false);
- List<EObject> dependentsToKeep = Arrays.asList(new EObject[] { propertyToEdit });
- request.getParameters().put(RequestParameterConstants.DEPENDENTS_TO_KEEP, dependentsToKeep);
-
- IElementEditService provider = ElementEditServiceUtils.getCommandProvider(partAssociation.eContainer());
- if(provider == null) {
- return null;
- }
- ICommand destroyCommand = provider.getEditCommand(request);
-
- return destroyCommand;
- }
-}
+/*****************************************************************************
+ * Copyright (c) 2011-2012 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:
+ *
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.sysml.service.types.helper.advice;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Set;
+
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.gmf.runtime.common.core.command.AbstractCommand;
+import org.eclipse.gmf.runtime.common.core.command.CommandResult;
+import org.eclipse.gmf.runtime.common.core.command.CompositeCommand;
+import org.eclipse.gmf.runtime.common.core.command.ICommand;
+import org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand;
+import org.eclipse.gmf.runtime.emf.core.util.EMFCoreUtil;
+import org.eclipse.gmf.runtime.emf.type.core.ISpecializationType;
+import org.eclipse.gmf.runtime.emf.type.core.edithelper.AbstractEditHelperAdvice;
+import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyDependentsRequest;
+import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyElementRequest;
+import org.eclipse.gmf.runtime.emf.type.core.requests.ReorientRelationshipRequest;
+import org.eclipse.gmf.runtime.emf.type.core.requests.SetRequest;
+import org.eclipse.gmf.runtime.notation.View;
+import org.eclipse.jface.dialogs.MessageDialogWithToggle;
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.papyrus.infra.services.edit.service.ElementEditServiceUtils;
+import org.eclipse.papyrus.infra.services.edit.service.IElementEditService;
+import org.eclipse.papyrus.infra.services.edit.utils.RequestParameterConstants;
+import org.eclipse.papyrus.sysml.constraints.ConstraintBlock;
+import org.eclipse.papyrus.sysml.constraints.ConstraintProperty;
+import org.eclipse.papyrus.sysml.constraints.ConstraintsPackage;
+import org.eclipse.papyrus.sysml.service.types.Activator;
+import org.eclipse.papyrus.sysml.service.types.element.SysMLElementTypes;
+import org.eclipse.papyrus.sysml.service.types.utils.ConnectorUtils;
+import org.eclipse.papyrus.uml.diagram.common.util.CrossReferencerUtil;
+import org.eclipse.papyrus.uml.service.types.utils.ElementUtil;
+import org.eclipse.papyrus.uml.service.types.utils.NamedElementHelper;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.uml2.uml.Association;
+import org.eclipse.uml2.uml.Connector;
+import org.eclipse.uml2.uml.Element;
+import org.eclipse.uml2.uml.Port;
+import org.eclipse.uml2.uml.Property;
+import org.eclipse.uml2.uml.Type;
+import org.eclipse.uml2.uml.UMLFactory;
+import org.eclipse.uml2.uml.UMLPackage;
+import org.eclipse.uml2.uml.util.UMLUtil;
+import org.eclipse.uml2.uml.util.UMLUtil.StereotypeApplicationHelper;
+
+/**
+ * <pre>
+ * This HelperAdvice completes {@link Property} edit commands with:
+ * - possibly required (sysML) association re-factor command.
+ * </pre>
+ */
+public class PropertyEditHelperAdvice extends AbstractEditHelperAdvice {
+
+ /**
+ * <pre>
+ * {@inheritDoc}
+ *
+ * While setting {@link Property} (excluding {@link Port} and {@link ConstraintParameter} type:
+ * - add possibly required (sysML) association re-factor command when needed.
+ * - add/remove possibly required ConstraintProperty stereotype when needed.
+ * </pre>
+ */
+ @SuppressWarnings("unchecked")
+ @Override
+ protected ICommand getBeforeSetCommand(SetRequest request) {
+ ICommand gmfCommand = super.getBeforeSetCommand(request);
+
+ EObject elementToEdit = request.getElementToEdit();
+ if((elementToEdit instanceof Property) && !(elementToEdit instanceof Port) && (request.getFeature() == UMLPackage.eINSTANCE.getTypedElement_Type()) && (request.getValue() instanceof Type)) {
+
+ Property propertyToEdit = (Property)elementToEdit;
+
+ // SysML specification : all property typed by a ConstraintBlock must have a ContraintProperty stereotype applied
+ if(request.getValue() instanceof org.eclipse.uml2.uml.Class) {
+ ICommand stereotypeApplicationCommand = getConstraintPropertyStereotypeApplicationCommand(propertyToEdit, (org.eclipse.uml2.uml.Class)request.getValue(), request);
+ gmfCommand = CompositeCommand.compose(gmfCommand, stereotypeApplicationCommand);
+ }
+
+ // Exclude ConstraintParameter (simple property without ConstraintProperty stereotype owned by a ConstraintBlock)
+ if(propertyToEdit.eContainer() instanceof org.eclipse.uml2.uml.Class && UMLUtil.getStereotypeApplication((Element)propertyToEdit.eContainer(), ConstraintBlock.class) != null) {
+ if(UMLUtil.getStereotypeApplication(propertyToEdit, ConstraintProperty.class) == null) {
+ return gmfCommand;
+ }
+ }
+
+ Association relatedAssociation = propertyToEdit.getAssociation();
+
+ // The edited property has to be related to a SysML association
+ if((relatedAssociation == null) || !(ElementUtil.hasNature(relatedAssociation, SysMLElementTypes.SYSML_NATURE))) {
+ // If no association exist and the new type is a Block
+ // (not a ConstraintBlock => a property typed by a ConstraintBlock is a ConstraintProperty, not a Part neither a Reference),
+ // add the association
+ if((relatedAssociation == null) && ((ISpecializationType)SysMLElementTypes.BLOCK).getMatcher().matches((Type)request.getValue()) && !((ISpecializationType)SysMLElementTypes.CONSTRAINT_BLOCK).getMatcher().matches((Type)request.getValue()) && ((ISpecializationType)SysMLElementTypes.BLOCK).getMatcher().matches(propertyToEdit.eContainer())) {
+ ICommand addAssociationCommand = getCreatePartAssociationCommand((org.eclipse.uml2.uml.Class)propertyToEdit.eContainer(), propertyToEdit, (org.eclipse.uml2.uml.Class)request.getValue());
+ gmfCommand = CompositeCommand.compose(gmfCommand, addAssociationCommand);
+ }
+ return gmfCommand;
+ }
+
+ // Setting new type can be related to an association re-orient (or trigger the association re-orient)
+ // Retrieve elements already under re-factor.
+ List<EObject> currentlyRefactoredElements = (request.getParameter(RequestParameterConstants.ASSOCIATION_REFACTORED_ELEMENTS) != null) ? (List<EObject>)request.getParameter(RequestParameterConstants.ASSOCIATION_REFACTORED_ELEMENTS) : new ArrayList<EObject>();
+ if(!currentlyRefactoredElements.contains(propertyToEdit)) {
+ currentlyRefactoredElements.add(propertyToEdit);
+ request.getParameters().put(RequestParameterConstants.ASSOCIATION_REFACTORED_ELEMENTS, currentlyRefactoredElements);
+
+ // Current association already under re-factor ?
+ if(currentlyRefactoredElements.contains(relatedAssociation)) {
+ return gmfCommand;
+ }
+ }
+
+ // If the new type is not a block, destroy related association
+ // This must be done only if the setting of the property type is not part of an association re-orient (hence after the previous code-block),
+ // otherwise there is no legitimate reason to destroy the existing association while re-orienting it.
+ if(!((ISpecializationType)SysMLElementTypes.BLOCK).getMatcher().matches((Type)request.getValue()) && propertyToEdit.getType() != null) {
+ ICommand destroyCommand = getDestroyPartAssociationCommand(relatedAssociation, propertyToEdit);
+ gmfCommand = CompositeCommand.compose(gmfCommand, destroyCommand);
+ return gmfCommand;
+ }
+
+ ICommand refactorCommand = getAssociationRefactoringCommand(propertyToEdit, relatedAssociation, request);
+ gmfCommand = CompositeCommand.compose(gmfCommand, refactorCommand);
+ }
+
+ if(gmfCommand != null) {
+ gmfCommand = gmfCommand.reduce();
+ }
+
+ return gmfCommand;
+ }
+
+ /**
+ *
+ * @see org.eclipse.gmf.runtime.emf.type.core.edithelper.AbstractEditHelperAdvice#getAfterSetCommand(org.eclipse.gmf.runtime.emf.type.core.requests.SetRequest)
+ *
+ * @param setRequest
+ * @return
+ */
+ @Override
+ protected ICommand getAfterSetCommand(SetRequest setRequest) {
+ ICommand afterSetCommand = super.getAfterSetCommand(setRequest);
+ EObject elementToEdit = setRequest.getElementToEdit();
+ if((elementToEdit instanceof Property) && !(elementToEdit instanceof Port) && (setRequest.getFeature() == UMLPackage.eINSTANCE.getTypedElement_Type()) && (setRequest.getValue() instanceof Type)) {
+ afterSetCommand = getDestroyAssociatedNestedConnectorCommand((Property)elementToEdit, afterSetCommand);
+ }
+ return afterSetCommand;
+ }
+
+ /**
+ *
+ * @see org.eclipse.gmf.runtime.emf.type.core.edithelper.AbstractEditHelperAdvice#getAfterDestroyDependentsCommand(org.eclipse.gmf.runtime.emf.type.core.requests.DestroyDependentsRequest)
+ *
+ * @param destroyDependentsRequest
+ * @return
+ */
+ @Override
+ protected ICommand getAfterDestroyDependentsCommand(DestroyDependentsRequest destroyDependentsRequest) {
+ ICommand afterDestroyDependentsCommand = super.getAfterDestroyDependentsCommand(destroyDependentsRequest);
+ EObject elementToDestroy = destroyDependentsRequest.getElementToDestroy();
+ if(elementToDestroy instanceof Property) {
+ afterDestroyDependentsCommand = getDestroyAssociatedNestedConnectorCommand((Property)elementToDestroy, afterDestroyDependentsCommand);
+ }
+ return afterDestroyDependentsCommand;
+ }
+
+ /**
+ * Create a destroy command for all connectors that have this property in their <NestedConnectorEnd> property path.
+ *
+ * @param property
+ * the part to be destroyed
+ * @param command
+ * @return
+ */
+ private ICommand getDestroyAssociatedNestedConnectorCommand(Property property, ICommand command) {
+ List<Connector> instancesFilteredByType = org.eclipse.papyrus.uml.tools.utils.ElementUtil.getInstancesFilteredByType(property.getModel(), Connector.class, null);
+ List<Connector> connectorToDestroy = ConnectorUtils.filterConnectorByPropertyInNestedConnectorEnd(instancesFilteredByType, (Property)property);
+ for(Connector connector : connectorToDestroy) {
+ ICommand destroyConnectorCommand = getDestroyConnectorCommand(connector);
+ command = CompositeCommand.compose(command, destroyConnectorCommand);
+ }
+ return command;
+ }
+
+ /**
+ * Create a connector destroy command.
+ *
+ * @param connector
+ * @return the connector destroy command
+ */
+ private ICommand getDestroyConnectorCommand(Connector connector) {
+ DestroyElementRequest request = new DestroyElementRequest(connector, false);
+ IElementEditService provider = ElementEditServiceUtils.getCommandProvider(connector.eContainer());
+ if(provider == null) {
+ return null;
+ }
+ return provider.getEditCommand(request);
+ }
+
+ /**
+ * Create a re-factoring command related to a Property move.
+ *
+ * @param setProperty
+ * the property which type is set
+ * @param associationToRefactor
+ * the association to re-factor (re-orient action)
+ * @param request
+ * the original set request
+ * @return the re-factoring command
+ */
+ private ICommand getAssociationRefactoringCommand(Property setProperty, Association associationToRefactor, SetRequest request) {
+
+ Association relatedAssociation = setProperty.getAssociation(); // Should not be null, test before calling method.
+
+ if(associationToRefactor.getMemberEnds().size() >= 2) {
+ // Re-orient the related association (do not use edit service to avoid infinite loop here)
+ int direction = ReorientRelationshipRequest.REORIENT_TARGET;
+ if(setProperty == associationToRefactor.getMemberEnds().get(1)) {
+ direction = ReorientRelationshipRequest.REORIENT_SOURCE;
+ }
+ ReorientRelationshipRequest reorientRequest = new ReorientRelationshipRequest(relatedAssociation, (Type)request.getValue(), setProperty.eContainer(), direction);
+ reorientRequest.addParameters(request.getParameters());
+ IElementEditService provider = ElementEditServiceUtils.getCommandProvider(relatedAssociation);
+ if(provider != null) {
+ return provider.getEditCommand(reorientRequest);
+ }
+ }
+
+ return null;
+ }
+
+ /**
+ * Create a part association creation command.
+ *
+ * @return the part association creation command
+ */
+ private ICommand getCreatePartAssociationCommand(final org.eclipse.uml2.uml.Class sourceBlock, final Property sourceProperty, final org.eclipse.uml2.uml.Class targetBlock) {
+ return new AbstractCommand("Create part association") {
+
+ @Override
+ protected CommandResult doUndoWithResult(IProgressMonitor progressMonitor, IAdaptable info) throws ExecutionException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ protected CommandResult doRedoWithResult(IProgressMonitor progressMonitor, IAdaptable info) throws ExecutionException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ protected CommandResult doExecuteWithResult(IProgressMonitor progressMonitor, IAdaptable info) throws ExecutionException {
+ Association association = UMLFactory.eINSTANCE.createAssociation();
+ // Add the association in the model
+ org.eclipse.uml2.uml.Package container = (org.eclipse.uml2.uml.Package)EMFCoreUtil.getLeastCommonContainer(Arrays.asList(new EObject[]{ sourceBlock, targetBlock }), UMLPackage.eINSTANCE.getPackage());
+ container.getPackagedElements().add(association);
+ // Use existing Property as source...
+ association.getMemberEnds().add(sourceProperty);
+ // ... and create the opposite (unnamed) Property
+ Property targetProperty = UMLFactory.eINSTANCE.createProperty();
+ association.getOwnedEnds().add(targetProperty);
+
+ // Set Association name
+ // Initialize the element name based on the created IElementType
+ String initializedName = NamedElementHelper.getDefaultNameWithIncrementFromBase(UMLPackage.eINSTANCE.getAssociation().getName(), association.eContainer().eContents());
+ association.setName(initializedName);
+ // Add SysML Nature on the new Association
+ ElementUtil.addNature(association, SysMLElementTypes.SYSML_NATURE);
+ return CommandResult.newOKCommandResult(association);
+ }
+ };
+
+ }
+
+ /**
+ * Apply/remove the ConstraintProperty stereotype application
+ *
+ * @return the ConstraintProperty stereotype application command
+ */
+ private ICommand getConstraintPropertyStereotypeApplicationCommand(final Property sourceProperty, final org.eclipse.uml2.uml.Class targetBlock, final SetRequest request) {
+ return new AbstractTransactionalCommand(request.getEditingDomain(), "Apply/Remove ConstraintProperty Stereotype", null) {
+
+ @Override
+ protected CommandResult doExecuteWithResult(IProgressMonitor progressMonitor, IAdaptable info) throws ExecutionException {
+ // SysML specification : all property typed by a ConstraintBlock must have a ContraintProperty stereotype applied
+ ConstraintProperty constraintPropertyApplication = UMLUtil.getStereotypeApplication(sourceProperty, ConstraintProperty.class);
+ if(UMLUtil.getStereotypeApplication(targetBlock, ConstraintBlock.class) != null) {
+ if(constraintPropertyApplication == null) {
+ StereotypeApplicationHelper.INSTANCE.applyStereotype(sourceProperty, ConstraintsPackage.eINSTANCE.getConstraintProperty());
+ final String diagramType = null;
+ // Remove representations
+ Set<View> memberViewsToDestroy = CrossReferencerUtil.getCrossReferencingViews(sourceProperty, diagramType);
+ if(memberViewsToDestroy.size() != 0) {
+ final IPreferenceStore store = Activator.getDefault().getPreferenceStore();
+ final String DISPLAY_MESSAGE_FOR_TYPING_ACTION_PREFERENCE_KEY = "displayMessageForTypingActionPreferenceKey";
+ boolean contains = store.contains(DISPLAY_MESSAGE_FOR_TYPING_ACTION_PREFERENCE_KEY);
+ if(!contains) {
+ store.setValue(DISPLAY_MESSAGE_FOR_TYPING_ACTION_PREFERENCE_KEY, MessageDialogWithToggle.NEVER);
+ store.setDefault(DISPLAY_MESSAGE_FOR_TYPING_ACTION_PREFERENCE_KEY, MessageDialogWithToggle.NEVER);
+ }
+ final String hideValue = store.getString(DISPLAY_MESSAGE_FOR_TYPING_ACTION_PREFERENCE_KEY);
+ if(!hideValue.equals(MessageDialogWithToggle.ALWAYS)) {
+ int size = memberViewsToDestroy.size();
+ MessageDialogWithToggle.openInformation(Display.getDefault().getActiveShell(), "Change Type Action", "WARNING! Typing a Property by a ConstraintBlock make this property become a ConstraintProperty. ConstraintProperty have a specific representation. " + "\nSo all representations of this property will be removed from the model (" + size + " occurence" + ((size > 1) ? "s" : "") + ").", "Don't show this dialog the next time", false, store, DISPLAY_MESSAGE_FOR_TYPING_ACTION_PREFERENCE_KEY);
+ }
+ }
+ for(View view : memberViewsToDestroy) {
+ final DestroyElementRequest destroyRequest = new DestroyElementRequest(request.getEditingDomain(), view, false);
+ final IElementEditService commandProvider = ElementEditServiceUtils.getCommandProvider(view);
+ ICommand editCommand = commandProvider.getEditCommand(destroyRequest);
+ editCommand.execute(progressMonitor, info);
+ }
+ }
+ } else {
+ if(constraintPropertyApplication != null) {
+ StereotypeApplicationHelper.INSTANCE.removeFromContainmentList(sourceProperty, constraintPropertyApplication);
+ }
+ }
+ return CommandResult.newOKCommandResult(sourceProperty);
+ }
+ };
+ }
+
+ /**
+ * Create a part association destroy command.
+ *
+ * @return the part association destroy command
+ */
+ @SuppressWarnings("unchecked")
+ private ICommand getDestroyPartAssociationCommand(Association partAssociation, Property propertyToEdit) {
+ DestroyElementRequest request = new DestroyElementRequest(partAssociation, false);
+ List<EObject> dependentsToKeep = Arrays.asList(new EObject[]{ propertyToEdit });
+ request.getParameters().put(RequestParameterConstants.DEPENDENTS_TO_KEEP, dependentsToKeep);
+ IElementEditService provider = ElementEditServiceUtils.getCommandProvider(partAssociation.eContainer());
+ if(provider == null) {
+ return null;
+ }
+ ICommand destroyCommand = provider.getEditCommand(request);
+ return destroyCommand;
+ }
+}
diff --git a/plugins/sysml/org.eclipse.papyrus.sysml.service.types/src/org/eclipse/papyrus/sysml/service/types/utils/ConnectorUtils.java b/plugins/sysml/org.eclipse.papyrus.sysml.service.types/src/org/eclipse/papyrus/sysml/service/types/utils/ConnectorUtils.java
index d9d723e..4033a75 100644
--- a/plugins/sysml/org.eclipse.papyrus.sysml.service.types/src/org/eclipse/papyrus/sysml/service/types/utils/ConnectorUtils.java
+++ b/plugins/sysml/org.eclipse.papyrus.sysml.service.types/src/org/eclipse/papyrus/sysml/service/types/utils/ConnectorUtils.java
@@ -19,6 +19,7 @@ import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
+import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.gmf.runtime.notation.View;
import org.eclipse.papyrus.sysml.blocks.Block;
@@ -428,4 +429,33 @@ public class ConnectorUtils extends org.eclipse.papyrus.uml.service.types.utils.
}
return true;
}
+
+
+
+ /**
+ * Filter connectors that have this property in their <NestedConnectorEnd> property path.
+ * @param connectors
+ * @param part
+ * @return connectors that have this property in their <NestedConnectorEnd> property path.
+ */
+ public static List<Connector> filterConnectorByPropertyInNestedConnectorEnd(List<Connector> connectors, Property part) {
+ List<Connector> res = new ArrayList<Connector>();
+ for(Connector connector : connectors) {
+ EList<ConnectorEnd> ends = connector.getEnds();
+ for(ConnectorEnd connectorEnd : ends) {
+ NestedConnectorEnd stereotypeApplication = UMLUtil.getStereotypeApplication(connectorEnd, NestedConnectorEnd.class);
+ if (stereotypeApplication != null){
+ EList<Property> propertyPath = stereotypeApplication.getPropertyPath();
+ for(Property property : propertyPath) {
+ if (property.equals(part)){
+ res.add(connector);
+ }
+ }
+ }
+ }
+ }
+ return res;
+ }
+
+
}
diff --git a/plugins/sysml/org.eclipse.papyrus.sysml/src/org/eclipse/papyrus/sysml/util/SysmlResource.java b/plugins/sysml/org.eclipse.papyrus.sysml/src/org/eclipse/papyrus/sysml/util/SysmlResource.java
index b432ffa..b1d3bc8 100644
--- a/plugins/sysml/org.eclipse.papyrus.sysml/src/org/eclipse/papyrus/sysml/util/SysmlResource.java
+++ b/plugins/sysml/org.eclipse.papyrus.sysml/src/org/eclipse/papyrus/sysml/util/SysmlResource.java
@@ -1,213 +1,220 @@
-/*****************************************************************************
- * Copyright (c) 2009 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:
- * Yann Tanguy (CEA LIST) yann.tanguy@cea.fr - Initial API and implementation
- * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr
- *****************************************************************************/
-package org.eclipse.papyrus.sysml.util;
-
-import org.eclipse.papyrus.sysml.SysmlPackage;
-
-public class SysmlResource {
-
- public static final String LIBRARIES_PATHMAP = "pathmap://SysML_LIBRARIES/"; //$NON-NLS-1$
-
- public static final String SYSML_PRIMITIVE_TYPES_LIBRARY_URI = LIBRARIES_PATHMAP + "SysMLPrimitiveTypes.uml"; //$NON-NLS-1$
-
- public static final String PROFILES_PATHMAP = "pathmap://SysML_PROFILES/"; //$NON-NLS-1$
-
- public static final String SYSML_PROFILE_NS_URI = SysmlPackage.eNS_URI;
-
- public static final String SYSML_PROFILE_URI = PROFILES_PATHMAP + "SysML.profile.uml"; //$NON-NLS-1$
-
- // Stereotypes ids
- @Deprecated
- public static String CONFORM_ID = "SysML::ModelElements::Conform";
-
- @Deprecated
- public static String VIEW_ID = "SysML::ModelElements::View";
-
- @Deprecated
- public static String VIEW_POINT_ID = "SysML::ModelElements::ViewPoint";
-
- /**
- * @deprecated use VIEW_POINT_ID instead
- */
- public static String VIEWPOINT_ID = VIEW_POINT_ID;
-
- @Deprecated
- public static String RATIONALE_ID = "SysML::ModelElements::Rationale";
-
- @Deprecated
- public static String PROBLEM_ID = "SysML::ModelElements::Problem";
-
- @Deprecated
- public static String BLOCK_ID = "SysML::Blocks::Block";
-
- @Deprecated
- public static String DISTRIBUTED_PROPERTY_ID = "SysML::Blocks::DistributedProperty";
-
- @Deprecated
- public static String DIMENSION_ID = "SysML::Blocks::Dimension";
-
- @Deprecated
- public static String UNIT_ID = "SysML::Blocks::Unit";
-
- @Deprecated
- public static String VALUE_TYPE_ID = "SysML::Blocks::ValueType";
-
- @Deprecated
- public static String NESTED_CONNECTOR_END_ID = "SysML::Blocks::NestedConnectorEnd";
-
- /** @deprecated use NESTED_CONNECTOR_END_ID instead */
- public static String NESTED_CONNECTOREND_ID = NESTED_CONNECTOR_END_ID;
-
- @Deprecated
- public static String PARTICIPANT_PROPERTY_ID = "SysML::Blocks::ParticipantProperty";
-
- @Deprecated
- public static String CONNECTOR_PROPERTY_ID = "SysML::Blocks::ConnectorProperty";
-
- @Deprecated
- public static String BINDING_CONNECTOR_ID = "SysML::Blocks::BindingConnector";
-
- @Deprecated
- public static String PROPERTY_SPECIFIC_TYPE_ID = "SysML::Blocks::PropertySpecificType";
-
- @Deprecated
- public static String FLOW_PORT_ID = "SysML::PortAndFlows::FlowPort";
-
- @Deprecated
- public static String FLOW_PROPERTY_ID = "SysML::PortAndFlows::FlowProperty";
-
- @Deprecated
- public static String FLOW_SPECIFICATION_ID = "SysML::PortAndFlows::FlowSpecification";
-
- @Deprecated
- public static String ITEM_FLOW_ID = "SysML::PortAndFlows::ItemFlow";
-
- @Deprecated
- public static String CONSTRAINT_BLOCK_ID = "SysML::Constraints::ConstraintBlock";
-
- @Deprecated
- public static String CONSTRAINT_PROPERTY_ID = "SysML::Constraints::ConstraintProperty";
-
- @Deprecated
- public static String OPTIONAL_ID = "SysML::Activities::Optional";
-
- @Deprecated
- public static String RATE_ID = "SysML::Activities::Rate";
-
- @Deprecated
- public static String PROBABILITY_ID = "SysML::Activities::Probability";
-
- @Deprecated
- public static String CONTINUOUS_ID = "SysML::Activities::Continuous";
-
- @Deprecated
- public static String DISCRETE_ID = "SysML::Activities::Discrete";
-
- @Deprecated
- public static String CONTROL_OPERATOR_ID = "SysML::Activities::ControlOperator";
-
- @Deprecated
- public static String NO_BUFFER_ID = "SysML::Activities::NoBuffer";
-
- @Deprecated
- public static String OVERWRITE_ID = "SysML::Activities::Overwrite";
-
- @Deprecated
- public static String ALLOCATE_ID = "SysML::Allocations::Allocate";
-
- @Deprecated
- public static String ALLOCATED_ID = "SysML::Allocations::Allocated";
-
- @Deprecated
- public static String ALLOCATE_ACTIVITY_PARTITION_ID = "SysML::Allocations::AllocateActivityPartition";
-
- @Deprecated
- public static String DERIVE_REQT_ID = "SysML::Requirements::DeriveReqt";
-
- @Deprecated
- public static String VERIFY_ID = "SysML::Requirements::Verify";
-
- @Deprecated
- public static String COPY_ID = "SysML::Requirements::Copy";
-
- @Deprecated
- public static String SATISFY_ID = "SysML::Requirements::Satisfy";
-
- @Deprecated
- public static String TEST_CASE_ID = "SysML::Requirements::TestCase";
-
- @Deprecated
- public static String REQUIREMENT_ID = "SysML::Requirements::Requirement";
-
- @Deprecated
- public static String REQUIREMENT_RELATED_ID = "SysML::Requirements::RequirementRelated";
-
- // SubProfiles ids
- @Deprecated
- public static String SYSML_ID = "SysML";
-
- @Deprecated
- public static String MODEL_ELEMENTS_ID = "SysML::ModelElements";
-
- @Deprecated
- public static String BLOCKS_ID = "SysML::Blocks";
-
- @Deprecated
- public static String PORT_AND_FLOWS_ID = "SysML::PortAndFlows";
-
- @Deprecated
- public static String CONSTRAINTS_ID = "SysML::Constraints";
-
- @Deprecated
- public static String ACTIVITIES_ID = "SysML::Activities";
-
- @Deprecated
- public static String ALLOCATIONS_ID = "SysML::Allocations";
-
- @Deprecated
- public static String REQUIREMENTS_ID = "SysML::Requirements";
-
- // stereotype properties ids
- // requirements properties
- @Deprecated
- public static String REQUIREMENT_BASE_CLASS_ID = "base_Class"; //$NON-NLS-1$
-
- @Deprecated
- public static String REQUIREMENT_DERIVED_ID = "derived"; //$NON-NLS-1$
-
- @Deprecated
- public static String REQUIREMENT_DERIVED_FROM_ID = "derivedFrom";//$NON-NLS-1$
-
- @Deprecated
- public static String REQUIREMENT_ID_ID = "id";//$NON-NLS-1$
-
- @Deprecated
- public static String REQUIREMENT_MASTER_ID = "master";//$NON-NLS-1$
-
- @Deprecated
- public static String REQUIREMENT_REFINED_BY_ID = "refinedBy";//$NON-NLS-1$
-
- @Deprecated
- public static String REQUIREMENT_SATISFIED_BY_ID = "satisfiedBy";//$NON-NLS-1$
-
- @Deprecated
- public static String REQUIREMENT_TEXT_ID = "text";//$NON-NLS-1$
-
- @Deprecated
- public static String REQUIREMENT_TRACED_TO_ID = "tracedTo";//$NON-NLS-1$
-
- @Deprecated
- public static String REQUIREMENT_VERIFIED_BY_ID = "verifiedBy";//$NON-NLS-1$
-
-}
+/*****************************************************************************
+ * Copyright (c) 2009 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:
+ * Yann Tanguy (CEA LIST) yann.tanguy@cea.fr - Initial API and implementation
+ * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr
+ *****************************************************************************/
+package org.eclipse.papyrus.sysml.util;
+
+import org.eclipse.papyrus.sysml.SysmlPackage;
+
+/**
+ * For all deprecated : use org.eclipse.uml2.uml.util.UMLUtil.getStereotypeApplication
+ * Ex :
+ * replace appliedStereotype = connectorEnd.getAppliedStereotype("SysML::Blocks::NestedConnectorEnd");connectorEnd.getStereotypeApplication(appliedStereotype);
+ * by org.eclipse.uml2.uml.util.UMLUtil.getStereotypeApplication(element, NestedConnectorEnd.class);
+ */
+public class SysmlResource {
+
+ public static final String LIBRARIES_PATHMAP = "pathmap://SysML_LIBRARIES/"; //$NON-NLS-1$
+
+ public static final String SYSML_PRIMITIVE_TYPES_LIBRARY_URI = LIBRARIES_PATHMAP + "SysMLPrimitiveTypes.uml"; //$NON-NLS-1$
+
+ public static final String PROFILES_PATHMAP = "pathmap://SysML_PROFILES/"; //$NON-NLS-1$
+
+ public static final String SYSML_PROFILE_NS_URI = SysmlPackage.eNS_URI;
+
+ public static final String SYSML_PROFILE_URI = PROFILES_PATHMAP + "SysML.profile.uml"; //$NON-NLS-1$
+
+
+ // Stereotypes ids
+ @Deprecated
+ public static String CONFORM_ID = "SysML::ModelElements::Conform";
+
+ @Deprecated
+ public static String VIEW_ID = "SysML::ModelElements::View";
+
+ @Deprecated
+ public static String VIEW_POINT_ID = "SysML::ModelElements::ViewPoint";
+
+ /**
+ * @deprecated use VIEW_POINT_ID instead
+ */
+ public static String VIEWPOINT_ID = VIEW_POINT_ID;
+
+ @Deprecated
+ public static String RATIONALE_ID = "SysML::ModelElements::Rationale";
+
+ @Deprecated
+ public static String PROBLEM_ID = "SysML::ModelElements::Problem";
+
+ @Deprecated
+ public static String BLOCK_ID = "SysML::Blocks::Block";
+
+ @Deprecated
+ public static String DISTRIBUTED_PROPERTY_ID = "SysML::Blocks::DistributedProperty";
+
+ @Deprecated
+ public static String DIMENSION_ID = "SysML::Blocks::Dimension";
+
+ @Deprecated
+ public static String UNIT_ID = "SysML::Blocks::Unit";
+
+ @Deprecated
+ public static String VALUE_TYPE_ID = "SysML::Blocks::ValueType";
+
+ @Deprecated
+ public static String NESTED_CONNECTOR_END_ID = "SysML::Blocks::NestedConnectorEnd";
+
+ /** @deprecated use NESTED_CONNECTOR_END_ID instead */
+ public static String NESTED_CONNECTOREND_ID = NESTED_CONNECTOR_END_ID;
+
+ @Deprecated
+ public static String PARTICIPANT_PROPERTY_ID = "SysML::Blocks::ParticipantProperty";
+
+ @Deprecated
+ public static String CONNECTOR_PROPERTY_ID = "SysML::Blocks::ConnectorProperty";
+
+ @Deprecated
+ public static String BINDING_CONNECTOR_ID = "SysML::Blocks::BindingConnector";
+
+ @Deprecated
+ public static String PROPERTY_SPECIFIC_TYPE_ID = "SysML::Blocks::PropertySpecificType";
+
+ @Deprecated
+ public static String FLOW_PORT_ID = "SysML::PortAndFlows::FlowPort";
+
+ @Deprecated
+ public static String FLOW_PROPERTY_ID = "SysML::PortAndFlows::FlowProperty";
+
+ @Deprecated
+ public static String FLOW_SPECIFICATION_ID = "SysML::PortAndFlows::FlowSpecification";
+
+ @Deprecated
+ public static String ITEM_FLOW_ID = "SysML::PortAndFlows::ItemFlow";
+
+ @Deprecated
+ public static String CONSTRAINT_BLOCK_ID = "SysML::Constraints::ConstraintBlock";
+
+ @Deprecated
+ public static String CONSTRAINT_PROPERTY_ID = "SysML::Constraints::ConstraintProperty";
+
+ @Deprecated
+ public static String OPTIONAL_ID = "SysML::Activities::Optional";
+
+ @Deprecated
+ public static String RATE_ID = "SysML::Activities::Rate";
+
+ @Deprecated
+ public static String PROBABILITY_ID = "SysML::Activities::Probability";
+
+ @Deprecated
+ public static String CONTINUOUS_ID = "SysML::Activities::Continuous";
+
+ @Deprecated
+ public static String DISCRETE_ID = "SysML::Activities::Discrete";
+
+ @Deprecated
+ public static String CONTROL_OPERATOR_ID = "SysML::Activities::ControlOperator";
+
+ @Deprecated
+ public static String NO_BUFFER_ID = "SysML::Activities::NoBuffer";
+
+ @Deprecated
+ public static String OVERWRITE_ID = "SysML::Activities::Overwrite";
+
+ @Deprecated
+ public static String ALLOCATE_ID = "SysML::Allocations::Allocate";
+
+ @Deprecated
+ public static String ALLOCATED_ID = "SysML::Allocations::Allocated";
+
+ @Deprecated
+ public static String ALLOCATE_ACTIVITY_PARTITION_ID = "SysML::Allocations::AllocateActivityPartition";
+
+ @Deprecated
+ public static String DERIVE_REQT_ID = "SysML::Requirements::DeriveReqt";
+
+ @Deprecated
+ public static String VERIFY_ID = "SysML::Requirements::Verify";
+
+ @Deprecated
+ public static String COPY_ID = "SysML::Requirements::Copy";
+
+ @Deprecated
+ public static String SATISFY_ID = "SysML::Requirements::Satisfy";
+
+ @Deprecated
+ public static String TEST_CASE_ID = "SysML::Requirements::TestCase";
+
+ @Deprecated
+ public static String REQUIREMENT_ID = "SysML::Requirements::Requirement";
+
+ @Deprecated
+ public static String REQUIREMENT_RELATED_ID = "SysML::Requirements::RequirementRelated";
+
+ // SubProfiles ids
+ @Deprecated
+ public static String SYSML_ID = "SysML";
+
+ @Deprecated
+ public static String MODEL_ELEMENTS_ID = "SysML::ModelElements";
+
+ @Deprecated
+ public static String BLOCKS_ID = "SysML::Blocks";
+
+ @Deprecated
+ public static String PORT_AND_FLOWS_ID = "SysML::PortAndFlows";
+
+ @Deprecated
+ public static String CONSTRAINTS_ID = "SysML::Constraints";
+
+ @Deprecated
+ public static String ACTIVITIES_ID = "SysML::Activities";
+
+ @Deprecated
+ public static String ALLOCATIONS_ID = "SysML::Allocations";
+
+ @Deprecated
+ public static String REQUIREMENTS_ID = "SysML::Requirements";
+
+ // stereotype properties ids
+ // requirements properties
+ @Deprecated
+ public static String REQUIREMENT_BASE_CLASS_ID = "base_Class"; //$NON-NLS-1$
+
+ @Deprecated
+ public static String REQUIREMENT_DERIVED_ID = "derived"; //$NON-NLS-1$
+
+ @Deprecated
+ public static String REQUIREMENT_DERIVED_FROM_ID = "derivedFrom";//$NON-NLS-1$
+
+ @Deprecated
+ public static String REQUIREMENT_ID_ID = "id";//$NON-NLS-1$
+
+ @Deprecated
+ public static String REQUIREMENT_MASTER_ID = "master";//$NON-NLS-1$
+
+ @Deprecated
+ public static String REQUIREMENT_REFINED_BY_ID = "refinedBy";//$NON-NLS-1$
+
+ @Deprecated
+ public static String REQUIREMENT_SATISFIED_BY_ID = "satisfiedBy";//$NON-NLS-1$
+
+ @Deprecated
+ public static String REQUIREMENT_TEXT_ID = "text";//$NON-NLS-1$
+
+ @Deprecated
+ public static String REQUIREMENT_TRACED_TO_ID = "tracedTo";//$NON-NLS-1$
+
+ @Deprecated
+ public static String REQUIREMENT_VERIFIED_BY_ID = "verifiedBy";//$NON-NLS-1$
+
+}
diff --git a/plugins/uml/tools/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/ElementUtil.java b/plugins/uml/tools/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/ElementUtil.java
index f2d1719..80546c1 100644
--- a/plugins/uml/tools/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/ElementUtil.java
+++ b/plugins/uml/tools/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/ElementUtil.java
@@ -30,6 +30,7 @@ import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.uml2.uml.Element;
import org.eclipse.uml2.uml.ElementImport;
import org.eclipse.uml2.uml.Image;
+import org.eclipse.uml2.uml.Model;
import org.eclipse.uml2.uml.Package;
import org.eclipse.uml2.uml.PackageImport;
import org.eclipse.uml2.uml.Stereotype;
@@ -302,28 +303,58 @@ public class ElementUtil {
}
/**
- * Retrieve an list of all instances in the model that are instances of
- * the java.lang.Class metaType or with a stereotype applied
- *
- * @param <T>
+ * Retrieve an list of all instances in the Package that are instances of
+ * the java.lang.Class metaType OR with a stereotype applied
*
+ * @param topPackage
+ *
* @param metaType
- * selected classes
- * @param model
- * to check
+ * selected classes
* @param appliedStereotype
- * may be null, metatype is ignored if not null
+ * may be null, metatype is ignored if not null
* @return a list containing the selected instances
*/
- //duplicated code from /org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/util/Util.java
- //+add template to this method
- @SuppressWarnings("unchecked")
+
public static final <T extends EObject> List<T> getInstancesFilteredByType(final Package topPackage, final java.lang.Class<T> metaType, final Stereotype appliedStereotype) {
// retrieve parent element
// Package topPackage = Util.topPackage(element);
// Assert.isNotNull(topPackage,
// "Top package should not be null for element " + element);
- Iterator<EObject> iter = topPackage.eAllContents();
+ return getInstancesFilteredByType(topPackage.eAllContents(), metaType, appliedStereotype );
+ }
+
+ /**
+ * Retrieve an list of all instances in the Model that are instances of
+ * the java.lang.Class metaType OR with a stereotype applied
+ *
+ * @param topPackage
+ *
+ * @param metaType
+ * selected classes
+ * @param appliedStereotype
+ * may be null, metatype is ignored if not null
+ * @return a list containing the selected instances
+ */
+ public static final <T extends EObject> List<T> getInstancesFilteredByType(final Model model, final java.lang.Class<T> metaType, final Stereotype appliedStereotype) {
+ return getInstancesFilteredByType(model.eAllContents(), metaType, appliedStereotype );
+ }
+
+ /**
+ * Retrieve an list of all instances that are instances of
+ * the java.lang.Class metaType OR with a stereotype applied
+ *
+ * @param iter
+ * iterator on all the instances
+ * @param metaType
+ * selected classes
+ * @param appliedStereotype
+ * may be null, metatype is ignored if not null
+ * @return a list containing the selected instances
+ */
+ //duplicated code from /org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/util/Util.java
+ //+add template to this method
+ @SuppressWarnings("unchecked")
+ private static <T extends EObject> List<T> getInstancesFilteredByType(Iterator<EObject> iter, final java.lang.Class<T> metaType, final Stereotype appliedStereotype ) {
List<T> filteredElements = new ArrayList<T>();
while(iter.hasNext()) {
@@ -406,6 +437,6 @@ public class ElementUtil {
}
return filteredElements;
- }
+ }
}