Search in sources :

Example 6 with CollectionListModel

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());
            }
        }
    });
}
Also used : ListSelectionEvent(javax.swing.event.ListSelectionEvent) CollectionListModel(com.intellij.ui.CollectionListModel) ProjectTemplate(com.intellij.platform.ProjectTemplate) ArchivedProjectTemplate(com.intellij.platform.templates.ArchivedProjectTemplate) ListSelectionListener(javax.swing.event.ListSelectionListener)

Aggregations

CollectionListModel (com.intellij.ui.CollectionListModel)6 JBList (com.intellij.ui.components.JBList)4 NotNull (org.jetbrains.annotations.NotNull)3 JBPopup (com.intellij.openapi.ui.popup.JBPopup)2 List (java.util.List)2 javax.swing (javax.swing)2 Nullable (org.jetbrains.annotations.Nullable)2 GotoImplementationHandler (com.intellij.codeInsight.navigation.GotoImplementationHandler)1 GotoTargetHandler (com.intellij.codeInsight.navigation.GotoTargetHandler)1 ListBackgroundUpdaterTask (com.intellij.codeInsight.navigation.ListBackgroundUpdaterTask)1 ScopeHighlighter (com.intellij.codeInsight.unwrap.ScopeHighlighter)1 FindUtil (com.intellij.find.FindUtil)1 AllIcons (com.intellij.icons.AllIcons)1 PsiCopyPasteManager (com.intellij.ide.PsiCopyPasteManager)1 PsiElementListCellRenderer (com.intellij.ide.util.PsiElementListCellRenderer)1 Logger (com.intellij.openapi.diagnostic.Logger)1 Editor (com.intellij.openapi.editor.Editor)1 EditorUtil (com.intellij.openapi.editor.ex.util.EditorUtil)1 Module (com.intellij.openapi.module.Module)1 Configurable (com.intellij.openapi.options.Configurable)1