Subversion Repositories eFlore/Archives.cel-v1

Rev

Rev 14 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 14 Rev 26
-
 
1
/**
-
 
2
 David Delon david.delon@clapas.net 2007
-
 
3
 
-
 
4
 */
-
 
5
 
1
/*
6
/*
2
 * Copyright 2006 Google Inc.
-
 
3
 * 
-
 
4
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
-
 
5
 * use this file except in compliance with the License. You may obtain a copy of
7
 * TopPanel.java  : affichage information portant sur le statut de la connexion utilisateur
6
 * the License at
-
 
7
 * 
8
 * 
8
 * http://www.apache.org/licenses/LICENSE-2.0
-
 
9
 * 
9
 * 
10
 * Unless required by applicable law or agreed to in writing, software
10
 * 1: Le programme affiche le statut connecte si l'utilisateur s'est connecte precedemment, sinon s'affiche le statut deconnecte
11
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11
 * 2: Le programme arme les actions liees a la connection ou a la deconnection
12
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12
 *    - Connection : affichage de la boite de connexion
13
 * License for the specific language governing permissions and limitations under
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
 * the License.
-
 
15
 */
14
 */
16
package org.tela_botanica.client;
15
package org.tela_botanica.client;
17
 
16
 
18
import com.google.gwt.json.client.JSONArray;
17
import com.google.gwt.json.client.JSONArray;
19
import com.google.gwt.json.client.JSONBoolean;
18
import com.google.gwt.json.client.JSONBoolean;
20
import com.google.gwt.json.client.JSONParser;
19
import com.google.gwt.json.client.JSONParser;
21
import com.google.gwt.json.client.JSONString;
20
import com.google.gwt.json.client.JSONString;
22
import com.google.gwt.json.client.JSONValue;
21
import com.google.gwt.json.client.JSONValue;
23
import com.google.gwt.user.client.HTTPRequest;
22
import com.google.gwt.user.client.HTTPRequest;
24
import com.google.gwt.user.client.ResponseTextHandler;
23
import com.google.gwt.user.client.ResponseTextHandler;
25
import com.google.gwt.user.client.Window;
24
import com.google.gwt.user.client.Window;
26
import com.google.gwt.user.client.ui.ClickListener;
25
import com.google.gwt.user.client.ui.ClickListener;
27
import com.google.gwt.user.client.ui.Composite;
26
import com.google.gwt.user.client.ui.Composite;
28
import com.google.gwt.user.client.ui.HTML;
27
import com.google.gwt.user.client.ui.HTML;
29
import com.google.gwt.user.client.ui.HorizontalPanel;
28
import com.google.gwt.user.client.ui.HorizontalPanel;
30
import com.google.gwt.user.client.ui.Label;
29
import com.google.gwt.user.client.ui.Label;
31
import com.google.gwt.user.client.ui.Widget;
30
import com.google.gwt.user.client.ui.Widget;
32
 
-
 
33
/**
-
 
34
 * Composite permet de wrapper des Widget pour creer un nouveau Widget cf methode initWidget()
-
 
35
 */
-
 
36
 
31
 
37
 
32
 
