12/09/2009

Eclipse: quickly change perspectives with keyboard shortcuts

Perspectives offer a nice way to quickly adapt Eclipse to the kind of work we are doing; there is a perspective for development, debugging, etc. After using it a while, creating some keyboard-shortcuts helps a lot as well. At the end of this article, we'll have perspective-icons like these:



Let's see what the buttons do:
  • JavaEE Perspective (Alt+1)
    • In this perspective the Project Explorer (tree) is displayed on the left, on the right we have the code-editor window and the tool-windows benefiting from a wide display are on the bottom. The icon shows a tree, that's why it makes sense to use this perspective for the one displaying the tree.
    • To open this perspective, select Window->Open Perspective->Other, and select JavaEE. The defaults are almost right, we just have to either close the outline and task list view if we don't use it, or move them to the left (next to the Project Explorer) so that they won't occupy so much space.
    •  To attach it to Alt+1, press Ctrl+Shift+L twice (this is a double-shortcut which on first press shows the available options in a tooltip, on a second press presents us the Preferences->Key window); in type filter text enter java ee; click on Show Perspective (Parameter Java EE) ; click binding, then press the new bind-key Alt+1 and Apply and OK.
  • Java Perspective (Alt+2)
    • This one is very similar to the previous one, except that we don't have the tree displayed, which results in a much wider source-window (for developers fancying long lines...)
    • To open this perspective, select Window->Open Perspective->Other, and select Java (Default). Let's close the Outline / Task List / Spring Explorer view as well as the Package Explorer and Hierarchy view. 
    • Attach the Show Perspective (Parameter: Java) command to Alt+2
    • This results in a very clean interface; we just have to get used to press Alt+1 to switch to the view we declared previously if we need the views we just closed. Just try pressing Alt+1 and Alt+2 repetitively a couple of times; you'll see easy it is to switch. In no time we get used to press Alt+2 when we need a "code-and-tool" like environment and Alt+1 when we want to browse around in the Package Explorer / Ant / etc views.
  • Debug Perspective (Alt+3)
    • The debug-layout really depends on the developer, but the methology is similar. So open this perspective and customize it the way you want.
    • Attach it to Alt+3.
  • Team Synchronizing Perspective (Alt+4)
    • Customize / attach key like earlier.
  • Database Development Perspective (Alt+5)
    • Customize / attach key like earlier.
The last ones are really depending on your development workflow. A typical workflow using these shortcuts can be something like this:
  • Find and Open the needed class or resource:
    • Alt+1 for browsing in Project Explorer
    • Alt+2 and press Ctrl+Shift+R to quickly open the source-file/resource. Here the first couple of characters of the classname should be enough to type - or CaMeL case, e.g. if you want to open DeadLetterChannel, just enter DLC. Neat, huh? And highly addictive...
  • After the modifications are done starting the debugger switches immediately to the Debug Perspective, but if the wide code-view is needed just press Alt+2 (it's a real relief after the very-useful-but-so-crowded Debug perspective); and when you need something from the debugger tool windows, it's very easy to switch back to the Debug  Perspective with Alt+3. Since the usual shortcuts like F5 (step into), F6 (step over) and F7 (step return) work in Java perspective as well, I usually find myself stepping thru the code there, and only when I arrive at the troublesome part, I switch to the Debug Perspective to see the watches, call stacks, etc.
  • When everything is ready, debugged, etc, Alt+4 switches to the Synchronising Perspective to submit the changes to source-control.
  • After a rebuild on the development server, the Database perspective (Alt+5) can be used to interact with the database.
The order of the buttons on the top-right corner depends on the order we opened the perspectives; I usually order them the same way as my keyboard-shortcuts (e.g. the first one is JavaEE because Alt+1 activates it, etc); thus the mouse usage is coherent to the keyboard. The buttons can be easily re-ordered with the mouse by dragging them to their place (Note: the "Show Text" option is turned off on the screenshot on the top of this post)

Comments and opinions are warmly welcome!
How does your developer workflow look like?

Thanks for reading and have a nice day!

3 comments:

  1. checkout this list of shortcuts

    http://shortcut-finder.appspot.com/?query=eclipse

    ReplyDelete
  2. thanks for sharing this, helpful to jump from ddms and java perspectives in android.

    ReplyDelete