Index: src/org/jboss/tools/openshift/express/internal/ui/wizard/ApplicationConfigurationWizardPageModel.java =================================================================== --- src/org/jboss/tools/openshift/express/internal/ui/wizard/ApplicationConfigurationWizardPageModel.java (revision 39655) +++ src/org/jboss/tools/openshift/express/internal/ui/wizard/ApplicationConfigurationWizardPageModel.java (working copy) @@ -20,6 +20,7 @@ import org.jboss.tools.common.ui.databinding.ObservableUIPojo; 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.StringUtils; import com.openshift.express.client.IApplication; import com.openshift.express.client.ICartridge; @@ -48,13 +49,14 @@ // start with a null value as a marker of non-initialized state (used during // first pass validation) - private List existingApplications = null; + private List existingApplications = new ArrayList();; private List cartridges = new ArrayList(); private List embeddableCartridges = new ArrayList(); private String existingApplicationName; private boolean existingApplicationsLoaded = false;; - public ApplicationConfigurationWizardPageModel(OpenShiftExpressApplicationWizardModel wizardModel) + public ApplicationConfigurationWizardPageModel( + OpenShiftExpressApplicationWizardModel wizardModel) throws OpenShiftException { this.wizardModel = wizardModel; setExistingApplication(wizardModel.getApplication()); @@ -111,21 +113,26 @@ return existingApplicationName; } - public void setExistingApplicationName(String applicationName) throws OpenShiftException { - firePropertyChange(PROPERTY_EXISTING_APPLICATION_NAME - , existingApplicationName - , this.existingApplicationName = applicationName); - if (applicationName != null) { - for (IApplication application : getApplications()) { - if (application.getName().equals(applicationName)) { - setApplicationName(application.getName()); - setSelectedCartridge(application.getCartridge()); - setSelectedEmbeddableCartridges(new HashSet( - application.getEmbeddedCartridges())); - } - } + /** + * Sets the existing application in this model by name. If there's an + * existing application with the given name, all properties related to an + * existing application are also set. + * + * @param applicationName + * @throws OpenShiftException + * + * @see #doSetExistingApplication(IApplication) + */ + public void setExistingApplicationName(String applicationName) + throws OpenShiftException { + firePropertyChange(PROPERTY_EXISTING_APPLICATION_NAME, + this.existingApplicationName, + this.existingApplicationName = applicationName); + + if (!StringUtils.isEmpty(applicationName) + && isExistingApplication(applicationName)) { + doSetExistingApplication(getExistingApplication(applicationName)); } - } public void loadExistingApplications() throws OpenShiftException { @@ -146,13 +153,17 @@ return existingApplicationsLoaded; } - public boolean isExistingApplication(String applicationName) { + public IApplication getExistingApplication(String applicationName) { for (IApplication application : getExistingApplications()) { if (application.getName().equalsIgnoreCase(applicationName)) { - return true; + return application; } } - return false; + return null; + } + + public boolean isExistingApplication(String applicationName) { + return getExistingApplication(applicationName) != null; } /** @@ -215,12 +226,46 @@ return cartridges; } - public void setExistingApplication(IApplication application) throws OpenShiftException { - if(application != null) { + /** + * Sets the existing application to this model. All properties that are + * related to an existing application are also set + * + * @param application + * @throws OpenShiftException + * + * @see #setExistingApplicationName(String) + * @see #setApplicationName(IApplication) + * @see #setSelectedCartridge(IApplication) + * @see #setSelectedEmbeddableCartridges(Set) + * @see #wizardModel#setApplication + */ + public void setExistingApplication(IApplication application) + throws OpenShiftException { + if (application != null) { setExistingApplicationName(application.getName()); + doSetExistingApplication(application); + } + } + + /** + * Sets the properties in this model that are related to an existing + * application. It does not set the name of the existing application!. + * + * @param application + * @throws OpenShiftException + * + * @see #setApplicationName(IApplication) + * @see #setSelectedCartridge(IApplication) + * @see #setSelectedEmbeddableCartridges(Set) + * @see #wizardModel#setApplication + */ + protected void doSetExistingApplication(IApplication application) + throws OpenShiftException { + if (application != null) { setApplicationName(application.getName()); setSelectedCartridge(application.getCartridge()); - setSelectedEmbeddableCartridges(new HashSet(application.getEmbeddedCartridges())); + setSelectedEmbeddableCartridges(new HashSet( + application.getEmbeddedCartridges())); wizardModel.setApplication(application); } }