inspection toolwindow: cosmetics from youtrack commentaries

This commit is contained in:
Dmitry Batkovich
2016-03-21 17:52:17 +03:00
parent 3b1c00101e
commit d18ea6bdd7
3 changed files with 26 additions and 62 deletions
@@ -76,8 +76,8 @@ public class InspectionNodeInfo extends JPanel {
JScrollPane pane = ScrollPaneFactory.createScrollPane(description, true);
add(pane,
new GridBagConstraints(0, 1, 1, 1, 1.0, 1.0, GridBagConstraints.NORTHWEST, GridBagConstraints.BOTH,
new JBInsets(0, 10, 0, 0), 0, 0));
new GridBagConstraints(0, 1, 1, 1, 1.0, 1.0, GridBagConstraints.NORTHWEST, GridBagConstraints.VERTICAL,
new JBInsets(0, 10, 0, 0), getFontMetrics(UIUtil.getLabelFont()).charWidth('f') * 110 - pane.getMinimumSize().width, 0));
add(myButton,
new GridBagConstraints(0, 2, 1, 1, 1.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE,
new JBInsets(15, 9, 9, 0), 0, 0));
@@ -40,6 +40,7 @@ import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.application.ModalityState;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.editor.*;
import com.intellij.openapi.editor.colors.EditorColors;
import com.intellij.openapi.editor.ex.EditorEx;
import com.intellij.openapi.fileEditor.OpenFileDescriptor;
import com.intellij.openapi.project.DumbAware;
@@ -397,7 +398,7 @@ public class InspectionResultsView extends JPanel implements Disposable, Occuren
mySplitter.setSecondComponent(getNothingToShowTextLabel());
}
else {
showInRightPanel(myTree.getCommonSelectedElement());
showInRightPanel(myTree.getCommonSelectedElement(), oldEditor == null);
}
}
else {
@@ -406,12 +407,12 @@ public class InspectionResultsView extends JPanel implements Disposable, Occuren
final InspectionTreeNode node = (InspectionTreeNode)pathSelected.getLastPathComponent();
if (node instanceof ProblemDescriptionNode) {
final ProblemDescriptionNode problemNode = (ProblemDescriptionNode)node;
showInRightPanel(problemNode.getElement());
showInRightPanel(problemNode.getElement(), oldEditor == null);
}
else if (node instanceof InspectionPackageNode ||
node instanceof InspectionModuleNode ||
node instanceof RefElementNode) {
showInRightPanel(node.getContainingFileLocalEntity());
showInRightPanel(node.getContainingFileLocalEntity(), oldEditor == null);
}
else if (node instanceof InspectionNode) {
final String shortName = ((InspectionNode)node).getToolWrapper().getShortName();
@@ -419,7 +420,7 @@ public class InspectionResultsView extends JPanel implements Disposable, Occuren
mySplitter.setSecondComponent(getNothingToShowTextLabel());
}
else {
showInRightPanel(null);
showInRightPanel(null, oldEditor == null);
}
}
else if (node instanceof InspectionRootNode || node instanceof InspectionGroupNode || node instanceof InspectionSeverityGroupNode) {
@@ -453,7 +454,7 @@ public class InspectionResultsView extends JPanel implements Disposable, Occuren
return multipleSelectionLabel;
}
private void showInRightPanel(@Nullable final RefEntity refEntity) {
private void showInRightPanel(@Nullable final RefEntity refEntity, boolean hasNoEditorToReuse) {
Cursor currentCursor = getCursor();
try {
setCursor(new Cursor(Cursor.WAIT_CURSOR));
@@ -471,7 +472,7 @@ public class InspectionResultsView extends JPanel implements Disposable, Occuren
}
editorPanel.add(previewPanel, BorderLayout.CENTER);
if (problemCount > 0) {
final QuickFixToolbar fixToolbar = new QuickFixToolbar(myPreviewEditor == null || myPreviewEditor.getUserData(PREVIEW_EDITOR_IS_REUSED_KEY) == null
final QuickFixToolbar fixToolbar = new QuickFixToolbar(myPreviewEditor == null || (!hasNoEditorToReuse && myPreviewEditor.getUserData(PREVIEW_EDITOR_IS_REUSED_KEY) == null)
? null
: myPreviewEditor, this);
myLoadingProgressPreview = fixToolbar;
@@ -522,9 +523,11 @@ public class InspectionResultsView extends JPanel implements Disposable, Occuren
settings.setLeadingWhitespaceShown(true);
settings.setRightMarginShown(true);
settings.setRightMargin(60);
myPreviewEditor.getColorsScheme().setColor(EditorColors.GUTTER_BACKGROUND, myPreviewEditor.getColorsScheme().getDefaultBackground());
myPreviewEditor.getScrollPane().setBorder(IdeBorderFactory.createBorder(SideBorder.TOP));
UsagePreviewPanel.highlight(Collections.emptyList(), myPreviewEditor, myProject);
}
myPreviewEditor.getSettings().setFoldingOutlineShown(problemCount != 1);
if (problemCount == 1) {
final PsiElement finalSelectedElement = selectedElement;
@@ -28,7 +28,6 @@ import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Disposer;
import com.intellij.ui.IdeBorderFactory;
import com.intellij.ui.SimpleColoredComponent;
import com.intellij.util.containers.ContainerUtil;
import com.intellij.util.ui.AsyncProcessIcon;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -36,8 +35,6 @@ import org.jetbrains.annotations.Nullable;
import javax.swing.*;
import javax.swing.tree.TreePath;
import java.awt.*;
import java.util.Collections;
import java.util.List;
/**
* @author Dmitry Batkovich
@@ -45,7 +42,6 @@ import java.util.List;
public class QuickFixToolbar extends JPanel implements InspectionTreeLoadingProgressAware {
private static final Logger LOG = Logger.getInstance(QuickFixToolbar.class);
private static final int MAX_FIX_COUNT = 3;
@Nullable private final String myTargetName;
@NotNull private final InspectionResultsView myView;
private final InspectionToolWrapper myWrapper;
private final ProblemPreviewEditorFoldings myFoldings;
@@ -62,13 +58,12 @@ public class QuickFixToolbar extends JPanel implements InspectionTreeLoadingProg
int problemCount = descriptors.length;
setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0));
myTargetName = getTargetName();
if (view.isUpdating() && !areDescriptorNodesSelected()) {
setBorder(IdeBorderFactory.createEmptyBorder(16, 9, 13, 0));
AsyncProcessIcon waitingIcon = new AsyncProcessIcon("Inspection preview panel updating...");
Disposer.register(this, waitingIcon);
myWaitingLabel = getLabel(null, problemCount);
myWaitingLabel = getLabel(problemCount);
add(myWaitingLabel);
add(waitingIcon);
}
@@ -98,7 +93,7 @@ public class QuickFixToolbar extends JPanel implements InspectionTreeLoadingProg
if (myWaitingLabel != null) {
myWaitingLabel.clear();
final InspectionTree tree = myView.getTree();
appendTextToLabel(myWaitingLabel, tree.getSelectedProblemCount(), null);
appendTextToLabel(myWaitingLabel, tree.getSelectedProblemCount());
}
}
@@ -112,29 +107,20 @@ public class QuickFixToolbar extends JPanel implements InspectionTreeLoadingProg
boolean multipleDescriptors = problemCount > 1;
setLayout(new BoxLayout(this, BoxLayout.LINE_AXIS));
if (multipleDescriptors) {
add(getLabel(fixes, problemCount));
add(getLabel(problemCount));
}
final DefaultActionGroup actions = new DefaultActionGroup();
if (hasFixes) {
actions.addAll(createFixActions(fixes, multipleDescriptors));
}
actions.add(createSuppressionCombo(myWrapper, tree.getSelectionPaths(), project, multipleDescriptors));
actions.add(createSuppressionCombo(myWrapper, tree.getSelectionPaths(), project));
final ActionToolbar toolbar = ActionManager.getInstance().createActionToolbar(ActionPlaces.UNKNOWN, actions, true);
final JComponent component = toolbar.getComponent();
toolbar.setTargetComponent(this);
add(component);
}
@Nullable
private String getTargetName() {
if (myView.getTree().getSelectionCount() == 1) {
final Object node = myView.getTree().getSelectionPath().getLastPathComponent();
return node instanceof RefElementNode ? ((RefElementNode)node).getElement().getName() : null;
}
return null;
}
private boolean areDescriptorNodesSelected() {
final TreePath[] paths = myView.getTree().getSelectionPaths();
for (TreePath path : paths) {
@@ -146,34 +132,25 @@ public class QuickFixToolbar extends JPanel implements InspectionTreeLoadingProg
}
@NotNull
private SimpleColoredComponent getLabel(QuickFixAction[] fixes, int problemsCount) {
private static SimpleColoredComponent getLabel(int problemsCount) {
SimpleColoredComponent label = new SimpleColoredComponent();
appendTextToLabel(label, problemsCount, fixes);
appendTextToLabel(label, problemsCount);
label.setBorder(IdeBorderFactory.createEmptyBorder(0, 0, 0, 2));
return label;
}
private void appendTextToLabel(SimpleColoredComponent label,
int problemsCount,
QuickFixAction[] fixes) {
boolean hasFixesNonIntersectedFixes = fixes != null && fixes.length == 0;
label.append(problemsCount + " problems" +
(myTargetName == null ? "" : (" in " + myTargetName)) +
(problemsCount > 1 && (fixes != null && fixes.length >= MAX_FIX_COUNT) ? " Fix all:" : "") +
(!hasFixesNonIntersectedFixes ? ":" : ""));
if (hasFixesNonIntersectedFixes) {
label.append(" select a single problem to see its quick fixes");
}
private static void appendTextToLabel(SimpleColoredComponent label,
int problemsCount) {
label.append(problemsCount + " problems:");
}
private static AnAction createSuppressionCombo(@NotNull final InspectionToolWrapper toolWrapper,
@NotNull final TreePath[] paths,
@NotNull final Project project,
boolean multipleDescriptors) {
@NotNull final TreePath[] paths,
@NotNull final Project project) {
final AnAction[] suppressors = new SuppressActionWrapper(project, toolWrapper, paths).getChildren(null);
final ComboBoxAction action = new ComboBoxAction() {
{
getTemplatePresentation().setText(multipleDescriptors ? "Suppress All" : "Suppress");
getTemplatePresentation().setText("Suppress");
getTemplatePresentation().setEnabledAndVisible(suppressors.length != 0);
}
@@ -190,7 +167,7 @@ public class QuickFixToolbar extends JPanel implements InspectionTreeLoadingProg
}
@NotNull
private static List<AnAction> createFixActions(QuickFixAction[] fixes, boolean multipleDescriptors) {
private static AnAction[] createFixActions(QuickFixAction[] fixes, boolean multipleDescriptors) {
if (fixes.length > MAX_FIX_COUNT) {
final ComboBoxAction fixComboBox = new ComboBoxAction() {
{
@@ -209,24 +186,8 @@ public class QuickFixToolbar extends JPanel implements InspectionTreeLoadingProg
return actionGroup;
}
};
return Collections.singletonList(fixComboBox);
return new AnAction[] {fixComboBox};
}
else {
final DefaultActionGroup group = new DefaultActionGroup();
final boolean multipleFixes = fixes.length > 1;
for (QuickFixAction fix : fixes) {
final AnAction quickFixButtonCustonPresentation = createQuickFixButton(fix, multipleDescriptors && !multipleFixes);
//group.addAll(fixes);
group.add(quickFixButtonCustonPresentation);
}
return ContainerUtil.list(fixes);
}
}
private static AnAction createQuickFixButton(@NotNull QuickFixAction fix, boolean multipleFixes) {
if (multipleFixes) {
fix.getTemplatePresentation().setText("Fix all '" + fix.getText() + "'");
}
return fix;
return fixes;
}
}