You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by sc...@apache.org on 2006/02/27 23:52:46 UTC

svn commit: r381473 - in /myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/schedule: renderer/AbstractScheduleRenderer.java renderer/ScheduleEntryRenderer.java util/ScheduleEntryComparator.java

Author: schof
Date: Mon Feb 27 14:52:44 2006
New Revision: 381473

URL: http://svn.apache.org/viewcvs?rev=381473&view=rev
Log:
Fixes TOMAHAWK-150.  (Patch by Jurgen Lust)

Modified:
    myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/schedule/renderer/AbstractScheduleRenderer.java
    myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/schedule/renderer/ScheduleEntryRenderer.java
    myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/schedule/util/ScheduleEntryComparator.java

Modified: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/schedule/renderer/AbstractScheduleRenderer.java
URL: http://svn.apache.org/viewcvs/myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/schedule/renderer/AbstractScheduleRenderer.java?rev=381473&r1=381472&r2=381473&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/schedule/renderer/AbstractScheduleRenderer.java (original)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/schedule/renderer/AbstractScheduleRenderer.java Mon Feb 27 14:52:44 2006
@@ -51,7 +51,6 @@
     //~ Static fields/initializers ---------------------------------------------
 
     protected static final ScheduleEntryComparator comparator = new ScheduleEntryComparator();
-    private ScheduleEntryRenderer entryRenderer = null;
 
     //~ Methods ----------------------------------------------------------------
 
@@ -301,30 +300,52 @@
                 .booleanValue();
     }
 
+    /**
+     * The user of the Schedule component can customize the look and feel
+     * by specifying a custom implementation of the ScheduleEntryRenderer.
+     * This method gets an instance of the specified class, or if none
+     * was specified, takes the default.
+     * 
+     * @param component the Schedule component
+     * @return a ScheduleEntryRenderer instance
+     */
     protected ScheduleEntryRenderer getEntryRenderer(UIComponent component)
     {
-        if (entryRenderer != null)
-            return entryRenderer;
-        String className = null;
-        ValueBinding binding = component.getValueBinding("entryRenderer");
-        if (binding != null)
-        {
-            className = (String) binding.getValue(FacesContext
-                    .getCurrentInstance());
-        }
-        if (className == null)
-        {
-            Map attributes = component.getAttributes();
-            className = (String) attributes.get("entryRenderer");
-        }
-        try
+        ScheduleEntryRenderer entryRenderer = null;
+        Map attributes = component.getAttributes();
+        //First check if there an entryRenderer has already been instantiated
+        Object rendererObject = attributes.get("entryRendererInstance");
+        if (rendererObject instanceof ScheduleEntryRenderer)
         {
-            entryRenderer = (ScheduleEntryRenderer) Class.forName(className)
-                    .newInstance();
+            entryRenderer = (ScheduleEntryRenderer) rendererObject;
         }
-        catch (Exception e)
+        else
         {
-            entryRenderer = new DefaultScheduleEntryRenderer();
+            //No entryRenderer was instantiated, do that here
+            String className = null;
+            //Was the classname specified as attribute of the component?
+            ValueBinding binding = component.getValueBinding("entryRenderer");
+            if (binding != null)
+            {
+                className = (String) binding.getValue(FacesContext
+                        .getCurrentInstance());
+            }
+            if (className == null)
+            {
+                className = (String) attributes.get("entryRenderer");
+            }
+            try
+            { //try to instantiate a renderer of the specified class
+                entryRenderer = (ScheduleEntryRenderer) Class
+                        .forName(className).newInstance();
+            }
+            catch (Exception e)
+            {
+                //something went wrong, let's take the default
+                entryRenderer = new DefaultScheduleEntryRenderer();
+            }
+            //Store the instance in the component attributes for later use
+            attributes.put("entryRendererInstance", entryRenderer);
         }
         return entryRenderer;
     }
@@ -351,7 +372,8 @@
 
         try
         {
-            Integer rowHeightObject = (Integer)attributes.get(getRowHeightProperty());
+            Integer rowHeightObject = (Integer) attributes
+                    .get(getRowHeightProperty());
             rowHeight = rowHeightObject.intValue();
         }
         catch (Exception e)

Modified: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/schedule/renderer/ScheduleEntryRenderer.java
URL: http://svn.apache.org/viewcvs/myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/schedule/renderer/ScheduleEntryRenderer.java?rev=381473&r1=381472&r2=381473&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/schedule/renderer/ScheduleEntryRenderer.java (original)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/schedule/renderer/ScheduleEntryRenderer.java Mon Feb 27 14:52:44 2006
@@ -1,6 +1,7 @@
 package org.apache.myfaces.custom.schedule.renderer;
 
 import java.io.IOException;
+import java.io.Serializable;
 
 import javax.faces.context.FacesContext;
 import javax.faces.context.ResponseWriter;
@@ -28,7 +29,7 @@
  * @author Jurgen Lust (latest modification by $Author$)
  * @version $Revision$
  */
-public interface ScheduleEntryRenderer
+public interface ScheduleEntryRenderer extends Serializable
 {
     /**
      * Render the content of an entry.

Modified: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/schedule/util/ScheduleEntryComparator.java
URL: http://svn.apache.org/viewcvs/myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/schedule/util/ScheduleEntryComparator.java?rev=381473&r1=381472&r2=381473&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/schedule/util/ScheduleEntryComparator.java (original)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/schedule/util/ScheduleEntryComparator.java Mon Feb 27 14:52:44 2006
@@ -16,6 +16,7 @@
 
 package org.apache.myfaces.custom.schedule.util;
 
+import java.io.Serializable;
 import java.util.Comparator;
 
 import org.apache.myfaces.custom.schedule.model.ScheduleEntry;
@@ -30,8 +31,10 @@
  * @author Bruno Aranda (adaptation of Jurgen's code to myfaces)
  * @version $Revision$
  */
-public class ScheduleEntryComparator implements Comparator
+public class ScheduleEntryComparator implements Comparator, Serializable
 {
+    private static final long serialVersionUID = 6863061256811196989L;
+
     //~ Methods ----------------------------------------------------------------
 
     /**