Search in sources :

Example 16 with IScopeContext

use of org.eclipse.core.runtime.preferences.IScopeContext in project jbosstools-hibernate by jbosstools.

the class SimpleTestProjectWithMapping method setDefaultConsoleConfiguration.

public void setDefaultConsoleConfiguration(String ccName) throws BackingStoreException, CoreException {
    IScopeContext scope = new ProjectScope(getIProject());
    Preferences node = scope.getNode(HibernatePropertiesConstants.HIBERNATE_CONSOLE_NODE);
    node.putBoolean(HibernatePropertiesConstants.HIBERNATE3_ENABLED, true);
    // $NON-NLS-1$
    node.put(HibernatePropertiesConstants.DEFAULT_CONFIGURATION, ccName);
    node.flush();
    addHibernateNature();
}
Also used : ProjectScope(org.eclipse.core.resources.ProjectScope) IScopeContext(org.eclipse.core.runtime.preferences.IScopeContext) Preferences(org.osgi.service.prefs.Preferences)

Example 17 with IScopeContext

use of org.eclipse.core.runtime.preferences.IScopeContext in project jbosstools-hibernate by jbosstools.

the class HibernateNature method getDefaultConsoleConfigurationName.

public String getDefaultConsoleConfigurationName() {
    IJavaProject prj = JavaCore.create(project);
    IScopeContext scope = new ProjectScope(prj.getProject());
    Preferences node = scope.getNode(HibernatePropertiesConstants.HIBERNATE_CONSOLE_NODE);
    if (node != null) {
        String cfg = node.get(HibernatePropertiesConstants.DEFAULT_CONFIGURATION, prj.getProject().getName());
        return cfg;
    } else {
        return null;
    }
}
Also used : ProjectScope(org.eclipse.core.resources.ProjectScope) IScopeContext(org.eclipse.core.runtime.preferences.IScopeContext) IJavaProject(org.eclipse.jdt.core.IJavaProject) Preferences(org.osgi.service.prefs.Preferences)

Example 18 with IScopeContext

use of org.eclipse.core.runtime.preferences.IScopeContext 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 19 with IScopeContext

use of org.eclipse.core.runtime.preferences.IScopeContext 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)

Example 20 with IScopeContext

use of org.eclipse.core.runtime.preferences.IScopeContext in project eclipse.platform.runtime by eclipse.

the class ContentTypeCatalog method internalFindContentTypesFor.

/**
 * This is the implementation for file name based content type matching.
 *
 * @return all matching content types in the preferred order
 * @see IContentTypeManager#findContentTypesFor(String)
 */
private synchronized IContentType[][] internalFindContentTypesFor(ContentTypeMatcher matcher, final String fileName, Comparator<IContentType> sortingPolicy) {
    IScopeContext context = matcher.getContext();
    IContentType[][] result = { NO_CONTENT_TYPES, NO_CONTENT_TYPES, NO_CONTENT_TYPES };
    Set<ContentType> existing = new HashSet<>();
    final Set<ContentType> allByFileName;
    if (context.equals(manager.getContext()))
        allByFileName = getDirectlyAssociated(fileName, IContentTypeSettings.FILE_NAME_SPEC);
    else {
        allByFileName = new HashSet<>(getDirectlyAssociated(fileName, IContentTypeSettings.FILE_NAME_SPEC | IContentType.IGNORE_USER_DEFINED));
        allByFileName.addAll(matcher.getDirectlyAssociated(this, fileName, IContentTypeSettings.FILE_NAME_SPEC));
    }
    Set<ContentType> selectedByName = selectMatchingByName(context, allByFileName, Collections.emptySet(), fileName, IContentType.FILE_NAME_SPEC);
    existing.addAll(selectedByName);
    result[0] = selectedByName.toArray(new IContentType[selectedByName.size()]);
    if (result[0].length > 1)
        Arrays.sort(result[0], sortingPolicy);
    final String fileExtension = ContentTypeManager.getFileExtension(fileName);
    if (fileExtension != null) {
        final Set<ContentType> allByFileExtension;
        if (context.equals(manager.getContext()))
            allByFileExtension = getDirectlyAssociated(fileExtension, IContentTypeSettings.FILE_EXTENSION_SPEC);
        else {
            allByFileExtension = new HashSet<>(getDirectlyAssociated(fileExtension, IContentTypeSettings.FILE_EXTENSION_SPEC | IContentType.IGNORE_USER_DEFINED));
            allByFileExtension.addAll(matcher.getDirectlyAssociated(this, fileExtension, IContentTypeSettings.FILE_EXTENSION_SPEC));
        }
        Set<ContentType> selectedByExtension = selectMatchingByName(context, allByFileExtension, selectedByName, fileExtension, IContentType.FILE_EXTENSION_SPEC);
        existing.addAll(selectedByExtension);
        if (!selectedByExtension.isEmpty())
            result[1] = selectedByExtension.toArray(new IContentType[selectedByExtension.size()]);
    }
    if (result[1].length > 1)
        Arrays.sort(result[1], sortingPolicy);
    final Set<ContentType> allByFilePattern;
    if (context.equals(manager.getContext()))
        allByFilePattern = getMatchingRegexpAssociated(fileName, IContentTypeSettings.FILE_PATTERN_SPEC);
    else {
        allByFilePattern = new HashSet<>(getMatchingRegexpAssociated(fileName, IContentTypeSettings.FILE_PATTERN_SPEC | IContentType.IGNORE_USER_DEFINED));
        allByFilePattern.addAll(matcher.getMatchingRegexpAssociated(this, fileName, IContentTypeSettings.FILE_PATTERN_SPEC));
    }
    existing.addAll(allByFilePattern);
    if (!allByFilePattern.isEmpty())
        result[2] = allByFilePattern.toArray(new IContentType[allByFilePattern.size()]);
    return result;
}
Also used : IScopeContext(org.eclipse.core.runtime.preferences.IScopeContext)

Aggregations

IScopeContext (org.eclipse.core.runtime.preferences.IScopeContext)73 ProjectScope (org.eclipse.core.resources.ProjectScope)42 IEclipsePreferences (org.eclipse.core.runtime.preferences.IEclipsePreferences)17 InstanceScope (org.eclipse.core.runtime.preferences.InstanceScope)16 DefaultScope (org.eclipse.core.runtime.preferences.DefaultScope)15 BackingStoreException (org.osgi.service.prefs.BackingStoreException)15 Preferences (org.osgi.service.prefs.Preferences)14 IProject (org.eclipse.core.resources.IProject)13 CoreException (org.eclipse.core.runtime.CoreException)8 ArrayList (java.util.ArrayList)6 IResource (org.eclipse.core.resources.IResource)6 ILiferayProjectProvider (com.liferay.ide.core.ILiferayProjectProvider)5 Iterator (java.util.Iterator)5 HashSet (java.util.HashSet)4 List (java.util.List)4 Set (java.util.Set)4 IFile (org.eclipse.core.resources.IFile)4 IAdaptable (org.eclipse.core.runtime.IAdaptable)4 PreferencesAccess (org.eclipse.jdt.internal.ui.preferences.PreferencesAccess)4 FormatterProfileStore (org.eclipse.jdt.internal.ui.preferences.formatter.FormatterProfileStore)4