import com.itmill.toolkit.terminal.gwt.client.ApplicationConnection;
import com.itmill.toolkit.terminal.gwt.client.CaptionWrapper;
import com.itmill.toolkit.terminal.gwt.client.Container;
+import com.itmill.toolkit.terminal.gwt.client.ContainerResizedListener;
import com.itmill.toolkit.terminal.gwt.client.Paintable;
import com.itmill.toolkit.terminal.gwt.client.StyleConstants;
import com.itmill.toolkit.terminal.gwt.client.UIDL;
+import com.itmill.toolkit.terminal.gwt.client.Util;
-public class IGridLayout extends SimplePanel implements Paintable, Container {
+public class IGridLayout extends SimplePanel implements Paintable, Container,
+ ContainerResizedListener {
public static final String CLASSNAME = "i-gridlayout";
private Grid grid = new Grid();
+ private boolean needsLayout = false;
+
+ private Element margin = DOM.createDiv();
+
+ private Element meterElement;
+
+ private String width;
+
public IGridLayout() {
super();
+ DOM.appendChild(getElement(), margin);
+ DOM.setStyleAttribute(getElement(), "overflow", "hidden");
setStyleName(CLASSNAME);
setWidget(grid);
}
+ protected Element getContainerElement() {
+ return margin;
+ }
+
+ public void setWidth(String width) {
+ this.width = width;
+ if (width != null && !width.equals("")) {
+ needsLayout = true;
+ } else {
+ needsLayout = false;
+ grid.setWidth("");
+ }
+ }
+
public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
if (client.updateComponent(this, uidl, false)) {
return;
}
-
final MarginInfo margins = new MarginInfo(uidl
.getIntAttribute("margins"));
- Element margin = getElement();
setStyleName(margin, CLASSNAME + "-" + StyleConstants.MARGIN_TOP,
margins.hasTop());
setStyleName(margin, CLASSNAME + "-" + StyleConstants.MARGIN_RIGHT,
setStyleName(margin, CLASSNAME + "-" + "spacing", uidl
.hasAttribute("spacing"));
-
+ iLayout();
grid.updateFromUIDL(uidl, client);
}
}
+ public void iLayout() {
+ if (needsLayout) {
+ super.setWidth(width);
+ if (meterElement == null) {
+ meterElement = DOM.createDiv();
+ DOM.setStyleAttribute(meterElement, "overflow", "hidden");
+ DOM.setStyleAttribute(meterElement, "height", "0");
+ DOM.appendChild(getContainerElement(), meterElement);
+ }
+ int contentWidth = DOM.getElementPropertyInt(meterElement,
+ "offsetWidth");
+ int offsetWidth = getOffsetWidth();
+
+ grid.setWidth((offsetWidth - (offsetWidth - contentWidth)) + "px");
+ } else {
+ grid.setWidth("");
+ }
+ Util.runDescendentsLayout(this);
+ }
+
}
--- /dev/null
+package com.itmill.toolkit.tests.tickets;\r
+\r
+import com.itmill.toolkit.data.Property.ValueChangeEvent;\r
+import com.itmill.toolkit.data.Property.ValueChangeListener;\r
+import com.itmill.toolkit.ui.Button;\r
+import com.itmill.toolkit.ui.GridLayout;\r
+import com.itmill.toolkit.ui.Label;\r
+import com.itmill.toolkit.ui.TextField;\r
+import com.itmill.toolkit.ui.Window;\r
+\r
+public class Ticket1805 extends com.itmill.toolkit.Application {\r
+\r
+ public void init() {\r
+ final Window main = new Window(getClass().getName().substring(\r
+ getClass().getName().lastIndexOf(".") + 1));\r
+ setMainWindow(main);\r
+ main.getLayout().setMargin(false);\r
+\r
+ Label description = new Label(\r
+ "GridLayout with 100% (no height), is wanted to "\r
+ + "share all available width with columns "\r
+ + "relatively to their natural width. And it "\r
+ + "should still work with margins and spacings");\r
+ main.addComponent(description);\r
+\r
+ final GridLayout grid = new GridLayout(4, 1);\r
+\r
+ final TextField size = new TextField("Grid width in css unit");\r
+ size.addListener(new ValueChangeListener() {\r
+ public void valueChange(ValueChangeEvent event) {\r
+ String width = size.getValue().toString();\r
+ if (width == null || width.equals("")) {\r
+ grid.setSizeUndefined();\r
+ } else {\r
+ grid.setWidth(width);\r
+ }\r
+ }\r
+ });\r
+ main.addComponent(size);\r
+ main.addComponent(new Button("set size"));\r
+\r
+ grid.setMargin(true);\r
+ grid.setSpacing(true);\r
+\r
+ grid.addComponent(new Label("WIDE"));\r
+ grid.addComponent(new Label("_I_"));\r
+ grid.addComponent(new Label("VEEEEEEEEEEERY_WIDE"));\r
+ Label label = new Label("|");\r
+ grid.addComponent(label);\r
+ grid.setComponentAlignment(label, GridLayout.ALIGNMENT_RIGHT,\r
+ GridLayout.ALIGNMENT_TOP);\r
+ main.addComponent(grid);\r
+ }\r
+\r
+}\r