| author | Sascha Becher | 2012-02-28 17:22:29 (EST) |
|---|---|---|
| committer | Curtis Windatt | 2012-02-28 17:24:05 (EST) |
| commit | 97efef7d5fdd7f7b4236744427df566ae811e826 (patch) (side-by-side diff) | |
| tree | 5f8d67d1104e0235348b5d69494d9bf13b928ab2 | |
| parent | aa329da03215585202e84e13473c2d47f2bc84fd (diff) | |
| download | eclipse.pde.ui-97efef7d5fdd7f7b4236744427df566ae811e826.zip eclipse.pde.ui-97efef7d5fdd7f7b4236744427df566ae811e826.tar.gz eclipse.pde.ui-97efef7d5fdd7f7b4236744427df566ae811e826.tar.bz2 | |
Bug 372803 - Extension Element Search shows wrong match count
8 files changed, 248 insertions, 137 deletions
diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/PDEUIMessages.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/PDEUIMessages.java index fdbe4a0..4d39c12 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/PDEUIMessages.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/PDEUIMessages.java @@ -1429,6 +1429,7 @@ public class PDEUIMessages extends NLS { public static String Actions_delete_label; public static String Actions_filter_relatedPluginElements; public static String Actions_search_relatedPluginElements; + public static String Actions_search_targetplatform; public static String Actions_synchronizeVersions_label; public static String Menus_new_label; diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/actions/SearchExtensionsAction.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/actions/SearchExtensionsAction.java index 40ae21b..afd006b 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/actions/SearchExtensionsAction.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/actions/SearchExtensionsAction.java @@ -11,8 +11,7 @@ package org.eclipse.pde.internal.ui.editor.actions; import org.eclipse.jface.action.Action; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.viewers.*; import org.eclipse.pde.internal.core.search.PluginSearchInput; import org.eclipse.pde.internal.core.search.PluginSearchScope; import org.eclipse.pde.internal.ui.PDEPluginImages; @@ -30,31 +29,26 @@ import org.eclipse.search.ui.NewSearchUI; */ public class SearchExtensionsAction extends Action { - protected FormFilteredTree fFilteredTree; + private FormFilteredTree fFilteredTree; + private boolean fUseCurrentFilter; - private IStructuredSelection fSelection; - private String fFilterRelatedText; - - public SearchExtensionsAction(FormFilteredTree filteredTree, String actionText) { - this(filteredTree.getViewer().getSelection(), actionText); - fFilteredTree = filteredTree; - } - - public SearchExtensionsAction(ISelection selection, String actionText) { + /** + * @param filteredTree the extensions section tree + * @param actionText description + * @param useCurrentFilter when <code>true</code> the search is performed with the current filtering applied to the tree, + * otherwise the filter text is generated from the current selection + */ + public SearchExtensionsAction(FormFilteredTree filteredTree, String actionText, boolean useCurrentFilter) { setImageDescriptor(PDEPluginImages.DESC_SEARCH_EXTENSIONS); setDisabledImageDescriptor(PDEPluginImages.DESC_SEARCH_EXTENSIONS_DISABLED); setText(actionText); - if (selection != null && selection instanceof IStructuredSelection) { - fSelection = (IStructuredSelection) selection; - } + fFilteredTree = filteredTree; + fUseCurrentFilter = useCurrentFilter; } public void run() { - if (fSelection != null) { - this.fFilterRelatedText = ExtensionsFilterUtil.getFilterRelatedPattern(fSelection); - NewSearchUI.activateSearchResultView(); - NewSearchUI.runQueryInBackground(createSearchQuery()); - } + NewSearchUI.activateSearchResultView(); + NewSearchUI.runQueryInBackground(createSearchQuery()); } protected ISearchQuery createSearchQuery() { @@ -68,13 +62,23 @@ public class SearchExtensionsAction extends Action { } private String getFilterText() { - if (fFilterRelatedText != null && fFilterRelatedText.length() > 0) { - return fFilterRelatedText; - } if (fFilteredTree != null) { - return fFilteredTree.getFilterControl().getText(); + if (fUseCurrentFilter && fFilteredTree.isFiltered()) { + return fFilteredTree.getFilterControl().getText(); + } + return ExtensionsFilterUtil.getFilterRelatedPattern(getSelection()); } return new String(); } + private IStructuredSelection getSelection() { + if (fFilteredTree != null && fFilteredTree.getViewer() != null) { + ISelection selection = fFilteredTree.getViewer().getSelection(); + if (selection != null && selection instanceof IStructuredSelection) { + return (IStructuredSelection) selection; + } + } + return new StructuredSelection(); + } + }
\ No newline at end of file diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/plugin/ExtensionsSection.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/plugin/ExtensionsSection.java index 46b9e7b..c41b1ef 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/plugin/ExtensionsSection.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/plugin/ExtensionsSection.java @@ -20,6 +20,7 @@ import org.eclipse.core.runtime.jobs.IJobChangeEvent; import org.eclipse.core.runtime.jobs.JobChangeAdapter; import org.eclipse.jface.action.*; import org.eclipse.jface.dialogs.IMessageProvider; +import org.eclipse.jface.layout.GridDataFactory; import org.eclipse.jface.resource.JFaceResources; import org.eclipse.jface.util.IPropertyChangeListener; import org.eclipse.jface.util.PropertyChangeEvent; @@ -54,6 +55,8 @@ import org.eclipse.swt.dnd.Clipboard; import org.eclipse.swt.events.*; import org.eclipse.swt.graphics.*; import org.eclipse.swt.internal.BidiUtil; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.*; import org.eclipse.ui.actions.ActionContext; import org.eclipse.ui.actions.ActionFactory; @@ -64,11 +67,12 @@ import org.eclipse.ui.progress.WorkbenchJob; public class ExtensionsSection extends TreeSection implements IModelChangedListener, IPropertyChangeListener { private static final int REFRESHJOB_DELAY_TIME = 1200; // milliseconds to wait private static final int ACCELERATED_SCROLLING = 15; // lines to skip - private static final int BUTTON_MOVE_DOWN = 4; - private static final int BUTTON_MOVE_UP = 3; - private static final int BUTTON_EDIT = 2; - private static final int BUTTON_REMOVE = 1; - private static final int BUTTON_ADD = 0; + private static final int BUTTON_MOVE_DOWN = 5; + private static final int BUTTON_MOVE_UP = 4; + private static final int BUTTON_EDIT = 3; + private static final int BUTTON_REMOVE = 2; + private static final int BUTTON_ADD = 1; + private static final int BUTTON_SEARCH = 0; private TreeViewer fExtensionTree; private Image fExtensionImage; private Image fGenericElementImage; @@ -80,6 +84,7 @@ public class ExtensionsSection extends TreeSection implements IModelChangedListe private CollapseAction fCollapseAction; private ToggleExpandStateAction fExpandAction; private FilterRelatedExtensionsAction fFilterRelatedAction; + private SearchExtensionsAction fSearchToolbarAction; private SearchExtensionsAction fSearchAction; private boolean fBypassFilterDelay = false; @@ -149,7 +154,7 @@ public class ExtensionsSection extends TreeSection implements IModelChangedListe } public ExtensionsSection(PDEFormPage page, Composite parent) { - super(page, parent, Section.DESCRIPTION, new String[] {PDEUIMessages.ManifestEditor_DetailExtension_new, PDEUIMessages.ManifestEditor_DetailExtension_remove, PDEUIMessages.ManifestEditor_DetailExtension_edit, PDEUIMessages.ManifestEditor_DetailExtension_up, PDEUIMessages.ManifestEditor_DetailExtension_down}); + super(page, parent, Section.DESCRIPTION, new String[] {PDEUIMessages.Actions_search_targetplatform, PDEUIMessages.ManifestEditor_DetailExtension_new, PDEUIMessages.ManifestEditor_DetailExtension_remove, PDEUIMessages.ManifestEditor_DetailExtension_edit, PDEUIMessages.ManifestEditor_DetailExtension_up, PDEUIMessages.ManifestEditor_DetailExtension_down}); fHandleDefaultButton = false; } @@ -237,6 +242,13 @@ public class ExtensionsSection extends TreeSection implements IModelChangedListe Composite container = createClientContainer(section, 2, toolkit); TreePart treePart = getTreePart(); createViewerPartControl(container, SWT.MULTI, 2, toolkit); + // fix layout to place search button right to the filter text + Control searchButton = treePart.getButton(BUTTON_SEARCH); + ((GridLayout) searchButton.getParent().getLayout()).marginHeight = 2; + searchButton.setLayoutData(GridDataFactory.swtDefaults().align(SWT.BEGINNING, SWT.BEGINNING).grab(false, false).hint(SWT.DEFAULT, 19).create()); + searchButton.setToolTipText(PDEUIMessages.ExtensionsPage_searchWithExtensionsFilter); + Control addButton = treePart.getButton(BUTTON_ADD); + ((GridData) addButton.getLayoutData()).verticalIndent = 16; fExtensionTree = treePart.getTreeViewer(); fExtensionTree.setContentProvider(new ExtensionContentProvider()); fExtensionTree.setLabelProvider(new ExtensionLabelProvider()); @@ -283,9 +295,11 @@ public class ExtensionsSection extends TreeSection implements IModelChangedListe // Add action to filter tree with some of the selection's attributes fFilterRelatedAction = new FilterRelatedExtensionsAction(fExtensionTree, fFilteredTree, this, false); toolBarManager.add(fFilterRelatedAction); + // Add action to search workspace for related elements according to tree selection + fSearchToolbarAction = new SearchExtensionsAction(fFilteredTree, PDEUIMessages.Actions_search_relatedPluginElements, false); + toolBarManager.add(fSearchToolbarAction); // Add action to search all workspace plugins with current filtering applied to the tree viewer - fSearchAction = new SearchExtensionsAction(fFilteredTree, PDEUIMessages.ExtensionsPage_searchWithExtensionsFilter); - toolBarManager.add(fSearchAction); + fSearchAction = new SearchExtensionsAction(fFilteredTree, PDEUIMessages.ExtensionsPage_searchWithExtensionsFilter, true); // Add separator Separator separator = new Separator(); toolBarManager.add(separator); @@ -324,6 +338,9 @@ public class ExtensionsSection extends TreeSection implements IModelChangedListe protected void buttonSelected(int index) { switch (index) { + case BUTTON_SEARCH : + fSearchAction.run(); + break; case BUTTON_ADD : handleNew(); break; @@ -437,7 +454,7 @@ public class ExtensionsSection extends TreeSection implements IModelChangedListe if (ExtensionsFilterUtil.isFilterRelatedEnabled(ssel)) { FilterRelatedExtensionsAction filterRelatedAction = new FilterRelatedExtensionsAction(fExtensionTree, fFilteredTree, this, true); manager.add(filterRelatedAction); - SearchExtensionsAction searchRelatedAction = new SearchExtensionsAction(ssel, PDEUIMessages.Actions_search_relatedPluginElements); + SearchExtensionsAction searchRelatedAction = new SearchExtensionsAction(fFilteredTree, PDEUIMessages.Actions_search_relatedPluginElements, false); manager.add(searchRelatedAction); manager.add(new Separator()); } @@ -584,7 +601,7 @@ public class ExtensionsSection extends TreeSection implements IModelChangedListe Text filterControl = fFilteredTree.getFilterControl(); if (filterControl != null && attributeValue != null) { String trimmedValue = attributeValue.trim(); - if (trimmedValue.length() > 0 && ExtensionsFilterUtil.isNotBoolean(trimmedValue)) { + if (trimmedValue.length() > 0 && !ExtensionsFilterUtil.isBoolean(trimmedValue)) { if (trimmedValue.startsWith("%")) {//$NON-NLS-1$ IPluginModelBase model = getPluginModelBase(); trimmedValue = ((model != null) ? model.getResourceString(trimmedValue) : trimmedValue).replaceAll("\"", ""); //$NON-NLS-1$ //$NON-NLS-2$ @@ -1294,16 +1311,21 @@ public class ExtensionsSection extends TreeSection implements IModelChangedListe } private void updateButtons(Object item) { + boolean filterRelatedEnabled = false; + if (fExtensionTree != null) { + filterRelatedEnabled = ExtensionsFilterUtil.isFilterRelatedEnabled((IStructuredSelection) fExtensionTree.getSelection()); + } if (fExpandAction != null) { fExpandAction.setEnabled(ToggleExpandStateAction.isExpandable((IStructuredSelection) fExtensionTree.getSelection())); } if (fFilterRelatedAction != null) { - fFilterRelatedAction.setEnabled(ExtensionsFilterUtil.isFilterRelatedEnabled((IStructuredSelection) fExtensionTree.getSelection())); + fFilterRelatedAction.setEnabled(filterRelatedEnabled); } - if (fSearchAction != null) { + if (fSearchToolbarAction != null && fSearchAction != null) { Text filterControl = fFilteredTree.getFilterControl(); boolean searchEnabled = filterControl != null && filterControl.getText().length() > 0; - fSearchAction.setEnabled(searchEnabled); + getTreePart().setButtonEnabled(BUTTON_SEARCH, searchEnabled); + fSearchToolbarAction.setEnabled(filterRelatedEnabled); } if (getPage().getModel().isEditable() == false) diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/pderesources.properties b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/pderesources.properties index c1562a3..417a959 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/pderesources.properties +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/pderesources.properties @@ -1191,6 +1191,7 @@ Actions_open_label = &Open Actions_delete_label = &Delete Actions_filter_relatedPluginElements=&Filter Related Actions_search_relatedPluginElements=Search &Related +Actions_search_targetplatform=Search Actions_synchronizeVersions_label = S&ynchronize Versions... Menus_new_label = &New @@ -1541,7 +1542,7 @@ ExtensionsPage_title=Extensions ExtensionsPage_tabName=Extensions ExtensionsPage_sortAlpha=Sort the Extensions alphabetically ExtensionsPage_toggleExpandState=Toggle Expand State -ExtensionsPage_searchWithExtensionsFilter=Extension Element Search +ExtensionsPage_searchWithExtensionsFilter=Search with current filter ExtensionDetails_title=Extension Details ExtensionDetails_desc=Set the properties of the selected extension. Required fields are denoted by "*". ExtensionDetails_id=ID diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/search/ExtensionsPatternFilter.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/search/ExtensionsPatternFilter.java index ba0e021..0b37bd2 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/search/ExtensionsPatternFilter.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/search/ExtensionsPatternFilter.java @@ -11,8 +11,6 @@ package org.eclipse.pde.internal.ui.search; import java.util.*; -import java.util.regex.Matcher; -import java.util.regex.Pattern; import org.eclipse.jface.viewers.Viewer; import org.eclipse.pde.core.plugin.*; import org.eclipse.pde.internal.core.bundle.BundlePlugin; @@ -41,13 +39,14 @@ public class ExtensionsPatternFilter extends PatternFilter { protected String fSearchPattern; - protected Set fAttributes = new HashSet(); + protected Set fSearchPatterns = new HashSet(); protected final Set fMatchingLeafs = new HashSet(); protected final Set fFoundAnyElementsCache = new HashSet(); /** - * Check if the leaf element is a match with the filter text. The - * default behavior checks that the label of the element is a match. + * Check if the leaf element is a match with the filter text. The default behavior + * checks that the element name or extension point is a match employing wildcards. + * An implicit wild card is added at the end always (default behaviour). * * Subclasses should override this method. * @@ -58,11 +57,10 @@ public class ExtensionsPatternFilter extends PatternFilter { * @return true if the given element's label matches the filter text */ protected boolean isLeafMatch(Viewer viewer, Object element) { - // match label; default behaviour - if (viewer != null && super.isLeafMatch(viewer, element)) { + // match element name or extension point with wildcards; modified default behaviour + if (isNameMatch(element)) { return true; } - // match all splitted attribute's values of IPluginElement against splitted filter patterns if (element instanceof IPluginElement) { return doIsLeafMatch((IPluginElement) element); @@ -72,30 +70,33 @@ public class ExtensionsPatternFilter extends PatternFilter { protected boolean doIsLeafMatch(IPluginElement pluginElement) { List syntheticAttributes = ExtensionsFilterUtil.handlePropertyTester(pluginElement); - if (fAttributes != null && fAttributes.size() > 0) { + if (fSearchPatterns != null && fSearchPatterns.size() > 0) { int attributeNumber = 0; - for (Iterator iterator = fAttributes.iterator(); iterator.hasNext();) { - String valuePattern = (String) iterator.next(); - if (attributeNumber < fAttributes.size() && attributeNumber < ATTRIBUTE_LIMIT) { - boolean quoted = isQuoted(valuePattern); - if (valuePattern != null && valuePattern.length() > 0) { + for (Iterator iterator = fSearchPatterns.iterator(); iterator.hasNext();) { + String searchPattern = (String) iterator.next(); + if (attributeNumber < fSearchPatterns.size() && attributeNumber < ATTRIBUTE_LIMIT) { + boolean quoted = isQuoted(searchPattern); + if (searchPattern != null && searchPattern.length() > 0) { + if (quoted) { + searchPattern = searchPattern.substring(1, searchPattern.length() - 1); + } int attributeCount = pluginElement.getAttributeCount(); - IPluginAttribute[] pluginAttributes = pluginElement.getAttributes(); + IPluginAttribute[] elementAttributes = pluginElement.getAttributes(); for (int i = 0; i < attributeCount; i++) { - IPluginAttribute attributeElement = pluginAttributes[i]; + IPluginAttribute attributeElement = elementAttributes[i]; if (attributeElement != null && attributeElement.getValue() != null) { String[] attributes = getAttributeSplit(attributeElement.getValue(), quoted); if (attributes != null) { List attributeList = new ArrayList(Arrays.asList(attributes)); attributeList.addAll(syntheticAttributes); - if (matchWithAttributes(pluginElement, valuePattern, attributeList, quoted)) { + if (matchWithAttributes(pluginElement, searchPattern, attributeElement.getName(), attributeList, quoted)) { return true; } } } } - if (valuePattern.equalsIgnoreCase(pluginElement.getName())) { + if (searchPattern.equalsIgnoreCase(pluginElement.getName())) { return true; } } @@ -106,36 +107,93 @@ public class ExtensionsPatternFilter extends PatternFilter { return false; } - private boolean matchWithAttributes(IPluginElement pluginElement, String valuePattern, List attributeList, boolean quoted) { + protected boolean isNameMatch(Object element) { + if (element != null) { + if (element instanceof IPluginElement) { + if (super.wordMatches(((IPluginElement) element).getName())) { + return true; + } + } else if (element instanceof IPluginExtension) { + if (super.wordMatches(((IPluginExtension) element).getPoint())) { + return true; + } + } + } + return false; + } + + protected boolean matchWithAttributes(IPluginElement pluginElement, String searchPattern, String attributeName, List attributeList, boolean quoted) { for (int k = 0; k < attributeList.size(); k++) { - String attribute = (String) attributeList.get(k); - if (attribute != null && attribute.length() > 0) { - if (!attribute.startsWith("%")) { //$NON-NLS-1$ - int delimiterPosition = attribute.indexOf('?'); // strip right of '?' + String attributeValue = (String) attributeList.get(k); + if (attributeValue != null && attributeValue.length() > 0) { + if (!attributeValue.startsWith("%") || quoted) { //$NON-NLS-1$ + int delimiterPosition = attributeValue.indexOf('?'); // strip right of '?' if (delimiterPosition != -1) { - attribute = attribute.substring(0, delimiterPosition); + attributeValue = attributeValue.substring(0, delimiterPosition); + } + // case insensitive exact match required + if (attributeValue.equalsIgnoreCase(searchPattern)) { + return true; + // missing use of resource bundle localization requires wildcard enabled search + } else if (!quoted && isNoneResourceMatch(attributeValue, attributeName, searchPattern)) { + return true; + } + } else { // resource bundle key found + String resourceValue = pluginElement.getResourceString(attributeValue); + attributeValue = (resourceValue != null && resourceValue.length() > 0) ? resourceValue : attributeValue; + super.setPattern(new String(searchPattern)); + // case insensitive match required with wildcards enabled + boolean match = (super.wordMatches(attributeValue)); + super.setPattern(fSearchPattern); + if (match) { + return true; } - } else { - String resourceValue = pluginElement.getResourceString(attribute); - attribute = (resourceValue != null && resourceValue.length() > 0) ? resourceValue : attribute; - } - String pattern = valuePattern.toLowerCase(); - if (quoted) { - pattern = pattern.substring(1, pattern.length() - 1); } - if (attribute.toLowerCase().equals(pattern)) { + } + } + return false; + } + + /** + * While the plugin model offers resource bundle localization, some plugins may skip this and use fix text for display. + * Wildcard enabled search of the PatternFilter should be available in this case. Only a list of attributes that + * are expected to contain resource bundles are evaluated as long as the value doesn't contain a point. On some elements + * for example a name attribute can contain an id. Those are skipped though. + * + * @param attributeValue + * @param attributeName + * @param searchPattern + * @return whether this is a match + */ + protected boolean isNoneResourceMatch(String attributeValue, String attributeName, String searchPattern) { + if (ExtensionsFilterUtil.isAttributeNameMatch(attributeName, ExtensionsFilterUtil.RESOURCE_ATTRIBUTES)) { + if (attributeValue.indexOf('.') == -1 && searchPattern.indexOf('.') == -1) { // no ids + super.setPattern(searchPattern); + boolean match = super.wordMatches(attributeValue); + super.setPattern(fSearchPattern); + if (match) { return true; } + super.setPattern(fSearchPattern); } } return false; } - private static boolean isQuoted(String value) { + static boolean isQuoted(String value) { return value.startsWith("\"") && value.endsWith("\""); //$NON-NLS-1$ //$NON-NLS-2$ } - private static String[] getAttributeSplit(String text, boolean quoted) { + /** + * Splits attributes on occurrence of /<br> + * If <code>quoted</code> is set to <code>true</code> parameter <code>text</code> is returned as the only + * element in the array, thus skipping the splitting. + * + * @param text text to split + * @param quoted decides whether splitting actually occurs + * @return split array containing the splitted attributes or one element containing the value of parameter <code>text</code> + */ + static String[] getAttributeSplit(String text, boolean quoted) { if (text.length() < 2) { return null; } @@ -225,28 +283,7 @@ public class ExtensionsPatternFilter extends PatternFilter { text = text.replaceAll("\"{1,}", "\""); //$NON-NLS-1$//$NON-NLS-2$ // treat quoted text as a whole, thus enables searching for file paths if (text.replaceAll("[^\"]", "").length() % 2 == 0) { //$NON-NLS-1$//$NON-NLS-2$ - List patterns = new ArrayList(); - List matchList = new ArrayList(); - Pattern regex = Pattern.compile("[^\\s\"']+|\"[^\"]*\"|'[^']*'"); //$NON-NLS-1$ - Matcher regexMatcher = regex.matcher(text); - while (regexMatcher.find()) { - matchList.add(regexMatcher.group()); - } - for (int i = 0; i < matchList.size(); i++) { - String element = (String) matchList.get(i); - if (isQuoted(element)) { - patterns.add(element); - } else { - String[] elements = element.split("/"); //$NON-NLS-1$ - for (int k = 0; k < elements.length; k++) { - String splitted = elements[k]; - if (splitted.length() > 0) { - patterns.add(splitted); - } - } - } - } - return (String[]) patterns.toArray(new String[0]); + return text.split("/(?=([^\"]*\"[^\"]*\")*(?![^\"]*\"))"); //$NON-NLS-1$ } // filter text must have erroneous quoting, replacing all text = text.replaceAll("[\"]", ""); //$NON-NLS-1$ //$NON-NLS-2$ } @@ -281,11 +318,14 @@ public class ExtensionsPatternFilter extends PatternFilter { super.setPattern(patternString); fSearchPattern = patternString; String[] patterns = (patternString != null) ? splitWithQuoting(patternString) : new String[] {}; - fAttributes.clear(); - fAttributes.addAll(Arrays.asList(patterns)); + fSearchPatterns.clear(); + fSearchPatterns.addAll(Arrays.asList(patterns)); fFoundAnyElementsCache.clear(); } + /** + * @return the whole filter text (unsplit) + */ public String getPattern() { return fSearchPattern; } diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/search/FindExtensionsByAttributeQuery.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/search/FindExtensionsByAttributeQuery.java index b6d0ed2..91bf1e8 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/search/FindExtensionsByAttributeQuery.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/search/FindExtensionsByAttributeQuery.java @@ -77,12 +77,13 @@ public class FindExtensionsByAttributeQuery implements ISearchQuery { */ public ISearchResult getSearchResult() { if (fSearchResult == null) - fSearchResult = new SearchResult(this); + fSearchResult = new SearchResult(this) { + public int getMatchCount() { + // returns overall count of plugins found when searching + return getElements().length; + } + }; return fSearchResult; } - public PluginSearchInput getPluginSearchInput() { - return fSearchInput; - } - }
\ No newline at end of file diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/util/AcceleratedTreeScrolling.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/util/AcceleratedTreeScrolling.java index 652079d..52c4ff0 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/util/AcceleratedTreeScrolling.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/util/AcceleratedTreeScrolling.java @@ -68,20 +68,22 @@ public class AcceleratedTreeScrolling implements MouseWheelListener { if (index == 0) { return parentItem; } - TreeItem nextItem = parentItem == null ? tree.getItem(index - 1) : parentItem.getItem(index - 1); - int count = nextItem.getItemCount(); - while (count > 0 && nextItem.getExpanded()) { - nextItem = nextItem.getItem(count - 1); - count = nextItem.getItemCount(); + TreeItem previousItem = parentItem == null ? tree.getItem(index - 1) : parentItem.getItem(index - 1); + int count = previousItem.getItemCount(); + while (count > 0 && previousItem.getExpanded()) { + previousItem = previousItem.getItem(count - 1); + count = previousItem.getItemCount(); } - return nextItem; + return previousItem; } TreeItem NextItem(Tree tree, TreeItem item) { if (item == null) return null; if (item.getExpanded()) { - return item.getItem(0); + if (item.getItemCount() > 0) { + return item.getItem(0); + } } TreeItem childItem = item; TreeItem parentItem = childItem.getParentItem(); diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/util/ExtensionsFilterUtil.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/util/ExtensionsFilterUtil.java index 75a5a95..9068875 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/util/ExtensionsFilterUtil.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/util/ExtensionsFilterUtil.java @@ -24,12 +24,16 @@ public class ExtensionsFilterUtil { public static final String ATTRIBUTE_CATEGORYID = "categoryId"; //$NON-NLS-1$ public static final String ATTRIBUTE_COMMANDID = "commandId"; //$NON-NLS-1$ public static final String ATTRIBUTE_DEFAULTHANDLER = "defaultHandler"; //$NON-NLS-1$ + public static final String ATTRIBUTE_DESCRIPTION = "description"; //$NON-NLS-1$ public static final String ATTRIBUTE_ID = "id"; //$NON-NLS-1$ + public static final String ATTRIBUTE_LABEL = "label"; //$NON-NLS-1$ + public static final String ATTRIBUTE_MNEMONIC = "mnemonic"; //$NON-NLS-1$ public static final String ATTRIBUTE_NAME = "name"; //$NON-NLS-1$ public static final String ATTRIBUTE_NAMESPACE = "namespace"; //$NON-NLS-1$ public static final String ATTRIBUTE_PROPERTIES = "properties"; //$NON-NLS-1$ public static final String ATTRIBUTE_PATTERN = "pattern"; //$NON-NLS-1$ public static final String ATTRIBUTE_REQUIREDACTIVITYID = "requiredActivityId"; //$NON-NLS-1$ + public static final String ATTRIBUTE_TOOLTIP = "tooltip"; //$NON-NLS-1$ public static final String ATTRIBUTE_VALUE = "value"; //$NON-NLS-1$ public static final String ELEMENT_ACATEGORY = "org.eclipse.ui.activities.category"; //$NON-NLS-1$ @@ -37,15 +41,18 @@ public class ExtensionsFilterUtil { public static final String ELEMENT_AR_BINDING = "org.eclipse.ui.activities.activityRequirementBinding"; //$NON-NLS-1$ public static final String ELEMENT_CA_BINDING = "org.eclipse.ui.activities.categoryActivityBinding"; //$NON-NLS-1$ public static final String ELEMENT_COMMAND = "org.eclipse.ui.commands.command"; //$NON-NLS-1$ - public static final String ELEMENT_EQUALS = "org.eclipse.ui.handlers.equals"; //$NON-NLS-1$ + public static final String ELEMENT_EQUALS = "equals"; //$NON-NLS-1$ public static final String ELEMENT_HELP_TOC = "org.eclipse.help.toc.toc"; //$NON-NLS-1$ - public static final String ELEMENT_INSTANCEOF = "org.eclipse.ui.handlers.instanceof"; //$NON-NLS-1$ + public static final String ELEMENT_INSTANCEOF = "instanceof"; //$NON-NLS-1$ public static final String ELEMENT_MENU_COMMAND = "org.eclipse.ui.menus.command"; //$NON-NLS-1$ + public static final String ELEMENT_PARAMETER = "parameter"; //$NON-NLS-1$ public static final String ELEMENT_PATTERNBINDING = "org.eclipse.ui.activities.activityPatternBinding"; //$NON-NLS-1$ public static final String ELEMENT_PROPERTYTESTER = "org.eclipse.core.expressions.propertyTesters.propertyTester"; //$NON-NLS-1$ + public static final String ELEMENT_VARIABLE = "variable"; //$NON-NLS-1$ public static final String[] HIGH_PRIORITY_ELEMENTS = new String[] {ELEMENT_COMMAND, ELEMENT_MENU_COMMAND, ELEMENT_INSTANCEOF, ELEMENT_EQUALS}; - public static final String[] LOW_PRIORITY_ELEMENTS = new String[] {ELEMENT_CA_BINDING, ELEMENT_AR_BINDING, ELEMENT_HELP_TOC}; + public static final String[] LOW_PRIORITY_ELEMENTS = new String[] {ELEMENT_PARAMETER, ELEMENT_CA_BINDING, ELEMENT_AR_BINDING, ELEMENT_VARIABLE, ELEMENT_HELP_TOC}; + public static final String[] RESOURCE_ATTRIBUTES = new String[] {ATTRIBUTE_LABEL, ATTRIBUTE_NAME, ATTRIBUTE_TOOLTIP, ATTRIBUTE_MNEMONIC, ATTRIBUTE_DESCRIPTION}; public static final Map CUSTOM_RELATIONS; @@ -54,12 +61,18 @@ public class ExtensionsFilterUtil { CUSTOM_RELATIONS.put(ELEMENT_COMMAND, new String[] {ATTRIBUTE_ID, ATTRIBUTE_DEFAULTHANDLER}); CUSTOM_RELATIONS.put(ELEMENT_INSTANCEOF, new String[] {ATTRIBUTE_VALUE}); CUSTOM_RELATIONS.put(ELEMENT_EQUALS, new String[] {ATTRIBUTE_VALUE}); + CUSTOM_RELATIONS.put(ELEMENT_PARAMETER, new String[] {ATTRIBUTE_NAME}); + CUSTOM_RELATIONS.put(ELEMENT_VARIABLE, new String[] {ATTRIBUTE_NAME}); CUSTOM_RELATIONS.put(ELEMENT_MENU_COMMAND, new String[] {ATTRIBUTE_COMMANDID, ATTRIBUTE_ID}); CUSTOM_RELATIONS.put(ELEMENT_CA_BINDING, new String[] {ATTRIBUTE_ACTIVITYID, ATTRIBUTE_CATEGORYID}); CUSTOM_RELATIONS.put(ELEMENT_AR_BINDING, new String[] {ATTRIBUTE_REQUIREDACTIVITYID, ATTRIBUTE_ACTIVITYID}); CUSTOM_RELATIONS.put(ELEMENT_HELP_TOC, new String[] {ATTRIBUTE_CATEGORY}); } + private static String BOOLEAN_TRUE = "true"; //$NON-NLS-1$ + private static String BOOLEAN_FALSE = "false"; //$NON-NLS-1$ + private static String ADDITIONS = "additions"; //$NON-NLS-1$ + public static boolean add(Set pattern, IPluginElement pluginElement, String attributeName) { IPluginAttribute attribute = pluginElement.getAttribute(attributeName); if (attribute != null) { @@ -71,7 +84,7 @@ public class ExtensionsFilterUtil { public static boolean add(Set pattern, String value) { if (value != null && value.length() > 0) { String trimmed = value.trim(); - if (isNotBoolean(trimmed)) { + if (!isBoolean(trimmed)) { return pattern.add(trimmed); } } @@ -130,14 +143,17 @@ public class ExtensionsFilterUtil { if (!value.startsWith("%")) { //$NON-NLS-1$ int delimiterPosition = value.indexOf('?'); // split before '?' and right after last '=' if (delimiterPosition == -1) { - if (!value.equalsIgnoreCase("true") && !value.equalsIgnoreCase("false")) { //$NON-NLS-1$ //$NON-NLS-2$ + if (!isBoolean(value)) { filterPatterns.add(value); } } else { filterPatterns.add(value.substring(0, delimiterPosition)); int position = value.lastIndexOf('='); if (position != -1) { - filterPatterns.add(value.substring(position + 1, value.length())); + String placeHolder = value.substring(position + 1, value.length()); + if (!placeHolder.equalsIgnoreCase(ADDITIONS)) { + filterPatterns.add(placeHolder); + } } } } else { @@ -203,10 +219,12 @@ public class ExtensionsFilterUtil { private static boolean addMatchingElements(Set customAttributes, IPluginElement pluginElement, String elementName, final String[] elements) { boolean elementMatch = false; - for (int i = 0; i < elements.length; i++) { - if (elements[i].equals(elementName)) { - addAll(customAttributes, pluginElement, elements[i]); - elementMatch = true; + if (elementName != null) { + for (int i = 0; i < elements.length; i++) { + if (elementName.endsWith(elements[i])) { + addAll(customAttributes, pluginElement, elements[i]); + elementMatch = true; + } } } return elementMatch; @@ -232,23 +250,36 @@ public class ExtensionsFilterUtil { public static List handlePropertyTester(IPluginElement pluginElement) { List propertyTestAttributes = new ArrayList(); + if (isElementNameMatch(pluginElement, ELEMENT_PROPERTYTESTER)) { + Set attributes = handlePropertyTester(new HashSet(), pluginElement); + for (Iterator iterator = attributes.iterator(); iterator.hasNext();) { + propertyTestAttributes.add(iterator.next()); + } + } + return propertyTestAttributes; + } + + public static boolean isElementNameMatch(IPluginElement pluginElement, String expected) { String elementName = getElementPath(pluginElement); - boolean elementMatch = false; if (elementName == null) { // workaround for non-editable plugins of the target platform - if (ELEMENT_PROPERTYTESTER.endsWith(pluginElement.getName())) { - elementMatch = true; + if (expected.endsWith(pluginElement.getName())) { + return true; } - } else if (ELEMENT_PROPERTYTESTER.equalsIgnoreCase(elementName)) { - elementMatch = true; + } else if (elementName.endsWith(expected)) { + return true; } - if (elementMatch) { - Set attributes = handlePropertyTester(new HashSet(), pluginElement); - for (Iterator iterator = attributes.iterator(); iterator.hasNext();) { - propertyTestAttributes.add(iterator.next()); + return false; + } + + public static boolean isAttributeNameMatch(String attributeName, String[] matches) { + for (int i = 0; i < matches.length; i++) { + String matchingAttribute = matches[i]; + if (matchingAttribute.equals(attributeName)) { + return true; } } - return propertyTestAttributes; + return false; } public static boolean isFilterRelatedEnabled(IPluginElement pluginElement) { @@ -260,13 +291,22 @@ public class ExtensionsFilterUtil { } } // test for custom relations - Object attributes = CUSTOM_RELATIONS.get(getElementPath(pluginElement)); - if (attributes != null) { - String[] attributesArray = (String[]) attributes; - for (int i = 0; i < attributesArray.length; i++) { - IPluginAttribute attribute = pluginElement.getAttribute(attributesArray[i]); - if (attribute != null) { - return true; + String elementName = getElementPath(pluginElement); + if (elementName != null) { + Set keySet = CUSTOM_RELATIONS.keySet(); + for (Iterator iterator = keySet.iterator(); iterator.hasNext();) { + String key = (String) iterator.next(); + if (elementName.endsWith(key)) { + Object attributes = CUSTOM_RELATIONS.get(key); + if (attributes != null) { + String[] attributesArray = (String[]) attributes; + for (int i = 0; i < attributesArray.length; i++) { + IPluginAttribute attribute = pluginElement.getAttribute(attributesArray[i]); + if (attribute != null) { + return true; + } + } + } } } } @@ -287,8 +327,8 @@ public class ExtensionsFilterUtil { return createFilterRelatedAction; } - public static boolean isNotBoolean(String bool) { - return !bool.equalsIgnoreCase(Boolean.TRUE.toString()) && !bool.equalsIgnoreCase(Boolean.FALSE.toString()); + public static boolean isBoolean(String bool) { + return bool.equalsIgnoreCase(BOOLEAN_TRUE) || bool.equalsIgnoreCase(BOOLEAN_FALSE); } }
\ No newline at end of file |

