comparison flys-client/src/main/java/de/intevation/flys/client/client/ui/MainMenu.java @ 2:bc5d4d2297b9

Introduced a service that retrieves the user who is currently logged in. This user is displayed in the menu bar. flys-client/trunk@1309 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Thu, 10 Feb 2011 08:57:34 +0000
parents 0e22a19852e7
children e2b3966b40ca
comparison
equal deleted inserted replaced
1:0e22a19852e7 2:bc5d4d2297b9
2 2
3 import com.google.gwt.core.client.GWT; 3 import com.google.gwt.core.client.GWT;
4 4
5 import com.smartgwt.client.widgets.Label; 5 import com.smartgwt.client.widgets.Label;
6 import com.smartgwt.client.widgets.layout.HLayout; 6 import com.smartgwt.client.widgets.layout.HLayout;
7
8 import de.intevation.artifacts.common.model.User;
7 9
8 import de.intevation.flys.client.client.FLYSMessages; 10 import de.intevation.flys.client.client.FLYSMessages;
9 11
10 12
11 /** 13 /**
14 public class MainMenu extends HLayout { 16 public class MainMenu extends HLayout {
15 17
16 /** The interface that provides i18n messages. */ 18 /** The interface that provides i18n messages. */
17 private FLYSMessages messages = GWT.create(FLYSMessages.class); 19 private FLYSMessages messages = GWT.create(FLYSMessages.class);
18 20
21 /** The user that is currently logged in. */
22 protected User currentUser;
23
24 /** The label that displays the current logged in user. */
25 protected Label userText;
26
27 /** The label that displays the title of the application. */
28 protected Label titleText;
29
19 /** 30 /**
20 * The default constructor for creating a new MainMenu. 31 * The default constructor for creating a new MainMenu.
21 */ 32 */
22 public MainMenu() { 33 public MainMenu() {
34 userText = new Label(messages.user(messages.guest()));
35 titleText = new Label(messages.title());
36
23 init(); 37 init();
24 } 38 }
25 39
26 40
41 /**
42 * This method is called by the constructor after creating the necessary
43 * components. It initializes layout specific stuff like width, height,
44 * colors and so on and appends the components.
45 */
27 protected void init() { 46 protected void init() {
28 setWidth("100%"); 47 setWidth("100%");
29 setHeight("50"); 48 setHeight("50");
30
31 setBorder("1px solid #808080"); 49 setBorder("1px solid #808080");
32 setBackgroundColor("#C3D9FF"); 50 setBackgroundColor("#C3D9FF");
33 51
34 addMember(new Label(messages.title())); 52 titleText.setWidth("60%");
35 addMember(new Label(messages.greeting("GAST"))); 53
54 addMember(titleText);
55 addMember(userText);
56 }
57
58
59 /**
60 * Set the current {@link User} and call {@link updateCurrentUser()}
61 * afterwards.
62 *
63 * @param user the new user.
64 */
65 public void setCurrentUser(User currentUser) {
66 this.currentUser = currentUser;
67
68 updateCurrentUser();
69 }
70
71
72 /**
73 * Update the text field that shows the current user. If no user is
74 * currently logged in, the text will display {@link FLYSMessages.guest()}.
75 */
76 public void updateCurrentUser() {
77 String name = currentUser != null
78 ? currentUser.getLastName() + ", " + currentUser.getFirstName()
79 : messages.guest();
80
81 GWT.log("Update the current user: " + name);
82 userText.setContents(messages.user(name));
36 } 83 }
37 } 84 }
38 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : 85 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org