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 ForEach implements ActiveEditorDrop { 32 33 private String variable = ""; 34 private String collection = ""; 35 private boolean fixed = false; 36 private String begin = ""; 37 private String end = ""; 38 private String step = ""; 39 40 41 42 public ForEach() { 43 } 44 45 public boolean handleTransfer(JTextComponent targetComponent) { 46 47 ForEachCustomizer c = new ForEachCustomizer(this, targetComponent); 48 boolean accept = c.showDialog(); 49 if (accept) { 50 String body = createBody(); 51 try { 52 JSPPaletteUtilities.insert(body, targetComponent); 53 } catch (BadLocationException ble) { 54 accept = false; 55 } 56 } 57 58 return accept; 59 } 60 61 private String createBody() { 62 63 String strVariable = " var=\"" + variable + "\""; 65 String strCollection = " items=\"" + collection + "\""; 67 String strBegin = "", strEnd = "", strStep = ""; 68 if (fixed) { 69 if (begin.length() > 0) 70 strBegin = " begin=\"" + begin + "\""; if (end.length() > 0) 72 strEnd = " end=\"" + end + "\""; if (step.length() > 0) 74 strStep = " step=\"" + step + "\""; } 76 77 String fe = "<c:forEach" + strVariable + strCollection + strBegin + strEnd + strStep + ">\n" + "</c:forEach>"; 80 return fe; 81 } 82 83 public String getVariable() { 84 return variable; 85 } 86 87 public void setVariable(String variable) { 88 this.variable = variable; 89 } 90 91 public String getCollection() { 92 return collection; 93 } 94 95 public void setCollection(String collection) { 96 this.collection = collection; 97 } 98 99 public boolean isFixed() { 100 return fixed; 101 } 102 103 public void setFixed(boolean fixed) { 104 this.fixed = fixed; 105 } 106 107 public String getBegin() { 108 return begin; 109 } 110 111 public void setBegin(String begin) { 112 this.begin = begin; 113 } 114 115 public String getEnd() { 116 return end; 117 } 118 119 public void setEnd(String end) { 120 this.end = end; 121 } 122 123 public String getStep() { 124 return step; 125 } 126 127 public void setStep(String step) { 128 this.step = step; 129 } 130 131 132 } 133 | Popular Tags |