What does JFace add to SWT?

懵懂的女人 提交于 2019-12-03 08:56:50

问题


What is the difference betweem the following:

  1. TreeViewer & Tree
  2. TableViewer & Table
  3. TreeViewerColumn & TreeColumn
  4. 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.Thanks in advance!


回答1:


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.

  1. 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.

  2. 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.

  3. 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).

  4. TableViewerColumn. Same thing for TableViewers : adds edition and content management.

For SWT/JFace doc, please have a look at.

  1. 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.

  2. Steve Northover's book (the father SWT) "SWT: The Standard Widget Toolkit, Volume 1" (AFAIK there's no second volume yet).

  3. "Eclipse: Building Commercial-Quality Plug-ins" by Eric Clayberg and Dan Rube. Eric is now a Google VP and the father of WindowBuilder Pro

  4. The SWT snippets are also a fast-track to mastering SWT objects.

  5. Other good books include

    • "The Definitive Guide to SWT and JFace" by Rob Warner and Robert Harris
    • "Manning's SWT/JFAce in action"


来源:https://stackoverflow.com/questions/5125584/what-does-jface-add-to-swt

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!