Jump to: navigation, search

Difference between revisions of "FAQ What is a viewer?"

 
m (added image, no thumbnail support set up?)
 
Line 1: Line 1:
The purpose of a viewer is to simplify the interaction between an underlying
+
The purpose of a viewer is to simplify the interaction between an underlying model and the widgets  used to present elements of that model. A viewer is not used as a high-level replacement for an SWT widget but  as an adapter that sits beside an SWT widget and automates some of the more mundane widget-manipulation tasks, such as adding and removing items, sorting, filtering, and refreshing.
model and the widgets  used to present elements of that model. A viewer is
+
not used as a high-level replacement for an SWT widget but  as an
+
adapter that sits beside an SWT widget and automates some of the more
+
mundane widget-manipulation tasks, such as adding and removing items, sorting,
+
filtering, and refreshing.
+
  
 +
A viewer is created by first creating an SWT widget, constructing the viewer on that widget, and then setting its content provider, label provider, and input.  This snippet is from the <tt>BooksView</tt> class in the FAQ Examples plug-in, which creates a table viewer to display a library of books:
  
 
A viewer is created by first creating an SWT widget,
 
constructing the viewer on that widget, and then setting its content provider,
 
label provider, and input.  This snippet is from the <tt>BooksView</tt> class
 
in the FAQ Examples plug-in, which creates a table viewer to display a library
 
of books:
 
 
<pre>
 
<pre>
 
   int style = SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL;
 
   int style = SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL;
Line 22: Line 12:
 
</pre>
 
</pre>
  
 +
In general, JFace viewers allow you to create a model-view-controller (MVC) architecture.  The view is the underlying SWT widget, the model is specified by the framework user, and the JFace viewer and its associated components form the controller. The viewer input is a model element that seeds the population of the viewer.
  
 +
[[Image:Package explorer.jpg|frame|right|JDT Package Explorer]]
  
In general, JFace viewers allow you to create a model-view-controller (MVC)
+
The JDT Package Explorer uses a <tt>TreeViewer</tt> to display the contents of a workspace, represented as a <tt>JavaModel</tt>.
architecture.  The view is the underlying SWT widget, the
+
model is specified by the framework user, and the JFace viewer and its associated
+
components form the controller. The viewer input is a model element that seeds
+
the population of the viewer.
+
 
+
 
+
 
+
The JDT Package Explorer uses a <tt>TreeViewer</tt> to display the  
+
contents of a workspace, represented as a <tt>JavaModel</tt>.  
+
The UI manifests itself as shown in Figure 8.1.
+
 
+
 
+
 
+
&nbsp;&nbsp;&nbsp;&nbsp;<img src="../images/sampleclass.png">
+
 
+
 
+
&nbsp;&nbsp;&nbsp;&nbsp;'''Figure 8.1'''&nbsp;&nbsp;
+
Package Explorer showing the workspace contents
+
 
+
 
+
 
+
The corresponding Spider diagram (Figure 8.2) shows the relationships
+
among the Package Explorer, its viewer, its model, the underlying widget,
+
and the label and content providers for the JDT Package Explorer.
+
 
+
  
 +
The corresponding Spider diagram (Figure 8.2) shows the relationships  among the Package Explorer, its viewer, its model, the underlying widget,  and the label and content providers for the JDT Package Explorer.
  
 
&nbsp;&nbsp;&nbsp;&nbsp;<img src="../images/ViewerModel.png" width=547>
 
&nbsp;&nbsp;&nbsp;&nbsp;<img src="../images/ViewerModel.png" width=547>
 
+
&nbsp;&nbsp;&nbsp;&nbsp;'''Figure 8.2'''&nbsp;&nbsp; Spider diagram of Package Explorer components
 
+
&nbsp;&nbsp;&nbsp;&nbsp;'''Figure 8.2'''&nbsp;&nbsp;
+
Spider diagram of Package Explorer components
+
 
+
 
+
 
+
 
+
 
+
 
+
 
+
 
+
  
 
== See Also: ==
 
== See Also: ==
 +
*[[FAQ What are content and label providers?]]
 +
*[[FAQ How do I sort the contents of a viewer?]]
 +
*[[FAQ How do I filter the contents of a viewer?]]
 +
*[[FAQ What is a view?]]
 +
*[[FAQ What is the difference between a view and a viewer?]]
  
 
+
{{Template:FAQ_Tagline}}
[[FAQ_What_are_content_and_label_providers%3F]]
+
 
+
 
+
[[FAQ_How_do_I_sort_the_contents_of_a_viewer%3F]]
+
 
+
 
+
[[FAQ_How_do_I_filter_the_contents_of_a_viewer%3F]]
+
 
+
 
+
[[FAQ_What_is_a_view%3F]]
+
 
+
 
+
[[FAQ_What_is_the_difference_between_a_view_and_a_viewer%3F]]
+
 
+
<hr><font size=-2>This FAQ was originally published in [http://www.eclipsefaq.org Official Eclipse 3.0 FAQs]. Copyright 2004, Pearson Education, Inc. All rights reserved. This text is made available here under the terms of the [http://www.eclipse.org/legal/epl-v10.html Eclipse Public License v1.0].</font>
+

Latest revision as of 21:37, 29 May 2006

The purpose of a viewer is to simplify the interaction between an underlying model and the widgets used to present elements of that model. A viewer is not used as a high-level replacement for an SWT widget but as an adapter that sits beside an SWT widget and automates some of the more mundane widget-manipulation tasks, such as adding and removing items, sorting, filtering, and refreshing.

A viewer is created by first creating an SWT widget, constructing the viewer on that widget, and then setting its content provider, label provider, and input. This snippet is from the BooksView class in the FAQ Examples plug-in, which creates a table viewer to display a library of books:

   int style = SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL;
   Table table = new Table(parent, style);
   TableViewer viewer = new TableViewer(table);
   viewer.setContentProvider(new BookshelfContentProvider());
   viewer.setLabelProvider(new BookshelfLabelProvider());
   viewer.setInput(createBookshelf());

In general, JFace viewers allow you to create a model-view-controller (MVC) architecture. The view is the underlying SWT widget, the model is specified by the framework user, and the JFace viewer and its associated components form the controller. The viewer input is a model element that seeds the population of the viewer.

JDT Package Explorer

The JDT Package Explorer uses a TreeViewer to display the contents of a workspace, represented as a JavaModel.

The corresponding Spider diagram (Figure 8.2) shows the relationships among the Package Explorer, its viewer, its model, the underlying widget, and the label and content providers for the JDT Package Explorer.

    <img src="../images/ViewerModel.png" width=547>     Figure 8.2   Spider diagram of Package Explorer components

See Also:


This FAQ was originally published in Official Eclipse 3.0 FAQs. Copyright 2004, Pearson Education, Inc. All rights reserved. This text is made available here under the terms of the Eclipse Public License v1.0.