From f9f6cdecd9a44fae8dd7bcd6da8ece53a5ff643a Mon Sep 17 00:00:00 2001 From: Jens Lidestrom Date: Mon, 30 Dec 2019 18:52:16 +0100 Subject: 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 --- .../databinding/swt/typed/WidgetProperties.java | 17 +++-- .../databinding/swt/ControlVisibleProperty.java | 2 +- .../databinding/swt/MenuVisibleProperty.java | 35 ++++++++++ .../databinding/swt/ScrollBarVisibleProperty.java | 35 ++++++++++ .../databinding/swt/ToolBarVisibleProperty.java | 35 ++++++++++ .../databinding/swt/ToolTipVisibleProperty.java | 35 ++++++++++ .../databinding/swt/WidgetVisibleProperty.java | 77 ++++++++++++++++++++++ 7 files changed, 229 insertions(+), 7 deletions(-) create mode 100644 bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/swt/MenuVisibleProperty.java create mode 100644 bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/swt/ScrollBarVisibleProperty.java create mode 100644 bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/swt/ToolBarVisibleProperty.java create mode 100644 bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/swt/ToolTipVisibleProperty.java create mode 100644 bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/swt/WidgetVisibleProperty.java (limited to 'bundles/org.eclipse.jface.databinding/src/org/eclipse/jface') 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 IWidgetValueProperty visible() { - return new ControlVisibleProperty<>(); + public static IWidgetValueProperty 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 { + @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 "; //$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 { + @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 "; //$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 { + @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 "; //$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 { + @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 "; //$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 type of the source object + * + * @since 1.10.0 + */ +public class WidgetVisibleProperty extends WidgetDelegatingValueProperty { + private IValueProperty control; + private IValueProperty menu; + private IValueProperty toolBar; + private IValueProperty scrollBar; + private IValueProperty toolTip; + + /** + * + */ + public WidgetVisibleProperty() { + super(String.class); + } + + @SuppressWarnings("unchecked") + @Override + protected IValueProperty doGetDelegate(S source) { + if (source instanceof Control) { + if (control == null) { + control = (IValueProperty) new ControlVisibleProperty(); + } + return control; + } + if (source instanceof Menu) { + if (menu == null) { + menu = (IValueProperty) new MenuVisibleProperty(); + } + return menu; + } + if (source instanceof ToolBar) { + if (toolBar == null) { + toolBar = (IValueProperty) new ToolBarVisibleProperty(); + } + return toolBar; + } + if (source instanceof ScrollBar) { + if (scrollBar == null) { + scrollBar = (IValueProperty) new ScrollBarVisibleProperty(); + } + return scrollBar; + } + if (source instanceof ToolTip) { + if (toolTip == null) { + toolTip = (IValueProperty) new ToolTipVisibleProperty(); + } + return toolTip; + } + throw notSupported(source); + } +} -- cgit v1.2.3