summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPetya Sabeva2012-10-23 10:34:32 (EDT)
committerPetya Sabeva2012-10-23 10:34:32 (EDT)
commit902baf826975f2cc80b8211d347a3bd52fd5cdeb (patch)
treeb80be9d426ce9046b746824aab54fe725256bc59
parentf975b1598455aba61d84d63085373e98b48b6740 (diff)
downloadwebtools.dali-902baf826975f2cc80b8211d347a3bd52fd5cdeb.zip
webtools.dali-902baf826975f2cc80b8211d347a3bd52fd5cdeb.tar.gz
webtools.dali-902baf826975f2cc80b8211d347a3bd52fd5cdeb.tar.bz2
Bug 364602 - JPA 2.0 - Support for embeddables + SWTBot tests
-rw-r--r--jpa_diagram_editor/development/org.eclipse.jpt.jpadiagrameditor.releng/pom.xml3
-rw-r--r--jpa_diagram_editor/development/org.eclipse.jpt.jpadiagrameditor.repository/pom.xml2
-rw-r--r--jpa_diagram_editor/features/org.eclipse.jpt.jpadiagrameditor.feature/pom.xml2
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.branding/pom.xml2
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.doc.user/pom.xml2
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/icons/ent/add_embeddable.gifbin0 -> 426 bytes
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/icons/ent/element-collection.gifbin0 -> 872 bytes
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/pom.xml4
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/JPADiagramEditor.java2
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/command/AddAttributeCommand.java31
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/command/CreateNewAttributeCommand.java13
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/command/DeleteAttributeCommand.java26
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/command/SetMappedByNewValueCommand.java19
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/AddAllEntitiesFeature.java2
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/AddHasReferenceRelationFeature.java118
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/AddInheritedEntityFeature.java70
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/AddJPAEntityFeature.java18
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/AddRelationFeature.java6
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateEmbeddableFeature.java (renamed from jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateJPAEntityFromMappedSuperclassFeature.java)209
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateInheritedEntityFeature.java42
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateJPAEntityFeature.java4
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateManyToManyBiDirRelationFeature.java35
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateManyToManyUniDirRelationFeature.java33
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateManyToOneBiDirRelationFeature.java34
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateManyToOneUniDirRelationFeature.java31
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateMappedSuperclassFeature.java4
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateOneToManyRelationFeature.java29
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateOneToManyUniDirRelationFeature.java8
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateOneToOneBiDirRelationFeature.java37
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateOneToOneUniDirRelationFeature.java37
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateRelationFeature.java203
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/DeleteJPAEntityFeature.java6
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/DeleteRelationFeature.java61
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/DirectEditAttributeFeature.java2
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/DirectEditJPAEntityFeature.java6
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/EmbedCollectionOfObjectsFeature.java252
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/EmbedSingleObjectFeature.java205
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/GraphicalRemoveAttributeFeature.java27
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/MoveEntityShapeFeature.java2
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/RefactorEntityFeature.java7
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/RemoveAttributeFeature.java34
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/RemoveRelationFeature.java6
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/UpdateAttributeFeature.java22
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/i18n/JPAEditorMessages.java24
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/i18n/messages.properties96
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/modelintegration/ui/JPADiagramEditorInput.java1
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/modelintegration/ui/OpenJpaDiagramActionDelegate.java6
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/modelintegration/util/CreateDiagramJob.java11
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/modelintegration/util/ModelIntegrationUtil.java5
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/propertypage/JPADiagramPropertyPage.java2
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/provider/IJPAEditorFeatureProvider.java21
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/provider/IJPAEditorImageCreator.java17
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/provider/JPAEditorFeatureProvider.java155
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/provider/JPAEditorImageCreator.java82
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/provider/JPAEditorImageProvider.java9
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/provider/JPAEditorToolBehaviorProvider.java50
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/AbstractRelation.java14
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/HasCollectionReferenceRelation.java24
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/HasReferanceRelation.java95
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/HasSingleReferenceRelation.java24
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/IBidirectionalRelation.java2
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/IsARelation.java11
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/ManyToManyBiDirRelation.java29
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/ManyToManyUniDirRelation.java11
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/ManyToOneBiDirRelation.java29
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/ManyToOneUniDirRelation.java11
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/OneToManyUniDirRelation.java11
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/OneToOneBiDirRelation.java21
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/OneToOneUniDirRelation.java11
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/EntityChangeListener.java47
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/IJPAEditorPredefinedRenderingStyle.java5
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/IJPAEditorUtil.java33
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/JPAEditorConstants.java28
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/JPAEditorPredefinedColoredAreas.java108
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/JPAEditorUtil.java307
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/JPAEditorUtilImpl.java57
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/JPASolver.java153
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/JpaArtifactFactory.java1065
-rw-r--r--jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.swtbot.tests/pom.xml2
-rw-r--r--jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.swtbot.tests/src/org/eclipse/jpt/jpadiagrameditor/swtbot/tests/ui/editor/ContextMenuHelper.java3
-rw-r--r--jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.swtbot.tests/src/org/eclipse/jpt/jpadiagrameditor/swtbot/tests/ui/editor/EditorProxy.java1816
-rw-r--r--jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.swtbot.tests/src/org/eclipse/jpt/jpadiagrameditor/swtbot/tests/ui/editor/ElementDisappears.java27
-rw-r--r--jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.swtbot.tests/src/org/eclipse/jpt/jpadiagrameditor/swtbot/tests/ui/editor/ElementIsShown.java2
-rw-r--r--jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.swtbot.tests/src/org/eclipse/jpt/jpadiagrameditor/swtbot/tests/ui/editor/EmbeddableInDiagramSWTBotTest.java1992
-rw-r--r--jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.swtbot.tests/src/org/eclipse/jpt/jpadiagrameditor/swtbot/tests/ui/editor/EntitiesInDiagramSWTBotTest.java1420
-rw-r--r--jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.swtbot.tests/src/org/eclipse/jpt/jpadiagrameditor/swtbot/tests/ui/editor/JPADiagramEditorSWTBotTest.java2466
-rw-r--r--jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.swtbot.tests/src/org/eclipse/jpt/jpadiagrameditor/swtbot/tests/ui/editor/MappedSuperclassesInDiagramSWTBotTest.java874
-rw-r--r--jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/pom.xml2
-rw-r--r--jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/feature/AddRelationFeatureTest.java4
-rw-r--r--jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/feature/CreateRelationFeaturesTest.java34
-rw-r--r--jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/provider/JPAEditorFeatureProviderTest.java2
-rw-r--r--jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/relation/CreateRelationAttributesTest.java22
-rw-r--r--jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/relation/CreateRelationsInFieldAnnotatedEntitiesTest.java35
-rw-r--r--jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/relation/CreateRelationsTest.java50
-rw-r--r--jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/util/JPAEditorUtilTest.java25
95 files changed, 8655 insertions, 4352 deletions
diff --git a/jpa_diagram_editor/development/org.eclipse.jpt.jpadiagrameditor.releng/pom.xml b/jpa_diagram_editor/development/org.eclipse.jpt.jpadiagrameditor.releng/pom.xml
index e0a040f..47848c4 100644
--- a/jpa_diagram_editor/development/org.eclipse.jpt.jpadiagrameditor.releng/pom.xml
+++ b/jpa_diagram_editor/development/org.eclipse.jpt.jpadiagrameditor.releng/pom.xml
@@ -4,11 +4,12 @@
<groupId>org.eclipse.jpt.jpadiagrameditor</groupId>
<artifactId>org.eclipse.jpt.jpadiagrameditor_parent</artifactId>
- <version>1.1.0-SNAPSHOT</version>
+ <version>1.2.0-SNAPSHOT</version>
<packaging>pom</packaging>
<properties>
<tycho-version>0.15.0</tycho-version>
+ <tycho.testArgLine>-Xmx512m -Xms128m -XX:PermSize=32m -XX:MaxPermSize=256m -DenableDebug -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=1044</tycho.testArgLine>
</properties>
<modules>
diff --git a/jpa_diagram_editor/development/org.eclipse.jpt.jpadiagrameditor.repository/pom.xml b/jpa_diagram_editor/development/org.eclipse.jpt.jpadiagrameditor.repository/pom.xml
index 00ac863..e11e17f 100644
--- a/jpa_diagram_editor/development/org.eclipse.jpt.jpadiagrameditor.repository/pom.xml
+++ b/jpa_diagram_editor/development/org.eclipse.jpt.jpadiagrameditor.repository/pom.xml
@@ -5,7 +5,7 @@
<parent>
<artifactId>org.eclipse.jpt.jpadiagrameditor_parent</artifactId>
<groupId>org.eclipse.jpt.jpadiagrameditor</groupId>
- <version>1.1.0-SNAPSHOT</version>
+ <version>1.2.0-SNAPSHOT</version>
<relativePath>../org.eclipse.jpt.jpadiagrameditor.releng/pom.xml</relativePath>
</parent>
diff --git a/jpa_diagram_editor/features/org.eclipse.jpt.jpadiagrameditor.feature/pom.xml b/jpa_diagram_editor/features/org.eclipse.jpt.jpadiagrameditor.feature/pom.xml
index c0ed14d..f9bb32e 100644
--- a/jpa_diagram_editor/features/org.eclipse.jpt.jpadiagrameditor.feature/pom.xml
+++ b/jpa_diagram_editor/features/org.eclipse.jpt.jpadiagrameditor.feature/pom.xml
@@ -5,7 +5,7 @@
<parent>
<artifactId>org.eclipse.jpt.jpadiagrameditor_parent</artifactId>
<groupId>org.eclipse.jpt.jpadiagrameditor</groupId>
- <version>1.1.0-SNAPSHOT</version>
+ <version>1.2.0-SNAPSHOT</version>
<relativePath>../../development/org.eclipse.jpt.jpadiagrameditor.releng/pom.xml</relativePath>
</parent>
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.branding/pom.xml b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.branding/pom.xml
index 8d023a9..be70157 100644
--- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.branding/pom.xml
+++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.branding/pom.xml
@@ -5,7 +5,7 @@
<parent>
<artifactId>org.eclipse.jpt.jpadiagrameditor_parent</artifactId>
<groupId>org.eclipse.jpt.jpadiagrameditor</groupId>
- <version>1.1.0-SNAPSHOT</version>
+ <version>1.2.0-SNAPSHOT</version>
<relativePath>../../development/org.eclipse.jpt.jpadiagrameditor.releng/pom.xml</relativePath>
</parent>
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.doc.user/pom.xml b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.doc.user/pom.xml
index 520c50d..1a2a423 100644
--- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.doc.user/pom.xml
+++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.doc.user/pom.xml
@@ -5,7 +5,7 @@
<parent>
<artifactId>org.eclipse.jpt.jpadiagrameditor_parent</artifactId>
<groupId>org.eclipse.jpt.jpadiagrameditor</groupId>
- <version>1.1.0-SNAPSHOT</version>
+ <version>1.2.0-SNAPSHOT</version>
<relativePath>../../development/org.eclipse.jpt.jpadiagrameditor.releng/pom.xml</relativePath>
</parent>
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/icons/ent/add_embeddable.gif b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/icons/ent/add_embeddable.gif
new file mode 100644
index 0000000..56fa623
--- /dev/null
+++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/icons/ent/add_embeddable.gif
Binary files differ
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/icons/ent/element-collection.gif b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/icons/ent/element-collection.gif
new file mode 100644
index 0000000..64706d2
--- /dev/null
+++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/icons/ent/element-collection.gif
Binary files differ
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/pom.xml b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/pom.xml
index 27ced13..a6c33f4 100644
--- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/pom.xml
+++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/pom.xml
@@ -1,12 +1,12 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
- <version>1.1.0-SNAPSHOT</version>
+ <version>1.2.0-SNAPSHOT</version>
<parent>
<artifactId>org.eclipse.jpt.jpadiagrameditor_parent</artifactId>
<groupId>org.eclipse.jpt.jpadiagrameditor</groupId>
- <version>1.1.0-SNAPSHOT</version>
+ <version>1.2.0-SNAPSHOT</version>
<relativePath>../../development/org.eclipse.jpt.jpadiagrameditor.releng/pom.xml</relativePath>
</parent>
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/JPADiagramEditor.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/JPADiagramEditor.java
index 0974bb9..b9facc1 100644
--- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/JPADiagramEditor.java
+++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/JPADiagramEditor.java
@@ -392,6 +392,4 @@ public class JPADiagramEditor extends DiagramEditor implements JpaEditorManager{
return null;
}
-
-
}
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/command/AddAttributeCommand.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/command/AddAttributeCommand.java
index 95bc69a..5c7d53e 100644
--- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/command/AddAttributeCommand.java
+++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/command/AddAttributeCommand.java
@@ -9,6 +9,7 @@ import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jpt.common.utility.command.Command;
+import org.eclipse.jpt.jpa.core.context.java.JavaPersistentAttribute;
import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.JPADiagramEditorPlugin;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.propertypage.JPADiagramPropertyPage;
@@ -48,18 +49,28 @@ public class AddAttributeCommand implements Command{
public void execute() {
IType type = null;
try {
- JPAEditorUtil.createImport(this.cu1, this.cu2.getType(this.attributeType.getName()).getElementName());
- type = this.cu1.findPrimaryType();
+ JPAEditorUtil.createImport(cu1, cu2.getType(attributeType.getName()).getElementName());
+ type = cu1.findPrimaryType();
- if (this.isCollection) {
- createAttributeOfCollectiontype(this.fp, this.jpt, this.attributeType,
- this.mapKeyType, this.attributeName, this.actName, this.cu1, type);
+ if (isCollection) {
+ createAttributeOfCollectiontype(fp, jpt, attributeType,
+ mapKeyType, attributeName, actName, cu1, type);
} else {
- createSimpleAttribute(this.attributeType, this.attributeName, this.actName,
- this.isCollection, type);
+ createSimpleAttribute(attributeType, attributeName, actName,
+ isCollection, type);
+ }
+
+ JavaPersistentAttribute attr = jpt.getAttributeNamed(attributeName);
+ int cnt = 0;
+ while ((attr == null) && (cnt < 25)) {
+ try {
+ Thread.sleep(250);
+ } catch (InterruptedException e) {
+ }
+ jpt.getJavaResourceType().getJavaResourceCompilationUnit().synchronizeWithJavaSource();
+ attr = jpt.getAttributeNamed(attributeName);
+ cnt++;
}
-
- this.jpt.getJavaResourceType().getJavaResourceCompilationUnit().synchronizeWithJavaSource();
} catch (JavaModelException e) {
JPADiagramEditorPlugin.logError("Cannnot create a new attribute with name " + attributeName, e); //$NON-NLS-1$
@@ -69,7 +80,7 @@ public class AddAttributeCommand implements Command{
private void createSimpleAttribute(JavaPersistentType attributeType,
String attributeName, String actName, boolean isCollection,
IType type) throws JavaModelException {
- type.createField(" private " + JPAEditorUtil.returnSimpleName(attributeType.getName()) + " "
+ type.createField(" private " + JPAEditorUtil.returnSimpleName(attributeType.getName()) + " " //$NON-NLS-1$ //$NON-NLS-2$
+ JPAEditorUtil.decapitalizeFirstLetter(actName) + ";", null, false, new NullProgressMonitor()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
type.createMethod(JpaArtifactFactory.instance().genGetterContents(attributeName,
JPAEditorUtil.returnSimpleName(attributeType.getName()), null,
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/command/CreateNewAttributeCommand.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/command/CreateNewAttributeCommand.java
index dd75c88..d6714db 100644
--- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/command/CreateNewAttributeCommand.java
+++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/command/CreateNewAttributeCommand.java
@@ -9,6 +9,7 @@ import org.eclipse.jdt.core.IImportDeclaration;
import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jpt.common.utility.command.Command;
+import org.eclipse.jpt.jpa.core.context.java.JavaPersistentAttribute;
import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JPAEditorUtil;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JpaArtifactFactory;
@@ -110,6 +111,16 @@ public class CreateNewAttributeCommand implements Command {
}
- jpt.getJavaResourceType().getJavaResourceCompilationUnit().synchronizeWithJavaSource();
+ JavaPersistentAttribute attr = jpt.getAttributeNamed(attrName);
+ int cnt = 0;
+ while ((attr == null) && (cnt < 25)) {
+ try {
+ Thread.sleep(250);
+ } catch (InterruptedException e) {
+ }
+ jpt.getJavaResourceType().getJavaResourceCompilationUnit().synchronizeWithJavaSource();
+ attr = jpt.getAttributeNamed(attrName);
+ cnt++;
+ }
}
}
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/command/DeleteAttributeCommand.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/command/DeleteAttributeCommand.java
index 5f3c699..5877009 100644
--- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/command/DeleteAttributeCommand.java
+++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/command/DeleteAttributeCommand.java
@@ -15,6 +15,8 @@ import org.eclipse.jpt.jpadiagrameditor.ui.internal.JPADiagramEditorPlugin;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.IJPAEditorFeatureProvider;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JPAEditorUtil;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JpaArtifactFactory;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IWorkbenchSite;
public class DeleteAttributeCommand implements Command {
@@ -32,19 +34,20 @@ public class DeleteAttributeCommand implements Command {
public void execute() {
synchronized (jpt) {
- String attrNameWithCapitalLetter = this.attributeName.substring(0, 1)
+ String attrNameWithCapitalLetter = attributeName.substring(0, 1)
.toUpperCase(Locale.ENGLISH)
- + this.attributeName.substring(1);
- ICompilationUnit compUnit = this.fp.getCompilationUnit(this.jpt);
+ + attributeName.substring(1);
+ ICompilationUnit compUnit = fp.getCompilationUnit(jpt);
IType javaType = compUnit.findPrimaryType();
-
+ JavaPersistentAttribute jpa = jpt.getAttributeNamed(attributeName);
+
String typeSignature = null;
String getterPrefix = "get"; //$NON-NLS-1$
String methodName = getterPrefix + attrNameWithCapitalLetter;
IMethod getAttributeMethod = javaType.getMethod(methodName,
new String[0]);
if (!getAttributeMethod.exists()) {
- JavaPersistentAttribute jpa = this.jpt.getAttributeNamed(this.attributeName);
+
String typeName = jpa.getResourceAttribute().getTypeBinding().getQualifiedName();
if ("boolean".equals(typeName)) { //$NON-NLS-1$
getterPrefix = "is"; //$NON-NLS-1$
@@ -63,17 +66,17 @@ public class DeleteAttributeCommand implements Command {
methodName = null;
boolean isMethodAnnotated = JpaArtifactFactory.instance()
- .isMethodAnnotated(this.jpt);
+ .isMethodAnnotated(jpt);
if (isMethodAnnotated) {
try {
- IField attributeField = javaType.getField(this.attributeName);
+ IField attributeField = javaType.getField(attributeName);
if ((attributeField != null) && !attributeField.exists())
- attributeField = javaType.getField(JPAEditorUtil.revertFirstLetterCase(this.attributeName));
+ attributeField = javaType.getField(JPAEditorUtil.revertFirstLetterCase(attributeName));
if ((attributeField != null) && attributeField.exists())
attributeField.delete(true, new NullProgressMonitor());
} catch (JavaModelException e) {
- JPADiagramEditorPlugin.logError("Cannot remove the attribute field with name " + this.attributeName, e); //$NON-NLS-1$
+ JPADiagramEditorPlugin.logError("Cannot remove the attribute field with name " + attributeName, e); //$NON-NLS-1$
}
try {
methodName = getterPrefix + attrNameWithCapitalLetter; //$NON-NLS-1$
@@ -99,7 +102,7 @@ public class DeleteAttributeCommand implements Command {
IField attributeField = javaType.getField(this.attributeName);
if (attributeField != null)
if (!attributeField.exists())
- attributeField = javaType.getField(JPAEditorUtil.revertFirstLetterCase(this.attributeName));
+ attributeField = javaType.getField(JPAEditorUtil.revertFirstLetterCase(attributeName));
if ((attributeField != null) && attributeField.exists())
attributeField.delete(true, new NullProgressMonitor());
} catch (JavaModelException e) {
@@ -115,6 +118,9 @@ public class DeleteAttributeCommand implements Command {
} catch (Exception e) {
JPADiagramEditorPlugin.logError("Cannot remove the attribute setter with name " + methodName + "(...)", e); //$NON-NLS-1$ //$NON-NLS-2$
}
+
+ IWorkbenchSite ws = ((IEditorPart) fp.getDiagramTypeProvider().getDiagramEditor()).getSite();
+ JPAEditorUtil.organizeImports(compUnit, ws);
this.jpt.getJavaResourceType().getJavaResourceCompilationUnit().synchronizeWithJavaSource();
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/command/SetMappedByNewValueCommand.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/command/SetMappedByNewValueCommand.java
index d16dffd..872c9a2 100644
--- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/command/SetMappedByNewValueCommand.java
+++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/command/SetMappedByNewValueCommand.java
@@ -16,11 +16,13 @@ public class SetMappedByNewValueCommand implements Command {
private String inverseEntityName;
private String inverseAttributeName;
private JavaPersistentAttribute newAt;
+ private JavaPersistentAttribute oldAt;
private IRelation rel;
public SetMappedByNewValueCommand(IJPAEditorFeatureProvider fp,
PersistenceUnit pu, String inverseEntityName,
String inverseAttributeName, JavaPersistentAttribute newAt,
+ JavaPersistentAttribute oldAt,
IRelation rel) {
super();
this.fp =fp;
@@ -28,16 +30,29 @@ public class SetMappedByNewValueCommand implements Command {
this.inverseEntityName = inverseEntityName;
this.inverseAttributeName = inverseAttributeName;
this.newAt = newAt;
+ this.oldAt = oldAt;
this.rel = rel;
}
public void execute() {
fp.addAttribForUpdate(pu, inverseEntityName
+ EntityChangeListener.SEPARATOR + inverseAttributeName
- + EntityChangeListener.SEPARATOR + newAt.getName());
+ + EntityChangeListener.SEPARATOR + newAt.getName()
+ + EntityChangeListener.SEPARATOR + oldAt.getName());
Annotation a = rel.getInverseAnnotatedAttribute().getMapping().getMappingAnnotation();
if (OwnableRelationshipMappingAnnotation.class.isInstance(a)) {
- ((OwnableRelationshipMappingAnnotation)a).setMappedBy(newAt.getName());
+ String mappedBy = ((OwnableRelationshipMappingAnnotation)a).getMappedBy();
+ String[] mappedByAttrs = mappedBy.split("\\."); //$NON-NLS-1$
+ if(mappedByAttrs.length > 1){
+ if(mappedByAttrs[0].equals(oldAt.getName())){
+ mappedBy = newAt.getName() + "." + mappedByAttrs[1]; //$NON-NLS-1$
+ } else if(mappedByAttrs[1].equals(oldAt.getName())){
+ mappedBy = mappedByAttrs[0] + "." + newAt.getName(); //$NON-NLS-1$
+ }
+ } else {
+ mappedBy = newAt.getName();
+ }
+ ((OwnableRelationshipMappingAnnotation)a).setMappedBy(mappedBy);
rel.getInverse().getJavaResourceType().getJavaResourceCompilationUnit().synchronizeWithJavaSource();
}
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/AddAllEntitiesFeature.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/AddAllEntitiesFeature.java
index 0e8e8bb..1390704 100644
--- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/AddAllEntitiesFeature.java
+++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/AddAllEntitiesFeature.java
@@ -100,7 +100,7 @@ public class AddAllEntitiesFeature extends AbstractCustomFeature implements IAdd
for (ClassRef classRef : unit.getClassRefs()) {
if (classRef.getJavaPersistentType() != null) { // null if
JavaPersistentType jpt = classRef.getJavaPersistentType();
- if (JpaArtifactFactory.instance().hasEntityOrMappedSuperclassAnnotation(jpt)) {
+ if (JpaArtifactFactory.instance().hasAnyAnnotationType(jpt)) {
PictogramElement pe = getFeatureProvider().getPictogramElementForBusinessObject(jpt);
if (pe != null)
continue;
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/AddHasReferenceRelationFeature.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/AddHasReferenceRelationFeature.java
new file mode 100644
index 0000000..75dcf8e
--- /dev/null
+++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/AddHasReferenceRelationFeature.java
@@ -0,0 +1,118 @@
+package org.eclipse.jpt.jpadiagrameditor.ui.internal.feature;
+
+import static org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.HasReferanceRelation.HasReferenceType.COLLECTION;
+
+import java.util.List;
+
+import org.eclipse.emf.transaction.RecordingCommand;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.emf.transaction.util.TransactionUtil;
+import org.eclipse.graphiti.features.IAddBendpointFeature;
+import org.eclipse.graphiti.features.IFeatureProvider;
+import org.eclipse.graphiti.features.context.IAddConnectionContext;
+import org.eclipse.graphiti.features.context.IAddContext;
+import org.eclipse.graphiti.features.context.impl.AddBendpointContext;
+import org.eclipse.graphiti.features.impl.AbstractAddFeature;
+import org.eclipse.graphiti.mm.pictograms.ConnectionDecorator;
+import org.eclipse.graphiti.mm.pictograms.Diagram;
+import org.eclipse.graphiti.mm.pictograms.FreeFormConnection;
+import org.eclipse.graphiti.mm.pictograms.PictogramElement;
+import org.eclipse.graphiti.services.Graphiti;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.IJPAEditorFeatureProvider;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.IJPAEditorImageCreator;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.JPAEditorImageCreator;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.HasReferanceRelation;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.HasReferanceRelation.HasReferenceType;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JPAEditorUtil;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.Wrp;
+import org.eclipse.swt.graphics.Point;
+
+public class AddHasReferenceRelationFeature extends AbstractAddFeature {
+
+ private static final double START_COEFFICIENT = 0.1;
+
+ private IJPAEditorImageCreator imageCreator;
+
+ public AddHasReferenceRelationFeature(IFeatureProvider fp) {
+ this(fp, new JPAEditorImageCreator());
+ }
+
+ public AddHasReferenceRelationFeature(IFeatureProvider fp,
+ IJPAEditorImageCreator imageCreator) {
+ super(fp);
+ this.imageCreator = imageCreator;
+ }
+
+ public boolean canAdd(IAddContext context) {
+ return true;
+ }
+
+ public PictogramElement add(IAddContext context) {
+ final IAddConnectionContext addConContext = (IAddConnectionContext) context;
+ final HasReferanceRelation relation = (HasReferanceRelation)context.getNewObject();
+ final Diagram diagram = getDiagram();
+ final Wrp wrp = new Wrp();
+
+ TransactionalEditingDomain ted = TransactionUtil.getEditingDomain(diagram);
+ RecordingCommand rc = new RecordingCommand(ted) {
+ protected void doExecute() {
+ FreeFormConnection connection = createConnection(addConContext, relation, diagram);
+ imageCreator.createHasReferenceConnectionLine(diagram, connection);
+ getFeatureProvider().putKeyToBusinessObject(relation.getId(), relation);
+ link(connection, relation);
+ layoutPictogramElement(connection);
+ wrp.setObj(connection);
+ }
+ };
+ try {
+ ted.getCommandStack().execute(rc);
+ } catch (Exception e){
+
+ }
+
+ return (PictogramElement)wrp.getObj();
+ }
+
+ private FreeFormConnection createConnection(IAddConnectionContext addConContext, HasReferanceRelation relation,
+ final Diagram diagram) {
+ FreeFormConnection connection = getFeatureProvider().getPeServiceUtil().createFreeFormConnection(diagram);
+ connection.setStart(addConContext.getSourceAnchor());
+ connection.setEnd(addConContext.getTargetAnchor());
+ connection.setVisible(true);
+ connection.setActive(true);
+ List<Point> points = JPAEditorUtil.createBendPointList(connection, false);
+ for (int i = 0; i < points.size(); i++) {
+ Point p = points.get(i);
+ AddBendpointContext ctx = new AddBendpointContext(connection, p.x, p.y, i);
+ IAddBendpointFeature ft = getFeatureProvider().getAddBendpointFeature(ctx);
+ ft.addBendpoint(ctx);
+ }
+ getFeatureProvider().getPeServiceUtil().setPropertyValue(connection, HasReferanceRelation.HAS_REFERENCE_CONNECTION_PROP_KEY, Boolean.TRUE.toString());
+ addDecorators(connection, relation);
+ addTextDecorators(connection, relation);
+
+ return connection;
+ }
+
+ public IJPAEditorFeatureProvider getFeatureProvider() {
+ return (IJPAEditorFeatureProvider)super.getFeatureProvider();
+ }
+
+ private void addDecorators(FreeFormConnection c, HasReferanceRelation rel) {
+ HasReferenceType relType = rel.getReferenceType();
+ double startCoefficient = START_COEFFICIENT;
+ double endCoefficient = 1.0 - startCoefficient;
+ int len = JPAEditorUtil.calcConnectionLength(c);
+ ConnectionDecorator d1 = imageCreator.createHasReferenceStartConnectionDecorator(c, startCoefficient);
+ Graphiti.getGaService().setLocation(d1.getGraphicsAlgorithm(), Math.round(len/10), 0);
+ if (COLLECTION.equals(relType)) {
+ ConnectionDecorator d = imageCreator.createManyEndDecorator(c, endCoefficient, true);
+ Graphiti.getGaService().setLocation(d.getGraphicsAlgorithm(),Math.round(-len/10), 0);
+ }
+ }
+
+
+ private void addTextDecorators(FreeFormConnection connection, HasReferanceRelation relation) {
+ imageCreator.createCardinalityConnectionDecorator(getDiagram(), connection, relation.getEmbeddedAnnotatedAttribute().getName(), 1.0);
+ }
+} \ No newline at end of file
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/AddInheritedEntityFeature.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/AddInheritedEntityFeature.java
index 86cf387..0e82104 100644
--- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/AddInheritedEntityFeature.java
+++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/AddInheritedEntityFeature.java
@@ -15,9 +15,16 @@
*******************************************************************************/
package org.eclipse.jpt.jpadiagrameditor.ui.internal.feature;
+import java.util.List;
+
+import org.eclipse.emf.transaction.RecordingCommand;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.emf.transaction.util.TransactionUtil;
+import org.eclipse.graphiti.features.IAddBendpointFeature;
import org.eclipse.graphiti.features.IFeatureProvider;
import org.eclipse.graphiti.features.context.IAddConnectionContext;
import org.eclipse.graphiti.features.context.IAddContext;
+import org.eclipse.graphiti.features.context.impl.AddBendpointContext;
import org.eclipse.graphiti.features.impl.AbstractAddFeature;
import org.eclipse.graphiti.mm.pictograms.ConnectionDecorator;
import org.eclipse.graphiti.mm.pictograms.Diagram;
@@ -28,21 +35,23 @@ import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.IJPAEditorFeaturePr
import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.IJPAEditorImageCreator;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.JPAEditorImageCreator;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.IsARelation;
-import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.IJPAEditorUtil;
-import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JPAEditorUtilImpl;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JPAEditorUtil;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.Wrp;
+import org.eclipse.swt.graphics.Point;
public class AddInheritedEntityFeature extends AbstractAddFeature {
+
+ private static final double START_COEFFICIENT = 0.1;
private IJPAEditorImageCreator imageCreator;
public AddInheritedEntityFeature(IFeatureProvider fp) {
- this(fp, new JPAEditorImageCreator(), new JPAEditorUtilImpl());
+ this(fp, new JPAEditorImageCreator());
}
public AddInheritedEntityFeature(IFeatureProvider fp,
- IJPAEditorImageCreator imageCreator,
- IJPAEditorUtil jpaEditorUtil) {
+ IJPAEditorImageCreator imageCreator) {
super(fp);
this.imageCreator = imageCreator;
}
@@ -53,24 +62,48 @@ public class AddInheritedEntityFeature extends AbstractAddFeature {
}
public PictogramElement add(IAddContext context) {
- final IAddConnectionContext addConContext = (IAddConnectionContext) context;
+ final IAddConnectionContext addConContext = (IAddConnectionContext) context;
+
final IsARelation relation = (IsARelation)context.getNewObject();
final Diagram diagram = getDiagram();
- FreeFormConnection connection = createIsAConnection(addConContext, relation, diagram);
- imageCreator.createIsAConnectionLine(diagram, connection);
- layoutPictogramElement(connection);
- return connection;
+ final Wrp wrp = new Wrp();
+
+ TransactionalEditingDomain ted = TransactionUtil.getEditingDomain(diagram);
+ RecordingCommand rc = new RecordingCommand(ted) {
+ protected void doExecute() {
+ FreeFormConnection connection = createConnection(addConContext, diagram);
+ imageCreator.createIsAConnectionLine(diagram, connection);
+ getFeatureProvider().putKeyToBusinessObject(relation.getId(), relation);
+ link(connection, relation);
+ layoutPictogramElement(connection);
+ wrp.setObj(connection);
+ }
+ };
+ try {
+ ted.getCommandStack().execute(rc);
+ } catch (Exception e){
+
+ }
+
+ return (PictogramElement)wrp.getObj();
}
- private FreeFormConnection createIsAConnection(IAddConnectionContext addConContext, IsARelation relation,
- final Diagram diagram) {
- FreeFormConnection connection = getFeatureProvider().getPeService().createFreeFormConnection(diagram);
+ private FreeFormConnection createConnection(IAddConnectionContext addConContext, final Diagram diagram) {
+ FreeFormConnection connection = getFeatureProvider().getPeServiceUtil().createFreeFormConnection(diagram);
connection.setStart(addConContext.getSourceAnchor());
connection.setEnd(addConContext.getTargetAnchor());
connection.setVisible(true);
- connection.setActive(true);
+ connection.setActive(true);
+ List<Point> points = JPAEditorUtil.createBendPointList(connection, false);
+ for (int i = 0; i < points.size(); i++) {
+ Point p = points.get(i);
+ AddBendpointContext ctx = new AddBendpointContext(connection, p.x, p.y, i);
+ IAddBendpointFeature ft = getFeatureProvider().getAddBendpointFeature(ctx);
+ ft.addBendpoint(ctx);
+ }
getFeatureProvider().getPeServiceUtil().setPropertyValue(connection, IsARelation.IS_A_CONNECTION_PROP_KEY, Boolean.TRUE.toString());
addDecorators(connection);
+
return connection;
}
@@ -78,9 +111,12 @@ public class AddInheritedEntityFeature extends AbstractAddFeature {
return (IJPAEditorFeatureProvider)super.getFeatureProvider();
}
- private void addDecorators(FreeFormConnection c) {
- ConnectionDecorator d = imageCreator.createArrowConnectionDecorator(c, 0.9999, true);
- Graphiti.getGaService().setLocation(d.getGraphicsAlgorithm(), 0, 0);
+ private void addDecorators(FreeFormConnection c) {
+ double startCoefficient = START_COEFFICIENT;
+ double endCoefficient = 1.0 - startCoefficient;
+ int len = JPAEditorUtil.calcConnectionLength(c);
+ ConnectionDecorator d1 = imageCreator.createIsAArrowConnectionDecorator(c, endCoefficient);
+ Graphiti.getGaService().setLocation(d1.getGraphicsAlgorithm(), Math.round(-len/10), 0);
}
}
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/AddJPAEntityFeature.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/AddJPAEntityFeature.java
index efb15d7..27ecc16 100644
--- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/AddJPAEntityFeature.java
+++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/AddJPAEntityFeature.java
@@ -347,13 +347,25 @@ public class AddJPAEntityFeature extends AbstractAddShapeFeature {
return entityRectangle;
}
+ private String determineTheAppropriateTypeCommand(JPAEditorConstants.DIAGRAM_OBJECT_TYPE dot){
+ String typeIconId = ""; //$NON-NLS-1$
+ if(dot.equals(JPAEditorConstants.DIAGRAM_OBJECT_TYPE.Entity)){
+ typeIconId = JPAEditorImageProvider.JPA_ENTITY;
+ } else if (dot.equals(JPAEditorConstants.DIAGRAM_OBJECT_TYPE.MappedSupeclass)){
+ typeIconId = JPAEditorImageProvider.MAPPED_SUPERCLASS;
+ } else if (dot.equals(JPAEditorConstants.DIAGRAM_OBJECT_TYPE.Embeddable)){
+ typeIconId = JPAEditorImageProvider.EMBEDDABLE;
+ }
+
+ return typeIconId;
+ }
+
private ContainerShape addHeader(JavaPersistentType addedWrapper,
ContainerShape entityShape,
int width,
JPAEditorConstants.DIAGRAM_OBJECT_TYPE dot) {
- String entityIconId = dot.equals(JPAEditorConstants.DIAGRAM_OBJECT_TYPE.Entity) ?
- JPAEditorImageProvider.JPA_ENTITY :
- JPAEditorImageProvider.MAPPED_SUPERCLASS;
+
+ String entityIconId = determineTheAppropriateTypeCommand(dot);
ContainerShape headerIconShape = Graphiti.getPeService().createContainerShape(
entityShape, false);
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/AddRelationFeature.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/AddRelationFeature.java
index 3b148d6..0f8498d 100644
--- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/AddRelationFeature.java
+++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/AddRelationFeature.java
@@ -151,7 +151,7 @@ public class AddRelationFeature extends AbstractAddFeature {
double endCoefficient = 1.0 - startCoefficient;
int len = JPAEditorUtil.calcConnectionLength(c);
if (UNI.equals(direction)) {
- ConnectionDecorator d = imageCreator.createArrowConnectionDecorator(c, endCoefficient, false);
+ ConnectionDecorator d = imageCreator.createArrowConnectionDecorator(c, endCoefficient);
Graphiti.getGaService().setLocation(d.getGraphicsAlgorithm(),Math.round(-len/10), 0);
}
}
@@ -171,7 +171,7 @@ public class AddRelationFeature extends AbstractAddFeature {
ConnectionDecorator d1 = imageCreator.createManyStartDecorator(c, startCoefficient);
Graphiti.getGaService().setLocation(d1.getGraphicsAlgorithm(),Math.round(len/10), 0);
if (UNI.equals(direction)) {
- ConnectionDecorator d2 = imageCreator.createArrowConnectionDecorator(c, endCoefficient, false);
+ ConnectionDecorator d2 = imageCreator.createArrowConnectionDecorator(c, endCoefficient);
Graphiti.getGaService().setLocation(d2.getGraphicsAlgorithm(),Math.round(-len/10), 0);
}
}
@@ -186,7 +186,7 @@ public class AddRelationFeature extends AbstractAddFeature {
ConnectionDecorator d = imageCreator.createManyEndWithArrowDecorator(c, endCoefficient);
Graphiti.getGaService().setLocation(d.getGraphicsAlgorithm(),Math.round(-len/10), 0);
} else {
- ConnectionDecorator d = imageCreator.createManyEndDecorator(c, endCoefficient);
+ ConnectionDecorator d = imageCreator.createManyEndDecorator(c, endCoefficient, false);
Graphiti.getGaService().setLocation(d.getGraphicsAlgorithm(),Math.round(-len/10), 0);
}
}
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateJPAEntityFromMappedSuperclassFeature.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateEmbeddableFeature.java
index 504c88a..f25fa0f 100644
--- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateJPAEntityFromMappedSuperclassFeature.java
+++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateEmbeddableFeature.java
@@ -1,97 +1,112 @@
-package org.eclipse.jpt.jpadiagrameditor.ui.internal.feature;
-
-import java.util.List;
-import org.eclipse.core.resources.IProject;
-import org.eclipse.graphiti.features.IFeatureProvider;
-import org.eclipse.graphiti.features.context.ICreateContext;
-import org.eclipse.graphiti.features.impl.AbstractCreateFeature;
-import org.eclipse.graphiti.mm.pictograms.Diagram;
-import org.eclipse.graphiti.mm.pictograms.Shape;
-import org.eclipse.jface.preference.IPreferenceStore;
-import org.eclipse.jpt.jpa.core.JpaPreferences;
-import org.eclipse.jpt.jpa.core.JpaProject;
-import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType;
-import org.eclipse.jpt.jpadiagrameditor.ui.internal.JPADiagramEditorPlugin;
-import org.eclipse.jpt.jpadiagrameditor.ui.internal.i18n.JPAEditorMessages;
-import org.eclipse.jpt.jpadiagrameditor.ui.internal.propertypage.JPADiagramPropertyPage;
-import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.IJPAEditorFeatureProvider;
-import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.JPAEditorImageProvider;
-import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JPAEditorUtil;
-
-
-
-public class CreateJPAEntityFromMappedSuperclassFeature extends
- AbstractCreateFeature {
- private IPreferenceStore jpaPreferenceStore = JPADiagramEditorPlugin
- .getDefault().getPreferenceStore();
-
- public CreateJPAEntityFromMappedSuperclassFeature(IFeatureProvider fp) {
- super(
- fp,
- JPAEditorMessages.CreateJPAEntityFromMappedSuperclassFeature_createInheritedEntityFeatureName,
- JPAEditorMessages.CreateJPAEntityFromMappedSuperclassFeature_createInheritedEntityFeatureDescription);
- }
-
- public boolean canCreate(ICreateContext context) {
- return context.getTargetContainer() instanceof Diagram;
- }
-
- public Object[] create(ICreateContext context) {
- List<Shape> shapes = this.getFeatureProvider().getDiagramTypeProvider()
- .getDiagram().getChildren();
- IProject targetProject = null;
- JpaProject jpaProject = null;
- if ((shapes == null) || (shapes.size() == 0)) {
- jpaProject = getTargetJPAProject();
- targetProject = jpaProject.getProject();
- } else {
- Shape sh = shapes.get(0);
- JavaPersistentType jpt = (JavaPersistentType) getFeatureProvider()
- .getBusinessObjectForPictogramElement(sh);
- if (jpt == null)
- return new Object[] {};
- jpaProject = jpt.getJpaProject();
- targetProject = jpaProject.getProject();
- }
-
- String mappedSuperclassName = getFeatureProvider()
- .getJPAEditorUtil()
- .generateUniqueMappedSuperclassName(
- jpaProject,
- JPADiagramPropertyPage.getDefaultPackage(jpaProject.getProject()),
- getFeatureProvider());
-
- if (! JpaPreferences.getDiscoverAnnotatedClasses(jpaProject.getProject())) {
- JPAEditorUtil.createRegisterEntityInXMLJob(jpaProject, mappedSuperclassName);
- }
-
-
- try {
- this.getFeatureProvider()
- .getJPAEditorUtil()
- .createEntityFromMappedSuperclassInProject(targetProject,
- mappedSuperclassName, jpaPreferenceStore);
- } catch (Exception e1) {
- JPADiagramEditorPlugin.logError("Cannot create an entity in the project " + targetProject.getName(), e1); //$NON-NLS-1$
- }
-
- CreateJPAEntityFeature createEntityFeature = new CreateJPAEntityFeature(
- getFeatureProvider(), true, mappedSuperclassName);
- return createEntityFeature.create(context);
- }
-
- public String getCreateImageId() {
- return JPAEditorImageProvider.ADD_INHERITED_ENTITY;
- }
-
-
- public IJPAEditorFeatureProvider getFeatureProvider() {
- return (IJPAEditorFeatureProvider) super.getFeatureProvider();
- }
-
- private JpaProject getTargetJPAProject() {
- return getFeatureProvider().getMoinIntegrationUtil()
- .getProjectByDiagram(getDiagram());
- }
-
-}
+package org.eclipse.jpt.jpadiagrameditor.ui.internal.feature;
+
+import java.util.List;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.graphiti.features.IFeatureProvider;
+import org.eclipse.graphiti.features.context.ICreateContext;
+import org.eclipse.graphiti.features.impl.AbstractCreateFeature;
+import org.eclipse.graphiti.mm.pictograms.Diagram;
+import org.eclipse.graphiti.mm.pictograms.Shape;
+import org.eclipse.jdt.core.ICompilationUnit;
+import org.eclipse.jpt.jpa.core.JpaPreferences;
+import org.eclipse.jpt.jpa.core.JpaProject;
+import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType;
+import org.eclipse.jpt.jpa.core.context.persistence.PersistenceUnit;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.JPADiagramEditorPlugin;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.i18n.JPAEditorMessages;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.propertypage.JPADiagramPropertyPage;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.IJPAEditorFeatureProvider;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.JPAEditorImageProvider;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JPAEditorUtil;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JpaArtifactFactory;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IWorkbenchSite;
+
+public class CreateEmbeddableFeature extends AbstractCreateFeature {
+
+ public CreateEmbeddableFeature(IFeatureProvider fp) {
+ super(
+ fp,
+ JPAEditorMessages.CreateEmbeddableFeature_EmbeddableFeatureName,
+ JPAEditorMessages.CreateEmbeddableFeature_EmbeddableFeatureDescription);
+ }
+
+ public boolean canCreate(ICreateContext context) {
+ return context.getTargetContainer() instanceof Diagram;
+ }
+
+ public Object[] create(ICreateContext context) {
+ List<Shape> shapes = this.getFeatureProvider().getDiagramTypeProvider()
+ .getDiagram().getChildren();
+ IProject targetProject = null;
+ JpaProject jpaProject = null;
+ if ((shapes == null) || (shapes.size() == 0)) {
+ jpaProject = getTargetJPAProject();
+ targetProject = jpaProject.getProject();
+ } else {
+ Shape sh = shapes.get(0);
+ JavaPersistentType jpt = (JavaPersistentType) getFeatureProvider()
+ .getBusinessObjectForPictogramElement(sh);
+ if (jpt == null)
+ return new Object[] {};
+ jpaProject = jpt.getJpaProject();
+ targetProject = jpaProject.getProject();
+ }
+
+ String embeddableName = getFeatureProvider().getJPAEditorUtil()
+ .generateUniqueTypeName(
+ jpaProject,
+ JPADiagramPropertyPage.getDefaultPackage(jpaProject.getProject()),
+ ".Embeddable", getFeatureProvider()); //$NON-NLS-1$
+
+ if (!JpaPreferences
+ .getDiscoverAnnotatedClasses(jpaProject.getProject())) {
+ JPAEditorUtil.createRegisterEntityInXMLJob(jpaProject,
+ embeddableName);
+ }
+
+ try {
+ getFeatureProvider().getJPAEditorUtil()
+ .createEmbeddableInProject(targetProject, embeddableName);
+ } catch (Exception e1) {
+ JPADiagramEditorPlugin
+ .logError(
+ "Cannot create a embeddable in the project " + targetProject.getName(), e1); //$NON-NLS-1$
+ }
+ // jpaProject.updateAndWait();
+ PersistenceUnit pu = JpaArtifactFactory.instance().getPersistenceUnit(
+ jpaProject);
+ JavaPersistentType jpt = JpaArtifactFactory.instance().getJPT(
+ embeddableName, pu);
+
+ if (jpt != null) {
+ addGraphicalRepresentation(context, jpt);
+ IWorkbenchSite ws = ((IEditorPart) getDiagramEditor()).getSite();
+ ICompilationUnit cu = getFeatureProvider().getCompilationUnit(jpt);
+ getFeatureProvider().getJPAEditorUtil().formatCode(cu, ws);
+ return new Object[] { jpt };
+ } else {
+ JPADiagramEditorPlugin
+ .logError(
+ "The embeddable " + //$NON-NLS-1$
+ embeddableName
+ + " could not be created", new Exception()); //$NON-NLS-1$
+ }
+
+ return new Object[] {};
+ }
+
+ public String getCreateImageId() {
+ return JPAEditorImageProvider.ADD_EMBEDDABLE;
+ }
+
+ public IJPAEditorFeatureProvider getFeatureProvider() {
+ return (IJPAEditorFeatureProvider) super.getFeatureProvider();
+ }
+
+ private JpaProject getTargetJPAProject() {
+ return getFeatureProvider().getMoinIntegrationUtil()
+ .getProjectByDiagram(getDiagram());
+ }
+}
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateInheritedEntityFeature.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateInheritedEntityFeature.java
index df7edb2..e7f47cd 100644
--- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateInheritedEntityFeature.java
+++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateInheritedEntityFeature.java
@@ -25,12 +25,18 @@ import org.eclipse.graphiti.mm.pictograms.Anchor;
import org.eclipse.graphiti.mm.pictograms.Connection;
import org.eclipse.graphiti.mm.pictograms.Diagram;
import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jpt.jpa.core.JpaProject;
+import org.eclipse.jpt.jpa.core.context.Embeddable;
import org.eclipse.jpt.jpa.core.context.PersistentType;
import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType;
+import org.eclipse.jpt.jpa.core.context.persistence.ClassRef;
+import org.eclipse.jpt.jpa.core.context.persistence.PersistenceUnit;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.JPADiagramEditorPlugin;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.i18n.JPAEditorMessages;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.modelintegration.util.ModelIntegrationUtil;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.IJPAEditorFeatureProvider;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.JPAEditorImageProvider;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JpaArtifactFactory;
public class CreateInheritedEntityFeature extends AbstractCreateConnectionFeature {
@@ -101,6 +107,40 @@ public class CreateInheritedEntityFeature extends AbstractCreateConnectionFeatur
public IJPAEditorFeatureProvider getFeatureProvider() {
return (IJPAEditorFeatureProvider)super.getFeatureProvider();
}
-
+
+ @Override
+ public void endConnecting() {
+ super.endConnecting();
+ getFeatureProvider().setOriginalPersistentTypeColor();
+ }
+
+ @Override
+ public void startConnecting() {
+ super.startConnecting();
+ disableAllNotValidJPTs();
+ }
+
+ @SuppressWarnings("restriction")
+ private void disableAllNotValidJPTs(){
+ Diagram d = getDiagram();
+ JpaProject project = ModelIntegrationUtil.getProjectByDiagram(d.getName());
+ PersistenceUnit unit = project.getRootContextNode().getPersistenceXml().
+ getRoot().getPersistenceUnits().iterator().next();
+ disableAllEmbeddables(unit);
+ }
+
+ /**
+ * Disable (color in gray) all {@link Embeddable}s registered in the persistence unit.
+ * @param unit
+ */
+ private void disableAllEmbeddables(PersistenceUnit unit) {
+ for (ClassRef classRef : unit.getClassRefs()) {
+ if (classRef.getJavaPersistentType() != null) {
+ final JavaPersistentType jpt = classRef.getJavaPersistentType();
+ if(JpaArtifactFactory.instance().hasEmbeddableAnnotation(jpt))
+ getFeatureProvider().setGrayColor(jpt);
+ }
+ }
+ }
}
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateJPAEntityFeature.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateJPAEntityFeature.java
index a2ccf02..02d90ba 100644
--- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateJPAEntityFeature.java
+++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateJPAEntityFeature.java
@@ -117,9 +117,9 @@ public class CreateJPAEntityFeature extends AbstractCreateFeature {
targetProject = jpaProject.getProject();
}
String entityName = getFeatureProvider().getJPAEditorUtil().
- generateUniqueEntityName(jpaProject,
+ generateUniqueTypeName(jpaProject,
JPADiagramPropertyPage.getDefaultPackage(jpaProject.getProject()),
- getFeatureProvider());
+ ".Entity", getFeatureProvider()); //$NON-NLS-1$
if(!JPAEditorUtil.checkIsSetPersistenceProviderLibrary(jpaProject)){
Shell shell = JPADiagramEditorPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getShell();
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateManyToManyBiDirRelationFeature.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateManyToManyBiDirRelationFeature.java
index a861fbf..af75f94 100644
--- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateManyToManyBiDirRelationFeature.java
+++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateManyToManyBiDirRelationFeature.java
@@ -15,12 +15,17 @@
*******************************************************************************/
package org.eclipse.jpt.jpadiagrameditor.ui.internal.feature;
+import java.util.HashSet;
+import java.util.Set;
+
import org.eclipse.graphiti.mm.pictograms.PictogramElement;
import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.i18n.JPAEditorMessages;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.IJPAEditorFeatureProvider;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.JPAEditorImageProvider;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.HasReferanceRelation;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.ManyToManyBiDirRelation;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JPAEditorConstants;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JPAEditorUtil;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JpaArtifactFactory;
@@ -34,7 +39,7 @@ public class CreateManyToManyBiDirRelationFeature extends CreateManyToManyRelati
}
@Override
- public ManyToManyBiDirRelation createRelation(IJPAEditorFeatureProvider fp, PictogramElement source, PictogramElement target) {
+ public ManyToManyBiDirRelation createRelation(IJPAEditorFeatureProvider fp, PictogramElement source, PictogramElement target, JavaPersistentType embeddingEntity) {
JavaPersistentType owner = (JavaPersistentType)(getBusinessObjectForPictogramElement(source));
JavaPersistentType inverse = (JavaPersistentType)(getBusinessObjectForPictogramElement(target));
@@ -50,15 +55,33 @@ public class CreateManyToManyBiDirRelationFeature extends CreateManyToManyRelati
nameWithNonCapitalLetter2 = JPAEditorUtil.produceValidAttributeName(inverseAttributeName);
String inverseAttributeText = JPAEditorUtil.produceUniqueAttributeName(inverse, ownerAttributeText, nameWithNonCapitalLetter2);
- ManyToManyBiDirRelation rel = new ManyToManyBiDirRelation(fp, owner, inverse, ownerAttributeText, inverseAttributeText, true,
- getFeatureProvider().getCompilationUnit(owner),
- getFeatureProvider().getCompilationUnit(inverse));
+ ManyToManyBiDirRelation rel = new ManyToManyBiDirRelation(fp, owner, inverse, ownerAttributeText, inverseAttributeText, true, embeddingEntity);
return rel;
}
public String getCreateImageId() {
return JPAEditorImageProvider.ICON_MANY_TO_MANY_2_DIR;
- }
-
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jpt.jpadiagrameditor.ui.internal.feature.CreateRelationFeature#isRelationshipPossible()
+ */
+ @Override
+ protected boolean isRelationshipPossible() {
+ if(JpaArtifactFactory.instance().hasEmbeddableAnnotation(owner)) {
+ Set<HasReferanceRelation> refs = JpaArtifactFactory.instance().findAllHasReferenceRelsByEmbeddableWithEntity(owner, getFeatureProvider());
+ if (refs.size() != 1)
+ return false;
+ for (HasReferanceRelation ref : refs) {
+ HashSet<String> annotations = JpaArtifactFactory.instance().getAnnotationNames(ref.getEmbeddedAnnotatedAttribute());
+ for (String annotationName : annotations) {
+ if (annotationName.equals(JPAEditorConstants.ANNOTATION_ELEMENT_COLLECTION) || annotationName.equals(JPAEditorConstants.ANNOTATION_EMBEDDED_ID)) {
+ return false;
+ }
+ }
+ }
+ }
+ return true;
+ }
} \ No newline at end of file
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateManyToManyUniDirRelationFeature.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateManyToManyUniDirRelationFeature.java
index 54f5bd3..f227422 100644
--- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateManyToManyUniDirRelationFeature.java
+++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateManyToManyUniDirRelationFeature.java
@@ -15,12 +15,17 @@
*******************************************************************************/
package org.eclipse.jpt.jpadiagrameditor.ui.internal.feature;
+import java.util.HashSet;
+import java.util.Set;
+
import org.eclipse.graphiti.mm.pictograms.PictogramElement;
import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.i18n.JPAEditorMessages;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.IJPAEditorFeatureProvider;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.JPAEditorImageProvider;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.HasReferanceRelation;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.ManyToManyUniDirRelation;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JPAEditorConstants;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JPAEditorUtil;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JpaArtifactFactory;
@@ -34,7 +39,7 @@ public class CreateManyToManyUniDirRelationFeature extends CreateManyToManyRelat
}
@Override
- public ManyToManyUniDirRelation createRelation(IJPAEditorFeatureProvider fp, PictogramElement source, PictogramElement target) {
+ public ManyToManyUniDirRelation createRelation(IJPAEditorFeatureProvider fp, PictogramElement source, PictogramElement target, JavaPersistentType embeddingEntity) {
JavaPersistentType owner = (JavaPersistentType)(getBusinessObjectForPictogramElement(source));
JavaPersistentType inverse = (JavaPersistentType)(getBusinessObjectForPictogramElement(target));
@@ -43,14 +48,32 @@ public class CreateManyToManyUniDirRelationFeature extends CreateManyToManyRelat
if (JpaArtifactFactory.instance().isMethodAnnotated(owner))
nameWithNonCapitalLetter = JPAEditorUtil.produceValidAttributeName(attributeName);
String attributeText = JPAEditorUtil.produceUniqueAttributeName(owner, nameWithNonCapitalLetter);
- ManyToManyUniDirRelation relation = new ManyToManyUniDirRelation(fp, owner, inverse, attributeText, true,
- getFeatureProvider().getCompilationUnit(owner),
- getFeatureProvider().getCompilationUnit(inverse));
+ ManyToManyUniDirRelation relation = new ManyToManyUniDirRelation(fp, owner, inverse, attributeText, true);
return relation;
}
public String getCreateImageId() {
return JPAEditorImageProvider.ICON_MANY_TO_MANY_1_DIR;
- }
+ }
+
+ @Override
+ protected boolean isRelationshipPossible() {
+ if(JpaArtifactFactory.instance().hasEmbeddableAnnotation(owner)) {
+ Set<HasReferanceRelation> refs = JpaArtifactFactory.instance().findAllHasReferenceRelsByEmbeddableWithEntity(owner, getFeatureProvider());
+ if (refs.isEmpty()) {
+ return false;
+ } else {
+ for (HasReferanceRelation ref : refs) {
+ HashSet<String> annotations = JpaArtifactFactory.instance().getAnnotationNames(ref.getEmbeddedAnnotatedAttribute());
+ for (String annotationName : annotations) {
+ if (annotationName.equals(JPAEditorConstants.ANNOTATION_ELEMENT_COLLECTION) || annotationName.equals(JPAEditorConstants.ANNOTATION_EMBEDDED_ID)) {
+ return false;
+ }
+ }
+ }
+ }
+ }
+ return true;
+ }
} \ No newline at end of file
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateManyToOneBiDirRelationFeature.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateManyToOneBiDirRelationFeature.java
index c29e2b8..1c6e2ff 100644
--- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateManyToOneBiDirRelationFeature.java
+++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateManyToOneBiDirRelationFeature.java
@@ -15,12 +15,17 @@
*******************************************************************************/
package org.eclipse.jpt.jpadiagrameditor.ui.internal.feature;
+import java.util.HashSet;
+import java.util.Set;
+
import org.eclipse.graphiti.mm.pictograms.PictogramElement;
import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.i18n.JPAEditorMessages;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.IJPAEditorFeatureProvider;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.JPAEditorImageProvider;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.HasReferanceRelation;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.ManyToOneBiDirRelation;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JPAEditorConstants;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JPAEditorUtil;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JpaArtifactFactory;
@@ -35,7 +40,7 @@ public class CreateManyToOneBiDirRelationFeature extends CreateManyToOneRelation
@Override
public ManyToOneBiDirRelation createRelation(IJPAEditorFeatureProvider fp, PictogramElement source,
- PictogramElement target) {
+ PictogramElement target, JavaPersistentType embeddingEntity) {
JavaPersistentType owner = (JavaPersistentType)(getBusinessObjectForPictogramElement(source));
JavaPersistentType inverse = (JavaPersistentType)(getBusinessObjectForPictogramElement(target));
@@ -51,14 +56,31 @@ public class CreateManyToOneBiDirRelationFeature extends CreateManyToOneRelation
nameWithNonCapitalLetter2 = JPAEditorUtil.produceValidAttributeName(inverseAttributeName);
String inverseAttributeText = JPAEditorUtil.produceUniqueAttributeName(inverse, ownerAttributeText, nameWithNonCapitalLetter2);
- ManyToOneBiDirRelation rel = new ManyToOneBiDirRelation(fp, owner, inverse, ownerAttributeText, inverseAttributeText, true,
- getFeatureProvider().getCompilationUnit(owner),
- getFeatureProvider().getCompilationUnit(inverse));
+ ManyToOneBiDirRelation rel = new ManyToOneBiDirRelation(fp, owner, inverse, ownerAttributeText, inverseAttributeText, true, embeddingEntity);
return rel;
}
public String getCreateImageId() {
return JPAEditorImageProvider.ICON_MANY_TO_ONE_2_DIR;
- }
-
+ }
+
+ @Override
+ protected boolean isRelationshipPossible() {
+ if(JpaArtifactFactory.instance().hasEmbeddableAnnotation(owner)) {
+ Set<HasReferanceRelation> refs = JpaArtifactFactory.instance().findAllHasReferenceRelsByEmbeddableWithEntity(owner, getFeatureProvider());
+ if (refs.size() != 1){
+ return false;
+ } else {
+ for (HasReferanceRelation ref : refs) {
+ HashSet<String> annotations = JpaArtifactFactory.instance().getAnnotationNames(ref.getEmbeddedAnnotatedAttribute());
+ for (String annotationName : annotations) {
+ if (annotationName.equals(JPAEditorConstants.ANNOTATION_EMBEDDED_ID)) {
+ return false;
+ }
+ }
+ }
+ }
+ }
+ return true;
+ }
} \ No newline at end of file
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateManyToOneUniDirRelationFeature.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateManyToOneUniDirRelationFeature.java
index 8355aa6..7280e65 100644
--- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateManyToOneUniDirRelationFeature.java
+++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateManyToOneUniDirRelationFeature.java
@@ -15,12 +15,17 @@
*******************************************************************************/
package org.eclipse.jpt.jpadiagrameditor.ui.internal.feature;
+import java.util.HashSet;
+import java.util.Set;
+
import org.eclipse.graphiti.mm.pictograms.PictogramElement;
import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.i18n.JPAEditorMessages;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.IJPAEditorFeatureProvider;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.JPAEditorImageProvider;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.HasReferanceRelation;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.ManyToOneUniDirRelation;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JPAEditorConstants;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JPAEditorUtil;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JpaArtifactFactory;
@@ -34,7 +39,7 @@ public class CreateManyToOneUniDirRelationFeature extends CreateManyToOneRelatio
}
@Override
- public ManyToOneUniDirRelation createRelation(IJPAEditorFeatureProvider fp, PictogramElement source, PictogramElement target) {
+ public ManyToOneUniDirRelation createRelation(IJPAEditorFeatureProvider fp, PictogramElement source, PictogramElement target, JavaPersistentType embeddingEntity) {
JavaPersistentType owner = (JavaPersistentType)(getBusinessObjectForPictogramElement(source));
JavaPersistentType inverse = (JavaPersistentType)(getBusinessObjectForPictogramElement(target));
@@ -43,14 +48,32 @@ public class CreateManyToOneUniDirRelationFeature extends CreateManyToOneRelatio
if (JpaArtifactFactory.instance().isMethodAnnotated(owner))
nameWithNonCapitalLetter = JPAEditorUtil.produceValidAttributeName(attributeName);
String attributeText = JPAEditorUtil.produceUniqueAttributeName(owner, nameWithNonCapitalLetter);
- ManyToOneUniDirRelation relation = new ManyToOneUniDirRelation(fp, owner, inverse, attributeText, true,
- getFeatureProvider().getCompilationUnit(owner),
- getFeatureProvider().getCompilationUnit(inverse));
+ ManyToOneUniDirRelation relation = new ManyToOneUniDirRelation(fp, owner, inverse, attributeText, true);
return relation;
}
public String getCreateImageId() {
return JPAEditorImageProvider.ICON_MANY_TO_ONE_1_DIR;
+ }
+
+ @Override
+ protected boolean isRelationshipPossible() {
+ if(JpaArtifactFactory.instance().hasEmbeddableAnnotation(owner)) {
+ Set<HasReferanceRelation> refs = JpaArtifactFactory.instance().findAllHasReferenceRelsByEmbeddableWithEntity(owner, getFeatureProvider());
+ if (refs.isEmpty()){
+ return false;
+ } else {
+ for (HasReferanceRelation ref : refs) {
+ HashSet<String> annotations = JpaArtifactFactory.instance().getAnnotationNames(ref.getEmbeddedAnnotatedAttribute());
+ for (String annotationName : annotations) {
+ if (annotationName.equals(JPAEditorConstants.ANNOTATION_EMBEDDED_ID)) {
+ return false;
+ }
+ }
+ }
+ }
+ }
+ return true;
}
} \ No newline at end of file
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateMappedSuperclassFeature.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateMappedSuperclassFeature.java
index 93d2e7c..1e07482 100644
--- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateMappedSuperclassFeature.java
+++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateMappedSuperclassFeature.java
@@ -73,10 +73,10 @@ public class CreateMappedSuperclassFeature extends
String mappedSuperclassName = getFeatureProvider()
.getJPAEditorUtil()
- .generateUniqueMappedSuperclassName(
+ .generateUniqueTypeName(
jpaProject,
JPADiagramPropertyPage.getDefaultPackage(jpaProject.getProject()),
- getFeatureProvider());
+ ".MpdSuprcls", getFeatureProvider()); //$NON-NLS-1$
if (! JpaPreferences.getDiscoverAnnotatedClasses(jpaProject.getProject())) {
JPAEditorUtil.createRegisterEntityInXMLJob(jpaProject, mappedSuperclassName);
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateOneToManyRelationFeature.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateOneToManyRelationFeature.java
index c3ec2d1..bf531a0 100644
--- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateOneToManyRelationFeature.java
+++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateOneToManyRelationFeature.java
@@ -15,7 +15,13 @@
*******************************************************************************/
package org.eclipse.jpt.jpadiagrameditor.ui.internal.feature;
+import java.util.HashSet;
+import java.util.Set;
+
import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.IJPAEditorFeatureProvider;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.HasReferanceRelation;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JPAEditorConstants;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JpaArtifactFactory;
abstract class CreateOneToManyRelationFeature
extends CreateRelationFeature {
@@ -24,4 +30,27 @@ abstract class CreateOneToManyRelationFeature
super(fp, name, description);
}
+ /* (non-Javadoc)
+ * @see org.eclipse.jpt.jpadiagrameditor.ui.internal.feature.CreateRelationFeature#isRelationshipPossible()
+ */
+ @Override
+ protected boolean isRelationshipPossible() {
+ if(JpaArtifactFactory.instance().hasEmbeddableAnnotation(owner)) {
+ Set<HasReferanceRelation> refs = JpaArtifactFactory.instance().findAllHasReferenceRelsByEmbeddableWithEntity(owner, getFeatureProvider());
+ if(refs.isEmpty()){
+ return false;
+ } else {
+ for (HasReferanceRelation ref : refs) {
+ HashSet<String> annotations = JpaArtifactFactory.instance().getAnnotationNames(ref.getEmbeddedAnnotatedAttribute());
+ for (String annotationName : annotations) {
+ if (annotationName.equals(JPAEditorConstants.ANNOTATION_ELEMENT_COLLECTION) || annotationName.equals(JPAEditorConstants.ANNOTATION_EMBEDDED_ID)) {
+ return false;
+ }
+ }
+ }
+ }
+ }
+ return true;
+ }
+
}
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateOneToManyUniDirRelationFeature.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateOneToManyUniDirRelationFeature.java
index 574c0b7..322653c 100644
--- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateOneToManyUniDirRelationFeature.java
+++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateOneToManyUniDirRelationFeature.java
@@ -35,7 +35,7 @@ public class CreateOneToManyUniDirRelationFeature extends CreateOneToManyRelatio
@Override
public OneToManyUniDirRelation createRelation(IJPAEditorFeatureProvider fp, PictogramElement source,
- PictogramElement target) {
+ PictogramElement target, JavaPersistentType embeddingEntity) {
JavaPersistentType owner = (JavaPersistentType)(getBusinessObjectForPictogramElement(source));
JavaPersistentType inverse = (JavaPersistentType)(getBusinessObjectForPictogramElement(target));
@@ -45,14 +45,12 @@ public class CreateOneToManyUniDirRelationFeature extends CreateOneToManyRelatio
nameWithNonCapitalLetter = JPAEditorUtil.produceValidAttributeName(attributeName);
String attributeText = JPAEditorUtil.produceUniqueAttributeName(owner, nameWithNonCapitalLetter);
- OneToManyUniDirRelation relation = new OneToManyUniDirRelation(fp, owner, inverse, attributeText, true,
- getFeatureProvider().getCompilationUnit(owner),
- getFeatureProvider().getCompilationUnit(inverse));
+ OneToManyUniDirRelation relation = new OneToManyUniDirRelation(fp, owner, inverse, attributeText, true);
return relation;
}
public String getCreateImageId() {
return JPAEditorImageProvider.ICON_ONE_TO_MANY_1_DIR;
- }
+ }
} \ No newline at end of file
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateOneToOneBiDirRelationFeature.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateOneToOneBiDirRelationFeature.java
index d664af2..6fb57c2 100644
--- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateOneToOneBiDirRelationFeature.java
+++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateOneToOneBiDirRelationFeature.java
@@ -15,12 +15,17 @@
*******************************************************************************/
package org.eclipse.jpt.jpadiagrameditor.ui.internal.feature;
+import java.util.HashSet;
+import java.util.Set;
+
import org.eclipse.graphiti.mm.pictograms.PictogramElement;
import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.i18n.JPAEditorMessages;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.IJPAEditorFeatureProvider;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.JPAEditorImageProvider;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.HasReferanceRelation;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.OneToOneBiDirRelation;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JPAEditorConstants;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JPAEditorUtil;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JpaArtifactFactory;
@@ -35,7 +40,7 @@ public class CreateOneToOneBiDirRelationFeature extends CreateOneToOneRelationFe
@Override
public OneToOneBiDirRelation createRelation(IJPAEditorFeatureProvider fp, PictogramElement source,
- PictogramElement target) {
+ PictogramElement target, JavaPersistentType embeddingEntity) {
JavaPersistentType owner = (JavaPersistentType)(getBusinessObjectForPictogramElement(source));
JavaPersistentType inverse = (JavaPersistentType)(getBusinessObjectForPictogramElement(target));
@@ -51,14 +56,34 @@ public class CreateOneToOneBiDirRelationFeature extends CreateOneToOneRelationFe
nameWithNonCapitalLetter2 = JPAEditorUtil.produceValidAttributeName(inverseAttributeName);
String inverseAttributeText = JPAEditorUtil.produceUniqueAttributeName(inverse, ownerAttributeText, nameWithNonCapitalLetter2);
- OneToOneBiDirRelation rel = new OneToOneBiDirRelation(fp, owner, inverse, ownerAttributeText, inverseAttributeText, true,
- getFeatureProvider().getCompilationUnit(owner),
- getFeatureProvider().getCompilationUnit(inverse));
+ OneToOneBiDirRelation rel = new OneToOneBiDirRelation(fp, owner, inverse, ownerAttributeText, inverseAttributeText, true, embeddingEntity);
return rel;
}
public String getCreateImageId() {
return JPAEditorImageProvider.ICON_ONE_TO_ONE_2_DIR;
- }
-
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jpt.jpadiagrameditor.ui.internal.feature.CreateRelationFeature#isRelationshipPossible()
+ */
+ @Override
+ protected boolean isRelationshipPossible() {
+ if(JpaArtifactFactory.instance().hasEmbeddableAnnotation(owner)) {
+ Set<HasReferanceRelation> refs = JpaArtifactFactory.instance().findAllHasReferenceRelsByEmbeddableWithEntity(owner, getFeatureProvider());
+ if (refs.size() != 1){
+ return false;
+ } else {
+ for (HasReferanceRelation ref : refs) {
+ HashSet<String> annotations = JpaArtifactFactory.instance().getAnnotationNames(ref.getEmbeddedAnnotatedAttribute());
+ for (String annotationName : annotations) {
+ if (annotationName.equals(JPAEditorConstants.ANNOTATION_EMBEDDED_ID)) {
+ return false;
+ }
+ }
+ }
+ }
+ }
+ return true;
+ }
} \ No newline at end of file
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateOneToOneUniDirRelationFeature.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateOneToOneUniDirRelationFeature.java
index 5c1d766..1e556db 100644
--- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateOneToOneUniDirRelationFeature.java
+++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateOneToOneUniDirRelationFeature.java
@@ -15,12 +15,17 @@
*******************************************************************************/
package org.eclipse.jpt.jpadiagrameditor.ui.internal.feature;
+import java.util.HashSet;
+import java.util.Set;
+
import org.eclipse.graphiti.mm.pictograms.PictogramElement;
import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.i18n.JPAEditorMessages;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.IJPAEditorFeatureProvider;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.JPAEditorImageProvider;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.HasReferanceRelation;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.OneToOneUniDirRelation;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JPAEditorConstants;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JPAEditorUtil;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JpaArtifactFactory;
@@ -35,7 +40,7 @@ public class CreateOneToOneUniDirRelationFeature extends CreateOneToOneRelationF
@Override
public OneToOneUniDirRelation createRelation(IJPAEditorFeatureProvider fp, PictogramElement source,
- PictogramElement target) {
+ PictogramElement target, JavaPersistentType embeddingEntity) {
JavaPersistentType owner = (JavaPersistentType)(getBusinessObjectForPictogramElement(source));
JavaPersistentType inverse = (JavaPersistentType)(getBusinessObjectForPictogramElement(target));
@@ -45,14 +50,34 @@ public class CreateOneToOneUniDirRelationFeature extends CreateOneToOneRelationF
if (JpaArtifactFactory.instance().isMethodAnnotated(owner))
nameWithNonCapitalLetter = JPAEditorUtil.produceValidAttributeName(name);
String attribTxt = JPAEditorUtil.produceUniqueAttributeName(owner, nameWithNonCapitalLetter);
- OneToOneUniDirRelation res = new OneToOneUniDirRelation(fp, owner, inverse, attribTxt, true,
- getFeatureProvider().getCompilationUnit(owner),
- getFeatureProvider().getCompilationUnit(inverse));
+ OneToOneUniDirRelation res = new OneToOneUniDirRelation(fp, owner, inverse, attribTxt, true);
return res;
}
public String getCreateImageId() {
return JPAEditorImageProvider.ICON_ONE_TO_ONE_1_DIR;
- }
-
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jpt.jpadiagrameditor.ui.internal.feature.CreateRelationFeature#isRelationshipPossible()
+ */
+ @Override
+ protected boolean isRelationshipPossible() {
+ if(JpaArtifactFactory.instance().hasEmbeddableAnnotation(owner)) {
+ Set<HasReferanceRelation> refs = JpaArtifactFactory.instance().findAllHasReferenceRelsByEmbeddableWithEntity(owner, getFeatureProvider());
+ if (refs.isEmpty()){
+ return false;
+ } else {
+ for (HasReferanceRelation ref : refs) {
+ HashSet<String> annotations = JpaArtifactFactory.instance().getAnnotationNames(ref.getEmbeddedAnnotatedAttribute());
+ for (String annotationName : annotations) {
+ if (annotationName.equals(JPAEditorConstants.ANNOTATION_EMBEDDED_ID)) {
+ return false;
+ }
+ }
+ }
+ }
+ }
+ return true;
+ }
} \ No newline at end of file
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateRelationFeature.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateRelationFeature.java
index 3414293..6149fa8 100644
--- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateRelationFeature.java
+++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateRelationFeature.java
@@ -15,32 +15,51 @@
*******************************************************************************/
package org.eclipse.jpt.jpadiagrameditor.ui.internal.feature;
+import java.util.Set;
+
import org.eclipse.graphiti.features.context.ICreateConnectionContext;
import org.eclipse.graphiti.features.context.impl.AddConnectionContext;
import org.eclipse.graphiti.features.impl.AbstractCreateConnectionFeature;
import org.eclipse.graphiti.mm.pictograms.Anchor;
import org.eclipse.graphiti.mm.pictograms.Connection;
+import org.eclipse.graphiti.mm.pictograms.Diagram;
import org.eclipse.graphiti.mm.pictograms.PictogramElement;
+import org.eclipse.jpt.jpa.core.JpaProject;
+import org.eclipse.jpt.jpa.core.context.Embeddable;
+import org.eclipse.jpt.jpa.core.context.MappedSuperclass;
import org.eclipse.jpt.jpa.core.context.PersistentType;
import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType;
+import org.eclipse.jpt.jpa.core.context.persistence.ClassRef;
+import org.eclipse.jpt.jpa.core.context.persistence.PersistenceUnit;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.modelintegration.util.ModelIntegrationUtil;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.IJPAEditorFeatureProvider;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.AbstractRelation;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.HasReferanceRelation;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JPAEditorUtil;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JpaArtifactFactory;
abstract public class CreateRelationFeature extends AbstractCreateConnectionFeature {
+
+ protected JavaPersistentType owner;
public CreateRelationFeature(IJPAEditorFeatureProvider fp, String name, String description) {
super(fp, name, description);
}
public boolean canCreate(ICreateConnectionContext context) {
- JavaPersistentType owner = (JavaPersistentType)getPersistentType(context.getSourceAnchor());
+ owner = (JavaPersistentType)getPersistentType(context.getSourceAnchor());
JavaPersistentType inverse = (JavaPersistentType)getPersistentType(context.getTargetAnchor());
if ((owner == null) || (inverse == null))
return false;
- if (JpaArtifactFactory.instance().hasMappedSuperclassAnnotation(inverse))
+ if (JpaArtifactFactory.instance().hasMappedSuperclassAnnotation(inverse)
+ || JpaArtifactFactory.instance().hasEmbeddableAnnotation(inverse))
return false;
+ if(JpaArtifactFactory.instance().hasEmbeddableAnnotation(owner)) {
+ if(!isRelationshipPossible() || isParentEntity(inverse)
+ || JPAEditorUtil.checkJPAFacetVersion(owner.getJpaProject(), JPAEditorUtil.JPA_PROJECT_FACET_10))
+ return false;
+ }
if ((this instanceof ICreateBiDirRelationFeature) &&
(JpaArtifactFactory.instance().hasMappedSuperclassAnnotation(owner)))
return false;
@@ -48,31 +67,55 @@ abstract public class CreateRelationFeature extends AbstractCreateConnectionFeat
}
public boolean canStartConnection(ICreateConnectionContext context) {
- JavaPersistentType owner = (JavaPersistentType)getPersistentType(context.getSourceAnchor());
+ owner = (JavaPersistentType)getPersistentType(context.getSourceAnchor());
if (owner == null)
return false;
- if ((this instanceof ICreateBiDirRelationFeature) &&
- JpaArtifactFactory.instance().hasMappedSuperclassAnnotation(owner))
- return false;
return true;
}
public Connection create(ICreateConnectionContext context) {
Connection newConnection = null;
- PersistentType owner = getPersistentType(context.getSourceAnchor());
- PersistentType inverse = getPersistentType(context.getTargetAnchor());
+ JavaPersistentType owner = (JavaPersistentType) getPersistentType(context.getSourceAnchor());
+ JavaPersistentType inverse = (JavaPersistentType) getPersistentType(context.getTargetAnchor());
if (owner != null && inverse != null) {
- AbstractRelation rel = createRelation(getFeatureProvider(), context.getSourceAnchor().getParent(),
- context.getTargetAnchor().getParent());
- AddConnectionContext addContext =
- new AddConnectionContext(context.getSourceAnchor(), context
- .getTargetAnchor());
- addContext.setNewObject(rel);
- newConnection =
- (Connection) getFeatureProvider().addIfPossible(addContext);
+
+// List<JavaPersistentType> embeddingEntities = new ArrayList<JavaPersistentType>();
+ if(JpaArtifactFactory.instance().hasEmbeddableAnnotation(owner) && (this instanceof ICreateBiDirRelationFeature)){
+ Set<HasReferanceRelation> refs = JpaArtifactFactory.instance().findAllHasReferenceRelationsByEmbeddable(owner, getFeatureProvider());
+// if(refs.size()>1){
+// SelectEmbeddingEntitiesDialog dlg = new SelectEmbeddingEntitiesDialog(owner, getFeatureProvider());
+// List<JavaPersistentType> selectedJPTs = dlg.selectInverseRelationshipEntities();
+// if(selectedJPTs == null || selectedJPTs.isEmpty()){
+// return null;
+// }
+// embeddingEntities.addAll(selectedJPTs);
+// } else {
+// embeddingEntities.add(refs.iterator().next().getEmbeddingEntity());
+// }
+
+// for(JavaPersistentType embeddingJPT : embeddingEntities) {
+ newConnection = makeRelation(context, refs.iterator().next().getEmbeddingEntity());
+// }
+ } else {
+ newConnection = makeRelation(context, null);
+ }
}
return newConnection;
}
+
+ private Connection makeRelation(ICreateConnectionContext context,
+ JavaPersistentType embeddingJPT) {
+ Connection newConnection;
+ AbstractRelation rel = createRelation(getFeatureProvider(), context.getSourceAnchor().getParent(),
+ context.getTargetAnchor().getParent(), embeddingJPT);
+ AddConnectionContext addContext =
+ new AddConnectionContext(context.getSourceAnchor(), context
+ .getTargetAnchor());
+ addContext.setNewObject(rel);
+ newConnection =
+ (Connection) getFeatureProvider().addIfPossible(addContext);
+ return newConnection;
+ }
/**
* Returns the PersistentType class belonging to the anchor, or null if not available.
@@ -93,10 +136,136 @@ abstract public class CreateRelationFeature extends AbstractCreateConnectionFeat
* Creates a new OneToOneRelation between two PersistentType classes.
*/
abstract protected AbstractRelation createRelation(IJPAEditorFeatureProvider fp, PictogramElement source,
- PictogramElement target);
+ PictogramElement target, JavaPersistentType type);
public IJPAEditorFeatureProvider getFeatureProvider() {
return (IJPAEditorFeatureProvider)super.getFeatureProvider();
}
+
+ /**
+ * If the relationship is between an embeddable class and an entity and if the embeddable has an
+ * element collection to another entity, then the relationships of type one-to-many and
+ * many-to-many must not be allowed (by spec).
+ * @return true, if the relationship is allowed, false otherwise.
+ */
+ abstract protected boolean isRelationshipPossible();
+
+ @Override
+ public void attachedToSource(ICreateConnectionContext context) {
+ super.attachedToSource(context);
+ getFeatureProvider().setOriginalPersistentTypeColor();
+ disableUnvalidRelationTargets();
+ }
+
+ @Override
+ public void endConnecting() {
+ super.endConnecting();
+ getFeatureProvider().setOriginalPersistentTypeColor();
+ }
+
+ @Override
+ public void startConnecting() {
+ super.startConnecting();
+ disableAllEmbeddables();
+ }
+
+ /**
+ * For each unvalid relationship's target, change the color of the respective
+ * java persistent type in gray to simulate disability of the persistent type.
+ */
+ @SuppressWarnings("restriction")
+ private void disableUnvalidRelationTargets(){
+ Diagram d = getDiagram();
+ JpaProject project = ModelIntegrationUtil.getProjectByDiagram(d.getName());
+ PersistenceUnit unit = project.getRootContextNode().getPersistenceXml().
+ getRoot().getPersistenceUnits().iterator().next();
+ if(JpaArtifactFactory.instance().hasEntityAnnotation(owner)){
+ disableAllJPTsThatAreNotEntities(unit);
+ }
+ else if(JpaArtifactFactory.instance().hasMappedSuperclassAnnotation(owner)){
+ if (this instanceof ICreateBiDirRelationFeature){
+ disableAllPersistentTypes(unit);
+ } else {
+ disableAllJPTsThatAreNotEntities(unit);
+ }
+ }
+ else if(JpaArtifactFactory.instance().hasEmbeddableAnnotation(owner)) {
+ if(!isRelationshipPossible() || JPAEditorUtil.checkJPAFacetVersion(owner.getJpaProject(), JPAEditorUtil.JPA_PROJECT_FACET_10)) {
+ disableAllPersistentTypes(unit);
+ } else {
+ disableAllJPTsThatAreNotEntities(unit);
+ }
+ }
+ }
+
+ /**
+ * Disable all {@link MappedSuperclass}es and {@link Embeddable}s
+ * registered in the persistence unit.
+ * @param unit
+ */
+ private void disableAllJPTsThatAreNotEntities(PersistenceUnit unit) {
+ for (ClassRef classRef : unit.getClassRefs()) {
+ if (classRef.getJavaPersistentType() != null) {
+ final JavaPersistentType jpt = classRef.getJavaPersistentType();
+ if(JpaArtifactFactory.instance().hasEmbeddableAnnotation(jpt) || JpaArtifactFactory.instance().hasMappedSuperclassAnnotation(jpt) || isParentEntity(jpt)){
+ getFeatureProvider().setGrayColor(jpt);
+ }
+
+ }
+ }
+ }
+ /**
+ * Disable (color in gray) all {@link JavaPersistentType}s registered in the
+ * persistence unit.
+ * @param unit
+ */
+ private void disableAllPersistentTypes(PersistenceUnit unit) {
+ for (ClassRef classRef : unit.getClassRefs()) {
+ if (classRef.getJavaPersistentType() != null) {
+ final JavaPersistentType jpt = classRef.getJavaPersistentType();
+ getFeatureProvider().setGrayColor(jpt);
+ }
+ }
+ }
+
+ /**
+ * Disable all {@link Embeddable}s
+ * registered in the persistence unit.
+ * @param unit
+ */
+ @SuppressWarnings("restriction")
+ private void disableAllEmbeddables() {
+ Diagram d = getDiagram();
+ JpaProject project = ModelIntegrationUtil.getProjectByDiagram(d.getName());
+ PersistenceUnit unit = project.getRootContextNode().getPersistenceXml().
+ getRoot().getPersistenceUnits().iterator().next();
+ boolean isJPA10Project = JPAEditorUtil.checkJPAFacetVersion(ModelIntegrationUtil.getProjectByDiagram(getDiagram().getName()), JPAEditorUtil.JPA_PROJECT_FACET_10);
+ if(!isJPA10Project)
+ return;
+ for (ClassRef classRef : unit.getClassRefs()) {
+ if (classRef.getJavaPersistentType() != null) {
+ final JavaPersistentType jpt = classRef.getJavaPersistentType();
+ if(JpaArtifactFactory.instance().hasEmbeddableAnnotation(jpt)){
+ getFeatureProvider().setGrayColor(jpt);
+ }
+
+ }
+ }
+ }
+
+ private boolean isParentEntity(JavaPersistentType jpt) {
+ if(JpaArtifactFactory.instance().hasEntityAnnotation(jpt)){
+ Set<HasReferanceRelation> refs = JpaArtifactFactory.instance().findAllHasReferenceRelationsByEmbeddable(owner, getFeatureProvider());
+ if(!refs.isEmpty()){
+ for(HasReferanceRelation ref : refs){
+ if(ref.getEmbeddingEntity().equals(jpt)){
+ return true;
+ }
+
+ }
+ }
+ }
+ return false;
+ }
} \ No newline at end of file
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/DeleteJPAEntityFeature.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/DeleteJPAEntityFeature.java
index f188152..c3b3c19 100644
--- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/DeleteJPAEntityFeature.java
+++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/DeleteJPAEntityFeature.java
@@ -80,11 +80,7 @@ public class DeleteJPAEntityFeature extends DefaultDeleteFeature {
}
}
-
- public String getQuestionToUser() {
- return MessageFormat.format(JPAEditorMessages.DeleteJPAEntityFeature_deleteJPAEntityQuestion, entityName, entityClassName);
- }
-
+
public IJPAEditorFeatureProvider getFeatureProvider() {
return (IJPAEditorFeatureProvider)super.getFeatureProvider();
}
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/DeleteRelationFeature.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/DeleteRelationFeature.java
index c6c7813..cac5bcf 100644
--- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/DeleteRelationFeature.java
+++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/DeleteRelationFeature.java
@@ -26,6 +26,7 @@ import org.eclipse.jpt.jpa.core.context.java.JavaPersistentAttribute;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.i18n.JPAEditorMessages;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.IJPAEditorFeatureProvider;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.AbstractRelation;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.HasReferanceRelation;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.IBidirectionalRelation;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.IRelation;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.IUnidirectionalRelation;
@@ -70,13 +71,37 @@ public class DeleteRelationFeature extends DefaultDeleteFeature{
}
preDelete(context);
- AbstractRelation rel = (AbstractRelation)businessObjectForPictogramElement;
+
+ if(businessObjectForPictogramElement instanceof AbstractRelation) {
+ deleteAbstractRelation(businessObjectForPictogramElement);
+ } else if (businessObjectForPictogramElement instanceof HasReferanceRelation){
+ deleteEmbeddedRelation(businessObjectForPictogramElement);
+ }
+
+ postDelete(context);
+ }
+
+ private void deleteEmbeddedRelation(Object businessObjectForPictogramElement) {
+ HasReferanceRelation rel = (HasReferanceRelation)businessObjectForPictogramElement;
+ JavaPersistentAttribute attribute = rel.getEmbeddedAnnotatedAttribute();
+ PictogramElement textShape = getFeatureProvider().getPictogramElementForBusinessObject(attribute);
+ if(textShape == null)
+ return;
+ ClickRemoveAttributeButtonFeature feat = new ClickRemoveAttributeButtonFeature(getFeatureProvider());
+ IDeleteContext delCtx = new DeleteContext(textShape);
+ feat.delete(delCtx, false);
+ }
+
+ private void deleteAbstractRelation(Object businessObjectForPictogramElement) {
+ AbstractRelation rel = (AbstractRelation)businessObjectForPictogramElement;
if (rel instanceof IUnidirectionalRelation) {
IUnidirectionalRelation relation = (IUnidirectionalRelation)rel;
- ClickRemoveAttributeButtonFeature feat = new ClickRemoveAttributeButtonFeature(getFeatureProvider());
JavaPersistentAttribute attribute = relation.getAnnotatedAttribute();
PictogramElement textShape = getFeatureProvider().getPictogramElementForBusinessObject(attribute);
+ if(textShape == null)
+ return;
+ ClickRemoveAttributeButtonFeature feat = new ClickRemoveAttributeButtonFeature(getFeatureProvider());
IDeleteContext delCtx = new DeleteContext(textShape);
feat.delete(delCtx, false);
}
@@ -87,28 +112,36 @@ public class DeleteRelationFeature extends DefaultDeleteFeature{
JavaPersistentAttribute ownerAttribute = relation.getOwnerAnnotatedAttribute();
PictogramElement ownerAttributeTextShape = getFeatureProvider().getPictogramElementForBusinessObject(ownerAttribute);
+ if(ownerAttributeTextShape == null)
+ return;
IDeleteContext deleteOwnerAttributeContext = new DeleteContext(ownerAttributeTextShape);
feat.delete(deleteOwnerAttributeContext, false);
JavaPersistentAttribute inverseAttribute = relation.getInverseAnnotatedAttribute();
PictogramElement inverseAttributeTextShape = getFeatureProvider().getPictogramElementForBusinessObject(inverseAttribute);
+ if(inverseAttributeTextShape == null)
+ return;
IDeleteContext deleteInverseAttributeContext = new DeleteContext(inverseAttributeTextShape);
- feat.delete(deleteInverseAttributeContext, false);
- }
-
- postDelete(context);
- }
+ feat.delete(deleteInverseAttributeContext, false);
+ }
+ }
public void postDelete(IDeleteContext context) {
PictogramElement pe = context.getPictogramElement();
Object businessObjectForPictogramElement = getBusinessObjectForPictogramElement(pe);
- IRelation rel = (IRelation)businessObjectForPictogramElement;
- IWorkbenchSite ws = ((IEditorPart)getDiagramEditor()).getSite();
- ICompilationUnit cu = getFeatureProvider().getCompilationUnit(rel.getOwner());
- ut.organizeImports(cu, ws);
- if (rel instanceof IBidirectionalRelation) {
- cu = getFeatureProvider().getCompilationUnit(rel.getInverse());
- ut.organizeImports(cu, ws);
+ IWorkbenchSite ws = ((IEditorPart) getDiagramEditor()).getSite();
+ if (businessObjectForPictogramElement instanceof IRelation) {
+ IRelation rel = (IRelation) businessObjectForPictogramElement;
+ ICompilationUnit cu = getFeatureProvider().getCompilationUnit(rel.getOwner());
+ ut.organizeImports(cu, ws);
+ if (rel instanceof IBidirectionalRelation) {
+ cu = getFeatureProvider().getCompilationUnit(rel.getInverse());
+ ut.organizeImports(cu, ws);
+ }
+ } else if(businessObjectForPictogramElement instanceof HasReferanceRelation){
+ HasReferanceRelation rel = (HasReferanceRelation) businessObjectForPictogramElement;
+ ICompilationUnit cu = getFeatureProvider().getCompilationUnit(rel.getEmbeddingEntity());
+ ut.organizeImports(cu, ws);
}
}
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/DirectEditAttributeFeature.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/DirectEditAttributeFeature.java
index 63d7ef3..e00a6a7 100644
--- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/DirectEditAttributeFeature.java
+++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/DirectEditAttributeFeature.java
@@ -111,7 +111,7 @@ public class DirectEditAttributeFeature extends AbstractDirectEditingFeature {
if (oldAt.getName().equals(value))
return;
try {
- JpaArtifactFactory.instance().renameAttribute(oldAt, value, inverseJPTName, getFeatureProvider());
+ JpaArtifactFactory.instance().renameAttribute((JavaPersistentType)oldAt.getParent(), oldAt.getName(), value, inverseJPTName, getFeatureProvider());
} catch (InterruptedException e) {
return;
}
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/DirectEditJPAEntityFeature.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/DirectEditJPAEntityFeature.java
index cd6e455..636e087 100644
--- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/DirectEditJPAEntityFeature.java
+++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/DirectEditJPAEntityFeature.java
@@ -116,7 +116,9 @@ public class DirectEditJPAEntityFeature extends AbstractDirectEditingFeature {
JpaArtifactFactory.instance().renameEntity(jpt, value);
// Properties props = JPADiagramPropertyPage.loadProperties(jpt.getJpaProject().getProject());
- if (JPADiagramPropertyPage.doesDirecteEditingAffectClassNameByDefault(jpt.getJpaProject().getProject(), props)) {
+ if ((JpaArtifactFactory.instance().hasEntityAnnotation(jpt) && JPADiagramPropertyPage.doesDirecteEditingAffectClassNameByDefault(jpt.getJpaProject().getProject(), props))
+ || JpaArtifactFactory.instance().hasMappedSuperclassAnnotation(jpt)
+ || JpaArtifactFactory.instance().hasEmbeddableAnnotation(jpt)) {
RenameEntityWithoutUIFeature ft = new RenameEntityWithoutUIFeature(getFeatureProvider(), value);
ft.execute(jpt);
return;
@@ -142,7 +144,7 @@ public class DirectEditJPAEntityFeature extends AbstractDirectEditingFeature {
if (JpaArtifactFactory.instance().isMethodAnnotated(at))
newAtName = JPAEditorUtil.produceValidAttributeName(newAtName);
try {
- newAtName = JpaArtifactFactory.instance().renameAttribute(at, newAtName, jpt.getName(), getFeatureProvider()).getName();
+ newAtName = JpaArtifactFactory.instance().renameAttribute(jpt, at.getName(), newAtName, jpt.getName(), getFeatureProvider()).getName();
} catch (InterruptedException e) {
JPADiagramEditorPlugin.logError(e);
}
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/EmbedCollectionOfObjectsFeature.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/EmbedCollectionOfObjectsFeature.java
new file mode 100644
index 0000000..90368bf
--- /dev/null
+++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/EmbedCollectionOfObjectsFeature.java
@@ -0,0 +1,252 @@
+package org.eclipse.jpt.jpadiagrameditor.ui.internal.feature;
+
+import java.util.Set;
+
+import org.eclipse.graphiti.features.IFeatureProvider;
+import org.eclipse.graphiti.features.context.ICreateConnectionContext;
+import org.eclipse.graphiti.features.context.impl.AddConnectionContext;
+import org.eclipse.graphiti.features.impl.AbstractCreateConnectionFeature;
+import org.eclipse.graphiti.mm.pictograms.Anchor;
+import org.eclipse.graphiti.mm.pictograms.Connection;
+import org.eclipse.graphiti.mm.pictograms.Diagram;
+import org.eclipse.jpt.jpa.core.JpaProject;
+import org.eclipse.jpt.jpa.core.context.Embeddable;
+import org.eclipse.jpt.jpa.core.context.Entity;
+import org.eclipse.jpt.jpa.core.context.MappedSuperclass;
+import org.eclipse.jpt.jpa.core.context.PersistentType;
+import org.eclipse.jpt.jpa.core.context.java.JavaPersistentAttribute;
+import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType;
+import org.eclipse.jpt.jpa.core.context.persistence.ClassRef;
+import org.eclipse.jpt.jpa.core.context.persistence.PersistenceUnit;
+import org.eclipse.jpt.jpa.core.jpa2.MappingKeys2_0;
+import org.eclipse.jpt.jpa.core.jpa2.resource.java.ElementCollection2_0Annotation;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.i18n.JPAEditorMessages;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.modelintegration.util.ModelIntegrationUtil;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.propertypage.JPADiagramPropertyPage;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.IJPAEditorFeatureProvider;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.JPAEditorImageProvider;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.HasCollectionReferenceRelation;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.HasReferanceRelation;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.HasReferanceRelation.HasReferenceType;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JPAEditorUtil;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JpaArtifactFactory;
+
+public class EmbedCollectionOfObjectsFeature extends AbstractCreateConnectionFeature {
+
+ private JavaPersistentType embeddingEntity;
+
+ public EmbedCollectionOfObjectsFeature(IFeatureProvider fp) {
+ this(fp, JPAEditorMessages.EmbedCollectionOfObjectsFeature_ElementCollectionFeatureName, JPAEditorMessages.EmbedCollectionOfObjectsFeature_ElementCollectionFeatureDescription);
+ }
+
+ public EmbedCollectionOfObjectsFeature(IFeatureProvider fp, String name,
+ String description) {
+ super(fp, name, description);
+ }
+
+ public boolean canCreate(ICreateConnectionContext context) {
+ JavaPersistentType embeddingEntity = (JavaPersistentType)getPersistentType(context.getSourceAnchor());
+ JavaPersistentType embeddable = (JavaPersistentType)getPersistentType(context.getTargetAnchor());
+ if ((embeddable == null) || (embeddingEntity == null))
+ return false;
+
+ if (!JpaArtifactFactory.instance().hasEmbeddableAnnotation(embeddable))
+ return false;
+
+ if(!JpaArtifactFactory.instance().hasEntityAnnotation(embeddingEntity) &&
+ !JpaArtifactFactory.instance().hasEmbeddableAnnotation(embeddingEntity))
+ return false;
+ if(isNotAllowed(embeddingEntity, embeddable)){
+ return false;
+ }
+ return true;
+ }
+
+ public Connection create(ICreateConnectionContext context) {
+ JavaPersistentType embeddingEntity = (JavaPersistentType)getPersistentType(context.getSourceAnchor());
+ JavaPersistentType embeddable = (JavaPersistentType)getPersistentType(context.getTargetAnchor());
+
+ boolean isMap = JPADiagramPropertyPage.isMapType(embeddingEntity.getJpaProject().getProject());
+ String mapKeyType = null;
+ if(isMap){
+ mapKeyType = "java.lang.String"; //$NON-NLS-1$
+ }
+
+ JavaPersistentAttribute embeddedAttribute = JPAEditorUtil.addAnnotatedAttribute(getFeatureProvider(), embeddingEntity, embeddable, true, mapKeyType);
+ embeddedAttribute.setMappingKey(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY);
+ embeddedAttribute.getResourceAttribute().addAnnotation(ElementCollection2_0Annotation.ANNOTATION_NAME);
+
+ HasReferanceRelation rel = new HasCollectionReferenceRelation(embeddingEntity, embeddable);
+ rel.setEmbeddedAnnotatedAttribute(embeddedAttribute);
+
+ AddHasReferenceRelationFeature ft = new AddHasReferenceRelationFeature(getFeatureProvider());
+
+ AddConnectionContext cont = new AddConnectionContext(context.getSourceAnchor(), context.getTargetAnchor());
+ cont.setNewObject(rel);
+
+ Connection connection = (Connection) ft.add(cont);
+
+ return connection;
+ }
+
+ public boolean canStartConnection(ICreateConnectionContext context) {
+ embeddingEntity = (JavaPersistentType)getPersistentType(context.getSourceAnchor());
+ if (embeddingEntity == null)
+ return false;
+ return true;
+ }
+
+ public String getCreateImageId() {
+ return JPAEditorImageProvider.ICON_ELEMENT_COLLECTION;
+ }
+
+ protected PersistentType getPersistentType(Anchor anchor) {
+ if (anchor != null) {
+ Object refObject =
+ getBusinessObjectForPictogramElement(anchor.getParent());
+ if (refObject instanceof PersistentType) {
+ return (PersistentType) refObject;
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Checks whether the given embeddable is already embedded as element collection in entity
+ * or it embed in itself an element collection of another embeddable.
+ * @param jpt - the given emebeddable
+ * @param isEmbedded - true if the embed connection is doing between entity and embeddable, false if the connection
+ * is trying to be done between two embeddables.
+ * @return true if the given emebddable is embedded as element collection in an entity or it embed in itself
+ * an element collection of another embeddable.
+ */
+ private boolean isEmbeddableAlreadyEmbeddedAsElementCollection(JavaPersistentType jpt, boolean isEmbedded){
+ Set<HasReferanceRelation> refs = JpaArtifactFactory.instance().findAllHasReferenceRelationsByEmbeddable(jpt, getFeatureProvider());
+ if(!refs.isEmpty()){
+ for(HasReferanceRelation ref : refs){
+ if(ref.getReferenceType().equals(HasReferenceType.COLLECTION)){
+ if(!isEmbedded && ref.getEmbeddable().equals(jpt)){
+ return true;
+ } else if(isEmbedded && ref.getEmbeddingEntity().equals(jpt)){
+ return true;
+ }
+ }
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Checks whether the connection is possible. If the source of the connection is embeddable and it already
+ * embeds in itself an element collection of another embeddable, or if the target of the connection is already
+ * embedded as an element connection in some entity, then the connection is not allowed by specification.
+ * @param embeddingEntity - the source entity of the connection
+ * @param embeddable - the target entity of the connection
+ * @return true if the connection is possible, false otherwise.
+ */
+ private boolean isNotAllowed(JavaPersistentType embeddingEntity, JavaPersistentType embeddable){
+ boolean notAllowed = false;
+ if(JpaArtifactFactory.instance().hasEmbeddableAnnotation(embeddingEntity)){
+ notAllowed = isEmbeddableAlreadyEmbeddedAsElementCollection(embeddingEntity, false);
+ } else if(JpaArtifactFactory.instance().hasEntityAnnotation(embeddingEntity)){
+ notAllowed = isEmbeddableAlreadyEmbeddedAsElementCollection(embeddable, true);
+ }
+ return notAllowed;
+ }
+
+ public IJPAEditorFeatureProvider getFeatureProvider() {
+ return (IJPAEditorFeatureProvider)super.getFeatureProvider();
+ }
+
+ @Override
+ public void attachedToSource(ICreateConnectionContext context) {
+ super.attachedToSource(context);
+ getFeatureProvider().setOriginalPersistentTypeColor();
+ disableUnvalidRelationTargets();
+ }
+
+ @Override
+ public void endConnecting() {
+ super.endConnecting();
+ getFeatureProvider().setOriginalPersistentTypeColor();
+ }
+
+ @Override
+ public void startConnecting() {
+ super.startConnecting();
+ disableAllMappedSuperclasses();
+ }
+
+ /**
+ * For each unvalid relationship's target, change the color of the respective
+ * java persistent type in gray to simulate disability of the persistent type.
+ */
+ @SuppressWarnings("restriction")
+ private void disableUnvalidRelationTargets(){
+ Diagram d = getDiagram();
+ JpaProject project = ModelIntegrationUtil.getProjectByDiagram(d.getName());
+ PersistenceUnit unit = project.getRootContextNode().getPersistenceXml().
+ getRoot().getPersistenceUnits().iterator().next();
+ if(JpaArtifactFactory.instance().hasEntityAnnotation(embeddingEntity)
+ || JpaArtifactFactory.instance().hasEmbeddableAnnotation(embeddingEntity)){
+ disableAllNotEmbeddablesOrEmbedAsElementCollection(unit);
+ }
+ else if(JpaArtifactFactory.instance().hasMappedSuperclassAnnotation(embeddingEntity)){
+ disableAllPersistentType(unit);
+ }
+ }
+
+ /**
+ * Disable all {@link MappedSuperclass}es, {@link Entity}s and {@link Embeddable}s, which are part of
+ * element collection connection, registered in the persistence unit.
+ * @param unit
+ */
+ private void disableAllNotEmbeddablesOrEmbedAsElementCollection(PersistenceUnit unit) {
+ for (ClassRef classRef : unit.getClassRefs()) {
+ if (classRef.getJavaPersistentType() != null) {
+ final JavaPersistentType jpt = classRef.getJavaPersistentType();
+ if(JpaArtifactFactory.instance().hasEntityAnnotation(jpt) || JpaArtifactFactory.instance().hasMappedSuperclassAnnotation(jpt)
+ || embeddingEntity.equals(jpt) || isNotAllowed(embeddingEntity, jpt)){
+ getFeatureProvider().setGrayColor(jpt);
+ }
+
+ }
+ }
+ }
+
+ /**
+ * Disable (color in gray) all {@link JavaPersistentType}s registered in the
+ * persistence unit.
+ * @param unit
+ */
+ private void disableAllPersistentType(PersistenceUnit unit) {
+ for (ClassRef classRef : unit.getClassRefs()) {
+ if (classRef.getJavaPersistentType() != null) {
+ final JavaPersistentType jpt = classRef.getJavaPersistentType();
+ getFeatureProvider().setGrayColor(jpt);
+ }
+ }
+ }
+
+ /**
+ * Disable all {@link MappedSuperclass}es
+ * registered in the persistence unit.
+ * @param unit
+ */
+ @SuppressWarnings("restriction")
+ private void disableAllMappedSuperclasses() {
+ Diagram d = getDiagram();
+ JpaProject project = ModelIntegrationUtil.getProjectByDiagram(d.getName());
+ PersistenceUnit unit = project.getRootContextNode().getPersistenceXml().
+ getRoot().getPersistenceUnits().iterator().next();
+ for (ClassRef classRef : unit.getClassRefs()) {
+ if (classRef.getJavaPersistentType() != null) {
+ final JavaPersistentType jpt = classRef.getJavaPersistentType();
+ if(JpaArtifactFactory.instance().hasMappedSuperclassAnnotation(jpt)){
+ getFeatureProvider().setGrayColor(jpt);
+ }
+
+ }
+ }
+ }
+}
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/EmbedSingleObjectFeature.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/EmbedSingleObjectFeature.java
new file mode 100644
index 0000000..72fe587
--- /dev/null
+++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/EmbedSingleObjectFeature.java
@@ -0,0 +1,205 @@
+package org.eclipse.jpt.jpadiagrameditor.ui.internal.feature;
+
+import org.eclipse.graphiti.features.IFeatureProvider;
+import org.eclipse.graphiti.features.context.ICreateConnectionContext;
+import org.eclipse.graphiti.features.context.impl.AddConnectionContext;
+import org.eclipse.graphiti.features.impl.AbstractCreateConnectionFeature;
+import org.eclipse.graphiti.mm.pictograms.Anchor;
+import org.eclipse.graphiti.mm.pictograms.Connection;
+import org.eclipse.graphiti.mm.pictograms.Diagram;
+import org.eclipse.jpt.jpa.core.JpaProject;
+import org.eclipse.jpt.jpa.core.MappingKeys;
+import org.eclipse.jpt.jpa.core.context.Entity;
+import org.eclipse.jpt.jpa.core.context.MappedSuperclass;
+import org.eclipse.jpt.jpa.core.context.PersistentType;
+import org.eclipse.jpt.jpa.core.context.java.JavaPersistentAttribute;
+import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType;
+import org.eclipse.jpt.jpa.core.context.persistence.ClassRef;
+import org.eclipse.jpt.jpa.core.context.persistence.PersistenceUnit;
+import org.eclipse.jpt.jpa.core.resource.java.EmbeddedAnnotation;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.i18n.JPAEditorMessages;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.modelintegration.util.ModelIntegrationUtil;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.IJPAEditorFeatureProvider;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.JPAEditorImageProvider;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.HasReferanceRelation;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.HasSingleReferenceRelation;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JPAEditorUtil;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JpaArtifactFactory;
+
+public class EmbedSingleObjectFeature extends AbstractCreateConnectionFeature {
+
+ private JavaPersistentType embeddingEntity;
+
+ public EmbedSingleObjectFeature(IFeatureProvider fp) {
+ this(fp, JPAEditorMessages.EmbedSingleObjectFeature_EmbeddedFeatureName, JPAEditorMessages.EmbedSingleObjectFeature_EmbeddedFeatureDescription);
+ }
+
+ public EmbedSingleObjectFeature(IFeatureProvider fp, String name,
+ String description) {
+ super(fp, name, description);
+ }
+
+ public boolean canCreate(ICreateConnectionContext context) {
+ embeddingEntity = (JavaPersistentType)getPersistentType(context.getSourceAnchor());
+ JavaPersistentType embeddable = (JavaPersistentType)getPersistentType(context.getTargetAnchor());
+ if ((embeddingEntity == null) || (embeddable == null))
+ return false;
+
+ if (!JpaArtifactFactory.instance().hasEmbeddableAnnotation(embeddable))
+ return false;
+
+ if(JpaArtifactFactory.instance().hasEmbeddableAnnotation(embeddingEntity) &&
+ JPAEditorUtil.checkJPAFacetVersion(embeddable.getJpaProject(), JPAEditorUtil.JPA_PROJECT_FACET_10))
+ return false;
+
+ if(!JpaArtifactFactory.instance().hasEntityAnnotation(embeddingEntity) &&
+ !JpaArtifactFactory.instance().hasEmbeddableAnnotation(embeddingEntity))
+ return false;
+ return true;
+ }
+
+ public Connection create(ICreateConnectionContext context) {
+ JavaPersistentType embeddingEntity = (JavaPersistentType)getPersistentType(context.getSourceAnchor());
+ JavaPersistentType embeddable = (JavaPersistentType)getPersistentType(context.getTargetAnchor());
+
+ JavaPersistentAttribute embeddedAttribute = JPAEditorUtil.addAnnotatedAttribute(getFeatureProvider(), embeddingEntity, embeddable, false, null);
+ embeddedAttribute.setMappingKey(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY);
+ embeddedAttribute.getResourceAttribute().addAnnotation(EmbeddedAnnotation.ANNOTATION_NAME);
+
+ HasReferanceRelation rel = new HasSingleReferenceRelation(embeddingEntity, embeddable);
+ rel.setEmbeddedAnnotatedAttribute(embeddedAttribute);
+
+ AddHasReferenceRelationFeature ft = new AddHasReferenceRelationFeature(getFeatureProvider());
+
+ AddConnectionContext cont = new AddConnectionContext(context.getSourceAnchor(), context.getTargetAnchor());
+ cont.setNewObject(rel);
+
+ Connection connection = (Connection) ft.add(cont);
+
+ return connection;
+ }
+
+ public boolean canStartConnection(ICreateConnectionContext context) {
+ embeddingEntity = (JavaPersistentType)getPersistentType(context.getSourceAnchor());
+
+ if (embeddingEntity == null)
+ return false;
+
+ return true;
+ }
+
+ public String getCreateImageId() {
+ return JPAEditorImageProvider.ICON_EMBEDDED;
+ }
+
+ protected PersistentType getPersistentType(Anchor anchor) {
+ if (anchor != null) {
+ Object refObject =
+ getBusinessObjectForPictogramElement(anchor.getParent());
+ if (refObject instanceof PersistentType) {
+ return (PersistentType) refObject;
+ }
+ }
+ return null;
+ }
+
+ public IJPAEditorFeatureProvider getFeatureProvider() {
+ return (IJPAEditorFeatureProvider)super.getFeatureProvider();
+ }
+
+ @Override
+ public void startConnecting() {
+ super.startConnecting();
+ disableAllMappedSuperclasses();
+ }
+
+ @Override
+ public void attachedToSource(ICreateConnectionContext context) {
+ super.attachedToSource(context);
+ getFeatureProvider().setOriginalPersistentTypeColor();
+ disableUnvalidRelationTargets();
+ }
+
+ @Override
+ public void endConnecting() {
+ super.endConnecting();
+ getFeatureProvider().setOriginalPersistentTypeColor();
+ }
+
+ /**
+ * For each unvalid relationship's target, change the color of the respective
+ * java persistent type in gray to simulate disability of the persistent type.
+ */
+ @SuppressWarnings("restriction")
+ private void disableUnvalidRelationTargets(){
+ Diagram d = getDiagram();
+ JpaProject project = ModelIntegrationUtil.getProjectByDiagram(d.getName());
+ PersistenceUnit unit = project.getRootContextNode().getPersistenceXml().
+ getRoot().getPersistenceUnits().iterator().next();
+ boolean isJPA10Project = JPAEditorUtil.checkJPAFacetVersion(embeddingEntity.getJpaProject(), JPAEditorUtil.JPA_PROJECT_FACET_10);
+ if(JpaArtifactFactory.instance().hasEntityAnnotation(embeddingEntity)
+ || (!isJPA10Project && JpaArtifactFactory.instance().hasEmbeddableAnnotation(embeddingEntity))){
+ disableAllJPTsThatAreNotEmbeddables(unit);
+ }
+ else if(JpaArtifactFactory.instance().hasMappedSuperclassAnnotation(embeddingEntity)
+ || (isJPA10Project && JpaArtifactFactory.instance().hasEmbeddableAnnotation(embeddingEntity))){
+ disableAllPersistenTypes(unit);
+ }
+ }
+
+ /**
+ * Disable all {@link MappedSuperclass}es and {@link Entity}s
+ * registered in the persistence unit.
+ * @param unit
+ */
+ private void disableAllJPTsThatAreNotEmbeddables(PersistenceUnit unit) {
+ for (ClassRef classRef : unit.getClassRefs()) {
+ if (classRef.getJavaPersistentType() != null) {
+ final JavaPersistentType jpt = classRef.getJavaPersistentType();
+ if(JpaArtifactFactory.instance().hasEntityAnnotation(jpt) || JpaArtifactFactory.instance().hasMappedSuperclassAnnotation(jpt)){
+ getFeatureProvider().setGrayColor(jpt);
+ }
+
+ }
+ }
+ }
+
+ /**
+ * Disable all {@link MappedSuperclass}es
+ * registered in the persistence unit.
+ * @param unit
+ */
+ @SuppressWarnings("restriction")
+ private void disableAllMappedSuperclasses() {
+ Diagram d = getDiagram();
+ JpaProject project = ModelIntegrationUtil.getProjectByDiagram(d.getName());
+ PersistenceUnit unit = project.getRootContextNode().getPersistenceXml().
+ getRoot().getPersistenceUnits().iterator().next();
+ boolean isJPA10Project = JPAEditorUtil.checkJPAFacetVersion(ModelIntegrationUtil.getProjectByDiagram(getDiagram().getName()), JPAEditorUtil.JPA_PROJECT_FACET_10);
+ for (ClassRef classRef : unit.getClassRefs()) {
+ if (classRef.getJavaPersistentType() != null) {
+ final JavaPersistentType jpt = classRef.getJavaPersistentType();
+ if(JpaArtifactFactory.instance().hasMappedSuperclassAnnotation(jpt) ||
+ (isJPA10Project && JpaArtifactFactory.instance().hasEmbeddableAnnotation(jpt))){
+ getFeatureProvider().setGrayColor(jpt);
+ }
+
+ }
+ }
+ }
+
+ /**
+ * Disable (color in gray) all {@link JavaPersistentType}s registered in the
+ * persistence unit.
+ * @param unit
+ */
+ private void disableAllPersistenTypes(PersistenceUnit unit) {
+ for (ClassRef classRef : unit.getClassRefs()) {
+ if (classRef.getJavaPersistentType() != null) {
+ final JavaPersistentType jpt = classRef.getJavaPersistentType();
+ getFeatureProvider().setGrayColor(jpt);
+ }
+ }
+ }
+
+} \ No newline at end of file
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/GraphicalRemoveAttributeFeature.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/GraphicalRemoveAttributeFeature.java
index cda70b5..3ebd97c 100644
--- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/GraphicalRemoveAttributeFeature.java
+++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/GraphicalRemoveAttributeFeature.java
@@ -16,8 +16,6 @@
package org.eclipse.jpt.jpadiagrameditor.ui.internal.feature;
import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Iterator;
import java.util.List;
import org.eclipse.emf.transaction.RecordingCommand;
@@ -25,10 +23,8 @@ import org.eclipse.emf.transaction.TransactionalEditingDomain;
import org.eclipse.emf.transaction.util.TransactionUtil;
import org.eclipse.graphiti.features.IFeatureProvider;
import org.eclipse.graphiti.features.context.ICustomContext;
-import org.eclipse.graphiti.features.context.impl.AddConnectionContext;
import org.eclipse.graphiti.features.context.impl.AddContext;
import org.eclipse.graphiti.features.custom.AbstractCustomFeature;
-import org.eclipse.graphiti.mm.pictograms.AnchorContainer;
import org.eclipse.graphiti.mm.pictograms.ContainerShape;
import org.eclipse.graphiti.mm.pictograms.PictogramElement;
import org.eclipse.graphiti.mm.pictograms.Shape;
@@ -36,7 +32,6 @@ import org.eclipse.graphiti.services.Graphiti;
import org.eclipse.jpt.jpa.core.context.java.JavaPersistentAttribute;
import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.IJPAEditorFeatureProvider;
-import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.IRelation;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.GraphicsUpdater;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JPAEditorConstants;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JpaArtifactFactory;
@@ -71,6 +66,7 @@ public class GraphicalRemoveAttributeFeature extends AbstractCustomFeature {
removeCompartmentChildren(relationShape);
removeCompartmentChildren(basicShape);
+
readdCompartmentsChildren((JavaPersistentType) bo, entityShape, primShape, relationShape, basicShape);
layoutPictogramElement(entityShape);
@@ -81,21 +77,8 @@ public class GraphicalRemoveAttributeFeature extends AbstractCustomFeature {
}
public void reconnect(JavaPersistentType jpt) {
- IJPAEditorFeatureProvider fp = getFeatureProvider();
- Collection<IRelation> rels = JpaArtifactFactory.instance().produceAllRelations(jpt, fp);
- Iterator<IRelation> it = rels.iterator();
- while (it.hasNext()) {
- IRelation rel = it.next();
- AddRelationFeature relF = new AddRelationFeature(fp);
- AnchorContainer acSource = (AnchorContainer) fp.getPictogramElementForBusinessObject(rel.getOwner());
- AnchorContainer acTarget = (AnchorContainer) fp.getPictogramElementForBusinessObject(rel.getInverse());
- AddConnectionContext ctx = new AddConnectionContext(acSource.getAnchors().iterator().next(), acTarget
- .getAnchors().iterator().next());
- ctx.setNewObject(rel);
- relF.add(ctx);
- }
+ JpaArtifactFactory.instance().addNewRelations(getFeatureProvider(), jpt);
JpaArtifactFactory.instance().rearrangeIsARelations(getFeatureProvider());
-
}
private void readdCompartmentsChildren(JavaPersistentType javaPersistentType, ContainerShape entityShape,
@@ -113,10 +96,12 @@ public class GraphicalRemoveAttributeFeature extends AbstractCustomFeature {
for (JavaPersistentAttribute attribute : javaPersistentType.getAttributes()) {
addContext.setNewObject(attribute);
graphicalAdd.execute(addContext);
-
getFeatureProvider().renewAttributeJoiningStrategyPropertyListener(attribute);
- getFeatureProvider().addJPTForUpdate(javaPersistentType.getName());
+// getFeatureProvider().addJPTForUpdate(javaPersistentType.getName());
}
+ GraphicsUpdater.updateEntityShape(entityShape);
+ getFeatureProvider().addJPTForUpdate(javaPersistentType.getName());
+
}
private void removeCompartmentChildren(ContainerShape compartmentShape) {
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/MoveEntityShapeFeature.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/MoveEntityShapeFeature.java
index 4d167a7..80d2593 100644
--- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/MoveEntityShapeFeature.java
+++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/MoveEntityShapeFeature.java
@@ -67,6 +67,6 @@ public class MoveEntityShapeFeature extends DefaultMoveShapeFeature {
public IJPAEditorFeatureProvider getFeatureProvider() {
return (IJPAEditorFeatureProvider)super.getFeatureProvider();
- }
+ }
}
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/RefactorEntityFeature.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/RefactorEntityFeature.java
index e13ee43..efdf9ab 100644
--- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/RefactorEntityFeature.java
+++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/RefactorEntityFeature.java
@@ -296,12 +296,13 @@ public abstract class RefactorEntityFeature extends AbstractCustomFeature {
Set<JavaPersistentAttribute> newSelfAts = new HashSet<JavaPersistentAttribute>();
while (iter.hasNext()) {
JavaPersistentAttribute at = iter.next();
- ICompilationUnit cu = getFeatureProvider().getCompilationUnit((JavaPersistentType) at.getParent());
+ JavaPersistentType atParent = (JavaPersistentType) at.getParent();
+ ICompilationUnit cu = getFeatureProvider().getCompilationUnit(atParent);
if (!cu.exists()) {
at = (JavaPersistentAttribute)at.getPersistenceUnit().getPersistentType(newJptName).getAttributeNamed(at.getName());
JavaPersistentAttribute newAt = null;
try {
- newAt = JpaArtifactFactory.instance().renameAttribute(at, JPAEditorUtil.returnSimpleName(newJptName), newJptName, getFeatureProvider());
+ newAt = JpaArtifactFactory.instance().renameAttribute(atParent, at.getName(), JPAEditorUtil.returnSimpleName(newJptName), newJptName, getFeatureProvider());
} catch (InterruptedException e) {
JPADiagramEditorPlugin.logError(e);
}
@@ -309,7 +310,7 @@ public abstract class RefactorEntityFeature extends AbstractCustomFeature {
newSelfAts.add(newAt);
} else {
try {
- JpaArtifactFactory.instance().renameAttribute(at, JPAEditorUtil.returnSimpleName(newJptName), newJptName, getFeatureProvider());
+ JpaArtifactFactory.instance().renameAttribute(atParent, at.getName(), JPAEditorUtil.returnSimpleName(newJptName), newJptName, getFeatureProvider());
} catch (InterruptedException e) {
JPADiagramEditorPlugin.logError(e);
}
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/RemoveAttributeFeature.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/RemoveAttributeFeature.java
index 777d12c..21a9ad6 100644
--- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/RemoveAttributeFeature.java
+++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/RemoveAttributeFeature.java
@@ -15,14 +15,12 @@
*******************************************************************************/
package org.eclipse.jpt.jpadiagrameditor.ui.internal.feature;
-import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import org.eclipse.graphiti.features.IFeatureProvider;
import org.eclipse.graphiti.features.context.IContext;
import org.eclipse.graphiti.features.context.IRemoveContext;
-import org.eclipse.graphiti.features.context.impl.AddConnectionContext;
import org.eclipse.graphiti.features.context.impl.CustomContext;
import org.eclipse.graphiti.features.context.impl.RemoveContext;
import org.eclipse.graphiti.features.custom.ICustomFeature;
@@ -35,8 +33,8 @@ import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.JPADiagramEditorPlugin;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.IJPAEditorFeatureProvider;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.JPAEditorFeatureProvider;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.HasReferanceRelation;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.IRelation;
-import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JPAEditorUtil;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JpaArtifactFactory;
public class RemoveAttributeFeature extends DefaultRemoveFeature {
@@ -105,13 +103,20 @@ public class RemoveAttributeFeature extends DefaultRemoveFeature {
fp.remove(fp.getKeyForBusinessObject(bo));
if (!skipRemoveRelations) {
IRelation rel = fp.getRelationRelatedToAttribute(jpa);
- removeRelation(rel);
+ if(rel != null) {
+ removeRelation(rel);
+ }
+
+ HasReferanceRelation embedRel = fp.getEmbeddedRelationRelatedToAttribute(jpa);
+ if(embedRel != null) {
+ removeRelation(embedRel);
+ }
}
}
ContainerShape entityShape = ((ContainerShape) pe).getContainer().getContainer();
try{
- graphicalRemoveAttribute(entityShape);
+ graphicalRemoveAttribute(entityShape);
} catch (Exception e){
JPADiagramEditorPlugin.logError(e);
}
@@ -123,7 +128,7 @@ public class RemoveAttributeFeature extends DefaultRemoveFeature {
graphicalRemove.execute(customContext);
}
- private void removeRelation(IRelation rel) {
+ private void removeRelation(Object rel) {
if (rel == null)
return;
Connection conn = (Connection) getFeatureProvider().getPictogramElementForBusinessObject(rel);
@@ -137,22 +142,7 @@ public class RemoveAttributeFeature extends DefaultRemoveFeature {
return;
if (jpt == null)
return;
-
- Collection<IRelation> rels = JpaArtifactFactory.instance()
- .produceAllRelations(jpt, getFeatureProvider());
- Iterator<IRelation> iter = rels.iterator();
- while (iter.hasNext()) {
- IRelation rel = iter.next();
- ContainerShape ownerShape = (ContainerShape) getFeatureProvider().getPictogramElementForBusinessObject(
- rel.getOwner());
- ContainerShape inverseShape = (ContainerShape) getFeatureProvider().getPictogramElementForBusinessObject(
- rel.getInverse());
- AddConnectionContext cntx = new AddConnectionContext(JPAEditorUtil.getAnchor(ownerShape), JPAEditorUtil
- .getAnchor(inverseShape));
- cntx.setNewObject(rel);
- AddRelationFeature ft = new AddRelationFeature(getFeatureProvider());
- ft.add(cntx);
- }
+ JpaArtifactFactory.instance().addNewRelations(getFeatureProvider(), jpt);
JpaArtifactFactory.instance().rearrangeIsARelations(getFeatureProvider());
}
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/RemoveRelationFeature.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/RemoveRelationFeature.java
index 6f73e1d..75acf9d 100644
--- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/RemoveRelationFeature.java
+++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/RemoveRelationFeature.java
@@ -36,6 +36,7 @@ import org.eclipse.graphiti.mm.pictograms.Shape;
import org.eclipse.graphiti.services.Graphiti;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.IJPAEditorFeatureProvider;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.AbstractRelation;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.HasReferanceRelation;
@SuppressWarnings("restriction")
@@ -65,7 +66,10 @@ public class RemoveRelationFeature extends AbstractFeature implements IRemoveFea
if (bo instanceof AbstractRelation) {
AbstractRelation rel = (AbstractRelation)bo;
getFeatureProvider().remove(rel.getId());
- }
+ } else if (bo instanceof HasReferanceRelation) {
+ HasReferanceRelation rel = (HasReferanceRelation) bo;
+ getFeatureProvider().remove(rel.getId());
+ }
}
public final void remove(final IRemoveContext context) {
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/UpdateAttributeFeature.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/UpdateAttributeFeature.java
index 3dff02c..da91a89 100644
--- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/UpdateAttributeFeature.java
+++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/UpdateAttributeFeature.java
@@ -15,18 +15,13 @@
*******************************************************************************/
package org.eclipse.jpt.jpadiagrameditor.ui.internal.feature;
-import java.util.Collection;
-import java.util.Iterator;
-
import org.eclipse.graphiti.features.IFeatureProvider;
import org.eclipse.graphiti.features.context.ICustomContext;
-import org.eclipse.graphiti.features.context.impl.AddConnectionContext;
import org.eclipse.graphiti.features.custom.AbstractCustomFeature;
import org.eclipse.graphiti.mm.algorithms.Rectangle;
import org.eclipse.graphiti.mm.algorithms.Text;
import org.eclipse.graphiti.mm.algorithms.styles.Color;
import org.eclipse.graphiti.mm.algorithms.styles.Orientation;
-import org.eclipse.graphiti.mm.pictograms.AnchorContainer;
import org.eclipse.graphiti.mm.pictograms.ContainerShape;
import org.eclipse.graphiti.mm.pictograms.Diagram;
import org.eclipse.graphiti.mm.pictograms.Shape;
@@ -35,7 +30,6 @@ import org.eclipse.graphiti.services.IGaService;
import org.eclipse.graphiti.util.IColorConstant;
import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.IJPAEditorFeatureProvider;
-import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.IRelation;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JPAEditorConstants;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JpaArtifactFactory;
@@ -48,21 +42,7 @@ public class UpdateAttributeFeature extends AbstractCustomFeature {
public void reconnect(JavaPersistentType jpt) {
IJPAEditorFeatureProvider fp = getFeatureProvider();
- Collection<IRelation> rels = JpaArtifactFactory.instance().produceAllRelations(jpt, fp);
-
- Iterator<IRelation> it = rels.iterator();
- while (it.hasNext()) {
- IRelation rel = it.next();
- AddRelationFeature relF = new AddRelationFeature(fp);
- AnchorContainer acSource = (AnchorContainer) fp.getPictogramElementForBusinessObject(rel.getOwner());
- AnchorContainer acTarget = (AnchorContainer) fp.getPictogramElementForBusinessObject(rel.getInverse());
- if ((acSource != null) && (acTarget != null)) {
- AddConnectionContext ctx = new AddConnectionContext(acSource.getAnchors().iterator().next(), acTarget
- .getAnchors().iterator().next());
- ctx.setNewObject(rel);
- relF.add(ctx);
- }
- }
+ JpaArtifactFactory.instance().addNewRelations(fp, jpt);
}
/**
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/i18n/JPAEditorMessages.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/i18n/JPAEditorMessages.java
index 531f29e..c577927 100644
--- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/i18n/JPAEditorMessages.java
+++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/i18n/JPAEditorMessages.java
@@ -36,6 +36,10 @@ public class JPAEditorMessages extends NLS {
public static String CreateDiagramJob_createDiagramJobName;
public static String CreateDiagramJob_getJPADiagramMonitorTaskName;
+ public static String CreateEmbeddableFeature_EmbeddableFeatureDescription;
+
+ public static String CreateEmbeddableFeature_EmbeddableFeatureName;
+
public static String CreateIsARelationFeature_description;
public static String CreateIsARelationFeature_name;
@@ -44,9 +48,7 @@ public class JPAEditorMessages extends NLS {
public static String CreateJPAEntityFeature_createEntityErrorStatusMsg;
public static String CreateJPAEntityFeature_jpaEntityFeatureDescription;
public static String CreateJPAEntityFeature_jpaEntityFeatureName;
- public static String CreateJPAEntityFeature_jpaProjectSelectionDialogDescription;
- public static String CreateJPAEntityFeature_jpaProjectSelectionDialogTitle;
- public static String CreateJPAEntityFromMappedSuperclassFeature_createInheritedEntityFeatureDescription;
+
public static String CreateJPAEntityFromMappedSuperclassFeature_createInheritedEntityFeatureName;
public static String CreateMappedSuperclassFeature_createMappedSuperclassFeatureDescription;
public static String CreateMappedSuperclassFeature_createMappedSuperclassFeatureName;
@@ -143,8 +145,6 @@ public class JPAEditorMessages extends NLS {
public static String JPAEditorToolBehaviorProvider_createAttributeButtonDescription;
public static String JPAEditorToolBehaviorProvider_createAttributeButtonlabel;
- public static String JPAEditorToolBehaviorProvider_customSubMenuDescription;
- public static String JPAEditorToolBehaviorProvider_customSubMenuText;
public static String JPAEditorToolBehaviorProvider_deleteAttributeButtonDescription;
public static String JPAEditorToolBehaviorProvider_deleteAttributeButtonlabel;
public static String JPAEditorToolBehaviorProvider_deleteEntityFromModelButtonDescription;
@@ -173,9 +173,9 @@ public class JPAEditorMessages extends NLS {
public static String JPAEditorToolBehaviorProvider_openJPADetailsView;
public static String JPAEditorToolBehaviorProvider_openJPADetailsViewDesc;
public static String JPAEditorToolBehaviorProvider_openMiniatureView;
- public static String JPAEditorToolBehaviorProvider_openMiniatureViewDesc;
- public static String JPAEditorToolBehaviorProvider_applyPattern;
- public static String JPAEditorToolBehaviorProvider_applyPatternDesc;
+ public static String JPAEditorToolBehaviorProvider_openMiniatureViewDesc;
+
+ public static String JPAEditorToolBehaviorProvider_CompositionPaletteName;
public static String JPAEditorToolBehaviorProvider_expandAttrMenuItem;
public static String JPAEditorToolBehaviorProvider_expandAttrMenuItemDescr;
@@ -247,6 +247,14 @@ public class JPAEditorMessages extends NLS {
public static String MoveEntityFeature_ContextMenuOperationDescription;
+ public static String EmbedCollectionOfObjectsFeature_ElementCollectionFeatureDescription;
+
+ public static String EmbedCollectionOfObjectsFeature_ElementCollectionFeatureName;
+
+ public static String EmbedSingleObjectFeature_EmbeddedFeatureDescription;
+
+ public static String EmbedSingleObjectFeature_EmbeddedFeatureName;
+
public static String EntitiesCoordinatesXML_CannotCloseFileStreamErrorMSG;
public static String EntitiesCoordinatesXML_CannotCreateDOMFileErrorMSG;
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/i18n/messages.properties b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/i18n/messages.properties
index f79f7be..4f1314a 100644
--- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/i18n/messages.properties
+++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/i18n/messages.properties
@@ -16,15 +16,17 @@
AddJPAEntityFeature_basicAttributesShapes=Other Attributes
AddJPAEntityFeature_primaryKeysShape=Primary Key
AddJPAEntityFeature_relationAttributesShapes=Relation Attributes
-ClickAddAttributeButtonFeature_createAttributeButtonDescription=Create a new attribute of this entity.
+ClickAddAttributeButtonFeature_createAttributeButtonDescription=Create a new attribute of this persistent type.
ClickAddAttributeButtonFeature_createAttributeButtonLabel=Create Attribute
-ClickRemoveAttributeButtonFeature_createAttributeButtonDescription=Create a new attribute of this entity.
+ClickRemoveAttributeButtonFeature_createAttributeButtonDescription=Create a new attribute of this persistent type.
ClickRemoveAttributeButtonFeature_createAttributeButtonlabel=Create Attribute
ClickRemoveAttributeButtonFeature_deleteAttributeQuestion=Do you want to delete attribute "{0}"?
CreateDiagramJob_createDiagramJobName=Creating diagram for: {0}...
CreateDiagramJob_getJPADiagramMonitorTaskName=Get JPA Diagram
+CreateEmbeddableFeature_EmbeddableFeatureDescription=Create a new Embeddable object.
+CreateEmbeddableFeature_EmbeddableFeatureName=Embeddable
CreateIsARelationFeature_description=Click on an entity or mapped superclass and then click somewhere in the diagram to create new inherited entity
CreateIsARelationFeature_name=Inherited Entity
@@ -34,9 +36,6 @@ CreateJPAEntityFeature_createEntityErrorMsgTitle=Cannot Create Entity
CreateJPAEntityFeature_createEntityErrorStatusMsg=Persistence API library is not into the project's classpath.
CreateJPAEntityFeature_jpaEntityFeatureDescription=Create a new JPA entity.
CreateJPAEntityFeature_jpaEntityFeatureName=Java Entity
-CreateJPAEntityFeature_jpaProjectSelectionDialogDescription=Select a JPA project to contain the entity.
-CreateJPAEntityFeature_jpaProjectSelectionDialogTitle=Select JPA Project
-CreateJPAEntityFromMappedSuperclassFeature_createInheritedEntityFeatureDescription=Create a new JPA entity that will inherit a new Mapped Superclass.
CreateJPAEntityFromMappedSuperclassFeature_createInheritedEntityFeatureName=Inherited Entity
CreateMappedSuperclassFeature_createMappedSuperclassFeatureDescription=Create a new Mapped Superclass.
CreateMappedSuperclassFeature_createMappedSuperclassFeatureName=Mapped Superclass
@@ -63,8 +62,8 @@ CreateOneToOneUniDirRelationFeature_oneToOneUniDirFeatureDescription=Create new
CreateOneToOneUniDirRelationFeature_oneToOneUniDirFeatureName=One-to-One
DeleteFeature_deleteConfirm=Confirm Delete
-DeleteJPAEntityFeature_deleteJPAEntityQuestion=Do you want to remove the entity "{0}" from the diagram and delete the corresponding Java resource "{1}"?
-DeleteJPAEntityFeature_deleteJPAEntitiesQuestion=Do you want to remove the selected entities from the diagram and delete the corresponding Java resources?
+DeleteJPAEntityFeature_deleteJPAEntityQuestion=Do you want to remove the persistent type "{0}" from the diagram and delete the corresponding Java resource "{1}"?
+DeleteJPAEntityFeature_deleteJPAEntitiesQuestion=Do you want to remove the selected persistent types from the diagram and delete the corresponding Java resources?
DeleteRelationFeature_deleteRelationQuestion=Do you want to remove this relation from the diagram and update the corresponding Java resources?
@@ -74,12 +73,12 @@ DirectEditAttributeFeature_lineBreaksNotAllowedMsg=You cannot use line breaks in
DirectEditAttributeFeature_spacesNotAllowedMsg=You cannot use spaces in attribute names.
DirectEditJPAEntityFeature_bracesNotAllowedMsg=You cannot use braces in entity names.
-DirectEditJPAEntityFeature_classNameMsg=Enter an entity name.
-DirectEditJPAEntityFeature_duplicateEntityName=Entity with name "{0}" already exists.
-DirectEditJPAEntityFeature_lineBreaksNotAllowedMsg=You cannot use line breaks in entity names.
-DirectEditJPAEntityFeature_scpacesNotAllowedMsg=You cannot use spaces in entity names.
-DirectEditJPAEntityFeature_invalidSymbolsMsg="{0}" is not a valid entity name.
-DiscardAndRemoveAllEntitiesFeature_ContextMenuOperationDescription=Remove All Entities From Diagram and Discard Changes
+DirectEditJPAEntityFeature_classNameMsg=Enter a persistent type name.
+DirectEditJPAEntityFeature_duplicateEntityName=Persistent type with name "{0}" already exists.
+DirectEditJPAEntityFeature_lineBreaksNotAllowedMsg=You cannot use line breaks in persistent type names.
+DirectEditJPAEntityFeature_scpacesNotAllowedMsg=You cannot use spaces in persistent type names.
+DirectEditJPAEntityFeature_invalidSymbolsMsg="{0}" is not a valid persistent type name.
+DiscardAndRemoveAllEntitiesFeature_ContextMenuOperationDescription=Remove All Persistent Types From Diagram and Discard Changes
JpaArtifactFactory_CanNotCheckReturnType=Cannot check the return type
@@ -92,7 +91,7 @@ JPADiagramPropertyPage_errSavePropsMsgText=The JPA diagram properties could not
JPAEditorPreferencesPage_pageDescription=Default settings for the JPA diagram editor:
JPAEditorPreferencesPage_DefaultCollectionTypeSectionDescription=Relation attributes, which you generate using the JPA editor,\nare automatically created to be of the specified collection type.
JPAEditorPreferencesPage_DefaultCollectionTypeSectionTittle=Default Collection Type
-JPAEditorPreferencesPage_DefaultPackageMsg=Entities, which you generate using the JPA editor palette,\nare automatically created in the specified package.
+JPAEditorPreferencesPage_DefaultPackageMsg=Persistent types, which you generate using the JPA editor palette,\nare automatically created in the specified package.
JPAEditorPreferencesPage_DefaultTableNamePrefixMsg=Entities, which you have created, using the JPA editor palette, are automatically\nannotated with @Table(name=...), where the name of the table is a result of\nconcatenation of the given prefix and the name of the entity. If you set\na blank prefix, the newly created entities are not annotated with @Table.
JPAEditorPreferencesPage_DefaultTableNameLabel=Default &table name prefix:
JPAEditorPreferencesPage_DefaultPackageToUse=Default &Java package for new entities:
@@ -100,8 +99,8 @@ JPAEditorPreferencesPage_invalidPackage="{0}" is not a valid Java identifier.
JPAEditorPreferencesPage_invalidTableNamePrefix=Table name prefix may contain letters, digits and underscores only, and must not start with a digit.
JPAEditorPreferencesPage_directEditAffectsClass=&Editing the entity name in the diagram affects the class name in the source file
JPAEditorPreferencesPage_directEditAffectsClassTooltip=If this option is checked and the entity name is appointed\nby the @Entity annotation, direct entity name editing will\naffect the annotation and will cause class name refactoring.\nIf this option is unchecked, direct editing will affect the\nannotation only. If the entity name is not appointed by the\n@Entity annotation, direct editing will cause class name\nrefactoring regardless this option is checked or not.
-JPAEditorPreferencesPage_entityAccessTypeButtonGroupTooltip=Entities, which you generate using the JPA editor palette,\nare automatically created with the specified access.
-JPAEditorPreferencesPage_entityAccessTypeButtonGroupLabel=Entity access type
+JPAEditorPreferencesPage_entityAccessTypeButtonGroupTooltip=Persistent types, which you generate using the JPA editor palette,\nare automatically created with the specified access.
+JPAEditorPreferencesPage_entityAccessTypeButtonGroupLabel=Persistent type access type
JPAEditorPreferencesPage_entityFieldBasedAccessButtonLabel=&Field-based
JPAEditorPreferencesPage_entityPropertyBasedAccessButtonLabel=&Property-based
JPAEditorPreferencesPage_defaultFolderControlTooltip=The newly created diagram file(s) will be stored in this folder
@@ -117,62 +116,59 @@ JPAEditorPropertyPage_oneToManyOldStyleTooltip=If this option is checked, the ne
JPAEditorToolBehaviorProvider_collapseAttrGroupMenuItem=Collapse Attributes Group
JPAEditorToolBehaviorProvider_collapseAttrGroupMenuItemDescr=Collapse the attributes group.
JPAEditorToolBehaviorProvider_collapseCompartToolTip=Double click to collapse "{0}" attributes group.
-JPAEditorToolBehaviorProvider_collapseEntityMenuItem=Collapse Entity
-JPAEditorToolBehaviorProvider_collapseEntityMenuItemDescr=Collapse entity.
+JPAEditorToolBehaviorProvider_collapseEntityMenuItem=Collapse Persistent Type
+JPAEditorToolBehaviorProvider_collapseEntityMenuItemDescr=Collapse persistent type.
JPAEditorToolBehaviorProvider_collapseAllEntitiesMenuItem=Collapse All
-JPAEditorToolBehaviorProvider_collapseAllEntitiesMenuItemDescr=Collapse all entities
-JPAEditorToolBehaviorProvider_createAttributeButtonDescription=Create new attribute of this entity.
+JPAEditorToolBehaviorProvider_collapseAllEntitiesMenuItemDescr=Collapse all persistent types
+JPAEditorToolBehaviorProvider_createAttributeButtonDescription=Create new attribute of this persistent type.
JPAEditorToolBehaviorProvider_createAttributeButtonlabel=Create Attribute
-JPAEditorToolBehaviorProvider_customSubMenuDescription=Custom features submenu
-JPAEditorToolBehaviorProvider_customSubMenuText=Custom
JPAEditorToolBehaviorProvider_deleteAttributeButtonDescription=Delete this attribute from the model.
JPAEditorToolBehaviorProvider_deleteAttributeButtonlabel=Delete Attribute
-JPAEditorToolBehaviorProvider_deleteEntityFromModelButtonDescription=Remove this JPA entity from the diagram and delete it from the JPA model.
+JPAEditorToolBehaviorProvider_deleteEntityFromModelButtonDescription=Remove this persistent type from the diagram and delete it from the JPA model.
JPAEditorToolBehaviorProvider_deleteEntityFromModelButtonLabel=Delete
JPAEditorToolBehaviorProvider_discardChangesMenuItem=Discard Changes
-JPAEditorToolBehaviorProvider_discardChangesMenuItemDescr=Discard all changes made to this JPA entity after the last saving.
-JPAEditorToolBehaviorProvider_removeEntityFromDiagramButtonDescription=Discard all changes made to this JPA entity after the last saving and remove it from the diagram.
+JPAEditorToolBehaviorProvider_discardChangesMenuItemDescr=Discard all changes made to this persistent after the last saving.
+JPAEditorToolBehaviorProvider_removeEntityFromDiagramButtonDescription=Discard all changes made to this persistent type after the last saving and remove it from the diagram.
JPAEditorToolBehaviorProvider_removeEntityFromDiagramButtonLabel=Discard Changes and Remove
JPAEditorToolBehaviorProvider_saveButtonText=Save
-JPAEditorToolBehaviorProvider_saveButtonDescription=Save all changes made to this JPA entity.
+JPAEditorToolBehaviorProvider_saveButtonDescription=Save all changes made to this persistent type.
JPAEditorToolBehaviorProvider_saveMenuItem=Save
-JPAEditorToolBehaviorProvider_saveMenuItemDescr=Save all changes made to this JPA entity.
+JPAEditorToolBehaviorProvider_saveMenuItemDescr=Save all changes made to this persistent type.
JPAEditorToolBehaviorProvider_restoreButtonText=Discard Changes
-JPAEditorToolBehaviorProvider_restoreButtonDescription=Discard all changes made to this JPA entity after the last saving.
-JPAEditorToolBehaviorProvider_removeAndSaveButtonText=Save And Remove
-JPAEditorToolBehaviorProvider_removeAndSaveButtonDescription=Save all changes made to this entity and remove it from the diagram.
-JPAEditorToolBehaviorProvider_showAllTheEntities=Show All Entities
-JPAEditorToolBehaviorProvider_showAllTheEntitiesDesc=Show all entities within the project on the diagram.
-JPAEditorToolBehaviorProvider_refactorSubMenu=Refactor Entity Class
+JPAEditorToolBehaviorProvider_restoreButtonDescription=Discard all changes made to this persistent type after the last saving.
+JPAEditorToolBehaviorProvider_removeAndSaveButtonText=Save and Remove
+JPAEditorToolBehaviorProvider_removeAndSaveButtonDescription=Save all changes made to this persistent type and remove it from the diagram.
+JPAEditorToolBehaviorProvider_showAllTheEntities=Show all Persistent Types
+JPAEditorToolBehaviorProvider_showAllTheEntitiesDesc=Show all persistent types within the project on the diagram.
+JPAEditorToolBehaviorProvider_refactorSubMenu=Refactor Persistent Type Class
JPAEditorToolBehaviorProvider_renameEntityClass=Rename...
JPAEditorToolBehaviorProvider_moveEntityClass=Move...
JPAEditorToolBehaviorProvider_openJPADetailsView=Open JPA Details View
JPAEditorToolBehaviorProvider_openJPADetailsViewDesc=Open the JPA Details view to view/modify the details of the selected persistent object.
JPAEditorToolBehaviorProvider_openMiniatureView=Open Miniature View
JPAEditorToolBehaviorProvider_openMiniatureViewDesc=Open the Miniature view to display the diagram in a larger scale.
-JPAEditorToolBehaviorProvider_applyPattern=Apply Template...
-JPAEditorToolBehaviorProvider_applyPatternDesc=Apply Template
+JPAEditorToolBehaviorProvider_CompositionPaletteName=Composition
JPAEditorToolBehaviorProvider_expandAttrMenuItem=Expand Attributes Group
JPAEditorToolBehaviorProvider_expandAttrMenuItemDescr=Expand the attributes group.
JPAEditorToolBehaviorProvider_expandCompartToolTip=Double click to expand "{0}" attributes group.
-JPAEditorToolBehaviorProvider_expandEntityMenuItem=Expand Entity
-JPAEditorToolBehaviorProvider_expandEntitymenuItemDescr=Expand entity.
+JPAEditorToolBehaviorProvider_expandEntityMenuItem=Expand Persistent Type
+JPAEditorToolBehaviorProvider_expandEntitymenuItemDescr=Expand persistent type.
JPAEditorToolBehaviorProvider_expandAllEntitiesMenuItem=Expand All
-JPAEditorToolBehaviorProvider_expandAllEntitiesMenuItemDescr=Expand all entities.
+JPAEditorToolBehaviorProvider_expandAllEntitiesMenuItemDescr=Expand all persistent types.
JPAEditorToolBehaviorProvider_InheritanceCompartmentTitle=Inheritance
JPAEditorToolBehaviorProvider_refactorAttributeType=Refactor Attribute Type...
JPAEditorToolBehaviorProvider_refactorAttributeTypeDesc=Change the type of the selected attribute.
-JPAEditorToolBehaviorProvider_removeAllEntitiesMenu=Remove All Entities From Diagram
+JPAEditorToolBehaviorProvider_removeAllEntitiesMenu=Remove all Persistent Types from Diagram
JPAEditorToolBehaviorProvider_removeAndSaveAllEntitiesAction=...and Save Changes
JPAEditorToolBehaviorProvider_removeAndDiscardAllEntitiesAction=...and Discard Changes
-JPAEditorToolBehaviorProvider_removeAndSaveAllEntitiesConfirmation=Do you want to save the changes and remove all entities from the diagram?
-JPAEditorToolBehaviorProvider_removeAndDiscardAllEntitiesConfirmation=Do you want to discard the changes and remove all entities from the diagram?
+JPAEditorToolBehaviorProvider_removeAndSaveAllEntitiesConfirmation=Do you want to save the changes and remove all persistent types from the diagram?
+JPAEditorToolBehaviorProvider_removeAndDiscardAllEntitiesConfirmation=Do you want to discard the changes and remove all persistent types from the diagram?
JPAEditorDiagramTypeProvider_cantMakeDiagramWritableTitle=Can't Make Diagram Writable
JPAEditorDiagramTypeProvider_cantMakeDiagramWritableMsg=Cannot make the JPA diagram file writable:\n\n{0}
JPAEditorDiagramTypeProvider_JPADiagramReadOnlyTitle=JPA Diagram Read-Only
JPAEditorDiagramTypeProvider_JPADiagramReadOnlyMsg=The JPA diagram file is read-only and cannot be synchronized with the model. In order to open the diagram, the JPA editor must make this file writable.
-JPAEditorDiagramTypeProvider_JPADiagramReadOnlyHasToAddMsg=Cannot show the selected entity in the JPA diagram, because the diagram file is read-only. In order to show the entity, the JPA editor must make this file writable.
+JPAEditorDiagramTypeProvider_JPADiagramReadOnlyHasToAddMsg=Cannot show the selected persistent type in the JPA diagram, because the diagram file is read-only. In order to show the persistent types, the JPA editor must make this file writable.
OpenJpaDiagramActionDelegate_openJPADiagramErrorMsgTitle=Cannot Open Diagram
OpenJpaDiagramActionDelegate_openJPADiagramErrorMsg=Cannot open the JPA diagram editor
@@ -191,6 +187,10 @@ PaletteCompartment_Objects=Entities
BTN_OK=OK
BTN_CANCEL=Cancel
+EmbedCollectionOfObjectsFeature_ElementCollectionFeatureDescription=Embed collection of embeddable into entity or other embeddable.
+EmbedCollectionOfObjectsFeature_ElementCollectionFeatureName=Embed Collection of Elements
+EmbedSingleObjectFeature_EmbeddedFeatureDescription=Embed a single embeddable into entity or other embeddable.
+EmbedSingleObjectFeature_EmbeddedFeatureName=Embed Single Element
EntitiesCoordinatesXML_CannotCloseFileStreamErrorMSG=Cannot close the stream
EntitiesCoordinatesXML_CannotCreateDOMFileErrorMSG=Cannot create DOM file.
EntitiesCoordinatesXML_CannotFindFileErrorMSG=Cannot find file.
@@ -199,7 +199,7 @@ EntitiesCoordinatesXML_CannotParseFileErrorMSG=Cannot parse file.
EntitiesCoordinatesXML_CannotReadFileErrorMSG=Cannot read file.
EntitiesCoordinatesXML_CannotRefrfreshFile=Cannot refresh the diagram xml file.
-SelectTypeDialog_chooseAttributeTypeDialogText=Select a primitive type for the attribute "{0}" of the entity "{1}" or choose the "Browse" button to select a class type.
+SelectTypeDialog_chooseAttributeTypeDialogText=Select a primitive type for the attribute "{0}" of the persistent type "{1}" or choose the "Browse" button to select a class type.
SelectTypeDialog_browseBtnTxt=&Browse...
SelectTypeDialog_browseBtnDesc=Browse to select a class.
SelectTypeDialog_typeLabel=&Type:
@@ -209,15 +209,15 @@ SelectTypeDialog_invalidTypeMsgTitle=Invalid Type
SelectTypeDialog_invalidTypeMsgText="{0}" is not valid java type or primitive.
SelectTypeDialog_emptyTypeErrorText=The new type name must not be empty
-JPASolver_closeWarningMsg=The entity "{0}" is open elsewhere with identical changes. Using this button will not lose those changes. Close the other editor(s), where the entity "{0}" is open and try again!
+JPASolver_closeWarningMsg=The persistent type "{0}" is open elsewhere with identical changes. Using this button will not lose those changes. Close the other editor(s), where the persistent type "{0}" is open and try again!
JPASolver_closeEditors=Close Editors
-MoveEntityFeature_ContextMenuOperationDescription=Move Entity Class
+MoveEntityFeature_ContextMenuOperationDescription=Move Persistent Type Class
RefactorAttributeTypeFeature_ContextMenuOperationDescription=Refactor Attribute Type
ModelIntegrationUtil_CannotSetFileContentErrorMSG=Cannot set file content.
-RemoveJPAEntityFeature_discardWarningMsg=The entity "{0}" is open elsewhere with identical changes. Using this button will remove the entity from the diagram, but will not lose those changes. In order to lose the changes you need first to close the other editor(s), where the entity "{0}" is open and try again!\n\nDo you want to continue with removing anyway?
+RemoveJPAEntityFeature_discardWarningMsg=The persistent type "{0}" is open elsewhere with identical changes. Using this button will remove the persistent type from the diagram, but will not lose those changes. In order to lose the changes you need first to close the other editor(s), where the persistent type "{0}" is open and try again!\n\nDo you want to continue with removing anyway?
-RenameEntityFeature_ContextMenuOperationDescription=Rename Entity Class
+RenameEntityFeature_ContextMenuOperationDescription=Rename Persistent Type Class
-SaveAndRemoveAllEntitiesFeature_ContextMenuOperationDescription=Remove All Entities From Diagram and Save Changes
+SaveAndRemoveAllEntitiesFeature_ContextMenuOperationDescription=Remove all Persistent Types from Diagram and Save Changes
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/modelintegration/ui/JPADiagramEditorInput.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/modelintegration/ui/JPADiagramEditorInput.java
index 82570f0..3631eb4 100644
--- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/modelintegration/ui/JPADiagramEditorInput.java
+++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/modelintegration/ui/JPADiagramEditorInput.java
@@ -124,4 +124,5 @@ public class JPADiagramEditorInput extends DiagramEditorInput
public String getProjectName() {
return projectName;
}
+
}
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/modelintegration/ui/OpenJpaDiagramActionDelegate.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/modelintegration/ui/OpenJpaDiagramActionDelegate.java
index a56301e..3305b5b 100644
--- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/modelintegration/ui/OpenJpaDiagramActionDelegate.java
+++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/modelintegration/ui/OpenJpaDiagramActionDelegate.java
@@ -15,6 +15,7 @@
*******************************************************************************/
package org.eclipse.jpt.jpadiagrameditor.ui.internal.modelintegration.ui;
+import java.io.IOException;
import java.lang.ref.WeakReference;
import java.util.Iterator;
import java.util.Set;
@@ -93,7 +94,7 @@ public class OpenJpaDiagramActionDelegate implements IObjectActionDelegate {
String diagramName = diagram.getName();
JpaProject jpaProject = ModelIntegrationUtil.getProjectByDiagram(diagramName);
- if (!JPAEditorUtil.checkJPAFacetVersion(jpaProject, "1.0") && !ModelIntegrationUtil.isDiagramOpen(diagramName)) { //$NON-NLS-1$
+ if (!JPAEditorUtil.checkJPAFacetVersion(jpaProject, JPAEditorUtil.JPA_PROJECT_FACET_10) && !ModelIntegrationUtil.isDiagramOpen(diagramName)) {
boolean wasEnabled = OptionalMessageDialog.isDialogEnabled(JPAEditorConstants.JPA_SUPPORT_DIALOG_ID);
int btnIndex = OptionalMessageDialog.open(JPAEditorConstants.JPA_SUPPORT_DIALOG_ID,
Display.getDefault().getShells()[0],
@@ -122,7 +123,6 @@ public class OpenJpaDiagramActionDelegate implements IObjectActionDelegate {
}
public void postShutdown( IWorkbench workbench ){
-
}
});
//CSN #1305850 2010
@@ -222,4 +222,4 @@ public class OpenJpaDiagramActionDelegate implements IObjectActionDelegate {
}
-} \ No newline at end of file
+}
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/modelintegration/util/CreateDiagramJob.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/modelintegration/util/CreateDiagramJob.java
index e2ea8f1..0bf985e 100644
--- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/modelintegration/util/CreateDiagramJob.java
+++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/modelintegration/util/CreateDiagramJob.java
@@ -29,18 +29,11 @@ import org.eclipse.jpt.jpadiagrameditor.ui.internal.i18n.JPAEditorMessages;
public class CreateDiagramJob extends Job {
- //private Connection moinConnection = null;
private PersistenceUnit persistenceUnit;
private Diagram diagram;
private int grid;
private boolean snap;
-
- /*
- public Connection getMoinConnection() {
- return moinConnection;
- }
- */
-
+
public Diagram getDiagram() {
return diagram;
}
@@ -53,11 +46,9 @@ public class CreateDiagramJob extends Job {
}
public IStatus run(IProgressMonitor monitor) {
- //IProject project = persistenceUnit.getJpaProject().getProject();
try{
monitor.beginTask(JPAEditorMessages.CreateDiagramJob_getJPADiagramMonitorTaskName, 3);
monitor.worked(1);
- //moinConnection = ConnectionManager.getInstance().createConnection(project);
monitor.worked(1);
diagram = ModelIntegrationUtil.createDiagram(persistenceUnit, grid, snap);
monitor.worked(1);
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/modelintegration/util/ModelIntegrationUtil.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/modelintegration/util/ModelIntegrationUtil.java
index 46d4886..2a60010 100644
--- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/modelintegration/util/ModelIntegrationUtil.java
+++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/modelintegration/util/ModelIntegrationUtil.java
@@ -191,6 +191,7 @@ public class ModelIntegrationUtil {
String pathName = diagramFileName.toString();
URI resourceURI = URI.createFileURI(pathName);
+
final Resource resource = resourceSet.createResource(resourceURI);
if (!resource.isLoaded())
return createNewDiagram(project, defaultTransEditDomain, resourceSet, resource, diagramName, grid, snap);
@@ -365,7 +366,7 @@ public class ModelIntegrationUtil {
return ref.get();
return null;
}
-
+
public static void deleteDiagramXMIFile(final Diagram diagram) {
if(diagram != null && diagram.eResource()!=null){
TransactionalEditingDomain ted = ModelIntegrationUtil.getTransactionalEditingDomain(diagram);
@@ -385,4 +386,4 @@ public class ModelIntegrationUtil {
});
}
}
-} \ No newline at end of file
+}
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/propertypage/JPADiagramPropertyPage.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/propertypage/JPADiagramPropertyPage.java
index 3cdedee..5451faa 100644
--- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/propertypage/JPADiagramPropertyPage.java
+++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/propertypage/JPADiagramPropertyPage.java
@@ -93,7 +93,7 @@ public class JPADiagramPropertyPage extends PropertyPage {
protected Control createContents(Composite parent) {
final Composite composite = createCompositeContainer(parent);
project = (IProject)getElement().getAdapter(IProject.class);
- isJPA10Project = JPAEditorUtil.checkJPAFacetVersion(project, "1.0"); //$NON-NLS-1$;
+ isJPA10Project = JPAEditorUtil.checkJPAFacetVersion(project, JPAEditorUtil.JPA_PROJECT_FACET_10);
loadProperties();
createDefaultFolderControl(composite);
createDefaultPackageControl(composite);
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/provider/IJPAEditorFeatureProvider.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/provider/IJPAEditorFeatureProvider.java
index 8c37d93..c12e148 100644
--- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/provider/IJPAEditorFeatureProvider.java
+++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/provider/IJPAEditorFeatureProvider.java
@@ -33,6 +33,8 @@ import org.eclipse.jpt.jpa.core.context.java.JavaPersistentAttribute;
import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType;
import org.eclipse.jpt.jpa.core.context.persistence.PersistenceUnit;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.modelintegration.util.IModelIntegrationUtil;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.HasReferanceRelation;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.HasReferanceRelation.HasReferenceType;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.IRelation;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.IRelation.RelDir;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.IRelation.RelType;
@@ -45,11 +47,11 @@ import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.IPeServiceUtil;
public interface IJPAEditorFeatureProvider extends IFeatureProvider{
public Diagram getDiagram();
-
- public HashSet<IsARelation> getAllRedundantIsARelations();
-
+
public HashSet<IsARelation> getAllExistingIsARelations();
-
+
+ public HashSet<HasReferanceRelation> getAllExistingHasReferenceRelations();
+
public ICompilationUnit getCompilationUnit(JavaPersistentType jpt);
public boolean hasObjectWithName(String name);
@@ -62,8 +64,8 @@ public interface IJPAEditorFeatureProvider extends IFeatureProvider{
public IRelation getRelationRelatedToAttribute(JavaPersistentAttribute jpa);
- public boolean existsRelation(JavaPersistentType jpt1, JavaPersistentType jpt2);
-
+ public HasReferanceRelation getEmbeddedRelationRelatedToAttribute(JavaPersistentAttribute jpa);
+
public Object getBusinessObjectForKey(String key);
public void addJPTForUpdate(String jptName);
@@ -71,9 +73,12 @@ public interface IJPAEditorFeatureProvider extends IFeatureProvider{
public boolean doesRelationExist(JavaPersistentType owner,
JavaPersistentType inverse,
String ownerAttributeName,
+ String inverseAttributeName,
RelType relType,
RelDir relDir);
+ public boolean doesEmbeddedRelationExist(JavaPersistentType embeddable, JavaPersistentType embeddingEntity, String embeddedAttributeName, HasReferenceType relType);
+
public void restoreEntity(JavaPersistentType jpt);
public void addRemoveIgnore(JavaPersistentType jpt, String atName);
@@ -119,5 +124,9 @@ public interface IJPAEditorFeatureProvider extends IFeatureProvider{
public void removeAllRedundantIsARelations();
public boolean existRedundantIsARelations();
+
+ public void setGrayColor(final JavaPersistentType jpt);
+
+ public void setOriginalPersistentTypeColor();
} \ No newline at end of file
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/provider/IJPAEditorImageCreator.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/provider/IJPAEditorImageCreator.java
index 12e399c..9baccf6 100644
--- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/provider/IJPAEditorImageCreator.java
+++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/provider/IJPAEditorImageCreator.java
@@ -32,22 +32,21 @@ public interface IJPAEditorImageCreator {
public Polyline createConnectionLine(Diagram d, Connection connection);
public Polyline createIsAConnectionLine(Diagram d, Connection connection);
+
+ public Polyline createHasReferenceConnectionLine(Diagram d, Connection connection);
- //public ConnectionDecorator createTextConnectionDecorator(Connection connection, String text, double location);
+ public ConnectionDecorator createArrowConnectionDecorator(Connection connection, double location);
+
+ public ConnectionDecorator createIsAArrowConnectionDecorator(Connection connection, double location);
- public ConnectionDecorator createArrowConnectionDecorator(Connection connection, double location, boolean isA);
+ public ConnectionDecorator createHasReferenceStartConnectionDecorator(Connection connection, double location);
public ConnectionDecorator createManyEndWithArrowDecorator(Connection connection, double location);
public ConnectionDecorator createManyStartDecorator(Connection connection, double location);
- public ConnectionDecorator createManyEndDecorator(Connection connection, double location);
-
- public ConnectionDecorator createIconConnectionDecorator(Connection connection, String iconId, double location);
-
- public ConnectionDecorator createCardinalityConnectionDecorator(Diagram d, Connection c, String text, double location);
-
- public ConnectionDecorator createIsATextConnectionDecorator(Diagram d, Connection c);
+ public ConnectionDecorator createManyEndDecorator(Connection connection, double location, boolean isEmbedded);
+ public ConnectionDecorator createCardinalityConnectionDecorator(Diagram d, Connection c, String text, double location);
}
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/provider/JPAEditorFeatureProvider.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/provider/JPAEditorFeatureProvider.java
index 3449be4..53655ff 100644
--- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/provider/JPAEditorFeatureProvider.java
+++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/provider/JPAEditorFeatureProvider.java
@@ -49,7 +49,6 @@ import org.eclipse.graphiti.features.context.IMoveConnectionDecoratorContext;
import org.eclipse.graphiti.features.context.IMoveShapeContext;
import org.eclipse.graphiti.features.context.IRemoveContext;
import org.eclipse.graphiti.features.context.IResizeShapeContext;
-import org.eclipse.graphiti.features.context.impl.AddConnectionContext;
import org.eclipse.graphiti.features.custom.ICustomFeature;
import org.eclipse.graphiti.features.impl.Reason;
import org.eclipse.graphiti.internal.services.GraphitiInternal;
@@ -65,19 +64,23 @@ import org.eclipse.graphiti.mm.pictograms.Shape;
import org.eclipse.graphiti.services.Graphiti;
import org.eclipse.graphiti.services.IPeService;
import org.eclipse.graphiti.ui.features.DefaultFeatureProvider;
+import org.eclipse.graphiti.util.IColorConstant;
import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jdt.internal.core.CompilationUnit;
import org.eclipse.jdt.internal.core.SourceType;
import org.eclipse.jpt.jpa.core.JpaNode;
+import org.eclipse.jpt.jpa.core.JpaProject;
import org.eclipse.jpt.jpa.core.context.PersistentAttribute;
import org.eclipse.jpt.jpa.core.context.PersistentType;
import org.eclipse.jpt.jpa.core.context.java.JavaEntity;
import org.eclipse.jpt.jpa.core.context.java.JavaPersistentAttribute;
import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType;
+import org.eclipse.jpt.jpa.core.context.persistence.ClassRef;
import org.eclipse.jpt.jpa.core.context.persistence.PersistenceUnit;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.JPADiagramEditorPlugin;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.feature.AddAllEntitiesFeature;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.feature.AddAttributeFeature;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.feature.AddHasReferenceRelationFeature;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.feature.AddJPAEntityFeature;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.feature.AddRelationFeature;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.feature.ClickAddAttributeButtonFeature;
@@ -85,6 +88,7 @@ import org.eclipse.jpt.jpadiagrameditor.ui.internal.feature.ClickRemoveAttribute
import org.eclipse.jpt.jpadiagrameditor.ui.internal.feature.CollapseAllEntitiesFeature;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.feature.CollapseCompartmentShapeFeature;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.feature.CollapseEntityFeature;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.feature.CreateEmbeddableFeature;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.feature.CreateJPAEntityFeature;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.feature.CreateManyToManyBiDirRelationFeature;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.feature.CreateManyToManyUniDirRelationFeature;
@@ -114,16 +118,20 @@ import org.eclipse.jpt.jpadiagrameditor.ui.internal.modelintegration.util.ModelI
import org.eclipse.jpt.jpadiagrameditor.ui.internal.modelintegration.util.ModelIntegrationUtilImpl;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.propertypage.JPADiagramPropertyPage;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.AbstractRelation;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.HasReferanceRelation;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.HasReferanceRelation.HasReferenceType;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.IRelation;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.IRelation.RelDir;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.IRelation.RelType;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.IsARelation;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.GraphicsUpdaterImpl;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.IGraphicsUpdater;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.IJPAEditorPredefinedRenderingStyle;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.IJPAEditorUtil;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.IJpaSolver;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.IPeServiceUtil;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JPAEditorConstants;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JPAEditorPredefinedColoredAreas;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JPAEditorUtil;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JPAEditorUtilImpl;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JPASolver;
@@ -177,12 +185,16 @@ public class JPAEditorFeatureProvider extends DefaultFeatureProvider implements
return res;
}
- public HashSet<IsARelation> getAllRedundantIsARelations() {
+ public HashSet<HasReferanceRelation> getAllExistingHasReferenceRelations() {
EList<Connection> allCons = getDiagram().getConnections();
- HashSet<IsARelation> res = new HashSet<IsARelation>();
+ HashSet<HasReferanceRelation> res = new HashSet<HasReferanceRelation>();
for (Connection conn : allCons) {
- if (IsARelation.isIsAConnection(conn))
- res.add(new IsARelation(this, conn));
+ if (HasReferanceRelation.isHasReferenceConnection(conn))
+ try {
+ HasReferanceRelation hasReferenceRelation = (HasReferanceRelation) getBusinessObjectForPictogramElement(conn);
+ res.add(hasReferenceRelation);
+ } catch (NullPointerException e) {
+ }
}
return res;
}
@@ -199,7 +211,7 @@ public class JPAEditorFeatureProvider extends DefaultFeatureProvider implements
redundantConnections.add(conn);
continue;
}
- if (!rel.getSuperclass().getName().equals(getFirstSuperclassBelongingToTheDiagram(rel.getSubclass()).getName())) {
+ if (rel != null && !rel.getSuperclass().getName().equals(getFirstSuperclassBelongingToTheDiagram(rel.getSubclass()).getName())) {
redundantConnections.add(conn);
}
}
@@ -221,7 +233,7 @@ public class JPAEditorFeatureProvider extends DefaultFeatureProvider implements
} catch (NullPointerException e) {
return true;
}
- if (!rel.getSuperclass().equals(getFirstSuperclassBelongingToTheDiagram(rel.getSubclass()))) {
+ if (rel != null && !rel.getSuperclass().equals(getFirstSuperclassBelongingToTheDiagram(rel.getSubclass()))) {
return true;
}
}
@@ -231,6 +243,7 @@ public class JPAEditorFeatureProvider extends DefaultFeatureProvider implements
public JavaPersistentType getFirstSuperclassBelongingToTheDiagram(JavaPersistentType subclass) {
Iterable<PersistentType> h = subclass.getInheritanceHierarchy();
+
Iterator<PersistentType> iter = h.iterator();
if (!iter.hasNext())
return null;
@@ -269,10 +282,6 @@ public class JPAEditorFeatureProvider extends DefaultFeatureProvider implements
public void addAttribForUpdate(PersistenceUnit pu, String entAtMappedBy) {
((JPASolver)getIndependenceSolver()).addAttribForUpdate(pu, entAtMappedBy);
}
-
- public boolean existsRelation(JavaPersistentType jpt1, JavaPersistentType jpt2) {
- return ((JPASolver)getIndependenceSolver()).existsRelation(jpt1, jpt2);
- }
@Override
public IAddFeature getAddFeature(IAddContext context) {
@@ -281,6 +290,8 @@ public class JPAEditorFeatureProvider extends DefaultFeatureProvider implements
return new AddJPAEntityFeature(this, true);
} else if (newObj instanceof AbstractRelation) {
return new AddRelationFeature(this);
+ } else if (newObj instanceof HasReferanceRelation) {
+ return new AddHasReferenceRelationFeature(this);
} else if (newObj instanceof PersistentAttribute) {
if (Diagram.class.isInstance(context.getTargetContainer())) {
return null;
@@ -303,7 +314,8 @@ public class JPAEditorFeatureProvider extends DefaultFeatureProvider implements
@Override
public ICreateFeature[] getCreateFeatures() {
return new ICreateFeature[] {new CreateJPAEntityFeature(this),
- new CreateMappedSuperclassFeature(this)};
+ new CreateMappedSuperclassFeature(this),
+ new CreateEmbeddableFeature(this)};
}
@Override
@@ -312,7 +324,8 @@ public class JPAEditorFeatureProvider extends DefaultFeatureProvider implements
Object bo = getBusinessObjectForPictogramElement(pe);
if (bo instanceof JavaPersistentType) {
return new DeleteJPAEntityFeature(this);
- } else if (bo instanceof AbstractRelation) {
+ } else if ((bo instanceof AbstractRelation) ||
+ (bo instanceof HasReferanceRelation)) {
return new DeleteRelationFeature(this);
} else if (bo instanceof JavaPersistentAttribute) {
return new ClickRemoveAttributeButtonFeature(this);
@@ -380,7 +393,8 @@ public class JPAEditorFeatureProvider extends DefaultFeatureProvider implements
super.getRemoveFeature(context);
if (bo instanceof JavaPersistentType) {
return new RemoveJPAEntityFeature(this, true);
- } else if (bo instanceof AbstractRelation) {
+ } else if ((bo instanceof AbstractRelation) ||
+ (bo instanceof HasReferanceRelation)){
return new RemoveRelationFeature(this);
}
GraphicsAlgorithm ga = pe.getGraphicsAlgorithm();
@@ -469,40 +483,9 @@ public class JPAEditorFeatureProvider extends DefaultFeatureProvider implements
return super.getDirectEditingFeature(context);
}
- public void addMissingRelations(JavaPersistentType newEntity, ContainerShape newShape) {
- Collection<PictogramElement> allContainedPictogramElements = Graphiti.getPeService()
- .getAllContainedPictogramElements(getDiagramTypeProvider().getDiagram());
-
- for (PictogramElement pe : allContainedPictogramElements) {
- if ((pe != newShape) && (pe instanceof ContainerShape)) {
- JavaPersistentType entity = (JavaPersistentType)getBusinessObjectForPictogramElement(pe);
- AbstractRelation newRel = produceNecessaryRelation(newEntity, entity);
- if (newRel != null) {
- JavaPersistentType owner = newRel.getOwner();
- JavaPersistentType inverse = newRel.getInverse();
- ContainerShape ownerShape = (ContainerShape)getPictogramElementForBusinessObject(owner);
- ContainerShape inverseShape = (ContainerShape)getPictogramElementForBusinessObject(inverse);
- AddRelationFeature f = new AddRelationFeature(this);
- AddConnectionContext ctx =
- new AddConnectionContext(JPAEditorUtil.getAnchor(ownerShape), JPAEditorUtil.getAnchor(inverseShape));
- f.add(ctx);
- }
- }
- }
- }
-
public void renewAttributeJoiningStrategyPropertyListener(JavaPersistentAttribute jpa) {
((JPASolver)getIndependenceSolver()).renewAttributeJoiningStrategyPropertyListener(jpa);
}
-
- private AbstractRelation produceNecessaryRelation(JavaPersistentType ent1, JavaPersistentType ent2) {
- return null;
- }
-
- public String produceKeyForRel(JavaPersistentType jpt, String attributeName) {
- return ((JPASolver)getIndependenceSolver()).produceKeyForRel(jpt, attributeName);
- }
-
public ClickAddAttributeButtonFeature getClickAddAttributeButtonFeature() {
if (clickAddAttBtnFeat == null) {
@@ -549,7 +532,7 @@ public class JPAEditorFeatureProvider extends DefaultFeatureProvider implements
if(!(jpt.getMapping() instanceof JavaEntity)){
PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() {
public void run() {
- removeFromDiagramIfNotEntity(jpt);
+ removeFromDiagramIfNotPersistentType(jpt);
}});
}
@@ -568,7 +551,7 @@ public class JPAEditorFeatureProvider extends DefaultFeatureProvider implements
Connection connection = iterator.next();
if (GraphitiInternal.getEmfService().isObjectAlive(connection)) {
Object ob = getBusinessObjectForPictogramElement(connection);
- if(ob instanceof AbstractRelation){
+ if((ob instanceof AbstractRelation) || (ob instanceof HasReferanceRelation)){
String key = getKeyForBusinessObject(ob);
((JPASolver)getIndependenceSolver()).remove(key);
}
@@ -579,7 +562,7 @@ public class JPAEditorFeatureProvider extends DefaultFeatureProvider implements
}
- private void removeFromDiagramIfNotEntity(final JavaPersistentType jpt) {
+ private void removeFromDiagramIfNotPersistentType(final JavaPersistentType jpt) {
final PictogramElement cs = this.getPictogramElementForBusinessObject(jpt);
if (cs != null) {
final Shape shape = (Shape) cs;
@@ -631,21 +614,31 @@ public class JPAEditorFeatureProvider extends DefaultFeatureProvider implements
public boolean doesRelationExist(JavaPersistentType owner,
JavaPersistentType inverse,
String ownerAttributeName,
+ String inverseAttributeName,
RelType relType,
RelDir relDir) {
- String id = AbstractRelation.generateId(owner, inverse, ownerAttributeName, relType, relDir);
+ String id = AbstractRelation.generateId(owner, inverse, ownerAttributeName, inverseAttributeName, relType, relDir);
return (getBusinessObjectForKey(id) != null);
- }
+ }
+
+ public boolean doesEmbeddedRelationExist(JavaPersistentType embeddable, JavaPersistentType embeddingEntity, String embeddedAttributeName, HasReferenceType relType){
+ String id = HasReferanceRelation.generateId(embeddable, embeddingEntity, embeddedAttributeName, relType);
+ return (getBusinessObjectForKey(id) != null);
+ }
public boolean isRelationRelatedToAttribute(JavaPersistentAttribute jpa) {
return ((JPASolver)getIndependenceSolver()).isRelationRelatedToAttribute(jpa);
}
-
+
public IRelation getRelationRelatedToAttribute(JavaPersistentAttribute jpa) {
- return ((JPASolver)getIndependenceSolver()).getRelationRelatedToAttribute(jpa);
+ return ((JPASolver)getIndependenceSolver()).getRelationRelatedToAttribute(jpa, this);
}
+ public HasReferanceRelation getEmbeddedRelationRelatedToAttribute(JavaPersistentAttribute jpa) {
+ return ((JPASolver)getIndependenceSolver()).getEmbeddedRelationToAttribute(jpa);
+ }
+
public ICompilationUnit getCompilationUnit(JavaPersistentType jpt) {
return ((JPASolver)getIndependenceSolver()).getCompilationUnit(jpt);
}
@@ -744,5 +737,63 @@ public class JPAEditorFeatureProvider extends DefaultFeatureProvider implements
public Properties loadProperties(IProject project) {
return JPADiagramPropertyPage.loadProperties(project);
}
+
+ /**
+ * Color the given persistent type in gray.
+ * @param jpt - the {@link JavaPersistentType} to be colored.
+ */
+ public void setGrayColor(final JavaPersistentType jpt) {
+ final PictogramElement pe = getPictogramElementForBusinessObject(jpt);
+ if(pe == null)
+ return;
+ TransactionalEditingDomain ted = getTransactionalEditingDomain();
+ if(ted == null)
+ return;
+ ted.getCommandStack().execute(new RecordingCommand(ted) {
+
+ @Override
+ protected void doExecute() {
+ Graphiti.getGaService().setRenderingStyle(pe.getGraphicsAlgorithm(),
+ JPAEditorPredefinedColoredAreas.getAdaptedGradientColoredAreas(IJPAEditorPredefinedRenderingStyle.SILVER_WHITE_GLOSS_ID));
+ pe.getGraphicsAlgorithm().setForeground(Graphiti.getGaService().manageColor(getDiagram(),JPAEditorConstants.ENTITY_DISABLED_COLOR));
+ }
+
+ });
+ }
+ /**
+ * For each persistent type in the JPA project's persistence unit,
+ * color the type in its original color, depending on the persistent
+ * type.
+ */
+ public void setOriginalPersistentTypeColor(){
+ Diagram d = getDiagram();
+ JpaProject project = ModelIntegrationUtil.getProjectByDiagram(d.getName());
+ PersistenceUnit unit = project.getRootContextNode().getPersistenceXml().
+ getRoot().getPersistenceUnits().iterator().next();
+ for (ClassRef classRef : unit.getClassRefs()) {
+ if (classRef.getJavaPersistentType() != null) { // null if
+ final JavaPersistentType jpt = classRef.getJavaPersistentType();
+ final PictogramElement pe = getPictogramElementForBusinessObject(jpt);
+ if(pe == null)
+ continue;
+ TransactionalEditingDomain ted = getTransactionalEditingDomain();
+
+ JPAEditorConstants.DIAGRAM_OBJECT_TYPE dot = JpaArtifactFactory.instance().determineDiagramObjectType(jpt);
+ final String renderingStyle = JpaArtifactFactory.instance().getRenderingStyle(dot);
+ final IColorConstant foreground = JpaArtifactFactory.instance().getForeground(dot);
+ if(ted == null)
+ continue;
+ ted.getCommandStack().execute(new RecordingCommand(ted) {
+
+ @Override
+ protected void doExecute() {
+ Graphiti.getGaService().setRenderingStyle(pe.getGraphicsAlgorithm(),
+ JPAEditorPredefinedColoredAreas.getAdaptedGradientColoredAreas(renderingStyle));
+ pe.getGraphicsAlgorithm().setForeground(Graphiti.getGaService().manageColor(getDiagram(), foreground));
+ }
+ });
+ }
+ }
+ }
}
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/provider/JPAEditorImageCreator.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/provider/JPAEditorImageCreator.java
index 628f4dc..75efe4a 100644
--- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/provider/JPAEditorImageCreator.java
+++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/provider/JPAEditorImageCreator.java
@@ -15,7 +15,7 @@
*******************************************************************************/
package org.eclipse.jpt.jpadiagrameditor.ui.internal.provider;
-import org.eclipse.graphiti.mm.algorithms.Image;
+import org.eclipse.graphiti.mm.algorithms.Polygon;
import org.eclipse.graphiti.mm.algorithms.Polyline;
import org.eclipse.graphiti.mm.algorithms.Text;
import org.eclipse.graphiti.mm.algorithms.styles.LineStyle;
@@ -45,6 +45,14 @@ public class JPAEditorImageCreator implements IJPAEditorImageCreator {
polyline.setLineStyle(LineStyle.DASH);
return polyline;
}
+
+ public Polyline createHasReferenceConnectionLine(Diagram d, Connection connection) {
+ Polyline polyline = Graphiti.getGaService().createPolyline(connection);
+ polyline.setForeground(Graphiti.getGaService().manageColor(d, JPAEditorConstants.EMBEDDED_CONNECTION_LINE_COLOR));
+ polyline.setLineWidth(JPAEditorConstants.EMBEDDED_CONNECTION_LINE_WIDTH);
+ polyline.setLineStyle(LineStyle.DASHDOTDOT);
+ return polyline;
+ }
public ConnectionDecorator createCardinalityConnectionDecorator(Diagram d, Connection c, String text, double location) {
ConnectionDecorator textDecorator = Graphiti.getPeService().createConnectionDecorator(c, true, location, true);
@@ -57,65 +65,61 @@ public class JPAEditorImageCreator implements IJPAEditorImageCreator {
return textDecorator;
}
- public ConnectionDecorator createArrowConnectionDecorator(Connection connection,
- double location,
- boolean isA) {
+ public ConnectionDecorator createArrowConnectionDecorator(Connection connection, double location) {
+ ConnectionDecorator cd = Graphiti.getPeService().createConnectionDecorator(connection, false, location, true);
+ Polygon arrow = Graphiti.getGaService().createPolygon(cd, new int[] { 11, 3, 0, 0, 11, -3, 11, 3 });
+ arrow.setForeground(Graphiti.getGaService().manageColor(connection.getParent(), JPAEditorConstants.CONNECTION_LINE_COLOR));
+ arrow.setLineWidth(JPAEditorConstants.CONNECTION_LINE_WIDTH);
+ arrow.setFilled(true);
+ return cd;
+ }
+
+ public ConnectionDecorator createIsAArrowConnectionDecorator(Connection connection, double location) {
+ ConnectionDecorator cd = Graphiti.getPeService().createConnectionDecorator(connection, false, location, true);
+ Polygon arrow = Graphiti.getGaService().createPolygon(cd, new int[] { 11, 6, 0, 0, 11, -6, 11, 6 });
+ arrow.setForeground(Graphiti.getGaService().manageColor(connection.getParent(), JPAEditorConstants.IS_A_CONNECTION_LINE_COLOR));
+ arrow.setBackground(Graphiti.getGaService().manageColor(connection.getParent(), JPAEditorConstants.IS_A_ARROW_COLOR));
+ arrow.setLineWidth(JPAEditorConstants.CONNECTION_LINE_WIDTH);
+ arrow.setFilled(true);
+ return cd;
+ }
+
+ public ConnectionDecorator createHasReferenceStartConnectionDecorator(Connection connection, double location) {
ConnectionDecorator cd = Graphiti.getPeService().createConnectionDecorator(connection, false, location, true);
- Polyline arrow = Graphiti.getGaService().createPolyline(cd, new int[] { 11, 3, 0, 0, 11, -3, 11, 3 });
- arrow.setForeground(Graphiti.getGaService().manageColor(connection.getParent(), isA ?
- JPAEditorConstants.IS_A_CONNECTION_LINE_COLOR :
- JPAEditorConstants.CONNECTION_LINE_COLOR));
+ Polygon arrow = Graphiti.getGaService().createPolygon(cd, new int[] { 0, 0, -5, 3, -10, 0, -5, -3, 0, 0 });
+ arrow.setForeground(Graphiti.getGaService().manageColor(connection.getParent(), JPAEditorConstants.EMBEDDED_CONNECTION_LINE_COLOR));
+ arrow.setBackground(Graphiti.getGaService().manageColor(connection.getParent(), JPAEditorConstants.EMBEDDED_CONNECTION_LINE_COLOR));
arrow.setLineWidth(JPAEditorConstants.CONNECTION_LINE_WIDTH);
+ arrow.setFilled(true);
+
return cd;
}
public ConnectionDecorator createManyEndWithArrowDecorator(Connection connection, double location) {
ConnectionDecorator cd = Graphiti.getPeService().createConnectionDecorator(connection, false, location, true);
- Polyline arrow = null;
- arrow = Graphiti.getGaService().createPolyline(cd, new int[] { -2, 7, 6, 0, -2, -7, 6, 0, 20, 3, 20, -3, 7, 0});
- arrow.setForeground(Graphiti.getGaService().manageColor(connection.getParent(), JPAEditorConstants.CONNECTION_LINE_COLOR));
+ Polygon arrow = Graphiti.getGaService().createPolygon(cd, new int[] { -2, 7, 6, 0, -2, -7, 6, 0, 20, 3, 20, -3, 7, 0});
+ arrow.setForeground(Graphiti.getGaService().manageColor(connection.getParent(), JPAEditorConstants.CONNECTION_LINE_COLOR));
+ arrow.setBackground(Graphiti.getGaService().manageColor(connection.getParent(), JPAEditorConstants.CONNECTION_LINE_COLOR));
arrow.setLineWidth(JPAEditorConstants.CONNECTION_LINE_WIDTH);
+ arrow.setFilled(true);
return cd;
}
- public ConnectionDecorator createManyEndDecorator(Connection connection, double location) {
+ public ConnectionDecorator createManyEndDecorator(Connection connection, double location, boolean isEmbedded) {
ConnectionDecorator cd = Graphiti.getPeService().createConnectionDecorator(connection, false, location, true);
- Polyline arrow = null;
- arrow = Graphiti.getGaService().createPolyline(cd, new int[] { 0, 7,
- 8, 0,
- 0, -7 });
- arrow.setForeground(Graphiti.getGaService().manageColor(connection.getParent(), JPAEditorConstants.CONNECTION_LINE_COLOR));
+ Polyline arrow = Graphiti.getGaService().createPolyline(cd, new int[] { 0, 7, 8, 0, 0, -7 });
+ arrow.setForeground(Graphiti.getGaService().manageColor(connection.getParent(), isEmbedded ? JPAEditorConstants.EMBEDDED_CONNECTION_LINE_COLOR
+ :JPAEditorConstants.CONNECTION_LINE_COLOR));
arrow.setLineWidth(JPAEditorConstants.CONNECTION_LINE_WIDTH);
return cd;
}
public ConnectionDecorator createManyStartDecorator(Connection connection, double location) {
ConnectionDecorator cd = Graphiti.getPeService().createConnectionDecorator(connection, false, location, true);
- Polyline arrow = null;
- arrow = Graphiti.getGaService().createPolyline(cd, new int[] {0, 7,
- -8, 0,
- 0, -7 });
+ Polyline arrow = Graphiti.getGaService().createPolyline(cd, new int[] {0, 7, -8, 0, 0, -7 });
arrow.setForeground(Graphiti.getGaService().manageColor(connection.getParent(), JPAEditorConstants.CONNECTION_LINE_COLOR));
arrow.setLineWidth(JPAEditorConstants.CONNECTION_LINE_WIDTH);
return cd;
- }
-
- public ConnectionDecorator createIconConnectionDecorator(Connection connection, String iconId, double location) {
- ConnectionDecorator iconDecorator = Graphiti.getPeService().createConnectionDecorator(connection, true, location, true);
- Image icon = Graphiti.getGaService().createImage(connection, iconId);
- Graphiti.getGaService().setLocation(icon, 5, -20);
- return iconDecorator;
- }
-
- public ConnectionDecorator createIsATextConnectionDecorator(Diagram d, Connection c) {
- ConnectionDecorator textDecorator = Graphiti.getPeService().createConnectionDecorator(c, true, 0.5, true);
- Text txt = Graphiti.getGaService().createDefaultText(d, textDecorator);
- txt.setLineWidth(JPAEditorConstants.CONNECTION_LINE_WIDTH);
- txt.setValue(JPAEditorConstants.IS_A);
- Graphiti.getGaService().manageColor(c.getParent(), IColorConstant.BLACK);
- //Point pt = JPAEditorUtil.recalcTextDecoratorPosition((FreeFormConnection)c, textDecorator);
- Graphiti.getGaService().setLocation(txt, 5, 5, false);
- return textDecorator;
}
}
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/provider/JPAEditorImageProvider.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/provider/JPAEditorImageProvider.java
index cd1a814..824c9b2 100644
--- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/provider/JPAEditorImageProvider.java
+++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/provider/JPAEditorImageProvider.java
@@ -24,9 +24,12 @@ public class JPAEditorImageProvider extends AbstractImageProvider {
public static final String JPA_ENTITY = PREFIX + "entity"; //$NON-NLS-1$
public static final String MAPPED_SUPERCLASS = PREFIX + "mapped_superclass"; //$NON-NLS-1$
+ public static final String EMBEDDABLE = PREFIX + "embeddable"; //$NON-NLS-1$
public static final String ADD_JPA_ENTITY = PREFIX + "add_entity"; //$NON-NLS-1$
public static final String ADD_INHERITED_ENTITY = PREFIX + "add_inherited_entity"; //$NON-NLS-1$
public static final String ADD_MAPPED_SUPERCLASS = PREFIX + "add_mapped_superclass"; //$NON-NLS-1$
+ public static final String ADD_EMBEDDABLE = PREFIX + "add_embeddable"; //$NON-NLS-1$
+
public static final String PRIMARY_KEY = PREFIX + "pk"; //$NON-NLS-1$
public static final String ICON_BASIC = PREFIX + "field"; //$NON-NLS-1$
public static final String ADD_ATTRIBUTE = PREFIX + "add_attribute"; //$NON-NLS-1$
@@ -39,6 +42,7 @@ public class JPAEditorImageProvider extends AbstractImageProvider {
public static final String ICON_VERSION = PREFIX + "version"; //$NON-NLS-1$
public static final String ICON_TRANSIENT = PREFIX + "transient"; //$NON-NLS-1$
public static final String ICON_EMBEDDED = PREFIX + "embedded"; //$NON-NLS-1$
+ public static final String ICON_ELEMENT_COLLECTION = PREFIX + "element-collection"; //$NON-NLS-1$
public static final String ICON_UNMAPPED = PREFIX + "unmapped"; //$NON-NLS-1$
@@ -56,7 +60,7 @@ public class JPAEditorImageProvider extends AbstractImageProvider {
public static final String ICON_RESTORE = PREFIX + "restore"; //$NON-NLS-1$
public static final String ICON_SAVE_AND_REMOVE = PREFIX + "save_and_remove"; //$NON-NLS-1$
- private static final String ROOT_FOLDER_FOR_IMG = "icons/"; //$NON-NLS-1$
+ public static final String ROOT_FOLDER_FOR_IMG = "icons/"; //$NON-NLS-1$
public JPAEditorImageProvider() {
super();
@@ -67,9 +71,11 @@ public class JPAEditorImageProvider extends AbstractImageProvider {
addImageFilePath(ICON_BASIC, ROOT_FOLDER_FOR_IMG + "ent/basic.gif"); //$NON-NLS-1$
addImageFilePath(JPA_ENTITY, ROOT_FOLDER_FOR_IMG + "ent/entity.gif"); //$NON-NLS-1$
addImageFilePath(MAPPED_SUPERCLASS, ROOT_FOLDER_FOR_IMG + "ent/mapped-superclass.gif"); //$NON-NLS-1$
+ addImageFilePath(EMBEDDABLE, ROOT_FOLDER_FOR_IMG + "ent/embeddable.gif"); //$NON-NLS-1$
addImageFilePath(ADD_JPA_ENTITY, ROOT_FOLDER_FOR_IMG + "ent/add_entity.gif"); //$NON-NLS-1$
addImageFilePath(ADD_INHERITED_ENTITY, ROOT_FOLDER_FOR_IMG + "ent/add_entity.gif"); //$NON-NLS-1$
addImageFilePath(ADD_MAPPED_SUPERCLASS, ROOT_FOLDER_FOR_IMG + "ent/add_mapped-superclass.gif"); //$NON-NLS-1$
+ addImageFilePath(ADD_EMBEDDABLE, ROOT_FOLDER_FOR_IMG + "ent/add_embeddable.gif"); //$NON-NLS-1$
addImageFilePath(PRIMARY_KEY, ROOT_FOLDER_FOR_IMG + "ent/id.gif"); //$NON-NLS-1$
addImageFilePath(ADD_ATTRIBUTE, ROOT_FOLDER_FOR_IMG + "ent/add_attribute.gif"); //$NON-NLS-1$
addImageFilePath(REMOVE_ATTRIBUTE, ROOT_FOLDER_FOR_IMG + "ent/remove_attribute.gif"); //$NON-NLS-1$
@@ -81,6 +87,7 @@ public class JPAEditorImageProvider extends AbstractImageProvider {
addImageFilePath(ICON_VERSION, ROOT_FOLDER_FOR_IMG + "ent/version.gif"); //$NON-NLS-1$
addImageFilePath(ICON_TRANSIENT, ROOT_FOLDER_FOR_IMG + "ent/transient.gif"); //$NON-NLS-1$
addImageFilePath(ICON_EMBEDDED, ROOT_FOLDER_FOR_IMG + "ent/embedded.gif"); //$NON-NLS-1$
+ addImageFilePath(ICON_ELEMENT_COLLECTION, ROOT_FOLDER_FOR_IMG + "ent/element-collection.gif"); //$NON-NLS-1$
addImageFilePath(ICON_UNMAPPED, ROOT_FOLDER_FOR_IMG + "ent/null-attribute-mapping.gif"); //$NON-NLS-1$
addImageFilePath(ICON_ONE_TO_ONE_1_DIR, ROOT_FOLDER_FOR_IMG + "ent/one-to-one-1-dir.gif"); //$NON-NLS-1$
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/provider/JPAEditorToolBehaviorProvider.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/provider/JPAEditorToolBehaviorProvider.java
index 6518f97..bc02b90 100644
--- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/provider/JPAEditorToolBehaviorProvider.java
+++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/provider/JPAEditorToolBehaviorProvider.java
@@ -59,6 +59,7 @@ import org.eclipse.graphiti.tb.IContextButtonPadData;
import org.eclipse.graphiti.tb.IContextMenuEntry;
import org.eclipse.graphiti.tb.IDecorator;
import org.eclipse.graphiti.tb.ImageDecorator;
+import org.eclipse.jpt.jpa.core.JpaProject;
import org.eclipse.jpt.jpa.core.context.java.JavaPersistentAttribute;
import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.JPADiagramEditorPlugin;
@@ -72,6 +73,8 @@ import org.eclipse.jpt.jpadiagrameditor.ui.internal.feature.CollapseEntityFeatur
import org.eclipse.jpt.jpadiagrameditor.ui.internal.feature.CreateInheritedEntityFeature;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.feature.DeleteJPAEntityFeature;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.feature.DiscardAndRemoveAllEntitiesFeature;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.feature.EmbedCollectionOfObjectsFeature;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.feature.EmbedSingleObjectFeature;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.feature.ExpandAllEntitiesFeature;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.feature.ExpandCompartmentShapeFeature;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.feature.ExpandEntityFeature;
@@ -87,6 +90,7 @@ import org.eclipse.jpt.jpadiagrameditor.ui.internal.feature.SaveAndRemoveAllEnti
import org.eclipse.jpt.jpadiagrameditor.ui.internal.feature.SaveEntityFeature;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.i18n.JPAEditorMessages;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.modelintegration.ui.JPAEditorMatchingStrategy;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.modelintegration.util.ModelIntegrationUtil;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.GraphicsUpdater;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.IEclipseFacade;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JPAEditorConstants;
@@ -239,19 +243,51 @@ public class JPAEditorToolBehaviorProvider extends DefaultToolBehaviorProvider {
ret.set(0, ret.get(1));
ret.set(1, en);
- PaletteCompartmentEntry ent = new PaletteCompartmentEntry(JPAEditorMessages.JPAEditorToolBehaviorProvider_InheritanceCompartmentTitle, superCompartments[1].getIconId());
- CreateInheritedEntityFeature ft = new CreateInheritedEntityFeature(this.getFeatureProvider());
+ createInheritancePaletteSection(ret, superCompartments);
+
+ createCompositionPaletteSection(ret, superCompartments);
+
+ return ret.toArray(new IPaletteCompartmentEntry[ret.size()]);
+ }
+
+ private void createCompositionPaletteSection(
+ List<IPaletteCompartmentEntry> ret,
+ IPaletteCompartmentEntry[] superCompartments) {
+ PaletteCompartmentEntry compositionEnt = new PaletteCompartmentEntry(JPAEditorMessages.JPAEditorToolBehaviorProvider_CompositionPaletteName, superCompartments[1].getIconId());
+
+ EmbedSingleObjectFeature embedObjectFt = new EmbedSingleObjectFeature(this.getFeatureProvider());
+ ConnectionCreationToolEntry isEmbeddedObjectToolEntry = new ConnectionCreationToolEntry(embedObjectFt.getCreateName(),
+ embedObjectFt.getCreateDescription(), embedObjectFt.getCreateImageId(), embedObjectFt.getCreateLargeImageId());
+ isEmbeddedObjectToolEntry.addCreateConnectionFeature(embedObjectFt);
+ compositionEnt.addToolEntry(isEmbeddedObjectToolEntry);
+
+ if(!JPAEditorUtil.checkJPAFacetVersion(getTargetJPAProject(), JPAEditorUtil.JPA_PROJECT_FACET_10)) {
+ EmbedCollectionOfObjectsFeature embedCollectionFt = new EmbedCollectionOfObjectsFeature(this.getFeatureProvider());
+ ConnectionCreationToolEntry isEmbeddedCollectionToolEntry = new ConnectionCreationToolEntry(embedCollectionFt.getCreateName(),
+ embedCollectionFt.getCreateDescription(), embedCollectionFt.getCreateImageId(), embedCollectionFt.getCreateLargeImageId());
+ isEmbeddedCollectionToolEntry.addCreateConnectionFeature(embedCollectionFt);
+ compositionEnt.addToolEntry(isEmbeddedCollectionToolEntry);
+ }
+
+ ret.add(2, compositionEnt);
+ }
+
+ private JpaProject getTargetJPAProject() {
+ return ModelIntegrationUtil.getProjectByDiagram(getDiagramTypeProvider().getDiagram().getName());
+ }
+
+ private void createInheritancePaletteSection(
+ List<IPaletteCompartmentEntry> ret,
+ IPaletteCompartmentEntry[] superCompartments) {
+ PaletteCompartmentEntry ent = new PaletteCompartmentEntry(JPAEditorMessages.JPAEditorToolBehaviorProvider_InheritanceCompartmentTitle, superCompartments[1].getIconId());
+ CreateInheritedEntityFeature ft = new CreateInheritedEntityFeature((IJPAEditorFeatureProvider) this.getFeatureProvider());
ConnectionCreationToolEntry isARelToolEntry = new ConnectionCreationToolEntry(ft.getCreateName(),
ft.getCreateDescription(), ft.getCreateImageId(), ft.getCreateLargeImageId());
isARelToolEntry.addCreateConnectionFeature(ft);
ent.addToolEntry(isARelToolEntry);
-
-
ret.add(1, ent);
-
- return ret.toArray(new IPaletteCompartmentEntry[ret.size()]);
- }
+ }
@Override
public IDecorator[] getDecorators(PictogramElement pe) {
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/AbstractRelation.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/AbstractRelation.java
index 1af1f3e..b35a2bf 100644
--- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/AbstractRelation.java
+++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/AbstractRelation.java
@@ -50,7 +50,7 @@ abstract public class AbstractRelation implements IRelation {
}
public String getId() {
- return generateId(owner, inverse, getOwnerAttributeName(), getRelType(), getRelDir());
+ return generateId(owner, inverse, getOwnerAttributeName(), getInverseAttributeName(), getRelType(), getRelDir());
}
public JavaPersistentType getOwner() {
@@ -116,11 +116,19 @@ abstract public class AbstractRelation implements IRelation {
public static String generateId(JavaPersistentType owner,
JavaPersistentType inverse,
String ownerAttributeName,
+ String inverseAttributeName,
RelType relType,
RelDir relDir) {
- String id = owner.getName() + "-" + inverse.getName() + SEPARATOR + //$NON-NLS-1$
+ String id = ""; //$NON-NLS-1$
+ if(inverseAttributeName != null){
+ id = owner.getName() + "-" + inverse.getName() + SEPARATOR + //$NON-NLS-1$
relTypeToIdPart.get(relType) + SEPARATOR +
- relDirToIdPart.get(relDir) + SEPARATOR + ownerAttributeName;
+ relDirToIdPart.get(relDir) + SEPARATOR + ownerAttributeName + SEPARATOR + inverseAttributeName;
+ } else {
+ id = owner.getName() + "-" + inverse.getName() + SEPARATOR + //$NON-NLS-1$
+ relTypeToIdPart.get(relType) + SEPARATOR +
+ relDirToIdPart.get(relDir) + SEPARATOR + ownerAttributeName;
+ }
return id;
}
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/HasCollectionReferenceRelation.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/HasCollectionReferenceRelation.java
new file mode 100644
index 0000000..59972c8
--- /dev/null
+++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/HasCollectionReferenceRelation.java
@@ -0,0 +1,24 @@
+package org.eclipse.jpt.jpadiagrameditor.ui.internal.relations;
+
+import org.eclipse.graphiti.mm.pictograms.Connection;
+import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.IJPAEditorFeatureProvider;
+
+public class HasCollectionReferenceRelation extends HasReferanceRelation{
+
+ public HasCollectionReferenceRelation(JavaPersistentType embeddingEntity,
+ JavaPersistentType embeddable) {
+ super(embeddingEntity, embeddable);
+ }
+
+ public HasCollectionReferenceRelation(IJPAEditorFeatureProvider fp,
+ Connection conn) {
+ super(fp, conn);
+ }
+
+ @Override
+ public HasReferenceType getReferenceType() {
+ return HasReferenceType.COLLECTION;
+ }
+
+}
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/HasReferanceRelation.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/HasReferanceRelation.java
new file mode 100644
index 0000000..d044a9f
--- /dev/null
+++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/HasReferanceRelation.java
@@ -0,0 +1,95 @@
+package org.eclipse.jpt.jpadiagrameditor.ui.internal.relations;
+
+import java.util.Hashtable;
+
+import org.eclipse.graphiti.mm.pictograms.Anchor;
+import org.eclipse.graphiti.mm.pictograms.Connection;
+import org.eclipse.graphiti.mm.pictograms.ContainerShape;
+import org.eclipse.jpt.jpa.core.context.java.JavaPersistentAttribute;
+import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.IJPAEditorFeatureProvider;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JPAEditorConstants;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JPAEditorUtil;
+
+public abstract class HasReferanceRelation {
+ protected final static String SEPARATOR = ";hasReference;"; //$NON-NLS-1$
+ public final static String HAS_REFERENCE_CONNECTION_PROP_KEY = "is_has_reference_connection"; //$NON-NLS-1$
+
+ protected JavaPersistentType embeddingEntity;
+ protected JavaPersistentType embeddable;
+
+ public final static Hashtable<HasReferenceType, String> relTypeToIdPart = new Hashtable<HasReferenceType, String>();
+
+ private JavaPersistentAttribute embeddedAnnotatedAttribute;
+
+ public static enum HasReferenceType {
+ SINGLE, COLLECTION
+ }
+
+ static {
+ relTypeToIdPart.put(HasReferenceType.SINGLE, "1-1;"); //$NON-NLS-1$
+ relTypeToIdPart.put(HasReferenceType.COLLECTION, "1-N;"); //$NON-NLS-1$
+ }
+
+ public HasReferanceRelation(JavaPersistentType embeddingEntity,
+ JavaPersistentType embeddable) {
+ this.embeddingEntity = embeddingEntity;
+ this.embeddable = embeddable;
+ }
+
+ public HasReferanceRelation(IJPAEditorFeatureProvider fp, Connection conn) {
+ Anchor start = conn.getStart();
+ Anchor end = conn.getEnd();
+ Object startObj = fp.getBusinessObjectForPictogramElement((ContainerShape)start.eContainer());
+ Object endObj = fp.getBusinessObjectForPictogramElement((ContainerShape)end.eContainer());
+ if ((endObj == null) || (startObj == null))
+ throw new NullPointerException("Some of the connection ends is null"); //$NON-NLS-1$
+ if (!(endObj instanceof JavaPersistentType) || !(startObj instanceof JavaPersistentType))
+ throw new IllegalArgumentException();
+ this.embeddingEntity = (JavaPersistentType)startObj;
+ this.embeddable = (JavaPersistentType)endObj;
+ }
+
+
+ public JavaPersistentType getEmbeddable() {
+ return embeddable;
+ }
+
+ public JavaPersistentType getEmbeddingEntity() {
+ return embeddingEntity;
+ }
+
+ public static boolean isHasReferenceConnection(Connection conn) {
+ String val = JPAEditorUtil.getPeUtil().getPropertyValue(conn, HAS_REFERENCE_CONNECTION_PROP_KEY);
+ return (Boolean.TRUE.toString().equals(val));
+ }
+
+ public String getId() {
+ return generateId(embeddable, embeddingEntity, embeddedAnnotatedAttribute.getName(), getReferenceType());
+ }
+
+ public static String generateId(JavaPersistentType startJpt, JavaPersistentType endJpt, String embeddedAttributeName, HasReferenceType relType) {
+ return JPAEditorConstants.HAS_REFERENCE_RELATION_ID_PREFIX +
+ startJpt.getName() + SEPARATOR + relTypeToIdPart.get(relType) + endJpt.getName()+ "-" + embeddedAttributeName; //$NON-NLS-1$
+ }
+
+ public boolean equals(Object otherRel) {
+ if (!HasReferanceRelation.class.isInstance(otherRel))
+ return false;
+ return getId().equals(((HasReferanceRelation)otherRel).getId());
+ }
+
+ public int hashCode() {
+ return getId().hashCode();
+ }
+
+ public abstract HasReferenceType getReferenceType();
+
+ public JavaPersistentAttribute getEmbeddedAnnotatedAttribute() {
+ return embeddedAnnotatedAttribute;
+ }
+
+ public void setEmbeddedAnnotatedAttribute(JavaPersistentAttribute embeddedAnnotatedAttribute) {
+ this.embeddedAnnotatedAttribute = embeddedAnnotatedAttribute;
+ }
+}
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/HasSingleReferenceRelation.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/HasSingleReferenceRelation.java
new file mode 100644
index 0000000..48c204d
--- /dev/null
+++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/HasSingleReferenceRelation.java
@@ -0,0 +1,24 @@
+package org.eclipse.jpt.jpadiagrameditor.ui.internal.relations;
+
+import org.eclipse.graphiti.mm.pictograms.Connection;
+import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.IJPAEditorFeatureProvider;
+
+public class HasSingleReferenceRelation extends HasReferanceRelation{
+
+ public HasSingleReferenceRelation(JavaPersistentType embeddingEntity,
+ JavaPersistentType embeddable) {
+ super(embeddingEntity, embeddable);
+ }
+
+ public HasSingleReferenceRelation(IJPAEditorFeatureProvider fp,
+ Connection conn) {
+ super(fp, conn);
+ }
+
+ @Override
+ public HasReferenceType getReferenceType() {
+ return HasReferenceType.SINGLE;
+ }
+
+}
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/IBidirectionalRelation.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/IBidirectionalRelation.java
index cf74687..59ce5e2 100644
--- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/IBidirectionalRelation.java
+++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/IBidirectionalRelation.java
@@ -25,6 +25,6 @@ public interface IBidirectionalRelation extends IRelation {
public abstract void setOwnerAnnotatedAttribute(JavaPersistentAttribute ownerAnnotatedAttribute);
- public abstract void setInverseAnnotatedAttribute(JavaPersistentAttribute inverseAnnotatedAttribute);
+ public abstract void setInverseAnnotatedAttribute(JavaPersistentAttribute inverseAnnotatedAttribute);
} \ No newline at end of file
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/IsARelation.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/IsARelation.java
index 28da316..9654e70 100644
--- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/IsARelation.java
+++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/IsARelation.java
@@ -89,15 +89,10 @@ public class IsARelation {
startJpt.getName() + SEPARATOR + endJpt.getName();
}
- public boolean equals(Object obj) {
- if (obj == null)
+ public boolean equals(Object otherRel) {
+ if (!IsARelation.class.isInstance(otherRel))
return false;
- if (this.hashCode() != obj.hashCode())
- return false;
- if (!(obj instanceof IsARelation))
- return false;
- IsARelation rel = (IsARelation)obj;
- return this.getId().equals(rel.getId());
+ return getId().equals(((IsARelation)otherRel).getId());
}
public int hashCode() {
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/ManyToManyBiDirRelation.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/ManyToManyBiDirRelation.java
index ba1e06c..df0af0a 100644
--- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/ManyToManyBiDirRelation.java
+++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/ManyToManyBiDirRelation.java
@@ -15,7 +15,6 @@
*******************************************************************************/
package org.eclipse.jpt.jpadiagrameditor.ui.internal.relations;
-import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jpt.jpa.core.context.java.JavaPersistentAttribute;
import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.propertypage.JPADiagramPropertyPage;
@@ -30,14 +29,12 @@ public class ManyToManyBiDirRelation extends ManyToManyRelation implements IBidi
JavaPersistentType inverse,
String ownerAttributeName,
String inverseAttributeName,
- boolean createAttribs,
- ICompilationUnit ownerCU,
- ICompilationUnit inverseCU) {
+ boolean createAttribs, JavaPersistentType embeddingEntity) {
super(owner, inverse);
this.ownerAttributeName = ownerAttributeName;
this.inverseAttributeName = inverseAttributeName;
if (createAttribs)
- createRelation(fp, ownerCU, inverseCU);
+ createRelation(fp, embeddingEntity);
}
@@ -65,15 +62,20 @@ public class ManyToManyBiDirRelation extends ManyToManyRelation implements IBidi
this.inverseAnnotatedAttribute = inverseAnnotatedAttribute;
}
- private void createRelation(IJPAEditorFeatureProvider fp, ICompilationUnit ownerCU, ICompilationUnit inverseCU) {
+ private void createRelation(IJPAEditorFeatureProvider fp, JavaPersistentType embeddingEntity) {
boolean isMap = JPADiagramPropertyPage.isMapType(owner.getJpaProject().getProject());
- String mapKeyType = getMapKeyType(isMap, inverse);
- ownerAnnotatedAttribute = JPAEditorUtil.addAnnotatedAttribute(fp, owner, inverse, ownerCU, inverseCU, true, mapKeyType);
-
- mapKeyType = getMapKeyType(isMap, owner);
- inverseAnnotatedAttribute = JPAEditorUtil.addAnnotatedAttribute(fp, inverse, owner, inverseCU, ownerCU, true, mapKeyType);
+ String mapKeyType = getMapKeyType(isMap, inverse, embeddingEntity);
+ ownerAnnotatedAttribute = JPAEditorUtil.addAnnotatedAttribute(fp, owner, inverse, true, mapKeyType);
+ mapKeyType = getMapKeyType(isMap, owner, embeddingEntity);
+ if(JpaArtifactFactory.instance().hasEmbeddableAnnotation(owner)){
+// inverseAnnotatedAttribute = JpaArtifactFactory.instance().addEmbeddedAttribute(owner, inverse, mapKeyType, true, fp);
+ inverseAnnotatedAttribute = JPAEditorUtil.addAnnotatedAttribute(fp, inverse, embeddingEntity, true, mapKeyType);
+
+ } else {
+ inverseAnnotatedAttribute = JPAEditorUtil.addAnnotatedAttribute(fp, inverse, owner, true, mapKeyType);
+ }
JpaArtifactFactory.instance().addManyToManyBidirectionalRelation(fp, owner, ownerAnnotatedAttribute, inverse, inverseAnnotatedAttribute, isMap);
}
@@ -81,7 +83,10 @@ public class ManyToManyBiDirRelation extends ManyToManyRelation implements IBidi
return RelDir.BI;
}
- private String getMapKeyType(boolean isMap, JavaPersistentType jpt){
+ private String getMapKeyType(boolean isMap, JavaPersistentType jpt, JavaPersistentType embeddingEntity){
+ if(JpaArtifactFactory.instance().hasEmbeddableAnnotation(jpt) && embeddingEntity!=null){
+ return isMap ? JpaArtifactFactory.instance().getIdType(embeddingEntity) : null;
+ }
return isMap ? JpaArtifactFactory.instance().getIdType(jpt) : null;
}
} \ No newline at end of file
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/ManyToManyUniDirRelation.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/ManyToManyUniDirRelation.java
index f00027d..db27555 100644
--- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/ManyToManyUniDirRelation.java
+++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/ManyToManyUniDirRelation.java
@@ -15,7 +15,6 @@
*******************************************************************************/
package org.eclipse.jpt.jpadiagrameditor.ui.internal.relations;
-import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jpt.jpa.core.context.java.JavaPersistentAttribute;
import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.propertypage.JPADiagramPropertyPage;
@@ -29,13 +28,11 @@ public class ManyToManyUniDirRelation extends ManyToManyRelation implements IUni
public ManyToManyUniDirRelation(IJPAEditorFeatureProvider fp, JavaPersistentType owner,
JavaPersistentType inverse,
String ownerAttributeName,
- boolean createAttribs,
- ICompilationUnit ownerCU,
- ICompilationUnit inverseCU) {
+ boolean createAttribs) {
super(owner, inverse);
this.ownerAttributeName = ownerAttributeName;
if (createAttribs)
- createRelation(fp, ownerCU, inverseCU);
+ createRelation(fp);
}
public JavaPersistentAttribute getAnnotatedAttribute() {
@@ -46,10 +43,10 @@ public class ManyToManyUniDirRelation extends ManyToManyRelation implements IUni
this.ownerAnnotatedAttribute = annotatedAttribute;
}
- private void createRelation(IJPAEditorFeatureProvider fp, ICompilationUnit ownerCU, ICompilationUnit inverseCU) {
+ private void createRelation(IJPAEditorFeatureProvider fp) {
boolean isMap = JPADiagramPropertyPage.isMapType(owner.getJpaProject().getProject());
String mapKeyType = getMapKeyType(isMap, inverse);
- ownerAnnotatedAttribute = JPAEditorUtil.addAnnotatedAttribute(fp, owner, inverse, ownerCU, inverseCU, true, mapKeyType);
+ ownerAnnotatedAttribute = JPAEditorUtil.addAnnotatedAttribute(fp, owner, inverse, true, mapKeyType);
JpaArtifactFactory.instance().addManyToManyUnidirectionalRelation(fp, owner, ownerAnnotatedAttribute, isMap);
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/ManyToOneBiDirRelation.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/ManyToOneBiDirRelation.java
index 191a84c..96c025b 100644
--- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/ManyToOneBiDirRelation.java
+++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/ManyToOneBiDirRelation.java
@@ -15,7 +15,6 @@
*******************************************************************************/
package org.eclipse.jpt.jpadiagrameditor.ui.internal.relations;
-import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jpt.jpa.core.context.java.JavaPersistentAttribute;
import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.propertypage.JPADiagramPropertyPage;
@@ -30,14 +29,12 @@ public class ManyToOneBiDirRelation extends ManyToOneRelation implements IBidir
JavaPersistentType inverse,
String ownerAttributeName,
String inverseAttributeName,
- boolean createAttribs,
- ICompilationUnit ownerCU,
- ICompilationUnit inverseCU) {
+ boolean createAttribs, JavaPersistentType embeddingEntity) {
super(owner, inverse);
this.ownerAttributeName = ownerAttributeName;
this.inverseAttributeName = inverseAttributeName;
if (createAttribs)
- createRelation(fp, ownerCU, inverseCU);
+ createRelation(fp, embeddingEntity);
}
@@ -57,13 +54,18 @@ public class ManyToOneBiDirRelation extends ManyToOneRelation implements IBidir
this.inverseAnnotatedAttribute = inverseAnnotatedAttribute;
}
- private void createRelation(IJPAEditorFeatureProvider fp, ICompilationUnit ownerCU, ICompilationUnit inverseCU) {
- ownerAnnotatedAttribute = JPAEditorUtil.addAnnotatedAttribute(fp, owner, inverse, ownerCU, inverseCU, false, null);
+ private void createRelation(IJPAEditorFeatureProvider fp, JavaPersistentType embeddingEntity) {
+ ownerAnnotatedAttribute = JPAEditorUtil.addAnnotatedAttribute(fp, owner, inverse, false, null);
boolean isMap = JPADiagramPropertyPage.isMapType(owner.getJpaProject().getProject());
- String mapKeyType = getMapKeyType(isMap, owner);
- inverseAnnotatedAttribute = JPAEditorUtil.addAnnotatedAttribute(fp, inverse, owner, inverseCU, ownerCU, true, mapKeyType);
-
+ String mapKeyType = getMapKeyType(isMap, owner, embeddingEntity);
+ if(JpaArtifactFactory.instance().hasEmbeddableAnnotation(owner)){
+// inverseAnnotatedAttribute = JpaArtifactFactory.instance().addEmbeddedAttribute(owner, inverse, mapKeyType, true, fp);
+ inverseAnnotatedAttribute = JPAEditorUtil.addAnnotatedAttribute(fp, inverse, embeddingEntity, true, mapKeyType);
+
+ } else {
+ inverseAnnotatedAttribute = JPAEditorUtil.addAnnotatedAttribute(fp, inverse, owner, true, mapKeyType);
+ }
JpaArtifactFactory.instance().addManyToOneBidirectionalRelation(fp, owner, ownerAnnotatedAttribute, inverse, inverseAnnotatedAttribute, isMap);
}
@@ -71,7 +73,10 @@ public class ManyToOneBiDirRelation extends ManyToOneRelation implements IBidir
return RelDir.BI;
}
- private String getMapKeyType(boolean isMap, JavaPersistentType jpt){
+ private String getMapKeyType(boolean isMap, JavaPersistentType jpt, JavaPersistentType embeddingEntity){
+ if(JpaArtifactFactory.instance().hasEmbeddableAnnotation(jpt) && embeddingEntity!=null){
+ return isMap ? JpaArtifactFactory.instance().getIdType(embeddingEntity) : null;
+ }
return isMap ? JpaArtifactFactory.instance().getIdType(jpt) : null;
- }
+ }
} \ No newline at end of file
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/ManyToOneUniDirRelation.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/ManyToOneUniDirRelation.java
index 98aca30..fcbbd72 100644
--- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/ManyToOneUniDirRelation.java
+++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/ManyToOneUniDirRelation.java
@@ -15,7 +15,6 @@
*******************************************************************************/
package org.eclipse.jpt.jpadiagrameditor.ui.internal.relations;
-import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jpt.jpa.core.context.java.JavaPersistentAttribute;
import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.IJPAEditorFeatureProvider;
@@ -28,13 +27,11 @@ public class ManyToOneUniDirRelation extends ManyToOneRelation implements IUnidi
public ManyToOneUniDirRelation(IJPAEditorFeatureProvider fp, JavaPersistentType owner,
JavaPersistentType inverse,
String ownerAttributeName,
- boolean createAttribs,
- ICompilationUnit ownerCU,
- ICompilationUnit inverseCU) {
+ boolean createAttribs) {
super(owner, inverse);
this.ownerAttributeName = ownerAttributeName;
if (createAttribs)
- createRelation(fp, ownerCU, inverseCU);
+ createRelation(fp);
}
public JavaPersistentAttribute getAnnotatedAttribute() {
@@ -45,8 +42,8 @@ public class ManyToOneUniDirRelation extends ManyToOneRelation implements IUnidi
this.ownerAnnotatedAttribute = annotatedAttribute;
}
- private void createRelation(IJPAEditorFeatureProvider fp, ICompilationUnit ownerCU, ICompilationUnit inverseCU) {
- ownerAnnotatedAttribute = JPAEditorUtil.addAnnotatedAttribute(fp, owner, inverse, ownerCU, inverseCU, false, null);
+ private void createRelation(IJPAEditorFeatureProvider fp) {
+ ownerAnnotatedAttribute = JPAEditorUtil.addAnnotatedAttribute(fp, owner, inverse, false, null);
JpaArtifactFactory.instance().addManyToOneUnidirectionalRelation(fp, owner, ownerAnnotatedAttribute);
}
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/OneToManyUniDirRelation.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/OneToManyUniDirRelation.java
index a153b4d..e5c5da8 100644
--- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/OneToManyUniDirRelation.java
+++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/OneToManyUniDirRelation.java
@@ -15,7 +15,6 @@
*******************************************************************************/
package org.eclipse.jpt.jpadiagrameditor.ui.internal.relations;
-import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jpt.jpa.core.context.java.JavaPersistentAttribute;
import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.propertypage.JPADiagramPropertyPage;
@@ -29,13 +28,11 @@ public class OneToManyUniDirRelation extends OneToManyRelation implements IUnidi
public OneToManyUniDirRelation(IJPAEditorFeatureProvider fp, JavaPersistentType owner,
JavaPersistentType inverse,
String ownerAttributeName,
- boolean createAttribs,
- ICompilationUnit ownerCU,
- ICompilationUnit inverseCU) {
+ boolean createAttribs) {
super(owner, inverse);
this.ownerAttributeName = ownerAttributeName;
if (createAttribs)
- createRelation(fp, ownerCU, inverseCU);
+ createRelation(fp);
}
public JavaPersistentAttribute getAnnotatedAttribute() {
@@ -46,10 +43,10 @@ public class OneToManyUniDirRelation extends OneToManyRelation implements IUnidi
this.ownerAnnotatedAttribute = annotatedAttribute;
}
- private void createRelation(IJPAEditorFeatureProvider fp, ICompilationUnit ownerCU, ICompilationUnit inverseCU) {
+ private void createRelation(IJPAEditorFeatureProvider fp) {
boolean isMap = JPADiagramPropertyPage.isMapType(owner.getJpaProject().getProject());
String mapKeyType = getMapKeyType(isMap, inverse);
- ownerAnnotatedAttribute = JPAEditorUtil.addAnnotatedAttribute(fp, owner, inverse, ownerCU, inverseCU, true, mapKeyType);
+ ownerAnnotatedAttribute = JPAEditorUtil.addAnnotatedAttribute(fp, owner, inverse, true, mapKeyType);
JpaArtifactFactory.instance().addOneToManyUnidirectionalRelation(fp, owner, ownerAnnotatedAttribute, isMap);
}
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/OneToOneBiDirRelation.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/OneToOneBiDirRelation.java
index 3466b89..8784131 100644
--- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/OneToOneBiDirRelation.java
+++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/OneToOneBiDirRelation.java
@@ -15,7 +15,6 @@
*******************************************************************************/
package org.eclipse.jpt.jpadiagrameditor.ui.internal.relations;
-import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jpt.jpa.core.context.java.JavaPersistentAttribute;
import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.IJPAEditorFeatureProvider;
@@ -28,14 +27,12 @@ public class OneToOneBiDirRelation extends OneToOneRelation implements IBidirect
JavaPersistentType inverse,
String ownerAttributeName,
String inverseAttributeName,
- boolean createAttribs,
- ICompilationUnit ownerCU,
- ICompilationUnit inverseCU) {
+ boolean createAttribs, JavaPersistentType embeddingEntity) {
super(owner, inverse);
this.ownerAttributeName = ownerAttributeName;
this.inverseAttributeName = inverseAttributeName;
if (createAttribs)
- createRelation(fp, ownerCU, inverseCU);
+ createRelation(fp, embeddingEntity);
}
public JavaPersistentAttribute getOwnerAnnotatedAttribute() {
@@ -56,15 +53,19 @@ public class OneToOneBiDirRelation extends OneToOneRelation implements IBidirect
this.inverseAnnotatedAttribute = inverseAnnotatedAttribute;
}
- private void createRelation(IJPAEditorFeatureProvider fp, ICompilationUnit ownerCU, ICompilationUnit inverseCU) {
- ownerAnnotatedAttribute = JPAEditorUtil.addAnnotatedAttribute(fp, owner, inverse, ownerCU, inverseCU, false, null);
- inverseAnnotatedAttribute = JPAEditorUtil.addAnnotatedAttribute(fp, inverse, owner, inverseCU, ownerCU, false, null);
+ private void createRelation(IJPAEditorFeatureProvider fp, JavaPersistentType embeddingEntity) {
+ ownerAnnotatedAttribute = JPAEditorUtil.addAnnotatedAttribute(fp, owner, inverse, false, null);
+ if(JpaArtifactFactory.instance().hasEmbeddableAnnotation(owner)){
+// inverseAnnotatedAttribute = JpaArtifactFactory.instance().addEmbeddedAttribute(owner, inverse, null, false, fp);
+ inverseAnnotatedAttribute = JPAEditorUtil.addAnnotatedAttribute(fp, inverse, embeddingEntity, false, null);
+ } else {
+ inverseAnnotatedAttribute = JPAEditorUtil.addAnnotatedAttribute(fp, inverse, owner, false, null);
+ }
JpaArtifactFactory.instance().addOneToOneBidirectionalRelation(fp, owner, ownerAnnotatedAttribute, inverse, inverseAnnotatedAttribute);
}
public RelDir getRelDir() {
return RelDir.BI;
- }
-
+ }
} \ No newline at end of file
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/OneToOneUniDirRelation.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/OneToOneUniDirRelation.java
index e262d9d..b7a4fac 100644
--- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/OneToOneUniDirRelation.java
+++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/OneToOneUniDirRelation.java
@@ -15,7 +15,6 @@
*******************************************************************************/
package org.eclipse.jpt.jpadiagrameditor.ui.internal.relations;
-import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jpt.jpa.core.context.java.JavaPersistentAttribute;
import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.IJPAEditorFeatureProvider;
@@ -28,13 +27,11 @@ public class OneToOneUniDirRelation extends OneToOneRelation implements IUnidire
public OneToOneUniDirRelation(IJPAEditorFeatureProvider fp, JavaPersistentType owner,
JavaPersistentType inverse,
String ownerAttributeName,
- boolean createAttribs,
- ICompilationUnit ownerCU,
- ICompilationUnit inverseCU) {
+ boolean createAttribs) {
super(owner, inverse);
this.ownerAttributeName = ownerAttributeName;
if (createAttribs)
- createRelation(fp, ownerCU, inverseCU);
+ createRelation(fp);
}
public JavaPersistentAttribute getAnnotatedAttribute() {
@@ -45,8 +42,8 @@ public class OneToOneUniDirRelation extends OneToOneRelation implements IUnidire
this.ownerAnnotatedAttribute = annotatedAttribute;
}
- private void createRelation(IJPAEditorFeatureProvider fp, ICompilationUnit ownerCU, ICompilationUnit inverseCU) {
- ownerAnnotatedAttribute = JPAEditorUtil.addAnnotatedAttribute(fp, owner, inverse, ownerCU, inverseCU, false, null);
+ private void createRelation(IJPAEditorFeatureProvider fp) {
+ ownerAnnotatedAttribute = JPAEditorUtil.addAnnotatedAttribute(fp, owner, inverse, false, null);
JpaArtifactFactory.instance().addOneToOneUnidirectionalRelation(fp, owner, ownerAnnotatedAttribute);
}
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/EntityChangeListener.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/EntityChangeListener.java
index 7d49567..dd853cc 100644
--- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/EntityChangeListener.java
+++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/EntityChangeListener.java
@@ -15,32 +15,17 @@
*******************************************************************************/
package org.eclipse.jpt.jpadiagrameditor.ui.internal.util;
-import java.io.ObjectInputStream.GetField;
-import java.lang.reflect.InvocationTargetException;
import java.util.Collection;
import java.util.HashSet;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.Set;
-import org.eclipse.emf.common.notify.Adapter;
-import org.eclipse.emf.common.notify.Notification;
-import org.eclipse.emf.common.util.EList;
-import org.eclipse.emf.common.util.TreeIterator;
-import org.eclipse.emf.ecore.EClass;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.EOperation;
-import org.eclipse.emf.ecore.EReference;
-import org.eclipse.emf.ecore.EStructuralFeature;
-import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.graphiti.features.context.impl.RemoveContext;
-import org.eclipse.graphiti.mm.Property;
-import org.eclipse.graphiti.mm.algorithms.GraphicsAlgorithm;
import org.eclipse.graphiti.mm.pictograms.ContainerShape;
-import org.eclipse.graphiti.mm.pictograms.PictogramElement;
-import org.eclipse.graphiti.mm.pictograms.PictogramLink;
import org.eclipse.jpt.jpa.core.JpaPreferences;
import org.eclipse.jpt.jpa.core.context.MappedByRelationship;
+import org.eclipse.jpt.jpa.core.context.MappedByRelationshipStrategy;
import org.eclipse.jpt.jpa.core.context.PersistentType;
import org.eclipse.jpt.jpa.core.context.java.JavaAttributeMapping;
import org.eclipse.jpt.jpa.core.context.java.JavaPersistentAttribute;
@@ -50,6 +35,7 @@ import org.eclipse.jpt.jpa.core.context.persistence.PersistenceUnit;
import org.eclipse.jpt.jpa.core.internal.context.java.JavaNullTypeMapping;
import org.eclipse.jpt.jpa.core.resource.java.OwnableRelationshipMappingAnnotation;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.JPADiagramEditorPlugin;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.command.SetMappedByNewValueCommand;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.feature.RemoveAndSaveEntityFeature;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.IJPAEditorFeatureProvider;
import org.eclipse.swt.widgets.Display;
@@ -136,7 +122,7 @@ public class EntityChangeListener extends Thread {
PersistenceUnit pu = JpaArtifactFactory.instance().getPersistenceUnit(jpt);
PersistentType pt = pu.getPersistentType(jpt.getName());
- if ((pt == null) || !JpaArtifactFactory.instance().hasEntityOrMappedSuperclassAnnotation(jpt)) {
+ if ((pt == null) || !JpaArtifactFactory.instance().hasAnyAnnotationType(jpt)) {
JpaArtifactFactory.instance().forceSaveEntityClass(jpt, featureProvider);
@@ -163,6 +149,7 @@ public class EntityChangeListener extends Thread {
String entityName = jptAndAttrib[0];
String attribName = jptAndAttrib[1];
String mappedBy = jptAndAttrib[2];
+ String oldMappedBy = jptAndAttrib[3];
JavaPersistentType jpt = (JavaPersistentType)pu.getPersistentType(entityName);
if (jpt != null) {
JavaPersistentAttribute jpa = jpt.getAttributeNamed(attribName);
@@ -174,7 +161,31 @@ public class EntityChangeListener extends Thread {
if (!ownableRef.strategyIsMappedBy()) {
ownableRef.setStrategyToMappedBy();
}
- ownableRef.getMappedByStrategy().setMappedByAttribute(mappedBy);
+ MappedByRelationshipStrategy mappedByStrategy = ownableRef.getMappedByStrategy();
+ String mappedByAttr = mappedByStrategy.getMappedByAttribute();
+
+ String[] mappedByAttrs = mappedByAttr.split("\\."); //$NON-NLS-1$
+ if(mappedByAttrs.length > 1){
+ if(mappedByAttrs[0].equals(oldMappedBy)){
+ mappedByAttr = mappedBy + "." + mappedByAttrs[1]; //$NON-NLS-1$
+ } else if(mappedByAttrs[1].equals(oldMappedBy)){
+ mappedByAttr = mappedByAttrs[0] + "." + mappedBy; //$NON-NLS-1$
+ }
+ } else {
+ mappedByAttr = mappedBy;
+ }
+ mappedByStrategy.setMappedByAttribute(mappedByAttr);
+
+
+// if(mappedByAttrs.length > 1){
+// if(mappedByAttrs[0].equals(oldAt.getName())){
+// mappedBy = newAt.getName() + "." + mappedByAttrs[1];
+// } else if(mappedByAttrs[1].equals(oldAt.getName())){
+// mappedBy = mappedByAttrs[0] + "." + newAt.getName();
+// }
+// } else {
+// mappedBy = newAt.getName();
+ jpt.update();
attribsToUpdate.remove(jptAtMB);
}
}
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/IJPAEditorPredefinedRenderingStyle.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/IJPAEditorPredefinedRenderingStyle.java
index 9a4538b..d38ac35 100644
--- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/IJPAEditorPredefinedRenderingStyle.java
+++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/IJPAEditorPredefinedRenderingStyle.java
@@ -24,4 +24,9 @@ public interface IJPAEditorPredefinedRenderingStyle extends IPredefinedRendering
*/
public static final String GREEN_WHITE_GLOSS_ID = "green-white-gloss"; //$NON-NLS-1$
+ /**
+ * The ID for a violet-to-white gradient with a gloss-effect.
+ */
+ public static final String VIOLET_WHITE_GLOSS_ID = "violet-white-gloss"; //$NON-NLS-1$
+
}
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/IJPAEditorUtil.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/IJPAEditorUtil.java
index c781948..e0b5f3d 100644
--- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/IJPAEditorUtil.java
+++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/IJPAEditorUtil.java
@@ -18,32 +18,21 @@ package org.eclipse.jpt.jpadiagrameditor.ui.internal.util;
import java.util.List;
import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject;
-import org.eclipse.graphiti.mm.pictograms.ConnectionDecorator;
import org.eclipse.graphiti.mm.pictograms.FreeFormConnection;
import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jpt.jpa.core.JpaProject;
import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.IJPAEditorFeatureProvider;
-import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.IJPAEditorImageCreator.RelEndDir;
import org.eclipse.swt.graphics.Point;
import org.eclipse.ui.IWorkbenchSite;
public interface IJPAEditorUtil {
-
- public List<Point> createBendPointList(FreeFormConnection c, int cnt, int connectionsNum, boolean selfRelation);
-
+
public List<Point> createBendPointList(FreeFormConnection c, boolean selfRelation);
- public int calcConnectionLength(FreeFormConnection c);
-
- public RelEndDir getConnectionStartDir(FreeFormConnection c);
-
- public RelEndDir getConnectionEndDir(FreeFormConnection c);
-
public JavaPersistentType getJPType(ICompilationUnit cu);
public void organizeImports(ICompilationUnit cu, IWorkbenchSite ws);
@@ -52,12 +41,8 @@ public interface IJPAEditorUtil {
public void formatCode(ICompilationUnit cu, IWorkbenchSite ws);
- public String generateUniqueEntityName(JpaProject jpaProject,
- String pack,
- IJPAEditorFeatureProvider fp);
-
- public String generateUniqueMappedSuperclassName(JpaProject jpaProject,
- String pack, IJPAEditorFeatureProvider fp);
+ public String generateUniqueTypeName(JpaProject jpaProject,
+ String pack, String objectTypeName, IJPAEditorFeatureProvider fp);
public IFile createEntityInProject(IProject project,
String entityName,
@@ -72,17 +57,11 @@ public interface IJPAEditorUtil {
String entityName,
JavaPersistentType mappedSuperclass) throws Exception;
-
- public IFile createEntityFromMappedSuperclassInProject(IProject project,
- String mappedSuperclassName, IPreferenceStore jpaPreferenceStore) throws Exception;
-
- public IFile createMappedSuperclassInProject(IProject project,
- IFolder folder, String mappedSuperclassName) throws Exception;
-
public IFile createMappedSuperclassInProject(IProject project,
- String mappedSuperclassName) throws Exception;
+ String mappedSuperclassName) throws Exception;
- public boolean isCardinalityDecorator(ConnectionDecorator cd);
+ public IFile createEmbeddableInProject(IProject project,
+ String embeddableName) throws Exception;
public void discardWorkingCopyOnce(ICompilationUnit cu);
}
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/JPAEditorConstants.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/JPAEditorConstants.java
index 6264d09..dca88e1 100644
--- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/JPAEditorConstants.java
+++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/JPAEditorConstants.java
@@ -22,16 +22,20 @@ import java.util.Set;
import org.eclipse.graphiti.util.ColorConstant;
import org.eclipse.graphiti.util.IColorConstant;
import org.eclipse.jpt.jpa.core.MappingKeys;
+import org.eclipse.jpt.jpa.core.jpa2.MappingKeys2_0;
public class JPAEditorConstants {
public static enum DIAGRAM_OBJECT_TYPE {
Entity,
- MappedSupeclass
+ MappedSupeclass,
+ Embeddable
};
public static final String IS_A_RELATION_ID_PREFIX = "is_a_relation:"; //$NON-NLS-1$
+ public static final String HAS_REFERENCE_RELATION_ID_PREFIX = "has_reference_relation:"; //$NON-NLS-1$
+
public static final String IS_A = "is-a"; //$NON-NLS-1$
public static final String HEADER_PREFIX_DIRTY = "* "; //$NON-NLS-1$
@@ -59,25 +63,41 @@ public class JPAEditorConstants {
public static final IColorConstant ENTITY_BACKGROUND =
new ColorConstant(212, 231, 248);
+ public static final IColorConstant ENTITY_DISABLED_COLOR =
+ new ColorConstant(192, 192, 192);
+
public static final IColorConstant MAPPED_SUPERCLASS_BACKGROUND =
new ColorConstant(212, 248, 231);
+
+ public static final IColorConstant EMBEDDABLE_BACKGROUND =
+ new ColorConstant(231, 227, 227);
public static final IColorConstant CONNECTION_LINE_COLOR =
new ColorConstant(98, 131,167);
public static final IColorConstant IS_A_CONNECTION_LINE_COLOR =
- new ColorConstant(98, 167, 131);
+ new ColorConstant(98, 167, 131);
+
+ public static final IColorConstant IS_A_ARROW_COLOR =
+ new ColorConstant(255, 255, 255);
+
+ public static final IColorConstant EMBEDDED_CONNECTION_LINE_COLOR =
+ new ColorConstant(122, 78, 120);
public static final IColorConstant ENTITY_BORDER_COLOR =
new ColorConstant(98, 131,167);
public static final IColorConstant MAPPED_SUPERCLASS_BORDER_COLOR =
- new ColorConstant(98, 167, 131);
+ new ColorConstant(98, 167, 131);
+
+ public static final IColorConstant EMBEDDABLE_BORDER_COLOR =
+ new ColorConstant(157, 103, 154);
public final static String TRUE_STRING = Boolean.toString(true);
public final static int CONNECTION_LINE_WIDTH = 2;
public final static int IS_A_CONNECTION_LINE_WIDTH = 2;
+ public final static int EMBEDDED_CONNECTION_LINE_WIDTH = 2;
public final static int ENTITY_BORDER_WIDTH = 2;
@@ -125,6 +145,7 @@ public class JPAEditorConstants {
public final static String ANNOTATION_MANY_TO_MANY = "ManyToMany"; //$NON-NLS-1$
public final static String ANNOTATION_VERSION = "Version"; //$NON-NLS-1$
public final static String ANNOTATION_EMBEDDED = "Embedded"; //$NON-NLS-1$
+ public final static String ANNOTATION_ELEMENT_COLLECTION = "ElementCollection"; //$NON-NLS-1$
public final static String ANNOTATION_EMBEDDED_ID = "EmbeddedId"; //$NON-NLS-1$
public final static String ANNOTATION_TRANSIENT = "Transient"; //$NON-NLS-1$
@@ -164,6 +185,7 @@ public class JPAEditorConstants {
ANNOTATION_NAME_TO_KEY.put(ANNOTATION_MANY_TO_MANY, MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY);
ANNOTATION_NAME_TO_KEY.put(ANNOTATION_VERSION, MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY);
ANNOTATION_NAME_TO_KEY.put(ANNOTATION_EMBEDDED, MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY);
+ ANNOTATION_NAME_TO_KEY.put(ANNOTATION_ELEMENT_COLLECTION, MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY);
ANNOTATION_NAME_TO_KEY.put(ANNOTATION_EMBEDDED_ID, MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY);
ANNOTATION_NAME_TO_KEY.put(ANNOTATION_TRANSIENT, MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY);
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/JPAEditorPredefinedColoredAreas.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/JPAEditorPredefinedColoredAreas.java
index 2e90359..1038671 100644
--- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/JPAEditorPredefinedColoredAreas.java
+++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/JPAEditorPredefinedColoredAreas.java
@@ -49,6 +49,28 @@ public class JPAEditorPredefinedColoredAreas extends PredefinedColoredAreas
gradientColoredAreas.setStyleAdaption(IPredefinedRenderingStyle.STYLE_ADAPTATION_DEFAULT);
return gradientColoredAreas;
}
+
+ /**
+ * The color-areas, which are used for default elements with the ID
+ * {@link #VIOLET_WHITE_GLOSS_ID}.
+ */
+ private static GradientColoredAreas getVioletWhiteGlossDefaultAreas() {
+ final GradientColoredAreas gradientColoredAreas = StylesFactory.eINSTANCE.createGradientColoredAreas();
+ final EList<GradientColoredArea> gcas = gradientColoredAreas.getGradientColor();
+
+ addGradientColoredArea(gcas, "F5F0F5", 0, LocationType.LOCATION_TYPE_ABSOLUTE_START, "F5F0F5", 1, //$NON-NLS-1$ //$NON-NLS-2$
+ LocationType.LOCATION_TYPE_ABSOLUTE_START);
+ addGradientColoredArea(gcas, "F1EBF5", 1, LocationType.LOCATION_TYPE_ABSOLUTE_START, "F1EBF5", 2, //$NON-NLS-1$ //$NON-NLS-2$
+ LocationType.LOCATION_TYPE_ABSOLUTE_START);
+ addGradientColoredArea(gcas, "E6DAEE", 2, LocationType.LOCATION_TYPE_ABSOLUTE_START, "E6DAEE", 3, //$NON-NLS-1$ //$NON-NLS-2$
+ LocationType.LOCATION_TYPE_ABSOLUTE_START);
+ addGradientColoredArea(gcas, "E4D8EC", 3, LocationType.LOCATION_TYPE_ABSOLUTE_START, "FAFCFB", 2, //$NON-NLS-1$ //$NON-NLS-2$
+ LocationType.LOCATION_TYPE_ABSOLUTE_END);
+ addGradientColoredArea(gcas, "DADAEB", 2, LocationType.LOCATION_TYPE_ABSOLUTE_END, "DADAEB", 0, //$NON-NLS-1$ //$NON-NLS-2$
+ LocationType.LOCATION_TYPE_ABSOLUTE_END);
+ gradientColoredAreas.setStyleAdaption(IPredefinedRenderingStyle.STYLE_ADAPTATION_DEFAULT);
+ return gradientColoredAreas;
+ }
/**
* The color-areas, which are used for primary selected elements with the ID
@@ -71,10 +93,33 @@ public class JPAEditorPredefinedColoredAreas extends PredefinedColoredAreas
LocationType.LOCATION_TYPE_ABSOLUTE_END);
return gradientColoredAreas;
}
+
+ /**
+ * The color-areas, which are used for primary selected elements with the ID
+ * {@link #GREEN_WHITE_GLOSS_ID}.
+ */
+ private static GradientColoredAreas getVioletWhiteGlossPrimarySelectedAreas() {
+ final GradientColoredAreas gradientColoredAreas = StylesFactory.eINSTANCE.createGradientColoredAreas();
+ gradientColoredAreas.setStyleAdaption(IPredefinedRenderingStyle.STYLE_ADAPTATION_PRIMARY_SELECTED);
+ final EList<GradientColoredArea> gcas = gradientColoredAreas.getGradientColor();
+
+ addGradientColoredArea(gcas, "EEEAF1", 0, LocationType.LOCATION_TYPE_ABSOLUTE_START, "EEEAF1", 1, //$NON-NLS-1$ //$NON-NLS-2$
+ LocationType.LOCATION_TYPE_ABSOLUTE_START);
+ addGradientColoredArea(gcas, "CDB8DE", 1, LocationType.LOCATION_TYPE_ABSOLUTE_START, "CDB8DE", 2, //$NON-NLS-1$ //$NON-NLS-2$
+ LocationType.LOCATION_TYPE_ABSOLUTE_START);
+ addGradientColoredArea(gcas, "C2A9D7", 2, LocationType.LOCATION_TYPE_ABSOLUTE_START, "C2A9D7", 3, //$NON-NLS-1$ //$NON-NLS-2$
+ LocationType.LOCATION_TYPE_ABSOLUTE_START);
+ addGradientColoredArea(gcas, "BA9ED2", 3, LocationType.LOCATION_TYPE_ABSOLUTE_START, "CAB5DD", 2, //$NON-NLS-1$ //$NON-NLS-2$
+ LocationType.LOCATION_TYPE_ABSOLUTE_END);
+ addGradientColoredArea(gcas, "CEBAE0", 2, LocationType.LOCATION_TYPE_ABSOLUTE_END, "CEBAE0", 0, //$NON-NLS-1$ //$NON-NLS-2$
+ LocationType.LOCATION_TYPE_ABSOLUTE_END);
+
+ return gradientColoredAreas;
+ }
/**
* The color-areas, which are used for secondary selected elements with the
- * ID {@link #GREEN_WHITE_GLOSS_ID}.
+ * ID {@link #VIOLET_WHITE_GLOSS_ID}.
*/
private static GradientColoredAreas getGreenWhiteGlossSecondarySelectedAreas() {
final GradientColoredAreas gradientColoredAreas = StylesFactory.eINSTANCE.createGradientColoredAreas();
@@ -91,14 +136,38 @@ public class JPAEditorPredefinedColoredAreas extends PredefinedColoredAreas
LocationType.LOCATION_TYPE_ABSOLUTE_END);
addGradientColoredArea(gcas, "B2E5CD", 2, LocationType.LOCATION_TYPE_ABSOLUTE_END, "B2E5CD", 0, //$NON-NLS-1$ //$NON-NLS-2$
LocationType.LOCATION_TYPE_ABSOLUTE_END);
+
+ return gradientColoredAreas;
+ }
+
+ /**
+ * The color-areas, which are used for secondary selected elements with the
+ * ID {@link #VIOLET_WHITE_GLOSS_ID}.
+ */
+ private static GradientColoredAreas getVioletWhiteGlossSecondarySelectedAreas() {
+ final GradientColoredAreas gradientColoredAreas = StylesFactory.eINSTANCE.createGradientColoredAreas();
+ gradientColoredAreas.setStyleAdaption(IPredefinedRenderingStyle.STYLE_ADAPTATION_SECONDARY_SELECTED);
+ final EList<GradientColoredArea> gcas = gradientColoredAreas.getGradientColor();
+
+ addGradientColoredArea(gcas, "EEEAF1", 0, LocationType.LOCATION_TYPE_ABSOLUTE_START, "EEEAF1", 1, //$NON-NLS-1$ //$NON-NLS-2$
+ LocationType.LOCATION_TYPE_ABSOLUTE_START);
+ addGradientColoredArea(gcas, "DCCEE8", 1, LocationType.LOCATION_TYPE_ABSOLUTE_START, "DCCEE8", 2, //$NON-NLS-1$ //$NON-NLS-2$
+ LocationType.LOCATION_TYPE_ABSOLUTE_START);
+ addGradientColoredArea(gcas, "E1CEEB", 2, LocationType.LOCATION_TYPE_ABSOLUTE_START, "E1CEEB", 3, //$NON-NLS-1$ //$NON-NLS-2$
+ LocationType.LOCATION_TYPE_ABSOLUTE_START);
+ addGradientColoredArea(gcas, "E0CEE8", 3, LocationType.LOCATION_TYPE_ABSOLUTE_START, "E0D2E8", 2, //$NON-NLS-1$ //$NON-NLS-2$
+ LocationType.LOCATION_TYPE_ABSOLUTE_END);
+ addGradientColoredArea(gcas, "D8C8E6", 2, LocationType.LOCATION_TYPE_ABSOLUTE_END, "D8C8E6", 0, //$NON-NLS-1$ //$NON-NLS-2$
+ LocationType.LOCATION_TYPE_ABSOLUTE_END);
+
return gradientColoredAreas;
}
/**
* The color-areas, which are used for elements where an action is allowed
- * with the ID {@link #GREEN_WHITE_GLOSS_ID}.
+ * with the ID {@link #GREEN_WHITE_GLOSS_ID} or {@link #VIOLET_WHITE_GLOSS_ID}.
*/
- private static GradientColoredAreas getGreeenWhiteGlossActionAllowedAreas() {
+ private static GradientColoredAreas getWhiteGlossActionAllowedAreas() {
final GradientColoredAreas gradientColoredAreas = StylesFactory.eINSTANCE.createGradientColoredAreas();
gradientColoredAreas.setStyleAdaption(IPredefinedRenderingStyle.STYLE_ADAPTATION_ACTION_ALLOWED);
final EList<GradientColoredArea> gcas = gradientColoredAreas.getGradientColor();
@@ -110,9 +179,9 @@ public class JPAEditorPredefinedColoredAreas extends PredefinedColoredAreas
/**
* The color-areas, which are used for elements where an action is forbidden
- * with the ID {@link #GREEN_WHITE_GLOSS_ID}.
+ * with the ID {@link #GREEN_WHITE_GLOSS_ID} or {@link #VIOLET_WHITE_GLOSS_ID}.
*/
- private static GradientColoredAreas getGreenWhiteGlossActionForbiddenAreas() {
+ private static GradientColoredAreas getWhiteGlossActionForbiddenAreas() {
final GradientColoredAreas gradientColoredAreas = StylesFactory.eINSTANCE.createGradientColoredAreas();
gradientColoredAreas.setStyleAdaption(IPredefinedRenderingStyle.STYLE_ADAPTATION_ACTION_FORBIDDEN);
final EList<GradientColoredArea> gcas = gradientColoredAreas.getGradientColor();
@@ -120,8 +189,7 @@ public class JPAEditorPredefinedColoredAreas extends PredefinedColoredAreas
addGradientColoredArea(gcas, "FF00CC", 0, LocationType.LOCATION_TYPE_ABSOLUTE_START, "FF0066", 0, //$NON-NLS-1$ //$NON-NLS-2$
LocationType.LOCATION_TYPE_ABSOLUTE_END);
return gradientColoredAreas;
- }
-
+ }
public static AdaptedGradientColoredAreas getGreenWhiteGlossAdaptions() {
final AdaptedGradientColoredAreas agca = StylesFactory.eINSTANCE.createAdaptedGradientColoredAreas();
@@ -133,9 +201,25 @@ public class JPAEditorPredefinedColoredAreas extends PredefinedColoredAreas
agca.getAdaptedGradientColoredAreas().add(IPredefinedRenderingStyle.STYLE_ADAPTATION_SECONDARY_SELECTED,
getGreenWhiteGlossSecondarySelectedAreas());
agca.getAdaptedGradientColoredAreas().add(IPredefinedRenderingStyle.STYLE_ADAPTATION_ACTION_ALLOWED,
- getGreeenWhiteGlossActionAllowedAreas());
+ getWhiteGlossActionAllowedAreas());
+ agca.getAdaptedGradientColoredAreas().add(IPredefinedRenderingStyle.STYLE_ADAPTATION_ACTION_FORBIDDEN,
+ getWhiteGlossActionForbiddenAreas());
+ return agca;
+ }
+
+ public static AdaptedGradientColoredAreas getVioletWhiteGlossAdaptions() {
+ final AdaptedGradientColoredAreas agca = StylesFactory.eINSTANCE.createAdaptedGradientColoredAreas();
+ agca.setDefinedStyleId(VIOLET_WHITE_GLOSS_ID);
+ agca.setGradientType(IGradientType.VERTICAL);
+ agca.getAdaptedGradientColoredAreas().add(IPredefinedRenderingStyle.STYLE_ADAPTATION_DEFAULT, getVioletWhiteGlossDefaultAreas());
+ agca.getAdaptedGradientColoredAreas().add(IPredefinedRenderingStyle.STYLE_ADAPTATION_PRIMARY_SELECTED,
+ getVioletWhiteGlossPrimarySelectedAreas());
+ agca.getAdaptedGradientColoredAreas().add(IPredefinedRenderingStyle.STYLE_ADAPTATION_SECONDARY_SELECTED,
+ getVioletWhiteGlossSecondarySelectedAreas());
+ agca.getAdaptedGradientColoredAreas().add(IPredefinedRenderingStyle.STYLE_ADAPTATION_ACTION_ALLOWED,
+ getWhiteGlossActionAllowedAreas());
agca.getAdaptedGradientColoredAreas().add(IPredefinedRenderingStyle.STYLE_ADAPTATION_ACTION_FORBIDDEN,
- getGreenWhiteGlossActionForbiddenAreas());
+ getWhiteGlossActionForbiddenAreas());
return agca;
}
@@ -143,8 +227,12 @@ public class JPAEditorPredefinedColoredAreas extends PredefinedColoredAreas
AdaptedGradientColoredAreas res = PredefinedColoredAreas.getAdaptedGradientColoredAreas(id);
if (res != null)
return res;
- if (GREEN_WHITE_GLOSS_ID.equals(id))
+ if (GREEN_WHITE_GLOSS_ID.equals(id)) {
return getGreenWhiteGlossAdaptions();
+ } else if (VIOLET_WHITE_GLOSS_ID.equals(id)){
+ return getVioletWhiteGlossAdaptions();
+ }
+
return null;
}
}
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/JPAEditorUtil.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/JPAEditorUtil.java
index 16b9e13..b8cb3be 100644
--- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/JPAEditorUtil.java
+++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/JPAEditorUtil.java
@@ -34,6 +34,7 @@ import java.util.Properties;
import java.util.Set;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
+
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject;
@@ -95,7 +96,9 @@ import org.eclipse.jpt.jpadiagrameditor.ui.internal.propertypage.JPADiagramPrope
import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.IJPAEditorFeatureProvider;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.IJPAEditorImageCreator.RelEndDir;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.JPAEditorImageProvider;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.HasReferanceRelation;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.IRelation;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.IsARelation;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JPAEditorConstants.ShapeType;
import org.eclipse.swt.graphics.Point;
import org.eclipse.ui.IEditorInput;
@@ -112,6 +115,7 @@ import org.eclipse.wst.common.project.facet.core.ProjectFacetsManager;
@SuppressWarnings("restriction")
public class JPAEditorUtil {
+ public static final String JPA_PROJECT_FACET_10 = "1.0"; //$NON-NLS-1$
private static IPeServiceUtil peUtil = null;
private final static String PERSISTENCE_PROVIDER_LIBRARY_STRING = "javax/persistence/"; //$NON-NLS-1$
@@ -143,20 +147,7 @@ public class JPAEditorUtil {
return peUtil;
}
- public static boolean equalsIgnoreFirstLetterCase(String s1, String s2) {
- if ((s1 == null) && (s2 == null))
- return true;
- if ((s1 == null) || (s2 == null))
- return false;
- if (s1.length() != s2.length())
- return false;
- if (s1.length() == 0)
- return true;
- return s1.substring(0, 1).equalsIgnoreCase(s2.substring(0, 1)) &&
- s1.substring(1).equals(s2.substring(1));
- }
-
- public static Anchor getAnchor(ContainerShape cs) {
+ private static Anchor getAnchor(ContainerShape cs) {
Collection<Anchor> anchors = cs.getAnchors();
if (anchors.iterator().hasNext())
return anchors.iterator().next();
@@ -202,24 +193,13 @@ public class JPAEditorUtil {
public static String getAttributeTypeName(JavaResourceAttribute at) {
return at.getTypeBinding().getQualifiedName();
- }
-
- public static List<String> getAttributeTypeTypeNames(JavaResourceAttribute at) {
- ListIterator<String> tt = at.getTypeBinding().getTypeArgumentNames().iterator();
- if ((tt == null) || !tt.hasNext())
- return null;
- LinkedList<String> res = new LinkedList<String>();
- while (tt.hasNext())
- res.add(tt.next());
- return res;
}
public static String getAttributeTypeNameWithGenerics(JavaPersistentAttribute at) {
return getAttributeTypeNameWithGenerics(at.getResourceAttribute());
}
-
- public static String getAttributeTypeNameWithGenerics(JavaResourceAttribute at) {
+ private static String getAttributeTypeNameWithGenerics(JavaResourceAttribute at) {
StringBuilder res = new StringBuilder(getAttributeTypeName(at));
ListIterator<String> it = at.getTypeBinding().getTypeArgumentNames().iterator();
if ((it != null) && it.hasNext()) {
@@ -230,7 +210,6 @@ public class JPAEditorUtil {
return res.toString();
}
-
public static String[] getGenericsElementTypes(String typeName) {
if (typeName.indexOf("<") == -1) //$NON-NLS-1$
return null;
@@ -252,19 +231,8 @@ public class JPAEditorUtil {
}
return res.toString();
}
-
- public static String createCommaSeparatedListOfSimpleTypeNames(ListIterator<String> strIt) {
- if ((strIt == null) || !strIt.hasNext())
- return null;
- StringBuilder res = new StringBuilder(JPAEditorUtil.returnSimpleName(strIt.next()));
- while (strIt.hasNext()) {
- res.append(", "); //$NON-NLS-1$
- res.append(JPAEditorUtil.returnSimpleName(strIt.next()));
- }
- return res.toString();
- }
-
- public static String createCommaSeparatedListOfFullTypeNames(ListIterator<String> strIt) {
+
+ private static String createCommaSeparatedListOfFullTypeNames(ListIterator<String> strIt) {
if ((strIt == null) || !strIt.hasNext())
return null;
StringBuilder res = new StringBuilder(strIt.next());
@@ -275,7 +243,6 @@ public class JPAEditorUtil {
return res.toString();
}
-
public static String getText(JavaPersistentType jpt) {
return JPAEditorUtil.returnSimpleName(JpaArtifactFactory.instance().getEntityName(jpt));
}
@@ -305,51 +272,6 @@ public class JPAEditorUtil {
return (JavaPersistentType)pt;
}
- public static String getNameFromShape(Shape sh) {
- ContainerShape csh = (ContainerShape)sh;
- List<Shape> shapes = csh.getChildren();
- Iterator<Shape> it = shapes.iterator();
- while (it.hasNext()) {
- Shape shape = it.next();
- GraphicsAlgorithm ga = shape.getGraphicsAlgorithm();
- if (ga instanceof Rectangle) {
- Rectangle rect = (Rectangle)ga;
- if (rect.getY() == 0) {
- List<GraphicsAlgorithm> gas = rect.getGraphicsAlgorithmChildren();
- if (gas.size() > 0) {
- GraphicsAlgorithm gra = gas.get(0);
- if (gra instanceof Text)
- return ((Text)gra).getValue();
- }
- }
- }
- }
- return null;
- }
-
- public static void setNameOfShape(Shape sh, String name) {
- ContainerShape csh = (ContainerShape)sh;
- List<Shape> shapes = csh.getChildren();
- Iterator<Shape> it = shapes.iterator();
- while (it.hasNext()) {
- Shape shape = it.next();
- GraphicsAlgorithm ga = shape.getGraphicsAlgorithm();
- if (ga instanceof Rectangle) {
- Rectangle rect = (Rectangle)ga;
- if (rect.getY() == 0) {
- List<GraphicsAlgorithm> gas = rect.getGraphicsAlgorithmChildren();
- if (gas.size() > 0) {
- GraphicsAlgorithm gra = gas.get(0);
- if (gra instanceof Text) {
- ((Text)gra).setValue(name);
- return;
- }
- }
- }
- }
- };
- }
-
public static void setJPTNameInShape(ContainerShape cs, String newName) {
setJPTNameInShape(cs, newName, getPeUtil());
}
@@ -367,8 +289,7 @@ public class JPAEditorUtil {
return;
}
}
-
-
+
public static String produceValidAttributeName(String name) {
if ((name == null) || (name.length() == 0))
return ""; //$NON-NLS-1$
@@ -382,13 +303,12 @@ public class JPAEditorUtil {
decapitalizeFirstLetter(name);
}
- public static boolean isUpperCase(String s) {
+ private static boolean isUpperCase(String s) {
if ((s == null) || (s.length() == 0) || (s.length() > 1))
throw new IllegalArgumentException("The given string has to contain one symbol exactly"); //$NON-NLS-1$
return s.toUpperCase(Locale.ENGLISH).equals(s);
}
-
public static void createRegisterEntityInXMLJob(final JpaProject jpaProject, final String classFQN) {
final JptXmlResource resource = jpaProject.getPersistenceXmlResource();
XmlPersistence xmlPersistence = (XmlPersistence) resource.getRootObject();
@@ -432,8 +352,8 @@ public class JPAEditorUtil {
String[] typeFQNs = getAllTypes(typeFQN);
createImports(cu, typeFQNs);
}
-
- public static String[] getAllTypes(String typeFQN){
+
+ private static String[] getAllTypes(String typeFQN){
typeFQN = typeFQN.replace('[', ',');
typeFQN = typeFQN.replace(']', ',');
typeFQN = typeFQN.replace('<', ',');
@@ -503,28 +423,14 @@ public class JPAEditorUtil {
icon = Graphiti.getGaService().createImage(iconRect, JPAEditorImageProvider.ICON_TRANSIENT);
} else if(annotations.contains(JPAEditorConstants.ANNOTATION_EMBEDDED)){
icon = Graphiti.getGaService().createImage(iconRect, JPAEditorImageProvider.ICON_EMBEDDED);
+ } else if(annotations.contains(JPAEditorConstants.ANNOTATION_ELEMENT_COLLECTION)){
+ icon = Graphiti.getGaService().createImage(iconRect, JPAEditorImageProvider.ICON_ELEMENT_COLLECTION);
} else {
icon = Graphiti.getGaService().createImage(iconRect, JPAEditorImageProvider.ICON_BASIC);
}
return icon;
}
- public static Shape getIconShape(Shape attributeShape) {
- int y = attributeShape.getGraphicsAlgorithm().getY();
- ContainerShape cs = attributeShape.getContainer();
- Iterator<Shape> it = cs.getChildren().iterator();
- while (it.hasNext()) {
- Shape shp = it.next();
- GraphicsAlgorithm ga = shp.getGraphicsAlgorithm();
- if ((ga != null) && (ga.getY() == y) &&
- (ShapeType.ICON.toString().
- equals(Graphiti.getPeService().getPropertyValue(shp,
- JPAEditorConstants.PROP_SHAPE_TYPE))))
- return shp;
- }
- return null;
- }
-
public static Collection<ContainerShape> getRelatedShapes(ContainerShape cs) {
Collection<ContainerShape> res = new HashSet<ContainerShape>();
Collection<Connection> cons = new HashSet<Connection>();
@@ -568,7 +474,7 @@ public class JPAEditorUtil {
return createBendPointList(c, cnt - 1, cnt, selfRelation);
}
- public static List<Point> createBendPointList(FreeFormConnection c, int cnt, int connectionsNum, boolean selfRelation) {
+ private static List<Point> createBendPointList(FreeFormConnection c, int cnt, int connectionsNum, boolean selfRelation) {
return selfRelation ?
createBendPointListForSelfRelation(c, cnt, connectionsNum) :
createBendPointListForNonSelfRelation(c, cnt, connectionsNum);
@@ -854,10 +760,14 @@ public class JPAEditorUtil {
while (cIter.hasNext()) {
Connection c = cIter.next();
Object o = fp.getBusinessObjectForPictogramElement(c);
- if (!(o instanceof IRelation))
+ if (!(o instanceof IRelation) && !(o instanceof HasReferanceRelation) && !(o instanceof IsARelation))
continue;
- IRelation rel = (IRelation)o;
- rearrangeConnection(c, cnt, setSize, rel.getOwner() == rel.getInverse());
+ boolean isSelfConnection = false;
+ if(o instanceof IRelation){
+ IRelation rel = (IRelation)o;
+ isSelfConnection = rel.getOwner() == rel.getInverse();
+ }
+ rearrangeConnection(c, cnt, setSize, isSelfConnection);
cnt++;
}
}
@@ -866,19 +776,19 @@ public class JPAEditorUtil {
});
}
- static public boolean areConnectionsWithIdenticalEnds(Connection c1, Connection c2) {
+ static private boolean areConnectionsWithIdenticalEnds(Connection c1, Connection c2) {
return ((c1.getStart() == c2.getStart()) && (c1.getEnd() == c2.getEnd())) ||
((c1.getStart() == c2.getEnd()) && (c1.getEnd() == c2.getStart()));
}
- static public boolean connectionBelongsToSet(Connection c, Set<Connection> s) {
+ static private boolean connectionBelongsToSet(Connection c, Set<Connection> s) {
if (s.isEmpty())
return false;
Connection example = s.iterator().next();
return areConnectionsWithIdenticalEnds(c, example);
}
- static public int getNumberOfConnectionsWithSameEndsAs(Connection c) {
+ static private int getNumberOfConnectionsWithSameEndsAs(Connection c) {
Anchor from = c.getStart();
Anchor to = c.getEnd();
Collection<Connection> cs1 = from.getOutgoingConnections();
@@ -901,7 +811,7 @@ public class JPAEditorUtil {
return cnt;
}
- static void addConnection(Set<Set<Connection>> sets, Connection c, boolean selfOnly) {
+ private static void addConnection(Set<Set<Connection>> sets, Connection c, boolean selfOnly) {
if (sets == null)
throw new NullPointerException("'sets' parameter should not be null"); //$NON-NLS-1$
if (selfOnly && (c.getStart() != c.getEnd()))
@@ -921,13 +831,13 @@ public class JPAEditorUtil {
sets.add(newSet);
}
- static public void rearrangeConnection(Connection connection, int cnt, int connectionsNum, boolean selfRelation) {
+ static private void rearrangeConnection(Connection connection, int cnt, int connectionsNum, boolean selfRelation) {
FreeFormConnection c = (FreeFormConnection)connection;
rearrangeConnectionBendPoints(c, cnt, connectionsNum, selfRelation);
rearrangeConnectionDecoratorsLocation(c, cnt, connectionsNum);
}
- static public void rearrangeConnectionBendPoints(FreeFormConnection c, int cnt, int connectionsNum, boolean selfRelation) {
+ static private void rearrangeConnectionBendPoints(FreeFormConnection c, int cnt, int connectionsNum, boolean selfRelation) {
List<org.eclipse.graphiti.mm.algorithms.styles.Point> oldPts = c.getBendpoints();
List<org.eclipse.swt.graphics.Point> newPts = JPAEditorUtil.createBendPointList(c, cnt, connectionsNum, selfRelation);
if (newPts == null)
@@ -946,7 +856,7 @@ public class JPAEditorUtil {
}
}
- static public void rearrangeConnectionDecoratorsLocation(FreeFormConnection c, int cnt, int connectionsNum) {
+ static private void rearrangeConnectionDecoratorsLocation(FreeFormConnection c, int cnt, int connectionsNum) {
Collection<ConnectionDecorator> dcrs = c.getConnectionDecorators();
int len = JPAEditorUtil.calcConnectionLength(c);
for (ConnectionDecorator dcr : dcrs) {
@@ -1024,12 +934,12 @@ public class JPAEditorUtil {
return ret;
}
- static public RelEndDir getConnectionStartDir(FreeFormConnection c) {
+ static private RelEndDir getConnectionStartDir(FreeFormConnection c) {
EList<org.eclipse.graphiti.mm.algorithms.styles.Point> pts = c.getBendpoints();
return getConnectionEndDir(pts.get(0), pts.get(1));
}
- static public RelEndDir getConnectionEndDir(FreeFormConnection c) {
+ static private RelEndDir getConnectionEndDir(FreeFormConnection c) {
List<org.eclipse.graphiti.mm.algorithms.styles.Point> pts = c.getBendpoints();
return getConnectionEndDir(pts.get(pts.size() - 1), pts.get(pts.size() - 2));
}
@@ -1053,30 +963,8 @@ public class JPAEditorUtil {
action.run(new StructuredSelection(cu));
}
- static public String generateUniqueEntityName(JpaProject jpaProject,
- String pack,
- IJPAEditorFeatureProvider fp) {
- String NAME = pack + ".Entity"; //$NON-NLS-1$
- String name = null;
-
- HashSet<String> JPAProjectEntityNames = getEntityNames(jpaProject);
- HashSet<String> JPAProjectEntitySimpleNames = getEntitySimpleNames(jpaProject);
-
- for (int i = 1; i < 100000000; i++) {
- name = NAME + i;
- if ((!fp.hasObjectWithName(name)) &&
- !JPAProjectEntityNames.contains(name.toLowerCase(Locale.ENGLISH)) &&
- !JPAProjectEntitySimpleNames.contains(JPAEditorUtil.returnSimpleName(name).toLowerCase(Locale.ENGLISH)) &&
- !isJavaFileInProject(jpaProject.getProject(), name, pack))
- break;
- }
- return name;
- }
-
-
- static public String generateUniqueMappedSuperclassName(
- JpaProject jpaProject, String pack, IJPAEditorFeatureProvider fp) {
- String NAME = pack + ".MpdSuprcls"; //$NON-NLS-1$
+ static public String generateUniquePersistentObjectName(JpaProject jpaProject, String pack, String objectTypeName, IJPAEditorFeatureProvider fp){
+ String NAME = pack + objectTypeName;
String name = null;
HashSet<String> JPAProjectEntityNames = getEntityNames(jpaProject);
@@ -1115,14 +1003,6 @@ public class JPAEditorUtil {
mappedSuperclassPackage, idName, hasPrimaryKey);
}
-
- static public IFile createEntityFromMappedSuperclassInProject(
- IProject project, String mappedSuperclassName,
- IPreferenceStore jpaPreferenceStore) throws Exception {
- IFolder folder = getPackageFolder(project);
- return createMappedSuperclassInProject(project, folder, mappedSuperclassName);
- }
-
@SuppressWarnings("deprecation")
private static IFolder getPackageFolder(IProject project) throws JavaModelException {
@@ -1147,44 +1027,35 @@ public class JPAEditorUtil {
}
- static public IFile createMappedSuperclassInProject(IProject project,
+ public static IFile createMappedSuperclassInProject(IProject project,
String mappedSuperclassName) throws Exception {
IFolder folder = getPackageFolder(project);
- return createMappedSuperclassInProject(project, folder, mappedSuperclassName);
- }
-
- static public IFile createMappedSuperclassInProject(IProject project,
- IFolder folder, String mappedSuperclassName) throws Exception {
-
String mappedSuperclassShortName = mappedSuperclassName
.substring(mappedSuperclassName.lastIndexOf('.') + 1);
- if (!folder.exists()) {
- folder.create(true, true, new NullProgressMonitor());
- }
- IFile file = folder.getFile(mappedSuperclassShortName + ".java"); //$NON-NLS-1$
-
- if (!file.exists()) {
- String content = "package " + JPADiagramPropertyPage.getDefaultPackage(project) + ";\n\n" //$NON-NLS-1$ //$NON-NLS-2$
- + "import javax.persistence.*;\n\n" //$NON-NLS-1$
- + "@MappedSuperclass \n" //$NON-NLS-1$
- + "public class " + mappedSuperclassShortName + " {\n\n" //$NON-NLS-1$ //$NON-NLS-2$
- + "}"; //$NON-NLS-1$
- ByteArrayOutputStream stream = new ByteArrayOutputStream();
- try {
- stream.write(content.getBytes());
- stream.flush();
- file.create(new ByteArrayInputStream(stream.toByteArray()),
- true, new NullProgressMonitor());
- } finally {
- stream.close();
- }
- }
- return file;
+ String content = "package " + JPADiagramPropertyPage.getDefaultPackage(project) + ";\n\n" //$NON-NLS-1$ //$NON-NLS-2$
+ + "import javax.persistence.*;\n\n" //$NON-NLS-1$
+ + "@MappedSuperclass \n" //$NON-NLS-1$
+ + "public class " + mappedSuperclassShortName + " {\n\n" //$NON-NLS-1$ //$NON-NLS-2$
+ + "}"; //$NON-NLS-1$
+ return createClassInProject(project, folder, mappedSuperclassShortName, content);
}
-
-
+
+ public static IFile createEmbeddableInProject(IProject project, String embeddableName) throws Exception {
+ IFolder folder = getPackageFolder(project);
+ String embeddableShortName = embeddableName
+ .substring(embeddableName.lastIndexOf('.') + 1);
+ String content = "package " + JPADiagramPropertyPage.getDefaultPackage(project) + ";\n\n" //$NON-NLS-1$ //$NON-NLS-2$
+ + "import javax.persistence.*;\n\n" //$NON-NLS-1$
+ + "import java.io.Serializable;\n\n" //$NON-NLS-1$
+ + "@Embeddable \n" //$NON-NLS-1$
+ + "public class " + embeddableShortName + " implements Serializable {\n\n" //$NON-NLS-1$ //$NON-NLS-2$
+ + "private static final long serialVersionUID = 1L;\n\n" //$NON-NLS-1$
+ + "}"; //$NON-NLS-1$
+ return createClassInProject(project, folder, embeddableShortName, content);
+ }
+
@SuppressWarnings("deprecation")
- static public boolean isJavaFileInProject(IProject project,
+ static private boolean isJavaFileInProject(IProject project,
String entityName,
String defaultEntityPacakage) {
IJavaProject javaProject = JavaCore.create(project);
@@ -1298,7 +1169,7 @@ public class JPAEditorUtil {
}
}
- static private IFile createEntity(IProject project,
+ private static IFile createEntity(IProject project,
IFolder folder,
String entityName,
boolean isMappedSuperclassChild,
@@ -1308,10 +1179,7 @@ public class JPAEditorUtil {
boolean hasPrimaryKey) throws Exception {
String entityShortName = entityName.substring(entityName.lastIndexOf('.') + 1);
- if (!folder.exists()) {
- folder.create(true, true, new NullProgressMonitor());
- }
- IFile file = folder.getFile(entityShortName + ".java"); //$NON-NLS-1$
+
Properties props = JPADiagramPropertyPage.loadProperties(project);
String tableNamePrefix = JPADiagramPropertyPage.getDefaultTablePrefixName(project, props);
String tableName = (tableNamePrefix.length() > 0) ? (tableNamePrefix + entityShortName.toUpperCase(Locale.ENGLISH)) : ""; //$NON-NLS-1$
@@ -1332,32 +1200,46 @@ public class JPAEditorUtil {
packageImport = "import " + mappedSuperclassPackage + ".*;"; //$NON-NLS-1$ //$NON-NLS-2$
}
+
String primaryKeyDeclaration = ""; //$NON-NLS-1$
if (!hasPrimaryKey)
primaryKeyDeclaration = generatePrimaryKeyDeclaration(fieldBasedAccess, idName);
+ String content = "package " + JPADiagramPropertyPage.getDefaultPackage(project, props) //$NON-NLS-1$
+ + ";\n\n" //$NON-NLS-1$
+ + "import javax.persistence.*;\n" //$NON-NLS-1$
+ + packageImport+"\n\n" //$NON-NLS-1$
+ + "@Entity \n" //$NON-NLS-1$
+ + ((tableName.length() > 0) ? ("@Table(name=\"" //$NON-NLS-1$
+ + tableName + "\")\n") : "") //$NON-NLS-1$ //$NON-NLS-2$
+ + classDeclarationStringContent
+ + primaryKeyDeclaration
+ +"}"; //$NON-NLS-1$
+
+ return createClassInProject(project, folder, entityShortName, content);
+ }
+
+ private static IFile createClassInProject(IProject project,
+ IFolder folder, String classShortName, String content) throws Exception{
+
+ if (!folder.exists()) {
+ folder.create(true, true, new NullProgressMonitor());
+ }
+ IFile file = folder.getFile(classShortName + ".java"); //$NON-NLS-1$
+
if (!file.exists()) {
- String content = "package " + JPADiagramPropertyPage.getDefaultPackage(project, props) //$NON-NLS-1$
- + ";\n\n" //$NON-NLS-1$
- + "import javax.persistence.*;\n" //$NON-NLS-1$
- + packageImport+"\n\n" //$NON-NLS-1$
- + "@Entity \n" //$NON-NLS-1$
- + ((tableName.length() > 0) ? ("@Table(name=\"" //$NON-NLS-1$
- + tableName + "\")\n") : "") //$NON-NLS-1$ //$NON-NLS-2$
- + classDeclarationStringContent
- + primaryKeyDeclaration
- +"}"; //$NON-NLS-1$
ByteArrayOutputStream stream = new ByteArrayOutputStream();
try {
stream.write(content.getBytes());
stream.flush();
- file.create(new ByteArrayInputStream(stream.toByteArray()), true, new NullProgressMonitor());
+ file.create(new ByteArrayInputStream(stream.toByteArray()),
+ true, new NullProgressMonitor());
} finally {
stream.close();
- }
+ }
}
return file;
- }
+ }
static private String generatePrimaryKeyDeclaration(boolean fieldBasedAccess, String primaryKeyName) {
String primaryKeyDeclaration = (fieldBasedAccess ? " @Id \n" : "") //$NON-NLS-1$ //$NON-NLS-2$
@@ -1489,13 +1371,13 @@ public class JPAEditorUtil {
return isAdded;
}
- public static String cutOffStringPrefix(String s, String prefix) {
+ private static String cutOffStringPrefix(String s, String prefix) {
if (s.startsWith(prefix))
return s.substring(prefix.length());
return s;
}
- public static String cutOffHeaderDirtyPrefix(String header) {
+ private static String cutOffHeaderDirtyPrefix(String header) {
return cutOffStringPrefix(header, JPAEditorConstants.HEADER_PREFIX_DIRTY);
}
@@ -1506,8 +1388,7 @@ public class JPAEditorUtil {
}
public static JavaPersistentAttribute addAnnotatedAttribute(IJPAEditorFeatureProvider fp, JavaPersistentType referencingJPT,
- JavaPersistentType referencedJPT, ICompilationUnit referencingCU, ICompilationUnit referencedCU, boolean isCollection,
- String mapKeyType){
+ JavaPersistentType referencedJPT, boolean isCollection, String mapKeyType){
String name = returnSimpleName(referencedJPT.getName());
String actName = returnSimpleName(JpaArtifactFactory.instance().getEntityName(referencedJPT));
@@ -1521,13 +1402,9 @@ public class JPAEditorUtil {
}
nameWithNonCapitalLetter = produceUniqueAttributeName(referencingJPT, nameWithNonCapitalLetter);
actNameWithNonCapitalLetter = produceUniqueAttributeName(referencingJPT, actNameWithNonCapitalLetter);
-
- if(mapKeyType == null){
- return JpaArtifactFactory.instance().addAttribute(fp, referencingJPT, referencedJPT,
- nameWithNonCapitalLetter, actNameWithNonCapitalLetter, isCollection,
- referencingCU, referencedCU);
- }
-
+
+ ICompilationUnit referencingCU = JPAEditorUtil.getCompilationUnit(referencingJPT);
+ ICompilationUnit referencedCU = JPAEditorUtil.getCompilationUnit(referencedJPT);
return JpaArtifactFactory.instance().addAttribute(fp, referencingJPT, referencedJPT, mapKeyType,
nameWithNonCapitalLetter,
actNameWithNonCapitalLetter, isCollection,
@@ -1535,4 +1412,4 @@ public class JPAEditorUtil {
referencedCU);
}
-} \ No newline at end of file
+}
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/JPAEditorUtilImpl.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/JPAEditorUtilImpl.java
index c77aaee..b111c76 100644
--- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/JPAEditorUtilImpl.java
+++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/JPAEditorUtilImpl.java
@@ -18,43 +18,23 @@ package org.eclipse.jpt.jpadiagrameditor.ui.internal.util;
import java.util.List;
import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject;
-import org.eclipse.graphiti.mm.pictograms.ConnectionDecorator;
import org.eclipse.graphiti.mm.pictograms.FreeFormConnection;
import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jpt.jpa.core.JpaProject;
import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.IJPAEditorFeatureProvider;
-import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.IJPAEditorImageCreator.RelEndDir;
import org.eclipse.swt.graphics.Point;
import org.eclipse.ui.IWorkbenchSite;
public class JPAEditorUtilImpl implements IJPAEditorUtil {
- public int calcConnectionLength(FreeFormConnection c) {
- return JPAEditorUtil.calcConnectionLength(c);
- }
-
- public List<Point> createBendPointList(FreeFormConnection c, int cnt, int connectionsNum, boolean selfRelation) {
- return JPAEditorUtil.createBendPointList(c, cnt, connectionsNum, selfRelation);
- }
-
public List<Point> createBendPointList(FreeFormConnection c, boolean selfRelation) {
return JPAEditorUtil.createBendPointList(c, selfRelation);
}
- public RelEndDir getConnectionStartDir(FreeFormConnection c) {
- return JPAEditorUtil.getConnectionStartDir(c);
-
- }
-
- public RelEndDir getConnectionEndDir(FreeFormConnection c) {
- return JPAEditorUtil.getConnectionEndDir(c);
- }
-
public JavaPersistentType getJPType(ICompilationUnit cu) {
return JPAEditorUtil.getJPType(cu);
}
@@ -67,17 +47,6 @@ public class JPAEditorUtilImpl implements IJPAEditorUtil {
JPAEditorUtil.formatCode(cu, ws);
}
- public String generateUniqueEntityName(JpaProject jpaProject,
- String pack,
- IJPAEditorFeatureProvider fp) {
- return JPAEditorUtil.generateUniqueEntityName(jpaProject, pack, fp);
- }
-
- public String generateUniqueMappedSuperclassName(JpaProject jpaProject, String pack, IJPAEditorFeatureProvider fp) {
- return JPAEditorUtil.generateUniqueMappedSuperclassName(jpaProject, pack, fp);
- }
-
-
public IFile createEntityInProject(IProject project, String entityName, IPreferenceStore jpaPreferenceStore,
boolean isMappedSuperclassChild, String mappedSuperclassName,
String mappedSuperclassPackage, String idName,
@@ -95,28 +64,24 @@ public class JPAEditorUtilImpl implements IJPAEditorUtil {
public ICompilationUnit getCompilationUnit(JavaPersistentType jpt) {
return JPAEditorUtil.getCompilationUnit(jpt);
}
-
- public boolean isCardinalityDecorator(ConnectionDecorator dc) {
- return JPAEditorUtil.isCardinalityDecorator(dc);
- }
public void discardWorkingCopyOnce(ICompilationUnit cu) {
JPAEditorUtil.discardWorkingCopyOnce(cu);
}
-
- public IFile createEntityFromMappedSuperclassInProject(IProject project,
- String mappedSuperclassName, IPreferenceStore jpaPreferenceStore) throws Exception {
- return JPAEditorUtil.createEntityFromMappedSuperclassInProject(project, mappedSuperclassName, jpaPreferenceStore);
- }
-
- public IFile createMappedSuperclassInProject(IProject project,
- IFolder folder, String mappedSuperclassName) throws Exception {
- return JPAEditorUtil.createMappedSuperclassInProject(project, folder, mappedSuperclassName);
- }
-
+
public IFile createMappedSuperclassInProject(IProject project,
String mappedSuperclassName) throws Exception {
return JPAEditorUtil.createMappedSuperclassInProject(project, mappedSuperclassName);
}
+ public String generateUniqueTypeName(JpaProject jpaProject, String pack,
+ String objectTypeName, IJPAEditorFeatureProvider fp) {
+ return JPAEditorUtil.generateUniquePersistentObjectName(jpaProject, pack, objectTypeName, fp);
+ }
+
+ public IFile createEmbeddableInProject(IProject project,
+ String embeddableName) throws Exception {
+ return JPAEditorUtil.createEmbeddableInProject(project, embeddableName);
+ }
+
}
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/JPASolver.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/JPASolver.java
index c3c8701..5a3ee9e 100644
--- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/JPASolver.java
+++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/JPASolver.java
@@ -25,6 +25,7 @@ import java.util.Iterator;
import java.util.List;
import java.util.Set;
import java.util.WeakHashMap;
+
import org.eclipse.core.internal.resources.File;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IMarkerDelta;
@@ -39,7 +40,6 @@ import org.eclipse.emf.transaction.TransactionalEditingDomain;
import org.eclipse.emf.transaction.util.TransactionUtil;
import org.eclipse.graphiti.dt.IDiagramTypeProvider;
import org.eclipse.graphiti.features.IRemoveFeature;
-import org.eclipse.graphiti.features.context.impl.AddConnectionContext;
import org.eclipse.graphiti.features.context.impl.AddContext;
import org.eclipse.graphiti.features.context.impl.CustomContext;
import org.eclipse.graphiti.features.context.impl.RemoveContext;
@@ -63,6 +63,7 @@ import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.internal.core.PackageFragmentRoot;
import org.eclipse.jpt.common.core.JptResourceModel;
+import org.eclipse.jpt.common.core.resource.java.Annotation;
import org.eclipse.jpt.common.core.resource.java.JavaResourceAbstractType;
import org.eclipse.jpt.common.core.resource.java.JavaResourceCompilationUnit;
import org.eclipse.jpt.common.utility.internal.iterator.ArrayIterator;
@@ -103,11 +104,11 @@ import org.eclipse.jpt.jpa.core.context.java.JavaOneToOneMapping;
import org.eclipse.jpt.jpa.core.context.java.JavaPersistentAttribute;
import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType;
import org.eclipse.jpt.jpa.core.context.persistence.PersistenceUnit;
+import org.eclipse.jpt.jpa.core.resource.java.OwnableRelationshipMappingAnnotation;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.JPADiagramEditor;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.JPADiagramEditorPlugin;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.facade.EclipseFacade;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.feature.AddAttributeFeature;
-import org.eclipse.jpt.jpadiagrameditor.ui.internal.feature.AddRelationFeature;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.feature.GraphicalRemoveAttributeFeature;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.feature.RemoveAttributeFeature;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.feature.RemoveRelationFeature;
@@ -115,8 +116,10 @@ import org.eclipse.jpt.jpadiagrameditor.ui.internal.modelintegration.util.ModelI
import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.IJPAEditorFeatureProvider;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.JPAEditorDiagramTypeProvider;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.AbstractRelation;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.HasReferanceRelation;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.IBidirectionalRelation;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.IRelation;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.IsARelation;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.IWorkbenchPage;
@@ -147,6 +150,9 @@ public class JPASolver implements IResourceChangeListener, IJpaSolver {
private HashSet<String> addIgnore = new HashSet<String>();
private Hashtable<String, IRelation> attribToRel = new Hashtable<String, IRelation>();
+ private Hashtable<String, HasReferanceRelation> attribToEmbeddedRel = new Hashtable<String, HasReferanceRelation>();
+ private Hashtable<String, IsARelation> attribToIsARel = new Hashtable<String, IsARelation>();
+
private static final String SEPARATOR = "-"; //$NON-NLS-1$
private IEclipseFacade eclipseFacade;
@@ -286,6 +292,10 @@ public class JPASolver implements IResourceChangeListener, IJpaSolver {
return name;
} else if (bo instanceof AbstractRelation) {
return ((AbstractRelation) bo).getId();
+ } else if (bo instanceof HasReferanceRelation) {
+ return ((HasReferanceRelation)bo).getId();
+ } else if (bo instanceof IsARelation) {
+ return ((IsARelation)bo).getId();
} else if (bo instanceof JavaPersistentAttribute) {
JavaPersistentAttribute at = (JavaPersistentAttribute) bo;
return (((PersistentType)at.getParent()).getName() + "-" + at.getName()); //$NON-NLS-1$
@@ -310,12 +320,20 @@ public class JPASolver implements IResourceChangeListener, IJpaSolver {
protected String produceOwnerKeyForRel(AbstractRelation rel) {
return produceKeyForRel(rel.getOwner(), rel.getOwnerAttributeName());
}
+
+ protected String produceKeyForEmbeddedRel(HasReferanceRelation rel){
+ return produceKeyForRel(rel.getEmbeddingEntity(), rel.getEmbeddedAnnotatedAttribute().getName());
+ }
+
+ protected String produceKeyForIsARel(IsARelation rel) {
+ return produceKeyForRel(rel.getSubclass(), rel.getSuperclass().getName());
+ }
protected String produceInverseKeyForRel(AbstractRelation rel) {
return produceKeyForRel(rel.getInverse(), rel.getInverseAttributeName());
}
- public String produceKeyForRel(JavaPersistentType jpt, String attributeName) {
+ private String produceKeyForRel(JavaPersistentType jpt, String attributeName) {
return jpt.getName() + SEPARATOR + attributeName;
}
@@ -335,6 +353,12 @@ public class JPASolver implements IResourceChangeListener, IJpaSolver {
if (rel instanceof IBidirectionalRelation) {
attribToRel.put(produceInverseKeyForRel(rel), rel);
}
+ } else if (bo instanceof HasReferanceRelation) {
+ HasReferanceRelation rel = (HasReferanceRelation) bo;
+ attribToEmbeddedRel.put(produceKeyForEmbeddedRel(rel), rel);
+ } else if (bo instanceof IsARelation) {
+ IsARelation rel = (IsARelation) bo;
+ attribToIsARel.put(produceKeyForIsARel(rel), rel);
} else if (bo instanceof JavaPersistentAttribute) {
addPropertiesListenerToAttribute((JavaPersistentAttribute)bo);
}
@@ -369,6 +393,12 @@ public class JPASolver implements IResourceChangeListener, IJpaSolver {
attribToRel.remove(produceOwnerKeyForRel(rel));
if (rel instanceof IBidirectionalRelation)
attribToRel.remove(produceInverseKeyForRel(rel));
+ } else if (o instanceof HasReferanceRelation) {
+ HasReferanceRelation rel = (HasReferanceRelation) o;
+ attribToEmbeddedRel.remove(produceKeyForEmbeddedRel(rel));
+ } else if (o instanceof IsARelation) {
+ IsARelation rel = (IsARelation) o;
+ attribToIsARel.remove(produceKeyForIsARel(rel));
} else if (o instanceof JavaPersistentAttribute) {
removeListenersFromAttribute((JavaPersistentAttribute)o);
}
@@ -383,42 +413,74 @@ public class JPASolver implements IResourceChangeListener, IJpaSolver {
String key = produceKeyForRel((JavaPersistentType)jpa.getParent(), jpa.getName());
return attribToRel.containsKey(key);
}
-
- public IRelation getRelationRelatedToAttribute(JavaPersistentAttribute jpa) {
- String key = produceKeyForRel((JavaPersistentType)jpa.getParent(), jpa.getName());
+
+ public IRelation getRelationRelatedToAttribute(JavaPersistentAttribute jpa, IJPAEditorFeatureProvider fp) {
+ String key = findRelationshipKey(jpa, fp);
return attribToRel.get(key);
}
-
- public Set<IRelation> getRelationsRelatedToEntity(JavaPersistentType jpt) {
- HashSet<IRelation> res = new HashSet<IRelation>();
- for (JavaPersistentAttribute at : jpt.getAttributes()) {
- IRelation rel = getRelationRelatedToAttribute(at);
- if (rel != null)
- res.add(rel);
+
+ /**
+ * This method is called to update the existing relationships when an Embeddable class is renamed. By the renamed
+ * embedded attribute, find the target entity of the relationship:
+ * First finds the type of the embedded attribute -> the embeddable class. Then iterates over the embeddable's attributes
+ * and check for each attribute if it is involved in a relationship. If yes, find its parent -> the target entity class
+ * and iterates over its attribute. Check if there is an attribute that is involved in a relationship and has a "mappedBy" attribute
+ * that consists of the name of the attribute which will be renamed and the name of the attribute in the embeddable class. If such an attribute
+ * exists, the unique key for the existing relationship must be ganerated by the target entity and the name of the found attribute.
+ * Otherwise the key must be generated by the name of the attribute that will be renamed and its parent entity.
+ * @param jpa - the {@link JavaPersistentAttribute} which will be renamed
+ * @param fp
+ * @return the unique key for the relationship.
+ */
+ private String findRelationshipKey(JavaPersistentAttribute jpa, IJPAEditorFeatureProvider fp){
+ JpaArtifactFactory jpaFactory = JpaArtifactFactory.instance();
+ if(jpaFactory.isEmbeddedAttribute(jpa)){
+ JavaPersistentType embeddableClass = jpaFactory.findJPT(jpa, fp, JpaArtifactFactory.instance().getAnnotations(jpa)[0]);
+ if(embeddableClass == null)
+ return ""; //$NON-NLS-1$
+ for (JavaPersistentAttribute relEntAt : embeddableClass.getAttributes()) {
+ IResource r = relEntAt.getParent().getResource();
+ if (!r.exists())
+ throw new RuntimeException();
+ Annotation[] ans = jpaFactory.getAnnotations(relEntAt);
+ for (Annotation an : ans) {
+ String annotationName = JPAEditorUtil.returnSimpleName(an.getAnnotationName());
+ if (JPAEditorConstants.RELATION_ANNOTATIONS.contains(annotationName)) {
+ JavaPersistentType jpt = jpaFactory.findJPT(relEntAt, fp, an);
+ if(jpt == null)
+ return ""; //$NON-NLS-1$
+ for(JavaPersistentAttribute attribute : jpt.getAttributes()){
+ Annotation[] inverseAnns = jpaFactory.getAnnotations(attribute);
+ for(Annotation inverseAn : inverseAnns){
+ String inverseAnName = JPAEditorUtil.returnSimpleName(inverseAn.getAnnotationName());
+ if(JPAEditorConstants.RELATION_ANNOTATIONS.contains(inverseAnName)){
+ String mappedBy = ((OwnableRelationshipMappingAnnotation)inverseAn).getMappedBy();
+ if(mappedBy.equals(jpa.getName()+"."+relEntAt.getName())) //$NON-NLS-1$
+ return produceKeyForRel(jpt, attribute.getName());
+ }
+ }
+ }
+ }
+ }
+ }
+// } else {
+// JavaPersistentType embeddedJPT = (JavaPersistentType) jpa.getParent();
+// if(jpaFactory.hasEmbeddableAnnotation(embeddedJPT)){
+// Set<IRelation> rels = featureProvider.getAllExistingIRelations();
+// for(IRelation rel : rels){
+// if(rel.getOwnerAnnotatedAttribute().equals(jpa) && (rel instanceof IBidirectionalRelation)){
+// return findRelationshipKey(rel.getInverseAnnotatedAttribute(), featureProvider);
+// }
+// }
+// }
}
- return res;
+ return produceKeyForRel((JavaPersistentType) jpa.getParent(), jpa.getName());
}
- public boolean existsRelation(JavaPersistentType jpt1, JavaPersistentType jpt2) {
- Set<IRelation> rels = getRelationsRelatedToEntity(jpt1);
- if (existsRelation(jpt1, jpt2, rels))
- return true;
- rels = getRelationsRelatedToEntity(jpt2);
- return existsRelation(jpt1, jpt2, rels);
- }
-
- public boolean existsRelation(JavaPersistentType jpt1,
- JavaPersistentType jpt2,
- Set<IRelation> rels) {
- Iterator<IRelation> it = rels.iterator();
- while (it.hasNext()) {
- IRelation rel = it.next();
- if ((jpt1.equals(rel.getOwner()) && jpt2.equals(rel.getInverse())) ||
- ((jpt2.equals(rel.getOwner()) && jpt1.equals(rel.getInverse()))))
- return true;
- }
- return false;
+ public HasReferanceRelation getEmbeddedRelationToAttribute(JavaPersistentAttribute jpa) {
+ String key = produceKeyForRel((JavaPersistentType)jpa.getParent(), jpa.getName());
+ return attribToEmbeddedRel.get(key);
}
public Collection<Object> getVisualizedObjects() {
@@ -945,6 +1007,8 @@ public class JPASolver implements IResourceChangeListener, IJpaSolver {
util = null;
keyToBO.clear();
attribToRel.clear();
+ attribToEmbeddedRel.clear();
+ attribToIsARel.clear();
persistentTypes.clear();
keyToBO = null;
attribToRel = null;
@@ -1305,6 +1369,12 @@ public class JPASolver implements IResourceChangeListener, IJpaSolver {
if (rel == null)
continue;
Connection conn = (Connection) featureProvider.getPictogramElementForBusinessObject(rel);
+ if(conn == null){
+ HasReferanceRelation embedRel = featureProvider.getEmbeddedRelationRelatedToAttribute(at);
+ if(embedRel == null)
+ continue;
+ conn = (Connection)featureProvider.getPictogramElementForBusinessObject(embedRel);
+ }
while (conn != null) {
RemoveContext ctx = new RemoveContext(conn);
RemoveRelationFeature ft = new RemoveRelationFeature(featureProvider);
@@ -1319,21 +1389,7 @@ public class JPASolver implements IResourceChangeListener, IJpaSolver {
RemoveAttributeFeature ft = new RemoveAttributeFeature(featureProvider, true, true);
ft.remove(ctx);
}
- Collection<IRelation> rels = JpaArtifactFactory.instance().produceAllRelations(
- (JavaPersistentType) event.getSource(), featureProvider);
- Iterator<IRelation> iter = rels.iterator();
- while (iter.hasNext()) {
- IRelation rel = iter.next();
- ContainerShape ownerShape = (ContainerShape) featureProvider
- .getPictogramElementForBusinessObject(rel.getOwner());
- ContainerShape inverseShape = (ContainerShape) featureProvider
- .getPictogramElementForBusinessObject(rel.getInverse());
- AddConnectionContext cntx = new AddConnectionContext(JPAEditorUtil.getAnchor(ownerShape),
- JPAEditorUtil.getAnchor(inverseShape));
- cntx.setNewObject(rel);
- AddRelationFeature ft = new AddRelationFeature(featureProvider);
- ft.add(cntx);
- }
+ JpaArtifactFactory.instance().addNewRelations(featureProvider, (JavaPersistentType) event.getSource());
} catch (Exception e) {
//$NON-NLS-1$
}
@@ -1478,5 +1534,4 @@ public class JPASolver implements IResourceChangeListener, IJpaSolver {
public Collection<JavaPersistentType> getPersistentTypes() {
return persistentTypes;
}
-
}
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/JpaArtifactFactory.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/JpaArtifactFactory.java
index e65cffb..8df8768 100644
--- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/JpaArtifactFactory.java
+++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/JpaArtifactFactory.java
@@ -39,7 +39,6 @@ import org.eclipse.graphiti.features.context.impl.AddConnectionContext;
import org.eclipse.graphiti.features.context.impl.RemoveContext;
import org.eclipse.graphiti.mm.pictograms.Connection;
import org.eclipse.graphiti.mm.pictograms.ContainerShape;
-import org.eclipse.graphiti.mm.pictograms.PictogramElement;
import org.eclipse.graphiti.mm.pictograms.Shape;
import org.eclipse.graphiti.services.Graphiti;
import org.eclipse.graphiti.util.IColorConstant;
@@ -72,7 +71,6 @@ import org.eclipse.jpt.jpa.core.context.ReadOnlyPersistentAttribute;
import org.eclipse.jpt.jpa.core.context.RelationshipMapping;
import org.eclipse.jpt.jpa.core.context.java.JavaAttributeMapping;
import org.eclipse.jpt.jpa.core.context.java.JavaEntity;
-import org.eclipse.jpt.jpa.core.context.java.JavaMappedSuperclass;
import org.eclipse.jpt.jpa.core.context.java.JavaPersistentAttribute;
import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType;
import org.eclipse.jpt.jpa.core.context.java.JavaTypeMapping;
@@ -93,6 +91,7 @@ import org.eclipse.jpt.jpadiagrameditor.ui.internal.command.DeleteAttributeComma
import org.eclipse.jpt.jpadiagrameditor.ui.internal.command.RenameAttributeCommand;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.command.RenameEntityCommand;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.command.SetMappedByNewValueCommand;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.feature.AddHasReferenceRelationFeature;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.feature.AddInheritedEntityFeature;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.feature.AddRelationFeature;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.feature.RemoveRelationFeature;
@@ -100,6 +99,10 @@ import org.eclipse.jpt.jpadiagrameditor.ui.internal.feature.UpdateAttributeFeatu
import org.eclipse.jpt.jpadiagrameditor.ui.internal.i18n.JPAEditorMessages;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.propertypage.JPADiagramPropertyPage;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.IJPAEditorFeatureProvider;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.HasCollectionReferenceRelation;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.HasReferanceRelation;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.HasReferanceRelation.HasReferenceType;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.HasSingleReferenceRelation;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.IBidirectionalRelation;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.IRelation;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.IRelation.RelDir;
@@ -119,7 +122,8 @@ import org.eclipse.swt.widgets.Display;
@SuppressWarnings("restriction")
public class JpaArtifactFactory {
- private static final JpaArtifactFactory INSTANCE = new JpaArtifactFactory();
+ private static final JpaArtifactFactory INSTANCE = new JpaArtifactFactory();
+ private static String MAPPED_BY_ATTRIBUTE_SPLIT_SEPARATOR = "\\."; //$NON-NLS-1$
private static final int MAX_NUM_OF_ITERATIONS = 25;
private static final int PAUSE_DURATION = 200;
@@ -139,6 +143,8 @@ public class JpaArtifactFactory {
if (!fp.existRedundantIsARelations() && (isARels.size() == 0))
return;
TransactionalEditingDomain ted = fp.getTransactionalEditingDomain();
+ if(ted == null)
+ return;
RecordingCommand rc = new RecordingCommand(ted) {
@Override
protected void doExecute() {
@@ -147,8 +153,7 @@ public class JpaArtifactFactory {
}
};
ted.getCommandStack().execute(rc);
- }
-
+ }
public Collection<IsARelation> produceAllMissingIsARelations(IJPAEditorFeatureProvider fp) {
Collection<JavaPersistentType> persistentTypes = fp.getPersistentTypes();
@@ -213,7 +218,8 @@ public class JpaArtifactFactory {
if (direction == JPAEditorConstants.RELATION_TYPE_BIDIRECTIONAL) {
JavaPersistentAttribute resolvedAttribute = setMappingKeyToAttribute(fp, referencedJPT, referencedAttribute, MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY);
- setMappedByAnnotationAttribute(resolvedAttribute, referencedJPT, ownerAttibute);
+ String mappedByAttr = getMappeByAttribute(fp, ownerJPT, ownerAttibute);
+ setMappedByAnnotationAttribute(resolvedAttribute, referencedJPT, mappedByAttr);
}
}
@@ -228,7 +234,8 @@ public class JpaArtifactFactory {
return;
JavaPersistentAttribute resolvedSingleSideAttribute = setMappingKeyToAttribute(fp, singleSideJPT, singleSideAttibute, MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY);
- setMappedByAnnotationAttribute(resolvedSingleSideAttribute, singleSideJPT, manySideAttribute);
+ String mappedByAttr = getMappeByAttribute(fp, manySideJPT, manySideAttribute);
+ setMappedByAnnotationAttribute(resolvedSingleSideAttribute, singleSideJPT, mappedByAttr);
if (isMap) {
singleSideAttibute.getResourceAttribute().addAnnotation(MapKeyAnnotation.ANNOTATION_NAME);
}
@@ -244,15 +251,31 @@ public class JpaArtifactFactory {
if (direction == JPAEditorConstants.RELATION_TYPE_BIDIRECTIONAL) {
setMappingKeyToAttribute(fp, manySideJPT, manySideAttribute, MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY);
- setMappedByAnnotationAttribute(resolvedSingleSideAttribute, singleSideJPT, manySideAttribute);
+ String mappedByAttr = getMappeByAttribute(fp, manySideJPT, manySideAttribute);
+ setMappedByAnnotationAttribute(resolvedSingleSideAttribute, singleSideJPT, mappedByAttr);
} else {
addJoinColumnIfNecessary(resolvedSingleSideAttribute, singleSideJPT, fp);
}
if (isMap)
singleSideAttibute.getResourceAttribute().addAnnotation(MapKeyAnnotation.ANNOTATION_NAME);
}
+
+ private String getMappeByAttribute(IFeatureProvider fp,
+ JavaPersistentType ownerSideJPT, JavaPersistentAttribute ownerSideAttribute) {
+
+ String mappedByAttr = ownerSideAttribute.getName();
+
+ if(JpaArtifactFactory.instance().hasEmbeddableAnnotation(ownerSideJPT)){
+ HasReferanceRelation ref = JpaArtifactFactory.instance().findFisrtHasReferenceRelationByEmbeddable(ownerSideJPT, (IJPAEditorFeatureProvider)fp);
+ if(ref != null){
+ JavaPersistentAttribute embeddingAttribute = ref.getEmbeddedAnnotatedAttribute();
+ mappedByAttr = embeddingAttribute.getName() + "." + ownerSideAttribute.getName(); //$NON-NLS-1$
+ }
+ }
+ return mappedByAttr;
+ }
- private void setMappedByAnnotationAttribute(JavaPersistentAttribute resolvedAttr, JavaPersistentType type1, JavaPersistentAttribute jpa){
+ private void setMappedByAnnotationAttribute(JavaPersistentAttribute resolvedAttr, JavaPersistentType type1, String jpaName){
JavaAttributeMapping mapping = resolvedAttr.getMapping();
if (!(mapping instanceof RelationshipMapping)) {
@@ -265,7 +288,7 @@ public class JpaArtifactFactory {
}
if (!(annotation instanceof OwnableRelationshipMappingAnnotation))
return;
- ((OwnableRelationshipMappingAnnotation)annotation).setMappedBy(jpa.getName());
+ ((OwnableRelationshipMappingAnnotation)annotation).setMappedBy(jpaName);
}
private JavaPersistentAttribute setMappingKeyToAttribute(IFeatureProvider fp, JavaPersistentType jpt, JavaPersistentAttribute jpa, String mappingKey){
@@ -277,7 +300,7 @@ public class JpaArtifactFactory {
private void addJoinColumnIfNecessary(JavaPersistentAttribute jpa,
JavaPersistentType jpt, IFeatureProvider fp) {
- if (JPAEditorUtil.checkJPAFacetVersion(jpa.getJpaProject(), "1.0") || //$NON-NLS-1$
+ if (JPAEditorUtil.checkJPAFacetVersion(jpa.getJpaProject(), JPAEditorUtil.JPA_PROJECT_FACET_10) ||
JPADiagramPropertyPage.shouldOneToManyUnidirBeOldStyle(jpa
.getJpaProject().getProject()))
return;
@@ -384,7 +407,8 @@ public class JpaArtifactFactory {
if (direction == JPAEditorConstants.RELATION_TYPE_BIDIRECTIONAL) {
JavaPersistentAttribute resolvedInverseSideAttribute = setMappingKeyToAttribute(fp, inverseSideJPT, inverseSideAttibute, MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY);
- setMappedByAnnotationAttribute(resolvedInverseSideAttribute, inverseSideJPT, ownerSideAttribute);
+ String mappedByAttr = getMappeByAttribute(fp, ownerSideJPT, ownerSideAttribute);
+ setMappedByAnnotationAttribute(resolvedInverseSideAttribute, inverseSideJPT, mappedByAttr);
if (isMap)
resolvedInverseSideAttribute.getResourceAttribute().addAnnotation(MapKeyAnnotation.ANNOTATION_NAME);
@@ -392,8 +416,7 @@ public class JpaArtifactFactory {
}
- public void restoreEntityClass(JavaPersistentType jpt,
- IJPAEditorFeatureProvider fp) {
+ public void restoreEntityClass(JavaPersistentType jpt, IJPAEditorFeatureProvider fp) {
fp.restoreEntity(jpt);
}
@@ -478,7 +501,7 @@ public class JpaArtifactFactory {
if (name == null)
name = jpt.getName();
return name;
- }
+ }
public boolean hasNameAnnotation(JavaPersistentType jpt) {
if (jpt == null)
@@ -494,85 +517,153 @@ public class JpaArtifactFactory {
return (mapping.getSpecifiedName() != null);
}
return false;
- }
-
- /*
- @SuppressWarnings("unchecked")
- public String getAttributeName(JavaPersistentAttribute jpa) {
-
- JavaResourcePersistentType jrpt = jpa.getJpaProject()
- .getJavaResourcePersistentType(jpa.getName());
- ASTNode nd = jrpt.getMember().getModifiedDeclaration().getDeclaration();
- if (nd instanceof TypeDeclaration) {
- ListIterator<?> modfs = ((TypeDeclaration) nd).modifiers()
- .listIterator();
- while (modfs.hasNext()) {
- Object modf = modfs.next();
- if (modf instanceof NormalAnnotation) {
- NormalAnnotation an = (NormalAnnotation)modf;
- List<MemberValuePair> vals = an.values();
- if (vals != null) {
- for (int i = 0; i < vals.size(); i++) {
- MemberValuePair mvp = vals.get(i);
- if (mvp.getName().toString().equals("name")) ; //$NON-NLS-1$
- return JPAEditorUtil.stripQuotes(mvp.getValue()
- .toString());
-
- }
- }
- }
- }
- }
- return jpa.getName();
}
- */
- public boolean hasEntityOrMappedSuperclassAnnotation(JavaPersistentType jpt) {
- return hasEntityAnnotation(jpt) || hasMappedSuperclassAnnotation(jpt);
+ /**
+ * Checks whether the the persistent type has any of the following annotations:
+ * Entity, Embeddable or MappedSuperclass
+ * @param jpt
+ * @return true, if the given jpt is annotated, false otherwise.
+ */
+ public boolean hasAnyAnnotationType(JavaPersistentType jpt) {
+ return hasEntityAnnotation(jpt) || hasMappedSuperclassAnnotation(jpt) || hasEmbeddableAnnotation(jpt);
}
+ /**
+ * Checks whether the persistent type is of entity type
+ * @param jpt
+ * @return true, if the given jpt is an entity, false otherwise
+ */
public boolean hasEntityAnnotation(JavaPersistentType jpt) {
return (jpt.getMappingKey() == MappingKeys.ENTITY_TYPE_MAPPING_KEY);
}
+ /**
+ * Checks whether the persistent type is of mapped superclass type.
+ * @param jpt
+ * @return true, if the given jpt is a mapped superclass, false, otherwise.
+ */
public boolean hasMappedSuperclassAnnotation(JavaPersistentType jpt) {
return (jpt.getMappingKey() == MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY);
- }
+ }
+
+ /**
+ * Checks whether the persistent type is of an embeddable type.
+ * @param jpt
+ * @return true, if the given jpt is an embeddable class, false otherwise.
+ */
+ public boolean hasEmbeddableAnnotation(JavaPersistentType jpt){
+ return (jpt.getMappingKey() == MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY);
+ }
public String getSpecifiedEntityName(JavaPersistentType jpt){
JavaTypeMapping jtm = jpt.getMapping();
if (jtm instanceof JavaEntity) {
- JavaEntity gje = (JavaEntity)jtm;
- return gje.getSpecifiedName();
- }
- JavaMappedSuperclass jms = (JavaMappedSuperclass)jtm;
- return jms.getName();
+ JavaEntity gje = (JavaEntity) jtm;
+ return gje.getSpecifiedName();
+ }
+ return jtm.getName();
}
public void renameEntity(JavaPersistentType jpt, String newName) {
JavaTypeMapping jtm = jpt.getMapping();
if (jtm instanceof JavaEntity) {
- JavaEntity gje = (JavaEntity)jtm;
- gje.setSpecifiedName(newName);
+ JavaEntity gje = (JavaEntity) jtm;
+ gje.setSpecifiedName(newName);
+ }
}
+
+ /**
+ * Create inverseSideAttribute of the bidirectional relationship between an embeddable class
+ * and an entity.
+ * @param embeddableOwner - the embeddable class
+ * @param inverseEntity - the entity class
+ * @param mapKeyType
+ * @param isCollection - whether the attribute is of a collection type
+ * @param fp
+ * @return the inverse attribute of the relationship.
+ */
+ public JavaPersistentAttribute addEmbeddedAttribute(JavaPersistentType embeddableOwner, JavaPersistentType inverseEntity, String mapKeyType, boolean isCollection, IJPAEditorFeatureProvider fp){
+ ICompilationUnit ijl = fp.getCompilationUnit(inverseEntity);
+ JavaPersistentType embeddingEntity = null;
+ String attributeName = ""; //$NON-NLS-1$
+ String actName = ""; //$NON-NLS-1$
+ ICompilationUnit cu2 = null;
+ HasReferanceRelation ref = findFisrtHasReferenceRelationByEmbeddable(embeddableOwner, fp);
+ if(ref != null){
+ embeddingEntity = ref.getEmbeddingEntity();
+ attributeName = JPAEditorUtil.decapitalizeFirstLetter(embeddingEntity.getSimpleName());
+ actName = JPAEditorUtil.decapitalizeFirstLetter(embeddingEntity.getSimpleName());
+ cu2 = JPAEditorUtil.getCompilationUnit(embeddingEntity);
+ }
+ return addAttribute(fp, inverseEntity, embeddingEntity, mapKeyType, attributeName, actName, isCollection, ijl, cu2);
}
- public JavaPersistentAttribute addAttribute(IJPAEditorFeatureProvider fp, JavaPersistentType jpt,
- JavaPersistentType attributeType, String attributeName,
- String actName, boolean isCollection, ICompilationUnit cu1,
- ICompilationUnit cu2) {
+ /**
+ * Find the first {@link HasReferenceRelation} for the given embeddable class from all existing
+ * {@link HasReferanceRelation} in the diagram.
+ * @param embeddable - the given embeddable class
+ * @param fp
+ * @return the first {@link HasReferenceRelation} for the given embeddable class.
+ */
+ public HasReferanceRelation findFisrtHasReferenceRelationByEmbeddable(JavaPersistentType embeddable, IJPAEditorFeatureProvider fp){
+ HashSet<HasReferanceRelation> hasReferencesConnections = fp.getAllExistingHasReferenceRelations();
+ for(HasReferanceRelation ref : hasReferencesConnections){
+ if (ref.getEmbeddable().equals(embeddable) && hasEntityAnnotation(ref.getEmbeddingEntity())){
+ return ref;
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Find the first {@link HasReferenceRelation} for the given embeddable class from all existing
+ * {@link HasReferanceRelation} in the diagram.
+ * @param embeddable - the given embeddable class
+ * @param fp
+ * @return the first {@link HasReferenceRelation} for the given embeddable class.
+ */
+ public Set<HasReferanceRelation> findAllHasReferenceRelationsByEmbeddable(JavaPersistentType embeddable, IJPAEditorFeatureProvider fp){
+ HashSet<HasReferanceRelation> allHasRefForEmbeddable = new HashSet<HasReferanceRelation>();
+ HashSet<HasReferanceRelation> hasReferencesConnections = fp.getAllExistingHasReferenceRelations();
+ for(HasReferanceRelation ref : hasReferencesConnections){
+ if (ref.getEmbeddable().equals(embeddable) || ref.getEmbeddingEntity().equals(embeddable)){
+ allHasRefForEmbeddable.add(ref);
+ }
+ }
+ return allHasRefForEmbeddable;
+ }
+
+ public Set<HasReferanceRelation> findAllHasReferenceRelsByEmbeddableWithEntity(JavaPersistentType embeddable, IJPAEditorFeatureProvider fp){
+ Set<HasReferanceRelation> allRefs = findAllHasReferenceRelationsByEmbeddable(embeddable, fp);
+ Set<HasReferanceRelation> entityRefs = new HashSet<HasReferanceRelation>();
+ for(HasReferanceRelation ref : allRefs){
+ if(hasEntityAnnotation(ref.getEmbeddingEntity())){
+ entityRefs.add(ref);
+ }
+ }
- return addAttribute(fp, jpt, attributeType, null, attributeName,
- actName, isCollection, cu1, cu2);
+ return entityRefs;
}
+ /**
+ * Create a relationship attribute.
+ * @param fp
+ * @param jpt - the referencing {@link JavaPersistentType}
+ * @param attributeType - the referenced {@link JavaPersistentType}
+ * @param mapKeyType
+ * @param attributeName - the name of the attribute
+ * @param actName - the actual name of the attribute
+ * @param isCollection - whether the attribute is of a collection type
+ * @param cu1 - the {@link ICompilationUnit} of the referencing {@link JavaPersistentType}
+ * @param cu2 - the {@link ICompilationUnit} of the referenced {@link JavaPersistentType}
+ * @return the newly created relationship attribute.
+ */
public JavaPersistentAttribute addAttribute(IJPAEditorFeatureProvider fp, JavaPersistentType jpt,
JavaPersistentType attributeType, String mapKeyType, String attributeName,
String actName, boolean isCollection, ICompilationUnit cu1,
ICompilationUnit cu2) {
-
- fp.getDiagramTypeProvider().getDiagramEditor().selectPictogramElements(new PictogramElement[] {});
-
+
try {
if (doesAttributeExist(jpt, actName)) {
return (JavaPersistentAttribute) jpt
@@ -589,20 +680,18 @@ public class JpaArtifactFactory {
} catch (InterruptedException e) {
JPADiagramEditorPlugin.logError("Cannot add a new attribute with name " + actName, e); //$NON-NLS-1$
}
-
- if(jpt.getAttributeNamed(attributeName) == null){
- System.out.println("bahhhhhh go +++++++++++++ " + attributeName);
- jpt.getJavaResourceType().getJavaResourceCompilationUnit().synchronizeWithJavaSource();
- }
+
JavaPersistentAttribute res = jpt.getAttributeNamed(actName);
- if(res == null){
- System.out.println("6ti eba majkata ====================is");
- jpt.getJavaResourceType().getJavaResourceCompilationUnit().synchronizeWithJavaSource();
- res = jpt.getAttributeNamed(actName);
- }
return res;
}
+ /**
+ * Checks whether an entity's attribute is of a collection type
+ * @param entityShape - the pictogram element for the entity in the diagram
+ * @param fp
+ * @param attrTxt - the attribute name
+ * @return true, if the entity's attribute is of a collection type, false otherwise.
+ */
public boolean isCollection(ContainerShape entityShape,
IJPAEditorFeatureProvider fp, String attrTxt) {
Object ob = fp.getBusinessObjectForPictogramElement(entityShape);
@@ -626,6 +715,14 @@ public class JpaArtifactFactory {
return false;
}
+ /**
+ * Checks whether the getter method of an entity's attribute returns a collection type.
+ * @param entityShape - the pictogram element for the entity in the diagram
+ * @param fp
+ * @param attrTxt - the attribute name
+ * @return true if the getter method of an attribute returns a collection type,
+ * false otherwise.
+ */
public boolean isGetterMethodReturnTypeCollection(
ContainerShape entityShape, IJPAEditorFeatureProvider fp,
String attrTxt) {
@@ -652,6 +749,13 @@ public class JpaArtifactFactory {
return false;
}
+ /**
+ * Creates a new basic entity attribute of type "java.lang.String"
+ * @param jpt - the entity, in which the new attribute will be added
+ * @param isCollection - whether the attribute is a collection
+ * @param fp
+ * @return the newly created attribute.
+ */
public String createNewAttribute(JavaPersistentType jpt,
boolean isCollection, IJPAEditorFeatureProvider fp) {
@@ -662,15 +766,22 @@ public class JpaArtifactFactory {
"", newAttrName, isCollection, fp); //$NON-NLS-1$
}
- /*
- * public String createNewAttribute(JavaPersistentType jpt, String attrName,
- * String attrTypeName, String annotation, String actName, boolean
- * isCollection, JPAEditorFeatureProvider fp) {
- *
- * ICompilationUnit ijl = fp.getCompilationUnit(jpt); return
- * addNewAttribute(jpt, ijl, attrName, attrTypeName, annotation, actName,
- * isCollection, fp); }
- */
+ public String addNewAttribute(JavaPersistentType jpt, ICompilationUnit cu,
+ String attrName, String attrTypeName, String annotation,
+ String actName, boolean isCollection, IJPAEditorFeatureProvider fp) {
+
+ try {
+ List<String> annotations = new LinkedList<String>();
+ annotations.add(annotation);
+ boolean isMethodAnnotated = JpaArtifactFactory.instance()
+ .isMethodAnnotated(jpt);
+ makeNewAttribute(fp, jpt, cu, attrName, attrTypeName, null, actName,
+ annotations, isCollection, isMethodAnnotated);
+ } catch (JavaModelException e) {
+ JPADiagramEditorPlugin.logError("Cannot create a new attribute with name " + attrName, e); //$NON-NLS-1$
+ }
+ return attrName;
+ }
public JavaPersistentAttribute createANewAttribute(JavaPersistentType jpt,
String attrName, String attrTypeName, String[] attrTypeElementNames,
@@ -682,7 +793,7 @@ public class JpaArtifactFactory {
attrTypeElementNames, actName, annotations, isCollection,
isMethodAnnotated, fp);
}
-
+
private JavaPersistentAttribute addANewAttribute(JavaPersistentType jpt,
ICompilationUnit cu, String attrName, String attrTypeName,
String[] attrTypeElementNames, String actName,
@@ -700,31 +811,12 @@ public class JpaArtifactFactory {
return attr;
}
- public String addNewAttribute(JavaPersistentType jpt, ICompilationUnit cu,
- String attrName, String attrTypeName, String annotation,
- String actName, boolean isCollection, IJPAEditorFeatureProvider fp) {
-
- try {
- List<String> annotations = new LinkedList<String>();
- annotations.add(annotation);
- boolean isMethodAnnotated = JpaArtifactFactory.instance()
- .isMethodAnnotated(jpt);
- makeNewAttribute(fp, jpt, cu, attrName, attrTypeName, null, actName,
- annotations, isCollection, isMethodAnnotated);
- } catch (JavaModelException e) {
- JPADiagramEditorPlugin.logError("Cannot create a new attribute with name " + attrName, e); //$NON-NLS-1$
- }
- return attrName;
- }
-
public JavaPersistentAttribute makeNewAttribute(IFeatureProvider fp, JavaPersistentType jpt,
ICompilationUnit cu, String attrName, String attrTypeName,
String[] attrTypes, String actName,
List<String> annotations, boolean isCollection,
boolean isMethodAnnotated) throws JavaModelException {
-
- fp.getDiagramTypeProvider().getDiagramEditor().selectPictogramElements(new PictogramElement[] {});
-
+
Command createNewAttributeCommand = new CreateNewAttributeCommand(jpt, cu, attrName, attrTypeName, attrTypes, actName, annotations, isCollection, isMethodAnnotated);
try {
getJpaProjectManager().execute(createNewAttributeCommand, SynchronousUiCommandExecutor.instance());
@@ -736,6 +828,12 @@ public class JpaArtifactFactory {
return jpa;
}
+ /**
+ * Delete an attribute from the entity.
+ * @param jpt - the entity from which the attribute will be deleted
+ * @param attributeName - the name of the attribute to be deleted
+ * @param fp
+ */
public void deleteAttribute(JavaPersistentType jpt, String attributeName,
IJPAEditorFeatureProvider fp) {
@@ -747,6 +845,13 @@ public class JpaArtifactFactory {
}
}
+ /**
+ * Generate unique attribute name.
+ * @param jpt - the entity in which the attribute will be created.
+ * @param attrTypeName - the basic attribute name
+ * @param fp
+ * @return an unique attribute name.
+ */
private String genUniqueAttrName(JavaPersistentType jpt,
String attrTypeName, IJPAEditorFeatureProvider fp) {
@@ -788,41 +893,42 @@ public class JpaArtifactFactory {
return name;
}
+ /**
+ * Get all annotation for the given attribute.
+ * @param persistentAttribite
+ * @return an array of all current annotations of the given attribute.
+ */
public Annotation[] getAnnotations(JavaPersistentAttribute persistentAttribite) {
JavaResourceAttribute jrpt = persistentAttribite.getResourceAttribute();
Annotation[] res = new Annotation[jrpt.getAnnotationsSize()];
- //mappingAnnotationsSize() + jrpt.supportingAnnotationsSize()];
int c = 0;
for (Annotation annotation : jrpt.getAnnotations()) {
res[c] = annotation;
c++;
}
- /*
- it = jrpt.supportingAnnotations();
- while (it.hasNext()) {
- res[c] = it.next();
- c++;
- }
- */
return res;
}
- public HashSet<String> getAnnotationNames(
- JavaPersistentAttribute persistentAttribite) {
+ /**
+ * Get all annotations as string for the given attribute.
+ * @param persistentAttribite
+ * @return a set of strings of all current annotation names of the given attribute.
+ */
+ public HashSet<String> getAnnotationNames(JavaPersistentAttribute persistentAttribite) {
JavaResourceAttribute jrpt = persistentAttribite.getResourceAttribute();
HashSet<String> res = new HashSet<String>();
for (Annotation annotation : jrpt.getAnnotations()) {
res.add(JPAEditorUtil.returnSimpleName(annotation.getAnnotationName()));
}
- /*
- it = jrpt.supportingAnnotations();
- while (it.hasNext())
- res.add(JPAEditorUtil.cutFromLastDot(it.next().getAnnotationName()));
- */
return res;
}
+ /**
+ * Get all annotations as string for the given attribute.
+ * @param persistentAttribite
+ * @return a list of strings of all current annotation names of the given attribute.
+ */
public List<String> getAnnotationStrings(
JavaPersistentAttribute persistentAttribite) {
@@ -834,17 +940,14 @@ public class JpaArtifactFactory {
org.eclipse.jdt.core.dom.Annotation jdtAn = an.getAstAnnotation(jdtCU);
res.add(jdtAn.toString());
}
- /*
- it = jrpt.supportingAnnotations();
- while (it.hasNext()) {
- Annotation an = it.next();
- org.eclipse.jdt.core.dom.Annotation jdtAn = an.getJdtAnnotation(jdtCU);
- res.add(jdtAn.toString());
- }
- */
return res;
}
+ /**
+ * Checks whether the attribute is an owner of the relationship.
+ * @param at
+ * @return true, if the attribute is owner of the relationship, false otherwise.
+ */
private boolean isNonOwner(JavaPersistentAttribute at) {
JavaAttributeMapping jam = at.getMapping();
if (!(jam.getMappingAnnotation() instanceof OwnableRelationshipMappingAnnotation))
@@ -853,10 +956,16 @@ public class JpaArtifactFactory {
return nom.getMappedBy() != null;
}
- public Collection<IRelation> produceAllRelations(
+ /**
+ * Collect all relationships for the given {@link JavaPersistentType}.
+ * @param newJPT
+ * @param fp
+ * @return an collection of all relationships for the given {@link JavaPersistentType}.
+ */
+ private Collection<IRelation> produceAllIRelations(
JavaPersistentType newJPT, IJPAEditorFeatureProvider fp) {
- Collection<IRelation> res = produceRelations(newJPT, fp);
+ Collection<IRelation> res = produceIRelations(newJPT, null, fp);
Iterator<IRelation> it = res.iterator();
HashSet<JavaPersistentType> checkedEntities = new HashSet<JavaPersistentType>();
while (it.hasNext()) {
@@ -874,83 +983,78 @@ public class JpaArtifactFactory {
if (jpt == null)
continue;
//if (!checkedEntities.contains(jpt)) {
- Collection<IRelation> rels = produceRelations(jpt, newJPT, fp);
- res.addAll(rels);
+ Collection<IRelation> rels = produceIRelations(jpt, newJPT, fp);
+ res.addAll(rels);
//}
}
return res;
}
- private Collection<IRelation> produceRelations(
- JavaPersistentType newJPT, IJPAEditorFeatureProvider fp) {
-
- HashSet<IRelation> res = new HashSet<IRelation>();
- for (JavaPersistentAttribute at : newJPT.getAttributes()) {
- IRelation rel = produceRelation(at, fp);
- if (rel != null)
- res.add(rel);
- }
- return res;
- }
-
- public boolean isRelationAnnotated(JavaPersistentAttribute jpa) {
+ /**
+ * Collect all "has-reference" relationships for the given {@link JavaPersistentType}.
+ * @param newJPT
+ * @param fp
+ * @return an collection of all "has-reference" relationships for the given {@link JavaPersistentType}.
+ */
+ public Collection<HasReferanceRelation> produceAllEmbeddedRelations(JavaPersistentType jpt, IJPAEditorFeatureProvider fp) {
- HashSet<String> anNames = getAnnotationNames(jpa);
- Iterator<String> it = anNames.iterator();
+ Collection<HasReferanceRelation> res = produceEmbRelations(jpt, null, fp);
+ Iterator<HasReferanceRelation> it = res.iterator();
+ HashSet<JavaPersistentType> checkedEntities = new HashSet<JavaPersistentType>();
while (it.hasNext()) {
- String anName = it.next();
- if (JPAEditorConstants.RELATION_ANNOTATIONS.contains(anName))
- return true;
+ HasReferanceRelation rel = it.next();
+ checkedEntities.add(rel.getEmbeddable());
+ checkedEntities.add(rel.getEmbeddingEntity());
}
- return false;
- }
-
- public IRelation produceRelation(
- JavaPersistentAttribute persistentAttribite,
- IJPAEditorFeatureProvider fp) {
-
- JavaResourceAttribute jrpa = persistentAttribite
- .getResourceAttribute();
-
- IRelation res = null;
- Annotation[] ans = getAnnotations(persistentAttribite);
- for (Annotation an : ans) {
- String annotationName = JPAEditorUtil.returnSimpleName(an.getAnnotationName());
- if (JPAEditorConstants.RELATION_ANNOTATIONS.contains(annotationName)) {
- String relTypeName = getRelTypeName((RelationshipMappingAnnotation)an, jrpa);
- JavaPersistentType relJPT = (JavaPersistentType)fp.getBusinessObjectForKey(relTypeName);
- if (relJPT != null)
- res = produceRelation(persistentAttribite, an, relJPT, fp);
- return res;
- }
+ List<Shape> shapes = fp.getDiagramTypeProvider().getDiagram().getChildren();
+ Iterator<Shape> iter = shapes.iterator();
+ while (iter.hasNext()) {
+ Shape sh = iter.next();
+ JavaPersistentType embeddingEntity = (JavaPersistentType) fp.getBusinessObjectForPictogramElement(sh);
+ if (embeddingEntity == null)
+ continue;
+ Collection<HasReferanceRelation> rels = produceEmbRelations(embeddingEntity, jpt, fp);
+ res.addAll(rels);
}
return res;
-
- }
-
- private Collection<IRelation> produceRelations(JavaPersistentType jpt1,
- JavaPersistentType jpt2, IJPAEditorFeatureProvider fp) {
+ }
+
+ /**
+ * Collect all "has-reference" relationships for the given {@link JavaPersistentType}.
+ * @param embeddingEntity
+ * @param embeddable
+ * @param fp
+ * @return an collection of all "has-reference" relationships for the given {@link JavaPersistentType}.
+ */
+ private Collection<HasReferanceRelation> produceEmbRelations(JavaPersistentType embeddingEntity,
+ JavaPersistentType embeddable, IJPAEditorFeatureProvider fp) {
- Collection<IRelation> resSet = new HashSet<IRelation>();
- IRelation res = null;
- for (JavaPersistentAttribute at : jpt1.getAttributes()) {
- IResource r = at.getParent().getResource();
+ Collection<HasReferanceRelation> resSet = new HashSet<HasReferanceRelation>();
+ HasReferanceRelation res = null;
+ for (JavaPersistentAttribute embeddingAttribute : embeddingEntity.getAttributes()) {
+ IResource r = embeddingAttribute.getParent().getResource();
if (!r.exists())
throw new RuntimeException();
try {
- JavaResourceAttribute jrpa = at.getResourceAttribute();
- Annotation[] ans = this.getAnnotations(at);
+ JavaResourceAttribute jrpa = embeddingAttribute.getResourceAttribute();
+ Annotation[] ans = this.getAnnotations(embeddingAttribute);
for (Annotation an : ans) {
String annotationName = JPAEditorUtil.returnSimpleName(an.getAnnotationName());
- if (JPAEditorConstants.RELATION_ANNOTATIONS.contains(annotationName)) {
- String relTypeName = getRelTypeName((RelationshipMappingAnnotation)an, jrpa);
- if (!relTypeName.equals(jpt2.getName()))
- continue;
- JavaPersistentType relJPT = (JavaPersistentType) fp
- .getBusinessObjectForKey(jpt2.getName());
- res = produceRelation(at, an, relJPT, fp);
- if (res != null)
- resSet.add(res);
+ if (JPAEditorConstants.ANNOTATION_EMBEDDED.equals(annotationName) ||
+ JPAEditorConstants.ANNOTATION_ELEMENT_COLLECTION.equals(annotationName)
+ || JPAEditorConstants.ANNOTATION_EMBEDDED_ID.equals(annotationName)) {
+ String attributeTypeName = getRelTypeName(an, jrpa);
+ if(embeddable != null) {
+ if (!attributeTypeName.equals(embeddable.getName()))
+ continue;
+ }
+
+ JavaPersistentType embeddableClass = findJPT(embeddingAttribute, fp, an);
+ if (embeddableClass != null) {
+ res = produceEmbeddedRelation(embeddingAttribute, an, embeddableClass, fp);
+ if (res != null)
+ resSet.add(res);
+ }
}
}
@@ -963,134 +1067,69 @@ public class JpaArtifactFactory {
}
/**
- * Returns the relation annotation of the given attribute if there is any. If not - returns null
- *
- * @param at
- * @return
+ * Create a new relationship.
+ * @param persistentAttribite
+ * @param jpt2
+ * @param fp
+ * @return the newly created relationship.
*/
-
- /*
- private IAnnotation getRelationAnnotation(JavaPersistentAttribute at) {
- JavaResourcePersistentAttribute jrpa = at.getResourcePersistentAttribute();
- IAnnotatable m = getAttributeMember(at);
- IAnnotation[] ans = null;
- try {
- ans = m.getAnnotations();
- } catch (JavaModelException e) {
- tracer.error("", e);
- return null;
- }
- for (IAnnotation an : ans) {
- if (JPAEditorConstants.RELATION_ANNOTATIONS.contains(JPAEditorUtil.cutFromLastDot(an.getElementName()))) {
- return an;
- }
+ public IRelation produceIRelation(JavaPersistentAttribute persistentAttribite, JavaPersistentType jpt2,
+ IJPAEditorFeatureProvider fp) {
+
+ IRelation res = null;
+ Annotation[] ans = getAnnotations(persistentAttribite);
+ for (Annotation an : ans) {
+ String annotationName = JPAEditorUtil.returnSimpleName(an.getAnnotationName());
+ if (JPAEditorConstants.RELATION_ANNOTATIONS.contains(annotationName)) {
+ if(jpt2 != null){
+ JavaResourceAttribute jrpa = persistentAttribite.getResourceAttribute();
+ String relTypeName = getRelTypeName(an, jrpa);
+ if (!relTypeName.equals(jpt2.getName()))
+ continue;
+ }
+
+ JavaPersistentType relJPT = findJPT(persistentAttribite, fp, an);
+ if (relJPT != null) {
+ res = produceRelation(persistentAttribite, an, relJPT, fp);
+ }
+ }
}
- return null;
+ return res;
+
}
- */
-
- /*
- public JavaPersistentAttribute getRelatedAttribute(JavaPersistentType jpt,
- JavaPersistentType relJPT) {
-
- ListIterator<JavaPersistentAttribute> it = relJPT.attributes();
- while (it.hasNext()) {
- JavaPersistentAttribute relEntityAt = it.next();
- JavaResourcePersistentAttribute jrpa = relEntityAt
- .getResourcePersistentAttribute();
- ASTNode nd = jrpa.getMember().getModifiedDeclaration()
- .getDeclaration();
- if ((nd instanceof MethodDeclaration)
- || (nd instanceof FieldDeclaration)) {
- ListIterator<?> modfs = ((BodyDeclaration) nd).modifiers()
- .listIterator();
- while (modfs.hasNext()) {
- Object modf = modfs.next();
- if (modf instanceof Annotation) {
- Annotation an = (Annotation) modf;
- String annotationName = an.getTypeName()
- .getFullyQualifiedName();
- annotationName = annotationName
- .substring(annotationName.lastIndexOf('.') + 1);
- if (JPAEditorConstants.RELATION_ANNOTATIONS
- .contains(annotationName)) {
- String ownerTypeName = getRelTypeName(an, jrpa);
- if (!ownerTypeName.equals(jpt.getName()))
- continue;
- return relEntityAt;
- }
- }
- }
- }
+ /**
+ * Gets the parent {@link JavaPersistentType} of an attribute
+ * @param persistentAttribite
+ * @param fp
+ * @param an - attribute's relationship annotation
+ * @return the parent {@link JavaPersistentType} of an attribute.
+ */
+ public JavaPersistentType findJPT(JavaPersistentAttribute persistentAttribite, IJPAEditorFeatureProvider fp, Annotation an) {
+ JavaResourceAttribute jrpa = persistentAttribite.getResourceAttribute();
+ String relTypeName = getRelTypeName(an, jrpa);
+ JavaPersistentType relJPT = (JavaPersistentType)fp.getBusinessObjectForKey(relTypeName);
+ return relJPT;
+ }
+
+ private Collection<IRelation> produceIRelations(
+ JavaPersistentType newJPT, JavaPersistentType jpt2, IJPAEditorFeatureProvider fp) {
+
+ Set<IRelation> res = new HashSet<IRelation>();
+ for (JavaPersistentAttribute at : newJPT.getAttributes()) {
+ IRelation rel = produceIRelation(at, jpt2, fp);
+ if (rel != null)
+ res.add(rel);
}
- return null;
+ return res;
}
- */
-
- /*
- * If the given attribute is relation annotated and points to some entity,
- * which is visualized in the diagram this method returns the pointed
- * entity. Otherwise - null
+ /**
+ * Returns the {@link JavaPersistentType} registered in the {@link PersistenceUnit} with the given name.
+ * @param name
+ * @param pu
+ * @return the {@link JavaPersistentType} registered in the {@link PersistenceUnit} with the given name.
*/
-
- /*
- public JavaPersistentType getRelatedEntity(JavaPersistentAttribute jpa,
- IJPAEditorFeatureProvider fp) {
-
- JavaResourcePersistentAttribute jrpa = jpa
- .getResourcePersistentAttribute();
- IType t = jrpa.getJavaResourceCompilationUnit().getCompilationUnit().findPrimaryType();
- IAnnotatable m = getAttributeMember(jpa);
- IAnnotation[] ans = m.getAnnotations();
- for (IAnnotation an : ans) {
- String annotationName = an.getElementName();
- annotationName = JPAEditorUtil.cutFromLastDot(annotationName);
-
- if (JPAEditorConstants.RELATION_ANNOTATIONS
- .contains(annotationName)) {
- String relTypeName = getRelTypeName(an, jrpa);
- JavaPersistentType relJPT = (JavaPersistentType) jpa
- .getPersistentType().getPersistenceUnit()
- .getPersistentType(relTypeName);
- if (relJPT != null)
- if (fp.getPictogramElementForBusinessObject(relJPT) != null)
- return relJPT;
- }
-
-
- }
-
- if ((nd instanceof MethodDeclaration)
- || (nd instanceof FieldDeclaration)) {
- ListIterator<?> modfs = ((BodyDeclaration) nd).modifiers()
- .listIterator();
- while (modfs.hasNext()) {
- Object modf = modfs.next();
- if (modf instanceof Annotation) {
- Annotation an = (Annotation)modf;
- String annotationName = an.getTypeName()
- .getFullyQualifiedName();
- annotationName = annotationName.substring(annotationName
- .lastIndexOf('.') + 1);
- if (JPAEditorConstants.RELATION_ANNOTATIONS
- .contains(annotationName)) {
- String relTypeName = getRelTypeName(an, jrpa);
- JavaPersistentType relJPT = (JavaPersistentType) jpa
- .getPersistentType().getPersistenceUnit()
- .getPersistentType(relTypeName);
- if (relJPT != null)
- if (fp.getPictogramElementForBusinessObject(relJPT) != null)
- return relJPT;
- }
- }
- }
- }
- return null;
- }
- */
-
public JavaPersistentType getJPT(String name, PersistenceUnit pu) {
JavaPersistentType jpt = (JavaPersistentType) pu.getPersistentType(name);
int cnt = 0;
@@ -1106,9 +1145,11 @@ public class JpaArtifactFactory {
return jpt;
}
- /*
- * Return all the attributes belonging to another entities and
- * involved in a relation with the entity given as parameter
+ /**
+ * Returns all the attributes belonging to another entities and
+ * involved in a relationship with the given entity.
+ * @param jpt
+ * @return a set of all attributes of an entity involved in relationship with the given entity.
*/
public Set<JavaPersistentAttribute> getRelatedAttributes(JavaPersistentType jpt) {
Set<JavaPersistentAttribute> res = new HashSet<JavaPersistentAttribute>();
@@ -1138,11 +1179,12 @@ public class JpaArtifactFactory {
return res;
}
- /*
- * Return the attribute (if there is any) belonging to jpt1 and
- * involved in a relation with jpt
+ /**
+ * Return the attribute (if any) belonging to jpt and involved in a relationship with relJPT.
+ * @param jpt
+ * @param relJPT
+ * @return the attribute belonging to jpt and involved in a relationship with relJPT.
*/
-
private Set<JavaPersistentAttribute> getRelAttributes(JavaPersistentType jpt,
JavaPersistentType relJPT) {
@@ -1155,8 +1197,10 @@ public class JpaArtifactFactory {
String annotationName = null;
for (Annotation an : ans) {
annotationName = JPAEditorUtil.returnSimpleName(an.getAnnotationName());
- if (JPAEditorConstants.RELATION_ANNOTATIONS.contains(annotationName)) {
- String relTypeName = getRelTypeName((RelationshipMappingAnnotation)an, at.getResourceAttribute());
+ if (JPAEditorConstants.RELATION_ANNOTATIONS.contains(annotationName) || JPAEditorConstants.ANNOTATION_EMBEDDED.equals(annotationName)
+ || JPAEditorConstants.ANNOTATION_ELEMENT_COLLECTION.equals(annotationName)
+ || JPAEditorConstants.ANNOTATION_EMBEDDED_ID.equals(annotationName)) {
+ String relTypeName = getRelTypeName(an, at.getResourceAttribute());
if (!relTypeName.equals(jpt.getName()))
continue;
res.add(at);
@@ -1166,12 +1210,11 @@ public class JpaArtifactFactory {
return res;
}
-
public void renameEntityClass(JavaPersistentType jpt, String newEntityName, IJPAEditorFeatureProvider fp) {
Command renameEntityCommand = new RenameEntityCommand(jpt, newEntityName, fp);
try {
- getJpaProjectManager().execute(renameEntityCommand, SynchronousUiCommandExecutor.instance());
+ getJpaProjectManager().execute(renameEntityCommand);
} catch (InterruptedException e) {
JPADiagramEditorPlugin.logError("Cannot rename entity " + jpt.getName(), e); //$NON-NLS-1$
}
@@ -1191,16 +1234,6 @@ public class JpaArtifactFactory {
JavaResourceAttribute jra = oldAt
.getResourceAttribute();
fp.addRemoveIgnore((JavaPersistentType)oldAt.getParent(), jra.getName());
- IRelation rel = fp.getRelationRelatedToAttribute(oldAt);
- String inverseAttributeName = null;
- JavaPersistentType inverseJPT = null;
- if (IBidirectionalRelation.class.isInstance(rel)) {
- inverseJPT = rel.getInverse();
- if (inverseJPT != oldAt.getParent()) {
- pu = JpaArtifactFactory.INSTANCE.getPersistenceUnit(jpt);
- inverseAttributeName = rel.getInverseAttributeName();
- }
- }
Command renameAttributeCommand = new RenameAttributeCommand(jpt, oldName, newName, fp);
getJpaProjectManager().execute(renameAttributeCommand, SynchronousUiCommandExecutor.instance());
@@ -1209,22 +1242,45 @@ public class JpaArtifactFactory {
if (newAt == null) {
JPADiagramEditorPlugin.logError("The attribute " + newName + " could not be resolved", new NullPointerException()); //$NON-NLS-1$ //$NON-NLS-2$
}
+
fp.addRemoveIgnore(jpt, oldAt.getName());
try {
fp.replaceAttribute(oldAt, newAt);
} catch (Exception e) {
return newAt;
}
+
+ updateIRelationshipAttributes(jpt, inverseEntityName, fp, pu, oldAt,
+ newAt);
+
+ return newAt;
+ }
+
+ private void updateIRelationshipAttributes(JavaPersistentType jpt,
+ String inverseEntityName, IJPAEditorFeatureProvider fp,
+ PersistenceUnit pu, JavaPersistentAttribute oldAt,
+ JavaPersistentAttribute newAt) throws InterruptedException {
+ IRelation rel = fp.getRelationRelatedToAttribute(oldAt);
+ String inverseAttributeName = null;
+ JavaPersistentType inverseJPT = null;
+ if (IBidirectionalRelation.class.isInstance(rel)) {
+ inverseJPT = rel.getInverse();
+ if (inverseJPT != oldAt.getParent()) {
+ pu = JpaArtifactFactory.INSTANCE.getPersistenceUnit(jpt);
+ inverseAttributeName = rel.getInverseAttributeName();
+ }
+ }
+
if (inverseAttributeName != null) {
- Command changeMappedByValueCommand = new SetMappedByNewValueCommand(fp, pu, inverseEntityName, inverseAttributeName, newAt, rel);
+ Command changeMappedByValueCommand = new SetMappedByNewValueCommand(fp, pu, inverseEntityName, inverseAttributeName, newAt, oldAt, rel);
getJpaProjectManager().execute(changeMappedByValueCommand, SynchronousUiCommandExecutor.instance());
}
if (rel != null)
updateRelation(jpt, fp, rel);
-
- return newAt;
}
+
+
private JpaProjectManager getJpaProjectManager() {
return (JpaProjectManager) ResourcesPlugin.getWorkspace().getAdapter(JpaProjectManager.class);
}
@@ -1239,17 +1295,19 @@ public class JpaArtifactFactory {
}
}
- public JavaPersistentAttribute renameAttribute(JavaPersistentAttribute jpa,
- String newName, String newEntityName, IJPAEditorFeatureProvider fp) throws InterruptedException {
- return renameAttribute((JavaPersistentType)jpa.getParent(), jpa.getName(), newName,
- newEntityName, fp);
- }
-
+ /**
+ * Create a new {@link IRelation}.
+ * @param persistentAttribite
+ * @param an
+ * @param relJPT
+ * @param fp
+ * @return the newly created {@link IRelation}
+ */
private IRelation produceRelation(JavaPersistentAttribute persistentAttribite, Annotation an,
JavaPersistentType relJPT, IJPAEditorFeatureProvider fp) {
Hashtable<JavaPersistentAttribute, Annotation> ht = getRelAttributeAnnotation(
- persistentAttribite, relJPT);
+ persistentAttribite, relJPT, fp);
if (ht == null) {
return produceUniDirRelation((JavaPersistentType)persistentAttribite
.getParent(), persistentAttribite, an, relJPT, fp);
@@ -1263,8 +1321,49 @@ public class JpaArtifactFactory {
}
+ /**
+ * Create a new {@link HasReferanceRelation}.
+ * @param embeddingAttribute
+ * @param an
+ * @param embeddable
+ * @param fp
+ * @return the newly created {@link HasReferanceRelation}.
+ */
+ private HasReferanceRelation produceEmbeddedRelation(JavaPersistentAttribute embeddingAttribute, Annotation an,
+ JavaPersistentType embeddable, IJPAEditorFeatureProvider fp) {
+
+ if (!JPAEditorUtil.getCompilationUnit((JavaPersistentType) embeddingAttribute.getParent()).exists())
+ return null;
+ JavaPersistentType embeddingEntity = (JavaPersistentType) embeddingAttribute.getParent();
+ String annotationName = JPAEditorUtil.returnSimpleName(an.getAnnotationName());
+ String embeddedAttributeName = embeddingAttribute.getName();
+ HasReferanceRelation res = null;
+ if (annotationName.equals(JPAEditorConstants.ANNOTATION_EMBEDDED) || JPAEditorConstants.ANNOTATION_EMBEDDED_ID.equals(annotationName)) {
+ if (!fp.doesEmbeddedRelationExist(embeddable, embeddingEntity, embeddedAttributeName, HasReferenceType.SINGLE)) {
+ res = new HasSingleReferenceRelation(embeddingEntity, embeddable);
+ }
+ } else if (annotationName.equals(JPAEditorConstants.ANNOTATION_ELEMENT_COLLECTION)) {
+ if (!fp.doesEmbeddedRelationExist(embeddable, embeddingEntity, embeddedAttributeName, HasReferenceType.COLLECTION)){
+ res = new HasCollectionReferenceRelation(embeddingEntity, embeddable);
+ }
+ }
+ if (res != null){
+ res.setEmbeddedAnnotatedAttribute(embeddingAttribute);
+ }
+ return res;
+ }
+
+ /**
+ * Determine whether the relationship is biderectional or unidirectional.
+ * If there is a mappedBy attribute, which value is the same as the given attribute,
+ * then the relationship is bidirectional, oderwise - unidirectional.
+ * @param jpa - the owner relationship attribute
+ * @param relJPT - inverse {@link JavaPersistentType}.
+ * @param fp
+ * @return a {@link Hashtable} containing the pair: inverseAttribute <-> relation annotation.
+ */
private Hashtable<JavaPersistentAttribute, Annotation> getRelAttributeAnnotation(
- JavaPersistentAttribute jpa, JavaPersistentType relJPT) {
+ JavaPersistentAttribute jpa, JavaPersistentType relJPT, IJPAEditorFeatureProvider fp) {
JavaPersistentType jpt = (JavaPersistentType)jpa.getParent();
for (JavaPersistentAttribute relEntAt : relJPT.getAttributes()) {
@@ -1276,14 +1375,28 @@ public class JpaArtifactFactory {
for (Annotation an : ans) {
String annotationName = JPAEditorUtil.returnSimpleName(an.getAnnotationName());
if (JPAEditorConstants.RELATION_ANNOTATIONS.contains(annotationName)) {
- String relTypeName = getRelTypeName((RelationshipMappingAnnotation)an, relJRA);
- if (!relTypeName.equals(jpt.getName()))
- continue;
+
JavaAttributeMapping mp = relEntAt.getMapping();
if (!OwnableRelationshipMappingAnnotation.class.isInstance(mp.getMappingAnnotation()))
continue;
- String mappedBy = ((OwnableRelationshipMappingAnnotation)mp.getMappingAnnotation()).getMappedBy();
- if (!jpa.getName().equals(mappedBy))
+
+ if(an instanceof OwnableRelationshipMappingAnnotation) {
+ String mappedByAttr = ((OwnableRelationshipMappingAnnotation)an).getMappedBy();
+ if(mappedByAttr == null)
+ continue;
+
+ String[] mappedByStrings = mappedByAttr.split(MAPPED_BY_ATTRIBUTE_SPLIT_SEPARATOR);
+ if(mappedByStrings.length>1){
+ jpt = getInvolvedEntity(fp, jpt, relEntAt, an, mappedByStrings);
+ } else {
+ String mappedBy = ((OwnableRelationshipMappingAnnotation)mp.getMappingAnnotation()).getMappedBy();
+ if (!jpa.getName().equals(mappedBy))
+ continue;
+ }
+ }
+
+ String relTypeName = getRelTypeName(an, relJRA);
+ if (!relTypeName.equals(jpt.getName()))
continue;
Hashtable<JavaPersistentAttribute, Annotation> ht = new Hashtable<JavaPersistentAttribute, Annotation>();
ht.put(relEntAt, an);
@@ -1293,44 +1406,43 @@ public class JpaArtifactFactory {
}
return null;
}
-
-
- /*
- ASTNode nd = jrpa.getMember().getModifiedDeclaration()
- .getDeclaration();
- String annotationName = null;
- if ((nd instanceof MethodDeclaration)
- || (nd instanceof FieldDeclaration)) {
- ListIterator<?> modfs = ((BodyDeclaration) nd).modifiers()
- .listIterator();
- while (modfs.hasNext()) {
- Object modf = modfs.next();
- if (modf instanceof Annotation) {
- Annotation an = (Annotation)modf;
- annotationName = an.getTypeName()
- .getFullyQualifiedName();
- annotationName = annotationName
- .substring(annotationName.lastIndexOf('.') + 1);
- if (JPAEditorConstants.RELATION_ANNOTATIONS
- .contains(annotationName)) {
- String relTypeName = getRelTypeName(an, jrpa);
- if (!relTypeName.equals(jpt.getName()))
- continue;
- JavaAttributeMapping mp = at.getSpecifiedMapping();
- if (!OwnableRelationshipMappingAnnotation.class.isInstance(mp.getMappingAnnotation()))
- continue;
- String mappedBy = ((OwnableRelationshipMappingAnnotation)mp.getMappingAnnotation()).getMappedBy();
- if (!jpa.getName().equals(mappedBy))
- continue;
- Hashtable<JavaPersistentAttribute, Annotation> ht = new Hashtable<JavaPersistentAttribute, Annotation>();
- ht.put(at, an);
- return ht;
- }
- }
- }
+
+ /**
+ * If the value of the mappedBy attribute consist of two strings separated by a dot, that means that
+ * the bidirectional relationship is between an embeddable class and an entity.
+ * This method find the parent entity of the relation attribute. After that takes the embedded attribute of
+ * this entity and checks whether the parent of the embedded attributes is the same as the given embeddable class.
+ * If yes, then return the entity that contains the embedded attribute.
+ * @param fp
+ * @param jpt - the embedded class
+ * @param relEntAt - the relation attribute in the entity class
+ * @param an - the relation attribute annotation
+ * @param mappedByStrings - all strings in the mappedBy attribute
+ * @return the entity involved in the bidirectional relationship between the embeddable class and some entity.
+ */
+ private JavaPersistentType getInvolvedEntity(IJPAEditorFeatureProvider fp, JavaPersistentType jpt,
+ JavaPersistentAttribute relEntAt, Annotation an, String[] mappedByStrings) {
+ String mappedBy = mappedByStrings[0];
+ JavaPersistentType involvedEntity = findJPT(relEntAt, fp, an);
+ JavaPersistentAttribute embeddedAttribute = involvedEntity.getAttributeNamed(mappedBy);
+ if(embeddedAttribute != null){
+ JavaPersistentType embeddedJPT = findJPT(embeddedAttribute, fp, getAnnotations(embeddedAttribute)[0]);
+ if(embeddedJPT.equals(jpt)) {
+ jpt = involvedEntity;
}
- */
+ }
+ return jpt;
+ }
+ /**
+ * Create unidirectional relationship.
+ * @param jpt
+ * @param at
+ * @param an
+ * @param relJPT
+ * @param fp
+ * @return the newly created unidirectional relationship.
+ */
private IUnidirectionalRelation produceUniDirRelation(
JavaPersistentType jpt, JavaPersistentAttribute at, Annotation an,
JavaPersistentType relJPT, IJPAEditorFeatureProvider fp) {
@@ -1338,41 +1450,52 @@ public class JpaArtifactFactory {
if (isNonOwner(at) || !JPAEditorUtil.getCompilationUnit((JavaPersistentType) at.getParent()).exists())
return null;
String annotationName = JPAEditorUtil.returnSimpleName(an.getAnnotationName());
+ IUnidirectionalRelation res = createUniDirRelationshipDependsOnTheType(jpt, at, relJPT, fp, annotationName);
+ if (res != null)
+ res.setAnnotatedAttribute(at);
+ return res;
+ }
+
+ private IUnidirectionalRelation createUniDirRelationshipDependsOnTheType(
+ JavaPersistentType jpt, JavaPersistentAttribute at,
+ JavaPersistentType relJPT, IJPAEditorFeatureProvider fp,
+ String annotationName) {
IUnidirectionalRelation res = null;
String attrName = at.getName();
if (annotationName.equals(JPAEditorConstants.ANNOTATION_ONE_TO_ONE)) {
- if (!fp.doesRelationExist(jpt, relJPT, attrName, RelType.ONE_TO_ONE,
+ if (!fp.doesRelationExist(jpt, relJPT, attrName, null, RelType.ONE_TO_ONE,
RelDir.UNI))
- res = new OneToOneUniDirRelation(fp, jpt, relJPT, attrName, false,
- fp.getCompilationUnit(jpt), fp
- .getCompilationUnit(relJPT));
+ res = new OneToOneUniDirRelation(fp, jpt, relJPT, attrName, false);
} else if (annotationName
.equals(JPAEditorConstants.ANNOTATION_ONE_TO_MANY)) {
- if (!fp.doesRelationExist(jpt, relJPT, attrName, RelType.ONE_TO_MANY,
+ if (!fp.doesRelationExist(jpt, relJPT, attrName, null, RelType.ONE_TO_MANY,
RelDir.UNI))
- res = new OneToManyUniDirRelation(fp, jpt, relJPT, attrName, false,
- fp.getCompilationUnit(jpt), fp
- .getCompilationUnit(relJPT));
+ res = new OneToManyUniDirRelation(fp, jpt, relJPT, attrName, false);
} else if (annotationName
.equals(JPAEditorConstants.ANNOTATION_MANY_TO_ONE)) {
- if (!fp.doesRelationExist(jpt, relJPT, attrName, RelType.MANY_TO_ONE,
+ if (!fp.doesRelationExist(jpt, relJPT, attrName, null, RelType.MANY_TO_ONE,
RelDir.UNI))
- res = new ManyToOneUniDirRelation(fp, jpt, relJPT, attrName, false,
- fp.getCompilationUnit(jpt), fp
- .getCompilationUnit(relJPT));
+ res = new ManyToOneUniDirRelation(fp, jpt, relJPT, attrName, false);
} else if (annotationName
.equals(JPAEditorConstants.ANNOTATION_MANY_TO_MANY)) {
- if (!fp.doesRelationExist(jpt, relJPT, attrName, RelType.MANY_TO_MANY,
+ if (!fp.doesRelationExist(jpt, relJPT, attrName, null, RelType.MANY_TO_MANY,
RelDir.UNI))
- res = new ManyToManyUniDirRelation(fp, jpt, relJPT, attrName,
- false, fp.getCompilationUnit(jpt), fp
- .getCompilationUnit(relJPT));
+ res = new ManyToManyUniDirRelation(fp, jpt, relJPT, attrName, false);
}
- if (res != null)
- res.setAnnotatedAttribute(at);
return res;
}
+ /**
+ * Create bidirectional relationship.
+ * @param jpt
+ * @param at
+ * @param an
+ * @param relJPT
+ * @param relAt
+ * @param relAn
+ * @param fp
+ * @return the newly created bidirectional relationship.
+ */
private IBidirectionalRelation produceBiDirRelation(JavaPersistentType jpt,
JavaPersistentAttribute at, Annotation an,
JavaPersistentType relJPT, JavaPersistentAttribute relAt,
@@ -1407,36 +1530,46 @@ public class JpaArtifactFactory {
String mappedBy = ((OwnableRelationshipMappingAnnotation)m.getMappingAnnotation()).getMappedBy();
if (mappedBy == null)
return null;
+ String[] attrs = mappedBy.split(MAPPED_BY_ATTRIBUTE_SPLIT_SEPARATOR);
+ if(attrs.length > 1) {
+ mappedBy = attrs[1];
+ }
if (!mappedBy.equals(ownerAttrName))
return null;
}
}
+ IBidirectionalRelation res = createBiDirRelationshipDependsOnTheType(
+ jpt, relJPT, fp, annotationName, ownerAttrName, inverseAttrName);
+ if (res != null) {
+ res.setOwnerAnnotatedAttribute(at);
+ res.setInverseAnnotatedAttribute(relAt);
+ }
+ return res;
+ }
+
+ private IBidirectionalRelation createBiDirRelationshipDependsOnTheType(
+ JavaPersistentType jpt, JavaPersistentType relJPT,
+ IJPAEditorFeatureProvider fp, String annotationName,
+ String ownerAttrName, String inverseAttrName) {
IBidirectionalRelation res = null;
if (annotationName.equals(JPAEditorConstants.ANNOTATION_ONE_TO_ONE)) {
- if (!fp.doesRelationExist(jpt, relJPT, ownerAttrName, RelType.ONE_TO_ONE,
+ if (!fp.doesRelationExist(jpt, relJPT, ownerAttrName, inverseAttrName, RelType.ONE_TO_ONE,
RelDir.BI))
res = new OneToOneBiDirRelation(fp, jpt, relJPT, ownerAttrName,
- inverseAttrName, false, fp.getCompilationUnit(jpt), fp
- .getCompilationUnit(relJPT));
+ inverseAttrName, false, relJPT);
} else if (annotationName
.equals(JPAEditorConstants.ANNOTATION_MANY_TO_ONE)) {
- if (!fp.doesRelationExist(jpt, relJPT, ownerAttrName, RelType.MANY_TO_ONE,
+ if (!fp.doesRelationExist(jpt, relJPT, ownerAttrName, inverseAttrName, RelType.MANY_TO_ONE,
RelDir.BI))
res = new ManyToOneBiDirRelation(fp, jpt, relJPT, ownerAttrName,
- inverseAttrName, false, fp.getCompilationUnit(jpt), fp
- .getCompilationUnit(relJPT));
+ inverseAttrName, false, relJPT);
} else if (annotationName
.equals(JPAEditorConstants.ANNOTATION_MANY_TO_MANY)) {
- if (!fp.doesRelationExist(jpt, relJPT, ownerAttrName, RelType.MANY_TO_MANY,
+ if (!fp.doesRelationExist(jpt, relJPT, ownerAttrName, inverseAttrName, RelType.MANY_TO_MANY,
RelDir.BI))
res = new ManyToManyBiDirRelation(fp, jpt, relJPT, ownerAttrName,
- inverseAttrName, false, fp.getCompilationUnit(jpt), fp
- .getCompilationUnit(relJPT));
- }
- if (res != null) {
- res.setOwnerAnnotatedAttribute(at);
- res.setInverseAnnotatedAttribute(relAt);
+ inverseAttrName, false, relJPT);
}
return res;
}
@@ -1458,6 +1591,16 @@ public class JpaArtifactFactory {
return false;
}
+ /**
+ * Create the attribute's getter method in entity's compilation unit.
+ * @param attrName - the name of the attribute
+ * @param attrType - the type of the attribute
+ * @param attrTypeElementNames
+ * @param actName
+ * @param annotations
+ * @param isCollection
+ * @return the string representation of the attribute's getter method.
+ */
public String genGetterContents(String attrName, String attrType,
String[] attrTypeElementNames, String actName,
List<String> annotations, boolean isCollection) {
@@ -1488,6 +1631,15 @@ public class JpaArtifactFactory {
return contents;
}
+ /**
+ * Create the attribute's setter method in entity's compilation unit.
+ * @param attrName - the name of the attribute
+ * @param attrType - the type of the attribute
+ * @param attrTypeElementNames
+ * @param actName
+ * @param isCollection
+ * @return the string representation of the attribute's setter method.
+ */
public String genSetterContents(String attrName, String attrType,
String[] attrTypeElementNames, String actName, boolean isCollection) {
@@ -1619,12 +1771,26 @@ public class JpaArtifactFactory {
}
}
- private void addNewRelations(IJPAEditorFeatureProvider fp,
+ public void addNewRelations(IJPAEditorFeatureProvider fp,
+ JavaPersistentType jpt) {
+ addIRelationships(fp, jpt);
+ addEmbeddedRelation(fp, jpt);
+ }
+
+ private void addEmbeddedRelation(IJPAEditorFeatureProvider fp,
+ JavaPersistentType jpt) {
+ Collection<HasReferanceRelation> newEmbeddedRels = produceAllEmbeddedRelations(jpt, fp);
+ Iterator<HasReferanceRelation> relationIterator = newEmbeddedRels.iterator();
+ while (relationIterator.hasNext()) {
+ HasReferanceRelation rel = relationIterator.next();
+ addNewEmbeddedRelation(fp, rel);
+ }
+ }
+
+ private void addIRelationships(IJPAEditorFeatureProvider fp,
JavaPersistentType jpt) {
-
Collection<IRelation> selfRels = new HashSet<IRelation>();
- Collection<IRelation> newRels = JpaArtifactFactory.instance()
- .produceAllRelations(jpt, fp);
+ Collection<IRelation> newRels = produceAllIRelations(jpt, fp);
Iterator<IRelation> relsIt = newRels.iterator();
while (relsIt.hasNext()) {
IRelation rel = relsIt.next();
@@ -1638,7 +1804,7 @@ public class JpaArtifactFactory {
while (relsIt.hasNext()) {
IRelation rel = relsIt.next();
addNewRelation(fp, rel);
- }
+ }
}
public void addIsARelations(IJPAEditorFeatureProvider fp,
@@ -1669,16 +1835,26 @@ public class JpaArtifactFactory {
ft.add(ctx);
}
- private String getRelTypeName(RelationshipMappingAnnotation an,
+ private void addNewEmbeddedRelation(IJPAEditorFeatureProvider fp, HasReferanceRelation rel) {
+ AddConnectionContext ctx = new AddConnectionContext(JPAEditorUtil
+ .getAnchor(rel.getEmbeddingEntity(), fp), JPAEditorUtil.getAnchor(rel
+ .getEmbeddable(), fp));
+ ctx.setNewObject(rel);
+ ctx.setTargetContainer(fp.getDiagramTypeProvider().getDiagram());
+ AddHasReferenceRelationFeature ft = new AddHasReferenceRelationFeature(fp);
+ ft.add(ctx);
+ }
+
+ private String getRelTypeName(Annotation an,
JavaResourceAttribute jra) {
String relTypeName = null;
try {
boolean isMap = jra.getTypeBinding().getQualifiedName().equals(JPAEditorConstants.MAP_TYPE);
relTypeName = jra.getTypeBinding().getTypeArgumentName(isMap ? 1 : 0);
} catch (Exception e) {}
- if (relTypeName == null)
- relTypeName = an.getFullyQualifiedTargetEntityClassName();
- if (relTypeName == null)
+ if (relTypeName == null && an != null && (an instanceof RelationshipMappingAnnotation))
+ relTypeName = ((RelationshipMappingAnnotation)an).getFullyQualifiedTargetEntityClassName();
+ if (relTypeName == null)
relTypeName = JPAEditorUtil.getAttributeTypeName(jra);
return relTypeName;
}
@@ -1738,7 +1914,11 @@ public class JpaArtifactFactory {
public boolean isEmbeddedId(ReadOnlyPersistentAttribute jpa) {
return (jpa.getMappingKey() == MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY);
- }
+ }
+
+ public boolean isEmbeddedAttribute(JavaPersistentAttribute jpa) {
+ return (jpa.getMappingKey() == MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY);
+ }
public String getColumnName(JavaPersistentAttribute jpa) {
String columnName= null;
@@ -1753,23 +1933,38 @@ public class JpaArtifactFactory {
}
public IColorConstant getForeground(JPAEditorConstants.DIAGRAM_OBJECT_TYPE dot) {
- IColorConstant foreground = dot.equals(JPAEditorConstants.DIAGRAM_OBJECT_TYPE.MappedSupeclass) ?
- JPAEditorConstants.MAPPED_SUPERCLASS_BORDER_COLOR:
- JPAEditorConstants.ENTITY_BORDER_COLOR;
+ IColorConstant foreground = IColorConstant.WHITE;
+ if(dot.equals(JPAEditorConstants.DIAGRAM_OBJECT_TYPE.MappedSupeclass)){
+ foreground = JPAEditorConstants.MAPPED_SUPERCLASS_BORDER_COLOR;
+ } else if(dot.equals(JPAEditorConstants.DIAGRAM_OBJECT_TYPE.Entity)){
+ foreground = JPAEditorConstants.ENTITY_BORDER_COLOR;
+ } else if (dot.equals(JPAEditorConstants.DIAGRAM_OBJECT_TYPE.Embeddable)){
+ foreground = JPAEditorConstants.EMBEDDABLE_BORDER_COLOR;
+ }
return foreground;
}
public IColorConstant getBackground(JPAEditorConstants.DIAGRAM_OBJECT_TYPE dot) {
- IColorConstant background = dot.equals(JPAEditorConstants.DIAGRAM_OBJECT_TYPE.MappedSupeclass) ?
- JPAEditorConstants.MAPPED_SUPERCLASS_BACKGROUND:
- JPAEditorConstants.ENTITY_BACKGROUND;
+ IColorConstant background = IColorConstant.WHITE;
+ if(dot.equals(JPAEditorConstants.DIAGRAM_OBJECT_TYPE.MappedSupeclass)){
+ background = JPAEditorConstants.MAPPED_SUPERCLASS_BACKGROUND;
+ } else if(dot.equals(JPAEditorConstants.DIAGRAM_OBJECT_TYPE.Entity)){
+ background = JPAEditorConstants.ENTITY_BACKGROUND;
+ } else if (dot.equals(JPAEditorConstants.DIAGRAM_OBJECT_TYPE.Embeddable)){
+ background = JPAEditorConstants.EMBEDDABLE_BACKGROUND;
+ }
return background;
}
public String getRenderingStyle(JPAEditorConstants.DIAGRAM_OBJECT_TYPE dot) {
- String renderingStyle = dot.equals(JPAEditorConstants.DIAGRAM_OBJECT_TYPE.MappedSupeclass) ?
- IJPAEditorPredefinedRenderingStyle.GREEN_WHITE_GLOSS_ID :
- IJPAEditorPredefinedRenderingStyle.BLUE_WHITE_GLOSS_ID;
+ String renderingStyle = ""; //$NON-NLS-1$
+ if(dot.equals(JPAEditorConstants.DIAGRAM_OBJECT_TYPE.MappedSupeclass)){
+ renderingStyle = IJPAEditorPredefinedRenderingStyle.GREEN_WHITE_GLOSS_ID;
+ } else if(dot.equals(JPAEditorConstants.DIAGRAM_OBJECT_TYPE.Entity)){
+ renderingStyle = IJPAEditorPredefinedRenderingStyle.BLUE_WHITE_GLOSS_ID;
+ } else if (dot.equals(JPAEditorConstants.DIAGRAM_OBJECT_TYPE.Embeddable)){
+ renderingStyle = IJPAEditorPredefinedRenderingStyle.VIOLET_WHITE_GLOSS_ID;
+ }
return renderingStyle;
}
@@ -1778,6 +1973,8 @@ public class JpaArtifactFactory {
return JPAEditorConstants.DIAGRAM_OBJECT_TYPE.Entity;
} else if (this.hasMappedSuperclassAnnotation(jpt)) {
return JPAEditorConstants.DIAGRAM_OBJECT_TYPE.MappedSupeclass;
+ } else if (this.hasEmbeddableAnnotation(jpt)){
+ return JPAEditorConstants.DIAGRAM_OBJECT_TYPE.Embeddable;
}
throw new IllegalArgumentException();
}
diff --git a/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.swtbot.tests/pom.xml b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.swtbot.tests/pom.xml
index 0dd1c08..ebfbddb 100644
--- a/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.swtbot.tests/pom.xml
+++ b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.swtbot.tests/pom.xml
@@ -5,7 +5,7 @@
<parent>
<artifactId>org.eclipse.jpt.jpadiagrameditor_parent</artifactId>
<groupId>org.eclipse.jpt.jpadiagrameditor</groupId>
- <version>1.1.0-SNAPSHOT</version>
+ <version>1.2.0-SNAPSHOT</version>
<relativePath>../../development/org.eclipse.jpt.jpadiagrameditor.releng/pom.xml</relativePath>
</parent>
diff --git a/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.swtbot.tests/src/org/eclipse/jpt/jpadiagrameditor/swtbot/tests/ui/editor/ContextMenuHelper.java b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.swtbot.tests/src/org/eclipse/jpt/jpadiagrameditor/swtbot/tests/ui/editor/ContextMenuHelper.java
index 38c3a66..40a3e17 100644
--- a/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.swtbot.tests/src/org/eclipse/jpt/jpadiagrameditor/swtbot/tests/ui/editor/ContextMenuHelper.java
+++ b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.swtbot.tests/src/org/eclipse/jpt/jpadiagrameditor/swtbot/tests/ui/editor/ContextMenuHelper.java
@@ -29,7 +29,8 @@ public class ContextMenuHelper
* @throws WidgetNotFoundException
* if the widget is not found.
*/
- public static void clickContextMenu( final AbstractSWTBot<?> bot, final String... texts )
+ @SuppressWarnings("unchecked")
+ public static void clickContextMenu( final AbstractSWTBot<?> bot, final String... texts )
{
final Matcher<?>[] matchers = new Matcher<?>[texts.length];
for ( int i = 0; i < texts.length; i++ )
diff --git a/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.swtbot.tests/src/org/eclipse/jpt/jpadiagrameditor/swtbot/tests/ui/editor/EditorProxy.java b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.swtbot.tests/src/org/eclipse/jpt/jpadiagrameditor/swtbot/tests/ui/editor/EditorProxy.java
index a5cfcaf..ccfbd64 100644
--- a/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.swtbot.tests/src/org/eclipse/jpt/jpadiagrameditor/swtbot/tests/ui/editor/EditorProxy.java
+++ b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.swtbot.tests/src/org/eclipse/jpt/jpadiagrameditor/swtbot/tests/ui/editor/EditorProxy.java
@@ -12,7 +12,7 @@ import static org.junit.Assert.fail;
import java.awt.AWTException;
import java.awt.Robot;
-import java.util.Iterator;
+import java.util.ArrayList;
import java.util.List;
import java.util.Set;
@@ -35,10 +35,14 @@ import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jpt.jpa.core.context.java.JavaPersistentAttribute;
import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType;
+import org.eclipse.jpt.jpa.ui.internal.details.JptUiDetailsMessages;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.i18n.JPAEditorMessages;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.IJPAEditorFeatureProvider;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.HasReferanceRelation;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.IRelation;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.IRelation.RelType;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.IsARelation;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JPAEditorConstants;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JPAEditorUtil;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Point;
@@ -62,67 +66,88 @@ import org.eclipse.swtbot.swt.finder.widgets.SWTBotTree;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IEditorReference;
+@SuppressWarnings("restriction")
public class EditorProxy {
-
+
private final SWTWorkbenchBot workbenchBot;
protected SWTGefBot bot;
-
+ private SWTBotGefEditor jpaDiagramEditor;
+
/**
* Create proxy object.
- *
+ *
* @param bot
*/
public EditorProxy(SWTWorkbenchBot workbenchBot, SWTGefBot bot) {
this.workbenchBot = workbenchBot;
this.bot = bot;
}
-
- public SWTBotGefEditor openDiagramOnJPAContentNode(String name) {
- SWTBotTree projectTree = workbenchBot.viewByTitle("Project Explorer").bot().tree();
+
+ public SWTBotGefEditor openDiagramOnJPAContentNode(String name, boolean isJPA20) {
+ SWTBotTree projectTree = workbenchBot.viewByTitle("Project Explorer")
+ .bot().tree();
projectTree.expandNode(name).expandNode("JPA Content").select();
ContextMenuHelper.clickContextMenu(projectTree, "Open Diagram");
-
- workbenchBot.waitUntil(shellIsActive(JPAEditorMessages.OpenJpaDiagramActionDelegate_jpaSupportWarningTitle), 5000);
- SWTBotShell jpaSupportWarningDialog = workbenchBot.shell(JPAEditorMessages.OpenJpaDiagramActionDelegate_jpaSupportWarningTitle);
- getOkButton(jpaSupportWarningDialog).click();
-
+
+ if(isJPA20) {
+ workbenchBot
+ .waitUntil(
+ shellIsActive(JPAEditorMessages.OpenJpaDiagramActionDelegate_jpaSupportWarningTitle),
+ 10000);
+ SWTBotShell jpaSupportWarningDialog = workbenchBot
+ .shell(JPAEditorMessages.OpenJpaDiagramActionDelegate_jpaSupportWarningTitle);
+ getOkButton(jpaSupportWarningDialog).click();
+ }
+
SWTBotGefEditor jpaDiagramEditor = bot.gefEditor(name);
assertFalse("Editor must not be dirty!", jpaDiagramEditor.isDirty());
-
- List<SWTBotGefEditPart> entities = jpaDiagramEditor.mainEditPart().children();
+
+ List<SWTBotGefEditPart> entities = jpaDiagramEditor.mainEditPart()
+ .children();
assertTrue("Editor must not contains any entities!", entities.isEmpty());
-
+
return jpaDiagramEditor;
}
-
+
public SWTBotGefEditor openDiagramOnJPAProjectNode(String name) {
- SWTBotTree projectTree = workbenchBot.viewByTitle("Project Explorer").bot().tree();
+ SWTBotTree projectTree = workbenchBot.viewByTitle("Project Explorer")
+ .bot().tree();
projectTree.expandNode(name).select();
- ContextMenuHelper.clickContextMenu(projectTree, "JPA Tools", "Open Diagram");
-
- workbenchBot.waitUntil(shellIsActive(JPAEditorMessages.OpenJpaDiagramActionDelegate_jpaSupportWarningTitle), 5000);
- SWTBotShell jpaSupportWarningDialog = workbenchBot.shell(JPAEditorMessages.OpenJpaDiagramActionDelegate_jpaSupportWarningTitle);
+ ContextMenuHelper.clickContextMenu(projectTree, "JPA Tools",
+ "Open Diagram");
+
+ workbenchBot
+ .waitUntil(
+ shellIsActive(JPAEditorMessages.OpenJpaDiagramActionDelegate_jpaSupportWarningTitle),
+ 10000);
+ SWTBotShell jpaSupportWarningDialog = workbenchBot
+ .shell(JPAEditorMessages.OpenJpaDiagramActionDelegate_jpaSupportWarningTitle);
getOkButton(jpaSupportWarningDialog).click();
-
+
SWTBotGefEditor jpaDiagramEditor = bot.gefEditor(name);
assertFalse("Editor must not be dirty!", jpaDiagramEditor.isDirty());
return jpaDiagramEditor;
}
-
+
/**
- * Gets the "Select Type" dialog that appears when the attribute's context menu
- * "Refactor Attribute Type..." is selected
- * @param jpaDiagramEditor
+ * Gets the "Select Type" dialog that appears when the attribute's context
+ * menu "Refactor Attribute Type..." is selected
+ *
* @param attribute
* @return the "Select Type" dialog
*/
- public SWTBotShell getSelectNewAttributeTypeDialog(final SWTBotGefEditor jpaDiagramEditor, SWTBotGefEditPart attribute) {
+ public SWTBotShell getSelectNewAttributeTypeDialog(SWTBotGefEditPart attribute) {
attribute.click();
- jpaDiagramEditor.clickContextMenu(JPAEditorMessages.JPAEditorToolBehaviorProvider_refactorAttributeType);
-
- workbenchBot.waitUntil(shellIsActive(JPAEditorMessages.SelectTypeDialog_chooseAttributeTypeDialogWindowTitle), 5000);
- SWTBotShell changeTypeDialog = workbenchBot.shell(JPAEditorMessages.SelectTypeDialog_chooseAttributeTypeDialogWindowTitle);
+ jpaDiagramEditor
+ .clickContextMenu(JPAEditorMessages.JPAEditorToolBehaviorProvider_refactorAttributeType);
+
+ workbenchBot
+ .waitUntil(
+ shellIsActive(JPAEditorMessages.SelectTypeDialog_chooseAttributeTypeDialogWindowTitle),
+ 10000);
+ SWTBotShell changeTypeDialog = workbenchBot
+ .shell(JPAEditorMessages.SelectTypeDialog_chooseAttributeTypeDialogWindowTitle);
getNewTypeInputField(changeTypeDialog);
return changeTypeDialog;
}
@@ -130,11 +155,14 @@ public class EditorProxy {
/**
* Gets the text input field of the "Select Type" dialog, which appears when
* the attribute's context menu "Refcator Attribute Type..." is selected
- * @param changeTypeDialog - the "Select Type" dialog
+ *
+ * @param changeTypeDialog
+ * - the "Select Type" dialog
* @return the text input field
*/
public SWTBotText getNewTypeInputField(SWTBotShell changeTypeDialog) {
- SWTBotText attributeType = changeTypeDialog.bot().textWithLabel(JPAEditorMessages.SelectTypeDialog_typeLabel);
+ SWTBotText attributeType = changeTypeDialog.bot().textWithLabel(
+ JPAEditorMessages.SelectTypeDialog_typeLabel);
assertEquals("java.lang.String", attributeType.getText());
assertTrue(getOkButton(changeTypeDialog).isEnabled());
assertTrue(getCancelButton(changeTypeDialog).isEnabled());
@@ -143,115 +171,198 @@ public class EditorProxy {
/**
* Gets the current attribute type value
- * @param jpaDiagramEditor
+ *
* @param attributeName
* @param fp
* @return the value of the attribute's type
*/
- public String getAttributeType(SWTBotGefEditor jpaDiagramEditor, String attributeName, final IFeatureProvider fp) {
- SWTBotGefEditPart attribute = jpaDiagramEditor.getEditPart(attributeName);
+ public String getAttributeType(String attributeName, final IFeatureProvider fp) {
+ SWTBotGefEditPart attribute = jpaDiagramEditor
+ .getEditPart(attributeName);
PictogramElement el = (PictogramElement) attribute.part().getModel();
Object bo = fp.getBusinessObjectForPictogramElement(el);
- assertTrue("The selected element is not an attribute!", (bo instanceof JavaPersistentAttribute));
- String currentAttributeType = JPAEditorUtil.getAttributeTypeName((JavaPersistentAttribute)bo);
+ assertTrue("The selected element is not an attribute!",
+ (bo instanceof JavaPersistentAttribute));
+ String currentAttributeType = JPAEditorUtil
+ .getAttributeTypeName((JavaPersistentAttribute) bo);
return currentAttributeType;
}
-
+
/**
- * Adds a new attribute to the entity and checks that:
- * 1. The newly created attribute is selected
- * 2. The "Other Attributes" section is visible
- * @param jpaDiagramEditor
- * @param attributeName - the name of the attribute
+ * Adds a new attribute to the entity and checks that: 1. The newly created
+ * attribute is selected 2. The "Other Attributes" section is visible
+ *
+ * @param attributeName
+ * - the name of the attribute
* @return the newly added attribute
*/
- public SWTBotGefEditPart addAttributeToEntity(final SWTBotGefEditor jpaDiagramEditor, SWTBotGefEditPart entity, String attributeName) {
- pressEntityContextButton(jpaDiagramEditor, entity, JPAEditorMessages.JPAEditorToolBehaviorProvider_createAttributeButtonlabel);
-
- bot.waitUntil(new ElementIsShown(jpaDiagramEditor, attributeName), 30000);
- SWTBotGefEditPart attribute = jpaDiagramEditor.getEditPart(attributeName);
+ public SWTBotGefEditPart addAttributeToJPT(SWTBotGefEditPart jptType,
+ String attributeName) {
+ pressEntityContextButton(jptType,
+ JPAEditorMessages.JPAEditorToolBehaviorProvider_createAttributeButtonlabel);
+
+ bot.waitUntil(new ElementIsShown(jpaDiagramEditor, attributeName),
+ 10000);
+ List<SWTBotGefEditPart> editParts = new ArrayList<SWTBotGefEditPart>();
+ editParts.add(jptType);
+ SWTBotGefEditPart attribute = jpaDiagramEditor
+ .getEditpart(attributeName, editParts);
assertNotNull("Atrribute is not added.", attribute);
-
- assertTrue("The newly added attribute must be selected.", jpaDiagramEditor.selectedEditParts().size() == 1);
- assertTrue("The newly added attribute must be selected.", jpaDiagramEditor.selectedEditParts().contains(attribute));
-
- assertTrue("\"Other Attributes\" section must be visible!", isSectionVisible(jpaDiagramEditor, JPAEditorMessages.AddJPAEntityFeature_basicAttributesShapes));
-
+
+ assertTrue("The newly added attribute must be selected.",
+ jpaDiagramEditor.selectedEditParts().size() == 1);
+ assertTrue("The newly added attribute must be selected.",
+ jpaDiagramEditor.selectedEditParts().contains(attribute));
+
+ assertTrue("\"Other Attributes\" section must be visible!",
+ isSectionVisible(JPAEditorMessages.AddJPAEntityFeature_basicAttributesShapes, jptType));
+
return attribute;
}
-
+
/**
* Checks whether a section with the specified name is visible
- * @param diagramEditor
- * @param sectionTitle - the name of the section
- * @return true, if the section with the specified name is visible,
- * false otherwise
- */
- public boolean isSectionVisible(SWTBotGefEditor diagramEditor, String sectionTitle){
- SWTBotGefEditPart section = diagramEditor.getEditPart(sectionTitle);
- if(section == null)
- return false;
- ((PictogramElement)section.part().getModel()).isVisible();
+ *
+ * @param sectionTitle
+ * - the name of the section
+ * @return true, if the section with the specified name is visible, false
+ * otherwise
+ */
+ public boolean isSectionVisible(String sectionTitle, SWTBotGefEditPart editPart) {
+ List<SWTBotGefEditPart> editParts = new ArrayList<SWTBotGefEditPart>();
+ editParts.add(editPart);
+ SWTBotGefEditPart section = jpaDiagramEditor.getEditpart(sectionTitle,
+ editParts);
+ ((PictogramElement) section.part().getModel()).isVisible();
IFigure figure = ((GraphicalEditPart) section.part()).getFigure();
return figure.isVisible();
}
-
+
/**
* Adds an entity to the diagram
- * @param jpaDiagramEditor
- * @param entityName - the name of the entity to be added
+ *
+ * @param entityName
+ * - the name of the entity to be added
* @return the added entity
*/
- public SWTBotGefEditPart addEntityToDiagram(final SWTBotGefEditor jpaDiagramEditor, int x, int y, String entityName) {
- jpaDiagramEditor.activateTool(JPAEditorMessages.CreateJPAEntityFeature_jpaEntityFeatureName);
+ public SWTBotGefEditPart addEntityToDiagram(int x, int y, String entityName) {
+ jpaDiagramEditor
+ .activateTool(JPAEditorMessages.CreateJPAEntityFeature_jpaEntityFeatureName);
jpaDiagramEditor.doubleClick(x, y);
- bot.waitUntil(new ElementIsShown(jpaDiagramEditor, entityName), 30000);
-
- List<SWTBotGefEditPart> entities = jpaDiagramEditor.mainEditPart().children();
- assertFalse("Editor must contains at least one entity!", entities.isEmpty());
-
+ bot.waitUntil(new ElementIsShown(jpaDiagramEditor, entityName), 10000);
+
+ List<SWTBotGefEditPart> entities = jpaDiagramEditor.mainEditPart()
+ .children();
+ assertFalse("Editor must contains at least one entity!",
+ entities.isEmpty());
+
SWTBotGefEditPart entity = jpaDiagramEditor.getEditPart(entityName);
assertNotNull("Entity is not added!", entity);
-
+
SWTBotGefEditPart idAttribute = jpaDiagramEditor.getEditPart("id");
assertNotNull("Entity must have a primary key attribute!", idAttribute);
- assertTrue("\"Primary Key\" section must be visible!", isSectionVisible(jpaDiagramEditor, JPAEditorMessages.AddJPAEntityFeature_primaryKeysShape));
- assertFalse("\"Relation Attributes\" section must not be visible!", isSectionVisible(jpaDiagramEditor, JPAEditorMessages.AddJPAEntityFeature_relationAttributesShapes));
- assertFalse("\"Other Attributes\" section must not be visible!", isSectionVisible(jpaDiagramEditor, JPAEditorMessages.AddJPAEntityFeature_basicAttributesShapes));
-
+ assertTrue(
+ "\"Primary Key\" section must be visible!",
+ isSectionVisible(JPAEditorMessages.AddJPAEntityFeature_primaryKeysShape, entity));
+ assertFalse(
+ "\"Relation Attributes\" section must not be visible!",
+ isSectionVisible(JPAEditorMessages.AddJPAEntityFeature_relationAttributesShapes, entity));
+ assertFalse(
+ "\"Other Attributes\" section must not be visible!",
+ isSectionVisible(JPAEditorMessages.AddJPAEntityFeature_basicAttributesShapes, entity));
+
return entity;
}
-
+
/**
- * Adds mapped superclass to the diagram
- * @param jpaDiagramEditor
- * @param entityName - the name of the mapped superclass to be added
+ * Adds mapped superclass to the diagram
+ *
+ * @param entityName
+ * - the name of the mapped superclass to be added
* @return the added mapped superclass
*/
- public SWTBotGefEditPart addMappedSuperclassToDiagram(final SWTBotGefEditor jpaDiagramEditor, int x, int y, String entityName) {
- jpaDiagramEditor.activateTool(JPAEditorMessages.CreateMappedSuperclassFeature_createMappedSuperclassFeatureName);
- jpaDiagramEditor.doubleClick(x, y);
- bot.waitUntil(new ElementIsShown(jpaDiagramEditor, entityName), 30000);
-
- List<SWTBotGefEditPart> entities = jpaDiagramEditor.mainEditPart().children();
- assertFalse("Editor must contains at least one mapped superclass!", entities.isEmpty());
-
- SWTBotGefEditPart mappedSuperclass = jpaDiagramEditor.getEditPart(entityName);
+ public SWTBotGefEditPart addMappedSuperclassToDiagram(int x, int y, String entityName) {
+ jpaDiagramEditor
+ .activateTool(JPAEditorMessages.CreateMappedSuperclassFeature_createMappedSuperclassFeatureName);
+ jpaDiagramEditor.doubleClick(x, y);
+ bot.waitUntil(new ElementIsShown(jpaDiagramEditor, entityName), 10000);
+
+ List<SWTBotGefEditPart> entities = jpaDiagramEditor.mainEditPart()
+ .children();
+ assertFalse("Editor must contains at least one mapped superclass!",
+ entities.isEmpty());
+
+ SWTBotGefEditPart mappedSuperclass = jpaDiagramEditor
+ .getEditPart(entityName);
assertNotNull("Mapped superclass is not added!", mappedSuperclass);
-
- SWTBotGefEditPart idAttribute = jpaDiagramEditor.getEditPart("id");
- assertNull("Mapped superclass must not have a primary key attribute!", idAttribute);
- assertFalse("\"Primary Key\" section must not be visible!", isSectionVisible(jpaDiagramEditor, JPAEditorMessages.AddJPAEntityFeature_primaryKeysShape));
- assertFalse("\"Relation Attributes\" section must not be visible!", isSectionVisible(jpaDiagramEditor, JPAEditorMessages.AddJPAEntityFeature_relationAttributesShapes));
- assertFalse("\"Other Attributes\" section must not be visible!", isSectionVisible(jpaDiagramEditor, JPAEditorMessages.AddJPAEntityFeature_basicAttributesShapes));
+ List<SWTBotGefEditPart> parts = new ArrayList<SWTBotGefEditPart>();
+ parts.add(mappedSuperclass);
+ SWTBotGefEditPart idAttribute = jpaDiagramEditor.getEditpart("id", parts);
+ assertNull("Mapped superclass must not have a primary key attribute!",
+ idAttribute);
+
+ assertFalse(
+ "\"Primary Key\" section must not be visible!",
+ isSectionVisible(JPAEditorMessages.AddJPAEntityFeature_primaryKeysShape,
+ mappedSuperclass));
+ assertFalse(
+ "\"Relation Attributes\" section must not be visible!",
+ isSectionVisible(JPAEditorMessages.AddJPAEntityFeature_relationAttributesShapes,
+ mappedSuperclass));
+ assertFalse(
+ "\"Other Attributes\" section must not be visible!",
+ isSectionVisible(JPAEditorMessages.AddJPAEntityFeature_basicAttributesShapes,
+ mappedSuperclass));
+
return mappedSuperclass;
}
-
-
+ /**
+ * Adds mapped superclass to the diagram
+ *
+ * @param entityName
+ * - the name of the mapped superclass to be added
+ * @return the added mapped superclass
+ */
+ public SWTBotGefEditPart addEmbeddableToDiagram(int x, int y, String entityName) {
+ jpaDiagramEditor.activateTool(JPAEditorMessages.CreateEmbeddableFeature_EmbeddableFeatureName);
+ jpaDiagramEditor.doubleClick(x, y);
+ bot.waitUntil(new ElementIsShown(jpaDiagramEditor, entityName), 10000);
+
+ List<SWTBotGefEditPart> entities = jpaDiagramEditor.mainEditPart()
+ .children();
+ assertFalse("Editor must contains at least one embeddable!",
+ entities.isEmpty());
+
+ SWTBotGefEditPart embeddable = jpaDiagramEditor.getEditPart(entityName);
+ assertNotNull("Embeddable is not added!", embeddable);
+
+ List<SWTBotGefEditPart> editParts = new ArrayList<SWTBotGefEditPart>();
+ editParts.add(embeddable);
+ SWTBotGefEditPart idAttribute = jpaDiagramEditor.getEditpart("id",
+ editParts);
+ assertNull("Embeddablemust not have a primary key attribute!",
+ idAttribute);
+
+ assertFalse(
+ "\"Primary Key\" section must not be visible!",
+ isSectionVisible(JPAEditorMessages.AddJPAEntityFeature_primaryKeysShape,
+ embeddable));
+ assertFalse(
+ "\"Relation Attributes\" section must not be visible!",
+ isSectionVisible(JPAEditorMessages.AddJPAEntityFeature_relationAttributesShapes,
+ embeddable));
+ assertFalse(
+ "\"Other Attributes\" section must not be visible!",
+ isSectionVisible(JPAEditorMessages.AddJPAEntityFeature_basicAttributesShapes,
+ embeddable));
+
+ return embeddable;
+ }
+
/**
* Pressing the "Yes" button of the "Confirm Delete" question dialog.
*/
@@ -259,7 +370,7 @@ public class EditorProxy {
SWTBotShell shell = getDeleteEntityDialog();
shell.bot().button("Yes").click();
}
-
+
/**
* Pressing the "No" button of the "Confirm Delete" question dialog.
*/
@@ -269,117 +380,153 @@ public class EditorProxy {
}
/**
- * Gets the dialog that appears after the "Delete" context button/menu
- * is pressed.
- * @return the question dialog, asking whether to the delete the selected entity
+ * Gets the dialog that appears after the "Delete" context button/menu is
+ * pressed.
+ *
+ * @return the question dialog, asking whether to the delete the selected
+ * entity
*/
public SWTBotShell getDeleteEntityDialog() {
- workbenchBot.waitUntil(shellIsActive(JPAEditorMessages.DeleteFeature_deleteConfirm), 5000);
- SWTBotShell shell = workbenchBot.shell(JPAEditorMessages.DeleteFeature_deleteConfirm);
+ workbenchBot.waitUntil(
+ shellIsActive(JPAEditorMessages.DeleteFeature_deleteConfirm),
+ 10000);
+ SWTBotShell shell = workbenchBot
+ .shell(JPAEditorMessages.DeleteFeature_deleteConfirm);
return shell;
}
-
+
/**
- * Gets the dialog that appears after the "Refactor Entity Class -> Rename..." context menu
- * is pressed.
+ * Gets the dialog that appears after the
+ * "Refactor Entity Class -> Rename..." context menu is pressed.
+ *
* @return the "Rename Compilation Unit" dialog
*/
public SWTBotShell getRenameEntityDialog() {
- workbenchBot.waitUntil(shellIsActive("Rename Compilation Unit"), 5000);
+ workbenchBot.waitUntil(shellIsActive("Rename Compilation Unit"), 10000);
SWTBotShell shell = workbenchBot.shell("Rename Compilation Unit");
assertFalse(getFinishButton(shell).isEnabled());
assertTrue(getCancelButton(shell).isEnabled());
return shell;
}
-
+
/**
- * Gets the dialog that appears after the "Refactor Entity Class -> Move..." context menu
- * is pressed.
+ * Gets the dialog that appears after the "Refactor Entity Class -> Move..."
+ * context menu is pressed.
+ *
* @return the "Move" dialog
*/
public SWTBotShell getMoveEntityDialog() {
- workbenchBot.waitUntil(shellIsActive("Move"), 5000);
+ workbenchBot.waitUntil(shellIsActive("Move"), 10000);
SWTBotShell shell = workbenchBot.shell("Move");
assertFalse(getOkButton(shell).isEnabled());
assertTrue(getCancelButton(shell).isEnabled());
return shell;
}
-
+
/**
- * Gets the dialog that appears after the "Remove All Entities from Diagram -> ...and Save/Discard Changes" context menu
- * is pressed. Press the OK button.
+ * Gets the dialog that appears after the
+ * "Remove All Entities from Diagram -> ...and Save/Discard Changes" context
+ * menu is pressed. Press the OK button.
*/
public void confirmRemoveEntitiesFromDiagramDialog() {
- workbenchBot.waitUntil(shellIsActive(JPAEditorMessages.JPAEditorToolBehaviorProvider_removeAllEntitiesMenu), 5000);
- SWTBotShell shell = workbenchBot.shell(JPAEditorMessages.JPAEditorToolBehaviorProvider_removeAllEntitiesMenu);
+ workbenchBot.waitUntil(
+ shellIsActive(JPAEditorMessages.JPAEditorToolBehaviorProvider_removeAllEntitiesMenu), 10000);
+ SWTBotShell shell = workbenchBot
+ .shell(JPAEditorMessages.JPAEditorToolBehaviorProvider_removeAllEntitiesMenu);
assertTrue("Ok button is disabled", getOkButton(shell).isEnabled());
assertTrue(getCancelButton(shell).isEnabled());
getOkButton(shell).click();
}
-
-
+
/**
* Deletes an entity with the specified name using the context button.
- * @param jpaDiagramEditor
- * @param entityName - the name of the entity to be deleted
+ *
+ * @param entityName
+ * - the name of the entity to be deleted
*/
- public void deleteDiagramElements(SWTBotGefEditor jpaDiagramEditor){
-
+ public void deleteDiagramElements() {
+
jpaDiagramEditor.save();
- List<SWTBotGefEditPart> entitiesInDiagram = jpaDiagramEditor.mainEditPart().children();
- assertFalse("Diagram must contain at least one entity!", entitiesInDiagram.isEmpty());
-
- Iterator<SWTBotGefEditPart> iterator = entitiesInDiagram.iterator();
- while (iterator.hasNext()) {
- SWTBotGefEditPart editPart = iterator.next();
+ List<SWTBotGefEditPart> entitiesInDiagram = jpaDiagramEditor
+ .mainEditPart().children();
+ assertFalse("Diagram must contain at least one entity!",
+ entitiesInDiagram.isEmpty());
+
+ for (int i = 0; i < entitiesInDiagram.size(); i++) {
+ SWTBotGefEditPart editPart = entitiesInDiagram.get(i);
assertNotNull(editPart);
- editPart.select();
- jpaDiagramEditor.clickContextMenu("Delete");
- confirmDelete();
+ JavaPersistentType type = getJPTObjectForGefElement(editPart);
+ if (type != null) {
+ editPart.select();
+ jpaDiagramEditor.clickContextMenu("Delete");
+ confirmDelete();
+ }
}
+ waitASecond();
entitiesInDiagram = jpaDiagramEditor.mainEditPart().children();
assertTrue("Diagram must be empty!", entitiesInDiagram.isEmpty());
assertTrue("Editor must be dirty!", jpaDiagramEditor.isDirty());
}
-
+
+ public void deleteAttributeInJPT(SWTBotGefEditPart jpt, String attributeName) {
+
+ waitASecond();
+ jpaDiagramEditor.activateDefaultTool();
+
+ List<SWTBotGefEditPart> jptParts = new ArrayList<SWTBotGefEditPart>();
+ jptParts.add(jpt);
+ SWTBotGefEditPart attribute = jpaDiagramEditor.getEditpart(
+ attributeName, jptParts);
+ attribute.select();
+ attribute.click();
+ jpaDiagramEditor.clickContextMenu("Delete");
+ confirmDelete();
+ bot.waitUntil(new ElementDisappears(jpaDiagramEditor, jpt, attributeName),
+ 10000);
+ }
+
/**
* Press some of the entity's context buttons
+ *
* @param jpaDiagramEditor
- * @param contextButtonName - the name of the button to be pressed
+ * @param contextButtonName
+ * - the name of the button to be pressed
*/
- public void pressEntityContextButton(SWTBotGefEditor jpaDiagramEditor, SWTBotGefEditPart part, String contextButtonName){
- pressContextButton(jpaDiagramEditor, part, contextButtonName);
+ public void pressEntityContextButton(SWTBotGefEditPart part, String contextButtonName) {
+ pressContextButton(part, contextButtonName);
}
-
+
/**
* Press the "Delete Attribute" attribute's context button
- * @param jpaDiagramEditor
+ *
*/
- public void pressAttributeDeleteContextButton(SWTBotGefEditor jpaDiagramEditor, SWTBotGefEditPart part){
- pressContextButton(jpaDiagramEditor, part, JPAEditorMessages.JPAEditorToolBehaviorProvider_deleteAttributeButtonlabel);
+ public void pressAttributeDeleteContextButton(SWTBotGefEditPart part) {
+ pressContextButton(part,
+ JPAEditorMessages.JPAEditorToolBehaviorProvider_deleteAttributeButtonlabel);
}
/**
- * Assert that the context button pad is shown, when the mouse is placed over the
- * entity and press the the desired button
- * @param jpaDiagramEditor
- * @param contextButtonName - the name of the button to be pressed.
+ * Assert that the context button pad is shown, when the mouse is placed
+ * over the entity and press the the desired button
+ *
+ * @param contextButtonName
+ * - the name of the button to be pressed.
*/
- @SuppressWarnings("restriction")
- private void pressContextButton(final SWTBotGefEditor jpaDiagramEditor, SWTBotGefEditPart part, String contextButtonName) {
+ private void pressContextButton(SWTBotGefEditPart part, String contextButtonName) {
jpaDiagramEditor.click(0, 0);
jpaDiagramEditor.click(part);
-
- ContextButtonPad pad = findContextButtonPad(jpaDiagramEditor);
+
+ ContextButtonPad pad = findContextButtonPad();
assertNotNull(pad);
- for(final Object button : pad.getChildren()){
- if(((ContextButton)button).getEntry().getText().equals(contextButtonName)){
+ for (final Object button : pad.getChildren()) {
+ if (((ContextButton) button).getEntry().getText()
+ .equals(contextButtonName)) {
asyncExec(new VoidResult() {
public void run() {
- ((ContextButton)button).doClick();
-
+ ((ContextButton) button).doClick();
+
}
});
}
@@ -388,15 +535,15 @@ public class EditorProxy {
/**
* Place the mouse over the entity to show the context button pad.
- * @param jpaDiagramEditor
+ *
*/
- public void moveMouse(final SWTBotGefEditor jpaDiagramEditor, final int x, final int y) {
+ public void moveMouse(final int x, final int y) {
syncExec(new VoidResult() {
public void run() {
Robot r;
try {
r = new Robot();
- Point p = getOrigin(jpaDiagramEditor);
+ Point p = getOrigin();
r.mouseMove(p.x + x, p.y + y);
} catch (AWTException e) {
fail(e.getMessage());
@@ -407,14 +554,14 @@ public class EditorProxy {
/**
* Gets the context button pad, after placing the mouse over the entity
- * @param editor
+ *
* @return the entity's context button pad
*/
@SuppressWarnings("restriction")
- private ContextButtonPad findContextButtonPad(SWTBotGefEditor editor) {
- SWTBotGefEditPart rootEditPart = editor.rootEditPart();
- IFigure feedbackLayer = ((ScalableFreeformRootEditPart) rootEditPart.part())
- .getLayer(LayerConstants.HANDLE_LAYER);
+ private ContextButtonPad findContextButtonPad() {
+ SWTBotGefEditPart rootEditPart = jpaDiagramEditor.rootEditPart();
+ IFigure feedbackLayer = ((ScalableFreeformRootEditPart) rootEditPart
+ .part()).getLayer(LayerConstants.HANDLE_LAYER);
ContextButtonPad cbp = null;
for (Object obj : feedbackLayer.getChildren()) {
if (obj instanceof ContextButtonPad) {
@@ -425,11 +572,11 @@ public class EditorProxy {
return cbp;
}
-
- private FigureCanvas getCanvas(SWTBotGefEditor editorGef) {
- IEditorReference reference = editorGef.getReference();
+ private FigureCanvas getCanvas() {
+ IEditorReference reference = jpaDiagramEditor.getReference();
final IEditorPart editor = reference.getEditor(true);
- GraphicalViewer graphicalViewer = (GraphicalViewer) editor.getAdapter(GraphicalViewer.class);
+ GraphicalViewer graphicalViewer = (GraphicalViewer) editor
+ .getAdapter(GraphicalViewer.class);
final Control control = graphicalViewer.getControl();
if (control instanceof FigureCanvas) {
FigureCanvas c = (FigureCanvas) control;
@@ -437,202 +584,248 @@ public class EditorProxy {
}
return null;
}
-
- private Point getOrigin(SWTBotGefEditor editorGef) {
- Canvas c = getCanvas(editorGef);
+
+ private Point getOrigin() {
+ Canvas c = getCanvas();
Point p = c.toDisplay(0, 0);
return p;
}
-
+
/**
* Get the error message that appears in the "Select Type" dialog
+ *
* @param dialog
* @return the error message
*/
- public SWTBotText getDialogErroMessage(SWTBotShell dialog){
+ public SWTBotText getDialogErroMessage(SWTBotShell dialog) {
return dialog.bot().text(1);
}
-
+
/**
* Gets the "OK" button of a dialog
+ *
* @param dialog
* @return the "OK" button
*/
- public SWTBotButton getOkButton(SWTBotShell dialog){
+ public SWTBotButton getOkButton(SWTBotShell dialog) {
return dialog.bot().button(IDialogConstants.OK_LABEL);
}
-
+
/**
* Gets the "Cancel" button of a dialog
+ *
* @param dialog
* @return the "Cancel" button
*/
- public SWTBotButton getCancelButton(SWTBotShell dialog){
+ public SWTBotButton getCancelButton(SWTBotShell dialog) {
return dialog.bot().button(IDialogConstants.CANCEL_LABEL);
}
-
+
/**
* Gets the "Finish" button of a dialog
+ *
* @param dialog
* @return the "Finish" button
*/
public SWTBotButton getFinishButton(SWTBotShell dialog) {
return dialog.bot().button("Finish");
}
-
+
/**
* Find the IRelation object for the given GEF Connection
- * @param jpaDiagramEditor
+ *
* @param gefConn
* @return the IRelation object for the given GEF Connection
*/
@SuppressWarnings("restriction")
- public IRelation getConnection(SWTBotGefEditor jpaDiagramEditor, SWTBotGefConnectionEditPart gefConn){
- IFeatureProvider fp = ((DiagramEditPart)jpaDiagramEditor.mainEditPart().part()).getFeatureProvider();
- FreeFormConnection conn = (FreeFormConnection) gefConn.part().getModel();
- Object ob = fp.getBusinessObjectForPictogramElement(conn);
- if(ob instanceof IRelation){
- return (IRelation)ob;
- }
-
- return null;
+ public IRelation getConnection(SWTBotGefConnectionEditPart gefConn) {
+ IFeatureProvider fp = ((DiagramEditPart) jpaDiagramEditor
+ .mainEditPart().part()).getFeatureProvider();
+ FreeFormConnection conn = (FreeFormConnection) gefConn.part()
+ .getModel();
+ Object ob = fp.getBusinessObjectForPictogramElement(conn);
+ if (ob instanceof IRelation) {
+ return (IRelation) ob;
+ }
+
+ return null;
}
-
+
+ /**
+ * Find the IRelation object for the given GEF Connection
+ *
+ * @param gefConn
+ * @return the IRelation object for the given GEF Connection
+ */
+ @SuppressWarnings("restriction")
+ public HasReferanceRelation getHasReferenceConnection(SWTBotGefConnectionEditPart gefConn) {
+ IFeatureProvider fp = ((DiagramEditPart) jpaDiagramEditor
+ .mainEditPart().part()).getFeatureProvider();
+ FreeFormConnection conn = (FreeFormConnection) gefConn.part()
+ .getModel();
+ Object ob = fp.getBusinessObjectForPictogramElement(conn);
+ if (ob instanceof HasReferanceRelation) {
+ return (HasReferanceRelation) ob;
+ }
+
+ return null;
+ }
+
/**
* Gets the business object (JavaPersistentType) for the given GEF element
- * @param jpaDiagramEditor
+ *
* @param element
- * @return the java persistent type for the given element, null if the selected element is not an entity
+ * @return the java persistent type for the given element, null if the
+ * selected element is not an entity
*/
- @SuppressWarnings("restriction")
- public JavaPersistentType getEntityForElement(SWTBotGefEditor jpaDiagramEditor, SWTBotGefEditPart element){
- final IFeatureProvider fp = ((DiagramEditPart)jpaDiagramEditor.mainEditPart().part()).getFeatureProvider();
+ public JavaPersistentType getJPTObjectForGefElement(SWTBotGefEditPart element) {
+ final IFeatureProvider fp = ((DiagramEditPart) jpaDiagramEditor
+ .mainEditPart().part()).getFeatureProvider();
PictogramElement el = (PictogramElement) element.part().getModel();
Object bo = fp.getBusinessObjectForPictogramElement(el);
- if (bo instanceof JavaPersistentType){
- return (JavaPersistentType)bo;
+ if (bo instanceof JavaPersistentType) {
+ return (JavaPersistentType) bo;
}
return null;
}
-
+
+ public JavaPersistentAttribute getJPAObjectForGefElement(SWTBotGefEditPart element) {
+ final IFeatureProvider fp = ((DiagramEditPart) jpaDiagramEditor
+ .mainEditPart().part()).getFeatureProvider();
+ PictogramElement el = (PictogramElement) element.part().getModel();
+ Object bo = fp.getBusinessObjectForPictogramElement(el);
+ if (bo instanceof JavaPersistentAttribute) {
+ return (JavaPersistentAttribute) bo;
+ }
+ return null;
+ }
+
/**
* Gets the existing isARelation
- * @param jpaDiagramEditor
+ *
* @return the existing isArelation if exists, null otherwise
*/
@SuppressWarnings("restriction")
- public IsARelation getIsARelationship(SWTBotGefEditor jpaDiagramEditor){
- IJPAEditorFeatureProvider fp = (IJPAEditorFeatureProvider) ((DiagramEditPart)jpaDiagramEditor.mainEditPart().part()).getFeatureProvider();
+ public IsARelation getIsARelationship() {
+ IJPAEditorFeatureProvider fp = (IJPAEditorFeatureProvider) ((DiagramEditPart) jpaDiagramEditor
+ .mainEditPart().part()).getFeatureProvider();
Set<IsARelation> isARelationships = fp.getAllExistingIsARelations();
assertFalse(isARelationships.isEmpty());
assertEquals(1, isARelationships.size());
IsARelation relation = isARelationships.iterator().next();
return relation;
}
-
+
/**
* CHecks whether the Entity contains unsaved changes.
- * @param jpaDiagramEditor
+ *
* @param element
* @return true if the entity contains unsaved changes, false otherwise
*/
@SuppressWarnings("restriction")
- public boolean isEntityDirty(SWTBotGefEditor jpaDiagramEditor, SWTBotGefEditPart element){
- final IFeatureProvider fp = ((DiagramEditPart)jpaDiagramEditor.mainEditPart().part()).getFeatureProvider();
+ public boolean isJPTDirty(SWTBotGefEditPart element) {
+ final IFeatureProvider fp = ((DiagramEditPart) jpaDiagramEditor
+ .mainEditPart().part()).getFeatureProvider();
PictogramElement el = (PictogramElement) element.part().getModel();
Object bo = fp.getBusinessObjectForPictogramElement(el);
IResource res = null;
- if(bo instanceof JavaPersistentAttribute){
- res = ((JavaPersistentAttribute)bo).getResource();
- } else if (bo instanceof JavaPersistentType){
- res = ((JavaPersistentType)bo).getResource();
+ if (bo instanceof JavaPersistentAttribute) {
+ res = ((JavaPersistentAttribute) bo).getResource();
+ } else if (bo instanceof JavaPersistentType) {
+ res = ((JavaPersistentType) bo).getResource();
}
-
- if(res != null){
- ICompilationUnit unit = JPAEditorUtil.getCompilationUnit((IFile)res);
+
+ if (res != null) {
+ ICompilationUnit unit = JPAEditorUtil
+ .getCompilationUnit((IFile) res);
try {
return unit.hasUnsavedChanges();
} catch (JavaModelException e) {
e.printStackTrace();
}
}
-
+
return false;
}
-
+
/**
- * Select the bidirectional self relation and call its "Delete" context menu.
- * On the confirmation dialog press "No" and assert that
- * the connection and the relative relation attributes still exist
- * and the "Relation Attributes" sections of the entities' are visible.
- * @param jpaDiagramEditor
+ * Select the bidirectional relation and call its "Delete" context menu. On
+ * the confirmation dialog press "No" and assert that the connection and the
+ * relative relation attributes still exist and the "Relation Attributes"
+ * sections of the entities' are visible.
+ *
* @param entity1
+ * @param entity2
* @param connection
* @param ownerAttributeName
* @param inverseAttributeName
*/
- public void assertSelfBiDirRelationIsNotDeleted(
- SWTBotGefEditor jpaDiagramEditor, SWTBotGefEditPart entity1,
- SWTBotGefConnectionEditPart connection,
+ public void assertBiDirRelationIsNotDeleted(SWTBotGefEditPart entity1,
+ SWTBotGefEditPart entity2, SWTBotGefConnectionEditPart connection,
String ownerAttributeName, String inverseAttributeName) {
connection.select();
jpaDiagramEditor.clickContextMenu("Delete");
denyDelete();
assertFalse(entity1.sourceConnections().isEmpty());
- assertFalse(entity1.targetConnections().isEmpty());
+ assertFalse(entity2.targetConnections().isEmpty());
connection = entity1.sourceConnections().get(0);
assertNotNull("Attribute must not be deleted!", connection);
assertNotNull(jpaDiagramEditor.getEditPart(ownerAttributeName));
assertNotNull(jpaDiagramEditor.getEditPart(inverseAttributeName));
- assertTrue("\"Relation Attributes\" section of the owner entity must be visible!", isSectionVisible(jpaDiagramEditor, entity1, JPAEditorMessages.AddJPAEntityFeature_relationAttributesShapes));
+ assertTrue(
+ "\"Relation Attributes\" section of the owner entity must be visible!",
+ isSectionVisible(entity1,
+ JPAEditorMessages.AddJPAEntityFeature_relationAttributesShapes));
+ assertTrue(
+ "\"Relation Attributes\" section of the inverse entity must be visible!",
+ isSectionVisible(entity2,
+ JPAEditorMessages.AddJPAEntityFeature_relationAttributesShapes));
}
-
+
/**
- * Select the bidirectional relation and call its "Delete" context menu.
- * On the confirmation dialog press "No" and assert that
- * the connection and the relative relation attributes still exist
- * and the "Relation Attributes" sections of the entities' are visible.
- * @param jpaDiagramEditor
+ * Select the bidirectional self relation and call its "Delete" context
+ * menu. On the confirmation dialog press "No" and assert that the
+ * connection and the relative relation attributes still exist and the
+ * "Relation Attributes" sections of the entities' are visible.
+ *
* @param entity1
- * @param entity2
* @param connection
* @param ownerAttributeName
* @param inverseAttributeName
*/
- public void assertBiDirRelationIsNotDeleted(
- SWTBotGefEditor jpaDiagramEditor, SWTBotGefEditPart entity1,
- SWTBotGefEditPart entity2,
- SWTBotGefConnectionEditPart connection,
- String ownerAttributeName, String inverseAttributeName) {
+ public void assertSelfBiDirRelationIsNotDeleted(SWTBotGefEditPart entity1,
+ SWTBotGefConnectionEditPart connection, String ownerAttributeName,
+ String inverseAttributeName) {
connection.select();
jpaDiagramEditor.clickContextMenu("Delete");
denyDelete();
assertFalse(entity1.sourceConnections().isEmpty());
- assertFalse(entity2.targetConnections().isEmpty());
+ assertFalse(entity1.targetConnections().isEmpty());
connection = entity1.sourceConnections().get(0);
assertNotNull("Attribute must not be deleted!", connection);
assertNotNull(jpaDiagramEditor.getEditPart(ownerAttributeName));
assertNotNull(jpaDiagramEditor.getEditPart(inverseAttributeName));
- assertTrue("\"Relation Attributes\" section of the owner entity must be visible!", isSectionVisible(jpaDiagramEditor, entity1, JPAEditorMessages.AddJPAEntityFeature_relationAttributesShapes));
- assertTrue("\"Relation Attributes\" section of the inverse entity must be visible!", isSectionVisible(jpaDiagramEditor, entity2, JPAEditorMessages.AddJPAEntityFeature_relationAttributesShapes));
+ assertTrue(
+ "\"Relation Attributes\" section of the owner entity must be visible!",
+ isSectionVisible(entity1,
+ JPAEditorMessages.AddJPAEntityFeature_relationAttributesShapes));
}
/**
- * Select the unidirectional relation and call its "Delete" context menu.
- * On the confirmation dialog press "No" and assert that
- * the connection and the relative relation attributes still exist
- * and the "Relation Attributes" sections of the entities' are visible.
- * @param jpaDiagramEditor
+ * Select the unidirectional relation and call its "Delete" context menu. On
+ * the confirmation dialog press "No" and assert that the connection and the
+ * relative relation attributes still exist and the "Relation Attributes"
+ * sections of the entities' are visible.
+ *
* @param entity1
* @param entity2
* @param connection
* @param ownerAttributeName
* @param inverseAttributeName
*/
- public void assertUniDirRelationIsNotDeleted(
- SWTBotGefEditor jpaDiagramEditor, SWTBotGefEditPart entity1,
- SWTBotGefEditPart entity2,
- SWTBotGefConnectionEditPart connection, String attributeName) {
+ public void assertUniDirRelationIsNotDeleted(SWTBotGefEditPart entity1,
+ SWTBotGefEditPart entity2, SWTBotGefConnectionEditPart connection,
+ String attributeName) {
connection.select();
jpaDiagramEditor.clickContextMenu("Delete");
denyDelete();
@@ -641,23 +834,28 @@ public class EditorProxy {
connection = entity1.sourceConnections().get(0);
assertNotNull("Attribute must not be deleted!", connection);
assertNotNull(jpaDiagramEditor.getEditPart(attributeName));
- assertTrue("\"Relation Attributes\" section of the owner entity must be visible!",isSectionVisible(jpaDiagramEditor, entity1, JPAEditorMessages.AddJPAEntityFeature_relationAttributesShapes));
- assertFalse("\"Relation Attributes\" section of the inverse entity must not be visible!", isSectionVisible(jpaDiagramEditor, entity2, JPAEditorMessages.AddJPAEntityFeature_relationAttributesShapes));
+ assertTrue(
+ "\"Relation Attributes\" section of the owner entity must be visible!",
+ isSectionVisible(entity1,
+ JPAEditorMessages.AddJPAEntityFeature_relationAttributesShapes));
+ assertFalse(
+ "\"Relation Attributes\" section of the inverse entity must not be visible!",
+ isSectionVisible(entity2,
+ JPAEditorMessages.AddJPAEntityFeature_relationAttributesShapes));
}
-
+
/**
- * Select the unidirectional self relation and call its "Delete" context menu.
- * On the confirmation dialog press "No" and assert that
- * the connection and the relative relation attributes still exist
- * and the "Relation Attributes" sections of the entities' are visible.
- * @param jpaDiagramEditor
+ * Select the unidirectional self relation and call its "Delete" context
+ * menu. On the confirmation dialog press "No" and assert that the
+ * connection and the relative relation attributes still exist and the
+ * "Relation Attributes" sections of the entities' are visible.
+ *
* @param entity1
* @param connection
* @param ownerAttributeName
* @param inverseAttributeName
*/
- public void assertSelfUniDirRelationIsNotDeleted(
- SWTBotGefEditor jpaDiagramEditor, SWTBotGefEditPart entity1,
+ public void assertSelfUniDirRelationIsNotDeleted(SWTBotGefEditPart entity1,
SWTBotGefConnectionEditPart connection, String attributeName) {
connection.select();
jpaDiagramEditor.clickContextMenu("Delete");
@@ -667,143 +865,175 @@ public class EditorProxy {
connection = entity1.sourceConnections().get(0);
assertNotNull("Attribute must not be deleted!", connection);
assertNotNull(jpaDiagramEditor.getEditPart(attributeName));
- assertTrue("\"Relation Attributes\" section of the owner entity must be visible!", isSectionVisible(jpaDiagramEditor, entity1, JPAEditorMessages.AddJPAEntityFeature_relationAttributesShapes));
+ assertTrue(
+ "\"Relation Attributes\" section of the owner entity must be visible!",
+ isSectionVisible(entity1,
+ JPAEditorMessages.AddJPAEntityFeature_relationAttributesShapes));
}
/**
- * Select the bidirectional relation and call its "Delete" context menu.
- * On the confirmation dialog press "Yes" and assert that
- * the connection and the relative relation attributes do not exist anymore
- * and the "Relation Attributes" sections of the entities' are not visible.
- * @param jpaDiagramEditor
+ * Select the bidirectional relation and call its "Delete" context menu. On
+ * the confirmation dialog press "Yes" and assert that the connection and
+ * the relative relation attributes do not exist anymore and the
+ * "Relation Attributes" sections of the entities' are not visible.
+ *
* @param entity1
* @param entity2
* @param connection
* @param ownerAttributeName
* @param inverseAttributeName
*/
- public void assertBiDirRelationIsDeleted(SWTBotGefEditor jpaDiagramEditor,
- SWTBotGefEditPart entity1, SWTBotGefEditPart entity2,
- SWTBotGefConnectionEditPart connection,
- String ownerAttributeName, String inverseAttributeName) {
+ public void assertBiDirRelationIsDeleted(SWTBotGefEditPart entity1, SWTBotGefEditPart entity2,
+ SWTBotGefConnectionEditPart connection, String ownerAttributeName,
+ String inverseAttributeName) {
connection.select();
jpaDiagramEditor.clickContextMenu("Delete");
confirmDelete();
- bot.waitUntil(new ElementDisappears(jpaDiagramEditor, ownerAttributeName));
+ bot.waitUntil(new ElementDisappears(jpaDiagramEditor,
+ ownerAttributeName), 10000);
assertTrue(entity1.sourceConnections().isEmpty());
assertTrue(entity2.targetConnections().isEmpty());
assertNull(jpaDiagramEditor.getEditPart(ownerAttributeName));
assertNull(jpaDiagramEditor.getEditPart(inverseAttributeName));
- assertFalse("\"Relation Attributes\" section of the owner entity must not be visible!", isSectionVisible(jpaDiagramEditor, entity1, JPAEditorMessages.AddJPAEntityFeature_relationAttributesShapes));
- assertFalse("\"Relation Attributes\" section of the inverse entity must not be visible!", isSectionVisible(jpaDiagramEditor, entity2, JPAEditorMessages.AddJPAEntityFeature_relationAttributesShapes));
+
+ assertFalse(
+ "\"Relation Attributes\" section of the owner entity must not be visible!",
+ isSectionVisible(entity1,
+ JPAEditorMessages.AddJPAEntityFeature_relationAttributesShapes));
+ assertFalse(
+ "\"Relation Attributes\" section of the inverse entity must not be visible!",
+ isSectionVisible(entity2,
+ JPAEditorMessages.AddJPAEntityFeature_relationAttributesShapes));
}
-
+
/**
- * Select the bidirectional self relation and call its "Delete" context menu.
- * On the confirmation dialog press "Yes" and assert that
- * the connection and the relative relation attributes do not exist anymore
- * and the "Relation Attributes" sections of the entities' are not visible.
- * @param jpaDiagramEditor
+ * Select the bidirectional self relation and call its "Delete" context
+ * menu. On the confirmation dialog press "Yes" and assert that the
+ * connection and the relative relation attributes do not exist anymore and
+ * the "Relation Attributes" sections of the entities' are not visible.
+ *
* @param entity1
* @param connection
* @param ownerAttributeName
* @param inverseAttributeName
*/
- public void assertSelfBiDirRelationIsDeleted(SWTBotGefEditor jpaDiagramEditor,
- SWTBotGefEditPart entity1,
- SWTBotGefConnectionEditPart connection,
- String ownerAttributeName, String inverseAttributeName) {
+ public void assertSelfBiDirRelationIsDeleted(SWTBotGefEditPart entity1,
+ SWTBotGefConnectionEditPart connection, String ownerAttributeName,
+ String inverseAttributeName) {
connection.select();
jpaDiagramEditor.clickContextMenu("Delete");
confirmDelete();
- bot.waitUntil(new ElementDisappears(jpaDiagramEditor, ownerAttributeName));
+ bot.waitUntil(new ElementDisappears(jpaDiagramEditor,
+ ownerAttributeName), 10000);
assertTrue(entity1.sourceConnections().isEmpty());
assertTrue(entity1.targetConnections().isEmpty());
assertNull(jpaDiagramEditor.getEditPart(ownerAttributeName));
assertNull(jpaDiagramEditor.getEditPart(inverseAttributeName));
- assertFalse("\"Relation Attributes\" section of the owner entity must not be visible!", isSectionVisible(jpaDiagramEditor, entity1, JPAEditorMessages.AddJPAEntityFeature_relationAttributesShapes));
+ assertFalse(
+ "\"Relation Attributes\" section of the owner entity must not be visible!",
+ isSectionVisible(entity1,
+ JPAEditorMessages.AddJPAEntityFeature_relationAttributesShapes));
}
-
+
/**
- * Select the unidirectional relation and call its "Delete" context menu.
- * On the confirmation dialog press "Yes" and assert that
- * the connection and the relative relation attributes do not exist anymore
- * and the "Relation Attributes" sections of the entities' are not visible.
- * @param jpaDiagramEditor
+ * Select the unidirectional relation and call its "Delete" context menu. On
+ * the confirmation dialog press "Yes" and assert that the connection and
+ * the relative relation attributes do not exist anymore and the
+ * "Relation Attributes" sections of the entities' are not visible.
+ *
* @param entity1
* @param entity2
* @param connection
* @param ownerAttributeName
* @param inverseAttributeName
*/
- public void assertUniDirRelationIsDeleted(SWTBotGefEditor jpaDiagramEditor,
- SWTBotGefEditPart entity1, SWTBotGefEditPart entity2,
+ public void assertUniDirRelationIsDeleted(SWTBotGefEditPart entity1, SWTBotGefEditPart entity2,
SWTBotGefConnectionEditPart connection, String attributeName) {
connection.select();
jpaDiagramEditor.clickContextMenu("Delete");
confirmDelete();
- bot.waitUntil(new ElementDisappears(jpaDiagramEditor, attributeName));
+ bot.waitUntil(new ElementDisappears(jpaDiagramEditor, attributeName),
+ 10000);
assertTrue(entity1.sourceConnections().isEmpty());
assertTrue(entity2.targetConnections().isEmpty());
assertNull(jpaDiagramEditor.getEditPart(attributeName));
- assertFalse("\"Relation Attributes\" section of the owner entity must not be visible!", isSectionVisible(jpaDiagramEditor, entity1, JPAEditorMessages.AddJPAEntityFeature_relationAttributesShapes));
- assertFalse("\"Relation Attributes\" section of the inverse entity must not be visible!", isSectionVisible(jpaDiagramEditor, entity2, JPAEditorMessages.AddJPAEntityFeature_relationAttributesShapes));
+ assertFalse(
+ "\"Relation Attributes\" section of the owner entity must not be visible!",
+ isSectionVisible(entity1,
+ JPAEditorMessages.AddJPAEntityFeature_relationAttributesShapes));
+ assertFalse(
+ "\"Relation Attributes\" section of the inverse entity must not be visible!",
+ isSectionVisible(entity2,
+ JPAEditorMessages.AddJPAEntityFeature_relationAttributesShapes));
}
-
+
/**
- * Select the unidirectional self relation and call its "Delete" context menu.
- * On the confirmation dialog press "Yes" and assert that
- * the connection and the relative relation attributes do not exist anymore
- * and the "Relation Attributes" sections of the entities' are not visible.
- * @param jpaDiagramEditor
+ * Select the unidirectional self relation and call its "Delete" context
+ * menu. On the confirmation dialog press "Yes" and assert that the
+ * connection and the relative relation attributes do not exist anymore and
+ * the "Relation Attributes" sections of the entities' are not visible.
+ *
* @param entity1
* @param connection
* @param ownerAttributeName
* @param inverseAttributeName
*/
- public void assertSelfUniDirRelationIsDeleted(SWTBotGefEditor jpaDiagramEditor,
- SWTBotGefEditPart entity1,
+ public void assertSelfUniDirRelationIsDeleted(SWTBotGefEditPart entity1,
SWTBotGefConnectionEditPart connection, String attributeName) {
connection.select();
jpaDiagramEditor.clickContextMenu("Delete");
confirmDelete();
- bot.waitUntil(new ElementDisappears(jpaDiagramEditor, attributeName));
+ bot.waitUntil(new ElementDisappears(jpaDiagramEditor, attributeName),
+ 10000);
assertTrue(entity1.sourceConnections().isEmpty());
assertTrue(entity1.targetConnections().isEmpty());
assertNull(jpaDiagramEditor.getEditPart(attributeName));
- assertFalse("\"Relation Attributes\" section of the owner entity must not be visible!", isSectionVisible(jpaDiagramEditor, entity1, JPAEditorMessages.AddJPAEntityFeature_relationAttributesShapes));
+ assertFalse(
+ "\"Relation Attributes\" section of the owner entity must not be visible!",
+ isSectionVisible(entity1,
+ JPAEditorMessages.AddJPAEntityFeature_relationAttributesShapes));
}
-
+
/**
- * Assert that there is exactly one GEF element representing the relationship
- * @param jpaDiagramEditor
+ * Assert that there is exactly one GEF element representing the
+ * relationship
+ *
* @param entity1
* @param entity2
*/
- public void assertConnectionIsCreated(SWTBotGefEditor jpaDiagramEditor,
- SWTBotGefEditPart entity1, SWTBotGefEditPart entity2, boolean isBiDIr) {
- //assert that there is exactly one relationship, which start from entity1
- //and that there is no relationship which starts from entity2
+ public void assertConnectionIsCreated(SWTBotGefEditPart entity1, SWTBotGefEditPart entity2,
+ boolean isBiDIr) {
+ // assert that there is exactly one relationship, which start from
+ // entity1
+ // and that there is no relationship which starts from entity2
assertFalse(entity1.sourceConnections().isEmpty());
assertEquals(1, entity1.sourceConnections().size());
assertTrue(entity2.sourceConnections().isEmpty());
-
- //assert that there is exactly one relationship which ends in entity2
- //and that there is no relationship which end in entity1.
+
+ // assert that there is exactly one relationship which ends in entity2
+ // and that there is no relationship which end in entity1.
assertFalse(entity2.targetConnections().isEmpty());
assertEquals(1, entity2.targetConnections().size());
- assertTrue(entity1.targetConnections().isEmpty());
-
- assertTrue("\"Relation Attributes\" section of the owner entity must be visible!", isSectionVisible(jpaDiagramEditor, entity1, JPAEditorMessages.AddJPAEntityFeature_relationAttributesShapes));
- if(isBiDIr){
- assertTrue("\"Relation Attributes\" section of the inverse entity must be visible!", isSectionVisible(jpaDiagramEditor, entity2, JPAEditorMessages.AddJPAEntityFeature_relationAttributesShapes));
+// assertTrue(entity1.targetConnections().isEmpty());
+
+ assertTrue(
+ "\"Relation Attributes\" section of the owner entity must be visible!",
+ isSectionVisible(entity1,
+ JPAEditorMessages.AddJPAEntityFeature_relationAttributesShapes));
+ if (isBiDIr) {
+ assertTrue(
+ "\"Relation Attributes\" section of the inverse entity must be visible!",
+ isSectionVisible(entity2,
+ JPAEditorMessages.AddJPAEntityFeature_relationAttributesShapes));
} else {
- assertFalse("\"Relation Attributes\" section of the inverse entity must not be visible!", isSectionVisible(jpaDiagramEditor, entity2, JPAEditorMessages.AddJPAEntityFeature_relationAttributesShapes));
+ assertFalse(
+ "\"Relation Attributes\" section of the inverse entity must not be visible!",
+ isSectionVisible(entity2,
+ JPAEditorMessages.AddJPAEntityFeature_relationAttributesShapes));
}
}
-
- public void assertIsARelationExists(SWTBotGefEditor jpaDiagramEditor,
- SWTBotGefEditPart entity1, SWTBotGefEditPart entity2) {
+
+ public void assertIsARelationExists(SWTBotGefEditPart entity1, SWTBotGefEditPart entity2) {
// assert that there is exactly one relationship, which start from
// entity2 and that there is no relationship which starts from entity2
assertFalse(entity2.sourceConnections().isEmpty());
@@ -818,89 +1048,121 @@ public class EditorProxy {
}
/**
- * Assert that there is exactly one GEF element representing the self relationship
- * @param jpaDiagramEditor
+ * Assert that there is exactly one GEF element representing the self
+ * relationship
+ *
* @param entity1
*/
- public void assertSelfConnectionIsCreated(SWTBotGefEditor jpaDiagramEditor,
- SWTBotGefEditPart entity1) {
- //assert that there is exactly one relationship, which start from entity1
- //and ends in entity2
+ public void assertSelfConnectionIsCreated(SWTBotGefEditPart entity1) {
+ // assert that there is exactly one relationship, which start from
+ // entity1
+ // and ends in entity2
assertFalse(entity1.sourceConnections().isEmpty());
assertEquals(1, entity1.sourceConnections().size());
assertFalse(entity1.targetConnections().isEmpty());
assertEquals(1, entity1.targetConnections().size());
-
- assertTrue(isSectionVisible(jpaDiagramEditor, entity1, JPAEditorMessages.AddJPAEntityFeature_relationAttributesShapes));
+
+ assertTrue(isSectionVisible(entity1, JPAEditorMessages.AddJPAEntityFeature_relationAttributesShapes));
}
-
+
/**
* Assert that the owner relationship attribute exists
- * @param jpaDiagramEditor
+ *
* @param rel
* @return the name of the owner relationship attribute
*/
- public String testOwnerRelationAttributeProperties(
- SWTBotGefEditor jpaDiagramEditor, IRelation rel) {
+ public String testOwnerRelationAttributeProperties(IRelation rel) {
JavaPersistentAttribute ownerAttr = rel.getOwnerAnnotatedAttribute();
String attributeName = rel.getOwnerAttributeName();
assertNotNull(ownerAttr);
assertNotNull(jpaDiagramEditor.getEditPart(attributeName));
-
+
return attributeName;
}
-
+
+ /**
+ * Assert that the embedded attribute exists
+ *
+ * @param rel
+ * @return the name of the embedding attribute
+ */
+ public String testEmbeddedAttributeProperties(HasReferanceRelation rel,
+ String attributeMapping) {
+ JavaPersistentAttribute embeddedAttr = rel
+ .getEmbeddedAnnotatedAttribute();
+ String attributeName = embeddedAttr.getName();
+ assertNotNull(embeddedAttr);
+ assertNotNull(jpaDiagramEditor.getEditPart(attributeName));
+ assertEquals("The attribute must be embedded attribute.",
+ embeddedAttr.getMappingKey(), attributeMapping);
+
+ return attributeName;
+ }
+
/**
* Assert that the inverse relationship attribute exists.
- * @param jpaDiagramEditor
+ *
* @param rel
* @return the name of the inverse relationship attribute
*/
- public String testInverseRelationAttributeProperties(
- SWTBotGefEditor jpaDiagramEditor, IRelation rel) {
- JavaPersistentAttribute inverseAttr = rel.getInverseAnnotatedAttribute();
+ public String testInverseRelationAttributeProperties(IRelation rel) {
+ JavaPersistentAttribute inverseAttr = rel
+ .getInverseAnnotatedAttribute();
String inverseAttributeName = rel.getInverseAttributeName();
assertNotNull(inverseAttr);
assertNotNull(jpaDiagramEditor.getEditPart(inverseAttributeName));
return inverseAttributeName;
}
-
-
+
/**
* Checks whether a section of a particular entity is visible
- * @param diagramEditor
- * @param editPart - the particular entity
- * @param sectionTitle - the title of the section to be checked
- * @return true, if the sections is visible, false otherwise
+ *
+ * @param editPart
+ * - the particular entity
+ * @param sectionTitle
+ * - the title of the section to be checked
+ * @return true, if the sections is visible, false otherwise
*/
@SuppressWarnings("deprecation")
- public boolean isSectionVisible(SWTBotGefEditor diagramEditor, SWTBotGefEditPart editPart, String sectionTitle){
+ public boolean isSectionVisible(SWTBotGefEditPart editPart, String sectionTitle) {
List<SWTBotGefEditPart> children = editPart.children();
- SWTBotGefEditPart section = diagramEditor.getEditpart(sectionTitle, children);
- ((PictogramElement)section.part().getModel()).isVisible();
+ SWTBotGefEditPart section = jpaDiagramEditor.getEditpart(sectionTitle,
+ children);
+ ((PictogramElement) section.part().getModel()).isVisible();
IFigure figure = ((GraphicalEditPart) section.part()).getFigure();
- return figure.isVisible();
+ return figure.isVisible() || figure.isShowing();
+ }
+
+ public SWTBotGefEditPart getSectionInJPT(SWTBotGefEditPart editPart, String sectionTitle) {
+ List<SWTBotGefEditPart> children = editPart.children();
+ SWTBotGefEditPart section = jpaDiagramEditor.getEditpart(sectionTitle,
+ children);
+ return section;
}
/**
* Change the mapping of the type or attribute.
+ *
* @param newMappingType
*/
public void changeMappingtype(String newMappingType) {
- workbenchBot.waitUntil(shellIsActive("Mapping Type Selection"), 5000);
- SWTBotShell mappingTypeShell = workbenchBot.shell("Mapping Type Selection");
- mappingTypeShell.bot().table().getTableItem(newMappingType).select();
+ workbenchBot.waitUntil(shellIsActive("Mapping Type Selection"), 10000);
+ SWTBotShell mappingTypeShell = workbenchBot
+ .shell("Mapping Type Selection");
+ mappingTypeShell.bot().table().getTableItem(newMappingType).select();
getOkButton(mappingTypeShell).click();
}
/**
* Click on the mapping type link in the JPA Details view
+ *
* @param styledText
* @param position
*/
- public void clickOnStyledText(final SWTBotStyledText styledText, int position) {
- styledText.navigateTo(new Position(0, position));
+ public void clickOnStyledText(final SWTBotStyledText styledText,
+ int position) {
+ styledText.navigateTo(new Position(0, position));
asyncExec(new VoidResult() {
public void run() {
styledText.widget.notifyListeners(SWT.MouseDown, new Event());
@@ -911,89 +1173,815 @@ public class EditorProxy {
public void waitASecond() {
try {
- Thread.sleep(2000);
+ Thread.sleep(3000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
-
- /**
- * Assert that the relation attribute is correctly mapped in the JPA Details view
- * @param jpaDiagramEditor
- * @param attributeName
- * @param relationAttributeMapping - the expected attribute mapping
- */
- public void assertAttributeIsCorretlyMapped(IFeatureProvider fp,
- SWTBotGefEditor jpaDiagramEditor, String attributeName, String relationAttributeMapping) {
-
- SWTBotGefEditPart attribute = jpaDiagramEditor.getEditPart(attributeName);
- PictogramElement el = (PictogramElement) attribute.part().getModel();
- Object bo = fp.getBusinessObjectForPictogramElement(el);
- assertTrue("The selected element is not an attribute!", (bo instanceof JavaPersistentAttribute));
-
- assertEquals(((JavaPersistentAttribute)bo).getMappingKey(), relationAttributeMapping);
- }
-
+
/**
- * Assert that the relation attribute is correctly mapped in the JPA Details view
- * @param jpaDiagramEditor
+ * Assert that the relation attribute is correctly mapped in the JPA Details
+ * view
+ *
* @param attributeName
- * @param relationAttributeMapping - the expected attribute mapping
+ * @param relationAttributeMapping
+ * - the expected attribute mapping
*/
- public void assertAttributeIsCorretlyMappedInJPADetailsView(
- SWTBotGefEditor jpaDiagramEditor, String attributeName, String relationAttributeMapping) {
+ public void assertAttributeIsCorretlyMapped(String attributeName,
+ String relationAttributeMapping) {
- //assert that the JPA Details view is opened
+ // assert that the JPA Details view is opened
SWTBotView jpaDetailsView = workbenchBot.viewByTitle("JPA Details");
jpaDetailsView.setFocus();
- assertTrue("JPA Details view must be opened!", jpaDetailsView.isActive());
-
- SWTBotGefEditPart oneToManyAttr = jpaDiagramEditor.getEditPart(attributeName);
- oneToManyAttr.click();
- oneToManyAttr.select();
+ assertTrue("JPA Details view must be opened!",
+ jpaDetailsView.isActive());
- //assert that the default entity's attribute is mapped as primary key
+ SWTBotGefEditPart attribute = jpaDiagramEditor
+ .getEditPart(attributeName);
+ attribute.select();
+ attribute.click();
+
+ // assert that the default entity's attribute is mapped as primary key
SWTBot jpaDetailsBot = jpaDetailsView.bot();
SWTBotStyledText styledText = jpaDetailsBot.styledText();
- assertEquals("Attribute '" +attributeName+ "' is mapped as " +relationAttributeMapping+ ".", styledText.getText());
+ assertEquals("Attribute '" + attributeName + "' is mapped as "
+ + relationAttributeMapping + ".", styledText.getText());
}
-
- /**
- * Assert that the type is correctly mapped in the JPA Details view
- * @param jpaDiagramEditor
- * @param typeName
- * @param typeMapping - the expected type mapping
- */
- public void assertTypeIsCorretlyMapped(IFeatureProvider fp,
- SWTBotGefEditor jpaDiagramEditor, String typeName, String typeMapping) {
- SWTBotGefEditPart attribute = jpaDiagramEditor.getEditPart(typeName);
- PictogramElement el = (PictogramElement) attribute.part().getModel();
- Object bo = fp.getBusinessObjectForPictogramElement(el);
- assertTrue("The selected element is not an persistent type!", (bo instanceof JavaPersistentType));
- assertEquals(((JavaPersistentType)bo).getMappingKey(), typeMapping);
- }
-
/**
* Assert that the type is correctly mapped in the JPA Details view
- * @param jpaDiagramEditor
+ *
* @param typeName
- * @param typeMapping - the expected type mapping
+ * @param typeMapping
+ * - the expected type mapping
*/
- public void assertTypeIsCorretlyMappedInJPADetailsView(
- SWTBotGefEditor jpaDiagramEditor, String typeName, String typeMapping) {
+ public void assertTypeIsCorretlyMapped(String typeName, String typeMapping) {
workbenchBot.viewByTitle("JPA Details").close();
- jpaDiagramEditor.clickContextMenu(JPAEditorMessages.JPAEditorToolBehaviorProvider_openJPADetailsView);
- //assert that the JPA Details view is opened
- SWTBotView jpaDetailsView = workbenchBot.viewByTitle("JPA Details");
- assertTrue("JPA Details view must be opened!", jpaDetailsView.isActive());
SWTBotGefEditPart type = jpaDiagramEditor.getEditPart(typeName);
type.click();
+
+ jpaDiagramEditor
+ .clickContextMenu(JPAEditorMessages.JPAEditorToolBehaviorProvider_openJPADetailsView);
+ // assert that the JPA Details view is opened
+ SWTBotView jpaDetailsView = workbenchBot.viewByTitle("JPA Details");
+ assertTrue("JPA Details view must be opened!",
+ jpaDetailsView.isActive());
- //assert that the default entity's attribute is mapped as the given mapping key
+ // assert that the default entity's attribute is mapped as the given
+ // mapping key
SWTBot jpaDetailsBot = jpaDetailsView.bot();
SWTBotStyledText styledText = jpaDetailsBot.styledText();
- assertEquals("Type '" +typeName+ "' is mapped as " +typeMapping+ ".", styledText.getText());
+ assertEquals("Type '" + typeName + "' is mapped as " + typeMapping
+ + ".", styledText.getText());
+ }
+
+ public void deleteJPTViaButton(SWTBotGefEditPart jptType) {
+
+ String jptName = getJPTObjectForGefElement(jptType)
+ .getSimpleName();
+
+ pressEntityContextButton(jptType,
+ JPAEditorMessages.JPAEditorToolBehaviorProvider_deleteEntityFromModelButtonLabel);
+ denyDelete();
+
+ jptType = jpaDiagramEditor.getEditPart(jptName);
+ assertNotNull("Entity is deleted!", jptType);
+
+ pressEntityContextButton(jptType,
+ JPAEditorMessages.JPAEditorToolBehaviorProvider_deleteEntityFromModelButtonLabel);
+ confirmDelete();
+ bot.waitUntil(new ElementDisappears(jpaDiagramEditor, jptName), 10000);
+ jptType = jpaDiagramEditor.getEditPart(jptName);
+ assertNull("Entity is not deleted!", jptType);
+ }
+
+ public void deleteJPTViaMenu(SWTBotGefEditPart jptType) {
+
+ String jptName = getJPTObjectForGefElement(jptType)
+ .getSimpleName();
+
+ jpaDiagramEditor
+ .clickContextMenu(JPAEditorMessages.JPAEditorToolBehaviorProvider_deleteEntityFromModelButtonLabel);
+ denyDelete();
+
+ jptType = jpaDiagramEditor.getEditPart(jptName);
+ assertNotNull("Entity is deleted!", jptType);
+
+ jpaDiagramEditor
+ .clickContextMenu(JPAEditorMessages.JPAEditorToolBehaviorProvider_deleteEntityFromModelButtonLabel);
+ confirmDelete();
+ bot.waitUntil(new ElementDisappears(jpaDiagramEditor, jptName), 10000);
+ jptType = jpaDiagramEditor.getEditPart(jptName);
+ assertNull("Entity is not deleted!", jptType);
+ }
+
+ public void removeAttributeViaButton(SWTBotGefEditPart jptType, String attributeName) {
+
+ assertFalse(
+ "\"Other Attributes\" section must not be visible!",
+
+ isSectionVisible(JPAEditorMessages.AddJPAEntityFeature_basicAttributesShapes,
+ jptType));
+
+ SWTBotGefEditPart attribute = addAttributeToJPT(jptType, attributeName);
+ assertTrue("Editor must be dirty", jpaDiagramEditor.isDirty());
+ jpaDiagramEditor.save();
+
+ pressAttributeDeleteContextButton(attribute);
+ denyDelete();
+ attribute = jpaDiagramEditor.getEditPart(attributeName);
+ assertNotNull("Attribute must not be deleted!", attribute);
+
+ pressAttributeDeleteContextButton(attribute);
+ confirmDelete();
+ bot.waitUntil(new ElementDisappears(jpaDiagramEditor, attributeName),
+ 20000);
+ attribute = jpaDiagramEditor.getEditPart(attributeName);
+ assertNull("Attribute must be deleted!", attribute);
+
+ jpaDiagramEditor.save();
+ assertFalse(
+ "\"Other Attributes\" section must not be visible!",
+ isSectionVisible(JPAEditorMessages.AddJPAEntityFeature_basicAttributesShapes,
+ jptType));
+
+ }
+
+ public void removeAttributeViaMenu(SWTBotGefEditPart jptType, String attributeName) {
+ assertFalse(
+ "\"Other Attributes\" section must not be visible!",
+ isSectionVisible(JPAEditorMessages.AddJPAEntityFeature_basicAttributesShapes,
+ jptType));
+
+ SWTBotGefEditPart attribute = addAttributeToJPT(jptType, attributeName);
+ assertTrue("Editor must be dirty", jpaDiagramEditor.isDirty());
+ jpaDiagramEditor.save();
+
+ attribute.click();
+ jpaDiagramEditor.clickContextMenu("Delete");
+ denyDelete();
+ attribute = jpaDiagramEditor.getEditPart(attributeName);
+ assertNotNull("Attribute must not be deleted!", attribute);
+
+ attribute.click();
+ jpaDiagramEditor.clickContextMenu("Delete");
+ confirmDelete();
+ bot.waitUntil(new ElementDisappears(jpaDiagramEditor, attributeName),
+ 20000);
+ attribute = jpaDiagramEditor.getEditPart(attributeName);
+ assertNull("Attribute must be deleted!", attribute);
+
+ assertFalse(
+ "\"Other Attributes\" section must not be visible!",
+ isSectionVisible(JPAEditorMessages.AddJPAEntityFeature_basicAttributesShapes,
+ jptType));
+ }
+
+ public void directEditAttribute(SWTBotGefEditPart jptType, String attributeName) {
+
+ assertFalse(
+ "\"Other Attributes\" section must not be visible!",
+ isSectionVisible(JPAEditorMessages.AddJPAEntityFeature_basicAttributesShapes,
+ jptType));
+
+ SWTBotGefEditPart attribute = addAttributeToJPT(jptType, attributeName);
+ assertNotNull("The attribute must not be renamed!", attribute);
+
+ jpaDiagramEditor.directEditType("newAttrName");
+ SWTBotGefEditPart oldAttribute = jpaDiagramEditor
+ .getEditPart(attributeName);
+ SWTBotGefEditPart newAttribute = jpaDiagramEditor
+ .getEditPart("newAttrName");
+ assertNotNull("The attribute must be renamed!", newAttribute);
+ assertNull("The attribute must be renamed!", oldAttribute);
+ }
+
+ public void collapseExpandJPTViaButton(SWTBotGefEditPart jptType) {
+
+ int heigth = ((PictogramElement) jptType.part().getModel())
+ .getGraphicsAlgorithm().getHeight();
+
+ pressEntityContextButton(jptType, "Collapse");
+ waitASecond();
+
+ int newHeight = ((PictogramElement) jptType.part().getModel())
+ .getGraphicsAlgorithm().getHeight();
+ assertEquals("Entity must be collapsed!",
+ JPAEditorConstants.ENTITY_MIN_HEIGHT, newHeight);
+ assertTrue(newHeight < heigth);
+
+ pressEntityContextButton(jptType, "Expand");
+ waitASecond();
+
+ newHeight = ((PictogramElement) jptType.part().getModel())
+ .getGraphicsAlgorithm().getHeight();
+ assertEquals("Entity must be expanded!", heigth, newHeight);
+ assertTrue(newHeight > JPAEditorConstants.ENTITY_MIN_HEIGHT);
+ }
+
+ public void collapseExpandJPTViaMenu(SWTBotGefEditPart jptType) {
+
+ int heigth = ((PictogramElement) jptType.part().getModel())
+ .getGraphicsAlgorithm().getHeight();
+
+ jpaDiagramEditor.click(jptType);
+
+ jpaDiagramEditor
+ .clickContextMenu(JPAEditorMessages.JPAEditorToolBehaviorProvider_collapseEntityMenuItem);
+ waitASecond();
+
+ int newHeight = ((PictogramElement) jptType.part().getModel())
+ .getGraphicsAlgorithm().getHeight();
+ assertEquals("Entity must be collapsed!",
+ JPAEditorConstants.ENTITY_MIN_HEIGHT, newHeight);
+ assertTrue(newHeight < heigth);
+
+ jpaDiagramEditor
+ .clickContextMenu(JPAEditorMessages.JPAEditorToolBehaviorProvider_expandEntityMenuItem);
+ waitASecond();
+
+ newHeight = ((PictogramElement) jptType.part().getModel())
+ .getGraphicsAlgorithm().getHeight();
+ assertEquals("Entity must be expanded!", heigth, newHeight);
+ assertTrue(newHeight > JPAEditorConstants.ENTITY_MIN_HEIGHT);
+ }
+
+ public void collapseExpandAllJPTsViaMenu(SWTBotGefEditPart jptType1, SWTBotGefEditPart jptType2) {
+
+ int heigth1 = ((PictogramElement) jptType1.part().getModel())
+ .getGraphicsAlgorithm().getHeight();
+
+ int heigth2 = ((PictogramElement) jptType2.part().getModel())
+ .getGraphicsAlgorithm().getHeight();
+
+ jpaDiagramEditor
+ .clickContextMenu(JPAEditorMessages.JPAEditorToolBehaviorProvider_collapseAllEntitiesMenuItem);
+ waitASecond();
+
+ // check that entity1 is collapsed
+ int newHeight1 = ((PictogramElement) jptType1.part().getModel())
+ .getGraphicsAlgorithm().getHeight();
+ assertEquals("Entity1 must be collapsed!",
+ JPAEditorConstants.ENTITY_MIN_HEIGHT, newHeight1);
+ assertTrue(newHeight1 < heigth1);
+
+ // check that entity2 is collapsed
+ int newHeight2 = ((PictogramElement) jptType2.part().getModel())
+ .getGraphicsAlgorithm().getHeight();
+ assertEquals("Entity2 must be collapsed!",
+ JPAEditorConstants.ENTITY_MIN_HEIGHT, newHeight2);
+ assertTrue(newHeight2 < heigth2);
+
+ jpaDiagramEditor
+ .clickContextMenu(JPAEditorMessages.JPAEditorToolBehaviorProvider_expandAllEntitiesMenuItem);
+ waitASecond();
+
+ // check that entity1 is expanded
+ newHeight1 = ((PictogramElement) jptType1.part().getModel())
+ .getGraphicsAlgorithm().getHeight();
+ assertEquals("Entity must be expanded!", heigth1, newHeight1);
+ assertTrue(newHeight1 > JPAEditorConstants.ENTITY_MIN_HEIGHT);
+
+ // check that entity2 is expanded
+ newHeight2 = ((PictogramElement) jptType2.part().getModel())
+ .getGraphicsAlgorithm().getHeight();
+ assertEquals("Entity must be expanded!", heigth2, newHeight2);
+ assertTrue(newHeight2 > JPAEditorConstants.ENTITY_MIN_HEIGHT);
+ }
+
+ public void discardChanges(SWTBotGefEditPart jptType, String attributeName) {
+
+ assertFalse(
+ "\"Other Attributes\" section must not be visible!",
+ isSectionVisible(JPAEditorMessages.AddJPAEntityFeature_basicAttributesShapes,
+ jptType));
+ assertFalse(isJPTDirty(jptType));
+
+ addAttributeToJPT(jptType, attributeName);
+ assertTrue("Editor must be dirty", jpaDiagramEditor.isDirty());
+ assertTrue(isJPTDirty(jptType));
+
+ jptType.click();
+ jpaDiagramEditor
+ .clickContextMenu(JPAEditorMessages.JPAEditorToolBehaviorProvider_discardChangesMenuItem);
+ SWTBotGefEditPart attribute = jpaDiagramEditor.getEditPart(attributeName);
+ assertNull("Changes must be discard!", attribute);
+ assertFalse(isJPTDirty(jptType));
+ }
+
+ public void removeAndDiscardChangesViaMenu(SWTBotGefEditPart jptType,
+ String attributeName) {
+
+ String jptName = getJPTObjectForGefElement(jptType).getSimpleName();
+
+ assertFalse("Diagram must contain at least one entity!",
+ jpaDiagramEditor.mainEditPart().children().isEmpty());
+
+ assertFalse(
+ "\"Other Attributes\" section must not be visible!",
+ isSectionVisible(JPAEditorMessages.AddJPAEntityFeature_basicAttributesShapes, jptType));
+ assertFalse(isJPTDirty(jptType));
+
+ addAttributeToJPT(jptType, attributeName);
+ assertTrue("Editor must be dirty", jpaDiagramEditor.isDirty());
+ assertTrue(isJPTDirty(jptType));
+
+ jptType.click();
+ jpaDiagramEditor
+ .clickContextMenu(JPAEditorMessages.JPAEditorToolBehaviorProvider_removeAndDiscardAllEntitiesAction);
+ confirmRemoveEntitiesFromDiagramDialog();
+ assertTrue("Diagram must be empty!", jpaDiagramEditor.mainEditPart()
+ .children().isEmpty());
+
+ jpaDiagramEditor
+ .clickContextMenu(JPAEditorMessages.JPAEditorToolBehaviorProvider_showAllTheEntities);
+ assertFalse("Diagram must contain at least one entity!",
+ jpaDiagramEditor.mainEditPart().children().isEmpty());
+
+ jptType = jpaDiagramEditor.getEditPart(jptName);
+ SWTBotGefEditPart attribute = jpaDiagramEditor
+ .getEditPart(attributeName);
+ assertNull("Changes must be discard!", attribute);
+ assertFalse(isJPTDirty(jptType));
+ }
+
+ public void removeAndSaveChangesViaMenu(SWTBotGefEditPart jptType, String attributeName) {
+
+ assertFalse("Diagram must contain at least one entity!",
+ jpaDiagramEditor.mainEditPart().children().isEmpty());
+
+ String jptName = getJPTObjectForGefElement(jptType).getSimpleName();
+
+ assertFalse(
+ "\"Other Attributes\" section must not be visible!",
+ isSectionVisible(JPAEditorMessages.AddJPAEntityFeature_basicAttributesShapes, jptType));
+ assertFalse(isJPTDirty(jptType));
+
+ addAttributeToJPT(jptType, attributeName);
+ assertTrue("Editor must be dirty", jpaDiagramEditor.isDirty());
+ assertTrue(isJPTDirty(jptType));
+
+ jptType.click();
+ jpaDiagramEditor
+ .clickContextMenu(JPAEditorMessages.JPAEditorToolBehaviorProvider_removeAndSaveAllEntitiesAction);
+ confirmRemoveEntitiesFromDiagramDialog();
+ assertTrue("Diagram must be empty!", jpaDiagramEditor.mainEditPart()
+ .children().isEmpty());
+
+ jpaDiagramEditor
+ .clickContextMenu(JPAEditorMessages.JPAEditorToolBehaviorProvider_showAllTheEntities);
+ assertFalse("Diagram must contain at least one entity!",
+ jpaDiagramEditor.mainEditPart().children().isEmpty());
+
+ jptType = jpaDiagramEditor.getEditPart(jptName);
+ SWTBotGefEditPart attribute = jpaDiagramEditor
+ .getEditPart(attributeName);
+ assertNotNull("Changes must be discard!", attribute);
+ assertFalse(isJPTDirty(jptType));
+ }
+
+ public void saveOnlyJPT(SWTBotGefEditPart jptType, String attributeName) {
+
+ assertFalse(
+ "\"Other Attributes\" section must not be visible!",
+ isSectionVisible(JPAEditorMessages.AddJPAEntityFeature_basicAttributesShapes,
+ jptType));
+ assertFalse(isJPTDirty(jptType));
+
+ addAttributeToJPT(jptType, attributeName);
+ assertTrue("Editor must be dirty", jpaDiagramEditor.isDirty());
+ assertTrue(isJPTDirty(jptType));
+
+ jptType.click();
+ jpaDiagramEditor
+ .clickContextMenu(JPAEditorMessages.JPAEditorToolBehaviorProvider_saveButtonText);
+ assertTrue("Editor must be dirty", jpaDiagramEditor.isDirty());
+ assertFalse(isJPTDirty(jptType));
+ }
+
+ public void testUniDirRelation(String relationFeatureName, SWTBotGefEditPart owner,
+ SWTBotGefEditPart inverse, RelType reltype, String linkLabel) {
+
+ jpaDiagramEditor.activateTool(relationFeatureName, 0);
+
+ jpaDiagramEditor.click(owner);
+ jpaDiagramEditor.click(inverse);
+ bot.waitUntil(new ConnectionIsShown(owner));
+
+ waitASecond();
+ jpaDiagramEditor.activateDefaultTool();
+
+ assertConnectionIsCreated(owner, inverse, false);
+
+ SWTBotGefConnectionEditPart connection = owner.sourceConnections().get(
+ 0);
+ IRelation rel = getConnection(connection);
+ assertNotNull(rel);
+ assertEquals(IRelation.RelDir.UNI, rel.getRelDir());
+ assertEquals(reltype, rel.getRelType());
+
+ String attributeName = testOwnerRelationAttributeProperties(rel);
+ assertNull(rel.getInverseAnnotatedAttribute());
+
+ assertAttributeIsCorretlyMapped(attributeName,
+ linkLabel);
+
+ assertUniDirRelationIsNotDeleted(owner, inverse,
+ connection, attributeName);
+
+ assertUniDirRelationIsDeleted(owner, inverse,
+ connection, attributeName);
+ }
+
+ public void testSelfUniDirRelation(String relationFeatureName, SWTBotGefEditPart entity,
+ RelType reltype, String linkLabel){
+
+ jpaDiagramEditor.activateTool(relationFeatureName, 0);
+ jpaDiagramEditor.click(entity);
+ jpaDiagramEditor.click(entity);
+ bot.waitUntil(new ConnectionIsShown(entity));
+
+ waitASecond();
+ jpaDiagramEditor.activateDefaultTool();
+
+ assertSelfConnectionIsCreated(entity);
+
+ SWTBotGefConnectionEditPart connection = entity.sourceConnections().get(0);
+ IRelation rel = getConnection(connection);
+ assertNotNull(rel);
+ assertEquals(IRelation.RelDir.UNI, rel.getRelDir());
+ assertEquals(reltype, rel.getRelType());
+
+ String attributeName = testOwnerRelationAttributeProperties(rel);
+ assertNull(rel.getInverseAnnotatedAttribute());
+
+ assertAttributeIsCorretlyMapped(attributeName, linkLabel);
+
+ assertSelfUniDirRelationIsNotDeleted(entity, connection, attributeName);
+
+ assertSelfUniDirRelationIsDeleted(entity, connection, attributeName);
+ }
+
+ public void testUniDirRelRemoveOwnerAttribute(String relationFeatureName,
+ SWTBotGefEditPart owner, SWTBotGefEditPart inverse,
+ RelType reltype, String linkLabel) {
+
+ jpaDiagramEditor.activateTool(relationFeatureName, 0);
+ jpaDiagramEditor.click(owner);
+ jpaDiagramEditor.click(inverse);
+ bot.waitUntil(new ConnectionIsShown(owner));
+
+ waitASecond();
+ jpaDiagramEditor.activateDefaultTool();
+
+ assertConnectionIsCreated(owner, inverse, false);
+
+ SWTBotGefConnectionEditPart connection = owner.sourceConnections().get(
+ 0);
+ IRelation rel = getConnection(connection);
+ assertNotNull(rel);
+ assertEquals(IRelation.RelDir.UNI, rel.getRelDir());
+ assertEquals(reltype, rel.getRelType());
+
+ String attributeName = testOwnerRelationAttributeProperties(rel);
+ assertNull(rel.getInverseAnnotatedAttribute());
+
+ assertAttributeIsCorretlyMapped(attributeName, linkLabel);
+
+ // delete the owner attribute
+ SWTBotGefEditPart ownerAttrPart = jpaDiagramEditor
+ .getEditPart(attributeName);
+ ownerAttrPart.select();
+ jpaDiagramEditor.clickContextMenu("Delete");
+ confirmDelete();
+ bot.waitUntil(new ElementDisappears(jpaDiagramEditor, attributeName),
+ 10000);
+ // assert that the connection does not exists anymore
+ assertTrue(owner.sourceConnections().isEmpty());
+ assertTrue(inverse.targetConnections().isEmpty());
+ assertNull(jpaDiagramEditor.getEditPart(attributeName));
+ assertFalse(isSectionVisible(owner, JPAEditorMessages.AddJPAEntityFeature_relationAttributesShapes));
+ }
+
+ public void testBiDirRel(String relationFeatureName, SWTBotGefEditPart owner,
+ SWTBotGefEditPart inverse, RelType reltype, String linkLabel) {
+ testBiDirRelWithTwoMappingTypes(relationFeatureName,
+ owner, inverse, reltype, linkLabel, linkLabel);
+ }
+
+ public void testSelfBiDirRel(String relationFeatureName, SWTBotGefEditPart owner,
+ RelType reltype, String linkLabel) {
+ testSelfBiDirRelWithTwoMappings(relationFeatureName,
+ owner, reltype, linkLabel, linkLabel);
+ }
+
+ public void testBiDirRelWithTwoMappingTypes(String relationFeatureName,
+ SWTBotGefEditPart owner, SWTBotGefEditPart inverse,
+ RelType reltype, String ownerLinkLabel, String inverseLinkLabel) {
+
+ jpaDiagramEditor.activateTool(relationFeatureName, 1);
+ jpaDiagramEditor.click(owner);
+ jpaDiagramEditor.click(inverse);
+ bot.waitUntil(new ConnectionIsShown(owner));
+
+ waitASecond();
+ jpaDiagramEditor.activateDefaultTool();
+
+ assertConnectionIsCreated(owner, inverse, true);
+
+ SWTBotGefConnectionEditPart connection = owner.sourceConnections().get(
+ 0);
+ IRelation rel = getConnection(connection);
+ assertNotNull(rel);
+ assertEquals(IRelation.RelDir.BI, rel.getRelDir());
+ assertEquals(reltype, rel.getRelType());
+
+ String ownerAttributeName = testOwnerRelationAttributeProperties(rel);
+
+ String inverseAttributeName = testInverseRelationAttributeProperties(rel);
+
+ assertAttributeIsCorretlyMapped(ownerAttributeName, ownerLinkLabel);
+ assertAttributeIsCorretlyMapped(inverseAttributeName, inverseLinkLabel);
+
+ assertBiDirRelationIsNotDeleted(owner, inverse,
+ connection, ownerAttributeName, inverseAttributeName);
+
+ assertBiDirRelationIsDeleted(owner, inverse,
+ connection, ownerAttributeName, inverseAttributeName);
+ }
+
+ public void testSelfBiDirRelWithTwoMappings(String relationFeatureName,
+ SWTBotGefEditPart entity, RelType reltype, String ownerLinkLabel, String inverseLinkLabel){
+
+ jpaDiagramEditor.activateTool(relationFeatureName, 1);
+ jpaDiagramEditor.click(entity);
+ jpaDiagramEditor.click(entity);
+ bot.waitUntil(new ConnectionIsShown(entity));
+
+ waitASecond();
+ jpaDiagramEditor.activateDefaultTool();
+
+ assertSelfConnectionIsCreated(entity);
+
+ SWTBotGefConnectionEditPart connection = entity.sourceConnections().get(0);
+ IRelation rel = getConnection(connection);
+ assertNotNull(rel);
+ assertEquals(IRelation.RelDir.BI, rel.getRelDir());
+ assertEquals(reltype, rel.getRelType());
+
+ String ownerAttributeName = testOwnerRelationAttributeProperties(rel);
+
+ String inverseAttributeName = testInverseRelationAttributeProperties(rel);
+
+ assertAttributeIsCorretlyMapped(ownerAttributeName, ownerLinkLabel);
+ assertAttributeIsCorretlyMapped(inverseAttributeName, inverseLinkLabel);
+
+ assertSelfBiDirRelationIsNotDeleted(entity, connection, ownerAttributeName,
+ inverseAttributeName);
+
+ assertSelfBiDirRelationIsDeleted(entity, connection, ownerAttributeName, inverseAttributeName);
+ }
+
+ public void testBiDirRelRemoveInverseAttribute(String relationFeatureName,
+ SWTBotGefEditPart owner, SWTBotGefEditPart inverse,
+ RelType reltype, String linkLabel) {
+
+ testBiDirRelWithTwoMappingsWithoutInverseAttr(relationFeatureName, owner, inverse, reltype, linkLabel,
+ linkLabel);
+ }
+
+ public void testBiDirRelWithTwoMappingsWithoutInverseAttr(String relationFeatureName,
+ SWTBotGefEditPart owner, SWTBotGefEditPart inverse,
+ RelType reltype, String ownerLinkLabel, String inverseLinkLabel) {
+
+ jpaDiagramEditor.activateTool(relationFeatureName, 1);
+ jpaDiagramEditor.click(owner);
+ jpaDiagramEditor.click(inverse);
+ bot.waitUntil(new ConnectionIsShown(owner));
+
+ waitASecond();
+ jpaDiagramEditor.activateDefaultTool();
+
+ assertConnectionIsCreated(owner, inverse, true);
+
+ SWTBotGefConnectionEditPart connection = owner.sourceConnections().get(
+ 0);
+ IRelation rel = getConnection(connection);
+ assertNotNull(rel);
+ assertEquals(IRelation.RelDir.BI, rel.getRelDir());
+ assertEquals(reltype, rel.getRelType());
+
+ String ownerAttributeName = testOwnerRelationAttributeProperties(rel);
+
+ String inverseAttributeName = testInverseRelationAttributeProperties(rel);
+
+ assertAttributeIsCorretlyMapped(ownerAttributeName, ownerLinkLabel);
+ assertAttributeIsCorretlyMapped(inverseAttributeName, inverseLinkLabel);
+
+ // delete the inverse attribute
+ SWTBotGefEditPart inverseAttr = jpaDiagramEditor
+ .getEditPart(inverseAttributeName);
+ inverseAttr.select();
+ jpaDiagramEditor.clickContextMenu("Delete");
+ confirmDelete();
+
+ waitASecond();
+ // assert that the connection still exists, but it is unidirectional now
+ assertConnectionIsCreated(owner, inverse, false);
+ connection = owner.sourceConnections().get(0);
+ rel = getConnection(connection);
+ assertNotNull(rel);
+ assertEquals(IRelation.RelDir.UNI, rel.getRelDir());
+ assertEquals(reltype, rel.getRelType());
+ assertEquals(ownerAttributeName,
+ testOwnerRelationAttributeProperties(rel));
+ assertNull(rel.getInverseAnnotatedAttribute());
+ assertAttributeIsCorretlyMapped(ownerAttributeName,
+ ownerLinkLabel);
+
+ // delete the owner attribute
+ SWTBotGefEditPart ownerAttr = jpaDiagramEditor
+ .getEditPart(ownerAttributeName);
+ ownerAttr.click();
+ jpaDiagramEditor.clickContextMenu("Delete");
+ confirmDelete();
+ bot.waitUntil(new ElementDisappears(jpaDiagramEditor,
+ ownerAttributeName), 10000);
+ // assert that the connection does not exists anymore
+ assertTrue(owner.sourceConnections().isEmpty());
+ assertTrue(inverse.targetConnections().isEmpty());
+ assertNull(jpaDiagramEditor.getEditPart(ownerAttributeName));
+ assertNull(jpaDiagramEditor.getEditPart(inverseAttributeName));
+ assertFalse(isSectionVisible(owner,
+ JPAEditorMessages.AddJPAEntityFeature_relationAttributesShapes));
+ assertFalse(isSectionVisible(inverse,
+ JPAEditorMessages.AddJPAEntityFeature_relationAttributesShapes));
+ }
+
+ public void testBiDirRelRemoveOwnerAttr(String relationFeatureName, SWTBotGefEditPart owner,
+ SWTBotGefEditPart inverse, RelType reltype, String linkLabel) {
+ testBiDirRelWithTwoMappingsWithoutOwnerAttr(
+ relationFeatureName, owner, inverse, reltype, linkLabel,
+ linkLabel);
+ }
+
+ public void testBiDirRelWithTwoMappingsWithoutOwnerAttr(String relationFeatureName,
+ SWTBotGefEditPart owner, SWTBotGefEditPart inverse,
+ RelType reltype, String ownerLinkLabel, String inverseLinkLabel) {
+
+ jpaDiagramEditor.activateTool(relationFeatureName, 1);
+ jpaDiagramEditor.click(owner);
+ jpaDiagramEditor.click(inverse);
+ bot.waitUntil(new ConnectionIsShown(owner));
+
+ waitASecond();
+ jpaDiagramEditor.activateDefaultTool();
+
+ assertConnectionIsCreated(owner, inverse, true);
+
+ SWTBotGefConnectionEditPart connection = owner.sourceConnections().get(
+ 0);
+ IRelation rel = getConnection(connection);
+ assertNotNull(rel);
+ assertEquals(IRelation.RelDir.BI, rel.getRelDir());
+ assertEquals(reltype, rel.getRelType());
+
+ String ownerAttributeName = testOwnerRelationAttributeProperties(rel);
+
+ String inverseAttributeName = testInverseRelationAttributeProperties(rel);
+
+ assertAttributeIsCorretlyMapped(ownerAttributeName, ownerLinkLabel);
+ assertAttributeIsCorretlyMapped(inverseAttributeName, inverseLinkLabel);
+
+ // delete the owner attribute
+ SWTBotGefEditPart ownerAttrPart = jpaDiagramEditor
+ .getEditPart(ownerAttributeName);
+ ownerAttrPart.select();
+ jpaDiagramEditor.clickContextMenu("Delete");
+ confirmDelete();
+ bot.waitUntil(new ElementDisappears(jpaDiagramEditor,
+ ownerAttributeName), 10000);
+ // assert that the connection does not exists anymore
+ assertTrue(owner.sourceConnections().isEmpty());
+ assertTrue(inverse.targetConnections().isEmpty());
+ assertNull(jpaDiagramEditor.getEditPart(ownerAttributeName));
+ // assert that the inverse attribute still exists
+ assertNotNull(jpaDiagramEditor.getEditPart(inverseAttributeName));
+ assertFalse(isSectionVisible(owner,
+ JPAEditorMessages.AddJPAEntityFeature_relationAttributesShapes));
+ // assert that the inverse attribute still exists
+ assertTrue(isSectionVisible(inverse,
+ JPAEditorMessages.AddJPAEntityFeature_relationAttributesShapes));
+ }
+
+ public void createInheritedEntity(SWTBotGefEditPart superclass, String subclassName,
+ String superclassMappingLinkLabel, boolean byMappedSuperclass) {
+
+ String superclassName = getJPTObjectForGefElement(superclass).getSimpleName();
+
+ jpaDiagramEditor
+ .activateTool(JPAEditorMessages.CreateJPAEntityFromMappedSuperclassFeature_createInheritedEntityFeatureName);
+ jpaDiagramEditor.click(superclass);
+ jpaDiagramEditor.click(50, 200);
+
+ bot.waitUntil(new ElementIsShown(jpaDiagramEditor, subclassName), 10000);
+
+ SWTBotGefEditPart inheritedEntity = jpaDiagramEditor
+ .getEditPart(subclassName);
+ assertNotNull(inheritedEntity);
+ if(byMappedSuperclass){
+ assertTrue(isSectionVisible(inheritedEntity,
+ JPAEditorMessages.AddJPAEntityFeature_primaryKeysShape));
+ } else {
+ assertFalse(isSectionVisible(inheritedEntity,
+ JPAEditorMessages.AddJPAEntityFeature_primaryKeysShape));
+ }
+ assertFalse(isSectionVisible(inheritedEntity,
+ JPAEditorMessages.AddJPAEntityFeature_relationAttributesShapes));
+ assertFalse(isSectionVisible(inheritedEntity,
+ JPAEditorMessages.AddJPAEntityFeature_basicAttributesShapes));
+
+ jpaDiagramEditor.activateDefaultTool();
+
+ assertIsARelationExists(superclass, inheritedEntity);
+
+ SWTBotGefConnectionEditPart connection = superclass.targetConnections()
+ .get(0);
+ FreeFormConnection conn = (FreeFormConnection) connection.part()
+ .getModel();
+ assertTrue(IsARelation.isIsAConnection(conn));
+ IsARelation rel = getIsARelationship();
+ assertNotNull(rel);
+
+ assertEquals(getJPTObjectForGefElement(inheritedEntity), rel.getSubclass());
+ assertEquals(getJPTObjectForGefElement(superclass), rel.getSuperclass());
+
+ assertTypeIsCorretlyMapped(superclassName, superclassMappingLinkLabel);
+ assertTypeIsCorretlyMapped(subclassName, JptUiDetailsMessages.EntityUiProvider_linkLabel);
+ }
+
+ public void testNoConnectionIsCreated(String relationFeatureName,
+ int indexInPallete, SWTBotGefEditPart owner,
+ SWTBotGefEditPart inverse) {
+
+ jpaDiagramEditor.activateTool(relationFeatureName, indexInPallete);
+
+ jpaDiagramEditor.click(owner);
+ jpaDiagramEditor.click(inverse);
+
+ waitASecond();
+
+ assertTrue("There is no connection created.", owner
+ .sourceConnections().isEmpty());
+ assertTrue("There is no connection created.", inverse
+ .sourceConnections().isEmpty());
+ assertTrue("There is no connection.", inverse.targetConnections()
+ .isEmpty());
+ }
+
+ public void testNoConnectionIsCreatedWithEmbeddable(String relationFeatureName,
+ int indexInPallete, SWTBotGefEditPart owner,
+ SWTBotGefEditPart inverse) {
+
+ jpaDiagramEditor.activateTool(relationFeatureName, indexInPallete);
+
+ jpaDiagramEditor.click(owner);
+ jpaDiagramEditor.click(inverse);
+
+ waitASecond();
+
+ assertTrue("There is no connection created.", owner
+ .sourceConnections().isEmpty());
+ assertTrue("There is no connection created.", inverse
+ .sourceConnections().isEmpty());
+ }
+
+ public void testNoEmbeddedConnectionIsCreated(String relationFeatureName,
+ int indexInPallete, SWTBotGefEditPart owner,
+ SWTBotGefEditPart inverse, boolean alreadyEmbed) {
+
+ jpaDiagramEditor.activateTool(relationFeatureName, indexInPallete);
+
+ jpaDiagramEditor.click(owner);
+ jpaDiagramEditor.click(inverse);
+
+ waitASecond();
+
+ assertTrue("There is no connection created.", owner
+ .sourceConnections().isEmpty());
+ if(alreadyEmbed){
+ assertFalse("There is no connection created.", inverse
+ .sourceConnections().isEmpty());
+ } else {
+ assertTrue("There is no connection created.", inverse
+ .sourceConnections().isEmpty());
+ }
+ assertTrue("There is no connection.", inverse.targetConnections()
+ .isEmpty());
+ }
+
+ public void setJpaDiagramEditor(SWTBotGefEditor jpaDiagramEditor) {
+ this.jpaDiagramEditor = jpaDiagramEditor;
}
}
diff --git a/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.swtbot.tests/src/org/eclipse/jpt/jpadiagrameditor/swtbot/tests/ui/editor/ElementDisappears.java b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.swtbot.tests/src/org/eclipse/jpt/jpadiagrameditor/swtbot/tests/ui/editor/ElementDisappears.java
index 2e33cb8..3e2a900 100644
--- a/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.swtbot.tests/src/org/eclipse/jpt/jpadiagrameditor/swtbot/tests/ui/editor/ElementDisappears.java
+++ b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.swtbot.tests/src/org/eclipse/jpt/jpadiagrameditor/swtbot/tests/ui/editor/ElementDisappears.java
@@ -1,25 +1,42 @@
package org.eclipse.jpt.jpadiagrameditor.swtbot.tests.ui.editor;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.swtbot.eclipse.gef.finder.widgets.SWTBotGefEditPart;
import org.eclipse.swtbot.eclipse.gef.finder.widgets.SWTBotGefEditor;
import org.eclipse.swtbot.swt.finder.waits.DefaultCondition;
public class ElementDisappears extends DefaultCondition{
- private String entityName;
+ private String name;
private SWTBotGefEditor gefEditor;
+ private SWTBotGefEditPart entity;
+
+ public ElementDisappears(SWTBotGefEditor gefEditor, String name){
+ this(gefEditor, null, name);
+
+ }
- public ElementDisappears(SWTBotGefEditor gefEditor, String entityName){
+ public ElementDisappears(SWTBotGefEditor gefEditor, SWTBotGefEditPart entity, String name){
super();
this.gefEditor = gefEditor;
- this.entityName = entityName;
+ this.entity = entity;
+ this.name = name;
}
+ @SuppressWarnings("deprecation")
public boolean test() throws Exception {
- return gefEditor.getEditPart(entityName) == null;
+ if(entity != null){
+ List<SWTBotGefEditPart> parts = new ArrayList<SWTBotGefEditPart>();
+ parts.add(entity);
+ return gefEditor.getEditpart(name, parts) == null;
+ }
+ return gefEditor.getEditPart(name) == null;
}
public String getFailureMessage() {
- return "Entity with name ''" + entityName + "'' did not show.";
+ return "Element with name ''" + name + "'' did not disappear.";
}
diff --git a/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.swtbot.tests/src/org/eclipse/jpt/jpadiagrameditor/swtbot/tests/ui/editor/ElementIsShown.java b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.swtbot.tests/src/org/eclipse/jpt/jpadiagrameditor/swtbot/tests/ui/editor/ElementIsShown.java
index 6eb5c5f..fcfbf40 100644
--- a/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.swtbot.tests/src/org/eclipse/jpt/jpadiagrameditor/swtbot/tests/ui/editor/ElementIsShown.java
+++ b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.swtbot.tests/src/org/eclipse/jpt/jpadiagrameditor/swtbot/tests/ui/editor/ElementIsShown.java
@@ -19,7 +19,7 @@ public class ElementIsShown extends DefaultCondition{
}
public String getFailureMessage() {
- return "Entity with name ''" + entityName + "'' did not show.";
+ return "Element with name ''" + entityName + "'' did not show.";
}
}
diff --git a/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.swtbot.tests/src/org/eclipse/jpt/jpadiagrameditor/swtbot/tests/ui/editor/EmbeddableInDiagramSWTBotTest.java b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.swtbot.tests/src/org/eclipse/jpt/jpadiagrameditor/swtbot/tests/ui/editor/EmbeddableInDiagramSWTBotTest.java
new file mode 100644
index 0000000..c0aeadd
--- /dev/null
+++ b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.swtbot.tests/src/org/eclipse/jpt/jpadiagrameditor/swtbot/tests/ui/editor/EmbeddableInDiagramSWTBotTest.java
@@ -0,0 +1,1992 @@
+package org.eclipse.jpt.jpadiagrameditor.swtbot.tests.ui.editor;
+
+import java.util.List;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.graphiti.features.IFeatureProvider;
+import org.eclipse.graphiti.ui.internal.parts.DiagramEditPart;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jpt.jpa.core.JpaProject;
+import org.eclipse.jpt.jpa.core.MappingKeys;
+import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType;
+import org.eclipse.jpt.jpa.core.jpa2.MappingKeys2_0;
+import org.eclipse.jpt.jpa.ui.internal.details.JptUiDetailsMessages;
+import org.eclipse.jpt.jpa.ui.internal.jpa2.details.JptUiDetailsMessages2_0;
+import org.eclipse.jpt.jpadiagrameditor.swtbot.tests.internal.JPACreateFactory;
+import org.eclipse.jpt.jpadiagrameditor.swtbot.tests.internal.Utils;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.i18n.JPAEditorMessages;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.HasReferanceRelation;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.HasReferanceRelation.HasReferenceType;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.IRelation;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JpaArtifactFactory;
+import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot;
+import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotEditor;
+import org.eclipse.swtbot.eclipse.gef.finder.SWTBotGefTestCase;
+import org.eclipse.swtbot.eclipse.gef.finder.SWTGefBot;
+import org.eclipse.swtbot.eclipse.gef.finder.widgets.SWTBotGefConnectionEditPart;
+import org.eclipse.swtbot.eclipse.gef.finder.widgets.SWTBotGefEditPart;
+import org.eclipse.swtbot.eclipse.gef.finder.widgets.SWTBotGefEditor;
+import org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException;
+import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner;
+import org.eclipse.swtbot.swt.finder.utils.SWTBotPreferences;
+import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell;
+import org.eclipse.swtbot.swt.finder.widgets.SWTBotText;
+import org.eclipse.swtbot.swt.finder.widgets.TimeoutException;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+@RunWith(SWTBotJunit4ClassRunner.class)
+@SuppressWarnings("restriction")
+public class EmbeddableInDiagramSWTBotTest extends SWTBotGefTestCase {
+
+ protected static String TEST_PROJECT;
+ protected static JPACreateFactory factory = JPACreateFactory.instance();
+ protected static JpaProject jpaProject;
+
+ // protected static JpaProject jpaProject10;
+
+ protected static SWTGefBot bot = new SWTGefBot();
+ protected static SWTWorkbenchBot workbenchBot = new SWTWorkbenchBot();
+ protected static EditorProxy editorProxy = new EditorProxy(workbenchBot,
+ bot);
+
+ protected static SWTBotGefEditor jpaDiagramEditor;
+
+ @BeforeClass
+ public static void beforeClass() throws Exception {
+
+ SWTBotPreferences.TIMEOUT = 1000;
+ try {
+ bot.viewByTitle("Welcome").close();
+ } catch (Exception e) {
+ // ignore
+ } finally {
+ SWTBotPreferences.TIMEOUT = 5000;
+ }
+ workbenchBot.perspectiveByLabel("JPA").activate();
+ workbenchBot.viewByTitle("JPA Structure").close();
+
+ TEST_PROJECT = "Test_" + System.currentTimeMillis();
+
+ factory = JPACreateFactory.instance();
+ jpaProject = factory.createJPA20Project(TEST_PROJECT);
+ assertNotNull(jpaProject);
+
+ jpaDiagramEditor = editorProxy
+ .openDiagramOnJPAContentNode(TEST_PROJECT, true);
+ editorProxy.setJpaDiagramEditor(jpaDiagramEditor);
+
+ Thread.sleep(2000);
+ }
+
+ /**
+ * Add embeddable to diagram and check that it does not contain a
+ * "Primary Key", "Relation Attributes" and "Other Attributes" sections.
+ */
+ @Test
+ public void testAddEmbeddable() {
+ Utils.sayTestStarted("testAddEmbeddable");
+
+ editorProxy.addEmbeddableToDiagram(50, 50, "Embeddable1");
+ assertTrue("Editor must be dirty", jpaDiagramEditor.isDirty());
+
+ jpaDiagramEditor.save();
+ assertFalse("Editor must not be dirty!", jpaDiagramEditor.isDirty());
+
+ editorProxy.deleteDiagramElements();
+ jpaDiagramEditor.save();
+
+ Utils.sayTestFinished("testAddEmbeddable");
+ }
+
+ /**
+ * Remove an embeddable from the diagram using the embeddable's context
+ * button "Delete"
+ */
+ @Test
+ public void testRemoveEmnbeddableViaButton() {
+ Utils.sayTestStarted("testRemoveEmnbeddableViaButton");
+
+ SWTBotGefEditPart embeddable = editorProxy.addEmbeddableToDiagram(50,
+ 50, "Embeddable1");
+ assertTrue("Editor must be dirty", jpaDiagramEditor.isDirty());
+
+ editorProxy.deleteJPTViaButton(embeddable);
+
+ assertTrue("Editor must be dirty", jpaDiagramEditor.isDirty());
+ jpaDiagramEditor.save();
+
+ Utils.sayTestFinished("testRemoveEmnbeddableViaButton");
+ }
+
+ /**
+ * Remove an embeddable from the diagram using the embeddable's context menu
+ * "Delete"
+ */
+ @Test
+ public void testRemoveEmbeddableViaContextMenu() {
+ Utils.sayTestStarted("testRemoveEmbeddableViaContextMenu");
+
+ SWTBotGefEditPart embeddable = editorProxy.addEmbeddableToDiagram(50,
+ 50, "Embeddable1");
+ assertTrue("Editor must be dirty", jpaDiagramEditor.isDirty());
+
+ editorProxy.deleteJPTViaMenu(embeddable);
+
+ assertTrue("Editor must be dirty", jpaDiagramEditor.isDirty());
+ jpaDiagramEditor.save();
+
+ Utils.sayTestFinished("testRemoveEmbeddableViaContextMenu");
+ }
+
+ /**
+ * Adds a new attribute to the embeddable using the entity's context button
+ * "Create Attribute"
+ */
+ @Test
+ public void testAddAttributeToEmbeddablle() {
+ Utils.sayTestStarted("testAddAttributeToEmbeddablle");
+
+ SWTBotGefEditPart embeddable = editorProxy.addEmbeddableToDiagram(50,
+ 50, "Embeddable1");
+ assertTrue("Editor must be dirty", jpaDiagramEditor.isDirty());
+
+ assertFalse(
+ "\"Other Attributes\" section must not be visible!",
+ editorProxy
+ .isSectionVisible(
+ JPAEditorMessages.AddJPAEntityFeature_basicAttributesShapes,
+ embeddable));
+
+ editorProxy.addAttributeToJPT(embeddable, "attribute1");
+ assertTrue("Editor must be dirty", jpaDiagramEditor.isDirty());
+
+ embeddable.click();
+ editorProxy.deleteDiagramElements();
+ jpaDiagramEditor.save();
+
+ Utils.sayTestFinished("testAddAttributeToEmbeddablle");
+ }
+
+ /**
+ * Removes the attribute using the "Delete Attribute" context button.
+ */
+ @Test
+ public void testRemoveAttributeFromEmbeddableViaContextButton() {
+ Utils.sayTestStarted("testRemoveAttributeFromEmbeddableViaContextButton");
+
+ SWTBotGefEditPart embeddable = editorProxy.addEmbeddableToDiagram(50,
+ 50, "Embeddable1");
+ assertTrue("Editor must be dirty", jpaDiagramEditor.isDirty());
+
+ editorProxy.removeAttributeViaButton(embeddable, "attribute1");
+
+ embeddable.click();
+ editorProxy.deleteDiagramElements();
+ jpaDiagramEditor.save();
+
+ Utils.sayTestFinished("testRemoveAttributeFromEmbeddableViaContextButton");
+ }
+
+ /**
+ * Removes the attribute using the "Delete" context menu.
+ */
+ @Test
+ public void testRemoveAttributeFromEmbeddableViaMenu() {
+ Utils.sayTestStarted("testRemoveAttributeFromEmbeddableViaMenu");
+
+ SWTBotGefEditPart embeddable = editorProxy.addEmbeddableToDiagram(50,
+ 50, "Embeddable1");
+ assertTrue("Editor must be dirty", jpaDiagramEditor.isDirty());
+
+ editorProxy.removeAttributeViaMenu(embeddable, "attribute1");
+
+ embeddable.click();
+ editorProxy.deleteDiagramElements();
+ jpaDiagramEditor.save();
+
+ Utils.sayTestFinished("testRemoveAttributeFromEmbeddableViaMenu");
+ }
+
+ /**
+ * Adds a new attribute and rename it
+ */
+ @Test
+ public void testDirectEditingAttributeInEmbeddable() {
+ Utils.sayTestStarted("testDirectEditingAttributeInEmbeddable");
+
+ SWTBotGefEditPart embeddable = editorProxy.addEmbeddableToDiagram(50,
+ 50, "Embeddable1");
+ assertTrue("Editor must be dirty", jpaDiagramEditor.isDirty());
+
+ editorProxy.directEditAttribute(embeddable, "attribute1");
+
+ assertTrue("Editor must be dirty", jpaDiagramEditor.isDirty());
+
+ editorProxy.deleteDiagramElements();
+ jpaDiagramEditor.save();
+
+ Utils.sayTestFinished("testDirectEditingAttributeInEmbeddable");
+ }
+
+ /**
+ * Adds a new embeddable and rename it
+ */
+ @Ignore
+ @Test
+ public void testDirectEditingEmbeddable() {
+ Utils.sayTestStarted("testDirectEditingEmbeddable");
+
+ SWTBotGefEditPart embeddable = editorProxy.addEmbeddableToDiagram(50,
+ 50, "Embeddable1");
+ assertTrue("Editor must be dirty", jpaDiagramEditor.isDirty());
+
+ editorProxy.moveMouse(100, 70);
+ embeddable.click();
+ embeddable.activateDirectEdit();
+ jpaDiagramEditor.directEditType("NewEntityName");
+ editorProxy.moveMouse(0, 0);
+
+ SWTBotGefEditPart oldEmbeddable = jpaDiagramEditor
+ .getEditPart("Embeddable1");
+ SWTBotGefEditPart newEmbeddable = jpaDiagramEditor
+ .getEditPart("NewEntityName");
+ assertNotNull("The entity must be renamed!", newEmbeddable);
+ assertNull("The attribute must be renamed!", oldEmbeddable);
+
+ assertTrue("Editor must be dirty", jpaDiagramEditor.isDirty());
+
+ editorProxy.deleteDiagramElements();
+ jpaDiagramEditor.save();
+
+ Utils.sayTestFinished("testDirectEditingEmbeddable");
+ }
+
+ /**
+ * Test that the source of the embeddable is opened, when is double clicked
+ * on it
+ */
+ @Ignore
+ @Test
+ public void testDoubleClickOnEmbeddable() {
+ Utils.sayTestStarted("testDoubleClickOnEmbeddable");
+
+ SWTBotGefEditPart embeddable = editorProxy.addEmbeddableToDiagram(50,
+ 50, "Embeddable1");
+ assertTrue("Editor must be dirty", jpaDiagramEditor.isDirty());
+
+ editorProxy.moveMouse(100, 70);
+ jpaDiagramEditor.doubleClick(embeddable);
+ editorProxy.moveMouse(0, 0);
+
+ SWTBotEditor activeEditor = workbenchBot.activeEditor();
+ assertEquals("The Java editor of the enity did not open!",
+ "Embeddable1.java", activeEditor.getTitle());
+ activeEditor.close();
+
+ editorProxy.deleteDiagramElements();
+ jpaDiagramEditor.save();
+
+ Utils.sayTestFinished("testDoubleClickOnEmbeddable");
+ }
+
+ /**
+ * Change the attribute type.
+ */
+ @Test
+ public void testChangeAttributeTypeInEmbeddable() {
+ Utils.sayTestStarted("testChangeAttributeTypeInEmbeddable");
+
+ SWTBotGefEditPart embeddable = editorProxy.addEmbeddableToDiagram(50,
+ 50, "Embeddable1");
+ assertTrue("Editor must be dirty", jpaDiagramEditor.isDirty());
+
+ assertFalse(
+ "\"Other Attributes\" section must not be visible!",
+ editorProxy
+ .isSectionVisible(
+ JPAEditorMessages.AddJPAEntityFeature_basicAttributesShapes,
+ embeddable));
+
+ SWTBotGefEditPart attribute = editorProxy.addAttributeToJPT(embeddable,
+ "attribute1");
+ assertNotNull("The attribute must not be renamed!", attribute);
+
+ final IFeatureProvider fp = ((DiagramEditPart) jpaDiagramEditor
+ .mainEditPart().part()).getFeatureProvider();
+
+ String currentAttributeType = editorProxy.getAttributeType(
+ "attribute1", fp);
+ assertEquals("java.lang.String", currentAttributeType);
+
+ SWTBotShell changeTypeDialog = editorProxy
+ .getSelectNewAttributeTypeDialog(attribute);
+ SWTBotText attributeType = editorProxy
+ .getNewTypeInputField(changeTypeDialog);
+
+ // test invalid attribute type
+ attributeType.setText("");
+ assertFalse(editorProxy.getOkButton(changeTypeDialog).isEnabled());
+ assertTrue(editorProxy.getCancelButton(changeTypeDialog).isEnabled());
+ SWTBotText dialogError = editorProxy
+ .getDialogErroMessage(changeTypeDialog);
+ assertEquals(" The new type name must not be empty",
+ dialogError.getText());
+ // cancel the dialog
+ editorProxy.getCancelButton(changeTypeDialog).click();
+
+ // assert that the attribute type is not changed
+ currentAttributeType = editorProxy.getAttributeType("attribute1", fp);
+ assertEquals("The attribute type must not be changed!",
+ "java.lang.String", currentAttributeType);
+
+ changeTypeDialog = editorProxy
+ .getSelectNewAttributeTypeDialog(attribute);
+ attributeType = editorProxy.getNewTypeInputField(changeTypeDialog);
+
+ // change the attribute type to int
+ attributeType.setText("int");
+ assertTrue(editorProxy.getOkButton(changeTypeDialog).isEnabled());
+ assertTrue(editorProxy.getCancelButton(changeTypeDialog).isEnabled());
+ // confirm the dialog
+ editorProxy.getOkButton(changeTypeDialog).click();
+ editorProxy.waitASecond();
+ // assert that the attribute's type is changed
+ String newAttributeType = editorProxy
+ .getAttributeType("attribute1", fp);
+ assertFalse("The attribute type must be changed!",
+ ("java.lang.String").equals(newAttributeType));
+ assertEquals("The attribute type must be changed!", "int",
+ newAttributeType);
+
+ assertTrue("Editor must be dirty!", jpaDiagramEditor.isDirty());
+ embeddable.click();
+ editorProxy.deleteDiagramElements();
+ jpaDiagramEditor.save();
+
+ Utils.sayTestFinished("testChangeAttributeTypeInEmbeddable");
+ }
+
+ /**
+ * Rename the embeddable using its context menu
+ * "Refactor Entity Class -> Rename..."
+ */
+ @Ignore
+ @Test
+ public void testRenameEmbeddableViaMenu() {
+ Utils.sayTestStarted("testRenameEmbeddableViaMenu");
+
+ SWTBotGefEditPart embeddable = editorProxy.addEmbeddableToDiagram(50,
+ 50, "Embeddable1");
+ assertTrue("Editor must be dirty", jpaDiagramEditor.isDirty());
+
+ embeddable.click();
+ jpaDiagramEditor
+ .clickContextMenu(JPAEditorMessages.JPAEditorToolBehaviorProvider_renameEntityClass);
+
+ SWTBotShell renameEntityDialog = editorProxy.getRenameEntityDialog();
+ SWTBotText embeddableName = renameEntityDialog.bot().textWithLabel(
+ "New name:");
+
+ // test invalid entity name
+ embeddableName.setText("");
+ assertFalse(editorProxy.getFinishButton(renameEntityDialog).isEnabled());
+ assertTrue(editorProxy.getCancelButton(renameEntityDialog).isEnabled());
+
+ embeddableName.setText("NewEntityName");
+ assertTrue(editorProxy.getFinishButton(renameEntityDialog).isEnabled());
+ assertTrue(editorProxy.getCancelButton(renameEntityDialog).isEnabled());
+
+ editorProxy.getFinishButton(renameEntityDialog).click();
+ bot.waitUntil(new ElementIsShown(jpaDiagramEditor, "NewEntityName"),
+ 10000);
+
+ embeddable = jpaDiagramEditor.getEditPart("NewEntityName");
+ assertNotNull("Entity name must be changed!", embeddable);
+ assertNull("Entity naem must be changed!",
+ jpaDiagramEditor.getEditPart("Embeddable1"));
+
+ embeddable.click();
+ editorProxy.deleteDiagramElements();
+ jpaDiagramEditor.save();
+
+ Utils.sayTestFinished("testRenameEmbeddableViaMenu");
+ }
+
+ /**
+ * Move the embeddable class using the embeddable's context menu
+ * "Refactor Entity Class -> Move..."
+ */
+ @Ignore
+ @Test
+ public void testMoveEmbeddableViaMenu() throws JavaModelException {
+ Utils.sayTestStarted("testMoveEmbeddableViaMenu");
+
+ SWTBotGefEditPart embeddable = editorProxy.addEmbeddableToDiagram(50,
+ 50, "Embeddable1");
+ assertTrue("Editor must be dirty", jpaDiagramEditor.isDirty());
+
+ JpaArtifactFactory factory = JpaArtifactFactory.instance();
+
+ String packageName = factory
+ .getMappedSuperclassPackageDeclaration(editorProxy
+ .getJPTObjectForGefElement(embeddable));
+
+ embeddable.click();
+ jpaDiagramEditor
+ .clickContextMenu(JPAEditorMessages.JPAEditorToolBehaviorProvider_moveEntityClass);
+
+ SWTBotShell moveEntityDialog = editorProxy.getMoveEntityDialog();
+ moveEntityDialog.bot().tree().getTreeItem(TEST_PROJECT).select()
+ .expandNode("src").expandNode("org").select().click();
+ assertTrue(editorProxy.getOkButton(moveEntityDialog).isEnabled());
+ editorProxy.getOkButton(moveEntityDialog).click();
+ editorProxy.waitASecond();
+
+ embeddable = jpaDiagramEditor.getEditPart("Embeddable1");
+ String newEntityPackage = factory
+ .getMappedSuperclassPackageDeclaration(editorProxy
+ .getJPTObjectForGefElement(embeddable));
+ assertFalse("Entity must be moved!",
+ packageName.equals(newEntityPackage));
+ assertTrue("Entity must be changed!", newEntityPackage.equals("org"));
+
+ embeddable.click();
+ editorProxy.deleteDiagramElements();
+ jpaDiagramEditor.save();
+
+ Utils.sayTestFinished("testMoveEmbeddableViaMenu");
+ }
+
+ /**
+ * Collapse/expand embeddable using its context buttons
+ */
+ @Test
+ public void testCollapseExapandEmbeddableViaContextButton() {
+ Utils.sayTestStarted("testCollapseExapandEmbeddableViaContextButton");
+
+ SWTBotGefEditPart embeddable = editorProxy.addEmbeddableToDiagram(50,
+ 50, "Embeddable1");
+ assertTrue("Editor must be dirty", jpaDiagramEditor.isDirty());
+
+ editorProxy.addAttributeToJPT(embeddable, "attribute1");
+
+ editorProxy.collapseExpandJPTViaButton(embeddable);
+
+ editorProxy.deleteDiagramElements();
+ jpaDiagramEditor.save();
+
+ Utils.sayTestFinished("testCollapseExapandEmbeddableViaContextButton");
+ }
+
+ /**
+ * Collapse/expand embeddable using its context menus
+ */
+ @Test
+ public void testCollapseExapandEmbeddableViaMenu() {
+ Utils.sayTestStarted("testCollapseExapandEmbeddableViaMenu");
+
+ SWTBotGefEditPart embeddable = editorProxy.addEmbeddableToDiagram(50,
+ 50, "Embeddable1");
+ assertTrue("Editor must be dirty", jpaDiagramEditor.isDirty());
+
+ editorProxy.addAttributeToJPT(embeddable, "attribute1");
+
+ editorProxy.collapseExpandJPTViaMenu(embeddable);
+
+ editorProxy.deleteDiagramElements();
+ jpaDiagramEditor.save();
+
+ Utils.sayTestFinished("testCollapseExapandEmbeddableViaMenu");
+ }
+
+ /**
+ * Collapse/expand all embeddables using the context menus
+ */
+ @Test
+ public void testCollapseExapandAllEmbeddablesViaMenu() {
+ Utils.sayTestStarted("testCollapseExapandAllEmbeddablesViaMenu");
+
+ SWTBotGefEditPart embeddable1 = editorProxy.addEmbeddableToDiagram(50,
+ 50, "Embeddable1");
+ assertTrue("Editor must be dirty", jpaDiagramEditor.isDirty());
+
+ editorProxy.addAttributeToJPT(embeddable1, "attribute1");
+
+ SWTBotGefEditPart embeddable2 = editorProxy.addEmbeddableToDiagram(300,
+ 50, "Embeddable2");
+ assertTrue("Editor must be dirty", jpaDiagramEditor.isDirty());
+
+ editorProxy.addAttributeToJPT(embeddable2, "attribute1");
+
+ editorProxy.collapseExpandAllJPTsViaMenu(embeddable1, embeddable2);
+
+ editorProxy.deleteDiagramElements();
+ jpaDiagramEditor.save();
+
+ Utils.sayTestFinished("testCollapseExapandAllEmbeddablesViaMenu");
+ }
+
+ /**
+ * Add a new attribute without saving the embeddable and call the
+ * "Discard Changes" context menu. Assert that the newly added attribute is
+ * removed and the embeddable does not contain unsaved changes.
+ */
+ @Test
+ public void testDiscardChangesFromEmbeddable() {
+ Utils.sayTestStarted("testDiscardChangesFromEmbeddable");
+
+ SWTBotGefEditPart embeddable = editorProxy.addEmbeddableToDiagram(50,
+ 50, "Embeddable1");
+ assertTrue("Editor must be dirty", jpaDiagramEditor.isDirty());
+
+ editorProxy.discardChanges(embeddable, "attribute1");
+
+ editorProxy.deleteDiagramElements();
+ jpaDiagramEditor.save();
+
+ Utils.sayTestFinished("testDiscardChangesFromEmbeddable");
+ }
+
+ /**
+ * Add a new attribute without saving the embeddable and call the
+ * embeddable's context menu "Remove All Entities from Diagram -> ... and
+ * Discard
+ * Changes" context menu. Assert that the diagram is empty. Call "Show All
+ * Entities" context menu and assert that the newly added attribute is
+ * removed and the embeddable does not contain unsaved changes.
+ */
+ @Test
+ public void testRemoveAndDiscardChangesFromEmbeddableViaMenu() {
+ Utils.sayTestStarted("testRemoveAndDiscardChangesFromEmbeddableViaMenu");
+
+ SWTBotGefEditPart embeddable = editorProxy.addEmbeddableToDiagram(50,
+ 50, "Embeddable1");
+ assertTrue("Editor must be dirty", jpaDiagramEditor.isDirty());
+
+ editorProxy.removeAndDiscardChangesViaMenu(embeddable, "attribute1");
+
+ embeddable.click();
+ editorProxy.deleteDiagramElements();
+ jpaDiagramEditor.save();
+
+ Utils.sayTestFinished("testRemoveAndDiscardChangesFromEmbeddableViaMenu");
+ }
+
+ /**
+ * Add a new attribute without saving the embeddable and call the
+ * embeddable's context menu "Remove All Entities from Diagram -> ... and
+ * Save Changes" context menu. Assert that the diagram is empty. Call "Show
+ * All Entities" context menu and assert that the newly added attribute is
+ * added and the embeddable does not contain unsaved changes.
+ */
+ @Test
+ public void testRemoveAndSaveChangesToEmbeddableViaMenu() {
+ Utils.sayTestStarted("testRemoveAndSaveChangesToEmbeddableViaMenu");
+
+ SWTBotGefEditPart embeddable = editorProxy.addEmbeddableToDiagram(50,
+ 50, "Embeddable1");
+ assertTrue("Editor must be dirty", jpaDiagramEditor.isDirty());
+
+ editorProxy.removeAndSaveChangesViaMenu(embeddable, "attribute1");
+
+ embeddable.click();
+ editorProxy.deleteDiagramElements();
+ jpaDiagramEditor.save();
+
+ Utils.sayTestFinished("testRemoveAndSaveChangesToEmbeddableViaMenu");
+ }
+
+ /**
+ * Add a new attribute to the embeddable. From the embeddable's context menu
+ * select "Save". Assert that the embeddable does not contain any unsaved
+ * changes, but the diagram editor is still dirty.
+ */
+ @Test
+ public void testSaveOnlyEmbeddable() {
+ Utils.sayTestStarted("testSaveOnlyEmbeddable");
+
+ SWTBotGefEditPart embeddable = editorProxy.addEmbeddableToDiagram(50,
+ 50, "Embeddable1");
+ assertTrue("Editor must be dirty", jpaDiagramEditor.isDirty());
+
+ editorProxy.saveOnlyJPT(embeddable, "attribute1");
+
+ editorProxy.deleteDiagramElements();
+ jpaDiagramEditor.save();
+
+ Utils.sayTestFinished("testSaveOnlyEmbeddable");
+ }
+
+ /**
+ * Add one entity and one embeddable in the diagram. Embed a single instance
+ * of the embeddable into the entity and checks that the connection exists
+ * and a new embedded attribute is added to the entity.
+ */
+ @Test
+ public void testEmbedSingleObjectInEntity() {
+ Utils.sayTestStarted("testEmbedSingleObjectInEntity");
+
+ SWTBotGefEditPart entity = editorProxy.addEntityToDiagram(50, 50,
+ "Entity1");
+ SWTBotGefEditPart embeddable = editorProxy.addEmbeddableToDiagram(50,
+ 200, "Embeddable1");
+ assertTrue("Editor must be dirty", jpaDiagramEditor.isDirty());
+
+ _testEmbeddedConnection(JPAEditorMessages.EmbedSingleObjectFeature_EmbeddedFeatureName, entity, embeddable,
+ HasReferenceType.SINGLE,
+ MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY,
+ JptUiDetailsMessages.EmbeddedMappingUiProvider_linkLabel, 2);
+
+ editorProxy.deleteDiagramElements();
+ jpaDiagramEditor.save();
+
+ Utils.sayTestFinished("testEmbedSingleObjectInEntity");
+ }
+
+ /**
+ * Add one entity and one embeddable in the diagram. Embed a collection of
+ * the embeddable into the entity and checks that the connection exists and
+ * a new embedded attribute is added to the entity.
+ */
+ @Test
+ public void testEmbedCollectionOfObjectsInEntity() {
+ Utils.sayTestStarted("testEmbedCollectionOfObjectsInEntity");
+
+ SWTBotGefEditPart entity = editorProxy.addEntityToDiagram(50, 50,
+ "Entity1");
+ SWTBotGefEditPart embeddable = editorProxy.addEmbeddableToDiagram(50,
+ 200, "Embeddable1");
+ assertTrue("Editor must be dirty", jpaDiagramEditor.isDirty());
+
+ _testEmbeddedConnection(JPAEditorMessages.EmbedCollectionOfObjectsFeature_ElementCollectionFeatureName, entity,
+ embeddable, HasReferenceType.COLLECTION,
+ MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY,
+ JptUiDetailsMessages2_0.ElementCollectionMapping2_0_linkLabel,
+ 2);
+
+ editorProxy.deleteDiagramElements();
+ jpaDiagramEditor.save();
+
+ Utils.sayTestFinished("testEmbedCollectionOfObjectsInEntity");
+ }
+
+ /**
+ * Add two embeddables in the diagram. Embed a single instance of the first
+ * embeddable into the second embeddable and checks that the connection
+ * exists and a new embedded attribute is added to the second embeddable.
+ */
+ @Test
+ public void testEmbedSingleObjectInEmbeddable() {
+ Utils.sayTestStarted("testEmbedSingleObjectInEmbeddable");
+
+ SWTBotGefEditPart embeddable1 = editorProxy.addEmbeddableToDiagram(50,
+ 50, "Embeddable1");
+ SWTBotGefEditPart embeddable2 = editorProxy.addEmbeddableToDiagram(50,
+ 200, "Embeddable2");
+ assertTrue("Editor must be dirty", jpaDiagramEditor.isDirty());
+
+ _testEmbeddedConnection(JPAEditorMessages.EmbedSingleObjectFeature_EmbeddedFeatureName, embeddable1,
+ embeddable2, HasReferenceType.SINGLE,
+ MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY,
+ JptUiDetailsMessages.EmbeddedMappingUiProvider_linkLabel, 2);
+
+ editorProxy.deleteDiagramElements();
+ jpaDiagramEditor.save();
+
+ Utils.sayTestFinished("testEmbedSingleObjectInEmbeddable");
+ }
+
+ /**
+ * Add two embeddables in the diagram. Embed a collection of the first
+ * embeddable into the second embeddable and checks that the connection
+ * exists and a new embedded attribute is added to the second embeddable.
+ */
+ @Test
+ public void testEmbedCollectionOfObjectsInEmbeddable() {
+ Utils.sayTestStarted("testEmbedCollectionOfObjectsInEmbeddable");
+
+ SWTBotGefEditPart embeddable1 = editorProxy.addEmbeddableToDiagram(50,
+ 50, "Embeddable1");
+ SWTBotGefEditPart embeddable2 = editorProxy.addEmbeddableToDiagram(50,
+ 200, "Embeddable2");
+ assertTrue("Editor must be dirty", jpaDiagramEditor.isDirty());
+
+ _testEmbeddedConnection(JPAEditorMessages.EmbedCollectionOfObjectsFeature_ElementCollectionFeatureName, embeddable1,
+ embeddable2, HasReferenceType.COLLECTION,
+ MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY,
+ JptUiDetailsMessages2_0.ElementCollectionMapping2_0_linkLabel,
+ 2);
+
+ editorProxy.deleteDiagramElements();
+ jpaDiagramEditor.save();
+
+ Utils.sayTestFinished("testEmbedCollectionOfObjectsInEmbeddable");
+ }
+
+ /**
+ * Add two embeddables and one entity in the diagram. Embed a collection of
+ * the first embeddable to the second one. Check that it is not possible to
+ * embed a collection of the second embeddable into the entity, but it is
+ * possible to embed a collection of the first embeddable to the entity.
+ */
+ @Test
+ public void testEmbedCollectionOfObjectsInEmbeddableAndEntity() {
+ Utils.sayTestStarted("testEmbedCollectionOfObjectsInEmbeddableAndEntity");
+
+ SWTBotGefEditPart embeddable1 = editorProxy.addEmbeddableToDiagram(50,
+ 50, "Embeddable1");
+ SWTBotGefEditPart embeddable2 = editorProxy.addEmbeddableToDiagram(50,
+ 200, "Embeddable2");
+
+ assertTrue("Editor must be dirty", jpaDiagramEditor.isDirty());
+
+ embedConnection(JPAEditorMessages.EmbedCollectionOfObjectsFeature_ElementCollectionFeatureName, embeddable1,
+ embeddable2, HasReferenceType.COLLECTION,
+ MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY,
+ JptUiDetailsMessages2_0.ElementCollectionMapping2_0_linkLabel,
+ 2);
+
+ SWTBotGefEditPart entity = editorProxy.addEntityToDiagram(200, 50,
+ "Entity1");
+
+ editorProxy.testNoEmbeddedConnectionIsCreated(
+ JPAEditorMessages.EmbedCollectionOfObjectsFeature_ElementCollectionFeatureName, 0, entity, embeddable1, true);
+
+ _testEmbeddedConnection(JPAEditorMessages.EmbedCollectionOfObjectsFeature_ElementCollectionFeatureName, entity,
+ embeddable2, HasReferenceType.COLLECTION,
+ MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY,
+ JptUiDetailsMessages2_0.ElementCollectionMapping2_0_linkLabel,
+ 4);
+
+ editorProxy.deleteAttributeInJPT(embeddable1, "embeddable2");
+
+ editorProxy.deleteDiagramElements();
+ jpaDiagramEditor.save();
+
+ Utils.sayTestFinished("testEmbedCollectionOfObjectsInEmbeddableAndEntity");
+ }
+
+ /**
+ * Test no one-to-one unidirectional relationship from entity to embeddable
+ * is created.
+ */
+ @Test
+ public void testOneToOneUniDirRelationFromEntityToEmbeddable() {
+ Utils.sayTestStarted("testOneToOneUniDirRelationFromEntityToEmbeddable");
+
+ SWTBotGefEditPart entity = editorProxy.addEntityToDiagram(50, 200,
+ "Entity1");
+ SWTBotGefEditPart embeddable = editorProxy.addEmbeddableToDiagram(50,
+ 50, "Embeddable1");
+
+ editorProxy
+ .testNoConnectionIsCreated(
+ JPAEditorMessages.CreateOneToOneUniDirRelationFeature_oneToOneUniDirFeatureName,
+ 0, entity, embeddable);
+
+ editorProxy.deleteDiagramElements();
+ jpaDiagramEditor.save();
+
+ Utils.sayTestFinished("testOneToOneUniDirRelationFromEntityToEmbeddable");
+ }
+
+ /**
+ * Test no one-to-one bidirectional relationship from entity to embeddable
+ * is created.
+ */
+ @Test
+ public void testOneToOneBiDirRelationFromEntityToEmbeddable() {
+ Utils.sayTestStarted("testOneToOneBiDirRelationFromEntityToEmbeddable");
+
+ SWTBotGefEditPart entity = editorProxy.addEntityToDiagram(50, 200,
+ "Entity1");
+ SWTBotGefEditPart embeddable = editorProxy.addEmbeddableToDiagram(50,
+ 50, "Embeddable1");
+
+ editorProxy
+ .testNoConnectionIsCreated(
+ JPAEditorMessages.CreateOneToOneBiDirRelationFeature_oneToOneBiDirFeatureName,
+ 1, entity, embeddable);
+
+ editorProxy.deleteDiagramElements();
+ jpaDiagramEditor.save();
+
+ Utils.sayTestFinished("testOneToOneBiDirRelationFromEntityToEmbeddable");
+ }
+
+ /**
+ * Test no one-to-many unidirectional relationship from entity to embeddable
+ * is created.
+ */
+ @Test
+ public void testOneToManyUniDirRelationFromEntityToEmbeddable() {
+ Utils.sayTestStarted("testOneToManyUniDirRelationFromEntityToEmbeddable");
+
+ SWTBotGefEditPart entity = editorProxy.addEntityToDiagram(50, 200,
+ "Entity1");
+ SWTBotGefEditPart embeddable = editorProxy.addEmbeddableToDiagram(50,
+ 50, "Embeddable1");
+
+ editorProxy
+ .testNoConnectionIsCreated(
+ JPAEditorMessages.CreateOneToManyUniDirRelationFeature_oneToManyUniDirFeatureName,
+ 0, entity, embeddable);
+
+ editorProxy.deleteDiagramElements();
+ jpaDiagramEditor.save();
+
+ Utils.sayTestFinished("testOneToManyUniDirRelationFromEntityToEmbeddable");
+ }
+
+ /**
+ * Test no many-to-one unidirectional relationship from entity to embeddable
+ * is created.
+ */
+ @Test
+ public void testManyToOneUniDirRelationFromEntityToEmbeddable() {
+ Utils.sayTestStarted("testManyToOneUniDirRelationFromEntityToEmbeddable");
+
+ SWTBotGefEditPart entity = editorProxy.addEntityToDiagram(50, 200,
+ "Entity1");
+ SWTBotGefEditPart embeddable = editorProxy.addEmbeddableToDiagram(50,
+ 50, "Embeddable1");
+
+ editorProxy
+ .testNoConnectionIsCreated(
+ JPAEditorMessages.CreateManyToOneUniDirRelationFeature_manyToOneUniDirFeatureName,
+ 0, entity, embeddable);
+
+ editorProxy.deleteDiagramElements();
+ jpaDiagramEditor.save();
+
+ Utils.sayTestFinished("testManyToOneUniDirRelationFromEntityToEmbeddable");
+ }
+
+ /**
+ * Test no many-to-one bidirectional relationship from entity to embeddable
+ * is created.
+ */
+ @Test
+ public void testManyToOneBiDirRelationFromEntityToEmbeddable() {
+ Utils.sayTestStarted("testManyToOneBiDirRelationFromEntityToEmbeddable");
+
+ SWTBotGefEditPart entity = editorProxy.addEntityToDiagram(50, 200,
+ "Entity1");
+ SWTBotGefEditPart embeddable = editorProxy.addEmbeddableToDiagram(50,
+ 50, "Embeddable1");
+
+ editorProxy
+ .testNoConnectionIsCreated(
+ JPAEditorMessages.CreateManyToOneBiDirRelationFeature_manyToOneBiDirFeatureName,
+ 1, entity, embeddable);
+
+ editorProxy.deleteDiagramElements();
+ jpaDiagramEditor.save();
+
+ Utils.sayTestFinished("testManyToOneBiDirRelationFromEntityToEmbeddable");
+ }
+
+ /**
+ * Test no many-to-many unidirectional relationship from entity to
+ * embeddable is created.
+ */
+ @Test
+ public void testManyToManyUniDirRelationFromEntityToEmbeddable() {
+ Utils.sayTestStarted("testManyToManyUniDirRelationFromEntityToEmbeddable");
+
+ SWTBotGefEditPart entity = editorProxy.addEntityToDiagram(50, 200,
+ "Entity1");
+ SWTBotGefEditPart embeddable = editorProxy.addEmbeddableToDiagram(50,
+ 50, "Embeddable1");
+
+ editorProxy
+ .testNoConnectionIsCreated(
+ JPAEditorMessages.CreateManyToManyUniDirRelationFeature_manyToManyUniDirFeatureName,
+ 0, entity, embeddable);
+
+ editorProxy.deleteDiagramElements();
+ jpaDiagramEditor.save();
+
+ Utils.sayTestFinished("testManyToManyUniDirRelationFromEntityToEmbeddable");
+ }
+
+ /**
+ * Test no many-to-many bidirectional relationship from entity to embeddable
+ * is created.
+ */
+ @Test
+ public void testManyToManyBiDirRelationFromEntityToEmbeddable() {
+ Utils.sayTestStarted("testManyToManyBiDirRelationFromEntityToEmbeddable");
+
+ SWTBotGefEditPart entity = editorProxy.addEntityToDiagram(50, 200,
+ "Entity1");
+ SWTBotGefEditPart embeddable = editorProxy.addEmbeddableToDiagram(50,
+ 50, "Embeddable1");
+
+ editorProxy
+ .testNoConnectionIsCreated(
+ JPAEditorMessages.CreateManyToManyBiDirRelationFeature_manyToManyBiDirFeatureName,
+ 1, entity, embeddable);
+
+ editorProxy.deleteDiagramElements();
+ jpaDiagramEditor.save();
+
+ Utils.sayTestFinished("testManyToManyBiDirRelationFromEntityToEmbeddable");
+ }
+
+ /**
+ * Test that if the embeddable is not embedded, no one-to-one bidirectional
+ * relationship will be created from the embeddable to the entity. Add
+ * second entity and embed a single value of the embeddable. Check that a
+ * one-to-one relationship will be created from embeddable to the entity.
+ * Check that if the inverse attribute will be deleted the connection will
+ * be transformed into one-to-one unidirectional relationship. Test that if
+ * the owner attribute will be deleted, the relationship will disappear.
+ */
+ @Test
+ public void testOneToOneBiDirRelationFromEmbeddableToEntity() {
+ Utils.sayTestStarted("testOneToOneBiDirRelationFromEmbeddableToEntity");
+
+ SWTBotGefEditPart entity = editorProxy.addEntityToDiagram(50, 200,
+ "Entity1");
+ SWTBotGefEditPart embeddable = editorProxy.addEmbeddableToDiagram(50,
+ 50, "Embeddable1");
+
+ editorProxy
+ .testNoConnectionIsCreated(
+ JPAEditorMessages.CreateOneToOneBiDirRelationFeature_oneToOneBiDirFeatureName,
+ 1, embeddable, entity);
+
+ SWTBotGefEditPart embeddingEntity = editorProxy.addEntityToDiagram(200,
+ 50, "Entity2");
+
+ embedConnection(JPAEditorMessages.EmbedSingleObjectFeature_EmbeddedFeatureName, embeddingEntity, embeddable,
+ HasReferenceType.SINGLE,
+ MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY,
+ JptUiDetailsMessages.EmbeddedMappingUiProvider_linkLabel, 3);
+
+ editorProxy
+ .testBiDirRel(
+ JPAEditorMessages.CreateOneToOneBiDirRelationFeature_oneToOneBiDirFeatureName,
+ embeddable,
+ entity,
+ IRelation.RelType.ONE_TO_ONE,
+ JptUiDetailsMessages.OneToOneMappingUiProvider_linkLabel);
+
+ editorProxy
+ .testBiDirRelRemoveInverseAttribute(
+ JPAEditorMessages.CreateOneToOneBiDirRelationFeature_oneToOneBiDirFeatureName,
+ embeddable,
+ entity,
+ IRelation.RelType.ONE_TO_ONE,
+ JptUiDetailsMessages.OneToOneMappingUiProvider_linkLabel);
+
+ editorProxy
+ .testBiDirRelRemoveOwnerAttr(
+ JPAEditorMessages.CreateOneToOneBiDirRelationFeature_oneToOneBiDirFeatureName,
+ embeddable,
+ entity,
+ IRelation.RelType.ONE_TO_ONE,
+ JptUiDetailsMessages.OneToOneMappingUiProvider_linkLabel);
+
+ editorProxy.deleteDiagramElements();
+ jpaDiagramEditor.save();
+
+ Utils.sayTestFinished("testOneToOneBiDirRelationFromEmbeddableToEntity");
+ }
+
+ /**
+ * Test that if the embeddable is not embedded, no many-to-one bidirectional
+ * relationship will be created from the embeddable to the entity. Add
+ * second entity and embed a single value of the embeddable. Check that a
+ * many-to-one relationship will be created from embeddable to the entity.
+ * Check that if the inverse attribute will be deleted the connection will
+ * be transformed into one-to-one unidirectional relationship. Test that if
+ * the owner attribute will be deleted, the relationship will disappear.
+ */
+ @Test
+ public void testManyToOneBiDirRelationFromEmbeddableToEntity() {
+ Utils.sayTestStarted("testManyToOneBiDirRelationFromEmbeddableToEntity");
+
+ SWTBotGefEditPart entity = editorProxy.addEntityToDiagram(50, 200,
+ "Entity1");
+ SWTBotGefEditPart embeddable = editorProxy.addEmbeddableToDiagram(50,
+ 50, "Embeddable1");
+
+ editorProxy
+ .testNoConnectionIsCreated(
+ JPAEditorMessages.CreateManyToOneBiDirRelationFeature_manyToOneBiDirFeatureName,
+ 1, embeddable, entity);
+
+ SWTBotGefEditPart embeddingEntity = editorProxy.addEntityToDiagram(200,
+ 50, "Entity2");
+
+ embedConnection(JPAEditorMessages.EmbedSingleObjectFeature_EmbeddedFeatureName, embeddingEntity, embeddable,
+ HasReferenceType.SINGLE,
+ MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY,
+ JptUiDetailsMessages.EmbeddedMappingUiProvider_linkLabel, 3);
+
+ editorProxy
+ .testBiDirRelWithTwoMappingTypes(
+ JPAEditorMessages.CreateManyToOneBiDirRelationFeature_manyToOneBiDirFeatureName,
+ embeddable,
+ entity,
+ IRelation.RelType.MANY_TO_ONE,
+ JptUiDetailsMessages.ManyToOneMappingUiProvider_linkLabel,
+ JptUiDetailsMessages.OneToManyMappingUiProvider_linkLabel);
+
+ editorProxy
+ .testBiDirRelWithTwoMappingsWithoutInverseAttr(
+ JPAEditorMessages.CreateManyToOneBiDirRelationFeature_manyToOneBiDirFeatureName,
+ embeddable,
+ entity,
+ IRelation.RelType.MANY_TO_ONE,
+ JptUiDetailsMessages.ManyToOneMappingUiProvider_linkLabel,
+ JptUiDetailsMessages.OneToManyMappingUiProvider_linkLabel);
+
+ editorProxy
+ .testBiDirRelWithTwoMappingsWithoutOwnerAttr(
+ JPAEditorMessages.CreateManyToOneBiDirRelationFeature_manyToOneBiDirFeatureName,
+ embeddable,
+ entity,
+ IRelation.RelType.MANY_TO_ONE,
+ JptUiDetailsMessages.ManyToOneMappingUiProvider_linkLabel,
+ JptUiDetailsMessages.OneToManyMappingUiProvider_linkLabel);
+
+ editorProxy.deleteDiagramElements();
+ jpaDiagramEditor.save();
+
+ Utils.sayTestFinished("testManyToOneBiDirRelationFromEmbeddableToEntity");
+ }
+
+ /**
+ * Test that if the embeddable is not embedded, no many-to-many
+ * bidirectional relationship will be created from the embeddable to the
+ * entity. Add second entity and embed a single value of the embeddable.
+ * Check that a many-to-many relationship will be created from embeddable to
+ * the entity. Check that if the inverse attribute will be deleted the
+ * connection will be transformed into one-to-one unidirectional
+ * relationship. Test that if the owner attribute will be deleted, the
+ * relationship will disappear.
+ */
+ @Test
+ public void testManyToManyBiDirRelationFromEmbeddableToEntity() {
+ Utils.sayTestStarted("testManyToManyBiDirRelationFromEmbeddableToEntity");
+
+ SWTBotGefEditPart entity = editorProxy.addEntityToDiagram(50, 200,
+ "Entity1");
+ SWTBotGefEditPart embeddable = editorProxy.addEmbeddableToDiagram(50,
+ 50, "Embeddable1");
+
+ editorProxy
+ .testNoConnectionIsCreated(
+ JPAEditorMessages.CreateManyToManyBiDirRelationFeature_manyToManyBiDirFeatureName,
+ 1, embeddable, entity);
+
+ SWTBotGefEditPart embeddingEntity = editorProxy.addEntityToDiagram(200,
+ 50, "Entity2");
+
+ embedConnection(JPAEditorMessages.EmbedSingleObjectFeature_EmbeddedFeatureName, embeddingEntity, embeddable,
+ HasReferenceType.SINGLE,
+ MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY,
+ JptUiDetailsMessages.EmbeddedMappingUiProvider_linkLabel, 3);
+
+ editorProxy
+ .testBiDirRel(
+ JPAEditorMessages.CreateManyToManyBiDirRelationFeature_manyToManyBiDirFeatureName,
+ embeddable,
+ entity,
+ IRelation.RelType.MANY_TO_MANY,
+ JptUiDetailsMessages.ManyToManyMappingUiProvider_linkLabel);
+
+ editorProxy
+ .testBiDirRelRemoveInverseAttribute(
+ JPAEditorMessages.CreateManyToManyBiDirRelationFeature_manyToManyBiDirFeatureName,
+ embeddable,
+ entity,
+ IRelation.RelType.MANY_TO_MANY,
+ JptUiDetailsMessages.ManyToManyMappingUiProvider_linkLabel);
+
+ editorProxy
+ .testBiDirRelRemoveOwnerAttr(
+ JPAEditorMessages.CreateManyToManyBiDirRelationFeature_manyToManyBiDirFeatureName,
+ embeddable,
+ entity,
+ IRelation.RelType.MANY_TO_MANY,
+ JptUiDetailsMessages.ManyToManyMappingUiProvider_linkLabel);
+
+ editorProxy.deleteDiagramElements();
+ jpaDiagramEditor.save();
+
+ Utils.sayTestFinished("testManyToManyBiDirRelationFromEmbeddableToEntity");
+ }
+
+ /**
+ * Test that if the embeddable is not embedded, no one-to-one unidirectional
+ * relationship will be created from the embeddable to the entity. Add
+ * second entity and embed a single value of the embeddable. Check that a
+ * one-to-one relationship will be created from embeddable to the entity.
+ * Check that if the owner attribute will be deleted, the relationship will
+ * disappear.
+ */
+ @Test
+ public void testOneToOneUniDirRelationFromEmbeddableToEntity() {
+ Utils.sayTestStarted("testOneToOneUniDirRelationFromEmbeddableToEntity");
+
+ SWTBotGefEditPart entity = editorProxy.addEntityToDiagram(50, 200,
+ "Entity1");
+ SWTBotGefEditPart embeddable = editorProxy.addEmbeddableToDiagram(50,
+ 50, "Embeddable1");
+
+ editorProxy
+ .testNoConnectionIsCreated(
+ JPAEditorMessages.CreateOneToOneUniDirRelationFeature_oneToOneUniDirFeatureName,
+ 0, embeddable, entity);
+
+ SWTBotGefEditPart embeddingEntity = editorProxy.addEntityToDiagram(200,
+ 50, "Entity2");
+
+ embedConnection(JPAEditorMessages.EmbedSingleObjectFeature_EmbeddedFeatureName, embeddingEntity, embeddable,
+ HasReferenceType.SINGLE,
+ MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY,
+ JptUiDetailsMessages.EmbeddedMappingUiProvider_linkLabel, 3);
+
+ editorProxy
+ .testUniDirRelation(
+ JPAEditorMessages.CreateOneToOneUniDirRelationFeature_oneToOneUniDirFeatureName,
+ embeddable,
+ entity,
+ IRelation.RelType.ONE_TO_ONE,
+ JptUiDetailsMessages.OneToOneMappingUiProvider_linkLabel);
+
+ editorProxy
+ .testUniDirRelRemoveOwnerAttribute(
+ JPAEditorMessages.CreateOneToOneUniDirRelationFeature_oneToOneUniDirFeatureName,
+ embeddable,
+ entity,
+ IRelation.RelType.ONE_TO_ONE,
+ JptUiDetailsMessages.OneToOneMappingUiProvider_linkLabel);
+
+ editorProxy.deleteDiagramElements();
+ jpaDiagramEditor.save();
+
+ Utils.sayTestFinished("testOneToOneUniDirRelationFromEmbeddableToEntity");
+ }
+
+ /**
+ * Test that if the embeddable is not embedded, no many-to-one
+ * unidirectional relationship will be created from the embeddable to the
+ * entity. Add second entity and embed a single value of the embeddable.
+ * Check that a many-to-one relationship will be created from embeddable to
+ * the entity. Check that if the owner attribute will be deleted, the
+ * relationship will disappear.
+ */
+ @Test
+ public void testManyToOneUniDirRelationFromEmbeddableToEntity() {
+ Utils.sayTestStarted("testManyToOneUniDirRelationFromEmbeddableToEntity");
+
+ SWTBotGefEditPart entity = editorProxy.addEntityToDiagram(50, 200,
+ "Entity1");
+ SWTBotGefEditPart embeddable = editorProxy.addEmbeddableToDiagram(50,
+ 50, "Embeddable1");
+
+ editorProxy
+ .testNoConnectionIsCreated(
+ JPAEditorMessages.CreateManyToOneUniDirRelationFeature_manyToOneUniDirFeatureName,
+ 0, embeddable, entity);
+
+ SWTBotGefEditPart embeddingEntity = editorProxy.addEntityToDiagram(200,
+ 50, "Entity2");
+
+ embedConnection(JPAEditorMessages.EmbedSingleObjectFeature_EmbeddedFeatureName, embeddingEntity, embeddable,
+ HasReferenceType.SINGLE,
+ MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY,
+ JptUiDetailsMessages.EmbeddedMappingUiProvider_linkLabel, 3);
+
+ editorProxy
+ .testUniDirRelation(
+ JPAEditorMessages.CreateManyToOneUniDirRelationFeature_manyToOneUniDirFeatureName,
+ embeddable,
+ entity,
+ IRelation.RelType.MANY_TO_ONE,
+ JptUiDetailsMessages.ManyToOneMappingUiProvider_linkLabel);
+
+ editorProxy
+ .testUniDirRelRemoveOwnerAttribute(
+ JPAEditorMessages.CreateManyToOneBiDirRelationFeature_manyToOneBiDirFeatureName,
+ embeddable,
+ entity,
+ IRelation.RelType.MANY_TO_ONE,
+ JptUiDetailsMessages.ManyToOneMappingUiProvider_linkLabel);
+
+ editorProxy.deleteDiagramElements();
+ jpaDiagramEditor.save();
+
+ Utils.sayTestFinished("testManyToOneUniDirRelationFromEmbeddableToEntity");
+ }
+
+ /**
+ * Test that if the embeddable is not embedded, no many-to-many
+ * unidirectional relationship will be created from the embeddable to the
+ * entity. Add second entity and embed a single value of the embeddable.
+ * Check that a many-to-many relationship will be created from embeddable to
+ * the entity. Check that if the owner attribute will be deleted, the
+ * relationship will disappear.
+ */
+ @Test
+ public void testManyToManyUniDirRelationFromEmbeddableToEntity() {
+ Utils.sayTestStarted("testManyToManyUniDirRelationFromEmbeddableToEntity");
+
+ SWTBotGefEditPart entity = editorProxy.addEntityToDiagram(50, 200,
+ "Entity1");
+ SWTBotGefEditPart embeddable = editorProxy.addEmbeddableToDiagram(50,
+ 50, "Embeddable1");
+
+ editorProxy
+ .testNoConnectionIsCreated(
+ JPAEditorMessages.CreateManyToManyUniDirRelationFeature_manyToManyUniDirFeatureName,
+ 0, embeddable, entity);
+
+ SWTBotGefEditPart embeddingEntity = editorProxy.addEntityToDiagram(200,
+ 50, "Entity2");
+
+ embedConnection(JPAEditorMessages.EmbedSingleObjectFeature_EmbeddedFeatureName, embeddingEntity, embeddable,
+ HasReferenceType.SINGLE,
+ MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY,
+ JptUiDetailsMessages.EmbeddedMappingUiProvider_linkLabel, 3);
+
+ editorProxy
+ .testUniDirRelation(
+ JPAEditorMessages.CreateManyToManyUniDirRelationFeature_manyToManyUniDirFeatureName,
+ embeddable,
+ entity,
+ IRelation.RelType.MANY_TO_MANY,
+ JptUiDetailsMessages.ManyToManyMappingUiProvider_linkLabel);
+
+ editorProxy
+ .testUniDirRelRemoveOwnerAttribute(
+ JPAEditorMessages.CreateManyToManyUniDirRelationFeature_manyToManyUniDirFeatureName,
+ embeddable,
+ entity,
+ IRelation.RelType.MANY_TO_MANY,
+ JptUiDetailsMessages.ManyToManyMappingUiProvider_linkLabel);
+
+ editorProxy.deleteDiagramElements();
+ jpaDiagramEditor.save();
+
+ Utils.sayTestFinished("testManyToManyUniDirRelationFromEmbeddableToEntity");
+ }
+
+ /**
+ * Test that if the embeddable is not embedded, no one-to-one bidirectional
+ * relationship will be created from the embeddable to the entity. Add
+ * second entity and embed a collection of the embeddable. Check that a
+ * one-to-one relationship will be created from embeddable to the entity.
+ * Check that if the owner attribute will be deleted, the relationship will
+ * disappear.
+ */
+ @Test
+ public void testOneToOneBiDirRelationFromEmbeddedCollectionToEntity() {
+ Utils.sayTestStarted("testOneToOneBiDirRelationFromEmbeddableToEntity");
+
+ SWTBotGefEditPart entity = editorProxy.addEntityToDiagram(50, 200,
+ "Entity1");
+ SWTBotGefEditPart embeddable = editorProxy.addEmbeddableToDiagram(50,
+ 50, "Embeddable1");
+
+ editorProxy
+ .testNoConnectionIsCreated(
+ JPAEditorMessages.CreateOneToOneBiDirRelationFeature_oneToOneBiDirFeatureName,
+ 1, embeddable, entity);
+
+ SWTBotGefEditPart embeddingEntity = editorProxy.addEntityToDiagram(200,
+ 50, "Entity2");
+
+ embedConnection(JPAEditorMessages.EmbedCollectionOfObjectsFeature_ElementCollectionFeatureName, embeddingEntity,
+ embeddable, HasReferenceType.COLLECTION,
+ MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY,
+ JptUiDetailsMessages2_0.ElementCollectionMapping2_0_linkLabel,
+ 3);
+
+ editorProxy
+ .testBiDirRel(
+ JPAEditorMessages.CreateOneToOneBiDirRelationFeature_oneToOneBiDirFeatureName,
+ embeddable,
+ entity,
+ IRelation.RelType.ONE_TO_ONE,
+ JptUiDetailsMessages.OneToOneMappingUiProvider_linkLabel);
+
+ editorProxy
+ .testBiDirRelRemoveInverseAttribute(
+ JPAEditorMessages.CreateOneToOneBiDirRelationFeature_oneToOneBiDirFeatureName,
+ embeddable,
+ entity,
+ IRelation.RelType.ONE_TO_ONE,
+ JptUiDetailsMessages.OneToOneMappingUiProvider_linkLabel);
+
+ editorProxy
+ .testBiDirRelRemoveOwnerAttr(
+ JPAEditorMessages.CreateOneToOneBiDirRelationFeature_oneToOneBiDirFeatureName,
+ embeddable,
+ entity,
+ IRelation.RelType.ONE_TO_ONE,
+ JptUiDetailsMessages.OneToOneMappingUiProvider_linkLabel);
+
+ editorProxy.deleteDiagramElements();
+ jpaDiagramEditor.save();
+
+ Utils.sayTestFinished("testOneToOneBiDirRelationFromEmbeddableToEntity");
+ }
+
+ /**
+ * Test that if the embeddable is not embedded, no many-to-one bidirectional
+ * relationship will be created from the embeddable to the entity. Add
+ * second entity and embed a collection of the embeddable. Check that a
+ * many-to-one relationship will be created from embeddable to the entity.
+ * Check that if the owner attribute will be deleted, the relationship will
+ * disappear.
+ */
+ @Test
+ public void testManyToOneBiDirRelationFromEmbeddedCollectionToEntity() {
+ Utils.sayTestStarted("testManyToOneBiDirRelationFromEmbeddableToEntity");
+
+ SWTBotGefEditPart entity = editorProxy.addEntityToDiagram(50, 200,
+ "Entity1");
+ SWTBotGefEditPart embeddable = editorProxy.addEmbeddableToDiagram(50,
+ 50, "Embeddable1");
+
+ editorProxy
+ .testNoConnectionIsCreated(
+ JPAEditorMessages.CreateManyToOneBiDirRelationFeature_manyToOneBiDirFeatureName,
+ 1, embeddable, entity);
+
+ SWTBotGefEditPart embeddingEntity = editorProxy.addEntityToDiagram(200,
+ 50, "Entity2");
+
+ embedConnection(JPAEditorMessages.EmbedCollectionOfObjectsFeature_ElementCollectionFeatureName, embeddingEntity,
+ embeddable, HasReferenceType.COLLECTION,
+ MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY,
+ JptUiDetailsMessages2_0.ElementCollectionMapping2_0_linkLabel,
+ 3);
+
+ editorProxy
+ .testBiDirRelWithTwoMappingTypes(
+ JPAEditorMessages.CreateManyToOneBiDirRelationFeature_manyToOneBiDirFeatureName,
+ embeddable,
+ entity,
+ IRelation.RelType.MANY_TO_ONE,
+ JptUiDetailsMessages.ManyToOneMappingUiProvider_linkLabel,
+ JptUiDetailsMessages.OneToManyMappingUiProvider_linkLabel);
+
+ editorProxy
+ .testBiDirRelWithTwoMappingsWithoutInverseAttr(
+ JPAEditorMessages.CreateManyToOneBiDirRelationFeature_manyToOneBiDirFeatureName,
+ embeddable,
+ entity,
+ IRelation.RelType.MANY_TO_ONE,
+ JptUiDetailsMessages.ManyToOneMappingUiProvider_linkLabel,
+ JptUiDetailsMessages.OneToManyMappingUiProvider_linkLabel);
+
+ editorProxy
+ .testBiDirRelWithTwoMappingsWithoutOwnerAttr(
+ JPAEditorMessages.CreateManyToOneBiDirRelationFeature_manyToOneBiDirFeatureName,
+ embeddable,
+ entity,
+ IRelation.RelType.MANY_TO_ONE,
+ JptUiDetailsMessages.ManyToOneMappingUiProvider_linkLabel,
+ JptUiDetailsMessages.OneToManyMappingUiProvider_linkLabel);
+
+ editorProxy.deleteDiagramElements();
+ jpaDiagramEditor.save();
+
+ Utils.sayTestFinished("testManyToOneBiDirRelationFromEmbeddableToEntity");
+ }
+
+ /**
+ * Test that no one-to-one bidirectional relationship will be created, if
+ * the embeddable is embedded in two entities.
+ */
+ @Test
+ public void testNoOneToOneBiDirConnectionIsCreatedInEmbeddableInTwoEntities() {
+ Utils.sayTestStarted("testNoOneToOneBiDirConnectionIsCreatedInEmbeddableInTwoEntities");
+
+ SWTBotGefEditPart entity = editorProxy.addEntityToDiagram(50, 200,
+ "Entity1");
+ SWTBotGefEditPart embeddable = editorProxy.addEmbeddableToDiagram(50,
+ 50, "Embeddable1");
+
+ SWTBotGefEditPart embeddingEntity1 = editorProxy.addEntityToDiagram(
+ 200, 50, "Entity2");
+
+ SWTBotGefEditPart embeddingEntity2 = editorProxy.addEntityToDiagram(
+ 200, 200, "Entity3");
+
+ embedConnection(JPAEditorMessages.EmbedSingleObjectFeature_EmbeddedFeatureName, embeddingEntity1, embeddable,
+ HasReferenceType.SINGLE,
+ MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY,
+ JptUiDetailsMessages.EmbeddedMappingUiProvider_linkLabel, 3);
+
+ embedConnection(JPAEditorMessages.EmbedSingleObjectFeature_EmbeddedFeatureName, embeddingEntity2, embeddable,
+ HasReferenceType.SINGLE,
+ MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY,
+ JptUiDetailsMessages.EmbeddedMappingUiProvider_linkLabel, 3);
+
+ editorProxy
+ .testNoConnectionIsCreatedWithEmbeddable(
+ JPAEditorMessages.CreateOneToOneBiDirRelationFeature_oneToOneBiDirFeatureName,
+ 1, entity, embeddable);
+
+ editorProxy
+ .testUniDirRelation(
+ JPAEditorMessages.CreateOneToOneUniDirRelationFeature_oneToOneUniDirFeatureName,
+ embeddable,
+ entity,
+ IRelation.RelType.ONE_TO_ONE,
+ JptUiDetailsMessages.OneToOneMappingUiProvider_linkLabel);
+
+ editorProxy
+ .testUniDirRelRemoveOwnerAttribute(
+ JPAEditorMessages.CreateOneToOneUniDirRelationFeature_oneToOneUniDirFeatureName,
+ embeddable,
+ entity,
+ IRelation.RelType.ONE_TO_ONE,
+ JptUiDetailsMessages.OneToOneMappingUiProvider_linkLabel);
+
+ editorProxy.deleteDiagramElements();
+ jpaDiagramEditor.save();
+
+ Utils.sayTestFinished("testNoOneToOneBiDirConnectionIsCreatedInEmbeddableInTwoEntities");
+ }
+
+ /**
+ * Test that no many-to-one bidirectional relationship will be created, if
+ * the embeddable is embedded in two entities.
+ */
+ @Test
+ public void testNoManyToOneBiDirConnectionIsCreatedInEmbeddableInTwoEntities() {
+ Utils.sayTestStarted("testNoBiDirConnectionIsCreatedInEmbeddableInTwoEntities");
+
+ SWTBotGefEditPart entity = editorProxy.addEntityToDiagram(50, 200,
+ "Entity1");
+ SWTBotGefEditPart embeddable = editorProxy.addEmbeddableToDiagram(50,
+ 50, "Embeddable1");
+
+ SWTBotGefEditPart embeddingEntity1 = editorProxy.addEntityToDiagram(
+ 200, 50, "Entity2");
+
+ SWTBotGefEditPart embeddingEntity2 = editorProxy.addEntityToDiagram(
+ 200, 200, "Entity3");
+
+ embedConnection(JPAEditorMessages.EmbedSingleObjectFeature_EmbeddedFeatureName, embeddingEntity1, embeddable,
+ HasReferenceType.SINGLE,
+ MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY,
+ JptUiDetailsMessages.EmbeddedMappingUiProvider_linkLabel, 3);
+
+ embedConnection(JPAEditorMessages.EmbedSingleObjectFeature_EmbeddedFeatureName, embeddingEntity2, embeddable,
+ HasReferenceType.SINGLE,
+ MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY,
+ JptUiDetailsMessages.EmbeddedMappingUiProvider_linkLabel, 3);
+
+ editorProxy
+ .testNoConnectionIsCreatedWithEmbeddable(
+ JPAEditorMessages.CreateManyToOneBiDirRelationFeature_manyToOneBiDirFeatureName,
+ 1, entity, embeddable);
+
+ editorProxy
+ .testUniDirRelation(
+ JPAEditorMessages.CreateManyToOneUniDirRelationFeature_manyToOneUniDirFeatureName,
+ embeddable,
+ entity,
+ IRelation.RelType.MANY_TO_ONE,
+ JptUiDetailsMessages.ManyToOneMappingUiProvider_linkLabel);
+
+ editorProxy
+ .testUniDirRelRemoveOwnerAttribute(
+ JPAEditorMessages.CreateManyToOneBiDirRelationFeature_manyToOneBiDirFeatureName,
+ embeddable,
+ entity,
+ IRelation.RelType.MANY_TO_ONE,
+ JptUiDetailsMessages.ManyToOneMappingUiProvider_linkLabel);
+
+ editorProxy.deleteDiagramElements();
+ jpaDiagramEditor.save();
+
+ Utils.sayTestFinished("testNoBiDirConnectionIsCreatedInEmbeddableInTwoEntities");
+ }
+
+ /**
+ * Test that no many-to-many bidirectional relationship will be created, if
+ * the embeddable is embedded in two entities.
+ */
+ @Test
+ public void testNoManyToManyBiDirConnectionIsCreatedInEmbeddableInTwoEntities() {
+ Utils.sayTestStarted("testNoManyToManyBiDirConnectionIsCreatedInEmbeddableInTwoEntities");
+
+ SWTBotGefEditPart entity = editorProxy.addEntityToDiagram(50, 200,
+ "Entity1");
+ SWTBotGefEditPart embeddable = editorProxy.addEmbeddableToDiagram(50,
+ 50, "Embeddable1");
+
+ SWTBotGefEditPart embeddingEntity1 = editorProxy.addEntityToDiagram(
+ 200, 50, "Entity2");
+
+ SWTBotGefEditPart embeddingEntity2 = editorProxy.addEntityToDiagram(
+ 200, 200, "Entity3");
+
+ embedConnection(JPAEditorMessages.EmbedSingleObjectFeature_EmbeddedFeatureName, embeddingEntity1, embeddable,
+ HasReferenceType.SINGLE,
+ MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY,
+ JptUiDetailsMessages.EmbeddedMappingUiProvider_linkLabel, 3);
+
+ embedConnection(JPAEditorMessages.EmbedSingleObjectFeature_EmbeddedFeatureName, embeddingEntity2, embeddable,
+ HasReferenceType.SINGLE,
+ MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY,
+ JptUiDetailsMessages.EmbeddedMappingUiProvider_linkLabel, 3);
+
+ editorProxy
+ .testNoConnectionIsCreatedWithEmbeddable(
+ JPAEditorMessages.CreateManyToManyBiDirRelationFeature_manyToManyBiDirFeatureName,
+ 1, entity, embeddable);
+
+ editorProxy
+ .testUniDirRelation(
+ JPAEditorMessages.CreateManyToManyUniDirRelationFeature_manyToManyUniDirFeatureName,
+ embeddable,
+ entity,
+ IRelation.RelType.MANY_TO_MANY,
+ JptUiDetailsMessages.ManyToManyMappingUiProvider_linkLabel);
+
+ editorProxy
+ .testUniDirRelRemoveOwnerAttribute(
+ JPAEditorMessages.CreateManyToManyUniDirRelationFeature_manyToManyUniDirFeatureName,
+ embeddable,
+ entity,
+ IRelation.RelType.MANY_TO_MANY,
+ JptUiDetailsMessages.ManyToManyMappingUiProvider_linkLabel);
+
+ editorProxy.deleteDiagramElements();
+ jpaDiagramEditor.save();
+
+ Utils.sayTestFinished("testNoManyToManyBiDirConnectionIsCreatedInEmbeddableInTwoEntities");
+ }
+
+ /**
+ * Test that if the embeddable is not embedded, no one-to-one unidirectional
+ * relationship will be created from the embeddable to the entity. Add
+ * second entity and embed a collection of the embeddable. Check that a
+ * one-to-one relationship will be created from embeddable to the entity.
+ * Check that if the owner attribute will be deleted, the relationship will
+ * disappear.
+ */
+ @Test
+ public void testOneToOneUniDirRelationFromEmbeddedCollectionToEntity() {
+ Utils.sayTestStarted("testOneToOneUniDirRelationFromEmbeddedCollectionToEntity");
+
+ SWTBotGefEditPart entity = editorProxy.addEntityToDiagram(50, 200,
+ "Entity1");
+ SWTBotGefEditPart embeddable = editorProxy.addEmbeddableToDiagram(50,
+ 50, "Embeddable1");
+
+ editorProxy
+ .testNoConnectionIsCreated(
+ JPAEditorMessages.CreateOneToOneBiDirRelationFeature_oneToOneBiDirFeatureName,
+ 0, embeddable, entity);
+
+ SWTBotGefEditPart embeddingEntity = editorProxy.addEntityToDiagram(200,
+ 50, "Entity2");
+
+ embedConnection(JPAEditorMessages.EmbedCollectionOfObjectsFeature_ElementCollectionFeatureName, embeddingEntity,
+ embeddable, HasReferenceType.COLLECTION,
+ MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY,
+ JptUiDetailsMessages2_0.ElementCollectionMapping2_0_linkLabel,
+ 3);
+
+ editorProxy
+ .testUniDirRelation(
+ JPAEditorMessages.CreateOneToOneUniDirRelationFeature_oneToOneUniDirFeatureName,
+ embeddable,
+ entity,
+ IRelation.RelType.ONE_TO_ONE,
+ JptUiDetailsMessages.OneToOneMappingUiProvider_linkLabel);
+
+ editorProxy
+ .testUniDirRelRemoveOwnerAttribute(
+ JPAEditorMessages.CreateOneToOneUniDirRelationFeature_oneToOneUniDirFeatureName,
+ embeddable,
+ entity,
+ IRelation.RelType.ONE_TO_ONE,
+ JptUiDetailsMessages.OneToOneMappingUiProvider_linkLabel);
+
+ editorProxy.deleteDiagramElements();
+ jpaDiagramEditor.save();
+
+ Utils.sayTestFinished("testOneToOneUniDirRelationFromEmbeddedCollectionToEntity");
+ }
+
+ /**
+ * Test that if the embeddable is not embedded, no many-to-one
+ * unidirectional relationship will be created from the embeddable to the
+ * entity. Add second entity and embed a collection of the embeddable. Check
+ * that a many-to-one relationship will be created from embeddable to the
+ * entity. Check that if the owner attribute will be deleted, the
+ * relationship will disappear.
+ */
+ @Test
+ public void testManyToOneUniDirRelationFromEmbeddedCollectionToEntity() {
+ Utils.sayTestStarted("testManyToOneUniDirRelationFromEmbeddedCollectionToEntity");
+
+ SWTBotGefEditPart entity = editorProxy.addEntityToDiagram(50, 200,
+ "Entity1");
+ SWTBotGefEditPart embeddable = editorProxy.addEmbeddableToDiagram(50,
+ 50, "Embeddable1");
+
+ editorProxy
+ .testNoConnectionIsCreated(
+ JPAEditorMessages.CreateManyToOneBiDirRelationFeature_manyToOneBiDirFeatureName,
+ 1, embeddable, entity);
+
+ SWTBotGefEditPart embeddingEntity = editorProxy.addEntityToDiagram(200,
+ 50, "Entity2");
+
+ embedConnection(JPAEditorMessages.EmbedCollectionOfObjectsFeature_ElementCollectionFeatureName, embeddingEntity,
+ embeddable, HasReferenceType.COLLECTION,
+ MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY,
+ JptUiDetailsMessages2_0.ElementCollectionMapping2_0_linkLabel,
+ 3);
+
+ editorProxy
+ .testUniDirRelation(
+ JPAEditorMessages.CreateManyToOneUniDirRelationFeature_manyToOneUniDirFeatureName,
+ embeddable,
+ entity,
+ IRelation.RelType.MANY_TO_ONE,
+ JptUiDetailsMessages.ManyToOneMappingUiProvider_linkLabel);
+
+ editorProxy
+ .testUniDirRelRemoveOwnerAttribute(
+ JPAEditorMessages.CreateManyToOneBiDirRelationFeature_manyToOneBiDirFeatureName,
+ embeddable,
+ entity,
+ IRelation.RelType.MANY_TO_ONE,
+ JptUiDetailsMessages.ManyToOneMappingUiProvider_linkLabel);
+
+ editorProxy.deleteDiagramElements();
+ jpaDiagramEditor.save();
+
+ Utils.sayTestFinished("testManyToOneUniDirRelationFromEmbeddedCollectionToEntity");
+ }
+
+ /**
+ * Test that if a collection of embeddable is embedded into an entity,
+ * neither uni- nor bi-directional many-to-many relationships will be
+ * created.
+ */
+ @Test
+ public void testManyToManyRelationFromEmbeddedCollectionToEntity() {
+ Utils.sayTestStarted("testManyToManyRelationFromEmbeddedCollectionToEntity");
+
+ SWTBotGefEditPart entity = editorProxy.addEntityToDiagram(50, 200,
+ "Entity1");
+ SWTBotGefEditPart embeddable = editorProxy.addEmbeddableToDiagram(50,
+ 50, "Embeddable1");
+
+ editorProxy
+ .testNoConnectionIsCreated(
+ JPAEditorMessages.CreateManyToManyUniDirRelationFeature_manyToManyUniDirFeatureName,
+ 0, embeddable, entity);
+
+ editorProxy
+ .testNoConnectionIsCreated(
+ JPAEditorMessages.CreateManyToManyBiDirRelationFeature_manyToManyBiDirFeatureName,
+ 1, embeddable, entity);
+
+ SWTBotGefEditPart embeddingEntity = editorProxy.addEntityToDiagram(200,
+ 50, "Entity2");
+
+ embedConnection(JPAEditorMessages.EmbedCollectionOfObjectsFeature_ElementCollectionFeatureName, embeddingEntity,
+ embeddable, HasReferenceType.COLLECTION,
+ MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY,
+ JptUiDetailsMessages2_0.ElementCollectionMapping2_0_linkLabel,
+ 3);
+
+ editorProxy
+ .testNoConnectionIsCreated(
+ JPAEditorMessages.CreateManyToManyBiDirRelationFeature_manyToManyBiDirFeatureName,
+ 0, embeddable, entity);
+
+ editorProxy
+ .testNoConnectionIsCreated(
+ JPAEditorMessages.CreateManyToManyBiDirRelationFeature_manyToManyBiDirFeatureName,
+ 1, embeddable, entity);
+
+ editorProxy.deleteDiagramElements();
+ jpaDiagramEditor.save();
+
+ Utils.sayTestFinished("testManyToManyRelationFromEmbeddedCollectionToEntity");
+ }
+
+ /**
+ * Test that if a collection of embeddable is embedded into an entity, no
+ * one-to-many unidirectional relationships will be created.
+ */
+ @Test
+ public void testOneToManyRelationFromEmbeddedCollectionToEntity() {
+ Utils.sayTestStarted("testOneToManyRelationFromEmbeddedCollectionToEntity");
+
+ SWTBotGefEditPart entity = editorProxy.addEntityToDiagram(50, 200,
+ "Entity1");
+ SWTBotGefEditPart embeddable = editorProxy.addEmbeddableToDiagram(50,
+ 50, "Embeddable1");
+
+ editorProxy
+ .testNoConnectionIsCreated(
+ JPAEditorMessages.CreateOneToManyUniDirRelationFeature_oneToManyUniDirFeatureName,
+ 0, embeddable, entity);
+
+ SWTBotGefEditPart embeddingEntity = editorProxy.addEntityToDiagram(200,
+ 50, "Entity2");
+
+ embedConnection(JPAEditorMessages.EmbedCollectionOfObjectsFeature_ElementCollectionFeatureName, embeddingEntity,
+ embeddable, HasReferenceType.COLLECTION,
+ MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY,
+ JptUiDetailsMessages2_0.ElementCollectionMapping2_0_linkLabel,
+ 3);
+
+ editorProxy
+ .testNoConnectionIsCreated(
+ JPAEditorMessages.CreateOneToManyUniDirRelationFeature_oneToManyUniDirFeatureName,
+ 0, embeddable, entity);
+
+ editorProxy.deleteDiagramElements();
+ jpaDiagramEditor.save();
+
+ Utils.sayTestFinished("testOneToManyRelationFromEmbeddedCollectionToEntity");
+ }
+
+ @Test
+ public void testJPA10WithEmbeddables() throws CoreException {
+ Utils.sayTestStarted("testJPA10WithEmbeddables");
+
+ workbenchBot.closeAllEditors();
+
+ String name = "Test10_" + System.currentTimeMillis();
+
+ JpaProject jpaProject10 = factory.createJPAProject(name);
+ assertNotNull(jpaProject10);
+
+ SWTBotGefEditor jpaDiagramEditor10 = editorProxy
+ .openDiagramOnJPAContentNode(name, false);
+ editorProxy.setJpaDiagramEditor(jpaDiagramEditor10);
+
+ SWTBotGefEditPart embeddable1 = editorProxy.addEmbeddableToDiagram(50,
+ 50, "Embeddable1");
+ SWTBotGefEditPart embeddable2 = editorProxy.addEmbeddableToDiagram(50,
+ 200, "Embeddable2");
+
+ SWTBotGefEditPart entity = editorProxy.addEntityToDiagram(300, 50,
+ "Entity1");
+
+ boolean notAllowed = false;
+
+ try {
+ jpaDiagramEditor10.activateTool(JPAEditorMessages.EmbedCollectionOfObjectsFeature_ElementCollectionFeatureName);
+ } catch (WidgetNotFoundException e) {
+ notAllowed = true;
+ }
+
+ assertTrue(
+ "The action \"Embed Collection of Elements\" must not be available by JPA projects with 1.0 facet.",
+ notAllowed);
+
+ editorProxy.testNoEmbeddedConnectionIsCreated(JPAEditorMessages.EmbedSingleObjectFeature_EmbeddedFeatureName, 0, embeddable1, embeddable2, false);
+
+ embedConnection(jpaDiagramEditor10, JPAEditorMessages.EmbedSingleObjectFeature_EmbeddedFeatureName, entity, embeddable1,
+ HasReferenceType.SINGLE,
+ MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY,
+ JptUiDetailsMessages.EmbeddedMappingUiProvider_linkLabel, 2);
+
+ SWTBotGefEditPart entity1 = editorProxy.addEntityToDiagram(300, 300,
+ "Entity2");
+ editorProxy
+ .testNoConnectionIsCreated(
+ JPAEditorMessages.CreateOneToManyUniDirRelationFeature_oneToManyUniDirFeatureName,
+ 0, embeddable1, entity1);
+
+ editorProxy
+ .testNoConnectionIsCreated(
+ JPAEditorMessages.CreateOneToOneUniDirRelationFeature_oneToOneUniDirFeatureName,
+ 0, embeddable1, entity1);
+
+ editorProxy
+ .testNoConnectionIsCreated(
+ JPAEditorMessages.CreateOneToOneBiDirRelationFeature_oneToOneBiDirFeatureName,
+ 1, embeddable1, entity1);
+
+ editorProxy
+ .testNoConnectionIsCreated(
+ JPAEditorMessages.CreateManyToOneUniDirRelationFeature_manyToOneUniDirFeatureName,
+ 0, embeddable1, entity1);
+
+ editorProxy
+ .testNoConnectionIsCreated(
+ JPAEditorMessages.CreateManyToOneBiDirRelationFeature_manyToOneBiDirFeatureName,
+ 1, embeddable1, entity1);
+
+ editorProxy
+ .testNoConnectionIsCreated(
+ JPAEditorMessages.CreateManyToManyUniDirRelationFeature_manyToManyUniDirFeatureName,
+ 0, embeddable1, entity1);
+
+ editorProxy
+ .testNoConnectionIsCreated(
+ JPAEditorMessages.CreateManyToManyBiDirRelationFeature_manyToManyBiDirFeatureName,
+ 1, embeddable1, entity1);
+
+ editorProxy.deleteAttributeInJPT(entity, "embeddable1");
+
+ editorProxy.deleteDiagramElements();
+
+ jpaDiagramEditor10.saveAndClose();
+
+ Utils.sayTestFinished("testJPA10WithEmbeddables");
+
+ }
+
+ /**
+ * Test all specific for the embedded connections properties and delete the
+ * embedded attribute and check that the connection is deleted as well.
+ *
+ * @param toolEntry
+ * - the name of the feature in the palette
+ * @param embeddingEntity
+ * @param embeddable
+ * @param refType
+ * @param embeddedMappingKey
+ * @param linkLabel
+ * @param elementsInDiagramCount1
+ */
+ private void _testEmbeddedConnection(String toolEntry,
+ SWTBotGefEditPart embeddingEntity, SWTBotGefEditPart embeddable,
+ HasReferenceType refType, String embeddedMappingKey,
+ String linkLabel, int elementsInDiagramCount1) {
+ List<SWTBotGefEditPart> entitiesInDiagram = jpaDiagramEditor
+ .mainEditPart().children();
+ int elementsInDiagramCount = entitiesInDiagram.size();
+ assertEquals("Editor contains " + elementsInDiagramCount
+ + " pictogram elements.", elementsInDiagramCount1,
+ elementsInDiagramCount);
+
+ String attributeName = embedConnection(toolEntry, embeddingEntity,
+ embeddable, refType, embeddedMappingKey, linkLabel,
+ elementsInDiagramCount);
+
+ editorProxy.deleteAttributeInJPT(embeddingEntity, attributeName);
+
+ editorProxy.waitASecond();
+
+ entitiesInDiagram = jpaDiagramEditor.mainEditPart().children();
+ assertEquals("Connection must disappear.", elementsInDiagramCount,
+ entitiesInDiagram.size());
+ }
+
+ /**
+ * Test all specific for the embedded connections properties.
+ *
+ * @param toolEntry
+ * @param embeddingEntity
+ * @param embeddable
+ * @param refType
+ * @param embeddedMappingKey
+ * @param linkLabel
+ * @param elementsInDiagramCount
+ * @return the name of the embedded attribute
+ */
+ private String embedConnection(String toolEntry,
+ SWTBotGefEditPart embeddingEntity, SWTBotGefEditPart embeddable,
+ HasReferenceType refType, String embeddedMappingKey,
+ String linkLabel, int elementsInDiagramCount) {
+
+ jpaDiagramEditor.activateTool(toolEntry);
+
+ jpaDiagramEditor.click(embeddingEntity);
+ jpaDiagramEditor.click(embeddable);
+
+ String attributeName = checkEmbeddedConnectionProperties(
+ embeddingEntity, embeddable, refType, embeddedMappingKey,
+ linkLabel);
+ return attributeName;
+ }
+
+ private String embedConnection(SWTBotGefEditor gefEditor, String toolEntry,
+ SWTBotGefEditPart embeddingEntity, SWTBotGefEditPart embeddable,
+ HasReferenceType refType, String embeddedMappingKey,
+ String linkLabel, int elementsInDiagramCount) {
+
+ gefEditor.activateTool(toolEntry);
+
+ gefEditor.click(embeddingEntity);
+ gefEditor.click(embeddable);
+
+ String attributeName = checkEmbeddedConnectionProperties(
+ embeddingEntity, embeddable, refType, embeddedMappingKey,
+ linkLabel);
+ return attributeName;
+ }
+
+ private String checkEmbeddedConnectionProperties(
+ SWTBotGefEditPart embeddingEntity, SWTBotGefEditPart embeddable,
+ HasReferenceType refType, String embeddedMappingKey,
+ String linkLabel) {
+
+ bot.waitUntil(new ConnectionIsShown(embeddingEntity), 15000);
+
+// List<SWTBotGefEditPart> entitiesInDiagram = jpaDiagramEditor
+// .mainEditPart().children();
+// assertEquals("Connection must appear.", entitiesInDiagram.size(),
+// elementsInDiagramCount + 1);
+
+ assertFalse("The connection must appear", embeddingEntity
+ .sourceConnections().isEmpty());
+ SWTBotGefConnectionEditPart connection = embeddingEntity
+ .sourceConnections().get(0);
+ HasReferanceRelation rel = editorProxy
+ .getHasReferenceConnection(connection);
+ assertNotNull(rel);
+ assertEquals(refType, rel.getReferenceType());
+
+ String attributeName = editorProxy.testEmbeddedAttributeProperties(rel,
+ embeddedMappingKey);
+ assertNotNull(rel.getEmbeddedAnnotatedAttribute());
+
+ editorProxy.assertAttributeIsCorretlyMapped(attributeName, linkLabel);
+
+ JavaPersistentType parententity = (JavaPersistentType) rel
+ .getEmbeddedAnnotatedAttribute().getOwningPersistentType();
+ assertEquals("The entity must contain an embedded attribute.",
+ parententity,
+ editorProxy.getJPTObjectForGefElement(embeddingEntity));
+ assertEquals(rel.getEmbeddingEntity(),
+ editorProxy.getJPTObjectForGefElement(embeddingEntity));
+ assertEquals(rel.getEmbeddable(),
+ editorProxy.getJPTObjectForGefElement(embeddable));
+ return attributeName;
+ }
+
+ @AfterClass
+ public static void afterClass() throws CoreException{
+ IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
+ for(IProject project : projects){
+ project.delete(true, true, new NullProgressMonitor());
+ }
+
+ ResourcesPlugin.getWorkspace().getRoot().refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor());
+ }
+}
diff --git a/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.swtbot.tests/src/org/eclipse/jpt/jpadiagrameditor/swtbot/tests/ui/editor/EntitiesInDiagramSWTBotTest.java b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.swtbot.tests/src/org/eclipse/jpt/jpadiagrameditor/swtbot/tests/ui/editor/EntitiesInDiagramSWTBotTest.java
new file mode 100644
index 0000000..41cbb15
--- /dev/null
+++ b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.swtbot.tests/src/org/eclipse/jpt/jpadiagrameditor/swtbot/tests/ui/editor/EntitiesInDiagramSWTBotTest.java
@@ -0,0 +1,1420 @@
+package org.eclipse.jpt.jpadiagrameditor.swtbot.tests.ui.editor;
+
+import java.util.List;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.graphiti.features.IFeatureProvider;
+import org.eclipse.graphiti.mm.pictograms.PictogramElement;
+import org.eclipse.graphiti.ui.internal.parts.DiagramEditPart;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jpt.jpa.core.JpaProject;
+import org.eclipse.jpt.jpa.ui.internal.details.JptUiDetailsMessages;
+import org.eclipse.jpt.jpadiagrameditor.swtbot.tests.internal.JPACreateFactory;
+import org.eclipse.jpt.jpadiagrameditor.swtbot.tests.internal.Utils;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.i18n.JPAEditorMessages;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.IRelation;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JPAEditorConstants;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JpaArtifactFactory;
+import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot;
+import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotEditor;
+import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView;
+import org.eclipse.swtbot.eclipse.gef.finder.SWTBotGefTestCase;
+import org.eclipse.swtbot.eclipse.gef.finder.SWTGefBot;
+import org.eclipse.swtbot.eclipse.gef.finder.widgets.SWTBotGefEditPart;
+import org.eclipse.swtbot.eclipse.gef.finder.widgets.SWTBotGefEditor;
+import org.eclipse.swtbot.swt.finder.SWTBot;
+import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner;
+import org.eclipse.swtbot.swt.finder.utils.SWTBotPreferences;
+import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell;
+import org.eclipse.swtbot.swt.finder.widgets.SWTBotStyledText;
+import org.eclipse.swtbot.swt.finder.widgets.SWTBotText;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+@RunWith(SWTBotJunit4ClassRunner.class)
+@SuppressWarnings("restriction")
+public class EntitiesInDiagramSWTBotTest extends SWTBotGefTestCase {
+
+ protected static String TEST_PROJECT;
+ protected static JPACreateFactory factory = JPACreateFactory.instance();
+ protected static JpaProject jpaProject;
+
+ protected static SWTGefBot bot = new SWTGefBot();
+ protected static SWTWorkbenchBot workbenchBot = new SWTWorkbenchBot();
+ protected static EditorProxy editorProxy = new EditorProxy(workbenchBot,
+ bot);
+
+ protected static SWTBotGefEditor jpaDiagramEditor;
+
+ @BeforeClass
+ public static void beforeClass() throws Exception {
+
+ SWTBotPreferences.TIMEOUT = 1000;
+ try {
+ bot.viewByTitle("Welcome").close();
+ } catch (Exception e) {
+ // ignore
+ } finally {
+ SWTBotPreferences.TIMEOUT = 5000;
+ }
+ workbenchBot.perspectiveByLabel("JPA").activate();
+
+ TEST_PROJECT = "Test_" + System.currentTimeMillis();
+
+ factory = JPACreateFactory.instance();
+ jpaProject = factory.createJPA20Project(TEST_PROJECT);
+ assertNotNull(jpaProject);
+
+ jpaDiagramEditor = editorProxy
+ .openDiagramOnJPAContentNode(TEST_PROJECT, true);
+ editorProxy.setJpaDiagramEditor(jpaDiagramEditor);
+
+ Thread.sleep(2000);
+ }
+
+ /**
+ * Add entity to diagram and check that it contains a "Primary Key" section
+ * with one attribute "id" and no "Relation Attributes" and
+ * "Other Attributes" sections.
+ */
+ @Test
+ public void testAddEntity() {
+ Utils.sayTestStarted("testAddEntity");
+
+ editorProxy.addEntityToDiagram(50, 50, "Entity1");
+ assertTrue("Editor must be dirty", jpaDiagramEditor.isDirty());
+
+ jpaDiagramEditor.save();
+ assertFalse("Editor must not be dirty!", jpaDiagramEditor.isDirty());
+
+ editorProxy.deleteDiagramElements();
+ jpaDiagramEditor.save();
+
+ Utils.sayTestFinished("testAddEntity");
+ }
+
+ /**
+ * Remove an entity from the diagram using the entity's context button
+ * "Delete"
+ */
+ @Test
+ public void testRemoveEntityViaButton() {
+ Utils.sayTestStarted("testRemoveEntityViaButton");
+
+ SWTBotGefEditPart entity = editorProxy.addEntityToDiagram(50, 50, "Entity1");
+
+ editorProxy.deleteJPTViaButton(entity);
+
+ assertTrue("Editor must be dirty", jpaDiagramEditor.isDirty());
+ jpaDiagramEditor.save();
+
+ Utils.sayTestFinished("testRemoveEntityViaButton");
+ }
+
+ /**
+ * Remove an entity from the diagram using the entity's context menu
+ * "Delete"
+ */
+ @Test
+ public void testRemoveEntityViaContextMenu() {
+ Utils.sayTestStarted("testRemoveEntityViaContextMenu");
+
+ SWTBotGefEditPart entity = editorProxy.addEntityToDiagram(50, 50, "Entity1");
+
+ editorProxy.deleteJPTViaMenu(entity);
+
+ assertTrue("Editor must be dirty", jpaDiagramEditor.isDirty());
+ jpaDiagramEditor.save();
+
+ Utils.sayTestFinished("testRemoveEntityViaContextMenu");
+ }
+
+ /**
+ * Adds a new attribute to the entity using the entity's context button
+ * "Create Attribute"
+ */
+ @Test
+ public void testAddAttribute() {
+ Utils.sayTestStarted("testRemoveEntityViaContextMenu");
+
+ SWTBotGefEditPart entity = editorProxy.addEntityToDiagram(50, 50, "Entity1");
+
+ assertFalse(
+ "\"Other Attributes\" section must not be visible!",
+ editorProxy.isSectionVisible(JPAEditorMessages.AddJPAEntityFeature_basicAttributesShapes, entity));
+
+ editorProxy.addAttributeToJPT(entity, "attribute1");
+ assertTrue("Editor must be dirty", jpaDiagramEditor.isDirty());
+
+ entity.click();
+ editorProxy.deleteDiagramElements();
+ jpaDiagramEditor.save();
+
+ Utils.sayTestFinished("testRemoveEntityViaContextMenu");
+ }
+
+ /**
+ * Removes the attribute using the "Delete Attribute" context button.
+ */
+ @Test
+ public void testRemoveAttributeViaContextButton() {
+ Utils.sayTestStarted("testRemoveAttributeViaContextButton");
+
+ SWTBotGefEditPart entity = editorProxy.addEntityToDiagram(50, 50, "Entity1");
+
+ editorProxy.removeAttributeViaButton(entity, "attribute1");
+
+ entity.click();
+ editorProxy.deleteDiagramElements();
+ jpaDiagramEditor.save();
+
+ Utils.sayTestFinished("testRemoveAttributeViaContextButton");
+ }
+
+ /**
+ * Removes the attribute using the "Delete" context menu.
+ */
+ @Test
+ public void testRemoveAttributeViaMenu() {
+ Utils.sayTestStarted("testRemoveAttributeViaMenu");
+
+ SWTBotGefEditPart entity = editorProxy.addEntityToDiagram(50, 50, "Entity1");
+
+ editorProxy.removeAttributeViaMenu(entity, "attribute1");
+
+ entity.click();
+ editorProxy.deleteDiagramElements();
+ jpaDiagramEditor.save();
+
+ Utils.sayTestFinished("testRemoveAttributeViaMenu");
+ }
+
+ /**
+ * Adds a new attribute and rename it
+ */
+ @Test
+ public void testDirectEditingAttribute() {
+ Utils.sayTestStarted("testDirectEditingAttribute");
+
+ SWTBotGefEditPart entity = editorProxy.addEntityToDiagram(50, 50, "Entity1");
+
+ editorProxy.directEditAttribute(entity, "attribute1");
+
+ assertTrue("Editor must be dirty", jpaDiagramEditor.isDirty());
+
+ editorProxy.deleteDiagramElements();
+ jpaDiagramEditor.save();
+
+ Utils.sayTestFinished("testDirectEditingAttribute");
+ }
+
+ /**
+ * Adds a new entity and rename it
+ */
+ @Ignore
+ @Test
+ public void testDirectEditingEntity() {
+ Utils.sayTestStarted("testDirectEditingEntity");
+
+ SWTBotGefEditPart entity = editorProxy.addEntityToDiagram(50, 50, "Entity1");
+ assertTrue("Editor must be dirty", jpaDiagramEditor.isDirty());
+
+ editorProxy.moveMouse(100, 70);
+ entity.click();
+ entity.activateDirectEdit();
+ jpaDiagramEditor.directEditType("NewEntityName");
+ editorProxy.moveMouse(0, 0);
+
+ SWTBotGefEditPart oldEntity = jpaDiagramEditor.getEditPart("Entity1");
+ SWTBotGefEditPart newEntity = jpaDiagramEditor
+ .getEditPart("NewEntityName");
+ assertNotNull("The entity must be renamed!", newEntity);
+ assertNull("The attribute must be renamed!", oldEntity);
+
+ assertTrue("Editor must be dirty", jpaDiagramEditor.isDirty());
+
+ editorProxy.deleteDiagramElements();
+ jpaDiagramEditor.save();
+
+ Utils.sayTestFinished("testDirectEditingEntity");
+ }
+
+ /**
+ * Test that the source of the entity is opened, when is double clicked on
+ * it
+ */
+ @Ignore
+ @Test
+ public void testDoubleClickOnEntity() {
+ Utils.sayTestStarted("testDoubleClickOnEntity");
+
+ SWTBotGefEditPart entity = editorProxy.addEntityToDiagram(50, 50, "Entity1");
+ assertTrue("Editor must be dirty", jpaDiagramEditor.isDirty());
+ editorProxy.moveMouse(100, 70);
+ jpaDiagramEditor.doubleClick(entity);
+ editorProxy.moveMouse(0, 0);
+
+ SWTBotEditor activeEditor = workbenchBot.activeEditor();
+ assertEquals("The Java editor of the enity did not open!",
+ "Entity1.java", activeEditor.getTitle());
+ activeEditor.close();
+
+ editorProxy.deleteDiagramElements();
+ jpaDiagramEditor.save();
+
+ Utils.sayTestFinished("testDoubleClickOnEntity");
+ }
+
+ /**
+ * Change the attribute type.
+ */
+ @Test
+ public void testChangeAttributeType() {
+ Utils.sayTestStarted("testChangeAttributeType");
+
+ SWTBotGefEditPart entity = editorProxy.addEntityToDiagram(50, 50, "Entity1");
+
+ assertFalse("\"Other Attributes\" section must not be visible!",
+ editorProxy.isSectionVisible(JPAEditorMessages.AddJPAEntityFeature_basicAttributesShapes, entity));
+
+ SWTBotGefEditPart attribute = editorProxy.addAttributeToJPT(entity, "attribute1");
+ assertNotNull("The attribute must not be renamed!", attribute);
+
+ final IFeatureProvider fp = ((DiagramEditPart) jpaDiagramEditor
+ .mainEditPart().part()).getFeatureProvider();
+
+ String currentAttributeType = editorProxy.getAttributeType("attribute1", fp);
+ assertEquals("java.lang.String", currentAttributeType);
+
+ SWTBotShell changeTypeDialog = editorProxy
+ .getSelectNewAttributeTypeDialog(attribute);
+ SWTBotText attributeType = editorProxy
+ .getNewTypeInputField(changeTypeDialog);
+
+ // test invalid attribute type
+ attributeType.setText("");
+ assertFalse(editorProxy.getOkButton(changeTypeDialog).isEnabled());
+ assertTrue(editorProxy.getCancelButton(changeTypeDialog).isEnabled());
+ SWTBotText dialogError = editorProxy
+ .getDialogErroMessage(changeTypeDialog);
+ assertEquals(" The new type name must not be empty",
+ dialogError.getText());
+ // cancel the dialog
+ editorProxy.getCancelButton(changeTypeDialog).click();
+
+ // assert that the attribute type is not changed
+ currentAttributeType = editorProxy.getAttributeType("attribute1", fp);
+ assertEquals("The attribute type must not be changed!",
+ "java.lang.String", currentAttributeType);
+
+ changeTypeDialog = editorProxy.getSelectNewAttributeTypeDialog(attribute);
+ attributeType = editorProxy.getNewTypeInputField(changeTypeDialog);
+
+ // change the attribute type to int
+ attributeType.setText("int");
+ assertTrue(editorProxy.getOkButton(changeTypeDialog).isEnabled());
+ assertTrue(editorProxy.getCancelButton(changeTypeDialog).isEnabled());
+ // confirm the dialog
+ editorProxy.getOkButton(changeTypeDialog).click();
+ editorProxy.waitASecond();
+ // assert that the attribute's type is changed
+ String newAttributeType = editorProxy
+ .getAttributeType("attribute1", fp);
+ assertFalse("The attribute type must be changed!",
+ ("java.lang.String").equals(newAttributeType));
+ assertEquals("The attribute type must be changed!", "int",
+ newAttributeType);
+
+ assertTrue("Editor must be dirty!", jpaDiagramEditor.isDirty());
+ entity.click();
+ editorProxy.deleteDiagramElements();
+ jpaDiagramEditor.save();
+
+ Utils.sayTestFinished("testChangeAttributeType");
+ }
+
+ /**
+ * Rename the entity using its context menu
+ * "Refactor Entity Class -> Rename..."
+ */
+ @Ignore
+ @Test
+ public void testRenameEntityViaMenu() {
+ Utils.sayTestStarted("testRenameEntityViaMenu");
+
+ SWTBotGefEditPart entity = editorProxy.addEntityToDiagram(50, 50, "Entity1");
+
+ entity.click();
+ jpaDiagramEditor
+ .clickContextMenu(JPAEditorMessages.JPAEditorToolBehaviorProvider_renameEntityClass);
+
+ SWTBotShell renameEntityDialog = editorProxy.getRenameEntityDialog();
+ SWTBotText entityName = renameEntityDialog.bot().textWithLabel(
+ "New name:");
+
+ // test invalid entity name
+ entityName.setText("");
+ assertFalse(editorProxy.getFinishButton(renameEntityDialog).isEnabled());
+ assertTrue(editorProxy.getCancelButton(renameEntityDialog).isEnabled());
+
+ entityName.setText("NewEntityName");
+ assertTrue(editorProxy.getFinishButton(renameEntityDialog).isEnabled());
+ assertTrue(editorProxy.getCancelButton(renameEntityDialog).isEnabled());
+
+ editorProxy.getFinishButton(renameEntityDialog).click();
+ bot.waitUntil(new ElementIsShown(jpaDiagramEditor, "NewEntityName"),
+ 10000);
+
+ entity = jpaDiagramEditor.getEditPart("NewEntityName");
+ assertNotNull("Entity name must be changed!", entity);
+ assertNull("Entity naem must be changed!",
+ jpaDiagramEditor.getEditPart("Entity1"));
+
+ entity.click();
+ editorProxy.deleteDiagramElements();
+ jpaDiagramEditor.save();
+
+ Utils.sayTestFinished("testRenameEntityViaMenu");
+ }
+
+ /**
+ * Move the entity class using the entity's context menu
+ * "Refactor Entity Class -> Move..."
+ */
+ @Ignore
+ @Test
+ public void testMoveEntityViaMenu() throws JavaModelException {
+ Utils.sayTestStarted("testMoveEntityViaMenu");
+
+ SWTBotGefEditPart entity = editorProxy.addEntityToDiagram(50, 50, "Entity1");
+ JpaArtifactFactory factory = JpaArtifactFactory.instance();
+
+ String packageName = factory
+ .getMappedSuperclassPackageDeclaration(editorProxy
+ .getJPTObjectForGefElement(entity));
+
+ entity.click();
+ jpaDiagramEditor
+ .clickContextMenu(JPAEditorMessages.JPAEditorToolBehaviorProvider_moveEntityClass);
+
+ SWTBotShell moveEntityDialog = editorProxy.getMoveEntityDialog();
+ moveEntityDialog.bot().tree().getTreeItem(TEST_PROJECT).select()
+ .expandNode("src").expandNode("org").select().click();
+ assertTrue(editorProxy.getOkButton(moveEntityDialog).isEnabled());
+ editorProxy.getOkButton(moveEntityDialog).click();
+ editorProxy.waitASecond();
+
+ entity = jpaDiagramEditor.getEditPart("Entity1");
+ String newEntityPackage = factory
+ .getMappedSuperclassPackageDeclaration(editorProxy
+ .getJPTObjectForGefElement(entity));
+ assertFalse("Entity must be moved!",
+ packageName.equals(newEntityPackage));
+ assertTrue("Entity must be changed!", newEntityPackage.equals("org"));
+
+ entity.click();
+ editorProxy.deleteDiagramElements();
+ jpaDiagramEditor.save();
+
+ Utils.sayTestFinished("testMoveEntityViaMenu");
+ }
+
+ /**
+ * Collapse/expand entity using its context buttons
+ */
+ @Test
+ public void testCollapseExapandEntityViaContextButton() {
+ Utils.sayTestStarted("testCollapseExapandEntityViaContextButton");
+
+ SWTBotGefEditPart entity = editorProxy.addEntityToDiagram(50, 50, "Entity1");
+
+ editorProxy.collapseExpandJPTViaButton(entity);
+
+ editorProxy.deleteDiagramElements();
+ jpaDiagramEditor.save();
+
+ Utils.sayTestFinished("testCollapseExapandEntityViaContextButton");
+ }
+
+ /**
+ * Collapse/expand entity using its context menus
+ */
+ @Test
+ public void testCollapseExapandEntityViaMenu() {
+ Utils.sayTestStarted("testCollapseExapandEntityViaMenu");
+
+ SWTBotGefEditPart entity = editorProxy.addEntityToDiagram(50, 50, "Entity1");
+
+ editorProxy.collapseExpandJPTViaMenu(entity);
+
+ editorProxy.deleteDiagramElements();
+ jpaDiagramEditor.save();
+
+ Utils.sayTestFinished("testCollapseExapandEntityViaMenu");
+ }
+
+ /**
+ * Collapse/expand all entities using the context menus
+ */
+ @Test
+ public void testCollapseExapandAllEntitiesViaMenu() {
+ Utils.sayTestStarted("testCollapseExapandAllEntitiesViaMenu");
+
+ SWTBotGefEditPart entity1 = editorProxy.addEntityToDiagram(50, 50, "Entity1");
+ SWTBotGefEditPart entity2 = editorProxy.addEntityToDiagram(300, 50, "Entity2");
+
+ editorProxy.collapseExpandAllJPTsViaMenu(entity1, entity2);
+
+ editorProxy.deleteDiagramElements();
+ jpaDiagramEditor.save();
+
+ Utils.sayTestFinished("testCollapseExapandAllEntitiesViaMenu");
+ }
+
+ /**
+ * Add a new attribute without saving the entity and call the
+ * "Discard Changes" context menu. Assert that the newly added attribute is
+ * removed and the entity does not contain unsaved changes.
+ */
+ @Test
+ public void testDiscardChanges() {
+ Utils.sayTestStarted("testDiscardChanges");
+
+ SWTBotGefEditPart entity = editorProxy.addEntityToDiagram(50, 50, "Entity1");
+
+ editorProxy.discardChanges(entity, "attribute1");
+
+ editorProxy.deleteDiagramElements();
+ jpaDiagramEditor.save();
+
+ Utils.sayTestFinished("testDiscardChanges");
+ }
+
+ /**
+ * Add a new attribute without saving the entity and call the entity's
+ * context menu "Remove All Entities from Diagram -> ... and Discard
+ * Changes" context menu. Assert that the diagram is empty. Call "Show All
+ * Entities" context menu and assert that the newly added attribute is
+ * removed and the entity does not contain unsaved changes.
+ */
+ @Test
+ public void testRemoveAndDiscardChangesViaMenu() {
+ Utils.sayTestStarted("testRemoveAndDiscardChangesViaMenu");
+
+ SWTBotGefEditPart entity = editorProxy.addEntityToDiagram(50, 50, "Entity1");
+
+ editorProxy.removeAndDiscardChangesViaMenu(entity,
+ "attribute1");
+
+ entity.click();
+ editorProxy.deleteDiagramElements();
+ jpaDiagramEditor.save();
+
+ Utils.sayTestFinished("testRemoveAndDiscardChangesViaMenu");
+ }
+
+ /**
+ * Add a new attribute without saving the entity and call the entity's
+ * context menu "Remove All Entities from Diagram -> ... and Save
+ * Changes" context menu. Assert that the diagram is empty. Call "Show All
+ * Entities" context menu and assert that the newly added attribute is added
+ * and the entity does not contain unsaved changes.
+ */
+ @Test
+ public void testRemoveAndSaveChangesViaMenu() {
+ Utils.sayTestStarted("testRemoveAndSaveChangesViaMenu");
+
+ SWTBotGefEditPart entity = editorProxy.addEntityToDiagram(50, 50, "Entity1");
+
+ editorProxy.removeAndSaveChangesViaMenu(entity, "attribute1");
+
+ entity.click();
+ editorProxy.deleteDiagramElements();
+ jpaDiagramEditor.save();
+
+ Utils.sayTestFinished("testRemoveAndSaveChangesViaMenu");
+ }
+
+ /**
+ * Add a new attribute to the entity. From the entity's context menu select
+ * "Save". Assert that the entity does not contain any unsaved changes, but
+ * the diagram editor is still dirty.
+ */
+ @Test
+ public void testSaveOnlyEntity() {
+ Utils.sayTestStarted("testSaveOnlyEntity");
+
+ SWTBotGefEditPart entity = editorProxy.addEntityToDiagram(50, 50, "Entity1");
+ editorProxy.saveOnlyJPT(entity, "attribute1");
+
+ editorProxy.deleteDiagramElements();
+ jpaDiagramEditor.save();
+
+ Utils.sayTestFinished("testSaveOnlyEntity");
+ }
+
+ /**
+ * Create a JPA project and one entity in it. Open the JPA diagram editor
+ * and call the "Show All Entities" context menu. Assert that the previously
+ * created entity is shown in the diagram.
+ *
+ * @throws Exception
+ */
+ @Test
+ public void testShowAllEntities() throws Exception {
+ Utils.sayTestStarted("testShowAllEntities");
+
+ factory.createEntity(jpaProject, "com.sap.test.Customer");
+ assertTrue(jpaDiagramEditor.mainEditPart().children().isEmpty());
+
+ jpaDiagramEditor
+ .clickContextMenu(JPAEditorMessages.JPAEditorToolBehaviorProvider_showAllTheEntities);
+
+ List<SWTBotGefEditPart> entities = jpaDiagramEditor.mainEditPart()
+ .children();
+ assertFalse("Diagram editor must contain at least one entity!",
+ entities.isEmpty());
+
+ SWTBotGefEditPart entity = jpaDiagramEditor.getEditPart("Customer");
+ assertNotNull(entity);
+
+ editorProxy.deleteDiagramElements();
+ jpaDiagramEditor.save();
+
+ Utils.sayTestFinished("testShowAllEntities");
+ }
+
+ /**
+ * Collapse/expand "Primary Key" section by double click on it
+ */
+ @Ignore
+ @Test
+ public void testCollapseExpandCompartmentByDoubleClick() {
+ Utils.sayTestStarted("testCollapseExpandCompartmentByDoubleClick");
+
+ editorProxy.addEntityToDiagram(50, 50, "Entity1");
+
+ editorProxy.moveMouse(100, 100);
+ SWTBotGefEditPart primaryKeySection = jpaDiagramEditor
+ .getEditPart(JPAEditorMessages.AddJPAEntityFeature_primaryKeysShape);
+
+ int height = ((PictogramElement) primaryKeySection.part().getModel())
+ .getGraphicsAlgorithm().getHeight();
+
+ primaryKeySection.click();
+
+ jpaDiagramEditor.doubleClick(primaryKeySection);
+ primaryKeySection = jpaDiagramEditor
+ .getEditPart(JPAEditorMessages.AddJPAEntityFeature_primaryKeysShape);
+ int newHeight = ((PictogramElement) primaryKeySection.part().getModel())
+ .getGraphicsAlgorithm().getHeight();
+ assertEquals("Primary Key section must be collapsed!",
+ JPAEditorConstants.COMPARTMENT_MIN_HEIGHT, newHeight);
+ assertTrue(newHeight < height);
+
+ jpaDiagramEditor.doubleClick(primaryKeySection);
+ primaryKeySection = jpaDiagramEditor
+ .getEditPart(JPAEditorMessages.AddJPAEntityFeature_primaryKeysShape);
+ int newHeight1 = ((PictogramElement) primaryKeySection.part()
+ .getModel()).getGraphicsAlgorithm().getHeight();
+ assertEquals("Primary Key section must be collapsed!", height,
+ newHeight1);
+ assertTrue(newHeight1 > JPAEditorConstants.COMPARTMENT_MIN_HEIGHT);
+
+ editorProxy.moveMouse(0, 0);
+ editorProxy.deleteDiagramElements();
+ jpaDiagramEditor.save();
+
+ Utils.sayTestFinished("testCollapseExpandCompartmentByDoubleClick");
+ }
+
+ /**
+ * Collapse/expand compartment by its context menu
+ */
+ @Ignore
+ @Test
+ public void testCollapseExpandCompartmentByContextMenu() {
+ Utils.sayTestStarted("testCollapseExpandCompartmentByContextMenu");
+
+ SWTBotGefEditPart entity = editorProxy.addEntityToDiagram(50, 50, "Entity1");
+
+ // editorProxy.moveMouse(jpaDiagramEditor, 100, 100);
+ SWTBotGefEditPart primaryKeySection = editorProxy.getSectionInJPT(entity,
+ JPAEditorMessages.AddJPAEntityFeature_primaryKeysShape);
+ // SWTBotGefEditPart primaryKeySection =
+ // jpaDiagramEditor.getEditPart(JPAEditorMessages.AddJPAEntityFeature_primaryKeysShape);
+ primaryKeySection.select();
+ int height = ((PictogramElement) primaryKeySection.part().getModel())
+ .getGraphicsAlgorithm().getHeight();
+
+ primaryKeySection.click();
+
+ jpaDiagramEditor
+ .clickContextMenu(JPAEditorMessages.JPAEditorToolBehaviorProvider_collapseAttrGroupMenuItem);
+ primaryKeySection = jpaDiagramEditor
+ .getEditPart(JPAEditorMessages.AddJPAEntityFeature_primaryKeysShape);
+ int newHeight = ((PictogramElement) primaryKeySection.part().getModel())
+ .getGraphicsAlgorithm().getHeight();
+ assertEquals("Primary Key section must be collapsed!",
+ JPAEditorConstants.COMPARTMENT_MIN_HEIGHT, newHeight);
+ assertTrue(newHeight < height);
+
+ jpaDiagramEditor
+ .clickContextMenu(JPAEditorMessages.JPAEditorToolBehaviorProvider_expandAttrMenuItem);
+ primaryKeySection = jpaDiagramEditor
+ .getEditPart(JPAEditorMessages.AddJPAEntityFeature_primaryKeysShape);
+ int newHeight1 = ((PictogramElement) primaryKeySection.part()
+ .getModel()).getGraphicsAlgorithm().getHeight();
+ assertEquals("Primary Key section must be collapsed!", height,
+ newHeight1);
+ assertTrue(newHeight1 > JPAEditorConstants.COMPARTMENT_MIN_HEIGHT);
+
+ editorProxy.moveMouse(0, 0);
+ editorProxy.deleteDiagramElements();
+ jpaDiagramEditor.save();
+
+ Utils.sayTestFinished("testCollapseExpandCompartmentByContextMenu");
+ }
+
+ /**
+ * Test the integration between the JPA diagram editor and the JPA Details
+ * view: 1.) Close the JPA Details view 2.) Create an entity and call the
+ * context menu "Open JPA Details View" 3.) Assert that the JPA Details view
+ * is opened and the appropriate information is shown (the type is mapped as
+ * entity and the expandable sections are available). 4.) Change the mapping
+ * type to "Mapped Superclass" 5.) Change the mapping type to "Embeddable"
+ * and assert that the type is removed from the diagram 6.) Revert the
+ * mapping type to be "Entity" and call the "Show All Entities" context menu
+ * to visualize the entity in the diagram editor.
+ */
+ @Ignore
+ @Test
+ public void testChangeEntityMappingTypeViaJPADetailsView() {
+ Utils.sayTestStarted("testChangeEntityMappingTypeViaJPADetailsView");
+
+ workbenchBot.viewByTitle("JPA Details").close();
+ SWTBotGefEditPart entity = editorProxy.addEntityToDiagram(50, 50, "Entity1");
+
+ jpaDiagramEditor.save();
+ jpaDiagramEditor
+ .clickContextMenu(JPAEditorMessages.JPAEditorToolBehaviorProvider_openJPADetailsView);
+
+ // assert that the JPA Details view is opened
+ SWTBotView jpaDetailsView = workbenchBot.viewByTitle("JPA Details");
+ assertTrue("JPA Details view must be opened!",
+ jpaDetailsView.isActive());
+
+ // assert that the type is mapped as entity in the JPA Deatils view
+ entity.click();
+ SWTBot jpaDetailsBot = jpaDetailsView.bot();
+ SWTBotStyledText styledText = jpaDetailsBot.styledText();
+ assertEquals("Type 'Entity1' is mapped as entity.",
+ styledText.getText());
+ assertNotNull("Entity must be shown in the diagram!",
+ jpaDiagramEditor.getEditPart("Entity1"));
+ // assert that the entity's sections are enabled
+ assertTrue(jpaDetailsBot.label("Entity").isEnabled());
+ assertTrue(jpaDetailsBot.label("Queries").isEnabled());
+ assertTrue(jpaDetailsBot.label("Inheritance").isEnabled());
+ assertTrue(jpaDetailsBot.label("Attribute Overrides").isEnabled());
+ assertTrue(jpaDetailsBot.label("Primary Key Generation").isEnabled());
+ assertTrue(jpaDetailsBot.label("Secondary Tables").isEnabled());
+
+ // change the mapping type to "Mapped Superclass" and assert that the
+ // type is mapped
+ // as mapped superclass in the JPA Details view
+ editorProxy.clickOnStyledText(styledText, 30);
+ editorProxy.changeMappingtype("Mapped Superclass");
+ styledText = jpaDetailsBot.styledText();
+ assertEquals("Type 'Entity1' is mapped as mapped superclass.",
+ styledText.getText());
+ assertNotNull("Entity must be shown in the diagram!",
+ jpaDiagramEditor.getEditPart("Entity1"));
+ // assert that the mapped superclass'es sections are enabled
+ assertTrue(jpaDetailsBot.label("Mapped Superclass").isEnabled());
+ assertTrue(jpaDetailsBot.label("Queries").isEnabled());
+
+ // change the mapping type to "Embeddable" and assert that the element
+ // is removed from the diagram
+ // and the type is mapped as embeddable in the JPA Details view
+ editorProxy.clickOnStyledText(styledText, 30);
+ editorProxy.changeMappingtype("Embeddable");
+ styledText = jpaDetailsBot.styledText();
+ assertEquals("Type 'Entity1' is mapped as embeddable.",
+ styledText.getText());
+ assertNotNull("Entity must disappear from the diagram!",
+ jpaDiagramEditor.getEditPart("Entity1"));
+ // assert that the embeddable's section is enabled
+ // assertTrue(jpaDetailsBot.label("Embeddable").isEnabled());
+
+ // revert the mapping type to Entity
+ editorProxy.clickOnStyledText(styledText, 30);
+ editorProxy.changeMappingtype("Entity");
+ assertNotNull("Entity must disappear from the diagram!",
+ jpaDiagramEditor.getEditPart("Entity1"));
+
+ jpaDiagramEditor.click(0, 0);
+
+ jpaDiagramEditor.select("Entity1");
+ styledText = jpaDetailsBot.styledText();
+ assertEquals("Type 'Entity1' is mapped as entity.",
+ styledText.getText());
+ // assert that the entity's sections are enabled
+ assertTrue(jpaDetailsBot.label("Entity").isEnabled());
+ assertTrue(jpaDetailsBot.label("Queries").isEnabled());
+ assertTrue(jpaDetailsBot.label("Inheritance").isEnabled());
+ assertTrue(jpaDetailsBot.label("Attribute Overrides").isEnabled());
+ assertTrue(jpaDetailsBot.label("Primary Key Generation").isEnabled());
+ assertTrue(jpaDetailsBot.label("Secondary Tables").isEnabled());
+
+ entity.click();
+ editorProxy.deleteDiagramElements();
+ jpaDiagramEditor.save();
+
+ Utils.sayTestFinished("testChangeEntityMappingTypeViaJPADetailsView");
+ }
+
+ /**
+ * Test the integration between the JPA diagram editor and the JPA Details
+ * view: 1.) Close the JPA Details view 2.) Create an entity and call the
+ * context menu "Open JPA Details View" 3.) Assert that the JPA Details view
+ * is opened and the appropriate information is shown (the id attribute is
+ * mapped as id and the expandable sections are available). 4.) Change the
+ * attribute mapping type to "Basic" and assert that the attribute is moved
+ * to "Other Attributes" compartment 5.) Change the attribute mapping type
+ * to "On-To-Many" and assert that the attribute is moved to
+ * "Relation Attributes" compartment 7.) Revert the attribute mapping to
+ * "ID" and assert that the attributes is moved back to the "Primary Key"
+ * compartment
+ */
+ @Ignore
+ @Test
+ public void testChangeAttributeMappingTypeViaJPADetailsView() {
+ Utils.sayTestStarted("testChangeAttributeMappingTypeViaJPADetailsView");
+
+ workbenchBot.viewByTitle("JPA Details").close();
+ SWTBotGefEditPart entity = editorProxy.addEntityToDiagram(50, 50, "Entity1");
+
+ jpaDiagramEditor.save();
+ jpaDiagramEditor
+ .clickContextMenu(JPAEditorMessages.JPAEditorToolBehaviorProvider_openJPADetailsView);
+
+ // assert that the JPA Details view is opened
+ SWTBotView jpaDetailsView = workbenchBot.viewByTitle("JPA Details");
+ assertTrue("JPA Details view must be opened!",
+ jpaDetailsView.isActive());
+
+ SWTBotGefEditPart primaryKeyAttr = jpaDiagramEditor.getEditPart("id");
+ primaryKeyAttr.click();
+
+ // assert that the default entity's attribute is mapped as primary key
+ SWTBot jpaDetailsBot = jpaDetailsView.bot();
+ SWTBotStyledText styledText = jpaDetailsBot.styledText();
+ assertEquals("Attribute 'id' is mapped as ID.", styledText.getText());
+ // assert that the attribute is under "Primary Key" section
+ assertTrue(
+ "Attribute must be in the \"Primary Key\" section of the entity!",
+ editorProxy.isSectionVisible(JPAEditorMessages.AddJPAEntityFeature_primaryKeysShape,
+ entity));
+ assertFalse(
+ "Attribute must be in the \"Primary Key\" section of the entity!",
+ editorProxy
+ .isSectionVisible(JPAEditorMessages.AddJPAEntityFeature_relationAttributesShapes,
+ entity));
+ assertFalse(
+ "Attribute must be in the \"Primary Key\" section of the entity!",
+ editorProxy
+ .isSectionVisible(JPAEditorMessages.AddJPAEntityFeature_basicAttributesShapes,
+ entity));
+ // assert that the ID's sections are available
+ assertTrue(jpaDetailsBot.label("ID").isEnabled());
+ assertTrue(jpaDetailsBot.label("Type").isEnabled());
+ assertTrue(jpaDetailsBot.label("Primary Key Generation").isEnabled());
+
+ // change the attribute type to basic
+ editorProxy.clickOnStyledText(styledText, 29);
+ editorProxy.changeMappingtype("Basic");
+ styledText = jpaDetailsBot.styledText();
+ assertEquals("Attribute 'id' is mapped as basic.", styledText.getText());
+ // assert that the attribute is moved under "Other Attributes" section
+ assertFalse(
+ "Attribute must be in the \"Primary Key\" section of the entity!",
+ editorProxy.isSectionVisible(JPAEditorMessages.AddJPAEntityFeature_primaryKeysShape,
+ entity));
+ assertFalse(
+ "Attribute must be in the \"Relation Attributes\" section of the entity!",
+ editorProxy
+ .isSectionVisible(JPAEditorMessages.AddJPAEntityFeature_relationAttributesShapes,
+ entity));
+ assertTrue(
+ "Attribute must be in the \"Other Attributes\" section of the entity!",
+ editorProxy
+ .isSectionVisible(JPAEditorMessages.AddJPAEntityFeature_basicAttributesShapes,
+ entity));
+ // assert that the Basic's sections are available
+ assertTrue(jpaDetailsBot.label("Basic").isEnabled());
+ assertTrue(jpaDetailsBot.label("Type").isEnabled());
+
+ // change the attribute type to Many to Many
+ editorProxy.clickOnStyledText(styledText, 29);
+ editorProxy.changeMappingtype("Many to Many");
+ styledText = jpaDetailsBot.styledText();
+ assertEquals("Attribute 'id' is mapped as many to many.",
+ styledText.getText());
+ // assert that the attribute is moved under the "Relation Attributes"
+ // section
+ assertFalse(
+ "Attribute must be in the \"Primary key\" section of the entity!",
+ editorProxy.isSectionVisible(JPAEditorMessages.AddJPAEntityFeature_primaryKeysShape,
+ entity));
+ assertTrue(
+ "Attribute must be in the \"Relation Attributes\" section of the entity!",
+ editorProxy
+ .isSectionVisible(JPAEditorMessages.AddJPAEntityFeature_relationAttributesShapes,
+ entity));
+ assertFalse(
+ "Attribute must be in the \"Other Attributes\" section of the entity!",
+ editorProxy
+ .isSectionVisible(JPAEditorMessages.AddJPAEntityFeature_basicAttributesShapes,
+ entity));
+ // assert that the Many to Many's sections are available
+ assertTrue(jpaDetailsBot.label("Many to Many").isEnabled());
+ assertTrue(jpaDetailsBot.label("Joining Strategy").isEnabled());
+ assertTrue(jpaDetailsBot.label("Ordering").isEnabled());
+
+ // revert the attribute type back to Id
+ editorProxy.clickOnStyledText(styledText, 29);
+ editorProxy.changeMappingtype("ID");
+ styledText = jpaDetailsBot.styledText();
+ assertEquals("Attribute 'id' is mapped as ID.", styledText.getText());
+ // assert that the attribute is under "Primary Key" section
+ assertTrue(
+ "Attribute must be in the \"Primary Key\" section of the entity!",
+ editorProxy.isSectionVisible(JPAEditorMessages.AddJPAEntityFeature_primaryKeysShape,
+ entity));
+ assertFalse(
+ "Attribute must be in the \"Relation Attributes\" section of the entity!",
+ editorProxy
+ .isSectionVisible(JPAEditorMessages.AddJPAEntityFeature_relationAttributesShapes,
+ entity));
+ assertFalse(
+ "Attribute must be in the \"Other Attributes\" section of the entity!",
+ editorProxy
+ .isSectionVisible(JPAEditorMessages.AddJPAEntityFeature_basicAttributesShapes,
+ entity));
+ // assert that the ID's sections are available
+ assertTrue(jpaDetailsBot.label("ID").isEnabled());
+ assertTrue(jpaDetailsBot.label("Type").isEnabled());
+ assertTrue(jpaDetailsBot.label("Primary Key Generation").isEnabled());
+
+ entity.click();
+ editorProxy.deleteDiagramElements();
+ jpaDiagramEditor.save();
+
+ Utils.sayTestFinished("testChangeAttributeMappingTypeViaJPADetailsView");
+ }
+
+ /**
+ * Creates "One to One" unidirectional relationship (from entity1 to
+ * entity2). Assert that the relation attributes exists. Delete the
+ * relationship and assert that the attributes do not exists anymore.
+ * Check that if the owner attribute will be deleted, the relationship will
+ * disappear.
+ *
+ */
+ @Test
+ public void testOneToOneUniDirRelationship() {
+ Utils.sayTestStarted("testOneToOneUniDirRelationship");
+
+ SWTBotGefEditPart entity1 = editorProxy.addEntityToDiagram(50, 50, "Entity1");
+ SWTBotGefEditPart entity2 = editorProxy.addEntityToDiagram(50, 200, "Entity2");
+
+ // create One-to-One unidirectional relation from entity1 to entity2
+ editorProxy.testUniDirRelation(JPAEditorMessages.CreateOneToOneUniDirRelationFeature_oneToOneUniDirFeatureName,
+ entity1, entity2, IRelation.RelType.ONE_TO_ONE,
+ JptUiDetailsMessages.OneToOneMappingUiProvider_linkLabel);
+
+ // create One-to-One unidirectional relation from entity1 to entity2
+ editorProxy.testUniDirRelRemoveOwnerAttribute(
+ JPAEditorMessages.CreateOneToOneUniDirRelationFeature_oneToOneUniDirFeatureName,
+ entity1, entity2, IRelation.RelType.ONE_TO_ONE,
+ JptUiDetailsMessages.OneToOneMappingUiProvider_linkLabel);
+
+ editorProxy.deleteDiagramElements();
+
+ jpaDiagramEditor.save();
+
+ Utils.sayTestFinished("testOneToOneUniDirRelationship");
+ }
+
+ /**
+ * Creates "One to One" unidirectional self relationship (from entity1 to
+ * entity1). Assert that the relation attributes exists. Delete the
+ * relationship and assert that the attributes do not exists anymore.
+ */
+ @Test
+ public void testSelfOneToOneUniDirRelationship() {
+ Utils.sayTestStarted("testSelfOneToOneUniDirRelationship");
+
+ SWTBotGefEditPart entity1 = editorProxy.addEntityToDiagram(50, 50, "Entity1");
+
+ // create One-to-One unidirectional self relation from entity1 to
+ // entity1
+ editorProxy.testSelfUniDirRelation(
+ JPAEditorMessages.CreateOneToOneUniDirRelationFeature_oneToOneUniDirFeatureName,
+ entity1, IRelation.RelType.ONE_TO_ONE,
+ JptUiDetailsMessages.OneToOneMappingUiProvider_linkLabel);
+
+ editorProxy.deleteDiagramElements();
+
+ jpaDiagramEditor.save();
+
+ Utils.sayTestFinished("testSelfOneToOneUniDirRelationship");
+ }
+
+ /**
+ * Creates "One to One" bidirectional relationship (from entity1 to
+ * entity2). Assert that the relation attributes exists. Delete the
+ * relationship and assert that the attributes do not exists anymore.
+ * Check that if the inverse attribute will be deleted the
+ * connection will be transformed into one-to-one unidirectional
+ * relationship. Test that if the owner attribute will be deleted, the
+ * relationship will disappear.
+ */
+ @Test
+ public void testOneToOneBiDirRelationship() {
+ Utils.sayTestStarted("testOneToOneBiDirRelationship");
+
+ SWTBotGefEditPart entity1 = editorProxy.addEntityToDiagram(50, 50, "Entity1");
+ SWTBotGefEditPart entity2 = editorProxy.addEntityToDiagram(50, 200, "Entity2");
+
+ // create One-to-One bidirectional relation from entity1 to entity2
+ editorProxy.testBiDirRel(
+ JPAEditorMessages.CreateOneToOneBiDirRelationFeature_oneToOneBiDirFeatureName,
+ entity1, entity2, IRelation.RelType.ONE_TO_ONE,
+ JptUiDetailsMessages.OneToOneMappingUiProvider_linkLabel);
+
+ // create One-to-One bidirectional relation from entity1 to entity2
+ editorProxy.testBiDirRelRemoveInverseAttribute(
+ JPAEditorMessages.CreateOneToOneBiDirRelationFeature_oneToOneBiDirFeatureName,
+ entity1, entity2, IRelation.RelType.ONE_TO_ONE,
+ JptUiDetailsMessages.OneToOneMappingUiProvider_linkLabel);
+
+ // create One-to-One bidirectional relation from entity1 to entity2
+ editorProxy.testBiDirRelRemoveOwnerAttr(
+ JPAEditorMessages.CreateOneToOneBiDirRelationFeature_oneToOneBiDirFeatureName,
+ entity1, entity2, IRelation.RelType.ONE_TO_ONE,
+ JptUiDetailsMessages.OneToOneMappingUiProvider_linkLabel);
+
+ editorProxy.deleteDiagramElements();
+
+ jpaDiagramEditor.save();
+
+ Utils.sayTestFinished("testOneToOneBiDirRelationship");
+ }
+
+ /**
+ * Creates "One to One" bidirectional self relationship (from entity1 to
+ * entity1). Assert that the relation attributes exists. Delete the
+ * relationship and assert that the attributes do not exists anymore.
+ */
+ @Test
+ public void testSelfOneToOneBiDirRelationship() {
+ Utils.sayTestStarted("testSelfOneToOneBiDirRelationship");
+
+ SWTBotGefEditPart entity1 = editorProxy.addEntityToDiagram(50, 50, "Entity1");
+
+ // create One-to-One bidirectional self relation from entity1 to entity1
+ editorProxy.testSelfBiDirRel(
+ JPAEditorMessages.CreateOneToOneBiDirRelationFeature_oneToOneBiDirFeatureName,
+ entity1, IRelation.RelType.ONE_TO_ONE,
+ JptUiDetailsMessages.OneToOneMappingUiProvider_linkLabel);
+
+ editorProxy.deleteDiagramElements();
+
+ jpaDiagramEditor.save();
+
+ Utils.sayTestFinished("testSelfOneToOneBiDirRelationship");
+ }
+
+ /**
+ * Creates "One to Many" unidirectional relationship (from entity1 to
+ * entity2). Assert that the relation attributes exists. Delete the
+ * relationship and assert that the attributes do not exists anymore.
+ * Check that if the owner attribute will be deleted, the relationship will
+ * disappear.
+ */
+ @Test
+ public void testOneToManyUniDirRelationship() {
+ Utils.sayTestStarted("testOneToManyUniDirRelationship");
+
+ SWTBotGefEditPart entity1 = editorProxy.addEntityToDiagram(50, 50, "Entity1");
+ SWTBotGefEditPart entity2 = editorProxy.addEntityToDiagram(50, 200, "Entity2");
+
+ // create One-to-Many unidirectional relation from entity1 to entity2
+ editorProxy.testUniDirRelation(
+ JPAEditorMessages.CreateOneToManyUniDirRelationFeature_oneToManyUniDirFeatureName,
+ entity1, entity2, IRelation.RelType.ONE_TO_MANY,
+ JptUiDetailsMessages.OneToManyMappingUiProvider_linkLabel);
+
+ // create One-to-One bidirectional relation from entity1 to entity2
+ editorProxy.testUniDirRelRemoveOwnerAttribute(
+ JPAEditorMessages.CreateOneToManyUniDirRelationFeature_oneToManyUniDirFeatureName,
+ entity1, entity2, IRelation.RelType.ONE_TO_MANY,
+ JptUiDetailsMessages.OneToManyMappingUiProvider_linkLabel);
+
+ editorProxy.deleteDiagramElements();
+
+ jpaDiagramEditor.save();
+
+ Utils.sayTestFinished("testOneToManyUniDirRelationship");
+ }
+
+ /**
+ * Creates "One to Many" unidirectional self relationship (from entity1 to
+ * entity1). Assert that the relation attributes exists. Delete the
+ * relationship and assert that the attributes do not exists anymore.
+ */
+ @Test
+ public void testSelfOneToManyUniDirRelationship() {
+ Utils.sayTestStarted("testSelfOneToManyUniDirRelationship");
+
+ SWTBotGefEditPart entity1 = editorProxy.addEntityToDiagram(50, 50, "Entity1");
+
+ // create One-to-Many unidirectional self relation from entity1 to
+ // entity1
+
+ editorProxy.testSelfUniDirRelation(
+ JPAEditorMessages.CreateOneToManyUniDirRelationFeature_oneToManyUniDirFeatureName,
+ entity1, IRelation.RelType.ONE_TO_MANY,
+ JptUiDetailsMessages.OneToManyMappingUiProvider_linkLabel);
+
+ editorProxy.deleteDiagramElements();
+
+ jpaDiagramEditor.save();
+
+ Utils.sayTestFinished("testSelfOneToManyUniDirRelationship");
+ }
+
+ /**
+ * Creates "Many to One" unidirectional relationship (from entity1 to
+ * entity2). Assert that the relation attributes exists. Delete the
+ * relationship and assert that the attributes do not exists anymore.
+ * Check that if the owner attribute will be deleted, the relationship will
+ * disappear.
+ */
+ @Test
+ public void testManyToOneUniDirRelationship() {
+ Utils.sayTestStarted("testManyToOneUniDirRelationship");
+
+ SWTBotGefEditPart entity1 = editorProxy.addEntityToDiagram(50, 50, "Entity1");
+ SWTBotGefEditPart entity2 = editorProxy.addEntityToDiagram(50, 200, "Entity2");
+
+ // create Many-to-One unidirectional relation from entity1 to entity2
+ editorProxy.testUniDirRelation(
+ JPAEditorMessages.CreateManyToOneUniDirRelationFeature_manyToOneUniDirFeatureName,
+ entity1, entity2, IRelation.RelType.MANY_TO_ONE,
+ JptUiDetailsMessages.ManyToOneMappingUiProvider_linkLabel);
+
+ // create Many-to-One bidirectional relation from entity1 to entity2
+ editorProxy.testUniDirRelRemoveOwnerAttribute(
+ JPAEditorMessages.CreateManyToOneUniDirRelationFeature_manyToOneUniDirFeatureName,
+ entity1, entity2, IRelation.RelType.MANY_TO_ONE,
+ JptUiDetailsMessages.ManyToOneMappingUiProvider_linkLabel);
+
+ editorProxy.deleteDiagramElements();
+
+ jpaDiagramEditor.save();
+
+ Utils.sayTestFinished("testManyToOneUniDirRelationship");
+ }
+
+ /**
+ * Creates "Many to One" unidirectional self relationship (from entity1 to
+ * entity1). Assert that the relation attributes exists. Delete the
+ * relationship and assert that the attributes do not exists anymore.
+ */
+ @Test
+ public void testSelfManyToOneUniDirRelationship() {
+ Utils.sayTestStarted("testSelfManyToOneUniDirRelationship");
+
+ SWTBotGefEditPart entity1 = editorProxy.addEntityToDiagram(50, 50, "Entity1");
+
+ // create Many-to-One unidirectional self relation from entity1 to
+ // entity1
+ editorProxy.testSelfUniDirRelation(
+ JPAEditorMessages.CreateManyToOneUniDirRelationFeature_manyToOneUniDirFeatureName,
+ entity1, IRelation.RelType.MANY_TO_ONE,
+ JptUiDetailsMessages.ManyToOneMappingUiProvider_linkLabel);
+
+ editorProxy.deleteDiagramElements();
+
+ jpaDiagramEditor.save();
+
+ Utils.sayTestFinished("testSelfManyToOneUniDirRelationship");
+ }
+
+ /**
+ * Creates a "Many to One" bidirectional relationship (from entity1 to
+ * entity2). Assert that the relation attributes exists. Delete the
+ * relationship and assert that the attributes do not exists anymore.
+ * Check that if the inverse attribute will be deleted the
+ * connection will be transformed into many-to-one unidirectional
+ * relationship. Test that if the owner attribute will be deleted, the
+ * relationship will disappear.
+ */
+ @Test
+ public void testManyToOneBiDirRelationship() {
+ Utils.sayTestStarted("testManyToOneBiDirRelationship");
+
+ SWTBotGefEditPart entity1 = editorProxy.addEntityToDiagram(50, 50, "Entity1");
+ SWTBotGefEditPart entity2 = editorProxy.addEntityToDiagram(50, 200, "Entity2");
+
+ // create Many-to-One bidirectional relation from entity1 to entity2
+ editorProxy.testBiDirRelWithTwoMappingTypes(
+ JPAEditorMessages.CreateManyToOneBiDirRelationFeature_manyToOneBiDirFeatureName,
+ entity1, entity2, IRelation.RelType.MANY_TO_ONE,
+ JptUiDetailsMessages.ManyToOneMappingUiProvider_linkLabel,
+ JptUiDetailsMessages.OneToManyMappingUiProvider_linkLabel);
+
+ // create Many-to-One bidirectional relation from entity1 to entity2
+ editorProxy.testBiDirRelWithTwoMappingsWithoutInverseAttr(
+ JPAEditorMessages.CreateManyToOneBiDirRelationFeature_manyToOneBiDirFeatureName,
+ entity1, entity2, IRelation.RelType.MANY_TO_ONE,
+ JptUiDetailsMessages.ManyToOneMappingUiProvider_linkLabel,
+ JptUiDetailsMessages.OneToManyMappingUiProvider_linkLabel);
+
+ // create Many-to-One bidirectional relation from entity1 to entity2
+ editorProxy.testBiDirRelWithTwoMappingsWithoutOwnerAttr(
+ JPAEditorMessages.CreateManyToOneBiDirRelationFeature_manyToOneBiDirFeatureName,
+ entity1, entity2, IRelation.RelType.MANY_TO_ONE,
+ JptUiDetailsMessages.ManyToOneMappingUiProvider_linkLabel,
+ JptUiDetailsMessages.OneToManyMappingUiProvider_linkLabel);
+
+ editorProxy.deleteDiagramElements();
+
+ jpaDiagramEditor.save();
+
+ Utils.sayTestFinished("testManyToOneBiDirRelationship");
+ }
+
+ /**
+ * Creates a "Many to One" bidirectional self relationship (from entity1 to
+ * entity1). Assert that the relation attributes exists. Delete the
+ * relationship and assert that the attributes do not exists anymore.
+ */
+ @Test
+ public void testSelfManyToOneBiDirRelationship() {
+ Utils.sayTestStarted("testSelfManyToOneBiDirRelationship");
+
+ SWTBotGefEditPart entity1 = editorProxy.addEntityToDiagram(50, 50, "Entity1");
+
+ // create Many-to-Many bidirectional self relation from entity1 to
+ // entity1
+ editorProxy.testSelfBiDirRelWithTwoMappings(
+ JPAEditorMessages.CreateManyToOneBiDirRelationFeature_manyToOneBiDirFeatureName,
+ entity1, IRelation.RelType.MANY_TO_ONE,
+ JptUiDetailsMessages.ManyToOneMappingUiProvider_linkLabel,
+ JptUiDetailsMessages.OneToManyMappingUiProvider_linkLabel);
+
+ editorProxy.deleteDiagramElements();
+ jpaDiagramEditor.save();
+
+ Utils.sayTestFinished("testSelfManyToOneBiDirRelationship");
+ }
+
+ /**
+ * Creates "Many to Many" unidirectional relationship (from entity1 to
+ * entity2). Assert that the relation attributes exists. Delete the
+ * relationship and assert that the attributes do not exists anymore.
+ * Check that if the owner attribute will be deleted, the relationship will
+ * disappear.
+ */
+ @Test
+ public void testManyToManyUniDirRelationship() {
+ Utils.sayTestStarted("testManyToManyUniDirRelationship");
+
+ SWTBotGefEditPart entity1 = editorProxy.addEntityToDiagram(50, 50, "Entity1");
+ SWTBotGefEditPart entity2 = editorProxy.addEntityToDiagram(50, 200, "Entity2");
+
+ // create Many-to-Many unidirectional relation from entity1 to entity2
+ editorProxy.testUniDirRelation(
+ JPAEditorMessages.CreateManyToManyUniDirRelationFeature_manyToManyUniDirFeatureName,
+ entity1, entity2, IRelation.RelType.MANY_TO_MANY,
+ JptUiDetailsMessages.ManyToManyMappingUiProvider_linkLabel);
+
+ // create Many-to-Many bidirectional relation from entity1 to entity2
+ editorProxy.testUniDirRelRemoveOwnerAttribute(
+ JPAEditorMessages.CreateManyToManyUniDirRelationFeature_manyToManyUniDirFeatureName,
+ entity1, entity2, IRelation.RelType.MANY_TO_MANY,
+ JptUiDetailsMessages.ManyToManyMappingUiProvider_linkLabel);
+
+ editorProxy.deleteDiagramElements();
+
+ jpaDiagramEditor.save();
+
+ Utils.sayTestFinished("testManyToManyUniDirRelationship");
+ }
+
+ /**
+ * Creates "Many to Many" unidirectional self relationship (from entity1 to
+ * entity1). Assert that the relation attributes exists. Delete the
+ * relationship and assert that the attributes do not exists anymore.
+ */
+ @Test
+ public void testSelfManyToManyUniDirRelationship() {
+ Utils.sayTestStarted("testSelfManyToManyUniDirRelationship");
+
+ SWTBotGefEditPart entity1 = editorProxy.addEntityToDiagram(50, 50, "Entity1");
+
+ // create Many-to-Many unidirectional self relation from entity1 to
+ // entity1
+ editorProxy.testSelfUniDirRelation(
+ JPAEditorMessages.CreateManyToManyUniDirRelationFeature_manyToManyUniDirFeatureName,
+ entity1, IRelation.RelType.MANY_TO_MANY,
+ JptUiDetailsMessages.ManyToManyMappingUiProvider_linkLabel);
+
+ editorProxy.deleteDiagramElements();
+
+ jpaDiagramEditor.save();
+
+ Utils.sayTestFinished("testSelfManyToManyUniDirRelationship");
+ }
+
+ /**
+ * Creates a "Many to Many" bidirectional relationship (from entity1 to
+ * entity2). Assert that the relation attributes exists. Delete the
+ * relationship and assert that the attributes do not exists anymore.
+ * Check that if the inverse attribute will be deleted the
+ * connection will be transformed into many-to-many unidirectional
+ * relationship. Test that if the owner attribute will be deleted, the
+ * relationship will disappear.
+ */
+ @Test
+ public void testManyToManyBiDirRelationship() {
+ Utils.sayTestStarted("testManyToManyBiDirRelationship");
+
+ SWTBotGefEditPart entity1 = editorProxy.addEntityToDiagram(50, 50, "Entity1");
+ SWTBotGefEditPart entity2 = editorProxy.addEntityToDiagram(50, 200, "Entity2");
+
+ // create Many-to-Many bidirectional relation from entity1 to entity2
+ editorProxy.testBiDirRel(
+ JPAEditorMessages.CreateManyToManyBiDirRelationFeature_manyToManyBiDirFeatureName,
+ entity1, entity2, IRelation.RelType.MANY_TO_MANY,
+ JptUiDetailsMessages.ManyToManyMappingUiProvider_linkLabel);
+
+ // create Many-to-Many bidirectional relation from entity1 to entity2
+ editorProxy.testBiDirRelRemoveInverseAttribute(
+ JPAEditorMessages.CreateManyToManyBiDirRelationFeature_manyToManyBiDirFeatureName,
+ entity1, entity2, IRelation.RelType.MANY_TO_MANY,
+ JptUiDetailsMessages.ManyToManyMappingUiProvider_linkLabel);
+
+ // create Many-to-Many bidirectional relation from entity1 to entity2
+ editorProxy.testBiDirRelRemoveOwnerAttr(
+ JPAEditorMessages.CreateManyToManyBiDirRelationFeature_manyToManyBiDirFeatureName,
+ entity1, entity2, IRelation.RelType.MANY_TO_MANY,
+ JptUiDetailsMessages.ManyToManyMappingUiProvider_linkLabel);
+
+ editorProxy.deleteDiagramElements();
+
+ jpaDiagramEditor.save();
+
+ Utils.sayTestFinished("testManyToManyBiDirRelationship");
+ }
+
+ /**
+ * Creates a "Many to Many" bidirectional self relationship (from entity1 to
+ * entity1). Assert that the relation attributes exists. Delete the
+ * relationship and assert that the attributes do not exists anymore.
+ */
+ @Test
+ public void testSelfManyToManyBiDirRelationship() {
+ Utils.sayTestStarted("testSelfManyToManyBiDirRelationship");
+
+ SWTBotGefEditPart entity1 = editorProxy.addEntityToDiagram(50, 50, "Entity1");
+
+ // create Many-to-Many bidirectional self relation from entity1 to
+ // entity1
+ editorProxy.testSelfBiDirRel(
+ JPAEditorMessages.CreateManyToManyBiDirRelationFeature_manyToManyBiDirFeatureName,
+ entity1, IRelation.RelType.MANY_TO_MANY,
+ JptUiDetailsMessages.ManyToManyMappingUiProvider_linkLabel);
+
+ editorProxy.deleteDiagramElements();
+
+ jpaDiagramEditor.save();
+
+ Utils.sayTestFinished("testSelfManyToManyBiDirRelationship");
+ }
+
+ /**
+ * Creates a new Inherited entity by entity. Assert that the inherited
+ * entity does not contain a primary key.
+ */
+ @Test
+ public void testInheritedEntityByEntity() {
+ Utils.sayTestFinished("testInheritedEntityByEntity");
+
+ SWTBotGefEditPart entity1 = editorProxy.addEntityToDiagram(50, 50, "Entity1");
+
+ editorProxy.createInheritedEntity(entity1, "Entity2",
+ JptUiDetailsMessages.EntityUiProvider_linkLabel, false);
+
+ editorProxy.deleteDiagramElements();
+
+ jpaDiagramEditor.save();
+
+ Utils.sayTestFinished("testInheritedEntityByEntity");
+ }
+
+ /**
+ * Test that the JPA Diagram editor is opened when the context menu
+ * "JPA Tools -> Open Diagram" of the project is called.
+ */
+ @Test
+ public void testOpenDiagramOnProjectLevel() {
+ Utils.sayTestStarted("testOpenDiagramOnProjectLevel");
+
+ workbenchBot.closeAllEditors();
+ // open JPA diagram editor on project level: JPA Tools -> Open Diagram
+ SWTBotGefEditor diagramEditor = editorProxy
+ .openDiagramOnJPAProjectNode(TEST_PROJECT);
+ diagramEditor.close();
+
+ Utils.sayTestFinished("testOpenDiagramOnProjectLevel");
+ }
+
+ /**
+ * Test that the JPA Diagram editor is opened when the context menu
+ * "Open Diagram" of the JPA content node is called.
+ */
+ @Test
+ public void testOpenDiagramOnJPAContentNodeLevel() {
+ Utils.sayTestStarted("testOpenDiagramOnJPAContentNodeLevel");
+
+ workbenchBot.closeAllEditors();
+ // open JPA diagram editor on JPA content level: Open Diagram
+ SWTBotGefEditor diagramEditor = editorProxy
+ .openDiagramOnJPAContentNode(TEST_PROJECT, true);
+ diagramEditor.close();
+
+ Utils.sayTestFinished("testOpenDiagramOnJPAContentNodeLevel");
+ }
+
+ @AfterClass
+ public static void afterClass() throws CoreException{
+ IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
+ for(IProject project : projects){
+ project.delete(true, true, new NullProgressMonitor());
+ }
+
+ ResourcesPlugin.getWorkspace().getRoot().refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor());
+ }
+}
diff --git a/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.swtbot.tests/src/org/eclipse/jpt/jpadiagrameditor/swtbot/tests/ui/editor/JPADiagramEditorSWTBotTest.java b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.swtbot.tests/src/org/eclipse/jpt/jpadiagrameditor/swtbot/tests/ui/editor/JPADiagramEditorSWTBotTest.java
deleted file mode 100644
index d071966..0000000
--- a/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.swtbot.tests/src/org/eclipse/jpt/jpadiagrameditor/swtbot/tests/ui/editor/JPADiagramEditorSWTBotTest.java
+++ /dev/null
@@ -1,2466 +0,0 @@
-package org.eclipse.jpt.jpadiagrameditor.swtbot.tests.ui.editor;
-
-
-import static org.junit.Assert.assertFalse;
-
-import java.util.List;
-
-import org.eclipse.graphiti.features.IFeatureProvider;
-import org.eclipse.graphiti.mm.pictograms.FreeFormConnection;
-import org.eclipse.graphiti.mm.pictograms.PictogramElement;
-import org.eclipse.graphiti.ui.internal.parts.DiagramEditPart;
-import org.eclipse.jdt.core.JavaModelException;
-import org.eclipse.jpt.jpa.core.JpaProject;
-import org.eclipse.jpt.jpa.core.MappingKeys;
-import org.eclipse.jpt.jpa.core.context.MappingFile;
-import org.eclipse.jpt.jpadiagrameditor.swtbot.tests.internal.JPACreateFactory;
-import org.eclipse.jpt.jpadiagrameditor.swtbot.tests.internal.Utils;
-import org.eclipse.jpt.jpadiagrameditor.ui.internal.i18n.JPAEditorMessages;
-import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.IRelation;
-import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.IsARelation;
-import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JPAEditorConstants;
-import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JpaArtifactFactory;
-import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot;
-import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotEditor;
-import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView;
-import org.eclipse.swtbot.eclipse.gef.finder.SWTBotGefTestCase;
-import org.eclipse.swtbot.eclipse.gef.finder.SWTGefBot;
-import org.eclipse.swtbot.eclipse.gef.finder.widgets.SWTBotGefConnectionEditPart;
-import org.eclipse.swtbot.eclipse.gef.finder.widgets.SWTBotGefEditPart;
-import org.eclipse.swtbot.eclipse.gef.finder.widgets.SWTBotGefEditor;
-import org.eclipse.swtbot.swt.finder.SWTBot;
-import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner;
-import org.eclipse.swtbot.swt.finder.utils.SWTBotPreferences;
-import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell;
-import org.eclipse.swtbot.swt.finder.widgets.SWTBotStyledText;
-import org.eclipse.swtbot.swt.finder.widgets.SWTBotText;
-import org.junit.After;
-import org.junit.BeforeClass;
-import org.junit.Ignore;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-
-@RunWith(SWTBotJunit4ClassRunner.class)
-public class JPADiagramEditorSWTBotTest extends SWTBotGefTestCase {
-
- protected static String TEST_PROJECT;
- protected static JPACreateFactory factory = JPACreateFactory.instance();
- protected static JpaProject jpaProject;
-
- protected static SWTGefBot bot = new SWTGefBot();
- protected static SWTWorkbenchBot workbenchBot = new SWTWorkbenchBot();
- protected static EditorProxy editorProxy = new EditorProxy(workbenchBot, bot);
-
- protected static SWTBotGefEditor jpaDiagramEditor;
-
- @BeforeClass
- public static void beforeClass() throws Exception {
-
- SWTBotPreferences.TIMEOUT = 1000;
- try {
- bot.viewByTitle("Welcome").close();
- } catch (Exception e) {
- // ignore
- } finally {
- SWTBotPreferences.TIMEOUT = 5000;
- }
- workbenchBot.perspectiveByLabel("JPA").activate();
-
- TEST_PROJECT = "Test_" + System.currentTimeMillis();
-
- factory = JPACreateFactory.instance();
- jpaProject = factory.createJPA20Project(TEST_PROJECT);
- assertNotNull(jpaProject);
-
- jpaDiagramEditor = editorProxy.openDiagramOnJPAContentNode(TEST_PROJECT);
-
- Thread.sleep(2000);
- }
-
-// @After
-// public void tearDown() throws Exception {
-// editorProxy.deleteDiagramElements(jpaDiagramEditor);
-// }
-
- /**
- * Add entity to diagram and check that it contains a "Primary Key" section
- * with one attribute "id" and no "Relation Attributes" and "Other Attributes"
- * sections.
- */
- @Test
- public void testAddEntity() {
- Utils.sayTestStarted("testAddEntity");
-
- editorProxy.addEntityToDiagram(jpaDiagramEditor, 50, 50, "Entity1");
- assertTrue("Editor must be dirty", jpaDiagramEditor.isDirty());
-
- jpaDiagramEditor.save();
- assertFalse("Editor must not be dirty!", jpaDiagramEditor.isDirty());
-
- editorProxy.deleteDiagramElements(jpaDiagramEditor);
- jpaDiagramEditor.save();
-
- Utils.sayTestFinished("testAddEntity");
- }
-
- /**
- * Remove an entity from the diagram using the entity's context button "Delete"
- */
- @Test
- public void testRemoveEntityViaButton(){
- Utils.sayTestStarted("testRemoveEntityViaButton");
-
- SWTBotGefEditPart entity = editorProxy.addEntityToDiagram(jpaDiagramEditor, 50, 50, "Entity1");
-
- editorProxy.pressEntityContextButton(jpaDiagramEditor, entity, JPAEditorMessages.JPAEditorToolBehaviorProvider_deleteEntityFromModelButtonLabel);
- editorProxy.denyDelete();
- entity = jpaDiagramEditor.getEditPart("Entity1");
- assertNotNull("Entity is deleted!", entity);
-
- editorProxy.pressEntityContextButton(jpaDiagramEditor, entity, JPAEditorMessages.JPAEditorToolBehaviorProvider_deleteEntityFromModelButtonLabel);
- editorProxy.confirmDelete();
- entity = jpaDiagramEditor.getEditPart("Entity1");
- assertNull("Entity is not deleted!", entity);
-
- assertTrue("Editor must be dirty", jpaDiagramEditor.isDirty());
- jpaDiagramEditor.save();
-
- Utils.sayTestFinished("testRemoveEntityViaButton");
- }
-
- /**
- * Remove an entity from the diagram using the entity's context menu "Delete"
- */
- @Test
- public void testRemoveEntityViaContextMenu(){
- Utils.sayTestStarted("testRemoveEntityViaContextMenu");
-
- SWTBotGefEditPart entity = editorProxy.addEntityToDiagram(jpaDiagramEditor, 50, 50, "Entity1");
-
- jpaDiagramEditor.clickContextMenu(JPAEditorMessages.JPAEditorToolBehaviorProvider_deleteEntityFromModelButtonLabel);
- editorProxy.denyDelete();
- entity = jpaDiagramEditor.getEditPart("Entity1");
- assertNotNull("Entity is deleted!", entity);
-
- jpaDiagramEditor.clickContextMenu(JPAEditorMessages.JPAEditorToolBehaviorProvider_deleteEntityFromModelButtonLabel);
- editorProxy.confirmDelete();
- entity = jpaDiagramEditor.getEditPart("Entity1");
- assertNull("Entity is not deleted!", entity);
-
- assertTrue("Editor must be dirty", jpaDiagramEditor.isDirty());
- jpaDiagramEditor.save();
-
- Utils.sayTestFinished("testRemoveEntityViaContextMenu");
- }
-
- /**
- * Adds a new attribute to the entity using the entity's context button "Create Attribute"
- */
- @Test
- public void testAddAttribute(){
- Utils.sayTestStarted("testRemoveEntityViaContextMenu");
-
- SWTBotGefEditPart entity = editorProxy.addEntityToDiagram(jpaDiagramEditor, 50, 50, "Entity1");
-
- assertFalse("\"Other Attributes\" section must not be visible!", editorProxy.isSectionVisible(jpaDiagramEditor, JPAEditorMessages.AddJPAEntityFeature_basicAttributesShapes));
-
- editorProxy.addAttributeToEntity(jpaDiagramEditor, entity, "attribute1");
- assertTrue("Editor must be dirty", jpaDiagramEditor.isDirty());
-
- entity.click();
- editorProxy.deleteDiagramElements(jpaDiagramEditor);
- jpaDiagramEditor.save();
-
- Utils.sayTestFinished("testRemoveEntityViaContextMenu");
- }
-
- /**
- * Removes the attribute using the "Delete Attribute" context button.
- */
- @Test
- public void testRemoveAttributeViaContextButton(){
- Utils.sayTestStarted("testRemoveAttributeViaContextButton");
-
- SWTBotGefEditPart entity = editorProxy.addEntityToDiagram(jpaDiagramEditor, 50, 50, "Entity1");
- assertFalse("\"Other Attributes\" section must not be visible!", editorProxy.isSectionVisible(jpaDiagramEditor, JPAEditorMessages.AddJPAEntityFeature_basicAttributesShapes));
-
- SWTBotGefEditPart attribute = editorProxy.addAttributeToEntity(jpaDiagramEditor, entity, "attribute1");
- assertTrue("Editor must be dirty", jpaDiagramEditor.isDirty());
- jpaDiagramEditor.save();
-
- editorProxy.pressAttributeDeleteContextButton(jpaDiagramEditor, attribute);
- editorProxy.denyDelete();
- attribute = jpaDiagramEditor.getEditPart("attribute1");
- assertNotNull("Attribute must not be deleted!", attribute);
-
- editorProxy.pressAttributeDeleteContextButton(jpaDiagramEditor, attribute);
- editorProxy.confirmDelete();
- attribute = jpaDiagramEditor.getEditPart("attribute1");
- assertNull("Attribute must be deleted!", attribute);
-
- assertFalse("\"Other Attributes\" section must not be visible!", editorProxy.isSectionVisible(jpaDiagramEditor, JPAEditorMessages.AddJPAEntityFeature_basicAttributesShapes));
-
- entity.click();
- editorProxy.deleteDiagramElements(jpaDiagramEditor);
- jpaDiagramEditor.save();
-
- Utils.sayTestFinished("testRemoveAttributeViaContextButton");
- }
-
- /**
- * Removes the attribute using the "Delete" context menu.
- */
- @Test
- public void testRemoveAttributeViaMenu(){
- Utils.sayTestStarted("testRemoveAttributeViaMenu");
-
- SWTBotGefEditPart entity = editorProxy.addEntityToDiagram(jpaDiagramEditor, 50, 50, "Entity1");
-
- assertFalse("\"Other Attributes\" section must not be visible!", editorProxy.isSectionVisible(jpaDiagramEditor, JPAEditorMessages.AddJPAEntityFeature_basicAttributesShapes));
-
- SWTBotGefEditPart attribute = editorProxy.addAttributeToEntity(jpaDiagramEditor, entity, "attribute1");
- assertTrue("Editor must be dirty", jpaDiagramEditor.isDirty());
- jpaDiagramEditor.save();
-
- attribute.click();
- jpaDiagramEditor.clickContextMenu("Delete");
- editorProxy.denyDelete();
- attribute = jpaDiagramEditor.getEditPart("attribute1");
- assertNotNull("Attribute must not be deleted!", attribute);
-
- attribute.click();
- jpaDiagramEditor.clickContextMenu("Delete");
- editorProxy.confirmDelete();
- attribute = jpaDiagramEditor.getEditPart("attribute1");
- assertNull("Attribute must be deleted!", attribute);
-
- assertFalse("\"Other Attributes\" section must not be visible!", editorProxy.isSectionVisible(jpaDiagramEditor, JPAEditorMessages.AddJPAEntityFeature_basicAttributesShapes));
-
- entity.click();
- editorProxy.deleteDiagramElements(jpaDiagramEditor);
- jpaDiagramEditor.save();
-
- Utils.sayTestFinished("testRemoveAttributeViaMenu");
- }
-
- /**
- * Adds a new entity and rename it
- */
- @Ignore
- @Test
- public void testDirectEditingEntity(){
- Utils.sayTestStarted("testDirectEditingEntity");
-
- SWTBotGefEditPart entity = editorProxy.addEntityToDiagram(jpaDiagramEditor, 50, 50, "Entity1");
- assertTrue("Editor must be dirty", jpaDiagramEditor.isDirty());
-
- editorProxy.moveMouse(jpaDiagramEditor, 100, 70);
- entity.click();
- entity.activateDirectEdit();
- jpaDiagramEditor.directEditType("NewEntityName");
- editorProxy.moveMouse(jpaDiagramEditor, 0, 0);
-
- SWTBotGefEditPart oldEntity = jpaDiagramEditor.getEditPart("Entity1");
- SWTBotGefEditPart newEntity = jpaDiagramEditor.getEditPart("NewEntityName");
- assertNotNull("The entity must be renamed!", newEntity);
- assertNull("The attribute must be renamed!", oldEntity);
-
- assertTrue("Editor must be dirty", jpaDiagramEditor.isDirty());
-
- editorProxy.deleteDiagramElements(jpaDiagramEditor);
- jpaDiagramEditor.save();
-
- Utils.sayTestFinished("testDirectEditingEntity");
- }
-
- /**
- * Test that the source of the entity is opened, when is double clicked on it
- */
- @Ignore
- @Test
- public void testDoubleClickOnEntity(){
- Utils.sayTestStarted("testDoubleClickOnEntity");
-
- SWTBotGefEditPart entity = editorProxy.addEntityToDiagram(jpaDiagramEditor, 50, 50, "Entity1");
- assertTrue("Editor must be dirty", jpaDiagramEditor.isDirty());
- editorProxy.moveMouse(jpaDiagramEditor, 100, 70);
- jpaDiagramEditor.doubleClick(entity);
- editorProxy.moveMouse(jpaDiagramEditor, 0, 0);
-
- SWTBotEditor activeEditor = workbenchBot.activeEditor();
- assertEquals("The Java editor of the enity did not open!", "Entity1.java", activeEditor.getTitle());
- activeEditor.close();
-
- editorProxy.deleteDiagramElements(jpaDiagramEditor);
- jpaDiagramEditor.save();
-
- Utils.sayTestFinished("testDoubleClickOnEntity");
- }
-
- /**
- * Change the attribute type.
- */
- @Test
- @SuppressWarnings("restriction")
- public void testChangeAttributeType(){
- Utils.sayTestStarted("testChangeAttributeType");
-
- List<SWTBotGefEditPart> entities = jpaDiagramEditor.mainEditPart().children();
- assertTrue("Editor must not contain any entities!", entities.isEmpty());
-
- SWTBotGefEditPart entity = editorProxy.addEntityToDiagram(jpaDiagramEditor, 50, 50, "Entity1");
-
- assertFalse("\"Other Attributes\" section must not be visible!", editorProxy.isSectionVisible(jpaDiagramEditor, JPAEditorMessages.AddJPAEntityFeature_basicAttributesShapes));
-
- SWTBotGefEditPart attribute = editorProxy.addAttributeToEntity(jpaDiagramEditor, entity, "attribute1");
- assertNotNull("The attribute must not be renamed!", attribute);
- final IFeatureProvider fp = ((DiagramEditPart)jpaDiagramEditor.mainEditPart().part()).getFeatureProvider();
-
- String currentAttributeType = editorProxy.getAttributeType(jpaDiagramEditor, "attribute1", fp);
- assertEquals("java.lang.String", currentAttributeType);
-
- SWTBotShell changeTypeDialog = editorProxy.getSelectNewAttributeTypeDialog(jpaDiagramEditor, attribute);
- SWTBotText attributeType = editorProxy.getNewTypeInputField(changeTypeDialog);
-
- //test invalid attribute type
- attributeType.setText("");
- assertFalse(editorProxy.getOkButton(changeTypeDialog).isEnabled());
- assertTrue(editorProxy.getCancelButton(changeTypeDialog).isEnabled());
- SWTBotText dialogError = editorProxy.getDialogErroMessage(changeTypeDialog);
- assertEquals(" The new type name must not be empty", dialogError.getText());
- //cancel the dialog
- editorProxy.getCancelButton(changeTypeDialog).click();
-
- //assert that the attribute type is not changed
- currentAttributeType = editorProxy.getAttributeType(jpaDiagramEditor, "attribute1", fp);
- assertEquals("The attribute type must not be changed!", "java.lang.String", currentAttributeType);
-
- changeTypeDialog = editorProxy.getSelectNewAttributeTypeDialog(jpaDiagramEditor, attribute);
- attributeType = editorProxy.getNewTypeInputField(changeTypeDialog);
-
- //change the attribute type to int
- attributeType.setText("int");
- assertTrue(editorProxy.getOkButton(changeTypeDialog).isEnabled());
- assertTrue(editorProxy.getCancelButton(changeTypeDialog).isEnabled());
- //confirm the dialog
- editorProxy.getOkButton(changeTypeDialog).click();
- //assert that the attribute's type is changed
- String newAttributeType = currentAttributeType = editorProxy.getAttributeType(jpaDiagramEditor, "attribute1", fp);
- assertFalse("The attribute type must be changed!", ("java.lang.String").equals(newAttributeType));
- assertEquals("The attribute type must be changed!", "int", newAttributeType);
-
- assertTrue("Editor must be dirty!", jpaDiagramEditor.isDirty());
- entity.click();
- editorProxy.deleteDiagramElements(jpaDiagramEditor);
- jpaDiagramEditor.save();
-
- Utils.sayTestFinished("testChangeAttributeType");
- }
-
- /**
- * Rename the entity using its context menu "Refactor Entity Class -> Rename..."
- */
- @Ignore
- @Test
- public void testRenameEntityViaMenu(){
- Utils.sayTestStarted("testRenameEntityViaMenu");
-
- SWTBotGefEditPart entity = editorProxy.addEntityToDiagram(jpaDiagramEditor, 50, 50, "Entity1");
-
- entity.click();
- jpaDiagramEditor.clickContextMenu(JPAEditorMessages.JPAEditorToolBehaviorProvider_renameEntityClass);
-
- SWTBotShell renameEntityDialog = editorProxy.getRenameEntityDialog();
- SWTBotText entityName = renameEntityDialog.bot().textWithLabel("New name:");
-
- //test invalid entity name
- entityName.setText("");
- assertFalse(editorProxy.getFinishButton(renameEntityDialog).isEnabled());
- assertTrue(editorProxy.getCancelButton(renameEntityDialog).isEnabled());
-
- entityName.setText("NewEntityName");
- assertTrue(editorProxy.getFinishButton(renameEntityDialog).isEnabled());
- assertTrue(editorProxy.getCancelButton(renameEntityDialog).isEnabled());
-
- editorProxy.getFinishButton(renameEntityDialog).click();
- bot.waitUntil(new ElementIsShown(jpaDiagramEditor, "NewEntityName"), 30000);
-
- entity = jpaDiagramEditor.getEditPart("NewEntityName");
- assertNotNull("Entity name must be changed!", entity);
- assertNull("Entity naem must be changed!", jpaDiagramEditor.getEditPart("Entity1"));
-
- entity.click();
- editorProxy.deleteDiagramElements(jpaDiagramEditor);
- jpaDiagramEditor.save();
-
- Utils.sayTestFinished("testRenameEntityViaMenu");
- }
-
- /**
- * Move the entity class using the entity's context menu "Refactor Entity Class -> Move..."
- */
- @Ignore
- @Test
- public void testMoveEntityViaMenu() throws JavaModelException{
- Utils.sayTestStarted("testMoveEntityViaMenu");
-
- SWTBotGefEditPart entity = editorProxy.addEntityToDiagram(jpaDiagramEditor, 50, 50, "Entity1");
- JpaArtifactFactory factory = JpaArtifactFactory.instance();
-
- String packageName = factory.getMappedSuperclassPackageDeclaration(editorProxy.getEntityForElement(jpaDiagramEditor, entity));
-
- entity.click();
- jpaDiagramEditor.clickContextMenu(JPAEditorMessages.JPAEditorToolBehaviorProvider_moveEntityClass);
-
- SWTBotShell moveEntityDialog = editorProxy.getMoveEntityDialog();
- moveEntityDialog.bot().tree().getTreeItem(TEST_PROJECT).select().expandNode("src").expandNode("org").select().click();
- assertTrue(editorProxy.getOkButton(moveEntityDialog).isEnabled());
- editorProxy.getOkButton(moveEntityDialog).click();
- editorProxy.waitASecond();
-
- entity = jpaDiagramEditor.getEditPart("Entity1");
- String newEntityPackage= factory.getMappedSuperclassPackageDeclaration(editorProxy.getEntityForElement(jpaDiagramEditor, entity));
- assertFalse("Entity must be moved!", packageName.equals(newEntityPackage));
- assertTrue("Entity must be changed!", newEntityPackage.equals("org"));
-
- entity.click();
- editorProxy.deleteDiagramElements(jpaDiagramEditor);
- jpaDiagramEditor.save();
-
- Utils.sayTestFinished("testMoveEntityViaMenu");
- }
-
- /**
- * Collapse/expand entity using its context buttons
- */
- @Test
- public void testCollapseExapandEntityViaContextButton(){
- Utils.sayTestStarted("testCollapseExapandEntityViaContextButton");
-
- SWTBotGefEditPart entity = editorProxy.addEntityToDiagram(jpaDiagramEditor, 50, 50, "Entity1");
-
- int heigth = ((PictogramElement)entity.part().getModel()).getGraphicsAlgorithm().getHeight();
-
- editorProxy.pressEntityContextButton(jpaDiagramEditor, entity, "Collapse");
-
- entity = jpaDiagramEditor.getEditPart("Entity1");
- int newHeight = ((PictogramElement)entity.part().getModel()).getGraphicsAlgorithm().getHeight();
- assertEquals("Entity must be collapsed!", JPAEditorConstants.ENTITY_MIN_HEIGHT, newHeight);
- assertTrue(newHeight < heigth);
-
- editorProxy.pressEntityContextButton(jpaDiagramEditor, entity, "Expand");
- entity = jpaDiagramEditor.getEditPart("Entity1");