Java Code Examples for org.eclipse.core.runtime.preferences.IScopeContext#getNode()

The following examples show how to use org.eclipse.core.runtime.preferences.IScopeContext#getNode() . 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 File: BazelProjectSupport.java    From eclipse with 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
Source File: AbstractProfileManager.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
@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 3
Source File: AbstractProfileManager.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Update all formatter settings with the settings of the specified profile.
 * 
 * @param profile
 *            The profile to write to the preference store
 */
private void writeToPreferenceStore(Profile profile, IScopeContext context) {
	final Map profileOptions = profile.getSettings();

	for (int i = 0; i < fKeySets.length; i++) {
		updatePreferences(context.getNode(fKeySets[i].getNodeName()), fKeySets[i].getKeys(), profileOptions);
	}

	final IEclipsePreferences uiPrefs = context.getNode(getNodeId());
	if (uiPrefs.getInt(fProfileVersionKey, 0) != fProfileVersioner.getCurrentVersion()) {
		uiPrefs.putInt(fProfileVersionKey, fProfileVersioner.getCurrentVersion());
	}

	if (context.getName() == InstanceScope.SCOPE) {
		uiPrefs.put(fProfileKey, profile.getID());
	} else if (context.getName() == ProjectScope.SCOPE && !profile.isSharedProfile()) {
		uiPrefs.put(fProfileKey, profile.getID());
	}
}
 
Example 4
Source File: CodeCheckerProject.java    From CodeCheckerEclipsePlugin with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * 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 5
Source File: BazelProjectSupport.java    From eclipse with 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 6
Source File: DefaultResourceBlacklist.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
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;
}
 
Example 7
Source File: OptionsConfigurationBlock.java    From typescript.java with MIT License 5 votes vote down vote up
private IEclipsePreferences getNode(IScopeContext context, IWorkingCopyManager manager) {
	IEclipsePreferences node = context.getNode(fQualifier);
	if (manager != null) {
		return manager.getWorkingCopy(node);
	}
	return node;
}
 
Example 8
Source File: AbstractProfileManager.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Only to read project specific settings to find out to what profile it matches.
 * 
 * @param context
 *            The project context
 */
private Map readFromPreferenceStore(IScopeContext context, Profile workspaceProfile) {
	final Map profileOptions = new HashMap();
	IEclipsePreferences uiPrefs = context.getNode(getNodeId());

	int version = uiPrefs.getInt(fProfileVersionKey, fProfileVersioner.getFirstVersion());
	if (version != fProfileVersioner.getCurrentVersion()) {
		Map allOptions = new HashMap();
		for (int i = 0; i < fKeySets.length; i++) {
			addAll(context.getNode(fKeySets[i].getNodeName()), allOptions);
		}
		CustomProfile profile = new CustomProfile("tmp", allOptions, version, fProfileVersioner.getProfileKind()); //$NON-NLS-1$
		fProfileVersioner.update(profile);
		return profile.getSettings();
	}

	boolean hasValues = false;
	for (int i = 0; i < fKeySets.length; i++) {
		KeySet keySet = fKeySets[i];
		IEclipsePreferences preferences = context.getNode(keySet.getNodeName());
		for (final Iterator keyIter = keySet.getKeys().iterator(); keyIter.hasNext();) {
			final String key = (String) keyIter.next();
			Object val = preferences.get(key, null);
			if (val != null) {
				hasValues = true;
			} else {
				val = workspaceProfile.getSettings().get(key);
			}
			profileOptions.put(key, val);
		}
	}

	if (!hasValues) {
		return null;
	}

	setLatestCompliance(profileOptions);
	return profileOptions;
}
 
Example 9
Source File: PreferenceKey.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
public void flush(IScopeContext context)
{
	IEclipsePreferences node = context.getNode(fQualifier);
	if (node != null)
	{
		try
		{
			node.flush();
		}
		catch (BackingStoreException e)
		{
			IdeLog.logError(FormatterPlugin.getDefault(), "Error flushing a node", e, IDebugScopes.DEBUG); //$NON-NLS-1$
		}
	}
}
 
Example 10
Source File: CodeCheckerProject.java    From CodeCheckerEclipsePlugin with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Initializes project related fields.
 *  - Is the last used configuration was local or global.
 */
private void initProjectRelated() {
    IScopeContext context = new ProjectScope(project);
    IEclipsePreferences preferences = context.getNode(CodeCheckerNature.NATURE_ID);

    isGlobal = preferences.getBoolean(ConfigTypes.IS_GLOBAL.toString(), true);
}
 
Example 11
Source File: PreferenceCommons.java    From xds-ide with 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 12
Source File: PreferenceKey.java    From xds-ide with Eclipse Public License 1.0 5 votes vote down vote up
private IEclipsePreferences getNode(IScopeContext context, IWorkingCopyManager manager) {
    IEclipsePreferences node= context.getNode(fQualifier);
    if (manager != null) {
        return manager.getWorkingCopy(node);
    }
    return node;
}
 
Example 13
Source File: PreferenceKey.java    From xds-ide with 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 14
Source File: PreferenceKey.java    From xds-ide with 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 15
Source File: BazelProjectSupport.java    From eclipse with 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 16
Source File: BazelProjectSupport.java    From eclipse with 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 17
Source File: Theme.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
private void delete(IScopeContext context)
{
	try
	{
		IEclipsePreferences prefs = context.getNode(ThemePlugin.PLUGIN_ID);
		Preferences preferences = prefs.node(ThemeManager.THEMES_NODE);
		preferences.remove(getName());
		preferences.flush();
	}
	catch (BackingStoreException e)
	{
		IdeLog.logError(ThemePlugin.getDefault(), e);
	}
}
 
Example 18
Source File: GwtSdk.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 4 votes vote down vote up
private static IEclipsePreferences getProjectProperties(IProject project) {
  IScopeContext projectScope = new ProjectScope(project);
  return projectScope.getNode(GWTPlugin.PLUGIN_ID);
}
 
Example 19
Source File: GWTProjectProperties.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 4 votes vote down vote up
private static IEclipsePreferences getProjectProperties(IProject project) {
  IScopeContext projectScope = new ProjectScope(project);
  return projectScope.getNode(GWTPlugin.PLUGIN_ID);
}
 
Example 20
Source File: WebAppProjectProperties.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 4 votes vote down vote up
private static IEclipsePreferences getProjectProperties(IProject project) {
  IScopeContext projectScope = new ProjectScope(project);
  return projectScope.getNode(CorePlugin.PLUGIN_ID);
}