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