Search in sources :

Example 1 with FilteringListModel

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();
    }
}
Also used : FilteringListModel(com.intellij.ui.speedSearch.FilteringListModel) FilteringListModel(com.intellij.ui.speedSearch.FilteringListModel)

Example 2 with FilteringListModel

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);
        }
    }
}
Also used : UIUtil(com.intellij.util.ui.UIUtil) KeyListener(java.awt.event.KeyListener) IdentityHashMap(java.util.IdentityHashMap) ModalityState(com.intellij.openapi.application.ModalityState) ContainerUtil(com.intellij.util.containers.ContainerUtil) KeyAdapter(java.awt.event.KeyAdapter) KeyEvent(java.awt.event.KeyEvent) ArrayList(java.util.ArrayList) TestOnly(org.jetbrains.annotations.TestOnly) java.awt(java.awt) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) Map(java.util.Map) AbstractTreeStructure(com.intellij.ide.util.treeView.AbstractTreeStructure) ApplicationManager(com.intellij.openapi.application.ApplicationManager) FilteringListModel(com.intellij.ui.speedSearch.FilteringListModel) NotNull(org.jetbrains.annotations.NotNull) ListSelectionListener(javax.swing.event.ListSelectionListener) MouseListener(java.awt.event.MouseListener) Condition(com.intellij.openapi.util.Condition) HideableDecorator(com.intellij.ui.HideableDecorator) ListSpeedSearch(com.intellij.ui.ListSpeedSearch) javax.swing(javax.swing) FilteringListModel(com.intellij.ui.speedSearch.FilteringListModel) HideableDecorator(com.intellij.ui.HideableDecorator) ListSelectionListener(javax.swing.event.ListSelectionListener) ListSpeedSearch(com.intellij.ui.ListSpeedSearch)

Example 3 with FilteringListModel

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();
    }
}
Also used : ListWithFilter(com.intellij.ui.speedSearch.ListWithFilter) ArrayList(java.util.ArrayList) FilteringListModel(com.intellij.ui.speedSearch.FilteringListModel) SplitterProportionsData(com.intellij.openapi.ui.SplitterProportionsData)

Example 4 with FilteringListModel

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();
}
Also used : FilteringListModel(com.intellij.ui.speedSearch.FilteringListModel) FilteringListModel(com.intellij.ui.speedSearch.FilteringListModel)

Aggregations

FilteringListModel (com.intellij.ui.speedSearch.FilteringListModel)4 ArrayList (java.util.ArrayList)2 AbstractTreeStructure (com.intellij.ide.util.treeView.AbstractTreeStructure)1 ApplicationManager (com.intellij.openapi.application.ApplicationManager)1 ModalityState (com.intellij.openapi.application.ModalityState)1 SplitterProportionsData (com.intellij.openapi.ui.SplitterProportionsData)1 Condition (com.intellij.openapi.util.Condition)1 HideableDecorator (com.intellij.ui.HideableDecorator)1 ListSpeedSearch (com.intellij.ui.ListSpeedSearch)1 ListWithFilter (com.intellij.ui.speedSearch.ListWithFilter)1 ContainerUtil (com.intellij.util.containers.ContainerUtil)1 UIUtil (com.intellij.util.ui.UIUtil)1 java.awt (java.awt)1 KeyAdapter (java.awt.event.KeyAdapter)1 KeyEvent (java.awt.event.KeyEvent)1 KeyListener (java.awt.event.KeyListener)1 MouseListener (java.awt.event.MouseListener)1 IdentityHashMap (java.util.IdentityHashMap)1 List (java.util.List)1 Map (java.util.Map)1