]> source.dussan.org Git - vaadin-framework.git/commitdiff
commented
authorMarc Englund <marc.englund@itmill.com>
Tue, 4 Dec 2007 09:39:53 +0000 (09:39 +0000)
committerMarc Englund <marc.englund@itmill.com>
Tue, 4 Dec 2007 09:39:53 +0000 (09:39 +0000)
svn changeset:3137/svn branch:trunk

src/com/itmill/toolkit/demo/featurebrowser/TableExample.java

index cd31e9c44a6ca8280e2c6b79834d29b848aefabc..8139133d064a102be65823bc1a1bc19aa499c330 100644 (file)
@@ -35,19 +35,20 @@ public class TableExample extends CustomComponent implements Action.Handler,
     private static final Object PROPERTY_KIND = "Kind";\r
     private static final Object PROPERTY_HIRED = "Hired";\r
 \r
+    // "global" components\r
     Table source;\r
     Table saved;\r
-\r
     Button saveSelected;\r
     Button hireSelected;\r
     Button deleteSelected;\r
 \r
     public TableExample() {\r
-\r
+        // main layout\r
         OrderedLayout main = new OrderedLayout();\r
         main.setMargin(true);\r
         setCompositionRoot(main);\r
 \r
+        // "source" table with bells & whistlesenabled\r
         source = new Table("Also try the row context-menu");\r
         source.setPageLength(7);\r
         source.setWidth(550);\r
@@ -60,6 +61,7 @@ public class TableExample extends CustomComponent implements Action.Handler,
         source.addActionHandler(this);\r
         main.addComponent(source);\r
 \r
+        // x-selected button row\r
         OrderedLayout horiz = new OrderedLayout(\r
                 OrderedLayout.ORIENTATION_HORIZONTAL);\r
         horiz.setMargin(false, false, true, false);\r
@@ -77,6 +79,7 @@ public class TableExample extends CustomComponent implements Action.Handler,
         deleteSelected.addListener(this);\r
         horiz.addComponent(deleteSelected);\r
 \r
+        // "saved" table, minimalistic\r
         saved = new Table();\r
         saved.setPageLength(5);\r
         saved.setWidth(550);\r
@@ -88,6 +91,7 @@ public class TableExample extends CustomComponent implements Action.Handler,
         main.addComponent(saved);\r
     }\r
 \r
+    // set up the properties (columns)\r
     private void initProperties(Table table) {\r
         table.addContainerProperty(PROPERTY_SPECIES, String.class, "");\r
         table.addContainerProperty(PROPERTY_TYPE, String.class, "");\r
@@ -97,6 +101,7 @@ public class TableExample extends CustomComponent implements Action.Handler,
                         Boolean.FALSE);\r
     }\r
 \r
+    // fill the table with some random data\r
     private void fillTable(Table table) {\r
         initProperties(table);\r
 \r
@@ -117,9 +122,11 @@ public class TableExample extends CustomComponent implements Action.Handler,
 \r
     }\r
 \r
+    // Called for each item (row), returns valid actions for that item\r
     public Action[] getActions(Object target, Object sender) {\r
         if (sender == source) {\r
             Item item = source.getItem(target);\r
+            // save, delete, and hire if not already hired\r
             if (item != null\r
                     && item.getItemProperty(PROPERTY_HIRED).getValue() == Boolean.FALSE) {\r
                 return ACTIONS_HIRE;\r
@@ -127,14 +134,17 @@ public class TableExample extends CustomComponent implements Action.Handler,
                 return ACTIONS_NOHIRE;\r
             }\r
         } else {\r
+            // "saved" table only has one action\r
             return new Action[] { ACTION_DELETE };\r
         }\r
     }\r
 \r
