1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Patch for Hoda Amer.

This patch enables Outline view filters to show/hide -static members, non-public members, and fields (same as in JDT). 
Please note that the patch creates three new packages and 5 new classes. 
It also has 9 new icon files (in three different directories). 
The modified files + the new files are all zipped into the attached file.
This commit is contained in:
John Camelon 2003-05-05 14:15:16 +00:00
parent b8a4db2ba7
commit 83f96aa7ee
17 changed files with 787 additions and 1 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 160 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 97 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 111 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 95 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 69 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 89 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 127 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 97 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 149 B

View file

@ -121,6 +121,10 @@ public class CPluginImages {
public static final String IMG_TOOL_GOTO_NEXT_ERROR= NAME_PREFIX + "next_error_nav.gif";
public static final String IMG_EDIT_PROPERTIES= NAME_PREFIX + "prop_edt.gif";
public static final String IMG_ACTION_SHOW_FIELDS= NAME_PREFIX + "fields_co.gif";
public static final String IMG_ACTION_SHOW_PUBLIC= NAME_PREFIX + "public_co.gif";
public static final String IMG_ACTION_SHOW_STATIC= NAME_PREFIX + "static_co.gif";
public static final ImageDescriptor DESC_OBJS_TEMPLATE= createManaged(T_OBJ, IMG_OBJS_TEMPLATE);
public static final ImageDescriptor DESC_OVR_STATIC= create(T_OVR, "static_co.gif");

View file

@ -22,6 +22,10 @@ public interface ICHelpContextIds {
public static final String NEW_CPROJECT_WIZARD_PAGE= PREFIX + "new_cproject_wizard_page_context";
public static final String NEW_LAUNCH_WIZARD_PAGE= PREFIX + "new_launch_wizard_page_context";
// Actions
public static final String FILTER_PUBLIC_ACTION= PREFIX + "filter_public_action";
public static final String FILTER_FIELDS_ACTION= PREFIX + "filter_fields_action";
public static final String FILTER_STATIC_ACTION= PREFIX + "filter_static_action";
// Preference/property pages
public static final String C_PREF_PAGE= PREFIX + "new_c_pref_page_context";

View file

@ -0,0 +1,71 @@
/*******************************************************************************
* Copyright (c) 2001 Rational Software Corp. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v0.5
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v05.html
*
* Contributors:
* Rational Software - initial implementation
******************************************************************************/
package org.eclipse.cdt.internal.ui.actions;
import java.text.MessageFormat;
import java.util.MissingResourceException;
import java.util.ResourceBundle;
/**
* Class that gives access to the action messages resource bundle.
*/
public class ActionMessages {
private static final String BUNDLE_NAME= "org.eclipse.cdt.internal.ui.actions.ActionMessages"; //$NON-NLS-1$
private static final ResourceBundle RESOURCE_BUNDLE= ResourceBundle.getBundle(BUNDLE_NAME);
private ActionMessages() {
// no instance
}
/**
* Returns the resource string associated with the given key in the resource bundle. If there isn't
* any value under the given key, the key is returned.
*
* @param key the resource key
* @return the string
*/
public static String getString(String key) {
try {
return RESOURCE_BUNDLE.getString(key);
} catch (MissingResourceException e) {
return '!' + key + '!';
}
}
/**
* Returns the formatted resource string associated with the given key in the resource bundle.
* <code>MessageFormat</code> is used to format the message. If there isn't any value
* under the given key, the key is returned.
*
* @param key the resource key
* @param arg the message argument
* @return the string
*/
public static String getFormattedString(String key, Object arg) {
return getFormattedString(key, new Object[] { arg });
}
/**
* Returns the formatted resource string associated with the given key in the resource bundle.
* <code>MessageFormat</code> is used to format the message. If there isn't any value
* under the given key, the key is returned.
*
* @param key the resource key
* @param args the message arguments
* @return the string
*/
public static String getFormattedString(String key, Object[] args) {
return MessageFormat.format(getString(key), args);
}
}

View file

@ -0,0 +1,274 @@
###############################################################################
# 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
###############################################################################
OpenWithMenu.label=Open Wit&h
RefactorMenu.label=Refac&tor
SourceMenu.label=&Source
NavigateMenu.label=&Navigate
BuildAction.label=&Build Project
RebuildAction.label=Rebuild Pro&ject
SelectionConverter.codeResolveOrInput_failed=Couldn't convert text selection into a Java element
SelectionConverter.codeResolve_failed=Couldn't convert text selection into a Java element
OpenAction.label=&Open
OpenAction.tooltip=Open an editor on the selected element
OpenAction.description=Open an editor on the selected element
OpenAction.declaration.label=&Open Declaration
OpenAction.select_element=&Select or enter the element to open:
OpenAction.error.title=Open
OpenAction.error.message=Cannot open default editor.
OpenAction.error.messageArgs=Cannot open default editor on {0}. {1}
OpenAction.error.messageProblems=Problems Opening Editor
OpenAction.error.messageBadSelection=Current text selection doesn't resolve to a Java element
OpenSuperImplementationAction.label=Open S&uper Implementation
OpenSuperImplementationAction.tooltip=Open the Implementation in the Super Type
OpenSuperImplementationAction.description=Open the Implementation in the Super Type
OpenSuperImplementationAction.error.title=Open Super Implementation
OpenSuperImplementationAction.error.message=Opening failed. Check log for details.
OpenSuperImplementationAction.not_applicable=Operation not applicable to current text selection. Please position the cursor inside a method.
OpenSuperImplementationAction.no_super_implementation=Super implementation for method ''{0}'' does not exist.
OpenTypeHierarchyAction.label=Open Type Hie&rarchy
OpenTypeHierarchyAction.tooltip=Open a type hierarchy on the selected element
OpenTypeHierarchyAction.description=Open a type hierarchy on the selected element
OpenTypeHierarchyAction.dialog.title=Open Type Hierarchy
OpenTypeHierarchyAction.messages.title=Can\'t create type hierarchy
OpenTypeHierarchyAction.messages.no_java_element=No Java element selected.
OpenTypeHierarchyAction.messages.no_java_resources=Selected package fragment doesn\'t contain any Java resource.
OpenTypeHierarchyAction.messages.no_types=Selected compilation unit doesn\'t contain a type.
OpenTypeHierarchyAction.messages.no_valid_java_element=No valid Java element selected.
ShowInPackageViewAction.label=Show in Pac&kage Explorer
ShowInPackageViewAction.description=Show the selected element in Package Explorer
ShowInPackageViewAction.tooltip=Show in Package Explorer
ShowInPackageViewAction.select_name=&Select or enter the element to reveal:
ShowInPackageViewAction.dialog.title=Show In Package Explorer
ShowInPackageViewAction.error.message=Internal error. Please see log for details.
ShowInPackageViewAction.not_found=Cannot reveal the selected element in Package Explorer. The element may be filtered out.
ShowInNavigatorView.label=Show in &Navigator View
ShowInNavigatorView.dialog.title=Show in Navigator View
ShowInNavigatorView.dialog.message=Select the element to be opened in the navigator view:
ShowInNavigatorView.error.activation_failed=Unable to activate Resource Navigator
ShowInNavigatorView.error.conversion_failed=Unable to convert Java element into a resource
OverrideMethodsAction.label=O&verride/Implement Methods...
OverrideMethodsAction.description=Override or Implement Methods from super types.
OverrideMethodsAction.tooltip=Override/Implement Methods
OverrideMethodsAction.error.title=Override/Implement Methods
OverrideMethodsAction.error.nothing_found=No methods to override found for this type.
OverrideMethodsAction.error.type_removed_in_editor=Input type has been removed in editor.
OverrideMethodsAction.not_applicable=Operation not applicable to current text selection. Please position the cursor inside a type.
AddGetterSetterAction.label=Gene&rate Getter and Setter...
AddGetterSetterAction.description=Generate Getter and Setter methods for type's fields
AddGetterSetterAction.tooltip=Generate Getter and Setter methods for the Type's Fields
AddGetterSetterAction.error.title=Generate Getter and Setter
AddGetterSetterAction.error.actionfailed=Generating Getter and Setter Failed.
AddGetterSetterAction.error.fieldNotExisting=The field ''{0}'' has been removed in the editor.
AddGetterSetterAction.not_applicable=Operation not applicable to current text selection. A field has to be selected or a type that declares fields.
AddGetterSetterAction.read_only=The compilation unit in which the field ''{0}'' is declared is read only.
AddGetterSetterAction.QueryDialog.title=Generate Getter and Setter
AddGetterSetterAction.SkipSetterForFinalDialog.message=Field ''{0}'' is final.\nOK to skip creation of the setter method?
AddGetterSetterAction.SkipExistingDialog.message=Method ''{0}'' already exists.\nSkip creation?
AddGetterSetterAction.SkipExistingDialog.skip.label=&Skip
AddGetterSetterAction.SkipExistingDialog.replace.label=&Replace
AddGetterSetterAction.SkipExistingDialog.skipAll.label=Skip &All
AddGetterSetterAction.dialog.title=&Select getters and setters to create:
AddGetterSetterAction.one_selected=1 method selected.
AddGetterSetterAction.methods_selected={0} methods selected.
AddGettSetterAction.typeContainsNoFields.message=The type contains no fields or all fields have getters/setters already.
AddUnimplementedConstructorsAction.label=Add &Constructors from Superclass
AddUnimplementedConstructorsAction.description=Evaluate and add constructors from superclass
AddUnimplementedConstructorsAction.tooltip=Add Constructors from Superclass
AddUnimplementedConstructorsAction.error.title=Add Constructors from Superclass
AddUnimplementedConstructorsAction.error.nothing_found=No unimplemented constructors found.
AddUnimplementedConstructorsAction.error.type_removed_in_editor=Input type has been removed in editor.
AddUnimplementedConstructorsAction.not_applicable=Operation not applicable to current text selection. Please position the cursor inside a type.
AddJavaDocStubAction.label=Add &Javadoc Comment
AddJavaDocStubAction.description=Add a Javadoc comment stub to the member element
AddJavaDocStubAction.tooltip=Add a Javadoc comment stub to the member element
AddJavaDocStubsAction.error.dialogTitle=Add Javadoc Comment
AddJavaDocStubsAction.error.noWorkingCopy=Could not find working copy.
AddJavaDocStubsAction.error.memberNotExisting=Member has been removed in editor.
AddJavaDocStubsAction.error.actionFailed=Error while adding Javadoc comment
AddJavaDocStubsAction.not_applicable=Operation not applicable to current text selection. Please position the cursor inside a type or method.
ExternalizeStringsAction.label= &Externalize Strings...
ExternalizeStringsAction.dialog.title= Externalize Strings
ExternalizeStringsAction.dialog.message=Couldn't open Externalize String Wizard
FindStringsToExternalizeAction.label= &Find Strings to Externalize...
FindStringsToExternalizeAction.dialog.title= Find Strings to Externalize
FindStringsToExternalizeAction.error.message=Unexpected Exception. See log.
FindStringsToExternalizeAction.foundStrings= {0} in {1}
FindStringsToExternalizeAction.noStrings= No strings to externalize were found.
FindStringsToExternalizeAction.not_externalized= {0} &not externalized string(s) found.
FindStringsToExternalizeAction.button.label= &Externalize...
FindStringsToExternalizeAction.find_strings=Finding not externalized strings...
OpenExternalJavadocAction.label=Open E&xternal Javadoc
OpenExternalJavadocAction.description=Opens the Javadoc of the selected element in an external browser
OpenExternalJavadocAction.tooltip=Opens the Javadoc of the selected element in an external browser
OpenExternalJavadocAction.help_not_available=Help support not available
OpenExternalJavadocAction.select_element=&Select or enter the element to open:
OpenExternalJavadocAction.libraries.no_location=The documentation location for ''{0}'' has not been configured. For elements from libraries specify the Javadoc location URL on the property page of the parent JAR (''{1}'')
OpenExternalJavadocAction.source.no_location=The documentation location for ''{0}'' has not been configured. For elements from source specify the Javadoc location URL on the property page of the parent project (''{1}'')
OpenExternalJavadocAction.no_entry=The documentation does not contain an entry for ''{0}''.\n(File ''{1}'' does not exist.)
OpenExternalJavadocAction.opening_failed=Opening Javadoc failed. See log for details
OpenExternalJavadocAction.dialog.title=Open External Javadoc
OpenExternalJavadocAction.code_resolve_failed=Couldn't convert text selection into a Java element
SelfEncapsulateFieldAction.label=Encap&sulate Field...
SelfEncapsulateFieldAction.dialog.title=Encapsulate Field
SelfEncapsulateFieldAction.dialog.unavailable=Operation unavailable on the current selection. Select a field.
SelfEncapsulateFieldAction.dialog.cannot_perform=Cannot perform refactoring. See log for more details.
SelfEncapsulateFieldAction.dialog.field_doesnot_exit=Editor buffer does not contain field {0}.
OrganizeImportsAction.label=Or&ganize Imports
OrganizeImportsAction.tooltip=Evaluate All Required Imports and Replace the Current Imports
OrganizeImportsAction.description=Evaluate all required imports and replace the current imports
OrganizeImportsAction.multi.op.description=Organizing imports...
OrganizeImportsAction.multi.error.parse={0}: Compilation unit has parse errors. No changes applied.
OrganizeImportsAction.multi.error.readonly={0}: Compilation unit is read-only. No changes applied.
OrganizeImportsAction.multi.error.unresolvable={0}: Compilation unit contains ambiguous references. User interaction required.
OrganizeImportsAction.multi.error.unexpected={0}: Unexpected error. See log for details.
OrganizeImportsAction.multi.error.notoncp={0}: Compilation unit not on build path. No changes applied.
OrganizeImportsAction.selectiondialog.title=Organize Imports
OrganizeImportsAction.selectiondialog.message=&Choose type to import:
OrganizeImportsAction.error.title=Organize Imports
OrganizeImportsAction.error.message=Unexpected error in organize imports. See log for details.
OrganizeImportsAction.single.error.parse=Compilation unit has parse errors: ''{0}''. No changes applied.
OrganizeImportsAction.summary_added={0} import(s) added.
OrganizeImportsAction.summary_removed={0} import(s) removed.
OrganizeImportsAction.multi.status.title=Organize Imports
OrganizeImportsAction.multi.status.description=Problems while organizing imports on some compilation units. See 'Details' for more information.
SortMembersAction.label=Sort &Members
SortMembersAction.tooltip=Sorts all Members using the Member Order Preference
SortMembersAction.description=Sorts all members using the member order preference
SortMembersAction.error.title=Sort Members
SortMembersAction.not_applicable=Operation not applicable to current text editor.
SortMembersAction.containsmarkers=Markers like bookmarks, breakpoints or user defined tasks in a reordered member will be lost. Ok to continue?
OpenBrowserUtil.help_not_available=Help support not available
MemberFilterActionGroup.hide_fields.label=Hide Fiel&ds
MemberFilterActionGroup.hide_fields.tooltip=Hide Fields
MemberFilterActionGroup.hide_fields.description=Toggles the visibility of fields
MemberFilterActionGroup.hide_static.label=Hide &Static Members
MemberFilterActionGroup.hide_static.tooltip=Hide Static Members
MemberFilterActionGroup.hide_static.description=Toggles the visibility of static members
MemberFilterActionGroup.hide_nonpublic.label=Hide Non-&Public Members
MemberFilterActionGroup.hide_nonpublic.tooltip=Hide Non-Public Members
MemberFilterActionGroup.hide_nonpublic.description=Toggles the visibility of non-public members
NewWizardsActionGroup.new=Ne&w
OpenProjectAction.dialog.title=Open Project
OpenProjectAction.dialog.message=Select project(s) to be opened
OpenProjectAction.error.message=Problems while opening projects
OpenProjectAction.no_java_nature.one=The following project doesn't have a Java nature and is therefore not present in the Package Explorer:
OpenProjectAction.no_java_nature.multiple=The following projects don't have a Java nature and are therefore not present in the Package Explorer:
OpenJavaPerspectiveAction.dialog.title=Open Java Perspective
OpenJavaPerspectiveAction.error.open_failed=Couldn\'t open Java perspective
OpenJavaBrowsingPerspectiveAction.dialog.title=Open Java Browsing Perspective
OpenJavaBrowsingPerspectiveAction.error.open_failed=Couldn\'t open Java browsing perspective
OpenTypeInHierarchyAction.label=Open Type in Hierarchy...
OpenTypeInHierarchyAction.description=Open a type in a type hierarchy
OpenTypeInHierarchyAction.tooltip=Open a type in a type hierarchy
OpenTypeInHierarchyAction.dialogMessage=&Choose a type (? = any character, * = any string):
OpenTypeInHierarchyAction.dialogTitle=Open Type in Hierarchy
RefreshAction.label= Re&fresh
RefreshAction.toolTip= Refresh
RefreshAction.progressMessage= Refreshing...
RefreshAction.error.title= Refresh Problems
RefreshAction.error.message= Problems occurred refreshing the selected resources.
RefreshAction.locationDeleted.title= Project location has been deleted
RefreshAction.locationDeleted.message= The location for project {0} ({1}) has been deleted.\n Delete {0} from the workspace?
ModifyParameterAction.problem.title=Refactoring
ModifyParameterAction.problem.message=Operation not possible.
PullUpAction.problem.title=Refactoring
PullUpAction.problem.message=Operation not possible.
OverrideMethodQuery.groupMethodsByTypes=Group methods by &types
OverrideMethodQuery.dialog.title=Override/Implement Methods
OverrideMethodQuery.dialog.description=&Select methods to override or implement:
OverrideMethodQuery.selectioninfo.one={0} method selected.
OverrideMethodQuery.selectioninfo.more={0} methods selected.
ActionUtil.notOnBuildPath.title=Operation Cannot be Performed
ActionUtil.notOnBuildPath.message=The resource is not on the build path of a Java project.
ActionUtil.not_possible=Operation Not Possible
ActionUtil.no_linked=This operation is unavailable on linked packages and package fragment roots.
SelectAllAction.label= Select A&ll
SelectAllAction.tooltip= Select All
AddToClasspathAction.label=Add to &Build Path
AddToClasspathAction.toolTip=Add JAR to the Java build path
AddToClasspathAction.progressMessage=Adding to build path...
AddToClasspathAction.error.title=Add to Build Path
AddToClasspathAction.error.message=Problems occurred while adding to the build path.
RemoveFromClasspathAction.Remove=Remove from &Build Path
RemoveFromClasspathAction.tooltip=Remove package fragment root from the Java build path
RemoveFromClasspathAction.Removing=Removing from build path...
RemoveFromClasspathAction.exception_dialog_title=Remove From Build Path
RemoveFromClasspathAction.Problems_occurred=Problems occurred while removing from the build path.
AddDelegateMethodsAction.error.title=Generate Delegate Methods
AddDelegateMethodsAction.error.actionfailed=Generating delegate methods failed.
AddDelegateMethodsAction.label=Generate Delegate &Methods...
AddDelegateMethodsAction.description=Adds delegate methods for a type's fields
AddDelegateMethodsAction.tooltip=Adds Delegates Methods for a Type's Fields
AddDelegateMethodsAction.not_applicable=Operation not applicable to current text selection. Please select a field or a type that declares some fields.
AddDelegateMethodsAction.duplicate_methods=Duplicate method(s) selected
AddDelegateMethodsAction.title=Delegate Methods Generation
AddDelegateMethodsAction.message=Select &methods to create delegates for:
AddDelegateMethodsAction.monitor.message=Creating {0} methods...
AddDelegateMethodsAction.selectioninfo.one={0} method selected.
AddDelegateMethodsAction.selectioninfo.more={0} methods selected.

View file

@ -17,6 +17,7 @@ import org.eclipse.cdt.internal.ui.util.ProblemTreeViewer;
import org.eclipse.cdt.ui.CElementContentProvider;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.ui.IWorkingCopyManager;
import org.eclipse.cdt.ui.actions.MemberFilterActionGroup;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
@ -59,6 +60,8 @@ public class CContentOutlinePage extends Page implements IContentOutlinePage, IS
private OpenIncludeAction fOpenIncludeAction;
private SearchForReferencesAction fSearchForReferencesAction;
private MemberFilterActionGroup fMemberFilterActionGroup;
public CContentOutlinePage(CEditor editor) {
this("#TranslationUnitOutlinerContext", editor);
}
@ -172,7 +175,8 @@ public class CContentOutlinePage extends Page implements IContentOutlinePage, IS
site.setSelectionProvider(treeViewer);
IActionBars bars= site.getActionBars();
bars.setGlobalActionHandler(ICEditorActionDefinitionIds.TOGGLE_PRESENTATION, fTogglePresentation);
registerToolbarActions();
//IFileEditorInput editorInput= (IFileEditorInput)fEditor.getEditorInput();
IEditorInput editorInput= (IEditorInput)fEditor.getEditorInput();
@ -201,6 +205,10 @@ public class CContentOutlinePage extends Page implements IContentOutlinePage, IS
public void dispose() {
CUIPlugin.getDefault().getProblemMarkerManager().removeListener(treeViewer);
if (fMemberFilterActionGroup != null) {
fMemberFilterActionGroup.dispose();
fMemberFilterActionGroup= null;
}
super.dispose();
}
@ -298,4 +306,17 @@ public class CContentOutlinePage extends Page implements IContentOutlinePage, IS
}
contentUpdated();
}
private void registerToolbarActions() {
IToolBarManager toolBarManager= getSite().getActionBars().getToolBarManager();
if (toolBarManager != null) {
//toolBarManager.add(new ClassOnlyAction());
//toolBarManager.add(new LexicalSortingAction());
fMemberFilterActionGroup= new MemberFilterActionGroup(treeViewer, "COutlineViewer"); //$NON-NLS-1$
fMemberFilterActionGroup.contributeToToolBar(toolBarManager);
}
}
}

