public void profileReplaced(CustomProfile oldProfile, CustomProfile newProfile) {
    fProfiles.remove(oldProfile.getID());
    fProfiles.put(newProfile.getID(), newProfile);
    fProfilesByName.remove(oldProfile);
    fProfilesByName.add(newProfile);
    Collections.sort(fProfilesByName);

    if (!oldProfile.isSharedProfile()) {
      updateProfilesWithName(oldProfile.getID(), null, false);
    }

    setSelected(newProfile);
    notifyObservers(PROFILE_CREATED_EVENT);
    notifyObservers(SELECTION_CHANGED_EVENT);
  }
  public void profileChanged(CustomProfile profile) {
    if (!profile.isSharedProfile()) {
      updateProfilesWithName(profile.getID(), profile, true);
    }

    notifyObservers(SETTINGS_CHANGED_EVENT);
  }
 /**
  * Set the selected profile. The profile must already be contained in this profile manager.
  *
  * @param profile The profile to select
  */
 public void setSelected(Profile profile) {
   final Profile newSelected = fProfiles.get(profile.getID());
   if (newSelected != null && !newSelected.equals(fSelected)) {
     fSelected = newSelected;
     notifyObservers(SELECTION_CHANGED_EVENT);
   }
 }
  public void profileRenamed(CustomProfile profile, String oldID) {
    fProfiles.remove(oldID);
    fProfiles.put(profile.getID(), profile);

    if (!profile.isSharedProfile()) {
      updateProfilesWithName(oldID, profile, false);
    }

    Collections.sort(fProfilesByName);
    notifyObservers(PROFILE_RENAMED_EVENT);
  }
 /**
  * Add a new custom profile to this profile manager.
  *
  * @param profile The profile to add
  */
 public void addProfile(CustomProfile profile) {
   profile.setManager(this);
   final CustomProfile oldProfile = (CustomProfile) fProfiles.get(profile.getID());
   if (oldProfile != null) {
     fProfiles.remove(oldProfile.getID());
     fProfilesByName.remove(oldProfile);
     oldProfile.setManager(null);
   }
   fProfiles.put(profile.getID(), profile);
   fProfilesByName.add(profile);
   Collections.sort(fProfilesByName);
   fSelected = profile;
   notifyObservers(PROFILE_CREATED_EVENT);
 }
  public boolean deleteProfile(CustomProfile profile) {
    int index = fProfilesByName.indexOf(profile);

    fProfiles.remove(profile.getID());
    fProfilesByName.remove(profile);

    profile.setManager(null);

    if (index >= fProfilesByName.size()) index--;
    fSelected = fProfilesByName.get(index);

    if (!profile.isSharedProfile()) {
      updateProfilesWithName(profile.getID(), null, false);
    }

    notifyObservers(PROFILE_DELETED_EVENT);
    return true;
  }
 /**
  * Notify observers with a message. The message must be one of the following:
  *
  * @param message Message to send out
  * @see #SELECTION_CHANGED_EVENT
  * @see #PROFILE_DELETED_EVENT
  * @see #PROFILE_RENAMED_EVENT
  * @see #PROFILE_CREATED_EVENT
  * @see #SETTINGS_CHANGED_EVENT
  */
 protected void notifyObservers(int message) {
   setChanged();
   notifyObservers(new Integer(message));
 }