[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[news.eclipse.platform.swt] Re: Problems with TreeViewer and java.io.File.listRoots()

Karl Sand wrote:

Running my code on a Windows 2000 system i always get the "javaw.exe, no disk, no disk in floppy found" popup-window. when i click cancel or continue the popup-window disappears. I tracked this behaviour down to the use of listRoots(). But when i use java.io.File.listRoots() outside my SWT-app in a Swing application everything works as it should and there is no popup-window.

The problem is not listRoots() itself, it's calling list() on the File objects returned by listRoots(). For every node displayed in the tree, the TreeViewer calls the content provider's hasChildren() method so that it knows whether or not to display a "[+]" for expanding the node.


   public boolean hasChildren(Object arg0) {
       // Get the children
       Object[] obj = getChildren(arg0);

       // Return whether the parent has children
       return obj == null ? false : obj.length > 0;
   }

Just return true in this method. Then all nodes will initially be expandable. When you try to actually expand a node without any children, the "[+]" sign will disappear.


You could check if arg0 is one of the objects returned by listRoot() and only return true in these cases but the performance will be much better if you do it for all nodes.

--
Stefan Zeiger - Developer of Novocode Application Framework
Build SWT-based MVC GUIs via XML: http://www.novocode.com/naf/