Customizing the Development Environment

Our last topic in this chapter is all about customizing your development environment. Eclipse is easy to customize, starting from the most basic—you can move any view, editor, or toolbar around simply by dragging it.

Screenshot

If you don't like to work in an environment where things can move around with mouse movements by mistake, you can lock the toolbars with the WindowScreenshot Lock the Toolbars menu item. And if a perspective gets all scrambled by inadvertent mouse movements, use WindowScreenshot Reset Perspective to restore things.


You can also customize how Eclipse will generate code for you. For example, the default code generation style doesn't place opening curly braces on their own lines:

public void printer( ) {
 System.out.println("No worries.");
}


However, your coding style might be more like this, where each curly brace does get its own line:

public void printer( ) {
 System.out.println("No worries.");
}


You can customize this with the WindowsScreenshot Preferences item, opening the Preferences dialog you see in Screenshot-29. Select the JavaScreenshot Code Formatter item, which lets you specify options for code generation. Here, select the "Insert a new line before an opening brace" item, as you see in the figure; the sample code below will change to match.

Screenshot-29. Customizing code generation
Java figs/ecps_0229.gif

Here's another way you can customize how Eclipse generates code. When you create a new file, this kind of comment is inserted automatically:

/*
 * Created on Oct 17, 2003
 *
 * To change the template for this generated file go to
 * Window>Preferences>Java>Code Generation>Code and Comments
 */


As this text says, you can change this with the WindowScreenshot Preferences item, followed by the JavaScreenshot Code GenerationScreenshot Code and Comments item (the > you see in the code is the HTML escaped version of >, which is used so the resulting Javadoc can be opened in a browser; the comment actually reads, "To change the template for this generated file go to Window Screenshot Preferences Screenshot Java Screenshot Code Generation Screenshot Code and Comments"). When you open the Preferences dialog and select the JavaScreenshot Code GenerationScreenshot Code and CommentsScreenshot CodeScreenshot New Java files item, as you see in Screenshot-30, you can edit the template Eclipse uses to generate this comment.

Screenshot-30. Configuring comment templates
Java figs/ecps_0230.gif

You can even create new code assist items in Eclipse. For example, say you want to create a shortcut for the code needed to print out the current date. To do that, select WindowScreenshot Preferences, followed by the JavaScreenshot EditorScreenshot Templates item. We'll create a new shortcut named ptd to print the date, as you see in the name box in Screenshot-31. In this case, the template System.out.println("${date}"); will be replaced by the code to print out the date. Besides ${date}, you can use other values, such as ${cursor}, to indicate where to place the cursor after the insertion has been performed (when you type ${, code assist will display all the possible values you can use in code assist expressions).

Screenshot-31. Creating a code assist shortcut
Java figs/ecps_0231.gif

Now when you type ptd in code, followed by Ctrl+Space, code assist will enter the code needed to print out the current date, as you see in Screenshot-32. In fact, if you type p, followed by Ctrl+Space, code assist will list all its options that begin with the letter "p"—including ptd.

Screenshot-32. Customizing code assist
Java figs/ecps_0232.gif

Another way of customizing your development environment is to create working sets. Working sets let you limit what appears in the Package Explorer. For example, to create a working set consisting only of the projects Ch02_01 and Ch02_02, click the Package Explorer's pull-down menu (that's the inverted black triangle at the top of this view) and select the Select Working Set item, opening the Select Working Set dialog. To create a new working set, click the New button and select the Java item in the Working Set Type box in the New Working Set dialog. Then click the Next button. Now you can select the projects for this working set, as you see in Screenshot-33. In this case, we'll create a working set named 1And2Only and select only the Ch02_01 and Ch02_02 projects for this working set.

Screenshot-33. Creating a working set
Java figs/ecps_0233.gif

Clicking Finish creates the new working set and opens the Select Working Set dialog. Select the 1And2Only working set and click OK. When you do, only the Ch02_01 and Ch02_02 projects appear in the Package Explorer, as you see in Screenshot-34.

Screenshot-34. Using a working set
Java figs/ecps_0234.gif

To restore all projects to the Package Explorer, select the Deselect Working Set item from the Package Explorer's pull-down menu. In fact, you can customize entire perspectives as well. To do that, select the WindowScreenshot Customize menu item, opening the Customize Perspective dialog, as you see in Screenshot-35. You can use this dialog to customize menu items available for the current perspective; for example, you can specify what views the user can switch to with the WindowScreenshot Show View menu item, as you see in the figure.

Screenshot-35. Customizing a perspective
Java figs/ecps_0235.gif
Screenshot

After you're done setting Eclipse preferences, you can export those preferences so others can use them as well. To do that, use the Import and Export buttons in the WindowScreenshot Preferences dialog.


And that completes our look at some of the extraordinary power that Eclipse places at your fingertips for Java development. In the next chapter, we're going to discuss testing and debugging your Java code.

      
Comments