]> git.argeo.org Git - lgpl/argeo-commons.git/blob - UserMenu.java
a654dddd4054f7aa27b318352afe65d892a0ec29
[lgpl/argeo-commons.git] / UserMenu.java
1 package org.argeo.cms.util;
2
3 import org.argeo.cms.CmsException;
4 import org.argeo.cms.widgets.auth.CmsLoginShell;
5 import org.eclipse.swt.SWT;
6 import org.eclipse.swt.events.ShellAdapter;
7 import org.eclipse.swt.events.ShellEvent;
8 import org.eclipse.swt.widgets.Control;
9 import org.eclipse.swt.widgets.Display;
10 import org.eclipse.swt.widgets.Shell;
11
12 /** The site-related user menu */
13 public class UserMenu extends CmsLoginShell {
14 private final Control source;
15
16 public UserMenu(Control source) {
17 super(CmsUtils.getCmsView());
18 if (source == null)
19 throw new CmsException("Source control cannot be null.");
20 this.source = source;
21 open();
22 }
23
24 @Override
25 protected Shell createShell() {
26 return new Shell(Display.getCurrent(), SWT.NO_TRIM | SWT.BORDER
27 | SWT.ON_TOP);
28 }
29
30 @Override
31 public void open() {
32 Shell shell = getShell();
33 shell.pack();
34 shell.layout();
35 shell.setLocation(source.toDisplay(source.getSize().x
36 - shell.getSize().x, source.getSize().y));
37 shell.addShellListener(new ShellAdapter() {
38 private static final long serialVersionUID = 5178980294808435833L;
39
40 @Override
41 public void shellDeactivated(ShellEvent e) {
42 closeShell();
43 }
44 });
45 super.open();
46 }
47
48 }