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

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

Introduction

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

Prototype

boolean isDefault(String name);

Source Link

Document

Returns whether the current value of the preference with the given name has the default value.

Usage

From source file:cz.vutbr.fit.xhriba01.bc.jdt.ui.javaeditor.SemanticHighlightings.java

License:Open Source License

/**
 * If the setting pointed to by <code>oldKey</code> is not the default
 * setting, store that setting under <code>newKey</code> and reset
 * <code>oldKey</code> to its default setting.
 * <p>/*from   w ww  .  j  av  a  2 s .co m*/
 * Returns <code>true</code> if any changes were made.
 * </p>
 *
 * @param store the preference store to read from and write to
 * @param oldKey the old preference key
 * @param newKey the new preference key
 * @return <code>true</code> if <code>store</code> was modified,
 *         <code>false</code> if not
 * @since 3.1
 */
private static boolean conditionalReset(IPreferenceStore store, String oldKey, String newKey) {
    if (!store.isDefault(oldKey)) {
        if (store.isDefault(newKey))
            store.setValue(newKey, store.getString(oldKey));
        store.setToDefault(oldKey);
        return true;
    }
    return false;
}

From source file:cz.vutbr.fit.xhriba01.bc.jdt.ui.javaeditor.SemanticHighlightings.java

License:Open Source License

/**
 * Sets the default value and fires a property
 * change event if necessary./*from   w  w  w.jav  a2s. com*/
 *
 * @param store   the preference store
 * @param key the preference key
 * @param newValue the new value
 * @since 3.3
 */
private static void setDefaultAndFireEvent(IPreferenceStore store, String key, RGB newValue) {
    RGB oldValue = null;
    if (store.isDefault(key))
        oldValue = PreferenceConverter.getDefaultColor(store, key);

    PreferenceConverter.setDefault(store, key, newValue);

    if (oldValue != null && !oldValue.equals(newValue))
        store.firePropertyChangeEvent(key, oldValue, newValue);
}

From source file:de.anbos.eclipse.easyshell.plugin.preferences.Initializer.java

License:Open Source License

private int migrate_check_pref_and_ask_user(IPreferenceStore store, Version version, List<String> prefList,
        int migrateState) {
    // if cancel or no just skip this time
    if (migrateState == 1 || migrateState == 2) {
        return migrateState;
    }//www . j a  v  a2  s.  com
    boolean migrationPossible = false;
    for (String pref : prefList) {
        if (!store.isDefault(pref)) {
            migrationPossible = true;
            break;
        }
    }
    if (migrationPossible) {
        // ask user if not already asked and said yes
        if (migrateState != 0) {
            String title = Activator.getResourceString("easyshell.plugin.name");
            String question = MessageFormat.format(Activator.getResourceString("easyshell.question.migrate"),
                    version.getName());
            MessageDialog dialog = new MessageDialog(null, title, null, question, MessageDialog.QUESTION,
                    new String[] { "Yes", "No", "Cancel" }, 0); // no is the default
            migrateState = dialog.open();
        }
    }
    return migrateState;
}

From source file:de.walware.ecommons.preferences.ui.OverlayPreferenceStore.java

License:Open Source License

private void propagateProperty(final IPreferenceStore orgin, final OverlayStorePreference key,
        final IPreferenceStore target) {

    if (orgin.isDefault(key.fKey)) {
        if (!target.isDefault(key.fKey)) {
            target.setToDefault(key.fKey);
        }//  w  w  w . java  2  s . c  o m
        return;
    }

    final Type type = key.fType;
    switch (type) {

    case BOOLEAN: {
        final boolean originValue = orgin.getBoolean(key.fKey);
        final boolean targetValue = target.getBoolean(key.fKey);
        if (targetValue != originValue) {
            target.setValue(key.fKey, originValue);
        }
        break;
    }

    case DOUBLE: {
        final double originValue = orgin.getDouble(key.fKey);
        final double targetValue = target.getDouble(key.fKey);
        if (targetValue != originValue) {
            target.setValue(key.fKey, originValue);
        }
        break;
    }

    case FLOAT: {
        final float originValue = orgin.getFloat(key.fKey);
        final float targetValue = target.getFloat(key.fKey);
        if (targetValue != originValue) {
            target.setValue(key.fKey, originValue);
        }
        break;
    }

    case INT: {
        final int originValue = orgin.getInt(key.fKey);
        final int targetValue = target.getInt(key.fKey);
        if (targetValue != originValue) {
            target.setValue(key.fKey, originValue);
        }
        break;
    }

    case LONG: {
        final long originValue = orgin.getLong(key.fKey);
        final long targetValue = target.getLong(key.fKey);
        if (targetValue != originValue) {
            target.setValue(key.fKey, originValue);
        }
        break;
    }

    case STRING: {
        final String originValue = orgin.getString(key.fKey);
        final String targetValue = target.getString(key.fKey);
        if (targetValue != null && originValue != null && !targetValue.equals(originValue)) {
            target.setValue(key.fKey, originValue);
        }
        break;
    }
    }
}

From source file:descent.internal.ui.javaeditor.JavaSourceViewer.java

License:Open Source License

/**
 * Creates a color from the information stored in the given preference store.
 * Returns <code>null</code> if there is no such information available.
 *
 * @param store the store to read from/*from   w  w w.  j  a v a2s  .  com*/
 * @param key the key used for the lookup in the preference store
 * @param display the display used create the color
 * @return the created color according to the specification in the preference store
 * @since 3.0
 */
