Subversion Repositories eFlore/Archives.cel-v1

Rev

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

Rev Author Line No. Line
28 ddelon 1
/**
2
 David Delon david.delon@clapas.net 2007
3
 
4
 */
5
 
6
/*
7
 * ConnexionView.java  : affichage information portant sur le statut de la connexion utilisateur
8
 *
9
 *
10
 * 1: Le programme affiche le statut connecte si l'utilisateur s'est connecte precedemment, sinon s'affiche le statut deconnecte
11
 * 2: Le programme arme les actions liees a la connection ou a la deconnection
12
 *    - Connection : affichage de la boite de connexion
13
 *    - Deconnexion : appel du service de deconnexion, et appel de la re-initialisation de l'affichage pour le nouvel identifiant utilisateur obtenu (identifiant  de session)
14
 */
15
package org.tela_botanica.client;
16
 
17
import net.mygwt.ui.client.widget.WidgetContainer;
18
 
19
import com.google.gwt.json.client.JSONArray;
20
import com.google.gwt.json.client.JSONBoolean;
21
import com.google.gwt.json.client.JSONParser;
22
import com.google.gwt.json.client.JSONString;
23
import com.google.gwt.json.client.JSONValue;
24
import com.google.gwt.user.client.HTTPRequest;
25
import com.google.gwt.user.client.ResponseTextHandler;
26
import com.google.gwt.user.client.Window;
27
import com.google.gwt.user.client.ui.ClickListener;
28
import com.google.gwt.user.client.ui.HTML;
29
import com.google.gwt.user.client.ui.HorizontalPanel;
30
import com.google.gwt.user.client.ui.Label;
31
import com.google.gwt.user.client.ui.Widget;
32
 
33
 
34
public class ConnexionView {
35
 
36
 
37
  private Mediator mediator=null;
38
 
39
  private String user =null;
40
  private Label signLabel = new Label() ;
41
 
42
  private String serviceBaseUrl = null;
43
 
44
  public ConnexionView(final Mediator med) {
45
 
46
	mediator=med;
47
	user=mediator.getUser();
48
 
49
    serviceBaseUrl = mediator.getServiceBaseUrl();
50
 
51
    if (!mediator.getConnected()) {
52
    	signLabel.setText("Connexion");
53
    }
54
    else {
55
    	signLabel.setText(user+ " (deconnexion)");
56
    }
57
 
58
	HorizontalPanel outer = new HorizontalPanel();
59
	HorizontalPanel inner = new HorizontalPanel();
60
 
61
 
62
	outer.setHorizontalAlignment(HorizontalPanel.ALIGN_RIGHT);
63
 
64
	 inner.add(signLabel);
65
	 inner.add(new HTML("<b>Carnet en ligne</b>"));
66
 
67
	 inner.setSpacing(3);
68
	 outer.add(inner);
69
 
70
 
71
 
72
	 signLabel.addClickListener(
73
		    	new ClickListener() {
74
		    		public void onClick(Widget sender) {
75
 
76
		    			// Non connecte ? Lien vers boite de connection
77
 
78
		    			if (!mediator.getConnected()) {
79
		    				LoginDialog loginDialog = new LoginDialog(med);
80
 
81
		    				// Position it roughly in the middle of the screen.
82
		    				int left = (Window.getClientWidth() - 512) / 2;
83
		    				int top = (Window.getClientHeight() - 256) / 2;
84
		    				loginDialog.setPopupPosition(left, top);
85
		    				loginDialog.show();
86
		    			}
87
 
88
		    			else {
89
 
90
		    				// Deja Connecte : lancement deconnexion sur selection de l'action
91
			    			HTTPRequest.asyncGet(serviceBaseUrl + "/User/" + user    ,
92
			    					new ResponseTextHandler() {
93
 
94
			    						public void onCompletion(String str) {
95
 
96
			    								JSONValue jsonValue = JSONParser.parse(str);
97
			    								JSONArray jsonArray;
98
			    								if ((jsonArray = jsonValue.isArray()) != null) {
99
			    									user = Util.toCelString(((JSONString) jsonArray.get(0)).toString()); // Identifiant utilisateur : identifant de session
100
			    									mediator.setConnected(((JSONBoolean) jsonArray.get(1)).booleanValue());
101
			    								}
102
 
103
			    								if (!mediator.getConnected()) { // La deconnexion a ete accepte :
104
			    									mediator.onLogoff(user);
105
			    								}
106
			    						}
107
			    			});
108
 
109
 
110
		    			}
111
 
112
		    		}
113
		     	}
114
	);
115
 
116
	 WidgetContainer north=mediator.getNorthContainer();
117
	 north.add(outer);
118
 
119
 
120
  }
121
 
122
public Label getSignLabel() {
123
	return signLabel;
124
}
125
 
126
 
127
 
128
 
129
}
130
 
131
 
132
/* +--Fin du code ---------------------------------------------------------------------------------------+
133
* $Log$
134
* Revision 1.6  2007-12-22 14:48:53  ddelon
135
* Documentation et refactorisation
136
*
137
* Revision 1.5  2007-09-17 19:25:34  ddelon
138
* Documentation
139
*
140
*
141
*/