inspection tool window: disable/enable button apply changes for all of scopes + ...
authorDmitry Batkovich <dmitry.batkovich@jetbrains.com>
Wed, 14 Sep 2016 12:25:45 +0000 (15:25 +0300)
committerDmitry Batkovich <dmitry.batkovich@jetbrains.com>
Wed, 14 Sep 2016 12:26:26 +0000 (15:26 +0300)
java/java-impl/src/com/intellij/codeInspection/ui/EntryPointsNode.java
platform/lang-impl/src/com/intellij/codeInspection/ui/InspectionNode.java
platform/lang-impl/src/com/intellij/codeInspection/ui/InspectionNodeInfo.java
platform/lang-impl/src/com/intellij/codeInspection/ui/InspectionResultsView.java
platform/lang-impl/src/com/intellij/profile/codeInspection/ui/inspectionsTree/InspectionsConfigTreeTable.java

index cefbbc77a9b346a7012f7015c28c2a6e760526b7..7558f4f96808cf2a7be46c3040a68a735131cd1d 100644 (file)
@@ -56,4 +56,9 @@ public class EntryPointsNode extends InspectionNode {
   public void visitProblemSeverities(FactoryMap<HighlightDisplayLevel, Integer> counter) {
     //do nothing here
   }
+
+  @Override
+  public int getProblemCount(boolean allowSuppressed) {
+    return 0;
+  }
 }
index 4ee35da099b36f2ad3b96ffc1a12d5c9c9a5a265..f09a2b6a88fd19c44588b05ffe00f545a67a2973 100644 (file)
 
 package com.intellij.codeInspection.ui;
 
-import com.intellij.codeInsight.daemon.HighlightDisplayKey;
 import com.intellij.codeInspection.InspectionProfile;
+import com.intellij.codeInspection.ex.InspectionProfileImpl;
 import com.intellij.codeInspection.ex.InspectionToolWrapper;
+import com.intellij.codeInspection.ex.ToolsImpl;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
 
