]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
* Fixing ctrl+space problem in text feed assist (refs #3697)
authormiettinen <miettinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Mon, 15 Oct 2012 10:39:00 +0000 (10:39 +0000)
committermiettinen <miettinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Mon, 15 Oct 2012 10:39:00 +0000 (10:39 +0000)
* When the selection is chosen in text feed assist box with enter, the equation validation is run.

git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@26013 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/expressions/CompletionProcessor.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/ExpressionFieldConfiguration.java

index bf328c09ea8ae3eb593fa7f360d6fc0e127e3482..7e57c1fcf7952160c7db73be422e5808856342e1 100644 (file)
@@ -93,7 +93,7 @@ public class EquationTab extends LabelPropertyTabContributor implements Widget {
        private IWorkbenchSite site;\r
        private Button deleteExpression, newExpression;\r
        private WidgetSupportImpl support;\r
-       private WidgetSupportImpl expressionSupport = new WidgetSupportImpl();\r
+       private final WidgetSupportImpl expressionSupport = new WidgetSupportImpl();\r
 \r
        @Override\r
        public void createControls(Composite body, IWorkbenchSite site, ISessionContext context, WidgetSupport _support) {\r
@@ -112,7 +112,7 @@ public class EquationTab extends LabelPropertyTabContributor implements Widget {
                                                        @Override\r
                                                        public Resource perform(ReadGraph graph)\r
                                                                        throws DatabaseException {\r
-                                                               return (Resource)var.getRepresents(graph);\r
+                                                               return var.getRepresents(graph);\r
                                                        }\r
                                                });\r
                                        input = new StructuredSelection(r);\r
@@ -517,7 +517,7 @@ public class EquationTab extends LabelPropertyTabContributor implements Widget {
                                        Collection<Resource> variables = graph.getObjects(model, l0.ConsistsOf);\r
                                        for(Resource v : variables) {\r
                                                Object unit = graph.getPossibleRelatedValue(v, sr.HasUnit);\r
-                                               if (unit != null && !map.keySet().contains((String) unit)) {\r
+                                               if (unit != null && !map.keySet().contains(unit)) {\r
                                                        map.put((String)unit, (String)unit);\r
 \r
                                                }\r
@@ -614,14 +614,13 @@ public class EquationTab extends LabelPropertyTabContributor implements Widget {
                                expressionWidget.validateFieldsTimed();\r
                        }\r
                });\r
-\r
+               \r
                // Pressing return without shift key triggers saving the expression\r
                expressionWidget.addVerifyKeyListener(new VerifyKeyListener() {\r
 \r
                        @Override\r
                        public void verifyKey(VerifyEvent event) {\r
-                               \r
-                               // Check if some of the expression fields has active completion assistant\r
+                           // Check if some of the expression fields has active completion assistant\r
                                boolean isAnyAssistSessionActive = false;\r
                                for (int i = 0; i < expressionWidget.getExpression().getExpressionFields().size(); ++i) {\r
                                        if (expressionWidget.getExpression().getExpressionFields().get(i).isAssistSessionActive()) {\r
@@ -629,13 +628,16 @@ public class EquationTab extends LabelPropertyTabContributor implements Widget {
                                                break;\r
                                        }\r
                                }\r
-                               if (!isAnyAssistSessionActive) {\r
-                                       if(event.keyCode == SWT.CR || event.keyCode == SWT.KEYPAD_CR) {\r
-                                               if((event.stateMask & SWT.SHIFT) == 0) {\r
-                                                       event.doit = false;\r
+                               if(event.keyCode == SWT.CR || event.keyCode == SWT.KEYPAD_CR) {\r
+                                   if (!isAnyAssistSessionActive) {\r
+                                       if((event.stateMask & SWT.SHIFT) == 0) {\r
+                                           event.doit = false;\r
                                                        ((StyledText)event.widget).getParent().forceFocus();\r
                                                        expressionWidget.save();\r
                                                }\r
+                                   } else {\r
+                                       // When a proposed expression is selected with enter, fields are validated.\r
+                           expressionWidget.validateFieldsTimed();\r
                                        }\r
                                }\r
                        }\r
@@ -645,11 +647,16 @@ public class EquationTab extends LabelPropertyTabContributor implements Widget {
                if(focusLostListener == null) {\r
                        focusLostListener = new org.eclipse.ui.IPartListener2()\r
                        {\r
-                               public void partInputChanged(IWorkbenchPartReference partRef) {}\r
-                               public void partVisible(IWorkbenchPartReference partRef) {}\r
-                               public void partHidden(IWorkbenchPartReference partRef) {}\r
-                               public void partOpened(IWorkbenchPartReference partRef) {}\r
-                               public void partDeactivated(IWorkbenchPartReference partRef)\r
+                               @Override\r
+                public void partInputChanged(IWorkbenchPartReference partRef) {}\r
+                               @Override\r
+                public void partVisible(IWorkbenchPartReference partRef) {}\r
+                               @Override\r
+                public void partHidden(IWorkbenchPartReference partRef) {}\r
+                               @Override\r
+                public void partOpened(IWorkbenchPartReference partRef) {}\r
+                               @Override\r
+                public void partDeactivated(IWorkbenchPartReference partRef)\r
                                {\r
                                        if(partRef.getPart(false) instanceof PropertyPageView) {\r
                                                PropertyPageView ppv = (PropertyPageView)partRef.getPart(false);\r
@@ -662,9 +669,12 @@ public class EquationTab extends LabelPropertyTabContributor implements Widget {
                                                }\r
                                        }\r
                                }\r
-                               public void partClosed(IWorkbenchPartReference partRef) {}\r
-                               public void partBroughtToTop(IWorkbenchPartReference partRef) {}\r
-                               public void partActivated(IWorkbenchPartReference partRef) {}\r
+                               @Override\r
+                public void partClosed(IWorkbenchPartReference partRef) {}\r
+                               @Override\r
+                public void partBroughtToTop(IWorkbenchPartReference partRef) {}\r
+                               @Override\r
+                public void partActivated(IWorkbenchPartReference partRef) {}\r
                        };\r
                        site.getPage().addPartListener(focusLostListener);\r
                }\r
index 533fc146746f074e0cb6c540894918059a8af1cd..34140ed84e3bcdc707383cf4e8a9d61135a9bdeb 100644 (file)
@@ -46,12 +46,12 @@ public class CompletionProcessor implements IContentAssistProcessor {
        private ArrayList<String> functions;\r
        private ArrayList<String> variables = null;\r
        \r
-       private char[] allowedCharacters = {\r
+       private final char[] allowedCharacters = {\r
                'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','å','ä','ö',\r
                'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','Å','Ä','Ö',\r
                '1','2','3','4','5','6','7','8','9','0','.','_','(',')'};\r
            \r
-       private String allowedConnectedCharactersRegExp = "[\\Q({[:;,<=>+-*/^\\E]";\r
+       private final String allowedConnectedCharactersRegExp = "[\\Q({[:;,<=>+-*/^\\E]";\r
        \r
        public CompletionProcessor(Table allowedVariables, boolean allowFunctions){\r
                this.allowedVariables = allowedVariables;\r
@@ -151,13 +151,18 @@ public class CompletionProcessor implements IContentAssistProcessor {
                }\r
                String token = tokens[tokens.length - 1];\r
                \r
-               // Split the last token on '+', '-', etc. characters \r
-               String tokensOfLastToken[] = token.split(allowedConnectedCharactersRegExp);\r
+               // If a '+', '-', etc. character is in the end, return all. \r
+           if (allowedConnectedCharactersRegExp.indexOf(token.charAt(token.length() - 1)) != -1) {\r
+               return collectProposals("", offset);\r
+           }\r
+           \r
+           // Split the last token on '+', '-', etc. characters\r
+        String tokensOfLastToken[] = token.split(allowedConnectedCharactersRegExp);\r
                if (tokensOfLastToken.length == 0) {\r
                        return collectProposals("", offset);\r
                }\r
                token = tokensOfLastToken[tokensOfLastToken.length - 1];\r
-//             System.out.println(token + "\noffset = " + offset);\r
+               //System.out.println(token + "\noffset = " + offset);\r
 \r
                return collectProposals(token, offset);\r
        }\r
index 5521aa2d3348db328bbf38c2f73b4ed8c2fe2417..ce741b548afab54a3e1dd3f72ab7dea989cf3ac6 100644 (file)
@@ -62,13 +62,15 @@ public class ExpressionFieldConfiguration extends SourceViewerConfiguration {
                return assistSessionActive;\r
        }\r
        \r
-       public String[] getConfiguredContentTypes(ISourceViewer sourceViewer) {\r
+       @Override\r
+    public String[] getConfiguredContentTypes(ISourceViewer sourceViewer) {\r
                return new String[] {\r
                                IDocument.DEFAULT_CONTENT_TYPE\r
                };\r
        }\r
 \r
-       public IPresentationReconciler getPresentationReconciler(ISourceViewer sourceViewer) {\r
+       @Override\r
+    public IPresentationReconciler getPresentationReconciler(ISourceViewer sourceViewer) {\r
                PresentationReconciler reconciler = new PresentationReconciler();\r
 \r
                DefaultDamagerRepairer dr = new DefaultDamagerRepairer(getSclTokenScanner());\r
@@ -158,7 +160,8 @@ public class ExpressionFieldConfiguration extends SourceViewerConfiguration {
                public void assistSessionEnded(ContentAssistEvent event) {\r
                        if (event.processor.equals(completionProcessor)) {\r
                                Thread waitBeforeStateChange = new Thread() {\r
-                                       public void run() {\r
+                                       @Override\r
+                    public void run() {\r
                                                try {\r
                                                        sleep(WAIT_BEFORE_STATUS_CHANGE);\r
                                                        assistSessionActive = false;\r