Subversion Repositories eFlore/Archives.cel-v1

Rev

Rev 12 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 12 Rev 14
Line 13... Line 13...
13
 * License for the specific language governing permissions and limitations under
13
 * License for the specific language governing permissions and limitations under
14
 * the License.
14
 * the License.
15
 */
15
 */
16
package org.tela_botanica.client;
16
package org.tela_botanica.client;
Line -... Line 17...
-
 
17
 
-
 
18
import com.google.gwt.json.client.JSONArray;
-
 
19
import com.google.gwt.json.client.JSONBoolean;
-
 
20
import com.google.gwt.json.client.JSONParser;
-
 
21
import com.google.gwt.json.client.JSONString;
-
 
22
import com.google.gwt.json.client.JSONValue;
-
 
23
import com.google.gwt.user.client.HTTPRequest;
-
 
24
import com.google.gwt.user.client.ResponseTextHandler;
-
 
25
import com.google.gwt.user.client.Window;
17
 
26
import com.google.gwt.user.client.ui.ClickListener;
18
import com.google.gwt.user.client.ui.Composite;
27
import com.google.gwt.user.client.ui.Composite;
19
import com.google.gwt.user.client.ui.HTML;
28
import com.google.gwt.user.client.ui.HTML;
20
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;
Line 21... Line 31...
21
import com.google.gwt.user.client.ui.VerticalPanel;
31
import com.google.gwt.user.client.ui.Widget;
22
 
32
 
23
/**
33
/**
Line -... Line 34...
-
 
34
 * Composite permet de wrapper des Widget pour creer un nouveau Widget cf methode initWidget()
24
 * Composite permet de wrapper des Widget pour creer un nouveau Widget cf methode initWidget()
35
 */
Line -... Line 36...
-
 
36
 
-
 
37
 
-
 
38
public class TopPanel extends Composite {
-
 
39
 
-
 
40
	
-
 
41
  private Mediator mediator=null;
Line 25... Line 42...
25
 */
42
	  
26
 
43
  private String user =null;	
-
 
44
  private Label signLabel = new Label() ;
-
 
45
  
-
 
46
  private String serviceBaseUrl = null;
-
 
47
	
-
 
48
  public TopPanel(final Mediator med) {
-
 
49
 
-
 
50
	mediator=med;
-
 
51
	  
-
 
52
	mediator.registerTopPanel(this);
-
 
53
	  
-
 
54
	user=mediator.getUser();
-
 
55
	
-
 
56
   	signLabel.setStyleName("selection_label");
-
 
57
   	
-
 
58
    serviceBaseUrl = mediator.getServiceBaseUrl();
-
 
59
 
27
public class TopPanel extends Composite {
60
    if (!mediator.getConnected()) {
28
 
61
    	signLabel.setText("Connexion");
-
 
62
    }
Line 29... Line 63...
29
	
63
    else {
Line -... Line 64...
-
 
64
    	signLabel.setText(user+ " (deconnexion)");
30
	
65
    }
-
 
66
 
-
 
67
	HorizontalPanel outer = new HorizontalPanel();
-
 
68
	HorizontalPanel inner = new HorizontalPanel();
Line -... Line 69...
-
 
69
   
-
 
70
    
-
 
71
	outer.setHorizontalAlignment(HorizontalPanel.ALIGN_RIGHT);
-
 
72
 
-
 
73
	 inner.add(signLabel);
-
 
74
	 inner.add(new HTML("<b>Carnet en ligne</b>"));
-
 
75
	 
-
 
76
	 inner.setSpacing(3);
-
 
77
	 outer.add(inner);
-
 
78
 
-
 
79
	 signLabel.addClickListener(
-
 
80
		    	new ClickListener() {
-
 
81
		    		public void onClick(Widget sender) {
-
 
82
		    
-
 
83
		    			if (!mediator.getConnected()) {
-
 
84
		    				LoginDialog loginDialog = new LoginDialog(med);
-
 
85
 
-
 
86
		    				// Position it roughly in the middle of the screen.
-
 
87
		    				int left = (Window.getClientWidth() - 512) / 2;
-
 
88
		    				int top = (Window.getClientHeight() - 256) / 2;
-
 
89
		    				loginDialog.setPopupPosition(left, top);
-
 
90
		    				loginDialog.show();
-
 
91
		    			}
-
 
92
		    			
-
 
93
		    			else {
-
 
94
		    				
-
 
95
			    			HTTPRequest.asyncGet(serviceBaseUrl + "/User/" + user    ,
-
 
96
			    					new ResponseTextHandler() {
-
 
97
 
-
 
98
			    						public void onCompletion(String str) {
-
 
99
			    							
-
 
100
			    								JSONValue jsonValue = JSONParser.parse(str);
-
 
101
			    								JSONArray jsonArray;
Line -... Line 102...
-
 
102
			    								if ((jsonArray = jsonValue.isArray()) != null) {
-
 
103
			    									user = ((JSONString) jsonArray.get(0)).stringValue();
-
 
104
			    									mediator.setConnected(((JSONBoolean) jsonArray.get(1)).booleanValue());
-
 
105
			    								}
-
 
106
 
-
 
107
			    								if (!mediator.getConnected()) {
Line 31... Line 108...
31
  public TopPanel(final Mediator med) {
108
			    									mediator.onLogoff(user);
-
 
109
			    								}
32
	 
110
			    						}
Line -... Line 111...
-
 
111
			    			});
-
 
112
 
-
 
113
		    				
-
 
114
		    			}
-
 
115
	
-
 
116
		    		}
-
 
117
		     	}
33
   
118
	);