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.corext.template.php.PHPUnitContext;
8 import net.sourceforge.phpdt.internal.ui.text.link.LinkedPositionManager;
9 import net.sourceforge.phpdt.internal.ui.text.link.LinkedPositionUI;
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.swt.graphics.Image;
19 * A PHP identifier proposal.
21 public class SQLProposal extends AbstractProposal { //implements
22 // IPHPCompletionProposal
24 private final TemplateContext fContext;
25 private final Image fImage_var;
26 private final IRegion fRegion;
27 private final String fColumnName;
28 private final String fTableName;
30 private int fRelevance;
32 * Creates a template proposal with a template and its context.
37 * the context in which the template was requested.
39 * the icon of the proposal.
41 public SQLProposal(String tableName, TemplateContext context, IRegion region,
42 ITextViewer viewer, Image image_var) {
44 fTableName = tableName;
47 fImage_var = image_var;
52 public SQLProposal(String tableName, String columnName, TemplateContext context, IRegion region,
53 ITextViewer viewer, Image image_var) {
55 fTableName = tableName;
56 fColumnName = columnName;
58 fImage_var = image_var;
63 * @see ICompletionProposal#apply(IDocument)
65 public void apply(IDocument document) {
67 // if (fTemplateBuffer == null)
68 // fTemplateBuffer= fContext.evaluate(fTemplate);
69 int start = fRegion.getOffset();
70 int end = fRegion.getOffset() + fRegion.getLength();
71 String resultString = fTableName;
72 if (fColumnName!=null) {
73 resultString = fColumnName;
75 // insert template string
76 // String templateString = fTemplate; // fTemplateBuffer.getString();
77 document.replace(start, end - start, resultString);
78 // translate positions
79 LinkedPositionManager manager = new LinkedPositionManager(document);
80 // TemplatePosition[] variables= fTemplateBuffer.getVariables();
81 // for (int i= 0; i != variables.length; i++) {
82 // TemplatePosition variable= variables[i];
84 // if (variable.isResolved())
87 // int[] offsets= variable.getOffsets();
88 // int length= variable.getLength();
90 // for (int j= 0; j != offsets.length; j++)
91 // manager.addPosition(offsets[j] + start, length);
93 LinkedPositionUI editor = new LinkedPositionUI(fViewer, manager);
94 editor.setFinalCaretOffset(resultString.length() + start);
95 // editor.setFinalCaretOffset(getCaretOffset(fTemplateBuffer) + start);
97 fSelectedRegion = editor.getSelectedRegion();
98 } catch (BadLocationException e) {
99 PHPeclipsePlugin.log(e);
102 // catch (CoreException e) {
103 // handleException(e);
107 * @see ICompletionProposal#getAdditionalProposalInfo()
109 public String getAdditionalProposalInfo() {
110 if (fColumnName==null) {
111 return textToHTML(fTableName);
113 return fColumnName+" (Table: "+fTableName+")";
117 * @see ICompletionProposal#getContextInformation()
119 public IContextInformation getContextInformation() {
123 * @see ICompletionProposal#getDisplayString()
125 public String getDisplayString() {
126 if (fColumnName==null) {
129 return fColumnName+" (Table: "+fTableName+")"; // $NON-NLS-1$
132 * @see ICompletionProposal#getImage()
134 public Image getImage() {
138 * @see IJavaCompletionProposal#getRelevance()
140 public int getRelevance() {
144 * @param relevance The relevance to set.
146 public void setRelevance(int relevance) {
147 fRelevance = relevance;