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 SetProperty implements ActiveEditorDrop { 32 33 public static final String [] implicitBeans = new String [] { "request", 35 "response", 36 "pageContext", 37 "session", 38 "application", 39 "out", 40 "config", 41 "page", 42 "exception" 43 }; 44 public static final int BEAN_DEFAULT = -1; 45 public static final String [] implicitTypes = new String [] { "javax.servlet.http.HttpServletRequest", 47 "javax.servlet.http.HttpServletResponse", 48 "javax.servlet.jsp.PageContext", 49 "javax.servlet.http.HttpSession", 50 "javax.servlet.ServletContext", 51 "javax.servlet.jsp.JspWriter", 52 "javax.servlet.ServletConfig", 53 "java.lang.Object", 54 "java.lang.Throwable" 55 }; 56 57 private int beanIndex = BEAN_DEFAULT; 58 private String bean = ""; 59 private String property = ""; 60 private String value = ""; 61 62 public SetProperty() { 63 } 64 65 public boolean handleTransfer(JTextComponent targetComponent) { 66 67 SetPropertyCustomizer c = new SetPropertyCustomizer(this, targetComponent); 68 boolean accept = c.showDialog(); 69 if (accept) { 70 String body = createBody(); 71 try { 72 JSPPaletteUtilities.insert(body, targetComponent); 73 } catch (BadLocationException ble) { 74 accept = false; 75 } 76 } 77 78 return accept; 79 } 80 81 private String createBody() { 82 83 String strBean = " name=\"\""; if (beanIndex == -1) 85 strBean = " name=\"" + bean + "\""; else 87 strBean = " name=\"" + implicitBeans[beanIndex] + "\""; 89 String strProperty = " property=\"" + property + "\""; 91 String strValue = " value=\"" + value + "\""; 93 String sp = "<jsp:setProperty" + strBean + strProperty + strValue + " />"; 95 return sp; 96 } 97 98 public int getBeanIndex() { 99 return beanIndex; 100 } 101 102 public void setBeanIndex(int beanIndex) { 103 this.beanIndex = beanIndex; 104 } 105 106 public String getBean() { 107 return bean; 108 } 109 110 public void setBean(String bean) { 111 this.bean = bean; 112 } 113 114 public String getProperty() { 115 return property; 116 } 117 118 public void setProperty(String property) { 119 this.property = property; 120 } 121 122 public String getValue() { 123 return value; 124 } 125 126 public void setValue(String value) { 127 this.value = value; 128 } 129 130 } 131 | Popular Tags |