View file

@ -0,0 +1,95 @@
/*******************************************************************************
* Copyright (c) 2001 Rational Software Corp. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v0.5
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v05.html
*
* Contributors:
* Rational Software - initial implementation
******************************************************************************/
package org.eclipse.cdt.internal.ui.viewsupport;
import org.eclipse.cdt.core.model.IDeclaration;
import org.eclipse.cdt.core.model.IField;
import org.eclipse.cdt.core.model.IMember;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.viewers.ViewerFilter;
/**
* Filter for the methods viewer.
* Changing a filter property does not trigger a refiltering of the viewer
*/
public class MemberFilter extends ViewerFilter{
public static final int FILTER_NONPUBLIC= 1;
public static final int FILTER_STATIC= 2;
public static final int FILTER_FIELDS= 4;
private int fFilterProperties;
/**
* Modifies filter and add a property to filter for
*/
public final void addFilter(int filter) {
fFilterProperties |= filter;
}
/**
* Modifies filter and remove a property to filter for
*/
public final void removeFilter(int filter) {
fFilterProperties &= (-1 ^ filter);
}
/**
* Tests if a property is filtered
*/
public final boolean hasFilter(int filter) {
return (fFilterProperties & filter) != 0;
}
/*
* @see ViewerFilter@isFilterProperty
*/
public boolean isFilterProperty(Object element, Object property) {
return false;
}
/*
* @see ViewerFilter@select
*/
public boolean select(Viewer viewer, Object parentElement, Object element) {
if(element instanceof IDeclaration){
IDeclaration declaration = (IDeclaration) element;
if (hasFilter(FILTER_STATIC) && (declaration.isStatic()) ) {
return false;
}
if (element instanceof IMember) {
IMember member= (IMember)element;
if (hasFilter(FILTER_NONPUBLIC) && (member.getVisibility() != IMember.V_PUBLIC)) {
return false;
}
if (hasFilter(FILTER_FIELDS) && element instanceof IField) {
return false;
}
}
}
return true;
}
/*
private boolean isMemberInInterface(IMember member) throws JavaModelException {
IType parent= member.getDeclaringType();
return parent != null && parent.isInterface();
}
private boolean isFieldInInterface(IMember member) throws JavaModelException {
return (member.getElementType() == IJavaElement.FIELD) && member.getDeclaringType().isInterface();
}
private boolean isTopLevelType(IMember member) throws JavaModelException {
IType parent= member.getDeclaringType();
return parent == null;
}
*/
}

