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;
22 // import net.sourceforge.phpdt.internal.ui.text.link.LinkedPositionManager;
23 // import net.sourceforge.phpdt.internal.ui.text.link.LinkedPositionUI;
24 // import net.sourceforge.phpdt.internal.ui.util.ExceptionHandler;
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) {
88 Shell shell = fViewer.getTextWidget().getShell();
89 PHPeclipsePlugin.log(e);
90 // ExceptionHandler.handle(e, shell,
91 // ObfuscatorMessages.getString("TemplateEvaluator.error.title"), null);
95 protected void openErrorDialog(BadLocationException e) {
96 Shell shell = fViewer.getTextWidget().getShell();
97 MessageDialog.openError(shell, TemplateMessages
98 .getString("TemplateEvaluator.error.title"), e.getMessage()); //$NON-NLS-1$
101 public IContextInformation getContextInformation() {