mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
list model editor: respect isRemovable
This commit is contained in:
@@ -25,6 +25,7 @@ import gnu.trove.TObjectObjectProcedure;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class CollectionModelEditor<T, E extends CollectionItemEditor<T>> implements ElementProducer<T> {
|
||||
@@ -146,4 +147,20 @@ public abstract class CollectionModelEditor<T, E extends CollectionItemEditor<T>
|
||||
modifiedToOriginal.forEachEntry(procedure);
|
||||
}
|
||||
}
|
||||
|
||||
protected final boolean areSelectedItemsRemovable(@NotNull ListSelectionModel selectionMode) {
|
||||
int minSelectionIndex = selectionMode.getMinSelectionIndex();
|
||||
int maxSelectionIndex = selectionMode.getMaxSelectionIndex();
|
||||
if (minSelectionIndex < 0 || maxSelectionIndex < 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
List<T> items = getItems();
|
||||
for (int i = minSelectionIndex; i <= maxSelectionIndex; i++) {
|
||||
if (itemEditor.isRemovable(items.get(i))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package com.intellij.util.ui;
|
||||
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
import com.intellij.ui.*;
|
||||
import com.intellij.ui.components.JBList;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
@@ -35,7 +36,7 @@ public class ListModelEditor<T> extends ListModelEditorBase<T> {
|
||||
list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
||||
list.setCellRenderer(new MyListCellRenderer());
|
||||
|
||||
toolbarDecorator = ToolbarDecorator.createDecorator(list)
|
||||
toolbarDecorator = ToolbarDecorator.createDecorator(list, model)
|
||||
.setAddAction(new AnActionButtonRunnable() {
|
||||
@Override
|
||||
public void run(AnActionButton button) {
|
||||
@@ -51,7 +52,13 @@ public class ListModelEditor<T> extends ListModelEditorBase<T> {
|
||||
model.add(item);
|
||||
ListScrollingUtil.selectItem(list, ContainerUtil.indexOfIdentity(model.getItems(), item));
|
||||
}
|
||||
});
|
||||
})
|
||||
.setRemoveActionUpdater(new AnActionButtonUpdater() {
|
||||
@Override
|
||||
public boolean isEnabled(AnActionEvent e) {
|
||||
return areSelectedItemsRemovable(list.getSelectionModel());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -365,12 +365,7 @@ public class TableModelEditor<T> extends CollectionModelEditor<T, CollectionItem
|
||||
|
||||
@Override
|
||||
public boolean isEnabled(AnActionEvent e) {
|
||||
for (T item : table.getSelectedObjects()) {
|
||||
if (itemEditor.isRemovable(item)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
return areSelectedItemsRemovable(table.getSelectionModel());
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user