Subversion Repositories eFlore/Archives.cel-v1

Rev

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

Rev 12 Rev 14
1
/*
1
/*
2
 * Copyright 2006 Google Inc.
2
 * Copyright 2006 Google Inc.
3
 * 
3
 * 
4
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
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
5
 * use this file except in compliance with the License. You may obtain a copy of
6
 * the License at
6
 * the License at
7
 * 
7
 * 
8
 * http://www.apache.org/licenses/LICENSE-2.0
8
 * http://www.apache.org/licenses/LICENSE-2.0
9
 * 
9
 * 
10
 * Unless required by applicable law or agreed to in writing, software
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
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;
-
 
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;
21
import com.google.gwt.user.client.ui.VerticalPanel;
30
import com.google.gwt.user.client.ui.Label;
-
 
31
import com.google.gwt.user.client.ui.Widget;
22
 
32
 
23
/**
33
/**
24
 * Composite permet de wrapper des Widget pour creer un nouveau Widget cf methode initWidget()
34
 * Composite permet de wrapper des Widget pour creer un nouveau Widget cf methode initWidget()
25
 */
35
 */
-
 
36
 
26
 
37
 
27
public class TopPanel extends Composite {
38
public class TopPanel extends Composite {
28
 
39
 
-
 
40
	
-
 
41
  private Mediator mediator=null;
-
 
42
	  
-
 
43
  private String user =null;	
-
 
44
  private Label signLabel = new Label() ;
-
 
45
  
29
	
46
  private String serviceBaseUrl = null;
30
	
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
 
-
 
60
    if (!mediator.getConnected()) {
-
 
61
    	signLabel.setText("Connexion");
-
 
62
    }
-
 
63
    else {
31
  public TopPanel(final Mediator med) {
64
    	signLabel.setText(user+ " (deconnexion)");
32
	 
65
    }
-
 
66
 
33
   
67
	HorizontalPanel outer = new HorizontalPanel();
34
   VerticalPanel outer = new VerticalPanel();
68
	HorizontalPanel inner = new HorizontalPanel();
35
   
69
   
36
    
70
    
37
	outer.setHorizontalAlignment(HorizontalPanel.ALIGN_RIGHT);
71
	outer.setHorizontalAlignment(HorizontalPanel.ALIGN_RIGHT);
-
 
72
 
38
 
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;
-
 
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()) {
-
 
108
			    									mediator.onLogoff(user);
-
 
109
			    								}
-
 
110
			    						}
-
 
111
			    			});
-
 
112
 
-
 
113
		    				
-
 
114
		    			}
-
 
115
	
39
	 outer.add(new HTML("<b>Carnet en ligne</b>"));
116
		    		}
-
 
117
		     	}
40
 
118
	);		
-
 
119
 
-
 
120
    initWidget(outer);
-
 
121
    
-
 
122
  }
-
 
123
 
-
 
124
public Label getSignLabel() {
-
 
125
	return signLabel;
41
 
126
}
42
 
127
 
43
    initWidget(outer);
128
  
44
  }
129
 
45
 
130
  
46
}
131
}