1 19 package org.netbeans.modules.xml.refactoring.ui.j.ui; 20 21 import java.beans.BeanInfo ; 22 import java.util.Enumeration ; 23 import javax.swing.Icon ; 24 import javax.swing.ImageIcon ; 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 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 nodeLabel; 45 private Icon 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 resourceName; 53 54 private Node origNode; 55 56 60 public CheckNode(Object userObject, Node node) { 61 super(userObject, true); 62 this.origNode = node; 63 nodeLabel = node.getDisplayName(); 64 icon = new ImageIcon (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 label, ImageIcon icon) { 72 super(new Object (), true); 73 this.nodeLabel = label; 74 this.icon = icon; 75 } 76 77 public String getLabel() { 78 return nodeLabel; 79 } 80 81 public void setLabel(String nodeLabel) { 82 this.nodeLabel = nodeLabel; 83 } 84 85 Icon 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 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 tooltip; 158 public String getToolTip() { 159 if (tooltip==null) { 160 return null; 177 } 178 return tooltip; 179 } 180 181 public Node getOrigNode() { 183 return origNode; 184 } 185 187 } 188 | Popular Tags |