Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLaurent Wouters2013-10-16 14:49:02 +0000
committerCamille Letavernier2013-11-18 13:59:01 +0000
commitb1016a6d67c1aa22532356683e3eb62942db3d4b (patch)
treecb0e9277d4dfc0d942f4cf3e149142615a5bdc4a
parente0daa6d33906a0152507de60ae953b55184bbc69 (diff)
downloadorg.eclipse.papyrus-b1016a6d67c1aa22532356683e3eb62942db3d4b.tar.gz
org.eclipse.papyrus-b1016a6d67c1aa22532356683e3eb62942db3d4b.tar.xz
org.eclipse.papyrus-b1016a6d67c1aa22532356683e3eb62942db3d4b.zip
Refactored the EMF facet queries that need only iterate over the notation resources
Signed-off-by: Laurent Wouters <laurent.wouters@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/nattable/org.eclipse.papyrus.infra.nattable.modelexplorer/META-INF/MANIFEST.MF3
-rw-r--r--plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.modelexplorer/src/org/eclipse/papyrus/infra/nattable/modelexplorer/queries/GetContainedTables.java39
-rw-r--r--plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.modelexplorer/src/org/eclipse/papyrus/infra/nattable/modelexplorer/queries/IsTableContainer.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
11 files changed, 249 insertions, 170 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 c27a051bf40..35221d2ab62 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 cb1c209789b..07a423e048f 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 b6ea0b02f61..1aa786b4f3d 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 e4ec7d72230..e4e95c79d73 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/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 085bcb3762f..ffe59c92ab5 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
@@ -13,8 +13,7 @@ Require-Bundle: org.eclipse.ui,
org.eclipse.papyrus.infra.widgets;bundle-version="1.0.0",
org.eclipse.papyrus.infra.gmfdiag.commands;bundle-version="1.0.0",
org.eclipse.gmf.runtime.emf.type.core,
- org.eclipse.core.expressions,
- com.google.guava
+ org.eclipse.core.expressions
Export-Package: org.eclipse.papyrus.infra.nattable.modelexplorer,
org.eclipse.papyrus.infra.nattable.modelexplorer.handlers,
org.eclipse.papyrus.infra.nattable.modelexplorer.messages,
diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.modelexplorer/src/org/eclipse/papyrus/infra/nattable/modelexplorer/queries/GetContainedTables.java b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.modelexplorer/src/org/eclipse/papyrus/infra/nattable/modelexplorer/queries/GetContainedTables.java
index ee0b8b81bb3..414660dec0b 100644
--- a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.modelexplorer/src/org/eclipse/papyrus/infra/nattable/modelexplorer/queries/GetContainedTables.java
+++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.modelexplorer/src/org/eclipse/papyrus/infra/nattable/modelexplorer/queries/GetContainedTables.java
@@ -11,37 +11,36 @@
*****************************************************************************/
package org.eclipse.papyrus.infra.nattable.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.gmf.runtime.notation.Diagram;
import org.eclipse.papyrus.infra.nattable.model.nattable.Table;
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 tables */
-public class GetContainedTables extends AbstractEditorContainerQuery implements IJavaModelQuery<EObject, Collection<org.eclipse.papyrus.infra.nattable.model.nattable.Table>> {
-
- public Collection<org.eclipse.papyrus.infra.nattable.model.nattable.Table> 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 Table;
+public class GetContainedTables extends AbstractEditorContainerQuery implements IJavaModelQuery<EObject, Collection<Table>> {
+
+ public Collection<Table> evaluate(final EObject context, final ParameterValueList parameterValues) throws ModelQueryExecutionException {
+ List<Table> result = new ArrayList<Table>(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(((Table)root).getContext(), context))
+ result.add((Table)root);
}
- };
- Function<EStructuralFeature.Setting, Table> f = new Function<EStructuralFeature.Setting, Table>() {
-
- public Table apply(EStructuralFeature.Setting arg0) {
- return (Table)arg0.getEObject();
- }
-
- };
- return NavigatorUtils.findFilterAndApply(context, p, f);
+ }
+ return result;
}
}
diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.modelexplorer/src/org/eclipse/papyrus/infra/nattable/modelexplorer/queries/IsTableContainer.java b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.modelexplorer/src/org/eclipse/papyrus/infra/nattable/modelexplorer/queries/IsTableContainer.java
index fa86a2c332f..ef5dba8d2f3 100644
--- a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.modelexplorer/src/org/eclipse/papyrus/infra/nattable/modelexplorer/queries/IsTableContainer.java
+++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.modelexplorer/src/org/eclipse/papyrus/infra/nattable/modelexplorer/queries/IsTableContainer.java
@@ -11,30 +11,33 @@
*****************************************************************************/
package org.eclipse.papyrus.infra.nattable.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.nattable.model.nattable.NattablePackage;
import org.eclipse.papyrus.infra.nattable.model.nattable.Table;
import org.eclipse.papyrus.views.modelexplorer.NavigatorUtils;
import org.eclipse.papyrus.views.modelexplorer.queries.AbstractEditorContainerQuery;
-import com.google.common.base.Predicate;
-
public class IsTableContainer 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 Table && ((Table)arg0).getContext() == context;
+ Iterator<EObject> roots = NavigatorUtils.getNotationRoots(context);
+ if (roots == null)
+ return false;
+ while (roots.hasNext()) {
+ EObject root = roots.next();
+ if (root instanceof Table) {
+ if (EcoreUtil.equals(((Table)root).getContext(), context))
+ return true;
}
- };
-
- return NavigatorUtils.any(context, NattablePackage.eINSTANCE.getTable(), 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 b77828352f3..2afb7c89239 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="1.0.0",
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 85cbf8698ac..d394f0f961b 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 fd0bba7267d..86a868ba216 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 938b037ab89..84453d1167b 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

Back to the top