Author: dgeraskov
Date: 2010-02-01 07:41:34 -0500 (Mon, 01 Feb 2010)
New Revision: 20045
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/HibernateJpaProperties.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/PersistenceUnitProperties.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/PersistenceUnitPropertyListListener.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/basic/HibernateBasic.java
Log:
https://jira.jboss.org/jira/browse/JBIDE-5182
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/HibernateJpaProperties.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/HibernateJpaProperties.java 2010-02-01
12:27:09 UTC (rev 20044)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/HibernateJpaProperties.java 2010-02-01
12:41:34 UTC (rev 20045)
@@ -19,7 +19,6 @@
import org.eclipse.jpt.utility.internal.model.value.ItemPropertyListValueModelAdapter;
import org.eclipse.jpt.utility.internal.model.value.ListAspectAdapter;
import org.eclipse.jpt.utility.internal.model.value.SimplePropertyValueModel;
-import org.eclipse.jpt.utility.model.event.PropertyChangeEvent;
import org.eclipse.jpt.utility.model.value.ListValueModel;
import org.eclipse.jpt.utility.model.value.PropertyValueModel;
import
org.jboss.tools.hibernate.jpt.core.internal.context.basic.BasicHibernateProperties;
@@ -29,8 +28,7 @@
* @author Dmitry Geraskov
*
*/
-public class HibernateJpaProperties extends AbstractModel implements
- HibernateProperties {
+public class HibernateJpaProperties extends AbstractModel {
private PersistenceUnit persistenceUnit;
@@ -56,7 +54,7 @@
}
private ListValueModel<Property>
buildPropertyListAdapter(ListValueModel<Property> propertiesAdapter) {
- return new ItemPropertyListValueModelAdapter<Property>(propertiesAdapter,
Property.VALUE_PROPERTY);
+ return new ItemPropertyListValueModelAdapter<Property>(propertiesAdapter,
Property.VALUE_PROPERTY, Property.NAME_PROPERTY);
}
private ListValueModel<Property>
buildPropertiesAdapter(PropertyValueModel<PersistenceUnit> subjectHolder) {
@@ -94,15 +92,4 @@
return this.persistenceUnit.getJpaProject();
}
- public boolean itemIsProperty(Property item) {
- throw new UnsupportedOperationException();
- }
-
- public void propertyChanged(PropertyChangeEvent event) {
- throw new UnsupportedOperationException();
- }
-
- public String propertyIdFor(Property property) {
- throw new UnsupportedOperationException();
- }
-}
+}
\ No newline at end of file
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/PersistenceUnitProperties.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/PersistenceUnitProperties.java 2010-02-01
12:27:09 UTC (rev 20044)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/PersistenceUnitProperties.java 2010-02-01
12:41:34 UTC (rev 20045)
@@ -41,4 +41,6 @@
* Return the JPA project the PersistenceUnit belongs to.
*/
JpaProject getJpaProject();
+
+ void updateProperties();
}
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/PersistenceUnitPropertyListListener.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/PersistenceUnitPropertyListListener.java 2010-02-01
12:27:09 UTC (rev 20044)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/PersistenceUnitPropertyListListener.java 2010-02-01
12:41:34 UTC (rev 20045)
@@ -10,12 +10,7 @@
******************************************************************************/
package org.jboss.tools.hibernate.jpt.core.internal.context;
-import java.util.Iterator;
-
-import org.eclipse.jpt.core.context.persistence.PersistenceUnit.Property;
-import org.eclipse.jpt.utility.model.Model;
import org.eclipse.jpt.utility.model.event.ListChangeEvent;
-import org.eclipse.jpt.utility.model.event.PropertyChangeEvent;
import org.eclipse.jpt.utility.model.listener.ListChangeListener;
/**
@@ -31,68 +26,29 @@
this.parent = parent;
}
- // ********** Behavior **********
- protected boolean add(Property newItem, Model source) {
- if (this.model().itemIsProperty(newItem)) {
- String propertyName = this.model().propertyIdFor(newItem);
- this.model().propertyChanged(
- new PropertyChangeEvent(source, propertyName, null, newItem));
- return true;
- }
- return false;
- }
-
- protected boolean remove(Property item, Model source) {
- if (this.model().itemIsProperty(item)) {
- String propertyName = this.model().propertyIdFor(item);
- this.model().propertyChanged(
- new PropertyChangeEvent(source, propertyName, item, null)); // oldItem is the removed
property
- return true;
- }
- return false;
- }
-
- // replace
- protected Property set(Property newItem, Model source) {
- if (this.model().itemIsProperty(newItem)) {
- String propertyName = this.model().propertyIdFor(newItem);
- this.model().propertyChanged(
- new PropertyChangeEvent(source, propertyName, null, newItem)); // oldItem unknown
- return newItem;
- }
- return null;
- }
-
// ********** ListChangeListener implementation **********
public void itemsAdded(ListChangeEvent e) {
- for (Iterator<Property> stream = this.items(e); stream.hasNext();) {
- this.add(stream.next(), e.getSource());
- }
+ model().updateProperties();
}
public void itemsRemoved(ListChangeEvent e) {
- for (Iterator<Property> stream = this.items(e); stream.hasNext();) {
- this.remove(stream.next(), e.getSource());
- }
+ model().updateProperties();
}
public void itemsReplaced(ListChangeEvent e) {
- // ItemAspectListValueModelAdapter(270) does not provide old value
- for (Iterator<Property> newStream = this.items(e); newStream.hasNext();) {
- this.set(newStream.next(), e.getSource());
- }
+ model().updateProperties();
}
public void itemsMoved(ListChangeEvent e) {
- throw new UnsupportedOperationException("source: " + e.getSource() + " -
aspect: " + e.getAspectName()); //$NON-NLS-1$//$NON-NLS-2$
+ model().updateProperties();
}
public void listCleared(ListChangeEvent e) {
- throw new UnsupportedOperationException("source: " + e.getSource() + " -
aspect: " + e.getAspectName()); //$NON-NLS-1$//$NON-NLS-2$
+ model().updateProperties();
}
public void listChanged(ListChangeEvent e) {
- throw new UnsupportedOperationException("source: " + e.getSource() + " -
aspect: " + e.getAspectName()); //$NON-NLS-1$//$NON-NLS-2$
+ model().updateProperties();
}
// ********** internal methods **********
@@ -100,9 +56,4 @@
return this.parent;
}
- @SuppressWarnings("unchecked")
- private Iterator<Property> items(ListChangeEvent event) {
- return (Iterator<Property>) event.items();
- }
-
-}
+}
\ No newline at end of file
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/basic/HibernateBasic.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/basic/HibernateBasic.java 2010-02-01
12:27:09 UTC (rev 20044)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/basic/HibernateBasic.java 2010-02-01
12:41:34 UTC (rev 20045)
@@ -125,6 +125,7 @@
}
public void setConfigurationFile(String newConfigFile) {
+ if (!valueWasChanged(configFile, newConfigFile)) return;
String old = this.configFile;
this.configFile = newConfigFile;
this.putProperty(CONFIG_FILE_PROPERTY, newConfigFile);
@@ -148,6 +149,7 @@
}
public void setDialect(String newDialect) {
+ if (!valueWasChanged(dialect, newDialect)) return;
String old = this.dialect;
this.dialect = newDialect;
this.putProperty(DIALECT_PROPERTY, newDialect);
@@ -171,6 +173,7 @@
}
public void setDriver(String newDriver) {
+ if (!valueWasChanged(driver, newDriver)) return;
String old = this.driver;
this.driver = newDriver;
this.putProperty(DRIVER_PROPERTY, newDriver);
@@ -194,6 +197,7 @@
}
public void setUrl(String newUrl) {
+ if (!valueWasChanged(url, newUrl)) return;
String old = this.url;
this.url = newUrl;
this.putProperty(URL_PROPERTY, newUrl);
@@ -217,6 +221,7 @@
}
public void setSchemaDefault(String newSchemaDefault) {
+ if (!valueWasChanged(schemaDefault, newSchemaDefault)) return;
String old = this.schemaDefault;
this.schemaDefault = newSchemaDefault;
this.putProperty(SCHEMA_DEFAULT_PROPERTY, newSchemaDefault);
@@ -240,6 +245,7 @@
}
public void setCatalogDefault(String newCatalogDefault) {
+ if (!valueWasChanged(catalogDefault, newCatalogDefault)) return;
String old = this.catalogDefault;
this.catalogDefault = newCatalogDefault;
this.putProperty(CATALOG_DEFAULT_PROPERTY, newCatalogDefault);
@@ -263,6 +269,7 @@
}
public void setUsername(String newUsername) {
+ if (!valueWasChanged(username, newUsername)) return;
String old = this.username;
this.username = newUsername;
this.putProperty(USERNAME_PROPERTY, newUsername);
@@ -286,6 +293,7 @@
}
public void setPassword(String newPassword) {
+ if (!valueWasChanged(password, newPassword)) return;
String old = this.password;
this.password = newPassword;
this.putProperty(PASSWORD_PROPERTY, newPassword);
@@ -299,4 +307,20 @@
this.firePropertyChanged(event.getAspectName(), old, newPassword);
}
+ public void updateProperties() {
+ setConfigurationFile(this.getStringValue(HIBERNATE_CONFIG_FILE));
+ setDialect(this.getStringValue(HIBERNATE_DIALECT));
+ setDriver(this.getStringValue(HIBERNATE_DRIVER));
+ setUrl(this.getStringValue(HIBERNATE_URL));
+ setSchemaDefault(this.getStringValue(HIBERNATE_SCHEMA_DEFAULT));
+ setCatalogDefault(this.getStringValue(HIBERNATE_CATALOG));
+ setUsername(this.getStringValue(HIBERNATE_USERNAME));
+ setPassword(this.getStringValue(HIBERNATE_PASSWORD));
+ }
+
+ private boolean valueWasChanged(String oldValue, String newValue){
+ return oldValue == null ? newValue != null
+ : !oldValue.equals(newValue);
+ }
+
}