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

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

Introduction

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

Prototype

void putValue(String name, String value);

Source Link

Document

Sets the current value of the preference with the given name to the given string value without sending a property change.

Usage

From source file:com.google.dart.tools.ui.theme.ColorThemeManager.java

License:Open Source License

/**
 * Adds the color theme to the list and saves it to the preferences. Existing themes will be
 * overwritten with the new content./*from  w w  w  .j  ava  2  s  .c o m*/
 * 
 * @param content The content of the color theme file.
 * @return The saved color theme, or <code>null</code> if the theme was not valid.
 */
public ColorTheme saveTheme(String content) {
    ColorTheme theme;
    try {
        theme = ColorThemeManager.parseTheme(new ByteArrayInputStream(content.getBytes()));
        String name = theme.getName();
        themes.put(name, theme);
        IPreferenceStore store = getPreferenceStore();
        for (int i = 1;; i++) {
            if (!store.contains("importedColorTheme" + i)) { // $NON-NLS-1$
                store.putValue("importedColorTheme" + i, content); // $NON-NLS-1$
                break;
            }
        }
        return theme;
    } catch (Exception e) {
        return null;
    }
}

From source file:com.google.dart.tools.ui.themes.ColorPreferenceTest.java

License:Open Source License

public void testColorPrefs() throws Exception {
    IPreferenceStore store = PreferenceConstants.getPreferenceStore();
    PreferenceConstants.initializeDefaultValues(store);
    openTestEditor("");
    IPreferenceStore prefs = testEditor.getPreferences();
    Display display = testEditor.getViewer().getTextWidget().getDisplay();
    Color ebg = DartUI.getEditorBackground(prefs, display);
    Color efg = DartUI.getEditorForeground(prefs, display);
    Color esbg = DartUI.getEditorSelectionBackground(prefs, display);
    Color esfg = DartUI.getEditorSelectionForeground(prefs, display);
    assertNull(ebg);//from w  ww.  j  a va2s .  c om
    assertNull(efg);
    assertNull(esbg);
    assertNull(esfg);
    // simulate changing theme
    store.putValue("AbstractTextEditor.Color.Foreground.SystemDefault", "false");
    store.putValue("AbstractTextEditor.Color.Background.SystemDefault", "false");
    store.putValue("AbstractTextEditor.Color.SelectionBackground.SystemDefault", "false");
    store.putValue("AbstractTextEditor.Color.SelectionForeground.SystemDefault", "false");
    store.putValue("AbstractTextEditor.Color.Foreground", "0,0,0");
    store.putValue("AbstractTextEditor.Color.Background", "1,1,1");
    store.putValue("AbstractTextEditor.Color.SelectionForeground", "10,10,10");
    store.putValue("AbstractTextEditor.Color.SelectionBackground", "11,11,11");
    ebg = DartUI.getEditorBackground(prefs, display);
    efg = DartUI.getEditorForeground(prefs, display);
    esbg = DartUI.getEditorSelectionBackground(prefs, display);
    esfg = DartUI.getEditorSelectionForeground(prefs, display);
    assertNotNull(ebg);
    assertNotNull(efg);
    assertNotNull(esbg);
    assertNotNull(esfg);
    // simulate restoring defaults
    store.setToDefault("AbstractTextEditor.Color.Foreground.SystemDefault");
    store.setToDefault("AbstractTextEditor.Color.Background.SystemDefault");
    store.setToDefault("AbstractTextEditor.Color.SelectionBackground.SystemDefault");
    store.setToDefault("AbstractTextEditor.Color.SelectionForeground.SystemDefault");
    store.setToDefault("AbstractTextEditor.Color.Foreground");
    store.setToDefault("AbstractTextEditor.Color.Background");
    store.setToDefault("AbstractTextEditor.Color.SelectionForeground");
    store.setToDefault("AbstractTextEditor.Color.SelectionBackground");
    ebg = DartUI.getEditorBackground(prefs, display);
    efg = DartUI.getEditorForeground(prefs, display);
    esbg = DartUI.getEditorSelectionBackground(prefs, display);
    esfg = DartUI.getEditorSelectionForeground(prefs, display);
    assertNull(ebg);
    assertNull(efg);
    assertNull(esbg);
    assertNull(esfg);
}

