Index: src/org/jboss/tools/openshift/express/internal/ui/wizard/ApplicationConfigurationWizardPageModel.java =================================================================== --- src/org/jboss/tools/openshift/express/internal/ui/wizard/ApplicationConfigurationWizardPageModel.java (revision 41749) +++ src/org/jboss/tools/openshift/express/internal/ui/wizard/ApplicationConfigurationWizardPageModel.java (working copy) @@ -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 gearProfiles = new ArrayList(); private List embeddedCartridges = new ArrayList(); 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 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 getCartridges() { @@ -243,7 +247,7 @@ public IGearProfile getGearProfileByName(String name) { List gearProfiles = getGearProfiles(); - if (gearProfiles == null) { + if (gearProfiles == null || name == null) { return null; } @@ -258,6 +262,23 @@ return matchingGearProfile; } + public ICartridge getCartridgeByName(String name) { + List 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) { Index: src/org/jboss/tools/openshift/express/internal/ui/utils/OpenShiftUserPreferencesProvider.java =================================================================== --- src/org/jboss/tools/openshift/express/internal/ui/utils/OpenShiftUserPreferencesProvider.java (revision 0) +++ src/org/jboss/tools/openshift/express/internal/ui/utils/OpenShiftUserPreferencesProvider.java (revision 0) @@ -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); + } + +}