teichmann@5861: /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde teichmann@5861: * Software engineering by Intevation GmbH teichmann@5861: * teichmann@5993: * This file is Free Software under the GNU AGPL (>=v3) teichmann@5861: * and comes with ABSOLUTELY NO WARRANTY! Check out the teichmann@5993: * documentation coming with Dive4Elements River for details. teichmann@5861: */ teichmann@5861: teichmann@5835: package org.dive4elements.river.client.client.ui.minfo; raimund@3508: sascha@3535: import com.google.gwt.core.client.GWT; christian@4183: rrenkert@7971: import com.smartgwt.client.util.SC; rrenkert@7971: import com.smartgwt.client.widgets.Button; sascha@3535: import com.smartgwt.client.widgets.Canvas; christian@4183: sascha@3535: import com.smartgwt.client.widgets.events.ClickEvent; rrenkert@7971: import com.smartgwt.client.widgets.events.ClickHandler; christian@4183: sascha@3535: import com.smartgwt.client.widgets.layout.VLayout; rrenkert@7971: import com.smartgwt.client.widgets.tree.TreeNode; sascha@3535: teichmann@5835: import org.dive4elements.river.client.client.FLYSConstants; christian@4183: teichmann@5835: import org.dive4elements.river.client.client.services.LoadArtifactServiceAsync; teichmann@5835: import org.dive4elements.river.client.client.services.RemoveArtifactServiceAsync; christian@4183: teichmann@5835: import org.dive4elements.river.client.client.ui.DatacageTwinPanel; rrenkert@7971: import org.dive4elements.river.client.client.ui.DatacageWidget; teichmann@5835: import org.dive4elements.river.client.client.ui.RecommendationPairRecord; christian@4183: teichmann@5835: import org.dive4elements.river.client.shared.model.DataList; rrenkert@7971: import org.dive4elements.river.client.shared.model.ToLoad; teichmann@5835: teichmann@5835: import org.dive4elements.river.client.shared.model.Recommendation; teichmann@5835: import org.dive4elements.river.client.shared.model.User; sascha@3535: raimund@3508: import java.util.ArrayList; raimund@3508: import java.util.List; raimund@3508: raimund@3508: // TODO Probably better to branch off AbstractUIProvider. raimund@3508: public class BedHeightsDatacagePanel raimund@3508: extends DatacageTwinPanel { raimund@3508: raimund@3508: protected static FLYSConstants MSG = GWT.create(FLYSConstants.class); raimund@3508: raimund@3508: /** raimund@3508: * List to track previously selected but now removed pairs. (Needed to raimund@3508: * be able to identify artifacts that can be removed from the collection. raimund@3508: */ raimund@3508: protected List removedPairs = raimund@3508: new ArrayList(); raimund@3508: raimund@3508: /** Service handle to clone and add artifacts to collection. */ raimund@3508: LoadArtifactServiceAsync loadArtifactService = GWT.create( tom@8856: org.dive4elements.river.client.client.services tom@8856: .LoadArtifactService.class); raimund@3508: raimund@3508: /** Service to remove artifacts from collection. */ raimund@3508: RemoveArtifactServiceAsync removeArtifactService = GWT.create( tom@8856: org.dive4elements.river.client.client.services tom@8856: .RemoveArtifactService.class); raimund@3508: rrenkert@7971: protected DatacageWidget datacage; raimund@3508: raimund@3508: public BedHeightsDatacagePanel(User user) { raimund@3508: super(user); raimund@3508: } raimund@3508: raimund@3508: /** tom@8856: * Creates graphical representation and interaction widgets for the data. raimund@3508: * @param dataList the data. raimund@3508: * @return graphical representation and interaction widgets for data. raimund@3508: */ raimund@3508: @Override raimund@3508: public Canvas create(DataList dataList) { raimund@3508: GWT.log("createData()"); raimund@3508: raimund@3508: Canvas widget = createWidget(); raimund@3508: Canvas submit = getNextButton(); rrenkert@7971: datacage = new DatacageWidget( tom@8298: this.artifact, user, "minfo_diff_panel", "load-system:true", false); rrenkert@7971: rrenkert@7971: Button plusBtn = new Button(MSG.datacage_add_pair()); rrenkert@7971: plusBtn.setAutoFit(true); rrenkert@7971: plusBtn.addClickHandler(new ClickHandler() { rrenkert@7971: @Override rrenkert@7971: public void onClick(ClickEvent event) { rrenkert@7971: plusClicked(); rrenkert@7971: } rrenkert@7971: }); raimund@3508: raimund@3508: VLayout layout = new VLayout(); rrenkert@7971: VLayout helperLayout = new VLayout(); rrenkert@7971: helperLayout.addMember(datacage); rrenkert@7971: helperLayout.addMember(plusBtn); raimund@3508: raimund@3508: layout.addMember(widget); raimund@3508: layout.addMember(submit); raimund@3508: layout.setMembersMargin(10); raimund@3508: this.helperContainer.addMember(helperLayout); raimund@3508: andre@8719: populateGrid(dataList, "bedheight"); raimund@3508: raimund@3508: return layout; raimund@3508: } raimund@3508: andre@8719: public void adjustRecommendation(Recommendation recommendation) { andre@8719: recommendation.setFactory("bedheight"); raimund@3508: } raimund@3508: raimund@3508: @Override tom@8856: protected String createDataString( tom@8856: String artifact, tom@8856: Recommendation recommendation tom@8856: ) { andre@8719: return createDataString(artifact, recommendation, "bedheight"); raimund@3508: } rrenkert@7971: rrenkert@7971: /** rrenkert@7971: * Callback for add-button. rrenkert@7971: * Fires to load for every selected element and handler. rrenkert@7971: */ rrenkert@7971: public void plusClicked() { rrenkert@7971: List selection = datacage.getPlainSelection(); rrenkert@7971: rrenkert@7971: if (selection == null || selection.isEmpty()) { rrenkert@7971: SC.say(MSG.warning()); rrenkert@7971: return; rrenkert@7971: } rrenkert@7971: rrenkert@7971: for (TreeNode node : selection) { rrenkert@7971: ToLoad toLoad1 = new ToLoad(); rrenkert@7971: ToLoad toLoad2 = new ToLoad(); rrenkert@7971: rrenkert@7971: String factory = node.getAttribute("factory"); rrenkert@7971: if (factory != null) { // we need at least a factory rrenkert@7971: String artifact = node.getAttribute("artifact-id"); rrenkert@7971: String out = node.getAttribute("out"); rrenkert@7971: String name = node.getAttribute("facet"); rrenkert@7971: String ids = node.getAttribute("ids"); rrenkert@7971: String info = node.getAttribute("info"); rrenkert@7971: String targetOut = node.getAttribute("target_out"); rrenkert@7971: rrenkert@7971: String[] splitIds = ids.split("#"); rrenkert@7971: String[] splitInfo = info.split("#"); rrenkert@7971: toLoad1.add(artifact, rrenkert@7971: factory, rrenkert@7971: out, rrenkert@7971: name, rrenkert@7971: splitIds[0], rrenkert@7971: splitInfo[0], rrenkert@7971: targetOut); rrenkert@7971: toLoad2.add(artifact, rrenkert@7971: factory, rrenkert@7971: out, rrenkert@7971: name, rrenkert@7971: splitIds[1], rrenkert@7971: splitInfo[1], rrenkert@7971: targetOut); rrenkert@7971: } rrenkert@7971: differencesList.addData(new RecommendationPairRecord( rrenkert@7971: toLoad1.toRecommendations().get(0), rrenkert@7971: toLoad2.toRecommendations().get(0))); rrenkert@7971: } rrenkert@7971: } raimund@3508: } raimund@3508: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :