Child pages
  • The Plug-in Architecture of Eclipse
Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 11 Next »

Warning

This tutorial isn't complete yet!

This tutorial will teach you the basics of writing plugins that run inside the Eclipse framework. You will learn about editors, views, and extension points by creating one of each yourself.

Preliminaries

There's a few things to do before we dive into the tutorial itself. For example, to do Eclipse programming, you will have to get your hands on an Eclipse installation first. Read through the following sections to get ready for the tutorial tasks.

Required Software

For this tutorial, we need you to have Eclipse and Git installed:

  1. Install Eclipse. For what we do, we recommend installing the Eclipse Modeling Tools, with a few extras. Our Wiki page on getting Eclipse has the details: simply follow the instructions for downloading and installing Eclipse and you should be set.
  2. You should already have obtained a working Git installation for the first tutorial.

General Remarks

Over the course of this tutorial, you will be writing a bit of code. Here's a few rules we ask you to follow:

  • All your Java code should be in packages with the prefix de.cau.cs.rtprakt.login, where login is your login name as used for your email address at the institute. From now on, this rule will apply to all tutorials. Once we start with the actual practical projects, we will choose another package name.
  • All Java classes, fields, and methods should be thoroughly commented with the standard Javadoc comment format. Javadoc comments are well supported by Eclipse, providing code completion, syntax highlighting, and further features to help you. The code inside your methods should also be well commented. Try to think about what kinds of information would help someone unfamiliar with your code understand it.
  • As you will already have noticed during the first tutorial, our tutorials use Turing machines as the underlying theme. This is partly because we're computer scientists and computer scientists are expected to choose computer sciency examples, but mostly because Turing machines work great as examples for the different kinds of topics we will be covering with you. You may thus want to take some time to read up again on the topic. Wikipedia or the material of your Theoretical Computer Science lecture might be a great start.
  • During this tutorial, we will be using Git mostly from the command line instead of using Eclipse's built-in Git support. This is because we've found Eclipse's Git support to be too unstable and buggy for us to trust it completely.

Finding Documentation

During the tutorial, we will cover each topic only briefly, so it is always a good idea to find more information online. Here's some more resources that will prove helpful:

  • Java Platform, Standard Edition 6 API Specification
    As Java programmers, you will already know this one, but it's so important and helpful that it's worth repeating. The API documentation contains just about everything you need to know about the API provided by Java6.
  • Eclipse Help System
    Eclipse comes with its own help system that contains a wealth of information. You will be spending most of your time in the Platform Plug-in Developer Guide, which contains the following three important sections:
    • Programmer's Guide
      When you encounter a new topic, such as SWT or JFace, the Programmer's Guide often contains helpful articles to give you a first overview. Recommended reading.
    • References -> API Reference
      One of the two most important parts of the Eclipse Help System, the API Reference contains the Javadoc documentation of all Eclipse framework classes. Extremely helpful.
    • References -> Extension Points Reference
      The other of the two most important parts of the Eclipse Help System, the Extension Point Reference lists all extension points of the Eclipse framework along with information about what they are and how to use them. Also extremely helpful.
  • Eclipsepedia
    The official Eclipse Wiki. Contains a wealth of information on Eclipse programming.
  • Eclipse Resources
    Provides forums, tutorials, articles, presentations, etc. on Eclipse and Eclipse-related topics.

You will find that despite of all of these resources Eclipse is still not as well commented and documented as we'd like it to be. Finding out how stuff works in the world of Eclipse can thus sometimes be a challenge. However, this does not only apply to you, but also to many people who are conveniently connected by something called The Internet. It should go without saying that if all else fails, Google often turns up great tutorials or solutions to problems you may run into. And if it doesn't, Miro and I will be happy to help you as well.

Preparing the Repository

ToDo

Write this section.

Creating a Simple Text Editor

OK, with all the preliminaries out of the way let's get working. Fire up Eclipse, choose an empty workspace, close the Welcome panel it will present you with and follow the following steps.

Creating a New Plugin

