summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorShenxue Zhou2013-04-09 18:09:20 (EDT)
committerNeil Hauge2013-04-09 18:23:34 (EDT)
commitd692b2952c6cb5d339aac871455311934789dfc8 (patch)
tree0d7c6d6ca51c75f455cad7d4862dbc9110aee972
parenta95a5d592ad325352554f43ed43ebfd1f32ae31b (diff)
downloadwebtools.dali-d692b2952c6cb5d339aac871455311934789dfc8.zip
webtools.dali-d692b2952c6cb5d339aac871455311934789dfc8.tar.gz
webtools.dali-d692b2952c6cb5d339aac871455311934789dfc8.tar.bz2
399558 - Improve "Make Persistent" wizard to do attribute level
annotations. Contribution from Shenxue.
-rw-r--r--common/plugins/org.eclipse.jpt.common.core/META-INF/MANIFEST.MF1
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/META-INF/MANIFEST.MF1
-rw-r--r--jpa/features/org.eclipse.jpt.jpa.feature/feature.xml7
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.annotate/.classpath8
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.annotate/.gitignore1
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.annotate/.project28
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.annotate/.settings/org.eclipse.jdt.core.prefs11
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.annotate/META-INF/MANIFEST.MF21
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.annotate/about.html34
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.annotate/build.properties18
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.annotate/plugin.properties23
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.annotate/property_files/jpt_jpa_annotate.properties13
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.annotate/src/org/eclipse/jpt/jpa/annotate/DatabaseAnnotationNameBuilder.java108
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.annotate/src/org/eclipse/jpt/jpa/annotate/JavaClassAnnotater.java761
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.annotate/src/org/eclipse/jpt/jpa/annotate/JptJpaAnnotateMessages.java29
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.annotate/src/org/eclipse/jpt/jpa/annotate/internal/plugin/JptJpaAnnotatePlugin.java30
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.annotate/src/org/eclipse/jpt/jpa/annotate/mapping/AnnotationAttrConverter.java79
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.annotate/src/org/eclipse/jpt/jpa/annotate/mapping/AnnotationAttribute.java39
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.annotate/src/org/eclipse/jpt/jpa/annotate/mapping/AnnotationAttributeNames.java41
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.annotate/src/org/eclipse/jpt/jpa/annotate/mapping/AnnotationAttributes.java74
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.annotate/src/org/eclipse/jpt/jpa/annotate/mapping/BasicEntityPropertyElem.java61
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.annotate/src/org/eclipse/jpt/jpa/annotate/mapping/ColumnAttributes.java311
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.annotate/src/org/eclipse/jpt/jpa/annotate/mapping/EntityMappingsDoc.java97
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.annotate/src/org/eclipse/jpt/jpa/annotate/mapping/EntityPropertyElem.java180
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.annotate/src/org/eclipse/jpt/jpa/annotate/mapping/EntityRefPropertyElem.java282
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.annotate/src/org/eclipse/jpt/jpa/annotate/mapping/GeneratedValueAttributes.java58
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.annotate/src/org/eclipse/jpt/jpa/annotate/mapping/IdEntityPropertyElement.java45
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.annotate/src/org/eclipse/jpt/jpa/annotate/mapping/JavaMapper.java259
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.annotate/src/org/eclipse/jpt/jpa/annotate/mapping/JoinStrategy.java23
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.annotate/src/org/eclipse/jpt/jpa/annotate/mapping/JoinTableAttributes.java98
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.annotate/src/org/eclipse/jpt/jpa/annotate/mapping/TableAnnotationAttributes.java80
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.annotate/src/org/eclipse/jpt/jpa/annotate/util/AnnotateMappingUtil.java590
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.annotate/src/org/eclipse/jpt/jpa/annotate/util/DefaultTableUtil.java99
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/META-INF/MANIFEST.MF1
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/images/objects/key.gifbin0 -> 324 bytes
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/images/objects/list-of-values.pngbin0 -> 1072 bytes
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/plugin.properties6
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/plugin.xml2
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/property_files/jpt_jpa_ui_make_persistent.properties100
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/JptJpaUiImages.java4
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/handlers/MakePersistentHandler.java2
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/JpaMakePersistentWizard.java87
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/gen/DatabaseGroup.java2
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/makepersistent/AddJoinColumnDlg.java225
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/makepersistent/AssociationAnnotationWizard.java330
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/makepersistent/BasicAnnotationDialog.java167
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/makepersistent/ClassMappingPage.java532
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/makepersistent/DbColumnAnnotationCtl.java436
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/makepersistent/EntityMappingPage.java213
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/makepersistent/IdAnnotationDialog.java162
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/makepersistent/JavaClassMapping.java97
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/makepersistent/JoinColumnsAnnotationEditor.java461
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/makepersistent/JoinPropertiesPage.java195
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/makepersistent/JpaMakePersistentWizard.java201
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/makepersistent/JpaMakePersistentWizardPage.java (renamed from jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/JpaMakePersistentWizardPage.java)300
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/makepersistent/JptJpaUiMakePersistentMessages.java118
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/makepersistent/ManyToManyJoinPropsPage.java232
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/makepersistent/ManyToManyMappingPage.java28
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/makepersistent/ManyToOneJoinPropsPage.java285
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/makepersistent/ManyToOneMappingPage.java35
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/makepersistent/MappingAnnotationCtl.java163
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/makepersistent/OneToManyJoinPropsPage.java387
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/makepersistent/OneToManyMappingPage.java35
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/makepersistent/OneToOneJoinPropsPage.java415
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/makepersistent/OneToOneMappingPage.java36
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/makepersistent/OrmUiUtil.java69
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/makepersistent/PropsMappingPage.java612
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/makepersistent/SelectCascadeDialog.java159
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/makepersistent/SelectColumnDialog.java67
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/makepersistent/SelectOrderByDialog.java508
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/makepersistent/SelectPropertyDialog.java104
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/makepersistent/SelectTableDialog.java76
72 files changed, 10140 insertions, 222 deletions
diff --git a/common/plugins/org.eclipse.jpt.common.core/META-INF/MANIFEST.MF b/common/plugins/org.eclipse.jpt.common.core/META-INF/MANIFEST.MF
index b05f21f..68d8d4b 100644
--- a/common/plugins/org.eclipse.jpt.common.core/META-INF/MANIFEST.MF
+++ b/common/plugins/org.eclipse.jpt.common.core/META-INF/MANIFEST.MF
@@ -55,6 +55,7 @@ Export-Package: org.eclipse.jpt.common.core,
org.eclipse.jpt.jpa.db,
org.eclipse.jpt.jpa.db.ui,
org.eclipse.jpt.jpa.gen,
+ org.eclipse.jpt.jpa.annotate,
org.eclipse.jpt.jpa.ui",
org.eclipse.jpt.common.core.internal.utility.command;x-friends:="org.eclipse.jpt.jaxb.core,org.eclipse.jpt.jpa.core",
org.eclipse.jpt.common.core.internal.utility.jdt;x-friends:="org.eclipse.jpt.jaxb.core,org.eclipse.jpt.jpa.core",
diff --git a/common/plugins/org.eclipse.jpt.common.utility/META-INF/MANIFEST.MF b/common/plugins/org.eclipse.jpt.common.utility/META-INF/MANIFEST.MF
index e802afa..08a9cff 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/META-INF/MANIFEST.MF
+++ b/common/plugins/org.eclipse.jpt.common.utility/META-INF/MANIFEST.MF
@@ -22,6 +22,7 @@ Export-Package: org.eclipse.jpt.common.utility,
org.eclipse.jpt.jpa.db,
org.eclipse.jpt.jpa.db.ui,
org.eclipse.jpt.jpa.gen,
+ org.eclipse.jpt.jpa.annotate,
org.eclipse.jpt.jpa.ui",
org.eclipse.jpt.common.utility.internal.collection;
x-friends:="org.eclipse.jpt.jpa.core,
diff --git a/jpa/features/org.eclipse.jpt.jpa.feature/feature.xml b/jpa/features/org.eclipse.jpt.jpa.feature/feature.xml
index fa74e73..b19af4a 100644
--- a/jpa/features/org.eclipse.jpt.jpa.feature/feature.xml
+++ b/jpa/features/org.eclipse.jpt.jpa.feature/feature.xml
@@ -35,6 +35,13 @@
unpack="false"/>
<plugin
+ id="org.eclipse.jpt.jpa.annotate"
+ download-size="0"
+ install-size="0"
+ version="0.0.0"
+ unpack="false"/>
+
+ <plugin
id="org.eclipse.jpt.jpa.core"
download-size="0"
install-size="0"
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.annotate/.classpath b/jpa/plugins/org.eclipse.jpt.jpa.annotate/.classpath
new file mode 100644
index 0000000..a1d4f10
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.jpa.annotate/.classpath
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="src" path="property_files"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.annotate/.gitignore b/jpa/plugins/org.eclipse.jpt.jpa.annotate/.gitignore
new file mode 100644
index 0000000..e7bff1c
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.jpa.annotate/.gitignore
@@ -0,0 +1 @@
+/bin
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.annotate/.project b/jpa/plugins/org.eclipse.jpt.jpa.annotate/.project
new file mode 100644
index 0000000..9a6ccb1
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.jpa.annotate/.project
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.eclipse.jpt.jpa.annotate</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.ManifestBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.SchemaBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.annotate/.settings/org.eclipse.jdt.core.prefs b/jpa/plugins/org.eclipse.jpt.jpa.annotate/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 0000000..416f4fb
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.jpa.annotate/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,11 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.compiler.compliance=1.5
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate
+org.eclipse.jdt.core.compiler.debug.localVariable=generate
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.5
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.annotate/META-INF/MANIFEST.MF b/jpa/plugins/org.eclipse.jpt.jpa.annotate/META-INF/MANIFEST.MF
new file mode 100644
index 0000000..b2a4d0e
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.jpa.annotate/META-INF/MANIFEST.MF
@@ -0,0 +1,21 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: %pluginName
+Bundle-Vendor: %providerName
+Bundle-Version: 1.0.0.qualifier
+Bundle-SymbolicName: org.eclipse.jpt.jpa.annotate;singleton:=true
+Bundle-Activator: org.eclipse.jpt.jpa.annotate.internal.plugin.JptJpaAnnotatePlugin
+Bundle-ActivationPolicy: lazy
+Bundle-ClassPath: .
+Bundle-Localization: plugin
+Bundle-RequiredExecutionEnvironment: J2SE-1.5
+Require-Bundle: org.eclipse.jdt.core,
+ org.eclipse.core.resources,
+ org.eclipse.core.runtime,
+ org.eclipse.jpt.jpa.db,
+ org.eclipse.jpt.jpa.core,
+ org.eclipse.jpt.common.core,
+ org.eclipse.jpt.common.utility
+Export-Package: org.eclipse.jpt.jpa.annotate,
+ org.eclipse.jpt.jpa.annotate.mapping,
+ org.eclipse.jpt.jpa.annotate.util
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.annotate/about.html b/jpa/plugins/org.eclipse.jpt.jpa.annotate/about.html
new file mode 100644
index 0000000..be534ba
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.jpa.annotate/about.html
@@ -0,0 +1,34 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN">
+<HTML>
+
+<head>
+<title>About</title>
+<meta http-equiv=Content-Type content="text/html; charset=ISO-8859-1">
+</head>
+
+<BODY lang="EN-US">
+
+<H3>About This Content</H3>
+
+<P>May 02, 2008</P>
+
+<H3>License</H3>
+
+<P>The Eclipse Foundation makes available all content in this plug-in
+("Content"). Unless otherwise indicated below, the Content is provided to you
+under the terms and conditions of the Eclipse Public License Version 1.0
+("EPL"). A copy of the EPL is available at
+<A href="http://www.eclipse.org/org/documents/epl-v10.php">http://www.eclipse.org/org/documents/epl-v10.php</A>.
+For purposes of the EPL, "Program" will mean the Content.</P>
+
+<P>If you did not receive this Content directly from the Eclipse Foundation, the
+Content is being redistributed by another party ("Redistributor") and different
+terms and conditions may apply to your use of any object code in the Content.
+Check the Redistributor's license that was provided with the Content. If no such
+license exists, contact the Redistributor. Unless otherwise indicated below, the
+terms and conditions of the EPL still apply to any source code in the Content
+and such source code may be obtained at
+<A href="http://www.eclipse.org/">http://www.eclipse.org/</A>.</P>
+
+</BODY>
+</HTML>
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.annotate/build.properties b/jpa/plugins/org.eclipse.jpt.jpa.annotate/build.properties
new file mode 100644
index 0000000..47a1b39
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.jpa.annotate/build.properties
@@ -0,0 +1,18 @@
+################################################################################
+# Copyright (c) 2013 Oracle. All rights reserved.
+# This program and the accompanying materials are made available under the
+# terms of the Eclipse Public License v1.0, which accompanies this distribution
+# and is available at http://www.eclipse.org/legal/epl-v10.html.
+#
+# Contributors:
+# Oracle - initial API and implementation
+################################################################################
+
+source.. = src/,\
+ property_files/
+output.. = bin/
+bin.includes = META-INF/,\
+ .,\
+ about.html,\
+ plugin.properties
+jars.compile.order = .
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.annotate/plugin.properties b/jpa/plugins/org.eclipse.jpt.jpa.annotate/plugin.properties
new file mode 100644
index 0000000..f528a37
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.jpa.annotate/plugin.properties
@@ -0,0 +1,23 @@
+################################################################################
+# Copyright (c) 2013 Oracle. All rights reserved.
+# This program and the accompanying materials are made available under the
+# terms of the Eclipse Public License v1.0, which accompanies this distribution
+# and is available at http://www.eclipse.org/legal/epl-v10.html.
+#
+# Contributors:
+# Oracle - initial API and implementation
+################################################################################
+# ====================================================================
+# To code developer:
+# Do NOT change the properties between this line and the
+# "%%% END OF TRANSLATED PROPERTIES %%%" line.
+# Make a new property name, append to the end of the file and change
+# the code to use the new property.
+# ====================================================================
+
+# ====================================================================
+# %%% END OF TRANSLATED PROPERTIES %%%
+# ====================================================================
+
+pluginName = Dali Java Persistence Tools - Annotate
+providerName = Eclipse Web Tools Platform
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.annotate/property_files/jpt_jpa_annotate.properties b/jpa/plugins/org.eclipse.jpt.jpa.annotate/property_files/jpt_jpa_annotate.properties
new file mode 100644
index 0000000..12711c4
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.jpa.annotate/property_files/jpt_jpa_annotate.properties
@@ -0,0 +1,13 @@
+################################################################################
+# Copyright (c) 2013 Oracle. All rights reserved.
+# This program and the accompanying materials are made available under the
+# terms of the Eclipse Public License v1.0, which accompanies this distribution
+# and is available at http://www.eclipse.org/legal/epl-v10.html.
+#
+# Contributors:
+# Oracle - initial API and implementation
+################################################################################
+
+# JptJpaAnnotateMessages
+
+ANNOTATE_JAVA_CLASS=Annotate Java Class Attributes... \ No newline at end of file
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.annotate/src/org/eclipse/jpt/jpa/annotate/DatabaseAnnotationNameBuilder.java b/jpa/plugins/org.eclipse.jpt.jpa.annotate/src/org/eclipse/jpt/jpa/annotate/DatabaseAnnotationNameBuilder.java
new file mode 100644
index 0000000..074410b
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.jpa.annotate/src/org/eclipse/jpt/jpa/annotate/DatabaseAnnotationNameBuilder.java
@@ -0,0 +1,108 @@
+/*******************************************************************************
+ * Copyright (c) 2007, 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.jpa.annotate;
+
+import org.eclipse.jpt.common.utility.internal.ObjectTools;
+import org.eclipse.jpt.jpa.db.Column;
+import org.eclipse.jpt.jpa.db.ForeignKey;
+import org.eclipse.jpt.jpa.db.Table;
+
+
+/**
+ * Provide a pluggable way to determine whether and how the entity generator
+ * prints the names of various database objects.
+ */
+public interface DatabaseAnnotationNameBuilder {
+
+ /**
+ * Given the name of an entity and the table to which it is mapped,
+ * build and return a string to be used as the value for the entity's
+ * Table annotation's 'name' element. Return null if the entity
+ * maps to the table by default.
+ */
+ String buildTableAnnotationName(String entityName, Table table);
+
+ /**
+ * Given the name of an attribute (field or property) and the column
+ * to which it is mapped,
+ * build and return a string to be used as the value for the attribute's
+ * Column annotation's 'name' element. Return null if the attribute
+ * maps to the column by default.
+ */
+ String buildColumnAnnotationName(String attributeName, Column column);
+
+ /**
+ * Given the name of an attribute (field or property) and the
+ * many-to-one or many-to-many foreign key to which it is mapped,
+ * build and return a string to be used as the value for the attribute's
+ * JoinColumn annotation's 'name' element. Return null if the attribute
+ * maps to the join column by default.
+ * The specified foreign key consists of a single column pair whose
+ * referenced column is the single-column primary key of the foreign
+ * key's referenced table.
+ */
+ String buildJoinColumnAnnotationName(String attributeName, ForeignKey foreignKey);
+
+ /**
+ * Build and return a string to be used as the value for a JoinColumn
+ * annotation's 'name' or 'referencedColumnName' element.
+ * This is called for many-to-one and many-to-many mappings when
+ * the default join column name and/or referenced column name are/is
+ * not applicable.
+ * @see #buildJoinColumnAnnotationName(String, ForeignKey)
+ */
+ String buildJoinColumnAnnotationName(Column column);
+
+ /**
+ * Build and return a string to be used as the value for a JoinTable
+ * annotation's 'name' element.
+ * This is called for many-to-many mappings when the default
+ * join table name is not applicable.
+ */
+ String buildJoinTableAnnotationName(Table table);
+
+
+ /**
+ * The default implementation simple returns the database object's name,
+ * unaltered.
+ */
+ final class Default
+ implements DatabaseAnnotationNameBuilder
+ {
+ public static final DatabaseAnnotationNameBuilder INSTANCE = new Default();
+ public static DatabaseAnnotationNameBuilder instance() {
+ return INSTANCE;
+ }
+ // ensure single instance
+ private Default() {
+ super();
+ }
+ public String buildTableAnnotationName(String entityName, Table table) {
+ return table.getName();
+ }
+ public String buildColumnAnnotationName(String attributeName, Column column) {
+ return column.getName();
+ }
+ public String buildJoinColumnAnnotationName(String attributeName, ForeignKey foreignKey) {
+ return foreignKey.getColumnPair().getBaseColumn().getName();
+ }
+ public String buildJoinColumnAnnotationName(Column column) {
+ return column.getName();
+ }
+ public String buildJoinTableAnnotationName(Table table) {
+ return table.getName();
+ }
+ @Override
+ public String toString() {
+ return ObjectTools.singletonToString(this);
+ }
+ }
+
+}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.annotate/src/org/eclipse/jpt/jpa/annotate/JavaClassAnnotater.java b/jpa/plugins/org.eclipse.jpt.jpa.annotate/src/org/eclipse/jpt/jpa/annotate/JavaClassAnnotater.java
new file mode 100644
index 0000000..779bf16
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.jpa.annotate/src/org/eclipse/jpt/jpa/annotate/JavaClassAnnotater.java
@@ -0,0 +1,761 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+
+package org.eclipse.jpt.jpa.annotate;
+
+import java.util.Iterator;
+import java.util.List;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.SubMonitor;
+import org.eclipse.jpt.jpa.annotate.mapping.AnnotationAttributeNames;
+import org.eclipse.jpt.jpa.annotate.mapping.BasicEntityPropertyElem;
+import org.eclipse.jpt.jpa.annotate.mapping.ColumnAttributes;
+import org.eclipse.jpt.jpa.annotate.mapping.EntityMappingsDoc;
+import org.eclipse.jpt.jpa.annotate.mapping.EntityPropertyElem;
+import org.eclipse.jpt.jpa.annotate.mapping.EntityRefPropertyElem;
+import org.eclipse.jpt.jpa.annotate.mapping.GeneratedValueAttributes;
+import org.eclipse.jpt.jpa.annotate.mapping.IdEntityPropertyElement;
+import org.eclipse.jpt.jpa.annotate.mapping.JoinStrategy;
+import org.eclipse.jpt.jpa.annotate.mapping.JoinTableAttributes;
+import org.eclipse.jpt.jpa.core.MappingKeys;
+import org.eclipse.jpt.jpa.core.context.AttributeMapping;
+import org.eclipse.jpt.jpa.core.context.BasicMapping;
+import org.eclipse.jpt.jpa.core.context.Cascade;
+import org.eclipse.jpt.jpa.core.context.CollectionMapping;
+import org.eclipse.jpt.jpa.core.context.ColumnMapping;
+import org.eclipse.jpt.jpa.core.context.Entity;
+import org.eclipse.jpt.jpa.core.context.FetchType;
+import org.eclipse.jpt.jpa.core.context.GeneratedValue;
+import org.eclipse.jpt.jpa.core.context.GenerationType;
+import org.eclipse.jpt.jpa.core.context.IdMapping;
+import org.eclipse.jpt.jpa.core.context.ManyToManyMapping;
+import org.eclipse.jpt.jpa.core.context.ManyToOneMapping;
+import org.eclipse.jpt.jpa.core.context.ManyToOneRelationship;
+import org.eclipse.jpt.jpa.core.context.OneToManyMapping;
+import org.eclipse.jpt.jpa.core.context.OneToOneMapping;
+import org.eclipse.jpt.jpa.core.context.OneToOneRelationship;
+import org.eclipse.jpt.jpa.core.context.PersistentType;
+import org.eclipse.jpt.jpa.core.context.RelationshipMapping;
+import org.eclipse.jpt.jpa.core.context.SpecifiedColumn;
+import org.eclipse.jpt.jpa.core.context.SpecifiedJoinColumn;
+import org.eclipse.jpt.jpa.core.context.SpecifiedJoinColumnRelationshipStrategy;
+import org.eclipse.jpt.jpa.core.context.SpecifiedJoinTable;
+import org.eclipse.jpt.jpa.core.context.SpecifiedJoinTableRelationshipStrategy;
+import org.eclipse.jpt.jpa.core.context.SpecifiedMappedByRelationshipStrategy;
+import org.eclipse.jpt.jpa.core.context.SpecifiedPersistentAttribute;
+import org.eclipse.jpt.jpa.core.context.SpecifiedPrimaryKeyJoinColumn;
+import org.eclipse.jpt.jpa.core.context.SpecifiedPrimaryKeyJoinColumnRelationshipStrategy;
+import org.eclipse.jpt.jpa.core.jpa2.context.ManyToOneRelationship2_0;
+import org.eclipse.jpt.jpa.core.jpa2.context.OneToManyRelationship2_0;
+import org.eclipse.jpt.jpa.core.jpa2.context.OneToOneRelationship2_0;
+import org.eclipse.jpt.jpa.core.resource.orm.JPA;
+import org.eclipse.jpt.jpa.db.Column;
+import org.eclipse.jpt.jpa.db.ForeignKey;
+import org.eclipse.jpt.jpa.db.Schema;
+import org.eclipse.jpt.jpa.db.Table;
+
+public class JavaClassAnnotater
+{
+ private PersistentType persistentType;
+ private EntityMappingsDoc mappingDoc;
+ private DatabaseAnnotationNameBuilder databaseAnnotationNameBuilder = DatabaseAnnotationNameBuilder.Default.INSTANCE;
+ private Schema schema;
+ private Table table;
+
+ public JavaClassAnnotater(PersistentType persistentType, EntityMappingsDoc mappingDoc, Schema schema)
+ {
+ this.persistentType = persistentType;
+ this.mappingDoc = mappingDoc;
+ this.schema = schema;
+ if (mappingDoc.getTableAttrs().getTableName() != null)
+ {
+ this.table = this.schema.getTableNamed(mappingDoc.getTableAttrs().getTableName());
+ }
+ }
+
+ public void annotate(IProgressMonitor pm)
+ {
+ if (this.table != null)
+ {
+ SubMonitor sm = SubMonitor.convert(pm, mappingDoc.getEntityProperties().length + 1);
+ sm.setTaskName(JptJpaAnnotateMessages.ANNOTATE_JAVA_CLASS);
+ syncTableAnnotation();
+ sm.worked(1);
+ for (EntityPropertyElem entityPropertyElem : mappingDoc.getEntityProperties())
+ {
+ syncPropAnnotation(entityPropertyElem, entityPropertyElem.getPropertyName());
+ sm.worked(1);
+ }
+ }
+ }
+
+ public DatabaseAnnotationNameBuilder getDatabaseAnnotationNameBuilder()
+ {
+ return this.databaseAnnotationNameBuilder;
+ }
+
+ public void setDatabaseAnnotationNameBuilder(DatabaseAnnotationNameBuilder databaseAnnotationNameBuilder)
+ {
+ if (databaseAnnotationNameBuilder == null)
+ {
+ throw new NullPointerException("database annotation name builder is required"); //$NON-NLS-1$
+ }
+ this.databaseAnnotationNameBuilder = databaseAnnotationNameBuilder;
+ }
+
+ private void syncTableAnnotation()
+ {
+ Entity entity = (Entity)this.persistentType.getMapping();
+ String tableName = this.databaseAnnotationNameBuilder.buildTableAnnotationName(entity.getName(), table);
+ if (tableName != null)
+ {
+ entity.getTable().setSpecifiedName(tableName);
+ }
+ }
+
+ private void syncPropAnnotation(EntityPropertyElem propElem, String attributeName)
+ {
+ SpecifiedPersistentAttribute persistentAttribute = (SpecifiedPersistentAttribute)this.persistentType.getAttributeNamed(attributeName);
+ if (propElem == null || propElem.isUnmapped())
+ {
+ persistentAttribute.setMappingKey(null);
+ return;
+ }
+ String tagName = propElem.getTagName();
+ if (tagName.equals(JPA.BASIC))
+ {
+ syncBasicAnnotation(propElem, persistentAttribute);
+ }
+// else if (tagName.equals(JPA.EMBEDDED_TAG))
+// {
+// _annotations.deleteClassMemberAnnotations(methName, propName, AnnotationNames.getPropTypeAnnotationNames(AnnotationNames.EMBEDDED_ANNOTATION));
+// _annotations.ensureClassMemberAnnotation(methName, propName, AnnotationNames.EMBEDDED_ANNOTATION);
+// }
+// else if (tagName.equals(JPA.EMBEDDED_ID_TAG))
+// {
+// _annotations.deleteClassMemberAnnotations(methName, propName, AnnotationNames.getPropTypeAnnotationNames(AnnotationNames.EMBEDDED_ID_ANNOTATION));
+// _annotations.ensureClassMemberAnnotation(methName, propName, AnnotationNames.EMBEDDED_ID_ANNOTATION);
+// }
+ else if (tagName.equals(JPA.ID))
+ {
+ syncIdAnnotation(propElem, persistentAttribute);
+ }
+ else if (tagName.equals(JPA.MANY_TO_MANY))
+ {
+ syncManyToManyAnnotation(propElem, persistentAttribute);
+ }
+ else if (tagName.equals(JPA.MANY_TO_ONE))
+ {
+ syncManyToOneAnnotation(propElem, persistentAttribute);
+ }
+ else if (tagName.equals(JPA.ONE_TO_MANY))
+ {
+ syncOneToManyAnnotation(propElem, persistentAttribute);
+ }
+ else if (tagName.equals(JPA.ONE_TO_ONE))
+ {
+ syncOneToOneAnnotation(propElem, persistentAttribute);
+ }
+// else if (tagName.equals(JPA.VERSION_TAG))
+// {
+// syncVersionAnnotation(propElem, methName, propName);
+// }
+ }
+
+ private void syncBasicAnnotation(EntityPropertyElem propElem, SpecifiedPersistentAttribute persistentAttribute)
+ {
+ /*remove the conflicting annotations*/
+ // Since "Basic" is the default mapping, we can just clear the mapping annotation
+ AttributeMapping mapping = persistentAttribute.setMappingKey(null);
+ BasicMapping basicMapping = (BasicMapping)mapping;
+ assert propElem instanceof BasicEntityPropertyElem;
+ BasicEntityPropertyElem basicElem = (BasicEntityPropertyElem)propElem;
+ if (basicElem.getTemporalType() != null)
+ {
+ // TODO Set Temporal annotation
+ }
+
+ syncColumnAnnotation(propElem, basicMapping);
+ }
+
+ private void syncIdAnnotation(EntityPropertyElem propElem, SpecifiedPersistentAttribute persistentAttribute)
+ {
+ AttributeMapping mapping = persistentAttribute.setMappingKey(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY);
+ IdMapping idMapping = (IdMapping) mapping;
+
+ assert propElem instanceof IdEntityPropertyElement;
+ IdEntityPropertyElement idElem = (IdEntityPropertyElement)propElem;
+ GeneratedValueAttributes genAttrs = idElem.getGeneratedValueAttrs();
+ if (genAttrs != null)
+ {
+ GeneratedValue gv = idMapping.addGeneratedValue();
+ if (genAttrs.getStrategy() != null)
+ {
+ GenerationType type = getGenerationType(genAttrs.getStrategy());
+ if (type != null && type != gv.getDefaultStrategy())
+ {
+ gv.setSpecifiedStrategy(type);
+ }
+ }
+ if (genAttrs.getGenerator() != null && genAttrs.getGenerator().equals(gv.getDefaultGenerator()))
+ {
+ gv.setSpecifiedGenerator(genAttrs.getGenerator());
+ }
+ }
+
+ syncColumnAnnotation(propElem, idMapping);
+ }
+
+ private void syncColumnAnnotation(EntityPropertyElem propElem, ColumnMapping columnMapping)
+ {
+ ColumnAttributes colAttrs = propElem.getColumnAnnotationAttrs();
+ SpecifiedColumn column = columnMapping.getColumn();
+ if (propElem.getDBColumn() != null)
+ {
+ Column dbColumn = propElem.getDBColumn();
+ String colName = this.databaseAnnotationNameBuilder.buildColumnAnnotationName(propElem.getPropertyName(), dbColumn);
+ // Setting col name, unique, nullable, length, precision, scale, insertable, updatable
+ // only when it's not the default mapping.
+ if (colName != null)
+ {
+ // Column Name
+ column.setSpecifiedName(colName);
+ // Unique
+ if (colAttrs.isSetUnique() && colAttrs.isUnique())
+ {
+ column.setSpecifiedUnique(colAttrs.isUnique());
+ }
+ // Nullable
+ if (colAttrs.isSetNullable() && !colAttrs.isNullable())
+ {
+ column.setSpecifiedNullable(colAttrs.isNullable());
+ }
+ //Length
+ if (colAttrs.isSetLength() && colAttrs.getLength() != column.getDefaultLength())
+ {
+ column.setSpecifiedLength(colAttrs.getLength());
+ }
+ // Precision
+ if (colAttrs.isSetPrecision() && colAttrs.getPrecision() != column.getDefaultPrecision())
+ {
+ column.setSpecifiedPrecision(colAttrs.getPrecision());
+ }
+ // Scale
+ if (colAttrs.isSetScale() && colAttrs.getScale() != column.getDefaultScale())
+ {
+ column.setSpecifiedScale(colAttrs.getScale());
+ }
+ // Insertable
+ if (colAttrs.isSetInsertable() && !colAttrs.isInsertable())
+ {
+ column.setSpecifiedInsertable(colAttrs.isInsertable());
+ }
+ // Updatable
+ if (colAttrs.isSetUpdatable() && !colAttrs.isUpdatable())
+ {
+ column.setSpecifiedUpdatable(colAttrs.isUpdatable());
+ }
+ }
+ }
+ // ColumnDefinition
+ if (colAttrs != null && colAttrs.getColumnDefinition() != null)
+ {
+ column.setColumnDefinition(colAttrs.getColumnDefinition());
+ }
+ }
+
+ private void syncManyToOneAnnotation(EntityPropertyElem propElem, SpecifiedPersistentAttribute persistentAttribute)
+ {
+ assert propElem instanceof EntityRefPropertyElem;
+ EntityRefPropertyElem refPropElem = (EntityRefPropertyElem)propElem;
+
+ AttributeMapping mapping = persistentAttribute.setMappingKey(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY);
+ ManyToOneMapping mtoMapping = (ManyToOneMapping)mapping;
+
+ // Target Entity
+ if (refPropElem.getRefEntityClassName() != null &&
+ !refPropElem.getRefEntityClassName().equals(mtoMapping.getDefaultTargetEntity()))
+ {
+ mtoMapping.setSpecifiedTargetEntity(refPropElem.getRefEntityClassName());
+ }
+
+ // Fetch
+ if (propElem.getAnnotationAttribute(AnnotationAttributeNames.FETCH) != null)
+ {
+ FetchType fetchType = getFetchType(propElem.getAnnotationAttribute(AnnotationAttributeNames.FETCH).attrValue);
+ if (fetchType != null && fetchType != mtoMapping.getDefaultFetch())
+ {
+ mtoMapping.setSpecifiedFetch(fetchType);
+ }
+ }
+
+ // Cascade
+ syncCascadeMember(mtoMapping, refPropElem);
+
+ if (!isJpa1_0Project() && refPropElem.getJoinTable() != null)
+ {
+ ManyToOneRelationship relation = mtoMapping.getRelationship();
+ ManyToOneRelationship2_0 relation2 = (ManyToOneRelationship2_0)relation;
+ relation2.setStrategyToJoinTable();
+ SpecifiedJoinTableRelationshipStrategy joinTableStrategy = relation2.getJoinTableStrategy();
+ syncJoinTableAnnotation(refPropElem, joinTableStrategy);
+ }
+ else if (!refPropElem.getJoinColumns().isEmpty())
+ {
+ mtoMapping.getRelationship().setStrategyToJoinColumn();
+ SpecifiedJoinColumnRelationshipStrategy joinColumnStrategy = mtoMapping.getRelationship().getJoinColumnStrategy();
+ syncJoinColumnsAnnotations(refPropElem.getDBTable(), refPropElem.getReferencedTable(),
+ refPropElem.getPropertyName(), refPropElem.getJoinColumns(), joinColumnStrategy);
+ }
+ }
+
+ private void syncOneToManyAnnotation(EntityPropertyElem propElem, SpecifiedPersistentAttribute persistentAttribute)
+ {
+ assert propElem instanceof EntityRefPropertyElem;
+ EntityRefPropertyElem refPropElem = (EntityRefPropertyElem)propElem;
+
+ AttributeMapping mapping = persistentAttribute.setMappingKey(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY);
+ OneToManyMapping otmMapping = (OneToManyMapping)mapping;
+
+ // Target Entity
+ if (refPropElem.getRefEntityClassName() != null &&
+ !refPropElem.getRefEntityClassName().equals(otmMapping.getDefaultTargetEntity()))
+ {
+ otmMapping.setSpecifiedTargetEntity(refPropElem.getRefEntityClassName());
+ }
+
+ // Fetch
+ if (propElem.getAnnotationAttribute(AnnotationAttributeNames.FETCH) != null)
+ {
+ FetchType fetchType = getFetchType(propElem.getAnnotationAttribute(AnnotationAttributeNames.FETCH).attrValue);
+ if (fetchType != null && fetchType != otmMapping.getDefaultFetch())
+ {
+ otmMapping.setSpecifiedFetch(fetchType);
+ }
+ }
+
+ // Cascade
+ syncCascadeMember(otmMapping, refPropElem);
+
+ syncToManyAnnotations(propElem, otmMapping);
+
+ if (propElem.getAnnotationAttribute(AnnotationAttributeNames.MAPPEDBY) != null)
+ {
+ // Mapped by
+ otmMapping.getRelationship().setStrategyToMappedBy();
+ SpecifiedMappedByRelationshipStrategy mappedByStrategy = otmMapping.getRelationship().getMappedByStrategy();
+ mappedByStrategy.setMappedByAttribute(propElem.getAnnotationAttribute(AnnotationAttributeNames.MAPPEDBY).attrValue);
+ }
+ else if (refPropElem.getJoinTable() != null)
+ {
+ // Join Table
+ otmMapping.getRelationship().setStrategyToJoinTable();
+ SpecifiedJoinTableRelationshipStrategy joinTableStrategy = otmMapping.getRelationship().getJoinTableStrategy();
+ syncJoinTableAnnotation(refPropElem, joinTableStrategy);
+ }
+ else if (!isJpa1_0Project() && !refPropElem.getJoinColumns().isEmpty())
+ {
+ // Join columns
+ SpecifiedJoinColumnRelationshipStrategy joinColumnStrategy = null;
+ if (otmMapping.getRelationship() instanceof OneToManyRelationship2_0)
+ {
+ OneToManyRelationship2_0 relation2_0 = (OneToManyRelationship2_0)otmMapping.getRelationship();
+ relation2_0.setStrategyToJoinColumn();
+ joinColumnStrategy = relation2_0.getJoinColumnStrategy();
+ }
+ if (joinColumnStrategy != null)
+ {
+ syncJoinColumnsAnnotations(refPropElem.getDBTable(), refPropElem.getReferencedTable(),
+ refPropElem.getPropertyName(), refPropElem.getJoinColumns(), joinColumnStrategy);
+ }
+ }
+ }
+
+ private void syncOneToOneAnnotation(EntityPropertyElem propElem, SpecifiedPersistentAttribute persistentAttribute)
+ {
+ assert propElem instanceof EntityRefPropertyElem;
+ EntityRefPropertyElem refPropElem = (EntityRefPropertyElem)propElem;
+ AttributeMapping mapping = persistentAttribute.setMappingKey(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY);
+ OneToOneMapping otoMapping = (OneToOneMapping)mapping;
+
+ // Target Entity
+ if (refPropElem.getRefEntityClassName() != null &&
+ !refPropElem.getRefEntityClassName().equals(otoMapping.getDefaultTargetEntity()))
+ {
+ otoMapping.setSpecifiedTargetEntity(refPropElem.getRefEntityClassName());
+ }
+
+ // Fetch
+ if (propElem.getAnnotationAttribute(AnnotationAttributeNames.FETCH) != null)
+ {
+ FetchType fetchType = getFetchType(propElem.getAnnotationAttribute(AnnotationAttributeNames.FETCH).attrValue);
+ if (fetchType != null && fetchType != otoMapping.getDefaultFetch())
+ {
+ otoMapping.setSpecifiedFetch(fetchType);
+ }
+ }
+
+ // Cascade
+ syncCascadeMember(otoMapping, refPropElem);
+
+ if (propElem.getAnnotationAttribute(AnnotationAttributeNames.MAPPEDBY) != null)
+ {
+ // Mapped by
+ otoMapping.getRelationship().setStrategyToMappedBy();
+ SpecifiedMappedByRelationshipStrategy mappedByStrategy = otoMapping.getRelationship().getMappedByStrategy();
+ mappedByStrategy.setMappedByAttribute(propElem.getAnnotationAttribute(AnnotationAttributeNames.MAPPEDBY).attrValue);
+ }
+ else if (!refPropElem.getJoinColumns().isEmpty())
+ {
+ // Join columns
+ otoMapping.getRelationship().setStrategyToJoinColumn();
+ SpecifiedJoinColumnRelationshipStrategy joinColumnStrategy = otoMapping.getRelationship().getJoinColumnStrategy();
+ syncJoinColumnsAnnotations(refPropElem.getDBTable(), refPropElem.getReferencedTable(),
+ refPropElem.getPropertyName(), refPropElem.getJoinColumns(), joinColumnStrategy);
+ }
+ else if (refPropElem.getJoinStrategy() == JoinStrategy.PRIMARY_KEY_JOIN_COLUMNS)
+ {
+ // Primary Key Join Columns
+ otoMapping.getRelationship().setStrategyToPrimaryKeyJoinColumn();
+ SpecifiedPrimaryKeyJoinColumnRelationshipStrategy pkJoinStrategy = otoMapping.getRelationship().getPrimaryKeyJoinColumnStrategy();
+ syncPkJoinColumnAnnotations(refPropElem.getPkJoinColumns(), pkJoinStrategy);
+ }
+ else if (!isJpa1_0Project() && refPropElem.getJoinTable() != null)
+ {
+ // Join table
+ OneToOneRelationship relation = otoMapping.getRelationship();
+ OneToOneRelationship2_0 relation2 = (OneToOneRelationship2_0)relation;
+ relation2.setStrategyToJoinTable();
+ SpecifiedJoinTableRelationshipStrategy joinTableStrategy = relation2.getJoinTableStrategy();
+ syncJoinTableAnnotation(refPropElem, joinTableStrategy);
+ }
+ }
+
+ private void syncManyToManyAnnotation(EntityPropertyElem propElem, SpecifiedPersistentAttribute persistentAttribute)
+ {
+ assert propElem instanceof EntityRefPropertyElem;
+ EntityRefPropertyElem refPropElem = (EntityRefPropertyElem)propElem;
+ AttributeMapping mapping = persistentAttribute.setMappingKey(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY);
+ ManyToManyMapping mtmMapping = (ManyToManyMapping)mapping;
+
+ // Target Entity
+ if (refPropElem.getRefEntityClassName() != null &&
+ !refPropElem.getRefEntityClassName().equals(mtmMapping.getDefaultTargetEntity()))
+ {
+ mtmMapping.setSpecifiedTargetEntity(refPropElem.getRefEntityClassName());
+ }
+
+ // Fetch
+ if (propElem.getAnnotationAttribute(AnnotationAttributeNames.FETCH) != null)
+ {
+ FetchType fetchType = getFetchType(propElem.getAnnotationAttribute(AnnotationAttributeNames.FETCH).attrValue);
+ if (fetchType != null && fetchType != mtmMapping.getDefaultFetch())
+ {
+ mtmMapping.setSpecifiedFetch(fetchType);
+ }
+ }
+
+ // Cascade
+ syncCascadeMember(mtmMapping, refPropElem);
+
+ syncToManyAnnotations(propElem, mtmMapping);
+
+ // Join Strategy
+ if (refPropElem.getAnnotationAttribute(AnnotationAttributeNames.MAPPEDBY) != null)
+ {
+ // Mapped By
+ mtmMapping.getRelationship().setStrategyToMappedBy();
+ SpecifiedMappedByRelationshipStrategy mappedByStrategy = mtmMapping.getRelationship().getMappedByStrategy();
+ mappedByStrategy.setMappedByAttribute(propElem.getAnnotationAttribute(AnnotationAttributeNames.MAPPEDBY).attrValue);
+ }
+ else if (refPropElem.getJoinTable() != null)
+ {
+ // Join table
+ mtmMapping.getRelationship().setStrategyToJoinTable();
+ SpecifiedJoinTableRelationshipStrategy joinTableStrategy = mtmMapping.getRelationship().getJoinTableStrategy();
+ syncJoinTableAnnotation(refPropElem, joinTableStrategy);
+ }
+
+ }
+
+ private void syncCascadeMember(RelationshipMapping relationMapping, EntityRefPropertyElem refPropElem)
+ {
+ Cascade cascade = relationMapping.getCascade();
+ // Clear the exising cascade
+ cascade.setAll(false);
+ cascade.setMerge(false);
+ cascade.setPersist(false);
+ cascade.setRefresh(false);
+ cascade.setRemove(false);
+
+ List<String> cascadeStrs = refPropElem.getAllCascades();
+ for (String cascadeStr : cascadeStrs)
+ {
+ if (cascadeStr.equals(JPA.CASCADE_ALL))
+ {
+ cascade.setAll(true);
+ }
+ if (cascadeStr.equals(JPA.CASCADE_PERSIST))
+ {
+ cascade.setPersist(true);
+ }
+ if (cascadeStr.equals(JPA.CASCADE_MERGE))
+ {
+ cascade.setMerge(true);
+ }
+ if (cascadeStr.equals(JPA.CASCADE_REMOVE))
+ {
+ cascade.setRemove(true);
+ }
+ if (cascadeStr.equals(JPA.CASCADE_REFRESH))
+ {
+ cascade.setRefresh(true);
+ }
+ }
+ }
+
+ private void syncJoinTableAnnotation(EntityRefPropertyElem refPropEmElem, SpecifiedJoinTableRelationshipStrategy jtRelation)
+ {
+ JoinTableAttributes joinTableAttrs = refPropEmElem.getJoinTable();
+ assert joinTableAttrs != null;
+ SpecifiedJoinTable joinTable = jtRelation.getJoinTable();
+ Table dbJoinTable = null;
+ // Name
+ if (joinTableAttrs.getTableName() != null)
+ {
+ dbJoinTable = this.schema.getTableNamed(joinTableAttrs.getTableName());
+ if (dbJoinTable != null)
+ {
+ String joinTableName = this.databaseAnnotationNameBuilder.buildJoinTableAnnotationName(dbJoinTable);
+ joinTable.setSpecifiedName(joinTableName != null ? joinTableName : dbJoinTable.getName());
+ }
+ }
+
+ List<ColumnAttributes> cols = joinTableAttrs.getJoinColumns();
+ for (ColumnAttributes col : cols)
+ {
+ SpecifiedJoinColumn joinColumn = joinTable.addSpecifiedJoinColumn();
+
+ syncJoinColumnAnnotations(true, dbJoinTable, refPropEmElem.getDBTable(),
+ refPropEmElem.getPropertyName(), col, joinColumn);
+ }
+ List<ColumnAttributes> inverseCols = joinTableAttrs.getInverseJoinColumns();
+ for (ColumnAttributes col : inverseCols)
+ {
+ SpecifiedJoinColumn joinColumn = joinTable.addSpecifiedInverseJoinColumn();
+ syncJoinColumnAnnotations(true, dbJoinTable, refPropEmElem.getReferencedTable(), refPropEmElem.getPropertyName(),
+ col, joinColumn);
+ }
+ }
+
+ private void syncJoinColumnAnnotations(boolean isJoinTable, Table baseTable, Table refTable, String propName,
+ ColumnAttributes col, SpecifiedJoinColumn joinColumn)
+ {
+ if (baseTable == null || refTable == null)
+ {
+ return;
+ }
+ boolean printoutNameOrRefName = false;
+ if (col.getName() != null)
+ {
+ Column dbColumn = baseTable.getColumnNamed(col.getName());
+ ForeignKey fk = getForeignKey(dbColumn);
+ Column refDbCol = col.getReferencedColumnName() != null ?
+ refTable.getColumnNamed(col.getReferencedColumnName()) : null;
+
+ if ((fk != null && !fk.referencesSingleColumnPrimaryKey()) || isJoinTable)
+ {
+ if (refDbCol != null)
+ {
+ // need to print out both columnName and referenceColumnName
+ String colName = this.databaseAnnotationNameBuilder.buildJoinColumnAnnotationName(dbColumn);
+ String refColName = this.databaseAnnotationNameBuilder.buildJoinColumnAnnotationName(refDbCol);
+ joinColumn.setSpecifiedName(colName);
+ joinColumn.setSpecifiedReferencedColumnName(refColName);
+ printoutNameOrRefName = true;
+ }
+ }
+ else
+ {
+ // No need to print out referenceColumnName. Print out columnName if
+ // the name cannot be defaulted
+ String colName = this.databaseAnnotationNameBuilder.buildColumnAnnotationName(propName, dbColumn);
+ if (colName != null)
+ {
+ joinColumn.setSpecifiedName(colName);
+ printoutNameOrRefName = true;
+ }
+ }
+ }
+ if (printoutNameOrRefName)
+ {
+ // Unique
+ if (col.isSetUnique() && col.isUnique())
+ {
+ joinColumn.setSpecifiedUnique(col.isUnique());
+ }
+ // Nullable
+ if (col.isSetNullable() && !col.isNullable())
+ {
+ joinColumn.setSpecifiedNullable(col.isNullable());
+ }
+ // Insertable
+ if (col.isSetInsertable() && !col.isInsertable())
+ {
+ joinColumn.setSpecifiedInsertable(col.isInsertable());
+ }
+ // Updatable
+ if (col.isSetUpdatable() && !col.isUpdatable())
+ {
+ joinColumn.setSpecifiedUpdatable(col.isUpdatable());
+ }
+ // Column Definition
+ if (col.getColumnDefinition() != null)
+ {
+ joinColumn.setColumnDefinition(col.getColumnDefinition());
+ }
+ }
+ }
+
+ private void syncJoinColumnsAnnotations(Table baseTable, Table refTable, String propertyName, List<ColumnAttributes> joinColumns, SpecifiedJoinColumnRelationshipStrategy joinColumnStrategy)
+ {
+ if (joinColumns == null || joinColumns.size() == 0)
+ {
+ return;
+ }
+ int count = joinColumns.size();
+ /*remove empty join column tags so that no annotation is generated for them*/
+ for (int i = count-1; i >= 0; --i)
+ {
+ if (joinColumns.get(i).isEmpty())
+ {
+ joinColumns.remove(i);
+ }
+ }
+ count = joinColumns.size(); //recompute the size just in case any tag has been removed from the list above
+
+ for (int i = 0; i < count; ++i)
+ {
+ ColumnAttributes col = joinColumns.get(i);
+ SpecifiedJoinColumn joinColumn = joinColumnStrategy.addSpecifiedJoinColumn();
+ syncJoinColumnAnnotations(false, baseTable, refTable, propertyName, col, joinColumn);
+ }
+ }
+
+ /**
+ * Sync the MapBy and OrderBy annotations.
+ */
+ private void syncToManyAnnotations(EntityPropertyElem propElem, CollectionMapping collectionMapping)
+ {
+ assert propElem instanceof EntityPropertyElem;
+ EntityRefPropertyElem refPropElem = (EntityRefPropertyElem)propElem;
+ // TODO @MapKey
+
+ // Order by
+ if (refPropElem.getOrderBy() != null)
+ {
+ collectionMapping.getOrderable().setSpecifiedOrderBy(refPropElem.getOrderBy());
+ }
+ }
+
+ private void syncPkJoinColumnAnnotations(List<ColumnAttributes> pkJoinCols, SpecifiedPrimaryKeyJoinColumnRelationshipStrategy pkJoinStrategy)
+ {
+ for (ColumnAttributes pkJoinCol : pkJoinCols)
+ {
+ SpecifiedPrimaryKeyJoinColumn pkJoinColumn = pkJoinStrategy.addPrimaryKeyJoinColumn();
+ // Name
+ if (pkJoinCol.getName() != null && !pkJoinCol.getName().equals(pkJoinColumn.getDefaultName()))
+ {
+ pkJoinColumn.setSpecifiedName(pkJoinCol.getName());
+ }
+ // Referenced Column Name
+ if (pkJoinCol.getReferencedColumnName() != null &&
+ !pkJoinCol.getReferencedColumnName().equals(pkJoinColumn.getDefaultReferencedColumnName()))
+ {
+ pkJoinColumn.setSpecifiedReferencedColumnName(pkJoinCol.getReferencedColumnName());
+ }
+ // Column Definition
+ if (pkJoinCol.getColumnDefinition() != null)
+ {
+ pkJoinColumn.setColumnDefinition(pkJoinCol.getColumnDefinition());
+ }
+ }
+ }
+
+ private GenerationType getGenerationType(String strategy)
+ {
+ if (strategy.equalsIgnoreCase("auto"))
+ {
+ return GenerationType.AUTO;
+ }
+ else if (strategy.equalsIgnoreCase("identity"))
+ {
+ return GenerationType.IDENTITY;
+ }
+ else if (strategy.equalsIgnoreCase("sequence"))
+ {
+ return GenerationType.SEQUENCE;
+ }
+ else if (strategy.equalsIgnoreCase("table"))
+ {
+ return GenerationType.TABLE;
+ }
+ return null;
+ }
+
+ private FetchType getFetchType(String fetch)
+ {
+ if (fetch == null)
+ {
+ return null;
+ }
+ else if (fetch.equalsIgnoreCase("eager"))
+ {
+ return FetchType.EAGER;
+ }
+ else if (fetch.equalsIgnoreCase("lazy"))
+ {
+ return FetchType.LAZY;
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ private boolean isJpa1_0Project()
+ {
+ return this.persistentType.getPersistenceUnit().getJpaPlatform().getJpaVersion().getVersion().equals("1.0");
+ }
+
+ private ForeignKey getForeignKey(Column dbColumn)
+ {
+ if( dbColumn== null || !dbColumn.isPartOfForeignKey())
+ {
+ return null;
+ }
+ ForeignKey foreignKey = null;
+ Iterable<ForeignKey> it = dbColumn.getTable().getForeignKeys();
+ Iterator<ForeignKey> i = it.iterator();
+ while( i.hasNext() )
+ {
+ ForeignKey fk = i.next();
+ Column c = fk.getBaseColumns().iterator().next();
+ if( c.equals( dbColumn ) )
+ {
+ foreignKey = fk;
+ break;
+ }
+ }
+ return foreignKey;
+ }
+
+}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.annotate/src/org/eclipse/jpt/jpa/annotate/JptJpaAnnotateMessages.java b/jpa/plugins/org.eclipse.jpt.jpa.annotate/src/org/eclipse/jpt/jpa/annotate/JptJpaAnnotateMessages.java
new file mode 100644
index 0000000..4b4e6ca
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.jpa.annotate/src/org/eclipse/jpt/jpa/annotate/JptJpaAnnotateMessages.java
@@ -0,0 +1,29 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+
+package org.eclipse.jpt.jpa.annotate;
+
+import org.eclipse.osgi.util.NLS;
+
+public class JptJpaAnnotateMessages
+{
+ private static final String BUNDLE_NAME = "jpt_jpa_annotate"; //$NON-NLS-1$
+ private static final Class<?> BUNDLE_CLASS = JptJpaAnnotateMessages.class;
+ static {
+ NLS.initializeMessages(BUNDLE_NAME, BUNDLE_CLASS);
+ }
+
+ public static String ANNOTATE_JAVA_CLASS;
+
+ private JptJpaAnnotateMessages() {
+ throw new UnsupportedOperationException();
+ }
+
+}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.annotate/src/org/eclipse/jpt/jpa/annotate/internal/plugin/JptJpaAnnotatePlugin.java b/jpa/plugins/org.eclipse.jpt.jpa.annotate/src/org/eclipse/jpt/jpa/annotate/internal/plugin/JptJpaAnnotatePlugin.java
new file mode 100644
index 0000000..bdeec83
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.jpa.annotate/src/org/eclipse/jpt/jpa/annotate/internal/plugin/JptJpaAnnotatePlugin.java
@@ -0,0 +1,30 @@
+package org.eclipse.jpt.jpa.annotate.internal.plugin;
+
+import org.eclipse.jpt.common.core.internal.utility.JptPlugin;
+
+public class JptJpaAnnotatePlugin extends JptPlugin
+{
+ // ********** singleton **********
+
+ private static volatile JptJpaAnnotatePlugin INSTANCE;
+
+ /**
+ * Return the singleton Dali common core plug-in.
+ */
+ public static JptJpaAnnotatePlugin instance() {
+ return INSTANCE;
+ }
+
+
+ // ********** Dali plug-in **********
+
+ public JptJpaAnnotatePlugin() {
+ super();
+ }
+
+ @Override
+ protected void setInstance(JptPlugin plugin) {
+ INSTANCE = (JptJpaAnnotatePlugin) plugin;
+ }
+
+}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.annotate/src/org/eclipse/jpt/jpa/annotate/mapping/AnnotationAttrConverter.java b/jpa/plugins/org.eclipse.jpt.jpa.annotate/src/org/eclipse/jpt/jpa/annotate/mapping/AnnotationAttrConverter.java
new file mode 100644
index 0000000..e413f2f
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.jpa.annotate/src/org/eclipse/jpt/jpa/annotate/mapping/AnnotationAttrConverter.java
@@ -0,0 +1,79 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+
+package org.eclipse.jpt.jpa.annotate.mapping;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public class AnnotationAttrConverter
+{
+ public final static String FETCH = "fetch";
+ public final static String LOB_TYPE = "lob-type";
+ public final static String DISCRIMINATOR_TYPE = "discriminator-type";
+ public final static String TEMPORAL = "temporal";
+ public final static String INHERITANCE_STRAGETY = "inheritance-strategy";
+ public final static String GENERATION_STRATEGY = "generation-stragegy";
+
+ private static Map<String, String> tagEnumClassMap;
+ private static Map<String, String[]> tagEnumValuesMap;
+
+ static
+ {
+ tagEnumClassMap = new HashMap<String, String>(8);
+ /*the enumeration tags are:
+ * fetch --> javax.persistence.FetchType
+ * lob --> javax.persistence.Lob
+ * discriminator-type --> javax.persistence.DiscriminatorType
+ * temporal --> javax.persistence.Temporal
+ * inheritance-strategy --> javax.persistence.InheritanceType
+ * strategy --> javax.persistence.GenerationType
+ * */
+ tagEnumClassMap.put(FETCH, "javax.persistence.FetchType");
+ tagEnumClassMap.put(LOB_TYPE, "java.lang.annotation.ElementType");
+ tagEnumClassMap.put(DISCRIMINATOR_TYPE, "javax.persistence.DiscriminatorType");
+ tagEnumClassMap.put(TEMPORAL, "javax.persistence.TemporalType");
+ tagEnumClassMap.put(INHERITANCE_STRAGETY, "javax.persistence.InheritanceType");
+ tagEnumClassMap.put(GENERATION_STRATEGY, "javax.persistence.GenerationType");
+
+ tagEnumValuesMap = new HashMap<String, String[]>(8);
+ tagEnumValuesMap.put(FETCH, new String[]{"LAZY", "EAGER"});
+ tagEnumValuesMap.put(LOB_TYPE, new String[]{"METHOD", "FIELD"});
+ tagEnumValuesMap.put(DISCRIMINATOR_TYPE, new String[]{"CHAR", "INTEGER", "STRING"});
+ tagEnumValuesMap.put(TEMPORAL, new String[]{"DATE", "TIME", "TIMESTAMP"});
+ tagEnumValuesMap.put(INHERITANCE_STRAGETY, new String[]{"JOINED", "SINGLE_TABLE", "TABLE_PER_CLASS"});
+ tagEnumValuesMap.put(GENERATION_STRATEGY, new String[]{"AUTO", "IDENTITY", "SEQUENCE", "TABLE"});
+ }
+
+ public static String[] getTagEnumStringValues(String tagName)
+ {
+ return tagEnumValuesMap.get(tagName);
+ }
+
+ public static String getTagEnumClass(String tagName)
+ {
+ return tagEnumClassMap.get(tagName);
+ }
+
+ public static String adjustAnnotationValue(AnnotationAttribute attr)
+ {
+// assert attr.dataType == AttributeDataTypes.STRING_TYPE;
+ String attrVal = attr.attrValue;
+ String enumClass = getTagEnumClass(attr.tagName);
+ if (enumClass == null)
+ return attrVal;
+ if (enumClass.equals("javax.persistence.DiscriminatorType") //$NON-NLS-1$
+ && "CHARACTER".equals(attrVal)) //$NON-NLS-1$
+ {
+ attrVal = "CHAR"; //$NON-NLS-1$
+ }
+ return enumClass + '.' + attrVal;
+ }
+}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.annotate/src/org/eclipse/jpt/jpa/annotate/mapping/AnnotationAttribute.java b/jpa/plugins/org.eclipse.jpt.jpa.annotate/src/org/eclipse/jpt/jpa/annotate/mapping/AnnotationAttribute.java
new file mode 100644
index 0000000..0eeb931
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.jpa.annotate/src/org/eclipse/jpt/jpa/annotate/mapping/AnnotationAttribute.java
@@ -0,0 +1,39 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+
+package org.eclipse.jpt.jpa.annotate.mapping;
+
+public class AnnotationAttribute
+{
+ public String attrName;
+ public String tagName;
+ public String attrValue;
+
+ public AnnotationAttribute(String name, String value)
+ {
+ this(name, name, value);
+ }
+
+ public AnnotationAttribute(String name, String tagName, String value)
+ {
+ this.attrName = name;
+ this.tagName = tagName;
+ this.attrValue = value;
+ }
+
+ // copy constructor
+ public AnnotationAttribute(AnnotationAttribute another)
+ {
+ attrName = another.attrName;
+ tagName = another.tagName;
+ attrValue = another.attrValue;
+ }
+
+}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.annotate/src/org/eclipse/jpt/jpa/annotate/mapping/AnnotationAttributeNames.java b/jpa/plugins/org.eclipse.jpt.jpa.annotate/src/org/eclipse/jpt/jpa/annotate/mapping/AnnotationAttributeNames.java
new file mode 100644
index 0000000..5c285e7
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.jpa.annotate/src/org/eclipse/jpt/jpa/annotate/mapping/AnnotationAttributeNames.java
@@ -0,0 +1,41 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+
+package org.eclipse.jpt.jpa.annotate.mapping;
+
+public class AnnotationAttributeNames
+{
+ public static final String CASCADE = "cascade";
+ public static final String CATALOG = "catalog";
+ public static final String COLUMN_DEFINITION = "columnDefinition";
+ public static final String DISCRIMINATOR_TYPE = "discriminatorType";
+ public static final String FETCH = "fetch";
+ public static final String GENERATOR = "generator";
+ public static final String INSERTABLE = "insertable";
+ public static final String INVERSE_JOIN_COLUMN = "inverseJoinColumn";
+ public static final String INVERSE_JOIN_COLUMNS = "inverseJoinColumns";
+ public static final String JOIN_COLUMN = "joinColumn";
+ public static final String JOIN_COLUMNS = "joinColumns";
+ public static final String LENGTH = "length";
+ public static final String MAPPEDBY = "mappedBy";
+ public static final String NAME = "name";
+ public static final String NULLABLE = "nullable";
+ public static final String PRECISION = "precision";
+ public static final String REFERENCED_COLUMN_NAME = "referencedColumnName";
+ public static final String SCALE = "scale";
+ public static final String SCHEMA = "schema";
+ public static final String STRATEGY = "strategy";
+ public static final String TABLE = "table";
+ public static final String TARGET_ENTITY = "targetEntity";
+ public static final String TEMPORAL = "temporal";
+ public static final String UNIQUE = "unique";
+ public static final String UPDATABLE = "updatable";
+ public static final String VALUE = "value";
+}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.annotate/src/org/eclipse/jpt/jpa/annotate/mapping/AnnotationAttributes.java b/jpa/plugins/org.eclipse.jpt.jpa.annotate/src/org/eclipse/jpt/jpa/annotate/mapping/AnnotationAttributes.java
new file mode 100644
index 0000000..e0478c0
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.jpa.annotate/src/org/eclipse/jpt/jpa/annotate/mapping/AnnotationAttributes.java
@@ -0,0 +1,74 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+
+package org.eclipse.jpt.jpa.annotate.mapping;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+public class AnnotationAttributes
+{
+ private Map<String, AnnotationAttribute> attrs;
+
+ public AnnotationAttributes()
+ {
+ attrs = new HashMap<String, AnnotationAttribute>(6);
+ }
+
+ // copy constructor
+ public AnnotationAttributes(AnnotationAttributes another)
+ {
+ this();
+ Iterator<String> it = another.attrs.keySet().iterator();
+ while (it.hasNext())
+ {
+ String key = it.next();
+ AnnotationAttribute attr = another.attrs.get(key);
+ attrs.put(key, new AnnotationAttribute(attr));
+ }
+ }
+
+ public void setAnnotationAttribute(AnnotationAttribute attr)
+ {
+ attrs.put(attr.attrName, attr);
+ }
+
+ public AnnotationAttribute getAnnotationAttribute(String name)
+ {
+ return attrs.get(name);
+ }
+
+ public void removeAnnotationAttribute(String name)
+ {
+ attrs.remove(name);
+ }
+
+ public AnnotationAttribute[] getAnnotationAttributes(String[] attrNames)
+ {
+ AnnotationAttribute[] attrs = new AnnotationAttribute[attrNames.length];
+ int index = 0;
+ for (String attrName : attrNames)
+ {
+ attrs[index++] = this.attrs.get(attrName);
+ }
+ return attrs;
+ }
+
+ public boolean isEmpty()
+ {
+ return attrs.isEmpty();
+ }
+
+ public void dispose()
+ {
+ attrs.clear();
+ }
+}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.annotate/src/org/eclipse/jpt/jpa/annotate/mapping/BasicEntityPropertyElem.java b/jpa/plugins/org.eclipse.jpt.jpa.annotate/src/org/eclipse/jpt/jpa/annotate/mapping/BasicEntityPropertyElem.java
new file mode 100644
index 0000000..8577096
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.jpa.annotate/src/org/eclipse/jpt/jpa/annotate/mapping/BasicEntityPropertyElem.java
@@ -0,0 +1,61 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+
+package org.eclipse.jpt.jpa.annotate.mapping;
+
+import org.eclipse.jpt.jpa.db.Table;
+
+
+public class BasicEntityPropertyElem extends EntityPropertyElem
+{
+ private String temporalType;
+
+ public BasicEntityPropertyElem(String fqClassName, Table table)
+ {
+ super(fqClassName, table);
+ }
+
+ public BasicEntityPropertyElem(String fqClassName, Table table, String propName, String propType)
+ {
+ super(fqClassName, table, propName, propType);
+ }
+
+ public BasicEntityPropertyElem(BasicEntityPropertyElem another)
+ {
+ super(another);
+ temporalType = another.temporalType;
+ }
+
+ public boolean isSetTemporalType()
+ {
+ return temporalType != null;
+ }
+
+ public String getTemporalType()
+ {
+ return temporalType;
+ }
+
+ public void setTemporalType(String temporalType)
+ {
+ this.temporalType = temporalType;
+ }
+
+ public AnnotationAttribute getTemporalAnnotationAttribute()
+ {
+ AnnotationAttribute attr = null;
+ if (temporalType != null)
+ {
+ attr = new AnnotationAttribute(
+ AnnotationAttributeNames.VALUE, AnnotationAttrConverter.TEMPORAL, temporalType);
+ }
+ return attr;
+ }
+}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.annotate/src/org/eclipse/jpt/jpa/annotate/mapping/ColumnAttributes.java b/jpa/plugins/org.eclipse.jpt.jpa.annotate/src/org/eclipse/jpt/jpa/annotate/mapping/ColumnAttributes.java
new file mode 100644
index 0000000..24944af
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.jpa.annotate/src/org/eclipse/jpt/jpa/annotate/mapping/ColumnAttributes.java
@@ -0,0 +1,311 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+
+package org.eclipse.jpt.jpa.annotate.mapping;
+
+import java.text.NumberFormat;
+import java.text.ParseException;
+
+import org.eclipse.jpt.jpa.annotate.internal.plugin.JptJpaAnnotatePlugin;
+
+public class ColumnAttributes extends AnnotationAttributes
+{
+ public ColumnAttributes()
+ {
+ super();
+ }
+
+ public ColumnAttributes(ColumnAttributes another)
+ {
+ super(another);
+ }
+
+ public void setName(String name)
+ {
+ AnnotationAttribute attr = new AnnotationAttribute(
+ AnnotationAttributeNames.NAME, name);
+ setAnnotationAttribute(attr);
+ }
+
+ public String getName()
+ {
+ String name = null;
+ AnnotationAttribute attr = getAnnotationAttribute(AnnotationAttributeNames.NAME);
+ if (attr != null)
+ name = attr.attrValue;
+ return name;
+ }
+
+ public void setReferencedColumnName(String referencedColumnName)
+ {
+ AnnotationAttribute attr = new AnnotationAttribute(
+ AnnotationAttributeNames.REFERENCED_COLUMN_NAME,
+ referencedColumnName);
+ setAnnotationAttribute(attr);
+ }
+
+ public String getReferencedColumnName()
+ {
+ String refColName = null;
+ AnnotationAttribute attr = getAnnotationAttribute(AnnotationAttributeNames.REFERENCED_COLUMN_NAME);
+ if (attr != null)
+ refColName = attr.attrValue;
+ return refColName;
+ }
+
+ public void setUnique(boolean unique)
+ {
+ AnnotationAttribute attr = new AnnotationAttribute(
+ AnnotationAttributeNames.UNIQUE,
+ unique ? "true" : "false");
+ setAnnotationAttribute(attr);
+ }
+
+ public boolean isSetUnique()
+ {
+ return getAnnotationAttribute(AnnotationAttributeNames.UNIQUE) != null;
+ }
+
+ public boolean isUnique()
+ {
+ boolean isUnique = false;
+ AnnotationAttribute attr = getAnnotationAttribute(AnnotationAttributeNames.UNIQUE);
+ if (attr != null)
+ {
+ isUnique = attr.attrValue.equals("true") ? true : false;
+ }
+ return isUnique;
+ }
+
+ public void setNullable(boolean nullable)
+ {
+ AnnotationAttribute attr = new AnnotationAttribute(
+ AnnotationAttributeNames.NULLABLE,
+ nullable ? "true" : "false");
+ setAnnotationAttribute(attr);
+ }
+
+ public boolean isSetNullable()
+ {
+ return getAnnotationAttribute(AnnotationAttributeNames.NULLABLE) != null;
+ }
+
+ public boolean isNullable()
+ {
+ boolean isNullable = false;
+ AnnotationAttribute attr = getAnnotationAttribute(AnnotationAttributeNames.NULLABLE);
+ if (attr != null)
+ {
+ isNullable = attr.attrValue.equals("true") ? true : false;
+ }
+ return isNullable;
+ }
+
+ public void setInsertable(boolean insertable)
+ {
+ AnnotationAttribute attr = new AnnotationAttribute(
+ AnnotationAttributeNames.INSERTABLE,
+ insertable ? "true" : "false");
+ setAnnotationAttribute(attr);
+ }
+
+ public boolean isSetInsertable()
+ {
+ return getAnnotationAttribute(AnnotationAttributeNames.INSERTABLE) != null;
+ }
+
+ public boolean isInsertable()
+ {
+ boolean isInsertable = false;
+ AnnotationAttribute attr = getAnnotationAttribute(AnnotationAttributeNames.INSERTABLE);
+ if (attr != null)
+ {
+ isInsertable = attr.attrValue.equals("true") ? true : false;
+ }
+ return isInsertable;
+ }
+
+ public void setUpdatable(boolean updatable)
+ {
+ AnnotationAttribute attr = new AnnotationAttribute(
+ AnnotationAttributeNames.UPDATABLE,
+ updatable ? "true" : "false");
+ setAnnotationAttribute(attr);
+ }
+
+ public boolean isSetUpdatable()
+ {
+ return getAnnotationAttribute(AnnotationAttributeNames.UPDATABLE) != null;
+ }
+
+ public boolean isUpdatable()
+ {
+ boolean isUpdatable = false;
+ AnnotationAttribute attr = getAnnotationAttribute(AnnotationAttributeNames.UPDATABLE);
+ if (attr != null)
+ {
+ isUpdatable = attr.attrValue.equals("true") ? true : false;
+ }
+ return isUpdatable;
+ }
+
+ public void setColumnDefinition(String columnDefinition)
+ {
+ AnnotationAttribute attr = new AnnotationAttribute(
+ AnnotationAttributeNames.COLUMN_DEFINITION,
+ columnDefinition);
+ setAnnotationAttribute(attr);
+ }
+
+ public String getColumnDefinition()
+ {
+ String colDef = null;
+ AnnotationAttribute attr = getAnnotationAttribute(AnnotationAttributeNames.COLUMN_DEFINITION);
+ if (attr != null)
+ colDef = attr.attrValue;
+ return colDef;
+ }
+
+ public void setTable(String table)
+ {
+ AnnotationAttribute attr = new AnnotationAttribute(
+ AnnotationAttributeNames.TABLE, table);
+ setAnnotationAttribute(attr);
+ }
+
+ public String getTable()
+ {
+ String table = null;
+ AnnotationAttribute attr = getAnnotationAttribute(AnnotationAttributeNames.TABLE);
+ if (attr != null)
+ table = attr.attrValue;
+ return table;
+ }
+
+ public void setLength(int length)
+ {
+ AnnotationAttribute attr = new AnnotationAttribute(
+ AnnotationAttributeNames.LENGTH,
+ String.valueOf(length));
+ setAnnotationAttribute(attr);
+ }
+
+ public void setLength(String lengthStr)
+ {
+ AnnotationAttribute attr = new AnnotationAttribute(
+ AnnotationAttributeNames.LENGTH,
+ lengthStr);
+ setAnnotationAttribute(attr);
+ }
+
+ public boolean isSetLength()
+ {
+ return getAnnotationAttribute(AnnotationAttributeNames.LENGTH) != null;
+ }
+
+ public int getLength()
+ {
+ int length = 0;
+ AnnotationAttribute attr = getAnnotationAttribute(AnnotationAttributeNames.LENGTH);
+ if (attr != null)
+ {
+ try
+ {
+ Number number = NumberFormat.getNumberInstance().parse(attr.attrValue);
+ length = number.intValue();
+ }
+ catch (ParseException pe)
+ {
+ JptJpaAnnotatePlugin.instance().logError(pe);
+ }
+ }
+ return length;
+ }
+
+ public void setPrecision(int precision)
+ {
+ AnnotationAttribute attr = new AnnotationAttribute(
+ AnnotationAttributeNames.PRECISION,
+ String.valueOf(precision));
+ setAnnotationAttribute(attr);
+ }
+
+ public void setPrecision(String precisionStr)
+ {
+ AnnotationAttribute attr = new AnnotationAttribute(
+ AnnotationAttributeNames.PRECISION,
+ precisionStr);
+ setAnnotationAttribute(attr);
+ }
+
+ public boolean isSetPrecision()
+ {
+ return getAnnotationAttribute(AnnotationAttributeNames.PRECISION) != null;
+ }
+
+ public int getPrecision()
+ {
+ int precision = 0;
+ AnnotationAttribute attr = getAnnotationAttribute(AnnotationAttributeNames.PRECISION);
+ if (attr != null)
+ {
+ try
+ {
+ Number number = NumberFormat.getNumberInstance().parse(attr.attrValue);
+ precision = number.intValue();
+ }
+ catch (ParseException pe)
+ {
+ JptJpaAnnotatePlugin.instance().logError(pe);
+ }
+ }
+ return precision;
+ }
+
+ public void setScale(int scale)
+ {
+ AnnotationAttribute attr = new AnnotationAttribute(
+ AnnotationAttributeNames.SCALE,
+ String.valueOf(scale));
+ setAnnotationAttribute(attr);
+ }
+
+ public void setScale(String scaleStr)
+ {
+ AnnotationAttribute attr = new AnnotationAttribute(
+ AnnotationAttributeNames.SCALE,
+ scaleStr);
+ setAnnotationAttribute(attr);
+ }
+
+ public boolean isSetScale()
+ {
+ return getAnnotationAttribute(AnnotationAttributeNames.SCALE) != null;
+ }
+
+ public int getScale()
+ {
+ int scale = 0;
+ AnnotationAttribute attr = getAnnotationAttribute(AnnotationAttributeNames.SCALE);
+ if (attr != null)
+ {
+ try
+ {
+ Number number = NumberFormat.getNumberInstance().parse(attr.attrValue);
+ scale = number.intValue();
+ }
+ catch (ParseException pe)
+ {
+ JptJpaAnnotatePlugin.instance().logError(pe);
+ }
+ }
+ return scale;
+ }
+}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.annotate/src/org/eclipse/jpt/jpa/annotate/mapping/EntityMappingsDoc.java b/jpa/plugins/org.eclipse.jpt.jpa.annotate/src/org/eclipse/jpt/jpa/annotate/mapping/EntityMappingsDoc.java
new file mode 100644
index 0000000..6ec16f1
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.jpa.annotate/src/org/eclipse/jpt/jpa/annotate/mapping/EntityMappingsDoc.java
@@ -0,0 +1,97 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+
+package org.eclipse.jpt.jpa.annotate.mapping;
+
+import org.eclipse.core.resources.IProject;
+
+/**
+ *
+ * An EntityMappingsDoc stores all the mapping information needed to convert a java
+ * class into an jpa entity
+ */
+public class EntityMappingsDoc
+{
+ // fully qualified class name
+ private String _className;
+ private IProject _project;
+ private TableAnnotationAttributes _tableAttrs;
+ private EntityPropertyElem[] _entityProperties;
+ // flag to indicate whether annotations should be added to property
+ // getters or fields.
+ private boolean _isPropertyAccess;
+
+ public EntityMappingsDoc(String className, IProject proj,
+ TableAnnotationAttributes tableAttrs,
+ EntityPropertyElem[] entityProps, boolean isPropertyAccess)
+ {
+ _className = className;
+ _project = proj;
+ _tableAttrs = tableAttrs;
+ _entityProperties = entityProps;
+ _isPropertyAccess = isPropertyAccess;
+ }
+
+ public void setClassName(String className)
+ {
+ _className = className;
+ }
+ public String getClassName()
+ {
+ return _className;
+ }
+ public void setProject(IProject project)
+ {
+ _project = project;
+ }
+ public IProject getProject()
+ {
+ return _project;
+ }
+ public void setTableAttrs(TableAnnotationAttributes tableAttr)
+ {
+ _tableAttrs = tableAttr;
+ }
+ public TableAnnotationAttributes getTableAttrs()
+ {
+ return _tableAttrs;
+ }
+ public void setEntityProperties(EntityPropertyElem[] entityProperties)
+ {
+ _entityProperties = entityProperties;
+ }
+ public EntityPropertyElem[] getEntityProperties()
+ {
+ return _entityProperties;
+ }
+ public void setPropertyAccess(boolean isPropertyAccess)
+ {
+ _isPropertyAccess = isPropertyAccess;
+ }
+ public boolean isPropertyAccess()
+ {
+ return _isPropertyAccess;
+ }
+
+ public EntityPropertyElem getProperty(String propName)
+ {
+ EntityPropertyElem ret = null;
+ for (EntityPropertyElem propElem : _entityProperties)
+ {
+ if (propElem.getPropertyName().equals(propName))
+ {
+ ret = propElem;
+ break;
+ }
+ }
+ return ret;
+ }
+
+}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.annotate/src/org/eclipse/jpt/jpa/annotate/mapping/EntityPropertyElem.java b/jpa/plugins/org.eclipse.jpt.jpa.annotate/src/org/eclipse/jpt/jpa/annotate/mapping/EntityPropertyElem.java
new file mode 100644
index 0000000..9ce9a88
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.jpa.annotate/src/org/eclipse/jpt/jpa/annotate/mapping/EntityPropertyElem.java
@@ -0,0 +1,180 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+
+package org.eclipse.jpt.jpa.annotate.mapping;
+
+import org.eclipse.jpt.jpa.db.Column;
+import org.eclipse.jpt.jpa.db.Table;
+
+
+public class EntityPropertyElem
+{
+ private String _fqClassName;
+ private Table _dbTable;
+ private String _propertyName;
+ private String _propertyType;
+ private String _tagName;
+ private boolean _unmapped;
+ private Column _column;
+ private ColumnAttributes _columnAnnotationAttrs;
+ private AnnotationAttributes _annotationAttrs;
+
+ public EntityPropertyElem(String fqClassName, Table table)
+ {
+ _fqClassName = fqClassName;
+ _dbTable = table;
+ _columnAnnotationAttrs = null;
+ _annotationAttrs = new AnnotationAttributes();
+ }
+
+ public EntityPropertyElem(String fqClassName, Table table, String propName, String propType)
+ {
+ this(fqClassName, table);
+ _propertyName = propName;
+ _propertyType = propType;
+ }
+
+ // Copy constructor
+ public EntityPropertyElem(EntityPropertyElem another)
+ {
+ this(another.getClassName(), another.getDBTable());
+ _propertyName = another._propertyName;
+ _propertyType = another._propertyType;
+ _tagName = another._tagName;
+ _unmapped = another._unmapped;
+ if (another._columnAnnotationAttrs != null)
+ _columnAnnotationAttrs = new ColumnAttributes(another._columnAnnotationAttrs);
+ if (another._annotationAttrs != null)
+ _annotationAttrs = new AnnotationAttributes(another._annotationAttrs);
+ }
+
+ public String getClassName()
+ {
+ return this._fqClassName;
+ }
+
+ public Table getDBTable()
+ {
+ return this._dbTable;
+ }
+
+ public String getPropertyName()
+ {
+ return _propertyName;
+ }
+
+ public void setPropertyName(String propName)
+ {
+ _propertyName = propName;
+ }
+
+ public String getPropertyType()
+ {
+ return _propertyType;
+ }
+
+ public void setPropertyType(String propType)
+ {
+ _propertyType = propType;
+ }
+
+ public String getTagName()
+ {
+ return _tagName;
+ }
+
+ public void setTagName(String tagName)
+ {
+ _tagName = tagName;
+ }
+
+ public boolean isUnmapped()
+ {
+ return _unmapped;
+ }
+
+ public void setUnmapped(boolean unmapped)
+ {
+ _unmapped = unmapped;
+ }
+
+ public void setColumnAnnotationAttrs(ColumnAttributes columnAnnotationAttrs)
+ {
+ this._columnAnnotationAttrs = columnAnnotationAttrs;
+ }
+
+ public ColumnAttributes getColumnAnnotationAttrs()
+ {
+ return _columnAnnotationAttrs;
+ }
+
+ public void setAnnotationAttr(AnnotationAttribute attr)
+ {
+ _annotationAttrs.setAnnotationAttribute(attr);
+ }
+ public AnnotationAttributes getAnnotationAttrs()
+ {
+ return _annotationAttrs;
+ }
+
+ public AnnotationAttribute[] getAnnotationAttrs(String[] attrNames)
+ {
+ return _annotationAttrs.getAnnotationAttributes(attrNames);
+ }
+
+ public AnnotationAttribute getAnnotationAttribute(String attrName)
+ {
+ return _annotationAttrs.getAnnotationAttribute(attrName);
+ }
+
+ public void setDBColumn(Column column)
+ {
+ _column = column;
+ }
+
+ public Column getDBColumn()
+ {
+ return _column;
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result
+ + ((_fqClassName == null) ? 0 : _fqClassName.hashCode());
+ result = prime * result
+ + ((_propertyName == null) ? 0 : _propertyName.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (!(obj instanceof EntityPropertyElem))
+ return false;
+ EntityPropertyElem other = (EntityPropertyElem) obj;
+ if (_fqClassName == null) {
+ if (other._fqClassName != null)
+ return false;
+ } else if (!_fqClassName.equals(other._fqClassName))
+ return false;
+ if (_propertyName == null) {
+ if (other._propertyName != null)
+ return false;
+ } else if (!_propertyName.equals(other._propertyName))
+ return false;
+ return true;
+ }
+
+}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.annotate/src/org/eclipse/jpt/jpa/annotate/mapping/EntityRefPropertyElem.java b/jpa/plugins/org.eclipse.jpt.jpa.annotate/src/org/eclipse/jpt/jpa/annotate/mapping/EntityRefPropertyElem.java
new file mode 100644
index 0000000..d08cc3c
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.jpa.annotate/src/org/eclipse/jpt/jpa/annotate/mapping/EntityRefPropertyElem.java
@@ -0,0 +1,282 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+
+package org.eclipse.jpt.jpa.annotate.mapping;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.jpt.jpa.core.resource.orm.JPA;
+import org.eclipse.jpt.jpa.db.Table;
+
+public class EntityRefPropertyElem extends EntityPropertyElem
+{
+ public static final String ASCENDING = "Ascending";
+ public static final String DESCENDING = "Descending";
+ private String refEntityClassName;
+ private Table refTable;
+ private JoinTableAttributes joinTable;
+ private List<ColumnAttributes> joinColumns;
+ private List<ColumnAttributes> inverseJoinColumns;
+ private List<ColumnAttributes> pkJoinColumns;
+ private List<String> cascades;
+ private String mapKey;
+ private String orderBy;
+ private JoinStrategy joinStrategy;
+
+ public EntityRefPropertyElem(String fqClassName, Table table)
+ {
+ super(fqClassName, table);
+ cascades = new ArrayList<String>();
+ joinColumns = new ArrayList<ColumnAttributes>();
+ inverseJoinColumns = new ArrayList<ColumnAttributes>();
+ pkJoinColumns = new ArrayList<ColumnAttributes>();
+ }
+
+ public EntityRefPropertyElem(String fqClassName, Table table, String propName, String propType)
+ {
+ super(fqClassName, table, propName, propType);
+ cascades = new ArrayList<String>();
+ joinColumns = new ArrayList<ColumnAttributes>();
+ inverseJoinColumns = new ArrayList<ColumnAttributes>();
+ pkJoinColumns = new ArrayList<ColumnAttributes>();
+ }
+
+ // Copy constructor
+ public EntityRefPropertyElem(EntityRefPropertyElem another)
+ {
+ super(another);
+ refEntityClassName = another.refEntityClassName;
+ refTable = another.refTable;
+ mapKey = another.mapKey;
+ orderBy = another.orderBy;
+ joinStrategy = another.joinStrategy;
+
+ if (another.joinTable != null)
+ joinTable = new JoinTableAttributes(another.joinTable);
+ cascades = new ArrayList<String>();
+ joinColumns = new ArrayList<ColumnAttributes>();
+ inverseJoinColumns = new ArrayList<ColumnAttributes>();
+ pkJoinColumns = new ArrayList<ColumnAttributes>();
+ cascades.addAll(another.cascades);
+ joinColumns.addAll(another.joinColumns);
+ inverseJoinColumns.addAll(another.inverseJoinColumns);
+ pkJoinColumns.addAll(another.pkJoinColumns);
+ }
+
+ public String getRefEntityClassName()
+ {
+ return refEntityClassName;
+ }
+
+ public void setRefEntityClassName(String refClass)
+ {
+ refEntityClassName = refClass;
+ }
+
+ public Table getReferencedTable()
+ {
+ return refTable;
+ }
+
+ public void setReferencedTable(Table refTable)
+ {
+ this.refTable = refTable;
+ }
+
+ public boolean isManyToOne()
+ {
+ return getTagName().equals(JPA.MANY_TO_ONE);
+ }
+
+ public boolean isOneToOne()
+ {
+ return getTagName().equals(JPA.ONE_TO_ONE);
+ }
+
+ public boolean isOneToMany()
+ {
+ return getTagName().equals(JPA.ONE_TO_MANY);
+ }
+
+ public boolean isManyToMany()
+ {
+ return getTagName().equals(JPA.MANY_TO_MANY);
+ }
+
+ public boolean isEntityCollection()
+ {
+ return isOneToMany() || isManyToMany();
+ }
+
+ public void setJoinTable(JoinTableAttributes joinTable)
+ {
+ this.joinTable = joinTable;
+ }
+
+ public JoinTableAttributes getJoinTable()
+ {
+ return joinTable;
+ }
+
+ public void removeJoinTable()
+ {
+ if (joinTable != null)
+ joinTable.dispose();
+ joinTable = null;
+
+ }
+ public void removeMappedBy()
+ {
+ if (getAnnotationAttrs() != null)
+ {
+ getAnnotationAttrs().removeAnnotationAttribute(AnnotationAttributeNames.MAPPEDBY);
+ }
+
+ }
+ public void addJoinColumn(ColumnAttributes joinColumn)
+ {
+ joinColumns.add(joinColumn);
+ }
+
+ public List<ColumnAttributes> getJoinColumns()
+ {
+ return joinColumns;
+ }
+
+ public void removeAllJoinColumns()
+ {
+ joinColumns.clear();
+ }
+
+ public void setJoinColumns(List<ColumnAttributes> joinColumns)
+ {
+ this.joinColumns.clear();
+ if (joinColumns != null)
+ this.joinColumns.addAll(joinColumns);
+ }
+
+ public void addInverseJoinColumn(ColumnAttributes joinColumn)
+ {
+ inverseJoinColumns.add(joinColumn);
+ }
+
+ public List<ColumnAttributes> getInverseJoinColumns()
+ {
+ return inverseJoinColumns;
+ }
+
+ public void removeAllInverseJoinColumns()
+ {
+ inverseJoinColumns.clear();
+ }
+
+ public void setInverseJoinColumns(List<ColumnAttributes> joinColumns)
+ {
+ this.inverseJoinColumns.clear();
+ if (joinColumns != null)
+ this.inverseJoinColumns.addAll(joinColumns);
+ }
+
+ public void addPkJoinColumn(ColumnAttributes joinColumn)
+ {
+ pkJoinColumns.add(joinColumn);
+ }
+
+ public List<ColumnAttributes> getPkJoinColumns()
+ {
+ return pkJoinColumns;
+ }
+
+ public void removeAllPKJoinColumns()
+ {
+ pkJoinColumns.clear();
+ }
+
+ public void setPKJoinColumns(List<ColumnAttributes> joinColumns)
+ {
+ this.pkJoinColumns.clear();
+ if (joinColumns != null)
+ this.pkJoinColumns.addAll(joinColumns);
+ }
+
+ /**
+ * Convenience method to retrieve "mappedBy" attribute
+ */
+ public String getMappedBy()
+ {
+ String mappedBy = null;
+ if (getAnnotationAttrs() != null)
+ {
+ AnnotationAttribute attr = getAnnotationAttrs().getAnnotationAttribute(AnnotationAttributeNames.MAPPEDBY);
+ if (attr != null)
+ mappedBy = attr.attrValue;
+ }
+ return mappedBy;
+ }
+
+ public void setMappedBy(String mappedBy)
+ {
+ AnnotationAttribute attr = new AnnotationAttribute(AnnotationAttributeNames.MAPPEDBY, mappedBy);
+ setAnnotationAttr(attr);
+ }
+
+ public List<String> getAllCascades()
+ {
+ return cascades;
+ }
+
+ public void addCascade(String cascade)
+ {
+ cascades.add(cascade);
+ }
+
+ public void removeAllCascades()
+ {
+ cascades.clear();
+ }
+
+ public void setCascades(List<String> cascades)
+ {
+ assert cascades != null;
+ this.cascades.clear();
+ this.cascades.addAll(cascades);
+ }
+
+ public void setMapKey(String mapKey)
+ {
+ this.mapKey = mapKey;
+ }
+
+ public String getMapKey()
+ {
+ return mapKey;
+ }
+
+ public void setOrderBy(String orderBy)
+ {
+ this.orderBy = orderBy;
+ }
+
+ public String getOrderBy()
+ {
+ return orderBy;
+ }
+
+ public JoinStrategy getJoinStrategy()
+ {
+ return this.joinStrategy;
+ }
+
+ public void setJoinStrategy(JoinStrategy joinStrategy)
+ {
+ this.joinStrategy = joinStrategy;
+ }
+}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.annotate/src/org/eclipse/jpt/jpa/annotate/mapping/GeneratedValueAttributes.java b/jpa/plugins/org.eclipse.jpt.jpa.annotate/src/org/eclipse/jpt/jpa/annotate/mapping/GeneratedValueAttributes.java
new file mode 100644
index 0000000..ec57e1a
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.jpa.annotate/src/org/eclipse/jpt/jpa/annotate/mapping/GeneratedValueAttributes.java
@@ -0,0 +1,58 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+
+package org.eclipse.jpt.jpa.annotate.mapping;
+
+public class GeneratedValueAttributes extends AnnotationAttributes
+{
+ public GeneratedValueAttributes()
+ {
+ super();
+ }
+
+ public GeneratedValueAttributes(GeneratedValueAttributes another)
+ {
+ super(another);
+ }
+
+ public void setGenerator(String generator)
+ {
+ AnnotationAttribute attr = new AnnotationAttribute(
+ AnnotationAttributeNames.GENERATOR, generator);
+ setAnnotationAttribute(attr);
+ }
+
+ public String getGenerator()
+ {
+ String generator = null;
+ AnnotationAttribute attr = getAnnotationAttribute(AnnotationAttributeNames.GENERATOR);
+ if (attr != null)
+ generator = attr.attrValue;
+ return generator;
+ }
+
+ public void setStrategy(String strategy)
+ {
+ AnnotationAttribute attr = new AnnotationAttribute(
+ AnnotationAttributeNames.STRATEGY, AnnotationAttrConverter.GENERATION_STRATEGY, strategy);
+ setAnnotationAttribute(attr);
+ }
+
+ public String getStrategy()
+ {
+ String strategy = null;
+ AnnotationAttribute attr = getAnnotationAttribute(AnnotationAttributeNames.STRATEGY);
+ if (attr != null)
+ strategy = attr.attrValue;
+ return strategy;
+ }
+
+
+}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.annotate/src/org/eclipse/jpt/jpa/annotate/mapping/IdEntityPropertyElement.java b/jpa/plugins/org.eclipse.jpt.jpa.annotate/src/org/eclipse/jpt/jpa/annotate/mapping/IdEntityPropertyElement.java
new file mode 100644
index 0000000..84ed721
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.jpa.annotate/src/org/eclipse/jpt/jpa/annotate/mapping/IdEntityPropertyElement.java
@@ -0,0 +1,45 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+
+package org.eclipse.jpt.jpa.annotate.mapping;
+
+import org.eclipse.jpt.jpa.db.Table;
+
+public class IdEntityPropertyElement extends EntityPropertyElem
+{
+ private GeneratedValueAttributes genAttrs;
+
+ public IdEntityPropertyElement(String fqClassName, Table table)
+ {
+ super(fqClassName, table);
+ }
+
+ public IdEntityPropertyElement(String fqClassName, Table table, String propName, String propType)
+ {
+ super(fqClassName, table, propName, propType);
+ }
+
+ public IdEntityPropertyElement(IdEntityPropertyElement another)
+ {
+ super(another);
+ if (another.genAttrs != null)
+ genAttrs = new GeneratedValueAttributes(another.genAttrs);
+ }
+
+ public GeneratedValueAttributes getGeneratedValueAttrs()
+ {
+ return genAttrs;
+ }
+
+ public void setGeneratedValueAttrs(GeneratedValueAttributes genAttrs)
+ {
+ this.genAttrs = genAttrs;
+ }
+}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.annotate/src/org/eclipse/jpt/jpa/annotate/mapping/JavaMapper.java b/jpa/plugins/org.eclipse.jpt.jpa.annotate/src/org/eclipse/jpt/jpa/annotate/mapping/JavaMapper.java
new file mode 100644
index 0000000..5b24f92
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.jpa.annotate/src/org/eclipse/jpt/jpa/annotate/mapping/JavaMapper.java
@@ -0,0 +1,259 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+
+package org.eclipse.jpt.jpa.annotate.mapping;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.jdt.core.Flags;
+import org.eclipse.jdt.core.IField;
+import org.eclipse.jdt.core.IType;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jpt.common.utility.internal.ClassNameTools;
+import org.eclipse.jpt.jpa.annotate.internal.plugin.JptJpaAnnotatePlugin;
+import org.eclipse.jpt.jpa.annotate.util.AnnotateMappingUtil;
+import org.eclipse.jpt.jpa.core.resource.orm.JPA;
+import org.eclipse.jpt.jpa.db.Column;
+import org.eclipse.jpt.jpa.db.Table;
+
+public class JavaMapper
+{
+ private IProject _project;
+ private String _fqEntityType;
+ private Table _table;
+ private String _pkProp;
+ private List<EntityPropertyElem> _entityProperties;
+ private IType _entityType;
+
+ public JavaMapper(IProject project, String fqEntityType, Table table, String pkProp)
+ {
+ _project = project;
+ _fqEntityType = fqEntityType;
+ _table = table;
+ _pkProp = pkProp;
+ _entityProperties = new ArrayList<EntityPropertyElem>();
+ try
+ {
+ _entityType = AnnotateMappingUtil.getType(_fqEntityType, _project);
+ }
+ catch (JavaModelException e)
+ {
+ JptJpaAnnotatePlugin.instance().logError(e);
+ }
+
+ }
+
+ public void map()
+ {
+ try
+ {
+ IField[] fields = _entityType.getFields();
+ for (IField field : fields)
+ {
+ // filter out static/inherited fields
+ if (Flags.isStatic(field.getFlags()) || Flags.isSuper(field.getFlags()))
+ continue;
+ if (_pkProp != null && _pkProp.equals(field.getElementName()))
+ {
+ EntityPropertyElem entityProp = mapProperty(field, true /* isId */);
+ _entityProperties.add(entityProp);
+ }
+ else
+ {
+ EntityPropertyElem entityProp = mapField(field);
+ _entityProperties.add(entityProp);
+ }
+ }
+ }
+ catch (JavaModelException je)
+ {
+ JptJpaAnnotatePlugin.instance().logError(je);
+ }
+ }
+
+ public List<EntityPropertyElem> getEntityProperties()
+ {
+ return _entityProperties;
+ }
+
+ private void setColumnAttrs(ColumnAttributes colAttrs, Column col)
+ {
+ colAttrs.setName(col.getName());
+ colAttrs.setNullable(col.isNullable());
+ colAttrs.setUnique(col.isPartOfUniqueConstraint());
+ if (col.isNumeric())
+ {
+ if (col.getPrecision() != 0)
+ colAttrs.setPrecision(col.getPrecision());
+ if (col.getScale() != 0)
+ colAttrs.setScale(col.getScale());
+ }
+ else
+ {
+ colAttrs.setLength(col.getLength());
+ }
+ }
+
+ private EntityPropertyElem mapProperty(IField field, boolean isId)
+ {
+ try
+ {
+ String propName = field.getElementName();
+ String fqType = AnnotateMappingUtil.getFieldType(field, _entityType);
+
+ EntityPropertyElem entityProp;
+ String tagName;
+ if (isId)
+ {
+ tagName = JPA.ID;
+ entityProp = new IdEntityPropertyElement(this._fqEntityType, this._table, propName, fqType);
+ }
+ else
+ {
+ tagName = JPA.BASIC;
+ entityProp = new BasicEntityPropertyElem(this._fqEntityType, this._table, propName, fqType);
+ }
+ entityProp.setTagName(tagName);
+ Column col = computeDefaultCol(propName);
+ if (col != null)
+ {
+ entityProp.setDBColumn(col);
+ ColumnAttributes colAttrs = new ColumnAttributes();
+ setColumnAttrs(colAttrs, col);
+ entityProp.setColumnAnnotationAttrs(colAttrs);
+ }
+ return entityProp;
+ }
+ catch (JavaModelException je)
+ {
+ JptJpaAnnotatePlugin.instance().logError(je);
+ }
+ return null;
+ }
+
+ private EntityPropertyElem mapOneToMany(IField field)
+ {
+ // TODO find out whether array type is supported
+ try
+ {
+ String type = AnnotateMappingUtil.getFieldType(field, _entityType);
+ String componentType = AnnotateMappingUtil.getGenericsComponentTypeName(type);
+ if (componentType != null)
+ {
+ componentType = AnnotateMappingUtil.resolveType(componentType, _entityType);
+ if (isSimpleType(componentType))
+ return mapProperty(field, false);
+ }
+
+ EntityRefPropertyElem erpe = new EntityRefPropertyElem(this._fqEntityType, this._table, field.getElementName(), type);
+ erpe.setTagName(JPA.ONE_TO_MANY);
+ erpe.setRefEntityClassName(componentType);
+ if (componentType != null)
+ {
+ IType refType = AnnotateMappingUtil.getType(componentType, _project);
+ if (refType != null)
+ {
+ Set<String> propNames = AnnotateMappingUtil.getMappedByList(_fqEntityType, refType, false);
+ if (propNames.size() == 1)
+ {
+ AnnotationAttribute attr = new AnnotationAttribute(AnnotationAttributeNames.MAPPEDBY,
+ propNames.iterator().next());
+ erpe.setAnnotationAttr(attr);
+ erpe.setJoinStrategy(JoinStrategy.MAPPED_BY);
+ }
+ }
+ }
+ return erpe;
+ }
+ catch (JavaModelException e)
+ {
+ JptJpaAnnotatePlugin.instance().logError(e);
+ return null;
+ }
+ }
+
+ private EntityPropertyElem mapManyToOne(IField field)
+ {
+ try
+ {
+ String fqType = AnnotateMappingUtil.getFieldType(field, _entityType);
+ EntityRefPropertyElem erpe = new EntityRefPropertyElem(this._fqEntityType, this._table, field.getElementName(), fqType);
+ erpe.setTagName(JPA.MANY_TO_ONE);
+ erpe.setRefEntityClassName(AnnotateMappingUtil.getFieldType(field, _entityType));
+ erpe.setJoinStrategy(JoinStrategy.JOIN_COLUMNS);
+ return erpe;
+ }
+ catch (JavaModelException je)
+ {
+ JptJpaAnnotatePlugin.instance().logError(je);
+ }
+ return null;
+ }
+
+ private EntityPropertyElem mapField(IField field)
+ {
+ try
+ {
+ String type = AnnotateMappingUtil.getFieldType(field, _entityType);
+ boolean isSimpleProperty;
+ if (AnnotateMappingUtil.isRepeatingType(type, _project))
+ {
+ if (AnnotateMappingUtil.isArrayType(type) &&
+ AnnotateMappingUtil.stripArrayDimensions(type).equals("byte"))
+ {
+ isSimpleProperty = true;
+ }
+ else
+ {
+ return mapOneToMany(field);
+ }
+ }
+ else
+ {
+ isSimpleProperty = isSimpleType(type);
+ }
+ if (isSimpleProperty)
+ return mapProperty(field, false);
+ else
+ return mapManyToOne(field);
+ }
+ catch (JavaModelException je)
+ {
+ JptJpaAnnotatePlugin.instance().logError(je);
+ }
+ return null;
+ }
+
+ private Column computeDefaultCol(String propName)
+ {
+ for( Column col : _table.getColumns() )
+ {
+ String colName = col.getName();
+ if (propName.equalsIgnoreCase(colName) || propName.equalsIgnoreCase(AnnotateMappingUtil.dbNameToJavaName(colName)))
+ {
+ return col;
+ }
+ }
+ return null;
+ }
+
+ private boolean isSimpleType(String type)
+ {
+ boolean isSimpleType = ClassNameTools.isPrimitive(type) ||
+ ClassNameTools.isPrimitiveWrapper(type) ||
+ type.startsWith("java."); //$NON-NLS-1$
+ return isSimpleType;
+
+ }
+
+}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.annotate/src/org/eclipse/jpt/jpa/annotate/mapping/JoinStrategy.java b/jpa/plugins/org.eclipse.jpt.jpa.annotate/src/org/eclipse/jpt/jpa/annotate/mapping/JoinStrategy.java
new file mode 100644
index 0000000..9949bc3
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.jpa.annotate/src/org/eclipse/jpt/jpa/annotate/mapping/JoinStrategy.java
@@ -0,0 +1,23 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+
+
+package org.eclipse.jpt.jpa.annotate.mapping;
+
+public enum JoinStrategy
+{
+ MAPPED_BY,
+
+ JOIN_COLUMNS,
+
+ JOIN_TABLE,
+
+ PRIMARY_KEY_JOIN_COLUMNS
+}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.annotate/src/org/eclipse/jpt/jpa/annotate/mapping/JoinTableAttributes.java b/jpa/plugins/org.eclipse.jpt.jpa.annotate/src/org/eclipse/jpt/jpa/annotate/mapping/JoinTableAttributes.java
new file mode 100644
index 0000000..8abebd6
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.jpa.annotate/src/org/eclipse/jpt/jpa/annotate/mapping/JoinTableAttributes.java
@@ -0,0 +1,98 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+
+package org.eclipse.jpt.jpa.annotate.mapping;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class JoinTableAttributes extends TableAnnotationAttributes
+{
+ private List<ColumnAttributes> joinColumns;
+ private List<ColumnAttributes> inverseJoinColumns;
+
+ public JoinTableAttributes()
+ {
+ super();
+ joinColumns = new ArrayList<ColumnAttributes>();
+ inverseJoinColumns = new ArrayList<ColumnAttributes>();
+ }
+
+ public JoinTableAttributes(JoinTableAttributes another)
+ {
+ super(another);
+ joinColumns = new ArrayList<ColumnAttributes>();
+ inverseJoinColumns = new ArrayList<ColumnAttributes>();
+ joinColumns.addAll(another.joinColumns);
+ inverseJoinColumns.addAll(another.inverseJoinColumns);
+ }
+
+ public JoinTableAttributes(String tableName, String catalog, String schema)
+ {
+ super(tableName, catalog, schema);
+ joinColumns = new ArrayList<ColumnAttributes>();
+ inverseJoinColumns = new ArrayList<ColumnAttributes>();
+ }
+
+ public void addJoinColumn(ColumnAttributes joinColumn)
+ {
+ joinColumns.add(joinColumn);
+ }
+
+ public List<ColumnAttributes> getJoinColumns()
+ {
+ return joinColumns;
+ }
+
+ public void removeAllJoinColumns()
+ {
+ for (ColumnAttributes col : joinColumns)
+ col.dispose();
+ joinColumns.clear();
+ }
+
+ public void setJoinColumns(List<ColumnAttributes> joinColumns)
+ {
+ removeAllJoinColumns();
+ if (joinColumns != null)
+ this.joinColumns.addAll(joinColumns);
+ }
+
+ public void addInverseJoinColumn(ColumnAttributes joinColumn)
+ {
+ inverseJoinColumns.add(joinColumn);
+ }
+
+ public List<ColumnAttributes> getInverseJoinColumns()
+ {
+ return inverseJoinColumns;
+ }
+
+ public void removeAllInverseJoinColumns()
+ {
+ for (ColumnAttributes col : inverseJoinColumns)
+ col.dispose();
+ this.inverseJoinColumns.clear();
+ }
+
+ public void setInverseJoinColumns(List<ColumnAttributes> joinColumns)
+ {
+ removeAllInverseJoinColumns();
+ if (joinColumns != null)
+ this.inverseJoinColumns.addAll(joinColumns);
+ }
+
+ public void dispose()
+ {
+ super.dispose();
+ removeAllJoinColumns();
+ removeAllInverseJoinColumns();
+ }
+}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.annotate/src/org/eclipse/jpt/jpa/annotate/mapping/TableAnnotationAttributes.java b/jpa/plugins/org.eclipse.jpt.jpa.annotate/src/org/eclipse/jpt/jpa/annotate/mapping/TableAnnotationAttributes.java
new file mode 100644
index 0000000..4c96e16
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.jpa.annotate/src/org/eclipse/jpt/jpa/annotate/mapping/TableAnnotationAttributes.java
@@ -0,0 +1,80 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+
+package org.eclipse.jpt.jpa.annotate.mapping;
+
+public class TableAnnotationAttributes extends AnnotationAttributes
+{
+ public TableAnnotationAttributes()
+ {
+ super();
+ }
+
+ public TableAnnotationAttributes(String tableName, String catalog, String schema)
+ {
+ setTableName(tableName);
+ setCatalog(catalog);
+ setSchema(schema);
+ }
+
+ public TableAnnotationAttributes(TableAnnotationAttributes another)
+ {
+ super(another);
+ }
+
+ public void setTableName(String tableName)
+ {
+ AnnotationAttribute attr = new AnnotationAttribute(
+ AnnotationAttributeNames.NAME, tableName);
+ setAnnotationAttribute(attr);
+ }
+
+ public String getTableName()
+ {
+ String name = null;
+ AnnotationAttribute attr = getAnnotationAttribute(AnnotationAttributeNames.NAME);
+ if (attr != null)
+ name = attr.attrValue;
+ return name;
+ }
+
+ public void setCatalog(String catalog)
+ {
+ AnnotationAttribute attr = new AnnotationAttribute(
+ AnnotationAttributeNames.CATALOG, catalog);
+ setAnnotationAttribute(attr);
+ }
+
+ public String getCatalog()
+ {
+ String catalog = null;
+ AnnotationAttribute attr = getAnnotationAttribute(AnnotationAttributeNames.CATALOG);
+ if (attr != null)
+ catalog = attr.attrValue;
+ return catalog;
+ }
+
+ public void setSchema(String schema)
+ {
+ AnnotationAttribute attr = new AnnotationAttribute(
+ AnnotationAttributeNames.SCHEMA, schema);
+ setAnnotationAttribute(attr);
+ }
+
+ public String getSchema()
+ {
+ String schema = null;
+ AnnotationAttribute attr = getAnnotationAttribute(AnnotationAttributeNames.SCHEMA);
+ if (attr != null)
+ schema = attr.attrValue;
+ return schema;
+ }
+
+}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.annotate/src/org/eclipse/jpt/jpa/annotate/util/AnnotateMappingUtil.java b/jpa/plugins/org.eclipse.jpt.jpa.annotate/src/org/eclipse/jpt/jpa/annotate/util/AnnotateMappingUtil.java
new file mode 100644
index 0000000..faa7bd3
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.jpa.annotate/src/org/eclipse/jpt/jpa/annotate/util/AnnotateMappingUtil.java
@@ -0,0 +1,590 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+
+package org.eclipse.jpt.jpa.annotate.util;
+
+import java.math.BigDecimal;
+import java.util.Arrays;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.Set;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.jdt.core.Flags;
+import org.eclipse.jdt.core.IField;
+import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.IType;
+import org.eclipse.jdt.core.ITypeHierarchy;
+import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jdt.core.Signature;
+import org.eclipse.jpt.common.utility.internal.ClassNameTools;
+import org.eclipse.jpt.common.utility.internal.NameTools;
+import org.eclipse.jpt.common.utility.internal.StringTools;
+
+public class AnnotateMappingUtil
+{
+ public static final String[] REPEATING_TYPES = new String[]
+ {
+ java.util.Collection.class.getName(),
+ java.util.Enumeration.class.getName(),
+ java.util.Iterator.class.getName(),
+ java.util.Map.class.getName()
+ };
+
+ /** java primitive types */
+ public static String[] PRIMITIVE_TYPES = new String[] { "int", //$NON-NLS-1$
+ "double", //$NON-NLS-1$
+ "long", //$NON-NLS-1$
+ "short", //$NON-NLS-1$
+ "byte", //$NON-NLS-1$
+ "float", //$NON-NLS-1$
+ "boolean", //$NON-NLS-1$
+ "char", //$NON-NLS-1$
+ "void" }; //$NON-NLS-1$
+ public static String[] PRIMITIVE_WRAPPERS = new String[] {Integer.class.getName(),
+ Double.class.getName(),
+ Long.class.getName(),
+ Short.class.getName(),
+ Byte.class.getName(),
+ Float.class.getName(),
+ Boolean.class.getName(),
+ Character.class.getName()};
+
+ public final static String GET_PREFIX = "get"; //$NON-NLS-1$
+ public final static String IS_PREFIX = "is"; //$NON-NLS-1$
+ public final static String BOOLEAN = "boolean"; //$NON-NLS-1$
+
+ public static boolean isRepeatingType(String type, IProject project) throws JavaModelException
+ {
+ if (isArrayType(type))
+ return true;
+ String strippedType = stripTypeParameters(type);
+ for (String repeatingType : REPEATING_TYPES)
+ {
+ if (strippedType.equals(repeatingType) ||
+ isAssignableFrom(strippedType, repeatingType, project))
+ return true;
+ }
+ return false;
+ }
+
+
+ /**
+ * Returns the properties in refType of the same type entityClass.
+ *
+ */
+ public static Set<String> getMappedByList(String entityClass, IType refType, boolean isManyToMany)
+ throws JavaModelException
+ {
+ Set<String> propNames = new java.util.HashSet<String>();
+ IField[] fields = refType.getFields();
+ for (IField field : fields)
+ {
+ // filter out static/inherited fields
+ if (Flags.isStatic(field.getFlags()) || Flags.isSuper(field.getFlags()))
+ continue;
+
+ String fieldType = getFieldType(field, refType);
+ String dt = null;
+ if (fieldType != null)
+ {
+ if (isManyToMany)
+ {
+ dt = getGenericsComponentTypeName(fieldType);
+ if (dt != null)
+ dt = resolveType(dt, refType);
+ } else
+ {
+ dt = fieldType;
+ }
+ }
+ if (dt != null && dt.equals(entityClass))
+ {
+ propNames.add(field.getElementName());
+ }
+ }
+ return propNames;
+ }
+
+ public static String getGenericsComponentTypeName(String s)
+ {
+ //s is in the form T<x, y>
+ int i1 = s.indexOf('<');
+ if (i1 < 0) {
+ return null;
+ }
+ int i2 = s.indexOf('>', i1);
+ if (i2 < 0) {
+ return null;
+ }
+ String typeName = s.substring(i1+1, i2);
+ //don't bother with the Map case for now
+ if (typeName.indexOf(',') >= 0) {
+ return null;
+ }
+
+ return typeName;
+ }
+
+ /**
+ * returns the fully qualified type for an IField
+ * @param field
+ * @param containingType
+ * @return
+ * @throws JavaModelException
+ */
+ public static String getFieldType(IField field, IType containingType) throws JavaModelException
+ {
+ String shortType = field.getTypeSignature();
+ shortType = Signature.toString(shortType);
+ if (ClassNameTools.isPrimitive(shortType))
+ return shortType;
+ String type = resolveType(shortType, containingType);
+ return type;
+ }
+
+ public static boolean isNumeric(String type)
+ {
+ return (type.equals(Integer.class.getName()) || type.equals(Integer.TYPE.getName())
+ || type.equals(Float.class.getName()) || type.equals(Float.TYPE.getName())
+ || type.equals(Double.class.getName()) || type.equals(Double.TYPE.getName())
+ || type.equals(Short.class.getName()) || type.equals(Short.TYPE.getName())
+ || type.equals(Long.class.getName()) || type.equals(Long.TYPE.getName())
+ || type.equals(Byte.class.getName()) || type.equals(Byte.TYPE.getName())
+ || type.equals(Number.class.getName())
+ || type.equals(BigDecimal.class.getName()));
+ }
+
+ public static boolean isString(String type)
+ {
+ return (type.equals(String.class.getName()));
+ }
+
+ public static boolean isDate(String type, IProject proj) throws JavaModelException
+ {
+ return isAssignableFrom(type, Date.class.getName(), proj) ||
+ isAssignableFrom(type, Calendar.class.getName(), proj);
+ }
+
+ public static boolean isBoolean(String type)
+ {
+ return (type.equals(Boolean.class.getName()) || type.equals(Boolean.TYPE.getName()));
+ }
+
+ /**
+ * Checks if this type is an array type ie type has [] at the end.
+ */
+ public static boolean isArrayType( String type )
+ {
+ return type.endsWith( "[]" ); //$NON-NLS-1$
+ }
+
+ public static boolean hasMatchingTypeParameterBraces( String type )
+ {
+ assert type != null : "Type was null."; //$NON-NLS-1$
+ char[] chars = type.toCharArray();
+ int openCount = 0;
+ int closeCount = 0;
+
+ for ( int i = 0; i < chars.length; ++i )
+ {
+ if ( chars[i] == '<' )
+ ++openCount;
+
+ if ( chars[i] == '>' )
+ ++closeCount;
+
+ if ( closeCount > openCount )
+ return false;
+ }
+
+ return openCount == closeCount;
+ }
+
+ /**
+ * returns true if the array brackets on the string type are properly matched
+ * false otherwise
+ */
+ public static boolean hasMatchingArrayBrackets( String type )
+ {
+ int firstBracket = type.indexOf( "[" ); //$NON-NLS-1$
+ int nextBracket = type.indexOf( "]" ); //$NON-NLS-1$
+
+ // if no brackets at all, return true
+ if ( firstBracket == -1 && nextBracket == -1 )
+ {
+ return true;
+ }
+
+ String tempType = type;
+
+ while( tempType.length() > 0 )
+ {
+ nextBracket = tempType.indexOf( "]" ); //$NON-NLS-1$
+ if ( nextBracket < firstBracket ||
+ firstBracket == -1 ||
+ nextBracket != firstBracket + 1 )
+ {
+ return false;
+ }
+ tempType = tempType.substring( nextBracket + 1 );
+ firstBracket = tempType.indexOf( "[" ); //$NON-NLS-1$
+ }
+ return true;
+ }
+
+
+ /**
+ * Strips type parameter information from a type name, for example "java.util.List<java.lang.String>"
+ * would become "java.util.List". Stripping "<>" would become "". If the "<" don't match, then
+ * the provided type name is returned as-is, for example "List<<>" would be returned as "List<<>".
+ * This will not return null.
+ */
+ public static String stripTypeParameters( String typeName )
+ {
+ assert typeName != null : "Type name was null."; //$NON-NLS-1$
+
+ if ( hasMatchingTypeParameterBraces( typeName ) )
+ {
+ int index = typeName.indexOf( '<' );
+
+ if ( index > -1 )
+ typeName = typeName.substring( 0, index ).trim();
+ }
+
+ assert typeName != null : "Returning null type."; //$NON-NLS-1$
+ return typeName;
+ }
+
+ /**
+ * Strips any array dimensions off of the provided type name.
+ * For example, stripping "Foo[]" will return "Foo". If the brackets
+ * are not matched, the type name will be returned unchanged. For example,
+ * stripping "Foo]" will return "Foo]", and stripping "Foo[][" will
+ * return "Foo[][". Stripping "[]" will return "". Null is not returned.
+ */
+ public static String stripArrayDimensions( String typeName )
+ {
+ assert typeName != null : "Type name was null."; //$NON-NLS-1$
+
+ if ( hasMatchingArrayBrackets( typeName ) )
+ {
+ typeName = stripTypeParameters( typeName ); // Deal with things like Collection<String[]>
+ int index = typeName.indexOf( '[' );
+
+ if( index > -1 )
+ typeName = typeName.substring( 0, index ).trim();
+ }
+
+ assert typeName != null : "Returning null type."; //$NON-NLS-1$
+ return typeName;
+ }
+
+
+ /**
+ * Retrieves an IType for a given Java project or any project it references.
+ * Anonymous types cannot be retrieved with this method.
+ * @param fullyQualifiedType The fully qualified name of the type - for example "java.lang.String".
+ * This doesn't work for primitive or array types, such as "int" or "Foo[]".
+ * @param project The project that is in scope.
+ */
+ public static IType getType( String fullyQualifiedType, IProject project ) throws JavaModelException
+ {
+ assert fullyQualifiedType != null : "Fully qualified type should not be null."; //$NON-NLS-1$
+
+ // the JDT returns a non-null anonymous class IType
+ // for empty string and package names that end with a dot
+ // if the type starts with a dot, the JDT helpfully removes it
+ // and returns the type referenced without the dot
+ // short circuit here for perf and so validation results make sense
+ // e.g. if the valid type is "Thing", then ".Thing" and "Thing." should not be valid
+ if ( fullyQualifiedType.trim().length() == 0
+ || fullyQualifiedType.startsWith(".") //$NON-NLS-1$
+ || fullyQualifiedType.endsWith(".")) //$NON-NLS-1$
+ return null;
+
+ int ltIndex = fullyQualifiedType.indexOf( '<' );
+ int gtIndex = fullyQualifiedType.lastIndexOf( '>' );
+ if ( ltIndex != -1 && gtIndex != -1 && gtIndex > ltIndex )
+ assert false :
+ "Type should have type parameter info stripped before calling this method: " + fullyQualifiedType; //$NON-NLS-1$
+ assert !isArrayType( fullyQualifiedType ) : "Type should have array brackets stripped before calling: " + //$NON-NLS-1$
+ fullyQualifiedType;
+ assert project != null : "Project should not be null."; //$NON-NLS-1$
+
+ // if the project is not accessible, this will cause a JavaModelException below
+ if ( !project.isAccessible() )
+ {
+ return null;
+ }
+
+ IJavaProject javaProject = JavaCore.create( project );
+
+ if (( javaProject == null ) || ( !javaProject.exists() ))
+ {
+ return null;
+ }
+
+ IType type = null;
+ type = javaProject.findType( fullyQualifiedType );
+ if ( type != null && ( !type.exists() || type.isAnonymous() ) )
+ {
+ type = null;
+ }
+ return type;
+ }
+
+ /**
+ * Determines if the class or interface represented by the subtype name is either the same as, or is a superclass
+ * or superinterface of, the class or interface represented by the specified supertype name. It returns true if
+ * so; otherwise it returns false. This method will not block and wait if the required compiler information is not
+ * instantly available - in this case it will return false right away. Callers should be aware that false can
+ * sometimes mean that "we could neither confirm nor deny that the type is assignable from the super type". Callers
+ * should handle this by calling this method as often as needed and not caching the result. Type parameter
+ * information should be removed before calling this method (see {@link #stripTypeParameters(String)} for
+ * this purpose).
+ * @param fullyQualifiedSubTypeName The subtype name.
+ * @param fullyQualifiedSuperTypeName The supertype name.
+ * @param project The relevant project. If null is passed for this parameter, then it attempts to
+ * determine the active Java project based on the current editor. If no Java project can be
+ * determined, then this method will definitley return false.
+ */
+ public static boolean isAssignableFrom( String fullyQualifiedSubTypeName, String fullyQualifiedSuperTypeName,
+ IProject project ) throws JavaModelException
+ {
+ assert fullyQualifiedSubTypeName != null : "Sub type name was null."; //$NON-NLS-1$
+ assert fullyQualifiedSuperTypeName != null : "Super type name was null."; //$NON-NLS-1$
+ assert fullyQualifiedSubTypeName.indexOf( '<' ) == -1 :
+ "Subtype should have type parameter info stripped before calling this method: " + //$NON-NLS-1$
+ fullyQualifiedSubTypeName;
+ assert fullyQualifiedSuperTypeName.indexOf( '<' ) == -1 :
+ "Supertype should have type parameter info stripped before calling this method: " + //$NON-NLS-1$
+ fullyQualifiedSuperTypeName;
+ boolean assignableFrom = false;
+
+ if ( project != null )
+ {
+ IType subType = getType( fullyQualifiedSubTypeName, project );
+ IType superType = getType( fullyQualifiedSuperTypeName, project );
+
+ if ( subType != null && superType != null )
+ {
+ ITypeHierarchy th = subType.newSupertypeHierarchy( null );
+ assert th != null : "Type hierarchy was null."; //$NON-NLS-1$
+ assignableFrom = th.contains( superType );
+ }
+ }
+
+ return assignableFrom;
+ }
+
+ /**
+ * Resolves a type name against an IType to get a fully qualified type name. If
+ * it cannot be resolved for some reason (eg. the type is ambiguous), this returns null.
+ */
+ public static String resolveType( String typeName, IType type ) throws JavaModelException
+ {
+ assert typeName != null : "Type name was null."; //$NON-NLS-1$
+ assert type != null : "Type was null."; //$NON-NLS-1$
+ int bracketIndex = typeName.indexOf( '[' );
+ int typeParamIndex = typeName.indexOf( '<' );
+ int suffixIndex = -1;
+ String typeSuffix = null;
+
+ if ( bracketIndex > -1 && typeParamIndex > -1 )
+ suffixIndex = bracketIndex <= typeParamIndex ? bracketIndex : typeParamIndex;
+ else if ( bracketIndex > -1 )
+ suffixIndex = bracketIndex;
+ else if ( typeParamIndex > -1 )
+ suffixIndex = typeParamIndex;
+
+ if ( suffixIndex > -1 )
+ {
+ typeSuffix = typeName.substring( suffixIndex );
+ typeName = typeName.substring( 0, suffixIndex ).trim();
+ }
+
+ String value = null;
+ String[][] typeMatches = type.resolveType( typeName );
+
+ // If typeMatches.length > 1 then the type was ambiguous. We return null in that case.
+ if ( typeMatches != null && typeMatches.length == 1 )
+ {
+ value = ( typeMatches[0][0].length() == 0 ? typeMatches[0][1] :
+ typeMatches[0][0] + "." + typeMatches[0][1] ); //$NON-NLS-1$
+ }
+
+ if ( value == null && type.isBinary() )
+ {
+ // For some reason, resolving types against binary types doesn't always
+ // (ever?) work. If the type we're trying to resolve it against is binary,
+ // try to resolve against the project instead (and since there should only
+ // be one reachable type with a given fully qualified name on the project
+ // classpath anyway, this should be legit).
+ IProject project = type.getJavaProject().getProject();
+ assert project != null : "Project was null."; //$NON-NLS-1$
+ IType resolvedType = getType( typeName, project );
+
+ if ( resolvedType != null )
+ value = resolvedType.getFullyQualifiedName( '.' );
+ }
+
+ if ( value != null && typeSuffix != null )
+ value += typeSuffix;
+
+ return value;
+ }
+
+
+ /**
+ * Strips out package information and returns the java class name
+ * If the class uses &lt;&gt;, then keep that in.
+ * Examples: <pre>
+ * getClassName("MyClass") = "MyClass"
+ * getClassName("java.util.ArrayList") = "ArrayList"
+ * getClassName("java.util.String[]") = "String[]"
+ * getClassName("java.util.ArrayList&lt;java.lang.String&gt;") = "ArrayList&lt;String&gt;"
+ * getClassName("java.util.ArrayList&lt;java.lang.ArrayList&lt;String&gt;&gt;") = ArrayList&lt;ArrayList&lt;String&gt;&gt;
+ * getClassName("java.util.ArrayList&lt;java.lang.String[]&gt;[]") = ArrayList&lt;String[]&gt;[]
+ * </pre>
+ * @param fullClassName the fully qualified class name
+ * @return the name of the class
+ */
+ public static String getClassName( String fullClassName )
+ {
+ if ( fullClassName == null )
+ {
+ return null;
+ }
+ else
+ {
+ int endBracket = fullClassName.lastIndexOf('>'); //$NON-NLS-1$
+ if (endBracket >= 0)
+ {
+ int beginBracket = fullClassName.indexOf('<'); //$NON-NLS-1$
+ assert beginBracket >= 0 : "no matching '<' for '>' in " + fullClassName; //$NON-NLS-1$
+ assert beginBracket < endBracket : "bad class syntax in " + fullClassName; //$NON-NLS-1$
+ return (getClassName(fullClassName.substring(0, beginBracket)) + "<" + //$NON-NLS-1$
+ getClassName(fullClassName.substring(beginBracket + 1, endBracket)) + ">" + //$NON-NLS-1$
+ fullClassName.substring(endBracket + 1));
+ }
+ else
+ {
+ int dotpos = fullClassName.lastIndexOf( '.' );
+ return ( dotpos < 0 )? fullClassName : fullClassName.substring( dotpos + 1 );
+ }
+ }
+ }
+
+ /******************************************************************************
+ * Determines is two objects are equal, accounting for one or both
+ * objects being null or the two objects being array types.
+ * @param o1 The first object to compare.
+ * @param o2 The second object to compare.
+ * @return True if the two objects are equal.
+ ******************************************************************************/
+ public static final boolean areEqual( Object o1, Object o2 )
+ {
+ boolean objectsAreEqual = false;
+ if( o1 == o2 )
+ {
+ objectsAreEqual = true;
+ }
+ else if ( o1 != null && o2 != null )
+ {
+ if ( o1.getClass().isArray() && o2.getClass().isArray() )
+ {
+ objectsAreEqual = Arrays.equals(
+ ( Object[] ) o1, ( Object[] ) o2 );
+ }
+ else
+ {
+ objectsAreEqual = o1.equals( o2 );
+ }
+ }
+
+ return objectsAreEqual;
+ }
+
+ public static String dbNameToJavaName(String dbName)
+ {
+ String result = dbName;
+ if (StringTools.isUppercase(result) || StringTools.isLowercase(result)) {
+ // leave mixed case identifiers alone?
+ result = StringTools.convertAllCapsToCamelCase(result, false);
+ }
+ result = NameTools.convertToJavaIdentifier(result);
+ return result;
+ }
+
+ /**
+ * Utility methods used to convert DB object names to
+ * appropriate Java type and field name
+ */
+ public static String pluralise(String name) {
+ String result = name;
+ if (name.length() == 1) {
+ result += 's';
+ } else if (!seemsPluralised(name)) {
+ String lower = name.toLowerCase();
+ if (!lower.endsWith("data")) { //orderData --> orderDatas is dumb
+ char secondLast = lower.charAt(name.length() - 2);
+ if (!isVowel(secondLast) && lower.endsWith("y")) {
+ // city, body etc --> cities, bodies
+ result = name.substring(0, name.length() - 1) + "ies";
+ } else if (lower.endsWith("ch") || lower.endsWith("s")) {
+ // switch --> switches or bus --> buses
+ result = name + "es";
+ } else {
+ result = name + "s";
+ }
+ }
+ }
+ return result;
+ }
+
+ public static String singularise(String name) {
+ String result = name;
+ if (seemsPluralised(name)) {
+ String lower = name.toLowerCase();
+ if (lower.endsWith("ies")) {
+ // cities --> city
+ result = name.substring(0, name.length() - 3) + "y";
+ } else if (lower.endsWith("ches") || lower.endsWith("ses")) {
+ // switches --> switch or buses --> bus
+ result = name.substring(0, name.length() - 2);
+ } else if (lower.endsWith("s")) {
+ // customers --> customer
+ result = name.substring(0, name.length() - 1);
+ }
+ }
+ return result;
+ }
+ private final static boolean isVowel(char c) {
+ boolean vowel = false;
+ vowel |= c == 'a';
+ vowel |= c == 'e';
+ vowel |= c == 'i';
+ vowel |= c == 'o';
+ vowel |= c == 'u';
+ vowel |= c == 'y';
+ return vowel;
+ }
+ private static boolean seemsPluralised(String name) {
+ name = name.toLowerCase();
+ boolean pluralised = false;
+ pluralised |= name.endsWith("es");
+ pluralised |= name.endsWith("s");
+ pluralised &= !(name.endsWith("ss") || name.endsWith("us"));
+ return pluralised;
+ }
+
+}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.annotate/src/org/eclipse/jpt/jpa/annotate/util/DefaultTableUtil.java b/jpa/plugins/org.eclipse.jpt.jpa.annotate/src/org/eclipse/jpt/jpa/annotate/util/DefaultTableUtil.java
new file mode 100644
index 0000000..594ba2f
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.jpa.annotate/src/org/eclipse/jpt/jpa/annotate/util/DefaultTableUtil.java
@@ -0,0 +1,99 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+
+package org.eclipse.jpt.jpa.annotate.util;
+
+import java.util.Iterator;
+
+import org.eclipse.jpt.jpa.core.context.Entity;
+import org.eclipse.jpt.jpa.core.context.persistence.PersistenceUnit;
+import org.eclipse.jpt.jpa.db.Schema;
+import org.eclipse.jpt.jpa.db.Table;
+
+public class DefaultTableUtil
+{
+ public static Table findTable(Schema schema, String javaClassName, PersistenceUnit persistenceUnit)
+ {
+ if (schema == null || javaClassName == null || persistenceUnit == null)
+ {
+ return null;
+ }
+ Table table = null;
+ Entity entity = persistenceUnit.getEntity(javaClassName);
+ if (entity != null)
+ {
+ String tableName = entity.getTable().getName();
+ table = schema.getTableNamed(tableName);
+ }
+
+ if (table == null)
+ {
+ table = findTable(schema, javaClassName);
+ }
+ return table;
+ }
+
+ public static Table findTable(Schema schema, String javaClassName)
+ {
+ if (schema == null || javaClassName == null)
+ {
+ return null;
+ }
+ String simpleClassName = AnnotateMappingUtil.getClassName(javaClassName);
+ Table table = findTableCaseInsensitive(schema, simpleClassName);
+ if (table == null)
+ {
+ simpleClassName = AnnotateMappingUtil.pluralise(simpleClassName);
+ table = findTableCaseInsensitive(schema, simpleClassName);
+ }
+ if (table == null)
+ {
+ simpleClassName = AnnotateMappingUtil.singularise(simpleClassName);
+ table = findTableCaseInsensitive(schema, simpleClassName);
+ }
+ if (table == null)
+ {
+ Iterator<Table> tableIt = schema.getTables().iterator();
+ while (tableIt.hasNext())
+ {
+ Table table2 = tableIt.next();
+ String tableName2 = AnnotateMappingUtil.dbNameToJavaName(table2.getName());
+ if (tableName2.equalsIgnoreCase(simpleClassName))
+ {
+ table = table2;
+ break;
+ }
+ }
+ }
+ return table;
+ }
+
+ private static Table findTableCaseInsensitive(Schema schema, String tableName)
+ {
+ String tableName2 = tableName;
+ Table table = null;
+ if (schema != null)
+ {
+ table = schema.getTableNamed(tableName2);
+ if (table == null)
+ {
+ tableName2 = tableName2.toUpperCase();
+ table = schema.getTableNamed(tableName2);
+ }
+ if (table == null)
+ {
+ tableName2 = tableName2.toLowerCase();
+ table = schema.getTableNamed(tableName2);
+ }
+ }
+ return table;
+ }
+
+}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/META-INF/MANIFEST.MF b/jpa/plugins/org.eclipse.jpt.jpa.ui/META-INF/MANIFEST.MF
index d79c2ff..a346b3b 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/META-INF/MANIFEST.MF
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/META-INF/MANIFEST.MF
@@ -26,6 +26,7 @@ Require-Bundle: org.eclipse.core.expressions;bundle-version="[3.4.0,4.0.0)",
org.eclipse.jpt.jpa.db;bundle-version="[2.0.0,3.0.0)",
org.eclipse.jpt.jpa.db.ui;bundle-version="[2.0.0,3.0.0)",
org.eclipse.jpt.jpa.gen;bundle-version="[2.0.0,3.0.0)",
+ org.eclipse.jpt.jpa.annotate;bundle-version="[1.0.0,3.0.0)",
org.eclipse.jpt.common.utility;bundle-version="[2.0.0,3.0.0)",
org.eclipse.jst.common.annotations.controller;bundle-version="[1.1.100,2.0.0)",
org.eclipse.jst.common.project.facet.core;bundle-version="[1.3.100,2.0.0)",
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/images/objects/key.gif b/jpa/plugins/org.eclipse.jpt.jpa.ui/images/objects/key.gif
new file mode 100644
index 0000000..03af38b
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/images/objects/key.gif
Binary files differ
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/images/objects/list-of-values.png b/jpa/plugins/org.eclipse.jpt.jpa.ui/images/objects/list-of-values.png
new file mode 100644
index 0000000..8081fd9
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/images/objects/list-of-values.png
Binary files differ
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/plugin.properties b/jpa/plugins/org.eclipse.jpt.jpa.ui/plugin.properties
index b9e2ad0..e8ce1ce 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/plugin.properties
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/plugin.properties
@@ -80,4 +80,8 @@ JptCreationToolbar.description = Command group for creating JPA elements
NewEntityAction.label = New Entity
jpaJpqlHyperlinkTarget = JPQL Editor
-jpaJpqlHyperlinkDetector = JPQL Query \ No newline at end of file
+jpaJpqlHyperlinkDetector = JPQL Query
+
+annotateJavaClassWizardName = Entity from Java Class
+annotateJavaClassWizardDescription = Add JPA annotations to an existing Java Class.
+annotateJavaClassActionLabel = Generate Entity from Java Class...
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/plugin.xml b/jpa/plugins/org.eclipse.jpt.jpa.ui/plugin.xml
index 80f0128..bdf3723 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/plugin.xml
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/plugin.xml
@@ -1278,5 +1278,5 @@
name="%jpaJpqlHyperlinkTarget">
</target>
</extension>
-
+
</plugin>
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/property_files/jpt_jpa_ui_make_persistent.properties b/jpa/plugins/org.eclipse.jpt.jpa.ui/property_files/jpt_jpa_ui_make_persistent.properties
new file mode 100644
index 0000000..1d3528a
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/property_files/jpt_jpa_ui_make_persistent.properties
@@ -0,0 +1,100 @@
+################################################################################
+# Copyright (c) 2013 Oracle. All rights reserved.
+# This program and the accompanying materials are made available under the
+# terms of the Eclipse Public License v1.0, which accompanies this distribution
+# and is available at http://www.eclipse.org/legal/epl-v10.html.
+#
+# Contributors:
+# Oracle - initial API and implementation
+################################################################################
+
+ADD=&Add
+REMOVE=&Remove
+BROWSE=B&rowse...
+CASCADE=&Cascade:
+CHOOSE_TYPE=Choose Type
+
+CLASS_MAPPING_PAGE_TYPE_TABLE_COLUMN=Java Class
+CLASS_MAPPING_PAGE_MAPPING_TABLE_COLUMN=Table
+CLASS_MAPPING_PAGE_PRIMARY_KEY_PROPERTY_COLUMN=Primary Key Attribute
+CLASS_MAPPING_PAGE_TITLE=Class Mapping Properties
+CLASS_MAPPING_PAGE_DESC=Specify the mapping database table, and the Java attrbite used as primary key.
+SELECT_TABLE_DLG_TITLE=Table Selection
+SELECT_TABLE_DLG_DESC=&Select a table
+
+PROPS_MAPPING_PAGE_TITLE=Attribute Mapping
+PROPS_MAPPING_PAGE_DESC=Map Java bean attributes to database columns using the Edit button. \
+Use the Remove button to unmap an attribute.
+PROPS_MAPPING_PAGE_LABEL=Attribute mappings:
+PROPS_MAPPING_PAGE_JAVA_CLASS_LABEL=Java Class
+PROPS_MAPPING_PAGE_PROPERTY_NAME_LABEL=Attribute Name
+PROPS_MAPPING_PAGE_PROPERTY_TYPE_LABEL=Attribute Type
+PROPS_MAPPING_PAGE_DATABASE_COLUMN=Database Column/Join
+PROPS_MAPPING_PAGE_COLUMN_TYPE=Column Type
+PROPS_MAPPING_PAGE_COLUMN_TYPE_NA=N/A
+PROPS_MAPPING_PAGE_EDIT=Edit...
+PROPS_MAPPING_PAGE_REMOVE=Remove
+PROPS_MAPPING_PAGE_UNSPECIFIED=(unspecified)
+MAPPED_BY_DESC=Mapped by
+PK_JOIN_COLUMN_DESC=Primary key join columns
+JOIN_TABLE_DESC=join table
+PROPS_MAPPING_PAGE_JOIN_AND=Join %s and %s
+PROPERTY_NAME_LABEL=&Attribute name:
+PROPERTY_TYPE_LABEL=Attribute &type:
+ID_ANNOTATION_DLG_TITLE=Id Annotation
+ID_ANNOTATION_GROUP_DESC=Id attributes
+GENERATION_STRATEGY=&Generation strategy:
+COL_ANNOTATION_GROUP_DESC=Database column
+COLUMN_NAME=&Column name:
+REF_COLUMN_NAME=&Referenced column name:
+UNIQUE=&Unique:
+NULLABLE=&Nullable:
+LENGTH=&Length:
+PRECISION=Pr&ecision:
+SCALE=&Scale:
+INSERTABLE=&Insertable:
+UPDATABLE=Up&datable:
+SELECT_COLUMN_DLG_TITLE=Select Column
+SELECT_COLUMN_DLG_DESC=Select a column for attribute \"%s\":
+SELECT_CASCADE_DLG_TITLE=Choose Cascade Values
+BASIC_ANNOTATION_DLG_TITLE=Basic Annotation
+BASIC_ANNOTATION_GROUP_DESC=Basic attributes
+TEMPORAL=&Temporal type:
+FETCH_TYPE=&Fetch type:
+TOMANY_ANNOTATION_DLG_TITLE=Collection Mapping
+TARGET_ENTITY_GROUP_DESC=Target entity
+TARGET_ENTITY_GROUP_LABEL=&Target entity:
+ORDER_BY_TITLE=Order By
+ORDER_BY_LABEL=&Order by:
+ORDER_BY_DESC=Choose the properties from the \"%s\" entity to be used for sorting:
+PROPS_MAPPING_PAGE_MAPPEDBY=&Mapped by:
+PROPS_MAPPING_PAGE_JOIN_TABLE=&Join table:
+MANY_TO_MANY_PROP_DESC=Many to many attributes
+ONE_TO_MANY_PROP_DESC=One to many attributes
+MANY_TO_ONE_PROP_DESC=Many to one attributes
+ONE_TO_ONE_PROP_DESC=One to one attributes
+JOIN_PROPS=Join Attributes
+REF_TABLE_NOT_SPECIFIED=The referenced table is not specified!
+ADD_JOIN_COLUMN=Add join column
+JOIN_COLUMN_TABLE_DESC=%s - %s Join:
+NO_JOIN_COLUMN_LABEL=No %s - %s Join.
+ADD_JOIN_COLUMN_DLG_TITLE=Add Join Column
+ASSOCIATION_WIZARD_TITLE=Collection Mapping
+ASSOCIATION_WIZARD_ERROR=Error
+ASSOCIATION_WIZARD_NO_TARGET_ENTITY=A target entity is not specified for the \"%s\" attribute.
+CARDINALITY_PAGE_TITLE=Cardinality
+CARDINALITY_PAGE_DESC=Specify the mapping cardinality.
+MAPPING_PAGE_TITLE=Collection Mapping
+MAPPING_PAGE_DESC=Specify the mapping attributes.
+JOIN_PROPS_PAGE_TITLE=Join Strategy
+JOIN_PROPS_PAGE_DESC=Specify the join strategy.
+CHOOSE_PROPERTY_TITLE=Choose Attribute
+CHOOSE_PROPERTY_DESC=Choose a field from the \"%s\" entity for the \"%s\" attribute:
+PK_JOIN_COLUMNS_LABEL=Primary key join columns:
+JOIN_COLUMNS_LABEL=Join columns:
+EDIT_JOIN_COLUMNS=Edit Join Columns
+EDIT_JOIN_COLUMNS_DESC=Edit the join columns between %s and %s tables:
+SELECT_ORDERBY_DIALOG_PROPERTY=Attribute
+SELECT_ORDERBY_DIALOG_ORDER=Order
+
+
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/JptJpaUiImages.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/JptJpaUiImages.java
index f24ac42..77ccd7a 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/JptJpaUiImages.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/JptJpaUiImages.java
@@ -117,6 +117,10 @@ public final class JptJpaUiImages {
public static final ImageDescriptor ENTITY_GEN_COLUMN = buildImageDescriptor(OBJECTS_ + "entity-gen-column.gif");
public static final ImageDescriptor ENTITY_GEN_KEY_COLUMN = buildImageDescriptor(OBJECTS_ + "entity-gen-column-key.gif");
+ // ********** make persistent database **********
+
+ public static final ImageDescriptor LIST_OF_VALUES = buildImageDescriptor(OBJECTS_ + "list-of-values.png");
+ public static final ImageDescriptor KEY = buildImageDescriptor(OBJECTS_ + "key.gif");
// ********** misc **********
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/handlers/MakePersistentHandler.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/handlers/MakePersistentHandler.java
index 5a8fd56..93811c3 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/handlers/MakePersistentHandler.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/handlers/MakePersistentHandler.java
@@ -29,7 +29,7 @@ import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.jface.wizard.WizardDialog;
import org.eclipse.jpt.jpa.core.JpaProject;
import org.eclipse.jpt.jpa.ui.internal.plugin.JptJpaUiPlugin;
-import org.eclipse.jpt.jpa.ui.internal.wizards.JpaMakePersistentWizard;
+import org.eclipse.jpt.jpa.ui.internal.wizards.makepersistent.JpaMakePersistentWizard;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.handlers.HandlerUtil;
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/JpaMakePersistentWizard.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/JpaMakePersistentWizard.java
deleted file mode 100644
index 81e0bfe..0000000
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/JpaMakePersistentWizard.java
+++ /dev/null
@@ -1,87 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2010, 2013 Oracle. All rights reserved.
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0, which accompanies this distribution
- * and is available at http://www.eclipse.org/legal/epl-v10.html.
- *
- * Contributors:
- * Oracle - initial API and implementation
- ******************************************************************************/
-package org.eclipse.jpt.jpa.ui.internal.wizards;
-
-import java.lang.reflect.InvocationTargetException;
-import java.util.Set;
-import org.eclipse.jdt.core.IType;
-import org.eclipse.jface.resource.JFaceResources;
-import org.eclipse.jface.resource.LocalResourceManager;
-import org.eclipse.jface.resource.ResourceManager;
-import org.eclipse.jface.wizard.Wizard;
-import org.eclipse.jpt.common.core.internal.utility.PlatformTools;
-import org.eclipse.jpt.jpa.core.JpaProject;
-import org.eclipse.jpt.jpa.ui.JpaWorkbench;
-import org.eclipse.jpt.jpa.ui.JptJpaUiImages;
-import org.eclipse.jpt.jpa.ui.JptJpaUiMessages;
-import org.eclipse.jpt.jpa.ui.internal.plugin.JptJpaUiPlugin;
-import org.eclipse.ui.IWorkbench;
-import org.eclipse.ui.PlatformUI;
-
-public class JpaMakePersistentWizard
- extends Wizard
-{
- private final JpaProject jpaProject;
-
- private final Set<IType> selectedTypes;
-
- private final ResourceManager resourceManager;
-
- private JpaMakePersistentWizardPage makePersistentWizardPage;
-
- private static final String HELP_CONTEXT_ID = JptJpaUiPlugin.instance().getPluginID() + ".GenerateEntitiesFromSchemaWizard"; //$NON-NLS-1$
-
-
- public JpaMakePersistentWizard(JpaProject jpaProject, Set<IType> selectedTypes) {
- super();
- this.jpaProject = jpaProject;
- this.selectedTypes = selectedTypes;
- this.resourceManager = this.buildResourceManager();
- this.setWindowTitle(JptJpaUiMessages.JpaMakePersistentWizardPage_title);
- this.setDefaultPageImageDescriptor(JptJpaUiImages.ENTITY_BANNER);
- }
-
- protected ResourceManager buildResourceManager() {
- JpaWorkbench jpaWorkbench = this.getJpaWorkbench();
- return (jpaWorkbench != null) ? jpaWorkbench.buildLocalResourceManager() : new LocalResourceManager(JFaceResources.getResources(this.getWorkbench().getDisplay()));
- }
-
- private JpaWorkbench getJpaWorkbench() {
- return PlatformTools.getAdapter(this.getWorkbench(), JpaWorkbench.class);
- }
-
- private IWorkbench getWorkbench() {
- return PlatformUI.getWorkbench();
- }
-
- @Override
- public void addPages() {
- this.setForcePreviousAndNextButtons(true);
- this.makePersistentWizardPage = new JpaMakePersistentWizardPage(this.jpaProject, this.selectedTypes, this.resourceManager, HELP_CONTEXT_ID);
- this.addPage(this.makePersistentWizardPage);
- return;
- }
-
- @Override
- public boolean performFinish() {
- try {
- this.makePersistentWizardPage.performFinish();
- } catch (InvocationTargetException ex) {
- JptJpaUiPlugin.instance().logError(ex);
- }
- return true;
- }
-
- @Override
- public void dispose() {
- this.resourceManager.dispose();
- super.dispose();
- }
-}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/gen/DatabaseGroup.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/gen/DatabaseGroup.java
index 7955b3e..bddd415 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/gen/DatabaseGroup.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/gen/DatabaseGroup.java
@@ -80,7 +80,7 @@ public class DatabaseGroup
// ********** construction **********
- protected DatabaseGroup(IWizardContainer wizardContainer, JpaProject jpaProject, Composite parent, ResourceManager resourceManager, int widthHint) {
+ public DatabaseGroup(IWizardContainer wizardContainer, JpaProject jpaProject, Composite parent, ResourceManager resourceManager, int widthHint) {
super();
this.wizardContainer = wizardContainer;
this.jpaProject = jpaProject;
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/makepersistent/AddJoinColumnDlg.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/makepersistent/AddJoinColumnDlg.java
new file mode 100644
index 0000000..c94cb9d
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/makepersistent/AddJoinColumnDlg.java
@@ -0,0 +1,225 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+
+package org.eclipse.jpt.jpa.ui.internal.wizards.makepersistent;
+
+
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.resource.ResourceManager;
+import org.eclipse.jpt.jpa.annotate.mapping.ColumnAttributes;
+import org.eclipse.jpt.jpa.annotate.mapping.EntityRefPropertyElem;
+import org.eclipse.jpt.jpa.db.Table;
+import org.eclipse.jpt.jpa.ui.JptJpaUiImages;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Combo;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Text;
+
+public class AddJoinColumnDlg extends Dialog
+{
+ private Table table;
+ private Table refTable;
+ private Text colNameText;
+ private Button colNameBrowseBtn;
+ private Button uniqueChkbox;
+ private Combo nullableCombo;
+ private Combo insertableCombo;
+ private Combo updatableCombo;
+ private Text refColNameText;
+ private Button refColNameBrowseBtn;
+ private ColumnAttributes colAttrs;
+ private ResourceManager resourceManager;
+ private EntityRefPropertyElem entityRefElem;
+
+ public AddJoinColumnDlg(Shell shell, ResourceManager resourceManager, Table table, Table refTable,
+ EntityRefPropertyElem entityRefElem)
+ {
+ super(shell);
+ this.table = table;
+ this.refTable = refTable;
+ this.resourceManager = resourceManager;
+ this.entityRefElem = entityRefElem;
+ colAttrs = new ColumnAttributes();
+ }
+
+ @Override
+ protected void configureShell(Shell newShell)
+ {
+ newShell.setText(JptJpaUiMakePersistentMessages.ADD_JOIN_COLUMN_DLG_TITLE);
+ super.configureShell(newShell);
+ }
+
+ @Override
+ protected Control createDialogArea(Composite parent)
+ {
+ initializeDialogUnits(parent);
+
+ Composite composite = (Composite)super.createDialogArea(parent);
+ GridLayout gl = new GridLayout(3, false);
+ composite.setLayout(gl);
+ GridData gd = new GridData();
+ gd.widthHint = 300;
+ composite.setLayoutData(gd);
+
+ // Column name
+ AssociationAnnotationWizard.createLabel(composite, 1,
+ JptJpaUiMakePersistentMessages.COLUMN_NAME,
+ -1);
+ colNameText = AssociationAnnotationWizard.createText(composite, true, 1, SWT.BORDER);
+ colNameBrowseBtn = AssociationAnnotationWizard.createImageButton(
+ composite, resourceManager.createImage(JptJpaUiImages.LIST_OF_VALUES), 1, SWT.NONE,
+ JptJpaUiMakePersistentMessages.BROWSE);
+ // unique
+ AssociationAnnotationWizard.createLabel(composite, 1,
+ JptJpaUiMakePersistentMessages.UNIQUE,
+ -1);
+ uniqueChkbox = AssociationAnnotationWizard.createButton(composite, 2,
+ null, -1, SWT.CHECK);
+
+ String[] booleanVals = new String[] {"true", "false"};
+ // nullable
+ AssociationAnnotationWizard.createLabel(composite, 1,
+ JptJpaUiMakePersistentMessages.NULLABLE,
+ -1);
+ nullableCombo = AssociationAnnotationWizard.createCombo(composite, true, 1,
+ SWT.BORDER | SWT.READ_ONLY | SWT.DROP_DOWN, -1);
+ nullableCombo.setItems(booleanVals);
+ new Label(composite, SWT.NULL);
+
+ // insertable
+ AssociationAnnotationWizard.createLabel(composite, 1,
+ JptJpaUiMakePersistentMessages.INSERTABLE,
+ -1);
+ insertableCombo = AssociationAnnotationWizard.createCombo(composite, true, 1,
+ SWT.BORDER | SWT.READ_ONLY | SWT.DROP_DOWN, -1);
+ insertableCombo.setItems(booleanVals);
+ new Label(composite, SWT.NULL);
+
+ // updatable
+ AssociationAnnotationWizard.createLabel(composite, 1,
+ JptJpaUiMakePersistentMessages.UPDATABLE,
+ -1);
+ updatableCombo = AssociationAnnotationWizard.createCombo(composite, true, 1,
+ SWT.BORDER | SWT.READ_ONLY | SWT.DROP_DOWN, -1);
+ updatableCombo.setItems(booleanVals);
+ new Label(composite, SWT.NULL);
+
+ // reference column name
+ // Column name
+ AssociationAnnotationWizard.createLabel(composite, 1,
+ JptJpaUiMakePersistentMessages.REF_COLUMN_NAME,
+ -1);
+ refColNameText = AssociationAnnotationWizard.createText(composite, true, 1, SWT.BORDER);
+ refColNameBrowseBtn = AssociationAnnotationWizard.createImageButton(
+ composite, resourceManager.createImage(JptJpaUiImages.LIST_OF_VALUES), 1, SWT.NONE,
+ JptJpaUiMakePersistentMessages.BROWSE);
+
+ addListeners();
+ return composite;
+ }
+
+ @Override
+ protected boolean isResizable()
+ {
+ return true;
+ }
+
+ private void addListeners()
+ {
+ colNameText.addModifyListener(new ModifyListener()
+ {
+ public void modifyText(ModifyEvent e)
+ {
+ colAttrs.setName(colNameText.getText());
+ }
+ });
+ colNameBrowseBtn.addSelectionListener(new SelectionAdapter()
+ {
+ @Override
+ public void widgetSelected(SelectionEvent e)
+ {
+ SelectColumnDialog dlg = new SelectColumnDialog(Display.getDefault().getActiveShell(),
+ table, entityRefElem.getPropertyName());
+ if (dlg.open() == Dialog.OK)
+ {
+ colNameText.setText(dlg.getSelectedColumn());
+ }
+ }
+ });
+ uniqueChkbox.addSelectionListener(new SelectionAdapter()
+ {
+ @Override
+ public void widgetSelected(SelectionEvent e)
+ {
+ colAttrs.setUnique(uniqueChkbox.getSelection());
+ }
+ });
+ nullableCombo.addSelectionListener(new SelectionAdapter()
+ {
+ @Override
+ public void widgetSelected(SelectionEvent e)
+ {
+ colAttrs.setNullable(nullableCombo.getSelectionIndex() == 0);
+ }
+ });
+ insertableCombo.addSelectionListener(new SelectionAdapter()
+ {
+ @Override
+ public void widgetSelected(SelectionEvent e)
+ {
+ colAttrs.setInsertable(insertableCombo.getSelectionIndex() == 0);
+ }
+ });
+ updatableCombo.addSelectionListener(new SelectionAdapter()
+ {
+ @Override
+ public void widgetSelected(SelectionEvent e)
+ {
+ colAttrs.setUpdatable(updatableCombo.getSelectionIndex() == 0);
+ }
+ });
+ refColNameText.addModifyListener(new ModifyListener()
+ {
+ public void modifyText(ModifyEvent e)
+ {
+ colAttrs.setReferencedColumnName(refColNameText.getText());
+ }
+ });
+ refColNameBrowseBtn.addSelectionListener(new SelectionAdapter()
+ {
+ @Override
+ public void widgetSelected(SelectionEvent e)
+ {
+ SelectColumnDialog dlg = new SelectColumnDialog(Display.getDefault().getActiveShell(),
+ refTable, entityRefElem.getPropertyName());
+ if (dlg.open() == Dialog.OK)
+ {
+ refColNameText.setText(dlg.getSelectedColumn());
+ }
+ }
+ });
+ }
+
+ public ColumnAttributes getNewJoinColumn()
+ {
+ return colAttrs;
+ }
+}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/makepersistent/AssociationAnnotationWizard.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/makepersistent/AssociationAnnotationWizard.java
new file mode 100644
index 0000000..c9bf27b
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/makepersistent/AssociationAnnotationWizard.java
@@ -0,0 +1,330 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+
+package org.eclipse.jpt.jpa.ui.internal.wizards.makepersistent;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.jface.resource.ResourceManager;
+import org.eclipse.jface.wizard.IWizardPage;
+import org.eclipse.jface.wizard.Wizard;
+import org.eclipse.jface.wizard.WizardPage;
+import org.eclipse.jpt.jpa.annotate.mapping.EntityRefPropertyElem;
+import org.eclipse.jpt.jpa.annotate.util.DefaultTableUtil;
+import org.eclipse.jpt.jpa.core.context.persistence.PersistenceUnit;
+import org.eclipse.jpt.jpa.core.resource.orm.JPA;
+import org.eclipse.jpt.jpa.db.Schema;
+import org.eclipse.jpt.jpa.db.Table;
+import org.eclipse.jpt.jpa.ui.internal.plugin.JptJpaUiPlugin;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Combo;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.MessageBox;
+import org.eclipse.swt.widgets.Text;
+
+public class AssociationAnnotationWizard extends Wizard
+{
+ protected final static int JOIN_PROP_GROUP_HEIGHT = 300;
+ private PersistenceUnit persistenceUnit;
+ private ResourceManager resourceManager;
+ private EntityRefPropertyElem refElem;
+ private IProject project;
+ private Schema schema;
+ private String javaClass;
+ private Table table;
+ private CardinalityPage cardinalityPage;
+ private ManyToManyMappingPage mtmPage;
+ private OneToManyMappingPage otmPage;
+ private ManyToOneMappingPage mtoPage;
+ private OneToOneMappingPage otoPage;
+ private ManyToManyJoinPropsPage mtmJoinPropsPage;
+ private OneToManyJoinPropsPage otmJoinPropsPage;
+ private ManyToOneJoinPropsPage mtoJoinPropsPage;
+ private OneToOneJoinPropsPage otoJoinPropsPage;
+ private Button oneToManyRadio;
+ private Button manyToManyRadio;
+ private Button oneToOneRadio;
+ private Button manyToOneRadio;
+
+ public AssociationAnnotationWizard(PersistenceUnit persistenceUnit, ResourceManager resourceManager,
+ IProject project, String javaClass,
+ Schema schema, Table table, EntityRefPropertyElem refElem)
+ {
+ this.persistenceUnit = persistenceUnit;
+ this.resourceManager = resourceManager;
+ this.project = project;
+ this.javaClass = javaClass;
+ this.schema = schema;
+ this.table = table;
+ this.refElem = refElem;
+ setWindowTitle(JptJpaUiMakePersistentMessages.ASSOCIATION_WIZARD_TITLE);
+ }
+
+ @Override
+ public void addPages()
+ {
+ try
+ {
+ super.addPages();
+ cardinalityPage = new CardinalityPage(refElem);
+
+ String refClass = refElem.getRefEntityClassName();
+ Table refTable = null;
+ if (refClass.equals(javaClass))
+ {
+ refTable = table;
+ }
+ else
+ {
+ refTable = DefaultTableUtil.findTable(schema, refClass, persistenceUnit);
+ }
+ if (refTable != null)
+ {
+ this.refElem.setReferencedTable(refTable);
+ }
+ mtmJoinPropsPage = new ManyToManyJoinPropsPage(persistenceUnit, resourceManager, project, javaClass, schema, table, refTable, refElem);
+ otmJoinPropsPage = new OneToManyJoinPropsPage(persistenceUnit, resourceManager, project, javaClass, schema, table, refTable, refElem);
+ mtoJoinPropsPage = new ManyToOneJoinPropsPage(persistenceUnit, resourceManager, project, javaClass, schema, table, refTable, refElem);
+ otoJoinPropsPage = new OneToOneJoinPropsPage(persistenceUnit, resourceManager, project, javaClass, schema, table, refTable, refElem);
+ mtmPage = new ManyToManyMappingPage(persistenceUnit, resourceManager, project, refElem, mtmJoinPropsPage);
+ otmPage = new OneToManyMappingPage(persistenceUnit, resourceManager, project, refElem, otmJoinPropsPage);
+ mtoPage = new ManyToOneMappingPage(persistenceUnit, resourceManager, project, refElem, mtoJoinPropsPage);
+ otoPage = new OneToOneMappingPage(persistenceUnit, resourceManager, project, refElem, otoJoinPropsPage);
+ addPage(cardinalityPage);
+ addPage(mtmPage);
+ addPage(otmPage);
+ addPage(mtoPage);
+ addPage(otoPage);
+ addPage(mtmJoinPropsPage);
+ addPage(otmJoinPropsPage);
+ addPage(mtoJoinPropsPage);
+ addPage(otoJoinPropsPage);
+ }
+ catch (Exception e)
+ {
+ JptJpaUiPlugin.instance().logError(e);
+ }
+ }
+
+ @Override
+ public boolean performFinish()
+ {
+ return true;
+ }
+
+ static void displayNoTargetEntityError(String propertyName)
+ {
+ MessageBox msgBox = new MessageBox(Display.getDefault().getActiveShell(), SWT.ERROR);
+ msgBox.setText(JptJpaUiMakePersistentMessages.ASSOCIATION_WIZARD_ERROR);
+ String msg = String.format(JptJpaUiMakePersistentMessages.ASSOCIATION_WIZARD_NO_TARGET_ENTITY,
+ propertyName);
+ msgBox.setMessage(msg);
+ msgBox.open();
+ }
+
+ private class CardinalityPage extends WizardPage
+ {
+ private EntityRefPropertyElem refElem;
+
+ public CardinalityPage(EntityRefPropertyElem refElem)
+ {
+ super("Cardinality Page"); //$NON-NLS-1$
+ this.refElem = refElem;
+ setTitle(JptJpaUiMakePersistentMessages.CARDINALITY_PAGE_TITLE);
+ setMessage(JptJpaUiMakePersistentMessages.CARDINALITY_PAGE_DESC);
+ }
+
+ public void createControl(Composite parent)
+ {
+ initializeDialogUnits(parent);
+
+ Composite composite = new Composite(parent, SWT.NULL);
+ GridLayout gl = new GridLayout(1, false);
+ composite.setLayout(gl);
+ SelectionAdapter selectionAdapter = new SelectionAdapter()
+ {
+ @Override
+ public void widgetSelected(SelectionEvent e)
+ {
+ handleCardinalityChange();
+ }
+ };
+ if (refElem.isOneToMany() || refElem.isManyToMany())
+ {
+ oneToManyRadio = new Button(composite, SWT.RADIO);
+ oneToManyRadio.setText(JPA.ONE_TO_MANY);
+ oneToManyRadio.addSelectionListener(selectionAdapter);
+ manyToManyRadio = new Button(composite, SWT.RADIO);
+ manyToManyRadio.setText(JPA.MANY_TO_MANY);
+ manyToManyRadio.addSelectionListener(selectionAdapter);
+ if (refElem.isOneToMany())
+ oneToManyRadio.setSelection(true);
+ else
+ manyToManyRadio.setSelection(true);
+ }
+ else
+ {
+ oneToOneRadio = new Button(composite, SWT.RADIO);
+ oneToOneRadio.setText(JPA.ONE_TO_ONE);
+ oneToOneRadio.addSelectionListener(selectionAdapter);
+ manyToOneRadio = new Button(composite, SWT.RADIO);
+ manyToOneRadio.setText(JPA.MANY_TO_ONE);
+ manyToOneRadio.addSelectionListener(selectionAdapter);
+ if (refElem.isOneToOne())
+ oneToOneRadio.setSelection(true);
+ else
+ manyToOneRadio.setSelection(true);
+ }
+
+ setControl(composite);
+ }
+
+ @Override
+ public IWizardPage getNextPage()
+ {
+ if (refElem.isOneToMany())
+ return otmPage;
+ else if (refElem.isManyToMany())
+ return mtmPage;
+ else if (refElem.isManyToOne())
+ return mtoPage;
+ else if (refElem.isOneToOne())
+ return otoPage;
+ return null;
+ }
+
+ private void handleCardinalityChange()
+ {
+ if (oneToManyRadio != null && oneToManyRadio.getSelection())
+ {
+ refElem.setTagName(JPA.ONE_TO_MANY);
+ }
+ else if (manyToManyRadio != null && manyToManyRadio.getSelection())
+ {
+ refElem.setTagName(JPA.MANY_TO_MANY);
+ }
+ else if (manyToOneRadio != null && manyToOneRadio.getSelection())
+ {
+ refElem.setTagName(JPA.MANY_TO_ONE);
+ }
+ else if (oneToOneRadio != null && oneToOneRadio.getSelection())
+ {
+ refElem.setTagName(JPA.ONE_TO_ONE);
+ }
+ // need to clear the "mappedBy" attr when switching cardinalities
+ refElem.removeMappedBy();
+ }
+ }
+
+ static Label createLabel(Composite container, int span, String text)
+ {
+ return createLabel(container, span, text, -1);
+ }
+
+ static Label createLabel(Composite container, int span, String text, int widthHint)
+ {
+ Label label = new Label(container, SWT.NONE);
+ label.setText(text);
+ GridData gd = new GridData();
+ gd.horizontalSpan = span;
+ gd.widthHint = widthHint;
+ label.setLayoutData(gd);
+ return label;
+ }
+
+ static Button createButton(Composite container, int span, String text, int widthHint, int style)
+ {
+ Button button = new Button(container, style);
+ if (text != null)
+ button.setText(text);
+ GridData gd = new GridData();
+ gd.horizontalSpan = span;
+ gd.widthHint = widthHint;
+ button.setLayoutData(gd);
+ return button;
+ }
+
+ static Text createText(Composite container, int span, boolean fillHorizontal, String text, int style)
+ {
+ return createText(container, span, fillHorizontal, text, style, -1);
+ }
+
+ static Text createText(Composite container, int span, boolean fillHorizontal, String text, int style, int widthHint)
+ {
+ Text textCtl = new Text(container, style);
+ if (text != null)
+ textCtl.setText(text);
+ GridData gd;
+ if (fillHorizontal)
+ gd = new GridData(GridData.FILL_HORIZONTAL);
+ else
+ gd = new GridData();
+ gd.widthHint = widthHint;
+ gd.horizontalSpan = span;
+ textCtl.setLayoutData(gd);
+ return textCtl;
+ }
+
+ static Button createImageButton(Composite container, Image image, int span, int style, String toolTipText)
+ {
+ Button button = new Button(container, style);
+ button.setImage(image);
+ GridData gd = new GridData(GridData.END, GridData.CENTER, false, false);
+ gd.horizontalSpan = span;
+ button.setLayoutData(gd);
+ if (toolTipText != null)
+ button.setToolTipText(toolTipText);
+ return button;
+ }
+
+ static Combo createCombo(Composite container, boolean fillHorizontal, int colSpan, int style)
+ {
+ return createCombo(container, fillHorizontal, colSpan, style, -1);
+ }
+
+ static Combo createCombo(Composite container, boolean fillHorizontal, int colSpan, int style, int widthHint)
+ {
+ Combo combo = new Combo(container, style);
+ GridData gd;
+ if (fillHorizontal)
+ gd = new GridData(GridData.FILL_HORIZONTAL);
+ else
+ gd = new GridData();
+ gd.widthHint = widthHint;
+ gd.horizontalSpan = colSpan;
+ combo.setLayoutData(gd);
+ return combo;
+ }
+
+ static Text createText(Composite container, boolean fillHorizontal, int colSpan, int style)
+ {
+ Text text = new Text(container, style);
+ GridData gd;
+ if (fillHorizontal)
+ {
+ gd = new GridData(GridData.FILL_HORIZONTAL);
+ }
+ else
+ {
+ gd = new GridData();
+ }
+ gd.horizontalSpan = colSpan;
+ text.setLayoutData(gd);
+ return text;
+ }
+
+}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/makepersistent/BasicAnnotationDialog.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/makepersistent/BasicAnnotationDialog.java
new file mode 100644
index 0000000..d11222f
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/makepersistent/BasicAnnotationDialog.java
@@ -0,0 +1,167 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+
+package org.eclipse.jpt.jpa.ui.internal.wizards.makepersistent;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.resource.ResourceManager;
+import org.eclipse.jpt.jpa.annotate.mapping.AnnotationAttrConverter;
+import org.eclipse.jpt.jpa.annotate.mapping.BasicEntityPropertyElem;
+import org.eclipse.jpt.jpa.annotate.mapping.EntityPropertyElem;
+import org.eclipse.jpt.jpa.annotate.util.AnnotateMappingUtil;
+import org.eclipse.jpt.jpa.db.Table;
+import org.eclipse.jpt.jpa.ui.internal.plugin.JptJpaUiPlugin;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Combo;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Group;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Text;
+
+public class BasicAnnotationDialog extends Dialog
+{
+ private ResourceManager resourceManager;
+ private IProject project;
+ private Table table;
+ private EntityPropertyElem entityProp;
+ private DbColumnAnnotationCtl columnGroupCtl;
+ private Text propNameText;
+ private Text propTypeText;
+ private Combo temporalCombo;
+
+ public BasicAnnotationDialog(Shell parentShell, ResourceManager resourceManager, IProject project,
+ Table table, EntityPropertyElem entityProp)
+ {
+ super(parentShell);
+ this.resourceManager = resourceManager;
+ this.project = project;
+ this.table = table;
+ this.entityProp = entityProp;
+ }
+
+ @Override
+ protected void configureShell(Shell newShell)
+ {
+ newShell.setText(JptJpaUiMakePersistentMessages.BASIC_ANNOTATION_DLG_TITLE);
+ super.configureShell(newShell);
+ }
+
+ @Override
+ protected Control createDialogArea(Composite parent)
+ {
+ Composite composite = (Composite)super.createDialogArea(parent);
+ GridLayout gl = new GridLayout(1, false);
+ gl.verticalSpacing = 10;
+ gl.marginHeight = 10;
+ gl.marginWidth = 10;
+ composite.setLayout(gl);
+ GridData gd = new GridData();
+ gd.widthHint = 400;
+ composite.setLayoutData(gd);
+ createBasicGroup(composite);
+ columnGroupCtl = new DbColumnAnnotationCtl(resourceManager, entityProp, table);
+ columnGroupCtl.createColumnGroup(composite, SWT.NONE);
+ initFields();
+ addListeners();
+ return composite;
+ }
+
+ private Group createBasicGroup(Composite parent)
+ {
+ Group basicGroup = new Group(parent, SWT.NONE);
+ basicGroup.setText(JptJpaUiMakePersistentMessages.BASIC_ANNOTATION_GROUP_DESC);
+ GridLayout layout = new GridLayout(2, false);
+ basicGroup.setLayout(layout);
+ basicGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+ // Property Name
+ AssociationAnnotationWizard.createLabel(basicGroup, 1,
+ JptJpaUiMakePersistentMessages.PROPERTY_NAME_LABEL,
+ -1);
+ propNameText = AssociationAnnotationWizard.createText(basicGroup, 1, true, null,
+ SWT.BORDER | SWT.READ_ONLY);
+
+ // Property type
+ AssociationAnnotationWizard.createLabel(basicGroup, 1,
+ JptJpaUiMakePersistentMessages.PROPERTY_TYPE_LABEL,
+ -1);
+ propTypeText = AssociationAnnotationWizard.createText(basicGroup, 1, true, null,
+ SWT.BORDER | SWT.READ_ONLY);
+
+ // temporal combo if the field is date/time
+ try
+ {
+ if (AnnotateMappingUtil.isDate(entityProp.getPropertyType(), project))
+ {
+ AssociationAnnotationWizard.createLabel(basicGroup, 1,
+ JptJpaUiMakePersistentMessages.TEMPORAL,
+ -1);
+ temporalCombo = AssociationAnnotationWizard.createCombo(basicGroup, true, 1,
+ SWT.BORDER | SWT.READ_ONLY | SWT.DROP_DOWN, -1);
+ }
+ }
+ catch (JavaModelException je)
+ {
+ JptJpaUiPlugin.instance().logError(je);
+ }
+ return basicGroup;
+ }
+
+ private void initFields()
+ {
+ propNameText.setText(entityProp.getPropertyName());
+ propTypeText.setText(entityProp.getPropertyType());
+ if (temporalCombo != null)
+ {
+ String[] temporals = AnnotationAttrConverter.getTagEnumStringValues(AnnotationAttrConverter.TEMPORAL);
+ temporalCombo.setItems(temporals);
+ assert entityProp instanceof BasicEntityPropertyElem;
+ BasicEntityPropertyElem basicProp = (BasicEntityPropertyElem)entityProp;
+ String temporalType = basicProp.getTemporalType();
+ if (temporalType != null)
+ {
+ int index = temporalCombo.indexOf(temporalType);
+ assert index != -1;
+ temporalCombo.select(index);
+ }
+ }
+ columnGroupCtl.initFields();
+ }
+
+ private void addListeners()
+ {
+ if (temporalCombo != null)
+ {
+ temporalCombo.addSelectionListener(new SelectionAdapter()
+ {
+ @Override
+ public void widgetSelected(SelectionEvent e)
+ {
+ handleTemporalTypeChange();
+ }
+ });
+ }
+ columnGroupCtl.addListeners();
+ }
+
+ private void handleTemporalTypeChange()
+ {
+ String newTemporalType = temporalCombo.getItem(temporalCombo.getSelectionIndex());
+ assert entityProp instanceof BasicEntityPropertyElem;
+ BasicEntityPropertyElem basicProp = (BasicEntityPropertyElem)entityProp;
+ basicProp.setTemporalType(newTemporalType);
+ }
+}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/makepersistent/ClassMappingPage.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/makepersistent/ClassMappingPage.java
new file mode 100644
index 0000000..b8ff8aa
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/makepersistent/ClassMappingPage.java
@@ -0,0 +1,532 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+
+package org.eclipse.jpt.jpa.ui.internal.wizards.makepersistent;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.EventListener;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
+import org.eclipse.jdt.core.Flags;
+import org.eclipse.jdt.core.IField;
+import org.eclipse.jdt.core.IType;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jdt.core.Signature;
+import org.eclipse.jdt.ui.JavaElementLabelProvider;
+import org.eclipse.jface.resource.ResourceManager;
+import org.eclipse.jface.viewers.CellEditor;
+import org.eclipse.jface.viewers.ColumnLabelProvider;
+import org.eclipse.jface.viewers.ComboBoxViewerCellEditor;
+import org.eclipse.jface.viewers.EditingSupport;
+import org.eclipse.jface.viewers.IStructuredContentProvider;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.jface.viewers.TableViewerColumn;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jface.wizard.WizardPage;
+import org.eclipse.jpt.common.utility.internal.ClassNameTools;
+import org.eclipse.jpt.common.utility.internal.iterator.IteratorTools;
+import org.eclipse.jpt.jpa.annotate.util.DefaultTableUtil;
+import org.eclipse.jpt.jpa.annotate.util.AnnotateMappingUtil;
+import org.eclipse.jpt.jpa.core.JpaProject;
+import org.eclipse.jpt.jpa.core.MappingKeys;
+import org.eclipse.jpt.jpa.db.Column;
+import org.eclipse.jpt.jpa.db.ConnectionProfile;
+import org.eclipse.jpt.jpa.db.Schema;
+import org.eclipse.jpt.jpa.db.Table;
+import org.eclipse.jpt.jpa.ui.JptJpaUiImages;
+import org.eclipse.jpt.jpa.ui.internal.plugin.JptJpaUiPlugin;
+import org.eclipse.jpt.jpa.ui.internal.wizards.gen.DatabaseGroup;
+import org.eclipse.jpt.jpa.ui.internal.wizards.makepersistent.JpaMakePersistentWizard.TypeComparator;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+
+public class ClassMappingPage extends WizardPage
+{
+ /* CU private */ final JpaProject jpaProject;
+ /* CU private */ final ResourceManager resourceManager;
+ private JavaClassMapping[] javaClassMappings;
+ private JpaMakePersistentWizardPage makePersistentPage;
+ private DatabaseGroup databaseGroup;
+ private Schema schema;
+ private List<String> tableNames;
+ private TableViewer classMappingTableViewer;
+ private final Set<Listener> listeners = Collections.synchronizedSet(new HashSet<Listener>());
+ private static final int TYPE_COLUMN_WIDTH = 200;
+ private static final int DATABASE_TABLE_COLUMN_WIDTH = 200;
+ private static final int PRIMARY_KEY_PROPERTY_COLUMN_WIDTH = 200;
+ private static final int MAPPING_TABLE_HEIGHT = 180;
+
+
+ public ClassMappingPage(JpaProject proj, JavaClassMapping[] javaClassMappings,
+ ResourceManager resourceManager, JpaMakePersistentWizardPage makePersistentPage)
+ {
+ super("Class Mapping Properties"); //$NON-NLS-1$
+ this.resourceManager = resourceManager;
+ this.jpaProject = proj;
+ this.javaClassMappings = javaClassMappings;
+ this.makePersistentPage = makePersistentPage;
+ this.tableNames = new ArrayList<String>();
+ setTitle(JptJpaUiMakePersistentMessages.CLASS_MAPPING_PAGE_TITLE);
+ setMessage(JptJpaUiMakePersistentMessages.CLASS_MAPPING_PAGE_DESC);
+
+ this.makePersistentPage.addListener(new JpaMakePersistentWizardPage.Listener()
+ {
+ public void mappingTypeChanged(JavaClassMapping javaClassMapping)
+ {
+ handleMappingTypeChange(javaClassMapping);
+ }
+ });
+
+ }
+
+ public void createControl(Composite parent)
+ {
+ initializeDialogUnits(parent);
+
+ Composite composite = new Composite(parent, SWT.NULL);
+ GridLayout layout = new GridLayout();
+ layout.numColumns = 3;
+ composite.setLayout(layout);
+
+ this.databaseGroup = createDatabaseGroup(composite, -1);
+
+ // Create class - db table mapping table
+ Composite comp = new Composite( composite , SWT.NONE );
+ GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
+ gridData.horizontalSpan = 3;
+ comp.setLayoutData(gridData);
+ GridLayout gridLayout = new GridLayout(1, false);
+ comp.setLayout(gridLayout);
+
+ this.classMappingTableViewer = new TableViewer(comp, SWT.BORDER | SWT.FULL_SELECTION | SWT.H_SCROLL | SWT.V_SCROLL);
+ this.classMappingTableViewer.getTable().setLinesVisible(true);
+ this.classMappingTableViewer.getTable().setHeaderVisible(true);
+ this.classMappingTableViewer.setContentProvider(new ClassMappingContentProvider());
+ this.classMappingTableViewer.setComparator(new TypeComparator());
+ this.createTypeTableColumn();
+ this.createDBTableColumn();
+ this.createPrimaryKeyPropertyColumn();
+ this.classMappingTableViewer.setInput(this.javaClassMappings);
+
+ GridData data = new GridData(SWT.FILL, SWT.FILL, true, true);
+ data.widthHint = TYPE_COLUMN_WIDTH + DATABASE_TABLE_COLUMN_WIDTH + PRIMARY_KEY_PROPERTY_COLUMN_WIDTH;
+ data.heightHint = MAPPING_TABLE_HEIGHT;
+ this.classMappingTableViewer.getTable().setLayoutData(data);
+
+ setControl(composite);
+ }
+
+ @Override
+ public void dispose() {
+ if(this.databaseGroup != null) {
+ this.databaseGroup.dispose();
+ }
+ super.dispose();
+ }
+
+ public JavaClassMapping[] getJavaClassMappings()
+ {
+ return this.javaClassMappings;
+ }
+
+ public Schema getSchema()
+ {
+ return this.schema;
+ }
+
+ private DatabaseGroup createDatabaseGroup(Composite parent, int widthHint)
+ {
+ DatabaseGroup dbGroup = new DatabaseGroup(this.getContainer(), this.jpaProject, parent, resourceManager, widthHint);
+ /**
+ * listen for when the Database Connection changes its selected schema
+ * so we can keep the page in synch
+ */
+ class DatabasePageListener implements DatabaseGroup.Listener {
+ public void selectedConnectionProfileChanged(ConnectionProfile connectionProfile) {
+ // ignore
+ }
+ public void selectedSchemaChanged(Schema schema) {
+ ClassMappingPage.this.schema = schema;
+ updateTableNames();
+ }
+ }
+ dbGroup.addListener(new DatabasePageListener());
+ dbGroup.init();
+ return dbGroup;
+ }
+
+ protected void createTypeTableColumn()
+ {
+ TableViewerColumn column = new TableViewerColumn(this.classMappingTableViewer, SWT.NONE);
+ column.getColumn().setWidth(TYPE_COLUMN_WIDTH);
+ column.getColumn().setText(JptJpaUiMakePersistentMessages.CLASS_MAPPING_PAGE_TYPE_TABLE_COLUMN);
+ column.setLabelProvider(new TypeColumnLabelProvider());
+ }
+
+ protected void createDBTableColumn()
+ {
+ TableViewerColumn column;
+ column = new TableViewerColumn(this.classMappingTableViewer, SWT.NONE);
+ column.getColumn().setWidth(DATABASE_TABLE_COLUMN_WIDTH);
+ column.getColumn().setText(JptJpaUiMakePersistentMessages.CLASS_MAPPING_PAGE_MAPPING_TABLE_COLUMN);
+
+ column.setEditingSupport(new EditingSupport(this.classMappingTableViewer) {
+ @Override
+ protected Object getValue(Object element)
+ {
+ return ((JavaClassMapping)element).getDBTable();
+ }
+
+ @Override
+ protected void setValue(Object element, Object value) {
+ ((JavaClassMapping) element).setDBTable((String)value);
+ syncPKProp((JavaClassMapping) element);
+ getViewer().update(element, null);
+ fireClassMappingChanged((JavaClassMapping) element);
+ }
+
+ @Override
+ protected CellEditor getCellEditor(Object element) {
+ final ComboBoxViewerCellEditor comboCellEditor =
+ new ComboBoxViewerCellEditor((Composite) ClassMappingPage.this.classMappingTableViewer.getControl());
+
+ comboCellEditor.setLabelProvider(buildDBTableComboCellEditorLabelProvider());
+ comboCellEditor.setContentProvider(buildDBTableComboCellEditorContentProvider());
+ comboCellEditor.setInput(ClassMappingPage.this.tableNames);
+ return comboCellEditor;
+ }
+
+ @Override
+ protected boolean canEdit(Object element) {
+ return true;
+ }
+ });
+
+ column.setLabelProvider(new DBTableColumnLabelProvider());
+ }
+
+ protected void createPrimaryKeyPropertyColumn()
+ {
+ TableViewerColumn column;
+ column = new TableViewerColumn(this.classMappingTableViewer, SWT.NONE);
+ column.getColumn().setWidth(PRIMARY_KEY_PROPERTY_COLUMN_WIDTH);
+ column.getColumn().setText(JptJpaUiMakePersistentMessages.CLASS_MAPPING_PAGE_PRIMARY_KEY_PROPERTY_COLUMN);
+
+ column.setEditingSupport(new EditingSupport(this.classMappingTableViewer) {
+ @Override
+ protected Object getValue(Object element)
+ {
+ return ((JavaClassMapping)element).getPrimaryKeyProperty();
+ }
+
+ @Override
+ protected void setValue(Object element, Object value) {
+ ((JavaClassMapping) element).setPrimaryKeyProperty((String)value);
+ getViewer().update(element, null);
+ fireClassMappingChanged((JavaClassMapping) element);
+ }
+
+ @Override
+ protected CellEditor getCellEditor(Object element) {
+ final ComboBoxViewerCellEditor comboCellEditor =
+ new ComboBoxViewerCellEditor((Composite) ClassMappingPage.this.classMappingTableViewer.getControl());
+
+ comboCellEditor.setLabelProvider(buildDBTableComboCellEditorLabelProvider());
+ comboCellEditor.setContentProvider(buildPrimaryKeyComboCellEditorContentProvider());
+ JavaClassMapping mapping = (JavaClassMapping)element;
+ comboCellEditor.setInput(getPKPropertyNames(mapping.getJDTType()));
+ return comboCellEditor;
+ }
+
+ @Override
+ protected boolean canEdit(Object element) {
+ return true;
+ }
+ });
+
+ column.setLabelProvider(new PrimaryKeyPropertyColumnLabelProvider());
+
+ }
+
+ public void addListener(Listener listener)
+ {
+ if( ! this.listeners.add(listener)) {
+ throw new IllegalArgumentException("duplicate listener: " + listener); //$NON-NLS-1$
+ }
+ }
+
+ public void removeListener(Listener listener)
+ {
+ if( ! this.listeners.remove(listener)) {
+ throw new IllegalArgumentException("missing listener: " + listener); //$NON-NLS-1$
+ }
+ }
+
+ private Iterator<Listener> listeners() {
+ return IteratorTools.clone(this.listeners);
+ }
+
+ private void fireClassMappingChanged(JavaClassMapping javaClassMapping)
+ {
+ for(Iterator<Listener> stream = this.listeners(); stream.hasNext(); )
+ {
+ stream.next().classMappingChanged(javaClassMapping);
+ }
+ }
+
+ private void syncPKProp(JavaClassMapping javaClassMapping)
+ {
+ if (javaClassMapping.getDBTable() != null)
+ {
+ String pkProp = computeDefaultPKProp(javaClassMapping.getDBTable(), javaClassMapping.getJDTType());
+ if (pkProp != null)
+ {
+ javaClassMapping.setPrimaryKeyProperty(pkProp);
+ }
+ }
+ }
+
+ private String computeDefaultPKProp(String tableName, IType jdtType)
+ {
+ Table table = getSchema().getTableNamed(tableName);
+ if (table == null)
+ return null;
+ if (table.getPrimaryKeyColumnsSize() != 1)
+ return null;
+ Column pkCol = table.getPrimaryKeyColumn();
+ String pkPropName = AnnotateMappingUtil.dbNameToJavaName(pkCol.getName());
+ List<String> pkPropNames = getPKPropertyNames(jdtType);
+ for (String temp : pkPropNames)
+ {
+ if (temp.equalsIgnoreCase(pkPropName))
+ return temp;
+ }
+ return null;
+ }
+
+ private String computeDefaultTableName(String fqClassName)
+ {
+ if (this.schema != null)
+ {
+ Table table = DefaultTableUtil.findTable(schema, fqClassName);
+ if (table != null)
+ {
+ return table.getName();
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Returns the property names that could be primary keys
+ */
+ private List<String> getPKPropertyNames(IType jdtType)
+ {
+ List<String> props = new ArrayList<String>();
+ try
+ {
+ IField[] fields = jdtType.getFields();
+ for (IField field : fields)
+ {
+ // filter out static/inherited fields
+ if (Flags.isSuper(field.getFlags()) || Flags.isStatic(field.getFlags()))
+ continue;
+ String typeStr = field.getTypeSignature();
+ typeStr = Signature.toString(typeStr);
+ if (!ClassNameTools.isPrimitive(typeStr))
+ typeStr = AnnotateMappingUtil.resolveType(typeStr, jdtType);
+ if (AnnotateMappingUtil.isString(typeStr) ||
+ AnnotateMappingUtil.isNumeric(typeStr) ||
+ AnnotateMappingUtil.isDate(typeStr, this.jpaProject.getProject()))
+ {
+ props.add(field.getElementName());
+ }
+ }
+ }
+ catch (JavaModelException je)
+ {
+ JptJpaUiPlugin.instance().logError(je);
+ }
+ return props;
+ }
+
+ private void updateTableNames()
+ {
+ tableNames.clear();
+ if (schema != null)
+ {
+ for( Table table : schema.getTables() )
+ {
+ tableNames.add(table.getName());
+ }
+ for (JavaClassMapping javaClassMapping : javaClassMappings)
+ {
+ if (javaClassMapping.getMappingKey().equals(MappingKeys.ENTITY_TYPE_MAPPING_KEY))
+ {
+ String tableName = computeDefaultTableName(javaClassMapping.getName());
+ if (tableName != null)
+ {
+ javaClassMapping.setDBTable(tableName);
+ syncPKProp(javaClassMapping);
+ fireClassMappingChanged(javaClassMapping);
+ }
+ }
+ }
+ }
+ if (this.classMappingTableViewer != null)
+ this.classMappingTableViewer.refresh(true);
+ }
+
+ private void handleMappingTypeChange(JavaClassMapping javaClassMapping)
+ {
+ this.classMappingTableViewer.getTable().clearAll();
+ this.classMappingTableViewer.refresh(true);
+ fireClassMappingChanged(javaClassMapping);
+ }
+
+ /**
+ * Allows clients to listen for changes to the java class mappings
+ */
+ public interface Listener extends EventListener
+ {
+ void classMappingChanged(JavaClassMapping javaClassMapping);
+ }
+
+ //The ComboBoxViewerCellEditor does not support the image, so no reason to implement getImage(Object)
+ protected ColumnLabelProvider buildDBTableComboCellEditorLabelProvider() {
+ return new ColumnLabelProvider() {
+ @Override
+ public String getText(Object element) {
+ return (String)element;
+ }
+ };
+ }
+
+ protected IStructuredContentProvider buildDBTableComboCellEditorContentProvider() {
+ return new IStructuredContentProvider() {
+ public Object[] getElements(Object inputElement) {
+ return ((List<String>)inputElement).toArray();
+ }
+
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ //do nothing
+ }
+
+ public void dispose() {
+ //do nothing
+ }
+ };
+ }
+
+ protected IStructuredContentProvider buildPrimaryKeyComboCellEditorContentProvider() {
+ return new IStructuredContentProvider() {
+ public Object[] getElements(Object inputElement) {
+ return ((List<String>)inputElement).toArray();
+ }
+
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ //do nothing
+ }
+
+ public void dispose() {
+ //do nothing
+ }
+ };
+ }
+
+ private final class ClassMappingContentProvider implements IStructuredContentProvider
+ {
+ public Object[] getElements(Object inputElement)
+ {
+ List<JavaClassMapping> entityMappings = new ArrayList<JavaClassMapping>();
+ JavaClassMapping[] javaClassMappings = (JavaClassMapping[]) inputElement;
+ for (JavaClassMapping javaClassMapping : javaClassMappings)
+ {
+ if (javaClassMapping.getMappingKey().equals(MappingKeys.ENTITY_TYPE_MAPPING_KEY))
+ {
+ entityMappings.add(javaClassMapping);
+ }
+ }
+ return entityMappings.toArray();
+ }
+
+ public void dispose(){}
+
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput)
+ {
+ }
+
+ }
+
+ private final class TypeColumnLabelProvider extends ColumnLabelProvider
+ {
+ private final JavaElementLabelProvider javaElementLabelProvider =
+ new JavaElementLabelProvider(JavaElementLabelProvider.SHOW_POST_QUALIFIED
+ | JavaElementLabelProvider.SHOW_SMALL_ICONS
+ | JavaElementLabelProvider.SHOW_OVERLAY_ICONS);
+
+ @Override
+ public String getText(Object element) {
+ return this.javaElementLabelProvider.getText(((JavaClassMapping) element).getJDTType());
+ }
+
+ @Override
+ public Image getImage(Object element) {
+ return this.javaElementLabelProvider.getImage(((JavaClassMapping) element).getJDTType());
+ }
+ }
+
+ private class DBTableColumnLabelProvider
+ extends ColumnLabelProvider
+ {
+ @Override
+ public String getText(Object element) {
+ JavaClassMapping mapping = (JavaClassMapping)element;
+ return mapping.getDBTable();
+ }
+
+ @Override
+ public Image getImage(Object element) {
+ JavaClassMapping mapping = (JavaClassMapping)element;
+ return (mapping.getDBTable() == null) ? null : this.getResourceManager().createImage(JptJpaUiImages.TABLE);
+ }
+
+ private ResourceManager getResourceManager() {
+ return ClassMappingPage.this.resourceManager;
+ }
+ }
+
+ private class PrimaryKeyPropertyColumnLabelProvider
+ extends ColumnLabelProvider
+ {
+ @Override
+ public String getText(Object element) {
+ JavaClassMapping mapping = (JavaClassMapping)element;
+ return mapping.getPrimaryKeyProperty();
+ }
+
+ @Override
+ public Image getImage(Object element) {
+ JavaClassMapping mapping = (JavaClassMapping)element;
+ return (mapping.getPrimaryKeyProperty() == null) ? null : this.getResourceManager().createImage(JptJpaUiImages.KEY);
+ }
+
+ private ResourceManager getResourceManager() {
+ return ClassMappingPage.this.resourceManager;
+ }
+ }
+}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/makepersistent/DbColumnAnnotationCtl.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/makepersistent/DbColumnAnnotationCtl.java
new file mode 100644
index 0000000..9b0e36f
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/makepersistent/DbColumnAnnotationCtl.java
@@ -0,0 +1,436 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+
+package org.eclipse.jpt.jpa.ui.internal.wizards.makepersistent;
+
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.resource.ResourceManager;
+import org.eclipse.jpt.jpa.annotate.mapping.ColumnAttributes;
+import org.eclipse.jpt.jpa.annotate.mapping.EntityPropertyElem;
+import org.eclipse.jpt.jpa.annotate.util.AnnotateMappingUtil;
+import org.eclipse.jpt.jpa.core.resource.orm.JPA;
+import org.eclipse.jpt.jpa.db.Table;
+import org.eclipse.jpt.jpa.ui.JptJpaUiImages;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Combo;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Group;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Text;
+
+public class DbColumnAnnotationCtl
+{
+ private ResourceManager resourceManager;
+ private EntityPropertyElem entityProp;
+ private Table table;
+ private Text colNameText;
+ private Button colNameBrowseBtn;
+ private Combo nullableCombo;
+ private Button uniqueChkbox;
+ private Text lengthText;
+ private Text precisionText;
+ private Text scaleText;
+ private Combo insertableCombo;
+ private Combo updatableCombo;
+ private boolean isNumeric;
+ private boolean isBasicMapping;
+
+ public DbColumnAnnotationCtl(ResourceManager resourceManager, EntityPropertyElem entityProp,
+ Table table)
+ {
+ this.resourceManager = resourceManager;
+ this.entityProp = entityProp;
+ this.table = table;
+ }
+
+ Composite createColumnGroup(Composite parent, int style)
+ {
+ Group colGroup = new Group(parent, SWT.NONE);
+ colGroup.setText(JptJpaUiMakePersistentMessages.COL_ANNOTATION_GROUP_DESC);
+ GridLayout layout = new GridLayout(3, false);
+ colGroup.setLayout(layout);
+ colGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+ // Column Name
+ AssociationAnnotationWizard.createLabel(colGroup, 1,
+ JptJpaUiMakePersistentMessages.COLUMN_NAME,
+ -1);
+ colNameText = AssociationAnnotationWizard.createText(colGroup, true, 1, SWT.BORDER);
+ colNameBrowseBtn = AssociationAnnotationWizard.createImageButton(
+ colGroup, resourceManager.createImage(JptJpaUiImages.LIST_OF_VALUES), 1, SWT.NONE,
+ JptJpaUiMakePersistentMessages.BROWSE);
+
+ // unique check box if it's basic annotation
+ isBasicMapping = entityProp.getTagName().equals(JPA.BASIC);
+ if (isBasicMapping)
+ {
+ AssociationAnnotationWizard.createLabel(colGroup, 1,
+ JptJpaUiMakePersistentMessages.UNIQUE,
+ -1);
+ uniqueChkbox = AssociationAnnotationWizard.createButton(colGroup, 2,
+ null, -1, SWT.CHECK);
+ }
+
+ // nullable
+ AssociationAnnotationWizard.createLabel(colGroup, 1,
+ JptJpaUiMakePersistentMessages.NULLABLE,
+ -1);
+ nullableCombo = AssociationAnnotationWizard.createCombo(colGroup, true, 1,
+ SWT.BORDER | SWT.READ_ONLY | SWT.DROP_DOWN, -1);
+ new Label(colGroup, SWT.NULL);
+
+ // insertable and updatable for basic mapping
+ if (isBasicMapping)
+ {
+ AssociationAnnotationWizard.createLabel(colGroup, 1,
+ JptJpaUiMakePersistentMessages.INSERTABLE,
+ -1);
+ insertableCombo = AssociationAnnotationWizard.createCombo(colGroup, true, 1,
+ SWT.BORDER | SWT.READ_ONLY | SWT.DROP_DOWN, -1);
+ new Label(colGroup, SWT.NULL);
+
+ AssociationAnnotationWizard.createLabel(colGroup, 1,
+ JptJpaUiMakePersistentMessages.UPDATABLE,
+ -1);
+ updatableCombo = AssociationAnnotationWizard.createCombo(colGroup, true, 1,
+ SWT.BORDER | SWT.READ_ONLY | SWT.DROP_DOWN, -1);
+ new Label(colGroup, SWT.NULL);
+ }
+ // length if field type is not numeric
+ isNumeric = AnnotateMappingUtil.isNumeric(entityProp.getPropertyType());
+ if (!isNumeric)
+ {
+ AssociationAnnotationWizard.createLabel(colGroup, 1,
+ JptJpaUiMakePersistentMessages.LENGTH,
+ -1);
+ lengthText = AssociationAnnotationWizard.createText(colGroup, true, 1, SWT.BORDER);
+ new Label(colGroup, SWT.NULL);
+ }
+ else
+ {
+ // precision and scale if the filed is numeric
+ AssociationAnnotationWizard.createLabel(colGroup, 1,
+ JptJpaUiMakePersistentMessages.PRECISION,
+ -1);
+ precisionText = AssociationAnnotationWizard.createText(colGroup, true, 1, SWT.BORDER);
+ new Label(colGroup, SWT.NULL);
+
+ AssociationAnnotationWizard.createLabel(colGroup, 1,
+ JptJpaUiMakePersistentMessages.SCALE,
+ -1);
+ scaleText = AssociationAnnotationWizard.createText(colGroup, true, 1, SWT.BORDER);
+ new Label(colGroup, SWT.NULL);
+ }
+ return colGroup;
+ }
+
+ void initFields()
+ {
+ String[] boolComboVals = new String[]{"true", "false"};
+ nullableCombo.setItems(boolComboVals);
+ if (isBasicMapping)
+ {
+ insertableCombo.setItems(boolComboVals);
+ updatableCombo.setItems(boolComboVals);
+ }
+ ColumnAttributes colAttrs = entityProp.getColumnAnnotationAttrs();
+ if (colAttrs != null)
+ {
+ // column name
+ if (colAttrs.getName() != null)
+ colNameText.setText(colAttrs.getName());
+ // unique
+ if (colAttrs.isSetUnique() && isBasicMapping)
+ uniqueChkbox.setSelection(colAttrs.isUnique());
+ // nullable
+ if (colAttrs.isSetNullable())
+ {
+ if (colAttrs.isNullable())
+ nullableCombo.select(0);
+ else
+ nullableCombo.select(1);
+ }
+ // length
+ if (!isNumeric)
+ {
+ if (colAttrs.isSetLength())
+ {
+ lengthText.setText(String.valueOf(colAttrs.getLength()));
+ }
+ }
+ else
+ {
+ // precision and scale
+ if (colAttrs.isSetPrecision())
+ {
+ precisionText.setText(String.valueOf(colAttrs.getPrecision()));
+ }
+ if (colAttrs.isSetScale())
+ {
+ scaleText.setText(String.valueOf(colAttrs.getScale()));
+ }
+ }
+ if (isBasicMapping)
+ {
+ // insertable
+ if (colAttrs.isSetInsertable())
+ {
+ if (colAttrs.isInsertable())
+ insertableCombo.select(0);
+ else
+ insertableCombo.select(1);
+ }
+ // updatable
+ if (colAttrs.isSetUpdatable())
+ {
+ if (colAttrs.isUpdatable())
+ updatableCombo.select(0);
+ else
+ updatableCombo.select(1);
+ }
+ }
+ }
+ }
+
+ void addListeners()
+ {
+ colNameText.addModifyListener(new ModifyListener()
+ {
+ public void modifyText(ModifyEvent e)
+ {
+ handleColNameChange();
+ }
+ });
+ colNameBrowseBtn.addSelectionListener(new SelectionAdapter()
+ {
+ @Override
+ public void widgetSelected(SelectionEvent e)
+ {
+ chooseColumn();
+ }
+ });
+ if (isBasicMapping)
+ {
+ uniqueChkbox.addSelectionListener(new SelectionAdapter()
+ {
+ @Override
+ public void widgetSelected(SelectionEvent e)
+ {
+ handleUniqueChange();
+ }
+ });
+ }
+ nullableCombo.addSelectionListener(new SelectionAdapter()
+ {
+ @Override
+ public void widgetSelected(SelectionEvent e)
+ {
+ handleNullableChange();
+ }
+ });
+ if (lengthText != null)
+ {
+ lengthText.addModifyListener(new ModifyListener()
+ {
+ public void modifyText(ModifyEvent e)
+ {
+ handleLengthChange();
+ }
+ });
+ }
+ if (precisionText != null)
+ {
+ precisionText.addModifyListener(new ModifyListener()
+ {
+ public void modifyText(ModifyEvent e)
+ {
+ handlePrecisionChange();
+ }
+ });
+ }
+ if (scaleText != null)
+ {
+ scaleText.addModifyListener(new ModifyListener()
+ {
+ public void modifyText(ModifyEvent e)
+ {
+ handleScaleChange();
+ }
+ });
+ }
+ if (isBasicMapping)
+ {
+ insertableCombo.addSelectionListener(new SelectionAdapter()
+ {
+ @Override
+ public void widgetSelected(SelectionEvent e)
+ {
+ handleInsertableChange();
+ }
+ });
+ updatableCombo.addSelectionListener(new SelectionAdapter()
+ {
+ @Override
+ public void widgetSelected(SelectionEvent e)
+ {
+ handleUpdatableChange();
+ }
+ });
+ }
+ }
+
+ private void handleColNameChange()
+ {
+ ColumnAttributes colAttrs = entityProp.getColumnAnnotationAttrs();
+ entityProp.setDBColumn(table.getColumnNamed(colNameText.getText()));
+ if (colAttrs == null)
+ {
+ colAttrs = new ColumnAttributes();
+ colAttrs.setName(colNameText.getText());
+ entityProp.setColumnAnnotationAttrs(colAttrs);
+ }
+ else
+ {
+ colAttrs.setName(colNameText.getText());
+ }
+
+ }
+ private void chooseColumn()
+ {
+ SelectColumnDialog dlg = new SelectColumnDialog(Display.getDefault().getActiveShell(),
+ table, entityProp.getPropertyName());
+ if (dlg.open() == Dialog.OK)
+ {
+ colNameText.setText(dlg.getSelectedColumn());
+ }
+ }
+
+ private void handleUniqueChange()
+ {
+ boolean isUnique = uniqueChkbox.getSelection();
+ ColumnAttributes colAttrs = entityProp.getColumnAnnotationAttrs();
+ if (colAttrs == null)
+ {
+ colAttrs = new ColumnAttributes();
+ colAttrs.setUnique(isUnique);
+ entityProp.setColumnAnnotationAttrs(colAttrs);
+ }
+ else
+ {
+ colAttrs.setUnique(isUnique);
+ }
+ }
+
+ private void handleNullableChange()
+ {
+ int index = nullableCombo.getSelectionIndex();
+ ColumnAttributes colAttrs = entityProp.getColumnAnnotationAttrs();
+ boolean nullable = index == 0 ? true : false;
+ if (colAttrs == null)
+ {
+ colAttrs = new ColumnAttributes();
+ colAttrs.setNullable(nullable);
+ entityProp.setColumnAnnotationAttrs(colAttrs);
+ }
+ else
+ {
+ colAttrs.setNullable(nullable);
+ }
+ }
+
+ private void handleLengthChange()
+ {
+ // TODO validate
+ ColumnAttributes colAttrs = entityProp.getColumnAnnotationAttrs();
+ if (colAttrs == null)
+ {
+ colAttrs = new ColumnAttributes();
+ colAttrs.setLength(lengthText.getText());
+ entityProp.setColumnAnnotationAttrs(colAttrs);
+ }
+ else
+ {
+ colAttrs.setLength(lengthText.getText());
+ }
+ }
+
+ private void handleScaleChange()
+ {
+ // TODO validate
+ ColumnAttributes colAttrs = entityProp.getColumnAnnotationAttrs();
+ if (colAttrs == null)
+ {
+ colAttrs = new ColumnAttributes();
+ colAttrs.setScale(scaleText.getText());
+ entityProp.setColumnAnnotationAttrs(colAttrs);
+ }
+ else
+ {
+ colAttrs.setScale(scaleText.getText());
+ }
+ }
+
+ private void handlePrecisionChange()
+ {
+ // TODO validate
+ ColumnAttributes colAttrs = entityProp.getColumnAnnotationAttrs();
+ if (colAttrs == null)
+ {
+ colAttrs = new ColumnAttributes();
+ colAttrs.setPrecision(precisionText.getText());
+ entityProp.setColumnAnnotationAttrs(colAttrs);
+ }
+ else
+ {
+ colAttrs.setPrecision(precisionText.getText());
+ }
+ }
+
+ private void handleInsertableChange()
+ {
+ int index = insertableCombo.getSelectionIndex();
+ ColumnAttributes colAttrs = entityProp.getColumnAnnotationAttrs();
+ boolean insertable = index == 0 ? true : false;
+ if (colAttrs == null)
+ {
+ colAttrs = new ColumnAttributes();
+ colAttrs.setInsertable(insertable);
+ entityProp.setColumnAnnotationAttrs(colAttrs);
+ }
+ else
+ {
+ colAttrs.setInsertable(insertable);
+ }
+ }
+
+ private void handleUpdatableChange()
+ {
+ int index = updatableCombo.getSelectionIndex();
+ ColumnAttributes colAttrs = entityProp.getColumnAnnotationAttrs();
+ boolean updatable = index == 0 ? true : false;
+ if (colAttrs == null)
+ {
+ colAttrs = new ColumnAttributes();
+ colAttrs.setUpdatable(updatable);
+ entityProp.setColumnAnnotationAttrs(colAttrs);
+ }
+ else
+ {
+ colAttrs.setUpdatable(updatable);
+ }
+ }
+}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/makepersistent/EntityMappingPage.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/makepersistent/EntityMappingPage.java
new file mode 100644
index 0000000..2a2eb3f
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/makepersistent/EntityMappingPage.java
@@ -0,0 +1,213 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+
+package org.eclipse.jpt.jpa.ui.internal.wizards.makepersistent;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.resource.ResourceManager;
+import org.eclipse.jface.wizard.IWizardPage;
+import org.eclipse.jface.wizard.WizardPage;
+import org.eclipse.jpt.jpa.annotate.mapping.EntityRefPropertyElem;
+import org.eclipse.jpt.jpa.core.context.persistence.PersistenceUnit;
+import org.eclipse.jpt.jpa.ui.JptJpaUiImages;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Group;
+import org.eclipse.swt.widgets.Text;
+
+public class EntityMappingPage extends WizardPage
+{
+ protected static final int JOIN_PROPS_GROUP_MIN_HEIGHT = 400;
+ private PersistenceUnit persistenceUnit;
+ private ResourceManager resourceManager;
+ protected IProject project;
+ protected EntityRefPropertyElem refElem;
+ protected IWizardPage nextPage;
+ private MappingAnnotationCtl mappingCtl;
+ private Group mappingGroup;
+ private Text targetEntityText;
+ private Button targetEntityBrowseBtn;
+ private Text orderByText;
+ private Button orderByBrowseBtn;
+
+ public EntityMappingPage(PersistenceUnit persistenceUnit, ResourceManager resourceManager, IProject project, EntityRefPropertyElem refElem, IWizardPage nextPage)
+ {
+ super("Mapping Properties Page"); //$NON-NLS-1$
+ this.persistenceUnit = persistenceUnit;
+ this.resourceManager = resourceManager;
+ this.project = project;
+ this.refElem = refElem;
+ this.nextPage = nextPage;
+ setTitle(JptJpaUiMakePersistentMessages.MAPPING_PAGE_TITLE);
+ setMessage(JptJpaUiMakePersistentMessages.MAPPING_PAGE_DESC);
+ }
+
+ public void createControl(Composite parent)
+ {
+ initializeDialogUnits(parent);
+
+ Composite composite = new Composite(parent, SWT.NONE);
+ GridLayout gl = new GridLayout(1, true);
+ composite.setLayout(gl);
+ GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
+ gd.widthHint = 400;
+ composite.setLayoutData(gd);
+
+ mappingCtl = new MappingAnnotationCtl(resourceManager, refElem);
+ mappingGroup = (Group)mappingCtl.createMappingPropGroup(composite, SWT.NONE);
+ createTargetEntityGroup(composite);
+ initFields();
+ addListeners();
+ setControl(composite);
+ }
+
+ @Override
+ public void setVisible(boolean visible)
+ {
+ super.setVisible(visible);
+ if (visible)
+ {
+ if (refElem.isOneToMany())
+ mappingGroup.setText(JptJpaUiMakePersistentMessages.ONE_TO_MANY_PROP_DESC);
+ else if (refElem.isManyToMany())
+ mappingGroup.setText(JptJpaUiMakePersistentMessages.MANY_TO_MANY_PROP_DESC);
+ else if (refElem.isManyToOne())
+ mappingGroup.setText(JptJpaUiMakePersistentMessages.MANY_TO_ONE_PROP_DESC);
+ else if (refElem.isOneToOne())
+ mappingGroup.setText(JptJpaUiMakePersistentMessages.ONE_TO_ONE_PROP_DESC);
+ }
+ }
+
+ @Override
+ public IWizardPage getNextPage()
+ {
+ return nextPage;
+ }
+
+ protected Group createTargetEntityGroup(Composite parent)
+ {
+ Group targetEntityGroup = new Group(parent, SWT.NONE);
+ targetEntityGroup.setText(JptJpaUiMakePersistentMessages.TARGET_ENTITY_GROUP_DESC);
+ GridLayout gl = new GridLayout(3, false);
+ targetEntityGroup.setLayout(gl);
+ targetEntityGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+ // target entity
+ AssociationAnnotationWizard.createLabel(targetEntityGroup, 1,
+ JptJpaUiMakePersistentMessages.TARGET_ENTITY_GROUP_LABEL,
+ -1);
+ targetEntityText = AssociationAnnotationWizard.createText(targetEntityGroup, true, 1, SWT.BORDER);
+ targetEntityBrowseBtn = AssociationAnnotationWizard.createImageButton(
+ targetEntityGroup, resourceManager.createImage(JptJpaUiImages.LIST_OF_VALUES), 1, SWT.NONE,
+ JptJpaUiMakePersistentMessages.BROWSE);
+ // order by
+ AssociationAnnotationWizard.createLabel(targetEntityGroup, 1,
+ JptJpaUiMakePersistentMessages.ORDER_BY_LABEL,
+ -1);
+ orderByText = AssociationAnnotationWizard.createText(targetEntityGroup, true, 1, SWT.BORDER);
+ orderByBrowseBtn = AssociationAnnotationWizard.createImageButton(
+ targetEntityGroup, resourceManager.createImage(JptJpaUiImages.LIST_OF_VALUES), 1, SWT.NONE,
+ JptJpaUiMakePersistentMessages.BROWSE);
+
+ return targetEntityGroup;
+ }
+
+ protected PersistenceUnit getPersistenceUnit()
+ {
+ return this.persistenceUnit;
+ }
+
+ protected void initFields()
+ {
+ mappingCtl.initFields();
+ if (refElem.getRefEntityClassName() != null && targetEntityText != null)
+ targetEntityText.setText(refElem.getRefEntityClassName());
+ if (refElem.getOrderBy() != null && orderByText != null)
+ orderByText.setText(refElem.getOrderBy());
+ }
+
+ protected void addListeners()
+ {
+ mappingCtl.addListeners();
+ if (targetEntityText != null)
+ {
+ targetEntityText.addModifyListener(new ModifyListener()
+ {
+ public void modifyText(ModifyEvent e)
+ {
+ refElem.setRefEntityClassName(targetEntityText.getText());
+ }
+ });
+ }
+ if (targetEntityBrowseBtn != null)
+ {
+ targetEntityBrowseBtn.addSelectionListener(new SelectionAdapter()
+ {
+ @Override
+ public void widgetSelected( SelectionEvent e )
+ {
+ String selectedClass = OrmUiUtil.selectJavaClass(project);
+ if (selectedClass != null)
+ targetEntityText.setText(selectedClass);
+ }
+ });
+ }
+
+ if (orderByBrowseBtn != null)
+ {
+ orderByBrowseBtn.addSelectionListener(new SelectionAdapter()
+ {
+ @Override
+ public void widgetSelected( SelectionEvent e )
+ {
+ if (refElem.getRefEntityClassName() == null)
+ {
+ AssociationAnnotationWizard.displayNoTargetEntityError(refElem.getPropertyName());
+ return;
+ }
+ SelectOrderByDialog dlg = new SelectOrderByDialog(Display.getDefault().getActiveShell(),
+ resourceManager, project, refElem.getRefEntityClassName(), refElem.getOrderBy());
+ if (dlg.open() == Dialog.OK)
+ {
+ String orderBy = dlg.getOrderByDisplayStr();
+ if (orderBy != null)
+ orderByText.setText(orderBy);
+ else
+ orderByText.setText("");
+ }
+ }
+ });
+ }
+
+ if (orderByText != null)
+ {
+ orderByText.addModifyListener(new ModifyListener()
+ {
+ public void modifyText(ModifyEvent e)
+ {
+ if (orderByText.getText().length() != 0)
+ refElem.setOrderBy(orderByText.getText());
+ else
+ refElem.setOrderBy(null);
+ }
+ });
+ }
+
+ }
+
+}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/makepersistent/IdAnnotationDialog.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/makepersistent/IdAnnotationDialog.java
new file mode 100644
index 0000000..26e26d5
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/makepersistent/IdAnnotationDialog.java
@@ -0,0 +1,162 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+
+package org.eclipse.jpt.jpa.ui.internal.wizards.makepersistent;
+
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.resource.ResourceManager;
+import org.eclipse.jpt.jpa.annotate.mapping.AnnotationAttrConverter;
+import org.eclipse.jpt.jpa.annotate.mapping.EntityPropertyElem;
+import org.eclipse.jpt.jpa.annotate.mapping.GeneratedValueAttributes;
+import org.eclipse.jpt.jpa.annotate.mapping.IdEntityPropertyElement;
+import org.eclipse.jpt.jpa.db.Table;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Combo;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Group;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Text;
+
+public class IdAnnotationDialog extends Dialog
+{
+ private ResourceManager resourceManager;
+ private EntityPropertyElem entityProp;
+ private Table table;
+ private Text propNameText;
+ private Text propTypeText;
+ private Combo genStrategyCombo;
+ private DbColumnAnnotationCtl columnGroupCtl;
+
+ public IdAnnotationDialog(Shell parentShell, ResourceManager resourceManager, Table table, EntityPropertyElem entityProp)
+ {
+ super(parentShell);
+ this.resourceManager = resourceManager;
+ this.table = table;
+ this.entityProp = entityProp;
+ }
+
+ @Override
+ protected void configureShell(Shell newShell)
+ {
+ newShell.setText(JptJpaUiMakePersistentMessages.ID_ANNOTATION_DLG_TITLE);
+ super.configureShell(newShell);
+ }
+
+ @Override
+ protected Control createDialogArea(Composite parent)
+ {
+ Composite composite = (Composite)super.createDialogArea(parent);
+ GridLayout gl = new GridLayout(1, false);
+ gl.verticalSpacing = 10;
+ gl.marginHeight = 10;
+ gl.marginWidth = 10;
+ composite.setLayout(gl);
+ GridData gd = new GridData();
+ gd.widthHint = 400;
+ composite.setLayoutData(gd);
+ createIdGroup(composite);
+ columnGroupCtl = new DbColumnAnnotationCtl(resourceManager, entityProp, table);
+ columnGroupCtl.createColumnGroup(composite, SWT.NONE);
+ initFields();
+ addListeners();
+ return composite;
+ }
+
+ private Group createIdGroup(Composite parent)
+ {
+ Group idGroup = new Group(parent, SWT.NONE);
+ idGroup.setText(JptJpaUiMakePersistentMessages.ID_ANNOTATION_GROUP_DESC);
+ GridLayout layout = new GridLayout(2, false);
+ idGroup.setLayout(layout);
+ idGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+ // Property Name
+ AssociationAnnotationWizard.createLabel(idGroup, 1,
+ JptJpaUiMakePersistentMessages.PROPERTY_NAME_LABEL,
+ -1);
+ propNameText = AssociationAnnotationWizard.createText(idGroup, 1, true, null,
+ SWT.BORDER | SWT.READ_ONLY);
+
+ // Property type
+ AssociationAnnotationWizard.createLabel(idGroup, 1,
+ JptJpaUiMakePersistentMessages.PROPERTY_TYPE_LABEL,
+ -1);
+ propTypeText = AssociationAnnotationWizard.createText(idGroup, 1, true, null,
+ SWT.BORDER | SWT.READ_ONLY);
+
+ // Generation Strategy
+ AssociationAnnotationWizard.createLabel(idGroup, 1,
+ JptJpaUiMakePersistentMessages.GENERATION_STRATEGY,
+ -1);
+ genStrategyCombo = AssociationAnnotationWizard.createCombo(idGroup, true, 1,
+ SWT.BORDER | SWT.READ_ONLY | SWT.DROP_DOWN, -1);
+ return idGroup;
+ }
+
+ private void initFields()
+ {
+ propNameText.setText(entityProp.getPropertyName());
+ propTypeText.setText(entityProp.getPropertyType());
+
+ String[] strategies = AnnotationAttrConverter.getTagEnumStringValues(AnnotationAttrConverter.GENERATION_STRATEGY);
+ genStrategyCombo.setItems(strategies);
+ assert entityProp instanceof IdEntityPropertyElement;
+ IdEntityPropertyElement idProp = (IdEntityPropertyElement)entityProp;
+ GeneratedValueAttributes genAttrs = idProp.getGeneratedValueAttrs();
+ if (genAttrs != null)
+ {
+ String strategy = genAttrs.getStrategy();
+ if ( strategy!= null)
+ {
+ int index = genStrategyCombo.indexOf(strategy);
+ assert index != -1;
+ genStrategyCombo.select(index);
+ }
+ }
+ columnGroupCtl.initFields();
+ }
+
+ private void addListeners()
+ {
+ genStrategyCombo.addSelectionListener(new SelectionAdapter()
+ {
+ @Override
+ public void widgetSelected(SelectionEvent e)
+ {
+ handleGenStrategyChange();
+ }
+ });
+
+ columnGroupCtl.addListeners();
+ }
+
+ private void handleGenStrategyChange()
+ {
+ String newStrategy = genStrategyCombo.getItem(genStrategyCombo.getSelectionIndex());
+ assert entityProp instanceof IdEntityPropertyElement;
+ IdEntityPropertyElement idProp = (IdEntityPropertyElement)entityProp;
+ GeneratedValueAttributes genAttrs = idProp.getGeneratedValueAttrs();
+ if (genAttrs == null)
+ {
+ genAttrs = new GeneratedValueAttributes();
+ genAttrs.setStrategy(newStrategy);
+ idProp.setGeneratedValueAttrs(genAttrs);
+ }
+ else
+ {
+ genAttrs.setStrategy(newStrategy);
+ }
+ }
+
+}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/makepersistent/JavaClassMapping.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/makepersistent/JavaClassMapping.java
new file mode 100644
index 0000000..98b1a4c
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/makepersistent/JavaClassMapping.java
@@ -0,0 +1,97 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+
+package org.eclipse.jpt.jpa.ui.internal.wizards.makepersistent;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.jdt.core.IType;
+import org.eclipse.jpt.jpa.annotate.mapping.EntityPropertyElem;
+import org.eclipse.jpt.jpa.core.MappingKeys;
+import org.eclipse.jpt.jpa.core.context.PersistentType;
+
+public class JavaClassMapping implements PersistentType.Config
+{
+ private IType jdtType;
+ private String mappingKey;
+ private String dbTable;
+ private String primaryKeyProperty;
+ private List<EntityPropertyElem> propertyMappings;
+
+ public JavaClassMapping(IType itype)
+ {
+ super();
+ this.jdtType = itype;
+ this.mappingKey = MappingKeys.ENTITY_TYPE_MAPPING_KEY;
+ this.propertyMappings = new ArrayList<EntityPropertyElem>();
+ }
+
+ public IType getJDTType()
+ {
+ return this.jdtType;
+ }
+
+ public String getFullyQualifiedName()
+ {
+ return this.jdtType.getFullyQualifiedName();
+ }
+
+ public String getName()
+ {
+ return this.jdtType.getFullyQualifiedName();
+ }
+
+ public String getMappingKey()
+ {
+ return this.mappingKey;
+ }
+
+ protected void setMappingKey(String mappingKey)
+ {
+ this.mappingKey = mappingKey;
+ }
+
+ public void setDBTable(String dbTable)
+ {
+ this.dbTable = dbTable;
+ }
+
+ public String getDBTable()
+ {
+ return this.dbTable;
+ }
+
+ public void setPrimaryKeyProperty(String prop)
+ {
+ this.primaryKeyProperty = prop;
+ }
+
+ public String getPrimaryKeyProperty()
+ {
+ return this.primaryKeyProperty;
+ }
+
+ public List<EntityPropertyElem> getPropertyMappings()
+ {
+ return this.propertyMappings;
+ }
+
+ public void setPropertyMappings(List<EntityPropertyElem> propMappings)
+ {
+ clearPropertyMappings();
+ this.propertyMappings.addAll(propMappings);
+ }
+
+ public void clearPropertyMappings()
+ {
+ this.propertyMappings.clear();
+ }
+}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/makepersistent/JoinColumnsAnnotationEditor.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/makepersistent/JoinColumnsAnnotationEditor.java
new file mode 100644
index 0000000..1e523c2
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/makepersistent/JoinColumnsAnnotationEditor.java
@@ -0,0 +1,461 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+
+package org.eclipse.jpt.jpa.ui.internal.wizards.makepersistent;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.draw2d.ColorConstants;
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.resource.ResourceManager;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.IStructuredContentProvider;
+import org.eclipse.jface.viewers.ITableLabelProvider;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jpt.common.ui.internal.util.SWTUtil;
+import org.eclipse.jpt.jpa.annotate.mapping.ColumnAttributes;
+import org.eclipse.jpt.jpa.annotate.mapping.EntityRefPropertyElem;
+import org.eclipse.jpt.jpa.annotate.mapping.JoinTableAttributes;
+import org.eclipse.jpt.jpa.db.Table;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.DisposeEvent;
+import org.eclipse.swt.events.DisposeListener;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.TableColumn;
+import org.eclipse.ui.forms.events.HyperlinkEvent;
+import org.eclipse.ui.forms.events.IHyperlinkListener;
+import org.eclipse.ui.forms.widgets.Hyperlink;
+
+public class JoinColumnsAnnotationEditor
+{
+ private ResourceManager resourceManager;
+ private EntityRefPropertyElem refElem;
+ private boolean isInverseJoin;
+ private Table table;
+ private Table refTable;
+ private JoinPropertiesPage joinPropsPage;
+ private Label noJoinLabel;
+ private Hyperlink actionLink;
+
+ public JoinColumnsAnnotationEditor(ResourceManager resourceManager, EntityRefPropertyElem refElem, boolean isInverseJoin,
+ Table table, Table refTable, JoinPropertiesPage joinPropsPage)
+ {
+ this.resourceManager = resourceManager;
+ assert refElem != null;
+ this.isInverseJoin = isInverseJoin;
+ this.refElem = refElem;
+ this.table = table;
+ this.refTable = refTable;
+ this.joinPropsPage = joinPropsPage;
+ }
+
+ private List<ColumnAttributes> getEntityJoinColumns()
+ {
+ List<ColumnAttributes> joinColumns = new ArrayList<ColumnAttributes>();
+ List<ColumnAttributes> srcJoinColumns = null;
+ JoinTableAttributes joinTable = refElem.getJoinTable();
+ if (joinTable != null)
+ {
+ if (isInverseJoin)
+ srcJoinColumns = joinTable.getInverseJoinColumns();
+ else
+ srcJoinColumns = joinTable.getJoinColumns();
+ }
+ else
+ {
+ srcJoinColumns = refElem.getJoinColumns();
+ }
+ for (ColumnAttributes srcColAttrs : srcJoinColumns)
+ {
+ joinColumns.add(new ColumnAttributes(srcColAttrs));
+ }
+ return joinColumns;
+ }
+
+ public Control createJoinColumnsControl(Composite parent)
+ {
+ if (table == null)
+ return null; // could happen when the join table is not specified yet
+ if (refTable == null)
+ {
+ if (refElem.isManyToMany())
+ {
+ // do not show anything because the message would look stupid here
+ return null;
+ }
+ Label label = new Label(parent, SWT.NONE);
+ label.setText(JptJpaUiMakePersistentMessages.REF_TABLE_NOT_SPECIFIED);
+ return label;
+ }
+
+ final Composite composite = new Composite(parent, SWT.NONE);
+ GridLayout gl = new GridLayout(1, false);
+ composite.setLayout(gl);
+
+ List<ColumnAttributes> joinColumns = getEntityJoinColumns();
+
+ String actionLabel;
+ final boolean add;
+ if (joinColumns == null || joinColumns.isEmpty())
+ {
+ noJoinLabel = new Label(composite, SWT.NONE);
+ String desc = String.format(
+ JptJpaUiMakePersistentMessages.NO_JOIN_COLUMN_LABEL,
+ table.getName(), refTable.getName());
+ noJoinLabel.setText(desc);
+ actionLabel = JptJpaUiMakePersistentMessages.ADD_JOIN_COLUMN;
+ add = true;
+ }
+ else
+ {
+ Label joinColumnTableLabel = new Label(composite, SWT.NONE);
+ String tableDesc = String.format(
+ JptJpaUiMakePersistentMessages.JOIN_COLUMN_TABLE_DESC,
+ table.getName(), refTable.getName());
+ joinColumnTableLabel.setText(tableDesc);
+ actionLabel = JptJpaUiMakePersistentMessages.EDIT_JOIN_COLUMNS;
+ TableViewer joinColumnsTable = createJoinColumnTable(composite, joinColumns, (400 - 60) / 2);
+ add = false;
+ GridData gd2 = new GridData(GridData.FILL_HORIZONTAL);
+ int ncols = joinColumns.size() > 2 ? 2 : 1;
+ //gd2.heightHint = SWTUtil.getTableHeightHint(joinColumnsTable.getTable(), ncols);
+ gd2.heightHint = 60;
+ joinColumnsTable.getTable().setLayoutData(gd2);
+ }
+ actionLink = new Hyperlink(composite, SWT.NONE);
+ actionLink.setForeground(ColorConstants.blue);
+ actionLink.setText(actionLabel);
+ actionLink.setUnderlined(true);
+ actionLink.addHyperlinkListener(new IHyperlinkListener()
+ {
+ public void linkActivated(HyperlinkEvent e)
+ {
+ Display display = Display.getDefault();
+ if (display.isDisposed()) return;
+ display.asyncExec(new Runnable()
+ {
+ public void run()
+ {
+ if (add)
+ addJoinColumn();
+ else
+ editJoinColumns();
+ }
+ });
+ }
+
+ public void linkEntered(HyperlinkEvent e) {}
+ public void linkExited(HyperlinkEvent e) {}
+ });
+
+ composite.addDisposeListener(new DisposeListener()
+ {
+ public void widgetDisposed(DisposeEvent e)
+ {
+ Control[] children = composite.getChildren();
+ for (Control child : children)
+ child.dispose();
+ }
+ });
+ return composite;
+ }
+
+ public void setEnable(boolean enabled)
+ {
+ if (actionLink != null)
+ {
+ actionLink.setEnabled(enabled);
+ if (enabled)
+ actionLink.setForeground(ColorConstants.blue);
+ else
+ actionLink.setForeground(ColorConstants.gray);
+ }
+ if (noJoinLabel != null)
+ noJoinLabel.setEnabled(enabled);
+ }
+
+
+ private TableViewer createJoinColumnTable(Composite parent,
+ List<ColumnAttributes> joinColumns, int colWidth)
+ {
+ org.eclipse.swt.widgets.Table joinColumnsTable =
+ new org.eclipse.swt.widgets.Table(parent,
+ SWT.BORDER | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.SINGLE);
+ joinColumnsTable.setLinesVisible(true);
+ joinColumnsTable.setHeaderVisible(true);
+
+ TableColumn colNameCol = new TableColumn(joinColumnsTable, SWT.NONE);
+ colNameCol.setWidth(colWidth);
+ colNameCol.setText(table.getName());
+ colNameCol.setResizable(true);
+ TableColumn refColNameCol = new TableColumn(joinColumnsTable, SWT.NONE);
+ refColNameCol.setWidth(colWidth);
+ refColNameCol.setText(refTable.getName());
+ refColNameCol.setResizable(true);
+
+ TableViewer tableViewer = new TableViewer(joinColumnsTable);
+ tableViewer.setContentProvider(new JoinColumnsContentProvider());
+ tableViewer.setLabelProvider(new JoinColumnsLabelProvider());
+ tableViewer.setInput(joinColumns.toArray(new ColumnAttributes[0]));
+ return tableViewer;
+ }
+
+ private final class JoinColumnsContentProvider implements IStructuredContentProvider
+ {
+
+ public Object[] getElements(Object inputElement)
+ {
+ if (inputElement instanceof ColumnAttributes[])
+ {
+ return (ColumnAttributes[])inputElement;
+ }
+ return null;
+ }
+
+ public void dispose()
+ {
+ }
+
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput)
+ {
+ }
+
+ }
+
+ private final class JoinColumnsLabelProvider extends LabelProvider implements ITableLabelProvider
+ {
+ public Image getColumnImage(Object element, int columnIndex)
+ {
+ return null;
+ }
+
+ public String getColumnText(Object element, int columnIndex)
+ {
+ ColumnAttributes colAttrs = (ColumnAttributes)element;
+ String colText = null;
+
+ switch (columnIndex)
+ {
+ case 0:
+ {
+ colText = colAttrs.getName();
+ break;
+ }
+ case 1:
+ {
+ colText = colAttrs.getReferencedColumnName();
+ }
+ }
+ return colText;
+ }
+ }
+
+ private void addJoinColumn()
+ {
+ AddJoinColumnDlg dlg = new AddJoinColumnDlg(Display.getDefault().getActiveShell(), resourceManager,
+ table, refTable, refElem);
+ if (dlg.open() == Dialog.OK)
+ {
+ ColumnAttributes joinCol = dlg.getNewJoinColumn();
+ JoinTableAttributes joinTable = refElem.getJoinTable();
+ if (joinTable != null)
+ {
+ if (isInverseJoin)
+ joinTable.addInverseJoinColumn(joinCol);
+ else
+ joinTable.addJoinColumn(joinCol);
+ }
+ else
+ {
+ refElem.addJoinColumn(joinCol);
+ }
+ joinPropsPage.refreshJoinProperties();
+ }
+
+ }
+
+ private void editJoinColumns()
+ {
+ List<ColumnAttributes> joinCols = getEntityJoinColumns();
+ EditJoinColumnsDialog dlg = new EditJoinColumnsDialog(Display.getDefault().getActiveShell(),
+ table, refTable, joinCols);
+ if (dlg.open() == Dialog.OK)
+ {
+ joinCols = dlg.getJoinColumns();
+ JoinTableAttributes joinTable = refElem.getJoinTable();
+ if (joinTable != null)
+ {
+ if (isInverseJoin)
+ joinTable.setInverseJoinColumns(joinCols);
+ else
+ joinTable.setJoinColumns(joinCols);
+ }
+ else
+ {
+ refElem.setJoinColumns(joinCols);
+ }
+
+ joinPropsPage.refreshJoinProperties();
+ }
+ }
+
+ private class EditJoinColumnsDialog extends Dialog
+ {
+ private Table table;
+ private Table refTable;
+ private List<ColumnAttributes> joinColumns;
+ private TableViewer joinColumnTable;
+ private Button addButton;
+ private Button removeButton;
+
+ public EditJoinColumnsDialog(Shell shell, Table table, Table refTable,
+ List<ColumnAttributes> joinColumns)
+ {
+ super(shell);
+ this.table = table;
+ this.refTable = refTable;
+ this.joinColumns = new ArrayList<ColumnAttributes>();
+ if (joinColumns != null)
+ this.joinColumns.addAll(joinColumns);
+ }
+
+ @Override
+ protected void configureShell(Shell newShell)
+ {
+ newShell.setText(JptJpaUiMakePersistentMessages.EDIT_JOIN_COLUMNS);
+ super.configureShell(newShell);
+ }
+
+ @Override
+ protected Control createDialogArea(Composite parent)
+ {
+ initializeDialogUnits(parent);
+ Composite composite = (Composite)super.createDialogArea(parent);
+ GridLayout gl = new GridLayout(2, false);
+ gl.marginWidth = 10;
+ gl.marginHeight = 10;
+ gl.verticalSpacing = 10;
+ composite.setLayout(gl);
+
+ Label label = new Label(composite, SWT.NONE);
+ String desc = String.format(JptJpaUiMakePersistentMessages.EDIT_JOIN_COLUMNS_DESC,
+ table.getName(), refTable.getName());
+ label.setText(desc);
+ GridData gd = new GridData();
+ gd.horizontalSpan = 2;
+ label.setLayoutData(gd);
+
+ joinColumnTable = createJoinColumnTable(composite, joinColumns, 200);
+ GridData gd2 = new GridData(GridData.FILL_HORIZONTAL);
+ gd2.heightHint = SWTUtil.getTableHeightHint(joinColumnTable.getTable(), 5);
+ joinColumnTable.getTable().setLayoutData(gd2);
+ joinColumnTable.addSelectionChangedListener(new ISelectionChangedListener()
+ {
+ public void selectionChanged(SelectionChangedEvent event)
+ {
+ updateButtons();
+ }
+ });
+
+ createAddRemoveButtonComposite(composite);
+ updateButtons();
+ return composite;
+ }
+
+ @Override
+ protected boolean isResizable()
+ {
+ return true;
+ }
+
+ public List<ColumnAttributes> getJoinColumns()
+ {
+ return joinColumns;
+ }
+
+ private void createAddRemoveButtonComposite(Composite parent)
+ {
+ //Add and Remove JoinColumns buttons
+ Composite buttonComposite = new Composite(parent, SWT.NULL);
+ GridLayout buttonLayout = new GridLayout(1, false);
+ buttonComposite.setLayout(buttonLayout);
+ GridData data = new GridData();
+ data.horizontalAlignment = GridData.FILL;
+ data.verticalAlignment = GridData.BEGINNING;
+ buttonComposite.setLayoutData(data);
+
+ addButton = new Button(buttonComposite, SWT.PUSH);
+ addButton.setText( JptJpaUiMakePersistentMessages.ADD );
+ GridData gridData = new GridData();
+ gridData.horizontalAlignment = GridData.FILL;
+ addButton.setLayoutData(gridData);
+ addButton.addSelectionListener(new SelectionAdapter()
+ {
+ public void widgetSelected(SelectionEvent e)
+ {
+ AddJoinColumnDlg dlg = new AddJoinColumnDlg(Display.getDefault().getActiveShell(), resourceManager,
+ table, refTable, refElem);
+ if (dlg.open() == Dialog.OK)
+ {
+ ColumnAttributes joinCol = dlg.getNewJoinColumn();
+ joinColumns.add(joinCol);
+ joinColumnTable.add(joinCol);
+ }
+ }
+ });
+
+ removeButton = new Button(buttonComposite, SWT.PUSH);
+ removeButton.setText( JptJpaUiMakePersistentMessages.REMOVE );
+ gridData = new GridData();
+ gridData.horizontalAlignment = GridData.FILL;
+ removeButton.setLayoutData(gridData);
+ removeButton.addSelectionListener(new SelectionAdapter()
+ {
+ public void widgetSelected(SelectionEvent e)
+ {
+ StructuredSelection selection = (StructuredSelection)joinColumnTable.getSelection();
+ if( selection.isEmpty())
+ return;
+ ColumnAttributes selectedCol = (ColumnAttributes)selection.getFirstElement();
+
+ //Update TableViewer model
+ joinColumns.remove(selectedCol);
+ joinColumnTable.remove(selectedCol);
+ }
+ });
+
+ addButton.setFocus();
+ }
+
+ private void updateButtons()
+ {
+ if (joinColumnTable.getSelection().isEmpty())
+ removeButton.setEnabled(false);
+ else
+ removeButton.setEnabled(true);
+ }
+ }
+
+}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/makepersistent/JoinPropertiesPage.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/makepersistent/JoinPropertiesPage.java
new file mode 100644
index 0000000..60c3aeb
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/makepersistent/JoinPropertiesPage.java
@@ -0,0 +1,195 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+
+package org.eclipse.jpt.jpa.ui.internal.wizards.makepersistent;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.resource.ResourceManager;
+import org.eclipse.jface.wizard.IWizardPage;
+import org.eclipse.jface.wizard.WizardPage;
+import org.eclipse.jpt.jpa.annotate.mapping.EntityRefPropertyElem;
+import org.eclipse.jpt.jpa.annotate.mapping.JoinTableAttributes;
+import org.eclipse.jpt.jpa.annotate.util.AnnotateMappingUtil;
+import org.eclipse.jpt.jpa.core.context.persistence.PersistenceUnit;
+import org.eclipse.jpt.jpa.core.internal.GenericJpaPlatformFactory;
+import org.eclipse.jpt.jpa.db.Schema;
+import org.eclipse.jpt.jpa.db.Table;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Text;
+
+public class JoinPropertiesPage extends WizardPage
+{
+ protected PersistenceUnit persistenceUnit;
+ protected ResourceManager resourceManager;
+ protected IProject project;
+ protected String javaClass;
+ protected Schema schema;
+ protected Table table;
+ protected Table inverseTable;
+ protected EntityRefPropertyElem refElem;
+ protected String tagName;
+ private Composite joinPropsComposite;
+
+ public JoinPropertiesPage(PersistenceUnit persistenceUnit, ResourceManager resourceManager,
+ IProject project, String javaClass,
+ Schema schema, Table table, Table inverseTable, EntityRefPropertyElem refElem)
+ {
+ super("Join Properties Page"); //$NON-NLS-1$
+ this.persistenceUnit = persistenceUnit;
+ this.resourceManager = resourceManager;
+ this.project = project;
+ this.javaClass = javaClass;
+ this.refElem = refElem;
+ this.schema = schema;
+ this.table = table;
+ this.inverseTable = inverseTable;
+ setTitle(JptJpaUiMakePersistentMessages.JOIN_PROPS_PAGE_TITLE);
+ setMessage(JptJpaUiMakePersistentMessages.JOIN_PROPS_PAGE_DESC);
+ }
+
+ public void createControl(Composite parent)
+ {
+ initializeDialogUnits(parent);
+
+ Composite composite = new Composite(parent, SWT.NONE);
+ GridLayout gl = new GridLayout(1, true);
+ composite.setLayout(gl);
+ GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
+ gd.widthHint = 400;
+ composite.setLayoutData(gd);
+ joinPropsComposite = createJoinProps(composite);
+ addListeners();
+ setControl(composite);
+ }
+
+ @Override
+ public IWizardPage getNextPage()
+ {
+ return null;
+ }
+
+ @Override
+ public void setVisible(boolean visible)
+ {
+ super.setVisible(visible);
+ if (visible)
+ {
+ String newTagName = refElem.getTagName();
+ if (!AnnotateMappingUtil.areEqual(tagName, newTagName))
+ {
+ tagName = newTagName;
+ initFields();
+ refreshJoinProperties();
+ }
+ }
+ }
+
+ protected Composite createJoinProps(Composite parent) { return null;}
+
+ protected void refreshJoinProperties() {};
+
+ protected Composite getJoinPropsComposite()
+ {
+ return joinPropsComposite;
+ }
+
+ protected void addListeners() {};
+
+ protected void initFields() {};
+
+ protected String getJoinTableName()
+ {
+ String joinTableName = null;
+ JoinTableAttributes joinTableAttrs = refElem.getJoinTable();
+ if (joinTableAttrs != null)
+ {
+ joinTableName = joinTableAttrs.getTableName();
+ }
+ return joinTableName;
+ }
+
+ protected boolean isJpa1_0Project()
+ {
+ return this.persistenceUnit.getJpaPlatform().getJpaVersion().getVersion().equals("1.0");
+ }
+
+ protected boolean isGeneric1_0Project()
+ {
+ return isJpa1_0Project() &&
+ this.persistenceUnit.getJpaPlatform().getConfig().getId().equals(GenericJpaPlatformFactory.ID);
+ }
+
+ protected void chooseJoinTable(Text joinTableText)
+ {
+ SelectTableDialog dlg = new SelectTableDialog(Display.getDefault().getActiveShell(),
+ resourceManager, schema);
+ if (dlg.open() == Dialog.OK)
+ {
+ joinTableText.setText(dlg.getSelectedTable());
+ }
+ }
+
+ protected void handleJoinTableChange(Text joinTableText)
+ {
+ String newJoinTable = joinTableText.getText();
+
+ if (newJoinTable != null && newJoinTable.length() > 0)
+ {
+ JoinTableAttributes joinTblAttr = refElem.getJoinTable();
+ if (joinTblAttr != null)
+ {
+ String oldJoinTable = joinTblAttr.getTableName();
+ if (oldJoinTable == null || !oldJoinTable.equalsIgnoreCase(newJoinTable))
+ {
+ joinTblAttr.setTableName(newJoinTable);
+ joinTblAttr.setSchema(schema.getName());
+ joinTblAttr.removeAllJoinColumns();
+ joinTblAttr.removeAllInverseJoinColumns();
+ }
+ }
+ else
+ {
+ joinTblAttr = new JoinTableAttributes();
+ joinTblAttr.setTableName(newJoinTable);
+ joinTblAttr.setSchema(schema.getName());
+ refElem.setJoinTable(joinTblAttr);
+ }
+ }
+ else
+ {
+ refElem.removeJoinTable();
+ }
+ refreshJoinProperties();
+ }
+
+ protected void chooseMappedBy(Text mappedByText)
+ {
+ SelectPropertyDialog dlg = new SelectPropertyDialog(Display.getDefault().getActiveShell(),
+ project, javaClass, refElem, false);
+ if (dlg.open() == Dialog.OK)
+ {
+ mappedByText.setText(dlg.getSelectedProp());
+ }
+ }
+
+ protected void handleMappedByChange(Text mappedByText)
+ {
+ if (mappedByText.getText() == null || mappedByText.getText().length() == 0)
+ refElem.removeMappedBy();
+ else
+ refElem.setMappedBy(mappedByText.getText());
+ }
+
+}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/makepersistent/JpaMakePersistentWizard.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/makepersistent/JpaMakePersistentWizard.java
new file mode 100644
index 0000000..34e6d1a
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/makepersistent/JpaMakePersistentWizard.java
@@ -0,0 +1,201 @@
+/*******************************************************************************
+ * Copyright (c) 2010, 2013 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.jpa.ui.internal.wizards.makepersistent;
+
+import java.lang.reflect.InvocationTargetException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.ListIterator;
+import java.util.Set;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.jdt.core.IType;
+import org.eclipse.jdt.ui.JavaElementComparator;
+import org.eclipse.jface.resource.JFaceResources;
+import org.eclipse.jface.resource.LocalResourceManager;
+import org.eclipse.jface.resource.ResourceManager;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jface.viewers.ViewerComparator;
+import org.eclipse.jface.wizard.Wizard;
+import org.eclipse.jpt.common.core.internal.utility.PlatformTools;
+import org.eclipse.jpt.jpa.core.JpaEntityGeneratorDatabaseAnnotationNameBuilder;
+import org.eclipse.jpt.jpa.core.JpaFile;
+import org.eclipse.jpt.jpa.core.JpaProject;
+import org.eclipse.jpt.jpa.core.context.JpaContextModelRoot;
+import org.eclipse.jpt.jpa.core.context.persistence.Persistence;
+import org.eclipse.jpt.jpa.core.context.persistence.PersistenceUnit;
+import org.eclipse.jpt.jpa.core.context.persistence.PersistenceXml;
+import org.eclipse.jpt.jpa.db.Column;
+import org.eclipse.jpt.jpa.db.ForeignKey;
+import org.eclipse.jpt.jpa.db.Schema;
+import org.eclipse.jpt.jpa.db.Table;
+import org.eclipse.jpt.jpa.annotate.DatabaseAnnotationNameBuilder;
+import org.eclipse.jpt.jpa.ui.JpaWorkbench;
+import org.eclipse.jpt.jpa.ui.JptJpaUiImages;
+import org.eclipse.jpt.jpa.ui.JptJpaUiMessages;
+import org.eclipse.jpt.jpa.ui.internal.plugin.JptJpaUiPlugin;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.PlatformUI;
+
+public class JpaMakePersistentWizard
+ extends Wizard
+{
+ private final JpaProject jpaProject;
+
+ private final Set<IType> selectedTypes;
+
+ private final ResourceManager resourceManager;
+
+ private JpaMakePersistentWizardPage makePersistentWizardPage;
+
+ private ClassMappingPage classMappingPage;
+
+ private PropsMappingPage propsMappingPage;
+
+ private JavaClassMapping[] javaClassMappings;
+
+ private static final String HELP_CONTEXT_ID = JptJpaUiPlugin.instance().getPluginID() + ".GenerateEntitiesFromSchemaWizard"; //$NON-NLS-1$
+
+ private DatabaseAnnotationNameBuilder databaseAnnotationNameBuilder;
+
+ public JpaMakePersistentWizard(JpaProject jpaProject, Set<IType> selectedTypes) {
+ super();
+ this.jpaProject = jpaProject;
+ this.selectedTypes = selectedTypes;
+ this.resourceManager = this.buildResourceManager();
+ this.javaClassMappings = this.buildJavaClassMappings(this.selectedTypes);
+ this.setWindowTitle(JptJpaUiMessages.JpaMakePersistentWizardPage_title);
+ this.setDefaultPageImageDescriptor(JptJpaUiImages.ENTITY_BANNER);
+ this.databaseAnnotationNameBuilder = new LocalDatabaseAnnotationNameBuilder(this.jpaProject.getJpaPlatform().getEntityGeneratorDatabaseAnnotationNameBuilder());
+ }
+
+ protected ResourceManager buildResourceManager() {
+ JpaWorkbench jpaWorkbench = this.getJpaWorkbench();
+ return (jpaWorkbench != null) ? jpaWorkbench.buildLocalResourceManager() : new LocalResourceManager(JFaceResources.getResources(this.getWorkbench().getDisplay()));
+ }
+
+ protected JavaClassMapping[] buildJavaClassMappings(Set<IType> selectedJdtTypes)
+ {
+ List<JavaClassMapping> mappings = new ArrayList<JavaClassMapping>();
+ for (IType jdtType : selectedJdtTypes)
+ {
+ JpaFile jpaFile = this.jpaProject.getJpaFile((IFile) jdtType.getResource());
+ if (jpaFile.getRootStructureNodesSize() == 0)
+ mappings.add(new JavaClassMapping(jdtType));
+ }
+ return mappings.toArray(new JavaClassMapping[0]);
+ }
+
+ private JpaWorkbench getJpaWorkbench() {
+ return PlatformTools.getAdapter(this.getWorkbench(), JpaWorkbench.class);
+ }
+
+ private IWorkbench getWorkbench() {
+ return PlatformUI.getWorkbench();
+ }
+
+ @Override
+ public void addPages() {
+ this.setForcePreviousAndNextButtons(true);
+ this.makePersistentWizardPage = new JpaMakePersistentWizardPage(this.jpaProject, this.javaClassMappings, this.resourceManager, HELP_CONTEXT_ID);
+ this.classMappingPage = new ClassMappingPage(this.jpaProject, this.javaClassMappings, this.resourceManager, this.makePersistentWizardPage);
+ this.propsMappingPage = new PropsMappingPage(this.jpaProject, this.javaClassMappings, this.resourceManager, this.classMappingPage);
+ this.addPage(this.makePersistentWizardPage);
+ this.addPage(this.classMappingPage);
+ this.addPage(this.propsMappingPage);
+ return;
+ }
+
+ @Override
+ public boolean performFinish() {
+ try {
+ this.makePersistentWizardPage.performFinish();
+ } catch (InvocationTargetException ex) {
+ JptJpaUiPlugin.instance().logError(ex);
+ }
+ return true;
+ }
+
+ @Override
+ public void dispose() {
+ this.resourceManager.dispose();
+ super.dispose();
+ }
+
+ protected Schema getSchema()
+ {
+ return this.classMappingPage.getSchema();
+ }
+
+ protected JavaClassMapping[] getJavaClassMappings()
+ {
+ return this.classMappingPage.getJavaClassMappings();
+ }
+
+ protected PersistenceUnit getPersistenceUnit()
+ {
+ JpaContextModelRoot rcn = this.jpaProject.getContextModelRoot();
+ PersistenceXml pxml = (rcn == null) ? null : rcn.getPersistenceXml();
+ Persistence persistence = (pxml == null) ? null : pxml.getRoot();
+ if (persistence == null)
+ {
+ return null;
+ }
+ ListIterator<PersistenceUnit> units = persistence.getPersistenceUnits().iterator();
+ return units.hasNext() ? units.next() : null;
+ }
+
+ protected DatabaseAnnotationNameBuilder getDatabaseAnnotationNameBuilder()
+ {
+ return this.databaseAnnotationNameBuilder;
+ }
+
+ protected static final class TypeComparator extends ViewerComparator {
+ public final JavaElementComparator javaElementComparator = new JavaElementComparator();
+
+ @Override
+ public int compare(Viewer viewer, Object e1, Object e2) {
+ if ((e1 instanceof JavaClassMapping) && (e2 instanceof JavaClassMapping)) {
+ return this.javaElementComparator.compare(viewer, ((JavaClassMapping) e1).getJDTType(), ((JavaClassMapping) e2).getJDTType());
+ }
+ return 0;
+ }
+ }
+
+ // ********** name builder adapter **********
+
+ /**
+ * adapt the JPA platform-supplied builder to the builder interface
+ * expected by the entity generator
+ */
+ private static class LocalDatabaseAnnotationNameBuilder implements DatabaseAnnotationNameBuilder {
+ private JpaEntityGeneratorDatabaseAnnotationNameBuilder builder;
+ LocalDatabaseAnnotationNameBuilder(JpaEntityGeneratorDatabaseAnnotationNameBuilder builder) {
+ super();
+ this.builder = builder;
+ }
+ public String buildTableAnnotationName(String entityName, Table table) {
+ return this.builder.buildTableAnnotationName(entityName, table);
+ }
+ public String buildColumnAnnotationName(String attributeName, Column column) {
+ return this.builder.buildColumnAnnotationName(attributeName, column);
+ }
+ public String buildJoinColumnAnnotationName(String attributeName, ForeignKey foreignKey) {
+ return this.builder.buildJoinColumnAnnotationName(attributeName, foreignKey);
+ }
+ public String buildJoinColumnAnnotationName(Column column) {
+ return this.builder.buildJoinColumnAnnotationName(column);
+ }
+ public String buildJoinTableAnnotationName(Table table) {
+ return this.builder.buildJoinTableAnnotationName(table);
+ }
+ }
+
+}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/JpaMakePersistentWizardPage.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/makepersistent/JpaMakePersistentWizardPage.java
index 48ab9b4..6c579e9 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/JpaMakePersistentWizardPage.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/makepersistent/JpaMakePersistentWizardPage.java
@@ -7,12 +7,17 @@
* Contributors:
* Oracle - initial API and implementation
******************************************************************************/
-package org.eclipse.jpt.jpa.ui.internal.wizards;
+package org.eclipse.jpt.jpa.ui.internal.wizards.makepersistent;
import java.io.File;
import java.lang.reflect.InvocationTargetException;
+import java.util.Collections;
+import java.util.EventListener;
+import java.util.HashSet;
+import java.util.Iterator;
import java.util.ListIterator;
import java.util.Set;
+
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IWorkspace;
@@ -22,9 +27,8 @@ import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.SubMonitor;
import org.eclipse.core.runtime.jobs.ISchedulingRule;
-import org.eclipse.jdt.core.IType;
-import org.eclipse.jdt.ui.JavaElementComparator;
import org.eclipse.jdt.ui.JavaElementLabelProvider;
import org.eclipse.jface.dialogs.ProgressMonitorDialog;
import org.eclipse.jface.operation.IRunnableWithProgress;
@@ -41,7 +45,6 @@ import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.TableViewerColumn;
import org.eclipse.jface.viewers.Viewer;
-import org.eclipse.jface.viewers.ViewerComparator;
import org.eclipse.jface.viewers.ViewerFilter;
import org.eclipse.jface.window.Window;
import org.eclipse.jface.wizard.WizardPage;
@@ -53,16 +56,17 @@ import org.eclipse.jpt.common.utility.command.Command;
import org.eclipse.jpt.common.utility.internal.ArrayTools;
import org.eclipse.jpt.common.utility.internal.ObjectTools;
import org.eclipse.jpt.common.utility.internal.iterable.IterableTools;
-import org.eclipse.jpt.common.utility.internal.iterable.TransformationIterable;
+import org.eclipse.jpt.common.utility.internal.iterator.IteratorTools;
import org.eclipse.jpt.common.utility.internal.model.value.AspectPropertyValueModelAdapter;
import org.eclipse.jpt.common.utility.internal.model.value.SimplePropertyValueModel;
-import org.eclipse.jpt.common.utility.internal.predicate.PredicateAdapter;
-import org.eclipse.jpt.common.utility.internal.transformer.TransformerAdapter;
import org.eclipse.jpt.common.utility.model.event.PropertyChangeEvent;
import org.eclipse.jpt.common.utility.model.listener.PropertyChangeListener;
import org.eclipse.jpt.common.utility.model.value.ModifiablePropertyValueModel;
import org.eclipse.jpt.common.utility.model.value.PropertyValueModel;
-import org.eclipse.jpt.jpa.core.JpaFile;
+import org.eclipse.jpt.jpa.annotate.JavaClassAnnotater;
+import org.eclipse.jpt.jpa.annotate.mapping.EntityMappingsDoc;
+import org.eclipse.jpt.jpa.annotate.mapping.EntityPropertyElem;
+import org.eclipse.jpt.jpa.annotate.mapping.TableAnnotationAttributes;
import org.eclipse.jpt.jpa.core.JpaProject;
import org.eclipse.jpt.jpa.core.JpaProjectManager;
import org.eclipse.jpt.jpa.core.MappingKeys;
@@ -73,14 +77,18 @@ import org.eclipse.jpt.jpa.core.context.persistence.Persistence;
import org.eclipse.jpt.jpa.core.context.persistence.PersistenceUnit;
import org.eclipse.jpt.jpa.core.context.persistence.PersistenceXml;
import org.eclipse.jpt.jpa.core.internal.context.java.JavaSourceFileDefinition;
+import org.eclipse.jpt.jpa.core.internal.context.persistence.AbstractPersistenceUnit;
import org.eclipse.jpt.jpa.core.internal.jpa1.context.orm.GenericOrmXmlDefinition;
import org.eclipse.jpt.jpa.core.resource.ResourceMappingFile;
import org.eclipse.jpt.jpa.core.resource.orm.XmlEntityMappings;
+import org.eclipse.jpt.jpa.db.Schema;
import org.eclipse.jpt.jpa.ui.JpaPlatformUi;
import org.eclipse.jpt.jpa.ui.JptJpaUiMessages;
import org.eclipse.jpt.jpa.ui.details.MappingUiDefinition;
import org.eclipse.jpt.jpa.ui.internal.jface.XmlMappingFileViewerFilter;
import org.eclipse.jpt.jpa.ui.internal.plugin.JptJpaUiPlugin;
+import org.eclipse.jpt.jpa.ui.internal.wizards.SelectMappingFileDialog;
+import org.eclipse.jpt.jpa.ui.internal.wizards.makepersistent.JpaMakePersistentWizard.TypeComparator;
import org.eclipse.jpt.jpa.ui.internal.wizards.orm.EmbeddedMappingFileWizard;
import org.eclipse.jpt.jpa.ui.wizards.entity.JptJpaUiWizardsEntityMessages;
import org.eclipse.swt.SWT;
@@ -101,15 +109,15 @@ import org.eclipse.ui.ide.IDE;
import org.eclipse.ui.model.WorkbenchContentProvider;
import org.eclipse.ui.model.WorkbenchLabelProvider;
+@SuppressWarnings("restriction")
public class JpaMakePersistentWizardPage
extends WizardPage
{
private TableViewer classTableViewer;
private final String helpContextId;
- private final TypeConfig[] selectedTypes;
-
/* CU private */ final JpaProject jpaProject;
+ private JavaClassMapping[] javaClassMappings;
private JptResourceType jptResourceType;
private final ModifiablePropertyValueModel<Boolean> annotateInJavaModel;
@@ -120,6 +128,8 @@ public class JpaMakePersistentWizardPage
private final ModifiablePropertyValueModel<Boolean> listInPersistenceXmlModel;
/* CU private */ final ResourceManager resourceManager;
+
+ private final Set<Listener> listeners = Collections.synchronizedSet(new HashSet<Listener>());
// sizing constants
private final static int TABLE_HEIGHT = 250;
@@ -130,14 +140,14 @@ public class JpaMakePersistentWizardPage
protected JpaMakePersistentWizardPage(
JpaProject jpaProject,
- Set<IType> selectedJdtTypes,
+ JavaClassMapping[] javaClassMappings,
ResourceManager resourceManager,
String helpContextId
) {
super(MAKE_PERSISTENT_PAGE_NAME);
this.jpaProject = jpaProject;
- this.selectedTypes = this.buildSelectedTypes(selectedJdtTypes);
+ this.javaClassMappings = javaClassMappings;
this.resourceManager = resourceManager;
this.jptResourceType = JavaSourceFileDefinition.instance().getResourceType();
this.helpContextId = helpContextId;
@@ -146,47 +156,7 @@ public class JpaMakePersistentWizardPage
this.listInPersistenceXmlModel = new SimplePropertyValueModel<Boolean>(Boolean.valueOf(!this.jpaProject.discoversAnnotatedClasses()));
this.setTitle(JptJpaUiMessages.JpaMakePersistentWizardPage_title);
this.setMessage(JptJpaUiMessages.JpaMakePersistentWizardPage_message);
- }
-
- protected TypeConfig[] buildSelectedTypes(Set<IType> selectedJdtTypes) {
- return ArrayTools.array(this.buildSelectedTypesIterable(selectedJdtTypes), TypeConfig.class);
- }
-
- protected Iterable<TypeConfig> buildSelectedTypesIterable(Set<IType> selectedJdtTypes) {
- return new TransformationIterable<IType, TypeConfig>(this.filterNonPersistentJdtTypes(selectedJdtTypes), new JdtTypeTransformer());
- }
-
- /* CU private */ class JdtTypeTransformer
- extends TransformerAdapter<IType, TypeConfig>
- {
- @Override
- public TypeConfig transform(IType jdtType) {
- return new TypeConfig(jdtType);
- }
- }
-
- /**
- * Return all {@link IType JDT type}s that are not already persistent.
- * Any root structure nodes means the type is already annotated,
- * listed in <code>persistence.xml</code>, or listed in a mapping file.
- */
- protected Iterable<IType> filterNonPersistentJdtTypes(Set<IType> selectedJdtTypes) {
- return IterableTools.filter(selectedJdtTypes, new JdtTypeIsNonPersistent());
- }
-
- /* CU private */ class JdtTypeIsNonPersistent
- extends PredicateAdapter<IType>
- {
- @Override
- public boolean evaluate(IType jdtType) {
- return this.getJpaFile(jdtType).getRootStructureNodesSize() == 0;
- }
- private JpaFile getJpaFile(IType jdtType) {
- return this.getJpaProject().getJpaFile((IFile) jdtType.getResource());
- }
- private JpaProject getJpaProject() {
- return JpaMakePersistentWizardPage.this.jpaProject;
- }
+
}
protected JpaPlatformUi getJpaPlatformUi() {
@@ -243,7 +213,7 @@ public class JpaMakePersistentWizardPage
this.classTableViewer.setComparator(new TypeComparator());
this.createTypeTableColumn();
this.createMappingTableColumn();
- this.classTableViewer.setInput(this.selectedTypes);
+ this.classTableViewer.setInput(this.javaClassMappings);
data = new GridData(SWT.FILL, SWT.FILL, true, true);
data.heightHint = TABLE_HEIGHT;
@@ -258,6 +228,48 @@ public class JpaMakePersistentWizardPage
setControl(composite);
}
+ @Override
+ public boolean canFlipToNextPage() {
+ return this.annotateInJavaModel.getValue().booleanValue() && containsEntities() && super.canFlipToNextPage();
+ }
+
+ private boolean containsEntities() {
+ boolean ret = false;
+ for (JavaClassMapping javaClassMapping : this.javaClassMappings) {
+ if (javaClassMapping.getMappingKey().equals(MappingKeys.ENTITY_TYPE_MAPPING_KEY)) {
+ ret = true;
+ break;
+ }
+ }
+ return ret;
+ }
+
+ public void addListener(Listener listener)
+ {
+ if( ! this.listeners.add(listener)) {
+ throw new IllegalArgumentException("duplicate listener: " + listener); //$NON-NLS-1$
+ }
+ }
+
+ public void removeListener(Listener listener)
+ {
+ if( ! this.listeners.remove(listener)) {
+ throw new IllegalArgumentException("missing listener: " + listener); //$NON-NLS-1$
+ }
+ }
+
+ private Iterator<Listener> listeners() {
+ return IteratorTools.clone(this.listeners);
+ }
+
+ private void fireMappingTypeChanged(JavaClassMapping javaClassMapping)
+ {
+ for(Iterator<Listener> stream = this.listeners(); stream.hasNext(); )
+ {
+ stream.next().mappingTypeChanged(javaClassMapping);
+ }
+ }
+
private Composite createMappingFileControl(Composite parent) {
Composite composite = new Composite(parent, SWT.NULL);
GridLayout layout = new GridLayout();
@@ -380,13 +392,15 @@ public class JpaMakePersistentWizardPage
column.setEditingSupport(new EditingSupport(this.classTableViewer) {
@Override
protected Object getValue(Object element) {
- return getMappingUiDefinition(((TypeConfig) element).mappingKey);
+ return getMappingUiDefinition(((JavaClassMapping) element).getMappingKey());
}
@Override
protected void setValue(Object element, Object value) {
- ((TypeConfig) element).setMappingKey(((MappingUiDefinition) value).getKey());
- getViewer().update(element, null);
+ ((JavaClassMapping) element).setMappingKey(((MappingUiDefinition) value).getKey());
+ validate();
+ fireMappingTypeChanged((JavaClassMapping) element);
+ getViewer().update(element, null);
}
@Override
@@ -422,7 +436,7 @@ public class JpaMakePersistentWizardPage
protected IStructuredContentProvider buildMappingComboCellEditorContentProvider() {
return new IStructuredContentProvider() {
public Object[] getElements(Object inputElement) {
- return ArrayTools.array(((TypeConfig) inputElement).getTypeMappingUiDefinitions());
+ return ArrayTools.array(getTypeMappingUiDefinitions());
}
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
@@ -439,6 +453,14 @@ public class JpaMakePersistentWizardPage
return new MappingColumnLabelProvider();
}
+ /**
+ * Allows clients to listen for changes to the java class mapping keys
+ */
+ public interface Listener extends EventListener
+ {
+ void mappingTypeChanged(JavaClassMapping javaClassMapping);
+ }
+
/* CU private */ class MappingColumnLabelProvider
extends ColumnLabelProvider
{
@@ -460,7 +482,7 @@ public class JpaMakePersistentWizardPage
}
private MappingUiDefinition getMappingUiDefinition(Object element) {
- return JpaMakePersistentWizardPage.this.getMappingUiDefinition(((TypeConfig) element).mappingKey);
+ return JpaMakePersistentWizardPage.this.getMappingUiDefinition(((JavaClassMapping) element).getMappingKey());
}
private ResourceManager getResourceManager() {
return JpaMakePersistentWizardPage.this.resourceManager;
@@ -478,7 +500,7 @@ public class JpaMakePersistentWizardPage
protected void validate() {
String errorMessage = null;
- if (this.selectedTypes.length == 0) {
+ if (this.javaClassMappings.length == 0) {
errorMessage = JptJpaUiMessages.JpaMakePersistentWizardPage_selectedTypesPersistentError;
}
else if (this.isAddToOrmMappingFile()) {
@@ -509,7 +531,7 @@ public class JpaMakePersistentWizardPage
}
private void performAddToOrmXml() throws InvocationTargetException {
- this.perform(new AddToOrmXmlRunnable(this.jpaProject, this.getOrmXmlResource(), this.selectedTypes));
+ this.perform(new AddToOrmXmlRunnable(this.jpaProject, this.getOrmXmlResource(), this.javaClassMappings));
try {
this.openEditor(this.getOrmXmlResource().getFile());
}
@@ -519,7 +541,8 @@ public class JpaMakePersistentWizardPage
}
private void performAnnotateInJava() {
- this.perform(new AnnotateInJavaRunnable(this.jpaProject, this.selectedTypes, this.isListInPersistenceXml()));
+ JpaMakePersistentWizard wizard = (JpaMakePersistentWizard)this.getWizard();
+ this.perform(new AnnotateInJavaRunnable(wizard, this.jpaProject, this.javaClassMappings, this.isListInPersistenceXml()));
}
private void perform(IRunnableWithProgress runnable) {
@@ -577,42 +600,15 @@ public class JpaMakePersistentWizardPage
return new File(getMappingFileLocation()).getName();
}
-
- public class TypeConfig
- implements PersistentType.Config
- {
- private final IType jdtType;
-
- /* CU private */ String mappingKey;
-
- public TypeConfig(IType jdtType) {
- super();
- this.jdtType = jdtType;
- this.mappingKey = MappingKeys.ENTITY_TYPE_MAPPING_KEY;
- }
-
- public String getName() {
- return this.jdtType.getFullyQualifiedName();
- }
-
- public String getMappingKey() {
- return this.mappingKey;
- }
-
- protected void setMappingKey(String mappingKey) {
- this.mappingKey = mappingKey;
- }
-
- protected Iterable<MappingUiDefinition> getTypeMappingUiDefinitions() {
- JpaPlatformUi ui = JpaMakePersistentWizardPage.this.getJpaPlatformUi();
- return (ui != null) ? ui.getTypeMappingUiDefinitions(JpaMakePersistentWizardPage.this.jptResourceType) : IterableTools.<MappingUiDefinition>emptyIterable();
- }
+ protected Iterable<MappingUiDefinition> getTypeMappingUiDefinitions() {
+ JpaPlatformUi ui = JpaMakePersistentWizardPage.this.getJpaPlatformUi();
+ return (ui != null) ? ui.getTypeMappingUiDefinitions(JpaMakePersistentWizardPage.this.jptResourceType) : IterableTools.<MappingUiDefinition>emptyIterable();
}
-
+
private final class TypeContentProvider implements IStructuredContentProvider
{
public Object[] getElements(Object inputElement){
- return (TypeConfig[]) inputElement;
+ return (JavaClassMapping[]) inputElement;
}
public void dispose(){}
@@ -630,21 +626,12 @@ public class JpaMakePersistentWizardPage
@Override
public String getText(Object element) {
- return this.javaElementLabelProvider.getText(((TypeConfig) element).jdtType);
+ return this.javaElementLabelProvider.getText(((JavaClassMapping) element).getJDTType());
}
@Override
public Image getImage(Object element) {
- return this.javaElementLabelProvider.getImage(((TypeConfig) element).jdtType);
- }
- }
-
- private final class TypeComparator extends ViewerComparator {
- private final JavaElementComparator javaElementComparator = new JavaElementComparator();
-
- @Override
- public int compare(Viewer viewer, Object e1, Object e2) {
- return this.javaElementComparator.compare(viewer, ((TypeConfig) e1).jdtType, ((TypeConfig) e2).jdtType);
+ return this.javaElementLabelProvider.getImage(((JavaClassMapping) element).getJDTType());
}
}
@@ -677,13 +664,13 @@ public class JpaMakePersistentWizardPage
{
private final JpaProject jpaProject;
private final JptXmlResource ormXmlResource;
- private final PersistentType.Config[] selectedTypeConfigs;
+ private final PersistentType.Config[] selectedTypes;
- AddToOrmXmlRunnable(JpaProject jpaProject, JptXmlResource ormXmlResource, PersistentType.Config[] selectedTypeConfigs) {
+ AddToOrmXmlRunnable(JpaProject jpaProject, JptXmlResource ormXmlResource, PersistentType.Config[] selectedTypes) {
super();
this.jpaProject = jpaProject;
this.ormXmlResource = ormXmlResource;
- this.selectedTypeConfigs = selectedTypeConfigs;
+ this.selectedTypes = selectedTypes;
}
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
@@ -699,7 +686,7 @@ public class JpaMakePersistentWizardPage
// lock the orm.xml resource, it is the only thing we will be modifying.
ISchedulingRule rule = workspace.getRuleFactory().modifyRule(this.ormXmlResource.getFile());
workspace.run(
- new AddToOrmXmlWorkspaceRunnable(this.jpaProject, this.ormXmlResource, this.selectedTypeConfigs),
+ new AddToOrmXmlWorkspaceRunnable(this.jpaProject, this.ormXmlResource, this.selectedTypes),
rule,
IWorkspace.AVOID_UPDATE,
monitor
@@ -718,13 +705,13 @@ public class JpaMakePersistentWizardPage
{
private final JpaProject jpaProject;
private final JptXmlResource ormXmlResource;
- private final PersistentType.Config[] selectedTypeConfigs;
+ private final PersistentType.Config[] selectedTypes;
- AddToOrmXmlWorkspaceRunnable(JpaProject jpaProject, JptXmlResource ormXmlResource, PersistentType.Config[] selectedTypeConfigs) {
+ AddToOrmXmlWorkspaceRunnable(JpaProject jpaProject, JptXmlResource ormXmlResource, PersistentType.Config[] selectedTypes) {
super();
this.jpaProject = jpaProject;
this.ormXmlResource = ormXmlResource;
- this.selectedTypeConfigs = selectedTypeConfigs;
+ this.selectedTypes = selectedTypes;
}
public void run(IProgressMonitor monitor) {
@@ -735,7 +722,7 @@ public class JpaMakePersistentWizardPage
if (jpaProjectManager == null) {
return;
}
- Command addToOrmXmlCommand = new AddToOrmXmlCommand(this.getEntityMappings(),this.selectedTypeConfigs, monitor);
+ Command addToOrmXmlCommand = new AddToOrmXmlCommand(this.getEntityMappings(),this.selectedTypes, monitor);
try {
jpaProjectManager.execute(addToOrmXmlCommand, SynchronousUiCommandContext.instance());
} catch (InterruptedException ex) {
@@ -772,23 +759,24 @@ public class JpaMakePersistentWizardPage
implements Command
{
private final EntityMappings entityMappings;
- private final PersistentType.Config[] selectedTypeConfigs;
+ private final PersistentType.Config[] selectedTypes;
private final IProgressMonitor monitor;
- AddToOrmXmlCommand(EntityMappings entityMappings, PersistentType.Config[] selectedTypeConfigs, IProgressMonitor monitor) {
+ AddToOrmXmlCommand(EntityMappings entityMappings, PersistentType.Config[] selectedTypes, IProgressMonitor monitor) {
super();
this.entityMappings = entityMappings;
- this.selectedTypeConfigs = selectedTypeConfigs;
+ this.selectedTypes = selectedTypes;
this.monitor = monitor;
}
public void execute() {
- this.entityMappings.addPersistentTypes(this.selectedTypeConfigs, this.monitor);
+ //TODO add API to EntityMappings - added this post-M6
+ this.entityMappings.addPersistentTypes(this.selectedTypes, this.monitor);
}
@Override
public String toString() {
- return ObjectTools.toString(this, this.selectedTypeConfigs);
+ return ObjectTools.toString(this, this.selectedTypes);
}
}
@@ -801,14 +789,16 @@ public class JpaMakePersistentWizardPage
/* CU private */ static class AnnotateInJavaRunnable
implements IRunnableWithProgress
{
+ private final JpaMakePersistentWizard wizard;
private final JpaProject jpaProject;
- private final PersistentType.Config[] selectedTypeConfigs;
+ private final PersistentType.Config[] selectedTypes;
private final boolean listInPersistenceXml;
- AnnotateInJavaRunnable(JpaProject jpaProject, PersistentType.Config[] selectedTypeConfigs, boolean listInPersistenceXml) {
+ AnnotateInJavaRunnable(JpaMakePersistentWizard wizard, JpaProject jpaProject, PersistentType.Config[] selectedTypes, boolean listInPersistenceXml) {
super();
+ this.wizard = wizard;
this.jpaProject = jpaProject;
- this.selectedTypeConfigs = selectedTypeConfigs;
+ this.selectedTypes = selectedTypes;
this.listInPersistenceXml = listInPersistenceXml;
}
@@ -825,7 +815,7 @@ public class JpaMakePersistentWizardPage
// lock the entire project, since we could be modifying multiple java files and the persistence.xml file
ISchedulingRule rule = workspace.getRuleFactory().modifyRule(this.jpaProject.getProject());
workspace.run(
- new AnnotateInJavaWorkspaceRunnable(this.jpaProject, this.selectedTypeConfigs, this.listInPersistenceXml),
+ new AnnotateInJavaWorkspaceRunnable(this.wizard, this.jpaProject, this.selectedTypes, this.listInPersistenceXml),
rule,
IWorkspace.AVOID_UPDATE,
monitor
@@ -843,13 +833,15 @@ public class JpaMakePersistentWizardPage
implements IWorkspaceRunnable
{
private final JpaProject jpaProject;
- private final PersistentType.Config[] selectedTypeConfigs;
+ private final PersistentType.Config[] selectedTypes;
private final boolean listInPersistenceXml;
+ private JpaMakePersistentWizard wizard;
- AnnotateInJavaWorkspaceRunnable(JpaProject jpaProject, PersistentType.Config[] selectedTypeConfigs, boolean listInPersistenceXml) {
+ AnnotateInJavaWorkspaceRunnable(JpaMakePersistentWizard wizard, JpaProject jpaProject, PersistentType.Config[] selectedTypes, boolean listInPersistenceXml) {
super();
+ this.wizard = wizard;
this.jpaProject = jpaProject;
- this.selectedTypeConfigs = selectedTypeConfigs;
+ this.selectedTypes = selectedTypes;
this.listInPersistenceXml = listInPersistenceXml;
}
@@ -865,7 +857,7 @@ public class JpaMakePersistentWizardPage
if (jpaProjectManager == null) {
return;
}
- Command annotateInJavaCommand = new AnnotateInJavaCommand(persistenceUnit, this.selectedTypeConfigs, this.listInPersistenceXml, monitor);
+ Command annotateInJavaCommand = new AnnotateInJavaCommand(this.wizard, persistenceUnit, this.selectedTypes, this.listInPersistenceXml, monitor);
try {
jpaProjectManager.execute(annotateInJavaCommand, SynchronousUiCommandContext.instance());
} catch (InterruptedException ex) {
@@ -923,25 +915,71 @@ public class JpaMakePersistentWizardPage
implements Command
{
private final PersistenceUnit persistenceUnit;
- private final PersistentType.Config[] selectedTypeConfigs;
+ private final PersistentType.Config[] selectedTypes;
private final boolean listInPersistenceXml;
private final IProgressMonitor monitor;
+ private final JpaMakePersistentWizard wizard;
- AnnotateInJavaCommand(PersistenceUnit persistenceUnit, PersistentType.Config[] selectedTypeConfigs, boolean listInPersistenceXml, IProgressMonitor monitor) {
+ AnnotateInJavaCommand(JpaMakePersistentWizard wiz, PersistenceUnit persistenceUnit, PersistentType.Config[] selectedTypes, boolean listInPersistenceXml, IProgressMonitor monitor) {
super();
+ this.wizard = wiz;
this.persistenceUnit = persistenceUnit;
- this.selectedTypeConfigs = selectedTypeConfigs;
+ this.selectedTypes = selectedTypes;
this.listInPersistenceXml = listInPersistenceXml;
this.monitor = monitor;
}
public void execute() {
- this.persistenceUnit.addPersistentTypes(this.selectedTypeConfigs, this.listInPersistenceXml, this.monitor);
+ if (this.wizard.getSchema() == null) {
+ this.persistenceUnit.addPersistentTypes(this.selectedTypes, this.listInPersistenceXml, this.monitor);
+ }
+ else {
+ JavaClassMapping[] classMappings = wizard.getJavaClassMappings();
+ SubMonitor sm = SubMonitor.convert(this.monitor, classMappings.length * 2);
+ for (JavaClassMapping classMapping : classMappings) {
+ if (sm.isCanceled()) {
+ return;
+ }
+ PersistentType.Config[] mappedTypes = new PersistentType.Config[1];
+ mappedTypes[0] = classMapping;
+ ((AbstractPersistenceUnit) this.persistenceUnit).addPersistentTypes(mappedTypes, this.listInPersistenceXml, sm);
+ sm.worked(1);
+ if (classMapping.getMappingKey().equals(MappingKeys.ENTITY_TYPE_MAPPING_KEY)) {
+ PersistentType persistentType = this.persistenceUnit.getPersistentType(classMapping.getFullyQualifiedName());
+ annotateJavaClass(this.wizard.getSchema(), classMapping, persistentType, sm);
+ }
+ sm.worked(1);
+ }
+ }
+
}
@Override
public String toString() {
- return ObjectTools.toString(this, this.selectedTypeConfigs);
+ return ObjectTools.toString(this, this.selectedTypes);
+ }
+
+ private void annotateJavaClass(Schema schema, JavaClassMapping classMapping, PersistentType persistentType, IProgressMonitor pm)
+ {
+ TableAnnotationAttributes tableAttrs = new TableAnnotationAttributes();
+ tableAttrs.setTableName(classMapping.getDBTable());
+ tableAttrs.setSchema(schema.getName());
+ EntityPropertyElem[] propElems = classMapping.getPropertyMappings().toArray(new EntityPropertyElem[0]);
+ EntityMappingsDoc mappingDoc = new EntityMappingsDoc(classMapping.getFullyQualifiedName(),
+ this.persistenceUnit.getJpaProject().getProject(), tableAttrs,
+ propElems, false);
+ JavaClassAnnotater annotater = new JavaClassAnnotater(persistentType, mappingDoc, wizard.getSchema());
+ annotater.setDatabaseAnnotationNameBuilder(wizard.getDatabaseAnnotationNameBuilder());
+ try
+ {
+ annotater.annotate(pm);
+ }
+ catch (Exception e)
+ {
+ JptJpaUiPlugin.instance().logError(e);
+ }
+
}
}
+
}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/makepersistent/JptJpaUiMakePersistentMessages.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/makepersistent/JptJpaUiMakePersistentMessages.java
new file mode 100644
index 0000000..a88526e
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/makepersistent/JptJpaUiMakePersistentMessages.java
@@ -0,0 +1,118 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+
+package org.eclipse.jpt.jpa.ui.internal.wizards.makepersistent;
+
+import org.eclipse.osgi.util.NLS;
+
+
+public class JptJpaUiMakePersistentMessages {
+
+ private static final String BUNDLE_NAME = "jpt_jpa_ui_make_persistent"; //$NON-NLS-1$
+ private static final Class<?> BUNDLE_CLASS = JptJpaUiMakePersistentMessages.class;
+ static {
+ NLS.initializeMessages(BUNDLE_NAME, BUNDLE_CLASS);
+ }
+
+ public static String ADD;
+ public static String REMOVE;
+ public static String BROWSE;
+ public static String CASCADE;
+ public static String CHOOSE_TYPE;
+
+ public static String CLASS_MAPPING_PAGE_TITLE;
+ public static String CLASS_MAPPING_PAGE_DESC;
+ public static String CLASS_MAPPING_PAGE_TYPE_TABLE_COLUMN;
+ public static String CLASS_MAPPING_PAGE_MAPPING_TABLE_COLUMN;
+ public static String CLASS_MAPPING_PAGE_PRIMARY_KEY_PROPERTY_COLUMN;
+
+ public static String SELECT_TABLE_DLG_DESC;
+ public static String SELECT_TABLE_DLG_TITLE;
+
+ public static String PROPS_MAPPING_PAGE_TITLE;
+ public static String PROPS_MAPPING_PAGE_DESC;
+ public static String PROPS_MAPPING_PAGE_LABEL;
+ public static String PROPS_MAPPING_PAGE_JAVA_CLASS_LABEL;
+ public static String PROPS_MAPPING_PAGE_PROPERTY_NAME_LABEL;
+ public static String PROPS_MAPPING_PAGE_PROPERTY_TYPE_LABEL;
+ public static String PROPS_MAPPING_PAGE_DATABASE_COLUMN;
+ public static String PROPS_MAPPING_PAGE_COLUMN_TYPE;
+ public static String PROPS_MAPPING_PAGE_COLUMN_TYPE_NA;
+ public static String PROPS_MAPPING_PAGE_EDIT;
+ public static String PROPS_MAPPING_PAGE_REMOVE;
+ public static String PROPS_MAPPING_PAGE_UNSPECIFIED;
+ public static String PROPS_MAPPING_PAGE_MAPPEDBY;
+ public static String PROPS_MAPPING_PAGE_JOIN_TABLE;
+ public static String PROPS_MAPPING_PAGE_JOIN_AND;
+
+ public static String PROPERTY_NAME_LABEL;
+ public static String PROPERTY_TYPE_LABEL;
+ public static String ID_ANNOTATION_DLG_TITLE;
+ public static String ID_ANNOTATION_GROUP_DESC;
+ public static String GENERATION_STRATEGY;
+ public static String COL_ANNOTATION_GROUP_DESC;
+ public static String COLUMN_NAME;
+ public static String REF_COLUMN_NAME;
+ public static String UNIQUE;
+ public static String NULLABLE;
+ public static String LENGTH;
+ public static String PRECISION;
+ public static String SCALE;
+ public static String INSERTABLE;
+ public static String UPDATABLE;
+ public static String TEMPORAL;
+ public static String FETCH_TYPE;
+ public static String SELECT_COLUMN_DLG_TITLE;
+ public static String SELECT_COLUMN_DLG_DESC;
+ public static String BASIC_ANNOTATION_DLG_TITLE;
+ public static String BASIC_ANNOTATION_GROUP_DESC;
+ public static String SELECT_CASCADE_DLG_TITLE;
+ public static String TOMANY_ANNOTATION_DLG_TITLE;
+ public static String TARGET_ENTITY_GROUP_DESC;
+ public static String TARGET_ENTITY_GROUP_LABEL;
+ public static String ORDER_BY_TITLE;
+ public static String ORDER_BY_LABEL;
+ public static String ORDER_BY_DESC;
+ public static String MAPPED_BY_DESC;
+ public static String PK_JOIN_COLUMN_DESC;
+ public static String JOIN_TABLE_DESC;
+ public static String MANY_TO_MANY_PROP_DESC;
+ public static String ONE_TO_MANY_PROP_DESC;
+ public static String MANY_TO_ONE_PROP_DESC;
+ public static String ONE_TO_ONE_PROP_DESC;
+ public static String JOIN_PROPS;
+ public static String REF_TABLE_NOT_SPECIFIED;
+ public static String ADD_JOIN_COLUMN;
+ public static String JOIN_COLUMN_TABLE_DESC;
+ public static String NO_JOIN_COLUMN_LABEL;
+ public static String ADD_JOIN_COLUMN_DLG_TITLE;
+ public static String ASSOCIATION_WIZARD_TITLE;
+ public static String ASSOCIATION_WIZARD_ERROR;
+ public static String ASSOCIATION_WIZARD_NO_TARGET_ENTITY;
+ public static String CARDINALITY_PAGE_TITLE;
+ public static String CARDINALITY_PAGE_DESC;
+ public static String MAPPING_PAGE_TITLE;
+ public static String MAPPING_PAGE_DESC;
+ public static String JOIN_PROPS_PAGE_TITLE;
+ public static String JOIN_PROPS_PAGE_DESC;
+ public static String CHOOSE_PROPERTY_TITLE;
+ public static String CHOOSE_PROPERTY_DESC;
+ public static String PK_JOIN_COLUMNS_LABEL;
+ public static String JOIN_COLUMNS_LABEL;
+ public static String EDIT_JOIN_COLUMNS;
+ public static String EDIT_JOIN_COLUMNS_DESC;
+ public static String SELECT_ORDERBY_DIALOG_PROPERTY;
+ public static String SELECT_ORDERBY_DIALOG_ORDER;
+
+ private JptJpaUiMakePersistentMessages() {
+ throw new UnsupportedOperationException();
+ }
+
+}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/makepersistent/ManyToManyJoinPropsPage.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/makepersistent/ManyToManyJoinPropsPage.java
new file mode 100644
index 0000000..c3298f0
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/makepersistent/ManyToManyJoinPropsPage.java
@@ -0,0 +1,232 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+
+package org.eclipse.jpt.jpa.ui.internal.wizards.makepersistent;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.jface.resource.ResourceManager;
+import org.eclipse.jpt.jpa.annotate.mapping.EntityRefPropertyElem;
+import org.eclipse.jpt.jpa.annotate.mapping.JoinStrategy;
+import org.eclipse.jpt.jpa.core.context.persistence.PersistenceUnit;
+import org.eclipse.jpt.jpa.db.Schema;
+import org.eclipse.jpt.jpa.db.Table;
+import org.eclipse.jpt.jpa.ui.JptJpaUiImages;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Text;
+
+public class ManyToManyJoinPropsPage extends JoinPropertiesPage
+{
+ private Text mappedByText;
+ private Button mappedByBrowseBtn;
+ private Button joinTableRadio;
+ private Text joinTableText;
+ private Button joinTableBtn;
+ private Button mappedByRadio;
+ private Control joinColumnsCtl;
+ private Control inverseJoinColumnsCtl;
+
+ public ManyToManyJoinPropsPage(PersistenceUnit persistenceUnit, ResourceManager resourceManager, IProject project, String javaClass,
+ Schema schema, Table table, Table inverseTable, EntityRefPropertyElem refElem)
+ {
+ super(persistenceUnit, resourceManager, project, javaClass, schema, table, inverseTable, refElem);
+ }
+
+ @Override
+ public Composite createJoinProps(Composite parent)
+ {
+ Composite group = new Composite(parent, SWT.NONE);
+ GridLayout gl = new GridLayout(3, false);
+ group.setLayout(gl);
+ GridData gd = new GridData(SWT.FILL, SWT.FILL, true, false);
+ gd.widthHint = 400;
+ gd.heightHint = AssociationAnnotationWizard.JOIN_PROP_GROUP_HEIGHT;
+ group.setLayoutData(gd);
+
+ mappedByRadio = AssociationAnnotationWizard.createButton(group, 1,
+ JptJpaUiMakePersistentMessages.PROPS_MAPPING_PAGE_MAPPEDBY,
+ -1, SWT.RADIO);
+ mappedByText = AssociationAnnotationWizard.createText(group, true, 1, SWT.BORDER);
+ Image listImage = resourceManager.createImage(JptJpaUiImages.LIST_OF_VALUES);
+ mappedByBrowseBtn = AssociationAnnotationWizard.createImageButton(
+ group, listImage, 1, SWT.NONE,
+ JptJpaUiMakePersistentMessages.BROWSE);
+
+ joinTableRadio = AssociationAnnotationWizard.createButton(group, 1,
+ JptJpaUiMakePersistentMessages.PROPS_MAPPING_PAGE_JOIN_TABLE,
+ -1, SWT.RADIO);
+ joinTableText = AssociationAnnotationWizard.createText(group, true, 1, SWT.BORDER);
+ joinTableBtn = AssociationAnnotationWizard.createImageButton(
+ group, listImage, 1, SWT.NONE,
+ JptJpaUiMakePersistentMessages.BROWSE);
+ return group;
+ }
+
+ @Override
+ protected void initFields()
+ {
+ String mappedBy = refElem.getMappedBy();
+ if (mappedBy != null)
+ {
+ mappedByRadio.setSelection(true);
+ mappedByText.setEnabled(true);
+ mappedByBrowseBtn.setEnabled(true);
+ mappedByText.setText(mappedBy);
+ joinTableRadio.setSelection(false);
+ joinTableText.setEnabled(false);
+ joinTableBtn.setEnabled(false);
+ }
+ else
+ {
+ mappedByRadio.setSelection(false);
+ mappedByText.setEnabled(false);
+ mappedByBrowseBtn.setEnabled(false);
+ joinTableRadio.setSelection(true);
+ joinTableText.setEnabled(true);
+ joinTableBtn.setEnabled(true);
+ if (refElem.getJoinTable() != null)
+ joinTableText.setText(refElem.getJoinTable().getTableName());
+ }
+ }
+
+ @Override
+ protected void addListeners()
+ {
+ super.addListeners();
+ joinTableRadio.addSelectionListener(new SelectionAdapter()
+ {
+ @Override
+ public void widgetSelected(SelectionEvent e)
+ {
+ handleJoinPropsChange();
+ }
+ });
+ joinTableText.addModifyListener(new ModifyListener()
+ {
+ public void modifyText(ModifyEvent e)
+ {
+ handleJoinTableChange(joinTableText);
+ }
+ });
+ joinTableBtn.addSelectionListener(new SelectionAdapter()
+ {
+ @Override
+ public void widgetSelected(SelectionEvent e)
+ {
+ chooseJoinTable(joinTableText);
+ }
+ });
+ mappedByText.addModifyListener(new ModifyListener()
+ {
+ public void modifyText(ModifyEvent e)
+ {
+ handleMappedByChange(mappedByText);
+ }
+ });
+ mappedByBrowseBtn.addSelectionListener(new SelectionAdapter()
+ {
+ @Override
+ public void widgetSelected(SelectionEvent e)
+ {
+ chooseMappedBy(mappedByText);
+ }
+ });
+
+ mappedByRadio.addSelectionListener(new SelectionAdapter()
+ {
+ @Override
+ public void widgetSelected(SelectionEvent e)
+ {
+ handleJoinPropsChange();
+ }
+ });
+ }
+
+ private void handleJoinPropsChange()
+ {
+ if (joinTableRadio.getSelection())
+ {
+ refElem.setJoinStrategy(JoinStrategy.JOIN_TABLE);
+ refElem.removeMappedBy();
+ joinTableText.setEnabled(true);
+ joinTableBtn.setEnabled(true);
+ mappedByText.setText("");
+ mappedByText.setEnabled(false);
+ mappedByBrowseBtn.setEnabled(false);
+ }
+ else
+ {
+ refElem.setJoinStrategy(JoinStrategy.MAPPED_BY);
+ refElem.removeJoinTable();
+ joinTableText.setText("");
+ joinTableText.setEnabled(false);
+ joinTableBtn.setEnabled(false);
+ mappedByText.setEnabled(true);
+ mappedByBrowseBtn.setEnabled(true);
+ refreshJoinProperties();
+ }
+ }
+
+ @Override
+ protected void refreshJoinProperties()
+ {
+ if (joinColumnsCtl != null)
+ {
+ joinColumnsCtl.dispose();
+ }
+ if (inverseJoinColumnsCtl != null)
+ {
+ inverseJoinColumnsCtl.dispose();
+ }
+ String joinTableName = getJoinTableName();
+ Table joinTable = null;
+ if (joinTableName != null)
+ joinTable = schema.getTableNamed(joinTableName);
+
+ JoinColumnsAnnotationEditor joinColEditor =
+ new JoinColumnsAnnotationEditor(resourceManager, refElem, false, joinTable, table, this);
+ Composite joinProps = getJoinPropsComposite();
+ joinColumnsCtl = joinColEditor.createJoinColumnsControl(joinProps);
+ if (joinColumnsCtl != null)
+ {
+ GridData gd2 = new GridData(GridData.FILL_HORIZONTAL);
+ gd2.horizontalSpan = 3;
+ gd2.widthHint = 400;
+ joinColumnsCtl.setLayoutData(gd2);
+ joinProps.pack();
+ joinProps.layout();
+ }
+
+ JoinColumnsAnnotationEditor inverseJoinColEditor =
+ new JoinColumnsAnnotationEditor(resourceManager, refElem, true, joinTable, inverseTable, this);
+
+ inverseJoinColumnsCtl = inverseJoinColEditor.createJoinColumnsControl(joinProps);
+ if (inverseJoinColumnsCtl != null)
+ {
+ GridData gd2 = new GridData(GridData.FILL_HORIZONTAL);
+ gd2.horizontalSpan = 3;
+ gd2.widthHint = 400;
+ inverseJoinColumnsCtl.setLayoutData(gd2);
+ joinProps.pack();
+ joinProps.layout();
+ }
+
+ }
+
+}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/makepersistent/ManyToManyMappingPage.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/makepersistent/ManyToManyMappingPage.java
new file mode 100644
index 0000000..7f282f0
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/makepersistent/ManyToManyMappingPage.java
@@ -0,0 +1,28 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+
+package org.eclipse.jpt.jpa.ui.internal.wizards.makepersistent;
+
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.jface.resource.ResourceManager;
+import org.eclipse.jface.wizard.IWizardPage;
+import org.eclipse.jpt.jpa.annotate.mapping.EntityRefPropertyElem;
+import org.eclipse.jpt.jpa.core.context.persistence.PersistenceUnit;
+
+public class ManyToManyMappingPage extends EntityMappingPage
+{
+ public ManyToManyMappingPage(PersistenceUnit persistenceUnit, ResourceManager resourceManager, IProject project, EntityRefPropertyElem refElem, IWizardPage nextPage)
+ {
+ super(persistenceUnit, resourceManager, project, refElem, nextPage);
+ }
+
+
+}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/makepersistent/ManyToOneJoinPropsPage.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/makepersistent/ManyToOneJoinPropsPage.java
new file mode 100644
index 0000000..ad283cc
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/makepersistent/ManyToOneJoinPropsPage.java
@@ -0,0 +1,285 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+
+package org.eclipse.jpt.jpa.ui.internal.wizards.makepersistent;
+
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.jface.resource.ResourceManager;
+import org.eclipse.jpt.jpa.annotate.mapping.EntityRefPropertyElem;
+import org.eclipse.jpt.jpa.annotate.mapping.JoinStrategy;
+import org.eclipse.jpt.jpa.annotate.mapping.JoinTableAttributes;
+import org.eclipse.jpt.jpa.core.context.persistence.PersistenceUnit;
+import org.eclipse.jpt.jpa.db.Schema;
+import org.eclipse.jpt.jpa.db.Table;
+import org.eclipse.jpt.jpa.ui.JptJpaUiImages;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Text;
+
+public class ManyToOneJoinPropsPage extends JoinPropertiesPage
+{
+ private JoinColumnsAnnotationEditor joinColEditor;
+ private Button joinColumnRadio;
+ private Button joinTableRadio;
+ private Composite joinColumnGroup;
+ private Composite joinTableGroup;
+ private Text joinTableText;
+ private Button joinTableBtn;
+ private Control joinColumnsCtl;
+ private Control joinColumnsCtl2, inverseJoinColumnsCtl;
+ private boolean isJpa1_0Project;
+
+ public ManyToOneJoinPropsPage(PersistenceUnit persistenceUnit, ResourceManager resourceManager, IProject project, String javaClass,
+ Schema schema, Table table, Table inverseTable, EntityRefPropertyElem refElem)
+ {
+ super(persistenceUnit, resourceManager, project, javaClass, schema, table, inverseTable, refElem);
+ joinColEditor =
+ new JoinColumnsAnnotationEditor(resourceManager, refElem, false, table, inverseTable, this);
+ this.isJpa1_0Project = isJpa1_0Project();
+ }
+
+ @Override
+ public Composite createJoinProps(Composite parent)
+ {
+ Composite group;
+
+ if (isJpa1_0Project)
+ {
+ group = new Composite(parent, SWT.NONE);
+ GridLayout gl = new GridLayout(1, false);
+ group.setLayout(gl);
+ GridData gd = new GridData(GridData.FILL_HORIZONTAL);
+ gd.widthHint = 400;
+ gd.heightHint = AssociationAnnotationWizard.JOIN_PROP_GROUP_HEIGHT;
+ group.setLayoutData(gd);
+ }
+ else
+ {
+ // Outer group
+ group = new Composite(parent, SWT.NONE);
+ GridLayout gl = new GridLayout(3, false);
+ group.setLayout(gl);
+ GridData gd = new GridData(GridData.FILL_HORIZONTAL);
+ group.setLayoutData(gd);
+
+ joinColumnRadio = AssociationAnnotationWizard.createButton(group, 3,
+ JptJpaUiMakePersistentMessages.JOIN_COLUMNS_LABEL,
+ -1, SWT.RADIO);
+ // Join columns ctl parent
+ joinColumnGroup = new Composite(group, SWT.NONE);
+ GridData gd2 = new GridData(GridData.FILL_HORIZONTAL);
+ gd2.horizontalSpan = 3;
+ joinColumnGroup.setLayoutData(gd2);
+ GridLayout gl2 = new GridLayout(1, false);
+ gl2.marginWidth = gl2.marginHeight = 0;
+ joinColumnGroup.setLayout(gl2);
+
+ joinTableRadio = AssociationAnnotationWizard.createButton(group, 1,
+ JptJpaUiMakePersistentMessages.PROPS_MAPPING_PAGE_JOIN_TABLE,
+ -1, SWT.RADIO);
+ joinTableText = AssociationAnnotationWizard.createText(group, true, 1, SWT.BORDER);
+ Image listImage = resourceManager.createImage(JptJpaUiImages.LIST_OF_VALUES);
+ joinTableBtn = AssociationAnnotationWizard.createImageButton(
+ group, listImage, 1, SWT.NONE,
+ JptJpaUiMakePersistentMessages.BROWSE);
+ // Join Table ctl parent
+ joinTableGroup = new Composite(group, SWT.NONE);
+ GridData gd3 = new GridData(GridData.FILL_HORIZONTAL);
+ gd3.horizontalSpan = 3;
+ gd3.widthHint = 400;
+ gd3.heightHint = 280;
+ joinTableGroup.setLayoutData(gd3);
+ GridLayout gl3 = new GridLayout(1, false);
+ gl3.marginWidth = gl3.marginHeight = 0;
+ joinTableGroup.setLayout(gl3);
+ }
+ return group;
+ }
+
+ @Override
+ protected void addListeners()
+ {
+ super.addListeners();
+ if (!isJpa1_0Project)
+ {
+ joinTableRadio.addSelectionListener(new SelectionAdapter()
+ {
+ @Override
+ public void widgetSelected(SelectionEvent e)
+ {
+ handleJoinPropsChange();
+ }
+ });
+ joinTableText.addModifyListener(new ModifyListener()
+ {
+ public void modifyText(ModifyEvent e)
+ {
+ handleJoinTableChange(joinTableText);
+ }
+ });
+ joinTableBtn.addSelectionListener(new SelectionAdapter()
+ {
+ @Override
+ public void widgetSelected(SelectionEvent e)
+ {
+ chooseJoinTable(joinTableText);
+ }
+ });
+ }
+ }
+
+ @Override
+ protected void initFields()
+ {
+ if (isJpa1_0Project)
+ {
+ return;
+ }
+ JoinTableAttributes joinTableAttr = refElem.getJoinTable();
+ if (joinTableAttr == null)
+ {
+ joinColumnRadio.setSelection(true);
+ joinColEditor.setEnable(true);
+ joinTableRadio.setSelection(false);
+ joinTableText.setEnabled(false);
+ joinTableBtn.setEnabled(false);
+ }
+ else
+ {
+ joinColumnRadio.setSelection(false);
+ joinColEditor.setEnable(false);
+ joinTableRadio.setSelection(true);
+ joinTableText.setEnabled(true);
+ joinTableBtn.setEnabled(true);
+ if (refElem.getJoinTable() != null)
+ joinTableText.setText(refElem.getJoinTable().getTableName());
+ }
+ }
+
+ @Override
+ protected void refreshJoinProperties()
+ {
+ if (joinColumnsCtl != null)
+ {
+ joinColumnsCtl.dispose();
+ joinColumnsCtl = null;
+ }
+
+ Composite joinProps = getJoinPropsComposite();
+ if (refElem.getJoinStrategy() == JoinStrategy.JOIN_COLUMNS)
+ {
+ Composite parent = joinColumnGroup != null ? joinColumnGroup : joinProps;
+ joinColumnsCtl = joinColEditor.createJoinColumnsControl(parent);
+ if (joinColumnsCtl != null)
+ {
+ GridData gd2 = new GridData(GridData.FILL_HORIZONTAL);
+ gd2.grabExcessHorizontalSpace = true;
+ joinColumnsCtl.setLayoutData(gd2);
+ parent.pack();
+ parent.layout();
+ }
+ }
+ if (!isJpa1_0Project)
+ {
+ refreshJoinTableGroup();
+ }
+
+ joinProps.pack();
+ joinProps.layout();
+ }
+
+ private void refreshJoinTableGroup()
+ {
+ if (joinColumnsCtl2 != null)
+ {
+ joinColumnsCtl2.dispose();
+ joinColumnsCtl2 = null;
+ }
+ if (inverseJoinColumnsCtl != null)
+ {
+ inverseJoinColumnsCtl.dispose();
+ inverseJoinColumnsCtl = null;
+ }
+ if (refElem.getJoinStrategy() != JoinStrategy.JOIN_TABLE)
+ {
+ return;
+ }
+ String joinTableName = getJoinTableName();
+ Table joinTable = null;
+ if (joinTableName != null)
+ joinTable = schema.getTableNamed(joinTableName);
+
+ JoinColumnsAnnotationEditor joinColEditor =
+ new JoinColumnsAnnotationEditor(resourceManager, refElem, false, joinTable, table, this);
+ joinColumnsCtl2 = joinColEditor.createJoinColumnsControl(joinTableGroup);
+ if (joinColumnsCtl2 != null)
+ {
+ GridData gd2 = new GridData(GridData.FILL_HORIZONTAL);
+ gd2.grabExcessHorizontalSpace = true;
+ joinColumnsCtl2.setLayoutData(gd2);
+ joinTableGroup.pack();
+ joinTableGroup.layout();
+ }
+
+ JoinColumnsAnnotationEditor inverseJoinColEditor =
+ new JoinColumnsAnnotationEditor(resourceManager, refElem, true, joinTable, inverseTable, this);
+
+ inverseJoinColumnsCtl = inverseJoinColEditor.createJoinColumnsControl(joinTableGroup);
+ if (inverseJoinColumnsCtl != null)
+ {
+ GridData gd2 = new GridData(GridData.FILL_HORIZONTAL);
+ gd2.grabExcessHorizontalSpace = true;
+ inverseJoinColumnsCtl.setLayoutData(gd2);
+ joinTableGroup.pack();
+ joinTableGroup.layout();
+ }
+
+ }
+
+ private void handleJoinPropsChange()
+ {
+ if (joinTableRadio.getSelection())
+ {
+ refElem.setJoinStrategy(JoinStrategy.JOIN_TABLE);
+ refElem.removeAllJoinColumns();
+ JoinTableAttributes joinTblAttr = refElem.getJoinTable();
+ if (joinTblAttr == null)
+ {
+ joinTblAttr = new JoinTableAttributes();
+ refElem.setJoinTable(joinTblAttr);
+ }
+ refreshJoinProperties();
+ joinTableText.setEnabled(true);
+ joinTableBtn.setEnabled(true);
+ joinColumnRadio.setSelection(false);
+ }
+ else
+ {
+ refElem.setJoinStrategy(JoinStrategy.JOIN_COLUMNS);
+ refElem.removeJoinTable();
+ joinTableText.setText("");
+ refreshJoinProperties();
+ joinTableText.setEnabled(false);
+ joinTableBtn.setEnabled(false);
+ joinColumnRadio.setSelection(true);
+ }
+ }
+
+}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/makepersistent/ManyToOneMappingPage.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/makepersistent/ManyToOneMappingPage.java
new file mode 100644
index 0000000..d0711e6
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/makepersistent/ManyToOneMappingPage.java
@@ -0,0 +1,35 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+
+package org.eclipse.jpt.jpa.ui.internal.wizards.makepersistent;
+
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.jface.resource.ResourceManager;
+import org.eclipse.jface.wizard.IWizardPage;
+import org.eclipse.jpt.jpa.annotate.mapping.EntityRefPropertyElem;
+import org.eclipse.jpt.jpa.core.context.persistence.PersistenceUnit;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Group;
+
+public class ManyToOneMappingPage extends EntityMappingPage
+{
+ public ManyToOneMappingPage(PersistenceUnit persistenceUnit, ResourceManager resourceManager, IProject project, EntityRefPropertyElem refElem, IWizardPage nextPage)
+ {
+ super(persistenceUnit, resourceManager, project, refElem, nextPage);
+ }
+
+ @Override
+ protected Group createTargetEntityGroup(Composite parent)
+ {
+ return null;
+ }
+
+}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/makepersistent/MappingAnnotationCtl.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/makepersistent/MappingAnnotationCtl.java
new file mode 100644
index 0000000..2a21918
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/makepersistent/MappingAnnotationCtl.java
@@ -0,0 +1,163 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+
+package org.eclipse.jpt.jpa.ui.internal.wizards.makepersistent;
+
+import java.util.List;
+
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.resource.ResourceManager;
+import org.eclipse.jpt.jpa.annotate.mapping.AnnotationAttrConverter;
+import org.eclipse.jpt.jpa.annotate.mapping.AnnotationAttribute;
+import org.eclipse.jpt.jpa.annotate.mapping.AnnotationAttributeNames;
+import org.eclipse.jpt.jpa.annotate.mapping.EntityRefPropertyElem;
+import org.eclipse.jpt.jpa.ui.JptJpaUiImages;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Combo;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Group;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Text;
+
+public class MappingAnnotationCtl
+{
+ private EntityRefPropertyElem refElem;
+ private Text propNameText;
+ private Text propTypeText;
+ private Text cascadeText;
+ private Button cascadeBrowseBtn;
+ private Combo fetchTypeCombo;
+ private ResourceManager resourceManager;
+
+ public MappingAnnotationCtl(ResourceManager resourceManager, EntityRefPropertyElem refElem)
+ {
+ this.refElem = refElem;
+ this.resourceManager = resourceManager;
+ }
+
+ Composite createMappingPropGroup(Composite parent, int style)
+ {
+ Group mappingGroup = new Group(parent, SWT.NONE);
+ GridLayout layout = new GridLayout(3, false);
+ mappingGroup.setLayout(layout);
+ mappingGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+
+ // Property Name
+ AssociationAnnotationWizard.createLabel(mappingGroup, 1,
+ JptJpaUiMakePersistentMessages.PROPERTY_NAME_LABEL, -1);
+ propNameText = AssociationAnnotationWizard.createText(mappingGroup, 1, true, null,
+ SWT.BORDER | SWT.READ_ONLY);
+ new Label(mappingGroup, SWT.NULL);
+ // Property type
+ AssociationAnnotationWizard.createLabel(mappingGroup, 1,
+ JptJpaUiMakePersistentMessages.PROPERTY_TYPE_LABEL, -1);
+ propTypeText = AssociationAnnotationWizard.createText(mappingGroup, 1, true, null,
+ SWT.BORDER | SWT.READ_ONLY);
+ new Label(mappingGroup, SWT.NULL);
+ // cascade
+ AssociationAnnotationWizard.createLabel(mappingGroup, 1,
+ JptJpaUiMakePersistentMessages.CASCADE, -1);
+ cascadeText = AssociationAnnotationWizard.createText(mappingGroup, 1, true, null,
+ SWT.BORDER | SWT.READ_ONLY);
+ cascadeBrowseBtn = AssociationAnnotationWizard.createImageButton(
+ mappingGroup, resourceManager.createImage(JptJpaUiImages.LIST_OF_VALUES), 1, SWT.NONE,
+ JptJpaUiMakePersistentMessages.BROWSE);
+ // Fetch type
+ AssociationAnnotationWizard.createLabel(mappingGroup, 1,
+ JptJpaUiMakePersistentMessages.FETCH_TYPE,
+ -1);
+ fetchTypeCombo = AssociationAnnotationWizard.createCombo(mappingGroup, true, 1,
+ SWT.BORDER | SWT.READ_ONLY | SWT.DROP_DOWN, -1);
+ new Label(mappingGroup, SWT.NULL);
+ return mappingGroup;
+ }
+
+ void initFields()
+ {
+ propNameText.setText(refElem.getPropertyName());
+ propTypeText.setText(refElem.getPropertyType());
+ String cascadeStr = getCascadeDisplayStr(refElem.getAllCascades());
+ cascadeText.setText(cascadeStr);
+ fetchTypeCombo.setItems(
+ AnnotationAttrConverter.getTagEnumStringValues(AnnotationAttrConverter.FETCH));
+ AnnotationAttribute fetchAttr =
+ refElem.getAnnotationAttribute(AnnotationAttributeNames.FETCH);
+ if (fetchAttr != null)
+ {
+ fetchTypeCombo.select(fetchTypeCombo.indexOf(fetchAttr.attrValue));
+ }
+ }
+
+ void addListeners()
+ {
+ cascadeBrowseBtn.addSelectionListener(new SelectionAdapter()
+ {
+ @Override
+ public void widgetSelected(SelectionEvent e)
+ {
+ chooseCascade();
+ }
+ });
+ fetchTypeCombo.addSelectionListener(new SelectionAdapter()
+ {
+ @Override
+ public void widgetSelected(SelectionEvent e)
+ {
+ handleFetchTypeChange();
+ }
+ });
+
+ }
+
+ private String getCascadeDisplayStr(List<String> cascades)
+ {
+ assert cascades != null;
+ if (cascades.isEmpty())
+ return ""; //$NON-NLS-1$
+
+ StringBuffer cascadeBuf = new StringBuffer();
+ for (int i = 0; i < cascades.size(); i++)
+ {
+ if (i != 0)
+ cascadeBuf.append(", "); //$NON-NLS-1$
+ cascadeBuf.append(cascades.get(i));
+ }
+ return cascadeBuf.toString();
+ }
+
+ private void chooseCascade()
+ {
+ SelectCascadeDialog dlg = new SelectCascadeDialog(Display.getDefault().getActiveShell(),
+ refElem.getAllCascades());
+ if (dlg.open() == Dialog.OK)
+ {
+ List<String> cascades = dlg.getAllCascades();
+ refElem.setCascades(cascades);
+ cascadeText.setText(getCascadeDisplayStr(cascades));
+ }
+ }
+
+ private void handleFetchTypeChange()
+ {
+ int index = fetchTypeCombo.getSelectionIndex();
+ String newFetchType = fetchTypeCombo.getItem(index);
+ AnnotationAttribute fetchAttr =
+ new AnnotationAttribute(
+ AnnotationAttributeNames.FETCH, AnnotationAttrConverter.FETCH, newFetchType);
+
+ refElem.setAnnotationAttr(fetchAttr);
+ }
+}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/makepersistent/OneToManyJoinPropsPage.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/makepersistent/OneToManyJoinPropsPage.java
new file mode 100644
index 0000000..02ccd73
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/makepersistent/OneToManyJoinPropsPage.java
@@ -0,0 +1,387 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+
+package org.eclipse.jpt.jpa.ui.internal.wizards.makepersistent;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.resource.ResourceManager;
+import org.eclipse.jpt.jpa.annotate.mapping.EntityRefPropertyElem;
+import org.eclipse.jpt.jpa.annotate.mapping.JoinStrategy;
+import org.eclipse.jpt.jpa.annotate.mapping.JoinTableAttributes;
+import org.eclipse.jpt.jpa.core.context.persistence.PersistenceUnit;
+import org.eclipse.jpt.jpa.db.Schema;
+import org.eclipse.jpt.jpa.db.Table;
+import org.eclipse.jpt.jpa.ui.JptJpaUiImages;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Text;
+
+public class OneToManyJoinPropsPage extends JoinPropertiesPage
+{
+ private Button mappedByRadio;
+ private Text mappedByText;
+ private Button mappedByBrowseBtn;
+ private Button joinColumnRadio;
+ private Button joinTableRadio;
+ private Composite joinColumnGroup;
+ private Composite joinTableGroup;
+ private Text joinTableText;
+ private Button joinTableBtn;
+ private Control joinColumnsCtl;
+ private Control joinColumnsCtl2, inverseJoinColumnsCtl;
+ private JoinColumnsAnnotationEditor joinColEditor;
+
+ public OneToManyJoinPropsPage(PersistenceUnit persistenceUnit, ResourceManager resourceManager, IProject project, String javaClass,
+ Schema schema, Table table, Table inverseTable, EntityRefPropertyElem refElem)
+ {
+ super(persistenceUnit, resourceManager, project, javaClass, schema, table, inverseTable, refElem);
+ this.joinColEditor =
+ new JoinColumnsAnnotationEditor(resourceManager, refElem, false, table, inverseTable, this);
+
+ }
+
+ @Override
+ public Composite createJoinProps(Composite parent)
+ {
+ Composite group = new Composite(parent, SWT.NONE);
+ GridLayout gl = new GridLayout(3, false);
+ group.setLayout(gl);
+ GridData gd = new GridData(GridData.FILL_HORIZONTAL);
+ group.setLayoutData(gd);
+
+ // Mapped by
+ mappedByRadio = AssociationAnnotationWizard.createButton(group, 1,
+ JptJpaUiMakePersistentMessages.PROPS_MAPPING_PAGE_MAPPEDBY,
+ -1, SWT.RADIO);
+ mappedByText = AssociationAnnotationWizard.createText(group, true, 1, SWT.BORDER);
+ mappedByBrowseBtn = AssociationAnnotationWizard.createImageButton(
+ group, resourceManager.createImage(JptJpaUiImages.LIST_OF_VALUES), 1, SWT.NONE,
+ JptJpaUiMakePersistentMessages.BROWSE);
+ // Join Columns
+ if (!isJpa1_0Project())
+ {
+ joinColumnRadio = AssociationAnnotationWizard.createButton(group, 3,
+ JptJpaUiMakePersistentMessages.JOIN_COLUMNS_LABEL,
+ -1, SWT.RADIO);
+ // Join columns ctl parent
+ joinColumnGroup = new Composite(group, SWT.NONE);
+ GridData gd2 = new GridData(GridData.FILL_HORIZONTAL);
+ gd2.horizontalSpan = 3;
+ joinColumnGroup.setLayoutData(gd2);
+ GridLayout gl2 = new GridLayout(1, false);
+ gl2.marginWidth = gl2.marginHeight = 0;
+ joinColumnGroup.setLayout(gl2);
+ }
+ // Join Table
+ joinTableRadio = AssociationAnnotationWizard.createButton(group, 1,
+ JptJpaUiMakePersistentMessages.PROPS_MAPPING_PAGE_JOIN_TABLE,
+ -1, SWT.RADIO);
+ joinTableText = AssociationAnnotationWizard.createText(group, true, 1, SWT.BORDER);
+ Image listImage = resourceManager.createImage(JptJpaUiImages.LIST_OF_VALUES);
+ joinTableBtn = AssociationAnnotationWizard.createImageButton(
+ group, listImage, 1, SWT.NONE,
+ JptJpaUiMakePersistentMessages.BROWSE);
+ // Join Table ctl parent
+ joinTableGroup = new Composite(group, SWT.NONE);
+ GridData gd3 = new GridData(GridData.FILL_HORIZONTAL);
+ gd3.horizontalSpan = 3;
+ gd3.widthHint = 400;
+ gd3.heightHint = 280;
+ joinTableGroup.setLayoutData(gd3);
+ GridLayout gl3 = new GridLayout(1, false);
+ gl3.marginWidth = gl3.marginHeight = 0;
+ joinTableGroup.setLayout(gl3);
+
+ return group;
+ }
+
+ @Override
+ protected void addListeners()
+ {
+ super.addListeners();
+ mappedByRadio.addSelectionListener(new SelectionAdapter()
+ {
+ @Override
+ public void widgetSelected(SelectionEvent e)
+ {
+ handleJoinPropsChange();
+ }
+ });
+ if (!isJpa1_0Project())
+ {
+ joinColumnRadio.addSelectionListener(new SelectionAdapter()
+ {
+ @Override
+ public void widgetSelected(SelectionEvent e)
+ {
+ handleJoinPropsChange();
+ }
+ });
+ }
+ joinTableRadio.addSelectionListener(new SelectionAdapter()
+ {
+ @Override
+ public void widgetSelected(SelectionEvent e)
+ {
+ handleJoinPropsChange();
+ }
+ });
+
+ mappedByText.addModifyListener(new ModifyListener()
+ {
+ public void modifyText(ModifyEvent e)
+ {
+ handleMappedByChange(mappedByText);
+ }
+ });
+ mappedByBrowseBtn.addSelectionListener(new SelectionAdapter()
+ {
+ @Override
+ public void widgetSelected(SelectionEvent e)
+ {
+ chooseMappedBy();
+ }
+ });
+
+ joinTableText.addModifyListener(new ModifyListener()
+ {
+ public void modifyText(ModifyEvent e)
+ {
+ handleJoinTableChange(joinTableText);
+ }
+ });
+ joinTableBtn.addSelectionListener(new SelectionAdapter()
+ {
+ @Override
+ public void widgetSelected(SelectionEvent e)
+ {
+ chooseJoinTable(joinTableText);
+ }
+ });
+
+ }
+
+ @Override
+ protected void initFields()
+ {
+ String mappedBy = refElem.getMappedBy();
+ if (mappedBy != null || (refElem.getJoinTable() == null && refElem.getJoinColumns().isEmpty()))
+ {
+ mappedByRadio.setSelection(true);
+ mappedByText.setEnabled(true);
+ mappedByBrowseBtn.setEnabled(true);
+ if (mappedBy != null)
+ {
+ mappedByText.setText(mappedBy);
+ }
+ joinTableRadio.setSelection(false);
+ joinTableText.setEnabled(false);
+ joinTableBtn.setEnabled(false);
+ if (!isJpa1_0Project())
+ {
+ joinColumnRadio.setSelection(false);
+ }
+ }
+ else if (refElem.getJoinTable() != null)
+ {
+ mappedByRadio.setSelection(false);
+ mappedByText.setEnabled(false);
+ mappedByBrowseBtn.setEnabled(false);
+ joinTableRadio.setSelection(true);
+ joinTableText.setEnabled(true);
+ joinTableBtn.setEnabled(true);
+ if (refElem.getJoinTable() != null)
+ joinTableText.setText(refElem.getJoinTable().getTableName());
+ if (!isJpa1_0Project())
+ {
+ joinColumnRadio.setSelection(false);
+ }
+ }
+ else if (!isJpa1_0Project() && !refElem.getJoinColumns().isEmpty())
+ {
+ mappedByRadio.setSelection(false);
+ mappedByText.setEnabled(false);
+ mappedByBrowseBtn.setEnabled(false);
+ joinTableRadio.setSelection(false);
+ joinTableText.setEnabled(false);
+ joinTableBtn.setEnabled(false);
+ joinColumnRadio.setSelection(true);
+ }
+
+ }
+
+ @Override
+ protected void refreshJoinProperties()
+ {
+ if (joinColumnsCtl != null)
+ {
+ joinColumnsCtl.dispose();
+ joinColumnsCtl = null;
+ }
+
+ Composite joinProps = getJoinPropsComposite();
+ if (!isJpa1_0Project() && refElem.getJoinStrategy() == JoinStrategy.JOIN_COLUMNS)
+ {
+ Composite parent = joinColumnGroup != null ? joinColumnGroup : joinProps;
+ joinColumnsCtl = joinColEditor.createJoinColumnsControl(parent);
+ if (joinColumnsCtl != null)
+ {
+ GridData gd2 = new GridData(GridData.FILL_HORIZONTAL);
+ gd2.grabExcessHorizontalSpace = true;
+ joinColumnsCtl.setLayoutData(gd2);
+ parent.pack();
+ parent.layout();
+ }
+ }
+ refreshJoinTableGroup();
+
+ joinProps.pack();
+ joinProps.layout();
+ }
+
+ private void refreshJoinTableGroup()
+ {
+ if (joinColumnsCtl2 != null)
+ {
+ joinColumnsCtl2.dispose();
+ joinColumnsCtl2 = null;
+ }
+ if (inverseJoinColumnsCtl != null)
+ {
+ inverseJoinColumnsCtl.dispose();
+ inverseJoinColumnsCtl = null;
+ }
+ if (refElem.getJoinStrategy() != JoinStrategy.JOIN_TABLE)
+ {
+ return;
+ }
+ String joinTableName = getJoinTableName();
+ Table joinTable = null;
+ if (joinTableName != null)
+ joinTable = schema.getTableNamed(joinTableName);
+
+ JoinColumnsAnnotationEditor joinColEditor =
+ new JoinColumnsAnnotationEditor(resourceManager, refElem, false, joinTable, table, this);
+ joinColumnsCtl2 = joinColEditor.createJoinColumnsControl(joinTableGroup);
+ if (joinColumnsCtl2 != null)
+ {
+ GridData gd2 = new GridData(GridData.FILL_HORIZONTAL);
+ gd2.grabExcessHorizontalSpace = true;
+ joinColumnsCtl2.setLayoutData(gd2);
+ joinTableGroup.pack();
+ joinTableGroup.layout();
+ }
+
+ JoinColumnsAnnotationEditor inverseJoinColEditor =
+ new JoinColumnsAnnotationEditor(resourceManager, refElem, true, joinTable, inverseTable, this);
+
+ inverseJoinColumnsCtl = inverseJoinColEditor.createJoinColumnsControl(joinTableGroup);
+ if (inverseJoinColumnsCtl != null)
+ {
+ GridData gd2 = new GridData(GridData.FILL_HORIZONTAL);
+ gd2.grabExcessHorizontalSpace = true;
+ inverseJoinColumnsCtl.setLayoutData(gd2);
+ joinTableGroup.pack();
+ joinTableGroup.layout();
+ }
+
+ }
+
+ private void chooseMappedBy()
+ {
+ if (refElem.getRefEntityClassName() == null)
+ {
+ AssociationAnnotationWizard.displayNoTargetEntityError(refElem.getPropertyName());
+ return;
+ }
+ SelectPropertyDialog dlg = new SelectPropertyDialog(Display.getDefault().getActiveShell(),
+ project, javaClass, refElem, false);
+ if (dlg.open() == Dialog.OK)
+ {
+ mappedByText.setText(dlg.getSelectedProp());
+ }
+ }
+
+ private void handleJoinPropsChange()
+ {
+ if (mappedByRadio.getSelection())
+ {
+ refElem.setJoinStrategy(JoinStrategy.MAPPED_BY);
+ refElem.removeAllJoinColumns();
+ refElem.removeJoinTable();
+ refreshJoinProperties();
+
+ mappedByText.setEnabled(true);
+ mappedByBrowseBtn.setEnabled(true);
+ joinTableRadio.setSelection(false);
+ joinTableText.setText("");
+ joinTableText.setEnabled(false);
+ joinTableBtn.setEnabled(false);
+ if (!isJpa1_0Project())
+ {
+ joinColumnRadio.setSelection(false);
+ }
+ }
+ else if (joinTableRadio.getSelection())
+ {
+ refElem.setJoinStrategy(JoinStrategy.JOIN_TABLE);
+ refElem.removeAllJoinColumns();
+ refElem.removeMappedBy();
+ JoinTableAttributes joinTblAttr = refElem.getJoinTable();
+ if (joinTblAttr == null)
+ {
+ joinTblAttr = new JoinTableAttributes();
+ refElem.setJoinTable(joinTblAttr);
+ }
+ refreshJoinProperties();
+
+ mappedByRadio.setSelection(false);
+ mappedByText.setText("");
+ mappedByText.setEnabled(false);
+ mappedByBrowseBtn.setEnabled(false);
+
+ joinTableText.setEnabled(true);
+ joinTableBtn.setEnabled(true);
+ if (!isJpa1_0Project())
+ {
+ joinColumnRadio.setSelection(false);
+ }
+ }
+ else
+ {
+ refElem.setJoinStrategy(JoinStrategy.JOIN_COLUMNS);
+ refElem.removeJoinTable();
+ refElem.removeMappedBy();
+ refreshJoinProperties();
+
+ mappedByRadio.setSelection(false);
+ mappedByText.setText("");
+ mappedByText.setEnabled(false);
+ mappedByBrowseBtn.setEnabled(false);
+
+ joinTableText.setText("");
+ joinTableText.setEnabled(false);
+ joinTableBtn.setEnabled(false);
+ joinTableRadio.setSelection(false);
+ }
+ }
+
+}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/makepersistent/OneToManyMappingPage.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/makepersistent/OneToManyMappingPage.java
new file mode 100644
index 0000000..68a8634
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/makepersistent/OneToManyMappingPage.java
@@ -0,0 +1,35 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+
+package org.eclipse.jpt.jpa.ui.internal.wizards.makepersistent;
+
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.jface.resource.ResourceManager;
+import org.eclipse.jface.wizard.IWizardPage;
+import org.eclipse.jpt.jpa.annotate.mapping.EntityRefPropertyElem;
+import org.eclipse.jpt.jpa.core.context.persistence.PersistenceUnit;
+
+public class OneToManyMappingPage extends EntityMappingPage
+{
+
+ public OneToManyMappingPage(PersistenceUnit persistenceUnit, ResourceManager resourceManager,IProject project, EntityRefPropertyElem refElem, IWizardPage nextPage)
+ {
+ super(persistenceUnit, resourceManager, project, refElem, nextPage);
+ }
+
+ @Override
+ protected void initFields()
+ {
+ super.initFields();
+ //refreshJoinProperties();
+ }
+
+}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/makepersistent/OneToOneJoinPropsPage.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/makepersistent/OneToOneJoinPropsPage.java
new file mode 100644
index 0000000..04e20d5
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/makepersistent/OneToOneJoinPropsPage.java
@@ -0,0 +1,415 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+
+package org.eclipse.jpt.jpa.ui.internal.wizards.makepersistent;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.jface.resource.ResourceManager;
+import org.eclipse.jpt.jpa.annotate.mapping.EntityRefPropertyElem;
+import org.eclipse.jpt.jpa.annotate.mapping.JoinStrategy;
+import org.eclipse.jpt.jpa.annotate.mapping.JoinTableAttributes;
+import org.eclipse.jpt.jpa.core.context.persistence.PersistenceUnit;
+import org.eclipse.jpt.jpa.db.Schema;
+import org.eclipse.jpt.jpa.db.Table;
+import org.eclipse.jpt.jpa.ui.JptJpaUiImages;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Text;
+
+public class OneToOneJoinPropsPage extends JoinPropertiesPage
+{
+ private Button joinColumnRadio;
+ private Button pkJoinColumnRadio;
+ private Button mappedByRadio;
+ private Text mappedByText;
+ private Button mappedByBrowseBtn;
+ private Button joinTableRadio;
+ private Composite joinColumnGroup;
+ private Composite joinTableGroup;
+ private Text joinTableText;
+ private Button joinTableBtn;
+ private Control joinColumnsCtl;
+ private Control joinColumnsCtl2, inverseJoinColumnsCtl;
+ private JoinColumnsAnnotationEditor joinColEditor;
+
+ public OneToOneJoinPropsPage(PersistenceUnit persistenceUnit, ResourceManager resourceManager, IProject project, String javaClass,
+ Schema schema, Table table, Table inverseTable, EntityRefPropertyElem refElem)
+ {
+ super(persistenceUnit, resourceManager, project, javaClass, schema, table, inverseTable, refElem);
+ joinColEditor =
+ new JoinColumnsAnnotationEditor(resourceManager, refElem, false, table, inverseTable, this);
+ }
+
+ @Override
+ public Composite createJoinProps(Composite parent)
+ {
+ Composite group = new Composite(parent, SWT.NONE);
+ GridLayout gl = new GridLayout(3, false);
+ group.setLayout(gl);
+ GridData gd = new GridData(GridData.FILL_HORIZONTAL);
+ gd.widthHint = 400;
+ gd.heightHint = AssociationAnnotationWizard.JOIN_PROP_GROUP_HEIGHT;
+ group.setLayoutData(gd);
+
+ mappedByRadio = AssociationAnnotationWizard.createButton(group, 1,
+ JptJpaUiMakePersistentMessages.PROPS_MAPPING_PAGE_MAPPEDBY,
+ -1, SWT.RADIO);
+ mappedByText = AssociationAnnotationWizard.createText(group, true, 1, SWT.BORDER);
+ mappedByBrowseBtn = AssociationAnnotationWizard.createImageButton(
+ group, resourceManager.createImage(JptJpaUiImages.LIST_OF_VALUES), 1, SWT.NONE,
+ JptJpaUiMakePersistentMessages.BROWSE);
+ pkJoinColumnRadio = AssociationAnnotationWizard.createButton(group, 3,
+ JptJpaUiMakePersistentMessages.PK_JOIN_COLUMNS_LABEL,
+ -1, SWT.RADIO);
+
+ joinColumnRadio = AssociationAnnotationWizard.createButton(group, 3,
+ JptJpaUiMakePersistentMessages.JOIN_COLUMNS_LABEL,
+ -1, SWT.RADIO);
+
+ // Join columns ctl parent
+ joinColumnGroup = new Composite(group, SWT.NONE);
+ GridData gd2 = new GridData(GridData.FILL_HORIZONTAL);
+ gd2.horizontalSpan = 3;
+ gd2.widthHint = 400;
+ joinColumnGroup.setLayoutData(gd2);
+ GridLayout gl2 = new GridLayout(1, false);
+ gl2.marginWidth = gl2.marginHeight = 0;
+ joinColumnGroup.setLayout(gl2);
+
+ if (!isJpa1_0Project())
+ {
+ joinTableRadio = AssociationAnnotationWizard.createButton(group, 1,
+ JptJpaUiMakePersistentMessages.PROPS_MAPPING_PAGE_JOIN_TABLE,
+ -1, SWT.RADIO);
+ joinTableText = AssociationAnnotationWizard.createText(group, true, 1, SWT.BORDER);
+ Image listImage = resourceManager.createImage(JptJpaUiImages.LIST_OF_VALUES);
+ joinTableBtn = AssociationAnnotationWizard.createImageButton(
+ group, listImage, 1, SWT.NONE,
+ JptJpaUiMakePersistentMessages.BROWSE);
+ // Join Table ctl parent
+ joinTableGroup = new Composite(group, SWT.NONE);
+ GridData gd3 = new GridData(GridData.FILL_HORIZONTAL);
+ gd3.horizontalSpan = 3;
+ gd3.widthHint = 400;
+ gd3.heightHint = 280;
+ joinTableGroup.setLayoutData(gd3);
+ GridLayout gl3 = new GridLayout(1, false);
+ gl3.marginWidth = gl3.marginHeight = 0;
+ joinTableGroup.setLayout(gl3);
+ }
+ return group;
+ }
+
+ @Override
+ protected void initFields()
+ {
+ String mappedBy = refElem.getMappedBy();
+ if (mappedBy != null)
+ {
+ refElem.setJoinStrategy(JoinStrategy.MAPPED_BY);
+ mappedByRadio.setSelection(true);
+ mappedByText.setText(mappedBy);
+ mappedByText.setEnabled(true);
+ mappedByBrowseBtn.setEnabled(true);
+ pkJoinColumnRadio.setSelection(false);
+ joinColumnRadio.setSelection(false);
+ joinColEditor.setEnable(false);
+ if (!isJpa1_0Project())
+ {
+ joinTableRadio.setSelection(false);
+ joinTableText.setEnabled(false);
+ joinTableBtn.setEnabled(false);
+ }
+ }
+ else
+ {
+ refElem.setJoinStrategy(JoinStrategy.JOIN_COLUMNS);
+ mappedByRadio.setSelection(false);
+ mappedByText.setText("");
+ mappedByText.setEnabled(false);
+ mappedByBrowseBtn.setEnabled(false);
+ pkJoinColumnRadio.setSelection(false);
+ joinColumnRadio.setSelection(true);
+ joinColEditor.setEnable(true);
+ if (!isJpa1_0Project())
+ {
+ joinTableRadio.setSelection(false);
+ joinTableText.setEnabled(false);
+ joinTableBtn.setEnabled(false);
+ }
+ }
+ }
+
+ @Override
+ protected void refreshJoinProperties()
+ {
+ if (joinColumnsCtl != null)
+ {
+ joinColumnsCtl.dispose();
+ joinColumnsCtl = null;
+ }
+
+ Composite joinProps = getJoinPropsComposite();
+ if (refElem.getJoinStrategy() == JoinStrategy.JOIN_COLUMNS)
+ {
+ Composite parent = joinColumnGroup != null ? joinColumnGroup : joinProps;
+ joinColumnsCtl = joinColEditor.createJoinColumnsControl(parent);
+ if (joinColumnsCtl != null)
+ {
+ GridData gd2 = new GridData(GridData.FILL_HORIZONTAL);
+ gd2.grabExcessHorizontalSpace = true;
+ joinColumnsCtl.setLayoutData(gd2);
+ parent.pack();
+ parent.layout();
+ }
+ }
+ if (!isJpa1_0Project())
+ {
+ refreshJoinTableGroup();
+ }
+
+ joinProps.pack();
+ joinProps.layout();
+ }
+
+ private void refreshJoinTableGroup()
+ {
+ if (joinColumnsCtl2 != null)
+ {
+ joinColumnsCtl2.dispose();
+ joinColumnsCtl2 = null;
+ }
+ if (inverseJoinColumnsCtl != null)
+ {
+ inverseJoinColumnsCtl.dispose();
+ inverseJoinColumnsCtl = null;
+ }
+ if (refElem.getJoinStrategy() != JoinStrategy.JOIN_TABLE)
+ {
+ return;
+ }
+ String joinTableName = getJoinTableName();
+ Table joinTable = null;
+ if (joinTableName != null)
+ joinTable = schema.getTableNamed(joinTableName);
+
+ JoinColumnsAnnotationEditor joinColEditor =
+ new JoinColumnsAnnotationEditor(resourceManager, refElem, false, joinTable, table, this);
+ joinColumnsCtl2 = joinColEditor.createJoinColumnsControl(joinTableGroup);
+ if (joinColumnsCtl2 != null)
+ {
+ GridData gd2 = new GridData(GridData.FILL_HORIZONTAL);
+ gd2.grabExcessHorizontalSpace = true;
+ joinColumnsCtl2.setLayoutData(gd2);
+ joinTableGroup.pack();
+ joinTableGroup.layout();
+ }
+
+ JoinColumnsAnnotationEditor inverseJoinColEditor =
+ new JoinColumnsAnnotationEditor(resourceManager, refElem, true, joinTable, inverseTable, this);
+
+ inverseJoinColumnsCtl = inverseJoinColEditor.createJoinColumnsControl(joinTableGroup);
+ if (inverseJoinColumnsCtl != null)
+ {
+ GridData gd2 = new GridData(GridData.FILL_HORIZONTAL);
+ gd2.grabExcessHorizontalSpace = true;
+ inverseJoinColumnsCtl.setLayoutData(gd2);
+ joinTableGroup.pack();
+ joinTableGroup.layout();
+ }
+
+ }
+
+ @Override
+ protected void addListeners()
+ {
+ super.addListeners();
+ pkJoinColumnRadio.addSelectionListener(new SelectionAdapter()
+ {
+ @Override
+ public void widgetSelected(SelectionEvent e)
+ {
+ handleJoinPropsChange();
+ }
+ });
+ joinColumnRadio.addSelectionListener(new SelectionAdapter()
+ {
+ @Override
+ public void widgetSelected(SelectionEvent e)
+ {
+ handleJoinPropsChange();
+ }
+ });
+
+ if (!isJpa1_0Project())
+ {
+ joinTableRadio.addSelectionListener(new SelectionAdapter()
+ {
+ @Override
+ public void widgetSelected(SelectionEvent e)
+ {
+ handleJoinPropsChange();
+ }
+ });
+ joinTableText.addModifyListener(new ModifyListener()
+ {
+ public void modifyText(ModifyEvent e)
+ {
+ handleJoinTableChange(joinTableText);
+ }
+ });
+ joinTableBtn.addSelectionListener(new SelectionAdapter()
+ {
+ @Override
+ public void widgetSelected(SelectionEvent e)
+ {
+ chooseJoinTable(joinTableText);
+ }
+ });
+
+ }
+
+ mappedByText.addModifyListener(new ModifyListener()
+ {
+ public void modifyText(ModifyEvent e)
+ {
+ handleMappedByChange(mappedByText);
+ }
+ });
+ mappedByBrowseBtn.addSelectionListener(new SelectionAdapter()
+ {
+ @Override
+ public void widgetSelected(SelectionEvent e)
+ {
+ chooseMappedBy(mappedByText);
+ }
+ });
+
+ }
+
+ private void handleJoinPropsChange()
+ {
+ if (mappedByRadio.getSelection())
+ {
+ refElem.setJoinStrategy(JoinStrategy.MAPPED_BY);
+ refElem.removeAllJoinColumns();
+ refElem.removeJoinTable();
+ refElem.removeAllPKJoinColumns();
+ refreshJoinProperties();
+
+ mappedByText.setEnabled(true);
+ mappedByBrowseBtn.setEnabled(true);
+ pkJoinColumnRadio.setSelection(false);
+ joinColumnRadio.setSelection(false);
+ if (!isJpa1_0Project())
+ {
+ joinTableRadio.setSelection(false);
+ joinTableText.setText("");
+ joinTableText.setEnabled(false);
+ joinTableBtn.setEnabled(false);
+ }
+ }
+ else if (pkJoinColumnRadio.getSelection())
+ {
+ refElem.setJoinStrategy(JoinStrategy.PRIMARY_KEY_JOIN_COLUMNS);
+ refElem.removeMappedBy();
+ refElem.removeAllJoinColumns();
+ refElem.removeJoinTable();
+ refreshJoinProperties();
+
+ mappedByRadio.setSelection(false);
+ mappedByText.setText("");
+ mappedByText.setEnabled(false);
+ mappedByBrowseBtn.setEnabled(false);
+
+ joinColumnRadio.setSelection(false);
+ if (!isJpa1_0Project())
+ {
+ joinTableRadio.setSelection(false);
+ joinTableText.setText("");
+ joinTableText.setEnabled(false);
+ joinTableBtn.setEnabled(false);
+ }
+ }
+ else if (joinColumnRadio.getSelection())
+ {
+ refElem.setJoinStrategy(JoinStrategy.JOIN_COLUMNS);
+ refElem.removeMappedBy();
+ refElem.removeAllPKJoinColumns();
+ refElem.removeJoinTable();
+ refreshJoinProperties();
+
+ mappedByRadio.setSelection(false);
+ mappedByText.setText("");
+ mappedByText.setEnabled(false);
+ mappedByBrowseBtn.setEnabled(false);
+
+ pkJoinColumnRadio.setSelection(false);
+ if (!isJpa1_0Project())
+ {
+ joinTableRadio.setSelection(false);
+ joinTableText.setText("");
+ joinTableText.setEnabled(false);
+ joinTableBtn.setEnabled(false);
+ }
+ }
+ else if (!isJpa1_0Project() && joinTableRadio.getSelection())
+ {
+ refElem.setJoinStrategy(JoinStrategy.JOIN_TABLE);
+ refElem.removeAllJoinColumns();
+ refElem.removeMappedBy();
+ refElem.removeAllPKJoinColumns();
+ JoinTableAttributes joinTblAttr = refElem.getJoinTable();
+ if (joinTblAttr == null)
+ {
+ joinTblAttr = new JoinTableAttributes();
+ refElem.setJoinTable(joinTblAttr);
+ }
+ refreshJoinProperties();
+
+ mappedByRadio.setSelection(false);
+ mappedByText.setText("");
+ mappedByText.setEnabled(false);
+ mappedByBrowseBtn.setEnabled(false);
+
+ joinTableText.setEnabled(true);
+ joinTableBtn.setEnabled(true);
+ joinColumnRadio.setSelection(false);
+ }
+ else
+ {
+ refElem.setJoinStrategy(JoinStrategy.JOIN_COLUMNS);
+ refElem.removeJoinTable();
+ refElem.removeMappedBy();
+ refreshJoinProperties();
+
+ mappedByRadio.setSelection(false);
+ mappedByText.setText("");
+ mappedByText.setEnabled(false);
+ mappedByBrowseBtn.setEnabled(false);
+
+ joinTableText.setText("");
+ joinTableText.setEnabled(false);
+ joinTableBtn.setEnabled(false);
+ joinTableRadio.setSelection(false);
+ }
+
+ }
+
+}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/makepersistent/OneToOneMappingPage.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/makepersistent/OneToOneMappingPage.java
new file mode 100644
index 0000000..e782e47
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/makepersistent/OneToOneMappingPage.java
@@ -0,0 +1,36 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+
+package org.eclipse.jpt.jpa.ui.internal.wizards.makepersistent;
+
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.jface.resource.ResourceManager;
+import org.eclipse.jface.wizard.IWizardPage;
+import org.eclipse.jpt.jpa.annotate.mapping.EntityRefPropertyElem;
+import org.eclipse.jpt.jpa.core.context.persistence.PersistenceUnit;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Group;
+
+public class OneToOneMappingPage extends EntityMappingPage
+{
+
+ public OneToOneMappingPage(PersistenceUnit persistenceUnit, ResourceManager resourceManager, IProject project, EntityRefPropertyElem refElem, IWizardPage nextPage)
+ {
+ super(persistenceUnit, resourceManager, project, refElem, nextPage);
+ }
+
+ @Override
+ protected Group createTargetEntityGroup(Composite parent)
+ {
+ return null;
+ }
+
+}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/makepersistent/OrmUiUtil.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/makepersistent/OrmUiUtil.java
new file mode 100644
index 0000000..cf9b339
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/makepersistent/OrmUiUtil.java
@@ -0,0 +1,69 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+
+package org.eclipse.jpt.jpa.ui.internal.wizards.makepersistent;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.jdt.core.IJavaElement;
+import org.eclipse.jdt.core.IType;
+import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jdt.core.search.IJavaSearchScope;
+import org.eclipse.jdt.core.search.SearchEngine;
+import org.eclipse.jdt.internal.ui.dialogs.FilteredTypesSelectionDialog;
+import org.eclipse.jdt.ui.IJavaElementSearchConstants;
+import org.eclipse.jdt.ui.JavaUI;
+import org.eclipse.jface.dialogs.ProgressMonitorDialog;
+import org.eclipse.jface.window.Window;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Shell;
+
+public class OrmUiUtil
+{
+ /**
+ * Launch the class chooser to allow user to pick a java class
+ * @return the class user picks to null of the class chooser dlg was canceled
+ */
+ public static String selectJavaClass(IProject project)
+ {
+ String javaClass = null;
+
+ Display display = Display.getDefault();
+ Shell shell = display.getActiveShell();
+ IJavaSearchScope sc
+ = SearchEngine.createJavaSearchScope( new IJavaElement[]
+ {
+ JavaCore.create(project)
+ } );
+
+ try
+ {
+ FilteredTypesSelectionDialog dlg = (FilteredTypesSelectionDialog)JavaUI.createTypeDialog( shell, new ProgressMonitorDialog( shell ), sc, IJavaElementSearchConstants.CONSIDER_CLASSES, false );
+ dlg.setTitle(JptJpaUiMakePersistentMessages.CHOOSE_TYPE);
+ dlg.setBlockOnOpen( true );
+
+ if ( dlg.open() == Window.OK )
+ {
+ Object[] sels = dlg.getResult();
+ if (sels == null)
+ return null;
+ assert( sels[0] instanceof IType );
+ IType type = (IType)sels[0];
+ javaClass = type.getFullyQualifiedName('.');
+ }
+ }
+ catch ( JavaModelException jme )
+ {
+ // todo -- notify user
+ }
+ return javaClass;
+ }
+
+}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/makepersistent/PropsMappingPage.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/makepersistent/PropsMappingPage.java
new file mode 100644
index 0000000..f2635d8
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/makepersistent/PropsMappingPage.java
@@ -0,0 +1,612 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.jpa.ui.internal.wizards.makepersistent;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.jdt.ui.JavaElementLabelProvider;
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.resource.ResourceManager;
+import org.eclipse.jface.viewers.ILabelProviderListener;
+import org.eclipse.jface.viewers.ITableLabelProvider;
+import org.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.jface.viewers.TreeSelection;
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jface.wizard.WizardDialog;
+import org.eclipse.jface.wizard.WizardPage;
+import org.eclipse.jpt.common.ui.JptCommonUiImages;
+import org.eclipse.jpt.jpa.annotate.mapping.AnnotationAttributeNames;
+import org.eclipse.jpt.jpa.annotate.mapping.BasicEntityPropertyElem;
+import org.eclipse.jpt.jpa.annotate.mapping.ColumnAttributes;
+import org.eclipse.jpt.jpa.annotate.mapping.EntityPropertyElem;
+import org.eclipse.jpt.jpa.annotate.mapping.EntityRefPropertyElem;
+import org.eclipse.jpt.jpa.annotate.mapping.IdEntityPropertyElement;
+import org.eclipse.jpt.jpa.annotate.mapping.JavaMapper;
+import org.eclipse.jpt.jpa.annotate.mapping.JoinStrategy;
+import org.eclipse.jpt.jpa.annotate.util.AnnotateMappingUtil;
+import org.eclipse.jpt.jpa.core.JpaProject;
+import org.eclipse.jpt.jpa.core.MappingKeys;
+import org.eclipse.jpt.jpa.core.context.persistence.PersistenceUnit;
+import org.eclipse.jpt.jpa.core.resource.orm.JPA;
+import org.eclipse.jpt.jpa.db.Schema;
+import org.eclipse.jpt.jpa.ui.JptJpaUiImages;
+import org.eclipse.jpt.jpa.ui.internal.wizards.makepersistent.JpaMakePersistentWizard.TypeComparator;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Tree;
+import org.eclipse.swt.widgets.TreeColumn;
+import org.eclipse.ui.ISharedImages;
+import org.eclipse.ui.PlatformUI;
+
+public class PropsMappingPage extends WizardPage
+{
+ /* CU private */ final JpaProject jpaProject;
+ /* CU private */ final ResourceManager resourceManager;
+ private JavaClassMapping[] javaClassMappings;
+ private ClassMappingPage classMappingPage;
+
+ private TreeViewer mappingTreeViewer;
+ private Button editBtn;
+ private Button removeBtn;
+
+ private static final int JAVA_CLASS_COLUMN_WIDTH = 130;
+ private static final int PROPERTY_NAME_COLUMN_WIDTH = 110;
+ private static final int PROPERTY_TYPE_COLUMN_WIDTH = 130;
+ private static final int PROPERTY_DATABASE_COLUMN_WIDTH = 140;
+ private static final int PROPERTY_COLUMN_TYPE_WIDTH = 100;
+ private static final int MAPPING_TABLE_HEIGHT = 80;
+ private static final int JAVA_CLASS_COLUMN_INDEX = 0;
+ private static final int NAME_COLUMN_INDEX = 1;
+ private static final int TYPE_COLUMN_INDEX = 2;
+ private static final int DATABASE_COLUMN_INDEX = 3;
+ private static final int COLUMN_TYPE_INDEX = 4;
+
+
+ public PropsMappingPage(JpaProject proj, JavaClassMapping[] javaClassMappings,
+ ResourceManager resourceManager, ClassMappingPage classMappingPage)
+ {
+ super("Class Mapping Properties"); //$NON-NLS-1$
+ this.resourceManager = resourceManager;
+ this.jpaProject = proj;
+ this.javaClassMappings = javaClassMappings;
+ this.classMappingPage = classMappingPage;
+ setTitle(JptJpaUiMakePersistentMessages.PROPS_MAPPING_PAGE_TITLE);
+ setMessage(JptJpaUiMakePersistentMessages.PROPS_MAPPING_PAGE_DESC);
+
+ this.classMappingPage.addListener(new ClassMappingPage.Listener()
+ {
+ public void classMappingChanged(JavaClassMapping javaClassMapping)
+ {
+ handleClassMappingChange(javaClassMapping);
+ }
+ });
+ }
+
+ public void createControl(Composite parent)
+ {
+ initializeDialogUnits(parent);
+
+ Composite composite = new Composite(parent, SWT.NULL);
+ composite.setLayout(new GridLayout(2, false));
+ Label label = new Label(composite, SWT.NONE);
+ label.setText(JptJpaUiMakePersistentMessages.PROPS_MAPPING_PAGE_LABEL);
+ GridData gd = new GridData();
+ gd.horizontalSpan = 2;
+ label.setLayoutData(gd);
+
+ createMappingTable(composite);
+ createMappingButtons(composite);
+ updateMappingButtons();
+ setControl(composite);
+ }
+
+ private void createMappingTable(Composite parent)
+ {
+ Tree mappingTree = new Tree(parent, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.SINGLE);
+ mappingTree.setHeaderVisible(true);
+ mappingTree.setLinesVisible(true);
+ this.mappingTreeViewer = new TreeViewer(mappingTree);
+
+ TreeColumn column1 = new TreeColumn(mappingTree, SWT.LEFT);
+ column1.setAlignment(SWT.LEFT);
+ column1.setText(JptJpaUiMakePersistentMessages.PROPS_MAPPING_PAGE_JAVA_CLASS_LABEL);
+ column1.setWidth(JAVA_CLASS_COLUMN_WIDTH);
+
+ TreeColumn column2 = new TreeColumn(mappingTree, SWT.RIGHT);
+ column2.setAlignment(SWT.LEFT);
+ column2.setText(JptJpaUiMakePersistentMessages.PROPS_MAPPING_PAGE_PROPERTY_NAME_LABEL);
+ column2.setWidth(PROPERTY_NAME_COLUMN_WIDTH);
+
+ TreeColumn column3 = new TreeColumn(mappingTree, SWT.RIGHT);
+ column3.setAlignment(SWT.LEFT);
+ column3.setText(JptJpaUiMakePersistentMessages.PROPS_MAPPING_PAGE_PROPERTY_TYPE_LABEL);
+ column3.setWidth(PROPERTY_TYPE_COLUMN_WIDTH);
+
+ TreeColumn column4 = new TreeColumn(mappingTree, SWT.RIGHT);
+ column4.setAlignment(SWT.LEFT);
+ column4.setText(JptJpaUiMakePersistentMessages.PROPS_MAPPING_PAGE_DATABASE_COLUMN);
+ column4.setWidth(PROPERTY_DATABASE_COLUMN_WIDTH);
+
+ TreeColumn column5 = new TreeColumn(mappingTree, SWT.RIGHT);
+ column5.setAlignment(SWT.LEFT);
+ column5.setText(JptJpaUiMakePersistentMessages.PROPS_MAPPING_PAGE_COLUMN_TYPE);
+ column5.setWidth(PROPERTY_COLUMN_TYPE_WIDTH);
+
+ GridData gd = new GridData(GridData.FILL_BOTH);
+ gd.widthHint = JAVA_CLASS_COLUMN_WIDTH + PROPERTY_NAME_COLUMN_WIDTH
+ + PROPERTY_TYPE_COLUMN_WIDTH + PROPERTY_DATABASE_COLUMN_WIDTH
+ + PROPERTY_COLUMN_TYPE_WIDTH;
+ gd.heightHint = MAPPING_TABLE_HEIGHT;
+ mappingTree.setLayoutData(gd);
+
+ this.mappingTreeViewer.setContentProvider(new PropertiesMappingContentProvider());
+ this.mappingTreeViewer.setComparator(new TypeComparator());
+ this.mappingTreeViewer.setLabelProvider(new PropertiesMappingLabelProvider());
+ this.mappingTreeViewer.setInput(this.javaClassMappings);
+ this.mappingTreeViewer.expandAll();
+
+ mappingTree.addSelectionListener(new SelectionAdapter()
+ {
+ @Override
+ public void widgetSelected(SelectionEvent e)
+ {
+ updateMappingButtons();
+ }
+ });
+ }
+
+ private void createMappingButtons(Composite parent)
+ {
+ Composite buttons = new Composite(parent, SWT.NULL);
+ GridLayout gridLayout = new GridLayout(1, false);
+ gridLayout.marginHeight = 0;
+ buttons.setLayout(gridLayout);
+ buttons.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING));
+
+ editBtn = new Button(buttons, SWT.NULL);
+ editBtn.setImage(this.resourceManager.createImage(JptCommonUiImages.EDIT_BUTTON));
+ editBtn.setToolTipText(JptJpaUiMakePersistentMessages.PROPS_MAPPING_PAGE_EDIT);
+ editBtn.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));
+ editBtn.addSelectionListener(new SelectionAdapter()
+ {
+ @Override
+ public void widgetSelected(SelectionEvent e)
+ {
+ editMapping();
+ }
+ });
+
+ removeBtn = new Button(buttons, SWT.NULL);
+ removeBtn.setImage(PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_TOOL_DELETE));
+ removeBtn.setToolTipText(JptJpaUiMakePersistentMessages.PROPS_MAPPING_PAGE_REMOVE);
+ removeBtn.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));
+
+ removeBtn.addSelectionListener(new SelectionAdapter()
+ {
+ @Override
+ public void widgetSelected(SelectionEvent e)
+ {
+ removeMapping();
+ }
+ });
+ }
+
+ private void updateMappingButtons()
+ {
+ TreeSelection sel = (TreeSelection)this.mappingTreeViewer.getSelection();
+ if (sel.getFirstElement() instanceof EntityPropertyElem)
+ {
+ editBtn.setEnabled(true);
+ removeBtn.setEnabled(true);
+ }
+ else
+ {
+ editBtn.setEnabled(false);
+ removeBtn.setEnabled(false);
+ }
+ }
+
+ private void editMapping()
+ {
+ Object selectedObj = ((TreeSelection)this.mappingTreeViewer.getSelection()).getFirstElement();
+ EntityPropertyElem entityProp = (EntityPropertyElem)selectedObj;
+ Schema schema = this.classMappingPage.getSchema();
+ JavaClassMapping classMapping = getClassMapping(entityProp.getClassName());
+ int index = classMapping != null ? classMapping.getPropertyMappings().indexOf(entityProp) : -1;
+
+ if (entityProp.getTagName().equals(JPA.ID))
+ {
+ assert entityProp instanceof IdEntityPropertyElement;
+ IdEntityPropertyElement idEntityProp = (IdEntityPropertyElement)entityProp;
+ IdEntityPropertyElement idEntityPropCopy = new IdEntityPropertyElement(idEntityProp);
+ IdAnnotationDialog dlg = new IdAnnotationDialog(
+ Display.getDefault().getActiveShell(), this.resourceManager,
+ idEntityProp.getDBTable(), idEntityPropCopy);
+ if (dlg.open() == Dialog.OK && index != -1)
+ {
+ classMapping.getPropertyMappings().remove(index);
+ idEntityPropCopy.setUnmapped(false);
+ classMapping.getPropertyMappings().add(index, idEntityPropCopy);
+ this.mappingTreeViewer.update(idEntityPropCopy, null);
+ }
+ }
+ else if (entityProp.getTagName().equals(JPA.BASIC))
+ {
+ assert entityProp instanceof BasicEntityPropertyElem;
+ BasicEntityPropertyElem basicEntityProp = (BasicEntityPropertyElem)entityProp;
+ BasicEntityPropertyElem basicEntityPropCopy = new BasicEntityPropertyElem(basicEntityProp);
+
+ BasicAnnotationDialog dlg = new BasicAnnotationDialog(
+ Display.getDefault().getActiveShell(), this.resourceManager,
+ this.jpaProject.getProject(), entityProp.getDBTable(), basicEntityPropCopy);
+ if (dlg.open() == Dialog.OK && index != -1)
+ {
+ classMapping.getPropertyMappings().remove(index);
+ basicEntityPropCopy.setUnmapped(false);
+ classMapping.getPropertyMappings().add(index, basicEntityPropCopy);
+ this.mappingTreeViewer.update(basicEntityPropCopy, null);
+ }
+ }
+ else if (entityProp.getTagName().equals(JPA.ONE_TO_MANY) ||
+ entityProp.getTagName().equals(JPA.MANY_TO_MANY) ||
+ entityProp.getTagName().equals(JPA.MANY_TO_ONE) ||
+ entityProp.getTagName().equals(JPA.ONE_TO_ONE))
+ {
+ assert entityProp instanceof EntityRefPropertyElem;
+ EntityRefPropertyElem refElem = (EntityRefPropertyElem)entityProp;
+ EntityRefPropertyElem refElemCopy = new EntityRefPropertyElem(refElem);
+ PersistenceUnit persistenceUnit = ((JpaMakePersistentWizard)this.getWizard()).getPersistenceUnit();
+ AssociationAnnotationWizard wizard = new AssociationAnnotationWizard(persistenceUnit, this.resourceManager,
+ this.jpaProject.getProject(), classMapping.getFullyQualifiedName(), schema,
+ entityProp.getDBTable(), refElemCopy);
+ WizardDialog dialog = new WizardDialog(Display.getCurrent().getActiveShell(), wizard);
+ dialog.create();
+
+ if (dialog.open() == Dialog.OK && index != -1)
+ {
+ classMapping.getPropertyMappings().remove(index);
+ refElemCopy.setUnmapped(false);
+ classMapping.getPropertyMappings().add(index, refElemCopy);
+ this.mappingTreeViewer.update(refElemCopy, null);
+ }
+ }
+ }
+
+ private void removeMapping()
+ {
+ Object selectedObj = ((TreeSelection)this.mappingTreeViewer.getSelection()).getFirstElement();
+ EntityPropertyElem entityProp = (EntityPropertyElem)selectedObj;
+ entityProp.setUnmapped(true);
+ this.mappingTreeViewer.update(entityProp, null);
+ }
+
+ private void handleClassMappingChange(JavaClassMapping javaClassMapping)
+ {
+ javaClassMapping.clearPropertyMappings();
+ Schema schema = this.classMappingPage.getSchema();
+ if (schema != null && javaClassMapping.getDBTable() != null)
+ {
+ org.eclipse.jpt.jpa.db.Table dbTable = schema.getTableNamed(javaClassMapping.getDBTable());
+ JavaMapper javaMapper = new JavaMapper(this.jpaProject.getProject(), javaClassMapping.getFullyQualifiedName(),
+ dbTable, javaClassMapping.getPrimaryKeyProperty());
+ javaMapper.map();
+ javaClassMapping.setPropertyMappings(javaMapper.getEntityProperties());
+ }
+ if (this.mappingTreeViewer != null)
+ {
+ this.mappingTreeViewer.getTree().removeAll();
+ this.mappingTreeViewer.refresh(true);
+ this.mappingTreeViewer.expandAll();
+ }
+ }
+
+ private String getDBColumnDisplayStr(EntityPropertyElem propElem)
+ {
+ String colText = null;
+
+ String tagName = propElem.getTagName();
+ if (tagName.equals(JPA.ID) || tagName.equals(JPA.BASIC))
+ {
+ ColumnAttributes colAttrs = propElem.getColumnAnnotationAttrs();
+ if (colAttrs != null)
+ {
+ colText = colAttrs.getAnnotationAttribute(AnnotationAttributeNames.NAME).attrValue;
+ }
+// else
+// {
+// // no mapped db column: just display property name
+// colText = propElem.getPropertyName();
+// }
+ }
+ else if (propElem instanceof EntityRefPropertyElem)
+ {
+ EntityRefPropertyElem refElem = (EntityRefPropertyElem)propElem;
+ if (refElem.getMappedBy() != null)
+ colText = JptJpaUiMakePersistentMessages.MAPPED_BY_DESC
+ + refElem.getMappedBy();
+ else if (refElem.getJoinTable() != null &&
+ refElem.getJoinTable().getTableName() != null)
+ {
+ colText = refElem.getJoinTable().getTableName() + " "
+ + JptJpaUiMakePersistentMessages.JOIN_TABLE_DESC;
+ }
+ else if (refElem.getJoinColumns().size() > 0)
+ {
+ ColumnAttributes joinCol = refElem.getJoinColumns().get(0);
+ String colName = joinCol.getName();
+ String refColName = joinCol.getReferencedColumnName();
+ if (colName != null && refColName != null)
+ colText = String.format(JptJpaUiMakePersistentMessages.PROPS_MAPPING_PAGE_JOIN_AND,
+ colName, refColName);
+ else if (colName != null)
+ colText = colName;
+ }
+ else if (refElem.getJoinStrategy() == JoinStrategy.PRIMARY_KEY_JOIN_COLUMNS)
+ {
+ colText = JptJpaUiMakePersistentMessages.PK_JOIN_COLUMN_DESC;
+ }
+ }
+ return colText;
+ }
+
+ private JavaClassMapping getClassMapping(String fqClassName)
+ {
+ for (JavaClassMapping classMapping : this.javaClassMappings)
+ {
+ if (classMapping.getFullyQualifiedName().equals(fqClassName))
+ {
+ return classMapping;
+ }
+ }
+ return null;
+ }
+
+ private class PropertiesMappingContentProvider implements ITreeContentProvider
+ {
+ public Object[] getElements(Object inputElement)
+ {
+ JavaClassMapping[] javaClassMappings = (JavaClassMapping[])inputElement;
+ List<JavaClassMapping> entityMappings = new ArrayList<JavaClassMapping>();
+ for (JavaClassMapping javaClassMapping : javaClassMappings)
+ {
+ if (javaClassMapping.getMappingKey().equals(MappingKeys.ENTITY_TYPE_MAPPING_KEY))
+ {
+ entityMappings.add(javaClassMapping);
+ }
+ }
+ return entityMappings.toArray();
+ }
+
+ public void dispose()
+ {
+ }
+
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput)
+ {
+ }
+
+ public Object[] getChildren(Object parentElement)
+ {
+ if (parentElement instanceof JavaClassMapping)
+ {
+ return ((JavaClassMapping)parentElement).getPropertyMappings().toArray();
+ }
+ return new Object[0];
+ }
+
+ public Object getParent(Object element)
+ {
+ return null;
+ }
+
+ public boolean hasChildren(Object element)
+ {
+ if (element instanceof JavaClassMapping)
+ return true;
+ return false;
+ }
+ }
+
+ private class PropertiesMappingLabelProvider implements ITableLabelProvider
+ {
+ private final JavaElementLabelProvider javaElementLabelProvider =
+ new JavaElementLabelProvider(JavaElementLabelProvider.SHOW_POST_QUALIFIED
+ | JavaElementLabelProvider.SHOW_SMALL_ICONS
+ | JavaElementLabelProvider.SHOW_OVERLAY_ICONS);
+
+ public Image getColumnImage(Object element, int columnIndex)
+ {
+ switch (columnIndex)
+ {
+ case JAVA_CLASS_COLUMN_INDEX:
+ {
+ if (element instanceof JavaClassMapping)
+ {
+ return this.javaElementLabelProvider.getImage(((JavaClassMapping)element).getJDTType());
+ }
+ break;
+ }
+ case NAME_COLUMN_INDEX:
+ {
+ if (element instanceof EntityPropertyElem)
+ {
+ EntityPropertyElem propElem = (EntityPropertyElem)element;
+ Image image = null;
+ if (propElem.getTagName().equals(JPA.ID))
+ image = resourceManager.createImage(JptJpaUiImages.ID);
+ else if (propElem.getTagName().equals(JPA.BASIC))
+ image = resourceManager.createImage(JptJpaUiImages.BASIC);
+ else if (propElem.getTagName().equals(JPA.ONE_TO_MANY))
+ image = resourceManager.createImage(JptJpaUiImages.ONE_TO_MANY);
+ else if (propElem.getTagName().equals(JPA.MANY_TO_MANY))
+ image = resourceManager.createImage(JptJpaUiImages.MANY_TO_MANY);
+ else if (propElem.getTagName().equals(JPA.MANY_TO_ONE))
+ image = resourceManager.createImage(JptJpaUiImages.MANY_TO_ONE);
+ else if (propElem.getTagName().equals(JPA.ONE_TO_ONE))
+ image = resourceManager.createImage(JptJpaUiImages.ONE_TO_ONE);
+
+ return image;
+ }
+ break;
+ }
+ case TYPE_COLUMN_INDEX:
+ {
+ if (element instanceof EntityRefPropertyElem)
+ {
+ EntityRefPropertyElem refElem = (EntityRefPropertyElem)element;
+ if (refElem.isEntityCollection() && refElem.getRefEntityClassName() == null)
+ {
+ return resourceManager.createImage(JptCommonUiImages.WARNING);
+ }
+ }
+ break;
+ }
+ case DATABASE_COLUMN_INDEX:
+ {
+ if (element instanceof EntityPropertyElem)
+ {
+ EntityPropertyElem propElem = (EntityPropertyElem)element;
+ if (!propElem.isUnmapped())
+ {
+ String colDispStr = getDBColumnDisplayStr(propElem);
+ if (colDispStr == null)
+ return resourceManager.createImage(JptCommonUiImages.WARNING);
+ }
+ }
+ break;
+ }
+
+ }
+ return null;
+ }
+
+ public String getColumnText(Object element, int columnIndex)
+ {
+ switch (columnIndex)
+ {
+ case JAVA_CLASS_COLUMN_INDEX:
+ {
+ if (element instanceof JavaClassMapping)
+ {
+ return ((JavaClassMapping)element).getJDTType().getElementName();
+ }
+ break;
+ }
+ case NAME_COLUMN_INDEX:
+ {
+ if (element instanceof EntityPropertyElem)
+ {
+ EntityPropertyElem propElem = (EntityPropertyElem)element;
+ return propElem.getPropertyName();
+ }
+ break;
+ }
+ case TYPE_COLUMN_INDEX:
+ {
+ if (element instanceof EntityPropertyElem)
+ {
+ EntityPropertyElem propElem = (EntityPropertyElem)element;
+ String label = AnnotateMappingUtil.getClassName(propElem.getPropertyType());
+ if (propElem instanceof EntityRefPropertyElem)
+ {
+ EntityRefPropertyElem refElem = (EntityRefPropertyElem)propElem;
+ if (refElem.isEntityCollection())
+ {
+ if (refElem.getRefEntityClassName() == null)
+ {
+ label += '<' + JptJpaUiMakePersistentMessages.PROPS_MAPPING_PAGE_UNSPECIFIED + '>';
+ }
+ }
+ }
+ return label;
+ }
+ break;
+ }
+ case DATABASE_COLUMN_INDEX:
+ {
+ if (element instanceof EntityPropertyElem)
+ {
+ String colText = null;
+ EntityPropertyElem propElem = (EntityPropertyElem)element;
+ if (propElem.isUnmapped())
+ {
+ colText = "-";
+ }
+ else
+ {
+ colText = getDBColumnDisplayStr(propElem);
+ if (colText == null)
+ {
+ colText = JptJpaUiMakePersistentMessages.PROPS_MAPPING_PAGE_UNSPECIFIED;
+ }
+ }
+ return colText;
+ }
+ break;
+ }
+ case COLUMN_TYPE_INDEX:
+ {
+ if (element instanceof EntityPropertyElem)
+ {
+ EntityPropertyElem propElem = (EntityPropertyElem)element;
+ String colText = null;
+ if (propElem.isUnmapped())
+ {
+ colText = "-";
+ }
+ else
+ {
+ ColumnAttributes colAttrs = propElem.getColumnAnnotationAttrs();
+ if (colAttrs != null)
+ {
+ String colName = colAttrs.getAnnotationAttribute(AnnotationAttributeNames.NAME).attrValue;
+ if (colName != null)
+ {
+ Schema schema = classMappingPage.getSchema();
+ if (schema != null && propElem.getDBColumn() != null)
+ {
+ colText = propElem.getDBColumn().getDataTypeName();
+ }
+ }
+ }
+ else
+ colText = JptJpaUiMakePersistentMessages.PROPS_MAPPING_PAGE_COLUMN_TYPE_NA;
+ }
+ return colText;
+ }
+ break;
+
+ }
+
+ }
+ return null;
+ }
+ public void addListener(ILabelProviderListener listener){}
+
+ public void dispose(){}
+
+ public boolean isLabelProperty(Object element, String property)
+ {
+ return false;
+ }
+
+ public void removeListener(ILabelProviderListener listener){}
+ }
+}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/makepersistent/SelectCascadeDialog.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/makepersistent/SelectCascadeDialog.java
new file mode 100644
index 0000000..3adb014
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/makepersistent/SelectCascadeDialog.java
@@ -0,0 +1,159 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+
+package org.eclipse.jpt.jpa.ui.internal.wizards.makepersistent;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jpt.jpa.core.resource.orm.JPA;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Shell;
+
+public class SelectCascadeDialog extends Dialog
+{
+ private Button allCheckbox;
+ private Button persistCheckbox;
+ private Button mergeCheckbox;
+ private Button removeCheckbox;
+ private Button refreshCheckbox;
+ private List<String> cascadeValues;
+
+ public SelectCascadeDialog(Shell shell, List<String> initialValues)
+ {
+ super(shell);
+ cascadeValues = new ArrayList<String>();
+ cascadeValues.addAll(initialValues);
+ }
+
+ @Override
+ protected void configureShell(Shell newShell)
+ {
+ newShell.setText(JptJpaUiMakePersistentMessages.SELECT_CASCADE_DLG_TITLE);
+ super.configureShell(newShell);
+ }
+
+ @Override
+ protected Control createDialogArea(Composite parent)
+ {
+ Composite composite = (Composite)super.createDialogArea(parent);
+ GridData gd = new GridData(GridData.FILL_BOTH);
+ gd.widthHint = 250;
+ gd.heightHint = 200;
+ composite.setLayoutData(gd);
+ allCheckbox = new Button(composite, SWT.CHECK);
+ allCheckbox.setText(JPA.CASCADE_ALL);
+ persistCheckbox = new Button(composite, SWT.CHECK);
+ persistCheckbox.setText(JPA.CASCADE_PERSIST);
+ mergeCheckbox = new Button(composite, SWT.CHECK);
+ mergeCheckbox.setText(JPA.CASCADE_MERGE);
+ removeCheckbox = new Button(composite, SWT.CHECK);
+ removeCheckbox.setText(JPA.CASCADE_REMOVE);
+ refreshCheckbox = new Button(composite, SWT.CHECK);
+ refreshCheckbox.setText(JPA.CASCADE_REFRESH);
+
+
+ SelectionAdapter selectionAdapater = new SelectionAdapter()
+ {
+ @Override
+ public void widgetSelected( SelectionEvent e )
+ {
+ selectOtherCascade();
+ }
+ };
+ SelectionAdapter selectionAdapater2 = new SelectionAdapter()
+ {
+ @Override
+ public void widgetSelected( SelectionEvent e )
+ {
+ selectAllCascade();
+ }
+ };
+ persistCheckbox.addSelectionListener(selectionAdapater);
+ mergeCheckbox.addSelectionListener(selectionAdapater);
+ removeCheckbox.addSelectionListener(selectionAdapater);
+ refreshCheckbox.addSelectionListener(selectionAdapater);
+ allCheckbox.addSelectionListener(selectionAdapater2);
+
+ init();
+ return composite;
+ }
+
+ private void init()
+ {
+ if (cascadeValues.contains(JPA.CASCADE_ALL))
+ allCheckbox.setSelection(true);
+ if (cascadeValues.contains(JPA.CASCADE_PERSIST))
+ persistCheckbox.setSelection(true);
+ if (cascadeValues.contains(JPA.CASCADE_MERGE))
+ mergeCheckbox.setSelection(true);
+ if (cascadeValues.contains(JPA.CASCADE_MERGE))
+ removeCheckbox.setSelection(true);
+ if (cascadeValues.contains(JPA.CASCADE_REFRESH))
+ refreshCheckbox.setSelection(true);
+
+ }
+ @Override
+ protected boolean isResizable()
+ {
+ return true;
+ }
+
+ public List<String> getAllCascades()
+ {
+ return cascadeValues;
+ }
+
+ private void selectAllCascade()
+ {
+ cascadeValues.clear();
+ if (allCheckbox.getSelection())
+ {
+ cascadeValues.add(JPA.CASCADE_ALL);
+ persistCheckbox.setSelection(false);
+ mergeCheckbox.setSelection(false);
+ removeCheckbox.setSelection(false);
+ refreshCheckbox.setSelection(false);
+ }
+ }
+
+ private void selectOtherCascade()
+ {
+ cascadeValues.clear();
+ if (persistCheckbox.getSelection())
+ {
+ cascadeValues.add(JPA.CASCADE_PERSIST);
+ allCheckbox.setSelection(false);
+ }
+ if (mergeCheckbox.getSelection())
+ {
+ cascadeValues.add(JPA.CASCADE_MERGE);
+ allCheckbox.setSelection(false);
+ }
+ if (removeCheckbox.getSelection())
+ {
+ cascadeValues.add(JPA.CASCADE_REMOVE);
+ allCheckbox.setSelection(false);
+ }
+ if (refreshCheckbox.getSelection())
+ {
+ cascadeValues.add(JPA.CASCADE_REFRESH);
+ allCheckbox.setSelection(false);
+ }
+ }
+
+}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/makepersistent/SelectColumnDialog.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/makepersistent/SelectColumnDialog.java
new file mode 100644
index 0000000..166357a
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/makepersistent/SelectColumnDialog.java
@@ -0,0 +1,67 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+
+package org.eclipse.jpt.jpa.ui.internal.wizards.makepersistent;
+
+import java.util.ArrayList;
+
+import org.eclipse.jface.viewers.ILabelProvider;
+import org.eclipse.jface.viewers.ILabelProviderListener;
+import org.eclipse.jpt.jpa.db.Column;
+import org.eclipse.jpt.jpa.db.Table;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.dialogs.ElementListSelectionDialog;
+
+public class SelectColumnDialog extends ElementListSelectionDialog
+{
+ public SelectColumnDialog(Shell shell, Table table, String attributeName)
+ {
+ super(shell, new ILabelProvider()
+ {
+ public Image getImage(Object element)
+ {
+ return null;
+ }
+
+ public String getText(Object element)
+ {
+ return element.toString();
+ }
+ public void addListener(ILabelProviderListener listener) {}
+ public void dispose() {}
+
+ public boolean isLabelProperty(Object element, String property)
+ {
+ return false;
+ }
+
+ public void removeListener(ILabelProviderListener listener) {}
+ });
+ setTitle(JptJpaUiMakePersistentMessages.SELECT_COLUMN_DLG_TITLE);
+ String text = String.format(
+ JptJpaUiMakePersistentMessages.SELECT_COLUMN_DLG_DESC,
+ attributeName);
+ setMessage(text);
+
+ ArrayList<String> columnList = new ArrayList<String>();
+ for( Column column : table.getColumns() )
+ {
+ columnList.add(column.getName());
+ }
+ setElements(columnList.toArray());
+ }
+
+ public String getSelectedColumn()
+ {
+ return (String)this.getFirstResult();
+ }
+
+}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/makepersistent/SelectOrderByDialog.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/makepersistent/SelectOrderByDialog.java
new file mode 100644
index 0000000..70c568d
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/makepersistent/SelectOrderByDialog.java
@@ -0,0 +1,508 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+
+package org.eclipse.jpt.jpa.ui.internal.wizards.makepersistent;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.StringTokenizer;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.jdt.core.Flags;
+import org.eclipse.jdt.core.IField;
+import org.eclipse.jdt.core.IType;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.resource.ResourceManager;
+import org.eclipse.jface.viewers.CellEditor;
+import org.eclipse.jface.viewers.CheckboxTableViewer;
+import org.eclipse.jface.viewers.ColumnWeightData;
+import org.eclipse.jface.viewers.ComboBoxCellEditor;
+import org.eclipse.jface.viewers.ICellModifier;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.IStructuredContentProvider;
+import org.eclipse.jface.viewers.ITableLabelProvider;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jpt.common.ui.JptCommonUiImages;
+import org.eclipse.jpt.common.ui.internal.util.SWTUtil;
+import org.eclipse.jpt.common.ui.internal.util.TableLayoutComposite;
+import org.eclipse.jpt.jpa.annotate.mapping.EntityRefPropertyElem;
+import org.eclipse.jpt.jpa.annotate.util.AnnotateMappingUtil;
+import org.eclipse.jpt.jpa.ui.JptJpaUiMessages;
+import org.eclipse.jpt.jpa.ui.internal.plugin.JptJpaUiPlugin;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.CCombo;
+import org.eclipse.swt.events.KeyAdapter;
+import org.eclipse.swt.events.KeyEvent;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.TableColumn;
+import org.eclipse.swt.widgets.TableItem;
+
+public class SelectOrderByDialog extends Dialog
+{
+ private IProject project;
+ private String fqRefClassName;
+ private CheckboxTableViewer propertiesTable;
+ private List<PropertyOrder> initialOrderBys;
+ private List<PropertyOrder> finalOrderBys;
+
+ private static final String[] PROPERTY_TABLE_COLUMN_PROPERTIES = { "property", "order" };
+ private static final int PROPERTY_COLUMN_INDEX = 0;
+ private static final int ORDER_COLUMN_INDEX = 1;
+ private static final String[] ORDER_NAMES = {EntityRefPropertyElem.ASCENDING,
+ EntityRefPropertyElem.DESCENDING};
+ private ResourceManager resourceManager;
+
+ public SelectOrderByDialog(Shell shell, ResourceManager resourceManager, IProject project, String fqRefClassName, String orderBy)
+ {
+ super(shell);
+ this.resourceManager = resourceManager;
+ this.project = project;
+ this.fqRefClassName = fqRefClassName;
+ initOrderBys(orderBy);
+ }
+
+ @Override
+ protected void configureShell(Shell newShell)
+ {
+ newShell.setText(JptJpaUiMakePersistentMessages.ORDER_BY_TITLE);
+ super.configureShell(newShell);
+ }
+
+ @Override
+ protected Control createDialogArea(Composite parent)
+ {
+ Composite composite = (Composite)super.createDialogArea(parent);
+ GridLayout gl = new GridLayout(1, false);
+ composite.setLayout(gl);
+ Label label = new Label(composite, SWT.NONE);
+ String desc = String.format(JptJpaUiMakePersistentMessages.ORDER_BY_DESC,
+ AnnotateMappingUtil.getClassName(fqRefClassName));
+ label.setText(desc);
+
+ Composite tablesGroup = new Composite(composite, SWT.NONE);
+ tablesGroup.setLayout(new GridLayout(2, false));
+ GridData data = new GridData();
+ data.verticalAlignment = SWT.FILL;
+ data.horizontalAlignment = SWT.FILL;
+ data.grabExcessHorizontalSpace = true;
+ data.grabExcessVerticalSpace = true;
+ tablesGroup.setLayoutData(data);
+
+ createPropertiesTable(tablesGroup);
+ createButtonComposite(tablesGroup);
+
+ return composite;
+ }
+
+ public String getOrderByDisplayStr()
+ {
+ StringBuffer buf = new StringBuffer();
+ boolean first = true;
+ for (PropertyOrder propOrder : finalOrderBys)
+ {
+ if (propOrder.included)
+ {
+ if (!first)
+ buf.append(", ");
+ else
+ first = false;
+ buf.append(propOrder.propertyName);
+ if (propOrder.order.equals(EntityRefPropertyElem.DESCENDING))
+ buf.append(" DESC");
+ }
+ }
+ if (buf.length() > 0)
+ return buf.toString();
+ else
+ return null;
+ }
+ private void createPropertiesTable(Composite parent)
+ {
+ TableLayoutComposite layout= new TableLayoutComposite(parent, SWT.NONE);
+ addColumnLayoutData(layout);
+
+ final org.eclipse.swt.widgets.Table table = new org.eclipse.swt.widgets.Table(layout, SWT.H_SCROLL | SWT.V_SCROLL | SWT.SINGLE | SWT.FULL_SELECTION | SWT.BORDER | SWT.CHECK);
+ table.setHeaderVisible(true);
+ table.setLinesVisible(true);
+
+ TableColumn tableNameColumn = new TableColumn(table, SWT.NONE, PROPERTY_COLUMN_INDEX);
+ tableNameColumn.setText(JptJpaUiMakePersistentMessages.SELECT_ORDERBY_DIALOG_PROPERTY);
+ tableNameColumn.setResizable(true);
+
+ TableColumn entityNameColumn = new TableColumn(table, SWT.NONE, ORDER_COLUMN_INDEX);
+ entityNameColumn.setText(JptJpaUiMakePersistentMessages.SELECT_ORDERBY_DIALOG_ORDER);
+ entityNameColumn.setResizable(true);
+
+ GridData gd= new GridData(GridData.FILL_BOTH);
+ gd.heightHint= SWTUtil.getTableHeightHint(table, 10);
+ gd.widthHint = 400;
+ layout.setLayoutData(gd);
+
+ this.propertiesTable = new CheckboxTableViewer(table);
+ this.propertiesTable.setUseHashlookup(true);
+ this.propertiesTable.setLabelProvider(new PropertyTableLabelProvider());
+ this.propertiesTable.setContentProvider(new PropertyTableContentProvider());
+
+ this.propertiesTable.addPostSelectionChangedListener(new ISelectionChangedListener() {
+ public void selectionChanged(SelectionChangedEvent event) {
+ handlePropertiesSelectionChanged(event);
+ }
+ });
+
+ table.addKeyListener(new KeyAdapter() {
+ @Override
+ public void keyPressed(KeyEvent e) {
+ if (e.keyCode == SWT.F2 && e.stateMask == SWT.NONE) {
+ //editEntityNameIfPossible();
+ e.doit= false;
+ }
+ }
+ });
+
+ this.addCellEditors();
+ initPropertiesTable();
+ }
+
+ private void addColumnLayoutData(TableLayoutComposite layout)
+ {
+ layout.addColumnData(new ColumnWeightData(50, true));
+ layout.addColumnData(new ColumnWeightData(50, true));
+ }
+
+ private void createButtonComposite(Composite tablesGroup)
+ {
+ Composite buttonComposite = new Composite(tablesGroup, SWT.NULL);
+ GridLayout buttonLayout = new GridLayout(1, false);
+ buttonComposite.setLayout(buttonLayout);
+ GridData data = new GridData();
+ data.horizontalAlignment = GridData.FILL;
+ data.verticalAlignment = GridData.BEGINNING;
+ buttonComposite.setLayoutData(data);
+
+ Button selectAllButton = new Button(buttonComposite, SWT.PUSH);
+ selectAllButton.setImage(resourceManager.createImage(JptCommonUiImages.SELECT_ALL_BUTTON));
+ selectAllButton.setToolTipText(JptJpaUiMessages.General_selectAll);
+ GridData gridData = new GridData();
+ gridData.horizontalAlignment = GridData.FILL;
+ selectAllButton.setLayoutData(gridData);
+ selectAllButton.addSelectionListener(new SelectionListener() {
+ public void widgetDefaultSelected(SelectionEvent e) {
+ // do nothing
+ }
+
+ public void widgetSelected(SelectionEvent e) {
+ selectAllProperties();
+ }
+ });
+
+ Button deselectAllButton = new Button(buttonComposite, SWT.PUSH);
+ deselectAllButton.setImage(resourceManager.createImage(JptCommonUiImages.DESELECT_ALL_BUTTON));
+ deselectAllButton.setToolTipText(JptJpaUiMessages.General_deselectAll);
+ gridData = new GridData();
+ gridData.horizontalAlignment = GridData.FILL;
+ deselectAllButton.setLayoutData(gridData);
+ deselectAllButton.addSelectionListener(new SelectionListener() {
+ public void widgetDefaultSelected(SelectionEvent e) {
+ // do nothing
+ }
+
+ public void widgetSelected(SelectionEvent e) {
+ deselectAllProperties();
+ }
+ });
+
+ }
+
+ private void syncPropertiesSelection()
+ {
+ int index = 0;
+ for (PropertyOrder propOrder : finalOrderBys)
+ {
+ if (propOrder.included != propertiesTable.getChecked(propOrder))
+ {
+ propOrder.included = !propOrder.included;
+ if (propOrder.included)
+ {
+ propOrder.order = EntityRefPropertyElem.ASCENDING;
+ }
+ propertiesTable.update(propOrder, null);
+ }
+ index++;
+ }
+ }
+
+ private void selectAllProperties()
+ {
+ propertiesTable.setAllChecked(true);
+ syncPropertiesSelection();
+ }
+
+ private void deselectAllProperties()
+ {
+ propertiesTable.setAllChecked(false);
+ syncPropertiesSelection();
+ }
+
+ private void handlePropertiesSelectionChanged(SelectionChangedEvent event)
+ {
+ syncPropertiesSelection();
+ }
+
+ private void initPropertiesTable()
+ {
+ IType refType = null;
+ finalOrderBys = new ArrayList<PropertyOrder>();
+
+ try
+ {
+ refType = AnnotateMappingUtil.getType(fqRefClassName, project);
+ IField[] fields = refType.getFields();
+ for (IField field : fields)
+ {
+ // filter out static/inherited fields
+ if (Flags.isStatic(field.getFlags()) || Flags.isSuper(field.getFlags()))
+ continue;
+
+ String typeStr = AnnotateMappingUtil.getFieldType(field, refType);
+ if (AnnotateMappingUtil.isString(typeStr) ||
+ AnnotateMappingUtil.isNumeric(typeStr) ||
+ AnnotateMappingUtil.isDate(typeStr, project) ||
+ AnnotateMappingUtil.isBoolean(typeStr))
+ {
+ PropertyOrder propertyOrder = new PropertyOrder(field.getElementName(), EntityRefPropertyElem.ASCENDING);
+ if (initialOrderBys.contains(propertyOrder))
+ {
+ PropertyOrder another = initialOrderBys.get(initialOrderBys.indexOf(propertyOrder));
+ propertyOrder.included = true;
+ propertyOrder.order = another.order;
+ }
+ finalOrderBys.add(propertyOrder);
+ }
+ }
+ propertiesTable.setInput(finalOrderBys);
+ for (PropertyOrder propOrder : finalOrderBys)
+ {
+ propertiesTable.setChecked(propOrder, propOrder.included);
+ propertiesTable.update(propOrder, null);
+ }
+ }
+ catch (JavaModelException je)
+ {
+ JptJpaUiPlugin.instance().logError(je);
+ }
+
+ }
+
+ private void addCellEditors()
+ {
+ this.propertiesTable.setColumnProperties(PROPERTY_TABLE_COLUMN_PROPERTIES);
+
+ CellEditor[] editors = new CellEditor[PROPERTY_TABLE_COLUMN_PROPERTIES.length];
+ editors[ORDER_COLUMN_INDEX] = new ComboBoxCellEditor(this.propertiesTable.getTable(),
+ ORDER_NAMES, SWT.READ_ONLY | SWT.DROP_DOWN);
+
+ this.propertiesTable.setCellEditors(editors);
+ this.propertiesTable.setCellModifier(new PropertyOrderCellModifier());
+ }
+
+ private void initOrderBys(String orderBy)
+ {
+ initialOrderBys = new ArrayList<PropertyOrder>();
+ if (orderBy != null && orderBy.length() > 0)
+ {
+ StringTokenizer tok = new StringTokenizer(orderBy, ",");
+ while (tok.hasMoreTokens())
+ {
+ String str = tok.nextToken();
+ if (str.charAt(0) == ' ')
+ str = str.substring(1);
+ String propName = null;
+ String propOrder = null;
+ PropertyOrder orderObj = null;
+ int index = str.indexOf(' ');
+ if (index != -1)
+ {
+ propName = str.substring(0, index);
+ String temp = str.substring(index + 1);
+ propOrder = temp.equals("DESC") ? EntityRefPropertyElem.DESCENDING :
+ EntityRefPropertyElem.ASCENDING;
+ orderObj = new PropertyOrder(propName, propOrder);
+ }
+ else
+ {
+ propName = str;
+ orderObj = new PropertyOrder(propName, EntityRefPropertyElem.ASCENDING);
+ }
+ initialOrderBys.add(orderObj);
+ }
+ }
+ }
+
+ // inner classes
+ private class PropertyOrder
+ {
+ public String propertyName;
+ public String order;
+ public boolean included;
+
+ public PropertyOrder(String propertyName, String order)
+ {
+ this(propertyName, order, false);
+ }
+
+ public PropertyOrder(String propertyName, String order, boolean included)
+ {
+ this.propertyName = propertyName;
+ this.order = order;
+ this.included = included;
+ }
+
+ @Override
+ public boolean equals(Object another)
+ {
+ if (!(another instanceof PropertyOrder))
+ return false;
+ return propertyName.equals(((PropertyOrder)another).propertyName);
+ }
+
+ @Override
+ public String toString()
+ {
+ return "["+ this.propertyName + " order " + this.order + "]";
+ }
+
+ }
+
+ private class PropertyTableLabelProvider extends LabelProvider implements ITableLabelProvider
+ {
+ PropertyTableLabelProvider()
+ {
+ super();
+ }
+
+ public Image getColumnImage(Object element, int columnIndex)
+ {
+ return null;
+ }
+
+ public String getColumnText(Object element, int columnIndex)
+ {
+ if (element == null) {
+ return null;
+ }
+ switch (columnIndex)
+ {
+ case PROPERTY_COLUMN_INDEX:
+ return ((PropertyOrder) element).propertyName;
+
+ case ORDER_COLUMN_INDEX:
+ {
+ if (propertiesTable.getChecked(element))
+ return ((PropertyOrder) element).order;
+ else
+ return null;
+ }
+ }
+ throw new IllegalArgumentException("invalid column index: " + columnIndex);
+ }
+
+ }
+
+ private class PropertyTableContentProvider implements IStructuredContentProvider
+ {
+ PropertyTableContentProvider()
+ {
+ super();
+ }
+
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ // do nothing
+ }
+
+ public void dispose() {
+ // do nothing
+ }
+
+ public Object[] getElements(Object inputElement)
+ {
+ return ((Collection<?>) inputElement).toArray();
+ }
+ }
+
+ /**
+ * A CellModifier to update the property orders
+ */
+ private class PropertyOrderCellModifier implements ICellModifier
+ {
+ private CCombo orderCombo;
+ public PropertyOrderCellModifier()
+ {
+ super();
+ CellEditor cellEditor = propertiesTable.getCellEditors()[ORDER_COLUMN_INDEX];
+ assert cellEditor instanceof ComboBoxCellEditor;
+ ComboBoxCellEditor comboEditor = (ComboBoxCellEditor)cellEditor;
+ orderCombo = (CCombo)comboEditor.getControl();
+
+ }
+
+ public boolean canModify(Object element, String property)
+ {
+ // order column can be modified if the element is selected
+ if (property.equals(PROPERTY_TABLE_COLUMN_PROPERTIES[ORDER_COLUMN_INDEX]) &&
+ propertiesTable.getChecked(element))
+ return true;
+ else
+ return false;
+ }
+
+ public Object getValue(Object element, String property)
+ {
+ // return the index of the value in the table model
+ if (property.equals(PROPERTY_TABLE_COLUMN_PROPERTIES[ORDER_COLUMN_INDEX]))
+ {
+ return finalOrderBys.indexOf(element);
+ }
+ return new Integer(0);
+ }
+
+ /**
+ * element is the selected TableItem
+ * value is the selected item index in the comboCellEditor
+ */
+ public void modify(Object element, String property, Object value)
+ {
+ if ( ! (element instanceof TableItem))
+ {
+ return;
+ }
+ Integer index = (Integer)value;
+ TableItem item = (TableItem)element;
+ PropertyOrder propertyOrder = (PropertyOrder)item.getData();
+ String newOrder = orderCombo.getItem(index);
+ propertyOrder.order = newOrder;
+ propertiesTable.refresh();
+ }
+
+ }
+
+}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/makepersistent/SelectPropertyDialog.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/makepersistent/SelectPropertyDialog.java
new file mode 100644
index 0000000..e13fe1c
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/makepersistent/SelectPropertyDialog.java
@@ -0,0 +1,104 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+
+package org.eclipse.jpt.jpa.ui.internal.wizards.makepersistent;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.Set;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.jdt.core.IType;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jface.viewers.ILabelProvider;
+import org.eclipse.jface.viewers.ILabelProviderListener;
+import org.eclipse.jpt.jpa.annotate.mapping.EntityRefPropertyElem;
+import org.eclipse.jpt.jpa.annotate.util.AnnotateMappingUtil;
+import org.eclipse.jpt.jpa.ui.internal.plugin.JptJpaUiPlugin;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.dialogs.ElementListSelectionDialog;
+
+public class SelectPropertyDialog extends ElementListSelectionDialog
+{
+ private String entityClass;
+ EntityRefPropertyElem refElem;
+ private IType refType;
+ private boolean isManyToMany;
+
+ public SelectPropertyDialog(Shell shell, IProject project,
+ String entityClass, EntityRefPropertyElem refElem, boolean isManyToMany)
+ {
+ super(shell, new ILabelProvider()
+ {
+ public Image getImage(Object element)
+ {
+ return null;
+ }
+
+ public String getText(Object element)
+ {
+ return element.toString();
+ }
+ public void addListener(ILabelProviderListener listener) {}
+ public void dispose() {}
+
+ public boolean isLabelProperty(Object element, String property)
+ {
+ return false;
+ }
+
+ public void removeListener(ILabelProviderListener listener) {}
+ });
+ setTitle(JptJpaUiMakePersistentMessages.CHOOSE_PROPERTY_TITLE);
+
+ this.entityClass = entityClass;
+ this.refElem = refElem;
+ try
+ {
+ refType = AnnotateMappingUtil.getType(refElem.getRefEntityClassName(), project);
+ }
+ catch (JavaModelException je)
+ {
+ JptJpaUiPlugin.instance().logError(je);
+ }
+ String desc = String.format(
+ JptJpaUiMakePersistentMessages.CHOOSE_PROPERTY_DESC, refElem.getRefEntityClassName(),
+ refElem.getPropertyName());
+ setMessage(desc);
+ this.isManyToMany = isManyToMany;
+ addProperties();
+ }
+
+ private void addProperties()
+ {
+ try
+ {
+ Set mappedBySet = AnnotateMappingUtil.getMappedByList(entityClass, refType, isManyToMany);
+ Iterator mappedByIt = mappedBySet.iterator();
+ ArrayList<String> propList = new ArrayList<String>();
+ while (mappedByIt.hasNext())
+ {
+ propList.add((String)mappedByIt.next());
+ }
+ setElements(propList.toArray());
+ }
+ catch (JavaModelException je)
+ {
+ JptJpaUiPlugin.instance().logError(je);
+ }
+ }
+
+ public String getSelectedProp()
+ {
+ return (String)this.getFirstResult();
+ }
+
+}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/makepersistent/SelectTableDialog.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/makepersistent/SelectTableDialog.java
new file mode 100644
index 0000000..6c18f97
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/makepersistent/SelectTableDialog.java
@@ -0,0 +1,76 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+
+package org.eclipse.jpt.jpa.ui.internal.wizards.makepersistent;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.jface.resource.ResourceManager;
+import org.eclipse.jface.viewers.ILabelProvider;
+import org.eclipse.jface.viewers.ILabelProviderListener;
+import org.eclipse.jpt.jpa.db.Schema;
+import org.eclipse.jpt.jpa.db.Table;
+import org.eclipse.jpt.jpa.ui.JptJpaUiImages;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.dialogs.ElementListSelectionDialog;
+
+/**
+ * A database table selection dialog which allows user to filter tables by name
+ */
+public class SelectTableDialog extends ElementListSelectionDialog {
+
+ public SelectTableDialog(Shell shell, final ResourceManager resourceManager){
+ super(shell, new ILabelProvider(){
+ public Image getImage(Object element) {
+ return resourceManager.createImage(JptJpaUiImages.TABLE);
+ }
+
+ public String getText(Object element) {
+ return element.toString();
+ }
+ public void addListener(ILabelProviderListener listener) {}
+ public void dispose() {}
+
+ public boolean isLabelProperty(Object element, String property) {
+ return false;
+ }
+
+ public void removeListener(ILabelProviderListener listener) {}
+
+ });
+ this.setTitle( JptJpaUiMakePersistentMessages.SELECT_TABLE_DLG_TITLE );
+ this.setMessage( JptJpaUiMakePersistentMessages.SELECT_TABLE_DLG_DESC);
+ }
+
+ public SelectTableDialog(Shell shell, ResourceManager resourceManager, Schema schema){
+ this(shell, resourceManager);
+
+ ArrayList<String> list = new ArrayList<String>();
+ for( Table table : schema.getTables() )
+ {
+ list.add(table.getName());
+ }
+ this.setElements( list.toArray() );
+
+ }
+
+ public SelectTableDialog(Shell shell, ResourceManager resourceManager, List<String> tableNames){
+ this(shell, resourceManager);
+ this.setElements( tableNames.toArray() );
+ }
+ public String getSelectedTable()
+ {
+ String tableName = (String)this.getFirstResult();
+ return tableName ;
+ }
+
+} \ No newline at end of file