[jbosstools-commits] JBoss Tools SVN: r39409 - trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard.

jbosstools-commits at lists.jboss.org jbosstools-commits at lists.jboss.org
Fri Mar 9 10:58:07 EST 2012


Author: adietish
Date: 2012-03-09 10:58:06 -0500 (Fri, 09 Mar 2012)
New Revision: 39409

Modified:
   trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ApplicationConfigurationWizardPage.java
   trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ApplicationConfigurationWizardPageModel.java
Log:
[JBIDE-11240] setting the exsting application when the it's name is set to the model and it matches an existing application (was: only happened when browsing and selecting the application)

Modified: trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ApplicationConfigurationWizardPage.java
===================================================================
--- trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ApplicationConfigurationWizardPage.java	2012-03-09 15:43:14 UTC (rev 39408)
+++ trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ApplicationConfigurationWizardPage.java	2012-03-09 15:58:06 UTC (rev 39409)
@@ -207,7 +207,7 @@
 					final IApplication selectedApplication = appSelectionDialog.getSelectedApplication();
 					if (selectedApplication != null) {
 						try {
-							pageModel.setExistingApplication(selectedApplication);
+							pageModel.setExistingApplicationName(selectedApplication.getName());
 						} catch (OpenShiftException ex) {
 							OpenShiftUIActivator.log(OpenShiftUIActivator.createErrorStatus(NLS.bind(
 									"Could not get embedded cartridges for application {0}",

Modified: trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ApplicationConfigurationWizardPageModel.java
===================================================================
--- trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ApplicationConfigurationWizardPageModel.java	2012-03-09 15:43:14 UTC (rev 39408)
+++ trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ApplicationConfigurationWizardPageModel.java	2012-03-09 15:58:06 UTC (rev 39409)
@@ -21,6 +21,7 @@
 import org.jboss.tools.openshift.express.internal.core.console.UserDelegate;
 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,7 +49,7 @@
 
 	// start with a null value as a marker of non-initialized state (used during
 	// first pass validation)
-	private List<IApplication> existingApplications = null;
+	private List<IApplication> existingApplications = new ArrayList<IApplication>();
 	private List<ICartridge> cartridges = new ArrayList<ICartridge>();
 	private List<IEmbeddableCartridge> embeddableCartridges = new ArrayList<IEmbeddableCartridge>();
 	private String existingApplicationName;
@@ -111,21 +112,24 @@
 		return existingApplicationName;
 	}
 
+	/**
+	 * 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
-				, 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<IEmbeddableCartridge>(
-							application.getEmbeddedCartridges()));
-				}
-			}
+				, this.existingApplicationName, this.existingApplicationName = applicationName);
+
+		if (!StringUtils.isEmpty(applicationName)
+				&& isExistingApplication(applicationName)) {
+			doSetExistingApplication(getExistingApplication(applicationName));
 		}
-	
 	}
 
 	public void loadExistingApplications() throws OpenShiftException {
@@ -146,15 +150,19 @@
 		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;
+	}
+
 	/**
 	 * @param existingApplications
 	 *            the existingApplications to set
@@ -215,9 +223,40 @@
 		return cartridges;
 	}
 
+	/**
+	 * Sets the properties in this model that are related to an existing
+	 * application. The name of the existing application is 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) {
+		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<IEmbeddableCartridge>(application.getEmbeddedCartridges()));
@@ -226,7 +265,7 @@
 	}
 
 	public void resetExistingApplication() throws OpenShiftException {
-		setExistingApplication(null);
+		setExistingApplication((IApplication) null);
 	}
 
 	public void setApplicationName(String applicationName) {



More information about the jbosstools-commits mailing list