Child pages
  • The Plug-in Architecture of Eclipse

Versions Compared

Key

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

...

  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.viewsmodel with two fields int index and char character, and add a constructor for initialization as well as corresponding getter methods.
  6. Create a class TapeContentProvider in the de.cau.cs.rtprak.login.simple.views package that implements IStructuredContentProvider.
    • The methods dispose() and inputChanged() may remain empty.
    • The method getElements() must return an array of objects, where each object must contain all necessary data to be displayed in a single row of the table. The number of returned objects corresponds to the number of rows.
    • Suppose the input element is an instance of TuringTape. The result of getElements() shall be an array of TapeData elements. The size of the array shall be one more than the maximum of the tape head position and the length of the tape text. The index and character of each tape data element shall be filled with i and the result of turingTape.getCharacter(i), respectively, where i is the array index of the element.
  7. Create a class TapeLabelProvider in the de.cau.cs.rtprak.login.simple.views package that extends BaseLabelProvider and implements ITableLabelProvider.
    • Add a private field tape of type TuringTape that is initialized from the constructor.
    • Add fields presentImage and absentImage of type Image.
    • Initialize each image using the following code, where path_to_image is icons/head_present.gif and icons/head_absent.gif, respectively:

      Code Block
      languagejava
      image = Activator.imageDescriptorFromPlugin(Activator.PLUGIN_ID, "path_to_image").createImage();
    • Override the implementation of dispose() in TapeLabelProvider to dispose both images after calling super.dispose().
    • In getColumnImage() and getColumnText(), first check whether the element is an instance of TapeData and the column index is 0, and return null otherwise. If the check passes, return the following:
      • getColumnImage(): presentImage if the index given by the tape data element equals the current value of tape.getHeadPosition(), absentImage otherwise.
      • getColumnText(): a String containing the character of the tape data element.
  8. Add the following lines to createPartControl() in TapeViewPart:

    Code Block
    tableViewer.setContentProvider(new TapeContentProvider());
    tableViewer.setLabelProvider(new TapeLabelProvider(tape));
    tableViewer.setInput(tape);

 

Creating an Extension Point

...