Subversion Repositories eFlore/Archives.cel-v1

Rev

Rev 12 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 ddelon 1
/*
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
6
 * the License at
7
 *
8
 * http://www.apache.org/licenses/LICENSE-2.0
9
 *
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
12
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13
 * License for the specific language governing permissions and limitations under
14
 * the License.
15
 */
16
package org.tela_botanica.client;
17
 
14 ddelon 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;
26
import com.google.gwt.user.client.ui.ClickListener;
2 ddelon 27
import com.google.gwt.user.client.ui.Composite;
28
import com.google.gwt.user.client.ui.HTML;
29
import com.google.gwt.user.client.ui.HorizontalPanel;
14 ddelon 30
import com.google.gwt.user.client.ui.Label;
31
import com.google.gwt.user.client.ui.Widget;
2 ddelon 32
 
33
/**
34
 * Composite permet de wrapper des Widget pour creer un nouveau Widget cf methode initWidget()
35
 */
36
 
14 ddelon 37
 
2 ddelon 38
public class TopPanel extends Composite {
12 ddelon 39
 
11 ddelon 40
 
14 ddelon 41
  private Mediator mediator=null;
42
 
43
  private String user =null;
44
  private Label signLabel = new Label() ;
45
 
46
  private String serviceBaseUrl = null;
12 ddelon 47
 
48
  public TopPanel(final Mediator med) {
14 ddelon 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 {
64
    	signLabel.setText(user+ " (deconnexion)");
65
    }
66
 
67
	HorizontalPanel outer = new HorizontalPanel();
68
	HorizontalPanel inner = new HorizontalPanel();
12 ddelon 69
 
11 ddelon 70
 
71
	outer.setHorizontalAlignment(HorizontalPanel.ALIGN_RIGHT);
72
 
14 ddelon 73
	 inner.add(signLabel);
74
	 inner.add(new HTML("<b>Carnet en ligne</b>"));
75
 
76
	 inner.setSpacing(3);
77
	 outer.add(inner);
11 ddelon 78
 
14 ddelon 79
	 signLabel.addClickListener(
80
		    	new ClickListener() {
81
		    		public void onClick(Widget sender) {
82
 
83
		    			if (!mediator.getConnected()) {
84
		    				LoginDialog loginDialog = new LoginDialog(med);
11 ddelon 85
 
14 ddelon 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() {
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) {
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
 
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
}