TweetFollow Us on Twitter

The Cool Side of the Moon

Volume Number: 20 (2004)
Issue Number: 3
Column Tag: Programming

Eclipse IDE

by Ruben Kleiman

The Cool Side of the Moon

The Eclipse IDE on the Macintosh

The Eclipse IDE

In this article we'll tour the Eclipse IDE and discuss how it fits into the Macintosh architecture, focusing on development for Java. We will go beyond hype and precisely look at how Eclipse now stands on the Macintosh.

Why Eclipse?

With so many excellent, even free, IDEs out there, why Eclipse? For the writer, there are three reasons. First, Eclipse is intuitive to learn and use, and just one IDE serves a wide variety of purposes--from Java, AOP, web, to C/C++ development. The investment pays good dividends.

Second, Eclipse's general architecture has created a global community of plug-in developers from whom I draw a wide variety of tools. Some research groups release plug-ins unavailable elsewhere. In a pinch, I can easily roll my own. One way to think of Eclipse is as Emacs for the User Interface generation. While Lisp is the language for extending Emacs, for Eclipse the language is the plug-in architecture and Java.

Finally, I'm addicted to Eclipse's extensive and reliable refactoring features: they have saved my overnighters for more useful work than code wrestling.

Features and Benefits

Eclipse is a robust, open-source IDE based on a general plug-in architecture. All components of Eclipse are plug-ins. The most widely used plug-in is the Java Development Toolkit (JDT). Another is the new C/C++ Development Toolkit (CDT), supporting the GNU gcc compilers, including Objective C. The Eclipse IDE runs on and has cross-platform development libraries for MacOS-Carbon, Win32-win32, Win32-CE/win32, Solaris/motif, QNX/photon, Linux/qt, Linux/motif, Linux/gtk, HPUX/motif, and AIX/motif.

Apart from the Java and C++ editors, there are plug-in editors for UML, XML (<oXygen/>), Ant, visual programming, and more. Editors can be extended and share their resources with other plug-ins. One need not re-invent the wheel to add a small but useful contribution. To write your own editor, use the Graphical Editor Framework (GEF) plug-in.

There are plug-ins for team support (CVS synchronization, including SSH2 in Eclipse 3.0), JUnit, code instrumentation (Clover), Automated Software Quality (Hyades), web application server build and deployment (e.g., for JBoss, Apache Tomcat, IBM Websphere, BEA Weblogic), a platform delivery framework (OSGi), and more. There is an Eclipse project developing end-to-end web service development plug-ins.

Naturally, there is a Plug-in Development Environment (PDE), itself a plug-in, for creating plug-ins. And, for the JDT and the Eclipse IDE, the help system has a well-documented Java Development Environment Plug-in Developer Guide and a Platform Plug-in Developer Guide, respectively.

Eclipse on the Macintosh

So how is Eclipse integrated with the Mac? Eclipse uses the Carbon library via its Standard Widget Toolkit (SWT). While Swing generally implements its widgets with a combination of Java and native code, SWT maps its widgets to Carbon widgets via one-to-one C calls to the native widget APIs. When debugging, this means that when you run into a handle to a Carbon widget, you see precisely what you would expect if you were working in Objective C. By default, Eclipse obtains the Aqua look-and-feel and the best performance that Carbon can afford.

SWT emulates non-native widgets, and there is a separate SWT library for each platform. In addition, there's a shared library that glues SWT Java calls to the native API. At the lowest level, SWT maps to the Carbon Event Manager (Listing 1).

Listing 1: SWT Event Loop Life Cycle

Event loop using a window. Display interacts with the Carbon event manager 
to handle the application event loop via readAndDispatch(). A Shell is a window entirely 
handled by the Carbon Window Manager: it is instantiated with the Display as its parent.

Display display = new Display ();
Shell window = new Shell(display);
window.open();
while (!window.isDisposed()) {
  if (!display.readAndDispatch())
      display.sleep();
}
display.dispose();

