Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Made the login dialog as a part of the wizard, instead of having it as

an own dialog.
  • Loading branch information...
commit e6a66b4f6e4a366bf078f64a812af2b93b8ac5b2 1 parent 53f8401
@KlasJoensson authored
View
20 plugins/net.bioclipse.usermanager/src/net/bioclipse/usermanager/LoginWizardPage.java
@@ -1,17 +1,17 @@
package net.bioclipse.usermanager;
import net.bioclipse.usermanager.dialogs.DialogArea;
-
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.widgets.Composite;
+
public class LoginWizardPage extends WizardPage {
-
- private DialogArea loginDialogArea;
+
+ private DialogArea loginDialogArea;
protected LoginWizardPage(String pageName, UserContainer userContainer) {
super(pageName);
- this.loginDialogArea = new DialogArea(userContainer ,true);
+ this.loginDialogArea = new DialogArea(userContainer ,true, this);
}
@Override
@@ -23,7 +23,17 @@ public void createControl(Composite parent) {
@Override
public boolean isPageComplete() {
- return loginDialogArea.getErrorFlag();
+ return !loginDialogArea.getErrorFlag();
+ }
+
+ public String getUsername() {
+ return loginDialogArea.getUsername();
+ }
+
+ public String getPassword() {
+ return loginDialogArea.getPassword();
+
}
}
+
View
182 plugins/net.bioclipse.usermanager/src/net/bioclipse/usermanager/NewAccountWizard.java
@@ -10,17 +10,27 @@
******************************************************************************/
package net.bioclipse.usermanager;
+import net.bioclipse.core.util.LogUtils;
import net.bioclipse.usermanager.business.IUserManager;
import net.bioclipse.usermanager.dialogs.CreateUserDialog;
import net.bioclipse.usermanager.dialogs.LoginDialog;
+import org.apache.log4j.Logger;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.SubProgressMonitor;
+import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.window.Window;
import org.eclipse.jface.wizard.Wizard;
+import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.INewWizard;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.handlers.IHandlerService;
/**
* A wizard for handling the users third parts accounts
@@ -30,75 +40,141 @@
*/
public class NewAccountWizard extends Wizard implements INewWizard {
- private NewAccountWizardPage mainPage;
+ private static final Logger logger
+ = Logger.getLogger(LoginDialog.class);
+
+ private NewAccountWizardPage addAccountPage;
+ private LoginWizardPage loginPage;
public NewAccountWizard() {
- boolean cancel = false;
- IUserManager usermanager = Activator.getDefault().getUserManager();
- if (usermanager.getUserNames().size() == 0) {
- UserContainer sandbox = usermanager.getSandBoxUserContainer();
- CreateUserDialog dialog
- = new CreateUserDialog( PlatformUI.getWorkbench()
- .getActiveWorkbenchWindow()
- .getShell(), sandbox );
- dialog.open();
- if (dialog.getReturnCode() == dialog.OK) {
- usermanager.switchUserContainer( sandbox );
- }
- else if (dialog.getReturnCode() == dialog.CANCEL) {
- cancel = true;
- }
- }
-
- if ( !cancel && !usermanager.isLoggedIn() ) {
- UserContainer sandbox = usermanager.getSandBoxUserContainer();
- LoginDialog loginDialog
- = new LoginDialog( PlatformUI.getWorkbench()
- .getActiveWorkbenchWindow()
- .getShell(),
- sandbox );
-
- loginDialog.open();
- if ( loginDialog.getReturnCode() == LoginDialog.OK ) {
- if ( loginDialog.isUserContainerEdited() ) {
- Activator.getDefault().getUserManager()
- .switchUserContainer(sandbox);
- }
- }
- }
+// boolean cancel = false;
+ IUserManager usermanager = Activator.getDefault().getUserManager();
+ if (usermanager.getUserNames().size() == 0) {
+ UserContainer sandbox = usermanager.getSandBoxUserContainer();
+ CreateUserDialog dialog
+ = new CreateUserDialog( PlatformUI.getWorkbench()
+ .getActiveWorkbenchWindow()
+ .getShell(), sandbox );
+ dialog.open();
+ if (dialog.getReturnCode() == Window.OK) {
+ usermanager.switchUserContainer( sandbox );
+ }
+ else if (dialog.getReturnCode() == Window.CANCEL) {
+ dispose();
+ }
+ }
}
@Override
public void init(IWorkbench workbench, IStructuredSelection selection) {
- setWindowTitle("Add an account to Bioclipse");
- setNeedsProgressMonitor(true);
+ setWindowTitle("Add an account to Bioclipse");
+ setNeedsProgressMonitor(true);
}
-
- public void addPages() {
- super.addPages();
- // TODO add the Bioclipse create-account and log-in dialogs as pages
- // are the any more to be added?
- mainPage = new NewAccountWizardPage("mainPage");
- mainPage.setTitle("New Account");
- mainPage.setDescription("Add a third-part account to Bioclipse");
- addPage(mainPage);
- setDefaultPageImageDescriptor(ImageDescriptor
- .createFromFile(this.getClass(),
- "BioclipseAccountLogo3_medium.png"));
- }
-
+
+ public void addPages() {
+ super.addPages();
+ IUserManager usermanager = Activator.getDefault().getUserManager();
+ if ( !usermanager.isLoggedIn() ) {
+ UserContainer sandbox = usermanager.getSandBoxUserContainer();
+ loginPage = new LoginWizardPage("loginPage", sandbox);
+ loginPage.setTitle("Log In To Your Bioclipse Account");
+ loginPage.setDescription("Before adding an acount you have to " +
+ "loggin or create a new acount.");
+ addPage(loginPage);
+ }
+
+ addAccountPage = new NewAccountWizardPage("addAccountPage");
+ addAccountPage.setTitle("New Account");
+ addAccountPage.setDescription("Add a third-part account to Bioclipse");
+ addPage(addAccountPage);
+
+
+ setDefaultPageImageDescriptor(ImageDescriptor
+ .createFromFile(this.getClass(),
+ "BioclipseAccountLogo3_medium.png"));
+ }
+
@Override
public boolean performFinish() {
- if (mainPage.createAccount()) {
+ IUserManager usermanager = Activator.getDefault().getUserManager();
+ if ( !usermanager.isLoggedIn() ) {
+ performLogin();
+ }
+
+ if (addAccountPage.createAccount()) {
dispose();
return true;
} else
return false;
}
-
+
@Override
public boolean canFinish() {
- return mainPage.isPageComplete();
+ return addAccountPage.isPageComplete();
}
+ public boolean performCancel() {
+ return true;
+ }
+
+ private void performLogin() {
+ final String username = loginPage.getUsername();
+ final String password = loginPage.getPassword();
+ Job job = new Job("Signing in " + username) {
+
+ @Override
+ protected IStatus run( IProgressMonitor monitor ) {
+
+ try {
+ int scale = 1000;
+ monitor.beginTask( "Signing in...",
+ IProgressMonitor.UNKNOWN );
+ Activator.getDefault().getUserManager()
+ .signInWithProgressBar(
+ username,
+ password,
+ new SubProgressMonitor(
+ monitor,
+ 1 * scale) );
+ }
+ catch ( final Exception e ) {
+ Display.getDefault().asyncExec(new Runnable() {
+
+ public void run() {
+ MessageDialog.openInformation(
+ PlatformUI
+ .getWorkbench()
+ .getActiveWorkbenchWindow()
+ .getShell(),
+ "Could not sign in "
+ + username,
+ e.getMessage() );
+ try {
+ ((IHandlerService)
+ PlatformUI.getWorkbench()
+ .getActiveWorkbenchWindow()
+ .getService(IHandlerService.class) )
+ .executeCommand(
+ "net.bioclipse.usermanager" +
+ ".commands.login",
+ null );
+ }
+ catch ( Exception e ) {
+ LogUtils.handleException(
+ e,
+ logger,
+ "net.bioclipse.usermanager" );
+ }
+ }
+ });
+ }
+ finally {
+ monitor.done();
+ }
+ return Status.OK_STATUS;
+ }
+ };
+ job.setUser( true );
+ job.schedule();
+ }
}
View
17 plugins/net.bioclipse.usermanager/src/net/bioclipse/usermanager/NewAccountWizardPage.java
@@ -95,12 +95,6 @@ public void createControl(Composite parent) {
giveFocus();
}
setControl(container);
- if ( !Activator.getDefault().getUserManager().isLoggedIn() ) {
- System.out.println("CANCEL!" + this.getWizard().performCancel());
- // TODO FIXME find a better way to do this that does not cause an
- // Exception.
- this.getShell().close();
- }
}
@@ -213,10 +207,13 @@ private String createErrorMessage(ArrayList<String> unfilledFields) {
@Override
public boolean isPageComplete() {
- if (addedAccounts.size()>0) {
- AccountPropertiesPage account =
- addedAccounts.get(accountTypeCombo.getSelectionIndex());
- return account.isFieldsProperlyFilled();
+ if (isCurrentPage()) {
+ if (addedAccounts.size()>0) {
+ AccountPropertiesPage account =
+ addedAccounts.get(accountTypeCombo.getSelectionIndex());
+ return account.isFieldsProperlyFilled();
+ } else
+ return false;
} else
return false;
}
View
97 plugins/net.bioclipse.usermanager/src/net/bioclipse/usermanager/dialogs/DialogArea.java
@@ -13,10 +13,13 @@
import net.bioclipse.usermanager.UserContainer;
+import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.window.Window;
+import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormLayout;
@@ -24,7 +27,9 @@
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.PlatformUI;
@@ -36,7 +41,7 @@
* @author Klas Jšnsson (aka "konditorn")
*
*/
-public class DialogArea {
+public class DialogArea implements Listener {
private UserContainer userContainer=null;
private Label usernameLabel;
@@ -47,17 +52,24 @@
private Text repeatPasswordText;
private boolean userContainerEdited;
private boolean createNewAccountButton;
+ private boolean errorFlag;
+ private WizardPage page;
/**
+ * The constructor.
*
* @param userContainer
- * @param createNewAccountButton
+ * @param createNewAccountButton Set to true if this button is wanted.
+ * @param page If this is a part of a wizard add it here if not set it to
+ * null
*/
public DialogArea(UserContainer userContainer,
- Boolean createNewAccountButton) {
+ Boolean createNewAccountButton, WizardPage page) {
this.userContainer = userContainer;
this.userContainerEdited = false;
this.createNewAccountButton = createNewAccountButton;
+ this.errorFlag = true;
+ this.page = page;
}
/**
@@ -87,7 +99,8 @@ public Composite getLoginArea(Composite parent) {
final FormData formData_2 = new FormData();
formData_2.top = new FormAttachment(0, 93);
passwordText.setLayoutData(formData_2);
-
+ passwordText.addListener(SWT.CHANGED, this);
+
usernameText = new Text(container, SWT.BORDER);
formData.bottom = new FormAttachment(usernameText, 0, SWT.BOTTOM);
formData.right = new FormAttachment(usernameText, -5, SWT.LEFT);
@@ -98,6 +111,8 @@ public Composite getLoginArea(Composite parent) {
formData_3.right = new FormAttachment(100, -34);
formData_3.top = new FormAttachment(0, 53);
usernameText.setLayoutData(formData_3);
+ usernameText.addListener(SWT.CHANGED, this);
+
if (createNewAccountButton) {
Button createNewKeyringButton = new Button(container, SWT.NONE);
createNewKeyringButton.addSelectionListener(new SelectionAdapter() {
@@ -154,6 +169,8 @@ public void widgetSelected(SelectionEvent e) {
formData_5.left = new FormAttachment(0, 154);
formData_5.right = new FormAttachment(0, 470);
repeatPasswordText.setLayoutData(formData_5);
+ repeatPasswordText.addListener(SWT.CHANGED, this);
+
container.setTabList(new Control[] { usernameText,
passwordText,
repeatPasswordText,
@@ -161,6 +178,20 @@ public void widgetSelected(SelectionEvent e) {
passwordLabel,
repeatPasswordLabel });
}
+
+// Label icon = new Label(container, SWT.NONE);
+// ImageDescriptor imgDesc = ImageDescriptor
+// .createFromFile(this.getClass(),
+// "icons/login_16.png");
+// Image img = imgDesc.createImage();
+// icon.setImage(img);
+// final FormData formData_6 = new FormData();
+// formData_6.top = new FormAttachment(usernameText, 0, SWT.RIGHT);
+// formData_6.left = new FormAttachment(usernameText, 0, SWT.RIGHT);
+// icon.setLayoutData(formData_6);
+
+ usernameText.setFocus();
+
return container;
}
@@ -183,25 +214,43 @@ public boolean isUserContainerEdited() {
*/
public boolean isFilledIn() {
if (createNewAccountButton) {
- return ( !usernameText.getText().isEmpty() &&
- !passwordText.getText().isEmpty() );
+ if (usernameText.getText().isEmpty() ||
+ passwordText.getText().isEmpty() )
+ return false;
+ else
+ return true;
+// return ( !usernameText.getText().isEmpty() &&
+// !passwordText.getText().isEmpty() );
} else
- return ( !usernameText.getText().isEmpty() &&
- !passwordText.getText().isEmpty() &&
- !repeatPasswordText.getText().isEmpty() );
+ if (usernameText.getText().isEmpty() ||
+ passwordText.getText().isEmpty() ||
+ repeatPasswordText.getText().isEmpty())
+ return false;
+ else
+ return true;
+ // return ( !usernameText.getText().isEmpty() &&
+// !passwordText.getText().isEmpty() &&
+// !repeatPasswordText.getText().isEmpty() );
}
/**
- * Returns a string that explains what's wrong.
- *
+ * Returns a string that explains what's wrong, if nothing is wrong it
+ * returns null.
+ *
* @return The error-message
*/
public String getErrorMessage() {
String message = null;
if (!isFilledIn()) {
+ if (createNewAccountButton) {
+ message = "Please fill in all fields.\n" +
+ "Fill in your username and your password.";
+ } else {
message = "Please fill in all fields.\n" +
- "Fill in your username and your password (twice)";
- } else if (!passwordText.getText().equals(repeatPasswordText.getText()))
+ "Fill in your username and your password (twice).";
+ }
+ } else if (!createNewAccountButton &&
+ !passwordText.getText().equals(repeatPasswordText.getText()))
message = "Not same password:\n The repeated password doesnt" +
" match the password";
return message;
@@ -213,7 +262,25 @@ public String getErrorMessage() {
* @return True if the exists an error.
*/
public boolean getErrorFlag() {
- return (!isFilledIn() &&
- !passwordText.getText().equals(repeatPasswordText.getText()) );
+ return errorFlag;
}
+
+ @Override
+ public void handleEvent(Event event) {
+ if (!isFilledIn())
+ errorFlag = true;
+ else if (!createNewAccountButton &&
+ !passwordText.getText().equals(repeatPasswordText.getText()) )
+ errorFlag = true;
+ else
+ errorFlag = false;
+ if (page != null) {
+ page.setPageComplete(!errorFlag);
+ page.getWizard().getContainer().updateButtons();
+ page.setErrorMessage(getErrorMessage());
+ page.getWizard().getContainer().updateMessage();
+ }
+ }
+
+
}
View
2  plugins/net.bioclipse.usermanager/src/net/bioclipse/usermanager/dialogs/LoginDialog.java
@@ -187,7 +187,7 @@ protected void buttonPressed(int buttonId) {
/*
* LOGIN
*/
- if (buttonId == IDialogConstants.OK_ID) {
+ if (buttonId == IDialogConstants.OK_ID) {
username = usernameText.getText();
password = passwordText.getText();
final String username = this.username;
Please sign in to comment.
Something went wrong with that request. Please try again.