diff options
Diffstat (limited to 'jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal')
48 files changed, 728 insertions, 476 deletions
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 5c7d53ea8e..1a693d8b8e 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 @@ -1,5 +1,23 @@ +/*******************************************************************************
+ * <copyright>
+ *
+ * Copyright (c) 2012 SAP AG and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Petya Sabeva - initial API, implementation and documentation
+ *
+ * </copyright>
+ *
+ *******************************************************************************/
+
package org.eclipse.jpt.jpadiagrameditor.ui.internal.command;
+import java.util.Iterator;
+import java.util.List;
import java.util.Locale;
import java.util.Properties;
@@ -18,22 +36,43 @@ 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;
-public class AddAttributeCommand implements Command{
+/**
+ * A new {@link Command} class that is called to create a new attribute in the
+ * selected persistent type.
+ *
+ * @author i045693
+ *
+ */
+public class AddAttributeCommand implements Command {
private IJPAEditorFeatureProvider fp;
private JavaPersistentType jpt;
- private JavaPersistentType attributeType;
+ private String attributeType;
private String mapKeyType;
private String attributeName;
private String actName;
+ private String[] attrTypes;
+ private List<String> annotations;
private boolean isCollection;
- private ICompilationUnit cu1;
- private ICompilationUnit cu2;
-
- public AddAttributeCommand(IJPAEditorFeatureProvider fp, JavaPersistentType jpt,
- JavaPersistentType attributeType, String mapKeyType, String attributeName,
- String actName, boolean isCollection, ICompilationUnit cu1,
- ICompilationUnit cu2){
+ 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,
+ JavaPersistentType jpt, String attributeType, String mapKeyType,
+ String attributeName, String actName, String[] attrTypes,
+ List<String> annotations,
+ boolean isCollection, ICompilationUnit cu) {
super();
this.fp = fp;
this.jpt = jpt;
@@ -41,140 +80,341 @@ public class AddAttributeCommand implements Command{ this.mapKeyType = mapKeyType;
this.attributeName = attributeName;
this.actName = actName;
+ this.attrTypes = attrTypes;
+ this.annotations = annotations;
this.isCollection = isCollection;
- this.cu1 = cu1;
- this.cu2 = cu2;
+ this.cu = cu;
}
+ /**
+ * Creates a new attribute.
+ */
public void execute() {
IType type = null;
try {
- JPAEditorUtil.createImport(cu1, cu2.getType(attributeType.getName()).getElementName());
- type = cu1.findPrimaryType();
+ JPAEditorUtil.createImport(cu, attributeType);
+ attributeType = JPAEditorUtil.returnSimpleName(attributeType);
+ type = cu.findPrimaryType();
- if (isCollection) {
- createAttributeOfCollectiontype(fp, jpt, attributeType,
- mapKeyType, attributeName, actName, cu1, type);
- } else {
- createSimpleAttribute(attributeType, attributeName, actName,
- isCollection, type);
+ if ((attrTypes != null) && (attrTypes.length > 0)) {
+ JPAEditorUtil.createImports(cu, attrTypes);
+ }
+
+ String contents = "";
+ if (annotations != null) {
+ Iterator<String> it = annotations.iterator();
+ while (it.hasNext()) {
+ String an = it.next();
+ contents += " " + an + "\n"; //$NON-NLS-1$ //$NON-NLS-2$
+ }
}
- JavaPersistentAttribute attr = jpt.getAttributeNamed(attributeName);
+ createAttribute(fp, jpt, attributeType, mapKeyType, attributeName,
+ actName, cu, type, isCollection, attrTypes, contents);
+
+ JavaPersistentAttribute attr = jpt.getAttributeNamed(actName);
int cnt = 0;
while ((attr == null) && (cnt < 25)) {
try {
Thread.sleep(250);
} catch (InterruptedException e) {
+ JPADiagramEditorPlugin.logError("Cannnot create a new attribute with name " + attributeName, e); //$NON-NLS-1$
}
- jpt.getJavaResourceType().getJavaResourceCompilationUnit().synchronizeWithJavaSource();
- attr = jpt.getAttributeNamed(attributeName);
+ jpt.getJavaResourceType().getJavaResourceCompilationUnit()
+ .synchronizeWithJavaSource();
+ jpt.update();
+ attr = jpt.getAttributeNamed(actName);
cnt++;
}
-
+
} catch (JavaModelException e) {
- JPADiagramEditorPlugin.logError("Cannnot create a new attribute with name " + attributeName, e); //$NON-NLS-1$
+ JPADiagramEditorPlugin
+ .logError(
+ "Cannnot create a new attribute with name " + attributeName, e); //$NON-NLS-1$
}
}
-
- private void createSimpleAttribute(JavaPersistentType attributeType,
+
+ /**
+ * Creates an attribute the persistent type.
+ *
+ * @param fp
+ * @param jpt
+ * @param attrTypeName
+ * @param mapKeyType
+ * @param attrName
+ * @param actName
+ * @param cu
+ * @param type
+ * @param isCollection
+ * @throws JavaModelException
+ */
+ private void createAttribute(IJPAEditorFeatureProvider fp,
+ JavaPersistentType 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,
+ mapKeyType, attrName, actName, cu, type);
+ } else {
+ createSimpleAttribute(attrTypeName, attrName, actName,
+ isCollection, type, attrTypeElementNames, annotationContents);
+ }
+ }
+
+ /**
+ * Creates a new attribute of a basic type.
+ *
+ * @param attributeType
+ * @param attributeName
+ * @param actName
+ * @param isCollection
+ * @param type
+ * @throws JavaModelException
+ */
+ private void createSimpleAttribute(String attributeType,
String attributeName, String actName, boolean isCollection,
- IType type) throws JavaModelException {
- type.createField(" private " + JPAEditorUtil.returnSimpleName(attributeType.getName()) + " " //$NON-NLS-1$ //$NON-NLS-2$
- + JPAEditorUtil.decapitalizeFirstLetter(actName) + ";", null, false, new NullProgressMonitor()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- type.createMethod(JpaArtifactFactory.instance().genGetterContents(attributeName,
- JPAEditorUtil.returnSimpleName(attributeType.getName()), null,
- actName, null, isCollection), null, false,
- new NullProgressMonitor());
- type.createMethod(JpaArtifactFactory.instance().genSetterContents(attributeName,
- JPAEditorUtil.returnSimpleName(attributeType.getName()), null,
- actName, isCollection), null, false,
- new NullProgressMonitor());
+ IType type, String[] attrTypeElementNames, String annotationContents) throws JavaModelException {
+
+
+ String attrFieldContent = " private " + attributeType + //$NON-NLS-1$
+ ((attrTypes == null) ? "" : ("<" + JPAEditorUtil.createCommaSeparatedListOfSimpleTypeNames(attrTypes) + ">")) + //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ " " + JPAEditorUtil.decapitalizeFirstLetter(actName) + ";"; //$NON-NLS-1$ //$NON-NLS-2$
+
+ String contents = "";
+ if(!JpaArtifactFactory.instance().isMethodAnnotated(jpt)){
+ contents = annotationContents + attrFieldContent;
+ } else {
+ contents = attrFieldContent;
+ }
+
+ type.createField(contents, null, false, new NullProgressMonitor()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+
+ type.createMethod(
+ genGetterContents(attributeName, attributeType, actName, attrTypeElementNames, annotationContents), null,
+ false, new NullProgressMonitor());
+ type.createMethod(
+ genSetterContents(attributeName, attributeType, actName, attrTypeElementNames), null,
+ false, new NullProgressMonitor());
}
+ /**
+ * 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
+ * @param attributeName
+ * @param actName
+ * @param cu
+ * @param type
+ * @throws JavaModelException
+ */
private void createAttributeOfCollectiontype(IJPAEditorFeatureProvider fp,
- JavaPersistentType jpt, JavaPersistentType attributeType,
- String mapKeyType, String attributeName, String actName,
- ICompilationUnit cu1, IType type) throws JavaModelException {
+ JavaPersistentType 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);
if (JPADiagramPropertyPage.isCollectionType(project, props)) {
createAttributeByCollectionMethodType(attributeType, null,
- attributeName, actName, cu1, type, JPAEditorConstants.COLLECTION_TYPE);
+ attributeName, actName, cu, type,
+ JPAEditorConstants.COLLECTION_TYPE);
} else if (JPADiagramPropertyPage.isListType(project, props)) {
createAttributeByCollectionMethodType(attributeType, null,
- attributeName, actName, cu1, type, JPAEditorConstants.LIST_TYPE);
+ attributeName, actName, cu, type,
+ JPAEditorConstants.LIST_TYPE);
} else if (JPADiagramPropertyPage.isSetType(project, props)) {
createAttributeByCollectionMethodType(attributeType, null,
- attributeName, actName, cu1, type, JPAEditorConstants.SET_TYPE);
+ attributeName, actName, cu, type,
+ JPAEditorConstants.SET_TYPE);
} else {
createAttributeByCollectionMethodType(attributeType, mapKeyType,
- attributeName, actName, cu1, type, JPAEditorConstants.MAP_TYPE);
+ attributeName, actName, cu, type,
+ JPAEditorConstants.MAP_TYPE);
}
}
-
- private void createAttributeByCollectionMethodType(
- JavaPersistentType attributeType, String mapKeyType, String attributeName,
- String actName, ICompilationUnit cu1, IType type, String collectionType)
+ /**
+ * Create attribute by the specified collection type in the
+ * Preference/Properties page.
+ *
+ * @param attributeType
+ * @param mapKeyType
+ * @param attributeName
+ * @param actName
+ * @param cu
+ * @param type
+ * @param collectionType
+ * @throws JavaModelException
+ */
+ private void createAttributeByCollectionMethodType(String attributeType,
+ String mapKeyType, String attributeName, String actName,
+ ICompilationUnit cu, IType type, String collectionType)
throws JavaModelException {
- mapKeyType = createContentType(mapKeyType, attributeType, actName, cu1, type, collectionType);
- type.createMethod(genGetterWithAppropriateType(attributeName, mapKeyType,
- JPAEditorUtil.returnSimpleName(attributeType.getName()),
- actName, collectionType), null, false,
+ mapKeyType = createContentType(mapKeyType, attributeType, actName, cu,
+ type, collectionType);
+ type.createMethod(
+ genGetterWithAppropriateType(attributeName, mapKeyType,
+ attributeType, actName, collectionType), null, false,
new NullProgressMonitor());
- type.createMethod(genSetterWithAppropriateType(attributeName, mapKeyType,
- JPAEditorUtil.returnSimpleName(attributeType.getName()),
- actName, collectionType), null, false,
+ type.createMethod(
+ genSetterWithAppropriateType(attributeName, mapKeyType,
+ attributeType, actName, collectionType), null, false,
new NullProgressMonitor());
}
-
- private String createContentType(String mapKeyType, JavaPersistentType attributeType,
- String actName, ICompilationUnit cu1, IType type, String collectionType)
- throws JavaModelException {
-
+
+ /**
+ * Create field in the entity by the specified collection type.
+ *
+ * @param mapKeyType
+ * @param attributeType
+ * @param actName
+ * @param cu
+ * @param type
+ * @param collectionType
+ * @return string representation of the field's collection type.
+ * @throws JavaModelException
+ */
+ private String createContentType(String mapKeyType, String attributeType,
+ String actName, ICompilationUnit cu, IType type,
+ String collectionType) throws JavaModelException {
+
if (mapKeyType != null) {
- mapKeyType = JPAEditorUtil.createImport(cu1, mapKeyType);
+ mapKeyType = JPAEditorUtil.createImport(cu, mapKeyType);
}
- JPAEditorUtil.createImport(cu1, collectionType);
+ JPAEditorUtil.createImport(cu, collectionType);
type.createField(
- " private " + JPAEditorUtil.returnSimpleName(collectionType) + "<" +//$NON-NLS-1$ //$NON-NLS-2$
- ((mapKeyType != null) ? (mapKeyType + ", ") : "") + //$NON-NLS-1$ //$NON-NLS-2$
- JPAEditorUtil.returnSimpleName(attributeType.getName()) + "> " + JPAEditorUtil.decapitalizeFirstLetter(actName) + //$NON-NLS-1$
- ";", null, false, new NullProgressMonitor()); //$NON-NLS-1$
+ " private " + JPAEditorUtil.returnSimpleName(collectionType) + "<" + //$NON-NLS-1$ //$NON-NLS-2$
+ ((mapKeyType != null) ? (mapKeyType + ", ") : "") + //$NON-NLS-1$ //$NON-NLS-2$
+ attributeType
+ + "> " + JPAEditorUtil.decapitalizeFirstLetter(actName) + //$NON-NLS-1$
+ ";", null, false, new NullProgressMonitor()); //$NON-NLS-1$
return mapKeyType;
}
-
- private String genGetterWithAppropriateType(String attrName, String mapKeyType, String attrType,
- String actName, String type) {
+
+ /**
+ * Create the attribute's getter method in entity's compilation unit with
+ * the appropriate collection type, selected in the Preference/Properties
+ * page.
+ *
+ * @param attrName
+ * - the name of the attribute
+ * @param attrType
+ * - the type of the attribute
+ * @param attrTypeElementNames
+ * @param actName
+ * @param isCollection
+ * @return the string representation of the attribute's getter method.
+ */
+ private String genGetterWithAppropriateType(String attrName,
+ String mapKeyType, String attrType, String actName, String type) {
String attrNameWithCapitalA = actName.substring(0, 1).toUpperCase(
Locale.ENGLISH)
+ actName.substring(1);
- String contents = " public " + JPAEditorUtil.returnSimpleName(type) + //$NON-NLS-1$
- "<" + ((mapKeyType != null) ? (mapKeyType + ", ") : "") + attrType + "> " + //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
- "get" + attrNameWithCapitalA + "() {\n" + //$NON-NLS-1$ //$NON-NLS-2$
- " return " //$NON-NLS-1$
- + JPAEditorUtil.decapitalizeFirstLetter(actName) + ";\n" + //$NON-NLS-1$
- " }\n"; //$NON-NLS-1$
+ String contents = " public " + JPAEditorUtil.returnSimpleName(type) + //$NON-NLS-1$
+ "<"
+ + ((mapKeyType != null) ? (mapKeyType + ", ") : "") + attrType + "> " + //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ "get" + attrNameWithCapitalA + "() {\n" + //$NON-NLS-1$ //$NON-NLS-2$
+ " return " //$NON-NLS-1$
+ + JPAEditorUtil.decapitalizeFirstLetter(actName) + ";\n" + //$NON-NLS-1$
+ " }\n"; //$NON-NLS-1$
return contents;
}
-
- private String genSetterWithAppropriateType(String attrName, String mapKeyType, String attrType,
- String actName, String type) {
+
+ /**
+ * Create the attribute's setter method in entity's compilation unit with
+ * the appropriate collection type, selected in the Preference/Properties
+ * page.
+ *
+ * @param attrName
+ * - the name of the attribute
+ * @param attrType
+ * - the type of the attribute
+ * @param attrTypeElementNames
+ * @param actName
+ * @param isCollection
+ * @return the string representation of the attribute's setter method.
+ */
+ private String genSetterWithAppropriateType(String attrName,
+ String mapKeyType, String attrType, String actName, String type) {
String attrNameWithCapitalA = actName.substring(0, 1).toUpperCase(
Locale.ENGLISH)
+ actName.substring(1);
- String contents = " public void set" + attrNameWithCapitalA + //$NON-NLS-1$
- "(" + JPAEditorUtil.returnSimpleName(type) + //$NON-NLS-1$
- "<" + ((mapKeyType != null) ? (mapKeyType + ", ") : "") + attrType + "> param) " + //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
- "{\n" + //$NON-NLS-1$
- " this." //$NON-NLS-1$
+ String contents = " public void set" + attrNameWithCapitalA + //$NON-NLS-1$
+ "("
+ + JPAEditorUtil.returnSimpleName(type)
+ + //$NON-NLS-1$
+ "<"
+ + ((mapKeyType != null) ? (mapKeyType + ", ") : "") + attrType + "> param) " + //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ "{\n"
+ + //$NON-NLS-1$
+ " this." //$NON-NLS-1$
+ JPAEditorUtil.decapitalizeFirstLetter(actName)
- + " = param;\n" + //$NON-NLS-1$
- " }\n"; //$NON-NLS-1$
+ + " = param;\n" + //$NON-NLS-1$
+ " }\n"; //$NON-NLS-1$
return contents;
}
-
+
+ /**
+ * Create the attribute's getter method in entity's compilation unit.
+ *
+ * @param attrName
+ * - the name of the attribute
+ * @param attrType
+ * - the type of the attribute
+ * @param actName
+ * @param annotationContents - the annotations as string representation
+ * @return the string representation of the attribute's getter method.
+ */
+ private String genGetterContents(String attrName, String attrType,
+ String actName, String[] attrTypeElementNames, String annotationContents) {
+
+ String attrNameWithCapitalA = actName.substring(0, 1).toUpperCase(
+ Locale.ENGLISH)
+ + actName.substring(1);
+
+ String contents = "";
+ if(JpaArtifactFactory.instance().isMethodAnnotated(jpt)){
+ contents += annotationContents;
+ }
+ contents += " public " + attrType + //$NON-NLS-1$
+ ((attrTypeElementNames == null) ? "" : ("<" + JPAEditorUtil.createCommaSeparatedListOfSimpleTypeNames(attrTypeElementNames) + ">")) + //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ (attrType.equals("boolean") ? " is" : " get") + attrNameWithCapitalA + "() {\n" + //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ " return " //$NON-NLS-1$
+ + JPAEditorUtil.decapitalizeFirstLetter(actName) + ";\n" + //$NON-NLS-1$
+ " }\n"; //$NON-NLS-1$
+
+ return contents;
+ }
+
+ /**
+ * Create the attribute's setter method in entity's compilation unit.
+ *
+ * @param attrName
+ * - the name of the attribute
+ * @param attrType
+ * - the type of the attribute
+ * @return the string representation of the attribute's setter method.
+ */
+ private String genSetterContents(String attrName, String attrType,
+ String actName, String[] attrTypeElementNames) {
+
+ String attrNameWithCapitalA = actName.substring(0, 1).toUpperCase(
+ Locale.ENGLISH) + actName.substring(1);
+
+ String contents = " public void set" + attrNameWithCapitalA + "(" + attrType + //$NON-NLS-1$ //$NON-NLS-2$
+ ((attrTypeElementNames == null) ? "" : ("<" + JPAEditorUtil.createCommaSeparatedListOfSimpleTypeNames(attrTypeElementNames) + ">")) + //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ " param) {\n" //$NON-NLS-1$
+ + " this." //$NON-NLS-1$
+ + JPAEditorUtil.decapitalizeFirstLetter(actName)
+ + " = param;\n" + //$NON-NLS-1$
+ " }\n";
+ return contents;
+ }
+
}
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/command/CreateNewAttributeCommand.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/command/CreateNewAttributeCommand.java deleted file mode 100644 index d6714dbf81..0000000000 --- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/command/CreateNewAttributeCommand.java +++ /dev/null @@ -1,126 +0,0 @@ -package org.eclipse.jpt.jpadiagrameditor.ui.internal.command;
-
-import java.util.Iterator;
-import java.util.List;
-
-import org.eclipse.core.runtime.NullProgressMonitor;
-import org.eclipse.jdt.core.ICompilationUnit;
-import org.eclipse.jdt.core.IImportDeclaration;
-import org.eclipse.jdt.core.IType;
-import org.eclipse.jdt.core.JavaModelException;
-import org.eclipse.jpt.common.utility.command.Command;
-import org.eclipse.jpt.jpa.core.context.java.JavaPersistentAttribute;
-import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType;
-import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JPAEditorUtil;
-import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JpaArtifactFactory;
-
-public class CreateNewAttributeCommand implements Command {
-
- private JavaPersistentType jpt;
- private ICompilationUnit cu;
- private String attrName;
- private String attrTypeName;
- private String[] attrTypes;
- private String actName;
- private List<String> annotations;
- private boolean isCollection;
- private boolean isMethodAnnotated;
-
- public CreateNewAttributeCommand(JavaPersistentType jpt,
- ICompilationUnit cu, String attrName, String attrTypeName,
- String[] attrTypes, String actName,
- List<String> annotations, boolean isCollection,
- boolean isMethodAnnotated){
- super();
- this.jpt = jpt;
- this.cu = cu;
- this.attrName = attrName;
- this.attrTypeName = attrTypeName;
- this.attrTypes = attrTypes;
- this.actName = actName;
- this.annotations = annotations;
- this.isCollection = isCollection;
- this.isMethodAnnotated = isMethodAnnotated;
- }
-
- public void execute() {
- try {
- IType type = cu.findPrimaryType();
- String contents = ""; //$NON-NLS-1$
- isMethodAnnotated = (annotations != null) && (!annotations.isEmpty()) ? isMethodAnnotated
- : JpaArtifactFactory.instance().isMethodAnnotated(jpt);
-
- if (!isMethodAnnotated) {
- if (annotations != null) {
- Iterator<String> it = annotations.iterator();
- while (it.hasNext()) {
- String an = it.next();
- contents += " " + an + "\n"; //$NON-NLS-1$ //$NON-NLS-2$
- }
- }
- }
-
- if(annotations!=null && annotations.contains("@Basic")){ //$NON-NLS-1$
- if(!cu.getImport("javax.persistence.*").exists() && !cu.getImport("javax.persistence.Basic").exists()){ //$NON-NLS-1$ //$NON-NLS-2$
- JPAEditorUtil.createImports(cu, "javax.persistence.Basic"); //$NON-NLS-1$
- }
- }
-
- boolean shouldAddImport = true;
- IImportDeclaration[] importDeclarations = cu.getImports();
- String attrShortTypeName = JPAEditorUtil.returnSimpleName(attrTypeName);
- for(IImportDeclaration importDecl : importDeclarations){
- String importedDeclarationFQN = importDecl.getElementName();
- String importedDeclarationShortName = JPAEditorUtil.returnSimpleName(importedDeclarationFQN);
- if(attrShortTypeName.equals(importedDeclarationShortName) && !attrTypeName.equals(importedDeclarationFQN))
- shouldAddImport = false;
- }
-
- if(shouldAddImport){
- JPAEditorUtil.createImports(cu, attrTypeName);
- attrTypeName = JPAEditorUtil.returnSimpleName(attrTypeName);
- }
- if ((attrTypes != null) && (attrTypes.length > 0)) {
- JPAEditorUtil.createImports(cu, attrTypes);
- }
-
- contents += " private " + attrTypeName + //$NON-NLS-1$
- ((attrTypes == null) ? "" : ("<" + JPAEditorUtil.createCommaSeparatedListOfSimpleTypeNames(attrTypes) + ">")) + //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- " " + attrName + ";"; //$NON-NLS-1$ //$NON-NLS-2$
-
- type.createMethod(
- JpaArtifactFactory.instance().genSetterContents(attrName, attrTypeName, attrTypes,
- actName, isCollection), null, false,
- new NullProgressMonitor());
- if (isMethodAnnotated) {
- type.createMethod(
- JpaArtifactFactory.instance().genGetterContents(attrName, attrTypeName,
- attrTypes, actName, annotations,
- isCollection), null, false,
- new NullProgressMonitor());
- type.createField(contents, null, false, new NullProgressMonitor());
- } else {
- type.createField(contents, null, false, new NullProgressMonitor());
- type.createMethod(
- JpaArtifactFactory.instance().genGetterContents(attrName, attrTypeName,
- attrTypes, actName, null, isCollection),
- null, false, new NullProgressMonitor());
- }
-
- } catch (JavaModelException e) {
-
- }
-
- JavaPersistentAttribute attr = jpt.getAttributeNamed(attrName);
- int cnt = 0;
- while ((attr == null) && (cnt < 25)) {
- try {
- Thread.sleep(250);
- } catch (InterruptedException e) {
- }
- jpt.getJavaResourceType().getJavaResourceCompilationUnit().synchronizeWithJavaSource();
- attr = jpt.getAttributeNamed(attrName);
- cnt++;
- }
- }
-}
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/command/DeleteAttributeCommand.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/command/DeleteAttributeCommand.java index 5877009dc2..1e42dc2300 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 @@ -1,3 +1,19 @@ +/*******************************************************************************
+ * <copyright>
+ *
+ * Copyright (c) 2012 SAP AG and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Petya Sabeva - initial API, implementation and documentation
+ *
+ * </copyright>
+ *
+ *******************************************************************************/
+
package org.eclipse.jpt.jpadiagrameditor.ui.internal.command;
import java.util.Locale;
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 37b4b0c119..9e6e5c7be2 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 @@ -1,3 +1,19 @@ +/*******************************************************************************
+ * <copyright>
+ *
+ * Copyright (c) 2012 SAP AG and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Petya Sabeva - initial API, implementation and documentation
+ *
+ * </copyright>
+ *
+ *******************************************************************************/
+
package org.eclipse.jpt.jpadiagrameditor.ui.internal.command;
import java.lang.reflect.InvocationTargetException;
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 f91a718a24..d62c293acb 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 @@ -1,3 +1,19 @@ +/*******************************************************************************
+ * <copyright>
+ *
+ * Copyright (c) 2012 SAP AG and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Petya Sabeva - initial API, implementation and documentation
+ *
+ * </copyright>
+ *
+ *******************************************************************************/
+
package org.eclipse.jpt.jpadiagrameditor.ui.internal.command;
import org.eclipse.jdt.core.ICompilationUnit;
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/command/SetMappedByNewValueCommand.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/command/SetMappedByNewValueCommand.java index 872c9a2a09..2da316d763 100644 --- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/command/SetMappedByNewValueCommand.java +++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/command/SetMappedByNewValueCommand.java @@ -1,3 +1,19 @@ +/*******************************************************************************
+ * <copyright>
+ *
+ * Copyright (c) 2012 SAP AG and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Petya Sabeva - initial API, implementation and documentation
+ *
+ * </copyright>
+ *
+ *******************************************************************************/
+
package org.eclipse.jpt.jpadiagrameditor.ui.internal.command;
import org.eclipse.jpt.common.core.resource.java.Annotation;
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/AddAllEntitiesFeature.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/AddAllEntitiesFeature.java index 1390704e81..70fe35a43c 100644 --- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/AddAllEntitiesFeature.java +++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/AddAllEntitiesFeature.java @@ -70,7 +70,6 @@ public class AddAllEntitiesFeature extends AbstractCustomFeature implements IAdd return true; } - @SuppressWarnings("restriction") public void execute(ICustomContext context) { Diagram d = getDiagram(); JpaProject project = getTargetJPAProject(); diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/AddHasReferenceRelationFeature.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/AddHasReferenceRelationFeature.java index 75dcf8e997..16ac69218d 100644 --- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/AddHasReferenceRelationFeature.java +++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/AddHasReferenceRelationFeature.java @@ -1,3 +1,19 @@ +/*******************************************************************************
+ * <copyright>
+ *
+ * Copyright (c) 2012 SAP AG and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Petya Sabeva - initial API, implementation and documentation
+ *
+ * </copyright>
+ *
+ *******************************************************************************/
+
package org.eclipse.jpt.jpadiagrameditor.ui.internal.feature;
import static org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.HasReferanceRelation.HasReferenceType.COLLECTION;
@@ -87,7 +103,6 @@ public class AddHasReferenceRelationFeature extends AbstractAddFeature { IAddBendpointFeature ft = getFeatureProvider().getAddBendpointFeature(ctx);
ft.addBendpoint(ctx);
}
- getFeatureProvider().getPeServiceUtil().setPropertyValue(connection, HasReferanceRelation.HAS_REFERENCE_CONNECTION_PROP_KEY, Boolean.TRUE.toString());
addDecorators(connection, relation);
addTextDecorators(connection, relation);
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 4d9a785d08..8cc319bc9f 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 @@ -53,7 +53,7 @@ public class ClickAddAttributeButtonFeature extends AbstractCreateFeature { JavaPersistentType jpt = (JavaPersistentType)getFeatureProvider().getBusinessObjectForPictogramElement(entityShape); String newAttrName = JpaArtifactFactory.instance().createNewAttribute(jpt, false, getFeatureProvider()); - JavaPersistentAttribute newAttr = jpt.getAttributeNamed(newAttrName); + JavaPersistentAttribute newAttr = (JavaPersistentAttribute) jpt.resolveAttribute(newAttrName); getFeatureProvider().addAddIgnore((JavaPersistentType)newAttr.getParent(), newAttr.getName()); addGraphicalRepresentation(context, newAttr); 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 new file mode 100644 index 0000000000..ac1e6d888b --- /dev/null +++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/ClickAddElementCollectionButtonFeature.java @@ -0,0 +1,89 @@ +/*******************************************************************************
+ * <copyright>
+ *
+ * Copyright (c) 2012 SAP AG and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Petya Sabeva - initial API, implementation and documentation
+ *
+ * </copyright>
+ *
+ *******************************************************************************/
+
+package org.eclipse.jpt.jpadiagrameditor.ui.internal.feature;
+
+import org.eclipse.graphiti.features.IFeatureProvider;
+import org.eclipse.graphiti.features.context.IContext;
+import org.eclipse.graphiti.features.context.ICreateContext;
+import org.eclipse.graphiti.features.impl.AbstractCreateFeature;
+import org.eclipse.graphiti.mm.pictograms.ContainerShape;
+import org.eclipse.jdt.core.ICompilationUnit;
+import org.eclipse.jpt.jpa.core.context.java.JavaPersistentAttribute;
+import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType;
+import org.eclipse.jpt.jpa.core.jpa2.MappingKeys2_0;
+import org.eclipse.jpt.jpa.core.jpa2.resource.java.ElementCollection2_0Annotation;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.i18n.JPAEditorMessages;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.IJPAEditorFeatureProvider;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JpaArtifactFactory;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IWorkbenchSite;
+
+public class ClickAddElementCollectionButtonFeature extends AbstractCreateFeature {
+
+ public ClickAddElementCollectionButtonFeature(IFeatureProvider provider) {
+ super(provider, "", ""); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public boolean canExecute(IContext context) {
+ return true;
+ }
+
+ public boolean canUndo(IContext context) {
+ return false;
+ }
+
+ public boolean canCreate(ICreateContext context) {
+ return true;
+ }
+
+ public Object[] create(ICreateContext context) {
+ ContainerShape entityShape = context.getTargetContainer();
+ JavaPersistentType jpt = (JavaPersistentType)getFeatureProvider().getBusinessObjectForPictogramElement(entityShape);
+ String newAttrName = JpaArtifactFactory.instance().createNewAttribute(jpt, true, getFeatureProvider());
+
+ JavaPersistentAttribute newAttr = (JavaPersistentAttribute) jpt.resolveAttribute(newAttrName);
+ newAttr.setMappingKey(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY);
+ newAttr.getResourceAttribute().addAnnotation(ElementCollection2_0Annotation.ANNOTATION_NAME);
+
+ getFeatureProvider().addAddIgnore((JavaPersistentType)newAttr.getParent(), newAttr.getName());
+ addGraphicalRepresentation(context, newAttr);
+ getFeatureProvider().getDirectEditingInfo().setActive(true);
+
+ IWorkbenchSite ws = ((IEditorPart)getDiagramEditor()).getSite();
+ ICompilationUnit cu = getFeatureProvider().getCompilationUnit(jpt);
+ getFeatureProvider().getJPAEditorUtil().formatCode(cu, ws);
+
+ return new Object[] {newAttr};
+ }
+
+ public boolean isAvailable(IContext context) {
+ return true;
+ }
+
+ public String getName() {
+ return JPAEditorMessages.ClickAddElementCollectionButtonFeature_CreateElementCollectionAttributeFeatureName;
+ }
+
+ public String getDescription() {
+ return JPAEditorMessages.ClickAddElementCollectionButtonFeature_CreateElementCollectionAttributeFeatureDescription;
+ }
+
+ 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/CreateEmbeddableFeature.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateEmbeddableFeature.java index f25fa0f0d7..7f73f3eb15 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 @@ -1,3 +1,19 @@ +/*******************************************************************************
+ * <copyright>
+ *
+ * Copyright (c) 2012 SAP AG and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Petya Sabeva - initial API, implementation and documentation
+ *
+ * </copyright>
+ *
+ *******************************************************************************/
+
package org.eclipse.jpt.jpadiagrameditor.ui.internal.feature;
import java.util.List;
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateInheritedEntityFeature.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateInheritedEntityFeature.java index e7f47cd621..6947fa7d9d 100644 --- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateInheritedEntityFeature.java +++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateInheritedEntityFeature.java @@ -120,7 +120,6 @@ public class CreateInheritedEntityFeature extends AbstractCreateConnectionFeatur disableAllNotValidJPTs(); } - @SuppressWarnings("restriction") private void disableAllNotValidJPTs(){ Diagram d = getDiagram(); JpaProject project = ModelIntegrationUtil.getProjectByDiagram(d.getName()); 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 02d90ba43b..db45096d71 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 @@ -100,7 +100,6 @@ public class CreateJPAEntityFeature extends AbstractCreateFeature { return context.getTargetContainer() instanceof Diagram; } - @SuppressWarnings("restriction") public Object[] create(ICreateContext context) { List<Shape> shapes = this.getFeatureProvider().getDiagramTypeProvider().getDiagram().getChildren(); IProject targetProject = null; diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateManyToManyBiDirRelationFeature.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateManyToManyBiDirRelationFeature.java index af75f9471b..db16e24e0f 100644 --- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateManyToManyBiDirRelationFeature.java +++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateManyToManyBiDirRelationFeature.java @@ -1,7 +1,7 @@ /******************************************************************************* * <copyright> * - * Copyright (c) 2005, 2010 SAP AG. + * Copyright (c) 2005, 2012 SAP AG. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateManyToManyUniDirRelationFeature.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateManyToManyUniDirRelationFeature.java index f227422c4a..81fe2d39db 100644 --- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateManyToManyUniDirRelationFeature.java +++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateManyToManyUniDirRelationFeature.java @@ -1,7 +1,7 @@ /******************************************************************************* * <copyright> * - * Copyright (c) 2005, 2010 SAP AG. + * Copyright (c) 2005, 2012 SAP AG. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateManyToOneBiDirRelationFeature.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateManyToOneBiDirRelationFeature.java index 1c6e2ff76f..e18cd35e64 100644 --- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateManyToOneBiDirRelationFeature.java +++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateManyToOneBiDirRelationFeature.java @@ -1,7 +1,7 @@ /******************************************************************************* * <copyright> * - * Copyright (c) 2005, 2010 SAP AG. + * Copyright (c) 2005, 2012 SAP AG. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateManyToOneUniDirRelationFeature.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateManyToOneUniDirRelationFeature.java index 7280e65ef8..560e49cf19 100644 --- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateManyToOneUniDirRelationFeature.java +++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateManyToOneUniDirRelationFeature.java @@ -1,7 +1,7 @@ /******************************************************************************* * <copyright> * - * Copyright (c) 2005, 2010 SAP AG. + * Copyright (c) 2005, 2012 SAP AG. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateOneToManyRelationFeature.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateOneToManyRelationFeature.java index bf531a090d..a448461134 100644 --- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateOneToManyRelationFeature.java +++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateOneToManyRelationFeature.java @@ -1,7 +1,7 @@ /******************************************************************************* * <copyright> * - * Copyright (c) 2005, 2010 SAP AG. + * Copyright (c) 2005, 2012 SAP AG. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateOneToOneBiDirRelationFeature.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateOneToOneBiDirRelationFeature.java index 6fb57c291d..689fbf9c8a 100644 --- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateOneToOneBiDirRelationFeature.java +++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateOneToOneBiDirRelationFeature.java @@ -1,7 +1,7 @@ /******************************************************************************* * <copyright> * - * Copyright (c) 2005, 2010 SAP AG. + * Copyright (c) 2005, 2012 SAP AG. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateOneToOneUniDirRelationFeature.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateOneToOneUniDirRelationFeature.java index 1e556db826..6036ef3626 100644 --- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateOneToOneUniDirRelationFeature.java +++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateOneToOneUniDirRelationFeature.java @@ -1,7 +1,7 @@ /******************************************************************************* * <copyright> * - * Copyright (c) 2005, 2010 SAP AG. + * Copyright (c) 2005, 2012 SAP AG. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateRelationFeature.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateRelationFeature.java index 6149fa84e8..fd6aef9a64 100644 --- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateRelationFeature.java +++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateRelationFeature.java @@ -1,7 +1,7 @@ /******************************************************************************* * <copyright> * - * Copyright (c) 2005, 2010 SAP AG. + * Copyright (c) 2005, 2012 SAP AG. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -173,7 +173,6 @@ abstract public class CreateRelationFeature extends AbstractCreateConnectionFeat * For each unvalid relationship's target, change the color of the respective * java persistent type in gray to simulate disability of the persistent type. */ - @SuppressWarnings("restriction") private void disableUnvalidRelationTargets(){ Diagram d = getDiagram(); JpaProject project = ModelIntegrationUtil.getProjectByDiagram(d.getName()); @@ -234,7 +233,6 @@ abstract public class CreateRelationFeature extends AbstractCreateConnectionFeat * registered in the persistence unit. * @param unit */ - @SuppressWarnings("restriction") private void disableAllEmbeddables() { Diagram d = getDiagram(); JpaProject project = ModelIntegrationUtil.getProjectByDiagram(d.getName()); 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 90368bf803..cd293a767b 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 @@ -1,3 +1,19 @@ +/*******************************************************************************
+ * <copyright>
+ *
+ * Copyright (c) 2012 SAP AG and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Petya Sabeva - initial API, implementation and documentation
+ *
+ * </copyright>
+ *
+ *******************************************************************************/
+
package org.eclipse.jpt.jpadiagrameditor.ui.internal.feature;
import java.util.Set;
@@ -14,6 +30,7 @@ import org.eclipse.jpt.jpa.core.context.Embeddable; import org.eclipse.jpt.jpa.core.context.Entity;
import org.eclipse.jpt.jpa.core.context.MappedSuperclass;
import org.eclipse.jpt.jpa.core.context.PersistentType;
+import org.eclipse.jpt.jpa.core.context.ReadOnlyPersistentAttribute;
import org.eclipse.jpt.jpa.core.context.java.JavaPersistentAttribute;
import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType;
import org.eclipse.jpt.jpa.core.context.persistence.ClassRef;
@@ -139,13 +156,21 @@ public class EmbedCollectionOfObjectsFeature extends AbstractCreateConnectionFea /**
* Checks whether the connection is possible. If the source of the connection is embeddable and it already
* embeds in itself an element collection of another embeddable, or if the target of the connection is already
- * embedded as an element connection in some entity, then the connection is not allowed by specification.
+ * embedded as an element connection in some entity, or the if the target embeddable contains an attribute with
+ * mapping element-collection, then the connection is not allowed by specification.
* @param embeddingEntity - the source entity of the connection
* @param embeddable - the target entity of the connection
* @return true if the connection is possible, false otherwise.
*/
private boolean isNotAllowed(JavaPersistentType embeddingEntity, JavaPersistentType embeddable){
boolean notAllowed = false;
+ if(JpaArtifactFactory.instance().hasEmbeddableAnnotation(embeddable)){
+ for(ReadOnlyPersistentAttribute attr : embeddable.getAllAttributes()){
+ if(attr.getMappingKey().equals(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY)){
+ return true;
+ }
+ }
+ }
if(JpaArtifactFactory.instance().hasEmbeddableAnnotation(embeddingEntity)){
notAllowed = isEmbeddableAlreadyEmbeddedAsElementCollection(embeddingEntity, false);
} else if(JpaArtifactFactory.instance().hasEntityAnnotation(embeddingEntity)){
@@ -181,7 +206,6 @@ public class EmbedCollectionOfObjectsFeature extends AbstractCreateConnectionFea * For each unvalid relationship's target, change the color of the respective
* java persistent type in gray to simulate disability of the persistent type.
*/
- @SuppressWarnings("restriction")
private void disableUnvalidRelationTargets(){
Diagram d = getDiagram();
JpaProject project = ModelIntegrationUtil.getProjectByDiagram(d.getName());
@@ -233,7 +257,6 @@ public class EmbedCollectionOfObjectsFeature extends AbstractCreateConnectionFea * registered in the persistence unit.
* @param unit
*/
- @SuppressWarnings("restriction")
private void disableAllMappedSuperclasses() {
Diagram d = getDiagram();
JpaProject project = ModelIntegrationUtil.getProjectByDiagram(d.getName());
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 72fe587cb9..b41f28ce6e 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 @@ -1,3 +1,19 @@ +/*******************************************************************************
+ * <copyright>
+ *
+ * Copyright (c) 2012 SAP AG and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Petya Sabeva - initial API, implementation and documentation
+ *
+ * </copyright>
+ *
+ *******************************************************************************/
+
package org.eclipse.jpt.jpadiagrameditor.ui.internal.feature;
import org.eclipse.graphiti.features.IFeatureProvider;
@@ -130,7 +146,6 @@ public class EmbedSingleObjectFeature extends AbstractCreateConnectionFeature { * For each unvalid relationship's target, change the color of the respective
* java persistent type in gray to simulate disability of the persistent type.
*/
- @SuppressWarnings("restriction")
private void disableUnvalidRelationTargets(){
Diagram d = getDiagram();
JpaProject project = ModelIntegrationUtil.getProjectByDiagram(d.getName());
@@ -169,7 +184,6 @@ public class EmbedSingleObjectFeature extends AbstractCreateConnectionFeature { * registered in the persistence unit.
* @param unit
*/
- @SuppressWarnings("restriction")
private void disableAllMappedSuperclasses() {
Diagram d = getDiagram();
JpaProject project = ModelIntegrationUtil.getProjectByDiagram(d.getName());
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 c5c4387291..24fb6c8ea6 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 @@ -1,7 +1,7 @@ /******************************************************************************* * <copyright> * - * Copyright (c) 2005, 2011 SAP AG. + * Copyright (c) 2005, 2012 SAP AG. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -17,6 +17,7 @@ package org.eclipse.jpt.jpadiagrameditor.ui.internal.feature; import java.text.MessageFormat; import java.util.List; + import org.eclipse.graphiti.features.IFeatureProvider; import org.eclipse.graphiti.features.context.ICustomContext; import org.eclipse.graphiti.features.custom.AbstractCustomFeature; @@ -25,7 +26,6 @@ import org.eclipse.graphiti.mm.pictograms.Shape; import org.eclipse.jdt.core.ICompilationUnit; import org.eclipse.jface.dialogs.IDialogConstants; import org.eclipse.jpt.common.core.resource.java.JavaResourceAttribute; -import org.eclipse.jpt.common.core.resource.java.JavaResourceAnnotatedElement.Kind; import org.eclipse.jpt.jpa.core.context.PersistentType; import org.eclipse.jpt.jpa.core.context.java.JavaPersistentAttribute; import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType; @@ -37,10 +37,7 @@ import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JpaArtifactFactory; import org.eclipse.ui.IEditorPart; import org.eclipse.ui.IWorkbenchSite; - public class RefactorAttributeTypeFeature extends AbstractCustomFeature { - - //private static final TracerI tracer = TracingManager.getTracer(RefactorAttributeTypeFeature.class); public RefactorAttributeTypeFeature(IFeatureProvider fp) { super(fp); @@ -72,18 +69,20 @@ public class RefactorAttributeTypeFeature extends AbstractCustomFeature { getFeatureProvider().addAddIgnore((JavaPersistentType)jpa.getParent(), jpa.getName()); JavaResourceAttribute jra = jpa.getResourceAttribute(); getFeatureProvider().addRemoveIgnore((JavaPersistentType)jpa.getParent(), jra.getName()); - boolean isMethodAnnotated = jra.getKind() == Kind.METHOD; List<String> annotations = JpaArtifactFactory.instance().getAnnotationStrings(jpa); JpaArtifactFactory.instance().deleteAttribute((JavaPersistentType)jpa.getParent(), jpa.getName(), - getFeatureProvider()); - JavaPersistentAttribute newAt = JpaArtifactFactory.instance().createANewAttribute((JavaPersistentType)jpa.getParent(), - jpa.getName(), newTypeName, attributeTypeTypeNames, jpa.getName(), annotations, - false, isMethodAnnotated, getFeatureProvider()); + getFeatureProvider()); + + JavaPersistentAttribute newAt = JpaArtifactFactory.instance().makeNewAttribute(getFeatureProvider(), (JavaPersistentType)jpa.getParent(), + null, jpa.getName(), newTypeName, jpa.getName(), newTypeName, attributeTypeTypeNames, annotations, false); + getFeatureProvider().replaceAttribute(jpa, newAt); + IWorkbenchSite ws = ((IEditorPart)getDiagramEditor()).getSite(); ICompilationUnit cu = getFeatureProvider().getCompilationUnit((JavaPersistentType)newAt.getParent()); - getFeatureProvider().getJPAEditorUtil().formatCode(cu, ws); + getFeatureProvider().getJPAEditorUtil().formatCode(cu, ws); + JPAEditorUtil.organizeImports(cu, ws); JpaArtifactFactory.instance().remakeRelations(getFeatureProvider(), ((Shape)pe).getContainer(), (JavaPersistentType)newAt.getParent()); } diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/i18n/JPAEditorMessages.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/i18n/JPAEditorMessages.java index c57792706f..08c8b4192c 100644 --- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/i18n/JPAEditorMessages.java +++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/i18n/JPAEditorMessages.java @@ -29,6 +29,10 @@ public class JPAEditorMessages extends NLS { public static String ClickAddAttributeButtonFeature_createAttributeButtonDescription; public static String ClickAddAttributeButtonFeature_createAttributeButtonLabel; + public static String ClickAddElementCollectionButtonFeature_CreateElementCollectionAttributeFeatureDescription; + + public static String ClickAddElementCollectionButtonFeature_CreateElementCollectionAttributeFeatureName; + public static String ClickRemoveAttributeButtonFeature_createAttributeButtonDescription; public static String ClickRemoveAttributeButtonFeature_createAttributeButtonlabel; public static String ClickRemoveAttributeButtonFeature_deleteAttributeQuestion; @@ -176,6 +180,9 @@ public class JPAEditorMessages extends NLS { public static String JPAEditorToolBehaviorProvider_openMiniatureViewDesc; public static String JPAEditorToolBehaviorProvider_CompositionPaletteName; + + public static String JPAEditorToolBehaviorProvider_CreateElementCollectionAttributeButtonLabel; + public static String JPAEditorToolBehaviorProvider_CreateElementCollectionAttributeButtonDescription; public static String JPAEditorToolBehaviorProvider_expandAttrMenuItem; public static String JPAEditorToolBehaviorProvider_expandAttrMenuItemDescr; diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/i18n/messages.properties b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/i18n/messages.properties index 4f1314a53c..17ffd80baf 100644 --- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/i18n/messages.properties +++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/i18n/messages.properties @@ -18,6 +18,8 @@ AddJPAEntityFeature_primaryKeysShape=Primary Key AddJPAEntityFeature_relationAttributesShapes=Relation Attributes ClickAddAttributeButtonFeature_createAttributeButtonDescription=Create a new attribute of this persistent type. ClickAddAttributeButtonFeature_createAttributeButtonLabel=Create Attribute +ClickAddElementCollectionButtonFeature_CreateElementCollectionAttributeFeatureDescription=Create a new attribute of a basic collection type in the persistent type. +ClickAddElementCollectionButtonFeature_CreateElementCollectionAttributeFeatureName=Create Collection Attribute ClickRemoveAttributeButtonFeature_createAttributeButtonDescription=Create a new attribute of this persistent type. ClickRemoveAttributeButtonFeature_createAttributeButtonlabel=Create Attribute @@ -148,6 +150,8 @@ JPAEditorToolBehaviorProvider_openJPADetailsViewDesc=Open the JPA Details view t JPAEditorToolBehaviorProvider_openMiniatureView=Open Miniature View JPAEditorToolBehaviorProvider_openMiniatureViewDesc=Open the Miniature view to display the diagram in a larger scale. JPAEditorToolBehaviorProvider_CompositionPaletteName=Composition +JPAEditorToolBehaviorProvider_CreateElementCollectionAttributeButtonLabel=Create Collection Attribute +JPAEditorToolBehaviorProvider_CreateElementCollectionAttributeButtonDescription=Create a new attribute of a basic collection type in the persistent type. JPAEditorToolBehaviorProvider_expandAttrMenuItem=Expand Attributes Group JPAEditorToolBehaviorProvider_expandAttrMenuItemDescr=Expand the attributes group. JPAEditorToolBehaviorProvider_expandCompartToolTip=Double click to expand "{0}" attributes group. diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/modelintegration/util/ModelIntegrationUtil.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/modelintegration/util/ModelIntegrationUtil.java index 2a6001046a..bb49a5084d 100644 --- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/modelintegration/util/ModelIntegrationUtil.java +++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/modelintegration/util/ModelIntegrationUtil.java @@ -1,7 +1,7 @@ /******************************************************************************* * <copyright> * - * Copyright (c) 2005, 2011 SAP AG and others. + * Copyright (c) 2005, 2012 SAP AG and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/provider/IJPAEditorFeatureProvider.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/provider/IJPAEditorFeatureProvider.java index c12e148b6a..d1d8397399 100644 --- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/provider/IJPAEditorFeatureProvider.java +++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/provider/IJPAEditorFeatureProvider.java @@ -1,7 +1,7 @@ /******************************************************************************* * <copyright> * - * Copyright (c) 2005, 2010 SAP AG. + * Copyright (c) 2005, 2012 SAP AG. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/provider/IJPAEditorImageCreator.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/provider/IJPAEditorImageCreator.java index 9baccf6905..a4caab9018 100644 --- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/provider/IJPAEditorImageCreator.java +++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/provider/IJPAEditorImageCreator.java @@ -1,7 +1,7 @@ /******************************************************************************* * <copyright> * - * Copyright (c) 2005, 2010 SAP AG. + * Copyright (c) 2005, 2012 SAP AG. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at 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 53655ffc3c..da59395e4e 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 @@ -84,6 +84,7 @@ import org.eclipse.jpt.jpadiagrameditor.ui.internal.feature.AddHasReferenceRelat import org.eclipse.jpt.jpadiagrameditor.ui.internal.feature.AddJPAEntityFeature; import org.eclipse.jpt.jpadiagrameditor.ui.internal.feature.AddRelationFeature; import org.eclipse.jpt.jpadiagrameditor.ui.internal.feature.ClickAddAttributeButtonFeature; +import org.eclipse.jpt.jpadiagrameditor.ui.internal.feature.ClickAddElementCollectionButtonFeature; import org.eclipse.jpt.jpadiagrameditor.ui.internal.feature.ClickRemoveAttributeButtonFeature; import org.eclipse.jpt.jpadiagrameditor.ui.internal.feature.CollapseAllEntitiesFeature; import org.eclipse.jpt.jpadiagrameditor.ui.internal.feature.CollapseCompartmentShapeFeature; @@ -144,6 +145,8 @@ import org.eclipse.ui.PlatformUI; public class JPAEditorFeatureProvider extends DefaultFeatureProvider implements IJPAEditorFeatureProvider { private ClickAddAttributeButtonFeature clickAddAttBtnFeat = null; + private ClickAddElementCollectionButtonFeature clickAddCollectionAttBtnFeat = null; + private ClickRemoveAttributeButtonFeature clickRemoveAttBtnFeat = null; private IPeServiceUtil peServiceUtil = new PeServiceUtilImpl(); private IPeService peService = Graphiti.getPeService(); @@ -189,12 +192,14 @@ public class JPAEditorFeatureProvider extends DefaultFeatureProvider implements EList<Connection> allCons = getDiagram().getConnections(); HashSet<HasReferanceRelation> res = new HashSet<HasReferanceRelation>(); for (Connection conn : allCons) { - if (HasReferanceRelation.isHasReferenceConnection(conn)) - try { - HasReferanceRelation hasReferenceRelation = (HasReferanceRelation) getBusinessObjectForPictogramElement(conn); + try { + Object ob = getBusinessObjectForPictogramElement(conn); + if(ob instanceof HasReferanceRelation) { + HasReferanceRelation hasReferenceRelation = (HasReferanceRelation) ob; res.add(hasReferenceRelation); - } catch (NullPointerException e) { } + } catch (NullPointerException e) { + } } return res; } @@ -494,6 +499,13 @@ public class JPAEditorFeatureProvider extends DefaultFeatureProvider implements return clickAddAttBtnFeat; } + public ClickAddElementCollectionButtonFeature getClickAddElementCollectionButtonFeature() { + if (clickAddCollectionAttBtnFeat == null) { + clickAddCollectionAttBtnFeat = new ClickAddElementCollectionButtonFeature(this); + } + return clickAddCollectionAttBtnFeat; + } + public ClickRemoveAttributeButtonFeature getClickRemoveAttributeButtonFeature() { if (clickRemoveAttBtnFeat == null) { clickRemoveAttBtnFeat = new ClickRemoveAttributeButtonFeature(this); diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/provider/JPAEditorImageCreator.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/provider/JPAEditorImageCreator.java index 75efe4a261..403ca00799 100644 --- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/provider/JPAEditorImageCreator.java +++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/provider/JPAEditorImageCreator.java @@ -1,7 +1,7 @@ /******************************************************************************* * <copyright> * - * Copyright (c) 2005, 2010 SAP AG. + * Copyright (c) 2005, 2012 SAP AG. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/provider/JPAEditorImageProvider.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/provider/JPAEditorImageProvider.java index 824c9b2c7f..224a860b77 100644 --- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/provider/JPAEditorImageProvider.java +++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/provider/JPAEditorImageProvider.java @@ -1,7 +1,7 @@ /******************************************************************************* * <copyright> * - * Copyright (c) 2005, 2010 SAP AG. + * Copyright (c) 2005, 2012 SAP AG. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -24,15 +24,16 @@ public class JPAEditorImageProvider extends AbstractImageProvider { public static final String JPA_ENTITY = PREFIX + "entity"; //$NON-NLS-1$ public static final String MAPPED_SUPERCLASS = PREFIX + "mapped_superclass"; //$NON-NLS-1$ - public static final String EMBEDDABLE = PREFIX + "embeddable"; //$NON-NLS-1$ + public static final String EMBEDDABLE = PREFIX + "embeddable"; //$NON-NLS-1$ public static final String ADD_JPA_ENTITY = PREFIX + "add_entity"; //$NON-NLS-1$ public static final String ADD_INHERITED_ENTITY = PREFIX + "add_inherited_entity"; //$NON-NLS-1$ public static final String ADD_MAPPED_SUPERCLASS = PREFIX + "add_mapped_superclass"; //$NON-NLS-1$ - public static final String ADD_EMBEDDABLE = PREFIX + "add_embeddable"; //$NON-NLS-1$ + public static final String ADD_EMBEDDABLE = PREFIX + "add_embeddable"; //$NON-NLS-1$ public static final String PRIMARY_KEY = PREFIX + "pk"; //$NON-NLS-1$ public static final String ICON_BASIC = PREFIX + "field"; //$NON-NLS-1$ public static final String ADD_ATTRIBUTE = PREFIX + "add_attribute"; //$NON-NLS-1$ + public static final String ADD_ELEMENT_COLLECTION = PREFIX + "add_element-collection.gif"; //$NON-NLS-1$ public static final String REMOVE_ATTRIBUTE = PREFIX + "remove_attribute"; //$NON-NLS-1$ public static final String ICON_ONE_TO_ONE = PREFIX + "one_to_one_relation"; //$NON-NLS-1$ public static final String ICON_ONE_TO_MANY = PREFIX + "one_to_many_relation"; //$NON-NLS-1$ @@ -42,7 +43,7 @@ public class JPAEditorImageProvider extends AbstractImageProvider { public static final String ICON_VERSION = PREFIX + "version"; //$NON-NLS-1$ public static final String ICON_TRANSIENT = PREFIX + "transient"; //$NON-NLS-1$ public static final String ICON_EMBEDDED = PREFIX + "embedded"; //$NON-NLS-1$ - public static final String ICON_ELEMENT_COLLECTION = PREFIX + "element-collection"; //$NON-NLS-1$ + public static final String ICON_ELEMENT_COLLECTION = PREFIX + "element-collection"; //$NON-NLS-1$ public static final String ICON_UNMAPPED = PREFIX + "unmapped"; //$NON-NLS-1$ @@ -71,13 +72,14 @@ public class JPAEditorImageProvider extends AbstractImageProvider { addImageFilePath(ICON_BASIC, ROOT_FOLDER_FOR_IMG + "ent/basic.gif"); //$NON-NLS-1$ addImageFilePath(JPA_ENTITY, ROOT_FOLDER_FOR_IMG + "ent/entity.gif"); //$NON-NLS-1$ addImageFilePath(MAPPED_SUPERCLASS, ROOT_FOLDER_FOR_IMG + "ent/mapped-superclass.gif"); //$NON-NLS-1$ - addImageFilePath(EMBEDDABLE, ROOT_FOLDER_FOR_IMG + "ent/embeddable.gif"); //$NON-NLS-1$ + addImageFilePath(EMBEDDABLE, ROOT_FOLDER_FOR_IMG + "ent/embeddable.gif"); //$NON-NLS-1$ addImageFilePath(ADD_JPA_ENTITY, ROOT_FOLDER_FOR_IMG + "ent/add_entity.gif"); //$NON-NLS-1$ addImageFilePath(ADD_INHERITED_ENTITY, ROOT_FOLDER_FOR_IMG + "ent/add_entity.gif"); //$NON-NLS-1$ addImageFilePath(ADD_MAPPED_SUPERCLASS, ROOT_FOLDER_FOR_IMG + "ent/add_mapped-superclass.gif"); //$NON-NLS-1$ - addImageFilePath(ADD_EMBEDDABLE, ROOT_FOLDER_FOR_IMG + "ent/add_embeddable.gif"); //$NON-NLS-1$ + addImageFilePath(ADD_EMBEDDABLE, ROOT_FOLDER_FOR_IMG + "ent/add_embeddable.gif"); //$NON-NLS-1$ addImageFilePath(PRIMARY_KEY, ROOT_FOLDER_FOR_IMG + "ent/id.gif"); //$NON-NLS-1$ addImageFilePath(ADD_ATTRIBUTE, ROOT_FOLDER_FOR_IMG + "ent/add_attribute.gif"); //$NON-NLS-1$ + addImageFilePath(ADD_ELEMENT_COLLECTION, ROOT_FOLDER_FOR_IMG + "ent/add_element-collection.gif"); //$NON-NLS-1$ addImageFilePath(REMOVE_ATTRIBUTE, ROOT_FOLDER_FOR_IMG + "ent/remove_attribute.gif"); //$NON-NLS-1$ addImageFilePath(ICON_ONE_TO_ONE, ROOT_FOLDER_FOR_IMG + "ent/one-to-one.gif"); //$NON-NLS-1$ addImageFilePath(ICON_ONE_TO_MANY, ROOT_FOLDER_FOR_IMG + "ent/one-to-many.gif"); //$NON-NLS-1$ @@ -87,7 +89,7 @@ public class JPAEditorImageProvider extends AbstractImageProvider { addImageFilePath(ICON_VERSION, ROOT_FOLDER_FOR_IMG + "ent/version.gif"); //$NON-NLS-1$ addImageFilePath(ICON_TRANSIENT, ROOT_FOLDER_FOR_IMG + "ent/transient.gif"); //$NON-NLS-1$ addImageFilePath(ICON_EMBEDDED, ROOT_FOLDER_FOR_IMG + "ent/embedded.gif"); //$NON-NLS-1$ - addImageFilePath(ICON_ELEMENT_COLLECTION, ROOT_FOLDER_FOR_IMG + "ent/element-collection.gif"); //$NON-NLS-1$ + addImageFilePath(ICON_ELEMENT_COLLECTION, ROOT_FOLDER_FOR_IMG + "ent/element-collection.gif"); //$NON-NLS-1$ addImageFilePath(ICON_UNMAPPED, ROOT_FOLDER_FOR_IMG + "ent/null-attribute-mapping.gif"); //$NON-NLS-1$ addImageFilePath(ICON_ONE_TO_ONE_1_DIR, ROOT_FOLDER_FOR_IMG + "ent/one-to-one-1-dir.gif"); //$NON-NLS-1$ diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/provider/JPAEditorToolBehaviorProvider.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/provider/JPAEditorToolBehaviorProvider.java index bc02b90b7d..f4d319c145 100644 --- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/provider/JPAEditorToolBehaviorProvider.java +++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/provider/JPAEditorToolBehaviorProvider.java @@ -1,7 +1,7 @@ /******************************************************************************* * <copyright> * - * Copyright (c) 2005, 2010 SAP AG. + * Copyright (c) 2005, 2012 SAP AG. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -66,6 +66,7 @@ import org.eclipse.jpt.jpadiagrameditor.ui.internal.JPADiagramEditorPlugin; import org.eclipse.jpt.jpadiagrameditor.ui.internal.facade.EclipseFacade; import org.eclipse.jpt.jpadiagrameditor.ui.internal.feature.AddAllEntitiesFeature; import org.eclipse.jpt.jpadiagrameditor.ui.internal.feature.ClickAddAttributeButtonFeature; +import org.eclipse.jpt.jpadiagrameditor.ui.internal.feature.ClickAddElementCollectionButtonFeature; import org.eclipse.jpt.jpadiagrameditor.ui.internal.feature.ClickRemoveAttributeButtonFeature; import org.eclipse.jpt.jpadiagrameditor.ui.internal.feature.CollapseAllEntitiesFeature; import org.eclipse.jpt.jpadiagrameditor.ui.internal.feature.CollapseCompartmentShapeFeature; @@ -169,6 +170,17 @@ public class JPAEditorToolBehaviorProvider extends DefaultToolBehaviorProvider { button.setDescription(JPAEditorMessages.JPAEditorToolBehaviorProvider_createAttributeButtonDescription); button.setIconId(JPAEditorImageProvider.ADD_ATTRIBUTE); data.getDomainSpecificContextButtons().add(button); + + if(!JPAEditorUtil.checkJPAFacetVersion(getTargetJPAProject(), JPAEditorUtil.JPA_PROJECT_FACET_10)){ + ClickAddElementCollectionButtonFeature addCollectionfeature = getConcreteFeatureProvider().getClickAddElementCollectionButtonFeature(); + createCtx = new CreateContext(); + createCtx.setTargetContainer(cs); + button = new ContextButtonEntry(addCollectionfeature, createCtx); + button.setText(JPAEditorMessages.JPAEditorToolBehaviorProvider_CreateElementCollectionAttributeButtonLabel); + button.setDescription(JPAEditorMessages.JPAEditorToolBehaviorProvider_CreateElementCollectionAttributeButtonDescription); + button.setIconId(JPAEditorImageProvider.ADD_ELEMENT_COLLECTION); + data.getDomainSpecificContextButtons().add(button); + } PictogramElementContext c = (PictogramElementContext) context; RemoveAndSaveEntityFeature ft2 = new RemoveAndSaveEntityFeature(getFeatureProvider()); @@ -550,18 +562,7 @@ public class JPAEditorToolBehaviorProvider extends DefaultToolBehaviorProvider { expandCompartmentMenuItem.setSubmenu(false); return new IContextMenuEntry[] {collapseCompartmentMenuItem, expandCompartmentMenuItem}; } - - /* - //Apply Pattern menu - - ICustomFeature applyPatternFeature = new ApplyPatternFeature(getFeatureProvider()); - ContextMenuEntry applyPatternMenuItem = new ContextMenuEntry(applyPatternFeature, context); - applyPatternMenuItem.setText(JPAEditorMessages.JPAEditorToolBehaviorProvider_applyPattern); - applyPatternMenuItem.setDescription(JPAEditorMessages.JPAEditorToolBehaviorProvider_applyPatternDesc); - applyPatternMenuItem.setSubmenu(false); - //Apply Pattern menu - */ - + ContextMenuEntry refactorClassSubmenu = new ContextMenuEntry(null, null); refactorClassSubmenu.setText(JPAEditorMessages.JPAEditorToolBehaviorProvider_refactorSubMenu); refactorClassSubmenu.setDescription(JPAEditorMessages.JPAEditorToolBehaviorProvider_refactorSubMenu); @@ -593,22 +594,21 @@ public class JPAEditorToolBehaviorProvider extends DefaultToolBehaviorProvider { expandEntityMenuItem, expandAllMenuItem, restoreEntityMenuItem, - //applyPatternMenuItem, removeAllEntitiesSubmenu, openJPADetailsViewMenuItem, openMiniatureViewMenuItem}; - - customFeature = new RefactorAttributeTypeFeature(getFeatureProvider()); + + customFeature = new RefactorAttributeTypeFeature(getFeatureProvider()); ContextMenuEntry refactorAttributeTypeMenuItem = new ContextMenuEntry(customFeature, context); refactorAttributeTypeMenuItem.setText(JPAEditorMessages.JPAEditorToolBehaviorProvider_refactorAttributeType); refactorAttributeTypeMenuItem.setDescription(JPAEditorMessages.JPAEditorToolBehaviorProvider_refactorAttributeTypeDesc); refactorAttributeTypeMenuItem.setSubmenu(false); + return new IContextMenuEntry[] { refactorClassSubmenu, refactorAttributeTypeMenuItem, collapseAllMenuItem, expandAllMenuItem, - //applyPatternMenuItem, openJPADetailsViewMenuItem, openMiniatureViewMenuItem}; } diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/HasCollectionReferenceRelation.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/HasCollectionReferenceRelation.java index 59972c8c32..e4ba675db1 100644 --- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/HasCollectionReferenceRelation.java +++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/HasCollectionReferenceRelation.java @@ -1,3 +1,19 @@ +/*******************************************************************************
+ * <copyright>
+ *
+ * Copyright (c) 2012 SAP AG and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Petya Sabeva - initial API, implementation and documentation
+ *
+ * </copyright>
+ *
+ *******************************************************************************/
+
package org.eclipse.jpt.jpadiagrameditor.ui.internal.relations;
import org.eclipse.graphiti.mm.pictograms.Connection;
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/HasReferanceRelation.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/HasReferanceRelation.java index d044a9fbd2..da8c575010 100644 --- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/HasReferanceRelation.java +++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/HasReferanceRelation.java @@ -1,3 +1,19 @@ +/*******************************************************************************
+ * <copyright>
+ *
+ * Copyright (c) 2012 SAP AG and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Petya Sabeva - initial API, implementation and documentation
+ *
+ * </copyright>
+ *
+ *******************************************************************************/
+
package org.eclipse.jpt.jpadiagrameditor.ui.internal.relations;
import java.util.Hashtable;
@@ -9,11 +25,9 @@ import org.eclipse.jpt.jpa.core.context.java.JavaPersistentAttribute; import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.IJPAEditorFeatureProvider;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JPAEditorConstants;
-import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JPAEditorUtil;
public abstract class HasReferanceRelation {
protected final static String SEPARATOR = ";hasReference;"; //$NON-NLS-1$
- public final static String HAS_REFERENCE_CONNECTION_PROP_KEY = "is_has_reference_connection"; //$NON-NLS-1$
protected JavaPersistentType embeddingEntity;
protected JavaPersistentType embeddable;
@@ -58,14 +72,9 @@ public abstract class HasReferanceRelation { public JavaPersistentType getEmbeddingEntity() {
return embeddingEntity;
}
-
- public static boolean isHasReferenceConnection(Connection conn) {
- String val = JPAEditorUtil.getPeUtil().getPropertyValue(conn, HAS_REFERENCE_CONNECTION_PROP_KEY);
- return (Boolean.TRUE.toString().equals(val));
- }
public String getId() {
- return generateId(embeddable, embeddingEntity, embeddedAnnotatedAttribute.getName(), getReferenceType());
+ return generateId(embeddingEntity, embeddable, embeddedAnnotatedAttribute.getName(), getReferenceType());
}
public static String generateId(JavaPersistentType startJpt, JavaPersistentType endJpt, String embeddedAttributeName, HasReferenceType relType) {
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/HasSingleReferenceRelation.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/HasSingleReferenceRelation.java index 48c204d4fe..807f064125 100644 --- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/HasSingleReferenceRelation.java +++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/HasSingleReferenceRelation.java @@ -1,3 +1,19 @@ +/*******************************************************************************
+ * <copyright>
+ *
+ * Copyright (c) 2012 SAP AG and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Petya Sabeva - initial API, implementation and documentation
+ *
+ * </copyright>
+ *
+ *******************************************************************************/
+
package org.eclipse.jpt.jpadiagrameditor.ui.internal.relations;
import org.eclipse.graphiti.mm.pictograms.Connection;
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 df0af0ae1b..b57a95f916 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 @@ -1,7 +1,7 @@ /******************************************************************************* * <copyright> * - * Copyright (c) 2005, 2010 SAP AG. + * Copyright (c) 2005, 2012 SAP AG. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -70,7 +70,6 @@ public class ManyToManyBiDirRelation extends ManyToManyRelation implements IBidi mapKeyType = getMapKeyType(isMap, owner, embeddingEntity); if(JpaArtifactFactory.instance().hasEmbeddableAnnotation(owner)){ -// inverseAnnotatedAttribute = JpaArtifactFactory.instance().addEmbeddedAttribute(owner, inverse, mapKeyType, true, fp); inverseAnnotatedAttribute = JPAEditorUtil.addAnnotatedAttribute(fp, inverse, embeddingEntity, true, mapKeyType); } else { 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 96c025ba59..e83431cc08 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 @@ -1,7 +1,7 @@ /******************************************************************************* * <copyright> * - * Copyright (c) 2005, 2010 SAP AG. + * Copyright (c) 2005, 2012 SAP AG. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -60,7 +60,6 @@ public class ManyToOneBiDirRelation extends ManyToOneRelation implements IBidir boolean isMap = JPADiagramPropertyPage.isMapType(owner.getJpaProject().getProject()); String mapKeyType = getMapKeyType(isMap, owner, embeddingEntity); if(JpaArtifactFactory.instance().hasEmbeddableAnnotation(owner)){ -// inverseAnnotatedAttribute = JpaArtifactFactory.instance().addEmbeddedAttribute(owner, inverse, mapKeyType, true, fp); inverseAnnotatedAttribute = JPAEditorUtil.addAnnotatedAttribute(fp, inverse, embeddingEntity, true, mapKeyType); } else { 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 8784131925..56ef13519e 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 @@ -1,7 +1,7 @@ /******************************************************************************* * <copyright> * - * Copyright (c) 2005, 2010 SAP AG. + * Copyright (c) 2005, 2012 SAP AG. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -57,7 +57,6 @@ public class OneToOneBiDirRelation extends OneToOneRelation implements IBidirect ownerAnnotatedAttribute = JPAEditorUtil.addAnnotatedAttribute(fp, owner, inverse, false, null); if(JpaArtifactFactory.instance().hasEmbeddableAnnotation(owner)){ -// inverseAnnotatedAttribute = JpaArtifactFactory.instance().addEmbeddedAttribute(owner, inverse, null, false, fp); inverseAnnotatedAttribute = JPAEditorUtil.addAnnotatedAttribute(fp, inverse, embeddingEntity, false, null); } else { inverseAnnotatedAttribute = JPAEditorUtil.addAnnotatedAttribute(fp, inverse, owner, false, null); diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/EntitiesCoordinatesXML.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/EntitiesCoordinatesXML.java index 884e466102..971ae1aea9 100644 --- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/EntitiesCoordinatesXML.java +++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/EntitiesCoordinatesXML.java @@ -1,3 +1,19 @@ +/******************************************************************************* + * <copyright> + * + * Copyright (c) 2010, 2012 SAP AG and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Petya Sabeva - initial API, implementation and documentation + * + * </copyright> + * + *******************************************************************************/ + package org.eclipse.jpt.jpadiagrameditor.ui.internal.util; import java.io.Closeable; @@ -42,6 +58,7 @@ import org.w3c.dom.NodeList; import org.w3c.dom.Text; import org.xml.sax.SAXException; +@SuppressWarnings("resource") public class EntitiesCoordinatesXML { private Document document; @@ -88,10 +105,8 @@ public class EntitiesCoordinatesXML { return (JpaProjectManager) ResourcesPlugin.getWorkspace().getAdapter(JpaProjectManager.class); } - private Closeable findXMLFile(boolean inputStream) throws FileNotFoundException{ - - Iterator<JpaProject> iter = getJpaProjectManager().getJpaProjects().iterator(); - + private Closeable findXMLFile(boolean inputStream) throws FileNotFoundException{ + IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName); try { IResource[] resources = project.members(); diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/IJPAEditorPredefinedRenderingStyle.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/IJPAEditorPredefinedRenderingStyle.java index d38ac3521d..bf657a1971 100644 --- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/IJPAEditorPredefinedRenderingStyle.java +++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/IJPAEditorPredefinedRenderingStyle.java @@ -1,7 +1,7 @@ /******************************************************************************* * <copyright> * - * Copyright (c) 2005, 2010 SAP AG. + * Copyright (c) 2005, 2012 SAP AG. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/IJPAEditorUtil.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/IJPAEditorUtil.java index e0b5f3df02..b43aeb0b78 100644 --- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/IJPAEditorUtil.java +++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/IJPAEditorUtil.java @@ -1,7 +1,7 @@ /******************************************************************************* * <copyright> * - * Copyright (c) 2005, 2010 SAP AG. + * Copyright (c) 2005, 2012 SAP AG. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/JPAEditorConstants.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/JPAEditorConstants.java index dca88e1e02..3929af2f29 100644 --- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/JPAEditorConstants.java +++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/JPAEditorConstants.java @@ -1,7 +1,7 @@ /******************************************************************************* * <copyright> * - * Copyright (c) 2005, 2010 SAP AG. + * Copyright (c) 2005, 2012 SAP AG. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/JPAEditorPredefinedColoredAreas.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/JPAEditorPredefinedColoredAreas.java index 1038671fcd..fd75cdd1bf 100644 --- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/JPAEditorPredefinedColoredAreas.java +++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/JPAEditorPredefinedColoredAreas.java @@ -1,7 +1,7 @@ /******************************************************************************* * <copyright> * - * Copyright (c) 2005, 2010 SAP AG. + * Copyright (c) 2005, 2012 SAP AG. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at 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 a4c5b15f4d..07d3f0d6f8 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 @@ -1,7 +1,7 @@ /******************************************************************************* * <copyright> * - * Copyright (c) 2005, 2011 SAP AG and others. + * Copyright (c) 2005, 2012 SAP AG and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -1411,12 +1411,10 @@ public class JPAEditorUtil { actNameWithNonCapitalLetter = produceUniqueAttributeName(referencingJPT, actNameWithNonCapitalLetter); ICompilationUnit referencingCU = JPAEditorUtil.getCompilationUnit(referencingJPT); - ICompilationUnit referencedCU = JPAEditorUtil.getCompilationUnit(referencedJPT); return JpaArtifactFactory.instance().addAttribute(fp, referencingJPT, referencedJPT, mapKeyType, nameWithNonCapitalLetter, actNameWithNonCapitalLetter, isCollection, - referencingCU, - referencedCU); + referencingCU); } } diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/JPAEditorUtilImpl.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/JPAEditorUtilImpl.java index b111c7677c..87a11d0e0b 100644 --- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/JPAEditorUtilImpl.java +++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/JPAEditorUtilImpl.java @@ -1,7 +1,7 @@ /******************************************************************************* * <copyright> * - * Copyright (c) 2005, 2010 SAP AG. + * Copyright (c) 2005, 2012 SAP AG. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at 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 5a3ee9ec3b..e9ad502dec 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 @@ -1,7 +1,7 @@ /******************************************************************************* * <copyright> * - * Copyright (c) 2005, 2011 SAP AG. + * Copyright (c) 2005, 2012 SAP AG. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at 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 8df876858f..5703776982 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 @@ -86,7 +86,6 @@ import org.eclipse.jpt.jpa.core.resource.java.RelationshipMappingAnnotation; import org.eclipse.jpt.jpa.core.resource.java.TableAnnotation; 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.CreateNewAttributeCommand; import org.eclipse.jpt.jpadiagrameditor.ui.internal.command.DeleteAttributeCommand; import org.eclipse.jpt.jpadiagrameditor.ui.internal.command.RenameAttributeCommand; import org.eclipse.jpt.jpadiagrameditor.ui.internal.command.RenameEntityCommand; @@ -572,32 +571,6 @@ public class JpaArtifactFactory { gje.setSpecifiedName(newName); } } - - /** - * Create inverseSideAttribute of the bidirectional relationship between an embeddable class - * and an entity. - * @param embeddableOwner - the embeddable class - * @param inverseEntity - the entity class - * @param mapKeyType - * @param isCollection - whether the attribute is of a collection type - * @param fp - * @return the inverse attribute of the relationship. - */ - public JavaPersistentAttribute addEmbeddedAttribute(JavaPersistentType embeddableOwner, JavaPersistentType inverseEntity, String mapKeyType, boolean isCollection, IJPAEditorFeatureProvider fp){ - ICompilationUnit ijl = fp.getCompilationUnit(inverseEntity); - JavaPersistentType embeddingEntity = null; - String attributeName = ""; //$NON-NLS-1$ - String actName = ""; //$NON-NLS-1$ - ICompilationUnit cu2 = null; - HasReferanceRelation ref = findFisrtHasReferenceRelationByEmbeddable(embeddableOwner, fp); - if(ref != null){ - embeddingEntity = ref.getEmbeddingEntity(); - attributeName = JPAEditorUtil.decapitalizeFirstLetter(embeddingEntity.getSimpleName()); - actName = JPAEditorUtil.decapitalizeFirstLetter(embeddingEntity.getSimpleName()); - cu2 = JPAEditorUtil.getCompilationUnit(embeddingEntity); - } - return addAttribute(fp, inverseEntity, embeddingEntity, mapKeyType, attributeName, actName, isCollection, ijl, cu2); - } /** * Find the first {@link HasReferenceRelation} for the given embeddable class from all existing @@ -655,33 +628,23 @@ public class JpaArtifactFactory { * @param attributeName - the name of the attribute * @param actName - the actual name of the attribute * @param isCollection - whether the attribute is of a collection type - * @param cu1 - the {@link ICompilationUnit} of the referencing {@link JavaPersistentType} - * @param cu2 - the {@link ICompilationUnit} of the referenced {@link JavaPersistentType} + * @param cu - the {@link ICompilationUnit} of the referencing {@link JavaPersistentType} * @return the newly created relationship attribute. */ public JavaPersistentAttribute addAttribute(IJPAEditorFeatureProvider fp, JavaPersistentType jpt, JavaPersistentType attributeType, String mapKeyType, String attributeName, - String actName, boolean isCollection, ICompilationUnit cu1, - ICompilationUnit cu2) { + String actName, boolean isCollection, ICompilationUnit cu) { try { if (doesAttributeExist(jpt, actName)) { - return (JavaPersistentAttribute) jpt - .resolveAttribute(attributeName); + return (JavaPersistentAttribute) jpt.resolveAttribute(attributeName); } - } catch (JavaModelException e) { JPADiagramEditorPlugin.logError("Cannnot create a new attribute with name " + attributeName, e); //$NON-NLS-1$ } - Command addAttributeCommand = new AddAttributeCommand(fp, jpt, attributeType, mapKeyType, attributeName, actName, isCollection, cu1, cu2); - try { - getJpaProjectManager().execute(addAttributeCommand, SynchronousUiCommandExecutor.instance()); - } catch (InterruptedException e) { - JPADiagramEditorPlugin.logError("Cannot add a new attribute with name " + actName, e); //$NON-NLS-1$ - } - - JavaPersistentAttribute res = jpt.getAttributeNamed(actName); + JavaPersistentAttribute res = makeNewAttribute(fp, jpt, cu, attributeName, attributeType.getName(), actName, mapKeyType, null, null, isCollection); + return res; } @@ -759,72 +722,31 @@ public class JpaArtifactFactory { public String createNewAttribute(JavaPersistentType jpt, boolean isCollection, IJPAEditorFeatureProvider fp) { - ICompilationUnit ijl = fp.getCompilationUnit(jpt); String attrTypeName = "java.lang.String"; //$NON-NLS-1$ String newAttrName = genUniqueAttrName(jpt, attrTypeName, fp); - return addNewAttribute(jpt, ijl, newAttrName, attrTypeName, - "", newAttrName, isCollection, fp); //$NON-NLS-1$ + ICompilationUnit cu = fp.getCompilationUnit(jpt); + makeNewAttribute(fp, jpt, cu, newAttrName, attrTypeName, newAttrName, attrTypeName, null, null, isCollection); + return newAttrName; } - - public String addNewAttribute(JavaPersistentType jpt, ICompilationUnit cu, - String attrName, String attrTypeName, String annotation, - String actName, boolean isCollection, IJPAEditorFeatureProvider fp) { - - try { - List<String> annotations = new LinkedList<String>(); - annotations.add(annotation); - boolean isMethodAnnotated = JpaArtifactFactory.instance() - .isMethodAnnotated(jpt); - makeNewAttribute(fp, jpt, cu, attrName, attrTypeName, null, actName, - annotations, isCollection, isMethodAnnotated); - } catch (JavaModelException e) { - JPADiagramEditorPlugin.logError("Cannot create a new attribute with name " + attrName, e); //$NON-NLS-1$ + + public JavaPersistentAttribute makeNewAttribute(IJPAEditorFeatureProvider fp, JavaPersistentType jpt, ICompilationUnit cu, String attrName, String attrTypeName, + String actName, String mapKeyType, String[] attrTypes, List<String> annotations, boolean isCollection) { + + if(cu == null){ + cu = fp.getCompilationUnit(jpt); } - return attrName; - } - - public JavaPersistentAttribute createANewAttribute(JavaPersistentType jpt, - String attrName, String attrTypeName, String[] attrTypeElementNames, - String actName, List<String> annotations, boolean isCollection, - boolean isMethodAnnotated, IJPAEditorFeatureProvider fp) { - ICompilationUnit ijl = fp.getCompilationUnit(jpt); - return addANewAttribute(jpt, ijl, attrName, attrTypeName, - attrTypeElementNames, actName, annotations, isCollection, - isMethodAnnotated, fp); - } - - private JavaPersistentAttribute addANewAttribute(JavaPersistentType jpt, - ICompilationUnit cu, String attrName, String attrTypeName, - String[] attrTypeElementNames, String actName, - List<String> annotations, boolean isCollection, - boolean isMethodAnnotated, IJPAEditorFeatureProvider fp) { - - JavaPersistentAttribute attr = null; - try { - attr = makeNewAttribute(fp, jpt, cu, attrName, attrTypeName, - attrTypeElementNames, actName, annotations, isCollection, - isMethodAnnotated); - } catch (JavaModelException e) { - JPADiagramEditorPlugin.logError("Cannot create a new attribute with name " + attrName, e); //$NON-NLS-1$ - } - return attr; - } - - public JavaPersistentAttribute makeNewAttribute(IFeatureProvider fp, JavaPersistentType jpt, - ICompilationUnit cu, String attrName, String attrTypeName, - String[] attrTypes, String actName, - List<String> annotations, boolean isCollection, - boolean isMethodAnnotated) throws JavaModelException { - - Command createNewAttributeCommand = new CreateNewAttributeCommand(jpt, cu, attrName, attrTypeName, attrTypes, actName, annotations, isCollection, isMethodAnnotated); + Command createNewAttributeCommand = new AddAttributeCommand(fp, jpt, attrTypeName, mapKeyType, attrName, actName, attrTypes, annotations, isCollection, cu); try { getJpaProjectManager().execute(createNewAttributeCommand, SynchronousUiCommandExecutor.instance()); } catch (InterruptedException e) { JPADiagramEditorPlugin.logError("Cannot create a new attribute with name " + attrName, e); //$NON-NLS-1$ } - JavaPersistentAttribute jpa = jpt.getAttributeNamed(attrName); + JavaPersistentAttribute jpa = jpt.getAttributeNamed(attrName); + if(jpa == null){ + jpa = jpt.getAttributeNamed(actName); + } return jpa; } @@ -936,7 +858,7 @@ public class JpaArtifactFactory { CompilationUnit jdtCU = jpt.getJavaResourceType().getJavaResourceCompilationUnit().buildASTRoot(); JavaResourceAttribute jrpt = persistentAttribite.getResourceAttribute(); List<String> res = new LinkedList<String>(); - for (Annotation an : jrpt.getAnnotations()) { + for (Annotation an : jrpt.getTopLevelAnnotations()) { org.eclipse.jdt.core.dom.Annotation jdtAn = an.getAstAnnotation(jdtCU); res.add(jdtAn.toString()); } @@ -1591,81 +1513,6 @@ public class JpaArtifactFactory { return false; } - /** - * Create the attribute's getter method in entity's compilation unit. - * @param attrName - the name of the attribute - * @param attrType - the type of the attribute - * @param attrTypeElementNames - * @param actName - * @param annotations - * @param isCollection - * @return the string representation of the attribute's getter method. - */ - public String genGetterContents(String attrName, String attrType, - String[] attrTypeElementNames, String actName, - List<String> annotations, boolean isCollection) { - - String attrNameWithCapitalA = actName.substring(0, 1).toUpperCase(Locale.ENGLISH) - + actName.substring(1); - String contents = ""; //$NON-NLS-1$ - if (annotations != null) { - Iterator<String> it = annotations.iterator(); - while (it.hasNext()) { - String an = it.next(); - contents += " " + an + "\n"; //$NON-NLS-1$ //$NON-NLS-2$ - } - } - if (isCollection) { - contents += " public Collection<"+ attrType + "> get" + attrNameWithCapitalA + "() {\n" + //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - " return " //$NON-NLS-1$ - + JPAEditorUtil.decapitalizeFirstLetter(actName) + ";\n" + //$NON-NLS-1$ - " }\n"; //$NON-NLS-1$ - } else { - contents += " public "+ attrType + //$NON-NLS-1$ - ((attrTypeElementNames == null)?"":("<" + JPAEditorUtil.createCommaSeparatedListOfSimpleTypeNames(attrTypeElementNames) + ">")) + //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - (attrType.equals("boolean") ? " is" : " get") + attrNameWithCapitalA + "() {\n" + //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ - " return " //$NON-NLS-1$ - + JPAEditorUtil.decapitalizeFirstLetter(actName) + ";\n" + //$NON-NLS-1$ - " }\n"; //$NON-NLS-1$ - } - return contents; - } - - /** - * Create the attribute's setter method in entity's compilation unit. - * @param attrName - the name of the attribute - * @param attrType - the type of the attribute - * @param attrTypeElementNames - * @param actName - * @param isCollection - * @return the string representation of the attribute's setter method. - */ - public String genSetterContents(String attrName, String attrType, - String[] attrTypeElementNames, String actName, boolean isCollection) { - - String attrNameWithCapitalA = actName.substring(0, 1).toUpperCase(Locale.ENGLISH) - + actName.substring(1); - String contents = ""; //$NON-NLS-1$ - if (isCollection) { - contents = " public void set" + attrNameWithCapitalA + "(Collection<" + attrType + "> param) " + //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - "{\n" + //$NON-NLS-1$ - " this." //$NON-NLS-1$ - + JPAEditorUtil.decapitalizeFirstLetter(actName) - + " = param;\n" + //$NON-NLS-1$ - " }\n"; //$NON-NLS-1$ - } else { - contents = " public void set" + attrNameWithCapitalA + "(" + attrType + //$NON-NLS-1$ //$NON-NLS-2$ - ((attrTypeElementNames == null)?"":("<" + JPAEditorUtil.createCommaSeparatedListOfSimpleTypeNames(attrTypeElementNames) + ">")) + //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - " param) {\n" //$NON-NLS-1$ - + - " this." //$NON-NLS-1$ - + JPAEditorUtil.decapitalizeFirstLetter(actName) - + " = param;\n" + //$NON-NLS-1$ - " }\n"; //$NON-NLS-1$ - } - return contents; - } - private boolean doesAttributeExist(JavaPersistentType jpt, String name) throws JavaModelException { boolean exists = false; |