Search in sources :

Example 36 with IScopeContext

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

the class StubUtility method getLineDelimiterPreference.

public static String getLineDelimiterPreference(IProject project) {
    IScopeContext[] scopeContext;
    if (project != null) {
        // project preference
        scopeContext = new IScopeContext[] { new ProjectScope(project) };
        String lineDelimiter = Platform.getPreferencesService().getString(Platform.PI_RUNTIME, Platform.PREF_LINE_SEPARATOR, null, scopeContext);
        if (lineDelimiter != null)
            return lineDelimiter;
    }
    // workspace preference
    scopeContext = new IScopeContext[] { InstanceScope.INSTANCE };
    //$NON-NLS-1$ //$NON-NLS-2$
    String platformDefault = System.getProperty("line.separator", "\n");
    return Platform.getPreferencesService().getString(Platform.PI_RUNTIME, Platform.PREF_LINE_SEPARATOR, platformDefault, scopeContext);
}
Also used : ProjectScope(org.eclipse.core.resources.ProjectScope) IScopeContext(org.eclipse.core.runtime.preferences.IScopeContext)

Example 37 with IScopeContext

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

the class ProjectUtil method setPathPersistentProperty.

private static void setPathPersistentProperty(IProject project, IPath path, String propertyName) {
    IScopeContext projectScope = new ProjectScope(project);
    IEclipsePreferences projectNode = projectScope.getNode(Activator.PLUGIN_ID);
    if (projectNode != null) {
        projectNode.put(propertyName, path.toPortableString());
        try {
            projectNode.flush();
        } catch (BackingStoreException e) {
            Activator.getDefault().getPluginLogger().error(e.getMessage(), e);
        }
    }
}
Also used : ProjectScope(org.eclipse.core.resources.ProjectScope) IScopeContext(org.eclipse.core.runtime.preferences.IScopeContext) IEclipsePreferences(org.eclipse.core.runtime.preferences.IEclipsePreferences) BackingStoreException(org.osgi.service.prefs.BackingStoreException)

Example 38 with IScopeContext

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

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 sortingPolicy) {
    IScopeContext context = matcher.getContext();
    IContentType[][] result = { NO_CONTENT_TYPES, NO_CONTENT_TYPES };
    final Set 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 selectedByName = selectMatchingByName(context, allByFileName, Collections.EMPTY_SET, fileName, IContentType.FILE_NAME_SPEC);
    result[0] = (IContentType[]) selectedByName.toArray(new IContentType[selectedByName.size()]);
    final String fileExtension = ContentTypeManager.getFileExtension(fileName);
    if (fileExtension != null) {
        final Set 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 selectedByExtension = selectMatchingByName(context, allByFileExtension, selectedByName, fileExtension, IContentType.FILE_EXTENSION_SPEC);
        if (!selectedByExtension.isEmpty())
            result[1] = (IContentType[]) selectedByExtension.toArray(new IContentType[selectedByExtension.size()]);
    }
    if (result[0].length > 1)
        Arrays.sort(result[0], sortingPolicy);
    if (result[1].length > 1)
        Arrays.sort(result[1], sortingPolicy);
    return result;
}
Also used : IScopeContext(org.eclipse.core.runtime.preferences.IScopeContext)

Example 39 with IScopeContext

use of org.eclipse.core.runtime.preferences.IScopeContext in project xtext-xtend by eclipse.

the class JavaProjectPreferencesInitializer method addOwnFileExtensionsToJavaBuildResourceCopyFilter.

@SuppressWarnings("restriction")
@Inject
public void addOwnFileExtensionsToJavaBuildResourceCopyFilter(FileExtensionProvider extensionProvider) {
    @SuppressWarnings("deprecation") IScopeContext defaultScope = new DefaultScope();
    // The class org.eclipse.jdt.internal.launching.LaunchingPreferenceInitializer has this very nasty habit
    // of replacing all RESOURCE_COPY_FILTERs with its own filter. Calling getNode(LaunchingPlugin.ID_PLUGIN)
    // causes LaunchingPreferenceInitializer to be executed that afterwards we can append our filters safely.
    // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=395366
    defaultScope.getNode(org.eclipse.jdt.internal.launching.LaunchingPlugin.ID_PLUGIN);
    IEclipsePreferences dnode = defaultScope.getNode(JavaCore.PLUGIN_ID);
    if (dnode == null)
        return;
    Set<String> filters = Sets.newLinkedHashSet();
    for (String filter : dnode.get(JavaCore.CORE_JAVA_BUILD_RESOURCE_COPY_FILTER, "").split(",")) {
        String trimmed = filter.trim();
        if (!"".equals(trimmed))
            filters.add(trimmed);
    }
    for (String ext : extensionProvider.getFileExtensions()) filters.add("*." + ext);
    dnode.put(JavaCore.CORE_JAVA_BUILD_RESOURCE_COPY_FILTER, Joiner.on(", ").join(filters));
    try {
        dnode.flush();
    } catch (BackingStoreException e) {
        log.error("Error saving preferences", e);
    }
}
Also used : IScopeContext(org.eclipse.core.runtime.preferences.IScopeContext) IEclipsePreferences(org.eclipse.core.runtime.preferences.IEclipsePreferences) BackingStoreException(org.osgi.service.prefs.BackingStoreException) DefaultScope(org.eclipse.core.runtime.preferences.DefaultScope) Inject(com.google.inject.Inject)

Example 40 with IScopeContext

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

the class FileDocumentProvider method getLineDelimiterPreference.

/**
 * Returns the default line delimiter preference for the given file.
 *
 * @param file the file
 * @return the default line delimiter
 * @since 3.1
 */
private String getLineDelimiterPreference(IFile file) {
    IScopeContext[] scopeContext;
    if (file != null && file.getProject() != null) {
        // project preference
        scopeContext = new IScopeContext[] { new ProjectScope(file.getProject()) };
        String lineDelimiter = Platform.getPreferencesService().getString(Platform.PI_RUNTIME, Platform.PREF_LINE_SEPARATOR, null, scopeContext);
        if (lineDelimiter != null)
            return lineDelimiter;
    }
    // workspace preference
    scopeContext = new IScopeContext[] { InstanceScope.INSTANCE };
    return Platform.getPreferencesService().getString(Platform.PI_RUNTIME, Platform.PREF_LINE_SEPARATOR, null, scopeContext);
}
Also used : ProjectScope(org.eclipse.core.resources.ProjectScope) 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