diff options
author | Jens Lidestrom | 2019-12-30 17:52:16 +0000 |
---|---|---|
committer | Jens Lideström | 2020-01-05 18:57:19 +0000 |
commit | f9f6cdecd9a44fae8dd7bcd6da8ece53a5ff643a (patch) | |
tree | b3f00dbc7bd5bb2d7ce828e877ccae0b5cd31187 /bundles/org.eclipse.jface.databinding/src/org/eclipse/jface | |
parent | fe2068a41074ecd45675d9d9f61ee2814d8afb2a (diff) | |
download | eclipse.platform.ui-f9f6cdecd9a44fae8dd7bcd6da8ece53a5ff643a.tar.gz eclipse.platform.ui-f9f6cdecd9a44fae8dd7bcd6da8ece53a5ff643a.tar.xz eclipse.platform.ui-f9f6cdecd9a44fae8dd7bcd6da8ece53a5ff643a.zip |
Bug 558698 - Add support for Widget visibility
* Add WidgetVisibleProperty delegating property.
* Add property implementation classes for relevant widgets.
* Widen WidgetProperties#visible type parameter to include Widgets. Note:
This is a breaking change with clients do some *really* specific,
unlikely stuff stuff with this method. But since it is so incredibly
unlikely to be a problem in practice only the minor version of
the bundle has been increased in this commit.
Change-Id: I2a2adbdf62ad081e489df77636dace7139db6daa
Signed-off-by: Jens Lidestrom <jens@lidestrom.se>
Diffstat (limited to 'bundles/org.eclipse.jface.databinding/src/org/eclipse/jface')
7 files changed, 229 insertions, 7 deletions
diff --git a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/databinding/swt/typed/WidgetProperties.java b/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/databinding/swt/typed/WidgetProperties.java index 720b830ab0a..2e44c85b99e 100644 --- a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/databinding/swt/typed/WidgetProperties.java +++ b/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/databinding/swt/typed/WidgetProperties.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008, 2015 Matthew Hall and others. + * Copyright (c) 2008, 2020 Matthew Hall and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -31,7 +31,6 @@ import org.eclipse.jface.internal.databinding.swt.ControlFontProperty; import org.eclipse.jface.internal.databinding.swt.ControlForegroundProperty; import org.eclipse.jface.internal.databinding.swt.ControlLocationProperty; import org.eclipse.jface.internal.databinding.swt.ControlSizeProperty; -import org.eclipse.jface.internal.databinding.swt.ControlVisibleProperty; import org.eclipse.jface.internal.databinding.swt.DateTimeSelectionProperty; import org.eclipse.jface.internal.databinding.swt.ListSelectionProperty; import org.eclipse.jface.internal.databinding.swt.MenuItemSelectionProperty; @@ -50,6 +49,7 @@ import org.eclipse.jface.internal.databinding.swt.WidgetSingleSelectionIndexProp import org.eclipse.jface.internal.databinding.swt.WidgetTextProperty; import org.eclipse.jface.internal.databinding.swt.WidgetTextWithEventsProperty; import org.eclipse.jface.internal.databinding.swt.WidgetTooltipTextProperty; +import org.eclipse.jface.internal.databinding.swt.WidgetVisibleProperty; import org.eclipse.swt.SWT; import org.eclipse.swt.custom.CCombo; import org.eclipse.swt.custom.CLabel; @@ -80,6 +80,7 @@ import org.eclipse.swt.widgets.TabItem; import org.eclipse.swt.widgets.Table; import org.eclipse.swt.widgets.TableColumn; import org.eclipse.swt.widgets.Text; +import org.eclipse.swt.widgets.ToolBar; import org.eclipse.swt.widgets.ToolItem; import org.eclipse.swt.widgets.ToolTip; import org.eclipse.swt.widgets.TrayItem; @@ -440,12 +441,16 @@ public class WidgetProperties { /** * Returns a value property for observing the visibility state of a - * {@link Control}. + * {@link Control}, {@link Menu}, {@link ScrollBar}, {@link ToolBar} or + * {@link ToolTip}. + * + * @see Control#getVisible * * @return a value property for observing the visibility state of a - * {@link Control}. + * {@link Control}, {@link Menu}, {@link ScrollBar}, {@link ToolBar} or + * {@link ToolTip}. */ - public static <S extends Control> IWidgetValueProperty<S, Boolean> visible() { - return new ControlVisibleProperty<>(); + public static <S extends Widget> IWidgetValueProperty<S, Boolean> visible() { + return new WidgetVisibleProperty<>(); } } diff --git a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/swt/ControlVisibleProperty.java b/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/swt/ControlVisibleProperty.java index d78451d998d..397dbb501b8 100644 --- a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/swt/ControlVisibleProperty.java +++ b/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/swt/ControlVisibleProperty.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008, 2015 Matthew Hall and others. + * Copyright (c) 2008, 2020 Matthew Hall and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 diff --git a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/swt/MenuVisibleProperty.java b/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/swt/MenuVisibleProperty.java new file mode 100644 index 00000000000..39e6614e018 --- /dev/null +++ b/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/swt/MenuVisibleProperty.java @@ -0,0 +1,35 @@ +/****************************************************************************** + * Copyright (c) 2020 Jens Lidestrom and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + ******************************************************************************/ + +package org.eclipse.jface.internal.databinding.swt; + +import org.eclipse.swt.widgets.Menu; + +/** + * @since 1.10.0 + */ +public class MenuVisibleProperty extends WidgetBooleanValueProperty<Menu> { + @Override + boolean doGetBooleanValue(Menu source) { + return source.getVisible(); + } + + @Override + void doSetBooleanValue(Menu source, boolean value) { + source.setVisible(value); + } + + @Override + public String toString() { + return "Menu.visible <boolean>"; //$NON-NLS-1$ + } +} diff --git a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/swt/ScrollBarVisibleProperty.java b/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/swt/ScrollBarVisibleProperty.java new file mode 100644 index 00000000000..831b2eb435a --- /dev/null +++ b/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/swt/ScrollBarVisibleProperty.java @@ -0,0 +1,35 @@ +/******************************************************************************* + * Copyright (c) 2020 Jens Lidestrom and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + ******************************************************************************/ + +package org.eclipse.jface.internal.databinding.swt; + +import org.eclipse.swt.widgets.ScrollBar; + +/** + * @since 1.10.0 + */ +public class ScrollBarVisibleProperty extends WidgetBooleanValueProperty<ScrollBar> { + @Override + boolean doGetBooleanValue(ScrollBar source) { + return source.getVisible(); + } + + @Override + void doSetBooleanValue(ScrollBar source, boolean value) { + source.setVisible(value); + } + + @Override + public String toString() { + return "ScrollBar.visible <boolean>"; //$NON-NLS-1$ + } +} diff --git a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/swt/ToolBarVisibleProperty.java b/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/swt/ToolBarVisibleProperty.java new file mode 100644 index 00000000000..d70f9b6e7f3 --- /dev/null +++ b/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/swt/ToolBarVisibleProperty.java @@ -0,0 +1,35 @@ +/******************************************************************************* + * Copyright (c) 2020 Jens Lidestrom and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + ******************************************************************************/ + +package org.eclipse.jface.internal.databinding.swt; + +import org.eclipse.swt.widgets.ToolBar; + +/** + * @since 1.10.0 + */ +public class ToolBarVisibleProperty extends WidgetBooleanValueProperty<ToolBar> { + @Override + boolean doGetBooleanValue(ToolBar source) { + return source.getVisible(); + } + + @Override + void doSetBooleanValue(ToolBar source, boolean value) { + source.setVisible(value); + } + + @Override + public String toString() { + return "ToolBar.visible <boolean>"; //$NON-NLS-1$ + } +} diff --git a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/swt/ToolTipVisibleProperty.java b/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/swt/ToolTipVisibleProperty.java new file mode 100644 index 00000000000..f1aee480479 --- /dev/null +++ b/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/swt/ToolTipVisibleProperty.java @@ -0,0 +1,35 @@ +/******************************************************************************* + * Copyright (c) 2020 Jens Lidestrom and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + ******************************************************************************/ + +package org.eclipse.jface.internal.databinding.swt; + +import org.eclipse.swt.widgets.ToolTip; + +/** + * @since 1.10.0 + */ +public class ToolTipVisibleProperty extends WidgetBooleanValueProperty<ToolTip> { + @Override + boolean doGetBooleanValue(ToolTip source) { + return source.getVisible(); + } + + @Override + void doSetBooleanValue(ToolTip source, boolean value) { + source.setVisible(value); + } + + @Override + public String toString() { + return "ToolTip.visible <boolean>"; //$NON-NLS-1$ + } +} diff --git a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/swt/WidgetVisibleProperty.java b/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/swt/WidgetVisibleProperty.java new file mode 100644 index 00000000000..9d4bd0dddf8 --- /dev/null +++ b/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/swt/WidgetVisibleProperty.java @@ -0,0 +1,77 @@ +/****************************************************************************** + * Copyright (c) 2020 Jens Lidestrom and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + ******************************************************************************/ + +package org.eclipse.jface.internal.databinding.swt; + +import org.eclipse.core.databinding.property.value.IValueProperty; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Menu; +import org.eclipse.swt.widgets.ScrollBar; +import org.eclipse.swt.widgets.ToolBar; +import org.eclipse.swt.widgets.ToolTip; +import org.eclipse.swt.widgets.Widget; + +/** + * @param <S> type of the source object + * + * @since 1.10.0 + */ +public class WidgetVisibleProperty<S extends Widget> extends WidgetDelegatingValueProperty<S, Boolean> { + private IValueProperty<S, Boolean> control; + private IValueProperty<S, Boolean> menu; + private IValueProperty<S, Boolean> toolBar; + private IValueProperty<S, Boolean> scrollBar; + private IValueProperty<S, Boolean> toolTip; + + /** + * + */ + public WidgetVisibleProperty() { + super(String.class); + } + + @SuppressWarnings("unchecked") + @Override + protected IValueProperty<S, Boolean> doGetDelegate(S source) { + if (source instanceof Control) { + if (control == null) { + control = (IValueProperty<S, Boolean>) new ControlVisibleProperty<Control>(); + } + return control; + } + if (source instanceof Menu) { + if (menu == null) { + menu = (IValueProperty<S, Boolean>) new MenuVisibleProperty(); + } + return menu; + } + if (source instanceof ToolBar) { + if (toolBar == null) { + toolBar = (IValueProperty<S, Boolean>) new ToolBarVisibleProperty(); + } + return toolBar; + } + if (source instanceof ScrollBar) { + if (scrollBar == null) { + scrollBar = (IValueProperty<S, Boolean>) new ScrollBarVisibleProperty(); + } + return scrollBar; + } + if (source instanceof ToolTip) { + if (toolTip == null) { + toolTip = (IValueProperty<S, Boolean>) new ToolTipVisibleProperty(); + } + return toolTip; + } + throw notSupported(source); + } +} |