- Timestamp:
- 07/23/08 18:25:30 (4 months ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/com/itmill/toolkit/tests/book/TableEditableBean.java
r5113 r5114 5 5 package com.itmill.toolkit.tests.book; 6 6 7 import java.util.Calendar;8 import java.util.Collection;9 import java.util.Date;10 import java.util.GregorianCalendar;11 12 import com.itmill.toolkit.data.Container;13 7 import com.itmill.toolkit.data.Item; 14 8 import com.itmill.toolkit.data.Property; 15 9 import com.itmill.toolkit.data.Property.ValueChangeEvent; 16 10 import com.itmill.toolkit.data.util.BeanItem; 17 import com.itmill.toolkit.data.util.IndexedContainer; 18 import com.itmill.toolkit.ui.Button; 11 import com.itmill.toolkit.ui.BaseFieldFactory; 19 12 import com.itmill.toolkit.ui.CheckBox; 13 import com.itmill.toolkit.ui.Component; 20 14 import com.itmill.toolkit.ui.CustomComponent; 21 import com.itmill.toolkit.ui. Label;15 import com.itmill.toolkit.ui.Field; 22 16 import com.itmill.toolkit.ui.OrderedLayout; 23 import com.itmill.toolkit.ui.RichTextArea;24 17 import com.itmill.toolkit.ui.Table; 25 import com.itmill.toolkit.ui.TextField;26 import com.itmill.toolkit.ui.Button.ClickEvent;27 18 28 19 public class TableEditableBean extends CustomComponent { 29 20 public class MyBean { 30 boolean selected 1;31 boolean selected2;21 boolean selected; 22 String text; 32 23 33 24 public MyBean() { 34 selected 1= false;35 selected2 = false;25 selected = false; 26 text = "Hello"; 36 27 } 37 28 38 public boolean isSelected1() { 39 return selected1; 40 } 29 public boolean isSelected() { 30 System.out.println("isSelected() called: " + selected); 31 return selected; 32 } 41 33 42 public void setSelected1(boolean selected) {43 this.selected1= selected;44 System.out.println("setSelected1("+selected1+") called.");45 }34 public void setSelected(boolean selected) { 35 this.selected = selected; 36 System.out.println("setSelected1("+selected+") called."); 37 } 46 38 47 public boolean isSelected2() { 48 return selected2; 49 } 39 public String getText() { 40 System.out.println("getText() called: " + text); 41 return text; 42 } 50 43 51 public void setSelected2(boolean selected) {52 this.selected2 = selected;53 System.out.println("setSelected2("+selected+") called.");54 }44 public void setText(String text) { 45 this.text = text; 46 System.out.println("setText("+text+") called."); 47 } 55 48 }; 49 50 public class MyFieldFactory extends BaseFieldFactory { 51 public Field createField(Class type, Component uiContext) { 52 // Boolean field 53 if (Boolean.class.isAssignableFrom(type)) { 54 final CheckBox checkbox = new CheckBox(); 55 checkbox.setSwitchMode(true); 56 checkbox.setImmediate(true); 57 return checkbox; 58 } 59 return super.createField(type, uiContext); 60 } 61 } 62 63 public class MyTable extends Table { 64 /** Really adds an item and not just an item id. */ 65 public void addItem(Item item, Object itemId) { 66 67 } 68 } 56 69 57 70 TableEditableBean() { … … 63 76 final Table table = new Table(); 64 77 layout.addComponent(table); 78 table.setPageLength(8); 65 79 66 80 // Define the names and data types of columns. 67 table.addContainerProperty("selected 1", Boolean.class, null);68 table.addContainerProperty(" selected2", Boolean.class,null);81 table.addContainerProperty("selected", Boolean.class, null); 82 table.addContainerProperty("text", String.class, null); 69 83 70 84 // Add a few items in the table. 71 for (int i=0; i< 100; i++) {85 for (int i=0; i<5; i++) { 72 86 MyBean item = new MyBean(); 73 87 BeanItem bitem = new BeanItem(item); 74 table.addItem(new Object[] {bitem,bitem},75 new Integer(i)); // Item identifier88 //table.addItem(bitem); 89 table.addItem(new Object[]{bitem,bitem}, new Integer(i)); 76 90 } 77 91 78 table.setWriteThrough(true);79 table.set ReadThrough(true);80 table.setPageLength(8); 81 92 // Use custom field factory that sets the checkboxes in immediate mode. 93 table.setFieldFactory(new MyFieldFactory()); 94 95 // Have a check box to switch the table between normal and editable mode. 82 96 final CheckBox switchEditable = new CheckBox("Editable"); 83 97 switchEditable.addListener(new Property.ValueChangeListener() { 84 98 public void valueChange(ValueChangeEvent event) { 85 table.commit();86 99 table.setEditable(((Boolean)event.getProperty().getValue()).booleanValue()); 87 100 }
