Mercurial > dive4elements > river
view flys-client/src/main/java/de/intevation/flys/client/client/FLYS.java @ 514:b9127f876a6a
Enhanced the Data object to save default values/labels.
flys-client/trunk@1984 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Tue, 24 May 2011 10:44:59 +0000 |
parents | 924da6695800 |
children | 92c200887b20 |
line wrap: on
line source
package de.intevation.flys.client.client; import com.google.gwt.core.client.EntryPoint; import com.google.gwt.core.client.GWT; import com.google.gwt.user.client.rpc.AsyncCallback; 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; import de.intevation.flys.client.shared.model.Artifact; import de.intevation.flys.client.shared.model.Collection; import de.intevation.flys.client.shared.model.CollectionItem; import de.intevation.flys.client.shared.model.River; import de.intevation.flys.client.shared.model.User; import de.intevation.flys.client.client.services.ArtifactService; import de.intevation.flys.client.client.services.ArtifactServiceAsync; import de.intevation.flys.client.client.services.DescribeCollectionService; import de.intevation.flys.client.client.services.DescribeCollectionServiceAsync; import de.intevation.flys.client.client.services.GetArtifactService; import de.intevation.flys.client.client.services.GetArtifactServiceAsync; import de.intevation.flys.client.client.services.RiverService; import de.intevation.flys.client.client.services.RiverServiceAsync; import de.intevation.flys.client.client.services.UserService; import de.intevation.flys.client.client.services.UserServiceAsync; import de.intevation.flys.client.client.ui.CollectionView; import de.intevation.flys.client.client.ui.FLYSHeader; import de.intevation.flys.client.client.ui.FLYSView; import de.intevation.flys.client.client.ui.FLYSWorkspace; import de.intevation.flys.client.client.ui.MainMenu; import de.intevation.flys.client.client.ui.ProjectList; import de.intevation.flys.client.client.ui.FLYSFooter; /** * Entry point classes define <code>onModuleLoad()</code>. * * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> */ 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); /** The RiverService used to retrieve the supported rivers of the server.*/ protected RiverServiceAsync riverService = GWT.create(RiverService.class); /** The ArtifactService used to communicate with the Artifact server. */ protected ArtifactServiceAsync artifactService = GWT.create(ArtifactService.class); /** The ArtifactService used to communicate with the Artifact server. */ protected DescribeCollectionServiceAsync describeCollectionService = GWT.create(DescribeCollectionService.class); /** The GetArtifactService used to open an existing collection. */ protected GetArtifactServiceAsync getArtifactService = GWT.create(GetArtifactService.class); /** The menu bar at the top of the application.*/ protected MainMenu menu; /** The content window. It takes the whole space beneath the menu bar.*/ protected FLYSView view; /** The project list that displays the projects of the user.*/ protected ProjectList projectList; /** The FLYSWorkspace.*/ protected FLYSWorkspace workspace; /** The footer. */ protected FLYSFooter footer; /** The user who is currently logged in.*/ protected User currentUser; /** The list of rivers supported by the server.*/ protected River[] rivers; /** * This is the entry point method. */ public void onModuleLoad() { VLayout vertical = new VLayout(); vertical.setLayoutMargin(1); vertical.setWidth100(); vertical.setHeight100(); HLayout spacerBar = new HLayout(); spacerBar.setWidth("100%"); spacerBar.setHeight("20px"); spacerBar.setStyleName("bgBlueLight"); menu = new MainMenu(this); view = new FLYSView(); footer = new FLYSFooter(this); vertical.addMember(new FLYSHeader()); vertical.addMember(menu); vertical.addMember(spacerBar); vertical.addMember(view); vertical.addMember(footer); RootPanel.get("app").add(vertical); initConfiguration(); Config config = Config.getInstance(); String url = config.getServerUrl(); String locale = config.getLocale(); getRivers(); userService.getCurrentUser(url, locale, new AsyncCallback<User>() { public void onFailure(Throwable caught) { GWT.log("Could not find a logged in user."); SC.warn(MSG.getString(caught.getMessage())); } public void onSuccess(User user) { GWT.log("Found a user. Set '"+ user.getName() + "'"); setCurrentUser(user); menu.setCurrentUser(user); projectList = new ProjectList(FLYS.this, user); workspace = new FLYSWorkspace(); view.setProjectList(projectList); view.setFLYSWorkspace(workspace); readRivers(); } }); } /** * This method should be called at system start. It initialzes the client * configuration. */ protected void initConfiguration() { String xml = FLYSResources.INSTANCE.initialConfiguration().getText(); Config.getInstance(XMLParser.parse(xml)); } /** * Returns the user that is currently logged in. * * @return the current user. */ public User getCurrentUser() { return currentUser; } /** * Sets the current user. */ public void setCurrentUser(User user) { currentUser = user; } /** * Returns the project list. */ public ProjectList getProjectList() { return projectList; } /** * Returns a list of rivers supported by the artifact server. * * @return a list of rivers supported by the artifact server. */ public River[] getRivers() { return rivers; } protected void readRivers() { Config config = Config.getInstance(); String url = config.getServerUrl(); String locale = config.getLocale(); GWT.log("Fetch rivers from server '" + url + "'"); riverService.list(url, locale, 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); view.addCollectionChangeHandler(getProjectList()); } public void openProject(String collectionID) { if (collectionID == null) { return; } GWT.log("Open existing project: " + collectionID); Config config = Config.getInstance(); final String url = config.getServerUrl(); final String locale = config.getLocale(); describeCollectionService.describe(collectionID, url, locale, new AsyncCallback<Collection>() { public void onFailure(Throwable caught) { SC.warn(MSG.getString(caught.getMessage())); } public void onSuccess(Collection c) { final Collection collection = c; final CollectionItem item = c.getItem(0); if (item == null) { SC.warn(MSG.error_load_parameterization()); return; } getArtifactService.getArtifact( url, locale, item.identifier(), item.hash(), new AsyncCallback<Artifact>() { public void onFailure(Throwable caught) { SC.warn(MSG.getString(caught.getMessage())); } public void onSuccess(Artifact artifact) { CollectionView view = new CollectionView( FLYS.this, collection, artifact); view.addCollectionChangeHandler( getProjectList()); workspace.addView(view); } }); } }); } /** * Create a new Artifact. */ public void newArtifact(String factory) { Config config = Config.getInstance(); String url = config.getServerUrl(); String locale = config.getLocale(); artifactService.create(url, locale, factory, new AsyncCallback<Artifact>() { public void onFailure(Throwable caught) { GWT.log("Could not create the new artifact."); SC.warn(MSG.getString(caught.getMessage())); } public void onSuccess(Artifact artifact) { GWT.log("Successfully created a new artifact."); } }); } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :