]> source.dussan.org Git - vaadin-framework.git/commitdiff
Updated book examples. Components inside Tables, editable Tables.
authorMarko Grönroos <magi@iki.fi>
Fri, 11 Jul 2008 16:59:56 +0000 (16:59 +0000)
committerMarko Grönroos <magi@iki.fi>
Fri, 11 Jul 2008 16:59:56 +0000 (16:59 +0000)
svn changeset:5100/svn branch:trunk

src/com/itmill/toolkit/tests/book/BookTestApplication.java
src/com/itmill/toolkit/tests/book/TableEditable.java [new file with mode: 0644]
src/com/itmill/toolkit/tests/book/TableExample3.java [new file with mode: 0644]

index 59764ccadd1faba3718239508227d1f4db15711f..e4a48fc4cad1ebeaf81c31b30e986469a660858b 100644 (file)
@@ -132,7 +132,7 @@ public class BookTestApplication extends com.itmill.toolkit.Application {
                         "labelcontent", "tree", "embedded", "textfield",
                         "textfieldvalidation", "datefield", "button",
                         "select/select", "select/native", "select/optiongroup",
-                        "select/twincol", "filterselect", "validator", "table", "table/select",
+                        "select/twincol", "filterselect", "validator", "table", "table/select", "table/component", "table/paging", "table/editable",
                         "upload", "link", "gridlayout", "orderedlayout",
                         "formlayout", "form", "form/simple", "form/layout", "panel", "expandlayout", "expandlayout/root", "tabsheet",
                         "alignment", "alignment/grid", "window", "window/opener",
@@ -547,14 +547,20 @@ public class BookTestApplication extends com.itmill.toolkit.Application {
     }
     
     void example_Table(Window main, String param) {
-        if (param != null && param.equals("select")) {
-            main.addComponent(new TableExample2());
-        } else if (param != null && param.equals("paging")) {
-            PagingTable table = new PagingTable();
-            table.addContainerProperty("Column 1", String.class, null);
-            for (int i=0; i<100; i++)
-                table.addItem(new Object[]{"Item "+i}, new Integer(i));
-            main.addComponent(table);
+        if (param != null) {
+            if (param.equals("select")) {
+                main.addComponent(new TableExample2());
+            } else if (param.equals("component")) {
+                main.addComponent(new TableExample3());
+            } else if (param.equals("editable")) {
+                main.addComponent(new TableEditable());
+            } else if (param.equals("paging")) {
+                PagingTable table = new PagingTable();
+                table.addContainerProperty("Column 1", String.class, null);
+                for (int i=0; i<100; i++)
+                    table.addItem(new Object[]{"Item "+i}, new Integer(i));
+                main.addComponent(table);
+            }
         }else
             main.addComponent(new TableExample1());
     }
diff --git a/src/com/itmill/toolkit/tests/book/TableEditable.java b/src/com/itmill/toolkit/tests/book/TableEditable.java
new file mode 100644 (file)
index 0000000..76c4f4e
--- /dev/null
@@ -0,0 +1,62 @@
+/* 
+@ITMillApache2LicenseForJavaFiles@
+ */
+
+package com.itmill.toolkit.tests.book;
+
+import java.util.Calendar;
+import java.util.Date;
+import java.util.GregorianCalendar;
+
+import com.itmill.toolkit.data.Property;
+import com.itmill.toolkit.data.Property.ValueChangeEvent;
+import com.itmill.toolkit.ui.Button;
+import com.itmill.toolkit.ui.CheckBox;
+import com.itmill.toolkit.ui.CustomComponent;
+import com.itmill.toolkit.ui.Label;
+import com.itmill.toolkit.ui.OrderedLayout;
+import com.itmill.toolkit.ui.RichTextArea;
+import com.itmill.toolkit.ui.Table;
+import com.itmill.toolkit.ui.TextField;
+import com.itmill.toolkit.ui.Button.ClickEvent;
+
+public class TableEditable extends CustomComponent {
+    /* A layout needed for the example. */
+    OrderedLayout layout = new OrderedLayout(OrderedLayout.ORIENTATION_VERTICAL);
+    
+    TableEditable() {
+        setCompositionRoot(layout);
+
+        // Create a table. It is by default not editable.
+        final Table table = new Table();
+        
+        // Define the names and data types of columns.
+        table.addContainerProperty("Date",     Date.class,  null);
+        table.addContainerProperty("Work",     Boolean.class, null);
+        table.addContainerProperty("Comments", String.class,  null);
+        
+        // Add a few items in the table.
+        for (int i=0; i<100; i++) {
+            Calendar calendar = new GregorianCalendar(2008,0,1);
+            calendar.add(Calendar.DAY_OF_YEAR, i);
+            
+            // Create the table row.
+            table.addItem(new Object[] {calendar.getTime(),
+                                        new Boolean(false),
+                                        ""},
+                          new Integer(i)); // Item identifier
+        }
+        
+        table.setPageLength(8);
+        layout.addComponent(table);
+        
+        final CheckBox switchEditable = new CheckBox("Editable");
+        switchEditable.addListener(new Property.ValueChangeListener() {
+            public void valueChange(ValueChangeEvent event) {
+                table.setEditable(((Boolean)event.getProperty().getValue()).booleanValue());
+            }
+        });
+        switchEditable.setImmediate(true);
+        layout.addComponent(switchEditable);
+    }
+}
diff --git a/src/com/itmill/toolkit/tests/book/TableExample3.java b/src/com/itmill/toolkit/tests/book/TableExample3.java
new file mode 100644 (file)
index 0000000..43ce9f6
--- /dev/null
@@ -0,0 +1,78 @@
+/* 
+@ITMillApache2LicenseForJavaFiles@
+ */
+
+package com.itmill.toolkit.tests.book;
+
+import com.itmill.toolkit.data.Property;
+import com.itmill.toolkit.data.Property.ValueChangeEvent;
+import com.itmill.toolkit.ui.Button;
+import com.itmill.toolkit.ui.CheckBox;
+import com.itmill.toolkit.ui.CustomComponent;
+import com.itmill.toolkit.ui.Label;
+import com.itmill.toolkit.ui.OrderedLayout;
+import com.itmill.toolkit.ui.RichTextArea;
+import com.itmill.toolkit.ui.Table;
+import com.itmill.toolkit.ui.TextField;
+import com.itmill.toolkit.ui.Button.ClickEvent;
+
+public class TableExample3 extends CustomComponent {
+    /* A layout needed for the example. */
+    OrderedLayout layout = new OrderedLayout(OrderedLayout.ORIENTATION_VERTICAL);
+    
+    TableExample3() {
+        setCompositionRoot(layout);
+
+        // Create a table and add a style to allow setting the row height in theme.
+        final Table table = new Table();
+        table.addStyleName("components-inside");
+        
+        /* Define the names and data types of columns.
+         * The "default value" parameter is meaningless here. */
+        table.addContainerProperty("Sum",            Label.class,     null);
+        table.addContainerProperty("Is Transferred", CheckBox.class,  null);
+        table.addContainerProperty("Comments",       TextField.class, null);
+        table.addContainerProperty("Details",        Button.class,    null);
+
+        /* Add a few items in the table. */
+        for (int i=0; i<100; i++) {
+            // Create the fields for the current table row
+            Label sumField = new Label(String.format("Sum is <b>$%04.2f</b><br/><i>(VAT incl.)</i>",
+                                  new Object[] {new Double(Math.random()*1000)}),
+                                  Label.CONTENT_XHTML);
+            CheckBox transferredField = new CheckBox("is transferred");
+            
+            // Multiline text field. This required modifying the height of the
+            // table row.
+            TextField commentsField = new TextField();
+            commentsField.setRows(3);
+            
+            // The Table item identifier for the row.
+            Integer itemId = new Integer(i);
+            
+            // Create a button and handle its click. A Button does not know
+            // the item it is contained in, so we have to store the item
+            // ID as user-defined data.
+            Button detailsField = new Button("show details");
+            detailsField.setData(itemId);
+            detailsField.addListener(new Button.ClickListener() {
+                public void buttonClick(ClickEvent event) {
+                    // Get the item identifier from the user-defined data.
+                    Integer itemId = (Integer)event.getButton().getData();
+                    getWindow().showNotification("Link "+itemId.intValue()+" clicked.");
+                } 
+            });
+            detailsField.addStyleName("link");
+            
+            // Create the table row.
+            table.addItem(new Object[] {sumField, transferredField,
+                                        commentsField, detailsField},
+                          itemId);
+        }
+        
+        /* Show just three rows because they are so high. */
+        table.setPageLength(3);
+
+        layout.addComponent(table);
+    }
+}