]>
Commit | Line | Data |
---|---|---|
1b2798f6 EK |
1 | /******************************************************************************* |
2 | * Copyright (c) 2000, 2011 IBM Corporation and others. | |
3 | * All rights reserved. This program and the accompanying materials | |
4 | * are made available under the terms of the Eclipse Public License v1.0 | |
5 | * which accompanies this distribution, and is available at | |
6 | * http://www.eclipse.org/legal/epl-v10.html | |
7 | * | |
8 | * Contributors: | |
9 | * IBM Corporation - initial API and implementation | |
10 | *******************************************************************************/ | |
11 | package org.eclipse.jdt.internal.ui.preferences.cleanup; | |
12 | ||
13 | import java.util.ArrayList; | |
14 | import java.util.List; | |
15 | ||
16 | import org.eclipse.core.runtime.preferences.IEclipsePreferences; | |
17 | import org.eclipse.core.runtime.preferences.IScopeContext; | |
18 | ||
19 | import org.eclipse.jdt.internal.corext.fix.CleanUpConstants; | |
20 | ||
21 | import org.eclipse.jdt.ui.JavaUI; | |
22 | ||
23 | import org.eclipse.jdt.internal.ui.JavaPlugin; | |
24 | import org.eclipse.jdt.internal.ui.preferences.PreferencesAccess; | |
25 | import org.eclipse.jdt.internal.ui.preferences.formatter.IProfileVersioner; | |
26 | import org.eclipse.jdt.internal.ui.preferences.formatter.ProfileManager; | |
27 | ||
28 | public class CleanUpProfileManager extends ProfileManager { | |
29 | ||
30 | public static KeySet[] KEY_SETS= { | |
31 | new KeySet(JavaUI.ID_PLUGIN, new ArrayList<String>(JavaPlugin.getDefault().getCleanUpRegistry().getDefaultOptions(CleanUpConstants.DEFAULT_CLEAN_UP_OPTIONS).getKeys())) | |
32 | }; | |
33 | ||
34 | private final PreferencesAccess fPreferencesAccess; | |
35 | ||
36 | public CleanUpProfileManager(List<Profile> profiles, IScopeContext context, PreferencesAccess preferencesAccess, IProfileVersioner profileVersioner) { | |
37 | super(profiles, context, preferencesAccess, profileVersioner, KEY_SETS, CleanUpConstants.CLEANUP_PROFILE, CleanUpConstants.CLEANUP_SETTINGS_VERSION_KEY); | |
38 | fPreferencesAccess= preferencesAccess; | |
39 | } | |
40 | ||
41 | /* (non-Javadoc) | |
42 | * @see org.eclipse.jdt.internal.ui.preferences.cleanup.ProfileManager#getDefaultProfile() | |
43 | */ | |
44 | @Override | |
45 | public Profile getDefaultProfile() { | |
46 | return getProfile(CleanUpConstants.DEFAULT_PROFILE); | |
47 | } | |
48 | ||
49 | /** | |
50 | * {@inheritDoc} | |
51 | */ | |
52 | @Override | |
53 | protected void updateProfilesWithName(String oldName, Profile newProfile, boolean applySettings) { | |
54 | super.updateProfilesWithName(oldName, newProfile, applySettings); | |
55 | ||
56 | IEclipsePreferences node= fPreferencesAccess.getInstanceScope().getNode(JavaUI.ID_PLUGIN); | |
57 | String name= node.get(CleanUpConstants.CLEANUP_ON_SAVE_PROFILE, null); | |
58 | if (name != null && name.equals(oldName)) { | |
59 | if (newProfile == null) { | |
60 | node.remove(CleanUpConstants.CLEANUP_ON_SAVE_PROFILE); | |
61 | } else { | |
62 | node.put(CleanUpConstants.CLEANUP_ON_SAVE_PROFILE, newProfile.getID()); | |
63 | } | |
64 | } | |
65 | } | |
66 | ||
67 | } |