Mercurial > dive4elements > river
comparison flys-client/src/main/java/de/intevation/flys/client/client/ui/DatacageWindow.java @ 910:7f72239e56c8
#259 Use the LoadArtifactService to clone Artifacts and add them to the current Collection.
flys-client/trunk@2767 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Thu, 15 Sep 2011 16:27:07 +0000 |
parents | c0e13cf826d7 |
children | 4668357b255e |
comparison
equal
deleted
inserted
replaced
909:794d1af42987 | 910:7f72239e56c8 |
---|---|
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 |
6 import com.smartgwt.client.util.SC; | |
5 import com.smartgwt.client.widgets.Window; | 7 import com.smartgwt.client.widgets.Window; |
6 | 8 |
9 import de.intevation.flys.client.client.Config; | |
7 import de.intevation.flys.client.client.FLYSConstants; | 10 import de.intevation.flys.client.client.FLYSConstants; |
8 | 11 |
9 import de.intevation.flys.client.client.event.DatacageHandler; | 12 import de.intevation.flys.client.client.event.DatacageHandler; |
10 | 13 |
14 import de.intevation.flys.client.client.services.LoadArtifactService; | |
15 import de.intevation.flys.client.client.services.LoadArtifactServiceAsync; | |
16 | |
11 import de.intevation.flys.client.shared.model.Artifact; | 17 import de.intevation.flys.client.shared.model.Artifact; |
12 import de.intevation.flys.client.shared.model.ArtifactDescription; | 18 import de.intevation.flys.client.shared.model.ArtifactDescription; |
19 import de.intevation.flys.client.shared.model.Collection; | |
13 import de.intevation.flys.client.shared.model.Data; | 20 import de.intevation.flys.client.shared.model.Data; |
14 import de.intevation.flys.client.shared.model.DataItem; | 21 import de.intevation.flys.client.shared.model.DataItem; |
15 import de.intevation.flys.client.shared.model.DataList; | 22 import de.intevation.flys.client.shared.model.DataList; |
16 import de.intevation.flys.client.shared.model.ToLoad; | 23 import de.intevation.flys.client.shared.model.ToLoad; |
17 import de.intevation.flys.client.shared.model.User; | 24 import de.intevation.flys.client.shared.model.User; |
24 extends Window | 31 extends Window |
25 implements DatacageHandler | 32 implements DatacageHandler |
26 { | 33 { |
27 protected FLYSConstants messages = | 34 protected FLYSConstants messages = |
28 GWT.create(FLYSConstants.class); | 35 GWT.create(FLYSConstants.class); |
36 | |
37 protected LoadArtifactServiceAsync loadService = | |
38 GWT.create(LoadArtifactService.class); | |
29 | 39 |
30 protected CollectionView view; | 40 protected CollectionView view; |
31 | 41 |
32 public DatacageWindow( | 42 public DatacageWindow( |
33 Artifact artifact, | 43 Artifact artifact, |
58 | 68 |
59 @Override | 69 @Override |
60 public void toLoad(ToLoad toLoad) { | 70 public void toLoad(ToLoad toLoad) { |
61 destroy(); | 71 destroy(); |
62 List<Recommendation> recs = toLoad.toRecommendations(); | 72 List<Recommendation> recs = toLoad.toRecommendations(); |
63 view.loadRecommendedArtifacts( | 73 loadArtifacts(recs.toArray(new Recommendation[recs.size()])); |
64 recs.toArray(new Recommendation[recs.size()])); | |
65 } | 74 } |
66 | 75 |
67 | 76 |
68 protected String findRiver(Artifact artifact) { | 77 protected String findRiver(Artifact artifact) { |
69 ArtifactDescription adescr = artifact.getArtifactDescription(); | 78 ArtifactDescription adescr = artifact.getArtifactDescription(); |
84 } | 93 } |
85 } | 94 } |
86 | 95 |
87 return ""; | 96 return ""; |
88 } | 97 } |
98 | |
99 | |
100 protected void loadArtifacts(Recommendation[] recommendations) { | |
101 Config cfg = Config.getInstance(); | |
102 | |
103 final Collection collection = view.getCollection(); | |
104 final Artifact masterArtifact = view.getArtifact(); | |
105 final String serverUrl = cfg.getServerUrl(); | |
106 final String locale = cfg.getLocale(); | |
107 | |
108 for (final Recommendation recommendation: recommendations) { | |
109 // XXX: UGLY! If no reference artifact given use uuid of | |
110 // current artifact as reference. | |
111 if (recommendation.getMasterArtifact() == null) { | |
112 recommendation.setMasterArtifact(masterArtifact.getUuid()); | |
113 } | |
114 | |
115 final String factory = recommendation.getFactory(); | |
116 | |
117 GWT.log("Load new artifact with factory: " + factory); | |
118 | |
119 loadService.load( | |
120 collection, | |
121 recommendation, | |
122 factory, | |
123 serverUrl, | |
124 locale, | |
125 new AsyncCallback<Artifact>() { | |
126 public void onFailure(Throwable caught) { | |
127 SC.warn(caught.getMessage()); | |
128 } | |
129 | |
130 public void onSuccess(Artifact artifact) { | |
131 GWT.log("Created new artifact: " + artifact.getUuid()); | |
132 } | |
133 }); | |
134 } | |
135 } | |
89 } | 136 } |
90 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : | 137 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |