]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
equation editor
authorniemisto <niemisto@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Tue, 17 Nov 2009 14:38:03 +0000 (14:38 +0000)
committerniemisto <niemisto@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Tue, 17 Nov 2009 14:38:03 +0000 (14:38 +0000)
git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@13107 ac1ea38d-2e2b-0410-8846-a27921b304fc

org.simantics.sysdyn.ui/META-INF/MANIFEST.MF
org.simantics.sysdyn.ui/plugin.xml
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/SysdynResource.java [deleted file]
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/SysdynDiagramEditor.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/equation/EquationView.java [new file with mode: 0644]
org.simantics.sysdyn/META-INF/MANIFEST.MF
org.simantics.sysdyn/src/org/simantics/sysdyn/SysdynResource.java [moved from org.simantics.sysdyn.ui/src/org/simantics/sysdyn/SysdynResource.java with 94% similarity]
sysdyn_ontologies/sysdyn.graph

index ab6b800dd8223746933b41aacdda0d3a37fb9334..4274ee39ae3ec0dc480527774fcd368911dde7a3 100644 (file)
@@ -13,4 +13,5 @@ Require-Bundle: org.simantics.h2d;bundle-version="1.0.0",
  org.simantics.ui;bundle-version="1.0.0",
  org.eclipse.ui;bundle-version="3.5.0",
  org.eclipse.core.runtime;bundle-version="3.5.0",
- org.simantics.objmap;bundle-version="0.1.0"
+ org.simantics.objmap;bundle-version="0.1.0",
+ org.simantics.sysdyn;bundle-version="1.0.0"
index bd010c488cbf11686abc886bfd0edef23e85f341..19dc2d0cb26c5982b075ecf81874de8bfa0e534e 100644 (file)
             name="Modelica View"\r
             restorable="true">\r
       </view>\r
+      <view\r
+            category="org.simantics.sysdyn.ui.category"\r
+            class="org.simantics.sysdyn.ui.equation.EquationView"\r
+            id="org.simantics.sysdyn.ui.equation.view"\r
+            name="Equation View"\r
+            restorable="true">\r
+      </view>\r
    </extension>\r
 \r
 </plugin>\r
diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/SysdynResource.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/SysdynResource.java
deleted file mode 100644 (file)
index 426b322..0000000
+++ /dev/null
@@ -1,72 +0,0 @@
-/*******************************************************************************\r
- * Copyright (c) 2007- VTT Technical Research Centre of Finland.\r
- * All rights reserved. This program and the accompanying materials\r
- * are made available under the terms of the Eclipse Public License v1.0\r
- * which accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- *     VTT Technical Research Centre of Finland - initial API and implementation\r
- *******************************************************************************/\r
-package org.simantics.sysdyn.ui;\r
-\r
-\r
-import org.simantics.db.Resource;\r
-import org.simantics.db.ReadGraph;\r
-import org.simantics.db.Session;\r
-import org.simantics.db.exception.DatabaseException;\r
-\r
-public class SysdynResource {\r
-    \r
-    public final Resource HasX;\r
-    public final Resource HasY;\r
-    public final Resource SysdynModel;\r
-    public final Resource SysdynModelManager;\r
-    public final Resource SysdynModellingDomain;\r
-    public final Resource TestDiagram;\r
-    public final Resource Variable;\r
-    public final Resource VariableElement;\r
-    \r
-    public static class URIs {\r
-        public static final String HasX = "http://www.simantics.org/Sysdyn#HasX";\r
-        public static final String HasY = "http://www.simantics.org/Sysdyn#HasY";\r
-        public static final String SysdynModel = "http://www.simantics.org/Sysdyn#SysdynModel";\r
-        public static final String SysdynModelManager = "http://www.simantics.org/Sysdyn#SysdynModelManager";\r
-        public static final String SysdynModellingDomain = "http://www.simantics.org/Sysdyn#SysdynModellingDomain";\r
-        public static final String TestDiagram = "http://www.simantics.org/Sysdyn#TestDiagram";\r
-        public static final String Variable = "http://www.simantics.org/Sysdyn#Variable";\r
-        public static final String VariableElement = "http://www.simantics.org/Sysdyn#VariableElement";\r
-    }\r
-    \r
-    public static Resource getResourceOrNull(ReadGraph graph, String uri) {\r
-        try {\r
-            return graph.getResourceByURI(uri);\r
-        } catch(DatabaseException e) {\r
-            System.err.println(e.getMessage());\r
-            return null;\r
-        }\r
-    }\r
-    \r
-    public SysdynResource(ReadGraph graph) {\r
-        HasX = getResourceOrNull(graph, URIs.HasX);\r
-        HasY = getResourceOrNull(graph, URIs.HasY);\r
-        SysdynModel = getResourceOrNull(graph, URIs.SysdynModel);\r
-        SysdynModelManager = getResourceOrNull(graph, URIs.SysdynModelManager);\r
-        SysdynModellingDomain = getResourceOrNull(graph, URIs.SysdynModellingDomain);\r
-        TestDiagram = getResourceOrNull(graph, URIs.TestDiagram);\r
-        Variable = getResourceOrNull(graph, URIs.Variable);\r
-        VariableElement = getResourceOrNull(graph, URIs.VariableElement);\r
-    }\r
-    \r
-    public static SysdynResource getInstance(ReadGraph graph) {\r
-        Session session = graph.getSession();\r
-        SysdynResource ret = session.getService(SysdynResource.class);\r
-        if(ret == null) {\r
-            ret = new SysdynResource(graph);\r
-            session.registerService(SysdynResource.class, ret);\r
-        }\r
-        return ret;\r
-    }\r
-    \r
-}\r
-\r
index afefa9169ff2549668cf92bdcb27cee5cd8399a7..0a2d62f76b0026f90192b09e591bb504f1e18d9a 100644 (file)
@@ -154,10 +154,17 @@ public class SysdynDiagramEditor extends ResourceEditorPart {
                     \r
                     @Override\r
                     public void selectionChanged(ISelection selection) {\r
-                        ArrayList<Resource> resources = new ArrayList<Resource>(selection.size());\r
+                        final ArrayList<Resource> resources = new ArrayList<Resource>(selection.size());\r
                         for(IElement element : selection)\r
                             resources.add(mapping.inverseGet(element));\r
-                        selectionProvider.setSelection(new StructuredSelection(resources));\r
+                        composite.getDisplay().asyncExec(new Runnable() {\r
+\r
+                            @Override\r
+                            public void run() {\r
+                                selectionProvider.setSelection(new StructuredSelection(resources));\r
+                            }\r
+                            \r
+                        });\r
                     }\r
                     \r
                 });\r
diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/equation/EquationView.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/equation/EquationView.java
new file mode 100644 (file)
index 0000000..ed3d881
--- /dev/null
@@ -0,0 +1,123 @@
+package org.simantics.sysdyn.ui.equation;\r
+\r
+import org.eclipse.jface.viewers.ISelection;\r
+import org.eclipse.jface.viewers.IStructuredSelection;\r
+import org.eclipse.swt.SWT;\r
+import org.eclipse.swt.events.FocusAdapter;\r
+import org.eclipse.swt.events.FocusEvent;\r
+import org.eclipse.swt.events.KeyAdapter;\r
+import org.eclipse.swt.events.KeyEvent;\r
+import org.eclipse.swt.graphics.Font;\r
+import org.eclipse.swt.widgets.Composite;\r
+import org.eclipse.swt.widgets.Text;\r
+import org.eclipse.ui.ISelectionListener;\r
+import org.eclipse.ui.IWorkbenchPart;\r
+import org.eclipse.ui.part.ViewPart;\r
+import org.simantics.db.Builtins;\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.WriteGraph;\r
+import org.simantics.db.common.request.ReadRequest;\r
+import org.simantics.db.common.request.WriteRequest;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.sysdyn.SysdynResource;\r
+import org.simantics.ui.SimanticsUI;\r
+\r
+public class EquationView extends ViewPart implements ISelectionListener {\r
+    \r
+    static final Font FONT = new Font(null, "Courier New", 12, SWT.NORMAL);\r
+    \r
+    Text text;\r
+    Resource auxiliary;\r
+    String originalText;\r
+    \r
+    @Override    \r
+    public void createPartControl(Composite parent) {\r
+        getSite().getPage().addPostSelectionListener(this);\r
+        text = new Text(parent, SWT.MULTI);\r
+        text.setFont(FONT);\r
+        text.addFocusListener(new FocusAdapter() {\r
+            \r
+            @Override\r
+            public void focusLost(FocusEvent e) {\r
+                final String currentText = text.getText();\r
+                if(originalText != null && !originalText.equals(currentText)) {\r
+                    SimanticsUI.getSession().asyncRequest(new WriteRequest() {\r
+\r
+                        @Override\r
+                        public void perform(WriteGraph g)\r
+                                throws DatabaseException {\r
+                            SysdynResource sr = SysdynResource.getInstance(g);\r
+                            g.claimValue(auxiliary, sr.HasValue, currentText);\r
+                        }\r
+                        \r
+                    });\r
+                }\r
+            }            \r
+            \r
+        });\r
+        text.addKeyListener(new KeyAdapter() {          \r
+                        \r
+            @Override\r
+            public void keyPressed(KeyEvent e) {\r
+                if(e.keyCode == SWT.ESC) {\r
+                    text.setText(originalText);\r
+                }                \r
+            }\r
+            \r
+        });\r
+    }   \r
+\r
+    class UpdateViewRequest extends ReadRequest {\r
+\r
+        Resource resource;\r
+        \r
+        public UpdateViewRequest(Resource resource) {\r
+            this.resource = resource;\r
+        }\r
+        \r
+        @Override\r
+        public void run(ReadGraph g) throws DatabaseException {\r
+            SysdynResource sr = SysdynResource.getInstance(g);\r
+            Builtins b = g.getBuiltins();\r
+            if(g.isInstanceOf(resource, sr.Auxiliary)) {\r
+                auxiliary = resource;\r
+                final String name = g.getRelatedValue(resource, b.HasName);\r
+                final String value = g.getPossibleRelatedValue(resource, sr.HasValue);\r
+                text.getDisplay().asyncExec(new Runnable() {\r
+\r
+                    @Override\r
+                    public void run() {\r
+                        if(value == null)\r
+                            originalText = "";\r
+                        else\r
+                            originalText = value;\r
+                        text.setText(originalText);\r
+                        setPartName(name + " equation");\r
+                    }\r
+                    \r
+                });\r
+            }\r
+        }\r
+        \r
+    }\r
+    \r
+    @Override\r
+    public void selectionChanged(IWorkbenchPart part, ISelection selection) {\r
+        if(selection instanceof IStructuredSelection) {\r
+            IStructuredSelection structuredSelection = \r
+                (IStructuredSelection)selection;\r
+            if(structuredSelection.size() == 1) {\r
+                Object element = structuredSelection.getFirstElement();\r
+                if(element instanceof Resource)\r
+                    SimanticsUI.getSession().asyncRequest(new UpdateViewRequest((Resource)element));\r
+            }\r
+        }\r
+    }\r
+\r
+    @Override\r
+    public void setFocus() {\r
+        text.setFocus();\r
+    }\r
+\r
+}\r
index dcebe58c6f7470d0020ac07614c7124b4b6f71fa..6e6d17f2e45a90bc324fdfd39cd7d5524d7b12ed 100644 (file)
@@ -4,4 +4,9 @@ Bundle-Name: Sysdyn
 Bundle-SymbolicName: org.simantics.sysdyn
 Bundle-Version: 1.0.0.qualifier
 Bundle-RequiredExecutionEnvironment: JavaSE-1.6
