2.6 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 basicyou can move any view, editor, or toolbar around simply by dragging it.

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 Window Lock the Toolbars menu item. And if a perspective gets all scrambled by inadvertent mouse movements, use Window 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 programming 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 Windows Preferences item, opening the Preferences dialog you see in Figure 2-29. Select the Java 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.

Figure 2-29. Customizing code generation
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 Window Preferences item, followed by the Java Code Generation 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 Preferences Java Code Generation Code and Comments). When you open the Preferences dialog and select the Java Code Generation Code and Comments Code New Java files item, as you see in Figure 2-30, you can edit the template Eclipse uses to generate this comment.

Figure 2-30. Configuring comment templates
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 Window Preferences, followed by the Java Editor Templates item. We'll create a new shortcut named ptd to print the date, as you see in the name box in Figure 2-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).

Figure 2-31. Creating a code assist shortcut
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 Figure 2-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 .

Figure 2-32. Customizing code assist
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 Figure 2-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.

Figure 2-33. Creating a working set
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 Figure 2-34.

Figure 2-34. Using a working set
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 Window Customize menu item, opening the Customize Perspective dialog, as you see in Figure 2-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 Window Show View menu item, as you see in the figure.

Figure 2-35. Customizing a perspective
figs/ecps_0235.gif

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 Window 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.



Eclipse
Eclipse
ISBN: 0596006411
EAN: 2147483647
Year: 2006
Pages: 114
Authors: Steve Holzner

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net