KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > web > core > palette > items > ForEach


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.web.core.palette.items;
21 import javax.swing.text.BadLocationException JavaDoc;
22 import javax.swing.text.JTextComponent JavaDoc;
23 import org.netbeans.modules.web.core.palette.JSPPaletteUtilities;
24 import org.openide.text.ActiveEditorDrop;
25
26
27 /**
28  *
29  * @author Libor Kotouc
30  */

31 public class ForEach implements ActiveEditorDrop {
32
33     private String JavaDoc variable = "";
34     private String JavaDoc collection = "";
35     private boolean fixed = false;
36     private String JavaDoc begin = "";
37     private String JavaDoc end = "";
38     private String JavaDoc step = "";
39
40
41
42     public ForEach() {
43     }
44
45     public boolean handleTransfer(JTextComponent JavaDoc targetComponent) {
46
47         ForEachCustomizer c = new ForEachCustomizer(this, targetComponent);
48         boolean accept = c.showDialog();
49         if (accept) {
50             String JavaDoc body = createBody();
51             try {
52                 JSPPaletteUtilities.insert(body, targetComponent);
53             } catch (BadLocationException JavaDoc ble) {
54                 accept = false;
55             }
56         }
57         
58         return accept;
59     }
60
61     private String JavaDoc createBody() {
62         
63         String JavaDoc strVariable = " var=\"" + variable + "\""; // NOI18N
64

65         String JavaDoc strCollection = " items=\"" + collection + "\""; // NOI18N
66

67         String JavaDoc strBegin = "", strEnd = "", strStep = "";
68         if (fixed) {
69             if (begin.length() > 0)
70                 strBegin = " begin=\"" + begin + "\""; // NOI18N
71
if (end.length() > 0)
72                 strEnd = " end=\"" + end + "\""; // NOI18N
73
if (step.length() > 0)
74                 strStep = " step=\"" + step + "\""; // NOI18N
75
}
76         
77         String JavaDoc fe = "<c:forEach" + strVariable + strCollection + strBegin + strEnd + strStep + ">\n" + // NOI18N
78
"</c:forEach>";// NOI18N
79

80         return fe;
81     }
82
83     public String JavaDoc getVariable() {
84         return variable;
85     }
86
87     public void setVariable(String JavaDoc variable) {
88         this.variable = variable;
89     }
90
91     public String JavaDoc getCollection() {
92         return collection;
93     }
94
95     public void setCollection(String JavaDoc 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 JavaDoc getBegin() {
108         return begin;
109     }
110
111     public void setBegin(String JavaDoc begin) {
112         this.begin = begin;
113     }
114
115     public String JavaDoc getEnd() {
116         return end;
117     }
118
119     public void setEnd(String JavaDoc end) {
120         this.end = end;
121     }
122
123     public String JavaDoc getStep() {
124         return step;
125     }
126
127     public void setStep(String JavaDoc step) {
128         this.step = step;
129     }
130
131    
132 }
133
Popular Tags