]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
Added key verification support for expression fields.
authorlempinen <lempinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Tue, 5 Oct 2010 13:00:01 +0000 (13:00 +0000)
committerlempinen <lempinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Tue, 5 Oct 2010 13:00:01 +0000 (13:00 +0000)
Enter key is used as apply and shift+enter is used as line change

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

org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/EquationTab.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/ExpressionWidget.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/BasicExpression.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/DelayExpression.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/EmptyExpression.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/IExpression.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/LookupExpression.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/StockExpression.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/WithLookupExpression.java

index 5e61552b2468bd686c798a16d4d8105549ff6472..6d2ded05ce36ef1913428711890d134907e18a20 100644 (file)
@@ -7,12 +7,15 @@ import java.util.Map;
 import org.eclipse.jface.layout.GridDataFactory;\r
 import org.eclipse.jface.layout.GridLayoutFactory;\r
 import org.eclipse.swt.SWT;\r
+import org.eclipse.swt.custom.StyledText;\r
+import org.eclipse.swt.custom.VerifyKeyListener;\r
 import org.eclipse.swt.events.FocusEvent;\r
 import org.eclipse.swt.events.FocusListener;\r
 import org.eclipse.swt.events.ModifyEvent;\r
 import org.eclipse.swt.events.ModifyListener;\r
 import org.eclipse.swt.events.MouseEvent;\r
 import org.eclipse.swt.events.MouseListener;\r
+import org.eclipse.swt.events.VerifyEvent;\r
 import org.eclipse.swt.graphics.Point;\r
 import org.eclipse.swt.widgets.Composite;\r
 import org.eclipse.swt.widgets.Label;\r
@@ -231,6 +234,20 @@ public class EquationTab extends PropertyTabContributorImpl {
             }\r
         });\r
         \r
