Skip to main content

This CGIT instance is deprecated, and repositories have been moved to Gitlab or Github. See the repository descriptions for specific locations.

summaryrefslogtreecommitdiffstats
blob: be02256d1edf04c89ac35c54d546ed96b04c1e3e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/*******************************************************************************
 * Copyright (c) 2002-2005 IBM Corporation and others.
 * All rights reserved.   This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *   IBM - Initial API and implementation
 *******************************************************************************/
package org.eclipse.wst.wsi.ui.internal;

import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.viewers.ViewerFilter;

import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;

import java.util.Collection;

public class ResourceFilter extends ViewerFilter 
{
  protected String[] fExtensions;
  protected IFile[] fExcludedFiles;
  protected Collection fExcludes;
	
  public ResourceFilter(String[] extensions, Collection exclude) 
  {
    fExtensions= extensions;
    fExcludes= exclude;
    fExcludedFiles = null;
  }

  public ResourceFilter(String[] extensions, IFile[] excludedFiles, Collection exclude) 
  {
    fExtensions= extensions;
    fExcludes= exclude;
    fExcludedFiles = excludedFiles;
  }
	
  public boolean isFilterProperty(Object element, Object property) 
  {
    return false;
  }
	
  public boolean select(Viewer viewer, Object parent, Object element) 
  {
    if (element instanceof IFile) 
    {
      if (fExcludes != null && fExcludes.contains(element)) 
      {
	return false;
      }
      String name= ((IFile)element).getName();
      if (fExcludedFiles != null) 
      {
        for (int j= 0; j < fExcludedFiles.length; j++) 
        {
          if ( ((IFile)element).getLocation().
               toString().compareTo(((IFile)fExcludedFiles[j]).getLocation().toString()) == 0 )
           return false;             
        }            
      }
      if (fExtensions.length == 0) 
      {
        // assume that we don't want to filter any files based on 
        // extension
        return true;
      }
      for (int i= 0; i < fExtensions.length; i++) 
      {
        if (name.endsWith(fExtensions[i]))
        {
          return true;
        }
      } 
      return false;
    } 
    else if (element instanceof IContainer) 
    { // IProject, IFolder
      try 
      {
      	IResource[] resources= ((IContainer)element).members();
	for (int i= 0; i < resources.length; i++) 
        {
	  // recursive!
	  if (select(viewer, parent, resources[i])) 
          {
	    return true;
	  }
	}
      } 
      catch (CoreException e) 
      {
      }				
    }
    return false;
  }
}

Back to the top