myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sc...@apache.org
Subject svn commit: r169637 - in /myfaces/trunk: src/components/org/apache/myfaces/custom/sortheader/ webapps/simple/ webapps/simple/images/ webapps/src/example/org/apache/myfaces/examples/listexample/
Date Wed, 11 May 2005 14:24:10 GMT
Author: schof
Date: Wed May 11 07:24:09 2005
New Revision: 169637

URL: http://svn.apache.org/viewcvs?rev=169637&view=rev
Log:
Fixes MYFACES-191

Added:
    myfaces/trunk/webapps/simple/images/ascending-arrow.gif   (with props)
    myfaces/trunk/webapps/simple/images/descending-arrow.gif   (with props)
    myfaces/trunk/webapps/src/example/org/apache/myfaces/examples/listexample/OpenDataList.java
Modified:
    myfaces/trunk/src/components/org/apache/myfaces/custom/sortheader/HtmlSortHeaderRenderer.java
    myfaces/trunk/webapps/simple/openDataTable.jsp

Modified: myfaces/trunk/src/components/org/apache/myfaces/custom/sortheader/HtmlSortHeaderRenderer.java
URL: http://svn.apache.org/viewcvs/myfaces/trunk/src/components/org/apache/myfaces/custom/sortheader/HtmlSortHeaderRenderer.java?rev=169637&r1=169636&r2=169637&view=diff
==============================================================================
--- myfaces/trunk/src/components/org/apache/myfaces/custom/sortheader/HtmlSortHeaderRenderer.java
(original)
+++ myfaces/trunk/src/components/org/apache/myfaces/custom/sortheader/HtmlSortHeaderRenderer.java
Wed May 11 07:24:09 2005
@@ -1,12 +1,12 @@
 /*
  * Copyright 2004 The Apache Software Foundation.
- * 
+ *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
- * 
+ *
  *      http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -28,7 +28,7 @@
 /**
  * @author Manfred Geiler (latest modification by $Author$)
  * @version $Revision$ $Date$
- * $Log$
+ * $Log: HtmlSortHeaderRenderer.java,v $
  * Revision 1.6  2004/10/13 11:50:58  matze
  * renamed packages to org.apache
  *
@@ -48,28 +48,33 @@
 public class HtmlSortHeaderRenderer
         extends HtmlLinkRendererBase
 {
+    private static final String FACET_ASCENDING = "ascending";
+    private static final String FACET_DESCENDING = "descending";
+
     //private static final Log log = LogFactory.getLog(HtmlSortHeaderRenderer.class);
 
     public void encodeEnd(FacesContext facesContext, UIComponent component) throws IOException
     {
         RendererUtils.checkParamValidity(facesContext, component, HtmlCommandSortHeader.class);
-
         if (UserRoleUtils.isEnabledOnUserRole(component))
         {
             HtmlCommandSortHeader sortHeader = (HtmlCommandSortHeader)component;
             HtmlDataTable dataTable = sortHeader.findParentDataTable();
-
-            if (sortHeader.isArrow() && sortHeader.getColumnName().equals(dataTable.getSortColumn()))
+            if (sortHeader.getColumnName().equals(dataTable.getSortColumn()))
             {
-                ResponseWriter writer = facesContext.getResponseWriter();
-
-                if (dataTable.isSortAscending())
+                UIComponent img = (dataTable.isSortAscending())
+                                  ? sortHeader.getFacet(FACET_ASCENDING)
+                                  : sortHeader.getFacet(FACET_DESCENDING);
+                // render directional image
+                if (img != null)
                 {
-                    writer.write("↑");
+                    RendererUtils.renderChild(facesContext, img);
                 }
-                else
+                // render directional character
+                if (sortHeader.isArrow())
                 {
-                    writer.write("↓");
+                    ResponseWriter writer = facesContext.getResponseWriter();
+                    writer.write((dataTable.isSortAscending()) ? "↑" : "↓");
                 }
             }
         }

Added: myfaces/trunk/webapps/simple/images/ascending-arrow.gif
URL: http://svn.apache.org/viewcvs/myfaces/trunk/webapps/simple/images/ascending-arrow.gif?rev=169637&view=auto
==============================================================================
Binary file - no diff available.

Propchange: myfaces/trunk/webapps/simple/images/ascending-arrow.gif
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: myfaces/trunk/webapps/simple/images/descending-arrow.gif
URL: http://svn.apache.org/viewcvs/myfaces/trunk/webapps/simple/images/descending-arrow.gif?rev=169637&view=auto
==============================================================================
Binary file - no diff available.

Propchange: myfaces/trunk/webapps/simple/images/descending-arrow.gif
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Modified: myfaces/trunk/webapps/simple/openDataTable.jsp
URL: http://svn.apache.org/viewcvs/myfaces/trunk/webapps/simple/openDataTable.jsp?rev=169637&r1=169636&r2=169637&view=diff
==============================================================================
--- myfaces/trunk/webapps/simple/openDataTable.jsp (original)
+++ myfaces/trunk/webapps/simple/openDataTable.jsp Wed May 11 07:24:09 2005
@@ -6,7 +6,7 @@
 
 <!--
 /*
- * Copyright 2005 The Apache Software Foundation.
+ * Copyright 2004 The Apache Software Foundation.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -40,7 +40,7 @@
                  headerClass="standardTable_Header"
                  footerClass="standardTable_Header"
                  rowClasses="standardTable_Row1,standardTable_Row2"
-                 columnClasses="standardTable_Column,standardTable_ColumnCentered, standardTable_Column"
+                 columnClasses="standardTable_Column,standardTable_ColumnCentered,standardTable_Column"
                  var="row"
                  value="#{openDataList.data}"
                  preserveDataModel="true"
@@ -50,7 +50,13 @@
                  preserveSort="true">
         <x:columns value="#{openDataList.columnHeaders}" var="columnHeader">
             <f:facet name="header">
-                <x:commandSortHeader columnName="#{columnHeader}" arrow="true">
+                <x:commandSortHeader columnName="#{columnHeader}" arrow="false">
+                    <f:facet name="ascending">
+                        <h:graphicImage value="images/ascending-arrow.gif" rendered="true"
border="0"/>
+                    </f:facet>
+                    <f:facet name="descending">
+                        <h:graphicImage value="images/descending-arrow.gif" rendered="true"
border="0"/>
+                    </f:facet>
                     <h:outputText value="#{columnHeader}" />
                 </x:commandSortHeader>
             </f:facet>

Added: myfaces/trunk/webapps/src/example/org/apache/myfaces/examples/listexample/OpenDataList.java
URL: http://svn.apache.org/viewcvs/myfaces/trunk/webapps/src/example/org/apache/myfaces/examples/listexample/OpenDataList.java?rev=169637&view=auto
==============================================================================
--- myfaces/trunk/webapps/src/example/org/apache/myfaces/examples/listexample/OpenDataList.java
(added)
+++ myfaces/trunk/webapps/src/example/org/apache/myfaces/examples/listexample/OpenDataList.java
Wed May 11 07:24:09 2005
@@ -0,0 +1,109 @@
+package org.apache.myfaces.examples.listexample;
+
+import java.util.*;
+import javax.faces.model.*;
+
+public class OpenDataList extends SortableList
+{
+    private DataModel data;
+    private DataModel columnHeaders;
+
+    private static final int SORT_ASCENDING = 1;
+    private static final int SORT_DESCENDING = -1;
+
+    public OpenDataList()
+    {
+        super(null);
+
+        // create header info
+        List headerList = new ArrayList();
+        headerList.add("Index");
+        headerList.add("Type");
+        headerList.add("Model");
+        columnHeaders = new ListDataModel(headerList);
+
+        // create list of lists (data)
+        List rowList = new ArrayList();
+        for (int i = 100; i <= 999; i++)
+        {
+            List colList = new ArrayList();
+            colList.add(new Integer(i));
+            colList.add("Car Type " + i);
+            colList.add((i%2==0) ? "blue" : "green");
+            rowList.add(colList);
+        }
+        data = new ListDataModel(rowList);
+    }
+
+    //==========================================================================
+    // Getters
+    //==========================================================================
+
+    public DataModel getData()
+    {
+        sort(getSort(), isAscending());
+        return data;
+    }
+
+    public DataModel getColumnHeaders()
+    {
+        return columnHeaders;
+    }
+
+    //==========================================================================
+    // Public Methods
+    //==========================================================================
+
+    public Object getColumnValue()
+    {
+        Object columnValue = null;
+        if (data.isRowAvailable() && columnHeaders.isRowAvailable())
+        {
+            columnValue = ((List)data.getRowData()).get(columnHeaders.getRowIndex());
+        }
+        return columnValue;
+    }
+
+    //==========================================================================
+    // Protected Methods
+    //==========================================================================
+
+    protected boolean isDefaultAscending(String sortColumn)
+    {
+        return true;
+    }
+
+    protected void sort(final String column, final boolean ascending)
+    {
+        if (column != null)
+        {
+            int columnIndex = ( (List) columnHeaders.getWrappedData()).indexOf(column);
+            int direction = (ascending) ? SORT_ASCENDING : SORT_DESCENDING;
+            sort(columnIndex, direction);
+        }
+    }
+
+    protected void sort(final int columnIndex, final int direction)
+    {
+        Comparator comparator = new Comparator()
+        {
+            public int compare(Object o1, Object o2)
+            {
+                int result = 0;
+                Object column1 = ((List)o1).get(columnIndex);
+                Object column2 = ((List)o2).get(columnIndex);
+                if (column1 == null && column2 != null)
+                    result = -1;
+                else if (column1 == null && column2 == null)
+                    result = 0;
+                else if (column1 != null && column2 == null)
+                    result = 1;
+                else
+                    result = ((Comparable)column1).compareTo(column2) * direction;
+                return result;
+            }
+        };
+        Collections.sort((List)data.getWrappedData(), comparator);
+    }
+
+}



Mime
View raw message