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.ui.text.java.IPHPCompletionProposal;
9 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
11 import org.eclipse.core.runtime.CoreException;
12 import org.eclipse.jface.dialogs.MessageDialog;
13 import org.eclipse.jface.text.BadLocationException;
14 import org.eclipse.jface.text.IDocument;
15 import org.eclipse.jface.text.IRegion;
16 import org.eclipse.jface.text.ITextViewer;
17 import org.eclipse.jface.text.contentassist.ContextInformation;
18 import org.eclipse.jface.text.contentassist.IContextInformation;
19 import org.eclipse.swt.graphics.Point;
20 import org.eclipse.swt.widgets.Shell;
24 * A PHP identifier proposal.
26 public abstract class AbstractProposal implements IPHPCompletionProposal {
27 protected IRegion fSelectedRegion; // initialized by apply()
29 protected final ITextViewer fViewer;
31 protected ContextInformation fContextInfo;
33 public AbstractProposal(ITextViewer viewer) {
38 protected static String textToHTML(String string) {
39 StringBuffer buffer = new StringBuffer(string.length());
40 buffer.append("<pre>"); //$NON-NLS-1$
42 for (int i = 0; i != string.length(); i++) {
43 char ch = string.charAt(i);
47 buffer.append("&"); //$NON-NLS-1$
51 buffer.append("<"); //$NON-NLS-1$
55 buffer.append(">"); //$NON-NLS-1$
59 buffer.append(" "); //$NON-NLS-1$
63 buffer.append("<br>"); //$NON-NLS-1$
72 buffer.append("</pre>"); //$NON-NLS-1$
73 return buffer.toString();
77 * @see ICompletionProposal#getSelection(IDocument)
79 public Point getSelection(IDocument document) {
80 return new Point(fSelectedRegion.getOffset(), fSelectedRegion
84 protected void handleException(CoreException e) {
85 PHPeclipsePlugin.log(e);
88 protected void openErrorDialog(BadLocationException e) {
89 Shell shell = fViewer.getTextWidget().getShell();
90 MessageDialog.openError(shell, TemplateMessages
91 .getString("TemplateEvaluator.error.title"), e.getMessage()); //$NON-NLS-1$
94 public IContextInformation getContextInformation() {