1 /*******************************************************************************
2 * Copyright (c) 2000, 2004 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Common Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/cpl-v10.html
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
11 package net.sourceforge.phpdt.internal.ui.text.template.preferences;
13 //import net.sourceforge.phpeclipse.PHPeclipsePlugin;
15 import net.sourceforge.phpeclipse.ui.WebUI;
17 import org.eclipse.jface.dialogs.MessageDialog;
18 import org.eclipse.jface.text.BadLocationException;
19 import org.eclipse.jface.text.IDocument;
20 import org.eclipse.jface.text.ITextViewer;
21 import org.eclipse.jface.text.contentassist.ICompletionProposal;
22 import org.eclipse.jface.text.contentassist.IContextInformation;
23 import org.eclipse.jface.text.templates.TemplateVariableResolver;
24 import org.eclipse.swt.graphics.Image;
25 import org.eclipse.swt.graphics.Point;
26 import org.eclipse.swt.widgets.Shell;
29 * A proposal for insertion of template variables.
31 public class TemplateVariableProposal implements ICompletionProposal {
33 private TemplateVariableResolver fVariable;
39 private ITextViewer fViewer;
41 private Point fSelection;
44 * Creates a template variable proposal.
47 * the template variable
49 * the offset to replace
51 * the length to replace
55 public TemplateVariableProposal(TemplateVariableResolver variable,
56 int offset, int length, ITextViewer viewer) {
64 * @see ICompletionProposal#apply(IDocument)
66 public void apply(IDocument document) {
69 String variable = fVariable.getType().equals("dollar") ? "$$" : "${" + fVariable.getType() + '}'; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
70 document.replace(fOffset, fLength, variable);
71 fSelection = new Point(fOffset + variable.length(), 0);
73 } catch (BadLocationException e) {
76 Shell shell = fViewer.getTextWidget().getShell();
80 TemplatePreferencesMessages
81 .getString("TemplateVariableProposal.error.title"), e.getMessage()); //$NON-NLS-1$
86 * @see ICompletionProposal#getSelection(IDocument)
88 public Point getSelection(IDocument document) {
93 * @see ICompletionProposal#getAdditionalProposalInfo()
95 public String getAdditionalProposalInfo() {
100 * @see ICompletionProposal#getDisplayString()
102 public String getDisplayString() {
103 return fVariable.getType() + " - " + fVariable.getDescription(); //$NON-NLS-1$
107 * @see ICompletionProposal#getImage()
109 public Image getImage() {
114 * @see ICompletionProposal#getContextInformation()
116 public IContextInformation getContextInformation() {