2 * (c) Copyright IBM Corp. 2000, 2001.
5 package net.sourceforge.phpdt.internal.ui.text.template;
6 import net.sourceforge.phpdt.internal.corext.template.TemplateContext;
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.swt.graphics.Image;
18 * A PHP identifier proposal.
20 public class SQLProposal extends AbstractProposal { //implements
21 // IPHPCompletionProposal
23 private final TemplateContext fContext;
24 private final Image fImage_var;
25 private final IRegion fRegion;
26 private final String fColumnName;
27 private final String fTableName;
29 private int fRelevance;
31 * Creates a template proposal with a template and its context.
36 * the context in which the template was requested.
38 * the icon of the proposal.
40 public SQLProposal(String tableName, TemplateContext context, IRegion region,
41 ITextViewer viewer, Image image_var) {
43 fTableName = tableName;
46 fImage_var = image_var;
51 public SQLProposal(String tableName, String columnName, TemplateContext context, IRegion region,
52 ITextViewer viewer, Image image_var) {
54 fTableName = tableName;
55 fColumnName = columnName;
57 fImage_var = image_var;
62 * @see ICompletionProposal#apply(IDocument)
64 public void apply(IDocument document) {
66 // if (fTemplateBuffer == null)
67 // fTemplateBuffer= fContext.evaluate(fTemplate);
68 int start = fRegion.getOffset();
69 int end = fRegion.getOffset() + fRegion.getLength();
70 String resultString = fTableName;
71 if (fColumnName!=null) {
72 resultString = fColumnName;
74 // insert template string
75 // String templateString = fTemplate; // fTemplateBuffer.getString();
76 document.replace(start, end - start, resultString);
77 // translate positions
78 LinkedPositionManager manager = new LinkedPositionManager(document);
79 // TemplatePosition[] variables= fTemplateBuffer.getVariables();
80 // for (int i= 0; i != variables.length; i++) {
81 // TemplatePosition variable= variables[i];
83 // if (variable.isResolved())
86 // int[] offsets= variable.getOffsets();
87 // int length= variable.getLength();
89 // for (int j= 0; j != offsets.length; j++)
90 // manager.addPosition(offsets[j] + start, length);
92 LinkedPositionUI editor = new LinkedPositionUI(fViewer, manager);
93 editor.setFinalCaretOffset(resultString.length() + start);
94 // editor.setFinalCaretOffset(getCaretOffset(fTemplateBuffer) + start);
96 fSelectedRegion = editor.getSelectedRegion();
97 } catch (BadLocationException e) {
98 PHPeclipsePlugin.log(e);
101 // catch (CoreException e) {
102 // handleException(e);
106 * @see ICompletionProposal#getAdditionalProposalInfo()
108 public String getAdditionalProposalInfo() {
109 if (fColumnName==null) {
110 return textToHTML(fTableName);
112 return fColumnName+" (Table: "+fTableName+")";
116 * @see ICompletionProposal#getContextInformation()
118 public IContextInformation getContextInformation() {
122 * @see ICompletionProposal#getDisplayString()
124 public String getDisplayString() {
125 if (fColumnName==null) {
128 return fColumnName+" (Table: "+fTableName+")"; // $NON-NLS-1$
131 * @see ICompletionProposal#getImage()
133 public Image getImage() {
137 * @see IJavaCompletionProposal#getRelevance()
139 public int getRelevance() {
143 * @param relevance The relevance to set.
145 public void setRelevance(int relevance) {
146 fRelevance = relevance;