Java ExplorerManager Filter











up vote
0
down vote

favorite












I have implemented https://blogs.oracle.com/geertjan/file-browser to show only folders (changed == in accept() to !=). However, no matter what I have done it only calls the FileFilterNodeChildren for the first level, the children of the root node. So what I get is the folders of the root node (the directory I want) but it show ALL files and folders below this level. I have put in statements that verify that the filter function is only called for the first level.



What do I need to do to filter the children of the first level and below?










share|improve this question




















  • 1




    I'm not quite sure I understand what you're after. Do you want to only see the folders of the first level? Do you want to see folders only on any level? And did you step through your code with a debugger to see where it goes wrong? That's typically the best way to learn something about the code you copied.
    – Thomas
    Aug 24 at 15:53












  • I want to see only folders, at whatever level. I do not want to see any files in this Explorer.
    – Val K
    Aug 24 at 16:03












  • Note that the classes being used (e.g. DataFolder) are not basic JDK classes and thus I can't help you with the specifics of that library. However, it seems that if you check for ` node.getLookup().lookup(DataFolder.class) != null` this might mean something different than "it is a folder". You'd need to read up on what lookup is doing to better understand what's going on. Just copy-paste won't help you in the long run.
    – Thomas
    Aug 24 at 16:18










  • Replying to Thomas: I put a breakpoint on the accept function. For the four directories at the first level (below the root) the accept function is called twice. That is, accept() is called for each of the four directories, then it is called again for each of the four directories. It is not called for any of the files or directories below the first level directories. I added a System.out.print for each of the node.getDisplayName() so that I could tell which directories it was being called on.
    – Val K
    Aug 24 at 16:25















up vote
0
down vote

favorite












I have implemented https://blogs.oracle.com/geertjan/file-browser to show only folders (changed == in accept() to !=). However, no matter what I have done it only calls the FileFilterNodeChildren for the first level, the children of the root node. So what I get is the folders of the root node (the directory I want) but it show ALL files and folders below this level. I have put in statements that verify that the filter function is only called for the first level.



What do I need to do to filter the children of the first level and below?










share|improve this question




















  • 1




    I'm not quite sure I understand what you're after. Do you want to only see the folders of the first level? Do you want to see folders only on any level? And did you step through your code with a debugger to see where it goes wrong? That's typically the best way to learn something about the code you copied.
    – Thomas
    Aug 24 at 15:53












  • I want to see only folders, at whatever level. I do not want to see any files in this Explorer.
    – Val K
    Aug 24 at 16:03












  • Note that the classes being used (e.g. DataFolder) are not basic JDK classes and thus I can't help you with the specifics of that library. However, it seems that if you check for ` node.getLookup().lookup(DataFolder.class) != null` this might mean something different than "it is a folder". You'd need to read up on what lookup is doing to better understand what's going on. Just copy-paste won't help you in the long run.
    – Thomas
    Aug 24 at 16:18










  • Replying to Thomas: I put a breakpoint on the accept function. For the four directories at the first level (below the root) the accept function is called twice. That is, accept() is called for each of the four directories, then it is called again for each of the four directories. It is not called for any of the files or directories below the first level directories. I added a System.out.print for each of the node.getDisplayName() so that I could tell which directories it was being called on.
    – Val K
    Aug 24 at 16:25













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I have implemented https://blogs.oracle.com/geertjan/file-browser to show only folders (changed == in accept() to !=). However, no matter what I have done it only calls the FileFilterNodeChildren for the first level, the children of the root node. So what I get is the folders of the root node (the directory I want) but it show ALL files and folders below this level. I have put in statements that verify that the filter function is only called for the first level.



What do I need to do to filter the children of the first level and below?










share|improve this question















I have implemented https://blogs.oracle.com/geertjan/file-browser to show only folders (changed == in accept() to !=). However, no matter what I have done it only calls the FileFilterNodeChildren for the first level, the children of the root node. So what I get is the folders of the root node (the directory I want) but it show ALL files and folders below this level. I have put in statements that verify that the filter function is only called for the first level.



What do I need to do to filter the children of the first level and below?







java netbeans netbeans-platform filefilter






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Aug 30 at 14:45

























asked Aug 24 at 15:50









Val K

13




