Selecting an item in a tree

I have a feeling I’m missing something very simple here - hope someone can point me in the right direction.

I have created a tree which uses a FilesystemContainer as its data source. I create the tree like this:

filesystemContainer = new FilesystemContainer(new File(app.getRootPlaylistDir()));
tree = new Tree(null,filesystemContainer);
tree.setItemCaptionPropertyId(FilesystemContainer.PROPERTY_NAME);

At some point, I want to create a new file in the filesystem, and add it to the tree. This works. However, when I create the file, I do it by selecting the parent directory, and then adding the file to the file system. I would like to change the selection at that point to be the new file.

So for example, if the tree looks like:
aaaa
-----bbbb
-----------cccc

and directory ‘cccc’ is selected and I add file ‘newFile’, the tree looks like
aaaa
-----bbbb
-----------cccc
-----------------newFile

Which is correct, but I want newFile to actually be selected. How do I force that?

My code in this area looks like this, but it does not do anything except repaint the tree with the new entry - nothing is showing selected…

try{
____fw = new FileWriter(fullPath);
____fw.write(“Id=99999\n”); // Dummy id
____fw.flush();
____fw.close();
____tree.setValue(fullPath);
____tree.requestRepaint();
}

Thanks in advance,

nbc

The item IDs in a FilesystemContainer are File objects, not paths. You need to use the File object associated with the file in the setValue().

Notice that you can’t just create a new File object with the same path, that is, “tree.setValue(new File(fullPath))”, as that object would not be the same as is in the container.

You probably need to iterate over the item IDs (which are File object) of the files in the container to find the correct item ID, and then use that to set the selection.

Got it - thanks very much - that should do it…

nbc