What does JFace add to SWT?
What is the difference betweem the following:
- TreeViewer & Tree
- TableViewer & Table
- TreeViewerColumn & TreeColumn
- TableViewerColumn & TableColumn
When to use viewer & regular widget?
PS: It would a great help if you can help me find a good resource for understanding them开发者_StackOverflow.Thanks in advance!
You could have titled your question "What does JFace add to SWT ?".
Viewers are from JFace, Widgets are from SWT.
In summary, JFace make Widgets easy to manipulate and insert into a GUI. JFace frees you from all the drudgery of manipulating SWT widget elements to add behaviour to static widgets. SWT just provides listeners, JFace uses these listeners for you to allow you to concentrate on the mapping between the real world model and its SWT representation.
Let's see that on the specific examples you've listed.
If you build a standard SWT widget, you will have to describe the content of a Tree (set one or more top items, hook some TreeItems to each root, possibly add a selection listener) and then manage all its transitions. That Tree will have very little built in logic: just collapse/expand and selection listeners. Period.
That will be a static Tree.
A TreeViewer will allow you to inject many different kinds of behaviours in that Tree: How it is populated, filtered, how the TreeItems are labelled.
You will do that by registering classes satisfying to well specified interfaces (for instance the ILabelProvider will allow you to map a TreeItem label to a file name in a folder).
Without the TreeViewer, building a decent responsive tree would be a lot of hard work. In summary, it makes it easy to map the underlying real world hierarchical model to the SWT Tree representation.The same holds true for a TableViewer. A TableViewer allows you to add some custom behaviour to your table. How do you edit a cell for instance.
TreeViewerColumn. A long time ago (before 3.3), SWT Trees did not have columns. Trees did not have Columns Tables had columns but they did not expand/colapse. Since 3.3 you can add columns to a Tree. You do this better with by adding a TreeViewerColumn to your TreeViewer rather than by just adding a TreeColumn to a Tree (which you still have to do) for reasons similar to the ones above, you can add support for editing the content of the column cells and you can populate the column (by writing a Label Provider again).
TableViewerColumn. Same thing for TableViewers : adds edition and content management.
For SWT/JFace doc, please have a look at.
Viewers belonging to JFace not to SWT proper, to go forward, look up JFace tutorials on google and you'll find a lot of examples.
Steve Northover's book (the father SWT) "SWT: The Standard Widget Toolkit, Volume 1" (AFAIK there's no second volume yet).
"Eclipse: Building Commercial-Quality Plug-ins" by Eric Clayberg and Dan Rube. Eric is now a Google VP and the father of WindowBuilder Pro
The SWT snippets are also a fast-track to mastering SWT objects.
Other good books include
- "The Definitive Guide to SWT and JFace" by Rob Warner and Robert Harris
- "Manning's SWT/JFAce in action"
精彩评论