### Eclipse Workspace Patch 1.0
#P org.eclipse.jst.jsp.ui
Index: plugin.properties
===================================================================
RCS file: /cvsroot/webtools/sourceediting/plugins/org.eclipse.jst.jsp.ui/plugin.properties,v
retrieving revision 1.26
diff -u -r1.26 plugin.properties
--- plugin.properties 16 Nov 2009 20:21:19 -0000 1.26
+++ plugin.properties 10 Feb 2010 09:02:35 -0000
@@ -104,3 +104,9 @@
##
Java_Element_hyperlink=Java Element
Taglib_hyperlink=Tag Library Descriptor
+
+HideImportDeclaration.label=Import Directive
+HideImportDeclaration.description=Hides Import Directives
+
+HideFontStyle.label=Font Style
+HideFontStyle.description=Hides Font Style Tags
Index: plugin.xml
===================================================================
RCS file: /cvsroot/webtools/sourceediting/plugins/org.eclipse.jst.jsp.ui/plugin.xml,v
retrieving revision 1.93
diff -u -r1.93 plugin.xml
--- plugin.xml 3 Dec 2009 02:44:10 -0000 1.93
+++ plugin.xml 10 Feb 2010 09:02:40 -0000
@@ -1071,4 +1071,24 @@
+ true
if pattern filters are enabled
+ * @param patterns the filter patterns
+ * @param enabledFilterIds the Ids of the enabled filters
+ */
+ public SSECustomFiltersDialog(
+ 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= SSEFilterDescriptor.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(SSEFilterMessages.CustomFiltersDialog_title);
+ setMessage(SSEFilterMessages.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(SSEFilterMessages.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, SSEFilterMessages.CustomFiltersDialog_name_filter_pattern_description);
+
+ // Info text
+ final Label info= new Label(group, SWT.LEFT);
+ info.setText(SSEFilterMessages.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(SSEFilterMessages.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(SSEFilterMessages.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 SSEFilterDescriptor)
+ description.setText(((SSEFilterDescriptor)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 SSEFilterDescriptor) {
+ // 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= SSEFilterMessages.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= SSEFilterMessages.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 SSEFilterDescriptor)
+ return ((SSEFilterDescriptor)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(((SSEFilterDescriptor)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
+ * @since 3.0
+ */
+ public Stack getFilterDescriptorChangeHistory() {
+ return fFilterDescriptorChangeHistory;
+ }
+
+ private SSEFilterDescriptor[] getEnabledFilterDescriptors() {
+ SSEFilterDescriptor[] 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 (SSEFilterDescriptor[])result.toArray(new SSEFilterDescriptor[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/filter/SSEFilterDescriptor.java
===================================================================
RCS file: src/org/eclipse/wst/sse/ui/filter/SSEFilterDescriptor.java
diff -N src/org/eclipse/wst/sse/ui/filter/SSEFilterDescriptor.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ src/org/eclipse/wst/sse/ui/filter/SSEFilterDescriptor.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,290 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 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.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.
+ *
+ * since 2.0
+ */
+public class SSEFilterDescriptor implements Comparable, IPluginContribution {
+
+ private static String PATTERN_FILTER_ID_PREFIX= "_patternFilterId_"; //$NON-NLS-1$
+
+
+ private static final String EXTENSION_POINT_NAME= "sseElementFilter"; //$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 SSEFilterDescriptor#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 SSEFilterDescriptor[] fgFilterDescriptors;
+
+
+ private IConfigurationElement fElement;
+
+ /**
+ * Returns all contributed Java element filters.
+ * @return all contributed Java element filters
+ */
+ public static SSEFilterDescriptor[] 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 SSEFilterDescriptor[] getFilterDescriptors(String targetId) {
+ SSEFilterDescriptor[] filterDescs= SSEFilterDescriptor.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 (SSEFilterDescriptor[])result.toArray(new SSEFilterDescriptor[result.size()]);
+ }
+
+ /**
+ * Creates a new filter descriptor for the given configuration element.
+ * @param element configuration element
+ */
+ private SSEFilterDescriptor(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 = SSEFilterMessages.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
+ * @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 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);
+ 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 SSEFilterDescriptor)
+ return Collator.getInstance().compare(getName(), ((SSEFilterDescriptor)o).getName());
+ else
+ return Integer.MIN_VALUE;
+ }
+
+ //---- initialization ---------------------------------------------------
+
+ /**
+ * Creates the filter descriptors.
+ * @param elements the configuration elements
+ * @return new filter descriptors
+ */
+ private static SSEFilterDescriptor[] 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 SSEFilterDescriptor[] desc= new SSEFilterDescriptor[1];
+ SafeRunner.run(new SafeRunnable(SSEFilterMessages.FilterDescriptor_filterDescriptionCreationError_message) {
+ public void run() throws Exception {
+ desc[0]= new SSEFilterDescriptor(element);
+ }
+ });
+
+ if (desc[0] != null && !descIds.contains(desc[0].getId())) {
+ result.add(desc[0]);
+ descIds.add(desc[0].getId());
+ }
+ }
+ }
+ return (SSEFilterDescriptor[])result.toArray(new SSEFilterDescriptor[result.size()]);
+ }
+
+ public String getLocalId() {
+ return fElement.getAttribute(ID_ATTRIBUTE);
+ }
+
+ public String getPluginId() {
+ return fElement.getContributor().getName();
+ }
+}
Index: src/org/eclipse/wst/sse/ui/filter/SSEFilterMessages.java
===================================================================
RCS file: src/org/eclipse/wst/sse/ui/filter/SSEFilterMessages.java
diff -N src/org/eclipse/wst/sse/ui/filter/SSEFilterMessages.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ src/org/eclipse/wst/sse/ui/filter/SSEFilterMessages.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,38 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 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.filter;
+
+import org.eclipse.osgi.util.NLS;
+
+public final class SSEFilterMessages extends NLS {
+
+ private static final String BUNDLE_NAME= "org.eclipse.wst.sse.ui.filter.SSEFilterMessages";//$NON-NLS-1$
+
+ private SSEFilterMessages() {
+ // 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, SSEFilterMessages.class);
+ }
+}
Index: src/org/eclipse/wst/sse/ui/filter/SSEFilterMessages.properties
===================================================================
RCS file: src/org/eclipse/wst/sse/ui/filter/SSEFilterMessages.properties
diff -N src/org/eclipse/wst/sse/ui/filter/SSEFilterMessages.properties
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ src/org/eclipse/wst/sse/ui/filter/SSEFilterMessages.properties 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,24 @@
+###############################################################################
+# Copyright (c) 2000, 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.sseElementFilters 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/filter/SSENamePatternFilter.java
===================================================================
RCS file: src/org/eclipse/wst/sse/ui/filter/SSENamePatternFilter.java
diff -N src/org/eclipse/wst/sse/ui/filter/SSENamePatternFilter.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ src/org/eclipse/wst/sse/ui/filter/SSENamePatternFilter.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,81 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 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.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 + *
+ * + * @since 2.0 + */ +public class SSENamePatternFilter extends ViewerFilter { + private String[] fPatterns; + private SSEStringMatcher[] 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 SSEStringMatcher(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 SSEStringMatcher[newPatterns.length]; + for (int i = 0; i < newPatterns.length; i++) { + //Reset the matchers to prevent constructor overhead + fMatchers[i]= new SSEStringMatcher(newPatterns[i], true, false); + } + } +} Index: src/org/eclipse/wst/sse/ui/filter/SSEStringMatcher.java =================================================================== RCS file: src/org/eclipse/wst/sse/ui/filter/SSEStringMatcher.java diff -N src/org/eclipse/wst/sse/ui/filter/SSEStringMatcher.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/wst/sse/ui/filter/SSEStringMatcher.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,384 @@ +/******************************************************************************* + * Copyright (c) 2000, 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.filter; + +import java.util.Vector; + +/** + * A string pattern matcher. Supports '*' and '?' wildcards. + */ +public class SSEStringMatcher { + 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 SSEStringMatcher(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 betweenstart
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 SSEStringMatcher.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/filter/SWTUtil.java
===================================================================
RCS file: src/org/eclipse/wst/sse/ui/filter/SWTUtil.java
diff -N src/org/eclipse/wst/sse/ui/filter/SWTUtil.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ src/org/eclipse/wst/sse/ui/filter/SWTUtil.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,166 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 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.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 {
+
+ /**
+ * The default visible item count for {@link Combo}s.
+ * Workaround for https://bugs.eclipse.org/bugs/show_bug.cgi?id=245569 .
+ *
+ * @see Combo#setVisibleItemCount(int)
+ *
+ * @since 3.5
+ */
+ 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;
+ }
+ });
+ }
+
+ /**
+ * Sets the default visible item count for {@link Combo}s.
+ * Workaround for https://bugs.eclipse.org/bugs/show_bug.cgi?id=7845 .
+ *
+ * @param combo the combo
+ *
+ * @see Combo#setVisibleItemCount(int)
+ * @see #COMBO_VISIBLE_ITEM_COUNT
+ *
+ * @since 3.5
+ */
+ 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/SSEUIMessages.java
===================================================================
RCS file: /cvsroot/webtools/sourceediting/plugins/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/SSEUIMessages.java,v
retrieving revision 1.25
diff -u -r1.25 SSEUIMessages.java
--- src/org/eclipse/wst/sse/ui/internal/SSEUIMessages.java 4 Feb 2010 21:17:09 -0000 1.25
+++ src/org/eclipse/wst/sse/ui/internal/SSEUIMessages.java 10 Feb 2010 09:03:08 -0000
@@ -185,6 +185,7 @@
public static String ShowPropertiesAction_0;
public static String ContentOutlineConfiguration_0;
public static String ContentOutlineConfiguration_1;
+ public static String ContentOutlineConfiguration_2;
public static String AbstractOpenOn_0;
public static String FormatActionDelegate_jobName;
public static String FormatActionDelegate_errorStatusMessage;
Index: src/org/eclipse/wst/sse/ui/internal/SSEUIPluginResources.properties
===================================================================
RCS file: /cvsroot/webtools/sourceediting/plugins/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/SSEUIPluginResources.properties,v
retrieving revision 1.30
diff -u -r1.30 SSEUIPluginResources.properties
--- src/org/eclipse/wst/sse/ui/internal/SSEUIPluginResources.properties 4 Feb 2010 21:17:09 -0000 1.30
+++ src/org/eclipse/wst/sse/ui/internal/SSEUIPluginResources.properties 10 Feb 2010 09:03:09 -0000
@@ -159,6 +159,7 @@
ShowPropertiesAction_0=P&roperties
ContentOutlineConfiguration_0=Collapse All
ContentOutlineConfiguration_1=Link with Editor
+ContentOutlineConfiguration_2=Filters
AbstractOpenOn_0=Current text selection does not resolve to a file
FormatActionDelegate_jobName=Formatting...
FormatActionDelegate_errorStatusMessage=Exceptions occurred while formatting documents
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.16
diff -u -r1.16 ContentOutlineConfiguration.java
--- src/org/eclipse/wst/sse/ui/views/contentoutline/ContentOutlineConfiguration.java 10 Apr 2007 20:06:19 -0000 1.16
+++ src/org/eclipse/wst/sse/ui/views/contentoutline/ContentOutlineConfiguration.java 10 Feb 2010 09:03:10 -0000
@@ -86,6 +86,9 @@
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);
@@ -107,7 +110,9 @@
*/
protected IContributionItem[] createMenuContributions(TreeViewer viewer) {
IContributionItem toggleLinkItem = new PropertyChangeUpdateActionContributionItem(new ToggleLinkAction(getPreferenceStore(), OUTLINE_LINK_PREF));
- IContributionItem[] items = new IContributionItem[]{toggleLinkItem};
+ IContributionItem filterItem = new CustomFilterActionContributionItem(new CustomFilterAction(getPreferenceStore(),fOutlineFilterPref, viewer),fOutlineFilterPref, getPreferenceStore(), viewer );
+
+ IContributionItem[] items = new IContributionItem[]{toggleLinkItem, filterItem};
return items;
}
@@ -313,4 +318,12 @@
fMenuContributions = null;
}
}
+
+ // added
+
+ public void setOutlineFilterTarget(String targetId){
+ fOutlineFilterPref = targetId;
+ }
+
+
}
Index: src/org/eclipse/wst/sse/ui/views/contentoutline/CustomFilterAction.java
===================================================================
RCS file: src/org/eclipse/wst/sse/ui/views/contentoutline/CustomFilterAction.java
diff -N src/org/eclipse/wst/sse/ui/views/contentoutline/CustomFilterAction.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ src/org/eclipse/wst/sse/ui/views/contentoutline/CustomFilterAction.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,343 @@
+package org.eclipse.wst.sse.ui.views.contentoutline;
+
+ /*******************************************************************************
+ * Copyright (c) 2001, 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
+ *******************************************************************************/
+
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Map;
+
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.jface.viewers.StructuredViewer;
+import org.eclipse.jface.viewers.ViewerFilter;
+import org.eclipse.jface.window.Window;
+import org.eclipse.wst.sse.ui.filter.SSECustomFiltersDialog;
+import org.eclipse.wst.sse.ui.filter.SSEFilterDescriptor;
+import org.eclipse.wst.sse.ui.filter.SSENamePatternFilter;
+import org.eclipse.wst.sse.ui.internal.SSEUIMessages;
+import org.eclipse.wst.sse.ui.internal.contentoutline.PropertyChangeUpdateAction;
+
+ /**
+ * Action group to add the filter action to a view part's tool bar
+ * menu.
+ * + * This class may be instantiated; it is not intended to be subclassed. + *
+ * + * @since 2.0 + * + * @noextend This class is not intended to be subclassed by clients. + */ + public class CustomFilterAction extends PropertyChangeUpdateAction { + + + 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; + SSEFilterDescriptor descriptor; + String id; + + private ViewerFilter filterInstance= null; + + public FilterItem(SSEFilterDescriptor 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 SSENamePatternFilter 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 CustomFilterAction(IPreferenceStore store,String ownerId, StructuredViewer viewer) {
+ super(SSEUIMessages.ContentOutlineConfiguration_2, store, ownerId, store.getBoolean(ownerId)); //$NON-NLS-1$
+ Assert.isNotNull(ownerId);
+ Assert.isNotNull(viewer);
+ fStore = store;
+ fTargetId= ownerId;
+ fViewer= viewer;
+ fPatternFilter= new SSENamePatternFilter();
+
+ fUserDefinedPatterns= new String[0];
+ fUserDefinedPatternsEnabled= false;
+ fPreviousPatterns= new String[0];
+
+ fFilterItems= new HashMap();
+ SSEFilterDescriptor[] filterDescriptors= SSEFilterDescriptor.getFilterDescriptors(fTargetId);
+ for (int i= 0; i < filterDescriptors.length; i++) {
+ FilterItem item= new FilterItem(filterDescriptors[i]);
+ fFilterItems.put(item.id, item);
+
+ }
+
+ initializeWithViewDefaults();
+
+ updateViewerFilters();
+
+ }
+
+ public void update() {
+ openDialog();
+ }
+
+
+
+ /*
+ * @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 + * + * @since 3.1 + * + * @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 SSENamePatternFilter){ + SSENamePatternFilter filter = (SSENamePatternFilter)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(SSECustomFiltersDialog.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), SSECustomFiltersDialog.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$ + } + + + private void openDialog() { + SSECustomFiltersDialog dialog= new SSECustomFiltersDialog( + 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/views/contentoutline/CustomFilterActionContributionItem.java =================================================================== RCS file: src/org/eclipse/wst/sse/ui/views/contentoutline/CustomFilterActionContributionItem.java diff -N src/org/eclipse/wst/sse/ui/views/contentoutline/CustomFilterActionContributionItem.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/wst/sse/ui/views/contentoutline/CustomFilterActionContributionItem.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,83 @@ +/******************************************************************************* + * Copyright (c) 2001, 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.views.contentoutline; + +import org.eclipse.jface.action.Action; +import org.eclipse.jface.action.ActionContributionItem; +import org.eclipse.jface.preference.IPreferenceStore; +import org.eclipse.jface.viewers.Viewer; +import org.eclipse.swt.events.MenuEvent; +import org.eclipse.swt.events.MenuListener; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.SelectionListener; +import org.eclipse.swt.widgets.Menu; +import org.eclipse.swt.widgets.MenuItem; +import org.eclipse.ui.texteditor.IUpdate; + +/** + * A listener on the given action's PreferenceStore. It calls .update() on the + * action when the given key changes value. + */ +public class CustomFilterActionContributionItem extends ActionContributionItem { + + + + private String fProperty = null; + private IPreferenceStore fStore; + private int fIndex; + + public CustomFilterActionContributionItem(Action action, String preference, IPreferenceStore store, Viewer viewer) { + super(action); + fProperty = preference; + fStore = store; + } + + /* + * Overrides method from ContributionItem. + */ + public void fill(Menu menu, int index) { + + super.fill(menu, index); + fIndex = index; + MenuItem filterMenuItem = menu.getItem(index); + + menu.addMenuListener(new MenuListener() { + + public void menuShown(MenuEvent e) { + Object obj =e.getSource(); + if (obj instanceof Menu){ + Menu menu = (Menu)obj; + menu.getItem(fIndex).setSelection(fStore.getBoolean(fProperty)); + } + } + + public void menuHidden(MenuEvent e) { + + } + }); + + filterMenuItem.addSelectionListener(new SelectionListener() { + + public void widgetSelected(SelectionEvent e) { + ((IUpdate) getAction()).update(); + + } + + public void widgetDefaultSelected(SelectionEvent e) { + + } + }); + + } + + +} #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.44 diff -u -r1.44 plugin.properties --- plugin.properties 16 Nov 2009 20:21:30 -0000 1.44 +++ plugin.properties 10 Feb 2010 09:03:16 -0000 @@ -137,4 +137,14 @@ # Menu contributions command.toggle.comment.mnemonic=T command.add.block.comment.mnemonic=A -command.remove.block.comment.mnemonic=R \ No newline at end of file +command.remove.block.comment.mnemonic=R + + +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.110 diff -u -r1.110 plugin.xml --- plugin.xml 3 Dec 2009 02:44:03 -0000 1.110 +++ plugin.xml 10 Feb 2010 09:03:19 -0000 @@ -1661,5 +1661,34 @@ +