Project: Eclipse_Platform_UI
Bug 123375 [DataBinding] Enhancements to the data binding framework
Reported: 2006-01-10 23:18:37 | Status: verified fixed

My team has developed a library with some similarities to the data binding framework. I've been investigating what is required to adopt the data binding framework without losing any features. We don't actually need the data binding or validation part. We need standardized interfaces for trees, sets, lists, and scalars that fire change notifications, and utilities and content providers to work with them. Although this isn't the main focus of the framework, there is a subset of the framework that comes very close to giving us what we need. I've prepared a patch that refactors the framework to add the features we need. Nick has approved the features in principle, and Boris has approved an initial version of the API. However, since David is most active in the code right now I've filed this bug to get his feedback. Requirements: - Need read-only interfaces for sets, lists, trees, and scalars that fire change notifications. - Asynchronous support. Updatables need to be able to indicate that their value is currently being recomputed asynchronously and will change soon. Needed for progress and busy affordances. - Support for "updatable functions". An updatable function is a transformation from one object to another where the transformation may change over time. - Library of set operations. Require: - union (a set consisting of elements from a set of sets) - list-to-set conversion - set transformation (takes a set and an updatable function as input, produces a new set consisting of the function applied to all elements in the original set) - Require standard content providers and label providers that can be instantiated directly and can use the above data types. - The tree interface needs to make it easy to reuse a set as one level in a tree. - Need to be able to instrument calls to IUpdatable getters. We use this to automatically compute dependencies and attach listeners. Changes made by the patch: - Implements the requirements (above). - Renames the existing writable IUpdatable interfaces to IWritableUpdatable* to distinguish them from the read-only versions. The writable ones extend the read-only ones. - Adds a greedyExec utility. This is similar to SWT's asyncExec, but it reduces flicker by running the runnable before the next repaint rather than at the end of the event queue. Also added runOnce, which ensures that a runnable will run before the next repaint and only run once. Replaced asyncExecs with greedyExecs and runOnces. - (optional) Adds ControlUpdator and ComputableValue utility classes. These make use of the instrumented getters to automatically attach and detach listeners. Boris suggested this pattern awile back and I thought it was brilliant so added it. If anyone has objections, they can be pulled out from the API and I can just use them for my own code. This is the extent of the patch. However, I have some additional suggestions which I did not implement, but would like to mention before they're forgotten: - Suggestion: remove getType(). I often need to wrap data structures that do not supply this information, where computing it would require extra plugin activation, or where the code for determining the types would double the code size of the updatable. For this reason, I couldn't include getType on the new read-only interfaces. Since implementers of the writable interfaces are likely to hit the same problems, I would strongly recommend that the remainder of the library discard this pattern as well. It looks like it is only necessary for locating the correct conversions. If conversion lookups used instanceof or isAssignableTo rather than identity comparisons, then the java types of the elements would be enough and this method could be removed. - Suggestion: make the IUpdatable implementations API. The data binding library has a lot of useful IUpdatable implementations that convert a wide variety of data types into standard data structures. However, creating them requires a lot of context (you need a BindingContext, a factory, and a Property first). It is clear that the factory has benefits for WYSIWIG editors and data-driven UIs. But for those of us who are using them programmatically, it would be a lot easier to say "new CComboUpdatableValue(myCombo, SWTProperties.TEXT)". These classes are too useful to be internal. (Make them final, though). - Suggestion: Remove ChangeEvent.getParent(). With the ITreeProvider in the patch, it is not necessary. - Suggestion: Remove one of the writable tree variants (ITree and IUpdatableTree. I've renamed them to IWritableTree and IWritableUpdatable tree respectively in my patch). Remove the getters from the remaining tree interface and make it extend the read-only ITreeProvider interface. This will permit utilities that understand the read-only version to work with the writable one.

Files changed in fix:
bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/databinding/AbstractUpdatableSet.java bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/databinding/ChangeEvent.java bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/databinding/ILazyReadableValue.java bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/databinding/IReadable.java bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/databinding/IReadableList.java bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/databinding/IReadableSet.java bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/databinding/IReadableValue.java bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/databinding/ITree.java bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/databinding/ITreeProvider.java bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/databinding/IUpdatable.java bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/databinding/IUpdatableCollection.java bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/databinding/IUpdatableFunction.java bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/databinding/IUpdatableFunctionFactory.java bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/databinding/IUpdatableTree.java bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/databinding/IUpdatableValue.java bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/databinding/Updatable.java bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/databinding/UpdatableCollection.java bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/databinding/UpdatableTracker.java bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/databinding/UpdatableValue.java bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/databinding/WritableUpdatable.java bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/databinding/swt/ControlUpdator.java bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/databinding/updatables/CalculatedValue.java bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/databinding/updatables/ComputedValue.java bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/databinding/updatables/ConditionalUpdatableValue.java bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/databinding/updatables/ConvertingSet.java bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/databinding/updatables/EmptyReadableSet.java bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/databinding/updatables/IdentityFunction.java bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/databinding/updatables/InverseMapping.java bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/databinding/updatables/ListToSetAdapter.java bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/databinding/updatables/SettableList.java bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/databinding/updatables/SettableValue.java bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/databinding/updatables/UnionSet.java bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/databinding/updatables/UpdatableFunction.java bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/databinding/updatables/WritableSet.java bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/databinding/viewers/DirtyIndicationLabelProvider.java bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/databinding/viewers/ListeningLabelProvider.java bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/databinding/viewers/UpdatableSetContentProvider.java bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/databinding/viewers/UpdatableTreeContentProvider.java bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/databinding/viewers/ViewerLabelProvider.java bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/CollectionBinding.java bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/ListUpdatableCollection.java bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/NestedUpdatableCollection.java bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/NestedUpdatableTree.java bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/NestedUpdatableValue.java bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/TreeBinding.java bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/ValueBinding.java bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/beans/CopyOfJavaBeanUpdatableCollection.java bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/beans/JavaBeanUpdatableCollection.java bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/beans/JavaBeanUpdatableTree.java bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/beans/JavaBeanUpdatableValue.java bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/swt/AsyncRunnable.java bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/swt/ButtonUpdatableValue.java bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/swt/CComboUpdatableCollection.java bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/swt/CComboUpdatableValue.java bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/swt/ComboUpdatableCollection.java bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/swt/ComboUpdatableValue.java bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/swt/ControlUpdatableValue.java bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/swt/LabelUpdatableValue.java bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/swt/ListUpdatableCollection.java bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/swt/ListUpdatableValue.java bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/swt/SWTUtil.java bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/swt/SpinnerUpdatableValue.java bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/swt/TableUpdatableValue.java bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/swt/TextUpdatableValue.java bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/swt/WorkQueue.java bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/viewers/StructuredViewerUpdatableValue.java bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/viewers/TableViewerUpdatableCollection.java bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/viewers/TreeViewerUpdatableTree.java bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/viewers/UpdatableCollectionViewer.java examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/contentprovider/test/AsynchronousTestSet.java examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/contentprovider/test/LabelProviderTest.java examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/contentprovider/test/RenamableItem.java examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/contentprovider/test/SimpleNode.java examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/contentprovider/test/SomeMathFunction.java examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/contentprovider/test/StructuredContentProviderTest.java examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/contentprovider/test/TreeContentProviderTest.java examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/model/AggregateUpdatableValue.java examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/layout/GridDataFactory.java examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/layout/GridLayoutFactory.java examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/layout/LayoutConstants.java examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/layout/LayoutGenerator.java tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/databinding/SelectionAwareUpdatableCollectionTest.java tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/databinding/UpdatableCollectionTest.java tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/BindingTestSuite.java tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/DatabindingContextTest.java tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/UpdatableTest.java tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/scenarios/MasterDetailScenarios.java tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/scenarios/UpdatableFactoriesTest.java tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/util/Mocks.java