Creating an Aptana Editor class
From Aptana Development
This page describes how to create a new Aptana Editor class.
Contents |
Introduction
In this page, we discuss the additional supporting classes that need to be created when you define a new Editor sub-classed from UnifiedEditor. This examples assumes we are creating an SQL editor. Feel free to substitute class names as is appropriate for the language editor you are creating.
Instructions
MIME Type Constant
Aptana uses MIME types to identify languages and these are used throughout the code. Aptana uses MIME type constants for each language in the language's parsing package to minimize typos. For example, the Aptana SQL editor defines com.aptana.ide.editor.sql.parsing.SQLMimeType as the following:
package com.aptana.ide.editor.sql.parsing;
public class SQLMimeType
{
public static final String MimeType = "text/sql";
}
Modifying the Editor Class
You should have already created an Editor class that is a UnifiedEditor sub-class. Your next step is to fill in the required methods to complete the editor's definition.
- Add the following to the Editor's constructor so that it is included when you search for plugin preferences:
addPluginToPreferenceStore(SQLPlugin.getDefault());
- Add the default file extension this editor works with. This should not included the leading period. For the SQL editor, we would define getDefaultFileExtension() as follows:
public String getDefaultFileExtension() { return "sql"; } - Finally, return a Contributer and a FileServiceFactory by defining createLocalContributer and getFileServiceFactory as follows:
protected IUnifiedEditorContributor createLocalContributor() { return new SQLContributer(); } public IFileServiceFactory getFileServiceFactory() { return SQLFileServiceFactory.getInstance(); }
These two classes do not exist, so you can create them using a Quick Fix. The Contributer should sub-class "BaseContributer". The file service factory needs to implement the "IFileServiceFactory" interface.
Modifying the Contributer Class
Fill in a few details to the default contributer implementation the Quick Fix created for us.
- First, getLocalContentType needs to return the MIME type we defined earlier. Replace the return statement as follows:
public String getLocalContentType() { return SQLMimeType.MimeType; } - Finally, we can return a default reconciling strategy with the following:
public UnifiedReconcilingStrategy getReconcilingStrategy() { return new UnifiedReconcilingStrategy(); }
Modifying the File Service Factory Class
- This class should be a singleton. Use the following code:
public final class SQLFileServiceFactory implements IFileServiceFactory { private static SQLFileServiceFactory instance; private SQLFileServiceFactory() { } public static IFileServiceFactory getInstance() { if (instance == null) { instance = new SQLFileServiceFactory(); } return instance; } }Note the following points:
- The constructor is private, so no one can create an instance of this class except for the class itself.
- The class is marked final since subclasses cannot call the constructor either.
- Define getInstance as the only means to get to the singleton. That method will create the instance and store it in its private static field if it has not yet been defined.
- Define createFileService.
public FileService createFileService(IFileSourceProvider sourceProvider) { IParser parser = null; IParseState parseState = null; FileService fileService = new FileService(parser, parseState, sourceProvider, SQLMimeType.MimeType); ParentOffsetMapper parentMapper = new ParentOffsetMapper(fileService); BaseFileLanguageService languageService = new BaseFileLanguageService(fileService, parseState, parser, parentMapper); fileService.setErrorManager(new UnifiedErrorManager(fileService)); fileService.addLanguageService(SQLMimeType.MimeType, languageService); return fileService; }
The null Parser and ParseState are placeholders for when we add colorizing. The other lines essentially hook up a defulat error manager and associate the parser with the editor using this file service.
Related Topics
Aptana Developer Home


