use of com.intellij.ui.speedSearch.FilteringListModel in project intellij-community by JetBrains.
the class MasterDetailPopupBuilder method removeSelectedItems.
private void removeSelectedItems() {
if (myChooserComponent instanceof JList) {
JList list = (JList) myChooserComponent;
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();
}
}
use of com.intellij.ui.speedSearch.FilteringListModel in project android by JetBrains.
the class TreeGrid method setModel.
private void setModel(@NotNull AbstractTreeStructure model, boolean showSectionHeaders) {
// using the AbstractTreeStructure instead of the model as the actual TreeModel when used with IJ components
// works in a very strange way, each time you expand or contract a node it will add or remove all its children.
Object root = model.getRootElement();
Object[] sections = model.getChildElements(root);
mySectionToComponent.clear();
myLists.clear();
myHideables.clear();
removeAll();
setAutoscrolls(false);
ListSelectionListener listSelectionListener = e -> {
if (e.getValueIsAdjusting()) {
return;
}
ListSelectionModel sourceSelectionModel = (ListSelectionModel) e.getSource();
if (!sourceSelectionModel.isSelectionEmpty()) {
for (JList<T> aList : myLists) {
if (sourceSelectionModel != aList.getSelectionModel()) {
aList.clearSelection();
}
}
}
};
for (Object section : sections) {
String name = section.toString();
FilteringListModel<T> listModel = new FilteringListModel<>(new AbstractListModel() {
@Override
public int getSize() {
return model.getChildElements(section).length;
}
@Override
public Object getElementAt(int index) {
return model.getChildElements(section)[index];
}
});
// Needed as otherwise the filtered list does not show any content.
listModel.refilter();
// JBList does not work with HORIZONTAL_WRAP
//noinspection UndesirableClassUsage,unchecked
JList<T> list = new JList<>(listModel);
list.setAutoscrolls(false);
list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
list.setVisibleRowCount(-1);
list.getSelectionModel().addListSelectionListener(listSelectionListener);
// for tests to find the right list
list.setName(name);
list.addKeyListener(myKeyListener);
new ListSpeedSearch(list);
myLists.add(list);
if (showSectionHeaders) {
JPanel panel = new // must be BorderLayout for HideableDecorator to work
JPanel(// must be BorderLayout for HideableDecorator to work
new BorderLayout()) {
@Override
public Dimension getMaximumSize() {
return new Dimension(super.getMaximumSize().width, super.getPreferredSize().height);
}
};
HideableDecorator hidyPanel = new HideableDecorator(panel, name, false);
myHideables.add(hidyPanel);
hidyPanel.setContentComponent(list);
add(panel);
mySectionToComponent.put(section, panel);
} else {
if (getComponentCount() > 0) {
add(new JSeparator());
}
list.setMaximumSize(new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE));
add(list);
mySectionToComponent.put(section, list);
}
}
}
use of com.intellij.ui.speedSearch.FilteringListModel in project intellij-community by JetBrains.
the class ContentChooser method rebuildListContent.
private void rebuildListContent() {
ArrayList<Item> items = new ArrayList<>();
int i = 0;
List<Data> contents = new ArrayList<>(getContents());
for (Data content : contents) {
String longText = getStringRepresentationFor(content);
if (StringUtil.isEmpty(longText))
continue;
items.add(new Item(i++, longText));
}
myAllContents = contents;
FilteringListModel listModel = (FilteringListModel) myList.getModel();
((CollectionListModel) listModel.getOriginalModel()).removeAll();
listModel.addAll(items);
ListWithFilter listWithFilter = UIUtil.getParentOfType(ListWithFilter.class, myList);
if (listWithFilter != null) {
listWithFilter.getSpeedSearch().update();
if (listModel.getSize() == 0)
listWithFilter.resetFilter();
}
}
use of com.intellij.ui.speedSearch.FilteringListModel in project intellij-community by JetBrains.
the class BookmarksAction method notFiltered.
static boolean notFiltered(JList list) {
ListModel model1 = list.getModel();
if (!(model1 instanceof FilteringListModel))
return true;
final FilteringListModel model = (FilteringListModel) model1;
return model.getOriginalModel().getSize() == model.getSize();
}
Aggregations