protected void setSelectedRoots(Object[] roots) { ArrayList<Object> rootsList = new ArrayList<Object>(roots.length); for (Object root : roots) { if (root != null) { rootsList.add(root); } } myList.getSelectionModel().clearSelection(); int rowCount = getRowCount(); for (int i = 0; i < rowCount; i++) { Object currObject = getValueAt(i); LOG.assertTrue(currObject != null); if (rootsList.contains(currObject)) { myList.getSelectionModel().addSelectionInterval(i, i); } } }
public SelectTemplateStep( WizardContext context, StepSequence sequence, final MultiMap<TemplatesGroup, ProjectTemplate> map) { myWizardContext = context; mySequence = sequence; Messages.installHyperlinkSupport(myDescriptionPane); myFormatPanel = new ProjectFormatPanel(); myNamePathComponent = initNamePathComponent(context); if (context.isCreatingNewProject()) { mySettingsPanel.add(myNamePathComponent, BorderLayout.NORTH); addExpertPanel(myModulePanel); } else { mySettingsPanel.add(myModulePanel, BorderLayout.NORTH); } bindModuleSettings(); myExpertDecorator = new HideableDecorator(myExpertPlaceholder, "Mor&e Settings", false); myExpertPanel.setBorder( IdeBorderFactory.createEmptyBorder(0, IdeBorderFactory.TITLED_BORDER_INDENT, 5, 0)); myExpertDecorator.setContentComponent(myExpertPanel); myList = new ProjectTypesList(myTemplatesList, map, context); myList.installKeyAction(getNameComponent()); myTemplatesList .getSelectionModel() .addListSelectionListener( new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { ProjectTemplate template = getSelectedTemplate(); boolean loading = template instanceof LoadingProjectTemplate; myModuleBuilder = template == null || loading ? null : template.createModuleBuilder(); setupPanels(template); mySequence.setType(myModuleBuilder == null ? null : myModuleBuilder.getBuilderId()); myWizardContext.requestWizardButtonsUpdate(); } }); if (myWizardContext.isCreatingNewProject()) { addProjectFormat(myModulePanel); } }
@Override protected JComponent createCenterPanel() { myJBList = new JBList(mySettings); myJBList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); myJBList .getSelectionModel() .addListSelectionListener( new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { Object selectedValue = myJBList.getSelectedValue(); if (selectedValue instanceof RunnerAndConfigurationSettings) { mySelectedSettings = (RunnerAndConfigurationSettings) selectedValue; } else { mySelectedSettings = null; } setOKActionEnabled(mySelectedSettings != null); } }); myJBList.setCellRenderer( new ColoredListCellRenderer() { @Override protected void customizeCellRenderer( JList list, Object value, int index, boolean selected, boolean hasFocus) { if (value instanceof RunnerAndConfigurationSettings) { RunnerAndConfigurationSettings settings = (RunnerAndConfigurationSettings) value; RunManagerEx runManager = RunManagerEx.getInstanceEx(myProject); setIcon(runManager.getConfigurationIcon(settings)); RunConfiguration configuration = settings.getConfiguration(); append( configuration.getName(), settings.isTemporary() ? SimpleTextAttributes.GRAY_ATTRIBUTES : SimpleTextAttributes.REGULAR_ATTRIBUTES); } } }); return new JBScrollPane(myJBList); }
public ProjectTypeStep( WizardContext context, NewProjectWizard wizard, ModulesProvider modulesProvider) { myContext = context; myWizard = wizard; myTemplatesMap = new ConcurrentMultiMap<TemplatesGroup, ProjectTemplate>(); final List<TemplatesGroup> groups = fillTemplatesMap(context); myProjectTypeList.setModel(new CollectionListModel<TemplatesGroup>(groups)); myProjectTypeList.setSelectionModel(new SingleSelectionModel()); myProjectTypeList.addListSelectionListener( new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { updateSelection(); } }); myProjectTypeList.setCellRenderer( new GroupedItemsListRenderer( new ListItemDescriptorAdapter<TemplatesGroup>() { @Nullable @Override public String getTextFor(TemplatesGroup value) { return value.getName(); } @Nullable @Override public String getTooltipFor(TemplatesGroup value) { return value.getDescription(); } @Nullable @Override public Icon getIconFor(TemplatesGroup value) { return value.getIcon(); } @Override public boolean hasSeparatorAboveOf(TemplatesGroup value) { int index = groups.indexOf(value); if (index < 1) return false; TemplatesGroup upper = groups.get(index - 1); if (upper.getParentGroup() == null && value.getParentGroup() == null) return true; return !Comparing.equal(upper.getParentGroup(), value.getParentGroup()) && !Comparing.equal(upper.getName(), value.getParentGroup()); } }) { @Override protected JComponent createItemComponent() { JComponent component = super.createItemComponent(); myTextLabel.setBorder(IdeBorderFactory.createEmptyBorder(3)); return component; } }); new ListSpeedSearch(myProjectTypeList) { @Override protected String getElementText(Object element) { return ((TemplatesGroup) element).getName(); } }; myModulesProvider = modulesProvider; Project project = context.getProject(); final LibrariesContainer container = LibrariesContainerFactory.createContainer(context, modulesProvider); FrameworkSupportModelBase model = new FrameworkSupportModelBase(project, null, container) { @NotNull @Override public String getBaseDirectoryForLibrariesPath() { ModuleBuilder builder = getSelectedBuilder(); return StringUtil.notNullize(builder.getContentEntryPath()); } @Override public ModuleBuilder getModuleBuilder() { return getSelectedBuilder(); } }; myFrameworksPanel = new AddSupportForFrameworksPanel( Collections.<FrameworkSupportInModuleProvider>emptyList(), model, true, myHeaderPanel); Disposer.register(this, myFrameworksPanel); myFrameworksPanelPlaceholder.add(myFrameworksPanel.getMainPanel()); myConfigurationUpdater = new ModuleBuilder.ModuleConfigurationUpdater() { @Override public void update(@NotNull Module module, @NotNull ModifiableRootModel rootModel) { if (isFrameworksMode()) { myFrameworksPanel.addSupport(module, rootModel); } } }; myProjectTypeList .getSelectionModel() .addListSelectionListener( new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { projectTypeChanged(); } }); myTemplatesList.addListSelectionListener( new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { updateSelection(); } }); for (TemplatesGroup templatesGroup : myTemplatesMap.keySet()) { ModuleBuilder builder = templatesGroup.getModuleBuilder(); if (builder != null) { myWizard.getSequence().addStepsForBuilder(builder, context, modulesProvider); } for (ProjectTemplate template : myTemplatesMap.get(templatesGroup)) { myWizard .getSequence() .addStepsForBuilder(myBuilders.get(template), context, modulesProvider); } } final String groupId = PropertiesComponent.getInstance().getValue(PROJECT_WIZARD_GROUP); if (groupId != null) { TemplatesGroup group = ContainerUtil.find( groups, new Condition<TemplatesGroup>() { @Override public boolean value(TemplatesGroup group) { return groupId.equals(group.getId()); } }); if (group != null) { myProjectTypeList.setSelectedValue(group, true); } } if (myProjectTypeList.getSelectedValue() == null) { myProjectTypeList.setSelectedIndex(0); } myTemplatesList.restoreSelection(); }
private void initLeftPanel() { myLeftPanel = new JPanel(new GridLayoutManager(2, 1, JBInsets.NONE, -1, -1)); mySearchField = new SearchTextField(false); mySearchField.addDocumentListener( new DocumentAdapter() { @Override protected void textChanged(DocumentEvent e) { TemplateItem tmp = myCurrentTemplateItem; myFilteringListModel.refilter(); int idx = myFilteringListModel.getElementIndex(tmp); myList.setSelectedIndex(idx < 0 ? 0 : idx); } }); new AnAction() { @Override public void actionPerformed(AnActionEvent e) { InputEvent event = e.getInputEvent(); if (event instanceof KeyEvent) { int row = myList.getSelectedIndex(); int toSelect; switch (((KeyEvent) event).getKeyCode()) { case KeyEvent.VK_UP: toSelect = row == 0 ? myList.getItemsCount() - 1 : row - 1; myList.setSelectedIndex(toSelect); myList.ensureIndexIsVisible(toSelect); break; case KeyEvent.VK_DOWN: toSelect = row < myList.getItemsCount() - 1 ? row + 1 : 0; myList.setSelectedIndex(toSelect); myList.ensureIndexIsVisible(toSelect); break; } } } }.registerCustomShortcutSet( new CustomShortcutSet(KeyEvent.VK_UP, KeyEvent.VK_DOWN), mySearchField); myLeftPanel.add( mySearchField, new GridConstraints( 0, 0, 1, 1, GridConstraints.ANCHOR_NORTHWEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_CAN_SHRINK, GridConstraints.SIZEPOLICY_FIXED, null, null, null)); myList = new JBList(); List<ProjectTemplatesGroup> templatesGroups = new SortedList<ProjectTemplatesGroup>( new Comparator<ProjectTemplatesGroup>() { @Override public int compare(ProjectTemplatesGroup o1, ProjectTemplatesGroup o2) { // Put DSL/Development groups on top & Other group to the last place if (o1.getName().equals("DSL")) return -1; if (o2.getName().equals("DSL")) return 1; if (o1.getName().equals("Development")) return -1; if (o2.getName().equals("Development")) return 1; if (o1.getName().equals("Other")) return 1; if (o2.getName().equals("Other")) return -1; return o1.getName().compareToIgnoreCase(o2.getName()); } }); List<TemplateItem> templateItems = new LinkedList<TemplateItem>(); templatesGroups.addAll(Arrays.asList(ProjectTemplatesGroup.EP_NAME.getExtensions())); for (ProjectTemplatesGroup templatesGroup : templatesGroups) { for (MPSProjectTemplate template : templatesGroup.getTemplates()) { templateItems.add(new TemplateItem(template, templatesGroup)); } } CollectionListModel<TemplateItem> model = new CollectionListModel<TemplateItem>(templateItems); myFilteringListModel = new FilteringListModel<TemplateItem>(model); myFilteringListModel.setFilter( new Condition<TemplateItem>() { @Override public boolean value(TemplateItem templateItem) { return templateItem .getName() .toLowerCase() .contains(mySearchField.getText().trim().toLowerCase()); } }); myList.setModel(myFilteringListModel); myList.setCellRenderer( new GroupedItemsListRenderer( new ListItemDescriptor() { @Nullable @Override public String getTextFor(Object value) { return ((TemplateItem) value).getName(); } @Nullable @Override public String getTooltipFor(Object value) { return null; } @Nullable @Override public Icon getIconFor(Object value) { return ((TemplateItem) value).getIcon(); } @Override public boolean hasSeparatorAboveOf(Object value) { TemplateItem item = (TemplateItem) value; int index = myFilteringListModel.getElementIndex(item); return index == 0 || !myFilteringListModel .getElementAt(index - 1) .getGroupName() .equals(item.getGroupName()); } @Nullable @Override public String getCaptionAboveOf(Object value) { return ((TemplateItem) value).getGroupName(); } })); myList .getSelectionModel() .addListSelectionListener( new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { myCurrentTemplateItem = (TemplateItem) myList.getSelectedValue(); updateRightPanel(); } }); myLeftPanel.add( ScrollPaneFactory.createScrollPane(myList), new GridConstraints( 1, 0, 1, 1, GridConstraints.ANCHOR_NORTHWEST, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK, GridConstraints.SIZEPOLICY_CAN_GROW | GridConstraints.SIZEPOLICY_CAN_SHRINK, null, null, null)); myLeftPanel.setPreferredSize(new Dimension(200, 400)); }