Skip to main content

By clicking Submit, you agree to the developerWorks terms of use.

The first time you sign into developerWorks, a profile is created for you. Select information in your profile (name, country/region, and company) is displayed to the public and will accompany any content you post. You may update your IBM account at any time.

All information submitted is secure.

  • Close [x]

The first time you sign in to developerWorks, a profile is created for you, so you need to choose a display name. Your display name accompanies the content you post on developerworks.

Please choose a display name between 3-31 characters. Your display name must be unique in the developerWorks community and should not be your email address for privacy reasons.

By clicking Submit, you agree to the developerWorks terms of use.

All information submitted is secure.

  • Close [x]

Create an Eclipse game plug-in, Part 1: Getting started

How to build fun plug-ins for Eclipse using the SWT, OpenGL, and the LWJGL

Trebor Fenstermaker, Software Consultant, Sunnyside Avenue Software, LLC
Although he's programmed in Java since 1999, Trebor Fenstermaker was, for much of that time, highly suspicious of Java IDEs and was a die-hard command-line user, even doing all his code editing in vi -- until a colleague showed him that he really could be more efficient with Eclipse. He now evangelizes his fellow UNIX command-line refugees on its wonders and enjoys exploring its more powerful features -- including its endless possibilities for expansion through custom plug-ins.

Summary:  Although most users think of Eclipse as an Integrated Development Environment (IDE) for building Java™ applications, it is really something much more basic. Eclipse is a framework for building plug-ins, allowing any developer to extend its functionality to solve nearly any problem, just by leveraging a set of APIs and readily available libraries. In this four-part "Create an Eclipse game plug-in" tutorial series, you will solve a pressing problem most programmers encounter daily: how to break away to play a quick video game without switching applications and making it obvious. You will also learn the Eclipse plug-in architecture and learn how to define your own plug-in, develop an interface using SWT, and create code that interacts with other Eclipse resources.

View more content in this series

Date:  07 Mar 2006
Level:  Intermediate PDF:  A4 and Letter (1257 KB | 35 pages)Get Adobe® Reader®

Activity:  17934 views
Comments:  

Creating the plug-in

Let's start the process rolling by using the Eclipse Plug-in wizard to define a plug-in.

Start Eclipse and define your project

Start Eclipse and choose File > New > Project.

On the New Project screen, select the Plug-in Development folder and choose Plug-in Project, as shown in Figure 1.


Figure 1. Selecting the Plug-in Project wizard
Selecting the Plug-in Project wizard

On the New Plug-In Project screen (see Figure 2), enter the name of your plug-in. Because this is a shootout game, use com.devworks.tutorial.shootout. Keep the default directory created by this name; it will be located under your workspace. Be sure the Create a Java Project box in Project Settings is checked, and keep the defaults of /src and /bin for the folder names. Finally, for your target platform, choose Eclipse V3.2.


Figure 2. Setting the project name and directories
Setting the project name and directories

Describing the plug-in

Each plug-in is described by an XML manifest file called plugin.xml, which comes bundled with your package. The Plug-in Properties of this next screen (see Figure 3) save you from having to create this by hand -- always a nice thing to avoid. Leave the values as they are, but notice what kind of information the manifest provides: version, name, provider, etc.

On the Plug-in Options screen, ensure that the checkbox is selected for Generate an activator and that the class name is set to com.devworks.tutorial.shootout.ShootoutPlugin. Also make sure the checkbox is selected for This plug-in will make contributions to the UI.

Finally, answer No to the question of creating a rich client application. This is used to create a threadbare version of Eclipse that allows you to build an entire application on the Eclipse framework. You're just creating a single plug-in here.


Figure 3. Entering the plug-in properties that will be stored in the manifest
Entering the plug-in properties that will be stored in the manifest

Choosing the template for the plug-in

The next screen of the wizard, shown in Figure 4, asks if you'd like to use a template. For your shootout game, you'll be creating a view, so select the checkbox Create a plug-in using one of the templates, then select the one labeled Plug-in with a view. As the text on the right panel of this figure explains, this template will give you the basic functionality of workbench view, including support for menus, tool bars, and so forth.


Figure 4. Selecting the plug-in with a view template
Selecting the plug-in with a view template

Setting the view properties

On this next screen, shown in Figure 5, you'll define various settings for your view. Again, in keeping with the shootout theme of the game, ensure that your View Class Name is ShootoutView and the View Name is Shootout View (note the space). Change the View Category name to Devworks Tutorial. This will keep things tidy later when you go to open your view in the Open View screen. Be sure Add the view to the resource perspective is checked so you can see it there. To start with, you'll be expanding on the basic Table Viewer model, so select the Table viewer as the type of viewer that should be hosted in this view.


Figure 5. Setting the view properties
Setting the view properties

Finally, on the last screen (see Figure 6), keep the default options (in this case, all features are chosen). Some of these will be used later, but all are instructive to see as you examine the code generated by the wizard.


Figure 6. Selecting the actions supported by the view
Selecting the actions supported by the view

Finishing the wizard and examining the results

Click Finish, and Eclipse will ask if you want to switch to the perspective associated with the plug-in development. Say Yes, and it will generate the stub of your project and switch you to the appropriate perspective.

Your Eclipse desktop should now show you the plug-in view (see Figure 7). If you explore the com.devworks.tutorial.shootout package in the Package Explorer, you will see that the wizard has generated the two classes: ShootoutPlugin.java and ShootoutView.java. These match the names you chose in the wizard.


Figure 7. The plug-in perspective and generated classes
The plug-in perspective and generated classes

The ShootoutPlugin extends the AbstractUIPlugin defined by the Eclipse plug-in architecture and is the launching point for the behavior of your plug-in. The ShootoutView class extends the ViewPart abstract class and was created because you asked the wizard to provide a "Plug-in with a view." You will add your widgets and other visual elements to this class.

The wizard also generated the plugin.xml using the values you supplied on the appropriate screen. This is the manifest file that will be bundled with your final plug-in and is used to describe the package to Eclipse. Eclipse provides a nice set of tabular screens for editing the plug-in.xml, as seen in Figure 7. You can use this set of screens to adjust properties related to your plug-in -- specifically, dependencies on other plug-ins.

2 of 9 | Previous | Next

Comments



static.content.url=http://www.ibm.com/developerworks/js/artrating/
SITE_ID=1
Zone=Open source
ArticleID=104971
TutorialTitle=Create an Eclipse game plug-in, Part 1: Getting started
publish-date=03072006
author1-email=tcf@sunnysideave.com
author1-email-cc=