1 19 20 package org.netbeans.beaninfo.editors; 21 22 import java.awt.*; 23 import java.beans.*; 24 import java.util.*; 25 import javax.swing.*; 26 import javax.swing.border.*; 27 import javax.swing.event.*; 28 import javax.swing.tree.*; 29 30 import org.openide.*; 31 import org.openide.explorer.*; 32 import org.openide.explorer.propertysheet.PropertyEnv; 33 import org.openide.explorer.propertysheet.editors.*; 34 import org.openide.explorer.view.*; 35 import org.openide.loaders.*; 36 import org.openide.nodes.*; 37 import org.openide.util.*; 38 39 46 public class DataObjectPanel extends JPanel { 47 48 final static int DEFAULT_INSET = 10; 49 50 protected DataFilter folderFilter; 51 protected DataFilter dataFilter; 52 protected NodeAcceptor nodeFilter; 53 protected Insets insets; 54 protected String subTitle; 55 protected String description; 56 protected DataObject rootObject; 57 58 protected Node rootNode; 59 protected DataObject dObj; 60 62 protected boolean multiSelection; 63 protected int selectionMode = JFileChooser.FILES_ONLY; 64 65 protected PropertyEditorSupport myEditor; 66 67 private PropertyEnv env; 68 69 public DataObjectPanel(PropertyEditorSupport my, PropertyEnv env) { 70 this.env = env; 71 myEditor = my; 72 } 73 74 76 public void setEnv(PropertyEnv env) { 77 this.env = env; 78 } 79 80 88 public void setDataFilter(DataFilter df) { 89 dataFilter = df; 90 } 91 92 100 public void setNodeFilter(NodeAcceptor acceptor) { 101 nodeFilter = acceptor; 102 } 103 104 110 public void setInsetValue(int insetVal) { 111 insets = new Insets(insetVal, insetVal, insetVal, insetVal); 112 } 113 114 120 public void setText(String text) { 121 subTitle = text; 122 } 123 124 132 public void setRootObject(DataObject obj) { 133 rootObject = obj; 134 } 135 136 public void setRootNode(Node n) { 137 rootNode = n; 138 } 139 140 144 public void setFolderFilter(DataFilter f) { 145 folderFilter = f; 146 } 147 148 152 public DataFilter getFolderFilter() { 153 return folderFilter; 154 } 155 156 161 public void setDataObject(DataObject d) { 162 dObj = d; 163 } 164 165 172 public void setMultiSelection (boolean multiSelection) { 173 this.multiSelection = multiSelection; 174 } 175 176 186 public void setSelectionMode (int selectionMode) { 187 this.selectionMode = selectionMode; 188 } 189 190 195 public void setDescription(String desc) { 196 } 197 198 protected Node findNode(Node parent, DataObject val) { 199 Children children = parent.getChildren(); 200 Node theNode = children.findChild(val.getName()); 201 if (theNode == null) { 202 Node [] allNodes = children.getNodes(); 203 if ((allNodes != null) && (allNodes.length > 0)) { 204 for (int i = 0; 205 (i < allNodes.length) && (theNode == null); i++) { 206 DataObject dObj = (DataObject) 207 allNodes [i].getCookie(DataObject.class); 208 if ((dObj != null) && (dObj == val)) { 209 theNode = allNodes [i]; 210 } 211 } 212 } 213 } 214 215 return theNode; 216 } 217 218 protected Node findNodeForObj(Node rootNode, DataObject dObj) { 219 Node node = null; 220 DataFolder df = dObj.getFolder(); 221 Vector<DataFolder> v = new Vector<DataFolder>(); 222 while (df != null) { 223 v.addElement(df); 224 df = df.getFolder(); 225 } 226 227 if (! v.isEmpty()) { 228 Node parent = findParentNode(v, rootNode.getChildren()); 229 if (parent != null) { 230 node = findNode(parent, dObj); 231 } else { 232 node = findNode(rootNode, dObj); 233 } 234 } else { 235 node = findNode(rootNode, dObj); 236 } 237 238 return node; 239 } 240 241 protected Node findParentNode(Vector<DataFolder> v, Children children) { 242 DataFolder df = v.lastElement(); 243 244 Node n = children.findChild(df.getNodeDelegate().getName()); 246 if (n == null) { 247 Node [] nodes = children.getNodes(); 248 for (int i = 0; (i < nodes.length) && (n == null); i++) { 249 DataFolder folder = 250 (DataFolder) nodes [i].getCookie(DataFolder.class); 251 if ((folder != null) && (folder == df)) { 252 n = nodes [i]; 253 } 254 } 255 } 256 257 if (v.size() > 1) { 258 v.removeElement(df); 259 if (n != null) { 260 return findParentNode(v, n.getChildren()); 261 } else { 262 return findParentNode(v, children); 264 } 265 } 266 return n; 267 } 268 269 273 public DataObject getDataObject() { 274 return null; 275 } 276 277 281 public Node getNode() { 282 return null; 283 } 284 285 290 public Object getPropertyValue() throws IllegalStateException { 291 return getDataObject(); 292 } 293 294 protected void setOkButtonEnabled (boolean b) { 295 if (env != null) { 296 env.setState(b ? env.STATE_VALID : env.STATE_INVALID); 297 } 298 } 299 300 static class FilteredChildren extends FilterNode.Children { 301 private NodeAcceptor nodeAcceptor; 302 private DataFilter dFilter; 303 304 FilteredChildren(Node n, NodeAcceptor acceptor, DataFilter filter) { 305 super (n); 306 nodeAcceptor = acceptor; 307 dFilter = filter; 308 } 309 310 private Node [] makeFilterNode(Node n) { 311 FilteredChildren children = 312 new FilteredChildren(n, nodeAcceptor, dFilter); 313 return new Node [] { new FilterNode(n, children) }; 314 } 315 316 @Override 317 protected Node[] createNodes(Node key) { 318 if (key != null) { 319 Node[] n = new Node[] {key}; 320 if (dFilter != null) { 321 DataObject dObj = 322 (DataObject) n [0].getCookie(DataObject.class); 323 if ((dObj != null) && (dFilter.acceptDataObject(dObj))) { 324 return makeFilterNode(n [0]); 325 } 326 } 327 328 if (nodeAcceptor.acceptNodes(n)) { 329 return makeFilterNode(n [0]); 330 } 331 } 332 return new Node [0]; 333 } 334 } 335 336 } 337 | Popular Tags |