Author: knopp
Date: Fri Jun  8 13:30:43 2007
New Revision: 545612

URL: http://svn.apache.org/viewvc?view=rev&rev=545612
Log:
WICKET-630 - It should be possible to specify different CSS class names for 
certain columns in DataTable

Added:
    
incubator/wicket/trunk/jdk-1.4/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/repeater/data/table/IStyledColumn.java
Modified:
    
incubator/wicket/trunk/jdk-1.4/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/repeater/data/table/AbstractColumn.java
    
incubator/wicket/trunk/jdk-1.4/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/repeater/data/table/DataTable.java
    
incubator/wicket/trunk/jdk-1.4/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/repeater/data/table/HeadersToolbar.java

Modified: 
incubator/wicket/trunk/jdk-1.4/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/repeater/data/table/AbstractColumn.java
URL: 
http://svn.apache.org/viewvc/incubator/wicket/trunk/jdk-1.4/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/repeater/data/table/AbstractColumn.java?view=diff&rev=545612&r1=545611&r2=545612
==============================================================================
--- 
incubator/wicket/trunk/jdk-1.4/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/repeater/data/table/AbstractColumn.java
 (original)
+++ 
incubator/wicket/trunk/jdk-1.4/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/repeater/data/table/AbstractColumn.java
 Fri Jun  8 13:30:43 2007
@@ -25,7 +25,7 @@
  * 
  * @author Igor Vaynberg ( ivaynberg )
  */
-public abstract class AbstractColumn implements IColumn
+public abstract class AbstractColumn implements IStyledColumn
 {
        private IModel displayModel;
        private String sortProperty;
@@ -92,5 +92,13 @@
                {
                        displayModel.detach();
                }
+       }
+       
+       /**
+        * @ssee [EMAIL PROTECTED] IStyledColumn#getCssClass()}
+        */
+       public String getCssClass()
+       {
+               return null;
        }
 }

Modified: 
incubator/wicket/trunk/jdk-1.4/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/repeater/data/table/DataTable.java
URL: 
http://svn.apache.org/viewvc/incubator/wicket/trunk/jdk-1.4/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/repeater/data/table/DataTable.java?view=diff&rev=545612&r1=545611&r2=545612
==============================================================================
--- 
incubator/wicket/trunk/jdk-1.4/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/repeater/data/table/DataTable.java
 (original)
+++ 
incubator/wicket/trunk/jdk-1.4/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/repeater/data/table/DataTable.java
 Fri Jun  8 13:30:43 2007
@@ -16,7 +16,11 @@
  */
 package org.apache.wicket.extensions.markup.html.repeater.data.table;
 
+import org.apache.wicket.Component;
+import org.apache.wicket.behavior.AbstractBehavior;
+import org.apache.wicket.behavior.IBehavior;
 import 
org.apache.wicket.extensions.markup.html.repeater.data.grid.DataGridView;
+import org.apache.wicket.markup.ComponentTag;
 import org.apache.wicket.markup.html.WebMarkupContainer;
 import org.apache.wicket.markup.html.navigation.paging.IPageable;
 import org.apache.wicket.markup.html.panel.Panel;
@@ -26,6 +30,7 @@
 import org.apache.wicket.markup.repeater.RepeatingView;
 import org.apache.wicket.markup.repeater.data.IDataProvider;
 import org.apache.wicket.model.IModel;
