From 93974267c16534c5a6f8f7aa9852038569cee9d6 Mon Sep 17 00:00:00 2001 From: miettinen Date: Mon, 15 Oct 2012 10:39:00 +0000 Subject: [PATCH] * Fixing ctrl+space problem in text feed assist (refs #3697) * 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 --- .../sysdyn/ui/properties/EquationTab.java | 46 +++++++++++-------- .../expressions/CompletionProcessor.java | 15 ++++-- .../ExpressionFieldConfiguration.java | 9 ++-- 3 files changed, 44 insertions(+), 26 deletions(-) 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 bf328c09..7e57c1fc 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 @@ -93,7 +93,7 @@ public class EquationTab extends LabelPropertyTabContributor implements Widget { private IWorkbenchSite site; private Button deleteExpression, newExpression; private WidgetSupportImpl support; - private WidgetSupportImpl expressionSupport = new WidgetSupportImpl(); + private final WidgetSupportImpl expressionSupport = new WidgetSupportImpl(); @Override public void createControls(Composite body, IWorkbenchSite site, ISessionContext context, WidgetSupport _support) { @@ -112,7 +112,7 @@ public class EquationTab extends LabelPropertyTabContributor implements Widget { @Override public Resource perform(ReadGraph graph) throws DatabaseException { - return (Resource)var.getRepresents(graph); + return var.getRepresents(graph); } }); input = new StructuredSelection(r); @@ -517,7 +517,7 @@ public class EquationTab extends LabelPropertyTabContributor implements Widget { Collection variables = graph.getObjects(model, l0.ConsistsOf); for(Resource v : variables) { Object unit = graph.getPossibleRelatedValue(v, sr.HasUnit); - if (unit != null && !map.keySet().contains((String) unit)) { + if (unit != null && !map.keySet().contains(unit)) { map.put((String)unit, (String)unit); } @@ -614,14 +614,13 @@ public class EquationTab extends LabelPropertyTabContributor implements Widget { expressionWidget.validateFieldsTimed(); } }); - + // Pressing return without shift key triggers saving the expression expressionWidget.addVerifyKeyListener(new VerifyKeyListener() { @Override public void verifyKey(VerifyEvent event) { - - // Check if some of the expression fields has active completion assistant + // Check if some of the expression fields has active completion assistant boolean isAnyAssistSessionActive = false; for (int i = 0; i < expressionWidget.getExpression().getExpressionFields().size(); ++i) { if (expressionWidget.getExpression().getExpressionFields().get(i).isAssistSessionActive()) { @@ -629,13 +628,16 @@ public class EquationTab extends LabelPropertyTabContributor implements Widget { break; } } - if (!isAnyAssistSessionActive) { - if(event.keyCode == SWT.CR || event.keyCode == SWT.KEYPAD_CR) { - if((event.stateMask & SWT.SHIFT) == 0) { - event.doit = false; + if(event.keyCode == SWT.CR || event.keyCode == SWT.KEYPAD_CR) { + if (!isAnyAssistSessionActive) { + if((event.stateMask & SWT.SHIFT) == 0) { + event.doit = false; ((StyledText)event.widget).getParent().forceFocus(); expressionWidget.save(); } + } else { + // When a proposed expression is selected with enter, fields are validated. + expressionWidget.validateFieldsTimed(); } } } @@ -645,11 +647,16 @@ public class EquationTab extends LabelPropertyTabContributor implements Widget { if(focusLostListener == null) { focusLostListener = new org.eclipse.ui.IPartListener2() { - public void partInputChanged(IWorkbenchPartReference partRef) {} - public void partVisible(IWorkbenchPartReference partRef) {} - public void partHidden(IWorkbenchPartReference partRef) {} - public void partOpened(IWorkbenchPartReference partRef) {} - public void partDeactivated(IWorkbenchPartReference partRef) + @Override + public void partInputChanged(IWorkbenchPartReference partRef) {} + @Override + public void partVisible(IWorkbenchPartReference partRef) {} + @Override + public void partHidden(IWorkbenchPartReference partRef) {} + @Override + public void partOpened(IWorkbenchPartReference partRef) {} + @Override + public void partDeactivated(IWorkbenchPartReference partRef) { if(partRef.getPart(false) instanceof PropertyPageView) { PropertyPageView ppv = (PropertyPageView)partRef.getPart(false); @@ -662,9 +669,12 @@ public class EquationTab extends LabelPropertyTabContributor implements Widget { } } } - public void partClosed(IWorkbenchPartReference partRef) {} - public void partBroughtToTop(IWorkbenchPartReference partRef) {} - public void partActivated(IWorkbenchPartReference partRef) {} + @Override + public void partClosed(IWorkbenchPartReference partRef) {} + @Override + public void partBroughtToTop(IWorkbenchPartReference partRef) {} + @Override + public void partActivated(IWorkbenchPartReference partRef) {} }; site.getPage().addPartListener(focusLostListener); } diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/CompletionProcessor.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/CompletionProcessor.java index 533fc146..34140ed8 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/CompletionProcessor.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/CompletionProcessor.java @@ -46,12 +46,12 @@ public class CompletionProcessor implements IContentAssistProcessor { private ArrayList functions; private ArrayList variables = null; - private char[] allowedCharacters = { + private final char[] allowedCharacters = { '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','å','ä','ö', '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','Å','Ä','Ö', '1','2','3','4','5','6','7','8','9','0','.','_','(',')'}; - private String allowedConnectedCharactersRegExp = "[\\Q({[:;,<=>+-*/^\\E]"; + private final String allowedConnectedCharactersRegExp = "[\\Q({[:;,<=>+-*/^\\E]"; public CompletionProcessor(Table allowedVariables, boolean allowFunctions){ this.allowedVariables = allowedVariables; @@ -151,13 +151,18 @@ public class CompletionProcessor implements IContentAssistProcessor { } String token = tokens[tokens.length - 1]; - // Split the last token on '+', '-', etc. characters - String tokensOfLastToken[] = token.split(allowedConnectedCharactersRegExp); + // If a '+', '-', etc. character is in the end, return all. + if (allowedConnectedCharactersRegExp.indexOf(token.charAt(token.length() - 1)) != -1) { + return collectProposals("", offset); + } + + // Split the last token on '+', '-', etc. characters + String tokensOfLastToken[] = token.split(allowedConnectedCharactersRegExp); if (tokensOfLastToken.length == 0) { return collectProposals("", offset); } token = tokensOfLastToken[tokensOfLastToken.length - 1]; -// System.out.println(token + "\noffset = " + offset); + //System.out.println(token + "\noffset = " + offset); return collectProposals(token, offset); } diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/ExpressionFieldConfiguration.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/ExpressionFieldConfiguration.java index 5521aa2d..ce741b54 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/ExpressionFieldConfiguration.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/ExpressionFieldConfiguration.java @@ -62,13 +62,15 @@ public class ExpressionFieldConfiguration extends SourceViewerConfiguration { return assistSessionActive; } - public String[] getConfiguredContentTypes(ISourceViewer sourceViewer) { + @Override + public String[] getConfiguredContentTypes(ISourceViewer sourceViewer) { return new String[] { IDocument.DEFAULT_CONTENT_TYPE }; } - public IPresentationReconciler getPresentationReconciler(ISourceViewer sourceViewer) { + @Override + public IPresentationReconciler getPresentationReconciler(ISourceViewer sourceViewer) { PresentationReconciler reconciler = new PresentationReconciler(); DefaultDamagerRepairer dr = new DefaultDamagerRepairer(getSclTokenScanner()); @@ -158,7 +160,8 @@ public class ExpressionFieldConfiguration extends SourceViewerConfiguration { public void assistSessionEnded(ContentAssistEvent event) { if (event.processor.equals(completionProcessor)) { Thread waitBeforeStateChange = new Thread() { - public void run() { + @Override + public void run() { try { sleep(WAIT_BEFORE_STATUS_CHANGE); assistSessionActive = false; -- 2.47.1