38
public class TopPanel extends Composite {
33
public class TopPanel extends Composite {
39
 
34
 
40
	
35
	
41
  private Mediator mediator=null;
36
  private Mediator mediator=null;
42
	  
37
	  
43
  private String user =null;	
38
  private String user =null;	
44
  private Label signLabel = new Label() ;
39
  private Label signLabel = new Label() ;
45
  
40
  
46
  private String serviceBaseUrl = null;
41
  private String serviceBaseUrl = null;
47
	
42
	
48
  public TopPanel(final Mediator med) {
43
  public TopPanel(final Mediator med) {
49
 
44
 
50
	mediator=med;
45
	mediator=med;
51
	  
46
	  
52
	mediator.registerTopPanel(this);
47
	mediator.registerTopPanel(this);
53
	  
48
	  
54
	user=mediator.getUser();
49
	user=mediator.getUser();
55
	
50
	
56
   	signLabel.setStyleName("selection_label");
51
   	signLabel.setStyleName("selection_label");
57
   	
52
   	
58
    serviceBaseUrl = mediator.getServiceBaseUrl();
53
    serviceBaseUrl = mediator.getServiceBaseUrl();
59
 
54
 
60
    if (!mediator.getConnected()) {
55
    if (!mediator.getConnected()) {
61
    	signLabel.setText("Connexion");
56
    	signLabel.setText("Connexion");
62
    }
57
    }
63
    else {
58
    else {
64
    	signLabel.setText(user+ " (deconnexion)");
59
    	signLabel.setText(user+ " (deconnexion)");
65
    }
60
    }
66
 
61
 
67
	HorizontalPanel outer = new HorizontalPanel();
62
	HorizontalPanel outer = new HorizontalPanel();
68
	HorizontalPanel inner = new HorizontalPanel();
63
	HorizontalPanel inner = new HorizontalPanel();
69
   
64
   
70
    
65
    
71
	outer.setHorizontalAlignment(HorizontalPanel.ALIGN_RIGHT);
66
	outer.setHorizontalAlignment(HorizontalPanel.ALIGN_RIGHT);
72
 
67
 
73
	 inner.add(signLabel);
68
	 inner.add(signLabel);
74
	 inner.add(new HTML("<b>Carnet en ligne</b>"));
69
	 inner.add(new HTML("<b>Carnet en ligne</b>"));
75
	 
70
	 
76
	 inner.setSpacing(3);
71
	 inner.setSpacing(3);
77
	 outer.add(inner);
72
	 outer.add(inner);
-
 
73
 
-
 
74
	 
78
 
75
	 
79
	 signLabel.addClickListener(
76
	 signLabel.addClickListener(
80
		    	new ClickListener() {
77
		    	new ClickListener() {
81
		    		public void onClick(Widget sender) {
78
		    		public void onClick(Widget sender) {
-
 
79
		    
-
 
80
		    			// Non connecte ? Lien vers boite de connection
82
		    
81
		    			
83
		    			if (!mediator.getConnected()) {
82
		    			if (!mediator.getConnected()) {
84
		    				LoginDialog loginDialog = new LoginDialog(med);
83
		    				LoginDialog loginDialog = new LoginDialog(med);
85
 
84
 
86
		    				// Position it roughly in the middle of the screen.
85
		    				// Position it roughly in the middle of the screen.
87
		    				int left = (Window.getClientWidth() - 512) / 2;
86
		    				int left = (Window.getClientWidth() - 512) / 2;
88
		    				int top = (Window.getClientHeight() - 256) / 2;
87
		    				int top = (Window.getClientHeight() - 256) / 2;
89
		    				loginDialog.setPopupPosition(left, top);
88
		    				loginDialog.setPopupPosition(left, top);
90
		    				loginDialog.show();
89
		    				loginDialog.show();
91
		    			}
90
		    			}
92
		    			
91
		    			
93
		    			else {
92
		    			else {
94
		    				
93
		    			
-
 
94
		    				// Deja Connecte : lancement deconnexion sur selection de l'action
95
			    			HTTPRequest.asyncGet(serviceBaseUrl + "/User/" + user    ,
95
			    			HTTPRequest.asyncGet(serviceBaseUrl + "/User/" + user    ,
96
			    					new ResponseTextHandler() {
96
			    					new ResponseTextHandler() {
97
 
97
 
98
			    						public void onCompletion(String str) {
98
			    						public void onCompletion(String str) {
99
			    							
99
			    							
100
			    								JSONValue jsonValue = JSONParser.parse(str);
100
			    								JSONValue jsonValue = JSONParser.parse(str);
101
			    								JSONArray jsonArray;
101
			    								JSONArray jsonArray;
102
			    								if ((jsonArray = jsonValue.isArray()) != null) {
102
			    								if ((jsonArray = jsonValue.isArray()) != null) {
103
			    									user = ((JSONString) jsonArray.get(0)).stringValue();
103
			    									user = ((JSONString) jsonArray.get(0)).stringValue(); // Identifiant utilisateur : identifant de session
104
			    									mediator.setConnected(((JSONBoolean) jsonArray.get(1)).booleanValue());
104
			    									mediator.setConnected(((JSONBoolean) jsonArray.get(1)).booleanValue());
105
			    								}
105
			    								}
106
 
106
 
107
			    								if (!mediator.getConnected()) {
107
			    								if (!mediator.getConnected()) { // La deconnexion a ete accepte :
108
			    									mediator.onLogoff(user);
108
			    									mediator.onLogoff(user);
109
			    								}
109
			    								}
110
			    						}
110
			    						}
111
			    			});
111
			    			});
112
 
112
 
113
		    				
113
		    				
114
		    			}
114
		    			}
115
	
115
	
116
		    		}
116
		    		}
117
		     	}
117
		     	}
118
	);		
118
	);		
119
 
119
 
120
    initWidget(outer);
120
    initWidget(outer);
121
    
121
    
122
  }
122
  }
123
 
123
 
124
public Label getSignLabel() {
124
public Label getSignLabel() {
125
	return signLabel;
125
	return signLabel;
126
}
126
}
127
 
127
 
128
  
128
  
129
 
129
 
130
  
130
  
131
}
131
}
-
 
132
 
-
 
133
 
-
 
134
/* +--Fin du code ---------------------------------------------------------------------------------------+
-
 
135
* $Log$
-
 
136
* 
-
 
137
*/