summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLaurent Wouters2013-11-18 10:52:36 (EST)
committerCamille Letavernier2013-11-18 10:52:36 (EST)
commitccda2811a197106c52b6721a5b8148fac3106531 (patch)
tree86821a84caef6e9e9759e3435251f1919751e0f9
parent849d032c694b3027fbc08311f9f7d17b99b231a6 (diff)
downloadorg.eclipse.papyrus-ccda2811a197106c52b6721a5b8148fac3106531.zip
org.eclipse.papyrus-ccda2811a197106c52b6721a5b8148fac3106531.tar.gz
org.eclipse.papyrus-ccda2811a197106c52b6721a5b8148fac3106531.tar.bz2
Refactored the EMF facet queries that need only iterate over the
notation resources Conflicts: Cherry picked from b1016a in master. One of the plug-ins doesn't exist in Kepler. The files have been excluded from the cherry pick. Signed-off-by: Laurent Wouters <laurent.wouters@cea.fr> Alsy-by: Camille Letavernier <camille.letavernier@cea.fr>
-rw-r--r--extraplugins/codegen/org.eclipse.papyrus.texteditor.modelexplorer/src/org/eclipse/papyrus/texteditor/modelexplorer/queries/GetContainedTextEditors.java49
-rw-r--r--extraplugins/codegen/org.eclipse.papyrus.texteditor.modelexplorer/src/org/eclipse/papyrus/texteditor/modelexplorer/queries/IsTextEditorContainer.java30
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.modelexplorer/src/org/eclipse/papyrus/infra/gmfdiag/modelexplorer/queries/GetContainedDiagrams.java34
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.modelexplorer/src/org/eclipse/papyrus/infra/gmfdiag/modelexplorer/queries/IsDiagramContainer.java23
-rw-r--r--plugins/infra/table/org.eclipse.papyrus.infra.table.modelexplorer/META-INF/MANIFEST.MF1
-rw-r--r--plugins/infra/table/org.eclipse.papyrus.infra.table.modelexplorer/src/org/eclipse/papyrus/infra/table/modelexplorer/queries/GetContainedTables.java59
-rw-r--r--plugins/infra/table/org.eclipse.papyrus.infra.table.modelexplorer/src/org/eclipse/papyrus/infra/table/modelexplorer/queries/IsTableContainer.java28
-rw-r--r--plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/NavigatorUtils.java130
8 files changed, 216 insertions, 138 deletions
diff --git a/extraplugins/codegen/org.eclipse.papyrus.texteditor.modelexplorer/src/org/eclipse/papyrus/texteditor/modelexplorer/queries/GetContainedTextEditors.java b/extraplugins/codegen/org.eclipse.papyrus.texteditor.modelexplorer/src/org/eclipse/papyrus/texteditor/modelexplorer/queries/GetContainedTextEditors.java
index c27a051..35221d2 100644
--- a/extraplugins/codegen/org.eclipse.papyrus.texteditor.modelexplorer/src/org/eclipse/papyrus/texteditor/modelexplorer/queries/GetContainedTextEditors.java
+++ b/extraplugins/codegen/org.eclipse.papyrus.texteditor.modelexplorer/src/org/eclipse/papyrus/texteditor/modelexplorer/queries/GetContainedTextEditors.java
@@ -15,22 +15,20 @@
package org.eclipse.papyrus.texteditor.modelexplorer.queries;
+import java.util.ArrayList;
import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.EStructuralFeature;
+import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.emf.facet.infra.query.core.exception.ModelQueryExecutionException;
import org.eclipse.emf.facet.infra.query.core.java.IJavaModelQuery;
import org.eclipse.emf.facet.infra.query.core.java.ParameterValueList;
-import org.eclipse.papyrus.infra.emf.utils.EMFHelper;
import org.eclipse.papyrus.texteditor.model.texteditormodel.TextEditorModel;
+import org.eclipse.papyrus.views.modelexplorer.NavigatorUtils;
import org.eclipse.papyrus.views.modelexplorer.queries.AbstractEditorContainerQuery;
-import com.google.common.base.Function;
-import com.google.common.base.Predicate;
-import com.google.common.collect.Iterables;
-import com.google.common.collect.Sets;
-
/** Get the collection of all contained tables */
//FIXME this query is declared using Element in the querySet -> change into EObject when the EMF-Facet bug will be corrected 365744
public class GetContainedTextEditors extends AbstractEditorContainerQuery implements IJavaModelQuery<EObject, Collection<TextEditorModel>> {
@@ -39,32 +37,17 @@ public class GetContainedTextEditors extends AbstractEditorContainerQuery implem
* {@inheritDoc}
*/
public Collection<TextEditorModel> evaluate(final EObject context, final ParameterValueList parameterValues) throws ModelQueryExecutionException {
- Predicate<EStructuralFeature.Setting> p = new Predicate<EStructuralFeature.Setting>() {
-
- public boolean apply(EStructuralFeature.Setting setting) {
- return (setting.getEObject() instanceof TextEditorModel);
+ List<TextEditorModel> result = new ArrayList<TextEditorModel>(3);
+ Iterator<EObject> roots = NavigatorUtils.getNotationRoots(context);
+ if (roots == null)
+ return result;
+ while (roots.hasNext()) {
+ EObject root = roots.next();
+ if (root instanceof TextEditorModel) {
+ if (EcoreUtil.equals(((TextEditorModel)root).getEditedObject(), context))
+ result.add((TextEditorModel)root);
}
- };
-
- Function<EStructuralFeature.Setting, TextEditorModel> f = new Function<EStructuralFeature.Setting, TextEditorModel>() {
-
- public TextEditorModel apply(EStructuralFeature.Setting setting) {
- if (setting.getEObject() instanceof TextEditorModel) {
- return (TextEditorModel) setting.getEObject();
- }
- return null;
- }
-
- };
-
- Iterable<TextEditorModel> transform = Iterables.transform(Iterables.filter(EMFHelper.getUsages(context), p), f);
- transform = Iterables.filter(transform, new Predicate<TextEditorModel>() {
-
- public boolean apply(TextEditorModel table) {
- return table != null;
- }
- });
- return Sets.newHashSet(transform);
+ }
+ return result;
}
-
}
diff --git a/extraplugins/codegen/org.eclipse.papyrus.texteditor.modelexplorer/src/org/eclipse/papyrus/texteditor/modelexplorer/queries/IsTextEditorContainer.java b/extraplugins/codegen/org.eclipse.papyrus.texteditor.modelexplorer/src/org/eclipse/papyrus/texteditor/modelexplorer/queries/IsTextEditorContainer.java
index cb1c209..07a423e 100644
--- a/extraplugins/codegen/org.eclipse.papyrus.texteditor.modelexplorer/src/org/eclipse/papyrus/texteditor/modelexplorer/queries/IsTextEditorContainer.java
+++ b/extraplugins/codegen/org.eclipse.papyrus.texteditor.modelexplorer/src/org/eclipse/papyrus/texteditor/modelexplorer/queries/IsTextEditorContainer.java
@@ -14,17 +14,17 @@
*****************************************************************************/
package org.eclipse.papyrus.texteditor.modelexplorer.queries;
+import java.util.Iterator;
+
import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.emf.facet.infra.query.core.exception.ModelQueryExecutionException;
import org.eclipse.emf.facet.infra.query.core.java.IJavaModelQuery;
import org.eclipse.emf.facet.infra.query.core.java.ParameterValueList;
import org.eclipse.papyrus.texteditor.model.texteditormodel.TextEditorModel;
-import org.eclipse.papyrus.texteditor.model.texteditormodel.TextEditorModelPackage;
import org.eclipse.papyrus.views.modelexplorer.NavigatorUtils;
import org.eclipse.papyrus.views.modelexplorer.queries.AbstractEditorContainerQuery;
-import com.google.common.base.Predicate;
-
/** Returns true if the element contains a Table */
//FIXME this query is declared using Element in the querySet -> change into EObject when the EMF-Facet bug will be corrected 365744
public class IsTextEditorContainer extends AbstractEditorContainerQuery implements IJavaModelQuery<EObject, Boolean> {
@@ -33,20 +33,16 @@ public class IsTextEditorContainer extends AbstractEditorContainerQuery implemen
* {@inheritDoc}
*/
public Boolean evaluate(final EObject context, ParameterValueList parameterValues) throws ModelQueryExecutionException {
- Predicate<EObject> p = new Predicate<EObject>() {
-
- public boolean apply(EObject arg0) {
- if(arg0 instanceof TextEditorModel) {
- TextEditorModel textEditorInstance = (TextEditorModel)arg0;
- if (textEditorInstance.getEditedObject() == context) {
- // System.err.println("isContainer = true: " + context); //$NON-NLS-1$
- }
- return (textEditorInstance.getEditedObject() == context);
- }
- return false;
+ Iterator<EObject> roots = NavigatorUtils.getNotationRoots(context);
+ if (roots == null)
+ return false;
+ while (roots.hasNext()) {
+ EObject root = roots.next();
+ if (root instanceof TextEditorModel) {
+ if (EcoreUtil.equals(((TextEditorModel)root).getEditedObject(), context))
+ return true;
}
- };
-
- return NavigatorUtils.any(context, TextEditorModelPackage.eINSTANCE.getTextEditorModel(), false, p);
+ }
+ return false;
}
}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.modelexplorer/src/org/eclipse/papyrus/infra/gmfdiag/modelexplorer/queries/GetContainedDiagrams.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.modelexplorer/src/org/eclipse/papyrus/infra/gmfdiag/modelexplorer/queries/GetContainedDiagrams.java
index b6ea0b0..1aa786b 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.modelexplorer/src/org/eclipse/papyrus/infra/gmfdiag/modelexplorer/queries/GetContainedDiagrams.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.modelexplorer/src/org/eclipse/papyrus/infra/gmfdiag/modelexplorer/queries/GetContainedDiagrams.java
@@ -12,10 +12,13 @@
*/
package org.eclipse.papyrus.infra.gmfdiag.modelexplorer.queries;
+import java.util.ArrayList;
import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.EStructuralFeature;
+import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.emf.facet.infra.query.core.exception.ModelQueryExecutionException;
import org.eclipse.emf.facet.infra.query.core.java.IJavaModelQuery;
import org.eclipse.emf.facet.infra.query.core.java.ParameterValueList;
@@ -23,26 +26,21 @@ import org.eclipse.gmf.runtime.notation.Diagram;
import org.eclipse.papyrus.views.modelexplorer.NavigatorUtils;
import org.eclipse.papyrus.views.modelexplorer.queries.AbstractEditorContainerQuery;
-import com.google.common.base.Function;
-import com.google.common.base.Predicate;
-
/** Get the collection of all contained diagrams */
public class GetContainedDiagrams extends AbstractEditorContainerQuery implements IJavaModelQuery<EObject, Collection<org.eclipse.gmf.runtime.notation.Diagram>> {
- public Collection<org.eclipse.gmf.runtime.notation.Diagram> evaluate(final EObject context, final ParameterValueList parameterValues) throws ModelQueryExecutionException {
- Predicate<EStructuralFeature.Setting> p = new Predicate<EStructuralFeature.Setting>() {
-
- public boolean apply(EStructuralFeature.Setting arg0) {
- return arg0.getEObject() instanceof Diagram;
+ public Collection<Diagram> evaluate(final EObject context, final ParameterValueList parameterValues) throws ModelQueryExecutionException {
+ List<Diagram> result = new ArrayList<Diagram>(3);
+ Iterator<EObject> roots = NavigatorUtils.getNotationRoots(context);
+ if (roots == null)
+ return result;
+ while (roots.hasNext()) {
+ EObject root = roots.next();
+ if (root instanceof Diagram) {
+ if (EcoreUtil.equals(((Diagram)root).getElement(), context))
+ result.add((Diagram)root);
}
- };
- Function<EStructuralFeature.Setting, Diagram> f = new Function<EStructuralFeature.Setting, Diagram>() {
-
- public Diagram apply(EStructuralFeature.Setting arg0) {
- return (Diagram)arg0.getEObject();
- }
-
- };
- return NavigatorUtils.findFilterAndApply(context, p, f);
+ }
+ return result;
}
}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.modelexplorer/src/org/eclipse/papyrus/infra/gmfdiag/modelexplorer/queries/IsDiagramContainer.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.modelexplorer/src/org/eclipse/papyrus/infra/gmfdiag/modelexplorer/queries/IsDiagramContainer.java
index e4ec7d7..e4e95c7 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.modelexplorer/src/org/eclipse/papyrus/infra/gmfdiag/modelexplorer/queries/IsDiagramContainer.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.modelexplorer/src/org/eclipse/papyrus/infra/gmfdiag/modelexplorer/queries/IsDiagramContainer.java
@@ -12,30 +12,33 @@
*/
package org.eclipse.papyrus.infra.gmfdiag.modelexplorer.queries;
+import java.util.Iterator;
+
import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.emf.facet.infra.query.core.exception.ModelQueryExecutionException;
import org.eclipse.emf.facet.infra.query.core.java.IJavaModelQuery;
import org.eclipse.emf.facet.infra.query.core.java.ParameterValueList;
import org.eclipse.gmf.runtime.notation.Diagram;
-import org.eclipse.gmf.runtime.notation.NotationPackage;
import org.eclipse.papyrus.views.modelexplorer.NavigatorUtils;
import org.eclipse.papyrus.views.modelexplorer.queries.AbstractEditorContainerQuery;
-import com.google.common.base.Predicate;
-
public class IsDiagramContainer extends AbstractEditorContainerQuery implements IJavaModelQuery<EObject, Boolean> {
/**
* Return true if the element is a Diagram Container
*/
public Boolean evaluate(final EObject context, ParameterValueList parameterValues) throws ModelQueryExecutionException {
- Predicate<EObject> p = new Predicate<EObject>() {
-
- public boolean apply(EObject arg0) {
- return arg0 instanceof Diagram && ((Diagram)arg0).getElement() == context;
+ Iterator<EObject> roots = NavigatorUtils.getNotationRoots(context);
+ if (roots == null)
+ return false;
+ while (roots.hasNext()) {
+ EObject root = roots.next();
+ if (root instanceof Diagram) {
+ if (EcoreUtil.equals(((Diagram)root).getElement(), context))
+ return true;
}
- };
-
- return NavigatorUtils.any(context, NotationPackage.eINSTANCE.getDiagram(), false, p);
+ }
+ return false;
}
}
diff --git a/plugins/infra/table/org.eclipse.papyrus.infra.table.modelexplorer/META-INF/MANIFEST.MF b/plugins/infra/table/org.eclipse.papyrus.infra.table.modelexplorer/META-INF/MANIFEST.MF
index 8c55ade..4720188 100644
--- a/plugins/infra/table/org.eclipse.papyrus.infra.table.modelexplorer/META-INF/MANIFEST.MF
+++ b/plugins/infra/table/org.eclipse.papyrus.infra.table.modelexplorer/META-INF/MANIFEST.MF
@@ -11,7 +11,6 @@ Require-Bundle: org.eclipse.emf.facet.infra.browser.uicore;bundle-version="0.1.0
org.eclipse.emf.transaction;bundle-version="1.4.0",
org.eclipse.gmf.runtime.common.core;bundle-version="1.4.1",
org.eclipse.gmf.runtime.emf.commands.core;bundle-version="1.4.0",
- com.google.guava;bundle-version="10.0.1",
org.eclipse.gmf.runtime.emf.type.core;bundle-version="1.4.0",
org.eclipse.papyrus.infra.core.sasheditor;bundle-version="0.10.1",
org.eclipse.jface;bundle-version="3.8.0",
diff --git a/plugins/infra/table/org.eclipse.papyrus.infra.table.modelexplorer/src/org/eclipse/papyrus/infra/table/modelexplorer/queries/GetContainedTables.java b/plugins/infra/table/org.eclipse.papyrus.infra.table.modelexplorer/src/org/eclipse/papyrus/infra/table/modelexplorer/queries/GetContainedTables.java
index 85cbf86..d394f0f 100644
--- a/plugins/infra/table/org.eclipse.papyrus.infra.table.modelexplorer/src/org/eclipse/papyrus/infra/table/modelexplorer/queries/GetContainedTables.java
+++ b/plugins/infra/table/org.eclipse.papyrus.infra.table.modelexplorer/src/org/eclipse/papyrus/infra/table/modelexplorer/queries/GetContainedTables.java
@@ -14,27 +14,20 @@
package org.eclipse.papyrus.infra.table.modelexplorer.queries;
+import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
+import java.util.List;
import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.EStructuralFeature;
-import org.eclipse.emf.ecore.EStructuralFeature.Setting;
+import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.emf.facet.infra.query.core.exception.ModelQueryExecutionException;
import org.eclipse.emf.facet.infra.query.core.java.IJavaModelQuery;
import org.eclipse.emf.facet.infra.query.core.java.ParameterValueList;
-import org.eclipse.emf.facet.widgets.nattable.instance.tableinstance.TableInstance;
-import org.eclipse.emf.facet.widgets.nattable.instance.tableinstance.TableinstancePackage;
-import org.eclipse.papyrus.infra.emf.utils.EMFHelper;
import org.eclipse.papyrus.infra.table.instance.papyrustableinstance.PapyrusTableInstance;
-import org.eclipse.papyrus.infra.table.instance.papyrustableinstance.PapyrustableinstancePackage;
+import org.eclipse.papyrus.views.modelexplorer.NavigatorUtils;
import org.eclipse.papyrus.views.modelexplorer.queries.AbstractEditorContainerQuery;
-import com.google.common.base.Function;
-import com.google.common.base.Predicate;
-import com.google.common.collect.Iterables;
-import com.google.common.collect.Sets;
-
/** Get the collection of all contained tables */
//FIXME this query is declared using Element in the querySet -> change into EObject when the EMF-Facet bug will be corrected 365744
public class GetContainedTables extends AbstractEditorContainerQuery implements IJavaModelQuery<EObject, Collection<PapyrusTableInstance>> {
@@ -43,39 +36,17 @@ public class GetContainedTables extends AbstractEditorContainerQuery implements
* {@inheritDoc}
*/
public Collection<PapyrusTableInstance> evaluate(final EObject context, final ParameterValueList parameterValues) throws ModelQueryExecutionException {
- Predicate<EStructuralFeature.Setting> p = new Predicate<EStructuralFeature.Setting>() {
-
- public boolean apply(EStructuralFeature.Setting setting) {
- return setting.getEObject() instanceof TableInstance && setting.getEStructuralFeature() == TableinstancePackage.Literals.TABLE_INSTANCE__CONTEXT;
- }
- };
- Function<EStructuralFeature.Setting, PapyrusTableInstance> f = new Function<EStructuralFeature.Setting, PapyrusTableInstance>() {
-
- public PapyrusTableInstance apply(EStructuralFeature.Setting setting) {
- Collection<Setting> references = EMFHelper.getUsages(setting.getEObject());
- Predicate<Setting> p2 = new Predicate<EStructuralFeature.Setting>() {
-
- public boolean apply(Setting setting) {
- return setting.getEObject() instanceof PapyrusTableInstance && PapyrustableinstancePackage.Literals.PAPYRUS_TABLE_INSTANCE__TABLE == setting.getEStructuralFeature();
- }
- };
- Iterator<Setting> iterator = Iterables.filter(references, p2).iterator();
- if(iterator.hasNext()) {
- return (PapyrusTableInstance)iterator.next().getEObject();
- }
- return null;
+ List<PapyrusTableInstance> result = new ArrayList<PapyrusTableInstance>(3);
+ Iterator<EObject> roots = NavigatorUtils.getNotationRoots(context);
+ if (roots == null)
+ return result;
+ while (roots.hasNext()) {
+ EObject root = roots.next();
+ if (root instanceof PapyrusTableInstance) {
+ if (EcoreUtil.equals(((PapyrusTableInstance)root).getTable().getContext(), context))
+ result.add((PapyrusTableInstance)root);
}
-
- };
-
- Iterable<PapyrusTableInstance> transform = Iterables.transform(Iterables.filter(EMFHelper.getUsages(context), p), f);
- transform = Iterables.filter(transform, new Predicate<PapyrusTableInstance>() {
-
- public boolean apply(PapyrusTableInstance table) {
- return table != null;
- }
- });
- return Sets.newHashSet(transform);
+ }
+ return result;
}
-
}
diff --git a/plugins/infra/table/org.eclipse.papyrus.infra.table.modelexplorer/src/org/eclipse/papyrus/infra/table/modelexplorer/queries/IsTableContainer.java b/plugins/infra/table/org.eclipse.papyrus.infra.table.modelexplorer/src/org/eclipse/papyrus/infra/table/modelexplorer/queries/IsTableContainer.java
index fd0bba7..86a868b 100644
--- a/plugins/infra/table/org.eclipse.papyrus.infra.table.modelexplorer/src/org/eclipse/papyrus/infra/table/modelexplorer/queries/IsTableContainer.java
+++ b/plugins/infra/table/org.eclipse.papyrus.infra.table.modelexplorer/src/org/eclipse/papyrus/infra/table/modelexplorer/queries/IsTableContainer.java
@@ -13,17 +13,17 @@
*****************************************************************************/
package org.eclipse.papyrus.infra.table.modelexplorer.queries;
+import java.util.Iterator;
+
import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.emf.facet.infra.query.core.exception.ModelQueryExecutionException;
import org.eclipse.emf.facet.infra.query.core.java.IJavaModelQuery;
import org.eclipse.emf.facet.infra.query.core.java.ParameterValueList;
import org.eclipse.papyrus.infra.table.instance.papyrustableinstance.PapyrusTableInstance;
-import org.eclipse.papyrus.infra.table.instance.papyrustableinstance.PapyrustableinstancePackage;
import org.eclipse.papyrus.views.modelexplorer.NavigatorUtils;
import org.eclipse.papyrus.views.modelexplorer.queries.AbstractEditorContainerQuery;
-import com.google.common.base.Predicate;
-
/** Returns true if the element contains a Table */
//FIXME this query is declared using Element in the querySet -> change into EObject when the EMF-Facet bug will be corrected 365744
public class IsTableContainer extends AbstractEditorContainerQuery implements IJavaModelQuery<EObject, Boolean> {
@@ -32,18 +32,16 @@ public class IsTableContainer extends AbstractEditorContainerQuery implements IJ
* {@inheritDoc}
*/
public Boolean evaluate(final EObject context, ParameterValueList parameterValues) throws ModelQueryExecutionException {
- Predicate<EObject> p = new Predicate<EObject>() {
-
- public boolean apply(EObject arg0) {
- if(arg0 instanceof PapyrusTableInstance) {
- PapyrusTableInstance tableInstance = (PapyrusTableInstance)arg0;
- return (tableInstance.getTable() != null && tableInstance.getTable().getContext() == context);
-
- }
- return false;
+ Iterator<EObject> roots = NavigatorUtils.getNotationRoots(context);
+ if (roots == null)
+ return false;
+ while (roots.hasNext()) {
+ EObject root = roots.next();
+ if (root instanceof PapyrusTableInstance) {
+ if (EcoreUtil.equals(((PapyrusTableInstance)root).getTable().getContext(), context))
+ return true;
}
- };
-
- return NavigatorUtils.any(context, PapyrustableinstancePackage.eINSTANCE.getPapyrusTableInstance(), false, p);
+ }
+ return false;
}
}
diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/NavigatorUtils.java b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/NavigatorUtils.java
index 938b037..84453d1 100644
--- a/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/NavigatorUtils.java
+++ b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/NavigatorUtils.java
@@ -62,6 +62,136 @@ import com.google.common.collect.Lists;
public class NavigatorUtils {
/**
+ * Gets the roots of the notations resources related to the given object
+ * @param element The object from which to retrieve the notation resources
+ * @return An iterator of notation resources' roots, or <code>null</code> if none cannot be resolved
+ */
+ public static Iterator<EObject> getNotationRoots(EObject element) {
+ Iterator<Resource> notations = getNotationResources(element);
+ if (notations == null)
+ return null;
+ return new RootsIterator(notations);
+ }
+
+ /**
+ * Represents an iterator on all the roots of the notations resources of a ResourceSet
+ * @author Laurent Wouters
+ */
+ private static class RootsIterator implements Iterator<EObject> {
+ private Iterator<Resource> notations;
+ private Iterator<EObject> inner;
+
+ public RootsIterator(Iterator<Resource> notations) {
+ this.notations = notations;
+ if (notations.hasNext())
+ inner = notations.next().getAllContents();
+ }
+
+ public boolean hasNext() {
+ if (inner == null)
+ return false;
+ if (inner.hasNext())
+ return true;
+ while (notations.hasNext()) {
+ inner = notations.next().getAllContents();
+ if (inner.hasNext())
+ return true;
+ }
+ inner = null;
+ return false;
+ }
+
+ public EObject next() {
+ if (inner == null)
+ return null;
+ if (inner.hasNext())
+ return inner.next();
+ while (notations.hasNext()) {
+ inner = notations.next().getAllContents();
+ if (inner.hasNext())
+ return inner.next();
+ }
+ inner = null;
+ return null;
+ }
+
+ public void remove() {
+ throw new UnsupportedOperationException();
+ }
+ }
+
+
+ /**
+ * Gets the notation resources related to the given object
+ * @param element The object from which to retrieve the notation resources
+ * @return An iterator of notation resources, or <code>null</code> if none cannot be resolved
+ */
+ public static Iterator<Resource> getNotationResources(EObject element) {
+ Iterator<Resource> result = tryGetNotationResources(element);
+ if (result != null)
+ return result;
+ IAdaptable input = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getInput();
+ if (input != null) {
+ EObject obj = (EObject) input.getAdapter(EObject.class);
+ return tryGetNotationResources(obj);
+ }
+ return null;
+ }
+
+ /**
+ * Tries to get the notation resources related to the given object
+ * @param element The object from which to retrieve the notation resources
+ * @return An iterator of notation resources, or <code>null</code> if none cannot be resolved
+ */
+ private static Iterator<Resource> tryGetNotationResources(EObject element) {
+ if (element == null)
+ return null;
+ if (element.eResource() == null)
+ return null;
+ return new NotationsIterator(element.eResource().getResourceSet());
+ }
+
+
+ /**
+ * Represents an iterator over the notation resources of a ResourceSet
+ * @author Laurent Wouters
+ */
+ private static class NotationsIterator implements Iterator<Resource> {
+ private Iterator<Resource> inner;
+ private Resource next;
+
+ public NotationsIterator(ResourceSet set) {
+ inner = set.getResources().iterator();
+ next = getNextNotation();
+ }
+
+ private Resource getNextNotation() {
+ while (inner.hasNext()) {
+ Resource resource = inner.next();
+ String uri = resource.getURI().toString();
+ if (uri.endsWith(".notation"))
+ return resource;
+ }
+ return null;
+ }
+
+ public boolean hasNext() {
+ return (next != null);
+ }
+
+ public Resource next() {
+ Resource result = next;
+ next = getNextNotation();
+ return result;
+ }
+
+ public void remove() {
+ throw new UnsupportedOperationException();
+ }
+ }
+
+
+ /**
* Find a <IViewPart> by it's id string.
*
* @param viewID