Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 74368 - [Viewers] TableViewer: Default providers needed
Summary: [Viewers] TableViewer: Default providers needed
Status: RESOLVED DUPLICATE of bug 104570
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.0   Edit
Hardware: PC All
: P4 enhancement (vote)
Target Milestone: ---   Edit
Assignee: Boris Bokowski CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on: 21284
Blocks:
  Show dependency tree
 
Reported: 2004-09-20 16:13 EDT by David J. Orme CLA
Modified: 2005-09-28 12:02 EDT (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description David J. Orme CLA 2004-09-20 16:13:54 EDT
The existing JFace architecture is very flexible for presenting and editing all
kinds of data.  However, this flexibility comes at a price: one must currently
write quite a bit of code in order to implement a TableViewer or a TreeViewer in
their application.  However, it is important that any solution to this problem
gain convenience without losing flexibility or dropping backward compatibility
with the existing implementation.

In this bug report, I propose to enhance the existing viewer framework by
including a standard set of Providers that use reflection to marshall and
unmarshall their data.

The existing viewer framework is remarkable in its flexibility.  One can use it
to edit literally any model that one can imagine, even those that don't natively
conform to the structure that the viewer would naturally expect.  That is, by
writing an appropriate content provider, one could use a JFace TableViewer to
edit search results, or to display aggregated totals.

The following classes and interfaces are used by JFace to generically access,
display, and edit arbitrary data structures:

* CellEditor
* ICellModifier
* IBaseLabelProvider
* IContentProvider

I contend that it is possible to provide reasonable default implementations for
all of the interfaces as well as a factory class that can use java.lang.Reflect
to analyze a Java data structure and produce a reasonable viewer instance for
editing 80% of Java data structures without writing additional code.

The remainder of this essay will describe the general strategy I would recommend:

I will work from the following assumptions:

1) The user wants to edit 80% of the cases as easily as possible.

2) The user will work with either a factory class that contains methods:

* allowing the user to set a model object to edit
* allowing the user to specify the attributes of each object to edit.
* allowing the user to generate from these specifications a TableViewer,
TreeViewer, etc., that can edit the specified collection according to her
specifications.

We will do this as follows:

Most editing work involves using some Iterator or ListIterator to edit the
contents of a collection.  We don't care what kind of collection it is or where
its data came from, we just care that we can reasonably iterate over its
contents.  We also don't care about how the data is persisted.  Java object
persistence frameworks have been popping up like mushrooms after a rain lately,
and most projects have already adopted one.  So if we can limit the scope of the
problem to editing data that is stored in a plain old Java object (POJO), we can
solve what 80% of people want with 20% of the effort.

In addition, this approach enables the ListIterator interface to be used as a
wrapper interface for all sorts of data that isn't natively in a list format,
such as JDBC database data or Map data.  If you can implement a ListIterator
over your data, you can edit it.

Based on this understanding, one can implement a generic ContentProvider,
CellModifier and LabelProvider that will use Java reflection to return a
collection to edit and actually perform the editing.  One can also implement a
factory object as described above that can specify the attributes of a
collection's objects to edit, and can actually create a TableViewer that can
edit a collection with those attributes with CellEditors in the right places, etc.
Comment 1 David J. Orme CLA 2004-09-20 16:41:00 EDT
I didn't cover how to get the Iterator or ListIterator from the model object.  I
would recommend following the conventions of the Java collections framework. 
Just use reflection to look for a listIterator() or iterator() method and call
it.  The document that clients have to implement this method if they want to be
edited using a JFace Viewer.
Comment 2 David J. Orme CLA 2004-09-20 16:42:16 EDT
re: comment #1

s/JFace Viewer/JFace Viewer Factory/;

Comment 3 Dave Orme CLA 2005-09-28 11:07:11 EDT
Suggest we mark this as a dupe of bug 104570
Comment 4 Boris Bokowski CLA 2005-09-28 12:02:25 EDT
Sure!

*** This bug has been marked as a duplicate of 104570 ***