Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVincent Lorenzo2018-06-07 13:31:18 +0000
committerPatrick Tessier2019-01-21 09:45:33 +0000
commite1ba57872dafc3aec4ae4e0c453dedba61e05adb (patch)
treee99ce4c8e1ecd8881f675e507a0ce387e781adb7
parentc696b02ef658c459be448dc6eef043f4e0fcb59a (diff)
downloadorg.eclipse.papyrus-e1ba57872dafc3aec4ae4e0c453dedba61e05adb.tar.gz
org.eclipse.papyrus-e1ba57872dafc3aec4ae4e0c453dedba61e05adb.tar.xz
org.eclipse.papyrus-e1ba57872dafc3aec4ae4e0c453dedba61e05adb.zip
Bug 535653: [Table][Richtext] Referencing a UML Element using the richtext editor doesn't work when the edited feature is a stereotype property
Change-Id: I5d9c90eb1bff21899a227e8598f128dd2ac34cc9 Signed-off-by: Vincent Lorenzo <vincent.lorenzo@cea.fr>
-rw-r--r--plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.richtext/src/org/eclipse/papyrus/uml/nattable/richtext/celleditor/RichTextCellEditorWithUMLReferences.java113
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.ui/src/org/eclipse/papyrus/uml/ui/editors/UMLRichtextEditorWithReferences.java18
2 files changed, 95 insertions, 36 deletions
diff --git a/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.richtext/src/org/eclipse/papyrus/uml/nattable/richtext/celleditor/RichTextCellEditorWithUMLReferences.java b/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.richtext/src/org/eclipse/papyrus/uml/nattable/richtext/celleditor/RichTextCellEditorWithUMLReferences.java
index 9ceb2a55e5b..4a983acb886 100644
--- a/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.richtext/src/org/eclipse/papyrus/uml/nattable/richtext/celleditor/RichTextCellEditorWithUMLReferences.java
+++ b/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.richtext/src/org/eclipse/papyrus/uml/nattable/richtext/celleditor/RichTextCellEditorWithUMLReferences.java
@@ -1,5 +1,5 @@
/*****************************************************************************
- * Copyright (c) 2016 CEA LIST and others.
+ * Copyright (c) 2016, 2018 CEA LIST and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -10,11 +10,15 @@
*
* Contributors:
* CEA LIST - Initial API and implementation
- *
+ * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Bug 535055
*****************************************************************************/
package org.eclipse.papyrus.uml.nattable.richtext.celleditor;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.nebula.widgets.nattable.extension.nebula.richtext.RichTextCellEditor;
import org.eclipse.nebula.widgets.nattable.style.DisplayMode;
@@ -23,6 +27,7 @@ import org.eclipse.papyrus.infra.nattable.manager.table.INattableModelManager;
import org.eclipse.papyrus.infra.nattable.utils.AxisUtils;
import org.eclipse.papyrus.infra.nattable.utils.NattableConfigAttributes;
import org.eclipse.papyrus.infra.widgets.editors.richtext.GenericRichTextEditor;
+import org.eclipse.papyrus.uml.nattable.utils.UMLTableUtils;
import org.eclipse.papyrus.uml.ui.editors.UMLRichtextEditorWithReferences;
import org.eclipse.papyrus.uml.ui.editors.UMLToolbarConfiguration;
import org.eclipse.swt.SWT;
@@ -30,6 +35,8 @@ import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.uml2.uml.Element;
+import org.eclipse.uml2.uml.Property;
+import org.eclipse.uml2.uml.Stereotype;
/**
* @author Vincent Lorenzo
@@ -111,32 +118,79 @@ public class RichTextCellEditorWithUMLReferences extends RichTextCellEditor {
Control ctrl = super.activateCell(parent, originalCanonicalValue);
if (this.editor instanceof GenericRichTextEditor) {
- Element editedElement = getEditedElement();
- EStructuralFeature editedFeature = getEditedFeature();
- if (editedElement != null && editedFeature != null) {
- ((GenericRichTextEditor) this.editor).configureEdition(editedElement, editedFeature);
+ final List<Object> objects = organizeEditedObjectAndFeature();
+ if (null != objects && 2 == objects.size()) {
+ final EObject realEditedObject = (EObject) objects.get(0);
+ final EStructuralFeature realFeature = (EStructuralFeature) objects.get(1);
+ ((GenericRichTextEditor) this.editor).configureEdition(realEditedObject, realFeature);
}
}
return ctrl;
}
/**
+ *
* @return
- * the edited feature
+ * <code>null</code> or a list containing 2 elements when we found them. The first one is the edited eobject and the second one is the edited feature of the first one.
*/
- protected EStructuralFeature getEditedFeature() {
+ private List<Object> organizeEditedObjectAndFeature() {
final INattableModelManager manager = this.configRegistry.getConfigAttribute(NattableConfigAttributes.NATTABLE_MODEL_MANAGER_CONFIG_ATTRIBUTE, DisplayMode.NORMAL, NattableConfigAttributes.NATTABLE_MODEL_MANAGER_ID);
- Object columnObject = AxisUtils.getRepresentedElement(manager.getColumnElement(getColumnIndex()));
- EStructuralFeature editedFeature = null;
- if (columnObject instanceof EStructuralFeature) {
- editedFeature = (EStructuralFeature) columnObject;
+ int columnIndex = this.layerCell.getColumnIndex();
+ int rowIndex = this.layerCell.getRowIndex();
+ Object row = manager.getRowElement(rowIndex);
+ Object column = manager.getColumnElement(columnIndex);
+ row = AxisUtils.getRepresentedElement(row);
+ column = AxisUtils.getRepresentedElement(column);
+
+ Element editedElement = null;
+ Object feature = null;
+
+ if (row instanceof EObject && (column instanceof EStructuralFeature || column instanceof String)) {
+ editedElement = (Element) row;
+ feature = column;
+ } else if (column instanceof EObject && (row instanceof EStructuralFeature || row instanceof String)) {
+ editedElement = (Element) column;
+ feature = row;
} else {
- Object rowObject = AxisUtils.getRepresentedElement(manager.getRowElement(getRowIndex()));
- if (rowObject instanceof EStructuralFeature) {
- editedFeature = (EStructuralFeature) rowObject;
+ return null;
+ }
+
+
+ EStructuralFeature realFeature = null;
+ EObject realEditedObject = null;
+ if (feature instanceof EStructuralFeature) {
+ realFeature = (EStructuralFeature) feature;
+ realEditedObject = editedElement;
+ } else if (feature instanceof String) {
+ final String id = AxisUtils.getPropertyId(feature);
+ final List<Stereotype> stereotypesWithEditedFeatureAppliedOnElement = UMLTableUtils.getAppliedStereotypesWithThisProperty(editedElement, id);
+ if (1 == stereotypesWithEditedFeatureAppliedOnElement.size()) {
+ realEditedObject = editedElement.getStereotypeApplication(stereotypesWithEditedFeatureAppliedOnElement.get(0));
+ final Property prop = UMLTableUtils.getRealStereotypeProperty(editedElement, id);
+ if (null != prop.getName()) {
+ realFeature = realEditedObject.eClass().getEStructuralFeature(prop.getName());
+ }
}
}
- return editedFeature;
+ if (null != realEditedObject && null != realFeature) {
+ final List<Object> returnedValue = new ArrayList<Object>();
+ returnedValue.add(realEditedObject);
+ returnedValue.add(realFeature);
+ }
+ return null;
+ }
+
+
+ /**
+ * @return
+ * the edited feature
+ */
+ protected EStructuralFeature getEditedFeature() {
+ final List<Object> objects = organizeEditedObjectAndFeature();
+ if (null != objects && 2 == objects.size()) {
+ return (EStructuralFeature) objects.get(1);
+ }
+ return null;
}
/**
@@ -144,19 +198,24 @@ public class RichTextCellEditorWithUMLReferences extends RichTextCellEditor {
* the edited element
*/
protected Element getEditedElement() {
- final INattableModelManager manager = this.configRegistry.getConfigAttribute(NattableConfigAttributes.NATTABLE_MODEL_MANAGER_CONFIG_ATTRIBUTE, DisplayMode.NORMAL, NattableConfigAttributes.NATTABLE_MODEL_MANAGER_ID);
- Object rowObject = AxisUtils.getRepresentedElement(manager.getRowElement(getRowIndex()));
+ final EObject eobject = getEditedEObject();
+ if (eobject instanceof Element) {
+ return (Element) eobject;
+ }
+ return null;
+ }
- Element editedElement = null;
- if (rowObject instanceof Element) {
- editedElement = (Element) rowObject;
- } else {
- Object columnObject = AxisUtils.getRepresentedElement(manager.getColumnElement(getColumnIndex()));
- if (columnObject instanceof Element) {
- editedElement = (Element) rowObject;
- }
+ /**
+ *
+ * @return
+ * the edited eobject
+ */
+ private EObject getEditedEObject() {
+ final List<Object> objects = organizeEditedObjectAndFeature();
+ if (null != objects && 2 == objects.size()) {
+ return (EObject) objects.get(0);
}
- return editedElement;
+ return null;
}
/**
diff --git a/plugins/uml/org.eclipse.papyrus.uml.ui/src/org/eclipse/papyrus/uml/ui/editors/UMLRichtextEditorWithReferences.java b/plugins/uml/org.eclipse.papyrus.uml.ui/src/org/eclipse/papyrus/uml/ui/editors/UMLRichtextEditorWithReferences.java
index f31457402af..52322bbd5ee 100644
--- a/plugins/uml/org.eclipse.papyrus.uml.ui/src/org/eclipse/papyrus/uml/ui/editors/UMLRichtextEditorWithReferences.java
+++ b/plugins/uml/org.eclipse.papyrus.uml.ui/src/org/eclipse/papyrus/uml/ui/editors/UMLRichtextEditorWithReferences.java
@@ -1,5 +1,5 @@
/*****************************************************************************
- * Copyright (c) 2016 CEA LIST and others.
+ * Copyright (c) 2016, 2018 CEA LIST and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -10,6 +10,7 @@
*
* Contributors:
* Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
+ * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Bug 535653
*****************************************************************************/
package org.eclipse.papyrus.uml.ui.editors;
@@ -34,7 +35,6 @@ import org.eclipse.papyrus.uml.tools.providers.SemanticUMLContentProvider;
import org.eclipse.papyrus.uml.tools.util.UMLProviderHelper;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
-import org.eclipse.uml2.uml.Element;
import org.eclipse.uml2.uml.UMLPackage;
/**
@@ -115,10 +115,10 @@ public class UMLRichtextEditorWithReferences extends GenericRichTextEditor {
@Override
public void configureEdition(EObject editedElement, EStructuralFeature editedFeature) {
super.configureEdition(editedElement, editedFeature);
- if (editedElement instanceof Element) {
- setContentProvider(createContentProvider((Element) editedElement, editedFeature));
- setTextReferencesHelper(createTextReferencesHelper((Element) editedElement));
- setLabelProvider(createLabelProvider((Element) editedElement));
+ if (null != editedElement) {
+ setContentProvider(createContentProvider(editedElement, editedFeature));
+ setTextReferencesHelper(createTextReferencesHelper(editedElement));
+ setLabelProvider(createLabelProvider(editedElement));
}
}
@@ -219,7 +219,7 @@ public class UMLRichtextEditorWithReferences extends GenericRichTextEditor {
* @return
* the content provider to use for the richtext editor with reference
*/
- private IStaticContentProvider createContentProvider(final Element editedElement, final EStructuralFeature editedFeature) {
+ private IStaticContentProvider createContentProvider(final EObject editedElement, final EStructuralFeature editedFeature) {
IStaticContentProvider provider = null;
if (editedElement != null && editedFeature != null) {
final Resource baseResource = editedElement.eResource();
@@ -245,7 +245,7 @@ public class UMLRichtextEditorWithReferences extends GenericRichTextEditor {
* @return
* the {@link TextReferencesHelper} to use
*/
- private TextReferencesHelper createTextReferencesHelper(final Element editedElement) {
+ private TextReferencesHelper createTextReferencesHelper(final EObject editedElement) {
TextReferencesHelper helper = null;
if (editedElement != null && editedElement.eResource() != null) {
helper = new NameReferencesHelper(editedElement.eResource());
@@ -260,7 +260,7 @@ public class UMLRichtextEditorWithReferences extends GenericRichTextEditor {
* @return
* the label provider to use for this element
*/
- private ILabelProvider createLabelProvider(final Element editedElement) {
+ private ILabelProvider createLabelProvider(final EObject editedElement) {
ILabelProvider labelProvider = null;
if (editedElement != null) {
LabelProviderService lpSvc = null;

Back to the top