ingo@0: package de.intevation.flys.client.client; ingo@0: ingo@0: import com.google.gwt.core.client.EntryPoint; ingo@2: import com.google.gwt.core.client.GWT; ingo@2: import com.google.gwt.user.client.rpc.AsyncCallback; ingo@0: import com.google.gwt.user.client.ui.RootPanel; ingo@9: import com.google.gwt.xml.client.XMLParser; ingo@1: ingo@1: import com.smartgwt.client.widgets.layout.VLayout; raimund@80: import com.smartgwt.client.widgets.layout.HLayout; ingo@1: ingo@9: import de.intevation.flys.client.shared.model.Artifact; ingo@6: import de.intevation.flys.client.shared.model.Collection; ingo@6: import de.intevation.flys.client.shared.model.DefaultCollection; ingo@29: import de.intevation.flys.client.shared.model.River; ingo@25: import de.intevation.flys.client.shared.model.User; ingo@6: ingo@9: import de.intevation.flys.client.client.services.ArtifactService; ingo@9: import de.intevation.flys.client.client.services.ArtifactServiceAsync; ingo@29: import de.intevation.flys.client.client.services.RiverService; ingo@29: import de.intevation.flys.client.client.services.RiverServiceAsync; ingo@2: import de.intevation.flys.client.client.services.UserService; ingo@2: import de.intevation.flys.client.client.services.UserServiceAsync; ingo@6: import de.intevation.flys.client.client.ui.CollectionView; ingo@27: import de.intevation.flys.client.client.ui.FLYSHeader; ingo@1: import de.intevation.flys.client.client.ui.FLYSView; ingo@6: import de.intevation.flys.client.client.ui.FLYSWorkspace; ingo@1: import de.intevation.flys.client.client.ui.MainMenu; ingo@4: import de.intevation.flys.client.client.ui.ProjectList; raimund@80: import de.intevation.flys.client.client.ui.FLYSFooter; ingo@1: ingo@0: ingo@0: /** ingo@0: * Entry point classes define onModuleLoad(). ingo@1: * ingo@1: * @author Ingo Weinzierl ingo@0: */ ingo@0: public class FLYS implements EntryPoint { ingo@0: ingo@2: /** The UserService used to retrieve information about the current user. */ ingo@2: protected UserServiceAsync userService = GWT.create(UserService.class); ingo@2: ingo@29: /** The RiverService used to retrieve the supported rivers of the server.*/ ingo@29: protected RiverServiceAsync riverService = GWT.create(RiverService.class); ingo@29: ingo@9: /** The ArtifactService used to communicate with the Artifact server. */ ingo@9: protected ArtifactServiceAsync artifactService = ingo@9: GWT.create(ArtifactService.class); ingo@9: ingo@4: /** The menu bar at the top of the application.*/ ingo@2: protected MainMenu menu; ingo@4: ingo@4: /** The content window. It takes the whole space beneath the menu bar.*/ ingo@2: protected FLYSView view; ingo@2: ingo@4: /** The project list that displays the projects of the user.*/ ingo@4: protected ProjectList projectList; ingo@4: ingo@6: /** The FLYSWorkspace.*/ ingo@6: protected FLYSWorkspace workspace; ingo@6: raimund@80: /** The footer. */ raimund@80: protected FLYSFooter footer; raimund@80: ingo@25: /** The user who is currently logged in.*/ ingo@25: protected User currentUser; ingo@25: ingo@29: /** The list of rivers supported by the server.*/ ingo@29: protected River[] rivers; ingo@29: ingo@2: ingo@1: /** ingo@1: * This is the entry point method. ingo@1: */ ingo@1: public void onModuleLoad() { ingo@0: ingo@1: VLayout vertical = new VLayout(); ingo@1: vertical.setLayoutMargin(1); ingo@1: vertical.setWidth100(); ingo@1: vertical.setHeight100(); ingo@0: raimund@80: HLayout spacerBar = new HLayout(); raimund@80: spacerBar.setWidth("100%"); raimund@80: spacerBar.setHeight("20px"); raimund@80: spacerBar.setStyleName("bgBlueLight"); raimund@80: ingo@6: menu = new MainMenu(this); ingo@2: view = new FLYSView(); raimund@80: footer = new FLYSFooter(this); ingo@1: ingo@27: vertical.addMember(new FLYSHeader()); ingo@1: vertical.addMember(menu); raimund@80: vertical.addMember(spacerBar); ingo@1: vertical.addMember(view); raimund@80: vertical.addMember(footer); ingo@1: ingo@1: RootPanel.get("app").add(vertical); ingo@2: ingo@9: initConfiguration(); ingo@25: String serverUrl = Config.getInstance().getServerUrl(); ingo@9: ingo@29: getRivers(); ingo@29: ingo@25: userService.getCurrentUser(serverUrl, new AsyncCallback() { ingo@2: public void onFailure(Throwable caught) { ingo@2: GWT.log("Could not find a logged in user."); ingo@2: // TODO do something ingo@2: } ingo@2: ingo@2: public void onSuccess(User user) { ingo@25: GWT.log("Found a user. Set '"+ user.getName() + "'"); ingo@25: setCurrentUser(user); ingo@25: ingo@2: menu.setCurrentUser(user); ingo@4: ingo@4: projectList = new ProjectList(user); ingo@6: workspace = new FLYSWorkspace(); ingo@4: view.setProjectList(projectList); ingo@6: view.setFLYSWorkspace(workspace); ingo@2: } ingo@2: }); ingo@0: } ingo@6: ingo@6: ingo@6: /** ingo@9: * This method should be called at system start. It initialzes the client ingo@9: * configuration. ingo@9: */ ingo@9: protected void initConfiguration() { ingo@9: String xml = FLYSResources.INSTANCE.initialConfiguration().getText(); ingo@9: Config.getInstance(XMLParser.parse(xml)); ingo@9: } ingo@9: ingo@9: ingo@9: /** ingo@25: * Returns the user that is currently logged in. ingo@25: * ingo@25: * @return the current user. ingo@25: */ ingo@25: public User getCurrentUser() { ingo@25: return currentUser; ingo@25: } ingo@25: ingo@25: ingo@25: /** ingo@25: * Sets the current user. ingo@25: */ ingo@25: public void setCurrentUser(User user) { ingo@25: currentUser = user; ingo@25: } ingo@25: ingo@25: ingo@25: /** ingo@28: * Returns the project list. ingo@28: */ ingo@28: public ProjectList getProjectList() { ingo@28: return projectList; ingo@28: } ingo@28: ingo@28: ingo@28: /** ingo@29: * Returns a list of rivers supported by the artifact server. ingo@29: * ingo@29: * @return a list of rivers supported by the artifact server. ingo@29: */ ingo@29: public River[] getRivers() { ingo@29: if (rivers == null) { ingo@29: String url = Config.getInstance().getServerUrl(); ingo@29: GWT.log("Fetch rivers from server '" + url + "'"); ingo@29: ingo@29: riverService.list(url, new AsyncCallback() { ingo@29: public void onFailure(Throwable caught) { ingo@29: GWT.log("Could not recieve a list of rivers."); ingo@29: GWT.log(caught.getMessage()); ingo@29: } ingo@29: ingo@29: public void onSuccess(River[] newRivers) { ingo@29: GWT.log("Retrieved " + newRivers.length + " new rivers."); ingo@29: rivers = newRivers; ingo@29: } ingo@29: }); ingo@29: } ingo@29: ingo@29: return rivers; ingo@29: } ingo@29: ingo@29: ingo@29: /** ingo@6: * This method creates a new CollectionView and adds it to the workspace. ingo@6: */ ingo@6: public void newProject() { ingo@100: CollectionView view = new CollectionView(this); ingo@100: workspace.addView(view); ingo@97: ingo@97: view.addCollectionChangeHandler(getProjectList()); ingo@9: } ingo@9: ingo@9: ingo@9: /** ingo@9: * Create a new Artifact. ingo@9: */ ingo@9: public void newArtifact(String factory) { ingo@14: String url = Config.getInstance().getServerUrl(); ingo@14: ingo@14: artifactService.create(url, factory, new AsyncCallback() { ingo@9: public void onFailure(Throwable caught) { ingo@9: GWT.log("Could not create the new artifact."); ingo@9: GWT.log(caught.getMessage()); ingo@9: } ingo@9: ingo@9: public void onSuccess(Artifact artifact) { ingo@9: GWT.log("Successfully created a new artifact."); ingo@9: } ingo@9: }); ingo@6: } ingo@0: } ingo@1: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :