1 11 package org.eclipse.jface.text.contentassist; 12 13 import org.eclipse.swt.custom.StyledText; 14 import org.eclipse.swt.custom.VerifyKeyListener; 15 import org.eclipse.swt.events.KeyListener; 16 import org.eclipse.swt.events.SelectionListener; 17 import org.eclipse.swt.graphics.Point; 18 import org.eclipse.swt.widgets.Control; 19 20 import org.eclipse.core.runtime.Assert; 21 22 import org.eclipse.jface.contentassist.*; 23 24 import org.eclipse.jface.text.IDocument; 25 import org.eclipse.jface.text.IEventConsumer; 26 import org.eclipse.jface.text.ITextViewer; 27 import org.eclipse.jface.text.ITextViewerExtension; 28 import org.eclipse.jface.text.contentassist.ContextInformationPopup.ContextFrame; 29 30 31 37 final class ContentAssistSubjectControlAdapter implements IContentAssistSubjectControl { 38 39 42 private ITextViewer fViewer; 43 44 47 private IContentAssistSubjectControl fContentAssistSubjectControl; 48 49 50 55 ContentAssistSubjectControlAdapter(IContentAssistSubjectControl contentAssistSubjectControl) { 56 Assert.isNotNull(contentAssistSubjectControl); 57 fContentAssistSubjectControl= contentAssistSubjectControl; 58 } 59 60 65 public ContentAssistSubjectControlAdapter(ITextViewer viewer) { 66 Assert.isNotNull(viewer); 67 fViewer= viewer; 68 } 69 70 73 public int getLineHeight() { 74 if (fContentAssistSubjectControl != null) 75 return fContentAssistSubjectControl.getLineHeight(); 76 77 return fViewer.getTextWidget().getLineHeight(getCaretOffset()); 78 } 79 80 83 public Control getControl() { 84 if (fContentAssistSubjectControl != null) 85 return fContentAssistSubjectControl.getControl(); 86 return fViewer.getTextWidget(); 87 } 88 89 92 public Point getLocationAtOffset(int offset) { 93 if (fContentAssistSubjectControl != null) 94 return fContentAssistSubjectControl.getLocationAtOffset(offset); 95 return fViewer.getTextWidget().getLocationAtOffset(offset); 96 } 97 98 101 public Point getWidgetSelectionRange() { 102 if (fContentAssistSubjectControl != null) 103 return fContentAssistSubjectControl.getWidgetSelectionRange(); 104 return fViewer.getTextWidget().getSelectionRange(); 105 } 106 107 110 public Point getSelectedRange() { 111 if (fContentAssistSubjectControl != null) 112 return fContentAssistSubjectControl.getSelectedRange(); 113 return fViewer.getSelectedRange(); 114 } 115 116 119 public int getCaretOffset() { 120 if (fContentAssistSubjectControl != null) 121 return fContentAssistSubjectControl.getCaretOffset(); 122 return fViewer.getTextWidget().getCaretOffset(); 123 } 124 125 128 public String getLineDelimiter() { 129 if (fContentAssistSubjectControl != null) 130 return fContentAssistSubjectControl.getLineDelimiter(); 131 return fViewer.getTextWidget().getLineDelimiter(); 132 } 133 134 137 public void addKeyListener(KeyListener keyListener) { 138 if (fContentAssistSubjectControl != null) 139 fContentAssistSubjectControl.addKeyListener(keyListener); 140 else 141 fViewer.getTextWidget().addKeyListener(keyListener); 142 } 143 144 147 public void removeKeyListener(KeyListener keyListener) { 148 if (fContentAssistSubjectControl != null) 149 fContentAssistSubjectControl.removeKeyListener(keyListener); 150 else 151 fViewer.getTextWidget().removeKeyListener(keyListener); 152 } 153 154 157 public IDocument getDocument() { 158 if (fContentAssistSubjectControl != null) 159 return fContentAssistSubjectControl.getDocument(); 160 return fViewer.getDocument(); 161 } 162 163 166 public boolean prependVerifyKeyListener(VerifyKeyListener verifyKeyListener) { 167 if (fContentAssistSubjectControl != null) { 168 return fContentAssistSubjectControl.prependVerifyKeyListener(verifyKeyListener); 169 } else if (fViewer instanceof ITextViewerExtension) { 170 ITextViewerExtension e= (ITextViewerExtension) fViewer; 171 e.prependVerifyKeyListener(verifyKeyListener); 172 return true; 173 } else { 174 175 StyledText textWidget= fViewer.getTextWidget(); 176 if (Helper.okToUse(textWidget)) { 177 textWidget.addVerifyKeyListener(verifyKeyListener); 178 return true; 179 } 180 } 181 return false; 182 } 183 184 187 public boolean appendVerifyKeyListener(VerifyKeyListener verifyKeyListener) { 188 if (fContentAssistSubjectControl != null) 189 return fContentAssistSubjectControl.appendVerifyKeyListener(verifyKeyListener); 190 else if (fViewer instanceof ITextViewerExtension) { 191 ITextViewerExtension extension= (ITextViewerExtension)fViewer; 192 extension.appendVerifyKeyListener(verifyKeyListener); 193 return true; 194 } else { 195 StyledText textWidget= fViewer.getTextWidget(); 196 if (Helper.okToUse(textWidget)) { 197 textWidget.addVerifyKeyListener(verifyKeyListener); 198 return true; 199 } 200 } 201 return false; 202 } 203 204 207 public void removeVerifyKeyListener(VerifyKeyListener verifyKeyListener) { 208 if (fContentAssistSubjectControl != null) { 209 fContentAssistSubjectControl.removeVerifyKeyListener(verifyKeyListener); 210 } else if (fViewer instanceof ITextViewerExtension) { 211 ITextViewerExtension extension= (ITextViewerExtension) fViewer; 212 extension.removeVerifyKeyListener(verifyKeyListener); 213 } else { 214 StyledText textWidget= fViewer.getTextWidget(); 215 if (Helper.okToUse(textWidget)) 216 textWidget.removeVerifyKeyListener(verifyKeyListener); 217 } 218 } 219 220 223 public void setEventConsumer(IEventConsumer eventConsumer) { 224 if (fContentAssistSubjectControl != null) 225 fContentAssistSubjectControl.setEventConsumer(eventConsumer); 226 else 227 fViewer.setEventConsumer(eventConsumer); 228 } 229 230 233 public void setSelectedRange(int i, int j) { 234 if (fContentAssistSubjectControl != null) 235 fContentAssistSubjectControl.setSelectedRange(i, j); 236 else 237 fViewer.setSelectedRange(i, j); 238 } 239 240 243 public void revealRange(int i, int j) { 244 if (fContentAssistSubjectControl != null) 245 fContentAssistSubjectControl.revealRange(i, j); 246 else 247 fViewer.revealRange(i, j); 248 } 249 250 253 public boolean supportsVerifyKeyListener() { 254 if (fContentAssistSubjectControl != null) 255 return fContentAssistSubjectControl.supportsVerifyKeyListener(); 256 return true; 257 } 258 268 public char[] getCompletionProposalAutoActivationCharacters(ContentAssistant contentAssistant, int offset) { 269 if (fContentAssistSubjectControl != null) 270 return contentAssistant.getCompletionProposalAutoActivationCharacters(fContentAssistSubjectControl, offset); 271 return contentAssistant.getCompletionProposalAutoActivationCharacters(fViewer, offset); 272 } 273 274 285 char[] getContextInformationAutoActivationCharacters(ContentAssistant contentAssistant, int offset) { 286 if (fContentAssistSubjectControl != null) 287 return contentAssistant.getContextInformationAutoActivationCharacters(fContentAssistSubjectControl, offset); 288 return contentAssistant.getContextInformationAutoActivationCharacters(fViewer, offset); 289 } 290 291 298 CompletionProposalPopup createCompletionProposalPopup(ContentAssistant contentAssistant, AdditionalInfoController controller) { 299 if (fContentAssistSubjectControl != null) 300 return new CompletionProposalPopup(contentAssistant, fContentAssistSubjectControl, controller); 301 return new CompletionProposalPopup(contentAssistant, fViewer, controller); 302 303 } 304 305 311 ContextInformationPopup createContextInfoPopup(ContentAssistant contentAssistant) { 312 if (fContentAssistSubjectControl != null) 313 return new ContextInformationPopup(contentAssistant, fContentAssistSubjectControl); 314 return new ContextInformationPopup(contentAssistant, fViewer); 315 316 } 317 318 328 public IContextInformationValidator getContextInformationValidator(ContentAssistant contentAssistant, int offset) { 329 if (fContentAssistSubjectControl != null) 330 return contentAssistant.getContextInformationValidator(fContentAssistSubjectControl, offset); 331 return contentAssistant.getContextInformationValidator(fViewer, offset); 332 } 333 334 343 public IContextInformationPresenter getContextInformationPresenter(ContentAssistant contentAssistant, int offset) { 344 if (fContentAssistSubjectControl != null) 345 return contentAssistant.getContextInformationPresenter(fContentAssistSubjectControl, offset); 346 return contentAssistant.getContextInformationPresenter(fViewer, offset); 347 } 348 349 354 public void installValidator(ContextFrame frame) { 355 if (fContentAssistSubjectControl != null) { 356 if (frame.fValidator instanceof ISubjectControlContextInformationValidator) 357 ((ISubjectControlContextInformationValidator)frame.fValidator).install(frame.fInformation, fContentAssistSubjectControl, frame.fOffset); 358 } else 359 frame.fValidator.install(frame.fInformation, fViewer, frame.fOffset); 360 } 361 362 367 public void installContextInformationPresenter(ContextFrame frame) { 368 if (fContentAssistSubjectControl != null) { 369 if (frame.fPresenter instanceof ISubjectControlContextInformationPresenter) 370 ((ISubjectControlContextInformationPresenter)frame.fValidator).install(frame.fInformation, fContentAssistSubjectControl, frame.fBeginOffset); 371 } else 372 frame.fPresenter.install(frame.fInformation, fViewer, frame.fBeginOffset); 373 } 374 375 385 public IContextInformation[] computeContextInformation(ContentAssistant contentAssistant, int offset) { 386 if (fContentAssistSubjectControl != null) 387 return contentAssistant.computeContextInformation(fContentAssistSubjectControl, offset); 388 return contentAssistant.computeContextInformation(fViewer, offset); 389 } 390 391 394 public boolean addSelectionListener(SelectionListener selectionListener) { 395 if (fContentAssistSubjectControl != null) 396 return fContentAssistSubjectControl.addSelectionListener(selectionListener); 397 fViewer.getTextWidget().addSelectionListener(selectionListener); 398 return true; 399 } 400 401 404 public void removeSelectionListener(SelectionListener selectionListener) { 405 if (fContentAssistSubjectControl != null) 406 fContentAssistSubjectControl.removeSelectionListener(selectionListener); 407 else 408 fViewer.getTextWidget().removeSelectionListener(selectionListener); 409 } 410 } 411 | Popular Tags |