Java Code Examples for org.eclipse.jface.preference.IPreferenceStore#isDefault()

The following examples show how to use org.eclipse.jface.preference.IPreferenceStore#isDefault() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JavaSourceViewer.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * 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
 * @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;
}
 
Example 2
Source File: JavaUIPreferenceInitializer.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Sets the default value and fires a property
 * change event if necessary.
 *
 * @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);
}
 
Example 3
Source File: EditorConfigUIPreferenceInitializer.java    From editorconfig-eclipse with Apache License 2.0 6 votes vote down vote up
/**
 * Sets the default value and fires a property change event if necessary.
 *
 * @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
 */
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);
	}
}
 
Example 4
Source File: ExpressionBuilder.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Creates a color from the information stored in the given preference
 * store. Returns <code>null</code> if there is no such information
 * available.
 */
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;
}
 
Example 5
Source File: UIUtil.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
public static 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;
}
 
Example 6
Source File: AbstractSyntaxColoringPage.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * 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
 * @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 2.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;
}
 
Example 7
Source File: PythonSourceViewer.java    From Pydev with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Updates the viewer's font to match the preferences.
 */
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());
}
 
Example 8
Source File: ViewerColorUpdater.java    From goclipse with Eclipse Public License 1.0 6 votes vote down vote up
protected 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;
}
 
Example 9
Source File: SemanticHighlightings.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Sets the default value and fires a property
 * change event if necessary.
 *
 * @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);
}
 
Example 10
Source File: PythonSourceViewer.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Creates a color from the information stored in the given preference store. Returns <code>null</code> if there is no such information available.
 */
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;
}
 
Example 11
Source File: StyledTextDescriptor.java    From n4js with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Creates and returns with a new {@link StyledText styled text} instance hooked up to the given parent composite.
 *
 * @param parent
 *            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;
}
 
Example 12
Source File: TLCChainedPreferenceStore.java    From tlaplus with MIT License 4 votes vote down vote up
public boolean isDefault(String name) {
	IPreferenceStore visibleStore= getVisibleStore(name);
	if (visibleStore != null)
		return visibleStore.isDefault(name);
	return false;
}
 
Example 13
Source File: PreferenceConstants.java    From typescript.java with MIT License 3 votes vote down vote up
/**
 * Sets the default value and fires a property change event if necessary.
 * 
 * @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) {
	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);
}
 
Example 14
Source File: SemanticHighlightings.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 3 votes vote down vote up
/**
 * 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>
 * 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;
}