You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by jl...@apache.org on 2006/06/19 21:33:47 UTC

svn commit: r415393 - in /myfaces/tomahawk/trunk: core/src/main/java/org/apache/myfaces/custom/schedule/model/ core/src/main/java/org/apache/myfaces/custom/schedule/renderer/ examples/simple/src/main/java/org/apache/myfaces/examples/schedule/

Author: jlust
Date: Mon Jun 19 12:33:46 2006
New Revision: 415393

URL: http://svn.apache.org/viewvc?rev=415393&view=rev
Log:
Applied patch for TOMAHAWK-499, adding basic support for all-day events.

Modified:
    myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/model/DefaultScheduleEntry.java
    myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/model/ScheduleDay.java
    myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/model/ScheduleEntry.java
    myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/renderer/DefaultScheduleEntryRenderer.java
    myfaces/tomahawk/trunk/examples/simple/src/main/java/org/apache/myfaces/examples/schedule/ScheduleExampleHandler.java

Modified: myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/model/DefaultScheduleEntry.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/model/DefaultScheduleEntry.java?rev=415393&r1=415392&r2=415393&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/model/DefaultScheduleEntry.java (original)
+++ myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/model/DefaultScheduleEntry.java Mon Jun 19 12:33:46 2006
@@ -18,7 +18,11 @@
 
 import java.io.Serializable;
 
+import java.util.Calendar;
 import java.util.Date;
+import java.util.GregorianCalendar;
+
+import org.apache.myfaces.custom.schedule.util.ScheduleUtil;
 
 
 /**
@@ -44,6 +48,7 @@
     private String id;
     private String subtitle;
     private String title;
+    private boolean allDay;
 
     //~ Methods ----------------------------------------------------------------
 
@@ -76,6 +81,18 @@
      */
     public Date getEndTime()
     {
+    	if (endTime == null) endTime = new Date();
+    	if (isAllDay()) {
+    		Calendar cal = GregorianCalendar.getInstance();
+    		Date truncated = ScheduleUtil.truncate(endTime);
+    		cal.setTime(truncated);
+    		cal.add(Calendar.MILLISECOND, -1);
+    		truncated = cal.getTime();
+    		if (!truncated.equals(endTime)) {
+    			cal.add(Calendar.DATE, 1);
+    		}
+    		return cal.getTime();
+    	}
         return endTime;
     }
 
@@ -104,11 +121,16 @@
     }
 
     /**
-     * @return Returns the startTime.
+     * @return Returns the startTime. If the allDay property is true, the startTime is truncated to 00:00.
      */
     public Date getStartTime()
     {
-        return startTime;
+    	if (startTime == null) startTime = new Date();
+    	if (isAllDay()) {
+    		return ScheduleUtil.truncate(startTime);
+    	} else {
+            return startTime;
+    	}
     }
 
     /**
@@ -142,5 +164,21 @@
     {
         return title;
     }
+    
+    /**
+     * @return Returns true if the entry last all day.
+     */
+    public boolean isAllDay()
+    {
+    	return allDay;
+    }
+
+	/**
+	 * @param allDay does the entry last all day?
+	 */
+	public void setAllDay(boolean allDay) {
+		this.allDay = allDay;
+	}
+	
 }
 //The End

Modified: myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/model/ScheduleDay.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/model/ScheduleDay.java?rev=415393&r1=415392&r2=415393&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/model/ScheduleDay.java (original)
+++ myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/model/ScheduleDay.java Mon Jun 19 12:33:46 2006
@@ -155,6 +155,7 @@
     
     /**
      * Get the non-inclusive hour by which all events on this day have completed.
+     * All day events are not included, as their end time is implicit.
      * 
      * @return From 0, where there are no events and 24 where events exist up to the last hour
      */
