Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does JFace add to SWT?

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!

like image 290
Reddy Avatar asked Feb 26 '11 07:02

Reddy


People also ask

What is JFace in Java?

JFace is defined by the Eclipse project as "a UI toolkit that provides helper classes for developing UI features that can be tedious to implement." The Standard Widget Toolkit (SWT) is an open source widget toolkit for Java designed to provide efficient, portable access to the user-interface facilities of the operating ...

What is org Eclipse JFace?

eclipse. jface. text. Provides a framework for creating and manipulating text documents.


1 Answers

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"
like image 60
Alain Pannetier Avatar answered Oct 08 '22 12:10

Alain Pannetier