-Require-Bundle: org.simantics.objmap;bundle-version="0.1.0"
+Require-Bundle: org.simantics.objmap;bundle-version="0.1.0",
+ org.simantics.db;bundle-version="0.6.2"
+Export-Package: org.simantics.sysdyn,
+ org.simantics.sysdyn.modelica,
+ org.simantics.sysdyn.representation,
+ org.simantics.sysdyn.representation.visitors
similarity index 94%
rename from org.simantics.sysdyn.ui/src/org/simantics/sysdyn/SysdynResource.java
rename to org.simantics.sysdyn/src/org/simantics/sysdyn/SysdynResource.java
index 07dfa85a5f93210764ce470cd98461e40a1342c8..5281df8f829ace3fd97e137e46c546956374d3fa 100644 (file)
@@ -26,6 +26,7 @@ public class SysdynResource {
     public final Resource HasAngle;\r
     public final Resource HasHead;\r
     public final Resource HasTail;\r
+    public final Resource HasValue;\r
     public final Resource HasX;\r
     public final Resource HasY;\r
     public final Resource IndependentVariable;\r
@@ -45,6 +46,7 @@ public class SysdynResource {
         public static final String HasAngle = "http://www.simantics.org/Sysdyn#HasAngle";\r
         public static final String HasHead = "http://www.simantics.org/Sysdyn#HasHead";\r
         public static final String HasTail = "http://www.simantics.org/Sysdyn#HasTail";\r
+        public static final String HasValue = "http://www.simantics.org/Sysdyn#HasValue";\r
         public static final String HasX = "http://www.simantics.org/Sysdyn#HasX";\r
         public static final String HasY = "http://www.simantics.org/Sysdyn#HasY";\r
         public static final String IndependentVariable = "http://www.simantics.org/Sysdyn#IndependentVariable";\r
@@ -74,6 +76,7 @@ public class SysdynResource {
         HasAngle = getResourceOrNull(graph, URIs.HasAngle);\r
         HasHead = getResourceOrNull(graph, URIs.HasHead);\r
         HasTail = getResourceOrNull(graph, URIs.HasTail);\r
+        HasValue = getResourceOrNull(graph, URIs.HasValue);\r
         HasX = getResourceOrNull(graph, URIs.HasX);\r
         HasY = getResourceOrNull(graph, URIs.HasY);\r
         IndependentVariable = getResourceOrNull(graph, URIs.IndependentVariable);\r
index a4dddeb873e7cf30e5c5d47fb513d50677468993..eadd105a07e849a2499b6ec4d4dbd524dea5d36d 100644 (file)
@@ -34,10 +34,12 @@ Configuration <T ST.Composite
 Variable <T ST.Component    \r
     [HasX card "1"]\r
     [HasY card "1"]\r
-HasX <R L0.HasProperty\r
+HasX <R L0.HasProperty : L0.FunctionalRelation\r
     L0.HasRange L0.Double\r
-HasY <R L0.HasProperty\r
+HasY <R L0.HasProperty : L0.FunctionalRelation\r
     L0.HasRange L0.Double        \r
+HasValue <R L0.HasProperty : L0.FunctionalRelation\r
+    L0.HasRange L0.String\r
 \r
 IndependentVariable <T Variable\r
     [L0.HasName card "1"]\r
@@ -45,6 +47,7 @@ IndependentVariable <T Variable
 Auxiliary <T IndependentVariable\r
 Stock <T IndependentVariable\r
 Valve <T IndependentVariable\r
+    [HasValue card "0..1"]\r
 Cloud <T IndependentVariable  \r
 \r
 ######################################################################\r