Skip to main content
summaryrefslogtreecommitdiffstats
path: root/jpa
diff options
context:
space:
mode:
authorkmoore2007-05-10 15:47:12 +0000
committerkmoore2007-05-10 15:47:12 +0000
commitedddd4c7a6b977384dca23d886de1a7120988218 (patch)
treed3457d6322d3a8cd8bc565f80586da83aedb936e /jpa
parent6f69a1d6c41a6e1d417fae60452adf4f894c7050 (diff)
downloadwebtools.dali-edddd4c7a6b977384dca23d886de1a7120988218.tar.gz
webtools.dali-edddd4c7a6b977384dca23d886de1a7120988218.tar.xz
webtools.dali-edddd4c7a6b977384dca23d886de1a7120988218.zip
184886 - fixed NPE, have to cache the connectionProfile to remove the listener. Also null it out when populate(null) so we don't even up with a stale connectionProfile
Diffstat (limited to 'jpa')
-rw-r--r--jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/CatalogCombo.java240
-rw-r--r--jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/ColumnComposite.java8
-rw-r--r--jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/InheritanceComposite.java4
-rw-r--r--jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/JoinTableComposite.java1
-rw-r--r--jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/SchemaCombo.java234
-rw-r--r--jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/TableCombo.java108
-rw-r--r--jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/TableGeneratorComposite.java1
7 files changed, 311 insertions, 285 deletions
diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/CatalogCombo.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/CatalogCombo.java
index 91430694c8..c51d015c88 100644
--- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/CatalogCombo.java
+++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/CatalogCombo.java
@@ -1,16 +1,15 @@
/*******************************************************************************
-* Copyright (c) 2007 Oracle. 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:
-* Oracle - initial API and implementation
-*******************************************************************************/
+ * Copyright (c) 2007 Oracle. 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:
+ * Oracle - initial API and implementation
+ *******************************************************************************/
package org.eclipse.jpt.ui.internal.mappings.details;
import java.util.Iterator;
-
import org.eclipse.emf.common.command.CommandStack;
import org.eclipse.emf.common.notify.Adapter;
import org.eclipse.emf.common.notify.Notification;
@@ -41,36 +40,44 @@ import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetWidgetFactory;
public class CatalogCombo extends BaseJpaController
{
private ITable table;
+
private Adapter listener;
+
+ /**
+ * Caching the connectionProfile so we can remove the listener. If the
+ * cached table object has been removed from the model then we no longer
+ * have access to the parent and cannot find the connectionProfile
+ */
+ private ConnectionProfile connectionProfile;
+
private ConnectionListener connectionListener;
-
+
private CCombo combo;
-
- public CatalogCombo( Composite parent, CommandStack theCommandStack, TabbedPropertySheetWidgetFactory widgetFactory) {
+
+ public CatalogCombo(Composite parent, CommandStack theCommandStack, TabbedPropertySheetWidgetFactory widgetFactory) {
super(parent, theCommandStack, widgetFactory);
this.listener = this.buildTableListener();
this.connectionListener = this.buildConnectionListener();
}
-
+
private Adapter buildTableListener() {
return new AdapterImpl() {
- public void notifyChanged( Notification notification) {
- CatalogCombo.this.catalogChanged( notification);
+ public void notifyChanged(Notification notification) {
+ CatalogCombo.this.catalogChanged(notification);
}
};
}
- private ConnectionListener buildConnectionListener() {
+ private ConnectionListener buildConnectionListener() {
return new ConnectionListener() {
-
- public void aboutToClose( Connection connection) {
- // not interested to this event.
+ public void aboutToClose(Connection connection) {
+ // not interested to this event.
}
- public void closed( Connection connection) {
- getCombo().getDisplay().asyncExec( new Runnable() {
+ public void closed(Connection connection) {
+ getCombo().getDisplay().asyncExec(new Runnable() {
public void run() {
- if ( getControl().isDisposed()) {
+ if (getControl().isDisposed()) {
return;
}
CatalogCombo.this.populateCatalogCombo();
@@ -78,10 +85,10 @@ public class CatalogCombo extends BaseJpaController
});
}
- public void modified( Connection connection) {
- getCombo().getDisplay().asyncExec( new Runnable() {
+ public void modified(Connection connection) {
+ getCombo().getDisplay().asyncExec(new Runnable() {
public void run() {
- if ( getControl().isDisposed()) {
+ if (getControl().isDisposed()) {
return;
}
CatalogCombo.this.populateCatalogCombo();
@@ -89,15 +96,15 @@ public class CatalogCombo extends BaseJpaController
});
}
- public boolean okToClose( Connection connection) {
+ public boolean okToClose(Connection connection) {
// not interested to this event.
return true;
}
- public void opened( Connection connection) {
- getCombo().getDisplay().asyncExec( new Runnable() {
+ public void opened(Connection connection) {
+ getCombo().getDisplay().asyncExec(new Runnable() {
public void run() {
- if ( getControl().isDisposed()) {
+ if (getControl().isDisposed()) {
return;
}
CatalogCombo.this.populateCatalogCombo();
@@ -105,85 +112,77 @@ public class CatalogCombo extends BaseJpaController
});
}
- public void databaseChanged( Connection connection, final Database database) {
- getControl().getDisplay().asyncExec( new Runnable() {
+ public void databaseChanged(Connection connection, final Database database) {
+ getControl().getDisplay().asyncExec(new Runnable() {
public void run() {
- if( database == CatalogCombo.this.getDatabase()) {
- if ( !getControl().isDisposed()) {
+ if (database == CatalogCombo.this.getDatabase()) {
+ if (!getControl().isDisposed()) {
CatalogCombo.this.populateCatalogCombo();
}
}
}
});
}
-
- public void schemaChanged( Connection connection, final Schema schema) {
- // not interested to this event.
+
+ public void schemaChanged(Connection connection, final Schema schema) {
+ // not interested to this event.
}
- public void tableChanged( Connection connection, final Table table) {
- // not interested to this event.
+ public void tableChanged(Connection connection, final Table table) {
+ // not interested to this event.
}
};
- }
-
+ }
+
@Override
- protected void buildWidget( Composite parent) {
- this.combo = getWidgetFactory().createCCombo( parent, SWT.FLAT);
- this.combo.add( JptUiMappingsMessages.TableComposite_defaultEmpty);
-
- this.combo.addModifyListener( new ModifyListener() {
-
- public void modifyText( ModifyEvent e) {
- if ( isPopulating()) {
+ protected void buildWidget(Composite parent) {
+ this.combo = getWidgetFactory().createCCombo(parent, SWT.FLAT);
+ this.combo.add(JptUiMappingsMessages.TableComposite_defaultEmpty);
+ this.combo.addModifyListener(new ModifyListener() {
+ public void modifyText(ModifyEvent e) {
+ if (isPopulating()) {
return;
}
- String catalogText = (( CCombo) e.getSource()).getText();
- if ( catalogText.equals("")) { //$NON-NLS-1$
+ String catalogText = ((CCombo) e.getSource()).getText();
+ if (catalogText.equals("")) { //$NON-NLS-1$
catalogText = null;
- if ( CatalogCombo.this.table.getSpecifiedCatalog() == null
- || CatalogCombo.this.table.getSpecifiedCatalog().equals("")) { //$NON-NLS-1$
+ if (CatalogCombo.this.table.getSpecifiedCatalog() == null || CatalogCombo.this.table.getSpecifiedCatalog().equals("")) { //$NON-NLS-1$
return;
}
}
-
- if ( catalogText != null && combo.getItemCount() > 0 && catalogText.equals(combo.getItem(0))) {
+ if (catalogText != null && combo.getItemCount() > 0 && catalogText.equals(combo.getItem(0))) {
catalogText = null;
}
-
- if ( CatalogCombo.this.table.getSpecifiedCatalog() == null && catalogText != null) {
- CatalogCombo.this.setSpecifiedCatalog( catalogText);
+ if (CatalogCombo.this.table.getSpecifiedCatalog() == null && catalogText != null) {
+ CatalogCombo.this.setSpecifiedCatalog(catalogText);
}
-
- if ( CatalogCombo.this.table.getSpecifiedCatalog() != null
- && ! CatalogCombo.this.table.getSpecifiedCatalog().equals( catalogText)) {
- CatalogCombo.this.setSpecifiedCatalog( catalogText);
+ if (CatalogCombo.this.table.getSpecifiedCatalog() != null && !CatalogCombo.this.table.getSpecifiedCatalog().equals(catalogText)) {
+ CatalogCombo.this.setSpecifiedCatalog(catalogText);
}
}
});
}
-
- private void setSpecifiedCatalog( String catalogName) {
- this.table.setSpecifiedCatalog( catalogName);
- this.getConnectionProfile().setCatalogName( catalogName);
+
+ private void setSpecifiedCatalog(String catalogName) {
+ this.table.setSpecifiedCatalog(catalogName);
+ this.getConnectionProfile().setCatalogName(catalogName);
}
-
- protected void catalogChanged( Notification notification) {
-
- if ( notification.getFeatureID( ITable.class) == JpaCoreMappingsPackage.ITABLE__SPECIFIED_CATALOG) {
- Display.getDefault().asyncExec( new Runnable() {
+
+ protected void catalogChanged(Notification notification) {
+ if (notification.getFeatureID(ITable.class) == JpaCoreMappingsPackage.ITABLE__SPECIFIED_CATALOG) {
+ Display.getDefault().asyncExec(new Runnable() {
public void run() {
- if ( getControl().isDisposed()) {
+ if (getControl().isDisposed()) {
return;
}
CatalogCombo.this.populateCatalogName();
}
});
}
- else if ( notification.getFeatureID( ITable.class) == JpaCoreMappingsPackage.ITABLE__DEFAULT_CATALOG) {
- Display.getDefault().asyncExec( new Runnable() {
+ else if (notification.getFeatureID(ITable.class) == JpaCoreMappingsPackage.ITABLE__DEFAULT_CATALOG) {
+ Display.getDefault().asyncExec(new Runnable() {
public void run() {
- if ( getControl().isDisposed()) {
+ if (getControl().isDisposed()) {
return;
}
CatalogCombo.this.populateDefaultCatalogName();
@@ -191,12 +190,17 @@ public class CatalogCombo extends BaseJpaController
});
}
}
-
- public void doPopulate( EObject obj) {
- this.table = ( ITable) obj;
- this.populateCatalogCombo();
+
+ public void doPopulate(EObject obj) {
+ this.table = (ITable) obj;
+ if (this.table != null) {
+ this.populateCatalogCombo();
+ }
+ else {
+ this.connectionProfile = null;
+ }
}
-
+
public void doPopulate() {
this.populateCatalogCombo();
}
@@ -204,60 +208,63 @@ public class CatalogCombo extends BaseJpaController
protected Database getDatabase() {
return this.getConnectionProfile().getDatabase();
}
-
+
private ConnectionProfile getConnectionProfile() {
- return ( this.table != null) ? this.table.getJpaProject().connectionProfile() : null;
+ if (this.connectionProfile == null) {
+ this.connectionProfile = this.table.getJpaProject().connectionProfile();
+ }
+ return this.connectionProfile;
}
-
+
private void populateCatalogCombo() {
- if( this.table == null) {
+ if (this.table == null) {
return;
}
this.populateDefaultCatalogName();
-
- if ( this.getConnectionProfile().isConnected()) {
- this.combo.remove( 1, this.combo.getItemCount() - 1);
+ if (this.getConnectionProfile().isConnected()) {
+ this.combo.remove(1, this.combo.getItemCount() - 1);
Database database = this.getDatabase();
-
- if ( database != null) {
+ if (database != null) {
Iterator<String> catalogs = database.catalogNames();
- for ( Iterator<String> stream = CollectionTools.sort(catalogs); stream.hasNext(); ) {
+ for (Iterator<String> stream = CollectionTools.sort(catalogs); stream.hasNext();) {
this.combo.add(stream.next());
}
}
}
else {
- this.combo.remove( 1, this.combo.getItemCount() - 1);
+ this.combo.remove(1, this.combo.getItemCount() - 1);
}
this.populateCatalogName();
}
-
+
protected void populateDefaultCatalogName() {
-// String defaultCatalogName = this.table.getDefaultCatalog(); // DefaultCatalog cannot be initialized if DB not online
- String defaultCatalogName = this.getDatabase().getDefaultCatalogName(); // TOREVIEW
+ // String defaultCatalogName = this.table.getDefaultCatalog(); //
+ // DefaultCatalog cannot be initialized if DB not online
+ String defaultCatalogName = this.getDatabase().getDefaultCatalogName(); // TOREVIEW
int selectionIndex = combo.getSelectionIndex();
- combo.setItem( 0, NLS.bind( JptUiMappingsMessages.TableComposite_defaultWithOneParam, defaultCatalogName));
- if ( selectionIndex == 0) {
+ combo.setItem(0, NLS.bind(JptUiMappingsMessages.TableComposite_defaultWithOneParam, defaultCatalogName));
+ if (selectionIndex == 0) {
combo.clearSelection();
- combo.select( 0);
- }
+ combo.select(0);
+ }
}
-
+
protected void populateCatalogName() {
- if ( this.table == null) {
+ if (this.table == null) {
return;
}
String catalogName = this.table.getSpecifiedCatalog();
-// String defaultCatalogName = this.table.getDefaultCatalog(); // DefaultCatalog cannot be initialized if DB not online
- String defaultCatalogName = this.getDatabase().getDefaultCatalogName(); // TOREVIEW
- if ( ! StringTools.stringIsEmpty( catalogName)) {
- if ( !this.combo.getText().equals( catalogName)) {
- this.combo.setText( catalogName);
+ // String defaultCatalogName = this.table.getDefaultCatalog(); //
+ // DefaultCatalog cannot be initialized if DB not online
+ String defaultCatalogName = this.getDatabase().getDefaultCatalogName(); // TOREVIEW
+ if (!StringTools.stringIsEmpty(catalogName)) {
+ if (!this.combo.getText().equals(catalogName)) {
+ this.combo.setText(catalogName);
}
}
else {
- if ( ! this.combo.getText().equals( NLS.bind( JptUiMappingsMessages.TableComposite_defaultWithOneParam, defaultCatalogName))) {
- this.combo.select( 0);
+ if (!this.combo.getText().equals(NLS.bind(JptUiMappingsMessages.TableComposite_defaultWithOneParam, defaultCatalogName))) {
+ this.combo.select(0);
}
}
}
@@ -265,34 +272,33 @@ public class CatalogCombo extends BaseJpaController
public CCombo getCombo() {
return this.combo;
}
-
+
@Override
public Control getControl() {
return getCombo();
}
-
+
@Override
protected void disengageListeners() {
if (this.table != null) {
this.removeConnectionListener();
- this.table.eAdapters().remove( this.listener);
+ this.table.eAdapters().remove(this.listener);
}
}
-
+
@Override
protected void engageListeners() {
if (this.table != null) {
- this.table.eAdapters().add( this.listener);
+ this.table.eAdapters().add(this.listener);
this.addConnectionListener();
- }
+ }
}
-
+
private void addConnectionListener() {
- this.getConnectionProfile().addConnectionListener( this.connectionListener);
+ this.getConnectionProfile().addConnectionListener(this.connectionListener);
}
-
+
private void removeConnectionListener() {
- this.getConnectionProfile().removeConnectionListener( this.connectionListener);
+ this.getConnectionProfile().removeConnectionListener(this.connectionListener);
}
-
}
diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/ColumnComposite.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/ColumnComposite.java
index 91a6f5f3cb..ea3f8a805c 100644
--- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/ColumnComposite.java
+++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/ColumnComposite.java
@@ -335,9 +335,8 @@ public class ColumnComposite extends BaseJpaComposite
}
private ConnectionProfile getConnectionProfile() {
- if(this.connectionProfile == null) {
- IJpaProject jpaProject = this.column.getJpaProject();
- this.connectionProfile = jpaProject.connectionProfile();
+ if (this.connectionProfile == null) {
+ this.connectionProfile = this.column.getJpaProject().connectionProfile();
}
return this.connectionProfile;
}
@@ -457,6 +456,9 @@ public class ColumnComposite extends BaseJpaComposite
populateColumnCombo();
populateTableCombo();
}
+ else {
+ this.connectionProfile = null;
+ }
this.insertableComboViewer.populate();
this.updatableComboViewer.populate();
}
diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/InheritanceComposite.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/InheritanceComposite.java
index 0b57a6a621..5b032402da 100644
--- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/InheritanceComposite.java
+++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/InheritanceComposite.java
@@ -330,6 +330,7 @@ public class InheritanceComposite extends BaseJpaComposite {
}
else {
this.discriminatorColumn = null;
+ this.connectionProfile = null;
}
}
@@ -361,8 +362,7 @@ public class InheritanceComposite extends BaseJpaComposite {
private ConnectionProfile getConnectionProfile() {
if(this.connectionProfile == null) {
- IJpaProject jpaProject = this.entity.getJpaProject();
- this.connectionProfile = jpaProject.connectionProfile();
+ this.connectionProfile = this.entity.getJpaProject().connectionProfile();
}
return this.connectionProfile;
}
diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/JoinTableComposite.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/JoinTableComposite.java
index 2cbd1f02ac..f5fd60c608 100644
--- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/JoinTableComposite.java
+++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/JoinTableComposite.java
@@ -351,6 +351,7 @@ public class JoinTableComposite extends BaseJpaComposite
if (this.joinTable == null) {
this.joinColumnsComposite.populate(null);
this.inverseJoinColumnsComposite.populate(null);
+ this.connectionProfile = null;
return;
}
diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/SchemaCombo.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/SchemaCombo.java
index 67e079c92a..9655c2202a 100644
--- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/SchemaCombo.java
+++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/SchemaCombo.java
@@ -1,16 +1,15 @@
/*******************************************************************************
-* Copyright (c) 2007 Oracle. 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:
-* Oracle - initial API and implementation
-*******************************************************************************/
+ * Copyright (c) 2007 Oracle. 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:
+ * Oracle - initial API and implementation
+ *******************************************************************************/
package org.eclipse.jpt.ui.internal.mappings.details;
import java.util.Iterator;
-
import org.eclipse.emf.common.command.CommandStack;
import org.eclipse.emf.common.notify.Adapter;
import org.eclipse.emf.common.notify.Notification;
@@ -41,36 +40,44 @@ import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetWidgetFactory;
public class SchemaCombo extends BaseJpaController
{
private ITable table;
+
private Adapter listener;
+
+ /**
+ * Caching the connectionProfile so we can remove the listener. If the
+ * cached table object has been removed from the model then we no longer
+ * have access to the parent and cannot find the connectionProfile
+ */
+ private ConnectionProfile connectionProfile;
+
private ConnectionListener connectionListener;
-
+
private CCombo combo;
-
- public SchemaCombo( Composite parent, CommandStack theCommandStack, TabbedPropertySheetWidgetFactory widgetFactory) {
+
+ public SchemaCombo(Composite parent, CommandStack theCommandStack, TabbedPropertySheetWidgetFactory widgetFactory) {
super(parent, theCommandStack, widgetFactory);
this.listener = this.buildTableListener();
this.connectionListener = this.buildConnectionListener();
}
-
+
private Adapter buildTableListener() {
return new AdapterImpl() {
- public void notifyChanged( Notification notification) {
- SchemaCombo.this.schemaChanged( notification);
+ public void notifyChanged(Notification notification) {
+ SchemaCombo.this.schemaChanged(notification);
}
};
}
- private ConnectionListener buildConnectionListener() {
+ private ConnectionListener buildConnectionListener() {
return new ConnectionListener() {
-
- public void aboutToClose( Connection connection) {
- // not interested to this event.
+ public void aboutToClose(Connection connection) {
+ // not interested to this event.
}
- public void closed( Connection connection) {
- getCombo().getDisplay().asyncExec( new Runnable() {
+ public void closed(Connection connection) {
+ getCombo().getDisplay().asyncExec(new Runnable() {
public void run() {
- if ( getControl().isDisposed()) {
+ if (getControl().isDisposed()) {
return;
}
SchemaCombo.this.populateShemaCombo();
@@ -78,10 +85,10 @@ public class SchemaCombo extends BaseJpaController
});
}
- public void modified( Connection connection) {
- getCombo().getDisplay().asyncExec( new Runnable() {
+ public void modified(Connection connection) {
+ getCombo().getDisplay().asyncExec(new Runnable() {
public void run() {
- if ( getControl().isDisposed()) {
+ if (getControl().isDisposed()) {
return;
}
SchemaCombo.this.populateShemaCombo();
@@ -89,15 +96,15 @@ public class SchemaCombo extends BaseJpaController
});
}
- public boolean okToClose( Connection connection) {
+ public boolean okToClose(Connection connection) {
// not interested to this event.
return true;
}
- public void opened( Connection connection) {
- getCombo().getDisplay().asyncExec( new Runnable() {
+ public void opened(Connection connection) {
+ getCombo().getDisplay().asyncExec(new Runnable() {
public void run() {
- if ( getControl().isDisposed()) {
+ if (getControl().isDisposed()) {
return;
}
SchemaCombo.this.populateShemaCombo();
@@ -105,23 +112,23 @@ public class SchemaCombo extends BaseJpaController
});
}
- public void databaseChanged( Connection connection, final Database database) {
- getControl().getDisplay().asyncExec( new Runnable() {
+ public void databaseChanged(Connection connection, final Database database) {
+ getControl().getDisplay().asyncExec(new Runnable() {
public void run() {
- if( database == SchemaCombo.this.getDatabase()) {
- if ( !getControl().isDisposed()) {
+ if (database == SchemaCombo.this.getDatabase()) {
+ if (!getControl().isDisposed()) {
SchemaCombo.this.populateShemaCombo();
}
}
}
});
}
-
- public void schemaChanged( Connection connection, final Schema schema) {
- getControl().getDisplay().asyncExec( new Runnable() {
+
+ public void schemaChanged(Connection connection, final Schema schema) {
+ getControl().getDisplay().asyncExec(new Runnable() {
public void run() {
- if( schema == SchemaCombo.this.getTableSchema()) {
- if ( !getControl().isDisposed()) {
+ if (schema == SchemaCombo.this.getTableSchema()) {
+ if (!getControl().isDisposed()) {
SchemaCombo.this.populateShemaCombo();
}
}
@@ -130,71 +137,63 @@ public class SchemaCombo extends BaseJpaController
}
public void tableChanged(Connection connection, final Table table) {
- // not interested to this event.
+ // not interested to this event.
}
};
- }
-
+ }
+
@Override
- protected void buildWidget( Composite parent) {
- this.combo = getWidgetFactory().createCCombo( parent, SWT.FLAT);
- this.combo.add( JptUiMappingsMessages.TableComposite_defaultEmpty);
-
- this.combo.addModifyListener( new ModifyListener() {
-
- public void modifyText( ModifyEvent e) {
- if ( isPopulating()) {
+ protected void buildWidget(Composite parent) {
+ this.combo = getWidgetFactory().createCCombo(parent, SWT.FLAT);
+ this.combo.add(JptUiMappingsMessages.TableComposite_defaultEmpty);
+ this.combo.addModifyListener(new ModifyListener() {
+ public void modifyText(ModifyEvent e) {
+ if (isPopulating()) {
return;
}
- String schemaText = (( CCombo) e.getSource()).getText();
- if ( schemaText.equals("")) { //$NON-NLS-1$
+ String schemaText = ((CCombo) e.getSource()).getText();
+ if (schemaText.equals("")) { //$NON-NLS-1$
schemaText = null;
- if ( SchemaCombo.this.table.getSpecifiedSchema() == null
- || SchemaCombo.this.table.getSpecifiedSchema().equals("")) { //$NON-NLS-1$
+ if (SchemaCombo.this.table.getSpecifiedSchema() == null || SchemaCombo.this.table.getSpecifiedSchema().equals("")) { //$NON-NLS-1$
return;
}
}
-
- if ( schemaText != null && combo.getItemCount() > 0 && schemaText.equals(combo.getItem(0))) {
+ if (schemaText != null && combo.getItemCount() > 0 && schemaText.equals(combo.getItem(0))) {
schemaText = null;
}
-
- if ( SchemaCombo.this.table.getSpecifiedSchema() == null && schemaText != null) {
- SchemaCombo.this.table.setSpecifiedSchema( schemaText);
+ if (SchemaCombo.this.table.getSpecifiedSchema() == null && schemaText != null) {
+ SchemaCombo.this.table.setSpecifiedSchema(schemaText);
}
-
- if ( SchemaCombo.this.table.getSpecifiedSchema() != null
- && ! SchemaCombo.this.table.getSpecifiedSchema().equals( schemaText)) {
- SchemaCombo.this.table.setSpecifiedSchema( schemaText);
+ if (SchemaCombo.this.table.getSpecifiedSchema() != null && !SchemaCombo.this.table.getSpecifiedSchema().equals(schemaText)) {
+ SchemaCombo.this.table.setSpecifiedSchema(schemaText);
}
}
});
}
-
- protected void schemaChanged( Notification notification) {
-
- if ( notification.getFeatureID( ITable.class) == JpaCoreMappingsPackage.ITABLE__SPECIFIED_SCHEMA) {
- Display.getDefault().asyncExec( new Runnable() {
+
+ protected void schemaChanged(Notification notification) {
+ if (notification.getFeatureID(ITable.class) == JpaCoreMappingsPackage.ITABLE__SPECIFIED_SCHEMA) {
+ Display.getDefault().asyncExec(new Runnable() {
public void run() {
- if ( getControl().isDisposed()) {
+ if (getControl().isDisposed()) {
return;
}
SchemaCombo.this.populateSchemaName();
}
});
}
- else if ( notification.getFeatureID( ITable.class) == JpaCoreMappingsPackage.ITABLE__DEFAULT_SCHEMA) {
- Display.getDefault().asyncExec( new Runnable() {
+ else if (notification.getFeatureID(ITable.class) == JpaCoreMappingsPackage.ITABLE__DEFAULT_SCHEMA) {
+ Display.getDefault().asyncExec(new Runnable() {
public void run() {
- if ( getControl().isDisposed()) {
+ if (getControl().isDisposed()) {
return;
}
SchemaCombo.this.populateDefaultSchemaName();
}
});
}
- else if ( notification.getFeatureID( ITable.class) == JpaCoreMappingsPackage.ITABLE__DEFAULT_CATALOG) {
- Display.getDefault().asyncExec( new Runnable() {
+ else if (notification.getFeatureID(ITable.class) == JpaCoreMappingsPackage.ITABLE__DEFAULT_CATALOG) {
+ Display.getDefault().asyncExec(new Runnable() {
public void run() {
if (getControl().isDisposed()) {
return;
@@ -203,8 +202,8 @@ public class SchemaCombo extends BaseJpaController
}
});
}
- else if ( notification.getFeatureID(ITable.class) == JpaCoreMappingsPackage.ITABLE__SPECIFIED_CATALOG) {
- Display.getDefault().asyncExec( new Runnable() {
+ else if (notification.getFeatureID(ITable.class) == JpaCoreMappingsPackage.ITABLE__SPECIFIED_CATALOG) {
+ Display.getDefault().asyncExec(new Runnable() {
public void run() {
if (getControl().isDisposed()) {
return;
@@ -214,12 +213,17 @@ public class SchemaCombo extends BaseJpaController
});
}
}
-
- public void doPopulate( EObject obj) {
- this.table = ( ITable) obj;
- this.populateShemaCombo();
+
+ public void doPopulate(EObject obj) {
+ this.table = (ITable) obj;
+ if (this.table != null) {
+ this.populateShemaCombo();
+ }
+ else {
+ this.connectionProfile = null;
+ }
}
-
+
public void doPopulate() {
this.populateShemaCombo();
}
@@ -227,58 +231,59 @@ public class SchemaCombo extends BaseJpaController
protected Database getDatabase() {
return this.getConnectionProfile().getDatabase();
}
-
+
private ConnectionProfile getConnectionProfile() {
- return ( this.table != null) ? this.table.getJpaProject().connectionProfile() : null;
+ if (this.connectionProfile == null) {
+ this.connectionProfile = this.table.getJpaProject().connectionProfile();
+ }
+ return this.connectionProfile;
}
-
+
private void populateShemaCombo() {
- if( this.table == null) {
+ if (this.table == null) {
return;
}
this.populateDefaultSchemaName();
-
- if ( this.getConnectionProfile().isConnected()) {
- this.combo.remove( 1, this.combo.getItemCount() - 1);
+ if (this.getConnectionProfile().isConnected()) {
+ this.combo.remove(1, this.combo.getItemCount() - 1);
Database database = this.getDatabase();
-
- if ( database != null) {
+ if (database != null) {
Iterator<String> schemata = database.schemaNames();
- for ( Iterator<String> stream = CollectionTools.sort( schemata); stream.hasNext(); ) {
+ for (Iterator<String> stream = CollectionTools.sort(schemata); stream.hasNext();) {
this.combo.add(stream.next());
}
}
}
else {
- this.combo.remove( 1, this.combo.getItemCount() - 1);
+ this.combo.remove(1, this.combo.getItemCount() - 1);
}
this.populateSchemaName();
}
-
+
protected void populateDefaultSchemaName() {
String defaultSchemaName = this.table.getDefaultSchema();
int selectionIndex = combo.getSelectionIndex();
- combo.setItem( 0, NLS.bind( JptUiMappingsMessages.TableComposite_defaultWithOneParam, defaultSchemaName));
- if( selectionIndex == 0) {
+ combo.setItem(0, NLS.bind(JptUiMappingsMessages.TableComposite_defaultWithOneParam, defaultSchemaName));
+ if (selectionIndex == 0) {
combo.clearSelection();
- combo.select( 0);
- }
+ combo.select(0);
+ }
}
-
+
protected void populateSchemaName() {
- if( this.table == null) {
+ if (this.table == null) {
return;
}
String schemaName = this.table.getSpecifiedSchema();
String defaultSchemaName = this.table.getDefaultSchema();
- if ( ! StringTools.stringIsEmpty( schemaName)) {
- if ( !this.combo.getText().equals( schemaName)) {
- this.combo.setText( schemaName);
+ if (!StringTools.stringIsEmpty(schemaName)) {
+ if (!this.combo.getText().equals(schemaName)) {
+ this.combo.setText(schemaName);
}
}
else {
- if ( ! this.combo.getText().equals( NLS.bind( JptUiMappingsMessages.TableComposite_defaultWithOneParam, defaultSchemaName))) {
- this.combo.select( 0);
+ if (!this.combo.getText().equals(NLS.bind(JptUiMappingsMessages.TableComposite_defaultWithOneParam, defaultSchemaName))) {
+ this.combo.select(0);
}
}
}
@@ -286,38 +291,37 @@ public class SchemaCombo extends BaseJpaController
public CCombo getCombo() {
return this.combo;
}
-
+
@Override
public Control getControl() {
return getCombo();
}
protected Schema getTableSchema() {
- return this.getConnectionProfile().getDatabase().schemaNamed( table.getSchema());
+ return this.getConnectionProfile().getDatabase().schemaNamed(table.getSchema());
}
-
+
@Override
protected void disengageListeners() {
if (this.table != null) {
this.removeConnectionListener();
- this.table.eAdapters().remove( this.listener);
+ this.table.eAdapters().remove(this.listener);
}
}
-
+
@Override
protected void engageListeners() {
if (this.table != null) {
- this.table.eAdapters().add( this.listener);
+ this.table.eAdapters().add(this.listener);
this.addConnectionListener();
- }
+ }
}
-
+
private void addConnectionListener() {
- this.getConnectionProfile().addConnectionListener( this.connectionListener);
+ this.getConnectionProfile().addConnectionListener(this.connectionListener);
}
-
+
private void removeConnectionListener() {
- this.getConnectionProfile().removeConnectionListener( this.connectionListener);
+ this.getConnectionProfile().removeConnectionListener(this.connectionListener);
}
-
}
diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/TableCombo.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/TableCombo.java
index 89fae1b5f1..3304743c00 100644
--- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/TableCombo.java
+++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/TableCombo.java
@@ -9,7 +9,6 @@
package org.eclipse.jpt.ui.internal.mappings.details;
import java.util.Iterator;
-
import org.eclipse.emf.common.command.CommandStack;
import org.eclipse.emf.common.notify.Adapter;
import org.eclipse.emf.common.notify.Notification;
@@ -39,17 +38,26 @@ import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetWidgetFactory;
public class TableCombo extends BaseJpaController
{
private ITable table;
+
private Adapter listener;
+
+ /**
+ * Caching the connectionProfile so we can remove the listener. If the
+ * cached table object has been removed from the model then we no longer
+ * have access to parent and cannot find the connectionProfile
+ */
+ private ConnectionProfile connectionProfile;
+
private ConnectionListener connectionListener;
-
+
private CCombo combo;
-
+
public TableCombo(Composite parent, CommandStack theCommandStack, TabbedPropertySheetWidgetFactory widgetFactory) {
super(parent, theCommandStack, widgetFactory);
this.listener = buildTableListener();
this.connectionListener = buildConnectionListener();
}
-
+
private Adapter buildTableListener() {
return new AdapterImpl() {
public void notifyChanged(Notification notification) {
@@ -58,15 +66,14 @@ public class TableCombo extends BaseJpaController
};
}
- private ConnectionListener buildConnectionListener() {
+ private ConnectionListener buildConnectionListener() {
return new ConnectionListener() {
-
public void aboutToClose(Connection connection) {
- // not interested to this event.
+ // not interested to this event.
}
public void closed(Connection connection) {
- getCombo().getDisplay().asyncExec( new Runnable() {
+ getCombo().getDisplay().asyncExec(new Runnable() {
public void run() {
if (getControl().isDisposed()) {
return;
@@ -77,7 +84,7 @@ public class TableCombo extends BaseJpaController
}
public void modified(Connection connection) {
- getCombo().getDisplay().asyncExec( new Runnable() {
+ getCombo().getDisplay().asyncExec(new Runnable() {
public void run() {
if (getControl().isDisposed()) {
return;
@@ -93,7 +100,7 @@ public class TableCombo extends BaseJpaController
}
public void opened(Connection connection) {
- getCombo().getDisplay().asyncExec( new Runnable() {
+ getCombo().getDisplay().asyncExec(new Runnable() {
public void run() {
if (getControl().isDisposed()) {
return;
@@ -104,9 +111,9 @@ public class TableCombo extends BaseJpaController
}
public void databaseChanged(Connection connection, final Database database) {
- getControl().getDisplay().asyncExec( new Runnable() {
+ getControl().getDisplay().asyncExec(new Runnable() {
public void run() {
- if(database == TableCombo.this.getDatabase()) {
+ if (database == TableCombo.this.getDatabase()) {
if (!getControl().isDisposed()) {
TableCombo.this.populateTableCombo();
}
@@ -114,11 +121,11 @@ public class TableCombo extends BaseJpaController
}
});
}
-
+
public void schemaChanged(Connection connection, final Schema schema) {
- getControl().getDisplay().asyncExec( new Runnable() {
+ getControl().getDisplay().asyncExec(new Runnable() {
public void run() {
- if(schema == TableCombo.this.getTableSchema()) {
+ if (schema == TableCombo.this.getTableSchema()) {
if (!getControl().isDisposed()) {
TableCombo.this.populateTableCombo();
}
@@ -128,11 +135,11 @@ public class TableCombo extends BaseJpaController
}
public void tableChanged(Connection connection, final Table table) {
- // not interested to this event.
+ // not interested to this event.
}
};
- }
-
+ }
+
@Override
protected void buildWidget(Composite parent) {
this.combo = getWidgetFactory().createCCombo(parent, SWT.FLAT);
@@ -149,22 +156,19 @@ public class TableCombo extends BaseJpaController
return;
}
}
-
if (tableText != null && combo.getItemCount() > 0 && tableText.equals(combo.getItem(0))) {
tableText = null;
}
-
if (table.getSpecifiedName() == null && tableText != null) {
table.setSpecifiedName(tableText);
}
-
if (table.getSpecifiedName() != null && !table.getSpecifiedName().equals(tableText)) {
table.setSpecifiedName(tableText);
}
}
});
}
-
+
protected void tableChanged(Notification notification) {
if (notification.getFeatureID(ITable.class) == JpaCoreMappingsPackage.ITABLE__SPECIFIED_NAME) {
Display.getDefault().asyncExec(new Runnable() {
@@ -207,13 +211,17 @@ public class TableCombo extends BaseJpaController
});
}
}
+
public void doPopulate(EObject obj) {
this.table = (ITable) obj;
if (this.table != null) {
populateTableCombo();
}
+ else {
+ this.connectionProfile = null;
+ }
}
-
+
public void doPopulate() {
if (this.table != null) {
populateTableCombo();
@@ -221,42 +229,45 @@ public class TableCombo extends BaseJpaController
}
protected Database getDatabase() {
- return this.getConnectionProfile().getDatabase();
+ return getConnectionProfile().getDatabase();
}
protected Schema getTableSchema() {
- return this.getConnectionProfile().getDatabase().schemaNamed(table.getSchema());
+ return getConnectionProfile().getDatabase().schemaNamed(table.getSchema());
}
-
+
private ConnectionProfile getConnectionProfile() {
- return this.table.getJpaProject().connectionProfile();
+ if (this.connectionProfile == null) {
+ this.connectionProfile = this.table.getJpaProject().connectionProfile();
+ }
+ return this.connectionProfile;
}
-
+
private void populateTableCombo() {
if (this.table == null) {
return;
}
- //TODO don't do instanceof check here - check on Table, or isRoot check on Entity
- //this.tableCombo.setEnabled(!(this.table instanceof SingleTableInheritanceChildTableImpl));
+ // TODO don't do instanceof check here - check on Table, or isRoot check
+ // on Entity
+ // this.tableCombo.setEnabled(!(this.table instanceof
+ // SingleTableInheritanceChildTableImpl));
populateDefaultTableName();
-
- if (this.getConnectionProfile().isConnected()) {
- this.combo.remove(1, this.combo.getItemCount()-1);
+ if (getConnectionProfile().isConnected()) {
+ this.combo.remove(1, this.combo.getItemCount() - 1);
Schema schema = this.getTableSchema();
if (schema != null) {
Iterator<String> tables = schema.tableNames();
- for (Iterator<String> stream = CollectionTools.sort( tables); stream.hasNext(); ) {
+ for (Iterator<String> stream = CollectionTools.sort(tables); stream.hasNext();) {
this.combo.add(stream.next());
}
}
}
else {
- this.combo.remove(1, this.combo.getItemCount()-1);
+ this.combo.remove(1, this.combo.getItemCount() - 1);
}
-
populateTableName();
}
-
+
protected void populateDefaultTableName() {
if (this.table == null) {
return;
@@ -265,13 +276,15 @@ public class TableCombo extends BaseJpaController
int selectionIndex = combo.getSelectionIndex();
combo.setItem(0, NLS.bind(JptUiMappingsMessages.TableComposite_defaultWithOneParam, defaultTableName));
if (selectionIndex == 0) {
- //combo text does not update when switching between 2 mappings of the same type
- //that both have a default column name. clear the selection and then set it again
+ // combo text does not update when switching between 2 mappings of
+ // the same type
+ // that both have a default column name. clear the selection and
+ // then set it again
combo.clearSelection();
combo.select(0);
- }
+ }
}
-
+
protected void populateTableName() {
if (this.table == null) {
return;
@@ -293,12 +306,12 @@ public class TableCombo extends BaseJpaController
public CCombo getCombo() {
return this.combo;
}
-
+
@Override
public Control getControl() {
return getCombo();
}
-
+
@Override
protected void disengageListeners() {
if (this.table != null) {
@@ -306,21 +319,20 @@ public class TableCombo extends BaseJpaController
this.table.eAdapters().remove(this.listener);
}
}
-
+
@Override
protected void engageListeners() {
if (this.table != null) {
this.table.eAdapters().add(this.listener);
this.addConnectionListener();
- }
+ }
}
-
+
private void addConnectionListener() {
this.getConnectionProfile().addConnectionListener(this.connectionListener);
}
-
+
private void removeConnectionListener() {
this.getConnectionProfile().removeConnectionListener(this.connectionListener);
}
-
}
diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/TableGeneratorComposite.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/TableGeneratorComposite.java
index 5c19fe695f..5a61503574 100644
--- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/TableGeneratorComposite.java
+++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/TableGeneratorComposite.java
@@ -294,6 +294,7 @@ public class TableGeneratorComposite extends GeneratorComposite<ITableGenerator>
protected void doPopulate(EObject obj) {
super.doPopulate(obj);
if (obj == null) {
+ this.connectionProfile = null;
return;
}
populateTableNameCombo();

Back to the top