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

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

Introduction

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

Prototype

public void save(OutputStream out, String header) throws IOException 

Source Link

Document

Saves this preference store to the given output stream.

Usage

From source file:com.android.sdkstats.DdmsPreferenceStore.java

License:Apache License

/**
 * Returns the DDMS {@link PreferenceStore}.
 * This keeps a static reference on the store, so consequent calls will
 * return always the same store.//  w  w  w. j  ava  2 s.c  o m
 */
public PreferenceStore getPreferenceStore() {
    synchronized (DdmsPreferenceStore.class) {
        if (sPrefStore == null) {
            // get the location of the preferences
            String homeDir = null;
            try {
                homeDir = AndroidLocation.getFolder();
            } catch (AndroidLocationException e1) {
                // pass, we'll do a dummy store since homeDir is null
            }

            if (homeDir == null) {
                sPrefStore = new PreferenceStore();
                return sPrefStore;
            }

            assert homeDir != null;

            String rcFileName = homeDir + "ddms.cfg"; //$NON-NLS-1$

            // also look for an old pref file in the previous location
            String oldPrefPath = System.getProperty("user.home") //$NON-NLS-1$
                    + File.separator + ".ddmsrc"; //$NON-NLS-1$
            File oldPrefFile = new File(oldPrefPath);
            if (oldPrefFile.isFile()) {
                FileOutputStream fileOutputStream = null;
                try {
                    PreferenceStore oldStore = new PreferenceStore(oldPrefPath);
                    oldStore.load();

                    fileOutputStream = new FileOutputStream(rcFileName);
                    oldStore.save(fileOutputStream, ""); //$NON-NLS-1$
                    oldPrefFile.delete();

                    PreferenceStore newStore = new PreferenceStore(rcFileName);
                    newStore.load();
                    sPrefStore = newStore;
                } catch (IOException e) {
                    // create a new empty store.
                    sPrefStore = new PreferenceStore(rcFileName);
                } finally {
                    if (fileOutputStream != null) {
                        try {
                            fileOutputStream.close();
                        } catch (IOException e) {
                            // pass
                        }
                    }
                }
            } else {
                sPrefStore = new PreferenceStore(rcFileName);

                try {
                    sPrefStore.load();
                } catch (IOException e) {
                    System.err.println("Error Loading DDMS Preferences");
                }
            }
        }

        assert sPrefStore != null;
        return sPrefStore;
    }
}

From source file:com.android.sdkstats.SdkStatsService.java

License:Apache License

/**
 * Returns the DDMS {@link PreferenceStore}.
 *//*from   w w w  .j a va 2 s. c  om*/
public static synchronized PreferenceStore getPreferenceStore() {
    if (sPrefStore == null) {
        // get the location of the preferences
        String homeDir = null;
        try {
            homeDir = AndroidLocation.getFolder();
        } catch (AndroidLocationException e1) {
            // pass, we'll do a dummy store since homeDir is null
        }

        if (homeDir != null) {
            String rcFileName = homeDir + "ddms.cfg"; //$NON-NLS-1$

            // also look for an old pref file in the previous location
            String oldPrefPath = System.getProperty("user.home") //$NON-NLS-1$
                    + File.separator + ".ddmsrc"; //$NON-NLS-1$
            File oldPrefFile = new File(oldPrefPath);
            if (oldPrefFile.isFile()) {
                try {
                    PreferenceStore oldStore = new PreferenceStore(oldPrefPath);
                    oldStore.load();

                    oldStore.save(new FileOutputStream(rcFileName), "");
                    oldPrefFile.delete();

                    PreferenceStore newStore = new PreferenceStore(rcFileName);
                    newStore.load();
                    sPrefStore = newStore;
                } catch (IOException e) {
                    // create a new empty store.
                    sPrefStore = new PreferenceStore(rcFileName);
                }
            } else {
                sPrefStore = new PreferenceStore(rcFileName);

                try {
                    sPrefStore.load();
                } catch (IOException e) {
                    System.err.println("Error Loading Preferences");
                }
            }
        } else {
            sPrefStore = new PreferenceStore();
        }
    }

    return sPrefStore;
}

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

License:Apache License

@Override
public void saveTypeSystemPreferenceStore(Object element) {

    PreferenceStore tsStore = tsPreferenceStores.get(element);

    if (tsStore != null) {
        ByteArrayOutputStream tsStoreBytes = new ByteArrayOutputStream();
        try {/*from  w w w . j  a  v a  2 s  .  c o  m*/
            tsStore.save(tsStoreBytes, "");
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        IPreferenceStore store = CorpusServerPlugin.getDefault().getPreferenceStore();
        store.putValue(getTypeSystemId((CorpusServerCasEditorInput) element),
                new String(tsStoreBytes.toByteArray(), Charset.forName("UTF-8")));
    }

}

From source file:org.eclipse.help.ui.internal.views.ScopeSet.java

License:Open Source License

private void copy(PreferenceStore store) {
    try {/*ww  w  . ja v  a2 s  .  c o  m*/
        File file = File.createTempFile("sset", null); //$NON-NLS-1$
        FileOutputStream fos = new FileOutputStream(file);
        store.save(fos, ""); //$NON-NLS-1$
        fos.close();
        FileInputStream fis = new FileInputStream(file);
        getPreferenceStore();
        preferenceStore.load(fis);
        //when we clone the default set, we should
        //clear the default marker
        preferenceStore.setValue(KEY_DEFAULT, false);
        fis.close();
    } catch (IOException e) {
    }
}