KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > refactoring > spi > impl > 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-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19 package org.netbeans.modules.refactoring.spi.impl;
20
21 import java.util.Enumeration JavaDoc;
22 import javax.swing.Icon JavaDoc;
23 import javax.swing.tree.*;
24 import org.netbeans.modules.refactoring.spi.ui.TreeElement;
25 import org.openide.text.PositionBounds;
26 import org.netbeans.modules.refactoring.api.RefactoringElement;
27 import org.netbeans.modules.refactoring.plugins.RefactoringTreeElement;
28 import org.openide.util.NbBundle;
29
30 /**
31  * @author Pavel Flaska
32  */

33 public class CheckNode extends DefaultMutableTreeNode {
34
35     public final static int SINGLE_SELECTION = 0;
36     public final static int DIG_IN_SELECTION = 4;
37   
38     private int selectionMode;
39     private boolean isSelected;
40
41     private String JavaDoc nodeLabel;
42     private Icon JavaDoc icon;
43     
44     private boolean disabled = false;
45     private boolean needsRefresh = false;
46     
47     public CheckNode(Object JavaDoc userObject, String JavaDoc nodeLabel, Icon JavaDoc icon) {
48         super(userObject, !(userObject instanceof RefactoringElement));
49         this.isSelected = true;
50         setSelectionMode(DIG_IN_SELECTION);
51         this.nodeLabel = nodeLabel;
52         this.icon = icon;
53         if (userObject instanceof RefactoringTreeElement) {
54             if (((RefactoringTreeElement)userObject).getUserObject() instanceof RefactoringElement) {
55                 RefactoringElement ree = (RefactoringElement) ((RefactoringTreeElement)userObject).getUserObject();
56                 int s = ree.getStatus();
57                 if (s==RefactoringElement.GUARDED || s==RefactoringElement.READ_ONLY) {
58                     isSelected = false;
59                     disabled = true;
60                     this.nodeLabel = "[<font color=#CC0000>"
61                             + NbBundle.getMessage(CheckNode.class, s==RefactoringElement.GUARDED?"LBL_InGuardedBlock":"LBL_InReadOnlyFile")
62                             + "</font>]" + this.nodeLabel;
63                 }
64             }
65         }
66     }
67     
68     String JavaDoc getLabel() {
69         return nodeLabel;
70     }
71     
72     Icon JavaDoc getIcon() {
73         return icon;
74     }
75     
76     public void setDisabled() {
77         disabled = true;
78         isSelected = false;
79         removeAllChildren();
80     }
81     
82     boolean isDisabled() {
83         return disabled;
84     }
85
86     void setNeedsRefresh() {
87         needsRefresh = true;
88         setDisabled();
89     }
90     
91     boolean needsRefresh() {
92         return needsRefresh;
93     }
94     
95     public void setSelectionMode(int mode) {
96         selectionMode = mode;
97     }
98
99     public int getSelectionMode() {
100         return selectionMode;
101     }
102
103     public void setSelected(boolean isSelected) {
104         this.isSelected = isSelected;
105         if (userObject instanceof TreeElement) {
106             Object JavaDoc ob = ((TreeElement) userObject).getUserObject();
107             if (ob instanceof RefactoringElement) {
108                     ((RefactoringElement) ob).setEnabled(isSelected);
109             }
110         }
111         if ((selectionMode == DIG_IN_SELECTION) && (children != null)) {
112             Enumeration JavaDoc e = children.elements();
113             while (e.hasMoreElements()) {
114                 CheckNode node = (CheckNode)e.nextElement();
115                 node.setSelected(isSelected);
116             }
117         }
118     }
119
120     public boolean isSelected() {
121         if (userObject instanceof TreeElement) {
122             Object JavaDoc ob = ((TreeElement) userObject).getUserObject();
123             if (ob instanceof RefactoringElement) {
124                 return ((RefactoringElement) ob).isEnabled() &&
125                         !((((RefactoringElement) ob).getStatus() == RefactoringElement.GUARDED) || (((RefactoringElement) ob).getStatus() == RefactoringElement.READ_ONLY));
126             }
127         }
128         return isSelected;
129     }
130     
131     public PositionBounds getPosition() {
132         if (userObject instanceof RefactoringElement)
133             return ((RefactoringElement) userObject).getPosition();
134         return null;
135     }
136     
137     private String JavaDoc tooltip;
138     public String JavaDoc getToolTip() {
139         if (tooltip==null) {
140             if (userObject instanceof TreeElement) {
141                 Object JavaDoc re = ((TreeElement) userObject).getUserObject();
142                 if (re instanceof RefactoringElement) {
143                     tooltip = ((RefactoringElement) re).getDisplayText();
144                 }
145             }
146 // if ((resourceName != null) && (userObject instanceof RefactoringElement)) {
147
// RefactoringElement ree = (RefactoringElement) userObject;
148
// PositionBounds bounds = getPosition();
149
// if (bounds != null) {
150
// int line;
151
// try {
152
// line = bounds.getBegin().getLine() + 1;
153
// } catch (IOException ioe) {
154
// return null;
155
// }
156
// tooltip = resourceName + ':' + line;
157
// }
158
// }
159
return null;
160         }
161         return tooltip;
162     }
163 }
164
Popular Tags