diff --git a/bundles/org.eclipse.ui.ide/META-INF/MANIFEST.MF b/bundles/org.eclipse.ui.ide/META-INF/MANIFEST.MF index a55ff0186ad..32bc975604a 100644 --- a/bundles/org.eclipse.ui.ide/META-INF/MANIFEST.MF +++ b/bundles/org.eclipse.ui.ide/META-INF/MANIFEST.MF @@ -63,6 +63,7 @@ Require-Bundle: org.eclipse.core.resources;bundle-version="[3.20.0,4.0.0)";resol org.eclipse.e4.ui.ide;bundle-version="[3.15.0,4.0.0)";visibility:=reexport, org.eclipse.e4.core.di;bundle-version="[1.9.0,2.0.0)", org.eclipse.e4.core.di.extensions;bundle-version="[0.18.0,1.0.0)", + org.eclipse.e4.ui.dialogs;bundle-version="[1.7.0,2.0.0)", org.eclipse.ui.navigator;bundle-version="3.12.0" Import-Package: jakarta.annotation;version="[2.0.0,4.0.0)", jakarta.inject;version="[2.0.0,3.0.0)", diff --git a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/ExtendedMarkersView.java b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/ExtendedMarkersView.java index c77d7387206..2785ff61896 100644 --- a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/ExtendedMarkersView.java +++ b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/ExtendedMarkersView.java @@ -165,6 +165,12 @@ public class ExtendedMarkersView extends ViewPart { private MarkersTreeViewer viewer; + /** + * Hosts {@link #viewer} and provides the search box used to filter the shown + * markers. + */ + private MarkersFilteredTree filteredTree; + private Action filterAction; /** @@ -258,8 +264,12 @@ private void addMarkers(MarkerSupportItem markerItem, Collection allMar private void createViewer(Composite parent) { parent.setLayout(new FillLayout()); - viewer = new MarkersTreeViewer(new Tree(parent, SWT.H_SCROLL - /*| SWT.VIRTUAL */| SWT.V_SCROLL | SWT.MULTI | SWT.FULL_SELECTION)); + filteredTree = new MarkersFilteredTree(parent, + SWT.H_SCROLL /* | SWT.VIRTUAL */ | SWT.V_SCROLL | SWT.MULTI | SWT.FULL_SELECTION, + new MarkerPatternFilter(this)); + filteredTree.setInitialText(MarkerMessages.MarkerView_searchFilterInitialText); + + viewer = (MarkersTreeViewer) filteredTree.getViewer(); WorkbenchViewerSetup.setupViewer(viewer); viewer.getTree().setLinesVisible(true); viewer.setUseHashlookup(true); @@ -1485,6 +1495,17 @@ TreeViewer getViewer() { return viewer; } + /** + * Returns the {@link MarkersFilteredTree} hosting {@link #getViewer() the + * viewer}, which provides the search box used to filter the shown markers. + * + * @return the filtered tree, or null if the view controls were + * not created yet + */ + MarkersFilteredTree getFilteredTree() { + return filteredTree; + } + /** * The method should not be called directly, see * {@link MarkerUpdateScheduler} diff --git a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/MarkerPatternFilter.java b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/MarkerPatternFilter.java new file mode 100644 index 00000000000..b6649ce2c6c --- /dev/null +++ b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/MarkerPatternFilter.java @@ -0,0 +1,70 @@ +/******************************************************************************* + * Copyright (c) 2026 Advantest Europe GmbH and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Raghunandana Murthappa - initial API and implementation + ******************************************************************************/ + +package org.eclipse.ui.internal.views.markers; + +import org.eclipse.e4.ui.dialogs.filteredtree.PatternFilter; +import org.eclipse.jface.viewers.Viewer; +import org.eclipse.ui.views.markers.MarkerField; +import org.eclipse.ui.views.markers.MarkerItem; + +/** + * Matches a marker against the values of every field currently visible in a + * Markers view, so that typing in the view's search box filters the markers by + * any of the values shown in their columns (description, resource, path, + * location, type, ...). + */ +class MarkerPatternFilter extends PatternFilter { + + private final ExtendedMarkersView view; + + MarkerPatternFilter(ExtendedMarkersView view) { + this.view = view; + // so that a marker matches when the typed text occurs anywhere in one of + // its values, not only at the beginning of it + setIncludeLeadingWildcard(true); + } + + @Override + protected boolean isLeafMatch(Viewer viewer, Object element) { + if (!(element instanceof MarkerSupportItem item) || !item.isConcrete()) { + // categories are never a leaf match themselves, they stay visible + // through isParentMatch(...) as long as any of their markers match + return false; + } + for (MarkerField field : view.getVisibleFields()) { + if (matches(field, item)) { + return true; + } + } + return false; + } + + /** + * Returns whether the given item's value for the given field matches the + * current pattern. + */ + private boolean matches(MarkerField field, MarkerItem item) { + String value; + try { + value = field.getValue(item); + } catch (RuntimeException e) { + // a field can fail for markers it does not understand, or whose + // underlying resource vanished meanwhile - it simply does not match + // then, filtering must never break the view + return false; + } + return value != null && wordMatches(value); + } +} diff --git a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/MarkersFilteredTree.java b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/MarkersFilteredTree.java new file mode 100644 index 00000000000..58ad47d7aa2 --- /dev/null +++ b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/MarkersFilteredTree.java @@ -0,0 +1,39 @@ +/******************************************************************************* + * Copyright (c) 2026 Advantest Europe GmbH and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Raghunandana Murthappa - initial API and implementation + ******************************************************************************/ + +package org.eclipse.ui.internal.views.markers; + +import org.eclipse.e4.ui.dialogs.filteredtree.FilteredTree; +import org.eclipse.e4.ui.dialogs.filteredtree.PatternFilter; +import org.eclipse.jface.viewers.TreeViewer; +import org.eclipse.swt.widgets.Composite; + +/** + * A {@link FilteredTree} hosting the {@link MarkersTreeViewer} of a Markers + * view, so that the shown markers can be narrowed down with the search box + * displayed above the tree. + */ +class MarkersFilteredTree extends FilteredTree { + + MarkersFilteredTree(Composite parent, int treeStyle, PatternFilter filter) { + super(parent, treeStyle, filter); + } + + @Override + protected TreeViewer doCreateTreeViewer(Composite parent, int style) { + // the Markers views rely on their own viewer implementation, which + // among others clears the item caches while updating the UI + return new MarkersTreeViewer(parent, style); + } +} diff --git a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/views/markers/internal/MarkerMessages.java b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/views/markers/internal/MarkerMessages.java index 5b40e0e6630..11882254392 100644 --- a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/views/markers/internal/MarkerMessages.java +++ b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/views/markers/internal/MarkerMessages.java @@ -203,6 +203,7 @@ public class MarkerMessages extends NLS { public static String MarkerView_refreshing_counts; public static String MarkerView_queueing_updates; public static String MarkerView_processUpdates; + public static String MarkerView_searchFilterInitialText; public static String MarkerView_18; public static String MarkerView_19; diff --git a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/views/markers/internal/messages.properties b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/views/markers/internal/messages.properties index 716a5e947ef..04332fb93ad 100644 --- a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/views/markers/internal/messages.properties +++ b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/views/markers/internal/messages.properties @@ -185,6 +185,7 @@ MarkerView_waiting_on_changes=Waiting for workspace changes to finish MarkerView_searching_for_markers=Searching for markers MarkerView_refreshing_counts=Refreshing marker counts MarkerView_queueing_updates=Queueing viewer updates +MarkerView_searchFilterInitialText=type filter text MarkerView_18=Filtering on marker limit MarkerView_19=Refreshing view