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.*;
21  import org.apache.tapestry.engine.IEngineService;
22  import org.apache.tapestry.engine.ILink;
23  
24  import net.sf.tapfx.components.TapFXBaseComponent;
25  
26  
27  /***
28   * This provides many services and renders
29   * an icon as well as its label.
30   * You might imagine this where the Mail,
31   * or Calendar icons in Outlook are.
32   * <p/>
33   * Yuck.. I know this could be prettier.
34   *
35   * @author Joshua Long (josh@joshlong.com)
36   */
37  public abstract class OutlookLink extends TapFXBaseComponent/*
38  implements IDirect */
39  {
40      private static final Log log =
41              LogFactory.getLog(OutlookPane.class);
42  
43      private String prefix;
44  
45      public static final String SELECTED_OUTLOOK_LINK_ID =
46              "SELECTED_OUTLOOK_LINK_ID_";
47  
48  
49      public abstract String getPageName();
50  
51      public abstract void setPageName(String page);
52  
53      public abstract String getDirectUrl();
54  
55      public abstract void setDirectUrl(String directUrl);
56  
57      public abstract IActionListener getListener();
58  
59      public abstract void setListener(IActionListener directLink);
60  
61      public abstract IAsset getImage();
62  
63      public abstract void setImage(IAsset asset);
64  
65      public abstract String getImageUrl();
66  
67      public abstract void setImageUrl(String imageUrl);
68  
69  /*
70      public abstract Object getParameters();
71  
72      public abstract void setParameters(Object parameters);
73  */
74  
75      public abstract String getSelectedId();
76  
77      public abstract void setSelectedId(String selectedId);
78  
79      public abstract boolean isRestart();
80  
81      public abstract void setRestart(boolean restart);
82  
83      public boolean isStateful()
84      {
85          return false;
86      }
87  
88      public String getPrefix()
89      {
90          return prefix;
91      }
92  
93      public void trigger(IRequestCycle cycle)
94      {
95          IActionListener listener = getListener();
96          Object[] params = cycle.getServiceParameters();
97          for (int i = 0; i < params.length; i++)
98          {
99              log.debug("Inside trigger(), the param is " + params[i]);
100         }
101         if (listener == null)
102         {
103             throw Tapestry.createRequiredParameterException(this,
104                     "directLink");
105         }
106         listener.actionTriggered(this, cycle);
107         if (OutlookBar.getOutlookBar(cycle).getForceSession())
108         {
109             cycle.getRequestContext().createSession().setAttribute(OutlookLink.SELECTED_OUTLOOK_LINK_ID, params[0]);
110         }
111     }
112 
113     public void gotoPageAction(IRequestCycle cycle)
114     {
115 
116         String id = OutlookBar.getOutlookBarAggregateId(cycle);
117         String pn = getPageName();
118 
119         if (OutlookBar.getOutlookBar(cycle).getForceSession())
120         {
121             cycle.getRequestContext().createSession().setAttribute(OutlookLink.SELECTED_OUTLOOK_LINK_ID, id);
122         }
123         log.debug("goto setting memory: page is =" + pn + "selected id=" + id);
124 
125         if (this.getPageName() != null)
126         {
127             log.debug("goto Forwarding to a page");
128             IPage page = cycle.getPage(getPageName());
129             cycle.activate(page);
130         }
131         else
132         {
133             log.debug("goto Invoking listener");
134             getListener().actionTriggered(this, cycle);
135         }
136     }
137 
138     protected void setupComponent(IRequestCycle cycle)
139     {
140         if (cycle.isRewinding())
141         {
142             return;
143         }
144 
145         prefix = OutlookBar.getOutlookBar(cycle).getPrefix();
146 
147         IAsset img = getImage();
148         String url = img.buildURL(cycle);
149         setImageUrl(url);
150 
151         String id = OutlookBar.getOutlookBarAggregateId(cycle);
152         setSelectedId(id);
153         /* log("the id in link_setup() is " + id); */
154         Object[] params = {id};
155         IEngineService service =
156                 cycle.getEngine().getService(Tapestry.DIRECT_SERVICE);
157         ILink link = service.getLink(cycle, this, params);
158         setDirectUrl(link.getURL());
159 
160         /***
161          *   service =
162          cycle.getEngine().getService(Tapestry.ACTION_SERVICE );
163          service.getLink(cycle, this, new Object[]{});
164 
165          /// Object id = cycle.getAttribute(OutlookBar.AGGREGATE_ID);
166          //  String pn = getPageName();
167          //  log("the page name for this link is: " + pn + "; and the
168          selectedId is " + id);
169          //
170          cycle.getRequestContext().createSession().setAttribute(OutlookLink.SELECTED_OUTLOOK_LINK_ID, id);
171          */
172         if (isRestart())
173             log.debug("This is a restart link");
174         /*     if(getPageName() == null && getListener() == null)
175                  setRestart(true) ;*/
176     }
177 
178 }
179