summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMickael ADAM2014-05-23 10:26:15 (EDT)
committerMickael ADAM2014-06-02 10:47:49 (EDT)
commit2aee0c0178fad99998f2e8df39d4c75c61bfa247 (patch)
tree35b2cec54bc4fbadf079e6f38252b56e256d77e0
parent91223cdd788217a737501d5450c27b537983935f (diff)
downloadorg.eclipse.papyrus-2aee0c0178fad99998f2e8df39d4c75c61bfa247.zip
org.eclipse.papyrus-2aee0c0178fad99998f2e8df39d4c75c61bfa247.tar.gz
org.eclipse.papyrus-2aee0c0178fad99998f2e8df39d4c75c61bfa247.tar.bz2
435644: [wizard] UML model creation wizard shall proposed all diagramsrefs/changes/18/27718/2
kind https://bugs.eclipse.org/bugs/show_bug.cgi?id=435644 Patch set 1: - Patch DiagramKingContentProvider to remove owner contrainte. Patch set 2: - Takes Laurent Wouters's comments into account. Change-Id: I0340dc8dc3c1c299fddc53f88ec2b5926ee2347d Signed-off-by: Mickael ADAM <mickael.adam@ALL4TEC.net>
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/src/org/eclipse/papyrus/uml/diagram/wizards/kind/DiagramKindContentProvider.java89
1 files changed, 31 insertions, 58 deletions
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/src/org/eclipse/papyrus/uml/diagram/wizards/kind/DiagramKindContentProvider.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/src/org/eclipse/papyrus/uml/diagram/wizards/kind/DiagramKindContentProvider.java
index da9ffb5..7238174 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/src/org/eclipse/papyrus/uml/diagram/wizards/kind/DiagramKindContentProvider.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/src/org/eclipse/papyrus/uml/diagram/wizards/kind/DiagramKindContentProvider.java
@@ -20,15 +20,11 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import org.eclipse.emf.ecore.EClass;
import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.papyrus.infra.viewpoints.configuration.Category;
-import org.eclipse.papyrus.infra.viewpoints.configuration.ModelRule;
-import org.eclipse.papyrus.infra.viewpoints.configuration.PapyrusView;
import org.eclipse.papyrus.infra.viewpoints.policy.PolicyChecker;
import org.eclipse.papyrus.infra.viewpoints.policy.ViewPrototype;
-import org.eclipse.uml2.uml.UMLPackage;
/**
* The ContentProvider for DiagramCategory table.
@@ -37,7 +33,7 @@ import org.eclipse.uml2.uml.UMLPackage;
public class DiagramKindContentProvider implements IStructuredContentProvider {
private final Map<String, Collection<ViewPrototype>> prototypes;
-
+
/**
* Instantiates a new diagram kind content provider.
*
@@ -45,22 +41,23 @@ public class DiagramKindContentProvider implements IStructuredContentProvider {
public DiagramKindContentProvider() {
Collection<ViewPrototype> vps = PolicyChecker.getCurrent().getAllPrototypes();
this.prototypes = new HashMap<String, Collection<ViewPrototype>>();
- for (ViewPrototype vp : vps)
- for (Category category : vp.getCategories())
+ for(ViewPrototype vp : vps)
+ for(Category category : vp.getCategories())
cache(category.getName(), vp);
}
-
+
/**
* Stores the given diagram prototype in the cache
- * @param prototype The prototype to cache
+ *
+ * @param prototype
+ * The prototype to cache
*/
private void cache(String category, ViewPrototype prototype) {
- if (!prototypes.containsKey(category))
+ if(!prototypes.containsKey(category))
prototypes.put(category, new ArrayList<ViewPrototype>());
prototypes.get(category).add(prototype);
}
-
/**
* Dispose.
*
@@ -73,9 +70,12 @@ public class DiagramKindContentProvider implements IStructuredContentProvider {
/**
* Input changed.
*
- * @param viewer the viewer
- * @param oldInput the old input
- * @param newInput the new input
+ * @param viewer
+ * the viewer
+ * @param oldInput
+ * the old input
+ * @param newInput
+ * the new input
* @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
*/
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
@@ -84,15 +84,16 @@ public class DiagramKindContentProvider implements IStructuredContentProvider {
/**
* Gets the elements.
*
- * @param inputElement the input element
+ * @param inputElement
+ * the input element
* @return the elements
* @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object)
*/
public Object[] getElements(Object inputElement) {
if(inputElement instanceof Object[]) {
List<ViewPrototype> result = new ArrayList<ViewPrototype>();
- for (Object next: (Object[])inputElement) {
- if (next instanceof String) {
+ for(Object next : (Object[])inputElement) {
+ if(next instanceof String) {
String diagramCategory = (String)next;
result.addAll(getPrototypes(diagramCategory));
}
@@ -111,50 +112,22 @@ public class DiagramKindContentProvider implements IStructuredContentProvider {
/**
* Gets the creation commands.
*
- * @param diagramCategory the diagram category
+ * @param diagramCategory
+ * the diagram category
* @return the creation commands
*/
protected List<ViewPrototype> getPrototypes(String diagramCategory) {
- List<ViewPrototype> result = new ArrayList<ViewPrototype>();
- // Add the category-specific views
- if (prototypes.containsKey(diagramCategory)) {
- EClass rootType = getExpectedRootType(diagramCategory);
- for (ViewPrototype proto : prototypes.get(diagramCategory))
- if (isAllowedOn(proto, rootType))
- result.add(proto);
- }
- return result;
- }
-
- private EClass getExpectedRootType(String category) {
- if ("profile".equals(category))
- return UMLPackage.eINSTANCE.getProfile();
- return UMLPackage.eINSTANCE.getModel();
- }
-
- private boolean isAllowedOn(ViewPrototype prototype, EClass clazz) {
- PapyrusView current = prototype.getConfiguration();
- while (current != null) {
- for (ModelRule rule : current.getModelRules()) {
- int result = allows(rule, clazz);
- if (result == -1)
- return false;
- if (result == 1)
- return true;
+ HashMap<String, ViewPrototype> result = new HashMap<String, ViewPrototype>();
+ if(prototypes.containsKey(diagramCategory)) {
+ //Look for all diagram kind of the category
+ for(ViewPrototype prototype : prototypes.get(diagramCategory)) {
+ String label = prototype.getLabel();
+ //If the diagram is not contains in the result add it
+ if(!result.containsKey(label)) {
+ result.put(label, prototype);
+ }
}
- current = current.getParent();
- }
- return false;
- }
-
- private int allows(ModelRule rule, EClass owner) {
- EClass c = rule.getElement();
- if (c == null || c.isSuperTypeOf(owner)) {
- // matching type => check the application of the required stereotypes
- return rule.isPermit() ? 1 : -1;
- } else {
- // type is not matching => unknown
- return 0;
}
+ return new ArrayList<ViewPrototype>(result.values());
}
-} \ No newline at end of file
+}