use of com.intellij.ui.ListSpeedSearch in project intellij-community by JetBrains.
the class ModuleAwareProjectConfigurable method createComponent.
@Override
public JComponent createComponent() {
if (myProject.isDefault()) {
T configurable = createDefaultProjectConfigurable();
if (configurable != null) {
myModuleConfigurables.put(null, configurable);
return configurable.createComponent();
}
}
final List<Module> modules = ContainerUtil.filter(ModuleAttachProcessor.getSortedModules(myProject), module -> isSuitableForModule(module));
final T projectConfigurable = createProjectConfigurable();
if (modules.size() == 1 && projectConfigurable == null) {
Module module = modules.get(0);
final T configurable = createModuleConfigurable(module);
myModuleConfigurables.put(module, configurable);
return configurable.createComponent();
}
final Splitter splitter = new Splitter(false, 0.25f);
CollectionListModel<Module> listDataModel = new CollectionListModel<>(modules);
final JBList moduleList = new JBList(listDataModel);
new ListSpeedSearch(moduleList, (Function<Object, String>) o -> {
if (o == null) {
return getProjectConfigurableItemName();
} else if (o instanceof Module) {
return ((Module) o).getName();
}
return null;
});
moduleList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
moduleList.setCellRenderer(new ModuleListCellRenderer() {
@Override
public void customize(JList list, Module module, int index, boolean selected, boolean hasFocus) {
if (module == null) {
setText(getProjectConfigurableItemName());
setIcon(getProjectConfigurableItemIcon());
} else {
super.customize(list, module, index, selected, hasFocus);
}
}
});
splitter.setFirstComponent(new JBScrollPane(moduleList));
final CardLayout layout = new CardLayout();
final JPanel cardPanel = new JPanel(layout);
splitter.setSecondComponent(cardPanel);
if (projectConfigurable != null) {
myModuleConfigurables.put(null, projectConfigurable);
final JComponent component = projectConfigurable.createComponent();
cardPanel.add(component, PROJECT_ITEM_KEY);
listDataModel.add(0, null);
}
for (Module module : modules) {
final T configurable = createModuleConfigurable(module);
myModuleConfigurables.put(module, configurable);
final JComponent component = configurable.createComponent();
cardPanel.add(component, module.getName());
}
moduleList.addListSelectionListener(new ListSelectionListener() {
@Override
public void valueChanged(ListSelectionEvent e) {
final Module value = (Module) moduleList.getSelectedValue();
layout.show(cardPanel, value == null ? PROJECT_ITEM_KEY : value.getName());
}
});
if (moduleList.getItemsCount() > 0) {
moduleList.setSelectedIndex(0);
Module module = listDataModel.getElementAt(0);
layout.show(cardPanel, module == null ? PROJECT_ITEM_KEY : module.getName());
}
return splitter;
}
use of com.intellij.ui.ListSpeedSearch 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);
}
}
}
Aggregations