13








  • 1




    I'm not quite sure I understand what you're after. Do you want to only see the folders of the first level? Do you want to see folders only on any level? And did you step through your code with a debugger to see where it goes wrong? That's typically the best way to learn something about the code you copied.
    – Thomas
    Aug 24 at 15:53












  • I want to see only folders, at whatever level. I do not want to see any files in this Explorer.
    – Val K
    Aug 24 at 16:03












  • Note that the classes being used (e.g. DataFolder) are not basic JDK classes and thus I can't help you with the specifics of that library. However, it seems that if you check for ` node.getLookup().lookup(DataFolder.class) != null` this might mean something different than "it is a folder". You'd need to read up on what lookup is doing to better understand what's going on. Just copy-paste won't help you in the long run.
    – Thomas
    Aug 24 at 16:18










  • Replying to Thomas: I put a breakpoint on the accept function. For the four directories at the first level (below the root) the accept function is called twice. That is, accept() is called for each of the four directories, then it is called again for each of the four directories. It is not called for any of the files or directories below the first level directories. I added a System.out.print for each of the node.getDisplayName() so that I could tell which directories it was being called on.
    – Val K
    Aug 24 at 16:25














  • 1




    I'm not quite sure I understand what you're after. Do you want to only see the folders of the first level? Do you want to see folders only on any level? And did you step through your code with a debugger to see where it goes wrong? That's typically the best way to learn something about the code you copied.
    – Thomas
    Aug 24 at 15:53












  • I want to see only folders, at whatever level. I do not want to see any files in this Explorer.
    – Val K
    Aug 24 at 16:03












  • Note that the classes being used (e.g. DataFolder) are not basic JDK classes and thus I can't help you with the specifics of that library. However, it seems that if you check for ` node.getLookup().lookup(DataFolder.class) != null` this might mean something different than "it is a folder". You'd need to read up on what lookup is doing to better understand what's going on. Just copy-paste won't help you in the long run.
    – Thomas
    Aug 24 at 16:18










  • Replying to Thomas: I put a breakpoint on the accept function. For the four directories at the first level (below the root) the accept function is called twice. That is, accept() is called for each of the four directories, then it is called again for each of the four directories. It is not called for any of the files or directories below the first level directories. I added a System.out.print for each of the node.getDisplayName() so that I could tell which directories it was being called on.
    – Val K
    Aug 24 at 16:25








1




1




I'm not quite sure I understand what you're after. Do you want to only see the folders of the first level? Do you want to see folders only on any level? And did you step through your code with a debugger to see where it goes wrong? That's typically the best way to learn something about the code you copied.
– Thomas
Aug 24 at 15:53






I'm not quite sure I understand what you're after. Do you want to only see the folders of the first level? Do you want to see folders only on any level? And did you step through your code with a debugger to see where it goes wrong? That's typically the best way to learn something about the code you copied.
– Thomas
Aug 24 at 15:53














I want to see only folders, at whatever level. I do not want to see any files in this Explorer.
– Val K
Aug 24 at 16:03






I want to see only folders, at whatever level. I do not want to see any files in this Explorer.
– Val K
Aug 24 at 16:03














Note that the classes being used (e.g. DataFolder) are not basic JDK classes and thus I can't help you with the specifics of that library. However, it seems that if you check for ` node.getLookup().lookup(DataFolder.class) != null` this might mean something different than "it is a folder". You'd need to read up on what lookup is doing to better understand what's going on. Just copy-paste won't help you in the long run.
– Thomas
Aug 24 at 16:18




Note that the classes being used (e.g. DataFolder) are not basic JDK classes and thus I can't help you with the specifics of that library. However, it seems that if you check for ` node.getLookup().lookup(DataFolder.class) != null` this might mean something different than "it is a folder". You'd need to read up on what lookup is doing to better understand what's going on. Just copy-paste won't help you in the long run.
– Thomas
Aug 24 at 16:18












Replying to Thomas: I put a breakpoint on the accept function. For the four directories at the first level (below the root) the accept function is called twice. That is, accept() is called for each of the four directories, then it is called again for each of the four directories. It is not called for any of the files or directories below the first level directories. I added a System.out.print for each of the node.getDisplayName() so that I could tell which directories it was being called on.
– Val K
Aug 24 at 16:25




Replying to Thomas: I put a breakpoint on the accept function. For the four directories at the first level (below the root) the accept function is called twice. That is, accept() is called for each of the four directories, then it is called again for each of the four directories. It is not called for any of the files or directories below the first level directories. I added a System.out.print for each of the node.getDisplayName() so that I could tell which directories it was being called on.
– Val K
Aug 24 at 16:25












1 Answer
1






active

oldest

votes

















up vote
0
down vote













Inside of createNodes() you need to wrap the child nodes with instances of FileFilterNode. Here is a revised version of createNodes():



@Override
protected Node createNodes(Node object) {
List<Node> result = new ArrayList<Node>();
for (Node node : super.createNodes(object)) {
if (accept(node)) {
// This is the only changed line
result.add(new FileFilterNode(node));
}
}
return result.toArray(new Node[0]);
}


This was tested in NetBeans 8.2 on Windows and works as expected. The "File Browser" displays a tree containing only folders at all levels.






