]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Added some enforcement of immutability to structural user component UI's.
authorTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Mon, 29 Aug 2016 10:04:26 +0000 (13:04 +0300)
committerTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Mon, 29 Aug 2016 10:04:26 +0000 (13:04 +0300)
The changed UI components are:

* UC SCL Script/Module text editors
* UC interface editor

refs #6666

bundles/org.simantics.modeling.ui/META-INF/MANIFEST.MF
bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/componentTypeEditor/ComponentTypeScriptDocumentProvider.java
bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/componentTypeEditor/ComponentTypeViewer.java
bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/componentTypeEditor/PGraphEditorDocumentProvider.java
bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/componentTypeEditor/SCLModuleEditorDocumentProvider.java
bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/componentTypeEditor/SCLQueryEditorDocumentProvider.java
bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/diagramEditor/DiagramViewerSelectionProvider.java
bundles/org.simantics.modeling/src/org/simantics/modeling/scl/GraphModuleSourceRepository.java
bundles/org.simantics.structural2/src/org/simantics/structural2/utils/StructuralUtils.java

index 561e41e10919faa1239e398ebcc98838159a35c8..1b915e3a7a9e0daa82aaad885ec679e9d3aee27e 100644 (file)
@@ -32,7 +32,7 @@ Require-Bundle: org.simantics.project;bundle-version="1.0.0",
  org.simantics.issues;bundle-version="1.1.0",
  org.simantics.document;bundle-version="1.0.0",
  org.simantics.graph.db;bundle-version="1.1.9",
- org.bouncycastle.bcprov-jdk14;bundle-version="1.38.0",
+ org.bouncycastle;bundle-version="1.47.0",
  org.simantics.image2.ontology;bundle-version="1.1.0",
  org.simantics.scl.compiler;bundle-version="0.4.0",
  org.simantics.scl.compiler.dummy;bundle-version="1.0.0",
index 0129b2bb6040fa836102b39cf950513baf4de453..b31ccb109fbedc0847c97f095f968424ef00a9ce 100644 (file)
@@ -28,6 +28,7 @@ import org.simantics.modeling.ComponentTypeScriptResult;
 import org.simantics.scl.compiler.errors.CompilationError;\r
 import org.simantics.scl.compiler.errors.Locations;\r
 import org.simantics.structural.stubs.StructuralResource2;\r
+import org.simantics.structural2.utils.StructuralUtils;\r
 import org.simantics.ui.workbench.ResourceEditorInput;\r
 import org.simantics.utils.logging.TimeLogger;\r
 \r
@@ -37,6 +38,7 @@ public class ComponentTypeScriptDocumentProvider extends AbstractDocumentProvide
     \r
     protected Resource resource;\r
     protected String currentText;\r
+    protected boolean immutable;\r
     protected boolean errorHappened;\r
     \r
     protected AnnotationModel annotationModel = new AnnotationModel();\r
@@ -57,6 +59,8 @@ public class ComponentTypeScriptDocumentProvider extends AbstractDocumentProvide
                 public Document perform(ReadGraph graph) throws DatabaseException {\r
                     StructuralResource2 STR = StructuralResource2.getInstance(graph);\r
                     currentText = graph.getRelatedValue(resource, STR.ComponentTypeScript_code, Bindings.STRING);\r
+                    Resource owner = graph.getPossibleObject(resource, STR.ComponentType_hasScript_Inverse);\r
+                    immutable = owner != null && StructuralUtils.isImmutable(graph, owner);\r
                     errorHappened = false;\r
                     return new Document(currentText != null ? currentText : "");\r
                 }\r
@@ -139,17 +143,12 @@ public class ComponentTypeScriptDocumentProvider extends AbstractDocumentProvide
     \r
     @Override\r
     public boolean isModifiable(Object element) {\r
-        return !errorHappened;\r
+        return !errorHappened && !immutable;\r
     }\r
 \r
     @Override\r
     public boolean isReadOnly(Object element) {\r
-        return errorHappened;\r
+        return errorHappened || immutable;\r
     }\r
 \r
-    @Override\r
-    public boolean canSaveDocument(Object element) {\r
-        return !errorHappened && !getDocument(element).get().equals(currentText);\r
-    }\r
-    \r
 }\r
index 3cc4bbbf3ce68aa6d08f2b99438fad0190e134bc..f88ad39fa5bd351732044e6feaa028624068ac71 100644 (file)
@@ -45,9 +45,9 @@ import org.simantics.db.common.NamedResource;
 import org.simantics.db.common.request.UniqueRead;\r
 import org.simantics.db.common.utils.NameUtils;\r
 import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.db.layer0.util.Layer0Utils;\r
 import org.simantics.db.procedure.Listener;\r
 import org.simantics.db.request.Read;\r
