01: /*
02: * @(#)FileSystemTreeModel.java 9/12/2005
03: *
04: * Copyright 2002 - 2005 JIDE Software Inc. All rights reserved.
05: */
06: package com.jidesoft.plaf.basic;
07:
08: import com.jidesoft.swing.FolderChooser;
09:
10: import javax.swing.filechooser.FileSystemView;
11: import javax.swing.tree.DefaultMutableTreeNode;
12: import javax.swing.tree.DefaultTreeModel;
13: import javax.swing.tree.MutableTreeNode;
14: import javax.swing.tree.TreePath;
15:
16: class BasicFileSystemTreeModel extends DefaultTreeModel {
17: private FileSystemView _fileSystemView;
18:
19: public BasicFileSystemTreeModel(FolderChooser folderChooser) {
20: super (new MyComputerTreeNode(folderChooser));
21: }
22:
23: public FileSystemView getFileSystemView() {
24: if (_fileSystemView == null) {
25: _fileSystemView = FileSystemView.getFileSystemView();
26: }
27: return _fileSystemView;
28: }
29:
30: @Override
31: public Object getChild(Object parent, int index) {
32: if (parent instanceof DefaultMutableTreeNode) {
33: return ((DefaultMutableTreeNode) parent).getChildAt(index);
34: } else {
35: return null;
36: }
37: }
38:
39: public void removePath(TreePath path, int index,
40: Object deletedObject) {
41: TreePath parentPath = path.getParentPath();
42: Object source = parentPath.getLastPathComponent();
43: Object[] pathes = parentPath.getPath();
44: if (((LazyMutableTreeNode) source).isLoaded()) {
45: ((DefaultMutableTreeNode) source)
46: .remove((MutableTreeNode) deletedObject);
47: }
48: fireTreeNodesRemoved(source, pathes, new int[] { index },
49: new Object[] { deletedObject });
50: }
51:
52: public void addPath(TreePath parent, int insertionIndex,
53: Object insertedObject) {
54: // TreePath parentPath = parent;
55: // Object source = parentPath.getLastPathComponent();
56: // if (((LazyMutableTreeNode) source).isLoaded()) {
57: // ((DefaultMutableTreeNode) source).insert((MutableTreeNode) insertedObject, insertionIndex);
58: // }
59: fireTreeNodesInserted(parent.getLastPathComponent(), parent
60: .getPath(), new int[] { insertionIndex },
61: new Object[] { insertedObject });
62: }
63: }
|