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

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

Introduction

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

Prototype

public String[] preferenceNames() 

Source Link

Document

Returns an enumeration of all preferences known to this store which have current values other than their default value.

Usage

From source file:com.mindquarry.desktop.preferences.pages.ShortcutsPage.java

License:Open Source License

private void loadStoredShortcuts() {
    PreferenceStore store = (PreferenceStore) getPreferenceStore();
    HashMap<Integer, Shortcut> storedProfiles = new HashMap<Integer, Shortcut>();

    // load stored profiles
    String[] prefs = store.preferenceNames();
    for (String pref : prefs) {
        if (pref.startsWith(SHORTCUT_KEY_BASE)) {
            // analyze preference
            int nbr = Integer
                    .valueOf(pref.substring(SHORTCUT_KEY_BASE.length(), SHORTCUT_KEY_BASE.length() + 1));
            String prefName = pref.substring(SHORTCUT_KEY_BASE.length() + 2, pref.length());

            // init profile
            Shortcut shortcut;/*from   www .j ava  2  s . co m*/
            if (storedProfiles.containsKey(nbr)) {
                shortcut = storedProfiles.get(nbr);
            } else {
                shortcut = new Shortcut("", //$NON-NLS-1$
                        "", //$NON-NLS-1$
                        ""); //$NON-NLS-1$
                storedProfiles.put(nbr, shortcut);
            }
            // set shortcut values
            if (prefName.equals("category")) { //$NON-NLS-1$
                shortcut.setCategory(store.getString(pref));
            } else if (prefName.equals("action")) { //$NON-NLS-1$
                shortcut.setAction(store.getString(pref));
            } else if (prefName.equals("shortcut")) { //$NON-NLS-1$
                shortcut.setShortcutIdentifier(store.getString(pref));
            }
        }
    }
    // set profile list
    Iterator<Integer> keyIter = storedProfiles.keySet().iterator();
    while (keyIter.hasNext()) {
        Shortcut shortcut = storedProfiles.get(keyIter.next());
        shortcuts.add(shortcut);
    }
}

From source file:com.mindquarry.desktop.preferences.profile.Profile.java

License:Open Source License

public static List<Profile> loadProfiles(PreferenceStore store) {
    HashMap<Integer, Profile> storedProfiles = new HashMap<Integer, Profile>();

    // load stored profiles
    String[] prefs = store.preferenceNames();
    for (String pref : prefs) {
        if (pref.startsWith(PROFILE_KEY_BASE)) {
            String val = store.getString(pref);
            if (val.trim().equals(EMPTY)) {
                // ignore empty values as PreferenceStore cannot properly
                // delete entries, so we just set deleted entries to the
                // empty string
                continue;
            }//from w w w  . j a  v  a  2 s  .com
            // analyze preference
            int number = Integer
                    .valueOf(pref.substring(PROFILE_KEY_BASE.length(), PROFILE_KEY_BASE.length() + 1));
            String prefName = pref.substring(PROFILE_KEY_BASE.length() + 2, pref.length());

            // initialize profile
            Profile profile;
            if (storedProfiles.containsKey(number)) {
                profile = storedProfiles.get(number);
            } else {
                // TODO: maybe set type here to a non-value?
                profile = new Profile(EMPTY, EMPTY, EMPTY, EMPTY, EMPTY);
                storedProfiles.put(number, profile);
            }
            setProfileAttribute(store, profile, pref, prefName);
        }
    }
    // set profile list
    List<Profile> profiles = new ArrayList<Profile>();
    Iterator<Integer> keyIter = storedProfiles.keySet().iterator();
    while (keyIter.hasNext()) {
        Profile profile = storedProfiles.get(keyIter.next());
        profiles.add(profile);
    }
    return profiles;
}

From source file:com.mindquarry.desktop.preferences.profile.Profile.java

License:Open Source License

