comparison flys-client/src/main/java/de/intevation/flys/client/client/FLYS.java @ 217:907b61e4d702

Improved the exception handling - added warnings for user authentication errors and errors that occur while fetching supported rivers. flys-client/trunk@1659 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Fri, 08 Apr 2011 10:05:14 +0000
parents f7967d12ce6e
children 9040663aee01
comparison
equal deleted inserted replaced
216:4b0fb079ead9 217:907b61e4d702
4 import com.google.gwt.core.client.GWT; 4 import com.google.gwt.core.client.GWT;
5 import com.google.gwt.user.client.rpc.AsyncCallback; 5 import com.google.gwt.user.client.rpc.AsyncCallback;
6 import com.google.gwt.user.client.ui.RootPanel; 6 import com.google.gwt.user.client.ui.RootPanel;
7 import com.google.gwt.xml.client.XMLParser; 7 import com.google.gwt.xml.client.XMLParser;
8 8
9 import com.smartgwt.client.util.SC;
9 import com.smartgwt.client.widgets.layout.VLayout; 10 import com.smartgwt.client.widgets.layout.VLayout;
10 import com.smartgwt.client.widgets.layout.HLayout; 11 import com.smartgwt.client.widgets.layout.HLayout;
11 12
12 import de.intevation.flys.client.shared.model.Artifact; 13 import de.intevation.flys.client.shared.model.Artifact;
13 import de.intevation.flys.client.shared.model.River; 14 import de.intevation.flys.client.shared.model.River;
33 * 34 *
34 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> 35 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
35 */ 36 */
36 public class FLYS implements EntryPoint { 37 public class FLYS implements EntryPoint {
37 38
39 /** The message class that provides i18n strings.*/
40 protected FLYSConstants MSG = GWT.create(FLYSConstants.class);
41
38 /** The UserService used to retrieve information about the current user. */ 42 /** The UserService used to retrieve information about the current user. */
39 protected UserServiceAsync userService = GWT.create(UserService.class); 43 protected UserServiceAsync userService = GWT.create(UserService.class);
40 44
41 /** The RiverService used to retrieve the supported rivers of the server.*/ 45 /** The RiverService used to retrieve the supported rivers of the server.*/
42 protected RiverServiceAsync riverService = GWT.create(RiverService.class); 46 protected RiverServiceAsync riverService = GWT.create(RiverService.class);
100 getRivers(); 104 getRivers();
101 105
102 userService.getCurrentUser(serverUrl, new AsyncCallback<User>() { 106 userService.getCurrentUser(serverUrl, new AsyncCallback<User>() {
103 public void onFailure(Throwable caught) { 107 public void onFailure(Throwable caught) {
104 GWT.log("Could not find a logged in user."); 108 GWT.log("Could not find a logged in user.");
105 // TODO do something 109 SC.warn(MSG.getString(caught.getMessage()));
106 } 110 }
107 111
108 public void onSuccess(User user) { 112 public void onSuccess(User user) {
109 GWT.log("Found a user. Set '"+ user.getName() + "'"); 113 GWT.log("Found a user. Set '"+ user.getName() + "'");
110 setCurrentUser(user); 114 setCurrentUser(user);
113 117
114 projectList = new ProjectList(user); 118 projectList = new ProjectList(user);
115 workspace = new FLYSWorkspace(); 119 workspace = new FLYSWorkspace();
116 view.setProjectList(projectList); 120 view.setProjectList(projectList);
117 view.setFLYSWorkspace(workspace); 121 view.setFLYSWorkspace(workspace);
122
123 readRivers();
118 } 124 }
119 }); 125 });
120 } 126 }
121 127
122 128
160 * Returns a list of rivers supported by the artifact server. 166 * Returns a list of rivers supported by the artifact server.
161 * 167 *
162 * @return a list of rivers supported by the artifact server. 168 * @return a list of rivers supported by the artifact server.
163 */ 169 */
164 public River[] getRivers() { 170 public River[] getRivers() {
165 if (rivers == null) { 171 return rivers;
166 String url = Config.getInstance().getServerUrl(); 172 }
167 GWT.log("Fetch rivers from server '" + url + "'"); 173
168 174
169 riverService.list(url, new AsyncCallback<River[]>() { 175 protected void readRivers() {
170 public void onFailure(Throwable caught) { 176 String url = Config.getInstance().getServerUrl();
171 GWT.log("Could not recieve a list of rivers."); 177 GWT.log("Fetch rivers from server '" + url + "'");
172 GWT.log(caught.getMessage()); 178
173 } 179 riverService.list(url, new AsyncCallback<River[]>() {
174 180 public void onFailure(Throwable caught) {
175 public void onSuccess(River[] newRivers) { 181 GWT.log("Could not recieve a list of rivers.");
176 GWT.log("Retrieved " + newRivers.length + " new rivers."); 182 SC.warn(MSG.getString(caught.getMessage()));
177 rivers = newRivers; 183 }
178 } 184
179 }); 185 public void onSuccess(River[] newRivers) {
186 GWT.log("Retrieved " + newRivers.length + " new rivers.");
187 rivers = newRivers;
188 }
189 });
190 }
191
192
193 /**
194 * This method creates a new CollectionView and adds it to the workspace.
195 * <b>NOTE</b>The user needs to be logged in and there need to at least one
196 * river - otherwise a warning is displayed and no CollectionView is
197 * created.
198 */
199 public void newProject() {
200 if (getCurrentUser() == null) {
201 SC.warn(MSG.error_not_logged_in());
202 return;
180 } 203 }
181 204
182 return rivers; 205 if (getRivers() == null) {
183 } 206 SC.warn(MSG.error_no_rivers_found());
184 207 readRivers();
185 208
186 /** 209 return;
187 * This method creates a new CollectionView and adds it to the workspace. 210 }
188 */ 211
189 public void newProject() {
190 CollectionView view = new CollectionView(this); 212 CollectionView view = new CollectionView(this);
191 workspace.addView(view); 213 workspace.addView(view);
192 214
193 view.addCollectionChangeHandler(getProjectList()); 215 view.addCollectionChangeHandler(getProjectList());
194 } 216 }

http://dive4elements.wald.intevation.org