From source file:com.imperial.fiksen.codesimilarity.compare.ParseTreeMergeViewer.java

License:Open Source License

private void handleEndOfDocumentReached(Shell shell, boolean next) {
    IPreferenceStore store = CompareUIPlugin.getDefault().getPreferenceStore();
    String value = store.getString(ICompareUIConstants.PREF_NAVIGATION_END_ACTION);
    if (!value.equals(ICompareUIConstants.PREF_VALUE_PROMPT)) {
        performEndOfDocumentAction(shell, store, ICompareUIConstants.PREF_NAVIGATION_END_ACTION, next);
    } else {/*  ww w .j  a  v  a  2 s.  c  om*/
        shell.getDisplay().beep();
        String loopMessage;
        String nextMessage;
        String message;
        String title;
        if (next) {
            title = CompareMessages.TextMergeViewer_0;
            message = CompareMessages.TextMergeViewer_1;
            loopMessage = CompareMessages.TextMergeViewer_2;
            nextMessage = CompareMessages.TextMergeViewer_3;
        } else {
            title = CompareMessages.TextMergeViewer_4;
            message = CompareMessages.TextMergeViewer_5;
            loopMessage = CompareMessages.TextMergeViewer_6;
            nextMessage = CompareMessages.TextMergeViewer_7;
        }
        String[] localLoopOption = new String[] { loopMessage, ICompareUIConstants.PREF_VALUE_LOOP };
        String[] nextElementOption = new String[] { nextMessage, ICompareUIConstants.PREF_VALUE_NEXT };
        String[] doNothingOption = new String[] { CompareMessages.TextMergeViewer_17,
                ICompareUIConstants.PREF_VALUE_DO_NOTHING };
        NavigationEndDialog dialog = new NavigationEndDialog(shell, title, null, message,
                new String[][] { localLoopOption, nextElementOption, doNothingOption });
        int result = dialog.open();
        if (result == Window.OK) {
            performEndOfDocumentAction(shell, store, ICompareUIConstants.PREF_NAVIGATION_END_ACTION_LOCAL,
                    next);
            if (dialog.getToggleState()) {
                String oldValue = store.getString(ICompareUIConstants.PREF_NAVIGATION_END_ACTION);
                store.putValue(ICompareUIConstants.PREF_NAVIGATION_END_ACTION,
                        store.getString(ICompareUIConstants.PREF_NAVIGATION_END_ACTION_LOCAL));
                store.firePropertyChangeEvent(ICompareUIConstants.PREF_NAVIGATION_END_ACTION, oldValue,
                        store.getString(ICompareUIConstants.PREF_NAVIGATION_END_ACTION_LOCAL));
            }
        }
    }
}

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

License:Open Source License

@Override
public boolean performOk() {
    IPreferenceStore store = getPreferenceStore();
    int pos = 0;//ww  w .  j  a v  a2  s  .  c  o m

    // set properties from shortcuts
    for (Shortcut shortcut : shortcuts) {
        store.putValue(SHORTCUT_KEY_BASE + pos + ".category", //$NON-NLS-1$
                shortcut.getCategory());
        store.putValue(SHORTCUT_KEY_BASE + pos + ".action", //$NON-NLS-1$
                shortcut.getAction());
        store.putValue(SHORTCUT_KEY_BASE + pos + ".shortcut", //$NON-NLS-1$
                shortcut.getShortcutIdentifier());
        pos++;
    }
    return true;
}

From source file:com.motorolamobility.preflighting.ui.tabs.CheckersTabComposite.java

License:Apache License

