diff options
10 files changed, 621 insertions, 0 deletions
diff --git a/bundles/org.eclipse.core.databinding.property/src/org/eclipse/core/internal/databinding/property/value/ObservableValueProperty.java b/bundles/org.eclipse.core.databinding.property/src/org/eclipse/core/internal/databinding/property/value/ObservableValueProperty.java new file mode 100644 index 00000000..990d9636 --- /dev/null +++ b/bundles/org.eclipse.core.databinding.property/src/org/eclipse/core/internal/databinding/property/value/ObservableValueProperty.java @@ -0,0 +1,99 @@ +/******************************************************************************* + * 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 263709) + ******************************************************************************/ + +package org.eclipse.core.internal.databinding.property.value; + +import org.eclipse.core.databinding.observable.Realm; +import org.eclipse.core.databinding.observable.value.IObservableValue; +import org.eclipse.core.databinding.observable.value.IValueChangeListener; +import org.eclipse.core.databinding.observable.value.ValueChangeEvent; +import org.eclipse.core.databinding.property.INativePropertyListener; +import org.eclipse.core.databinding.property.ISimplePropertyListener; +import org.eclipse.core.databinding.property.SimplePropertyEvent; +import org.eclipse.core.databinding.property.value.SimpleValueProperty; + +/** + * @since 3.3 + * + */ +/* + * This class extends SimpleValueProperty rather than ValueProperty so make it + * easy to observe multiple IObservableValues, for example an IObservableList of + * IObservableValues. In the simple case of observe(Object) or + * observeDetail(IObservableValue) we just cast the source object to + * IObservableValue and return it. + */ +public class ObservableValueProperty extends SimpleValueProperty { + private final Object valueType; + + /** + * @param valueType + */ + public ObservableValueProperty(Object valueType) { + this.valueType = valueType; + } + + public Object getValueType() { + return valueType; + } + + protected Object doGetValue(Object source) { + return ((IObservableValue) source).getValue(); + } + + protected void doSetValue(Object source, Object value) { + ((IObservableValue) source).setValue(value); + } + + public INativePropertyListener adaptListener( + ISimplePropertyListener listener) { + return new Listener(listener); + } + + private class Listener implements INativePropertyListener, + IValueChangeListener { + private final ISimplePropertyListener listener; + + Listener(ISimplePropertyListener listener) { + this.listener = listener; + } + + public void handleValueChange(ValueChangeEvent event) { + listener + .handlePropertyChange(new SimplePropertyEvent(event + .getObservable(), ObservableValueProperty.this, + event.diff)); + } + } + + protected void doAddListener(Object source, INativePropertyListener listener) { + ((IObservableValue) source) + .addValueChangeListener((IValueChangeListener) listener); + } + + protected void doRemoveListener(Object source, + INativePropertyListener listener) { + ((IObservableValue) source) + .removeValueChangeListener((IValueChangeListener) listener); + } + + public IObservableValue observe(Realm realm, Object source) { + // Ignore realm if different + return (IObservableValue) source; + } + + public String toString() { + String result = "IObservableValue#value"; //$NON-NLS-1$ + if (valueType != null) + result += " <" + valueType + ">"; //$NON-NLS-1$ //$NON-NLS-2$ + return result; + } +}
\ No newline at end of file diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/BindingProperties.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/BindingProperties.java new file mode 100644 index 00000000..6b75da0a --- /dev/null +++ b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/BindingProperties.java @@ -0,0 +1,113 @@ +/******************************************************************************* + * 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 263709) + ******************************************************************************/ + +package org.eclipse.core.databinding; + +import org.eclipse.core.databinding.observable.IObservable; +import org.eclipse.core.databinding.property.list.IListProperty; +import org.eclipse.core.databinding.property.value.IValueProperty; +import org.eclipse.core.internal.databinding.BindingModelProperty; +import org.eclipse.core.internal.databinding.BindingTargetProperty; +import org.eclipse.core.internal.databinding.DataBindingContextBindingsProperty; +import org.eclipse.core.internal.databinding.DataBindingContextValidationStatusProvidersProperty; +import org.eclipse.core.internal.databinding.ValidationStatusProviderModelsProperty; +import org.eclipse.core.internal.databinding.ValidationStatusProviderTargetsProperty; +import org.eclipse.core.internal.databinding.ValidationStatusProviderValidationStatusProperty; +import org.eclipse.core.internal.databinding.property.value.ObservableValueProperty; +import org.eclipse.core.runtime.IStatus; + +/** + * A factory for creating properties for core types in the DataBinding framework + * e.g. {@link DataBindingContext} or ValidationStatusProvider. + * + * @since 1.2 + */ +public class BindingProperties { + /** + * Returns an {@link IListProperty} < {@link Binding} > for observing + * the bindings of a {@link DataBindingContext}. + * + * @return an {@link IListProperty} < {@link Binding} > for observing + * the bindings of a {@link DataBindingContext}. + */ + public static IListProperty bindings() { + return new DataBindingContextBindingsProperty(); + } + + /** + * Returns an {@link IValueProperty} < {@link IObservable} > for + * observing the model of a {@link Binding}. + * + * @return an {@link IValueProperty} < {@link IObservable} > for + * observing the model of a {@link Binding}. + */ + public static IValueProperty model() { + return new BindingModelProperty(); + } + + /** + * Returns an {@link IListProperty} < {@link IObservable} > for + * observing the models of a {@link ValidationStatusProvider}. + * + * @return an {@link IListProperty} < {@link IObservable} > for + * observing the models of a {@link ValidationStatusProvider}. + */ + public static IListProperty models() { + return new ValidationStatusProviderModelsProperty(); + } + + /** + * Returns an {@link IValueProperty} < {@link IObservable} > for + * observing the target of a {@link Binding}. + * + * @return an {@link IValueProperty} < {@link IObservable} > for + * observing the target of a {@link Binding}. + */ + public static IValueProperty target() { + return new BindingTargetProperty(); + } + + /** + * Returns an {@link IListProperty} < {@link IObservable} > for + * observing the targets of a {@link ValidationStatusProvider}. + * + * @return an {@link IListProperty} < {@link IObservable} > for + * observing the targets of a {@link ValidationStatusProvider}. + */ + public static IListProperty targets() { + return new ValidationStatusProviderTargetsProperty(); + } + + /** + * Returns an {@link IValueProperty} < {@link IStatus} > for observing + * the validation status of a {@link ValidationStatusProvider}. + * + * @return an {@link IValueProperty} < {@link IStatus} > for observing + * the validation status of a {@link ValidationStatusProvider}. + */ + public static IValueProperty validationStatus() { + return new ValidationStatusProviderValidationStatusProperty() + .value(new ObservableValueProperty(IStatus.class)); + } + + /** + * Returns an {@link IListProperty} < {@link ValidationStatusProvider} + * > for observing the validation status providers of a + * {@link DataBindingContext}. + * + * @return an {@link IListProperty} < {@link ValidationStatusProvider} + * > for observing the validation status providers of a + * {@link DataBindingContext}. + */ + public static IListProperty validationStatusProviders() { + return new DataBindingContextValidationStatusProvidersProperty(); + } +} diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/BindingModelProperty.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/BindingModelProperty.java new file mode 100644 index 00000000..dbfbbfae --- /dev/null +++ b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/BindingModelProperty.java @@ -0,0 +1,55 @@ +/******************************************************************************* + * 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 263709) + ******************************************************************************/ + +package org.eclipse.core.internal.databinding; + +import org.eclipse.core.databinding.Binding; +import org.eclipse.core.databinding.observable.IObservable; +import org.eclipse.core.databinding.property.INativePropertyListener; +import org.eclipse.core.databinding.property.ISimplePropertyListener; +import org.eclipse.core.databinding.property.value.IValueProperty; +import org.eclipse.core.databinding.property.value.SimpleValueProperty; + +/** + * @since 3.3 + * + */ +public class BindingModelProperty extends SimpleValueProperty implements + IValueProperty { + public Object getValueType() { + return IObservable.class; + } + + protected Object doGetValue(Object source) { + return ((Binding) source).getModel(); + } + + protected void doSetValue(Object source, Object value) { + // no setter API + } + + public INativePropertyListener adaptListener( + ISimplePropertyListener listener) { + // no listener API + return null; + } + + protected void doAddListener(Object source, INativePropertyListener listener) { + } + + protected void doRemoveListener(Object source, + INativePropertyListener listener) { + } + + public String toString() { + return "Binding#model <IObservable>"; //$NON-NLS-1$ + } +} diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/BindingTargetProperty.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/BindingTargetProperty.java new file mode 100644 index 00000000..dfa562e6 --- /dev/null +++ b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/BindingTargetProperty.java @@ -0,0 +1,55 @@ +/******************************************************************************* + * 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 263709) + ******************************************************************************/ + +package org.eclipse.core.internal.databinding; + +import org.eclipse.core.databinding.Binding; +import org.eclipse.core.databinding.observable.IObservable; +import org.eclipse.core.databinding.property.INativePropertyListener; +import org.eclipse.core.databinding.property.ISimplePropertyListener; +import org.eclipse.core.databinding.property.value.IValueProperty; +import org.eclipse.core.databinding.property.value.SimpleValueProperty; + +/** + * @since 3.3 + * + */ +public class BindingTargetProperty extends SimpleValueProperty implements + IValueProperty { + public Object getValueType() { + return IObservable.class; + } + + protected Object doGetValue(Object source) { + return ((Binding) source).getTarget(); + } + + protected void doSetValue(Object source, Object value) { + // no setter API + } + + public INativePropertyListener adaptListener( + ISimplePropertyListener listener) { + // no listener API + return null; + } + + protected void doAddListener(Object source, INativePropertyListener listener) { + } + + protected void doRemoveListener(Object source, + INativePropertyListener listener) { + } + + public String toString() { + return "Binding#target <IObservable>"; //$NON-NLS-1$ + } +} diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/DataBindingContextBindingsProperty.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/DataBindingContextBindingsProperty.java new file mode 100644 index 00000000..e4cc9ad7 --- /dev/null +++ b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/DataBindingContextBindingsProperty.java @@ -0,0 +1,37 @@ +/******************************************************************************* + * 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 263709) + ******************************************************************************/ + +package org.eclipse.core.internal.databinding; + +import org.eclipse.core.databinding.Binding; +import org.eclipse.core.databinding.DataBindingContext; +import org.eclipse.core.databinding.observable.Realm; +import org.eclipse.core.databinding.observable.list.IObservableList; +import org.eclipse.core.databinding.property.list.ListProperty; + +/** + * @since 3.3 + * + */ +public final class DataBindingContextBindingsProperty extends + ListProperty { + public Object getElementType() { + return Binding.class; + } + + public IObservableList observe(Realm realm, Object source) { + return ((DataBindingContext) source).getBindings(); + } + + public String toString() { + return "DataBindingContext#bindings[] <Binding>"; //$NON-NLS-1$ + } +}
\ No newline at end of file diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/DataBindingContextValidationStatusProvidersProperty.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/DataBindingContextValidationStatusProvidersProperty.java new file mode 100644 index 00000000..8cca35a0 --- /dev/null +++ b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/DataBindingContextValidationStatusProvidersProperty.java @@ -0,0 +1,37 @@ +/******************************************************************************* + * 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 263709) + ******************************************************************************/ + +package org.eclipse.core.internal.databinding; + +import org.eclipse.core.databinding.DataBindingContext; +import org.eclipse.core.databinding.ValidationStatusProvider; +import org.eclipse.core.databinding.observable.Realm; +import org.eclipse.core.databinding.observable.list.IObservableList; +import org.eclipse.core.databinding.property.list.ListProperty; + +/** + * @since 3.3 + * + */ +public final class DataBindingContextValidationStatusProvidersProperty extends + ListProperty { + public Object getElementType() { + return ValidationStatusProvider.class; + } + + public IObservableList observe(Realm realm, Object source) { + return ((DataBindingContext) source).getValidationStatusProviders(); + } + + public String toString() { + return "Binding#validationStatusProviders[] <ValidationStatusProvider>"; //$NON-NLS-1$ + } +}
\ No newline at end of file diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/ValidationStatusProviderModelsProperty.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/ValidationStatusProviderModelsProperty.java new file mode 100644 index 00000000..03755171 --- /dev/null +++ b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/ValidationStatusProviderModelsProperty.java @@ -0,0 +1,36 @@ +/******************************************************************************* + * 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 263709) + ******************************************************************************/ + +package org.eclipse.core.internal.databinding; + +import org.eclipse.core.databinding.ValidationStatusProvider; +import org.eclipse.core.databinding.observable.IObservable; +import org.eclipse.core.databinding.observable.Realm; +import org.eclipse.core.databinding.observable.list.IObservableList; +import org.eclipse.core.databinding.property.list.ListProperty; + +/** + * @since 3.3 + * + */ +public class ValidationStatusProviderModelsProperty extends ListProperty { + public Object getElementType() { + return IObservable.class; + } + + public IObservableList observe(Realm realm, Object source) { + return ((ValidationStatusProvider) source).getModels(); + } + + public String toString() { + return "ValidationStatusProvider#models[] <IObservable>"; //$NON-NLS-1$ + } +} diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/ValidationStatusProviderTargetsProperty.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/ValidationStatusProviderTargetsProperty.java new file mode 100644 index 00000000..30328395 --- /dev/null +++ b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/ValidationStatusProviderTargetsProperty.java @@ -0,0 +1,36 @@ +/******************************************************************************* + * 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 263709) + ******************************************************************************/ + +package org.eclipse.core.internal.databinding; + +import org.eclipse.core.databinding.ValidationStatusProvider; +import org.eclipse.core.databinding.observable.IObservable; +import org.eclipse.core.databinding.observable.Realm; +import org.eclipse.core.databinding.observable.list.IObservableList; +import org.eclipse.core.databinding.property.list.ListProperty; + +/** + * @since 3.3 + * + */ +public class ValidationStatusProviderTargetsProperty extends ListProperty { + public Object getElementType() { + return IObservable.class; + } + + public IObservableList observe(Realm realm, Object source) { + return ((ValidationStatusProvider) source).getTargets(); + } + + public String toString() { + return "ValidationStatusProvider#targets[] <IObservable>"; //$NON-NLS-1$ + } +} diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/ValidationStatusProviderValidationStatusProperty.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/ValidationStatusProviderValidationStatusProperty.java new file mode 100644 index 00000000..70753574 --- /dev/null +++ b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/ValidationStatusProviderValidationStatusProperty.java @@ -0,0 +1,54 @@ +/******************************************************************************* + * 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 263709) + ******************************************************************************/ + +package org.eclipse.core.internal.databinding; + +import org.eclipse.core.databinding.ValidationStatusProvider; +import org.eclipse.core.databinding.observable.value.IObservableValue; +import org.eclipse.core.databinding.property.INativePropertyListener; +import org.eclipse.core.databinding.property.ISimplePropertyListener; +import org.eclipse.core.databinding.property.value.SimpleValueProperty; + +/** + * @since 3.3 + * + */ +public final class ValidationStatusProviderValidationStatusProperty extends + SimpleValueProperty { + public Object getValueType() { + return IObservableValue.class; + } + + protected Object doGetValue(Object source) { + return ((ValidationStatusProvider) source).getValidationStatus(); + } + + protected void doSetValue(Object source, Object value) { + // no setter API + } + + public INativePropertyListener adaptListener( + ISimplePropertyListener listener) { + // no listener API + return null; + } + + protected void doAddListener(Object source, INativePropertyListener listener) { + } + + protected void doRemoveListener(Object source, + INativePropertyListener listener) { + } + + public String toString() { + return "ValidationStatusProvider#validationStatus <IObservableValue>"; //$NON-NLS-1$ + } +}
\ No newline at end of file diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/property/value/ObservableValueProperty.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/property/value/ObservableValueProperty.java new file mode 100644 index 00000000..990d9636 --- /dev/null +++ b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/property/value/ObservableValueProperty.java @@ -0,0 +1,99 @@ +/******************************************************************************* + * 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 263709) + ******************************************************************************/ + +package org.eclipse.core.internal.databinding.property.value; + +import org.eclipse.core.databinding.observable.Realm; +import org.eclipse.core.databinding.observable.value.IObservableValue; +import org.eclipse.core.databinding.observable.value.IValueChangeListener; +import org.eclipse.core.databinding.observable.value.ValueChangeEvent; +import org.eclipse.core.databinding.property.INativePropertyListener; +import org.eclipse.core.databinding.property.ISimplePropertyListener; +import org.eclipse.core.databinding.property.SimplePropertyEvent; +import org.eclipse.core.databinding.property.value.SimpleValueProperty; + +/** + * @since 3.3 + * + */ +/* + * This class extends SimpleValueProperty rather than ValueProperty so make it + * easy to observe multiple IObservableValues, for example an IObservableList of + * IObservableValues. In the simple case of observe(Object) or + * observeDetail(IObservableValue) we just cast the source object to + * IObservableValue and return it. + */ +public class ObservableValueProperty extends SimpleValueProperty { + private final Object valueType; + + /** + * @param valueType + */ + public ObservableValueProperty(Object valueType) { + this.valueType = valueType; + } + + public Object getValueType() { + return valueType; + } + + protected Object doGetValue(Object source) { + return ((IObservableValue) source).getValue(); + } + + protected void doSetValue(Object source, Object value) { + ((IObservableValue) source).setValue(value); + } + + public INativePropertyListener adaptListener( + ISimplePropertyListener listener) { + return new Listener(listener); + } + + private class Listener implements INativePropertyListener, + IValueChangeListener { + private final ISimplePropertyListener listener; + + Listener(ISimplePropertyListener listener) { + this.listener = listener; + } + + public void handleValueChange(ValueChangeEvent event) { + listener + .handlePropertyChange(new SimplePropertyEvent(event + .getObservable(), ObservableValueProperty.this, + event.diff)); + } + } + + protected void doAddListener(Object source, INativePropertyListener listener) { + ((IObservableValue) source) + .addValueChangeListener((IValueChangeListener) listener); + } + + protected void doRemoveListener(Object source, + INativePropertyListener listener) { + ((IObservableValue) source) + .removeValueChangeListener((IValueChangeListener) listener); + } + + public IObservableValue observe(Realm realm, Object source) { + // Ignore realm if different + return (IObservableValue) source; + } + + public String toString() { + String result = "IObservableValue#value"; //$NON-NLS-1$ + if (valueType != null) + result += " <" + valueType + ">"; //$NON-NLS-1$ //$NON-NLS-2$ + return result; + } +}
\ No newline at end of file |