+        expressionWidget.addVerifyKeyListener(new VerifyKeyListener() {\r
+                       \r
+                       @Override\r
+                       public void verifyKey(VerifyEvent event) {\r
+                               if(event.keyCode == SWT.CR || event.keyCode == SWT.KEYPAD_CR) {\r
+                                       if((event.stateMask & SWT.SHIFT) == 0) {\r
+                                               event.doit = false;\r
+                                               ((StyledText)event.widget).getParent().forceFocus();\r
+                                               expressionWidget.save();\r
+                                       }\r
+                               }\r
+                       }\r
+               });\r
+        \r
         focusLostListener = new org.eclipse.ui.IPartListener2()\r
         {\r
             public void partInputChanged(IWorkbenchPartReference partRef) {}\r
index 823eb4b796e3079cc73f2149d22728933458c5e6..7e6f2c2e3c43929b9209123d26582504868f9ae6 100644 (file)
@@ -5,6 +5,7 @@ import java.util.Map;
 \r
 import org.eclipse.jface.viewers.ISelection;\r
 import org.eclipse.jface.viewers.IStructuredSelection;\r
+import org.eclipse.swt.custom.VerifyKeyListener;\r
 import org.eclipse.swt.events.FocusListener;\r
 import org.eclipse.swt.events.ModifyListener;\r
 import org.eclipse.swt.widgets.Composite;\r
@@ -43,6 +44,7 @@ public class ExpressionWidget implements Widget {
     private ModifyListener modifyListener;\r
     private FocusListener focusListener;\r
     private Table variableTable;\r
+       private VerifyKeyListener verifyKeyListener;\r
     \r
     \r
     public ExpressionWidget(Composite parent, WidgetSupport support, int style) {\r
@@ -105,9 +107,12 @@ public class ExpressionWidget implements Widget {
                 exp.readData(variable, data);\r
             \r
             exp.createExpressionFields(parent, data);\r
+            if(modifyListener != null)\r
             exp.addModifyListener(modifyListener);\r
             if(focusListener != null)\r
                exp.addFocusListener(focusListener);\r
+            if(verifyKeyListener != null)\r
+               exp.addVerifyKeyListener(verifyKeyListener);\r
             this.expression = exp;\r
             this.parent.layout();\r
             validateFields();\r
@@ -154,6 +159,10 @@ public class ExpressionWidget implements Widget {
         this.modifyListener = listener;\r
     }\r
     \r
+    public void addVerifyKeyListener(VerifyKeyListener listener) {\r
+       this.verifyKeyListener = listener;\r
+    }\r
+    \r
     public void addFocusListener(FocusListener listener) {\r
         this.focusListener = listener;\r
     }\r
index 58d265f9a3218b36d8b9b463e6609c9d9d08a20d..f9bbaaf5234df8e3504668127736723012a1bce6 100644 (file)
@@ -9,6 +9,7 @@ import org.eclipse.jface.layout.GridLayoutFactory;
 import org.eclipse.jface.text.BadLocationException;\r
 import org.eclipse.jface.text.IDocument;\r
 import org.eclipse.swt.SWT;\r
+import org.eclipse.swt.custom.VerifyKeyListener;\r
 import org.eclipse.swt.events.FocusListener;\r
 import org.eclipse.swt.events.KeyListener;\r
 import org.eclipse.swt.events.ModifyListener;\r
@@ -162,4 +163,9 @@ public class BasicExpression implements IExpression {
     public void addFocusListener(FocusListener listener) {\r
         this.expression.getSourceViewer().getTextWidget().addFocusListener(listener);\r
     }\r
+\r
+       @Override\r
+       public void addVerifyKeyListener(VerifyKeyListener listener) {\r
+               this.expression.getSourceViewer().getTextWidget().addVerifyKeyListener(listener);\r
+       }\r
 }\r
index 8c9eb5dea07fd03779e3e7fe7d899040ce7d7479..5a4f6c201cc87ad9e0a81febe2f47b0dc490bac1 100644 (file)
@@ -3,6 +3,7 @@ package org.simantics.sysdyn.ui.properties.widgets.expressions;
 import java.util.List;\r
 import java.util.Map;\r
 \r
+import org.eclipse.swt.custom.VerifyKeyListener;\r
 import org.eclipse.swt.events.FocusListener;\r
 import org.eclipse.swt.events.KeyListener;\r
 import org.eclipse.swt.events.ModifyListener;\r
@@ -71,4 +72,10 @@ public class DelayExpression implements IExpression {
         \r
     }\r
 \r
+       @Override\r
+       public void addVerifyKeyListener(VerifyKeyListener listener) {\r
+               // TODO Auto-generated method stub\r
+               \r
+       }\r
+\r
 }\r
index f2a99fd3cf6a28a9a2bb8b088987a0c27760109e..14ab8cdd999bee4bd4a226f7cb946bdc7540e0ca 100644 (file)
@@ -3,6 +3,7 @@ package org.simantics.sysdyn.ui.properties.widgets.expressions;
 import java.util.List;\r
 import java.util.Map;\r
 \r
+import org.eclipse.swt.custom.VerifyKeyListener;\r
 import org.eclipse.swt.events.FocusListener;\r
 import org.eclipse.swt.events.KeyListener;\r
 import org.eclipse.swt.events.ModifyListener;\r
@@ -71,4 +72,10 @@ public class EmptyExpression implements IExpression {
         \r
     }\r
 \r
+       @Override\r
+       public void addVerifyKeyListener(VerifyKeyListener listener) {\r
+               // TODO Auto-generated method stub\r
+               \r
+       }\r
+\r
 }\r
index 6c8c152c2e2ffff4d0a2cd690d0aafd190db3788..cf1547809aef22f020b1e3fcee8f9c51e058736c 100644 (file)
@@ -3,6 +3,7 @@ package org.simantics.sysdyn.ui.properties.widgets.expressions;
 import java.util.List;\r
 import java.util.Map;\r
 \r
+import org.eclipse.swt.custom.VerifyKeyListener;\r
 import org.eclipse.swt.events.FocusListener;\r
 import org.eclipse.swt.events.KeyListener;\r
 import org.eclipse.swt.events.ModifyListener;\r
@@ -28,6 +29,8 @@ public interface IExpression {
     public void addModifyListener(ModifyListener listener);\r
     \r
     public void addKeyListener(KeyListener listener);\r
+    \r
+    public void addVerifyKeyListener(VerifyKeyListener listener);\r
 \r
     public void addFocusListener(FocusListener listener);\r
 }\r
index 4bb7fb3293e24757de588c92729e2c7e5542f17d..9acc70c7908720090323d23f6408fdeaca698058 100644 (file)
@@ -3,6 +3,7 @@ package org.simantics.sysdyn.ui.properties.widgets.expressions;
 import java.util.List;\r
 import java.util.Map;\r
 \r
+import org.eclipse.swt.custom.VerifyKeyListener;\r
 import org.eclipse.swt.events.FocusListener;\r
 import org.eclipse.swt.events.KeyListener;\r
 import org.eclipse.swt.events.ModifyListener;\r
@@ -71,4 +72,10 @@ public class LookupExpression implements IExpression {
         \r
     }\r
 \r
+       @Override\r
+       public void addVerifyKeyListener(VerifyKeyListener listener) {\r
+               // TODO Auto-generated method stub\r
+               \r
+       }\r
+\r
 }\r
index 5d9ab6091c2e72b0c1d49ce0fe2ac7af12a5bb88..55cbe81d8f2909fcdd48dfc633f5d9ef320c2d62 100644 (file)
@@ -10,6 +10,7 @@ import org.eclipse.jface.layout.GridLayoutFactory;
 import org.eclipse.jface.text.BadLocationException;\r
 import org.eclipse.jface.text.IDocument;\r
 import org.eclipse.swt.SWT;\r
+import org.eclipse.swt.custom.VerifyKeyListener;\r
 import org.eclipse.swt.events.FocusListener;\r
 import org.eclipse.swt.events.KeyListener;\r
 import org.eclipse.swt.events.ModifyListener;\r
@@ -213,5 +214,10 @@ public class StockExpression implements IExpression {
     public void addFocusListener(FocusListener listener) {\r
         this.expression.getSourceViewer().getTextWidget().addFocusListener(listener);\r
     }\r
+    \r
+       @Override\r
+       public void addVerifyKeyListener(VerifyKeyListener listener) {\r
+               this.expression.getSourceViewer().getTextWidget().addVerifyKeyListener(listener);\r
+       }\r
 \r
 }\r
index a0bcf27acf849328cd5fb6fca0e5783a46fbfba3..0fa9e8bc06c02769b6aeb90aee3723768f8c1e45 100644 (file)
@@ -19,6 +19,7 @@ import org.eclipse.jface.text.BadLocationException;
 import org.eclipse.jface.text.IDocument;\r
 import org.eclipse.swt.SWT;\r
 import org.eclipse.swt.awt.SWT_AWT;\r
+import org.eclipse.swt.custom.VerifyKeyListener;\r
 import org.eclipse.swt.events.FocusAdapter;\r
 import org.eclipse.swt.events.FocusEvent;\r
 import org.eclipse.swt.events.FocusListener;\r
@@ -290,6 +291,12 @@ public class WithLookupExpression implements IExpression {
         this.expression.getSourceViewer().getTextWidget().addKeyListener(listener);\r
         this.lookup.getSourceViewer().getTextWidget().addKeyListener(listener);\r
     }\r
+    \r
+       @Override\r
+       public void addVerifyKeyListener(VerifyKeyListener listener) {\r
+               this.expression.getSourceViewer().getTextWidget().addVerifyKeyListener(listener);\r
+               this.lookup.getSourceViewer().getTextWidget().addVerifyKeyListener(listener);\r
+       }\r
 \r
     @Override\r
     public void addModifyListener(ModifyListener listener) {\r