+ * This class may be instantiated; it is not intended to be subclassed. + *
+ * + * @noextend This class is not intended to be subclassed by clients. + */ + public class CustomFilterProcessor { + + + private static final String SEPARATOR= ","; //$NON-NLS-1$ + private final String TAG_USER_DEFINED_PATTERNS_ENABLED= "userDefinedPatternsEnabled"; //$NON-NLS-1$ + private final String TAG_USER_DEFINED_PATTERNS= "userDefinedPatterns"; //$NON-NLS-1$ + + + private static class FilterItem { + boolean enabled; + boolean previouslyEnabled; + OutlineFilterDescriptor descriptor; + String id; + + private ViewerFilter filterInstance= null; + + public FilterItem(OutlineFilterDescriptor descriptor) { + this.descriptor= descriptor; + this.id= descriptor.getId(); + this.previouslyEnabled= false; + this.enabled= descriptor.isEnabled(); + } + + public ViewerFilter getFilterInstance() { + if (filterInstance == null) { + filterInstance= descriptor.createViewerFilter(); + } + return filterInstance; + + } + } + + + private final StructuredViewer fViewer; + private final OutlineNamePatternFilter fPatternFilter; + + private boolean fUserDefinedPatternsEnabled; + private String[] fUserDefinedPatterns; + + private String[] fPreviousPatterns; + + private final Map fFilterItems; + + + + private final String fTargetId; + private IPreferenceStore fStore; + + + /** + * Creates a newCustomFilterAction
.
+ *
+ * @param store the preference Store
+ * @param ownerId the id of this action group's owner
+ * @param viewer the viewer to be filtered
+ */
+ public CustomFilterProcessor(IPreferenceStore store,String ownerId, StructuredViewer viewer) {
+ Assert.isNotNull(ownerId);
+ Assert.isNotNull(viewer);
+ fStore = store;
+ fTargetId= ownerId;
+ fViewer= viewer;
+ fPatternFilter= new OutlineNamePatternFilter();
+
+ fUserDefinedPatterns= new String[0];
+ fUserDefinedPatternsEnabled= false;
+ fPreviousPatterns= new String[0];
+
+ fFilterItems= new HashMap();
+ OutlineFilterDescriptor[] filterDescriptors= OutlineFilterDescriptor.getFilterDescriptors(fTargetId);
+ for (int i= 0; i < filterDescriptors.length; i++) {
+ FilterItem item= new FilterItem(filterDescriptors[i]);
+ fFilterItems.put(item.id, item);
+
+ }
+
+ initializeWithViewDefaults();
+
+ updateViewerFilters();
+
+ }
+
+
+
+
+ /*
+ * @see org.eclipse.jface.action.IContributionItem#isDynamic()
+ */
+ public boolean isDynamic() {
+ return true;
+ }
+ /**
+ * Returns a list of currently enabled filters. The filter
+ * is identified by its id.
+ * + * This method is for internal use only and should not + * be called by clients outside of JDT/UI. + *
+ * + * @return a list of currently enabled filters + * + * @noreference This method is not intended to be referenced by clients. + */ + public String[] internalGetEnabledFilterIds() { + ArrayList enabledFilterIds= new ArrayList(); + for (Iterator iterator= fFilterItems.values().iterator(); iterator.hasNext();) { + FilterItem item= (FilterItem) iterator.next(); + if (item.enabled) { + enabledFilterIds.add(item.id); + } + } + return (String[])enabledFilterIds.toArray(new String[enabledFilterIds.size()]); + } + + private void setEnabledFilterIds(String[] enabledIds) { + // set all to false + fUserDefinedPatternsEnabled= false; + for (Iterator iterator= fFilterItems.values().iterator(); iterator.hasNext();) { + FilterItem item= (FilterItem) iterator.next(); + item.enabled= false; + } + // set enabled to true + for (int i= 0; i < enabledIds.length; i++) { + FilterItem item= (FilterItem) fFilterItems.get(enabledIds[i]); + if (item != null) { + item.enabled= true; + } + if (fPatternFilter.getClass().getName().equals(enabledIds[i])) + fUserDefinedPatternsEnabled= true; + } + } + + private void setUserDefinedPatterns(String[] patterns) { + fUserDefinedPatterns= patterns; + } + + + private boolean areUserDefinedPatternsEnabled() { + return fUserDefinedPatternsEnabled; + } + + private void setUserDefinedPatternsEnabled(boolean state) { + fUserDefinedPatternsEnabled= state; + } + + + // ---------- viewer filter handling ---------- + + private boolean updateViewerFilters() { + ViewerFilter[] installedFilters= fViewer.getFilters(); + ArrayList viewerFilters= new ArrayList(installedFilters.length); + + HashSet patterns= new HashSet(); + + boolean hasChange= false; + boolean patternChange= false; + + for (Iterator iterator= fFilterItems.values().iterator(); iterator.hasNext();) { + FilterItem item= (FilterItem) iterator.next(); + if (item.descriptor.isCustomFilter()) { + if (item.enabled != item.previouslyEnabled) { + hasChange = true; + } + if (item.enabled){ + ViewerFilter filter= item.getFilterInstance(); // only create when changed + if (filter != null) { + viewerFilters.add(filter); + } + } + } else if (item.descriptor.isPatternFilter()) { + if (item.enabled) { + patterns.add(item.descriptor.getPattern()); + } + patternChange |= (item.enabled != item.previouslyEnabled); + } + item.previouslyEnabled= item.enabled; + } + + if (areUserDefinedPatternsEnabled()) { + for (int i= 0; i < fUserDefinedPatterns.length; i++) { + patterns.add(fUserDefinedPatterns[i]); + } + } + if (!patternChange) { // no pattern change so far, test if the user patterns made a difference + patternChange= hasChanges(patterns, fPreviousPatterns); + } + + fPreviousPatterns= (String[]) patterns.toArray(new String[patterns.size()]); + if (patternChange) { + fPatternFilter.setPatterns(fPreviousPatterns); + if (patterns.isEmpty()) { + viewerFilters.remove(fPatternFilter); + } else if (!viewerFilters.contains(fPatternFilter)) { + boolean contains = false; + for (int i=0; i< viewerFilters.size();i++){ + if (viewerFilters.get(i) instanceof OutlineNamePatternFilter){ + OutlineNamePatternFilter filter = (OutlineNamePatternFilter)viewerFilters.get(i); + String[] a1 =filter.getPatterns(); + String[] a2 =fPatternFilter.getPatterns(); + if (a1[0].equals(a2[0])) + contains= true; + else { + viewerFilters.remove(i); + } + break; + } + } + if (!contains) + viewerFilters.add(fPatternFilter); + } + hasChange= true; + } + if (hasChange) { + fViewer.setFilters((ViewerFilter[]) viewerFilters.toArray(new ViewerFilter[viewerFilters.size()])); // will refresh + } + return hasChange; + } + + private boolean hasChanges(HashSet patterns, String[] oldPatterns) { + HashSet copy= (HashSet) patterns.clone(); + for (int i= 0; i < oldPatterns.length; i++) { + boolean found= copy.remove(oldPatterns[i]); + if (!found) + return true; + } + return !copy.isEmpty(); + } + + // ---------- view kind/defaults persistency ---------- + + private void initializeWithViewDefaults() { + // get default values for view + + + fUserDefinedPatternsEnabled= fStore.getBoolean(getPreferenceKey(TAG_USER_DEFINED_PATTERNS_ENABLED)); + setUserDefinedPatterns(OutlineCustomFiltersDialog.convertFromString(fStore.getString(getPreferenceKey(TAG_USER_DEFINED_PATTERNS)), SEPARATOR)); + + for (Iterator iterator= fFilterItems.values().iterator(); iterator.hasNext();) { + FilterItem item= (FilterItem) iterator.next(); + String id= item.id; + // set default to value from plugin contributions (fixes https://bugs.eclipse.org/bugs/show_bug.cgi?id=73991 ): + fStore.setDefault(id, item.descriptor.isEnabled()); + item.enabled= fStore.getBoolean(id); + } + + } + + private void storeViewDefaults() { + // get default values for view + + fStore.setValue(getPreferenceKey(TAG_USER_DEFINED_PATTERNS_ENABLED), fUserDefinedPatternsEnabled); + fStore.setValue(getPreferenceKey(TAG_USER_DEFINED_PATTERNS), OutlineCustomFiltersDialog.convertToString(fUserDefinedPatterns ,SEPARATOR)); + + boolean fFilterSelected = false; + for (Iterator iterator= fFilterItems.values().iterator(); iterator.hasNext();) { + FilterItem item= (FilterItem) iterator.next(); + fStore.setValue(item.id, item.enabled); + if (item.enabled) + fFilterSelected = true; + } + + fStore.setValue(fTargetId, fUserDefinedPatternsEnabled || fFilterSelected); + + } + + private String getPreferenceKey(String tag) { + return "CustomFiltersActionGroup." + fTargetId + '.' + tag; //$NON-NLS-1$ + } + + + public void openDialog() { + OutlineCustomFiltersDialog dialog= new OutlineCustomFiltersDialog( + fViewer.getControl().getShell(), + fTargetId, + areUserDefinedPatternsEnabled(), + fUserDefinedPatterns, + internalGetEnabledFilterIds()); + + if (dialog.open() == Window.OK) { + + setEnabledFilterIds(dialog.getEnabledFilterIds()); + setUserDefinedPatternsEnabled(dialog.areUserDefinedPatternsEnabled()); + setUserDefinedPatterns(dialog.getUserDefinedPatterns()); + storeViewDefaults(); + + updateViewerFilters(); + } + else { + storeViewDefaults(); + } + } + } + Index: src/org/eclipse/wst/sse/ui/internal/filter/OutlineCustomFiltersDialog.java =================================================================== RCS file: src/org/eclipse/wst/sse/ui/internal/filter/OutlineCustomFiltersDialog.java diff -N src/org/eclipse/wst/sse/ui/internal/filter/OutlineCustomFiltersDialog.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/wst/sse/ui/internal/filter/OutlineCustomFiltersDialog.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,416 @@ +/******************************************************************************* + * Copyright (c) 2010 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.eclipse.wst.sse.ui.internal.filter; + +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.core.runtime.Assert; +import org.eclipse.jface.dialogs.IDialogConstants; +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.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.ui.PlatformUI; +import org.eclipse.ui.dialogs.SelectionDialog; +import org.eclipse.wst.sse.ui.internal.SSEUIPlugin; + + +public class OutlineCustomFiltersDialog extends SelectionDialog { + + private static final String SEPARATOR= ","; //$NON-NLS-1$ + + private String fViewId; + private boolean fEnablePatterns; + private String[] fPatterns; + private String[] fEnabledFilterIds; + + private OutlineFilterDescriptor[] fBuiltInFilters; + + private CheckboxTableViewer fCheckBoxList; + private Button fEnableUserDefinedPatterns; + private Text fUserDefinedPatterns; + + private Stack fFilterDescriptorChangeHistory; + + + /** + * Creates a dialog to customize Java element filters. + * + * @param shell the parent shell + * @param viewId the id of the view + * @param enablePatternstrue
if pattern filters are enabled
+ * @param patterns the filter patterns
+ * @param enabledFilterIds the Ids of the enabled filters
+ */
+ public OutlineCustomFiltersDialog(
+ 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= OutlineFilterDescriptor.getFilterDescriptors(fViewId);
+ fFilterDescriptorChangeHistory= new Stack();
+ }
+ public static final String CUSTOM_FILTERS_DIALOG= SSEUIPlugin.ID + "." + "open_custom_filters_dialog_context"; //$NON-NLS-1$
+ protected void configureShell(Shell shell) {
+ setTitle(OutlineFilterMessages.CustomFiltersDialog_title);
+ setMessage(OutlineFilterMessages.CustomFiltersDialog_filterList_label);
+ super.configureShell(shell);
+ PlatformUI.getWorkbench().getHelpSystem().setHelp(shell, 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(OutlineFilterMessages.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);
+ SWTUtil.setAccessibilityText(fUserDefinedPatterns, OutlineFilterMessages.CustomFiltersDialog_name_filter_pattern_description);
+
+ // Info text
+ final Label info= new Label(group, SWT.LEFT);
+ info.setText(OutlineFilterMessages.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(OutlineFilterMessages.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(OutlineFilterMessages.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 OutlineFilterDescriptor)
+ description.setText(((OutlineFilterDescriptor)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 OutlineFilterDescriptor) {
+ // 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= OutlineFilterMessages.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= OutlineFilterMessages.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 OutlineFilterDescriptor)
+ return ((OutlineFilterDescriptor)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(((OutlineFilterDescriptor)result[i]).getId());
+ return (String[]) enabledIds.toArray(new String[enabledIds.size()]);
+ }
+
+ /**
+ * @return true
if the user-defined patterns are disabled
+ */
+ public boolean areUserDefinedPatternsEnabled() {
+ return fEnablePatterns;
+ }
+
+ /**
+ * @return a stack with the filter descriptor check history
+ */
+ public Stack getFilterDescriptorChangeHistory() {
+ return fFilterDescriptorChangeHistory;
+ }
+
+ private OutlineFilterDescriptor[] getEnabledFilterDescriptors() {
+ OutlineFilterDescriptor[] 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 (OutlineFilterDescriptor[])result.toArray(new OutlineFilterDescriptor[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();
+
+ }
+}
Index: src/org/eclipse/wst/sse/ui/internal/filter/OutlineFilterDescriptor.java
===================================================================
RCS file: src/org/eclipse/wst/sse/ui/internal/filter/OutlineFilterDescriptor.java
diff -N src/org/eclipse/wst/sse/ui/internal/filter/OutlineFilterDescriptor.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ src/org/eclipse/wst/sse/ui/internal/filter/OutlineFilterDescriptor.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,277 @@
+/*******************************************************************************
+ * Copyright (c) 2010 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.eclipse.wst.sse.ui.internal.filter;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import com.ibm.icu.text.Collator;
+
+import org.eclipse.core.runtime.Assert;
+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.core.runtime.SafeRunner;
+
+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.eclipse.wst.sse.ui.internal.SSEUIPlugin;
+
+
+
+/**
+ * Represents a custom filter which is provided by the
+ * "org.eclipse.jdt.ui.javaElementFilters" extension point.
+ *
+ */
+public class OutlineFilterDescriptor implements Comparable, IPluginContribution {
+
+ private static String PATTERN_FILTER_ID_PREFIX= "_patternFilterId_"; //$NON-NLS-1$
+
+
+ private static final String EXTENSION_POINT_NAME= "outlineElementFilter"; //$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$
+ 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$
+
+ private static OutlineFilterDescriptor[] fgFilterDescriptors;
+
+
+ private IConfigurationElement fElement;
+
+ /**
+ * Returns all contributed Java element filters.
+ * @return all contributed Java element filters
+ */
+ public static OutlineFilterDescriptor[] getFilterDescriptors() {
+ if (fgFilterDescriptors == null) {
+ IExtensionRegistry registry= Platform.getExtensionRegistry();
+ IConfigurationElement[] elements= registry.getConfigurationElementsFor(SSEUIPlugin.ID, EXTENSION_POINT_NAME);
+ fgFilterDescriptors= createFilterDescriptors(elements);
+ }
+ return fgFilterDescriptors;
+ }
+ /**
+ * Returns all Java element filters which
+ * are contributed to the given view.
+ * @param targetId the target id
+ * @return all contributed Java element filters for the given view
+ */
+ public static OutlineFilterDescriptor[] getFilterDescriptors(String targetId) {
+ OutlineFilterDescriptor[] filterDescs= OutlineFilterDescriptor.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 (OutlineFilterDescriptor[])result.toArray(new OutlineFilterDescriptor[result.size()]);
+ }
+
+ /**
+ * Creates a new filter descriptor for the given configuration element.
+ * @param element configuration element
+ */
+ private OutlineFilterDescriptor(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 ViewerFilter
.
+ * This method is only valid for viewer filters.
+ * @return a new ViewerFilter
+ */
+ public ViewerFilter createViewerFilter() {
+ if (!isCustomFilter())
+ return null;
+
+ final ViewerFilter[] result= new ViewerFilter[1];
+ String message = OutlineFilterMessages.FilterDescriptor_filterCreationError_message;
+ ISafeRunnable code= new SafeRunnable(message) {
+ /*
+ * @see org.eclipse.core.runtime.ISafeRunnable#run()
+ */
+ public void run() throws Exception {
+ result[0]= (ViewerFilter)fElement.createExecutableExtension(CLASS_ATTRIBUTE);
+ }
+
+ };
+ SafeRunner.run(code);
+ return result[0];
+ }
+
+ //---- XML Attribute accessors ---------------------------------------------
+
+ /**
+ * Returns the filter's id.
+ * + * This attribute is mandatory for custom filters. + * The ID for pattern filters is + * PATTERN_FILTER_ID_PREFIX plus the pattern itself. + *
+ * @return the filter id + */ + 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. + *+ * If the name of a pattern filter is missing + * then the pattern is used as its name. + *
+ * @return the filter's name + */ + 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 ornull
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 null
if the filter is for all views
+ */
+ public String getTargetId() {
+ String tid= fElement.getAttribute(TARGET_ID_ATTRIBUTE);
+
+ if (tid != null)
+ return tid;
+
+ // Backwards compatibility code
+ return null;
+
+ }
+
+ /**
+ * Returns the filter's description.
+ *
+ * @return the description or null
if no description is provided
+ */
+ public String getDescription() {
+ String description= fElement.getAttribute(DESCRIPTION_ATTRIBUTE);
+ if (description == null)
+ description= ""; //$NON-NLS-1$
+ return description;
+ }
+
+ /**
+ * @return true
if this filter is a custom filter.
+ */
+ public boolean isPatternFilter() {
+ return getPattern() != null;
+ }
+
+ /**
+ * @return true
if this filter is a pattern filter.
+ */
+ public boolean isCustomFilter() {
+ return fElement.getAttribute(CLASS_ATTRIBUTE) != null;
+ }
+
+ /**
+ * Returns true
if the filter
+ * is initially enabled.
+ *
+ * This attribute is optional and defaults to true
.
+ * @return returns true
if the filter is initially enabled
+ */
+ public boolean isEnabled() {
+ String strVal= fElement.getAttribute(ENABLED_ATTRIBUTE);
+ return strVal == null || Boolean.valueOf(strVal).booleanValue();
+ }
+
+ /*
+ * Implements a method from IComparable
+ */
+ public int compareTo(Object o) {
+ if (o instanceof OutlineFilterDescriptor)
+ return Collator.getInstance().compare(getName(), ((OutlineFilterDescriptor)o).getName());
+ else
+ return Integer.MIN_VALUE;
+ }
+
+ //---- initialization ---------------------------------------------------
+
+ /**
+ * Creates the filter descriptors.
+ * @param elements the configuration elements
+ * @return new filter descriptors
+ */
+ private static OutlineFilterDescriptor[] 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 OutlineFilterDescriptor[] desc= new OutlineFilterDescriptor[1];
+ SafeRunner.run(new SafeRunnable(OutlineFilterMessages.FilterDescriptor_filterDescriptionCreationError_message) {
+ public void run() throws Exception {
+ desc[0]= new OutlineFilterDescriptor(element);
+ }
+ });
+
+ if (desc[0] != null && !descIds.contains(desc[0].getId())) {
+ result.add(desc[0]);
+ descIds.add(desc[0].getId());
+ }
+ }
+ }
+ return (OutlineFilterDescriptor[])result.toArray(new OutlineFilterDescriptor[result.size()]);
+ }
+
+ public String getLocalId() {
+ return fElement.getAttribute(ID_ATTRIBUTE);
+ }
+
+ public String getPluginId() {
+ return fElement.getContributor().getName();
+ }
+}
Index: src/org/eclipse/wst/sse/ui/internal/filter/OutlineFilterMessages.java
===================================================================
RCS file: src/org/eclipse/wst/sse/ui/internal/filter/OutlineFilterMessages.java
diff -N src/org/eclipse/wst/sse/ui/internal/filter/OutlineFilterMessages.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ src/org/eclipse/wst/sse/ui/internal/filter/OutlineFilterMessages.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,38 @@
+/*******************************************************************************
+ * Copyright (c) 2010 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.eclipse.wst.sse.ui.internal.filter;
+
+import org.eclipse.osgi.util.NLS;
+
+public final class OutlineFilterMessages extends NLS {
+
+ private static final String BUNDLE_NAME= "org.eclipse.wst.sse.ui.internal.filter.OutlineFilterMessages";//$NON-NLS-1$
+
+ private OutlineFilterMessages() {
+ // 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 CustomFiltersDialog_name_filter_pattern_description;
+ public static String OpenCustomFiltersDialogAction_text;
+ public static String FilterDescriptor_filterDescriptionCreationError_message;
+ public static String FilterDescriptor_filterCreationError_message;
+
+ static {
+ NLS.initializeMessages(BUNDLE_NAME, OutlineFilterMessages.class);
+ }
+}
Index: src/org/eclipse/wst/sse/ui/internal/filter/OutlineFilterMessages.properties
===================================================================
RCS file: src/org/eclipse/wst/sse/ui/internal/filter/OutlineFilterMessages.properties
diff -N src/org/eclipse/wst/sse/ui/internal/filter/OutlineFilterMessages.properties
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ src/org/eclipse/wst/sse/ui/internal/filter/OutlineFilterMessages.properties 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,24 @@
+###############################################################################
+# Copyright (c) 2010 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= Java 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
+CustomFiltersDialog_name_filter_pattern_description=Name filter patterns. The patterns are separated by comma, where star is any string
+
+OpenCustomFiltersDialogAction_text= &Filters...
+
+FilterDescriptor_filterDescriptionCreationError_message= One of the extensions for extension-point org.eclipse.wst.sse.ui.outlineElementFilter is incorrect.
+FilterDescriptor_filterCreationError_message= The org.eclipse.wst.sse.ui.sssElementFilters plug-in extension "{0}" specifies a viewer filter class which does not exist.
Index: src/org/eclipse/wst/sse/ui/internal/filter/OutlineNamePatternFilter.java
===================================================================
RCS file: src/org/eclipse/wst/sse/ui/internal/filter/OutlineNamePatternFilter.java
diff -N src/org/eclipse/wst/sse/ui/internal/filter/OutlineNamePatternFilter.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ src/org/eclipse/wst/sse/ui/internal/filter/OutlineNamePatternFilter.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,80 @@
+/*******************************************************************************
+ * Copyright (c) 2010 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.eclipse.wst.sse.ui.internal.filter;
+
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jface.viewers.ViewerFilter;
+import org.w3c.dom.Node;
+
+/**
+ * The NamePatternFilter selects the elements which
+ * match the given string patterns.
+ * + * The following characters have special meaning: + * ? => any character + * * => any string + *
+ * + */ +public class OutlineNamePatternFilter extends ViewerFilter { + private String[] fPatterns; + private StringMatcher[] fMatchers; + + + /** + * Gets the patterns for the receiver. + * @return returns the patterns to be filtered for + */ + public String[] getPatterns() { + return fPatterns; + } + + + /* (non-Javadoc) + * Method declared on ViewerFilter. + */ + public boolean select(Viewer viewer, Object parentElement, Object element) { + if (getPatterns().length == 0) { + return true; + } + String matchName= null; + if (element instanceof Node){ + matchName =((Node)element).getNodeName(); + } + if (matchName != null && matchName.length() > 0) { + String[] fPatterns = getPatterns(); + for (int i = 0; i < fPatterns.length; i++) { + if (new StringMatcher(fPatterns[i], true, false).match(matchName)) + return false; + } + return true; + } + return true; + } + + /** + * Sets the patterns to filter out for the receiver. + *+ * The following characters have special meaning: + * ? => any character + * * => any string + *
+ * @param newPatterns the new patterns + */ + 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); + } + } +} Index: src/org/eclipse/wst/sse/ui/internal/filter/SWTUtil.java =================================================================== RCS file: src/org/eclipse/wst/sse/ui/internal/filter/SWTUtil.java diff -N src/org/eclipse/wst/sse/ui/internal/filter/SWTUtil.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/wst/sse/ui/internal/filter/SWTUtil.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,156 @@ +/******************************************************************************* + * Copyright (c) 2010 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.eclipse.wst.sse.ui.internal.filter; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.accessibility.AccessibleAdapter; +import org.eclipse.swt.accessibility.AccessibleEvent; +import org.eclipse.swt.dnd.DragSource; +import org.eclipse.swt.dnd.DropTarget; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Caret; +import org.eclipse.swt.widgets.Combo; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Menu; +import org.eclipse.swt.widgets.ScrollBar; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.Table; +import org.eclipse.swt.widgets.Widget; + +import org.eclipse.core.runtime.Assert; + +import org.eclipse.jface.dialogs.IDialogConstants; +import org.eclipse.jface.layout.PixelConverter; +import org.eclipse.jface.resource.JFaceResources; + + +/** + * Utility class to simplify access to some SWT resources. + */ +public class SWTUtil { + + + public static final int COMBO_VISIBLE_ITEM_COUNT= 30; + + /** + * Returns the standard display to be used. The method first checks, if + * the thread calling this method has an associated display. If so, this + * display is returned. Otherwise the method returns the default display. + * @return returns the standard display to be used + */ + public static Display getStandardDisplay() { + Display display; + display= Display.getCurrent(); + if (display == null) + display= Display.getDefault(); + return display; + } + + /** + * Returns the shell for the given widget. If the widget doesn't represent + * a SWT object that manage a shell,null
is returned.
+ * @param widget the widget
+ *
+ * @return the shell for the given widget
+ */
+ public static Shell getShell(Widget widget) {
+ if (widget instanceof Control)
+ return ((Control)widget).getShell();
+ if (widget instanceof Caret)
+ return ((Caret)widget).getParent().getShell();
+ if (widget instanceof DragSource)
+ return ((DragSource)widget).getControl().getShell();
+ if (widget instanceof DropTarget)
+ return ((DropTarget)widget).getControl().getShell();
+ if (widget instanceof Menu)
+ return ((Menu)widget).getParent().getShell();
+ if (widget instanceof ScrollBar)
+ return ((ScrollBar)widget).getParent().getShell();
+
+ return null;
+ }
+
+
+ /**
+ * Returns a width hint for a button control.
+ * @param button the button
+ * @return the width hint
+ */
+ public static int getButtonWidthHint(Button button) {
+ button.setFont(JFaceResources.getDialogFont());
+ PixelConverter converter= new PixelConverter(button);
+ int widthHint= converter.convertHorizontalDLUsToPixels(IDialogConstants.BUTTON_WIDTH);
+ return Math.max(widthHint, button.computeSize(SWT.DEFAULT, SWT.DEFAULT, true).x);
+ }
+
+ /**
+ * Sets width and height hint for the button control.
+ * Note: This is a NOP if the button's layout data is not
+ * an instance of GridData
.
+ *
+ * @param button the button for which to set the dimension hint
+ */
+ public static void setButtonDimensionHint(Button button) {
+ Assert.isNotNull(button);
+ Object gd= button.getLayoutData();
+ if (gd instanceof GridData) {
+ ((GridData)gd).widthHint= getButtonWidthHint(button);
+ ((GridData)gd).horizontalAlignment = GridData.FILL;
+ }
+ }
+
+ public static int getTableHeightHint(Table table, int rows) {
+ if (table.getFont().equals(JFaceResources.getDefaultFont()))
+ table.setFont(JFaceResources.getDialogFont());
+ int result= table.getItemHeight() * rows + table.getHeaderHeight();
+ if (table.getLinesVisible())
+ result+= table.getGridLineWidth() * (rows - 1);
+ return result;
+ }
+
+ /**
+ * Adds an accessibility listener returning the given fixed name.
+ *
+ * @param control the control to add the accessibility support to
+ * @param text the name
+ */
+ public static void setAccessibilityText(Control control, final String text) {
+ control.getAccessible().addAccessibleListener(new AccessibleAdapter() {
+ public void getName(AccessibleEvent e) {
+ e.result= text;
+ }
+ });
+ }
+
+ /**
+ *
+ * @param combo the combo
+ *
+ * @see Combo#setVisibleItemCount(int)
+ * @see #COMBO_VISIBLE_ITEM_COUNT
+ *
+ */
+ public static void setDefaultVisibleItemCount(Combo combo) {
+ combo.setVisibleItemCount(COMBO_VISIBLE_ITEM_COUNT);
+ }
+
+ public static GridLayout newLayoutNoMargins(int columns) {
+ GridLayout layout= new GridLayout(columns, false);
+ layout.marginWidth= 0;
+ layout.marginHeight= 0;
+ return layout;
+ }
+
+
+}
Index: src/org/eclipse/wst/sse/ui/internal/filter/StringMatcher.java
===================================================================
RCS file: src/org/eclipse/wst/sse/ui/internal/filter/StringMatcher.java
diff -N src/org/eclipse/wst/sse/ui/internal/filter/StringMatcher.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ src/org/eclipse/wst/sse/ui/internal/filter/StringMatcher.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,384 @@
+/*******************************************************************************
+ * Copyright (c) 2010 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.eclipse.wst.sse.ui.internal.filter;
+
+import java.util.Vector;
+
+/**
+ * A string pattern matcher. Supports '*' and '?' wildcards.
+ */
+public class StringMatcher {
+ protected String fPattern;
+ protected int fLength; // pattern length
+ protected boolean fIgnoreWildCards;
+ protected boolean fIgnoreCase;
+ protected boolean fHasLeadingStar;
+ protected boolean fHasTrailingStar;
+ protected String fSegments[]; //the given pattern is split into * separated segments
+
+ /* boundary value beyond which we don't need to search in the text */
+ protected int fBound= 0;
+
+
+ protected static final char fSingleWildCard= '\u0000';
+
+ public static class Position {
+ int start; //inclusive
+ int end; //exclusive
+ public Position(int start, int end) {
+ this.start= start;
+ this.end= end;
+ }
+ public int getStart() {
+ return start;
+ }
+ public int getEnd() {
+ return end;
+ }
+ }
+ /**
+ * StringMatcher constructor takes in a String object that is a simple
+ * pattern. The pattern may contain '*' for 0 and many characters and
+ * '?' for exactly one character.
+ *
+ * Literal '*' and '?' characters must be escaped in the pattern
+ * e.g., "\*" means literal "*", etc.
+ *
+ * Escaping any other character (including the escape character itself),
+ * just results in that character in the pattern.
+ * e.g., "\a" means "a" and "\\" means "\"
+ *
+ * If invoking the StringMatcher with string literals in Java, don't forget
+ * escape characters are represented by "\\".
+ *
+ * @param pattern the pattern to match text against
+ * @param ignoreCase if true, case is ignored
+ * @param ignoreWildCards if true, wild cards and their escape sequences are ignored
+ * (everything is taken literally).
+ */
+ public StringMatcher(String pattern, boolean ignoreCase, boolean ignoreWildCards) {
+ if (pattern == null)
+ throw new IllegalArgumentException();
+ fIgnoreCase= ignoreCase;
+ fIgnoreWildCards= ignoreWildCards;
+ fPattern= pattern;
+ fLength= pattern.length();
+
+ if (fIgnoreWildCards) {
+ parseNoWildCards();
+ } else {
+ parseWildCards();
+ }
+ }
+ /**
+ * Find the first occurrence of the pattern between start
end(exclusive).
+ * @param text the String object to search in
+ * @param start the starting index of the search range, inclusive
+ * @param end the ending index of the search range, exclusive
+ * @return an StringMatcher.Position
object that keeps the starting
+ * (inclusive) and ending positions (exclusive) of the first occurrence of the
+ * pattern in the specified range of the text; return null if not found or subtext
+ * is empty (start==end). A pair of zeros is returned if pattern is empty string
+ * Note that for pattern like "*abc*" with leading and trailing stars, position of "abc"
+ * is returned. For a pattern like"*??*" in text "abcdf", (1,3) is returned
+ */
+ public StringMatcher.Position find(String text, int start, int end) {
+ if (text == null)
+ throw new IllegalArgumentException();
+
+ int tlen= text.length();
+ if (start < 0)
+ start= 0;
+ if (end > tlen)
+ end= tlen;
+ if (end < 0 ||start >= end )
+ return null;
+ if (fLength == 0)
+ return new Position(start, start);
+ if (fIgnoreWildCards) {
+ int x= posIn(text, start, end);
+ if (x < 0)
+ return null;
+ return new Position(x, x+fLength);
+ }
+
+ int segCount= fSegments.length;
+ if (segCount == 0)//pattern contains only '*'(s)
+ return new Position (start, end);
+
+ int curPos= start;
+ int matchStart= -1;
+ int i;
+ for (i= 0; i < segCount && curPos < end; ++i) {
+ String current= fSegments[i];
+ int nextMatch= regExpPosIn(text, curPos, end, current);
+ if (nextMatch < 0 )
+ return null;
+ if(i == 0)
+ matchStart= nextMatch;
+ curPos= nextMatch + current.length();
+ }
+ if (i < segCount)
+ return null;
+ return new Position(matchStart, curPos);
+ }
+ /**
+ * match the given text
with the pattern
+ * @return true if matched eitherwise false
+ * @param text a String object
+ */
+ public boolean match(String text) {
+ return match(text, 0, text.length());
+ }
+ /**
+ * Given the starting (inclusive) and the ending (exclusive) positions in the
+ * text
, determine if the given substring matches with aPattern
+ * @return true if the specified portion of the text matches the pattern
+ * @param text a String object that contains the substring to match
+ * @param start marks the starting position (inclusive) of the substring
+ * @param end marks the ending index (exclusive) of the substring
+ */
+ public boolean match(String text, int start, int end) {
+ if (null == text)
+ throw new IllegalArgumentException();
+
+ if (start > end)
+ return false;
+
+ if (fIgnoreWildCards)
+ return (end - start == fLength) && fPattern.regionMatches(fIgnoreCase, 0, text, start, fLength);
+ int segCount= fSegments.length;
+ if (segCount == 0 && (fHasLeadingStar || fHasTrailingStar)) // pattern contains only '*'(s)
+ return true;
+ if (start == end)
+ return fLength == 0;
+ if (fLength == 0)
+ return start == end;
+
+ int tlen= text.length();
+ if (start < 0)
+ start= 0;
+ if (end > tlen)
+ end= tlen;
+
+ int tCurPos= start;
+ int bound= end - fBound;
+ if ( bound < 0)
+ return false;
+ int i=0;
+ String current= fSegments[i];
+ int segLength= current.length();
+
+ /* process first segment */
+ if (!fHasLeadingStar){
+ if(!regExpRegionMatches(text, start, current, 0, segLength)) {
+ return false;
+ } else {
+ ++i;
+ tCurPos= tCurPos + segLength;
+ }
+ }
+ if ((fSegments.length == 1) && (!fHasLeadingStar) && (!fHasTrailingStar)) {
+ // only one segment to match, no wildcards specified
+ return tCurPos == end;
+ }
+ /* process middle segments */
+ while (i < segCount) {
+ current= fSegments[i];
+ int currentMatch;
+ int k= current.indexOf(fSingleWildCard);
+ if (k < 0) {
+ currentMatch= textPosIn(text, tCurPos, end, current);
+ if (currentMatch < 0)
+ return false;
+ } else {
+ currentMatch= regExpPosIn(text, tCurPos, end, current);
+ if (currentMatch < 0)
+ return false;
+ }
+ tCurPos= currentMatch + current.length();
+ i++;
+ }
+
+ /* process final segment */
+ if (!fHasTrailingStar && tCurPos != end) {
+ int clen= current.length();
+ return regExpRegionMatches(text, end - clen, current, 0, clen);
+ }
+ return i == segCount ;
+ }
+
+ /**
+ * This method parses the given pattern into segments seperated by wildcard '*' characters.
+ * Since wildcards are not being used in this case, the pattern consists of a single segment.
+ */
+ private void parseNoWildCards() {
+ fSegments= new String[1];
+ fSegments[0]= fPattern;
+ fBound= fLength;
+ }
+ /**
+ * Parses the given pattern into segments seperated by wildcard '*' characters.
+ */
+ private void parseWildCards() {
+ if(fPattern.startsWith("*"))//$NON-NLS-1$
+ fHasLeadingStar= true;
+ if(fPattern.endsWith("*")) {//$NON-NLS-1$
+ /* make sure it's not an escaped wildcard */
+ if (fLength > 1 && fPattern.charAt(fLength - 2) != '\\') {
+ fHasTrailingStar= true;
+ }
+ }
+
+ Vector temp= new Vector();
+
+ int pos= 0;
+ StringBuffer buf= new StringBuffer();
+ while (pos < fLength) {
+ char c= fPattern.charAt(pos++);
+ switch (c) {
+ case '\\':
+ if (pos >= fLength) {
+ buf.append(c);
+ } else {
+ char next= fPattern.charAt(pos++);
+ /* if it's an escape sequence */
+ if (next == '*' || next == '?' || next == '\\') {
+ buf.append(next);
+ } else {
+ /* not an escape sequence, just insert literally */
+ buf.append(c);
+ buf.append(next);
+ }
+ }
+ break;
+ case '*':
+ if (buf.length() > 0) {
+ /* new segment */
+ temp.addElement(buf.toString());
+ fBound += buf.length();
+ buf.setLength(0);
+ }
+ break;
+ case '?':
+ /* append special character representing single match wildcard */
+ buf.append(fSingleWildCard);
+ break;
+ default:
+ buf.append(c);
+ }
+ }
+
+ /* add last buffer to segment list */
+ if (buf.length() > 0) {
+ temp.addElement(buf.toString());
+ fBound += buf.length();
+ }
+
+ fSegments= new String[temp.size()];
+ temp.copyInto(fSegments);
+ }
+ /**
+ * @param text a string which contains no wildcard
+ * @param start the starting index in the text for search, inclusive
+ * @param end the stopping point of search, exclusive
+ * @return the starting index in the text of the pattern , or -1 if not found
+ */
+ protected int posIn(String text, int start, int end) {//no wild card in pattern
+ int max= end - fLength;
+
+ if (!fIgnoreCase) {
+ int i= text.indexOf(fPattern, start);
+ if (i == -1 || i > max)
+ return -1;
+ return i;
+ }
+
+ for (int i= start; i <= max; ++i) {
+ if (text.regionMatches(true, i, fPattern, 0, fLength))
+ return i;
+ }
+
+ return -1;
+ }
+ /**
+ * @param text a simple regular expression that may only contain '?'(s)
+ * @param start the starting index in the text for search, inclusive
+ * @param end the stopping point of search, exclusive
+ * @param p a simple regular expression that may contains '?'
+ * @return the starting index in the text of the pattern , or -1 if not found
+ */
+ protected int regExpPosIn(String text, int start, int end, String p) {
+ int plen= p.length();
+
+ int max= end - plen;
+ for (int i= start; i <= max; ++i) {
+ if (regExpRegionMatches(text, i, p, 0, plen))
+ return i;
+ }
+ return -1;
+ }
+
+
+ protected boolean regExpRegionMatches(String text, int tStart, String p, int pStart, int plen) {
+ while (plen-- > 0) {
+ char tchar= text.charAt(tStart++);
+ char pchar= p.charAt(pStart++);
+
+ /* process wild cards */
+ if (!fIgnoreWildCards) {
+ /* skip single wild cards */
+ if (pchar == fSingleWildCard) {
+ continue;
+ }
+ }
+ if (pchar == tchar)
+ continue;
+ if (fIgnoreCase) {
+ if (Character.toUpperCase(tchar) == Character.toUpperCase(pchar))
+ continue;
+ // comparing after converting to upper case doesn't handle all cases;
+ // also compare after converting to lower case
+ if (Character.toLowerCase(tchar) == Character.toLowerCase(pchar))
+ continue;
+ }
+ return false;
+ }
+ return true;
+ }
+ /**
+ * @param text the string to match
+ * @param start the starting index in the text for search, inclusive
+ * @param end the stopping point of search, exclusive
+ * @param p a string that has no wildcard
+ * @return the starting index in the text of the pattern , or -1 if not found
+ */
+ protected int textPosIn(String text, int start, int end, String p) {
+
+ int plen= p.length();
+ int max= end - plen;
+
+ if (!fIgnoreCase) {
+ int i= text.indexOf(p, start);
+ if (i == -1 || i > max)
+ return -1;
+ return i;
+ }
+
+ for (int i= start; i <= max; ++i) {
+ if (text.regionMatches(true, i, p, 0, plen))
+ return i;
+ }
+
+ return -1;
+ }
+}
Index: src/org/eclipse/wst/sse/ui/internal/handlers/CustomFilterHandler.java
===================================================================
RCS file: src/org/eclipse/wst/sse/ui/internal/handlers/CustomFilterHandler.java
diff -N src/org/eclipse/wst/sse/ui/internal/handlers/CustomFilterHandler.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ src/org/eclipse/wst/sse/ui/internal/handlers/CustomFilterHandler.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,35 @@
+/*******************************************************************************
+ * Copyright (c) 2010 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.eclipse.wst.sse.ui.internal.handlers;
+
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.handlers.HandlerUtil;
+import org.eclipse.ui.views.contentoutline.IContentOutlinePage;
+import org.eclipse.wst.sse.ui.internal.contentoutline.ConfigurableContentOutlinePage;
+import org.eclipse.wst.sse.ui.internal.filter.CustomFilterProcessor;
+
+public class CustomFilterHandler extends AbstractHandler {
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+
+ IEditorPart editor = HandlerUtil.getActiveEditor(event);
+
+ ConfigurableContentOutlinePage page = (ConfigurableContentOutlinePage) editor.getAdapter(IContentOutlinePage.class);
+ if (page != null) {
+ CustomFilterProcessor filterProcessor = new CustomFilterProcessor(page.getConfiguration().getPreferenceStore(), page.getConfiguration().getOutlineFilterTarget(), page.getTreeViewer());
+
+ filterProcessor.openDialog();
+ }
+ return null;
+ }
+}
Index: src/org/eclipse/wst/sse/ui/views/contentoutline/ContentOutlineConfiguration.java
===================================================================
RCS file: /cvsroot/webtools/sourceediting/plugins/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/views/contentoutline/ContentOutlineConfiguration.java,v
retrieving revision 1.17
diff -u -r1.17 ContentOutlineConfiguration.java
--- src/org/eclipse/wst/sse/ui/views/contentoutline/ContentOutlineConfiguration.java 22 Oct 2010 18:37:41 -0000 1.17
+++ src/org/eclipse/wst/sse/ui/views/contentoutline/ContentOutlineConfiguration.java 10 Nov 2010 17:17:25 -0000
@@ -86,6 +86,8 @@
private IContributionItem[] fMenuContributions = null;
private IContributionItem[] fToolbarContributions = null;
private final String OUTLINE_LINK_PREF = "outline-link-editor"; //$NON-NLS-1$
+ private final String OUTLINE_FILTER_PREF = "org.eclipse.wst.sse.ui.OutlinePage"; //$NON-NLS-1$
+ private String fOutlineFilterPref = OUTLINE_FILTER_PREF; //$NON-NLS-1$
ImageDescriptor SYNCED_D = EditorPluginImageHelper.getInstance().getImageDescriptor(EditorPluginImages.IMG_DLCL_SYNCED);
ImageDescriptor SYNCED_E = EditorPluginImageHelper.getInstance().getImageDescriptor(EditorPluginImages.IMG_ELCL_SYNCED);
@@ -195,7 +197,7 @@
* @return the preference store in which to remember preferences (such as
* the link-with-editor toggle state)
*/
- protected IPreferenceStore getPreferenceStore() {
+ public IPreferenceStore getPreferenceStore() {
return SSEUIPlugin.getInstance().getPreferenceStore();
}
@@ -313,4 +315,8 @@
fMenuContributions = null;
}
}
+
+ public String getOutlineFilterTarget(){
+ return fOutlineFilterPref ;
+ }
}
#P org.eclipse.wst.xml.ui
Index: plugin.properties
===================================================================
RCS file: /cvsroot/webtools/sourceediting/plugins/org.eclipse.wst.xml.ui/plugin.properties,v
retrieving revision 1.49
diff -u -r1.49 plugin.properties
--- plugin.properties 15 Oct 2010 19:09:07 -0000 1.49
+++ plugin.properties 10 Nov 2010 17:17:50 -0000
@@ -154,3 +154,11 @@
# XML Documentation view
xmlannotations=Documentation
+
+# outline filter
+HideComments.label=Comments
+HideComments.description=Hides Comments
+HideProcessingInstruction.label=Processing Instructions
+HideProcessingInstruction.description=Hides Processing Instructions
+HideCDATASection.label=CDATA
+HideCDATASection.description=Hides CDATA Section Tags
\ No newline at end of file
Index: plugin.xml
===================================================================
RCS file: /cvsroot/webtools/sourceediting/plugins/org.eclipse.wst.xml.ui/plugin.xml,v
retrieving revision 1.124
diff -u -r1.124 plugin.xml
--- plugin.xml 3 Nov 2010 14:26:54 -0000 1.124
+++ plugin.xml 10 Nov 2010 17:17:56 -0000
@@ -1782,4 +1782,31 @@