Mercurial > dive4elements > river
comparison flys-client/src/main/java/de/intevation/flys/client/client/FLYS.java @ 557:92c200887b20
#21 There might be just a single window for each project now. Users can't open a project twice.
flys-client/trunk@2083 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Wed, 08 Jun 2011 13:21:46 +0000 |
parents | 924da6695800 |
children | 347cf4a5a486 |
comparison
equal
deleted
inserted
replaced
556:046f43e1d305 | 557:92c200887b20 |
---|---|
1 package de.intevation.flys.client.client; | 1 package de.intevation.flys.client.client; |
2 | |
3 import java.util.ArrayList; | |
4 import java.util.List; | |
2 | 5 |
3 import com.google.gwt.core.client.EntryPoint; | 6 import com.google.gwt.core.client.EntryPoint; |
4 import com.google.gwt.core.client.GWT; | 7 import com.google.gwt.core.client.GWT; |
5 import com.google.gwt.user.client.rpc.AsyncCallback; | 8 import com.google.gwt.user.client.rpc.AsyncCallback; |
6 import com.google.gwt.user.client.ui.RootPanel; | 9 import com.google.gwt.user.client.ui.RootPanel; |
7 import com.google.gwt.xml.client.XMLParser; | 10 import com.google.gwt.xml.client.XMLParser; |
8 | 11 |
9 import com.smartgwt.client.util.SC; | 12 import com.smartgwt.client.util.SC; |
10 import com.smartgwt.client.widgets.layout.VLayout; | 13 import com.smartgwt.client.widgets.layout.VLayout; |
11 import com.smartgwt.client.widgets.layout.HLayout; | 14 import com.smartgwt.client.widgets.layout.HLayout; |
15 import com.smartgwt.client.widgets.events.CloseClickHandler; | |
16 import com.smartgwt.client.widgets.events.CloseClientEvent; | |
12 | 17 |
13 import de.intevation.flys.client.shared.model.Artifact; | 18 import de.intevation.flys.client.shared.model.Artifact; |
14 import de.intevation.flys.client.shared.model.Collection; | 19 import de.intevation.flys.client.shared.model.Collection; |
15 import de.intevation.flys.client.shared.model.CollectionItem; | 20 import de.intevation.flys.client.shared.model.CollectionItem; |
16 import de.intevation.flys.client.shared.model.River; | 21 import de.intevation.flys.client.shared.model.River; |
83 protected User currentUser; | 88 protected User currentUser; |
84 | 89 |
85 /** The list of rivers supported by the server.*/ | 90 /** The list of rivers supported by the server.*/ |
86 protected River[] rivers; | 91 protected River[] rivers; |
87 | 92 |
93 /** This list is used to track the opened projects.*/ | |
94 protected List<String> openProjects; | |
95 | |
88 | 96 |
89 /** | 97 /** |
90 * This is the entry point method. | 98 * This is the entry point method. |
91 */ | 99 */ |
92 public void onModuleLoad() { | 100 public void onModuleLoad() { |
101 openProjects = new ArrayList<String>(); | |
93 | 102 |
94 VLayout vertical = new VLayout(); | 103 VLayout vertical = new VLayout(); |
95 vertical.setLayoutMargin(1); | 104 vertical.setLayoutMargin(1); |
96 vertical.setWidth100(); | 105 vertical.setWidth100(); |
97 vertical.setHeight100(); | 106 vertical.setHeight100(); |
229 | 238 |
230 return; | 239 return; |
231 } | 240 } |
232 | 241 |
233 CollectionView view = new CollectionView(this); | 242 CollectionView view = new CollectionView(this); |
234 workspace.addView(view); | 243 workspace.addView("new-project", view); |
235 | 244 |
236 view.addCollectionChangeHandler(getProjectList()); | 245 view.addCollectionChangeHandler(getProjectList()); |
237 } | 246 } |
238 | 247 |
239 | 248 |
240 public void openProject(String collectionID) { | 249 protected void lockProject(String uuid) { |
250 if (isProjectLocked(uuid)) { | |
251 return; | |
252 } | |
253 | |
254 openProjects.add(uuid); | |
255 } | |
256 | |
257 | |
258 protected void unlockProject(String uuid) { | |
259 openProjects.remove(uuid); | |
260 } | |
261 | |
262 | |
263 protected boolean isProjectLocked(String uuid) { | |
264 return openProjects.contains(uuid); | |
265 } | |
266 | |
267 | |
268 public void openProject(final String collectionID) { | |
241 if (collectionID == null) { | 269 if (collectionID == null) { |
242 return; | 270 return; |
243 } | 271 } |
272 | |
273 if (isProjectLocked(collectionID)) { | |
274 workspace.bringUp(collectionID); | |
275 return; | |
276 } | |
277 | |
278 lockProject(collectionID); | |
244 | 279 |
245 GWT.log("Open existing project: " + collectionID); | 280 GWT.log("Open existing project: " + collectionID); |
246 | 281 |
247 Config config = Config.getInstance(); | 282 Config config = Config.getInstance(); |
248 final String url = config.getServerUrl(); | 283 final String url = config.getServerUrl(); |
268 locale, | 303 locale, |
269 item.identifier(), | 304 item.identifier(), |
270 item.hash(), | 305 item.hash(), |
271 new AsyncCallback<Artifact>() { | 306 new AsyncCallback<Artifact>() { |
272 public void onFailure(Throwable caught) { | 307 public void onFailure(Throwable caught) { |
308 unlockProject(collectionID); | |
273 SC.warn(MSG.getString(caught.getMessage())); | 309 SC.warn(MSG.getString(caught.getMessage())); |
274 } | 310 } |
275 | 311 |
276 public void onSuccess(Artifact artifact) { | 312 public void onSuccess(Artifact artifact) { |
277 CollectionView view = new CollectionView( | 313 CollectionView view = new CollectionView( |
278 FLYS.this, collection, artifact); | 314 FLYS.this, collection, artifact); |
279 | 315 |
280 view.addCollectionChangeHandler( | 316 view.addCollectionChangeHandler( |
281 getProjectList()); | 317 getProjectList()); |
282 | 318 view.addCloseClickHandler( |
283 workspace.addView(view); | 319 new CloseCollectionViewHandler( |
320 FLYS.this, collectionID)); | |
321 | |
322 workspace.addView(collectionID, view); | |
284 } | 323 } |
285 }); | 324 }); |
286 | 325 |
287 } | 326 } |
288 }); | 327 }); |
307 public void onSuccess(Artifact artifact) { | 346 public void onSuccess(Artifact artifact) { |
308 GWT.log("Successfully created a new artifact."); | 347 GWT.log("Successfully created a new artifact."); |
309 } | 348 } |
310 }); | 349 }); |
311 } | 350 } |
351 | |
352 | |
353 | |
354 /** | |
355 * This CloseClickHandler is used to remove lock on a specific Collection so | |
356 * that is might be opened again. | |
357 */ | |
358 private class CloseCollectionViewHandler implements CloseClickHandler { | |
359 protected FLYS flys; | |
360 protected String uuid; | |
361 | |
362 public CloseCollectionViewHandler(FLYS flys, String uuid) { | |
363 this.flys = flys; | |
364 this.uuid = uuid; | |
365 } | |
366 | |
367 public void onCloseClick(CloseClientEvent event) { | |
368 flys.unlockProject(uuid); | |
369 workspace.removeProject(uuid); | |
370 } | |
371 } | |
312 } | 372 } |
313 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : | 373 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |