KickJava   Java API By Example, From Geeks To Geeks.

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


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 If implements ActiveEditorDrop {
32
33     public static final String JavaDoc[] scopes = new String JavaDoc[] { "page", "request", "session", "application" }; // NOI18N
34
public static final int SCOPE_DEFAULT = 0;
35
36     private String JavaDoc condition = "";
37     private String JavaDoc variable = "";
38     private int scopeIndex = SCOPE_DEFAULT;
39     
40     public If() {
41     }
42
43     public boolean handleTransfer(JTextComponent JavaDoc targetComponent) {
44
45         IfCustomizer c = new IfCustomizer(this, targetComponent);
46         boolean accept = c.showDialog();
47         if (accept) {
48             String JavaDoc body = createBody();
49             try {
50                 JSPPaletteUtilities.insert(body, targetComponent);
51             } catch (BadLocationException JavaDoc ble) {
52                 accept = false;
53             }
54         }
55         
56         return accept;
57     }
58
59     private String JavaDoc createBody() {
60         
61         String JavaDoc strCondition = " test=\"" + condition + "\""; // NOI18N
62

63         String JavaDoc strVariable = "";
64         if (variable.length() > 0)
65             strVariable = " var=\"" + variable + "\""; // NOI18N
66

67         String JavaDoc strScope = "";
68         if (scopeIndex != SCOPE_DEFAULT)
69             strScope = " scope=\"" + scopes[scopeIndex] + "\""; // NOI18N
70

71         String JavaDoc ifBody = "<c:if" + strCondition + strVariable + strScope + ">\n" + // NOI18N
72
"</c:if>";// NOI18N
73

74         return ifBody;
75     }
76
77     public String JavaDoc getCondition() {
78         return condition;
79     }
80
81     public void setCondition(String JavaDoc condition) {
82         this.condition = condition;
83     }
84
85     public String JavaDoc getVariable() {
86         return variable;
87     }
88
89     public void setVariable(String JavaDoc 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