public static void storeProfiles(PreferenceStore store, List<Profile> profiles) {
    if (store == null) {
        return;/*from  ww  w  . j ava2 s .c om*/
    }
    // PreferenceStore cannot properly delete entries, so we first "delete"
    // all entries by setting them to the empty string and then set all
    // entries that are left in the following loop (on reading the config,
    // we ignore empty entries):
    int pos = 0;
    for (String storeKey : store.preferenceNames()) {
        if (storeKey.startsWith(Profile.PROFILE_KEY_BASE)) {
            store.putValue(Profile.PROFILE_KEY_BASE + pos + DELIM + Profile.PREF_NAME, EMPTY);
            store.putValue(Profile.PROFILE_KEY_BASE + pos + DELIM + Profile.PREF_TYPE, EMPTY);
            store.putValue(Profile.PROFILE_KEY_BASE + pos + DELIM + Profile.PREF_SVN_REPOS, EMPTY);
            store.putValue(Profile.PROFILE_KEY_BASE + pos + DELIM + Profile.PREF_LOGIN, EMPTY);
            store.putValue(Profile.PROFILE_KEY_BASE + pos + DELIM + Profile.PREF_SERVER_URL, EMPTY);
            store.putValue(Profile.PROFILE_KEY_BASE + pos + DELIM + Profile.PREF_WORKSPACES, EMPTY);
            store.putValue(Profile.PROFILE_KEY_BASE + pos + DELIM + Profile.PREF_PASSWORD, EMPTY);
            pos++;
        }
    }
    // reset counter and store profiles
    pos = 0;
    for (Profile profile : profiles) {
        store.putValue(Profile.PROFILE_KEY_BASE + pos + DELIM + Profile.PREF_NAME, profile.getName());
        store.putValue(Profile.PROFILE_KEY_BASE + pos + DELIM + Profile.PREF_TYPE, profile.getType().name());

        String svnReposValue = "";
        for (SVNRepoData svnRepo : profile.getSvnRepos()) {
            if (svnReposValue.equals("")) {
                svnReposValue += svnRepo.toString();
            } else {
                svnReposValue += ("," + svnRepo.toString());
            }
        }
        store.putValue(Profile.PROFILE_KEY_BASE + pos + DELIM + Profile.PREF_SVN_REPOS, svnReposValue);

        store.putValue(Profile.PROFILE_KEY_BASE + pos + DELIM + Profile.PREF_LOGIN, profile.getLogin());
        store.putValue(Profile.PROFILE_KEY_BASE + pos + DELIM + Profile.PREF_SERVER_URL,
                profile.getServerURL());
        store.putValue(Profile.PROFILE_KEY_BASE + pos + DELIM + Profile.PREF_WORKSPACES,
                profile.getWorkspaceFolder());

        // pseudo-encrypt and store password
        store.putValue(Profile.PROFILE_KEY_BASE + pos + DELIM + Profile.PREF_PASSWORD,
                encodeBase64(profile.getPassword()));

        // store selected teams
        String selectedTeamsValue = "";
        for (String teamID : profile.getSelectedTeams()) {
            if (selectedTeamsValue.equals("")) {
                selectedTeamsValue += teamID;
            } else {
                selectedTeamsValue += ("," + teamID);
            }
        }
        store.putValue(Profile.PROFILE_KEY_BASE + pos + DELIM + Profile.PREF_SELECTED_TEAMS,
                selectedTeamsValue);
        pos++;
    }
}

From source file:com.mindquarry.desktop.preferences.profile.Profile.java

License:Open Source License

private static Profile getSelectedProfile(PreferenceStore store, String namePrefId) {
    Profile profile = null;/* w  ww.  ja va 2  s .c  om*/
    int profileID = -1;

    String[] prefs = store.preferenceNames();

    // try to find ID of the given
    for (String pref : prefs) {
        if (pref.startsWith(PROFILE_KEY_BASE)) {
            // analyze preference
            int id = Integer.valueOf(pref.substring(PROFILE_KEY_BASE.length(), PROFILE_KEY_BASE.length() + 1));
            String prefName = pref.substring(PROFILE_KEY_BASE.length() + 2, pref.length());

            if ((prefName.equals(PREF_NAME)) && (store.getString(pref).equals(namePrefId))) {
                profileID = id;
            }
        }
    }
    if (profileID == -1) {
        return profile;
    }
    for (String pref : prefs) {
        if (pref.startsWith(PROFILE_KEY_BASE)) {
            // analyze preference
            int id = Integer.valueOf(pref.substring(PROFILE_KEY_BASE.length(), PROFILE_KEY_BASE.length() + 1));
            String prefName = pref.substring(PROFILE_KEY_BASE.length() + 2, pref.length());

            // initialize profile if not done already
            if (profile == null) {
                profile = new Profile(EMPTY, EMPTY, EMPTY, EMPTY, EMPTY);
            }

            // set profile values
            if (id == profileID) {
                setProfileAttribute(store, profile, pref, prefName);
            }
        }
    }
    return profile;
}

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

License:Open Source License

/**
 * Log4j configurator//from  w  w w  . j  a  v a 2  s  .  co m
 */
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.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  va2s  .c o m
    }

    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();
}

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 .ja va2  s. com
            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);
        }
    }
}