Subversion Repositories eFlore/Applications.del

Rev

Rev 939 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
823 aurelien 1
package org.tela_botanica.del.client.services.rest.async;
2
 
3
import com.google.gwt.http.client.Request;
4
import com.google.gwt.http.client.RequestCallback;
5
import com.google.gwt.http.client.Response;
6
import com.google.gwt.user.client.Window;
7
 
8
public abstract class VoteProtocoleCallback implements RequestCallback {
9
 
10
	public enum ModeRequete {
11
		AJOUT, MODIFICATION
12
	}
13
 
14
	protected ModeRequete mode;
15
 
16
	public VoteProtocoleCallback(ModeRequete mode) {
17
		this.mode = mode;
18
	}
19
 
20
	public VoteProtocoleCallback() {
21
		// TODO Auto-generated constructor stub
22
	}
23
 
24
	public void setMode(ModeRequete mode) {
25
		this.mode = mode;
26
	}
27
 
28
	@Override
29
	public void onResponseReceived(Request request, Response response){
30
		int statusCode = response.getStatusCode();
31
		int codeAttendu = 500;
32
		switch (mode) {
33
			case AJOUT:
34
				codeAttendu = 201;
35
				break;
36
			case MODIFICATION:
37
				codeAttendu = 200;
38
				break;
39
			default:
40
				codeAttendu = 500;
41
				break;
42
		}
43
 
44
		if (statusCode == codeAttendu) {
45
			surRetour(response.getText());
46
		} else {
47
			surErreur("Erreur " + statusCode + ": " + response.getText());
48
		}
49
	}
50
 
51
	@Override
52
	public void onError(Request request, Throwable exception) {
53
		Window.alert(exception.getMessage());
54
	}
55
 
56
	public abstract void surRetour(String messageRetour);
57
	public abstract void surErreur(String messageErreur);
58
}