Java Code Examples for org.eclipse.core.runtime.preferences.IEclipsePreferences#get()

The following examples show how to use org.eclipse.core.runtime.preferences.IEclipsePreferences#get() . 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: ValidPreferenceStore.java    From dsl-devkit with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Does its best at determining the default value for the given key. Checks
 * the given object's type and then looks in the list of defaults to see if
 * a value exists. If not or if there is a problem converting the value, the
 * default default value for that type is returned.
 *
 * @param key
 *          the key to search
 * @param object
 *          the object who default we are looking for
 * @return Object or <code>null</code>
 */
Object getDefault(final String key, final Object object) {
  final IEclipsePreferences defaults = getDefaultPreferences();
  if (object instanceof String) {
    return defaults.get(key, STRING_DEFAULT_DEFAULT);
  } else if (object instanceof Integer) {
    return Integer.valueOf(defaults.getInt(key, INT_DEFAULT_DEFAULT));
  } else if (object instanceof Double) {
    return new Double(defaults.getDouble(key, DOUBLE_DEFAULT_DEFAULT));
  } else if (object instanceof Float) {
    return new Float(defaults.getFloat(key, FLOAT_DEFAULT_DEFAULT));
  } else if (object instanceof Long) {
    return Long.valueOf(defaults.getLong(key, LONG_DEFAULT_DEFAULT));
  } else if (object instanceof Boolean) {
    return defaults.getBoolean(key, BOOLEAN_DEFAULT_DEFAULT) ? Boolean.TRUE : Boolean.FALSE;
  } else {
    return null;
  }
}
 
Example 2
Source File: ProfileManager.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * @param uiPrefs
 * @param allOptions
 */
private void addAll(IEclipsePreferences uiPrefs, Map<String, String> allOptions) {
	try {
		String[] keys= uiPrefs.keys();
		for (int i= 0; i < keys.length; i++) {
			String key= keys[i];
			String val= uiPrefs.get(key, null);
			if (val != null) {
				allOptions.put(key, val);
			}
		}
	} catch (BackingStoreException e) {
		// ignore
	}

}
 
Example 3
Source File: EclipseUtil.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Migrate the existing preferences from instance scope to configuration scope and then remove the preference key
 * from the instance scope.
 */
public static void migratePreference(String pluginId, String preferenceKey)
{
	IEclipsePreferences configNode = EclipseUtil.configurationScope().getNode(pluginId);
	if (StringUtil.isEmpty(configNode.get(preferenceKey, null))) // no value in config scope
	{
		IEclipsePreferences instanceNode = EclipseUtil.instanceScope().getNode(pluginId);
		String instancePrefValue = instanceNode.get(preferenceKey, null);
		if (!StringUtil.isEmpty(instancePrefValue))
		{
			// only migrate if there is a value!
			configNode.put(preferenceKey, instancePrefValue);
			instanceNode.remove(preferenceKey);
			try
			{
				configNode.flush();
				instanceNode.flush();
			}
			catch (BackingStoreException e)
			{
				IdeLog.logWarning(CorePlugin.getDefault(), e.getMessage(), e);
			}
		}
	}
}
 
Example 4
Source File: JavaModelManager.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Returns the value of the given option for the given Eclipse preferences.
 * If no value was already set, then inherits from the global options if specified.
 *
 * @param optionName The name of the option
 * @param inheritJavaCoreOptions Tells whether the value can be inherited from global JavaCore options
 * @param projectPreferences The eclipse preferences from which to get the value
 * @return The value of the option. May be <code>null</code>
 */
public String getOption(String optionName, boolean inheritJavaCoreOptions, IEclipsePreferences projectPreferences) {
	// Return the option value depending on its level
	switch (getOptionLevel(optionName)) {
		case VALID_OPTION:
			// Valid option, return the preference value
			String javaCoreDefault = inheritJavaCoreOptions ? JavaCore.getOption(optionName) : null;
			if (projectPreferences == null) return javaCoreDefault;
			String value = projectPreferences.get(optionName, javaCoreDefault);
			return value == null ? null : value.trim();
		case DEPRECATED_OPTION:
			// Return the deprecated option value if it was already set
			String oldValue = projectPreferences.get(optionName, null);
			if (oldValue != null) {
				return oldValue.trim();
			}
			// Get the new compatible value
			String[] compatibleOptions = (String[]) this.deprecatedOptions.get(optionName);
			String newDefault = inheritJavaCoreOptions ? JavaCore.getOption(compatibleOptions[0]) : null;
			String newValue = projectPreferences.get(compatibleOptions[0], newDefault);
			return newValue == null ? null : newValue.trim();
	}
	return null;
}
 
