Java Code Examples for org.eclipse.core.runtime.preferences.IScopeContext

The following examples show how to use org.eclipse.core.runtime.preferences.IScopeContext. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: eclipse   Source File: BazelProjectSupport.java    License: Apache License 2.0 6 votes vote down vote up
private static void addSettings(IProject project, String workspaceRoot, List<String> targets,
    List<String> buildFlags) throws BackingStoreException {
  IScopeContext projectScope = new ProjectScope(project);
  Preferences projectNode = projectScope.getNode(Activator.PLUGIN_ID);
  int i = 0;
  for (String target : targets) {
    projectNode.put("target" + i, target);
    i++;
  }
  projectNode.put("workspaceRoot", workspaceRoot);
  i = 0;
  for (String flag : buildFlags) {
    projectNode.put("buildFlag" + i, flag);
    i++;
  }
  projectNode.flush();
}
 
Example 2
/**
 * Switches the search scope of the preference store to use [Project, Instance, Configuration] if values are project
 * specific, and [Instance, Configuration] otherwise. This implementation requires that the given preference store
 * is based on the Project preference store when the page is used as a Properties page. (This is done in
 * {@link #doGetPreferenceStore()}).
 */
@SuppressWarnings("deprecation")
private void handleUseProjectSettings() {
	// Note: uses the pre Eclipse 3.6 way of specifying search scopes (deprecated since 3.6)
	boolean isUseProjectSettings = useProjectSettingsButton.getSelection();
	link.setEnabled(!isUseProjectSettings);
	if (!isUseProjectSettings) {
		((FixedScopedPreferenceStore) getPreferenceStore()).setSearchContexts(new IScopeContext[] {
				new InstanceScope(), new ConfigurationScope() });
	} else {
		((FixedScopedPreferenceStore) getPreferenceStore()).setSearchContexts(new IScopeContext[] {
				new ProjectScope(currentProject()), new InstanceScope(), new ConfigurationScope() });
		setProjectSpecificValues();
	}
	updateFieldEditors(isUseProjectSettings);
}
 
Example 3
@Override
@SuppressWarnings("deprecation")
public IPreferenceStore getWritablePreferenceStore(Object context) {
	lazyInitialize();
	IProject project = getProject(context);
	if (project == null) {
		return getWritablePreferenceStore();
	}
	ProjectScope projectScope = new ProjectScope(project);
	FixedScopedPreferenceStore result = new FixedScopedPreferenceStore(projectScope, getQualifier());
	result.setSearchContexts(new IScopeContext[] {
		projectScope,
		new InstanceScope(),
		new ConfigurationScope()
	});
	return result;
}
 
Example 4
public boolean hasProjectSpecificOptions(IProject project)
{
	if (project != null)
	{
		IScopeContext projectContext = new ProjectScope(project);
		PreferenceKey[] allKeys = fAllKeys;
		for (int i = 0; i < allKeys.length; i++)
		{
			if (allKeys[i].getStoredValue(projectContext, fManager) != null)
			{
				return true;
			}
		}
	}
	return false;
}
 
Example 5
/**
 * Updates project related fields, and saves to the preferences.
 */
private void updateProjectRelated() {
    IScopeContext context = new ProjectScope(project);
    IEclipsePreferences preferences = context.getNode(CodeCheckerNature.NATURE_ID);

    for (ConfigTypes ctp : ConfigTypes.PROJECT_TYPE){
        String value = null;
        switch (ctp) {
            case CHECKER_WORKSPACE:
                value = codeCheckerWorkspace.toString();
                break;
            case IS_GLOBAL:
                value = Boolean.toString(isGlobal);
                break;
            default:
                break;
        }
        preferences.put(ctp.toString(), value);
    }
    try {
        preferences.flush();
    } catch (BackingStoreException e) {
        Logger.log(IStatus.ERROR, "Preferences cannot be saved!");
        e.printStackTrace();
    }
}
 
