Search in sources :

Example 1 with IEclipsePreferences

use of org.eclipse.core.runtime.preferences.IEclipsePreferences in project che by eclipse.

the class PreferenceInitializer method initializeDefaultPreferences.

/* (non-Javadoc)
	 * @see org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer#initializeDefaultPreferences()
	 */
@Override
public void initializeDefaultPreferences() {
    IEclipsePreferences node = DefaultScope.INSTANCE.getNode(ResourcesPlugin.PI_RESOURCES);
    // auto-refresh default
    node.putBoolean(ResourcesPlugin.PREF_AUTO_REFRESH, PREF_AUTO_REFRESH_DEFAULT);
    node.putBoolean(ResourcesPlugin.PREF_LIGHTWEIGHT_AUTO_REFRESH, PREF_LIGHTWEIGHT_AUTO_REFRESH_DEFAULT);
    // linked resources default
    node.putBoolean(ResourcesPlugin.PREF_DISABLE_LINKING, PREF_DISABLE_LINKING_DEFAULT);
    // build manager defaults
    node.putBoolean(ResourcesPlugin.PREF_AUTO_BUILDING, PREF_AUTO_BUILDING_DEFAULT);
    node.put(ResourcesPlugin.PREF_BUILD_ORDER, PREF_BUILD_ORDER_DEFAULT);
    node.putInt(ResourcesPlugin.PREF_MAX_BUILD_ITERATIONS, PREF_MAX_BUILD_ITERATIONS_DEFAULT);
    node.putBoolean(ResourcesPlugin.PREF_DEFAULT_BUILD_ORDER, PREF_DEFAULT_BUILD_ORDER_DEFAULT);
    // history store defaults
    node.putBoolean(ResourcesPlugin.PREF_APPLY_FILE_STATE_POLICY, PREF_APPLY_FILE_STATE_POLICY_DEFAULT);
    node.putLong(ResourcesPlugin.PREF_FILE_STATE_LONGEVITY, PREF_FILE_STATE_LONGEVITY_DEFAULT);
    node.putLong(ResourcesPlugin.PREF_MAX_FILE_STATE_SIZE, PREF_MAX_FILE_STATE_SIZE_DEFAULT);
    node.putInt(ResourcesPlugin.PREF_MAX_FILE_STATES, PREF_MAX_FILE_STATES_DEFAULT);
    // save manager defaults
    node.putLong(ResourcesPlugin.PREF_SNAPSHOT_INTERVAL, PREF_SNAPSHOT_INTERVAL_DEFAULT);
    node.putInt(PREF_OPERATIONS_PER_SNAPSHOT, PREF_OPERATIONS_PER_SNAPSHOT_DEFAULT);
    node.putLong(PREF_DELTA_EXPIRATION, PREF_DELTA_EXPIRATION_DEFAULT);
    // encoding defaults
    node.put(ResourcesPlugin.PREF_ENCODING, PREF_ENCODING_DEFAULT);
}
Also used : IEclipsePreferences(org.eclipse.core.runtime.preferences.IEclipsePreferences)

Example 2 with IEclipsePreferences

use of org.eclipse.core.runtime.preferences.IEclipsePreferences in project che by eclipse.

the class JavaProject method setOptions.

@Override
public void setOptions(Map newOptions) {
    IEclipsePreferences projectPreferences = getEclipsePreferences();
    if (projectPreferences == null)
        return;
    try {
        if (newOptions == null) {
            projectPreferences.clear();
        } else {
            Iterator entries = newOptions.entrySet().iterator();
            JavaModelManager javaModelManager = getJavaModelManager();
            while (entries.hasNext()) {
                Map.Entry entry = (Map.Entry) entries.next();
                String key = (String) entry.getKey();
                String value = (String) entry.getValue();
                javaModelManager.storePreference(key, value, projectPreferences, newOptions);
            }
            // reset to default all options not in new map
            // @see https://bugs.eclipse.org/bugs/show_bug.cgi?id=26255
            // @see https://bugs.eclipse.org/bugs/show_bug.cgi?id=49691
            String[] pNames = projectPreferences.keys();
            int ln = pNames.length;
            for (int i = 0; i < ln; i++) {
                String key = pNames[i];
                if (!newOptions.containsKey(key)) {
                    // old preferences => remove from preferences table
                    projectPreferences.remove(key);
                }
            }
        }
        // persist options
        projectPreferences.flush();
        // flush cache immediately
        try {
            getPerProjectInfo().options = null;
        } catch (JavaModelException e) {
        // do nothing
        }
    } catch (BackingStoreException e) {
    // problem with pref store - quietly ignore
    }
}
Also used : JavaModelManager.getJavaModelManager(org.eclipse.jdt.internal.core.JavaModelManager.getJavaModelManager) IClasspathEntry(org.eclipse.jdt.core.IClasspathEntry) JavaModelException(org.eclipse.jdt.core.JavaModelException) IEclipsePreferences(org.eclipse.core.runtime.preferences.IEclipsePreferences) Iterator(java.util.Iterator) BackingStoreException(org.osgi.service.prefs.BackingStoreException) Map(java.util.Map) HashMap(java.util.HashMap)

