1) Moved net.sourceforge.phpeclipse.ui\src\net\sourceforge\phpdt back to net.sourcefo...
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / ui / text / template / AbstractProposal.java
1 /*
2  * (c) Copyright IBM Corp. 2000, 2001.
3  * All Rights Reserved.
4  */
5 package net.sourceforge.phpdt.internal.ui.text.template;
6
7 //import java.util.WeakHashMap;
8
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;
12
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;
23
24
25 /**
26  * A PHP identifier proposal.
27  */
28 public abstract class AbstractProposal implements IPHPCompletionProposal {
29         protected IRegion fSelectedRegion; // initialized by apply()
30
31         protected final ITextViewer fViewer;
32
33         protected ContextInformation fContextInfo;
34
35         public AbstractProposal(ITextViewer viewer) {
36                 fContextInfo = null;
37                 fViewer = viewer;
38         }
39
40         protected static String textToHTML(String string) {
41                 StringBuffer buffer = new StringBuffer(string.length());
42                 buffer.append("<pre>"); //$NON-NLS-1$
43
44                 for (int i = 0; i != string.length(); i++) {
45                         char ch = string.charAt(i);
46
47                         switch (ch) {
48                         case '&':
49                                 buffer.append("&amp;"); //$NON-NLS-1$
50                                 break;
51
52                         case '<':
53                                 buffer.append("&lt;"); //$NON-NLS-1$
54                                 break;
55
56                         case '>':
57                                 buffer.append("&gt;"); //$NON-NLS-1$
58                                 break;
59
60                         case '\t':
61                                 buffer.append("    "); //$NON-NLS-1$
62                                 break;
63
64                         case '\n':
65                                 buffer.append("<br>"); //$NON-NLS-1$
66                                 break;
67
68                         default:
69                                 buffer.append(ch);
70                                 break;
71                         }
72                 }
73
74                 buffer.append("</pre>"); //$NON-NLS-1$
75                 return buffer.toString();
76         }
77
78         /*
79          * @see ICompletionProposal#getSelection(IDocument)
80          */
81         public Point getSelection(IDocument document) {
82                 return new Point(fSelectedRegion.getOffset(), fSelectedRegion
83                                 .getLength());
84         }
85
86         protected void handleException(CoreException e) {
87                 PHPeclipsePlugin.log(e);
88         }
89
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$
94         }
95
96         public IContextInformation getContextInformation() {
97                 return null;
98         }
99
100 }