Mercurial > dive4elements > river
diff 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 |
line wrap: on
line diff
--- a/flys-client/src/main/java/de/intevation/flys/client/client/FLYS.java Fri Apr 08 09:51:41 2011 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/FLYS.java Fri Apr 08 10:05:14 2011 +0000 @@ -6,6 +6,7 @@ import com.google.gwt.user.client.ui.RootPanel; import com.google.gwt.xml.client.XMLParser; +import com.smartgwt.client.util.SC; import com.smartgwt.client.widgets.layout.VLayout; import com.smartgwt.client.widgets.layout.HLayout; @@ -35,6 +36,9 @@ */ public class FLYS implements EntryPoint { + /** The message class that provides i18n strings.*/ + protected FLYSConstants MSG = GWT.create(FLYSConstants.class); + /** The UserService used to retrieve information about the current user. */ protected UserServiceAsync userService = GWT.create(UserService.class); @@ -102,7 +106,7 @@ userService.getCurrentUser(serverUrl, new AsyncCallback<User>() { public void onFailure(Throwable caught) { GWT.log("Could not find a logged in user."); - // TODO do something + SC.warn(MSG.getString(caught.getMessage())); } public void onSuccess(User user) { @@ -115,6 +119,8 @@ workspace = new FLYSWorkspace(); view.setProjectList(projectList); view.setFLYSWorkspace(workspace); + + readRivers(); } }); } @@ -162,31 +168,47 @@ * @return a list of rivers supported by the artifact server. */ public River[] getRivers() { - if (rivers == null) { - String url = Config.getInstance().getServerUrl(); - GWT.log("Fetch rivers from server '" + url + "'"); + return rivers; + } - riverService.list(url, new AsyncCallback<River[]>() { - public void onFailure(Throwable caught) { - GWT.log("Could not recieve a list of rivers."); - GWT.log(caught.getMessage()); - } - public void onSuccess(River[] newRivers) { - GWT.log("Retrieved " + newRivers.length + " new rivers."); - rivers = newRivers; - } - }); - } + protected void readRivers() { + String url = Config.getInstance().getServerUrl(); + GWT.log("Fetch rivers from server '" + url + "'"); - return rivers; + riverService.list(url, new AsyncCallback<River[]>() { + public void onFailure(Throwable caught) { + GWT.log("Could not recieve a list of rivers."); + SC.warn(MSG.getString(caught.getMessage())); + } + + public void onSuccess(River[] newRivers) { + GWT.log("Retrieved " + newRivers.length + " new rivers."); + rivers = newRivers; + } + }); } /** * This method creates a new CollectionView and adds it to the workspace. + * <b>NOTE</b>The user needs to be logged in and there need to at least one + * river - otherwise a warning is displayed and no CollectionView is + * created. */ public void newProject() { + if (getCurrentUser() == null) { + SC.warn(MSG.error_not_logged_in()); + return; + } + + if (getRivers() == null) { + SC.warn(MSG.error_no_rivers_found()); + readRivers(); + + return; + } + CollectionView view = new CollectionView(this); workspace.addView(view);