aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarc Englund <marc.englund@itmill.com>2008-12-08 14:33:27 +0000
committerMarc Englund <marc.englund@itmill.com>2008-12-08 14:33:27 +0000
commitc970fa7a2a581ccff5f2ce7deef7f8aa3edb4275 (patch)
treeb8d0f3fcb8a53a68d765c1ef68db7f99881b24fc
parent3956a29cf805a1b6087be54163d0e3d618002de9 (diff)
downloadvaadin-framework-c970fa7a2a581ccff5f2ce7deef7f8aa3edb4275.tar.gz
vaadin-framework-c970fa7a2a581ccff5f2ce7deef7f8aa3edb4275.zip
Retains first field position when doing setItemDataSource() when layout is GridLAyout. Fixes #2244 setLayout() no longer copies all compoents to new layout, only fields.
svn changeset:6123/svn branch:trunk
-rw-r--r--src/com/itmill/toolkit/ui/Form.java37
1 files changed, 35 insertions, 2 deletions
diff --git a/src/com/itmill/toolkit/ui/Form.java b/src/com/itmill/toolkit/ui/Form.java
index 03d280bcaf..55f0655d15 100644
--- a/src/com/itmill/toolkit/ui/Form.java
+++ b/src/com/itmill/toolkit/ui/Form.java
@@ -121,6 +121,10 @@ public class Form extends AbstractField implements Item.Editor, Buffered, Item,
*/
private boolean validationVisibleOnCommit = true;
+ // special handling for gridlayout; remember initial cursor pos
+ private int gridlayoutCursorX = -1;
+ private int gridlayoutCursorY = -1;
+
/**
* Contructs a new form with default layout.
*
@@ -611,6 +615,19 @@ public class Form extends AbstractField implements Item.Editor, Buffered, Item,
*/
public void setItemDataSource(Item newDataSource, Collection propertyIds) {
+ if (layout instanceof GridLayout) {
+ GridLayout gl = (GridLayout) layout;
+ if (gridlayoutCursorX == -1) {
+ // first setItemDataSource, remember initial cursor
+ gridlayoutCursorX = gl.getCursorX();
+ gridlayoutCursorY = gl.getCursorY();
+ } else {
+ // restore initial cursor
+ gl.setCursorX(gridlayoutCursorX);
+ gl.setCursorY(gridlayoutCursorY);
+ }
+ }
+
// Removes all fields first from the form
removeAllProperties();
@@ -669,15 +686,31 @@ public class Form extends AbstractField implements Item.Editor, Buffered, Item,
newLayout = new FormLayout();
}
- // Move components from previous layout
+ // reset cursor memory
+ gridlayoutCursorX = -1;
+ gridlayoutCursorY = -1;
+
+ // Move fields from previous layout
if (layout != null) {
- newLayout.moveComponentsFrom(layout);
+ final Object[] properties = propertyIds.toArray();
+ for (int i = 0; i < properties.length; i++) {
+ Field f = getField(properties[i]);
+ layout.removeComponent(f);
+ if (newLayout instanceof CustomLayout) {
+ ((CustomLayout) newLayout).addComponent(f, properties[i]
+ .toString());
+ } else {
+ newLayout.addComponent(f);
+ }
+ }
+
layout.setParent(null);
}
// Replace the previous layout
newLayout.setParent(this);
layout = newLayout;
+
}
/**