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.DirectServiceParameter;
25  import org.apache.tapestry.engine.IEngineService;
26  import org.apache.tapestry.engine.ILink;
27  
28  import net.sf.tapfx.components.TapFXBaseComponent;
29  
30  /***
31   * This component renders a pane.
32   * The pane in turn encloses the link
33   * components.
34   * <p/>
35   * A pane, in Outlook, is what you click
36   * on and which slides up or down to reveal
37   * other panes.
38   *
39   * @author Joshua Long (josh@joshlong.com)
40   * @author andyhot
41   * @version $Id: OutlookPane.java,v 1.2 2005/11/04 23:38:08 andyhot Exp $
42   */
43  public abstract class OutlookPane extends TapFXBaseComponent implements
44          IDirect
45  {
46      private static final Log log =
47              LogFactory.getLog(OutlookPane.class);
48  
49      private static final String OUTLOOK_PANE_COUNT =
50              "net.sf.tapfx.components.outlookbar.outlook_pane_count";
51  
52      private String prefix;
53  
54      public abstract String getTitle();
55      public abstract void setTitle(String title);
56  
57      public abstract IActionListener getListener();
58      public abstract void setListener(IActionListener listener);
59  
60      public abstract String getDirectUrl();
61      public abstract void setDirectUrl(String directUrl);
62  
63      public abstract String getShowjavaScript();
64      public abstract void setShowjavaScript(String showjavaScript);
65  
66      public abstract String getPaneId();
67      public abstract void setPaneId(String paneId);
68      
69      public abstract IEngineService getDirectService();
70      
71      public abstract String getSelection();
72      public abstract void setSelection(String selection);    
73  
74      public boolean isStateful()
75      {
76          return true;
77      }
78  
79      public String getPrefix()
80      {
81          return prefix;
82      }
83  
84      static void setOutlookPaneCount(IRequestCycle cycle, Integer pane_count)
85      {
86          cycle.setAttribute(OutlookPane.OUTLOOK_PANE_COUNT, pane_count);
87      }
88  
89      static Integer getOutlookPaneCount(IRequestCycle cycle)
90      {
91          return (Integer) cycle.getAttribute(OutlookPane.OUTLOOK_PANE_COUNT);
92      }
93  
94      public void trigger(IRequestCycle cycle)
95      {
96          Object[] params = cycle.getListenerParameters();
97          for (int i = 0; i < params.length; i++)
98          {
99              log.debug("Inside trigger(), the param is " + params[i]);
100         }
101         //if (OutlookBar.getOutlookBar(cycle).getForceSession())
102         {
103         	setSelection((String)params[0]);
104             //cycle.getRequestContext().createSession().setAttribute(OutlookLink.SELECTED_OUTLOOK_LINK_ID, params[0]);            
105         }
106     }
107 
108     protected void setupComponent(IRequestCycle cycle)
109     {
110         Integer bar_count = OutlookBar.getOutlookBarCount(cycle);
111         if (null == bar_count)
112         {
113             throw Tapestry.createRequiredParameterException(this,
114                     "You need to provide a @OutlookBar around this component!");
115         }
116         prefix = OutlookBar.getOutlookBar(cycle).getPrefix();
117         log.debug("Inside of a pane, the bar count is " + bar_count.intValue());
118         Integer pane_count = getOutlookPaneCount(cycle);
119         if (null == pane_count)
120         {
121             pane_count = new Integer(0);
122         }
123         else
124         {
125             pane_count = new Integer(pane_count.intValue() + 1);
126         }
127         setOutlookPaneCount(cycle, pane_count);
128         log.debug("inside a pane, the pane count is " + pane_count);
129         String id = "$" + //bar_count.intValue() + "__" +
130                 pane_count.intValue();
131         String parent = OutlookBar.getOutlookBarCurrentId(cycle);
132         id = parent + id;
133         setPaneId(id);
134         setShowjavaScript("tapfx_showPanel('" + parent + "','" + id + "');");
135         OutlookBar.setOutlookBarAggregateId(cycle, id);
136         Object[] params = {id};        
137         DirectServiceParameter directParams = new DirectServiceParameter(this, params);
138         ILink link = getDirectService().getLink(cycle, false, directParams);        
139         String url = link.getURL();
140         setDirectUrl(url);
141         if (OutlookBar.getOutlookBar(cycle).getForceSession())
142         {
143             setShowjavaScript("window.location='" + url + "';");
144         }
145     }
146 }
147 
148