Coverage Report - net.sf.tacos.components.timeline.Timeline
 
Classes in this File Line Coverage Branch Coverage Complexity
Timeline
0% 
0% 
1,429
 
 1  
 package net.sf.tacos.components.timeline;
 2  
 
 3  
 import java.util.Collection;
 4  
 import java.util.Iterator;
 5  
 
 6  
 import org.apache.tapestry.BaseComponent;
 7  
 import org.apache.tapestry.IAsset;
 8  
 import org.apache.tapestry.IRequestCycle;
 9  
 import org.apache.tapestry.html.Shell;
 10  
 import org.apache.tapestry.json.JSONObject;
 11  
 
 12  
 /**
 13  
  * Timeline component, based on http://simile.mit.edu/timeline/
 14  
  *
 15  
  * @author Andreas Andreou, amplafi.com
 16  
  */
 17  0
 public abstract class Timeline extends BaseComponent {
 18  
 
 19  
     public abstract Collection getEvents();
 20  
 
 21  
     public abstract String getEventsUrl();
 22  
     
 23  
     public abstract IAsset getTimelineAsset();
 24  
     
 25  
     public abstract IAsset getSimileAjaxAsset();    
 26  
 
 27  
     protected void prepareForRender(IRequestCycle cycle)
 28  
     {
 29  0
         super.prepareForRender(cycle);
 30  
 
 31  0
         if (!cycle.isRewinding()) 
 32  
         {
 33  0
             Shell shell = Shell.get(cycle);
 34  0
             if (getSimileAjaxAsset()!=null)
 35  
             {
 36  0
                 addScriptToShell(shell, getSimileAjaxAsset().buildURL());
 37  
             }
 38  
 
 39  0
             addScriptToShell(shell, getTimelineAsset().buildURL());
 40  
         }
 41  0
     }
 42  
 
 43  
     public String getEventsJson()
 44  
     {
 45  0
         JSONObject json = new JSONObject();
 46  0
         for (Iterator iterator = getEvents().iterator(); iterator.hasNext();)
 47  
         {
 48  0
             TimelineEvent evt = (TimelineEvent) iterator.next();
 49  0
             evt.appendTo(json);
 50  0
         }
 51  0
         return json.toString(2);
 52  
     }
 53  
     
 54  
     private void addScriptToShell(Shell shell, String url) {
 55  0
         shell.includeAdditionalContent(
 56  
                 "<script src=\"" + url + "\" type=\"text/javascript\"></script>");
 57  0
     }
 58  
 }