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
|
/*******************************************************************************
* Copyright (c) 2004, 2010 QNX Software Systems and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* QNX Software Systems - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.internal.ui.dialogs.cpaths;
import java.util.Arrays;
import java.util.List;
import org.eclipse.cdt.core.model.IPathEntry;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.viewers.ViewerFilter;
/**
* Viewer filter for archive selection dialogs. Archives are files with file extension '.so', '.dll' and '.a'. The filter is not
* case sensitive.
*/
public class CPElementFilter extends ViewerFilter {
protected List<Object> fExcludes;
protected int[] fKind;
protected boolean fExportedOnly;
protected boolean fShowInherited;
/**
* @param excludedElements
* Excluded paths will not pass the filter. <code>null</code> is allowed if no files should be excluded.
*/
public CPElementFilter(Object[] excludedElements, int[] kind, boolean exportedOnly, boolean showInherited) {
if (excludedElements != null) {
fExcludes = Arrays.asList(excludedElements);
}
fKind = kind;
fExportedOnly = exportedOnly;
fShowInherited = showInherited;
}
public CPElementFilter(int[] kind, boolean exportedOnly, boolean showInherited) {
this(null, kind, exportedOnly, showInherited);
}
/*
* @see ViewerFilter#select
*/
@Override
public boolean select(Viewer viewer, Object parent, Object element) {
if (element instanceof CPElement) {
for (int i = 0; i < fKind.length; i++) {
if (((CPElement) element).getEntryKind() == fKind[i]) {
if (fExcludes == null || !fExcludes.contains(element)) {
if (fExportedOnly == true) {
if (!fShowInherited) {
return ((CPElement) element).getInherited() == null
&& ((CPElement) element).isExported();
}
return ((CPElement) element).isExported();
}
if (!fShowInherited) {
return ((CPElement) element).getInherited() == null;
}
return true;
}
}
}
} else if (element instanceof IPathEntry) {
for (int i = 0; i < fKind.length; i++) {
if (((IPathEntry) element).getEntryKind() == fKind[i]) {
if (fExcludes == null || !fExcludes.contains(element)) {
if (fExportedOnly == true) {
return ((IPathEntry) element).isExported();
}
return true;
}
}
}
} else if (element instanceof CPElementGroup) {
for (int i = 0; i < fKind.length; i++) {
if (((CPElementGroup) element).getEntryKind() == fKind[i]) {
return true;
}
}
} else {
return true;
}
return false;
}
}
|