public void install(ITextViewer textViewer) { if (!isInstalled) { this.textViewer = textViewer; textInputListener = new TextInputListener(); textViewer.addTextInputListener(textInputListener); handleInputDocumentChanged(null, textViewer.getDocument()); if (textViewer instanceof ISourceViewerExtension4) { ContentAssistantFacade facade = ((ISourceViewerExtension4) textViewer).getContentAssistantFacade(); if (facade == null) { shouldInstallCompletionListener = true; } else { facade.addCompletionListener(documentListener); } if (strategy instanceof ISourceViewerAware) { ((ISourceViewerAware) strategy).setSourceViewer((ISourceViewer) textViewer); } } isInstalled = true; } }
protected void handleInputDocumentChanged(IDocument oldInput, IDocument newInput) { if (shouldInstallCompletionListener) { ContentAssistantFacade facade = ((ISourceViewerExtension4) textViewer).getContentAssistantFacade(); if (facade != null) { facade.addCompletionListener(documentListener); } shouldInstallCompletionListener = false; } if (oldInput instanceof IXtextDocument) { ((IXtextDocument) oldInput).removeXtextDocumentContentObserver(documentListener); } if (newInput instanceof IXtextDocument) { ((IXtextDocument) newInput).addXtextDocumentContentObserver(documentListener); final IXtextDocument document = XtextDocumentUtil.get(textViewer); strategy.setDocument(document); if (!initalProcessDone && strategy instanceof IReconcilingStrategyExtension) { initalProcessDone = true; IReconcilingStrategyExtension reconcilingStrategyExtension = (IReconcilingStrategyExtension) strategy; reconcilingStrategyExtension.initialReconcile(); } } if (oldInput != null && newInput != null) { handleDocumentChanged(new InputChangedDocumentEvent(oldInput, newInput)); } }
/** * Obtains the content assistant facade of an editor. * @param editor the editor * @return the content assistant facade of the editor */ public static ContentAssistantFacade getContentAssistantFacade(IEditorPart editor) { ISourceViewer viewer = getSourceViewer(editor); if (viewer != null && viewer instanceof SourceViewer) { return ((SourceViewer)viewer).getContentAssistantFacade(); } return null; }
public void uninstall() { if (isInstalled) { textViewer.removeTextInputListener(textInputListener); isInstalled = false; if (documentListener != null) { if (textViewer instanceof ISourceViewerExtension4) { ContentAssistantFacade facade = ((ISourceViewerExtension4) textViewer).getContentAssistantFacade(); facade.removeCompletionListener(documentListener); } if (textViewer.getDocument() instanceof IXtextDocument) { ((IXtextDocument) textViewer.getDocument()).removeXtextDocumentContentObserver(documentListener); } } } }
public final ContentAssistantFacade getContentAssistantFacade() { return viewer.getContentAssistantFacade(); }