Example 6
@SuppressWarnings("all")
@Override
public IPreferenceStore getContextPreferenceStore(Object context) {
	IProject project = getProject(context);
	if (project == null) return getPreferenceStore();
	IPreferenceStore store = super.getContextPreferenceStore(context);
	ProjectScope projectScope = new ProjectScope(project);
	FixedScopedPreferenceStore jdtStore = new FixedScopedPreferenceStore(projectScope, JavaCore.PLUGIN_ID);
	jdtStore.setSearchContexts(new IScopeContext[] {
			projectScope,
			new InstanceScope(),
			new ConfigurationScope()
	});
	return new ChainedPreferenceStore(new IPreferenceStore[] {
		store,
		jdtStore,
		PreferenceConstants.getPreferenceStore()
	});
}
 
Example 7
public AbstractFormatterSelectionBlock(IStatusChangeListener context, IProject project,
		IWorkbenchPreferenceContainer container)
{
	super(context, project, ProfileManager.collectPreferenceKeys(TEMP_LIST, true), container);
	Collections.sort(TEMP_LIST, new Comparator<IScriptFormatterFactory>()
	{
		public int compare(IScriptFormatterFactory s1, IScriptFormatterFactory s2)
		{
			return s1.getName().compareToIgnoreCase(s2.getName());
		}
	});
	factories = TEMP_LIST.toArray(new IScriptFormatterFactory[TEMP_LIST.size()]);
	TEMP_LIST = new ArrayList<IScriptFormatterFactory>();
	sourcePreviewViewers = new ArrayList<SourceViewer>();

	// Override the super preferences lookup order.
	// All the changes to the formatter settings should go to the instance scope (no project scope here). Only the
	// selected profile will be picked from the project scope and then the instance scope when requested.
	fLookupOrder = new IScopeContext[] { EclipseUtil.instanceScope(), EclipseUtil.defaultScope() };
}
 
Example 8
@Override
protected void updateProfilesWithName(String oldName, Profile newProfile, boolean applySettings) {
	IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
	for (int i = 0; i < projects.length; i++) {
		IScopeContext projectScope = fPreferencesAccess.getProjectScope(projects[i]);
		IEclipsePreferences node = projectScope.getNode(getNodeId());
		String profileId = node.get(fProfileKey, null);
		if (oldName.equals(profileId)) {
			if (newProfile == null) {
				node.remove(fProfileKey);
			} else {
				if (applySettings) {
					writeToPreferenceStore(newProfile, projectScope);
				} else {
					node.put(fProfileKey, newProfile.getID());
				}
			}
		}
	}

	IScopeContext instanceScope = fPreferencesAccess.getInstanceScope();
	final IEclipsePreferences uiPrefs = instanceScope.getNode(getNodeId());
	if (newProfile != null && oldName.equals(uiPrefs.get(fProfileKey, null))) {
		writeToPreferenceStore(newProfile, instanceScope);
	}
}
 
Example 9
Source Project: typescript.java   Source File: OptionsConfigurationBlock.java    License: MIT License 6 votes vote down vote up
private boolean getChanges(IScopeContext currContext, List<Key> changedSettings) {
	boolean needsBuild = false;
	for (int i = 0; i < fAllKeys.length; i++) {
		Key key = fAllKeys[i];
		String oldVal = key.getStoredValue(currContext, null);
		String val = key.getStoredValue(currContext, fManager);
		if (val == null) {
			if (oldVal != null) {
				changedSettings.add(key);
				needsBuild |= !oldVal.equals(key.getStoredValue(fLookupOrder, true, fManager));
			}
		} else if (!val.equals(oldVal)) {
			changedSettings.add(key);
			needsBuild |= oldVal != null || !val.equals(key.getStoredValue(fLookupOrder, true, fManager));
		}
	}
	return needsBuild;
}
 
Example 10
Source Project: neoscada   Source File: Activator.java    License: Eclipse Public License 1.0 5 votes vote down vote up
public static TimeZone getTimeZone ()
{
    final IScopeContext[] scopeContext = new IScopeContext[] { ConfigurationScope.INSTANCE };
    final String tzId = Platform.getPreferencesService ().getString ( PLUGIN_ID, TIME_ZONE_KEY, TimeZone.getDefault ().getID (), scopeContext );
    if ( Arrays.asList ( TimeZone.getAvailableIDs () ).contains ( tzId ) )
    {
        return TimeZone.getTimeZone ( tzId );
    }
    return TimeZone.getDefault ();
}
 
