View Javadoc

1   /*
2    * Copyright 2004-2005 Andreas Andreou
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *  http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package net.sf.tapfx.components.outlookbar;
17  
18  import org.apache.commons.logging.Log;
19  import org.apache.commons.logging.LogFactory;
20  import org.apache.tapestry.IActionListener;
21  import org.apache.tapestry.IDirect;
22  import org.apache.tapestry.IRequestCycle;
23  import org.apache.tapestry.Tapestry;
24  import org.apache.tapestry.engine.IEngineService;
25  import org.apache.tapestry.engine.ILink;
26  
27  import net.sf.tapfx.components.TapFXBaseComponent;
28  
29  /***
30   * This component renders a pane.
31   * The pane in turn encloses the link
32   * components.
33   * <p/>
34   * A pane, in Outlook, is what you click
35   * on and which slides up or down to reveal
36   * other panes.
37   *
38   * @author Joshua Long (josh@joshlong.com)
39   */
40  public abstract class OutlookPane extends TapFXBaseComponent implements
41          IDirect
42  {
43      private static final Log log =
44              LogFactory.getLog(OutlookPane.class);
45  
46      private static final String OUTLOOK_PANE_COUNT =
47              "net.sf.tapfx.components.outlookbar.outlook_pane_count";
48  
49      private String prefix;
50  
51      public abstract String getTitle();
52  
53      public abstract void setTitle(String title);
54  
55      public abstract IActionListener getListener();
56  
57      public abstract void setListener(IActionListener listener);
58  
59      public abstract String getDirectUrl();
60  
61      public abstract void setDirectUrl(String directUrl);
62  
63      public abstract String getShowjavaScript();
64  
65      public abstract void setShowjavaScript(String showjavaScript);
66  
67      public abstract String getPaneId();
68  
69      public abstract void setPaneId(String paneId);
70  
71      public boolean isStateful()
72      {
73          return true;
74      }
75  
76      public String getPrefix()
77      {
78          return prefix;
79      }
80  
81      static void setOutlookPaneCount(IRequestCycle cycle, Integer pane_count)
82      {
83          cycle.setAttribute(OutlookPane.OUTLOOK_PANE_COUNT, pane_count);
84      }
85  
86      static Integer getOutlookPaneCount(IRequestCycle cycle)
87      {
88          return (Integer) cycle.getAttribute(OutlookPane.OUTLOOK_PANE_COUNT);
89      }
90  
91      public void trigger(IRequestCycle cycle)
92      {
93          log.debug("Inside trigger on outlook pane");
94          Object[] params = cycle.getServiceParameters();
95          for (int i = 0; i < params.length; i++)
96          {
97              log.debug("Inside trigger(), the param is " + params[i]);
98          }
99          //if (OutlookBar.getOutlookBar(cycle).getForceSession())
100         {
101             cycle.getRequestContext().createSession().setAttribute(OutlookLink.SELECTED_OUTLOOK_LINK_ID, params[0]);            
102         }
103     }
104 
105     protected void setupComponent(IRequestCycle cycle)
106     {
107         Integer bar_count = OutlookBar.getOutlookBarCount(cycle);
108         if (null == bar_count)
109         {
110             throw Tapestry.createRequiredParameterException(this,
111                     "You need to provide a @OutlookBar around this component!");
112         }
113         prefix = OutlookBar.getOutlookBar(cycle).getPrefix();
114         log.debug("Inside of a pane, the bar count is " + bar_count.intValue());
115         Integer pane_count = getOutlookPaneCount(cycle);
116         if (null == pane_count)
117         {
118             pane_count = new Integer(0);
119         }
120         else
121         {
122             pane_count = new Integer(pane_count.intValue() + 1);
123         }
124         setOutlookPaneCount(cycle, pane_count);
125         log.debug("inside a pane, the pane count is " + pane_count);
126         String id = "$" + //bar_count.intValue() + "__" +
127                 pane_count.intValue();
128         String parent = OutlookBar.getOutlookBarCurrentId(cycle);
129         id = parent + id;
130         setPaneId(id);
131         setShowjavaScript("tapfx_showPanel('" + parent + "','" + id + "');");
132         OutlookBar.setOutlookBarAggregateId(cycle, id);
133         Object[] params = {id};
134         IEngineService service = cycle.getEngine().getService(Tapestry.DIRECT_SERVICE);
135         ILink link = service.getLink(cycle, this, params);
136         String url = link.getURL();
137         setDirectUrl(url);
138         if (OutlookBar.getOutlookBar(cycle).getForceSession())
139         {
140             setShowjavaScript("window.location='" + url + "';");
141         }
142     }
143 }
144 
145