From: jsimomaa Date: Mon, 14 Jul 2014 06:34:05 +0000 (+0000) Subject: refs #5097 X-Git-Tag: v1.29.0~246 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=2efc892b658650f37acfa9bcf1cd74c07ade6d7a;p=simantics%2Fsysdyn.git refs #5097 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 --- diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/FunctionTab.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/FunctionTab.java index e50e110a..c0944c03 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/FunctionTab.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/FunctionTab.java @@ -17,14 +17,21 @@ import org.eclipse.swt.SWT; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Group; import org.eclipse.ui.IWorkbenchSite; +import org.lobobrowser.util.ID; import org.simantics.browsing.ui.swt.widgets.Label; import org.simantics.browsing.ui.swt.widgets.StringPropertyFactory; import org.simantics.browsing.ui.swt.widgets.StringPropertyModifier; import org.simantics.browsing.ui.swt.widgets.TrackedText; import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.common.request.IsParent; +import org.simantics.db.exception.DatabaseException; import org.simantics.db.management.ISessionContext; +import org.simantics.db.request.Read; import org.simantics.jfreechart.chart.properties.AdjustableTab; import org.simantics.layer0.Layer0; +import org.simantics.sysdyn.SysdynResource; import org.simantics.sysdyn.ui.properties.widgets.FunctionLabelFactory; import org.simantics.sysdyn.ui.properties.widgets.expressions.ExpressionField; import org.simantics.sysdyn.ui.properties.widgets.factories.FunctionNameInputValidator; @@ -85,6 +92,24 @@ public class FunctionTab extends AdjustableTab { information = new TrackedText(documentationGroup, support, SWT.MULTI | SWT.V_SCROLL | SWT.WRAP); information.setTextFactory(new StringPropertyFactory(Layer0.URIs.HasDescription)); information.addModifyListener(new StringPropertyModifier(context, Layer0.URIs.HasDescription)); + + if (id instanceof Resource) { + final Resource r = (Resource) id; + try { + boolean editable = context.getSession().syncRequest(new Read() { + + @Override + public Boolean perform(ReadGraph graph) throws DatabaseException { + boolean editable = new IsParent(SysdynResource.getInstance(graph).Built$in_Functions, r).perform(graph); + return !editable; + } + }); + information.setEditable(editable); + nameText.setEditable(editable); + } catch (DatabaseException e) { + e.printStackTrace(); + } + } } @Override diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/functions/FunctionCodeWidget.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/functions/FunctionCodeWidget.java index 696f4815..18294955 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/functions/FunctionCodeWidget.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/functions/FunctionCodeWidget.java @@ -34,6 +34,7 @@ import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport; import org.simantics.db.ReadGraph; import org.simantics.db.Resource; import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.IsParent; import org.simantics.db.common.request.WriteRequest; import org.simantics.db.common.utils.ListUtils; import org.simantics.db.exception.DatabaseException; @@ -152,6 +153,16 @@ public class FunctionCodeWidget implements Widget { }); if(code != null) { modelicaCode.setExpression(code); + + boolean editable = context.getSession().syncRequest(new Read() { + + @Override + public Boolean perform(ReadGraph graph) throws DatabaseException { + boolean asd = new IsParent(SysdynResource.getInstance(graph).Built$in_Functions, function).perform(graph); + return !asd; + } + }); + modelicaCode.getSourceViewer().setEditable(editable); validate(); } } catch (DatabaseException e) { @@ -206,6 +217,10 @@ public class FunctionCodeWidget implements Widget { } private void save() { + + if (!modelicaCode.getSourceViewer().isEditable()) + return; + final String code = modelicaCode.getExpression(); // Update input and output lists.