@@ -26,13 +27,11 @@ import org.jetbrains.annotations.Nullable;
  * @author max
  */
 public class InspectionNode extends InspectionTreeNode {
-  private final HighlightDisplayKey myKey;
-  @NotNull private final InspectionProfile myProfile;
+  @NotNull private final InspectionProfileImpl myProfile;
 
   public InspectionNode(@NotNull InspectionToolWrapper toolWrapper, @NotNull InspectionProfile profile) {
     super(toolWrapper);
-    myKey = HighlightDisplayKey.find(toolWrapper.getShortName());
-    myProfile = profile;
+    myProfile = (InspectionProfileImpl)profile;
   }
 
   public String toString() {
@@ -47,11 +46,7 @@ public class InspectionNode extends InspectionTreeNode {
   @Nullable
   @Override
   public String getCustomizedTailText() {
-    return myProfile.isToolEnabled(myKey) ? null : "Disabled";
-  }
-
-  @Override
-  public int getProblemCount(boolean allowSuppressed) {
-    return myKey == null ? 0 : super.getProblemCount(allowSuppressed);
+    final ToolsImpl tools = myProfile.getTools(getToolWrapper().getShortName(), null);
+    return tools.isEnabled() ? null : "Disabled";
   }
 }
index f5242b0e01439049147ca19bce6d0f7576ff3365..95a45dcf046af68a2240603ecf1f6aafcdb4bffc 100644 (file)
  */
 package com.intellij.codeInspection.ui;
 
-import com.intellij.codeInsight.daemon.HighlightDisplayKey;
 import com.intellij.codeInspection.InspectionsBundle;
 import com.intellij.codeInspection.actions.RunInspectionAction;
-import com.intellij.codeInspection.ex.DisableInspectionToolAction;
 import com.intellij.codeInspection.ex.InspectionProfileImpl;
 import com.intellij.codeInspection.ex.InspectionToolWrapper;
+import com.intellij.codeInspection.ex.ToolsImpl;
 import com.intellij.openapi.diagnostic.Logger;
 import com.intellij.openapi.project.Project;
 import com.intellij.profile.codeInspection.InspectionProjectProfileManager;
 import com.intellij.profile.codeInspection.ui.SingleInspectionProfilePanel;
+import com.intellij.profile.codeInspection.ui.inspectionsTree.InspectionsConfigTreeTable;
 import com.intellij.ui.*;
 import com.intellij.ui.components.JBLabel;
 import com.intellij.ui.components.JBLabelDecorator;
@@ -52,8 +52,8 @@ public class InspectionNodeInfo extends JPanel {
     LOG.assertTrue(toolWrapper != null);
     InspectionProfileImpl currentProfile =
       (InspectionProfileImpl)InspectionProjectProfileManager.getInstance(project).getCurrentProfile();
-    HighlightDisplayKey key = HighlightDisplayKey.find(toolWrapper.getShortName());
-    boolean enabled = currentProfile.isToolEnabled(key);
+    final ToolsImpl tools = currentProfile.getTools(toolWrapper.getShortName(), project);
+    boolean enabled = tools.isEnabled();
 
     JPanel titlePanel = new JPanel();
     titlePanel.setLayout(new BoxLayout(titlePanel, BoxLayout.LINE_AXIS));
@@ -92,15 +92,8 @@ public class InspectionNodeInfo extends JPanel {
     new ClickListener() {
       @Override
       public boolean onClick(@NotNull MouseEvent event, int clickCount) {
-        DisableInspectionToolAction.modifyAndCommitProjectProfile(model -> {
-          final String toolId = key.toString();
-          if (enabled) {
-            model.disableTool(toolId, project);
-          }
-          else {
-            ((InspectionProfileImpl)model).enableTool(toolId, project);
-          }
-        }, project);
+        InspectionsConfigTreeTable.setToolEnabled(!enabled, currentProfile, toolWrapper.getShortName(), project);
+        tree.getContext().getView().profileChanged();
         return true;
       }
     }.installOn(enableButton);
index 5afbe839f96ce86497f8611b9b0650a96b245bc9..5135de979590fa4978e43e7bb9c10179c27594e2 100644 (file)
@@ -254,14 +254,18 @@ public class InspectionResultsView extends JPanel implements Disposable, Occuren
       @Override
       public void profileChanged(Profile profile) {
         if (profile == profileManager.getCurrentProfile()) {
-          myTree.revalidate();
-          myTree.repaint();
-          syncRightPanel();
+          InspectionResultsView.this.profileChanged();
         }
       }
     }, this);
   }
 
+  public void profileChanged() {
+    myTree.revalidate();
+    myTree.repaint();
+    syncRightPanel();
+  }
+
   private void initTreeListeners() {
     myTree.getSelectionModel().addTreeSelectionListener(new TreeSelectionListener() {
       @Override
index 9237fcbbb2de040079c868fe7b3081525bef3d49..15a6d7009a9aca4d54f110a0e6d089400b697d56 100644 (file)
@@ -205,6 +205,21 @@ public class InspectionsConfigTreeTable extends TreeTable {
     public abstract void updateRightPanel();
   }
 
+  public static void setToolEnabled(boolean newState,
+                                    @NotNull InspectionProfileImpl profile,
+                                    @NotNull String toolId,
+                                    @NotNull Project project) {
+    if (newState) {
+      profile.enableTool(toolId, project);
+    }
+    else {
+      profile.disableTool(toolId, project);
+    }
+    for (ScopeToolState scopeToolState : profile.getTools(toolId, project).getTools()) {
+      scopeToolState.setEnabled(newState);
+    }
+  }
+
   private static class InspectionsConfigTreeTableModel extends DefaultTreeModel implements TreeTableModel {
 
     private final InspectionsConfigTreeTableSettings mySettings;
@@ -303,7 +318,7 @@ public class InspectionsConfigTreeTable extends TreeTable {
       final boolean doEnable = (Boolean) aValue;
       final InspectionProfileImpl profile = mySettings.getInspectionProfile();
       for (final InspectionConfigTreeNode aNode : InspectionsAggregationUtil.getInspectionsNodes((InspectionConfigTreeNode)node)) {
-        setToolEnabled(doEnable, profile, aNode.getKey());
+        setToolEnabled(doEnable, profile, aNode.getKey().toString(), mySettings.getProject());
         aNode.dropCache();
         mySettings.onChanged(aNode);
       }
@@ -337,7 +352,7 @@ public class InspectionsConfigTreeTable extends TreeTable {
 
       final InspectionProfileImpl profile = mySettings.getInspectionProfile();
       for (HighlightDisplayKey tool : tools) {
-        setToolEnabled(newState, profile, tool);
+        setToolEnabled(newState, profile, tool.toString(), mySettings.getProject());
       }
 
       for (InspectionConfigTreeNode node : nodes) {
@@ -357,19 +372,6 @@ public class InspectionsConfigTreeTable extends TreeTable {
       }
     }
 
-    private void setToolEnabled(boolean newState, InspectionProfileImpl profile, HighlightDisplayKey tool) {
-      final String toolId = tool.toString();
-      if (newState) {
-        profile.enableTool(toolId, mySettings.getProject());
-      }
-      else {
-        profile.disableTool(toolId, mySettings.getProject());
-      }
-      for (ScopeToolState scopeToolState : profile.getTools(toolId, mySettings.getProject()).getTools()) {
-        scopeToolState.setEnabled(newState);
-      }
-    }
-
     private static void collectInspectionFromNodes(final InspectionConfigTreeNode node,
                                                    final Set<HighlightDisplayKey> tools,
                                                    final List<InspectionConfigTreeNode> nodes) {