-import org.simantics.db.service.XSupport;\r
 import org.simantics.layer0.Layer0;\r
 import org.simantics.modeling.ui.Activator;\r
 import org.simantics.operation.Layer0X;\r
@@ -173,6 +173,12 @@ public class ComponentTypeViewer {
                 Layer0 L0 = Layer0.getInstance(graph);\r
                 Layer0X L0X = Layer0X.getInstance(graph);\r
                 StructuralResource2 STR = StructuralResource2.getInstance(graph);\r
+\r
+                boolean typeIsImmutable = graph.isImmutable(data.componentType)\r
+                        || graph.hasStatement(data.componentType, STR.ComponentType_Locked)\r
+                        || Layer0Utils.isPublished(graph, data.componentType)\r
+                        || Layer0Utils.isContainerPublished(graph, data.componentType);\r
+\r
                 for(Resource relation : graph.getObjects(data.componentType, L0.DomainOf)) {\r
                     if(graph.isSubrelationOf(relation, L0.HasProperty)) {\r
                         String name = graph.getRelatedValue(relation, L0.HasName);\r
@@ -216,7 +222,7 @@ public class ComponentTypeViewer {
                         \r
                         String valid = expression != null ? DerivedPropertiesSection.validateMonitorExpression(graph, data.componentType, relation, expression) : null; \r
 \r
-                        boolean immutable = graph.isImmutable(relation);\r
+                        boolean immutable = typeIsImmutable || graph.isImmutable(relation);\r
                         ComponentTypeViewerPropertyInfo info =\r
                                 new ComponentTypeViewerPropertyInfo(relation, name, type, defaultValue, numberType, unit, label, description, expression, valid, immutable);\r
                         \r
@@ -242,9 +248,7 @@ public class ComponentTypeViewer {
                     }\r
                 }\r
                 Collections.sort(result);\r
-                XSupport xs = graph.peekService(XSupport.class);\r
-                boolean immutable = xs != null ? xs.getImmutable(data.componentType) : false;\r
-                return new ComponentTypePropertiesResult(result, connectionPoints, immutable);\r
+                return new ComponentTypePropertiesResult(result, connectionPoints, typeIsImmutable);\r
             }\r
         }, new Listener<ComponentTypePropertiesResult>() {\r
             @Override\r
index e59d3da0a5dfb2e81adfe3c1a4026b6d56e8576e..2bb8fbf7699a80841351d04d60573f9a9950da8f 100644 (file)
@@ -2,7 +2,6 @@ package org.simantics.modeling.ui.componentTypeEditor;
 \r
 import java.io.PrintWriter;\r
 import java.io.StringWriter;\r
-import java.util.Arrays;\r
 import java.util.Collections;\r
 import java.util.List;\r
 \r
@@ -28,13 +27,7 @@ import org.simantics.db.exception.DatabaseException;
 import org.simantics.db.layer0.util.Layer0Utils;\r
 import org.simantics.layer0.Layer0;\r
 import org.simantics.scl.compiler.errors.CompilationError;\r
-import org.simantics.scl.compiler.errors.Failable;\r
-import org.simantics.scl.compiler.errors.Failure;\r
 import org.simantics.scl.compiler.errors.Locations;\r
-import org.simantics.scl.compiler.module.Module;\r
-import org.simantics.scl.compiler.module.repository.UpdateListener;\r
-import org.simantics.scl.osgi.SCLOsgi;\r
-import org.simantics.scl.runtime.SCLContext;\r
 import org.simantics.ui.workbench.ResourceEditorInput;\r
 import org.simantics.utils.logging.TimeLogger;\r
 \r
@@ -69,31 +62,11 @@ public class PGraphEditorDocumentProvider extends AbstractDocumentProvider {
         }\r
     }\r
 \r
-    // While this editor is active we do not want that this listener gets collected\r
-    private UpdateListener listener = new UpdateListener() {\r
-        @Override\r
-        public void notifyAboutUpdate() {\r
-            updateAnnotations();\r
-        }\r
-    };\r
-\r
     protected void updateAnnotations() {\r
         Simantics.getSession().asyncRequest(new ReadRequest() {\r
             @Override\r
             public void run(ReadGraph graph) throws DatabaseException {\r
-//                String moduleName = graph.getURI(resource);\r
-//                SCLContext context = SCLContext.getCurrent();\r
-//                context.put("graph", graph);\r
-//                Failable<Module> result = SCLOsgi.MODULE_REPOSITORY.getModule(moduleName, listener);\r
-//                \r
-//                if(result instanceof Failure) {\r
-//                    Failure failure = (Failure)result;\r
-//                    setAnnotations(Arrays.asList(failure.errors));\r
-//                }\r
-//                else {\r
-//                    setAnnotations(Collections.<CompilationError>emptyList());\r
-//                }\r
-               setAnnotations(Collections.<CompilationError>emptyList());\r
+                setAnnotations(Collections.emptyList());\r
             }\r
         });\r
     }\r
@@ -155,9 +128,4 @@ public class PGraphEditorDocumentProvider extends AbstractDocumentProvider {
         return errorHappened;\r
     }\r
 \r
-    @Override\r
-    public boolean canSaveDocument(Object element) {\r
-        return !errorHappened && !getDocument(element).get().equals(currentText);\r
-    }\r
-\r
 }\r
