From 36262e475ded6021dc3a32500bbd808f7cd21e04 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Marko=20Gr=C3=B6nroos?= Date: Wed, 23 Jul 2008 18:25:30 +0000 Subject: [PATCH] Updated Table editing test. svn changeset:5114/svn branch:trunk --- .../toolkit/tests/book/TableEditableBean.java | 93 +++++++++++-------- 1 file changed, 53 insertions(+), 40 deletions(-) diff --git a/src/com/itmill/toolkit/tests/book/TableEditableBean.java b/src/com/itmill/toolkit/tests/book/TableEditableBean.java index 966095a481..4d13fa7f80 100644 --- a/src/com/itmill/toolkit/tests/book/TableEditableBean.java +++ b/src/com/itmill/toolkit/tests/book/TableEditableBean.java @@ -4,55 +4,68 @@ package com.itmill.toolkit.tests.book; -import java.util.Calendar; -import java.util.Collection; -import java.util.Date; -import java.util.GregorianCalendar; - -import com.itmill.toolkit.data.Container; import com.itmill.toolkit.data.Item; import com.itmill.toolkit.data.Property; import com.itmill.toolkit.data.Property.ValueChangeEvent; import com.itmill.toolkit.data.util.BeanItem; -import com.itmill.toolkit.data.util.IndexedContainer; -import com.itmill.toolkit.ui.Button; +import com.itmill.toolkit.ui.BaseFieldFactory; import com.itmill.toolkit.ui.CheckBox; +import com.itmill.toolkit.ui.Component; import com.itmill.toolkit.ui.CustomComponent; -import com.itmill.toolkit.ui.Label; +import com.itmill.toolkit.ui.Field; 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 TableEditableBean extends CustomComponent { public class MyBean { - boolean selected1; - boolean selected2; + boolean selected; + String text; public MyBean() { - selected1 = false; - selected2 = false; + selected = false; + text = "Hello"; } - public boolean isSelected1() { - return selected1; - } + public boolean isSelected() { + System.out.println("isSelected() called: " + selected); + return selected; + } - public void setSelected1(boolean selected) { - this.selected1 = selected; - System.out.println("setSelected1("+selected1+") called."); - } + public void setSelected(boolean selected) { + this.selected = selected; + System.out.println("setSelected1("+selected+") called."); + } - public boolean isSelected2() { - return selected2; - } + public String getText() { + System.out.println("getText() called: " + text); + return text; + } - public void setSelected2(boolean selected) { - this.selected2 = selected; - System.out.println("setSelected2("+selected+") called."); - } + public void setText(String text) { + this.text = text; + System.out.println("setText("+text+") called."); + } }; + + public class MyFieldFactory extends BaseFieldFactory { + public Field createField(Class type, Component uiContext) { + // Boolean field + if (Boolean.class.isAssignableFrom(type)) { + final CheckBox checkbox = new CheckBox(); + checkbox.setSwitchMode(true); + checkbox.setImmediate(true); + return checkbox; + } + return super.createField(type, uiContext); + } + } + + public class MyTable extends Table { + /** Really adds an item and not just an item id. */ + public void addItem(Item item, Object itemId) { + + } + } TableEditableBean() { /* A layout needed for the example. */ @@ -62,27 +75,27 @@ public class TableEditableBean extends CustomComponent { // Create a table. It is by default not editable. final Table table = new Table(); layout.addComponent(table); + table.setPageLength(8); // Define the names and data types of columns. - table.addContainerProperty("selected1", Boolean.class, null); - table.addContainerProperty("selected2", Boolean.class, null); + table.addContainerProperty("selected", Boolean.class, null); + table.addContainerProperty("text", String.class, null); // Add a few items in the table. - for (int i=0; i<100; i++) { + for (int i=0; i<5; i++) { MyBean item = new MyBean(); BeanItem bitem = new BeanItem(item); - table.addItem(new Object[] {bitem,bitem}, - new Integer(i)); // Item identifier + //table.addItem(bitem); + table.addItem(new Object[]{bitem,bitem}, new Integer(i)); } - table.setWriteThrough(true); - table.setReadThrough(true); - table.setPageLength(8); - + // Use custom field factory that sets the checkboxes in immediate mode. + table.setFieldFactory(new MyFieldFactory()); + + // Have a check box to switch the table between normal and editable mode. final CheckBox switchEditable = new CheckBox("Editable"); switchEditable.addListener(new Property.ValueChangeListener() { public void valueChange(ValueChangeEvent event) { - table.commit(); table.setEditable(((Boolean)event.getProperty().getValue()).booleanValue()); } }); -- 2.39.5