From: Matti Tahvonen Date: Fri, 10 Aug 2007 06:26:56 +0000 (+0000) Subject: evolved IGridLayout's rendering + added test X-Git-Tag: 6.7.0.beta1~6127 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=7b7b8dea5f4cdbcef9c91c3aad362587a14a5d79;p=vaadin-framework.git evolved IGridLayout's rendering + added test svn changeset:1977/svn branch:trunk --- diff --git a/src/com/itmill/toolkit/terminal/gwt/client/ui/IGridLayout.java b/src/com/itmill/toolkit/terminal/gwt/client/ui/IGridLayout.java index 7cf0c64fb0..ab91f7f0ff 100644 --- a/src/com/itmill/toolkit/terminal/gwt/client/ui/IGridLayout.java +++ b/src/com/itmill/toolkit/terminal/gwt/client/ui/IGridLayout.java @@ -35,11 +35,16 @@ public class IGridLayout extends FlexTable implements Paintable, Layout { UIDL c = (UIDL) j.next(); if ("gc".equals(c.getTag())) { column++; + int w; if (c.hasAttribute("w")) { - int w = c.getIntAttribute("w"); - ((FlexCellFormatter) getCellFormatter()) - .setColSpan(row, column, w); + w = c.getIntAttribute("w"); } + else + w = 1; + ((FlexCellFormatter) getCellFormatter()) + .setColSpan(row, column, w); + + UIDL u = c.getChildUIDL(0); if (u != null) { Widget child = client.getWidget(u); @@ -57,6 +62,7 @@ public class IGridLayout extends FlexTable implements Paintable, Layout { } ((Paintable) child).updateFromUIDL(u, client); } + column += w -1; } } } diff --git a/src/com/itmill/toolkit/tests/TestForGridLayoutChildComponentRendering.java b/src/com/itmill/toolkit/tests/TestForGridLayoutChildComponentRendering.java new file mode 100644 index 0000000000..23f9f47b32 --- /dev/null +++ b/src/com/itmill/toolkit/tests/TestForGridLayoutChildComponentRendering.java @@ -0,0 +1,101 @@ +package com.itmill.toolkit.tests; + +import java.util.ArrayList; +import java.util.Iterator; + +import com.itmill.toolkit.terminal.ExternalResource; +import com.itmill.toolkit.ui.Button; +import com.itmill.toolkit.ui.Component; +import com.itmill.toolkit.ui.CustomComponent; +import com.itmill.toolkit.ui.GridLayout; +import com.itmill.toolkit.ui.Label; +import com.itmill.toolkit.ui.Link; +import com.itmill.toolkit.ui.OrderedLayout; +import com.itmill.toolkit.ui.Select; + +/** + * + * This Component contains some simple test to see that component + * updates its contents propertly. + * + * @author IT Mill Ltd. + */ +public class TestForGridLayoutChildComponentRendering extends CustomComponent { + + + private GridLayout main = new GridLayout(2,3); + + public TestForGridLayoutChildComponentRendering() { + + setCompositionRoot(main); + createNewView(); + } + + public void createNewView() { + main.removeAllComponents(); + main.addComponent(new Label("SDFGFHFHGJGFDSDSSSGFDD")); + + Link l = new Link(); + l.setCaption("Siirry ITMILLIIN"); + l.setResource(new ExternalResource("http://www.itmill.com/")); + l.setTargetHeight(200); + l.setTargetWidth(500); + l.setTargetBorder(Link.TARGET_BORDER_MINIMAL); + main.addComponent(l); + + + Select se = new Select("Tästä valitaan"); + se.setCaption("Whattaa select"); + se.addItem("valinta1"); + se.addItem("Valinta 2"); + + main.addComponent(se, 0, 1, 1, 1); + + + Button b = new Button("refresh view", this, "createNewView"); + main.addComponent(b); + + b = new Button("reorder view", this, "randomReorder"); + main.addComponent(b); + + b = new Button("remove randomly one component", this, "removeRandomComponent"); + main.addComponent(b); + + } + + public void randomReorder() { + Iterator it = main.getComponentIterator(); + ArrayList components = new ArrayList(); + while(it.hasNext()) + components.add(it.next()); + + main.removeAllComponents(); + + int size = components.size(); + int colspanIndex = ((int) (Math.random()*size)/2)*2 + 2; + + for(int i = components.size(); i > 0; i--) { + int index = (int) (Math.random()*i); + if(i == colspanIndex) + main.addComponent((Component) components.get(index), 0, (size - i )/2, 1, (size - i)/2); + else + main.addComponent((Component) components.get(index)); + components.remove(index); + } + } + + public void removeRandomComponent() { + Iterator it = main.getComponentIterator(); + ArrayList components = new ArrayList(); + while(it.hasNext()) + components.add(it.next()); + int size = components.size(); + int index = (int) (Math.random()*size); + main.removeComponent((Component) components.get(index)); + + } + + +} + +