]>
git.argeo.org Git - lgpl/argeo-commons.git/blob - cms/ui/util/UserMenuLink.java
1 package org
.argeo
.cms
.ui
.util
;
5 import org
.argeo
.cms
.CmsMsg
;
6 import org
.argeo
.cms
.auth
.CurrentUser
;
7 import org
.argeo
.cms
.swt
.CmsStyles
;
8 import org
.argeo
.cms
.swt
.auth
.CmsLoginShell
;
9 import org
.eclipse
.swt
.events
.DisposeEvent
;
10 import org
.eclipse
.swt
.events
.DisposeListener
;
11 import org
.eclipse
.swt
.events
.MouseEvent
;
12 import org
.eclipse
.swt
.events
.MouseListener
;
13 import org
.eclipse
.swt
.widgets
.Composite
;
14 import org
.eclipse
.swt
.widgets
.Control
;
15 import org
.eclipse
.swt
.widgets
.Label
;
17 /** Open the user menu when clicked */
18 public class UserMenuLink
extends MenuLink
{
20 public UserMenuLink() {
21 setCustom(CmsStyles
.CMS_USER_MENU_LINK
);
25 public Control
createUi(Composite parent
, Node context
) {
26 if (CurrentUser
.isAnonymous())
27 setLabel(CmsMsg
.login
.lead());
29 setLabel(CurrentUser
.getDisplayName());
31 Label link
= (Label
) ((Composite
) super.createUi(parent
, context
)).getChildren()[0];
32 link
.addMouseListener(new UserMenuLinkController(context
));
33 return link
.getParent();
36 protected CmsLoginShell
createUserMenu(Control source
, Node context
) {
37 return new UserMenu(source
.getParent(), context
);
40 private class UserMenuLinkController
implements MouseListener
, DisposeListener
{
41 private static final long serialVersionUID
= 3634864186295639792L;
43 private CmsLoginShell userMenu
= null;
44 private long lastDisposeTS
= 0l;
46 private final Node context
;
48 public UserMenuLinkController(Node context
) {
49 this.context
= context
;
56 public void mouseDown(MouseEvent e
) {
58 Control source
= (Control
) e
.getSource();
59 if (userMenu
== null) {
60 long durationSinceLastDispose
= System
.currentTimeMillis() - lastDisposeTS
;
61 // avoid to reopen the menu, if one has clicked gain
62 if (durationSinceLastDispose
> 200) {
63 userMenu
= createUserMenu(source
, context
);
64 userMenu
.getShell().addDisposeListener(this);
71 public void mouseDoubleClick(MouseEvent e
) {
75 public void mouseUp(MouseEvent e
) {
79 public void widgetDisposed(DisposeEvent event
) {
81 lastDisposeTS
= System
.currentTimeMillis();