Eclipse icon

In the Editors lecture you learned how to create a new editor in order to extend the capabilities of Eclipse. The solution presents a simple but functionally complete editor, a "mini-spreadsheet". It demonstrates how you can implement an editor that supports basic functionality, contributes actions, and allows others to extend its capabilities.

Note: The Editors topic relies on your understanding of the basic structure and capabilities of Views. Similarly, this editor solution relies on your understanding the Views solution found in the project com.ibm.lab.soln.views.

Running the Solution

To run the example, launch the run-time instance of Eclipse (Run > Run As > Run-time Workbench). Create a new mini-spreadsheet from File > New > Other > Mini-spreadsheet. The editor will be opened automatically.

Roadmap of the Solution

As described above, this solution is partitioned into two projects. The first, com.ibm.lab.soln.editor, defines the base functionality. The second, com.ibm.lab.soln.editor.extras, contributes actions to the editor's pulldown menu, toolbar, and pop-up menu. Since there are a fair amount of classes involved, they are arranged in different packages to make it clearer what roles the classes fulfill.

Note:This plug-in should have been separated into two plug-ins; one for the user interface, another for the model classes in the com.ibm.lab.soln.editor.core package. For simplicity's sake, the model and UI are in the same plug-in.

Base Model

Located in the com.ibm.lab.soln.editor.core package, these represent the model (non-UI) classes.
Class (All) Description
MiniSpreadsheet Model of a spreadsheet, containing 0...n rows.
IMiniSpreadsheetRow Model of a spreadsheet row. It is convenient to have a separate model for the rows, since JFace viewers, such as TableViewer, are row-oriented.
IMiniSpreadsheetListener Change notification interface.

Base User Interface

Located in the com.ibm.lab.soln.editor.ui package, these represent the base user interface classes expected by JFace.
Class (All) Description
MiniSpreadsheetContentProvider Mediator between the model, MiniSpreadsheet, and structured content viewers like TableViewer.
MiniSpreadsheetEditor The spreadsheet editor which provides a simple interface to modifying spreadsheet files (*.mss).
MiniSpreadsheetImages Convenience class defining all the image descriptors that the editor user interface requires.
MiniSpreadsheetLabelProvider Mediator between the spreadsheet's underlying elements, instances of MiniSpreadsheetRow, and the viewer.
MiniSpreadsheetUIPlugin Singleton representing the plug-in itself.

Base Actions

Located in the com.ibm.lab.soln.editor.ui.actions package, these represent the base user interface actions, that is, those actions that are defined by the editor itself, not contributed.
Class (All) Description
AppendRowAction Action to add a row to the end of the spreadsheet.
ChangeAlignmentAction Action that changes the alignment of the table columns. For this implementation, the column alignment isn't saved. In a more complete implementation, this would be saved as spreadsheet metadata.
ClearAllAction Action to set all cells to an empty string.
MiniSpreadsheetEditorAction Superclass to all the editor actions.
MiniSpreadsheetEditorActionBarContributor Responsible for adding the editor's menu choices and toolbar buttons. This class is a singleton, i.e., it is shared by all active instances of this editor.
MiniSpreadsheetRowActionFilter Defines an example action filter, used to query state information from MiniSpreadsheetRow instances using <objectState> tags. See the com.ibm.lab.soln.editor.extras project for an example of its use.
MiniSpreadsheetRowActionFilterFactory Manages the creation of instance of MiniSpreadsheetRowActionFilter.
RemoveRowAction Action to remove the selected rows.
ShowTotalAction Action to display the total of all selected integer rows.

Base Wizard

Located in the com.ibm.lab.soln.editor.ui.wizards package, defines the wizard necessary to create a new mini-spreadsheet.
Class (All) Description
MiniSpreadsheetWizardNewFileCreationPage An extension of the standard file creation wizard, it adds fields for the spreadsheet dimensions. Note that in this implementation, the user can add and delete rows, but cannot change the number of columns after the spreadsheet is created.
NewMiniSpreadsheetWizard Wizard to drive the spreadsheet file creation (*.mss).

Extended Actions

These classes are defined in a new plug-in, contained in the project com.ibm.lab.soln.editor.extras. The steps for contributing actions is different than the steps that an editor follows to define its own actions. The purpose of this plug-in is to clearly demonstrate this difference.
Class Description
IncrementRowValuesObjectActionDelegate Action to increment the integer values in the selected row(s). It performs an operation similar to those in the base context menu actions, but this action is contributed.
ShowMaxEditorActionDelegate Action to show the maximum of the integers in the table. It performs an operation similar to those in the base window pulldown menu actions, but this action is contributed.
DoubleActionDelegate Action to double integer values in the selected row(s). It performs an operation similar to those in the base toolbar button actions, but this action is contributed.

Notice that all the actions are subtypes of IActionDelegate. This extra level of indirection between an action contribution and the action itself allows the Workbench to defer loading the plug-in that is contributing the actions.

© Copyright International Business Machines Corporation, 2003.
All rights reserved.