Example usage for org.eclipse.jface.preference IPreferenceStore getString

List of usage examples for org.eclipse.jface.preference IPreferenceStore getString

Introduction

In this page you can find the example usage for org.eclipse.jface.preference IPreferenceStore getString.

Prototype

String getString(String name);

Source Link

Document

Returns the current value of the string-valued preference with the given name.

Usage

From source file:com.twinsoft.convertigo.eclipse.ConvertigoPlugin.java

License:Open Source License

static public String getLocalBuildAdditionalPath() {
    IPreferenceStore preferenceStore = ConvertigoPlugin.getDefault().getPreferenceStore();
    return preferenceStore.getString(ConvertigoPlugin.PREFERENCE_LOCAL_BUILD_ADDITIONAL_PATH);
}

From source file:com.vectrace.MercurialEclipse.history.MercurialHistoryPage.java

License:Open Source License

/**
 * @return an array of length NUMBER_OF_COLUMNS containing the user's preferred
 * column widths or null if they have not been set or if the column width persistence
 * pref (PREF_HISTORY_COLUMN_PERSISTENCE) is not enabled.
 *///from www . j a v  a  2  s.  c  om
private static int[] getColumnWidthsFromPrefsIfEnabled() {
    IPreferenceStore store = MercurialEclipsePlugin.getDefault().getPreferenceStore();

    if (store.getBoolean(PREF_HISTORY_COLUMN_PERSISTENCE) == false) {
        // Column width persistence pref is disabled
        return null;
    }

    String rawWidths = store.getString(PREF_HISTORY_COLUMN_WIDTHS);

    if (rawWidths == null || rawWidths.trim().length() == 0) {
        // No preferred widths have been recorded yet
        return null;
    }

    String[] rawWidthsSplit = rawWidths.split(",");
    int[] parsedWidths = new int[NUMBER_OF_COLUMNS];

    int colIdx = 0;
    while (colIdx < Math.min(rawWidthsSplit.length, NUMBER_OF_COLUMNS)) {
        parsedWidths[colIdx] = Integer.valueOf(rawWidthsSplit[colIdx]);
        colIdx++;
    }

    // This accounts for possible changes in the number of columns.
    if (colIdx < NUMBER_OF_COLUMNS) {
        // The number of columns has been increased. We set default widths and let the
        // user resize as they like.
        for (; colIdx < NUMBER_OF_COLUMNS; colIdx++) {
            parsedWidths[colIdx] = 50;
        }
    } else {
        // Nothing to do: either the number is unchanged or it is lower. We're covered
        // in both cases, meaning that the appropriate number of column data is created.
    }

    return parsedWidths;
}

From source file:com.vectrace.MercurialEclipse.MercurialEclipsePlugin.java

License:Open Source License

/**
 * Show a dialog only if the user hasn't selected "don't show again" for it.
 *
 * @param title The title/*  w w w .j a v  a2 s  . co m*/
 * @param message The message
 * @param type The type, for example MessageDialog.CONFIRM
 * @param key The preference key
 * @param shell The shell to use
 * @return True of ok was pressed
 */
public static boolean showDontShowAgainConfirmDialog(final String title, final String message, int type,
        String key, Shell shell) {
    IPreferenceStore store = getDefault().getPreferenceStore();
    String pref = store.getString(key);
    if (MessageDialogWithToggle.PROMPT.equals(pref)) {
        String toggleMessage = Messages.getString("Dialogs.DontShowAgain");
        MessageDialogWithToggle confirmDialog = MessageDialogWithToggle.open(type, shell, title, message,
                toggleMessage, false, store, key, SWT.NONE);
        int returnCode = confirmDialog.getReturnCode();
        return returnCode == Window.OK;
    }
    return true;
}

From source file:com.vectrace.MercurialEclipse.preferences.PreferenceInitializer.java

License:Open Source License

