Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » ITreeContentProvider with java.nio.file.Path;(Trying to provide content to a TreeViewer using Path class type)
ITreeContentProvider with java.nio.file.Path; [message #1851047] Fri, 25 March 2022 15:50 Go to next message
Eclipse UserFriend
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 #1851048 is a reply to message #1851047] Fri, 25 March 2022 16:07 Go to previous messageGo to next message
Eclipse UserFriend
What are you returning from this method when you find that hasChildren isn't being called--what's in the array?
Re: ITreeContentProvider with java.nio.file.Path; [message #1851049 is a reply to message #1851048] Fri, 25 March 2022 16:27 Go to previous messageGo to next message
Eclipse UserFriend
Probably your code throws a ClassCastException, which is not caught properly.

Hint:
inputElement instanceof Object
is always true.
Re: ITreeContentProvider with java.nio.file.Path; [message #1851050 is a reply to message #1851049] Fri, 25 March 2022 16:48 Go to previous messageGo to next message
Eclipse UserFriend
No exception. I've added a simple print in the catch block and it doesn't show.
  • Attachment: Captură.PNG
    (Size: 32.29KB, Downloaded 142 times)
Re: ITreeContentProvider with java.nio.file.Path; [message #1851051 is a reply to message #1851048] Fri, 25 March 2022 16:52 Go to previous messageGo to next message
Eclipse UserFriend
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 #1851056 is a reply to message #1851051] Fri, 25 March 2022 18:29 Go to previous messageGo to next message
Eclipse UserFriend
The debugger is your best friend. It can answer every question faster than posting a question to a forum.
Re: ITreeContentProvider with java.nio.file.Path; [message #1851203 is a reply to message #1851056] Wed, 30 March 2022 13:30 Go to previous message
Eclipse UserFriend
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.
Previous Topic:[ Eclipse 22/03 R ] Eclipse 'Project Explorer View' doesn't show Errors
Next Topic:URI Scheme handler without SWT
Goto Forum:
  


Current Time: Thu Feb 13 04:30:43 GMT 2025

Powered by FUDForum. Page generated in 0.03647 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top