Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPetya Sabeva2013-01-02 13:42:12 +0000
committerPetya Sabeva2013-01-02 13:57:57 +0000
commit4c46116f315db000d7550b9fa26ad4ef61c68733 (patch)
tree47c10829c3ff604d82b6aa8797e5ed3d134454ec /jpa_diagram_editor/plugins
parent8ac751a8b8531fb642ccd9f85746afe7ed2da36c (diff)
downloadwebtools.dali-4c46116f315db000d7550b9fa26ad4ef61c68733.tar.gz
webtools.dali-4c46116f315db000d7550b9fa26ad4ef61c68733.tar.xz
webtools.dali-4c46116f315db000d7550b9fa26ad4ef61c68733.zip
[364597] - JPA 2.0 - Support for derived ids
Diffstat (limited to 'jpa_diagram_editor/plugins')
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/icons/ent/many-to-one-1-key.gifbin0 -> 371 bytes
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/icons/ent/many-to-one-2-key.gifbin0 -> 370 bytes
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/icons/ent/many-to-one-key.gifbin0 -> 360 bytes
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/icons/ent/one-to-one-1-key.gifbin0 -> 357 bytes
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/icons/ent/one-to-one-2-key.gifbin0 -> 359 bytes
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/icons/ent/one-to-one-key.gifbin0 -> 346 bytes
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/JPADiagramEditor.java1
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/command/AddAttributeCommand.java31
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/command/DeleteAttributeCommand.java271
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/command/RenameAttributeCommand.java21
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/AddJPAEntityFeature.java25
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/AddRelationFeature.java52
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/ClickRemoveAttributeButtonFeature.java183
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateManyToManyRelationFeature.java2
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateManyToOneBiDirRelationFeature.java20
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateManyToOneRelationFeature.java4
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateManyToOneUniDirRelationFeature.java15
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateOneToManyRelationFeature.java2
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateOneToOneBiDirRelationFeature.java16
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateOneToOneRelationFeature.java4
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateOneToOneUniDirRelationFeature.java16
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateRelationFeature.java21
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/GraphicalAddAttributeFeature.java10
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/RefactorEntityFeature.java11
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/i18n/JPAEditorMessages.java2
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/i18n/messages.properties1
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/provider/JPAEditorFeatureProvider.java10
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/provider/JPAEditorImageProvider.java14
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/provider/JPAEditorToolBehaviorProvider.java52
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/ManyToOneBiDirRelation.java17
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/ManyToOneUniDirRelation.java11
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/OneToOneBiDirRelation.java12
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/OneToOneUniDirRelation.java11
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/JPAEditorConstants.java1
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/JPAEditorUtil.java20
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/JPASolver.java7
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/JpaArtifactFactory.java255
37 files changed, 882 insertions, 236 deletions
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/icons/ent/many-to-one-1-key.gif b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/icons/ent/many-to-one-1-key.gif
new file mode 100644
index 0000000000..e11633f87d
--- /dev/null
+++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/icons/ent/many-to-one-1-key.gif
Binary files differ
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/icons/ent/many-to-one-2-key.gif b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/icons/ent/many-to-one-2-key.gif
new file mode 100644
index 0000000000..7fd38a2573
--- /dev/null
+++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/icons/ent/many-to-one-2-key.gif
Binary files differ
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/icons/ent/many-to-one-key.gif b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/icons/ent/many-to-one-key.gif
new file mode 100644
index 0000000000..077e8aefdf
--- /dev/null
+++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/icons/ent/many-to-one-key.gif
Binary files differ
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/icons/ent/one-to-one-1-key.gif b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/icons/ent/one-to-one-1-key.gif
new file mode 100644
index 0000000000..0a46cfb479
--- /dev/null
+++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/icons/ent/one-to-one-1-key.gif
Binary files differ
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/icons/ent/one-to-one-2-key.gif b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/icons/ent/one-to-one-2-key.gif
new file mode 100644
index 0000000000..8ea6842c33
--- /dev/null
+++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/icons/ent/one-to-one-2-key.gif
Binary files differ
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/icons/ent/one-to-one-key.gif b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/icons/ent/one-to-one-key.gif
new file mode 100644
index 0000000000..3e72534885
--- /dev/null
+++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/icons/ent/one-to-one-key.gif
Binary files differ
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/JPADiagramEditor.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/JPADiagramEditor.java
index 1c260b28c2..af2edc271c 100644
--- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/JPADiagramEditor.java
+++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/JPADiagramEditor.java
@@ -321,6 +321,7 @@ public class JPADiagramEditor extends DiagramEditor implements JpaEditorManager{
jpaSelectionModel.setValue(jpaStructureNode);
setFileModel(jpaStructureNode);
selectionManager.setSelection(jpaStructureNode);
+// jpaStructureNode.getJpaPlatform().buildJpaFile(jpaStructureNode.getJpaProject(), jpaFileModel.getValue().getFile());
return;
}
}
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/command/AddAttributeCommand.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/command/AddAttributeCommand.java
index 8bad938b36..70a22057e7 100644
--- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/command/AddAttributeCommand.java
+++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/command/AddAttributeCommand.java
@@ -112,19 +112,22 @@ public class AddAttributeCommand implements Command {
createAttribute(fp, jpt, attributeType, mapKeyType, attributeName,
actName, cu, type, isCollection, attrTypes, contents);
- JavaPersistentAttribute attr = jpt.getAttributeNamed(actName);
- int cnt = 0;
- while ((attr == null) && (cnt < 25)) {
- try {
- Thread.sleep(250);
- } catch (InterruptedException e) {
- JPADiagramEditorPlugin.logError("Cannnot create a new attribute with name " + attributeName, e); //$NON-NLS-1$
+ if(jpt != null) {
+ JavaPersistentAttribute attr = jpt.getAttributeNamed(actName);
+ int cnt = 0;
+ while ((attr == null) && (cnt < 25)) {
+ try {
+ Thread.sleep(250);
+ } catch (InterruptedException e) {
+ JPADiagramEditorPlugin.logError("Cannnot create a new attribute with name " + attributeName, e); //$NON-NLS-1$
+ }
+ jpt.getJavaResourceType().getJavaResourceCompilationUnit()
+ .synchronizeWithJavaSource();
+ jpt.update();
+ jpt.synchronizeWithResourceModel();
+ attr = jpt.getAttributeNamed(actName);
+ cnt++;
}
- jpt.getJavaResourceType().getJavaResourceCompilationUnit()
- .synchronizeWithJavaSource();
- jpt.update();
- attr = jpt.getAttributeNamed(actName);
- cnt++;
}
} catch (JavaModelException e) {
@@ -182,7 +185,7 @@ public class AddAttributeCommand implements Command {
" " + JPAEditorUtil.decapitalizeFirstLetter(actName) + ";"; //$NON-NLS-1$ //$NON-NLS-2$
String contents = ""; //$NON-NLS-1$
- if(!JpaArtifactFactory.instance().isMethodAnnotated(jpt)){
+ if(jpt!= null && !JpaArtifactFactory.instance().isMethodAnnotated(jpt)){
contents = annotationContents + attrFieldContent;
} else {
contents = attrFieldContent;
@@ -379,7 +382,7 @@ public class AddAttributeCommand implements Command {
+ actName.substring(1);
String contents = ""; //$NON-NLS-1$
- if(JpaArtifactFactory.instance().isMethodAnnotated(jpt)){
+ if(jpt != null && JpaArtifactFactory.instance().isMethodAnnotated(jpt)){
contents += annotationContents;
}
contents += " public " + attrType + //$NON-NLS-1$
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/command/DeleteAttributeCommand.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/command/DeleteAttributeCommand.java
index 5252dbd526..eb3159aa0f 100644
--- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/command/DeleteAttributeCommand.java
+++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/command/DeleteAttributeCommand.java
@@ -25,7 +25,6 @@ import org.eclipse.jdt.core.IMethod;
import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jpt.common.utility.command.Command;
-import org.eclipse.jpt.jpa.core.context.java.JavaPersistentAttribute;
import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.JPADiagramEditorPlugin;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.IJPAEditorFeatureProvider;
@@ -39,109 +38,205 @@ public class DeleteAttributeCommand implements Command {
private JavaPersistentType jpt;
private String attributeName;
private IJPAEditorFeatureProvider fp;
+ private ICompilationUnit unit;
- public DeleteAttributeCommand(JavaPersistentType jpt, String attributeName,
+ public DeleteAttributeCommand(ICompilationUnit unit, JavaPersistentType jpt, String attributeName,
IJPAEditorFeatureProvider fp) {
super();
this.jpt = jpt;
+ this.unit = unit;
this.attributeName = attributeName;
this.fp = fp;
}
public void execute() {
- synchronized (jpt) {
- String attrNameWithCapitalLetter = attributeName.substring(0, 1)
- .toUpperCase(Locale.ENGLISH)
- + attributeName.substring(1);
- ICompilationUnit compUnit = fp.getCompilationUnit(jpt);
- IType javaType = compUnit.findPrimaryType();
- JavaPersistentAttribute jpa = jpt.getAttributeNamed(attributeName);
+//<<<<<<< OURS
+// synchronized (jpt) {
+// String attrNameWithCapitalLetter = attributeName.substring(0, 1)
+// .toUpperCase(Locale.ENGLISH)
+// + attributeName.substring(1);
+// ICompilationUnit compUnit = fp.getCompilationUnit(jpt);
+// IType javaType = compUnit.findPrimaryType();
+// JavaPersistentAttribute jpa = jpt.getAttributeNamed(attributeName);
+//
+// String typeSignature = null;
+// String getterPrefix = "get"; //$NON-NLS-1$
+// String methodName = getterPrefix + attrNameWithCapitalLetter;
+// IMethod getAttributeMethod = javaType.getMethod(methodName,
+// new String[0]);
+// if (!getAttributeMethod.exists()) {
+//
+// String typeName = jpa.getResourceAttribute().getTypeBinding().getQualifiedName();
+// if ("boolean".equals(typeName)) { //$NON-NLS-1$
+// getterPrefix = "is"; //$NON-NLS-1$
+// methodName = getterPrefix + attrNameWithCapitalLetter;
+// getAttributeMethod = javaType.getMethod(methodName,
+// new String[0]);
+// }
+// try {
+// if ((getAttributeMethod != null) && getAttributeMethod.exists()) {
+// typeSignature = getAttributeMethod.getReturnType();
+// }
+// } catch (JavaModelException e1) {
+// JPADiagramEditorPlugin.logError("Cannot obtain the type of the getter with name " + methodName + "()", e1); //$NON-NLS-1$ //$NON-NLS-2$
+// }
+// }
+// if (typeSignature == null)
+// methodName = null;
+//=======
+ boolean isMethodAnnotated = false;
+//>>>>>>> THEIRS
+//
+//<<<<<<< OURS
+// boolean isMethodAnnotated = JpaArtifactFactory.instance()
+// .isMethodAnnotated(jpt);
+// if (isMethodAnnotated) {
+// try {
+// IField attributeField = javaType.getField(attributeName);
+//
+// if ((attributeField != null) && !attributeField.exists())
+// attributeField = javaType.getField(JPAEditorUtil.revertFirstLetterCase(attributeName));
+// if ((attributeField != null) && attributeField.exists())
+// attributeField.delete(true, new NullProgressMonitor());
+// } catch (JavaModelException e) {
+// JPADiagramEditorPlugin.logError("Cannot remove the attribute field with name " + attributeName, e); //$NON-NLS-1$
+// }
+// try {
+// methodName = getterPrefix + attrNameWithCapitalLetter;
+// if (getAttributeMethod != null) {
+// typeSignature = getAttributeMethod.getReturnType();
+// if (getAttributeMethod.exists())
+// getAttributeMethod.delete(true, new NullProgressMonitor());
+// }
+// } catch (JavaModelException e) {
+// JPADiagramEditorPlugin.logError("Cannot remove the attribute getter with name " + methodName + "()", e); //$NON-NLS-1$ //$NON-NLS-2$
+// }
+// } else {
+// try {
+// methodName = getterPrefix + attrNameWithCapitalLetter;
+// if (getAttributeMethod.exists()) {
+// typeSignature = getAttributeMethod.getReturnType();
+// getAttributeMethod.delete(true, new NullProgressMonitor());
+// }
+// } catch (JavaModelException e) {
+// JPADiagramEditorPlugin.logError("Cannot remove the attribute getter with name " + methodName + "()", e); //$NON-NLS-1$ //$NON-NLS-2$
+// }
+// try {
+// IField attributeField = javaType.getField(this.attributeName);
+// if (attributeField != null)
+// if (!attributeField.exists())
+// attributeField = javaType.getField(JPAEditorUtil.revertFirstLetterCase(attributeName));
+// if ((attributeField != null) && attributeField.exists())
+// attributeField.delete(true, new NullProgressMonitor());
+// } catch (JavaModelException e) {
+// JPADiagramEditorPlugin.logError("Cannot remove the attribute field with name " + attributeName, e); //$NON-NLS-1$
+// }
+// }
+// try {
+// methodName = "set" + attrNameWithCapitalLetter; //$NON-NLS-1$
+// IMethod setAttributeMethod = javaType.getMethod(methodName,
+// new String[] { typeSignature });
+// if ((setAttributeMethod != null) && setAttributeMethod.exists())
+// setAttributeMethod.delete(true, new NullProgressMonitor());
+// } catch (Exception e) {
+// JPADiagramEditorPlugin.logError("Cannot remove the attribute setter with name " + methodName + "(...)", e); //$NON-NLS-1$ //$NON-NLS-2$
+// }
+//
+// IWorkbenchSite ws = ((IEditorPart) fp.getDiagramTypeProvider().getDiagramEditor()).getSite();
+// JPAEditorUtil.organizeImports(compUnit, ws);
+//
+// this.jpt.getJavaResourceType().getJavaResourceCompilationUnit().synchronizeWithJavaSource();
+//
+//=======
+ if(jpt != null) {
+ unit = fp.getCompilationUnit(jpt);
+ isMethodAnnotated = JpaArtifactFactory.instance()
+ .isMethodAnnotated(jpt);
+//>>>>>>> THEIRS
+ }
+
+ IType javaType = unit.findPrimaryType();
- String typeSignature = null;
- String getterPrefix = "get"; //$NON-NLS-1$
- String methodName = getterPrefix + attrNameWithCapitalLetter;
- IMethod getAttributeMethod = javaType.getMethod(methodName,
- new String[0]);
- if (!getAttributeMethod.exists()) {
-
- String typeName = jpa.getResourceAttribute().getTypeBinding().getQualifiedName();
- if ("boolean".equals(typeName)) { //$NON-NLS-1$
- getterPrefix = "is"; //$NON-NLS-1$
- methodName = getterPrefix + attrNameWithCapitalLetter;
- getAttributeMethod = javaType.getMethod(methodName,
- new String[0]);
- }
- try {
- if ((getAttributeMethod != null) && getAttributeMethod.exists()) {
- typeSignature = getAttributeMethod.getReturnType();
- }
- } catch (JavaModelException e1) {
- JPADiagramEditorPlugin.logError("Cannot obtain the type of the getter with name " + methodName + "()", e1); //$NON-NLS-1$ //$NON-NLS-2$
- }
- }
- if (typeSignature == null)
- methodName = null;
+ String attrNameWithCapitalLetter = attributeName.substring(0, 1)
+ .toUpperCase(Locale.ENGLISH) + attributeName.substring(1);
- boolean isMethodAnnotated = JpaArtifactFactory.instance()
- .isMethodAnnotated(jpt);
- if (isMethodAnnotated) {
- try {
- IField attributeField = javaType.getField(attributeName);
+ String typeSignature = null;
+ String getterPrefix = "get"; //$NON-NLS-1$
+ String methodName = getterPrefix + attrNameWithCapitalLetter;
+ IMethod getAttributeMethod = javaType.getMethod(methodName,
+ new String[0]);
+ if (!getAttributeMethod.exists()) {
+ getterPrefix = "is"; //$NON-NLS-1$
+ }
+ methodName = getterPrefix + attrNameWithCapitalLetter; //$NON-NLS-1$
+ getAttributeMethod = javaType.getMethod(methodName, new String[0]);
+ try {
+ if ((getAttributeMethod != null) && getAttributeMethod.exists());
+ typeSignature = getAttributeMethod.getReturnType();
+ } catch (JavaModelException e1) {
+ JPADiagramEditorPlugin.logError("Cannot obtain the type of the getter with name " + methodName + "()", e1); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ if (typeSignature == null)
+ methodName = null;
+
+ if (isMethodAnnotated) {
+ try {
+ IField attributeField = javaType.getField(attributeName);
- if ((attributeField != null) && !attributeField.exists())
- attributeField = javaType.getField(JPAEditorUtil.revertFirstLetterCase(attributeName));
- if ((attributeField != null) && attributeField.exists())
- attributeField.delete(true, new NullProgressMonitor());
- } catch (JavaModelException e) {
- JPADiagramEditorPlugin.logError("Cannot remove the attribute field with name " + attributeName, e); //$NON-NLS-1$
- }
- try {
- methodName = getterPrefix + attrNameWithCapitalLetter;
- if (getAttributeMethod != null) {
- typeSignature = getAttributeMethod.getReturnType();
- if (getAttributeMethod.exists())
- getAttributeMethod.delete(true, new NullProgressMonitor());
- }
- } catch (JavaModelException e) {
- JPADiagramEditorPlugin.logError("Cannot remove the attribute getter with name " + methodName + "()", e); //$NON-NLS-1$ //$NON-NLS-2$
- }
- } else {
- try {
- methodName = getterPrefix + attrNameWithCapitalLetter;
- if (getAttributeMethod.exists()) {
- typeSignature = getAttributeMethod.getReturnType();
+ if ((attributeField != null) && !attributeField.exists())
+ attributeField = javaType.getField(JPAEditorUtil.revertFirstLetterCase(attributeName));
+ if ((attributeField != null) && attributeField.exists())
+ attributeField.delete(true, new NullProgressMonitor());
+ } catch (JavaModelException e) {
+ JPADiagramEditorPlugin.logError("Cannot remove the attribute field with name " + attributeName, e); //$NON-NLS-1$
+ }
+ try {
+ methodName = getterPrefix + attrNameWithCapitalLetter; //$NON-NLS-1$
+ if (getAttributeMethod != null) {
+ typeSignature = getAttributeMethod.getReturnType();
+ if (getAttributeMethod.exists())
getAttributeMethod.delete(true, new NullProgressMonitor());
- }
- } catch (JavaModelException e) {
- JPADiagramEditorPlugin.logError("Cannot remove the attribute getter with name " + methodName + "()", e); //$NON-NLS-1$ //$NON-NLS-2$
- }
- try {
- IField attributeField = javaType.getField(this.attributeName);
- if (attributeField != null)
- if (!attributeField.exists())
- attributeField = javaType.getField(JPAEditorUtil.revertFirstLetterCase(attributeName));
- if ((attributeField != null) && attributeField.exists())
- attributeField.delete(true, new NullProgressMonitor());
- } catch (JavaModelException e) {
- JPADiagramEditorPlugin.logError("Cannot remove the attribute field with name " + attributeName, e); //$NON-NLS-1$
- }
- }
+ }
+ } catch (JavaModelException e) {
+ JPADiagramEditorPlugin.logError("Cannot remove the attribute getter with name " + methodName + "()", e); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ } else {
+ try {
+ methodName = getterPrefix + attrNameWithCapitalLetter; //$NON-NLS-1$
+ if (getAttributeMethod.exists()) {
+ typeSignature = getAttributeMethod.getReturnType();
+ getAttributeMethod.delete(true, new NullProgressMonitor());
+ }
+ } catch (JavaModelException e) {
+ JPADiagramEditorPlugin.logError("Cannot remove the attribute getter with name " + methodName + "()", e); //$NON-NLS-1$ //$NON-NLS-2$
+ }
try {
- methodName = "set" + attrNameWithCapitalLetter; //$NON-NLS-1$
- IMethod setAttributeMethod = javaType.getMethod(methodName,
- new String[] { typeSignature });
- if ((setAttributeMethod != null) && setAttributeMethod.exists())
- setAttributeMethod.delete(true, new NullProgressMonitor());
- } catch (Exception e) {
- JPADiagramEditorPlugin.logError("Cannot remove the attribute setter with name " + methodName + "(...)", e); //$NON-NLS-1$ //$NON-NLS-2$
- }
+ IField attributeField = javaType.getField(this.attributeName);
+ if (attributeField != null)
+ if (!attributeField.exists())
+ attributeField = javaType.getField(JPAEditorUtil.revertFirstLetterCase(attributeName));
+ if ((attributeField != null) && attributeField.exists())
+ attributeField.delete(true, new NullProgressMonitor());
+ } catch (JavaModelException e) {
+ JPADiagramEditorPlugin.logError("Cannot remove the attribute field with name " + attributeName, e); //$NON-NLS-1$
+ }
+ }
+ try {
+ methodName = "set" + attrNameWithCapitalLetter; //$NON-NLS-1$
+ IMethod setAttributeMethod = javaType.getMethod(methodName,
+ new String[] { typeSignature });
+ if ((setAttributeMethod != null) && setAttributeMethod.exists())
+ setAttributeMethod.delete(true, new NullProgressMonitor());
+ } catch (Exception e) {
+ JPADiagramEditorPlugin.logError("Cannot remove the attribute setter with name " + methodName + "(...)", e); //$NON-NLS-1$ //$NON-NLS-2$
+ }
- IWorkbenchSite ws = ((IEditorPart) fp.getDiagramTypeProvider().getDiagramEditor()).getSite();
- JPAEditorUtil.organizeImports(compUnit, ws);
-
- this.jpt.getJavaResourceType().getJavaResourceCompilationUnit().synchronizeWithJavaSource();
+ IWorkbenchSite ws = ((IEditorPart) fp.getDiagramTypeProvider().getDiagramEditor()).getSite();
+ JPAEditorUtil.organizeImports(unit, ws);
- }
+ if(jpt != null)
+ jpt.getJavaResourceType().getJavaResourceCompilationUnit().synchronizeWithJavaSource();
}
}
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/command/RenameAttributeCommand.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/command/RenameAttributeCommand.java
index d9f770193e..db274a4220 100644
--- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/command/RenameAttributeCommand.java
+++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/command/RenameAttributeCommand.java
@@ -18,6 +18,7 @@ package org.eclipse.jpt.jpadiagrameditor.ui.internal.command;
import java.lang.reflect.InvocationTargetException;
+import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jdt.core.IField;
@@ -37,16 +38,18 @@ import org.eclipse.ui.IWorkbenchWindow;
public class RenameAttributeCommand implements Command {
private JavaPersistentType jpt;
+ private ICompilationUnit jptCompilationUnit;
private String oldName;
private String newName;
private IJPAEditorFeatureProvider fp;
- public RenameAttributeCommand(JavaPersistentType jpt, String oldName,
+ public RenameAttributeCommand(ICompilationUnit jptCompilationUnit, JavaPersistentType jpt, String oldName,
String newName, IJPAEditorFeatureProvider fp){
super();
this.jpt = jpt;
+ this.jptCompilationUnit = jptCompilationUnit;
this.oldName = oldName;
this.newName = newName;
this.fp = fp;
@@ -54,10 +57,20 @@ public class RenameAttributeCommand implements Command {
}
public void execute() {
- ICompilationUnit cu = fp.getCompilationUnit(jpt);
+ if(jptCompilationUnit == null) {
+ jptCompilationUnit = fp.getCompilationUnit(jpt);
+ }
try {
- renameAttribute(cu, oldName, this.newName, fp, JpaArtifactFactory.instance().isMethodAnnotated(jpt));
- jpt.getJavaResourceType().getJavaResourceCompilationUnit().synchronizeWithJavaSource();
+ boolean isMethodAnnotated = false;
+ if(jpt!= null){
+ isMethodAnnotated = JpaArtifactFactory.instance().isMethodAnnotated(jpt);
+ }
+ renameAttribute(jptCompilationUnit, oldName, this.newName, fp, isMethodAnnotated);
+
+ if(jpt != null) {
+ jpt.getJavaResourceType().getJavaResourceCompilationUnit().synchronizeWithJavaSource();
+ jpt.getJpaPlatform().buildJpaFile(jpt.getJpaProject(), (IFile) jptCompilationUnit.getResource());
+ }
} catch (InterruptedException e) {
JPADiagramEditorPlugin.logError("Cannot rename attribute", e); //$NON-NLS-1$
}
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/AddJPAEntityFeature.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/AddJPAEntityFeature.java
index ca9c47812a..8a269f9843 100644
--- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/AddJPAEntityFeature.java
+++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/AddJPAEntityFeature.java
@@ -221,15 +221,15 @@ public class AddJPAEntityFeature extends AbstractAddShapeFeature {
}
private void fillCompartments(JavaPersistentType jpt, ContainerShape entityShape) {
- String[] primaryKeyAnnotations = new String[] {JPAEditorConstants.ANNOTATION_ID, JPAEditorConstants.ANNOTATION_EMBEDDED_ID};
+ String[] primaryKeyAnnotations = new String[] {JPAEditorConstants.ANNOTATION_ID, JPAEditorConstants.ANNOTATION_EMBEDDED_ID, JPAEditorConstants.ANNOTATION_MAPS_ID};
for(String annotation : primaryKeyAnnotations){
- addCompartmentChildren(primaryShape, jpt, annotation);
+ addCompartmentChildren(primaryShape, jpt, annotation, null);
}
String[] relationAnnotations = new String[] {JPAEditorConstants.ANNOTATION_MANY_TO_MANY,
JPAEditorConstants.ANNOTATION_MANY_TO_ONE, JPAEditorConstants.ANNOTATION_ONE_TO_MANY,
JPAEditorConstants.ANNOTATION_ONE_TO_ONE};
for(String annotation : relationAnnotations){
- addCompartmentChildren(relationShape, jpt, annotation);
+ addCompartmentChildren(relationShape, jpt, annotation, primaryKeyAnnotations);
}
addBasicAttributes(basicShape, jpt);
GraphicsUpdater.updateEntityShape(entityShape);
@@ -284,18 +284,29 @@ public class AddJPAEntityFeature extends AbstractAddShapeFeature {
private void addCompartmentChildren(
ContainerShape containerShape, JavaPersistentType jpt,
- String attributeAnnotations) {
+ String attributeAnnotations, String[] excludeAnnotations) {
List<JavaPersistentAttribute> attributes = new ArrayList<JavaPersistentAttribute>();
for (JavaPersistentAttribute attribute : jpt.getAttributes()) {
HashSet<String> annotations = JpaArtifactFactory.instance().getAnnotationNames(attribute);
- if (annotations.contains(attributeAnnotations)) {
+ if (annotations.contains(attributeAnnotations) && canAddAttribute(annotations, excludeAnnotations)) {
attributes.add(attribute);
}
}
addAttributes(containerShape, attributes);
}
+ private boolean canAddAttribute(HashSet<String> annotations, String[] excludeAnnotations){
+ if(excludeAnnotations == null || excludeAnnotations.length == 0)
+ return true;
+ for(String annotation : excludeAnnotations){
+ if(annotations.contains(annotation))
+ return false;
+ }
+
+ return true;
+ }
+
private void addBasicAttributes(ContainerShape containerShape, JavaPersistentType jpt){
List<JavaPersistentAttribute> attributes = new ArrayList<JavaPersistentAttribute>();
@@ -303,7 +314,7 @@ public class AddJPAEntityFeature extends AbstractAddShapeFeature {
HashSet<String> annotations = JpaArtifactFactory.instance().getAnnotationNames(attribute);
if(!(annotations.contains(JPAEditorConstants.ANNOTATION_ID))&& !(annotations.contains(JPAEditorConstants.ANNOTATION_EMBEDDED_ID)) && !(annotations.contains(JPAEditorConstants.ANNOTATION_MANY_TO_MANY)) &&
!(annotations.contains(JPAEditorConstants.ANNOTATION_MANY_TO_ONE)) && !(annotations.contains(JPAEditorConstants.ANNOTATION_ONE_TO_MANY))&&
- !(annotations.contains(JPAEditorConstants.ANNOTATION_ONE_TO_ONE)) || annotations.isEmpty()){
+ !(annotations.contains(JPAEditorConstants.ANNOTATION_ONE_TO_ONE)) && !(annotations.contains(JPAEditorConstants.ANNOTATION_MAPS_ID)) || annotations.isEmpty()){
attributes.add(attribute);
}
}
@@ -437,4 +448,4 @@ public class AddJPAEntityFeature extends AbstractAddShapeFeature {
graphicalAdd.add(addContext);
}
-} \ No newline at end of file
+}
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/AddRelationFeature.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/AddRelationFeature.java
index ad8216db92..5f300517c1 100644
--- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/AddRelationFeature.java
+++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/AddRelationFeature.java
@@ -21,6 +21,7 @@ import static org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.IRelation.R
import static org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.IRelation.RelType.ONE_TO_MANY;
import static org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.IRelation.RelType.ONE_TO_ONE;
+import java.util.HashSet;
import java.util.List;
import org.eclipse.emf.transaction.RecordingCommand;
@@ -51,6 +52,7 @@ import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.IJPAEditorUtil;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JPAEditorConstants;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JPAEditorUtil;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JPAEditorUtilImpl;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JpaArtifactFactory;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.Wrp;
import org.eclipse.swt.graphics.Point;
@@ -210,18 +212,30 @@ public class AddRelationFeature extends AbstractAddFeature {
}
JavaPersistentAttribute owner = rel.getOwner().getAttributeNamed(rel.getOwnerAttributeName());
owner.update();
- JavaAttributeMapping mapping = owner.getMapping();
- a = (OneToOneAnnotation)mapping.getMappingAnnotation();
- if (a == null)
- return;
- optional = a.getOptional();
- isOptional = (optional == null) ? true : optional.booleanValue();
- imageCreator.createCardinalityConnectionDecorator(getDiagram(), c, isOptional ? JPAEditorConstants.CARDINALITY_ZERO_ONE : JPAEditorConstants.CARDINALITY_ONE, 1.0);
- imageCreator.createCardinalityConnectionDecorator(getDiagram(), c, rel.getOwnerAttributeName(), 0.0);
+ HashSet<String> annotations = JpaArtifactFactory.instance().getAnnotationNames(owner);
+ if(isDerivedId(annotations)){
+ isOptional = false;
+ } else {
+ JavaAttributeMapping mapping = owner.getMapping();
+ a = (OneToOneAnnotation) mapping.getMappingAnnotation();
+ if (a == null)
+ return;
+ optional = a.getOptional();
+ isOptional = (optional == null) ? true : optional.booleanValue();
+ }
+ imageCreator.createCardinalityConnectionDecorator(getDiagram(), c, isOptional ? JPAEditorConstants.CARDINALITY_ZERO_ONE : JPAEditorConstants.CARDINALITY_ONE, 1.0);
+ imageCreator.createCardinalityConnectionDecorator(getDiagram(), c, rel.getOwnerAttributeName(), 0.0);
if (!UNI.equals(direction)) {
- imageCreator.createCardinalityConnectionDecorator(getDiagram(), c, rel.getInverseAttributeName(), 1.0);
+ imageCreator.createCardinalityConnectionDecorator(getDiagram(), c, rel.getInverseAttributeName(), 1.0);
}
}
+
+ private boolean isDerivedId(HashSet<String> annotations){
+ if(annotations.contains(JPAEditorConstants.ANNOTATION_ID) || annotations.contains(JPAEditorConstants.ANNOTATION_MAPS_ID)){
+ return true;
+ }
+ return false;
+ }
private void addOneToManyTextDecorator(FreeFormConnection c, IRelation rel) {
imageCreator.createCardinalityConnectionDecorator(getDiagram(), c, JPAEditorConstants.CARDINALITY_ZERO_ONE, 0.0);
@@ -230,15 +244,23 @@ public class AddRelationFeature extends AbstractAddFeature {
}
private void addManyToOneTextDecorator(FreeFormConnection c, RelDir direction, IRelation rel) {
+ boolean isOptional = false;
imageCreator.createCardinalityConnectionDecorator(getDiagram(), c, JPAEditorConstants.CARDINALITY_ZERO_N, 0.0);
imageCreator.createCardinalityConnectionDecorator(getDiagram(), c, rel.getOwnerAttributeName(), 0.0);
JavaPersistentAttribute owner = rel.getOwner().getAttributeNamed(rel.getOwnerAttributeName());
- JavaAttributeMapping mapping = owner.getMapping();
- ManyToOneAnnotation a = (ManyToOneAnnotation)mapping.getMappingAnnotation();
- if (a == null)
- return;
- Boolean optional = a.getOptional();
- boolean isOptional = (optional == null) ? true : optional.booleanValue();
+
+ HashSet<String> annotations = JpaArtifactFactory.instance().getAnnotationNames(owner);
+ if(isDerivedId(annotations)){
+ isOptional = false;
+ } else {
+ JavaAttributeMapping mapping = owner.getMapping();
+ ManyToOneAnnotation a = (ManyToOneAnnotation) mapping.getMappingAnnotation();
+ if (a == null)
+ return;
+ Boolean optional = a.getOptional();
+ isOptional = (optional == null) ? true : optional.booleanValue();
+ }
+
imageCreator.createCardinalityConnectionDecorator(getDiagram(), c, isOptional ?
JPAEditorConstants.CARDINALITY_ZERO_ONE :
JPAEditorConstants.CARDINALITY_ONE, 1.0);
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/ClickRemoveAttributeButtonFeature.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/ClickRemoveAttributeButtonFeature.java
index 506e4a4068..578b1b946b 100644
--- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/ClickRemoveAttributeButtonFeature.java
+++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/ClickRemoveAttributeButtonFeature.java
@@ -16,7 +16,11 @@
package org.eclipse.jpt.jpadiagrameditor.ui.internal.feature;
import java.text.MessageFormat;
+import java.util.HashSet;
+import java.util.ListIterator;
+import java.util.Set;
+import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.graphiti.features.IFeatureProvider;
import org.eclipse.graphiti.features.context.IContext;
import org.eclipse.graphiti.features.context.IDeleteContext;
@@ -24,9 +28,22 @@ import org.eclipse.graphiti.internal.features.context.impl.base.PictogramElement
import org.eclipse.graphiti.mm.algorithms.Text;
import org.eclipse.graphiti.mm.pictograms.ContainerShape;
import org.eclipse.graphiti.ui.features.DefaultDeleteFeature;
+import org.eclipse.jdt.core.IType;
+import org.eclipse.jpt.common.core.resource.java.Annotation;
+import org.eclipse.jpt.common.ui.internal.utility.SynchronousUiCommandExecutor;
+import org.eclipse.jpt.common.utility.command.Command;
+import org.eclipse.jpt.jpa.core.JpaProjectManager;
+import org.eclipse.jpt.jpa.core.context.PersistentType;
+import org.eclipse.jpt.jpa.core.context.java.JavaPersistentAttribute;
import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType;
+import org.eclipse.jpt.jpa.core.context.persistence.PersistenceUnit;
+import org.eclipse.jpt.jpa.core.jpa2.resource.java.MapsId2_0Annotation;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.JPADiagramEditorPlugin;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.command.DeleteAttributeCommand;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.i18n.JPAEditorMessages;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.IJPAEditorFeatureProvider;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JPAEditorConstants;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JPAEditorUtil;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JpaArtifactFactory;
@@ -43,9 +60,7 @@ public class ClickRemoveAttributeButtonFeature extends DefaultDeleteFeature {
protected String getQuestionToUser() {
return MessageFormat.format(JPAEditorMessages.ClickRemoveAttributeButtonFeature_deleteAttributeQuestion, new Object[] {attrName});
}
-
-
- @Override
+
public boolean canUndo(IContext context) {
return false;
}
@@ -58,9 +73,10 @@ public class ClickRemoveAttributeButtonFeature extends DefaultDeleteFeature {
}
private void deleteAttribute(ContainerShape pe, String attrName) {
- JavaPersistentType jpt = (JavaPersistentType)getFeatureProvider().getBusinessObjectForPictogramElement(pe.getContainer().getContainer());
+ JavaPersistentType jpt = (JavaPersistentType)getFeatureProvider().getBusinessObjectForPictogramElement(pe.getContainer().getContainer());
+ deleteFieldFromCompositePKClass(attrName, jpt);
JpaArtifactFactory.instance().deleteAttribute(jpt, attrName, getFeatureProvider());
- }
+ }
@Override
public void delete(IDeleteContext context) {
@@ -83,12 +99,13 @@ public class ClickRemoveAttributeButtonFeature extends DefaultDeleteFeature {
if (!getUserDecision(context)) {
return;
}
- }
+ }
preDelete(context);
if (textShape.getGraphicsAlgorithm() == null){
return;
- }
+ }
+
deleteAttribute(textShape, attrName);
}
@@ -122,5 +139,155 @@ public class ClickRemoveAttributeButtonFeature extends DefaultDeleteFeature {
return (IJPAEditorFeatureProvider)super.getFeatureProvider();
}
+ /**
+ * Returns a collection of java persistent types, that have an embedded id attribute of type, the given
+ * fully qualified name, or an id class annotation with the given fully qualified name.
+ * @param jpt - the java persistent type from which the attribute is originally deleted
+ * @param fqn - te fully qualified name of the composite primary key class
+ * @return a collection of java persistent types that uses the same composite primary key class.
+ */
+ private Set<JavaPersistentType> getAllJPTWithSameIDClassOrEmbeddedId(JavaPersistentType jpt, String fqn){
+ HashSet<JavaPersistentType> persistentTypes = new HashSet<JavaPersistentType>();
+ ListIterator<PersistenceUnit> lit = jpt.getJpaProject().getRootContextNode().getPersistenceXml().getRoot().getPersistenceUnits().iterator();
+ PersistenceUnit pu = lit.next();
+ for(PersistentType persistentType : pu.getPersistentTypes()){
+ if(!persistentType.equals(jpt) && ((hasSameEmbeddedId((JavaPersistentType) persistentType, fqn)) || hasSameIdClass((JavaPersistentType) persistentType, fqn))){
+ persistentTypes.add((JavaPersistentType) persistentType);
+ }
+ }
+ return persistentTypes;
+ }
+
+ /**
+ * Checks whether the given java persistent type has an id class annotation with the
+ * given fully qualified name.
+ * @param jpt - the java persistent type to be checked
+ * @param fqn - the fully qualified name of the id class
+ * @return true if the java persistent type has an id class annotation with the given
+ * fully qualified name, false otherwise.
+ */
+ private boolean hasSameIdClass(JavaPersistentType jpt, String fqn){
+ JpaArtifactFactory jpaFactory = JpaArtifactFactory.instance();
+ if(jpaFactory.hasIDClassAnnotation(jpt) && jpaFactory.getIdType(jpt).equals(fqn)){
+ return true;
+ }
+
+ return false;
+ }
+
+ /**
+ * Checks whether the given java persistent type has an embedded id attribute of type,
+ * the given fully qualified name.
+ * @param jpt - the java persistent type to be checked
+ * @param fqn - the fully qualified name of the embedded id attribute's type
+ * @return true, if the java persistent type has an embedded id attribute with the
+ * given fully qualified name.
+ */
+ private boolean hasSameEmbeddedId(JavaPersistentType jpt, String fqn){
+ JpaArtifactFactory jpaFactory = JpaArtifactFactory.instance();
+ for(JavaPersistentAttribute jpa : ((JavaPersistentType)jpt).getAttributes()){
+ if(jpaFactory.isEmbeddedId(jpa) && JPAEditorUtil.getAttributeTypeNameWithGenerics(jpa).equals(fqn)){
+ return true;
+ }
+ }
-} \ No newline at end of file
+ return false;
+ }
+
+ /**
+ * Checks whether the attribute which is going to be deleted is mapped as derived id.
+ * If yes, finds the helper attribute/field in the composite primary key class and if
+ * it is not used by another entity, deletes it too.
+ * @param attrName - the name of the attribute which is going to be deleted
+ * @param jpt - the java persistent type from which the attribute is originally deleted
+ */
+ private void deleteFieldFromCompositePKClass(String attrName,
+ JavaPersistentType jpt) {
+ JavaPersistentAttribute jpa = jpt.getAttributeNamed(attrName);
+ HashSet<String> annotations = JpaArtifactFactory.instance().getAnnotationNames(jpa);
+ if(annotations.contains(JPAEditorConstants.ANNOTATION_ONE_TO_ONE) || annotations.contains(JPAEditorConstants.ANNOTATION_MANY_TO_ONE)){
+ if(annotations.contains(JPAEditorConstants.ANNOTATION_ID)){
+ deleteFieldFromIdClassCompositePK(attrName, jpt);
+ } else if(annotations.contains(JPAEditorConstants.ANNOTATION_MAPS_ID)){
+ deleteFieldFromEmbeddedIDCompositePK(jpt, jpa);
+ }
+ }
+ }
+
+ /**
+ * By the maps id annotation value, find the attribute which has to be deleted from the
+ * embeddable class and deletes it.
+ * @param jpt - the java persistent type from which the attribute is originally deleted
+ * @param jpa - the attribute to be deleted
+ */
+ private void deleteFieldFromEmbeddedIDCompositePK(JavaPersistentType jpt,
+ JavaPersistentAttribute jpa) {
+ Annotation ann = jpa.getResourceAttribute().getAnnotation(MapsId2_0Annotation.ANNOTATION_NAME);
+ if(ann != null) {
+ String attribName = ((MapsId2_0Annotation)ann).getValue();
+ if(attribName == null)
+ return;
+ JpaArtifactFactory jpaFactory = JpaArtifactFactory.instance();
+ for(JavaPersistentAttribute jpa1 : jpt.getAttributes()){
+ if(jpaFactory.isEmbeddedId(jpa1)){
+ String fqn = JPAEditorUtil.getAttributeTypeNameWithGenerics(jpa1);
+ if(isDeleteAttributeAllowed(jpt, fqn)){
+ JavaPersistentType embeddedJPT = jpaFactory.getContextPersistentType(jpt.getJpaProject(), fqn);
+ jpaFactory.deleteAttribute(embeddedJPT, attribName, getFeatureProvider());
+ }
+ }
+ }
+ }
+ }
+
+ /**
+ * Deletes the field with the given name from the id class.
+ * @param attrName - the name of the field to be deleted
+ * @param jpt - the java persistent type from which the attribute is originally deleted
+ */
+ private void deleteFieldFromIdClassCompositePK(String attrName,
+ JavaPersistentType jpt) {
+ JpaArtifactFactory jpaFactory = JpaArtifactFactory.instance();
+ String idClassFQN = jpaFactory.getIdType(jpt);
+ if(idClassFQN != null && isDeleteAttributeAllowed(jpt, idClassFQN)){
+ IType type = jpaFactory.getType(jpt.getJpaProject().getJavaProject(), idClassFQN);
+ Command deleteAttributeCommand = new DeleteAttributeCommand(type.getCompilationUnit(), null, attrName, getFeatureProvider());
+ try {
+ getJpaProjectManager().execute(deleteAttributeCommand, SynchronousUiCommandExecutor.instance());
+ } catch (InterruptedException e) {
+ JPADiagramEditorPlugin.logError("Cannot delete attribute with name " + attrName, e); //$NON-NLS-1$
+ }
+ }
+ }
+
+ /**
+ * Finds all java persistent types, which either has attribute, mapped as embedded id and
+ * type, the given fully qualified name, or has an id class with the given fully qualified name.
+ * Then for each one java persistent type, checks whether it has an derived id. If at least one
+ * java persistent type has an derived id, then the method returns false. The method return true,
+ * if there isn't any java persistent type that has an derived identifier.
+ * @param jpt - the java persistent type, from which the attribute is originally deleted
+ * @param fqn - the fully qualified name of the composite primary key class
+ * @return true, if there isn't any java persistent type, that has a composite primary key class
+ * with the given fully qualified name and an derived identifiers; false - if there is at least
+ * one java persistent type with composite primary class, that has an derived id.
+ */
+ private boolean isDeleteAttributeAllowed(JavaPersistentType jpt, String fqn){
+ Set<JavaPersistentType> jpts = getAllJPTWithSameIDClassOrEmbeddedId(jpt, fqn);
+ for(JavaPersistentType perType : jpts){
+ for(JavaPersistentAttribute jpa : perType.getAttributes()){
+ HashSet<String> annotations = JpaArtifactFactory.instance().getAnnotationNames(jpa);
+ if((annotations.contains(JPAEditorConstants.ANNOTATION_ONE_TO_ONE) || annotations.contains(JPAEditorConstants.ANNOTATION_MANY_TO_ONE)) &&
+ (annotations.contains(JPAEditorConstants.ANNOTATION_ID) || annotations.contains(JPAEditorConstants.ANNOTATION_MAPS_ID))){
+ return false;
+ }
+
+ }
+ }
+ return true;
+ }
+
+ private JpaProjectManager getJpaProjectManager() {
+ return (JpaProjectManager) ResourcesPlugin.getWorkspace().getAdapter(JpaProjectManager.class);
+ }
+}
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateManyToManyRelationFeature.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateManyToManyRelationFeature.java
index 79d040fb7b..817d7eb5dd 100644
--- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateManyToManyRelationFeature.java
+++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateManyToManyRelationFeature.java
@@ -22,7 +22,7 @@ abstract class CreateManyToManyRelationFeature
extends CreateRelationFeature {
public CreateManyToManyRelationFeature(IJPAEditorFeatureProvider fp, String name, String description) {
- super(fp, name, description);
+ super(fp, name, description, false);
}
}
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateManyToOneBiDirRelationFeature.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateManyToOneBiDirRelationFeature.java
index dfcb7649e1..54cb460f80 100644
--- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateManyToOneBiDirRelationFeature.java
+++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateManyToOneBiDirRelationFeature.java
@@ -32,10 +32,10 @@ import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JpaArtifactFactory;
public class CreateManyToOneBiDirRelationFeature extends CreateManyToOneRelationFeature
implements ICreateBiDirRelationFeature {
-
- public CreateManyToOneBiDirRelationFeature(IJPAEditorFeatureProvider fp) {
+
+ public CreateManyToOneBiDirRelationFeature(IJPAEditorFeatureProvider fp, boolean isDerivedIdFeature) {
super(fp, JPAEditorMessages.CreateManyToOneBiDirRelationFeature_manyToOneBiDirFeatureName,
- JPAEditorMessages.CreateManyToOneBiDirRelationFeature_manyToOneBiDirFeatureDescription);
+ JPAEditorMessages.CreateManyToOneBiDirRelationFeature_manyToOneBiDirFeatureDescription, isDerivedIdFeature);
}
@Override
@@ -56,13 +56,15 @@ public class CreateManyToOneBiDirRelationFeature extends CreateManyToOneRelation
nameWithNonCapitalLetter2 = JPAEditorUtil.produceValidAttributeName(inverseAttributeName);
String inverseAttributeText = JPAEditorUtil.produceUniqueAttributeName(inverse, ownerAttributeText, nameWithNonCapitalLetter2);
- ManyToOneBiDirRelation rel = new ManyToOneBiDirRelation(fp, owner, inverse, ownerAttributeText, inverseAttributeText, true, embeddingEntity);
+ ManyToOneBiDirRelation rel = new ManyToOneBiDirRelation(fp, owner, inverse, ownerAttributeText, inverseAttributeText, true, embeddingEntity, isDerivedIdFeature);
return rel;
}
-
- @Override
- public String getCreateImageId() {
- return JPAEditorImageProvider.ICON_MANY_TO_ONE_2_DIR;
+
+ public String getCreateImageId() {
+ if(isDerivedIdFeature) {
+ return JPAEditorImageProvider.ICON_MANY_TO_ONE_2_KEY_DIR;
+ }
+ return JPAEditorImageProvider.ICON_MANY_TO_ONE_2_DIR;
}
@Override
@@ -84,4 +86,4 @@ public class CreateManyToOneBiDirRelationFeature extends CreateManyToOneRelation
}
return true;
}
-} \ No newline at end of file
+}
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateManyToOneRelationFeature.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateManyToOneRelationFeature.java
index 1f1c9eca1c..18c4e39bad 100644
--- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateManyToOneRelationFeature.java
+++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateManyToOneRelationFeature.java
@@ -20,8 +20,8 @@ import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.IJPAEditorFeaturePr
abstract class CreateManyToOneRelationFeature
extends CreateRelationFeature {
- public CreateManyToOneRelationFeature(IJPAEditorFeatureProvider fp, String name, String description) {
- super(fp, name, description);
+ public CreateManyToOneRelationFeature(IJPAEditorFeatureProvider fp, String name, String description, boolean isDerivedIdFeature) {
+ super(fp, name, description, isDerivedIdFeature);
}
}
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateManyToOneUniDirRelationFeature.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateManyToOneUniDirRelationFeature.java
index b48404558d..102366cd5b 100644
--- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateManyToOneUniDirRelationFeature.java
+++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateManyToOneUniDirRelationFeature.java
@@ -33,9 +33,10 @@ import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JpaArtifactFactory;
public class CreateManyToOneUniDirRelationFeature extends CreateManyToOneRelationFeature
implements ICreateUniDirRelationFeature {
- public CreateManyToOneUniDirRelationFeature(IJPAEditorFeatureProvider fp) {
+
+ public CreateManyToOneUniDirRelationFeature(IJPAEditorFeatureProvider fp, boolean isDerivedIdFeature) {
super(fp, JPAEditorMessages.CreateManyToOneUniDirRelationFeature_manyToOneUniDirFeatureName,
- JPAEditorMessages.CreateManyToOneUniDirRelationFeature_manyToOneUniDirFeatureDescription);
+ JPAEditorMessages.CreateManyToOneUniDirRelationFeature_manyToOneUniDirFeatureDescription, isDerivedIdFeature);
}
@Override
@@ -48,12 +49,14 @@ public class CreateManyToOneUniDirRelationFeature extends CreateManyToOneRelatio
if (JpaArtifactFactory.instance().isMethodAnnotated(owner))
nameWithNonCapitalLetter = JPAEditorUtil.produceValidAttributeName(attributeName);
String attributeText = JPAEditorUtil.produceUniqueAttributeName(owner, nameWithNonCapitalLetter);
- ManyToOneUniDirRelation relation = new ManyToOneUniDirRelation(fp, owner, inverse, attributeText, true);
+ ManyToOneUniDirRelation relation = new ManyToOneUniDirRelation(fp, owner, inverse, attributeText, true, isDerivedIdFeature);
return relation;
}
- @Override
- public String getCreateImageId() {
+ public String getCreateImageId() {
+ if(isDerivedIdFeature) {
+ return JPAEditorImageProvider.ICON_MANY_TO_ONE_1_KEY_DIR;
+ }
return JPAEditorImageProvider.ICON_MANY_TO_ONE_1_DIR;
}
@@ -77,4 +80,4 @@ public class CreateManyToOneUniDirRelationFeature extends CreateManyToOneRelatio
return true;
}
-} \ No newline at end of file
+}
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateOneToManyRelationFeature.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateOneToManyRelationFeature.java
index a448461134..58b58b455f 100644
--- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateOneToManyRelationFeature.java
+++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateOneToManyRelationFeature.java
@@ -27,7 +27,7 @@ abstract class CreateOneToManyRelationFeature
extends CreateRelationFeature {
public CreateOneToManyRelationFeature(IJPAEditorFeatureProvider fp, String name, String description) {
- super(fp, name, description);
+ super(fp, name, description, false);
}
/* (non-Javadoc)
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateOneToOneBiDirRelationFeature.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateOneToOneBiDirRelationFeature.java
index 98376cb9ff..b082a473eb 100644
--- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateOneToOneBiDirRelationFeature.java
+++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateOneToOneBiDirRelationFeature.java
@@ -32,10 +32,10 @@ import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JpaArtifactFactory;
public class CreateOneToOneBiDirRelationFeature extends CreateOneToOneRelationFeature
implements ICreateBiDirRelationFeature {
-
- public CreateOneToOneBiDirRelationFeature(IJPAEditorFeatureProvider fp) {
+
+ public CreateOneToOneBiDirRelationFeature(IJPAEditorFeatureProvider fp, boolean isDerivedIdFeature) {
super(fp, JPAEditorMessages.CreateOneToOneBiDirRelationFeature_oneToOneBiDirFeatureName,
- JPAEditorMessages.CreateOneToOneBiDirRelationFeature_oneToOneBiDirFeatureDescription);
+ JPAEditorMessages.CreateOneToOneBiDirRelationFeature_oneToOneBiDirFeatureDescription, isDerivedIdFeature);
}
@Override
@@ -56,12 +56,14 @@ public class CreateOneToOneBiDirRelationFeature extends CreateOneToOneRelationFe
nameWithNonCapitalLetter2 = JPAEditorUtil.produceValidAttributeName(inverseAttributeName);
String inverseAttributeText = JPAEditorUtil.produceUniqueAttributeName(inverse, ownerAttributeText, nameWithNonCapitalLetter2);
- OneToOneBiDirRelation rel = new OneToOneBiDirRelation(fp, owner, inverse, ownerAttributeText, inverseAttributeText, true, embeddingEntity);
+ OneToOneBiDirRelation rel = new OneToOneBiDirRelation(fp, owner, inverse, ownerAttributeText, inverseAttributeText, true, embeddingEntity, isDerivedIdFeature);
return rel;
}
- @Override
- public String getCreateImageId() {
+ public String getCreateImageId() {
+ if(isDerivedIdFeature) {
+ return JPAEditorImageProvider.ICON_ONE_TO_ONE_2_KEY_DIR;
+ }
return JPAEditorImageProvider.ICON_ONE_TO_ONE_2_DIR;
}
@@ -87,4 +89,4 @@ public class CreateOneToOneBiDirRelationFeature extends CreateOneToOneRelationFe
}
return true;
}
-} \ No newline at end of file
+}
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateOneToOneRelationFeature.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateOneToOneRelationFeature.java
index f4b9fea728..713aeef4c6 100644
--- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateOneToOneRelationFeature.java
+++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateOneToOneRelationFeature.java
@@ -20,7 +20,7 @@ import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.IJPAEditorFeaturePr
abstract class CreateOneToOneRelationFeature
extends CreateRelationFeature {
- public CreateOneToOneRelationFeature(IJPAEditorFeatureProvider fp, String name, String description) {
- super(fp, name, description);
+ public CreateOneToOneRelationFeature(IJPAEditorFeatureProvider fp, String name, String description , boolean isDerivedIdFeature) {
+ super(fp, name, description, isDerivedIdFeature);
}
}
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateOneToOneUniDirRelationFeature.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateOneToOneUniDirRelationFeature.java
index d38c03b3dd..bcc7831ba9 100644
--- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateOneToOneUniDirRelationFeature.java
+++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateOneToOneUniDirRelationFeature.java
@@ -32,10 +32,10 @@ import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JpaArtifactFactory;
public class CreateOneToOneUniDirRelationFeature extends CreateOneToOneRelationFeature
implements ICreateUniDirRelationFeature {
-
- public CreateOneToOneUniDirRelationFeature(IJPAEditorFeatureProvider fp) {
+
+ public CreateOneToOneUniDirRelationFeature(IJPAEditorFeatureProvider fp, boolean isDerivedIdFeature) {
super(fp, JPAEditorMessages.CreateOneToOneUniDirRelationFeature_oneToOneUniDirFeatureName,
- JPAEditorMessages.CreateOneToOneUniDirRelationFeature_oneToOneUniDirFeatureDescription);
+ JPAEditorMessages.CreateOneToOneUniDirRelationFeature_oneToOneUniDirFeatureDescription, isDerivedIdFeature);
}
@Override
@@ -50,12 +50,14 @@ public class CreateOneToOneUniDirRelationFeature extends CreateOneToOneRelationF
if (JpaArtifactFactory.instance().isMethodAnnotated(owner))
nameWithNonCapitalLetter = JPAEditorUtil.produceValidAttributeName(name);
String attribTxt = JPAEditorUtil.produceUniqueAttributeName(owner, nameWithNonCapitalLetter);
- OneToOneUniDirRelation res = new OneToOneUniDirRelation(fp, owner, inverse, attribTxt, true);
+ OneToOneUniDirRelation res = new OneToOneUniDirRelation(fp, owner, inverse, attribTxt, true, isDerivedIdFeature);
return res;
}
- @Override
- public String getCreateImageId() {
+ public String getCreateImageId() {
+ if(isDerivedIdFeature) {
+ return JPAEditorImageProvider.ICON_ONE_TO_ONE_1_KEY_DIR;
+ }
return JPAEditorImageProvider.ICON_ONE_TO_ONE_1_DIR;
}
@@ -81,4 +83,4 @@ public class CreateOneToOneUniDirRelationFeature extends CreateOneToOneRelationF
}
return true;
}
-} \ No newline at end of file
+}
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateRelationFeature.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateRelationFeature.java
index 33c637b503..d55b3ecd2a 100644
--- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateRelationFeature.java
+++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateRelationFeature.java
@@ -42,9 +42,12 @@ import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JpaArtifactFactory;
abstract public class CreateRelationFeature extends AbstractCreateConnectionFeature {
protected JavaPersistentType owner;
+
+ protected boolean isDerivedIdFeature;
- public CreateRelationFeature(IJPAEditorFeatureProvider fp, String name, String description) {
+ public CreateRelationFeature(IJPAEditorFeatureProvider fp, String name, String description, boolean isDerivedIdFeature) {
super(fp, name, description);
+ this.isDerivedIdFeature = isDerivedIdFeature;
}
public boolean canCreate(ICreateConnectionContext context) {
@@ -63,6 +66,10 @@ abstract public class CreateRelationFeature extends AbstractCreateConnectionFeat
if ((this instanceof ICreateBiDirRelationFeature) &&
(JpaArtifactFactory.instance().hasMappedSuperclassAnnotation(owner)))
return false;
+ if(isDerivedIdFeature && (!JpaArtifactFactory.instance().hasEntityAnnotation(owner)
+ || !JpaArtifactFactory.instance().hasEntityAnnotation(inverse))){
+ return false;
+ }
return true;
}
@@ -183,14 +190,14 @@ abstract public class CreateRelationFeature extends AbstractCreateConnectionFeat
disableAllJPTsThatAreNotEntities(unit);
}
else if(JpaArtifactFactory.instance().hasMappedSuperclassAnnotation(owner)){
- if (this instanceof ICreateBiDirRelationFeature){
+ if (isDerivedIdFeature || (this instanceof ICreateBiDirRelationFeature)){
disableAllPersistentTypes(unit);
} else {
disableAllJPTsThatAreNotEntities(unit);
}
}
else if(JpaArtifactFactory.instance().hasEmbeddableAnnotation(owner)) {
- if(!isRelationshipPossible() || JPAEditorUtil.checkJPAFacetVersion(owner.getJpaProject(), JPAEditorUtil.JPA_PROJECT_FACET_10)) {
+ if(isDerivedIdFeature || !isRelationshipPossible() || JPAEditorUtil.checkJPAFacetVersion(owner.getJpaProject(), JPAEditorUtil.JPA_PROJECT_FACET_10)) {
disableAllPersistentTypes(unit);
} else {
disableAllJPTsThatAreNotEntities(unit);
@@ -240,12 +247,12 @@ abstract public class CreateRelationFeature extends AbstractCreateConnectionFeat
PersistenceUnit unit = project.getRootContextNode().getPersistenceXml().
getRoot().getPersistenceUnits().iterator().next();
boolean isJPA10Project = JPAEditorUtil.checkJPAFacetVersion(ModelIntegrationUtil.getProjectByDiagram(getDiagram().getName()), JPAEditorUtil.JPA_PROJECT_FACET_10);
- if(!isJPA10Project)
- return;
+
for (ClassRef classRef : unit.getClassRefs()) {
if (classRef.getJavaPersistentType() != null) {
final JavaPersistentType jpt = classRef.getJavaPersistentType();
- if(JpaArtifactFactory.instance().hasEmbeddableAnnotation(jpt)){
+ if((isJPA10Project && JpaArtifactFactory.instance().hasEmbeddableAnnotation(jpt))
+ || (isDerivedIdFeature && !JpaArtifactFactory.instance().hasEntityAnnotation(jpt))){
getFeatureProvider().setGrayColor(jpt);
}
@@ -267,4 +274,4 @@ abstract public class CreateRelationFeature extends AbstractCreateConnectionFeat
}
return false;
}
-} \ No newline at end of file
+}
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/GraphicalAddAttributeFeature.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/GraphicalAddAttributeFeature.java
index 0889fd5f9b..ce12bb11bb 100644
--- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/GraphicalAddAttributeFeature.java
+++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/GraphicalAddAttributeFeature.java
@@ -74,12 +74,14 @@ public class GraphicalAddAttributeFeature extends AbstractAddShapeFeature {
private ContainerShape addAttributeToProperlyShape(ContainerShape entityShape, String txt, HashSet<String> annots,
ContainerShape primaryShape, ContainerShape relationShape, ContainerShape basicShape) {
ContainerShape textShape = null;
- if (annots.contains(JPAEditorConstants.ANNOTATION_ID) || annots.contains(JPAEditorConstants.ANNOTATION_EMBEDDED_ID)) {
+ if (annots.contains(JPAEditorConstants.ANNOTATION_ID) || annots.contains(JPAEditorConstants.ANNOTATION_EMBEDDED_ID)
+ || annots.contains(JPAEditorConstants.ANNOTATION_MAPS_ID)) {
textShape = addAttributeToShape(entityShape, txt, annots, primaryShape);
- } else if (annots.contains(JPAEditorConstants.ANNOTATION_MANY_TO_MANY)
+ } else if (!annots.contains(JPAEditorConstants.ANNOTATION_ID) && !annots.contains(JPAEditorConstants.ANNOTATION_MAPS_ID)
+ && (annots.contains(JPAEditorConstants.ANNOTATION_MANY_TO_MANY)
|| annots.contains(JPAEditorConstants.ANNOTATION_MANY_TO_ONE)
|| annots.contains(JPAEditorConstants.ANNOTATION_ONE_TO_MANY)
- || annots.contains(JPAEditorConstants.ANNOTATION_ONE_TO_ONE)) {
+ || annots.contains(JPAEditorConstants.ANNOTATION_ONE_TO_ONE))) {
textShape = addAttributeToShape(entityShape, txt, annots, relationShape);
} else {
textShape = addAttributeToShape(entityShape, txt, annots, basicShape);
@@ -142,4 +144,4 @@ public class GraphicalAddAttributeFeature extends AbstractAddShapeFeature {
public boolean canAdd(IAddContext context) {
return false;
}
-} \ No newline at end of file
+}
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/RefactorEntityFeature.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/RefactorEntityFeature.java
index 40a65fbc7a..4d5e9543da 100644
--- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/RefactorEntityFeature.java
+++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/RefactorEntityFeature.java
@@ -21,6 +21,7 @@ import java.util.Iterator;
import java.util.Set;
import java.util.concurrent.Semaphore;
import java.util.concurrent.TimeUnit;
+
import org.eclipse.emf.transaction.RecordingCommand;
import org.eclipse.emf.transaction.TransactionalEditingDomain;
import org.eclipse.emf.transaction.util.TransactionUtil;
@@ -72,7 +73,7 @@ public abstract class RefactorEntityFeature extends AbstractCustomFeature {
protected Set<JavaPersistentAttribute> ats = null;
protected boolean hasNameAnnotation = false;
-
+
public RefactorEntityFeature(IFeatureProvider fp) {
super(fp);
}
@@ -111,10 +112,10 @@ public abstract class RefactorEntityFeature extends AbstractCustomFeature {
}
public void execute(ICustomContext context, SelectionDispatchAction action) {
- final Shape pict = (Shape)context.getInnerPictogramElement();
+ PictogramElement pe = context.getInnerPictogramElement();
+ final ContainerShape pict = ((Shape)pe).getContainer();
+ JavaPersistentType jpt = (JavaPersistentType)getBusinessObjectForPictogramElement(pict);
- JavaPersistentType jpt = (JavaPersistentType)getFeatureProvider().
- getBusinessObjectForPictogramElement(pict);
ICompilationUnit cu = getFeatureProvider().getCompilationUnit(jpt);
StructuredSelection sel = new StructuredSelection(cu);
@@ -145,7 +146,7 @@ public abstract class RefactorEntityFeature extends AbstractCustomFeature {
protected void doExecute() {
remapEntity(oldName, pict, pu, rename, lsnr, dot, getFeatureProvider());
}
- });
+ });
}
public void execute(ICustomContext context, String newName, ICompilationUnit cu, JavaPersistentType jpt) {
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/i18n/JPAEditorMessages.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/i18n/JPAEditorMessages.java
index 769824a5b6..1c90f37ac1 100644
--- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/i18n/JPAEditorMessages.java
+++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/i18n/JPAEditorMessages.java
@@ -187,6 +187,8 @@ public class JPAEditorMessages extends NLS {
public static String JPAEditorToolBehaviorProvider_CreateElementCollectionAttributeButtonLabel;
public static String JPAEditorToolBehaviorProvider_CreateElementCollectionAttributeButtonDescription;
+
+ public static String JPAEditorToolBehaviorProvider_DerivedIdentifiersPalleteTitle;
public static String JPAEditorToolBehaviorProvider_expandAttrMenuItem;
public static String JPAEditorToolBehaviorProvider_expandAttrMenuItemDescr;
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/i18n/messages.properties b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/i18n/messages.properties
index 19919ccc8b..c6d1c982ee 100644
--- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/i18n/messages.properties
+++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/i18n/messages.properties
@@ -154,6 +154,7 @@ JPAEditorToolBehaviorProvider_openMiniatureViewDesc=Open the Miniature view to d
JPAEditorToolBehaviorProvider_CompositionPaletteName=Composition
JPAEditorToolBehaviorProvider_CreateElementCollectionAttributeButtonLabel=Create Collection Attribute
JPAEditorToolBehaviorProvider_CreateElementCollectionAttributeButtonDescription=Create a new attribute of a basic collection type in the persistent type.
+JPAEditorToolBehaviorProvider_DerivedIdentifiersPalleteTitle=Derived Identifiers
JPAEditorToolBehaviorProvider_expandAttrMenuItem=Expand Attributes Group
JPAEditorToolBehaviorProvider_expandAttrMenuItemDescr=Expand the attributes group.
JPAEditorToolBehaviorProvider_expandCompartToolTip=Double click to expand "{0}" attributes group.
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/provider/JPAEditorFeatureProvider.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/provider/JPAEditorFeatureProvider.java
index ba097b2d6a..011c46a322 100644
--- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/provider/JPAEditorFeatureProvider.java
+++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/provider/JPAEditorFeatureProvider.java
@@ -414,11 +414,11 @@ public class JPAEditorFeatureProvider extends DefaultFeatureProvider implements
@Override
public ICreateConnectionFeature[] getCreateConnectionFeatures() {
return new ICreateConnectionFeature[] {
- new CreateOneToOneUniDirRelationFeature(this),
- new CreateOneToOneBiDirRelationFeature(this),
+ new CreateOneToOneUniDirRelationFeature(this, false),
+ new CreateOneToOneBiDirRelationFeature(this, false),
new CreateOneToManyUniDirRelationFeature(this),
- new CreateManyToOneUniDirRelationFeature(this),
- new CreateManyToOneBiDirRelationFeature(this),
+ new CreateManyToOneUniDirRelationFeature(this, false),
+ new CreateManyToOneBiDirRelationFeature(this, false),
new CreateManyToManyUniDirRelationFeature(this),
new CreateManyToManyBiDirRelationFeature(this)
};
@@ -635,7 +635,7 @@ public class JPAEditorFeatureProvider extends DefaultFeatureProvider implements
}
public boolean doesEmbeddedRelationExist(JavaPersistentType embeddable, JavaPersistentType embeddingEntity, String embeddedAttributeName, HasReferenceType relType){
- String id = HasReferanceRelation.generateId(embeddable, embeddingEntity, embeddedAttributeName, relType);
+ String id = HasReferanceRelation.generateId(embeddingEntity, embeddable, embeddedAttributeName, relType);
return (getBusinessObjectForKey(id) != null);
}
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/provider/JPAEditorImageProvider.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/provider/JPAEditorImageProvider.java
index e6291053ee..19d89a5130 100644
--- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/provider/JPAEditorImageProvider.java
+++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/provider/JPAEditorImageProvider.java
@@ -31,6 +31,8 @@ public class JPAEditorImageProvider extends AbstractImageProvider {
public static final String ADD_EMBEDDABLE = PREFIX + "add_embeddable"; //$NON-NLS-1$
public static final String PRIMARY_KEY = PREFIX + "pk"; //$NON-NLS-1$
+ public static final String ONE_TO_ONE_PRIMARY_KEY = PREFIX + "one_to_one_pk"; //$NON-NLS-1$
+ public static final String MANY_TO_ONE_PRIMARY_KEY = PREFIX + "many_to_one_pk"; //$NON-NLS-1$
public static final String ICON_BASIC = PREFIX + "field"; //$NON-NLS-1$
public static final String ADD_ATTRIBUTE = PREFIX + "add_attribute"; //$NON-NLS-1$
public static final String ADD_ELEMENT_COLLECTION = PREFIX + "add_element-collection.gif"; //$NON-NLS-1$
@@ -47,6 +49,10 @@ public class JPAEditorImageProvider extends AbstractImageProvider {
public static final String ICON_UNMAPPED = PREFIX + "unmapped"; //$NON-NLS-1$
public static final String ICON_DERIVE_JPT = PREFIX + "derive_jpt"; //$NON-NLS-1$
+ public static final String ICON_ONE_TO_ONE_1_KEY_DIR = PREFIX + "one_to_one_1_key_relation"; //$NON-NLS-1$
+ public static final String ICON_ONE_TO_ONE_2_KEY_DIR = PREFIX + "one_to_one_2_key_relation"; //$NON-NLS-1$
+ public static final String ICON_MANY_TO_ONE_1_KEY_DIR = PREFIX + "many_to_one_1_key_relation"; //$NON-NLS-1$
+ public static final String ICON_MANY_TO_ONE_2_KEY_DIR = PREFIX + "many_to_one_2_key_relation"; //$NON-NLS-1$
public static final String ICON_ONE_TO_ONE_1_DIR = PREFIX + "one_to_one_1_dir_relation"; //$NON-NLS-1$
public static final String ICON_ONE_TO_MANY_1_DIR = PREFIX + "one_to_many_1_dir_relation"; //$NON-NLS-1$
@@ -79,6 +85,9 @@ public class JPAEditorImageProvider extends AbstractImageProvider {
addImageFilePath(ADD_MAPPED_SUPERCLASS, ROOT_FOLDER_FOR_IMG + "ent/add_mapped-superclass.gif"); //$NON-NLS-1$
addImageFilePath(ADD_EMBEDDABLE, ROOT_FOLDER_FOR_IMG + "ent/add_embeddable.gif"); //$NON-NLS-1$
addImageFilePath(PRIMARY_KEY, ROOT_FOLDER_FOR_IMG + "ent/id.gif"); //$NON-NLS-1$
+ addImageFilePath(ONE_TO_ONE_PRIMARY_KEY, ROOT_FOLDER_FOR_IMG + "ent/one-to-one-key.gif"); //$NON-NLS-1$
+ addImageFilePath(MANY_TO_ONE_PRIMARY_KEY, ROOT_FOLDER_FOR_IMG + "ent/many-to-one-key.gif"); //$NON-NLS-1$
+
addImageFilePath(ADD_ATTRIBUTE, ROOT_FOLDER_FOR_IMG + "ent/add_attribute.gif"); //$NON-NLS-1$
addImageFilePath(ADD_ELEMENT_COLLECTION, ROOT_FOLDER_FOR_IMG + "ent/add_element-collection.gif"); //$NON-NLS-1$
addImageFilePath(REMOVE_ATTRIBUTE, ROOT_FOLDER_FOR_IMG + "ent/remove_attribute.gif"); //$NON-NLS-1$
@@ -93,6 +102,11 @@ public class JPAEditorImageProvider extends AbstractImageProvider {
addImageFilePath(ICON_ELEMENT_COLLECTION, ROOT_FOLDER_FOR_IMG + "ent/element-collection.gif"); //$NON-NLS-1$
addImageFilePath(ICON_UNMAPPED, ROOT_FOLDER_FOR_IMG + "ent/null-attribute-mapping.gif"); //$NON-NLS-1$
addImageFilePath(ICON_DERIVE_JPT, ROOT_FOLDER_FOR_IMG + "ent/derive_jpt.gif"); //$NON-NLS-1$
+
+ addImageFilePath(ICON_ONE_TO_ONE_1_KEY_DIR, ROOT_FOLDER_FOR_IMG + "ent/one-to-one-1-key.gif"); //$NON-NLS-1$
+ addImageFilePath(ICON_ONE_TO_ONE_2_KEY_DIR, ROOT_FOLDER_FOR_IMG + "ent/one-to-one-2-key.gif"); //$NON-NLS-1$
+ addImageFilePath(ICON_MANY_TO_ONE_1_KEY_DIR, ROOT_FOLDER_FOR_IMG + "ent/many-to-one-1-key.gif"); //$NON-NLS-1$
+ addImageFilePath(ICON_MANY_TO_ONE_2_KEY_DIR, ROOT_FOLDER_FOR_IMG + "ent/many-to-one-2-key.gif"); //$NON-NLS-1$
addImageFilePath(ICON_ONE_TO_ONE_1_DIR, ROOT_FOLDER_FOR_IMG + "ent/one-to-one-1-dir.gif"); //$NON-NLS-1$
addImageFilePath(ICON_ONE_TO_MANY_1_DIR, ROOT_FOLDER_FOR_IMG + "ent/one-to-many-1-dir.gif"); //$NON-NLS-1$
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/provider/JPAEditorToolBehaviorProvider.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/provider/JPAEditorToolBehaviorProvider.java
index 4511839cea..6423eb1085 100644
--- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/provider/JPAEditorToolBehaviorProvider.java
+++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/provider/JPAEditorToolBehaviorProvider.java
@@ -73,6 +73,10 @@ import org.eclipse.jpt.jpadiagrameditor.ui.internal.feature.CollapseCompartmentS
import org.eclipse.jpt.jpadiagrameditor.ui.internal.feature.CollapseEntityFeature;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.feature.CreateInheritedEntityFeature;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.feature.CreateIsARelationFeature;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.feature.CreateManyToOneBiDirRelationFeature;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.feature.CreateManyToOneUniDirRelationFeature;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.feature.CreateOneToOneBiDirRelationFeature;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.feature.CreateOneToOneUniDirRelationFeature;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.feature.DeleteJPAEntityFeature;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.feature.DiscardAndRemoveAllEntitiesFeature;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.feature.EmbedCollectionOfObjectsFeature;
@@ -258,14 +262,58 @@ public class JPAEditorToolBehaviorProvider extends DefaultToolBehaviorProvider {
createInheritancePaletteSection(ret, superCompartments);
+ if(!JPAEditorUtil.checkJPAFacetVersion(getTargetJPAProject(), JPAEditorUtil.JPA_PROJECT_FACET_10)) {
+ createDerivedIdentifiersPalleteSection(ret, superCompartments);
+ }
+
createCompositionPaletteSection(ret, superCompartments);
return ret.toArray(new IPaletteCompartmentEntry[ret.size()]);
}
+
+ private void createDerivedIdentifiersPalleteSection(List<IPaletteCompartmentEntry> ret,
+ IPaletteCompartmentEntry[] superCompartments){
+ PaletteCompartmentEntry compositionEnt = new PaletteCompartmentEntry(JPAEditorMessages.JPAEditorToolBehaviorProvider_DerivedIdentifiersPalleteTitle, superCompartments[1].getIconId());
+
+ CreateOneToOneUniDirRelationFeature oneToOneUniDirPkFt = new CreateOneToOneUniDirRelationFeature((IJPAEditorFeatureProvider) this.getFeatureProvider(), true);
+ ConnectionCreationToolEntry oneToOneUniDirPkToolEntry = new ConnectionCreationToolEntry(oneToOneUniDirPkFt.getCreateName(),
+ oneToOneUniDirPkFt.getCreateDescription(), oneToOneUniDirPkFt.getCreateImageId(), oneToOneUniDirPkFt.getCreateLargeImageId());
+ oneToOneUniDirPkToolEntry.addCreateConnectionFeature(oneToOneUniDirPkFt);
+ compositionEnt.addToolEntry(oneToOneUniDirPkToolEntry);
+
+ CreateOneToOneBiDirRelationFeature oneToOneBiDirPkFt = new CreateOneToOneBiDirRelationFeature((IJPAEditorFeatureProvider) this.getFeatureProvider(), true);
+ ConnectionCreationToolEntry oneToOneBiDirPkToolEntry = new ConnectionCreationToolEntry(oneToOneBiDirPkFt.getCreateName(),
+ oneToOneBiDirPkFt.getCreateDescription(), oneToOneBiDirPkFt.getCreateImageId(), oneToOneBiDirPkFt.getCreateLargeImageId());
+ oneToOneBiDirPkToolEntry.addCreateConnectionFeature(oneToOneBiDirPkFt);
+ compositionEnt.addToolEntry(oneToOneBiDirPkToolEntry);
+
+ CreateManyToOneUniDirRelationFeature manyToOneUniDirPkFt = new CreateManyToOneUniDirRelationFeature((IJPAEditorFeatureProvider) this.getFeatureProvider(), true);
+ ConnectionCreationToolEntry manyToOneUniDirPkToolEntry = new ConnectionCreationToolEntry(manyToOneUniDirPkFt.getCreateName(),
+ manyToOneUniDirPkFt.getCreateDescription(), manyToOneUniDirPkFt.getCreateImageId(), manyToOneUniDirPkFt.getCreateLargeImageId());
+ manyToOneUniDirPkToolEntry.addCreateConnectionFeature(manyToOneUniDirPkFt);
+ compositionEnt.addToolEntry(manyToOneUniDirPkToolEntry);
+
+ CreateManyToOneBiDirRelationFeature manyToOneBiDirPkFt = new CreateManyToOneBiDirRelationFeature((IJPAEditorFeatureProvider) this.getFeatureProvider(), true);
+ ConnectionCreationToolEntry manyToOneBiDirPkToolEntry = new ConnectionCreationToolEntry(manyToOneBiDirPkFt.getCreateName(),
+ manyToOneBiDirPkFt.getCreateDescription(), manyToOneBiDirPkFt.getCreateImageId(), manyToOneBiDirPkFt.getCreateLargeImageId());
+ manyToOneBiDirPkToolEntry.addCreateConnectionFeature(manyToOneBiDirPkFt);
+ compositionEnt.addToolEntry(manyToOneBiDirPkToolEntry);
+
+ ret.add(2, compositionEnt);
+ }
private void createCompositionPaletteSection(
List<IPaletteCompartmentEntry> ret,
IPaletteCompartmentEntry[] superCompartments) {
+ int index;
+ boolean isJPA10Project = JPAEditorUtil.checkJPAFacetVersion(getTargetJPAProject(), JPAEditorUtil.JPA_PROJECT_FACET_10);
+
+ if(isJPA10Project) {
+ index = 2;
+ } else {
+ index = 3;
+ }
+
PaletteCompartmentEntry compositionEnt = new PaletteCompartmentEntry(JPAEditorMessages.JPAEditorToolBehaviorProvider_CompositionPaletteName, superCompartments[1].getIconId());
EmbedSingleObjectFeature embedObjectFt = new EmbedSingleObjectFeature(this.getFeatureProvider());
@@ -274,7 +322,7 @@ public class JPAEditorToolBehaviorProvider extends DefaultToolBehaviorProvider {
isEmbeddedObjectToolEntry.addCreateConnectionFeature(embedObjectFt);
compositionEnt.addToolEntry(isEmbeddedObjectToolEntry);
- if(!JPAEditorUtil.checkJPAFacetVersion(getTargetJPAProject(), JPAEditorUtil.JPA_PROJECT_FACET_10)) {
+ if(!isJPA10Project) {
EmbedCollectionOfObjectsFeature embedCollectionFt = new EmbedCollectionOfObjectsFeature(this.getFeatureProvider());
ConnectionCreationToolEntry isEmbeddedCollectionToolEntry = new ConnectionCreationToolEntry(embedCollectionFt.getCreateName(),
embedCollectionFt.getCreateDescription(), embedCollectionFt.getCreateImageId(), embedCollectionFt.getCreateLargeImageId());
@@ -282,7 +330,7 @@ public class JPAEditorToolBehaviorProvider extends DefaultToolBehaviorProvider {
compositionEnt.addToolEntry(isEmbeddedCollectionToolEntry);
}
- ret.add(2, compositionEnt);
+ ret.add(index, compositionEnt);
}
private JpaProject getTargetJPAProject() {
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/ManyToOneBiDirRelation.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/ManyToOneBiDirRelation.java
index 03cbc2c6fd..90fe21d886 100644
--- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/ManyToOneBiDirRelation.java
+++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/ManyToOneBiDirRelation.java
@@ -29,12 +29,13 @@ public class ManyToOneBiDirRelation extends ManyToOneRelation implements IBidir
JavaPersistentType inverse,
String ownerAttributeName,
String inverseAttributeName,
- boolean createAttribs, JavaPersistentType embeddingEntity) {
+ boolean createAttribs, JavaPersistentType embeddingEntity,
+ boolean isDerivedIdFeature) {
super(owner, inverse);
this.ownerAttributeName = ownerAttributeName;
this.inverseAttributeName = inverseAttributeName;
if (createAttribs)
- createRelation(fp, embeddingEntity);
+ createRelation(fp, embeddingEntity, isDerivedIdFeature);
}
@@ -58,9 +59,12 @@ public class ManyToOneBiDirRelation extends ManyToOneRelation implements IBidir
this.inverseAnnotatedAttribute = inverseAnnotatedAttribute;
}
- private void createRelation(IJPAEditorFeatureProvider fp, JavaPersistentType embeddingEntity) {
+ private void createRelation(IJPAEditorFeatureProvider fp, JavaPersistentType embeddingEntity, boolean isDerivedIdFeature) {
ownerAnnotatedAttribute = JPAEditorUtil.addAnnotatedAttribute(fp, owner, inverse, false, null);
-
+ if(isDerivedIdFeature){
+ JpaArtifactFactory.instance().calculateDerivedIdAnnotation(owner, inverse, ownerAnnotatedAttribute);
+ }
+
boolean isMap = JPADiagramPropertyPage.isMapType(owner.getJpaProject().getProject());
String mapKeyType = getMapKeyType(isMap, owner, embeddingEntity);
if(JpaArtifactFactory.instance().hasEmbeddableAnnotation(owner)){
@@ -70,7 +74,7 @@ public class ManyToOneBiDirRelation extends ManyToOneRelation implements IBidir
inverseAnnotatedAttribute = JPAEditorUtil.addAnnotatedAttribute(fp, inverse, owner, true, mapKeyType);
}
JpaArtifactFactory.instance().addManyToOneBidirectionalRelation(fp, owner, ownerAnnotatedAttribute, inverse, inverseAnnotatedAttribute, isMap);
- }
+ }
@Override
public RelDir getRelDir() {
@@ -83,4 +87,5 @@ public class ManyToOneBiDirRelation extends ManyToOneRelation implements IBidir
}
return isMap ? JpaArtifactFactory.instance().getIdType(jpt) : null;
}
-} \ No newline at end of file
+
+}
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/ManyToOneUniDirRelation.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/ManyToOneUniDirRelation.java
index 778cbc0b99..1823add090 100644
--- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/ManyToOneUniDirRelation.java
+++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/ManyToOneUniDirRelation.java
@@ -27,11 +27,11 @@ public class ManyToOneUniDirRelation extends ManyToOneRelation implements IUnidi
public ManyToOneUniDirRelation(IJPAEditorFeatureProvider fp, JavaPersistentType owner,
JavaPersistentType inverse,
String ownerAttributeName,
- boolean createAttribs) {
+ boolean createAttribs, boolean isDerivedIdFeature) {
super(owner, inverse);
this.ownerAttributeName = ownerAttributeName;
if (createAttribs)
- createRelation(fp);
+ createRelation(fp, isDerivedIdFeature);
}
public JavaPersistentAttribute getAnnotatedAttribute() {
@@ -42,8 +42,11 @@ public class ManyToOneUniDirRelation extends ManyToOneRelation implements IUnidi
this.ownerAnnotatedAttribute = annotatedAttribute;
}
- private void createRelation(IJPAEditorFeatureProvider fp) {
+ private void createRelation(IJPAEditorFeatureProvider fp, boolean isDerivedIdFeature) {
ownerAnnotatedAttribute = JPAEditorUtil.addAnnotatedAttribute(fp, owner, inverse, false, null);
+ if(isDerivedIdFeature){
+ JpaArtifactFactory.instance().calculateDerivedIdAnnotation(owner, inverse, ownerAnnotatedAttribute);
+ }
JpaArtifactFactory.instance().addManyToOneUnidirectionalRelation(fp, owner, ownerAnnotatedAttribute);
}
@@ -53,4 +56,4 @@ public class ManyToOneUniDirRelation extends ManyToOneRelation implements IUnidi
return RelDir.UNI;
}
-} \ No newline at end of file
+}
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/OneToOneBiDirRelation.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/OneToOneBiDirRelation.java
index 79ae9c0522..264c8adb19 100644
--- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/OneToOneBiDirRelation.java
+++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/OneToOneBiDirRelation.java
@@ -27,12 +27,13 @@ public class OneToOneBiDirRelation extends OneToOneRelation implements IBidirect
JavaPersistentType inverse,
String ownerAttributeName,
String inverseAttributeName,
- boolean createAttribs, JavaPersistentType embeddingEntity) {
+ boolean createAttribs, JavaPersistentType embeddingEntity,
+ boolean isDerivedIdFeature) {
super(owner, inverse);
this.ownerAttributeName = ownerAttributeName;
this.inverseAttributeName = inverseAttributeName;
if (createAttribs)
- createRelation(fp, embeddingEntity);
+ createRelation(fp, embeddingEntity, isDerivedIdFeature);
}
@Override
@@ -57,8 +58,11 @@ public class OneToOneBiDirRelation extends OneToOneRelation implements IBidirect
this.inverseAnnotatedAttribute = inverseAnnotatedAttribute;
}
- private void createRelation(IJPAEditorFeatureProvider fp, JavaPersistentType embeddingEntity) {
+ private void createRelation(IJPAEditorFeatureProvider fp, JavaPersistentType embeddingEntity, boolean isDerivedIdFeature) {
ownerAnnotatedAttribute = JPAEditorUtil.addAnnotatedAttribute(fp, owner, inverse, false, null);
+ if(isDerivedIdFeature){
+ JpaArtifactFactory.instance().calculateDerivedIdAnnotation(owner, inverse, ownerAnnotatedAttribute);
+ }
if(JpaArtifactFactory.instance().hasEmbeddableAnnotation(owner)){
inverseAnnotatedAttribute = JPAEditorUtil.addAnnotatedAttribute(fp, inverse, embeddingEntity, false, null);
@@ -72,4 +76,4 @@ public class OneToOneBiDirRelation extends OneToOneRelation implements IBidirect
public RelDir getRelDir() {
return RelDir.BI;
}
-} \ No newline at end of file
+}
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/OneToOneUniDirRelation.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/OneToOneUniDirRelation.java
index 6371bbfd84..02e45e5293 100644
--- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/OneToOneUniDirRelation.java
+++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/OneToOneUniDirRelation.java
@@ -27,11 +27,11 @@ public class OneToOneUniDirRelation extends OneToOneRelation implements IUnidire
public OneToOneUniDirRelation(IJPAEditorFeatureProvider fp, JavaPersistentType owner,
JavaPersistentType inverse,
String ownerAttributeName,
- boolean createAttribs) {
+ boolean createAttribs, boolean isDerivedIdFeature) {
super(owner, inverse);
this.ownerAttributeName = ownerAttributeName;
if (createAttribs)
- createRelation(fp);
+ createRelation(fp, isDerivedIdFeature);
}
public JavaPersistentAttribute getAnnotatedAttribute() {
@@ -42,8 +42,11 @@ public class OneToOneUniDirRelation extends OneToOneRelation implements IUnidire
this.ownerAnnotatedAttribute = annotatedAttribute;
}
- private void createRelation(IJPAEditorFeatureProvider fp) {
+ private void createRelation(IJPAEditorFeatureProvider fp, boolean isDerivedIdFeature) {
ownerAnnotatedAttribute = JPAEditorUtil.addAnnotatedAttribute(fp, owner, inverse, false, null);
+ if(isDerivedIdFeature){
+ JpaArtifactFactory.instance().calculateDerivedIdAnnotation(owner, inverse, ownerAnnotatedAttribute);
+ }
JpaArtifactFactory.instance().addOneToOneUnidirectionalRelation(fp, owner, ownerAnnotatedAttribute);
}
@@ -52,4 +55,4 @@ public class OneToOneUniDirRelation extends OneToOneRelation implements IUnidire
return RelDir.UNI;
}
-} \ No newline at end of file
+}
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/JPAEditorConstants.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/JPAEditorConstants.java
index 7e76a45bed..80e9c85179 100644
--- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/JPAEditorConstants.java
+++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/JPAEditorConstants.java
@@ -148,6 +148,7 @@ public class JPAEditorConstants {
public final static String ANNOTATION_ELEMENT_COLLECTION = "ElementCollection"; //$NON-NLS-1$
public final static String ANNOTATION_EMBEDDED_ID = "EmbeddedId"; //$NON-NLS-1$
public final static String ANNOTATION_TRANSIENT = "Transient"; //$NON-NLS-1$
+ public final static String ANNOTATION_MAPS_ID = "MapsId"; //$NON-NLS-1$
public static final int RELATION_TYPE_UNIDIRECTIONAL = 1;
public static final int RELATION_TYPE_BIDIRECTIONAL = 2;
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/JPAEditorUtil.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/JPAEditorUtil.java
index c7408ae0db..76a314f39f 100644
--- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/JPAEditorUtil.java
+++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/JPAEditorUtil.java
@@ -405,14 +405,24 @@ public class JPAEditorUtil {
Image icon = null;
if ((annotations == null) || (annotations.size() == 0) || annotations.contains(JPAEditorConstants.ANNOTATION_BASIC)) {
icon = Graphiti.getGaService().createImage(iconRect, JPAEditorImageProvider.ICON_BASIC);
- } else if (annotations.contains(JPAEditorConstants.ANNOTATION_ID)) {
+ } else if (annotations.contains(JPAEditorConstants.ANNOTATION_ID) &&
+ !annotations.contains(JPAEditorConstants.ANNOTATION_ONE_TO_ONE) &&
+ !annotations.contains(JPAEditorConstants.ANNOTATION_MANY_TO_ONE)) {
icon = Graphiti.getGaService().createImage(iconRect, JPAEditorImageProvider.PRIMARY_KEY);
- } else if (annotations.contains(JPAEditorConstants.ANNOTATION_ONE_TO_ONE)) {
- icon = Graphiti.getGaService().createImage(iconRect, JPAEditorImageProvider.ICON_ONE_TO_ONE);
+ } else if (annotations.contains(JPAEditorConstants.ANNOTATION_ONE_TO_ONE) ) {
+ if(annotations.contains(JPAEditorConstants.ANNOTATION_ID) || annotations.contains(JPAEditorConstants.ANNOTATION_MAPS_ID)){
+ icon = Graphiti.getGaService().createImage(iconRect, JPAEditorImageProvider.ONE_TO_ONE_PRIMARY_KEY);
+ } else {
+ icon = Graphiti.getGaService().createImage(iconRect, JPAEditorImageProvider.ICON_ONE_TO_ONE);
+ }
} else if (annotations.contains(JPAEditorConstants.ANNOTATION_ONE_TO_MANY)) {
icon = Graphiti.getGaService().createImage(iconRect, JPAEditorImageProvider.ICON_ONE_TO_MANY);
- } else if (annotations.contains(JPAEditorConstants.ANNOTATION_MANY_TO_ONE)) {
- icon = Graphiti.getGaService().createImage(iconRect, JPAEditorImageProvider.ICON_MANY_TO_ONE);
+ } else if (annotations.contains(JPAEditorConstants.ANNOTATION_MANY_TO_ONE)){
+ if(annotations.contains(JPAEditorConstants.ANNOTATION_ID) || annotations.contains(JPAEditorConstants.ANNOTATION_MAPS_ID)){
+ icon = Graphiti.getGaService().createImage(iconRect, JPAEditorImageProvider.MANY_TO_ONE_PRIMARY_KEY);
+ } else {
+ icon = Graphiti.getGaService().createImage(iconRect, JPAEditorImageProvider.ICON_MANY_TO_ONE);
+ }
} else if (annotations.contains(JPAEditorConstants.ANNOTATION_MANY_TO_MANY)) {
icon = Graphiti.getGaService().createImage(iconRect, JPAEditorImageProvider.ICON_MANY_TO_MANY);
} else if(annotations.contains(JPAEditorConstants.ANNOTATION_EMBEDDED_ID)){
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/JPASolver.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/JPASolver.java
index bf280b3ab1..be28b9b73a 100644
--- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/JPASolver.java
+++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/JPASolver.java
@@ -435,7 +435,12 @@ public class JPASolver implements IResourceChangeListener, IJpaSolver {
private String findRelationshipKey(JavaPersistentAttribute jpa, IJPAEditorFeatureProvider fp){
JpaArtifactFactory jpaFactory = JpaArtifactFactory.instance();
if(jpaFactory.isEmbeddedAttribute(jpa)){
- JavaPersistentType embeddableClass = jpaFactory.findJPT(jpa, fp, JpaArtifactFactory.instance().getAnnotations(jpa)[0]);
+ Annotation embeddedAn = null;
+ Annotation[] anns = JpaArtifactFactory.instance().getAnnotations(jpa);
+ if(anns != null && anns.length > 0){
+ embeddedAn = anns[0];
+ }
+ JavaPersistentType embeddableClass = jpaFactory.findJPT(jpa, fp, embeddedAn);
if(embeddableClass == null)
return ""; //$NON-NLS-1$
for (JavaPersistentAttribute relEntAt : embeddableClass.getAttributes()) {
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/JpaArtifactFactory.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/JpaArtifactFactory.java
index 402391a68e..618e58b165 100644
--- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/JpaArtifactFactory.java
+++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/JpaArtifactFactory.java
@@ -44,9 +44,11 @@ import org.eclipse.graphiti.services.Graphiti;
import org.eclipse.graphiti.util.IColorConstant;
import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jdt.core.IField;
+import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.IMethod;
import org.eclipse.jdt.core.IPackageDeclaration;
import org.eclipse.jdt.core.IType;
+import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.core.dom.CompilationUnit;
import org.eclipse.jpt.common.core.JptResourceModel;
@@ -76,8 +78,10 @@ import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType;
import org.eclipse.jpt.jpa.core.context.java.JavaTypeMapping;
import org.eclipse.jpt.jpa.core.context.persistence.ClassRef;
import org.eclipse.jpt.jpa.core.context.persistence.PersistenceUnit;
+import org.eclipse.jpt.jpa.core.jpa2.resource.java.MapsId2_0Annotation;
import org.eclipse.jpt.jpa.core.resource.java.AttributeOverrideAnnotation;
import org.eclipse.jpt.jpa.core.resource.java.ColumnAnnotation;
+import org.eclipse.jpt.jpa.core.resource.java.IdAnnotation;
import org.eclipse.jpt.jpa.core.resource.java.IdClassAnnotation;
import org.eclipse.jpt.jpa.core.resource.java.JoinColumnAnnotation;
import org.eclipse.jpt.jpa.core.resource.java.MapKeyAnnotation;
@@ -254,7 +258,7 @@ public class JpaArtifactFactory {
String mappedByAttr = getMappeByAttribute(fp, manySideJPT, manySideAttribute);
setMappedByAnnotationAttribute(resolvedSingleSideAttribute, singleSideJPT, mappedByAttr);
} else {
- addJoinColumnIfNecessary(resolvedSingleSideAttribute, singleSideJPT, fp);
+ addJoinColumnIfNecessary(resolvedSingleSideAttribute, singleSideJPT);
}
if (isMap)
singleSideAttibute.getResourceAttribute().addAnnotation(MapKeyAnnotation.ANNOTATION_NAME);
@@ -265,8 +269,8 @@ public class JpaArtifactFactory {
String mappedByAttr = ownerSideAttribute.getName();
- if(JpaArtifactFactory.instance().hasEmbeddableAnnotation(ownerSideJPT)){
- HasReferanceRelation ref = JpaArtifactFactory.instance().findFisrtHasReferenceRelationByEmbeddable(ownerSideJPT, (IJPAEditorFeatureProvider)fp);
+ if(hasEmbeddableAnnotation(ownerSideJPT)){
+ HasReferanceRelation ref = JpaArtifactFactory.INSTANCE.findFisrtHasReferenceRelationByEmbeddable(ownerSideJPT, (IJPAEditorFeatureProvider)fp);
if(ref != null){
JavaPersistentAttribute embeddingAttribute = ref.getEmbeddedAnnotatedAttribute();
mappedByAttr = embeddingAttribute.getName() + "." + ownerSideAttribute.getName(); //$NON-NLS-1$
@@ -298,7 +302,7 @@ public class JpaArtifactFactory {
}
private void addJoinColumnIfNecessary(JavaPersistentAttribute jpa,
- JavaPersistentType jpt, IFeatureProvider fp) {
+ JavaPersistentType jpt) {
if (JPAEditorUtil.checkJPAFacetVersion(jpa.getJpaProject(), JPAEditorUtil.JPA_PROJECT_FACET_10) ||
JPADiagramPropertyPage.shouldOneToManyUnidirBeOldStyle(jpa
@@ -345,6 +349,7 @@ public class JpaArtifactFactory {
private Hashtable<String, String> getOverriddenColNames(
JavaPersistentAttribute embIdAt) {
Hashtable<String, String> res = new Hashtable<String, String>();
+ if(embIdAt.getResourceAttribute().getAnnotationsSize(AttributeOverrideAnnotation.ANNOTATION_NAME) > 0){
AttributeOverrideAnnotation aon = (AttributeOverrideAnnotation) embIdAt
.getResourceAttribute().getAnnotation(0,
AttributeOverrideAnnotation.ANNOTATION_NAME);
@@ -358,6 +363,7 @@ public class JpaArtifactFactory {
res.put(aon.getName(), colName);
return res;
}
+ }
Iterable<AttributeOverrideAnnotation> it = new SubListIterableWrapper<NestableAnnotation, AttributeOverrideAnnotation>(
embIdAt.getResourceAttribute().getAnnotations(AttributeOverrideAnnotation.ANNOTATION_NAME));
for (AttributeOverrideAnnotation an : it) {
@@ -591,6 +597,32 @@ public class JpaArtifactFactory {
}
/**
+ * Finds all java persistent types, which has an attribute, mapped as
+ * embedded id and type, the fully qualified name of the given embeddable.
+ * @param embeddable
+ * @param fp
+ * @return a collection of all java persistent types, that have an embedded id attribute of
+ * the given embeddable type.
+ */
+ public HashSet<JavaPersistentType> findAllJPTWithTheGivenEmbeddedId(JavaPersistentType embeddable, IJPAEditorFeatureProvider fp){
+ HashSet<JavaPersistentType> embeddingEntities = new HashSet<JavaPersistentType>();
+ if(!hasEmbeddableAnnotation(embeddable))
+ return embeddingEntities;
+ ListIterator<PersistenceUnit> lit = embeddable.getJpaProject().getRootContextNode().getPersistenceXml().getRoot().getPersistenceUnits().iterator();
+ PersistenceUnit pu = lit.next();
+ for(PersistentType jpt : pu.getPersistentTypes()){
+ if(!jpt.equals(embeddable)){
+ for(JavaPersistentAttribute jpa : ((JavaPersistentType)jpt).getAttributes()){
+ if(isEmbeddedId(jpa) && JPAEditorUtil.getAttributeTypeNameWithGenerics(jpa).equals(embeddable.getName())){
+ embeddingEntities.add((JavaPersistentType) jpt);
+ }
+ }
+ }
+ }
+ return embeddingEntities;
+ }
+
+ /**
* Find the first {@link HasReferenceRelation} for the given embeddable class from all existing
* {@link HasReferanceRelation} in the diagram.
* @param embeddable - the given embeddable class
@@ -759,12 +791,13 @@ public class JpaArtifactFactory {
*/
public void deleteAttribute(JavaPersistentType jpt, String attributeName,
IJPAEditorFeatureProvider fp) {
-
- Command deleteAttributeCommand = new DeleteAttributeCommand(jpt, attributeName, fp);
- try {
- getJpaProjectManager().execute(deleteAttributeCommand, SynchronousUiCommandExecutor.instance());
- } catch (InterruptedException e) {
- JPADiagramEditorPlugin.logError("Cannot delete attribute with name " + attributeName, e); //$NON-NLS-1$
+ synchronized (jpt) {
+ Command deleteAttributeCommand = new DeleteAttributeCommand(null, jpt, attributeName, fp);
+ try {
+ getJpaProjectManager().execute(deleteAttributeCommand, SynchronousUiCommandExecutor.instance());
+ } catch (InterruptedException e) {
+ JPADiagramEditorPlugin.logError("Cannot delete attribute with name " + attributeName, e); //$NON-NLS-1$
+ }
}
}
@@ -1148,7 +1181,7 @@ public class JpaArtifactFactory {
String oldName, String newName, String inverseEntityName,
IJPAEditorFeatureProvider fp) throws InterruptedException {
newName = JPAEditorUtil.decapitalizeFirstLetter(newName);
- if (JpaArtifactFactory.instance().isMethodAnnotated(jpt)) {
+ if (isMethodAnnotated(jpt)) {
newName = JPAEditorUtil.produceValidAttributeName(newName);
}
newName = JPAEditorUtil.produceUniqueAttributeName(jpt, newName);
@@ -1159,7 +1192,7 @@ public class JpaArtifactFactory {
.getResourceAttribute();
fp.addRemoveIgnore((JavaPersistentType)oldAt.getParent(), jra.getName());
- Command renameAttributeCommand = new RenameAttributeCommand(jpt, oldName, newName, fp);
+ Command renameAttributeCommand = new RenameAttributeCommand(null, jpt, oldName, newName, fp);
getJpaProjectManager().execute(renameAttributeCommand, SynchronousUiCommandExecutor.instance());
JavaPersistentAttribute newAt = jpt.getAttributeNamed(newName);
@@ -1199,8 +1232,41 @@ public class JpaArtifactFactory {
Command changeMappedByValueCommand = new SetMappedByNewValueCommand(fp, pu, inverseEntityName, inverseAttributeName, newAt, oldAt, rel);
getJpaProjectManager().execute(changeMappedByValueCommand, SynchronousUiCommandExecutor.instance());
}
- if (rel != null)
+ if (rel != null) {
updateRelation(jpt, fp, rel);
+ if(hasIDClassAnnotation(jpt)) {
+ String idClassFQN = getIdType(jpt);
+ IJavaProject javaProject = JavaCore.create(jpt.getJpaProject().getProject());
+ IType type = getType(javaProject, idClassFQN);
+ if(type != null && type.getField(oldAt.getName()).exists()){
+ Command renameAttributeCommand = new RenameAttributeCommand(type.getCompilationUnit(), null, oldAt.getName(), newAt.getName(), fp);
+ getJpaProjectManager().execute(renameAttributeCommand, SynchronousUiCommandExecutor.instance());
+ }
+ }
+ }
+
+ HashSet<JavaPersistentType> embeddingEntities = findAllJPTWithTheGivenEmbeddedId(jpt, fp);
+ if(embeddingEntities != null && !embeddingEntities.isEmpty()){
+ renameMapsIdAnnotationValue(oldAt, newAt, embeddingEntities);
+ }
+
+ }
+
+ private void renameMapsIdAnnotationValue(JavaPersistentAttribute oldAt,
+ JavaPersistentAttribute newAt, HashSet<JavaPersistentType> embeddingEntities) {
+
+ for(JavaPersistentType embeddingEntity : embeddingEntities){
+ for(JavaPersistentAttribute attr : embeddingEntity.getAttributes()){
+ Annotation ann = attr.getResourceAttribute().getAnnotation(MapsId2_0Annotation.ANNOTATION_NAME);
+ if(ann != null){
+ MapsId2_0Annotation mapsIdAnn = (MapsId2_0Annotation) ann;
+ if(mapsIdAnn.getValue() != null && mapsIdAnn.getValue().equals(oldAt.getName())){
+ ((MapsId2_0Annotation)ann).setValue(newAt.getName());
+ embeddingEntity.synchronizeWithResourceModel();
+ }
+ }
+ }
+ }
}
@@ -1389,7 +1455,7 @@ public class JpaArtifactFactory {
if (annotationName.equals(JPAEditorConstants.ANNOTATION_ONE_TO_ONE)) {
if (!fp.doesRelationExist(jpt, relJPT, attrName, null, RelType.ONE_TO_ONE,
RelDir.UNI))
- res = new OneToOneUniDirRelation(fp, jpt, relJPT, attrName, false);
+ res = new OneToOneUniDirRelation(fp, jpt, relJPT, attrName, false, false);
} else if (annotationName
.equals(JPAEditorConstants.ANNOTATION_ONE_TO_MANY)) {
if (!fp.doesRelationExist(jpt, relJPT, attrName, null, RelType.ONE_TO_MANY,
@@ -1399,7 +1465,7 @@ public class JpaArtifactFactory {
.equals(JPAEditorConstants.ANNOTATION_MANY_TO_ONE)) {
if (!fp.doesRelationExist(jpt, relJPT, attrName, null, RelType.MANY_TO_ONE,
RelDir.UNI))
- res = new ManyToOneUniDirRelation(fp, jpt, relJPT, attrName, false);
+ res = new ManyToOneUniDirRelation(fp, jpt, relJPT, attrName, false, false);
} else if (annotationName
.equals(JPAEditorConstants.ANNOTATION_MANY_TO_MANY)) {
if (!fp.doesRelationExist(jpt, relJPT, attrName, null, RelType.MANY_TO_MANY,
@@ -1481,13 +1547,13 @@ public class JpaArtifactFactory {
if (!fp.doesRelationExist(jpt, relJPT, ownerAttrName, inverseAttrName, RelType.ONE_TO_ONE,
RelDir.BI))
res = new OneToOneBiDirRelation(fp, jpt, relJPT, ownerAttrName,
- inverseAttrName, false, relJPT);
+ inverseAttrName, false, relJPT, false);
} else if (annotationName
.equals(JPAEditorConstants.ANNOTATION_MANY_TO_ONE)) {
if (!fp.doesRelationExist(jpt, relJPT, ownerAttrName, inverseAttrName, RelType.MANY_TO_ONE,
RelDir.BI))
res = new ManyToOneBiDirRelation(fp, jpt, relJPT, ownerAttrName,
- inverseAttrName, false, relJPT);
+ inverseAttrName, false, relJPT, false);
} else if (annotationName
.equals(JPAEditorConstants.ANNOTATION_MANY_TO_MANY)) {
if (!fp.doesRelationExist(jpt, relJPT, ownerAttrName, inverseAttrName, RelType.MANY_TO_MANY,
@@ -1710,6 +1776,14 @@ public class JpaArtifactFactory {
return (JpaProject) project.getAdapter(JpaProject.class);
}
+ public boolean hasIDClassAnnotation(JavaPersistentType jpt){
+ Annotation an = jpt.getJavaResourceType().getAnnotation(IdClassAnnotation.ANNOTATION_NAME);
+ if(an != null){
+ return true;
+ }
+ return false;
+ }
+
public String getIdType(JavaPersistentType jpt) {
IdClassAnnotation an = (IdClassAnnotation)jpt.getJavaResourceType().getAnnotation(IdClassAnnotation.ANNOTATION_NAME);
if (an != null)
@@ -1725,8 +1799,9 @@ public class JpaArtifactFactory {
public JavaPersistentAttribute[] getIds(JavaPersistentType jpt) {
ArrayList<JavaPersistentAttribute> res = new ArrayList<JavaPersistentAttribute>();
for (JavaPersistentAttribute at : jpt.getAttributes()) {
- if (isId(at))
+ if (isId(at)) {
res.add(at);
+ }
}
JavaPersistentAttribute[] ret = new JavaPersistentAttribute[res.size()];
return res.toArray(ret);
@@ -1750,6 +1825,23 @@ public class JpaArtifactFactory {
return false;
}
+ private boolean hasSimplePk(JavaPersistentType jpt) {
+ for(JavaPersistentAttribute at : jpt.getAttributes()){
+ if(isSimpleId(at) && !hasIDClassAnnotation(jpt)){
+ return true;
+ }
+ }
+ return false;
+ }
+
+ private JavaPersistentAttribute getSimplePkAttribute(JavaPersistentType jpt){
+ for(JavaPersistentAttribute jpa : jpt.getAttributes()){
+ if(isSimpleId(jpa)){
+ return jpa;
+ }
+ }
+ return null;
+ }
public boolean isId(ReadOnlyPersistentAttribute jpa) {
return isSimpleId(jpa) || isEmbeddedId(jpa);
@@ -1759,6 +1851,24 @@ public class JpaArtifactFactory {
return (jpa.getMappingKey() == MappingKeys.ID_ATTRIBUTE_MAPPING_KEY);
}
+ private boolean hasEmbeddedPk(JavaPersistentType jpt){
+ for(JavaPersistentAttribute at : jpt.getAttributes()){
+ if(isEmbeddedId(at)){
+ return true;
+ }
+ }
+ return false;
+ }
+
+ private JavaPersistentAttribute getEmbeddedIdAttribute(JavaPersistentType jpt){
+ for(JavaPersistentAttribute jpa : jpt.getAttributes()){
+ if(isEmbeddedId(jpa)){
+ return jpa;
+ }
+ }
+ return null;
+ }
+
public boolean isEmbeddedId(ReadOnlyPersistentAttribute jpa) {
return (jpa.getMappingKey() == MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY);
}
@@ -1869,4 +1979,113 @@ public class JpaArtifactFactory {
JPADiagramEditorPlugin.logError("Cannot create hierarchy of entity type " + subclass.getName(), e); //$NON-NLS-1$
}
}
+
+ /**
+ * Adds derived identifier
+ * @param ownerJPT - the dependent entity (the relationship's owner entity)
+ * @param inverseJPT - the parent entity (the relationship's inverse/target entity)
+ * @param ownerAttr - the relationship's owner attribute
+ */
+ public void calculateDerivedIdAnnotation(JavaPersistentType ownerJPT, JavaPersistentType inverseJPT, JavaPersistentAttribute ownerAttr) {
+ String attributeType = null;
+ if(hasSimplePk(inverseJPT)){
+ JavaPersistentAttribute jpa = getSimplePkAttribute(inverseJPT);
+ attributeType = JPAEditorUtil.getAttributeTypeNameWithGenerics(jpa);
+ } else {
+ if(hasIDClassAnnotation(inverseJPT)){
+ attributeType = getIdType(inverseJPT);
+ } else if (hasEmbeddedPk(inverseJPT)){
+ attributeType = JPAEditorUtil.getAttributeTypeNameWithGenerics(getEmbeddedIdAttribute(inverseJPT));
+ }
+ }
+ addAppropriateDerivedIdAnnotation(ownerJPT, inverseJPT, ownerAttr, attributeType);
+
+ }
+
+ /**
+ * Adds the derived identifier annotation depending on the dependent entity's primary key type.
+ * @param ownerJPT - the dependent entity (the relationship's owner entity)
+ * @param inverseJPT - the parent entity (the relationship's inverse/target entity)
+ * @param ownerAttr - the relationship's owner attribute
+ * @param inverseIdClassFQN - he type of the primary key of the parent entity
+ */
+ private void addAppropriateDerivedIdAnnotation(JavaPersistentType ownerJPT,
+ JavaPersistentType inverseJPT, JavaPersistentAttribute ownerAttr,
+ String inverseIdClassFQN) {
+ if(hasIDClassAnnotation(ownerJPT)){
+ String ownerIdClassFQN = getIdType(ownerJPT);
+ addDerivedIdAnnotation(ownerJPT, inverseJPT, ownerAttr, ownerIdClassFQN,
+ inverseIdClassFQN, IdAnnotation.ANNOTATION_NAME);
+ } else if(hasEmbeddedPk(ownerJPT)){
+ String ownerIdClassFQN = JPAEditorUtil.getAttributeTypeNameWithGenerics(getEmbeddedIdAttribute(ownerJPT));
+ addDerivedIdAnnotation(ownerJPT, inverseJPT, ownerAttr, ownerIdClassFQN,
+ inverseIdClassFQN, MapsId2_0Annotation.ANNOTATION_NAME);
+ } else if(hasSimplePk(ownerJPT)){
+ ownerAttr.getResourceAttribute().addAnnotation(MapsId2_0Annotation.ANNOTATION_NAME);
+ } else {
+ ownerAttr.getResourceAttribute().addAnnotation(IdAnnotation.ANNOTATION_NAME);
+ }
+ addJoinColumnIfNecessary(ownerAttr, inverseJPT);
+ }
+
+ /**
+ * Adds the appropriate derived identifier's annotation to the relationship's owner attribute.
+ * @param ownerJPT - the dependent entity (the relationship's owner entity)
+ * @param inverseJPT - the parent entity ( the relationship's inverse/target entity)
+ * @param ownerAttr - the relationship's owner attribute
+ * @param ownerIdClassFQN - the fully qualified name of the composite primary key's class
+ * @param inverseIdClassFQN - the type of the primary key of the parent entity
+ * @param annotationName - the derived identifier's annotation (either @Id or @MapsId)
+ */
+ private void addDerivedIdAnnotation(JavaPersistentType ownerJPT,
+ JavaPersistentType inverseJPT, JavaPersistentAttribute ownerAttr,
+ String ownerIdClassFQN, String inverseIdClassFQN, String annotationName) {
+ if(!inverseIdClassFQN.equals(ownerIdClassFQN)){
+ String attributeType = JPAEditorUtil.returnSimpleName(inverseIdClassFQN);
+ addFieldInCompositeKeyClass(inverseJPT, ownerAttr, ownerIdClassFQN, attributeType);
+ Annotation ann = ownerAttr.getResourceAttribute().addAnnotation(annotationName);
+ if(ann instanceof MapsId2_0Annotation){
+ ((MapsId2_0Annotation)ann).setValue(ownerAttr.getName());
+ }
+ } else {
+ ownerAttr.getResourceAttribute().addAnnotation(annotationName);
+ }
+ }
+
+ /**
+ * This method is called during the calculation of the derived identifier. If the dependent entity has a
+ * composite primary key, this method is used to be created a new field in the composite primary key's class.
+ * The field will be of the same type as type the primary key of the parent entity and the name will be the
+ * same as the name of the owner relationship's attribute.
+ * @param inverseJPT - the parent entity (the relationship's inverse/target entity)
+ * @param ownerAttr - the dependent entity (the relationship's owner entity)
+ * @param fqnClass - the fully qualified name of the composite primary key's class
+ * @param attributeTypeName - the attribute's type
+ */
+ private void addFieldInCompositeKeyClass(JavaPersistentType inverseJPT,
+ JavaPersistentAttribute ownerAttr, String fqnClass, String attributeTypeName) {
+ IJavaProject javaProject = JavaCore.create(ownerAttr.getJpaProject().getProject());
+ IType type = getType(javaProject, fqnClass);
+ if(type != null && !type.getField(ownerAttr.getName()).exists()){
+ ICompilationUnit unit = type.getCompilationUnit();
+ JavaPersistentType jpt = JPAEditorUtil.getJPType(unit);
+ Command createNewAttributeCommand = new AddAttributeCommand(null, jpt, attributeTypeName, null, ownerAttr.getName(),
+ ownerAttr.getName(), null, null, false, unit);
+ try {
+ getJpaProjectManager().execute(createNewAttributeCommand, SynchronousUiCommandExecutor.instance());
+ } catch (InterruptedException e) {
+ JPADiagramEditorPlugin.logError("Cannot create a new attribute with name " + ownerAttr.getName(), e); //$NON-NLS-1$
+ }
+ }
+ }
+
+ public IType getType(IJavaProject javaProject, String fqnClass) {
+ try {
+ IType type = javaProject.findType(fqnClass);
+ return type;
+ } catch (JavaModelException e) {
+ e.printStackTrace();
+ }
+ return null;
+ }
}

Back to the top