Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPetya Sabeva2013-03-14 12:14:24 +0000
committerPetya Sabeva2013-04-10 13:29:21 +0000
commit3d776d5fddefa31731027bf638c9ffdf8e223110 (patch)
tree81bd2f6951484dcec75b845e4ce27fef75b33d61 /jpa_diagram_editor/plugins
parentd692b2952c6cb5d339aac871455311934789dfc8 (diff)
downloadwebtools.dali-3d776d5fddefa31731027bf638c9ffdf8e223110.tar.gz
webtools.dali-3d776d5fddefa31731027bf638c9ffdf8e223110.tar.xz
webtools.dali-3d776d5fddefa31731027bf638c9ffdf8e223110.zip
Bug 403482 - Add SWT bot tests for xml defined persistent types
Diffstat (limited to 'jpa_diagram_editor/plugins')
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/JPADiagramEditor.java8
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/command/AddAttributeCommand.java51
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/command/AddPersistentAttributeInOrmXMLCommand.java49
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/command/AddPersistentTypeToOrmXmlCommand.java2
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/command/DeleteAttributeCommand.java153
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/command/RemovePersistentAttributeFromormXmlCommand.java33
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/command/RenameAttributeCommand.java63
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/command/RenameEntityCommand.java22
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/AddJPAEntityFeature.java28
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/ClickAddAttributeButtonFeature.java2
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/ClickAddElementCollectionButtonFeature.java8
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/ClickRemoveAttributeButtonFeature.java10
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateEmbeddableFeature.java10
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateIsARelationFeature.java1
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateJPAEntityFeature.java5
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/DeleteRelationFeature.java34
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/EmbedCollectionOfObjectsFeature.java9
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/EmbedSingleObjectFeature.java9
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/GraphicalAddAttributeFeature.java6
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/GraphicalRemoveAttributeFeature.java1
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/RefactorAttributeTypeFeature.java4
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/RefactorEntityFeature.java2
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/provider/JPAEditorFeatureProvider.java12
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/ManyToManyBiDirRelation.java6
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/ManyToManyUniDirRelation.java2
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/ManyToOneBiDirRelation.java6
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/ManyToOneUniDirRelation.java2
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/OneToManyUniDirRelation.java2
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/OneToOneBiDirRelation.java6
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/OneToOneUniDirRelation.java2
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/JPAEditorUtil.java18
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/JPASolver.java4
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/JpaArtifactFactory.java142
33 files changed, 356 insertions, 356 deletions
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 164128413e..c014df25a7 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
@@ -337,10 +337,10 @@ public class JPADiagramEditor extends DiagramEditor implements JpaEditorManager{
.getBusinessObjectForPictogramElement(
(PictogramElement) m);
if ((bo == null) || (!(bo instanceof JpaStructureNode))){
- if(jpaSelectionModel == null)
- return;
- jpaSelectionModel.setValue(null);
- setFileModel(null);
+ if(jpaSelectionModel != null) {
+ jpaSelectionModel.setValue(null);
+ setFileModel(null);
+ }
return;
}
JpaStructureNode jpaStructureNode = (JpaStructureNode) bo;
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 31d2e3a384..9e9d2993f5 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
@@ -24,14 +24,14 @@ import java.util.Properties;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.jdt.core.ICompilationUnit;
+import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.IType;
+import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.core.JavaModelException;
-import org.eclipse.jpt.common.core.resource.java.JavaResourceType;
import org.eclipse.jpt.common.utility.command.Command;
import org.eclipse.jpt.jpa.core.context.PersistentType;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.JPADiagramEditorPlugin;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.propertypage.JPADiagramPropertyPage;
-import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.IJPAEditorFeatureProvider;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JPAEditorConstants;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JPAEditorUtil;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JpaArtifactFactory;
@@ -45,7 +45,6 @@ import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JpaArtifactFactory;
*/
public class AddAttributeCommand implements Command {
- private IJPAEditorFeatureProvider fp;
private PersistentType jpt;
private String attributeType;
private String mapKeyType;
@@ -54,27 +53,23 @@ public class AddAttributeCommand implements Command {
private String[] attrTypes;
private List<String> annotations;
private boolean isCollection;
- private ICompilationUnit cu;
/**
* Constructor for the create new attribute command.
*
- * @param fp
* @param jpt
* @param attributeType
* @param mapKeyType
* @param attributeName
* @param actName
* @param isCollection
- * @param cu
*/
- public AddAttributeCommand(IJPAEditorFeatureProvider fp,
+ public AddAttributeCommand(
PersistentType jpt, String attributeType, String mapKeyType,
String attributeName, String actName, String[] attrTypes,
List<String> annotations,
- boolean isCollection, ICompilationUnit cu) {
+ boolean isCollection) {
super();
- this.fp = fp;
this.jpt = jpt;
this.attributeType = attributeType;
this.mapKeyType = mapKeyType;
@@ -83,22 +78,18 @@ public class AddAttributeCommand implements Command {
this.attrTypes = attrTypes;
this.annotations = annotations;
this.isCollection = isCollection;
- this.cu = cu;
}
/**
* Creates a new attribute.
*/
public void execute() {
- IType type = null;
try {
-// if(jpt != null){
-// cu = JPAEditorUtil.getCompilationUnit(jpt);
-// }
+ IJavaProject jp = JavaCore.create(jpt.getJpaProject().getProject());
+ IType type = jp.findType(jpt.getName());
+ ICompilationUnit cu = type.getCompilationUnit();
JPAEditorUtil.createImport(cu, attributeType);
attributeType = JPAEditorUtil.returnSimpleName(attributeType);
- type = cu.findPrimaryType();
-
if ((attrTypes != null) && (attrTypes.length > 0)) {
JPAEditorUtil.createImports(cu, attrTypes);
}
@@ -112,15 +103,12 @@ public class AddAttributeCommand implements Command {
}
}
- createAttribute(fp, jpt, attributeType, mapKeyType, attributeName,
+ createAttribute(jpt, attributeType, mapKeyType, attributeName,
actName, cu, type, isCollection, attrTypes, contents);
- if(jpt != null) {
- jpt.getJpaProject().getContextModelRoot().synchronizeWithResourceModel();
- JavaResourceType jrt = jpt.getJavaResourceType();
- jrt.getJavaResourceCompilationUnit().synchronizeWithJavaSource();
- jpt.update();
- }
+ jpt.getJavaResourceType().getJavaResourceCompilationUnit().synchronizeWithJavaSource();
+ jpt.synchronizeWithResourceModel();
+ jpt.update();
} catch (JavaModelException e) {
JPADiagramEditorPlugin
@@ -132,7 +120,6 @@ public class AddAttributeCommand implements Command {
/**
* Creates an attribute the persistent type.
*
- * @param fp
* @param jpt
* @param attrTypeName
* @param mapKeyType
@@ -143,13 +130,12 @@ public class AddAttributeCommand implements Command {
* @param isCollection
* @throws JavaModelException
*/
- private void createAttribute(IJPAEditorFeatureProvider fp,
- PersistentType jpt, String attrTypeName, String mapKeyType,
+ private void createAttribute(PersistentType jpt, String attrTypeName, String mapKeyType,
String attrName, String actName, ICompilationUnit cu, IType type,
boolean isCollection, String[] attrTypeElementNames, String annotationContents) throws JavaModelException {
if (isCollection) {
- createAttributeOfCollectiontype(fp, jpt, attrTypeName,
+ createAttributeOfCollectiontype(jpt, attrTypeName,
mapKeyType, attrName, actName, cu, type);
} else {
createSimpleAttribute(attrTypeName, attrName, actName,
@@ -182,7 +168,7 @@ public class AddAttributeCommand implements Command {
} else {
contents = attrFieldContent;
}
-
+
type.createField(contents, null, false, new NullProgressMonitor());
type.createMethod(
@@ -197,7 +183,6 @@ public class AddAttributeCommand implements Command {
* Creates a new attribute of a collection type, depending on the specified
* collection type in the Preference/Properties page.
*
- * @param fp
* @param jpt
* @param attributeType
* @param mapKeyType
@@ -207,12 +192,12 @@ public class AddAttributeCommand implements Command {
* @param type
* @throws JavaModelException
*/
- private void createAttributeOfCollectiontype(IJPAEditorFeatureProvider fp,
+ private void createAttributeOfCollectiontype(
PersistentType jpt, String attributeType, String mapKeyType,
String attributeName, String actName, ICompilationUnit cu,
IType type) throws JavaModelException {
IProject project = jpt.getJpaProject().getProject();
- Properties props = fp.loadProperties(project);
+ Properties props = loadProperties(project);
if (JPADiagramPropertyPage.isCollectionType(project, props)) {
createAttributeByCollectionMethodType(attributeType, null,
attributeName, actName, cu, type,
@@ -411,5 +396,9 @@ public class AddAttributeCommand implements Command {
" }\n"; //$NON-NLS-1$
return contents;
}
+
+ private Properties loadProperties(IProject project) {
+ return JPADiagramPropertyPage.loadProperties(project);
+ }
}
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/command/AddPersistentAttributeInOrmXMLCommand.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/command/AddPersistentAttributeInOrmXMLCommand.java
new file mode 100644
index 0000000000..dce1b07364
--- /dev/null
+++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/command/AddPersistentAttributeInOrmXMLCommand.java
@@ -0,0 +1,49 @@
+package org.eclipse.jpt.jpadiagrameditor.ui.internal.command;
+
+import org.eclipse.jpt.common.utility.command.Command;
+import org.eclipse.jpt.jpa.core.context.PersistentAttribute;
+import org.eclipse.jpt.jpa.core.context.PersistentType;
+import org.eclipse.jpt.jpa.core.context.orm.OrmPersistentAttribute;
+import org.eclipse.jpt.jpa.core.context.orm.OrmPersistentType;
+import org.eclipse.jpt.jpa.core.context.persistence.MappingFileRef;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JpaArtifactFactory;
+
+public class AddPersistentAttributeInOrmXMLCommand implements Command {
+
+ private PersistentType jpt;
+ private PersistentAttribute jpa;
+ private String mappingKey;
+
+ public AddPersistentAttributeInOrmXMLCommand(PersistentType jpt, PersistentAttribute jpa, String mappingKey){
+ this.jpt = jpt;
+ this.jpa = jpa;
+ this.mappingKey = mappingKey;
+ }
+
+ public void execute() {
+ MappingFileRef ormXml = JpaArtifactFactory.instance().getOrmXmlByForPersistentType(jpt);
+ if(ormXml != null && ormXml.getMappingFile() != null) {
+ OrmPersistentType ormPersistentType = (OrmPersistentType)ormXml.getMappingFile().getManagedType(jpt.getName());
+ if(ormPersistentType == null)
+ return;
+ OrmPersistentAttribute ormAttribute = ormPersistentType.getAttributeNamed(jpa.getName());
+ if(ormAttribute == null) {
+ ormPersistentType.getJavaResourceType().getJavaResourceCompilationUnit().synchronizeWithJavaSource();
+ ormPersistentType.update();
+ ormAttribute = ormPersistentType.getAttributeNamed(jpa.getName());
+ }
+ if(ormAttribute != null && ormAttribute.isVirtual()){
+ if(mappingKey == null){
+ ormPersistentType.addAttributeToXml(ormAttribute);
+ } else {
+ ormPersistentType.addAttributeToXml(ormAttribute, mappingKey);
+ }
+ }
+ }
+
+ jpt.getJavaResourceType().getJavaResourceCompilationUnit().synchronizeWithJavaSource();
+ jpt.synchronizeWithResourceModel();
+ jpt.update();
+ }
+
+}
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/command/AddPersistentTypeToOrmXmlCommand.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/command/AddPersistentTypeToOrmXmlCommand.java
index ac8051ade1..a7f6a112e9 100644
--- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/command/AddPersistentTypeToOrmXmlCommand.java
+++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/command/AddPersistentTypeToOrmXmlCommand.java
@@ -53,6 +53,8 @@ public class AddPersistentTypeToOrmXmlCommand implements Command {
MappingFileRef mapFile = iter.next();
if(mapFile.getFileName().equals(ormFileName)){
OrmXml ormXml = (OrmXml) mapFile.getMappingFile();
+ if(ormXml == null || ormXml.getRoot() == null)
+ return;
OrmPersistentType type = ormXml.getRoot().addPersistentType(mapping, persistentTypeName);
for(PersistentAttribute pa : type.getDefaultAttributes()){
type.addAttributeToXml(type.getAttributeNamed(pa.getName()));
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 74c7ba545b..2440179665 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
@@ -20,12 +20,12 @@ import java.util.Locale;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.graphiti.ui.editor.IDiagramContainerUI;
-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.IType;
+import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.core.JavaModelException;
-import org.eclipse.jpt.common.core.resource.java.JavaResourceType;
import org.eclipse.jpt.common.utility.command.Command;
import org.eclipse.jpt.jpa.core.context.PersistentType;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.JPADiagramEditorPlugin;
@@ -39,34 +39,61 @@ public class DeleteAttributeCommand implements Command {
private PersistentType jpt;
private String attributeName;
private IJPAEditorFeatureProvider fp;
- private ICompilationUnit unit;
- public DeleteAttributeCommand(ICompilationUnit unit, PersistentType jpt, String attributeName,
+ public DeleteAttributeCommand(PersistentType jpt, String attributeName,
IJPAEditorFeatureProvider fp) {
super();
this.jpt = jpt;
- this.unit = unit;
this.attributeName = attributeName;
this.fp = fp;
}
public void execute() {
- boolean isMethodAnnotated = false;
- if(jpt != null) {
-
- JpaArtifactFactory.instance().removeOrmPersistentAttribute(jpt, attributeName);
-
- unit = fp.getCompilationUnit(jpt);
- isMethodAnnotated = JpaArtifactFactory.instance()
- .isMethodAnnotated(jpt);
- }
-
- IType javaType = unit.findPrimaryType();
+ JpaArtifactFactory.instance().removeOrmPersistentAttribute(jpt, attributeName);
+ try {
+ IJavaProject jp = JavaCore.create(jpt.getJpaProject().getProject());
+ IType javaType = jp.findType(jpt.getName());
+
String attrNameWithCapitalLetter = attributeName.substring(0, 1)
.toUpperCase(Locale.ENGLISH) + attributeName.substring(1);
+ IMethod getAttributeMethod = findGetterMethod(javaType,
+ attrNameWithCapitalLetter);
+
+ String typeSignature = getReturnedType(getAttributeMethod);
+
+ deleteGetterMethod(typeSignature, getAttributeMethod);
+ deleteField(javaType);
+ deleteSetterMethod(javaType, attrNameWithCapitalLetter,
+ typeSignature);
+
+ IWorkbenchSite ws = ((IDiagramContainerUI) fp.getDiagramTypeProvider().getDiagramBehavior().getDiagramContainer()).getSite();
+ JPAEditorUtil.organizeImports(javaType.getCompilationUnit(), ws);
+
+ jpt.getJavaResourceType().getJavaResourceCompilationUnit().synchronizeWithJavaSource();
+ jpt.synchronizeWithResourceModel();
+ jpt.update();
+
+ } catch (JavaModelException e) {
+ JPADiagramEditorPlugin
+ .logError(
+ "Cannnot delete attribute with name " + attributeName, e); //$NON-NLS-1$
+ }
+
+ }
+
+ private String getReturnedType(IMethod getAttributeMethod)
+ throws JavaModelException {
String typeSignature = null;
+ if ((getAttributeMethod != null) && getAttributeMethod.exists()) {
+ typeSignature = getAttributeMethod.getReturnType();
+ }
+ return typeSignature;
+ }
+
+ private IMethod findGetterMethod(IType javaType,
+ String attrNameWithCapitalLetter) {
String getterPrefix = "get"; //$NON-NLS-1$
String methodName = getterPrefix + attrNameWithCapitalLetter;
IMethod getAttributeMethod = javaType.getMethod(methodName,
@@ -76,78 +103,34 @@ public class DeleteAttributeCommand implements Command {
}
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; //$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$
- }
- } 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 {
- 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$
- }
+ return getAttributeMethod;
+ }
+
+ private void deleteSetterMethod(IType javaType,
+ String attrNameWithCapitalLetter, String typeSignature)
+ throws JavaModelException {
+ String methodName = "set" + attrNameWithCapitalLetter; //$NON-NLS-1$
+ if(typeSignature != null) {
+ IMethod setAttributeMethod = javaType.getMethod(methodName,
+ new String[] { typeSignature });
+ if ((setAttributeMethod != null) && setAttributeMethod.exists())
+ setAttributeMethod.delete(true, new NullProgressMonitor());
}
- try {
- methodName = "set" + attrNameWithCapitalLetter; //$NON-NLS-1$
- if(typeSignature != null) {
- 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$
+ }
+
+ private void deleteGetterMethod(String typeSignature, IMethod getAttributeMethod) throws JavaModelException {
+ if (getAttributeMethod != null && getAttributeMethod.exists()) {
+ getAttributeMethod.delete(true, new NullProgressMonitor());
}
+ }
- IWorkbenchSite ws = ((IDiagramContainerUI)fp.getDiagramTypeProvider().getDiagramBehavior().getDiagramContainer()).getSite();
- JPAEditorUtil.organizeImports(unit, ws);
-
- if(jpt != null) {
- jpt.getJpaProject().getContextModelRoot().synchronizeWithResourceModel();
- JavaResourceType jrt = jpt.getJavaResourceType();
- jrt.getJavaResourceCompilationUnit().synchronizeWithJavaSource();
- jpt.update();
+ private void deleteField(IType javaType) throws JavaModelException {
+ IField attributeField = javaType.getField(attributeName);
+ if (attributeField != null) {
+ if (!attributeField.exists()) {
+ attributeField = javaType.getField(JPAEditorUtil.revertFirstLetterCase(attributeName));
+ }
+ attributeField.delete(true, new NullProgressMonitor());
}
}
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/command/RemovePersistentAttributeFromormXmlCommand.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/command/RemovePersistentAttributeFromormXmlCommand.java
new file mode 100644
index 0000000000..bce128b0cf
--- /dev/null
+++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/command/RemovePersistentAttributeFromormXmlCommand.java
@@ -0,0 +1,33 @@
+package org.eclipse.jpt.jpadiagrameditor.ui.internal.command;
+
+import org.eclipse.jpt.common.utility.command.Command;
+import org.eclipse.jpt.jpa.core.context.PersistentType;
+import org.eclipse.jpt.jpa.core.context.orm.OrmPersistentAttribute;
+import org.eclipse.jpt.jpa.core.context.orm.OrmPersistentType;
+import org.eclipse.jpt.jpa.core.context.orm.OrmSpecifiedPersistentAttribute;
+import org.eclipse.jpt.jpa.core.context.persistence.MappingFileRef;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JpaArtifactFactory;
+
+public class RemovePersistentAttributeFromormXmlCommand implements Command {
+
+ private PersistentType jpt;
+ private String attributeName;
+
+ public RemovePersistentAttributeFromormXmlCommand(PersistentType jpt, String attributeName){
+ this.jpt = jpt;
+ this.attributeName = attributeName;
+ }
+
+ public void execute() {
+ MappingFileRef ormXml = JpaArtifactFactory.instance().getOrmXmlByForPersistentType(jpt);
+ if(ormXml != null && ormXml.getMappingFile() != null) {
+ OrmPersistentType ormPersistentType = (OrmPersistentType)ormXml.getMappingFile().getPersistentType(jpt.getName());
+ OrmPersistentAttribute ormReadOnlyAttribute = ormPersistentType.getAttributeNamed(attributeName);
+ if(ormReadOnlyAttribute instanceof OrmSpecifiedPersistentAttribute)
+ ormPersistentType.removeAttributeFromXml((OrmSpecifiedPersistentAttribute) ormReadOnlyAttribute);
+ }
+ jpt.getJavaResourceType().getJavaResourceCompilationUnit().synchronizeWithJavaSource();
+ jpt.synchronizeWithResourceModel();
+ jpt.update();
+ }
+}
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 6fc85cd5a9..cebbd02ba5 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
@@ -23,8 +23,10 @@ import java.util.List;
import org.eclipse.core.runtime.CoreException;
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.IType;
+import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.ui.refactoring.RenameSupport;
import org.eclipse.jpt.common.core.resource.java.JavaResourceType;
@@ -36,7 +38,6 @@ import org.eclipse.jpt.jpa.core.context.persistence.MappingFileRef;
import org.eclipse.jpt.jpa.core.resource.orm.XmlAttributeMapping;
import org.eclipse.jpt.jpa.core.resource.orm.XmlTypeMapping;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.JPADiagramEditorPlugin;
-import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.IJPAEditorFeatureProvider;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JPAEditorUtil;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JpaArtifactFactory;
import org.eclipse.swt.widgets.Shell;
@@ -45,43 +46,34 @@ import org.eclipse.ui.IWorkbenchWindow;
public class RenameAttributeCommand implements Command {
private PersistentType jpt;
- private ICompilationUnit jptCompilationUnit;
private String oldName;
private String newName;
- private IJPAEditorFeatureProvider fp;
- public RenameAttributeCommand(ICompilationUnit jptCompilationUnit, PersistentType jpt, String oldName,
- String newName, IJPAEditorFeatureProvider fp){
+ public RenameAttributeCommand(PersistentType jpt, String oldName,
+ String newName){
super();
this.jpt = jpt;
- this.jptCompilationUnit = jptCompilationUnit;
this.oldName = oldName;
- this.newName = newName;
- this.fp = fp;
-
+ this.newName = newName;
}
public void execute() {
- if(jptCompilationUnit == null) {
- jptCompilationUnit = fp.getCompilationUnit(jpt);
- }
- try {
- boolean isMethodAnnotated = false;
- if(jpt!= null){
- renameAttribute(jpt, oldName, newName);
- isMethodAnnotated = JpaArtifactFactory.instance().isMethodAnnotated(jpt);
- }
- renameAttribute(jptCompilationUnit, oldName, newName, fp, isMethodAnnotated);
+ try {
+ renameAttribute(jpt, oldName, newName);
+ boolean isMethodAnnotated = JpaArtifactFactory.instance().isMethodAnnotated(jpt);
+
+ ICompilationUnit jptCompilationUnit = JPAEditorUtil.getCompilationUnit(jpt);
+ renameAttribute(jptCompilationUnit, oldName, newName, isMethodAnnotated);
- if(jpt != null) {
- jpt.getJpaProject().getContextModelRoot().synchronizeWithResourceModel();
- JavaResourceType jrt = jpt.getJavaResourceType();
- jrt.getJavaResourceCompilationUnit().synchronizeWithJavaSource();
- jpt.update();
- }
- } catch (InterruptedException e) {
+
+ jpt.getJpaProject().getContextModelRoot().synchronizeWithResourceModel();
+ JavaResourceType jrt = jpt.getJavaResourceType();
+ jrt.getJavaResourceCompilationUnit().synchronizeWithJavaSource();
+ jpt.update();
+
+ } catch (Exception e) {
JPADiagramEditorPlugin.logError("Cannot rename attribute", e); //$NON-NLS-1$
}
}
@@ -90,7 +82,6 @@ public class RenameAttributeCommand implements Command {
MappingFileRef mapFileRef = JpaArtifactFactory.instance().getOrmXmlByForPersistentType(jpt);
if(mapFileRef != null) {
EntityMappings root = (EntityMappings) mapFileRef.getMappingFile().getRoot();
-// XmlEntityMappings xmlEntities = root.getXmlEntityMappings();
Iterator<OrmManagedType> managedTypesIter = root.getManagedTypes().iterator();
while(managedTypesIter.hasNext()) {
XmlTypeMapping xmlType = (XmlTypeMapping) managedTypesIter.next().getXmlManagedType();
@@ -103,24 +94,14 @@ public class RenameAttributeCommand implements Command {
}
}
}
-
-// List<XmlTypeMapping> typeMappings = xmlEntities.getTypeMappings();
-// for(XmlTypeMapping xmlType : typeMappings){
-// if(xmlType.getAttributes() == null)
-// return;
-// List<XmlAttributeMapping> attributeMappings = xmlType.getAttributes().getAttributeMappings();
-// for(XmlAttributeMapping attr : attributeMappings){
-// if(attr.getName().equals(oldName)){
-// attr.setName(newName);
-// }
-// }
-// }
}
}
private void renameAttribute(ICompilationUnit cu, String oldName,
- String newName, IJPAEditorFeatureProvider fp, boolean isMethodAnnotated) throws InterruptedException {
- IType javaType = cu.findPrimaryType();
+ String newName, boolean isMethodAnnotated) throws Exception {
+
+ IJavaProject jp = JavaCore.create(jpt.getJpaProject().getProject());
+ IType javaType = jp.findType(jpt.getName());
if (javaType == null)
return;
IField attributeField = null;
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/command/RenameEntityCommand.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/command/RenameEntityCommand.java
index ed882764b7..efb110ff35 100644
--- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/command/RenameEntityCommand.java
+++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/command/RenameEntityCommand.java
@@ -17,13 +17,16 @@
package org.eclipse.jpt.jpadiagrameditor.ui.internal.command;
import org.eclipse.jdt.core.ICompilationUnit;
+import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.IType;
+import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.ui.refactoring.RenameSupport;
import org.eclipse.jpt.common.core.resource.java.JavaResourceType;
import org.eclipse.jpt.common.utility.command.Command;
import org.eclipse.jpt.jpa.core.context.PersistentType;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.JPADiagramEditorPlugin;
-import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.IJPAEditorFeatureProvider;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JPAEditorUtil;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IWorkbenchWindow;
@@ -31,17 +34,15 @@ public class RenameEntityCommand implements Command {
private PersistentType jpt;
private String newEntityName;
- private IJPAEditorFeatureProvider fp;
- public RenameEntityCommand(PersistentType jpt, String newEntityName, IJPAEditorFeatureProvider fp){
+ public RenameEntityCommand(PersistentType jpt, String newEntityName){
super();
this.jpt = jpt;
this.newEntityName = newEntityName;
- this.fp = fp;
}
public void execute() {
- renameEntityClass(fp.getCompilationUnit(jpt), newEntityName);
+ renameEntityClass(JPAEditorUtil.getCompilationUnit(jpt), newEntityName);
jpt.getJpaProject().getContextModelRoot().synchronizeWithResourceModel();
JavaResourceType jrt = jpt.getJavaResourceType();
jrt.getJavaResourceCompilationUnit().synchronizeWithJavaSource();
@@ -49,8 +50,15 @@ public class RenameEntityCommand implements Command {
}
private void renameEntityClass(ICompilationUnit cu, String newName) {
- IType javaType = cu.findPrimaryType();
- renameType(javaType, newName);
+ IJavaProject jp = JavaCore.create(jpt.getJpaProject().getProject());
+ try {
+ IType javaType = jp.findType(jpt.getName());
+ renameType(javaType, newName);
+
+ } catch (JavaModelException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
}
private void renameType(IType type, String newName) {
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 6107022e81..af5d4813ef 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
@@ -141,32 +141,6 @@ public class AddJPAEntityFeature extends AbstractAddShapeFeature {
ICompilationUnit cu = ((SourceType)newObj).getCompilationUnit();
jpt = JPAEditorUtil.getJPType(cu);
}
-
-// MappingFileRef fileRef = JpaArtifactFactory.instance().getOrmXmlByForPersistentType(jpt);
-// if(fileRef != null) {
-// if(fileRef.getPersistentType(jpt.getName()) != null){
-// jpt = fileRef.getPersistentType(jpt.getName());
-// }
-// }
-
-
- //TODO this is wrong, should not need to do any of these updates or syncs.
- //should be changing the dali model synchronously so that all the syncs/updates are completed
- //take a look at the JpaProjectManager.execute(Command, ExtendedCommandContext)
-// JavaResourceType jrt = null;
-// if(jpt instanceof JavaPersistentType) {
-// jrt = ((JavaPersistentType)jpt).getJavaResourceType();
-// } else if (jpt instanceof OrmPersistentType){
-// jrt = ((OrmPersistentType)jpt).getJavaPersistentType().getJavaResourceType();
-// }
-//
-// if(jrt != null) {
-// jrt.getJavaResourceCompilationUnit().synchronizeWithJavaSource();
-// }
-//
- jpt.update();
- jpt.synchronizeWithResourceModel();
-
final Diagram targetDiagram = (Diagram) context.getTargetContainer();
final Wrp wrp = new Wrp();
createEntity(context, fp, targetDiagram, wrp, jpt);
@@ -433,7 +407,7 @@ public class AddJPAEntityFeature extends AbstractAddShapeFeature {
headerRect.setX(JPAEditorConstants.HEADER_TEXT_RECT_X);
String headerTextString = JPAEditorUtil.getText(addedWrapper);
- ICompilationUnit cu = getFeatureProvider().getCompilationUnit(addedWrapper);
+ ICompilationUnit cu = JPAEditorUtil.getCompilationUnit(addedWrapper);
JPAEditorUtil.becomeWorkingCopy(cu);
headerTextString = JPAEditorUtil.returnSimpleName(headerTextString);
try {
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/ClickAddAttributeButtonFeature.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/ClickAddAttributeButtonFeature.java
index 2d92aa341c..ed50a94083 100644
--- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/ClickAddAttributeButtonFeature.java
+++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/ClickAddAttributeButtonFeature.java
@@ -58,7 +58,7 @@ public class ClickAddAttributeButtonFeature extends AbstractCreateFeature {
PersistentAttribute newAttr = jpt.resolveAttribute(newAttrName);
getFeatureProvider().addAddIgnore((PersistentType) newAttr.getParent(), newAttr.getName());
- JpaArtifactFactory.instance().addOrmPersistentAttribute(jpt, newAttr, newAttr.getMappingKey());
+ JpaArtifactFactory.instance().addOrmPersistentAttribute(jpt, newAttr, null);
addGraphicalRepresentation(context, newAttr);
getFeatureProvider().getDirectEditingInfo().setActive(true);
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/ClickAddElementCollectionButtonFeature.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/ClickAddElementCollectionButtonFeature.java
index 94872114b6..1ed40aef8a 100644
--- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/ClickAddElementCollectionButtonFeature.java
+++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/ClickAddElementCollectionButtonFeature.java
@@ -57,9 +57,11 @@ public class ClickAddElementCollectionButtonFeature extends AbstractCreateFeatur
String newAttrName = JpaArtifactFactory.instance().createNewAttribute(jpt, true, getFeatureProvider());
PersistentAttribute newAttr = jpt.resolveAttribute(newAttrName);
- newAttr.getJavaPersistentAttribute().setMappingKey(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY);
- JpaArtifactFactory.instance().addOrmPersistentAttribute(jpt, newAttr, MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY);
-
+// newAttr.getJavaPersistentAttribute().setMappingKey(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY);
+ PersistentAttribute ormAttr = JpaArtifactFactory.instance().addOrmPersistentAttribute(jpt, newAttr, MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY);
+ if(ormAttr == null || ormAttr.isVirtual()){
+ newAttr.getJavaPersistentAttribute().setMappingKey(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY);
+ }
getFeatureProvider().addAddIgnore((PersistentType) newAttr.getParent(), newAttr.getName());
addGraphicalRepresentation(context, newAttr);
getFeatureProvider().getDirectEditingInfo().setActive(true);
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 2c0a115596..d645cc5bee 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
@@ -28,13 +28,13 @@ 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.ui.internal.utility.SynchronousUiCommandContext;
import org.eclipse.jpt.common.utility.command.Command;
import org.eclipse.jpt.jpa.core.JpaProjectManager;
import org.eclipse.jpt.jpa.core.context.AttributeMapping;
import org.eclipse.jpt.jpa.core.context.PersistentAttribute;
import org.eclipse.jpt.jpa.core.context.PersistentType;
+import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType;
import org.eclipse.jpt.jpa.core.context.persistence.PersistenceUnit;
import org.eclipse.jpt.jpa.core.jpa2.context.DerivedIdentity2_0;
import org.eclipse.jpt.jpa.core.jpa2.context.SingleRelationshipMapping2_0;
@@ -253,10 +253,10 @@ public class ClickRemoveAttributeButtonFeature extends DefaultDeleteFeature {
private void deleteFieldFromIdClassCompositePK(String attrName,
PersistentType 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());
+ JavaPersistentType idClassJPT = jpaFactory.getIdClassJPT(jpt);
+ if(idClassJPT != null && isDeleteAttributeAllowed(jpt, idClassJPT.getName())){
+
+ Command deleteAttributeCommand = new DeleteAttributeCommand(idClassJPT, attrName, getFeatureProvider());
try {
getJpaProjectManager().execute(deleteAttributeCommand, SynchronousUiCommandContext.instance());
} catch (InterruptedException e) {
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateEmbeddableFeature.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateEmbeddableFeature.java
index 6c47e7d837..1fe74e05ef 100644
--- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateEmbeddableFeature.java
+++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateEmbeddableFeature.java
@@ -97,15 +97,16 @@ public class CreateEmbeddableFeature extends AbstractCreateFeature {
PersistentType jpt = JpaArtifactFactory.instance().getJPT(
embeddableName, pu);
+
if (jpt != null) {
if(JPADiagramPropertyPage.doesSupportOrmXml(targetProject)) {
JpaArtifactFactory.instance().addPersistentTypeToORMXml(jpaProject, embeddableName, MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY);
}
- addGraphicalRepresentation(context, jpt);
+ addGraphicalRepresentation(context, jpt);
IWorkbenchSite ws = ((IDiagramContainerUI)getFeatureProvider().getDiagramTypeProvider().getDiagramBehavior().getDiagramContainer()).getSite();
ICompilationUnit cu = getFeatureProvider().getCompilationUnit(jpt);
getFeatureProvider().getJPAEditorUtil().formatCode(cu, ws);
- return new Object[] { jpt };
+ return new Object[] { jpt };
} else {
JPADiagramEditorPlugin
.logError(
@@ -114,7 +115,10 @@ public class CreateEmbeddableFeature extends AbstractCreateFeature {
+ " could not be created", new Exception()); //$NON-NLS-1$
}
- return new Object[] {};
+ IWorkbenchSite ws = ((IDiagramContainerUI) getDiagramBehavior().getDiagramContainer()).getSite();
+ ICompilationUnit cu = JPAEditorUtil.getCompilationUnit(jpt);
+ getFeatureProvider().getJPAEditorUtil().formatCode(cu, ws);
+ return new Object[] { jpt };
}
@Override
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateIsARelationFeature.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateIsARelationFeature.java
index 08b39f44ad..4ae1cc4f2f 100644
--- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateIsARelationFeature.java
+++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateIsARelationFeature.java
@@ -77,6 +77,7 @@ public class CreateIsARelationFeature extends AbstractCreateConnectionFeature {
for(PersistentAttribute jpa : subclass.getAttributes()){
if(jpa.getMappingKey().equals(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY)){
jpa.getJavaPersistentAttribute().setMappingKey(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY);
+// MappingFileRef mapFileRef = JpaArtifactFactory.instance().getOrmXmlByForPersistentType(jpa.getDeclaringPersistentType());
} else if(jpa.getMappingKey().equals(MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY)) {
jpa.getJavaPersistentAttribute().setMappingKey(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY);
}
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateJPAEntityFeature.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateJPAEntityFeature.java
index 3e615f27a6..7d91b469b0 100644
--- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateJPAEntityFeature.java
+++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateJPAEntityFeature.java
@@ -175,6 +175,11 @@ public class CreateJPAEntityFeature extends AbstractCreateFeature {
if (jpt != null) {
if(JPADiagramPropertyPage.doesSupportOrmXml(targetProject)) {
JpaArtifactFactory.instance().addPersistentTypeToORMXml(jpaProject, entityName, MappingKeys.ENTITY_TYPE_MAPPING_KEY);
+ try {
+ jpt.getResource().refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor());
+ } catch (CoreException e1) {
+ JPADiagramEditorPlugin.logError("Cannot refresh the project", e1); //$NON-NLS-1$
+ }
}
// jpt = pu.getPersistentType(entityName);
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/DeleteRelationFeature.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/DeleteRelationFeature.java
index 2364e0d757..8ed49b0d9b 100644
--- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/DeleteRelationFeature.java
+++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/DeleteRelationFeature.java
@@ -19,9 +19,7 @@ import org.eclipse.graphiti.features.context.IContext;
import org.eclipse.graphiti.features.context.IDeleteContext;
import org.eclipse.graphiti.features.context.impl.DeleteContext;
import org.eclipse.graphiti.mm.pictograms.PictogramElement;
-import org.eclipse.graphiti.ui.editor.IDiagramContainerUI;
import org.eclipse.graphiti.ui.features.DefaultDeleteFeature;
-import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jpt.jpa.core.context.PersistentAttribute;
import org.eclipse.jpt.jpa.core.context.PersistentType;
@@ -30,13 +28,10 @@ import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.IJPAEditorFeaturePr
import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.AbstractRelation;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.HasReferanceRelation;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.IBidirectionalRelation;
-import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.IRelation;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.IUnidirectionalRelation;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.IsARelation;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.IJPAEditorUtil;
-import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JPAEditorUtil;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JpaArtifactFactory;
-import org.eclipse.ui.IWorkbenchSite;
import org.eclipse.ui.PlatformUI;
@@ -97,7 +92,7 @@ public class DeleteRelationFeature extends DefaultDeleteFeature{
PersistentType subclass = rel.getSubclass();
JpaArtifactFactory.instance().buildHierarchy(superclass, subclass, false);
- JPAEditorUtil.getCompilationUnit(subclass);
+ ut.getCompilationUnit(subclass);
// subclass.getJavaResourceType().getJavaResourceCompilationUnit().synchronizeWithJavaSource();
getFeatureProvider().addJPTForUpdate(subclass.getName());
@@ -146,32 +141,7 @@ public class DeleteRelationFeature extends DefaultDeleteFeature{
feat.delete(deleteInverseAttributeContext, false);
}
}
-
- @Override
- public void postDelete(IDeleteContext context) {
- PictogramElement pe = context.getPictogramElement();
- Object businessObjectForPictogramElement = getBusinessObjectForPictogramElement(pe);
- IWorkbenchSite ws = ((IDiagramContainerUI)getFeatureProvider().getDiagramTypeProvider().getDiagramBehavior().getDiagramContainer()).getSite();
- if (businessObjectForPictogramElement instanceof IRelation) {
- IRelation rel = (IRelation) businessObjectForPictogramElement;
- ICompilationUnit cu = getFeatureProvider().getCompilationUnit(rel.getOwner());
- ut.organizeImports(cu, ws);
- if (rel instanceof IBidirectionalRelation) {
- cu = getFeatureProvider().getCompilationUnit(rel.getInverse());
- ut.organizeImports(cu, ws);
- }
- } else if(businessObjectForPictogramElement instanceof HasReferanceRelation){
- HasReferanceRelation rel = (HasReferanceRelation) businessObjectForPictogramElement;
- ICompilationUnit cu = getFeatureProvider().getCompilationUnit(rel.getEmbeddingEntity());
- ut.organizeImports(cu, ws);
- } else if (businessObjectForPictogramElement instanceof IsARelation){
- IsARelation rel = (IsARelation) businessObjectForPictogramElement;
- ICompilationUnit cu = getFeatureProvider().getCompilationUnit(rel.getSubclass());
- ut.organizeImports(cu, ws);
- }
- }
-
-
+
@Override
public IJPAEditorFeatureProvider getFeatureProvider() {
return (IJPAEditorFeatureProvider)super.getFeatureProvider();
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/EmbedCollectionOfObjectsFeature.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/EmbedCollectionOfObjectsFeature.java
index 32facd617b..6ac4da0739 100644
--- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/EmbedCollectionOfObjectsFeature.java
+++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/EmbedCollectionOfObjectsFeature.java
@@ -87,10 +87,11 @@ public class EmbedCollectionOfObjectsFeature extends AbstractCreateConnectionFea
mapKeyType = JPAEditorConstants.STRING_TYPE;
}
- PersistentAttribute embeddedAttribute = JPAEditorUtil.addAnnotatedAttribute(getFeatureProvider(), embeddingEntity, embeddable, true, mapKeyType);
- embeddedAttribute.getJavaPersistentAttribute().setMappingKey(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY);
- JpaArtifactFactory.instance().addOrmPersistentAttribute(embeddingEntity, embeddedAttribute, MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY);
-
+ PersistentAttribute embeddedAttribute = JPAEditorUtil.addAnnotatedAttribute(embeddingEntity, embeddable, true, mapKeyType);
+ PersistentAttribute ormAttr = JpaArtifactFactory.instance().addOrmPersistentAttribute(embeddingEntity, embeddedAttribute, MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY);
+ if(ormAttr == null || ormAttr.isVirtual()){
+ embeddedAttribute.getJavaPersistentAttribute().setMappingKey(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY);
+ }
HasReferanceRelation rel = new HasCollectionReferenceRelation(embeddingEntity, embeddable);
rel.setEmbeddedAnnotatedAttribute(embeddedAttribute);
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/EmbedSingleObjectFeature.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/EmbedSingleObjectFeature.java
index 4fb57392a0..8ba6d8b34e 100644
--- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/EmbedSingleObjectFeature.java
+++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/EmbedSingleObjectFeature.java
@@ -76,10 +76,11 @@ public class EmbedSingleObjectFeature extends AbstractCreateConnectionFeature {
PersistentType embeddingEntity = getPersistentType(context.getSourceAnchor());
PersistentType embeddable = getPersistentType(context.getTargetAnchor());
- PersistentAttribute embeddedAttribute = JPAEditorUtil.addAnnotatedAttribute(getFeatureProvider(), embeddingEntity, embeddable, false, null);
- embeddedAttribute.getJavaPersistentAttribute().setMappingKey(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY);
- JpaArtifactFactory.instance().addOrmPersistentAttribute(embeddingEntity, embeddedAttribute, MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY);
-
+ PersistentAttribute embeddedAttribute = JPAEditorUtil.addAnnotatedAttribute(embeddingEntity, embeddable, false, null);
+ PersistentAttribute ormAttr = JpaArtifactFactory.instance().addOrmPersistentAttribute(embeddingEntity, embeddedAttribute, MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY);
+ if(ormAttr == null || ormAttr.isVirtual()){
+ embeddedAttribute.getJavaPersistentAttribute().setMappingKey(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY);
+ }
HasReferanceRelation rel = new HasSingleReferenceRelation(embeddingEntity, embeddable);
rel.setEmbeddedAnnotatedAttribute(embeddedAttribute);
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 984d066860..d387d02ce7 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
@@ -63,9 +63,9 @@ public class GraphicalAddAttributeFeature extends AbstractAddShapeFeature {
.getNewObject();
String txt = JPAEditorUtil.getText(newAttr);
AttributeMapping attributeMapping = JpaArtifactFactory.instance().getAttributeMapping(newAttr);
- if(!attributeMapping.getKey().equals(newAttr.getJavaPersistentAttribute().getMappingKey())){
-// newAttr.getJavaPersistentAttribute().setMappingKey(attributeMapping.getKey());
- }
+// if(!attributeMapping.getKey().equals(newAttr.getJavaPersistentAttribute().getMappingKey())){
+//// newAttr.getJavaPersistentAttribute().setMappingKey(attributeMapping.getKey());
+// }
ContainerShape textShape = null;
ContainerShape primaryShape = GraphicsUpdater
.getPrimaryShape(entityShape);
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/GraphicalRemoveAttributeFeature.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/GraphicalRemoveAttributeFeature.java
index 2ecdd197ca..4f98e12cc1 100644
--- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/GraphicalRemoveAttributeFeature.java
+++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/GraphicalRemoveAttributeFeature.java
@@ -50,6 +50,7 @@ public class GraphicalRemoveAttributeFeature extends AbstractCustomFeature {
TransactionalEditingDomain ted = TransactionUtil.getEditingDomain(pe);
if (ted == null)
return;
+
ted.getCommandStack().execute(new RecordingCommand(ted) {
@Override
protected void doExecute() {
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/RefactorAttributeTypeFeature.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/RefactorAttributeTypeFeature.java
index c50c888c72..b21102ab75 100644
--- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/RefactorAttributeTypeFeature.java
+++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/RefactorAttributeTypeFeature.java
@@ -73,8 +73,8 @@ public class RefactorAttributeTypeFeature extends AbstractCustomFeature {
JpaArtifactFactory.instance().deleteAttribute((PersistentType) jpa.getParent(), jpa.getName(),
getFeatureProvider());
- PersistentAttribute newAt = JpaArtifactFactory.instance().makeNewAttribute(getFeatureProvider(), (PersistentType) jpa.getParent(),
- null, jpa.getName(), newTypeName, jpa.getName(), newTypeName, attributeTypeTypeNames, annotations, false);
+ PersistentAttribute newAt = JpaArtifactFactory.instance().makeNewAttribute((PersistentType) jpa.getParent(),
+ jpa.getName(), newTypeName, jpa.getName(), newTypeName, attributeTypeTypeNames, annotations, false);
getFeatureProvider().replaceAttribute(jpa, newAt);
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 36ceb56dca..4d8ce5f44a 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
@@ -152,7 +152,7 @@ public abstract class RefactorEntityFeature extends AbstractCustomFeature {
jpt.getJpaProject().addCollectionChangeListener(JpaProject.JPA_FILES_COLLECTION, lsnr);
ShowBusy showBusy = new ShowBusy(s);
JPASolver.ignoreEvents = true;
- JpaArtifactFactory.instance().renameEntityClass(jpt, newName, getFeatureProvider());
+ JpaArtifactFactory.instance().renameEntityClass(jpt, newName);
BusyIndicator.showWhile(Display.getCurrent(), showBusy);
jpt.getJpaProject().removeCollectionChangeListener(JpaProject.JPA_FILES_COLLECTION, lsnr);
JPASolver.ignoreEvents = false;
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 3d8eec9878..372e81b858 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
@@ -789,11 +789,10 @@ public class JPAEditorFeatureProvider extends DefaultFeatureProvider implements
for (ClassRef classRef : unit.getClassRefs()) {
if (classRef.getJavaPersistentType() != null) { // null if
final PersistentType jpt = classRef.getJavaPersistentType();
- PictogramElement pe = getPictogramElementForBusinessObject(jpt);
+ final PictogramElement pe = getPictogramElementForBusinessObject(jpt);
if(pe == null)
continue;
- final GraphicsAlgorithm algo = pe.getGraphicsAlgorithm();
- TransactionalEditingDomain ted = TransactionUtil.getEditingDomain(algo);
+ TransactionalEditingDomain ted = TransactionUtil.getEditingDomain(pe);
JPAEditorConstants.DIAGRAM_OBJECT_TYPE dot = JpaArtifactFactory.instance().determineDiagramObjectType(jpt);
String renderingStyle = JpaArtifactFactory.instance().getRenderingStyle(dot);
@@ -806,11 +805,14 @@ public class JPAEditorFeatureProvider extends DefaultFeatureProvider implements
@Override
protected void doExecute() {
- gaService.setRenderingStyle(algo, gradientColoredArea);
+ GraphicsAlgorithm algo = pe.getGraphicsAlgorithm();
+// gaService.setRenderingStyle(algo, gradientColoredArea);
algo.setForeground(gaService.manageColor(d, foreground));
+ gaService.setRenderingStyle(algo, gradientColoredArea);
+
}
});
- }
+ }
}
}
}
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/ManyToManyBiDirRelation.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/ManyToManyBiDirRelation.java
index 5f77911ad9..391b6b7dba 100644
--- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/ManyToManyBiDirRelation.java
+++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/ManyToManyBiDirRelation.java
@@ -70,14 +70,14 @@ public class ManyToManyBiDirRelation extends ManyToManyRelation implements IBidi
boolean isMap = JPADiagramPropertyPage.isMapType(owner.getJpaProject().getProject());
String mapKeyType = getMapKeyType(isMap, inverse, embeddingEntity);
- ownerAnnotatedAttribute = JPAEditorUtil.addAnnotatedAttribute(fp, owner, inverse, true, mapKeyType);
+ ownerAnnotatedAttribute = JPAEditorUtil.addAnnotatedAttribute(owner, inverse, true, mapKeyType);
mapKeyType = getMapKeyType(isMap, owner, embeddingEntity);
if(JpaArtifactFactory.instance().isEmbeddable(owner)){
- inverseAnnotatedAttribute = JPAEditorUtil.addAnnotatedAttribute(fp, inverse, embeddingEntity, true, mapKeyType);
+ inverseAnnotatedAttribute = JPAEditorUtil.addAnnotatedAttribute(inverse, embeddingEntity, true, mapKeyType);
} else {
- inverseAnnotatedAttribute = JPAEditorUtil.addAnnotatedAttribute(fp, inverse, owner, true, mapKeyType);
+ inverseAnnotatedAttribute = JPAEditorUtil.addAnnotatedAttribute(inverse, owner, true, mapKeyType);
}
JpaArtifactFactory.instance().addManyToManyBidirectionalRelation(fp, owner, ownerAnnotatedAttribute, inverse, inverseAnnotatedAttribute, isMap);
}
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/ManyToManyUniDirRelation.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/ManyToManyUniDirRelation.java
index 6a03f344e6..9d0277d448 100644
--- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/ManyToManyUniDirRelation.java
+++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/ManyToManyUniDirRelation.java
@@ -46,7 +46,7 @@ public class ManyToManyUniDirRelation extends ManyToManyRelation implements IUni
private void createRelation(IJPAEditorFeatureProvider fp) {
boolean isMap = JPADiagramPropertyPage.isMapType(owner.getJpaProject().getProject());
String mapKeyType = getMapKeyType(isMap, inverse);
- ownerAnnotatedAttribute = JPAEditorUtil.addAnnotatedAttribute(fp, owner, inverse, true, mapKeyType);
+ ownerAnnotatedAttribute = JPAEditorUtil.addAnnotatedAttribute(owner, inverse, true, mapKeyType);
JpaArtifactFactory.instance().addManyToManyUnidirectionalRelation(fp, owner, ownerAnnotatedAttribute, isMap);
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/ManyToOneBiDirRelation.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/ManyToOneBiDirRelation.java
index 5929017761..6cf06f2ae6 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
@@ -60,14 +60,14 @@ public class ManyToOneBiDirRelation extends ManyToOneRelation implements IBidir
}
private void createRelation(IJPAEditorFeatureProvider fp, PersistentType embeddingEntity, boolean isDerivedIdFeature) {
- ownerAnnotatedAttribute = JPAEditorUtil.addAnnotatedAttribute(fp, owner, inverse, false, null);
+ ownerAnnotatedAttribute = JPAEditorUtil.addAnnotatedAttribute(owner, inverse, false, null);
boolean isMap = JPADiagramPropertyPage.isMapType(owner.getJpaProject().getProject());
String mapKeyType = getMapKeyType(isMap, owner, embeddingEntity);
if(JpaArtifactFactory.instance().isEmbeddable(owner)){
- inverseAnnotatedAttribute = JPAEditorUtil.addAnnotatedAttribute(fp, inverse, embeddingEntity, true, mapKeyType);
+ inverseAnnotatedAttribute = JPAEditorUtil.addAnnotatedAttribute(inverse, embeddingEntity, true, mapKeyType);
} else {
- inverseAnnotatedAttribute = JPAEditorUtil.addAnnotatedAttribute(fp, inverse, owner, true, mapKeyType);
+ inverseAnnotatedAttribute = JPAEditorUtil.addAnnotatedAttribute(inverse, owner, true, mapKeyType);
}
JpaArtifactFactory.instance().addManyToOneBidirectionalRelation(fp, owner, ownerAnnotatedAttribute, inverse, inverseAnnotatedAttribute, isMap);
if(isDerivedIdFeature){
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 e609da96ed..53505a4925 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
@@ -43,7 +43,7 @@ public class ManyToOneUniDirRelation extends ManyToOneRelation implements IUnidi
}
private void createRelation(IJPAEditorFeatureProvider fp, boolean isDerivedIdFeature) {
- ownerAnnotatedAttribute = JPAEditorUtil.addAnnotatedAttribute(fp, owner, inverse, false, null);
+ ownerAnnotatedAttribute = JPAEditorUtil.addAnnotatedAttribute(owner, inverse, false, null);
JpaArtifactFactory.instance().addManyToOneUnidirectionalRelation(fp, owner, ownerAnnotatedAttribute);
if(isDerivedIdFeature){
JpaArtifactFactory.instance().calculateDerivedIdAttribute(owner, inverse, ownerAnnotatedAttribute);
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/OneToManyUniDirRelation.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/OneToManyUniDirRelation.java
index c3cc5a6609..0ce917af41 100644
--- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/OneToManyUniDirRelation.java
+++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/OneToManyUniDirRelation.java
@@ -46,7 +46,7 @@ public class OneToManyUniDirRelation extends OneToManyRelation implements IUnidi
private void createRelation(IJPAEditorFeatureProvider fp) {
boolean isMap = JPADiagramPropertyPage.isMapType(owner.getJpaProject().getProject());
String mapKeyType = getMapKeyType(isMap, inverse);
- ownerAnnotatedAttribute = JPAEditorUtil.addAnnotatedAttribute(fp, owner, inverse, true, mapKeyType);
+ ownerAnnotatedAttribute = JPAEditorUtil.addAnnotatedAttribute(owner, inverse, true, mapKeyType);
JpaArtifactFactory.instance().addOneToManyUnidirectionalRelation(fp, owner, ownerAnnotatedAttribute, isMap);
}
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/OneToOneBiDirRelation.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/OneToOneBiDirRelation.java
index b9b7983674..242352228d 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
@@ -59,12 +59,12 @@ public class OneToOneBiDirRelation extends OneToOneRelation implements IBidirect
}
private void createRelation(IJPAEditorFeatureProvider fp, PersistentType embeddingEntity, boolean isDerivedIdFeature) {
- ownerAnnotatedAttribute = JPAEditorUtil.addAnnotatedAttribute(fp, owner, inverse, false, null);
+ ownerAnnotatedAttribute = JPAEditorUtil.addAnnotatedAttribute(owner, inverse, false, null);
if(JpaArtifactFactory.instance().isEmbeddable(owner)){
- inverseAnnotatedAttribute = JPAEditorUtil.addAnnotatedAttribute(fp, inverse, embeddingEntity, false, null);
+ inverseAnnotatedAttribute = JPAEditorUtil.addAnnotatedAttribute(inverse, embeddingEntity, false, null);
} else {
- inverseAnnotatedAttribute = JPAEditorUtil.addAnnotatedAttribute(fp, inverse, owner, false, null);
+ inverseAnnotatedAttribute = JPAEditorUtil.addAnnotatedAttribute(inverse, owner, false, null);
}
JpaArtifactFactory.instance().addOneToOneBidirectionalRelation(fp, owner, ownerAnnotatedAttribute, inverse, inverseAnnotatedAttribute);
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 15e4a94360..c895569365 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
@@ -43,7 +43,7 @@ public class OneToOneUniDirRelation extends OneToOneRelation implements IUnidire
}
private void createRelation(IJPAEditorFeatureProvider fp, boolean isDerivedIdFeature) {
- ownerAnnotatedAttribute = JPAEditorUtil.addAnnotatedAttribute(fp, owner, inverse, false, null);
+ ownerAnnotatedAttribute = JPAEditorUtil.addAnnotatedAttribute(owner, inverse, false, null);
JpaArtifactFactory.instance().addOneToOneUnidirectionalRelation(fp, owner, ownerAnnotatedAttribute);
if(isDerivedIdFeature){
JpaArtifactFactory.instance().calculateDerivedIdAttribute(owner, inverse, ownerAnnotatedAttribute);
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 f7729e6ee0..dbee958c98 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
@@ -90,7 +90,6 @@ import org.eclipse.jpt.jpa.core.context.PersistentAttribute;
import org.eclipse.jpt.jpa.core.context.PersistentType;
import org.eclipse.jpt.jpa.core.context.TransientMapping;
import org.eclipse.jpt.jpa.core.context.VersionMapping;
-import org.eclipse.jpt.jpa.core.context.orm.OrmPersistentType;
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.context.DerivedIdentity2_0;
@@ -978,7 +977,8 @@ public class JPAEditorUtil {
static public void formatCode(ICompilationUnit cu, IWorkbenchSite ws) {
FormatAllAction action = new FormatAllAction(ws);
- action.run(new StructuredSelection(cu));
+ if(cu != null)
+ action.run(new StructuredSelection(cu));
}
static public String generateUniquePersistentObjectName(JpaProject jpaProject, String pack, String objectTypeName, IJPAEditorFeatureProvider fp){
@@ -1156,10 +1156,8 @@ public class JPAEditorUtil {
}
public static ICompilationUnit getCompilationUnit(PersistentType jpt) {
- if (jpt instanceof OrmPersistentType){
- jpt = ((OrmPersistentType)jpt).getJavaPersistentType();
- }
- return getCompilationUnit((IFile) jpt.getResource());
+ ICompilationUnit unit = jpt.getJavaResourceType().getJavaResourceCompilationUnit().getCompilationUnit();
+ return unit;
}
public static ICompilationUnit getCompilationUnit(IFile file) {
@@ -1414,7 +1412,7 @@ public class JPAEditorUtil {
return h1.equals(h2);
}
- public static PersistentAttribute addAnnotatedAttribute(IJPAEditorFeatureProvider fp, PersistentType referencingJPT,
+ public static PersistentAttribute addAnnotatedAttribute(PersistentType referencingJPT,
PersistentType referencedJPT, boolean isCollection, String mapKeyType){
String name = returnSimpleName(referencedJPT.getName());
@@ -1430,11 +1428,9 @@ public class JPAEditorUtil {
nameWithNonCapitalLetter = produceUniqueAttributeName(referencingJPT, nameWithNonCapitalLetter);
actNameWithNonCapitalLetter = produceUniqueAttributeName(referencingJPT, actNameWithNonCapitalLetter);
- ICompilationUnit referencingCU = JPAEditorUtil.getCompilationUnit(referencingJPT);
- return JpaArtifactFactory.instance().addAttribute(fp, referencingJPT, referencedJPT, mapKeyType,
+ return JpaArtifactFactory.instance().addAttribute(referencingJPT, referencedJPT, mapKeyType,
nameWithNonCapitalLetter,
- actNameWithNonCapitalLetter, isCollection,
- referencingCU);
+ actNameWithNonCapitalLetter, isCollection);
}
}
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 2d42e57dab..3517902d85 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
@@ -390,8 +390,8 @@ public class JPASolver implements IResourceChangeListener, IJpaSolver {
}
}
- ICompilationUnit cu = getCompilationUnit(jpt);
- JPAEditorUtil.discardWorkingCopyOnce(cu);
+// ICompilationUnit cu = getCompilationUnit(jpt);
+// JPAEditorUtil.discardWorkingCopyOnce(cu);
} else if (o instanceof AbstractRelation) {
AbstractRelation rel = (AbstractRelation) o;
attribToRel.remove(produceOwnerKeyForRel(rel));
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 c676abff27..a9bc5d83e6 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
@@ -48,7 +48,6 @@ 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;
@@ -87,6 +86,7 @@ import org.eclipse.jpt.jpa.core.context.SpecifiedJoinColumn;
import org.eclipse.jpt.jpa.core.context.SpecifiedJoinColumnRelationshipStrategy;
import org.eclipse.jpt.jpa.core.context.SpecifiedMappedByRelationshipStrategy;
import org.eclipse.jpt.jpa.core.context.TypeMapping;
+import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType;
import org.eclipse.jpt.jpa.core.context.orm.OrmManagedType;
import org.eclipse.jpt.jpa.core.context.orm.OrmPersistentAttribute;
import org.eclipse.jpt.jpa.core.context.orm.OrmPersistentType;
@@ -104,6 +104,7 @@ import org.eclipse.jpt.jpa.core.resource.java.IdAnnotation;
import org.eclipse.jpt.jpa.core.resource.java.MapKeyAnnotation;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.JPADiagramEditorPlugin;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.command.AddAttributeCommand;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.command.AddPersistentAttributeInOrmXMLCommand;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.command.AddPersistentTypeToOrmXmlCommand;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.command.CreateEntityTypeHierarchy;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.command.DeleteAttributeCommand;
@@ -312,10 +313,12 @@ public class JpaArtifactFactory {
}
private PersistentAttribute setMappingKeyToAttribute(IFeatureProvider fp, PersistentType jpt, PersistentAttribute jpa, String mappingKey){
- PersistentAttribute resolvedManySideAttribute = jpt.resolveAttribute(jpa.getName());
- resolvedManySideAttribute.getJavaPersistentAttribute().setMappingKey(mappingKey);
- addOrmPersistentAttribute(jpt, jpa, mappingKey);
- return resolvedManySideAttribute;
+ PersistentAttribute resolvedManySideAttribute = jpt.getAttributeNamed(jpa.getName());
+ PersistentAttribute ormAttr = addOrmPersistentAttribute(jpt, resolvedManySideAttribute, mappingKey);
+ if(ormAttr == null || ormAttr.isVirtual()){
+ resolvedManySideAttribute.getJavaPersistentAttribute().setMappingKey(mappingKey);
+ }
+ return jpa;
}
private void addJoinColumnIfNecessary(PersistentAttribute jpa,
@@ -708,7 +711,6 @@ public class JpaArtifactFactory {
/**
* Create a relationship attribute.
- * @param fp
* @param jpt - the referencing {@link PersistentType}
* @param attributeType - the referenced {@link PersistentType}
* @param mapKeyType
@@ -718,9 +720,9 @@ public class JpaArtifactFactory {
* @param cu - the {@link ICompilationUnit} of the referencing {@link PersistentType}
* @return the newly created relationship attribute.
*/
- public PersistentAttribute addAttribute(IJPAEditorFeatureProvider fp, PersistentType jpt,
+ public PersistentAttribute addAttribute(PersistentType jpt,
PersistentType attributeType, String mapKeyType, String attributeName,
- String actName, boolean isCollection, ICompilationUnit cu) {
+ String actName, boolean isCollection) {
try {
if (doesAttributeExist(jpt, actName)) {
@@ -729,7 +731,7 @@ public class JpaArtifactFactory {
} catch (JavaModelException e) {
JPADiagramEditorPlugin.logError("Cannnot create a new attribute with name " + attributeName, e); //$NON-NLS-1$
}
- PersistentAttribute res = makeNewAttribute(fp, jpt, cu, attributeName, attributeType.getName(), actName, mapKeyType, null, null, isCollection);
+ PersistentAttribute res = makeNewAttribute(jpt, attributeName, attributeType.getName(), actName, mapKeyType, null, null, isCollection);
return res;
}
@@ -766,18 +768,13 @@ public class JpaArtifactFactory {
boolean isCollection, IJPAEditorFeatureProvider fp) {
String newAttrName = genUniqueAttrName(jpt, JPAEditorConstants.STRING_TYPE, fp);
- ICompilationUnit cu = fp.getCompilationUnit(jpt);
- makeNewAttribute(fp, jpt, cu, newAttrName, JPAEditorConstants.STRING_TYPE, newAttrName, JPAEditorConstants.STRING_TYPE, null, null, isCollection);
+ makeNewAttribute(jpt, newAttrName, JPAEditorConstants.STRING_TYPE, newAttrName, JPAEditorConstants.STRING_TYPE, null, null, isCollection);
return newAttrName;
}
- public PersistentAttribute makeNewAttribute(IJPAEditorFeatureProvider fp, PersistentType jpt, ICompilationUnit cu, String attrName, String attrTypeName,
+
+ public PersistentAttribute makeNewAttribute(PersistentType jpt, String attrName, String attrTypeName,
String actName, String mapKeyType, String[] attrTypes, List<String> annotations, boolean isCollection) {
-
- if(cu == null){
- cu = fp.getCompilationUnit(jpt);
- }
-
- Command createNewAttributeCommand = new AddAttributeCommand(fp, jpt, attrTypeName, mapKeyType, attrName, actName, attrTypes, annotations, isCollection, cu);
+ Command createNewAttributeCommand = new AddAttributeCommand(jpt, attrTypeName, mapKeyType, attrName, actName, attrTypes, annotations, isCollection);
try {
getJpaProjectManager().execute(createNewAttributeCommand, SynchronousUiCommandContext.instance());
} catch (InterruptedException e) {
@@ -790,20 +787,15 @@ public class JpaArtifactFactory {
return jpa;
}
- public void addOrmPersistentAttribute(PersistentType jpt, PersistentAttribute jpa, String mappingKey){
- MappingFileRef ormXml = getOrmXmlByForPersistentType(jpt);
- if(ormXml != null && ormXml.getMappingFile() != null) {
- OrmPersistentType ormPersistentType = (OrmPersistentType)ormXml.getMappingFile().getPersistentType(jpt.getName());
- if(ormPersistentType == null)
- return;
- if(mappingKey != null) {
- ormPersistentType.addAttributeToXml(ormPersistentType.getAttributeNamed(jpa.getName()), mappingKey);
- } else {
- if(ormPersistentType.getAttributeNamed(jpa.getName()) != null){
- ormPersistentType.addAttributeToXml(ormPersistentType.getAttributeNamed(jpa.getName()), jpa.getMappingKey());
- }
- }
+ public PersistentAttribute addOrmPersistentAttribute(PersistentType jpt, PersistentAttribute jpa, String mappingKey){
+ Command addpersAttrCommand = new AddPersistentAttributeInOrmXMLCommand(jpt, jpa, mappingKey);
+ try {
+ getJpaProjectManager().execute(addpersAttrCommand, SynchronousUiCommandContext.instance());
+ } catch (InterruptedException e) {
+ e.printStackTrace();
}
+
+ return getORMPersistentAttribute(jpa);
}
public void removeOrmPersistentAttribute(PersistentType jpt, String attributeName){
@@ -814,6 +806,10 @@ public class JpaArtifactFactory {
if(ormReadOnlyAttribute instanceof OrmSpecifiedPersistentAttribute)
ormPersistentType.removeAttributeFromXml((OrmSpecifiedPersistentAttribute) ormReadOnlyAttribute);
}
+
+ jpt.getJavaResourceType().getJavaResourceCompilationUnit().synchronizeWithJavaSource();
+ jpt.synchronizeWithResourceModel();
+ jpt.update();
}
/**
@@ -826,7 +822,7 @@ public class JpaArtifactFactory {
IJPAEditorFeatureProvider fp) {
synchronized (jpt) {
- Command deleteAttributeCommand = new DeleteAttributeCommand(null, jpt, attributeName, fp);
+ Command deleteAttributeCommand = new DeleteAttributeCommand(jpt, attributeName, fp);
try {
getJpaProjectManager().execute(deleteAttributeCommand, SynchronousUiCommandContext.instance());
} catch (InterruptedException e) {
@@ -1200,9 +1196,9 @@ public class JpaArtifactFactory {
return res;
}
- public void renameEntityClass(PersistentType jpt, String newEntityName, IJPAEditorFeatureProvider fp) {
+ public void renameEntityClass(PersistentType jpt, String newEntityName) {
- Command renameEntityCommand = new RenameEntityCommand(jpt, newEntityName, fp);
+ Command renameEntityCommand = new RenameEntityCommand(jpt, newEntityName);
try {
getJpaProjectManager().execute(renameEntityCommand, SynchronousUiCommandContext.instance());
} catch (InterruptedException e) {
@@ -1240,7 +1236,7 @@ public class JpaArtifactFactory {
String attributeTypeName = getRelTypeName(oldAt);
- Command renameAttributeCommand = new RenameAttributeCommand(null, jpt, oldName, newName, fp);
+ Command renameAttributeCommand = new RenameAttributeCommand(jpt, oldName, newName);
getJpaProjectManager().execute(renameAttributeCommand, SynchronousUiCommandContext.instance());
PersistentAttribute newAt = jpt.getAttributeNamed(newName);
@@ -1306,11 +1302,9 @@ public class JpaArtifactFactory {
if (rel != null) {
updateRelation(jpt, fp, rel);
if(hasIDClass(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);
+ JavaPersistentType idClassJPT = getIdClassJPT(jpt);
+ if(idClassJPT != null && (idClassJPT.getAttributeNamed(oldAt.getName()) != null)){
+ Command renameAttributeCommand = new RenameAttributeCommand(idClassJPT, oldAt.getName(), newAt.getName());
getJpaProjectManager().execute(renameAttributeCommand, SynchronousUiCommandContext.instance());
}
}
@@ -1840,16 +1834,30 @@ public class JpaArtifactFactory {
}
return false;
}
-
- public String getIdType(PersistentType jpt) {
- String idClass = null;
+
+ public JavaPersistentType getIdClassJPT(PersistentType jpt){
+ JavaPersistentType idClassType = null;
TypeMapping mapping = getTypeMapping(jpt);
if(mapping instanceof Entity){
- idClass = ((Entity)mapping).getIdClassReference().getFullyQualifiedIdClassName();
+ idClassType = ((Entity)mapping).getIdClass();
+ if(idClassType == null) {
+ String idClassFqn = ((Entity)mapping).getIdClassReference().getFullyQualifiedIdClassName();
+ PersistentType idClassPersistentType = jpt.getPersistenceUnit().getPersistentType(idClassFqn);
+ if(idClassPersistentType instanceof OrmPersistentType){
+ idClassType = ((OrmPersistentType)idClassPersistentType).getJavaPersistentType();
+ } else {
+ idClassType = (JavaPersistentType) idClassPersistentType;
+ }
+ }
}
- if (idClass != null)
- return idClass;
+ return idClassType;
+ }
+
+ public String getIdType(PersistentType jpt) {
+ JavaPersistentType idClassJPT = getIdClassJPT(jpt);
+ if (idClassJPT != null)
+ return idClassJPT.getName();
PersistentAttribute[] ids = getIds(jpt);
if (ids.length == 0)
return null;
@@ -2053,12 +2061,11 @@ public class JpaArtifactFactory {
public void calculateDerivedIdAttribute(PersistentType ownerJPT, PersistentType inverseJPT, PersistentAttribute ownerAttr) {
String attributeType = null;
if(hasSimplePk(inverseJPT)){
-
PersistentAttribute jpa = getSimplePkAttribute(inverseJPT);
attributeType = JPAEditorUtil.getAttributeTypeNameWithGenerics(jpa);
} else {
if(hasIDClass(inverseJPT)){
- attributeType = getIdType(inverseJPT);
+ attributeType = getIdClassJPT(inverseJPT).getName();
} else if (hasEmbeddedPk(inverseJPT)){
attributeType = JPAEditorUtil.getAttributeTypeNameWithGenerics(getEmbeddedIdAttribute(inverseJPT));
}
@@ -2082,13 +2089,15 @@ public class JpaArtifactFactory {
boolean isXmlDefined = getORMPersistentAttribute(ownerAttr) != null;
if(hasIDClass(ownerJPT)){
annotationName = IdAnnotation.ANNOTATION_NAME;
- String ownerIdClassFQN = getIdType(ownerJPT);
- addDerivedIdAnnotation(ownerJPT, inverseJPT, ownerAttr, ownerIdClassFQN,
+ JavaPersistentType composedJPT = getIdClassJPT(ownerJPT);
+ addDerivedIdAnnotation(ownerJPT, inverseJPT, ownerAttr, composedJPT,
inverseIdClassFQN, annotationName, isXmlDefined);
} else if(hasEmbeddedPk(ownerJPT)){
annotationName = MapsIdAnnotation2_0.ANNOTATION_NAME;
- String ownerIdClassFQN = JPAEditorUtil.getAttributeTypeNameWithGenerics(getEmbeddedIdAttribute(ownerJPT));
- mapsIdValue = addDerivedIdAnnotation(ownerJPT, inverseJPT, ownerAttr, ownerIdClassFQN,
+ PersistentAttribute embeddedIdAttribute = getEmbeddedIdAttribute(ownerJPT);
+ String embbeddedIdAttrType = getRelTypeName(embeddedIdAttribute);
+ PersistentType composedJPT = getPersistenceUnit(ownerJPT).getPersistentType(embbeddedIdAttrType);
+ mapsIdValue = addDerivedIdAnnotation(ownerJPT, inverseJPT, ownerAttr, composedJPT,
inverseIdClassFQN, annotationName, isXmlDefined);
} else if(hasSimplePk(ownerJPT)){
annotationName = MapsIdAnnotation2_0.ANNOTATION_NAME;
@@ -2120,24 +2129,23 @@ public class JpaArtifactFactory {
*/
private String addDerivedIdAnnotation(PersistentType ownerJPT,
PersistentType inverseJPT, PersistentAttribute ownerAttr,
- String ownerIdClassFQN, String inverseIdClassFQN, String annotationName, boolean isXmlDefined) {
- if(!inverseIdClassFQN.equals(ownerIdClassFQN)){
+ PersistentType ownerIdClass, String inverseIdClassFQN, String annotationName, boolean isXmlDefined) {
+ if(ownerIdClass != null && !inverseIdClassFQN.equals(ownerIdClass.getName())){
String attributeType = JPAEditorUtil.returnSimpleName(inverseIdClassFQN);
- addFieldInCompositeKeyClass(inverseJPT, ownerAttr, ownerIdClassFQN, attributeType);
+ addFieldInCompositeKeyClass(inverseJPT, ownerAttr, ownerIdClass, attributeType);
if(!isXmlDefined) {
Annotation ann = ownerAttr.getJavaPersistentAttribute().getResourceAttribute().addAnnotation(annotationName);
if(ann != null && ann instanceof MapsIdAnnotation2_0){
((MapsIdAnnotation2_0)ann).setValue(ownerAttr.getName());
}
}
- return ownerAttr.getName();
} else {
if(!isXmlDefined) {
ownerAttr.getJavaPersistentAttribute().getResourceAttribute().addAnnotation(annotationName);
}
}
- return null;
+ return ownerAttr.getName();
}
private void addDerivedIdMapping(PersistentAttribute attr, String idAttributeName, String annotationName){
@@ -2163,21 +2171,11 @@ public class JpaArtifactFactory {
* @param attributeTypeName - the attribute's type
*/
private void addFieldInCompositeKeyClass(PersistentType inverseJPT,
- PersistentAttribute 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();
- PersistentType jpt = JPAEditorUtil.getJPType(unit);
- Command createNewAttributeCommand = new AddAttributeCommand(null, jpt, attributeTypeName, null, ownerAttr.getName(),
- ownerAttr.getName(), null, null, false, unit);
- try {
- getJpaProjectManager().execute(createNewAttributeCommand, SynchronousUiCommandContext.instance());
- } catch (InterruptedException e) {
- JPADiagramEditorPlugin.logError("Cannot create a new attribute with name " + ownerAttr.getName(), e); //$NON-NLS-1$
- }
- if(jpt != null) {
- PersistentAttribute attr = jpt.getAttributeNamed(ownerAttr.getName());
+ PersistentAttribute ownerAttr, PersistentType fqnClass, String attributeTypeName) {
+ if(fqnClass != null && (fqnClass.getAttributeNamed(ownerAttr.getName()) == null)){
+ PersistentAttribute attr = makeNewAttribute(fqnClass, ownerAttr.getName(), attributeTypeName, ownerAttr.getName(), null, null, null, false);
+ PersistentAttribute ormAttr = JpaArtifactFactory.instance().addOrmPersistentAttribute(fqnClass, attr, MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY);
+ if(ormAttr == null || ormAttr.isVirtual()){
attr.getJavaPersistentAttribute().setMappingKey(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY);
}
}

Back to the top