View file

@ -0,0 +1,50 @@
/*******************************************************************************
* Copyright (c) 2001 Rational Software Corp. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v0.5
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v05.html
*
* Contributors:
* Rational Software - initial implementation
******************************************************************************/
package org.eclipse.cdt.internal.ui.viewsupport;
import org.eclipse.jface.action.Action;
import org.eclipse.ui.help.WorkbenchHelp;
import org.eclipse.cdt.ui.actions.MemberFilterActionGroup;;
/**
* Action used to enable / disable method filter properties
*/
public class MemberFilterAction extends Action {
private int fFilterProperty;
private MemberFilterActionGroup fFilterActionGroup;
public MemberFilterAction(MemberFilterActionGroup actionGroup, String title, int property, String contextHelpId, boolean initValue) {
super(title);
fFilterActionGroup= actionGroup;
fFilterProperty= property;
WorkbenchHelp.setHelp(this, contextHelpId);
setChecked(initValue);
}
/**
* Returns this action's filter property.
*/
public int getFilterProperty() {
return fFilterProperty;
}
/*
* @see Action#actionPerformed
*/
public void run() {
fFilterActionGroup.setMemberFilter(fFilterProperty, isChecked());
}
}

View file

@ -0,0 +1,267 @@
/*******************************************************************************
* Copyright (c) 2001 Rational Software Corp. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v0.5
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v05.html
*
* Contributors:
* Rational Software - initial implementation
******************************************************************************/
package org.eclipse.cdt.ui.actions;
/**
* Action Group that contributes filter buttons for a view parts showing
* methods and fields. Contributed filters are: hide fields, hide static
* members and hide non-public members.
* <p>
* The action group installs a filter on a structured viewer. The filter is connected
* to the actions installed in the view part's toolbar menu and is updated when the
* state of the buttons changes.
* <p>
*/
import org.eclipse.cdt.internal.ui.viewsupport.MemberFilter;
import org.eclipse.cdt.internal.ui.viewsupport.MemberFilterAction;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.internal.ui.actions.ActionMessages;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.IToolBarManager;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.util.Assert;
import org.eclipse.jface.viewers.StructuredViewer;
import org.eclipse.swt.custom.BusyIndicator;
import org.eclipse.ui.IActionBars;
import org.eclipse.ui.IMemento;
import org.eclipse.ui.actions.ActionGroup;
import org.eclipse.cdt.internal.ui.ICHelpContextIds;
import org.eclipse.cdt.internal.ui.CPluginImages;
public class MemberFilterActionGroup extends ActionGroup {
public static final int FILTER_NONPUBLIC= MemberFilter.FILTER_NONPUBLIC;
public static final int FILTER_STATIC= MemberFilter.FILTER_STATIC;
public static final int FILTER_FIELDS= MemberFilter.FILTER_FIELDS;
private static final String TAG_HIDEFIELDS= "hidefields"; //$NON-NLS-1$
private static final String TAG_HIDESTATIC= "hidestatic"; //$NON-NLS-1$
private static final String TAG_HIDENONPUBLIC= "hidenonpublic"; //$NON-NLS-1$
private MemberFilterAction[] fFilterActions;
private MemberFilter fFilter;
private StructuredViewer fViewer;
private String fViewerId;
private boolean fInViewMenu;
/**
* Creates a new <code>MemberFilterActionGroup</code>.
*
* @param viewer the viewer to be filtered
* @param viewerId a unique id of the viewer. Used as a key to to store
* the last used filter settings in the preference store
*/
public MemberFilterActionGroup(StructuredViewer viewer, String viewerId) {
this(viewer, viewerId, false);
}
/**
* Creates a new <code>MemberFilterActionGroup</code>.
*
* @param viewer the viewer to be filtered
* @param viewerId a unique id of the viewer. Used as a key to to store
* the last used filter settings in the preference store
* @param inViewMenu if <code>true</code> the actions are added to the view
* menu. If <code>false</code> they are added to the toobar.
*
* @since 2.1
*/
public MemberFilterActionGroup(StructuredViewer viewer, String viewerId, boolean inViewMenu) {
fViewer= viewer;
fViewerId= viewerId;
fInViewMenu= inViewMenu;
// get initial values
IPreferenceStore store= CUIPlugin.getDefault().getPreferenceStore();
boolean doHideFields= store.getBoolean(getPreferenceKey(FILTER_FIELDS));
boolean doHideStatic= store.getBoolean(getPreferenceKey(FILTER_STATIC));
boolean doHidePublic= store.getBoolean(getPreferenceKey(FILTER_NONPUBLIC));
fFilter= new MemberFilter();
if (doHideFields)
fFilter.addFilter(FILTER_FIELDS);
if (doHideStatic)
fFilter.addFilter(FILTER_STATIC);
if (doHidePublic)
fFilter.addFilter(FILTER_NONPUBLIC);
// fields
String title= ActionMessages.getString("MemberFilterActionGroup.hide_fields.label"); //$NON-NLS-1$
String helpContext= ICHelpContextIds.FILTER_FIELDS_ACTION;
MemberFilterAction hideFields= new MemberFilterAction(this, title, FILTER_FIELDS, helpContext, doHideFields);
hideFields.setDescription(ActionMessages.getString("MemberFilterActionGroup.hide_fields.description")); //$NON-NLS-1$
hideFields.setToolTipText(ActionMessages.getString("MemberFilterActionGroup.hide_fields.tooltip")); //$NON-NLS-1$
CPluginImages.setImageDescriptors(hideFields, CPluginImages.T_LCL, CPluginImages.IMG_ACTION_SHOW_FIELDS); //$NON-NLS-1$
// static
title= ActionMessages.getString("MemberFilterActionGroup.hide_static.label"); //$NON-NLS-1$
helpContext= ICHelpContextIds.FILTER_STATIC_ACTION;
MemberFilterAction hideStatic= new MemberFilterAction(this, title, FILTER_STATIC, helpContext, doHideStatic);
hideStatic.setDescription(ActionMessages.getString("MemberFilterActionGroup.hide_static.description")); //$NON-NLS-1$
hideStatic.setToolTipText(ActionMessages.getString("MemberFilterActionGroup.hide_static.tooltip")); //$NON-NLS-1$
CPluginImages.setImageDescriptors(hideStatic, CPluginImages.T_LCL, CPluginImages.IMG_ACTION_SHOW_STATIC); //$NON-NLS-1$
// non-public
title= ActionMessages.getString("MemberFilterActionGroup.hide_nonpublic.label"); //$NON-NLS-1$
helpContext= ICHelpContextIds.FILTER_PUBLIC_ACTION;
MemberFilterAction hideNonPublic= new MemberFilterAction(this, title, FILTER_NONPUBLIC, helpContext, doHidePublic);
hideNonPublic.setDescription(ActionMessages.getString("MemberFilterActionGroup.hide_nonpublic.description")); //$NON-NLS-1$
hideNonPublic.setToolTipText(ActionMessages.getString("MemberFilterActionGroup.hide_nonpublic.tooltip")); //$NON-NLS-1$
CPluginImages.setImageDescriptors(hideNonPublic, CPluginImages.T_LCL, CPluginImages.IMG_ACTION_SHOW_PUBLIC); //$NON-NLS-1$
// order corresponds to order in toolbar
fFilterActions= new MemberFilterAction[] { hideFields, hideStatic, hideNonPublic };
fViewer.addFilter(fFilter);
}
private String getPreferenceKey(int filterProperty) {
return "MemberFilterActionGroup." + fViewerId + '.' + String.valueOf(filterProperty); //$NON-NLS-1$
}
/**
* Sets the member filters.
*
* @param filterProperty the filter to be manipulated. Valid values are <code>FILTER_FIELDS</code>,
* <code>FILTER_PUBLIC</code>, and <code>FILTER_PRIVATE</code> as defined by this action
* group
* @param set if <code>true</code> the given filter is installed. If <code>false</code> the
* given filter is removed
* .
*/
public void setMemberFilter(int filterProperty, boolean set) {
setMemberFilters(new int[] {filterProperty}, new boolean[] {set}, true);
}
private void setMemberFilters(int[] propertyKeys, boolean[] propertyValues, boolean refresh) {
if (propertyKeys.length == 0)
return;
Assert.isTrue(propertyKeys.length == propertyValues.length);
for (int i= 0; i < propertyKeys.length; i++) {
int filterProperty= propertyKeys[i];
boolean set= propertyValues[i];
if (set) {
fFilter.addFilter(filterProperty);
} else {
fFilter.removeFilter(filterProperty);
}
IPreferenceStore store= CUIPlugin.getDefault().getPreferenceStore();
for (int j= 0; j < fFilterActions.length; j++) {
int currProperty= fFilterActions[j].getFilterProperty();
if (currProperty == filterProperty) {
fFilterActions[j].setChecked(set);
}
store.setValue(getPreferenceKey(currProperty), hasMemberFilter(currProperty));
}
}
if (refresh) {
fViewer.getControl().setRedraw(false);
BusyIndicator.showWhile(fViewer.getControl().getDisplay(), new Runnable() {
public void run() {
fViewer.refresh();
}
});
fViewer.getControl().setRedraw(true);
}
}
/**
* Returns <code>true</code> if the given filter is installed.
*
* @param filterProperty the filter to be tested. Valid values are <code>FILTER_FIELDS</code>,
* <code>FILTER_PUBLIC</code>, and <code>FILTER_PRIVATE</code> as defined by this action
* group
*/
public boolean hasMemberFilter(int filterProperty) {
return fFilter.hasFilter(filterProperty);
}
/**
* Saves the state of the filter actions in a memento.
*
* @param memento the memento to which the state is saved
*/
public void saveState(IMemento memento) {
memento.putString(TAG_HIDEFIELDS, String.valueOf(hasMemberFilter(FILTER_FIELDS)));
memento.putString(TAG_HIDESTATIC, String.valueOf(hasMemberFilter(FILTER_STATIC)));
memento.putString(TAG_HIDENONPUBLIC, String.valueOf(hasMemberFilter(FILTER_NONPUBLIC)));
}
/**
* 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) {
setMemberFilters(
new int[] {FILTER_FIELDS, FILTER_STATIC, FILTER_NONPUBLIC},
new boolean[] {
Boolean.valueOf(memento.getString(TAG_HIDEFIELDS)).booleanValue(),
Boolean.valueOf(memento.getString(TAG_HIDESTATIC)).booleanValue(),
Boolean.valueOf(memento.getString(TAG_HIDENONPUBLIC)).booleanValue()
}, false);
}
/* (non-Javadoc)
* @see ActionGroup#fillActionBars(IActionBars)
*/
public void fillActionBars(IActionBars actionBars) {
contributeToToolBar(actionBars.getToolBarManager());
};
/**
* Adds the filter actions to the given tool bar
*
* @param tbm the tool bar to which the actions are added
*/
public void contributeToToolBar(IToolBarManager tbm) {
if (fInViewMenu)
return;
tbm.add(fFilterActions[0]); // fields
tbm.add(fFilterActions[1]); // static
tbm.add(fFilterActions[2]); // public
}
/**
* Adds the filter actions to the given menu manager.
*
* @param menu the menu manager to which the actions are added
* @since 2.1
*/
public void contributeToViewMenu(IMenuManager menu) {
if (!fInViewMenu)
return;
final String filters= "filters"; //$NON-NLS-1$
if (menu.find(filters) != null) {
menu.prependToGroup(filters, fFilterActions[0]); // fields
menu.prependToGroup(filters, fFilterActions[1]); // static
menu.prependToGroup(filters, fFilterActions[2]); // public
} else {
menu.add(fFilterActions[0]); // fields
menu.add(fFilterActions[1]); // static
menu.add(fFilterActions[2]); // public
}
}
/* (non-Javadoc)
* @see ActionGroup#dispose()
*/
public void dispose() {
super.dispose();
}
}