private SCLSourceViewerConfigurationNew sourceViewer;
protected AnnotationModel annotationModel = new AnnotationModel();
- public SCLModuleEditor2DocumentProvider(
- SCLSourceViewerConfigurationNew sourceViewer) {
+ private Object currentElement;
+ private TextualModuleSource currentSource;
+
+ public SCLModuleEditor2DocumentProvider(SCLSourceViewerConfigurationNew sourceViewer) {
this.sourceViewer = sourceViewer;
}
- private static TextualModuleSource toTextualModuleSource(Object input) {
- if(!(input instanceof SCLModuleEditorInput))
- return null;
- ModuleSource source = ((SCLModuleEditorInput)input).getAdapter(ModuleSource.class);
+ private void updateTextualModuleSource(Object input) {
+ if (currentElement != null && currentElement.equals(input))
+ return;
+ currentElement = input;
+ if(!(currentElement instanceof SCLModuleEditorInput))
+ return;
+
+ ModuleSource source = ((SCLModuleEditorInput)currentElement).getAdapter(ModuleSource.class);
if(source == null)
- return null;
+ return;
if(!(source instanceof TextualModuleSource))
- return null;
- return (TextualModuleSource)source;
+ return;
+ currentSource = (TextualModuleSource)source;
}
@Override
protected IDocument createDocument(Object element) throws CoreException {
- TextualModuleSource source = toTextualModuleSource(element);
- if(source == null)
+ updateTextualModuleSource(element);
+ if(currentSource == null)
throw new CoreException(
new Status(Status.ERROR, "org.simantics.scl.ui", "Source for the SCL module could not be found.")
);
Document document;
try {
- document = new Document(source.getSourceText(null));
+ document = new Document(currentSource.getSourceText(null));
} catch (IOException e) {
throw new CoreException(
new Status(Status.ERROR, "org.simantics.scl.ui", "Reading SCL module failed.", e)
IDocumentPartitioner partitioner = new FastPartitioner(new SCLPartitionScanner(), SCLPartitionScanner.PARTITION_TYPES);
partitioner.connect(document);
document.setDocumentPartitioner(partitioner);
- sourceViewer.updateCompletionAssistModuleName(source.getModuleName());
+ sourceViewer.updateCompletionAssistModuleName(currentSource.getModuleName());
return document;
}
+ @Override
+ public void changed(Object element) {
+ updateTextualModuleSource(element);
+ }
+
+ @Override
+ public void aboutToChange(Object element) {
+ super.aboutToChange(element);
+ }
+
@Override
public boolean isModifiable(Object element) {
- TextualModuleSource source = toTextualModuleSource(element);
- if(source == null)
+ if(currentSource == null)
return false;
- return source.isUpdateable();
+ return currentSource.isUpdateable();
}
@Override
@Override
protected void doSaveDocument(IProgressMonitor monitor, Object element,
IDocument document, boolean overwrite) throws CoreException {
- TextualModuleSource source = toTextualModuleSource(element);
- if(source == null)
+ if(currentSource == null)
return;
- source.update(document.get());
+ currentSource.update(document.get());
}
@Override