This is the main application thread. readAndDispatch() maps native events into SWT events. Carbon event loop timers are provided by Display methods. Listeners can be registered on any event type.

We can fork other threads for long-running tasks. Such threads can call back into the main thread, but only through an API that ensures that the interaction with the UI is safe. This is provided by Display's synchExec(Runnable) and aSynchExec(Runnable) methods; they allow the calling thread to block or not block, respectively, until the Runnable executes. For example, the forked thread may go off to zip some files for the user interface and, when done, use one of the *Exec(Runnable) methods to display a message to the user. From there on, Eclipse's user interface is based on SWT and JFace--a higher-level library providing Model-View-Controller-like access to SWT.

What about Cocoa? Cocoa and SWT are comparable frameworks, but SWT is founded on Carbon. The decision to use Carbon is arguable, but, since Carbon includes more lower-level APIs, it can provide some maneuvering room for the SWT implementors than Cocoa. There has been some work in pre-release versions of Eclipse 3.0 to support Carbon's HiView, but a higher priority of the Eclipse team seems to be to achieve a faster and more robust MacOS implementation in the near term. This, as we shall see, should be a welcome move.

How does Interface Builder fit in? Interface Builder generates code stubs suitable for Apple's Java extensions, but it generates NS* classes, not SWT or Swing classes. Since Interface Builder's output is a nib file, we could write a nib file reader in JavaCC and a generator for SWT or Swing using Carbon or Cocoa nibs. Alas, at the time of this writing, no such feature exists.

Finally: how usable is Eclipse on a Mac right now? The first version of Eclipse was released in November of 2001, but it wasn't until March 2003 that Eclipse support for the Mac started with Eclipse 2.1. There is little to complain about the Aqua look-and-feel (Figure 1). However, though on a Titanium PowerBook G4, at 667MHz and 512MB RAM, large project builds are as fast as one would expect, but tool tips and code assist are sluggish in Eclipse 2.1.2. Eclipse 2.1.2 is not up to par with its excellent performance on, e.g., Windows or Red Hat Linux. Eclipse developers are working to close this gap.

Installing Eclipse

Eclipse 2.1.x+ uses JRE 1.4+, so you need MacOS 10.2+. Eclipse requires 100 MB on disk and 256 MB of system RAM. To install Eclipse, go to http://www.eclipse.org and follow the download link to a MacOS version, with care to use Safari and the latest version of StuffIt, as instructed. We'll use Eclipse version 2.1.2 in this article. To uninstall Eclipse, just throw away the whole folder.

Getting Oriented

Three tips. First, the help system is indispensable. It has clear, often illustrated, step-by-step, task-oriented instructions, tutorials, APIs, and overviews of platform and plug-in features. The key areas you should peruse are the Java Development User Guide and the Workbench User Guide. Since almost all the information you'll ever need is there, it will pay you to get acquainted with these pages.

Second, select the Help -> About Eclipse Platform menu for an overview of the Eclipse features and plug-ins installed in your system. An Eclipse feature is a group of related plug-ins.

Finally, access your global preferences settings via the Window -> Preferences menu. Explore the Workbench and Java settings, especially those for the Java source editor's code formatting and code assist, as well as the auto-generation of comments and names for files, classes, methods, fields, etc.

What's Your Point Of View?

A View is a panel inside the Eclipse workbench window. For example, the Java Development Toolkit (JDT) plug-in and its extensions provide the following views:

  • An editor view. There are editors supporting many file types (e.g., Java or AspectJ class, Ant build file, property file). Depending on your preferences, you also have access to other editors (e.g., Emacs) by clicking on a file and using the Open With... context menu. (Eclipse 3.0 early-access has an Emacs key binding option.)

  • A view of the class inheritance tree (the Hierarchy View). In Eclipse 3.0 there is a Method Call view.

  • The system console (the Console View).

  • The "todos," error, build and other tool warnings, etc. (the Tasks View).

  • The hierarchical view of all of the resources in your project (the Package Explorer View).

  • An outline of a class's members and imported classes (the Outline View).

  • Packages, Types and Members views that display and let you to focus on Java packages, classes, and members, respectively.

  • The Synchronize view allows you to synchronize your project with a CVS repository.

  • If you use the Apache Ant tool, the Ant View allows you to look at your Ant xml file's tasks in outline and run them individually, or to look at the properties of your Ant file.

  • Eclipse's AspectJ IDE plug-in enhances most of the above views to support Aspect-Oriented Programming (AOP) using the AspectJ language. For example, the Outline view lets you see whether a member is advised, and by whom and how it is intercepted.

