1 19 20 package org.netbeans.modules.web.jsf.editor.jspel; 21 22 import java.util.ArrayList ; 23 import java.util.List ; 24 import javax.swing.text.Document ; 25 import javax.swing.text.JTextComponent ; 26 import org.netbeans.editor.Utilities; 27 import org.netbeans.editor.ext.ExtSyntaxSupport; 28 import org.netbeans.modules.editor.NbEditorUtilities; 29 import org.netbeans.modules.web.api.webmodule.WebModule; 30 import org.netbeans.modules.web.core.syntax.JspSyntaxSupport; 31 import org.netbeans.modules.web.core.syntax.completion.JspCompletionItem; 32 import org.netbeans.modules.web.jsf.api.facesmodel.ManagedBean; 33 import org.netbeans.spi.editor.completion.*; 34 import org.netbeans.spi.editor.completion.support.AsyncCompletionQuery; 35 import org.netbeans.spi.editor.completion.support.AsyncCompletionTask; 36 import org.openide.filesystems.FileObject; 37 41 public class JSFELCompletionProvider implements CompletionProvider{ 42 43 44 public JSFELCompletionProvider() { 45 } 46 47 public CompletionTask createTask(int queryType, JTextComponent component) { 48 if (queryType == COMPLETION_QUERY_TYPE) 49 return new AsyncCompletionTask(new CCQuery(component.getCaret().getDot()), component); 50 return null; 53 } 54 55 public int getAutoQueryTypes(JTextComponent component, String typedText) { 56 return 0; 57 } 58 59 static final class CCQuery extends AsyncCompletionQuery { 60 private int creationCaretOffset; 61 private JTextComponent component; 62 63 CCQuery(int caretOffset) { 64 this.creationCaretOffset = caretOffset; 65 } 66 67 protected void query(CompletionResultSet resultSet, Document doc, int offset) { 68 ExtSyntaxSupport sup = (ExtSyntaxSupport)Utilities.getSyntaxSupport(component); 69 FileObject fObject = NbEditorUtilities.getFileObject(doc); 70 WebModule wm = null; 71 if (fObject != null) 72 wm = WebModule.getWebModule(fObject); 73 if (sup instanceof JspSyntaxSupport && wm != null){ 74 JSFELExpression elExpr = new JSFELExpression (wm, (JspSyntaxSupport)sup); 75 ArrayList complItems = new ArrayList (); 76 77 switch (elExpr.parse(offset)){ 78 case JSFELExpression.EL_START: 79 List <ManagedBean>beans = JSFBeanCache.getBeans(wm); 80 81 for (ManagedBean bean : beans){ 82 if (bean.getManagedBeanName().startsWith(elExpr.getReplace())){ 83 complItems.add(new JSFResultItem.JSFBean(bean.getManagedBeanName(), bean.getManagedBeanClass())); 84 } 85 } 86 break; 87 case JSFELExpression.EL_JSF_BEAN: 88 List <CompletionItem> items = elExpr.getPropertyCompletionItems(elExpr.getObjectClass()); 89 complItems.addAll(items); 90 break; 91 } 92 for (int i = 0; i < complItems.size(); i++) 93 ((JspCompletionItem.JspResultItem)complItems.get(i)).setSubstituteOffset(offset - elExpr.getReplace().length()); 94 resultSet.addAllItems(complItems); 95 } 96 resultSet.finish(); 97 } 98 99 protected void prepareQuery(JTextComponent component) { 100 this.component = component; 101 } 102 } 103 104 105 static class DocQuery extends AsyncCompletionQuery { 106 protected void query(CompletionResultSet resultSet, Document doc, int caretOffset) { 107 } 108 } 109 } 110 | Popular Tags |