Mercurial > dive4elements > river
view flys-client/src/main/java/de/intevation/flys/client/client/ui/DatacageWindow.java @ 4253:a1bc5b8cff0f
Refactor GaugePanel to create it's own SectionStackSection
The GaugePanel constructor now creates a SectionStackSection instead of
using a provided one.
Improve the rendering of the GaugePanel by having access to the SmartGWT wrapper
(WidgetCanvas) object for the GWT Tree (GaugeTree) directly.
Add methods to close and open the section. Also add a getter for the section.
author | Björn Ricks <bjoern.ricks@intevation.de> |
---|---|
date | Thu, 25 Oct 2012 13:52:58 +0200 |
parents | 51ed89b754ae |
children | 80f5d1f2d4fd |
line wrap: on
line source
package de.intevation.flys.client.client.ui; import java.util.ArrayList; import java.util.List; 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.Window; import de.intevation.flys.client.client.Config; import de.intevation.flys.client.client.FLYSConstants; import de.intevation.flys.client.client.event.DatacageHandler; import de.intevation.flys.client.client.event.DatacageDoubleClickHandler; import de.intevation.flys.client.client.event.HasRedrawRequestHandlers; import de.intevation.flys.client.client.event.RedrawRequestHandler; import de.intevation.flys.client.client.event.RedrawRequestEvent; import de.intevation.flys.client.client.event.RedrawRequestEvent.Type; import de.intevation.flys.client.client.services.LoadArtifactService; import de.intevation.flys.client.client.services.LoadArtifactServiceAsync; import de.intevation.flys.client.shared.model.Artifact; import de.intevation.flys.client.shared.model.ArtifactDescription; 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.DataList; import de.intevation.flys.client.shared.model.ToLoad; import de.intevation.flys.client.shared.model.User; import de.intevation.flys.client.shared.model.Recommendation; public class DatacageWindow extends Window implements DatacageHandler, DatacageDoubleClickHandler, HasRedrawRequestHandlers { /** i18ner. */ protected FLYSConstants messages = GWT.create(FLYSConstants.class); /** Service to create/clone artifacts. */ protected LoadArtifactServiceAsync loadService = GWT.create(LoadArtifactService.class); protected CollectionView view; protected List<RedrawRequestHandler> handlers; protected int inProgress; public DatacageWindow( Artifact artifact, User user, String outs, CollectionView view ) { this.view = view; this.handlers = new ArrayList<RedrawRequestHandler>(); this.inProgress = 0; setWidth(400); setHeight(500); DatacageWidget dw = new DatacageWidget( artifact, user, outs, "load-system:true", true); dw.addDatacageHandler(this); dw.addDatacageDoubleClickHandler(this); addItem(dw); String river = findRiver(artifact); // TODO: i18n setTitle("Datenkorb: " + river); setShowMinimizeButton(false); setIsModal(true); setShowModalMask(true); setCanDragResize(true); centerInPage(); } @Override public void toLoad(ToLoad toLoad) { destroy(); List<Recommendation> recs = toLoad.toRecommendations(); loadArtifacts(recs.toArray(new Recommendation[recs.size()])); } @Override public void onDoubleClick(ToLoad toLoad) { destroy(); List<Recommendation> recs = toLoad.toRecommendations(); loadArtifacts(recs.toArray(new Recommendation[recs.size()])); } @Override public void addRedrawRequestHandler(RedrawRequestHandler handler) { if (handler != null) { handlers.add(handler); } } protected String findRiver(Artifact artifact) { ArtifactDescription adescr = artifact.getArtifactDescription(); DataList [] data = adescr.getOldData(); if (data != null && data.length > 0) { for (int i = 0; i < data.length; i++) { DataList dl = data[i]; if (dl.getState().equals("state.winfo.river")) { for (int j = dl.size()-1; j >= 0; --j) { Data d = dl.get(j); DataItem [] di = d.getItems(); if (di != null && di.length == 1) { return d.getItems()[0].getStringValue(); } } } } } return ""; } protected void decreateInProgress() { if (this.inProgress > 0) { this.inProgress--; } if (this.inProgress == 0) { fireRedrawRequest(); } } protected void fireRedrawRequest() { RedrawRequestEvent evt = new RedrawRequestEvent(Type.DEFAULT); for (RedrawRequestHandler handler: handlers) { handler.onRedrawRequest(evt); } } protected void loadArtifacts(Recommendation[] recommendations) { Config cfg = Config.getInstance(); final Collection collection = view.getCollection(); final Artifact masterArtifact = view.getArtifact(); final String locale = cfg.getLocale(); this.inProgress = recommendations.length; for (final Recommendation recommendation: recommendations) { // XXX: UGLY! If no reference artifact given use uuid of // current artifact as reference. if (recommendation.getMasterArtifact() == null) { recommendation.setMasterArtifact(masterArtifact.getUuid()); } final String factory = recommendation.getFactory(); GWT.log("Load new artifact with factory: " + factory); loadService.load( collection, recommendation, factory, locale, new AsyncCallback<Artifact>() { public void onFailure(Throwable caught) { decreateInProgress(); GWT.log("Create-artifact failed: " + caught.getMessage()); SC.warn(caught.getMessage()); } public void onSuccess(Artifact artifact) { decreateInProgress(); GWT.log("Created new artifact: " + artifact.getUuid()); } }); } } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :