aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoonas Lehtinen <joonas.lehtinen@itmill.com>2007-06-27 14:02:19 +0000
committerJoonas Lehtinen <joonas.lehtinen@itmill.com>2007-06-27 14:02:19 +0000
commit02e516142aead7fa840bc083bcc0cfd31b73367d (patch)
treecf444c3633fc6440a87ebb0117e9385d4b416371
parentb34597f23af0c2e2c536bafdb2a977c256d77bf5 (diff)
downloadvaadin-framework-02e516142aead7fa840bc083bcc0cfd31b73367d.tar.gz
vaadin-framework-02e516142aead7fa840bc083bcc0cfd31b73367d.zip
Experimental patch to block sending back variables that are just updated. Now only supportes textfield, tree and select.
svn changeset:1795/svn branch:trunk
-rw-r--r--src/com/itmill/toolkit/ui/AbstractField.java31
-rw-r--r--src/com/itmill/toolkit/ui/Select.java35
-rw-r--r--src/com/itmill/toolkit/ui/TextField.java2
-rw-r--r--src/com/itmill/toolkit/ui/Tree.java8
4 files changed, 57 insertions, 19 deletions
diff --git a/src/com/itmill/toolkit/ui/AbstractField.java b/src/com/itmill/toolkit/ui/AbstractField.java
index 2609cecc68..1cf7b69ac4 100644
--- a/src/com/itmill/toolkit/ui/AbstractField.java
+++ b/src/com/itmill/toolkit/ui/AbstractField.java
@@ -290,7 +290,7 @@ public abstract class AbstractField extends AbstractComponent implements Field,
if ((newValue == null && value != null)
|| (newValue != null && !newValue.equals(value))) {
setInternalValue(newValue);
- fireValueChange();
+ fireValueChange(false);
}
// If the value did not change, but the modification status did
@@ -351,7 +351,7 @@ public abstract class AbstractField extends AbstractComponent implements Field,
readTroughMode = readTrough;
if (!isModified() && readTroughMode && dataSource != null) {
setInternalValue(dataSource.getValue());
- fireValueChange();
+ fireValueChange(false);
}
}
@@ -387,7 +387,7 @@ public abstract class AbstractField extends AbstractComponent implements Field,
if ((newValue == null && value != null)
|| (newValue != null && !newValue.equals(value))) {
setInternalValue(newValue);
- fireValueChange();
+ fireValueChange(false);
}
return newValue;
@@ -403,6 +403,20 @@ public abstract class AbstractField extends AbstractComponent implements Field,
*/
public void setValue(Object newValue) throws Property.ReadOnlyException,
Property.ConversionException {
+ setValue(newValue, false);
+ }
+
+ /**
+ * Sets the value of the field.
+ *
+ * @param newValue
+ * the New value of the field.
+ * @param repaintIsNotNeeded True iff caller is sure that repaint is not needed.
+ * @throws Property.ReadOnlyException
+ * @throws Property.ConversionException
+ */
+ protected void setValue(Object newValue, boolean repaintIsNotNeeded) throws Property.ReadOnlyException,
+ Property.ConversionException {
if ((newValue == null && value != null)
|| (newValue != null && !newValue.equals(value))) {
@@ -453,7 +467,7 @@ public abstract class AbstractField extends AbstractComponent implements Field,
}
// Fires the value change
- fireValueChange();
+ fireValueChange(repaintIsNotNeeded);
}
}
@@ -534,7 +548,7 @@ public abstract class AbstractField extends AbstractComponent implements Field,
// Fires value change if the value has changed
if ((value != oldValue)
&& ((value != null && !value.equals(oldValue)) || value == null))
- fireValueChange();
+ fireValueChange(false);
}
/* Validation ****************************************************** */
@@ -735,9 +749,10 @@ public abstract class AbstractField extends AbstractComponent implements Field,
* Emits the value change event. The value contained in the field is
* validated before the event is created.
*/
- protected void fireValueChange() {
+ protected void fireValueChange(boolean repaintIsNotNeeded) {
fireEvent(new AbstractField.ValueChangeEvent(this));
- requestRepaint();
+ if (!repaintIsNotNeeded)
+ requestRepaint();
}
/* Read-only status change events *************************************** */
@@ -831,7 +846,7 @@ public abstract class AbstractField extends AbstractComponent implements Field,
*/
public void valueChange(Property.ValueChangeEvent event) {
if (isReadThrough() || !isModified())
- fireValueChange();
+ fireValueChange(false);
}
/**
diff --git a/src/com/itmill/toolkit/ui/Select.java b/src/com/itmill/toolkit/ui/Select.java
index b986e84e08..88120ca810 100644
--- a/src/com/itmill/toolkit/ui/Select.java
+++ b/src/com/itmill/toolkit/ui/Select.java
@@ -406,6 +406,8 @@ public class Select extends AbstractField implements Container,
// Multiselect mode
if (isMultiSelect()) {
+ // TODO Optimize by adding repaintNotNeeded whan applicaple
+
// Converts the key-array to id-set
LinkedList s = new LinkedList();
for (int i = 0; i < ka.length; i++) {
@@ -440,15 +442,15 @@ public class Select extends AbstractField implements Container,
Object current = getValue();
Collection visible = getVisibleItemIds();
if (visible != null && visible.contains(current))
- setValue(null);
+ setValue(null, true);
} else {
Object id = itemIdMapper.get(ka[0]);
if (id != null && id.equals(getNullSelectionItemId()))
- setValue(null);
+ setValue(null, true);
else if (itemIdMapper.isNewIdKey(ka[0]))
setValue(newitem);
else
- setValue(id);
+ setValue(id, true);
}
}
}
@@ -534,14 +536,33 @@ public class Select extends AbstractField implements Container,
*/
public void setValue(Object newValue) throws Property.ReadOnlyException,
Property.ConversionException {
+ setValue(newValue, false);
+ }
+
+ /**
+ * Sets the visible value of the property.
+ *
+ * <p>
+ * The value of the select is the selected item id. If the select is in
+ * multiselect-mode, the value is a set of selected item keys. In
+ * multiselect mode all collections of id:s can be assigned.
+ * </p>
+ *
+ * @param newValue
+ * the New selected item or collection of selected items.
+ * @param repaintIsNotNeeded True iff caller is sure that repaint is not needed.
+ * @see com.itmill.toolkit.ui.AbstractField#setValue(java.lang.Object, java.lang.Boolean)
+ */
+ protected void setValue(Object newValue, boolean repaintIsNotNeeded) throws Property.ReadOnlyException,
+ Property.ConversionException {
if (isMultiSelect()) {
if (newValue == null)
- super.setValue(new HashSet());
+ super.setValue(new HashSet(), repaintIsNotNeeded);
else if (Collection.class.isAssignableFrom(newValue.getClass()))
- super.setValue(new HashSet((Collection) newValue));
+ super.setValue(new HashSet((Collection) newValue), repaintIsNotNeeded);
} else if (newValue == null || items.containsId(newValue))
- super.setValue(newValue);
+ super.setValue(newValue, repaintIsNotNeeded);
}
/* Container methods **************************************************** */
@@ -798,7 +819,7 @@ public class Select extends AbstractField implements Container,
}
// TODO: This should be conditional
- fireValueChange();
+ fireValueChange(false);
}
}
diff --git a/src/com/itmill/toolkit/ui/TextField.java b/src/com/itmill/toolkit/ui/TextField.java
index 8d4bf0a459..a8d1bd279c 100644
--- a/src/com/itmill/toolkit/ui/TextField.java
+++ b/src/com/itmill/toolkit/ui/TextField.java
@@ -243,7 +243,7 @@ public class TextField extends AbstractField {
newValue = null;
if (newValue != oldValue
&& (newValue == null || !newValue.equals(oldValue)))
- setValue(newValue);
+ setValue(newValue,true);
}
}
diff --git a/src/com/itmill/toolkit/ui/Tree.java b/src/com/itmill/toolkit/ui/Tree.java
index 1d3f303aa3..a4440c2cbc 100644
--- a/src/com/itmill/toolkit/ui/Tree.java
+++ b/src/com/itmill/toolkit/ui/Tree.java
@@ -305,8 +305,10 @@ public class Tree extends Select implements Container.Hierarchical,
String[] keys = (String[]) variables.get("collapse");
for (int i = 0; i < keys.length; i++) {
Object id = itemIdMapper.get(keys[i]);
- if (id != null)
- collapseItem(id);
+ if (id != null && isExpanded(id)) {
+ expanded.remove(id);
+ fireCollapseEvent(id);
+ }
}
}
@@ -548,7 +550,7 @@ public class Tree extends Select implements Container.Hierarchical,
boolean success = ((Container.Hierarchical) items).setChildrenAllowed(
itemId, areChildrenAllowed);
if (success)
- fireValueChange();
+ fireValueChange(false);
return success;
}