]> source.dussan.org Git - vaadin-framework.git/commitdiff
evolved IGridLayout's rendering + added test
authorMatti Tahvonen <matti.tahvonen@itmill.com>
Fri, 10 Aug 2007 06:26:56 +0000 (06:26 +0000)
committerMatti Tahvonen <matti.tahvonen@itmill.com>
Fri, 10 Aug 2007 06:26:56 +0000 (06:26 +0000)
svn changeset:1977/svn branch:trunk

src/com/itmill/toolkit/terminal/gwt/client/ui/IGridLayout.java
src/com/itmill/toolkit/tests/TestForGridLayoutChildComponentRendering.java [new file with mode: 0644]

index 7cf0c64fb03954aed65d8d23ffff007bd9cbbb95..ab91f7f0ffe4818250e38ae9adf5a89e0c822d4e 100644 (file)
@@ -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 (file)
index 0000000..23f9f47
--- /dev/null
@@ -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));
+               
+       }
+
+
+}
+
+