From 2621c800daed4cda254cc99bd453a741b27ae7b3 Mon Sep 17 00:00:00 2001 From: Christoph Rueger Date: Sun, 5 May 2024 11:26:46 +0200 Subject: [PATCH 1/2] add search bar to ResolutionFailurePanel this allows to search the list of unresolved requirements. IMO this helps to make sense of this list, because without a search it is hard to "see" anything there Signed-off-by: Christoph Rueger --- .../resolve/ui/ResolutionFailurePanel.java | 26 ++++++- ...UnresolvedRequirementsContentProvider.java | 72 ++++++++++++++++++- 2 files changed, 94 insertions(+), 4 deletions(-) diff --git a/bndtools.core/src/org/bndtools/core/resolve/ui/ResolutionFailurePanel.java b/bndtools.core/src/org/bndtools/core/resolve/ui/ResolutionFailurePanel.java index a3107b4870..4eb668f633 100644 --- a/bndtools.core/src/org/bndtools/core/resolve/ui/ResolutionFailurePanel.java +++ b/bndtools.core/src/org/bndtools/core/resolve/ui/ResolutionFailurePanel.java @@ -9,6 +9,7 @@ import org.bndtools.core.resolve.ResolutionResult; import org.bndtools.core.ui.icons.Icons; import org.bndtools.core.ui.resource.RequirementWithResourceLabelProvider; +import org.bndtools.utils.swt.FilterPanelPart; import org.eclipse.core.runtime.IStatus; import org.eclipse.jface.viewers.ITreeContentProvider; import org.eclipse.jface.viewers.TreeViewer; @@ -35,6 +36,7 @@ import org.osgi.service.resolver.ResolutionException; import biz.aQute.resolve.ResolveProcess; +import bndtools.Plugin; import bndtools.model.obr.SorterComparatorAdapter; public class ResolutionFailurePanel { @@ -50,6 +52,11 @@ public class ResolutionFailurePanel { private Section sectProcessingErrors; private Section sectUnresolved; + private UnresolvedRequirementsContentProvider unresolvedRequirementsContentProvider; + private final FilterPanelPart unresolvedFilterPart = new FilterPanelPart(Plugin.getDefault() + .getScheduler()); + private static final String SEARCHSTRING_HINT = "Enter search string to filter unresolved requirements (Space to separate terms; '*' for partial matches)"; + private static final boolean failureTreeMode = true; public void createControl(final Composite parent) { @@ -85,10 +92,16 @@ public void createControl(final Composite parent) { gd.heightHint = 300; sectUnresolved.setLayoutData(gd); + unresolvedViewer = new TreeViewer(treeUnresolved); - unresolvedViewer.setContentProvider(new UnresolvedRequirementsContentProvider()); + + unresolvedRequirementsContentProvider = new UnresolvedRequirementsContentProvider(); + unresolvedViewer.setContentProvider(unresolvedRequirementsContentProvider); unresolvedViewer.setLabelProvider(new RequirementWithResourceLabelProvider()); setFailureViewMode(); + + addSearchbarForUnresolved(); + } public Control getControl() { @@ -301,4 +314,15 @@ private void appendLabels(Object unresolvedTreeElem, ITreeContentProvider conten void dispose() {} + private void addSearchbarForUnresolved() { + Control reqsFilterPanel = unresolvedFilterPart.createControl(composite, 5, 5); + unresolvedFilterPart.setHint(SEARCHSTRING_HINT); + unresolvedFilterPart.addPropertyChangeListener(event -> { + String filter = (String) event.getNewValue(); + + unresolvedRequirementsContentProvider.setFilter(filter); + unresolvedViewer.refresh(); + }); + } + } diff --git a/bndtools.core/src/org/bndtools/core/resolve/ui/UnresolvedRequirementsContentProvider.java b/bndtools.core/src/org/bndtools/core/resolve/ui/UnresolvedRequirementsContentProvider.java index d669a56419..6b5a0a61a8 100644 --- a/bndtools.core/src/org/bndtools/core/resolve/ui/UnresolvedRequirementsContentProvider.java +++ b/bndtools.core/src/org/bndtools/core/resolve/ui/UnresolvedRequirementsContentProvider.java @@ -1,23 +1,52 @@ package org.bndtools.core.resolve.ui; +import java.util.ArrayList; +import java.util.Arrays; import java.util.Collection; +import java.util.LinkedList; +import java.util.List; import org.eclipse.jface.viewers.ITreeContentProvider; import org.eclipse.jface.viewers.Viewer; +import org.osgi.resource.Requirement; + +import aQute.libg.glob.Glob; public class UnresolvedRequirementsContentProvider implements ITreeContentProvider { + private String wildcardFilter = null; + @Override public Object[] getElements(Object inputElement) { + + List arrays = new LinkedList<>(); + if (inputElement instanceof Object[]) - return (Object[]) inputElement; + arrays.add((Object[]) inputElement); if (inputElement instanceof Collection) { Collection coll = (Collection) inputElement; - return coll.toArray(); + arrays.add(coll.toArray()); } - return null; + return filter(flatten(arrays)); + } + + private Object[] flatten(List arrays) { + // Iterate over once to count the lengths + int length = 0; + for (Object[] array : arrays) { + length += array.length; + } + Object[] result = new Object[length]; + + // Iterate again to flatten out the arrays + int position = 0; + for (Object[] array : arrays) { + System.arraycopy(array, 0, result, position, array.length); + position += array.length; + } + return result; } @Override @@ -50,4 +79,41 @@ public boolean hasChildren(Object element) { return false; } + private Object[] filter(Object[] array) { + List filteredResults = new ArrayList<>(); + if (wildcardFilter == null || wildcardFilter.equals("*") || wildcardFilter.equals("")) { + return array; + } else { + String[] split = wildcardFilter.split("\\s+"); + Glob globs[] = new Glob[split.length]; + for (int i = 0; i < split.length; i++) { + globs[i] = new Glob(split[i].toLowerCase()); + } + + Arrays.stream(array) + .forEach(obj -> { + + if (obj instanceof Requirement rw) { + + for (Glob g : globs) { + if (g.matcher(rw.toString() + .toLowerCase()) + .find()) { + filteredResults.add(obj); + return; + } + } + } + + }); + + } + + return filteredResults.toArray(); + } + + public void setFilter(String filter) { + this.wildcardFilter = filter; + } + } From e83718a8f60678b643ed3ef12cdd01c395953b35 Mon Sep 17 00:00:00 2001 From: Christoph Rueger Date: Sun, 5 May 2024 11:31:38 +0200 Subject: [PATCH 2/2] improve search by using the full label Signed-off-by: Christoph Rueger --- .../bndtools/core/resolve/ui/ResolutionFailurePanel.java | 7 +++++-- .../ui/UnresolvedRequirementsContentProvider.java | 9 ++++++++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/bndtools.core/src/org/bndtools/core/resolve/ui/ResolutionFailurePanel.java b/bndtools.core/src/org/bndtools/core/resolve/ui/ResolutionFailurePanel.java index 4eb668f633..564d70e073 100644 --- a/bndtools.core/src/org/bndtools/core/resolve/ui/ResolutionFailurePanel.java +++ b/bndtools.core/src/org/bndtools/core/resolve/ui/ResolutionFailurePanel.java @@ -58,6 +58,7 @@ public class ResolutionFailurePanel { private static final String SEARCHSTRING_HINT = "Enter search string to filter unresolved requirements (Space to separate terms; '*' for partial matches)"; private static final boolean failureTreeMode = true; + private RequirementWithResourceLabelProvider requirementWithResourceLabelProvider; public void createControl(final Composite parent) { FormToolkit toolkit = new FormToolkit(parent.getDisplay()); @@ -95,9 +96,11 @@ public void createControl(final Composite parent) { unresolvedViewer = new TreeViewer(treeUnresolved); - unresolvedRequirementsContentProvider = new UnresolvedRequirementsContentProvider(); + requirementWithResourceLabelProvider = new RequirementWithResourceLabelProvider(); + unresolvedViewer.setLabelProvider(requirementWithResourceLabelProvider); + unresolvedRequirementsContentProvider = new UnresolvedRequirementsContentProvider( + requirementWithResourceLabelProvider); unresolvedViewer.setContentProvider(unresolvedRequirementsContentProvider); - unresolvedViewer.setLabelProvider(new RequirementWithResourceLabelProvider()); setFailureViewMode(); addSearchbarForUnresolved(); diff --git a/bndtools.core/src/org/bndtools/core/resolve/ui/UnresolvedRequirementsContentProvider.java b/bndtools.core/src/org/bndtools/core/resolve/ui/UnresolvedRequirementsContentProvider.java index 6b5a0a61a8..4421132413 100644 --- a/bndtools.core/src/org/bndtools/core/resolve/ui/UnresolvedRequirementsContentProvider.java +++ b/bndtools.core/src/org/bndtools/core/resolve/ui/UnresolvedRequirementsContentProvider.java @@ -6,6 +6,7 @@ import java.util.LinkedList; import java.util.List; +import org.bndtools.core.ui.resource.RequirementWithResourceLabelProvider; import org.eclipse.jface.viewers.ITreeContentProvider; import org.eclipse.jface.viewers.Viewer; import org.osgi.resource.Requirement; @@ -15,6 +16,11 @@ public class UnresolvedRequirementsContentProvider implements ITreeContentProvider { private String wildcardFilter = null; + private RequirementWithResourceLabelProvider labelProvider; + + public UnresolvedRequirementsContentProvider(RequirementWithResourceLabelProvider labelProvider) { + this.labelProvider = labelProvider; + } @Override public Object[] getElements(Object inputElement) { @@ -96,7 +102,8 @@ private Object[] filter(Object[] array) { if (obj instanceof Requirement rw) { for (Glob g : globs) { - if (g.matcher(rw.toString() + if (g.matcher(labelProvider.getLabel(rw) + .toString() .toLowerCase()) .find()) { filteredResults.add(obj);