Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpfullbright2008-04-30 19:36:53 +0000
committerpfullbright2008-04-30 19:36:53 +0000
commit34d3d19b1a4c80a76d8ce43bbde0bc61e3900c8b (patch)
treee6481174157c2cac4050782b801e6b9f0935e599
parent76404e5cfd758a9a77d1600dd6ee81fbd3b6d7a5 (diff)
downloadwebtools.dali-34d3d19b1a4c80a76d8ce43bbde0bc61e3900c8b.tar.gz
webtools.dali-34d3d19b1a4c80a76d8ce43bbde0bc61e3900c8b.tar.xz
webtools.dali-34d3d19b1a4c80a76d8ce43bbde0bc61e3900c8b.zip
[Bugs 228767, 228769, 228771] - JPA default schema controls
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/facet/JpaFacetDataModelProperties.java5
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/facet/JpaFacetDataModelProvider.java78
-rw-r--r--jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/properties/JpaProjectPropertiesPage.java58
-rw-r--r--jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/JpaFacetWizardPage.java60
4 files changed, 87 insertions, 114 deletions
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/facet/JpaFacetDataModelProperties.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/facet/JpaFacetDataModelProperties.java
index 75fd3521e0..6f7ce74c54 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/facet/JpaFacetDataModelProperties.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/facet/JpaFacetDataModelProperties.java
@@ -24,6 +24,11 @@ public interface JpaFacetDataModelProperties extends IDataModelProperties
public static final String CONNECTION = "JpaFacetDataModelProperties.CONNECTION";
/**
+ * Required, type Boolean, identifies whether database connection is active
+ */
+ public static final String CONNECTION_ACTIVE = "JpaFacetDataModelProperties.CONNECTION_ACTIVE";
+
+ /**
* Required, type Boolean, identifies if the user wishes to override default schema name
*/
public static final String USER_WANTS_TO_OVERRIDE_DEFAULT_SCHEMA =
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/facet/JpaFacetDataModelProvider.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/facet/JpaFacetDataModelProvider.java
index 2881372268..4dd9fa4e87 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/facet/JpaFacetDataModelProvider.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/facet/JpaFacetDataModelProvider.java
@@ -9,6 +9,8 @@
******************************************************************************/
package org.eclipse.jpt.core.internal.facet;
+import java.util.Iterator;
+import java.util.List;
import java.util.Set;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
@@ -20,6 +22,8 @@ import org.eclipse.jpt.db.JptDbPlugin;
import org.eclipse.jpt.db.Schema;
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.TransformationIterator;
import org.eclipse.wst.common.componentcore.datamodel.FacetInstallDataModelProvider;
import org.eclipse.wst.common.componentcore.internal.util.IModuleConstants;
import org.eclipse.wst.common.frameworks.datamodel.DataModelPropertyDescriptor;
@@ -71,6 +75,7 @@ public class JpaFacetDataModelProvider
Set<String> propertyNames = super.getPropertyNames();
propertyNames.add(PLATFORM_ID);
propertyNames.add(CONNECTION);
+ propertyNames.add(CONNECTION_ACTIVE);
propertyNames.add(USER_WANTS_TO_OVERRIDE_DEFAULT_SCHEMA);
propertyNames.add(USER_OVERRIDE_DEFAULT_SCHEMA);
propertyNames.add(RUNTIME);
@@ -80,7 +85,15 @@ public class JpaFacetDataModelProvider
propertyNames.add(CREATE_ORM_XML);
return propertyNames;
}
-
+
+ @Override
+ public boolean isPropertyEnabled(String propertyName) {
+ if (propertyName.equals(USER_OVERRIDE_DEFAULT_SCHEMA)) {
+ return getBooleanProperty(USER_WANTS_TO_OVERRIDE_DEFAULT_SCHEMA);
+ }
+ return super.isPropertyEnabled(propertyName);
+ }
+
@Override
public Object getDefaultProperty(String propertyName) {
if (propertyName.equals(FACET_ID)) {
@@ -92,6 +105,9 @@ public class JpaFacetDataModelProvider
if (propertyName.equals(CONNECTION)) {
return "";
}
+ if (propertyName.equals(CONNECTION_ACTIVE)) {
+ return connectionIsActive();
+ }
if (propertyName.equals(USER_WANTS_TO_OVERRIDE_DEFAULT_SCHEMA)) {
return Boolean.FALSE;
}
@@ -115,7 +131,7 @@ public class JpaFacetDataModelProvider
}
return super.getDefaultProperty(propertyName);
}
-
+
@Override
public boolean propertySet(String propertyName, Object propertyValue) {
boolean ok = super.propertySet(propertyName, propertyValue);
@@ -123,11 +139,36 @@ public class JpaFacetDataModelProvider
this.model.notifyPropertyChange(USE_SERVER_JPA_IMPLEMENTATION, IDataModel.DEFAULT_CHG);
this.model.notifyPropertyChange(DISCOVER_ANNOTATED_CLASSES, IDataModel.DEFAULT_CHG);
}
+ if (propertyName.equals(CONNECTION)) {
+ this.model.setBooleanProperty(CONNECTION_ACTIVE, connectionIsActive());
+ 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)) {
+ this.model.notifyPropertyChange(USER_OVERRIDE_DEFAULT_SCHEMA, IDataModel.DEFAULT_CHG);
+ this.model.notifyPropertyChange(USER_OVERRIDE_DEFAULT_SCHEMA, IDataModel.VALID_VALUES_CHG);
+ }
+ if (propertyName.equals(USER_WANTS_TO_OVERRIDE_DEFAULT_SCHEMA)) {
+ this.model.notifyPropertyChange(USER_OVERRIDE_DEFAULT_SCHEMA, IDataModel.ENABLE_CHG);
+ if (! (Boolean) propertyValue) {
+ this.model.setProperty(USER_OVERRIDE_DEFAULT_SCHEMA, null);
+ }
+ }
return ok;
}
@Override
public DataModelPropertyDescriptor[] getValidPropertyDescriptors(String propertyName) {
+ if (propertyName.equals(USER_OVERRIDE_DEFAULT_SCHEMA)) {
+ return CollectionTools.array(
+ new TransformationIterator<String, DataModelPropertyDescriptor>(schemas()) {
+ @Override
+ protected DataModelPropertyDescriptor transform(String next) {
+ return new DataModelPropertyDescriptor(next);
+ }
+ },
+ new DataModelPropertyDescriptor[0]);
+ }
if (propertyName.equals(JPA_LIBRARY)) {
String[] libraries = CollectionTools.sort(JavaCore.getUserLibraryNames());
DataModelPropertyDescriptor[] descriptors = new DataModelPropertyDescriptor[libraries.length + 1];
@@ -173,13 +214,38 @@ public class JpaFacetDataModelProvider
return (runtime == null) ? false : runtime.supports(ejb30);
}
- private String getDefaultSchemaName() {
+ private ConnectionProfile getConnection() {
String connectionName = getStringProperty(CONNECTION);
- ConnectionProfile connection =
- JptDbPlugin.instance().getConnectionProfileRepository().connectionProfileNamed(connectionName);
- Schema defaultSchema = connection.getDefaultSchema();
+ return JptDbPlugin.instance().getConnectionProfileRepository().connectionProfileNamed(connectionName);
+ }
+
+ private boolean connectionIsActive() {
+ return getConnection().isActive();
+ }
+
+ private String getDefaultSchemaName() {
+ Schema defaultSchema = getConnection().getDefaultSchema();
return (defaultSchema == null) ? null : defaultSchema.getName();
}
+
+ private Iterator<String> schemas() {
+ String setValue = getStringProperty(USER_OVERRIDE_DEFAULT_SCHEMA);
+
+ List<String> schemas = CollectionTools.sort(CollectionTools.list(
+ new TransformationIterator<Schema, String>(getConnection().getDatabase().schemata()) {
+ @Override
+ protected String transform(Schema next) {
+ return next.getName();
+ }
+ }));
+
+ if (! StringTools.stringIsEmpty(setValue) && ! schemas.contains(setValue)) {
+ return new CompositeIterator<String>(setValue, schemas.iterator());
+ }
+ else {
+ return schemas.iterator();
+ }
+ }
// ********** validation **********
diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/properties/JpaProjectPropertiesPage.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/properties/JpaProjectPropertiesPage.java
index f85e3ead6b..43a95b2562 100644
--- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/properties/JpaProjectPropertiesPage.java
+++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/properties/JpaProjectPropertiesPage.java
@@ -33,7 +33,6 @@ import org.eclipse.jpt.core.internal.facet.JpaFacetDataModelProvider;
import org.eclipse.jpt.core.internal.platform.JpaPlatformRegistry;
import org.eclipse.jpt.db.ConnectionProfile;
import org.eclipse.jpt.db.JptDbPlugin;
-import org.eclipse.jpt.db.Schema;
import org.eclipse.jpt.db.ui.internal.DTPUiTools;
import org.eclipse.jpt.ui.JptUiPlugin;
import org.eclipse.jpt.ui.internal.JpaHelpContextIds;
@@ -392,37 +391,9 @@ public class JpaProjectPropertiesPage
defaultSchemaLabel.setLayoutData(gd);
defaultSchemaCombo = createCombo(group, 1, true);
- defaultSchemaCombo.addSelectionListener(
- new SelectionListener() {
- public void widgetDefaultSelected(SelectionEvent e) {
- widgetSelected(e);
- }
-
- public void widgetSelected(SelectionEvent e) {
- String schema = defaultSchemaCombo.getText();
- model.setProperty(USER_OVERRIDE_DEFAULT_SCHEMA, schema);
- }
- }
- );
- fillSchemas();
-
- model.addListener(
- new IDataModelListener() {
- public void propertyChanged(DataModelEvent event) {
- if (event.getPropertyName().equals(CONNECTION)) {
- fillSchemas();
- }
- else if (event.getPropertyName().equals(USER_WANTS_TO_OVERRIDE_DEFAULT_SCHEMA)) {
- boolean enabled = (Boolean) event.getProperty();
- defaultSchemaLabel.setEnabled(enabled);
- defaultSchemaCombo.setEnabled(enabled);
- fillSchemas();
- }
- else if (event.getPropertyName().equals(USER_OVERRIDE_DEFAULT_SCHEMA)) {
- defaultSchemaCombo.select(defaultSchemaCombo.indexOf((String) event.getProperty()));
- }
- }
- });
+ synchHelper.synchCombo(
+ defaultSchemaCombo, USER_OVERRIDE_DEFAULT_SCHEMA,
+ new Control[] {defaultSchemaLabel});
performDefaults();
}
@@ -450,7 +421,7 @@ public class JpaProjectPropertiesPage
ConnectionProfile connection = getConnectionProfile();
connection.connect();
updateConnectLink();
- fillSchemas();
+ model.setBooleanProperty(CONNECTION_ACTIVE, connection.isActive());
return;
}
@@ -459,27 +430,6 @@ public class JpaProjectPropertiesPage
connectLink.setEnabled(! connectionProfile.isNull() && ! connectionProfile.isConnected());
}
- private void fillSchemas() {
- for (Iterator<String> stream = CollectionTools.sort(getConnectionProfile().getDatabase().schemaNames()); stream.hasNext(); ) {
- defaultSchemaCombo.add(stream.next());
- }
- String userOverrideDefaultSchema = model.getStringProperty(USER_OVERRIDE_DEFAULT_SCHEMA);
- if (userOverrideDefaultSchema != null && defaultSchemaCombo.indexOf(userOverrideDefaultSchema) < 0) {
- defaultSchemaCombo.add(userOverrideDefaultSchema);
- }
- if (! model.getBooleanProperty(USER_WANTS_TO_OVERRIDE_DEFAULT_SCHEMA)) {
- Schema defaultSchema = getConnectionProfile().getDefaultSchema();
- String defaultSchemaName = (defaultSchema == null) ? null : defaultSchema.getName();
- int defaultSchemaIndex = (defaultSchemaName == null) ? -1 : defaultSchemaCombo.indexOf(defaultSchemaName);
- if (defaultSchemaIndex >= 0) {
- defaultSchemaCombo.select(defaultSchemaIndex);
- }
- else {
- defaultSchemaCombo.deselectAll();
- }
- }
- }
-
private ConnectionProfile getConnectionProfile() {
return JptDbPlugin.instance().getConnectionProfileRepository().connectionProfileNamed(model.getStringProperty(CONNECTION));
}
diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/JpaFacetWizardPage.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/JpaFacetWizardPage.java
index f60db855f8..1dbee9ee18 100644
--- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/JpaFacetWizardPage.java
+++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/JpaFacetWizardPage.java
@@ -26,7 +26,6 @@ import org.eclipse.jpt.core.internal.facet.JpaFacetDataModelProperties;
import org.eclipse.jpt.core.internal.platform.JpaPlatformRegistry;
import org.eclipse.jpt.db.ConnectionProfile;
import org.eclipse.jpt.db.JptDbPlugin;
-import org.eclipse.jpt.db.Schema;
import org.eclipse.jpt.db.ui.internal.DTPUiTools;
import org.eclipse.jpt.ui.JptUiPlugin;
import org.eclipse.jpt.ui.internal.JpaHelpContextIds;
@@ -251,7 +250,7 @@ public class JpaFacetWizardPage extends DataModelFacetInstallPage
}
model.setProperty(CONNECTION, connection);
}
-
+
public void widgetDefaultSelected(SelectionEvent e) {
widgetSelected(e);
}
@@ -299,48 +298,18 @@ public class JpaFacetWizardPage extends DataModelFacetInstallPage
overrideDefaultSchemaButton = createButton(group, 3, JptUiMessages.JpaFacetWizardPage_overrideDefaultSchemaLabel, SWT.CHECK);
overrideDefaultSchemaButton.setSelection(false);
- synchHelper.synchCheckbox(overrideDefaultSchemaButton, USER_WANTS_TO_OVERRIDE_DEFAULT_SCHEMA, new Control[0]);
+ synchHelper.synchCheckbox(overrideDefaultSchemaButton, USER_WANTS_TO_OVERRIDE_DEFAULT_SCHEMA, null);
defaultSchemaLabel = new Label(group, SWT.LEFT);
defaultSchemaLabel.setText(JptUiMessages.JpaFacetWizardPage_defaultSchemaLabel);
GridData gd = new GridData();
gd.horizontalSpan = 1;
defaultSchemaLabel.setLayoutData(gd);
- defaultSchemaLabel.setEnabled(false);
defaultSchemaCombo = createCombo(group, 1, true);
- defaultSchemaCombo.setEnabled(false);
- defaultSchemaCombo.addSelectionListener(
- new SelectionListener() {
- public void widgetDefaultSelected(SelectionEvent e) {
- widgetSelected(e);
- }
-
- public void widgetSelected(SelectionEvent e) {
- String schema = defaultSchemaCombo.getText();
- model.setProperty(USER_OVERRIDE_DEFAULT_SCHEMA, schema);
- }
- }
- );
- fillSchemas();
-
- model.addListener(
- new IDataModelListener() {
- public void propertyChanged(DataModelEvent event) {
- if (event.getPropertyName().equals(CONNECTION)) {
- fillSchemas();
- }
- else if (event.getPropertyName().equals(USER_WANTS_TO_OVERRIDE_DEFAULT_SCHEMA)) {
- boolean enabled = (Boolean) event.getProperty();
- defaultSchemaLabel.setEnabled(enabled);
- defaultSchemaCombo.setEnabled(enabled);
- fillSchemas();
- }
- else if (event.getPropertyName().equals(USER_OVERRIDE_DEFAULT_SCHEMA)) {
- defaultSchemaCombo.select(defaultSchemaCombo.indexOf((String) event.getProperty()));
- }
- }
- });
+ synchHelper.synchCombo(
+ defaultSchemaCombo, USER_OVERRIDE_DEFAULT_SCHEMA,
+ new Control[] {defaultSchemaLabel});
}
private void fillConnections() {
@@ -365,8 +334,8 @@ public class JpaFacetWizardPage extends DataModelFacetInstallPage
private void openConnectionProfile() {
ConnectionProfile connection = getConnectionProfile();
connection.connect();
+ model.setBooleanProperty(CONNECTION_ACTIVE, connection.isActive());
updateConnectLink();
- fillSchemas();
return;
}
@@ -375,23 +344,6 @@ public class JpaFacetWizardPage extends DataModelFacetInstallPage
connectLink.setEnabled(! connectionProfile.isNull() && ! connectionProfile.isConnected());
}
- private void fillSchemas() {
- for (Iterator<String> stream = CollectionTools.sort(getConnectionProfile().getDatabase().schemaNames()); stream.hasNext(); ) {
- defaultSchemaCombo.add(stream.next());
- }
- if (! model.getBooleanProperty(USER_WANTS_TO_OVERRIDE_DEFAULT_SCHEMA)) {
- Schema defaultSchema = getConnectionProfile().getDefaultSchema();
- String defaultSchemaName = (defaultSchema == null) ? null : defaultSchema.getName();
- int defaultSchemaIndex = (defaultSchemaName == null) ? -1 : defaultSchemaCombo.indexOf(defaultSchemaName);
- if (defaultSchemaIndex >= 0) {
- defaultSchemaCombo.select(defaultSchemaIndex);
- }
- else {
- defaultSchemaCombo.deselectAll();
- }
- }
- }
-
private ConnectionProfile getConnectionProfile() {
return JptDbPlugin.instance().getConnectionProfileRepository().connectionProfileNamed(model.getStringProperty(CONNECTION));
}

Back to the top