public void profileChanged(CustomProfile profile) { if (!profile.isSharedProfile()) { updateProfilesWithName(profile.getID(), profile, true); } notifyObservers(SETTINGS_CHANGED_EVENT); }
@Override public Profile rename(String name, ProfileManager manager) { CustomProfile profile = new CustomProfile(name.trim(), getSettings(), getVersion(), getKind()); profile.setManager(manager); manager.profileReplaced(this, profile); return profile; }
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); setSelected(newProfile); }
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); }
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 addProfile(IProfile profile) { if (profile instanceof CustomProfile) { CustomProfile newProfile = (CustomProfile) profile; // newProfile.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 = newProfile; fDirty = true; } }
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; }
public boolean deleteProfile(IProfile profile) { if (profile instanceof CustomProfile) { CustomProfile oldProfile = (CustomProfile) profile; int index = fProfilesByName.indexOf(profile); fProfiles.remove(oldProfile.getID()); fProfilesByName.remove(oldProfile); // oldProfile.setManager(null); if (index >= fProfilesByName.size()) index--; fSelected = fProfilesByName.get(index); fDirty = true; return true; } return false; }
/** * Only to read project specific settings to find out to what profile it matches. * * @param context The project context */ private Map<String, String> readFromPreferenceStore( IScopeContext context, Profile workspaceProfile) { final Map<String, String> profileOptions = new HashMap<String, String>(); IEclipsePreferences uiPrefs = context.getNode(JavaUI.ID_PLUGIN); int version = uiPrefs.getInt(fProfileVersionKey, fProfileVersioner.getFirstVersion()); if (version != fProfileVersioner.getCurrentVersion()) { Map<String, String> allOptions = new HashMap<String, String>(); for (int i = 0; i < fKeySets.length; i++) { addAll(context.getNode(fKeySets[i].getNodeName()), allOptions); } CustomProfile profile = new CustomProfile( "tmp", allOptions, version, fProfileVersioner.getProfileKind()); // $NON-NLS-1$ fProfileVersioner.update(profile); return profile.getSettings(); } boolean hasValues = false; for (int i = 0; i < fKeySets.length; i++) { KeySet keySet = fKeySets[i]; IEclipsePreferences preferences = context.getNode(keySet.getNodeName()); for (final Iterator<String> keyIter = keySet.getKeys().iterator(); keyIter.hasNext(); ) { final String key = keyIter.next(); String val = preferences.get(key, null); if (val != null) { hasValues = true; } else { val = workspaceProfile.getSettings().get(key); } profileOptions.put(key, val); } } if (!hasValues) { return null; } setLatestCompliance(profileOptions); return profileOptions; }
public IProfile rename(IProfile profile, String newName) { final String trimmed = newName.trim(); if (trimmed.equals(profile.getName())) return profile; if (profile.isBuiltInProfile()) { CustomProfile newProfile = new CustomProfile( trimmed, profile.getSettings(), profile.getFormatterId(), profile.getVersion()); addProfile(newProfile); fDirty = true; return newProfile; } else { CustomProfile cProfile = (CustomProfile) profile; String oldID = profile.getID(); cProfile.fName = trimmed; fProfiles.remove(oldID); fProfiles.put(profile.getID(), profile); Collections.sort(fProfilesByName); fDirty = true; return cProfile; } }
/** * 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); }
/** * Create and initialize a new profile manager. * * @param profiles Initial custom profiles (List of type <code>CustomProfile</code>) * @param profileVersioner */ public ProfileManager( List<Profile> profiles, IScopeContext context, PreferencesAccess preferencesAccess, IProfileVersioner profileVersioner, KeySet[] keySets, String profileKey, String profileVersionKey) { fPreferencesAccess = preferencesAccess; fProfileVersioner = profileVersioner; fKeySets = keySets; fProfileKey = profileKey; fProfileVersionKey = profileVersionKey; fProfiles = new HashMap<String, Profile>(); fProfilesByName = new ArrayList<Profile>(); for (final Iterator<Profile> iter = profiles.iterator(); iter.hasNext(); ) { final Profile profile = iter.next(); if (profile instanceof CustomProfile) { ((CustomProfile) profile).setManager(this); } fProfiles.put(profile.getID(), profile); fProfilesByName.add(profile); } Collections.sort(fProfilesByName); String profileId = getSelectedProfileId(fPreferencesAccess.getInstanceScope()); Profile profile = fProfiles.get(profileId); if (profile == null) { profile = getDefaultProfile(); } fSelected = profile; if (context.getName() == ProjectScope.SCOPE && hasProjectSpecificSettings(context)) { Map<String, String> map = readFromPreferenceStore(context, profile); if (map != null) { List<String> allKeys = new ArrayList<String>(); for (int i = 0; i < fKeySets.length; i++) { allKeys.addAll(fKeySets[i].getKeys()); } Collections.sort(allKeys); Profile matching = null; String projProfileId = context.getNode(JavaUI.ID_PLUGIN).get(fProfileKey, null); if (projProfileId != null) { Profile curr = fProfiles.get(projProfileId); if (curr != null && (curr.isBuiltInProfile() || curr.hasEqualSettings(map, allKeys))) { matching = curr; } } else { // old version: look for similar for (final Iterator<Profile> iter = fProfilesByName.iterator(); iter.hasNext(); ) { Profile curr = iter.next(); if (curr.hasEqualSettings(map, allKeys)) { matching = curr; break; } } } if (matching == null) { String name; if (projProfileId != null && !fProfiles.containsKey(projProfileId)) { name = Messages.format( FormatterMessages.ProfileManager_unmanaged_profile_with_name, projProfileId.substring(ID_PREFIX.length())); } else { name = FormatterMessages.ProfileManager_unmanaged_profile; } // current settings do not correspond to any profile -> create a 'team' profile SharedProfile shared = new SharedProfile( name, map, fProfileVersioner.getCurrentVersion(), fProfileVersioner.getProfileKind()); shared.setManager(this); fProfiles.put(shared.getID(), shared); fProfilesByName.add(shared); // add last matching = shared; } fSelected = matching; } } }