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.PHPeclipsePlugin;
11 import org.eclipse.jface.text.BadLocationException;
12 import org.eclipse.jface.text.IDocument;
13 import org.eclipse.jface.text.IRegion;
14 import org.eclipse.jface.text.ITextViewer;
15 import org.eclipse.jface.text.contentassist.IContextInformation;
16 import org.eclipse.jface.text.templates.TemplateContext;
17 import org.eclipse.swt.graphics.Image;
20 * A PHP identifier proposal.
22 public class SQLProposal extends AbstractProposal {
23 private final TemplateContext fContext;
25 private final Image fImage_var;
27 private final IRegion fRegion;
29 private final String fColumnName;
31 private final String fTableName;
33 private int fRelevance;
36 * Creates a template proposal with a template and its context.
41 * the context in which the template was requested.
43 * the icon of the proposal.
45 public SQLProposal(String tableName, TemplateContext context,
46 IRegion region, ITextViewer viewer, Image image_var) {
48 fTableName = tableName;
51 fImage_var = image_var;
56 public SQLProposal(String tableName, String columnName,
57 TemplateContext context, IRegion region, ITextViewer viewer,
60 fTableName = tableName;
61 fColumnName = columnName;
63 fImage_var = image_var;
69 * @see ICompletionProposal#apply(IDocument)
71 public void apply(IDocument document) {
73 int start = fRegion.getOffset();
74 int end = fRegion.getOffset() + fRegion.getLength();
75 String resultString = fTableName;
76 if (fColumnName != null) {
77 resultString = fColumnName;
79 // insert template string
80 document.replace(start, end - start, resultString);
81 // translate positions
82 LinkedPositionManager manager = new LinkedPositionManager(document);
83 LinkedPositionUI editor = new LinkedPositionUI(fViewer, manager);
84 editor.setFinalCaretOffset(resultString.length() + start);
86 fSelectedRegion = editor.getSelectedRegion();
87 } catch (BadLocationException e) {
88 PHPeclipsePlugin.log(e);
94 * @see ICompletionProposal#getAdditionalProposalInfo()
96 public String getAdditionalProposalInfo() {
97 if (fColumnName == null) {
98 return textToHTML(fTableName);
100 return fColumnName + " (Table: " + fTableName + ")";
104 * @see ICompletionProposal#getContextInformation()
106 public IContextInformation getContextInformation() {
111 * @see ICompletionProposal#getDisplayString()
113 public String getDisplayString() {
114 if (fColumnName == null) {
117 return fColumnName + " (Table: " + fTableName + ")"; // $NON-NLS-1$
121 * @see ICompletionProposal#getImage()
123 public Image getImage() {
128 * @see IJavaCompletionProposal#getRelevance()
130 public int getRelevance() {
136 * The relevance to set.
138 public void setRelevance(int relevance) {
139 fRelevance = relevance;