Section 10.4. Eclipse: The Source of SWT


10.4. Eclipse: The Source of SWT

Eclipse is yet another GUI IDE. The Standard Widget Toolkit (SWT) was invented as part of this project. Since Eclipse uses SWT for its graphics, it has the most familiar GUI look and feel, and it is the fastest performer on lower end hardware.[5] Eclipse is built as an IDE toolkit. Although it was developed in Java/SWT, you can use it to develop AWT/Swing applications. It is build around a plug-in architecture, so it can be an IDE for virtually any language. To use it for Java, you must actually install the Java plug-ins.

[5] It's the fastest performer on high-end hardware too, but the difference is much less perceptible. Really fast and incredibly fast are hard for humans to discern.

10.4.1. Selecting and Installing Eclipse

The main site for obtaining Eclipse is www.eclipse.org. Installing Eclipse, particularly for a single user, is incredibly easy. But first, you have a few choices to make as to what to download. As of this writing, the current production release of Eclipse is 2.1.2. If you follow the Downloads link from the main page to the 2.1.2 build, you will see a fairly lengthy list of download choices.

The first major choice you must make is whether or not you plan to write your own plug-ins and extensions to Eclipse. If you do, you will probably wish to download the Eclipse Software Development Kit or the source code and build Eclipse for yourself. We strongly recommend that you choose the Eclipse SDK binary for GTK. The Motif UI is quite dated in comparison. The Eclipse SDK contains the Eclipse Platform (which you need), the Java Development Toolkit (which you need), and the Eclipse Platform Development Kit (which you need only if you plan to develop plug-ins for Eclipse). But by downloading the Eclipse SDK package, you get everything you need in one go. You could also download the Eclipse source package and build the whole thing yourself; save that for a spare week. For now, start with a prebuilt binary.

If you scroll down, you will see a collection of files that have "platform" in their names. You will note that there are two choices of Linux binary: one is Motif, the other GTK. If you are not familiar with these, Motif and GTK are two common extensions to the X Window API that provide widgets and other common functions and UI features. One of these, Motif, is rather old and (to brashly add opinion) dated in appearance, but it is very stable and mature. The other, GTK, stands for GIMP Toolkit and was developed to support the remarkable GNU Image Manipulation Program (GIMP). There are other widget/UI libraries that run on top of X Window, notably the Qt library used by KDE.

So, which to use? If you read the documentation on the Eclipse Web site, you will see that the Motif version has been more heavily tested and is available for other platforms than Linux. This is probably because Motif is standard on most commercial UNIX versions, and thus is where emphasis was placed to get the "most bang for the buck" in development and testing.

However, we much prefer the look of the GTK version and, to date, have found no major problems with it, so that is what we use for our examples. There should be no functional difference between the twomerely differences in the look and feel of menus, toolbars, and dialogs. One reason to select Motif might be if you are working in a mixed environment of Linux and other UNIX platforms, where you may be forced to use the Motif version on some platforms, and do not want the "cognitive dissonance" of switching between the two.[6]

[6] Please note that the differences are fewer and smaller than the differences involved in switching between any common X Window desktop and Microsoft Windows. If you can handle that (and many of us do every day), switching between Motif and GTK versions of Eclipse will be no problem for you.

So, step one: Download eclipse-SDK-2.1.2-linux-gtk.zip.

The Eclipse platform is a "generic IDE." You will see the term perspective all over Eclipse. A perspective is kind of a collection of tools in the IDE. The package you just downloaded contains a generic perspective called Resource. A perspective is a set of views, which are panes within the IDE, each having a specific purpose, such as editing the project contents, editing files, keeping a task list, and so on, as well as menus and toolbars relevant to those views. The Resource perspective has its uses, but it is not the main one you will be using as a Java programmer. As a Java programmer, you will most likely want the Java perspective.[7]

[7] Although you will also often be using the Debug perspective.

First, you must decide if you are going to install Eclipse in a common location (such as /usr/local or /opt), or if you are just going to install it in your home directory for your own use. The answer to this question, naturally, depends on whether or not you have root access on the machine and whether or not multiple people actually use the machine.

Caution

We are assuming you already have at least one Java SDK installed. If you do not, refer to Chapter 6 for some tips on installing Java SDKs.


We're going to install in the user's home directory. Doing this could hardly be simpler. So, step two: From your home directory, type:

 $ unzip eclipse-SDK-2.1.2-linux-gtk.zip 

That's it. You're done. Now just cd to the newly created eclipse directory and type ./eclipse. The first time you do this, you will see a "Completing the install" banner (Figure 10.11).

Figure 10.11. Running Eclipse for the first time


During this initial run some workspace directories and data files are set up. These store meta-information about projects and perspectives. After a moment, you will get the standard splash screen (Figure 10.12).

Figure 10.12. Eclipse splash screen


Following this, you will see the initial Eclipse IDE, with a welcome screen in the default Resource perspective (Figure 10.13).

Figure 10.13. The Eclipse Resource perspective


Eclipse works with projects. A project is a collection of files that you manage as a group. Usually a project is a single program, although it need not be. Eclipse remembers the state of all projects. If you close Eclipse in the middle of a debug session on a project, the next time you open Eclipse, it will have that same project open in the Debug perspective. If you then switch to another project and switch back, you will come back to the Debug perspective. Eclipse remembers. But we get ahead of ourselves here. You need to create a project.

10.4.2. Using Eclipse for a New Project

Now that you have Eclipse up and running (Figure 10.13), you will want to create a Java project. Eclipse has "wizards" (to use the Microsoft Windows terminology) for creating projects. From the main menu, select File>New>Project. You will get the screen shown in Figure 10.14.

Figure 10.14. Step one: New project


Now, you are not an idiot. This is not "Java Applications Programming on Linux for People with Well Below Average Intelligence." We're not going to walk you slowly and painfully through a screenshot of every window Eclipse can display and pretend that this is "educational." We like trees too much to do that. So let's pick up the pace a bit. The first screen in Figure 10.14 asks you to select the type of project. The next screen asks for a project name and it automatically chooses a directory to house the project. In Section 10.4.3 we will talk about changing away from this default. For now, trust Eclipse to do it right. Enter a project name and hit the Next button.

The next screen shows a tabbed display. The first tab allows you to add folders for source code. If you have already worked out a directory structure for your project, you may build it here. The next tab is the Projects tab. Here you specify other projects on which this project depends. The next tab is the Libraries tab. Basically, it lets you specify the project's classpath. Eclipse puts its preferred set of JARs on the classpath by default, including those that are standard with whichever Java runtime Eclipse found on startup. The last tab is called Order and Export; it allows you to specify the order in which source folders should be built, as well as to specify which folders are accessible to other projects that name this project on their Projects tabs (in other words, this is the "other side" of the Projects tab).

That's the final wizard box. Hit the Finish button. A dialog box pops up to tell you that the project you just created is associated with the Java perspective. Since you are currently in the Resource perspective, it asks you if it may switch you to the Java perspective. Hit the Yes button, and you will be rewarded with the Java perspective display (Figure 10.15).

Figure 10.15. The Java perspective


At this point, your exploration of the Eclipse tools would be more fruitful than anything we could tell you. There is a marvelous book on Eclipse, The Java Developer's Guide to Eclipse by Sherry Shavor et al. from Addison-Wesley. We encourage you to seek out that book.

10.4.3. Using Eclipse for an Existing Project

In the previous section, we mentioned that the second wizard screen in setting up a Java project allowed you to override the default path for a project. If you have an existing Java program, point the project path to the directory that is the base for that program's packages. When you create the project (in other words, when you hit the Finish button in the wizard), Eclipse will scan that directory and analyze what it finds there. It does an excellent job of importing a project and "eclipsifying" it, even to the point of recognizing and analyzing an ant's build.xml file.

10.4.4. Working with Eclipse

Eclipse is a huge topic. We can't devote enough space to it for this chapter to qualify as a user guide. The best we can do is to offer you a handful of tips.

  • The Java perspective consists mainly of the Package Explorer on the left, the edit window in the middle, the outline view in the right, and a bottom window that changes based on context. Initially, it is a task list. When you run a Java application, the console output is displayed there, overlaying the task list.

  • You can do a lot of what you need to get started on a project by right-clicking in the Package Explorer. For example, you can create a package by right-clicking and selecting New>Package. When you type a new package name into the resulting dialog box, all required folders are created under the project.

  • You can create new classes and interfaces in the same way. If you right-click on a package in the Package Explorer and select New>Class or New>Interface, an appropriate dialog box comes up, and a skeletal file is created in the appropriate place.

You can compile, run, and debug programs by hitting buttons on the toolbar, by selecting from the menu, by right-clicking almost anywhere, and by keyboard shortcuts. To put it plainly: Eclipse is a modern, rich IDE that works like other IDEs you have seen.

Eclipse's real advantages lie in some of the dynamism it offers. As you know, the authors of this book like text mode and command line, but we must admit that Eclipse's refactoring features are a great timesaver. For example, when you use the refactoring tools to change a method, you can be certain that every call to that method, everywhere in the project, is updated. Sure, we staunch CLI guys will tell you that you can use pipes and sed to similar effect, but even we must admit that you can miss some. We stand by what we have said: Know all the tools, and you can then choose the right one. But if all you have is a hammer, you'll end up using it to repair a china cup.



    Java Application Development with Linux
    Java Application Development on Linux
    ISBN: 013143697X
    EAN: 2147483647
    Year: 2004
    Pages: 292

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