Is TreeModel really as bad as I think?

When I first saw it javax.swing.tree.TreeModel, I thought that writing a lot of methods is a lot of work. Then I found DefaultTreeModeland thought that it would be easy to use for the file tree through the adapter template. So I started writing an adapter and it seems to have failed. I need to have access to the corresponding file specified TreeNode(which is easy, since it can be an instance variable), but I need and vice versa. This can be solved using a card, but it consumes quite a lot of memory. The transition to WeakHashMaphelped.

It worked, but I ran into some strange problems when the tree changed. In addition, all this was very slow, as File.list()received many times. There are some stupid methods, such as getChildCount(), getChild(Object parent, int index)and getIndexOfChild(Object parent, Object child), and in my naive implementation, every call leads to a directory reading.

Everything was pretty much and the result was terrible. Of course, it’s my fault, but wasn’t this a direct result of using the erroneous complex model?

This would not happen if there was one method, for example List getChildren(Object). Perhaps I did everything wrong, what's right?

Finally, I wrote MyCachingTreeModel implements TreeModelwith an adapter for each class that solved all this. But I'm still curious how otherwise this could be allowed.

Update:

, . :

TreeModel , ?

, . , .

+3
3

( :)

TreeModel , ?

, JTree, . , (= JTree) , - , , . , , , Thread. , , , ( getValue()).

, : , , " ". , , . , , , - .

, , - , , , , ( ) .


( --:)

API TreeModel ( Swing), Framework Framework . , ( ) Swing.

+1

API , - File.list() . , , , , , , , , , .

, API, .:)

+1

Also: consider the NetBeans platform and their Node and Explorer APIs>

0
source

Source: https://habr.com/ru/post/1790039/


All Articles