1 19 20 package org.netbeans.modules.web.core.palette.items; 21 import javax.swing.text.BadLocationException ; 22 import javax.swing.text.JTextComponent ; 23 import org.netbeans.modules.web.core.palette.JSPPaletteUtilities; 24 import org.openide.text.ActiveEditorDrop; 25 26 27 31 public class UseBean implements ActiveEditorDrop { 32 33 private static final int BEAN_DEFAULT = -1; 34 35 public static final String [] scopes = new String [] { "page", "request", "session", "application" }; public static final int SCOPE_DEFAULT = 0; 37 38 private int beanIndex = BEAN_DEFAULT; 39 private String bean = ""; 40 private String clazz = ""; 41 private int scopeIndex = SCOPE_DEFAULT; 42 43 private String [] beans; 44 45 public UseBean() { 46 beans = findBeans(); 47 if (beans.length > 0) 48 beanIndex = 0; 49 } 50 51 public boolean handleTransfer(JTextComponent targetComponent) { 52 53 UseBeanCustomizer c = new UseBeanCustomizer(this, targetComponent); 54 boolean accept = c.showDialog(); 55 if (accept) { 56 String body = createBody(); 57 try { 58 JSPPaletteUtilities.insert(body, targetComponent); 59 } catch (BadLocationException ble) { 60 accept = false; 61 } 62 } 63 64 return accept; 65 } 66 67 private String createBody() { 68 69 String strBean = " id=\"\""; if (beanIndex == -1) 71 strBean = " id=\"" + bean + "\""; else 73 strBean = " id=\"" + beans[beanIndex] + "\""; 75 String strClass = " class=\"" + clazz + "\""; 77 String strScope = " scope=\"" + scopes[scopeIndex] + "\""; 79 String ub = "<jsp:useBean" + strBean + strScope + strClass + " />"; 81 return ub; 82 } 83 84 private String [] findBeans() { 85 86 String [] beans = new String [] {}; 88 89 return beans; 90 } 91 92 public int getBeanIndex() { 93 return beanIndex; 94 } 95 96 public void setBeanIndex(int beanIndex) { 97 this.beanIndex = beanIndex; 98 } 99 100 public String getBean() { 101 return bean; 102 } 103 104 public void setBean(String bean) { 105 this.bean = bean; 106 } 107 108 public String getClazz() { 109 return clazz; 110 } 111 112 public void setClazz(String clazz) { 113 this.clazz = clazz; 114 } 115 116 public int getScopeIndex() { 117 return scopeIndex; 118 } 119 120 public void setScopeIndex(int scopeIndex) { 121 this.scopeIndex = scopeIndex; 122 } 123 124 public String [] getBeans() { 125 return beans; 126 } 127 128 public void setBeans(String [] beans) { 129 this.beans = beans; 130 } 131 132 } 133 | Popular Tags |