Skip to main content
summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorAlain Magloire2004-03-30 00:35:52 -0500
committerAlain Magloire2004-03-30 00:35:52 -0500
commit36e409eaa343a37040894c70e68afab451d64a08 (patch)
treea615363821bd75e108cd49884835efef599e6f40 /core
parentce09c92287317011045fa8448f8f4fa0d7af12d2 (diff)
downloadorg.eclipse.cdt-36e409eaa343a37040894c70e68afab451d64a08.tar.gz
org.eclipse.cdt-36e409eaa343a37040894c70e68afab451d64a08.tar.xz
org.eclipse.cdt-36e409eaa343a37040894c70e68afab451d64a08.zip
Change the old implementation of filter in the CView to match
the PackageExplorer.
Diffstat (limited to 'core')
-rw-r--r--core/org.eclipse.cdt.ui/ChangeLog28
-rw-r--r--core/org.eclipse.cdt.ui/plugin.properties31
-rw-r--r--core/org.eclipse.cdt.ui/plugin.xml56
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/BaseCElementContentProvider.java15
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/ICHelpContextIds.java4
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/cview/CElementFilters.java132
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/cview/CLibFilter.java40
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/cview/CPatternFilter.java123
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/cview/CView.java82
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/cview/CViewActionGroup.java8
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/cview/FilterSelectionAction.java90
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/cview/FiltersContentProvider.java104
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/cview/MainActionGroup.java29
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/cview/ShowLibrariesAction.java69
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/filters/ArchiveFilter.java38
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/filters/ClosedProjectFilter.java36
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/filters/CustomFiltersDialog.java378
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/filters/ExecutableFilter.java41
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/filters/FilterDescriptor.java266
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/filters/FilterMessages.java64
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/filters/FilterMessages.properties24
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/filters/NamePatternFilter.java96
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/filters/NonCElementFilter.java50
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/filters/ObjectFilter.java41
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/filters/SharedFilter.java41
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/actions/CustomFiltersActionGroup.java726
26 files changed, 1965 insertions, 647 deletions
diff --git a/core/org.eclipse.cdt.ui/ChangeLog b/core/org.eclipse.cdt.ui/ChangeLog
index 2c3ee5f584..0242ea82b3 100644
--- a/core/org.eclipse.cdt.ui/ChangeLog
+++ b/core/org.eclipse.cdt.ui/ChangeLog
@@ -1,3 +1,31 @@
+2004-03-30 Alain Magloire
+
+ Change the filter implementation of the CView to match
+ the PackageExplorer functionnality.
+
+ * src/org/eclipse/cdt/internal/ui/filters/ArchiveFilter.java
+ * src/org/eclipse/cdt/internal/ui/filters/ExecutableFilter.java
+ * src/org/eclipse/cdt/internal/ui/filters/SharedFilter.java
+ * src/org/eclipse/cdt/internal/ui/filters/ObjectFilter.java
+ * src/org/eclipse/cdt/internal/ui/filters/NamePatternFilter.java
+ * src/org/eclipse/cdt/internal/ui/filters/FilterDescriptor.java
+ * src/org/eclipse/cdt/internal/ui/filters/CustomFiltersDialog.java
+
+ * src/org/eclipse/cdt/internal/ui/BaseCElementContentProvider.java
+ * src/org/eclipse/cdt/internal/uiICHelpContextIds.java
+
+ * src/org/eclipse/cdt/internal/ui/cview/CView.java
+ * src/org/eclipse/cdt/internal/ui/cview/CViewActionGroup.java
+ * src/org/eclipse/cdt/internal/ui/cview/MainActionGroup.java
+
+ * src/org/eclipse/cdt/ui/actions/CustomFilterActionGroup.java
+
+ Removed Files.
+ * src/org/eclipse/cdt/internal/ui/cview/CElementFilters.java
+ * src/org/eclipse/cdt/internal/ui/cview/CLibFilter.java
+ * src/org/eclipse/cdt/internal/ui/cview/FilterContentProvider.java
+ * src/org/eclipse/cdt/internal/ui/cview/ShowLibrariesAction.java
+
2004-03-29 Alain Magloire
Put the Problem view as the default instead of Task view.
diff --git a/core/org.eclipse.cdt.ui/plugin.properties b/core/org.eclipse.cdt.ui/plugin.properties
index f7890dc82c..f45059c03a 100644
--- a/core/org.eclipse.cdt.ui/plugin.properties
+++ b/core/org.eclipse.cdt.ui/plugin.properties
@@ -115,3 +115,34 @@ CElementWorkingSetPage.name = C/C++
BuildConsoleFontDefinition.description= The C-Build console font is used by the C-Build console
BuildConsoleFontDefinition.label= C-Build Console Text Font
+
+##########################################################################
+# Filter Support
+##########################################################################
+
+HideClosedProjects.label= Closed projects
+HideClosedProjects.description= Hides closed projects
+
+HideExecutableFiles.label= Executable files
+HideExecutableFiles.description= Hides executable files
+
+HideSharedFiles.label= Shared object files
+HideSharedFiles.description= Hides shared object files
+
+HideArchiveFiles.label= Archive files
+HideArchiveFiles.description= Hides Archive files
+
+HideObjectFiles.label= Object files
+HideObjectFiles.description= Hides Object files
+
+HideNonCElements.label= Non-C elements
+HideNonCElements.description= Show only C elements
+
+HideReferencedLibraries.label= Referenced libraries
+HideReferencedLibraries.description= Hides referenced libraries i.e. those not contained inside the project itself
+
+HideCFiles.label= C files
+HideCFiles.description= Hides all C files
+
+HideHeaderFiles.label= Header files
+HideHeaderFiles.description= Hides all Header files
diff --git a/core/org.eclipse.cdt.ui/plugin.xml b/core/org.eclipse.cdt.ui/plugin.xml
index 270e9a9448..19cf5f2461 100644
--- a/core/org.eclipse.cdt.ui/plugin.xml
+++ b/core/org.eclipse.cdt.ui/plugin.xml
@@ -49,25 +49,61 @@
pattern=".*">
</filter>
<filter
- selected="false"
- pattern="*.o">
+ targetId="org.eclipse.cdt.ui.CView"
+ name="%HideExecutableFiles.label"
+ enabled="false"
+ description="%HideExecutableFiles.description"
+ class="org.eclipse.cdt.internal.ui.filters.ExecutableFilter"
+ id="org.eclipse.cdt.internal.ui.CView.ExecutableFilter">
</filter>
<filter
- selected="false"
- pattern="*.so">
+ targetId="org.eclipse.cdt.ui.CView"
+ name="%HideSharedFiles.label"
+ enabled="false"
+ description="%HideSharedFiles.description"
+ class="org.eclipse.cdt.internal.ui.filters.SharedFilter"
+ id="org.eclipse.cdt.internal.ui.CView.SharedFilter">
</filter>
<filter
- selected="false"
- pattern="*.a">
+ targetId="org.eclipse.cdt.ui.CView"
+ name="%HideObjectFiles.label"
+ enabled="false"
+ description="%HideObjectFiles.description"
+ class="org.eclipse.cdt.internal.ui.filters.ObjectFilter"
+ id="org.eclipse.cdt.internal.ui.CView.ArchiveFilter">
</filter>
<filter
- selected="false"
- pattern="Makefile">
+ targetId="org.eclipse.cdt.ui.CView"
+ name="%HideArchiveFiles.label"
+ enabled="false"
+ description="%HideArchiveFiles.description"
+ class="org.eclipse.cdt.internal.ui.filters.ArchiveFilter"
+ id="org.eclipse.cdt.internal.ui.CView.ArchiveFilter">
</filter>
<filter
- selected="false"
- pattern="*.h">
+ targetId="org.eclipse.cdt.ui.CView"
+ name="%HideClosedProjects.label"
+ enabled="false"
+ description="%HideClosedProjects.description"
+ class="org.eclipse.cdt.internal.ui.filters.ClosedProjectFilter"
+ id="org.eclipse.cdt.internal.ui.CView.ClosedProjectFilter">
</filter>
+ <filter
+ targetId="org.eclipse.cdt.ui.CView"
+ name="%HideNonCElements.label"
+ enabled="false"
+ description="%HideNonCElements.description"
+ class="org.eclipse.cdt.internal.ui.filters.NonCElementFilter"
+ id="org.eclipse.cdt.internal.ui.CView.NonCElementFilter">
+ </filter>
+ <!--filter
+ targetId="org.eclipse.cdt.ui.CView"
+ name="%HideHeaderFilter.label"
+ enabled="false"
+ description="%HideHeaderFilter.description"
+ class="org.eclipse.cdt.internal.ui.filters.HeaderFilter"
+ id="org.eclipse.cdt.internal.ui.CView.HeaderFilter">
+ </filter-->
</extension>
<extension
point="org.eclipse.ui.perspectives">
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/BaseCElementContentProvider.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/BaseCElementContentProvider.java
index 7b0b172784..b965b05440 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/BaseCElementContentProvider.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/BaseCElementContentProvider.java
@@ -244,7 +244,16 @@ public class BaseCElementContentProvider implements ITreeContentProvider {
}
protected Object[] getCProjects(ICModel cModel) {
- return cModel.getCProjects();
+ Object[] objects = cModel.getCProjects();
+ try {
+ Object[] nonC = cModel.getNonCResources();
+ if (nonC.length > 0) {
+ objects = concatenate(objects, nonC);
+ }
+ } catch (CModelException e) {
+ //
+ }
+ return objects;
}
protected Object[] getSourceRoots(ICProject cproject) {
@@ -263,9 +272,9 @@ public class BaseCElementContentProvider implements ITreeContentProvider {
for (int k= 0; k < children.length; k++) {
list.add(children[k]);
}
- } else if (hasChildren(root)) {
+ } else {
list.add(root);
- }
+ }
}
} catch (CModelException e1) {
}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/ICHelpContextIds.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/ICHelpContextIds.java
index 968648bd6a..5caefdbbfa 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/ICHelpContextIds.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/ICHelpContextIds.java
@@ -64,6 +64,10 @@ public interface ICHelpContextIds {
public static final String COPY_ACTION = PREFIX + "copy_action_context"; //$NON-NLS-1$
+ // Custom Filters
+ public static final String CUSTOM_FILTERS_DIALOG= PREFIX + "open_custom_filters_dialog_context"; //$NON-NLS-1$
+
+
public static final String PASTE_ACTION = PREFIX + "paste_action_context"; //$NON_NLS-1$ //$NON-NLS-1$
public static final String MOVE_ACTION = PREFIX + "move_action_context"; //$NON-NLS-1$
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/cview/CElementFilters.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/cview/CElementFilters.java
deleted file mode 100644
index d3470f85de..0000000000
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/cview/CElementFilters.java
+++ /dev/null
@@ -1,132 +0,0 @@
-package org.eclipse.cdt.internal.ui.cview;
-
-/*
- * (c) Copyright IBM Corp. 2000, 2001.
- * All Rights Reserved.
- */
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.StringTokenizer;
-
-import org.eclipse.core.runtime.IConfigurationElement;
-import org.eclipse.core.runtime.IExtension;
-import org.eclipse.core.runtime.IExtensionPoint;
-
-import org.eclipse.cdt.internal.ui.util.StringMatcher;
-import org.eclipse.cdt.ui.CUIPlugin;
-
-/**
- * The FiltersContent provides the elements for use by the list dialog
- * for selecting the patterns to apply.
- */
-public class CElementFilters {
- static List definedFilters = null;
- static List defaultFilters = null;
- static StringMatcher [] matchers = null;
- static String FILTERS_TAG= "CElementFilters"; //$NON-NLS-1$
- static String COMMA_SEPARATOR = ","; //$NON-NLS-1$
-
- /**
- * Returns the filters which are enabled by default.
- *
- * @return a list of strings
- */
- public static List getDefaultFilters() {
- if (defaultFilters == null) {
- readFilters();
- }
- return defaultFilters;
- }
-
- /**
- * Returns the filters currently defined for the workbench.
- */
- public static List getDefinedFilters() {
- if (definedFilters == null) {
- // Overide the default by the user preference
- CUIPlugin plugin = CUIPlugin.getDefault();
- String storedPatterns= plugin.getPluginPreferences().getString(FILTERS_TAG);
-
- if (storedPatterns.length() > 0) {
- StringTokenizer entries = new StringTokenizer(storedPatterns, COMMA_SEPARATOR);
- definedFilters = new ArrayList();
-
- while (entries.hasMoreElements()) {
- String nextToken = entries.nextToken();
- definedFilters.add(nextToken);
- }
- } else {
- readFilters();
- }
- }
- return definedFilters;
- }
-
- public static StringMatcher [] getMatchers() {
- if (matchers == null) {
- List list = getDefinedFilters();
- matchers = new StringMatcher[list.size()];
- for (int i = 0; i < matchers.length; i++) {
- matchers[i] = new StringMatcher((String)(list.get(i)), true, false);
- }
- }
- return matchers;
- }
-
- /**
- * Define new Patterns for the Duration of the session.
- */
- public static void setPatterns(String[] newPatterns) {
- //System.out.println ("SetPatterns call");
- matchers = new StringMatcher[newPatterns.length];
- for (int i = 0; i < newPatterns.length; i++) {
- //System.out.println ("Patterns " + newPatterns[i]);
- matchers[i] = new StringMatcher(newPatterns[i], true, false);
- }
- //CElementFactory.getDefault().refreshDeadBranchParents();
- }
-
-
- public static boolean match(String name) {
- StringMatcher [] m = getMatchers();
- if (m == null)
- return false;
- //System.out.println ("Pattern " + name);
- for (int i = 0; i < m.length; i++) {
- if (m[i].match(name)) {
- //System.out.println ("Match " + name);
- return true;
- }
- }
- return false;
- }
-
- private CElementFilters() {
- }
- /**
- * Reads the filters currently defined for the workbench.
- */
- static void readFilters() {
- definedFilters = new ArrayList();
- defaultFilters = new ArrayList();
- CUIPlugin plugin = CUIPlugin.getDefault();
- if (plugin != null) {
- IExtensionPoint extension = plugin.getDescriptor().getExtensionPoint(FILTERS_TAG);
- if (extension != null) {
- IExtension[] extensions = extension.getExtensions();
- for(int i = 0; i < extensions.length; i++){
- IConfigurationElement [] configElements = extensions[i].getConfigurationElements();
- for(int j = 0; j < configElements.length; j++){
- String pattern = configElements[j].getAttribute("pattern"); //$NON-NLS-1$
- if (pattern != null)
- definedFilters.add(pattern);
- String selected = configElements[j].getAttribute("selected"); //$NON-NLS-1$
- if (selected != null && selected.equalsIgnoreCase("true")) //$NON-NLS-1$
- defaultFilters.add(pattern);
- }
- }
- }
- }
- }
-}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/cview/CLibFilter.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/cview/CLibFilter.java
deleted file mode 100644
index 64c471e9c3..0000000000
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/cview/CLibFilter.java
+++ /dev/null
@@ -1,40 +0,0 @@
-package org.eclipse.cdt.internal.ui.cview;
-
-/*
- * (c) Copyright QNX Software Systems Ltd. 2002.
- * All Rights Reserved.
- */
-
-import org.eclipse.jface.viewers.Viewer;
-import org.eclipse.jface.viewers.ViewerFilter;
-
-import org.eclipse.cdt.core.model.ILibraryReference;
-
-public class CLibFilter extends ViewerFilter {
- private boolean showlib = true;
-
- public boolean getShowLibraries() {
- return showlib;
- }
-
- /* (non-Javadoc)
- * Method declared on ViewerFilter.
- */
- public boolean select(Viewer viewer, Object parentElement, Object element) {
- if (element instanceof ILibraryReference) {
- return showlib;
- }
- return true;
- }
-
- public void setShowLibraries (boolean show) {
- showlib = show;
- }
-
- /**
- * Creates a new library filter.
- */
- public CLibFilter() {
- super();
- }
-}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/cview/CPatternFilter.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/cview/CPatternFilter.java
deleted file mode 100644
index 019e2bfb1b..0000000000
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/cview/CPatternFilter.java
+++ /dev/null
@@ -1,123 +0,0 @@
-package org.eclipse.cdt.internal.ui.cview;
-
-/*
- * (c) Copyright QNX Software Systems Ltd. 2002.
- * All Rights Reserved.
- */
-
-import java.util.List;
-import java.util.Vector;
-import java.util.StringTokenizer;
-
-import org.eclipse.jface.viewers.Viewer;
-import org.eclipse.jface.viewers.ViewerFilter;
-import org.eclipse.core.resources.IResource;
-import org.eclipse.core.runtime.IAdaptable;
-
-import org.eclipse.cdt.internal.ui.util.StringMatcher;
-import org.eclipse.cdt.ui.CUIPlugin;
-
-import org.eclipse.cdt.core.model.ICContainer;
-import org.eclipse.cdt.core.model.ICProject;
-
-public class CPatternFilter extends ViewerFilter {
- private String[] patterns;
- private StringMatcher[] matchers;
-
- static String COMMA_SEPARATOR = ","; //$NON-NLS-1$
- static String FILTERS_TAG= "CElementFilters"; //$NON-NLS-1$
-
- private void initializeFromPreferences() {
- CUIPlugin plugin= CUIPlugin.getDefault();
- String storedPatterns= plugin.getPreferenceStore().getString(FILTERS_TAG);
-
- if (storedPatterns.length() == 0) {
- List defaultFilters= FiltersContentProvider.getDefaultFilters();
- String[] patterns= new String[defaultFilters.size()];
- defaultFilters.toArray(patterns);
- setPatterns(patterns);
- return;
- }
-
- //Get the strings separated by a comma and filter them from the currently
- //defined ones
-
- List definedFilters = FiltersContentProvider.getDefinedFilters();
-
- StringTokenizer entries = new StringTokenizer(storedPatterns, COMMA_SEPARATOR);
- Vector patterns = new Vector();
-
- while (entries.hasMoreElements()) {
- String nextToken = entries.nextToken();
- if (definedFilters.indexOf(nextToken) > -1)
- patterns.addElement(nextToken);
- }
-
- //Convert to an array of Strings
- String[] patternArray = new String[patterns.size()];
- patterns.toArray(patternArray);
- setPatterns(patternArray);
- }
-
- /**
- * Gets the patterns for the receiver. Returns the cached values if there
- * are any - if not look it up.
- */
- public String[] getPatterns() {
- if (patterns == null) {
- initializeFromPreferences();
- }
- return patterns;
- }
-
- /**
- * Sets the patterns to filter out for the receiver.
- */
- public void setPatterns(String[] newPatterns) {
-
- patterns = newPatterns;
- matchers = new StringMatcher[newPatterns.length];
- for (int i = 0; i < newPatterns.length; i++) {
- //Reset the matchers to prevent constructor overhead
- matchers[i] = new StringMatcher(newPatterns[i], true, false);
- }
- }
-
-
- /**
- * Return the currently configured StringMatchers. If there aren't any look
- * them up.
- */
- private StringMatcher[] getMatchers() {
- if (matchers == null)
- initializeFromPreferences();
- return matchers;
- }
-
- /* (non-Javadoc)
- * Method declared on ViewerFilter.
- */
- public boolean select(Viewer viewer, Object parentElement, Object element) {
- IResource resource = null;
- if (element instanceof IResource) {
- resource = (IResource) element;
- } else if (element instanceof IAdaptable) {
- IAdaptable adaptable = (IAdaptable) element;
- resource = (IResource) adaptable.getAdapter(IResource.class);
- }
-
- // Only apply the rule for Projects and folders.
- if (parentElement instanceof ICProject
- || parentElement instanceof ICContainer) {
- if (resource != null) {
- String name = resource.getName();
- StringMatcher[] testMatchers = getMatchers();
- for (int i = 0; i < testMatchers.length; i++) {
- if (testMatchers[i].match(name))
- return false;
- }
- }
- }
- return true;
- }
-}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/cview/CView.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/cview/CView.java
index f2edcd9dfc..3cbe2b8f9e 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/cview/CView.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/cview/CView.java
@@ -109,8 +109,6 @@ public class CView extends ViewPart implements ISetSelectionTarget, IPropertyCha
FrameList frameList;
CViewFrameSource frameSource;
- CLibFilter clibFilter = new CLibFilter();
- CPatternFilter patternFilter = new CPatternFilter();
ResourceWorkingSetFilter workingSetFilter = new ResourceWorkingSetFilter();
private boolean dragDetected;
@@ -123,11 +121,7 @@ public class CView extends ViewPart implements ISetSelectionTarget, IPropertyCha
static final String TAG_PATH = "path"; //$NON-NLS-1$
static final String TAG_VERTICAL_POSITION = "verticalPosition"; //$NON-NLS-1$
static final String TAG_HORIZONTAL_POSITION = "horizontalPosition"; //$NON-NLS-1$
- static final String TAG_FILTERS = "filters"; //$NON-NLS-1$
- static final String TAG_FILTER = "filter"; //$NON-NLS-1$
- static final String TAG_SHOWLIBRARIES = "showLibraries"; //$NON-NLS-1$
static final String TAG_WORKINGSET = "workingSet"; //$NON-NLS-1$
- static final String TAG_SORTER = "sorter"; //$NON-NLS-1$
//Menu tags
final String WORKING_GROUP_MARKER = "workingSetGroup"; //$NON-NLS-1$
@@ -358,9 +352,7 @@ public class CView extends ViewPart implements ISetSelectionTarget, IPropertyCha
* the viewer
*/
void initFilters(TreeViewer viewer) {
- viewer.addFilter(patternFilter);
viewer.addFilter(workingSetFilter);
- //viewer.addFilter(clibFilter);
}
/**
@@ -395,16 +387,12 @@ public class CView extends ViewPart implements ISetSelectionTarget, IPropertyCha
* Initializes the default preferences
*/
public static void initDefaults(IPreferenceStore store) {
- store.setDefault(TAG_SHOWLIBRARIES, true);
}
/**
* get the default preferences.
*/
void initFilterFromPreferences() {
- CUIPlugin plugin = CUIPlugin.getDefault();
- boolean show = plugin.getPreferenceStore().getBoolean(TAG_SHOWLIBRARIES);
- getLibraryFilter().setShowLibraries(show);
}
/**
@@ -515,12 +503,6 @@ public class CView extends ViewPart implements ISetSelectionTarget, IPropertyCha
CUIPlugin.getDefault().getProblemMarkerManager().addListener(viewer);
CUIPlugin.getDefault().getPreferenceStore().addPropertyChangeListener(this);
- if (memento != null) {
- restoreFilters();
- } else {
- initFilterFromPreferences();
- }
-
initFilters(viewer);
initWorkingSetFilter();
initListeners(viewer);
@@ -548,6 +530,12 @@ public class CView extends ViewPart implements ISetSelectionTarget, IPropertyCha
getActionGroup().fillActionBars(getViewSite().getActionBars());
updateActionBars((IStructuredSelection) viewer.getSelection());
+ if (memento != null) {
+ getActionGroup().restoreFilterAndSorterState(memento);
+ } else {
+ initFilterFromPreferences();
+ }
+
if (memento != null) {
restoreState(memento);
@@ -617,19 +605,6 @@ public class CView extends ViewPart implements ISetSelectionTarget, IPropertyCha
}
}
- CLibFilter getLibraryFilter() {
- return clibFilter;
- }
-
- /**
- * Returns the pattern filter for this view.
- *
- * @return the pattern filter
- */
- CPatternFilter getPatternFilter() {
- return patternFilter;
- }
-
/**
* Returns the working set filter for this view.
*
@@ -904,32 +879,12 @@ public class CView extends ViewPart implements ISetSelectionTarget, IPropertyCha
viewer.getControl().setRedraw(true);
}
- void restoreFilters() {
- // restore pattern filters
- IMemento filtersMem = memento.getChild(TAG_FILTERS);
- if (filtersMem != null) {
- IMemento children[] = filtersMem.getChildren(TAG_FILTER);
- String filters[] = new String[children.length];
- for (int i = 0; i < children.length; i++) {
- filters[i] = children[i].getString(TAG_ELEMENT);
- }
- getPatternFilter().setPatterns(filters);
- } else {
- getPatternFilter().setPatterns(new String[0]);
- }
-
- //restore library
- String show = memento.getString(TAG_SHOWLIBRARIES);
- if (show != null) {
- getLibraryFilter().setShowLibraries(show.equals("true")); //$NON-NLS-1$
- } else {
- initFilterFromPreferences();
- }
- }
-
void restoreState(IMemento memento) {
- //ICelement container = CElementFactory.getDefault().getRoot();
+
CoreModel factory = CoreModel.getDefault();
+
+ getActionGroup().restoreFilterAndSorterState(memento);
+
IMemento childMem = memento.getChild(TAG_EXPANDED);
if (childMem != null) {
ArrayList elements = new ArrayList();
@@ -1042,22 +997,7 @@ public class CView extends ViewPart implements ISetSelectionTarget, IPropertyCha
position = bar != null ? bar.getSelection() : 0;
memento.putString(TAG_HORIZONTAL_POSITION, String.valueOf(position));
- //save filters
- String filters[] = getPatternFilter().getPatterns();
- if (filters.length > 0) {
- IMemento filtersMem = memento.createChild(TAG_FILTERS);
- for (int i = 0; i < filters.length; i++) {
- IMemento child = filtersMem.createChild(TAG_FILTER);
- child.putString(TAG_ELEMENT, filters[i]);
- }
- }
-
- //save library filter
- boolean showLibraries = getLibraryFilter().getShowLibraries();
- String show = "true"; //$NON-NLS-1$
- if (!showLibraries) show = "false"; //$NON-NLS-1$
- memento.putString(TAG_SHOWLIBRARIES, show);
-
+ getActionGroup().saveFilterAndSorterState(memento);
//Save the working set away
if (workingSetFilter.getWorkingSet() != null) {
String wsname = workingSetFilter.getWorkingSet().getName();
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/cview/CViewActionGroup.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/cview/CViewActionGroup.java
index 264c952bf9..35fcf5574e 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/cview/CViewActionGroup.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/cview/CViewActionGroup.java
@@ -14,11 +14,13 @@ import java.net.MalformedURLException;
import java.net.URL;
import org.eclipse.cdt.ui.CUIPlugin;
+import org.eclipse.cdt.ui.actions.CustomFiltersActionGroup;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.swt.events.KeyEvent;
import org.eclipse.ui.IActionBars;
+import org.eclipse.ui.IMemento;
import org.eclipse.ui.actions.ActionGroup;
/**
@@ -114,4 +116,10 @@ public abstract class CViewActionGroup extends ActionGroup {
public void runDefaultAction(IStructuredSelection selection) {
}
+ public void restoreFilterAndSorterState(IMemento memento) {
+ }
+
+ public void saveFilterAndSorterState(IMemento memento) {
+ }
+
}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/cview/FilterSelectionAction.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/cview/FilterSelectionAction.java
deleted file mode 100644
index 4eb7b64acf..0000000000
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/cview/FilterSelectionAction.java
+++ /dev/null
@@ -1,90 +0,0 @@
-package org.eclipse.cdt.internal.ui.cview;
-
-/*
- * (c) Copyright IBM Corp. 2000, 2001.
- * All Rights Reserved.
- */
-
-import java.io.StringWriter;
-
-import org.eclipse.jface.viewers.LabelProvider;
-import org.eclipse.jface.viewers.TreeViewer;
-import org.eclipse.jface.window.Window;
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.ui.actions.SelectionProviderAction;
-import org.eclipse.ui.dialogs.ListSelectionDialog;
-
-import org.eclipse.cdt.ui.CUIPlugin;
-//import org.eclipse.cdt.core.model.CElementFilters;
-
-/**
- * The FilterAction is the class that adds the filter views to a PackagesView.
- */
-class FilterSelectionAction extends SelectionProviderAction {
-
-
- private CView cview;
- private Shell shell;
-
- /**
- * Create a new filter action
- * @param shell the shell that will be used for the list selection
- * @param packages the PackagesExplorerPart
- * @param label the label for the action
- */
- public FilterSelectionAction(Shell shell, CView cview, String label) {
- super(cview.getViewer(), label);
- setToolTipText(CViewMessages.getString("FilterSelectionAction.toolTip")); //$NON-NLS-1$
- setEnabled(true);
- this.shell= shell;
- this.cview= cview;
- }
-
- /**
- * Implementation of method defined on <code>IAction</code>.
- */
- public void run() {
- CPatternFilter filter= cview.getPatternFilter();
- FiltersContentProvider contentProvider= new FiltersContentProvider(filter);
-
- ListSelectionDialog dialog =
- new ListSelectionDialog(
- shell,
- cview.getViewer(),
- contentProvider,
- new LabelProvider(),
- CViewMessages.getString("FilterSelectionAction.selectFilters")); //$NON-NLS-1$
-
- dialog.setInitialSelections(contentProvider.getInitialSelections());
- dialog.setTitle(CViewMessages.getString("FilterSelectionAction.title")); //$NON-NLS-1$
- dialog.open();
- if (dialog.getReturnCode() == Window.OK) {
- Object[] results= dialog.getResult();
- String[] selectedPatterns= new String[results.length];
- System.arraycopy(results, 0, selectedPatterns, 0, results.length);
- filter.setPatterns(selectedPatterns);
- CElementFilters.setPatterns(selectedPatterns);
- saveInPreferences(selectedPatterns);
- TreeViewer viewer= cview.getViewer();
- viewer.getControl().setRedraw(false);
- viewer.refresh();
- viewer.getControl().setRedraw(true);
- }
- }
- /**
- * Save the supplied patterns in the preferences for the UIPlugin.
- * They are saved in the format patern,pattern,.
- */
- private void saveInPreferences(String[] patterns) {
- CUIPlugin plugin= CUIPlugin.getDefault();
- StringWriter writer= new StringWriter();
-
- for (int i = 0; i < patterns.length; i++) {
- writer.write(patterns[i]);
- writer.write(CPatternFilter.COMMA_SEPARATOR);
- }
-
- plugin.getPreferenceStore().setValue(
- CPatternFilter.FILTERS_TAG, writer.toString());
- }
-}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/cview/FiltersContentProvider.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/cview/FiltersContentProvider.java
deleted file mode 100644
index e765844cfd..0000000000
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/cview/FiltersContentProvider.java
+++ /dev/null
@@ -1,104 +0,0 @@
-package org.eclipse.cdt.internal.ui.cview;
-
-/*
- * (c) Copyright IBM Corp. 2000, 2001.
- * All Rights Reserved.
- */
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.eclipse.core.runtime.IConfigurationElement;
-import org.eclipse.core.runtime.IExtension;
-import org.eclipse.core.runtime.IExtensionPoint;
-import org.eclipse.jface.viewers.IStructuredContentProvider;
-import org.eclipse.jface.viewers.Viewer;
-
-import org.eclipse.cdt.ui.CUIPlugin;
-
-/**
- * The FiltersContentProvider provides the elements for use by the list dialog
- * for selecting the patterns to apply.
- */
-class FiltersContentProvider implements IStructuredContentProvider {
- private static List fgDefinedFilters;
- private static List fgDefaultFilters;
-
- private CPatternFilter filter;
-
- /**
- * Disposes of this content provider.
- * This is called by the viewer when it is disposed.
- */
- public void dispose() {}
- /**
- * Returns the filters which are enabled by default.
- *
- * @return a list of strings
- */
- public static List getDefaultFilters() {
- if (fgDefaultFilters == null) {
- readFilters();
- }
- return fgDefaultFilters;
- }
- /**
- * Returns the filters currently defined for the workbench.
- */
- public static List getDefinedFilters() {
- if (fgDefinedFilters == null) {
- readFilters();
- }
- return fgDefinedFilters;
- }
- /* (non-Jaadoc)
- * Method declared in IStructuredContentProvider.
- */
- public Object[] getElements(Object inputElement) {
- return getDefinedFilters().toArray();
- }
- /**
- * Return the initially selected values
- * @return java.lang.String[]
- */
- public String[] getInitialSelections() {
- return filter.getPatterns();
- }
- /* (non-Javadoc)
- * Method declared on IContentProvider.
- */
- public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
- }
- /**
- * Create a FiltersContentProvider using the selections from the suppliec
- * resource filter.
- */
- public FiltersContentProvider(CPatternFilter filter) {
- this.filter= filter;
- }
- /**
- * Reads the filters currently defined for the workbench.
- */
- private static void readFilters() {
- fgDefinedFilters = new ArrayList();
- fgDefaultFilters = new ArrayList();
- CUIPlugin plugin = CUIPlugin.getDefault();
- if (plugin != null) {
- IExtensionPoint extension = plugin.getDescriptor().getExtensionPoint(CPatternFilter.FILTERS_TAG);
- if (extension != null) {
- IExtension[] extensions = extension.getExtensions();
- for(int i = 0; i < extensions.length; i++){
- IConfigurationElement [] configElements = extensions[i].getConfigurationElements();
- for(int j = 0; j < configElements.length; j++){
- String pattern = configElements[j].getAttribute("pattern"); //$NON-NLS-1$
- if (pattern != null)
- fgDefinedFilters.add(pattern);
- String selected = configElements[j].getAttribute("selected"); //$NON-NLS-1$
- if (selected != null && selected.equalsIgnoreCase("true")) //$NON-NLS-1$
- fgDefaultFilters.add(pattern);
- }
- }
- }
- }
- }
-}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/cview/MainActionGroup.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/cview/MainActionGroup.java
index debef116b8..31646db11a 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/cview/MainActionGroup.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/cview/MainActionGroup.java
@@ -19,6 +19,7 @@ import org.eclipse.cdt.internal.ui.editor.OpenIncludeAction;
import org.eclipse.cdt.internal.ui.editor.SearchDialogAction;
import org.eclipse.cdt.internal.ui.search.actions.SelectionSearchGroup;
import org.eclipse.cdt.ui.CUIPlugin;
+import org.eclipse.cdt.ui.actions.CustomFiltersActionGroup;
import org.eclipse.cdt.ui.actions.RefactoringActionGroup;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
@@ -35,6 +36,7 @@ import org.eclipse.jface.viewers.Viewer;
import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IActionBars;
+import org.eclipse.ui.IMemento;
import org.eclipse.ui.IWorkbenchActionConstants;
import org.eclipse.ui.IWorkingSet;
import org.eclipse.ui.actions.ActionContext;
@@ -64,7 +66,7 @@ public class MainActionGroup extends CViewActionGroup {
// CElement action
OpenIncludeAction openIncludeAction;
- ShowLibrariesAction clibFilterAction;
+
// Collapsing
CollapseAllAction collapseAllAction;
ToggleLinkingAction toggleLinkingAction;
@@ -73,7 +75,6 @@ public class MainActionGroup extends CViewActionGroup {
FileSearchAction fFileSearchAction;
FileSearchActionInWorkingSet fFileSearchActionInWorkingSet;
SearchDialogAction fSearchDialogAction;
- FilterSelectionAction patternFilterAction;
BuildGroup buildGroup;
OpenFileGroup openFileGroup;
@@ -81,6 +82,7 @@ public class MainActionGroup extends CViewActionGroup {
RefactorActionGroup refactorGroup;
OpenProjectGroup openProjectGroup;
WorkingSetFilterActionGroup workingSetGroup;
+ CustomFiltersActionGroup fCustomFiltersActionGroup;
SelectionSearchGroup selectionSearchGroup;
RefactoringActionGroup refactoringActionGroup;
@@ -125,8 +127,6 @@ public class MainActionGroup extends CViewActionGroup {
//sortByNameAction = new SortViewAction(this, false);
//sortByTypeAction = new SortViewAction(this, true);
- patternFilterAction = new FilterSelectionAction(shell, getCView(), CViewMessages.getString("FilterSelectionAction.label")); //$NON-NLS-1$
- clibFilterAction = new ShowLibrariesAction(shell, getCView(), CViewMessages.getString("ShowLibrariesAction.label")); //$NON-NLS-1$
IPropertyChangeListener workingSetUpdater = new IPropertyChangeListener() {
public void propertyChange(PropertyChangeEvent event) {
@@ -145,6 +145,7 @@ public class MainActionGroup extends CViewActionGroup {
};
workingSetGroup = new WorkingSetFilterActionGroup(shell, workingSetUpdater);
workingSetGroup.setWorkingSet(getCView().getWorkingSet());
+ fCustomFiltersActionGroup= new CustomFiltersActionGroup(getCView(), getCView().getViewer());
addBookmarkAction = new AddBookmarkAction(shell);
addTaskAction = new AddTaskAction(shell);
@@ -314,6 +315,7 @@ public class MainActionGroup extends CViewActionGroup {
buildGroup.updateActionBars();
refactorGroup.updateActionBars();
workingSetGroup.updateActionBars();
+ fCustomFiltersActionGroup.updateActionBars();
}
public void fillActionBars(IActionBars actionBars) {
@@ -322,6 +324,7 @@ public class MainActionGroup extends CViewActionGroup {
actionBars.setGlobalActionHandler(ActionFactory.PROPERTIES.getId(), propertyDialogAction);
workingSetGroup.fillActionBars(actionBars);
+ fCustomFiltersActionGroup.fillActionBars(actionBars);
gotoGroup.fillActionBars(actionBars);
refactorGroup.fillActionBars(actionBars);
openFileGroup.fillActionBars(actionBars);
@@ -335,10 +338,26 @@ public class MainActionGroup extends CViewActionGroup {
IMenuManager menu = actionBars.getMenuManager();
//menu.add (clibFilterAction);
- menu.add(patternFilterAction);
+ //menu.add(fCustomFiltersActionGroup);
menu.add(toggleLinkingAction);
}
+ //---- Persistent state -----------------------------------------------------------------------
+
+ public void restoreFilterAndSorterState(IMemento memento) {
+ //fWorkingSetFilterActionGroup.restoreState(memento);
+ fCustomFiltersActionGroup.restoreState(memento);
+ }
+
+ public void saveFilterAndSorterState(IMemento memento) {
+ //fWorkingSetFilterActionGroup.saveState(memento);
+ fCustomFiltersActionGroup.saveState(memento);
+ }
+
+ public CustomFiltersActionGroup getCustomFilterActionGroup() {
+ return fCustomFiltersActionGroup;
+ }
+
public void dispose() {
IWorkspace workspace = CUIPlugin.getWorkspace();
refactorGroup.dispose();
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/cview/ShowLibrariesAction.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/cview/ShowLibrariesAction.java
deleted file mode 100644
index 8169277de2..0000000000
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/cview/ShowLibrariesAction.java
+++ /dev/null
@@ -1,69 +0,0 @@
-package org.eclipse.cdt.internal.ui.cview;
-
-/*
- * (c) Copyright IBM Corp. 2000, 2001.
- * All Rights Reserved.
- */
-
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.ui.actions.SelectionProviderAction;
-
-import org.eclipse.cdt.ui.CUIPlugin;
-
-/**
- * The ShowLibrariesAction is the class that adds the filter views to a PackagesView.
- */
-class ShowLibrariesAction extends SelectionProviderAction {
-
- private CView cview;
- private Shell shell;
-
- /**
- * Create a new filter action
- * @param shell the shell that will be used for the list selection
- * @param packages the PackagesExplorerPart
- * @param label the label for the action
- */
- public ShowLibrariesAction(Shell shell, CView cview, String label) {
- super(cview.getViewer(), label);
- this.cview = cview;
- CLibFilter filter = cview.getLibraryFilter();
- setChecked(filter.getShowLibraries());
- updateToolTipText();
- setEnabled(true);
- this.shell= shell;
- }
-
- /**
- * Implementation of method defined on <code>IAction</code>.
- */
- public void run() {
- CLibFilter filter = cview.getLibraryFilter();
- filter.setShowLibraries(isChecked());
- updateToolTipText();
- saveInPreferences();
-
- cview.getViewer().getControl().setRedraw(false);
- cview.getViewer().refresh();
- cview.getViewer().getControl().setRedraw(true);
- }
-
- /**
- * Save the supplied patterns in the preferences for the UIPlugin.
- * They are saved in the format patern,pattern,.
- */
- private void saveInPreferences() {
- CUIPlugin plugin = CUIPlugin.getDefault();
- Boolean b = new Boolean (cview.getLibraryFilter().getShowLibraries());
-
- plugin.getPreferenceStore().putValue(CView.TAG_SHOWLIBRARIES, b.toString());
- }
-
- private void updateToolTipText() {
- CLibFilter filter = cview.getLibraryFilter();
- if (filter.getShowLibraries())
- setToolTipText(CViewMessages.getString("ShowLibrariesAction.hideReferenced.tooltip")); //$NON-NLS-1$
- else
- setToolTipText(CViewMessages.getString("ShowLibrariesAction.showReferenced.tooltip")); //$NON-NLS-1$
- }
-}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/filters/ArchiveFilter.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/filters/ArchiveFilter.java
new file mode 100644
index 0000000000..0f5af39bc6
--- /dev/null
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/filters/ArchiveFilter.java
@@ -0,0 +1,38 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2003 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.internal.ui.filters;
+
+import org.eclipse.cdt.core.model.IArchive;
+import org.eclipse.cdt.core.model.IArchiveContainer;
+
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jface.viewers.ViewerFilter;
+
+
+
+/**
+ * The ArchiveFilter is a filter used to determine whether
+ * a C Archive is shown
+ */
+public class ArchiveFilter extends ViewerFilter {
+
+ /* (non-Javadoc)
+ * Method declared on ViewerFilter.
+ */
+ public boolean select(Viewer viewer, Object parentElement, Object element) {
+ if (element instanceof IArchive) {
+ if (! (parentElement instanceof IArchiveContainer)) {
+ return false;
+ }
+ }
+ return true;
+ }
+}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/filters/ClosedProjectFilter.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/filters/ClosedProjectFilter.java
new file mode 100644
index 0000000000..021ccdf579
--- /dev/null
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/filters/ClosedProjectFilter.java
@@ -0,0 +1,36 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2003 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.internal.ui.filters;
+
+
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jface.viewers.ViewerFilter;
+
+import org.eclipse.cdt.core.model.ICElement;
+import org.eclipse.core.resources.IResource;
+
+
+/**
+ * Filters closed projects
+ */
+public class ClosedProjectFilter extends ViewerFilter {
+
+ /*
+ * @see ViewerFilter
+ */
+ public boolean select(Viewer viewer, Object parent, Object element) {
+ if (element instanceof ICElement)
+ return ((ICElement)element).getCProject().getProject().isOpen();
+ if (element instanceof IResource)
+ return ((IResource)element).getProject().isOpen();
+ return true;
+ }
+}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/filters/CustomFiltersDialog.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/filters/CustomFiltersDialog.java
new file mode 100644
index 0000000000..21569b6b09
--- /dev/null
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/filters/CustomFiltersDialog.java
@@ -0,0 +1,378 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2003 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.internal.ui.filters;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+import java.util.Stack;
+import java.util.StringTokenizer;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Text;
+
+import org.eclipse.cdt.internal.ui.ICHelpContextIds;
+import org.eclipse.cdt.internal.ui.util.SWTUtil;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.util.Assert;
+import org.eclipse.jface.viewers.ArrayContentProvider;
+import org.eclipse.jface.viewers.CheckStateChangedEvent;
+import org.eclipse.jface.viewers.CheckboxTableViewer;
+import org.eclipse.jface.viewers.ICheckStateListener;
+import org.eclipse.jface.viewers.ILabelProvider;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
+
+import org.eclipse.ui.dialogs.SelectionDialog;
+import org.eclipse.ui.help.WorkbenchHelp;
+
+public class CustomFiltersDialog extends SelectionDialog {
+
+ private static final String SEPARATOR= ","; //$NON-NLS-1$
+
+ private String fViewId;
+ private boolean fEnablePatterns;
+ private String[] fPatterns;
+ private String[] fEnabledFilterIds;
+
+ private FilterDescriptor[] fBuiltInFilters;
+
+ private CheckboxTableViewer fCheckBoxList;
+ private Button fEnableUserDefinedPatterns;
+ private Text fUserDefinedPatterns;
+
+ private Stack fFilterDescriptorChangeHistory;
+
+
+ /**
+ * Creates a dialog to customize Java element filters.
+ *
+ * @param parentShell the parent shell
+ * @param input the root element to populate this dialog with
+ * @param contentProvider the content provider for navigating the model
+ * @param labelProvider the label provider for displaying model elements
+ * @param message the message to be displayed at the top of this dialog, or
+ * <code>null</code> to display a default message
+ */
+ public CustomFiltersDialog(
+ Shell shell,
+ String viewId,
+ boolean enablePatterns,
+ String[] patterns,
+ String[] enabledFilterIds) {
+
+ super(shell);
+ Assert.isNotNull(viewId);
+ Assert.isNotNull(patterns);
+ Assert.isNotNull(enabledFilterIds);
+
+ fViewId= viewId;
+ fPatterns= patterns;
+ fEnablePatterns= enablePatterns;
+ fEnabledFilterIds= enabledFilterIds;
+
+ fBuiltInFilters= FilterDescriptor.getFilterDescriptors(fViewId);
+ fFilterDescriptorChangeHistory= new Stack();
+ setShellStyle(getShellStyle() | SWT.RESIZE);
+ }
+
+ protected void configureShell(Shell shell) {
+ setTitle(FilterMessages.getString("CustomFiltersDialog.title")); //$NON-NLS-1$
+ setMessage(FilterMessages.getString("CustomFiltersDialog.filterList.label")); //$NON-NLS-1$
+ super.configureShell(shell);
+ WorkbenchHelp.setHelp(shell, ICHelpContextIds.CUSTOM_FILTERS_DIALOG);
+ }
+
+ /**
+ * Overrides method in Dialog
+ *
+ * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(Composite)
+ */
+ protected Control createDialogArea(Composite parent) {
+ initializeDialogUnits(parent);
+ // create a composite with standard margins and spacing
+ Composite composite= new Composite(parent, SWT.NONE);
+ GridLayout layout= new GridLayout();
+ layout.marginHeight= convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN);
+ layout.marginWidth= convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN);
+ layout.verticalSpacing= convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING);
+ layout.horizontalSpacing= convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);
+ composite.setLayout(layout);
+ composite.setLayoutData(new GridData(GridData.FILL_BOTH));
+ composite.setFont(parent.getFont());
+ Composite group= composite;
+
+ // Checkbox
+ fEnableUserDefinedPatterns= new Button(group, SWT.CHECK);
+ fEnableUserDefinedPatterns.setText(FilterMessages.getString("CustomFiltersDialog.enableUserDefinedPattern")); //$NON-NLS-1$
+
+ // Pattern field
+ fUserDefinedPatterns= new Text(group, SWT.SINGLE | SWT.BORDER);
+ GridData data= new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.GRAB_HORIZONTAL);
+ data.widthHint= convertWidthInCharsToPixels(59);
+ fUserDefinedPatterns.setLayoutData(data);
+ String patterns= convertToString(fPatterns, SEPARATOR);
+ fUserDefinedPatterns.setText(patterns);
+
+ // Info text
+ final Label info= new Label(group, SWT.LEFT);
+ info.setText(FilterMessages.getString("CustomFiltersDialog.patternInfo")); //$NON-NLS-1$
+
+ // Enabling / disabling of pattern group
+ fEnableUserDefinedPatterns.setSelection(fEnablePatterns);
+ fUserDefinedPatterns.setEnabled(fEnablePatterns);
+ info.setEnabled(fEnablePatterns);
+ fEnableUserDefinedPatterns.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent e) {
+ boolean state= fEnableUserDefinedPatterns.getSelection();
+ fUserDefinedPatterns.setEnabled(state);
+ info.setEnabled(fEnableUserDefinedPatterns.getSelection());
+ if (state)
+ fUserDefinedPatterns.setFocus();
+ }
+ });
+
+ // Filters provided by extension point
+ if (fBuiltInFilters.length > 0)
+ createCheckBoxList(group);
+
+ applyDialogFont(parent);
+ return parent;
+ }
+
+ private void createCheckBoxList(Composite parent) {
+ // Filler
+ new Label(parent, SWT.NONE);
+
+ Label info= new Label(parent, SWT.LEFT);
+ info.setText(FilterMessages.getString("CustomFiltersDialog.filterList.label")); //$NON-NLS-1$
+
+ fCheckBoxList= CheckboxTableViewer.newCheckList(parent, SWT.BORDER);
+ GridData data= new GridData(GridData.FILL_BOTH);
+ data.heightHint= fCheckBoxList.getTable().getItemHeight() * 10;
+ fCheckBoxList.getTable().setLayoutData(data);
+
+ fCheckBoxList.setLabelProvider(createLabelPrivder());
+ fCheckBoxList.setContentProvider(new ArrayContentProvider());
+
+ fCheckBoxList.setInput(fBuiltInFilters);
+ setInitialSelections(getEnabledFilterDescriptors());
+
+ List initialSelection= getInitialElementSelections();
+ if (initialSelection != null && !initialSelection.isEmpty())
+ checkInitialSelections();
+
+ // Description
+ info= new Label(parent, SWT.LEFT);
+ info.setText(FilterMessages.getString("CustomFiltersDialog.description.label")); //$NON-NLS-1$
+ final Text description= new Text(parent, SWT.LEFT | SWT.WRAP | SWT.MULTI | SWT.READ_ONLY | SWT.BORDER | SWT.VERTICAL);
+ data = new GridData(GridData.FILL_HORIZONTAL);
+ data.heightHint= convertHeightInCharsToPixels(3);
+ description.setLayoutData(data);
+ fCheckBoxList.addSelectionChangedListener(new ISelectionChangedListener() {
+ public void selectionChanged(SelectionChangedEvent event) {
+ ISelection selection= event.getSelection();
+ if (selection instanceof IStructuredSelection) {
+ Object selectedElement= ((IStructuredSelection)selection).getFirstElement();
+ if (selectedElement instanceof FilterDescriptor)
+ description.setText(((FilterDescriptor)selectedElement).getDescription());
+ }
+ }
+ });
+ fCheckBoxList.addCheckStateListener(new ICheckStateListener() {
+ /*
+ * @see org.eclipse.jface.viewers.ICheckStateListener#checkStateChanged(org.eclipse.jface.viewers.CheckStateChangedEvent)
+ */
+ public void checkStateChanged(CheckStateChangedEvent event) {
+ Object element= event.getElement();
+ if (element instanceof FilterDescriptor) {
+ // renew if already touched
+ if (fFilterDescriptorChangeHistory.contains(element))
+ fFilterDescriptorChangeHistory.remove(element);
+ fFilterDescriptorChangeHistory.push(element);
+ }
+ }});
+
+ addSelectionButtons(parent);
+ }
+
+ private void addSelectionButtons(Composite composite) {
+ Composite buttonComposite= new Composite(composite, SWT.RIGHT);
+ GridLayout layout= new GridLayout();
+ layout.numColumns= 2;
+ buttonComposite.setLayout(layout);
+ GridData data= new GridData(GridData.HORIZONTAL_ALIGN_END | GridData.GRAB_HORIZONTAL);
+ data.grabExcessHorizontalSpace= true;
+ composite.setData(data);
+
+ // Select All button
+ String label= FilterMessages.getString("CustomFiltersDialog.SelectAllButton.label"); //$NON-NLS-1$
+ Button selectButton= createButton(buttonComposite, IDialogConstants.SELECT_ALL_ID, label, false);
+ SWTUtil.setButtonDimensionHint(selectButton);
+ SelectionListener listener= new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent e) {
+ fCheckBoxList.setAllChecked(true);
+ fFilterDescriptorChangeHistory.clear();
+ for (int i= 0; i < fBuiltInFilters.length; i++)
+ fFilterDescriptorChangeHistory.push(fBuiltInFilters[i]);
+ }
+ };
+ selectButton.addSelectionListener(listener);
+
+ // Deselect All button
+ label= FilterMessages.getString("CustomFiltersDialog.DeselectAllButton.label"); //$NON-NLS-1$
+ Button deselectButton= createButton(buttonComposite, IDialogConstants.DESELECT_ALL_ID, label, false);
+ SWTUtil.setButtonDimensionHint(deselectButton);
+ listener= new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent e) {
+ fCheckBoxList.setAllChecked(false);
+ fFilterDescriptorChangeHistory.clear();
+ for (int i= 0; i < fBuiltInFilters.length; i++)
+ fFilterDescriptorChangeHistory.push(fBuiltInFilters[i]);
+ }
+ };
+ deselectButton.addSelectionListener(listener);
+ }
+
+ private void checkInitialSelections() {
+ Iterator itemsToCheck= getInitialElementSelections().iterator();
+ while (itemsToCheck.hasNext())
+ fCheckBoxList.setChecked(itemsToCheck.next(),true);
+ }
+
+ protected void okPressed() {
+ if (fBuiltInFilters != null) {
+ ArrayList result= new ArrayList();
+ for (int i= 0; i < fBuiltInFilters.length; ++i) {
+ if (fCheckBoxList.getChecked(fBuiltInFilters[i]))
+ result.add(fBuiltInFilters[i]);
+ }
+ setResult(result);
+ }
+ super.okPressed();
+ }
+
+ private ILabelProvider createLabelPrivder() {
+ return
+ new LabelProvider() {
+ public Image getImage(Object element) {
+ return null;
+ }
+ public String getText(Object element) {
+ if (element instanceof FilterDescriptor)
+ return ((FilterDescriptor)element).getName();
+ else
+ return null;
+ }
+ };
+ }
+
+ // ---------- result handling ----------
+
+ protected void setResult(List newResult) {
+ super.setResult(newResult);
+ if (fUserDefinedPatterns.getText().length() > 0) {
+ fEnablePatterns= fEnableUserDefinedPatterns.getSelection();
+ fPatterns= convertFromString(fUserDefinedPatterns.getText(), SEPARATOR);
+ } else {
+ fEnablePatterns= false;
+ fPatterns= new String[0];
+ }
+ }
+
+
+ /**
+ * @return the patterns which have been entered by the user
+ */
+ public String[] getUserDefinedPatterns() {
+ return fPatterns;
+ }
+
+ /**
+ * @return the ids of the enabled built-in filters
+ */
+ public String[] getEnabledFilterIds() {
+ Object[] result= getResult();
+ Set enabledIds= new HashSet(result.length);
+ for (int i= 0; i < result.length; i++)
+ enabledIds.add(((FilterDescriptor)result[i]).getId());
+ return (String[]) enabledIds.toArray(new String[enabledIds.size()]);
+ }
+
+ /**
+ * @return <code>true</code> if the user-defined patterns are disabled
+ */
+ public boolean areUserDefinedPatternsEnabled() {
+ return fEnablePatterns;
+ }
+
+ /**
+ * @return a stack with the filter descriptor check history
+ * @since 3.0
+ */
+ public Stack getFilterDescriptorChangeHistory() {
+ return fFilterDescriptorChangeHistory;
+ }
+
+ private FilterDescriptor[] getEnabledFilterDescriptors() {
+ FilterDescriptor[] filterDescs= fBuiltInFilters;
+ List result= new ArrayList(filterDescs.length);
+ List enabledFilterIds= Arrays.asList(fEnabledFilterIds);
+ for (int i= 0; i < filterDescs.length; i++) {
+ String id= filterDescs[i].getId();
+ if (enabledFilterIds.contains(id))
+ result.add(filterDescs[i]);
+ }
+ return (FilterDescriptor[])result.toArray(new FilterDescriptor[result.size()]);
+ }
+
+
+ public static String[] convertFromString(String patterns, String separator) {
+ StringTokenizer tokenizer= new StringTokenizer(patterns, separator);
+ String[] result= new String[tokenizer.countTokens()];
+ for (int i= 0; i < result.length; i++)
+ result[i]= tokenizer.nextToken().trim();
+ return result;
+ }
+
+ public static String convertToString(String[] patterns, String separator) {
+ int length= patterns.length;
+ StringBuffer strBuf= new StringBuffer();
+ if (length > 0)
+ strBuf.append(patterns[0]);
+ else
+ return ""; //$NON-NLS-1$
+ int i= 1;
+ while (i < length) {
+ strBuf.append(separator);
+ strBuf.append(" "); //$NON-NLS-1$
+ strBuf.append(patterns[i++]);
+ }
+ return strBuf.toString();
+ }
+}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/filters/ExecutableFilter.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/filters/ExecutableFilter.java
new file mode 100644
index 0000000000..9bfc319620
--- /dev/null
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/filters/ExecutableFilter.java
@@ -0,0 +1,41 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2003 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.internal.ui.filters;
+
+import org.eclipse.cdt.core.model.IBinary;
+import org.eclipse.cdt.core.model.IBinaryContainer;
+
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jface.viewers.ViewerFilter;
+
+
+
+/**
+ * The ExecutableFilter is a filter used to determine whether
+ * an executable is shown
+ */
+public class ExecutableFilter extends ViewerFilter {
+
+ /* (non-Javadoc)
+ * Method declared on ViewerFilter.
+ */
+ public boolean select(Viewer viewer, Object parentElement, Object element) {
+ if (element instanceof IBinary) {
+ IBinary bin = (IBinary)element;
+ if (! (parentElement instanceof IBinaryContainer)) {
+ if (bin.isExecutable()) {
+ return false;
+ }
+ }
+ }
+ return true;
+ }
+}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/filters/FilterDescriptor.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/filters/FilterDescriptor.java
new file mode 100644
index 0000000000..f007db9377
--- /dev/null
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/filters/FilterDescriptor.java
@@ -0,0 +1,266 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2003 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.internal.ui.filters;
+
+import java.text.Collator;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.eclipse.cdt.ui.CUIPlugin;
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.IPluginRegistry;
+import org.eclipse.core.runtime.ISafeRunnable;
+import org.eclipse.core.runtime.Platform;
+
+import org.eclipse.jface.util.Assert;
+import org.eclipse.jface.util.SafeRunnable;
+import org.eclipse.jface.viewers.ViewerFilter;
+
+
+/**
+ * Represents a custom filter which is provided by the
+ * "org.eclipse.jdt.ui.javaElementFilters" extension point.
+ *
+ * since 2.0
+ */
+public class FilterDescriptor implements Comparable {
+
+ private static String PATTERN_FILTER_ID_PREFIX= "_patternFilterId_"; //$NON-NLS-1$
+
+
+ private static final String EXTENSION_POINT_NAME= "CElementFilters"; //$NON-NLS-1$
+
+ private static final String FILTER_TAG= "filter"; //$NON-NLS-1$
+
+ private static final String PATTERN_ATTRIBUTE= "pattern"; //$NON-NLS-1$
+ private static final String ID_ATTRIBUTE= "id"; //$NON-NLS-1$
+ /**
+ * @deprecated as of 3.0 use {@link FilterDescriptor#TARGET_ID_ATTRIBUTE}
+ */
+ private static final String VIEW_ID_ATTRIBUTE= "viewId"; //$NON-NLS-1$
+ private static final String TARGET_ID_ATTRIBUTE= "targetId"; //$NON-NLS-1$
+ private static final String CLASS_ATTRIBUTE= "class"; //$NON-NLS-1$
+ private static final String NAME_ATTRIBUTE= "name"; //$NON-NLS-1$
+ private static final String ENABLED_ATTRIBUTE= "enabled"; //$NON-NLS-1$
+ private static final String DESCRIPTION_ATTRIBUTE= "description"; //$NON-NLS-1$
+ /**
+ * @deprecated use "enabled" instead
+ */
+ private static final String SELECTED_ATTRIBUTE= "selected"; //$NON-NLS-1$
+
+ private static FilterDescriptor[] fgFilterDescriptors;
+
+
+ private IConfigurationElement fElement;
+
+ /**
+ * Returns all contributed Java element filters.
+ */
+ public static FilterDescriptor[] getFilterDescriptors() {
+ if (fgFilterDescriptors == null) {
+ IPluginRegistry registry= Platform.getPluginRegistry();
+ IConfigurationElement[] elements= registry.getConfigurationElementsFor(CUIPlugin.PLUGIN_ID, EXTENSION_POINT_NAME);
+ fgFilterDescriptors= createFilterDescriptors(elements);
+ }
+ return fgFilterDescriptors;
+ }
+ /**
+ * Returns all Java element filters which
+ * are contributed to the given view.
+ */
+ public static FilterDescriptor[] getFilterDescriptors(String targetId) {
+ FilterDescriptor[] filterDescs= FilterDescriptor.getFilterDescriptors();
+ List result= new ArrayList(filterDescs.length);
+ for (int i= 0; i < filterDescs.length; i++) {
+ String tid= filterDescs[i].getTargetId();
+ if (tid == null || tid.equals(targetId))
+ result.add(filterDescs[i]);
+ }
+ return (FilterDescriptor[])result.toArray(new FilterDescriptor[result.size()]);
+ }
+
+ /**
+ * Creates a new filter descriptor for the given configuration element.
+ */
+ private FilterDescriptor(IConfigurationElement element) {
+ fElement= element;
+ // it is either a pattern filter or a custom filter
+ Assert.isTrue(isPatternFilter() ^ isCustomFilter(), "An extension for extension-point org.eclipse.cdt.ui.CElementFilters does not specify a correct filter"); //$NON-NLS-1$
+ Assert.isNotNull(getId(), "An extension for extension-point org.eclipse.cdt.ui.CElementFilters does not provide a valid ID"); //$NON-NLS-1$
+ Assert.isNotNull(getName(), "An extension for extension-point org.eclipse.cdt.ui.CElementFilters does not provide a valid name"); //$NON-NLS-1$
+ }
+
+ /**
+ * Creates a new <code>ViewerFilter</code>.
+ * This method is only valid for viewer filters.
+ */
+ public ViewerFilter createViewerFilter() {
+ if (!isCustomFilter())
+ return null;
+
+ final ViewerFilter[] result= new ViewerFilter[1];
+ String message= FilterMessages.getFormattedString("FilterDescriptor.filterCreationError.message", getId()); //$NON-NLS-1$
+ ISafeRunnable code= new SafeRunnable(message) {
+ /*
+ * @see org.eclipse.core.runtime.ISafeRunnable#run()
+ */
+ public void run() throws Exception {
+ result[0]= (ViewerFilter)fElement.createExecutableExtension(CLASS_ATTRIBUTE);
+ }
+
+ };
+ Platform.run(code);
+ return result[0];
+ }
+
+ //---- XML Attribute accessors ---------------------------------------------
+
+ /**
+ * Returns the filter's id.
+ * <p>
+ * This attribute is mandatory for custom filters.
+ * The ID for pattern filters is
+ * PATTERN_FILTER_ID_PREFIX plus the pattern itself.
+ * </p>
+ */
+ public String getId() {
+ if (isPatternFilter()) {
+ String targetId= getTargetId();
+ if (targetId == null)
+ return PATTERN_FILTER_ID_PREFIX + getPattern();
+ else
+ return targetId + PATTERN_FILTER_ID_PREFIX + getPattern();
+ } else
+ return fElement.getAttribute(ID_ATTRIBUTE);
+ }
+
+ /**
+ * Returns the filter's name.
+ * <p>
+ * If the name of a pattern filter is missing
+ * then the pattern is used as its name.
+ * </p>
+ */
+ public String getName() {
+ String name= fElement.getAttribute(NAME_ATTRIBUTE);
+ if (name == null && isPatternFilter())
+ name= getPattern();
+ return name;
+ }
+
+ /**
+ * Returns the filter's pattern.
+ *
+ * @return the pattern string or <code>null</code> if it's not a pattern filter
+ */
+ public String getPattern() {
+ return fElement.getAttribute(PATTERN_ATTRIBUTE);
+ }
+
+ /**
+ * Returns the filter's viewId.
+ *
+ * @return the view ID or <code>null</code> if the filter is for all views
+ * @since 3.0
+ */
+ public String getTargetId() {
+ String tid= fElement.getAttribute(TARGET_ID_ATTRIBUTE);
+
+ if (tid != null)
+ return tid;
+
+ // Backwards compatibility code
+ return fElement.getAttribute(VIEW_ID_ATTRIBUTE);
+
+ }
+
+ /**
+ * Returns the filter's description.
+ *
+ * @return the description or <code>null</code> if no description is provided
+ */
+ public String getDescription() {
+ String description= fElement.getAttribute(DESCRIPTION_ATTRIBUTE);
+ if (description == null)
+ description= ""; //$NON-NLS-1$
+ return description;
+ }
+
+ /**
+ * @return <code>true</code> if this filter is a custom filter.
+ */
+ public boolean isPatternFilter() {
+ return getPattern() != null;
+ }
+
+ /**
+ * @return <code>true</code> if this filter is a pattern filter.
+ */
+ public boolean isCustomFilter() {
+ return fElement.getAttribute(CLASS_ATTRIBUTE) != null;
+ }
+
+ /**
+ * Returns <code>true</code> if the filter
+ * is initially enabled.
+ *
+ * This attribute is optional and defaults to <code>true</code>.
+ */
+ public boolean isEnabled() {
+ String strVal= fElement.getAttribute(ENABLED_ATTRIBUTE);
+ if (strVal == null)
+ // backward compatibility
+ strVal= fElement.getAttribute(SELECTED_ATTRIBUTE);
+ return strVal == null || Boolean.valueOf(strVal).booleanValue();
+ }
+
+ /*
+ * Implements a method from IComparable
+ */
+ public int compareTo(Object o) {
+ if (o instanceof FilterDescriptor)
+ return Collator.getInstance().compare(getName(), ((FilterDescriptor)o).getName());
+ else
+ return Integer.MIN_VALUE;
+ }
+
+ //---- initialization ---------------------------------------------------
+
+ /**
+ * Creates the filter descriptors.
+ */
+ private static FilterDescriptor[] createFilterDescriptors(IConfigurationElement[] elements) {
+ List result= new ArrayList(5);
+ Set descIds= new HashSet(5);
+ for (int i= 0; i < elements.length; i++) {
+ final IConfigurationElement element= elements[i];
+ if (FILTER_TAG.equals(element.getName())) {
+
+ final FilterDescriptor[] desc= new FilterDescriptor[1];
+ Platform.run(new SafeRunnable(FilterMessages.getString("FilterDescriptor.filterDescriptionCreationError.message")) { //$NON-NLS-1$
+ public void run() throws Exception {
+ desc[0]= new FilterDescriptor(element);
+ }
+ });
+
+ if (desc[0] != null && !descIds.contains(desc[0].getId())) {
+ result.add(desc[0]);
+ descIds.add(desc[0].getId());
+ }
+ }
+ }
+ Collections.sort(result);
+ return (FilterDescriptor[])result.toArray(new FilterDescriptor[result.size()]);
+ }
+}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/filters/FilterMessages.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/filters/FilterMessages.java
new file mode 100644
index 0000000000..e52c083a23
--- /dev/null
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/filters/FilterMessages.java
@@ -0,0 +1,64 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2003 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.internal.ui.filters;
+
+import java.text.MessageFormat;
+import java.util.MissingResourceException;
+import java.util.ResourceBundle;
+
+public class FilterMessages {
+
+ private static final String RESOURCE_BUNDLE= FilterMessages.class.getName();
+
+ private static ResourceBundle fgResourceBundle= ResourceBundle.getBundle(RESOURCE_BUNDLE);
+
+ private FilterMessages() {
+ }
+
+ public static String getString(String key) {
+ try {
+ return fgResourceBundle.getString(key);
+ } catch (MissingResourceException e) {
+ return "!" + key + "!";//$NON-NLS-2$ //$NON-NLS-1$
+ }
+ }
+ /**
+ * Gets a string from the resource bundle and formats it with the argument
+ *
+ * @param key the string used to get the bundle value, must not be null
+ */
+ public static String getFormattedString(String key, Object[] args) {
+ String format= null;
+ try {
+ format= fgResourceBundle.getString(key);
+ } catch (MissingResourceException e) {
+ return "!" + key + "!";//$NON-NLS-2$ //$NON-NLS-1$
+ }
+ return MessageFormat.format(format, args);
+ }
+
+ /**
+ * Gets a string from the resource bundle and formats it with the argument
+ *
+ * @param key the string used to get the bundle value, must not be null
+ */
+ public static String getFormattedString(String key, Object arg) {
+ String format= null;
+ try {
+ format= fgResourceBundle.getString(key);
+ } catch (MissingResourceException e) {
+ return "!" + key + "!";//$NON-NLS-2$ //$NON-NLS-1$
+ }
+ if (arg == null)
+ arg= ""; //$NON-NLS-1$
+ return MessageFormat.format(format, new Object[] { arg });
+ }
+}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/filters/FilterMessages.properties b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/filters/FilterMessages.properties
new file mode 100644
index 0000000000..3fb7c951ad
--- /dev/null
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/filters/FilterMessages.properties
@@ -0,0 +1,24 @@
+###############################################################################
+# Copyright (c) 2000, 2003 IBM Corporation and others.
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Common Public License v1.0
+# which accompanies this distribution, and is available at
+# http://www.eclipse.org/legal/cpl-v10.html
+#
+# Contributors:
+# IBM Corporation - initial API and implementation
+###############################################################################
+
+CustomFiltersDialog.title= C Element Filters
+CustomFiltersDialog.patternInfo= The patterns are separated by comma (* = any string, ? = any character)
+CustomFiltersDialog.enableUserDefinedPattern= &Name filter patterns (matching names will be hidden):
+CustomFiltersDialog.filterList.label= S&elect the elements to exclude from the view:
+CustomFiltersDialog.description.label= Filter description:
+CustomFiltersDialog.SelectAllButton.label= &Select All
+CustomFiltersDialog.DeselectAllButton.label= &Deselect All
+
+OpenCustomFiltersDialogAction.text= &Filters...
+
+FilterDescriptor.filterDescriptionCreationError.message= One of the extensions for extension-point org.eclipse.cdt.ui.CElementFilters is incorrect.
+FilterDescriptor.filterCreationError.title= Filter Creation Error
+FilterDescriptor.filterCreationError.message= The org.eclipse.cdt.ui.CElementFilters plug-in extension "{0}" specifies a viewer filter class which does not exist.
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/filters/NamePatternFilter.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/filters/NamePatternFilter.java
new file mode 100644
index 0000000000..8d2f643d10
--- /dev/null
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/filters/NamePatternFilter.java
@@ -0,0 +1,96 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2003 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.internal.ui.filters;
+
+import org.eclipse.cdt.core.model.ICElement;
+import org.eclipse.cdt.internal.ui.util.StringMatcher;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.IAdaptable;
+
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jface.viewers.ViewerFilter;
+
+/**
+ * The NamePatternFilter selects the elements which
+ * match the given string patterns.
+ * <p>
+ * The following characters have special meaning:
+ * ? => any character
+ * * => any string
+ * </p>
+ *
+ * @since 2.0
+ */
+public class NamePatternFilter extends ViewerFilter {
+ private String[] fPatterns;
+ private StringMatcher[] fMatchers;
+
+ /**
+ * Return the currently configured StringMatchers.
+ */
+ private StringMatcher[] getMatchers() {
+ return fMatchers;
+ }
+
+ /**
+ * Gets the patterns for the receiver.
+ */
+ public String[] getPatterns() {
+ return fPatterns;
+ }
+
+
+ /* (non-Javadoc)
+ * Method declared on ViewerFilter.
+ */
+ public boolean select(Viewer viewer, Object parentElement, Object element) {
+ String matchName= null;
+ if (element instanceof ICElement) {
+ matchName= ((ICElement) element).getElementName();
+ } else if (element instanceof IAdaptable) {
+ IAdaptable adaptable= (IAdaptable) element;
+ ICElement javaElement= (ICElement)adaptable.getAdapter(ICElement.class);
+ if (javaElement != null)
+ matchName= javaElement.getElementName();
+ else {
+ IResource resource= (IResource)adaptable.getAdapter(IResource.class);
+ if (resource != null)
+ matchName= resource.getName();
+ }
+ }
+ if (matchName != null) {
+ StringMatcher[] testMatchers= getMatchers();
+ for (int i = 0; i < testMatchers.length; i++) {
+ if (testMatchers[i].match(matchName))
+ return false;
+ }
+ return true;
+ }
+ return true;
+ }
+
+ /**
+ * Sets the patterns to filter out for the receiver.
+ * <p>
+ * The following characters have special meaning:
+ * ? => any character
+ * * => any string
+ * </p>
+ */
+ public void setPatterns(String[] newPatterns) {
+ fPatterns = newPatterns;
+ fMatchers = new StringMatcher[newPatterns.length];
+ for (int i = 0; i < newPatterns.length; i++) {
+ //Reset the matchers to prevent constructor overhead
+ fMatchers[i]= new StringMatcher(newPatterns[i], true, false);
+ }
+ }
+}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/filters/NonCElementFilter.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/filters/NonCElementFilter.java
new file mode 100644
index 0000000000..a65c3acd51
--- /dev/null
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/filters/NonCElementFilter.java
@@ -0,0 +1,50 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2003 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.internal.ui.filters;
+
+import org.eclipse.cdt.core.model.ICElement;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IStorage;
+
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jface.viewers.ViewerFilter;
+
+
+
+/**
+ * Filters out all non-Java elements.
+ */
+public class NonCElementFilter extends ViewerFilter {
+
+ /**
+ * Returns the result of this filter, when applied to the
+ * given inputs.
+ *
+ * @param inputs the set of elements to
+ * @return Returns true if element should be included in filtered set
+ */
+ public boolean select(Viewer viewer, Object parent, Object element) {
+ if (element instanceof ICElement)
+ return true;
+
+ if (element instanceof IResource) {
+ IProject project= ((IResource)element).getProject();
+ return project == null || !project.isOpen();
+ }
+
+ // Exclude all IStorage elements which are neither Java elements nor resources
+ if (element instanceof IStorage)
+ return false;
+
+ return true;
+ }
+}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/filters/ObjectFilter.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/filters/ObjectFilter.java
new file mode 100644
index 0000000000..904cadfa0d
--- /dev/null
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/filters/ObjectFilter.java
@@ -0,0 +1,41 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2003 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.internal.ui.filters;
+
+import org.eclipse.cdt.core.model.IBinary;
+import org.eclipse.cdt.core.model.IBinaryContainer;
+
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jface.viewers.ViewerFilter;
+
+
+
+/**
+ * The ObjectFilter is a filter used to determine whether
+ * a Object is shown
+ */
+public class ObjectFilter extends ViewerFilter {
+
+ /* (non-Javadoc)
+ * Method declared on ViewerFilter.
+ */
+ public boolean select(Viewer viewer, Object parentElement, Object element) {
+ if (element instanceof IBinary) {
+ IBinary bin = (IBinary)element;
+ if (! (parentElement instanceof IBinaryContainer)) {
+ if (bin.isObject()) {
+ return false;
+ }
+ }
+ }
+ return true;
+ }
+}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/filters/SharedFilter.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/filters/SharedFilter.java
new file mode 100644
index 0000000000..937024af39
--- /dev/null
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/filters/SharedFilter.java
@@ -0,0 +1,41 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2003 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.internal.ui.filters;
+
+import org.eclipse.cdt.core.model.IBinary;
+import org.eclipse.cdt.core.model.IBinaryContainer;
+
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jface.viewers.ViewerFilter;
+
+
+
+/**
+ * The SharedFilter is a filter used to determine whether
+ * a Shared object is shown
+ */
+public class SharedFilter extends ViewerFilter {
+
+ /* (non-Javadoc)
+ * Method declared on ViewerFilter.
+ */
+ public boolean select(Viewer viewer, Object parentElement, Object element) {
+ if (element instanceof IBinary) {
+ IBinary bin = (IBinary)element;
+ if (! (parentElement instanceof IBinaryContainer)) {
+ if (bin.isSharedLib()) {
+ return false;
+ }
+ }
+ }
+ return true;
+ }
+}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/actions/CustomFiltersActionGroup.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/actions/CustomFiltersActionGroup.java
new file mode 100644
index 0000000000..557d07f3ee
--- /dev/null
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/actions/CustomFiltersActionGroup.java
@@ -0,0 +1,726 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2003 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.ui.actions;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.SortedSet;
+import java.util.Stack;
+import java.util.StringTokenizer;
+import java.util.TreeSet;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.widgets.Menu;
+import org.eclipse.swt.widgets.MenuItem;
+
+import org.eclipse.cdt.core.model.ICModel;
+import org.eclipse.cdt.internal.ui.filters.CustomFiltersDialog;
+import org.eclipse.cdt.internal.ui.filters.FilterDescriptor;
+import org.eclipse.cdt.internal.ui.filters.FilterMessages;
+import org.eclipse.cdt.internal.ui.filters.NamePatternFilter;
+import org.eclipse.cdt.ui.CUIPlugin;
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.action.ContributionItem;
+import org.eclipse.jface.action.GroupMarker;
+import org.eclipse.jface.action.IContributionItem;
+import org.eclipse.jface.action.IMenuListener;
+import org.eclipse.jface.action.IMenuManager;
+import org.eclipse.jface.action.IToolBarManager;
+import org.eclipse.jface.action.Separator;
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.jface.util.Assert;
+import org.eclipse.jface.viewers.IContentProvider;
+import org.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.jface.viewers.StructuredViewer;
+import org.eclipse.jface.viewers.ViewerFilter;
+import org.eclipse.jface.window.Window;
+
+import org.eclipse.ui.IActionBars;
+import org.eclipse.ui.IMemento;
+import org.eclipse.ui.IViewPart;
+import org.eclipse.ui.actions.ActionGroup;
+
+/**
+ * Action group to add the filter action to a view part's tool bar
+ * menu.
+ * <p>
+ * This class may be instantiated; it is not intended to be subclassed.
+ * </p>
+ *
+ * @since 2.0
+ */
+public class CustomFiltersActionGroup extends ActionGroup {
+
+ class ShowFilterDialogAction extends Action {
+ ShowFilterDialogAction() {
+ setText(FilterMessages.getString("OpenCustomFiltersDialogAction.text")); //$NON-NLS-1$
+ //setImageDescriptor(CPluginImages.DESC_CLCL_FILTER);
+ }
+
+ public void run() {
+ openDialog();
+ }
+ }
+
+ /**
+ * Menu contribution item which shows and lets check and uncheck filters.
+ *
+ * @since 3.0
+ */
+ class FilterActionMenuContributionItem extends ContributionItem {
+
+ private int fItemNumber;
+ private boolean fState;
+ private String fFilterId;
+ private String fFilterName;
+ private CustomFiltersActionGroup fActionGroup;
+
+ /**
+ * Constructor for FilterActionMenuContributionItem.
+ *
+ * @param actionGroup the action group
+ * @param filterId the id of the filter
+ * @param filterName the name of the filter
+ * @param state the initial state of the filter
+ * @param itemNumber the menu item index
+ */
+ public FilterActionMenuContributionItem(CustomFiltersActionGroup actionGroup, String filterId, String filterName, boolean state, int itemNumber) {
+ super(filterId);
+ Assert.isNotNull(actionGroup);
+ Assert.isNotNull(filterId);
+ Assert.isNotNull(filterName);
+ fActionGroup= actionGroup;
+ fFilterId= filterId;
+ fFilterName= filterName;
+ fState= state;
+ fItemNumber= itemNumber;
+ }
+
+ /*
+ * Overrides method from ContributionItem.
+ */
+ public void fill(Menu menu, int index) {
+ MenuItem mi= new MenuItem(menu, SWT.CHECK, index);
+ mi.setText("&" + fItemNumber + " " + fFilterName); //$NON-NLS-1$ //$NON-NLS-2$
+ /*
+ * XXX: Don't set the image - would look bad because other menu items don't provide image
+ * XXX: Get working set specific image name from XML - would need to cache icons
+ */
+// mi.setImage(JavaPluginImages.get(JavaPluginImages.IMG_OBJS_JAVA_WORKING_SET));
+ mi.setSelection(fState);
+ mi.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent e) {
+ fState= !fState;
+ fActionGroup.setFilter(fFilterId, fState);
+ }
+ });
+ }
+
+ /*
+ * @see org.eclipse.jface.action.IContributionItem#isDynamic()
+ */
+ public boolean isDynamic() {
+ return true;
+ }
+ }
+
+ private static final String TAG_CUSTOM_FILTERS = "customFilters"; //$NON-NLS-1$
+ private static final String TAG_USER_DEFINED_PATTERNS_ENABLED= "userDefinedPatternsEnabled"; //$NON-NLS-1$
+ private static final String TAG_USER_DEFINED_PATTERNS= "userDefinedPatterns"; //$NON-NLS-1$
+ private static final String TAG_XML_DEFINED_FILTERS= "xmlDefinedFilters"; //$NON-NLS-1$
+ private static final String TAG_LRU_FILTERS = "lastRecentlyUsedFilters"; //$NON-NLS-1$
+
+ private static final String TAG_CHILD= "child"; //$NON-NLS-1$
+ private static final String TAG_PATTERN= "pattern"; //$NON-NLS-1$
+ private static final String TAG_FILTER_ID= "filterId"; //$NON-NLS-1$
+ private static final String TAG_IS_ENABLED= "isEnabled"; //$NON-NLS-1$
+
+ private static final String SEPARATOR= ","; //$NON-NLS-1$
+
+ private static final int MAX_FILTER_MENU_ENTRIES= 3;
+ private static final String RECENT_FILTERS_GROUP_NAME= "recentFiltersGroup"; //$NON-NLS-1$
+
+ private StructuredViewer fViewer;
+
+ private NamePatternFilter fPatternFilter;
+ private Map fInstalledBuiltInFilters;
+
+ private Map fEnabledFilterIds;
+ private boolean fUserDefinedPatternsEnabled;
+ private String[] fUserDefinedPatterns;
+ /**
+ * Recently changed filter Ids stack with oldest on top (i.e. at the end).
+ *
+ * @since 3.0
+ */
+ private Stack fLRUFilterIdsStack;
+ /**
+ * Handle to menu manager to dynamically update
+ * the last recently used filters.
+ *
+ * @since 3.0
+ */
+ private IMenuManager fMenuManager;
+ /**
+ * The menu listener which dynamically updates
+ * the last recently used filters.
+ *
+ * @since 3.0
+ */
+ private IMenuListener fMenuListener;
+ /**
+ * Filter Ids used in the last view menu invocation.
+ *
+ * @since 3.0
+ */
+ private String[] fFilterIdsUsedInLastViewMenu;
+ private HashMap fFilterDescriptorMap;
+ private String fTargetId;
+
+ /**
+ * Creates a new <code>CustomFiltersActionGroup</code>.
+ *
+ * @param part the view part that owns this action group
+ * @param viewer the viewer to be filtered
+ */
+ public CustomFiltersActionGroup(IViewPart part, StructuredViewer viewer) {
+ this(part.getViewSite().getId(), viewer);
+ }
+
+ /**
+ * Creates a new <code>CustomFiltersActionGroup</code>.
+ *
+ * @param ownerId the id of this action group's owner
+ * @param viewer the viewer to be filtered
+ */
+ public CustomFiltersActionGroup(String ownerId, StructuredViewer viewer) {
+ Assert.isNotNull(ownerId);
+ Assert.isNotNull(viewer);
+ fTargetId= ownerId;
+ fViewer= viewer;
+
+ fLRUFilterIdsStack= new Stack();
+
+ initializeWithPluginContributions();
+ initializeWithViewDefaults();
+
+ installFilters();
+ }
+
+ /*
+ * Method declared on ActionGroup.
+ */
+ public void fillActionBars(IActionBars actionBars) {
+ fillToolBar(actionBars.getToolBarManager());
+ fillViewMenu(actionBars.getMenuManager());
+ }
+
+ public String[] removeFiltersFor(Object parent, Object element, IContentProvider contentProvider) {
+ String[] enabledFilters= getEnabledFilterIds();
+ Set newFilters= new HashSet();
+ for (int i= 0; i < enabledFilters.length; i++) {
+ String filterName= enabledFilters[i];
+ ViewerFilter filter= (ViewerFilter) fInstalledBuiltInFilters.get(filterName);
+ if (filter == null)
+ newFilters.add(filterName);
+ else if (isSelected(parent, element, contentProvider, filter))
+ newFilters.add(filterName);
+ }
+ if (newFilters.size() == enabledFilters.length)
+ return new String[0];
+ return (String[])newFilters.toArray(new String[newFilters.size()]);
+ }
+
+ public void setFilters(String[] newFilters) {
+ setEnabledFilterIds(newFilters);
+ updateViewerFilters(true);
+ }
+
+ private boolean isSelected(Object parent, Object element, IContentProvider contentProvider, ViewerFilter filter) {
+ if (contentProvider instanceof ITreeContentProvider) {
+ // the element and all its parents have to be selected
+ ITreeContentProvider provider = (ITreeContentProvider) contentProvider;
+ while (element != null && !(element instanceof ICModel)) {
+ if (!filter.select(fViewer, parent, element))
+ return false;
+ element= provider.getParent( element);
+ }
+ return true;
+ }
+ return filter.select(fViewer, parent, element);
+ }
+
+ /**
+ * Sets the enable state of the given filter.
+ *
+ * @param filterId the id of the filter
+ * @param state the filter state
+ */
+ private void setFilter(String filterId, boolean state) {
+ // Renew filter id in LRU stack
+ fLRUFilterIdsStack.remove(filterId);
+ fLRUFilterIdsStack.add(0, filterId);
+
+ fEnabledFilterIds.put(filterId, new Boolean(state));
+ storeViewDefaults();
+
+ updateViewerFilters(true);
+ }
+
+ private String[] getEnabledFilterIds() {
+ Set enabledFilterIds= new HashSet(fEnabledFilterIds.size());
+ Iterator iter= fEnabledFilterIds.entrySet().iterator();
+ while (iter.hasNext()) {
+ Map.Entry entry= (Map.Entry)iter.next();
+ String id= (String)entry.getKey();
+ boolean isEnabled= ((Boolean)entry.getValue()).booleanValue();
+ if (isEnabled)
+ enabledFilterIds.add(id);
+ }
+ return (String[])enabledFilterIds.toArray(new String[enabledFilterIds.size()]);
+ }
+
+
+ private void setEnabledFilterIds(String[] enabledIds) {
+ Iterator iter= fEnabledFilterIds.keySet().iterator();
+ while (iter.hasNext()) {
+ String id= (String)iter.next();
+ fEnabledFilterIds.put(id, Boolean.FALSE);
+ }
+ for (int i= 0; i < enabledIds.length; i++)
+ fEnabledFilterIds.put(enabledIds[i], Boolean.TRUE);
+ }
+
+ private void setUserDefinedPatterns(String[] patterns) {
+ fUserDefinedPatterns= patterns;
+ cleanUpPatternDuplicates();
+ }
+
+ /**
+ * Sets the recently changed filters.
+ *
+ * @param changeHistory the change history
+ * @since 3.0
+ */
+ private void setRecentlyChangedFilters(Stack changeHistory) {
+ Stack oldestFirstStack= new Stack();
+
+ int length= Math.min(changeHistory.size(), MAX_FILTER_MENU_ENTRIES);
+ for (int i= 0; i < length; i++)
+ oldestFirstStack.push(((FilterDescriptor)changeHistory.pop()).getId());
+
+ length= Math.min(fLRUFilterIdsStack.size(), MAX_FILTER_MENU_ENTRIES - oldestFirstStack.size());
+ int NEWEST= 0;
+ for (int i= 0; i < length; i++) {
+ Object filter= fLRUFilterIdsStack.remove(NEWEST);
+ if (!oldestFirstStack.contains(filter))
+ oldestFirstStack.push(filter);
+ }
+ fLRUFilterIdsStack= oldestFirstStack;
+ }
+
+ private boolean areUserDefinedPatternsEnabled() {
+ return fUserDefinedPatternsEnabled;
+ }
+
+ private void setUserDefinedPatternsEnabled(boolean state) {
+ fUserDefinedPatternsEnabled= state;
+ }
+
+ private void fillToolBar(IToolBarManager tooBar) {
+ }
+
+ public void fillViewMenu(IMenuManager viewMenu) {
+ /*
+ * Don't change the separator group name.
+ * Using this name ensures that other filters
+ * get contributed to the same group.
+ */
+ viewMenu.add(new Separator("filters")); //$NON-NLS-1$
+ viewMenu.add(new GroupMarker(RECENT_FILTERS_GROUP_NAME));
+ viewMenu.add(new ShowFilterDialogAction());
+
+ fMenuManager= viewMenu;
+ fMenuListener= new IMenuListener() {
+ public void menuAboutToShow(IMenuManager manager) {
+ removePreviousLRUFilterActions(manager);
+ addLRUFilterActions(manager);
+ }
+ };
+ fMenuManager.addMenuListener(fMenuListener);
+ }
+
+ private void removePreviousLRUFilterActions(IMenuManager mm) {
+ if (fFilterIdsUsedInLastViewMenu == null)
+ return;
+
+ for (int i= 0; i < fFilterIdsUsedInLastViewMenu.length; i++)
+ mm.remove(fFilterIdsUsedInLastViewMenu[i]);
+ }
+
+ private void addLRUFilterActions(IMenuManager mm) {
+ if (fLRUFilterIdsStack.isEmpty()) {
+ fFilterIdsUsedInLastViewMenu= null;
+ return;
+ }
+
+ SortedSet sortedFilters= new TreeSet(fLRUFilterIdsStack);
+ String[] recentlyChangedFilterIds= (String[])sortedFilters.toArray(new String[sortedFilters.size()]);
+
+ fFilterIdsUsedInLastViewMenu= new String[recentlyChangedFilterIds.length];
+ for (int i= 0; i < recentlyChangedFilterIds.length; i++) {
+ String id= recentlyChangedFilterIds[i];
+ fFilterIdsUsedInLastViewMenu[i]= id;
+ boolean state= fEnabledFilterIds.containsKey(id) && ((Boolean)fEnabledFilterIds.get(id)).booleanValue();
+ FilterDescriptor filterDesc= (FilterDescriptor)fFilterDescriptorMap.get(id);
+ if (filterDesc != null) {
+ IContributionItem item= new FilterActionMenuContributionItem(this, id, filterDesc.getName(), state, i+1);
+ mm.insertBefore(RECENT_FILTERS_GROUP_NAME, item);
+ }
+ }
+ }
+
+ /*
+ * Method declared on ActionGroup.
+ */
+ public void dispose() {
+ if (fMenuManager != null)
+ fMenuManager.removeMenuListener(fMenuListener);
+ super.dispose();
+ }
+
+ private void initializeWithPluginContributions() {
+ fUserDefinedPatterns= new String[0];
+ fUserDefinedPatternsEnabled= false;
+
+ FilterDescriptor[] filterDescs= FilterDescriptor.getFilterDescriptors(fTargetId);
+ fFilterDescriptorMap= new HashMap(filterDescs.length);
+ fEnabledFilterIds= new HashMap(filterDescs.length);
+ for (int i= 0; i < filterDescs.length; i++) {
+ String id= filterDescs[i].getId();
+ Boolean isEnabled= new Boolean(filterDescs[i].isEnabled());
+ //if (fEnabledFilterIds.containsKey(id))
+ // CUIPlugin.getDefault().log(new Status("WARNING: Duplicate id for extension-point \"org.eclipse.jdt.ui.CElementFilters\"")); //$NON-NLS-1$
+ fEnabledFilterIds.put(id, isEnabled);
+ fFilterDescriptorMap.put(id, filterDescs[i]);
+ }
+ }
+
+ // ---------- viewer filter handling ----------
+
+ private void installFilters() {
+ fInstalledBuiltInFilters= new HashMap(fEnabledFilterIds.size());
+ fPatternFilter= new NamePatternFilter();
+ fPatternFilter.setPatterns(getUserAndBuiltInPatterns());
+ fViewer.addFilter(fPatternFilter);
+ updateBuiltInFilters();
+ }
+
+ private void updateViewerFilters(boolean refresh) {
+ String[] patterns= getUserAndBuiltInPatterns();
+ fPatternFilter.setPatterns(patterns);
+ fViewer.getControl().setRedraw(false);
+ updateBuiltInFilters();
+ if (refresh)
+ fViewer.refresh();
+ fViewer.getControl().setRedraw(true);
+ }
+
+ private void updateBuiltInFilters() {
+ Set installedFilters= fInstalledBuiltInFilters.keySet();
+ Set filtersToAdd= new HashSet(fEnabledFilterIds.size());
+ Set filtersToRemove= new HashSet(fEnabledFilterIds.size());
+ Iterator iter= fEnabledFilterIds.entrySet().iterator();
+ while (iter.hasNext()) {
+ Map.Entry entry= (Map.Entry)iter.next();
+ String id= (String)entry.getKey();
+ boolean isEnabled= ((Boolean)entry.getValue()).booleanValue();
+ if (isEnabled && !installedFilters.contains(id))
+ filtersToAdd.add(id);
+ else if (!isEnabled && installedFilters.contains(id))
+ filtersToRemove.add(id);
+ }
+
+ // Install the filters
+ FilterDescriptor[] filterDescs= FilterDescriptor.getFilterDescriptors(fTargetId);
+ for (int i= 0; i < filterDescs.length; i++) {
+ String id= filterDescs[i].getId();
+ // just to double check - id should denote a custom filter anyway
+ boolean isCustomFilter= filterDescs[i].isCustomFilter();
+ if (isCustomFilter) {
+ if (filtersToAdd.contains(id)) {
+ ViewerFilter filter= filterDescs[i].createViewerFilter();
+ if (filter != null) {
+ fViewer.addFilter(filter);
+ fInstalledBuiltInFilters.put(id, filter);
+ }
+ }
+ if (filtersToRemove.contains(id)) {
+ fViewer.removeFilter((ViewerFilter)fInstalledBuiltInFilters.get(id));
+ fInstalledBuiltInFilters.remove(id);
+ }
+ }
+ }
+ }
+
+ private String[] getUserAndBuiltInPatterns() {
+ List patterns= new ArrayList(fUserDefinedPatterns.length);
+ if (areUserDefinedPatternsEnabled())
+ patterns.addAll(Arrays.asList(fUserDefinedPatterns));
+ FilterDescriptor[] filterDescs= FilterDescriptor.getFilterDescriptors(fTargetId);
+ for (int i= 0; i < filterDescs.length; i++) {
+ String id= filterDescs[i].getId();
+ boolean isPatternFilter= filterDescs[i].isPatternFilter();
+ Object isEnabled= fEnabledFilterIds.get(id);
+ if (isEnabled != null && isPatternFilter && ((Boolean)isEnabled).booleanValue())
+ patterns.add(filterDescs[i].getPattern());
+ }
+ return (String[])patterns.toArray(new String[patterns.size()]);
+ }
+
+ // ---------- view kind/defaults persistency ----------
+
+ private void initializeWithViewDefaults() {
+ // get default values for view
+ IPreferenceStore store= CUIPlugin.getDefault().getPreferenceStore();
+
+ // XXX: can be removed once bug 22533 is fixed.
+ if (!store.contains(getPreferenceKey("TAG_DUMMY_TO_TEST_EXISTENCE")))//$NON-NLS-1$
+ return;
+
+ // XXX: Uncomment once bug 22533 is fixed.
+// if (!store.contains(getPreferenceKey(TAG_USER_DEFINED_PATTERNS_ENABLED)))
+// return;
+
+ fUserDefinedPatternsEnabled= store.getBoolean(getPreferenceKey(TAG_USER_DEFINED_PATTERNS_ENABLED));
+ setUserDefinedPatterns(CustomFiltersDialog.convertFromString(store.getString(getPreferenceKey(TAG_USER_DEFINED_PATTERNS)), SEPARATOR));
+
+ Iterator iter= fEnabledFilterIds.keySet().iterator();
+ while (iter.hasNext()) {
+ String id= (String)iter.next();
+ Boolean isEnabled= new Boolean(store.getBoolean(id));
+ fEnabledFilterIds.put(id, isEnabled);
+ }
+
+ fLRUFilterIdsStack.clear();
+ String lruFilterIds= store.getString(TAG_LRU_FILTERS);
+ StringTokenizer tokenizer= new StringTokenizer(lruFilterIds, SEPARATOR);
+ while (tokenizer.hasMoreTokens()) {
+ String id= tokenizer.nextToken();
+ if (fFilterDescriptorMap.containsKey(id) && !fLRUFilterIdsStack.contains(id));
+ fLRUFilterIdsStack.push(id);
+ }
+ }
+
+ private void storeViewDefaults() {
+ // get default values for view
+ IPreferenceStore store= CUIPlugin.getDefault().getPreferenceStore();
+
+ // XXX: can be removed once bug 22533 is fixed.
+ store.setValue(getPreferenceKey("TAG_DUMMY_TO_TEST_EXISTENCE"), "storedViewPreferences");//$NON-NLS-1$//$NON-NLS-2$
+
+ store.setValue(getPreferenceKey(TAG_USER_DEFINED_PATTERNS_ENABLED), fUserDefinedPatternsEnabled);
+ store.setValue(getPreferenceKey(TAG_USER_DEFINED_PATTERNS), CustomFiltersDialog.convertToString(fUserDefinedPatterns ,SEPARATOR));
+
+ Iterator iter= fEnabledFilterIds.entrySet().iterator();
+ while (iter.hasNext()) {
+ Map.Entry entry= (Map.Entry)iter.next();
+ String id= (String)entry.getKey();
+ boolean isEnabled= ((Boolean)entry.getValue()).booleanValue();
+ store.setValue(id, isEnabled);
+ }
+
+ StringBuffer buf= new StringBuffer(fLRUFilterIdsStack.size() * 20);
+ iter= fLRUFilterIdsStack.iterator();
+ while (iter.hasNext()) {
+ buf.append((String)iter.next());
+ buf.append(SEPARATOR);
+ }
+ store.setValue(TAG_LRU_FILTERS, buf.toString());
+ }
+
+ private String getPreferenceKey(String tag) {
+ return "CustomFiltersActionGroup." + fTargetId + '.' + tag; //$NON-NLS-1$
+ }
+
+ // ---------- view instance persistency ----------
+
+ /**
+ * Saves the state of the custom filters in a memento.
+ *
+ * @param memento the memento into which the state is saved
+ */
+ public void saveState(IMemento memento) {
+ IMemento customFilters= memento.createChild(TAG_CUSTOM_FILTERS);
+ customFilters.putString(TAG_USER_DEFINED_PATTERNS_ENABLED, new Boolean(fUserDefinedPatternsEnabled).toString());
+ saveUserDefinedPatterns(customFilters);
+ saveXmlDefinedFilters(customFilters);
+ saveLRUFilters(customFilters);
+ }
+
+ private void saveXmlDefinedFilters(IMemento memento) {
+ if(fEnabledFilterIds != null && !fEnabledFilterIds.isEmpty()) {
+ IMemento xmlDefinedFilters= memento.createChild(TAG_XML_DEFINED_FILTERS);
+ Iterator iter= fEnabledFilterIds.entrySet().iterator();
+ while (iter.hasNext()) {
+ Map.Entry entry= (Map.Entry)iter.next();
+ String id= (String)entry.getKey();
+ Boolean isEnabled= (Boolean)entry.getValue();
+ IMemento child= xmlDefinedFilters.createChild(TAG_CHILD);
+ child.putString(TAG_FILTER_ID, id);
+ child.putString(TAG_IS_ENABLED, isEnabled.toString());
+ }
+ }
+ }
+ /**
+ * Stores the last recently used filter Ids into
+ * the given memento
+ *
+ * @param memento the memento into which to store the LRU filter Ids
+ * @since 3.0
+ */
+ private void saveLRUFilters(IMemento memento) {
+ if(fLRUFilterIdsStack != null && !fLRUFilterIdsStack.isEmpty()) {
+ IMemento lruFilters= memento.createChild(TAG_LRU_FILTERS);
+ Iterator iter= fLRUFilterIdsStack.iterator();
+ while (iter.hasNext()) {
+ String id= (String)iter.next();
+ IMemento child= lruFilters.createChild(TAG_CHILD);
+ child.putString(TAG_FILTER_ID, id);
+ }
+ }
+ }
+
+ private void saveUserDefinedPatterns(IMemento memento) {
+ if(fUserDefinedPatterns != null && fUserDefinedPatterns.length > 0) {
+ IMemento userDefinedPatterns= memento.createChild(TAG_USER_DEFINED_PATTERNS);
+ for (int i= 0; i < fUserDefinedPatterns.length; i++) {
+ IMemento child= userDefinedPatterns.createChild(TAG_CHILD);
+ child.putString(TAG_PATTERN, fUserDefinedPatterns[i]);
+ }
+ }
+ }
+
+ /**
+ * Restores the state of the filter actions from a memento.
+ * <p>
+ * Note: This method does not refresh the viewer.
+ * </p>
+ *
+ * @param memento the memento from which the state is restored
+ */
+ public void restoreState(IMemento memento) {
+ if (memento == null)
+ return;
+ IMemento customFilters= memento.getChild(TAG_CUSTOM_FILTERS);
+ if (customFilters == null)
+ return;
+ String userDefinedPatternsEnabled= customFilters.getString(TAG_USER_DEFINED_PATTERNS_ENABLED);
+ if (userDefinedPatternsEnabled == null)
+ return;
+
+ fUserDefinedPatternsEnabled= Boolean.valueOf(userDefinedPatternsEnabled).booleanValue();
+ restoreUserDefinedPatterns(customFilters);
+ restoreXmlDefinedFilters(customFilters);
+ restoreLRUFilters(customFilters);
+
+ updateViewerFilters(false);
+ }
+
+ private void restoreUserDefinedPatterns(IMemento memento) {
+ IMemento userDefinedPatterns= memento.getChild(TAG_USER_DEFINED_PATTERNS);
+ if(userDefinedPatterns != null) {
+ IMemento children[]= userDefinedPatterns.getChildren(TAG_CHILD);
+ String[] patterns= new String[children.length];
+ for (int i = 0; i < children.length; i++)
+ patterns[i]= children[i].getString(TAG_PATTERN);
+
+ setUserDefinedPatterns(patterns);
+ } else
+ setUserDefinedPatterns(new String[0]);
+ }
+
+ private void restoreXmlDefinedFilters(IMemento memento) {
+ IMemento xmlDefinedFilters= memento.getChild(TAG_XML_DEFINED_FILTERS);
+ if(xmlDefinedFilters != null) {
+ IMemento[] children= xmlDefinedFilters.getChildren(TAG_CHILD);
+ for (int i= 0; i < children.length; i++) {
+ String id= children[i].getString(TAG_FILTER_ID);
+ Boolean isEnabled= new Boolean(children[i].getString(TAG_IS_ENABLED));
+ fEnabledFilterIds.put(id, isEnabled);
+ }
+ }
+ }
+
+ private void restoreLRUFilters(IMemento memento) {
+ IMemento lruFilters= memento.getChild(TAG_LRU_FILTERS);
+ fLRUFilterIdsStack.clear();
+ if(lruFilters != null) {
+ IMemento[] children= lruFilters.getChildren(TAG_CHILD);
+ for (int i= 0; i < children.length; i++) {
+ String id= children[i].getString(TAG_FILTER_ID);
+ if (fFilterDescriptorMap.containsKey(id) && !fLRUFilterIdsStack.contains(id))
+ fLRUFilterIdsStack.push(id);
+ }
+ }
+ }
+
+ private void cleanUpPatternDuplicates() {
+ if (!areUserDefinedPatternsEnabled())
+ return;
+ List userDefinedPatterns= new ArrayList(Arrays.asList(fUserDefinedPatterns));
+ FilterDescriptor[] filters= FilterDescriptor.getFilterDescriptors(fTargetId);
+
+ for (int i= 0; i < filters.length; i++) {
+ if (filters[i].isPatternFilter()) {
+ String pattern= filters[i].getPattern();
+ if (userDefinedPatterns.contains(pattern)) {
+ fEnabledFilterIds.put(filters[i].getId(), Boolean.TRUE);
+ boolean hasMore= true;
+ while (hasMore)
+ hasMore= userDefinedPatterns.remove(pattern);
+ }
+ }
+ }
+ fUserDefinedPatterns= (String[])userDefinedPatterns.toArray(new String[userDefinedPatterns.size()]);
+ setUserDefinedPatternsEnabled(fUserDefinedPatternsEnabled && fUserDefinedPatterns.length > 0);
+ }
+
+ // ---------- dialog related code ----------
+
+ private void openDialog() {
+ CustomFiltersDialog dialog= new CustomFiltersDialog(
+ fViewer.getControl().getShell(),
+ fTargetId,
+ areUserDefinedPatternsEnabled(),
+ fUserDefinedPatterns,
+ getEnabledFilterIds());
+
+ if (dialog.open() == Window.OK) {
+ setEnabledFilterIds(dialog.getEnabledFilterIds());
+ setUserDefinedPatternsEnabled(dialog.areUserDefinedPatternsEnabled());
+ setUserDefinedPatterns(dialog.getUserDefinedPatterns());
+ setRecentlyChangedFilters(dialog.getFilterDescriptorChangeHistory());
+
+ storeViewDefaults();
+
+ updateViewerFilters(true);
+ }
+ }
+}

Back to the top