private static void detectAndSetHgExecutable(IPreferenceStore store) {
    // Currently only tested on Windows. The binary is expected to be found
    // at "os\win32\x86\hg.exe" (relative to the plugin/fragment directory)
    File hgExecutable = getIntegratedHgExecutable();
    String defaultExecPath;/* w  ww . ja  v a2s  .  c  o m*/
    String existingValue = store.getString(MERCURIAL_EXECUTABLE);

    // Use built in if possible
    if (store.getBoolean(USE_BUILT_IN_HG_EXECUTABLE) && hgExecutable != null) {
        defaultExecPath = hgExecutable.getPath();
        store.setValue(MERCURIAL_EXECUTABLE, defaultExecPath);
        store.setDefault(MERCURIAL_EXECUTABLE, defaultExecPath);
        return;
    }

    // Future: Should we ignore the integrated executable if the pref is disabled?
    if (hgExecutable == null) {
        hgExecutable = checkForPossibleHgExecutables();
    }
    if (hgExecutable == null) {
        defaultExecPath = "hg";
    } else {
        defaultExecPath = hgExecutable.getPath();
    }

    if (existingValue != null && !new File(existingValue).isFile()) {
        // If already set override if it's invalid
        store.setValue(MERCURIAL_EXECUTABLE, defaultExecPath);
    }
    store.setDefault(MERCURIAL_EXECUTABLE, defaultExecPath);
}

From source file:com.vectrace.MercurialEclipse.repository.RepoPropertiesPage.java

License:Open Source License

protected void internalSave() {
    if (adaptable == null) {
        return;//  w  w w  . j a  v a  2s  . c om
    }
    IHgRepositoryLocation adapter = (IHgRepositoryLocation) adaptable.getAdapter(IHgRepositoryLocation.class);
    if (!(adapter instanceof HgRepositoryLocation)) {
        return;
    }
    HgRepositoryLocation repo = (HgRepositoryLocation) adapter;
    IPreferenceStore store = getPreferenceStore();
    String user = store.getString(KEY_LOGIN_NAME);
    String pwd = store.getString(KEY_LOGIN_PWD);
    String lname = store.getString(KEY_LNAME);
    try {
        adaptable = MercurialEclipsePlugin.getRepoManager().updateRepoLocation(null, repo.getLocation(), lname,
                user, pwd);
    } catch (HgException e) {
        MercurialEclipsePlugin.logError(e);
    }
    // as selection is not updated in the view, simply copy new data to the old one
    repo.setUser(user);
    repo.setPassword(pwd);
    repo.setLogicalName(lname);
}

From source file:com.vectrace.MercurialEclipse.storage.HgCommitMessageManager.java

License:Open Source License

/**
 * Get the commit name for given root/*w  ww .  j  a v a 2s.c  om*/
 *
 * @param hgRoot
 *            non null
 * @return never null, but might be empty
 */
public static String getDefaultCommitName(HgRoot hgRoot) {
    // first the stored commit name
    IPreferenceStore store = MercurialEclipsePlugin.getDefault().getPreferenceStore();
    String commitName = store.getString(getKey(hgRoot));
    if (!StringUtils.isEmpty(commitName)) {
        return commitName;
    }

    String defaultUserName = hgRoot.getUser();
    if (StringUtils.isEmpty(defaultUserName)) {
        defaultUserName = MercurialUtilities.getDefaultUserName();
    }

    /*
     * dependent on the preference, use configured Mercurial name or repository
     * username (in some corporate environments this seems to be necessary)
     */
    if ("true".equals(MercurialUtilities.getPreference(MercurialPreferenceConstants.PREF_USE_MERCURIAL_USERNAME,
            "true"))) {
        return defaultUserName;
    }

    IHgRepositoryLocation repoLocation = MercurialEclipsePlugin.getRepoManager().getDefaultRepoLocation(hgRoot);
    if (repoLocation != null) {
        String user = repoLocation.getUser();
        if (!StringUtils.isEmpty(user)) {
            return user;
        }
    }
    return defaultUserName;
}

From source file:com.vectrace.MercurialEclipse.storage.HgRepositoryLocationManager.java

License:Open Source License

private Set<IHgRepositoryLocation> loadRepositories(String key) {
    Set<IHgRepositoryLocation> locations = new LinkedHashSet<IHgRepositoryLocation>();
    IPreferenceStore store = MercurialEclipsePlugin.getDefault().getPreferenceStore();
    String allReposLine = store.getString(key);
    if (StringUtils.isEmpty(allReposLine)) {
        return locations;
    }//from  w ww  . j  a  va  2 s.co m
    String[] repoLine = allReposLine.split("\\|");
    for (String line : repoLine) {
        if (line == null || line.length() == 0) {
            continue;
        }
        try {
            IHgRepositoryLocation loc = delegator.delegateParse(line);
            if (loc != null) {
                locations.add(loc);
            }
        } catch (Exception e) {
            // log exception, but don't bother the user with it.
            MercurialEclipsePlugin.logError(e);
        }
    }
    return locations;
}

From source file:com.vectrace.MercurialEclipse.storage.HgRepositoryLocationManager.java