Example 11
Source Project: eclipse   Source File: BazelProjectSupport.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * List targets configure for <code>project</code>. Each project configured for Bazel is
 * configured to track certain targets and this function fetch this list from the project
 * preferences.
 */
public static List<String> getTargets(IProject project) throws BackingStoreException {
  // Get the list of targets from the preferences
  IScopeContext projectScope = new ProjectScope(project);
  Preferences projectNode = projectScope.getNode(Activator.PLUGIN_ID);
  ImmutableList.Builder<String> builder = ImmutableList.builder();
  for (String s : projectNode.keys()) {
    if (s.startsWith("target")) {
      builder.add(projectNode.get(s, ""));
    }
  }
  return builder.build();
}
 
Example 12
Source Project: eclipse   Source File: BazelProjectSupport.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * List of build flags for <code>project</code>, taken from the project configuration
 */
public static List<String> getBuildFlags(IProject project) throws BackingStoreException {
  // Get the list of targets from the preferences
  IScopeContext projectScope = new ProjectScope(project);
  Preferences projectNode = projectScope.getNode(Activator.PLUGIN_ID);
  ImmutableList.Builder<String> builder = ImmutableList.builder();
  for (String s : projectNode.keys()) {
    if (s.startsWith("buildArgs")) {
      builder.add(projectNode.get(s, ""));
    }
  }
  return builder.build();
}
 
Example 13
Source Project: eclipse   Source File: BazelProjectSupport.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Return the {@link BazelInstance} corresponding to the given <code>project</code>. It looks for
 * the instance that runs for the workspace root configured for that project.
 *
 * @throws BazelNotFoundException
 */
public static BazelCommand.BazelInstance getBazelCommandInstance(IProject project)
    throws BackingStoreException, IOException, InterruptedException, BazelNotFoundException {
  IScopeContext projectScope = new ProjectScope(project.getProject());
  Preferences projectNode = projectScope.getNode(Activator.PLUGIN_ID);
  File workspaceRoot =
      new File(projectNode.get("workspaceRoot", project.getLocation().toFile().toString()));
  return Activator.getDefault().getCommand().getInstance(workspaceRoot);
}
 
Example 14
Source Project: eclipse   Source File: BazelProjectSupport.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Convert an Eclipse JDT project into an IntelliJ project view
 */
public static ProjectView getProjectView(IProject project)
    throws BackingStoreException, JavaModelException {
  com.google.devtools.bazel.e4b.projectviews.Builder builder = ProjectView.builder();
  IScopeContext projectScope = new ProjectScope(project);
  Preferences projectNode = projectScope.getNode(Activator.PLUGIN_ID);
  for (String s : projectNode.keys()) {
    if (s.startsWith("buildArgs")) {
      builder.addBuildFlag(projectNode.get(s, ""));
    } else if (s.startsWith("target")) {
      builder.addTarget(projectNode.get(s, ""));
    }
  }

  IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
  for (IClasspathEntry entry : ((IJavaProject) project).getRawClasspath()) {
    switch (entry.getEntryKind()) {
      case IClasspathEntry.CPE_SOURCE:
        IResource res = root.findMember(entry.getPath());
        if (res != null) {
          builder.addDirectory(res.getProjectRelativePath().removeFirstSegments(1).toOSString());
        }
        break;
      case IClasspathEntry.CPE_CONTAINER:
        String path = entry.getPath().toOSString();
        if (path.startsWith(STANDARD_VM_CONTAINER_PREFIX)) {
          builder.setJavaLanguageLevel(
              Integer.parseInt(path.substring(STANDARD_VM_CONTAINER_PREFIX.length())));
        }
        break;
    }
  }
  return builder.build();
}
 
