TurboManage

David Chandler's Journal of Java Web and Mobile Development

  • David M. Chandler


    Web app developer since 1994 now working for Google and residing in Atlanta with the wife of my youth and our five children. My current side project is a not-for-profit startup using GWT on AppEngine. In my "spare" time, I take pictures, preferably of Rocky Mountain National Park.

  • Subscribe

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 134 other followers

  • Sleepless Nights…

    May 2012
    S M T W T F S
    « Apr    
     12345
    6789101112
    13141516171819
    20212223242526
    2728293031  
  • Blog Stats

    • 344,154 hits

Archive for the ‘Eclipse’ Category

Google Plugin for Eclipse now open source

Posted by David Chandler on November 16, 2011

This is pretty big news for the GWT community and should make it easier for GWT frameworks to build tooling for Eclipse. Witness JBoss, who was working on GWT integration even before the announcement. Congrats to the GPE team!

Posted in Eclipse, Google Web Toolkit | Leave a Comment »

Configuring Eclipse on a Mac

Posted by David Chandler on July 8, 2010

I’m attempting to make the switch from Windows to Mac courtesy of my new employer (I’m pleased to be working with the GWT team at Google). While I very much like my shiny new MacBook Pro, I simply don’t get all the Mac hype. The biggest problem has been that I’m a keyboard person, and Macs are for mouse people. Most Windows keyboard shortcuts have Mac equivalents, but they’re just different enough to make for a bit of a learning curve, like Ctrl+arrows instead of Home and End. Thankfully, many keys can be remapped via System Preferences, but I haven’t found a way to map the editing keys yet (anyone?). My biggest annoyance is that holding down the Alt key doesn’t bring up menu shortcuts as on Windows. That makes going to Run | External Tools a real pain in Eclipse. Alt+R, E becomes Ctrl+F2,R,R,down arrow,E. Runner up annoyance is that there’s no way to use the keyboard to click “No” in a confirmation dialog.

At any rate, here are a few notes for other Eclipse users making the switch from Windows to Mac.

The first thing is to make the fonts readable. This is not necessarily a Mac thing, but the system font does seem especially small. In Eclipse preferences (Command+comma in most apps on the Mac–nice), I bumped up the font size (General | Appearance | Colors and Fonts | Basic | Text Font). This increases it for the Console window, but some plug-ins seem to use the system font instead, which leaves these “over the hill” eyes squinting at logs. Which, in turn, brings us to an almost-unbelievable discovery: you can’t change the system font on a latest, greatest Mac (OS X 10.6.3)! Problem still unsolved.

Now, time to move over my Eclipse external tools configurations from Windows. The external tools config to launch Finder in the selected project directory is very cool, but far from obvious. In the Run | External Tools | Configuration… dialog, enter the following information:

Location: /usr/bin/open
Working Directory: ${project_loc}
Arguments: .

This corresponds to typing “open .” in a Terminal window, which launches Finder in the current directory. Now if I could just configure a shortcut key to launch Terminal so I don’t have to click the icon in the dock every time… See Finder toolbar button to open Terminal to go the other way.

You can also create an external tool to launch Terminal in the selected project directory. Well, almost. To launch Terminal, you have to key into the Location field the full path /Applications/Utilities/Terminal.app/Contents/MacOS/Terminal; however, it always opens in your home directory, even if you set Working Directory to the ${project_loc} variable. That defeats the purpose of this particular tool launcher. Fortunately, xterm is a little smarter, so the following settings work:

Location: /usr/X11/bin/xterm
Working Directory: ${project_loc}
Arguments: (none)

Unfortunately, the default xterm font is miniscule.

Fortunately, you can put the following lines in ~/.Xdefaults to increase the default font size:

XTerm*font:     *-fixed-*-*-*-20-*
XTerm*boldFont: *-fixed-*-*-*-20-*

Now we’ve replicated the command prompt external tool from Windows Eclipse, but unfortunately, it’s a pain to get to the Run | External Tools menu via the keyboard. So we might as well punt and make it even easier with the mouse. thanks to this nifty open source plug-in for Eclipse. Once you’ve installed the plug-in, simply right-click on a project and select “Open in Terminal” to open a new xterm. Someone should contribute “Open in Finder” to that project, too.

Most keyboard shortcuts on Windows map directly to the map in the standard way; that is, you press the Command (Apple) key on the Mac instead of Ctrl on the PC. One notable exception is Ctrl+Space, which is identical on the Mac. Command+Space would be more consistent; however, this brings up the Spotlight search tool on the Mac. Since I’d rather have Ctrl+Space work in Eclipse where my muscle memory is expecting it, I swapped these keystrokes in Eclipse Preferences and Mac System Preferences. Another alternative is to disable Spotlight in favor of Google Quick Search Box.

Eclipse on Mac tricks welcome in the comments. No flames, please.

Posted in Eclipse | 7 Comments »

Coding getLogger() quickly with an Eclipse template

Posted by David Chandler on March 12, 2010

The AppEngine admin console log viewer is so powerful that it makes me want to log anything and everything. One obstacle to this (however minor) is that it’s a pain to write this for every class in which I want to log:

private static final Logger LOG = Logger.getLogger(MyLongClassName.class.getName());

Eclipse code templates to the rescue! Open Window | Preferences | Java | Editor | Templates and create a new template. Name it “log”, set the context to “Java type members”, and enter this pattern:

private static final Logger LOG = Logger.getLogger(${enclosing_type}.class.getName());
${imp:import(java.util.logging.Logger)}${cursor}

