3 import org
.eclipse
.rap
.rwt
.RWT
;
4 import org
.eclipse
.swt
.SWT
;
5 import org
.eclipse
.swt
.events
.MouseAdapter
;
6 import org
.eclipse
.swt
.events
.MouseEvent
;
7 import org
.eclipse
.swt
.events
.ShellAdapter
;
8 import org
.eclipse
.swt
.events
.ShellEvent
;
9 import org
.eclipse
.swt
.events
.TraverseEvent
;
10 import org
.eclipse
.swt
.events
.TraverseListener
;
11 import org
.eclipse
.swt
.layout
.GridData
;
12 import org
.eclipse
.swt
.layout
.GridLayout
;
13 import org
.eclipse
.swt
.widgets
.Control
;
14 import org
.eclipse
.swt
.widgets
.Label
;
15 import org
.eclipse
.swt
.widgets
.Shell
;
16 import org
.eclipse
.swt
.widgets
.Text
;
17 import org
.springframework
.security
.context
.SecurityContextHolder
;
19 /** The site-related user menu */
20 public class UserMenu
extends Shell
implements CmsStyles
{
21 private static final long serialVersionUID
= -5788157651532106301L;
23 private CmsLogin cmsLogin
;
24 private String username
= null;
26 public UserMenu(CmsLogin cmsLogin
, Control source
) {
27 super(source
.getDisplay(), SWT
.NO_TRIM
| SWT
.BORDER
| SWT
.ON_TOP
);
28 this.cmsLogin
= cmsLogin
;
30 setData(RWT
.CUSTOM_VARIANT
, CMS_USER_MENU
);
32 username
= SecurityContextHolder
.getContext().getAuthentication()
34 if (username
.equals("anonymous")) {
43 setLocation(source
.toDisplay(source
.getSize().x
- getSize().x
,
46 addShellListener(new ShellAdapter() {
47 private static final long serialVersionUID
= 5178980294808435833L;
50 public void shellDeactivated(ShellEvent e
) {
61 protected void userUi() {
62 setLayout(new GridLayout());
64 Label l
= new Label(this, SWT
.NONE
);
65 l
.setData(RWT
.CUSTOM_VARIANT
, CMS_USER_MENU_ITEM
);
66 l
.setData(RWT
.MARKUP_ENABLED
, true);
67 l
.setLayoutData(CmsUtils
.fillWidth());
68 l
.setText("<b>" + username
+ "</b>");
70 final CmsSession cmsSession
= (CmsSession
) getDisplay().getData(
72 l
= new Label(this, SWT
.NONE
);
73 l
.setData(RWT
.CUSTOM_VARIANT
, CMS_USER_MENU_ITEM
);
74 l
.setText(CmsMsg
.logout
.lead());
75 GridData lData
= CmsUtils
.fillWidth();
76 lData
.widthHint
= 120;
77 l
.setLayoutData(lData
);
79 l
.addMouseListener(new MouseAdapter() {
80 private static final long serialVersionUID
= 6444395812777413116L;
82 public void mouseDown(MouseEvent e
) {
83 SecurityContextHolder
.getContext().setAuthentication(null);
86 cmsSession
.authChange();
91 protected void anonymousUi() {
92 Integer textWidth
= 150;
93 setData(RWT
.CUSTOM_VARIANT
, CMS_USER_MENU
);
94 setLayout(new GridLayout(2, false));
96 new Label(this, SWT
.NONE
).setText(CmsMsg
.username
.lead());
97 final Text username
= new Text(this, SWT
.BORDER
);
98 username
.setData(RWT
.CUSTOM_VARIANT
, CMS_LOGIN_DIALOG_USERNAME
);
99 GridData gd
= CmsUtils
.fillWidth();
100 gd
.widthHint
= textWidth
;
101 username
.setLayoutData(gd
);
103 new Label(this, SWT
.NONE
).setText(CmsMsg
.password
.lead());
104 final Text password
= new Text(this, SWT
.BORDER
| SWT
.PASSWORD
);
105 password
.setData(RWT
.CUSTOM_VARIANT
, CMS_LOGIN_DIALOG_PASSWORD
);
106 gd
= CmsUtils
.fillWidth();
107 gd
.widthHint
= textWidth
;
108 password
.setLayoutData(gd
);
111 TraverseListener tl
= new TraverseListener() {
112 private static final long serialVersionUID
= -1158892811534971856L;
114 public void keyTraversed(TraverseEvent e
) {
115 if (e
.detail
== SWT
.TRAVERSE_RETURN
)
116 login(username
.getText(), password
.getTextChars());
119 username
.addTraverseListener(tl
);
120 password
.addTraverseListener(tl
);
123 protected void login(String username
, char[] password
) {
124 CmsSession cmsSession
= (CmsSession
) getDisplay().getData(
126 cmsLogin
.logInWithPassword(username
, password
);
129 // refreshUi(source.getParent());
130 cmsSession
.authChange();