1 11 package org.eclipse.jface.text.quickassist; 12 13 import org.eclipse.swt.graphics.Color; 14 15 16 import org.eclipse.jface.text.IDocument; 17 import org.eclipse.jface.text.IInformationControlCreator; 18 import org.eclipse.jface.text.ITextViewer; 19 import org.eclipse.jface.text.contentassist.ContentAssistant; 20 import org.eclipse.jface.text.contentassist.ICompletionListener; 21 import org.eclipse.jface.text.contentassist.ICompletionProposal; 22 import org.eclipse.jface.text.contentassist.IContentAssistProcessor; 23 import org.eclipse.jface.text.contentassist.IContextInformation; 24 import org.eclipse.jface.text.contentassist.IContextInformationValidator; 25 import org.eclipse.jface.text.source.Annotation; 26 import org.eclipse.jface.text.source.ISourceViewer; 27 import org.eclipse.jface.text.source.TextInvocationContext; 28 29 30 35 public class QuickAssistAssistant implements IQuickAssistAssistant { 36 37 38 private static final class QuickAssistAssistantImpl extends ContentAssistant { 39 42 public void possibleCompletionsClosed() { 43 super.possibleCompletionsClosed(); 44 } 45 } 46 47 48 private static final class ContentAssistProcessor implements IContentAssistProcessor { 49 50 private IQuickAssistProcessor fQuickAssistProcessor; 51 52 ContentAssistProcessor(IQuickAssistProcessor processor) { 53 fQuickAssistProcessor= processor; 54 } 55 56 59 public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int offset) { 60 if (!(viewer instanceof ISourceViewer)) 62 return null; 63 64 return fQuickAssistProcessor.computeQuickAssistProposals(new TextInvocationContext((ISourceViewer)viewer, offset, -1)); 65 } 66 67 70 public IContextInformation[] computeContextInformation(ITextViewer viewer, int offset) { 71 return null; 72 } 73 74 77 public char[] getCompletionProposalAutoActivationCharacters() { 78 return null; 79 } 80 81 84 public char[] getContextInformationAutoActivationCharacters() { 85 return null; 86 } 87 88 91 public String getErrorMessage() { 92 return null; 93 } 94 95 98 public IContextInformationValidator getContextInformationValidator() { 99 return null; 100 } 101 102 } 103 104 private QuickAssistAssistantImpl fQuickAssistAssistantImpl; 105 private IQuickAssistProcessor fQuickAssistProcessor; 106 107 public QuickAssistAssistant() { 108 fQuickAssistAssistantImpl= new QuickAssistAssistantImpl(); 109 fQuickAssistAssistantImpl.enableAutoActivation(false); 110 fQuickAssistAssistantImpl.enableAutoInsert(false); 111 } 112 113 116 public String showPossibleQuickAssists() { 117 return fQuickAssistAssistantImpl.showPossibleCompletions(); 118 } 119 120 123 public IQuickAssistProcessor getQuickAssistProcessor() { 124 return fQuickAssistProcessor; 125 } 126 127 130 public void setQuickAssistProcessor(IQuickAssistProcessor processor) { 131 fQuickAssistProcessor= processor; 132 fQuickAssistAssistantImpl.setDocumentPartitioning("__" + getClass().getName() + "_partitioning"); fQuickAssistAssistantImpl.setContentAssistProcessor(new ContentAssistProcessor(processor), IDocument.DEFAULT_CONTENT_TYPE); 134 } 135 136 139 public boolean canFix(Annotation annotation) { 140 return fQuickAssistProcessor != null && fQuickAssistProcessor.canFix(annotation); 141 } 142 143 146 public boolean canAssist(IQuickAssistInvocationContext invocationContext) { 147 return fQuickAssistProcessor != null && fQuickAssistProcessor.canAssist(invocationContext); 148 } 149 150 153 public void install(ISourceViewer sourceViewer) { 154 fQuickAssistAssistantImpl.install(sourceViewer); 155 } 156 157 160 public void setInformationControlCreator(IInformationControlCreator creator) { 161 fQuickAssistAssistantImpl.setInformationControlCreator(creator); 162 } 163 164 167 public void uninstall() { 168 fQuickAssistAssistantImpl.uninstall(); 169 } 170 175 public void setProposalSelectorBackground(Color background) { 176 fQuickAssistAssistantImpl.setProposalSelectorBackground(background); 177 } 178 179 182 public void setProposalSelectorForeground(Color foreground) { 183 fQuickAssistAssistantImpl.setProposalSelectorForeground(foreground); 184 } 185 186 190 protected void possibleCompletionsClosed() { 191 fQuickAssistAssistantImpl.possibleCompletionsClosed(); 192 } 193 194 197 public void addCompletionListener(ICompletionListener listener) { 198 fQuickAssistAssistantImpl.addCompletionListener(listener); 199 } 200 201 204 public void removeCompletionListener(ICompletionListener listener) { 205 fQuickAssistAssistantImpl.removeCompletionListener(listener); 206 } 207 208 211 public void setStatusLineVisible(boolean show) { 212 fQuickAssistAssistantImpl.setStatusLineVisible(show); 213 214 } 215 216 219 public void setStatusMessage(String message) { 220 fQuickAssistAssistantImpl.setStatusMessage(message); 221 } 222 } 223 | Popular Tags |