100f49e252f68fe6cc8e42b795b12acc0c9bf3b3
[simantics/platform.git] / bundles / org.simantics.scl.ui / src / org / simantics / scl / ui / editor2 / SCLModuleEditor2.java
1 package org.simantics.scl.ui.editor2;
2
3 import org.eclipse.jface.resource.JFaceResources;
4 import org.eclipse.jface.resource.LocalResourceManager;
5 import org.eclipse.jface.resource.ResourceManager;
6 import org.eclipse.jface.text.IDocument;
7 import org.eclipse.swt.widgets.Composite;
8 import org.eclipse.ui.IEditorInput;
9 import org.eclipse.ui.IEditorSite;
10 import org.eclipse.ui.PartInitException;
11 import org.eclipse.ui.contexts.IContextService;
12 import org.eclipse.ui.editors.text.TextEditor;
13 import org.simantics.scl.ui.editor.SCLSourceViewerConfigurationNew;
14 import org.simantics.scl.ui.editor.completion.SCLTextEditorEnvironment;
15
16 public class SCLModuleEditor2 extends TextEditor {
17     private boolean disposed = false;
18     protected ResourceManager resourceManager;
19
20     public SCLModuleEditor2() {
21         super();
22         resourceManager = new LocalResourceManager(JFaceResources.getResources());
23         SCLSourceViewerConfigurationNew sourceViewerConfiguration = new SCLSourceViewerConfigurationNew(resourceManager);
24         setDocumentProvider(new SCLModuleEditor2DocumentProvider(sourceViewerConfiguration));
25         setSourceViewerConfiguration(sourceViewerConfiguration);
26     }
27     
28     @Override
29     public boolean isTabsToSpacesConversionEnabled() {
30         return true;
31     }
32     
33     @Override
34     public void init(IEditorSite site, IEditorInput input)
35             throws PartInitException {
36         super.init(site, input);
37     }
38
39     @Override
40     public void createPartControl(Composite parent) {
41         super.createPartControl(parent);
42         getEditorSite().getService(IContextService.class).activateContext("org.simantics.scl.ui.editor");
43         updatePartName();
44     }
45
46     protected void updatePartName() {
47         setPartName(getEditorInput().getName());
48     }
49     
50     @Override
51     public void dispose() {
52         disposed = true;
53         super.dispose();
54         resourceManager.dispose();
55     }
56
57     public boolean isDisposed() {
58         return disposed;
59     }
60     
61     public SCLTextEditorEnvironment getSCLTextEditorEnvironment() {
62         return ((SCLSourceViewerConfigurationNew)getSourceViewerConfiguration())
63                 .getSclTextEditorEnvironment();
64     }
65
66     public IDocument getDocument() {
67         return getSourceViewer().getDocument();
68     }
69 }