Child pages
  • The Plug-in Architecture of Eclipse

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  • All your Java code should be in packages with the prefix de.cau.cs.rtpraktrtprak.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.

...

  1. New -> Project...
  2. In the project wizard, choose Plug-in Project and click Next.
  3. As the project name, enter de.cau.cs.rtpraktrtprak.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.rtpraktrtprak.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. Tell Eclipse that the project is inside a Git repository. Right-click on the project, click Team, and click Share Project. Select Git as the repository type and click Next. The repository information should appear and you should be able to simply click Finish.

...

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

...

  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.rtpraktrtprak.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.rtpraktrtprak.login.simple.editors.SimpleEditorPart, and the default to true.
  5. Save the manifest editor.

...

Info
titleHint

In this tutorial, we will be making use of the Standard Widget Toolkit (SWT) and JFace to build a user interface. It might be a good idea now to search for an introduction to SWT and JFace concepts on the Internet now before you proceed.

Creating the View Class

...

  1. Create a class TapeViewPart in a new package de.cau.cs.rtpraktrtprak.login.simple.views that extends the ViewPart class. (make sure that in the New Java Class wizard, the option Inherited abstract methods is checked.)
  2. Add a private field tableViewer of type TableViewer.
  3. Your TableViewPart contains a still empty method createPartControl. This method will be responsible for creating the user interface components of your view. Add the following code to create the table we want to display:

    Code Block
    languagejava
    titlecreatePartControl(...)
    Table table = new Table(parent, SWT.BORDER);
    TableColumn column = new TableColumn(table, SWT.NONE);
    column.setWidth(80);
    tableViewer = new TableViewer(table);
  4. The setFocus method controls what happens when your part gets the focus. Make sure the focus will then automatically be set to the table by adding the following code:

    Code Block
    titlesetFocus(...)
    tableViewer.getControl().setFocus();

 

 

...

Create the View Extension

We will now have to register our new view with Eclipse so that it can be seamlessly integrated into the workbench.

  1. Copy the three files tape_head.gif, head_present.gif, and head_absent.gif to the icons subfolder of your plug-in as you did it before. (You might need to refresh your project again if you did the copying outside of Eclipse.)
  2. Open the plugin.xml file in the Plugin Manifest Editor and switch to the Extensions tab.
  3. Click Add to add a new extension for the extension point org.eclipse.ui.views. Right-click the newly added extension and add a new view element through the New menu.
  4. Set the view element's properties as follows: ID de.cau.cs.rtprak.login.simple.view, name Tape, class de.cau.cs.rtprak.login.simple.views.TapeViewPart, category org.eclipse.ui, icon icons/tape_head.gif.

When you start the application, you should now be able to open your view by clicking Window -> Show View -> Other.

Add Content and Label Providers

The idea of JFace viewers is to abstract a bit from the underlying widget (in our case, the table) and instead work on data models that are to be viewed. Instead of adding items to the table directly, the table viewer is supplied with an input object, a content provider, and a label provider. The content provider allows the viewer to make sense of the input object and basically allows the viewer to access the input object's data. The label provider translates each item of data into text and icons that can be used to present the item to the user in the table.

We will now create content and label providers to do just that.

  1. Create a class TuringTape in a new package de.cau.cs.rtprak.login.simple.model with the following fields:

    Code Block
    languagejava
    titleFields
    private int headPosition = 1;
    private StringBuffer text = new StringBuffer();

    Also add corresponding getter and setter methods. (You can simply right-click somewhere in the class and choose Source -> Generate Getters and Setters.)

  2. Add two constants to the class:

    Code Block
    languagejava
    titleConstants
    public static final char START_CHAR = '\u25b7';
    public static final char BLANK_CHAR = '\u25fb';
  3. Add a method getCharacter(int pos) that calculates the tape character at position pos as follows:
    • For pos == 0, return the character START_CHAR.
    • For pos > text.length(), return the character BLANK_CHAR.
    • Otherwise, return the text character at index pos - 1.
  4. Add a private field tape of type TuringTape to TapeViewPart and initialize it with a new instance.
  5. Create a class TapeData in de.cau.cs.rtprak.login.simple.views with two fields int index and char character, and add a constructor for initialization as well as corresponding getter methods.

 

Creating an Extension Point

...