Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTran Le2012-10-17 22:48:48 +0000
committerTran Le2012-10-17 22:48:48 +0000
commit0717147417d1d612bec45150736101a7e4ac02fa (patch)
tree3f1f67d2f0751faeb43332676bcf806af9d5c6c5
parent9c87d1a223de909ed3f1361ffd0e850856484221 (diff)
downloadwebtools.dali-201210172249.tar.gz
webtools.dali-201210172249.tar.xz
webtools.dali-201210172249.zip
278049 - Entities from Tables wizard does not indicate that it will adv201210172249
Serializable interface
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.gen/src/org/eclipse/jpt/jpa/gen/internal/ORMGenTable.java13
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/gen/DefaultTableGenerationWizardPage.java59
2 files changed, 57 insertions, 15 deletions
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.gen/src/org/eclipse/jpt/jpa/gen/internal/ORMGenTable.java b/jpa/plugins/org.eclipse.jpt.jpa.gen/src/org/eclipse/jpt/jpa/gen/internal/ORMGenTable.java
index 73d4a91a2d..1eff2cf954 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.gen/src/org/eclipse/jpt/jpa/gen/internal/ORMGenTable.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.gen/src/org/eclipse/jpt/jpa/gen/internal/ORMGenTable.java
@@ -40,6 +40,7 @@ public class ORMGenTable
private List<ORMGenColumn> mColumns;
private Table mDbTable;
private HashMap<String, String> columnTypesMap = null;
+ public static String SERIALIZABLE_INTERFACE = "java.io.Serializable"; //$NON-NLS-1$
/**
* @param table
* The database table or null if this table is used to get/set
@@ -573,11 +574,15 @@ public class ORMGenTable
if (extendsClass != null && !extendsClass.equals("java.lang.Object") && !extendsClass.equals("Object")) {
buffer.append("extends " + simplifyClassName(extendsClass) + " "); //fix for bug 278626
}
- buffer.append("implements Serializable"); // assuming that the Java
- // file template imports the
- // java.io.Serializable
+ boolean firstInterface = true;
for (Iterator<String> iter = getImplements().iterator(); iter.hasNext();) {
- buffer.append(", " + simplifyClassName(iter.next()));
+ if(firstInterface) {
+ buffer.append("implements " + simplifyClassName(iter.next()));
+ firstInterface = false;
+ }
+ else {
+ buffer.append(", " + simplifyClassName(iter.next()));
+ }
}
return buffer.toString();
}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/gen/DefaultTableGenerationWizardPage.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/gen/DefaultTableGenerationWizardPage.java
index 410df7ccc0..a83f32beff 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/gen/DefaultTableGenerationWizardPage.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/gen/DefaultTableGenerationWizardPage.java
@@ -34,6 +34,7 @@ import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.viewers.ViewerFilter;
import org.eclipse.jface.window.Window;
import org.eclipse.jpt.common.core.internal.utility.JDTTools;
+import org.eclipse.jpt.common.utility.internal.CollectionTools;
import org.eclipse.jpt.jpa.core.JpaProject;
import org.eclipse.jpt.jpa.gen.internal.ORMGenCustomizer;
import org.eclipse.jpt.jpa.gen.internal.ORMGenTable;
@@ -67,6 +68,8 @@ public class DefaultTableGenerationWizardPage extends NewTypeWizardPage {
protected TableGenPanel defaultTableGenPanel ;
+ protected static String SERIALIZABLE_INTERFACE = ORMGenTable.SERIALIZABLE_INTERFACE;
+
public DefaultTableGenerationWizardPage(JpaProject jpaProject) {
super(true, "DefaultTableGenerationWizardPage"); //$NON-NLS-1$
this.jpaProject = jpaProject;
@@ -128,9 +131,9 @@ public class DefaultTableGenerationWizardPage extends NewTypeWizardPage {
this.defaultTableGenPanel.setORMGenTable(this.defaultsTable);
defaultTableGenPanel.updateControls();
//set the super class and implemented interfaces value
- String baseClass = this.defaultsTable.getExtends() == null ?"" : this.defaultsTable.getExtends();
- this.setSuperClass(baseClass, true);
- this.setSuperInterfaces(this.defaultsTable.getImplements(), true);
+ this.setTableSuperClass(this.defaultsTable);
+ this.setTableSuperInterfaces(this.defaultsTable);
+
IPackageFragmentRoot root = getSourceFolder(this.defaultsTable.getSourceFolder());
String initPackageName = this.getPackageText();
if(initPackageName.length() == 0) {
@@ -141,6 +144,23 @@ public class DefaultTableGenerationWizardPage extends NewTypeWizardPage {
}
}
+ private void setTableSuperClass(ORMGenTable genTable) {
+ String baseClass = genTable.getExtends() == null ? "" : genTable.getExtends();
+ this.setSuperClass(baseClass, true);
+ }
+
+ private void setTableSuperInterfaces(ORMGenTable genTable) {
+ List<String> superInterfaces = new ArrayList<String>(genTable.getImplements());
+ if( ! this.interfacesHasSerializable(superInterfaces)) {
+ superInterfaces.add(SERIALIZABLE_INTERFACE);
+ }
+ this.setSuperInterfaces(superInterfaces, true);
+ }
+
+ private boolean interfacesHasSerializable(List<String> interfaces) {
+ return CollectionTools.contains(interfaces.iterator(), SERIALIZABLE_INTERFACE);
+ }
+
//search for the source folder with the given name or return the first
//source folder if not found.
private IPackageFragmentRoot getSourceFolder(String srcFolder) {
@@ -299,18 +319,35 @@ public class DefaultTableGenerationWizardPage extends NewTypeWizardPage {
updateStatus(Status.OK_STATUS);
}
}
-
+
@Override
@SuppressWarnings({ "unchecked", "rawtypes" })
protected IStatus superInterfacesChanged() {
- IStatus ret = super.superInterfacesChanged();
- if ( ret.isOK() ) {
- List interfaces = getSuperInterfaces();
- if(defaultsTable!=null)
- defaultsTable.setImplements(interfaces);
+ IStatus status = super.superInterfacesChanged();
+ if(status.isOK()) {
+ List<String> interfaces = this.getSuperInterfaces();
+ if(this.defaultsTable != null) {
+ this.defaultsTable.setImplements(interfaces);
+ }
+ if(this.serializableInterfaceRemoved(interfaces)) {
+ this.removeAllSerializableFromTables(this.customizer.getTableNames());
+ }
}
- return ret;
- }
+ return status;
+ }
+
+ private void removeAllSerializableFromTables(List<String> tableNames) {
+ for(String tableName: tableNames) {
+ ORMGenTable table = this.customizer.getTable(tableName);
+ List<String> tableInterfaces = table.getImplements();
+ tableInterfaces.remove(SERIALIZABLE_INTERFACE);
+ table.setImplements(tableInterfaces);
+ }
+ }
+
+ private boolean serializableInterfaceRemoved(List<String> interfaces) {
+ return ( ! this.interfacesHasSerializable(interfaces)) && (this.customizer != null);
+ }
protected ORMGenCustomizer getCustomizer() {
GenerateEntitiesFromSchemaWizard wizard = (GenerateEntitiesFromSchemaWizard) this.getWizard();

Back to the top