For our text editor to integrate into Eclipse, we need to create a plug-in project for it:

  1. New -> Project...
  2. In the project wizard, choose Plug-in Project and click Next.
  3. As the project name, enter de.cau.cs.rtprakt.login.simple. Uncheck Use default location (which would put the project into your workspace), and put it into your local clone of the Git repository instead (the Location should read something like /path/to/git/repository/de.cau.cs.rtprakt.login.simple). Click Next.
  4. As the name, enter Simple (login). Also, make sure that Generate an activator and This plug-in will make contributions to the UI are both checked. Click Finish. (Eclipse might ask you whether you want to switch to the Plug-in Development Perspective, which configures Eclipse to provide the views that are important for plug-in development. Choose Yes. Or No. It won't have a big influence on your future...)
  5. Eclipse has now created your new plug-in and was nice enough to open the Plug-in Manifest Editor, which allows you to graphically edit two important files of your plugin: plugin.xml and META-INF/MANIFEST.MF. (By the way, this would be a great time to research the editor and the two files online.) Basically, those two files provide information that tell Eclipse what other plug-ins your plug-in needs and how it works together with other plug-ins by providing extensions and extension points. Our new plug-in will depend on two other plug-ins, so switch to the Dependencies tab of the editor and add dependencies to org.eclipse.ui.editors and org.eclipse.jface.text. Save the editor and close it. (You can always reopen it by opening one of the two mentioned files from the Package Explorer.)
  6. TODO: GIT PROJECT

Create the Main Editor Class

We will now create the class that implements the simple text editor. There won't be any programming involved here since we're lazy; instead, we will just inherit from an existing simple text editor.

  1. New -> Class.
  2. Package: de.cau.cs.rtprakt.login.simple.editors. Name: SimpleEditorPart. Superclass: org.eclipse.ui.editors.text.TextEditor. Click Finish.

Register the Editor

For the editor to be available inside Eclipse, we will have to register it by adding an extension to an extension point.

  1. Copy the attached file to a new subfolder icons in the plug-in folder (right-click the plug-in folder in the Package Explorer and choose New -> Folder...). You can copy the file by importing it from inside Eclipse (File -> Import... -> File System) or by copying it from outside Eclipse and refreshing the plug-in project afterwards (right-click the plug-in folder in the Package Explorer and choose Refresh).
  2. Open the Plug-in Manifest Editor again and switch to the Extensions tab.
  3. Click Add..., choose the org.eclipse.ui.editors extension point and click Finish.
  4. The extension point is now shown in the list of extensions, along with an editor extension. Select that extension and edit its details using the fields on the right. Set the ID to de.cau.cs.rtprakt.login.simple.editor, the name to Simple Text Editor, the icon to icons/turing-file.gif, the extensions to simple, the class to de.cau.cs.rtprakt.login.simple.editors.SimpleEditorPart, and the default to true.
  5. Save the manifest editor.

Test the Editor

It's time to test your new simple editor in a new Eclipse instance.

  1. Switch back to the Overview tab of the Plug-in Manifest Editor.
  2. Click Launch an Eclipse Application.
    • For future tests, you can now select Eclipse Application in the run menu.
    • To enable debug mode for your test instances: open the Run Configurations dialog, select the Arguments tab of the Eclipse Application configuration, and add -debug -consoleLog as program arguments. This dumps all errors and exceptions to the console view, so you can directly see what went wrong.
    • To improve performance, select only the plugins that are necessary: in the Plug-ins tab select Launch with plug-ins selected below only, deselect Target Platform, select Workspace, and then Add Required Plug-ins.
      • Make sure that org.eclipse.ui.ide.application is also selected, else you won't be able to launch Eclipse.
      • The requirements list needs to be updated when the dependencies of your plugins have changed; click Add Required Plug-ins again for updating. 
  3. In the new Eclipse instance, click New -> Project... -> General -> Project. Enter test as the project name.
  4. Right-click the new project and click New -> File... As the file name, enter test.simple. This will create a new file with that name and open the file in your newly added text editor. (You can see that it is your editor by looking at the editor icon, which should look like the icon you downloaded and put into the icons folder.)

Creating a Simple View

WRITE THIS SECTION

 

Creating an Extension Point

WRITE THIS SECTION

 

 

 

 

  • No labels