]> source.dussan.org Git - vaadin-framework.git/commitdiff
ItemStyleGenerator.getStyle now includes source component (#5822)
authorArtur Signell <artur@vaadin.com>
Tue, 4 Sep 2012 06:38:38 +0000 (09:38 +0300)
committerArtur Signell <artur@vaadin.com>
Tue, 4 Sep 2012 06:39:00 +0000 (09:39 +0300)
server/src/com/vaadin/ui/Table.java
server/src/com/vaadin/ui/Tree.java
uitest/src/com/vaadin/tests/Components.java
uitest/src/com/vaadin/tests/components/table/CellStyleGeneratorTest.java
uitest/src/com/vaadin/tests/components/table/Tables.java
uitest/src/com/vaadin/tests/components/tree/ItemStyleGenerator.java
uitest/src/com/vaadin/tests/components/tree/Trees.java
uitest/src/com/vaadin/tests/components/treetable/TreeTableTest.java
uitest/src/com/vaadin/tests/tickets/Ticket1857.java
uitest/src/com/vaadin/tests/tickets/Ticket2125.java
uitest/src/com/vaadin/tests/tickets/Ticket2208.java

index 5eb18ee61f8f3ef408592b186eb6aad2d7735c96..65189fed0c9c8d4262d9e85da8798516d2719043 100644 (file)
@@ -3479,8 +3479,8 @@ public class Table extends AbstractSelect implements Action.Container,
              * target.
              */
             if (cellStyleGenerator != null) {
-                String cellStyle = cellStyleGenerator
-                        .getStyle(itemId, columnId);
+                String cellStyle = cellStyleGenerator.getStyle(this, itemId,
+                        columnId);
                 if (cellStyle != null && !cellStyle.equals("")) {
                     target.addAttribute("style-" + columnIdMap.key(columnId),
                             cellStyle);
@@ -3567,7 +3567,7 @@ public class Table extends AbstractSelect implements Action.Container,
          * to the target.
          */
         if (cellStyleGenerator != null) {
-            String rowStyle = cellStyleGenerator.getStyle(itemId, null);
+            String rowStyle = cellStyleGenerator.getStyle(this, itemId, null);
             if (rowStyle != null && !rowStyle.equals("")) {
                 target.addAttribute("rowstyle", rowStyle);
             }
@@ -4602,6 +4602,8 @@ public class Table extends AbstractSelect implements Action.Container,
         /**
          * Called by Table when a cell (and row) is painted.
          * 
+         * @param source
+         *            the source Table
          * @param itemId
          *            The itemId of the painted cell
          * @param propertyId
@@ -4610,7 +4612,8 @@ public class Table extends AbstractSelect implements Action.Container,
          *         name will be v-table-cell-content-[style name], or
          *         v-table-row-[style name] for rows)
          */
-        public abstract String getStyle(Object itemId, Object propertyId);
+        public abstract String getStyle(Table source, Object itemId,
+                Object propertyId);
     }
 
     @Override
index ad3674fe1ece4ae393de6f8e933fa61dfbcf864b..306d1f18bab36cd48302770939cd6595e576a7e0 100644 (file)
@@ -611,7 +611,8 @@ public class Tree extends AbstractSelect implements Container.Hierarchical,
                 }
 
                 if (itemStyleGenerator != null) {
-                    String stylename = itemStyleGenerator.getStyle(itemId);
+                    String stylename = itemStyleGenerator
+                            .getStyle(this, itemId);
                     if (stylename != null) {
                         target.addAttribute(TreeConstants.ATTRIBUTE_NODE_STYLE,
                                 stylename);
@@ -1255,12 +1256,14 @@ public class Tree extends AbstractSelect implements Container.Hierarchical,
         /**
          * Called by Tree when an item is painted.
          * 
+         * @param source
+         *            the source Tree
          * @param itemId
          *            The itemId of the item to be painted
          * @return The style name to add to this item. (the CSS class name will
          *         be v-tree-node-[style name]
          */
-        public abstract String getStyle(Object itemId);
+        public abstract String getStyle(Tree source, Object itemId);
     }
 
     // Overriden so javadoc comes from Container.Hierarchical
index 5882c5cdb11b09475a1a45158abdced5085370e1..7ac1b55d350e1af26c9a197167119765addde5f0 100644 (file)
@@ -25,9 +25,9 @@ import com.vaadin.ui.ComponentContainer;
 import com.vaadin.ui.Embedded;
 import com.vaadin.ui.HorizontalSplitPanel;
 import com.vaadin.ui.Label;
-import com.vaadin.ui.UI.LegacyWindow;
 import com.vaadin.ui.Tree;
 import com.vaadin.ui.Tree.ItemStyleGenerator;
+import com.vaadin.ui.UI.LegacyWindow;
 import com.vaadin.ui.VerticalLayout;
 
 public class Components extends Application.LegacyApplication {
@@ -138,7 +138,7 @@ public class Components extends Application.LegacyApplication {
         naviTree.setItemStyleGenerator(new ItemStyleGenerator() {
 
             @Override
-            public String getStyle(Object itemId) {
+            public String getStyle(Tree source, Object itemId) {
                 Class<?> cls = (Class<?>) itemId;
                 if (!isAbstract(cls)) {
                     return "blue";
index 35f35c1407f57aced21d6e1bfd8ff6f4a064b416..fb4bc5a04549431b7f35f733fe648afc46dd0944 100644 (file)
@@ -17,7 +17,8 @@ public class CellStyleGeneratorTest extends TestBase {
         CellStyleGenerator g = new CellStyleGenerator() {
 
             @Override
-            public String getStyle(Object itemId, Object propertyId) {
+            public String getStyle(Table source, Object itemId,
+                    Object propertyId) {
                 if (propertyId != null && propertyId.equals("red")) {
                     return "red";
                 } else if (itemId.equals("blue") && propertyId == null) {
index 1431155b1ad9188cc868c532b7291f41de020e38..a08533fdbd2a90b56eb98b1162010ffbc2ee062e 100644 (file)
@@ -335,7 +335,8 @@ public class Tables<T extends Table> extends AbstractSelectTestCase<T>
                 c.setCellStyleGenerator(new CellStyleGenerator() {
 
                     @Override
-                    public String getStyle(Object itemId, Object propertyId) {
+                    public String getStyle(Table source, Object itemId,
+                            Object propertyId) {
                         if (cellStyleInfo.appliesTo(itemId, propertyId)) {
                             return cellStyleInfo.styleName;
                         }
index 33bd4cef65674307cc73affc6637d86576cf6f93..c561781d2b039fb1b99b261f29d6f0423db74416 100644 (file)
@@ -33,7 +33,7 @@ public class ItemStyleGenerator extends TestBase {
 
         tree.setItemStyleGenerator(new Tree.ItemStyleGenerator() {
             @Override
-            public String getStyle(Object itemId) {
+            public String getStyle(Tree source, Object itemId) {
                 // simple return itemId as css style name
                 return itemId.toString();
             }
index 3ee1d7b0de9f5dbadb25e8929c8498c51356c827..8796fb854ce74fbb6f851da9e15263a0865f3d05 100644 (file)
@@ -27,7 +27,7 @@ public class Trees extends AbstractSelectTestCase<Tree> implements
     private ItemStyleGenerator rootGreenSecondLevelRed = new com.vaadin.ui.Tree.ItemStyleGenerator() {
 
         @Override
-        public String getStyle(Object itemId) {
+        public String getStyle(Tree source, Object itemId) {
             Hierarchical c = (Container.Hierarchical) getComponent()
                     .getContainerDataSource();
             if (c.isRoot(itemId)) {
@@ -52,7 +52,7 @@ public class Trees extends AbstractSelectTestCase<Tree> implements
     private ItemStyleGenerator evenItemsBold = new com.vaadin.ui.Tree.ItemStyleGenerator() {
 
         @Override
-        public String getStyle(Object itemId) {
+        public String getStyle(Tree source, Object itemId) {
             Hierarchical c = (Container.Hierarchical) getComponent()
                     .getContainerDataSource();
             int idx = 0;
index f27a47f12bea92a258badf7a9629bc2ad4b18942..8fafdb2d26159ad8dc261f46c469c3f716059fb0 100644 (file)
@@ -9,6 +9,7 @@ import com.vaadin.data.Container;
 import com.vaadin.data.Container.Hierarchical;
 import com.vaadin.data.util.HierarchicalContainer;
 import com.vaadin.tests.components.table.Tables;
+import com.vaadin.ui.Table;
 import com.vaadin.ui.Table.CellStyleGenerator;
 import com.vaadin.ui.Tree.CollapseEvent;
 import com.vaadin.ui.Tree.CollapseListener;
@@ -28,7 +29,7 @@ public class TreeTableTest extends Tables<TreeTable> implements
     private CellStyleGenerator rootGreenSecondLevelRed = new com.vaadin.ui.Table.CellStyleGenerator() {
 
         @Override
-        public String getStyle(Object itemId, Object propertyId) {
+        public String getStyle(Table source, Object itemId, Object propertyId) {
             if (propertyId != null) {
                 return null;
             }
@@ -56,7 +57,7 @@ public class TreeTableTest extends Tables<TreeTable> implements
     private CellStyleGenerator evenItemsBold = new CellStyleGenerator() {
 
         @Override
-        public String getStyle(Object itemId, Object propertyId) {
+        public String getStyle(Table source, Object itemId, Object propertyId) {
             if (propertyId != null) {
                 return null;
             }
index 039f867ffffc1699f499fa55109c91ce42bcf7ea..be0158e0fbe1a0ca13ae66aed2ba69af9be5eb1b 100644 (file)
@@ -7,8 +7,8 @@ import com.vaadin.event.Action;
 import com.vaadin.event.Action.Handler;
 import com.vaadin.ui.CheckBox;
 import com.vaadin.ui.HorizontalLayout;
-import com.vaadin.ui.UI.LegacyWindow;
 import com.vaadin.ui.Table;
+import com.vaadin.ui.UI.LegacyWindow;
 import com.vaadin.ui.VerticalLayout;
 
 public class Ticket1857 extends Application.LegacyApplication implements
@@ -60,7 +60,8 @@ public class Ticket1857 extends Application.LegacyApplication implements
                 if (cellStylesEnabler.getValue().booleanValue()) {
                     t.setCellStyleGenerator(new Table.CellStyleGenerator() {
                         @Override
-                        public String getStyle(Object itemId, Object propertyId) {
+                        public String getStyle(Table source, Object itemId,
+                                Object propertyId) {
                             Object cell = t.getContainerProperty(itemId,
                                     propertyId).getValue();
                             if (!(cell instanceof Integer)) {
index bc1f8864185af2437d2867b15a6ccb3bf8c9d09b..defd7f4a22318d3226ce41c332c6d715b2b637f2 100644 (file)
@@ -5,10 +5,10 @@ import com.vaadin.data.util.MethodProperty;
 import com.vaadin.ui.CheckBox;
 import com.vaadin.ui.Component;
 import com.vaadin.ui.Label;
-import com.vaadin.ui.UI.LegacyWindow;
 import com.vaadin.ui.Table;
 import com.vaadin.ui.Table.CellStyleGenerator;
 import com.vaadin.ui.Table.ColumnGenerator;
+import com.vaadin.ui.UI.LegacyWindow;
 
 public class Ticket2125 extends Application.LegacyApplication {
 
@@ -42,7 +42,8 @@ public class Ticket2125 extends Application.LegacyApplication {
             });
             table.setCellStyleGenerator(new CellStyleGenerator() {
                 @Override
-                public String getStyle(Object itemId, Object propertyId) {
+                public String getStyle(Table source, Object itemId,
+                        Object propertyId) {
                     if (new Integer(4).equals(itemId)) {
                         if (propertyId == null) {
                             return "MYROW";
index f622f093ee2e1bfd713cfcc043ab7a3353fccfc1..98cd6724d4b92ee7c8ab3d12a8d7df6d0d89887e 100644 (file)
@@ -4,10 +4,10 @@ import com.vaadin.Application;
 import com.vaadin.data.Item;
 import com.vaadin.ui.Component;
 import com.vaadin.ui.Label;
-import com.vaadin.ui.UI.LegacyWindow;
 import com.vaadin.ui.Table;
 import com.vaadin.ui.Table.CellStyleGenerator;
 import com.vaadin.ui.Table.ColumnGenerator;
+import com.vaadin.ui.UI.LegacyWindow;
 
 public class Ticket2208 extends Application.LegacyApplication {
 
@@ -40,7 +40,8 @@ public class Ticket2208 extends Application.LegacyApplication {
         t.setCellStyleGenerator(new CellStyleGenerator() {
 
             @Override
-            public String getStyle(Object itemId, Object propertyId) {
+            public String getStyle(Table source, Object itemId,
+                    Object propertyId) {
                 if ("col 1 (red)".equals(propertyId)) {
                     return "red";
                 }