Search in sources :

Example 41 with IEclipsePreferences

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

the class JavaProject method setOption.

@Override
public void setOption(String optionName, String optionValue) {
    // Store option value
    IEclipsePreferences projectPreferences = getEclipsePreferences();
    boolean modified = getJavaModelManager().storePreference(optionName, optionValue, projectPreferences, null);
    // Write changes
    if (modified) {
        try {
            projectPreferences.flush();
        } catch (BackingStoreException e) {
        // problem with pref store - quietly ignore
        }
    }
    getJavaModelManager().resetProjectOptions(JavaProject.this);
    // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=233568
    JavaProject.this.resetCaches();
}
Also used : IEclipsePreferences(org.eclipse.core.runtime.preferences.IEclipsePreferences) BackingStoreException(org.osgi.service.prefs.BackingStoreException)

Example 42 with IEclipsePreferences

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

the class JavaProject method getOptions.

public Map getOptions(boolean inheritJavaCoreOptions) {
    // initialize to the defaults from JavaCore options pool
    Map options = inheritJavaCoreOptions ? JavaCore.getOptions() : new Hashtable(5);
    // Get project specific options
    PerProjectInfo perProjectInfo = null;
    Hashtable projectOptions = null;
    JavaModelManager javaModelManager = getJavaModelManager();
    HashSet optionNames = javaModelManager.optionNames;
    try {
        perProjectInfo = getPerProjectInfo();
        projectOptions = perProjectInfo.options;
        if (projectOptions == null) {
            // get eclipse preferences
            IEclipsePreferences projectPreferences = getEclipsePreferences();
            // cannot do better (non-Java project)
            if (projectPreferences == null)
                return options;
            // create project options
            String[] propertyNames = projectPreferences.keys();
            projectOptions = new Hashtable(propertyNames.length);
            for (int i = 0; i < propertyNames.length; i++) {
                String propertyName = propertyNames[i];
                String value = projectPreferences.get(propertyName, null);
                if (value != null) {
                    value = value.trim();
                    // Keep the option value, even if it's deprecated
                    // see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=324987
                    projectOptions.put(propertyName, value);
                    if (!optionNames.contains(propertyName)) {
                        // try to migrate deprecated options
                        String[] compatibleOptions = (String[]) javaModelManager.deprecatedOptions.get(propertyName);
                        if (compatibleOptions != null) {
                            for (int co = 0, length = compatibleOptions.length; co < length; co++) {
                                String compatibleOption = compatibleOptions[co];
                                if (!projectOptions.containsKey(compatibleOption))
                                    projectOptions.put(compatibleOption, value);
                            }
                        }
                    }
                }
            }
            // cache project options
            perProjectInfo.options = projectOptions;
        }
    } catch (JavaModelException jme) {
        projectOptions = new Hashtable();
    } catch (BackingStoreException e) {
        projectOptions = new Hashtable();
    }
    // Inherit from JavaCore options if specified
    if (inheritJavaCoreOptions) {
        Iterator propertyNames = projectOptions.entrySet().iterator();
        while (propertyNames.hasNext()) {
            Map.Entry entry = (Map.Entry) propertyNames.next();
            String propertyName = (String) entry.getKey();
            String propertyValue = (String) entry.getValue();
            if (propertyValue != null && javaModelManager.knowsOption(propertyName)) {
                options.put(propertyName, propertyValue.trim());
            }
        }
        Util.fixTaskTags(options);
        return options;
    }
    Util.fixTaskTags(projectOptions);
    return projectOptions;
}
Also used : JavaModelException(org.eclipse.jdt.core.JavaModelException) IEclipsePreferences(org.eclipse.core.runtime.preferences.IEclipsePreferences) Hashtable(java.util.Hashtable) BackingStoreException(org.osgi.service.prefs.BackingStoreException) JavaModelManager.getJavaModelManager(org.eclipse.jdt.internal.core.JavaModelManager.getJavaModelManager) PerProjectInfo(org.eclipse.jdt.internal.core.JavaModelManager.PerProjectInfo) IClasspathEntry(org.eclipse.jdt.core.IClasspathEntry) Iterator(java.util.Iterator) Map(java.util.Map) HashMap(java.util.HashMap) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 43 with IEclipsePreferences

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

the class PersistUtils method saveXMLMemento.

/**
	 * 
	 * Save the xml content to instance scope preference
	 * 
	 * @param pluginId String
	 * @param key String
	 * @param memento XMLMemento
	 */
