inspection settings simplification

This commit is contained in:
Dmitry Batkovich
2017-11-17 15:28:39 +03:00
parent a4d49c0b0e
commit 7fefe6ea04
3 changed files with 37 additions and 39 deletions
@@ -44,7 +44,6 @@ import com.intellij.ui.components.JBLabel;
import com.intellij.util.Alarm;
import com.intellij.util.SmartList;
import com.intellij.util.containers.ContainerUtil;
import com.intellij.util.containers.Queue;
import com.intellij.util.ui.JBInsets;
import com.intellij.util.ui.JBUI;
import com.intellij.util.ui.UIUtil;
@@ -69,6 +68,7 @@ import java.io.StringReader;
import java.util.*;
import java.util.List;
import static com.intellij.profile.codeInspection.ui.inspectionsTree.InspectionConfigTreeNode.updateUpHierarchy;
import static com.intellij.util.containers.ContainerUtil.exists;
public class SingleInspectionProfilePanel extends JPanel {
@@ -91,7 +91,7 @@ public class SingleInspectionProfilePanel extends JPanel {
private final InspectionsFilter myInspectionsFilter = new InspectionsFilter() {
@Override
protected void filterChanged() {
filterTree(myProfileFilter.getFilter());
filterTree();
}
};
private boolean myModified;
@@ -179,13 +179,6 @@ public class SingleInspectionProfilePanel extends JPanel {
return StringUtil.capitalizeWords(severity.getName().toLowerCase(Locale.US), true);
}
private static void updateUpHierarchy(final InspectionConfigTreeNode parent) {
if (parent != null) {
parent.dropCache();
updateUpHierarchy((InspectionConfigTreeNode)parent.getParent());
}
}
private static boolean isDescriptorAccepted(Descriptor descriptor,
@NonNls String filter,
final boolean forceInclude,
@@ -360,8 +353,7 @@ public class SingleInspectionProfilePanel extends JPanel {
if (node.isProperSetting() != properSetting) {
myAlarm.cancelAllRequests();
myAlarm.addRequest(() -> myTreeTable.repaint(), 300);
node.dropCache();
updateUpHierarchy((InspectionConfigTreeNode)node.getParent());
updateUpHierarchy(node);
}
}
}
@@ -404,7 +396,8 @@ public class SingleInspectionProfilePanel extends JPanel {
myProfileFilter.setFilter(filter);
}
private void filterTree(@Nullable String filter) {
private void filterTree() {
String filter = myProfileFilter != null ? myProfileFilter.getFilter() : null;
if (myTreeTable != null) {
getExpandedNodes(myProfile).saveVisibleState(myTreeTable.getTree());
fillTreeData(filter, true);
@@ -416,10 +409,6 @@ public class SingleInspectionProfilePanel extends JPanel {
}
}
private void filterTree() {
filterTree(myProfileFilter != null ? myProfileFilter.getFilter() : null);
}
private void reloadModel() {
try {
myIsInRestore = true;
@@ -524,7 +513,7 @@ public class SingleInspectionProfilePanel extends JPanel {
myTreeTable = InspectionsConfigTreeTable.create(new InspectionsConfigTreeTable.InspectionsConfigTreeTableSettings(myRoot, myProjectProfileManager.getProject()) {
@Override
protected void onChanged(final InspectionConfigTreeNode node) {
updateUpHierarchy((InspectionConfigTreeNode)node.getParent());
updateUpHierarchy(node);
}
@Override
@@ -687,7 +676,6 @@ public class SingleInspectionProfilePanel extends JPanel {
continue;
}
getGroupNode(myRoot, toolDescriptors.getDefaultDescriptor().getGroup()).add(node);
myRoot.dropCache();
}
if (filter != null && forceInclude && myRoot.getChildCount() == 0) {
final Set<String> filters = SearchableOptionsRegistrar.getInstance().getProcessedWords(filter);
@@ -856,8 +844,6 @@ public class SingleInspectionProfilePanel extends JPanel {
protected void onScopeRemoved(final int scopesCount) {
updateRecursively(nodes, scopesCount == 1);
}
});
final ToolbarDecorator wrappedTable = ToolbarDecorator.createDecorator(scopesAndScopesAndSeveritiesTable).disableUpDownActions().setRemoveActionUpdater(
@@ -896,22 +882,8 @@ public class SingleInspectionProfilePanel extends JPanel {
myOptionsPanel.repaint();
}
private void updateRecursively(List<InspectionConfigTreeNode.Tool> nodes, boolean updateOptionsAndDescriptionPanel) {
Queue<InspectionConfigTreeNode> q = new Queue<>(nodes.size());
Set<InspectionConfigTreeNode> alreadyUpdated = new THashSet<>();
for (InspectionConfigTreeNode node : nodes) {
q.addLast(node);
}
while (!q.isEmpty()) {
final InspectionConfigTreeNode inspectionConfigTreeNode = q.pullFirst();
if (!alreadyUpdated.add(inspectionConfigTreeNode)) continue;
inspectionConfigTreeNode.dropCache();
final TreeNode parent = inspectionConfigTreeNode.getParent();
if (parent != null && parent.getParent() != null) {
q.addLast((InspectionConfigTreeNode)parent);
}
}
private void updateRecursively(List<? extends InspectionConfigTreeNode> nodes, boolean updateOptionsAndDescriptionPanel) {
updateUpHierarchy(nodes);
myTreeTable.repaint();
if (updateOptionsAndDescriptionPanel) {
updateOptionsAndDescriptionPanel();
@@ -1214,7 +1186,7 @@ public class SingleInspectionProfilePanel extends JPanel {
@Override
public void filter() {
filterTree(getFilter());
filterTree();
}
@Override
@@ -6,10 +6,16 @@ import com.intellij.codeInspection.ex.Descriptor;
import com.intellij.openapi.util.ClearableLazyValue;
import com.intellij.openapi.util.Getter;
import com.intellij.profile.codeInspection.ui.ToolDescriptors;
import com.intellij.util.containers.Queue;
import gnu.trove.THashSet;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.TreeNode;
import java.util.Collections;
import java.util.List;
import java.util.Set;
import java.util.stream.IntStream;
public abstract class InspectionConfigTreeNode extends DefaultMutableTreeNode {
@@ -107,4 +113,26 @@ public abstract class InspectionConfigTreeNode extends DefaultMutableTreeNode {
}
return super.toString();
}
public static void updateUpHierarchy(@NotNull InspectionConfigTreeNode node) {
updateUpHierarchy(Collections.singletonList(node));
}
public static void updateUpHierarchy(List<? extends InspectionConfigTreeNode> nodes) {
Queue<InspectionConfigTreeNode> q = new Queue<>(nodes.size());
Set<InspectionConfigTreeNode> alreadyUpdated = new THashSet<>();
for (InspectionConfigTreeNode node : nodes) {
q.addLast(node);
}
while (!q.isEmpty()) {
final InspectionConfigTreeNode inspectionConfigTreeNode = q.pullFirst();
if (!alreadyUpdated.add(inspectionConfigTreeNode)) continue;
inspectionConfigTreeNode.dropCache();
final TreeNode parent = inspectionConfigTreeNode.getParent();
if (parent != null && parent.getParent() != null) {
q.addLast((InspectionConfigTreeNode)parent);
}
}
}
}
@@ -304,7 +304,6 @@ public class InspectionsConfigTreeTable extends TreeTable {
if (profile == null) return;
for (final InspectionConfigTreeNode.Tool aNode : InspectionsAggregationUtil.getInspectionsNodes((InspectionConfigTreeNode)node)) {
setToolEnabled(doEnable, profile, aNode.getKey().toString(), mySettings.getProject());
aNode.dropCache();
mySettings.onChanged(aNode);
}
updateRightPanel();
@@ -342,7 +341,6 @@ public class InspectionsConfigTreeTable extends TreeTable {
}
for (InspectionConfigTreeNode node : nodes) {
node.dropCache();
mySettings.onChanged(node);
}