Author: vyemialyanchyk
Date: 2009-01-12 15:22:25 -0500 (Mon, 12 Jan 2009)
New Revision: 13002
Added:
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/jpa/common/OwnerType.java
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/jpa/process/ChangeStructure.java
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/jpa/process/wizard/
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/jpa/process/wizard/EntitiesList.java
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/jpa/process/wizard/HibernateJPARefactoring.java
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/jpa/process/wizard/HibernateJPAWizard.java
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/jpa/process/wizard/IHibernateJPAWizardData.java
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/jpa/process/wizard/IHibernateJPAWizardParams.java
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/jpa/process/wizard/ResolveAmbiguous.java
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/JdtUiMessages.java
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/JdtUiMessages.properties
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/jpa/collect/AllEntitiesInfoCollector.java
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/jpa/collect/CollectEntityInfo.java
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/jpa/common/EntityInfo.java
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/jpa/common/JPAConst.java
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/jpa/common/RefEntityInfo.java
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/jpa/process/AllEntitiesProcessor.java
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/jpa/process/AnnotStyle.java
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/jpa/process/ProcessEntityInfo.java
Log:
JBIDE-3426
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/JdtUiMessages.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/JdtUiMessages.java 2009-01-12
19:37:40 UTC (rev 13001)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/JdtUiMessages.java 2009-01-12
20:22:25 UTC (rev 13002)
@@ -28,6 +28,13 @@
public static String SaveQueryEditorListener_errormessage;
public static String JPAMapToolActor_message_title;
public static String JPAMapToolActor_message;
+ public static String ResolveAmbiguous_column_Class;
+ public static String ResolveAmbiguous_column_Association;
+ public static String ResolveAmbiguous_column_Type;
+ public static String ResolveAmbiguous_column_Related;
+ public static String ResolveAmbiguous_column_Owner;
+ public static String ResolveAmbiguous_empty;
+ public static String ResolveAmbiguous_message;
static {
// initialize resource bundle
NLS.initializeMessages(BUNDLE_NAME, JdtUiMessages.class);
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/JdtUiMessages.properties
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/JdtUiMessages.properties 2009-01-12
19:37:40 UTC (rev 13001)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/JdtUiMessages.properties 2009-01-12
20:22:25 UTC (rev 13002)
@@ -32,3 +32,10 @@
SaveQueryEditorListener_errormessage=Error while query refactoring
JPAMapToolActor_message_title=Hibernate/JPA
JPAMapToolActor_message=Cannot generate annotations for an interface or enumeration
+ResolveAmbiguous_column_Class=Class
+ResolveAmbiguous_column_Association=Association
+ResolveAmbiguous_column_Type=Type
+ResolveAmbiguous_column_Related=Related
+ResolveAmbiguous_column_Owner=Owner
+ResolveAmbiguous_empty=<empty>
+ResolveAmbiguous_message=Edit entities relations.
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/jpa/collect/AllEntitiesInfoCollector.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/jpa/collect/AllEntitiesInfoCollector.java 2009-01-12
19:37:40 UTC (rev 13001)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/jpa/collect/AllEntitiesInfoCollector.java 2009-01-12
20:22:25 UTC (rev 13002)
@@ -20,6 +20,7 @@
import org.eclipse.jdt.core.dom.TypeDeclaration;
import org.hibernate.eclipse.jdt.ui.internal.jpa.common.EntityInfo;
import org.hibernate.eclipse.jdt.ui.internal.jpa.common.JPAConst;
+import org.hibernate.eclipse.jdt.ui.internal.jpa.common.OwnerType;
import org.hibernate.eclipse.jdt.ui.internal.jpa.common.RefEntityInfo;
import org.hibernate.eclipse.jdt.ui.internal.jpa.common.RefFieldInfo;
import org.hibernate.eclipse.jdt.ui.internal.jpa.common.RefType;
@@ -148,8 +149,109 @@
}
}
}
+
+ public void updateOwner(ProcessItem pi) {
+ if (pi.refEntityInfo.refType == RefType.ONE2ONE) {
+ pi.refEntityInfo.owner = OwnerType.UNDEF;
+ pi.refEntityInfo2.owner = OwnerType.UNDEF;
+ }
+ else if (pi.refEntityInfo.refType == RefType.ONE2MANY) {
+ pi.refEntityInfo.owner = OwnerType.YES;
+ pi.refEntityInfo2.owner = OwnerType.NO;
+ }
+ else if (pi.refEntityInfo.refType == RefType.MANY2ONE) {
+ pi.refEntityInfo.owner = OwnerType.NO;
+ pi.refEntityInfo2.owner = OwnerType.YES;
+ }
+ else if (pi.refEntityInfo.refType == RefType.MANY2MANY) {
+ pi.refEntityInfo.owner = OwnerType.UNDEF;
+ pi.refEntityInfo2.owner = OwnerType.UNDEF;
+ }
+ }
/**
+ * responsible for enumeration all entities pairs and
+ * setup relations between single candidate for several items case
+ */
+ protected class EntitySingleCandidateResolver {
+
+ /**
+ * enumerate function
+ */
+ public void enumEntityPairs() {
+ Iterator<Map.Entry<String, EntityInfo>> it =
mapCUs_Info.entrySet().iterator();
+ ProcessItem pi = new ProcessItem();
+ while (it.hasNext()) {
+ Map.Entry<String, EntityInfo> entry = it.next();
+ // entry.getKey() - fully qualified name
+ // entry.getValue() - EntityInfo
+ EntityInfo entryInfo = entry.getValue();
+ assert(entry.getKey().equals(entryInfo.getFullyQualifiedName()));
+ String fullyQualifiedName = entryInfo.getFullyQualifiedName();
+ // get references map:
+ // * field id -> RefEntityInfo
+ Iterator<Map.Entry<String, RefEntityInfo>> referencesIt =
+ entryInfo.getReferences().entrySet().iterator();
+ while (referencesIt.hasNext()) {
+ Map.Entry<String, RefEntityInfo> entry2 = referencesIt.next();
+ // entry2.getKey() - field id
+ // entry2.getValue() - RefEntityInfo
+ pi.fieldId = entry2.getKey();
+ pi.refEntityInfo = entry2.getValue();
+ String fullyQualifiedName2 = pi.refEntityInfo.fullyQualifiedName;
+ EntityInfo entryInfo2 = mapCUs_Info.get(fullyQualifiedName2);
+ assert(fullyQualifiedName2.equals(entryInfo2.getFullyQualifiedName()));
+ if (entryInfo2 != null && pi.refEntityInfo != null) {
+ pi.refEntityInfo2 = null;
+ pi.fieldId2 = null;
+ Set<RefFieldInfo> setRefEntityInfo =
entryInfo2.getRefFieldInfoSet(fullyQualifiedName);
+ if (setRefEntityInfo != null && setRefEntityInfo.size() > 1) {
+ // this case of complex decision - but if there is 1 candidate
+ // it is possible to select this candidate automatically
+ // in case of no solution - user should define this himself
+ // try to find 1 suitable candidate
+ RefType suitableRefType = RefType.UNDEF;
+ if (pi.refEntityInfo.refType == RefType.ONE2ONE) {
+ suitableRefType = RefType.ONE2ONE;
+ }
+ else if (pi.refEntityInfo.refType == RefType.ONE2MANY) {
+ suitableRefType = RefType.MANY2ONE;
+ }
+ else if (pi.refEntityInfo.refType == RefType.MANY2ONE) {
+ suitableRefType = RefType.ONE2MANY;
+ }
+ else if (pi.refEntityInfo.refType == RefType.MANY2MANY) {
+ suitableRefType = RefType.MANY2MANY;
+ }
+ RefFieldInfo rfiSingleCandidat = null;
+ Iterator<RefFieldInfo> itTmp = setRefEntityInfo.iterator();
+ while (itTmp.hasNext()) {
+ RefFieldInfo rfi = itTmp.next();
+ if (rfi.refType == suitableRefType) {
+ if (rfiSingleCandidat == null) {
+ rfiSingleCandidat = rfi;
+ }
+ else {
+ // there are a least 2 candidates
+ break;
+ }
+ }
+ }
+ if (!itTmp.hasNext() && rfiSingleCandidat != null) {
+ pi.fieldId2 = rfiSingleCandidat.fieldId;
+ pi.refEntityInfo2 = entryInfo2.getFieldIdRefEntityInfo(pi.fieldId2);
+ pi.refEntityInfo.mappedBy = pi.fieldId2;
+ pi.refEntityInfo2.mappedBy = pi.fieldId;
+ updateOwner(pi);
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+
+ /**
* process all entities pairs iteratively:
* firstly process pairs with more information about and
* pairs with small information about - process in last order
@@ -201,24 +303,28 @@
pi.refEntityInfo.mappedBy = pi.fieldId2;
pi.refEntityInfo2.refType = RefType.ONE2ONE;
pi.refEntityInfo2.mappedBy = pi.fieldId;
+ updateOwner(pi);
}
else if (pi.refEntityInfo2.refType == RefType.ONE2MANY) {
pi.refEntityInfo.refType = RefType.MANY2ONE;
pi.refEntityInfo.mappedBy = pi.fieldId2;
pi.refEntityInfo2.refType = RefType.ONE2MANY;
pi.refEntityInfo2.mappedBy = pi.fieldId;
+ updateOwner(pi);
}
else if (pi.refEntityInfo2.refType == RefType.MANY2ONE) {
pi.refEntityInfo.refType = RefType.ONE2MANY;
pi.refEntityInfo.mappedBy = pi.fieldId2;
pi.refEntityInfo2.refType = RefType.MANY2ONE;
pi.refEntityInfo2.mappedBy = pi.fieldId;
+ updateOwner(pi);
}
else if (pi.refEntityInfo2.refType == RefType.MANY2MANY) {
pi.refEntityInfo.refType = RefType.MANY2MANY;
pi.refEntityInfo.mappedBy = pi.fieldId2;
pi.refEntityInfo2.refType = RefType.MANY2MANY;
pi.refEntityInfo2.mappedBy = pi.fieldId;
+ updateOwner(pi);
}
}
else if (hasPrompt == 2) {
@@ -227,24 +333,28 @@
pi.refEntityInfo.mappedBy = pi.fieldId;
pi.refEntityInfo2.refType = RefType.ONE2ONE;
pi.refEntityInfo2.mappedBy = pi.fieldId2;
+ updateOwner(pi);
}
else if (pi.refEntityInfo.refType == RefType.ONE2MANY) {
pi.refEntityInfo.refType = RefType.ONE2MANY;
pi.refEntityInfo.mappedBy = pi.fieldId;
pi.refEntityInfo2.refType = RefType.MANY2ONE;
pi.refEntityInfo2.mappedBy = pi.fieldId2;
+ updateOwner(pi);
}
else if (pi.refEntityInfo.refType == RefType.MANY2ONE) {
pi.refEntityInfo.refType = RefType.MANY2ONE;
pi.refEntityInfo.mappedBy = pi.fieldId;
pi.refEntityInfo2.refType = RefType.ONE2MANY;
pi.refEntityInfo2.mappedBy = pi.fieldId2;
+ updateOwner(pi);
}
else if (pi.refEntityInfo.refType == RefType.MANY2MANY) {
pi.refEntityInfo.refType = RefType.MANY2MANY;
pi.refEntityInfo.mappedBy = pi.fieldId;
pi.refEntityInfo2.refType = RefType.MANY2MANY;
pi.refEntityInfo2.mappedBy = pi.fieldId2;
+ updateOwner(pi);
}
}
//if (hasPrompt == 3) - this is case where we get prompt from both sides -
@@ -255,12 +365,14 @@
pi.refEntityInfo.mappedBy = pi.fieldId2;
pi.refEntityInfo2.refType = RefType.ONE2ONE;
pi.refEntityInfo2.mappedBy = pi.fieldId;
+ updateOwner(pi);
}
else if (pi.refEntityInfo2.refType == RefType.ONE2MANY) {
pi.refEntityInfo.refType = RefType.MANY2ONE;
pi.refEntityInfo.mappedBy = pi.fieldId2;
pi.refEntityInfo2.refType = RefType.ONE2MANY;
pi.refEntityInfo2.mappedBy = pi.fieldId;
+ updateOwner(pi);
}
}
else if (pi.refEntityInfo.refType == RefType.ONE2MANY) {
@@ -269,12 +381,14 @@
pi.refEntityInfo.mappedBy = pi.fieldId2;
pi.refEntityInfo2.refType = RefType.MANY2ONE;
pi.refEntityInfo2.mappedBy = pi.fieldId;
+ updateOwner(pi);
}
else if (pi.refEntityInfo2.refType == RefType.ONE2MANY) {
pi.refEntityInfo.refType = RefType.MANY2MANY;
pi.refEntityInfo.mappedBy = pi.fieldId2;
pi.refEntityInfo2.refType = RefType.MANY2MANY;
pi.refEntityInfo2.mappedBy = pi.fieldId;
+ updateOwner(pi);
}
}
}
@@ -301,12 +415,14 @@
pi.refEntityInfo.mappedBy = pi.fieldId2;
pi.refEntityInfo2.refType = RefType.ONE2ONE;
pi.refEntityInfo2.mappedBy = pi.fieldId;
+ updateOwner(pi);
}
else if (pi.refEntityInfo2.refType == RefType.ONE2MANY) {
pi.refEntityInfo.refType = RefType.MANY2ONE;
pi.refEntityInfo.mappedBy = pi.fieldId2;
pi.refEntityInfo2.refType = RefType.ONE2MANY;
pi.refEntityInfo2.mappedBy = pi.fieldId;
+ updateOwner(pi);
}
}
else if (pi.refEntityInfo.refType == RefType.ONE2MANY) {
@@ -315,6 +431,7 @@
pi.refEntityInfo.mappedBy = pi.fieldId2;
pi.refEntityInfo2.refType = RefType.MANY2ONE;
pi.refEntityInfo2.mappedBy = pi.fieldId;
+ updateOwner(pi);
}
}
else if (pi.refEntityInfo.refType == RefType.MANY2ONE) {
@@ -323,6 +440,7 @@
pi.refEntityInfo.mappedBy = pi.fieldId2;
pi.refEntityInfo2.refType = RefType.ONE2ONE;
pi.refEntityInfo2.mappedBy = pi.fieldId;
+ updateOwner(pi);
}
}
}
@@ -350,6 +468,7 @@
pi.refEntityInfo.mappedBy = pi.fieldId2;
pi.refEntityInfo2.refType = RefType.MANY2MANY;
pi.refEntityInfo2.mappedBy = pi.fieldId;
+ updateOwner(pi);
}
}
}
@@ -359,6 +478,10 @@
};
ep.setConnector(m2mRelConnector);
ep.enumEntityPairs();
+ // 3)
+ // third - try to assign - "single candidates"
+ EntitySingleCandidateResolver escr = new EntitySingleCandidateResolver();
+ escr.enumEntityPairs();
// update import flags
it = mapCUs_Info.entrySet().iterator();
while (it.hasNext()) {
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/jpa/collect/CollectEntityInfo.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/jpa/collect/CollectEntityInfo.java 2009-01-12
19:37:40 UTC (rev 13001)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/jpa/collect/CollectEntityInfo.java 2009-01-12
20:22:25 UTC (rev 13002)
@@ -20,6 +20,7 @@
import org.eclipse.jdt.core.dom.ASTVisitor;
import org.eclipse.jdt.core.dom.ArrayType;
import org.eclipse.jdt.core.dom.CompilationUnit;
+import org.eclipse.jdt.core.dom.FieldAccess;
import org.eclipse.jdt.core.dom.FieldDeclaration;
import org.eclipse.jdt.core.dom.ITypeBinding;
import org.eclipse.jdt.core.dom.ImportDeclaration;
@@ -276,7 +277,7 @@
return true;
}
- public String getReturnIdentifier(MethodDeclaration node) {
+ public static String getReturnIdentifier(MethodDeclaration node) {
String res = null;
List bodyStatemants = node.getBody().statements();
Iterator it = bodyStatemants.iterator();
@@ -289,6 +290,11 @@
SimpleName sn = (SimpleName)obj;
res = sn.getIdentifier();
}
+ else if (obj instanceof FieldAccess) {
+ FieldAccess fa = (FieldAccess)obj;
+ SimpleName sn = fa.getName();
+ res = sn.getIdentifier();
+ }
break;
}
}
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/jpa/common/EntityInfo.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/jpa/common/EntityInfo.java 2009-01-12
19:37:40 UTC (rev 13001)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/jpa/common/EntityInfo.java 2009-01-12
20:22:25 UTC (rev 13002)
@@ -188,6 +188,15 @@
if (isAddEntityFlag()) {
addRequiredImport(JPAConst.IMPORT_ENTITY);
}
+ Iterator<Map.Entry<String, RefEntityInfo>> referencesIt =
+ getReferences().entrySet().iterator();
+ while (referencesIt.hasNext()) {
+ Map.Entry<String, RefEntityInfo> entry = referencesIt.next();
+ RefEntityInfo refEntityInfo = entry.getValue();
+ if (refEntityInfo.owner == OwnerType.NO) {
+ addRequiredImport(JPAConst.IMPORT_JOINCOLUMN);
+ }
+ }
// try to intellectually get primary id
primaryIdName = null;
String entityName = getName().toLowerCase();
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/jpa/common/JPAConst.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/jpa/common/JPAConst.java 2009-01-12
19:37:40 UTC (rev 13001)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/jpa/common/JPAConst.java 2009-01-12
20:22:25 UTC (rev 13002)
@@ -14,6 +14,7 @@
static public String IMPORT_ENTITY = "javax.persistence.Entity";
//$NON-NLS-1$
static public String IMPORT_GENERATED_VALUE =
"javax.persistence.GeneratedValue"; //$NON-NLS-1$
static public String IMPORT_ID = "javax.persistence.Id"; //$NON-NLS-1$
+ static public String IMPORT_JOINCOLUMN = "javax.persistence.JoinColumn";
//$NON-NLS-1$
static public String IMPORT_ONE2ONE = "javax.persistence.OneToOne";
//$NON-NLS-1$
static public String IMPORT_ONE2MANY = "javax.persistence.OneToMany";
//$NON-NLS-1$
static public String IMPORT_MANY2ONE = "javax.persistence.ManyToOne";
//$NON-NLS-1$
@@ -23,6 +24,7 @@
static public String ANNOTATION_ENTITY = "Entity"; //$NON-NLS-1$
static public String ANNOTATION_GENERATED_VALUE = "GeneratedValue";
//$NON-NLS-1$
static public String ANNOTATION_ID = "Id"; //$NON-NLS-1$
+ static public String ANNOTATION_JOINCOLUMN = "JoinColumn"; //$NON-NLS-1$
static public String ANNOTATION_ONE2ONE = "OneToOne"; //$NON-NLS-1$
static public String ANNOTATION_ONE2MANY = "OneToMany"; //$NON-NLS-1$
static public String ANNOTATION_MANY2ONE = "ManyToOne"; //$NON-NLS-1$
@@ -35,6 +37,7 @@
ALL_IMPORTS.add(IMPORT_ENTITY);
ALL_IMPORTS.add(IMPORT_GENERATED_VALUE);
ALL_IMPORTS.add(IMPORT_ID);
+ ALL_IMPORTS.add(IMPORT_JOINCOLUMN);
ALL_IMPORTS.add(IMPORT_ONE2ONE);
ALL_IMPORTS.add(IMPORT_ONE2MANY);
ALL_IMPORTS.add(IMPORT_MANY2ONE);
Added:
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/jpa/common/OwnerType.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/jpa/common/OwnerType.java
(rev 0)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/jpa/common/OwnerType.java 2009-01-12
20:22:25 UTC (rev 13002)
@@ -0,0 +1,22 @@
+/*******************************************************************************
+ * Copyright (c) 2007-2008 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is 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
+ *
+ * Contributor:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.hibernate.eclipse.jdt.ui.internal.jpa.common;
+
+/**
+ * possible owner definition
+ *
+ * @author Vitali
+ */
+public enum OwnerType {
+ UNDEF,
+ YES,
+ NO,
+}
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/jpa/common/RefEntityInfo.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/jpa/common/RefEntityInfo.java 2009-01-12
19:37:40 UTC (rev 13001)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/jpa/common/RefEntityInfo.java 2009-01-12
20:22:25 UTC (rev 13002)
@@ -33,6 +33,8 @@
*/
public String mappedBy = null;
//
+ public OwnerType owner = OwnerType.UNDEF;
+ //
public boolean annotated = false;
//
public boolean resolvedAnnotationName = false;
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/jpa/process/AllEntitiesProcessor.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/jpa/process/AllEntitiesProcessor.java 2009-01-12
19:37:40 UTC (rev 13001)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/jpa/process/AllEntitiesProcessor.java 2009-01-12
20:22:25 UTC (rev 13002)
@@ -15,65 +15,33 @@
import java.util.Map;
import org.eclipse.core.filebuffers.FileBuffers;
-import org.eclipse.core.filebuffers.ITextFileBuffer;
import org.eclipse.core.filebuffers.ITextFileBufferManager;
import org.eclipse.core.filebuffers.LocationKind;
import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.Status;
import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.core.dom.AST;
import org.eclipse.jdt.core.dom.rewrite.ASTRewrite;
-import org.eclipse.jdt.internal.ui.refactoring.RefactoringSaveHelper;
-import org.eclipse.jdt.internal.ui.refactoring.actions.RefactoringStarter;
-import org.eclipse.jdt.internal.ui.viewsupport.JavaElementImageProvider;
-import org.eclipse.jface.dialogs.IDialogConstants;
-import org.eclipse.jface.layout.GridDataFactory;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.text.BadLocationException;
-import org.eclipse.jface.text.IDocument;
-import org.eclipse.jface.viewers.IStructuredContentProvider;
-import org.eclipse.jface.viewers.LabelProvider;
-import org.eclipse.jface.viewers.TableViewer;
-import org.eclipse.jface.viewers.Viewer;
-import org.eclipse.ltk.core.refactoring.Change;
-import org.eclipse.ltk.core.refactoring.CompositeChange;
-import org.eclipse.ltk.core.refactoring.DocumentChange;
-import org.eclipse.ltk.core.refactoring.Refactoring;
-import org.eclipse.ltk.core.refactoring.RefactoringStatus;
-import org.eclipse.ltk.ui.refactoring.RefactoringWizard;
-import org.eclipse.ltk.ui.refactoring.UserInputWizardPage;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.ModifyEvent;
-import org.eclipse.swt.events.ModifyListener;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Combo;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Label;
import org.eclipse.text.edits.MalformedTreeException;
-import org.eclipse.text.edits.TextEdit;
import org.eclipse.text.edits.UndoEdit;
-import org.eclipse.ui.IWorkbenchWindow;
-import org.eclipse.ui.PlatformUI;
import org.hibernate.eclipse.console.HibernateConsolePlugin;
import org.hibernate.eclipse.jdt.ui.Activator;
-import org.hibernate.eclipse.jdt.ui.internal.JdtUiMessages;
import org.hibernate.eclipse.jdt.ui.internal.jpa.common.EntityInfo;
import org.hibernate.eclipse.jdt.ui.internal.jpa.common.Utils;
+import org.hibernate.eclipse.jdt.ui.internal.jpa.process.wizard.HibernateJPAWizard;
+import org.hibernate.eclipse.jdt.ui.internal.jpa.process.wizard.IHibernateJPAWizardData;
+import
org.hibernate.eclipse.jdt.ui.internal.jpa.process.wizard.IHibernateJPAWizardParams;
/**
* Modify entity classes
*
* @author Vitali
*/
-public class AllEntitiesProcessor {
+public class AllEntitiesProcessor implements IHibernateJPAWizardParams {
/**
* place to search compilation units
@@ -89,17 +57,6 @@
protected AnnotStyle annotationStylePreference = AnnotStyle.FIELDS;
/**
- * group all information about changes of document in one structure
- */
- protected class ChangeStructure {
- public String fullyQualifiedName;
- public IPath path;
- public IDocument document;
- public TextEdit textEdit;
- public ITextFileBuffer textFileBuffer;
- public Change change;
- };
- /**
* change info storage
*/
protected ArrayList<ChangeStructure> changes = new
ArrayList<ChangeStructure>();
@@ -255,7 +212,7 @@
if (entry.getValue().isAbstractFlag()) {
continue;
}
- collectModification(bufferManager, entry.getKey(), entry.getValue());
+ collectModification(bufferManager, entry.getKey(), entry.getValue(), entities);
}
} catch (CoreException e) {
HibernateConsolePlugin.getDefault().logErrorMessage("CoreException: ", e);
//$NON-NLS-1$
@@ -263,7 +220,7 @@
}
public void collectModification(ITextFileBufferManager bufferManager, String
fullyQualifiedName,
- EntityInfo entityInfo) throws CoreException {
+ EntityInfo entityInfo, Map<String, EntityInfo> entities) throws CoreException {
ChangeStructure cs = new ChangeStructure();
cs.fullyQualifiedName = fullyQualifiedName;
@@ -281,6 +238,7 @@
ProcessEntityInfo processor = new ProcessEntityInfo();
processor.setAnnotationStyle(annotationStyle);
processor.setEntityInfo(entityInfo);
+ processor.setEntities(entities);
processor.setASTRewrite(rewriter);
cu.accept(processor);
//
@@ -297,171 +255,23 @@
public boolean showRefactoringDialog(final Map<String, EntityInfo> entities,
final ITextFileBufferManager bufferManager) {
- final String wizard_title = JdtUiMessages.AllEntitiesProcessor_header;
+ IHibernateJPAWizardData data = new IHibernateJPAWizardData() {
- Refactoring ref = new Refactoring(){
-
- @Override
- public RefactoringStatus checkFinalConditions(IProgressMonitor pm){
- return RefactoringStatus.create(Status.OK_STATUS);
+ public ITextFileBufferManager getBufferManager() {
+ return bufferManager;
}
- @Override
- public RefactoringStatus checkInitialConditions(IProgressMonitor pm) {
- return RefactoringStatus.create(Status.OK_STATUS);
+ public Map<String, EntityInfo> getEntities() {
+ return entities;
}
- @Override
- public Change createChange(IProgressMonitor pm){
-
- final CompositeChange cc = new CompositeChange(""); //$NON-NLS-1$
- for (int i = 0; i < changes.size(); i++) {
- ChangeStructure cs = changes.get(i);
- String change_name = cs.fullyQualifiedName;
- DocumentChange change = new DocumentChange(change_name, cs.document);
- change.setEdit(cs.textEdit);
- cs.change = change;
- cc.add(change);
- }
- cc.markAsSynthetic();
- return cc;
+ public ArrayList<ChangeStructure> getChanges() {
+ return changes;
}
-
- @Override
- public String getName() {
- return JdtUiMessages.SaveQueryEditorListener_composite_change_name;
- }
- };
-
- final ModifyListener ml = new ModifyListener() {
-
- public void modifyText(ModifyEvent e) {
- int idx = ((Combo)e.getSource()).getSelectionIndex();
- if (idx == 0 && !getAnnotationStyle().equals(AnnotStyle.FIELDS)) {
- setAnnotationStyle(AnnotStyle.FIELDS);
- reCollectModification(bufferManager, entities);
- }
- else if (idx == 1 && !getAnnotationStyle().equals(AnnotStyle.GETTERS)) {
- setAnnotationStyle(AnnotStyle.GETTERS);
- reCollectModification(bufferManager, entities);
- }
- else if (idx == 2 && !getAnnotationStyle().equals(AnnotStyle.AUTO)) {
- setAnnotationStyle(getAnnotationStylePreference());
- reCollectModification(bufferManager, entities);
- setAnnotationStyle(AnnotStyle.AUTO);
- }
- }
};
-
- RefactoringWizard wizard = new RefactoringWizard(ref,
RefactoringWizard.DIALOG_BASED_USER_INTERFACE) {
-
- @Override
- protected void addUserInputPages() {
- UserInputWizardPage page = new UserInputWizardPage(wizard_title) {
- public void createControl(Composite parent) {
- initializeDialogUnits(parent);
- Composite container = new Composite(parent, SWT.NULL);
- GridLayout layout = new GridLayout();
- container.setLayout(layout);
- layout.numColumns = 1;
- Label label = new Label(container, SWT.NULL);
- label.setText(JdtUiMessages.AllEntitiesProcessor_message);
-
- TableViewer listViewer = new TableViewer(container, SWT.SINGLE |
SWT.H_SCROLL
- | SWT.V_SCROLL | SWT.BORDER);
- //listViewer.setComparator(getViewerComparator());
- Control control = listViewer.getControl();
- GridData data = new GridData(GridData.FILL_BOTH
- | GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL);
- data.heightHint = convertHeightInCharsToPixels(10);
- control.setLayoutData(data);
- listViewer.setContentProvider(new IStructuredContentProvider() {
- public Object[] getElements(Object inputElement) {
- return entities.values().toArray();
- }
-
- public void dispose() {
-
- }
-
- public void inputChanged(Viewer viewer, Object oldInput,
- Object newInput) {
-
- }
- });
-
- listViewer.setLabelProvider(new LabelProvider() {
-
- private Image classImage;
-
- {
- classImage = JavaElementImageProvider.getTypeImageDescriptor(false, false, 0,
false).createImage();
-
- }
- @Override
- public String getText(Object element) {
- EntityInfo info = (EntityInfo) element;
- return info.getFullyQualifiedName();
- }
-
- @Override
- public Image getImage(Object element) {
- return classImage;
- }
-
- @Override
- public void dispose() {
- classImage.dispose();
- super.dispose();
- }
- });
-
- listViewer.setInput(entities);
- GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL)
- .grab(true, true)
-
.hint(convertHorizontalDLUsToPixels(IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH),
- convertHorizontalDLUsToPixels(2 *
IDialogConstants.BUTTON_BAR_HEIGHT)).applyTo(listViewer.getControl());
- //Button generateChoice = new Button(container, SWT.CHECK);
- //generateChoice.setText("fdwsdfv");
- Composite combolabel = new Composite(container, SWT.NULL);
- layout = new GridLayout();
- combolabel.setLayout(layout);
- layout.numColumns = 2;
- Label labelChoice = new Label(combolabel, SWT.NULL);
- labelChoice.setText(JdtUiMessages.AllEntitiesProcessor_setup_annotation_generation_preference);
- Combo generateChoice = new Combo(combolabel, SWT.READ_ONLY);
- generateChoice.add(JdtUiMessages.AllEntitiesProcessor_annotate_fields);
- generateChoice.add(JdtUiMessages.AllEntitiesProcessor_annotate_getters);
- generateChoice.add(JdtUiMessages.AllEntitiesProcessor_auto_select_from_class_preference);
- int idx = 0;
- if (getAnnotationStyle().equals(AnnotStyle.FIELDS)) {
- idx = 0;
- }
- else if (getAnnotationStyle().equals(AnnotStyle.GETTERS)) {
- idx = 1;
- }
- else if (getAnnotationStyle().equals(AnnotStyle.AUTO)) {
- idx = 2;
- }
- generateChoice.select(idx);
- generateChoice.addModifyListener(ml);
- setControl(container);
- }
- };
- addPage(page);
- }
-
- };
-
- wizard.setWindowTitle(wizard_title);
- wizard.setDefaultPageTitle(wizard_title);
-
- IWorkbenchWindow win = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
- RefactoringStarter rStarter = new RefactoringStarter();
- boolean res = rStarter.activate(wizard, win.getShell(), wizard_title,
RefactoringSaveHelper.SAVE_ALL);
- RefactoringStatus rs = rStarter.getInitialConditionCheckingStatus();
- return res;
+ HibernateJPAWizard wizard = new HibernateJPAWizard(data, this);
+ return wizard.showWizard();
}
protected void setJavaProject(IJavaProject project) {
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/jpa/process/AnnotStyle.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/jpa/process/AnnotStyle.java 2009-01-12
19:37:40 UTC (rev 13001)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/jpa/process/AnnotStyle.java 2009-01-12
20:22:25 UTC (rev 13002)
@@ -1,5 +1,8 @@
package org.hibernate.eclipse.jdt.ui.internal.jpa.process;
+/**
+ * preferable annotation style enum type
+ */
public enum AnnotStyle {
FIELDS,
GETTERS,
Added:
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/jpa/process/ChangeStructure.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/jpa/process/ChangeStructure.java
(rev 0)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/jpa/process/ChangeStructure.java 2009-01-12
20:22:25 UTC (rev 13002)
@@ -0,0 +1,19 @@
+package org.hibernate.eclipse.jdt.ui.internal.jpa.process;
+
+import org.eclipse.core.filebuffers.ITextFileBuffer;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.ltk.core.refactoring.Change;
+import org.eclipse.text.edits.TextEdit;
+
+/**
+ * group all information about changes of document in one structure
+ */
+public class ChangeStructure {
+ public String fullyQualifiedName;
+ public IPath path;
+ public IDocument document;
+ public TextEdit textEdit;
+ public ITextFileBuffer textFileBuffer;
+ public Change change;
+}
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/jpa/process/ProcessEntityInfo.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/jpa/process/ProcessEntityInfo.java 2009-01-12
19:37:40 UTC (rev 13001)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/jpa/process/ProcessEntityInfo.java 2009-01-12
20:22:25 UTC (rev 13002)
@@ -12,11 +12,13 @@
import java.util.Iterator;
import java.util.List;
+import java.util.Map;
import java.util.Set;
import org.eclipse.jdt.core.dom.ASTNode;
import org.eclipse.jdt.core.dom.ASTVisitor;
import org.eclipse.jdt.core.dom.Block;
+import org.eclipse.jdt.core.dom.BodyDeclaration;
import org.eclipse.jdt.core.dom.CompilationUnit;
import org.eclipse.jdt.core.dom.FieldDeclaration;
import org.eclipse.jdt.core.dom.ImportDeclaration;
@@ -28,15 +30,16 @@
import org.eclipse.jdt.core.dom.QualifiedName;
import org.eclipse.jdt.core.dom.ReturnStatement;
import org.eclipse.jdt.core.dom.SimpleName;
-import org.eclipse.jdt.core.dom.SimpleType;
import org.eclipse.jdt.core.dom.StringLiteral;
import org.eclipse.jdt.core.dom.Type;
import org.eclipse.jdt.core.dom.TypeDeclaration;
import org.eclipse.jdt.core.dom.VariableDeclarationFragment;
import org.eclipse.jdt.core.dom.rewrite.ASTRewrite;
import org.eclipse.jdt.core.dom.rewrite.ListRewrite;
+import org.hibernate.eclipse.jdt.ui.internal.jpa.collect.CollectEntityInfo;
import org.hibernate.eclipse.jdt.ui.internal.jpa.common.EntityInfo;
import org.hibernate.eclipse.jdt.ui.internal.jpa.common.JPAConst;
+import org.hibernate.eclipse.jdt.ui.internal.jpa.common.OwnerType;
import org.hibernate.eclipse.jdt.ui.internal.jpa.common.RefEntityInfo;
import org.hibernate.eclipse.jdt.ui.internal.jpa.common.RefFieldInfo;
import org.hibernate.eclipse.jdt.ui.internal.jpa.common.RefType;
@@ -54,6 +57,10 @@
*/
protected EntityInfo entityInfo;
/**
+ * information about all entities
+ */
+ protected Map<String, EntityInfo> entities;
+ /**
* rewriter to generate new AST blocks
*/
protected ASTRewrite rewriter;
@@ -65,6 +72,10 @@
public void setEntityInfo(EntityInfo entityInfo) {
this.entityInfo = entityInfo;
}
+
+ public void setEntities(Map<String, EntityInfo> entities) {
+ this.entities = entities;
+ }
public void setASTRewrite(ASTRewrite rewriter) {
this.rewriter = rewriter;
@@ -283,7 +294,7 @@
if (type == null) {
return true;
}
- String returnIdentifier = getReturnIdentifier(node);
+ String returnIdentifier = CollectEntityInfo.getReturnIdentifier(node);
if (type.isSimpleType() || type.isPrimitiveType()) {
if (entityInfo.isAddGeneratedValueFlag()) {
String primaryIdName = entityInfo.getPrimaryIdName();
@@ -353,45 +364,34 @@
}
return true;
}
-
- // duplicate method from CollectEntityInfo
- public String getReturnIdentifier(MethodDeclaration node) {
- String res = null;
- List bodyStatemants = node.getBody().statements();
- Iterator it = bodyStatemants.iterator();
- for ( ; it.hasNext(); ) {
- Object obj = it.next();
- if (obj instanceof ReturnStatement) {
- ReturnStatement ret_statement = (ReturnStatement)obj;
- obj = ret_statement.getExpression();
- if (obj instanceof SimpleName) {
- SimpleName sn = (SimpleName)obj;
- res = sn.getIdentifier();
- }
- break;
- }
- }
- return res;
- }
- public boolean addSimpleMarkerAnnotation(FieldDeclaration node, String name) {
+ public boolean addSimpleMarkerAnnotation(BodyDeclaration node, String name) {
if (name == null || name.length() == 0) {
return false;
}
MarkerAnnotation matd = rewriter.getAST().newMarkerAnnotation();
matd.setTypeName(rewriter.getAST().newSimpleName(name));
- ListRewrite lrw = rewriter.getListRewrite(node, FieldDeclaration.MODIFIERS2_PROPERTY);
- lrw.insertFirst(matd, null);
+ ListRewrite lrw = null;
+ if (node instanceof FieldDeclaration) {
+ lrw = rewriter.getListRewrite(node, FieldDeclaration.MODIFIERS2_PROPERTY);
+ }
+ else if (node instanceof MethodDeclaration) {
+ lrw = rewriter.getListRewrite(node, MethodDeclaration.MODIFIERS2_PROPERTY);
+ }
+ if (lrw != null) {
+ lrw.insertFirst(matd, null);
+ }
return true;
}
- public boolean addComplexNormalAnnotation(FieldDeclaration node, String name,
RefEntityInfo rei) {
+ public boolean addComplexNormalAnnotation(BodyDeclaration node, String name,
RefEntityInfo rei) {
if (name == null || name.length() == 0) {
return false;
}
NormalAnnotation natd = rewriter.getAST().newNormalAnnotation();
MemberValuePair mvp = null;
- if (rei.mappedBy != null) {
+ if (rei.mappedBy != null && (rei.owner == OwnerType.YES ||
+ rei.owner == OwnerType.UNDEF)) {
mvp = rewriter.getAST().newMemberValuePair();
mvp.setName(rewriter.getAST().newSimpleName("mappedBy")); //$NON-NLS-1$
StringLiteral sl = rewriter.getAST().newStringLiteral();
@@ -402,41 +402,39 @@
if (mvp != null) {
natd.values().add(mvp);
}
- ListRewrite lrw = rewriter.getListRewrite(node, FieldDeclaration.MODIFIERS2_PROPERTY);
- lrw.insertFirst(natd, null);
- return true;
- }
-
- public boolean addSimpleMarkerAnnotation(MethodDeclaration node, String name) {
- if (name == null || name.length() == 0) {
- return false;
+ NormalAnnotation natd2 = null;
+ /** /
+ if (rei.owner == OwnerType.NO) {
+ natd2 = rewriter.getAST().newNormalAnnotation();
+ natd2.setTypeName(rewriter.getAST().newSimpleName(JPAConst.ANNOTATION_JOINCOLUMN));
+ mvp = null;
+ String fullyQualifiedName2 = rei.fullyQualifiedName;
+ EntityInfo entryInfo2 = entities.get(fullyQualifiedName2);
+ if (entryInfo2 != null) {
+ mvp = rewriter.getAST().newMemberValuePair();
+ mvp.setName(rewriter.getAST().newSimpleName("name")); //$NON-NLS-1$
+ StringLiteral sl = rewriter.getAST().newStringLiteral();
+ sl.setLiteralValue(entryInfo2.getPrimaryIdName());
+ mvp.setValue(sl);
+ }
+ if (mvp != null) {
+ natd2.values().add(mvp);
+ }
}
- MarkerAnnotation matd = rewriter.getAST().newMarkerAnnotation();
- matd.setTypeName(rewriter.getAST().newSimpleName(name));
- ListRewrite lrw = rewriter.getListRewrite(node,
MethodDeclaration.MODIFIERS2_PROPERTY);
- lrw.insertFirst(matd, null);
- return true;
- }
-
- public boolean addComplexNormalAnnotation(MethodDeclaration node, String name,
RefEntityInfo rei) {
- if (name == null || name.length() == 0) {
- return false;
+ /**/
+ ListRewrite lrw = null;
+ if (node instanceof FieldDeclaration) {
+ lrw = rewriter.getListRewrite(node, FieldDeclaration.MODIFIERS2_PROPERTY);
}
- NormalAnnotation natd = rewriter.getAST().newNormalAnnotation();
- MemberValuePair mvp = null;
- if (rei.mappedBy != null) {
- mvp = rewriter.getAST().newMemberValuePair();
- mvp.setName(rewriter.getAST().newSimpleName("mappedBy")); //$NON-NLS-1$
- StringLiteral sl = rewriter.getAST().newStringLiteral();
- sl.setLiteralValue(rei.mappedBy);
- mvp.setValue(sl);
+ else if (node instanceof MethodDeclaration) {
+ lrw = rewriter.getListRewrite(node, MethodDeclaration.MODIFIERS2_PROPERTY);
}
- natd.setTypeName(rewriter.getAST().newSimpleName(name));
- if (mvp != null) {
- natd.values().add(mvp);
+ if (lrw != null) {
+ if (natd2 != null) {
+ lrw.insertFirst(natd2, null);
+ }
+ lrw.insertFirst(natd, null);
}
- ListRewrite lrw = rewriter.getListRewrite(node,
MethodDeclaration.MODIFIERS2_PROPERTY);
- lrw.insertFirst(natd, null);
return true;
}
Added:
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/jpa/process/wizard/EntitiesList.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/jpa/process/wizard/EntitiesList.java
(rev 0)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/jpa/process/wizard/EntitiesList.java 2009-01-12
20:22:25 UTC (rev 13002)
@@ -0,0 +1,161 @@
+/*******************************************************************************
+ * Copyright (c) 2007-2009 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is 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
+ *
+ * Contributor:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.hibernate.eclipse.jdt.ui.internal.jpa.process.wizard;
+
+import org.eclipse.jdt.internal.ui.viewsupport.JavaElementImageProvider;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.layout.GridDataFactory;
+import org.eclipse.jface.viewers.IStructuredContentProvider;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.ltk.ui.refactoring.UserInputWizardPage;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Combo;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Label;
+import org.hibernate.eclipse.jdt.ui.internal.JdtUiMessages;
+import org.hibernate.eclipse.jdt.ui.internal.jpa.common.EntityInfo;
+import org.hibernate.eclipse.jdt.ui.internal.jpa.process.AnnotStyle;
+
+/**
+ * Entities list wizard page
+ *
+ * @author Vitali
+ */
+public class EntitiesList extends UserInputWizardPage {
+
+ protected IHibernateJPAWizardData data;
+
+ protected IHibernateJPAWizardParams params;
+
+ public EntitiesList(String name, IHibernateJPAWizardData data, IHibernateJPAWizardParams
params) {
+ super(name);
+ this.data = data;
+ this.params = params;
+ }
+
+ public void createControl(Composite parent) {
+ initializeDialogUnits(parent);
+ Composite container = new Composite(parent, SWT.NULL);
+ GridLayout layout = new GridLayout();
+ container.setLayout(layout);
+ layout.numColumns = 1;
+ Label label = new Label(container, SWT.NULL);
+ label.setText(JdtUiMessages.AllEntitiesProcessor_message);
+
+ TableViewer listViewer = new TableViewer(container, SWT.SINGLE | SWT.H_SCROLL
+ | SWT.V_SCROLL | SWT.BORDER);
+ //listViewer.setComparator(getViewerComparator());
+ Control control = listViewer.getControl();
+ GridData gridData = new GridData(GridData.FILL_BOTH
+ | GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL);
+ gridData.heightHint = convertHeightInCharsToPixels(10);
+ control.setLayoutData(gridData);
+ listViewer.setContentProvider(new IStructuredContentProvider() {
+ public Object[] getElements(Object inputElement) {
+ return data.getEntities().values().toArray();
+ }
+
+ public void dispose() {
+
+ }
+
+ public void inputChanged(Viewer viewer, Object oldInput,
+ Object newInput) {
+
+ }
+ });
+
+ listViewer.setLabelProvider(new LabelProvider() {
+
+ private Image classImage;
+
+ {
+ classImage = JavaElementImageProvider.getTypeImageDescriptor(false, false, 0,
false).createImage();
+
+ }
+ @Override
+ public String getText(Object element) {
+ EntityInfo info = (EntityInfo) element;
+ return info.getFullyQualifiedName();
+ }
+
+ @Override
+ public Image getImage(Object element) {
+ return classImage;
+ }
+
+ @Override
+ public void dispose() {
+ classImage.dispose();
+ super.dispose();
+ }
+ });
+
+ listViewer.setInput(data.getEntities());
+ GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL)
+ .grab(true, true)
+ .hint(convertHorizontalDLUsToPixels(IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH),
+ convertHorizontalDLUsToPixels(2 *
IDialogConstants.BUTTON_BAR_HEIGHT)).applyTo(listViewer.getControl());
+ //Button generateChoice = new Button(container, SWT.CHECK);
+ //generateChoice.setText("fdwsdfv");
+ Composite combolabel = new Composite(container, SWT.NULL);
+ layout = new GridLayout();
+ combolabel.setLayout(layout);
+ layout.numColumns = 2;
+ Label labelChoice = new Label(combolabel, SWT.NULL);
+ labelChoice.setText(JdtUiMessages.AllEntitiesProcessor_setup_annotation_generation_preference);
+ Combo generateChoice = new Combo(combolabel, SWT.READ_ONLY);
+ generateChoice.add(JdtUiMessages.AllEntitiesProcessor_annotate_fields);
+ generateChoice.add(JdtUiMessages.AllEntitiesProcessor_annotate_getters);
+ generateChoice.add(JdtUiMessages.AllEntitiesProcessor_auto_select_from_class_preference);
+ int idx = 0;
+ if (params.getAnnotationStyle().equals(AnnotStyle.FIELDS)) {
+ idx = 0;
+ }
+ else if (params.getAnnotationStyle().equals(AnnotStyle.GETTERS)) {
+ idx = 1;
+ }
+ else if (params.getAnnotationStyle().equals(AnnotStyle.AUTO)) {
+ idx = 2;
+ }
+ generateChoice.select(idx);
+ final ModifyListener ml = new ModifyListener() {
+
+ public void modifyText(ModifyEvent e) {
+ int idx = ((Combo)e.getSource()).getSelectionIndex();
+ if (idx == 0 && !params.getAnnotationStyle().equals(AnnotStyle.FIELDS)) {
+ params.setAnnotationStyle(AnnotStyle.FIELDS);
+ params.reCollectModification(data.getBufferManager(), data.getEntities());
+ }
+ else if (idx == 1 && !params.getAnnotationStyle().equals(AnnotStyle.GETTERS))
{
+ params.setAnnotationStyle(AnnotStyle.GETTERS);
+ params.reCollectModification(data.getBufferManager(), data.getEntities());
+ }
+ else if (idx == 2 && !params.getAnnotationStyle().equals(AnnotStyle.AUTO)) {
+ params.setAnnotationStyle(params.getAnnotationStylePreference());
+ params.reCollectModification(data.getBufferManager(), data.getEntities());
+ params.setAnnotationStyle(AnnotStyle.AUTO);
+ }
+ }
+
+ };
+ generateChoice.addModifyListener(ml);
+ setControl(container);
+ }
+}
Added:
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/jpa/process/wizard/HibernateJPARefactoring.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/jpa/process/wizard/HibernateJPARefactoring.java
(rev 0)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/jpa/process/wizard/HibernateJPARefactoring.java 2009-01-12
20:22:25 UTC (rev 13002)
@@ -0,0 +1,71 @@
+/*******************************************************************************
+ * Copyright (c) 2007-2009 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is 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
+ *
+ * Contributor:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.hibernate.eclipse.jdt.ui.internal.jpa.process.wizard;
+
+import java.util.ArrayList;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.ltk.core.refactoring.Change;
+import org.eclipse.ltk.core.refactoring.CompositeChange;
+import org.eclipse.ltk.core.refactoring.DocumentChange;
+import org.eclipse.ltk.core.refactoring.Refactoring;
+import org.eclipse.ltk.core.refactoring.RefactoringStatus;
+import org.hibernate.eclipse.jdt.ui.internal.JdtUiMessages;
+import org.hibernate.eclipse.jdt.ui.internal.jpa.process.ChangeStructure;
+
+/**
+ * Hibernate JPA refactoring
+ *
+ * @author Vitali
+ */
+public class HibernateJPARefactoring extends Refactoring {
+
+ /**
+ * change info storage
+ */
+ protected ArrayList<ChangeStructure> changes;
+
+ public HibernateJPARefactoring(ArrayList<ChangeStructure> changes) {
+ this.changes = changes;
+ }
+
+ @Override
+ public RefactoringStatus checkFinalConditions(IProgressMonitor pm){
+ return RefactoringStatus.create(Status.OK_STATUS);
+ }
+
+ @Override
+ public RefactoringStatus checkInitialConditions(IProgressMonitor pm) {
+ return RefactoringStatus.create(Status.OK_STATUS);
+ }
+
+ @Override
+ public Change createChange(IProgressMonitor pm){
+
+ final CompositeChange cc = new CompositeChange(""); //$NON-NLS-1$
+ for (int i = 0; i < changes.size(); i++) {
+ ChangeStructure cs = changes.get(i);
+ String change_name = cs.fullyQualifiedName;
+ DocumentChange change = new DocumentChange(change_name, cs.document);
+ change.setEdit(cs.textEdit);
+ cs.change = change;
+ cc.add(change);
+ }
+ cc.markAsSynthetic();
+ return cc;
+ }
+
+ @Override
+ public String getName() {
+ return JdtUiMessages.SaveQueryEditorListener_composite_change_name;
+ }
+}
Added:
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/jpa/process/wizard/HibernateJPAWizard.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/jpa/process/wizard/HibernateJPAWizard.java
(rev 0)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/jpa/process/wizard/HibernateJPAWizard.java 2009-01-12
20:22:25 UTC (rev 13002)
@@ -0,0 +1,63 @@
+/*******************************************************************************
+ * Copyright (c) 2007-2009 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is 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
+ *
+ * Contributor:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.hibernate.eclipse.jdt.ui.internal.jpa.process.wizard;
+
+import org.eclipse.jdt.internal.ui.refactoring.RefactoringSaveHelper;
+import org.eclipse.jdt.internal.ui.refactoring.actions.RefactoringStarter;
+import org.eclipse.ltk.core.refactoring.RefactoringStatus;
+import org.eclipse.ltk.ui.refactoring.RefactoringWizard;
+import org.eclipse.ltk.ui.refactoring.UserInputWizardPage;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.PlatformUI;
+import org.hibernate.eclipse.jdt.ui.internal.JdtUiMessages;
+
+/**
+ * Hibernate JPA refactoring wizard dialog
+ *
+ * @author Vitali
+ */
+public class HibernateJPAWizard extends RefactoringWizard {
+
+ protected final String wizard_title = JdtUiMessages.AllEntitiesProcessor_header;
+
+ protected IHibernateJPAWizardData data;
+
+ protected IHibernateJPAWizardParams params;
+
+ public HibernateJPAWizard(IHibernateJPAWizardData data, IHibernateJPAWizardParams
params) {
+ super(new HibernateJPARefactoring(data.getChanges()),
RefactoringWizard.WIZARD_BASED_USER_INTERFACE);
+ this.data = data;
+ this.params = params;
+ setWindowTitle(wizard_title);
+ setDefaultPageTitle(wizard_title);
+ }
+
+ @Override
+ protected void addUserInputPages() {
+ UserInputWizardPage page = new EntitiesList(wizard_title, data, params);
+ addPage(page);
+ UserInputWizardPage page2 = new ResolveAmbiguous(wizard_title, data, params);
+ addPage(page2);
+ }
+
+ public HibernateJPARefactoring getHibernateJPARefactoring() {
+ return (HibernateJPARefactoring)getRefactoring();
+ }
+
+ public boolean showWizard() {
+ IWorkbenchWindow win = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
+ RefactoringStarter refactoringStarter = new RefactoringStarter();
+ boolean res = refactoringStarter.activate(this, win.getShell(), wizard_title,
RefactoringSaveHelper.SAVE_ALL);
+ RefactoringStatus rs = refactoringStarter.getInitialConditionCheckingStatus();
+ return res;
+ }
+
+}
Added:
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/jpa/process/wizard/IHibernateJPAWizardData.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/jpa/process/wizard/IHibernateJPAWizardData.java
(rev 0)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/jpa/process/wizard/IHibernateJPAWizardData.java 2009-01-12
20:22:25 UTC (rev 13002)
@@ -0,0 +1,32 @@
+/*******************************************************************************
+ * Copyright (c) 2007-2009 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is 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
+ *
+ * Contributor:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.hibernate.eclipse.jdt.ui.internal.jpa.process.wizard;
+
+import java.util.ArrayList;
+import java.util.Map;
+
+import org.eclipse.core.filebuffers.ITextFileBufferManager;
+import org.hibernate.eclipse.jdt.ui.internal.jpa.common.EntityInfo;
+import org.hibernate.eclipse.jdt.ui.internal.jpa.process.ChangeStructure;
+
+/**
+ * Hibernate JPA wizard data for modification provide interface
+ *
+ * @author Vitali
+ */
+public interface IHibernateJPAWizardData {
+
+ public Map<String, EntityInfo> getEntities();
+
+ public ITextFileBufferManager getBufferManager();
+
+ public ArrayList<ChangeStructure> getChanges();
+}
Added:
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/jpa/process/wizard/IHibernateJPAWizardParams.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/jpa/process/wizard/IHibernateJPAWizardParams.java
(rev 0)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/jpa/process/wizard/IHibernateJPAWizardParams.java 2009-01-12
20:22:25 UTC (rev 13002)
@@ -0,0 +1,34 @@
+/*******************************************************************************
+ * Copyright (c) 2007-2009 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is 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
+ *
+ * Contributor:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.hibernate.eclipse.jdt.ui.internal.jpa.process.wizard;
+
+import java.util.Map;
+
+import org.eclipse.core.filebuffers.ITextFileBufferManager;
+import org.hibernate.eclipse.jdt.ui.internal.jpa.common.EntityInfo;
+import org.hibernate.eclipse.jdt.ui.internal.jpa.process.AnnotStyle;
+
+/**
+ * Hibernate JPA wizard input parameters interface
+ *
+ * @author Vitali
+ */
+public interface IHibernateJPAWizardParams {
+
+ public AnnotStyle getAnnotationStyle();
+
+ public void setAnnotationStyle(AnnotStyle annotationStyle);
+
+ public AnnotStyle getAnnotationStylePreference();
+
+ public void reCollectModification(ITextFileBufferManager bufferManager,
+ Map<String, EntityInfo> entities);
+}
Added:
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/jpa/process/wizard/ResolveAmbiguous.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/jpa/process/wizard/ResolveAmbiguous.java
(rev 0)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/jpa/process/wizard/ResolveAmbiguous.java 2009-01-12
20:22:25 UTC (rev 13002)
@@ -0,0 +1,480 @@
+/*******************************************************************************
+ * Copyright (c) 2007-2009 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is 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
+ *
+ * Contributor:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.hibernate.eclipse.jdt.ui.internal.jpa.process.wizard;
+
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+
+import org.eclipse.ltk.ui.refactoring.UserInputWizardPage;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.CCombo;
+import org.eclipse.swt.custom.TableEditor;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Table;
+import org.eclipse.swt.widgets.TableColumn;
+import org.eclipse.swt.widgets.TableItem;
+import org.hibernate.eclipse.jdt.ui.internal.JdtUiMessages;
+import org.hibernate.eclipse.jdt.ui.internal.jpa.common.EntityInfo;
+import org.hibernate.eclipse.jdt.ui.internal.jpa.common.OwnerType;
+import org.hibernate.eclipse.jdt.ui.internal.jpa.common.RefEntityInfo;
+import org.hibernate.eclipse.jdt.ui.internal.jpa.common.RefFieldInfo;
+import org.hibernate.eclipse.jdt.ui.internal.jpa.common.RefType;
+
+/**
+ * Resolve ambiguous list wizard page
+ *
+ * @author Vitali
+ */
+public class ResolveAmbiguous extends UserInputWizardPage {
+
+ protected IHibernateJPAWizardData data;
+
+ protected IHibernateJPAWizardParams params;
+
+ protected final int COLUMN_CLASS = 0;
+ protected final int COLUMN_ASSOCIATION = 1;
+ protected final int COLUMN_TYPE = 2;
+ protected final int COLUMN_RELATED = 3;
+ protected final int COLUMN_OWNER = 4;
+
+ protected Table table;
+ protected TableEditor editorType;
+ protected TableEditor editorRel;
+ protected TableEditor editorOwner;
+
+ protected EditorTypeModifyListener editorTypeModifyListener = new
EditorTypeModifyListener();
+ protected EditorRelModifyListener editorRelModifyListener = new
EditorRelModifyListener();
+ protected EditorOwnerModifyListener editorOwnerModifyListener = new
EditorOwnerModifyListener();
+
+ public ResolveAmbiguous(String name, IHibernateJPAWizardData data,
IHibernateJPAWizardParams params) {
+ super(name);
+ this.data = data;
+ this.params = params;
+ }
+
+ public void createControl(Composite parent) {
+ Composite container = new Composite(parent, SWT.NULL);
+ GridLayout layout = new GridLayout();
+ container.setLayout(layout);
+ layout.numColumns = 1;
+ Label label = new Label(container, SWT.NULL);
+ label.setText(JdtUiMessages.ResolveAmbiguous_message);
+ table = new Table(container, SWT.SINGLE | SWT.BORDER | SWT.H_SCROLL |
SWT.V_SCROLL | SWT.FULL_SELECTION );
+ table.setHeaderVisible(true);
+ table.setLinesVisible(true);
+ createTableColumns(table);
+ TableItem ti = null;
+ Iterator<Map.Entry<String, EntityInfo>> it =
data.getEntities().entrySet().iterator();
+ while (it.hasNext()) {
+ Map.Entry<String, EntityInfo> entry = it.next();
+ if (entry.getValue().isAbstractFlag()) {
+ continue;
+ }
+ //collectModification(bufferManager, entry.getKey(), entry.getValue());
+ Iterator<Map.Entry<String, RefEntityInfo>> referencesIt =
+ entry.getValue().getReferences().entrySet().iterator();
+ while (referencesIt.hasNext()) {
+ Map.Entry<String, RefEntityInfo> entryRef = referencesIt.next();
+ RefEntityInfo rei = entryRef.getValue();
+ ti = new TableItem(table, SWT.NONE);
+ ti.setData(rei);
+ ti.setText(COLUMN_CLASS, entry.getKey());
+ String shortName = getShortName(rei.fullyQualifiedName);
+ ti.setText(COLUMN_ASSOCIATION, shortName + " " + entryRef.getKey());
//$NON-NLS-1$
+ ti.setText(COLUMN_TYPE, rei.refType.toString());
+ if (null != rei.mappedBy) {
+ ti.setText(COLUMN_RELATED, rei.mappedBy);
+ }
+ else {
+ ti.setText(COLUMN_RELATED, JdtUiMessages.ResolveAmbiguous_empty);
+ }
+ ti.setText(COLUMN_OWNER, rei.owner.toString());
+ }
+ }
+ //
+ editorType = new TableEditor(table);
+ //The editor must have the same size as the cell and must
+ //not be any smaller than 50 pixels.
+ editorType.horizontalAlignment = SWT.LEFT;
+ editorType.grabHorizontal = true;
+ editorType.minimumWidth = 50;
+ //
+ editorRel = new TableEditor(table);
+ //The editor must have the same size as the cell and must
+ //not be any smaller than 50 pixels.
+ editorRel.horizontalAlignment = SWT.LEFT;
+ editorRel.grabHorizontal = true;
+ editorRel.minimumWidth = 50;
+ //
+ editorOwner = new TableEditor(table);
+ //The editor must have the same size as the cell and must
+ //not be any smaller than 50 pixels.
+ editorOwner.horizontalAlignment = SWT.LEFT;
+ editorOwner.grabHorizontal = true;
+ editorOwner.minimumWidth = 50;
+ // editing the second column
+ table.addSelectionListener(new TableSelectionListener());
+ GridData data = new GridData(GridData.FILL_BOTH
+ | GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL);
+ data.heightHint = convertHeightInCharsToPixels(10);
+ table.setLayoutData(data);
+ setControl(container);
+ }
+
+ protected class EditorTypeModifyListener implements ModifyListener {
+ public void modifyText(ModifyEvent e) {
+ CCombo text = (CCombo)editorType.getEditor();
+ String str = text.getText();
+ //editorType.getItem().setText(COLUMN_TYPE, str);
+ TableItem ti = editorType.getItem();
+ RefEntityInfo rei = (RefEntityInfo)ti.getData();
+ RefType oldVal = rei.refType;
+ OwnerType oldVal2 = rei.owner;
+ if (str.equalsIgnoreCase(RefType.ONE2ONE.toString())) {
+ rei.refType = RefType.ONE2ONE;
+ }
+ else if (str.equalsIgnoreCase(RefType.ONE2MANY.toString())) {
+ rei.refType = RefType.ONE2MANY;
+ rei.owner = OwnerType.YES;
+ }
+ else if (str.equalsIgnoreCase(RefType.MANY2ONE.toString())) {
+ rei.refType = RefType.MANY2ONE;
+ rei.owner = OwnerType.NO;
+ }
+ else if (str.equalsIgnoreCase(RefType.MANY2MANY.toString())) {
+ rei.refType = RefType.MANY2MANY;
+ }
+ else if (str.equalsIgnoreCase(RefType.UNDEF.toString())) {
+ rei.refType = RefType.UNDEF;
+ }
+ if (oldVal != rei.refType || oldVal2 != rei.owner) {
+ RefEntityInfo rei2 = findMappedRefEntityInfo(rei);
+ // firstly search
+ TableItem ti2 = findTableItem(rei2, rei);
+ // then - update
+ updateDependentRefEntityInfoType(rei, rei2);
+ updateEditorOwner(ti);
+ updateTI(ti);
+ updateTI(ti2);
+ params.reCollectModification(data.getBufferManager(), data.getEntities());
+ }
+ }
+ }
+
+ public void updateDependentRefEntityInfoType(RefEntityInfo rei, RefEntityInfo rei2) {
+ if (rei == null) {
+ return;
+ }
+ if (rei.refType == RefType.MANY2ONE) {
+ rei.owner = OwnerType.NO;
+ if (rei2 != null) {
+ rei2.refType = RefType.ONE2MANY;
+ rei2.owner = OwnerType.YES;
+ }
+ }
+ if (rei.refType == RefType.ONE2MANY) {
+ rei.owner = OwnerType.YES;
+ if (rei2 != null) {
+ rei2.refType = RefType.MANY2ONE;
+ rei2.owner = OwnerType.NO;
+ }
+ }
+ }
+
+ public void updateEditorType(TableItem item) {
+ // Clean up any previous editor control
+ Control oldEditorType = editorType.getEditor();
+ if (oldEditorType != null) {
+ oldEditorType.dispose();
+ }
+ // The control that will be the editor must be a child of the Table
+ CCombo comboType = new CCombo(table, SWT.NONE);
+ comboType.setEditable(false);
+ Color bkgnd = table.getBackground();
+ comboType.setBackground(bkgnd);
+ RefEntityInfo rei = (RefEntityInfo)item.getData();
+ comboType.add(RefType.ONE2ONE.toString());
+ comboType.add(RefType.ONE2MANY.toString());
+ comboType.add(RefType.MANY2ONE.toString());
+ comboType.add(RefType.MANY2MANY.toString());
+ comboType.add(RefType.UNDEF.toString());
+ comboType.setText(rei.refType.toString());
+ comboType.addModifyListener(editorTypeModifyListener);
+ //comboType.selectAll();
+ comboType.setFocus();
+ editorType.setEditor(comboType, item, COLUMN_TYPE);
+ }
+
+ protected class EditorRelModifyListener implements ModifyListener {
+ public void modifyText(ModifyEvent e) {
+ CCombo text = (CCombo)editorRel.getEditor();
+ String str = text.getText();
+ //editorRel.getItem().setText(COLUMN_RELATED, str);
+ TableItem ti = editorRel.getItem();
+ RefEntityInfo rei = (RefEntityInfo)ti.getData();
+ String oldVal = rei.mappedBy;
+ if (JdtUiMessages.ResolveAmbiguous_empty.equals(str)) {
+ rei.mappedBy = null;
+ }
+ else {
+ rei.mappedBy = str;
+ }
+ if (oldVal != rei.mappedBy) {
+ rei.refType = RefType.UNDEF;
+ rei.owner = OwnerType.UNDEF;
+ //RefEntityInfo rei2 = findMappedRefEntityInfo(rei);
+ // firstly search
+ //TableItem ti2 = findTableItem(rei2, rei);
+ // then - update
+ updateEditorType(ti);
+ updateEditorOwner(ti);
+ updateTI(ti);
+ params.reCollectModification(data.getBufferManager(), data.getEntities());
+ }
+ }
+ }
+
+ public void updateEditorRel(TableItem item) {
+ // Clean up any previous editor control
+ Control oldEditorRel = editorRel.getEditor();
+ if (oldEditorRel != null) {
+ oldEditorRel.dispose();
+ }
+ CCombo comboRel = new CCombo(table, SWT.NONE);
+ comboRel.setEditable(false);
+ Color bkgnd = table.getBackground();
+ comboRel.setBackground(bkgnd);
+ comboRel.add(JdtUiMessages.ResolveAmbiguous_empty);
+ String fullyQualifiedName = item.getText(0);
+ RefEntityInfo rei = (RefEntityInfo)item.getData();
+ Set<RefFieldInfo> setRefEntityInfo = findRelatedRefFieldInfos(fullyQualifiedName,
rei);
+ Iterator<RefFieldInfo> itTmp = setRefEntityInfo.iterator();
+ while (itTmp.hasNext()) {
+ RefFieldInfo rfi = itTmp.next();
+ comboRel.add(rfi.fieldId);
+ }
+ if (null != rei.mappedBy) {
+ comboRel.setText(rei.mappedBy);
+ }
+ else {
+ comboRel.setText(JdtUiMessages.ResolveAmbiguous_empty);
+ }
+ comboRel.addModifyListener(editorRelModifyListener);
+ //comboRel.selectAll();
+ //comboRel.setFocus();
+ editorRel.setEditor(comboRel, item, COLUMN_RELATED);
+ }
+
+ protected class EditorOwnerModifyListener implements ModifyListener {
+ public void modifyText(ModifyEvent e) {
+ CCombo text = (CCombo)editorOwner.getEditor();
+ String str = text.getText();
+ //editorOwner.getItem().setText(COLUMN_OWNER, str);
+ TableItem ti = editorOwner.getItem();
+ RefEntityInfo rei = (RefEntityInfo)ti.getData();
+ OwnerType oldVal = rei.owner;
+ if (str.equalsIgnoreCase(OwnerType.YES.toString())) {
+ rei.owner = OwnerType.YES;
+ }
+ else if (str.equalsIgnoreCase(OwnerType.NO.toString())) {
+ rei.owner = OwnerType.NO;
+ }
+ else if (str.equalsIgnoreCase(OwnerType.UNDEF.toString())) {
+ rei.owner = OwnerType.UNDEF;
+ }
+ if (oldVal != rei.owner) {
+ RefEntityInfo rei2 = findMappedRefEntityInfo(rei);
+ // firstly search
+ TableItem ti2 = findTableItem(rei2, rei);
+ // then - update
+ updateDependentRefEntityInfoOwner(rei, rei2);
+ updateEditorType(ti);
+ updateTI(ti);
+ updateTI(ti2);
+ params.reCollectModification(data.getBufferManager(), data.getEntities());
+ }
+ }
+ }
+
+ public void updateDependentRefEntityInfoOwner(RefEntityInfo rei, RefEntityInfo rei2) {
+ if (rei == null) {
+ return;
+ }
+ if (rei2 != null) {
+ if (rei.refType == RefType.ONE2ONE || rei.refType == RefType.MANY2MANY) {
+ if (rei.owner == OwnerType.YES) {
+ rei2.owner = OwnerType.NO;
+ } else if (rei.owner == OwnerType.NO) {
+ rei2.owner = OwnerType.YES;
+ }
+ }
+ }
+ if (rei.refType == RefType.MANY2ONE) {
+ if (rei.owner == OwnerType.YES) {
+ rei.refType = RefType.UNDEF;
+ if (rei2 != null) {
+ rei2.refType = RefType.UNDEF;
+ rei2.owner = OwnerType.NO;
+ }
+ }
+ else if (rei2 != null) {
+ rei2.owner = OwnerType.YES;
+ }
+ }
+ if (rei.refType == RefType.ONE2MANY) {
+ if (rei.owner == OwnerType.NO) {
+ rei.refType = RefType.UNDEF;
+ if (rei2 != null) {
+ rei2.refType = RefType.UNDEF;
+ rei2.owner = OwnerType.YES;
+ }
+ }
+ else if (rei2 != null) {
+ rei2.owner = OwnerType.NO;
+ }
+ }
+ }
+
+ public void updateEditorOwner(TableItem item) {
+ // Clean up any previous editor control
+ Control oldEditorOwner = editorOwner.getEditor();
+ if (oldEditorOwner != null) {
+ oldEditorOwner.dispose();
+ }
+ RefEntityInfo rei = (RefEntityInfo)item.getData();
+ CCombo comboOwner = new CCombo(table, SWT.NONE);
+ comboOwner.setEditable(false);
+ Color bkgnd = table.getBackground();
+ comboOwner.setBackground(bkgnd);
+ comboOwner.add(OwnerType.YES.toString());
+ comboOwner.add(OwnerType.NO.toString());
+ comboOwner.setText(rei.owner.toString());
+ comboOwner.addModifyListener(editorOwnerModifyListener);
+ editorOwner.setEditor(comboOwner, item, COLUMN_OWNER);
+ }
+
+ protected class TableSelectionListener extends SelectionAdapter {
+ public void widgetSelected(SelectionEvent e) {
+ // Identify the selected row
+ TableItem item = (TableItem)e.item;
+ if (item == null) {
+ return;
+ }
+ updateEditorType(item);
+ updateEditorRel(item);
+ updateEditorOwner(item);
+ }
+ }
+
+ public void updateTI(TableItem ti) {
+ if (ti == null) {
+ return;
+ }
+ RefEntityInfo rei = (RefEntityInfo)ti.getData();
+ ti.setText(COLUMN_TYPE, rei.refType.toString());
+ if (null != rei.mappedBy) {
+ ti.setText(COLUMN_RELATED, rei.mappedBy);
+ }
+ else {
+ ti.setText(COLUMN_RELATED, JdtUiMessages.ResolveAmbiguous_empty);
+ }
+ ti.setText(COLUMN_OWNER, rei.owner.toString());
+ }
+
+ protected void createTableColumns(Table table) {
+ TableColumn column = null;
+
+ column = new TableColumn(table, SWT.LEFT, COLUMN_CLASS);
+ column.setText(JdtUiMessages.ResolveAmbiguous_column_Class);
+ column.setWidth(200);
+
+ column = new TableColumn(table, SWT.LEFT, COLUMN_ASSOCIATION);
+ column.setText(JdtUiMessages.ResolveAmbiguous_column_Association);
+ column.setWidth(100);
+
+ column = new TableColumn(table, SWT.LEFT, COLUMN_TYPE);
+ column.setText(JdtUiMessages.ResolveAmbiguous_column_Type);
+ column.setWidth(80);
+
+ column = new TableColumn(table, SWT.LEFT, COLUMN_RELATED);
+ column.setText(JdtUiMessages.ResolveAmbiguous_column_Related);
+ column.setWidth(70);
+
+ column = new TableColumn(table, SWT.LEFT, COLUMN_OWNER);
+ column.setText(JdtUiMessages.ResolveAmbiguous_column_Owner);
+ column.setWidth(50);
+ }
+
+ public String getShortName(String fullyQualifiedName) {
+ int idx = fullyQualifiedName.lastIndexOf('.');
+ if (idx == -1) {
+ return fullyQualifiedName;
+ }
+ return fullyQualifiedName.substring(idx + 1);
+ }
+
+ protected Set<RefFieldInfo> findRelatedRefFieldInfos(
+ String fullyQualifiedName, RefEntityInfo rei) {
+ String fullyQualifiedName2 = rei.fullyQualifiedName;
+ EntityInfo entryInfo2 = data.getEntities().get(fullyQualifiedName2);
+ Set<RefFieldInfo> setRefEntityInfo =
entryInfo2.getRefFieldInfoSet(fullyQualifiedName);
+ return setRefEntityInfo;
+ }
+
+ protected RefEntityInfo findMappedRefEntityInfo(RefEntityInfo rei) {
+ if (rei.mappedBy == null) {
+ return null;
+ }
+ String fullyQualifiedName2 = rei.fullyQualifiedName;
+ EntityInfo entryInfo2 = data.getEntities().get(fullyQualifiedName2);
+ RefEntityInfo refEntityInfo = entryInfo2.getFieldIdRefEntityInfo(rei.mappedBy);
+ return refEntityInfo;
+ }
+
+ public String getFieldId(String fieldId) {
+ int idx = fieldId.lastIndexOf(' ');
+ if (idx == -1) {
+ return fieldId;
+ }
+ return fieldId.substring(idx + 1);
+ }
+
+ protected TableItem findTableItem(RefEntityInfo rei1, RefEntityInfo rei2) {
+ if (rei1 == null || rei2 == null ) {
+ return null;
+ }
+ TableItem ti = null, tiRes = null;
+ TableItem[] tis = table.getItems();
+ for (int i = 0; i < tis.length; i++) {
+ ti = tis[i];
+ if (!ti.getText(COLUMN_CLASS).equals(rei2.fullyQualifiedName)) {
+ continue;
+ }
+ String fieldId1 = getFieldId(ti.getText(COLUMN_ASSOCIATION));
+ String fieldId2 = ti.getText(COLUMN_RELATED);
+ if (fieldId2.equals(rei1.mappedBy) && fieldId1.equals(rei2.mappedBy)) {
+ tiRes = ti;
+ break;
+ }
+ }
+ return tiRes;
+ }
+}