Example 15
Source Project: google-cloud-eclipse   Source File: PreferenceResolver.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Resolve a path like <code>instance://org.example.bundle/path/to/boolean</code> to an
 * {@link IPreferenceStore}.
 * 
 * @param preferenceUri the preference path
 * @return the corresponding store
 * @throws IllegalArgumentException if unable to resolve the URI
 */
public static IPreferenceStore resolve(URI preferenceUri) throws IllegalArgumentException {
  IScopeContext context = resolveScopeContext(preferenceUri.getScheme());
  String path = preferenceUri.getHost();
  if (preferenceUri.getPath() != null) {
    path += preferenceUri.getPath();
  }
  return new ScopedPreferenceStore(context, path);
}
 
Example 16
@Override
public int open()
{
	String saveDirty = Platform.getPreferencesService().getString(IDebugUIConstants.PLUGIN_ID,
			IInternalDebugUIConstants.PREF_SAVE_DIRTY_EDITORS_BEFORE_LAUNCH, StringUtil.EMPTY,
			new IScopeContext[] { EclipseUtil.instanceScope(), EclipseUtil.defaultScope() });
	if (saveDirty.equals(MessageDialogWithToggle.ALWAYS))
	{
		setResult(dirtyResources);
		return Window.OK;
	}
	return super.open();
}
 
Example 17
@Override
@SuppressWarnings("deprecation")
public IPreferenceStore getWritablePreferenceStore() {
	lazyInitialize();
	FixedScopedPreferenceStore result = new FixedScopedPreferenceStore(new InstanceScope(), getQualifier());
	result.setSearchContexts(new IScopeContext[] {
		new InstanceScope(),
		new ConfigurationScope()
	});
	return result;
}
 
Example 18
Source Project: SparkBuilderGenerator   Source File: PreferenceStoreProvider.java    License: MIT License 5 votes vote down vote up
public PreferenceStoreWrapper providePreferenceStore() {
    IPreferenceStore[] preferenceStores = new IPreferenceStore[2];
    preferenceStores[0] = Activator.getDefault().getPreferenceStore();

    ScopedPreferenceStore jdtCorePreferenceStore = new ScopedPreferenceStore(InstanceScope.INSTANCE, "org.eclipse.jdt.core");
    if (currentJavaProject.isPresent()) { // if we are in a project add to search scope
        jdtCorePreferenceStore.setSearchContexts(new IScopeContext[] { new ProjectScope(currentJavaProject.get().getProject()), InstanceScope.INSTANCE });
    }
    preferenceStores[1] = jdtCorePreferenceStore;

    return new PreferenceStoreWrapper(new ChainedPreferenceStore(preferenceStores));
}
 
Example 19
protected boolean isAutoBuildEnabled()
{
	IPreferencesService service = Platform.getPreferencesService();
	String qualifier = ResourcesPlugin.getPlugin().getBundle().getSymbolicName();
	String key = "description.autobuilding";
	IScopeContext[] contexts = { InstanceScope.INSTANCE, ConfigurationScope.INSTANCE };
	return service.getBoolean(qualifier, key, false, contexts);
}
 
Example 20
protected boolean isAutoBuildEnabled()
{
	IPreferencesService service = Platform.getPreferencesService();
	String qualifier = ResourcesPlugin.getPlugin().getBundle().getSymbolicName();
	String key = "description.autobuilding";
	IScopeContext[] contexts = { InstanceScope.INSTANCE, ConfigurationScope.INSTANCE};
	return service.getBoolean( qualifier, key, false, contexts );
}
 
Example 21
private IScopeContext[] getLookupScopes(IProject project)
{
	List<IScopeContext> list = new ArrayList<IScopeContext>(3);
	list.add(EclipseUtil.instanceScope());
	list.add(EclipseUtil.defaultScope());

	if (project != null)
	{
		list.add(0, new ProjectScope(project));
	}

	return list.toArray(new IScopeContext[list.size()]);
}
 
