1 19 package org.openide.explorer.view; 20 21 import org.openide.explorer.*; 22 import org.openide.explorer.ExplorerManager.Provider; 23 import org.openide.nodes.Node; 24 import org.openide.nodes.Node.Property; 25 import org.openide.util.*; 26 27 import java.awt.*; 28 import java.awt.event.*; 29 30 import java.beans.*; 31 32 import java.util.*; 33 34 import javax.swing.*; 35 import javax.swing.BorderFactory ; 36 import javax.swing.event.*; 37 import javax.swing.tree.*; 38 39 40 73 public class BeanTreeView extends TreeView { 74 75 static final long serialVersionUID = 3841322840231536380L; 76 77 79 public BeanTreeView() { 80 setBorder(BorderFactory.createEmptyBorder()); 82 } 83 84 void initializeTree() { 85 super.initializeTree(); 86 } 87 88 92 protected NodeTreeModel createModel() { 93 return new NodeTreeModel(); 94 } 95 96 98 protected boolean selectionAccept(Node[] nodes) { 99 return true; 100 } 101 102 104 protected void showSelection(TreePath[] treePaths) { 105 tree.getSelectionModel().setSelectionPaths(treePaths); 106 107 if (treePaths.length == 1) { 108 showPathWithoutExpansion(treePaths[0]); 109 } 110 } 111 112 116 protected void selectionChanged(Node[] nodes, ExplorerManager em) 117 throws PropertyVetoException { 118 if (nodes.length > 0) { 119 Node context = nodes[0].getParentNode(); 120 121 for (int i = 1; i < nodes.length; i++) { 122 if (context != nodes[i].getParentNode()) { 123 em.setSelectedNodes(nodes); 124 125 return; 126 } 127 } 128 129 if (em.getRootContext().getParentNode() == context) { 131 em.setExploredContextAndSelection(null, nodes); 132 } else { 133 em.setExploredContextAndSelection(context, nodes); 134 } 135 } else { 136 em.setSelectedNodes(nodes); 137 } 138 } 139 140 143 protected void showPath(TreePath path) { 144 tree.expandPath(path); 145 showPathWithoutExpansion(path); 146 } 147 148 151 private void showPathWithoutExpansion(TreePath path) { 152 Rectangle rect = tree.getPathBounds(path); 153 154 if (rect != null) { tree.scrollRectToVisible(rect); 156 } 157 } 158 159 162 public void setEnabled(boolean enabled) { 163 this.tree.setEnabled(enabled); 164 } 165 166 169 public boolean isEnabled() { 170 if (this.tree == null) { 171 return true; 174 } 175 176 return this.tree.isEnabled(); 177 } 178 } 179 | Popular Tags |