License:Open Source License

/**
 * Returns the default repository location for a hg root, if it is set.
 * @return may return null//  w w w  .j a  v  a 2  s. com
 */
public IHgRepositoryLocation getDefaultRepoLocation(HgRoot hgRoot) {
    IPreferenceStore store = MercurialEclipsePlugin.getDefault().getPreferenceStore();
    String defLoc = store.getString(KEY_DEF_REPO_PREFIX + getRootKey(hgRoot));
    if (StringUtils.isEmpty(defLoc)) {
        // We have no preference set for this root. We'll try the hgrc file.
        defLoc = hgRoot.getDefaultPath();

        if (StringUtils.isEmpty(defLoc)) {
            return null;
        }
    }
    Set<IHgRepositoryLocation> locations = rootRepos.get(hgRoot);
    if (locations != null && !locations.isEmpty()) {
        synchronized (entriesLock) {
            for (IHgRepositoryLocation repo : locations) {
                if (repo.getLocation().equals(defLoc)) {
                    return repo;
                }
            }
        }
    }
    for (IHgRepositoryLocation repo : repoHistory) {
        if (repo.getLocation().equals(defLoc)) {
            internalAddRepoLocation(hgRoot, repo);
            return repo;
        }
    }
    return null;
}

From source file:com.vectrace.MercurialEclipse.synchronize.cs.UncommittedChangesetManager.java

License:Open Source License

/**
 * Builds the set of changesets from what was saved to the preference file.
 *
 * @param sets/* w w  w . ja va 2 s.c  o m*/
 *            (I/O) The set of changesets
 */
private void loadfromPreferences(Set<GroupedUncommittedChangeSet> sets) {
    loadingFromPrefs = true;
    try {
        IPreferenceStore store = MercurialEclipsePlugin.getDefault().getPreferenceStore();
        // Get the list of *active* changesets. There are also relics in the file.
        String changesets = store.getString(KEY_CS_LIST);

        // Get the name of the default cset
        String defName = store.getString(KEY_CS_DEFAULT);

        // Rebuild the csets so as to have them available in "sets"
        if (!StringUtils.isEmpty(changesets)) {
            String[] uniqueNames = changesets.split(MAPPINGS_SEPARATOR);
            for (String uniqueName : uniqueNames) {
                if (!StringUtils.isEmpty(uniqueName)) {
                    String[] parts = uniqueName.split(CHANGESET_NAME_SEPARATOR);
                    String name = decodeChangesetName(parts[0]);
                    GroupedUncommittedChangeSet changeset = new GroupedUncommittedChangeSet(name, group);
                    if (parts.length > 1) {
                        // We've got a unique ID from the prefs file.
                        changeset.setUniqueId(parts[1]);
                    }
                    sets.add(changeset);
                }
            }
        }
        for (GroupedUncommittedChangeSet changeSet : sets) {
            // Set the comment of each changeset that was read from the prefs. An important
            // corollary of this is that changesets saved to the prefs should have unique names:
            // csets will otherwise be confused and assignments of files to csets will be wrong.
            String comment = store.getString(KEY_CS_COMMENT_PREFIX + buildChangesetUniqueName(changeSet));
            if ("".equals(comment)) {
                // This accounts for legacy changeset names (which have no unique ID).
                comment = store.getString(KEY_CS_COMMENT_PREFIX + changeSet.getName());
            }
            changeSet.setComment(comment);

            // Identify the default set
            if (buildChangesetUniqueName(changeSet).equals(defName) || changeSet.getName().equals(defName)) {
                makeDefault(changeSet);
            }
        }
        if (projects == null) {
            return;
        }
        //
        // Assign each file of each project available in the workspace to the appropriate cset
        for (IProject project : projects) {
            String filesStr = store.getString(KEY_FILES_PER_PROJECT_PREFIX + project.getName());
            if (StringUtils.isEmpty(filesStr)) {
                continue;
            }
            Map<IFile, String> fileToChangeset = decode(filesStr, project);
            Set<Entry<IFile, String>> entrySet = fileToChangeset.entrySet();
            for (Entry<IFile, String> entry : entrySet) {
                String name = entry.getValue();
                GroupedUncommittedChangeSet changeset = getChangeset(name, sets);
                if (changeset == null) {
                    continue;
                    //               changeset = new WorkingChangeSet(name, group);
                    //               sets.add(changeset);
                }
                changeset.add(entry.getKey());
            }
        }
    } finally {
        loadingFromPrefs = false;
    }
}