]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
UC SCL script/procedural code editors respect L0.readOnly
authorTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Fri, 24 Apr 2020 17:34:14 +0000 (20:34 +0300)
committerTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Fri, 24 Apr 2020 17:36:14 +0000 (20:36 +0300)
Marking the input resource with L0.readOnly now makes the editors
consider the input immutable in the document provider.

gitlab #526

(cherry picked from commit 36e865dac0ec2db530fabc6fd9ea9841c3e812ae)

bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/componentTypeEditor/ComponentTypeScriptDocumentProvider.java
bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/componentTypeEditor/ComponentTypeScriptEditor.java
bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/componentTypeEditor/ProceduralComponentTypeCodeDocumentProvider.java

index 57d0aa69a6bbfdd30e4905aabcb992fb571b9097..a8e637a04dd240b0d8cd51aa9398e6dc5694bbc5 100644 (file)
@@ -21,6 +21,7 @@ import org.simantics.db.WriteGraph;
 import org.simantics.db.common.request.UniqueRead;
 import org.simantics.db.common.request.WriteRequest;
 import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.layer0.util.Layer0Utils;
 import org.simantics.db.procedure.Listener;
 import org.simantics.db.request.Read;
 import org.simantics.modeling.ComponentTypeScriptRequest;
@@ -60,7 +61,8 @@ public class ComponentTypeScriptDocumentProvider extends AbstractDocumentProvide
                     StructuralResource2 STR = StructuralResource2.getInstance(graph);
                     currentText = graph.getRelatedValue(resource, STR.ComponentTypeScript_code, Bindings.STRING);
                     Resource owner = graph.getPossibleObject(resource, STR.ComponentType_hasScript_Inverse);
-                    immutable = owner != null && StructuralUtils.isImmutable(graph, owner);
+                    immutable = Layer0Utils.isMarkedReadOnly(graph, resource)
+                            || owner != null && StructuralUtils.isImmutable(graph, owner);
                     errorHappened = false;
                     return new Document(currentText != null ? currentText : ""); //$NON-NLS-1$
                 }
index 6ee5ec77abe89da85f4b41313ea45a5182fdca7e..ec82da5f3e82022ef35e9d8a09ce8a3d1a3f627d 100644 (file)
@@ -31,13 +31,13 @@ import org.simantics.db.common.request.ReadRequest;
 import org.simantics.db.common.request.UniqueRead;
 import org.simantics.db.exception.DatabaseException;
 import org.simantics.db.layer0.request.combinations.Combinators;
-import org.simantics.db.request.Read;
 import org.simantics.layer0.Layer0;
 import org.simantics.scl.ui.editor.SCLSourceViewerConfigurationNew;
 import org.simantics.structural.stubs.StructuralResource2;
 import org.simantics.ui.workbench.IResourceEditorInput;
 import org.simantics.ui.workbench.TitleUpdater;
 import org.simantics.ui.workbench.ToolTipRequest;
+import org.simantics.utils.ui.ExceptionUtils;
 
 /**
  * @author Hannu Niemist&ouml;
@@ -45,25 +45,25 @@ import org.simantics.ui.workbench.ToolTipRequest;
  */
 public class ComponentTypeScriptEditor extends SCLModuleEditor {
 
+    protected ComponentTypeScriptDocumentProvider docProvider;
+    protected String scriptType = "";
+    protected int scriptTypeIndex = 0;
+
     public ComponentTypeScriptEditor() {
         super();
     }
 
     @Override
     protected void preInitialize() {
-        setDocumentProvider(new ComponentTypeScriptDocumentProvider(this));
+        docProvider = new ComponentTypeScriptDocumentProvider(this);
+        setDocumentProvider(docProvider);
         SCLSourceViewerConfigurationNew sourceViewerConfiguration = new SCLSourceViewerConfigurationNew(resourceManager);
         setSourceViewerConfiguration(sourceViewerConfiguration);
-        
     }
     
     protected ParametrizedRead<IResourceEditorInput, Boolean> getInputValidator() {
-        return new ParametrizedRead<IResourceEditorInput, Boolean>() {
-            @Override
-            public Read<Boolean> get(IResourceEditorInput parameter) {
-                return Combinators.constant(Boolean.TRUE);
-            }
-        };
+        // No-op validator that always returns true
+        return param -> Combinators.constant(Boolean.TRUE);
     }
     
     @Override
@@ -131,12 +131,14 @@ public class ComponentTypeScriptEditor extends SCLModuleEditor {
                 @Override
                 public void run(ReadGraph graph) throws DatabaseException {
                     StructuralResource2 STR = StructuralResource2.getInstance(graph);
-                    final String type = graph.getPossibleRelatedValue(script, STR.ComponentTypeScript_type);
+                    String type = graph.getPossibleRelatedValue(script, STR.ComponentTypeScript_type);
                     if(type != null)
+                        scriptType = type;
                         combo.getDisplay().asyncExec(() -> {
                             for(int i=0;i<EXECUTION_PHASES.length;++i)
                                 if(EXECUTION_PHASES[i].equals(type)) {
                                     combo.select(i);
+                                    scriptTypeIndex = i;
                                     return;
                                 }
                         });
@@ -145,12 +147,26 @@ public class ComponentTypeScriptEditor extends SCLModuleEditor {
         }
         combo.addSelectionListener(org.eclipse.swt.events.SelectionListener.widgetSelectedAdapter(e -> {
             int id = combo.getSelectionIndex();
+            if (id == scriptTypeIndex)
+                return;
+            if (docProvider.isReadOnly(getEditorInput())) {
+                // Return configured selection
+                combo.select(scriptTypeIndex);
+                return;
+            }
+            String newType = EXECUTION_PHASES[id];
             Simantics.getSession().asyncRequest((WriteGraph graph) -> {
                 StructuralResource2 STR = StructuralResource2.getInstance(graph);
                 String currentType = graph.getPossibleRelatedValue(script, STR.ComponentTypeScript_type);
-                String newType = EXECUTION_PHASES[id];
                 if(!newType.equals(currentType))
                     graph.claimLiteral(script, STR.ComponentTypeScript_type, newType, Bindings.STRING);
+            }, exc -> {
+                if (exc == null) {
+                    scriptType = newType;
+                    scriptTypeIndex = id;
+                } else {
+                    ExceptionUtils.logError(exc);
+                }
             });
         }));
         GridDataFactory.fillDefaults().grab(true, false).applyTo(combo);
index 1a1eb723fcfe363e000fcb4cf5d8f9e611780360..5cc209943b920d58bbb2a037efbe71b807bdd112 100644 (file)
@@ -31,6 +31,7 @@ import org.simantics.scl.ui.editor.SCLSourceViewerConfigurationNew;
 import org.simantics.scl.ui.editor.TextAndErrors;
 import org.simantics.structural2.scl.procedural.CompileProceduralComponentTypeRequest;
 import org.simantics.structural2.scl.procedural.ProceduralComponentTypeCompilationException;
+import org.simantics.structural2.utils.StructuralUtils;
 import org.simantics.ui.workbench.ResourceEditorInput;
 import org.simantics.utils.logging.TimeLogger;
 import org.simantics.utils.ui.SWTUtils;
@@ -55,6 +56,7 @@ public class ProceduralComponentTypeCodeDocumentProvider extends SCLModuleEditor
                 @Override
                 public Document perform(ReadGraph graph) throws DatabaseException {
                     currentText = graph.getValue(resource, Bindings.STRING);
+                    immutable = StructuralUtils.isImmutable(graph, resource);
                     errorHappened = false;
                     return new Document(currentText != null ? currentText : ""); //$NON-NLS-1$
                 }