]> source.dussan.org Git - vaadin-framework.git/commitdiff
added test case
authorMatti Tahvonen <matti.tahvonen@itmill.com>
Tue, 26 Aug 2008 12:57:59 +0000 (12:57 +0000)
committerMatti Tahvonen <matti.tahvonen@itmill.com>
Tue, 26 Aug 2008 12:57:59 +0000 (12:57 +0000)
svn changeset:5270/svn branch:trunk

src/com/itmill/toolkit/tests/tickets/Ticket1245.java [new file with mode: 0644]

diff --git a/src/com/itmill/toolkit/tests/tickets/Ticket1245.java b/src/com/itmill/toolkit/tests/tickets/Ticket1245.java
new file mode 100644 (file)
index 0000000..cd7555d
--- /dev/null
@@ -0,0 +1,92 @@
+package com.itmill.toolkit.tests.tickets;\r
+\r
+import com.itmill.toolkit.data.Item;\r
+import com.itmill.toolkit.data.Property;\r
+import com.itmill.toolkit.ui.AbstractSelect;\r
+import com.itmill.toolkit.ui.CustomComponent;\r
+import com.itmill.toolkit.ui.Label;\r
+import com.itmill.toolkit.ui.OrderedLayout;\r
+import com.itmill.toolkit.ui.Panel;\r
+import com.itmill.toolkit.ui.TextField;\r
+import com.itmill.toolkit.ui.Tree;\r
+import com.itmill.toolkit.ui.Window;\r
+\r
+public class Ticket1245 extends com.itmill.toolkit.Application {\r
+\r
+    TextField f = new TextField();\r
+\r
+    public void init() {\r
+        final Window main = new Window(getClass().getName().substring(\r
+                getClass().getName().lastIndexOf(".") + 1));\r
+        setMainWindow(main);\r
+\r
+        main.addComponent(new TreeExample());\r
+    }\r
+}\r
+\r
+class TreeExample extends CustomComponent {\r
+\r
+    // Id for the caption property\r
+    private static final Object CAPTION_PROPERTY = "caption";\r
+\r
+    private static final String desc = "non-first tree in non-sized orderedlayout seems to be the problem";\r
+\r
+    Tree tree;\r
+\r
+    public TreeExample() {\r
+        final OrderedLayout main = new OrderedLayout();\r
+        setCompositionRoot(main);\r
+\r
+        // Panel w/ Tree\r
+        main.setStyleName(Panel.STYLE_LIGHT);\r
+        main.setWidth(200);\r
+        // // Description, this is needed. Works in first slot\r
+        main.addComponent(new Label(desc));\r
+\r
+        // setting either width or height fixes the issue\r
+        // p.setWidth(500);\r
+        // p.setHeight(800);\r
+\r
+        // Tree with a few items\r
+        tree = new Tree();\r
+        tree.setImmediate(true);\r
+        // we'll use a property for caption instead of the item id ("value"),\r
+        // so that multiple items can have the same caption\r
+        tree.addContainerProperty(CAPTION_PROPERTY, String.class, "");\r
+        tree.setItemCaptionMode(AbstractSelect.ITEM_CAPTION_MODE_PROPERTY);\r
+        tree.setItemCaptionPropertyId(CAPTION_PROPERTY);\r
+        for (int i = 1; i <= 3; i++) {\r
+            final Object id = addCaptionedItem("Section " + i, null);\r
+            tree.expandItem(id);\r
+            addCaptionedItem("Team A", id);\r
+            addCaptionedItem("Team B", id);\r
+        }\r
+        main.addComponent(tree);\r
+    }\r
+\r
+    /**\r
+     * Helper to add an item with specified caption and (optional) parent.\r
+     * \r
+     * @param caption\r
+     *                The item caption\r
+     * @param parent\r
+     *                The (optional) parent item id\r
+     * @return the created item's id\r
+     */\r
+    private Object addCaptionedItem(String caption, Object parent) {\r
+        // add item, let tree decide id\r
+        final Object id = tree.addItem();\r
+        // get the created item\r
+        final Item item = tree.getItem(id);\r
+        // set our "caption" property\r
+        final Property p = item.getItemProperty(CAPTION_PROPERTY);\r
+        p.setValue(caption);\r
+        if (parent != null) {\r
+            tree.setChildrenAllowed(parent, true);\r
+            tree.setParent(id, parent);\r
+            tree.setChildrenAllowed(id, false);\r
+        }\r
+        return id;\r
+    }\r
+\r
+}
\ No newline at end of file