Example usage for org.eclipse.jface.preference PreferenceStore load

List of usage examples for org.eclipse.jface.preference PreferenceStore load

Introduction

In this page you can find the example usage for org.eclipse.jface.preference PreferenceStore load.

Prototype

public void load(InputStream in) throws IOException 

Source Link

Document

Loads this preference store from the given input stream.

Usage

From source file:com.diffplug.gradle.spotless.groovy.eclipse.GrEclipseFormatterStepImpl.java

License:Apache License

private static PreferenceStore createPreferences(final Properties properties) throws IOException {
    final PreferenceStore preferences = new PreferenceStore();
    ByteArrayOutputStream output = new ByteArrayOutputStream();
    properties.store(output, null);//from   ww w .j  a v a2s  .com
    ByteArrayInputStream input = new ByteArrayInputStream(output.toByteArray());
    preferences.load(input);
    return preferences;
}

From source file:net.sourceforge.eclipsetrader.core.CorePlugin.java

License:Open Source License

/**
 * Log4j configurator//from   w w w . j a  v a2 s . c om
 */
public void configureLogging() {
    try {
        PreferenceStore preferences = new PreferenceStore();

        // Set the default values from extension registry
        IExtensionRegistry registry = Platform.getExtensionRegistry();
        IExtensionPoint extensionPoint = registry
                .getExtensionPoint(CorePlugin.LOGGER_PREFERENCES_EXTENSION_POINT);
        IConfigurationElement[] members = extensionPoint.getConfigurationElements();
        for (int i = 0; i < members.length; i++) {
            IConfigurationElement element = members[i];
            if (element.getName().equals("logger")) //$NON-NLS-1$
            {
                if (element.getAttribute("defaultValue") != null) //$NON-NLS-1$
                {
                    String[] item = element.getAttribute("name").split(";"); //$NON-NLS-1$ //$NON-NLS-2$
                    for (int x = 0; x < item.length; x++)
                        preferences.setDefault("log4j.logger." + item[x], element.getAttribute("defaultValue")); //$NON-NLS-1$ //$NON-NLS-2$
                }
            }
        }

        // Set the default values from the bundle's properties file
        try {
            URL url = CorePlugin.getDefault().getBundle().getResource("log4j.properties"); //$NON-NLS-1$
            Properties properties = new Properties();
            properties.load(url.openStream());
            for (Iterator iter = properties.keySet().iterator(); iter.hasNext();) {
                String key = (String) iter.next();
                preferences.setDefault(key, (String) properties.get(key));
            }

            // Read the values from the user's configuration
            File file = CorePlugin.getDefault().getStateLocation().append("log4j.properties").toFile(); //$NON-NLS-1$
            if (file.exists())
                preferences.load(new FileInputStream(file));
        } catch (Exception e) {
            CorePlugin.logException(e);
        }

        // Configure log4j
        Properties properties = new Properties();
        String[] names = preferences.preferenceNames();
        for (int i = 0; i < names.length; i++)
            properties.put(names[i], preferences.getString(names[i]));
        PropertyConfigurator.configure(properties);
    } catch (Exception e) {
        BasicConfigurator.configure();
        logException(e);
    }
}

From source file:org.apache.opennlp.corpus_server.caseditor.DefaultCasDocumentProvider.java

License:Apache License

@Override
public IPreferenceStore getTypeSystemPreferenceStore(Object element) {

    PreferenceStore tsStore = tsPreferenceStores.get(element);

    if (tsStore == null) {

        IPreferenceStore store = CorpusServerPlugin.getDefault().getPreferenceStore();

        String tsStoreString = store.getString(getTypeSystemId((CorpusServerCasEditorInput) element));

        tsStore = new PreferenceStore();

        if (tsStoreString.length() != 0) {
            InputStream tsStoreIn = new ByteArrayInputStream(tsStoreString.getBytes(Charset.forName("UTF-8")));

            try {
                tsStore.load(tsStoreIn);
            } catch (IOException e) {
                e.printStackTrace();/*from w  w w  .j  a v  a  2s  .  co  m*/
            }
        }

        tsPreferenceStores.put(element, tsStore);
    }

    return tsStore;
}

From source file:org.jamon.eclipse.editor.preferences.PreferencesInitializer.java

License:Mozilla Public License

private void loadFromStandardPreferences(IPreferenceStore preferenceStore) {
    InputStream is = getClass().getResourceAsStream("jamon.syntax.default.preferences");
    if (is != null) {
        try {/*from w  w  w.j a v  a  2  s. c  om*/
            PreferenceStore ps = new PreferenceStore();
            ps.load(is);
            for (String name : ps.preferenceNames()) {
                preferenceStore.setDefault(name, ps.getString(name));
            }
        } catch (IOException e) {
            EclipseUtils.logError(e);
        } finally {
            EclipseUtils.closeQuiety(is);
        }
    }
}