IDEA-372145 [java] NullableAnnotationsPanel improvements

1. Add new annotation after selection
2. Use model to retrieve values to be robust against column reordering
3. Request focus after adding a row
4. Scroll to visible when annotation is already present

GitOrigin-RevId: e9bdae0993580fd83abb612097183b8e84e914ec
This commit is contained in:
Tagir Valeev
2025-12-01 19:48:04 +00:00
committed by intellij-monorepo-bot
parent 67d404a6f3
commit 57182897f5
@@ -232,13 +232,19 @@ public class NullableAnnotationsPanel {
}
private void addRow(String annotation, boolean checked) {
myTableModel.addRow(new Object[]{annotation, checked});
int row = myTable == null ? -1 : myTable.getSelectedRow();
if (row == -1) {
myTableModel.addRow(new Object[]{annotation, checked});
} else {
myTableModel.insertRow(row + 1, new Object[]{annotation, checked});
}
}
private Integer selectAnnotation(String annotation) {
for (int i = 0; i < myTable.getRowCount(); i++) {
if (annotation.equals(myTable.getValueAt(i, 0))) {
for (int i = 0; i < myTableModel.getRowCount(); i++) {
if (annotation.equals(myTableModel.getValueAt(i, 0))) {
myTable.setRowSelectionInterval(i, i);
myTable.scrollRectToVisible(myTable.getCellRect(i, 0, true));
return i;
}
}
@@ -247,7 +253,7 @@ public class NullableAnnotationsPanel {
private @NlsSafe String getSelectedAnnotation() {
int selectedRow = myTable.getSelectedRow();
return selectedRow < 0 ? null : (String)myTable.getValueAt(selectedRow, 0);
return selectedRow < 0 ? null : (String)myTableModel.getValueAt(selectedRow, 0);
}
private void chooseAnnotation(@NlsSafe String title) {
@@ -265,7 +271,7 @@ public class NullableAnnotationsPanel {
addAnnotationToCombo(qualifiedName);
Object added = selectAnnotation(qualifiedName);
assert added != null;
myTable.scrollRectToVisible(myTable.getCellRect((int)added, 0, true));
myTable.requestFocus();
}
}
@@ -286,19 +292,19 @@ public class NullableAnnotationsPanel {
}
public String[] getAnnotations() {
int size = myTable.getRowCount();
int size = myTableModel.getRowCount();
String[] result = new String[size];
for (int i = 0; i < size; i++) {
result[i] = (String)myTable.getValueAt(i, 0);
result[i] = (String)myTableModel.getValueAt(i, 0);
}
return result;
}
List<String> getCheckedAnnotations() {
List<String> result = new ArrayList<>();
for (int i = 0; i < myTable.getRowCount(); i++) {
if (Boolean.TRUE.equals(myTable.getValueAt(i, 1))) {
result.add((String)myTable.getValueAt(i, 0));
for (int i = 0; i < myTableModel.getRowCount(); i++) {
if (Boolean.TRUE.equals(myTableModel.getValueAt(i, 1))) {
result.add((String)myTableModel.getValueAt(i, 0));
}
}
return result;