use of com.intellij.ui.CollectionListModel 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.CollectionListModel in project intellij-community by JetBrains.
the class PsiElementListNavigator method navigateOrCreatePopup.
/**
* listUpdaterTask should be started after alarm is initialized so one-item popup won't blink
*/
@Nullable
public static JBPopup navigateOrCreatePopup(@NotNull final NavigatablePsiElement[] targets, final String title, final String findUsagesTitle, final ListCellRenderer listRenderer, @Nullable final ListBackgroundUpdaterTask listUpdaterTask, @NotNull final Consumer<Object[]> consumer) {
if (targets.length == 0)
return null;
if (targets.length == 1 && (listUpdaterTask == null || listUpdaterTask.isFinished())) {
consumer.consume(targets);
return null;
}
final CollectionListModel<NavigatablePsiElement> model = new CollectionListModel<>(targets);
final JBList list = new JBList(model);
HintUpdateSupply.installSimpleHintUpdateSupply(list);
list.setTransferHandler(new TransferHandler() {
@Nullable
@Override
protected Transferable createTransferable(JComponent c) {
final Object[] selectedValues = list.getSelectedValues();
final PsiElement[] copy = new PsiElement[selectedValues.length];
for (int i = 0; i < selectedValues.length; i++) {
copy[i] = (PsiElement) selectedValues[i];
}
return new PsiCopyPasteManager.MyTransferable(copy);
}
@Override
public int getSourceActions(JComponent c) {
return COPY;
}
});
list.setCellRenderer(listRenderer);
list.setFont(EditorUtil.getEditorFont());
final PopupChooserBuilder builder = new PopupChooserBuilder(list);
if (listRenderer instanceof PsiElementListCellRenderer) {
((PsiElementListCellRenderer) listRenderer).installSpeedSearch(builder);
}
PopupChooserBuilder popupChooserBuilder = builder.setTitle(title).setMovable(true).setResizable(true).setItemChoosenCallback(() -> {
int[] ids = list.getSelectedIndices();
if (ids == null || ids.length == 0)
return;
Object[] selectedElements = list.getSelectedValues();
consumer.consume(selectedElements);
}).setCancelCallback(() -> {
HintUpdateSupply.hideHint(list);
if (listUpdaterTask != null) {
listUpdaterTask.cancelTask();
}
return true;
});
final Ref<UsageView> usageView = new Ref<>();
if (findUsagesTitle != null) {
popupChooserBuilder = popupChooserBuilder.setCouldPin(popup -> {
final List<NavigatablePsiElement> items = model.getItems();
usageView.set(FindUtil.showInUsageView(null, items.toArray(new PsiElement[items.size()]), findUsagesTitle, targets[0].getProject()));
popup.cancel();
return false;
});
}
final JBPopup popup = popupChooserBuilder.createPopup();
builder.getScrollPane().setBorder(null);
builder.getScrollPane().setViewportBorder(null);
if (listUpdaterTask != null) {
listUpdaterTask.init((AbstractPopup) popup, list, usageView);
}
return popup;
}
use of com.intellij.ui.CollectionListModel in project intellij-community by JetBrains.
the class CodeInsightTestUtil method gotoImplementation.
@NotNull
@TestOnly
public static GotoTargetHandler.GotoData gotoImplementation(Editor editor, PsiFile file) {
GotoTargetHandler.GotoData data = new GotoImplementationHandler().getSourceAndTargetElements(editor, file);
if (data.listUpdaterTask != null) {
JBList list = new JBList();
CollectionListModel model = new CollectionListModel(new ArrayList());
list.setModel(model);
list.setModel(new NameFilteringListModel(list, Function.ID, Condition.FALSE, String::new));
JBPopup popup = new ComponentPopupBuilderImpl(list, null).createPopup();
data.listUpdaterTask.init((AbstractPopup) popup, list, new Ref<>());
data.listUpdaterTask.queue();
try {
while (!data.listUpdaterTask.isFinished()) {
UIUtil.dispatchAllInvocationEvents();
}
} finally {
Disposer.dispose(popup);
}
}
return data;
}
use of com.intellij.ui.CollectionListModel in project intellij-community by JetBrains.
the class ProjectTemplateList method restoreSelection.
void restoreSelection() {
final String templateName = PropertiesComponent.getInstance().getValue(PROJECT_WIZARD_TEMPLATE);
if (templateName != null && myList.getModel() instanceof CollectionListModel) {
@SuppressWarnings("unchecked") List<ProjectTemplate> list = ((CollectionListModel<ProjectTemplate>) myList.getModel()).toList();
ProjectTemplate template = ContainerUtil.find(list, template1 -> templateName.equals(template1.getName()));
if (template != null) {
myList.setSelectedValue(template, true);
}
}
myList.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
@Override
public void valueChanged(ListSelectionEvent e) {
ProjectTemplate template = getSelectedTemplate();
if (template != null) {
PropertiesComponent.getInstance().setValue(PROJECT_WIZARD_TEMPLATE, template.getName());
}
}
});
}
use of com.intellij.ui.CollectionListModel in project intellij-community by JetBrains.
the class SelectPluginsStep method fillPlugins.
public void fillPlugins() {
Collections.sort(myPlugins, (o1, o2) -> StringUtil.compare(o1.getName(), o2.getName(), true));
myPluginsList.setModel(new CollectionListModel(myPlugins));
myPluginsList.setSelectedIndex(0);
}
Aggregations