Many more views are available from free and commercial plugins. Views collaborate through the plug-in architecture. For example, the Members view's contents on which package is selected in the Packages view. Each view has a mini-toolbar, and sometimes drop-down and contextual menus, as well as tool icons. Try them out. Double-clicking on a view's mini-toolbar expands/minimizes the view.

Although you can open any of these views via the Window -> Show View menu, you will typically work with a group of views: this is where perspectives come in.

It Depends On Your Perspective

A perspective is just a group and placement of views in a window (Figure 1). The Eclipse Java Development Toolkit plug-in comes with some ready-made perspectives. You can create your custom perspectives based on existing perspectives by combining and arranging the views you want.


Figure 1. Default "Java Perspective"

JDT's most useful perspectives are the so-called Java, Java Browsing, and Debug perspectives. You can open them by selecting the Window -> Open Perspective menu. You create new perspectives by adding, deleting, and dragging views around an existing perspective. When you place more than one view on the same real estate, view selection tabs appear. You can open multiple perspectives on separate windows.

Creating A Java Project

Let's create a project. (If you want to learn more about what follows, review the help system's Java Development User Guide -> Getting Started -> Basic Tutorial section.)

  • Open the Eclipse IDE.

  • Go to File -> New -> Project... The project wizard's dialog lets you select the type of project. Select Java Project and click Next.

  • Name the project EclipseApp and specify its location in disk (the default location is the workspace folder). Click Next.

  • This Java Settings dialog allows you to specify the directories for the source and class files and libraries. First, make sure that you are looking at the dialog's Source tab. The default directory for sources should be EclipseApp/src. If it is not, select the EclipseApp folder icon, click Edit...and then click on the Create New Folder...button and name the folder src. Ensure that EclipseApp/build is the Default output folder at the dialog's bottom. If it is not, type it in.

  • Click on the Libraries tab to set up our build path. You should see your default JRE or JDK already in it. We won't need to add any libraries besides the JDK's, so click Finish.

You should now see the EclipseApp project in the Package Explorer view of Eclipse.

Working With Source Code

In the Package Explorer select the src folder and select File -> New -> Package. In the dialog, name the package mypackage and click Finish. Now select File -> New -> Class. Fill in the form to create a class named HairyClass in mypackage. The class opens in the Java editor. Notice that the stub for the constructor is marked with a // TODO task. The latter appears in the Tasks view; double-click on a task to go to its location. You can set task preferences in Windows -> Preferences -> Task Tags.

For the final contents of this class, see Listing 2. Let's enter the public field at the top. Just type pu and enter Command-Space. The code assist feature brings up the available completions in the context. You can navigate the completions menu with the arrow keys or mouse to view Javadocs, if available, or keep typing to reduce the suggestions. Hit return to fire a highlighted completion. Type the rest of the line using autocompletion to get the hang of it. When you get to third field, type up to public Ve and use autocompletion to select Vector. Note that java.util.Vector is now in the imports list. Now delete this line, retype it without autocompletion, and save it. Saving a file recompiles the class. There should now be squiggly lines around the name Vector. When the mouse hovers over the squiggles, the error message displays. There should be an error icon on the left margin of the line: depress the mouse on it to get suggestions for fixing the problem. Double-clicking on any suggestion makes Eclipse implement it. As you've been navigating the code, you've probably tried the Outline view, or perhaps you've switched to the Java Browsing perspective or created your own. Finish up this class.

