Index: src/org/jboss/tools/openshift/express/internal/core/console/IPasswordPrompter.java =================================================================== --- src/org/jboss/tools/openshift/express/internal/core/console/IPasswordPrompter.java (revision 39321) +++ src/org/jboss/tools/openshift/express/internal/core/console/IPasswordPrompter.java (working copy) @@ -1,31 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2012 Red Hat, Inc. - * Distributed under license by Red Hat, Inc. All rights reserved. - * This program is made available under the terms of the - * Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Red Hat, Inc. - initial API and implementation - ******************************************************************************/ -package org.jboss.tools.openshift.express.internal.core.console; - -import java.util.Map; - -import com.openshift.express.client.IUser; - -public interface IPasswordPrompter { - - public enum PromptResult { - PASSWORD_VALUE, SAVE_PASSWORD_VALUE; - } - /** - * Returns a map of the values entered by the user. The value indexed with {@link IPasswordPrompter.PromptResult.PASSWORD_VALUE} in the - * returning array is the input password, the value indexed with indexed with {@link IPasswordPrompter.PromptResult.SAVE_PASSWORD_VALUE} is the Boolean stating - * whether the password should be saved in the secured storage or not. - * - * @param user - * @return map with password value (as String) and 'save password' (as Boolean) - */ - public Map getPasswordFor(IUser user); -} Index: src/org/jboss/tools/openshift/express/internal/core/console/UserModel.java =================================================================== --- src/org/jboss/tools/openshift/express/internal/core/console/UserModel.java (revision 39321) +++ src/org/jboss/tools/openshift/express/internal/core/console/UserModel.java (working copy) @@ -15,13 +15,11 @@ import java.util.Collection; import java.util.HashMap; import java.util.Iterator; -import java.util.Map; import java.util.Map.Entry; import java.util.Set; import org.jboss.tools.common.ui.preferencevalue.StringPreferenceValue; import org.jboss.tools.common.ui.preferencevalue.StringsPreferenceValue; -import org.jboss.tools.openshift.express.internal.core.console.IPasswordPrompter.PromptResult; import org.jboss.tools.openshift.express.internal.ui.OpenShiftUIActivator; import org.jboss.tools.openshift.express.internal.ui.utils.Logger; import org.jboss.tools.openshift.express.internal.ui.utils.OpenShiftPasswordStorageKey; @@ -44,30 +42,6 @@ return model; } - private static IPasswordPrompter prompter; - public static void setPasswordPrompt(IPasswordPrompter prompt) { - prompter =prompt; - } - - public static IPasswordPrompter getPasswordPrompt() { - return prompter; - } - - /** - * Returns a map of the values entered by the user. The value indexed with {@link IPasswordPrompter.PromptResult.PASSWORD_VALUE} in the - * returning array is the input password, the value indexed with indexed with {@link IPasswordPrompter.PromptResult.SAVE_PASSWORD_VALUE} is the Boolean stating - * whether the password should be saved in the secured storage or not. - * - * @param user - * @return map with password value (as String) and 'save password' (as - * Boolean), or null if the password prompter could not be - * initialized - */ - - public static Map promptForPassword(IUser user) { - return prompter == null ? null : prompter.getPasswordFor(user); - } - /** The most recent user connected on OpenShift. */ private UserDelegate recentUser = null; private HashMap allUsers = new HashMap(); @@ -164,7 +138,7 @@ for (int i = 0; i < users.length; i++) { try { String password = getPasswordFromSecureStorage(users[i]); - UserDelegate u = new UserDelegate(createUser(users[i], password), password != null); + UserDelegate u = new UserDelegate(createUser(users[i], password), password != null, password != null); addUser(u); } catch (OpenShiftException ose) { // TODO Index: src/org/jboss/tools/openshift/express/internal/core/console/UserDelegate.java =================================================================== --- src/org/jboss/tools/openshift/express/internal/core/console/UserDelegate.java (revision 39321) +++ src/org/jboss/tools/openshift/express/internal/core/console/UserDelegate.java (working copy) @@ -11,10 +11,16 @@ package org.jboss.tools.openshift.express.internal.core.console; import java.util.List; -import java.util.Map; -import org.jboss.tools.openshift.express.internal.core.console.IPasswordPrompter.PromptResult; +import org.eclipse.jface.window.Window; +import org.eclipse.jface.wizard.IWizard; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.IWorkbenchWindow; +import org.eclipse.ui.PlatformUI; +import org.jboss.tools.common.ui.WizardUtils; import org.jboss.tools.openshift.express.internal.ui.utils.Logger; +import org.jboss.tools.openshift.express.internal.ui.viewer.ConnectToOpenShiftWizard; import com.openshift.express.client.IApplication; import com.openshift.express.client.ICartridge; @@ -27,12 +33,29 @@ public class UserDelegate implements IUser { private IUser delegate; private boolean rememberPassword; + private boolean connected; + private boolean alreadyPromptedForPassword; - public UserDelegate(IUser user, boolean rememberPassword) { + public UserDelegate(IUser user, boolean rememberPassword, boolean connected) { this.delegate = user; this.rememberPassword = rememberPassword; + this.setConnected(connected); } + /** + * @return the delegate + */ + protected final IUser getDelegate() { + return delegate; + } + + /** + * @param delegate the delegate to set + */ + protected final void setDelegate(IUser delegate) { + this.delegate = delegate; + } + public String getRhlogin() { return delegate.getRhlogin(); } @@ -44,98 +67,176 @@ return rememberPassword; } - protected void checkForPassword() { + /** + * @param rememberPassword the rememberPassword to set + */ + protected final void setRememberPassword(boolean rememberPassword) { + this.rememberPassword = rememberPassword; + } + + public boolean canPromptForPassword() { + return this.alreadyPromptedForPassword == false; + } + + /** + * Prompts user for password if it was not given or retrieved from secure storage before. + * @return true if user entered credentials, false otherwise. + */ + public boolean checkForPassword() { if( delegate.getPassword() == null || "".equals(delegate.getPassword())) { try { - Map passwordAndSaveValues = UserModel.promptForPassword(this); - if(passwordAndSaveValues != null) { - final String password = (String) passwordAndSaveValues.get(PromptResult.PASSWORD_VALUE); - delegate = UserModel.getDefault().createUser(delegate.getRhlogin(), password); - final Boolean save = (Boolean) passwordAndSaveValues.get(PromptResult.SAVE_PASSWORD_VALUE); - this.rememberPassword = save; - } + this.alreadyPromptedForPassword = true; + Display.getDefault().syncExec(new Runnable() { public void run() { + final IWorkbenchWindow activeWorkbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); + final Shell shell = activeWorkbenchWindow != null ? activeWorkbenchWindow.getShell() : null; + if(shell == null) { + Logger.error("Could not open Credentials Wizard: no shell available"); + return; + } + final IWizard connectToOpenShiftWizard = new ConnectToOpenShiftWizard(); + int returnCode = WizardUtils.openWizardDialog(connectToOpenShiftWizard, shell); + if (returnCode == Window.OK) { + Logger.debug("OpenShift Auth succeeded."); + setDelegate(UserModel.getDefault().getRecentUser().getDelegate()); + setConnected(true); + setRememberPassword(UserModel.getDefault().getRecentUser().isRememberPassword()); + } else { + setConnected(false); + } + }}); } catch( Exception e ) { Logger.error("Failed to retrieve User's password", e); } } + return (delegate.getPassword() != null && !"".equals(delegate.getPassword())); } public IApplication createApplication(String arg0, ICartridge arg1) throws OpenShiftException { - checkForPassword(); - return delegate.createApplication(arg0, arg1); + if(checkForPassword()) { + return delegate.createApplication(arg0, arg1); + } + return null; } public IDomain createDomain(String arg0, ISSHPublicKey arg1) throws OpenShiftException { - checkForPassword(); - return delegate.createDomain(arg0, arg1); + if(checkForPassword()) { + return delegate.createDomain(arg0, arg1); + } + return null; } public IApplication getApplicationByName(String arg0) throws OpenShiftException { - checkForPassword(); - return delegate.getApplicationByName(arg0); + if(checkForPassword()) { + return delegate.getApplicationByName(arg0); + } + return null; } public List getApplications() throws OpenShiftException { - checkForPassword(); - return delegate.getApplications(); + if(checkForPassword()) { + return delegate.getApplications(); + } + return null; } public List getApplicationsByCartridge(ICartridge arg0) throws OpenShiftException { - checkForPassword(); - return delegate.getApplicationsByCartridge(arg0); + if(checkForPassword()) { + return delegate.getApplicationsByCartridge(arg0); + } + return null; } public String getAuthIV() { - checkForPassword(); - return delegate.getAuthIV(); + if(checkForPassword()) { + return delegate.getAuthIV(); + } + return null; } public String getAuthKey() { - checkForPassword(); - return delegate.getAuthKey(); + if(checkForPassword()) { + return delegate.getAuthKey(); + } + return null; } public ICartridge getCartridgeByName(String arg0) throws OpenShiftException { - checkForPassword(); - return delegate.getCartridgeByName(arg0); + if(checkForPassword()) { + return delegate.getCartridgeByName(arg0); + } + return null; } public List getCartridges() throws OpenShiftException { - checkForPassword(); - return delegate.getCartridges(); + if(checkForPassword()) { + return delegate.getCartridges(); + } + return null; } public IDomain getDomain() throws OpenShiftException { - checkForPassword(); - return delegate.getDomain(); + if(checkForPassword()) { + return delegate.getDomain(); + } + return null; } public List getEmbeddableCartridges() throws OpenShiftException { - checkForPassword(); - return delegate.getEmbeddableCartridges(); + if(checkForPassword()) { + return delegate.getEmbeddableCartridges(); + } + return null; } public ISSHPublicKey getSshKey() throws OpenShiftException { - checkForPassword(); - return delegate.getSshKey(); + if(checkForPassword()) { + return delegate.getSshKey(); + } + return null; } public String getUUID() throws OpenShiftException { - checkForPassword(); - return delegate.getUUID(); + if(checkForPassword()) { + return delegate.getUUID(); + } + return null; } public boolean hasApplication(String arg0) throws OpenShiftException { - checkForPassword(); - return delegate.hasApplication(arg0); + if(checkForPassword()) { + return delegate.hasApplication(arg0); + } + return false; } public boolean hasApplication(ICartridge arg0) throws OpenShiftException { - checkForPassword(); - return delegate.hasApplication(arg0); + if(checkForPassword()) { + return delegate.hasApplication(arg0); + } + return false; } public boolean hasDomain() throws OpenShiftException { - checkForPassword(); - return delegate.hasDomain(); + if(checkForPassword()) { + return delegate.hasDomain(); + } + return false; + } public boolean isValid() throws OpenShiftException { - checkForPassword(); - return delegate.isValid(); + if(checkForPassword()) { + return delegate.isValid(); + } + return false; } public void refresh() throws OpenShiftException { - checkForPassword(); - delegate.refresh(); + if(checkForPassword()) { + delegate.refresh(); + } + } + + /** + * @return the connected + */ + public boolean isConnected() { + return connected; + } + + /** + * @param connected the connected to set + */ + public void setConnected(boolean connected) { + this.connected = connected; } } Index: src/org/jboss/tools/openshift/express/internal/ui/viewer/OpenShiftExpressConsoleContentProvider.java =================================================================== --- src/org/jboss/tools/openshift/express/internal/ui/viewer/OpenShiftExpressConsoleContentProvider.java (revision 39311) +++ src/org/jboss/tools/openshift/express/internal/ui/viewer/OpenShiftExpressConsoleContentProvider.java (working copy) @@ -22,6 +22,7 @@ import org.eclipse.jface.viewers.StructuredViewer; import org.eclipse.jface.viewers.Viewer; import org.eclipse.swt.widgets.Display; +import org.jboss.tools.openshift.express.internal.core.console.UserDelegate; import org.jboss.tools.openshift.express.internal.core.console.UserModel; import org.jboss.tools.openshift.express.internal.ui.utils.Logger; @@ -53,6 +54,11 @@ } } + public static class NotConnectedUserStub { + public NotConnectedUserStub () { + } + } + // Keep track of what's loading and what's finished private ArrayList loadedUsers = new ArrayList(); private ArrayList loadingUsers = new ArrayList(); @@ -76,7 +82,11 @@ @Override public Object[] getChildren(Object parentElement) { - if (parentElement instanceof IUser) { + if (parentElement instanceof UserDelegate) { + UserDelegate user = (UserDelegate) parentElement; + if(!user.isConnected() && !user.canPromptForPassword()) { + return new Object[]{new NotConnectedUserStub()}; + } if (!loadedUsers.contains(parentElement)) { if (!loadingUsers.contains(parentElement)) { // Load the data @@ -118,8 +128,8 @@ IUser user = ((OpenShiftExpressConsoleContentCategory) parentElement).getUser(); children = new Object[] { user }; } - if (parentElement instanceof IUser) { - final IUser user = (IUser) parentElement; + if (parentElement instanceof UserDelegate) { + final UserDelegate user = (UserDelegate) parentElement; if (user.hasDomain()) { children = user.getApplications().toArray(); } Index: src/org/jboss/tools/openshift/express/internal/ui/viewer/actionDelegate/OpenConnectionDialogActionDelegate.java =================================================================== --- src/org/jboss/tools/openshift/express/internal/ui/viewer/actionDelegate/OpenConnectionDialogActionDelegate.java (revision 39311) +++ src/org/jboss/tools/openshift/express/internal/ui/viewer/actionDelegate/OpenConnectionDialogActionDelegate.java (working copy) @@ -4,10 +4,10 @@ import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.window.Window; import org.eclipse.jface.wizard.IWizard; -import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.IViewActionDelegate; import org.eclipse.ui.IViewPart; +import org.eclipse.ui.PlatformUI; import org.eclipse.ui.navigator.CommonNavigator; import org.jboss.tools.common.ui.WizardUtils; import org.jboss.tools.openshift.express.internal.core.console.UserModel; @@ -20,8 +20,7 @@ @Override public void run(IAction action) { - final Display display = Display.getCurrent(); - final Shell shell = new Shell(display); + final Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(); final IWizard connectToOpenShiftWizard = new ConnectToOpenShiftWizard(); int returnCode = WizardUtils.openWizardDialog(connectToOpenShiftWizard, shell); if (returnCode == Window.OK) { Index: src/org/jboss/tools/openshift/express/internal/ui/viewer/property/PropertySourceAdapterFactory.java =================================================================== --- src/org/jboss/tools/openshift/express/internal/ui/viewer/property/PropertySourceAdapterFactory.java (revision 39311) +++ src/org/jboss/tools/openshift/express/internal/ui/viewer/property/PropertySourceAdapterFactory.java (working copy) @@ -12,10 +12,10 @@ import org.eclipse.core.runtime.IAdapterFactory; import org.eclipse.ui.views.properties.IPropertySource; +import org.jboss.tools.openshift.express.internal.core.console.UserDelegate; import com.openshift.express.client.IApplication; import com.openshift.express.client.IEmbeddableCartridge; -import com.openshift.express.client.IUser; /** * @author Xavier Coulon @@ -26,8 +26,8 @@ @Override public Object getAdapter(Object adaptableObject, @SuppressWarnings("rawtypes") Class adapterType) { if(adapterType == IPropertySource.class) { - if(adaptableObject instanceof IUser) { - return new UserPropertySource((IUser)adaptableObject); + if(adaptableObject instanceof UserDelegate) { + return new UserPropertySource((UserDelegate)adaptableObject); } if(adaptableObject instanceof IApplication) { return new ApplicationPropertySource((IApplication)adaptableObject); Index: src/org/jboss/tools/openshift/express/internal/ui/viewer/property/UserPropertySource.java =================================================================== --- src/org/jboss/tools/openshift/express/internal/ui/viewer/property/UserPropertySource.java (revision 39311) +++ src/org/jboss/tools/openshift/express/internal/ui/viewer/property/UserPropertySource.java (working copy) @@ -13,9 +13,10 @@ import org.eclipse.ui.views.properties.IPropertyDescriptor; import org.eclipse.ui.views.properties.IPropertySource; import org.eclipse.ui.views.properties.PropertyDescriptor; +import org.jboss.tools.openshift.express.internal.core.console.UserDelegate; +import org.jboss.tools.openshift.express.internal.ui.messages.OpenShiftExpressUIMessages; import org.jboss.tools.openshift.express.internal.ui.utils.Logger; -import com.openshift.express.client.IUser; import com.openshift.express.client.OpenShiftException; /** @@ -25,9 +26,9 @@ private static final String PROPERTY_DOMAIN = "Domain"; private static final String PROPERTY_USERNAME = "Username"; - private final IUser user; + private final UserDelegate user; - public UserPropertySource(IUser user) { + public UserPropertySource(UserDelegate user) { this.user = user; } @@ -46,6 +47,13 @@ @Override public Object getPropertyValue(Object id) { try { + if(!user.isConnected() && !user.canPromptForPassword()) { + return OpenShiftExpressUIMessages.USER_NOT_CONNECTED_LABEL; + } + if(!user.isConnected() && user.canPromptForPassword()) { + user.checkForPassword(); + } + if (id.equals(PROPERTY_USERNAME)) { return user.getRhlogin(); } Index: src/org/jboss/tools/openshift/express/internal/ui/viewer/OpenShiftExpressConsoleLabelProvider.java =================================================================== --- src/org/jboss/tools/openshift/express/internal/ui/viewer/OpenShiftExpressConsoleLabelProvider.java (revision 39311) +++ src/org/jboss/tools/openshift/express/internal/ui/viewer/OpenShiftExpressConsoleLabelProvider.java (working copy) @@ -18,7 +18,9 @@ import org.eclipse.ui.ISharedImages; import org.eclipse.ui.PlatformUI; import org.jboss.tools.openshift.express.internal.ui.OpenShiftUIActivator; +import org.jboss.tools.openshift.express.internal.ui.messages.OpenShiftExpressUIMessages; import org.jboss.tools.openshift.express.internal.ui.viewer.OpenShiftExpressConsoleContentProvider.LoadingStub; +import org.jboss.tools.openshift.express.internal.ui.viewer.OpenShiftExpressConsoleContentProvider.NotConnectedUserStub; import com.openshift.express.client.IApplication; import com.openshift.express.client.IEmbeddableCartridge; @@ -107,7 +109,10 @@ } if (element instanceof LoadingStub) { - return new StyledString("Loading..."); + return new StyledString(OpenShiftExpressUIMessages.LOADING_USER_APPLICATIONS_LABEL); + } + if (element instanceof NotConnectedUserStub) { + return new StyledString(OpenShiftExpressUIMessages.USER_NOT_CONNECTED_LABEL); } if (element instanceof OpenShiftException ) { return new StyledString( ((OpenShiftException)element).getMessage()); Index: src/org/jboss/tools/openshift/express/internal/ui/messages/OpenShiftExpressUIMessages.java =================================================================== --- src/org/jboss/tools/openshift/express/internal/ui/messages/OpenShiftExpressUIMessages.java (revision 39319) +++ src/org/jboss/tools/openshift/express/internal/ui/messages/OpenShiftExpressUIMessages.java (working copy) @@ -42,4 +42,9 @@ public static String REFRESH_VIEWER_ACTION; public static String DELETE_CONNECTION_ACTION; + + public static String USER_NOT_CONNECTED_LABEL; + + public static String LOADING_USER_APPLICATIONS_LABEL; + } Index: src/org/jboss/tools/openshift/express/internal/ui/messages/OpenShiftExpressUIMessages.properties =================================================================== --- src/org/jboss/tools/openshift/express/internal/ui/messages/OpenShiftExpressUIMessages.properties (revision 39319) +++ src/org/jboss/tools/openshift/express/internal/ui/messages/OpenShiftExpressUIMessages.properties (working copy) @@ -18,4 +18,8 @@ DELETE_CONNECTION_ACTION=Delete +USER_NOT_CONNECTED_LABEL= +LOADING_USER_APPLICATIONS_LABEL=Loading + + Index: src/org/jboss/tools/openshift/express/internal/ui/wizard/CredentialsWizardPageModel.java =================================================================== --- src/org/jboss/tools/openshift/express/internal/ui/wizard/CredentialsWizardPageModel.java (revision 39321) +++ src/org/jboss/tools/openshift/express/internal/ui/wizard/CredentialsWizardPageModel.java (working copy) @@ -214,7 +214,7 @@ IStatus status = Status.OK_STATUS; UserDelegate user = null; try { - user = new UserDelegate(UserModel.getDefault().createUser(getRhLogin(), getPassword()), rememberPassword); + user = new UserDelegate(UserModel.getDefault().createUser(rhLogin, password), rememberPassword, password != null); if (user.isValid()) { storeUser(user); } else { Index: src/org/jboss/tools/openshift/express/internal/ui/OpenShiftUIActivator.java =================================================================== --- src/org/jboss/tools/openshift/express/internal/ui/OpenShiftUIActivator.java (revision 39331) +++ src/org/jboss/tools/openshift/express/internal/ui/OpenShiftUIActivator.java (working copy) @@ -1,8 +1,6 @@ package org.jboss.tools.openshift.express.internal.ui; import java.net.URL; -import java.util.HashMap; -import java.util.Map; import org.eclipse.core.runtime.FileLocator; import org.eclipse.core.runtime.IPath; @@ -10,23 +8,16 @@ import org.eclipse.core.runtime.Path; import org.eclipse.core.runtime.Status; import org.eclipse.jface.resource.ImageDescriptor; -import org.eclipse.jface.window.Window; import org.eclipse.osgi.util.NLS; import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.plugin.AbstractUIPlugin; -import org.jboss.ide.eclipse.as.ui.dialogs.RequiredCredentialsDialog; -import org.jboss.tools.openshift.express.internal.core.console.IPasswordPrompter; import org.jboss.tools.openshift.express.internal.core.console.UserModel; import org.osgi.framework.BundleContext; -import com.openshift.express.client.IUser; - /** * The activator class controls the plug-in life cycle */ -public class OpenShiftUIActivator extends AbstractUIPlugin implements IPasswordPrompter { +public class OpenShiftUIActivator extends AbstractUIPlugin { // The plug-in ID public static final String PLUGIN_ID = "org.jboss.tools.openshift.express.ui"; //$NON-NLS-1$ @@ -50,7 +41,6 @@ public void start(BundleContext context) throws Exception { super.start(context); plugin = this; - UserModel.setPasswordPrompt(this); } /* @@ -128,20 +118,4 @@ return ImageDescriptor.createFromURL(imageFileUrl); } - public Map getPasswordFor(final IUser user) { - final Map val = new HashMap(); - Display.getDefault().syncExec(new Runnable() { - public void run() { - Shell shell = Display.getDefault().getActiveShell(); - RequiredCredentialsDialog d = new RequiredCredentialsDialog(shell, user.getRhlogin(), user.getPassword()); - d.setCanModifyUser(false); - d.setDescription("Provide enter the password for your express server"); - if( d.open() == Window.OK) { - val.put(PromptResult.PASSWORD_VALUE, d.getPass()); - val.put(PromptResult.SAVE_PASSWORD_VALUE, d.getSave()); - } - } - }); - return val; - } }