1 11 package org.eclipse.ui.texteditor.templates; 12 13 import org.eclipse.swt.graphics.Image; 14 import org.eclipse.swt.graphics.Point; 15 import org.eclipse.swt.widgets.Shell; 16 17 import org.eclipse.jface.dialogs.MessageDialog; 18 19 import org.eclipse.jface.text.BadLocationException; 20 import org.eclipse.jface.text.IDocument; 21 import org.eclipse.jface.text.ITextViewer; 22 import org.eclipse.jface.text.contentassist.ICompletionProposal; 23 import org.eclipse.jface.text.contentassist.IContextInformation; 24 import org.eclipse.jface.text.templates.TemplateVariableResolver; 25 26 35 final class TemplateVariableProposal implements ICompletionProposal { 36 37 private TemplateVariableResolver fVariable; 38 private int fOffset; 39 private int fLength; 40 private ITextViewer fViewer; 41 42 private Point fSelection; 43 44 52 public TemplateVariableProposal(TemplateVariableResolver variable, int offset, int length, ITextViewer viewer) { 53 fVariable= variable; 54 fOffset= offset; 55 fLength= length; 56 fViewer= viewer; 57 } 58 59 62 public void apply(IDocument document) { 63 64 try { 65 String variable= fVariable.getType().equals("dollar") ? "$$" : "${" + fVariable.getType() + '}'; document.replace(fOffset, fLength, variable); 67 fSelection= new Point(fOffset + variable.length(), 0); 68 69 } catch (BadLocationException e) { 70 Shell shell= fViewer.getTextWidget().getShell(); 71 MessageDialog.openError(shell, TextEditorTemplateMessages.TemplateVariableProposal_error_title, e.getMessage()); 72 } 73 } 74 75 78 public Point getSelection(IDocument document) { 79 return fSelection; 80 } 81 82 85 public String getAdditionalProposalInfo() { 86 return null; 87 } 88 89 92 public String getDisplayString() { 93 return fVariable.getType() + " - " + fVariable.getDescription(); } 95 96 99 public Image getImage() { 100 return null; 101 } 102 103 106 public IContextInformation getContextInformation() { 107 return null; 108 } 109 } 110 | Popular Tags |