Show
Ignore:
Timestamp:
07/23/08 18:25:30 (4 months ago)
Author:
magi@…
Message:

Updated Table editing test.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/src/com/itmill/toolkit/tests/book/TableEditableBean.java

    r5113 r5114  
    55package com.itmill.toolkit.tests.book; 
    66 
    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; 
    137import com.itmill.toolkit.data.Item; 
    148import com.itmill.toolkit.data.Property; 
    159import com.itmill.toolkit.data.Property.ValueChangeEvent; 
    1610import com.itmill.toolkit.data.util.BeanItem; 
    17 import com.itmill.toolkit.data.util.IndexedContainer; 
    18 import com.itmill.toolkit.ui.Button; 
     11import com.itmill.toolkit.ui.BaseFieldFactory; 
    1912import com.itmill.toolkit.ui.CheckBox; 
     13import com.itmill.toolkit.ui.Component; 
    2014import com.itmill.toolkit.ui.CustomComponent; 
    21 import com.itmill.toolkit.ui.Label; 
     15import com.itmill.toolkit.ui.Field; 
    2216import com.itmill.toolkit.ui.OrderedLayout; 
    23 import com.itmill.toolkit.ui.RichTextArea; 
    2417import com.itmill.toolkit.ui.Table; 
    25 import com.itmill.toolkit.ui.TextField; 
    26 import com.itmill.toolkit.ui.Button.ClickEvent; 
    2718 
    2819public class TableEditableBean extends CustomComponent { 
    2920        public class MyBean { 
    30                 boolean selected1; 
    31                 boolean selected2; 
     21                boolean selected; 
     22                String  text; 
    3223                 
    3324                public MyBean() { 
    34                         selected1 = false; 
    35                         selected2 = false; 
     25                        selected = false; 
     26                        text     = "Hello"; 
    3627                } 
    3728 
    38                 public boolean isSelected1() { 
    39                         return selected1; 
    40                 } 
     29                public boolean isSelected() { 
     30                    System.out.println("isSelected() called: " + selected); 
     31            return selected; 
     32        } 
    4133 
    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        } 
    4638 
    47                 public boolean isSelected2() { 
    48                         return selected2; 
    49                 } 
     39        public String getText() { 
     40            System.out.println("getText() called: " + text); 
     41            return text; 
     42        } 
    5043 
    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        } 
    5548        }; 
     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        } 
    5669 
    5770    TableEditableBean() { 
     
    6376        final Table table = new Table(); 
    6477        layout.addComponent(table); 
     78        table.setPageLength(8); 
    6579         
    6680        // Define the names and data types of columns. 
    67         table.addContainerProperty("selected1", Boolean.class, null); 
    68         table.addContainerProperty("selected2", Boolean.class, null); 
     81        table.addContainerProperty("selected", Boolean.class, null); 
     82        table.addContainerProperty("text",      String.class, null); 
    6983         
    7084        // Add a few items in the table. 
    71         for (int i=0; i<100; i++) { 
     85        for (int i=0; i<5; i++) { 
    7286                MyBean item = new MyBean(); 
    7387                BeanItem bitem = new BeanItem(item); 
    74             table.addItem(new Object[] {bitem,bitem}, 
    75                         new Integer(i)); // Item identifier 
     88                //table.addItem(bitem); 
     89                table.addItem(new Object[]{bitem,bitem}, new Integer(i)); 
    7690        } 
    7791         
    78         table.setWriteThrough(true); 
    79         table.setReadThrough(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. 
    8296        final CheckBox switchEditable = new CheckBox("Editable"); 
    8397        switchEditable.addListener(new Property.ValueChangeListener() { 
    8498            public void valueChange(ValueChangeEvent event) { 
    85                 table.commit(); 
    8699                table.setEditable(((Boolean)event.getProperty().getValue()).booleanValue()); 
    87100            }