2 * (c) Copyright IBM Corp. 2000, 2001.
5 package net.sourceforge.phpdt.internal.ui.text.template;
7 import net.sourceforge.phpdt.internal.ui.text.link.LinkedPositionManager;
8 import net.sourceforge.phpdt.internal.ui.text.link.LinkedPositionUI;
9 import net.sourceforge.phpeclipse.ui.WebUI;
10 //import net.sourceforge.phpeclipse.PHPeclipsePlugin;
12 import org.eclipse.jface.text.BadLocationException;
13 import org.eclipse.jface.text.IDocument;
14 import org.eclipse.jface.text.IRegion;
15 import org.eclipse.jface.text.ITextViewer;
16 import org.eclipse.jface.text.contentassist.IContextInformation;
17 import org.eclipse.jface.text.templates.TemplateContext;
18 import org.eclipse.swt.graphics.Image;
21 * A PHP identifier proposal.
23 public class SQLProposal extends AbstractProposal {
24 private final TemplateContext fContext;
26 private final Image fImage_var;
28 private final IRegion fRegion;
30 private final String fColumnName;
32 private final String fTableName;
34 private int fRelevance;
37 * Creates a template proposal with a template and its context.
42 * the context in which the template was requested.
44 * the icon of the proposal.
46 public SQLProposal(String tableName, TemplateContext context,
47 IRegion region, ITextViewer viewer, Image image_var) {
49 fTableName = tableName;
52 fImage_var = image_var;
57 public SQLProposal(String tableName, String columnName,
58 TemplateContext context, IRegion region, ITextViewer viewer,
61 fTableName = tableName;
62 fColumnName = columnName;
64 fImage_var = image_var;
70 * @see ICompletionProposal#apply(IDocument)
72 public void apply(IDocument document) {
74 int start = fRegion.getOffset();
75 int end = fRegion.getOffset() + fRegion.getLength();
76 String resultString = fTableName;
77 if (fColumnName != null) {
78 resultString = fColumnName;
80 // insert template string
81 document.replace(start, end - start, resultString);
82 // translate positions
83 LinkedPositionManager manager = new LinkedPositionManager(document);
84 LinkedPositionUI editor = new LinkedPositionUI(fViewer, manager);
85 editor.setFinalCaretOffset(resultString.length() + start);
87 fSelectedRegion = editor.getSelectedRegion();
88 } catch (BadLocationException e) {
95 * @see ICompletionProposal#getAdditionalProposalInfo()
97 public String getAdditionalProposalInfo() {
98 if (fColumnName == null) {
99 return textToHTML(fTableName);
101 return fColumnName + " (Table: " + fTableName + ")";
105 * @see ICompletionProposal#getContextInformation()
107 public IContextInformation getContextInformation() {
112 * @see ICompletionProposal#getDisplayString()
114 public String getDisplayString() {
115 if (fColumnName == null) {
118 return fColumnName + " (Table: " + fTableName + ")"; // $NON-NLS-1$
122 * @see ICompletionProposal#getImage()
124 public Image getImage() {
129 * @see IJavaCompletionProposal#getRelevance()
131 public int getRelevance() {
137 * The relevance to set.
139 public void setRelevance(int relevance) {
140 fRelevance = relevance;