Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVincent Lorenzo2014-04-03 05:30:13 -0400
committerVincent Lorenzo2014-04-03 05:30:13 -0400
commitcc50dbf1ba45ce0d4edf4bb54581774654fc8ca3 (patch)
tree37a3ef3e8d700d061ad8a2ba59e5381814d68e80
parent8c20759b3aae56fcf78c5c39310355b2e0b98d4b (diff)
downloadorg.eclipse.papyrus-cc50dbf1ba45ce0d4edf4bb54581774654fc8ca3.tar.gz
org.eclipse.papyrus-cc50dbf1ba45ce0d4edf4bb54581774654fc8ca3.tar.xz
org.eclipse.papyrus-cc50dbf1ba45ce0d4edf4bb54581774654fc8ca3.zip
431691: [Table 2] Paste from Spreadsheet must be able to apply required stereotypes for column properties in all usecases
https://bugs.eclipse.org/bugs/show_bug.cgi?id=431691 Apply the stereotypes required by columns representing stereotypes properties even if no post actions are defined AND even if the element id doesn't require stereotype
-rw-r--r--plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/provider/PasteEObjectAxisInNattableCommandProvider.java13
-rw-r--r--plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/utils/Constants.java12
-rw-r--r--plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/src/org/eclipse/papyrus/uml/nattable/manager/cell/StereotypePropertyCellManager.java70
-rw-r--r--plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/src/org/eclipse/papyrus/uml/nattable/utils/UMLTableUtils.java28
-rw-r--r--plugins/uml/tools/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/CustomElementOperations.java16
5 files changed, 126 insertions, 13 deletions
diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/provider/PasteEObjectAxisInNattableCommandProvider.java b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/provider/PasteEObjectAxisInNattableCommandProvider.java
index 8def89fed89..4c29552fa06 100644
--- a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/provider/PasteEObjectAxisInNattableCommandProvider.java
+++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/provider/PasteEObjectAxisInNattableCommandProvider.java
@@ -273,6 +273,11 @@ public class PasteEObjectAxisInNattableCommandProvider {
sharedMap.put(Constants.PASTED_ELEMENT_CONTAINER_KEY, tableContext);
sharedMap.put(Constants.REFERENCES_TO_SET_KEY, new ArrayList<IValueSetter>());
sharedMap.put(Constants.CELLS_TO_ADD_KEY, new ArrayList<Cell>());
+
+ //used to be able to apply stereotypes required by columns properties, in detached mode even if there is no post actions defined in the table configuration
+ //see bug 431691: [Table 2] Paste from Spreadsheet must be able to apply required stereotypes for column properties in all usecases
+ //https://bugs.eclipse.org/bugs/show_bug.cgi?id=431691
+ sharedMap.put(Constants.ADDITIONAL_POST_ACTIONS_TO_CONCLUDE_PASTE_KEY, new ArrayList<String>());
if(!useProgressMonitor) {
final ICommand pasteCommand = getPasteFromStringCommandInDetachedMode(contextEditingDomain, tableEditingDomain, new NullProgressMonitor(), sharedMap);
@@ -442,6 +447,14 @@ public class PasteEObjectAxisInNattableCommandProvider {
protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
//initialize lists
final Collection<String> postActions = getPostActions();
+
+ //we add the post actions added by cell manager
+ //see bug 431691: [Table 2] Paste from Spreadsheet must be able to apply required stereotypes for column properties in all usecases
+ //https://bugs.eclipse.org/bugs/show_bug.cgi?id=431691
+ @SuppressWarnings("unchecked")
+ final Collection<String> postActionsAddedByCellManagers = (Collection<String>)sharedMap.get(Constants.ADDITIONAL_POST_ACTIONS_TO_CONCLUDE_PASTE_KEY);
+ postActions.addAll(postActionsAddedByCellManagers);
+
@SuppressWarnings("unchecked")
final List<Cell> cells = (List<Cell>)sharedMap.get(Constants.CELLS_TO_ADD_KEY);
@SuppressWarnings("unchecked")
diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/utils/Constants.java b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/utils/Constants.java
index 16ca7e7c874..ccc528dbd0e 100644
--- a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/utils/Constants.java
+++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/utils/Constants.java
@@ -69,9 +69,21 @@ public class Constants {
* the key used to store the references to set after to have attached the pasted element to the model
*/
public static final String REFERENCES_TO_SET_KEY = "referencesToSet";
+
+ /**
+ * the key used to register additional post actions to conclude the paste. the returned value must be a Collection<String>
+ * These post actions have been executed by CellManager, but they must be concluded.
+ * These post actions are not defined in the configuration of the table, but added by CellManager
+ *
+ * This key is used to be able to apply stereotype required by columns properties, when there are no post actions defined
+ * in the paste configuration of the table
+ * see bug 431691: [Table 2] Paste from Spreadsheet must be able to apply required stereotypes for column properties in all usecases
+ */
+ public static final String ADDITIONAL_POST_ACTIONS_TO_CONCLUDE_PASTE_KEY = "additionnal_post_actions_to_conclude_paste";
/**
* the key used to store the cells to attached to the model
*/
public static final String CELLS_TO_ADD_KEY = "cellsToAdd";
+
}
diff --git a/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/src/org/eclipse/papyrus/uml/nattable/manager/cell/StereotypePropertyCellManager.java b/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/src/org/eclipse/papyrus/uml/nattable/manager/cell/StereotypePropertyCellManager.java
index a7279a39c2b..05391d17b1e 100644
--- a/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/src/org/eclipse/papyrus/uml/nattable/manager/cell/StereotypePropertyCellManager.java
+++ b/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/src/org/eclipse/papyrus/uml/nattable/manager/cell/StereotypePropertyCellManager.java
@@ -37,6 +37,7 @@ import org.eclipse.papyrus.infra.nattable.manager.table.INattableModelManager;
import org.eclipse.papyrus.infra.nattable.model.nattable.nattablecell.Cell;
import org.eclipse.papyrus.infra.nattable.model.nattable.nattableproblem.Problem;
import org.eclipse.papyrus.infra.nattable.model.nattable.nattableproblem.StringResolutionProblem;
+import org.eclipse.papyrus.infra.nattable.paste.PastePostActionRegistry;
import org.eclipse.papyrus.infra.nattable.utils.AxisUtils;
import org.eclipse.papyrus.infra.services.edit.service.ElementEditServiceUtils;
import org.eclipse.papyrus.infra.services.edit.service.IElementEditService;
@@ -50,10 +51,12 @@ import org.eclipse.papyrus.uml.nattable.paste.StereotypeApplicationStructure;
import org.eclipse.papyrus.uml.nattable.utils.Constants;
import org.eclipse.papyrus.uml.nattable.utils.UMLTableUtils;
import org.eclipse.papyrus.uml.tools.commands.ApplyStereotypeCommand;
+import org.eclipse.papyrus.uml.tools.utils.CustomElementOperations;
import org.eclipse.papyrus.uml.tools.utils.EnumerationUtil;
import org.eclipse.uml2.uml.Element;
import org.eclipse.uml2.uml.Enumeration;
import org.eclipse.uml2.uml.EnumerationLiteral;
+import org.eclipse.uml2.uml.NamedElement;
import org.eclipse.uml2.uml.PrimitiveType;
import org.eclipse.uml2.uml.Property;
import org.eclipse.uml2.uml.Stereotype;
@@ -165,7 +168,15 @@ public class StereotypePropertyCellManager extends UMLFeatureCellManager {
}
}
-
+ /**
+ *
+ * @see org.eclipse.papyrus.infra.nattable.manager.cell.AbstractCellManager#isCellEditable(java.lang.Object, java.lang.Object, java.util.Map)
+ *
+ * @param columnElement
+ * @param rowElement
+ * @param sharedMap
+ * @return
+ */
@Override
public boolean isCellEditable(final Object columnElement, final Object rowElement, final Map<?, ?> sharedMap) {
final List<Object> umlObjects = organizeAndResolvedObjects(columnElement, rowElement, sharedMap);
@@ -173,12 +184,27 @@ public class StereotypePropertyCellManager extends UMLFeatureCellManager {
final String id = (String)umlObjects.get(1);
switch(UMLTableUtils.getAppliedStereotypesWithThisProperty(el, id, sharedMap).size()) {
+ case 0:
+ //the element is not yet in the resource, and the stereotype required by a column is not yet applied
+ //see bug 431691: [Table 2] Paste from Spreadsheet must be able to apply required stereotypes for column properties in all usecases
+ //https://bugs.eclipse.org/bugs/show_bug.cgi?id=431691
+ final Object container = sharedMap.get(org.eclipse.papyrus.infra.nattable.utils.Constants.PASTED_ELEMENT_CONTAINER_KEY);
+ if(container instanceof Element) {
+ Element parent = (Element)container;
+ Property prop1 = UMLTableUtils.getRealStereotypeProperty(parent, id);
+ if(prop1 != null && prop1.getOwner() instanceof Stereotype) {
+ return CustomElementOperations.isStereotypeApplicable(parent, el, (Stereotype)prop1.eContainer());
+ }
+ }
+ break;
+
case 1:
final Property prop = UMLTableUtils.getRealStereotypeProperty(el, id, sharedMap);
return !prop.isDerived() && !prop.isReadOnly();
default:
return false;
}
+ return false;
}
/**
@@ -363,13 +389,55 @@ public class StereotypePropertyCellManager extends UMLFeatureCellManager {
return new GMFtoEMFCommandWrapper(cmd);
}
+ /**
+ * This method is used when we are pasting elements in detached mode
+ *
+ * @param columnElement
+ * the column element
+ * @param rowElement
+ * the row element
+ * @param valueAsString
+ * the value as string
+ * @param valueConverter
+ * the value converter to use
+ * @param tableManager
+ * the table manager
+ * @param sharedMap
+ * a map with shared elements. The method may read/add elements to the shared map. These contributions will be managed by a paste post
+ * action or by the paste manager itself
+ */
@Override
public void setStringValue(Object columnElement, Object rowElement, String valueAsString, AbstractStringValueConverter valueSolver, INattableModelManager tableManager, Map<?, ?> sharedMap) {
+ if(valueAsString ==null || valueAsString.isEmpty()){
+ return;
+ }
final List<Object> umlObjects = organizeAndResolvedObjects(columnElement, rowElement, sharedMap);
final Element el = (Element)umlObjects.get(0);
final String id = (String)umlObjects.get(1);
Property prop = UMLTableUtils.getRealStereotypeProperty(el, id, sharedMap);
List<Stereotype> stereotypes = UMLTableUtils.getAppliedStereotypesWithThisProperty(el, id, sharedMap);
+
+ if(stereotypes.size() == 0) {
+ Object parentElement = sharedMap.get(org.eclipse.papyrus.infra.nattable.utils.Constants.PASTED_ELEMENT_CONTAINER_KEY);
+ final Element element = prop.getOwner();
+ if(element instanceof Stereotype && parentElement instanceof Element) {
+ boolean isApplicable = CustomElementOperations.isStereotypeApplicable(((Element)parentElement).getNearestPackage(), el, (Stereotype)element);
+ if(isApplicable) {
+ //apply stereotype required by the column property using post actions mecanism
+ final String postActionId = Constants.POST_ACTION_APPLY_STEREOTYPE_PREFIX + ((NamedElement)element).getQualifiedName();
+
+ //we register a special post actions to conclude the stereotype application
+ @SuppressWarnings("unchecked")
+ final Collection<String> postActionIds = (Collection<String>)sharedMap.get(org.eclipse.papyrus.infra.nattable.utils.Constants.ADDITIONAL_POST_ACTIONS_TO_CONCLUDE_PASTE_KEY);
+ postActionIds.add(postActionId);
+ //we do the post action : we apply the streotype
+ PastePostActionRegistry.INSTANCE.doPostAction(tableManager, postActionId, (EObject)parentElement, el, (Map<Object, Object>)sharedMap, id);
+ stereotypes = UMLTableUtils.getAppliedStereotypesWithThisProperty(el, id, sharedMap);
+ }
+ }
+ }
+
+
ConvertedValueContainer<?> solvedValue = null;
EObject stereotypeApplication = null;
EStructuralFeature steApFeature = null;
diff --git a/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/src/org/eclipse/papyrus/uml/nattable/utils/UMLTableUtils.java b/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/src/org/eclipse/papyrus/uml/nattable/utils/UMLTableUtils.java
index 946701bce32..c6aaa80b212 100644
--- a/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/src/org/eclipse/papyrus/uml/nattable/utils/UMLTableUtils.java
+++ b/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/src/org/eclipse/papyrus/uml/nattable/utils/UMLTableUtils.java
@@ -55,15 +55,17 @@ public class UMLTableUtils {
assert id.startsWith(PROPERTY_OF_STEREOTYPE_PREFIX);
if(eobject instanceof Element) {
final Element element = (Element)eobject;
- final String propertyQN = id.replace(UMLTableUtils.PROPERTY_OF_STEREOTYPE_PREFIX, ""); //$NON-NLS-1$
- final String propertyName = NamedElementUtil.getNameFromQualifiedName(propertyQN);
- final String stereotypeQN = NamedElementUtil.getParentQualifiedName(propertyQN);
- final String stereotypeName = NamedElementUtil.getNameFromQualifiedName(stereotypeQN);
- final String profileQN = NamedElementUtil.getParentQualifiedName(stereotypeQN);
- final Profile profile = element.getNearestPackage().getAppliedProfile(profileQN, true);
- if(profile != null) {
- final Stereotype ste = profile.getOwnedStereotype(stereotypeName);
- return (Property)ste.getMember(propertyName);
+ if(element.getNearestPackage() != null) {
+ final String propertyQN = id.replace(UMLTableUtils.PROPERTY_OF_STEREOTYPE_PREFIX, ""); //$NON-NLS-1$
+ final String propertyName = NamedElementUtil.getNameFromQualifiedName(propertyQN);
+ final String stereotypeQN = NamedElementUtil.getParentQualifiedName(propertyQN);
+ final String stereotypeName = NamedElementUtil.getNameFromQualifiedName(stereotypeQN);
+ final String profileQN = NamedElementUtil.getParentQualifiedName(stereotypeQN);
+ final Profile profile = element.getNearestPackage().getAppliedProfile(profileQN, true);
+ if(profile != null) {
+ final Stereotype ste = profile.getOwnedStereotype(stereotypeName);
+ return (Property)ste.getMember(propertyName);
+ }
}
}
@@ -182,8 +184,10 @@ public class UMLTableUtils {
final List<Stereotype> stereotypes = new ArrayList<Stereotype>();
if(sharedMap != null) {
final List<StereotypeApplicationStructure> struct = findStereotypeApplicationDataStructure(element, id, sharedMap);
- for(final StereotypeApplicationStructure current : struct) {
- stereotypes.add(current.getStereotype());
+ if(struct != null) {
+ for(final StereotypeApplicationStructure current : struct) {
+ stereotypes.add(current.getStereotype());
+ }
}
}
if(element.eResource() != null) {
@@ -209,7 +213,7 @@ public class UMLTableUtils {
* a map owning interesting information, like {@link StereotypeApplicationStructure} which can be used to find stereotype, stereotype
* application and so on
* @return
- * the list of the found data structure
+ * the list of the found data structure or <code>null</code> if not found
*/
public static final List<StereotypeApplicationStructure> findStereotypeApplicationDataStructure(final Element editedElement, final String id, final Map<?, ?> sharedMap) {
//TODO : enhance the data structure to look for an editedElement + a propQn as Key!
diff --git a/plugins/uml/tools/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/CustomElementOperations.java b/plugins/uml/tools/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/CustomElementOperations.java
index 50a0b37ed7b..6dd84e2b478 100644
--- a/plugins/uml/tools/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/CustomElementOperations.java
+++ b/plugins/uml/tools/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/CustomElementOperations.java
@@ -55,6 +55,22 @@ public class CustomElementOperations extends ElementOperations {
/**
*
+ * @param parentElement
+ * the parent of the element (required because the element is probably to yet attached to its parent
+ * @param element
+ * the element on which we want apply a stereotype
+ * @param stereotype
+ * the stereotype to apply
+ * @return
+ * <code>true</code> if the stereotype can be applied on this element
+ */
+ public static boolean isStereotypeApplicable(final Element parentElement, Element element, Stereotype stereotype) {
+ return getDefinition(parentElement, stereotype) != null && getExtension(element, stereotype) != null;
+
+ }
+
+ /**
+ *
* @param element
* @param stereotype
* @return

Back to the top