2 * (c) Copyright IBM Corp. 2000, 2001.
5 package net.sourceforge.phpdt.internal.ui.text.template;
7 import net.sourceforge.phpdt.internal.corext.template.TemplateMessages;
8 import net.sourceforge.phpdt.internal.corext.template.TemplateVariable;
9 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
11 import org.eclipse.jface.dialogs.MessageDialog;
12 import org.eclipse.jface.text.BadLocationException;
13 import org.eclipse.jface.text.IDocument;
14 import org.eclipse.jface.text.ITextViewer;
15 import org.eclipse.jface.text.contentassist.ICompletionProposal;
16 import org.eclipse.jface.text.contentassist.IContextInformation;
17 import org.eclipse.swt.graphics.Image;
18 import org.eclipse.swt.graphics.Point;
19 import org.eclipse.swt.widgets.Shell;
20 //import org.eclipse.jdt.internal.ui.JavaPlugin;
23 * A proposal for insertion of template variables.
25 public class TemplateVariableProposal implements ICompletionProposal {
27 private TemplateVariable fVariable;
30 private ITextViewer fViewer;
32 private Point fSelection;
35 * Creates a template variable proposal.
37 * @param variable the template variable
38 * @param offset the offset to replace
39 * @param length the length to replace
40 * @param viewer the viewer
42 public TemplateVariableProposal(TemplateVariable variable, int offset, int length, ITextViewer viewer) {
50 * @see ICompletionProposal#apply(IDocument)
52 public void apply(IDocument document) {
55 String variable= fVariable.getName().equals("dollar") ? "$$" : "${" + fVariable.getName() + '}'; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
56 document.replace(fOffset, fLength, variable);
57 fSelection= new Point(fOffset + variable.length(), 0);
59 } catch (BadLocationException e) {
60 PHPeclipsePlugin.log(e);
62 Shell shell= fViewer.getTextWidget().getShell();
63 MessageDialog.openError(shell, TemplateMessages.getString("TemplateVariableProposal.error.title"), e.getMessage()); //$NON-NLS-1$
68 * @see ICompletionProposal#getSelection(IDocument)
70 public Point getSelection(IDocument document) {
75 * @see ICompletionProposal#getAdditionalProposalInfo()
77 public String getAdditionalProposalInfo() {
82 * @see ICompletionProposal#getDisplayString()
84 public String getDisplayString() {
85 return fVariable.getName() + " - " + fVariable.getDescription(); //$NON-NLS-1$
89 * @see ICompletionProposal#getImage()
91 public Image getImage() {
96 * @see ICompletionProposal#getContextInformation()
98 public IContextInformation getContextInformation() {