View Javadoc
1   package org.argeo.connect.ui.util;
2   
3   import javax.jcr.Node;
4   
5   import org.argeo.cms.util.CmsUtils;
6   import org.argeo.cms.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.graphics.Point;
11  import org.eclipse.swt.graphics.Rectangle;
12  import org.eclipse.swt.layout.GridLayout;
13  import org.eclipse.swt.widgets.Control;
14  import org.eclipse.swt.widgets.Display;
15  import org.eclipse.swt.widgets.Shell;
16  
17  public class ConnectLoginShell extends CmsLoginShell {
18  	private final Node context;
19  
20  	public ConnectLoginShell(Control source, Node context) {
21  		super(CmsUtils.getCmsView());
22  		this.context = context;
23  		createUi();
24  		open();
25  	}
26  
27  	@Override
28  	protected Shell createShell() {
29  		Shell backgroundShell = new Shell(getDisplay(), SWT.NO_TRIM | SWT.BORDER | SWT.ON_TOP);
30  		backgroundShell.setMaximized(true);
31  		backgroundShell.setAlpha(128);
32  		backgroundShell.setBackground(getDisplay().getSystemColor(SWT.COLOR_BLACK));
33  		Shell shell = new Shell(backgroundShell, SWT.NO_TRIM | SWT.BORDER | SWT.ON_TOP);
34  		shell.setLayout(new GridLayout());
35  		shell.setSize(getInitialSize());
36  
37  		Rectangle shellBounds = Display.getCurrent().getBounds();// RAP
38  		Point dialogSize = shell.getSize();
39  		int x = shellBounds.x + (shellBounds.width - dialogSize.x) / 2;
40  		int y = shellBounds.y + (shellBounds.height - dialogSize.y) / 2;
41  		shell.setLocation(x, y);
42  
43  		shell.addShellListener(new ShellAdapter() {
44  			private static final long serialVersionUID = -2701270481953688763L;
45  
46  			@Override
47  			public void shellDeactivated(ShellEvent e) {
48  				closeShell();
49  			}
50  		});
51  		return shell;
52  	}
53  
54  	protected Point getInitialSize() {
55  		return new Point(400, 400);
56  	}
57  
58  	protected Shell getBackgroundShell() {
59  		if (getShell().getParent() instanceof Shell)
60  			return (Shell) getShell().getParent();
61  		else
62  			return null;
63  	}
64  
65  	@Override
66  	public void open() {
67  		Shell backgroundShell = getBackgroundShell();
68  		if (backgroundShell != null && !backgroundShell.isDisposed()) {
69  			backgroundShell.open();
70  		}
71  		super.open();
72  	}
73  
74  	protected void closeShell() {
75  		Shell backgroundShell = getBackgroundShell();
76  		if (backgroundShell != null && !backgroundShell.isDisposed()) {
77  			backgroundShell.close();
78  			backgroundShell.dispose();
79  		}
80  
81  		super.closeShell();
82  	}
83  
84  	private Display getDisplay() {
85  		try {
86  			Display display = Display.getCurrent();
87  			if (display != null)
88  				return display;
89  			else
90  				return Display.getDefault();
91  		} catch (Exception e) {
92  			return Display.getCurrent();
93  		}
94  	}
95  
96  
97  	protected Node getContext() {
98  		return context;
99  	}
100 
101 
102 }