@@ -162,11 +163,22 @@
     {
     	Calendar endTime = GregorianCalendar.getInstance();
 
-    	if (entries.isEmpty()) {
+    	// Check all events, as the last to finish may not be the last to begin
+    	Date lastEnd = null;
+    	
+    	for (Iterator it = entries.iterator(); it.hasNext(); ) {
+    		ScheduleEntry next = (ScheduleEntry) it.next();
+    		
+    		if (!next.isAllDay() && (lastEnd == null || lastEnd.before(next.getEndTime()))) {
+    			lastEnd = next.getEndTime();
+    		}
+    	}
+    	if (lastEnd == null) {
     		
     		return 0;
     	}
-    	endTime.setTime(((ScheduleEntry) entries.last()).getEndTime());
+    	
+    	endTime.setTime(lastEnd);
     	
     	if (endTime.get(Calendar.MINUTE) > 0){
     		// Round up to next hour
@@ -178,19 +190,29 @@
     
     /**
      * Get the inclusive hour in which the first event on this day starts.
+     * All day events are not included, as their start time is implicit.
      * 
      * @return From 0, where there is an event in the first hour to 24 where there are no events
      */
     public int getFirstEventHour()
     {
-    	Calendar startTime = GregorianCalendar.getInstance();
+    	Calendar startTime = null;
 
-    	if (entries.isEmpty()) {
+    	for (Iterator it = entries.iterator(); it.hasNext(); ) {
+    		ScheduleEntry next = (ScheduleEntry) it.next();
+    		
+    		if (!next.isAllDay()) {
+    			startTime = GregorianCalendar.getInstance();
+    			startTime.setTime(((ScheduleEntry) entries.first()).getStartTime());
+    			break;
+    		}
+    	}
+
+    	if (startTime == null) {
     		
     		return 24;
     	}
-    	startTime.setTime(((ScheduleEntry) entries.first()).getStartTime());
-    	
+
     	return equalsDate(startTime.getTime()) ? startTime.get(Calendar.HOUR_OF_DAY) : 0;
     }
 }

Modified: myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/model/ScheduleEntry.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/model/ScheduleEntry.java?rev=415393&r1=415392&r2=415393&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/model/ScheduleEntry.java (original)
+++ myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/model/ScheduleEntry.java Mon Jun 19 12:33:46 2006
@@ -60,5 +60,10 @@
      * @return Returns the title.
      */
     public abstract String getTitle();
+
+    /**
+     * @return Returns true if the entry last all day.
+     */
+    public abstract boolean isAllDay();
 }
 //The End

Modified: myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/renderer/DefaultScheduleEntryRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/renderer/DefaultScheduleEntryRenderer.java?rev=415393&r1=415392&r2=415393&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/renderer/DefaultScheduleEntryRenderer.java (original)
+++ myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/renderer/DefaultScheduleEntryRenderer.java Mon Jun 19 12:33:46 2006
@@ -67,11 +67,16 @@
                 endTime = day.getDayEnd();
             }
 
-            DateFormat format = DateFormat.getTimeInstance(DateFormat.SHORT);
-            text.append(format.format(startTime));
-            text.append("-");
-            text.append(format.format(endTime));
-            text.append(": ");
+            if (!entry.isAllDay())
+            {
+            	DateFormat format = DateFormat.getTimeInstance(DateFormat.SHORT);
+            	text.append(format.format(startTime));
+            	if (!startTime.equals(endTime)) {
+            		text.append("-");
+            		text.append(format.format(endTime));
+            	}
+            	text.append(": ");
+            }
             text.append(entry.getTitle());
 
             writer.writeText(text.toString(), null);

Modified: myfaces/tomahawk/trunk/examples/simple/src/main/java/org/apache/myfaces/examples/schedule/ScheduleExampleHandler.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/examples/simple/src/main/java/org/apache/myfaces/examples/schedule/ScheduleExampleHandler.java?rev=415393&r1=415392&r2=415393&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/examples/simple/src/main/java/org/apache/myfaces/examples/schedule/ScheduleExampleHandler.java (original)
+++ myfaces/tomahawk/trunk/examples/simple/src/main/java/org/apache/myfaces/examples/schedule/ScheduleExampleHandler.java Mon Jun 19 12:33:46 2006
@@ -141,6 +141,13 @@
         entry6.setTitle("Zero length entry");
         entry6.setDescription("Is only rendered when the 'renderZeroLengthEntries' attribute is 'true'");
         model.addEntry(entry6);
+        //And also an allday event
+        DefaultScheduleEntry entry7 = new DefaultScheduleEntry();
+        entry7.setId(RandomStringUtils.randomNumeric(32));
+        entry7.setTitle("All day event");
+        entry7.setSubtitle("This event renders as an all-day event");
+        entry7.setAllDay(true);
+        model.addEntry(entry7);
         model.refresh();
     }
 }