Example 5
Source File: ExecutableEntry.java    From ice with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * This operation loads the ExecutableEntry from Eclipse Preferences. 
 * @param prefId
 */
public void loadFromPreferences(String prefId) {
	// Get the Application preferences
	IEclipsePreferences prefs = InstanceScope.INSTANCE.getNode(prefId);
	try {
		for (String key : prefs.keys()) {
			String pref = prefs.get(key, "");
			if (!pref.isEmpty()) {
				allowedValues.add(pref);
				allowedValueToURI.put(pref, URI.create(key));
			}
		}
	} catch (BackingStoreException e) {
		logger.error(getClass().getName() + " Exception!", e);
	}

	if (!allowedValues.isEmpty()) {
		allowedValues.add(0, "Select Application");
		setDefaultValue(allowedValues.get(0));
	} else {
		allowedValues.add("Import Application");
		setDefaultValue(allowedValues.get(0));
	}
}
 
Example 6
Source File: PreferencesHelper.java    From typescript.java with MIT License 5 votes vote down vote up
/**
 * Returns the boolean preference value from the given key and Eclipse
 * preferences.
 * 
 * @param key
 *            the preference name.
 * @param def
 *            the default value if not found.
 * @param preferences
 *            the Eclipse preferences.
 * @return the boolean preference value from the given key and Eclipse
 *         preferences.
 */
private static Boolean getBooleanPreferencesValue(IEclipsePreferences preferences, String key, Boolean def) {
	if (preferences == null) {
		return def;
	}
	String result = preferences.get(key, null);
	if (result == null) {
		return def;
	}
	try {
		return Boolean.parseBoolean(result);
	} catch (Throwable e) {
		return def;
	}
}
 
Example 7
Source File: TypeScriptCorePreferenceInitializer.java    From typescript.java with MIT License 5 votes vote down vote up
/**
 * Fix the embedded TypeScript runtime ande node.js preference if needed.
 * 
 * @param preferences
 * @see https://github.com/angelozerr/typescript.java/issues/121
 */
public static void fixEmbeddedPreference(IEclipsePreferences preferences) {
	boolean refresh = false;
	// Fix embedded TypeScript runtime if needed
	String embeddedTypeScriptId = preferences.get(TypeScriptCorePreferenceConstants.EMBEDDED_TYPESCRIPT_ID, null);
	if (embeddedTypeScriptId != null
			&& TypeScriptCorePlugin.getTypeScriptRepositoryManager().getRepository(embeddedTypeScriptId) == null) {
		preferences.put(TypeScriptCorePreferenceConstants.EMBEDDED_TYPESCRIPT_ID,
				TypeScriptCorePlugin.getTypeScriptRepositoryManager().getDefaultRepository().getName());
		refresh = true;
	}
	// Fix embedded node.js if needed
	String embeddedNode = preferences.get(TypeScriptCorePreferenceConstants.NODEJS_EMBEDDED_ID, null);
	if (embeddedNode != null
			&& TypeScriptCorePlugin.getNodejsInstallManager().findNodejsInstall(embeddedNode) == null) {
		if (useBundledNodeJsEmbedded(preferences)) {
			refresh = true;
		}
	}
	if (refresh) {
		try {
			preferences.flush();
		} catch (BackingStoreException e) {
			Trace.trace(Trace.SEVERE, "Error while fixing embedded TypeScript runtime and node.js preference", e);
		}
	}
}
 
Example 8
Source File: CleanUpPreferenceUtil.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public static boolean hasSettingsInScope(IScopeContext context) {
  	IEclipsePreferences node= context.getNode(JavaUI.ID_PLUGIN);

  	Set<String> keys= JavaPlugin.getDefault().getCleanUpRegistry().getDefaultOptions(CleanUpConstants.DEFAULT_SAVE_ACTION_OPTIONS).getKeys();
for (Iterator<String> iterator= keys.iterator(); iterator.hasNext();) {
	String key= iterator.next();
	if (node.get(SAVE_PARTICIPANT_KEY_PREFIX + key, null) != null)
		return true;
      }

  	return false;
  }
 
