2 * (c) Copyright IBM Corp. 2000, 2001.
5 package net.sourceforge.phpdt.internal.ui.text.template;
7 //import java.util.WeakHashMap;
9 import net.sourceforge.phpdt.internal.corext.template.TemplateMessages;
10 import net.sourceforge.phpdt.internal.ui.text.java.IPHPCompletionProposal;
11 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
13 import org.eclipse.core.runtime.CoreException;
14 import org.eclipse.jface.dialogs.MessageDialog;
15 import org.eclipse.jface.text.BadLocationException;
16 import org.eclipse.jface.text.IDocument;
17 import org.eclipse.jface.text.IRegion;
18 import org.eclipse.jface.text.ITextViewer;
19 import org.eclipse.jface.text.contentassist.ContextInformation;
20 import org.eclipse.jface.text.contentassist.IContextInformation;
21 import org.eclipse.swt.graphics.Point;
22 import org.eclipse.swt.widgets.Shell;
26 * A PHP identifier proposal.
28 public abstract class AbstractProposal implements IPHPCompletionProposal {
29 protected IRegion fSelectedRegion; // initialized by apply()
31 protected final ITextViewer fViewer;
33 protected ContextInformation fContextInfo;
35 public AbstractProposal(ITextViewer viewer) {
40 protected static String textToHTML(String string) {
41 StringBuffer buffer = new StringBuffer(string.length());
42 buffer.append("<pre>"); //$NON-NLS-1$
44 for (int i = 0; i != string.length(); i++) {
45 char ch = string.charAt(i);
49 buffer.append("&"); //$NON-NLS-1$
53 buffer.append("<"); //$NON-NLS-1$
57 buffer.append(">"); //$NON-NLS-1$
61 buffer.append(" "); //$NON-NLS-1$
65 buffer.append("<br>"); //$NON-NLS-1$
74 buffer.append("</pre>"); //$NON-NLS-1$
75 return buffer.toString();
79 * @see ICompletionProposal#getSelection(IDocument)
81 public Point getSelection(IDocument document) {
82 return new Point(fSelectedRegion.getOffset(), fSelectedRegion
86 protected void handleException(CoreException e) {
87 PHPeclipsePlugin.log(e);
90 protected void openErrorDialog(BadLocationException e) {
91 Shell shell = fViewer.getTextWidget().getShell();
92 MessageDialog.openError(shell, TemplateMessages
93 .getString("TemplateEvaluator.error.title"), e.getMessage()); //$NON-NLS-1$
96 public IContextInformation getContextInformation() {