Chapter 3. Creating JFace Viewers

In the last chapter, we looked at the basic building blocks of SWT, which provide a glue layer between the native operating system's widgets and Java. We'll now look at JFace, which builds upon SWT to provide an MVC architecture as well as many of the common widgets used by Eclipse.

In this chapter we will cover:

  • Creating a view for showing hierarchical data
  • Using image, font, and color resources
  • Generating styled text
  • Sorting and filtering entries in viewers
  • Adding double-click actions
  • Selections and property support
  • Creating a view for showing tabular data

Why JFace?

While SWT provides generic implementations for basic widgets (such as trees, buttons, labels, and so on), these often work at a level that deals with strings and responding to selection by integer index. To make it easier to display structured content, JFace provides several viewers, which provide combinations of SWT widgets and event managers to provide a UI for structured content.

There are many types of viewers (all subclasses of Viewer), but the most common ones are ContentViewers such as the TreeViewer and TableViewer . There are also text-based viewers (TextViewer has subclasses for SourceViewer ) as well as operational views (ConsoleViewer for the Console view, DetailedProgressViewer for the Progress view). In this chapter, we'll create views based on TreeViewer and TableViewer. Since JFace is based on SWT, knowing how SWT works is essential to understand how JFace is used.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset