aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArtur Signell <artur@vaadin.com>2012-01-31 13:58:36 +0200
committerArtur Signell <artur@vaadin.com>2012-01-31 15:08:39 +0200
commit00a8bb6002496dd135ed08cc92acfbab9a14bc18 (patch)
tree420a566938317610e7d44a8f0844e0759d14debb
parent15abf4ff4c9359c8a2c402a6fc156076045712b5 (diff)
downloadvaadin-framework-00a8bb6002496dd135ed08cc92acfbab9a14bc18.tar.gz
vaadin-framework-00a8bb6002496dd135ed08cc92acfbab9a14bc18.zip
#8324 Split Form and FormLayout into widget and paintable
-rw-r--r--src/com/vaadin/terminal/gwt/client/ui/VForm.java171
-rw-r--r--src/com/vaadin/terminal/gwt/client/ui/VFormLayout.java25
-rw-r--r--src/com/vaadin/terminal/gwt/client/ui/VFormLayoutPaintable.java39
-rw-r--r--src/com/vaadin/terminal/gwt/client/ui/VFormPaintable.java173
-rw-r--r--src/com/vaadin/ui/Form.java5
-rw-r--r--src/com/vaadin/ui/FormLayout.java4
6 files changed, 241 insertions, 176 deletions
diff --git a/src/com/vaadin/terminal/gwt/client/ui/VForm.java b/src/com/vaadin/terminal/gwt/client/ui/VForm.java
index a329e1eaef..d70d7ed0d8 100644
--- a/src/com/vaadin/terminal/gwt/client/ui/VForm.java
+++ b/src/com/vaadin/terminal/gwt/client/ui/VForm.java
@@ -19,12 +19,9 @@ import com.vaadin.terminal.gwt.client.ApplicationConnection;
import com.vaadin.terminal.gwt.client.Container;
import com.vaadin.terminal.gwt.client.RenderInformation;
import com.vaadin.terminal.gwt.client.RenderSpace;
-import com.vaadin.terminal.gwt.client.UIDL;
import com.vaadin.terminal.gwt.client.Util;
import com.vaadin.terminal.gwt.client.VConsole;
import com.vaadin.terminal.gwt.client.VErrorMessage;
-import com.vaadin.terminal.gwt.client.VPaintableMap;
-import com.vaadin.terminal.gwt.client.VPaintableWidget;
public class VForm extends ComplexPanel implements Container, KeyDownHandler {
@@ -36,33 +33,33 @@ public class VForm extends ComplexPanel implements Container, KeyDownHandler {
public static final String CLASSNAME = "v-form";
- private Container lo;
- private Element legend = DOM.createLegend();
- private Element caption = DOM.createSpan();
+ Widget lo;
+ Element legend = DOM.createLegend();
+ Element caption = DOM.createSpan();
private Element errorIndicatorElement = DOM.createDiv();
- private Element desc = DOM.createDiv();
- private Icon icon;
- private VErrorMessage errorMessage = new VErrorMessage();
+ Element desc = DOM.createDiv();
+ Icon icon;
+ VErrorMessage errorMessage = new VErrorMessage();
- private Element fieldContainer = DOM.createDiv();
+ Element fieldContainer = DOM.createDiv();
- private Element footerContainer = DOM.createDiv();
+ Element footerContainer = DOM.createDiv();
- private Element fieldSet = DOM.createFieldSet();
+ Element fieldSet = DOM.createFieldSet();
- private Container footer;
+ Widget footer;
- private ApplicationConnection client;
+ ApplicationConnection client;
private RenderInformation renderInformation = new RenderInformation();
private int borderPaddingHorizontal = -1;
- private boolean rendering = false;
+ boolean rendering = false;
ShortcutActionHandler shortcutHandler;
- private HandlerRegistration keyDownRegistration;
+ HandlerRegistration keyDownRegistration;
public VForm() {
setElement(DOM.createDiv());
@@ -84,130 +81,6 @@ public class VForm extends ComplexPanel implements Container, KeyDownHandler {
fieldSet.appendChild(footerContainer);
}
- public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
- rendering = true;
- this.client = client;
- id = uidl.getId();
-
- if (client.updateComponent(this, uidl, false)) {
- rendering = false;
- return;
- }
-
- boolean legendEmpty = true;
- if (uidl.hasAttribute("caption")) {
- caption.setInnerText(uidl.getStringAttribute("caption"));
- legendEmpty = false;
- } else {
- caption.setInnerText("");
- }
- if (uidl.hasAttribute("icon")) {
- if (icon == null) {
- icon = new Icon(client);
- legend.insertFirst(icon.getElement());
- }
- icon.setUri(uidl.getStringAttribute("icon"));
- legendEmpty = false;
- } else {
- if (icon != null) {
- legend.removeChild(icon.getElement());
- }
- }
- if (legendEmpty) {
- addStyleDependentName("nocaption");
- } else {
- removeStyleDependentName("nocaption");
- }
-
- if (uidl.hasAttribute("error")) {
- final UIDL errorUidl = uidl.getErrors();
- errorMessage.updateFromUIDL(errorUidl);
- errorMessage.setVisible(true);
-
- } else {
- errorMessage.setVisible(false);
- }
-
- if (uidl.hasAttribute("description")) {
- desc.setInnerHTML(uidl.getStringAttribute("description"));
- if (desc.getParentElement() == null) {
- fieldSet.insertAfter(desc, legend);
- }
- } else {
- desc.setInnerHTML("");
- if (desc.getParentElement() != null) {
- fieldSet.removeChild(desc);
- }
- }
-
- updateSize();
-
- // first render footer so it will be easier to handle relative height of
- // main layout
- if (uidl.getChildCount() > 1
- && !uidl.getChildUIDL(1).getTag().equals("actions")) {
- // render footer
- Container newFooter = (Container) client.getPaintable(uidl
- .getChildUIDL(1));
- if (footer == null) {
- add(newFooter.getWidgetForPaintable(), footerContainer);
- footer = newFooter;
- } else if (newFooter != footer) {
- remove(footer.getWidgetForPaintable());
- client.unregisterPaintable(footer);
- add(newFooter.getWidgetForPaintable(), footerContainer);
- }
- footer = newFooter;
- footer.updateFromUIDL(uidl.getChildUIDL(1), client);
- // needed for the main layout to know the space it has available
- updateSize();
- } else {
- if (footer != null) {
- remove(footer.getWidgetForPaintable());
- client.unregisterPaintable(footer);
- // needed for the main layout to know the space it has available
- updateSize();
- }
- }
-
- final UIDL layoutUidl = uidl.getChildUIDL(0);
- Container newLo = (Container) client.getPaintable(layoutUidl);
- if (lo == null) {
- lo = newLo;
- add(lo.getWidgetForPaintable(), fieldContainer);
- } else if (lo != newLo) {
- client.unregisterPaintable(lo);
- remove(lo.getWidgetForPaintable());
- lo = newLo;
- add(lo.getWidgetForPaintable(), fieldContainer);
- }
- lo.updateFromUIDL(layoutUidl, client);
-
- // also recalculates size of the footer if undefined size form - see
- // #3710
- updateSize();
- client.runDescendentsLayout(this);
-
- // We may have actions attached
- if (uidl.getChildCount() > 1) {
- UIDL childUidl = uidl.getChildByTagName("actions");
- if (childUidl != null) {
- if (shortcutHandler == null) {
- shortcutHandler = new ShortcutActionHandler(id, client);
- keyDownRegistration = addDomHandler(this,
- KeyDownEvent.getType());
- }
- shortcutHandler.updateActionMap(childUidl);
- }
- } else if (shortcutHandler != null) {
- keyDownRegistration.removeHandler();
- shortcutHandler = null;
- keyDownRegistration = null;
- }
-
- rendering = false;
- }
-
public void updateSize() {
renderInformation.updateSize(getElement());
@@ -241,12 +114,10 @@ public class VForm extends ComplexPanel implements Container, KeyDownHandler {
}
remove(oldComponent);
if (oldComponent == lo) {
- lo = (Container) VPaintableMap.get(client).getPaintable(
- newComponent);
+ lo = newComponent;
add(newComponent, fieldContainer);
} else {
- footer = (Container) VPaintableMap.get(client).getPaintable(
- newComponent);
+ footer = newComponent;
add(newComponent, footerContainer);
}
@@ -272,11 +143,6 @@ public class VForm extends ComplexPanel implements Container, KeyDownHandler {
}
- public void updateCaption(VPaintableWidget component, UIDL uidl) {
- // NOP form don't render caption for neither field layout nor footer
- // layout
- }
-
@Override
public void setHeight(String height) {
if (this.height.equals(height)) {
@@ -332,4 +198,11 @@ public class VForm extends ComplexPanel implements Container, KeyDownHandler {
public Widget getWidgetForPaintable() {
return this;
}
+
+ @Override
+ protected void add(Widget child, Element container) {
+ // Overridden to allow VFormPaintable to call this. Should be removed
+ // once functionality from VFormPaintable is moved to VForm.
+ super.add(child, container);
+ }
}
diff --git a/src/com/vaadin/terminal/gwt/client/ui/VFormLayout.java b/src/com/vaadin/terminal/gwt/client/ui/VFormLayout.java
index e6305b3c42..b2357f11e1 100644
--- a/src/com/vaadin/terminal/gwt/client/ui/VFormLayout.java
+++ b/src/com/vaadin/terminal/gwt/client/ui/VFormLayout.java
@@ -38,13 +38,13 @@ public class VFormLayout extends SimplePanel implements Container {
private final static String CLASSNAME = "v-formlayout";
- private ApplicationConnection client;
- private VFormLayoutTable table;
+ ApplicationConnection client;
+ VFormLayoutTable table;
private String width = "";
private String height = "";
- private boolean rendering = false;
+ boolean rendering = false;
public VFormLayout() {
super();
@@ -279,21 +279,6 @@ public class VFormLayout extends SimplePanel implements Container {
}
}
- public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
- rendering = true;
-
- this.client = client;
-
- if (client.updateComponent(this, uidl, true)) {
- rendering = false;
- return;
- }
-
- table.updateFromUIDL(uidl, client);
-
- rendering = false;
- }
-
public boolean isDynamicWidth() {
return width.equals("");
}
@@ -306,10 +291,6 @@ public class VFormLayout extends SimplePanel implements Container {
table.replaceChildComponent(oldComponent, newComponent);
}
- public void updateCaption(VPaintableWidget component, UIDL uidl) {
- table.updateCaption(component, uidl);
- }
-
public class Caption extends HTML {
public static final String CLASSNAME = "v-caption";
diff --git a/src/com/vaadin/terminal/gwt/client/ui/VFormLayoutPaintable.java b/src/com/vaadin/terminal/gwt/client/ui/VFormLayoutPaintable.java
new file mode 100644
index 0000000000..c4590a71c9
--- /dev/null
+++ b/src/com/vaadin/terminal/gwt/client/ui/VFormLayoutPaintable.java
@@ -0,0 +1,39 @@
+package com.vaadin.terminal.gwt.client.ui;
+
+import com.google.gwt.core.client.GWT;
+import com.google.gwt.user.client.ui.Widget;
+import com.vaadin.terminal.gwt.client.ApplicationConnection;
+import com.vaadin.terminal.gwt.client.UIDL;
+import com.vaadin.terminal.gwt.client.VPaintableWidget;
+
+public class VFormLayoutPaintable extends VAbstractPaintableWidgetContainer {
+ public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
+ getWidgetForPaintable().rendering = true;
+
+ getWidgetForPaintable().client = client;
+
+ if (client.updateComponent(this, uidl, true)) {
+ getWidgetForPaintable().rendering = false;
+ return;
+ }
+
+ getWidgetForPaintable().table.updateFromUIDL(uidl, client);
+
+ getWidgetForPaintable().rendering = false;
+ }
+
+ public void updateCaption(VPaintableWidget component, UIDL uidl) {
+ getWidgetForPaintable().table.updateCaption(component, uidl);
+ }
+
+ @Override
+ public VFormLayout getWidgetForPaintable() {
+ return (VFormLayout) super.getWidgetForPaintable();
+ }
+
+ @Override
+ protected Widget createWidget() {
+ return GWT.create(VFormLayout.class);
+ }
+
+}
diff --git a/src/com/vaadin/terminal/gwt/client/ui/VFormPaintable.java b/src/com/vaadin/terminal/gwt/client/ui/VFormPaintable.java
new file mode 100644
index 0000000000..5f519c09d4
--- /dev/null
+++ b/src/com/vaadin/terminal/gwt/client/ui/VFormPaintable.java
@@ -0,0 +1,173 @@
+package com.vaadin.terminal.gwt.client.ui;
+
+import com.google.gwt.core.client.GWT;
+import com.google.gwt.event.dom.client.KeyDownEvent;
+import com.google.gwt.user.client.ui.Widget;
+import com.vaadin.terminal.gwt.client.ApplicationConnection;
+import com.vaadin.terminal.gwt.client.UIDL;
+import com.vaadin.terminal.gwt.client.VPaintableMap;
+import com.vaadin.terminal.gwt.client.VPaintableWidget;
+
+public class VFormPaintable extends VAbstractPaintableWidgetContainer {
+
+ public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
+ getWidgetForPaintable().rendering = true;
+ getWidgetForPaintable().client = client;
+ getWidgetForPaintable().id = uidl.getId();
+
+ if (client.updateComponent(this, uidl, false)) {
+ getWidgetForPaintable().rendering = false;
+ return;
+ }
+
+ boolean legendEmpty = true;
+ if (uidl.hasAttribute("caption")) {
+ getWidgetForPaintable().caption.setInnerText(uidl
+ .getStringAttribute("caption"));
+ legendEmpty = false;
+ } else {
+ getWidgetForPaintable().caption.setInnerText("");
+ }
+ if (uidl.hasAttribute("icon")) {
+ if (getWidgetForPaintable().icon == null) {
+ getWidgetForPaintable().icon = new Icon(client);
+ getWidgetForPaintable().legend
+ .insertFirst(getWidgetForPaintable().icon.getElement());
+ }
+ getWidgetForPaintable().icon
+ .setUri(uidl.getStringAttribute("icon"));
+ legendEmpty = false;
+ } else {
+ if (getWidgetForPaintable().icon != null) {
+ getWidgetForPaintable().legend
+ .removeChild(getWidgetForPaintable().icon.getElement());
+ }
+ }
+ if (legendEmpty) {
+ getWidgetForPaintable().addStyleDependentName("nocaption");
+ } else {
+ getWidgetForPaintable().removeStyleDependentName("nocaption");
+ }
+
+ if (uidl.hasAttribute("error")) {
+ final UIDL errorUidl = uidl.getErrors();
+ getWidgetForPaintable().errorMessage.updateFromUIDL(errorUidl);
+ getWidgetForPaintable().errorMessage.setVisible(true);
+ } else {
+ getWidgetForPaintable().errorMessage.setVisible(false);
+ }
+
+ if (uidl.hasAttribute("description")) {
+ getWidgetForPaintable().desc.setInnerHTML(uidl
+ .getStringAttribute("description"));
+ if (getWidgetForPaintable().desc.getParentElement() == null) {
+ getWidgetForPaintable().fieldSet.insertAfter(
+ getWidgetForPaintable().desc,
+ getWidgetForPaintable().legend);
+ }
+ } else {
+ getWidgetForPaintable().desc.setInnerHTML("");
+ if (getWidgetForPaintable().desc.getParentElement() != null) {
+ getWidgetForPaintable().fieldSet
+ .removeChild(getWidgetForPaintable().desc);
+ }
+ }
+
+ getWidgetForPaintable().updateSize();
+
+ // first render footer so it will be easier to handle relative height of
+ // main layout
+ if (uidl.getChildCount() > 1
+ && !uidl.getChildUIDL(1).getTag().equals("actions")) {
+ // render footer
+ VPaintableWidget newFooter = client.getPaintable(uidl
+ .getChildUIDL(1));
+ Widget newFooterWidget = newFooter.getWidgetForPaintable();
+ if (getWidgetForPaintable().footer == null) {
+ getWidgetForPaintable().add(newFooter.getWidgetForPaintable(),
+ getWidgetForPaintable().footerContainer);
+ getWidgetForPaintable().footer = newFooterWidget;
+ } else if (newFooter != getWidgetForPaintable().footer) {
+ getWidgetForPaintable().remove(getWidgetForPaintable().footer);
+ client.unregisterPaintable(VPaintableMap.get(getConnection())
+ .getPaintable(getWidgetForPaintable().footer));
+ getWidgetForPaintable().add(newFooter.getWidgetForPaintable(),
+ getWidgetForPaintable().footerContainer);
+ }
+ getWidgetForPaintable().footer = newFooterWidget;
+ newFooter.updateFromUIDL(uidl.getChildUIDL(1), client);
+ // needed for the main layout to know the space it has available
+ getWidgetForPaintable().updateSize();
+ } else {
+ if (getWidgetForPaintable().footer != null) {
+ getWidgetForPaintable().remove(getWidgetForPaintable().footer);
+ client.unregisterPaintable(VPaintableMap.get(getConnection())
+ .getPaintable(getWidgetForPaintable().footer));
+ // needed for the main layout to know the space it has available
+ getWidgetForPaintable().updateSize();
+ }
+ }
+
+ final UIDL layoutUidl = uidl.getChildUIDL(0);
+ VPaintableWidget newLayout = client.getPaintable(layoutUidl);
+ Widget newLayoutWidget = newLayout.getWidgetForPaintable();
+ if (getWidgetForPaintable().lo == null) {
+ // Layout not rendered before
+ getWidgetForPaintable().lo = newLayoutWidget;
+ getWidgetForPaintable().add(newLayoutWidget,
+ getWidgetForPaintable().fieldContainer);
+ } else if (getWidgetForPaintable().lo != newLayoutWidget) {
+ // Layout has changed
+ client.unregisterPaintable(VPaintableMap.get(getConnection())
+ .getPaintable(getWidgetForPaintable().lo));
+ getWidgetForPaintable().remove(getWidgetForPaintable().lo);
+ getWidgetForPaintable().lo = newLayoutWidget;
+ getWidgetForPaintable().add(newLayoutWidget,
+ getWidgetForPaintable().fieldContainer);
+ }
+ newLayout.updateFromUIDL(layoutUidl, client);
+
+ // also recalculates size of the footer if undefined size form - see
+ // #3710
+ getWidgetForPaintable().updateSize();
+ client.runDescendentsLayout(getWidgetForPaintable());
+
+ // We may have actions attached
+ if (uidl.getChildCount() > 1) {
+ UIDL childUidl = uidl.getChildByTagName("actions");
+ if (childUidl != null) {
+ if (getWidgetForPaintable().shortcutHandler == null) {
+ getWidgetForPaintable().shortcutHandler = new ShortcutActionHandler(
+ getId(), client);
+ getWidgetForPaintable().keyDownRegistration = getWidgetForPaintable()
+ .addDomHandler(getWidgetForPaintable(),
+ KeyDownEvent.getType());
+ }
+ getWidgetForPaintable().shortcutHandler
+ .updateActionMap(childUidl);
+ }
+ } else if (getWidgetForPaintable().shortcutHandler != null) {
+ getWidgetForPaintable().keyDownRegistration.removeHandler();
+ getWidgetForPaintable().shortcutHandler = null;
+ getWidgetForPaintable().keyDownRegistration = null;
+ }
+
+ getWidgetForPaintable().rendering = false;
+ }
+
+ public void updateCaption(VPaintableWidget component, UIDL uidl) {
+ // NOP form don't render caption for neither field layout nor footer
+ // layout
+ }
+
+ @Override
+ public VForm getWidgetForPaintable() {
+ return (VForm) super.getWidgetForPaintable();
+ }
+
+ @Override
+ protected Widget createWidget() {
+ return GWT.create(VForm.class);
+ }
+
+}
diff --git a/src/com/vaadin/ui/Form.java b/src/com/vaadin/ui/Form.java
index 47210e1aed..c79804c7e7 100644
--- a/src/com/vaadin/ui/Form.java
+++ b/src/com/vaadin/ui/Form.java
@@ -27,7 +27,7 @@ import com.vaadin.terminal.CompositeErrorMessage;
import com.vaadin.terminal.ErrorMessage;
import com.vaadin.terminal.PaintException;
import com.vaadin.terminal.PaintTarget;
-import com.vaadin.terminal.gwt.client.ui.VForm;
+import com.vaadin.terminal.gwt.client.ui.VFormPaintable;
/**
* Form component provides easy way of creating and managing sets fields.
@@ -62,8 +62,7 @@ import com.vaadin.terminal.gwt.client.ui.VForm;
* @deprecated Use {@link FieldGroup} instead of {@link Form} for more
* flexibility.
*/
-@SuppressWarnings("serial")
-@ClientWidget(VForm.class)
+@ClientWidget(VFormPaintable.class)
@Deprecated
public class Form extends AbstractField<Object> implements Item.Editor,
Buffered, Item, Validatable, Action.Notifier {
diff --git a/src/com/vaadin/ui/FormLayout.java b/src/com/vaadin/ui/FormLayout.java
index eecf3372bb..c5c211924e 100644
--- a/src/com/vaadin/ui/FormLayout.java
+++ b/src/com/vaadin/ui/FormLayout.java
@@ -4,7 +4,7 @@
package com.vaadin.ui;
-import com.vaadin.terminal.gwt.client.ui.VFormLayout;
+import com.vaadin.terminal.gwt.client.ui.VFormLayoutPaintable;
/**
* FormLayout is used by {@link Form} to layout fields. It may also be used
@@ -21,7 +21,7 @@ import com.vaadin.terminal.gwt.client.ui.VFormLayout;
* bottom are by default on.
*
*/
-@ClientWidget(VFormLayout.class)
+@ClientWidget(VFormLayoutPaintable.class)
public class FormLayout extends AbstractOrderedLayout {
public FormLayout() {