- Getting Started
- Writing Java Code
- Running Java Code
- Working with Java Elements
- Tuning the Performance of JDT
- More on JDT Views and Perspectives
- Chapter Summary
More on JDT Views and Perspectives
Let's end this chapter with a little more detail on some of the views and perspectives that comprise JDT, and some cool stuff that may not be immediately obvious.
Filtering View Contents
|
The JDT views allow you to filter the elements that are displayed. You can select to have static members, fields, and nonpublic members hidden. These filtering criteria are useful if your workspace contains a significant amount of code, and navigating (especially in the Package Explorer view) becomes cumbersome. From the pull-down menu on the title bar of the Package Explorer view, you can filter the contents by working set or by a number of Java-specific criteria (see Figure 3.35). This is useful, for example, if you want to suppress the display of a project's referenced libraries.
Figure 3.35 Filtering the Package Explorer View
Package Explorer View
If the package names in the Package Explorer view are long and/or you have the width of the view sized so that you often find yourself scrolling the view horizontally to find the right package, you can abbreviate the package names in the view. In your Java Appearance preferences, select Compress package name segments (except the last one) and enter a pattern to represent the compression scheme. The pattern is a number followed by one or more optional characters specifying how each segment of the package name is to be compressed. The pattern number specifies how many characters of the name segment to include, and the pattern characters become the segment separators. The compression is applied to all package name segments, except the last one. For example, for the package name org.eclipse.jface,
causes to it be compressed to o.e.jface, 0 results in jface, and
results in or.ec.jface.
If you have compressed names, you can quickly determine the full name of a resource by selecting it in the Package Explorer view. The full name is displayed in the message area.
In addition to filters, you can use Go Into or Forward to focus the contents on the selected containing element, thereby reducing the content in the view. If you do this often, select Go into the selected element in your Java preferences to make this the default, instead of expanding the element in the view.
Finally, if you work with JAR files in your projects, in your File Associations preferences, add a file compression program that understands *.jar files to make it easy to view their contents.
Hierarchy View
|
The Hierarchy view is an exceptionally useful one, especially for exploring Java code (see Figure 3.36). There are three presentations available from the toolbar: the Type Hierarchy (Ctrl+1), the Supertype Hierarchy (Ctrl+2), and the Subtype Hierarchy (Ctrl+3). These three presentations revolve around a focal point type in the view, indicated by the label decoration. This is the type you opened the view on. Change this with Focus On... from the context menu. For classes, the Type presentation shows a single slice of the class hierarchy from Object through to all of the subclasses in a class. For interfaces, it shows all classes that implement the interface and their subtypes. The Supertype presentation shows classes that are extended and interfaces that are implemented. The Subtypes presentation shows a class and its subclasses or an interface and the classes that implement it.
Figure 3.36 Hierarchy View
|
Lock View and Show Members in Hierarchy locks the contents of the bottom pane and prevents it from changing as you select elements in the top pane. With this and Show All Inherited Members, it's easy to get a handle on where fields are defined and what classes and interfaces implement which methods.
|
You can drag a Java element from one of the Java views and drop it on the Hierarchy view to open it there. The view maintains a list of the elements you have opened here. Rather than opening an element again, you can select Previous Hierarchy Inputs to see a list of those available. Change the orientation of the view from vertical to horizontal by selecting Horizontal View Orientation from the Menu pull-down on the Hierarchy view toolbar.
Tasks View
|
If you end up with a lot of errors and warnings, say after you've imported a chunk of code, the errors can be easier to manage if you filter them. Select Filter... on the title bar and then select On selected resource only or On selected resource and its children.
Search View
|
In addition to displaying the results of a search, you can use the Search view to quickly navigate through Java references and declarations. Once you have a set of search results, select a declaration, reference, and implementer, then select References > or Declarations > from the context menu to execute another search. The view also maintains a history of your search results. Rather than executing a search again, select Previous Search Results and then select from the list.
Java Type Hierarchy Perspective
The Java Type Hierarchy Perspective is a perspective optimized for use with the Hierarchy view (see Figure 3.37). When you select Open Type Hierarchy, JDT replaces the contents of the Hierarchy view if it is open or opens a new one in the current perspective. Preferences provide a useful alternative to this default behavior. In the Java preferences, select Open a New Type Hierarchy Perspective. This causes the Java Type Hierarchy perspective to open in a new window. VisualAge for Java users, who like the ability to double-click on a class to open it in a window, may find this useful.
Figure 3.37 Java Type Hierarchy Perspective
Java Browsing Perspective
The Java Browsing perspective, shown in Figure 3.38, provides a slightly more structured approach to navigating through Java resources than the Java perspective. In addition to an editor pane, it contains Projects, Packages, Types, and Members views. The editor pane is set to Show Source of Selected Element Only. The organization of this view will be familiar to VisualAge for Java users. In fact, it's intended to mimic the VisualAge for Java user interface.
Figure 3.38 Java Browsing Perspective
The navigation model is to select an element (by single-clicking it) in a pane to see its contents in the next pane. Open and Open Type Hierarchy actions are available from all the views and the editor. You can specify different filters for the contents of each of the views. The default orientation of the Java Browsing perspective is shown in Figure 3.38. You can also orient the views vertically on the left with the editor on the right by changing your Java Appearance preferences to Stack views vertically in the Java Browsing perspective.Exercise Summary
The exercise in Chapter 29 accompanies this chapter. The exercise is broken down into a number of parts, each demonstrating different concepts and building on the previous part.
Hello World
You'll create the ubiquitous "Hello World" program, and you will see how to run it, including using a scrapbook page.
Quick Fix
You'll use JDT's quick-fix capabilities to fix a series of errors in a Java program
Code Generation
You'll see how to significantly improve your productivity by generating Java code to complete expressions, including the use of code templates.
Refactoring
In this part, you'll really start to see the power of JDT when using refactoring to clean up, reorganize, and extend a program.
Launch Configurations
You'll see how to use launch configurations to run Java programs, and you'll pass parameters to a program, pass JVM parameters, and reference declarations in a JAR file.
JRE 1.4 Code
In the final part of the exercise, you'll see how to configure JDT in order to develop code that requires JRE 1.4.