Search in sources :

Example 1 with Profile

use of org.eclipse.jdt.internal.ui.preferences.formatter.ProfileManager.Profile 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) {
        }
    }
}
Also used : IScopeContext(org.eclipse.core.runtime.preferences.IScopeContext) ProfileVersioner(org.eclipse.jdt.internal.ui.preferences.formatter.ProfileVersioner) ArrayList(java.util.ArrayList) BackingStoreException(org.osgi.service.prefs.BackingStoreException) PreferencesAccess(org.eclipse.jdt.internal.ui.preferences.PreferencesAccess) List(java.util.List) ArrayList(java.util.ArrayList) CustomProfile(org.eclipse.jdt.internal.ui.preferences.formatter.ProfileManager.CustomProfile) FormatterProfileStore(org.eclipse.jdt.internal.ui.preferences.formatter.FormatterProfileStore) Profile(org.eclipse.jdt.internal.ui.preferences.formatter.ProfileManager.Profile) CustomProfile(org.eclipse.jdt.internal.ui.preferences.formatter.ProfileManager.CustomProfile) URISyntaxException(java.net.URISyntaxException) CoreException(org.eclipse.core.runtime.CoreException) BackingStoreException(org.osgi.service.prefs.BackingStoreException)

Example 2 with Profile

use of org.eclipse.jdt.internal.ui.preferences.formatter.ProfileManager.Profile 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");
    }
}
Also used : FormatterProfileManager(org.eclipse.jdt.internal.ui.preferences.formatter.FormatterProfileManager) ProfileManager(org.eclipse.jdt.internal.ui.preferences.formatter.ProfileManager) CleanUpProfileManager(org.eclipse.jdt.internal.ui.preferences.cleanup.CleanUpProfileManager) BackingStoreException(org.osgi.service.prefs.BackingStoreException) PreferencesAccess(org.eclipse.jdt.internal.ui.preferences.PreferencesAccess) CustomProfile(org.eclipse.jdt.internal.ui.preferences.formatter.ProfileManager.CustomProfile) ProfileStore(org.eclipse.jdt.internal.ui.preferences.formatter.ProfileStore) FormatterProfileStore(org.eclipse.jdt.internal.ui.preferences.formatter.FormatterProfileStore) Profile(org.eclipse.jdt.internal.ui.preferences.formatter.ProfileManager.Profile) CustomProfile(org.eclipse.jdt.internal.ui.preferences.formatter.ProfileManager.CustomProfile) IScopeContext(org.eclipse.core.runtime.preferences.IScopeContext) CleanUpProfileManager(org.eclipse.jdt.internal.ui.preferences.cleanup.CleanUpProfileManager) CoreException(org.eclipse.core.runtime.CoreException) CleanUpProfileVersioner(org.eclipse.jdt.internal.ui.preferences.cleanup.CleanUpProfileVersioner) IProfileVersioner(org.eclipse.jdt.internal.ui.preferences.formatter.IProfileVersioner)

Example 3 with Profile

use of org.eclipse.jdt.internal.ui.preferences.formatter.ProfileManager.Profile 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");
    }
}
Also used : FormatterProfileManager(org.eclipse.jdt.internal.ui.preferences.formatter.FormatterProfileManager) ProfileManager(org.eclipse.jdt.internal.ui.preferences.formatter.ProfileManager) CleanUpProfileManager(org.eclipse.jdt.internal.ui.preferences.cleanup.CleanUpProfileManager) BackingStoreException(org.osgi.service.prefs.BackingStoreException) PreferencesAccess(org.eclipse.jdt.internal.ui.preferences.PreferencesAccess) CustomProfile(org.eclipse.jdt.internal.ui.preferences.formatter.ProfileManager.CustomProfile) ProfileStore(org.eclipse.jdt.internal.ui.preferences.formatter.ProfileStore) FormatterProfileStore(org.eclipse.jdt.internal.ui.preferences.formatter.FormatterProfileStore) FormatterProfileStore(org.eclipse.jdt.internal.ui.preferences.formatter.FormatterProfileStore) Profile(org.eclipse.jdt.internal.ui.preferences.formatter.ProfileManager.Profile) CustomProfile(org.eclipse.jdt.internal.ui.preferences.formatter.ProfileManager.CustomProfile) IScopeContext(org.eclipse.core.runtime.preferences.IScopeContext) CleanUpProfileVersioner(org.eclipse.jdt.internal.ui.preferences.cleanup.CleanUpProfileVersioner) ProfileVersioner(org.eclipse.jdt.internal.ui.preferences.formatter.ProfileVersioner) IProfileVersioner(org.eclipse.jdt.internal.ui.preferences.formatter.IProfileVersioner) CoreException(org.eclipse.core.runtime.CoreException) FormatterProfileManager(org.eclipse.jdt.internal.ui.preferences.formatter.FormatterProfileManager) IProfileVersioner(org.eclipse.jdt.internal.ui.preferences.formatter.IProfileVersioner)

Aggregations

CoreException (org.eclipse.core.runtime.CoreException)3 IScopeContext (org.eclipse.core.runtime.preferences.IScopeContext)3 PreferencesAccess (org.eclipse.jdt.internal.ui.preferences.PreferencesAccess)3 FormatterProfileStore (org.eclipse.jdt.internal.ui.preferences.formatter.FormatterProfileStore)3 CustomProfile (org.eclipse.jdt.internal.ui.preferences.formatter.ProfileManager.CustomProfile)3 Profile (org.eclipse.jdt.internal.ui.preferences.formatter.ProfileManager.Profile)3 BackingStoreException (org.osgi.service.prefs.BackingStoreException)3 CleanUpProfileManager (org.eclipse.jdt.internal.ui.preferences.cleanup.CleanUpProfileManager)2 CleanUpProfileVersioner (org.eclipse.jdt.internal.ui.preferences.cleanup.CleanUpProfileVersioner)2 FormatterProfileManager (org.eclipse.jdt.internal.ui.preferences.formatter.FormatterProfileManager)2 IProfileVersioner (org.eclipse.jdt.internal.ui.preferences.formatter.IProfileVersioner)2 ProfileManager (org.eclipse.jdt.internal.ui.preferences.formatter.ProfileManager)2 ProfileStore (org.eclipse.jdt.internal.ui.preferences.formatter.ProfileStore)2 ProfileVersioner (org.eclipse.jdt.internal.ui.preferences.formatter.ProfileVersioner)2 URISyntaxException (java.net.URISyntaxException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1