comparison 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
comparison
equal deleted inserted replaced
1431:987f95ceb623 1432:40f4137a2c31
1 package de.intevation.flys.client.client.ui; 1 package de.intevation.flys.client.client.ui;
2 2
3 import java.util.ArrayList;
3 import java.util.List; 4 import java.util.List;
4 5
5 import com.google.gwt.core.client.GWT; 6 import com.google.gwt.core.client.GWT;
6 import com.google.gwt.user.client.Timer; 7 import com.google.gwt.user.client.Timer;
7 import com.google.gwt.user.client.rpc.AsyncCallback; 8 import com.google.gwt.user.client.rpc.AsyncCallback;
10 import com.smartgwt.client.types.Positioning; 11 import com.smartgwt.client.types.Positioning;
11 import com.smartgwt.client.types.VerticalAlignment; 12 import com.smartgwt.client.types.VerticalAlignment;
12 import com.smartgwt.client.widgets.Canvas; 13 import com.smartgwt.client.widgets.Canvas;
13 import com.smartgwt.client.widgets.Img; 14 import com.smartgwt.client.widgets.Img;
14 import com.smartgwt.client.widgets.Label; 15 import com.smartgwt.client.widgets.Label;
16 import com.smartgwt.client.widgets.events.ClickEvent;
17 import com.smartgwt.client.widgets.events.ClickHandler;
18 import com.smartgwt.client.widgets.layout.HLayout;
15 import com.smartgwt.client.widgets.layout.VLayout; 19 import com.smartgwt.client.widgets.layout.VLayout;
16 20
17 import de.intevation.flys.client.client.Config; 21 import de.intevation.flys.client.client.Config;
18 import de.intevation.flys.client.client.FLYSConstants; 22 import de.intevation.flys.client.client.FLYSConstants;
23 import de.intevation.flys.client.client.event.HasStepBackHandlers;
24 import de.intevation.flys.client.client.event.StepBackEvent;
25 import de.intevation.flys.client.client.event.StepBackHandler;
19 import de.intevation.flys.client.client.services.DescribeArtifactService; 26 import de.intevation.flys.client.client.services.DescribeArtifactService;
20 import de.intevation.flys.client.client.services.DescribeArtifactServiceAsync; 27 import de.intevation.flys.client.client.services.DescribeArtifactServiceAsync;
21 import de.intevation.flys.client.shared.model.Artifact; 28 import de.intevation.flys.client.shared.model.Artifact;
29 import de.intevation.flys.client.shared.model.ArtifactDescription;
22 import de.intevation.flys.client.shared.model.CalculationMessage; 30 import de.intevation.flys.client.shared.model.CalculationMessage;
23 31 import de.intevation.flys.client.shared.model.DataList;
24 32
25 public class LoadingPanel extends Canvas { 33
34 public class LoadingPanel extends Canvas implements HasStepBackHandlers {
26 35
27 public static final int UPDATE_INTERVAL = 1000 * 3; 36 public static final int UPDATE_INTERVAL = 1000 * 3;
28 37
29 public static final DescribeArtifactServiceAsync describe = 38 public static final DescribeArtifactServiceAsync describe =
30 GWT.create(DescribeArtifactService.class); 39 GWT.create(DescribeArtifactService.class);
31 40
32 private FLYSConstants MSG = GWT.create(FLYSConstants.class); 41 private FLYSConstants MSG = GWT.create(FLYSConstants.class);
33 42
34 43
44 protected List<StepBackHandler> handlers;
45
35 protected CollectionView parent; 46 protected CollectionView parent;
36 protected Artifact artifact; 47 protected Artifact artifact;
37 48
38 protected VLayout dialog; 49 protected VLayout dialog;
50 protected HLayout cancelRow;
39 protected Label msg; 51 protected Label msg;
40 protected Label title; 52 protected Label title;
41 53
42 protected int i; 54 protected int i;
43 55
44 56
45 public LoadingPanel(CollectionView parent, Artifact artifact) { 57 public LoadingPanel(CollectionView parent, Artifact artifact) {
46 super(); 58 super();
47 59
60 this.handlers = new ArrayList<StepBackHandler>();
48 this.parent = parent; 61 this.parent = parent;
49 this.artifact = artifact; 62 this.artifact = artifact;
50 this.msg = new Label(""); 63 this.msg = new Label("");
51 this.title = new Label(""); 64 this.title = new Label("");
52 this.dialog = createDialog(); 65 this.dialog = createDialog();
75 public void setArtifact(Artifact artifact) { 88 public void setArtifact(Artifact artifact) {
76 this.artifact = artifact; 89 this.artifact = artifact;
77 } 90 }
78 91
79 92
93 public Artifact getArtifact() {
94 return artifact;
95 }
96
97
98 @Override
99 public void addStepBackHandler(StepBackHandler handler) {
100 if (handler != null) {
101 handlers.add(handler);
102 }
103 }
104
105
106 /**
107 * This method is called after the user has clicked the button to cancel the
108 * current process.
109 *
110 * @param e The StepBackEvent.
111 */
112 protected void fireStepBackEvent(StepBackEvent e) {
113 for (StepBackHandler handler: handlers) {
114 handler.onStepBack(e);
115 }
116 }
117
118
80 protected VLayout createDialog() { 119 protected VLayout createDialog() {
81 120
82 String baseUrl = GWT.getHostPageBaseURL(); 121 String baseUrl = GWT.getHostPageBaseURL();
83 122
84 title.setStyleName("loading-title"); 123 title.setStyleName("loading-title");
89 msg.setValign(VerticalAlignment.TOP); 128 msg.setValign(VerticalAlignment.TOP);
90 msg.setWidth100(); 129 msg.setWidth100();
91 msg.setHeight(100); 130 msg.setHeight(100);
92 131
93 Img img = new Img(baseUrl + MSG.loadingImg(), 25, 25); 132 Img img = new Img(baseUrl + MSG.loadingImg(), 25, 25);
133
134 Label cancelLabel = new Label(MSG.cancelCalculationLabel());
135 Img cancel = new Img(baseUrl + MSG.cancelCalculation(), 25, 25);
136 cancel.addClickHandler(new ClickHandler() {
137 @Override
138 public void onClick(ClickEvent e) {
139 cancel();
140 }
141 });
142
143 cancelRow = new HLayout();
144 cancelRow.setHeight(27);
145 cancelRow.setWidth100();
146 cancelRow.addMember(cancel);
147 cancelRow.addMember(cancelLabel);
94 148
95 VLayout box = new VLayout(); 149 VLayout box = new VLayout();
96 box.setStyleName("loading-box"); 150 box.setStyleName("loading-box");
97 box.setAlign(VerticalAlignment.TOP); 151 box.setAlign(VerticalAlignment.TOP);
98 box.setDefaultLayoutAlign(VerticalAlignment.TOP); 152 box.setDefaultLayoutAlign(VerticalAlignment.TOP);
99 box.addMember(title); 153 box.addMember(title);
100 box.addMember(msg); 154 box.addMember(msg);
155 box.addMember(cancelRow);
101 box.setMembersMargin(0); 156 box.setMembersMargin(0);
102 box.setHeight(125); 157 box.setHeight(125);
103 box.setWidth(275); 158 box.setWidth(275);
104 159
105 dialog = new VLayout(); 160 dialog = new VLayout();
114 169
115 return dialog; 170 return dialog;
116 } 171 }
117 172
118 173
174 public String getTargetState() {
175 ArtifactDescription desc = getArtifact().getArtifactDescription();
176 DataList[] oldData = desc.getOldData();
177
178 return oldData[oldData.length -1].getState();
179 }
180
181
119 private void startTimer() { 182 private void startTimer() {
120 Timer t = new Timer() { 183 Timer t = new Timer() {
121 @Override 184 @Override
122 public void run() { 185 public void run() {
123 update(); 186 update();
134 final String locale = config.getLocale(); 197 final String locale = config.getLocale();
135 198
136 describe.describe(locale, artifact, new AsyncCallback<Artifact>() { 199 describe.describe(locale, artifact, new AsyncCallback<Artifact>() {
137 public void onFailure(Throwable t) { 200 public void onFailure(Throwable t) {
138 GWT.log("Error while DESCRIBE artifact: " + t.getMessage()); 201 GWT.log("Error while DESCRIBE artifact: " + t.getMessage());
139 // SC.warn()... 202
140 startTimer(); 203 startTimer();
141 } 204 }
142 205
143 public void onSuccess(Artifact artifact) { 206 public void onSuccess(Artifact artifact) {
144 GWT.log("Successfully DESCRIBE artifact."); 207 GWT.log("Successfully DESCRIBE artifact.");
172 protected String getStepTitle(CalculationMessage msg) { 235 protected String getStepTitle(CalculationMessage msg) {
173 return MSG.step() + " " + msg.getCurrentStep() + "/" + msg.getSteps(); 236 return MSG.step() + " " + msg.getCurrentStep() + "/" + msg.getSteps();
174 } 237 }
175 238
176 239
240 private void cancel() {
241 fireStepBackEvent(new StepBackEvent(getTargetState()));
242 parent.removeChild(dialog);
243 parent.removeChild(this);
244 }
245
246
177 private void finish() { 247 private void finish() {
248 parent.removeChild(dialog);
178 parent.removeChild(this); 249 parent.removeChild(this);
179 parent.removeChild(dialog);
180 parent.setArtifact(artifact); 250 parent.setArtifact(artifact);
181 } 251 }
182 } 252 }
183 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : 253 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org