index 35265ce509f56cc66011a6f2c6c6232b1d9ee5df..c634f89b38b3a2d73075c99639b4eb20866ca570 100644 (file)
@@ -36,6 +36,7 @@ import org.simantics.scl.compiler.module.repository.UpdateListener;
 import org.simantics.scl.osgi.SCLOsgi;\r
 import org.simantics.scl.runtime.SCLContext;\r
 import org.simantics.scl.ui.editor.SCLSourceViewerConfigurationNew;\r
+import org.simantics.structural2.utils.StructuralUtils;\r
 import org.simantics.ui.workbench.ResourceEditorInput;\r
 import org.simantics.utils.logging.TimeLogger;\r
 \r
@@ -43,6 +44,7 @@ public class SCLModuleEditorDocumentProvider extends AbstractDocumentProvider {
 \r
     protected Resource resource;\r
     protected String currentText;\r
+    protected boolean immutable;\r
     protected boolean errorHappened;\r
 \r
     protected AnnotationModel annotationModel = new AnnotationModel();\r
@@ -62,6 +64,7 @@ public class SCLModuleEditorDocumentProvider extends AbstractDocumentProvider {
                 public Document perform(ReadGraph graph) throws DatabaseException {\r
                     Layer0 L0 = Layer0.getInstance(graph);\r
                     currentText = graph.getRelatedValue(resource, L0.SCLModule_definition, Bindings.STRING);\r
+                    immutable = StructuralUtils.isImmutable(graph, resource);\r
                     errorHappened = false;\r
                     return new Document(currentText != null ? currentText : "");\r
                 }\r
@@ -156,17 +159,12 @@ public class SCLModuleEditorDocumentProvider extends AbstractDocumentProvider {
 \r
     @Override\r
     public boolean isModifiable(Object element) {\r
-        return !errorHappened;\r
+        return !errorHappened && !immutable;\r
     }\r
 \r
     @Override\r
     public boolean isReadOnly(Object element) {\r
-        return errorHappened;\r
-    }\r
-\r
-    @Override\r
-    public boolean canSaveDocument(Object element) {\r
-        return !errorHappened && !getDocument(element).get().equals(currentText);\r
+        return errorHappened || immutable;\r
     }\r
 \r
 }\r
index 11dec0fcf54cba03292c49682920dc5651d7e5c4..5064ba9e61cf7fa282b808553caa4ead59206ac4 100644 (file)
@@ -214,9 +214,4 @@ public class SCLQueryEditorDocumentProvider extends AbstractDocumentProvider {
         return errorHappened;\r
     }\r
     \r
-    @Override\r
-    public boolean canSaveDocument(Object element) {\r
-        return !errorHappened && !getDocument(element).get().equals(currentText);\r
-    }\r
-\r
 }\r
index c3070d9cceb9f60ccd3fde3aef1e7407a14b9957..4317f59799f9c8819bb1459fe76d3997ac56dc90 100644 (file)
@@ -62,6 +62,7 @@ public class DiagramViewerSelectionProvider extends WorkbenchSelectionProvider {
                         public Variable perform(ReadGraph graph) throws DatabaseException {\r
 \r
                             DiagramResource DIA = DiagramResource.getInstance(graph);\r
+                            ModelingResources MOD = ModelingResources.getInstance(graph);\r
 \r
                             String uri = graph.getPossibleRelatedValue(resource, DIA.RuntimeDiagram_HasVariable);\r
                             if (uri == null)\r
@@ -71,9 +72,20 @@ public class DiagramViewerSelectionProvider extends WorkbenchSelectionProvider {
                             if (var == null)\r
                                 return null;\r
 \r
-                            Resource config = graph.getPossibleObject(resource2, ModelingResources.getInstance(graph).ElementToComponent);\r
-                            if (config == null)\r
+                            Resource config = graph.getPossibleObject(resource2, MOD.ElementToComponent);\r
+                            if (config == null) {\r
+                                // Apros #9646: if resource2 is the diagram\r
+                                // itself, return the diagram composite variable\r
+                                // since it is generally more useful than the\r
+                                // variable to the diagram.\r
+                                Resource composite = graph.getPossibleObject(resource2, MOD.DiagramToComposite);\r
+                                if (composite != null && composite.equals(var.getPossibleRepresents(graph))) {\r
+                                    //return Variables.getPossibleVariable(graph, resource2);\r
+                                    return var;\r
+                                }\r
+\r
                                 return null;\r
+                            }\r
 \r
                             return var.browsePossible(graph, config);\r
 \r
index a615634118fc2a586bfe4bae0e15c1ae4dd9b9b0..3edc7bfeae28dd2a696dc9c3bd1d9d984c00de5d 100644 (file)
@@ -19,6 +19,7 @@ import org.simantics.scl.compiler.source.ModuleSource;
 import org.simantics.scl.compiler.source.StringModuleSource;\r
 import org.simantics.scl.compiler.source.repository.ModuleSourceRepository;\r
 import org.simantics.scl.runtime.SCLContext;\r
+import org.simantics.structural2.utils.StructuralUtils;\r
 import org.simantics.scl.runtime.tuple.Tuple0;\r
 \r
 import gnu.trove.procedure.TObjectProcedure;\r
@@ -95,13 +96,16 @@ public enum GraphModuleSourceRepository implements ModuleSourceRepository {
     \r
     public static class GraphModuleSource extends StringModuleSource {\r
 \r
-        public GraphModuleSource(String moduleName, ClassLoader classLoader, String moduleText) {\r
+        private final boolean immutable;\r
+\r
+        public GraphModuleSource(String moduleName, ClassLoader classLoader, String moduleText, boolean immutable) {\r
             super(moduleName, classLoader, moduleText);\r
+            this.immutable = immutable;\r
         }\r
         \r
         @Override\r
         public boolean isUpdateable() {\r
-            return true;\r
+            return !immutable;\r
         }\r
         \r
         @Override\r
@@ -128,7 +132,8 @@ public enum GraphModuleSourceRepository implements ModuleSourceRepository {
             if(!graph.isInstanceOf(moduleResource, L0.SCLModule))\r
                 return null;\r
             String text = graph.getRelatedValue(moduleResource, L0.SCLModule_definition);\r
-            return new GraphModuleSource(parameter, getClass().getClassLoader(), text);\r
+            boolean immutable = StructuralUtils.isImmutable(graph, moduleResource);\r
+            return new GraphModuleSource(parameter, getClass().getClassLoader(), text, immutable);\r
         }\r
     }\r
     \r
index 0b0214e61ccf798be797d09c751282e6cbb4bc3a..d029f3ae7942db8592e2bc68241b30f5af17b2af 100644 (file)
@@ -16,6 +16,7 @@ import org.simantics.db.Statement;
 import org.simantics.db.WriteGraph;\r
 import org.simantics.db.common.CommentMetadata;\r
 import org.simantics.db.common.request.ObjectsWithType;\r
+import org.simantics.db.common.request.PossibleTypedParent;\r
 import org.simantics.db.common.utils.NameUtils;\r
 import org.simantics.db.exception.DatabaseException;\r
 import org.simantics.db.layer0.exception.MissingVariableException;\r
@@ -273,5 +274,17 @@ public class StructuralUtils {
        }\r
        return null;\r
     }\r
-    \r
+\r
+    public static boolean isImmutable(ReadGraph graph, Resource r) throws DatabaseException {\r
+        StructuralResource2 STR = StructuralResource2.getInstance(graph);\r
+        Resource uc = graph.syncRequest(new PossibleTypedParent(r, STR.ComponentType));\r
+        return graph.isImmutable(r)\r
+                // Anything under a published or locked user component is published as well\r
+                || (uc != null && (Layer0Utils.isPublished(graph, uc)\r
+                         || graph.hasStatement(uc, STR.ComponentType_Locked)))\r
+                // Anything under a published container (shared library) is published as well\r
+                || Layer0Utils.isContainerPublished(graph, r)\r
+                ;\r
+    }\r
+\r
 }\r