...
Create a class
TuringTape
in a new packagede.cau.cs.rtprak.login.simple.model
with the following fields:Code Block language java title Fields 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.)
Add two constants to the class:
Code Block language java title Constants public static final char START_CHAR = '\u25b7'; public static final char BLANK_CHAR = '\u25fb';
- Add a method
getCharacter(int pos)
that calculates the tape character at positionpos
as follows:- For
pos == 0
, return the characterSTART_CHAR
. - For
pos > text.length()
, return the characterBLANK_CHAR
. - Otherwise, return the text character at index
pos - 1
.
- For
- Add a private field tape of type
TuringTape
toTapeViewPart
and initialize it with a new instance. - Create a class
TapeData
inde.cau.cs.rtprak.login.simple.viewsmodel
with two fieldsint index
andchar character
, and add a constructor for initialization as well as corresponding getter methods. - Create a class
TapeContentProvider
in thede.cau.cs.rtprak.login.simple.views
package that implements IStructuredContentProvider.- The methods
dispose()
andinputChanged()
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 ofgetElements()
shall be an array ofTapeData
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 withi
and the result ofturingTape.getCharacter(i)
, respectively, wherei
is the array index of the element.
- The methods
- Create a class
TapeLabelProvider
in thede.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
andabsentImage
of type Image. Initialize each image using the following code, where
path_to_image
isicons/head_present.gif
andicons/head_absent.gif
, respectively:Code Block language java image = Activator.imageDescriptorFromPlugin(Activator.PLUGIN_ID, "path_to_image").createImage();
- Override the implementation of
dispose()
inTapeLabelProvider
to dispose both images after callingsuper.dispose()
. - In
getColumnImage()
andgetColumnText()
, first check whether the element is an instance ofTapeData
and the column index is 0, and returnnull
otherwise. If the check passes, return the following:getColumnImage()
:presentImage
if the index given by the tape data element equals the current value oftape.getHeadPosition()
,absentImage
otherwise.getColumnText()
: aString
containing the character of the tape data element.
- Add a private field tape of type
Add the following lines to
createPartControl()
inTapeViewPart
:Code Block tableViewer.setContentProvider(new TapeContentProvider()); tableViewer.setLabelProvider(new TapeLabelProvider(tape)); tableViewer.setInput(tape);
Creating an Extension Point
...