View Javadoc
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.ui.widgets.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  		super(CmsUiUtils.getCmsView());
21  		this.context = context;
22  		createUi();
23  		if (source == null)
24  			throw new CmsException("Source control cannot be null.");
25  		this.source = source;
26  		open();
27  	}
28  
29  	@Override
30  	protected Shell createShell() {
31  		return new Shell(Display.getCurrent(), SWT.NO_TRIM | SWT.BORDER | SWT.ON_TOP);
32  	}
33  
34  	@Override
35  	public void open() {
36  		Shell shell = getShell();
37  		shell.pack();
38  		shell.layout();
39  		shell.setLocation(source.toDisplay(source.getSize().x - shell.getSize().x, source.getSize().y));
40  		shell.addShellListener(new ShellAdapter() {
41  			private static final long serialVersionUID = 5178980294808435833L;
42  
43  			@Override
44  			public void shellDeactivated(ShellEvent e) {
45  				closeShell();
46  			}
47  		});
48  		super.open();
49  	}
50  
51  	protected Node getContext() {
52  		return context;
53  	}
54  
55  }