public void adapt(StyledText styledText) { this.styledText = styledText; // perform initialization of fake resource context updateFakeResourceContext(); // connect Xtext document to fake resource initXtextDocument(getFakeResourceContext()); // connect xtext document to xtext source viewer this.sourceviewer = createXtextSourceViewer(); this.decorationSupport = createSourceViewerDecorationSupport(); configureSourceViewerDecorationSupport(getDecorationSupport()); // install semantic highlighting support installHighlightingHelper(); this.validationJob = createValidationJob(); getXtextDocument().setValidationJob(getValidationJob()); styledText.setData(StyledTextXtextAdapter.class.getCanonicalName(), this); final IContentAssistant contentAssistant = getXtextSourceviewer().getContentAssistant(); final CompletionProposalAdapter completionProposalAdapter = new CompletionProposalAdapter(styledText, contentAssistant, KeyStroke.getInstance(SWT.CTRL, SWT.SPACE), null); if ((styledText.getStyle() & SWT.SINGLE) != 0) { // The regular key down event is too late (after popup is closed). // when using the StyledText.VerifyKey event (3005), we get the // event early enough! styledText.addListener(3005, new Listener() { public void handleEvent(Event event) { if (event.character == SWT.CR && !completionProposalAdapter.isProposalPopupOpen()) { Event selectionEvent = new Event(); selectionEvent.type = SWT.DefaultSelection; selectionEvent.widget = event.widget; for (Listener l : event.widget.getListeners(SWT.DefaultSelection)) { l.handleEvent(selectionEvent); } } } }); } // Register focus tracker for evaluating the active focus control in // core expression IFocusService service = (IFocusService) PlatformUI.getWorkbench().getService(IFocusService.class); service.addFocusTracker(styledText, StyledText.class.getCanonicalName()); // add JDT Style code completion hint decoration this.decoration = createContentAssistDecoration(styledText); initSelectionProvider(); }
public void adapt(StyledText styledText) { this.styledText = styledText; // perform initialization of fake resource context updateFakeResourceContext(); // connect Xtext document to fake resource initXtextDocument(fakeResourceContext); // connect xtext document to xtext source viewer createXtextSourceViewer(); // install semantic highlighting support installHighlightingHelper(); validationJob = createValidationJob(); document.setValidationJob(validationJob); styledText.setData(StyledTextXtextAdapter.class.getCanonicalName(), this); final IContentAssistant contentAssistant = sourceviewer.getContentAssistant(); final CompletionProposalAdapter completionProposalAdapter = new CompletionProposalAdapter(styledText, contentAssistant, KeyStroke.getInstance(SWT.CTRL, ' '), null); if ((styledText.getStyle() & SWT.SINGLE) != 0) { // The regular key down event is too late (after popup is closed). // when using the StyledText.VerifyKey event (3005), we get the // event early enough! styledText.addListener(3005, new Listener() { public void handleEvent(Event event) { if (event.character == SWT.CR && !completionProposalAdapter.isProposalPopupOpen()) { Event selectionEvent = new Event(); selectionEvent.type = SWT.DefaultSelection; selectionEvent.widget = event.widget; for (Listener l : event.widget.getListeners(SWT.DefaultSelection)) { l.handleEvent(selectionEvent); } } } }); } // Register focus tracker for evaluating the active focus control in // core expression IFocusService service = (IFocusService) PlatformUI.getWorkbench().getService(IFocusService.class); service.addFocusTracker(styledText, StyledText.class.getCanonicalName()); // add JDT Style code completion hint decoration createContentAssistDecoration(styledText); // FIX for Community Bug #3200: // Overriding the SelectionProvider causes the problem, because looking at // XtextStyledTextSelectionProvider#getSelection() the following set of instructions: // ... // if (styledText.isDisposed()) // return StructuredSelection.EMPTY; // ... // will end-up losing the selection after closing our Expression Editor. //initSelectionProvider(); }