mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-10-01 06:51:17 +07:00
inspection tool window: do not show just empty panel when selected entity isn't valid
This commit is contained in:
@@ -59,7 +59,6 @@ import com.intellij.pom.Navigatable;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.util.PsiUtilCore;
|
||||
import com.intellij.ui.*;
|
||||
import com.intellij.ui.components.JBLabel;
|
||||
import com.intellij.util.ConcurrencyUtil;
|
||||
import com.intellij.util.EditSourceOnDoubleClickHandler;
|
||||
import com.intellij.util.OpenSourceUtil;
|
||||
@@ -185,6 +184,7 @@ public class InspectionResultsView extends JPanel implements Disposable, Occuren
|
||||
if (!isExcludeAction || !myGlobalInspectionContext.getUIOptions().FILTER_RESOLVED_ITEMS) {
|
||||
myTree.queueUpdate();
|
||||
}
|
||||
syncRightPanel();
|
||||
}
|
||||
};
|
||||
createActionsToolbar();
|
||||
@@ -330,7 +330,7 @@ public class InspectionResultsView extends JPanel implements Disposable, Occuren
|
||||
|
||||
@Override
|
||||
public void dispose() {
|
||||
releaseEditor(myPreviewEditor);
|
||||
InspectionResultsViewUtil.releaseEditor(myPreviewEditor);
|
||||
mySplitter.dispose();
|
||||
myInspectionProfile = null;
|
||||
myDisposed = true;
|
||||
@@ -389,7 +389,7 @@ public class InspectionResultsView extends JPanel implements Disposable, Occuren
|
||||
}
|
||||
if (myTree.getSelectionModel().getSelectionCount() != 1) {
|
||||
if (myTree.getSelectedToolWrapper() == null) {
|
||||
mySplitter.setSecondComponent(getNothingToShowTextLabel());
|
||||
mySplitter.setSecondComponent(InspectionResultsViewUtil.getNothingToShowTextLabel());
|
||||
}
|
||||
else {
|
||||
showInRightPanel(myTree.getCommonSelectedElement());
|
||||
@@ -410,7 +410,7 @@ public class InspectionResultsView extends JPanel implements Disposable, Occuren
|
||||
}
|
||||
else if (node instanceof InspectionNode) {
|
||||
if (myGlobalInspectionContext.getPresentation(((InspectionNode)node).getToolWrapper()).isDummy()) {
|
||||
mySplitter.setSecondComponent(getNothingToShowTextLabel());
|
||||
mySplitter.setSecondComponent(InspectionResultsViewUtil.getNothingToShowTextLabel());
|
||||
}
|
||||
else {
|
||||
showInRightPanel(null);
|
||||
@@ -431,7 +431,7 @@ public class InspectionResultsView extends JPanel implements Disposable, Occuren
|
||||
oldEditor.putUserData(PREVIEW_EDITOR_IS_REUSED_KEY, null);
|
||||
}
|
||||
else {
|
||||
releaseEditor(oldEditor);
|
||||
InspectionResultsViewUtil.releaseEditor(oldEditor);
|
||||
if (oldEditor == myPreviewEditor) {
|
||||
myPreviewEditor = null;
|
||||
}
|
||||
@@ -439,14 +439,6 @@ public class InspectionResultsView extends JPanel implements Disposable, Occuren
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static JLabel getNothingToShowTextLabel() {
|
||||
final JLabel multipleSelectionLabel = new JBLabel(InspectionViewNavigationPanel.getTitleText(false, false));
|
||||
multipleSelectionLabel.setVerticalAlignment(SwingConstants.TOP);
|
||||
multipleSelectionLabel.setBorder(IdeBorderFactory.createEmptyBorder(16, 12, 0, 0));
|
||||
return multipleSelectionLabel;
|
||||
}
|
||||
|
||||
private void showInRightPanel(@Nullable final RefEntity refEntity) {
|
||||
Cursor currentCursor = getCursor();
|
||||
try {
|
||||
@@ -514,7 +506,7 @@ public class InspectionResultsView extends JPanel implements Disposable, Occuren
|
||||
});
|
||||
}
|
||||
else {
|
||||
myPreviewEditor = (EditorEx)EditorFactory.getInstance().createEditor(document, myProject, file.getVirtualFile(), true);
|
||||
myPreviewEditor = (EditorEx)EditorFactory.getInstance().createEditor( document, myProject, file.getVirtualFile(), true);
|
||||
DiffUtil.setFoldingModelSupport(myPreviewEditor);
|
||||
final EditorSettings settings = myPreviewEditor.getSettings();
|
||||
settings.setLineNumbersShown(false);
|
||||
@@ -542,7 +534,7 @@ public class InspectionResultsView extends JPanel implements Disposable, Occuren
|
||||
else if (selectedEntity == null) {
|
||||
return Pair.create(new InspectionNodeInfo(myTree, myProject), null);
|
||||
}
|
||||
return Pair.create(new JPanel(), null);
|
||||
return Pair.create(InspectionResultsViewUtil.getInvalidEntityLabel(selectedEntity), null);
|
||||
}
|
||||
|
||||
private boolean reuseEditorFor(Document document) {
|
||||
@@ -842,7 +834,7 @@ public class InspectionResultsView extends JPanel implements Disposable, Occuren
|
||||
}
|
||||
else if (selectedNode instanceof ProblemDescriptionNode && CommonDataKeys.NAVIGATABLE.is(dataId)) {
|
||||
Navigatable navigatable = getSelectedNavigatable(((ProblemDescriptionNode)selectedNode).getDescriptor());
|
||||
return navigatable == null ? getNavigatableForInvalidNode((ProblemDescriptionNode)selectedNode) : navigatable;
|
||||
return navigatable == null ? InspectionResultsViewUtil.getNavigatableForInvalidNode((ProblemDescriptionNode)selectedNode) : navigatable;
|
||||
}
|
||||
|
||||
return null;
|
||||
@@ -1013,19 +1005,4 @@ public class InspectionResultsView extends JPanel implements Disposable, Occuren
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void releaseEditor(@Nullable Editor editor) {
|
||||
if (editor != null && !editor.isDisposed()) {
|
||||
EditorFactory.getInstance().releaseEditor(editor);
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static Navigatable getNavigatableForInvalidNode(ProblemDescriptionNode node) {
|
||||
RefEntity element = node.getElement();
|
||||
if (!(element instanceof RefElement)) return null;
|
||||
PsiElement containingElement = ((RefElement)element).getElement();
|
||||
if (!(containingElement instanceof NavigatablePsiElement) || !containingElement.isValid()) return null;
|
||||
return (Navigatable)containingElement;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* Copyright 2000-2016 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.codeInspection.ui;
|
||||
|
||||
import com.intellij.codeInspection.reference.RefElement;
|
||||
import com.intellij.codeInspection.reference.RefEntity;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.editor.EditorFactory;
|
||||
import com.intellij.pom.Navigatable;
|
||||
import com.intellij.psi.NavigatablePsiElement;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.ui.IdeBorderFactory;
|
||||
import com.intellij.ui.components.JBLabel;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
/**
|
||||
* @author Dmitry Batkovich
|
||||
*/
|
||||
public class InspectionResultsViewUtil {
|
||||
static void releaseEditor(@Nullable Editor editor) {
|
||||
if (editor != null && !editor.isDisposed()) {
|
||||
EditorFactory.getInstance().releaseEditor(editor);
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
static Navigatable getNavigatableForInvalidNode(ProblemDescriptionNode node) {
|
||||
RefEntity element = node.getElement();
|
||||
if (!(element instanceof RefElement)) return null;
|
||||
PsiElement containingElement = ((RefElement)element).getElement();
|
||||
if (!(containingElement instanceof NavigatablePsiElement) || !containingElement.isValid()) return null;
|
||||
return (Navigatable)containingElement;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
static JLabel getNothingToShowTextLabel() {
|
||||
return createLabelForText(InspectionViewNavigationPanel.getTitleText(false, false));
|
||||
}
|
||||
|
||||
static JComponent getInvalidEntityLabel(@NotNull RefEntity entity) {
|
||||
final String name = entity.getName();
|
||||
return createLabelForText("\'" + name + "\' is no longer valid.");
|
||||
}
|
||||
|
||||
private static JLabel createLabelForText(String text) {
|
||||
final JLabel multipleSelectionLabel = new JBLabel(text);
|
||||
multipleSelectionLabel.setVerticalAlignment(SwingConstants.TOP);
|
||||
multipleSelectionLabel.setBorder(IdeBorderFactory.createEmptyBorder(16, 12, 0, 0));
|
||||
return multipleSelectionLabel;
|
||||
}
|
||||
}
|
||||
+8
-2
@@ -85,8 +85,14 @@ class InspectionViewPsiTreeChangeAdapter extends PsiTreeChangeAdapter {
|
||||
RefEntity element = ((CachedInspectionTreeNode)node).getElement();
|
||||
if (element instanceof RefElement) {
|
||||
final SmartPsiElementPointer pointer = ((RefElement)element).getPointer();
|
||||
VirtualFile containingFile = pointer.getVirtualFile();
|
||||
if (files.contains(containingFile)) {
|
||||
VirtualFile strictVirtualFile = pointer.getVirtualFile();
|
||||
if (strictVirtualFile == null || !strictVirtualFile.isValid()) {
|
||||
final PsiFile file = pointer.getContainingFile();
|
||||
if (file != null && file.isValid()) {
|
||||
strictVirtualFile = file.getVirtualFile();
|
||||
}
|
||||
}
|
||||
if (strictVirtualFile == null || files.contains(strictVirtualFile)) {
|
||||
((CachedInspectionTreeNode)node).dropCache(project);
|
||||
if (!needUpdateUI[0]) {
|
||||
needUpdateUI[0] = true;
|
||||
|
||||
Reference in New Issue
Block a user