Mercurial > dive4elements > river
comparison flys-client/src/main/java/de/intevation/flys/client/client/ui/ProjectList.java @ 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 | 17815a7354bc |
children | b92281182c6b |
comparison
equal
deleted
inserted
replaced
96:261a2ee7d9bb | 97:0bec0112c8b3 |
---|---|
1 package de.intevation.flys.client.client.ui; | 1 package de.intevation.flys.client.client.ui; |
2 | 2 |
3 import com.google.gwt.core.client.GWT; | 3 import com.google.gwt.core.client.GWT; |
4 import com.google.gwt.user.client.rpc.AsyncCallback; | |
4 | 5 |
5 import com.smartgwt.client.widgets.Canvas; | 6 import com.smartgwt.client.widgets.Canvas; |
6 import com.smartgwt.client.widgets.Label; | 7 import com.smartgwt.client.widgets.Label; |
7 import com.smartgwt.client.widgets.grid.ListGrid; | 8 import com.smartgwt.client.widgets.grid.ListGrid; |
8 import com.smartgwt.client.widgets.grid.ListGridField; | 9 import com.smartgwt.client.widgets.grid.ListGridField; |
10 import com.smartgwt.client.widgets.grid.ListGridRecord; | |
9 import com.smartgwt.client.widgets.layout.VLayout; | 11 import com.smartgwt.client.widgets.layout.VLayout; |
10 import com.smartgwt.client.types.VerticalAlignment; | 12 import com.smartgwt.client.types.VerticalAlignment; |
11 | 13 |
12 import de.intevation.flys.client.shared.model.Collection; | 14 import de.intevation.flys.client.shared.model.Collection; |
13 import de.intevation.flys.client.shared.model.CollectionRecord; | 15 import de.intevation.flys.client.shared.model.CollectionRecord; |
14 import de.intevation.flys.client.shared.model.DefaultCollection; | 16 import de.intevation.flys.client.shared.model.User; |
15 | 17 |
18 import de.intevation.flys.client.client.Config; | |
16 import de.intevation.flys.client.client.FLYSMessages; | 19 import de.intevation.flys.client.client.FLYSMessages; |
17 import de.intevation.flys.client.shared.model.User; | 20 import de.intevation.flys.client.client.event.CollectionChangeEvent; |
21 import de.intevation.flys.client.client.event.CollectionChangeHandler; | |
22 import de.intevation.flys.client.client.services.UserCollectionsService; | |
23 import de.intevation.flys.client.client.services.UserCollectionsServiceAsync; | |
18 | 24 |
19 | 25 |
20 /** | 26 /** |
21 * The project list shows a list of projects of a specific user. | 27 * The project list shows a list of projects of a specific user. |
22 * | 28 * |
23 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> | 29 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> |
24 */ | 30 */ |
25 public class ProjectList extends VLayout { | 31 public class ProjectList |
26 | 32 extends VLayout |
33 implements CollectionChangeHandler | |
34 { | |
27 /** The interface that provides i18n messages. */ | 35 /** The interface that provides i18n messages. */ |
28 private FLYSMessages messages = GWT.create(FLYSMessages.class); | 36 private FLYSMessages messages = GWT.create(FLYSMessages.class); |
37 | |
38 /** The UserService used to retrieve information about the current user. */ | |
39 protected UserCollectionsServiceAsync userCollectionsService = | |
40 GWT.create(UserCollectionsService.class); | |
29 | 41 |
30 /** The user whose projects should be displayed.*/ | 42 /** The user whose projects should be displayed.*/ |
31 protected User user; | 43 protected User user; |
32 | 44 |
33 /** The grid that contains the project rows.*/ | 45 /** The grid that contains the project rows.*/ |
42 public ProjectList(User user) { | 54 public ProjectList(User user) { |
43 this.user = user; | 55 this.user = user; |
44 | 56 |
45 grid = new CollectionGrid(); | 57 grid = new CollectionGrid(); |
46 initGrid(); | 58 initGrid(); |
59 init(); | |
47 | 60 |
48 // TODO Remove the following code block after a service to fetch the | 61 updateUserCollections(); |
49 // user collections has been implemented! Instead of these static lines, | |
50 // a callback mechanism should be implemented that updates this widget | |
51 // when the current user changes. | |
52 Collection c1 = new DefaultCollection("uu-1"); | |
53 Collection c2 = new DefaultCollection("uu-2"); | |
54 CollectionRecord rec1 = new CollectionRecord(c1); | |
55 CollectionRecord rec2 = new CollectionRecord(c2); | |
56 grid.addData(rec1); | |
57 grid.addData(rec2); | |
58 | |
59 init(); | |
60 } | 62 } |
61 | 63 |
62 | 64 |
63 protected void initGrid() { | 65 protected void initGrid() { |
64 grid.setEmptyMessage(messages.no_projects()); | 66 grid.setEmptyMessage(messages.no_projects()); |
66 grid.setShowRecordComponents(true); | 68 grid.setShowRecordComponents(true); |
67 grid.setShowRecordComponentsByCell(true); | 69 grid.setShowRecordComponentsByCell(true); |
68 grid.setCanRemoveRecords(false); | 70 grid.setCanRemoveRecords(false); |
69 grid.setShowHeader(false); | 71 grid.setShowHeader(false); |
70 grid.setWidth100(); | 72 grid.setWidth100(); |
73 grid.setHeight100(); | |
71 | 74 |
72 ListGridField date = new ListGridField("date", "date"); | 75 ListGridField date = new ListGridField("date", "date"); |
73 ListGridField name = new ListGridField("name", "name"); | 76 ListGridField name = new ListGridField("name", "name"); |
74 ListGridField pub = new ListGridField("publish", "publish"); | |
75 ListGridField del = new ListGridField("delete", "delete"); | |
76 | 77 |
77 date.setWidth(70); | 78 date.setWidth(100); |
78 name.setWidth(155); | 79 name.setWidth(195); |
79 pub.setWidth(35); | |
80 del.setWidth(35); | |
81 | 80 |
82 grid.setFields(date, name, pub, del); | 81 grid.setFields(date, name); |
83 } | 82 } |
84 | 83 |
85 | 84 |
86 /** | 85 /** |
87 * The init() method handles the layout stuff for this widget. | 86 * The init() method handles the layout stuff for this widget. |
112 gridWrapper.addChild(grid); | 111 gridWrapper.addChild(grid); |
113 | 112 |
114 addMember(titleWrapper); | 113 addMember(titleWrapper); |
115 addMember(gridWrapper); | 114 addMember(gridWrapper); |
116 } | 115 } |
116 | |
117 | |
118 public void onCollectionChange(CollectionChangeEvent event) { | |
119 GWT.log("ProjectList.onCollectionChange"); | |
120 | |
121 updateUserCollections(); | |
122 } | |
123 | |
124 | |
125 protected void updateUserCollections() { | |
126 Config config = Config.getInstance(); | |
127 String url = config.getServerUrl(); | |
128 | |
129 userCollectionsService.getUserCollections(url, user.identifier(), | |
130 new AsyncCallback<Collection[]>() { | |
131 public void onFailure(Throwable caught) { | |
132 GWT.log("Could not recieve a list of user collections."); | |
133 GWT.log(caught.getMessage()); | |
134 } | |
135 | |
136 public void onSuccess(Collection[] collections) { | |
137 int num = collections != null ? collections.length : 0; | |
138 | |
139 GWT.log("Received " + num + " user collections."); | |
140 | |
141 if (num == 0) { | |
142 return; | |
143 } | |
144 | |
145 updateGrid(collections); | |
146 } | |
147 } | |
148 ); | |
149 } | |
150 | |
151 | |
152 protected void clearGrid() { | |
153 ListGridRecord[] records = grid.getRecords(); | |
154 | |
155 for (ListGridRecord record: records) { | |
156 grid.removeData(record); | |
157 } | |
158 } | |
159 | |
160 | |
161 protected void updateGrid(Collection[] collections) { | |
162 clearGrid(); | |
163 | |
164 for (Collection c: collections) { | |
165 grid.addData(new CollectionRecord(c)); | |
166 } | |
167 } | |
117 } | 168 } |
118 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : | 169 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |