4.1. Hyperbola Hello WorldYou are now set up to develop Eclipse RCP applications. Here we show you how to use the built-in wizards and tooling to create a simple skeleton for the Hyperbola chat client developed throughout the book. The first thing you need is a plug-in project to hold your code. Go to File > New > Project... to start the new project wizard. Choose Plug-in Project and click Next. On this page, enter the project name. Since you are just starting on Hyperbola, enter "org.eclipsercp.hyperbola". Click Next and you should see a page similar to Figure 4-1. Figure 4-1. Defining the plug-in content
Here, enter the information about the plug-in itselfits id, version, name, etc. Based on the project name, the wizard guesses reasonable initial settings for most fields. The only things to change are:
Note Notice here that the Classpath field is empty. As of Eclipse 3.1, it is common practice to ship a plug-in as a JAR file. In this case, the plug-in itself is on the classpath, so there is no need to specify a value. Click Next and the wizard moves to the RCP Templates page. There are templates of varying complexity. For this part of the book, pick the Hello RCP template to create what is probably the simplest RCP application possible. Click Next to advance the wizard to the page shown in Figure 4-2. Here, you identify the Hyperbola application and give it a window title and perspective name, etc. You should only have to change the Application window title. Figure 4-2. Identifying the contents of the application
That's it. Click Finish to create your first Eclipse RCP application. You may be prompted to change to the Plug-in Development perspective. This is an arrangement of views in the Eclipse development environment that is particularly useful for plug-in development. We suggest that you select Yes here. When the wizard completes, your workspace contains a single project with the name org.eclipsercp.hyperbola, as shown in Figure 4-3. The project contains an src folder that contains the Java source files generated from the template by the new project wizard. Figure 4-3. Hello Hyperbola project structure
If you selected Yes to switch to the plug-in development perspective, your new plug-in is opened in a plug-in editor. The editor provides a comprehensive view of the various parts of the plug-in definition captured in different files such as plugin.xml, MANIFEST.MF, and build.properties. The plug-in editor works on all of these at onceyou can edit all aspects of a plug-in in one place. Figure 4-4 shows the first page of the editor. Figure 4-4. Hyperbola plug-in editor
Note If you close the plug-in editor and want it back, just double-click on the plugin.xml or MANIFEST.MF files, or use Open on the context menu for the files. To take Hyperbola for a spin, use the links in the Testing section of the Overview page. Click on the Launch an Eclipse application link and run Hyperbola. This launches Hyperbola as a separate Eclipse RCP application in its own JVM. As you can see from Figure 4-5, it doesn't do much, but it's a start. Figure 4-5. Simple Hyperbola shell
While the plug-in editor is open, take a look around. Along the bottom of the editor there are tabs for the different aspects of the plug-in. Go to the Dependencies page and notice that the Hyperbola plug-in depends on two other plug-ins: org.eclipse.core.runtime and org.eclipse.ui. This means that the Hyperbola plug-in can use classes exposed by those plug-ins. It also means that classes in other plug-ins are not available to Hyperbola. This control over class visibility is fundamental to the Eclipse notion of modularity and your ability to build systems from sets of plug-ins using Eclipse. The Dependencies page also has some useful Dependency Analysis tools to help you navigate the dependencies between plug-ins, find unused dependencies, look for cycles, etc.
Take a look at Hyperbola's Extensions page next. When PDE generated the Hyperbola skeleton, it added two extensions: an application and a perspective. If you poke around in here, you can see some of the values entered earlier as well as the names of various classes that were generated by the template. These extensions are the mechanism for linking classes into the Eclipse infrastructure. For example, Figure 4-7 shows the Hyperbola perspective extension. Notice how it lists the new perspective class (org.eclipsercp.hyperbola. Perspective) and links it into the org.eclipse.ui.perspectives extension point. Figure 4-7. Hyperbola extensions
Take a look at the other pages in the editor if you like. If not, there will be plenty of opportunity to use them later. The next section walks through the generated code and highlights its structure. This is followed by a section on running and debugging Eclipse applications. Subsequent chapters build on this base and add more and more function. |