Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 85334 Details for
Bug 212518
[DataBinding] ConstantObservableValue contribution
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
Immutable constant/static value observable
ConstantValue3.patch (text/plain), 7.33 KB, created by
Matt Carter
on 2007-12-15 11:27:34 EST
(
hide
)
Description:
Immutable constant/static value observable
Filename:
MIME Type:
Creator:
Matt Carter
Created:
2007-12-15 11:27:34 EST
Size:
7.33 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.core.databinding >Index: src/org/eclipse/core/databinding/observable/Observables.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/Observables.java,v >retrieving revision 1.3 >diff -u -r1.3 Observables.java >--- src/org/eclipse/core/databinding/observable/Observables.java 22 Nov 2007 21:56:15 -0000 1.3 >+++ src/org/eclipse/core/databinding/observable/Observables.java 15 Dec 2007 16:27:02 -0000 >@@ -7,6 +7,7 @@ > * > * Contributors: > * Brad Reynolds - initial API and implementation >+ * Matt Carter - Bug 212518 - Static value observable > ******************************************************************************/ > > package org.eclipse.core.databinding.observable; >@@ -21,6 +22,7 @@ > import org.eclipse.core.databinding.observable.set.ISetChangeListener; > import org.eclipse.core.databinding.observable.set.ObservableSet; > import org.eclipse.core.databinding.observable.value.IObservableValue; >+import org.eclipse.core.internal.databinding.observable.ConstantValue; > import org.eclipse.core.internal.databinding.observable.EmptyObservableList; > import org.eclipse.core.internal.databinding.observable.EmptyObservableSet; > import org.eclipse.core.internal.databinding.observable.ProxyObservableSet; >@@ -126,6 +128,68 @@ > } > > /** >+ * Returns a constant observable value which can be observed but on which >+ * set operations will fail. >+ * >+ * @param realm >+ * @param value >+ * static value for this observable >+ * @param type >+ * @return constant value observable >+ */ >+ public static IObservableValue staticObservableValue(Realm realm, >+ Object value, Class type) { >+ return new ConstantValue(realm, value, type); >+ } >+ >+ /** >+ * Returns a constant observable value which can be observed but on which >+ * set operations will fail. >+ * >+ * @note It is recommended that you use a version of this method which >+ * accepts a type argument and explicitly specify the type when it is >+ * known. This method will use a type of Object.class. >+ * >+ * @param realm >+ * @param value >+ * static value for this observable >+ * @return constant value observable >+ */ >+ public static IObservableValue staticObservableValue(Realm realm, Object value) { >+ return new ConstantValue(realm, value, Object.class); >+ } >+ >+ /** >+ * Returns a constant observable value which can be observed but on which >+ * set operations will fail. >+ * >+ * @param value >+ * static value for this observable >+ * @param type >+ * @return constant value observable >+ */ >+ public static IObservableValue staticObservableValue(Object value, >+ Class type) { >+ return new ConstantValue(value, type); >+ } >+ >+ /** >+ * Returns a constant observable value which can be observed but on which >+ * set operations will fail. >+ * >+ * @note It is recommended that you use a version of this method which >+ * accepts a type argument and explicitly specify the type when it is >+ * known. This method will use a type of Object.class. >+ * >+ * @param value >+ * static value for this observable >+ * @return constant value observable >+ */ >+ public static IObservableValue staticObservableValue(Object value) { >+ return new ConstantValue(value, Object.class); >+ } >+ >+ /** > * Returns an observable set that contains the same elements as the given > * set, and fires the same events as the given set, but can be disposed of > * without disposing of the wrapped set. >Index: src/org/eclipse/core/internal/databinding/observable/ConstantValue.java >=================================================================== >RCS file: src/org/eclipse/core/internal/databinding/observable/ConstantValue.java >diff -N src/org/eclipse/core/internal/databinding/observable/ConstantValue.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/core/internal/databinding/observable/ConstantValue.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,123 @@ >+/******************************************************************************* >+ * Copyright (c) 2005, 2007 Matt Carter 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: >+ * Matt Carter - Initial API and implementation >+ * - Bug 212518 - Static value observable >+ *******************************************************************************/ >+package org.eclipse.core.internal.databinding.observable; >+ >+import org.eclipse.core.databinding.observable.IChangeListener; >+import org.eclipse.core.databinding.observable.IStaleListener; >+import org.eclipse.core.databinding.observable.ObservableTracker; >+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.WritableValue; >+import org.eclipse.core.runtime.Assert; >+import org.eclipse.core.runtime.AssertionFailedException; >+ >+/** >+ * Constant, read-only observable value which can be observed but not changed. >+ * >+ * @see WritableValue >+ */ >+public class ConstantValue implements IObservableValue { >+ >+ final Object type; >+ final Object object; >+ final Realm realm; >+ >+ /** >+ * Construct a constant value of the given type, in the default realm. >+ * @param object immutable value >+ * @param type type >+ */ >+ public ConstantValue(Object object, Object type) { >+ this.realm = Realm.getDefault(); >+ this.object = object; >+ this.type = type; >+ } >+ >+ /** >+ * Construct a constant value of the given type, in the given realm. >+ * @param realm Realm >+ * @param object immutable value >+ * @param type type >+ */ >+ public ConstantValue(Realm realm, Object object, Object type) { >+ Assert.isNotNull(realm); >+ this.realm = realm; >+ this.object = object; >+ this.type = type; >+ } >+ >+ public Object getValueType() { >+ return type; >+ } >+ >+ /** >+ * Returns the constant value. Must be invoked in the {@link Realm} of the observable. >+ * >+ * @return the constant value >+ * @TrackedGetter >+ */ >+ public Object getValue() { >+ checkRealm(); >+ ObservableTracker.getterCalled(this); >+ return object; >+ } >+ >+ public void setValue(Object value) { >+ throw new UnsupportedOperationException(); >+ } >+ >+ public void addValueChangeListener(IValueChangeListener listener) { >+ // ignore >+ } >+ >+ public void removeValueChangeListener(IValueChangeListener listener) { >+ // ignore >+ } >+ >+ public void addChangeListener(IChangeListener listener) { >+ // ignore >+ } >+ >+ public void addStaleListener(IStaleListener listener) { >+ // ignore >+ } >+ >+ public void dispose() { >+ // nothing to dispose >+ } >+ >+ public Realm getRealm() { >+ return realm; >+ } >+ >+ public boolean isStale() { >+ return false; >+ } >+ >+ public void removeChangeListener(IChangeListener listener) { >+ // ignore >+ } >+ >+ public void removeStaleListener(IStaleListener listener) { >+ // ignore >+ } >+ /** >+ * Asserts that the realm is the current realm. >+ * >+ * @see Realm#isCurrent() >+ * @throws AssertionFailedException if the realm is not the current realm >+ */ >+ protected void checkRealm() { >+ Assert.isTrue(getRealm().isCurrent()); >+ } >+}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 212518
:
84944
|
85041
|
85043
|
85094
|
85095
|
85100
| 85334 |
89221
|
89222