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.swt.graphics.Point;
18 import org.eclipse.swt.widgets.Shell;
19 //import net.sourceforge.phpdt.internal.ui.text.link.LinkedPositionManager;
20 //import net.sourceforge.phpdt.internal.ui.text.link.LinkedPositionUI;
21 //import net.sourceforge.phpdt.internal.ui.util.ExceptionHandler;
24 * A PHP identifier proposal.
26 public abstract class AbstractProposal implements IPHPCompletionProposal {
27 protected IRegion fSelectedRegion; // initialized by apply()
28 protected final ITextViewer fViewer;
30 public AbstractProposal(ITextViewer viewer) {
33 protected static String textToHTML(String string) {
34 StringBuffer buffer = new StringBuffer(string.length());
35 buffer.append("<pre>"); //$NON-NLS-1$
37 for (int i = 0; i != string.length(); i++) {
38 char ch = string.charAt(i);
42 buffer.append("&"); //$NON-NLS-1$
46 buffer.append("<"); //$NON-NLS-1$
50 buffer.append(">"); //$NON-NLS-1$
54 buffer.append(" "); //$NON-NLS-1$
58 buffer.append("<br>"); //$NON-NLS-1$
67 buffer.append("</pre>"); //$NON-NLS-1$
68 return buffer.toString();
72 * @see ICompletionProposal#getSelection(IDocument)
74 public Point getSelection(IDocument document) {
75 return new Point(fSelectedRegion.getOffset(), fSelectedRegion.getLength());
78 protected void handleException(CoreException e) {
79 Shell shell = fViewer.getTextWidget().getShell();
80 PHPeclipsePlugin.log(e);
81 // ExceptionHandler.handle(e, shell, ObfuscatorMessages.getString("TemplateEvaluator.error.title"), null); //$NON-NLS-1$
84 protected void openErrorDialog(BadLocationException e) {
85 Shell shell = fViewer.getTextWidget().getShell();
86 MessageDialog.openError(shell, TemplateMessages.getString("TemplateEvaluator.error.title"), e.getMessage()); //$NON-NLS-1$