Mercurial > dive4elements > river
comparison flys-client/src/main/java/de/intevation/flys/client/client/ui/ProjectList.java @ 3380:f6519c699fca
Respect factory of cloned artifact when cloning.
flys-client/trunk@5118 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Felix Wolfsteller <felix.wolfsteller@intevation.de> |
---|---|
date | Tue, 24 Jul 2012 11:49:12 +0000 |
parents | caae9d686372 |
children | 6b5920c7ea6e |
comparison
equal
deleted
inserted
replaced
3379:0de61fc9d281 | 3380:f6519c699fca |
---|---|
43 import com.smartgwt.client.widgets.menu.events.MenuItemClickEvent; | 43 import com.smartgwt.client.widgets.menu.events.MenuItemClickEvent; |
44 import com.smartgwt.client.widgets.menu.events.ClickHandler; | 44 import com.smartgwt.client.widgets.menu.events.ClickHandler; |
45 import com.smartgwt.client.types.VerticalAlignment; | 45 import com.smartgwt.client.types.VerticalAlignment; |
46 | 46 |
47 import de.intevation.flys.client.shared.model.Collection; | 47 import de.intevation.flys.client.shared.model.Collection; |
48 import de.intevation.flys.client.shared.model.CollectionItem; | |
48 import de.intevation.flys.client.shared.model.CollectionRecord; | 49 import de.intevation.flys.client.shared.model.CollectionRecord; |
49 import de.intevation.flys.client.shared.model.User; | 50 import de.intevation.flys.client.shared.model.User; |
50 import de.intevation.flys.client.shared.model.Artifact; | 51 import de.intevation.flys.client.shared.model.Artifact; |
52 import de.intevation.flys.client.shared.model.ChartArtifact; | |
53 import de.intevation.flys.client.shared.model.FixAnalysisArtifact; | |
54 import de.intevation.flys.client.shared.model.MapArtifact; | |
55 import de.intevation.flys.client.shared.model.MINFOArtifact; | |
56 import de.intevation.flys.client.shared.model.WINFOArtifact; | |
51 import de.intevation.flys.client.shared.model.Recommendation; | 57 import de.intevation.flys.client.shared.model.Recommendation; |
52 | 58 |
53 import de.intevation.flys.client.client.event.FilterHandler; | 59 import de.intevation.flys.client.client.event.FilterHandler; |
54 import de.intevation.flys.client.client.event.StringFilterEvent; | 60 import de.intevation.flys.client.client.event.StringFilterEvent; |
55 import de.intevation.flys.client.client.event.RangeFilterEvent; | 61 import de.intevation.flys.client.client.event.RangeFilterEvent; |
57 import de.intevation.flys.client.client.Config; | 63 import de.intevation.flys.client.client.Config; |
58 import de.intevation.flys.client.client.FLYS; | 64 import de.intevation.flys.client.client.FLYS; |
59 import de.intevation.flys.client.client.FLYSConstants; | 65 import de.intevation.flys.client.client.FLYSConstants; |
60 import de.intevation.flys.client.client.event.CollectionChangeEvent; | 66 import de.intevation.flys.client.client.event.CollectionChangeEvent; |
61 import de.intevation.flys.client.client.event.CollectionChangeHandler; | 67 import de.intevation.flys.client.client.event.CollectionChangeHandler; |
68 import de.intevation.flys.client.client.services.AddArtifactService; | |
69 import de.intevation.flys.client.client.services.AddArtifactServiceAsync; | |
62 import de.intevation.flys.client.client.services.ArtifactService; | 70 import de.intevation.flys.client.client.services.ArtifactService; |
63 import de.intevation.flys.client.client.services.ArtifactServiceAsync; | 71 import de.intevation.flys.client.client.services.ArtifactServiceAsync; |
72 import de.intevation.flys.client.client.services.CreateCollectionService; | |
73 import de.intevation.flys.client.client.services.CreateCollectionServiceAsync; | |
64 import de.intevation.flys.client.client.services.DeleteCollectionService; | 74 import de.intevation.flys.client.client.services.DeleteCollectionService; |
65 import de.intevation.flys.client.client.services.DeleteCollectionServiceAsync; | 75 import de.intevation.flys.client.client.services.DeleteCollectionServiceAsync; |
76 import de.intevation.flys.client.client.services.DescribeCollectionService; | |
77 import de.intevation.flys.client.client.services.DescribeCollectionServiceAsync; | |
78 import de.intevation.flys.client.client.services.GetArtifactService; | |
79 import de.intevation.flys.client.client.services.GetArtifactServiceAsync; | |
80 import de.intevation.flys.client.client.services.DescribeCollectionServiceAsync; | |
66 import de.intevation.flys.client.client.services.SetCollectionNameService; | 81 import de.intevation.flys.client.client.services.SetCollectionNameService; |
67 import de.intevation.flys.client.client.services.SetCollectionNameServiceAsync; | 82 import de.intevation.flys.client.client.services.SetCollectionNameServiceAsync; |
68 import de.intevation.flys.client.client.services.SetCollectionTTLService; | 83 import de.intevation.flys.client.client.services.SetCollectionTTLService; |
69 import de.intevation.flys.client.client.services.SetCollectionTTLServiceAsync; | 84 import de.intevation.flys.client.client.services.SetCollectionTTLServiceAsync; |
70 import de.intevation.flys.client.client.services.UserCollectionsService; | 85 import de.intevation.flys.client.client.services.UserCollectionsService; |
71 import de.intevation.flys.client.client.services.UserCollectionsServiceAsync; | 86 import de.intevation.flys.client.client.services.UserCollectionsServiceAsync; |
72 import de.intevation.flys.client.client.services.DescribeCollectionService; | |
73 import de.intevation.flys.client.client.services.DescribeCollectionServiceAsync; | |
74 import de.intevation.flys.client.client.services.AddArtifactService; | |
75 import de.intevation.flys.client.client.services.AddArtifactServiceAsync; | |
76 import de.intevation.flys.client.client.services.CreateCollectionService; | |
77 import de.intevation.flys.client.client.services.CreateCollectionServiceAsync; | |
78 | 87 |
79 | 88 |
80 /** | 89 /** |
81 * The project list shows a list of projects of a specific user. | 90 * The project list shows a list of projects of a specific user. |
82 * | 91 * |
137 | 146 |
138 /** The AddArtifactService used to add an artifact to a collection. */ | 147 /** The AddArtifactService used to add an artifact to a collection. */ |
139 protected AddArtifactServiceAsync addArtifactService = | 148 protected AddArtifactServiceAsync addArtifactService = |
140 GWT.create(AddArtifactService.class); | 149 GWT.create(AddArtifactService.class); |
141 | 150 |
151 /** The GetArtifactService used to open an existing collection. */ | |
152 protected GetArtifactServiceAsync getArtifactService = | |
153 GWT.create(GetArtifactService.class); | |
154 | |
142 /** A pointer to the FLYS instance.*/ | 155 /** A pointer to the FLYS instance.*/ |
143 protected FLYS flys; | 156 protected FLYS flys; |
144 | 157 |
145 /** The user whose projects should be displayed.*/ | 158 /** The user whose projects should be displayed.*/ |
146 protected User user; | 159 protected User user; |
154 /** The collections visible in the grid.*/ | 167 /** The collections visible in the grid.*/ |
155 protected List<Collection> filteredCollections; | 168 protected List<Collection> filteredCollections; |
156 | 169 |
157 /** The collection to clone*/ | 170 /** The collection to clone*/ |
158 protected Collection cloneCollection; | 171 protected Collection cloneCollection; |
172 | |
173 /** The message class that provides i18n strings.*/ | |
174 protected FLYSConstants MSG = GWT.create(FLYSConstants.class); | |
175 | |
159 | 176 |
160 /** | 177 /** |
161 * The default constructor that creates a new ProjectList for a specific | 178 * The default constructor that creates a new ProjectList for a specific |
162 * user. | 179 * user. |
163 * | 180 * |
202 | 219 |
203 grid.setFields(date, name, fav); | 220 grid.setFields(date, name, fav); |
204 | 221 |
205 grid.addHeaderDoubleClickHandler(new HeaderDoubleClickHandler() { | 222 grid.addHeaderDoubleClickHandler(new HeaderDoubleClickHandler() { |
206 public void onHeaderDoubleClick(HeaderDoubleClickEvent event) { | 223 public void onHeaderDoubleClick(HeaderDoubleClickEvent event) { |
207 // cancel the event. | 224 // Cancel the event. |
208 return; | 225 return; |
209 } | 226 } |
210 }); | 227 }); |
211 | 228 |
212 // add a handler to set / unset the favorite state of a project | 229 // Add a handler to set / unset the favorite state of a project. |
213 grid.addCellClickHandler(new CellClickHandler() { | 230 grid.addCellClickHandler(new CellClickHandler() { |
214 public void onCellClick(CellClickEvent event) { | 231 public void onCellClick(CellClickEvent event) { |
215 if (event.getColNum() != 2) { | 232 if (event.getColNum() != 2) { |
216 return; | 233 return; |
217 } | 234 } |
222 c.setTTL(c.getTTL() == 0 ? -1 : 0); | 239 c.setTTL(c.getTTL() == 0 ? -1 : 0); |
223 updateCollectionTTL(c); | 240 updateCollectionTTL(c); |
224 } | 241 } |
225 }); | 242 }); |
226 | 243 |
227 // add a handler to open a project | 244 // Add a handler to open a project. |
228 grid.addCellDoubleClickHandler(new CellDoubleClickHandler() { | 245 grid.addCellDoubleClickHandler(new CellDoubleClickHandler() { |
229 public void onCellDoubleClick(CellDoubleClickEvent e) { | 246 public void onCellDoubleClick(CellDoubleClickEvent e) { |
230 CollectionRecord record = (CollectionRecord) e.getRecord(); | 247 CollectionRecord record = (CollectionRecord) e.getRecord(); |
231 String uuid = record != null | 248 String uuid = record != null |
232 ? record.getCollection().identifier() | 249 ? record.getCollection().identifier() |
233 : ""; | 250 : ""; |
234 getFlys().openProject(uuid); | 251 getFlys().openProject(uuid); |
235 } | 252 } |
236 }); | 253 }); |
237 | 254 |
238 // add a handler to open a context menu | 255 // Add a handler to open a context menu. |
239 grid.addRowContextClickHandler(new RowContextClickHandler() { | 256 grid.addRowContextClickHandler(new RowContextClickHandler() { |
240 public void onRowContextClick(RowContextClickEvent event) { | 257 public void onRowContextClick(RowContextClickEvent event) { |
241 CollectionRecord record = (CollectionRecord) event.getRecord(); | 258 CollectionRecord record = (CollectionRecord) event.getRecord(); |
242 | 259 |
243 Menu menu = createContextMenu(record); | 260 Menu menu = createContextMenu(record); |
563 } | 580 } |
564 } | 581 } |
565 ); | 582 ); |
566 } | 583 } |
567 | 584 |
585 | |
568 /** | 586 /** |
569 * Delete all entries in the ListGrid. | 587 * Delete all entries in the ListGrid. |
570 */ | 588 */ |
571 protected void clearGrid() { | 589 protected void clearGrid() { |
572 ListGridRecord[] records = grid.getRecords(); | 590 ListGridRecord[] records = grid.getRecords(); |
610 | 628 |
611 for (Collection c: filteredCollections) { | 629 for (Collection c: filteredCollections) { |
612 grid.addData(new CollectionRecord(c)); | 630 grid.addData(new CollectionRecord(c)); |
613 } | 631 } |
614 } | 632 } |
633 | |
615 | 634 |
616 /** | 635 /** |
617 * Filter for the user collections. | 636 * Filter for the user collections. |
618 * | 637 * |
619 * @param search String to search for in collection names. | 638 * @param search String to search for in collection names. |
754 | 773 |
755 | 774 |
756 public void onSuccess(Collection newCollection) { | 775 public void onSuccess(Collection newCollection) { |
757 GWT.log("Successfully DESCRIBED collection."); | 776 GWT.log("Successfully DESCRIBED collection."); |
758 String uuid = getMasterArtifact(newCollection); | 777 String uuid = getMasterArtifact(newCollection); |
759 cloneArtifact(uuid); | 778 cloneArtifact(uuid, newCollection); |
760 } | 779 } |
761 } | 780 } |
762 ); | 781 ); |
763 } | 782 } |
764 | 783 |
765 | 784 |
785 /** Get master artifacts UUID of a collection. */ | |
766 protected String getMasterArtifact(Collection newCollection) { | 786 protected String getMasterArtifact(Collection newCollection) { |
767 String uuid = newCollection.getItem(0).identifier(); | 787 String uuid = newCollection.getItem(0).identifier(); |
768 // The master artifact uuid. | 788 // The master artifact uuid. |
769 return uuid; | 789 return uuid; |
770 } | 790 } |
771 | 791 |
772 | 792 |
773 protected void cloneArtifact(String uuid) { | 793 /** Clone artifact/create collection, using the refArtifacts factory. */ |
774 Config config = Config.getInstance(); | 794 protected void cloneArtifact(String uuid, Artifact refArtifact, |
775 final String locale = config.getLocale(); | 795 final String locale) { |
776 | |
777 Recommendation recommendation = new Recommendation( | 796 Recommendation recommendation = new Recommendation( |
778 "winfo", | 797 refArtifact.getName(), |
779 null, | 798 null, |
780 uuid, | 799 uuid, |
781 null); | 800 null); |
782 | 801 |
783 String factory = recommendation.getFactory(); | 802 String factory = recommendation.getFactory(); |
796 } | 815 } |
797 ); | 816 ); |
798 } | 817 } |
799 | 818 |
800 | 819 |
820 /** | |
821 * Clone a project (collection). | |
822 */ | |
823 protected void cloneArtifact(final String uuid, Collection newCollection) { | |
824 Config config = Config.getInstance(); | |
825 final String locale = config.getLocale(); | |
826 | |
827 // Find out which factory to use for cloning. | |
828 CollectionItem master = newCollection.getItem(0); | |
829 getArtifactService.getArtifact( | |
830 locale, | |
831 master.identifier(), | |
832 master.hash(), | |
833 new AsyncCallback<Artifact>() { | |
834 public void onFailure(Throwable caught) { | |
835 SC.warn(MSG.getString(caught.getMessage())); | |
836 } | |
837 | |
838 public void onSuccess(Artifact artifact) { | |
839 cloneArtifact(uuid, artifact, locale); | |
840 } | |
841 }); | |
842 } | |
843 | |
844 | |
801 protected void createCollection(final Artifact artifact) { | 845 protected void createCollection(final Artifact artifact) { |
802 Config config = Config.getInstance(); | 846 Config config = Config.getInstance(); |
803 final String locale = config.getLocale(); | 847 final String locale = config.getLocale(); |
804 final String ownerid = user.identifier(); | 848 final String ownerid = user.identifier(); |
805 | 849 |