[jbosstools-commits] JBoss Tools SVN: r41767 - in trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui: wizard and 1 other directory.

jbosstools-commits at lists.jboss.org jbosstools-commits at lists.jboss.org
Thu Jun 7 08:42:38 EDT 2012


Author: xcoulon
Date: 2012-06-07 08:42:38 -0400 (Thu, 07 Jun 2012)
New Revision: 41767

Added:
   trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/utils/OpenShiftUserPreferencesProvider.java
Modified:
   trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ApplicationConfigurationWizardPageModel.java
Log:
Fixed - JBIDE-12119
default for apptype should be unselected, use last selected one if possible

Added: trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/utils/OpenShiftUserPreferencesProvider.java
===================================================================
--- trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/utils/OpenShiftUserPreferencesProvider.java	                        (rev 0)
+++ trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/utils/OpenShiftUserPreferencesProvider.java	2012-06-07 12:42:38 UTC (rev 41767)
@@ -0,0 +1,46 @@
+/******************************************************************************* 
+ * 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.ui.utils;
+
+import org.eclipse.core.runtime.preferences.IEclipsePreferences;
+import org.eclipse.core.runtime.preferences.InstanceScope;
+import org.jboss.tools.openshift.express.internal.ui.OpenShiftUIActivator;
+
+/**
+ * A small utility class that accesses the preferences to keep the last
+ * cartridge that a user selected to create an OpenShift Application.
+ * 
+ * @author Xavier Coulon
+ * 
+ */
+public class OpenShiftUserPreferencesProvider {
+
+	private static final String LAST_SELECTED_CARTRIDGE_KEY = OpenShiftUIActivator.PLUGIN_ID + ".lastSelectedCartridge";
+
+	/**
+	 * @return the last selected value, or null if that preference does not exist yet.
+	 */
+	public String getLastSelectedCartridgeName() {
+		// Find the last-selected one
+		IEclipsePreferences prefs = InstanceScope.INSTANCE.getNode(OpenShiftUIActivator.PLUGIN_ID);
+		return prefs.get(LAST_SELECTED_CARTRIDGE_KEY, null);
+	}
+
+	/**
+	 * Stores the given cartridge name in the preferences.
+	 * @param name
+	 */
+	public void setLastSelectedCartridgeName(String name) {
+		IEclipsePreferences prefs = InstanceScope.INSTANCE.getNode(OpenShiftUIActivator.PLUGIN_ID);
+		prefs.put(LAST_SELECTED_CARTRIDGE_KEY, name);
+	}
+
+}


Property changes on: trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/utils/OpenShiftUserPreferencesProvider.java
___________________________________________________________________
Added: svn:mime-type
   + text/plain

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-06-07 12:35:43 UTC (rev 41766)
+++ trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ApplicationConfigurationWizardPageModel.java	2012-06-07 12:42:38 UTC (rev 41767)
@@ -21,6 +21,7 @@
 import org.jboss.tools.openshift.express.internal.core.CartridgeNameComparator;
 import org.jboss.tools.openshift.express.internal.core.console.UserDelegate;
 import org.jboss.tools.openshift.express.internal.ui.utils.Logger;
+import org.jboss.tools.openshift.express.internal.ui.utils.OpenShiftUserPreferencesProvider;
 import org.jboss.tools.openshift.express.internal.ui.utils.StringUtils;
 
 import com.openshift.client.ApplicationScale;
@@ -61,7 +62,8 @@
 	private List<IGearProfile> gearProfiles = new ArrayList<IGearProfile>();
 	private List<IEmbeddableCartridge> embeddedCartridges = new ArrayList<IEmbeddableCartridge>();
 	private String existingApplicationName;
-	private boolean existingApplicationsLoaded = false;;
+	private boolean existingApplicationsLoaded = false;
+	private OpenShiftUserPreferencesProvider openShiftUserPreferencesProvider = new OpenShiftUserPreferencesProvider();
 
 	public ApplicationConfigurationWizardPageModel(OpenShiftExpressApplicationWizardModel wizardModel)
 			throws OpenShiftException {
@@ -207,7 +209,9 @@
 	public void setCartridges(List<ICartridge> cartridges) {
 		Collections.sort(cartridges, new CartridgeNameComparator());
 		firePropertyChange(PROPERTY_CARTRIDGES, this.cartridges, this.cartridges = cartridges);
-		setSelectedCartridge(ICartridge.JBOSSAS_7);
+		final String lastSelectedCartridgeName = openShiftUserPreferencesProvider.getLastSelectedCartridgeName();
+		final ICartridge selectedCartridge = getCartridgeByName(lastSelectedCartridgeName);
+		setSelectedCartridge(selectedCartridge);
 	}
 
 	public List<ICartridge> getCartridges() {
@@ -243,7 +247,7 @@
 
 	public IGearProfile getGearProfileByName(String name) {
 		List<IGearProfile> gearProfiles = getGearProfiles();
-		if (gearProfiles == null) {
+		if (gearProfiles == null || name == null) {
 			return null;
 		}
 
@@ -258,6 +262,23 @@
 		return matchingGearProfile;
 	}
 
+	public ICartridge getCartridgeByName(String name) {
+		List<ICartridge> cartridges = getCartridges();
+		if (cartridges == null || name == null) {
+			return null;
+		}
+
+		ICartridge matchingCartridge = null;
+		for (ICartridge cartridge : cartridges) {
+			if (name.equals(cartridge.getName())) {
+				matchingCartridge = cartridge;
+				break;
+			}
+		}
+
+		return matchingCartridge;
+	}
+	
 	/**
 	 * forces property change listeners to update their value
 	 */
@@ -271,6 +292,9 @@
 		firePropertyChange(PROPERTY_SELECTED_CARTRIDGE
 				, wizardModel.getApplicationCartridge()
 				, wizardModel.setApplicationCartridge(cartridge));
+		if(cartridge != null) {
+			openShiftUserPreferencesProvider.setLastSelectedCartridgeName(cartridge.getName());
+		}
 	}
 
 	protected void setSelectedCartridge(IApplication application) {



More information about the jbosstools-commits mailing list