mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Inspection settings UI: new severity level chooser ("Edit severity" action replaced from additional button to chooser)
This commit is contained in:
@@ -1,100 +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: 19-Apr-2009
|
||||
*/
|
||||
package com.intellij.profile.codeInspection.ui;
|
||||
|
||||
import com.intellij.codeHighlighting.HighlightDisplayLevel;
|
||||
import com.intellij.codeInsight.daemon.impl.HighlightInfoType;
|
||||
import com.intellij.codeInsight.daemon.impl.SeverityRegistrar;
|
||||
import com.intellij.codeInsight.daemon.impl.SeverityUtil;
|
||||
import com.intellij.codeInspection.ex.SeverityEditorDialog;
|
||||
import com.intellij.ui.ListCellRendererWrapper;
|
||||
import com.intellij.lang.annotation.HighlightSeverity;
|
||||
import com.intellij.ui.ComboboxWithBrowseButton;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.util.TreeSet;
|
||||
|
||||
public class LevelChooser extends ComboboxWithBrowseButton {
|
||||
public LevelChooser(final SeverityRegistrar severityRegistrar) {
|
||||
final JComboBox comboBox = getComboBox();
|
||||
final DefaultComboBoxModel model = new DefaultComboBoxModel();
|
||||
comboBox.setModel(model);
|
||||
fillModel(model, severityRegistrar);
|
||||
getButton().setToolTipText("Edit severities (" + getButton().getToolTipText(null) + ")");
|
||||
|
||||
comboBox.setRenderer(new ListCellRendererWrapper<HighlightSeverity>() {
|
||||
@Override
|
||||
public void customize(final JList list, final HighlightSeverity value, final int index, final boolean selected, final boolean hasFocus) {
|
||||
if (value != null) {
|
||||
setText(SingleInspectionProfilePanel.renderSeverity(value));
|
||||
setIcon(HighlightDisplayLevel.find(value).getIcon());
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
final SeverityEditorDialog dlg = new SeverityEditorDialog(LevelChooser.this, (HighlightSeverity)getComboBox().getSelectedItem(), severityRegistrar);
|
||||
dlg.show();
|
||||
if (dlg.isOK()) {
|
||||
final Object item = getComboBox().getSelectedItem();
|
||||
fillModel(model, severityRegistrar);
|
||||
final HighlightInfoType type = dlg.getSelectedType();
|
||||
if (type != null) {
|
||||
getComboBox().setSelectedItem(type.getSeverity(null));
|
||||
} else {
|
||||
getComboBox().setSelectedItem(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static void fillModel(DefaultComboBoxModel model, final SeverityRegistrar severityRegistrar) {
|
||||
model.removeAllElements();
|
||||
final TreeSet<HighlightSeverity> severities = new TreeSet<HighlightSeverity>(severityRegistrar);
|
||||
for (SeverityRegistrar.SeverityBasedTextAttributes type : SeverityUtil.getRegisteredHighlightingInfoTypes(severityRegistrar)) {
|
||||
severities.add(type.getSeverity());
|
||||
}
|
||||
severities.add(HighlightSeverity.ERROR);
|
||||
severities.add(HighlightSeverity.WARNING);
|
||||
severities.add(HighlightSeverity.WEAK_WARNING);
|
||||
severities.add(HighlightSeverity.GENERIC_SERVER_ERROR_OR_WARNING);
|
||||
for (HighlightSeverity severity : severities) {
|
||||
model.addElement(severity);
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public HighlightDisplayLevel getLevel() {
|
||||
HighlightSeverity severity = (HighlightSeverity)getComboBox().getSelectedItem();
|
||||
if (severity == null) return HighlightDisplayLevel.WARNING;
|
||||
return HighlightDisplayLevel.find(severity);
|
||||
}
|
||||
|
||||
public void setLevel(HighlightDisplayLevel level) {
|
||||
getComboBox().setSelectedItem(level.getSeverity());
|
||||
}
|
||||
}
|
||||
+116
@@ -0,0 +1,116 @@
|
||||
/*
|
||||
* 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.codeHighlighting.HighlightDisplayLevel;
|
||||
import com.intellij.codeInsight.daemon.impl.HighlightInfoType;
|
||||
import com.intellij.codeInsight.daemon.impl.SeverityRegistrar;
|
||||
import com.intellij.codeInsight.daemon.impl.SeverityUtil;
|
||||
import com.intellij.codeInspection.ex.SeverityEditorDialog;
|
||||
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.Presentation;
|
||||
import com.intellij.openapi.actionSystem.ex.ComboBoxAction;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.util.SortedSet;
|
||||
import java.util.TreeSet;
|
||||
|
||||
/**
|
||||
* @author Dmitry Batkovich
|
||||
*/
|
||||
public abstract class LevelChooserAction extends ComboBoxAction {
|
||||
|
||||
private final SeverityRegistrar mySeverityRegistrar;
|
||||
private HighlightSeverity myChosen = null;
|
||||
|
||||
public LevelChooserAction(final SeverityRegistrar severityRegistrar) {
|
||||
mySeverityRegistrar = severityRegistrar;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected DefaultActionGroup createPopupActionGroup(final JComponent button) {
|
||||
final DefaultActionGroup group = new DefaultActionGroup();
|
||||
|
||||
final SortedSet<HighlightSeverity> severities = new TreeSet<HighlightSeverity>(mySeverityRegistrar);
|
||||
for (final SeverityRegistrar.SeverityBasedTextAttributes type : SeverityUtil.getRegisteredHighlightingInfoTypes(mySeverityRegistrar)) {
|
||||
severities.add(type.getSeverity());
|
||||
}
|
||||
severities.add(HighlightSeverity.ERROR);
|
||||
severities.add(HighlightSeverity.WARNING);
|
||||
severities.add(HighlightSeverity.WEAK_WARNING);
|
||||
severities.add(HighlightSeverity.GENERIC_SERVER_ERROR_OR_WARNING);
|
||||
for (final HighlightSeverity severity : severities) {
|
||||
final HighlightSeverityAction action = new HighlightSeverityAction(severity);
|
||||
if (myChosen == null) {
|
||||
setChosen(action.getSeverity());
|
||||
}
|
||||
group.add(action);
|
||||
}
|
||||
group.addSeparator();
|
||||
group.add(new AnAction("Edit severities...") {
|
||||
@Override
|
||||
public void actionPerformed(final AnActionEvent e) {
|
||||
final SeverityEditorDialog dlg = new SeverityEditorDialog(button, myChosen, mySeverityRegistrar);
|
||||
dlg.show();
|
||||
if (dlg.isOK()) {
|
||||
final HighlightInfoType type = dlg.getSelectedType();
|
||||
if (type != null) {
|
||||
final HighlightSeverity severity = type.getSeverity(null);
|
||||
setChosen(severity);
|
||||
onChosen(severity);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
return group;
|
||||
}
|
||||
|
||||
protected abstract void onChosen(final HighlightSeverity severity);
|
||||
|
||||
public void setChosen(final HighlightSeverity severity) {
|
||||
myChosen = severity;
|
||||
final Presentation templatePresentation = getTemplatePresentation();
|
||||
templatePresentation.setText(SingleInspectionProfilePanel.renderSeverity(severity));
|
||||
templatePresentation.setIcon(HighlightDisplayLevel.find(severity).getIcon());
|
||||
}
|
||||
|
||||
private class HighlightSeverityAction extends AnAction {
|
||||
private final HighlightSeverity mySeverity;
|
||||
|
||||
public HighlightSeverity getSeverity() {
|
||||
return mySeverity;
|
||||
}
|
||||
|
||||
private HighlightSeverityAction(final HighlightSeverity severity) {
|
||||
mySeverity = severity;
|
||||
final Presentation presentation = getTemplatePresentation();
|
||||
presentation.setText(SingleInspectionProfilePanel.renderSeverity(severity));
|
||||
presentation.setIcon(HighlightDisplayLevel.find(severity).getIcon());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(final AnActionEvent e) {
|
||||
final HighlightSeverity severity = getSeverity();
|
||||
setChosen(severity);
|
||||
onChosen(severity);
|
||||
}
|
||||
}
|
||||
}
|
||||
+15
-27
@@ -24,7 +24,6 @@ import com.intellij.codeInsight.daemon.impl.SeverityRegistrar;
|
||||
import com.intellij.codeInsight.daemon.impl.SeverityUtil;
|
||||
import com.intellij.codeInsight.hint.HintUtil;
|
||||
import com.intellij.codeInspection.InspectionProfile;
|
||||
import com.intellij.codeInspection.InspectionProfileEntry;
|
||||
import com.intellij.codeInspection.InspectionsBundle;
|
||||
import com.intellij.codeInspection.ModifiableModel;
|
||||
import com.intellij.codeInspection.ex.*;
|
||||
@@ -81,8 +80,6 @@ import javax.swing.tree.DefaultTreeSelectionModel;
|
||||
import javax.swing.tree.TreeNode;
|
||||
import javax.swing.tree.TreePath;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.InputEvent;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.io.IOException;
|
||||
@@ -785,35 +782,26 @@ public class SingleInspectionProfilePanel extends JPanel {
|
||||
final NamedScope scope = node.getScope(myProjectProfileManager.getProject());
|
||||
if (scope != null || node.isInspectionNode()) {
|
||||
final HighlightDisplayKey key = descriptor.getKey();
|
||||
final LevelChooser chooser = new LevelChooser(((SeverityProvider)mySelectedProfile.getProfileManager()).getOwnSeverityRegistrar()) {
|
||||
@Override
|
||||
public Dimension getPreferredSize() {
|
||||
Dimension preferredSize = super.getPreferredSize();
|
||||
return new Dimension(Math.min(300, preferredSize.width), preferredSize.height);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Dimension getMinimumSize() {
|
||||
return getPreferredSize();
|
||||
}
|
||||
};
|
||||
chooser.getComboBox().addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
Project project = myProjectProfileManager.getProject();
|
||||
boolean toUpdate = mySelectedProfile.getErrorLevel(key, scope, project) != chooser.getLevel();
|
||||
mySelectedProfile.setErrorLevel(key, chooser.getLevel(), node.isInspectionNode() || node.isByDefault() ? -1 : node.getParent().getIndex(node),
|
||||
project);
|
||||
if (toUpdate) node.dropCache();
|
||||
}
|
||||
});
|
||||
chooser.setLevel(mySelectedProfile.getErrorLevel(key, scope, myProjectProfileManager.getProject()));
|
||||
final LevelChooserAction chooser =
|
||||
new LevelChooserAction(((SeverityProvider)mySelectedProfile.getProfileManager()).getOwnSeverityRegistrar()) {
|
||||
@Override
|
||||
protected void onChosen(final HighlightSeverity severity) {
|
||||
final HighlightDisplayLevel level = HighlightDisplayLevel.find(severity);
|
||||
final Project project = myProjectProfileManager.getProject();
|
||||
final boolean toUpdate = mySelectedProfile.getErrorLevel(key, scope, project) != level;
|
||||
mySelectedProfile.setErrorLevel(key, level,
|
||||
node.isInspectionNode() || node.isByDefault() ? -1 : node.getParent().getIndex(node),
|
||||
project);
|
||||
if (toUpdate) node.dropCache();
|
||||
}
|
||||
};
|
||||
chooser.setChosen(mySelectedProfile.getErrorLevel(key, scope, myProjectProfileManager.getProject()).getSeverity());
|
||||
|
||||
final JPanel withSeverity = new JPanel(new GridBagLayout());
|
||||
withSeverity.add(new JLabel(InspectionsBundle.message("inspection.severity")),
|
||||
new GridBagConstraints(0, 0, 1, 1, 0, 0, GridBagConstraints.WEST,
|
||||
GridBagConstraints.NONE, new Insets(0, 0, 10, 10), 0, 0));
|
||||
withSeverity.add(chooser, new GridBagConstraints(1, 0, 1, 1, 1.0, 0, GridBagConstraints.WEST,
|
||||
withSeverity.add(chooser.createCustomComponent(chooser.getTemplatePresentation()), new GridBagConstraints(1, 0, 1, 1, 1.0, 0, GridBagConstraints.WEST,
|
||||
GridBagConstraints.NONE, new Insets(0, 0, 10, 0), 0, 0));
|
||||
|
||||
final JComponent comp = descriptor.getState().getAdditionalConfigPanel();
|
||||
|
||||
@@ -105,6 +105,7 @@ public abstract class ComboBoxAction extends AnAction implements CustomComponent
|
||||
private boolean myMouseInside = false;
|
||||
private JBPopup myPopup;
|
||||
private boolean myForceTransparent = false;
|
||||
private Boolean myForceEnabled = null;
|
||||
|
||||
public ComboBoxButton(Presentation presentation) {
|
||||
myPresentation = presentation;
|
||||
@@ -201,6 +202,12 @@ public abstract class ComboBoxAction extends AnAction implements CustomComponent
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setEnabled(final boolean enabled) {
|
||||
super.setEnabled(enabled);
|
||||
myForceEnabled = enabled;
|
||||
}
|
||||
|
||||
public void setForceTransparent(boolean transparent) {
|
||||
myForceTransparent = transparent;
|
||||
}
|
||||
@@ -371,6 +378,9 @@ public abstract class ComboBoxAction extends AnAction implements CustomComponent
|
||||
final Dimension size = getSize();
|
||||
final boolean isEmpty = getIcon() == null && StringUtil.isEmpty(getText());
|
||||
|
||||
final Color textColor = (myForceEnabled == null ? myPresentation.isEnabled() : myForceEnabled)
|
||||
? UIManager.getColor("Panel.foreground")
|
||||
: UIUtil.getInactiveTextColor();
|
||||
if (myForceTransparent) {
|
||||
final Icon icon = getIcon();
|
||||
int x = 7;
|
||||
@@ -381,7 +391,7 @@ public abstract class ComboBoxAction extends AnAction implements CustomComponent
|
||||
if (!StringUtil.isEmpty(getText())) {
|
||||
final Font font = getFont();
|
||||
g.setFont(font);
|
||||
g.setColor(UIManager.getColor("Panel.foreground"));
|
||||
g.setColor(textColor);
|
||||
g.drawString(getText(), x, (size.height + font.getSize()) / 2 - 1);
|
||||
}
|
||||
} else {
|
||||
@@ -416,7 +426,7 @@ public abstract class ComboBoxAction extends AnAction implements CustomComponent
|
||||
if (!StringUtil.isEmpty(getText())) {
|
||||
final Font font = getFont();
|
||||
g2.setFont(font);
|
||||
g2.setColor(UIManager.getColor("Panel.foreground"));
|
||||
g2.setColor(textColor);
|
||||
g2.drawString(getText(), x, (size.height + font.getSize()) / 2 - 1);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user