public final static String CMS_HEADER_LEAD = "cms_header-lead";
public final static String CMS_HEADER_CENTER = "cms_header-center";
public final static String CMS_HEADER_END = "cms_header-end";
- public final static String CMS_LOGIN = "cms_login";
+ public final static String CMS_USER_MENU = "cms_user_menu";
+ public final static String CMS_USER_MENU_LINK = "cms_user_menu-link";
+ public final static String CMS_USER_MENU_ITEM = "cms_user_menu-item";
public final static String CMS_LOGIN_DIALOG = "cms_login_dialog";
public final static String CMS_LOGIN_DIALOG_USERNAME = "cms_login_dialog-username";
public final static String CMS_LOGIN_DIALOG_PASSWORD = "cms_login_dialog-password";
- public final static String CMS_USER_MENU = "cms_user_menu";
- public final static String CMS_USER_MENU_ITEM = "cms_user_menu-item";
// Body
public final static String CMS_SCROLLED_AREA = "cms_scrolled_area";
private int verticalAlignment = SWT.CENTER;
// internal
- //private Boolean isUrl = false;
+ // private Boolean isUrl = false;
private Integer imageWidth, imageHeight;
private BundleContext bundleContext;
@Override
public void afterPropertiesSet() {
-// if (target != null) {
-// if (target.startsWith("/")) {
-// isUrl = true;
-// } else {
-// try {
-// new URL(target);
-// isUrl = true;
-// } catch (MalformedURLException e1) {
-// isUrl = false;
-// }
-// }
-// }
+ // if (target != null) {
+ // if (target.startsWith("/")) {
+ // isUrl = true;
+ // } else {
+ // try {
+ // new URL(target);
+ // isUrl = true;
+ // } catch (MalformedURLException e1) {
+ // isUrl = false;
+ // }
+ // }
+ // }
if (image != null) {
ImageData image = loadImage();
}
}
+ /** @return {@link Composite} with a single {@link Label} child. */
@Override
public Control createUi(final Composite parent, Node context) {
Composite comp = new Composite(parent, SWT.BOTTOM);
if (target != null) {
labelText
.append("<a style='color:inherit;text-decoration:inherit;' href=\"");
-// if (!isUrl)
-// labelText.append('#');
+ // if (!isUrl)
+ // labelText.append('#');
labelText.append(target);
labelText.append("\">");
}
}
protected void userUi() {
- setLayout(new GridLayout());
-
- String username = SecurityContextHolder.getContext()
- .getAuthentication().getName();
+ setLayout(CmsUtils.noSpaceGridLayout());
+ Composite c = new Composite(this, SWT.NONE);
+ c.setLayout(new GridLayout());
+ c.setLayoutData(CmsUtils.fillAll());
- Label l = new Label(this, SWT.NONE);
- l.setData(RWT.CUSTOM_VARIANT, CMS_USER_MENU_ITEM);
- l.setData(RWT.MARKUP_ENABLED, true);
- l.setLayoutData(CmsUtils.fillWidth());
- l.setText("<b>" + username + "</b>");
+ // String username = SecurityContextHolder.getContext()
+ // .getAuthentication().getName();
+ //
+ // Label l = new Label(c, SWT.NONE);
+ // l.setData(RWT.CUSTOM_VARIANT, CMS_USER_MENU_ITEM);
+ // l.setData(RWT.MARKUP_ENABLED, true);
+ // l.setLayoutData(CmsUtils.fillWidth());
+ // l.setText("<b>" + username + "</b>");
- specificUserUi(this);
+ specificUserUi(c);
- l = new Label(this, SWT.NONE);
+ Label l = new Label(c, SWT.NONE);
l.setData(RWT.CUSTOM_VARIANT, CMS_USER_MENU_ITEM);
l.setText(CmsMsg.logout.lead());
GridData lData = CmsUtils.fillWidth();
c.setLayout(new GridLayout());
c.setLayoutData(CmsUtils.fillAll());
- Integer textWidth = 150;
+ Integer textWidth = 120;
setData(RWT.CUSTOM_VARIANT, CMS_USER_MENU);
// new Label(this, SWT.NONE).setText(CmsMsg.username.lead());
--- /dev/null
+package org.argeo.cms.util;
+
+import javax.jcr.Node;
+
+import org.argeo.cms.CmsMsg;
+import org.argeo.cms.CmsStyles;
+import org.argeo.cms.KernelHeader;
+import org.eclipse.swt.events.DisposeEvent;
+import org.eclipse.swt.events.DisposeListener;
+import org.eclipse.swt.events.MouseEvent;
+import org.eclipse.swt.events.MouseListener;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Label;
+import org.springframework.security.core.context.SecurityContextHolder;
+
+/** Open the user menu when clicked */
+public class UserMenuLink extends MenuLink {
+
+ public UserMenuLink() {
+ setCustom(CmsStyles.CMS_USER_MENU_LINK);
+ }
+
+ @Override
+ public Control createUi(Composite parent, Node context) {
+ String username = SecurityContextHolder.getContext()
+ .getAuthentication().getName();
+ if (username.equals(KernelHeader.USERNAME_ANONYMOUS))
+ setLabel(CmsMsg.login.lead());
+ else
+ setLabel(username);
+ Label link = (Label) ((Composite) super.createUi(parent, context))
+ .getChildren()[0];
+ link.addMouseListener(new UserMenuLinkController());
+ return link.getParent();
+ }
+
+ protected UserMenu createUserMenu(Control source) {
+ return new UserMenu(source.getParent());
+ }
+
+ private class UserMenuLinkController implements MouseListener,
+ DisposeListener {
+ private static final long serialVersionUID = 3634864186295639792L;
+
+ private UserMenu userMenu = null;
+ private long lastDisposeTS = 0l;
+
+ //
+ // MOUSE LISTENER
+ //
+ @Override
+ public void mouseDown(MouseEvent e) {
+ if (e.button == 1) {
+ Control source = (Control) e.getSource();
+ if (userMenu == null) {
+ long durationSinceLastDispose = System.currentTimeMillis()
+ - lastDisposeTS;
+ // avoid to reopen the menu, if one has clicked gain
+ if (durationSinceLastDispose > 200) {
+ userMenu = createUserMenu(source);
+ userMenu.addDisposeListener(this);
+ }
+ }
+ }
+ }
+
+ @Override
+ public void mouseDoubleClick(MouseEvent e) {
+ }
+
+ @Override
+ public void mouseUp(MouseEvent e) {
+ }
+
+ @Override
+ public void widgetDisposed(DisposeEvent event) {
+ userMenu = null;
+ lastDisposeTS = System.currentTimeMillis();
+ }
+ }
+}
\ No newline at end of file