]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
Equation editor sketch
authorlempinen <lempinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Fri, 27 Nov 2009 13:24:35 +0000 (13:24 +0000)
committerlempinen <lempinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Fri, 27 Nov 2009 13:24:35 +0000 (13:24 +0000)
git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@13197 ac1ea38d-2e2b-0410-8846-a27921b304fc

org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/equation/EquationView.java

index 04474d5792fa25fb3f872d9c39b0f8e20d6a3491..84e67309f65b213023e0ee7cb9ebacb0bfdf4e4f 100644 (file)
@@ -1,5 +1,8 @@
 package org.simantics.sysdyn.ui.equation;\r
 \r
+\r
+import org.eclipse.jface.layout.GridDataFactory;\r
+import org.eclipse.jface.layout.GridLayoutFactory;\r
 import org.eclipse.jface.viewers.ISelection;\r
 import org.eclipse.jface.viewers.IStructuredSelection;\r
 import org.eclipse.swt.SWT;\r
@@ -8,7 +11,14 @@ import org.eclipse.swt.events.FocusEvent;
 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.layout.RowLayout;\r
+import org.eclipse.swt.widgets.Combo;\r
 import org.eclipse.swt.widgets.Composite;\r
+import org.eclipse.swt.widgets.Label;\r
+import org.eclipse.swt.widgets.TabFolder;\r
+import org.eclipse.swt.widgets.TabItem;\r
+import org.eclipse.swt.widgets.Table;\r
+import org.eclipse.swt.widgets.TableItem;\r
 import org.eclipse.swt.widgets.Text;\r
 import org.eclipse.ui.ISelectionListener;\r
 import org.eclipse.ui.IWorkbenchPart;\r
