mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Inspections ui:
1. mixed severity for scope not shown if part of inspections which have no this scope have same severity for default scope 2. table tree updating fixed
This commit is contained in:
+4
-2
@@ -754,6 +754,7 @@ public class SingleInspectionProfilePanel extends JPanel {
|
||||
final boolean toUpdate = mySelectedProfile.getErrorLevel(key, scope, project) != level;
|
||||
mySelectedProfile.setErrorLevel(key, level, null, project);
|
||||
if (toUpdate) node.dropCache();
|
||||
myTreeTable.updateUI();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -817,7 +818,7 @@ public class SingleInspectionProfilePanel extends JPanel {
|
||||
|
||||
@Override
|
||||
protected void onSettingsChanged() {
|
||||
myTreeTable.getTree().updateUI();
|
||||
myTreeTable.updateUI();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -827,12 +828,13 @@ public class SingleInspectionProfilePanel extends JPanel {
|
||||
|
||||
@Override
|
||||
protected void onScopesOrderChanged() {
|
||||
myTreeTable.getTree().updateUI();
|
||||
myTreeTable.updateUI();
|
||||
updateOptionsAndDescriptionPanel();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onScopeRemoved(final int scopesCount) {
|
||||
myTreeTable.updateUI();
|
||||
if (scopesCount == 1) {
|
||||
updateOptionsAndDescriptionPanel();
|
||||
}
|
||||
|
||||
+112
-24
@@ -33,8 +33,11 @@ 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.containers.ContainerUtil;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import com.intellij.util.containers.*;
|
||||
import com.intellij.util.containers.HashSet;
|
||||
import com.intellij.util.ui.UIUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
@@ -46,6 +49,7 @@ import javax.swing.tree.TreePath;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import java.util.*;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -259,32 +263,122 @@ public class InspectionsConfigTreeTable extends TreeTable {
|
||||
}
|
||||
}
|
||||
|
||||
private static class SeverityAndOccurrences {
|
||||
private HighlightSeverity myPrimarySeverity;
|
||||
private final Map<String, HighlightSeverity> myOccurrences = new HashMap<String, HighlightSeverity>();
|
||||
|
||||
public void setSeverityToMixed() {
|
||||
myPrimarySeverity = ScopesAndSeveritiesTable.MIXED_FAKE_SEVERITY;
|
||||
}
|
||||
|
||||
public SeverityAndOccurrences incOccurrences(final String toolName, final HighlightSeverity severity) {
|
||||
if (myPrimarySeverity == null) {
|
||||
myPrimarySeverity = severity;
|
||||
} else if (!Comparing.equal(severity, myPrimarySeverity)) {
|
||||
myPrimarySeverity = ScopesAndSeveritiesTable.MIXED_FAKE_SEVERITY;
|
||||
}
|
||||
myOccurrences.put(toolName, severity);
|
||||
return this;
|
||||
}
|
||||
|
||||
public HighlightSeverity getPrimarySeverity() {
|
||||
return myPrimarySeverity;
|
||||
}
|
||||
|
||||
public int getOccurrencesSize() {
|
||||
return myOccurrences.size();
|
||||
}
|
||||
|
||||
public Map<String, HighlightSeverity> getOccurrences() {
|
||||
return myOccurrences;
|
||||
}
|
||||
}
|
||||
|
||||
private static class MultiColoredHighlightSeverityIconSink {
|
||||
|
||||
private final Map<String, HighlightSeverity> myScopeToAverageSeverityMap = new HashMap<String, HighlightSeverity>();
|
||||
|
||||
private final Map<String, SeverityAndOccurrences> myScopeToAverageSeverityMap = new HashMap<String, SeverityAndOccurrences>();
|
||||
|
||||
private String myDefaultScopeName;
|
||||
private boolean myIsFirst = true;
|
||||
|
||||
public Icon constructIcon(final InspectionProfileImpl inspectionProfile) {
|
||||
final Map<String, HighlightSeverity> computedSeverities = computeSeverities(inspectionProfile);
|
||||
|
||||
if (computedSeverities == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
boolean allScopesHasMixedSeverity = true;
|
||||
for (HighlightSeverity severity : computedSeverities.values()) {
|
||||
if (!severity.equals(ScopesAndSeveritiesTable.MIXED_FAKE_SEVERITY)) {
|
||||
allScopesHasMixedSeverity = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return allScopesHasMixedSeverity
|
||||
? ScopesAndSeveritiesTable.MIXED_FAKE_LEVEL.getIcon()
|
||||
: new MultiScopeSeverityIcon(computedSeverities, myDefaultScopeName, inspectionProfile);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private Map<String, HighlightSeverity> computeSeverities(final InspectionProfileImpl inspectionProfile) {
|
||||
if (myScopeToAverageSeverityMap.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
return !allScopesHasMixedSeverity()
|
||||
? new MultiScopeSeverityIcon(myScopeToAverageSeverityMap, myDefaultScopeName, inspectionProfile)
|
||||
: ScopesAndSeveritiesTable.MIXED_FAKE_LEVEL.getIcon();
|
||||
}
|
||||
final Map<String, HighlightSeverity> result = new HashMap<String, HighlightSeverity>();
|
||||
final Map.Entry<String, SeverityAndOccurrences> entry = ContainerUtil.getFirstItem(myScopeToAverageSeverityMap.entrySet());
|
||||
result.put(entry.getKey(), entry.getValue().getPrimarySeverity());
|
||||
if (myScopeToAverageSeverityMap.size() == 1) {
|
||||
return result;
|
||||
}
|
||||
String[] scopesOrder = inspectionProfile.getScopesOrder();
|
||||
if (scopesOrder == null || scopesOrder.length == 0) {
|
||||
final ArrayList<String> scopesList = new ArrayList<String>(myScopeToAverageSeverityMap.keySet());
|
||||
scopesList.remove(myDefaultScopeName);
|
||||
ContainerUtil.sort(scopesList);
|
||||
scopesOrder = ArrayUtil.toStringArray(scopesList);
|
||||
}
|
||||
|
||||
private boolean allScopesHasMixedSeverity() {
|
||||
for (final Map.Entry<String, HighlightSeverity> e : myScopeToAverageSeverityMap.entrySet()) {
|
||||
if (!ScopesAndSeveritiesTable.MIXED_FAKE_SEVERITY.equals(e.getValue())) {
|
||||
return false;
|
||||
final SeverityAndOccurrences defaultSeveritiesAndOccurrences = myScopeToAverageSeverityMap.get(myDefaultScopeName);
|
||||
final int allInspectionsCount = defaultSeveritiesAndOccurrences.getOccurrencesSize();
|
||||
final Map<String, HighlightSeverity> allScopes = defaultSeveritiesAndOccurrences.getOccurrences();
|
||||
String[] reversedScopesOrder = ArrayUtil.reverseArray(scopesOrder);
|
||||
for (String currentScope : reversedScopesOrder) {
|
||||
final SeverityAndOccurrences currentSeverityAndOccurrences = myScopeToAverageSeverityMap.get(currentScope);
|
||||
if (currentSeverityAndOccurrences == null) {
|
||||
continue;
|
||||
}
|
||||
final HighlightSeverity currentSeverity = currentSeverityAndOccurrences.getPrimarySeverity();
|
||||
if (currentSeverity == ScopesAndSeveritiesTable.MIXED_FAKE_SEVERITY ||
|
||||
currentSeverityAndOccurrences.getOccurrencesSize() == allInspectionsCount) {
|
||||
result.put(currentScope, currentSeverity);
|
||||
}
|
||||
else {
|
||||
Set<String> toolsToCheck = ContainerUtil.newHashSet(allScopes.keySet());
|
||||
toolsToCheck.removeAll(currentSeverityAndOccurrences.getOccurrences().keySet());
|
||||
boolean doContinue = false;
|
||||
final Map<String, HighlightSeverity> lowerScopeOccurrences = myScopeToAverageSeverityMap.get(myDefaultScopeName).getOccurrences();
|
||||
for (String toolName : toolsToCheck) {
|
||||
final HighlightSeverity currentToolSeverity = lowerScopeOccurrences.get(toolName);
|
||||
if (currentToolSeverity != null) {
|
||||
if (!currentSeverity.equals(currentToolSeverity)) {
|
||||
result.put(currentScope, ScopesAndSeveritiesTable.MIXED_FAKE_SEVERITY);
|
||||
doContinue = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (doContinue) {
|
||||
continue;
|
||||
}
|
||||
result.put(currentScope, currentSeverity);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public void put(final ScopeToolState defaultState, final Collection<ScopeToolState> nonDefault) {
|
||||
public void put(@NotNull final ScopeToolState defaultState, @NotNull final List<ScopeToolState> nonDefault) {
|
||||
putOne(defaultState);
|
||||
if (myDefaultScopeName == null) {
|
||||
myDefaultScopeName = defaultState.getScopeName();
|
||||
@@ -292,25 +386,19 @@ public class InspectionsConfigTreeTable extends TreeTable {
|
||||
for (final ScopeToolState scopeToolState : nonDefault) {
|
||||
putOne(scopeToolState);
|
||||
}
|
||||
if (myIsFirst) {
|
||||
myIsFirst = false;
|
||||
}
|
||||
}
|
||||
|
||||
private void putOne(final ScopeToolState state) {
|
||||
final Icon icon = state.getLevel().getIcon();
|
||||
final String scopeName = state.getScopeName();
|
||||
if (icon instanceof HighlightDisplayLevel.SingleColorIconWithMask) {
|
||||
if (myIsFirst) {
|
||||
myScopeToAverageSeverityMap.put(scopeName, state.getLevel().getSeverity());
|
||||
final SeverityAndOccurrences severityAndOccurrences = myScopeToAverageSeverityMap.get(scopeName);
|
||||
final String inspectionName = state.getTool().getShortName();
|
||||
if (severityAndOccurrences == null) {
|
||||
myScopeToAverageSeverityMap.put(scopeName, new SeverityAndOccurrences().incOccurrences(inspectionName, state.getLevel().getSeverity()));
|
||||
} else {
|
||||
final HighlightSeverity severity = myScopeToAverageSeverityMap.get(scopeName);
|
||||
if (!ScopesAndSeveritiesTable.MIXED_FAKE_SEVERITY.equals(severity) && !Comparing.equal(severity, state.getLevel().getSeverity())) {
|
||||
myScopeToAverageSeverityMap.put(scopeName, ScopesAndSeveritiesTable.MIXED_FAKE_SEVERITY);
|
||||
}
|
||||
severityAndOccurrences.incOccurrences(inspectionName, state.getLevel().getSeverity());
|
||||
}
|
||||
} else if (!ScopesAndSeveritiesTable.MIXED_FAKE_SEVERITY.equals(myScopeToAverageSeverityMap.get(scopeName))) {
|
||||
myScopeToAverageSeverityMap.put(scopeName, ScopesAndSeveritiesTable.MIXED_FAKE_SEVERITY);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+7
-2
@@ -78,8 +78,13 @@ public class ScopesAndSeveritiesTable extends JBTable {
|
||||
scopeEnabledColumn.setCellEditor(new ThreeStateCheckBoxRenderer());
|
||||
|
||||
final TableColumn severityColumn = columnModel.getColumn(SEVERITY_COLUMN);
|
||||
severityColumn.setCellRenderer(SeverityRenderer.create(tableSettings.getInspectionProfile()));
|
||||
severityColumn.setCellEditor(SeverityRenderer.create(tableSettings.getInspectionProfile()));
|
||||
severityColumn.setCellRenderer(SeverityRenderer.create(tableSettings.getInspectionProfile(), null));
|
||||
severityColumn.setCellEditor(SeverityRenderer.create(tableSettings.getInspectionProfile(), new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
tableSettings.onSettingsChanged();
|
||||
}
|
||||
}));
|
||||
|
||||
setColumnSelectionAllowed(false);
|
||||
setRowSelectionAllowed(true);
|
||||
|
||||
+16
-3
@@ -19,12 +19,14 @@ import com.intellij.codeHighlighting.HighlightDisplayLevel;
|
||||
import com.intellij.codeInspection.ex.InspectionProfileImpl;
|
||||
import com.intellij.lang.annotation.HighlightSeverity;
|
||||
import com.intellij.openapi.ui.ComboBoxTableRenderer;
|
||||
import com.intellij.openapi.ui.popup.LightweightWindowEvent;
|
||||
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 org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.event.MouseEvent;
|
||||
@@ -35,11 +37,14 @@ import java.util.SortedSet;
|
||||
* @author Dmitry Batkovich
|
||||
*/
|
||||
public class SeverityRenderer extends ComboBoxTableRenderer<SeverityState> {
|
||||
public SeverityRenderer(final SeverityState[] values) {
|
||||
private final Runnable myOnClose;
|
||||
|
||||
public SeverityRenderer(final SeverityState[] values, @Nullable final Runnable onClose) {
|
||||
super(values);
|
||||
myOnClose = onClose;
|
||||
}
|
||||
|
||||
public static SeverityRenderer create(final InspectionProfileImpl inspectionProfile) {
|
||||
public static SeverityRenderer create(final InspectionProfileImpl inspectionProfile, @Nullable final Runnable onClose) {
|
||||
final SortedSet<HighlightSeverity> severities =
|
||||
LevelChooserAction.getSeverities(((SeverityProvider)inspectionProfile.getProfileManager()).getOwnSeverityRegistrar());
|
||||
return new SeverityRenderer(ContainerUtil.map2Array(severities, new SeverityState[severities.size()], new Function<HighlightSeverity, SeverityState>() {
|
||||
@@ -47,7 +52,7 @@ public class SeverityRenderer extends ComboBoxTableRenderer<SeverityState> {
|
||||
public SeverityState fun(HighlightSeverity severity) {
|
||||
return new SeverityState(severity, true);
|
||||
}
|
||||
}));
|
||||
}), onClose);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -70,4 +75,12 @@ public class SeverityRenderer extends ComboBoxTableRenderer<SeverityState> {
|
||||
public boolean isCellEditable(final EventObject event) {
|
||||
return !(event instanceof MouseEvent) || ((MouseEvent)event).getClickCount() >= 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClosed(LightweightWindowEvent event) {
|
||||
super.onClosed(event);
|
||||
if (myOnClose != null) {
|
||||
myOnClose.run();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user