Mercurial > dive4elements > river
view flys-client/src/main/java/de/intevation/flys/client/client/ui/LoadingPanel.java @ 909:794d1af42987
Clone Artifacts and add them to the current Collection in the WspDatacagePanel.
flys-client/trunk@2766 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Thu, 15 Sep 2011 16:02:23 +0000 |
parents | a9dd792444a1 |
children | ea9a73782de4 |
line wrap: on
line source
package de.intevation.flys.client.client.ui; import java.util.List; import com.google.gwt.core.client.GWT; import com.google.gwt.resources.client.ImageResource; import com.google.gwt.user.client.Timer; import com.google.gwt.user.client.rpc.AsyncCallback; import com.smartgwt.client.types.Alignment; import com.smartgwt.client.types.Positioning; import com.smartgwt.client.types.VerticalAlignment; import com.smartgwt.client.widgets.Canvas; import com.smartgwt.client.widgets.Img; import com.smartgwt.client.widgets.Label; import com.smartgwt.client.widgets.layout.VLayout; import de.intevation.flys.client.client.Config; import de.intevation.flys.client.client.FLYSConstants; import de.intevation.flys.client.client.FLYSImages; import de.intevation.flys.client.client.services.DescribeArtifactService; import de.intevation.flys.client.client.services.DescribeArtifactServiceAsync; import de.intevation.flys.client.shared.model.Artifact; import de.intevation.flys.client.shared.model.CalculationMessage; public class LoadingPanel extends Canvas { public static final int UPDATE_INTERVAL = 1000 * 3; public static final DescribeArtifactServiceAsync describe = GWT.create(DescribeArtifactService.class); private FLYSImages IMAGES = GWT.create(FLYSImages.class); private FLYSConstants MSG = GWT.create(FLYSConstants.class); protected CollectionView parent; protected Artifact artifact; protected VLayout dialog; protected Label msg; protected Label title; protected int i; public LoadingPanel(CollectionView parent, Artifact artifact) { super(); this.parent = parent; this.artifact = artifact; this.msg = new Label(""); this.title = new Label(""); this.dialog = createDialog(); this.i = 0; initLayout(); startTimer(); } private void initLayout() { setWidth("100%"); setHeight("98%"); setBackgroundColor("#7f7f7f"); setOpacity(50); setPosition(Positioning.RELATIVE); parent.addChild(this); parent.addChild(dialog); dialog.moveTo(0, 20); moveTo(0, 7); } public void setArtifact(Artifact artifact) { this.artifact = artifact; } protected VLayout createDialog() { title.setStyleName("loading-title"); title.setHeight(25); title.setWidth100(); msg.setStyleName("loading-message"); msg.setValign(VerticalAlignment.TOP); msg.setWidth100(); msg.setHeight(100); ImageResource res = IMAGES.loading(); Img img = new Img(res.getURL(), 25, 25); VLayout box = new VLayout(); box.setStyleName("loading-box"); box.setAlign(VerticalAlignment.TOP); box.setDefaultLayoutAlign(VerticalAlignment.TOP); box.addMember(title); box.addMember(msg); box.setMembersMargin(0); box.setHeight(125); box.setWidth(275); dialog = new VLayout(); dialog.setAlign(Alignment.CENTER); dialog.setDefaultLayoutAlign(Alignment.CENTER); dialog.setMembersMargin(5); dialog.setHeight100(); dialog.setWidth100(); dialog.addMember(img); dialog.addMember(box); return dialog; } private void startTimer() { Timer t = new Timer() { @Override public void run() { update(); } }; t.schedule(UPDATE_INTERVAL); } protected void update() { updateMessage(); final Config config = Config.getInstance(); final String url = config.getServerUrl(); final String locale = config.getLocale(); describe.describe(url, locale, artifact, new AsyncCallback<Artifact>() { public void onFailure(Throwable t) { GWT.log("Error while DESCRIBE artifact: " + t.getMessage()); // SC.warn()... startTimer(); } public void onSuccess(Artifact artifact) { GWT.log("Successfully DESCRIBE artifact."); setArtifact(artifact); if (artifact.isInBackground()) { startTimer(); } else { finish(); } } }); } protected void updateMessage() { List<CalculationMessage> messages = artifact.getBackgroundMessages(); if (messages != null && messages.size() > 0) { CalculationMessage calcMsg = messages.get(0); title.setContents(getStepTitle(calcMsg)); msg.setContents(calcMsg.getMessage()); } else { title.setContents(MSG.calculationStarted()); } } protected String getStepTitle(CalculationMessage msg) { return MSG.step() + " " + msg.getCurrentStep() + "/" + msg.getSteps(); } private void finish() { parent.removeChild(this); parent.removeChild(dialog); } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :