From: Hannu Niemistö Date: Mon, 24 Jul 2017 10:52:26 +0000 (+0300) Subject: Merge "(refs #7375) Replaced collectEffects by CollectEffectsVisitor" X-Git-Tag: v1.31.0~264^2~34 X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=commitdiff_plain;h=ff1337ff96700fb157ec789cbef88b8f40e03798;hp=a8d72a172fdc815c8a9f0f584f010f7e35286f92 Merge "(refs #7375) Replaced collectEffects by CollectEffectsVisitor" --- diff --git a/bundles/org.simantics.scl.db/scl/Simantics/Variables.scl b/bundles/org.simantics.scl.db/scl/Simantics/Variables.scl index a8ffd13db..9a6ffde8c 100644 --- a/bundles/org.simantics.scl.db/scl/Simantics/Variables.scl +++ b/bundles/org.simantics.scl.db/scl/Simantics/Variables.scl @@ -21,6 +21,9 @@ Example: """ variable :: String -> Variable + @JavaName getPossibleVariable + possibleVariable :: String -> Maybe Variable + @JavaName getVariable """ Function **resourceVariable** converts a resource to a corresponding variable. diff --git a/bundles/org.simantics.scl.ui/src/org/simantics/scl/ui/editor2/SCLModuleEditor2DocumentProvider.java b/bundles/org.simantics.scl.ui/src/org/simantics/scl/ui/editor2/SCLModuleEditor2DocumentProvider.java index 4dfa0507b..cf6bf9a87 100644 --- a/bundles/org.simantics.scl.ui/src/org/simantics/scl/ui/editor2/SCLModuleEditor2DocumentProvider.java +++ b/bundles/org.simantics.scl.ui/src/org/simantics/scl/ui/editor2/SCLModuleEditor2DocumentProvider.java @@ -23,32 +23,38 @@ public class SCLModuleEditor2DocumentProvider extends AbstractDocumentProvider { 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) @@ -57,16 +63,25 @@ public class SCLModuleEditor2DocumentProvider extends AbstractDocumentProvider { 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 @@ -84,10 +99,9 @@ public class SCLModuleEditor2DocumentProvider extends AbstractDocumentProvider { @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