Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCamille Letavernier2017-11-30 05:17:32 -0500
committerRemi Schnekenburger2018-01-18 04:56:54 -0500
commit8df38d7b8ae96e41bb62753c2e6b5bfaca24e865 (patch)
tree73f711183034db0288594830b539f8f68b6b63ba
parent5b1553e561d0dd16b071eb32ecd0f76b0e34b4e0 (diff)
downloadorg.eclipse.papyrus-8df38d7b8ae96e41bb62753c2e6b5bfaca24e865.tar.gz
org.eclipse.papyrus-8df38d7b8ae96e41bb62753c2e6b5bfaca24e865.tar.xz
org.eclipse.papyrus-8df38d7b8ae96e41bb62753c2e6b5bfaca24e865.zip
Bug 484648: [Model Explorer] Link with Editor does not work with ME
customized through EMF Facets https://bugs.eclipse.org/bugs/show_bug.cgi?id=484648 Change-Id: I9ac56413a58ce987acf973a87fedba4f1840d632 Signed-off-by: Camille Letavernier <cletavernier@eclipsesource.com>
-rw-r--r--plugins/facet/org.eclipse.papyrus.emf.facet.custom.ui/META-INF/MANIFEST.MF2
-rw-r--r--plugins/facet/org.eclipse.papyrus.emf.facet.custom.ui/pom.xml2
-rw-r--r--plugins/facet/org.eclipse.papyrus.emf.facet.custom.ui/resources/customproperties.efacet15
-rw-r--r--plugins/facet/org.eclipse.papyrus.emf.facet.custom.ui/src/org/eclipse/papyrus/emf/facet/custom/ui/IContentPropertiesHandler.java7
-rw-r--r--plugins/facet/org.eclipse.papyrus.emf.facet.custom.ui/src/org/eclipse/papyrus/emf/facet/custom/ui/internal/CustomizedTreeContentProvider.java162
-rw-r--r--plugins/facet/org.eclipse.papyrus.emf.facet.custom.ui/src/org/eclipse/papyrus/emf/facet/custom/ui/internal/PropertiesHandler.java11
-rw-r--r--plugins/facet/org.eclipse.papyrus.emf.facet.custom.ui/src/org/eclipse/papyrus/emf/facet/custom/ui/internal/query/DefaultGetParentQuery.java57
-rw-r--r--plugins/infra/emf/org.eclipse.papyrus.infra.ui.emf/META-INF/MANIFEST.MF2
-rw-r--r--plugins/infra/emf/org.eclipse.papyrus.infra.ui.emf/pom.xml2
-rw-r--r--plugins/infra/emf/org.eclipse.papyrus.infra.ui.emf/src/org/eclipse/papyrus/infra/ui/emf/databinding/EObjectObservableValueEditingSupport.java2
-rw-r--r--plugins/infra/emf/org.eclipse.papyrus.infra.ui.emf/src/org/eclipse/papyrus/infra/ui/emf/providers/strategy/ContainmentBrowseStrategy.java153
-rw-r--r--plugins/infra/emf/org.eclipse.papyrus.infra.ui.emf/src/org/eclipse/papyrus/infra/ui/emf/utils/Constants.java2
-rw-r--r--plugins/infra/emf/org.eclipse.papyrus.infra.ui.emf/src/org/eclipse/papyrus/infra/ui/emf/utils/ProviderHelper.java93
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.modelexplorer/resources/PapyrusDiagram.custom26
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.modelexplorer/src/org/eclipse/papyrus/infra/gmfdiag/modelexplorer/queries/GetDiagramContainer.java46
-rw-r--r--plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.modelexplorer/META-INF/MANIFEST.MF2
-rw-r--r--plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.modelexplorer/pom.xml2
-rwxr-xr-xplugins/infra/nattable/org.eclipse.papyrus.infra.nattable.modelexplorer/resources/PapyrusTable.custom18
-rw-r--r--plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.modelexplorer/src/org/eclipse/papyrus/infra/nattable/modelexplorer/queries/GetTableContainer.java47
-rw-r--r--plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/ModelExplorerView.java105
-rw-r--r--tests/junit/plugins/views/org.eclipse.papyrus.views.modelexplorer.tests/src/org/eclipse/papyrus/views/modelexplorer/tests/ModelExplorerViewTests.java2
21 files changed, 523 insertions, 235 deletions
diff --git a/plugins/facet/org.eclipse.papyrus.emf.facet.custom.ui/META-INF/MANIFEST.MF b/plugins/facet/org.eclipse.papyrus.emf.facet.custom.ui/META-INF/MANIFEST.MF
index 17b0d363273..84e187da0bb 100644
--- a/plugins/facet/org.eclipse.papyrus.emf.facet.custom.ui/META-INF/MANIFEST.MF
+++ b/plugins/facet/org.eclipse.papyrus.emf.facet.custom.ui/META-INF/MANIFEST.MF
@@ -17,7 +17,7 @@ Require-Bundle: org.eclipse.papyrus.emf.facet.custom.core;bundle-version="[3.0.0
org.eclipse.papyrus.emf.facet.common.ui;bundle-version="[1.2.0,2.0.0)"
Bundle-Vendor: %Bundle-Vendor
Bundle-ActivationPolicy: lazy
-Bundle-Version: 3.0.0.qualifier
+Bundle-Version: 3.1.0.qualifier
Bundle-Name: %Bundle-Name
Bundle-Activator: org.eclipse.papyrus.emf.facet.custom.ui.internal.Activator
Bundle-ManifestVersion: 2
diff --git a/plugins/facet/org.eclipse.papyrus.emf.facet.custom.ui/pom.xml b/plugins/facet/org.eclipse.papyrus.emf.facet.custom.ui/pom.xml
index 3a6a7965e49..25a60b3624a 100644
--- a/plugins/facet/org.eclipse.papyrus.emf.facet.custom.ui/pom.xml
+++ b/plugins/facet/org.eclipse.papyrus.emf.facet.custom.ui/pom.xml
@@ -7,6 +7,6 @@
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>org.eclipse.papyrus.emf.facet.custom.ui</artifactId>
- <version>3.0.0-SNAPSHOT</version>
+ <version>3.1.0-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>
</project> \ No newline at end of file
diff --git a/plugins/facet/org.eclipse.papyrus.emf.facet.custom.ui/resources/customproperties.efacet b/plugins/facet/org.eclipse.papyrus.emf.facet.custom.ui/resources/customproperties.efacet
index c3ee21b1070..857d364a02a 100644
--- a/plugins/facet/org.eclipse.papyrus.emf.facet.custom.ui/resources/customproperties.efacet
+++ b/plugins/facet/org.eclipse.papyrus.emf.facet.custom.ui/resources/customproperties.efacet
@@ -327,6 +327,21 @@
xsi:type="javaQuery:JavaQuery"
implementationClassName="org.eclipse.papyrus.emf.facet.custom.ui.internal.query.DefaultVisibleAttributesQuery"/>
</facetOperations>
+ <facetOperations
+ name="parent">
+ <eType
+ xsi:type="ecore:EClass"
+ href="http://www.eclipse.org/emf/2002/Ecore#//EObject"/>
+ <eParameters
+ name="eStructuralFeature">
+ <eType
+ xsi:type="ecore:EClass"
+ href="http://www.eclipse.org/emf/2002/Ecore#//ETypedElement"/>
+ </eParameters>
+ <query
+ xsi:type="javaQuery:JavaQuery"
+ implementationClassName="org.eclipse.papyrus.emf.facet.custom.ui.internal.query.DefaultGetParentQuery"/>
+ </facetOperations>
</eClassifiers>
<eClassifiers
xsi:type="efacet:Facet"
diff --git a/plugins/facet/org.eclipse.papyrus.emf.facet.custom.ui/src/org/eclipse/papyrus/emf/facet/custom/ui/IContentPropertiesHandler.java b/plugins/facet/org.eclipse.papyrus.emf.facet.custom.ui/src/org/eclipse/papyrus/emf/facet/custom/ui/IContentPropertiesHandler.java
index 4b513772626..0fbd0ef3c55 100644
--- a/plugins/facet/org.eclipse.papyrus.emf.facet.custom.ui/src/org/eclipse/papyrus/emf/facet/custom/ui/IContentPropertiesHandler.java
+++ b/plugins/facet/org.eclipse.papyrus.emf.facet.custom.ui/src/org/eclipse/papyrus/emf/facet/custom/ui/IContentPropertiesHandler.java
@@ -51,4 +51,11 @@ public interface IContentPropertiesHandler {
* @return
*/
public FacetOperation getVisibleReferences();
+
+ /**
+ * Return the getParent customization operation
+ *
+ * @return
+ */
+ FacetOperation getParent();
}
diff --git a/plugins/facet/org.eclipse.papyrus.emf.facet.custom.ui/src/org/eclipse/papyrus/emf/facet/custom/ui/internal/CustomizedTreeContentProvider.java b/plugins/facet/org.eclipse.papyrus.emf.facet.custom.ui/src/org/eclipse/papyrus/emf/facet/custom/ui/internal/CustomizedTreeContentProvider.java
index c7fbc21b360..a6ac20b2e7e 100644
--- a/plugins/facet/org.eclipse.papyrus.emf.facet.custom.ui/src/org/eclipse/papyrus/emf/facet/custom/ui/internal/CustomizedTreeContentProvider.java
+++ b/plugins/facet/org.eclipse.papyrus.emf.facet.custom.ui/src/org/eclipse/papyrus/emf/facet/custom/ui/internal/CustomizedTreeContentProvider.java
@@ -19,11 +19,13 @@
package org.eclipse.papyrus.emf.facet.custom.ui.internal;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.IdentityHashMap;
+import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
@@ -376,19 +378,175 @@ public class CustomizedTreeContentProvider implements ICustomizedTreeContentProv
public Object getParent(final Object element) {
Object result = null;
if (element instanceof TreeElement) {
+ // It's a TreeElement, which means we've already displayed it.
+ // Finding its parent will be easy
final TreeElement treeElement = (TreeElement) element;
result = treeElement.getParent();
+ } else if (element instanceof EObject) {
+ // It's an EObject, meaning we don't know whether it's already
+ // been displayed. Delegate to the #parent custom query
+ EObject modelElement = (EObject) element;
+ result = customGetParent(modelElement);
}
return result;
}
+ /**
+ * Computes the parent TreeElement for a raw model element
+ *
+ * @param modelElement
+ * @return
+ */
+ private TreeElement customGetParent(final EObject modelElement) {
+ // The custom EObject/Facet parent path, without references
+ List<EObject> customParentPath = getModelElementPath(modelElement);
+
+ // The custom EObject/Facet parent path, including references
+ List<TreeElement> fullElementPath = getFullElementPath(customParentPath);
+
+ // Build the full TreeElement path and return the leaf element
+ return getParentTreeElementForPath(fullElementPath);
+ }
+
+ /**
+ * Returns the (customized) hierarchy of model elements until
+ * the given element (Included).
+ *
+ * This may be different from the semantic container path
+ * if the tree structure has been customized (e.g. via custom
+ * facet references)
+ *
+ * This path is the "natural path", i.e. it is unique (Even when the
+ * content provider actually represents a cyclic graph). It is however
+ * not necessarily the shortest path.
+ */
+ private List<EObject> getModelElementPath(final EObject modelElement) {
+
+ // Ordered from child to parent
+ Collection<EObject> customParentPath = new LinkedHashSet<>();
+ customParentPath.add(modelElement);
+
+ EObject currentModelElement = modelElement;
+ try {
+ while (currentModelElement != null) {
+ EObject parent = customManager.getCustomValueOf(currentModelElement, contentHandler.getParent(), EObject.class);
+ if (parent != null) {
+ if (customParentPath.contains(parent)) {
+ String message = "Cyclic path detected when computing the hierarchy for " + modelElement;
+ message += "\nPath: "+customParentPath;
+ message += "This may indicate an inconsistency in the facet/custom implementation(s) of the #parent query";
+ Logger.logError(message, Activator.getDefault());
+ break;
+ }
+ customParentPath.add(parent);
+ }
+ currentModelElement = parent;
+ }
+ } catch (CustomizationException ex) {
+ Logger.logError(ex, Activator.getDefault());
+ }
+
+ List<EObject> parentPath = new ArrayList<>(customParentPath);
+
+ // Order from parent to child
+ Collections.reverse(parentPath);
+ return parentPath;
+ }
+
+ /**
+ * Builds and returns the complete list of TreeElements corresponding
+ * to the given model element path. The resulting path will include the
+ * necessary EReferences (Which may include FacetReferences).
+ */
+ private List<TreeElement> getFullElementPath(Collection<EObject> customParentPath) {
+ List<TreeElement> treePath = new ArrayList<>(); // Contains EObjects and EReferences
+ TreeElement currentPathElement = null;
+ EObject currentSemanticParent = null;
+
+ for (EObject semanticElement : customParentPath) {
+
+ if (currentPathElement == null) {
+ // Root element
+ EObjectCacheElement cacheElement = new EObjectCacheElement(semanticElement, null);
+ currentPathElement = cache.get(cacheElement);
+ if (currentPathElement == null) {
+ currentPathElement = Arrays.stream(getElements(null)) //
+ .filter(EObjectTreeElement.class::isInstance) //
+ .map(EObjectTreeElement.class::cast) //
+ .filter(tree -> tree.getEObject() == semanticElement) //
+ .findAny().orElse(null);
+ }
+ } else {
+
+ TreeElement nextElement = Arrays.stream(getChildren(currentPathElement)) //
+ .filter(EObjectTreeElement.class::isInstance)//
+ .map(EObjectTreeElement.class::cast) //
+ .filter(tree -> tree.getEObject() == semanticElement) //
+ .findAny() //
+ .orElse(null);
+ if (nextElement == null) {
+ // Try references that may contain this element
+ List<EReference> references = getVisibleReferences(currentSemanticParent);
+ for (EReference reference : references) {
+ if (reference.getEType().isInstance(semanticElement)) {
+ // Potential match
+
+ EObjectCacheElement cacheElement = new EObjectCacheElement(reference, currentPathElement);
+ TreeElement cachedElement = cache.get(cacheElement);
+ if (cachedElement == null || false == cachedElement instanceof EReferenceTreeElement) {
+ // Since we called getChildren() earlier, this shouldn't happen
+ System.err.println("Reference is visible but wasn't found");
+ continue;
+ }
+
+ EReferenceTreeElement cachedRef = (EReferenceTreeElement) cachedElement;
+
+ List<EObjectTreeElement> children;
+ if (reference.getUpperBound() == 1) {
+ children = Collections.singletonList(getSingleValuedReferenceChild(reference, currentSemanticParent, cachedElement));
+ } else {
+ children = getMultiValuedReferenceChildren(reference, currentSemanticParent, cachedRef);
+ }
+
+ nextElement = children.stream() //
+ .filter(tree -> tree.getEObject() == semanticElement) //
+ .findAny() //
+ .orElse(null);
+
+ if (nextElement != null) {
+ treePath.add(cachedRef);
+ break;
+ }
+ }
+ }
+ }
+
+ currentPathElement = nextElement;
+ }
+
+ currentSemanticParent = semanticElement;
+ if (currentPathElement != null) {
+ treePath.add(currentPathElement);
+ } else {
+ System.err.println("Invalid root element: " + currentPathElement);
+ }
+ }
+
+ return treePath;
+ }
+
+ private TreeElement getParentTreeElementForPath(List<TreeElement> fullElementPath) {
+ if (fullElementPath.size() < 2) {
+ return null;
+ }
+ return fullElementPath.get(fullElementPath.size() - 2);
+ }
+
@Override
public boolean hasChildren(final Object element) {
return getChildren(element).length > 0;
}
-
-
@Override
public void inputChanged(final Viewer viewer, final Object oldInput, final Object newInput) {
if (oldInput != newInput) {
diff --git a/plugins/facet/org.eclipse.papyrus.emf.facet.custom.ui/src/org/eclipse/papyrus/emf/facet/custom/ui/internal/PropertiesHandler.java b/plugins/facet/org.eclipse.papyrus.emf.facet.custom.ui/src/org/eclipse/papyrus/emf/facet/custom/ui/internal/PropertiesHandler.java
index 12a5f4d731b..75e0738af68 100644
--- a/plugins/facet/org.eclipse.papyrus.emf.facet.custom.ui/src/org/eclipse/papyrus/emf/facet/custom/ui/internal/PropertiesHandler.java
+++ b/plugins/facet/org.eclipse.papyrus.emf.facet.custom.ui/src/org/eclipse/papyrus/emf/facet/custom/ui/internal/PropertiesHandler.java
@@ -54,6 +54,7 @@ public class PropertiesHandler implements IContentPropertiesHandler,
private static final String IS_VISIBLE = "isVisible"; //$NON-NLS-1$
private static final String VISIBLE_REFERENCES = "visibleReferences"; //$NON-NLS-1$
private static final String VISIBLE_ATTRIBUTES = "visibleAttributes"; //$NON-NLS-1$
+ private static final String PARENT = "parent"; //$NON-NLS-1$
private static final String IS_UNDERLINED = "isUnderlined"; //$NON-NLS-1$
private static final String IS_STRUCKTHROUGH = "isStruckthrough"; //$NON-NLS-1$
private static final String TOP_L_OVERLAY = "topLeftOverlay"; //$NON-NLS-1$
@@ -342,4 +343,14 @@ public class PropertiesHandler implements IContentPropertiesHandler,
return getPropertyByName(PropertiesHandler.CUSTOM,
PropertiesHandler.VISIBLE_REFERENCES);
}
+
+ /**
+ * @see org.eclipse.papyrus.emf.facet.custom.ui.IContentPropertiesHandler#getParent()
+ *
+ * @return
+ */
+ @Override
+ public FacetOperation getParent() {
+ return getPropertyByName(PropertiesHandler.CUSTOM, PropertiesHandler.PARENT);
+ }
} \ No newline at end of file
diff --git a/plugins/facet/org.eclipse.papyrus.emf.facet.custom.ui/src/org/eclipse/papyrus/emf/facet/custom/ui/internal/query/DefaultGetParentQuery.java b/plugins/facet/org.eclipse.papyrus.emf.facet.custom.ui/src/org/eclipse/papyrus/emf/facet/custom/ui/internal/query/DefaultGetParentQuery.java
new file mode 100644
index 00000000000..adbd067c07c
--- /dev/null
+++ b/plugins/facet/org.eclipse.papyrus.emf.facet.custom.ui/src/org/eclipse/papyrus/emf/facet/custom/ui/internal/query/DefaultGetParentQuery.java
@@ -0,0 +1,57 @@
+/*****************************************************************************
+ * Copyright (c) 2017 EclipseSource 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:
+ * EclipseSource - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.emf.facet.custom.ui.internal.query;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.jface.viewers.ITreeContentProvider;
+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.query.java.core.IJavaQuery2;
+import org.eclipse.papyrus.emf.facet.query.java.core.IParameterValueList2;
+
+/**
+ * <p>
+ * Default implementation of the #parent customization operation. This implementation
+ * returns the {@link EObject#eContainer() EObject's container}.
+ * </p>
+ * <p>
+ * The #parent customization operation is used to customize the behavior of {@link ITreeContentProvider#getParent(Object)},
+ * used to efficiently reveal elements in a custom tree structure.
+ * </p>
+ * <p>
+ * This default implementation is sufficient when displaying the natural containment tree,
+ * even if the intermediate references are customized. It should however be customized when
+ * removing natural containers (e.g. when simplifying the tree structure) or introducing
+ * a custom containment tree (e.g. when moving an element to a different parent)
+ * </p>
+ *
+ * @since 3.1
+ */
+public class DefaultGetParentQuery implements IJavaQuery2<EObject, EObject> {
+
+ /**
+ * @see org.eclipse.papyrus.emf.facet.query.java.core.IJavaQuery2#evaluate(org.eclipse.emf.ecore.EObject, org.eclipse.papyrus.emf.facet.query.java.core.IParameterValueList2, org.eclipse.papyrus.emf.facet.efacet.core.IFacetManager)
+ *
+ * @param source
+ * @param parameterValues
+ * @param facetManager
+ * @return
+ * @throws DerivedTypedElementException
+ */
+ @Override
+ public EObject evaluate(EObject source, IParameterValueList2 parameterValues, IFacetManager facetManager) throws DerivedTypedElementException {
+ return source.eContainer();
+ }
+
+}
diff --git a/plugins/infra/emf/org.eclipse.papyrus.infra.ui.emf/META-INF/MANIFEST.MF b/plugins/infra/emf/org.eclipse.papyrus.infra.ui.emf/META-INF/MANIFEST.MF
index 8aa547e82eb..9000a4a9871 100644
--- a/plugins/infra/emf/org.eclipse.papyrus.infra.ui.emf/META-INF/MANIFEST.MF
+++ b/plugins/infra/emf/org.eclipse.papyrus.infra.ui.emf/META-INF/MANIFEST.MF
@@ -20,7 +20,7 @@ Require-Bundle: org.eclipse.emf.edit.ui;bundle-version="[2.12.0,3.0.0)";visibili
org.eclipse.papyrus.infra.internationalization.utils;bundle-version="[1.0.0,2.0.0)"
Bundle-Vendor: %pluginProvider
Bundle-ActivationPolicy: lazy
-Bundle-Version: 2.0.0.qualifier
+Bundle-Version: 2.1.0.qualifier
Bundle-Name: %pluginName
Bundle-Localization: plugin
Bundle-Activator: org.eclipse.papyrus.infra.ui.internal.emf.Activator
diff --git a/plugins/infra/emf/org.eclipse.papyrus.infra.ui.emf/pom.xml b/plugins/infra/emf/org.eclipse.papyrus.infra.ui.emf/pom.xml
index 731ed5243ea..bd40569377b 100644
--- a/plugins/infra/emf/org.eclipse.papyrus.infra.ui.emf/pom.xml
+++ b/plugins/infra/emf/org.eclipse.papyrus.infra.ui.emf/pom.xml
@@ -7,6 +7,6 @@
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>org.eclipse.papyrus.infra.ui.emf</artifactId>
- <version>2.0.0-SNAPSHOT</version>
+ <version>2.1.0-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>
</project> \ No newline at end of file
diff --git a/plugins/infra/emf/org.eclipse.papyrus.infra.ui.emf/src/org/eclipse/papyrus/infra/ui/emf/databinding/EObjectObservableValueEditingSupport.java b/plugins/infra/emf/org.eclipse.papyrus.infra.ui.emf/src/org/eclipse/papyrus/infra/ui/emf/databinding/EObjectObservableValueEditingSupport.java
index 1eb292b50e4..507da228a20 100644
--- a/plugins/infra/emf/org.eclipse.papyrus.infra.ui.emf/src/org/eclipse/papyrus/infra/ui/emf/databinding/EObjectObservableValueEditingSupport.java
+++ b/plugins/infra/emf/org.eclipse.papyrus.infra.ui.emf/src/org/eclipse/papyrus/infra/ui/emf/databinding/EObjectObservableValueEditingSupport.java
@@ -216,7 +216,7 @@ public class EObjectObservableValueEditingSupport extends EditingSupport {
* @param object
* The old value.
* @return The value to return.
- * @since 2.0
+ * @since 2.1
*/
protected Object getMultiUnlimitedNaturalValue(final Object objects) {
if (objects instanceof List<?>) {
diff --git a/plugins/infra/emf/org.eclipse.papyrus.infra.ui.emf/src/org/eclipse/papyrus/infra/ui/emf/providers/strategy/ContainmentBrowseStrategy.java b/plugins/infra/emf/org.eclipse.papyrus.infra.ui.emf/src/org/eclipse/papyrus/infra/ui/emf/providers/strategy/ContainmentBrowseStrategy.java
index 7a6a326e719..3fdbad4f953 100644
--- a/plugins/infra/emf/org.eclipse.papyrus.infra.ui.emf/src/org/eclipse/papyrus/infra/ui/emf/providers/strategy/ContainmentBrowseStrategy.java
+++ b/plugins/infra/emf/org.eclipse.papyrus.infra.ui.emf/src/org/eclipse/papyrus/infra/ui/emf/providers/strategy/ContainmentBrowseStrategy.java
@@ -14,18 +14,18 @@ package org.eclipse.papyrus.infra.ui.emf.providers.strategy;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
-import java.util.Iterator;
import java.util.List;
+import java.util.stream.Collectors;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EReference;
import org.eclipse.gmf.runtime.notation.Diagram;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.ITreeContentProvider;
-import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.papyrus.infra.emf.utils.EMFHelper;
+import org.eclipse.papyrus.infra.ui.emf.utils.ProviderHelper;
import org.eclipse.papyrus.infra.widgets.providers.IAdaptableContentProvider;
import org.eclipse.papyrus.infra.widgets.strategy.ProviderBasedBrowseStrategy;
import org.eclipse.swt.widgets.TreeItem;
@@ -63,110 +63,12 @@ public class ContainmentBrowseStrategy extends ProviderBasedBrowseStrategy<TreeV
// Only browse Containment references and Facet references
if (semanticElement instanceof EReference) {
- // if(semanticElement instanceof FacetReference) {
- // return true;
- // }
-
return ((EReference) semanticElement).isContainment() && !((EReference) semanticElement).isDerived();
}
return true;
}
- //
- // Elements search
- //
-
- // /**
- // * {@inheritDoc}
- // */
- // @Override
- // public TreePath findPath(Object semanticElement, Object[] rootElements) {
- // List<Object> semanticPath = new LinkedList<Object>();
- // findSemanticPath(semanticElement, semanticPath);
- // return searchPath(semanticPath, rootElements);
- // }
-
- // /**
- // * Fills the semantic path to the given element
- // *
- // * @param element
- // * The element to retrieve
- // * @param currentPath
- // * The path to fill (in-out)
- // */
- // protected void findSemanticPath(Object element, List<Object> currentPath) {
- // if(element != null && element instanceof EObject) {
- // findSemanticPath(getSemanticParent(element), currentPath);
- // currentPath.add(element);
- // }
- // }
- //
- // protected Object getSemanticParent(Object element) {
- // if(element instanceof EObject) {
- // return ((EObject)element).eContainer();
- // }
- // return null;
- // }
- //
- // /**
- // * Retrieve the graphical TreePath from the given semantic path
- // *
- // * @param semanticPath
- // * @return
- // */
- // protected TreePath searchPath(List<Object> semanticPath, Object input) {
- // List<Object> graphicalPath = new LinkedList<Object>();
- // Object[] graphicalRootObjects = (Object[])input;
- // if(!searchPath(semanticPath, graphicalPath, graphicalRootObjects)) {
- // //Object not found
- // graphicalPath.clear();
- // }
- //
- // return new TreePath(graphicalPath.toArray());
- // }
- //
- // protected boolean searchPath(List<Object> semanticPath, List<Object> graphicalPath, Object[] graphicalRootObjects) {
- // if(semanticPath.isEmpty()) {
- // return true;
- // }
- //
- // if(graphicalRootObjects == null) {
- // return false;
- // }
- //
- // Object currentElement = semanticPath.get(0);
- // for(Object graphicalElement : graphicalRootObjects) {
- // Object semanticValue = adaptableProvider.getAdaptedValue(graphicalElement);
- //
- // //Specific case for containment EReference
- // if(semanticValue instanceof EReference) {
- // EReference referenceToBrowse = (EReference)semanticValue;
- // if(referenceToBrowse.isContainment()) {
- // graphicalPath.add(graphicalElement);
- //
- // if(searchPath(semanticPath, graphicalPath, provider.getChildren(graphicalElement))) {
- // //The element has been found
- // return true;
- // }
- //
- // //The element has not been found ; we revert the modifications
- // graphicalPath.remove(graphicalElement);
- // }
- // }
- //
- // if(semanticValue == currentElement) {
- // semanticPath.remove(0);
- // graphicalPath.add(graphicalElement);
- // if(searchPath(semanticPath, graphicalPath, provider.getChildren(graphicalElement))) {
- // return true;
- // }
- // }
- // }
- //
- // return false;
- // }
-
@Override
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
if (viewer instanceof TreeViewer) {
@@ -180,32 +82,8 @@ public class ContainmentBrowseStrategy extends ProviderBasedBrowseStrategy<TreeV
*/
@Override
public void revealSemanticElement(List<?> elementList) {
- // for each element we reveal it
- Iterator<?> elementListIterator = elementList.iterator();
- ArrayList<Object> treeElementToSelect = new ArrayList<Object>();
- while (elementListIterator.hasNext()) {
- Object currentElement = elementListIterator.next();
- // test if the type is an EObject
- if (currentElement instanceof EObject) {
- EObject currentEObject = (EObject) currentElement;
- if (currentEObject.eIsProxy()) {
- continue; // Cannot be revealed
- }
- // the content provider exist?
- if (provider != null) {
- // need the root in order to find all element in the tree
- Object root = provider.getElements(null)[0];
- // look for the path in order to access to this element
- List<Object> path = searchPath(currentEObject, Arrays.asList(provider.getElements(root)));
- if (path.size() > 0) {
- // expand in the common viewer the path
- expandItems(path, viewer.getTree().getItems());
- treeElementToSelect.add(path.get(path.size() - 1));
- }
- }
- }
- selectReveal(new StructuredSelection(treeElementToSelect));
- }
+ List<EObject> eobjects = elementList.stream().filter(EObject.class::isInstance).map(EObject.class::cast).collect(Collectors.toList());
+ ProviderHelper.selectReveal(eobjects, viewer);
}
public void expandItems(List<Object> treeElementList, TreeItem[] list) {
@@ -228,6 +106,14 @@ public class ContainmentBrowseStrategy extends ProviderBasedBrowseStrategy<TreeV
viewer.getTree().setRedraw(true);
}
+ /**
+ *
+ * @param selection
+ *
+ * @deprecated since 2.1
+ * Use {@link ProviderHelper#selectReveal(java.util.Collection, org.eclipse.jface.viewers.StructuredViewer)} instead
+ */
+ @Deprecated
public void selectReveal(ISelection selection) {
if (viewer != null) {
viewer.setSelection(selection, true);
@@ -240,7 +126,10 @@ public class ContainmentBrowseStrategy extends ProviderBasedBrowseStrategy<TreeV
* @param eobject
* @param objects
* @return
+ *
+ * @deprecated Since 2.1
*/
+ @Deprecated
protected List<Object> searchDirectContainmentPath(EObject eobject, List<Object> wrappedElements) {
List<Object> path = new ArrayList<Object>();
@@ -269,6 +158,15 @@ public class ContainmentBrowseStrategy extends ProviderBasedBrowseStrategy<TreeV
return path;
}
+ /**
+ *
+ * @param emfPath
+ * @param element
+ * @return
+ *
+ * @deprecated Since 2.1
+ */
+ @Deprecated
protected boolean browseElementForDirectContainment(List<EObject> emfPath, EObject element) {
if (emfPath.contains(element)) {
return true;
@@ -292,7 +190,10 @@ public class ContainmentBrowseStrategy extends ProviderBasedBrowseStrategy<TreeV
* @param objects
* a list of elements where eobject can be wrapped.
* @return the list of modelElementItem (from the root to the element that wrap the eobject)
+ *
+ * @deprecated Since 2.1 See {@link ProviderHelper#findObjectsToReveal(java.util.Collection, org.eclipse.jface.viewers.StructuredViewer)}
*/
+ @Deprecated
protected List<Object> searchPath(EObject eobject, List<Object> objects) {
// Simple/quick search (Based on containment)
List<Object> path = searchDirectContainmentPath(eobject, objects);
diff --git a/plugins/infra/emf/org.eclipse.papyrus.infra.ui.emf/src/org/eclipse/papyrus/infra/ui/emf/utils/Constants.java b/plugins/infra/emf/org.eclipse.papyrus.infra.ui.emf/src/org/eclipse/papyrus/infra/ui/emf/utils/Constants.java
index 8b667459c31..ed02c575b73 100644
--- a/plugins/infra/emf/org.eclipse.papyrus.infra.ui.emf/src/org/eclipse/papyrus/infra/ui/emf/utils/Constants.java
+++ b/plugins/infra/emf/org.eclipse.papyrus.infra.ui.emf/src/org/eclipse/papyrus/infra/ui/emf/utils/Constants.java
@@ -17,7 +17,7 @@ package org.eclipse.papyrus.infra.ui.emf.utils;
*
* The constants for the org.eclipse.papyrus.plugin infra.ui.emf.
*
- * @since 2.0
+ * @since 2.1
*
*/
public class Constants {
diff --git a/plugins/infra/emf/org.eclipse.papyrus.infra.ui.emf/src/org/eclipse/papyrus/infra/ui/emf/utils/ProviderHelper.java b/plugins/infra/emf/org.eclipse.papyrus.infra.ui.emf/src/org/eclipse/papyrus/infra/ui/emf/utils/ProviderHelper.java
index 5e6acf0d429..cf5c5930a23 100644
--- a/plugins/infra/emf/org.eclipse.papyrus.infra.ui.emf/src/org/eclipse/papyrus/infra/ui/emf/utils/ProviderHelper.java
+++ b/plugins/infra/emf/org.eclipse.papyrus.infra.ui.emf/src/org/eclipse/papyrus/infra/ui/emf/utils/ProviderHelper.java
@@ -13,19 +13,29 @@
*****************************************************************************/
package org.eclipse.papyrus.infra.ui.emf.utils;
+import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
import java.util.Objects;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.jface.viewers.IContentProvider;
import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.jface.viewers.StructuredViewer;
import org.eclipse.papyrus.emf.facet.custom.core.ICustomizationManager;
import org.eclipse.papyrus.infra.core.language.ILanguageService;
import org.eclipse.papyrus.infra.core.resource.IModel;
import org.eclipse.papyrus.infra.core.resource.ModelSet;
+import org.eclipse.papyrus.infra.emf.utils.EMFHelper;
import org.eclipse.papyrus.infra.emf.utils.HistoryUtil;
import org.eclipse.papyrus.infra.ui.emf.providers.EMFGraphicalContentProvider;
import org.eclipse.papyrus.infra.ui.emf.providers.strategy.ContainmentBrowseStrategy;
@@ -113,4 +123,87 @@ public class ProviderHelper {
return getContentProviderFactory(resourceSet).createSemanticContentProvider(resourceSet);
}
+ /**
+ * <p>
+ * Returns a collection of objects to reveal, corresponding to a collection of model elements.
+ * </p>
+ * <p>
+ * This method takes custom structure into account, and will wrap natural model elements into
+ * viewer-specific representation elements (Such as Facet TreeElements).
+ * </p>
+ *
+ * @param modelElements
+ * @param contentProvider
+ * @param providerInput
+ * The input used to get the root elements from the {@code ITreeContentProvider}
+ * @return
+ *
+ * @since 2.1
+ */
+ /*
+ * Implementation note:
+ *
+ * ITreeContentProvider#getParent can give us the path until the parent of the element to reveal.
+ * However, we also need the element itself. So we first retrieve all parents, then for each parent,
+ * filter their children to find the ones corresponding to the model elements we need to reveal.
+ *
+ * This method works well if (and only if) the ITreeContentProvider#getParent method is properly implemented,
+ * and returns a Wrapper Parent Element when passing a Semantic Model Element (Which is now the case for the EMF Facet provider)
+ * It also works well for providers that are not wrapping model elements... by simply returning a list equivalent to its argument.
+ */
+ public static List<Object> findObjectsToReveal(Collection<EObject> modelElements, ITreeContentProvider contentProvider, Object providerInput) {
+ List<Object> toReveal = new ArrayList<>();
+ ITreeContentProvider provider = (ITreeContentProvider) contentProvider;
+ Map<Object, Collection<EObject>> allParents = new HashMap<>();
+ for (EObject modelElement : modelElements) {
+ Object parent = provider.getParent(modelElement);
+ if (parent != null) {
+ if (!allParents.containsKey(parent)) {
+ allParents.put(parent, new HashSet<>());
+ }
+ allParents.get(parent).add(modelElement);
+ } else { // element can't be found via getParent.
+ // Try to find it in the root elements
+ Object providerElement = Arrays.stream(provider.getElements(providerInput)) //
+ .filter(element -> EMFHelper.getEObject(element) == modelElement) //
+ .findFirst().orElse(modelElement); //If we can't find it, use the raw model element
+
+ toReveal.add(providerElement);
+ }
+ }
+
+ for (Map.Entry<Object, Collection<EObject>> entry : allParents.entrySet()) {
+ Object[] children = provider.getChildren(entry.getKey());
+ Collection<EObject> semanticToReveal = entry.getValue();
+ Arrays.stream(children) //
+ .filter(child -> semanticToReveal.contains(EMFHelper.getEObject(child))) //
+ .forEach(toReveal::add);
+ }
+
+ return toReveal;
+ }
+
+ /**
+ * <p>
+ * Reveals and selects the given model element in the specified viewer.
+ * </p>
+ *
+ * <p>
+ * This methods takes custom structure into account (Thus will also work with custom EMF Facet providers).
+ * </p>
+ *
+ * @param modelElement
+ * @param viewer
+ * @since 2.1
+ */
+ public static void selectReveal(Collection<EObject> modelElements, StructuredViewer viewer) {
+ IContentProvider contentProvider = viewer.getContentProvider();
+ if (contentProvider instanceof ITreeContentProvider) {
+ List<Object> toReveal = findObjectsToReveal(modelElements, (ITreeContentProvider) contentProvider, viewer.getInput());
+ viewer.setSelection(new StructuredSelection(toReveal), true);
+ } else {
+ viewer.setSelection(new StructuredSelection(new ArrayList<>(modelElements)), true);
+ }
+ }
+
}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.modelexplorer/resources/PapyrusDiagram.custom b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.modelexplorer/resources/PapyrusDiagram.custom
index 6b59d09dbe5..21a39f95e3b 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.modelexplorer/resources/PapyrusDiagram.custom
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.modelexplorer/resources/PapyrusDiagram.custom
@@ -54,7 +54,7 @@
implementationClassName="org.eclipse.papyrus.infra.gmfdiag.modelexplorer.queries.GetDiagramIcon"/>
<override
xsi:type="efacet:FacetOperation"
- href="../../../plugin/org.eclipse.papyrus.emf.facet.custom.ui/resources/customproperties.efacet#//CustomizedEObject/image"/>
+ href="platform:/plugin/org.eclipse.papyrus.emf.facet.custom.ui/resources/customproperties.efacet#//CustomizedEObject/image"/>
</facetOperations>
<facetOperations
name="GetVisibleReferences"
@@ -68,7 +68,25 @@
implementationClassName="org.eclipse.papyrus.infra.gmfdiag.modelexplorer.queries.EmptyListQuery"/>
<override
xsi:type="efacet:FacetOperation"
- href="../../../plugin/org.eclipse.papyrus.emf.facet.custom.ui/resources/customproperties.efacet#//CustomizedEObject/visibleReferences"/>
+ href="platform:/plugin/org.eclipse.papyrus.emf.facet.custom.ui/resources/customproperties.efacet#//CustomizedEObject/visibleReferences"/>
+ </facetOperations>
+ <facetOperations
+ name="GetParent">
+ <eType
+ xsi:type="ecore:EClass"
+ href="http://www.eclipse.org/emf/2002/Ecore#//EObject"/>
+ <eParameters
+ name="eStructuralFeature">
+ <eType
+ xsi:type="ecore:EClass"
+ href="http://www.eclipse.org/emf/2002/Ecore#//ETypedElement"/>
+ </eParameters>
+ <query
+ xsi:type="javaQuery:JavaQuery"
+ implementationClassName="org.eclipse.papyrus.infra.gmfdiag.modelexplorer.queries.GetDiagramContainer"/>
+ <override
+ xsi:type="efacet:FacetOperation"
+ href="platform:/plugin/org.eclipse.papyrus.emf.facet.custom.ui/resources/customproperties.efacet#//CustomizedEObject/parent"/>
</facetOperations>
</eClassifiers>
<eClassifiers
@@ -118,8 +136,8 @@
implementationClassName="org.eclipse.papyrus.infra.gmfdiag.modelexplorer.queries.GetContainedDiagrams"/>
</facetOperations>
<extendedFacets
- href="../../../plugin/org.eclipse.papyrus.infra.gmfdiag.modelexplorer/resources/PapyrusDiagram.custom#//DiagramContainer"/>
+ href="platform:/plugin/org.eclipse.papyrus.infra.gmfdiag.modelexplorer/resources/PapyrusDiagram.custom#//DiagramContainer"/>
<customizedFacet
- href="../../../plugin/org.eclipse.papyrus.infra.gmfdiag.modelexplorer/resources/PapyrusDiagram.custom#//DiagramContainer"/>
+ href="platform:/plugin/org.eclipse.papyrus.infra.gmfdiag.modelexplorer/resources/PapyrusDiagram.custom#//DiagramContainer"/>
</eClassifiers>
</custom:Customization>
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.modelexplorer/src/org/eclipse/papyrus/infra/gmfdiag/modelexplorer/queries/GetDiagramContainer.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.modelexplorer/src/org/eclipse/papyrus/infra/gmfdiag/modelexplorer/queries/GetDiagramContainer.java
new file mode 100644
index 00000000000..f0e1a2756d9
--- /dev/null
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.modelexplorer/src/org/eclipse/papyrus/infra/gmfdiag/modelexplorer/queries/GetDiagramContainer.java
@@ -0,0 +1,46 @@
+/*****************************************************************************
+ * Copyright (c) 2018 EclipseSource 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:
+ * EclipseSource - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.infra.gmfdiag.modelexplorer.queries;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.gmf.runtime.notation.Diagram;
+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.query.java.core.IJavaQuery2;
+import org.eclipse.papyrus.emf.facet.query.java.core.IParameterValueList2;
+import org.eclipse.papyrus.infra.gmfdiag.common.utils.DiagramUtils;
+
+/**
+ * Query to retrieve the graphical container of a Diagram. If no such container
+ * exists, the semantic element of the Diagram is returned.
+ *
+ * @see {@link DiagramUtils#getOwner(Diagram)}
+ */
+public class GetDiagramContainer implements IJavaQuery2<Diagram, EObject> {
+
+ /**
+ * @see org.eclipse.papyrus.emf.facet.query.java.core.IJavaQuery2#evaluate(org.eclipse.emf.ecore.EObject, org.eclipse.papyrus.emf.facet.query.java.core.IParameterValueList2, org.eclipse.papyrus.emf.facet.efacet.core.IFacetManager)
+ *
+ * @param source
+ * @param parameterValues
+ * @param facetManager
+ * @return
+ * @throws DerivedTypedElementException
+ */
+ @Override
+ public EObject evaluate(Diagram source, IParameterValueList2 parameterValues, IFacetManager facetManager) throws DerivedTypedElementException {
+ return DiagramUtils.getOwner(source);
+ }
+
+}
diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.modelexplorer/META-INF/MANIFEST.MF b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.modelexplorer/META-INF/MANIFEST.MF
index 752cc7212a7..fa6e502d1f5 100644
--- a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.modelexplorer/META-INF/MANIFEST.MF
+++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.modelexplorer/META-INF/MANIFEST.MF
@@ -21,7 +21,7 @@ Require-Bundle: org.eclipse.papyrus.infra.nattable.model;bundle-version="[3.0.0,
org.eclipse.papyrus.infra.internationalization.utils;bundle-version="[1.0.0,2.0.0)",
org.eclipse.papyrus.infra.nattable.model.edit;bundle-version="[3.0.0,4.0.0)"
Bundle-Vendor: %Bundle-Vendor
-Bundle-Version: 3.0.0.qualifier
+Bundle-Version: 3.1.0.qualifier
Bundle-Activator: org.eclipse.papyrus.infra.nattable.modelexplorer.Activator
Bundle-ManifestVersion: 2
Bundle-Description: %pluginDescription
diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.modelexplorer/pom.xml b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.modelexplorer/pom.xml
index 4d7085e1bad..3b06a8d1009 100644
--- a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.modelexplorer/pom.xml
+++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.modelexplorer/pom.xml
@@ -8,7 +8,7 @@
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>org.eclipse.papyrus.infra.nattable.modelexplorer</artifactId>
- <version>3.0.0-SNAPSHOT</version>
+ <version>3.1.0-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>
<description>This plugin provides : - the facets and the customization to display the Papyrus Nattables in the ModelExplorer</description>
</project> \ No newline at end of file
diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.modelexplorer/resources/PapyrusTable.custom b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.modelexplorer/resources/PapyrusTable.custom
index b40aa1d4c96..d6d1165c42d 100755
--- a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.modelexplorer/resources/PapyrusTable.custom
+++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.modelexplorer/resources/PapyrusTable.custom
@@ -69,6 +69,24 @@
xsi:type="efacet:FacetOperation"
href="platform:/plugin/org.eclipse.papyrus.emf.facet.custom.ui/resources/customproperties.efacet#//CustomizedEObject/visibleReferences"/>
</facetOperations>
+ <facetOperations
+ name="GetParent">
+ <eType
+ xsi:type="ecore:EClass"
+ href="http://www.eclipse.org/emf/2002/Ecore#//EObject"/>
+ <eParameters
+ name="eStructuralFeature">
+ <eType
+ xsi:type="ecore:EClass"
+ href="http://www.eclipse.org/emf/2002/Ecore#//ETypedElement"/>
+ </eParameters>
+ <query
+ xsi:type="javaQuery:JavaQuery"
+ implementationClassName="org.eclipse.papyrus.infra.nattable.modelexplorer.queries.GetTableContainer"/>
+ <override
+ xsi:type="efacet:FacetOperation"
+ href="platform:/plugin/org.eclipse.papyrus.emf.facet.custom.ui/resources/customproperties.efacet#//CustomizedEObject/parent"/>
+ </facetOperations>
</eClassifiers>
<eClassifiers
xsi:type="efacet:Facet"
diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.modelexplorer/src/org/eclipse/papyrus/infra/nattable/modelexplorer/queries/GetTableContainer.java b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.modelexplorer/src/org/eclipse/papyrus/infra/nattable/modelexplorer/queries/GetTableContainer.java
new file mode 100644
index 00000000000..88f214038d6
--- /dev/null
+++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.modelexplorer/src/org/eclipse/papyrus/infra/nattable/modelexplorer/queries/GetTableContainer.java
@@ -0,0 +1,47 @@
+/*****************************************************************************
+ * Copyright (c) 2018 EclipseSource 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:
+ * EclipseSource - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.infra.nattable.modelexplorer.queries;
+
+import org.eclipse.emf.ecore.EObject;
+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.query.java.core.IJavaQuery2;
+import org.eclipse.papyrus.emf.facet.query.java.core.IParameterValueList2;
+import org.eclipse.papyrus.infra.nattable.model.nattable.Table;
+
+/**
+ * Query to retrieve the graphical container of a Table. If no such container
+ * exists, the semantic element of the Table is returned.
+ *
+ * @see {@link TableUtils#getOwner(Table)}
+ *
+ * @since 3.1
+ */
+public class GetTableContainer implements IJavaQuery2<Table, EObject> {
+
+ /**
+ * @see org.eclipse.papyrus.emf.facet.query.java.core.IJavaQuery2#evaluate(org.eclipse.emf.ecore.EObject, org.eclipse.papyrus.emf.facet.query.java.core.IParameterValueList2, org.eclipse.papyrus.emf.facet.efacet.core.IFacetManager)
+ *
+ * @param source
+ * @param parameterValues
+ * @param facetManager
+ * @return
+ * @throws DerivedTypedElementException
+ */
+ @Override
+ public EObject evaluate(Table source, IParameterValueList2 parameterValues, IFacetManager facetManager) throws DerivedTypedElementException {
+ return source.getOwner() == null ? source.getContext() : source.getOwner();
+ }
+
+}
diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/ModelExplorerView.java b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/ModelExplorerView.java
index e2e9f837787..14594961776 100644
--- a/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/ModelExplorerView.java
+++ b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/ModelExplorerView.java
@@ -38,8 +38,6 @@ import org.eclipse.emf.common.command.Command;
import org.eclipse.emf.common.command.CommandStackListener;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EReference;
-import org.eclipse.emf.ecore.resource.Resource;
-import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.edit.domain.EditingDomain;
import org.eclipse.emf.edit.domain.IEditingDomainProvider;
import org.eclipse.emf.transaction.ResourceSetChangeEvent;
@@ -50,6 +48,7 @@ import org.eclipse.emf.transaction.TransactionalEditingDomain;
import org.eclipse.jface.util.Policy;
import org.eclipse.jface.viewers.ColumnViewerToolTipSupport;
import org.eclipse.jface.viewers.DoubleClickEvent;
+import org.eclipse.jface.viewers.IContentProvider;
import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
@@ -63,9 +62,7 @@ import org.eclipse.jface.window.ToolTip;
import org.eclipse.papyrus.commands.DestroyElementPapyrusCommand;
import org.eclipse.papyrus.infra.core.resource.IReadOnlyHandler2;
import org.eclipse.papyrus.infra.core.resource.IReadOnlyListener;
-import org.eclipse.papyrus.infra.core.resource.ModelSet;
import org.eclipse.papyrus.infra.core.resource.ReadOnlyEvent;
-import org.eclipse.papyrus.infra.core.resource.additional.AdditionalResourcesModel;
import org.eclipse.papyrus.infra.core.sasheditor.editor.IPage;
import org.eclipse.papyrus.infra.core.sasheditor.editor.IPageLifeCycleEventsListener;
import org.eclipse.papyrus.infra.core.sasheditor.editor.ISashWindowsContainer;
@@ -87,6 +84,7 @@ import org.eclipse.papyrus.infra.ui.editor.reload.EditorReloadAdapter;
import org.eclipse.papyrus.infra.ui.editor.reload.EditorReloadEvent;
import org.eclipse.papyrus.infra.ui.editor.reload.TreeViewerContext;
import org.eclipse.papyrus.infra.ui.emf.providers.SemanticFromModelExplorer;
+import org.eclipse.papyrus.infra.ui.emf.utils.ProviderHelper;
import org.eclipse.papyrus.infra.ui.lifecycleevents.IEditorInputChangedListener;
import org.eclipse.papyrus.infra.ui.lifecycleevents.ISaveAndDirtyService;
import org.eclipse.papyrus.infra.widgets.editors.StringWithClearEditor;
@@ -94,10 +92,7 @@ import org.eclipse.papyrus.infra.widgets.providers.PatternViewerFilter;
import org.eclipse.papyrus.infra.widgets.util.IRevealSemanticElement;
import org.eclipse.papyrus.views.modelexplorer.SharedModelExplorerState.StateChangedEvent;
import org.eclipse.papyrus.views.modelexplorer.listener.DoubleClickListener;
-import org.eclipse.papyrus.views.modelexplorer.matching.IMatchingItem;
-import org.eclipse.papyrus.views.modelexplorer.matching.LinkItemMatchingItem;
import org.eclipse.papyrus.views.modelexplorer.matching.ModelElementItemMatchingItem;
-import org.eclipse.papyrus.views.modelexplorer.matching.ReferencableMatchingItem;
import org.eclipse.papyrus.views.modelexplorer.preferences.IFilterPreferenceConstants;
import org.eclipse.papyrus.views.modelexplorer.preferences.INavigatorPreferenceConstants;
import org.eclipse.swt.SWT;
@@ -142,7 +137,6 @@ import org.eclipse.ui.views.properties.tabbed.ITabbedPropertySheetPageContributo
import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetPage;
import com.google.common.base.Supplier;
-import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
/**
@@ -1167,94 +1161,17 @@ public class ModelExplorerView extends CommonNavigator implements IRevealSemanti
* The CommonViewer they are to be revealed in
*/
public static void reveal(Iterable<?> elementList, final CommonViewer commonViewer) {
- ArrayList<IMatchingItem> matchingItemsToSelect = new ArrayList<>();
- // filter out non EMF objects
- Iterable<EObject> list = Iterables.filter(elementList, EObject.class);
-
- for (EObject currentEObject : list) {
- matchingItemsToSelect.add(new ModelElementItemMatchingItem(currentEObject));
-
- // the content provider exist?
- if (commonViewer.getContentProvider() != null) {
- // retrieve the ancestors to reveal them
- // and allow the selection of the object
- ArrayList<EObject> parents = new ArrayList<>();
- EObject tmp = currentEObject.eContainer();
- while (tmp != null) {
- parents.add(tmp);
- tmp = tmp.eContainer();
- }
-
- Iterable<EObject> reverseParents = Lists.reverse(parents);
-
- // reveal the resource if necessary
- Resource r = null;
- if (!parents.isEmpty()) {
- r = parents.get(parents.size() - 1).eResource();
- } else {
- r = currentEObject.eResource();
- }
-
- if (r != null) {
- final ResourceSet rs = r.getResourceSet();
- final Resource resource = r;
- if (rs instanceof ModelSet && AdditionalResourcesModel.isAdditionalResource((ModelSet) rs, r.getURI())) {
- commonViewer.getControl().getDisplay().syncExec(new Runnable() {
-
- @Override
- public void run() {
- commonViewer.expandToLevel(new ReferencableMatchingItem(rs), 1);
- commonViewer.expandToLevel(new ReferencableMatchingItem(resource), 1);
- }
- });
-
- }
- }
-
- /*
- * reveal the ancestors tree using expandToLevel on each of them
- * in the good order. This is a lot faster than going through the whole tree
- * using getChildren of the ContentProvider since our Viewer uses a Hashtable
- * to keep track of the revealed elements.
- *
- * However we need to use a dedicated MatchingItem to do the matching,
- * and a specific comparer in our viewer so than the equals of MatchingItem is
- * used in priority.
- *
- * Please refer to MatchingItem for more infos.
- */
- EObject previousParent = null;
- for (EObject parent : reverseParents) {
- if (parent.eContainingFeature() != null && previousParent != null) {
- commonViewer.expandToLevel(new LinkItemMatchingItem(previousParent, parent.eContainmentFeature()), 1);
- }
-
- final IMatchingItem itemToExpand = new ModelElementItemMatchingItem(parent);
-
- commonViewer.getControl().getDisplay().syncExec(new Runnable() {
-
- @Override
- public void run() {
- commonViewer.expandToLevel(itemToExpand, 1);
- }
- });
-
- previousParent = parent;
- }
-
- final IMatchingItem itemToExpand = new LinkItemMatchingItem(currentEObject.eContainer(), currentEObject.eContainmentFeature());
-
- commonViewer.getControl().getDisplay().syncExec(new Runnable() {
-
- @Override
- public void run() {
- commonViewer.expandToLevel(itemToExpand, 1);
- }
- });
+ List<EObject> selectionList = new ArrayList<>();
+ for (Object element : elementList) {
+ if (element instanceof EObject) {
+ selectionList.add((EObject) element);
}
}
-
- selectReveal(new StructuredSelection(matchingItemsToSelect), commonViewer);
+ if (selectionList.isEmpty()) {
+ return;
+ }
+
+ Display.getDefault().syncExec(() -> ProviderHelper.selectReveal(selectionList, commonViewer));
}
/**
diff --git a/tests/junit/plugins/views/org.eclipse.papyrus.views.modelexplorer.tests/src/org/eclipse/papyrus/views/modelexplorer/tests/ModelExplorerViewTests.java b/tests/junit/plugins/views/org.eclipse.papyrus.views.modelexplorer.tests/src/org/eclipse/papyrus/views/modelexplorer/tests/ModelExplorerViewTests.java
index c53a653887f..9fcaa90e93f 100644
--- a/tests/junit/plugins/views/org.eclipse.papyrus.views.modelexplorer.tests/src/org/eclipse/papyrus/views/modelexplorer/tests/ModelExplorerViewTests.java
+++ b/tests/junit/plugins/views/org.eclipse.papyrus.views.modelexplorer.tests/src/org/eclipse/papyrus/views/modelexplorer/tests/ModelExplorerViewTests.java
@@ -75,7 +75,7 @@ public class ModelExplorerViewTests extends AbstractHandlerTest {
Assert.assertTrue("The active part is not the ModelExplorer", activePart instanceof ModelExplorerPageBookView); //$NON-NLS-1$
final IStructuredSelection currentSelection = getCurrentSelection();
- Assert.assertEquals("Only one element should be selected", currentSelection.size(), 1); //$NON-NLS-1$
+ Assert.assertEquals("Only one element should be selected", 1, currentSelection.size()); //$NON-NLS-1$
Object obj = currentSelection.getFirstElement();
obj = EMFHelper.getEObject(obj);
Assert.assertSame("The function revealSemanticElement seems doesn't work on the root of the model", obj, getRootOfTheModel()); //$NON-NLS-1$

Back to the top