| 1 |
/* |
| 2 |
* @(#)FileSystemTreeModel.java 9/12/2005 |
| 3 |
* |
| 4 |
* Copyright 2002 - 2005 JIDE Software Inc. All rights reserved. |
| 5 |
*/ |
| 6 |
package com.jidesoft.plaf.basic; |
| 7 |
|
| 8 |
import com.jidesoft.swing.FolderChooser; |
| 9 |
|
| 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 |
} |
| 35 |
else { |
| 36 |
return null; |
| 37 |
} |
| 38 |
} |
| 39 |
|
| 40 |
public void removePath(TreePath path, int index, Object deletedObject) { |
| 41 |
TreePath parentPath = path.getParentPath(); |
| 42 |
Object source = parentPath.getLastPathComponent(); |
| 43 |
Object[] paths = parentPath.getPath(); |
| 44 |
if (((LazyMutableTreeNode) source).isLoaded()) { |
| 45 |
((DefaultMutableTreeNode) source).remove((MutableTreeNode) deletedObject); |
| 46 |
} |
| 47 |
fireTreeNodesRemoved( |
| 48 |
source, |
| 49 |
paths, |
| 50 |
new int[]{index}, |
| 51 |
new Object[]{deletedObject}); |
| 52 |
} |
| 53 |
|
| 54 |
public void addPath(TreePath parent, int insertionIndex, Object insertedObject) { |
| 55 |
// TreePath parentPath = parent; |
| 56 |
// Object source = parentPath.getLastPathComponent(); |
| 57 |
// if (((LazyMutableTreeNode) source).isLoaded()) { |
| 58 |
// ((DefaultMutableTreeNode) source).insert((MutableTreeNode) insertedObject, insertionIndex); |
| 59 |
// } |
| 60 |
fireTreeNodesInserted(parent.getLastPathComponent(), |
| 61 |
parent.getPath(), |
| 62 |
new int[]{insertionIndex}, |
| 63 |
new Object[]{insertedObject}); |
| 64 |
} |
| 65 |
} |