]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Merge "(refs #7375) Replaced collectEffects by CollectEffectsVisitor"
authorHannu Niemistö <hannu.niemisto@semantum.fi>
Mon, 24 Jul 2017 10:52:26 +0000 (13:52 +0300)
committerGerrit Code Review <gerrit2@www.simantics.org>
Mon, 24 Jul 2017 10:52:26 +0000 (13:52 +0300)
bundles/org.simantics.scl.db/scl/Simantics/Variables.scl
bundles/org.simantics.scl.ui/src/org/simantics/scl/ui/editor2/SCLModuleEditor2DocumentProvider.java

index a8ffd13db76dedbe5ff5093e5e9ee722a96c7aea..9a6ffde8c17267717a3113d3ecfded655e262942 100644 (file)
@@ -21,6 +21,9 @@ Example:
     """
     variable :: String -> <ReadGraph> Variable
     
+    @JavaName getPossibleVariable
+    possibleVariable :: String -> <ReadGraph> Maybe Variable
+
     @JavaName getVariable
     """
 Function **resourceVariable** converts a resource to a corresponding variable.
index 4dfa0507ba3094f34f2a11540786a47cd5c14273..cf6bf9a87c6ade46606a2794453891406d19526e 100644 (file)
@@ -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