Inspections settings ui: filter actions in toolbar added

This commit is contained in:
Dmitry Batkovich
2014-07-22 14:34:45 +04:00
parent 006705cf3d
commit efe0d5a7b5
3 changed files with 252 additions and 7 deletions
@@ -52,6 +52,8 @@ import com.intellij.profile.codeInspection.InspectionProfileManager;
import com.intellij.profile.codeInspection.InspectionProfileManagerImpl;
import com.intellij.profile.codeInspection.InspectionProjectProfileManager;
import com.intellij.profile.codeInspection.SeverityProvider;
import com.intellij.profile.codeInspection.ui.filter.InspectionFilterAction;
import com.intellij.profile.codeInspection.ui.filter.InspectionsFilter;
import com.intellij.profile.codeInspection.ui.inspectionsTree.InspectionConfigTreeNode;
import com.intellij.profile.codeInspection.ui.inspectionsTree.InspectionsConfigTreeComparator;
import com.intellij.profile.codeInspection.ui.inspectionsTree.InspectionsConfigTreeRenderer;
@@ -105,6 +107,12 @@ public class SingleInspectionProfilePanel extends JPanel {
private JPanel myOptionsPanel;
private JPanel myInspectionProfilePanel = null;
private FilterComponent myProfileFilter;
private final InspectionsFilter myInspectionsFilter = new InspectionsFilter() {
@Override
protected void filterChanged() {
filterTree(myProfileFilter.getFilter());
}
};
private final InspectionConfigTreeNode myRoot =
new InspectionConfigTreeNode(InspectionsBundle.message("inspection.root.node.title"));
private final Alarm myAlarm = new Alarm();
@@ -308,7 +316,7 @@ public class SingleInspectionProfilePanel extends JPanel {
myProfileFilter.setFilter(filter);
}
public void filterTree(String filter) {
private void filterTree(@Nullable String filter) {
if (myTreeTable != null) {
getExpandedNodes(mySelectedProfile).saveVisibleState(myTreeTable.getTree());
fillTreeData(filter, true);
@@ -320,6 +328,10 @@ public class SingleInspectionProfilePanel extends JPanel {
}
}
private void filterTree() {
filterTree(myProfileFilter != null ? myProfileFilter.getFilter() : null);
}
private void reloadModel() {
try {
myIsInRestore = true;
@@ -346,6 +358,10 @@ public class SingleInspectionProfilePanel extends JPanel {
final CommonActionsManager actionManager = CommonActionsManager.getInstance();
DefaultActionGroup actions = new DefaultActionGroup();
actions.add(new InspectionFilterAction(mySelectedProfile, myInspectionsFilter));
actions.addSeparator();
actions.add(actionManager.createExpandAllAction(myTreeExpander, myTreeTable));
actions.add(actionManager.createCollapseAllAction(myTreeExpander, myTreeTable));
@@ -392,8 +408,6 @@ public class SingleInspectionProfilePanel extends JPanel {
}
});
actions.addSeparator();
final ActionToolbar actionToolbar = ActionManager.getInstance().createActionToolbar(ActionPlaces.UNKNOWN, actions, true);
actionToolbar.setTargetComponent(this);
return actionToolbar;
@@ -637,7 +651,7 @@ public class SingleInspectionProfilePanel extends JPanel {
return forceInclude;
}
private void fillTreeData(String filter, boolean forceInclude) {
private void fillTreeData(@Nullable String filter, boolean forceInclude) {
if (mySelectedProfile == null) return;
myRoot.removeAllChildren();
myRoot.dropCache();
@@ -646,11 +660,15 @@ public class SingleInspectionProfilePanel extends JPanel {
if (filter != null && !filter.isEmpty()) {
keySetList.addAll(SearchUtil.findKeys(filter, quoted));
}
Project project = myProjectProfileManager.getProject();
for (ToolDescriptors toolDescriptors : myInitialToolDescriptors) {
final Descriptor descriptor = toolDescriptors.getDefaultDescriptor();
if (filter != null && !filter.isEmpty() && !isDescriptorAccepted(descriptor, filter, forceInclude, keySetList, quoted)) {
continue;
}
if (!myInspectionsFilter.matches(mySelectedProfile.getTools(toolDescriptors.getDefaultDescriptor().getKey().toString(), project))) {
continue;
}
final InspectionConfigTreeNode node = new InspectionConfigTreeNode(toolDescriptors);
getGroupNode(myRoot, toolDescriptors.getDefaultDescriptor().getGroup()).add(node);
myRoot.dropCache();
@@ -908,7 +926,7 @@ public class SingleInspectionProfilePanel extends JPanel {
myInitialProfile = mySelectedProfile.getName();
}
initToolStates();
filterTree(myProfileFilter != null ? myProfileFilter.getFilter() : null);
filterTree();
}
@Override
@@ -962,8 +980,8 @@ public class SingleInspectionProfilePanel extends JPanel {
final JPanel northPanel = new JPanel(new GridBagLayout());
northPanel.setBorder(IdeBorderFactory.createEmptyBorder(2, 0, 2, 0));
northPanel.add(createTreeToolbarPanel().getComponent(), new GridBagConstraints(0, 0, 1, 1, 0.5, 1, GridBagConstraints.BASELINE_LEADING, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
northPanel.add(myProfileFilter, new GridBagConstraints(1, 0, 1, 1, 1, 1, GridBagConstraints.BASELINE_TRAILING, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
northPanel.add(myProfileFilter, new GridBagConstraints(0, 0, 1, 1, 1, 1, GridBagConstraints.BASELINE_TRAILING, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
northPanel.add(createTreeToolbarPanel().getComponent(), new GridBagConstraints(1, 0, 1, 1, 0.5, 1, GridBagConstraints.BASELINE_LEADING, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
treePanel.add(northPanel, BorderLayout.NORTH);
myMainSplitter = new Splitter(false);
@@ -0,0 +1,129 @@
/*
* Copyright 2000-2014 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.profile.codeInspection.ui.filter;
import com.intellij.codeHighlighting.HighlightDisplayLevel;
import com.intellij.codeInsight.daemon.impl.SeverityRegistrar;
import com.intellij.codeInspection.ex.InspectionProfileImpl;
import com.intellij.icons.AllIcons;
import com.intellij.lang.annotation.HighlightSeverity;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.DefaultActionGroup;
import com.intellij.openapi.actionSystem.ex.CheckboxAction;
import com.intellij.profile.codeInspection.SeverityProvider;
import com.intellij.profile.codeInspection.ui.LevelChooserAction;
import com.intellij.profile.codeInspection.ui.SingleInspectionProfilePanel;
import org.jetbrains.annotations.Nullable;
import java.util.SortedSet;
/**
* @author Dmitry Batkovich
*/
public class InspectionFilterAction extends DefaultActionGroup {
private final SeverityRegistrar mySeverityRegistrar;
private final InspectionsFilter myInspectionsFilter;
public InspectionFilterAction(final InspectionProfileImpl profile, final InspectionsFilter inspectionsFilter) {
super("Filter Inspections", true);
myInspectionsFilter = inspectionsFilter;
mySeverityRegistrar = ((SeverityProvider)profile.getProfileManager()).getOwnSeverityRegistrar();
getTemplatePresentation().setIcon(AllIcons.General.Filter);
tune();
}
private void tune() {
addAction(new ShowEnabledOrDisabledInspectionsAction(null));
addAction(new ShowEnabledOrDisabledInspectionsAction(true));
addAction(new ShowEnabledOrDisabledInspectionsAction(false));
addSeparator();
final SortedSet<HighlightSeverity> severities = LevelChooserAction.getSeverities(mySeverityRegistrar);
for (final HighlightSeverity severity : severities) {
add(new ShowWithSpecifiedSeverityInspectionsAction(severity));
}
addSeparator();
add(new ShowAvailableOnlyOnAnalyzeInspectionsAction());
}
private class ShowAvailableOnlyOnAnalyzeInspectionsAction extends CheckboxAction {
public ShowAvailableOnlyOnAnalyzeInspectionsAction() {
super("Show Only \"Available only for Analyze | Inspect Code\"");
}
@Override
public boolean isSelected(final AnActionEvent e) {
return myInspectionsFilter.isAvailableOnlyForAnalyze();
}
@Override
public void setSelected(final AnActionEvent e, final boolean state) {
myInspectionsFilter.setAvailableOnlyForAnalyze(state);
}
}
private class ShowWithSpecifiedSeverityInspectionsAction extends CheckboxAction {
private final HighlightSeverity mySeverity;
private ShowWithSpecifiedSeverityInspectionsAction(final HighlightSeverity severity) {
super(SingleInspectionProfilePanel.renderSeverity(severity),
null,
HighlightDisplayLevel.find(severity).getIcon());
mySeverity = severity;
}
@Override
public boolean isSelected(final AnActionEvent e) {
return myInspectionsFilter.containsSeverity(mySeverity);
}
@Override
public void setSelected(final AnActionEvent e, final boolean state) {
if (state) {
myInspectionsFilter.add(mySeverity);
} else {
myInspectionsFilter.remove(mySeverity);
}
}
}
private class ShowEnabledOrDisabledInspectionsAction extends CheckboxAction {
private final Boolean myShowEnabledActions;
public ShowEnabledOrDisabledInspectionsAction(@Nullable final Boolean showEnabledActions) {
super(showEnabledActions == null ? "All Inspections" : (showEnabledActions ? "Enabled" : "Disabled"));
myShowEnabledActions = showEnabledActions;
}
@Override
public boolean isSelected(final AnActionEvent e) {
return myInspectionsFilter.getSuitableInspectionsStates() == myShowEnabledActions;
}
@Override
public void setSelected(final AnActionEvent e, final boolean state) {
myInspectionsFilter.setSuitableInspectionsStates(myShowEnabledActions);
}
}
}
@@ -0,0 +1,98 @@
/*
* Copyright 2000-2014 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.profile.codeInspection.ui.filter;
import com.intellij.codeInspection.ex.GlobalInspectionToolWrapper;
import com.intellij.codeInspection.ex.InspectionToolWrapper;
import com.intellij.codeInspection.ex.ScopeToolState;
import com.intellij.codeInspection.ex.Tools;
import com.intellij.lang.annotation.HighlightSeverity;
import com.intellij.util.containers.HashSet;
import org.jetbrains.annotations.Nullable;
import java.util.Set;
/**
* @author Dmitry Batkovich
*/
public abstract class InspectionsFilter {
private final Set<HighlightSeverity> mySuitableSeverities = new HashSet<HighlightSeverity>();
private Boolean mySuitableInspectionsStates;
private boolean myAvailableOnlyForAnalyze;
public boolean isAvailableOnlyForAnalyze() {
return myAvailableOnlyForAnalyze;
}
public Boolean getSuitableInspectionsStates() {
return mySuitableInspectionsStates;
}
public boolean containsSeverity(final HighlightSeverity severity) {
return mySuitableSeverities.contains(severity);
}
public void setAvailableOnlyForAnalyze(final boolean availableOnlyForAnalyze) {
myAvailableOnlyForAnalyze = availableOnlyForAnalyze;
filterChanged();
}
public void setSuitableInspectionsStates(@Nullable final Boolean suitableInspectionsStates) {
mySuitableInspectionsStates = suitableInspectionsStates;
filterChanged();
}
public void add(final HighlightSeverity severity) {
mySuitableSeverities.add(severity);
filterChanged();
}
public void remove(final HighlightSeverity severity) {
mySuitableSeverities.remove(severity);
filterChanged();
}
public boolean matches(final Tools tools) {
if (mySuitableInspectionsStates != null && mySuitableInspectionsStates != tools.isEnabled()) {
return false;
}
if (myAvailableOnlyForAnalyze != isAvailableOnlyForAnalyze(tools)) {
return false;
}
if (mySuitableSeverities.isEmpty()) {
return true;
}
for (final ScopeToolState state : tools.getTools()) {
if (mySuitableInspectionsStates != null && mySuitableInspectionsStates != state.isEnabled()) {
continue;
}
if (mySuitableSeverities.contains(tools.getDefaultState().getLevel().getSeverity())) {
return true;
}
}
return false;
}
protected abstract void filterChanged();
private static boolean isAvailableOnlyForAnalyze(final Tools tools) {
final InspectionToolWrapper tool = tools.getTool();
return tool instanceof GlobalInspectionToolWrapper && ((GlobalInspectionToolWrapper)tool).worksInBatchModeOnly();
}
}