Example 3 with IEclipsePreferences

use of org.eclipse.core.runtime.preferences.IEclipsePreferences in project cubrid-manager by CUBRID.

the class PersistUtils method setGlobalPreferenceValue.

/**
	 * Save value to global preference of configuration scope
	 * 
	 * @param pluginId String
	 * @param key the key
	 * @param value the value
	 */
public static void setGlobalPreferenceValue(String pluginId, String key, String value) {
    IEclipsePreferences prefs = getGlobalPreference(pluginId);
    prefs.put(key, value);
    try {
        prefs.flush();
    } catch (BackingStoreException e) {
        prefs = null;
    }
}
Also used : IEclipsePreferences(org.eclipse.core.runtime.preferences.IEclipsePreferences) BackingStoreException(org.osgi.service.prefs.BackingStoreException)

Example 4 with IEclipsePreferences

use of org.eclipse.core.runtime.preferences.IEclipsePreferences in project cubrid-manager by CUBRID.

the class PersistUtils method setPreferenceValue.

/**
	 * Save value to plugin preference of instance scope
	 * 
	 * @param pluginId String
	 * @param key the key
	 * @param value the value
	 */
public static void setPreferenceValue(String pluginId, String key, String value) {
    IEclipsePreferences prefs = getPreference(pluginId);
    prefs.put(key, value);
    try {
        prefs.flush();
    } catch (BackingStoreException e) {
        prefs = null;
    }
}
Also used : IEclipsePreferences(org.eclipse.core.runtime.preferences.IEclipsePreferences) BackingStoreException(org.osgi.service.prefs.BackingStoreException)

Example 5 with IEclipsePreferences

use of org.eclipse.core.runtime.preferences.IEclipsePreferences in project cubrid-manager by CUBRID.

the class PersistUtils method getXMLMemento.

/**
	 * Get the node XML memento from instance scope preference
	 * 
	 * @param pluginId String
	 * @param key String
	 * @return IXMLMemento
	 */
public static IXMLMemento getXMLMemento(String pluginId, String key) {
    IEclipsePreferences preference = getPreference(pluginId);
    String xmlString = preference.get(key, "");
    if (xmlString == null || xmlString.length() == 0) {
        return null;
    }
    try {
        ByteArrayInputStream in = new ByteArrayInputStream(xmlString.getBytes("UTF-8"));
        return XMLMemento.loadMemento(in);
    } catch (UnsupportedEncodingException e) {
        return null;
    }
}
Also used : IEclipsePreferences(org.eclipse.core.runtime.preferences.IEclipsePreferences) ByteArrayInputStream(java.io.ByteArrayInputStream) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Aggregations

IEclipsePreferences (org.eclipse.core.runtime.preferences.IEclipsePreferences)319 BackingStoreException (org.osgi.service.prefs.BackingStoreException)75 Test (org.junit.Test)36 DefaultScope (org.eclipse.core.runtime.preferences.DefaultScope)24 ProjectScope (org.eclipse.core.resources.ProjectScope)23 CoreException (org.eclipse.core.runtime.CoreException)18 IScopeContext (org.eclipse.core.runtime.preferences.IScopeContext)17 InstanceScope (org.eclipse.core.runtime.preferences.InstanceScope)15 IStatus (org.eclipse.core.runtime.IStatus)14 IProject (org.eclipse.core.resources.IProject)13 IOException (java.io.IOException)11 ArrayList (java.util.ArrayList)11 Status (org.eclipse.core.runtime.Status)11 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)11 ContentAssistProcessorTestBuilder (org.eclipse.xtext.ui.testing.ContentAssistProcessorTestBuilder)10 IPreferenceStore (org.eclipse.jface.preference.IPreferenceStore)9 Preferences (org.osgi.service.prefs.Preferences)8 File (java.io.File)7 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)7 After (org.junit.After)7