KickJava   Java API By Example, From Geeks To Geeks.

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


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  * @author Libor Kotouc
29  */

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 JavaDoc targetComponent) {
41
42         ChooseCustomizer c = new ChooseCustomizer(this, targetComponent);
43         boolean accept = c.showDialog();
44         if (accept) {
45             String JavaDoc body = createBody();
46             try {
47                 JSPPaletteUtilities.insert(body, targetComponent);
48             } catch (BadLocationException JavaDoc ble) {
49                 accept = false;
50             }
51         }
52         
53         return accept;
54     }
55
56     private String JavaDoc createBody() {
57         
58         String JavaDoc cBody = generateChooseBody();
59         String JavaDoc body =
60                 "<c:choose>\n" + // NOI18N
61
cBody +
62                 "</c:choose>\n"; // NOI18N
63

64         return body;
65     }
66     
67     private String JavaDoc generateChooseBody() {
68         
69         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
70         for (int i = 0; i < whens; i++)
71             sb.append("<c:when test=\"\">\n</c:when>\n"); // NOI18N
72

73         if (otherwise)
74             sb.append("<c:otherwise>\n</c:otherwise>\n"); // NOI18N
75

76         String JavaDoc 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