ITreeContentProvider with java.nio.file.Path; [message #1851047] |
Fri, 25 March 2022 15:50  |
Eclipse User |
|
|
|
Hello
I'm new to the Eclipse platform and RCP, and started with the Lars Vogel and Packt books on the topic. There they treat the TreeViewer content provider with the FIle class (java,io.file). I want to tray with the new java.nio.file package. However, after executing the getElements routine, the next one, hasChildren isn't called if output from the previous one is Path[] class type, but for File[] works okay.
public class FileProvider implements ITreeContentProvider, IResourceChangeListener{
@Override
public Object[] getElements(Object inputElement) {
Path[] paths;
if (inputElement instanceof Object) {
try {
paths = Files.list((Path) inputElement).toArray(Path[]::new);
} catch (IOException e) {
// TODO Auto-generated catch block
paths = new Path[0];
e.printStackTrace();
}
} else {
//Do nothing, as long as only input is from Path class
paths = new Path[0];
}
return paths;
}
Anyone know why ?
|
|
|
|
|
|
Re: ITreeContentProvider with java.nio.file.Path; [message #1851051 is a reply to message #1851048] |
Fri, 25 March 2022 16:52   |
Eclipse User |
|
|
|
Hard to say as there are many fields. But mostly is populated with paths of files in the selected workspace. For instance I've added a simple print, right before return, to check that I have the expected data there to work with and it;s okay, the array is populated with what files I have (ex : b.txt)
for (int i = 0; i < paths.length; i++) {
System.out.println(paths[i].getFileName());
}
Attachment: Captură.PNG
(Size: 32.29KB, Downloaded 150 times)
|
|
|
|
Re: ITreeContentProvider with java.nio.file.Path; [message #1851203 is a reply to message #1851056] |
Wed, 30 March 2022 13:30  |
Eclipse User |
|
|
|
Followed advice, was hoping for a quick solution. Problem came from my side. In my original understanding, I thought that after getElements() function, the next one to be called is the hasChildren(). Not true for me, because I had a comparator functionality implemented. And that one wasn't handling the Path class, but the File class.
|
|
|
Powered by
FUDForum. Page generated in 0.03647 seconds