aboutsummaryrefslogtreecommitdiffstats
path: root/compatibility-server/src/main/java
diff options
context:
space:
mode:
authorTeemu Suo-Anttila <tsuoanttila@users.noreply.github.com>2017-02-22 11:35:19 +0200
committerPekka Hyvönen <pekka@vaadin.com>2017-02-22 11:35:19 +0200
commitca1bfa7511e35fad802271604158afd7be6531d0 (patch)
treef0c68b320cff5051a4a8dc4d5827f55276b1d73c /compatibility-server/src/main/java
parente76d2e8953e8bfb80018019dc5497e7760313403 (diff)
downloadvaadin-framework-ca1bfa7511e35fad802271604158afd7be6531d0.tar.gz
vaadin-framework-ca1bfa7511e35fad802271604158afd7be6531d0.zip
Pick changes from 7.7.7 (#8577)
* Fix java packaging order (#106) Closes vaadin/archetypes#113 * Use proper UTF-8 encoding for Content-Disposition filenames (#19527) (#6607) * Enable changing the backing bean for BeanItem (#4302) (#77) When storing a bean to the database, you typically get a new and updated bean instance back. By allowing to change the bean instance, we make it possible to just update the single BeanItem instance which can be used in many places. * Make AtmospherePushConnection methods public (#7973) There is no sensible way to use a custom version of APC, so protected access does not help in any way to access the underlying resource and/or connected UI. * Use correct indexes in multiselect checkboxes after removing rows (#8072) Fixes #8011 * Fix removal of hidden Grid columns (#8071) Fixes #8018 * Call error handler for exceptions in UI.init() (#8055) Fixes #4995 * Render font icon correctly on the 'more' menu item (#8126) * Render font icon correctly on the 'more' menu item Fixes #8125 * Reopen Grid details on attach, fixes #8015 (#8074) Fixes #8015 * Fix broken Grid tests after picking changes from 7.7.7 Removed duplicate setDetailsVisible calls from onDetach * Correctly detach components in merged cells when a static row is removed (#8142) Fixes #8140
Diffstat (limited to 'compatibility-server/src/main/java')
-rw-r--r--compatibility-server/src/main/java/com/vaadin/v7/data/util/BeanItem.java45
-rw-r--r--compatibility-server/src/main/java/com/vaadin/v7/data/util/MethodProperty.java31
-rw-r--r--compatibility-server/src/main/java/com/vaadin/v7/data/util/NestedMethodProperty.java34
-rw-r--r--compatibility-server/src/main/java/com/vaadin/v7/ui/Grid.java3
4 files changed, 111 insertions, 2 deletions
diff --git a/compatibility-server/src/main/java/com/vaadin/v7/data/util/BeanItem.java b/compatibility-server/src/main/java/com/vaadin/v7/data/util/BeanItem.java
index 8bba865ffc..a286cdc3b2 100644
--- a/compatibility-server/src/main/java/com/vaadin/v7/data/util/BeanItem.java
+++ b/compatibility-server/src/main/java/com/vaadin/v7/data/util/BeanItem.java
@@ -27,6 +27,7 @@ import java.util.Map;
import java.util.Set;
import com.vaadin.data.util.BeanUtil;
+import com.vaadin.v7.data.Property;
/**
* A wrapper class for adding the Item interface to any Java Bean.
@@ -41,7 +42,7 @@ public class BeanItem<BT> extends PropertysetItem {
/**
* The bean which this Item is based on.
*/
- private final BT bean;
+ private BT bean;
/**
* <p>
@@ -264,4 +265,46 @@ public class BeanItem<BT> extends PropertysetItem {
return bean;
}
+ /**
+ * Changes the Java Bean this item is based on.
+ * <p>
+ * This will cause any existing properties to be re-mapped to the new bean.
+ * Any added custom properties which are not of type {@link MethodProperty}
+ * or {@link NestedMethodProperty} will not be updated to reflect the change
+ * of bean.
+ * <p>
+ * Changing the bean will fire value change events for all properties of
+ * type {@link MethodProperty} or {@link NestedMethodProperty}.
+ *
+ * @param bean
+ * The new bean to use for this item, not <code>null</code>
+ */
+ public void setBean(BT bean) {
+ if (bean == null) {
+ throw new IllegalArgumentException("Bean cannot be null");
+ }
+
+ if (getBean().getClass() != bean.getClass()) {
+ throw new IllegalArgumentException(
+ "The new bean class " + bean.getClass().getName()
+ + " does not match the old bean class "
+ + getBean().getClass());
+ }
+
+ // Remap properties
+ for (Object propertyId : getItemPropertyIds()) {
+ Property p = getItemProperty(propertyId);
+ if (p instanceof MethodProperty) {
+ MethodProperty mp = (MethodProperty) p;
+ assert (mp.getInstance() == getBean());
+ mp.setInstance(bean);
+ } else if (p instanceof NestedMethodProperty) {
+ NestedMethodProperty nmp = (NestedMethodProperty) p;
+ assert (nmp.getInstance() == getBean());
+ nmp.setInstance(bean);
+ }
+ }
+
+ this.bean = bean;
+ }
}
diff --git a/compatibility-server/src/main/java/com/vaadin/v7/data/util/MethodProperty.java b/compatibility-server/src/main/java/com/vaadin/v7/data/util/MethodProperty.java
index ba5edbb146..e3651d0272 100644
--- a/compatibility-server/src/main/java/com/vaadin/v7/data/util/MethodProperty.java
+++ b/compatibility-server/src/main/java/com/vaadin/v7/data/util/MethodProperty.java
@@ -769,6 +769,37 @@ public class MethodProperty<T> extends AbstractProperty<T> {
super.fireValueChange();
}
+ /**
+ * The instance used by this property
+ *
+ * @return the instance used for fetching the property value
+ */
+ public Object getInstance() {
+ return instance;
+ }
+
+ /**
+ * Sets the instance used by this property.
+ * <p>
+ * The new instance must be of the same type as the old instance
+ * <p>
+ * To be consistent with {@link #setValue(Object)}, this method will fire a
+ * value change event even if the value stays the same
+ *
+ * @param instance
+ * the instance to use
+ */
+ public void setInstance(Object instance) {
+ if (this.instance.getClass() != instance.getClass()) {
+ throw new IllegalArgumentException("The new instance is of type "
+ + instance.getClass().getName()
+ + " which does not match the old instance type "
+ + this.instance.getClass().getName());
+ }
+ this.instance = instance;
+ fireValueChange();
+ }
+
private static final Logger getLogger() {
return Logger.getLogger(MethodProperty.class.getName());
}
diff --git a/compatibility-server/src/main/java/com/vaadin/v7/data/util/NestedMethodProperty.java b/compatibility-server/src/main/java/com/vaadin/v7/data/util/NestedMethodProperty.java
index 3f9236c4ac..ab23d07551 100644
--- a/compatibility-server/src/main/java/com/vaadin/v7/data/util/NestedMethodProperty.java
+++ b/compatibility-server/src/main/java/com/vaadin/v7/data/util/NestedMethodProperty.java
@@ -193,9 +193,10 @@ public class NestedMethodProperty<T> extends AbstractProperty<T> {
/**
* Gets the value stored in the Property. The value is resolved by calling
- * the specified getter method with the argument specified at instantiation.
+ * the specified getter methods on the current instance:
*
* @return the value of the Property
+ * @see #getInstance()
*/
@Override
public T getValue() {
@@ -267,4 +268,35 @@ public class NestedMethodProperty<T> extends AbstractProperty<T> {
return Collections.unmodifiableList(getMethods);
}
+ /**
+ * The instance used by this property
+ *
+ * @return the instance used for fetching the property value
+ */
+ public Object getInstance() {
+ return instance;
+ }
+
+ /**
+ * Sets the instance used by this property.
+ * <p>
+ * The new instance must be of the same type as the old instance
+ * <p>
+ * To be consistent with {@link #setValue(Object)}, this method will fire a
+ * value change event even if the value stays the same
+ *
+ * @param instance
+ * the instance to use
+ */
+ public void setInstance(Object instance) {
+ if (this.instance.getClass() != instance.getClass()) {
+ throw new IllegalArgumentException("The new instance is of type "
+ + instance.getClass().getName()
+ + " which does not match the old instance type "
+ + this.instance.getClass().getName());
+ }
+ this.instance = instance;
+ fireValueChange();
+ }
+
}
diff --git a/compatibility-server/src/main/java/com/vaadin/v7/ui/Grid.java b/compatibility-server/src/main/java/com/vaadin/v7/ui/Grid.java
index cabba91d31..ee9b968c00 100644
--- a/compatibility-server/src/main/java/com/vaadin/v7/ui/Grid.java
+++ b/compatibility-server/src/main/java/com/vaadin/v7/ui/Grid.java
@@ -2556,6 +2556,9 @@ public class Grid extends AbstractComponent
for (CELLTYPE cell : cells.values()) {
cell.detach();
}
+ for (CELLTYPE cell : cellGroups.values()) {
+ cell.detach();
+ }
}
}