]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@16189 ac1ea38d-2e2b...
authorlempinen <lempinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Thu, 17 Jun 2010 13:24:31 +0000 (13:24 +0000)
committerlempinen <lempinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Thu, 17 Jun 2010 13:24:31 +0000 (13:24 +0000)
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ConfigurationTab.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/EquationTab.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ResourceSelectionProcessor.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/VariableCommentTab.java [new file with mode: 0644]
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/TextWidget.java [new file with mode: 0644]
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/VariableNameWidget.java [moved from org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/NameWidget.java with 95% similarity]
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/factories/DoublePropertyFactory.java [new file with mode: 0644]

index 3c2ff78390094cd40c8550933c34ec69af897247..f5d6359d1cf5eccfdd645fb937b1ca23e83cd68c 100644 (file)
 package org.simantics.sysdyn.ui.properties;\r
 \r
+import org.eclipse.jface.layout.GridDataFactory;\r
+import org.eclipse.jface.layout.GridLayoutFactory;\r
+import org.eclipse.swt.SWT;\r
+import org.eclipse.swt.events.FocusEvent;\r
+import org.eclipse.swt.events.FocusListener;\r
+import org.eclipse.swt.events.VerifyEvent;\r
+import org.eclipse.swt.events.VerifyListener;\r
 import org.eclipse.swt.widgets.Composite;\r
+import org.eclipse.swt.widgets.Label;\r
+import org.eclipse.swt.widgets.Text;\r
 import org.eclipse.ui.IWorkbenchSite;\r
 import org.simantics.browsing.ui.swt.PropertyTabContributorImpl;\r
+import org.simantics.browsing.ui.swt.widgets.StringPropertyFactory;\r
 import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport;\r
+import org.simantics.db.Builtins;\r
 import org.simantics.db.management.ISessionContext;\r
+import org.simantics.sysdyn.SysdynResource;\r
+import org.simantics.sysdyn.ui.properties.widgets.TextWidget;\r
+import org.simantics.sysdyn.ui.properties.widgets.factories.DoublePropertyFactory;\r
 \r
 public class ConfigurationTab extends PropertyTabContributorImpl {\r
 \r
+    TextWidget name, startTime, stopTime;\r
+    \r
+    \r
     @Override\r
     public void createControls(Composite body, IWorkbenchSite site, ISessionContext context, WidgetSupport support) {\r
-        // TODO Auto-generated method stub\r
+        Composite composite = new Composite(body, SWT.NONE);\r
+        GridDataFactory.fillDefaults().grab(true, true).applyTo(composite);\r
+        GridLayoutFactory.fillDefaults().margins(3, 3).numColumns(2).applyTo(composite);\r
+\r
+        Label label = new Label(composite, SWT.NONE);\r
+        label.setText("Name");\r
+        \r
+        name = new TextWidget(composite, support, SWT.BORDER);\r
+        name.setTextFactory(new StringPropertyFactory(context, Builtins.URIs.HasName));\r
+        name.addFocusListener(new SaveListener());\r
+        name.addVerifyListener(new VerifyListener() {\r
+\r
+            @Override\r
+            public void verifyText(VerifyEvent e) {\r
+                e.doit = false;\r
+                String s = e.text;   \r
+                if(!s.contains(" ")) {\r
+                    e.doit = true;\r
+                }\r
+            }\r
+        });\r
+        GridDataFactory.fillDefaults().hint(200, SWT.DEFAULT).applyTo(name.getTextWidget());\r
+\r
+        label = new Label(composite, SWT.NONE);\r
+        label.setText("Start time");\r
+\r
+        startTime = new TextWidget(composite, support, SWT.BORDER | SWT.RIGHT);\r
+        startTime.setTextFactory(new DoublePropertyFactory(context, SysdynResource.URIs.HasStartTime));\r
+        startTime.addVerifyListener(new DoubleVerify());\r
+        startTime.addFocusListener(new SaveListener());\r
+        GridDataFactory.fillDefaults().hint(200, SWT.DEFAULT).applyTo(startTime.getTextWidget());\r
+\r
+        label = new Label(composite, SWT.NONE);\r
+        label.setText("Stop time");\r
+\r
+        stopTime = new TextWidget(composite, support, SWT.BORDER | SWT.RIGHT);\r
+        stopTime.setTextFactory(new DoublePropertyFactory(context, SysdynResource.URIs.HasStopTime));\r
+        stopTime.addVerifyListener(new DoubleVerify());\r
+        stopTime.addFocusListener(new SaveListener());\r
+        GridDataFactory.fillDefaults().hint(200, SWT.DEFAULT).applyTo(stopTime.getTextWidget());\r
         \r
     }\r
 \r
+    private class DoubleVerify implements VerifyListener {\r
 \r
+        @Override\r
+        public void verifyText(VerifyEvent e) {\r
+            e.doit = true;\r
+            for(int i = 0; i < e.text.length(); i++){\r
+                if(!Character.isDigit(e.text.charAt(i))){\r
+                    if(e.text.charAt(i) != '.') {\r
+                        e.doit = false;\r
+                        break; \r
+                    } else if(e.text.indexOf('.') != e.text.lastIndexOf('.')) {\r
+                        e.doit = false;\r
+                        break; \r
+                    } else if(((Text)e.widget).getText().substring(0, e.start).contains(".") ||\r
+                            ((Text)e.widget).getText().substring(e.end, ((Text)e.widget).getText().length()).contains(".")) {\r
+                        e.doit = false;\r
+                        break;     \r
+                    }\r
+                } \r
+            }\r
+        }\r
+    }\r
+    \r
+    private class SaveListener implements FocusListener {\r
+\r
+        @Override\r
+        public void focusGained(FocusEvent e) {\r
+        }\r
+\r
+        @Override\r
+        public void focusLost(FocusEvent e) {\r
+            save();\r
+        }\r
+        \r
+    }\r
+    \r
+    private void save() {\r
+        this.name.save();\r
+        this.startTime.save();\r
+        this.stopTime.save();\r
+    }\r
+    \r
+    \r
 }\r
