Mercurial > dive4elements > river
changeset 97:0bec0112c8b3
Integrated the ProjectList into the client. Now, the Collections of a user are displayed in the list.
flys-client/trunk@1610 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Tue, 29 Mar 2011 13:53:24 +0000 |
parents | 261a2ee7d9bb |
children | 83bf2fb17b7c |
files | flys-client/ChangeLog flys-client/src/main/java/de/intevation/flys/client/client/FLYS.java flys-client/src/main/java/de/intevation/flys/client/client/FLYSMessages.java flys-client/src/main/java/de/intevation/flys/client/client/FLYSMessages_de.properties flys-client/src/main/java/de/intevation/flys/client/client/FLYSMessages_en.properties flys-client/src/main/java/de/intevation/flys/client/client/ui/CollectionGrid.java flys-client/src/main/java/de/intevation/flys/client/client/ui/ProjectList.java flys-client/src/main/java/de/intevation/flys/client/shared/model/CollectionRecord.java flys-client/src/main/webapp/WEB-INF/web.xml |
diffstat | 9 files changed, 132 insertions(+), 34 deletions(-) [+] |
line wrap: on
line diff
--- a/flys-client/ChangeLog Tue Mar 29 13:49:04 2011 +0000 +++ b/flys-client/ChangeLog Tue Mar 29 13:53:24 2011 +0000 @@ -1,3 +1,21 @@ +2011-03-29 Ingo Weinzierl <ingo@intevation.de> + + * src/main/java/de/intevation/flys/client/client/FLYS.java: Registered the + ProjectList as CollectionChangeHandler of each created CollectionView. + + * src/main/java/de/intevation/flys/client/client/ui/ProjectList.java: + Implements the CollectionChangeHandler to update the list of user + collections after a collection changed (or has been created). + + * src/main/java/de/intevation/flys/client/client/ui/CollectionGrid.java, + src/main/java/de/intevation/flys/client/shared/model/CollectionRecord.java: + Modified the output of the 'name' and 'date' fields. + + * src/main/java/de/intevation/flys/client/client/FLYSMessages_en.properties, + src/main/java/de/intevation/flys/client/client/FLYSMessages_de.properties, + src/main/java/de/intevation/flys/client/client/FLYSMessages.java: + Added a format for datetime strings. + 2011-03-29 Ingo Weinzierl <ingo@intevation.de> * src/main/java/de/intevation/flys/client/server/UserCollectionsServiceImpl.java,
--- a/flys-client/src/main/java/de/intevation/flys/client/client/FLYS.java Tue Mar 29 13:49:04 2011 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/FLYS.java Tue Mar 29 13:53:24 2011 +0000 @@ -192,7 +192,11 @@ // 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(this, c)); + + CollectionView view = new CollectionView(this, c); + view.addCollectionChangeHandler(getProjectList()); + + workspace.addView(c.identifier(), view); }
--- a/flys-client/src/main/java/de/intevation/flys/client/client/FLYSMessages.java Tue Mar 29 13:49:04 2011 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/FLYSMessages.java Tue Mar 29 13:53:24 2011 +0000 @@ -44,6 +44,9 @@ @DefaultMessage("yyyy-MM-dd") String date_format(); + @DefaultMessage("yyyy-MM-dd HH:mm") + String datetime_format(); + @DefaultMessage("New Project") String new_project();
--- a/flys-client/src/main/java/de/intevation/flys/client/client/FLYSMessages_de.properties Tue Mar 29 13:49:04 2011 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/FLYSMessages_de.properties Tue Mar 29 13:53:24 2011 +0000 @@ -10,6 +10,7 @@ no_projects = Keine alten Berechnungen gefunden. load_projects = Lade Berechnungen... date_format = dd.MM.yyyy +datetime_format = dd.MM.yyyy HH:mm new_project = Neues Projekt new_calculation = Neue Berechnung module_selection = Modul
--- a/flys-client/src/main/java/de/intevation/flys/client/client/FLYSMessages_en.properties Tue Mar 29 13:49:04 2011 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/FLYSMessages_en.properties Tue Mar 29 13:53:24 2011 +0000 @@ -10,6 +10,7 @@ no_projects = No existing calculations found. load_projects = Load calculations... date_format = yyyy-MM-dd +datetime_format = yyyy-MM-dd HH:mm new_project = New Project new_calculation = New Calculation module_selection = Module
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/CollectionGrid.java Tue Mar 29 13:49:04 2011 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/CollectionGrid.java Tue Mar 29 13:53:24 2011 +0000 @@ -56,12 +56,15 @@ protected Canvas createDateField(ListGridRecord record) { CollectionRecord rec = (CollectionRecord) record; - Date date = rec.getDate(); - DateTimeFormat dtf = DateTimeFormat.getFormat(messages.date_format()); + Date date = rec.getCreationTime(); + DateTimeFormat dtf = DateTimeFormat.getFormat( + messages.datetime_format()); + String formatted = dtf.format(date); Label label = new Label(formatted); label.setHeight(15); + label.setWidth100(); return label; } @@ -75,8 +78,14 @@ protected Canvas createNameField(ListGridRecord record) { CollectionRecord rec = (CollectionRecord) record; - Label label = new Label(rec.getName()); + String name = rec.getName(); + int len = name.length(); + int sec = len - 15; + String sub = name.substring(0, 14) + "..." + name.substring(sec, len-1); + + Label label = new Label(sub); label.setHeight(15); + label.setWidth100(); return label; } @@ -91,7 +100,6 @@ protected Canvas createPublishField(ListGridRecord record) { IButton button = new IButton(); button.setHeight(15); - button.setWidth(30); button.setTitle("PUB"); return button; } @@ -106,7 +114,6 @@ protected Canvas createDeleteField(ListGridRecord record) { IButton button = new IButton(); button.setHeight(15); - button.setWidth(30); button.setTitle("DEL"); return button; }
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/ProjectList.java Tue Mar 29 13:49:04 2011 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/ProjectList.java Tue Mar 29 13:53:24 2011 +0000 @@ -1,20 +1,26 @@ package de.intevation.flys.client.client.ui; import com.google.gwt.core.client.GWT; +import com.google.gwt.user.client.rpc.AsyncCallback; import com.smartgwt.client.widgets.Canvas; import com.smartgwt.client.widgets.Label; import com.smartgwt.client.widgets.grid.ListGrid; import com.smartgwt.client.widgets.grid.ListGridField; +import com.smartgwt.client.widgets.grid.ListGridRecord; import com.smartgwt.client.widgets.layout.VLayout; import com.smartgwt.client.types.VerticalAlignment; import de.intevation.flys.client.shared.model.Collection; import de.intevation.flys.client.shared.model.CollectionRecord; -import de.intevation.flys.client.shared.model.DefaultCollection; +import de.intevation.flys.client.shared.model.User; +import de.intevation.flys.client.client.Config; import de.intevation.flys.client.client.FLYSMessages; -import de.intevation.flys.client.shared.model.User; +import de.intevation.flys.client.client.event.CollectionChangeEvent; +import de.intevation.flys.client.client.event.CollectionChangeHandler; +import de.intevation.flys.client.client.services.UserCollectionsService; +import de.intevation.flys.client.client.services.UserCollectionsServiceAsync; /** @@ -22,11 +28,17 @@ * * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> */ -public class ProjectList extends VLayout { - +public class ProjectList +extends VLayout +implements CollectionChangeHandler +{ /** The interface that provides i18n messages. */ private FLYSMessages messages = GWT.create(FLYSMessages.class); + /** The UserService used to retrieve information about the current user. */ + protected UserCollectionsServiceAsync userCollectionsService = + GWT.create(UserCollectionsService.class); + /** The user whose projects should be displayed.*/ protected User user; @@ -44,19 +56,9 @@ grid = new CollectionGrid(); initGrid(); + init(); - // TODO Remove the following code block after a service to fetch the - // user collections has been implemented! Instead of these static lines, - // a callback mechanism should be implemented that updates this widget - // when the current user changes. - Collection c1 = new DefaultCollection("uu-1"); - Collection c2 = new DefaultCollection("uu-2"); - CollectionRecord rec1 = new CollectionRecord(c1); - CollectionRecord rec2 = new CollectionRecord(c2); - grid.addData(rec1); - grid.addData(rec2); - - init(); + updateUserCollections(); } @@ -68,18 +70,15 @@ grid.setCanRemoveRecords(false); grid.setShowHeader(false); grid.setWidth100(); + grid.setHeight100(); ListGridField date = new ListGridField("date", "date"); ListGridField name = new ListGridField("name", "name"); - ListGridField pub = new ListGridField("publish", "publish"); - ListGridField del = new ListGridField("delete", "delete"); - date.setWidth(70); - name.setWidth(155); - pub.setWidth(35); - del.setWidth(35); + date.setWidth(100); + name.setWidth(195); - grid.setFields(date, name, pub, del); + grid.setFields(date, name); } @@ -114,5 +113,57 @@ addMember(titleWrapper); addMember(gridWrapper); } + + + public void onCollectionChange(CollectionChangeEvent event) { + GWT.log("ProjectList.onCollectionChange"); + + updateUserCollections(); + } + + + protected void updateUserCollections() { + Config config = Config.getInstance(); + String url = config.getServerUrl(); + + userCollectionsService.getUserCollections(url, user.identifier(), + new AsyncCallback<Collection[]>() { + public void onFailure(Throwable caught) { + GWT.log("Could not recieve a list of user collections."); + GWT.log(caught.getMessage()); + } + + public void onSuccess(Collection[] collections) { + int num = collections != null ? collections.length : 0; + + GWT.log("Received " + num + " user collections."); + + if (num == 0) { + return; + } + + updateGrid(collections); + } + } + ); + } + + + protected void clearGrid() { + ListGridRecord[] records = grid.getRecords(); + + for (ListGridRecord record: records) { + grid.removeData(record); + } + } + + + protected void updateGrid(Collection[] collections) { + clearGrid(); + + for (Collection c: collections) { + grid.addData(new CollectionRecord(c)); + } + } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/shared/model/CollectionRecord.java Tue Mar 29 13:49:04 2011 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/shared/model/CollectionRecord.java Tue Mar 29 13:53:24 2011 +0000 @@ -27,12 +27,12 @@ /** - * Returns the date of the last modification. + * Returns the date of the creation. * - * @return the last modification date. + * @return the creation time. */ - public Date getDate() { - return collection.getLastAccess(); + public Date getCreationTime() { + return collection.getCreationTime(); } @@ -42,7 +42,10 @@ * @return the name of the collection. */ public String getName() { - return collection.getName(); + String name = collection.getName(); + return name != null && name.length() > 0 + ? name + : collection.identifier(); } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/webapp/WEB-INF/web.xml Tue Mar 29 13:49:04 2011 +0000 +++ b/flys-client/src/main/webapp/WEB-INF/web.xml Tue Mar 29 13:53:24 2011 +0000 @@ -75,6 +75,16 @@ <servlet-name>add-artifact</servlet-name> <url-pattern>/flys/add-artifact</url-pattern> </servlet-mapping> + + <servlet> + <servlet-name>user-collections</servlet-name> + <servlet-class>de.intevation.flys.client.server.UserCollectionsServiceImpl</servlet-class> + </servlet> + + <servlet-mapping> + <servlet-name>user-collections</servlet-name> + <url-pattern>/flys/user-collections</url-pattern> + </servlet-mapping> <servlet> <servlet-name>ChartOutputService</servlet-name>