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 If implements ActiveEditorDrop { 32 33 public static final String [] scopes = new String [] { "page", "request", "session", "application" }; public static final int SCOPE_DEFAULT = 0; 35 36 private String condition = ""; 37 private String variable = ""; 38 private int scopeIndex = SCOPE_DEFAULT; 39 40 public If() { 41 } 42 43 public boolean handleTransfer(JTextComponent targetComponent) { 44 45 IfCustomizer c = new IfCustomizer(this, targetComponent); 46 boolean accept = c.showDialog(); 47 if (accept) { 48 String body = createBody(); 49 try { 50 JSPPaletteUtilities.insert(body, targetComponent); 51 } catch (BadLocationException ble) { 52 accept = false; 53 } 54 } 55 56 return accept; 57 } 58 59 private String createBody() { 60 61 String strCondition = " test=\"" + condition + "\""; 63 String strVariable = ""; 64 if (variable.length() > 0) 65 strVariable = " var=\"" + variable + "\""; 67 String strScope = ""; 68 if (scopeIndex != SCOPE_DEFAULT) 69 strScope = " scope=\"" + scopes[scopeIndex] + "\""; 71 String ifBody = "<c:if" + strCondition + strVariable + strScope + ">\n" + "</c:if>"; 74 return ifBody; 75 } 76 77 public String getCondition() { 78 return condition; 79 } 80 81 public void setCondition(String condition) { 82 this.condition = condition; 83 } 84 85 public String getVariable() { 86 return variable; 87 } 88 89 public void setVariable(String variable) { 90 this.variable = variable; 91 } 92 93 public int getScopeIndex() { 94 return scopeIndex; 95 } 96 97 public void setScopeIndex(int scopeIndex) { 98 this.scopeIndex = scopeIndex; 99 } 100 101 102 } 103 | Popular Tags |