DekGenius.com
Previous Section  < Day Day Up >  Next Section

Recipe 1.6 Managing Perspectives, Views, and Editors

1.6.1 Problem

How do you work with Eclipse views, editors, and perspectives?

1.6.2 Solution

To use Eclipse, you need to know what view, editor, and perspective mean:


View

This is a window that gives you a graphical display of your data, whether that data is text, bulleted lists, a GUI, images, and so on.


Editor

An editor is much like a view, except that the data in it is editable. When you're working on your code, you edit it in an editor, which is usually the central window displayed in the workbench.


Perspective

A perspective is a well-defined collection of views and editors. When you open a perspective, its views and/or editors appear in the workbench.

1.6.3 Discussion

Views display data but don't let you edit it; editors both display data and make it editable. Because screen space is always at a premium in GUIs, views are often stacked one on top of another. You select the one you want to see using tabs that appear on the edge of the stacked views.

If you want to reopen a view you've closed by mistake, select Window Show View, and choose the view you want from the menu that appears.


When you open code or other resources, their data will appear in an editor so that you can work on it. Eclipse automatically selects the right editor for the resource you're opening, based on the resource's file extension: the JDT's Java code editor for Java code (.java files), an XML editor if you have one installed for XML files (.xml files), and so on. You even can open Microsoft Word documents (.doc files) in an editor; Eclipse displays a Microsoft Word window in the editor space using Windows Object Linking and Embedding (OLE).

You can set which Eclipse editor or external program to use to open a specific type of file based on its file extension. Just select Window Preferences Workbench File Associations, select the file type, and associate an editor or program with it (if nothing else, you can use Eclipse's default text editor). You also can run programs outside Eclipse as external tools, invoked by selecting Run External Tools. To add and configure external tools, select Run External Tools External Tools.


Editors are where you do most of your work, developing code and working with other resources. For instance, you can develop a GUI in an editor by dragging and dropping controls when using a plug-in that provides that functionality (for more information on using a plug-in that enables you to design GUIs in this way, see Chapter 9).

You can have a number of editors open at the same time, and they'll appear stacked in the center of the workbench. You select the editor you want to work with by clicking the corresponding tab at the top of the stacked editors (or by selecting Window Switch to Editor, which displays a list of editors you can switch to). You close an editor simply by clicking the X in its associated tab (or by selecting Window Hide Editors, which toggles to Window Show Editors after hiding an editor).

As noted earlier, a perspective is a collection of views and editors that open and close as a group. For example, the Java perspective displays a set of views and editors appropriate to Java development. These include the Package Explorer view, which displays a clickable hierarchical class structure of the Java files in the project, and the JDT editor, which supports Java syntax checking, quick fixes for syntax errors, and so on. The Debug perspective, on the other hand, displays views and editors appropriate to debugging, including watch windows, the output console, a watch window for variables, and so on.

Perspectives usually appear by themselves, following your lead (the Java perspective opens automatically when you create a Java project, for example), but you also can open Eclipse perspectives explicitly by selecting Window Open Perspective, and then choosing a perspective from the submenu that appears. To close a perspective, select Window Close Perspective.

When you open a perspective, icons appear in its shortcut bar. (The shortcut bar is located on the far left in the Eclipse window. Refer back to Figure 1-2, in which the icon for the Resource view—showing a file and a folder—appears.) Once you open a perspective, Eclipse remembers that you used that perspective at least once and an icon for that perspective appears in the shortcut bar. To switch to that perspective, just click the corresponding icon. To remove icons from the shortcut bar, right-click the icons, and click Close. The icon at the top of the shortcut bar (showing a perspective with a + sign) enables you to open new perspectives.


Perspectives have a predefined set of views and editors built in. When you select a perspective, that set of views and editors appears automatically. By defining a set of perspectives, Eclipse makes your job easier because you don't have to open the specific views you want every time you want to write or debug code. You also can create (as well as delete) your own perspectives.

To get a handle on these concepts by way of an example, take a look at the next recipe, in which we dissect the Java perspective.

1.6.4 See Also

Recipe 1.3 on understanding the Eclipse workspace.

    Previous Section  < Day Day Up >  Next Section