Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 137063 Details for
Bug 267343
Cannot override default schema for PostgreSQL
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
candidate patch
267343.txt (text/plain), 84.84 KB, created by
Brian Vosburgh
on 2009-05-25 15:27:57 EDT
(
hide
)
Description:
candidate patch
Filename:
MIME Type:
Creator:
Brian Vosburgh
Created:
2009-05-25 15:27:57 EDT
Size:
84.84 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.jpt.ui >Index: src/org/eclipse/jpt/ui/internal/properties/JpaProjectPropertiesPage.java >=================================================================== >RCS file: /cvsroot/webtools/org.eclipse.jpa/components/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/properties/JpaProjectPropertiesPage.java,v >retrieving revision 1.30 >diff -u -r1.30 JpaProjectPropertiesPage.java >--- src/org/eclipse/jpt/ui/internal/properties/JpaProjectPropertiesPage.java 21 May 2009 14:44:28 -0000 1.30 >+++ src/org/eclipse/jpt/ui/internal/properties/JpaProjectPropertiesPage.java 25 May 2009 19:27:10 -0000 >@@ -46,10 +46,12 @@ > import org.eclipse.jpt.db.ConnectionAdapter; > import org.eclipse.jpt.db.ConnectionListener; > import org.eclipse.jpt.db.ConnectionProfile; >+import org.eclipse.jpt.db.ConnectionProfileFactory; > import org.eclipse.jpt.db.ConnectionProfileListener; > import org.eclipse.jpt.db.Database; > import org.eclipse.jpt.db.JptDbPlugin; > import org.eclipse.jpt.db.Schema; >+import org.eclipse.jpt.db.SchemaContainer; > import org.eclipse.jpt.db.ui.internal.DTPUiTools; > import org.eclipse.jpt.ui.internal.JpaHelpContextIds; > import org.eclipse.jpt.ui.internal.JptUiMessages; >@@ -110,47 +112,51 @@ > { > public static final String PROP_ID = "org.eclipse.jpt.ui.jpaProjectPropertiesPage"; //$NON-NLS-1$ > >- private WritablePropertyValueModel<IProject> projectHolder; >+ WritablePropertyValueModel<IProject> projectHolder; > >- private PropertyValueModel<JpaProject> jpaProjectHolder; >+ PropertyValueModel<JpaProject> jpaProjectHolder; > >- private Trigger trigger; >+ Trigger trigger; > >- private PropertyChangeListener validationListener; >+ PropertyChangeListener validationListener; > >- private PropertyChangeListener overrideDefaultCatalogListener; >+ PropertyChangeListener overrideDefaultCatalogListener; > >- private PropertyChangeListener overrideDefaultSchemaListener; >+ PropertyChangeListener overrideDefaultSchemaListener; > >- private PropertyChangeListener platformChangelistener; >+ PropertyChangeListener platformChangelistener; > >- private BufferedWritablePropertyValueModel<String> platformIdModel; >+ BufferedWritablePropertyValueModel<String> platformIdModel; > >- private BufferedWritablePropertyValueModel<String> connectionModel; >+ BufferedWritablePropertyValueModel<String> connectionModel; > >- private ListValueModel<String> connectionChoicesModel; >+ ListValueModel<String> connectionChoicesModel; > >- private PropertyValueModel<ConnectionProfile> connectionProfileModel; >+ PropertyValueModel<ConnectionProfile> connectionProfileModel; > >- private BufferedWritablePropertyValueModel<Boolean> overrideDefaultCatalogModel; >+ PropertyValueModel<Boolean> databaseSupportsCatalogsModel; > >- private BufferedWritablePropertyValueModel<String> defaultCatalogModel; >+ PropertyValueModel<Boolean> databaseExistsModel; > >- private WritablePropertyValueModel<String> combinedDefaultCatalogModel; >+ BufferedWritablePropertyValueModel<Boolean> overrideDefaultCatalogModel; > >- private ListValueModel<String> catalogChoicesModel; >+ BufferedWritablePropertyValueModel<String> defaultCatalogModel; >+ >+ WritablePropertyValueModel<String> combinedDefaultCatalogModel; >+ >+ ListValueModel<String> catalogChoicesModel; > >- private BufferedWritablePropertyValueModel<Boolean> overrideDefaultSchemaModel; >+ BufferedWritablePropertyValueModel<Boolean> overrideDefaultSchemaModel; > >- private BufferedWritablePropertyValueModel<String> defaultSchemaModel; >+ BufferedWritablePropertyValueModel<String> defaultSchemaModel; > >- private WritablePropertyValueModel<String> combinedDefaultSchemaModel; >+ WritablePropertyValueModel<String> combinedDefaultSchemaModel; > >- private ListValueModel<String> schemaChoicesModel; >+ ListValueModel<String> schemaChoicesModel; > >- private BufferedWritablePropertyValueModel<Boolean> discoverAnnotatedClassesModel; >+ BufferedWritablePropertyValueModel<Boolean> discoverAnnotatedClassesModel; > >- private WritablePropertyValueModel<Boolean> listAnnotatedClassesModel; >+ WritablePropertyValueModel<Boolean> listAnnotatedClassesModel; > > > // ************ construction/initialization ************ >@@ -175,6 +181,9 @@ > this.connectionChoicesModel = this.initializeConnectionChoicesModel(); > this.connectionProfileModel = this.initializeConnectionProfileModel(); > >+ this.databaseSupportsCatalogsModel = this.initializeDatabaseSupportsCatalogsModel(); >+ this.databaseExistsModel = this.initializeDatabaseExistsModel(); >+ > this.overrideDefaultCatalogModel = this.initializeOverrideDefaultCatalogModel(); > this.defaultCatalogModel = this.initializeDefaultCatalogModel(); > this.combinedDefaultCatalogModel = this.initializeCombinedDefaultCatalogModel(); >@@ -256,10 +265,9 @@ > } > > protected ListValueModel<String> initializeConnectionChoicesModel() { >- return new ExtendedListValueModelWrapper( >- (String) null, >- new SortedListValueModelAdapter( >- new CollectionListValueModelAdapter( >+ return new ExtendedListValueModelWrapper<String>( >+ new SortedListValueModelAdapter<String>( >+ new CollectionListValueModelAdapter<String>( > new ConnectionChoicesModel(this.projectHolder)))); > } > >@@ -271,15 +279,23 @@ > } > }; > } >+ >+ protected PropertyValueModel<Boolean> initializeDatabaseSupportsCatalogsModel() { >+ return new DatabaseSupportsCatalogsModel(this.connectionProfileModel); >+ } >+ >+ protected PropertyValueModel<Boolean> initializeDatabaseExistsModel() { >+ return new DatabaseExistsModel(this.connectionProfileModel); >+ } > > protected BufferedWritablePropertyValueModel<Boolean> initializeOverrideDefaultCatalogModel() { > OverrideDefaultCatalogModel model = new OverrideDefaultCatalogModel(this.jpaProjectHolder); >- BufferedWritablePropertyValueModel<Boolean> modelBuffer = >- new BufferedWritablePropertyValueModel(model, this.trigger); > model.addPropertyChangeListener(PropertyValueModel.VALUE, this.overrideDefaultCatalogListener); >- modelBuffer.addPropertyChangeListener(PropertyValueModel.VALUE, this.validationListener); >- return modelBuffer; >- >+ >+ BufferedWritablePropertyValueModel<Boolean> bufferedModel = new BufferedWritablePropertyValueModel<Boolean>(model, this.trigger); >+ bufferedModel.addPropertyChangeListener(PropertyValueModel.VALUE, this.validationListener); >+ >+ return bufferedModel; > } > > protected BufferedWritablePropertyValueModel<String> initializeDefaultCatalogModel() { >@@ -299,19 +315,15 @@ > } > > protected ListValueModel<String> initializeCatalogChoicesModel() { >- Collection<CollectionValueModel> cvms = new ArrayList<CollectionValueModel>(); >- cvms.add(new PropertyCollectionValueModelAdapter(this.defaultCatalogModel)); >+ Collection<CollectionValueModel<String>> cvms = new ArrayList<CollectionValueModel<String>>(); >+ cvms.add(new PropertyCollectionValueModelAdapter<String>(this.defaultCatalogModel)); > cvms.add(new CatalogChoicesModel(this.connectionProfileModel)); >- return new SortedListValueModelAdapter( >- new CompositeCollectionValueModel<CollectionValueModel, String>(cvms) { >+ return new SortedListValueModelAdapter<String>( >+ new CompositeCollectionValueModel<CollectionValueModel<String>, String>(cvms) { > @Override > public Iterator<String> iterator() { > Set<String> uniqueValues = new HashSet<String>(); >- for (String each : CollectionTools.iterable(super.iterator())) { >- if (each != null) { >- uniqueValues.add(each); >- } >- } >+ CollectionTools.addAll(uniqueValues, super.iterator()); > return uniqueValues.iterator(); > } > }); >@@ -338,25 +350,21 @@ > new CombinedDefaultSchemaModel( > this.defaultSchemaModel, > this.overrideDefaultSchemaModel, >- new DefaultDefaultSchemaModel(this.connectionProfileModel)); >+ new DefaultDefaultSchemaModel(this.defaultCatalogModel, this.connectionProfileModel)); > model.addPropertyChangeListener(PropertyValueModel.VALUE, this.validationListener); > return model; > } > > protected ListValueModel<String> initializeSchemaChoicesModel() { >- Collection<CollectionValueModel> cvms = new ArrayList<CollectionValueModel>(); >- cvms.add(new PropertyCollectionValueModelAdapter(this.defaultSchemaModel)); >- cvms.add(new SchemaChoicesModel(this.connectionProfileModel)); >- return new SortedListValueModelAdapter( >- new CompositeCollectionValueModel<CollectionValueModel, String>(cvms) { >+ Collection<CollectionValueModel<String>> cvms = new ArrayList<CollectionValueModel<String>>(); >+ cvms.add(new PropertyCollectionValueModelAdapter<String>(this.defaultSchemaModel)); >+ cvms.add(new SchemaChoicesModel(this.defaultCatalogModel, this.connectionProfileModel)); >+ return new SortedListValueModelAdapter<String>( >+ new CompositeCollectionValueModel<CollectionValueModel<String>, String>(cvms) { > @Override > public Iterator<String> iterator() { > Set<String> uniqueValues = new HashSet<String>(); >- for (String each : CollectionTools.iterable(super.iterator())) { >- if (each != null) { >- uniqueValues.add(each); >- } >- } >+ CollectionTools.addAll(uniqueValues, super.iterator()); > return uniqueValues.iterator(); > } > }); >@@ -676,7 +684,7 @@ > protected V value; > > >- protected BasePropertyAspectAdapter(PropertyValueModel<S> subjectHolder) { >+ BasePropertyAspectAdapter(PropertyValueModel<S> subjectHolder) { > super(subjectHolder); > this.value = null; > } >@@ -691,12 +699,12 @@ > > public final void setValue(V value) { > if (this.subject != null) { >- setValue_(value); >+ this.setValue_(value); > } > } > >- protected void setValue_(V value) { >- throw new UnsupportedOperationException("setValue"); >+ protected void setValue_(@SuppressWarnings("unused") V v) { >+ throw new UnsupportedOperationException(); > } > > >@@ -741,18 +749,15 @@ > // ************ internal *********************************************** > > protected V buildValue() { >- if (this.subject != null) { >- return buildValue_(); >- } >- return null; >+ return (this.subject == null) ? null : this.buildValue_(); > } > > protected abstract V buildValue_(); > > protected void valueChanged() { >- V oldValue = this.getValue(); >- this.value = buildValue(); >- this.fireAspectChange(oldValue, this.getValue()); >+ V old = this.getValue(); // subclasses override #getValue()... >+ this.value = this.buildValue(); >+ this.fireAspectChange(old, this.getValue()); > } > } > >@@ -761,7 +766,7 @@ > extends AspectAdapter<S> > implements CollectionValueModel<E> > { >- protected BaseCollectionAspectAdapter(PropertyValueModel<? extends S> subjectHolder) { >+ BaseCollectionAspectAdapter(PropertyValueModel<? extends S> subjectHolder) { > super(subjectHolder); > } > >@@ -831,7 +836,7 @@ > private IPreferenceChangeListener platformChangeListener; > > >- private JpaProjectHolder(PropertyValueModel<IProject> projectHolder) { >+ JpaProjectHolder(PropertyValueModel<IProject> projectHolder) { > super(projectHolder); > this.platformChangeListener = buildPlatformChangeListener(); > } >@@ -854,18 +859,19 @@ > > @Override > protected void engageSubject_() { >- IEclipsePreferences preferences = JptCorePlugin.getProjectPreferences(this.subject); >- preferences.addPreferenceChangeListener(this.platformChangeListener); > super.engageSubject_(); >+ this.getPreferences().addPreferenceChangeListener(this.platformChangeListener); > } > > @Override > protected void disengageSubject_() { >- IEclipsePreferences preferences = JptCorePlugin.getProjectPreferences(this.subject); >- preferences.removePreferenceChangeListener(this.platformChangeListener); >+ this.getPreferences().removePreferenceChangeListener(this.platformChangeListener); > super.disengageSubject_(); > } >- >+ >+ protected IEclipsePreferences getPreferences() { >+ return JptCorePlugin.getProjectPreferences(this.subject); >+ } > > // ************ internal *********************************************** > >@@ -879,7 +885,7 @@ > private static class PlatformIdModel > extends BasePropertyAspectAdapter<JpaProject, String> > { >- private PlatformIdModel(PropertyValueModel<JpaProject> jpaProjectHolder) { >+ PlatformIdModel(PropertyValueModel<JpaProject> jpaProjectHolder) { > super(jpaProjectHolder); > } > >@@ -903,7 +909,7 @@ > > private final class PlatformGroup > { >- private PlatformGroup(Composite composite) { >+ PlatformGroup(Composite composite) { > Group group = new Group(composite, SWT.NONE); > group.setText(JptUiMessages.JpaFacetWizardPage_platformLabel); > group.setLayout(new GridLayout()); >@@ -947,7 +953,7 @@ > private PropertyChangeListener connectionChangeListener; > > >- private ConnectionModel(PropertyValueModel<JpaProject> jpaProjectHolder) { >+ ConnectionModel(PropertyValueModel<JpaProject> jpaProjectHolder) { > super(jpaProjectHolder); > this.connectionChangeListener = buildConnectionChangeListener(); > } >@@ -976,15 +982,13 @@ > > @Override > protected void engageSubject_() { >- JpaDataSource dataSource = this.subject.getDataSource(); >- dataSource.addPropertyChangeListener(JpaDataSource.CONNECTION_PROFILE_NAME_PROPERTY, this.connectionChangeListener); > super.engageSubject_(); >+ this.subject.getDataSource().addPropertyChangeListener(JpaDataSource.CONNECTION_PROFILE_NAME_PROPERTY, this.connectionChangeListener); > } > > @Override > protected void disengageSubject_() { >- JpaDataSource dataSource = this.subject.getDataSource(); >- dataSource.removePropertyChangeListener(JpaDataSource.CONNECTION_PROFILE_NAME_PROPERTY, this.connectionChangeListener); >+ this.subject.getDataSource().removePropertyChangeListener(JpaDataSource.CONNECTION_PROFILE_NAME_PROPERTY, this.connectionChangeListener); > super.disengageSubject_(); > } > >@@ -1004,7 +1008,7 @@ > private ConnectionProfileListener connectionProfileListener; > > >- private ConnectionChoicesModel(PropertyValueModel<IProject> subjectHolder) { >+ ConnectionChoicesModel(PropertyValueModel<IProject> subjectHolder) { > super(subjectHolder); > this.connectionProfileListener = buildConnectionProfileListener(); > } >@@ -1037,14 +1041,12 @@ > > @Override > protected void engageSubject_() { >- JptDbPlugin.instance().getConnectionProfileFactory(). >- addConnectionProfileListener(this.connectionProfileListener); >+ this.getConnectionProfileFactory().addConnectionProfileListener(this.connectionProfileListener); > } > > @Override > protected void disengageSubject_() { >- JptDbPlugin.instance().getConnectionProfileFactory(). >- removeConnectionProfileListener(this.connectionProfileListener); >+ this.getConnectionProfileFactory().removeConnectionProfileListener(this.connectionProfileListener); > } > > >@@ -1052,20 +1054,23 @@ > > @Override > protected Iterator<String> iterator_() { >- return JptDbPlugin.instance().getConnectionProfileFactory().connectionProfileNames(); >+ return this.getConnectionProfileFactory().connectionProfileNames(); >+ } >+ >+ private ConnectionProfileFactory getConnectionProfileFactory() { >+ return JptDbPlugin.instance().getConnectionProfileFactory(); > } > } > > >- // ************ Catalog ************ >- private static class OverrideDefaultCatalogModel >- extends BasePropertyAspectAdapter<JpaProject, Boolean> >+ private abstract static class OverrideDefaultModel >+ extends BasePropertyAspectAdapter<JpaProject, Boolean> > { > // the superclass "value" is the *cached* value > private Boolean actualValue; >- >- >- private OverrideDefaultCatalogModel(PropertyValueModel<JpaProject> jpaProjectHolder) { >+ >+ >+ OverrideDefaultModel(PropertyValueModel<JpaProject> jpaProjectHolder) { > super(jpaProjectHolder); > } > >@@ -1074,14 +1079,14 @@ > > @Override > public Boolean getValue() { >- Boolean value = super.getValue(); >- return (value == null) ? Boolean.FALSE : value; >+ Boolean v = super.getValue(); >+ return (v == null) ? Boolean.FALSE : v; > } > > @Override > public void setValue_(Boolean newValue) { > this.actualValue = newValue; >- valueChanged(); >+ this.valueChanged(); > } > > >@@ -1089,14 +1094,16 @@ > > @Override > protected void engageSubject_() { >+ // we need to build 'actualValue' *before* calling 'super' >+ // because 'super' calls back here to #buildValue_() > this.actualValue = this.buildActualValue_(); > super.engageSubject_(); > } > > @Override > protected void disengageSubject_() { >- this.actualValue = null; > super.disengageSubject_(); >+ this.actualValue = null; > } > > >@@ -1108,7 +1115,28 @@ > } > > protected Boolean buildActualValue_() { >- return ! StringTools.stringIsEmpty(this.subject.getUserOverrideDefaultCatalog()); >+ return Boolean.valueOf(this.subjectHasUserOverrideDefault()); >+ } >+ >+ protected boolean subjectHasUserOverrideDefault() { >+ return ! StringTools.stringIsEmpty(this.getSubjectUserOverrideDefault()); >+ } >+ >+ protected abstract String getSubjectUserOverrideDefault(); >+ } >+ >+ >+ // ************ Catalog ************ >+ private static class OverrideDefaultCatalogModel >+ extends OverrideDefaultModel >+ { >+ OverrideDefaultCatalogModel(PropertyValueModel<JpaProject> jpaProjectHolder) { >+ super(jpaProjectHolder); >+ } >+ >+ @Override >+ protected String getSubjectUserOverrideDefault() { >+ return this.subject.getUserOverrideDefaultCatalog(); > } > } > >@@ -1116,7 +1144,7 @@ > private static class DefaultCatalogModel > extends PropertyAspectAdapter<JpaProject, String> > { >- private DefaultCatalogModel(PropertyValueModel<JpaProject> jpaProjectModel) { >+ DefaultCatalogModel(PropertyValueModel<JpaProject> jpaProjectModel) { > super(jpaProjectModel, JpaProject.USER_OVERRIDE_DEFAULT_CATALOG_PROPERTY); > } > >@@ -1136,57 +1164,89 @@ > return this.subject.getUserOverrideDefaultCatalog(); > } > } >- >- private static class DefaultDefaultCatalogModel >- extends BasePropertyAspectAdapter<ConnectionProfile, String> >+ >+ private abstract static class ConnectionProfilePropertyAspectAdapter<V> >+ extends BasePropertyAspectAdapter<ConnectionProfile, V> > { > private ConnectionListener connectionListener; >- >- >- private DefaultDefaultCatalogModel( >- PropertyValueModel<ConnectionProfile> connectionProfileModel) { >+ >+ ConnectionProfilePropertyAspectAdapter(PropertyValueModel<ConnectionProfile> connectionProfileModel) { > super(connectionProfileModel); >- this.connectionListener = buildConnectionListener(); >+ this.connectionListener = this.buildConnectionListener(); > } >- >- >- // ************ initialization ***************************************** >- >+ >+ // the connection opening is probably the only thing that will happen... > private ConnectionListener buildConnectionListener() { > return new ConnectionAdapter() { > @Override > public void opened(ConnectionProfile profile) { >- if (profile.equals(DefaultDefaultCatalogModel.this.subject)) { >- valueChanged(); >- } >- } >- @Override >- public void catalogChanged(ConnectionProfile profile, Catalog catalog) { >- if (profile.equals(DefaultDefaultCatalogModel.this.subject)) { >- valueChanged(); >- } >+ ConnectionProfilePropertyAspectAdapter.this.profileOpened(profile); > } > }; > } >- >- >- // ************ AspectAdapter impl ************************************* >- >+ >+ void profileOpened(ConnectionProfile profile) { >+ if (profile.equals(this.subject)) { >+ this.valueChanged(); >+ } >+ } >+ > @Override > protected void engageSubject_() { >- this.subject.addConnectionListener(this.connectionListener); > super.engageSubject_(); >+ this.subject.addConnectionListener(this.connectionListener); > } >- >+ > @Override > protected void disengageSubject_() { > this.subject.removeConnectionListener(this.connectionListener); > super.disengageSubject_(); > } >- >- >- // ************ internal *********************************************** >- >+ >+ } >+ >+ private static class DatabaseSupportsCatalogsModel >+ extends ConnectionProfilePropertyAspectAdapter<Boolean> >+ { >+ DatabaseSupportsCatalogsModel(PropertyValueModel<ConnectionProfile> connectionProfileModel) { >+ super(connectionProfileModel); >+ } >+ >+ @Override >+ protected Boolean buildValue_() { >+ return Boolean.valueOf(this.databaseSupportsCatalogs()); >+ } >+ >+ private boolean databaseSupportsCatalogs() { >+ Database db = this.subject.getDatabase(); >+ return (db != null) && db.supportsCatalogs(); >+ } >+ } >+ >+ private static class DatabaseExistsModel >+ extends ConnectionProfilePropertyAspectAdapter<Boolean> >+ { >+ DatabaseExistsModel(PropertyValueModel<ConnectionProfile> connectionProfileModel) { >+ super(connectionProfileModel); >+ } >+ >+ @Override >+ protected Boolean buildValue_() { >+ return Boolean.valueOf(this.databaseExists()); >+ } >+ >+ private boolean databaseExists() { >+ return (this.subject.getDatabase() != null); >+ } >+ } >+ >+ private static class DefaultDefaultCatalogModel >+ extends ConnectionProfilePropertyAspectAdapter<String> >+ { >+ DefaultDefaultCatalogModel(PropertyValueModel<ConnectionProfile> connectionProfileModel) { >+ super(connectionProfileModel); >+ } >+ > @Override > protected String buildValue_() { > Database db = this.subject.getDatabase(); >@@ -1209,13 +1269,13 @@ > private PropertyValueModel<String> defaultDefaultCatalogModel; > > >- private CombinedDefaultCatalogModel( >+ CombinedDefaultCatalogModel( > WritablePropertyValueModel<String> defaultCatalogModel, > PropertyValueModel<Boolean> overrideDefaultCatalogModel, > PropertyValueModel<String> defaultDefaultCatalogModel) { > super( >- new CompositeListValueModel( >- CollectionTools.list( >+ new CompositeListValueModel<ListValueModel<?>,Object>( >+ CollectionTools.<ListValueModel<?>>list( > new PropertyListValueModelAdapter<String>(defaultCatalogModel), > new PropertyListValueModelAdapter<Boolean>(overrideDefaultCatalogModel), > new PropertyListValueModelAdapter<String>(defaultDefaultCatalogModel) >@@ -1233,9 +1293,7 @@ > if (this.overrideDefaultCatalogModel.getValue()) { > return this.defaultCatalogModel.getValue(); > } >- else { >- return this.defaultDefaultCatalogModel.getValue(); >- } >+ return this.defaultDefaultCatalogModel.getValue(); > } > > >@@ -1250,114 +1308,72 @@ > } > > >- private static class CatalogChoicesModel >- extends BaseCollectionAspectAdapter<ConnectionProfile, String> >+ private static class ConnectionProfileCollectionAspectAdapter<E> >+ extends BaseCollectionAspectAdapter<ConnectionProfile, E> > { > private ConnectionListener connectionListener; >- >- >- private CatalogChoicesModel(PropertyValueModel<ConnectionProfile> subjectHolder) { >+ >+ ConnectionProfileCollectionAspectAdapter(PropertyValueModel<ConnectionProfile> subjectHolder) { > super(subjectHolder); >- this.connectionListener = buildConnectionListener(); >+ this.connectionListener = this.buildConnectionListener(); > } >- >- >- // ************ initialization ***************************************** >- >+ >+ // the connection opening is probably the only thing that will happen... > private ConnectionListener buildConnectionListener() { > return new ConnectionAdapter() { > @Override > public void opened(ConnectionProfile profile) { >- if (profile.equals(CatalogChoicesModel.this.subject)) { >- collectionChanged(); >- } >- } >- @Override >- public void catalogChanged(ConnectionProfile profile, Catalog catalog) { >- if (profile.equals(CatalogChoicesModel.this.subject)) { >- collectionChanged(); >- } >+ ConnectionProfileCollectionAspectAdapter.this.profileOpened(profile); > } > }; > } >- >- >- // ************ AspectAdapter impl ************************************* >- >+ >+ void profileOpened(ConnectionProfile profile) { >+ if (profile.equals(this.subject)) { >+ this.collectionChanged(); >+ } >+ } >+ > @Override > protected void engageSubject_() { > this.subject.addConnectionListener(this.connectionListener); > } >- >+ > @Override > protected void disengageSubject_() { > this.subject.removeConnectionListener(this.connectionListener); > } >- >- >- // ************ internal *********************************************** >- >+ >+ } >+ >+ private static class CatalogChoicesModel >+ extends ConnectionProfileCollectionAspectAdapter<String> >+ { >+ CatalogChoicesModel(PropertyValueModel<ConnectionProfile> subjectHolder) { >+ super(subjectHolder); >+ } >+ > @Override > protected Iterator<String> iterator_() { >- return (this.subject.getDatabase() == null) ? >+ Database db = this.subject.getDatabase(); >+ return ((db == null) || ( ! db.supportsCatalogs())) ? > EmptyIterator.<String>instance() : >- this.subject.getDatabase().sortedCatalogIdentifiers(); >+ db.sortedCatalogIdentifiers(); > } > } > > > // ************ Schema ************ > private static class OverrideDefaultSchemaModel >- extends BasePropertyAspectAdapter<JpaProject, Boolean> >+ extends OverrideDefaultModel > { >- // the superclass "value" is the *cached* value >- private Boolean actualValue; >- >- >- private OverrideDefaultSchemaModel(PropertyValueModel<JpaProject> jpaProjectHolder) { >+ OverrideDefaultSchemaModel(PropertyValueModel<JpaProject> jpaProjectHolder) { > super(jpaProjectHolder); > } >- >- >- // ************ WritablePropertyValueModel impl ************************ >- >- @Override >- public Boolean getValue() { >- Boolean value = super.getValue(); >- return (value == null) ? Boolean.FALSE : value; >- } >- >- @Override >- public void setValue_(Boolean newValue) { >- this.actualValue = newValue; >- valueChanged(); >- } >- >- >- // ************ AspectAdapter impl ************************************* >- >- @Override >- protected void engageSubject_() { >- this.actualValue = this.buildActualValue_(); >- super.engageSubject_(); >- } >- >- @Override >- protected void disengageSubject_() { >- this.actualValue = null; >- super.disengageSubject_(); >- } >- >- >- // ************ internal *********************************************** >- >+ > @Override >- protected Boolean buildValue_() { >- return this.actualValue; >- } >- >- protected Boolean buildActualValue_() { >- return ! StringTools.stringIsEmpty(this.subject.getUserOverrideDefaultSchema()); >+ public String getSubjectUserOverrideDefault() { >+ return this.subject.getUserOverrideDefaultSchema(); > } > } > >@@ -1365,7 +1381,7 @@ > private static class DefaultSchemaModel > extends PropertyAspectAdapter<JpaProject, String> > { >- private DefaultSchemaModel(PropertyValueModel<JpaProject> jpaProjectModel) { >+ DefaultSchemaModel(PropertyValueModel<JpaProject> jpaProjectModel) { > super(jpaProjectModel, JpaProject.USER_OVERRIDE_DEFAULT_SCHEMA_PROPERTY); > } > >@@ -1388,64 +1404,76 @@ > > > private static class DefaultDefaultSchemaModel >- extends BasePropertyAspectAdapter<ConnectionProfile, String> >+ extends ConnectionProfilePropertyAspectAdapter<String> > { >- private ConnectionListener connectionListener; >- >- >- private DefaultDefaultSchemaModel( >+ private final PropertyValueModel<String> defaultCatalogModel; >+ private final PropertyChangeListener catalogListener; >+ >+ DefaultDefaultSchemaModel(PropertyValueModel<String> defaultCatalogModel, > PropertyValueModel<ConnectionProfile> connectionProfileModel) { > super(connectionProfileModel); >- this.connectionListener = buildConnectionListener(); >+ this.defaultCatalogModel = defaultCatalogModel; >+ this.catalogListener = this.buildCatalogListener(); > } >- >- >- // ************ initialization ***************************************** >- >- private ConnectionListener buildConnectionListener() { >- return new ConnectionAdapter() { >- @Override >- public void opened(ConnectionProfile profile) { >- if (profile.equals(DefaultDefaultSchemaModel.this.subject)) { >- valueChanged(); >- } >- } >- @Override >- public void schemaChanged(ConnectionProfile profile, Schema schema) { >- if (profile.equals(DefaultDefaultSchemaModel.this.subject)) { >- valueChanged(); >- } >+ >+ private PropertyChangeListener buildCatalogListener() { >+ return new PropertyChangeListener() { >+ public void propertyChanged(PropertyChangeEvent event) { >+ DefaultDefaultSchemaModel.this.valueChanged(); > } > }; > } >- >- >- // ************ AspectAdapter impl ************************************* >- >+ > @Override > protected void engageSubject_() { >- this.subject.addConnectionListener(this.connectionListener); >+ // call 'super' last? >+ this.defaultCatalogModel.addPropertyChangeListener(PropertyValueModel.VALUE, this.catalogListener); > super.engageSubject_(); > } > > @Override > protected void disengageSubject_() { >- this.subject.removeConnectionListener(this.connectionListener); > super.disengageSubject_(); >+ this.defaultCatalogModel.removePropertyChangeListener(PropertyValueModel.VALUE, this.catalogListener); > } >- >- >- // ************ internal *********************************************** >- >+ > @Override > protected String buildValue_() { >- Database db = this.subject.getDatabase(); >- if (db == null) { >- return null; >- } >- Schema schema = db.getDefaultSchema(); >+ Schema schema = this.getDefaultSchema(); > return (schema == null) ? null : schema.getIdentifier(); > } >+ >+ private Schema getDefaultSchema() { >+ SchemaContainer sc = this.getSchemaContainer(); >+ return (sc == null) ? null : sc.getDefaultSchema(); >+ } >+ >+ private SchemaContainer getSchemaContainer() { >+ return this.databaseSupportsCatalogs() ? this.getCatalog() : this.getDatabase(); >+ } >+ >+ private boolean databaseSupportsCatalogs() { >+ Database db = this.getDatabase(); >+ return (db != null) && db.supportsCatalogs(); >+ } >+ >+ private Catalog getCatalog() { >+ String name = this.defaultCatalogModel.getValue(); >+ return (name == null) ? null : this.getCatalog(name); >+ } >+ >+ /** >+ * pre-condition: 'name' is not null >+ */ >+ private Catalog getCatalog(String name) { >+ Database db = this.getDatabase(); >+ return (db == null) ? null : db.getCatalogForIdentifier(name); >+ } >+ >+ private Database getDatabase() { >+ return this.subject.getDatabase(); >+ } >+ > } > > >@@ -1460,7 +1488,7 @@ > private PropertyValueModel<String> defaultDefaultSchemaModel; > > >- private CombinedDefaultSchemaModel( >+ CombinedDefaultSchemaModel( > WritablePropertyValueModel<String> defaultSchemaModel, > PropertyValueModel<Boolean> overrideDefaultSchemaModel, > PropertyValueModel<String> defaultDefaultSchemaModel) { >@@ -1484,9 +1512,7 @@ > if (this.overrideDefaultSchemaModel.getValue()) { > return this.defaultSchemaModel.getValue(); > } >- else { >- return this.defaultDefaultSchemaModel.getValue(); >- } >+ return this.defaultDefaultSchemaModel.getValue(); > } > > >@@ -1502,58 +1528,71 @@ > > > private static class SchemaChoicesModel >- extends BaseCollectionAspectAdapter<ConnectionProfile, String> >+ extends ConnectionProfileCollectionAspectAdapter<String> > { >- private ConnectionListener connectionListener; >- >- >- private SchemaChoicesModel(PropertyValueModel<ConnectionProfile> subjectHolder) { >+ private final PropertyValueModel<String> defaultCatalogModel; >+ private final PropertyChangeListener catalogListener; >+ >+ SchemaChoicesModel(PropertyValueModel<String> defaultCatalogModel, >+ PropertyValueModel<ConnectionProfile> subjectHolder) { > super(subjectHolder); >- this.connectionListener = buildConnectionListener(); >+ this.defaultCatalogModel = defaultCatalogModel; >+ this.catalogListener = this.buildCatalogListener(); > } >- >- >- // ************ initialization ***************************************** >- >- private ConnectionListener buildConnectionListener() { >- return new ConnectionAdapter() { >- @Override >- public void opened(ConnectionProfile profile) { >- if (profile.equals(SchemaChoicesModel.this.subject)) { >- collectionChanged(); >- } >- } >- @Override >- public void schemaChanged(ConnectionProfile profile, Schema schema) { >- if (profile.equals(SchemaChoicesModel.this.subject)) { >- collectionChanged(); >- } >+ >+ private PropertyChangeListener buildCatalogListener() { >+ return new PropertyChangeListener() { >+ public void propertyChanged(PropertyChangeEvent event) { >+ collectionChanged(); > } > }; > } >- >- >- // ************ AspectAdapter impl ************************************* >- >+ > @Override > protected void engageSubject_() { >- this.subject.addConnectionListener(this.connectionListener); >+ // call 'super' last? >+ this.defaultCatalogModel.addPropertyChangeListener(PropertyValueModel.VALUE, this.catalogListener); >+ super.engageSubject_(); > } >- >+ > @Override > protected void disengageSubject_() { >- this.subject.removeConnectionListener(this.connectionListener); >+ super.disengageSubject_(); >+ this.defaultCatalogModel.removePropertyChangeListener(PropertyValueModel.VALUE, this.catalogListener); > } >- >- >- // ************ internal *********************************************** >- >+ > @Override > protected Iterator<String> iterator_() { >- return (this.subject.getDatabase() == null) ? >- EmptyIterator.<String>instance() : >- this.subject.getDatabase().sortedSchemaIdentifiers(); >+ SchemaContainer sc = this.getSchemaContainer(); >+ return (sc == null) ? EmptyIterator.<String>instance() : sc.sortedSchemaIdentifiers(); >+ } >+ >+ private SchemaContainer getSchemaContainer() { >+ return this.databaseSupportsCatalogs() ? this.getCatalog() : this.getDatabase(); >+ } >+ >+ private boolean databaseSupportsCatalogs() { >+ Database db = this.getDatabase(); >+ return (db != null) && db.supportsCatalogs(); > } >+ >+ private Catalog getCatalog() { >+ String name = this.defaultCatalogModel.getValue(); >+ return (name == null) ? null : this.getCatalog(name); >+ } >+ >+ /** >+ * pre-condition: 'name' is not null >+ */ >+ private Catalog getCatalog(String name) { >+ Database db = this.getDatabase(); >+ return (db == null) ? null : db.getCatalogForIdentifier(name); >+ } >+ >+ private Database getDatabase() { >+ return this.subject.getDatabase(); >+ } >+ > } > > >@@ -1570,6 +1609,7 @@ > > PlatformUI.getWorkbench().getHelpSystem().setHelp(group, JpaHelpContextIds.PROPERTIES_JAVA_PERSISTENCE_CONNECTION); > >+ // connection > Combo connectionCombo = createCombo(group, 3, true); > > ComboModelAdapter.adapt( >@@ -1621,7 +1661,7 @@ > PropertyValueModel.VALUE, > linkUpdateListener); > >- // overrideDefaultCatalog >+ // override default catalog > Button overrideDefaultCatalogButton = createButton( > group, 3, > JptUiMessages.JpaFacetWizardPage_overrideDefaultCatalogLabel, >@@ -1648,7 +1688,7 @@ > JpaProjectPropertiesPage.this.overrideDefaultCatalogModel, > defaultCatalogLabel, defaultCatalogCombo); > >- // overrideDefaultSchema >+ // override default schema > Button overrideDefaultSchemaButton = createButton( > group, 3, > JptUiMessages.JpaFacetWizardPage_overrideDefaultSchemaLabel, >@@ -1703,7 +1743,7 @@ > private class DiscoverAnnotatedClassesModel > extends PropertyAspectAdapter<JpaProject, Boolean> > { >- private DiscoverAnnotatedClassesModel(PropertyValueModel<JpaProject> jpaProjectModel) { >+ DiscoverAnnotatedClassesModel(PropertyValueModel<JpaProject> jpaProjectModel) { > super(jpaProjectModel, JpaProject.DISCOVERS_ANNOTATED_CLASSES_PROPERTY); > } > >Index: src/org/eclipse/jpt/ui/internal/wizards/JpaFacetWizardPage.java >=================================================================== >RCS file: /cvsroot/webtools/org.eclipse.jpa/components/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/JpaFacetWizardPage.java,v >retrieving revision 1.32 >diff -u -r1.32 JpaFacetWizardPage.java >--- src/org/eclipse/jpt/ui/internal/wizards/JpaFacetWizardPage.java 8 May 2009 20:49:05 -0000 1.32 >+++ src/org/eclipse/jpt/ui/internal/wizards/JpaFacetWizardPage.java 25 May 2009 19:27:10 -0000 >@@ -35,6 +35,8 @@ > import org.eclipse.swt.widgets.Link; > import org.eclipse.ui.PlatformUI; > import org.eclipse.ui.help.IWorkbenchHelpSystem; >+import org.eclipse.wst.common.frameworks.datamodel.IDataModel; >+import org.eclipse.wst.common.frameworks.internal.datamodel.ui.DataModelSynchHelper; > import org.eclipse.wst.common.project.facet.core.IFacetedProjectWorkingCopy; > import org.eclipse.wst.common.project.facet.core.events.IFacetedProjectEvent; > import org.eclipse.wst.common.project.facet.core.events.IFacetedProjectListener; >@@ -53,6 +55,15 @@ > } > > @Override >+ protected IDataModel getDataModel() { >+ return super.getDataModel(); >+ } >+ >+ protected DataModelSynchHelper getSynchHelper() { >+ return this.synchHelper; >+ } >+ >+ @Override > protected Composite createTopLevelComposite(Composite parent) { > Composite composite = new Composite(parent, SWT.NULL); > GridLayout layout = new GridLayout(); >@@ -80,14 +91,14 @@ > wc.addListener( > new IFacetedProjectListener() { > public void handleEvent( final IFacetedProjectEvent event ) { >- model.setProperty(RUNTIME, wc.getPrimaryRuntime()); >+ getDataModel().setProperty(RUNTIME, wc.getPrimaryRuntime()); > } > }, > IFacetedProjectEvent.Type.PRIMARY_RUNTIME_CHANGED > ); > } > >- private Button createButton(Composite container, int span, String text, int style) { >+ Button createButton(Composite container, int span, String text, int style) { > Button button = new Button(container, SWT.NONE | style); > button.setText(text); > GridData gd = new GridData(); >@@ -96,7 +107,7 @@ > return button; > } > >- private Combo createCombo(Composite container, int span, boolean fillHorizontal) { >+ Combo createCombo(Composite container, int span, boolean fillHorizontal) { > Combo combo = new Combo(container, SWT.BORDER | SWT.SINGLE | SWT.READ_ONLY); > GridData gd; > if (fillHorizontal) { >@@ -128,18 +139,18 @@ > > @Override > public boolean isPageComplete() { >- if (! super.isPageComplete()) { >+ if ( ! super.isPageComplete()) { > return false; > } >- else { >- IStatus status =model.validate(); >- if( status.getSeverity() == IStatus.ERROR){ >- setErrorMessage( status.getMessage() ); >- return false; >- }; >- setErrorMessage(null); >- return true; >+ >+ IStatus status = this.model.validate(); >+ if (status.getSeverity() == IStatus.ERROR) { >+ this.setErrorMessage(status.getMessage()); >+ return false; > } >+ >+ this.setErrorMessage(null); >+ return true; > } > > @Override >@@ -164,7 +175,7 @@ > PlatformUI.getWorkbench().getHelpSystem().setHelp(group, JpaHelpContextIds.DIALOG_JPA_PLATFORM); > > platformCombo = createCombo(group, 1, true); >- synchHelper.synchCombo(platformCombo, PLATFORM_ID, null); >+ getSynchHelper().synchCombo(platformCombo, PLATFORM_ID, null); > } > } > >@@ -221,7 +232,7 @@ > PlatformUI.getWorkbench().getHelpSystem().setHelp(group, JpaHelpContextIds.NEW_JPA_PROJECT_CONTENT_PAGE_DATABASE); > > connectionCombo = createCombo(group, 3, true); >- synchHelper.synchCombo(connectionCombo, CONNECTION, null); >+ getSynchHelper().synchCombo(connectionCombo, CONNECTION, null); > connectionCombo.addSelectionListener( > new SelectionAdapter() { > @Override >@@ -260,7 +271,7 @@ > > addDriverLibraryButton = createButton(group, 3, JptUiMessages.JpaFacetWizardPage_addDriverLibraryLabel, SWT.CHECK); > addDriverLibraryButton.setSelection(false); >- synchHelper.synchCheckbox(addDriverLibraryButton, USER_WANTS_TO_ADD_DB_DRIVER_JARS_TO_CLASSPATH, null); >+ getSynchHelper().synchCheckbox(addDriverLibraryButton, USER_WANTS_TO_ADD_DB_DRIVER_JARS_TO_CLASSPATH, null); > > driverLibraryLabel = new Label(group, SWT.LEFT); > driverLibraryLabel.setText(JptUiMessages.JpaFacetWizardPage_driverLibraryLabel); >@@ -269,13 +280,13 @@ > driverLibraryLabel.setLayoutData(gd); > > driverLibraryCombo = createCombo(group, 1, true); >- synchHelper.synchCombo( >+ getSynchHelper().synchCombo( > driverLibraryCombo, DB_DRIVER_NAME, > new Control[] {driverLibraryLabel}); > > overrideDefaultCatalogButton = createButton(group, 3, JptUiMessages.JpaFacetWizardPage_overrideDefaultCatalogLabel, SWT.CHECK); > overrideDefaultCatalogButton.setSelection(false); >- synchHelper.synchCheckbox(overrideDefaultCatalogButton, USER_WANTS_TO_OVERRIDE_DEFAULT_CATALOG, null); >+ getSynchHelper().synchCheckbox(overrideDefaultCatalogButton, USER_WANTS_TO_OVERRIDE_DEFAULT_CATALOG, null); > > defaultCatalogLabel = new Label(group, SWT.LEFT); > defaultCatalogLabel.setText(JptUiMessages.JpaFacetWizardPage_defaultCatalogLabel); >@@ -284,13 +295,13 @@ > defaultCatalogLabel.setLayoutData(gd); > > defaultCatalogCombo = createCombo(group, 1, true); >- synchHelper.synchCombo( >+ getSynchHelper().synchCombo( > defaultCatalogCombo, USER_OVERRIDE_DEFAULT_CATALOG, > new Control[] {defaultCatalogLabel}); > > overrideDefaultSchemaButton = createButton(group, 3, JptUiMessages.JpaFacetWizardPage_overrideDefaultSchemaLabel, SWT.CHECK); > overrideDefaultSchemaButton.setSelection(false); >- synchHelper.synchCheckbox(overrideDefaultSchemaButton, USER_WANTS_TO_OVERRIDE_DEFAULT_SCHEMA, null); >+ getSynchHelper().synchCheckbox(overrideDefaultSchemaButton, USER_WANTS_TO_OVERRIDE_DEFAULT_SCHEMA, null); > > defaultSchemaLabel = new Label(group, SWT.LEFT); > defaultSchemaLabel.setText(JptUiMessages.JpaFacetWizardPage_defaultSchemaLabel); >@@ -299,28 +310,28 @@ > defaultSchemaLabel.setLayoutData(gd); > > defaultSchemaCombo = createCombo(group, 1, true); >- synchHelper.synchCombo( >+ getSynchHelper().synchCombo( > defaultSchemaCombo, USER_OVERRIDE_DEFAULT_SCHEMA, > new Control[] {defaultSchemaLabel}); > } > >- private void openNewConnectionWizard() { >+ void openNewConnectionWizard() { > String connectionName = DTPUiTools.createNewConnectionProfile(); > if (connectionName != null) { >- model.setProperty(CONNECTION, connectionName); >+ getDataModel().setProperty(CONNECTION, connectionName); > } > } > >- private void openConnectionProfile() { >+ void openConnectionProfile() { > ConnectionProfile cp = getConnectionProfile(); > if (cp != null) { > cp.connect(); >- model.setBooleanProperty(CONNECTION_ACTIVE, cp.isActive()); >+ getDataModel().setBooleanProperty(CONNECTION_ACTIVE, cp.isActive()); > updateConnectLink(); > } > } > >- private void updateConnectLink() { >+ void updateConnectLink() { > ConnectionProfile cp = this.getConnectionProfile(); > connectLink.setEnabled((cp != null) && cp.isDisconnected()); > addDriverLibraryButton.setEnabled(cp != null); >@@ -328,7 +339,7 @@ > > private ConnectionProfile getConnectionProfile() { > // we just use the connection profile to log in, so go the the db plug-in >- return JptDbPlugin.instance().getConnectionProfileFactory().buildConnectionProfile(model.getStringProperty(CONNECTION)); >+ return JptDbPlugin.instance().getConnectionProfileFactory().buildConnectionProfile(getDataModel().getStringProperty(CONNECTION)); > } > } > >@@ -348,10 +359,10 @@ > PlatformUI.getWorkbench().getHelpSystem().setHelp(group, JpaHelpContextIds.NEW_JPA_PROJECT_CONTENT_PAGE_CLASSPATH); > > discoverClassesButton = createButton(group, 1, JptUiMessages.JpaFacetWizardPage_discoverClassesButton, SWT.RADIO); >- synchHelper.synchRadio(discoverClassesButton, DISCOVER_ANNOTATED_CLASSES, null); >+ getSynchHelper().synchRadio(discoverClassesButton, DISCOVER_ANNOTATED_CLASSES, null); > > listClassesButton = createButton(group, 1, JptUiMessages.JpaFacetWizardPage_listClassesButton, SWT.RADIO); >- synchHelper.synchRadio(listClassesButton, LIST_ANNOTATED_CLASSES, null); >+ getSynchHelper().synchRadio(listClassesButton, LIST_ANNOTATED_CLASSES, null); > } > } > >@@ -369,7 +380,7 @@ > > createOrmXmlButton = new Button(group, SWT.CHECK); > createOrmXmlButton.setText(JptUiMessages.JpaFacetWizardPage_createOrmXmlButton); >- synchHelper.synchCheckbox(createOrmXmlButton, CREATE_ORM_XML, null); >+ getSynchHelper().synchCheckbox(createOrmXmlButton, CREATE_ORM_XML, null); > } > } > >#P org.eclipse.jpt.core >Index: src/org/eclipse/jpt/core/internal/facet/JpaFacetDataModelProvider.java >=================================================================== >RCS file: /cvsroot/webtools/org.eclipse.jpa/components/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/facet/JpaFacetDataModelProvider.java,v >retrieving revision 1.33 >diff -u -r1.33 JpaFacetDataModelProvider.java >--- src/org/eclipse/jpt/core/internal/facet/JpaFacetDataModelProvider.java 11 Mar 2009 00:22:00 -0000 1.33 >+++ src/org/eclipse/jpt/core/internal/facet/JpaFacetDataModelProvider.java 25 May 2009 19:27:12 -0000 >@@ -9,7 +9,6 @@ > ******************************************************************************/ > package org.eclipse.jpt.core.internal.facet; > >-import java.util.Collections; > import java.util.Comparator; > import java.util.HashMap; > import java.util.Iterator; >@@ -29,11 +28,9 @@ > import org.eclipse.jpt.db.DatabaseFinder; > import org.eclipse.jpt.db.JptDbPlugin; > import org.eclipse.jpt.db.Schema; >+import org.eclipse.jpt.db.SchemaContainer; > import org.eclipse.jpt.utility.internal.CollectionTools; >-import org.eclipse.jpt.utility.internal.StringTools; >-import org.eclipse.jpt.utility.internal.iterators.CompositeIterator; > import org.eclipse.jpt.utility.internal.iterators.EmptyIterator; >-import org.eclipse.jpt.utility.internal.iterators.TransformationIterator; > import org.eclipse.jst.common.project.facet.core.libprov.IPropertyChangeListener; > import org.eclipse.jst.common.project.facet.core.libprov.LibraryInstallDelegate; > import org.eclipse.osgi.util.NLS; >@@ -41,21 +38,23 @@ > import org.eclipse.wst.common.componentcore.internal.util.IModuleConstants; > import org.eclipse.wst.common.frameworks.datamodel.DataModelPropertyDescriptor; > import org.eclipse.wst.common.frameworks.datamodel.IDataModel; >-import org.eclipse.wst.common.frameworks.internal.plugin.WTPCommonMessages; >-import org.eclipse.wst.common.frameworks.internal.plugin.WTPCommonPlugin; > import org.eclipse.wst.common.project.facet.core.IFacetedProjectWorkingCopy; > import org.eclipse.wst.common.project.facet.core.IProjectFacetVersion; > import org.eclipse.wst.common.project.facet.core.ProjectFacetsManager; > import org.eclipse.wst.common.project.facet.core.runtime.IRuntime; > >-public class JpaFacetDataModelProvider extends FacetInstallDataModelProvider >+public class JpaFacetDataModelProvider >+ extends FacetInstallDataModelProvider > implements JpaFacetDataModelProperties > { >- private static final String EJB_FACET_ID = IModuleConstants.JST_EJB_MODULE; >+ private LibraryInstallDelegate defaultLibraryProvider; > >- private static final String RUNTIME_NONE = >- WTPCommonPlugin.getResourceString(WTPCommonMessages.RUNTIME_NONE, null); >+ /** cache the connection profile - change it whenever the user selects a different name */ >+ private ConnectionProfile connectionProfile; >+ > >+ private static final String EJB_FACET_ID = IModuleConstants.JST_EJB_MODULE; >+ > private static final IStatus PLATFORM_NOT_SPECIFIED_STATUS = > buildErrorStatus(JptCoreMessages.VALIDATE_PLATFORM_NOT_SPECIFIED); > >@@ -63,29 +62,19 @@ > buildInfoStatus(JptCoreMessages.VALIDATE_CONNECTION_NOT_CONNECTED); > > private static final IStatus USER_OVERRIDE_DEFAULT_CATALOG_NOT_SPECIFIED_STATUS = >- buildErrorStatus(JptCoreMessages.VALIDATE_DEFAULT_CATALOG_NOT_SPECIFIED); >+ buildErrorStatus(JptCoreMessages.VALIDATE_DEFAULT_CATALOG_NOT_SPECIFIED); > > private static final IStatus USER_OVERRIDE_DEFAULT_SCHEMA_NOT_SPECIFIED_STATUS = > buildErrorStatus(JptCoreMessages.VALIDATE_DEFAULT_SCHEMA_NOT_SPECIFIED); > >- private static final IStatus RUNTIME_NOT_SPECIFIED_STATUS = >- buildWarningStatus(JptCoreMessages.VALIDATE_RUNTIME_NOT_SPECIFIED); >- >- private static final IStatus RUNTIME_DOES_NOT_SUPPORT_EJB_30_STATUS = >- buildWarningStatus(JptCoreMessages.VALIDATE_RUNTIME_DOES_NOT_SUPPORT_EJB_30); >- >- >- private LibraryInstallDelegate defaultLibraryProvider; >- >- >+ > /** > * required default constructor > */ > public JpaFacetDataModelProvider() { > super(); > } >- >- >+ > @Override > public Set<String> getPropertyNames() { > @SuppressWarnings("unchecked") Set<String> propertyNames = super.getPropertyNames(); >@@ -105,24 +94,94 @@ > propertyNames.add(CREATE_ORM_XML); > return propertyNames; > } >+ >+ >+ // ********** properties ********** >+ >+ private String getPlatformId() { >+ return (String) this.getProperty(PLATFORM_ID); >+ } >+ >+ private String getConnectionName() { >+ return (String) this.getProperty(CONNECTION); >+ } >+ >+ private boolean userWantsToAddDbDriverJarsToClasspath() { >+ return this.getBooleanProperty(USER_WANTS_TO_ADD_DB_DRIVER_JARS_TO_CLASSPATH); >+ } >+ >+ private String getDriverName() { >+ return (String) this.getProperty(DB_DRIVER_NAME); >+ } >+ >+ private boolean userWantsToOverrideDefaultCatalog() { >+ return this.getBooleanProperty(USER_WANTS_TO_OVERRIDE_DEFAULT_CATALOG); >+ } > >+ private String getUserOverrideDefaultCatalog() { >+ return (String) this.getProperty(USER_OVERRIDE_DEFAULT_CATALOG); >+ } >+ >+ private boolean userWantsToOverrideDefaultSchema() { >+ return this.getBooleanProperty(USER_WANTS_TO_OVERRIDE_DEFAULT_SCHEMA); >+ } >+ >+ private String getUserOverrideDefaultSchema() { >+ return (String) this.getProperty(USER_OVERRIDE_DEFAULT_SCHEMA); >+ } >+ >+ private boolean discoverAnnotatedClasses() { >+ return this.getBooleanProperty(DISCOVER_ANNOTATED_CLASSES); >+ } >+ >+ private IFacetedProjectWorkingCopy getFacetedProjectWorkingCopy() { >+ return (IFacetedProjectWorkingCopy) this.getProperty(FACETED_PROJECT_WORKING_COPY); >+ } >+ >+ private IProjectFacetVersion getProjectFacetVersion() { >+ return (IProjectFacetVersion) this.getProperty(FACET_VERSION); >+ } >+ >+ private IRuntime getRuntime() { >+ return (IRuntime) this.getProperty(RUNTIME); >+ } >+ >+ private LibraryInstallDelegate getLibraryInstallDelegate() { >+ return (LibraryInstallDelegate) this.getProperty(LIBRARY_PROVIDER_DELEGATE); >+ } >+ >+ >+ // ********** enabled ********** >+ > @Override > public boolean isPropertyEnabled(String propertyName) { >- if (propertyName.equals(USER_OVERRIDE_DEFAULT_CATALOG)) { >- return getBooleanProperty(USER_WANTS_TO_OVERRIDE_DEFAULT_CATALOG); >- } >- if (propertyName.equals(USER_OVERRIDE_DEFAULT_SCHEMA)) { >- return getBooleanProperty(USER_WANTS_TO_OVERRIDE_DEFAULT_SCHEMA); >- } > if (propertyName.equals(USER_WANTS_TO_ADD_DB_DRIVER_JARS_TO_CLASSPATH)) { >- return getConnectionProfile() != null; >+ return (this.getConnectionProfile() != null); > } > if (propertyName.equals(DB_DRIVER_NAME)) { >- return getBooleanProperty(USER_WANTS_TO_ADD_DB_DRIVER_JARS_TO_CLASSPATH); >+ return this.userWantsToAddDbDriverJarsToClasspath(); > } >+ >+ if (propertyName.equals(USER_WANTS_TO_OVERRIDE_DEFAULT_CATALOG)) { >+ return this.connectionIsActive() && this.databaseSupportsCatalogs(); >+ } >+ if (propertyName.equals(USER_OVERRIDE_DEFAULT_CATALOG)) { >+ return this.userWantsToOverrideDefaultCatalog(); >+ } >+ >+ if (propertyName.equals(USER_WANTS_TO_OVERRIDE_DEFAULT_SCHEMA)) { >+ return this.connectionIsActive(); >+ } >+ if (propertyName.equals(USER_OVERRIDE_DEFAULT_SCHEMA)) { >+ return this.userWantsToOverrideDefaultSchema(); >+ } >+ > return super.isPropertyEnabled(propertyName); > } >- >+ >+ >+ // ********** defaults ********** >+ > @Override > public Object getDefaultProperty(String propertyName) { > if (propertyName.equals(RUNTIME)) { >@@ -135,37 +194,37 @@ > return JptCorePlugin.getDefaultJpaPlatformId(); > } > if (propertyName.equals(LIBRARY_PROVIDER_DELEGATE)) { >- return getDefaultLibraryProvider(); >+ return this.getDefaultLibraryProvider(); > } > if (propertyName.equals(CONNECTION)) { > return null; > } > if (propertyName.equals(CONNECTION_ACTIVE)) { >- return Boolean.valueOf(connectionIsActive()); >+ return Boolean.valueOf(this.connectionIsActive()); > } > if (propertyName.equals(USER_WANTS_TO_ADD_DB_DRIVER_JARS_TO_CLASSPATH)) { > return Boolean.FALSE; > } > if (propertyName.equals(DB_DRIVER_NAME)) { >- return getDefaultDriverName(); >+ return this.getDefaultDriverName(); > } > if (propertyName.equals(USER_WANTS_TO_OVERRIDE_DEFAULT_CATALOG)) { > return Boolean.FALSE; > } > if (propertyName.equals(USER_OVERRIDE_DEFAULT_CATALOG)) { >- return getDefaultCatalogName(); >+ return this.getDefaultCatalogName(); > } > if (propertyName.equals(USER_WANTS_TO_OVERRIDE_DEFAULT_SCHEMA)) { > return Boolean.FALSE; > } > if (propertyName.equals(USER_OVERRIDE_DEFAULT_SCHEMA)) { >- return getDefaultSchemaName(); >+ return this.getDefaultSchemaName(); > } > if (propertyName.equals(DISCOVER_ANNOTATED_CLASSES)) { >- return Boolean.valueOf(this.runtimeSupportsEjb30(this.runtime())); >+ return Boolean.valueOf(this.runtimeSupportsEjb30()); > } > if (propertyName.equals(LIST_ANNOTATED_CLASSES)) { >- return Boolean.valueOf( ! getBooleanProperty(DISCOVER_ANNOTATED_CLASSES)); >+ return Boolean.valueOf( ! this.discoverAnnotatedClasses()); > } > if (propertyName.equals(CREATE_ORM_XML)) { > return Boolean.TRUE; >@@ -173,63 +232,80 @@ > > return super.getDefaultProperty(propertyName); > } >- >- private String getDefaultDriverName() { >- ConnectionProfile cp = this.getConnectionProfile(); >- if (cp == null) { >- return null; >+ >+ private LibraryInstallDelegate getDefaultLibraryProvider() { >+ // delegate itself changes, not the instance of delegate >+ if (this.defaultLibraryProvider == null) { >+ this.defaultLibraryProvider = this.buildDefaultLibraryProvider(); > } >- return cp.getDriverName(); >+ return defaultLibraryProvider; > } >- >- private String getDefaultCatalogName() { >- ConnectionProfile cp = this.getConnectionProfile(); >- if (cp == null) { >+ >+ private LibraryInstallDelegate buildDefaultLibraryProvider() { >+ IFacetedProjectWorkingCopy fpjwc = this.getFacetedProjectWorkingCopy(); >+ if (fpjwc == null) { > return null; > } >- Database db = cp.getDatabase(); >- if (db == null) { >+ IProjectFacetVersion pfv = this.getProjectFacetVersion(); >+ if (pfv == null) { > return null; > } >- Catalog catalog = db.getDefaultCatalog(); >+ LibraryInstallDelegate lp = new LibraryInstallDelegate(fpjwc, pfv, this.buildEnablementVariables()); >+ lp.addListener(this.buildLibraryProviderListener()); >+ return lp; >+ } >+ >+ private Map<String, Object> buildEnablementVariables() { >+ Map<String, Object> enablementVariables = new HashMap<String, Object>(); >+ enablementVariables.put(JpaLibraryProviderConstants.EXPR_VAR_JPA_PLATFORM, this.getPlatformId()); >+ return enablementVariables; >+ } >+ >+ private IPropertyChangeListener buildLibraryProviderListener() { >+ return new IPropertyChangeListener() { >+ public void propertyChanged(String property, Object oldValue, Object newValue ) { >+ JpaFacetDataModelProvider.this.getDataModel().notifyPropertyChange(LIBRARY_PROVIDER_DELEGATE, IDataModel.VALUE_CHG); >+ } >+ }; >+ } >+ >+ private String getDefaultDriverName() { >+ ConnectionProfile cp = this.getConnectionProfile(); >+ return (cp == null) ? null : cp.getDriverName(); >+ } >+ >+ private String getDefaultCatalogName() { >+ Catalog catalog = this.getDefaultCatalog(); > return (catalog == null) ? null : catalog.getIdentifier(); > } > >+ private Catalog getDefaultCatalog() { >+ Database db = this.getDatabase(); >+ return (db == null) ? null : db.getDefaultCatalog(); >+ } >+ > private String getDefaultSchemaName() { >- ConnectionProfile cp = this.getConnectionProfile(); >- if (cp == null) { >- return null; >- } >- Database db = cp.getDatabase(); >- if (db == null) { >- return null; >- } >- Schema schema = db.getDefaultSchema(); >+ Schema schema = this.getDefaultSchema(); > return (schema == null) ? null : schema.getIdentifier(); > } > >- private LibraryInstallDelegate getDefaultLibraryProvider() { >- // delegate itself changes, not the instance of delegate >- if (defaultLibraryProvider == null) { >- IFacetedProjectWorkingCopy fpjwc = (IFacetedProjectWorkingCopy) getProperty(FACETED_PROJECT_WORKING_COPY); >- IProjectFacetVersion fv = (IProjectFacetVersion) getProperty(FACET_VERSION); >- if (fpjwc != null && fv != null ) { >- Map<String, Object> enablementVariables = new HashMap<String, Object>(); >- enablementVariables.put( >- JpaLibraryProviderConstants.EXPR_VAR_JPA_PLATFORM, >- getPlatformId()); >- defaultLibraryProvider = new LibraryInstallDelegate(fpjwc, fv, enablementVariables); >- defaultLibraryProvider.addListener( >- new IPropertyChangeListener() { >- public void propertyChanged(final String property, final Object oldValue, final Object newValue ) { >- JpaFacetDataModelProvider.this.model.notifyPropertyChange(LIBRARY_PROVIDER_DELEGATE, IDataModel.VALUE_CHG); >- } >- }); >- } >- } >- return defaultLibraryProvider; >+ private Schema getDefaultSchema() { >+ SchemaContainer sc = this.getSchemaContainer(); >+ return (sc == null) ? null : sc.getDefaultSchema(); > } >- >+ >+ private boolean runtimeSupportsEjb30() { >+ IRuntime runtime = this.getRuntime(); >+ return (runtime != null) && runtime.supports(this.getEJB30()); >+ } >+ >+ private IProjectFacetVersion getEJB30() { >+ return ProjectFacetsManager.getProjectFacet(EJB_FACET_ID).getVersion("3.0"); //$NON-NLS-1$ >+ } >+ >+ >+ // ********** synchronize data model ********** >+ > @Override > public boolean propertySet(String propertyName, Object propertyValue) { > boolean ok = super.propertySet(propertyName, propertyValue); >@@ -237,11 +313,11 @@ > if (propertyName.equals(FACETED_PROJECT_WORKING_COPY)) { > //no-op > } >- if( propertyName.equals(FACET_VERSION)){ >+ else if (propertyName.equals(FACET_VERSION)) { > this.model.notifyPropertyChange(LIBRARY_PROVIDER_DELEGATE, IDataModel.DEFAULT_CHG); > } >- if (propertyName.equals(RUNTIME)) { >- LibraryInstallDelegate lid = getLibraryInstallDelegate(); >+ else if (propertyName.equals(RUNTIME)) { >+ LibraryInstallDelegate lid = this.getLibraryInstallDelegate(); > if (lid != null) { > // may be null while model is being built up > // ... or in tests >@@ -250,321 +326,364 @@ > this.model.notifyPropertyChange(DISCOVER_ANNOTATED_CLASSES, IDataModel.DEFAULT_CHG); > this.model.notifyPropertyChange(LIST_ANNOTATED_CLASSES, IDataModel.DEFAULT_CHG); > } >- if (propertyName.equals(PLATFORM_ID)) { >- LibraryInstallDelegate lid = getLibraryInstallDelegate(); >+ else if (propertyName.equals(PLATFORM_ID)) { >+ LibraryInstallDelegate lid = this.getLibraryInstallDelegate(); > if (lid != null) { > // may be null while model is being built up > // ... or in tests >- lid.setEnablementContextVariable( >- JpaLibraryProviderConstants.EXPR_VAR_JPA_PLATFORM, >- (String) propertyValue); >+ lid.setEnablementContextVariable(JpaLibraryProviderConstants.EXPR_VAR_JPA_PLATFORM, propertyValue); > } > } >- if (propertyName.equals(CONNECTION)) { >- this.model.notifyPropertyChange(CONNECTION, IDataModel.VALID_VALUES_CHG); >- this.model.setBooleanProperty(CONNECTION_ACTIVE, connectionIsActive()); >+ else if (propertyName.equals(CONNECTION)) { >+ this.setBooleanProperty(CONNECTION_ACTIVE, this.connectionIsActive()); >+ >+ // db driver >+ if (propertyValue == null) { // connection set to '<None>' >+ this.setBooleanProperty(USER_WANTS_TO_ADD_DB_DRIVER_JARS_TO_CLASSPATH, false); >+ } >+ this.model.notifyPropertyChange(USER_WANTS_TO_ADD_DB_DRIVER_JARS_TO_CLASSPATH, IDataModel.ENABLE_CHG); > this.model.notifyPropertyChange(DB_DRIVER_NAME, IDataModel.DEFAULT_CHG); > this.model.notifyPropertyChange(DB_DRIVER_NAME, IDataModel.VALID_VALUES_CHG); >+ >+ // catalog >+ if ((propertyValue == null) || ! this.databaseSupportsCatalogs()) { // connection set to '<None>' or "non-catalog" database >+ this.setBooleanProperty(USER_WANTS_TO_OVERRIDE_DEFAULT_CATALOG, false); >+ } >+ this.model.notifyPropertyChange(USER_WANTS_TO_OVERRIDE_DEFAULT_CATALOG, IDataModel.ENABLE_CHG); > this.model.notifyPropertyChange(USER_OVERRIDE_DEFAULT_CATALOG, IDataModel.DEFAULT_CHG); > this.model.notifyPropertyChange(USER_OVERRIDE_DEFAULT_CATALOG, IDataModel.VALID_VALUES_CHG); >+ >+ // schema >+ if (propertyValue == null) { // connection set to '<None>' >+ this.setBooleanProperty(USER_WANTS_TO_OVERRIDE_DEFAULT_SCHEMA, false); >+ } >+ this.model.notifyPropertyChange(USER_WANTS_TO_OVERRIDE_DEFAULT_SCHEMA, IDataModel.ENABLE_CHG); > this.model.notifyPropertyChange(USER_OVERRIDE_DEFAULT_SCHEMA, IDataModel.DEFAULT_CHG); > this.model.notifyPropertyChange(USER_OVERRIDE_DEFAULT_SCHEMA, IDataModel.VALID_VALUES_CHG); > } >- if (propertyName.equals(CONNECTION_ACTIVE)) { >+ else if (propertyName.equals(CONNECTION_ACTIVE)) { >+ // catalog >+ if (this.propertyValueIsFalse(propertyValue)) { // connection is inactive >+ this.setBooleanProperty(USER_WANTS_TO_OVERRIDE_DEFAULT_CATALOG, false); >+ } >+ this.model.notifyPropertyChange(USER_WANTS_TO_OVERRIDE_DEFAULT_CATALOG, IDataModel.ENABLE_CHG); > this.model.notifyPropertyChange(USER_OVERRIDE_DEFAULT_CATALOG, IDataModel.DEFAULT_CHG); > this.model.notifyPropertyChange(USER_OVERRIDE_DEFAULT_CATALOG, IDataModel.VALID_VALUES_CHG); >+ >+ // schema >+ if (this.propertyValueIsFalse(propertyValue)) { // connection is inactive >+ this.setBooleanProperty(USER_WANTS_TO_OVERRIDE_DEFAULT_SCHEMA, false); >+ } >+ this.model.notifyPropertyChange(USER_WANTS_TO_OVERRIDE_DEFAULT_SCHEMA, IDataModel.ENABLE_CHG); > this.model.notifyPropertyChange(USER_OVERRIDE_DEFAULT_SCHEMA, IDataModel.DEFAULT_CHG); > this.model.notifyPropertyChange(USER_OVERRIDE_DEFAULT_SCHEMA, IDataModel.VALID_VALUES_CHG); >- this.model.notifyPropertyChange(USER_WANTS_TO_ADD_DB_DRIVER_JARS_TO_CLASSPATH, IDataModel.ENABLE_CHG); >- this.model.notifyPropertyChange(DB_DRIVER_NAME, IDataModel.ENABLE_CHG); > } >- if (propertyName.equals(USER_WANTS_TO_ADD_DB_DRIVER_JARS_TO_CLASSPATH)) { >+ else if (propertyName.equals(USER_WANTS_TO_ADD_DB_DRIVER_JARS_TO_CLASSPATH)) { > this.model.notifyPropertyChange(DB_DRIVER_NAME, IDataModel.ENABLE_CHG); >- if (! ((Boolean) propertyValue).booleanValue()) { >- this.model.setProperty(DB_DRIVER_NAME, null); >+ if (this.propertyValueIsFalse(propertyValue)) { >+ this.setProperty(DB_DRIVER_NAME, null); > } > } >- if (propertyName.equals(USER_WANTS_TO_OVERRIDE_DEFAULT_CATALOG)) { >+ else if (propertyName.equals(USER_WANTS_TO_OVERRIDE_DEFAULT_CATALOG)) { > this.model.notifyPropertyChange(USER_OVERRIDE_DEFAULT_CATALOG, IDataModel.ENABLE_CHG); >- if (! ((Boolean) propertyValue).booleanValue()) { >- this.model.setProperty(USER_OVERRIDE_DEFAULT_CATALOG, null); >+ if (this.propertyValueIsFalse(propertyValue)) { >+ this.setProperty(USER_OVERRIDE_DEFAULT_CATALOG, null); > } > } >- if (propertyName.equals(USER_WANTS_TO_OVERRIDE_DEFAULT_SCHEMA)) { >+ else if (propertyName.equals(USER_WANTS_TO_OVERRIDE_DEFAULT_SCHEMA)) { > this.model.notifyPropertyChange(USER_OVERRIDE_DEFAULT_SCHEMA, IDataModel.ENABLE_CHG); >- if (! ((Boolean) propertyValue).booleanValue()) { >- this.model.setProperty(USER_OVERRIDE_DEFAULT_SCHEMA, null); >+ if (this.propertyValueIsFalse(propertyValue)) { >+ this.setProperty(USER_OVERRIDE_DEFAULT_SCHEMA, null); > } > } >-// if (propertyName.equals(USE_SERVER_JPA_IMPLEMENTATION)) { >-// this.model.setBooleanProperty(USE_USER_JPA_LIBRARY, ! ((Boolean) propertyValue).booleanValue()); >-// } >-// if (propertyName.equals(USE_USER_JPA_LIBRARY)) { >-// this.model.setBooleanProperty(USE_SERVER_JPA_IMPLEMENTATION, ! ((Boolean) propertyValue).booleanValue()); >-// this.model.notifyPropertyChange(JPA_LIBRARY, IDataModel.ENABLE_CHG); >-// } >- if (propertyName.equals(DISCOVER_ANNOTATED_CLASSES)) { >- this.model.setBooleanProperty(LIST_ANNOTATED_CLASSES, ! ((Boolean) propertyValue).booleanValue()); >+ else if (propertyName.equals(DISCOVER_ANNOTATED_CLASSES)) { >+ this.setBooleanProperty(LIST_ANNOTATED_CLASSES, this.propertyValueIsFalse(propertyValue)); > } >- if (propertyName.equals(LIST_ANNOTATED_CLASSES)) { >- this.model.setBooleanProperty(DISCOVER_ANNOTATED_CLASSES, ! ((Boolean) propertyValue).booleanValue()); >+ else if (propertyName.equals(LIST_ANNOTATED_CLASSES)) { >+ this.setBooleanProperty(DISCOVER_ANNOTATED_CLASSES, this.propertyValueIsFalse(propertyValue)); > } > return ok; > } > >- private static final DataModelPropertyDescriptor[] EMPTY_DMPD_ARRAY = new DataModelPropertyDescriptor[0]; >+ private boolean propertyValueIsFalse(Object propertyValue) { >+ return ! this.propertyValueIsTrue(propertyValue); >+ } >+ >+ private boolean propertyValueIsTrue(Object propertyValue) { >+ return ((Boolean) propertyValue).booleanValue(); >+ } >+ >+ >+ // ********** property descriptors ********** > > @Override > public DataModelPropertyDescriptor[] getValidPropertyDescriptors(String propertyName) { > if (propertyName.equals(PLATFORM_ID)) { >- return CollectionTools.sort( >- CollectionTools.array( >- new TransformationIterator<String, DataModelPropertyDescriptor>( >- JpaPlatformRegistry.instance().jpaPlatformIds()) { >- @Override >- protected DataModelPropertyDescriptor transform(String platformId) { >- return platformIdPropertyDescriptor(platformId); >- } >- }, >- EMPTY_DMPD_ARRAY), >- new Comparator<DataModelPropertyDescriptor>() { >- public int compare(DataModelPropertyDescriptor o1, DataModelPropertyDescriptor o2) { >- return (o1.getPropertyDescription().compareTo(o2.getPropertyDescription())); >- }; >- }); >+ return this.buildValidPlatformDescriptors(); > } >+ > if (propertyName.equals(CONNECTION)) { >- return CollectionTools.array( >- new TransformationIterator<String, DataModelPropertyDescriptor>( >- new CompositeIterator<String>(null, connectionNames())) { >- @Override >- protected DataModelPropertyDescriptor transform(String next) { >- return connectionPropertyDescriptor(next); >- } >- }, >- EMPTY_DMPD_ARRAY); >+ return this.buildValidConnectionDescriptors(); > } >+ > if (propertyName.equals(DB_DRIVER_NAME)) { >- return CollectionTools.array( >- new TransformationIterator<String, DataModelPropertyDescriptor>(driverNames()) { >- @Override >- protected DataModelPropertyDescriptor transform(String next) { >- return new DataModelPropertyDescriptor(next); >- } >- }, >- EMPTY_DMPD_ARRAY); >+ return this.buildValidDriverDescriptors(); > } >+ > if (propertyName.equals(USER_OVERRIDE_DEFAULT_CATALOG)) { >- return CollectionTools.array( >- new TransformationIterator<String, DataModelPropertyDescriptor>(catalogNames()) { >- @Override >- protected DataModelPropertyDescriptor transform(String next) { >- return new DataModelPropertyDescriptor(next); >- } >- }, >- EMPTY_DMPD_ARRAY); >+ return this.buildValidCatalogDescriptors(); > } >+ > if (propertyName.equals(USER_OVERRIDE_DEFAULT_SCHEMA)) { >- return CollectionTools.array( >- new TransformationIterator<String, DataModelPropertyDescriptor>(schemaNames()) { >- @Override >- protected DataModelPropertyDescriptor transform(String next) { >- return new DataModelPropertyDescriptor(next); >- } >- }, >- EMPTY_DMPD_ARRAY); >+ return this.buildValidSchemaDescriptors(); > } > > return super.getValidPropertyDescriptors(propertyName); > } >- >+ >+ private DataModelPropertyDescriptor[] buildValidPlatformDescriptors() { >+ List<String> platformIDs = CollectionTools.list(JpaPlatformRegistry.instance().jpaPlatformIds()); >+ DataModelPropertyDescriptor[] descriptors = new DataModelPropertyDescriptor[platformIDs.size()]; >+ for (int i = 0; i < descriptors.length; i++) { >+ descriptors[i] = this.buildPlatformIdDescriptor(platformIDs.get(i)); >+ } >+ return CollectionTools.sort(descriptors, this.buildDescriptorComparator()); >+ } >+ >+ /** >+ * sort the descriptors by 'description' (as opposed to 'value') >+ */ >+ private Comparator<DataModelPropertyDescriptor> buildDescriptorComparator() { >+ return new Comparator<DataModelPropertyDescriptor>() { >+ public int compare(DataModelPropertyDescriptor o1, DataModelPropertyDescriptor o2) { >+ return (o1.getPropertyDescription().compareTo(o2.getPropertyDescription())); >+ } >+ }; >+ } >+ >+ private DataModelPropertyDescriptor[] buildValidConnectionDescriptors() { >+ List<String> connectionNames = this.buildValidConnectionNames(); >+ DataModelPropertyDescriptor[] descriptors = new DataModelPropertyDescriptor[connectionNames.size()]; >+ for (int i = 0; i < descriptors.length; i++) { >+ descriptors[i] = this.buildConnectionDescriptor(connectionNames.get(i)); >+ } >+ return descriptors; >+ } >+ >+ /** >+ * put a null entry at the top of the list (for <none>) >+ */ >+ private List<String> buildValidConnectionNames() { >+ List<String> connectionNames = CollectionTools.sort(CollectionTools.list(this.connectionProfileNames())); >+ connectionNames.add(0, null); >+ return connectionNames; >+ } >+ >+ private DataModelPropertyDescriptor[] buildValidDriverDescriptors() { >+ return new DataModelPropertyDescriptor[] { new DataModelPropertyDescriptor(this.getDriverName()) }; >+ } >+ >+ private DataModelPropertyDescriptor[] buildValidCatalogDescriptors() { >+ Database db = this.getDatabase(); >+ return (db == null) ? EMPTY_DMPD_ARRAY : this.buildDescriptors(this.buildValidCatalogNames(db)); >+ } >+ >+ /** >+ * pre-condition: 'db' is not null >+ */ >+ private List<String> buildValidCatalogNames(Database db) { >+ return this.buildValidStrings(db.sortedCatalogIdentifiers(), this.getDefaultCatalogName()); >+ } >+ >+ private DataModelPropertyDescriptor[] buildValidSchemaDescriptors() { >+ Database db = this.getDatabase(); >+ return (db == null) ? EMPTY_DMPD_ARRAY : this.buildDescriptors(this.buildValidSchemaNames()); >+ } >+ >+ private List<String> buildValidSchemaNames() { >+ return this.buildValidStrings(this.schemaNames(), this.getDefaultSchemaName()); >+ } >+ >+ private Iterator<String> schemaNames() { >+ SchemaContainer sc = this.getSchemaContainer(); >+ return (sc == null) ? EmptyIterator.<String>instance() : sc.sortedSchemaIdentifiers(); >+ } >+ >+ /** >+ * put an entry for the default at the top of the list >+ */ >+ private List<String> buildValidStrings(Iterator<String> stream, String defaultString) { >+ List<String> strings = CollectionTools.list(stream); >+ if ((defaultString != null) && ! strings.contains(defaultString)) { >+ strings.add(0, defaultString); >+ } >+ return strings; >+ } >+ >+ private DataModelPropertyDescriptor[] buildDescriptors(List<String> strings) { >+ DataModelPropertyDescriptor[] descriptors = new DataModelPropertyDescriptor[strings.size()]; >+ for (int i = 0; i < descriptors.length; i++) { >+ descriptors[i] = new DataModelPropertyDescriptor(strings.get(i)); >+ } >+ return descriptors; >+ } >+ >+ private static final DataModelPropertyDescriptor[] EMPTY_DMPD_ARRAY = new DataModelPropertyDescriptor[0]; >+ >+ /** >+ * platform and connection have 'description's (in addition to 'value's) >+ */ > @Override > public DataModelPropertyDescriptor getPropertyDescriptor(String propertyName) { > if (propertyName.equals(PLATFORM_ID)) { >- return platformIdPropertyDescriptor(getStringProperty(PLATFORM_ID)); >+ return this.buildPlatformIdDescriptor(this.getPlatformId()); > } > if (propertyName.equals(CONNECTION)) { >- return connectionPropertyDescriptor(getStringProperty(CONNECTION)); >+ return this.buildConnectionDescriptor(this.getConnectionName()); > } > return super.getPropertyDescriptor(propertyName); > } >- >- DataModelPropertyDescriptor platformIdPropertyDescriptor(String platformId) { >- return new DataModelPropertyDescriptor( >- platformId, JpaPlatformRegistry.instance().getJpaPlatformLabel(platformId)); >+ >+ DataModelPropertyDescriptor buildPlatformIdDescriptor(String platformId) { >+ return new DataModelPropertyDescriptor(platformId, this.getPlatformLabel(platformId)); > } >- >- DataModelPropertyDescriptor connectionPropertyDescriptor(String connection) { >- return StringTools.stringIsEmpty(connection) ? >- new DataModelPropertyDescriptor(null, JptCoreMessages.NONE) >- : >- new DataModelPropertyDescriptor(connection); >+ >+ private String getPlatformLabel(String platformId) { >+ return JpaPlatformRegistry.instance().getJpaPlatformLabel(platformId); > } > >- @Override >- public IStatus validate(String name) { >- if (name.equals(PLATFORM_ID)) { >- return this.validatePlatformId(this.getStringProperty(name)); >- } >- if (name.equals(LIBRARY_PROVIDER_DELEGATE)) { >- LibraryInstallDelegate delegate = (LibraryInstallDelegate) getProperty(LIBRARY_PROVIDER_DELEGATE); >- return delegate.validate(); >- } >- if (name.equals(CONNECTION)) { >- return this.validateConnectionName(this.getStringProperty(name)); >- } >- if (name.equals(USER_WANTS_TO_ADD_DB_DRIVER_JARS_TO_CLASSPATH) >- || name.equals(DB_DRIVER_NAME)) { >- return this.validateDbDriverName(); >- } >- if (name.equals(USER_WANTS_TO_OVERRIDE_DEFAULT_CATALOG) >- || name.equals(USER_OVERRIDE_DEFAULT_CATALOG)) { >- return this.validateUserOverrideDefaultCatalog(); >- } >- if (name.equals(USER_WANTS_TO_OVERRIDE_DEFAULT_SCHEMA) >- || name.equals(USER_OVERRIDE_DEFAULT_SCHEMA)) { >- return this.validateUserOverrideDefaultSchema(); >- } >- if (name.equals(DISCOVER_ANNOTATED_CLASSES)) { >- return this.validatePersistentClassManagement(this.getBooleanProperty(name)); >- } >- >- return super.validate(name); >+ private DataModelPropertyDescriptor buildConnectionDescriptor(String connectionName) { >+ String description = (connectionName == null) ? JptCoreMessages.NONE : null; >+ return new DataModelPropertyDescriptor(connectionName, description); > } > >- private IRuntime runtime() { >- return (IRuntime) this.getProperty(RUNTIME); >+ >+ // ********** database ********** >+ >+ private SchemaContainer getSchemaContainer() { >+ return this.databaseSupportsCatalogs() ? this.getCatalog() : this.getDatabase(); > } > >- private boolean runtimeSupportsEjb30(IRuntime runtime) { >- IProjectFacetVersion ejb30 = ProjectFacetsManager.getProjectFacet(EJB_FACET_ID).getVersion("3.0"); //$NON-NLS-1$ >- return (runtime == null) ? false : runtime.supports(ejb30); >+ private Catalog getCatalog() { >+ String name = this.getUserOverrideDefaultCatalog(); >+ return (name == null) ? null : this.getCatalog(name); > } >- >- private String getPlatformId() { >- return this.getStringProperty(PLATFORM_ID); >+ >+ /** >+ * pre-condition: 'name' is not null >+ */ >+ private Catalog getCatalog(String name) { >+ Database db = this.getDatabase(); >+ return (db == null) ? null : db.getCatalogForIdentifier(name); >+ } >+ >+ private boolean databaseSupportsCatalogs() { >+ Database db = this.getDatabase(); >+ return (db != null) && db.supportsCatalogs(); > } > >- private LibraryInstallDelegate getLibraryInstallDelegate() { >- return (LibraryInstallDelegate) getProperty(LIBRARY_PROVIDER_DELEGATE); >+ private Database getDatabase() { >+ ConnectionProfile cp = this.getConnectionProfile(); >+ return (cp == null) ? null : cp.getDatabase(); > } > >- private String getConnectionName() { >- return this.getStringProperty(CONNECTION); >+ private boolean connectionIsActive() { >+ ConnectionProfile cp = this.getConnectionProfile(); >+ return (cp != null) && cp.isActive(); > } >- >+ > private ConnectionProfile getConnectionProfile() { >- return this.buildConnectionProfile(this.getConnectionName()); >+ String name = this.getConnectionName(); >+ return (name == null) ? null : this.getConnectionProfile(name); > } > >- private ConnectionProfileFactory getConnectionProfileFactory() { >- // we don't have a JPA project yet, so go to the db plug-in directly to get the factory >- return JptDbPlugin.instance().getConnectionProfileFactory(); >+ /** >+ * pre-condition: 'name' is not null >+ */ >+ private ConnectionProfile getConnectionProfile(String name) { >+ if (this.cachedConnectionProfileIsStale(name)) { >+ this.connectionProfile = this.buildConnectionProfile(name); >+ } >+ return this.connectionProfile; > } > >- private ConnectionProfile buildConnectionProfile(String name) { >- return this.getConnectionProfileFactory().buildConnectionProfile(name, DatabaseFinder.Default.instance()); >+ private boolean cachedConnectionProfileIsStale(String name) { >+ return (this.connectionProfile == null) || ! this.connectionProfile.getName().equals(name); > } > >- private boolean connectionIsActive() { >- return this.connectionIsActive(this.getConnectionName()); >+ private ConnectionProfile buildConnectionProfile(String name) { >+ return this.getConnectionProfileFactory().buildConnectionProfile(name, DatabaseFinder.Default.instance()); > } > >- private boolean connectionIsActive(String connectionName) { >- ConnectionProfile cp = this.buildConnectionProfile(connectionName); >- return (cp != null) && cp.isActive(); >+ private Iterator<String> connectionProfileNames() { >+ return this.getConnectionProfileFactory().connectionProfileNames(); > } > >- private Iterator<String> connectionNames() { >- String setValue = getStringProperty(CONNECTION); >- >- List<String> connectionNames = CollectionTools.sort(CollectionTools.list( >- this.getConnectionProfileFactory().connectionProfileNames())); >- >- if (! StringTools.stringIsEmpty(setValue) && ! connectionNames.contains(setValue)) { >- return new CompositeIterator<String>(setValue, connectionNames.iterator()); >- } >- return connectionNames.iterator(); >+ private ConnectionProfileFactory getConnectionProfileFactory() { >+ // we don't have a JPA project yet, so go to the db plug-in directly to get the factory >+ return JptDbPlugin.instance().getConnectionProfileFactory(); > } >- >- private List<String> buildSortedCatalogNames() { >- ConnectionProfile cp = this.getConnectionProfile(); >- if (cp == null) { >- return Collections.emptyList(); >+ >+ >+ // ********** validation ********** >+ >+ @Override >+ public IStatus validate(String propertyName) { >+ if (propertyName.equals(PLATFORM_ID)) { >+ return this.validatePlatformId(); > } >- Database db = cp.getDatabase(); >- if (db == null) { >- return Collections.emptyList(); >+ if (propertyName.equals(LIBRARY_PROVIDER_DELEGATE)) { >+ return this.getLibraryInstallDelegate().validate(); > } >- return CollectionTools.list(db.sortedCatalogIdentifiers()); >- } >- >- private Iterator<String> catalogNames() { >- String setValue = getStringProperty(USER_OVERRIDE_DEFAULT_CATALOG); >- List<String> catalogNames = this.buildSortedCatalogNames(); >- >- if (StringTools.stringIsEmpty(setValue) || catalogNames.contains(setValue)) { >- return catalogNames.iterator(); >+ if (propertyName.equals(CONNECTION)) { >+ return this.validateConnection(); > } >- return new CompositeIterator<String>(setValue, catalogNames.iterator()); >- } >- >- private List<String> buildSortedSchemaNames() { >- ConnectionProfile cp = this.getConnectionProfile(); >- if (cp == null) { >- return Collections.emptyList(); >+ if (propertyName.equals(USER_WANTS_TO_ADD_DB_DRIVER_JARS_TO_CLASSPATH) >+ || propertyName.equals(DB_DRIVER_NAME)) { >+ return this.validateDbDriverName(); > } >- Database db = cp.getDatabase(); >- if (db == null) { >- return Collections.emptyList(); >+ if (propertyName.equals(USER_WANTS_TO_OVERRIDE_DEFAULT_CATALOG) >+ || propertyName.equals(USER_OVERRIDE_DEFAULT_CATALOG)) { >+ return this.validateUserOverrideDefaultCatalog(); > } >- return CollectionTools.list(db.sortedSchemaIdentifiers()); // use identifiers? names seem OK since combo-box is read-only? >- } >- >- private Iterator<String> schemaNames() { >- String setValue = getStringProperty(USER_OVERRIDE_DEFAULT_SCHEMA); >- List<String> schemaNames = this.buildSortedSchemaNames(); >- >- if (StringTools.stringIsEmpty(setValue) || schemaNames.contains(setValue)) { >- return schemaNames.iterator(); >+ if (propertyName.equals(USER_WANTS_TO_OVERRIDE_DEFAULT_SCHEMA) >+ || propertyName.equals(USER_OVERRIDE_DEFAULT_SCHEMA)) { >+ return this.validateUserOverrideDefaultSchema(); >+ } >+ if (propertyName.equals(DISCOVER_ANNOTATED_CLASSES)) { >+ return this.validatePersistentClassManagement(); > } >- return new CompositeIterator<String>(setValue, schemaNames.iterator()); >- } >- >- private Iterator<String> driverNames() { >- String setValue = getStringProperty(DB_DRIVER_NAME); > >- return new CompositeIterator<String>(setValue, EmptyIterator.<String> instance()); >+ return super.validate(propertyName); > } > >- >- // ********** validation ********** >- >- private IStatus validatePlatformId(String platformId) { >- return StringTools.stringIsEmpty(platformId) ? >- PLATFORM_NOT_SPECIFIED_STATUS >- : >- OK_STATUS; >+ private IStatus validatePlatformId() { >+ return (this.getPlatformId() == null) ? PLATFORM_NOT_SPECIFIED_STATUS : OK_STATUS; > } > >- private IStatus validateConnectionName(String connectionName) { >- if (StringTools.stringIsEmpty(connectionName)) { >- return OK_STATUS; >- } >- ConnectionProfile connectionProfile = getConnectionProfile(); >- if (connectionProfile == null) { >- return buildErrorStatus(NLS.bind(JptCoreMessages.VALIDATE_CONNECTION_INVALID, connectionName)); >+ private IStatus validateConnection() { >+ String connectionName = this.getConnectionName(); >+ return (connectionName == null) ? OK_STATUS : this.validateNonNullConnection(connectionName); >+ } > >+ private IStatus validateNonNullConnection(String connectionName) { >+ ConnectionProfile cp = this.getConnectionProfile(connectionName); >+ if (cp == null) { >+ return buildErrorStatus(NLS.bind(JptCoreMessages.VALIDATE_CONNECTION_INVALID, connectionName)); > } >- if (! connectionProfile.isActive()) { >+ if ( ! cp.isActive()) { > return CONNECTION_NOT_CONNECTED_STATUS; > } > return OK_STATUS; > } > >+ private IStatus validateDbDriverName() { >+ return OK_STATUS; >+ } >+ > private IStatus validateUserOverrideDefaultCatalog() { >- if (getBooleanProperty(USER_WANTS_TO_OVERRIDE_DEFAULT_CATALOG)) { >- if (StringTools.stringIsEmpty(getStringProperty(USER_OVERRIDE_DEFAULT_CATALOG))) { >+ if (this.userWantsToOverrideDefaultCatalog()) { >+ if (this.getUserOverrideDefaultCatalog() == null) { > return USER_OVERRIDE_DEFAULT_CATALOG_NOT_SPECIFIED_STATUS; > } > } >@@ -572,23 +691,20 @@ > } > > private IStatus validateUserOverrideDefaultSchema() { >- if (getBooleanProperty(USER_WANTS_TO_OVERRIDE_DEFAULT_SCHEMA)) { >- if (StringTools.stringIsEmpty(getStringProperty(USER_OVERRIDE_DEFAULT_SCHEMA))) { >+ if (this.userWantsToOverrideDefaultSchema()) { >+ if (this.getUserOverrideDefaultSchema() == null) { > return USER_OVERRIDE_DEFAULT_SCHEMA_NOT_SPECIFIED_STATUS; > } > } > return OK_STATUS; > } > >- private IStatus validatePersistentClassManagement(boolean discoverAnnotatedClasses) { >+ private IStatus validatePersistentClassManagement() { >+ @SuppressWarnings("unused") boolean discoverAnnotatedClasses = this.discoverAnnotatedClasses(); > // TODO warning if "discovery" is used, but no runtime specified ?? > return OK_STATUS; > } > >- private IStatus validateDbDriverName() { >- return OK_STATUS; >- } >- > > // ********** static methods ********** > >@@ -596,9 +712,9 @@ > return buildStatus(IStatus.INFO, message); > } > >- private static IStatus buildWarningStatus(String message) { >- return buildStatus(IStatus.WARNING, message); >- } >+// private static IStatus buildWarningStatus(String message) { >+// return buildStatus(IStatus.WARNING, message); >+// } > > private static IStatus buildErrorStatus(String message) { > return buildStatus(IStatus.ERROR, message); >@@ -607,4 +723,5 @@ > private static IStatus buildStatus(int severity, String message) { > return new Status(severity, JptCorePlugin.PLUGIN_ID, message); > } >+ > } >Index: src/org/eclipse/jpt/core/internal/GenericJpaModel.java >=================================================================== >RCS file: /cvsroot/webtools/org.eclipse.jpa/components/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/GenericJpaModel.java,v >retrieving revision 1.22 >diff -u -r1.22 GenericJpaModel.java >--- src/org/eclipse/jpt/core/internal/GenericJpaModel.java 18 May 2009 21:07:30 -0000 1.22 >+++ src/org/eclipse/jpt/core/internal/GenericJpaModel.java 25 May 2009 19:27:12 -0000 >@@ -131,6 +131,7 @@ > config.setProject(project); > config.setJpaPlatform(JptCorePlugin.getJpaPlatform(project)); > config.setConnectionProfileName(JptCorePlugin.getConnectionProfileName(project)); >+ config.setUserOverrideDefaultCatalogName(JptCorePlugin.getUserOverrideDefaultCatalogName(project)); > config.setUserOverrideDefaultSchemaName(JptCorePlugin.getUserOverrideDefaultSchemaName(project)); > config.setDiscoverAnnotatedClasses(JptCorePlugin.discoverAnnotatedClasses(project)); > return config;
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 267343
:
127795
|
129817
|
137063
|
137153
|
137200