1 19 package org.netbeans.modules.xml.multiview; 20 21 import org.netbeans.modules.xml.multiview.ui.BoxPanel; 22 import org.netbeans.modules.xml.multiview.ui.SectionInnerPanel; 23 import org.netbeans.modules.xml.multiview.ui.SectionNodePanel; 24 import org.netbeans.modules.xml.multiview.ui.SectionNodeView; 25 import org.netbeans.modules.xml.multiview.ui.SectionNodeInnerPanel; 26 import org.openide.nodes.AbstractNode; 27 import org.openide.nodes.Children; 28 import org.openide.nodes.Node; 29 import org.openide.util.HelpCtx; 30 31 import java.util.List ; 32 import java.util.LinkedList ; 33 import java.awt.*; 34 35 46 public class SectionNode extends AbstractNode { 47 48 protected final Object key; 49 private boolean expanded = false; 50 private SectionNodePanel sectionPanel = null; 51 private final String iconBase; 52 private final SectionNodeView sectionNodeView; 53 protected boolean helpProvider = false; 54 55 63 protected SectionNode(SectionNodeView sectionNodeView, Children children, Object key, String title, 64 String iconBase) { 65 super(children); 66 this.sectionNodeView = sectionNodeView; 67 this.key = key; 68 super.setDisplayName(title); 69 super.setIconBase(iconBase); 70 this.iconBase = iconBase; 71 sectionNodeView.registerNode(this); 72 } 73 74 public SectionNodeView getSectionNodeView() { 75 return sectionNodeView; 76 } 77 78 public Object getKey() { 79 return key; 80 } 81 82 public void addChild(SectionNode node) { 83 getChildren().add(new Node[]{node}); 84 } 85 86 90 public SectionNodeInnerPanel createInnerPanel() { 91 Children children = getChildren(); 92 if (children.getNodesCount() == 0) { 93 return createNodeInnerPanel(); 94 } else { 95 BoxPanel boxPanel = new BoxPanel(sectionNodeView); 96 populateBoxPanel(boxPanel); 97 return boxPanel; 98 } 99 } 100 101 105 public void populateBoxPanel() { 106 SectionInnerPanel innerPanel = getSectionNodePanel().getInnerPanel(); 107 if (innerPanel instanceof BoxPanel) { 108 populateBoxPanel((BoxPanel) innerPanel); 109 } 110 } 111 112 117 public void populateBoxPanel(BoxPanel boxPanel) { 118 List nodeList = new LinkedList (); 119 SectionInnerPanel nodeInnerPanel = createNodeInnerPanel(); 120 if (nodeInnerPanel != null) { 121 nodeList.add(nodeInnerPanel); 122 } 123 Node[] nodes = getChildren().getNodes(); 124 for (int i = 0; i < nodes.length; i++) { 125 nodeList.add(((SectionNode) nodes[i]).getSectionNodePanel()); 126 } 127 boxPanel.setComponents((Component[]) nodeList.toArray(new Component[0])); 128 } 129 130 131 public HelpCtx getHelpCtx() { 132 if (helpProvider) { 133 return new HelpCtx(getClass()); 134 } 135 final Node parentNode = getParentNode(); 136 if (parentNode instanceof SectionNode) { 137 return ((SectionNode) parentNode).getHelpCtx(); 138 } else { 139 return new HelpCtx(sectionNodeView.getClass()); 140 } 141 } 142 143 public boolean canDestroy() { 144 return true; 145 } 146 147 151 protected SectionNodeInnerPanel createNodeInnerPanel() { 152 return null; 153 } 154 155 public boolean isExpanded() { 156 return expanded; 157 } 158 159 public void setExpanded(boolean expanded) { 160 this.expanded = expanded; 161 } 162 163 public SectionNodePanel getSectionNodePanel() { 164 if (sectionPanel == null) { 165 sectionPanel = new SectionNodePanel(this); 166 } 167 return sectionPanel; 168 } 169 170 public String getIconBase() { 171 return iconBase; 172 } 173 174 public boolean equals(Object obj) { 175 if (getClass() == obj.getClass()) { 176 if (key.equals(((SectionNode) obj).key)) { 177 return true; 178 } 179 } 180 return false; 181 } 182 183 public int hashCode() { 184 return key.hashCode(); 185 } 186 187 public final void dataModelPropertyChange(Object source, String propertyName, Object oldValue, Object newValue) { 188 if (sectionPanel != null) { 189 SectionInnerPanel innerPanel = sectionPanel.getInnerPanel(); 190 if (innerPanel != null) { 191 innerPanel.dataModelPropertyChange(source, propertyName, oldValue, newValue); 192 } 193 } 194 Children children = getChildren(); 195 if (children != null) { 196 Node[] nodes = children.getNodes(); 197 for (int i = 0; i < nodes.length; i++) { 198 Node node = nodes[i]; 199 if (node instanceof SectionNode) { 200 ((SectionNode) node).dataModelPropertyChange(source, propertyName, oldValue, newValue); 201 } 202 } 203 } 204 } 205 206 207 211 public void refreshSubtree() { 212 if (sectionPanel != null) { 213 SectionInnerPanel innerPanel = sectionPanel.getInnerPanel(); 214 if (innerPanel != null) { 215 innerPanel.refreshView(); 216 } 217 } 218 Children children = getChildren(); 219 if (children != null) { 220 Node[] nodes = children.getNodes(); 221 for (int i = 0; i < nodes.length; i++) { 222 Node node = nodes[i]; 223 if (node instanceof SectionNode) { 224 ((SectionNode) node).refreshSubtree(); 225 } 226 } 227 } 228 } 229 230 236 public SectionNode getNodeForElement(Object element) { 237 if (key.equals(element)) { 238 return this; 239 } else { 240 final Node[] nodes = getChildren().getNodes(); 241 for (int i = 0; i < nodes.length; i++) { 242 Node node = nodes[i]; 243 if (node instanceof SectionNode) { 244 final SectionNode nodeForElement = ((SectionNode) node).getNodeForElement(element); 245 if (nodeForElement != null) { 246 return nodeForElement; 247 } 248 } 249 } 250 return null; 251 } 252 } 253 } 254 | Popular Tags |