KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > portlets > weather > component > UIWeatherViewPortlet


1 /**
2  * Wed, Jun 08, 2004 @ 17:03
3  * @author: Fran�ois MORON
4  * @email: francois.moron@rd.francetelecom.com
5  **/

6
7 /* IMPORTANT
8  * This portlet use a properties file (/WEB-INF/classes/WeatherResource.properties).
9  * Check proxy properties and set it according to your network configuration.
10  * Generaly "proxySet" must be "false" (no use of proxy server)
11  */

12
13 package org.exoplatform.portlets.weather.component;
14
15 import java.util.List JavaDoc;
16 import org.exoplatform.faces.core.component.UIPortlet;
17 import org.exoplatform.faces.core.event.ExoActionEvent;
18 import org.exoplatform.faces.core.event.ExoActionListener;
19 import org.exoplatform.portlets.weather.WeatherData;
20 import org.exoplatform.portlets.weather.WeatherUtil;
21
22 import com.capeclear.www.GlobalWeather_xsd.Station;
23
24
25 public class UIWeatherViewPortlet extends UIPortlet {
26     
27     private WeatherUtil weatherUtil_;
28     private WeatherData weatherData_;
29
30     private UIWeatherTitle uiWeatherTitle;
31     private UIWeatherView uiWeatherView;
32     private UISelectStationForm uiSelectStationForm;
33     
34     public UIWeatherViewPortlet() {
35         weatherData_ = new WeatherData();
36         weatherUtil_ = WeatherUtil.getInstance(this);
37         
38        setId("UIWeatherViewPortlet") ;
39         setRendererType("ChildrenRenderer");
40         
41         List JavaDoc children = getChildren();
42         
43         uiWeatherTitle = new UIWeatherTitle();
44         uiWeatherTitle.setId("UIWeatherViewPortletTitle");
45         uiWeatherTitle.setRendered(true);
46         uiWeatherView = new UIWeatherView();
47         uiWeatherView.setRendered(true);
48         uiSelectStationForm = new UISelectStationForm();
49         uiSelectStationForm.setRendered(false);
50         
51
52         if (weatherUtil_.isServiceInitialized()) {
53             uiWeatherView.setContextPath(weatherUtil_.getContextPath());
54             uiWeatherView.setResources(weatherUtil_.getResources());
55         }
56         process();
57         children.add(uiWeatherTitle);
58         children.add(uiWeatherView);
59         children.add(uiSelectStationForm);
60
61         //FormActionExceptionHandler unknownException =
62
// new FormActionExceptionHandler("Error ActionListener portlet weather (view mode)");
63
uiWeatherView.getUIWeatherForm().
64                 addActionListener(new SearchStationListener().
65               setActionToListen("WeatherFormSearch")) ;
66         uiSelectStationForm.addActionListener(new SelectStationListener().
67                 setActionToListen("SelectStationFormOk")) ;
68     }
69
70     private void process() {
71         String JavaDoc code;
72         
73         if (!weatherUtil_.isServiceInitialized()) {
74             uiWeatherTitle.setTitle("GlobalWeather Service can not be initialized");
75             uiWeatherTitle.setRendered(true);
76             uiWeatherView.setRendered(false);
77             uiSelectStationForm.setRendered(false);
78         }
79         else {
80             try {
81                 weatherUtil_.checkRequest(weatherData_);
82             }
83             catch (Exception JavaDoc ex) {
84                 ex.printStackTrace() ;
85                 weatherUtil_.setServiceAvailable(false);
86             }
87             if (!weatherUtil_.isServiceAvailable()) {
88                 uiWeatherTitle.setTitle("Service is not available");
89                 uiWeatherTitle.setRendered(true);
90                 uiWeatherView.setRendered(false);
91                 uiSelectStationForm.setRendered(false);
92             }
93             else {
94                 uiWeatherView.setStationFound(weatherData_.isStationFound());
95                 if (weatherData_.isStationFound()) {
96                     if (weatherData_.getNbStations() == 1) {
97                         Station station = weatherData_.getStationsList()[0];
98                         uiWeatherTitle.setTitle(station.getName()+" ("+station.getCountry()+")");
99                         try {
100                             uiWeatherView.setWeatherReport(weatherUtil_.getWeatherReport(weatherData_.getDisplayedStationCode()));
101                         } catch (Exception JavaDoc ex) {
102                             ex.printStackTrace();
103                         }
104                         uiWeatherTitle.setRendered(true);
105                         uiWeatherView.setRendered(true);
106                         uiSelectStationForm.setRendered(false);
107                     } else if (weatherData_.getNbStations() > 1) {
108                         uiWeatherTitle.setTitle("S�lection d'une station");
109                         uiWeatherTitle.setRendered(true);
110                         uiWeatherView.setRendered(false);
111                         uiSelectStationForm.setStationsList(weatherData_.getStationsList());
112                         uiSelectStationForm.setRendered(true);
113                     }
114                 }
115                 else {
116                     uiWeatherTitle.setTitle("Station inconnue");
117                     uiWeatherView.setWeatherReport(null);
118                     uiWeatherTitle.setRendered(true);
119                     uiWeatherView.setRendered(true);
120                     uiSelectStationForm.setRendered(false);
121                 }
122             }
123         }
124     }
125     
126     public class SearchStationListener extends ExoActionListener {
127         public void execute(ExoActionEvent event) throws Exception JavaDoc {
128             weatherData_.setSearchStationCode(uiWeatherView.getSearchStationCode());
129             uiWeatherView.setSearchStationCode("");
130             weatherData_.setSearchStationName(uiWeatherView.getSearchStationName());
131             uiWeatherView.setSearchStationName("");
132             weatherData_.setDisplayedStationCode("");
133             process();
134         }
135     }
136   
137     public class SelectStationListener extends ExoActionListener {
138         public void execute(ExoActionEvent event) throws Exception JavaDoc {
139             weatherData_.setSearchStationCode("");
140             weatherData_.setSearchStationName("");
141             weatherData_.setDisplayedStationCode(uiSelectStationForm.getSelectStationCode());
142             process();
143         }
144     }
145 }
146
147
Popular Tags