Search in sources :

Example 56 with IScopeContext

use of org.eclipse.core.runtime.preferences.IScopeContext in project liferay-ide by liferay.

the class PortalCore method getPreference.

public static String getPreference(String key) {
    IScopeContext[] scopes = new IScopeContext[] { InstanceScope.INSTANCE, DefaultScope.INSTANCE };
    IPreferencesService preferencesService = Platform.getPreferencesService();
    return preferencesService.getString(PLUGIN_ID, key, null, scopes);
}
Also used : IScopeContext(org.eclipse.core.runtime.preferences.IScopeContext) IPreferencesService(org.eclipse.core.runtime.preferences.IPreferencesService)

Example 57 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<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)

Example 58 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 59 with IScopeContext

use of org.eclipse.core.runtime.preferences.IScopeContext in project jop by jop-devel.

the class JOPUIUtils method getProjectSetting.

public static String getProjectSetting(ILaunchConfiguration configuration, String key, String def) {
    String projectName = getProjectName(configuration);
    if (projectName == null) {
        return def;
    }
    IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
    IScopeContext scopeContext = new ProjectScope(project);
    Preferences projectPrefs = scopeContext.getNode(IJOPUIConstants.PLUGIN_ID);
    return projectPrefs.get(key, def);
}
Also used : ProjectScope(org.eclipse.core.resources.ProjectScope) IScopeContext(org.eclipse.core.runtime.preferences.IScopeContext) Preferences(org.osgi.service.prefs.Preferences) IProject(org.eclipse.core.resources.IProject)

Example 60 with IScopeContext

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

the class DefaultResourceBlacklist method getPersistentValues.

protected String getPersistentValues(IProject project) {
    IScopeContext projectScope = getPreferenceScope(project);
    IEclipsePreferences node = projectScope.getNode(SCT_RESOURCE_NODE);
    String string = node.get(SCT_BLACKLIST_KEY, SCT_BLACKLIST_DEFAULT);
    return string;
}
Also used : IScopeContext(org.eclipse.core.runtime.preferences.IScopeContext) IEclipsePreferences(org.eclipse.core.runtime.preferences.IEclipsePreferences)

Aggregations

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