diff options
author | Matthew Hall | 2010-08-18 06:00:56 +0000 |
---|---|---|
committer | Matthew Hall | 2010-08-18 06:00:56 +0000 |
commit | e0d4eb21d6f8d5eed901d2fdf26fd8bf573e0f1a (patch) | |
tree | 3a210bca9b0578cf9e4f322cde9d14aa5e5bb562 | |
parent | 234f1ee896df179dca09b613f1f8c5ff9ad58815 (diff) | |
download | org.eclipse.e4.databinding-e0d4eb21d6f8d5eed901d2fdf26fd8bf573e0f1a.tar.gz org.eclipse.e4.databinding-e0d4eb21d6f8d5eed901d2fdf26fd8bf573e0f1a.tar.xz org.eclipse.e4.databinding-e0d4eb21d6f8d5eed901d2fdf26fd8bf573e0f1a.zip |
FIXED - bug 280157: [DataBinding] MenuItem enabled is missing
https://bugs.eclipse.org/bugs/show_bug.cgi?id=280157
12 files changed, 486 insertions, 155 deletions
diff --git a/bundles/org.eclipse.jface.databinding/META-INF/MANIFEST.MF b/bundles/org.eclipse.jface.databinding/META-INF/MANIFEST.MF index f9e15077..274f3aae 100644 --- a/bundles/org.eclipse.jface.databinding/META-INF/MANIFEST.MF +++ b/bundles/org.eclipse.jface.databinding/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: %pluginName Bundle-SymbolicName: org.eclipse.jface.databinding -Bundle-Version: 1.4.0.qualifier +Bundle-Version: 1.5.0.qualifier Bundle-ClassPath: . Bundle-Vendor: %providerName Bundle-Localization: plugin diff --git a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/databinding/swt/SWTObservables.java b/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/databinding/swt/SWTObservables.java index 32615369..1d7b53fa 100644 --- a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/databinding/swt/SWTObservables.java +++ b/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/databinding/swt/SWTObservables.java @@ -94,8 +94,29 @@ public class SWTObservables { */ public static ISWTObservableValue observeDelayedValue(int delay, ISWTObservableValue observable) { - return new SWTDelayedObservableValueDecorator(Observables - .observeDelayedValue(delay, observable), observable.getWidget()); + return new SWTDelayedObservableValueDecorator( + Observables.observeDelayedValue(delay, observable), + observable.getWidget()); + } + + /** + * Returns an observable value tracking the enabled state of the given + * widget. The supported types are: + * <ul> + * <li>org.eclipse.swt.widgets.Control</li> + * <li>org.eclipse.swt.widgets.Menu</li> + * <li>org.eclipse.swt.widgets.MenuItem</li> + * <li>org.eclipse.swt.widgets.ScrollBar</li> + * <li>org.eclipse.swt.widgets.ToolItem</li> + * </ul> + * + * @param widget + * @return an observable value tracking the enabled state of the given + * widget. + * @since 1.5 + */ + public static ISWTObservableValue observeEnabled(Widget widget) { + return WidgetProperties.enabled().observe(widget); } /** @@ -108,7 +129,7 @@ public class SWTObservables { * control */ public static ISWTObservableValue observeEnabled(Control control) { - return WidgetProperties.enabled().observe(control); + return observeEnabled((Widget) control); } /** @@ -168,6 +189,29 @@ public class SWTObservables { * <li>org.eclipse.swt.widgets.Combo</li> * <li>org.eclipse.swt.custom.CCombo</li> * <li>org.eclipse.swt.widgets.List</li> + * <li>org.eclipse.swt.widgets.MenuItem (since 1.5)</li> + * <li>org.eclipse.swt.widgets.Scale</li> + * </ul> + * + * @param widget + * @return observable value + * @throws IllegalArgumentException + * if <code>control</code> type is unsupported + * @since 1.5 + */ + public static ISWTObservableValue observeSelection(Widget widget) { + return WidgetProperties.selection().observe(widget); + } + + /** + * Returns an observable observing the selection attribute of the provided + * <code>control</code>. The supported types are: + * <ul> + * <li>org.eclipse.swt.widgets.Spinner</li> + * <li>org.eclipse.swt.widgets.Button</li> + * <li>org.eclipse.swt.widgets.Combo</li> + * <li>org.eclipse.swt.custom.CCombo</li> + * <li>org.eclipse.swt.widgets.List</li> * <li>org.eclipse.swt.widgets.Scale</li> * </ul> * @@ -177,7 +221,7 @@ public class SWTObservables { * if <code>control</code> type is unsupported */ public static ISWTObservableValue observeSelection(Control control) { - return WidgetProperties.selection().observe(control); + return observeSelection((Widget) control); } /** diff --git a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/databinding/swt/WidgetProperties.java b/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/databinding/swt/WidgetProperties.java index 67f60cd4..31ab6e02 100644 --- a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/databinding/swt/WidgetProperties.java +++ b/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/databinding/swt/WidgetProperties.java @@ -15,7 +15,6 @@ package org.eclipse.jface.databinding.swt; import org.eclipse.jface.internal.databinding.swt.ControlBackgroundProperty; import org.eclipse.jface.internal.databinding.swt.ControlBoundsProperty; -import org.eclipse.jface.internal.databinding.swt.ControlEnabledProperty; import org.eclipse.jface.internal.databinding.swt.ControlFocusedProperty; import org.eclipse.jface.internal.databinding.swt.ControlFontProperty; import org.eclipse.jface.internal.databinding.swt.ControlForegroundProperty; @@ -23,6 +22,7 @@ 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.WidgetEditableProperty; +import org.eclipse.jface.internal.databinding.swt.WidgetEnabledProperty; import org.eclipse.jface.internal.databinding.swt.WidgetImageProperty; import org.eclipse.jface.internal.databinding.swt.WidgetItemsProperty; import org.eclipse.jface.internal.databinding.swt.WidgetMaximumProperty; @@ -46,7 +46,10 @@ import org.eclipse.swt.widgets.Item; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Link; import org.eclipse.swt.widgets.List; +import org.eclipse.swt.widgets.Menu; +import org.eclipse.swt.widgets.MenuItem; import org.eclipse.swt.widgets.Scale; +import org.eclipse.swt.widgets.ScrollBar; import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Spinner; import org.eclipse.swt.widgets.TabItem; @@ -98,13 +101,15 @@ public class WidgetProperties { /** * Returns a value property for observing the enablement state of a - * {@link Control}. + * {@link Control}, {@link Menu} (since 1.5), {@link MenuItem} (since 1.5), + * {@link ScrollBar} (since 1.5) or {@link ToolItem} (since 1.5). * * @return a value property for observing the enablement state of a - * {@link Control}. + * {@link Control}, {@link Menu}, {@link MenuItem}, + * {@link ScrollBar} or {@link ToolItem}. */ public static IWidgetValueProperty enabled() { - return new ControlEnabledProperty(); + return new WidgetEnabledProperty(); } /** @@ -205,11 +210,12 @@ public class WidgetProperties { /** * Returns a value property for observing the selection state of a * {@link Button}, {@link CCombo}, {@link Combo}, {@link DateTime}, - * {@link List}, {@link Scale} or {@link Spinner}. + * {@link List}, {@link MenuItem} (since 1.5), {@link Scale} or + * {@link Spinner}. * * @return a value property for observing the selection state of a * {@link Button}, {@link CCombo}, {@link Combo}, {@link DateTime}, - * {@link List}, {@link Scale} or {@link Spinner}. + * {@link List}, {@link MenuItem}, {@link Scale} or {@link Spinner}. */ public static IWidgetValueProperty selection() { return new WidgetSelectionProperty(); diff --git a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/swt/MenuEnabledProperty.java b/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/swt/MenuEnabledProperty.java new file mode 100644 index 00000000..05e3c251 --- /dev/null +++ b/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/swt/MenuEnabledProperty.java @@ -0,0 +1,31 @@ +/******************************************************************************* + * Copyright (c) 2009 Matthew Hall and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Matthew Hall - initial API and implementation (bug 280157) + ******************************************************************************/ + +package org.eclipse.jface.internal.databinding.swt; + +import org.eclipse.swt.widgets.Menu; + +/** + * + */ +public class MenuEnabledProperty extends WidgetBooleanValueProperty { + public boolean doGetBooleanValue(Object source) { + return ((Menu) source).getEnabled(); + } + + void doSetBooleanValue(Object source, boolean value) { + ((Menu) source).setEnabled(value); + } + + public String toString() { + return "Menu.enabled <boolean>"; //$NON-NLS-1$ + } +} diff --git a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/swt/MenuItemEnabledProperty.java b/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/swt/MenuItemEnabledProperty.java new file mode 100644 index 00000000..9340e00c --- /dev/null +++ b/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/swt/MenuItemEnabledProperty.java @@ -0,0 +1,31 @@ +/******************************************************************************* + * Copyright (c) 2009 Matthew Hall and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Matthew Hall - initial API and implementation (bug 280157) + ******************************************************************************/ + +package org.eclipse.jface.internal.databinding.swt; + +import org.eclipse.swt.widgets.MenuItem; + +/** + * + */ +public class MenuItemEnabledProperty extends WidgetBooleanValueProperty { + public boolean doGetBooleanValue(Object source) { + return ((MenuItem) source).getEnabled(); + } + + void doSetBooleanValue(Object source, boolean value) { + ((MenuItem) source).setEnabled(value); + } + + public String toString() { + return "MenuItem.enabled <boolean>"; //$NON-NLS-1$ + } +} diff --git a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/swt/MenuItemSelectionProperty.java b/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/swt/MenuItemSelectionProperty.java new file mode 100644 index 00000000..ae3182dd --- /dev/null +++ b/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/swt/MenuItemSelectionProperty.java @@ -0,0 +1,39 @@ +/******************************************************************************* + * Copyright (c) 2008, 2009 Matthew Hall and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Matthew Hall - initial API and implementation (bug 194734) + ******************************************************************************/ + +package org.eclipse.jface.internal.databinding.swt; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.MenuItem; + +/** + * + */ +public class MenuItemSelectionProperty extends WidgetBooleanValueProperty { + /** + * + */ + public MenuItemSelectionProperty() { + super(SWT.Selection); + } + + boolean doGetBooleanValue(Object source) { + return ((MenuItem) source).getSelection(); + } + + void doSetBooleanValue(Object source, boolean value) { + ((MenuItem) source).setSelection(value); + } + + public String toString() { + return "MenuItem.selection <Boolean>"; //$NON-NLS-1$ + } +} diff --git a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/swt/ScrollBarEnabledProperty.java b/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/swt/ScrollBarEnabledProperty.java new file mode 100644 index 00000000..241c5c92 --- /dev/null +++ b/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/swt/ScrollBarEnabledProperty.java @@ -0,0 +1,31 @@ +/******************************************************************************* + * Copyright (c) 2009 Matthew Hall and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Matthew Hall - initial API and implementation (bug 280157) + ******************************************************************************/ + +package org.eclipse.jface.internal.databinding.swt; + +import org.eclipse.swt.widgets.ScrollBar; + +/** + * + */ +public class ScrollBarEnabledProperty extends WidgetBooleanValueProperty { + public boolean doGetBooleanValue(Object source) { + return ((ScrollBar) source).getEnabled(); + } + + void doSetBooleanValue(Object source, boolean value) { + ((ScrollBar) source).setEnabled(value); + } + + public String toString() { + return "ScrollBar.enabled <boolean>"; //$NON-NLS-1$ + } +} diff --git a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/swt/ToolItemEnabledProperty.java b/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/swt/ToolItemEnabledProperty.java new file mode 100644 index 00000000..9a38502a --- /dev/null +++ b/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/swt/ToolItemEnabledProperty.java @@ -0,0 +1,31 @@ +/******************************************************************************* + * Copyright (c) 2009 Matthew Hall and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Matthew Hall - initial API and implementation (bug 280157) + ******************************************************************************/ + +package org.eclipse.jface.internal.databinding.swt; + +import org.eclipse.swt.widgets.ToolItem; + +/** + * + */ +public class ToolItemEnabledProperty extends WidgetBooleanValueProperty { + public boolean doGetBooleanValue(Object source) { + return ((ToolItem) source).getEnabled(); + } + + void doSetBooleanValue(Object source, boolean value) { + ((ToolItem) source).setEnabled(value); + } + + public String toString() { + return "ToolItem.enabled <boolean>"; //$NON-NLS-1$ + } +} diff --git a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/swt/WidgetEnabledProperty.java b/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/swt/WidgetEnabledProperty.java new file mode 100644 index 00000000..d49112f8 --- /dev/null +++ b/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/swt/WidgetEnabledProperty.java @@ -0,0 +1,66 @@ +/******************************************************************************* + * Copyright (c) 2009 Matthew Hall and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Matthew Hall - initial API and implementation (bug 264286) + *******************************************************************************/ + +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.MenuItem; +import org.eclipse.swt.widgets.ScrollBar; +import org.eclipse.swt.widgets.ToolItem; + +/** + * + */ +public class WidgetEnabledProperty extends WidgetDelegatingValueProperty { + IValueProperty control; + IValueProperty menu; + IValueProperty menuItem; + IValueProperty scrollBar; + IValueProperty toolItem; + + /** + * + */ + public WidgetEnabledProperty() { + super(Boolean.TYPE); + } + + protected IValueProperty doGetDelegate(Object source) { + if (source instanceof Control) { + if (control == null) + control = new ControlEnabledProperty(); + return control; + } + if (source instanceof Menu) { + if (menu == null) + menu = new MenuEnabledProperty(); + return menu; + } + if (source instanceof MenuItem) { + if (menuItem == null) + menuItem = new MenuItemEnabledProperty(); + return menuItem; + } + if (source instanceof ScrollBar) { + if (scrollBar == null) + scrollBar = new ScrollBarEnabledProperty(); + return scrollBar; + } + if (source instanceof ToolItem) { + if (toolItem == null) + toolItem = new ToolItemEnabledProperty(); + return toolItem; + } + throw notSupported(source); + } +}
\ No newline at end of file diff --git a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/swt/WidgetSelectionProperty.java b/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/swt/WidgetSelectionProperty.java index 094aa4fa..8ed6f329 100644 --- a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/swt/WidgetSelectionProperty.java +++ b/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/swt/WidgetSelectionProperty.java @@ -18,6 +18,7 @@ import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Combo; import org.eclipse.swt.widgets.DateTime; import org.eclipse.swt.widgets.List; +import org.eclipse.swt.widgets.MenuItem; import org.eclipse.swt.widgets.Scale; import org.eclipse.swt.widgets.Spinner; @@ -32,6 +33,7 @@ public final class WidgetSelectionProperty extends private IValueProperty combo; private IValueProperty dateTime; private IValueProperty list; + private IValueProperty menuItem; private IValueProperty scale; private IValueProperty spinner; @@ -61,6 +63,11 @@ public final class WidgetSelectionProperty extends list = new ListSelectionProperty(); return list; } + if (source instanceof MenuItem) { + if (menuItem == null) + menuItem = new MenuItemSelectionProperty(); + return menuItem; + } if (source instanceof Scale) { if (scale == null) scale = new ScaleSelectionProperty(); diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/swt/SWTObservablesTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/swt/SWTObservablesTest.java index 18109a95..6659af5b 100644 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/swt/SWTObservablesTest.java +++ b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/swt/SWTObservablesTest.java @@ -14,32 +14,43 @@ package org.eclipse.jface.tests.databinding.swt; import org.eclipse.core.databinding.observable.IDecoratingObservable; -import org.eclipse.core.databinding.observable.list.IObservableList; import org.eclipse.core.databinding.property.IPropertyObservable; import org.eclipse.jface.databinding.conformance.util.ChangeEventTracker; import org.eclipse.jface.databinding.conformance.util.RealmTester; import org.eclipse.jface.databinding.swt.ISWTObservable; +import org.eclipse.jface.databinding.swt.ISWTObservableList; import org.eclipse.jface.databinding.swt.ISWTObservableValue; import org.eclipse.jface.databinding.swt.SWTObservables; import org.eclipse.jface.databinding.swt.WidgetProperties; import org.eclipse.jface.internal.databinding.swt.ButtonImageProperty; +import org.eclipse.jface.internal.databinding.swt.ButtonSelectionProperty; import org.eclipse.jface.internal.databinding.swt.ButtonTextProperty; +import org.eclipse.jface.internal.databinding.swt.CComboItemsProperty; import org.eclipse.jface.internal.databinding.swt.CComboSelectionProperty; import org.eclipse.jface.internal.databinding.swt.CComboTextProperty; import org.eclipse.jface.internal.databinding.swt.CLabelImageProperty; import org.eclipse.jface.internal.databinding.swt.CLabelTextProperty; import org.eclipse.jface.internal.databinding.swt.CTabItemTooltipTextProperty; +import org.eclipse.jface.internal.databinding.swt.ComboItemsProperty; import org.eclipse.jface.internal.databinding.swt.ComboSelectionProperty; import org.eclipse.jface.internal.databinding.swt.ComboTextProperty; +import org.eclipse.jface.internal.databinding.swt.ControlBackgroundProperty; +import org.eclipse.jface.internal.databinding.swt.ControlForegroundProperty; import org.eclipse.jface.internal.databinding.swt.ControlTooltipTextProperty; import org.eclipse.jface.internal.databinding.swt.DateTimeSelectionProperty; import org.eclipse.jface.internal.databinding.swt.ItemImageProperty; import org.eclipse.jface.internal.databinding.swt.ItemTextProperty; import org.eclipse.jface.internal.databinding.swt.LabelImageProperty; import org.eclipse.jface.internal.databinding.swt.LabelTextProperty; +import org.eclipse.jface.internal.databinding.swt.ListItemsProperty; +import org.eclipse.jface.internal.databinding.swt.ListSelectionProperty; +import org.eclipse.jface.internal.databinding.swt.MenuEnabledProperty; +import org.eclipse.jface.internal.databinding.swt.MenuItemEnabledProperty; +import org.eclipse.jface.internal.databinding.swt.MenuItemSelectionProperty; import org.eclipse.jface.internal.databinding.swt.ScaleMaximumProperty; import org.eclipse.jface.internal.databinding.swt.ScaleMinimumProperty; import org.eclipse.jface.internal.databinding.swt.ScaleSelectionProperty; +import org.eclipse.jface.internal.databinding.swt.ScrollBarEnabledProperty; import org.eclipse.jface.internal.databinding.swt.SpinnerMaximumProperty; import org.eclipse.jface.internal.databinding.swt.SpinnerMinimumProperty; import org.eclipse.jface.internal.databinding.swt.SpinnerSelectionProperty; @@ -47,6 +58,7 @@ import org.eclipse.jface.internal.databinding.swt.StyledTextTextProperty; import org.eclipse.jface.internal.databinding.swt.TableSingleSelectionIndexProperty; import org.eclipse.jface.internal.databinding.swt.TextEditableProperty; import org.eclipse.jface.internal.databinding.swt.TextTextProperty; +import org.eclipse.jface.internal.databinding.swt.ToolItemEnabledProperty; import org.eclipse.jface.tests.databinding.AbstractSWTTestCase; import org.eclipse.swt.SWT; import org.eclipse.swt.custom.CCombo; @@ -62,14 +74,20 @@ import org.eclipse.swt.widgets.DateTime; import org.eclipse.swt.widgets.Item; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.List; +import org.eclipse.swt.widgets.Menu; +import org.eclipse.swt.widgets.MenuItem; import org.eclipse.swt.widgets.Scale; +import org.eclipse.swt.widgets.ScrollBar; import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Spinner; import org.eclipse.swt.widgets.Table; import org.eclipse.swt.widgets.TableItem; 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.Tree; +import org.eclipse.swt.widgets.Widget; /** * @since 1.1 @@ -90,15 +108,22 @@ public class SWTObservablesTest extends AbstractSWTTestCase { RealmTester.setDefault(null); } + protected Shell getShell() { + if (shell == null) { + shell = new Shell(SWT.V_SCROLL); + } + return shell; + } + public void testObserveForeground() throws Exception { ISWTObservableValue value = SWTObservables.observeForeground(shell); - assertNotNull(value); + assertWidgetObservable(value, shell, ControlForegroundProperty.class); assertEquals(Color.class, value.getValueType()); } public void testObserveBackground() throws Exception { ISWTObservableValue value = SWTObservables.observeBackground(shell); - assertNotNull(value); + assertWidgetObservable(value, shell, ControlBackgroundProperty.class); assertEquals(Color.class, value.getValueType()); } @@ -111,82 +136,55 @@ public class SWTObservablesTest extends AbstractSWTTestCase { public void testObserveSelectionOfSpinner() throws Exception { Spinner spinner = new Spinner(shell, SWT.NONE); ISWTObservableValue value = SWTObservables.observeSelection(spinner); - assertNotNull(value); - assertTrue(value.getWidget() == spinner); - - IPropertyObservable propertyObservable = getPropertyObservable(value); - assertTrue(propertyObservable.getProperty() instanceof SpinnerSelectionProperty); + assertWidgetObservable(value, spinner, SpinnerSelectionProperty.class); } public void testObserveSelectionOfButton() throws Exception { Button button = new Button(shell, SWT.PUSH); ISWTObservableValue value = SWTObservables.observeSelection(button); - assertNotNull(value); - assertTrue(value.getWidget() == button); + assertWidgetObservable(value, button, ButtonSelectionProperty.class); } public void testObserveSelectionOfCombo() throws Exception { Combo combo = new Combo(shell, SWT.NONE); ISWTObservableValue value = SWTObservables.observeSelection(combo); - assertNotNull(value); - assertTrue(value.getWidget() == combo); - - IPropertyObservable propertyObservable = getPropertyObservable(value); - assertTrue(propertyObservable.getProperty() instanceof ComboSelectionProperty); + assertWidgetObservable(value, combo, ComboSelectionProperty.class); } public void testObserveSelectionOfCCombo() throws Exception { CCombo combo = new CCombo(shell, SWT.NONE); ISWTObservableValue value = SWTObservables.observeSelection(combo); - assertNotNull(value); - assertTrue(value.getWidget() == combo); - - IPropertyObservable property = getPropertyObservable(value); - assertTrue(property.getProperty() instanceof CComboSelectionProperty); + assertWidgetObservable(value, combo, CComboSelectionProperty.class); } public void testObserveSelectionOfDateTime_Date() throws Exception { DateTime dateTime = new DateTime(shell, SWT.DATE); ISWTObservableValue value = SWTObservables.observeSelection(dateTime); - assertNotNull(value); - assertTrue(value.getWidget() == dateTime); - IPropertyObservable property = getPropertyObservable(value); - assertTrue(property.getProperty() instanceof DateTimeSelectionProperty); + assertWidgetObservable(value, dateTime, DateTimeSelectionProperty.class); } public void testObserveSelectionOfDateTime_Calendar() throws Exception { DateTime dateTime = new DateTime(shell, SWT.CALENDAR); ISWTObservableValue value = SWTObservables.observeSelection(dateTime); - assertNotNull(value); - assertTrue(value.getWidget() == dateTime); - IPropertyObservable property = getPropertyObservable(value); - assertTrue(property.getProperty() instanceof DateTimeSelectionProperty); + assertWidgetObservable(value, dateTime, DateTimeSelectionProperty.class); } public void testObserveSelectionOfDateTime_Time() throws Exception { DateTime dateTime = new DateTime(shell, SWT.TIME); ISWTObservableValue value = SWTObservables.observeSelection(dateTime); - assertNotNull(value); - assertTrue(value.getWidget() == dateTime); - IPropertyObservable property = getPropertyObservable(value); - assertTrue(property.getProperty() instanceof DateTimeSelectionProperty); + assertWidgetObservable(value, dateTime, DateTimeSelectionProperty.class); } public void testObserveSelectionOfList() throws Exception { List list = new List(shell, SWT.NONE); ISWTObservableValue value = SWTObservables.observeSelection(list); - assertNotNull(value); - assertTrue(value.getWidget() == list); + assertWidgetObservable(value, list, ListSelectionProperty.class); } public void testObserveSelectionOfScale() throws Exception { Scale scale = new Scale(shell, SWT.NONE); ISWTObservableValue value = SWTObservables.observeSelection(scale); - assertNotNull(value); - assertTrue(value.getWidget() == scale); - - IPropertyObservable property = getPropertyObservable(value); - assertTrue(property.getProperty() instanceof ScaleSelectionProperty); + assertWidgetObservable(value, scale, ScaleSelectionProperty.class); } public void testObserveSelectionOfUnsupportedControl() throws Exception { @@ -204,10 +202,7 @@ public class SWTObservablesTest extends AbstractSWTTestCase { ISWTObservableValue value = SWTObservables.observeText(text, SWT.FocusOut); - assertNotNull(value); - assertTrue(value.getWidget() == text); - IPropertyObservable propertyObservable = getPropertyObservable(value); - assertTrue(propertyObservable.getProperty() instanceof TextTextProperty); + assertWidgetObservable(value, text, TextTextProperty.class); assertFalse(text.isListening(SWT.FocusOut)); ChangeEventTracker.observe(value); @@ -220,10 +215,7 @@ public class SWTObservablesTest extends AbstractSWTTestCase { ISWTObservableValue value = SWTObservables.observeText(text, SWT.FocusOut); - assertNotNull(value); - assertTrue(value.getWidget() == text); - IPropertyObservable propertyObservable = getPropertyObservable(value); - assertTrue(propertyObservable.getProperty() instanceof StyledTextTextProperty); + assertWidgetObservable(value, text, StyledTextTextProperty.class); assertFalse(text.isListening(SWT.FocusOut)); ChangeEventTracker.observe(value); @@ -242,45 +234,32 @@ public class SWTObservablesTest extends AbstractSWTTestCase { public void testObserveTextOfButton() throws Exception { Button button = new Button(shell, SWT.PUSH); ISWTObservableValue value = SWTObservables.observeText(button); - assertNotNull(button); - assertTrue(value.getWidget() == button); - IPropertyObservable propertyObservable = getPropertyObservable(value); - assertTrue(propertyObservable.getProperty() instanceof ButtonTextProperty); + assertWidgetObservable(value, button, ButtonTextProperty.class); } public void testObserveTextOfLabel() throws Exception { Label label = new Label(shell, SWT.NONE); ISWTObservableValue value = SWTObservables.observeText(label); - assertNotNull(label); - assertTrue(value.getWidget() == label); - IPropertyObservable propertyObservable = getPropertyObservable(value); - assertTrue(propertyObservable.getProperty() instanceof LabelTextProperty); + assertWidgetObservable(value, label, LabelTextProperty.class); } public void testObserveTextOfCLabel() throws Exception { CLabel label = new CLabel(shell, SWT.NONE); ISWTObservableValue value = SWTObservables.observeText(label); - assertNotNull(label); - assertTrue(value.getWidget() == label); - IPropertyObservable propertyObservable = getPropertyObservable(value); - assertTrue(propertyObservable.getProperty() instanceof CLabelTextProperty); + assertWidgetObservable(value, label, CLabelTextProperty.class); } public void testObserveTextOfCombo() throws Exception { Combo combo = new Combo(shell, SWT.NONE); ISWTObservableValue value = SWTObservables.observeText(combo); - assertNotNull(value); - assertTrue(value.getWidget() == combo); - - assertTrue(getPropertyObservable(value).getProperty() instanceof ComboTextProperty); + assertWidgetObservable(value, combo, ComboTextProperty.class); } /** * @param observable * @return */ - private IPropertyObservable getPropertyObservable( - ISWTObservableValue observable) { + private IPropertyObservable getPropertyObservable(ISWTObservable observable) { IDecoratingObservable decoratingObservable = (IDecoratingObservable) observable; IPropertyObservable propertyObservable = (IPropertyObservable) decoratingObservable .getDecorated(); @@ -290,23 +269,14 @@ public class SWTObservablesTest extends AbstractSWTTestCase { public void testObserveTextOfCCombo() throws Exception { CCombo combo = new CCombo(shell, SWT.NONE); ISWTObservableValue value = SWTObservables.observeText(combo); - assertNotNull(value); - assertTrue(value.getWidget() == combo); - - IDecoratingObservable decorating = (IDecoratingObservable) value; - IPropertyObservable property = (IPropertyObservable) decorating - .getDecorated(); - assertTrue(property.getProperty() instanceof CComboTextProperty); + assertWidgetObservable(value, combo, CComboTextProperty.class); } public void testObserveTextOfText() throws Exception { Text text = new Text(shell, SWT.NONE); ISWTObservableValue value = SWTObservables.observeText(text); - assertNotNull(value); - assertTrue(value.getWidget() == text); - IPropertyObservable propertyObservable = getPropertyObservable(value); - assertTrue(propertyObservable.getProperty() instanceof TextTextProperty); + assertWidgetObservable(value, text, TextTextProperty.class); assertFalse(text.isListening(SWT.Modify)); assertFalse(text.isListening(SWT.FocusOut)); @@ -316,10 +286,7 @@ public class SWTObservablesTest extends AbstractSWTTestCase { CTabFolder ctf = new CTabFolder(shell, SWT.NONE); Item item = new CTabItem(ctf, SWT.NONE); ISWTObservableValue value = SWTObservables.observeText(item); - assertNotNull(value); - assertTrue(value.getWidget() == item); - IPropertyObservable propertyObservable = getPropertyObservable(value); - assertTrue(propertyObservable.getProperty() instanceof ItemTextProperty); + assertWidgetObservable(value, item, ItemTextProperty.class); } public void testObserveTextOfUnsupportedControl() throws Exception { @@ -334,48 +301,33 @@ public class SWTObservablesTest extends AbstractSWTTestCase { public void testObserveImageOfButton() throws Exception { Button button = new Button(shell, SWT.PUSH); ISWTObservableValue value = SWTObservables.observeImage(button); - assertNotNull(button); - assertTrue(value.getWidget() == button); - IPropertyObservable propertyObservable = getPropertyObservable(value); - assertTrue(propertyObservable.getProperty() instanceof ButtonImageProperty); + assertWidgetObservable(value, button, ButtonImageProperty.class); } public void testObserveImageOfCLabel() throws Exception { CLabel cLabel = new CLabel(shell, SWT.NONE); ISWTObservableValue value = SWTObservables.observeImage(cLabel); - assertNotNull(cLabel); - assertTrue(value.getWidget() == cLabel); - IPropertyObservable propertyObservable = getPropertyObservable(value); - assertTrue(propertyObservable.getProperty() instanceof CLabelImageProperty); + assertWidgetObservable(value, cLabel, CLabelImageProperty.class); } public void testObserveImageOfItem() throws Exception { CTabFolder ctf = new CTabFolder(shell, SWT.NONE); Item item = new CTabItem(ctf, SWT.NONE); ISWTObservableValue value = SWTObservables.observeImage(item); - assertNotNull(item); - assertTrue(value.getWidget() == item); - IPropertyObservable propertyObservable = getPropertyObservable(value); - assertTrue(propertyObservable.getProperty() instanceof ItemImageProperty); + assertWidgetObservable(value, item, ItemImageProperty.class); } public void testObserveImageOfLabel() throws Exception { Label label = new Label(shell, SWT.NONE); ISWTObservableValue value = SWTObservables.observeImage(label); - assertNotNull(label); - assertTrue(value.getWidget() == label); - IPropertyObservable propertyObservable = getPropertyObservable(value); - assertTrue(propertyObservable.getProperty() instanceof LabelImageProperty); + assertWidgetObservable(value, label, LabelImageProperty.class); } public void testObserveTooltipOfItem() throws Exception { CTabFolder ctf = new CTabFolder(shell, SWT.NONE); Item item = new CTabItem(ctf, SWT.NONE); ISWTObservableValue value = SWTObservables.observeTooltipText(item); - assertNotNull(value); - assertTrue(value.getWidget() == item); - IPropertyObservable propertyObservable = getPropertyObservable(value); - assertTrue(propertyObservable.getProperty() instanceof CTabItemTooltipTextProperty); + assertWidgetObservable(value, item, CTabItemTooltipTextProperty.class); } public void testObserveTooltipOfUnsupportedControl() throws Exception { @@ -390,34 +342,28 @@ public class SWTObservablesTest extends AbstractSWTTestCase { public void testObserveTooltipOfControl() throws Exception { Label label = new Label(shell, SWT.NONE); ISWTObservableValue value = SWTObservables.observeTooltipText(label); - assertNotNull(value); - assertTrue(value.getWidget() == label); - IPropertyObservable propertyObservable = getPropertyObservable(value); - assertTrue(propertyObservable.getProperty() instanceof ControlTooltipTextProperty); + assertWidgetObservable(value, label, ControlTooltipTextProperty.class); } public void testObserveItemsOfCombo() throws Exception { Combo combo = new Combo(shell, SWT.NONE); - IObservableList list = SWTObservables.observeItems(combo); - assertNotNull(list); - assertTrue(list instanceof ISWTObservable); - assertTrue(((ISWTObservable) list).getWidget() == combo); + ISWTObservableList list = (ISWTObservableList) SWTObservables + .observeItems(combo); + assertWidgetObservable(list, combo, ComboItemsProperty.class); } public void testObserveItemsOfCCombo() throws Exception { CCombo ccombo = new CCombo(shell, SWT.NONE); - IObservableList list = SWTObservables.observeItems(ccombo); - assertNotNull(list); - ISWTObservable swtObservable = (ISWTObservable) list; - assertTrue(swtObservable.getWidget() == ccombo); + ISWTObservableList list = (ISWTObservableList) SWTObservables + .observeItems(ccombo); + assertWidgetObservable(list, ccombo, CComboItemsProperty.class); } public void testObserveItemsOfList() throws Exception { List list = new List(shell, SWT.NONE); - IObservableList observableList = SWTObservables.observeItems(list); - assertNotNull(observableList); - ISWTObservable swtObservable = (ISWTObservable) observableList; - assertTrue(swtObservable.getWidget() == list); + ISWTObservableList observableList = (ISWTObservableList) SWTObservables + .observeItems(list); + assertWidgetObservable(observableList, list, ListItemsProperty.class); } public void testObserveItemsOfUnsupportedControl() throws Exception { @@ -433,10 +379,8 @@ public class SWTObservablesTest extends AbstractSWTTestCase { Table table = new Table(shell, SWT.NONE); ISWTObservableValue value = SWTObservables .observeSingleSelectionIndex(table); - assertNotNull(value); - assertTrue(value.getWidget() == table); - IPropertyObservable propertyObservable = getPropertyObservable(value); - assertTrue(propertyObservable.getProperty() instanceof TableSingleSelectionIndexProperty); + assertWidgetObservable(value, table, + TableSingleSelectionIndexProperty.class); } public void testObserveSingleSelectionIndexOfCCombo_DeselectAll() @@ -557,21 +501,13 @@ public class SWTObservablesTest extends AbstractSWTTestCase { public void testObserveMinOfSpinner() throws Exception { Spinner spinner = new Spinner(shell, SWT.NONE); ISWTObservableValue value = SWTObservables.observeMin(spinner); - assertNotNull(value); - assertTrue(value.getWidget() == spinner); - - IPropertyObservable propertyObservable = getPropertyObservable(value); - assertTrue(propertyObservable.getProperty() instanceof SpinnerMinimumProperty); + assertWidgetObservable(value, spinner, SpinnerMinimumProperty.class); } public void testObserveMinOfScale() throws Exception { Scale scale = new Scale(shell, SWT.NONE); ISWTObservableValue value = SWTObservables.observeMin(scale); - assertNotNull(value); - assertTrue(value.getWidget() == scale); - - IPropertyObservable propertyObservable = getPropertyObservable(value); - assertTrue(propertyObservable.getProperty() instanceof ScaleMinimumProperty); + assertWidgetObservable(value, scale, ScaleMinimumProperty.class); } public void testObserveMinOfUnsupportedControl() throws Exception { @@ -586,21 +522,13 @@ public class SWTObservablesTest extends AbstractSWTTestCase { public void testObserveMaxOfSpinner() throws Exception { Spinner spinner = new Spinner(shell, SWT.NONE); ISWTObservableValue value = SWTObservables.observeMax(spinner); - assertNotNull(value); - assertTrue(value.getWidget() == spinner); - - IPropertyObservable propertyObservable = getPropertyObservable(value); - assertTrue(propertyObservable.getProperty() instanceof SpinnerMaximumProperty); + assertWidgetObservable(value, spinner, SpinnerMaximumProperty.class); } public void testObserveMaxOfScale() throws Exception { Scale scale = new Scale(shell, SWT.NONE); ISWTObservableValue value = SWTObservables.observeMax(scale); - assertNotNull(value); - assertTrue(value.getWidget() == scale); - - IPropertyObservable propertyObservable = getPropertyObservable(value); - assertTrue(propertyObservable.getProperty() instanceof ScaleMaximumProperty); + assertWidgetObservable(value, scale, ScaleMaximumProperty.class); } public void testObserveMaxOfUnsupportedControl() throws Exception { @@ -615,10 +543,48 @@ public class SWTObservablesTest extends AbstractSWTTestCase { public void testObserveEditableOfText() throws Exception { Text text = new Text(shell, SWT.NONE); ISWTObservableValue value = SWTObservables.observeEditable(text); - assertNotNull(value); - assertTrue(value.getWidget() == text); - IPropertyObservable propertyObservable = getPropertyObservable(value); - assertTrue(propertyObservable.getProperty() instanceof TextEditableProperty); + assertWidgetObservable(value, text, TextEditableProperty.class); + } + + public void testObserveEnabledOfMenu() throws Exception { + Menu menu = new Menu(shell, SWT.BAR); + ISWTObservableValue value = SWTObservables.observeEnabled(menu); + assertWidgetObservable(value, menu, MenuEnabledProperty.class); + } + + public void testObserveEnabledOfMenuItem() throws Exception { + Menu menu = new Menu(shell, SWT.DROP_DOWN); + MenuItem item = new MenuItem(menu, SWT.PUSH); + ISWTObservableValue value = SWTObservables.observeEnabled(item); + assertWidgetObservable(value, item, MenuItemEnabledProperty.class); + } + + public void testObserveSelectionOfMenuItem() throws Exception { + Menu menu = new Menu(shell, SWT.DROP_DOWN); + MenuItem item = new MenuItem(menu, SWT.PUSH); + ISWTObservableValue value = SWTObservables.observeSelection(item); + assertWidgetObservable(value, item, MenuItemSelectionProperty.class); + } + + public void testObserveEnabledOfScrollBar() throws Exception { + ScrollBar scrollBar = shell.getVerticalBar(); + ISWTObservableValue value = SWTObservables.observeEnabled(scrollBar); + assertWidgetObservable(value, scrollBar, ScrollBarEnabledProperty.class); + } + + public void testObserveEnabledOfToolItem() throws Exception { + ToolBar bar = new ToolBar(shell, SWT.HORIZONTAL); + ToolItem item = new ToolItem(bar, SWT.PUSH); + ISWTObservableValue value = SWTObservables.observeEnabled(item); + assertWidgetObservable(value, item, ToolItemEnabledProperty.class); + } + + private void assertWidgetObservable(ISWTObservable observable, + Widget widget, Class propertyClass) { + assertNotNull(observable); + assertTrue(observable.getWidget() == widget); + IPropertyObservable propertyObservable = getPropertyObservable(observable); + assertTrue(propertyClass.isInstance(propertyObservable.getProperty())); } public void testObserveEditableOfUnsupportedControl() throws Exception { diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/swt/WidgetPropertiesTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/swt/WidgetPropertiesTest.java index 657e593c..767688ac 100644 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/swt/WidgetPropertiesTest.java +++ b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/swt/WidgetPropertiesTest.java @@ -25,6 +25,9 @@ import org.eclipse.swt.graphics.Image; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Menu; +import org.eclipse.swt.widgets.MenuItem; +import org.eclipse.swt.widgets.ScrollBar; import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.TabFolder; import org.eclipse.swt.widgets.TabItem; @@ -70,6 +73,13 @@ public class WidgetPropertiesTest extends AbstractSWTTestCase { RealmTester.setDefault(null); } + protected Shell getShell() { + if (shell == null) { + shell = new Shell(SWT.V_SCROLL); + } + return shell; + } + public void testImage_ObserveButton() { Button button = /* who's got the */new Button(shell, SWT.PUSH); button.setImage(image1); @@ -208,4 +218,73 @@ public class WidgetPropertiesTest extends AbstractSWTTestCase { observable.setValue(string2); assertEquals(string2, column.getToolTipText()); } + + public void testEnabled_ObserveMenu() { + Menu menu = new Menu(shell, SWT.BAR); + IObservableValue observable = WidgetProperties.enabled().observe(menu); + + assertEquals(boolean.class, observable.getValueType()); + + menu.setEnabled(true); + assertEquals(Boolean.TRUE, observable.getValue()); + + observable.setValue(Boolean.FALSE); + assertEquals(false, menu.getEnabled()); + } + + public void testEnabled_ObserveMenuItem() { + Menu menu = new Menu(shell, SWT.BAR); + MenuItem item = new MenuItem(menu, SWT.PUSH); + IObservableValue observable = WidgetProperties.enabled().observe(item); + + assertEquals(boolean.class, observable.getValueType()); + + item.setEnabled(true); + assertEquals(Boolean.TRUE, observable.getValue()); + + observable.setValue(Boolean.FALSE); + assertEquals(false, item.getEnabled()); + } + + public void testSelection_ObserveMenuItem() { + Menu menu = new Menu(shell, SWT.BAR); + MenuItem item = new MenuItem(menu, SWT.CHECK); + IObservableValue observable = WidgetProperties.selection() + .observe(item); + + assertEquals(boolean.class, observable.getValueType()); + + item.setSelection(true); + assertEquals(Boolean.TRUE, observable.getValue()); + + observable.setValue(Boolean.FALSE); + assertEquals(false, item.getSelection()); + } + + public void testEnabled_ObserveScrollBar() { + ScrollBar bar = shell.getVerticalBar(); + IObservableValue observable = WidgetProperties.enabled().observe(bar); + + assertEquals(boolean.class, observable.getValueType()); + + bar.setEnabled(true); + assertEquals(Boolean.TRUE, observable.getValue()); + + observable.setValue(Boolean.FALSE); + assertEquals(false, bar.getEnabled()); + } + + public void testEnabled_ObserveToolItem() { + ToolBar bar = new ToolBar(shell, SWT.HORIZONTAL); + ToolItem item = new ToolItem(bar, SWT.PUSH); + IObservableValue observable = WidgetProperties.enabled().observe(item); + + assertEquals(boolean.class, observable.getValueType()); + + item.setEnabled(true); + assertEquals(Boolean.TRUE, observable.getValue()); + + observable.setValue(Boolean.FALSE); + assertEquals(false, item.getEnabled()); + } } |