diff flys-client/src/main/java/de/intevation/flys/client/client/ui/LoadingPanel.java @ 1432:40f4137a2c31

Added a cancel button to the LoadingPanel which stops running WSPLGEN calculations (realized by returning to the previous state). flys-client/trunk@3386 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Mon, 12 Dec 2011 09:11:28 +0000
parents bc06a671ef60
children 360e22afb98b
line wrap: on
line diff
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/LoadingPanel.java	Mon Dec 12 09:02:13 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/LoadingPanel.java	Mon Dec 12 09:11:28 2011 +0000
@@ -1,5 +1,6 @@
 package de.intevation.flys.client.client.ui;
 
+import java.util.ArrayList;
 import java.util.List;
 
 import com.google.gwt.core.client.GWT;
@@ -12,17 +13,25 @@
 import com.smartgwt.client.widgets.Canvas;
 import com.smartgwt.client.widgets.Img;
 import com.smartgwt.client.widgets.Label;
+import com.smartgwt.client.widgets.events.ClickEvent;
+import com.smartgwt.client.widgets.events.ClickHandler;
+import com.smartgwt.client.widgets.layout.HLayout;
 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.event.HasStepBackHandlers;
+import de.intevation.flys.client.client.event.StepBackEvent;
+import de.intevation.flys.client.client.event.StepBackHandler;
 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.ArtifactDescription;
 import de.intevation.flys.client.shared.model.CalculationMessage;
+import de.intevation.flys.client.shared.model.DataList;
 
 
-public class LoadingPanel extends Canvas {
+public class LoadingPanel extends Canvas implements HasStepBackHandlers {
 
     public static final int UPDATE_INTERVAL = 1000 * 3;
 
@@ -32,10 +41,13 @@
     private FLYSConstants MSG    = GWT.create(FLYSConstants.class);
 
 
+    protected List<StepBackHandler> handlers;
+
     protected CollectionView parent;
     protected Artifact       artifact;
 
     protected VLayout dialog;
+    protected HLayout cancelRow;
     protected Label   msg;
     protected Label   title;
 
@@ -45,6 +57,7 @@
     public LoadingPanel(CollectionView parent, Artifact artifact) {
         super();
 
+        this.handlers = new ArrayList<StepBackHandler>();
         this.parent   = parent;
         this.artifact = artifact;
         this.msg      = new Label("");
@@ -77,6 +90,32 @@
     }
 
 
+    public Artifact getArtifact() {
+        return artifact;
+    }
+
+
+    @Override
+    public void addStepBackHandler(StepBackHandler handler) {
+        if (handler != null) {
+            handlers.add(handler);
+        }
+    }
+
+
+    /**
+     * This method is called after the user has clicked the button to cancel the
+     * current process.
+     *
+     * @param e The StepBackEvent.
+     */
+    protected void fireStepBackEvent(StepBackEvent e) {
+        for (StepBackHandler handler: handlers) {
+            handler.onStepBack(e);
+        }
+    }
+
+
     protected VLayout createDialog() {
 
         String baseUrl = GWT.getHostPageBaseURL();
@@ -92,12 +131,28 @@
 
         Img img = new Img(baseUrl + MSG.loadingImg(), 25, 25);
 
+        Label cancelLabel = new Label(MSG.cancelCalculationLabel());
+        Img   cancel      = new Img(baseUrl + MSG.cancelCalculation(), 25, 25);
+        cancel.addClickHandler(new ClickHandler() {
+            @Override
+            public void onClick(ClickEvent e) {
+                cancel();
+            }
+        });
+
+        cancelRow = new HLayout();
+        cancelRow.setHeight(27);
+        cancelRow.setWidth100();
+        cancelRow.addMember(cancel);
+        cancelRow.addMember(cancelLabel);
+
         VLayout box = new VLayout();
         box.setStyleName("loading-box");
         box.setAlign(VerticalAlignment.TOP);
         box.setDefaultLayoutAlign(VerticalAlignment.TOP);
         box.addMember(title);
         box.addMember(msg);
+        box.addMember(cancelRow);
         box.setMembersMargin(0);
         box.setHeight(125);
         box.setWidth(275);
@@ -116,6 +171,14 @@
     }
 
 
+    public String getTargetState() {
+        ArtifactDescription desc = getArtifact().getArtifactDescription();
+        DataList[]       oldData = desc.getOldData();
+
+        return oldData[oldData.length -1].getState();
+    }
+
+
     private void startTimer() {
         Timer t = new Timer() {
             @Override
@@ -136,7 +199,7 @@
         describe.describe(locale, artifact, new AsyncCallback<Artifact>() {
             public void onFailure(Throwable t) {
                 GWT.log("Error while DESCRIBE artifact: " + t.getMessage());
-                // SC.warn()...
+
                 startTimer();
             }
 
@@ -174,9 +237,16 @@
     }
 
 
+    private void cancel() {
+        fireStepBackEvent(new StepBackEvent(getTargetState()));
+        parent.removeChild(dialog);
+        parent.removeChild(this);
+    }
+
+
     private void finish() {
+        parent.removeChild(dialog);
         parent.removeChild(this);
-        parent.removeChild(dialog);
         parent.setArtifact(artifact);
     }
 }

http://dive4elements.wald.intevation.org