From: Tuukka Lehtonen Date: Mon, 29 Aug 2016 10:04:26 +0000 (+0300) Subject: Added some enforcement of immutability to structural user component UI's. X-Git-Tag: v1.25.0~147 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=c160c0a55f;p=simantics%2Fplatform.git Added some enforcement of immutability to structural user component UI's. The changed UI components are: * UC SCL Script/Module text editors * UC interface editor refs #6666 --- diff --git a/bundles/org.simantics.modeling.ui/META-INF/MANIFEST.MF b/bundles/org.simantics.modeling.ui/META-INF/MANIFEST.MF index 561e41e10..1b915e3a7 100644 --- a/bundles/org.simantics.modeling.ui/META-INF/MANIFEST.MF +++ b/bundles/org.simantics.modeling.ui/META-INF/MANIFEST.MF @@ -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", diff --git a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/componentTypeEditor/ComponentTypeScriptDocumentProvider.java b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/componentTypeEditor/ComponentTypeScriptDocumentProvider.java index 0129b2bb6..b31ccb109 100644 --- a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/componentTypeEditor/ComponentTypeScriptDocumentProvider.java +++ b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/componentTypeEditor/ComponentTypeScriptDocumentProvider.java @@ -28,6 +28,7 @@ import org.simantics.modeling.ComponentTypeScriptResult; import org.simantics.scl.compiler.errors.CompilationError; import org.simantics.scl.compiler.errors.Locations; import org.simantics.structural.stubs.StructuralResource2; +import org.simantics.structural2.utils.StructuralUtils; import org.simantics.ui.workbench.ResourceEditorInput; import org.simantics.utils.logging.TimeLogger; @@ -37,6 +38,7 @@ public class ComponentTypeScriptDocumentProvider extends AbstractDocumentProvide protected Resource resource; protected String currentText; + protected boolean immutable; protected boolean errorHappened; protected AnnotationModel annotationModel = new AnnotationModel(); @@ -57,6 +59,8 @@ public class ComponentTypeScriptDocumentProvider extends AbstractDocumentProvide public Document perform(ReadGraph graph) throws DatabaseException { 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); errorHappened = false; return new Document(currentText != null ? currentText : ""); } @@ -139,17 +143,12 @@ public class ComponentTypeScriptDocumentProvider extends AbstractDocumentProvide @Override public boolean isModifiable(Object element) { - return !errorHappened; + return !errorHappened && !immutable; } @Override public boolean isReadOnly(Object element) { - return errorHappened; + return errorHappened || immutable; } - @Override - public boolean canSaveDocument(Object element) { - return !errorHappened && !getDocument(element).get().equals(currentText); - } - } diff --git a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/componentTypeEditor/ComponentTypeViewer.java b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/componentTypeEditor/ComponentTypeViewer.java index 3cc4bbbf3..f88ad39fa 100644 --- a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/componentTypeEditor/ComponentTypeViewer.java +++ b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/componentTypeEditor/ComponentTypeViewer.java @@ -45,9 +45,9 @@ import org.simantics.db.common.NamedResource; import org.simantics.db.common.request.UniqueRead; import org.simantics.db.common.utils.NameUtils; 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.db.service.XSupport; import org.simantics.layer0.Layer0; import org.simantics.modeling.ui.Activator; import org.simantics.operation.Layer0X; @@ -173,6 +173,12 @@ public class ComponentTypeViewer { Layer0 L0 = Layer0.getInstance(graph); Layer0X L0X = Layer0X.getInstance(graph); StructuralResource2 STR = StructuralResource2.getInstance(graph); + + boolean typeIsImmutable = graph.isImmutable(data.componentType) + || graph.hasStatement(data.componentType, STR.ComponentType_Locked) + || Layer0Utils.isPublished(graph, data.componentType) + || Layer0Utils.isContainerPublished(graph, data.componentType); + for(Resource relation : graph.getObjects(data.componentType, L0.DomainOf)) { if(graph.isSubrelationOf(relation, L0.HasProperty)) { String name = graph.getRelatedValue(relation, L0.HasName); @@ -216,7 +222,7 @@ public class ComponentTypeViewer { String valid = expression != null ? DerivedPropertiesSection.validateMonitorExpression(graph, data.componentType, relation, expression) : null; - boolean immutable = graph.isImmutable(relation); + boolean immutable = typeIsImmutable || graph.isImmutable(relation); ComponentTypeViewerPropertyInfo info = new ComponentTypeViewerPropertyInfo(relation, name, type, defaultValue, numberType, unit, label, description, expression, valid, immutable); @@ -242,9 +248,7 @@ public class ComponentTypeViewer { } } Collections.sort(result); - XSupport xs = graph.peekService(XSupport.class); - boolean immutable = xs != null ? xs.getImmutable(data.componentType) : false; - return new ComponentTypePropertiesResult(result, connectionPoints, immutable); + return new ComponentTypePropertiesResult(result, connectionPoints, typeIsImmutable); } }, new Listener() { @Override diff --git a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/componentTypeEditor/PGraphEditorDocumentProvider.java b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/componentTypeEditor/PGraphEditorDocumentProvider.java index e59d3da0a..2bb8fbf76 100644 --- a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/componentTypeEditor/PGraphEditorDocumentProvider.java +++ b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/componentTypeEditor/PGraphEditorDocumentProvider.java @@ -2,7 +2,6 @@ package org.simantics.modeling.ui.componentTypeEditor; import java.io.PrintWriter; import java.io.StringWriter; -import java.util.Arrays; import java.util.Collections; import java.util.List; @@ -28,13 +27,7 @@ import org.simantics.db.exception.DatabaseException; import org.simantics.db.layer0.util.Layer0Utils; import org.simantics.layer0.Layer0; import org.simantics.scl.compiler.errors.CompilationError; -import org.simantics.scl.compiler.errors.Failable; -import org.simantics.scl.compiler.errors.Failure; import org.simantics.scl.compiler.errors.Locations; -import org.simantics.scl.compiler.module.Module; -import org.simantics.scl.compiler.module.repository.UpdateListener; -import org.simantics.scl.osgi.SCLOsgi; -import org.simantics.scl.runtime.SCLContext; import org.simantics.ui.workbench.ResourceEditorInput; import org.simantics.utils.logging.TimeLogger; @@ -69,31 +62,11 @@ public class PGraphEditorDocumentProvider extends AbstractDocumentProvider { } } - // While this editor is active we do not want that this listener gets collected - private UpdateListener listener = new UpdateListener() { - @Override - public void notifyAboutUpdate() { - updateAnnotations(); - } - }; - protected void updateAnnotations() { Simantics.getSession().asyncRequest(new ReadRequest() { @Override public void run(ReadGraph graph) throws DatabaseException { -// String moduleName = graph.getURI(resource); -// SCLContext context = SCLContext.getCurrent(); -// context.put("graph", graph); -// Failable result = SCLOsgi.MODULE_REPOSITORY.getModule(moduleName, listener); -// -// if(result instanceof Failure) { -// Failure failure = (Failure)result; -// setAnnotations(Arrays.asList(failure.errors)); -// } -// else { -// setAnnotations(Collections.emptyList()); -// } - setAnnotations(Collections.emptyList()); + setAnnotations(Collections.emptyList()); } }); } @@ -155,9 +128,4 @@ public class PGraphEditorDocumentProvider extends AbstractDocumentProvider { return errorHappened; } - @Override - public boolean canSaveDocument(Object element) { - return !errorHappened && !getDocument(element).get().equals(currentText); - } - } diff --git a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/componentTypeEditor/SCLModuleEditorDocumentProvider.java b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/componentTypeEditor/SCLModuleEditorDocumentProvider.java index 35265ce50..c634f89b3 100644 --- a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/componentTypeEditor/SCLModuleEditorDocumentProvider.java +++ b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/componentTypeEditor/SCLModuleEditorDocumentProvider.java @@ -36,6 +36,7 @@ import org.simantics.scl.compiler.module.repository.UpdateListener; import org.simantics.scl.osgi.SCLOsgi; import org.simantics.scl.runtime.SCLContext; import org.simantics.scl.ui.editor.SCLSourceViewerConfigurationNew; +import org.simantics.structural2.utils.StructuralUtils; import org.simantics.ui.workbench.ResourceEditorInput; import org.simantics.utils.logging.TimeLogger; @@ -43,6 +44,7 @@ public class SCLModuleEditorDocumentProvider extends AbstractDocumentProvider { protected Resource resource; protected String currentText; + protected boolean immutable; protected boolean errorHappened; protected AnnotationModel annotationModel = new AnnotationModel(); @@ -62,6 +64,7 @@ public class SCLModuleEditorDocumentProvider extends AbstractDocumentProvider { public Document perform(ReadGraph graph) throws DatabaseException { Layer0 L0 = Layer0.getInstance(graph); currentText = graph.getRelatedValue(resource, L0.SCLModule_definition, Bindings.STRING); + immutable = StructuralUtils.isImmutable(graph, resource); errorHappened = false; return new Document(currentText != null ? currentText : ""); } @@ -156,17 +159,12 @@ public class SCLModuleEditorDocumentProvider extends AbstractDocumentProvider { @Override public boolean isModifiable(Object element) { - return !errorHappened; + return !errorHappened && !immutable; } @Override public boolean isReadOnly(Object element) { - return errorHappened; - } - - @Override - public boolean canSaveDocument(Object element) { - return !errorHappened && !getDocument(element).get().equals(currentText); + return errorHappened || immutable; } } diff --git a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/componentTypeEditor/SCLQueryEditorDocumentProvider.java b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/componentTypeEditor/SCLQueryEditorDocumentProvider.java index 11dec0fcf..5064ba9e6 100644 --- a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/componentTypeEditor/SCLQueryEditorDocumentProvider.java +++ b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/componentTypeEditor/SCLQueryEditorDocumentProvider.java @@ -214,9 +214,4 @@ public class SCLQueryEditorDocumentProvider extends AbstractDocumentProvider { return errorHappened; } - @Override - public boolean canSaveDocument(Object element) { - return !errorHappened && !getDocument(element).get().equals(currentText); - } - } diff --git a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/diagramEditor/DiagramViewerSelectionProvider.java b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/diagramEditor/DiagramViewerSelectionProvider.java index c3070d9cc..4317f5979 100644 --- a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/diagramEditor/DiagramViewerSelectionProvider.java +++ b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/diagramEditor/DiagramViewerSelectionProvider.java @@ -62,6 +62,7 @@ public class DiagramViewerSelectionProvider extends WorkbenchSelectionProvider { public Variable perform(ReadGraph graph) throws DatabaseException { DiagramResource DIA = DiagramResource.getInstance(graph); + ModelingResources MOD = ModelingResources.getInstance(graph); String uri = graph.getPossibleRelatedValue(resource, DIA.RuntimeDiagram_HasVariable); if (uri == null) @@ -71,9 +72,20 @@ public class DiagramViewerSelectionProvider extends WorkbenchSelectionProvider { if (var == null) return null; - Resource config = graph.getPossibleObject(resource2, ModelingResources.getInstance(graph).ElementToComponent); - if (config == null) + Resource config = graph.getPossibleObject(resource2, MOD.ElementToComponent); + if (config == null) { + // Apros #9646: if resource2 is the diagram + // itself, return the diagram composite variable + // since it is generally more useful than the + // variable to the diagram. + Resource composite = graph.getPossibleObject(resource2, MOD.DiagramToComposite); + if (composite != null && composite.equals(var.getPossibleRepresents(graph))) { + //return Variables.getPossibleVariable(graph, resource2); + return var; + } + return null; + } return var.browsePossible(graph, config); diff --git a/bundles/org.simantics.modeling/src/org/simantics/modeling/scl/GraphModuleSourceRepository.java b/bundles/org.simantics.modeling/src/org/simantics/modeling/scl/GraphModuleSourceRepository.java index a61563411..3edc7bfea 100644 --- a/bundles/org.simantics.modeling/src/org/simantics/modeling/scl/GraphModuleSourceRepository.java +++ b/bundles/org.simantics.modeling/src/org/simantics/modeling/scl/GraphModuleSourceRepository.java @@ -19,6 +19,7 @@ import org.simantics.scl.compiler.source.ModuleSource; import org.simantics.scl.compiler.source.StringModuleSource; import org.simantics.scl.compiler.source.repository.ModuleSourceRepository; import org.simantics.scl.runtime.SCLContext; +import org.simantics.structural2.utils.StructuralUtils; import org.simantics.scl.runtime.tuple.Tuple0; import gnu.trove.procedure.TObjectProcedure; @@ -95,13 +96,16 @@ public enum GraphModuleSourceRepository implements ModuleSourceRepository { public static class GraphModuleSource extends StringModuleSource { - public GraphModuleSource(String moduleName, ClassLoader classLoader, String moduleText) { + private final boolean immutable; + + public GraphModuleSource(String moduleName, ClassLoader classLoader, String moduleText, boolean immutable) { super(moduleName, classLoader, moduleText); + this.immutable = immutable; } @Override public boolean isUpdateable() { - return true; + return !immutable; } @Override @@ -128,7 +132,8 @@ public enum GraphModuleSourceRepository implements ModuleSourceRepository { if(!graph.isInstanceOf(moduleResource, L0.SCLModule)) return null; String text = graph.getRelatedValue(moduleResource, L0.SCLModule_definition); - return new GraphModuleSource(parameter, getClass().getClassLoader(), text); + boolean immutable = StructuralUtils.isImmutable(graph, moduleResource); + return new GraphModuleSource(parameter, getClass().getClassLoader(), text, immutable); } } diff --git a/bundles/org.simantics.structural2/src/org/simantics/structural2/utils/StructuralUtils.java b/bundles/org.simantics.structural2/src/org/simantics/structural2/utils/StructuralUtils.java index 0b0214e61..d029f3ae7 100644 --- a/bundles/org.simantics.structural2/src/org/simantics/structural2/utils/StructuralUtils.java +++ b/bundles/org.simantics.structural2/src/org/simantics/structural2/utils/StructuralUtils.java @@ -16,6 +16,7 @@ import org.simantics.db.Statement; import org.simantics.db.WriteGraph; import org.simantics.db.common.CommentMetadata; import org.simantics.db.common.request.ObjectsWithType; +import org.simantics.db.common.request.PossibleTypedParent; import org.simantics.db.common.utils.NameUtils; import org.simantics.db.exception.DatabaseException; import org.simantics.db.layer0.exception.MissingVariableException; @@ -273,5 +274,17 @@ public class StructuralUtils { } return null; } - + + public static boolean isImmutable(ReadGraph graph, Resource r) throws DatabaseException { + StructuralResource2 STR = StructuralResource2.getInstance(graph); + Resource uc = graph.syncRequest(new PossibleTypedParent(r, STR.ComponentType)); + return graph.isImmutable(r) + // Anything under a published or locked user component is published as well + || (uc != null && (Layer0Utils.isPublished(graph, uc) + || graph.hasStatement(uc, STR.ComponentType_Locked))) + // Anything under a published container (shared library) is published as well + || Layer0Utils.isContainerPublished(graph, r) + ; + } + }