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 30 public class Choose implements ActiveEditorDrop { 31 32 public static final int DEFAULT_WHENS = 1; 33 34 private int whens = DEFAULT_WHENS; 35 private boolean otherwise = true; 36 37 public Choose() { 38 } 39 40 public boolean handleTransfer(JTextComponent targetComponent) { 41 42 ChooseCustomizer c = new ChooseCustomizer(this, targetComponent); 43 boolean accept = c.showDialog(); 44 if (accept) { 45 String body = createBody(); 46 try { 47 JSPPaletteUtilities.insert(body, targetComponent); 48 } catch (BadLocationException ble) { 49 accept = false; 50 } 51 } 52 53 return accept; 54 } 55 56 private String createBody() { 57 58 String cBody = generateChooseBody(); 59 String body = 60 "<c:choose>\n" + cBody + 62 "</c:choose>\n"; 64 return body; 65 } 66 67 private String generateChooseBody() { 68 69 StringBuffer sb = new StringBuffer (); 70 for (int i = 0; i < whens; i++) 71 sb.append("<c:when test=\"\">\n</c:when>\n"); 73 if (otherwise) 74 sb.append("<c:otherwise>\n</c:otherwise>\n"); 76 String cBody = sb.toString(); 77 78 return cBody; 79 } 80 81 public int getWhens() { 82 return whens; 83 } 84 85 public void setWhens(int whens) { 86 this.whens = whens; 87 } 88 89 public boolean isOtherwise() { 90 return otherwise; 91 } 92 93 public void setOtherwise(boolean otherwise) { 94 this.otherwise = otherwise; 95 } 96 97 } 98 | Popular Tags |