import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ShellAdapter;
import org.eclipse.swt.events.ShellEvent;
-import org.eclipse.swt.graphics.Point;
-import org.eclipse.swt.graphics.Rectangle;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
public UserMenu(Control source, boolean autoclose) {
super(CmsUtils.getCmsView());
- shell = new Shell(source.getDisplay(), SWT.NO_TRIM | SWT.BORDER
- | SWT.ON_TOP);
+ if (source != null) {
+ shell = new Shell(Display.getCurrent(), SWT.NO_TRIM | SWT.BORDER
+ | SWT.ON_TOP);
+ } else {
+ shell = new Shell(Display.getCurrent(), SWT.NO_TRIM);
+ shell.setMaximized(true);
+ shell.setLayout(CmsUtils.noSpaceGridLayout());
+ }
shell.setData(RWT.CUSTOM_VARIANT, CMS_USER_MENU);
if (isAnonymous()) {
userUi(shell);
}
- shell.pack();
- shell.layout();
- if (autoclose)// popup
+ if (source != null) {// popup
+ shell.pack();
+ shell.layout();
shell.setLocation(source.toDisplay(
source.getSize().x - shell.getSize().x, source.getSize().y));
- else // centered
- {
- Rectangle shellBounds = Display.getCurrent().getBounds();// RAP
- Point dialogSize = shell.getSize();
- int x = shellBounds.x + (shellBounds.width - dialogSize.x) / 2;
- int y = shellBounds.y + (shellBounds.height - dialogSize.y) / 2;
- shell.setLocation(x, y);
-
+ } else { // centered
+ Composite parent = getCredentialsBlock();
+ parent.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, true,
+ true));
+ // Rectangle shellBounds = shell.getBounds();// RAP
+ // Point dialogSize = parent.getSize();
+ // int x = shellBounds.x + (shellBounds.width - dialogSize.x) / 2;
+ // int y = shellBounds.y + (shellBounds.height - dialogSize.y) / 2;
+ // parent.setLocation(x, y);
}
if (autoclose)
shell.addShellListener(new ShellAdapter() {
public class CmsLogin implements CmsStyles, CallbackHandler {
private Text username, password;
+ private Composite credentialsBlock;
+
private final CmsView cmsView;
public CmsLogin(CmsView cmsView) {
return CurrentUser.isAnonymous(cmsView.getSubject());
}
+ protected Composite getCredentialsBlock() {
+ return credentialsBlock;
+ }
+
protected void userUi(Composite parent) {
parent.setLayout(CmsUtils.noSpaceGridLayout());
- Composite c = new Composite(parent, SWT.NONE);
- c.setLayout(new GridLayout());
- c.setLayoutData(CmsUtils.fillAll());
+ credentialsBlock = new Composite(parent, SWT.NONE);
+ credentialsBlock.setLayout(new GridLayout());
+ credentialsBlock.setLayoutData(CmsUtils.fillAll());
- specificUserUi(c);
+ specificUserUi(credentialsBlock);
- Label l = new Label(c, SWT.NONE);
+ Label l = new Label(credentialsBlock, SWT.NONE);
l.setData(RWT.CUSTOM_VARIANT, CMS_USER_MENU_ITEM);
l.setText(CmsMsg.logout.lead());
GridData lData = CmsUtils.fillWidth();
parent.setLayout(CmsUtils.noSpaceGridLayout());
// We need a composite for the traversal
- Composite c = new Composite(parent, SWT.NONE);
- c.setLayout(new GridLayout());
- c.setLayoutData(CmsUtils.fillAll());
+ credentialsBlock = new Composite(parent, SWT.NONE);
+ credentialsBlock.setLayout(new GridLayout());
+ credentialsBlock.setLayoutData(CmsUtils.fillAll());
Integer textWidth = 120;
parent.setData(RWT.CUSTOM_VARIANT, CMS_USER_MENU);
// new Label(this, SWT.NONE).setText(CmsMsg.username.lead());
- username = new Text(c, SWT.BORDER);
+ username = new Text(credentialsBlock, SWT.BORDER);
username.setMessage(CmsMsg.username.lead());
username.setData(RWT.CUSTOM_VARIANT, CMS_LOGIN_DIALOG_USERNAME);
GridData gd = CmsUtils.fillWidth();
username.setLayoutData(gd);
// new Label(this, SWT.NONE).setText(CmsMsg.password.lead());
- password = new Text(c, SWT.BORDER | SWT.PASSWORD);
+ password = new Text(credentialsBlock, SWT.BORDER | SWT.PASSWORD);
password.setMessage(CmsMsg.password.lead());
password.setData(RWT.CUSTOM_VARIANT, CMS_LOGIN_DIALOG_PASSWORD);
gd = CmsUtils.fillWidth();
login();
}
};
- c.addTraverseListener(tl);
+ credentialsBlock.addTraverseListener(tl);
username.addTraverseListener(tl);
password.addTraverseListener(tl);
- parent.setTabList(new Control[] { c });
- c.setTabList(new Control[] { username, password });
- c.setFocus();
+ parent.setTabList(new Control[] { credentialsBlock });
+ credentialsBlock.setTabList(new Control[] { username, password });
+ credentialsBlock.setFocus();
}
protected void login() {
import org.argeo.security.ui.login.WorkbenchLogin;
import org.eclipse.rap.rwt.RWT;
+import org.eclipse.rap.rwt.client.service.JavaScriptExecutor;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.PlatformUI;
protected HttpServletRequest getRequest() {
return RWT.getRequest();
}
+
+ @Override
+ public int createUI() {
+ JavaScriptExecutor jsExecutor = RWT.getClient().getService(
+ JavaScriptExecutor.class);
+ int returnCode = super.createUI();
+ jsExecutor.execute("location.reload()");
+ return returnCode;
+ }
+
}
import org.argeo.cms.auth.CurrentUser;
import org.argeo.cms.auth.HttpRequestCallbackHandler;
import org.argeo.cms.util.UserMenu;
+import org.argeo.cms.widgets.auth.CmsLogin;
import org.argeo.eclipse.ui.specific.UiContext;
import org.eclipse.rap.rwt.application.EntryPoint;
import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.PlatformUI;
subject, new HttpRequestCallbackHandler(getRequest()));
loginContext.login();
} catch (CredentialNotFoundException e) {
- Shell shell = new Shell(display, SWT.NO_TRIM);
- shell.setMaximized(true);
- //shell.setBackground(display.getSystemColor(SWT.COLOR_CYAN));
- UserMenu userMenu = new UserMenu(shell, false);
- shell.open();
+ // Shell shell = new Shell(display, SWT.NO_TRIM);
+ // shell.setMaximized(true);
+ // shell.setBackground(display.getSystemColor(SWT.COLOR_CYAN));
+ UserMenu userMenu = new UserMenu(null, false);
+ // shell.open();
while (!userMenu.getShell().isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
return new Integer(result);
}
});
+ // explicit workbench closing
+ logout();
} finally {
display.dispose();
}
- // explicit workbench closing
- logout();
return returnCode;
}
protected abstract int createAndRunWorkbench(Display display,
String username);
- // private void fullLogout() {
- // String username = CurrentUser.getUsername(subject);
- // try {
- // LoginContext loginContext = new LoginContext(
- // AuthConstants.LOGIN_CONTEXT_USER, subject);
- // loginContext.logout();
- // HttpServletRequest httpRequest = getRequest();
- // httpRequest.setAttribute(HttpContext.AUTHORIZATION, null);
- // HttpSession httpSession = httpRequest.getSession();
- // httpSession.setAttribute(HttpContext.AUTHORIZATION, null);
- // httpSession.setMaxInactiveInterval(1);
- // log.info("Logged out " + (username != null ? username : "")
- // + " (THREAD=" + Thread.currentThread().getId() + ")");
- // } catch (LoginException e) {
- // log.error("Error when logging out", e);
- // }
- // }
-
protected HttpServletRequest getRequest() {
return UiContext.getHttpRequest();
}
return null;
}
+ // private class WorbenchCmsLogin extends CmsLogin {
+ // private final Shell shell;
+ //
+ // public WorbenchCmsLogin(CmsView cmsView, Shell shell) {
+ // super(cmsView);
+ // this.shell = shell;
+ // shell
+ // Composite parent = new Composite(shell, SWT.NONE);
+ // anonymousUi(parent);
+ // }
+ //
+ // }
}