Example 9
Source File: ProfileManager.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public static boolean hasProjectSpecificSettings(IScopeContext context, KeySet[] keySets) {
	for (int i= 0; i < keySets.length; i++) {
        KeySet keySet= keySets[i];
        IEclipsePreferences preferences= context.getNode(keySet.getNodeName());
        for (final Iterator<String> keyIter= keySet.getKeys().iterator(); keyIter.hasNext();) {
            final String key= keyIter.next();
            Object val= preferences.get(key, null);
            if (val != null) {
            	return true;
            }
           }
       }
	return false;
}
 
Example 10
Source File: SyncSystemModulesManager.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
public List<TreeNode> createInitialSelectionForDialogConsideringPreviouslyIgnored(DataAndImageTreeNode root,
        IEclipsePreferences iPreferenceStore) {
    List<TreeNode> initialSelection = new ArrayList<>();
    for (DataAndImageTreeNode<IInterpreterInfo> interpreterNode : (List<DataAndImageTreeNode<IInterpreterInfo>>) root
            .getChildren()) {

        IInterpreterInfo info = interpreterNode.getData();
        String key = createKeyForInfo(info);

        String ignoredValue = iPreferenceStore.get(key, "");
        if (ignoredValue != null && ignoredValue.length() > 0) {
            Set<String> previouslyIgnored = new HashSet(StringUtils.split(ignoredValue, "|||"));

            boolean added = false;
            for (TreeNode<PythonpathChange> pathNode : interpreterNode.getChildren()) {
                if (!previouslyIgnored.contains(pathNode.data.path)) {
                    initialSelection.add(pathNode);
                    added = true;
                } else {
                    if (SyncSystemModulesManager.DEBUG) {
                        System.out.println("Removed from initial selection: " + pathNode);
                    }
                }
            }
            if (added) {
                initialSelection.add(interpreterNode);
            }
        } else {
            //Node and children all selected initially (nothing ignored).
            initialSelection.add(interpreterNode);
            initialSelection.addAll(interpreterNode.getChildren());
        }
    }
    if (SyncSystemModulesManager.DEBUG) {
        for (TreeNode treeNode : initialSelection) {
            System.out.println("Initial selection: " + treeNode.getData());
        }
    }
    return initialSelection;
}
 
Example 11
Source File: DeployPreferences.java    From google-cloud-eclipse with Apache License 2.0 5 votes vote down vote up
protected DeployPreferences(IEclipsePreferences preferenceStore) {
  this.preferenceStore = preferenceStore;

  accountEmail = preferenceStore.get(PREF_ACCOUNT_EMAIL, DEFAULT_ACCOUNT_EMAIL);
  projectId = preferenceStore.get(PREF_PROJECT_ID, DEFAULT_PROJECT_ID);
  version = preferenceStore.get(PREF_CUSTOM_VERSION, DEFAULT_CUSTOM_VERSION);
  autoPromote = preferenceStore.getBoolean(PREF_ENABLE_AUTO_PROMOTE, DEFAULT_ENABLE_AUTO_PROMOTE);
  includeOptionalConfigurationFiles = preferenceStore.getBoolean(
      PREF_INCLUDE_OPTIONAL_CONFIGURATION_FILES, DEFAULT_INCLUDE_OPTIONAL_CONFIGURATION_FILES);
  bucket = preferenceStore.get(PREF_CUSTOM_BUCKET, DEFAULT_CUSTOM_BUCKET);
  stopPreviousVersion = preferenceStore.getBoolean(
      PREF_STOP_PREVIOUS_VERSION, DEFAULT_STOP_PREVIOUS_VERSION);
}
 
Example 12
Source File: LanguageConfigurationRegistryManager.java    From tm4e with Eclipse Public License 1.0 5 votes vote down vote up
private void loadFromPreferences() {
	// Load grammar definitions from the
	// "${workspace_loc}/metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.tm4e.languageconfiguration.prefs"
	IEclipsePreferences prefs = InstanceScope.INSTANCE.getNode(LanguageConfigurationPlugin.PLUGIN_ID);
	String json = prefs.get(PreferenceConstants.LANGUAGE_CONFIGURATIONS, null);
	if (json != null) {
		ILanguageConfigurationDefinition[] definitions = PreferenceHelper
				.loadLanguageConfigurationDefinitions(json);
		for (ILanguageConfigurationDefinition definition : definitions) {
			registerLanguageConfigurationDefinition(definition);
		}
	}
}
 
