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;
10 import org.eclipse.jface.dialogs.MessageDialog;
11 import org.eclipse.jface.text.BadLocationException;
12 import org.eclipse.jface.text.IDocument;
13 import org.eclipse.jface.text.ITextViewer;
14 import org.eclipse.jface.text.contentassist.ICompletionProposal;
15 import org.eclipse.jface.text.contentassist.IContextInformation;
16 import org.eclipse.swt.graphics.Image;
17 import org.eclipse.swt.graphics.Point;
18 import org.eclipse.swt.widgets.Shell;
19 //import org.eclipse.jdt.internal.ui.JavaPlugin;
22 * A proposal for insertion of template variables.
24 public class TemplateVariableProposal implements ICompletionProposal {
26 private TemplateVariable fVariable;
29 private ITextViewer fViewer;
31 private Point fSelection;
34 * Creates a template variable proposal.
36 * @param variable the template variable
37 * @param offset the offset to replace
38 * @param length the length to replace
39 * @param viewer the viewer
41 public TemplateVariableProposal(TemplateVariable variable, int offset, int length, ITextViewer viewer) {
49 * @see ICompletionProposal#apply(IDocument)
51 public void apply(IDocument document) {
54 String variable= fVariable.getName().equals("dollar") ? "$$" : "${" + fVariable.getName() + '}'; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
55 document.replace(fOffset, fLength, variable);
56 fSelection= new Point(fOffset + variable.length(), 0);
58 } catch (BadLocationException e) {
59 PHPeclipsePlugin.log(e);
61 Shell shell= fViewer.getTextWidget().getShell();
62 MessageDialog.openError(shell, TemplateMessages.getString("TemplateVariableProposal.error.title"), e.getMessage()); //$NON-NLS-1$
67 * @see ICompletionProposal#getSelection(IDocument)
69 public Point getSelection(IDocument document) {
74 * @see ICompletionProposal#getAdditionalProposalInfo()
76 public String getAdditionalProposalInfo() {
81 * @see ICompletionProposal#getDisplayString()
83 public String getDisplayString() {
84 return fVariable.getName() + " - " + fVariable.getDescription(); //$NON-NLS-1$
88 * @see ICompletionProposal#getImage()
90 public Image getImage() {
95 * @see ICompletionProposal#getContextInformation()
97 public IContextInformation getContextInformation() {