@@ -24,20 +34,100 @@ import org.simantics.sysdyn.SysdynResource;
 import org.simantics.ui.SimanticsUI;\r
 \r
 public class EquationView extends ViewPart implements ISelectionListener {\r
-    \r
+\r
     static final Font FONT = new Font(null, "Courier New", 12, SWT.NORMAL);\r
-    \r
+\r
+    Text nameText;\r
+\r
+    Composite equationComposite;\r
+    Label equationLabel;\r
     Text text;\r
-    Resource auxiliary;\r
+    Resource variable;\r
     String originalText;\r
-    \r
+    TabFolder tabFolder;\r
+    TabItem variables;\r
+    TabItem functions;\r
+    Composite unitsAndRange;\r
+    Composite variableType;\r
+\r
+\r
     @Override    \r
     public void createPartControl(Composite parent) {\r
         getSite().getPage().addPostSelectionListener(this);\r
-        text = new Text(parent, SWT.MULTI);\r
+\r
+        GridLayoutFactory.fillDefaults().numColumns(4).margins(5, 5).applyTo(parent);\r
+\r
+        // Upper part of the view: Name (and renaming)\r
+        nameText = new Text(parent, SWT.SINGLE | SWT.BORDER);\r
+        nameText.setFont(FONT);\r
+        GridDataFactory.fillDefaults().span(2, 1).applyTo(nameText);\r
+\r
+        // Center side of the view: (related) variables and possible functions\r
+        TabFolder tabFolder = new TabFolder (parent, SWT.NONE);\r
+        GridDataFactory.fillDefaults().span(1, 4).applyTo(tabFolder);\r
+        variables = new TabItem(tabFolder, SWT.NULL);\r
+        variables.setText("Variables");\r
+        Table table = new Table (tabFolder, SWT.SINGLE | SWT.BORDER | SWT.FULL_SELECTION);\r
+        TableItem item = new TableItem(table, SWT.NONE);\r
+        item.setText("auxiliary21");\r
+        item = new TableItem(table, SWT.NONE);\r
+        item.setText("stock5");\r
+        item = new TableItem(table, SWT.NONE);\r
+        item.setText("valve2");\r
+        variables.setControl(table);\r
+\r
+        functions = new TabItem(tabFolder, SWT.NULL);\r
+        functions.setText("Functions"); \r
+        table = new Table (tabFolder, SWT.SINGLE | SWT.BORDER | SWT.FULL_SELECTION);\r
+        item = new TableItem(table, SWT.NONE);\r
+        item.setText("min");\r
+        item = new TableItem(table, SWT.NONE);\r
+        item.setText("max");\r
+        item = new TableItem(table, SWT.NONE);\r
+        item.setText("abs");\r
+        functions.setControl(table);\r
+        \r
+        // Right side of the view: Details, comments\r
+        Composite emptyComposite = new Composite(parent, SWT.NONE);\r
+        GridDataFactory.fillDefaults().span(1,4).grab(true, true).applyTo(emptyComposite);\r
+\r
+        // Below the variable name: Variable type\r
+        variableType = new Composite(parent, SWT.NONE);\r
+        GridLayoutFactory.fillDefaults().numColumns(5).spacing(3, 0).applyTo(variableType);\r
+        GridDataFactory.fillDefaults().span(2, 1).applyTo(variableType);\r
+        Label label = new Label(variableType, SWT.SINGLE);\r
+        label.setText("Type:");\r
+        Combo comboDropDown = new Combo(variableType, SWT.DROP_DOWN | SWT.BORDER);\r
+        comboDropDown.add("Auxiliary");\r
+        comboDropDown.add("Lookup");\r
+        comboDropDown.add("Delay");\r
+        comboDropDown = new Combo(variableType, SWT.DROP_DOWN | SWT.BORDER);\r
+        comboDropDown.add("Normal");\r
+        comboDropDown.add("With Lookup");\r
+        \r
+        label = new Label(variableType, SWT.SINGLE );\r
+        label.setText("Unit:");\r
+        label.setAlignment(SWT.RIGHT);\r
+        GridDataFactory.fillDefaults().grab(true, false).align(SWT.END, SWT.CENTER).applyTo(label);\r
+        comboDropDown = new Combo(variableType, SWT.DROP_DOWN | SWT.BORDER);\r
+        comboDropDown.add("m");\r
+        comboDropDown.add("V");\r
+        comboDropDown.add("euro");\r
+        \r
+        // Below variable type: Equation\r
+        equationComposite = new Composite(parent, SWT.NONE);\r
+        GridDataFactory.fillDefaults().span(2, 1).grab(true, true).applyTo(equationComposite);\r
+        GridLayoutFactory.fillDefaults().numColumns(2).spacing(3, 3).applyTo(equationComposite);\r
+        equationLabel = new Label(equationComposite, SWT.NONE);\r
+        equationLabel.setFont(FONT);\r
+        equationLabel.setText("=");\r
+        GridDataFactory.fillDefaults().applyTo(equationLabel);\r
+\r
+        text = new Text(equationComposite, SWT.MULTI | SWT.V_SCROLL | SWT.BORDER);\r
         text.setFont(FONT);\r
+        GridDataFactory.fillDefaults().grab(true, true).applyTo(text);\r
         text.addFocusListener(new FocusAdapter() {\r
-            \r
+\r
             @Override\r
             public void focusLost(FocusEvent e) {\r
                 final String currentText = text.getText();\r
@@ -46,92 +136,114 @@ public class EquationView extends ViewPart implements ISelectionListener {
 \r
                         @Override\r
                         public void perform(WriteGraph g)\r
-                                throws DatabaseException {\r
+                        throws DatabaseException {\r
                             Builtins b = g.getBuiltins();\r
                             SysdynResource sr = SysdynResource.getInstance(g);\r
-                            \r
-                            Resource expression = g.getPossibleObject(auxiliary, sr.HasExpression);\r
+\r
+                            Resource expression = g.getPossibleObject(variable, sr.HasExpression);\r
                             if(expression == null) {\r
                                 expression = g.newResource();\r
                                 g.claim(expression, b.InstanceOf, sr.Expression);\r
-                                g.claim(auxiliary, sr.HasExpression, expression);\r
+                                g.claim(variable, sr.HasExpression, expression);\r
                             }\r
                             g.claimValue(expression, sr.HasText, currentText);\r
                         }\r
-                        \r
+\r
                     });\r
                 }\r
             }            \r
-            \r
+\r
         });\r
         text.addKeyListener(new KeyAdapter() {          \r
-                        \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
+        // Lower part of the view: Units and Range\r
+        unitsAndRange = new Composite(parent, SWT.NONE); \r
+        GridDataFactory.fillDefaults().span(2, 1).applyTo(unitsAndRange);\r
+        RowLayout layout = new RowLayout();\r
+        layout.spacing = 3;\r
+        unitsAndRange.setLayout(layout);\r
+        label = new Label(unitsAndRange, SWT.SINGLE);\r
+        label.setText("Range:");\r
+        label.setAlignment(SWT.RIGHT);\r
+        Composite c =  new Composite(unitsAndRange, SWT.NONE);\r
+        layout = new RowLayout();\r
+        layout.spacing = 2;\r
+        c.setLayout(layout);\r
+        Text text1 = new Text(c, SWT.SINGLE | SWT.BORDER);\r
+        text1.setToolTipText("Start");\r
+        text1 = new Text(c, SWT.SINGLE | SWT.BORDER);\r
+        text1.setToolTipText("Stop");\r
+        text1 = new Text(c, SWT.SINGLE | SWT.BORDER);\r
+        text1.setToolTipText("Step");\r
     }   \r
 \r
     class UpdateViewRequest extends ReadRequest {\r
 \r
         Resource resource;\r
-        \r
+\r
         public UpdateViewRequest(Resource resource) {\r
             this.resource = resource;\r
         }\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) || g.isInstanceOf(resource, sr.Valve)) {\r
-                auxiliary = resource;\r
-                final String name = g.getRelatedValue(resource, b.HasName);\r
-                Resource expression = g.getPossibleObject(resource, sr.HasExpression);     \r
-                final String value = expression == null ? null :\r
-                    (String)g.getPossibleRelatedValue(expression, sr.HasText);\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("Value of " + name);\r
-                    }\r
-                    \r
-                });\r
-            }\r
-            else if(g.isInstanceOf(resource, sr.Stock)) {\r
-                auxiliary = resource;\r
-                final String name = g.getRelatedValue(resource, b.HasName);\r
-                Resource expression = g.getPossibleObject(resource, sr.HasExpression);    \r
-                final String value = expression == null ? null :\r
-                    (String)g.getPossibleRelatedValue(expression, sr.HasText);\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("Initial value of " + name);\r
-                    }\r
-                    \r
-                });\r
-            }\r
+            final String eqLabel; \r
+            if (g.isInstanceOf(resource, sr.Auxiliary) || g.isInstanceOf(resource, sr.Valve))\r
+                eqLabel = "=";\r
+            else if (g.isInstanceOf(resource, sr.Stock))\r
+                eqLabel = "initial =";\r
+            else \r
+                return;\r
+            variable = resource;\r
+            final String name = g.getRelatedValue(resource, b.HasName);\r
+            Resource expression = g.getPossibleObject(resource, sr.HasExpression);     \r
+            final String value = expression == null ? null :\r
+                (String)g.getPossibleRelatedValue(expression, sr.HasText);\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
+                }\r
+\r
+            });\r
+            nameText.getDisplay().asyncExec(new Runnable() {\r
+\r
+                @Override\r
+                public void run() {\r
+                    nameText.setText(name);\r
+                }\r
+            });\r
+            equationComposite.getDisplay().asyncExec(new Runnable() {\r
+\r
+                @Override\r
+                public void run() {\r
+                    equationLabel.setText(eqLabel);\r
+                    equationComposite.layout();\r
+                }\r
+            });\r
+\r
         }\r
-        \r
+\r
+\r
+\r
     }\r
-    \r
+\r
     @Override\r
     public void selectionChanged(IWorkbenchPart part, ISelection selection) {\r
         if(selection instanceof IStructuredSelection) {\r
@@ -150,4 +262,4 @@ public class EquationView extends ViewPart implements ISelectionListener {
         text.setFocus();\r
     }\r
 \r
-}\r
+}
\ No newline at end of file