public static void saveXMLMemento(String pluginId, String key, XMLMemento memento) {
    String xmlString = null;
    try {
        xmlString = memento.saveToString();
    } catch (IOException e1) {
        e1.printStackTrace();
    }
    IEclipsePreferences preference = PersistUtils.getPreference(pluginId);
    try {
        preference.put(key, xmlString);
        preference.flush();
    } catch (BackingStoreException e) {
        preference = null;
    }
}
Also used : IEclipsePreferences(org.eclipse.core.runtime.preferences.IEclipsePreferences) BackingStoreException(org.osgi.service.prefs.BackingStoreException) IOException(java.io.IOException)

Example 44 with IEclipsePreferences

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

the class NodeFilterManager method loadFilterSetting.

@SuppressWarnings("deprecation")
private void loadFilterSetting() {
    synchronized (this) {
        IEclipsePreferences preference = new InstanceScope().getNode(CommonUIPlugin.PLUGIN_ID);
        String xmlString = preference.get(FILTER_XML_CONTENT, "");
        if (StringUtil.isEmpty(xmlString)) {
            LOGGER.warn("The preference.get(FILTER_XML_CONTENT) has a empty string.");
            return;
        }
        try {
            ByteArrayInputStream in = new ByteArrayInputStream(xmlString.getBytes("UTF-8"));
            IXMLMemento memento = XMLMemento.loadMemento(in);
            if (memento == null) {
                LOGGER.error("XMLMemento.loadMemento(in) is a null.");
                return;
            }
            IXMLMemento[] children = memento.getChildren("idFilter");
            for (int i = 0; i < children.length; i++) {
                String id = children[i].getString("id");
                idFilterList.add(id);
            }
            children = memento.getChildren("idGrayFilter");
            for (int i = 0; i < children.length; i++) {
                String id = children[i].getString("id");
                idGrayFilterList.add(id);
            }
            children = memento.getChildren("nameFilter");
            for (int i = 0; i < children.length; i++) {
                String pattern = children[i].getString("pattern");
                nameFilterList.add(pattern);
            }
        } catch (UnsupportedEncodingException e) {
            LOGGER.error("loadFilterSetting()", e);
        }
    }
}
Also used : IEclipsePreferences(org.eclipse.core.runtime.preferences.IEclipsePreferences) ByteArrayInputStream(java.io.ByteArrayInputStream) IXMLMemento(com.cubrid.cubridmanager.core.common.xml.IXMLMemento) InstanceScope(org.eclipse.core.runtime.preferences.InstanceScope) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 45 with IEclipsePreferences

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

the class CubridStatusMonitorInstance method removeSetting.

/**
	 * Remove the info of StatusMonInstanceData relevant to key from preference
	 * 
	 * @param key the key relevant to saving instance of StatusMonInstanceData
	 */
public void removeSetting(String key) {
    synchronized (this) {
        IEclipsePreferences preference = new InstanceScope().getNode(CubridManagerUIPlugin.PLUGIN_ID);
        preference.remove(key);
        try {
            preference.flush();
        } catch (BackingStoreException ex) {
            LOGGER.error(ex.getMessage());
        }
    }
}
Also used : IEclipsePreferences(org.eclipse.core.runtime.preferences.IEclipsePreferences) InstanceScope(org.eclipse.core.runtime.preferences.InstanceScope) BackingStoreException(org.osgi.service.prefs.BackingStoreException)

Aggregations

IEclipsePreferences (org.eclipse.core.runtime.preferences.IEclipsePreferences)79 BackingStoreException (org.osgi.service.prefs.BackingStoreException)15 Test (org.junit.Test)11 InstanceScope (org.eclipse.core.runtime.preferences.InstanceScope)9 IPreferenceStore (org.eclipse.jface.preference.IPreferenceStore)9 IXMLMemento (com.cubrid.cubridmanager.core.common.xml.IXMLMemento)6 ProjectScope (org.eclipse.core.resources.ProjectScope)6 IScopeContext (org.eclipse.core.runtime.preferences.IScopeContext)6 After (org.junit.After)6 ByteArrayInputStream (java.io.ByteArrayInputStream)5 IOException (java.io.IOException)5 ArrayList (java.util.ArrayList)5 UnsupportedEncodingException (java.io.UnsupportedEncodingException)4 HashMap (java.util.HashMap)4 HashSet (java.util.HashSet)4 Iterator (java.util.Iterator)4 Map (java.util.Map)4 XMLMemento (com.cubrid.cubridmanager.core.common.xml.XMLMemento)3 ISourceViewer (org.eclipse.jface.text.source.ISourceViewer)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2