KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > refactoring > ui > j > ui > CheckNode


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-2007 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19 package org.netbeans.modules.xml.refactoring.ui.j.ui;
20
21 import java.beans.BeanInfo JavaDoc;
22 import java.util.Enumeration JavaDoc;
23 import javax.swing.Icon JavaDoc;
24 import javax.swing.ImageIcon JavaDoc;
25 import javax.swing.tree.*;
26 import org.netbeans.modules.xml.refactoring.Usage;
27 import org.netbeans.modules.xml.refactoring.ui.j.api.RefactoringElement;
28 import org.netbeans.modules.xml.refactoring.ui.util.AnalysisUtilities;
29 import org.openide.nodes.Node;
30 import org.openide.text.PositionBounds;
31
32 /**
33  * @author Pavel Flaska
34  */

35 public class CheckNode extends DefaultMutableTreeNode {
36     public static final long serialVersionUID = 1L;
37     
38     public final static int SINGLE_SELECTION = 0;
39     public final static int DIG_IN_SELECTION = 4;
40     
41     private int selectionMode;
42     private boolean isSelected = true;
43     
44     private String JavaDoc nodeLabel;
45     private Icon JavaDoc icon;
46     
47     private boolean disabled = false;
48     private boolean checkEnabled = true;
49     private boolean needsRefresh = false;
50     
51     private PositionBounds bounds = null;
52     private String JavaDoc resourceName;
53     
54     private Node origNode;
55     
56     /**
57      * @param userObject usage path element, could be either Model or Component
58      * @param node original node for the userObject
59      */

60     public CheckNode(Object JavaDoc userObject, Node node) {
61         super(userObject, true);
62         this.origNode = node;
63         nodeLabel = node.getDisplayName();
64         icon = new ImageIcon JavaDoc(node.getIcon(BeanInfo.ICON_COLOR_16x16));
65         if (userObject instanceof Usage) {
66             isSelected = ((Usage)userObject).isIncludedInRefactoring();
67         }
68         setSelectionMode(DIG_IN_SELECTION);
69     }
70
71     public CheckNode(String JavaDoc label, ImageIcon JavaDoc icon) {
72         super(new Object JavaDoc(), true);
73         this.nodeLabel = label;
74         this.icon = icon;
75     }
76     
77     public String JavaDoc getLabel() {
78         return nodeLabel;
79     }
80     
81     public void setLabel(String JavaDoc nodeLabel) {
82         this.nodeLabel = nodeLabel;
83     }
84     
85     Icon JavaDoc getIcon() {
86         return icon;
87     }
88     
89     
90     
91     public void setDisabled() {
92         disabled = true;
93         isSelected = false;
94         removeAllChildren();
95     }
96     
97     boolean isDisabled() {
98         return disabled;
99     }
100     
101     public void setCheckEnabled(boolean enabled) {
102         checkEnabled = enabled;
103     }
104     
105     
106     public boolean getCheckEnabled() {
107         return checkEnabled;
108     }
109     
110     void setNeedsRefresh() {
111         needsRefresh = true;
112         setDisabled();
113     }
114     
115     boolean needsRefresh() {
116         return needsRefresh;
117     }
118     
119     public void setSelectionMode(int mode) {
120         selectionMode = mode;
121     }
122     
123     public int getSelectionMode() {
124         return selectionMode;
125     }
126     
127     public void setSelected(boolean isSelected) {
128         this.isSelected = isSelected;
129         if ((selectionMode == DIG_IN_SELECTION) && (children != null)) {
130             Enumeration JavaDoc e = children.elements();
131             while (e.hasMoreElements()) {
132                 CheckNode node = (CheckNode)e.nextElement();
133                 node.setSelected(isSelected);
134             }
135         }
136         
137         if (userObject instanceof Usage && isLeaf()){
138             ((Usage)userObject).setIncludedInRefactoring(isSelected);
139         }
140     }
141     
142     public boolean isSelected() {
143         if (userObject instanceof RefactoringElement) {
144             return ((RefactoringElement) userObject).isEnabled() &&
145                     !((((RefactoringElement) userObject).getStatus() == RefactoringElement.GUARDED) || (((RefactoringElement) userObject).getStatus() == RefactoringElement.READ_ONLY));
146         } else {
147             return isSelected;
148         }
149     }
150     
151     public PositionBounds getPosition() {
152         if (userObject instanceof RefactoringElement)
153             return ((RefactoringElement) userObject).getPosition();
154         return null;
155     }
156     
157     private String JavaDoc tooltip;
158     public String JavaDoc getToolTip() {
159         if (tooltip==null) {
160 // if ((resourceName != null) && (userObject instanceof RefactoringElement)) {
161
// RefactoringElement ree = (RefactoringElement) userObject;
162
// PositionBounds bounds = getPosition();
163
// if (bounds != null) {
164
// int line;
165
// try {
166
// line = bounds.getBegin().getLine() + 1;
167
// } catch (IOException ioe) {
168
// return null;
169
// }
170
// tooltip = resourceName + ':' + line;
171
// }
172
// }
173
// if (schemaComponent != null){
174
// // TODO schema file:line number myFolder/mySchema.xsd:42
175
// }
176
return null;
177         }
178         return tooltip;
179     }
180     
181 //lativ begin
182
public Node getOrigNode() {
183         return origNode;
184     }
185 //lativ end
186

187 }
188
Popular Tags