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