share|improve this answer























  • Okay, this works to get the filter called for nodes below the first level. However, when I try to filter out non-directory nodes (i.e.: files) then it causes other problems. These problems are difficult to describe and are better experienced. I will be using jtree instead of bean tree because it allows me to build the tree instead of it building the tree. Thanks for everyone's help.
    – Val K
    Nov 7 at 18:24












  • I tested it on Windows with NetBeans 8.2 just now and it seems to work fine. I'm curious what the other problems are.
    – Corey
    Nov 7 at 18:55










  • I just tested it on Linux using NetBeans 9.0.1. When I expand the final directory it "silently" throws an exception. (i.e.: I see the exception information in the debugger but not in the GUI.) On all others when I expand it I see a "blank" document for each of the files filtered out, an exception is thrown in the debugger for each and every one of those files, then when it is done with this (because throwing the exceptions takes time) the "blank" documents disappear and the tree appears how I expect it to be. By "blank" I mean that the document icon is shown with no name.
    – Val K
    Nov 13 at 16:35











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f52007913%2fjava-explorermanager-filter%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
0
down vote













Inside of createNodes() you need to wrap the child nodes with instances of FileFilterNode. Here is a revised version of createNodes():



@Override
protected Node createNodes(Node object) {
List<Node> result = new ArrayList<Node>();
for (Node node : super.createNodes(object)) {
if (accept(node)) {
// This is the only changed line
result.add(new FileFilterNode(node));
}
}
return result.toArray(new Node[0]);
}


This was tested in NetBeans 8.2 on Windows and works as expected. The "File Browser" displays a tree containing only folders at all levels.






share|improve this answer























  • Okay, this works to get the filter called for nodes below the first level. However, when I try to filter out non-directory nodes (i.e.: files) then it causes other problems. These problems are difficult to describe and are better experienced. I will be using jtree instead of bean tree because it allows me to build the tree instead of it building the tree. Thanks for everyone's help.
    – Val K
    Nov 7 at 18:24












  • I tested it on Windows with NetBeans 8.2 just now and it seems to work fine. I'm curious what the other problems are.
    – Corey
    Nov 7 at 18:55










  • I just tested it on Linux using NetBeans 9.0.1. When I expand the final directory it "silently" throws an exception. (i.e.: I see the exception information in the debugger but not in the GUI.) On all others when I expand it I see a "blank" document for each of the files filtered out, an exception is thrown in the debugger for each and every one of those files, then when it is done with this (because throwing the exceptions takes time) the "blank" documents disappear and the tree appears how I expect it to be. By "blank" I mean that the document icon is shown with no name.
    – Val K
    Nov 13 at 16:35















up vote
0
down vote













Inside of createNodes() you need to wrap the child nodes with instances of FileFilterNode. Here is a revised version of createNodes():



@Override
protected Node createNodes(Node object) {
List<Node> result = new ArrayList<Node>();
for (Node node : super.createNodes(object)) {
if (accept(node)) {
// This is the only changed line
result.add(new FileFilterNode(node));
}
}
return result.toArray(new Node[0]);
}


This was tested in NetBeans 8.2 on Windows and works as expected. The "File Browser" displays a tree containing only folders at all levels.






share|improve this answer























  • Okay, this works to get the filter called for nodes below the first level. However, when I try to filter out non-directory nodes (i.e.: files) then it causes other problems. These problems are difficult to describe and are better experienced. I will be using jtree instead of bean tree because it allows me to build the tree instead of it building the tree. Thanks for everyone's help.
    – Val K
    Nov 7 at 18:24












  • I tested it on Windows with NetBeans 8.2 just now and it seems to work fine. I'm curious what the other problems are.
    – Corey
    Nov 7 at 18:55










  • I just tested it on Linux using NetBeans 9.0.1. When I expand the final directory it "silently" throws an exception. (i.e.: I see the exception information in the debugger but not in the GUI.) On all others when I expand it I see a "blank" document for each of the files filtered out, an exception is thrown in the debugger for each and every one of those files, then when it is done with this (because throwing the exceptions takes time) the "blank" documents disappear and the tree appears how I expect it to be. By "blank" I mean that the document icon is shown with no name.
    – Val K
    Nov 13 at 16:35













up vote
0
down vote










up vote
0
down vote









Inside of createNodes() you need to wrap the child nodes with instances of FileFilterNode. Here is a revised version of createNodes():



@Override
protected Node createNodes(Node object) {
List<Node> result = new ArrayList<Node>();
for (Node node : super.createNodes(object)) {
if (accept(node)) {
// This is the only changed line
result.add(new FileFilterNode(node));
}
}
return result.toArray(new Node[0]);
}


This was tested in NetBeans 8.2 on Windows and works as expected. The "File Browser" displays a tree containing only folders at all levels.






share|improve this answer














Inside of createNodes() you need to wrap the child nodes with instances of FileFilterNode. Here is a revised version of createNodes():



