use of org.eclipse.jdt.internal.ui.preferences.PreferencesAccess in project liferay-ide by liferay.
the class LiferayUIPlugin method _installLiferayFormatterProfile.
@SuppressWarnings({ "rawtypes", "unchecked" })
private void _installLiferayFormatterProfile() {
PreferencesAccess access = PreferencesAccess.getOriginalPreferences();
ProfileVersioner profileVersioner = new ProfileVersioner();
IScopeContext instanceScope = access.getInstanceScope();
try {
FormatterProfileStore store = new FormatterProfileStore(profileVersioner);
List profiles = store.readProfiles(instanceScope);
if (profiles == null) {
profiles = new ArrayList();
}
// add liferay profile
Profile eclipseProfile = new CustomProfile("Liferay [plug-in]", getLiferaySettings(), profileVersioner.getCurrentVersion(), profileVersioner.getProfileKind());
profiles.add(eclipseProfile);
store.writeProfiles(profiles, instanceScope);
// ProfileManager manager = new FormatterProfileManager(profiles,
// instanceScope, access, profileVersioner);
// manager.setSelected(eclipseProfile);
// manager.commitChanges(instanceScope);
instanceScope.getNode(JavaUI.ID_PLUGIN).flush();
} catch (Exception ex) {
ex.printStackTrace();
} finally {
try {
instanceScope.getNode(JavaCore.PLUGIN_ID).flush();
} catch (BackingStoreException bse) {
}
}
}
use of org.eclipse.jdt.internal.ui.preferences.PreferencesAccess in project eclipse-cs by checkstyle.
the class FormatterConfigWriter method writeCleanupSettings.
private void writeCleanupSettings(final Map<String, String> settings) {
PreferencesAccess access = PreferencesAccess.getOriginalPreferences();
IScopeContext instanceScope = access.getInstanceScope();
IScopeContext scope = access.getProjectScope(mProject);
IProfileVersioner versioner = new CleanUpProfileVersioner();
ProfileStore profilesStore = new ProfileStore(CleanUpConstants.CLEANUP_PROFILES, versioner);
try {
List<Profile> profiles = profilesStore.readProfiles(instanceScope);
if (profiles == null) {
profiles = new ArrayList<Profile>();
}
profiles.addAll(CleanUpPreferenceUtil.getBuiltInProfiles());
ProfileManager manager = new CleanUpProfileManager(profiles, scope, access, versioner);
CustomProfile myProfile = (CustomProfile) manager.getProfile(ProfileManager.ID_PREFIX + mNewProfileName);
if (myProfile == null) {
// take current settings and create new profile
Profile current = manager.getSelected();
myProfile = new CustomProfile(mNewProfileName, current.getSettings(), versioner.getCurrentVersion(), versioner.getProfileKind());
manager.addProfile(myProfile);
}
Map<String, String> joinedSettings = myProfile.getSettings();
joinedSettings.putAll(settings);
myProfile.setSettings(joinedSettings);
manager.setSelected(myProfile);
// writes profiles to the workspace profile store
profilesStore.writeProfiles(manager.getSortedProfiles(), instanceScope);
// commits changes to the project profile settings
manager.commitChanges(scope);
scope.getNode(JDT_UI_PLUGINID).flush();
scope.getNode(JavaCore.PLUGIN_ID).flush();
if (scope != instanceScope) {
instanceScope.getNode(JDT_UI_PLUGINID).flush();
instanceScope.getNode(JavaCore.PLUGIN_ID).flush();
}
} catch (CoreException e) {
CheckstyleLog.log(e, "Error storing cleanup profile");
} catch (BackingStoreException e) {
CheckstyleLog.log(e, "Error storing cleanup profile");
}
}
use of org.eclipse.jdt.internal.ui.preferences.PreferencesAccess in project eclipse-cs by checkstyle.
the class FormatterConfigWriter method writeFormatterSettings.
/**
* Method for writing all formatter-settings to disc.
*
* @param settings
* All the settings.
*/
private void writeFormatterSettings(final Map<String, String> settings) {
PreferencesAccess access = PreferencesAccess.getOriginalPreferences();
IScopeContext instanceScope = access.getInstanceScope();
IScopeContext scope = access.getProjectScope(mProject);
IProfileVersioner versioner = new ProfileVersioner();
ProfileStore profilesStore = new FormatterProfileStore(versioner);
try {
List<Profile> profiles = profilesStore.readProfiles(instanceScope);
if (profiles == null) {
profiles = new ArrayList<Profile>();
}
ProfileManager manager = new FormatterProfileManager(profiles, scope, access, versioner);
CustomProfile myProfile = (CustomProfile) manager.getProfile(ProfileManager.ID_PREFIX + mNewProfileName);
if (myProfile == null) {
// take current settings and create new profile
Profile current = manager.getSelected();
myProfile = new CustomProfile(mNewProfileName, current.getSettings(), versioner.getCurrentVersion(), versioner.getProfileKind());
manager.addProfile(myProfile);
}
Map<String, String> joinedSettings = myProfile.getSettings();
joinedSettings.putAll(settings);
myProfile.setSettings(joinedSettings);
manager.setSelected(myProfile);
// writes profiles to the workspace profile store
profilesStore.writeProfiles(manager.getSortedProfiles(), instanceScope);
// commits changes to the project profile settings
manager.commitChanges(scope);
scope.getNode(JDT_UI_PLUGINID).flush();
scope.getNode(JavaCore.PLUGIN_ID).flush();
if (scope != instanceScope) {
instanceScope.getNode(JDT_UI_PLUGINID).flush();
instanceScope.getNode(JavaCore.PLUGIN_ID).flush();
}
} catch (CoreException e) {
CheckstyleLog.log(e, "Error storing formatter profile");
} catch (BackingStoreException e) {
CheckstyleLog.log(e, "Error storing formatter profile");
}
}
use of org.eclipse.jdt.internal.ui.preferences.PreferencesAccess in project mdw-designer by CenturyLinkCloud.
the class WorkspaceConfigurator method setFormatter.
protected void setFormatter() {
IScopeContext instanceScope = InstanceScope.INSTANCE;
IEclipsePreferences uiPrefs = instanceScope.getNode(JavaUI.ID_PLUGIN);
if (getWorkspaceConfig().getCodeFormatter().equals(WorkspaceConfig.CODE_FORMATTERS[0]))
uiPrefs.put("formatter_profile", "_CenturyLinkIT");
else
uiPrefs.put("formatter_profile", "_MDWCodeFormatter");
try {
uiPrefs.flush();
uiPrefs.sync();
IProfileVersioner profileVersioner = new ProfileVersioner();
ProfileStore profileStore = new FormatterProfileStore(profileVersioner);
List<ProfileManager.Profile> profiles = profileStore.readProfiles(instanceScope);
if (profiles == null)
profiles = profileStore.readProfiles(DefaultScope.INSTANCE);
if (profiles == null)
profiles = new ArrayList<>();
WorkingCopyManager workingCopyManager = new WorkingCopyManager();
PreferencesAccess access = PreferencesAccess.getWorkingCopyPreferences(workingCopyManager);
ProfileManager profileManager = new FormatterProfileManager(profiles, instanceScope, access, profileVersioner);
profileManager.commitChanges(instanceScope);
} catch (Exception ex) {
PluginMessages.uiError(getShell(), ex, "Set Code Formatter");
}
}
Aggregations