1 package net.sourceforge.phpdt.internal.ui.text.template;
3 import net.sourceforge.phpdt.internal.ui.PHPUiImages;
4 import net.sourceforge.phpdt.internal.ui.text.link.LinkedPositionManager;
5 import net.sourceforge.phpdt.internal.ui.text.link.LinkedPositionUI;
6 import net.sourceforge.phpeclipse.ui.WebUI;
7 //import net.sourceforge.phpeclipse.PHPeclipsePlugin;
9 import org.eclipse.jface.text.BadLocationException;
10 import org.eclipse.jface.text.IDocument;
11 import org.eclipse.jface.text.IRegion;
12 import org.eclipse.jface.text.ITextViewer;
13 import org.eclipse.jface.text.contentassist.IContextInformation;
14 import org.eclipse.swt.graphics.Image;
17 * A PHP local identifier proposal.
19 public class LocalVariableProposal extends AbstractProposal {
21 private final String fIdentifierName;
23 private final IRegion fRegion;
25 private final int fRelevance;
28 * Creates a template proposal with a template and its context.
33 * the icon of the proposal.
35 public LocalVariableProposal(String identifierName, IRegion region,
37 this(identifierName, region, viewer, 99);
40 public LocalVariableProposal(String identifierName, IRegion region,
41 ITextViewer viewer, int relevance) {
43 fIdentifierName = identifierName;
45 fRelevance = relevance;
49 * @see ICompletionProposal#apply(IDocument)
51 public void apply(IDocument document) {
53 // if (fTemplateBuffer == null)
54 // fTemplateBuffer= fContext.evaluate(fTemplate);
56 int start = fRegion.getOffset();
57 int end = fRegion.getOffset() + fRegion.getLength();
59 document.replace(start, end - start, fIdentifierName);
61 // translate positions
62 LinkedPositionManager manager = new LinkedPositionManager(document);
64 LinkedPositionUI editor = new LinkedPositionUI(fViewer, manager);
65 editor.setFinalCaretOffset(fIdentifierName.length() + start);
68 fSelectedRegion = editor.getSelectedRegion();
70 } catch (BadLocationException e) {
75 // catch (CoreException e) {
76 // handleException(e);
83 * @see java.lang.Object#equals(java.lang.Object)
85 public boolean equals(Object obj) {
86 if (obj instanceof LocalVariableProposal) {
87 return fIdentifierName
88 .equals(((LocalVariableProposal) obj).fIdentifierName);
94 * @see ICompletionProposal#getAdditionalProposalInfo()
96 public String getAdditionalProposalInfo() {
97 StringBuffer hoverInfoBuffer = new StringBuffer();
98 if (fRelevance > 95) {
99 hoverInfoBuffer.append("function source variable -");
101 hoverInfoBuffer.append("editor source variable -");
103 hoverInfoBuffer.append(fIdentifierName);
104 return hoverInfoBuffer.toString();
108 * @see ICompletionProposal#getContextInformation()
110 public IContextInformation getContextInformation() {
115 * @see ICompletionProposal#getDisplayString()
117 public String getDisplayString() {
118 return fIdentifierName; // $NON-NLS-1$ //$NON-NLS-1$
122 * @see ICompletionProposal#getImage()
124 public Image getImage() {
125 return PHPUiImages.get(PHPUiImages.IMG_VAR);
129 * @see IJavaCompletionProposal#getRelevance()
131 public int getRelevance() {
138 * @see java.lang.Object#hashCode()
140 public int hashCode() {
141 return fIdentifierName.hashCode();