]> git.argeo.org Git - lgpl/argeo-commons.git/blob - org.argeo.cms.e4/src/org/argeo/cms/e4/rap/LoginLifcecycle.java
Introduce CMS E4
[lgpl/argeo-commons.git] / org.argeo.cms.e4 / src / org / argeo / cms / e4 / rap / LoginLifcecycle.java
1 package org.argeo.cms.e4.rap;
2
3 import java.util.concurrent.atomic.AtomicBoolean;
4
5 import org.eclipse.e4.ui.workbench.lifecycle.PostContextCreate;
6 import org.eclipse.swt.SWT;
7 import org.eclipse.swt.events.SelectionAdapter;
8 import org.eclipse.swt.events.SelectionEvent;
9 import org.eclipse.swt.graphics.Point;
10 import org.eclipse.swt.graphics.Rectangle;
11 import org.eclipse.swt.layout.GridData;
12 import org.eclipse.swt.layout.GridLayout;
13 import org.eclipse.swt.widgets.Button;
14 import org.eclipse.swt.widgets.Composite;
15 import org.eclipse.swt.widgets.Display;
16 import org.eclipse.swt.widgets.Label;
17 import org.eclipse.swt.widgets.Shell;
18 import org.eclipse.swt.widgets.Text;
19
20 @SuppressWarnings("restriction")
21 public class LoginLifcecycle {
22 @PostContextCreate
23 boolean login(Display d) {
24 final AtomicBoolean rv = new AtomicBoolean(false);
25 final Shell s = new Shell(d);
26 s.setText("Login");
27 s.setLayout(new GridLayout(2, false));
28
29 {
30 Label l = new Label(s, SWT.NONE);
31 l.setText("Username");
32
33 Text t = new Text(s, SWT.BORDER);
34 t.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
35 }
36
37 {
38 Label l = new Label(s, SWT.NONE);
39 l.setText("Password");
40
41 Text t = new Text(s, SWT.BORDER | SWT.PASSWORD);
42 t.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
43 }
44
45 {
46 Composite buttonContainer = new Composite(s, SWT.NONE);
47 buttonContainer.setLayout(new GridLayout(2, true));
48 buttonContainer.setLayoutData(new GridData(SWT.TRAIL, SWT.CENTER, false, false, 2, 1));
49
50 {
51 Button b = new Button(buttonContainer, SWT.PUSH);
52 b.setText("Abort");
53 b.addSelectionListener(new SelectionAdapter() {
54 @Override
55 public void widgetSelected(SelectionEvent e) {
56 rv.set(false);
57 s.dispose();
58 }
59 });
60 }
61
62 {
63 Button b = new Button(buttonContainer, SWT.PUSH);
64 b.setText("Login");
65 b.addSelectionListener(new SelectionAdapter() {
66 @Override
67 public void widgetSelected(SelectionEvent e) {
68 rv.set(true);
69 s.dispose();
70 }
71 });
72 }
73 }
74 s.pack();
75 s.setSize(300, s.getSize().y + 10);
76 Rectangle bounds = d.getPrimaryMonitor().getBounds();
77
78 Point size = s.getSize();
79 s.setLocation(bounds.width / 2 - size.x / 2, bounds.height / 2 - size.y / 2);
80
81 s.open();
82 while (!s.isDisposed() && !d.isDisposed()) {
83 if (!d.readAndDispatch()) {
84 d.sleep();
85 }
86 }
87
88 return rv.get();
89 }
90 }