Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not expand same class twice in (quick) type hierarchy #1932

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is that (still) needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, because of the (anonymous) subclass of TreeViewer in 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);
};
}

}
Loading