1 19 package org.netbeans.modules.refactoring.spi.impl; 20 21 import java.util.Enumeration ; 22 import javax.swing.Icon ; 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 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 nodeLabel; 42 private Icon icon; 43 44 private boolean disabled = false; 45 private boolean needsRefresh = false; 46 47 public CheckNode(Object userObject, String nodeLabel, Icon 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 getLabel() { 69 return nodeLabel; 70 } 71 72 Icon 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 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 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 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 tooltip; 138 public String getToolTip() { 139 if (tooltip==null) { 140 if (userObject instanceof TreeElement) { 141 Object re = ((TreeElement) userObject).getUserObject(); 142 if (re instanceof RefactoringElement) { 143 tooltip = ((RefactoringElement) re).getDisplayText(); 144 } 145 } 146 return null; 160 } 161 return tooltip; 162 } 163 } 164 | Popular Tags |