Subversion Repositories eFlore/Archives.cel-v1

Rev

Rev 28 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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