package com.vaadin.terminal.gwt.client.ui;
import java.util.HashMap;
-import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
import com.google.gwt.dom.client.DivElement;
import com.google.gwt.dom.client.Document;
import com.google.gwt.dom.client.Style;
-import com.google.gwt.event.dom.client.DomEvent.Type;
-import com.google.gwt.event.shared.EventHandler;
-import com.google.gwt.event.shared.HandlerRegistration;
import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.Element;
import com.google.gwt.user.client.ui.ComplexPanel;
import com.google.gwt.user.client.ui.SimplePanel;
import com.google.gwt.user.client.ui.Widget;
import com.vaadin.terminal.gwt.client.ApplicationConnection;
-import com.vaadin.terminal.gwt.client.Container;
-import com.vaadin.terminal.gwt.client.EventId;
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.VPaintableMap;
import com.vaadin.terminal.gwt.client.VPaintableWidget;
-public class VAbsoluteLayout extends ComplexPanel implements Container {
+public class VAbsoluteLayout extends ComplexPanel {
/** Tag name for widget creation */
public static final String TAGNAME = "absolutelayout";
private Object previousStyleName;
- private Map<String, AbsoluteWrapper> pidToComponentWrappper = new HashMap<String, AbsoluteWrapper>();
+ Map<String, AbsoluteWrapper> pidToComponentWrappper = new HashMap<String, AbsoluteWrapper>();
protected ApplicationConnection client;
- private boolean rendering;
-
- private LayoutClickEventHandler clickEventHandler = new LayoutClickEventHandler(
- this, EventId.LAYOUT_CLICK) {
-
- @Override
- protected VPaintableWidget getChildComponent(Element element) {
- return getComponent(element);
- }
-
- @Override
- protected <H extends EventHandler> HandlerRegistration registerHandler(
- H handler, Type<H> type) {
- return addDomHandler(handler, type);
- }
- };
+ boolean rendering;
public VAbsoluteLayout() {
setElement(Document.get().createDivElement());
parent2.updateCaption(uidl);
}
- public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
- rendering = true;
- this.client = client;
- // TODO margin handling
- if (client.updateComponent(this, uidl, true)) {
- rendering = false;
- return;
- }
-
- clickEventHandler.handleEventHandlerRegistration(client);
-
- HashSet<String> unrenderedPids = new HashSet<String>(
- pidToComponentWrappper.keySet());
-
- for (Iterator<Object> childIterator = uidl.getChildIterator(); childIterator
- .hasNext();) {
- UIDL cc = (UIDL) childIterator.next();
- if (cc.getTag().equals("cc")) {
- UIDL componentUIDL = cc.getChildUIDL(0);
- unrenderedPids.remove(componentUIDL.getId());
- getWrapper(client, componentUIDL).updateFromUIDL(cc);
- }
- }
-
- for (String pid : unrenderedPids) {
- AbsoluteWrapper absoluteWrapper = pidToComponentWrappper.get(pid);
- pidToComponentWrappper.remove(pid);
- absoluteWrapper.destroy();
- }
- rendering = false;
- }
-
- private AbsoluteWrapper getWrapper(ApplicationConnection client,
- UIDL componentUIDL) {
+ AbsoluteWrapper getWrapper(ApplicationConnection client, UIDL componentUIDL) {
AbsoluteWrapper wrapper = pidToComponentWrappper.get(componentUIDL
.getId());
if (wrapper == null) {
* @return The Paintable which the element is a part of. Null if the element
* belongs to the layout and not to a child.
*/
- private VPaintableWidget getComponent(Element element) {
+ VPaintableWidget getComponent(Element element) {
return Util.getPaintableForElement(client, this, element);
}
--- /dev/null
+package com.vaadin.terminal.gwt.client.ui;\r
+\r
+import java.util.HashSet;\r
+import java.util.Iterator;\r
+\r
+import com.google.gwt.core.client.GWT;\r
+import com.google.gwt.event.dom.client.DomEvent.Type;\r
+import com.google.gwt.event.shared.EventHandler;\r
+import com.google.gwt.event.shared.HandlerRegistration;\r
+import com.google.gwt.user.client.Element;\r
+import com.google.gwt.user.client.ui.Widget;\r
+import com.vaadin.terminal.gwt.client.ApplicationConnection;\r
+import com.vaadin.terminal.gwt.client.EventId;\r
+import com.vaadin.terminal.gwt.client.UIDL;\r
+import com.vaadin.terminal.gwt.client.VPaintableWidget;\r
+import com.vaadin.terminal.gwt.client.ui.VAbsoluteLayout.AbsoluteWrapper;\r
+\r
+public class VAbsoluteLayoutPaintable extends VAbstractPaintableWidget {\r
+\r
+ private LayoutClickEventHandler clickEventHandler = new LayoutClickEventHandler(\r
+ this, EventId.LAYOUT_CLICK) {\r
+\r
+ @Override\r
+ protected VPaintableWidget getChildComponent(Element element) {\r
+ return getWidgetForPaintable().getComponent(element);\r
+ }\r
+\r
+ @Override\r
+ protected <H extends EventHandler> HandlerRegistration registerHandler(\r
+ H handler, Type<H> type) {\r
+ return getWidgetForPaintable().addDomHandler(handler, type);\r
+ }\r
+ };\r
+\r
+ public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {\r
+ getWidgetForPaintable().rendering = true;\r
+ getWidgetForPaintable().client = client;\r
+ // TODO margin handling\r
+ if (client.updateComponent(this, uidl, true)) {\r
+ getWidgetForPaintable().rendering = false;\r
+ return;\r
+ }\r
+\r
+ clickEventHandler.handleEventHandlerRegistration(client);\r
+\r
+ HashSet<String> unrenderedPids = new HashSet<String>(\r
+ getWidgetForPaintable().pidToComponentWrappper.keySet());\r
+\r
+ for (Iterator<Object> childIterator = uidl.getChildIterator(); childIterator\r
+ .hasNext();) {\r
+ UIDL cc = (UIDL) childIterator.next();\r
+ if (cc.getTag().equals("cc")) {\r
+ UIDL componentUIDL = cc.getChildUIDL(0);\r
+ unrenderedPids.remove(componentUIDL.getId());\r
+ getWidgetForPaintable().getWrapper(client, componentUIDL)\r
+ .updateFromUIDL(cc);\r
+ }\r
+ }\r
+\r
+ for (String pid : unrenderedPids) {\r
+ AbsoluteWrapper absoluteWrapper = getWidgetForPaintable().pidToComponentWrappper\r
+ .get(pid);\r
+ getWidgetForPaintable().pidToComponentWrappper.remove(pid);\r
+ absoluteWrapper.destroy();\r
+ }\r
+ getWidgetForPaintable().rendering = false;\r
+ }\r
+\r
+ @Override\r
+ protected Widget createWidget() {\r
+ return GWT.create(VAbsoluteLayout.class);\r
+ }\r
+\r
+ @Override\r
+ public VAbsoluteLayout getWidgetForPaintable() {\r
+ return (VAbsoluteLayout) super.getWidgetForPaintable();\r
+ }\r
+}\r