import java.util.Set;
-import com.google.gwt.core.client.Scheduler;
-import com.google.gwt.user.client.Command;
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.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 VCustomComponent extends SimplePanel implements Container {
+public class VCustomComponent extends SimplePanel {
private static final String CLASSNAME = "v-customcomponent";
private String height;
- private ApplicationConnection client;
- private boolean rendering;
+ ApplicationConnection client;
+ boolean rendering;
private String width;
- private RenderSpace renderSpace = new RenderSpace();
+ RenderSpace renderSpace = new RenderSpace();
public VCustomComponent() {
super();
setStyleName(CLASSNAME);
}
- public void updateFromUIDL(UIDL uidl, final ApplicationConnection client) {
- rendering = true;
- if (client.updateComponent(this, uidl, true)) {
- rendering = false;
- return;
- }
- this.client = client;
-
- final UIDL child = uidl.getChildUIDL(0);
- if (child != null) {
- final VPaintableWidget paintable = client.getPaintable(child);
- Widget widget = paintable.getWidgetForPaintable();
- if (widget != getWidget()) {
- if (getWidget() != null) {
- client.unregisterPaintable(VPaintableMap.get(client)
- .getPaintable(getWidget()));
- clear();
- }
- setWidget(widget);
- }
- paintable.updateFromUIDL(child, client);
- }
-
- boolean updateDynamicSize = updateDynamicSize();
- if (updateDynamicSize) {
- Scheduler.get().scheduleDeferred(new Command() {
- public void execute() {
- // FIXME deferred relative size update needed to fix some
- // scrollbar issues in sampler. This must be the wrong way
- // to do it. Might be that some other component is broken.
- client.handleComponentRelativeSize(VCustomComponent.this);
-
- }
- });
- }
-
- renderSpace.setWidth(getElement().getOffsetWidth());
- renderSpace.setHeight(getElement().getOffsetHeight());
-
- /*
- * Needed to update client size if the size of this component has
- * changed and the child uses relative size(s).
- */
- client.runDescendentsLayout(this);
-
- rendering = false;
- }
-
- private boolean updateDynamicSize() {
+ boolean updateDynamicSize() {
boolean updated = false;
if (isDynamicWidth()) {
int childWidth = Util.getRequiredWidth(getWidget());
}
}
- public void updateCaption(VPaintableWidget component, UIDL uidl) {
- // NOP, custom component dont render composition roots caption
- }
-
public boolean requestLayout(Set<Widget> children) {
// If a child grows in size, it will not necessarily be calculated
// correctly unless we remove previous size definitions
--- /dev/null
+package com.vaadin.terminal.gwt.client.ui;\r
+\r
+import com.google.gwt.core.client.GWT;\r
+import com.google.gwt.core.client.Scheduler;\r
+import com.google.gwt.user.client.Command;\r
+import com.google.gwt.user.client.ui.Widget;\r
+import com.vaadin.terminal.gwt.client.ApplicationConnection;\r
+import com.vaadin.terminal.gwt.client.UIDL;\r
+import com.vaadin.terminal.gwt.client.VPaintableMap;\r
+import com.vaadin.terminal.gwt.client.VPaintableWidget;\r
+\r
+public class VCustomComponentPaintable extends\r
+ VAbstractPaintableWidgetContainer {\r
+\r
+ public void updateFromUIDL(UIDL uidl, final ApplicationConnection client) {\r
+ getWidgetForPaintable().rendering = true;\r
+ if (client.updateComponent(this, uidl, true)) {\r
+ getWidgetForPaintable().rendering = false;\r
+ return;\r
+ }\r
+ getWidgetForPaintable().client = client;\r
+\r
+ final UIDL child = uidl.getChildUIDL(0);\r
+ if (child != null) {\r
+ final VPaintableWidget paintable = client.getPaintable(child);\r
+ Widget widget = paintable.getWidgetForPaintable();\r
+ if (widget != getWidgetForPaintable().getWidget()) {\r
+ if (getWidgetForPaintable().getWidget() != null) {\r
+ client.unregisterPaintable(VPaintableMap.get(client)\r
+ .getPaintable(getWidgetForPaintable().getWidget()));\r
+ getWidgetForPaintable().clear();\r
+ }\r
+ getWidgetForPaintable().setWidget(widget);\r
+ }\r
+ paintable.updateFromUIDL(child, client);\r
+ }\r
+\r
+ boolean updateDynamicSize = getWidgetForPaintable().updateDynamicSize();\r
+ if (updateDynamicSize) {\r
+ Scheduler.get().scheduleDeferred(new Command() {\r
+ public void execute() {\r
+ // FIXME deferred relative size update needed to fix some\r
+ // scrollbar issues in sampler. This must be the wrong way\r
+ // to do it. Might be that some other component is broken.\r
+ client.handleComponentRelativeSize(getWidgetForPaintable());\r
+\r
+ }\r
+ });\r
+ }\r
+\r
+ getWidgetForPaintable().renderSpace.setWidth(getWidgetForPaintable()\r
+ .getElement().getOffsetWidth());\r
+ getWidgetForPaintable().renderSpace.setHeight(getWidgetForPaintable()\r
+ .getElement().getOffsetHeight());\r
+\r
+ /*\r
+ * Needed to update client size if the size of this component has\r
+ * changed and the child uses relative size(s).\r
+ */\r
+ client.runDescendentsLayout(getWidgetForPaintable());\r
+\r
+ getWidgetForPaintable().rendering = false;\r
+ }\r
+\r
+ @Override\r
+ protected Widget createWidget() {\r
+ return GWT.create(VCustomComponent.class);\r
+ }\r
+\r
+ @Override\r
+ public VCustomComponent getWidgetForPaintable() {\r
+ return (VCustomComponent) super.getWidgetForPaintable();\r
+ }\r
+\r
+ public void updateCaption(VPaintableWidget component, UIDL uidl) {\r
+ // NOP, custom component dont render composition roots caption\r
+ }\r
+\r
+}\r
import com.google.gwt.user.client.ui.Widget;
import com.vaadin.terminal.gwt.client.ApplicationConnection;
import com.vaadin.terminal.gwt.client.BrowserInfo;
-import com.vaadin.terminal.gwt.client.Container;
import com.vaadin.terminal.gwt.client.ContainerResizedListener;
import com.vaadin.terminal.gwt.client.RenderInformation.FloatSize;
import com.vaadin.terminal.gwt.client.RenderSpace;
* @author Vaadin Ltd
*
*/
-public class VCustomLayout extends ComplexPanel implements VPaintableWidget,
- Container, ContainerResizedListener {
+public class VCustomLayout extends ComplexPanel implements
+ ContainerResizedListener {
public static final String CLASSNAME = "v-customlayout";
private final HashMap<String, Element> locationToElement = new HashMap<String, Element>();
/** Location-name to contained widget map */
- private final HashMap<String, Widget> locationToWidget = new HashMap<String, Widget>();
+ final HashMap<String, Widget> locationToWidget = new HashMap<String, Widget>();
/** Widget to captionwrapper map */
private final HashMap<VPaintableWidget, VCaptionWrapper> paintableToCaptionWrapper = new HashMap<VPaintableWidget, VCaptionWrapper>();
String currentTemplateName;
/** Unexecuted scripts loaded from the template */
- private String scripts = "";
+ String scripts = "";
/** Paintable ID of this paintable */
- private String pid;
+ String pid;
- private ApplicationConnection client;
+ ApplicationConnection client;
/** Has the template been loaded from contents passed in UIDL **/
private boolean hasTemplateContents = false;
locationToWidget.put(location, widget);
}
- /** Update the layout from UIDL */
- public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
- this.client = client;
- // ApplicationConnection manages generic component features
- if (client.updateComponent(this, uidl, true)) {
- return;
- }
-
- pid = uidl.getId();
- if (!hasTemplate()) {
- // Update HTML template only once
- initializeHTML(uidl, client);
- }
-
- // Evaluate scripts
- eval(scripts);
- scripts = null;
-
- iLayout();
- // TODO Check if this is needed
- client.runDescendentsLayout(this);
-
- Set<Widget> oldWidgets = new HashSet<Widget>();
- oldWidgets.addAll(locationToWidget.values());
-
- // For all contained widgets
- for (final Iterator<?> i = uidl.getChildIterator(); i.hasNext();) {
- final UIDL uidlForChild = (UIDL) i.next();
- if (uidlForChild.getTag().equals("location")) {
- final String location = uidlForChild.getStringAttribute("name");
- UIDL childUIDL = uidlForChild.getChildUIDL(0);
- final VPaintableWidget childPaintable = client
- .getPaintable(childUIDL);
- Widget childWidget = childPaintable.getWidgetForPaintable();
- try {
- setWidget(childWidget, location);
- childPaintable.updateFromUIDL(childUIDL, client);
- } catch (final IllegalArgumentException e) {
- // If no location is found, this component is not visible
- }
- oldWidgets.remove(childWidget);
- }
- }
- for (Iterator<Widget> iterator = oldWidgets.iterator(); iterator
- .hasNext();) {
- Widget oldWidget = iterator.next();
- if (oldWidget.isAttached()) {
- // slot of this widget is emptied, remove it
- remove(oldWidget);
- }
- }
-
- iLayout();
- // TODO Check if this is needed
- client.runDescendentsLayout(this);
-
- }
-
/** Initialize HTML-layout. */
- private void initializeHTML(UIDL uidl, ApplicationConnection client) {
+ void initializeHTML(UIDL uidl, ApplicationConnection client) {
final String newTemplateContents = uidl
.getStringAttribute("templateContents");
return false;
}-*/;
- private boolean hasTemplate() {
+ boolean hasTemplate() {
if (currentTemplateName == null && !hasTemplateContents) {
return false;
} else {
}
/** Evaluate given script in browser document */
- private static native void eval(String script)
+ static native void eval(String script)
/*-{
try {
if (script != null)
--- /dev/null
+package com.vaadin.terminal.gwt.client.ui;\r
+\r
+import java.util.HashSet;\r
+import java.util.Iterator;\r
+import java.util.Set;\r
+\r
+import com.google.gwt.core.client.GWT;\r
+import com.google.gwt.user.client.ui.Widget;\r
+import com.vaadin.terminal.gwt.client.ApplicationConnection;\r
+import com.vaadin.terminal.gwt.client.UIDL;\r
+import com.vaadin.terminal.gwt.client.VPaintableWidget;\r
+\r
+public class VCustomLayoutPaintable extends VAbstractPaintableWidgetContainer {\r
+\r
+ /** Update the layout from UIDL */\r
+ public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {\r
+ getWidgetForPaintable().client = client;\r
+ // ApplicationConnection manages generic component features\r
+ if (client.updateComponent(this, uidl, true)) {\r
+ return;\r
+ }\r
+\r
+ getWidgetForPaintable().pid = uidl.getId();\r
+ if (!getWidgetForPaintable().hasTemplate()) {\r
+ // Update HTML template only once\r
+ getWidgetForPaintable().initializeHTML(uidl, client);\r
+ }\r
+\r
+ // Evaluate scripts\r
+ VCustomLayout.eval(getWidgetForPaintable().scripts);\r
+ getWidgetForPaintable().scripts = null;\r
+\r
+ getWidgetForPaintable().iLayout();\r
+ // TODO Check if this is needed\r
+ client.runDescendentsLayout(getWidgetForPaintable());\r
+\r
+ Set<Widget> oldWidgets = new HashSet<Widget>();\r
+ oldWidgets.addAll(getWidgetForPaintable().locationToWidget.values());\r
+\r
+ // For all contained widgets\r
+ for (final Iterator<?> i = uidl.getChildIterator(); i.hasNext();) {\r
+ final UIDL uidlForChild = (UIDL) i.next();\r
+ if (uidlForChild.getTag().equals("location")) {\r
+ final String location = uidlForChild.getStringAttribute("name");\r
+ UIDL childUIDL = uidlForChild.getChildUIDL(0);\r
+ final VPaintableWidget childPaintable = client\r
+ .getPaintable(childUIDL);\r
+ Widget childWidget = childPaintable.getWidgetForPaintable();\r
+ try {\r
+ getWidgetForPaintable().setWidget(childWidget, location);\r
+ childPaintable.updateFromUIDL(childUIDL, client);\r
+ } catch (final IllegalArgumentException e) {\r
+ // If no location is found, this component is not visible\r
+ }\r
+ oldWidgets.remove(childWidget);\r
+ }\r
+ }\r
+ for (Iterator<Widget> iterator = oldWidgets.iterator(); iterator\r
+ .hasNext();) {\r
+ Widget oldWidget = iterator.next();\r
+ if (oldWidget.isAttached()) {\r
+ // slot of this widget is emptied, remove it\r
+ getWidgetForPaintable().remove(oldWidget);\r
+ }\r
+ }\r
+\r
+ getWidgetForPaintable().iLayout();\r
+ // TODO Check if this is needed\r
+ client.runDescendentsLayout(getWidgetForPaintable());\r
+\r
+ }\r
+\r
+ @Override\r
+ public VCustomLayout getWidgetForPaintable() {\r
+ return (VCustomLayout) super.getWidgetForPaintable();\r
+ }\r
+\r
+ @Override\r
+ protected Widget createWidget() {\r
+ return GWT.create(VCustomLayout.class);\r
+ }\r
+\r
+ public void updateCaption(VPaintableWidget paintable, UIDL uidl) {\r
+ getWidgetForPaintable().updateCaption(paintable, uidl);\r
+\r
+ }\r
+}\r
import com.vaadin.terminal.PaintException;
import com.vaadin.terminal.PaintTarget;
-import com.vaadin.terminal.gwt.client.ui.VCustomComponent;
+import com.vaadin.terminal.gwt.client.ui.VCustomComponentPaintable;
import com.vaadin.ui.ClientWidget.LoadStyle;
/**
* @since 3.0
*/
@SuppressWarnings("serial")
-@ClientWidget(value = VCustomComponent.class, loadStyle = LoadStyle.EAGER)
+@ClientWidget(value = VCustomComponentPaintable.class, loadStyle = LoadStyle.EAGER)
public class CustomComponent extends AbstractComponentContainer {
/**
import com.vaadin.data.Property;
import com.vaadin.terminal.PaintException;
import com.vaadin.terminal.PaintTarget;
-import com.vaadin.terminal.gwt.client.ui.VCustomComponent;
+import com.vaadin.terminal.gwt.client.ui.VCustomComponentPaintable;
/**
* A {@link Field} whose UI content can be constructed by the user, enabling the
*
* @since 7.0
*/
-@ClientWidget(VCustomComponent.class)
+@ClientWidget(VCustomComponentPaintable.class)
public abstract class CustomField<T> extends AbstractField<T> implements
ComponentContainer {
import com.vaadin.terminal.PaintException;
import com.vaadin.terminal.PaintTarget;
-import com.vaadin.terminal.gwt.client.ui.VCustomLayout;
+import com.vaadin.terminal.gwt.client.ui.VCustomLayoutPaintable;
/**
* <p>
* @since 3.0
*/
@SuppressWarnings("serial")
-@ClientWidget(VCustomLayout.class)
+@ClientWidget(VCustomLayoutPaintable.class)
public class CustomLayout extends AbstractLayout {
private static final int BUFFER_SIZE = 10000;