"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",
}
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());
}
--- /dev/null
+/*
+@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);
+ }
+}
--- /dev/null
+/*
+@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);
+ }
+}