]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.scl.ui/src/org/simantics/scl/ui/editor2/SCLModuleEditor2.java
Add outline page for SCLModuleEditor2
[simantics/platform.git] / bundles / org.simantics.scl.ui / src / org / simantics / scl / ui / editor2 / SCLModuleEditor2.java
index 0e068d69bd3568387a8ba73fbbe1599d741e15a3..9aa1f0dddc628a9c05f63934e7311d7158724c76 100644 (file)
@@ -26,10 +26,12 @@ import org.eclipse.ui.texteditor.ITextEditorActionDefinitionIds;
 import org.eclipse.ui.texteditor.IUpdate;
 import org.eclipse.ui.texteditor.SourceViewerDecorationSupport;
 import org.eclipse.ui.texteditor.TextNavigationAction;
+import org.eclipse.ui.views.contentoutline.IContentOutlinePage;
 import org.simantics.scl.ui.editor.SCLSourceViewerConfigurationNew;
 import org.simantics.scl.ui.editor.completion.SCLTextEditorEnvironment;
 import org.simantics.scl.ui.editor2.iterator.DocumentCharacterIterator;
 import org.simantics.scl.ui.editor2.iterator.JavaWordIterator;
+import org.simantics.scl.ui.outline.SCLModuleOutlinePage;
 
 import com.ibm.icu.text.BreakIterator;
 
@@ -37,21 +39,24 @@ public class SCLModuleEditor2 extends TextEditor {
     
     private static final char[] CHARS = new char[] { '(', ')', '{', '}', '[', ']', '<', '>' };
     
-    private static final String MATCHING_BRACKETS = "matchingBrackets";
-    private static final String MATCHING_BRACKETS_COLOR = "matchingBracketsColor";
-    private static final String HIGHLIGHT_BRACKET_AT_CARET_LOCATION = "highlightBracketAtCaretLocation";
-    private static final String ENCLOSING_BRACKETS = "enclosingBrackets";
+    private static final String MATCHING_BRACKETS = "matchingBrackets"; //$NON-NLS-1$
+    private static final String MATCHING_BRACKETS_COLOR = "matchingBracketsColor"; //$NON-NLS-1$
+    private static final String HIGHLIGHT_BRACKET_AT_CARET_LOCATION = "highlightBracketAtCaretLocation"; //$NON-NLS-1$
+    private static final String ENCLOSING_BRACKETS = "enclosingBrackets"; //$NON-NLS-1$
     
     private boolean disposed = false;
     protected ResourceManager resourceManager;
     private DefaultCharacterPairMatcher matcher;
 
+       private SCLModuleOutlinePage outline;
+
     public SCLModuleEditor2() {
         super();
         resourceManager = new LocalResourceManager(JFaceResources.getResources());
         SCLSourceViewerConfigurationNew sourceViewerConfiguration = new SCLSourceViewerConfigurationNew(resourceManager);
         setDocumentProvider(new SCLModuleEditor2DocumentProvider(sourceViewerConfiguration));
         setSourceViewerConfiguration(sourceViewerConfiguration);
+        outline = new SCLModuleOutlinePage(this);
     }
     
     @Override
@@ -64,7 +69,7 @@ public class SCLModuleEditor2 extends TextEditor {
             throws PartInitException {
         super.init(site, input);
         getPreferenceStore().setValue(MATCHING_BRACKETS, true);
-        getPreferenceStore().setValue(MATCHING_BRACKETS_COLOR, "192,192,192");
+        getPreferenceStore().setValue(MATCHING_BRACKETS_COLOR, "192,192,192"); //$NON-NLS-1$
         getPreferenceStore().setValue(HIGHLIGHT_BRACKET_AT_CARET_LOCATION, true);
         getPreferenceStore().setValue(ENCLOSING_BRACKETS, true);
     }
@@ -72,7 +77,7 @@ public class SCLModuleEditor2 extends TextEditor {
     @Override
     public void createPartControl(Composite parent) {
         super.createPartControl(parent);
-        getEditorSite().getService(IContextService.class).activateContext("org.simantics.scl.ui.editor");
+        getEditorSite().getService(IContextService.class).activateContext("org.simantics.scl.ui.editor"); //$NON-NLS-1$
         updatePartName();
     }
 
@@ -121,7 +126,7 @@ public class SCLModuleEditor2 extends TextEditor {
         disposed = true;
         super.dispose();
         resourceManager.dispose();
-        matcher.dispose();
+        if (matcher != null) matcher.dispose();
     }
 
     public boolean isDisposed() {
@@ -136,7 +141,16 @@ public class SCLModuleEditor2 extends TextEditor {
     public IDocument getDocument() {
         return getSourceViewer().getDocument();
     }
-    
+
+    @SuppressWarnings("unchecked")
+    @Override
+    public <T> T getAdapter(Class<T> adapter) {
+        if (IContentOutlinePage.class.equals(adapter)) {
+            return (T) outline;
+        }
+        return super.getAdapter(adapter);
+    }
+
     /**
      * Text navigation action to navigate to the next sub-word.
      *