summaryrefslogtreecommitdiff
path: root/platform/lang-impl/src/com/intellij/profile
diff options
context:
space:
mode:
Diffstat (limited to 'platform/lang-impl/src/com/intellij/profile')
-rw-r--r--platform/lang-impl/src/com/intellij/profile/codeInspection/ui/AddScopeUtil.java117
-rw-r--r--platform/lang-impl/src/com/intellij/profile/codeInspection/ui/AdvancedSettingsAction.java209
-rw-r--r--platform/lang-impl/src/com/intellij/profile/codeInspection/ui/InspectionToolsConfigurable.java4
-rw-r--r--platform/lang-impl/src/com/intellij/profile/codeInspection/ui/LevelChooserAction.java6
-rw-r--r--platform/lang-impl/src/com/intellij/profile/codeInspection/ui/MultiScopeSeverityIcon.java58
-rw-r--r--platform/lang-impl/src/com/intellij/profile/codeInspection/ui/ScopeOrderComparator.java62
-rw-r--r--platform/lang-impl/src/com/intellij/profile/codeInspection/ui/ScopesChooser.java60
-rw-r--r--platform/lang-impl/src/com/intellij/profile/codeInspection/ui/ScopesOrderDialog.java121
-rw-r--r--platform/lang-impl/src/com/intellij/profile/codeInspection/ui/SingleInspectionProfilePanel.java109
-rw-r--r--platform/lang-impl/src/com/intellij/profile/codeInspection/ui/filter/InspectionFilterAction.java18
-rw-r--r--platform/lang-impl/src/com/intellij/profile/codeInspection/ui/filter/InspectionsFilter.java19
-rw-r--r--platform/lang-impl/src/com/intellij/profile/codeInspection/ui/inspectionsTree/InspectionsConfigTreeTable.java70
-rw-r--r--platform/lang-impl/src/com/intellij/profile/codeInspection/ui/inspectionsTree/MultiScopeSeverityIcon.java19
-rw-r--r--platform/lang-impl/src/com/intellij/profile/codeInspection/ui/inspectionsTree/ScopesAndSeveritiesHintTable.java32
-rw-r--r--platform/lang-impl/src/com/intellij/profile/codeInspection/ui/table/ScopesAndSeveritiesTable.java94
-rw-r--r--platform/lang-impl/src/com/intellij/profile/codeInspection/ui/table/SeverityRenderer.java31
-rw-r--r--platform/lang-impl/src/com/intellij/profile/codeInspection/ui/table/SeverityState.java40
-rw-r--r--platform/lang-impl/src/com/intellij/profile/codeInspection/ui/table/ThreeStateCheckBoxRenderer.java22
18 files changed, 785 insertions, 306 deletions
diff --git a/platform/lang-impl/src/com/intellij/profile/codeInspection/ui/AddScopeUtil.java b/platform/lang-impl/src/com/intellij/profile/codeInspection/ui/AddScopeUtil.java
deleted file mode 100644
index d92445254f28..000000000000
--- a/platform/lang-impl/src/com/intellij/profile/codeInspection/ui/AddScopeUtil.java
+++ /dev/null
@@ -1,117 +0,0 @@
-/*
- * Copyright 2000-2012 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.
- */
-
-/*
- * User: anna
- * Date: 14-May-2009
- */
-package com.intellij.profile.codeInspection.ui;
-
-import com.intellij.codeHighlighting.HighlightDisplayLevel;
-import com.intellij.codeInspection.ex.Descriptor;
-import com.intellij.codeInspection.ex.InspectionProfileImpl;
-import com.intellij.codeInspection.ex.InspectionToolWrapper;
-import com.intellij.codeInspection.ex.ScopeToolState;
-import com.intellij.openapi.project.Project;
-import com.intellij.openapi.ui.Messages;
-import com.intellij.profile.codeInspection.ui.inspectionsTree.InspectionConfigTreeNode;
-import com.intellij.psi.search.scope.packageSet.CustomScopesProviderEx;
-import com.intellij.psi.search.scope.packageSet.NamedScope;
-import com.intellij.psi.search.scope.packageSet.NamedScopesHolder;
-import com.intellij.ui.treeStructure.Tree;
-import com.intellij.ui.treeStructure.treetable.TreeTable;
-import com.intellij.util.ArrayUtil;
-
-import javax.swing.tree.DefaultTreeModel;
-import javax.swing.tree.TreePath;
-import java.util.*;
-
-public class AddScopeUtil {
- public static ScopeToolState performAddScope(final TreeTable treeTable,
- final Project project,
- final InspectionProfileImpl inspectionProfile,
- final Collection<InspectionConfigTreeNode> selectedNodes) {
- final List<InspectionConfigTreeNode> nodes = new ArrayList<InspectionConfigTreeNode>();
- final List<Descriptor> descriptors = new ArrayList<Descriptor>();
- for (final InspectionConfigTreeNode node : selectedNodes) {
- collect(descriptors, nodes, node);
- }
-
- final List<String> availableScopes = getAvailableScopes(descriptors, project, inspectionProfile);
- final int idx = Messages.showChooseDialog(treeTable, "Scope:", "Choose Scope", ArrayUtil.toStringArray(availableScopes), availableScopes.get(0), Messages.getQuestionIcon());
- if (idx == -1) return null;
- final NamedScope chosenScope = NamedScopesHolder.getScope(project, availableScopes.get(idx));
-
- ScopeToolState scopeToolState = null;
- final Tree tree = treeTable.getTree();
-
- for (final InspectionConfigTreeNode node : nodes) {
- final Descriptor descriptor = node.getDefaultDescriptor();
- final InspectionToolWrapper toolWrapper = descriptor.getToolWrapper().createCopy(); //copy
- final HighlightDisplayLevel level = inspectionProfile.getErrorLevel(descriptor.getKey(), chosenScope, project);
- final boolean enabled = inspectionProfile.isToolEnabled(descriptor.getKey());
- scopeToolState = inspectionProfile.addScope(toolWrapper, chosenScope, level, enabled, project);
- node.dropCache();
- ((DefaultTreeModel)tree.getModel()).reload(node);
- tree.expandPath(new TreePath(node.getPath()));
- }
- tree.revalidate();
- return scopeToolState;
- }
-
- private static void collect(final List<Descriptor> descriptors,
- final List<InspectionConfigTreeNode> nodes,
- final InspectionConfigTreeNode node) {
- final ToolDescriptors currentDescriptors = node.getDescriptors();
- if (currentDescriptors != null) {
- nodes.add(node);
- descriptors.add(currentDescriptors.getDefaultDescriptor());
- descriptors.addAll(currentDescriptors.getNonDefaultDescriptors());
- } else if (node.getUserObject() instanceof String) {
- for(int i = 0; i < node.getChildCount(); i++) {
- final InspectionConfigTreeNode childNode = (InspectionConfigTreeNode)node.getChildAt(i);
- collect(descriptors, nodes, childNode);
- }
- }
- }
-
- private static List<String> getAvailableScopes(final List<Descriptor> descriptors, final Project project, final InspectionProfileImpl inspectionProfile) {
- final ArrayList<NamedScope> scopes = new ArrayList<NamedScope>();
- for (final NamedScopesHolder holder : NamedScopesHolder.getAllNamedScopeHolders(project)) {
- Collections.addAll(scopes, holder.getScopes());
- }
- scopes.remove(CustomScopesProviderEx.getAllScope());
-
- CustomScopesProviderEx.filterNoSettingsScopes(project, scopes);
-
- final Set<NamedScope> used = new HashSet<NamedScope>();
- for (final Descriptor descriptor : descriptors) {
- final List<ScopeToolState> nonDefaultTools = inspectionProfile.getNonDefaultTools(descriptor.getKey().toString(), project);
- if (nonDefaultTools != null) {
- for (final ScopeToolState state : nonDefaultTools) {
- used.add(state.getScope(project));
- }
- }
- }
- scopes.removeAll(used);
-
- final List<String> availableScopes = new ArrayList<String>();
- for (final NamedScope scope : scopes) {
- availableScopes.add(scope.getName());
- }
- return availableScopes;
- }
-} \ No newline at end of file
diff --git a/platform/lang-impl/src/com/intellij/profile/codeInspection/ui/AdvancedSettingsAction.java b/platform/lang-impl/src/com/intellij/profile/codeInspection/ui/AdvancedSettingsAction.java
new file mode 100644
index 000000000000..b0746769d83c
--- /dev/null
+++ b/platform/lang-impl/src/com/intellij/profile/codeInspection/ui/AdvancedSettingsAction.java
@@ -0,0 +1,209 @@
+/*
+ * 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;
+
+import com.intellij.codeInspection.ex.InspectionProfileImpl;
+import com.intellij.icons.AllIcons;
+import com.intellij.openapi.actionSystem.*;
+import com.intellij.openapi.application.ApplicationNamesInfo;
+import com.intellij.openapi.project.Project;
+import com.intellij.openapi.ui.popup.JBPopupFactory;
+import com.intellij.openapi.ui.popup.PopupStep;
+import com.intellij.openapi.ui.popup.util.BaseListPopupStep;
+import com.intellij.profile.codeInspection.ui.inspectionsTree.InspectionConfigTreeNode;
+import com.intellij.ui.LayeredIcon;
+import com.intellij.ui.awt.RelativePoint;
+import com.intellij.ui.components.JBLabel;
+import com.intellij.ui.popup.list.ListPopupImpl;
+import com.intellij.util.Consumer;
+import com.intellij.util.PlatformIcons;
+import com.intellij.util.containers.ContainerUtil;
+import com.intellij.util.ui.EmptyIcon;
+import com.intellij.util.ui.UIUtil;
+
+import javax.swing.*;
+import java.awt.*;
+
+/**
+ * @author Dmitry Batkovich
+ */
+public abstract class AdvancedSettingsAction extends AnAction {
+ private final int myCheckBoxIndent;
+ private Project myProject;
+ private InspectionConfigTreeNode myRoot;
+
+ public AdvancedSettingsAction(final Project project, InspectionConfigTreeNode root) {
+ super("Advanced Settings");
+ getTemplatePresentation().setIcon(AllIcons.General.Gear);
+ myProject = project;
+ myRoot = root;
+ myCheckBoxIndent = calculateCheckBoxIndent();
+ }
+
+ @Override
+ public void update(AnActionEvent e) {
+ super.update(e);
+ final InspectionProfileImpl inspectionProfile = getInspectionProfile();
+ final Icon icon = AllIcons.General.Gear;
+ e.getPresentation().setIcon(
+ (inspectionProfile != null && inspectionProfile.isProfileLocked()) ? LayeredIcon.create(icon, PlatformIcons.LOCKED_ICON) : icon);
+ }
+
+ @Override
+ public void actionPerformed(AnActionEvent e) {
+ final ListPopupImpl actionGroupPopup = (ListPopupImpl)JBPopupFactory.getInstance().createListPopup(
+ new BaseListPopupStep<MyAction>(null, ContainerUtil.list(new MyDisableNewInspectionsAction(), new MyResetAction())) {
+ @Override
+ public PopupStep onChosen(MyAction selectedValue, boolean finalChoice) {
+ if (selectedValue.enabled()) {
+ selectedValue.actionPerformed();
+ }
+ return FINAL_CHOICE;
+ }
+ });
+ actionGroupPopup.getList().setCellRenderer(new ListCellRenderer() {
+ @Override
+ public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
+ return ((MyAction)value).createCustomComponent(isSelected);
+ }
+ });
+ final Component component = e.getInputEvent().getComponent();
+ actionGroupPopup.show(new RelativePoint(component, new Point(component.getWidth() - 1, 0)));
+ }
+
+ private JLabel installLeftIndentToLabel(final JLabel label) {
+ label.setBorder(BorderFactory.createEmptyBorder(0, myCheckBoxIndent, 0, 0));
+ return label;
+ }
+
+ private class MyResetAction extends MyAction {
+
+ protected MyResetAction() {
+ super("All your changes will be lost");
+ }
+
+ @Override
+ protected JComponent createBaseComponent() {
+ return installLeftIndentToLabel(new JLabel("Reset to Defaults Settings"));
+ }
+
+ @Override
+ public void actionPerformed() {
+ final InspectionProfileImpl inspectionProfile = getInspectionProfile();
+ if (inspectionProfile == null) {
+ return;
+ }
+ inspectionProfile.resetToBase(myProject);
+ postProcessModification();
+ }
+
+ @Override
+ protected boolean enabled() {
+ return myRoot.isProperSetting();
+ }
+ }
+
+ private class MyDisableNewInspectionsAction extends MyAction {
+ public MyDisableNewInspectionsAction() {
+ super("New inspections may appear when " + ApplicationNamesInfo.getInstance().getFullProductName() + " is updated");
+ }
+
+ @Override
+ protected JComponent createBaseComponent() {
+ final JCheckBox checkBox = new JCheckBox("Disable new inspections by default");
+ final InspectionProfileImpl profile = getInspectionProfile();
+ checkBox.setEnabled(profile != null);
+ if (profile != null) {
+ checkBox.setSelected(profile.isProfileLocked());
+ }
+ checkBox.setOpaque(false);
+ return checkBox;
+ }
+
+ @Override
+ public void actionPerformed() {
+ final InspectionProfileImpl profile = getInspectionProfile();
+ if (profile != null) {
+ profile.lockProfile(!profile.isProfileLocked());
+ }
+ }
+
+
+ @Override
+ protected boolean enabled() {
+ return true;
+ }
+ }
+
+ private abstract class MyAction {
+ private final String myDescription;
+
+ protected MyAction(String description) {
+ myDescription = description;
+ }
+
+ protected abstract JComponent createBaseComponent();
+
+ protected abstract void actionPerformed();
+
+ protected abstract boolean enabled();
+
+ public JComponent createCustomComponent(final boolean selected) {
+ JPanel panel = new JPanel();
+ panel.setLayout(new BoxLayout(panel, BoxLayout.PAGE_AXIS));
+ panel.add(createBaseComponent());
+ panel.add(installLeftIndentToLabel(new JBLabel(myDescription, UIUtil.ComponentStyle.MINI)));
+ panel.setBackground(selected ? UIUtil.getListSelectionBackground() : UIUtil.getListBackground());
+ panel.setForeground(selected ? UIUtil.getListSelectionForeground() : UIUtil.getListForeground());
+ UIUtil.setEnabled(panel, enabled(), true);
+ return panel;
+ }
+ }
+
+ protected abstract InspectionProfileImpl getInspectionProfile();
+
+ protected abstract void postProcessModification();
+
+ private static int calculateCheckBoxIndent() {
+ JCheckBox checkBox = new JCheckBox();
+ Icon icon = checkBox.getIcon();
+ int indent = 0;
+ if (icon == null) {
+ icon = UIManager.getIcon("CheckBox.icon");
+ }
+ if (UIUtil.isUnderDarcula() || UIUtil.isUnderIntelliJLaF()) {
+ icon = EmptyIcon.create(20, 18);
+ }
+ if (icon != null) {
+ final Insets i = checkBox.getInsets();
+ final Rectangle r = checkBox.getBounds();
+ final Rectangle r1 = new Rectangle();
+ r1.x = i.left;
+ r1.y = i.top;
+ r1.width = r.width - (i.right + r1.x);
+ r1.height = r.height - (i.bottom + r1.y);
+ final Rectangle iconRect = new Rectangle();
+ SwingUtilities.layoutCompoundLabel(
+ checkBox, checkBox.getFontMetrics(checkBox.getFont()), checkBox.getText(), icon,
+ checkBox.getVerticalAlignment(), checkBox.getHorizontalAlignment(),
+ checkBox.getVerticalTextPosition(), checkBox.getHorizontalTextPosition(),
+ r1, new Rectangle(), iconRect,
+ checkBox.getText() == null ? 0 : checkBox.getIconTextGap());
+ indent = iconRect.x;
+ }
+ return indent + checkBox.getIconTextGap();
+ }
+}
diff --git a/platform/lang-impl/src/com/intellij/profile/codeInspection/ui/InspectionToolsConfigurable.java b/platform/lang-impl/src/com/intellij/profile/codeInspection/ui/InspectionToolsConfigurable.java
index 794945268d19..efc60c63f89d 100644
--- a/platform/lang-impl/src/com/intellij/profile/codeInspection/ui/InspectionToolsConfigurable.java
+++ b/platform/lang-impl/src/com/intellij/profile/codeInspection/ui/InspectionToolsConfigurable.java
@@ -151,7 +151,7 @@ public abstract class InspectionToolsConfigurable extends BaseConfigurable imple
final Set<String> levels = new HashSet<String>();
for (Object o : rootElement.getChildren("inspection_tool")) {
final Element inspectElement = (Element)o;
- levels.add(inspectElement.getAttributeValue("l"));
+ levels.add(inspectElement.getAttributeValue("level"));
for (Object s : inspectElement.getChildren("scope")) {
levels.add(((Element)s).getAttributeValue("level"));
}
@@ -532,6 +532,6 @@ public abstract class InspectionToolsConfigurable extends BaseConfigurable imple
public JComponent getPreferredFocusedComponent() {
final InspectionProfileImpl inspectionProfile = getSelectedObject();
assert inspectionProfile != null : configuredProfiles();
- return getProfilePanel(inspectionProfile).getTree();
+ return getProfilePanel(inspectionProfile).getPreferredFocusedComponent();
}
}
diff --git a/platform/lang-impl/src/com/intellij/profile/codeInspection/ui/LevelChooserAction.java b/platform/lang-impl/src/com/intellij/profile/codeInspection/ui/LevelChooserAction.java
index 1067a60ed358..df3b8bda3f3b 100644
--- a/platform/lang-impl/src/com/intellij/profile/codeInspection/ui/LevelChooserAction.java
+++ b/platform/lang-impl/src/com/intellij/profile/codeInspection/ui/LevelChooserAction.java
@@ -43,7 +43,11 @@ public abstract class LevelChooserAction extends ComboBoxAction {
private HighlightSeverity myChosen = null;
public LevelChooserAction(final InspectionProfileImpl profile) {
- mySeverityRegistrar = ((SeverityProvider)profile.getProfileManager()).getOwnSeverityRegistrar();
+ this(((SeverityProvider)profile.getProfileManager()).getOwnSeverityRegistrar());
+ }
+
+ public LevelChooserAction(final SeverityRegistrar severityRegistrar) {
+ mySeverityRegistrar = severityRegistrar;
}
@NotNull
diff --git a/platform/lang-impl/src/com/intellij/profile/codeInspection/ui/MultiScopeSeverityIcon.java b/platform/lang-impl/src/com/intellij/profile/codeInspection/ui/MultiScopeSeverityIcon.java
deleted file mode 100644
index 2bf909666f82..000000000000
--- a/platform/lang-impl/src/com/intellij/profile/codeInspection/ui/MultiScopeSeverityIcon.java
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * 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;
-
-import javax.swing.*;
-import java.awt.*;
-import java.util.List;
-
-/**
- * @author Dmitry Batkovich
- */
-public class MultiScopeSeverityIcon implements Icon {
- private final int mySize;
- private final List<Color> myColors;
-
- public MultiScopeSeverityIcon(final int size, final List<Color> colors) {
- mySize = size;
- myColors = colors;
- }
-
- @Override
- public void paintIcon(final Component c, final Graphics g, final int i, final int j) {
- final int iconWidth = getIconWidth();
- final int iconHeightCoordinate = j + getIconHeight();
-
- final int partWidth = iconWidth / myColors.size();
-
- for (int idx = 0; idx < myColors.size(); idx++) {
- final Color color = myColors.get(idx);
- g.setColor(color);
- final int x = i + partWidth * idx;
- g.fillRect(x, j, x + partWidth, iconHeightCoordinate);
- }
- }
-
- @Override
- public int getIconWidth() {
- return mySize;
- }
-
- @Override
- public int getIconHeight() {
- return mySize;
- }
-}
diff --git a/platform/lang-impl/src/com/intellij/profile/codeInspection/ui/ScopeOrderComparator.java b/platform/lang-impl/src/com/intellij/profile/codeInspection/ui/ScopeOrderComparator.java
new file mode 100644
index 000000000000..f2d8c5e1fd82
--- /dev/null
+++ b/platform/lang-impl/src/com/intellij/profile/codeInspection/ui/ScopeOrderComparator.java
@@ -0,0 +1,62 @@
+/*
+ * 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;
+
+import com.intellij.codeInspection.ex.InspectionProfileImpl;
+import com.intellij.util.ArrayUtil;
+
+import java.util.Comparator;
+
+/**
+ * @author Dmitry Batkovich
+ */
+public class ScopeOrderComparator implements Comparator<String> {
+ private final String[] myScopesOrder;
+
+ public ScopeOrderComparator(final InspectionProfileImpl inspectionProfile) {
+ this(inspectionProfile.getScopesOrder());
+ }
+
+ public ScopeOrderComparator(String[] scopesOrder) {
+ myScopesOrder = scopesOrder;
+ }
+
+ private int getKey(String scope) {
+ return myScopesOrder == null ? -1 : ArrayUtil.indexOf(myScopesOrder, scope);
+ }
+
+ @Override
+ public int compare(String scope1, String scope2) {
+ final int key = getKey(scope1);
+ final int key1 = getKey(scope2);
+ if (key >= 0) {
+ if (key1 >= 0) {
+ return key - key1;
+ }
+ else {
+ return -1;
+ }
+ }
+ else {
+ if (key1 >= 0) {
+ return 1;
+ }
+ else {
+ return scope1.compareTo(scope2);
+ }
+ }
+ }
+} \ No newline at end of file
diff --git a/platform/lang-impl/src/com/intellij/profile/codeInspection/ui/ScopesChooser.java b/platform/lang-impl/src/com/intellij/profile/codeInspection/ui/ScopesChooser.java
index 4932e7ff5ca9..fde3b141084d 100644
--- a/platform/lang-impl/src/com/intellij/profile/codeInspection/ui/ScopesChooser.java
+++ b/platform/lang-impl/src/com/intellij/profile/codeInspection/ui/ScopesChooser.java
@@ -22,13 +22,16 @@ import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.DefaultActionGroup;
import com.intellij.openapi.actionSystem.ex.ComboBoxAction;
import com.intellij.openapi.project.Project;
+import com.intellij.psi.search.scope.NonProjectFilesScope;
import com.intellij.psi.search.scope.packageSet.CustomScopesProviderEx;
import com.intellij.psi.search.scope.packageSet.NamedScope;
import com.intellij.psi.search.scope.packageSet.NamedScopesHolder;
+import com.intellij.util.containers.ContainerUtil;
import org.jetbrains.annotations.NotNull;
import javax.swing.*;
import java.util.ArrayList;
+import java.util.Set;
import java.util.List;
import java.util.Collections;
@@ -36,22 +39,28 @@ import java.util.Collections;
* @author Dmitry Batkovich
*/
public abstract class ScopesChooser extends ComboBoxAction {
+ public static final String TITLE = "Select a scope to change its settings";
private final List<Descriptor> myDefaultDescriptors;
private final InspectionProfileImpl myInspectionProfile;
private final Project myProject;
+ private final Set<String> myExcludedScopeNames;
- public ScopesChooser(final List<Descriptor> defaultDescriptors, final InspectionProfileImpl inspectionProfile, final Project project) {
+ public ScopesChooser(final List<Descriptor> defaultDescriptors,
+ final InspectionProfileImpl inspectionProfile,
+ final Project project,
+ final String[] excludedScopeNames) {
myDefaultDescriptors = defaultDescriptors;
myInspectionProfile = inspectionProfile;
myProject = project;
- setPopupTitle("Select a scope to change its settings");
+ myExcludedScopeNames = excludedScopeNames == null ? Collections.<String>emptySet() : ContainerUtil.newHashSet(excludedScopeNames);
+ setPopupTitle(TITLE);
getTemplatePresentation().setText("In All Scopes");
}
@NotNull
@Override
- protected DefaultActionGroup createPopupActionGroup(final JComponent button) {
+ public DefaultActionGroup createPopupActionGroup(final JComponent component) {
final DefaultActionGroup group = new DefaultActionGroup();
final List<NamedScope> predefinedScopes = new ArrayList<NamedScope>();
@@ -61,30 +70,47 @@ public abstract class ScopesChooser extends ComboBoxAction {
predefinedScopes.addAll(holder.getPredefinedScopes());
}
predefinedScopes.remove(CustomScopesProviderEx.getAllScope());
- fillActionGroup(group, predefinedScopes, myDefaultDescriptors, myInspectionProfile);
+ for (NamedScope predefinedScope : predefinedScopes) {
+ if (predefinedScope instanceof NonProjectFilesScope) {
+ predefinedScopes.remove(predefinedScope);
+ break;
+ }
+ }
+
+ fillActionGroup(group, predefinedScopes, myDefaultDescriptors, myInspectionProfile, myExcludedScopeNames);
group.addSeparator();
- fillActionGroup(group, customScopes, myDefaultDescriptors, myInspectionProfile);
+ fillActionGroup(group, customScopes, myDefaultDescriptors, myInspectionProfile, myExcludedScopeNames);
- //TODO edit scopes order
- //group.addSeparator();
- //group.add(new AnAction("Edit Scopes Order...") {
- // @Override
- // public void actionPerformed(final AnActionEvent e) {
- //
- // }
- //});
+ group.addSeparator();
+ group.add(new AnAction("Edit Scopes Order...") {
+ @Override
+ public void actionPerformed(final AnActionEvent e) {
+ final ScopesOrderDialog dlg = new ScopesOrderDialog(component, myInspectionProfile, myProject);
+ dlg.show();
+ if (dlg.isOK()) {
+ onScopesOrderChanged();
+ }
+ }
+ });
return group;
}
+ protected abstract void onScopesOrderChanged();
+
protected abstract void onScopeAdded();
private void fillActionGroup(final DefaultActionGroup group,
- final List<NamedScope> scopes,
- final List<Descriptor> defaultDescriptors,
- final InspectionProfileImpl inspectionProfile) {
+ final List<NamedScope> scopes,
+ final List<Descriptor> defaultDescriptors,
+ final InspectionProfileImpl inspectionProfile,
+ final Set<String> excludedScopeNames) {
for (final NamedScope scope : scopes) {
- group.add(new AnAction(scope.getName()) {
+ final String scopeName = scope.getName();
+ if (excludedScopeNames.contains(scopeName)) {
+ continue;
+ }
+ group.add(new AnAction(scopeName) {
@Override
public void actionPerformed(final AnActionEvent e) {
for (final Descriptor defaultDescriptor : defaultDescriptors) {
diff --git a/platform/lang-impl/src/com/intellij/profile/codeInspection/ui/ScopesOrderDialog.java b/platform/lang-impl/src/com/intellij/profile/codeInspection/ui/ScopesOrderDialog.java
new file mode 100644
index 000000000000..c69a3e5566a2
--- /dev/null
+++ b/platform/lang-impl/src/com/intellij/profile/codeInspection/ui/ScopesOrderDialog.java
@@ -0,0 +1,121 @@
+/*
+ * 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;
+
+import com.intellij.codeInspection.ex.InspectionProfileImpl;
+import com.intellij.openapi.project.Project;
+import com.intellij.openapi.ui.DialogWrapper;
+import com.intellij.psi.search.scope.NonProjectFilesScope;
+import com.intellij.psi.search.scope.packageSet.CustomScopesProviderEx;
+import com.intellij.psi.search.scope.packageSet.NamedScope;
+import com.intellij.psi.search.scope.packageSet.NamedScopesHolder;
+import com.intellij.ui.*;
+import com.intellij.ui.components.JBList;
+import com.intellij.util.ui.UIUtil;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+import javax.swing.*;
+import java.awt.*;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
+/**
+ * @author Dmitry Batkovich
+ */
+public class ScopesOrderDialog extends DialogWrapper {
+
+ private final JList myOptionsList = new JBList();
+
+ private final InspectionProfileImpl myInspectionProfile;
+ private final Project myProject;
+ private final JPanel myPanel;
+
+ public ScopesOrderDialog(final @NotNull Component parent,
+ final InspectionProfileImpl inspectionProfile,
+ final Project project) {
+ super(parent, true);
+ myInspectionProfile = inspectionProfile;
+ myProject = project;
+
+ final JPanel listPanel = ToolbarDecorator.createDecorator(myOptionsList).setMoveDownAction(new AnActionButtonRunnable() {
+ @Override
+ public void run(AnActionButton anActionButton) {
+ ListUtil.moveSelectedItemsDown(myOptionsList);
+ }
+ }).setMoveUpAction(new AnActionButtonRunnable() {
+ @Override
+ public void run(AnActionButton anActionButton) {
+ ListUtil.moveSelectedItemsUp(myOptionsList);
+ }
+ }).disableRemoveAction().disableAddAction().createPanel();
+ final JLabel descr = new JLabel("<html><p>If file appears in two or more scopes, it will be" +
+ "inspected with settings of the topmost scope in list above.</p><p/>" +
+ "<p>Scope order is set globally for all inspections in the profile.</p></html>");
+ descr.setPreferredSize(new Dimension(300, 100));
+ UIUtil.applyStyle(UIUtil.ComponentStyle.SMALL, descr);
+ myPanel = new JPanel();
+ myPanel.setLayout(new BorderLayout());
+ myPanel.add(listPanel, BorderLayout.CENTER);
+ myPanel.add(descr, BorderLayout.SOUTH);
+ fillList();
+ init();
+ setTitle("Scopes Order");
+ }
+
+ private void fillList() {
+ DefaultListModel model = new DefaultListModel();
+ model.removeAllElements();
+
+ final List<String> scopes = new ArrayList<String>();
+ for (final NamedScopesHolder holder : NamedScopesHolder.getAllNamedScopeHolders(myProject)) {
+ for (final NamedScope scope : holder.getScopes()) {
+ if (!(scope instanceof NonProjectFilesScope)) {
+ scopes.add(scope.getName());
+ }
+ }
+ }
+ scopes.remove(CustomScopesProviderEx.getAllScope().getName());
+ Collections.sort(scopes, new ScopeOrderComparator(myInspectionProfile));
+ for (String scopeName : scopes) {
+ model.addElement(scopeName);
+ }
+ myOptionsList.setModel(model);
+ myOptionsList.setSelectedIndex(0);
+ }
+
+ @Nullable
+ @Override
+ protected JComponent createCenterPanel() {
+ return myPanel;
+ }
+
+ @Override
+ protected void doOKAction() {
+ final int size = myOptionsList.getModel().getSize();
+ final String[] newScopeOrder = new String[size];
+ for (int i = 0; i < size; i++) {
+ final String scopeName = (String) myOptionsList.getModel().getElementAt(i);
+ newScopeOrder[i] = scopeName;
+ }
+ if (!Arrays.equals(newScopeOrder, myInspectionProfile.getScopesOrder())) {
+ myInspectionProfile.setScopesOrder(newScopeOrder);
+ }
+ super.doOKAction();
+ }
+}
diff --git a/platform/lang-impl/src/com/intellij/profile/codeInspection/ui/SingleInspectionProfilePanel.java b/platform/lang-impl/src/com/intellij/profile/codeInspection/ui/SingleInspectionProfilePanel.java
index ce5f308c1305..2da5c80a758b 100644
--- a/platform/lang-impl/src/com/intellij/profile/codeInspection/ui/SingleInspectionProfilePanel.java
+++ b/platform/lang-impl/src/com/intellij/profile/codeInspection/ui/SingleInspectionProfilePanel.java
@@ -132,6 +132,8 @@ public class SingleInspectionProfilePanel extends JPanel {
private Splitter myRightSplitter;
private Splitter myMainSplitter;
+ private String[] myInitialScopesOrder;
+
public SingleInspectionProfilePanel(@NotNull InspectionProjectProfileManager projectProfileManager,
@NotNull String inspectionProfileName,
@NotNull ModifiableModel profile) {
@@ -186,8 +188,10 @@ public class SingleInspectionProfilePanel extends JPanel {
if (myTreeTable != null) {
final TreePath selectionPath = myTreeTable.getTree().getSelectionPath();
if (selectionPath != null) {
- TreeUtil.selectNode(myTreeTable.getTree(), (TreeNode)selectionPath.getLastPathComponent());
- TreeUtil.showRowCentered(myTreeTable.getTree(), myTreeTable.getTree().getRowForPath(selectionPath), false);
+ TreeUtil.selectNode(myTreeTable.getTree(), (TreeNode) selectionPath.getLastPathComponent());
+ final int rowForPath = myTreeTable.getTree().getRowForPath(selectionPath);
+ TableUtil.selectRows(myTreeTable, new int[]{rowForPath});
+ scrollToCenter();
}
}
}
@@ -258,6 +262,7 @@ public class SingleInspectionProfilePanel extends JPanel {
if (!accept(state.getTool())) continue;
myInitialToolDescriptors.add(ToolDescriptors.fromScopeToolState(state, profile, project));
}
+ myInitialScopesOrder = mySelectedProfile.getScopesOrder();
}
protected boolean accept(InspectionToolWrapper entry) {
@@ -364,24 +369,6 @@ public class SingleInspectionProfilePanel extends JPanel {
actions.add(actionManager.createExpandAllAction(myTreeExpander, myTreeTable));
actions.add(actionManager.createCollapseAllAction(myTreeExpander, myTreeTable));
-
- actions.add(new AnAction(CommonBundle.message("button.reset.to.default"), CommonBundle.message("button.reset.to.default"),
- AllIcons.General.Reset) {
- {
- registerCustomShortcutSet(new CustomShortcutSet(KeyStroke.getKeyStroke(KeyEvent.VK_R, InputEvent.CTRL_MASK)), myTreeTable);
- }
- @Override
- public void update(AnActionEvent e) {
- e.getPresentation().setEnabled(myRoot.isProperSetting());
- }
-
- @Override
- public void actionPerformed(AnActionEvent e) {
- mySelectedProfile.resetToBase(myProjectProfileManager.getProject());
- postProcessModification();
- }
- });
-
actions.add(new AnAction("Reset to Empty", "Reset to empty", AllIcons.Actions.Reset_to_empty){
@Override
@@ -396,18 +383,19 @@ public class SingleInspectionProfilePanel extends JPanel {
}
});
- actions.add(new ToggleAction("Lock Profile", "Lock profile", AllIcons.Nodes.Padlock) {
+ actions.add(new AdvancedSettingsAction(myProjectProfileManager.getProject(), myRoot) {
@Override
- public boolean isSelected(AnActionEvent e) {
- return mySelectedProfile != null && mySelectedProfile.isProfileLocked();
+ protected InspectionProfileImpl getInspectionProfile() {
+ return mySelectedProfile;
}
@Override
- public void setSelected(AnActionEvent e, boolean state) {
- mySelectedProfile.lockProfile(state);
+ protected void postProcessModification() {
+ SingleInspectionProfilePanel.this.postProcessModification();
}
});
+
final ActionToolbar actionToolbar = ActionManager.getInstance().createActionToolbar(ActionPlaces.UNKNOWN, actions, true);
actionToolbar.setTargetComponent(this);
return actionToolbar;
@@ -424,11 +412,24 @@ public class SingleInspectionProfilePanel extends JPanel {
public void selectInspectionTool(String name) {
final InspectionConfigTreeNode node = findNodeByKey(name, myRoot);
if (node != null) {
- TreeUtil.showRowCentered(myTreeTable.getTree(), myTreeTable.getTree().getRowForPath(new TreePath(node.getPath())) - 1, true);//myTree.isRootVisible ? 0 : 1;
TreeUtil.selectNode(myTreeTable.getTree(), node);
+ final int rowForPath = myTreeTable.getTree().getRowForPath(new TreePath(node.getPath()));
+ TableUtil.selectRows(myTreeTable, new int[]{rowForPath});
+ scrollToCenter();
}
}
+ private void scrollToCenter() {
+ ListSelectionModel selectionModel = myTreeTable.getSelectionModel();
+ int maxSelectionIndex = selectionModel.getMaxSelectionIndex();
+ final int maxColumnSelectionIndex = Math.max(0, myTreeTable.getColumnModel().getSelectionModel().getMinSelectionIndex());
+ Rectangle maxCellRect = myTreeTable.getCellRect(maxSelectionIndex, maxColumnSelectionIndex, false);
+
+ final Point selectPoint = maxCellRect.getLocation();
+ final int allHeight = myTreeTable.getVisibleRect().height;
+ myTreeTable.scrollRectToVisible(new Rectangle(new Point(0, Math.max(0, selectPoint.y - allHeight / 2)), new Dimension(0, allHeight)));
+ }
+
@Nullable
private static InspectionConfigTreeNode findNodeByKey(String name, InspectionConfigTreeNode root) {
for (int i = 0; i < root.getChildCount(); i++) {
@@ -524,6 +525,7 @@ public class SingleInspectionProfilePanel extends JPanel {
final JScrollPane scrollPane = ScrollPaneFactory.createScrollPane(myTreeTable);
+ myTreeTable.getTree().setShowsRootHandles(true);
scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
TreeUtil.collapseAll(myTreeTable.getTree(), 1);
@@ -684,14 +686,15 @@ public class SingleInspectionProfilePanel extends JPanel {
}
private void updateOptionsAndDescriptionPanel(final TreePath... paths) {
- if (paths == null || paths.length == 0) {
+ if (mySelectedProfile == null || paths == null || paths.length == 0) {
return;
}
final TreePath path = paths[0];
if (path == null) return;
final List<InspectionConfigTreeNode> nodes = InspectionsAggregationUtil.getInspectionsNodes(paths);
if (!nodes.isEmpty()) {
- final InspectionConfigTreeNode singleNode = nodes.size() == 1 ? ContainerUtil.getFirstItem(nodes) : null;
+ final InspectionConfigTreeNode singleNode = paths.length == 1 && ((InspectionConfigTreeNode)paths[0].getLastPathComponent()).getDefaultDescriptor() != null
+ ? ContainerUtil.getFirstItem(nodes) : null;
if (singleNode != null && singleNode.getDefaultDescriptor().loadDescription() != null) {
// need this in order to correctly load plugin-supplied descriptions
final Descriptor defaultDescriptor = singleNode.getDefaultDescriptor();
@@ -721,7 +724,7 @@ public class SingleInspectionProfilePanel extends JPanel {
}
else {
try {
- myBrowser.read(new StringReader(EMPTY_HTML), null);
+ myBrowser.read(new StringReader("<html><body>Multiple inspections are selected. You can edit them as a single inspection.</body></html>"), null);
}
catch (IOException e1) {
//Can't be
@@ -733,7 +736,6 @@ public class SingleInspectionProfilePanel extends JPanel {
final JPanel severityPanel = new JPanel(new GridBagLayout());
final double severityPanelWeightY;
final JPanel configPanelAnchor = new JPanel(new GridLayout());
- configPanelAnchor.setBorder(IdeBorderFactory.createTitledBorder("Options", false, new Insets(0, 0, 0, 0)));
final Set<String> scopesNames = new THashSet<String>();
for (final InspectionConfigTreeNode node : nodes) {
@@ -754,7 +756,7 @@ public class SingleInspectionProfilePanel extends JPanel {
final HighlightDisplayKey key = node.getDefaultDescriptor().getKey();
final NamedScope scope = node.getDefaultDescriptor().getScope();
final boolean toUpdate = mySelectedProfile.getErrorLevel(key, scope, project) != level;
- mySelectedProfile.setErrorLevel(key, level, -1, project);
+ mySelectedProfile.setErrorLevel(key, level, null, project);
if (toUpdate) node.dropCache();
}
@@ -774,7 +776,13 @@ public class SingleInspectionProfilePanel extends JPanel {
public Descriptor fun(final InspectionConfigTreeNode node) {
return node.getDefaultDescriptor();
}
- }), mySelectedProfile, project) {
+ }), mySelectedProfile, project, null) {
+ @Override
+ protected void onScopesOrderChanged() {
+ myTreeTable.getTree().updateUI();
+ updateOptionsAndDescriptionPanel();
+ }
+
@Override
protected void onScopeAdded() {
updateOptionsAndDescriptionPanel();
@@ -812,12 +820,19 @@ public class SingleInspectionProfilePanel extends JPanel {
}
@Override
- protected void onChange() {
+ protected void onSettingsChanged() {
myTreeTable.getTree().updateUI();
}
@Override
protected void onScopeAdded() {
+ updateOptionsAndDescriptionPanel();
+ }
+
+ @Override
+ protected void onScopesOrderChanged() {
+ myTreeTable.getTree().updateUI();
+ updateOptionsAndDescriptionPanel();
}
@Override
@@ -829,8 +844,9 @@ public class SingleInspectionProfilePanel extends JPanel {
});
- final ToolbarDecorator wrappedTable = ToolbarDecorator.createDecorator(scopesAndScopesAndSeveritiesTable);
+ final ToolbarDecorator wrappedTable = ToolbarDecorator.createDecorator(scopesAndScopesAndSeveritiesTable).disableUpDownActions();
final JPanel panel = wrappedTable.createPanel();
+ panel.setMinimumSize(new Dimension(getMinimumSize().width, 3 * scopesAndScopesAndSeveritiesTable.getRowHeight()));
severityPanel.add(new JBLabel("Scopes & Severities"),
new GridBagConstraints(0, 0, 1, 1, 0, 0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE,
new Insets(5, 0, 2, 10), 0, 0));
@@ -842,8 +858,13 @@ public class SingleInspectionProfilePanel extends JPanel {
severityPanelWeightY = 0.3;
}
myOptionsPanel.add(severityPanel, new GridBagConstraints(0, 0, 1, 1, 1.0, severityPanelWeightY, GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
- myOptionsPanel.add(configPanelAnchor, new GridBagConstraints(0, 1, 1, 1, 1.0, 1.0, GridBagConstraints.WEST, GridBagConstraints.BOTH,
- new Insets(0, 0, 0, 0), 0, 0));
+ if (configPanelAnchor.getComponentCount() != 0) {
+ configPanelAnchor.setBorder(IdeBorderFactory.createTitledBorder("Options", false, new Insets(0, 0, 0, 0)));
+ }
+ if (configPanelAnchor.getComponentCount() != 0 || scopesNames.isEmpty()) {
+ myOptionsPanel.add(configPanelAnchor, new GridBagConstraints(0, 1, 1, 1, 1.0, 1.0, GridBagConstraints.WEST, GridBagConstraints.BOTH,
+ new Insets(0, 0, 0, 0), 0, 0));
+ }
myOptionsPanel.revalidate();
GuiUtils.enableChildren(myOptionsPanel, isThoughOneNodeEnabled(nodes));
}
@@ -887,7 +908,10 @@ public class SingleInspectionProfilePanel extends JPanel {
private static void setConfigPanel(final JPanel configPanelAnchor, final ScopeToolState state) {
configPanelAnchor.removeAll();
- configPanelAnchor.add(state.getAdditionalConfigPanel());
+ final JComponent additionalConfigPanel = state.getAdditionalConfigPanel();
+ if (additionalConfigPanel != null) {
+ configPanelAnchor.add(ScrollPaneFactory.createScrollPane(additionalConfigPanel, SideBorder.NONE));
+ }
}
private static InspectionConfigTreeNode getGroupNode(InspectionConfigTreeNode root, String[] groupPath) {
@@ -1001,6 +1025,7 @@ public class SingleInspectionProfilePanel extends JPanel {
if (mySelectedProfile.isChanged()) return true;
if (myShareProfile != (mySelectedProfile.getProfileManager() == myProjectProfileManager)) return true;
if (!Comparing.strEqual(myInitialProfile, mySelectedProfile.getName())) return true;
+ if (!Comparing.equal(myInitialScopesOrder, mySelectedProfile.getScopesOrder())) return true;
if (descriptorsAreChanged()) {
return true;
}
@@ -1111,10 +1136,6 @@ public class SingleInspectionProfilePanel extends JPanel {
return false;
}
- public Tree getTreeTable() {
- return myTreeTable.getTree();
- }
-
public boolean isProfileShared() {
return myShareProfile;
}
@@ -1176,15 +1197,15 @@ public class SingleInspectionProfilePanel extends JPanel {
final boolean showOptionsAndDescriptorPanels,
@NotNull HighlightDisplayLevel level) {
final HighlightDisplayKey key = child.getDefaultDescriptor().getKey();
- mySelectedProfile.setErrorLevel(key, level, -1, myProjectProfileManager.getProject());
+ mySelectedProfile.setErrorLevel(key, level, null, myProjectProfileManager.getProject());
child.dropCache();
if (showOptionsAndDescriptorPanels) {
updateOptionsAndDescriptionPanel(new TreePath(child.getPath()));
}
}
- public JComponent getTree() {
- return myTreeTable.getTree();
+ public JComponent getPreferredFocusedComponent() {
+ return myTreeTable;
}
private class MyFilterComponent extends FilterComponent {
diff --git a/platform/lang-impl/src/com/intellij/profile/codeInspection/ui/filter/InspectionFilterAction.java b/platform/lang-impl/src/com/intellij/profile/codeInspection/ui/filter/InspectionFilterAction.java
index cbd1c2482032..bccd2db28e21 100644
--- a/platform/lang-impl/src/com/intellij/profile/codeInspection/ui/filter/InspectionFilterAction.java
+++ b/platform/lang-impl/src/com/intellij/profile/codeInspection/ui/filter/InspectionFilterAction.java
@@ -20,7 +20,6 @@ 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;
@@ -60,6 +59,23 @@ public class InspectionFilterAction extends DefaultActionGroup {
addSeparator();
add(new ShowAvailableOnlyOnAnalyzeInspectionsAction());
+ add(new ShowOnlyCleanupInspectionsAction());
+ }
+
+ private class ShowOnlyCleanupInspectionsAction extends CheckboxAction {
+ public ShowOnlyCleanupInspectionsAction() {
+ super("Show Only Cleanup Inspections");
+ }
+
+ @Override
+ public boolean isSelected(final AnActionEvent e) {
+ return myInspectionsFilter.isShowOnlyCleanupInspections();
+ }
+
+ @Override
+ public void setSelected(final AnActionEvent e, final boolean state) {
+ myInspectionsFilter.setShowOnlyCleanupInspections(state);
+ }
}
private class ShowAvailableOnlyOnAnalyzeInspectionsAction extends CheckboxAction {
diff --git a/platform/lang-impl/src/com/intellij/profile/codeInspection/ui/filter/InspectionsFilter.java b/platform/lang-impl/src/com/intellij/profile/codeInspection/ui/filter/InspectionsFilter.java
index 432ef560ba58..117cd774dff8 100644
--- a/platform/lang-impl/src/com/intellij/profile/codeInspection/ui/filter/InspectionsFilter.java
+++ b/platform/lang-impl/src/com/intellij/profile/codeInspection/ui/filter/InspectionsFilter.java
@@ -33,11 +33,16 @@ public abstract class InspectionsFilter {
private final Set<HighlightSeverity> mySuitableSeverities = new HashSet<HighlightSeverity>();
private Boolean mySuitableInspectionsStates;
private boolean myAvailableOnlyForAnalyze;
+ private boolean myShowOnlyCleanupInspections;
public boolean isAvailableOnlyForAnalyze() {
return myAvailableOnlyForAnalyze;
}
+ public boolean isShowOnlyCleanupInspections() {
+ return myShowOnlyCleanupInspections;
+ }
+
public Boolean getSuitableInspectionsStates() {
return mySuitableInspectionsStates;
}
@@ -46,6 +51,11 @@ public abstract class InspectionsFilter {
return mySuitableSeverities.contains(severity);
}
+ public void setShowOnlyCleanupInspections(final boolean showOnlyCleanupInspections) {
+ myShowOnlyCleanupInspections = showOnlyCleanupInspections;
+ filterChanged();
+ }
+
public void setAvailableOnlyForAnalyze(final boolean availableOnlyForAnalyze) {
myAvailableOnlyForAnalyze = availableOnlyForAnalyze;
filterChanged();
@@ -67,10 +77,17 @@ public abstract class InspectionsFilter {
}
public boolean isEmptyFilter() {
- return mySuitableInspectionsStates == null && !myAvailableOnlyForAnalyze && mySuitableSeverities.isEmpty();
+ return mySuitableInspectionsStates == null
+ && !myAvailableOnlyForAnalyze
+ && !myShowOnlyCleanupInspections
+ && mySuitableSeverities.isEmpty();
}
public boolean matches(final Tools tools) {
+ if (myShowOnlyCleanupInspections && !tools.getTool().isCleanupTool()) {
+ return false;
+ }
+
if (mySuitableInspectionsStates != null && mySuitableInspectionsStates != tools.isEnabled()) {
return false;
}
diff --git a/platform/lang-impl/src/com/intellij/profile/codeInspection/ui/inspectionsTree/InspectionsConfigTreeTable.java b/platform/lang-impl/src/com/intellij/profile/codeInspection/ui/inspectionsTree/InspectionsConfigTreeTable.java
index 966a456e1d38..92cb62f0f800 100644
--- a/platform/lang-impl/src/com/intellij/profile/codeInspection/ui/inspectionsTree/InspectionsConfigTreeTable.java
+++ b/platform/lang-impl/src/com/intellij/profile/codeInspection/ui/inspectionsTree/InspectionsConfigTreeTable.java
@@ -28,17 +28,21 @@ import com.intellij.openapi.util.Comparing;
import com.intellij.profile.codeInspection.ui.InspectionsAggregationUtil;
import com.intellij.profile.codeInspection.ui.table.ScopesAndSeveritiesTable;
import com.intellij.profile.codeInspection.ui.table.ThreeStateCheckBoxRenderer;
+import com.intellij.ui.DoubleClickListener;
import com.intellij.ui.treeStructure.treetable.TreeTable;
import com.intellij.ui.treeStructure.treetable.TreeTableModel;
+import com.intellij.ui.treeStructure.treetable.TreeTableTree;
+import com.intellij.util.ui.UIUtil;
import org.jetbrains.annotations.Nullable;
import javax.swing.*;
+import javax.swing.table.AbstractTableModel;
import javax.swing.table.TableColumn;
import javax.swing.tree.DefaultTreeModel;
import javax.swing.tree.TreeNode;
+import javax.swing.tree.TreePath;
import java.awt.*;
-import java.awt.event.MouseAdapter;
-import java.awt.event.MouseEvent;
+import java.awt.event.*;
import java.util.*;
import java.util.List;
@@ -60,8 +64,8 @@ public class InspectionsConfigTreeTable extends TreeTable {
final TableColumn isEnabledColumn = getColumnModel().getColumn(IS_ENABLED_COLUMN);
isEnabledColumn.setMaxWidth(20);
- isEnabledColumn.setCellRenderer(new ThreeStateCheckBoxRenderer());
- isEnabledColumn.setCellEditor(new ThreeStateCheckBoxRenderer());
+ isEnabledColumn.setCellRenderer(new ThreeStateCheckBoxRenderer(false));
+ isEnabledColumn.setCellEditor(new ThreeStateCheckBoxRenderer(true));
addMouseMotionListener(new MouseAdapter() {
@Override
@@ -76,10 +80,42 @@ public class InspectionsConfigTreeTable extends TreeTable {
if (maybeIcon instanceof MultiScopeSeverityIcon) {
final LinkedHashMap<String, HighlightSeverity> scopeToAverageSeverityMap =
((MultiScopeSeverityIcon)maybeIcon).getScopeToAverageSeverityMap();
- IdeTooltipManager.getInstance().show(new IdeTooltip(InspectionsConfigTreeTable.this, point, new ScopesAndSeveritiesHintTable(scopeToAverageSeverityMap)), false);
+ IdeTooltipManager.getInstance().show(
+ new IdeTooltip(InspectionsConfigTreeTable.this, point, new ScopesAndSeveritiesHintTable(scopeToAverageSeverityMap)), false);
}
}
});
+
+ new DoubleClickListener() {
+ @Override
+ protected boolean onDoubleClick(MouseEvent event) {
+ final TreePath path = getTree().getPathForRow(getTree().getLeadSelectionRow());
+ if (path != null) {
+ final InspectionConfigTreeNode node = (InspectionConfigTreeNode)path.getLastPathComponent();
+ if (node.isLeaf()) {
+ swapInspectionEnableState();
+ }
+ }
+ return true;
+ }
+ }.installOn(this);
+
+ registerKeyboardAction(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ swapInspectionEnableState();
+ updateUI();
+ }
+ }, KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, 0), JComponent.WHEN_FOCUSED);
+
+ getEmptyText().setText("No enabled inspections available");
+ }
+
+ private void swapInspectionEnableState() {
+ for (int selectedRow : getSelectedRows()) {
+ final Object value = getValueAt(selectedRow, IS_ENABLED_COLUMN);
+ final boolean newValue = !Boolean.TRUE.equals(value);
+ setValueAt(newValue, selectedRow, IS_ENABLED_COLUMN);
+ }
}
public abstract static class InspectionsConfigTreeTableSettings {
@@ -107,6 +143,7 @@ public class InspectionsConfigTreeTable extends TreeTable {
private static class InspectionsConfigTreeTableModel extends DefaultTreeModel implements TreeTableModel {
private final InspectionsConfigTreeTableSettings mySettings;
+ private TreeTable myTreeTable;
public InspectionsConfigTreeTableModel(final InspectionsConfigTreeTableSettings settings) {
super(settings.getRoot());
@@ -154,7 +191,7 @@ public class InspectionsConfigTreeTable extends TreeTable {
mySettings.getInspectionProfile().getNonDefaultTools(toolId, mySettings.getProject()));
}
}
- return sink.constructIcon();
+ return sink.constructIcon(mySettings.getInspectionProfile());
} else if (column == IS_ENABLED_COLUMN) {
return isEnabled(inspectionsKeys);
}
@@ -195,26 +232,34 @@ public class InspectionsConfigTreeTable extends TreeTable {
aNode.dropCache();
mySettings.onChanged(aNode);
}
+ if (myTreeTable != null) {
+ UIUtil.invokeLaterIfNeeded(new Runnable() {
+ public void run() {
+ ((AbstractTableModel)myTreeTable.getModel()).fireTableDataChanged();
+ }
+ });
+ }
}
@Override
public void setTree(final JTree tree) {
+ myTreeTable = ((TreeTableTree)tree).getTreeTable();
}
}
private static class MultiColoredHighlightSeverityIconSink {
- private final LinkedHashMap<String, HighlightSeverity> myScopeToAverageSeverityMap = new LinkedHashMap<String, HighlightSeverity>();
+ private final Map<String, HighlightSeverity> myScopeToAverageSeverityMap = new HashMap<String, HighlightSeverity>();
+ private String myDefaultScopeName;
private boolean myIsFirst = true;
- public Icon constructIcon() {
+ public Icon constructIcon(final InspectionProfileImpl inspectionProfile) {
if (myScopeToAverageSeverityMap.isEmpty()) {
return null;
}
- //TODO order scopes
return !allScopesHasMixedSeverity()
- ? new MultiScopeSeverityIcon(myScopeToAverageSeverityMap)
+ ? new MultiScopeSeverityIcon(myScopeToAverageSeverityMap, myDefaultScopeName, inspectionProfile)
: ScopesAndSeveritiesTable.MIXED_FAKE_LEVEL.getIcon();
}
@@ -229,6 +274,9 @@ public class InspectionsConfigTreeTable extends TreeTable {
public void put(final ScopeToolState defaultState, final Collection<ScopeToolState> nonDefault) {
putOne(defaultState);
+ if (myDefaultScopeName == null) {
+ myDefaultScopeName = defaultState.getScopeName();
+ }
for (final ScopeToolState scopeToolState : nonDefault) {
putOne(scopeToolState);
}
@@ -237,7 +285,7 @@ public class InspectionsConfigTreeTable extends TreeTable {
}
}
- public void putOne(final ScopeToolState state) {
+ private void putOne(final ScopeToolState state) {
final Icon icon = state.getLevel().getIcon();
final String scopeName = state.getScopeName();
if (icon instanceof HighlightDisplayLevel.SingleColorIconWithMask) {
diff --git a/platform/lang-impl/src/com/intellij/profile/codeInspection/ui/inspectionsTree/MultiScopeSeverityIcon.java b/platform/lang-impl/src/com/intellij/profile/codeInspection/ui/inspectionsTree/MultiScopeSeverityIcon.java
index 6f093ca66349..099dbb622261 100644
--- a/platform/lang-impl/src/com/intellij/profile/codeInspection/ui/inspectionsTree/MultiScopeSeverityIcon.java
+++ b/platform/lang-impl/src/com/intellij/profile/codeInspection/ui/inspectionsTree/MultiScopeSeverityIcon.java
@@ -17,13 +17,15 @@ package com.intellij.profile.codeInspection.ui.inspectionsTree;
import com.intellij.codeHighlighting.HighlightDisplayLevel;
+import com.intellij.codeInspection.ex.InspectionProfileImpl;
import com.intellij.lang.annotation.HighlightSeverity;
+import com.intellij.profile.codeInspection.ui.ScopeOrderComparator;
import com.intellij.ui.JBColor;
import javax.swing.*;
import java.awt.*;
-import java.util.Collection;
-import java.util.LinkedHashMap;
+import java.util.*;
+import java.util.List;
/**
* @author Dmitry Batkovich
@@ -35,8 +37,17 @@ public class MultiScopeSeverityIcon implements Icon {
private final LinkedHashMap<String, HighlightSeverity> myScopeToAverageSeverityMap;
- public MultiScopeSeverityIcon(final LinkedHashMap<String, HighlightSeverity> scopeToAverageSeverityMap) {
- myScopeToAverageSeverityMap = scopeToAverageSeverityMap;
+ public MultiScopeSeverityIcon(final Map<String, HighlightSeverity> scopeToAverageSeverityMap,
+ final String defaultScopeName,
+ final InspectionProfileImpl inspectionProfile) {
+ final List<String> sortedScopeNames = new ArrayList<String>(scopeToAverageSeverityMap.keySet());
+ myScopeToAverageSeverityMap = new LinkedHashMap<String, HighlightSeverity>();
+ Collections.sort(sortedScopeNames, new ScopeOrderComparator(inspectionProfile));
+ sortedScopeNames.remove(defaultScopeName);
+ sortedScopeNames.add(defaultScopeName);
+ for (final String scopeName : sortedScopeNames) {
+ myScopeToAverageSeverityMap.put(scopeName, scopeToAverageSeverityMap.get(scopeName));
+ }
}
public LinkedHashMap<String, HighlightSeverity> getScopeToAverageSeverityMap() {
diff --git a/platform/lang-impl/src/com/intellij/profile/codeInspection/ui/inspectionsTree/ScopesAndSeveritiesHintTable.java b/platform/lang-impl/src/com/intellij/profile/codeInspection/ui/inspectionsTree/ScopesAndSeveritiesHintTable.java
index 05cb7ab193f5..68c7f20119bd 100644
--- a/platform/lang-impl/src/com/intellij/profile/codeInspection/ui/inspectionsTree/ScopesAndSeveritiesHintTable.java
+++ b/platform/lang-impl/src/com/intellij/profile/codeInspection/ui/inspectionsTree/ScopesAndSeveritiesHintTable.java
@@ -19,10 +19,12 @@ import com.intellij.codeHighlighting.HighlightDisplayLevel;
import com.intellij.lang.annotation.HighlightSeverity;
import com.intellij.profile.codeInspection.ui.SingleInspectionProfilePanel;
import com.intellij.ui.table.JBTable;
+import com.intellij.util.ui.UIUtil;
import javax.swing.*;
import javax.swing.table.AbstractTableModel;
import javax.swing.table.DefaultTableCellRenderer;
+import javax.swing.table.TableColumn;
import java.awt.*;
import java.util.ArrayList;
import java.util.LinkedHashMap;
@@ -38,9 +40,20 @@ public class ScopesAndSeveritiesHintTable extends JBTable {
public ScopesAndSeveritiesHintTable(final LinkedHashMap<String, HighlightSeverity> scopeToAverageSeverityMap) {
super(new MyModel(scopeToAverageSeverityMap));
- final DefaultTableCellRenderer cellRenderer = new DefaultTableCellRenderer();
- cellRenderer.setOpaque(false);
- getColumnModel().getColumn(SCOPE_COLUMN).setCellRenderer(cellRenderer);
+ getColumnModel().getColumn(SCOPE_COLUMN).setCellRenderer(new DefaultTableCellRenderer() {
+ @Override
+ public Component getTableCellRendererComponent(JTable table,
+ Object value,
+ boolean isSelected,
+ boolean hasFocus,
+ int row,
+ int column) {
+ super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
+ setOpaque(false);
+ UIUtil.applyStyle(UIUtil.ComponentStyle.SMALL, this);
+ return this;
+ }
+ });
getColumnModel().getColumn(SEVERITY_COLUMN).setCellRenderer(new DefaultTableCellRenderer() {
@Override
@@ -55,6 +68,7 @@ public class ScopesAndSeveritiesHintTable extends JBTable {
setIcon(HighlightDisplayLevel.find(severity).getIcon());
setText(SingleInspectionProfilePanel.renderSeverity(severity));
setOpaque(false);
+ UIUtil.applyStyle(UIUtil.ComponentStyle.SMALL, this);
return this;
}
});
@@ -62,6 +76,16 @@ public class ScopesAndSeveritiesHintTable extends JBTable {
setRowSelectionAllowed(false);
setColumnSelectionAllowed(false);
setOpaque(false);
+
+ for (int i = 0; i < getColumnModel().getColumnCount(); i++) {
+ int w = 0;
+ final TableColumn column = getColumnModel().getColumn(i);
+ for (int j = 0; j < getModel().getRowCount(); j++) {
+ final Component component = prepareRenderer(column.getCellRenderer(), j, i);
+ w = Math.max(component.getPreferredSize().width, w);
+ }
+ column.setPreferredWidth(w);
+ }
}
private final static class MyModel extends AbstractTableModel {
@@ -96,7 +120,7 @@ public class ScopesAndSeveritiesHintTable extends JBTable {
@Override
public Object getValueAt(final int rowIndex, final int columnIndex) {
switch (columnIndex) {
- case SCOPE_COLUMN: return myScopes.get(rowIndex);
+ case SCOPE_COLUMN: return rowIndex < getRowCount() - 1 ? myScopes.get(rowIndex) : "Everywhere else";
case SEVERITY_COLUMN: return myScopeToAverageSeverityMap.get(myScopes.get(rowIndex));
default: throw new IllegalArgumentException();
}
diff --git a/platform/lang-impl/src/com/intellij/profile/codeInspection/ui/table/ScopesAndSeveritiesTable.java b/platform/lang-impl/src/com/intellij/profile/codeInspection/ui/table/ScopesAndSeveritiesTable.java
index ad7dc946fff8..3b2c36bf7d34 100644
--- a/platform/lang-impl/src/com/intellij/profile/codeInspection/ui/table/ScopesAndSeveritiesTable.java
+++ b/platform/lang-impl/src/com/intellij/profile/codeInspection/ui/table/ScopesAndSeveritiesTable.java
@@ -17,20 +17,30 @@ package com.intellij.profile.codeInspection.ui.table;
import com.intellij.codeHighlighting.HighlightDisplayLevel;
import com.intellij.codeInsight.daemon.HighlightDisplayKey;
+import com.intellij.codeInspection.ex.Descriptor;
import com.intellij.codeInspection.ex.InspectionProfileImpl;
import com.intellij.codeInspection.ex.ScopeToolState;
import com.intellij.icons.AllIcons;
+import com.intellij.ide.DataManager;
import com.intellij.lang.annotation.HighlightSeverity;
+import com.intellij.openapi.actionSystem.DataContext;
+import com.intellij.openapi.actionSystem.PlatformDataKeys;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.project.Project;
+import com.intellij.openapi.ui.popup.JBPopupFactory;
+import com.intellij.openapi.ui.popup.ListPopup;
import com.intellij.openapi.util.Comparing;
-import com.intellij.profile.codeInspection.ui.AddScopeUtil;
+import com.intellij.profile.codeInspection.ui.ScopeOrderComparator;
+import com.intellij.profile.codeInspection.ui.ScopesChooser;
import com.intellij.profile.codeInspection.ui.inspectionsTree.InspectionConfigTreeNode;
import com.intellij.psi.search.scope.packageSet.NamedScope;
+import com.intellij.ui.awt.RelativePoint;
import com.intellij.ui.table.JBTable;
import com.intellij.ui.treeStructure.treetable.TreeTable;
import com.intellij.util.ArrayUtil;
+import com.intellij.util.Function;
import com.intellij.util.SmartList;
+import com.intellij.util.containers.ContainerUtil;
import com.intellij.util.ui.EditableModel;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -41,8 +51,8 @@ import javax.swing.event.ListSelectionListener;
import javax.swing.table.AbstractTableModel;
import javax.swing.table.TableColumn;
import javax.swing.table.TableColumnModel;
-import java.util.ArrayList;
-import java.util.LinkedHashSet;
+import java.awt.*;
+import java.util.*;
import java.util.List;
/**
@@ -66,8 +76,8 @@ public class ScopesAndSeveritiesTable extends JBTable {
final TableColumn scopeEnabledColumn = columnModel.getColumn(SCOPE_ENABLED_COLUMN);
scopeEnabledColumn.setMaxWidth(30);
- scopeEnabledColumn.setCellRenderer(new ThreeStateCheckBoxRenderer());
- scopeEnabledColumn.setCellEditor(new ThreeStateCheckBoxRenderer());
+ scopeEnabledColumn.setCellRenderer(new ThreeStateCheckBoxRenderer(false));
+ scopeEnabledColumn.setCellEditor(new ThreeStateCheckBoxRenderer(true));
final TableColumn severityColumn = columnModel.getColumn(SEVERITY_COLUMN);
severityColumn.setCellRenderer(SeverityRenderer.create(tableSettings.getInspectionProfile()));
@@ -94,6 +104,8 @@ public class ScopesAndSeveritiesTable extends JBTable {
setStriped(true);
setShowGrid(false);
+
+ ((MyTableModel)getModel()).setTable(this);
}
public abstract static class TableSettings {
@@ -148,11 +160,13 @@ public class ScopesAndSeveritiesTable extends JBTable {
protected abstract void onScopeAdded();
+ protected abstract void onScopesOrderChanged();
+
protected abstract void onScopeRemoved(final int scopesCount);
protected abstract void onScopeChosen(final @NotNull ScopeToolState scopeToolState);
- protected abstract void onChange();
+ protected abstract void onSettingsChanged();
}
@NotNull
@@ -177,7 +191,9 @@ public class ScopesAndSeveritiesTable extends JBTable {
private final Project myProject;
private final TableSettings myTableSettings;
private final List<HighlightDisplayKey> myKeys;
+ private final Comparator<String> myScopeComparator;
+ private JTable myTable;
private String[] myScopeNames;
public MyTableModel(final TableSettings tableSettings) {
@@ -188,12 +204,24 @@ public class ScopesAndSeveritiesTable extends JBTable {
myKeyNames = tableSettings.getKeyNames();
myNodes = tableSettings.getNodes();
myTreeTable = tableSettings.getTreeTable();
+ myScopeComparator = new ScopeOrderComparator(myInspectionProfile);
refreshAggregatedScopes();
}
+ public void setTable(JTable table) {
+ myTable = table;
+ }
+
@Override
public boolean isCellEditable(final int rowIndex, final int columnIndex) {
- return columnIndex != SCOPE_NAME_COLUMN;
+ if (columnIndex == SCOPE_NAME_COLUMN) {
+ return false;
+ } else if (columnIndex == SCOPE_ENABLED_COLUMN) {
+ return true;
+ }
+ assert columnIndex == SEVERITY_COLUMN;
+ final ExistedScopesStatesAndNonExistNames scopeToolState = getScopeToolState(rowIndex);
+ return scopeToolState.getNonExistNames().isEmpty();
}
@Override
@@ -221,7 +249,7 @@ public class ScopesAndSeveritiesTable extends JBTable {
return String.class;
}
if (SEVERITY_COLUMN == columnIndex) {
- return HighlightSeverity.class;
+ return SeverityState.class;
}
throw new IllegalArgumentException();
}
@@ -235,9 +263,9 @@ public class ScopesAndSeveritiesTable extends JBTable {
case SCOPE_ENABLED_COLUMN:
return isEnabled(rowIndex);
case SCOPE_NAME_COLUMN:
- return getScope(rowIndex).getName();
+ return rowIndex == lastRowIndex() ? "Everywhere else" : getScope(rowIndex).getName();
case SEVERITY_COLUMN:
- return getSeverity(rowIndex);
+ return getSeverityState(rowIndex);
default:
throw new IllegalArgumentException("Invalid column index " + columnIndex);
}
@@ -248,12 +276,12 @@ public class ScopesAndSeveritiesTable extends JBTable {
}
@NotNull
- private HighlightSeverity getSeverity(final int rowIndex) {
+ private SeverityState getSeverityState(final int rowIndex) {
final ExistedScopesStatesAndNonExistNames existedScopesStatesAndNonExistNames = getScopeToolState(rowIndex);
if (!existedScopesStatesAndNonExistNames.getNonExistNames().isEmpty()) {
- return MIXED_FAKE_SEVERITY;
+ return new SeverityState(MIXED_FAKE_SEVERITY, false);
}
- return ScopesAndSeveritiesTable.getSeverity(existedScopesStatesAndNonExistNames.getExistedStates());
+ return new SeverityState(ScopesAndSeveritiesTable.getSeverity(existedScopesStatesAndNonExistNames.getExistedStates()), true);
}
@Nullable
@@ -314,6 +342,7 @@ public class ScopesAndSeveritiesTable extends JBTable {
}
}
myScopeNames = ArrayUtil.toStringArray(scopesNames);
+ Arrays.sort(myScopeNames, myScopeComparator);
}
private int lastRowIndex() {
@@ -326,13 +355,14 @@ public class ScopesAndSeveritiesTable extends JBTable {
return;
}
if (columnIndex == SEVERITY_COLUMN) {
- final HighlightDisplayLevel level = HighlightDisplayLevel.find(((HighlightSeverity)value).getName());
+ final SeverityState severityState = (SeverityState)value;
+ final HighlightDisplayLevel level = HighlightDisplayLevel.find(severityState.getSeverity().getName());
if (level == null) {
- LOG.error("no display level found for name " + ((HighlightSeverity)value).getName());
+ LOG.error("no display level found for name " + severityState.getSeverity().getName());
return;
}
- final int idx = rowIndex == lastRowIndex() ? -1 : rowIndex;
- myInspectionProfile.setErrorLevel(myKeys, level, idx, myProject);
+ final String scopeName = rowIndex == lastRowIndex() ? null : getScope(rowIndex).getName();
+ myInspectionProfile.setErrorLevel(myKeys, level, scopeName, myProject);
}
else if (columnIndex == SCOPE_ENABLED_COLUMN) {
final NamedScope scope = getScope(rowIndex);
@@ -354,7 +384,7 @@ public class ScopesAndSeveritiesTable extends JBTable {
}
}
}
- myTableSettings.onChange();
+ myTableSettings.onSettingsChanged();
}
@Override
@@ -368,9 +398,31 @@ public class ScopesAndSeveritiesTable extends JBTable {
@Override
public void addRow() {
- AddScopeUtil.performAddScope(myTreeTable, myProject, myInspectionProfile, myNodes);
- myTableSettings.onScopeAdded();
- refreshAggregatedScopes();
+ final List<Descriptor> descriptors = ContainerUtil.map(myTableSettings.getNodes(), new Function<InspectionConfigTreeNode, Descriptor>() {
+ @Override
+ public Descriptor fun(InspectionConfigTreeNode inspectionConfigTreeNode) {
+ return inspectionConfigTreeNode.getDefaultDescriptor();
+ }
+ });
+ final ScopesChooser scopesChooser = new ScopesChooser(descriptors, myInspectionProfile, myProject, myScopeNames) {
+ @Override
+ protected void onScopeAdded() {
+ myTableSettings.onScopeAdded();
+ refreshAggregatedScopes();
+ }
+
+ @Override
+ protected void onScopesOrderChanged() {
+ myTableSettings.onScopesOrderChanged();
+ }
+ };
+ DataContext dataContext = DataManager.getInstance().getDataContext(myTable);
+ final JComponent component = (JComponent)PlatformDataKeys.CONTEXT_COMPONENT.getData(dataContext);
+ final ListPopup popup = JBPopupFactory.getInstance()
+ .createActionGroupPopup(ScopesChooser.TITLE, scopesChooser.createPopupActionGroup(myTable), dataContext,
+ JBPopupFactory.ActionSelectionAid.SPEEDSEARCH, false);
+ final RelativePoint point = new RelativePoint(myTable, new Point(myTable.getWidth() - popup.getContent().getPreferredSize().width, 0));
+ popup.show(point);
}
@Override
diff --git a/platform/lang-impl/src/com/intellij/profile/codeInspection/ui/table/SeverityRenderer.java b/platform/lang-impl/src/com/intellij/profile/codeInspection/ui/table/SeverityRenderer.java
index 2fe95e6d7224..e1b3d54b8fb7 100644
--- a/platform/lang-impl/src/com/intellij/profile/codeInspection/ui/table/SeverityRenderer.java
+++ b/platform/lang-impl/src/com/intellij/profile/codeInspection/ui/table/SeverityRenderer.java
@@ -22,6 +22,8 @@ import com.intellij.openapi.ui.ComboBoxTableRenderer;
import com.intellij.profile.codeInspection.SeverityProvider;
import com.intellij.profile.codeInspection.ui.LevelChooserAction;
import com.intellij.profile.codeInspection.ui.SingleInspectionProfilePanel;
+import com.intellij.util.Function;
+import com.intellij.util.containers.ContainerUtil;
import org.jetbrains.annotations.NotNull;
import javax.swing.*;
@@ -32,33 +34,40 @@ import java.util.SortedSet;
/**
* @author Dmitry Batkovich
*/
-public class SeverityRenderer extends ComboBoxTableRenderer<HighlightSeverity> {
- public SeverityRenderer(final HighlightSeverity[] values) {
+public class SeverityRenderer extends ComboBoxTableRenderer<SeverityState> {
+ public SeverityRenderer(final SeverityState[] values) {
super(values);
}
public static SeverityRenderer create(final InspectionProfileImpl inspectionProfile) {
final SortedSet<HighlightSeverity> severities =
LevelChooserAction.getSeverities(((SeverityProvider)inspectionProfile.getProfileManager()).getOwnSeverityRegistrar());
- return new SeverityRenderer(severities.toArray(new HighlightSeverity[severities.size()]));
+ return new SeverityRenderer(ContainerUtil.map2Array(severities, new SeverityState[severities.size()], new Function<HighlightSeverity, SeverityState>() {
+ @Override
+ public SeverityState fun(HighlightSeverity severity) {
+ return new SeverityState(severity, true);
+ }
+ }));
}
+ @Override
+ protected void customizeComponent(SeverityState value, JTable table, boolean isSelected) {
+ super.customizeComponent(value, table, isSelected);
+ setPaintArrow(value.isEnabledForEditing());
+ }
@Override
- protected String getTextFor(@NotNull final HighlightSeverity value) {
- return SingleInspectionProfilePanel.renderSeverity(value);
+ protected String getTextFor(@NotNull final SeverityState value) {
+ return SingleInspectionProfilePanel.renderSeverity(value.getSeverity());
}
@Override
- protected Icon getIconFor(@NotNull final HighlightSeverity value) {
- return HighlightDisplayLevel.find(value).getIcon();
+ protected Icon getIconFor(@NotNull final SeverityState value) {
+ return HighlightDisplayLevel.find(value.getSeverity()).getIcon();
}
@Override
public boolean isCellEditable(final EventObject event) {
- if (event instanceof MouseEvent) {
- return ((MouseEvent)event).getClickCount() >= 1;
- }
- return true;
+ return !(event instanceof MouseEvent) || ((MouseEvent)event).getClickCount() >= 1;
}
}
diff --git a/platform/lang-impl/src/com/intellij/profile/codeInspection/ui/table/SeverityState.java b/platform/lang-impl/src/com/intellij/profile/codeInspection/ui/table/SeverityState.java
new file mode 100644
index 000000000000..2aefde070af7
--- /dev/null
+++ b/platform/lang-impl/src/com/intellij/profile/codeInspection/ui/table/SeverityState.java
@@ -0,0 +1,40 @@
+/*
+ * 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.table;
+
+import com.intellij.lang.annotation.HighlightSeverity;
+
+/**
+ * @author Dmitry Batkovich
+ */
+public class SeverityState {
+
+ private final HighlightSeverity mySeverity;
+ private final boolean myEnabledForEditing;
+
+ public SeverityState(HighlightSeverity severity, boolean enabledForEditing) {
+ mySeverity = severity;
+ myEnabledForEditing = enabledForEditing;
+ }
+
+ public HighlightSeverity getSeverity() {
+ return mySeverity;
+ }
+
+ public boolean isEnabledForEditing() {
+ return myEnabledForEditing;
+ }
+}
diff --git a/platform/lang-impl/src/com/intellij/profile/codeInspection/ui/table/ThreeStateCheckBoxRenderer.java b/platform/lang-impl/src/com/intellij/profile/codeInspection/ui/table/ThreeStateCheckBoxRenderer.java
index 7d8cfdfc9db5..455e2a60cd19 100644
--- a/platform/lang-impl/src/com/intellij/profile/codeInspection/ui/table/ThreeStateCheckBoxRenderer.java
+++ b/platform/lang-impl/src/com/intellij/profile/codeInspection/ui/table/ThreeStateCheckBoxRenderer.java
@@ -15,11 +15,9 @@
*/
package com.intellij.profile.codeInspection.ui.table;
-import com.intellij.ui.ClickListener;
import com.intellij.util.SmartList;
import com.intellij.util.ui.ThreeStateCheckBox;
import com.intellij.util.ui.UIUtil;
-import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import javax.swing.*;
@@ -28,7 +26,7 @@ import javax.swing.event.ChangeEvent;
import javax.swing.table.TableCellEditor;
import javax.swing.table.TableCellRenderer;
import java.awt.*;
-import java.awt.event.MouseEvent;
+import java.awt.event.*;
import java.util.EventObject;
import java.util.List;
@@ -39,10 +37,16 @@ public class ThreeStateCheckBoxRenderer extends ThreeStateCheckBox implements Ta
private final List<CellEditorListener> myListeners = new SmartList<CellEditorListener>();
- public ThreeStateCheckBoxRenderer() {
+ public ThreeStateCheckBoxRenderer(final boolean isEditor) {
setThirdStateEnabled(false);
setHorizontalAlignment(CENTER);
setVerticalAlignment(CENTER);
+ addItemListener(new ItemListener() {
+ @Override
+ public void itemStateChanged(ItemEvent e) {
+ stopCellEditing();
+ }
+ });
}
@Override
@@ -69,16 +73,6 @@ public class ThreeStateCheckBoxRenderer extends ThreeStateCheckBox implements Ta
} else {
setSelected((Boolean) value);
}
- new ClickListener() {
- @Override
- public boolean onClick(@NotNull final MouseEvent event, final int clickCount) {
- if (clickCount == 1) {
- stopCellEditing();
- return true;
- }
- return false;
- }
- }.installOn(this);
return this;
}