private Color createColor(IPreferenceStore store, String key, Display display) {

    RGB rgb = null;

    if (store.contains(key)) {

        if (store.isDefault(key))
            rgb = PreferenceConverter.getDefaultColor(store, key);
        else
            rgb = PreferenceConverter.getColor(store, key);

        if (rgb != null)
            return new Color(display, rgb);
    }

    return null;
}

From source file:edu.depaul.cdm.madl.tools.ui.PreferenceConstants.java

License:Open Source License

/**
 * Sets the default value and fires a property change event if necessary.
 * //  w ww  .j  a  va  2  s . c  o m
 * @param store the preference store
 * @param key the preference key
 * @param newValue the new value
 */
private static void setDefaultAndFireEvent(IPreferenceStore store, String key, RGB newValue) {
    try {
        RGB oldValue = null;
        if (store.isDefault(key)) {
            oldValue = PreferenceConverter.getDefaultColor(store, key);
        }

        PreferenceConverter.setDefault(store, key, newValue);

        if (oldValue != null && !oldValue.equals(newValue)) {
            store.firePropertyChangeEvent(key, oldValue, newValue);
        }
    } catch (Throwable exception) {
        /*  DartToolsPlugin.log("INFO: Could not get the default value for the color preference named "
              + key, exception);*/
    }
}

From source file:eu.numberfour.n4js.ui.editor.StyledTextDescriptor.java

License:Open Source License

/**
 * Creates and returns with a new {@link StyledText styled text} instance hooked up to the given parent composite.
 *
 * @param parent//from   w  ww .  j a v  a2 s  .  c  om
 *            the parent of the styled text control.
 * @param style
 *            style bits for the new text control.
 * @return a new styled text control initialized from the descriptor.
 */
default StyledText toStyledText(final Composite parent, final int style) {

    final StyledText text = new StyledText(parent, READ_ONLY | style);
    text.setText(getText());
    text.setStyleRanges(getRanges());
    text.setFont(getFont());
    text.setEditable(false);
    text.setEnabled(false);

    final AtomicReference<Color> colorRef = new AtomicReference<>();
    final IPreferenceStore prefStore = EditorsUI.getPreferenceStore();
    if (null == prefStore || prefStore.getBoolean(PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT)) {

        colorRef.set(getDefault().getSystemColor(COLOR_LIST_BACKGROUND));

    } else {

        RGB rgb = null;
        if (prefStore.contains(PREFERENCE_COLOR_BACKGROUND)) {
            if (prefStore.isDefault(PREFERENCE_COLOR_BACKGROUND)) {
                rgb = getDefaultColor(prefStore, PREFERENCE_COLOR_BACKGROUND);
            } else {
                rgb = getColor(prefStore, PREFERENCE_COLOR_BACKGROUND);
            }
            if (rgb != null) {
                colorRef.set(new Color(text.getDisplay(), rgb));
            }
        }

    }

    if (null != colorRef.get()) {
        text.setBackground(colorRef.get());
        text.addDisposeListener(e -> {
            if (!colorRef.get().isDisposed()) {
                colorRef.get().dispose();
            }
        });
    }

    text.pack();
    return text;
}

From source file:ext.org.eclipse.jdt.internal.ui.JavaUIPreferenceInitializer.java

License:Open Source License

/**
 * Sets the default value and fires a property
 * change event if necessary.//from  w ww  .j  a  v a  2s. c om
 *
 * @param store   the preference store
 * @param key the preference key
 * @param newValue the new value
 * @param fireEvent <code>false</code> if no event should be fired
 * @since 3.4
 */
private static void setDefault(IPreferenceStore store, String key, RGB newValue, boolean fireEvent) {
    if (!fireEvent) {
        PreferenceConverter.setDefault(store, key, newValue);
        return;
    }

    RGB oldValue = null;
    if (store.isDefault(key))
        oldValue = PreferenceConverter.getDefaultColor(store, key);

    PreferenceConverter.setDefault(store, key, newValue);

    if (oldValue != null && !oldValue.equals(newValue))
        store.firePropertyChangeEvent(key, oldValue, newValue);
}

From source file:fede.workspace.eclipse.java.fields.JDISourceViewer.java

License:Apache License

/**
* Updates the viewer's font to match the preferences.
*//* ww w.  j  a va 2  s .c  o m*/
private void updateViewerFont() {
    IPreferenceStore store = getPreferenceStore();
    if (store != null) {
        FontData data = null;
        if (store.contains(JFaceResources.TEXT_FONT) && !store.isDefault(JFaceResources.TEXT_FONT)) {
            data = PreferenceConverter.getFontData(store, JFaceResources.TEXT_FONT);
        } else {
            data = PreferenceConverter.getDefaultFontData(store, JFaceResources.TEXT_FONT);
        }
        if (data != null) {
            Font font = new Font(getTextWidget().getDisplay(), data);
            applyFont(font);
            if (getFont() != null) {
                getFont().dispose();
            }
            setFont(font);
            return;
        }
    }
    // if all the preferences failed
    applyFont(JFaceResources.getTextFont());
}

From source file:fede.workspace.eclipse.java.fields.JDISourceViewer.java

License:Apache License

/**
* Creates a color from the information stored in the given preference
* store. Returns <code>null</code> if there is no such information
* available.//from w  w  w . j av  a 2 s.co m
* 
* @param store
*            the store
* @param key
*            the key
* @param display
*            the display
* 
* @return the color
*/
private Color createColor(IPreferenceStore store, String key, Display display) {
    RGB rgb = null;
    if (store.contains(key)) {
        if (store.isDefault(key)) {
            rgb = PreferenceConverter.getDefaultColor(store, key);
        } else {
            rgb = PreferenceConverter.getColor(store, key);
        }
        if (rgb != null) {
            return new Color(display, rgb);
        }
    }
    return null;
}