+import org.apache.wicket.util.string.Strings;
 
 
 /**
@@ -67,6 +72,31 @@
  */
 public class DataTable extends Panel implements IPageable
 {
+       static abstract class CssAttributeBehavior extends AbstractBehavior
+       {
+               protected abstract String getCssClass();
+               
+               /**
+                * @see IBehavior#onComponentTag(Component, ComponentTag)
+                */
+               public void onComponentTag(Component component, ComponentTag 
tag)
+               {
+                       String className = getCssClass();
+                       if (!Strings.isEmpty(className)) 
+                       {
+                               CharSequence oldClassName = 
tag.getString("class");
+                               if (Strings.isEmpty(oldClassName))
+                               {
+                                       tag.put("class", className);
+                               }
+                               else
+                               {
+                                       tag.put("class", oldClassName + " " + 
className);
+                               }
+                       }
+               }
+       }
+
        /**
         * The component id that toolbars must be created with in order to be 
added
         * to the data table
@@ -106,7 +136,21 @@
 
                        protected Item newCellItem(String id, int index, IModel 
model)
                        {
-                               return DataTable.this.newCellItem(id, index, 
model);
+                               Item item = DataTable.this.newCellItem(id, 
index, model);
+                               final IColumn column = 
DataTable.this.columns[index];
+                               if (column instanceof IStyledColumn)
+                               {
+                                       item.add(new 
DataTable.CssAttributeBehavior() 
+                                       {
+                                               private static final long 
serialVersionUID = 1L;
+               
+                                               protected String getCssClass()
+                                               {
+                                                       return 
((IStyledColumn)column).getCssClass();
+                                               }
+                                       });
+                               }
+                               return item;
                        }
 
                        protected Item newRowItem(String id, int index, IModel 
model)
@@ -286,7 +330,7 @@
         * 
         * @return DataItem created DataItem
         */
-       protected Item newCellItem(final String id, int index, final IModel 
model)
+       protected Item newCellItem(final String id, final int index, final 
IModel model)
        {
                return new Item(id, index, model);
        }

Modified: 
incubator/wicket/trunk/jdk-1.4/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/repeater/data/table/HeadersToolbar.java
URL: 
http://svn.apache.org/viewvc/incubator/wicket/trunk/jdk-1.4/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/repeater/data/table/HeadersToolbar.java?view=diff&rev=545612&r1=545611&r2=545612
==============================================================================
--- 
incubator/wicket/trunk/jdk-1.4/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/repeater/data/table/HeadersToolbar.java
 (original)
+++ 
incubator/wicket/trunk/jdk-1.4/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/repeater/data/table/HeadersToolbar.java
 Fri Jun  8 13:30:43 2007
@@ -34,7 +34,7 @@
 public class HeadersToolbar extends AbstractToolbar
 {
        private static final long serialVersionUID = 1L;
-
+       
        /**
         * Constructor
         * 
@@ -69,6 +69,20 @@
                        {
                                header = new WebMarkupContainer("header");
                        }
+                       
+                       if (column instanceof IStyledColumn)
+                       {
+                               header.add(new DataTable.CssAttributeBehavior() 
+                               {
+                                       private static final long 
serialVersionUID = 1L;
+       
+                                       protected String getCssClass()
+                                       {
+                                               return 
((IStyledColumn)column).getCssClass();
+                                       }
+                               });
+                       }
+                       
                        item.add(header);
                        item.setRenderBodyOnly(true);
                        header.add(column.getHeader("label"));

Added: 
incubator/wicket/trunk/jdk-1.4/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/repeater/data/table/IStyledColumn.java
URL: 
http://svn.apache.org/viewvc/incubator/wicket/trunk/jdk-1.4/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/repeater/data/table/IStyledColumn.java?view=auto&rev=545612
==============================================================================
--- 
incubator/wicket/trunk/jdk-1.4/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/repeater/data/table/IStyledColumn.java
 (added)
+++ 
incubator/wicket/trunk/jdk-1.4/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/repeater/data/table/IStyledColumn.java
 Fri Jun  8 13:30:43 2007
@@ -0,0 +1,15 @@
+package org.apache.wicket.extensions.markup.html.repeater.data.table;
+
+/**
+ * Interface that allows styling individuals DataTable columns 
+ * 
+ * @author Matej Knopp
+ */
+public interface IStyledColumn extends IColumn
+{
+       /**
+        * Returns the css class for this column.
+        * @return CSS class name
+        */
+       public String getCssClass();
+}


Reply via email to