Mercurial > dive4elements > river
diff gwt-client/src/main/java/org/dive4elements/river/client/client/ui/WspDatacagePanel.java @ 9220:e3c2ae1887e8
Allow to filter contents of datacage on client side.
Allow to override column label of datacage
Some code cleanup
author | gernotbelger |
---|---|
date | Wed, 04 Jul 2018 12:00:51 +0200 |
parents | 5e38e2924c07 |
children |
line wrap: on
line diff
--- a/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/WspDatacagePanel.java Wed Jul 04 10:46:37 2018 +0200 +++ b/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/WspDatacagePanel.java Wed Jul 04 12:00:51 2018 +0200 @@ -8,15 +8,12 @@ package org.dive4elements.river.client.client.ui; -import com.google.gwt.core.client.GWT; -import com.google.gwt.user.client.rpc.AsyncCallback; - -import com.smartgwt.client.util.SC; -import com.smartgwt.client.widgets.events.ClickEvent; +import java.util.List; +import java.util.Map; +import java.util.Set; import org.dive4elements.river.client.client.Config; import org.dive4elements.river.client.client.FLYS; -import org.dive4elements.river.client.client.FLYSConstants; import org.dive4elements.river.client.client.event.StepForwardEvent; import org.dive4elements.river.client.client.services.LoadArtifactService; import org.dive4elements.river.client.client.services.LoadArtifactServiceAsync; @@ -32,67 +29,40 @@ import org.dive4elements.river.client.shared.model.ToLoad; import org.dive4elements.river.client.shared.model.User; -import java.util.List; -import java.util.Map; -import java.util.Set; - +import com.google.gwt.core.client.GWT; +import com.google.gwt.user.client.rpc.AsyncCallback; +import com.smartgwt.client.util.SC; +import com.smartgwt.client.widgets.events.ClickEvent; public class WspDatacagePanel extends DatacagePanel { private static final long serialVersionUID = 2494432743877141135L; - public static final String WATERLEVEL_OUTS = "waterlevels_panel"; - - public static final FLYSConstants MSG = GWT.create(FLYSConstants.class); - - - protected LoadArtifactServiceAsync loadService = - GWT.create(LoadArtifactService.class); - - protected Recommendation recommendation; - protected Artifact artifact; - - - public WspDatacagePanel() { - super(); - } - + private static final String WATERLEVEL_OUTS = "waterlevels_panel"; - public WspDatacagePanel(User user) { - super(user); - } - + private final LoadArtifactServiceAsync loadService = GWT.create(LoadArtifactService.class); - @Override - public String getOuts() { - return WATERLEVEL_OUTS; + public WspDatacagePanel(final User user) { + super(user, WATERLEVEL_OUTS, null, false); } - - @Override - protected void createWidget() { - super.createWidget(); - widget.setIsMutliSelectable(false); - } - - /** * We need to override this method (defined in AbstractUIProvider) because * we have to create a new Artifact specified by the Datacage selection via * Async request. * - * @param e The ClickEvent. + * @param e + * The ClickEvent. */ @Override - public void onClick(ClickEvent e) { - List<String> errors = validate(); + public void onClick(final ClickEvent e) { + final List<String> errors = validate(); if (errors == null || errors.isEmpty()) { // 1) Fetch selected recommendation. - Config config = Config.getInstance(); - final String locale = config.getLocale(); - final Collection c = this.collection; - final Recommendation r = getSelectedRecommendation(); - + final Config config = Config.getInstance(); + final String locale = config.getLocale(); + final Collection c = this.collection; + final Recommendation r = getSelectedRecommendation(); if (r == null) { SC.warn(MSG.warning_no_wsp_selected()); @@ -101,38 +71,31 @@ // TODO: This could eventually be handled server-side. // 2) Create, load Artifact and fire event. - loadService.load( - c, r, r.getFactory(), locale, - new AsyncCallback<Artifact>() { - @Override - public void onFailure(Throwable caught) { - GWT.log("WspDatacagePanel", caught); - SC.warn(FLYS.getExceptionString(MSG, caught)); - } + this.loadService.load(c, r, r.getFactory(), locale, new AsyncCallback<Artifact>() { + @Override + public void onFailure(final Throwable caught) { + GWT.log("WspDatacagePanel", caught); + SC.warn(FLYS.getExceptionString(MSG, caught)); + } - @Override - public void onSuccess(Artifact newArtifact) { - GWT.log("Created new artifact."); - fireStepForwardEvent(new StepForwardEvent( - getData(r, newArtifact))); - } + @Override + public void onSuccess(final Artifact newArtifact) { + GWT.log("Created new artifact."); + fireStepForwardEvent(new StepForwardEvent(getData(r, newArtifact))); } - ); - } - else { + }); + } else { showErrors(errors); } } - protected Recommendation getSelectedRecommendation() { - ToLoad toLoad = widget.getSelection(); - List<Recommendation> recoms = toLoad.toRecommendations(); + final ToLoad toLoad = getSelection(); + final List<Recommendation> recoms = toLoad.toRecommendations(); return recoms.size() > 0 ? recoms.get(0) : null; } - /** * Nothing is done in this method. It returns null, because we serve the * Data another way! @@ -145,35 +108,32 @@ return null; } - /** Returns a Data Array with one default item. */ - protected Data[] getData(Recommendation r, Artifact newArtifact) { - String uuid = newArtifact.getUuid(); + protected final Data[] getData(final Recommendation r, final Artifact newArtifact) { + final String uuid = newArtifact.getUuid(); r.setMasterArtifact(uuid); - String value = createDataString(uuid, r); + final String value = createDataString(uuid, r); - DataItem item = new DefaultDataItem(dataName, dataName, value); - return new Data[] { new DefaultData( - dataName, null, null, new DataItem[] { item }) }; + final String dataName = getMyDataName(); + + final DataItem item = new DefaultDataItem(dataName, dataName, value); + return new Data[] { new DefaultData(dataName, null, null, new DataItem[] { item }) }; } - - protected String createDataString( - String artifact, - Recommendation recommendation - ) { - Facet f = null; + private String createDataString(final String artifactId, final Recommendation recommendation) { // The filter will only be available or previous calculation artifacts. - Filter filter = recommendation.getFilter(); + final Filter filter = recommendation.getFilter(); if (filter != null) { - Map<String, List<Facet>> outs = filter.getOuts(); - Set<Map.Entry<String, List<Facet>>> entries = outs.entrySet(); + Facet f = null; - for (Map.Entry<String, List<Facet>> entry: entries) { - List<Facet> fs = entry.getValue(); + final Map<String, List<Facet>> outs = filter.getOuts(); + final Set<Map.Entry<String, List<Facet>>> entries = outs.entrySet(); + + for (final Map.Entry<String, List<Facet>> entry : entries) { + final List<Facet> fs = entry.getValue(); f = fs.get(0); if (f != null) { @@ -181,13 +141,9 @@ } } - return "[" + artifact + ";" + f.getName() + ";" - + f.getIndex() + "]"; + return "[" + artifactId + ";" + f.getName() + ";" + f.getIndex() + "]"; } - else { - return "[" + artifact + ";" - + recommendation.getFactory() + ";" + 0 + "]"; - } + + return "[" + artifactId + ";" + recommendation.getFactory() + ";" + 0 + "]"; } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : +} \ No newline at end of file