Now create a class called MyMain in the same package and, in the New Java Class dialog check the box to create a main(String[] args) stub. Enter the code in Listing 2.

HairyClass is rather, well... hairy? Select the field identifier foo and then the Refactor -> Rename... menu. Rename the field to myVector. You can use the Preview... button to inspect the cascade of changes resulting from this; e.g., in MyMain, the reference to foo has changed to myVector. What's wrong with this picture? Select the myVector field name in HairyClass and Refactor -> Encapsulate Field... In the dialog that appears, make sure that keep field reference is unchecked and click OK. If you now inspect MyMain, you should see the field access changed to a method access and myVector is now private. Now proud of HairyClass, we rename it GreatClass using the same refactoring feature by selecting the class name or the class icon in the Package Explorer. Let's go further by creating an interface for it. Select the GreatClass name and Refactor -> Extract Interface... Name the interface IGreatClass and check off all methods except setMyVector(Vector). Note that GreatClass implements IGreatClass. Now let's be silly and delete getMyVector() from GreatClass and save. An error appears at the top: click for suggestions and ask it to Add unimplemented methods. Now getMyVector() is re-instated, with a pointer to the method's Javadocs in IGreatClass. For fun, inline the execute method.

Refactoring is a subject in itself. Explore the refactoring features in Eclipse and you'll see that it is very hard to break them. You can rename or move anything, with collateral refactoring of comments and literals as well, if you want. It is fun to use the refactoring dialog's Preview... button to try lots of what-ifs with your code. For more on refactoring, see the help system's Java Development User Guide -> Tasks -> Refactoring.

Listing 2: HairyClass and MyMain

Original listings of HairyClass and MyMain.
Class HairyClass
{
   public Vector foo;
   public int count;
   
   public void execute()
   {
      foo = new Vector(count);
   }
}
Class MyMain
{
   public static void main(String[] args)
   {
      HairyClass hc = new HairyClass();
      hc.count = 10;
      hc.execute();
      
      if(hc.foo.size() == 10)
         System.out.println("Hairy class, but it worked!");
   }
}

Builds

By default, the project compiles incrementally as you save files. There are also tools for generating Javadocs, JARs, adding your own "external" tools, and so on. Of course, for complex projects, the natural tools are Apache's Ant or Maven.

