summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLaurent Wouters2014-07-04 05:31:20 (EDT)
committerCamille Letavernier2014-07-21 08:26:02 (EDT)
commit8e8434454d81efa2d9a8487f40c63aa9914e966d (patch)
tree891d04b96637e6d0a361a5d5c7ec3fe6d0ebd05b
parent09adec7c19b4076b782d4bd0b8cec635ab6e2807 (diff)
downloadorg.eclipse.papyrus-8e8434454d81efa2d9a8487f40c63aa9914e966d.zip
org.eclipse.papyrus-8e8434454d81efa2d9a8487f40c63aa9914e966d.tar.gz
org.eclipse.papyrus-8e8434454d81efa2d9a8487f40c63aa9914e966d.tar.bz2
Exposed viewpoint API for counting views on objectsrefs/changes/49/29449/2
This API will be required by Sophia Change-Id: Ia8f083b01453a28a46e1ef4c66cf1be7bcd18e0a Signed-off-by: Laurent Wouters <laurent.wouters@cea.fr>
-rwxr-xr-xplugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/src/org/eclipse/papyrus/infra/viewpoints/policy/PolicyChecker.java61
-rwxr-xr-xplugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/src/org/eclipse/papyrus/infra/viewpoints/policy/ViewPrototype.java54
2 files changed, 58 insertions, 57 deletions
diff --git a/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/src/org/eclipse/papyrus/infra/viewpoints/policy/PolicyChecker.java b/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/src/org/eclipse/papyrus/infra/viewpoints/policy/PolicyChecker.java
index 0280472..b7b51ba 100755
--- a/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/src/org/eclipse/papyrus/infra/viewpoints/policy/PolicyChecker.java
+++ b/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/src/org/eclipse/papyrus/infra/viewpoints/policy/PolicyChecker.java
@@ -17,7 +17,6 @@ package org.eclipse.papyrus.infra.viewpoints.policy;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
-import java.util.Iterator;
import java.util.List;
import java.util.Map;
@@ -467,7 +466,7 @@ public class PolicyChecker {
return false;
if (!matchesProfiles(prototype.configuration, profileHelper.getAppliedProfiles(element)))
return false;
- if (!matchesCreationRoot(prototype.configuration, element, profileHelper.getAppliedStereotypes(element), getViewCountOn(element, prototype)))
+ if (!matchesCreationRoot(prototype.configuration, element, profileHelper.getAppliedStereotypes(element), prototype.getViewCountOn(element)))
return false;
return true;
}
@@ -613,7 +612,7 @@ public class PolicyChecker {
ViewPrototype proto = ViewPrototype.get(view);
if (proto == null)
continue;
- int count = getOwnedViewCount(element, proto);
+ int count = proto.getOwnedViewCount(element);
OwningRule rule = matchesCreationOwner(view, element, stereotypes, count);
if (rule == null)
continue;
@@ -622,7 +621,7 @@ public class PolicyChecker {
result.add(proto);
} else {
// We have to check if the owner can also be a root
- count = getViewCountOn(element, proto);
+ count = proto.getViewCountOn(element);
if (matchesCreationRoot(view, element, stereotypes, count)) {
// The owner can also be the root => OK
result.add(proto);
@@ -644,64 +643,12 @@ public class PolicyChecker {
*/
public OwningRule getOwningRuleFor(ViewPrototype prototype, EObject owner) {
Collection<EClass> stereotypes = profileHelper.getAppliedStereotypes(owner);
- int count = getOwnedViewCount(owner, prototype);
+ int count = prototype.getOwnedViewCount(owner);
OwningRule rule = matchesCreationOwner(prototype.configuration, owner, stereotypes, count);
return rule;
}
/**
- * Gets the number of views of a given type owned by a given object
- *
- * @param element
- * The object to count views for
- * @param prototype
- * The prototype of view to counts
- * @return The number of owned views
- */
- private int getOwnedViewCount(EObject element, ViewPrototype prototype) {
- int count = 0;
- Iterator<EObject> roots = NotationUtils.getNotationRoots(element);
- if (roots == null)
- return count;
- while (roots.hasNext()) {
- EObject view = roots.next();
- ViewPrototype proto = ViewPrototype.get(view);
- if (prototype == proto) {
- EObject owner = proto.getOwnerOf(view);
- if (EcoreUtil.equals(owner, element))
- count++;
- }
- }
- return count;
- }
-
- /**
- * Gets the number of views of a given type on a given object
- *
- * @param element
- * The object to count views on
- * @param prototype
- * The prototype of view to counts
- * @return The number of views on the object
- */
- private int getViewCountOn(EObject element, ViewPrototype prototype) {
- int count = 0;
- Iterator<EObject> roots = NotationUtils.getNotationRoots(element);
- if (roots == null)
- return count;
- while (roots.hasNext()) {
- EObject view = roots.next();
- ViewPrototype proto = ViewPrototype.get(view);
- if (prototype == proto) {
- EObject root = proto.getRootOf(view);
- if (EcoreUtil.equals(root, element))
- count++;
- }
- }
- return count;
- }
-
- /**
* Tries to match a view configuration from the given info
*
* @param implem
diff --git a/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/src/org/eclipse/papyrus/infra/viewpoints/policy/ViewPrototype.java b/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/src/org/eclipse/papyrus/infra/viewpoints/policy/ViewPrototype.java
index 4fd6cf9..68db4ea 100755
--- a/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/src/org/eclipse/papyrus/infra/viewpoints/policy/ViewPrototype.java
+++ b/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/src/org/eclipse/papyrus/infra/viewpoints/policy/ViewPrototype.java
@@ -19,6 +19,7 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.Comparator;
import java.util.HashMap;
+import java.util.Iterator;
import java.util.Map;
import org.eclipse.core.runtime.CoreException;
@@ -30,6 +31,7 @@ import org.eclipse.core.runtime.Platform;
import org.eclipse.emf.common.command.Command;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.papyrus.infra.viewpoints.configuration.Category;
import org.eclipse.papyrus.infra.viewpoints.configuration.ModelRule;
@@ -420,4 +422,56 @@ public abstract class ViewPrototype {
}
}
}
+
+ /**
+ * Gets the number of views of this type owned by a given object
+ *
+ * @param element
+ * The object to count views for
+ * @param prototype
+ * The prototype of view to counts
+ * @return The number of owned views
+ */
+ public int getOwnedViewCount(EObject element) {
+ int count = 0;
+ Iterator<EObject> roots = NotationUtils.getNotationRoots(element);
+ if (roots == null)
+ return count;
+ while (roots.hasNext()) {
+ EObject view = roots.next();
+ ViewPrototype proto = ViewPrototype.get(view);
+ if (this == proto) {
+ EObject owner = proto.getOwnerOf(view);
+ if (EcoreUtil.equals(owner, element))
+ count++;
+ }
+ }
+ return count;
+ }
+
+ /**
+ * Gets the number of views of this type on a given object
+ *
+ * @param element
+ * The object to count views on
+ * @param prototype
+ * The prototype of view to counts
+ * @return The number of views on the object
+ */
+ public int getViewCountOn(EObject element) {
+ int count = 0;
+ Iterator<EObject> roots = NotationUtils.getNotationRoots(element);
+ if (roots == null)
+ return count;
+ while (roots.hasNext()) {
+ EObject view = roots.next();
+ ViewPrototype proto = ViewPrototype.get(view);
+ if (this == proto) {
+ EObject root = proto.getRootOf(view);
+ if (EcoreUtil.equals(root, element))
+ count++;
+ }
+ }
+ return count;
+ }
}