Skip to content

Commit

Permalink
Do not expand same class twice in (quick) type hierarchy
Browse files Browse the repository at this point in the history
  • Loading branch information
fedejeanne committed Jan 15, 2025
1 parent 42dc611 commit 221a17f
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 1 deletion.
8 changes: 8 additions & 0 deletions org.eclipse.jdt.ui/.settings/.api_filters
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,14 @@
</message_arguments>
</filter>
</resource>
<resource path="ui/org/eclipse/jdt/internal/ui/typehierarchy/HierarchyInformationControl.java" type="org.eclipse.jdt.internal.ui.typehierarchy.HierarchyInformationControl">
<filter id="571519004">
<message_arguments>
<message_argument value="org.eclipse.jdt.internal.ui.typehierarchy.HierarchyInformationControl.createTreeViewer(Composite, int)"/>
<message_argument value="TreeViewer"/>
</message_arguments>
</filter>
</resource>
<resource path="ui/org/eclipse/jdt/internal/ui/viewsupport/ProblemTableViewer.java" type="org.eclipse.jdt.internal.ui.viewsupport.ProblemTableViewer">
<filter id="571473929">
<message_arguments>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
package org.eclipse.jdt.internal.ui.typehierarchy;

import java.lang.reflect.InvocationTargetException;
import java.util.HashSet;
import java.util.Set;
import java.util.function.Predicate;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.KeyAdapter;
Expand All @@ -23,6 +26,7 @@
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.widgets.Tree;
import org.eclipse.swt.widgets.Widget;

import org.eclipse.jface.bindings.TriggerSequence;
import org.eclipse.jface.bindings.keys.KeySequence;
Expand Down Expand Up @@ -130,7 +134,23 @@ protected TreeViewer createTreeViewer(Composite parent, int style) {
gd.heightHint= tree.getItemHeight() * 12;
tree.setLayoutData(gd);

TreeViewer treeViewer= new TreeViewer(tree);
TreeViewer treeViewer= new TreeViewer(tree) {
@Override
protected Predicate<Widget> getShouldWidgetExpand() {

Set<Object> expanded= new HashSet<>();

// Expand every class/interface only once
return w -> {
if (w == null) {
return false;
}

Object data= w.getData();
return data == null || expanded.add(data);
};
}
};
treeViewer.addFilter(new ViewerFilter() {
@Override
public boolean select(Viewer viewer, Object parentElement, Object element) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,15 @@
*******************************************************************************/
package org.eclipse.jdt.internal.ui.typehierarchy;

import java.util.HashSet;
import java.util.Set;
import java.util.function.Predicate;

import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.Tree;
import org.eclipse.swt.widgets.Widget;

import org.eclipse.core.runtime.Assert;

Expand Down Expand Up @@ -182,4 +187,19 @@ protected TypeHierarchyContentProvider getHierarchyContentProvider() {
return (TypeHierarchyContentProvider)getContentProvider();
}

@Override
protected Predicate<Widget> getShouldWidgetExpand() {
Set<Object> expanded= new HashSet<>();

// Expand every class/interface only once
return w -> {
if (w == null) {
return false;
}

Object data= w.getData();
return data == null || expanded.add(data);
};
}

}

0 comments on commit 221a17f

Please sign in to comment.