|
From: Christopher W. <caw...@us...> - 2006-02-10 19:58:21
|
Update of /cvsroot/rubyeclipse/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/filters In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12888/src/org/rubypeople/rdt/internal/ui/filters Added Files: FilterDescriptor.java FilterMessages.properties NamePatternFilter.java FilterMessages.java CustomFiltersDialog.java Log Message: filtering for Outline view --- NEW FILE: CustomFiltersDialog.java --- /******************************************************************************* * Copyright (c) 2000, 2005 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ package org.rubypeople.rdt.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.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.PlatformUI; import org.eclipse.ui.dialogs.SelectionDialog; import org.rubypeople.rdt.internal.ui.IRubyHelpContextIds; import org.rubypeople.rdt.internal.ui.util.SWTUtil; 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 Ruby element filters. * * @param shell the parent shell * @param viewId the id of the view * @param enablePatterns <code>true</code> if pattern filters are enabled * @param patterns the filter patterns * @param enabledFilterIds the Ids of the enabled filters */ 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.CustomFiltersDialog_title); setMessage(FilterMessages.CustomFiltersDialog_filterList_label); super.configureShell(shell); PlatformUI.getWorkbench().getHelpSystem().setHelp(shell, IRubyHelpContextIds.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.setFocus(); fEnableUserDefinedPatterns.setText(FilterMessages.CustomFiltersDialog_enableUserDefinedPattern); // 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.CustomFiltersDialog_patternInfo); // 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.CustomFiltersDialog_filterList_label); 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()); Arrays.sort(fBuiltInFilters); fCheckBoxList.setInput(fBuiltInFilters); setInitialSelections(getEnabledFilterDescriptors()); List initialSelection= getInitialElementSelections(); if (initialSelection != null && !initialSelection.isEmpty()) checkInitialSelections(); // Description info= new Label(parent, SWT.LEFT); info.setText(FilterMessages.CustomFiltersDialog_description_label); final Text description= new Text(parent, SWT.LEFT | SWT.WRAP | SWT.MULTI | SWT.READ_ONLY | SWT.BORDER | SWT.V_SCROLL); 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.CustomFiltersDialog_SelectAllButton_label; 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); // De-select All button label= FilterMessages.CustomFiltersDialog_DeselectAllButton_label; 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, true); int tokenCount= tokenizer.countTokens(); List result= new ArrayList(tokenCount); boolean escape= false; boolean append= false; while (tokenizer.hasMoreTokens()) { String token= tokenizer.nextToken().trim(); if (separator.equals(token)) { if (!escape) escape= true; else { addPattern(result, separator); append= true; } } else { if (!append) result.add(token); else addPattern(result, token); append= false; escape= false; } } return (String[])result.toArray(new String[result.size()]); } private static void addPattern(List list, String pattern) { if (list.isEmpty()) list.add(pattern); else { int index= list.size() - 1; list.set(index, ((String)list.get(index)) + pattern); } } public static String convertToString(String[] patterns, String separator) { int length= patterns.length; StringBuffer strBuf= new StringBuffer(); if (length > 0) strBuf.append(escapeSeparator(patterns[0], separator)); else return ""; //$NON-NLS-1$ int i= 1; while (i < length) { strBuf.append(separator); strBuf.append(" "); //$NON-NLS-1$ strBuf.append(escapeSeparator(patterns[i++], separator)); } return strBuf.toString(); } private static String escapeSeparator(String pattern, String separator) { int length= pattern.length(); StringBuffer buf= new StringBuffer(length); for (int i= 0; i < length; i++) { char ch= pattern.charAt(i); if (separator.equals(String.valueOf(ch))) buf.append(ch); buf.append(ch); } return buf.toString(); } } --- NEW FILE: FilterMessages.java --- /******************************************************************************* * Copyright (c) 2000, 2005 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ package org.rubypeople.rdt.internal.ui.filters; import org.eclipse.osgi.util.NLS; public final class FilterMessages extends NLS { private static final String BUNDLE_NAME= FilterMessages.class.getName(); private FilterMessages() { // Do not instantiate } public static String CustomFiltersDialog_title; public static String CustomFiltersDialog_patternInfo; public static String CustomFiltersDialog_enableUserDefinedPattern; public static String CustomFiltersDialog_filterList_label; public static String CustomFiltersDialog_description_label; public static String CustomFiltersDialog_SelectAllButton_label; public static String CustomFiltersDialog_DeselectAllButton_label; public static String OpenCustomFiltersDialogAction_text; public static String FilterDescriptor_filterDescriptionCreationError_message; public static String FilterDescriptor_filterCreationError_title; public static String FilterDescriptor_filterCreationError_message; static { NLS.initializeMessages(BUNDLE_NAME, FilterMessages.class); } } --- NEW FILE: FilterDescriptor.java --- /******************************************************************************* * Copyright (c) 2000, 2005 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ package org.rubypeople.rdt.internal.ui.filters; import java.text.Collator; import java.util.ArrayList; import java.util.HashSet; import java.util.List; import java.util.Set; import org.eclipse.core.runtime.IConfigurationElement; import org.eclipse.core.runtime.IExtensionRegistry; 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; import org.eclipse.ui.IPluginContribution; import org.eclipse.ui.activities.WorkbenchActivityHelper; import org.rubypeople.rdt.internal.corext.util.Messages; import org.rubypeople.rdt.ui.RubyUI; /** * Represents a custom filter which is provided by the * "org.eclipse.jdt.ui.javaElementFilters" extension point. * * since 2.0 */ public class FilterDescriptor implements Comparable, IPluginContribution { private static String PATTERN_FILTER_ID_PREFIX= "_patternFilterId_"; //$NON-NLS-1$ private static final String EXTENSION_POINT_NAME= "rubyElementFilters"; //$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) { IExtensionRegistry registry= Platform.getExtensionRegistry(); IConfigurationElement[] elements= registry.getConfigurationElementsFor(RubyUI.ID_PLUGIN, 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 (WorkbenchActivityHelper.filterItem(filterDescs[i])) continue; 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.jdt.ui.javaElementFilters does not specify a correct filter"); //$NON-NLS-1$ Assert.isNotNull(getId(), "An extension for extension-point org.eclipse.jdt.ui.javaElementFilters does not provide a valid ID"); //$NON-NLS-1$ Assert.isNotNull(getName(), "An extension for extension-point org.eclipse.jdt.ui.javaElementFilters 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= Messages.format(FilterMessages.FilterDescriptor_filterCreationError_message, getId()); 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.FilterDescriptor_filterDescriptionCreationError_message) { 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()); } } } return (FilterDescriptor[])result.toArray(new FilterDescriptor[result.size()]); } public String getLocalId() { return fElement.getAttribute(ID_ATTRIBUTE); } public String getPluginId() { return fElement.getNamespace(); } } --- NEW FILE: NamePatternFilter.java --- /******************************************************************************* * Copyright (c) 2000, 2005 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ package org.rubypeople.rdt.internal.ui.filters; import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.IAdaptable; import org.eclipse.jface.viewers.Viewer; import org.eclipse.jface.viewers.ViewerFilter; import org.rubypeople.rdt.core.IRubyElement; import org.rubypeople.rdt.internal.ui.util.StringMatcher; /** * 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-Rubydoc) * Method declared on ViewerFilter. */ public boolean select(Viewer viewer, Object parentElement, Object element) { String matchName= null; if (element instanceof IRubyElement) { matchName= ((IRubyElement) element).getElementName(); } else if (element instanceof IAdaptable) { IAdaptable adaptable= (IAdaptable) element; IRubyElement javaElement= (IRubyElement)adaptable.getAdapter(IRubyElement.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); } } } --- NEW FILE: FilterMessages.properties --- ############################################################################### # Copyright (c) 2000, 2005 IBM Corporation and others. # All rights reserved. This program and the accompanying materials # are made available under the terms of the Eclipse Public License v1.0 # which accompanies this distribution, and is available at # http://www.eclipse.org/legal/epl-v10.html # # Contributors: # IBM Corporation - initial API and implementation ############################################################################### CustomFiltersDialog_title= Ruby Element Filters CustomFiltersDialog_patternInfo= The patterns are separated by comma, where\n* = 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.jdt.ui.javaElementFilters is incorrect. FilterDescriptor_filterCreationError_title= Filter Creation Error FilterDescriptor_filterCreationError_message= The org.rubypeople.rdt.ui.rubyElementFilters plug-in extension "{0}" specifies a viewer filter class which does not exist. |