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() throws IOException 

Source Link

Document

Loads this preference store from the file established in the constructor PreferenceStore(java.lang.String) (or by setFileName).

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.//ww w.  j  av  a 2 s.c om
 */
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}.
 */// w w w  . j  av  a  2s.  c  o  m
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:com.archimatetool.editor.preferences.ColoursFontsPreferencePage.java

License:Open Source License

/**
 * @throws IOException//w  ww.  j av  a2s  . c o m
 * Import a User color scheme
 */
private void importUserColors() throws IOException {
    FileDialog dialog = new FileDialog(getShell(), SWT.OPEN);
    dialog.setText(Messages.ColoursFontsPreferencePage_4);

    if (!PlatformUtils.isMac()) { // Single file filtering in the Open dialog doesn't work on Mac
        dialog.setFilterExtensions(new String[] { "ArchiColours.prefs", "*.prefs", "*.*" }); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        dialog.setFileName("ArchiColours.prefs"); //$NON-NLS-1$
    } else {
        dialog.setFilterExtensions(new String[] { "*.prefs", "*.*" }); //$NON-NLS-1$ //$NON-NLS-2$
    }

    String path = dialog.open();
    if (path == null) {
        return;
    }

    PreferenceStore store = new PreferenceStore(path);
    store.load();

    // Fill Colors
    for (Entry<Object, Color> entry : fColorsCache.entrySet()) {
        String key = DEFAULT_FILL_COLOR_PREFIX + getColorKey(entry.getKey());
        String value = store.getString(key);

        if (StringUtils.isSet(value)) {
            setColor(entry.getKey(), ColorFactory.convertStringToRGB(value));
        }
    }

    // Element Line Color
    String key = DEFAULT_ELEMENT_LINE_COLOR;
    String value = store.getString(key);
    if (StringUtils.isSet(value)) {
        setColor(key, ColorFactory.convertStringToRGB(value));
    }

    // Connection Line Color
    key = DEFAULT_CONNECTION_LINE_COLOR;
    value = store.getString(key);
    if (StringUtils.isSet(value)) {
        setColor(key, ColorFactory.convertStringToRGB(value));
    }
}

From source file:joachimeichborn.geotag.ui.preferences.PreferencesDialog.java

License:Open Source License

public void showDialog() {
    final PreferenceStore store = new PreferenceStore("joachimeichborn.geotag.preferences");
    try {/*from   w w w.  j av a2  s  .c  o  m*/
        store.load();
    } catch (IOException e) {
        logger.fine("Could not load preferences store: " + e.getMessage());
    }
    logger.fine("STORE: " + store);
    dialog.setPreferenceStore(store);
    dialog.open();

    try {
        store.save();
    } catch (IOException e) {
        logger.log(Level.WARNING, "Could not save preferences: " + e.getMessage(), e);
    }
}

From source file:net.sourceforge.eclipsetrader.trading.actions.OpenLevel2Action.java

License:Open Source License

public void run(IAction action) {
    if (security != null) {
        IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();

        PreferenceStore preferences = new PreferenceStore(
                Level2View.getPreferenceStoreLocation(security).toOSString());
        try {/*from   w  w w  .  j  a  v a2s .co m*/
            preferences.load();
        } catch (Exception e) {
        }

        // Builds a random secondary id, if a new view needs to be opened
        String secondaryId = preferences.getString("secondaryId");
        if (secondaryId.equals("")) {
            String values = "abcdefghijklmnopqrstuvwxyz";
            for (int i = 0; i < 8; i++)
                secondaryId += values.charAt((int) (Math.random() * values.length()));
        }

        try {
            Level2View view = (Level2View) page.showView(Level2View.VIEW_ID, secondaryId,
                    IWorkbenchPage.VIEW_ACTIVATE);
            view.setSecurity(security);
        } catch (PartInitException e) {
            CorePlugin.logException(e);
        }
    }
}

From source file:org.apache.felix.sigil.eclipse.internal.model.repository.RepositoryConfiguration.java

License:Apache License

private static RepositoryModel loadRepository(String id, String key, RepositoryType type,
        IPreferenceStore prefs) {//from  w  w  w.  ja  v  a2 s  .c  o m
    String name = type.isDynamic() ? prefs.getString(key + NAME) : type.getType();

    PreferenceStore repPrefs = new PreferenceStore();
    RepositoryModel element = new RepositoryModel(id, name, type, repPrefs);

    String loc = prefs.getString(key + LOC);

    if (loc == null || loc.trim().length() == 0) {
        loc = makeFileName(element);
    }

    repPrefs.setFilename(loc);

    if (new File(loc).exists()) {
        try {
            repPrefs.load();
        } catch (IOException e) {
            SigilCore.error("Failed to load properties for repository " + key, e);
        }
    }

    repPrefs.setValue("id", id);

    return element;
}

From source file:org.archicontribs.database.DBSelectDatabase.java

License:Open Source License