Click OK to save it. Now open any class in the editor, and type “log” followed by Ctrl-Space. Press Enter. Presto!

I feel a template for AsyncCallbacks coming on…

Posted in Eclipse | 3 Comments »

Tips on organizing GWT modules

Posted by David Chandler on November 19, 2009

My current project is at the point where I’m starting to work on an administrative UI. I wanted to package it as a separate GWT module in order to not clutter up the main application module. There is some code such as the domain model that is shared between the main app and the admin code, so the question is how to organize the modules in order to share code between them.

My first attempt was to have the admin module simply inherit the main app module named ROA in admin.gwt.xml, like this:

	<inherits name="com.roa.app.ROA" />

This had two undesired results:

  • Both modules declare an entry-point, so GWT tries to load both, beginning with the inherited module.
  • At GWT compile time, all the code from the inherited module was duplicated under the admin module in the war structure.

My next attempt was to have the admin and app Java packages each point to a third sister package called “common” containing the domain model and other common code. Java is happy with this, but in order for GWT to compile the common code into JavaScript, you must make it a module. So now there are three packages, each with its own module:

admin.gwt.xml
app.gwt.xml
common.gwt.xml

Admin and app each have entry points and inherit the common module, which does not define an entry point. This works fine.

In the common module, I use the source tag to include multiple directories instead of just the default client directory. Note that if you specify one or more source directories, GWT no longer compiles the client directory by default, so you have to explicitly include it, as well:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE module PUBLIC "-//Google Inc.//DTD Google Web Toolkit 1.7.1//EN" "http://google-web-toolkit.googlecode.com/svn/tags/1.7.1/distro-source/core/src/gwt-module.dtd">
<module>
	<inherits name="com.google.gwt.user.User" />

	<source path="client" />
	<source path="domain" />
	<source path="presenter" />
</module>

Also, I moved the “public” directory containing CSS and images from the admin and app packages into the common module, and discovered that GWT does not create a “common” directory in the war, but rather copies the contents of the public folder from the inherited common module into both the admin and app module directories. That’s OK, though, as my CSS and images now exist in only one place in source control.

A final note: thank goodness for Eclipse refactoring tools. The easiest way to move a package (say, com.roa.app.domain to com.roa.common.domain) is to select it in the Project Explorer, then right-click, Refactor, and Rename… It’s a bit non-intuitive to use Rename rather than the Move command, but the latter appears to work only for moving packages to another project or source folder, whereas rename allows you to “move” it within the current source folder. Eclipse automatically fixes all the package and import declarations in affected code (whew!).

Posted in Eclipse, Google Web Toolkit, Headsmack | 8 Comments »

Eclipse keyboard shortcut for working with interfaces

Posted by David Chandler on November 3, 2009

Maybe everyone knows this already, but in case not…

Put your cursor in the name of an interface (say, a Display interface nested in a GWT presenter) and press Ctrl-T. Eclipse shows you all the classes that implement the interface and you can then navigate directly to an implementing class. I frequently use this in combination with Ctrl+Alt+H to find out how a method gets called.

You can find all of my favorite keyboard shortcuts in my Eclipse Google notebook listed in the left sidebar.

Posted in Eclipse | 1 Comment »

More Benefits of gwt-dispatch

Posted by David Chandler on September 25, 2009

When you use gwt-dispatch, a single dispatch servlet handles all service requests, so you no longer need to configure individual servlets in web.xml. Furthermore, action handlers are configured in Java code, like this:

		bindHandler(FindPrayerListsAction.class, FindListsHandler.class);
		bindHandler(AddPrayerListAction.class, AddPrayerListHandler.class);
		bindHandler(DeletePrayerListsAction.class, DeletePrayerListsHandler.class);

Because all configuration is done in Java, you can rename any handler, Action, Result, etc., and the Eclipse refactoring tools automatically rename it everywhere.

And speaking of Eclipse, did you know you can type only the capital letters of a class name and hit Ctrl+Space to let Eclipse automatically expand it? For example, to type “FindPrayerListsAction” above, I could simply type “FPLA” and hit Ctrl+Space. This also works in the Open Type (Ctrl+Shift+T) and Open Resource (Ctrl+Shift+R) dialogs.

Posted in Eclipse, Google Web Toolkit, Model-View-Presenter | Leave a Comment »

Eclipse Keyboard Shortcut of the Week

Posted by David Chandler on August 14, 2006

Just a quickie time-saver here. I hate having to use the mouse to navigate through code (yes, I can still use vi) as it slow and bothered my right shoulder enough over time to force me to mouse with my left hand. If you’re like me, you’ll want to know about:

Ctrl+Shift+T (Open Type) Just type the first few letters of the Java class you’re looking for, and voila, you can use the arrow keys to find exactly the right one. No more clicking on folders in Package Explorer.

Ctrl+Shift+R (Open Resource) Same drill, but works for any resource in the Package Explorer.

You can find a bunch more of my favorite keyboard shortcuts in my Eclipse Google Notebook (linked on left).

/dmc

Posted in Eclipse, Ergonomics | Comments Off

Eclipse Tip of the Day: Rename

Posted by David Chandler on March 30, 2006

Ever change your mind about a field name or type name? Just move the cursor over the name and hit Ctrl+2, R to rename it. Eclipse highlights all occurrences of the variable or type name and updates them all as you type. Very cool.

/dmc

Posted in Eclipse | Leave a Comment »

 
Follow

Get every new post delivered to your Inbox.

Join 134 other followers