Mercurial > dive4elements > river
changeset 226:a13382876e5d
The project list is sorted now.
flys-client/trunk@1671 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Tue, 12 Apr 2011 13:11:46 +0000 |
parents | 9040663aee01 |
children | 7f7f6d2c4b2c |
files | flys-client/ChangeLog 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 |
diffstat | 4 files changed, 116 insertions(+), 133 deletions(-) [+] |
line wrap: on
line diff
--- a/flys-client/ChangeLog Tue Apr 12 11:01:09 2011 +0000 +++ b/flys-client/ChangeLog Tue Apr 12 13:11:46 2011 +0000 @@ -1,3 +1,17 @@ +2011-04-12 Ingo Weinzierl <ingo@intevation.de> + + * src/main/java/de/intevation/flys/client/shared/model/CollectionRecord.java: + This record class uses the default mechanism to store/load values - + it uses the setAttribute() and getAttribute() methods now. + + * src/main/java/de/intevation/flys/client/client/ui/ProjectList.java: The + list is sorted based on the project's creation time now. + + * src/main/java/de/intevation/flys/client/client/ui/CollectionGrid.java: + Removed. The collection grid is no longer used, because the fields are + created by using default mechanisms (setting the field type, using cell + formatter). + 2011-04-12 Ingo Weinzierl <ingo@intevation.de> * src/main/java/de/intevation/flys/client/client/FLYS.java:
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/CollectionGrid.java Tue Apr 12 11:01:09 2011 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,121 +0,0 @@ -package de.intevation.flys.client.client.ui; - -import java.util.Date; - -import com.google.gwt.core.client.GWT; -import com.google.gwt.i18n.client.DateTimeFormat; - -import com.smartgwt.client.widgets.Canvas; -import com.smartgwt.client.widgets.IButton; -import com.smartgwt.client.widgets.Label; -import com.smartgwt.client.widgets.grid.ListGrid; -import com.smartgwt.client.widgets.grid.ListGridRecord; - -import de.intevation.flys.client.shared.model.CollectionRecord; - -import de.intevation.flys.client.client.FLYSConstants; - - -/** - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public class CollectionGrid extends ListGrid { - - /** The message class that provides i18n strings.*/ - FLYSConstants messages = GWT.create(FLYSConstants.class); - - /** - * The default constructor that creates a new ListGrid item. - * - * @param collection The artifact collection. - */ - public CollectionGrid() { - } - - @Override - protected Canvas createRecordComponent( - final ListGridRecord record, Integer col) - { - String field = getFieldName(col); - - if (field == null) return null; - if (field.equals("date")) return createDateField(record); - else if (field.equals("name")) return createNameField(record); - else if (field.equals("publish")) return createPublishField(record); - else if (field.equals("delete")) return createDeleteField(record); - - return null; - } - - - /** - * This method creates the date field for the collection grid. - * - * @param record The record to be displayed. - */ - protected Canvas createDateField(ListGridRecord record) { - CollectionRecord rec = (CollectionRecord) record; - - 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; - } - - - /** - * This method creates the name field for the collection grid. - * - * @param record The record to be displayed. - */ - protected Canvas createNameField(ListGridRecord record) { - CollectionRecord rec = (CollectionRecord) record; - - 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; - } - - - /** - * This method creates the field for the collection grid that provides a - * button to publish the collection. - * - * @param record The record to be displayed. - */ - protected Canvas createPublishField(ListGridRecord record) { - IButton button = new IButton(); - button.setHeight(15); - button.setTitle("PUB"); - return button; - } - - - /** - * This method creates the field for the collection grid that provides a - * button to delete the collection. - * - * @param record The record to be displayed. - */ - protected Canvas createDeleteField(ListGridRecord record) { - IButton button = new IButton(); - button.setHeight(15); - button.setTitle("DEL"); - return button; - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/ProjectList.java Tue Apr 12 11:01:09 2011 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/ProjectList.java Tue Apr 12 13:11:46 2011 +0000 @@ -1,11 +1,18 @@ package de.intevation.flys.client.client.ui; +import java.util.Date; + import com.google.gwt.core.client.GWT; +import com.google.gwt.i18n.client.DateTimeFormat; import com.google.gwt.user.client.rpc.AsyncCallback; +import com.smartgwt.client.types.Alignment; +import com.smartgwt.client.types.ListGridFieldType; +import com.smartgwt.client.types.SortDirection; import com.smartgwt.client.util.SC; import com.smartgwt.client.widgets.Canvas; import com.smartgwt.client.widgets.Label; +import com.smartgwt.client.widgets.grid.CellFormatter; import com.smartgwt.client.widgets.grid.ListGrid; import com.smartgwt.client.widgets.grid.ListGridField; import com.smartgwt.client.widgets.grid.ListGridRecord; @@ -66,7 +73,7 @@ this.flys = flys; this.user = user; - grid = new CollectionGrid(); + grid = new ListGrid(); initGrid(); init(); @@ -83,12 +90,11 @@ grid.setShowHeader(false); grid.setWidth100(); grid.setHeight100(); + grid.setSortDirection(SortDirection.DESCENDING); + grid.setSortField(0); - ListGridField date = new ListGridField("date", "date"); - ListGridField name = new ListGridField("name", "name"); - - date.setWidth(100); - name.setWidth(195); + ListGridField date = buildDateField(); + ListGridField name = buildNameField(); grid.setFields(date, name); @@ -226,5 +232,60 @@ grid.addData(new CollectionRecord(c)); } } + + + /** + * Builds the field in the grid that displays the creation time of a + * project. + * + * @return the grid field. + */ + protected ListGridField buildDateField() { + ListGridField date = new ListGridField("creationTime", "creationTime"); + date.setType(ListGridFieldType.DATE); + + date.setCellFormatter(new CellFormatter() { + public String format(Object value, ListGridRecord rec, int r, int c) { + if (value == null) { + return null; + } + + DateTimeFormat dtf = DateTimeFormat.getFormat( + messages.datetime_format()); + + return dtf.format((Date)value); + } + }); + + date.setWidth(105); + date.setAlign(Alignment.LEFT); + + return date; + } + + + /** + * Builds the field in the grid that displays the name of a project. + * + * @return the grid field. + */ + protected ListGridField buildNameField() { + ListGridField name = new ListGridField("name", "name"); + name.setType(ListGridFieldType.TEXT); + + name.setCellFormatter(new CellFormatter() { + public String format(Object value, ListGridRecord record, int row, int col) { + String n = (String) value; + int len = n.length(); + int sec = len - 15; + return n.substring(0, 14) + "..." + n.substring(sec, len-1); + } + }); + + name.setWidth(195); + name.setAlign(Alignment.LEFT); + + return name; + } } // 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 Apr 12 11:01:09 2011 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/shared/model/CollectionRecord.java Tue Apr 12 13:11:46 2011 +0000 @@ -23,6 +23,23 @@ */ public CollectionRecord(Collection collection) { this.collection = collection; + + setCreationTime(collection.getCreationTime()); + + String name = collection.getName(); + setName(name != null && name.length() > 0 + ? name + : collection.identifier()); + } + + + /** + * Sets the creation time. + * + * @param creationTime The creation time. + */ + public void setCreationTime(Date creationTime) { + setAttribute("creationTime", creationTime); } @@ -32,7 +49,7 @@ * @return the creation time. */ public Date getCreationTime() { - return collection.getCreationTime(); + return getAttributeAsDate("creationTime"); } @@ -41,14 +58,26 @@ * * @return the name of the collection. */ - public String getName() { - String name = collection.getName(); - return name != null && name.length() > 0 - ? name - : collection.identifier(); + public void setName(String name) { + setAttribute("name", name); } + /** + * Returns the name of the collection or the uuid if no name is specified. + * + * @return the name of the collection. + */ + public String getName() { + return getAttributeAsString("name"); + } + + + /** + * Returns the collection objects itself. + * + * @return the collection object. + */ public Collection getCollection() { return collection; }