From 3a19f9564681f624c21b9f796a64df50755aea07 Mon Sep 17 00:00:00 2001 From: lempinen Date: Tue, 5 Oct 2010 13:00:01 +0000 Subject: [PATCH] Added key verification support for expression fields. 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 --- .../sysdyn/ui/properties/EquationTab.java | 17 +++++++++++++++++ .../ui/properties/widgets/ExpressionWidget.java | 9 +++++++++ .../widgets/expressions/BasicExpression.java | 6 ++++++ .../widgets/expressions/DelayExpression.java | 7 +++++++ .../widgets/expressions/EmptyExpression.java | 7 +++++++ .../widgets/expressions/IExpression.java | 3 +++ .../widgets/expressions/LookupExpression.java | 7 +++++++ .../widgets/expressions/StockExpression.java | 6 ++++++ .../expressions/WithLookupExpression.java | 7 +++++++ 9 files changed, 69 insertions(+) diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/EquationTab.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/EquationTab.java index 5e61552b..6d2ded05 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/EquationTab.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/EquationTab.java @@ -7,12 +7,15 @@ import java.util.Map; import org.eclipse.jface.layout.GridDataFactory; import org.eclipse.jface.layout.GridLayoutFactory; import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.StyledText; +import org.eclipse.swt.custom.VerifyKeyListener; import org.eclipse.swt.events.FocusEvent; import org.eclipse.swt.events.FocusListener; import org.eclipse.swt.events.ModifyEvent; import org.eclipse.swt.events.ModifyListener; import org.eclipse.swt.events.MouseEvent; import org.eclipse.swt.events.MouseListener; +import org.eclipse.swt.events.VerifyEvent; import org.eclipse.swt.graphics.Point; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Label; @@ -231,6 +234,20 @@ public class EquationTab extends PropertyTabContributorImpl { } }); + expressionWidget.addVerifyKeyListener(new VerifyKeyListener() { + + @Override + public void verifyKey(VerifyEvent event) { + if(event.keyCode == SWT.CR || event.keyCode == SWT.KEYPAD_CR) { + if((event.stateMask & SWT.SHIFT) == 0) { + event.doit = false; + ((StyledText)event.widget).getParent().forceFocus(); + expressionWidget.save(); + } + } + } + }); + focusLostListener = new org.eclipse.ui.IPartListener2() { public void partInputChanged(IWorkbenchPartReference partRef) {} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/ExpressionWidget.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/ExpressionWidget.java index 823eb4b7..7e6f2c2e 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/ExpressionWidget.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/ExpressionWidget.java @@ -5,6 +5,7 @@ import java.util.Map; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.swt.custom.VerifyKeyListener; import org.eclipse.swt.events.FocusListener; import org.eclipse.swt.events.ModifyListener; import org.eclipse.swt.widgets.Composite; @@ -43,6 +44,7 @@ public class ExpressionWidget implements Widget { private ModifyListener modifyListener; private FocusListener focusListener; private Table variableTable; + private VerifyKeyListener verifyKeyListener; public ExpressionWidget(Composite parent, WidgetSupport support, int style) { @@ -105,9 +107,12 @@ public class ExpressionWidget implements Widget { exp.readData(variable, data); exp.createExpressionFields(parent, data); + if(modifyListener != null) exp.addModifyListener(modifyListener); if(focusListener != null) exp.addFocusListener(focusListener); + if(verifyKeyListener != null) + exp.addVerifyKeyListener(verifyKeyListener); this.expression = exp; this.parent.layout(); validateFields(); @@ -154,6 +159,10 @@ public class ExpressionWidget implements Widget { this.modifyListener = listener; } + public void addVerifyKeyListener(VerifyKeyListener listener) { + this.verifyKeyListener = listener; + } + public void addFocusListener(FocusListener listener) { this.focusListener = listener; } diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/BasicExpression.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/BasicExpression.java index 58d265f9..f9bbaaf5 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/BasicExpression.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/BasicExpression.java @@ -9,6 +9,7 @@ import org.eclipse.jface.layout.GridLayoutFactory; import org.eclipse.jface.text.BadLocationException; import org.eclipse.jface.text.IDocument; import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.VerifyKeyListener; import org.eclipse.swt.events.FocusListener; import org.eclipse.swt.events.KeyListener; import org.eclipse.swt.events.ModifyListener; @@ -162,4 +163,9 @@ public class BasicExpression implements IExpression { public void addFocusListener(FocusListener listener) { this.expression.getSourceViewer().getTextWidget().addFocusListener(listener); } + + @Override + public void addVerifyKeyListener(VerifyKeyListener listener) { + this.expression.getSourceViewer().getTextWidget().addVerifyKeyListener(listener); + } } diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/DelayExpression.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/DelayExpression.java index 8c9eb5de..5a4f6c20 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/DelayExpression.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/DelayExpression.java @@ -3,6 +3,7 @@ package org.simantics.sysdyn.ui.properties.widgets.expressions; import java.util.List; import java.util.Map; +import org.eclipse.swt.custom.VerifyKeyListener; import org.eclipse.swt.events.FocusListener; import org.eclipse.swt.events.KeyListener; import org.eclipse.swt.events.ModifyListener; @@ -71,4 +72,10 @@ public class DelayExpression implements IExpression { } + @Override + public void addVerifyKeyListener(VerifyKeyListener listener) { + // TODO Auto-generated method stub + + } + } diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/EmptyExpression.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/EmptyExpression.java index f2a99fd3..14ab8cdd 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/EmptyExpression.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/EmptyExpression.java @@ -3,6 +3,7 @@ package org.simantics.sysdyn.ui.properties.widgets.expressions; import java.util.List; import java.util.Map; +import org.eclipse.swt.custom.VerifyKeyListener; import org.eclipse.swt.events.FocusListener; import org.eclipse.swt.events.KeyListener; import org.eclipse.swt.events.ModifyListener; @@ -71,4 +72,10 @@ public class EmptyExpression implements IExpression { } + @Override + public void addVerifyKeyListener(VerifyKeyListener listener) { + // TODO Auto-generated method stub + + } + } diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/IExpression.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/IExpression.java index 6c8c152c..cf154780 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/IExpression.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/IExpression.java @@ -3,6 +3,7 @@ package org.simantics.sysdyn.ui.properties.widgets.expressions; import java.util.List; import java.util.Map; +import org.eclipse.swt.custom.VerifyKeyListener; import org.eclipse.swt.events.FocusListener; import org.eclipse.swt.events.KeyListener; import org.eclipse.swt.events.ModifyListener; @@ -28,6 +29,8 @@ public interface IExpression { public void addModifyListener(ModifyListener listener); public void addKeyListener(KeyListener listener); + + public void addVerifyKeyListener(VerifyKeyListener listener); public void addFocusListener(FocusListener listener); } diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/LookupExpression.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/LookupExpression.java index 4bb7fb32..9acc70c7 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/LookupExpression.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/LookupExpression.java @@ -3,6 +3,7 @@ package org.simantics.sysdyn.ui.properties.widgets.expressions; import java.util.List; import java.util.Map; +import org.eclipse.swt.custom.VerifyKeyListener; import org.eclipse.swt.events.FocusListener; import org.eclipse.swt.events.KeyListener; import org.eclipse.swt.events.ModifyListener; @@ -71,4 +72,10 @@ public class LookupExpression implements IExpression { } + @Override + public void addVerifyKeyListener(VerifyKeyListener listener) { + // TODO Auto-generated method stub + + } + } diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/StockExpression.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/StockExpression.java index 5d9ab609..55cbe81d 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/StockExpression.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/StockExpression.java @@ -10,6 +10,7 @@ import org.eclipse.jface.layout.GridLayoutFactory; import org.eclipse.jface.text.BadLocationException; import org.eclipse.jface.text.IDocument; import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.VerifyKeyListener; import org.eclipse.swt.events.FocusListener; import org.eclipse.swt.events.KeyListener; import org.eclipse.swt.events.ModifyListener; @@ -213,5 +214,10 @@ public class StockExpression implements IExpression { public void addFocusListener(FocusListener listener) { this.expression.getSourceViewer().getTextWidget().addFocusListener(listener); } + + @Override + public void addVerifyKeyListener(VerifyKeyListener listener) { + this.expression.getSourceViewer().getTextWidget().addVerifyKeyListener(listener); + } } diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/WithLookupExpression.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/WithLookupExpression.java index a0bcf27a..0fa9e8bc 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/WithLookupExpression.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/WithLookupExpression.java @@ -19,6 +19,7 @@ import org.eclipse.jface.text.BadLocationException; import org.eclipse.jface.text.IDocument; import org.eclipse.swt.SWT; import org.eclipse.swt.awt.SWT_AWT; +import org.eclipse.swt.custom.VerifyKeyListener; import org.eclipse.swt.events.FocusAdapter; import org.eclipse.swt.events.FocusEvent; import org.eclipse.swt.events.FocusListener; @@ -290,6 +291,12 @@ public class WithLookupExpression implements IExpression { this.expression.getSourceViewer().getTextWidget().addKeyListener(listener); this.lookup.getSourceViewer().getTextWidget().addKeyListener(listener); } + + @Override + public void addVerifyKeyListener(VerifyKeyListener listener) { + this.expression.getSourceViewer().getTextWidget().addVerifyKeyListener(listener); + this.lookup.getSourceViewer().getTextWidget().addVerifyKeyListener(listener); + } @Override public void addModifyListener(ModifyListener listener) { -- 2.47.1