Example 13
Source File: PyLintPreferences.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
public static File getPyLintLocation(IPythonNature pythonNature) {
    IEclipsePreferences preferences = PydevPrefs.getEclipsePreferences();
    if (LOCATION_SPECIFY.equals(preferences.get(SEARCH_PYLINT_LOCATION, DEFAULT_SEARCH_PYLINT_LOCATION))) {
        return new File(preferences.get(PYLINT_FILE_LOCATION, ""));
    }
    try {
        return pythonNature.getProjectInterpreter().searchExecutableForInterpreter("pylint", false);
    } catch (Exception e) {
        Log.log(e);
        return null;
    }
}
 
Example 14
Source File: CordovaEngineProvider.java    From thym with Eclipse Public License 1.0 5 votes vote down vote up
private List<HybridMobileEngine> getPreferencesEngines(){
	List<HybridMobileEngine> preferencesEngines = new ArrayList<>();
	IEclipsePreferences preferences = InstanceScope.INSTANCE.getNode(HybridCore.PLUGIN_ID);
	try {
		for(String key: preferences.keys()){
			String value = preferences.get(key, "");
			preferencesEngines.add(createEngine(key, value));
			
		}
	} catch (BackingStoreException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
	return preferencesEngines;
}
 
Example 15
Source File: GrammarRegistryManager.java    From tm4e with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Load TextMate grammars from preferences.
 */
private void loadGrammarsFromPreferences() {
	// Load grammar definitions from the
	// "${workspace_loc}/metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.tm4e.registry.prefs"
	IEclipsePreferences prefs = InstanceScope.INSTANCE.getNode(TMEclipseRegistryPlugin.PLUGIN_ID);
	String json = prefs.get(PreferenceConstants.GRAMMARS, null);
	if (json != null) {
		IGrammarDefinition[] definitions = PreferenceHelper.loadGrammars(json);
		for (IGrammarDefinition definition : definitions) {
			userCache.registerGrammarDefinition(definition);
		}
	}
}
 
Example 16
Source File: XmlUtils.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Load files status from preference store.
 */
public static void loadFilesStatus() {
    IEclipsePreferences preferences = Activator.getDefault().getCorePreferenceStore();
    String enabledFiles = preferences.get(ENABLED_FILES_PREFERENCE_KEY, null);
    if (enabledFiles != null) {
        fEnabledFiles = Sets.newHashSet(Splitter.on(ENABLED_FILES_SEP).omitEmptyStrings().split(enabledFiles));
    } else {
        fEnabledFiles = Sets.newHashSet();
    }
}
 
Example 17
Source File: ProfileManager.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.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<String, String> readFromPreferenceStore(IScopeContext context, Profile workspaceProfile) {
	final Map<String, String> profileOptions= new HashMap<String, String>();
	IEclipsePreferences uiPrefs= context.getNode(JavaUI.ID_PLUGIN);

	int version= uiPrefs.getInt(fProfileVersionKey, fProfileVersioner.getFirstVersion());
	if (version != fProfileVersioner.getCurrentVersion()) {
		Map<String, String> allOptions= new HashMap<String, String>();
		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<String> keyIter = keySet.getKeys().iterator(); keyIter.hasNext(); ) {
			final String key= keyIter.next();
			String 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 18
Source File: PreferenceInitializer.java    From APICloud-Studio with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void initializeDefaultPreferences()
{
	IEclipsePreferences prefs = EclipseUtil.defaultScope().getNode(JSCorePlugin.PLUGIN_ID);

	prefs.putDouble(IPreferenceConstants.JS_INDEX_VERSION, 0);

	// Warn on missing semicolons
	prefs.put(IPreferenceConstants.PREF_MISSING_SEMICOLON_SEVERITY, IProblem.Severity.WARNING.id());

	// Set up JS Parser validator to be on for build and reconcile
	prefs.putBoolean(PreferenceUtil.getEnablementPreferenceKey(JSParserValidator.ID, BuildType.BUILD), true);
	prefs.putBoolean(PreferenceUtil.getEnablementPreferenceKey(JSParserValidator.ID, BuildType.RECONCILE), true);

	// Set up JSLint prefs
	// Set default options
	// @formatter:off
	prefs.put(IPreferenceConstants.JS_LINT_OPTIONS, "{\n" + //$NON-NLS-1$
			"  \"laxLineEnd\": true,\n" + //$NON-NLS-1$
			"  \"undef\": true,\n" + //$NON-NLS-1$
			"  \"browser\": true,\n" + //$NON-NLS-1$
			"  \"jscript\": true,\n" + //$NON-NLS-1$
			"  \"debug\": true,\n" + //$NON-NLS-1$
			"  \"maxerr\": 100000,\n" + //$NON-NLS-1$
			"  \"white\": true,\n" + //$NON-NLS-1$
			"  \"predef\": [\n" + //$NON-NLS-1$
			"    \"Ti\",\n" + //$NON-NLS-1$
			"    \"Titanium\",\n" + //$NON-NLS-1$
			"    \"alert\",\n" + //$NON-NLS-1$
			"    \"require\",\n" + //$NON-NLS-1$
			"    \"exports\",\n" + //$NON-NLS-1$
			"    \"native\",\n" + //$NON-NLS-1$
			"    \"implements\",\n" + //$NON-NLS-1$
			"  ]\n" + //$NON-NLS-1$
			"}"); //$NON-NLS-1$
	// @formatter:on

	// Set default JSLint filters
	String[] defaultJSLintFilters = new String[] {
			"Missing space between .+", "Unexpected '\\(space\\)'\\.", //$NON-NLS-1$ //$NON-NLS-2$
			"Expected '.+' at column \\d+, not column \\d+\\.", "Unexpected space between .+", "Expected exactly one space between .+" }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
	prefs.put(PreferenceUtil.getFiltersKey(JSLintValidator.ID),
			PreferenceUtil.serializeFilters(defaultJSLintFilters));

	// Migrate the old filter prefs to new validator
	IEclipsePreferences cepPrefs = EclipseUtil.instanceScope().getNode("com.aptana.editor.common"); //$NON-NLS-1$
	String oldKey = MessageFormat.format("{0}:{1}", IJSConstants.CONTENT_TYPE_JS, //$NON-NLS-1$
			"com.aptana.editor.common.filterExpressions"); //$NON-NLS-1$
	String oldFilters = cepPrefs.get(oldKey, null);
	if (oldFilters != null)
	{
		try
		{
			String[] oldFilterArray = oldFilters.split(AbstractBuildParticipant.FILTER_DELIMITER);
			String[] combined = ArrayUtil.flatten(oldFilterArray, defaultJSLintFilters);

			IEclipsePreferences newPrefs = EclipseUtil.instanceScope().getNode(JSCorePlugin.PLUGIN_ID);
			newPrefs.put(PreferenceUtil.getFiltersKey(JSLintValidator.ID),
					PreferenceUtil.serializeFilters(combined));
			newPrefs.flush();
			cepPrefs.remove(oldKey);
		}
		catch (BackingStoreException e)
		{
			// ignore
		}
	}
}
 
Example 19
Source File: GdtPreferences.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Gets the problem severities as an encoded string. See
 * {@link com.google.gdt.eclipse.core.markers.GdtProblemSeverities} for details on how this string is decoded.
 */
public static String getEncodedProblemSeverities() {
  IEclipsePreferences instancePrefs = getConfigurationPreferences();
  return instancePrefs.get(PROBLEM_SEVERITIES, "");
}
 
Example 20
Source File: PreferencesHelper.java    From typescript.java with MIT License 3 votes vote down vote up
/**
 * Returns the String preference value from the given key and Eclipse
 * preferences.
 * 
 * @param key
 *            the preference name.
 * @param def
 *            the default value if not found.
 * @param preferences
 *            the Eclipse preferences.
 * @return the String preference value from the given key and Eclipse
 *         preferences.
 */
private static String getStringPreferencesValue(IEclipsePreferences preferences, String key, String def) {
	if (preferences == null) {
		return def;
	}
	String result = preferences.get(key, null);
	return result != null ? result : def;
}