Java Code Examples for org.osgi.service.prefs.Preferences#keys()

The following examples show how to use org.osgi.service.prefs.Preferences#keys() . 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: Ruleset.java    From CogniCrypt with Eclipse Public License 2.0 6 votes vote down vote up
public Ruleset(Preferences subPrefs) throws BackingStoreException {
	String[] keys = subPrefs.keys();
	for (String key : keys) {
		switch (key) {
			case "SelectedVersion":
				this.selectedVersion = subPrefs.get(key, "");
				break;
			case "CheckboxState":
				this.isChecked = subPrefs.getBoolean(key, false);
				break;
			case "FolderName":
				this.folderName = subPrefs.get(key, "");
				break;
			case "Url":
				this.url = subPrefs.get(key, "");
				break;
			default:
				break;
		}
	}
}
 
Example 2
Source File: StaticAnalyzerPreferences.java    From CogniCrypt with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * This method fetches the list of rule sets which are stored in preference file
 * 
 * @return list of rule sets
 */
private List<Ruleset> getRulesetsFromPrefs() {
	List<Ruleset> ruleSets = new ArrayList<Ruleset>();

	try {
		String[] listOfNodes = rulePreferences.childrenNames();

		for (String currentNode : listOfNodes) {
			Ruleset loadedRuleset = new Ruleset(currentNode);
			Preferences subPref = rulePreferences.node(currentNode);
			String[] keys = subPref.keys();
			for (String key : keys) {
				switch (key) {
					case "FolderName":
						loadedRuleset.setFolderName(subPref.get(key, ""));
						break;
					case "CheckboxState":
						loadedRuleset.setChecked(subPref.getBoolean(key, false));
						break;
					case "SelectedVersion":
						loadedRuleset.setSelectedVersion(subPref.get(key, ""));
						break;
					case "Url":
						loadedRuleset.setUrl(subPref.get(key, ""));
						break;
					default:
						break;
				}
			}
			ruleSets.add(loadedRuleset);
		}
	}
	catch (BackingStoreException e) {
		Activator.getDefault().logError(e);
	}
	return ruleSets;
}
 
Example 3
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 4
Source File: BazelProjectSupport.java    From eclipse with 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 5
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 6
Source File: GanttOptions.java    From ganttproject with GNU General Public License v3.0 5 votes vote down vote up
private void savePreferences(Preferences node, TransformerHandler handler) throws BackingStoreException, SAXException {
  AttributesImpl attrs = new AttributesImpl();
  startElement(node.name(), attrs, handler);
  String[] keys = node.keys();
  for (int i = 0; i < keys.length; i++) {
    addAttribute("name", keys[i], attrs);
    addAttribute("value", node.get(keys[i], ""), attrs);
    emptyElement("option", attrs, handler);
  }
  String[] children = node.childrenNames();
  for (int i = 0; i < children.length; i++) {
    savePreferences(node.node(children[i]), handler);
  }
  endElement(node.name(), handler);
}
 
Example 7
Source File: ThemeManager.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
/**
 * laziliy init the set of theme names.
 */
public synchronized Set<String> getThemeNames()
{
	if (fThemeNames == null)
	{
		fThemeNames = new HashSet<String>();
		// Add names of themes from builtins...
		fThemeNames.addAll(getBuiltinThemeNames());

		// Look in prefs to see what user themes are stored there, garb their names
		IScopeContext[] scopes = new IScopeContext[] { EclipseUtil.instanceScope(), EclipseUtil.defaultScope() };
		for (IScopeContext scope : scopes)
		{
			IEclipsePreferences prefs = scope.getNode(ThemePlugin.PLUGIN_ID);
			Preferences preferences = prefs.node(ThemeManager.THEMES_NODE);
			try
			{
				String[] themeNames = preferences.keys();
				fThemeNames.addAll(Arrays.asList(themeNames));
			}
			catch (BackingStoreException e)
			{
				IdeLog.logError(ThemePlugin.getDefault(), e);
			}
		}
	}
	return fThemeNames;
}
 
Example 8
Source File: JavaCorePreferenceModifyListener.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Clean imported preferences from obsolete keys.
 *
 * @param preferences JavaCore preferences.
 */
void cleanJavaCore(Preferences preferences) {
	try {
		String[] keys = preferences.keys();
		for (int k = 0, kl= keys.length; k<kl; k++) {
			String key = keys[k];
			if (key.startsWith(JavaModelManager.CP_CONTAINER_PREFERENCES_PREFIX) && !isJavaProjectAccessible(key)) {
				preferences.remove(key);
			}
		}
	} catch (BackingStoreException e) {
		// do nothing
	}
}