]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
refs #5097
authorjsimomaa <jsimomaa@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Mon, 14 Jul 2014 06:34:05 +0000 (06:34 +0000)
committerjsimomaa <jsimomaa@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Mon, 14 Jul 2014 06:34:05 +0000 (06:34 +0000)
Disable property view editing for Built-in functions

git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@29870 ac1ea38d-2e2b-0410-8846-a27921b304fc

org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/FunctionTab.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/functions/FunctionCodeWidget.java

index e50e110adcababd7ba8c42845a28b5ba92b6902f..c0944c03dda770532dd89a2328f721c2db70b1b0 100644 (file)
@@ -17,14 +17,21 @@ import org.eclipse.swt.SWT;
 import org.eclipse.swt.widgets.Composite;\r
 import org.eclipse.swt.widgets.Group;\r
 import org.eclipse.ui.IWorkbenchSite;\r
+import org.lobobrowser.util.ID;\r
 import org.simantics.browsing.ui.swt.widgets.Label;\r
 import org.simantics.browsing.ui.swt.widgets.StringPropertyFactory;\r
 import org.simantics.browsing.ui.swt.widgets.StringPropertyModifier;\r
 import org.simantics.browsing.ui.swt.widgets.TrackedText;\r
 import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport;\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.common.request.IsParent;\r
+import org.simantics.db.exception.DatabaseException;\r
 import org.simantics.db.management.ISessionContext;\r
+import org.simantics.db.request.Read;\r
 import org.simantics.jfreechart.chart.properties.AdjustableTab;\r
 import org.simantics.layer0.Layer0;\r
+import org.simantics.sysdyn.SysdynResource;\r
 import org.simantics.sysdyn.ui.properties.widgets.FunctionLabelFactory;\r
 import org.simantics.sysdyn.ui.properties.widgets.expressions.ExpressionField;\r
 import org.simantics.sysdyn.ui.properties.widgets.factories.FunctionNameInputValidator;\r
@@ -85,6 +92,24 @@ public class FunctionTab extends AdjustableTab {
         information = new TrackedText(documentationGroup, support, SWT.MULTI | SWT.V_SCROLL | SWT.WRAP);\r
         information.setTextFactory(new StringPropertyFactory(Layer0.URIs.HasDescription));\r
         information.addModifyListener(new StringPropertyModifier(context, Layer0.URIs.HasDescription));\r
+        \r
+        if (id instanceof Resource) {\r
+            final Resource r = (Resource) id;\r
+            try {\r
+                boolean editable = context.getSession().syncRequest(new Read<Boolean>() {\r
+\r
+                    @Override\r
+                    public Boolean perform(ReadGraph graph) throws DatabaseException {\r
+                        boolean editable = new IsParent(SysdynResource.getInstance(graph).Built$in_Functions, r).perform(graph);\r
+                        return !editable;\r
+                    }\r
+                });\r
+                information.setEditable(editable);\r
+                nameText.setEditable(editable);\r
+            } catch (DatabaseException e) {\r
+                e.printStackTrace();\r
+            }\r
+        }\r
        }\r
 \r
        @Override\r
index 696f4815d6dd67eb882b9095b7d6d83bfa53a003..18294955d201a52be16b7685d20cd15b5d4c13cd 100644 (file)
@@ -34,6 +34,7 @@ import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport;
 import org.simantics.db.ReadGraph;\r
 import org.simantics.db.Resource;\r
 import org.simantics.db.WriteGraph;\r
+import org.simantics.db.common.request.IsParent;\r
 import org.simantics.db.common.request.WriteRequest;\r
 import org.simantics.db.common.utils.ListUtils;\r
 import org.simantics.db.exception.DatabaseException;\r
@@ -152,6 +153,16 @@ public class FunctionCodeWidget implements Widget {
                        });\r
                        if(code != null) {\r
                                modelicaCode.setExpression(code);\r
+                               \r
+                               boolean editable = context.getSession().syncRequest(new Read<Boolean>() {\r
+\r
+                    @Override\r
+                    public Boolean perform(ReadGraph graph) throws DatabaseException {\r
+                        boolean asd = new IsParent(SysdynResource.getInstance(graph).Built$in_Functions, function).perform(graph);\r
+                        return !asd;\r
+                    }\r
+                               });\r
+                           modelicaCode.getSourceViewer().setEditable(editable);\r
                                validate();\r
                        }\r
                } catch (DatabaseException e) {\r
@@ -206,6 +217,10 @@ public class FunctionCodeWidget implements Widget {
        }\r
     \r
     private void save() {\r
+        \r
+        if (!modelicaCode.getSourceViewer().isEditable())\r
+            return;\r
+        \r
        final String code = modelicaCode.getExpression();\r
        \r
        // Update input and output lists.\r