\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
+ // 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
+ isAnyAssistSessionActive = true;\r
+ 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
+ ((StyledText)event.widget).getParent().forceFocus();\r
+ expressionWidget.save();\r
+ }\r
}\r
}\r
}\r
\r
IAnnotationAccess annotationAccess = new DefaultMarkerAnnotationAccess();\r
\r
+ ExpressionFieldConfiguration expressionFieldConfiguration;\r
+ \r
/**\r
* Create a new expression field\r
* @param parent\r
styles);\r
\r
// Configuration for color management\r
- _sourceViewer.configure(new ExpressionFieldConfiguration(cManager, allowedVariables, allowFunctions));\r
+ expressionFieldConfiguration = new ExpressionFieldConfiguration(cManager, allowedVariables, allowFunctions);\r
+ _sourceViewer.configure(expressionFieldConfiguration);\r
AnnotationPainter painter = new AnnotationPainter(_sourceViewer, annotationAccess);\r
_sourceViewer.addPainter(painter);\r
\r
}\r
\r
});\r
+ \r
}\r
\r
/**\r
public SourceViewer getSourceViewer() {\r
return this._sourceViewer;\r
}\r
+ \r
+ public boolean isAssistSessionActive() {\r
+ return expressionFieldConfiguration.isAssistSessionActive();\r
+ }\r
\r
/**\r
* Sets missing link annotations to given positions\r
import org.eclipse.jface.text.IDocument;\r
import org.eclipse.jface.text.ITextHover;\r
import org.eclipse.jface.text.TextAttribute;\r
+import org.eclipse.jface.text.contentassist.ContentAssistEvent;\r
import org.eclipse.jface.text.contentassist.ContentAssistant;\r
+import org.eclipse.jface.text.contentassist.ICompletionListener;\r
+import org.eclipse.jface.text.contentassist.ICompletionProposal;\r
import org.eclipse.jface.text.contentassist.IContentAssistant;\r
import org.eclipse.jface.text.presentation.IPresentationReconciler;\r
import org.eclipse.jface.text.presentation.PresentationReconciler;\r
\r
public class ExpressionFieldConfiguration extends SourceViewerConfiguration {\r
\r
-\r
+ private final long WAIT_BEFORE_STATUS_CHANGE = 100;\r
+ \r
ColorManager colorManager;\r
Table allowedVariables;\r
- Boolean allowFunctions;\r
+ boolean allowFunctions;\r
+ boolean assistSessionActive; \r
+ CompletionProcessor completionProcessor;\r
\r
public ExpressionFieldConfiguration(ColorManager colorManager, Table allowedVariables, boolean allowFunctions) {\r
super();\r
this.colorManager = colorManager;\r
this.allowedVariables = allowedVariables;\r
this.allowFunctions = allowFunctions;\r
+ this.assistSessionActive = false;\r
+ this.completionProcessor = null;\r
+ }\r
+ \r
+ public boolean isAssistSessionActive() {\r
+ return assistSessionActive;\r
}\r
\r
public String[] getConfiguredContentTypes(ISourceViewer sourceViewer) {\r
@Override\r
public IContentAssistant getContentAssistant(ISourceViewer sourceViewer) {\r
ContentAssistant assistant = new ContentAssistant();\r
- assistant.setContentAssistProcessor(new CompletionProcessor(allowedVariables, allowFunctions), "__dftl_partition_content_type");\r
+ completionProcessor = new CompletionProcessor(allowedVariables, allowFunctions);\r
+ assistant.setContentAssistProcessor(completionProcessor, "__dftl_partition_content_type");\r
assistant.enableAutoActivation(true);\r
assistant.enableAutoInsert(true);\r
assistant.setAutoActivationDelay(0);\r
assistant.setProposalPopupOrientation(IContentAssistant.PROPOSAL_OVERLAY);\r
assistant.setContextInformationPopupOrientation(IContentAssistant.CONTEXT_INFO_ABOVE);\r
+ assistant.addCompletionListener(new CompletionListener());\r
return assistant;\r
}\r
+ \r
+ private class CompletionListener implements ICompletionListener {\r
+\r
+ @Override\r
+ public void assistSessionStarted(ContentAssistEvent event) {\r
+ if (event.processor.equals(completionProcessor)) {\r
+ assistSessionActive = true;\r
+ }\r
+ }\r
\r
+ @Override\r
+ public void assistSessionEnded(ContentAssistEvent event) {\r
+ if (event.processor.equals(completionProcessor)) {\r
+ Thread waitBeforeStateChange = new Thread() {\r
+ public void run() {\r
+ try {\r
+ sleep(WAIT_BEFORE_STATUS_CHANGE);\r
+ assistSessionActive = false;\r
+ } catch (InterruptedException e) {\r
+ assistSessionActive = false;\r
+ }\r
+ }\r
+ };\r
+ waitBeforeStateChange.start();\r
+ }\r
+ }\r
+\r
+ @Override\r
+ public void selectionChanged(ICompletionProposal proposal,\r
+ boolean smartToggle) {\r
+ }\r
+ \r
+ }\r
+ \r
}\r