title: ITreeContentProvider - How to filter files while still showing parent folder?
body: <p>I am currently trying to implement a <code>SWT</code> <code>CheckBoxTreeViewer</code> for my project. However, I am currently running into some problems with the file filtering.</p>
  
  <p>I want my tree to show all files in a directory (including subdirectories) with a specific file extension (such as "txt") as well as their parent folders.</p>
  
  <p>For example:</p>
  
  <pre><code>parentA
     childA1.txt
     childA2.txt
  parentB
     childB1.txt
  </code></pre>
  
  <p>However, I can't figure out a way how to do this. I've tried several ways of coding the <code>FileFilter</code> as follows:</p>
  
  <pre><code>class FileTreeContentProvider implements ITreeContentProvider {
  
        public Object[] getChildren(Object arg0) {
          return ((File) arg0).listFiles();
        }
  
        public Object getParent(Object arg0) {
          return ((File) arg0).getParentFile();       
        }
  
        public boolean hasChildren(Object arg0) {
          Object[] obj = getChildren(arg0);
          return obj == null ? false : obj.length &gt; 0;
        }
  ...
  </code></pre>
  
  <p>1) </p>
  
  <pre><code> ...
     public Object[] getElements(Object arg0) {
        IWorkspace workspace = ResourcesPlugin.getWorkspace();
        File workspaceDirectory = workspace.getRoot().getLocation().toFile();
        String[] extension = new String[] {"txt"};
        Collection&lt;File&gt; files = FileUtils.listFiles(workspaceDirectory, extension, true);
        File[] files2 = new File[files.size()];
        int i = 0;
        for(File file : files) {
           files2[i] = file;
           i++;
        }
        return files2;
     }
     ...
  }
  </code></pre>
  
  <p>The problem with this is that it only shows the files with the file extension but not its parent directories.
  For example: </p>
  
  <pre><code>childA1.txt
  childA2.txt
  childB1.txt
  </code></pre>
  
  <p>2)</p>
  
  <pre><code>...
     public Object[] getElements(Object arg0) {
        IWorkspace workspace = ResourcesPlugin.getWorkspace();
        File workspaceDirectory = workspace.getRoot().getLocation().toFile();
        return workspaceDirectory.listFiles(new FilenameFilter() {
           @Override
           public boolean accept(File workspaceDirectory, String name) {
              if (workspaceDirectory.getName().startsWith(".") {
                 return false;
              }
              else {
                 return true;
              }
           }
        });
     }
     ...
  }
  </code></pre>
  
  <p>This snippet removes the folders starting with "." in the root directory, but does not remove the files starting with "." in the subdirectories. Therefore, I got something like this:</p>
  
  <pre><code>parentA
     .project
     .settings
     childA1.txt
     childA2.txt
  ...
  </code></pre>
  
  <p>Also, as it does not explicitly filter in just files ending in "txt", if I were to put other file types in the workspace folder I would also see those files in the tree which is not something I want.</p>
  
  <p>Is there anyway to fix this? I am using Eclipse Mars 4.5.1.</p>