Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fixed the login-icon tool-tip-text
  • Loading branch information
KlasJoensson committed Aug 15, 2012
1 parent 2487cfc commit 9919b10
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 11 deletions.
Expand Up @@ -25,6 +25,7 @@ public class User implements Serializable {
private static final long serialVersionUID = 1424921617301316765L;

private HashMap<String, Account> accounts;
private HashMap<String, Boolean> loggedInAccounts = new HashMap<String, Boolean>();
private String encryptedKey;
private String userName;

Expand All @@ -39,6 +40,7 @@ public class User implements Serializable {
this.encryptedKey = encryptedKey;
this.userName = userName;
accounts = new HashMap<String, Account>();
// loggedInAccounts = new HashMap<String, Boolean>();
}

/**
Expand All @@ -50,7 +52,7 @@ public class User implements Serializable {

this.userName = user.userName;
this.encryptedKey = user.encryptedKey;

// this.loggedInAccounts = new HashMap<String, Boolean>();//user.getLoggedInAccounts();
this.accounts = new HashMap<String, Account>();
for( String accountId : user.accounts.keySet() ) {
this.accounts.put( accountId,
Expand Down Expand Up @@ -88,4 +90,31 @@ void setEncryptedPassWord(String encryptedPassword) {
this.encryptedKey = encryptedPassword;
}

/**
* Add an account that the user as tried to login to.
*
* @param name The name of the account
* @param logInSucceeded True if the user is logged in
*/
public void addLoggedInAccount(String name, boolean logInSucceeded) {
loggedInAccounts.put( name, logInSucceeded );
}

/**
* Get the hash map with the information about the which account the user is
* logged in to.
*
* @return The accounts the user tried to log in to
*/
public HashMap<String, Boolean> getLoggedInAccounts() {
return loggedInAccounts;
}

/**
* Clears the hash map with information about the account that the user has
* tried to login to. To be used when the user are logging out.
*/
public void clearLoggedInAccounts() {
loggedInAccounts.clear();
}
}
Expand Up @@ -181,6 +181,7 @@ public boolean isLoggedIn() {
* Signs out the current superuser
*/
public void signOut() {
loggedInUser.clearLoggedInAccounts();
loggedInUser = null;
textEncryptor = null;
logger.debug( "Signed out user from usercontainer with id: "
Expand Down Expand Up @@ -517,7 +518,7 @@ public AccountType[] getAvailableAccountTypes() {
private boolean accountTypeIsAvailable( AccountType accountType ) {
return availableAccountTypes.contains( accountType );
}

/**
* Returns the account type for the an account corresponding to a given
* account id
Expand Down
Expand Up @@ -11,7 +11,6 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;

import net.bioclipse.usermanager.AccountType;
Expand All @@ -24,10 +23,6 @@
import net.bioclipse.core.util.LogUtils;

import org.eclipse.core.runtime.SubProgressMonitor;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.PlatformUI;

public class UserManager implements IUserManager {

Expand Down Expand Up @@ -92,7 +87,7 @@ public String[] getAvailableAccountTypeNames() {
public AccountType[] getAvailableAccountTypes() {
return userContainer.getAvailableAccountTypes();
}

public User getLoggedInUser() {
return userContainer.getLoggedInUser();
}
Expand Down Expand Up @@ -210,11 +205,16 @@ private boolean fireLoginWithProgressBar( SubProgressMonitor monitor ) {

try {
for( IUserManagerListener listener : listeners) {
failedLogin.clear();
loginOK = listener.receiveUserManagerEvent( UserManagerEvent.LOGIN );
if (!loginOK) {
name = listener.getClass().getName();
failedLogin.add( name
.substring( 0, name.lastIndexOf( '.' ) ) );
}
if (userContainer.getLoggedInUser().getLoggedInAccounts() != null ) {
name = listener.getClass().getName();
userContainer.getLoggedInUser().addLoggedInAccount( name.substring( 0, name.lastIndexOf( '.' ) ), loginOK );
}
if(usingMonitor) {
monitor.beginTask("signing in", ticks);
Expand Down
Expand Up @@ -217,7 +217,7 @@ protected IStatus run( IProgressMonitor monitor ) {
Iterator<String> itr = failedLogins.iterator();
String name = "";
errorMessage = "Bioclipse could not " +
"log-in to your one or several thried-part " +
"log-in to your one or several third-part " +
"account(s):\n\n";
while(itr.hasNext())
name = itr.next();
Expand All @@ -237,7 +237,7 @@ public void run() {

}
} );
}
}
}
catch ( final Exception e ) {
Display.getDefault().asyncExec(new Runnable() {
Expand Down
@@ -1,16 +1,24 @@
package net.bioclipse.usermanager.handlers;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

import net.bioclipse.usermanager.Activator;
import net.bioclipse.usermanager.business.IUserManager;

import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.commands.HandlerEvent;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.commands.ICommandService;
import org.eclipse.ui.commands.IElementUpdater;
import org.eclipse.ui.menus.UIElement;
import org.eclipse.ui.services.IEvaluationService;

public class LogoutHandler extends AbstractHandler {
public class LogoutHandler extends AbstractHandler implements IElementUpdater {

public Object execute( ExecutionEvent event ) throws ExecutionException {

Expand All @@ -26,4 +34,32 @@ public Object execute( ExecutionEvent event ) throws ExecutionException {
return null;
}

@Override
public void updateElement( UIElement element, Map parameters ) {
IUserManager userManager = Activator.getDefault().getUserManager();
String toolTipText = "";
if (userManager.isLoggedIn()) {
toolTipText = "You are logged in as: " + userManager.getLoggedInUserName();
HashMap<String, Boolean> accountInfo = userManager.getLoggedInUser().getLoggedInAccounts();
if ( accountInfo != null && !accountInfo.isEmpty() ) {
String key = "";
Set<String> keys = accountInfo.keySet();
Iterator<String> itr = keys.iterator();
while ( itr.hasNext() ) {
key = itr.next();
toolTipText += "\n " + key.substring( key.lastIndexOf( '.' ) + 1 ) +" login ";
if ( accountInfo.get( key ) )
toolTipText += "OK";
else
toolTipText += "failed";
}
}
}
else
/*It should not end up here, but just in case...*/
toolTipText = "You're hopefully logged in...";

element.setTooltip( toolTipText );
}

}

0 comments on commit 9919b10

Please sign in to comment.