package tool.editors;
import org.eclipse.jface.text.source.projection.ProjectionSupport;
import org.eclipse.ui.editors.text.TextEditor;
import org.eclipse.ui.views.contentoutline.IContentOutlinePage;
import tool.editors.text.ToolDocumentProvider;
public class ToolEditor extends TextEditor {
public static final String EDITOR_ID = "tool.editors.ToolEditor";
public static final String EDITOR_CONTEXT = EDITOR_ID + ".context";
public static final String RULER_CONTEXT = EDITOR_CONTEXT + ".ruler";
private ColorManager colorManager;
/** The outline page */
private ToolMethodContentOutlinePage fOutlinePage;
/** The projection support */
private ProjectionSupport fProjectionSupport;
public ToolEditor() {
super();
colorManager = new ColorManager();
setSourceViewerConfiguration(new ToolSourceViewerConfiguration(colorManager));
setDocumentProvider(new ToolDocumentProvider());
}
public void dispose() {
colorManager.dispose();
super.dispose();
}
/** The <code>JavaEditor</code> implementation of this
* <code>AbstractTextEditor</code> method performs gets
* the java content outline page if request is for a an
* outline page.
*
* @param required the required type
* @return an adapter for the required type or <code>null</code>
*/
@SuppressWarnings("rawtypes")
public Object getAdapter(Class required) {
if (IContentOutlinePage.class.equals(required)) {
if (fOutlinePage == null) {
fOutlinePage = new ToolMethodContentOutlinePage(
getDocumentProvider(), this );
if (getEditorInput() != null)
fOutlinePage.setInput(getEditorInput());
}
return fOutlinePage;
}
if (fProjectionSupport != null) {
Object adapter = fProjectionSupport.getAdapter(
getSourceViewer(), required);
if (adapter != null)
return adapter;
}
return super.getAdapter(required);
}
protected void initializeEditor() {
super.initializeEditor();
setEditorContextMenuId(EDITOR_CONTEXT);
setRulerContextMenuId(RULER_CONTEXT);
}
}