changeset 9:8facd8545a12

Added a global configuration for the client and classes providing methods to retrieve these information. flys-client/trunk@1317 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Wed, 16 Feb 2011 14:50:06 +0000
parents 9cb3ee7ed8ba
children fc616c192902
files flys-client/ChangeLog flys-client/src/main/java/de/intevation/flys/client/FLYS.gwt.xml flys-client/src/main/java/de/intevation/flys/client/client/Config.java flys-client/src/main/java/de/intevation/flys/client/client/FLYS.java flys-client/src/main/java/de/intevation/flys/client/client/FLYSResources.java flys-client/src/main/java/de/intevation/flys/client/client/config.xml
diffstat 6 files changed, 155 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/flys-client/ChangeLog	Fri Feb 11 13:48:17 2011 +0000
+++ b/flys-client/ChangeLog	Wed Feb 16 14:50:06 2011 +0000
@@ -1,3 +1,18 @@
+2011-02-16  Ingo Weinzierl <ingo@intevation.de>
+
+	* src/main/java/de/intevation/flys/client/FLYS.gwt.xml: Added the
+	  Resources and XML modules of GWT.
+
+	* src/main/java/de/intevation/flys/client/client/config.xml: An xml file
+	  that will contain the client configuration.
+
+	* src/main/java/de/intevation/flys/client/client/Config.java: New. This
+	  class should be used to handle the client configuration and provides
+	  methods for retrieving information about the configuration.
+
+	* src/main/java/de/intevation/flys/client/client/FLYSResources.java: The
+	  configuration (Config) is initialized at the startup.
+
 2011-02-11  Ingo Weinzierl <ingo@intevation.de>
 
 	* src/main/java/de/intevation/flys/client/shared/model/Artifact.java: New.
--- a/flys-client/src/main/java/de/intevation/flys/client/FLYS.gwt.xml	Fri Feb 11 13:48:17 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/FLYS.gwt.xml	Wed Feb 16 14:50:06 2011 +0000
@@ -6,6 +6,12 @@
   <!-- Inherit the i18n google stuff.                             -->
   <inherits name="com.google.gwt.i18n.I18N"/>
 
+  <!-- Inherit the XML stuff of GWT                               -->
+  <inherits name="com.google.gwt.xml.XML"/>
+
+  <!-- Inherit the Resource module of GWT                         -->
+  <inherits name="com.google.gwt.resources.Resources"/>
+
   <!-- Inherit the SmartGwt library.                              -->
   <inherits name="com.smartgwt.SmartGwt"/>
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/Config.java	Wed Feb 16 14:50:06 2011 +0000
@@ -0,0 +1,72 @@
+package de.intevation.flys.client.client;
+
+import com.google.gwt.xml.client.Document;
+import com.google.gwt.xml.client.Node;
+
+
+/**
+ * A class that is used to handle the global configuration of this client. You
+ * can retrieve an instance of this class using the <code>getInstance</code>
+ * methods. <b>NOTE:</b> the configuration is initialized using {@link
+ * getInstance(Document)} the first time.
+ *
+ * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
+ */
+public class Config {
+
+    /** The instance of the configuration. */
+    protected static Config INSTANCE;
+
+    /** The xml document that contains the configuration options.*/
+    protected Document config;
+
+
+    /**
+     * Get an instance by using {@link getInstance(Document)} or {@link
+     * getInstance()}.
+     */
+    private Config(Document config) {
+        this.config = config;
+    }
+
+
+    /**
+     * Returns an instance of this class and initializes the configuration of
+     * this has not been done so far.
+     *
+     * @param config The client configuration.
+     *
+     * @return an instance of this Config class.
+     */
+    public static Config getInstance(Document config) {
+        if (INSTANCE == null) {
+            INSTANCE = new Config(config);
+        }
+
+        return INSTANCE;
+    }
+
+
+    /**
+     * Returns an instance of this class. If it has not been initialized with a
+     * valid configuration, null is returned.
+     *
+     * @return an instance of this class or null, if the Config has not been
+     * initialized using {@link getInstance(Document)} so far.
+     */
+    public static Config getInstance() {
+        return INSTANCE;
+    }
+
+
+    /**
+     * Returns the URL of the artifact server.
+     *
+     * @return the artifact server url.
+     */
+    public String getServerUrl() {
+        Node server = config.getElementsByTagName("server").item(0);
+        return server.getFirstChild().getNodeValue();
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/FLYS.java	Fri Feb 11 13:48:17 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/FLYS.java	Wed Feb 16 14:50:06 2011 +0000
@@ -4,14 +4,18 @@
 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.widgets.layout.VLayout;
 
 import de.intevation.artifacts.common.model.User;
 
+import de.intevation.flys.client.shared.model.Artifact;
 import de.intevation.flys.client.shared.model.Collection;
 import de.intevation.flys.client.shared.model.DefaultCollection;
 
+import de.intevation.flys.client.client.services.ArtifactService;
+import de.intevation.flys.client.client.services.ArtifactServiceAsync;
 import de.intevation.flys.client.client.services.UserService;
 import de.intevation.flys.client.client.services.UserServiceAsync;
 import de.intevation.flys.client.client.ui.CollectionView;
@@ -31,6 +35,10 @@
     /** The UserService used to retrieve information about the current user. */
     protected UserServiceAsync userService = GWT.create(UserService.class);
 
+    /** The ArtifactService used to communicate with the Artifact server. */
+    protected ArtifactServiceAsync artifactService =
+        GWT.create(ArtifactService.class);
+
     /** The menu bar at the top of the application.*/
     protected MainMenu menu;
 
@@ -63,6 +71,8 @@
 
         RootPanel.get("app").add(vertical);
 
+        initConfiguration();
+
         userService.getCurrentUser(new AsyncCallback<User>() {
             public void onFailure(Throwable caught) {
                 GWT.log("Could not find a logged in user.");
@@ -83,13 +93,40 @@
 
 
     /**
+     * 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));
+    }
+
+
+    /**
      * This method creates a new CollectionView and adds it to the workspace.
      */
     public void newProject() {
         // TODO Call the REST service to create a new Collection
         // TODO Use the UUID of the Collection to add a new CollectionView!
         Collection c = new DefaultCollection(new java.util.Date().toString());
-        workspace.addView(c.identifier(), new CollectionView(c));
+        workspace.addView(c.identifier(), new CollectionView(this, c));
+    }
+
+
+    /**
+     * Create a new Artifact.
+     */
+    public void newArtifact(String factory) {
+        artifactService.create(factory, new AsyncCallback<Artifact>() {
+            public void onFailure(Throwable caught) {
+                GWT.log("Could not create the new artifact.");
+                GWT.log(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 :
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/FLYSResources.java	Wed Feb 16 14:50:06 2011 +0000
@@ -0,0 +1,21 @@
+package de.intevation.flys.client.client;
+
+import com.google.gwt.core.client.GWT;
+import com.google.gwt.resources.client.ClientBundle;
+import com.google.gwt.resources.client.TextResource;
+
+
+/**
+ * A {@link ClientBundle} that is used to handle resources in this client.
+ *
+ * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
+ */
+public interface FLYSResources extends ClientBundle {
+
+    public static final FLYSResources INSTANCE =
+        GWT.create(FLYSResources.class);
+
+        @Source("config.xml")
+        public TextResource initialConfiguration();
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/config.xml	Wed Feb 16 14:50:06 2011 +0000
@@ -0,0 +1,3 @@
+<config>
+    <server>http://localhost:8181</server>
+</config>

http://dive4elements.wald.intevation.org