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 124747 Details for
Bug 262407
[DataBinding] Option to specify default values for DuplexingObservableValue instead of subclassing
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
Patch
clipboard.txt (text/plain), 8.33 KB, created by
Matthew Hall
on 2009-02-04 19:27:55 EST
(
hide
)
Description:
Patch
Filename:
MIME Type:
Creator:
Matthew Hall
Created:
2009-02-04 19:27:55 EST
Size:
8.33 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.jface.tests.databinding >Index: src/org/eclipse/core/tests/databinding/observable/value/DuplexingObservableValueTest.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/databinding/observable/value/DuplexingObservableValueTest.java,v >retrieving revision 1.1 >diff -u -r1.1 DuplexingObservableValueTest.java >--- src/org/eclipse/core/tests/databinding/observable/value/DuplexingObservableValueTest.java 26 Jan 2009 17:06:38 -0000 1.1 >+++ src/org/eclipse/core/tests/databinding/observable/value/DuplexingObservableValueTest.java 5 Feb 2009 00:26:00 -0000 >@@ -7,19 +7,18 @@ > * > * Contributors: > * Matthew Hall - initial API and implementation (bug 173735) >+ * Matthew Hall - bug 262407 > *******************************************************************************/ > > package org.eclipse.core.tests.databinding.observable.value; > > import java.util.ArrayList; > import java.util.Collection; >-import java.util.Iterator; > > import org.eclipse.core.databinding.observable.list.IObservableList; > import org.eclipse.core.databinding.observable.list.WritableList; > import org.eclipse.core.databinding.observable.value.DuplexingObservableValue; > import org.eclipse.jface.tests.databinding.AbstractDefaultRealmTestCase; >-import org.eclipse.jface.util.Util; > > /** > * @since 1.0 >@@ -56,20 +55,8 @@ > } > > public void test_getValue() throws Exception { >- observable = new DuplexingObservableValue(list) { >- protected Object coalesceElements(Collection elements) { >- Iterator it = elements.iterator(); >- if (!it.hasNext()) >- return null; >- Object first = it.next(); >- while (it.hasNext()) { >- Object next = it.next(); >- if (!Util.equals(first, next)) >- return "<Multiple Values>"; >- } >- return first; >- } >- }; >+ observable = DuplexingObservableValue.withDefaults(list, null, >+ "<Multiple Values>"); > assertNull(observable.getValue()); > list.add("42"); > assertEquals("Value should be \"42\"", "42", observable.getValue()); >#P org.eclipse.jface.examples.databinding >Index: src/org/eclipse/jface/examples/databinding/snippets/Snippet028DuplexingObservableValue.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet028DuplexingObservableValue.java,v >retrieving revision 1.1 >diff -u -r1.1 Snippet028DuplexingObservableValue.java >--- src/org/eclipse/jface/examples/databinding/snippets/Snippet028DuplexingObservableValue.java 26 Jan 2009 17:06:31 -0000 1.1 >+++ src/org/eclipse/jface/examples/databinding/snippets/Snippet028DuplexingObservableValue.java 5 Feb 2009 00:26:01 -0000 >@@ -7,14 +7,13 @@ > * > * Contributors: > * Matthew Hall - initial API and implementation (bug 175735) >+ * Matthew Hall - bug 262407 > ******************************************************************************/ > > package org.eclipse.jface.examples.databinding.snippets; > > import java.beans.PropertyChangeListener; > import java.beans.PropertyChangeSupport; >-import java.util.Collection; >-import java.util.Iterator; > > import org.eclipse.core.databinding.DataBindingContext; > import org.eclipse.core.databinding.beans.BeanProperties; >@@ -28,7 +27,6 @@ > import org.eclipse.jface.databinding.viewers.ObservableListContentProvider; > import org.eclipse.jface.databinding.viewers.ObservableMapLabelProvider; > import org.eclipse.jface.databinding.viewers.ViewerProperties; >-import org.eclipse.jface.util.Util; > import org.eclipse.jface.viewers.StructuredSelection; > import org.eclipse.jface.viewers.TableViewer; > import org.eclipse.swt.SWT; >@@ -286,36 +284,20 @@ > IObservableList selections = ViewerProperties.multipleSelection() > .observe(viewer); > dbc.bindValue(WidgetProperties.text(SWT.Modify).observe(title), >- new StringDuplexingObservableValue(BeanProperties >- .value("title").observeDetail(selections))); >+ DuplexingObservableValue.withDefaults(BeanProperties.value( >+ "title").observeDetail(selections), "", >+ "<Multiple titles>")); > dbc.bindValue(WidgetProperties.text(SWT.Modify).observe(releaseDate), >- new StringDuplexingObservableValue(BeanProperties.value( >- "releaseDate").observeDetail(selections))); >+ DuplexingObservableValue.withDefaults(BeanProperties.value( >+ "releaseDate").observeDetail(selections), "", >+ "<Multiple dates>")); > dbc.bindValue(WidgetProperties.text(SWT.Modify).observe(director), >- new StringDuplexingObservableValue(BeanProperties.value( >- "director").observeDetail(selections))); >+ DuplexingObservableValue.withDefaults(BeanProperties.value( >+ "director").observeDetail(selections), "", >+ "<Multiple directors>")); > dbc.bindValue(WidgetProperties.text(SWT.Modify).observe(writer), >- new StringDuplexingObservableValue(BeanProperties.value( >- "writer").observeDetail(selections))); >- } >- >- private static class StringDuplexingObservableValue extends >- DuplexingObservableValue { >- >- public StringDuplexingObservableValue(IObservableList target) { >- super(target); >- } >- >- protected Object coalesceElements(Collection elements) { >- Iterator it = elements.iterator(); >- if (!it.hasNext()) >- return ""; >- Object first = it.next(); >- while (it.hasNext()) { >- if (!Util.equals(first, it.next())) >- return "<Multiple values>"; >- } >- return first; >- } >+ DuplexingObservableValue.withDefaults(BeanProperties.value( >+ "writer").observeDetail(selections), "", >+ "<Multiple writers>")); > } > } >#P org.eclipse.core.databinding >Index: src/org/eclipse/core/databinding/observable/value/DuplexingObservableValue.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/value/DuplexingObservableValue.java,v >retrieving revision 1.1 >diff -u -r1.1 DuplexingObservableValue.java >--- src/org/eclipse/core/databinding/observable/value/DuplexingObservableValue.java 26 Jan 2009 17:06:32 -0000 1.1 >+++ src/org/eclipse/core/databinding/observable/value/DuplexingObservableValue.java 5 Feb 2009 00:26:02 -0000 >@@ -7,22 +7,56 @@ > * > * Contributors: > * Matthew Hall - initial API and implementation (bug 175735) >+ * Matthew Hall - bug 262407 > ******************************************************************************/ > > package org.eclipse.core.databinding.observable.value; > > import java.util.Collection; >+import java.util.Iterator; > > import org.eclipse.core.databinding.observable.ChangeEvent; > import org.eclipse.core.databinding.observable.IChangeListener; > import org.eclipse.core.databinding.observable.IStaleListener; > import org.eclipse.core.databinding.observable.StaleEvent; > import org.eclipse.core.databinding.observable.list.IObservableList; >+import org.eclipse.core.internal.databinding.Util; > > /** > * @since 1.2 > */ > public abstract class DuplexingObservableValue extends AbstractObservableValue { >+ /** >+ * Returns a DuplexingObservableValue implementation with predefined values >+ * to use if the list is empty or contains multiple different values. >+ * >+ * @param target >+ * the observable list >+ * @param emptyValue >+ * the value to use when the target list is empty >+ * @param multiValue >+ * the value to use when the target list contains multiple values >+ * that are not equivalent to eachother. >+ * @return a DuplexingObservableValue implementation with predefined values >+ * to use if the list is empty or contains multiple different >+ * values. >+ */ >+ public static DuplexingObservableValue withDefaults(IObservableList target, >+ final Object emptyValue, final Object multiValue) { >+ return new DuplexingObservableValue(target) { >+ protected Object coalesceElements(Collection elements) { >+ if (elements.isEmpty()) >+ return emptyValue; >+ Iterator it = elements.iterator(); >+ Object first = it.next(); >+ while (it.hasNext()) >+ if (!Util.equals(first, it.next())) >+ return multiValue; >+ return first; >+ } >+ }; >+ } >+ > private IObservableList target; > private final Object valueType; >
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 262407
: 124747 |
124748