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

Hi,
In my SWT-app i make use of the JFace TreeViewer class. I want to be able
to browse my filesystem beginning with the filesystem root in a tree-view. To get the filesystem root i use the java.io.File.listRoots()-method.
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.
Does anybody know about an issue regarding listRoots(), SWT/JFace and Windows 2000? Is there an alternative to get the filesystem root WITHOUT user interaction? If somebody wants to reproduce this bug, here is the relevant code :



import java.io.File;

import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.window.ApplicationWindow;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

/**
* This class demonstrates the CheckboxTreeViewer
*/

/**
* This class demonstrates TreeViewer. It shows the drives, directories, and
* files on the system.
*/


public class FileTree extends ApplicationWindow {

   /**
    * FileTree constructor
    */
   public FileTree() {
       super(null);
   }

/**
* The application entry point
* * @param args
* the command line arguments
*/
public static void main(String[] args) {
new FileTree().run();
}


   /**
    * Runs the application
    */
   public void run() {
       // Don't return from open() until window closes
       setBlockOnOpen(true);

       // Open the main window
       open();

       // Dispose the display
       Display.getCurrent().dispose();
   }

/**
* Configures the shell
* * @param shell
* the shell
*/
protected void configureShell(Shell shell) {
super.configureShell(shell);


       // Set the title bar text and the size
       shell.setText("File Tree");
       shell.setSize(400, 400);
   }

/**
* Creates the main window's contents
* * @param parent
* the main window
* @return Control
*/
protected Control createContents(Composite parent) {
Composite composite = new Composite(parent, SWT.NONE);
composite.setLayout(new GridLayout(1, false));


       // Add a checkbox to toggle whether the labels preserve case
       Button preserveCase = new Button(composite, SWT.CHECK);
       preserveCase.setText("&Preserve case");

       // Create the tree viewer to display the file tree
       final TreeViewer tv = new TreeViewer(composite);
       tv.getTree().setLayoutData(new GridData(GridData.FILL_BOTH));
       tv.setContentProvider(new FileTreeContentProvider());
       tv.setInput("root"); // pass a non-null that will be ignored

       return composite;
   }

}

/**
* This class provides the content for the tree in FileTree
*/

class FileTreeContentProvider implements ITreeContentProvider {
/**
* Gets the children of the specified object
* * @param arg0
* the parent object
* @return Object[]
*/
public Object[] getChildren(Object arg0) {
// Return the files and subdirectories in this directory
return ((File) arg0).listFiles();
}


/**
* Gets the parent of the specified object
* * @param arg0
* the object
* @return Object
*/
public Object getParent(Object arg0) {
// Return this file's parent file
return ((File) arg0).getParentFile();
}


/**
* Returns whether the passed object has children
* * @param arg0
* the parent object
* @return boolean
*/
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;
   }

/**
* Gets the root element(s) of the tree
* * @param arg0
* the input data
* @return Object[]
*/
public Object[] getElements(Object arg0) {
// These are the root elements of the tree
// We don't care what arg0 is, because we just want all
// the root nodes in the file system
// Here comes the criticial listRoots()-method!!!
return File.listRoots();
}


   /**
    * Disposes any created resources
    */
   public void dispose() {
       // Nothing to dispose
   }

public void inputChanged(Viewer arg0, Object arg1, Object arg2) {
// TODO Methode FileTreeContentProvider.inputChanged implementieren
}


}