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 #1954

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">
<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,8 @@
package org.eclipse.jdt.internal.ui.typehierarchy;

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

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.KeyAdapter;
Expand All @@ -23,6 +25,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 +133,32 @@ 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) {
private Set<Object> visited;

@Override
protected void inputChanged(Object input, Object oldInput) {
visited= new HashSet<>();
super.inputChanged(input, oldInput);
visited= null;
}

@Override
protected void internalExpandToLevel(Widget node, int level) {
if (!shouldExpand(node))
return;

super.internalExpandToLevel(node, level);
}

private boolean shouldExpand(Widget widget) {
if (widget == null) {
return false;
}
Object data= widget.getData();
return data == null || visited.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 @@ -1212,7 +1212,12 @@ private void updateHierarchyViewer(final boolean doExpand) {
fPagebook.showPage(fNoHierarchyShownLabel);
} else {
if (getCurrentViewer().containsElements() != null) {
Runnable runnable= () -> JavaCore.runReadOnly(() -> getCurrentViewer().updateContent(doExpand));
Runnable runnable= () -> JavaCore.runReadOnly(() -> {
TypeHierarchyViewer viewer= getCurrentViewer();
viewer.preUpdateContent();
Copy link
Contributor

Choose a reason for hiding this comment

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

Its cool that you made it without new API. Wouldn' it be better to overload TypeHierarchyViewer.updateContent() such that you don't need to spread the implementation detail across several files?

viewer.updateContent(doExpand);
viewer.postUpdateContent();
});
BusyIndicator.showWhile(getDisplay(), runnable);
if (!isChildVisible(fViewerbook, getCurrentViewer().getControl())) {
setViewerVisibility(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,14 @@
*******************************************************************************/
package org.eclipse.jdt.internal.ui.typehierarchy;

import java.util.HashSet;
import java.util.Set;

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 All @@ -42,6 +46,8 @@ public abstract class TypeHierarchyViewer extends ProblemTreeViewer {

private HierarchyLabelProvider fLabelProvider;

private Set<Object> visited;


public TypeHierarchyViewer(Composite parent, IContentProvider contentProvider, TypeHierarchyLifeCycle lifeCycle) {
super(new Tree(parent, SWT.SINGLE));
Expand Down Expand Up @@ -182,4 +188,34 @@ protected TypeHierarchyContentProvider getHierarchyContentProvider() {
return (TypeHierarchyContentProvider)getContentProvider();
}

@Override
protected void inputChanged(Object input, Object oldInput) {
preUpdateContent();
super.inputChanged(input, oldInput);
postUpdateContent();
}

@Override
protected void internalExpandToLevel(Widget node, int level) {
if (!shouldExpand(node))
return;

super.internalExpandToLevel(node, level);
}

private boolean shouldExpand(Widget widget) {
if (widget == null) {
return false;
}
Object data= widget.getData();
return data == null || visited.add(data);
}

void preUpdateContent() {
visited= new HashSet<>();
}

void postUpdateContent() {
visited= null;
}
}
Loading