@Override
public void performOk(IPreferenceStore preferenceStore) {
    StringBuilder stringBuilder;/*from  www. jav a  2s .c om*/

    /*
     * Checkers information
     */
    Object[] checkerDescriptions = checkersTableViewer.getCheckedElements();

    stringBuilder = new StringBuilder();
    if (checkerDescriptions.length > 0) {
        for (Object checkerDescObj : checkerDescriptions) {
            CheckerDescription checkerDescription = (CheckerDescription) checkerDescObj;
            stringBuilder.append(checkerDescription.getId());
            stringBuilder.append(","); //$NON-NLS-1$
        }
        deleteLastChar(stringBuilder);
        preferenceStore.putValue(PreflightingUIPlugin.CHECKERS_PREFERENCE_KEY, stringBuilder.toString());
    } else {
        preferenceStore.putValue(PreflightingUIPlugin.CHECKERS_PREFERENCE_KEY, NO_CHECKERS_SELECTED);
    }

    stringBuilder = new StringBuilder();
    if (!selectedConditionsMap.isEmpty()) {
        for (String checkerId : selectedConditionsMap.keySet()) {
            stringBuilder.append(checkerId);
            stringBuilder.append(":");
            for (Condition condition : selectedConditionsMap.get(checkerId)) {
                stringBuilder.append(condition.getId());
                stringBuilder.append(","); //$NON-NLS-1$
            }
            deleteLastChar(stringBuilder);
            stringBuilder.append(";");
        }
        deleteLastChar(stringBuilder);
    }
    preferenceStore.setValue(PreflightingUIPlugin.CHECKERS_CONDITIONS_PREFERENCE_KEY, stringBuilder.toString());

    /*
     * Extended Properties
     */
    // Checker parameters
    saveExtendedProperty(checkerParams, preferenceStore, PreflightingUIPlugin.CHECKERS_PARAMS_PREFERENCE_KEY);
    // Custom checker warning levels
    saveExtendedProperty(customCheckersWarningLevels, preferenceStore,
            PreflightingUIPlugin.CHECKERS_WARNING_LEVELS_PREFERENCE_KEY);
    // Custom conditions warning levels
    saveExtendedProperty(customConditionsWarningLevels, preferenceStore,
            PreflightingUIPlugin.CHECKERS_CONDITIONS_WARNING_LEVELS_PREFERENCE_KEY);

}

From source file:com.nextep.designer.dbgm.ui.services.DBGMUIHelper.java

License:Open Source License

private static IConnection doGetConnection(TargetType t) {
    IConnection connection = null;//w  w w  . jav  a 2 s.  c om

    Collection<IConnection> connections = null;
    if (t != null) {
        connections = VCSPlugin.getViewService().getCurrentViewTargets().getTarget(t);
    } else {
        connections = VCSPlugin.getViewService().getCurrentViewTargets().getConnections();
    }
    if (connections.isEmpty()) {
        MessageDialog.openWarning(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
                DBGMUIMessages.getString("noExistingTargetConnectionTitle"), //$NON-NLS-1$
                MessageFormat.format(DBGMUIMessages.getString("noExistingTargetConnection"), //$NON-NLS-1$
                        t == null ? DBGMUIMessages.getString("helper.all") : t.getLabel())); //$NON-NLS-1$
        connection = (IConnection) UIControllerFactory
                .getController(IElementType.getInstance(IConnection.TYPE_ID))
                .newInstance(VCSPlugin.getViewService().getCurrentViewTargets());
        if (connection == null) {
            throw new ErrorException(DBGMUIMessages.getString("helper.connection.noTarget") + t.getLabel()); //$NON-NLS-1$
        }
    } else if (connections.size() == 1) {
        connection = connections.iterator().next();
    } else {
        ConnectionSelector selector = new ConnectionSelector(t);
        final IPreferenceStore store = DbgmUIPlugin.getDefault().getPreferenceStore();
        String lastConnection = store.getString(PREF_LAST_CONNECTION);
        if (lastConnection != null) {
            selector.setDefaultConnection(lastConnection);
        }
        final GUIWrapper w = new GUIWrapper(selector, DBGMUIMessages.getString("chooseConnectionTitle"), 520, //$NON-NLS-1$
                130);
        PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() {

            @Override
            public void run() {
                w.invoke();
            }
        });
        if (!w.isCancelled()) {
            connection = selector.getSelection();
            store.putValue(PREF_LAST_CONNECTION, connection.getName());
        } else {
            throw new CancelException(DBGMUIMessages.getString("helper.cancelled")); //$NON-NLS-1$
        }
    }
    checkConnectionPassword(connection);
    return connection;
}

From source file:com.nextep.designer.synch.ui.services.impl.SynchronizationUIService.java

License:Open Source License

