001: /* Soot - a J*va Optimization Framework
002: * Copyright (C) 2003 Jennifer Lhotak
003: *
004: * This library is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU Lesser General Public
006: * License as published by the Free Software Foundation; either
007: * version 2.1 of the License, or (at your option) any later version.
008: *
009: * This library is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012: * Lesser General Public License for more details.
013: *
014: * You should have received a copy of the GNU Lesser General Public
015: * License along with this library; if not, write to the
016: * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
017: * Boston, MA 02111-1307, USA.
018: */
019:
020: package ca.mcgill.sable.soot.editors;
021:
022: import org.eclipse.jface.text.source.ISourceViewer;
023: import org.eclipse.jface.text.source.IVerticalRuler;
024: import org.eclipse.swt.widgets.Composite;
025: import org.eclipse.ui.IEditorInput;
026: import org.eclipse.ui.IFileEditorInput;
027: import org.eclipse.ui.editors.text.TextEditor;
028: import org.eclipse.ui.views.contentoutline.IContentOutlinePage;
029:
030: import ca.mcgill.sable.soot.SootPlugin;
031:
032: public class JimpleEditor extends TextEditor {
033:
034: private ColorManager colorManager;
035: protected JimpleContentOutlinePage page;
036: private ISourceViewer viewer;
037:
038: /**
039: * Constructor for JimpleEditor.
040: */
041: public JimpleEditor() {
042: super ();
043: colorManager = SootPlugin.getDefault().getColorManager();
044: setSourceViewerConfiguration(new JimpleConfiguration(
045: colorManager, this ));
046: setDocumentProvider(new JimpleDocumentProvider());
047: setViewer(this .getSourceViewer());
048:
049: }
050:
051: /**
052: * This method is what creates the Jimple Content Outliner
053: */
054: public Object getAdapter(Class key) {
055: if (key.equals(IContentOutlinePage.class)) {
056: //System.out.println("in getAdapter of editor");
057: IEditorInput input = getEditorInput();
058: if (input instanceof IFileEditorInput) {
059: setPage(new JimpleContentOutlinePage(
060: ((IFileEditorInput) input).getFile(), this ));
061: return getPage();
062: }
063: }
064: return super .getAdapter(key);
065: }
066:
067: public void dispose() {
068: super .dispose();
069: }
070:
071: /**
072: * @return
073: */
074: public JimpleContentOutlinePage getPage() {
075: return page;
076: }
077:
078: /**
079: * @param page
080: */
081: public void setPage(JimpleContentOutlinePage page) {
082: this .page = page;
083: }
084:
085: protected ISourceViewer createSourceViewer(Composite parent,
086: IVerticalRuler ruler, int styles) {
087: setViewer(super .createSourceViewer(parent, ruler, styles));
088: SootPlugin.getDefault().addEditorViewer(getViewer());
089: return getViewer();
090: }
091:
092: /**
093: * @return
094: */
095: public ISourceViewer getViewer() {
096: return viewer;
097: }
098:
099: /**
100: * @param viewer
101: */
102: public void setViewer(ISourceViewer viewer) {
103: this.viewer = viewer;
104: }
105:
106: }
|