private void removeSelectedItems() {
    if (myChooserComponent instanceof JList list) {
      ListModel listModel = list.getModel();

      int index = list.getSelectedIndex();
      if (index == -1 || index >= listModel.getSize()) {
        return;
      }

      @SuppressWarnings("deprecation") Object[] values = list.getSelectedValues();
      for (Object value : values) {
        ItemWrapper item = (ItemWrapper)value;
        if (item.allowedToRemove()) {
          DefaultListModel model = listModel instanceof DefaultListModel ?
                                   (DefaultListModel)listModel :
                                   (DefaultListModel)((FilteringListModel)listModel).getOriginalModel();

          model.removeElement(item);

          if (model.getSize() > 0) {
            if (model.getSize() == index) {
              list.setSelectedIndex(model.getSize() - 1);
            }
            else if (model.getSize() > index) {
              list.setSelectedIndex(index);
            }
          }
          else {
            list.clearSelection();
          }

          item.removed(myProject);
        }
      }
    }
    else {
      myDelegate.removeSelectedItemsInTree();
    }
  }
private void removeSelectedItems()