Chapter 7. ViewsMany plug-ins either add a new Eclipse view or enhance an existing one as a way to provide information to the user. This chapter covers creating a new view, modifying the view to respond to selections in the active editor or other views, and exporting the view's selection to the rest of Eclipse. In addition, it briefly touches on the differences between editors and views, and when one should be used instead of the other. Views must implement the org.eclipse.ui.IViewPart interface. Typically, views are subclasses of org.eclipse.ui.part.ViewPart and thus indirectly subclasses of org.eclipse.ui.part.WorkbenchPart, inheriting much of the behavior needed to implement the IViewPart interface (see Figure 7-1). Figure 7-1. ViewPart classes.Views are contained in a view site (an instance of the class, org.eclipse.ui.IViewSite), which in turn is contained in a workbench page (an instance of org.eclipse.ui.IWorkbenchPage). In the spirit of lazy initialization, the IWorkbenchPage instance holds on to instances of org.eclipse.ui.IViewReference rather than the view itself so that views can be enumerated and referenced without actually loading the plug-in that defines the view. Views share a common set of behaviors with editors via the superclass org.eclipse.ui.part.WorkbenchPart and the org.eclipse.ui. IWorkbenchPart interface but have some very important differences. Any action performed in a view should immediately affect the state of the workspace and the underlying resource(s), whereas editors follow the classic open-modify-save paradigm. Editors appear in one area of Eclipse, while views are arranged around the outside of the editor area (see Section 1.2.1, Perspectives, views, and editors, on page 5). Editors are typically resource-based, while views may show information about one resource, multiple resources, or even something totally unrelated to resources at all. Because there are potentially hundreds of views in the workbench, they are organized into categories. The Show View dialog presents a list of views organized by category (see Section 2.5, Installing and Running the Product, on page 86) so that a user can more easily find a desired view. |