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.ui.WebUI;
12 //import net.sourceforge.phpeclipse.PHPeclipsePlugin;
14 import org.eclipse.core.runtime.CoreException;
15 import org.eclipse.jface.dialogs.MessageDialog;
16 import org.eclipse.jface.text.BadLocationException;
17 import org.eclipse.jface.text.IDocument;
18 import org.eclipse.jface.text.IRegion;
19 import org.eclipse.jface.text.ITextViewer;
20 import org.eclipse.jface.text.contentassist.ContextInformation;
21 import org.eclipse.jface.text.contentassist.IContextInformation;
22 import org.eclipse.swt.graphics.Point;
23 import org.eclipse.swt.widgets.Shell;
27 * A PHP identifier proposal.
29 public abstract class AbstractProposal implements IPHPCompletionProposal {
30 protected IRegion fSelectedRegion; // initialized by apply()
32 protected final ITextViewer fViewer;
34 protected ContextInformation fContextInfo;
36 public AbstractProposal(ITextViewer viewer) {
41 protected static String textToHTML(String string) {
42 StringBuffer buffer = new StringBuffer(string.length());
43 buffer.append("<pre>"); //$NON-NLS-1$
45 for (int i = 0; i != string.length(); i++) {
46 char ch = string.charAt(i);
50 buffer.append("&"); //$NON-NLS-1$
54 buffer.append("<"); //$NON-NLS-1$
58 buffer.append(">"); //$NON-NLS-1$
62 buffer.append(" "); //$NON-NLS-1$
66 buffer.append("<br>"); //$NON-NLS-1$
75 buffer.append("</pre>"); //$NON-NLS-1$
76 return buffer.toString();
80 * @see ICompletionProposal#getSelection(IDocument)
82 public Point getSelection(IDocument document) {
83 return new Point(fSelectedRegion.getOffset(), fSelectedRegion
87 protected void handleException(CoreException e) {
91 protected void openErrorDialog(BadLocationException e) {
92 Shell shell = fViewer.getTextWidget().getShell();
93 MessageDialog.openError(shell, TemplateMessages
94 .getString("TemplateEvaluator.error.title"), e.getMessage()); //$NON-NLS-1$
97 public IContextInformation getContextInformation() {