Mercurial > dive4elements > river
changeset 1321:cfbfaadf4b6f
Remove Artifacts not needed anymore when reparameterizing w-diffs.
flys-client/trunk@2962 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Felix Wolfsteller <felix.wolfsteller@intevation.de> |
---|---|
date | Thu, 13 Oct 2011 12:34:46 +0000 |
parents | 5733c05ce24c |
children | e2749cc3b7ad |
files | flys-client/ChangeLog flys-client/src/main/java/de/intevation/flys/client/client/ui/DatacageTwinPanel.java |
diffstat | 2 files changed, 112 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- a/flys-client/ChangeLog Thu Oct 13 12:30:08 2011 +0000 +++ b/flys-client/ChangeLog Thu Oct 13 12:34:46 2011 +0000 @@ -1,3 +1,15 @@ +2011-10-13 Felix Wolfsteller <felix.wolfsteller@intevation.de> + + In W-Diff selection GUI, track which items have been removed from the + listgrid, remove corresponding artifacts from collection if they are + not needed anymore using the new RemoveArtifactService. + + * src/main/java/de/intevation/flys/client/client/ui/DatacageTwinPanel.java: + Track removed items from ListGrid until clicking on "proceed". Then, + check whether artifacts removed from the list are still needed to + calculate other difference (which are still in the ListGrid), remove + them otherwise. + 2011-10-13 Felix Wolfsteller <felix.wolfsteller@intevation.de> Added helper in use of new RemoveArtifactService.
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/DatacageTwinPanel.java Thu Oct 13 12:30:08 2011 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/DatacageTwinPanel.java Thu Oct 13 12:34:46 2011 +0000 @@ -8,16 +8,20 @@ import com.google.gwt.core.client.GWT; import com.google.gwt.user.client.rpc.AsyncCallback; +import com.smartgwt.client.data.Record; +import com.smartgwt.client.types.ListGridFieldType; import com.smartgwt.client.widgets.Canvas; -import com.smartgwt.client.widgets.Label; import com.smartgwt.client.widgets.layout.HLayout; import com.smartgwt.client.widgets.layout.VLayout; import com.smartgwt.client.widgets.grid.ListGrid; import com.smartgwt.client.widgets.grid.ListGridField; import com.smartgwt.client.widgets.grid.ListGridRecord; import com.smartgwt.client.widgets.events.ClickEvent; +import com.smartgwt.client.widgets.grid.events.RecordClickEvent; +import com.smartgwt.client.widgets.grid.events.RecordClickHandler; import de.intevation.flys.client.shared.model.Artifact; +import de.intevation.flys.client.shared.model.Collection; import de.intevation.flys.client.shared.model.Data; import de.intevation.flys.client.shared.model.DataItem; import de.intevation.flys.client.shared.model.DefaultData; @@ -28,13 +32,14 @@ import de.intevation.flys.client.client.FLYSConstants; import de.intevation.flys.client.client.event.StepForwardEvent; import de.intevation.flys.client.shared.model.Recommendation; -import de.intevation.flys.client.shared.model.ToLoad; import de.intevation.flys.client.shared.model.Recommendation.Facet; import de.intevation.flys.client.shared.model.Recommendation.Filter; +import de.intevation.flys.client.client.Config; import de.intevation.flys.client.client.services.LoadArtifactService; import de.intevation.flys.client.client.services.LoadArtifactServiceAsync; -import de.intevation.flys.client.client.Config; +import de.intevation.flys.client.client.services.RemoveArtifactService; +import de.intevation.flys.client.client.services.RemoveArtifactServiceAsync; // TODO Probably better to branch off AbstractUIProvider. // TODO Merge with other datacage-widget impls. @@ -51,11 +56,23 @@ protected User user; + /** ListGrid that displays user-selected pairs to build differences with. */ protected ListGrid differencesList; + /* + * List to track previously selected but now removed pairs. (Needed to + * be able to identify artifacts that can be removed from the collection. + */ + protected List<RecommendationPairRecord> removedPairs = + new ArrayList<RecommendationPairRecord>(); + + /** Service handle to clone and add artifacts to collection. */ LoadArtifactServiceAsync loadArtifactService = GWT.create( de.intevation.flys.client.client.services.LoadArtifactService.class); + /** Service to remove artifacts from collection. */ + RemoveArtifactServiceAsync removeArtifactService = GWT.create( + de.intevation.flys.client.client.services.RemoveArtifactService.class); public DatacageTwinPanel(User user) { super(); @@ -170,6 +187,7 @@ /** * Validates the selection. + * @return List of internationalized errror messages (if any). */ @Override public List<String> validate() { @@ -197,22 +215,50 @@ differencesList = new ListGrid(); differencesList.setCanEdit(false); - differencesList.setCanRemoveRecords(true); differencesList.setCanSort(false); differencesList.setHeight(150); differencesList.setShowAllRecords(true); ListGridField nameField = new ListGridField("first", "Minuend"); ListGridField capitalField = new ListGridField("second", "Subtrahend"); + // Track removed rows, therefore more or less reimplement + // setCanRecomeRecords. + final ListGridField removeField = + new ListGridField("_removeRecord", "Remove Record"){{ + setType(ListGridFieldType.ICON); + setIcon("[SKIN]/actions/remove.png"); + setCanEdit(false); + setCanFilter(false); + setCanSort(false); + setCanGroupBy(false); + setCanFreeze(false); + setWidth(25); + }}; + differencesList.setFields(new ListGridField[] {nameField, - capitalField}); - + capitalField, removeField}); + + differencesList.addRecordClickHandler(new RecordClickHandler() { + public void onRecordClick(final RecordClickEvent event) { + // Just handle remove-clicks + if(!event.getField().getName().equals(removeField.getName())) { + return; + } + trackRemoved(event.getRecord()); + event.getViewer().removeData(event.getRecord()); + } + }); layout.addMember(differencesList); return layout; } + public void trackRemoved(Record r) { + RecommendationPairRecord pr = (RecommendationPairRecord) r; + this.removedPairs.add(pr); + } + /** * Validates data, does nothing if invalid, otherwise clones new selected * waterlevels and add them to collection, forward the artifact. @@ -230,10 +276,6 @@ Config config = Config.getInstance(); ListGridRecord[] records = differencesList.getRecords(); - // TODO Problem when same facet participates in two diffs. - // - // Resolve whether "new" ones were already cloned. - List<Recommendation> ar = new ArrayList<Recommendation>(); List<Recommendation> all = new ArrayList<Recommendation>(); for (ListGridRecord record : records) { @@ -252,6 +294,51 @@ final Recommendation[] toClone = ar.toArray(new Recommendation[ar.size()]); final Recommendation[] toUse = all.toArray(new Recommendation[all.size()]); + + // Find out whether "old" artifacts have to be removed. + List<String> artifactIdsToRemove = new ArrayList<String>(); + for (RecommendationPairRecord rp: this.removedPairs) { + Recommendation first = rp.getFirst(); + Recommendation second = rp.getSecond(); + + for (Recommendation recommendation: toUse) { + if (first != null && first.getIDs().equals(recommendation.getIDs())) { + first = null; + } + if (second != null && second.getIDs().equals(recommendation.getIDs())) { + second = null; + } + + if (first == null && second == null) { + break; + } + } + if (first != null) { + artifactIdsToRemove.add(first.getIDs()); + } + if (second != null) { + artifactIdsToRemove.add(second.getIDs()); + } + } + + // Remove old artifacts, if any. Do this asychronously without much + // feedback. + for(final String uuid: artifactIdsToRemove) { + removeArtifactService.remove(this.collection, + uuid, + config.getServerUrl(), + config.getLocale(), + new AsyncCallback<Collection>() { + public void onFailure(Throwable caught) { + GWT.log("RemoveArtifact (" + uuid + ") failed."); + } + public void onSuccess(Collection collection) { + GWT.log("RemoveArtifact succeeded"); + } + }); + } + + // Clone new ones, go forward. loadArtifactService.loadMany( this.collection, toClone, @@ -273,6 +360,9 @@ } + /** + * Create Data and DataItem from selection. + */ protected Data[] getData( Recommendation[] newRecommendations, Artifact[] newArtifacts,