Problems with a File system browser

View: New views
1 Messages — Rating Filter:   Alert me  

Problems with a File system browser

by Alejandro Murillo :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


I created a simple  Top Component (in the explorer area) that shows the contents (tree view) of a given directory:

private FileSystemBrowserTopComponent() {
        initComponents();  // view = new BeanTreeView();
        setName(NbBundle.getMessage(FileSystemBrowserTopComponent.class, "CTL_FileSystemBrowserTopComponent"));
        setToolTipText(NbBundle.getMessage(FileSystemBrowserTopComponent.class, "HINT_FileSystemBrowserTopComponent"));
        setIcon(Utilities.loadImage(ICON_PATH, true));
       
        explorerManager.setRootContext(getFileSystemRootNode());   // SEE below
        explorerManager.getRootContext().setDisplayName("Root Node");

        //  -- Activate Actions

        ActionMap map = getActionMap();
        map.put(DefaultEditorKit.copyAction, ExplorerUtils.actionCopy(explorerManager));
        map.put(DefaultEditorKit.cutAction, ExplorerUtils.actionCut(explorerManager));
        map.put(DefaultEditorKit.pasteAction, ExplorerUtils.actionPaste(explorerManager));
        map.put("delete", ExplorerUtils.actionDelete(explorerManager, true));
       
        associateLookup(ExplorerUtils.createLookup(explorerManager, getActionMap()));
}

private Node getFileSystemRootNode() {
        //
        //  -- File System
        //
       
        LocalFileSystem fileSystem = new LocalFileSystem();
       
        try {
            fileSystem.setRootDirectory(new File(dirname));
        } catch (PropertyVetoException ex) {
            ex.printStackTrace();
        } catch (IOException ex) {
            ex.printStackTrace();
        }
       
       
        //
        //  -- Returns the associated Node of the file system as the Root node
        //
       
        try {           
            return DataObject.find(fileSystem.getRoot()).getNodeDelegate();
           
        } catch (DataObjectNotFoundException ex) {
            ex.printStackTrace();
        }
       
        return null;
}


Everything works fine, except for these 2 problems:

(1) When I open or double click on a given file of the tree it gets displayed on the editor, but the content of the file is not shown immediately,
I only see the tab with the file name, but no the contents of the file. I have to click again on the file name to see the content (or swithc to another tab and comeback),
 any one knows what's wrong here?

(2) If I open a file, then close the app and then restart it, the content of the file is still in the editor (as desired), but if I open the file again from the explorer (double click on it)
it opens a new instance of the same file in the editor, so I end up with 2 views of the same file in the editor. What do I need to do so that it reuses the previous view (like  the IDE does)

Thanks
Alejandro
LightInTheBox - Buy quality products at wholesale price