From 7d7e7cdde5773cc51bf7319dc36c1fa9bde2008a Mon Sep 17 00:00:00 2001 From: David Dykstal Date: Wed, 20 Sep 2006 17:40:34 +0000 Subject: [PATCH] Bug 153255 - enabled creation of new profiles as a side effect of this bug --- .../ui/actions/SystemNewProfileAction.java | 30 +- .../internal/model/SystemProfileManager.java | 717 ++++++++---------- 2 files changed, 325 insertions(+), 422 deletions(-) diff --git a/rse/plugins/org.eclipse.rse.ui/UI/org/eclipse/rse/ui/actions/SystemNewProfileAction.java b/rse/plugins/org.eclipse.rse.ui/UI/org/eclipse/rse/ui/actions/SystemNewProfileAction.java index 5e5c2f28eae..c04c1561ee9 100644 --- a/rse/plugins/org.eclipse.rse.ui/UI/org/eclipse/rse/ui/actions/SystemNewProfileAction.java +++ b/rse/plugins/org.eclipse.rse.ui/UI/org/eclipse/rse/ui/actions/SystemNewProfileAction.java @@ -17,8 +17,6 @@ package org.eclipse.rse.ui.actions; import org.eclipse.jface.wizard.IWizard; -import org.eclipse.rse.core.model.ISystemProfile; -import org.eclipse.rse.model.SystemStartHere; import org.eclipse.rse.ui.ISystemContextMenuConstants; import org.eclipse.rse.ui.ISystemIconConstants; import org.eclipse.rse.ui.RSEUIPlugin; @@ -66,18 +64,26 @@ public class SystemNewProfileAction extends SystemBaseWizardAction { setEnabled(isEnabled()); } - /** - * We disable this action if it is a new workspace and the user has yet to create - * their first connection, and hence rename their default profile. - * @return true if the action is enabled + /* (non-Javadoc) + * @see org.eclipse.rse.ui.actions.SystemBaseAction#isEnabled() */ public boolean isEnabled() { - // defect 43428... - ISystemProfile defaultProfile = SystemStartHere.getSystemProfileManager().getDefaultPrivateSystemProfile(); - if (defaultProfile != null) - return false; - else - return true; + return true; + /* + * From the old javadoc: + * We disable this action if it is a new workspace and the user has yet to create + * their first connection, and hence rename their default profile. + * @return true if the action is enabled + * + * defect 43428 was an early RSE defect whose fix prevented the creation of profiles until the first + * connection was created. However, new default profiles are created when RSE is initially activated + * so there is no need to inhibit profile creation. + */ +// ISystemProfile defaultProfile = SystemStartHere.getSystemProfileManager().getDefaultPrivateSystemProfile(); +// if (defaultProfile != null) +// return false; +// else +// return true; } /** diff --git a/rse/plugins/org.eclipse.rse.ui/model/org/eclipse/rse/internal/model/SystemProfileManager.java b/rse/plugins/org.eclipse.rse.ui/model/org/eclipse/rse/internal/model/SystemProfileManager.java index 1d44a898cc9..9084815e5f4 100644 --- a/rse/plugins/org.eclipse.rse.ui/model/org/eclipse/rse/internal/model/SystemProfileManager.java +++ b/rse/plugins/org.eclipse.rse.ui/model/org/eclipse/rse/internal/model/SystemProfileManager.java @@ -15,6 +15,7 @@ ********************************************************************************/ package org.eclipse.rse.internal.model; + import java.util.ArrayList; import java.util.List; import java.util.Vector; @@ -34,34 +35,31 @@ import org.eclipse.rse.ui.validators.ValidatorProfileName; * A class that manages a list of SystemProfile objects. * This should be used as a singleton. */ -public class SystemProfileManager implements ISystemProfileManager -{ - private List _profiles = null; - private String[] profileNames = null; - private Vector profileNamesVector = null; - private static ISystemProfileManager singleton = null; +public class SystemProfileManager implements ISystemProfileManager { + private List _profiles = null; + private String[] profileNames = null; + private Vector profileNamesVector = null; + private static ISystemProfileManager singleton = null; private static final String PROFILE_FILE_NAME = "profile"; //$NON-NLS-1$ - -/** + + /** * Default constructor */ - protected SystemProfileManager() - { + protected SystemProfileManager() { super(); } + /** - * Return (and create if necessary) the singleton instance of this class. + * @return (and create if necessary) the singleton instance of this class. */ - public static ISystemProfileManager getSystemProfileManager() - { - if (singleton == null) - { + public static ISystemProfileManager getSystemProfileManager() { + if (singleton == null) { singleton = new SystemProfileManager(); RSEUIPlugin.getThePersistenceManager().restore(singleton); // restores all of RSE } return singleton; } - + /** * @return the name of the default private system profile. */ @@ -78,15 +76,14 @@ public class SystemProfileManager implements ISystemProfileManager } return name; } - + /** * Clear the default after a team sychronization say */ - public static void clearDefault() - { + public static void clearDefault() { singleton = null; } - + /** * Create a new profile with the given name, and add to the list. * The name must be unique within the existing list. @@ -96,541 +93,441 @@ public class SystemProfileManager implements ISystemProfileManager * @param name What to name this profile * @param makeActive true if this profile is to be added to the active profile list. * @return new profile, or null if name not unique. + * @see ISystemProfileManager#createSystemProfile(String, boolean) */ - public ISystemProfile createSystemProfile(String name, boolean makeActive) - { - // FIXME + public ISystemProfile createSystemProfile(String name, boolean makeActive) { + // FIXME - used to use MOF ISystemProfile existingProfile = getSystemProfile(name); - if (existingProfile != null) - { + if (existingProfile != null) { deleteSystemProfile(existingProfile); // replace the existing one with a new profile } - + ISystemProfile newProfile = internalCreateSystemProfileAndFolder(name); - if (makeActive) - { - SystemPreferencesManager.getPreferencesManager().addActiveProfile(name); - ((SystemProfile)newProfile).setActive(makeActive); - } + if (makeActive) { + SystemPreferencesManager.getPreferencesManager().addActiveProfile(name); + ((SystemProfile) newProfile).setActive(makeActive); + } RSEUIPlugin.getThePersistenceManager().commit(this); return newProfile; } - - /** - * Toggle an existing profile's state between active and inactive + + /* (non-Javadoc) + * @see org.eclipse.rse.core.model.ISystemProfileManager#makeSystemProfileActive(org.eclipse.rse.core.model.ISystemProfile, boolean) */ - public void makeSystemProfileActive(ISystemProfile profile, boolean makeActive) - { - boolean wasActive = isSystemProfileActive(profile.getName()); + public void makeSystemProfileActive(ISystemProfile profile, boolean makeActive) { + boolean wasActive = isSystemProfileActive(profile.getName()); if (wasActive && !makeActive) - SystemPreferencesManager.getPreferencesManager().deleteActiveProfile(profile.getName()); - else if (makeActive && !wasActive) - SystemPreferencesManager.getPreferencesManager().addActiveProfile(profile.getName()); - ((SystemProfile)profile).setActive(makeActive); - } - - /* - * private version that avoids name collision check - */ - private ISystemProfile internalCreateSystemProfile(String name) - { - ISystemProfile profile = new SystemProfile(); - - // FIXME initMOF().createSystemProfile(); - initialize(profile, name); - profile.setDefaultPrivate(name.equalsIgnoreCase(getDefaultPrivateSystemProfileName())); - //System.out.println("initializing new profile " + name + ", is default private? " + profile.isDefaultPrivate()); - return profile; + SystemPreferencesManager.getPreferencesManager().deleteActiveProfile(profile.getName()); + else if (makeActive && !wasActive) SystemPreferencesManager.getPreferencesManager().addActiveProfile(profile.getName()); + ((SystemProfile) profile).setActive(makeActive); } /* * private version that avoids name collision check */ - private ISystemProfile internalCreateSystemProfileAndFolder(String name) - { - ISystemProfile profile = internalCreateSystemProfile(name); -// SystemResourceManager.getProfileFolder(profile); // creates proj/profileName folder DWD This is where those pesky folders get created - return profile; + private ISystemProfile internalCreateSystemProfile(String name) { + ISystemProfile profile = new SystemProfile(); + initialize(profile, name); + profile.setDefaultPrivate(name.equalsIgnoreCase(getDefaultPrivateSystemProfileName())); + return profile; } - + + /* + * private version that avoids name collision check + */ + private ISystemProfile internalCreateSystemProfileAndFolder(String name) { + ISystemProfile profile = internalCreateSystemProfile(name); + // FIXME This is where the old style folders get created for profiles. + // This is no longer needed but + // SystemResourceManager.getProfileFolder(profile); // creates proj/profileName folder + return profile; + } + /* * private method to initialize state for new profile */ - private void initialize(ISystemProfile profile, String name) - { + private void initialize(ISystemProfile profile, String name) { profile.setName(name); profile.setProfileManager(this); getProfiles().add(profile); - invalidateCache(); + invalidateCache(); } - - /** - * Get an array of all existing profiles. + + /* (non-Javadoc) + * @see org.eclipse.rse.core.model.ISystemProfileManager#getSystemProfiles() */ - public ISystemProfile[] getSystemProfiles() - { + public ISystemProfile[] getSystemProfiles() { List profiles = getProfiles(); - // Ensure that one Profile is the default Profile - defect 48995 NH boolean defaultProfileExist = false; - for (int idx=0; (!defaultProfileExist) && (idx - *
  • Rename the profile in memory - *
  • Rename the underlying folder - *
  • Update the user preferences if this profile is currently active. - * + + /* (non-Javadoc) + * @see org.eclipse.rse.core.model.ISystemProfileManager#renameSystemProfile(org.eclipse.rse.core.model.ISystemProfile, java.lang.String) */ - public void renameSystemProfile(ISystemProfile profile, String newName) - { + public void renameSystemProfile(ISystemProfile profile, String newName) { boolean isActive = isSystemProfileActive(profile.getName()); String oldName = profile.getName(); profile.setName(newName); - if (isActive) - SystemPreferencesManager.getPreferencesManager().renameActiveProfile(oldName, newName); - invalidateCache(); + if (isActive) SystemPreferencesManager.getPreferencesManager().renameActiveProfile(oldName, newName); + invalidateCache(); // FIXME RSEUIPlugin.getThePersistenceManager().save(this); } - - /** - * Delete the given profile - * This will: - *
      - *
    • Delete the profile in memory - *
    • Delete the underlying folder - *
    • Update the user preferences if this profile is currently active. - *
    + + /* (non-Javadoc) + * @see org.eclipse.rse.core.model.ISystemProfileManager#deleteSystemProfile(org.eclipse.rse.core.model.ISystemProfile) */ - public void deleteSystemProfile(ISystemProfile profile) - { + public void deleteSystemProfile(ISystemProfile profile) { String oldName = profile.getName(); boolean isActive = isSystemProfileActive(oldName); - - getProfiles().remove(profile); - /* FIXME - // now in EMF, the profiles are "owned" by the Resource, and only referenced by the profile manager, - // so I don't think just removing it from the manager is enough... it must also be removed from its - // resource. Phil. - Resource res = profile.eResource(); - if (res != null) - res.getContents().remove(profile); -*/ - if (isActive) - SystemPreferencesManager.getPreferencesManager().deleteActiveProfile(oldName); - invalidateCache(); - - //FIXME RSEUIPlugin.getThePersistenceManager().save(this); - + getProfiles().remove(profile); + /* FIXME in EMF the profiles are "owned" by the Resource, and only referenced by the profile manager, + * so just removing it from the manager is not enough, it must also be removed from its resource. + * No longer needed since EMF is not in use. + * Resource res = profile.eResource(); + * if (res != null) + * res.getContents().remove(profile); + */ + if (isActive) SystemPreferencesManager.getPreferencesManager().deleteActiveProfile(oldName); + invalidateCache(); + // FIXME RSEUIPlugin.getThePersistenceManager().save(this); } - /** - * Clone the given profile to a new one with the given name. - * Pretty useless right now, as there is no data to clone! + /* (non-Javadoc) + * @see org.eclipse.rse.core.model.ISystemProfileManager#cloneSystemProfile(org.eclipse.rse.core.model.ISystemProfile, java.lang.String) */ - public ISystemProfile cloneSystemProfile(ISystemProfile profile, String newName) - { + public ISystemProfile cloneSystemProfile(ISystemProfile profile, String newName) { ISystemProfile newProfile = createSystemProfile(newName, false); return newProfile; } - /** - * Return true if the given profile is active. - * @see ISystemProfile#isActive() - */ - public boolean isSystemProfileActive(String profileName) - { - String[] activeProfiles = getActiveSystemProfileNames(); - boolean match = false; - for (int idx=0; !match && (idx