update definitions/documentations view in show usages (IDEA-58145 )

This commit is contained in:
anna
2011-08-25 19:26:00 +02:00
parent 145306318c
commit 6d3d2709d3
3 changed files with 108 additions and 13 deletions
@@ -50,6 +50,7 @@ import com.intellij.psi.search.ProjectScope;
import com.intellij.psi.search.PsiElementProcessor;
import com.intellij.psi.search.SearchScope;
import com.intellij.ui.InplaceButton;
import com.intellij.ui.JBTableWithHintProvider;
import com.intellij.ui.SpeedSearchBase;
import com.intellij.ui.TableScrollingUtil;
import com.intellij.ui.awt.RelativePoint;
@@ -681,7 +682,7 @@ public class ShowUsagesAction extends AnAction implements PopupAction {
return newFileEditor instanceof TextEditor ? ((TextEditor)newFileEditor).getEditor() : null;
}
private static class MyTable extends Table implements DataProvider {
private static class MyTable extends JBTableWithHintProvider implements DataProvider {
@Override
public boolean getScrollableTracksViewportWidth() {
return true;
@@ -691,16 +692,21 @@ public class ShowUsagesAction extends AnAction implements PopupAction {
if (LangDataKeys.PSI_ELEMENT.is(dataId)) {
final int[] selected = getSelectedRows();
if (selected.length == 1) {
final Object at = getValueAt(selected[0], 0);
if (at instanceof UsageNode) {
final Usage usage = ((UsageNode)at).getUsage();
if (usage instanceof UsageInfo2UsageAdapter) {
final PsiElement element = ((UsageInfo2UsageAdapter)usage).getElement();
if (element != null) {
final PsiElement view = UsageToPsiElementProvider.findAppropriateParentFrom(element);
return view == null ? element : view;
}
}
return getPsiElementForHint(getValueAt(selected[0], 0));
}
}
return null;
}
@Override
protected PsiElement getPsiElementForHint(Object selectedValue) {
if (selectedValue instanceof UsageNode) {
final Usage usage = ((UsageNode)selectedValue).getUsage();
if (usage instanceof UsageInfo2UsageAdapter) {
final PsiElement element = ((UsageInfo2UsageAdapter)usage).getElement();
if (element != null) {
final PsiElement view = UsageToPsiElementProvider.findAppropriateParentFrom(element);
return view == null ? element : view;
}
}
}
@@ -0,0 +1,84 @@
/*
* Copyright 2000-2011 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.ui;
import com.intellij.openapi.ui.popup.JBPopup;
import com.intellij.openapi.ui.popup.PopupChooserBuilder;
import com.intellij.psi.PsiElement;
import com.intellij.ui.components.JBList;
import com.intellij.ui.popup.PopupUpdateProcessor;
import com.intellij.ui.table.JBTable;
import javax.swing.*;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.table.TableModel;
import java.util.Collection;
public abstract class JBTableWithHintProvider extends JBTable {
private JBPopup myHint;
public JBTableWithHintProvider() {
addSelectionListener();
}
protected JBTableWithHintProvider(TableModel model) {
super(model);
}
private void addSelectionListener() {
getSelectionModel().addListSelectionListener(new ListSelectionListener() {
@Override
public void valueChanged(final ListSelectionEvent e) {
if (getClientProperty(PopupChooserBuilder.SELECTED_BY_MOUSE_EVENT) != Boolean.TRUE) {
final int selected = ((ListSelectionModel)e.getSource()).getLeadSelectionIndex();
if (selected == -1) return;
final PsiElement element = getPsiElementForHint(getValueAt(selected, 0));
if (element != null && element.isValid()) {
updateHint(element);
}
}
}
});
}
protected abstract PsiElement getPsiElementForHint(final Object selectedValue);
public void registerHint(final JBPopup hint) {
hideHint();
myHint = hint;
}
public void hideHint() {
if (myHint != null && myHint.isVisible()) {
myHint.cancel();
}
myHint = null;
}
public void updateHint(PsiElement element) {
if (myHint == null || !myHint.isVisible()) return;
final PopupUpdateProcessor updateProcessor = myHint.getUserData(PopupUpdateProcessor.class);
if (updateProcessor != null) {
updateProcessor.updatePopup(element);
}
}
}
@@ -26,6 +26,7 @@ import com.intellij.openapi.ui.popup.LightweightWindowEvent;
import com.intellij.openapi.wm.ex.WindowManagerEx;
import com.intellij.psi.PsiElement;
import com.intellij.ui.JBListWithHintProvider;
import com.intellij.ui.JBTableWithHintProvider;
import java.awt.*;
@@ -70,8 +71,12 @@ public abstract class PopupUpdateProcessor extends JBPopupAdapter {
if (fromQuickSearch) {
ChooseByNameBase.JPanelProvider panelProvider = (ChooseByNameBase.JPanelProvider)focusedComponent.getParent();
panelProvider.registerHint(windowEvent.asPopup());
} else if (focusedComponent != null && focusedComponent instanceof JBListWithHintProvider) {
((JBListWithHintProvider)focusedComponent).registerHint(windowEvent.asPopup());
} else if (focusedComponent != null) {
if (focusedComponent instanceof JBListWithHintProvider) {
((JBListWithHintProvider)focusedComponent).registerHint(windowEvent.asPopup());
} else if (focusedComponent instanceof JBTableWithHintProvider) {
((JBTableWithHintProvider)focusedComponent).registerHint(windowEvent.asPopup());
}
}
}
}