@Override
protected Node createNodes(Node object) {
List<Node> result = new ArrayList<Node>();
for (Node node : super.createNodes(object)) {
if (accept(node)) {
// This is the only changed line
result.add(new FileFilterNode(node));
}
}
return result.toArray(new Node[0]);
}


This was tested in NetBeans 8.2 on Windows and works as expected. The "File Browser" displays a tree containing only folders at all levels.







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 7 at 18:54

























answered Oct 23 at 16:44









Corey

538514




538514












  • Okay, this works to get the filter called for nodes below the first level. However, when I try to filter out non-directory nodes (i.e.: files) then it causes other problems. These problems are difficult to describe and are better experienced. I will be using jtree instead of bean tree because it allows me to build the tree instead of it building the tree. Thanks for everyone's help.
    – Val K
    Nov 7 at 18:24












  • I tested it on Windows with NetBeans 8.2 just now and it seems to work fine. I'm curious what the other problems are.
    – Corey
    Nov 7 at 18:55










  • I just tested it on Linux using NetBeans 9.0.1. When I expand the final directory it "silently" throws an exception. (i.e.: I see the exception information in the debugger but not in the GUI.) On all others when I expand it I see a "blank" document for each of the files filtered out, an exception is thrown in the debugger for each and every one of those files, then when it is done with this (because throwing the exceptions takes time) the "blank" documents disappear and the tree appears how I expect it to be. By "blank" I mean that the document icon is shown with no name.
    – Val K
    Nov 13 at 16:35


















  • Okay, this works to get the filter called for nodes below the first level. However, when I try to filter out non-directory nodes (i.e.: files) then it causes other problems. These problems are difficult to describe and are better experienced. I will be using jtree instead of bean tree because it allows me to build the tree instead of it building the tree. Thanks for everyone's help.
    – Val K
    Nov 7 at 18:24












  • I tested it on Windows with NetBeans 8.2 just now and it seems to work fine. I'm curious what the other problems are.
    – Corey
    Nov 7 at 18:55










  • I just tested it on Linux using NetBeans 9.0.1. When I expand the final directory it "silently" throws an exception. (i.e.: I see the exception information in the debugger but not in the GUI.) On all others when I expand it I see a "blank" document for each of the files filtered out, an exception is thrown in the debugger for each and every one of those files, then when it is done with this (because throwing the exceptions takes time) the "blank" documents disappear and the tree appears how I expect it to be. By "blank" I mean that the document icon is shown with no name.
    – Val K
    Nov 13 at 16:35
















Okay, this works to get the filter called for nodes below the first level. However, when I try to filter out non-directory nodes (i.e.: files) then it causes other problems. These problems are difficult to describe and are better experienced. I will be using jtree instead of bean tree because it allows me to build the tree instead of it building the tree. Thanks for everyone's help.
– Val K
Nov 7 at 18:24






Okay, this works to get the filter called for nodes below the first level. However, when I try to filter out non-directory nodes (i.e.: files) then it causes other problems. These problems are difficult to describe and are better experienced. I will be using jtree instead of bean tree because it allows me to build the tree instead of it building the tree. Thanks for everyone's help.
– Val K
Nov 7 at 18:24














I tested it on Windows with NetBeans 8.2 just now and it seems to work fine. I'm curious what the other problems are.
– Corey
Nov 7 at 18:55




I tested it on Windows with NetBeans 8.2 just now and it seems to work fine. I'm curious what the other problems are.
– Corey
Nov 7 at 18:55












I just tested it on Linux using NetBeans 9.0.1. When I expand the final directory it "silently" throws an exception. (i.e.: I see the exception information in the debugger but not in the GUI.) On all others when I expand it I see a "blank" document for each of the files filtered out, an exception is thrown in the debugger for each and every one of those files, then when it is done with this (because throwing the exceptions takes time) the "blank" documents disappear and the tree appears how I expect it to be. By "blank" I mean that the document icon is shown with no name.
– Val K
Nov 13 at 16:35




I just tested it on Linux using NetBeans 9.0.1. When I expand the final directory it "silently" throws an exception. (i.e.: I see the exception information in the debugger but not in the GUI.) On all others when I expand it I see a "blank" document for each of the files filtered out, an exception is thrown in the debugger for each and every one of those files, then when it is done with this (because throwing the exceptions takes time) the "blank" documents disappear and the tree appears how I expect it to be. By "blank" I mean that the document icon is shown with no name.
– Val K
Nov 13 at 16:35


















 

draft saved


draft discarded



















































 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f52007913%2fjava-explorermanager-filter%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







這個網誌中的熱門文章

Tangent Lines Diagram Along Smooth Curve

Yusuf al-Mu'taman ibn Hud

Zucchini