1 11 package org.eclipse.jface.text.contentassist; 12 13 import org.eclipse.swt.graphics.Image; 14 import org.eclipse.swt.graphics.Point; 15 16 import org.eclipse.core.runtime.Assert; 17 18 import org.eclipse.jface.text.BadLocationException; 19 import org.eclipse.jface.text.IDocument; 20 21 22 25 public final class CompletionProposal implements ICompletionProposal { 26 27 28 private String fDisplayString; 29 30 private String fReplacementString; 31 32 private int fReplacementOffset; 33 34 private int fReplacementLength; 35 36 private int fCursorPosition; 37 38 private Image fImage; 39 40 private IContextInformation fContextInformation; 41 42 private String fAdditionalProposalInfo; 43 44 53 public CompletionProposal(String replacementString, int replacementOffset, int replacementLength, int cursorPosition) { 54 this(replacementString, replacementOffset, replacementLength, cursorPosition, null, null, null, null); 55 } 56 57 69 public CompletionProposal(String replacementString, int replacementOffset, int replacementLength, int cursorPosition, Image image, String displayString, IContextInformation contextInformation, String additionalProposalInfo) { 70 Assert.isNotNull(replacementString); 71 Assert.isTrue(replacementOffset >= 0); 72 Assert.isTrue(replacementLength >= 0); 73 Assert.isTrue(cursorPosition >= 0); 74 75 fReplacementString= replacementString; 76 fReplacementOffset= replacementOffset; 77 fReplacementLength= replacementLength; 78 fCursorPosition= cursorPosition; 79 fImage= image; 80 fDisplayString= displayString; 81 fContextInformation= contextInformation; 82 fAdditionalProposalInfo= additionalProposalInfo; 83 } 84 85 88 public void apply(IDocument document) { 89 try { 90 document.replace(fReplacementOffset, fReplacementLength, fReplacementString); 91 } catch (BadLocationException x) { 92 } 94 } 95 96 99 public Point getSelection(IDocument document) { 100 return new Point(fReplacementOffset + fCursorPosition, 0); 101 } 102 103 106 public IContextInformation getContextInformation() { 107 return fContextInformation; 108 } 109 110 113 public Image getImage() { 114 return fImage; 115 } 116 117 120 public String getDisplayString() { 121 if (fDisplayString != null) 122 return fDisplayString; 123 return fReplacementString; 124 } 125 126 129 public String getAdditionalProposalInfo() { 130 return fAdditionalProposalInfo; 131 } 132 } 133 | Popular Tags |