index e398245abf4c439d2ac46fc1d03bd29e9f409479..b581a06ac1c63a93bf42f65c2852a368681a9c6f 100644 (file)
@@ -25,13 +25,13 @@ import org.simantics.db.management.ISessionContext;
 import org.simantics.sysdyn.SysdynResource;\r
 import org.simantics.sysdyn.ui.properties.widgets.ExpressionTypeWidget;\r
 import org.simantics.sysdyn.ui.properties.widgets.ExpressionWidget;\r
-import org.simantics.sysdyn.ui.properties.widgets.NameWidget;\r
+import org.simantics.sysdyn.ui.properties.widgets.VariableNameWidget;\r
 import org.simantics.sysdyn.ui.properties.widgets.ShortcutTabWidget;\r
 import org.simantics.sysdyn.ui.properties.widgets.UnitWidget;\r
 \r
 public class EquationTab extends PropertyTabContributorImpl {\r
 \r
-    NameWidget nameWidget;\r
+    VariableNameWidget nameWidget;\r
     ExpressionTypeWidget expressionTypeWidget;\r
     UnitWidget unitWidget;\r
     ShortcutTabWidget shortcutTabWidget;\r
@@ -42,7 +42,7 @@ public class EquationTab extends PropertyTabContributorImpl {
         Composite composite = new Composite(body, SWT.NONE);\r
         GridDataFactory.fillDefaults().grab(true, true).applyTo(composite);\r
         GridLayoutFactory.fillDefaults().margins(3, 3).numColumns(6).applyTo(composite);\r
-        nameWidget = new NameWidget(composite, support, SWT.BORDER);\r
+        nameWidget = new VariableNameWidget(composite, support, SWT.BORDER);\r
         nameWidget.setTextFactory(new StringPropertyFactory(context, Builtins.URIs.HasName));\r
 \r
 \r
index 83d0eca1a34c98af579b55bd46b1a44611a85ee7..57f162b27b1b1f98e537a62cb87fb00f56f58580 100644 (file)
@@ -1,6 +1,5 @@
 package org.simantics.sysdyn.ui.properties;\r
 \r
-import java.util.ArrayList;\r
 import java.util.Collection;\r
 import java.util.Collections;\r
 \r
@@ -21,7 +20,7 @@ public class ResourceSelectionProcessor implements SelectionProcessor<ISelection
         if(r != null)\r
         try {\r
             SysdynResource sr = SysdynResource.getInstance(backend);\r
-            ArrayList<ComparableTabContributor> tabs = new ArrayList<ComparableTabContributor>();\r
+//            ArrayList<ComparableTabContributor> tabs = new ArrayList<ComparableTabContributor>();\r
             if (backend.isInstanceOf(r, sr.IndependentVariable))\r
                 return Collections.singleton(\r
                     new ComparableTabContributor(\r
@@ -39,21 +38,21 @@ public class ResourceSelectionProcessor implements SelectionProcessor<ISelection
             if (backend.isInstanceOf(r, sr.Experiment))\r
                 return Collections.singleton(\r
                         new ComparableTabContributor(\r
-                            new ConfigurationTab(),\r
+                            new ExperimentTab(),\r
                             0,\r
                             r,\r
                             "Experiment Properties"));\r
             if (backend.isInstanceOf(r, sr.SysdynModel))\r
                 return Collections.singleton(\r
                         new ComparableTabContributor(\r
-                            new ConfigurationTab(),\r
+                            new ModelTab(),\r
                             0,\r
                             r,\r
                             "Model Properties"));\r
             if (backend.isInstanceOf(r, sr.Result))\r
                 return Collections.singleton(\r
                         new ComparableTabContributor(\r
-                            new ConfigurationTab(),\r
+                            new ResultTab(),\r
                             0,\r
                             r,\r
                             "Result Properties"));\r
diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/VariableCommentTab.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/VariableCommentTab.java
new file mode 100644 (file)
index 0000000..a82fb44
--- /dev/null
@@ -0,0 +1,5 @@
+package org.simantics.sysdyn.ui.properties;\r
+\r
+public class VariableCommentTab {\r
+\r
+}\r
diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/TextWidget.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/TextWidget.java
new file mode 100644 (file)
index 0000000..e220bcb
--- /dev/null
@@ -0,0 +1,148 @@
+package org.simantics.sysdyn.ui.properties.widgets;\r
+\r
+import org.eclipse.jface.viewers.ISelection;\r
+import org.eclipse.swt.SWT;\r
+import org.eclipse.swt.events.FocusListener;\r
+import org.eclipse.swt.events.KeyEvent;\r
+import org.eclipse.swt.events.KeyListener;\r
+import org.eclipse.swt.events.VerifyListener;\r
+import org.eclipse.swt.widgets.Composite;\r
+import org.eclipse.swt.widgets.Text;\r
+import org.simantics.browsing.ui.swt.widgets.StringPropertyFactory;\r
+import org.simantics.browsing.ui.swt.widgets.impl.ReadFactory;\r
+import org.simantics.browsing.ui.swt.widgets.impl.Widget;\r
+import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.WriteGraph;\r
+import org.simantics.db.common.request.WriteRequest;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.db.procedure.Listener;\r
+import org.simantics.sysdyn.ui.properties.widgets.factories.DoublePropertyFactory;\r
+import org.simantics.ui.SimanticsUI;\r
+import org.simantics.utils.datastructures.Triple;\r
+import org.simantics.utils.ui.ISelectionUtils;\r
+\r
+public class TextWidget implements Widget {\r
+\r
+    private Text textWidget;\r
+    private String originalText = "";\r
+    private ReadFactory<?, String> readFactory;\r
+    private Resource resource;\r
+\r
+    public TextWidget(Composite parent, WidgetSupport support, int style) {\r
+        support.register(this);\r
+        textWidget = new Text(parent, style);\r
+        textWidget.addKeyListener(new KeyListener() {\r
+\r
+            @Override\r
+            public void keyReleased(KeyEvent e) {\r
+            }\r
+\r
+            @Override\r
+            public void keyPressed(KeyEvent e) {\r
+                if(e.keyCode == SWT.ESC) {\r
+                    Text text = (Text)e.widget;\r
+                    text.setText(originalText);\r
+                    text.setSelection(text.getCharCount());\r
+                }\r
+            }\r
+        });\r
+    }\r
+\r
+    public void setTextFactory(ReadFactory<?, String> textFactory) {\r
+        this.readFactory = textFactory;\r
+    }\r
+\r
+    @Override\r
+    public void setInput(Object input) {\r
+        if(input instanceof ISelection)\r
+            resource = ISelectionUtils.filterSingleSelection((ISelection)input, Resource.class);\r
+\r
+        if(readFactory != null) {\r
+            readFactory.listen(input, new Listener<String>() {\r
+\r
+                @Override\r
+                public void exception(Throwable t) {\r
+                    t.printStackTrace();\r
+                }\r
+\r
+                @Override\r
+                public void execute(final String text) {\r
+\r
+                    if(text == null) return;\r
+\r
+                    textWidget.getDisplay().asyncExec(new Runnable() {\r
+\r
+                        @Override\r
+                        public void run() {\r
+\r
+                            if(isDisposed()) return;\r
+                            textWidget.setText(text);\r
+                            originalText = text;\r
+\r
+                        }\r
+\r
+                    });\r
+                }\r
+\r
+                @Override\r
+                public boolean isDisposed() {\r
+                    return textWidget.isDisposed();\r
+                }\r
+\r
+            });\r
+        }\r
+\r
+    }\r
+\r
+    @SuppressWarnings("unchecked")\r
+    public void save() {\r
+        if(originalText.equals(textWidget.getText())) return;\r
+        \r
+        final String text = textWidget.getText();\r
+        \r
+        SimanticsUI.getSession().asyncRequest(new WriteRequest() {\r
+            \r
+            @Override\r
+            public void perform(WriteGraph graph) throws DatabaseException {\r
+                \r
+                Triple triple = null;\r
+                Object object = null;\r
+                \r
+                if(readFactory instanceof DoublePropertyFactory) {\r
+                    DoublePropertyFactory factory = (DoublePropertyFactory)readFactory;\r
+                    triple = (Triple) factory.getIdentity(null);\r
+                    object = Double.parseDouble(text);\r
+                } else if (readFactory instanceof StringPropertyFactory) {\r
+                    StringPropertyFactory factory = (StringPropertyFactory)readFactory;\r
+                    triple = (Triple) factory.getIdentity(null);\r
+                    object = text;\r
+                }\r
+                \r
+                if(triple == null || object == null) return;\r
+                graph.claimValue(resource,  graph.getResource((String)triple.second), object);\r
+            }\r
+        });\r
+        \r
+    }\r
+\r
+    public void addKeyListener(KeyListener listener) {\r
+        this.textWidget.addKeyListener(listener);\r
+    }\r
+\r
+    public void addVerifyListener(VerifyListener listener) {\r
+        this.textWidget.addVerifyListener(listener);\r
+    }\r
+    \r
+    public void addFocusListener(FocusListener listener) {\r
+        this.textWidget.addFocusListener(listener);\r
+    }\r
+\r
+    public String getText() {\r
+        return textWidget.getText();\r
+    }\r
+\r
+    public Text getTextWidget() {\r
+        return textWidget;\r
+    }\r
+}\r
similarity index 95%
rename from org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/NameWidget.java
rename to org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/VariableNameWidget.java
index ed83f2342985495039cb2ef6da8483ca4dbe95fa..ab10229e708a069bb6bc43e070d833703b905126 100644 (file)
@@ -34,7 +34,7 @@ import org.simantics.sysdyn.representation.Variable;
 import org.simantics.ui.SimanticsUI;\r
 import org.simantics.utils.ui.ISelectionUtils;\r
 \r
-public class NameWidget implements Widget {\r
+public class VariableNameWidget implements Widget {\r
 \r
     private org.eclipse.swt.widgets.Text nameText;\r
     private String originalName = "";\r
@@ -42,7 +42,7 @@ public class NameWidget implements Widget {
     private Resource variable;\r
     private Resource configuration;\r
 \r
-    public NameWidget(Composite parent, WidgetSupport support, int style) {\r
+    public VariableNameWidget(Composite parent, WidgetSupport support, int style) {\r
         support.register(this);\r
         nameText = new org.eclipse.swt.widgets.Text(parent, style);\r
 \r
diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/factories/DoublePropertyFactory.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/factories/DoublePropertyFactory.java
new file mode 100644 (file)
index 0000000..f7a5d66
--- /dev/null
@@ -0,0 +1,32 @@
+package org.simantics.sysdyn.ui.properties.widgets.factories;\r
+\r
+import org.simantics.browsing.ui.swt.widgets.impl.ReadFactoryImpl;\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.db.management.ISessionContext;\r
+import org.simantics.utils.datastructures.Triple;\r
+\r
+public class DoublePropertyFactory extends ReadFactoryImpl<Resource, String> {\r
+\r
+    final private String propertyURI;\r
+    \r
+    public DoublePropertyFactory(ISessionContext context, String propertyURI) {\r
+        super(context);\r
+        this.propertyURI = propertyURI;\r
+    }\r
+\r
+    @Override\r
+    public Object getIdentity(Object inputContents) {\r
+        return new Triple<Resource, String, Object>((Resource)inputContents, propertyURI, getClass());\r
+    }\r
+    \r
+    @Override\r
+    public String perform(ReadGraph graph, Resource issue) throws DatabaseException {\r
+        \r
+        Double value = graph.getPossibleRelatedValue(issue, graph.getResource(propertyURI));\r
+        return value.toString();\r
+        \r
+    }\r
+    \r
+}\r