+    // called when an action is invoked on an item (row)\r
     public void handleAction(Action action, Object sender, Object target) {\r
         if (sender == source) {\r
             Item item = source.getItem(target);\r
             if (action == ACTION_HIRE) {\r
+                // set HIRED property to true\r
                 item.getItemProperty(PROPERTY_HIRED).setValue(Boolean.TRUE);\r
                 source.requestRepaint();\r
                 if (saved.containsId(target)) {\r
@@ -142,13 +152,15 @@ public class TableExample extends CustomComponent implements Action.Handler,
                     item.getItemProperty(PROPERTY_HIRED).setValue(Boolean.TRUE);\r
                     saved.requestRepaint();\r
                 }\r
-\r
                 getWindow().showNotification("Hired", "" + item);\r
+\r
             } else if (action == ACTION_SAVE) {\r
                 if (saved.containsId(target)) {\r
+                    // let's not save twice\r
                     getWindow().showNotification("Already saved", "" + item);\r
                     return;\r
                 }\r
+                // "manual" copy of the item properties we want\r
                 Item added = saved.addItem(target);\r
                 Property p = added.getItemProperty(PROPERTY_SPECIES);\r
                 p.setValue(item.getItemProperty(PROPERTY_SPECIES).getValue());\r
@@ -164,6 +176,7 @@ public class TableExample extends CustomComponent implements Action.Handler,
                 getWindow().showNotification("Deleted ", "" + item);\r
                 source.removeItem(target);\r
             }\r
+\r
         } else {\r
             // sender==saved\r
             if (action == ACTION_DELETE) {\r
@@ -177,33 +190,32 @@ public class TableExample extends CustomComponent implements Action.Handler,
     public void buttonClick(ClickEvent event) {\r
         Button b = event.getButton();\r
         if (b == saveSelected) {\r
+            // loop each selected and copy to "saved" table\r
             Set selected = (Set) source.getValue();\r
-            if (selected != null) {\r
-                int s = 0;\r
-                for (Iterator it = selected.iterator(); it.hasNext();) {\r
-                    Object id = it.next();\r
-                    if (!saved.containsId(id)) {\r
-                        Item item = source.getItem(id);\r
-                        Item added = saved.addItem(id);\r
-                        Property p = added.getItemProperty(PROPERTY_SPECIES);\r
-                        p.setValue(item.getItemProperty(PROPERTY_SPECIES)\r
-                                .getValue());\r
-                        p = added.getItemProperty(PROPERTY_TYPE);\r
-                        p.setValue(item.getItemProperty(PROPERTY_TYPE)\r
-                                .getValue());\r
-                        p = added.getItemProperty(PROPERTY_KIND);\r
-                        p.setValue(item.getItemProperty(PROPERTY_KIND)\r
-                                .getValue());\r
-                        p = added.getItemProperty(PROPERTY_HIRED);\r
-                        p.setValue(item.getItemProperty(PROPERTY_HIRED)\r
-                                .getValue());\r
-                        s++;\r
-                    }\r
+            int s = 0;\r
+            for (Iterator it = selected.iterator(); it.hasNext();) {\r
+                Object id = it.next();\r
+                if (!saved.containsId(id)) {\r
+                    Item item = source.getItem(id);\r
+                    Item added = saved.addItem(id);\r
+                    // "manual" copy of the properties we want\r
+                    Property p = added.getItemProperty(PROPERTY_SPECIES);\r
+                    p.setValue(item.getItemProperty(PROPERTY_SPECIES)\r
+                            .getValue());\r
+                    p = added.getItemProperty(PROPERTY_TYPE);\r
+                    p.setValue(item.getItemProperty(PROPERTY_TYPE).getValue());\r
+                    p = added.getItemProperty(PROPERTY_KIND);\r
+                    p.setValue(item.getItemProperty(PROPERTY_KIND).getValue());\r
+                    p = added.getItemProperty(PROPERTY_HIRED);\r
+                    p.setValue(item.getItemProperty(PROPERTY_HIRED).getValue());\r
+                    s++;\r
                 }\r
-                getWindow().showNotification("Saved " + s);\r
-                saved.requestRepaint();\r
             }\r
+            getWindow().showNotification("Saved " + s);\r
+            saved.requestRepaint();\r
+\r
         } else if (b == hireSelected) {\r
+            // loop each selected and set property HIRED to true\r
             int s = 0;\r
             Set selected = (Set) source.getValue();\r
             for (Iterator it = selected.iterator(); it.hasNext();) {\r
@@ -216,6 +228,7 @@ public class TableExample extends CustomComponent implements Action.Handler,
                     s++;\r
                 }\r
                 if (saved.containsId(id)) {\r
+                    // also update "saved" table\r
                     item = saved.getItem(id);\r
                     item.getItemProperty(PROPERTY_HIRED).setValue(Boolean.TRUE);\r
                     saved.requestRepaint();\r
@@ -224,7 +237,7 @@ public class TableExample extends CustomComponent implements Action.Handler,
             getWindow().showNotification("Hired " + s);\r
 \r
         } else {\r
-            // delete selected\r
+            // loop trough selected and delete\r
             int s = 0;\r
             Set selected = (Set) source.getValue();\r
             for (Iterator it = selected.iterator(); it.hasNext();) {\r