Example 22
Source Project: xds-ide   Source File: PreferenceKey.java    License: Eclipse Public License 1.0 5 votes vote down vote up
public String getStoredValue(IScopeContext[] lookupOrder, boolean ignoreTopScope, IWorkingCopyManager manager) {
	for (int i= ignoreTopScope ? 1 : 0; i < lookupOrder.length; i++) {
		String value= getStoredValue(lookupOrder[i], manager);
		if (value != null) {
			return value;
		}
	}
	return null;
}
 
Example 23
Source Project: xds-ide   Source File: PreferenceKey.java    License: Eclipse Public License 1.0 5 votes vote down vote up
public void setStoredValue(IScopeContext context, String value, IWorkingCopyManager manager) {
	if (value != null) {
		getNode(context, manager).put(fKey, value);
	} else {
		getNode(context, manager).remove(fKey);
	}
}
 
Example 24
Source Project: xds-ide   Source File: PreferenceKey.java    License: Eclipse Public License 1.0 5 votes vote down vote up
public void setStoredBoolean(IScopeContext context, Boolean value, IWorkingCopyManager manager) {
	if (value != null) {
		getNode(context, manager).putBoolean(fKey, value);
	} else {
		getNode(context, manager).remove(fKey);
	}
}
 
Example 25
Source Project: xds-ide   Source File: PreferenceKey.java    License: Eclipse Public License 1.0 5 votes vote down vote up
public void setStoredInt(IScopeContext context, Integer value, IWorkingCopyManager manager) {
    if (value != null) {
        getNode(context, manager).putInt(fKey, value);
    } else {
        getNode(context, manager).remove(fKey);
    }
}
 
Example 26
Source Project: xds-ide   Source File: PreferenceKey.java    License: Eclipse Public License 1.0 5 votes vote down vote up
public static void addChangeListener(IScopeContext context, IWorkingCopyManager manager, 
                                     String qualifier, IPreferenceChangeListener listener) 
{
    IEclipsePreferences node= context.getNode(qualifier);
    if (manager != null) {
        node =  manager.getWorkingCopy(node);
    }
    node.addPreferenceChangeListener(listener);
}
 
Example 27
Source Project: xds-ide   Source File: PreferenceKey.java    License: Eclipse Public License 1.0 5 votes vote down vote up
public static void removeChangeListener(IScopeContext context, IWorkingCopyManager manager, 
                                        String qualifier, IPreferenceChangeListener listener) 
{
    IEclipsePreferences node= context.getNode(qualifier);
    if (manager != null) {
        node =  manager.getWorkingCopy(node);
    }
    node.removePreferenceChangeListener(listener);
}
 
Example 28
/**
 * Checks the common editor plugin to see if the user has enabled hovers on content assist
 * 
 * @return <code>true</code>, if hover is enabled; <code>false</code>, otherwise.
 */
public Boolean isHoverEnabled()
{
	IScopeContext[] scopes = new IScopeContext[] { EclipseUtil.instanceScope(), EclipseUtil.defaultScope() };
	return Platform.getPreferencesService().getBoolean(CommonEditorPlugin.PLUGIN_ID,
			IPreferenceConstants.CONTENT_ASSIST_HOVER, true, scopes);
}
 
Example 29
Source Project: xds-ide   Source File: PreferenceCommons.java    License: Eclipse Public License 1.0 5 votes vote down vote up
/**
 * TODO : implement better architecture for storing preferences.
 * 
 * @param scope
 * @param qualifier
 * @see org.osgi.service.prefs.Preferences#flush
 */
public static void flush(IScopeContext scope, String qualifier) {
	try {
           IEclipsePreferences node = scope.getNode(qualifier);
           node.flush();
       } catch (BackingStoreException e) {
           LogHelper.logError(e);
       }
}
 
Example 30
public static String ofWorkspace() {
	IPreferencesService prefs = Platform.getPreferencesService();
	IScopeContext[] scopeContext = new IScopeContext[] { InstanceScope.INSTANCE };
	String lineSeparator = prefs.getString(Platform.PI_RUNTIME, Platform.PREF_LINE_SEPARATOR, null, scopeContext);
	if (lineSeparator == null) {
		lineSeparator = System.getProperty("line.separator");
	}
	return toLabel(lineSeparator);
}