private void saveDataSynchronizationTables(Collection<IVersionable<?>> synchronizedTables) {
    XMLMemento memento = XMLMemento.createWriteRoot(DATASYNC_TABLES_ROOT);
    for (IVersionable<?> synchedTable : synchronizedTables) {
        memento.createChild(DATASYNC_TABLE_REFID, synchedTable.getReference().getUID().toString());
    }/*from  www  .j  a v  a  2 s  .  c  o m*/
    final String prefKey = buildPreferenceKey(PREF_DATASYNC_TABLES_KEY);
    StringWriter writer = new StringWriter();
    try {
        memento.save(writer);
    } catch (IOException e) {
        log.warn("Error occurred while saving synchronized tables: " + e.getMessage(), e);
    }
    IPreferenceStore store = SynchUIPlugin.getDefault().getPreferenceStore();
    store.putValue(prefKey, writer.toString());
    try {
        new InstanceScope().getNode(SynchUIPlugin.PLUGIN_ID).flush();
    } catch (BackingStoreException e) {
        log.warn("Error occurred while saving synchronized tables: " + e.getMessage(), e);
    }
}

From source file:com.nextep.designer.vcs.ui.persistence.TargetSetPersistenceAccessor.java

License:Open Source License

/**
 * Saves the specified target set in the workspace preferences in a secured way. Any previous
 * connection definition for the current view / user will be replaced by the one specified
 * //from   w w  w  .  j  ava 2  s. c  om
 * @param set the {@link ITargetSet} to save
 */
private void saveTargetSet(ITargetSet set) {
    final XMLMemento m = XMLMemento.createWriteRoot("targetSet"); //$NON-NLS-1$
    final Collection<IConnection> connections = set.getConnections();
    for (IConnection c : connections) {
        saveState(c, m);
    }
    StringWriter writer = new StringWriter();
    try {
        m.save(writer);
    } catch (IOException e) {
        throw new ErrorException(VCSUIMessages.getString("helper.connection.saveFail"), e); //$NON-NLS-1$
    }
    IPreferenceStore store = VCSUIPlugin.getDefault().getPreferenceStore();
    store.putValue(getPreferenceKeyForTargetSet(VCSPlugin.getViewService().getCurrentWorkspace()),
            writer.toString());
    try {
        new InstanceScope().getNode(VCSUIPlugin.PLUGIN_ID).flush();
    } catch (BackingStoreException e) {
        throw new ErrorException(e);
    }
}

From source file:com.nokia.carbide.search.system.internal.ui.SearchPreferencePage.java

License:Open Source License

public static String getDefaultPerspectiveId() {
    handleDeletedPerspectives();// www.j a v a  2 s  . co m
    IPreferenceStore store = SearchPlugin.getDefault().getPreferenceStore();
    String id = store.getString(DEFAULT_PERSPECTIVE);
    if (id == null || id.length() == 0 || id.equals(NO_DEFAULT_PERSPECTIVE))
        return null;
    else if (PlatformUI.getWorkbench().getPerspectiveRegistry().findPerspectiveWithId(id) == null) {
        store.putValue(DEFAULT_PERSPECTIVE, id);
        return null;
    }
    return id;
}

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

License:Open Source License

/**
 * Reads the current width of all columns and saves the widths in the preference store.
 * <p>//from w w  w. jav a  2  s .c  o m
 * <b>NOTE</b>: Unfortunately, the architecture of JFace causes this method to be called
 * numerous times, way too many times to my taste. I have not been able to determine when the
 * resizing is finished, so as to call this method only once.
 */
private void persistColumnWidths() {
    //
    // Get all widths into a string.
    String values = ""; // comma-separated list of column widths
    int size;
    Table changeLogTable = viewer.getTable();
    TableColumn[] columns = changeLogTable.getColumns();
    assert columns.length == NUMBER_OF_COLUMNS;
    for (int i = 0; i < columns.length; i++) {
        if (i == 0 && graphColumnHidden) {
            // If the graph column is hidden preserve its last preferred width
            // so it will be the correct width next time it is enabled
            int[] previousPreferredWidths = getColumnWidthsFromPrefsIfEnabled();
            size = previousPreferredWidths == null ? 50 : previousPreferredWidths[0];
        } else {
            size = columns[i].getWidth();
        }

        values += size;
        if (i != (columns.length - 1)) {
            values += ",";
        }
    }
    // Save the string to the preference store.
    IPreferenceStore store = MercurialEclipsePlugin.getDefault().getPreferenceStore();
    store.putValue(PREF_HISTORY_COLUMN_WIDTHS, values);
}