private void loadValues() {
    PreferenceStore store = new PreferenceStore("org.archicontribs.database");

    //if preferences are not set, that's not an error
    try {/*from  w w w.j  av a 2s . co m*/
        store.load();
    } catch (IOException e) {
        return;
    }

    driver.setText(store.getString("driver"));
    server.setText(store.getString("server"));
    port.setText(store.getString("port"));
    database.setText(store.getString("database"));
    remember.setSelection(store.getBoolean("remember"));
    doNotAskAgain.setSelection(store.getBoolean("doNotAskAgain"));
    username.setText(store.getString("username"));
    password.setText(store.getString("password"));
}

From source file:org.cs3.pdt.connector.internal.preferences.PreferenceConfiguration.java

License:Open Source License

private PreferenceStore createStore(String configuration) {
    PreferenceStore store = new PreferenceStore(getConfigurationFileName(configuration));
    String defaultConfiguration = getDefaultConfiguration(configuration);
    if (defaultConfiguration.equals(PDTConnector.CONFIGURATION_SWI)) {
        initWithSWIPreferences(store);/*  w  ww . j  a v  a 2  s  . c o m*/
    } else if (defaultConfiguration.equals(PDTConnector.CONFIGURATION_SWI_LOGTALK)) {
        initWithSWILogtalkPreferences(store);
        //      } else if (defaultConfiguration.equals(PDTConnector.CONFIGURATION_YAP)) {
        //         initWithYAPPreferences(store);
        //      } else if (defaultConfiguration.equals(PDTConnector.CONFIGURATION_YAP_LOGTALK)) {
        //         initWithYAPLogtalkPreferences(store);
    } else {
        Debug.error("Invalid default configuration " + defaultConfiguration + " of " + configuration);
    }
    try {
        store.load();
    } catch (IOException e) {
    }
    return store;
}

From source file:org.cs3.prolog.connector.internal.preferences.PreferenceConfiguration.java

License:Open Source License

private PreferenceStore createStore(String configuration) {
    PreferenceStore store = new PreferenceStore(getConfigurationFileName(configuration));
    String defaultConfiguration = getDefaultConfiguration(configuration);
    if (defaultConfiguration.equals(PrologRuntimeUI.CONFIGURATION_SWI)) {
        initWithSWIPreferences(store);//from  ww  w.ja  v a  2 s  .  co m
    } else if (defaultConfiguration.equals(PrologRuntimeUI.CONFIGURATION_SWI_LOGTALK)) {
        initWithSWILogtalkPreferences(store);
    } else if (defaultConfiguration.equals(PrologRuntimeUI.CONFIGURATION_YAP)) {
        initWithYAPPreferences(store);
    } else if (defaultConfiguration.equals(PrologRuntimeUI.CONFIGURATION_YAP_LOGTALK)) {
        initWithYAPLogtalkPreferences(store);
    } else {
        Debug.error("Invalid default configuration " + defaultConfiguration + " of " + configuration);
    }
    try {
        store.load();
    } catch (IOException e) {
    }
    return store;
}

From source file:org.eclipsetrader.ui.internal.application.Activator.java

License:Open Source License

private void migrateSettings() throws Exception {
    IPath workspacePath = Platform.getLocation().append(".metadata").append(".plugins")
            .append("org.eclipse.core.runtime").append(".settings");

    File preferencesFile = workspacePath.append("org.eclipsetrader.ui.prefs").toFile();
    PreferenceStore preferences = new PreferenceStore(preferencesFile.toString());
    if (preferencesFile.exists()) {
        preferences.load();
    }/*from ww w . ja  v a2  s  .c  om*/

    File legacyPreferencesFile = workspacePath.append("org.eclipsetrader.ui.charts.prefs").toFile();
    if (legacyPreferencesFile.exists()) {
        PreferenceStore legacyPreferences = new PreferenceStore(legacyPreferencesFile.toString());
        legacyPreferences.load();
        for (String name : legacyPreferences.preferenceNames()) {
            preferences.putValue(name, legacyPreferences.getString(name));
        }
        legacyPreferencesFile.delete();
    }

    legacyPreferencesFile = workspacePath.append("org.eclipsetrader.ui.trading.prefs").toFile();
    if (legacyPreferencesFile.exists()) {
        PreferenceStore legacyPreferences = new PreferenceStore(legacyPreferencesFile.toString());
        legacyPreferences.load();
        for (String name : legacyPreferences.preferenceNames()) {
            preferences.putValue(name, legacyPreferences.getString(name));
        }
        legacyPreferencesFile.delete();
    }

    legacyPreferencesFile = workspacePath.append("org.eclipsetrader.ui.ats.prefs").toFile();
    if (legacyPreferencesFile.exists()) {
        PreferenceStore legacyPreferences = new PreferenceStore(legacyPreferencesFile.toString());
        legacyPreferences.load();
        for (String name : legacyPreferences.preferenceNames()) {
            preferences.putValue(name, legacyPreferences.getString(name));
        }
        legacyPreferencesFile.delete();
    }

    if (!preferencesFile.exists()) {
        preferencesFile.getParentFile().mkdirs();
    }
    preferences.save();
}