1 package net.sourceforge.phpdt.internal.ui.text.template;
3 import net.sourceforge.phpdt.internal.corext.template.TemplateMessages;
4 import net.sourceforge.phpdt.internal.corext.template.php.JavaContext;
5 import net.sourceforge.phpdt.internal.ui.text.link.LinkedPositionManager;
6 import net.sourceforge.phpdt.internal.ui.text.link.LinkedPositionUI;
7 import net.sourceforge.phpeclipse.ui.WebUI;
8 //import net.sourceforge.phpeclipse.PHPeclipsePlugin;
10 import org.eclipse.jface.text.BadLocationException;
11 import org.eclipse.jface.text.IDocument;
12 import org.eclipse.jface.text.IRegion;
13 import org.eclipse.jface.text.ITextViewer;
14 import org.eclipse.jface.text.templates.TemplateContext;
15 import org.eclipse.swt.graphics.Image;
18 * A PHP identifier proposal.
20 public class IdentifierProposal extends AbstractProposal {
21 private final TemplateContext fContext;
23 private final Image fImage_fun;
25 private final Image fImage_var;
27 private final IRegion fRegion;
29 private final String fTemplate;
31 public IdentifierProposal(String template, TemplateContext context,
32 IRegion region, ITextViewer viewer, Image image_fun, Image image_var) {
37 fImage_fun = image_fun;
38 fImage_var = image_var;
42 public void apply(IDocument document) {
44 int start = fRegion.getOffset();
45 int end = fRegion.getOffset() + fRegion.getLength();
46 document.replace(start, end - start, fTemplate);
47 // translate positions
48 LinkedPositionManager manager = new LinkedPositionManager(document);
50 LinkedPositionUI editor = new LinkedPositionUI(fViewer, manager);
51 editor.setFinalCaretOffset(fTemplate.length() + start);
53 fSelectedRegion = editor.getSelectedRegion();
54 } catch (BadLocationException e) {
60 public String getAdditionalProposalInfo() {
61 return textToHTML(fTemplate);
64 public String getDisplayString() {
66 + TemplateMessages.getString("TemplateProposal.delimiter")
67 + fTemplate; // $NON-NLS-1$
70 public Image getImage() {
71 if (fTemplate.charAt(0) == '$') {
77 public int getRelevance() {
78 if (fContext instanceof JavaContext) {
79 JavaContext context = (JavaContext) fContext;
80 switch (context.getCharacterBeforeStart()) {
81 // high relevance after whitespace