From 3b7caf79414d077a76562249d6357e4e9019abfe Mon Sep 17 00:00:00 2001 From: =?utf8?q?Marko=20Gr=C3=B6nroos?= Date: Fri, 11 Jul 2008 16:59:56 +0000 Subject: [PATCH] Updated book examples. Components inside Tables, editable Tables. svn changeset:5100/svn branch:trunk --- .../tests/book/BookTestApplication.java | 24 +++--- .../toolkit/tests/book/TableEditable.java | 62 +++++++++++++++ .../toolkit/tests/book/TableExample3.java | 78 +++++++++++++++++++ 3 files changed, 155 insertions(+), 9 deletions(-) create mode 100644 src/com/itmill/toolkit/tests/book/TableEditable.java create mode 100644 src/com/itmill/toolkit/tests/book/TableExample3.java diff --git a/src/com/itmill/toolkit/tests/book/BookTestApplication.java b/src/com/itmill/toolkit/tests/book/BookTestApplication.java index 59764ccadd..e4a48fc4ca 100644 --- a/src/com/itmill/toolkit/tests/book/BookTestApplication.java +++ b/src/com/itmill/toolkit/tests/book/BookTestApplication.java @@ -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 index 0000000000..76c4f4e100 --- /dev/null +++ b/src/com/itmill/toolkit/tests/book/TableEditable.java @@ -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 index 0000000000..43ce9f6790 --- /dev/null +++ b/src/com/itmill/toolkit/tests/book/TableExample3.java @@ -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 $%04.2f
(VAT incl.)", + 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); + } +} -- 2.39.5