Eclipse has an installed Ant plug-in that provides an Ant editor, two views, and a dialog. Both views are outliners: one is used to navigate elements in the editor; the other to quickly execute any target. The Ant dialog lets you configure your build and change Ant options. Also, there's a trend to generate Ant files rather than execute black-box tools. For example, Eclipse's Javadoc generator (File -> Export -> Javadocs) will create an Ant file for you that runs Javadoc with all your settings. This lets you include the Javadoc (or any other tool's) Ant output into your main Ant.

Finally, with Eclipse's AspectJ IDE plugin, there is support for multiple build configurations, allowing you to, e.g., switch between pre-production and production time builds.

Running And Debugging

Each project can be assigned multiple configurations for launching and debugging. The debugger provides all of the basic features, including remote JVM debugging. This makes it easy to work with web application servers; and, there are IDE plugins for JBoss, Weblogic, Websphere, and Tomcat to control the server. For illustrated, step-by-step instructions for running and debugging your project, start with Help's Java Development User Guide -> Getting Started -> Basic Tutorial section.

Testing And QA

Eclipse's JUnit plug-in helps you to set up test cases by mitigating the tedium of manually creating test classes. There are wizards to create test cases and suites, run them, create test configurations and debug them. If you are interested in this, step-by-step instructions are available in the help system's Java Development User Guide -> Getting Started -> Basic Tutorial.

To understand how well your tests cover the possible runtime cases, you can instrument your code with the Clover plug-in (http://www.thecortex.net/clover). Clover also gathers statistics to analyze your code's runtime characteristics.

Finally, Eclipse's Hyades plug-in is an ambitious project to provide a reference standard for tracing, testing and monitoring; it implements the UML2 Test standard. It includes user interfaces for profiling, testing (from test case modeling to implementation), logging, and platform-specific data collection. Hyades provides modules for cross-platform and multi-platform development. Stable versions of Hyades are available from the Eclipse website.

Teamwork

If you are one of those rare individuals in a development team, you'll use the Synchronize view or, for a full workbench, the CVS Repository Exploring perspective. You can get to the latter via Window -> Open Perspective -> Other... Set up and creation of projects is straightforward. Eclipse 2.x supports SSH1, and SSH2 will be supported in Eclipse 3.0 (in early release at the time of this writing).

Conclusion

Though we've only scratched the surface of the Eclipse IDE, by now you should have an insight into Eclipse, why you might want to use it, and how it fits into the Macintosh universe. Future articles will focus on cross-platform development using Eclipse's JFace and SWT libraries, on Objective C development, and on more plug-ins.

References

Shavor, S., D'Anjou, J., et. al. The Java Developer's Guide to Eclipse, Addison-Wesley, 2003; 896 pp.

Gamma, E., Beck, K., Contributing to Eclipse: Principles, Patterns, and Plugins, Addison-Wesley, 2003; 320 pp.

Budinsky, F., Steinberg, D., et. al., Eclipse Modeling Framework, Addison-Wesley, 2003; 704 pp.

Gallardo, D., Burnette, E., McGovern, R., Eclipse in Action: A Guide for the Java Developer, Manning, 2003; 380pp.


Ruben Kleiman is a software architect and writer now developing an intelligent personal assistant. Formerly, he was Principal Scientist at Apple Computer, Inc., Architect at SGI, and Member of Technical Staff in AI at Mitre Corporation and the Microelectronics and Computer Technology Corporation. He has lectured on artificial intelligence and object-oriented systems, holds various patents, and has written for technical journals and popular magazines. Ruben lives in Northern California and he may be reached at ruben@rubenkleiman.com.

 

Community Search:
MacTech Search:

Software Updates via MacUpdate

Latest Forum Discussions

See All

Tokkun Studio unveils alpha trailer for...
We are back on the MMORPG news train, and this time it comes from the sort of international developers Tokkun Studio. They are based in France and Japan, so it counts. Anyway, semantics aside, they have released an alpha trailer for the upcoming... | Read more »
Win a host of exclusive in-game Honor of...
To celebrate its latest Jujutsu Kaisen crossover event, Honor of Kings is offering a bounty of login and achievement rewards kicking off the holiday season early. [Read more] | Read more »
Miraibo GO comes out swinging hard as it...
Having just launched what feels like yesterday, Dreamcube Studio is wasting no time adding events to their open-world survival Miraibo GO. Abyssal Souls arrives relatively in time for the spooky season and brings with it horrifying new partners to... | Read more »
Ditch the heavy binders and high price t...
As fun as the real-world equivalent and the very old Game Boy version are, the Pokemon Trading Card games have historically been received poorly on mobile. It is a very strange and confusing trend, but one that The Pokemon Company is determined to... | Read more »
Peace amongst mobile gamers is now shatt...
Some of the crazy folk tales from gaming have undoubtedly come from the EVE universe. Stories of spying, betrayal, and epic battles have entered history, and now the franchise expands as CCP Games launches EVE Galaxy Conquest, a free-to-play 4x... | Read more »
Lord of Nazarick, the turn-based RPG bas...
Crunchyroll and A PLUS JAPAN have just confirmed that Lord of Nazarick, their turn-based RPG based on the popular OVERLORD anime, is now available for iOS and Android. Starting today at 2PM CET, fans can download the game from Google Play and the... | Read more »
Digital Extremes' recent Devstream...
If you are anything like me you are impatiently waiting for Warframe: 1999 whilst simultaneously cursing the fact Excalibur Prime is permanently Vault locked. To keep us fed during our wait, Digital Extremes hosted a Double Devstream to dish out a... | Read more »
The Frozen Canvas adds a splash of colou...
It is time to grab your gloves and layer up, as Torchlight: Infinite is diving into the frozen tundra in its sixth season. The Frozen Canvas is a colourful new update that brings a stylish flair to the Netherrealm and puts creativity in the... | Read more »
Back When AOL WAS the Internet – The Tou...
In Episode 606 of The TouchArcade Show we kick things off talking about my plans for this weekend, which has resulted in this week’s show being a bit shorter than normal. We also go over some more updates on our Patreon situation, which has been... | Read more »
Creative Assembly's latest mobile p...
The Total War series has been slowly trickling onto mobile, which is a fantastic thing because most, if not all, of them are incredibly great fun. Creative Assembly's latest to get the Feral Interactive treatment into portable form is Total War:... | Read more »

Price Scanner via MacPrices.net

Early Black Friday Deal: Apple’s newly upgrad...
Amazon has Apple 13″ MacBook Airs with M2 CPUs and 16GB of RAM on early Black Friday sale for $200 off MSRP, only $799. Their prices are the lowest currently available for these newly upgraded 13″ M2... Read more
13-inch 8GB M2 MacBook Airs for $749, $250 of...
Best Buy has Apple 13″ MacBook Airs with M2 CPUs and 8GB of RAM in stock and on sale on their online store for $250 off MSRP. Prices start at $749. Their prices are the lowest currently available for... Read more
Amazon is offering an early Black Friday $100...
Amazon is offering early Black Friday discounts on Apple’s new 2024 WiFi iPad minis ranging up to $100 off MSRP, each with free shipping. These are the lowest prices available for new minis anywhere... Read more
Price Drop! Clearance 14-inch M3 MacBook Pros...
Best Buy is offering a $500 discount on clearance 14″ M3 MacBook Pros on their online store this week with prices available starting at only $1099. Prices valid for online orders only, in-store... Read more
Apple AirPods Pro with USB-C on early Black F...
A couple of Apple retailers are offering $70 (28%) discounts on Apple’s AirPods Pro with USB-C (and hearing aid capabilities) this weekend. These are early AirPods Black Friday discounts if you’re... Read more
Price drop! 13-inch M3 MacBook Airs now avail...
With yesterday’s across-the-board MacBook Air upgrade to 16GB of RAM standard, Apple has dropped prices on clearance 13″ 8GB M3 MacBook Airs, Certified Refurbished, to a new low starting at only $829... Read more
Price drop! Apple 15-inch M3 MacBook Airs now...
With yesterday’s release of 15-inch M3 MacBook Airs with 16GB of RAM standard, Apple has dropped prices on clearance Certified Refurbished 15″ 8GB M3 MacBook Airs to a new low starting at only $999.... Read more
Apple has clearance 15-inch M2 MacBook Airs a...
Apple has clearance, Certified Refurbished, 15″ M2 MacBook Airs now available starting at $929 and ranging up to $410 off original MSRP. These are the cheapest 15″ MacBook Airs for sale today at... Read more
Apple drops prices on 13-inch M2 MacBook Airs...
Apple has dropped prices on 13″ M2 MacBook Airs to a new low of only $749 in their Certified Refurbished store. These are the cheapest M2-powered MacBooks for sale at Apple. Apple’s one-year warranty... Read more
Clearance 13-inch M1 MacBook Airs available a...
Apple has clearance 13″ M1 MacBook Airs, Certified Refurbished, now available for $679 for 8-Core CPU/7-Core GPU/256GB models. Apple’s one-year warranty is included, shipping is free, and each... Read more

Jobs Board

Seasonal Cashier - *Apple* Blossom Mall - J...
Seasonal Cashier - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) - Apple Read more
Seasonal Fine Jewelry Commission Associate -...
…Fine Jewelry Commission Associate - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) Read more
Seasonal Operations Associate - *Apple* Blo...
Seasonal Operations Associate - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) - Read more
Hair Stylist - *Apple* Blossom Mall - JCPen...
Hair Stylist - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) - Apple Blossom Read more
Cashier - *Apple* Blossom Mall - JCPenney (...
Cashier - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) - Apple Blossom Mall Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.