Current toTextualModuleSource() is called quite extensively when
isModifiable() is called. The module source can be cached as the input
of the editor does not tend to change
refs #7369
Change-Id: I671af197750301f8bffbb9624f58c5bab656e08b
private SCLSourceViewerConfigurationNew sourceViewer;
protected AnnotationModel annotationModel = new AnnotationModel();
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;
}
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 instanceof TextualModuleSource))
if(!(source instanceof TextualModuleSource))
- return null;
- return (TextualModuleSource)source;
+ return;
+ currentSource = (TextualModuleSource)source;
}
@Override
protected IDocument createDocument(Object element) throws CoreException {
}
@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 {
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)
} 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);
IDocumentPartitioner partitioner = new FastPartitioner(new SCLPartitionScanner(), SCLPartitionScanner.PARTITION_TYPES);
partitioner.connect(document);
document.setDocumentPartitioner(partitioner);
- sourceViewer.updateCompletionAssistModuleName(source.getModuleName());
+ sourceViewer.updateCompletionAssistModuleName(currentSource.getModuleName());
+ @Override
+ public void changed(Object element) {
+ updateTextualModuleSource(element);
+ }
+
+ @Override
+ public void aboutToChange(Object element) {
+ super.aboutToChange(element);
+ }
+
@Override
public boolean isModifiable(Object element) {
@Override
public boolean isModifiable(Object element) {
- TextualModuleSource source = toTextualModuleSource(element);
- if(source == null)
+ if(currentSource == null)
- return source.isUpdateable();
+ return currentSource.isUpdateable();
@Override
protected void doSaveDocument(IProgressMonitor monitor, Object element,
IDocument document, boolean overwrite) throws CoreException {
@Override
protected void doSaveDocument(IProgressMonitor monitor, Object element,
IDocument document, boolean overwrite) throws CoreException {
- TextualModuleSource source = toTextualModuleSource(element);
- if(source == null)
+ if(currentSource == null)
- source.update(document.get());
+ currentSource.update(document.get());