Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCedric Dumoulin2014-11-26 10:48:40 +0000
committerCedric Dumoulin2014-11-29 23:07:23 +0000
commit64a322e96c7e0cc7d8d944c4c2e1d068b2fda489 (patch)
tree987bca4f7ad728f1e8ba0a442f80b30c13285a34 /plugins/uml/profile
parent2c1318ec7d410d3a1932e7435246078ea1a65f61 (diff)
downloadorg.eclipse.papyrus-64a322e96c7e0cc7d8d944c4c2e1d068b2fda489.tar.gz
org.eclipse.papyrus-64a322e96c7e0cc7d8d944c4c2e1d068b2fda489.tar.xz
org.eclipse.papyrus-64a322e96c7e0cc7d8d944c4c2e1d068b2fda489.zip
432802 - profile - Improve Type Provider implementation. Add new
providers.
Diffstat (limited to 'plugins/uml/profile')
-rw-r--r--plugins/uml/profile/org.eclipse.papyrus.uml.profile.drafter.documentation/models/architecture.notation2
-rw-r--r--plugins/uml/profile/org.eclipse.papyrus.uml.profile.drafter.tests/src/org/eclipse/papyrus/uml/profile/drafter/tests/utils/UMLModelCreator.java210
-rw-r--r--plugins/uml/profile/org.eclipse.papyrus.uml.profile.drafter.tests/test/org/eclipse/papyrus/uml/profile/drafter/tests/utils/UMLModelCreatorTest.java228
-rw-r--r--plugins/uml/profile/org.eclipse.papyrus.uml.profile.drafter.tests/test/org/eclipse/papyrus/uml/profile/drafter/ui/model/TypeProviderTest.java126
-rw-r--r--plugins/uml/profile/org.eclipse.papyrus.uml.profile.drafter/src/org/eclipse/papyrus/uml/profile/drafter/ui/contentassist/TypeContentProposalProvider.java2
-rw-r--r--plugins/uml/profile/org.eclipse.papyrus.uml.profile.drafter/src/org/eclipse/papyrus/uml/profile/drafter/ui/dialog/TypeSelectorLabel.java17
-rw-r--r--plugins/uml/profile/org.eclipse.papyrus.uml.profile.drafter/src/org/eclipse/papyrus/uml/profile/drafter/ui/model/AccessibleTypeCatalog.java10
-rw-r--r--plugins/uml/profile/org.eclipse.papyrus.uml.profile.drafter/src/org/eclipse/papyrus/uml/profile/drafter/ui/model/CompoundTypeProvider.java70
-rw-r--r--plugins/uml/profile/org.eclipse.papyrus.uml.profile.drafter/src/org/eclipse/papyrus/uml/profile/drafter/ui/model/ITypeCatalog.java17
-rw-r--r--plugins/uml/profile/org.eclipse.papyrus.uml.profile.drafter/src/org/eclipse/papyrus/uml/profile/drafter/ui/model/ResourceTypeProvider.java101
-rw-r--r--plugins/uml/profile/org.eclipse.papyrus.uml.profile.drafter/src/org/eclipse/papyrus/uml/profile/drafter/ui/model/TypeModel.java13
-rw-r--r--plugins/uml/profile/org.eclipse.papyrus.uml.profile.drafter/src/org/eclipse/papyrus/uml/profile/drafter/ui/model/TypeProvider.java76
-rw-r--r--plugins/uml/profile/org.eclipse.papyrus.uml.profile.drafter/test/org/eclipse/papyrus/uml/profile/drafter/ui/model/CompoundTypeProviderTest.java130
-rw-r--r--plugins/uml/profile/org.eclipse.papyrus.uml.profile.drafter/test/org/eclipse/papyrus/uml/profile/drafter/ui/model/TypeProviderTest.java143
14 files changed, 1126 insertions, 19 deletions
diff --git a/plugins/uml/profile/org.eclipse.papyrus.uml.profile.drafter.documentation/models/architecture.notation b/plugins/uml/profile/org.eclipse.papyrus.uml.profile.drafter.documentation/models/architecture.notation
index d809c6a5322..7c444f25735 100644
--- a/plugins/uml/profile/org.eclipse.papyrus.uml.profile.drafter.documentation/models/architecture.notation
+++ b/plugins/uml/profile/org.eclipse.papyrus.uml.profile.drafter.documentation/models/architecture.notation
@@ -1362,7 +1362,7 @@
<layoutConstraint xmi:type="notation:Location" xmi:id="_S51tVmpKEeSHJZbEOSiM7A" y="20"/>
</children>
<children xmi:type="notation:DecorationNode" xmi:id="_S51tV2pKEeSHJZbEOSiM7A" type="6003">
- <layoutConstraint xmi:type="notation:Location" xmi:id="_S51tWGpKEeSHJZbEOSiM7A" x="22" y="-72"/>
+ <layoutConstraint xmi:type="notation:Location" xmi:id="_S51tWGpKEeSHJZbEOSiM7A" x="26" y="-25"/>
</children>
<children xmi:type="notation:DecorationNode" xmi:id="_S51tWWpKEeSHJZbEOSiM7A" visible="false" type="6005">
<layoutConstraint xmi:type="notation:Location" xmi:id="_S51tWmpKEeSHJZbEOSiM7A" y="20"/>
diff --git a/plugins/uml/profile/org.eclipse.papyrus.uml.profile.drafter.tests/src/org/eclipse/papyrus/uml/profile/drafter/tests/utils/UMLModelCreator.java b/plugins/uml/profile/org.eclipse.papyrus.uml.profile.drafter.tests/src/org/eclipse/papyrus/uml/profile/drafter/tests/utils/UMLModelCreator.java
new file mode 100644
index 00000000000..e15122663d0
--- /dev/null
+++ b/plugins/uml/profile/org.eclipse.papyrus.uml.profile.drafter.tests/src/org/eclipse/papyrus/uml/profile/drafter/tests/utils/UMLModelCreator.java
@@ -0,0 +1,210 @@
+/*****************************************************************************
+ * Copyright (c) 2014 Cedric Dumoulin.
+ *
+ *
+ * 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:
+ * Cedric Dumoulin Cedric.dumoulin@lifl.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.uml.profile.drafter.tests.utils;
+
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
+import org.eclipse.emf.ecore.util.EcoreUtil;
+import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl;
+import org.eclipse.uml2.uml.Class;
+import org.eclipse.uml2.uml.DataType;
+import org.eclipse.uml2.uml.Model;
+import org.eclipse.uml2.uml.Package;
+import org.eclipse.uml2.uml.UMLFactory;
+import org.eclipse.uml2.uml.UMLPackage;
+import org.eclipse.uml2.uml.resource.UMLResource;
+
+
+/**
+ * Class use to create a UML Model inside a Resource, and to populate it.
+ *
+ * @author cedric dumoulin
+ *
+ */
+public class UMLModelCreator {
+
+ protected Resource resource;
+
+ protected Package curPackage;
+
+ /**
+ *
+ * Constructor.
+ *
+ * @param resourceUri
+ */
+ public UMLModelCreator(String resourceUri, String rootModelName) {
+
+ resource = createResource(resourceUri);
+
+ Model model = createRootModel(rootModelName);
+ resource.getContents().add(model);
+ cd(model);
+ }
+
+
+
+
+
+ /**
+ *
+ * Constructor.
+ *
+ * @param resource
+ * @throws IllegalAccessException
+ */
+ public UMLModelCreator(Resource resource) throws IllegalArgumentException {
+ this.resource = resource;
+
+ // Lookup for a Pacakge ine the resource.
+ Package p = (Package)EcoreUtil.getObjectByType(resource.getContents(),UMLPackage.eINSTANCE.getPackage());
+ if( p == null) {
+ p = (Model)EcoreUtil.getObjectByType(resource.getContents(),UMLPackage.eINSTANCE.getModel());
+ }
+ if( p == null) {
+ throw new IllegalArgumentException("Resource must contains a Package or a Model");
+ }
+ cd(p);
+ }
+
+ /**
+ *
+ * @return
+ */
+ private Resource createResource(String uriName) {
+ ResourceSet resourceSet = new ResourceSetImpl();
+
+ // True for local test, false for plugin test
+ if(true) {
+ // Register the default resource factory -- only needed for stand-alone!
+ resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put(
+ Resource.Factory.Registry.DEFAULT_EXTENSION, new XMIResourceFactoryImpl());
+ resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put(
+ UMLResource.FILE_EXTENSION, UMLResource.Factory.INSTANCE );
+
+ }
+
+ URI uri = URI.createURI(uriName);
+ Resource resource = resourceSet.createResource(uri);
+
+ return resource;
+ }
+
+ /**
+ * @param rootModelName
+ * @return
+ */
+ private Model createRootModel(String rootModelName) {
+ Model model = UMLFactory.eINSTANCE.createModel();
+ model.setName(rootModelName);
+ return model;
+ }
+
+ /**
+ * Change current package to specified package.
+ * The package should belong to the Resource (not verified).
+ *
+ * @param p
+ */
+ public void cd(Package p) {
+ curPackage = p;
+ }
+
+ /**
+ * Change current package to the root model.
+ *
+ * @param p
+ */
+ public Package cdToRoot() {
+ // Lookup for a Pacakge ine the resource.
+ Package p = (Package)EcoreUtil.getObjectByType(resource.getContents(),UMLPackage.eINSTANCE.getPackage());
+ if( p == null) {
+ p = (Model)EcoreUtil.getObjectByType(resource.getContents(),UMLPackage.eINSTANCE.getModel());
+ }
+
+ return p;
+ }
+
+ public Class createClass( String name ) {
+ Class c = UMLFactory.eINSTANCE.createClass();
+ c.setName(name);
+ curPackage.getPackagedElements().add(c);
+ return c;
+ }
+
+ public DataType createDatatype( String name ) {
+ DataType c = UMLFactory.eINSTANCE.createDataType();
+ c.setName(name);
+ curPackage.getPackagedElements().add(c);
+ return c;
+ }
+
+ public Package createPackage( String name ) {
+ return createPackage(name, true);
+ }
+
+ public Model createModel( String name ) {
+ return createModel(name, true);
+ }
+
+ /**
+ *
+ * @param name
+ * @param changeCurrent
+ * @return
+ */
+ public Package createPackage( String name, boolean changeCurrent ) {
+ Package c = UMLFactory.eINSTANCE.createModel();
+ c.setName(name);
+ curPackage.getNestedPackages().add(c);
+ if( changeCurrent ) {
+ curPackage = c;
+ }
+ return c;
+ }
+
+ /**
+ *
+ * @param name
+ * @param changeCurrent
+ * @return
+ */
+ public Model createModel( String name, boolean changeCurrent ) {
+ Model c = UMLFactory.eINSTANCE.createModel();
+ c.setName(name);
+ curPackage.getNestedPackages().add(c);
+ if( changeCurrent ) {
+ curPackage = c;
+ }
+ return c;
+ }
+
+ /**
+ * Return the current Package.
+ *
+ * @return
+ */
+ public Package getCurrentDir() {
+ return curPackage;
+ }
+
+ public Resource getResource() {
+ return resource;
+ }
+
+
+}
diff --git a/plugins/uml/profile/org.eclipse.papyrus.uml.profile.drafter.tests/test/org/eclipse/papyrus/uml/profile/drafter/tests/utils/UMLModelCreatorTest.java b/plugins/uml/profile/org.eclipse.papyrus.uml.profile.drafter.tests/test/org/eclipse/papyrus/uml/profile/drafter/tests/utils/UMLModelCreatorTest.java
new file mode 100644
index 00000000000..d428da4cad6
--- /dev/null
+++ b/plugins/uml/profile/org.eclipse.papyrus.uml.profile.drafter.tests/test/org/eclipse/papyrus/uml/profile/drafter/tests/utils/UMLModelCreatorTest.java
@@ -0,0 +1,228 @@
+/*****************************************************************************
+ * Copyright (c) 2014 Cedric Dumoulin.
+ *
+ *
+ * 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:
+ * Cedric Dumoulin Cedric.dumoulin@lifl.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.uml.profile.drafter.tests.utils;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.fail;
+
+import java.util.Iterator;
+
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
+import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl;
+import org.eclipse.uml2.uml.Class;
+import org.eclipse.uml2.uml.DataType;
+import org.eclipse.uml2.uml.Model;
+import org.eclipse.uml2.uml.Package;
+import org.eclipse.uml2.uml.UMLFactory;
+import org.eclipse.uml2.uml.resource.UMLResource;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.Test;
+
+import com.google.common.base.Predicate;
+import com.google.common.collect.Iterators;
+
+
+/**
+ * @author cedric dumoulin
+ *
+ */
+public class UMLModelCreatorTest {
+
+ /**
+ * @throws java.lang.Exception
+ */
+ @AfterClass
+ public static void tearDownAfterClass() throws Exception {
+ }
+
+ /**
+ * @throws java.lang.Exception
+ */
+ @Before
+ public void setUp() throws Exception {
+ }
+
+ /**
+ * @throws java.lang.Exception
+ */
+ @After
+ public void tearDown() throws Exception {
+ }
+
+ /**
+ *
+ * @return
+ */
+ protected Resource createResource(String uriName) {
+ ResourceSet resourceSet = new ResourceSetImpl();
+
+ // True for local test, false for plugin test
+ if(true) {
+ // Register the default resource factory -- only needed for stand-alone!
+ resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put(
+ Resource.Factory.Registry.DEFAULT_EXTENSION, new XMIResourceFactoryImpl());
+ resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put(
+ UMLResource.FILE_EXTENSION, UMLResource.Factory.INSTANCE );
+
+ }
+
+ URI uri = URI.createURI(uriName);
+ Resource resource = resourceSet.createResource(uri);
+
+ return resource;
+ }
+
+
+ /**
+ * Test method for {@link org.eclipse.papyrus.uml.profile.drafter.tests.utils.UMLModelCreator#UMLModelCreator(java.lang.String, java.lang.String)}.
+ */
+ @Test
+ public void testUMLModelCreatorStringString() {
+ UMLModelCreator creator = new UMLModelCreator("temp.uml", "model");
+
+ assertNotNull("Object created", creator);
+ }
+
+ /**
+ * Test method for {@link org.eclipse.papyrus.uml.profile.drafter.tests.utils.UMLModelCreator#UMLModelCreator(org.eclipse.emf.ecore.resource.Resource)}.
+ */
+ @Test
+ public void testUMLModelCreatorResourceFailing() {
+ Resource resource = createResource("temp.uml");
+
+ try {
+ UMLModelCreator creator = new UMLModelCreator(resource);
+ fail("Exception must be thrown");
+ } catch (IllegalArgumentException e) {
+ // ok
+ }
+
+ }
+
+ /**
+ * Test method for {@link org.eclipse.papyrus.uml.profile.drafter.tests.utils.UMLModelCreator#UMLModelCreator(org.eclipse.emf.ecore.resource.Resource)}.
+ */
+ @Test
+ public void testUMLModelCreatorResource() {
+ Resource resource = createResource("temp.uml");
+
+ Model rootModel = UMLFactory.eINSTANCE.createModel();
+ rootModel.setName("model");
+ resource.getContents().add(rootModel);
+
+ UMLModelCreator creator = new UMLModelCreator(resource);
+
+ assertNotNull("Object created", creator);
+
+ }
+
+ /**
+ * Test method for {@link org.eclipse.papyrus.uml.profile.drafter.tests.utils.UMLModelCreator#cd(org.eclipse.uml2.uml.Package)}.
+ */
+ @Test
+ public void testCd() {
+ UMLModelCreator creator = new UMLModelCreator("temp.uml", "model");
+
+ creator.createPackage("p1", false);
+ Package p2 = creator.createPackage("p2", false);
+ creator.createPackage("p3", false);
+
+ creator.cd(p2);
+
+ assertSame("current package changed", creator.getCurrentDir(), p2);
+ }
+
+ /**
+ * Test method for {@link org.eclipse.papyrus.uml.profile.drafter.tests.utils.UMLModelCreator#createClass(java.lang.String)}.
+ */
+ @Test
+ public void testCreateClass() {
+ UMLModelCreator creator = new UMLModelCreator("temp.uml", "model");
+
+ Class c = creator.createClass("c1");
+
+ assertNotNull("Object created", c);
+ }
+
+ /**
+ * Test method for {@link org.eclipse.papyrus.uml.profile.drafter.tests.utils.UMLModelCreator#createDatatype(java.lang.String)}.
+ */
+ @Test
+ public void testCreateDatatype() {
+ UMLModelCreator creator = new UMLModelCreator("temp.uml", "model");
+
+ DataType c = creator.createDatatype("c1");
+
+ assertNotNull("Object created", c);
+ }
+
+ /**
+ * Test method for {@link org.eclipse.papyrus.uml.profile.drafter.tests.utils.UMLModelCreator#createPackage(java.lang.String)}.
+ */
+ @Test
+ public void testCreatePackage() {
+ UMLModelCreator creator = new UMLModelCreator("temp.uml", "model");
+
+ Package c = creator.createPackage("c1");
+
+ assertNotNull("Object created", c);
+ }
+
+ /**
+ * Test method for {@link org.eclipse.papyrus.uml.profile.drafter.tests.utils.UMLModelCreator#createModel(java.lang.String)}.
+ */
+ @Test
+ public void testCreateModel() {
+ UMLModelCreator creator = new UMLModelCreator("temp.uml", "model");
+
+ Model c = creator.createModel("c1");
+
+ assertNotNull("Object created", c);
+ }
+
+ /**
+ *
+ */
+ @Test
+ public void testCreation() {
+ UMLModelCreator creator = new UMLModelCreator("temp.uml", "model");
+ // Create model
+ Package p1 = creator.createPackage("p1");
+ creator.createDatatype("dt1");
+ creator.createDatatype("dt2");
+ creator.createClass("C1");
+ creator.cdToRoot();
+ Package p2 = creator.createPackage("p2");
+ creator.createDatatype("dt21");
+ creator.createDatatype("dt12");
+ creator.createClass("C21");
+
+ int expectedDatatypeCount = 4;
+ int expectedElementeCount = 9;
+
+ assertSame("Expected count", expectedElementeCount, Iterators.size( creator.getResource().getAllContents() ));
+
+ Iterator<EObject> iter = creator.getResource().getAllContents();
+ Iterator<DataType> datatypesIter = Iterators.filter(iter, DataType.class);
+ assertSame("Expected count", expectedDatatypeCount, Iterators.size(datatypesIter));
+ }
+}
diff --git a/plugins/uml/profile/org.eclipse.papyrus.uml.profile.drafter.tests/test/org/eclipse/papyrus/uml/profile/drafter/ui/model/TypeProviderTest.java b/plugins/uml/profile/org.eclipse.papyrus.uml.profile.drafter.tests/test/org/eclipse/papyrus/uml/profile/drafter/ui/model/TypeProviderTest.java
new file mode 100644
index 00000000000..eede9e9b6ff
--- /dev/null
+++ b/plugins/uml/profile/org.eclipse.papyrus.uml.profile.drafter.tests/test/org/eclipse/papyrus/uml/profile/drafter/ui/model/TypeProviderTest.java
@@ -0,0 +1,126 @@
+/*****************************************************************************
+ * Copyright (c) 2014 Cedric Dumoulin.
+ *
+ *
+ * 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:
+ * Cedric Dumoulin Cedric.dumoulin@lifl.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.uml.profile.drafter.ui.model;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import java.util.List;
+
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.papyrus.uml.profile.drafter.tests.utils.UMLModelCreator;
+import org.eclipse.uml2.uml.Package;
+import org.eclipse.uml2.uml.Type;
+import org.eclipse.uml2.uml.UMLPackage;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.Test;
+
+import com.google.common.collect.Iterators;
+
+
+/**
+ * @author cedric dumoulin
+ *
+ */
+public class TypeProviderTest {
+
+ protected UMLModelCreator creator;
+ int expectedDatatypeCount;
+
+
+ /**
+ * @throws java.lang.Exception
+ */
+ @AfterClass
+ public static void tearDownAfterClass() throws Exception {
+ }
+
+ /**
+ * @throws java.lang.Exception
+ */
+ @Before
+ public void setUp() throws Exception {
+ createUmlModel();
+
+ }
+
+ /**
+ *
+ */
+ private void createUmlModel() {
+ creator = new UMLModelCreator("temp.uml", "model");
+ // Create model
+ creator.createPackage("p1");
+ creator.createDatatype("dt1");
+ creator.createDatatype("dt2");
+ creator.createClass("C1");
+ creator.cdToRoot();
+ creator.createPackage("p2");
+ creator.createDatatype("dt21");
+ creator.createDatatype("dt12");
+ creator.createClass("C21");
+
+ expectedDatatypeCount = 4;
+ }
+
+ /**
+ * @throws java.lang.Exception
+ */
+ @After
+ public void tearDown() throws Exception {
+ }
+
+ /**
+ * Test method for {@link org.eclipse.papyrus.uml.profile.drafter.ui.model.ResourceTypeProvider#TypeProvider(org.eclipse.emf.ecore.resource.Resource, org.eclipse.emf.ecore.EClass)}.
+ */
+ @Test
+ public void testTypeProvider() {
+
+ UMLModelCreator creator = new UMLModelCreator("temp.uml", "model");
+
+ EClass requestedType = UMLPackage.eINSTANCE.getClass_();
+ ResourceTypeProvider typeProvider = new ResourceTypeProvider(creator.getResource(), requestedType);
+
+ assertNotNull("Object created", typeProvider);
+ }
+
+ /**
+ * Test method for {@link org.eclipse.papyrus.uml.profile.drafter.ui.model.ResourceTypeProvider#getTypes()}.
+ */
+ @Test
+ public void testGetTypes() {
+
+ EClass requestedType = UMLPackage.eINSTANCE.getDataType();
+ ResourceTypeProvider typeProvider = new ResourceTypeProvider(creator.getResource(), requestedType);
+
+ List<Type> types = typeProvider.getTypes();
+
+ assertEquals("Types found", expectedDatatypeCount, types.size());
+ }
+
+ /**
+ * Test method for {@link org.eclipse.papyrus.uml.profile.drafter.ui.model.ResourceTypeProvider#iterator()}.
+ */
+ @Test
+ public void testIterator() {
+ EClass requestedType = UMLPackage.eINSTANCE.getDataType();
+ ResourceTypeProvider typeProvider = new ResourceTypeProvider(creator.getResource(), requestedType);
+
+ assertEquals("Types found", expectedDatatypeCount, Iterators.size(typeProvider.iterator()));
+ }
+
+}
diff --git a/plugins/uml/profile/org.eclipse.papyrus.uml.profile.drafter/src/org/eclipse/papyrus/uml/profile/drafter/ui/contentassist/TypeContentProposalProvider.java b/plugins/uml/profile/org.eclipse.papyrus.uml.profile.drafter/src/org/eclipse/papyrus/uml/profile/drafter/ui/contentassist/TypeContentProposalProvider.java
index 5f2d6a65546..30039a258d5 100644
--- a/plugins/uml/profile/org.eclipse.papyrus.uml.profile.drafter/src/org/eclipse/papyrus/uml/profile/drafter/ui/contentassist/TypeContentProposalProvider.java
+++ b/plugins/uml/profile/org.eclipse.papyrus.uml.profile.drafter/src/org/eclipse/papyrus/uml/profile/drafter/ui/contentassist/TypeContentProposalProvider.java
@@ -14,6 +14,8 @@ import org.eclipse.uml2.uml.Type;
*
* @author cedric dumoulin
*
+ * TODO : 20141126 not used - can be removed
+
*/
public class TypeContentProposalProvider implements IContentProposalProvider {
diff --git a/plugins/uml/profile/org.eclipse.papyrus.uml.profile.drafter/src/org/eclipse/papyrus/uml/profile/drafter/ui/dialog/TypeSelectorLabel.java b/plugins/uml/profile/org.eclipse.papyrus.uml.profile.drafter/src/org/eclipse/papyrus/uml/profile/drafter/ui/dialog/TypeSelectorLabel.java
index 52693ec3743..7128f71e5d9 100644
--- a/plugins/uml/profile/org.eclipse.papyrus.uml.profile.drafter/src/org/eclipse/papyrus/uml/profile/drafter/ui/dialog/TypeSelectorLabel.java
+++ b/plugins/uml/profile/org.eclipse.papyrus.uml.profile.drafter/src/org/eclipse/papyrus/uml/profile/drafter/ui/dialog/TypeSelectorLabel.java
@@ -20,6 +20,7 @@ import org.eclipse.jface.fieldassist.IContentProposal;
import org.eclipse.jface.fieldassist.IContentProposalListener;
import org.eclipse.jface.fieldassist.IContentProposalProvider;
import org.eclipse.jface.fieldassist.TextContentAdapter;
+import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.papyrus.uml.profile.drafter.ui.contentassist.TypeContentProposalBase;
import org.eclipse.papyrus.uml.profile.drafter.ui.contentassist.TypeContentProposalProvider;
import org.eclipse.papyrus.uml.profile.drafter.ui.model.ITypeCatalog;
@@ -32,6 +33,8 @@ import org.eclipse.uml2.uml.Type;
* A Label used to select a uml {@link Type}.
*
* @author cedric dumoulin
+ *
+ * TODO : 20141126 not used - can be removed
*
*/
public class TypeSelectorLabel extends Text {
@@ -39,7 +42,9 @@ public class TypeSelectorLabel extends Text {
/**
* Type catalog used to propose existing types.
*/
- protected ITypeCatalog typeCatalog;
+ protected ITypeCatalog typeProvider;
+
+ protected ILabelProvider typeLabelProvider;
protected Type type;
@@ -49,11 +54,13 @@ public class TypeSelectorLabel extends Text {
* @param parent
* @param style
*/
- public TypeSelectorLabel(Composite parent, int style, ITypeCatalog typeCatalog) {
+ public TypeSelectorLabel(Composite parent, int style, ITypeCatalog typeProvider, ILabelProvider typeLabelProvider, Type defaultType) {
super(parent, style);
+ this.typeProvider = typeProvider;
+ this.typeLabelProvider = typeLabelProvider;
// TODO: set first type
- setType(typeCatalog.getTypes().get(0));
+ setType(defaultType);
// Set content assist
installContentAssist();
@@ -63,7 +70,7 @@ public class TypeSelectorLabel extends Text {
* Associate a ContentAssist based on the {@link ITypeCatalog}.
*/
private void installContentAssist() {
- installContentAssistantProvider( new TypeContentProposalProvider( typeCatalog ));
+ installContentAssistantProvider( new TypeContentProposalProvider( typeProvider ));
}
/**
@@ -118,7 +125,7 @@ public class TypeSelectorLabel extends Text {
*/
public void setType(Type type) {
- String label = typeCatalog.getTypeLabel(type);
+ String label = typeLabelProvider.getText(type);
setText(label);
setTypeInternal(type);
diff --git a/plugins/uml/profile/org.eclipse.papyrus.uml.profile.drafter/src/org/eclipse/papyrus/uml/profile/drafter/ui/model/AccessibleTypeCatalog.java b/plugins/uml/profile/org.eclipse.papyrus.uml.profile.drafter/src/org/eclipse/papyrus/uml/profile/drafter/ui/model/AccessibleTypeCatalog.java
index 37fc00d43e6..35d554444a2 100644
--- a/plugins/uml/profile/org.eclipse.papyrus.uml.profile.drafter/src/org/eclipse/papyrus/uml/profile/drafter/ui/model/AccessibleTypeCatalog.java
+++ b/plugins/uml/profile/org.eclipse.papyrus.uml.profile.drafter/src/org/eclipse/papyrus/uml/profile/drafter/ui/model/AccessibleTypeCatalog.java
@@ -15,6 +15,7 @@
package org.eclipse.papyrus.uml.profile.drafter.ui.model;
import java.util.Collections;
+import java.util.Iterator;
import java.util.List;
import org.eclipse.papyrus.uml.profile.drafter.exceptions.NotFoundException;
@@ -69,7 +70,7 @@ public class AccessibleTypeCatalog implements ITypeCatalog {
* @param type
* @return
*/
- @Override
+// @Override
public String getTypeLabel(Type type) {
return type.getLabel();
}
@@ -81,7 +82,7 @@ public class AccessibleTypeCatalog implements ITypeCatalog {
* @return
* @throws NotFoundException
*/
- @Override
+// @Override
public Type getType(String typeLabel) throws NotFoundException {
for( Type type : getTypes()) {
@@ -118,4 +119,9 @@ public class AccessibleTypeCatalog implements ITypeCatalog {
// return null;
}
+ @Override
+ public Iterator<Type> iterator() {
+ return getTypes().iterator();
+ }
+
}
diff --git a/plugins/uml/profile/org.eclipse.papyrus.uml.profile.drafter/src/org/eclipse/papyrus/uml/profile/drafter/ui/model/CompoundTypeProvider.java b/plugins/uml/profile/org.eclipse.papyrus.uml.profile.drafter/src/org/eclipse/papyrus/uml/profile/drafter/ui/model/CompoundTypeProvider.java
new file mode 100644
index 00000000000..cb70dfd17c7
--- /dev/null
+++ b/plugins/uml/profile/org.eclipse.papyrus.uml.profile.drafter/src/org/eclipse/papyrus/uml/profile/drafter/ui/model/CompoundTypeProvider.java
@@ -0,0 +1,70 @@
+/*****************************************************************************
+ * Copyright (c) 2014 Cedric Dumoulin.
+ *
+ *
+ * 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:
+ * Cedric Dumoulin Cedric.dumoulin@lifl.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.uml.profile.drafter.ui.model;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.eclipse.uml2.uml.Type;
+
+
+/**
+ * A {@link ITypeCatalog} made of subcollections of {@link ITypeCatalog}.
+ * @author cedric dumoulin
+ *
+ */
+public class CompoundTypeProvider implements ITypeCatalog {
+
+ protected List<ITypeCatalog> catalogs;
+
+ /**
+ * The union of provided types.
+ * TODO: consider using a TreeSet to avoid duplicate.
+ */
+ protected List<Type> types;
+
+
+
+ public CompoundTypeProvider(ITypeCatalog ... catalogs ) {
+
+ this.catalogs = new ArrayList<ITypeCatalog>();
+ this.types = new ArrayList<Type>();
+
+ for( ITypeCatalog provider : catalogs) {
+ addITypeProvider(provider);
+ }
+ }
+
+ /**
+ * @see org.eclipse.papyrus.uml.profile.drafter.ui.model.ITypeCatalog#getTypes()
+ *
+ * @return
+ */
+ @Override
+ public List<Type> getTypes() {
+ return types;
+ }
+
+ @Override
+ public Iterator<Type> iterator() {
+ return types.iterator();
+ }
+
+ public void addITypeProvider( ITypeCatalog typeProvider) {
+ catalogs.add(typeProvider);
+ types.addAll(typeProvider.getTypes());
+ }
+}
diff --git a/plugins/uml/profile/org.eclipse.papyrus.uml.profile.drafter/src/org/eclipse/papyrus/uml/profile/drafter/ui/model/ITypeCatalog.java b/plugins/uml/profile/org.eclipse.papyrus.uml.profile.drafter/src/org/eclipse/papyrus/uml/profile/drafter/ui/model/ITypeCatalog.java
index c910ca4c1f2..caa4f534ec8 100644
--- a/plugins/uml/profile/org.eclipse.papyrus.uml.profile.drafter/src/org/eclipse/papyrus/uml/profile/drafter/ui/model/ITypeCatalog.java
+++ b/plugins/uml/profile/org.eclipse.papyrus.uml.profile.drafter/src/org/eclipse/papyrus/uml/profile/drafter/ui/model/ITypeCatalog.java
@@ -14,9 +14,9 @@
package org.eclipse.papyrus.uml.profile.drafter.ui.model;
+import java.util.Iterator;
import java.util.List;
-import org.eclipse.papyrus.uml.profile.drafter.exceptions.NotFoundException;
import org.eclipse.uml2.uml.Type;
@@ -26,14 +26,14 @@ import org.eclipse.uml2.uml.Type;
* @author cedric dumoulin
*
*/
-public interface ITypeCatalog {
+public interface ITypeCatalog extends Iterable<Type> {
/**
* Get the label (human representation) of the specified type.
* @param type
* @return
*/
- public String getTypeLabel(Type type);
+// public String getTypeLabel(Type type);
/**
* Get the type corresponding to the specified label.
@@ -42,7 +42,7 @@ public interface ITypeCatalog {
*
* @return The {@link Type} corresponding to
*/
- public Type getType(String typeLabel) throws NotFoundException;
+// public Type getType(String typeLabel) throws NotFoundException;
/**
* Return a list of available types.
@@ -51,5 +51,12 @@ public interface ITypeCatalog {
*/
public List<Type> getTypes();
-
+ /**
+ * Return an iterator over the list of types.
+ *
+ * @see java.lang.Iterable#iterator()
+ *
+ * @return
+ */
+ public Iterator<Type> iterator();
}
diff --git a/plugins/uml/profile/org.eclipse.papyrus.uml.profile.drafter/src/org/eclipse/papyrus/uml/profile/drafter/ui/model/ResourceTypeProvider.java b/plugins/uml/profile/org.eclipse.papyrus.uml.profile.drafter/src/org/eclipse/papyrus/uml/profile/drafter/ui/model/ResourceTypeProvider.java
new file mode 100644
index 00000000000..a082f5055f0
--- /dev/null
+++ b/plugins/uml/profile/org.eclipse.papyrus.uml.profile.drafter/src/org/eclipse/papyrus/uml/profile/drafter/ui/model/ResourceTypeProvider.java
@@ -0,0 +1,101 @@
+/*****************************************************************************
+ * Copyright (c) 2014 Cedric Dumoulin.
+ *
+ *
+ * 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:
+ * Cedric Dumoulin Cedric.dumoulin@lifl.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.uml.profile.drafter.ui.model;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.emf.ecore.EClassifier;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.uml2.uml.Type;
+
+import com.google.common.base.Predicate;
+import com.google.common.collect.Iterators;
+
+
+/**
+ * A {@link ITypeCatalog} prividing all {@link Type} available in a provided {@link Resource}.
+ *
+ * @author cedric dumoulin
+ *
+ */
+public class ResourceTypeProvider implements ITypeCatalog {
+
+ protected Resource resource;
+ protected EClassifier requestedType;
+
+ protected Predicate<EObject> typePredicate;
+
+ /**
+ * Constructor.
+ *
+ * @param resource
+ * @param requestedType
+ */
+ public ResourceTypeProvider(Resource resource, EClass requestedType) {
+ this.resource = resource;
+ this.requestedType = requestedType;
+ this.typePredicate = new TypePredicate();
+ }
+
+ /**
+ * @see org.eclipse.papyrus.uml.profile.drafter.ui.model.ITypeCatalog#getTypes()
+ *
+ * @return
+ */
+ @Override
+ public List<Type> getTypes() {
+ List<Type> result = new ArrayList<Type>();
+
+ Iterator<EObject> iter = resource.getAllContents();
+ Iterators.filter(iter, getTypePredicate() );
+ while(iter.hasNext() )
+
+ {
+ EObject object = iter.next();
+ if (requestedType.isInstance(object))
+ {
+ result.add((Type)object);
+ }
+ }
+ return result;
+ }
+
+ private Predicate getTypePredicate() {
+ return typePredicate;
+ }
+
+ @Override
+ public Iterator<Type> iterator() {
+ // Return an Iterator with filtering over original iterator
+ return Iterators.filter(resource.getAllContents(), getTypePredicate() );
+ }
+
+ /**
+ *
+ *
+ */
+ class TypePredicate implements Predicate<EObject> {
+
+ @Override
+ public boolean apply(EObject input) {
+ return requestedType.isInstance(input);
+ }
+
+ }
+}
diff --git a/plugins/uml/profile/org.eclipse.papyrus.uml.profile.drafter/src/org/eclipse/papyrus/uml/profile/drafter/ui/model/TypeModel.java b/plugins/uml/profile/org.eclipse.papyrus.uml.profile.drafter/src/org/eclipse/papyrus/uml/profile/drafter/ui/model/TypeModel.java
index 7cbf31631f2..ee593674363 100644
--- a/plugins/uml/profile/org.eclipse.papyrus.uml.profile.drafter/src/org/eclipse/papyrus/uml/profile/drafter/ui/model/TypeModel.java
+++ b/plugins/uml/profile/org.eclipse.papyrus.uml.profile.drafter/src/org/eclipse/papyrus/uml/profile/drafter/ui/model/TypeModel.java
@@ -30,6 +30,7 @@ public class TypeModel extends ModelChangeSupport {
/**
* Catalog used to find a type from its label.
+ * TODO Is this still used ? Remove ?
*/
private ITypeCatalog typeCatalog;
@@ -72,10 +73,10 @@ public class TypeModel extends ModelChangeSupport {
public void setTypeLabel(String typeLabel) throws NotFoundException {
// Lookup the corresponding type
-
- Type type = typeCatalog.getType(typeLabel);
- setTypeInternal(type);
- setTypeLabelInternal(typeLabel);
+ throw new UnsupportedOperationException("Not implemented");
+// Type type = typeCatalog.getType(typeLabel);
+// setTypeInternal(type);
+// setTypeLabelInternal(typeLabel);
}
@@ -93,9 +94,9 @@ public class TypeModel extends ModelChangeSupport {
*/
public void setType(Type type) {
- String typeLabel = typeCatalog.getTypeLabel(type);
+// String typeLabel = typeCatalog.getTypeLabel(type);
setTypeInternal(type);
- setTypeLabelInternal(typeLabel);
+// setTypeLabelInternal(typeLabel);
}
diff --git a/plugins/uml/profile/org.eclipse.papyrus.uml.profile.drafter/src/org/eclipse/papyrus/uml/profile/drafter/ui/model/TypeProvider.java b/plugins/uml/profile/org.eclipse.papyrus.uml.profile.drafter/src/org/eclipse/papyrus/uml/profile/drafter/ui/model/TypeProvider.java
new file mode 100644
index 00000000000..8f5bb082758
--- /dev/null
+++ b/plugins/uml/profile/org.eclipse.papyrus.uml.profile.drafter/src/org/eclipse/papyrus/uml/profile/drafter/ui/model/TypeProvider.java
@@ -0,0 +1,76 @@
+/*****************************************************************************
+ * Copyright (c) 2014 Cedric Dumoulin.
+ *
+ *
+ * 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:
+ * Cedric Dumoulin Cedric.dumoulin@lifl.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.uml.profile.drafter.ui.model;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.List;
+
+import org.eclipse.uml2.uml.Type;
+
+
+/**
+ * A {@link ITypeCatalog} allowing to add {@link Type}.
+ * This implementation is backuped by a {@link List}.
+ *
+ * @author cedric dumoulin
+ *
+ */
+public class TypeProvider implements ITypeCatalog {
+
+ protected List<Type> types;
+
+ /**
+ * Constructor.
+ */
+ public TypeProvider() {
+ this.types = new ArrayList<Type>();
+
+ }
+
+ /**
+ * Constructor.
+ */
+ public TypeProvider( Type ...types) {
+ List<Type> initials = Arrays.asList(types);
+ this.types = new ArrayList<Type>(initials);
+ }
+
+
+ /**
+ * @see org.eclipse.papyrus.uml.profile.drafter.ui.model.ITypeCatalog#getTypes()
+ *
+ * @return
+ */
+ @Override
+ public List<Type> getTypes() {
+ return types;
+ }
+
+ /**
+ * @see org.eclipse.papyrus.uml.profile.drafter.ui.model.ITypeCatalog#iterator()
+ *
+ * @return
+ */
+ @Override
+ public Iterator<Type> iterator() {
+ return types.iterator();
+ }
+
+ public void addType( Type type ) {
+ types.add(type);
+ }
+}
diff --git a/plugins/uml/profile/org.eclipse.papyrus.uml.profile.drafter/test/org/eclipse/papyrus/uml/profile/drafter/ui/model/CompoundTypeProviderTest.java b/plugins/uml/profile/org.eclipse.papyrus.uml.profile.drafter/test/org/eclipse/papyrus/uml/profile/drafter/ui/model/CompoundTypeProviderTest.java
new file mode 100644
index 00000000000..b89eec86734
--- /dev/null
+++ b/plugins/uml/profile/org.eclipse.papyrus.uml.profile.drafter/test/org/eclipse/papyrus/uml/profile/drafter/ui/model/CompoundTypeProviderTest.java
@@ -0,0 +1,130 @@
+/*****************************************************************************
+ * Copyright (c) 2014 Cedric Dumoulin.
+ *
+ *
+ * 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:
+ * Cedric Dumoulin Cedric.dumoulin@lifl.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.uml.profile.drafter.ui.model;
+
+import static org.junit.Assert.*;
+
+import org.eclipse.core.commands.ITypedParameter;
+import org.eclipse.uml2.uml.Type;
+import org.eclipse.uml2.uml.UMLFactory;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.Test;
+
+
+/**
+ * @author cedric dumoulin
+ *
+ */
+public class CompoundTypeProviderTest {
+
+ protected Type type1;
+ protected Type type2;
+ protected Type type3;
+ protected int typeCount;
+
+
+ /**
+ * @throws java.lang.Exception
+ */
+ @AfterClass
+ public static void tearDownAfterClass() throws Exception {
+ }
+
+ /**
+ * @throws java.lang.Exception
+ */
+ @Before
+ public void setUp() throws Exception {
+ type1 = UMLFactory.eINSTANCE.createPrimitiveType();
+ type1.setName("int");
+ type2 = UMLFactory.eINSTANCE.createPrimitiveType();
+ type2.setName("boolean");
+ type3 = UMLFactory.eINSTANCE.createPrimitiveType();
+ type3.setName("double");
+
+ typeCount = 2;
+ }
+
+ /**
+ * @throws java.lang.Exception
+ */
+ @After
+ public void tearDown() throws Exception {
+ }
+
+ /**
+ * Test method for {@link org.eclipse.papyrus.uml.profile.drafter.ui.model.CompoundTypeProvider#CompoundTypeProvider(org.eclipse.papyrus.uml.profile.drafter.ui.model.ITypeCatalog[])}.
+ */
+ @Test
+ public void testCompoundTypeProvider() {
+ ITypeCatalog provider1 = new TypeProvider(type1);
+ ITypeCatalog provider2 = new TypeProvider(type2);
+
+ CompoundTypeProvider provider = new CompoundTypeProvider(provider1, provider2);
+
+ assertNotNull("object created", provider);
+ }
+
+ /**
+ * Test method for {@link org.eclipse.papyrus.uml.profile.drafter.ui.model.CompoundTypeProvider#getTypes()}.
+ */
+ @Test
+ public void testGetTypes() {
+ ITypeCatalog provider1 = new TypeProvider(type1);
+ ITypeCatalog provider2 = new TypeProvider(type2);
+ int typeCount = 2;
+
+ CompoundTypeProvider provider = new CompoundTypeProvider(provider1, provider2);
+
+ assertNotNull("list created", provider.getTypes());
+ assertEquals("All types found", typeCount, provider.getTypes().size());
+
+
+ }
+
+ /**
+ * Test method for {@link org.eclipse.papyrus.uml.profile.drafter.ui.model.CompoundTypeProvider#iterator()}.
+ */
+ @Test
+ public void testIterator() {
+ ITypeCatalog provider1 = new TypeProvider(type1);
+ ITypeCatalog provider2 = new TypeProvider(type2);
+
+ CompoundTypeProvider provider = new CompoundTypeProvider(provider1, provider2);
+
+ assertNotNull("iterator found", provider.iterator());
+ }
+
+ /**
+ * Test method for {@link org.eclipse.papyrus.uml.profile.drafter.ui.model.CompoundTypeProvider#addITypeProvider(org.eclipse.papyrus.uml.profile.drafter.ui.model.ITypeCatalog)}.
+ */
+ @Test
+ public void testAddITypeProvider() {
+ ITypeCatalog provider1 = new TypeProvider(type1);
+ ITypeCatalog provider2 = new TypeProvider(type2);
+ int typeCount = 2;
+
+ CompoundTypeProvider provider = new CompoundTypeProvider(provider1);
+
+ provider.addITypeProvider(provider2);
+
+
+ assertNotNull("list created", provider.getTypes());
+ assertEquals("All types found", typeCount, provider.getTypes().size());
+ }
+
+}
diff --git a/plugins/uml/profile/org.eclipse.papyrus.uml.profile.drafter/test/org/eclipse/papyrus/uml/profile/drafter/ui/model/TypeProviderTest.java b/plugins/uml/profile/org.eclipse.papyrus.uml.profile.drafter/test/org/eclipse/papyrus/uml/profile/drafter/ui/model/TypeProviderTest.java
new file mode 100644
index 00000000000..cb6410e01b9
--- /dev/null
+++ b/plugins/uml/profile/org.eclipse.papyrus.uml.profile.drafter/test/org/eclipse/papyrus/uml/profile/drafter/ui/model/TypeProviderTest.java
@@ -0,0 +1,143 @@
+/*****************************************************************************
+ * Copyright (c) 2014 Cedric Dumoulin.
+ *
+ *
+ * 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:
+ * Cedric Dumoulin Cedric.dumoulin@lifl.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.uml.profile.drafter.ui.model;
+
+import static org.junit.Assert.*;
+
+import org.eclipse.uml2.uml.Type;
+import org.eclipse.uml2.uml.UMLFactory;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.Test;
+
+
+/**
+ * @author cedric dumoulin
+ *
+ */
+public class TypeProviderTest {
+
+ protected Type type1;
+ protected Type type2;
+ protected int typeCount;
+
+ /**
+ * @throws java.lang.Exception
+ */
+ @AfterClass
+ public static void tearDownAfterClass() throws Exception {
+ }
+
+ /**
+ * @throws java.lang.Exception
+ */
+ @Before
+ public void setUp() throws Exception {
+ type1 = UMLFactory.eINSTANCE.createPrimitiveType();
+ type1.setName("int");
+ type2 = UMLFactory.eINSTANCE.createPrimitiveType();
+ type2.setName("boolean");
+
+ typeCount = 2;
+
+ }
+
+ /**
+ * @throws java.lang.Exception
+ */
+ @After
+ public void tearDown() throws Exception {
+ type1 = null;
+ type2 = null;
+ typeCount = 0;
+
+ }
+
+ /**
+ * Test method for {@link org.eclipse.papyrus.uml.profile.drafter.ui.model.TypeProvider#TypeCatalog()}.
+ */
+ @Test
+ public void testTypeProvider() {
+ TypeProvider provider = new TypeProvider();
+
+ assertNotNull("object created", provider);
+ }
+
+ /**
+ * Test method for {@link org.eclipse.papyrus.uml.profile.drafter.ui.model.TypeProvider#TypeCatalog(org.eclipse.uml2.uml.Type[])}.
+ */
+ @Test
+ public void testTypeProviderTypeArray() {
+
+
+ TypeProvider provider = new TypeProvider(type1, type2);
+
+ assertNotNull("object created", provider);
+ assertNotNull("list created", provider.getTypes());
+ assertEquals("all types created", typeCount, provider.getTypes().size());
+ }
+
+ /**
+ * Test method for {@link org.eclipse.papyrus.uml.profile.drafter.ui.model.TypeProvider#getTypes()}.
+ */
+ @Test
+ public void testGetTypes() {
+ TypeProvider provider = new TypeProvider();
+
+ assertNotNull("list created", provider.getTypes());
+ }
+
+ /**
+ * Test method for {@link org.eclipse.papyrus.uml.profile.drafter.ui.model.TypeProvider#iterator()}.
+ */
+ @Test
+ public void testIterator() {
+ TypeProvider provider = new TypeProvider();
+
+ provider.addType(type1);
+ provider.addType(type2);
+
+ assertNotNull("iterator found", provider.iterator());
+ }
+
+ /**
+ * Test method for {@link org.eclipse.papyrus.uml.profile.drafter.ui.model.TypeProvider#addType(org.eclipse.uml2.uml.Type)}.
+ */
+ @Test
+ public void testAddType() {
+ TypeProvider provider = new TypeProvider();
+
+ provider.addType(type1);
+ provider.addType(type2);
+
+ assertNotNull("list created", provider.getTypes());
+ assertEquals("all types created", typeCount, provider.getTypes().size());
+ }
+
+ /**
+ * Test method for {@link org.eclipse.papyrus.uml.profile.drafter.ui.model.TypeProvider#addType(org.eclipse.uml2.uml.Type)}.
+ */
+ @Test
+ public void testAddTypeFromConstructor() {
+ TypeProvider provider = new TypeProvider(type1);
+
+ provider.addType(type2);
+
+ assertNotNull("list created", provider.getTypes());
+ assertEquals("all types created", typeCount, provider.getTypes().size());
+ }
+
+}

Back to the top