Search in sources :

Example 6 with ProjectTemplate

use of com.intellij.platform.ProjectTemplate in project azure-tools-for-java by Microsoft.

the class HDInsightProjectTemplatesFactory method createTemplates.

@NotNull
@Override
public ProjectTemplate[] createTemplates(@Nullable String var1, WizardContext var2) {
    ArrayList<HDInsightTemplateItem> templateItems = HDInsightTemplates.getTemplates();
    int templateCount = templateItems.size();
    List<CustomHDInsightTemplateItem> customHDInsightTemplateItems = TemplatesUtil.getCustomTemplate();
    ProjectTemplate[] projectTemplates = new ProjectTemplate[templateCount + customHDInsightTemplateItems.size()];
    for (int i = 0; i < templateCount; i++) {
        projectTemplates[i] = new HDInsightProjectTemplate(templateItems.get(i));
    }
    for (int i = templateCount; i < templateCount + customHDInsightTemplateItems.size(); ++i) {
        projectTemplates[i] = new CustomProjectTemplate(customHDInsightTemplateItems.get(i - templateCount));
    }
    return projectTemplates;
}
Also used : CustomHDInsightTemplateItem(com.microsoft.azure.hdinsight.projects.template.CustomHDInsightTemplateItem) CustomProjectTemplate(com.microsoft.azure.hdinsight.projects.template.CustomProjectTemplate) CustomHDInsightTemplateItem(com.microsoft.azure.hdinsight.projects.template.CustomHDInsightTemplateItem) ProjectTemplate(com.intellij.platform.ProjectTemplate) CustomProjectTemplate(com.microsoft.azure.hdinsight.projects.template.CustomProjectTemplate) NotNull(org.jetbrains.annotations.NotNull)

Example 7 with ProjectTemplate

use of com.intellij.platform.ProjectTemplate 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)

Example 8 with ProjectTemplate

use of com.intellij.platform.ProjectTemplate in project intellij-community by JetBrains.

the class ProjectTypeStep method updateSelection.

private void updateSelection() {
    ProjectTemplate template = getSelectedTemplate();
    if (template != null) {
        myContext.setProjectTemplate(template);
    }
    ModuleBuilder builder = getSelectedBuilder();
    myContext.setProjectBuilder(builder);
    if (builder != null) {
        myWizard.getSequence().setType(builder.getBuilderId());
    }
    myWizard.setDelegate(builder instanceof WizardDelegate ? (WizardDelegate) builder : null);
    myWizard.updateWizardButtons();
}
Also used : ProjectTemplate(com.intellij.platform.ProjectTemplate)

Example 9 with ProjectTemplate

use of com.intellij.platform.ProjectTemplate in project intellij-community by JetBrains.

the class ProjectTypeStep method fillTemplatesMap.

private List<TemplatesGroup> fillTemplatesMap(WizardContext context) {
    List<ModuleBuilder> builders = ModuleBuilder.getAllBuilders();
    if (context.isCreatingNewProject()) {
        builders.add(new EmptyModuleBuilder());
    }
    Map<String, TemplatesGroup> groupMap = new HashMap<>();
    for (ModuleBuilder builder : builders) {
        BuilderBasedTemplate template = new BuilderBasedTemplate(builder);
        if (builder.isTemplate()) {
            TemplatesGroup group = groupMap.get(builder.getGroupName());
            if (group == null) {
                group = new TemplatesGroup(builder);
            }
            myTemplatesMap.putValue(group, template);
        } else {
            TemplatesGroup group = new TemplatesGroup(builder);
            groupMap.put(group.getName(), group);
            myTemplatesMap.put(group, new ArrayList<>());
        }
    }
    MultiMap<TemplatesGroup, ProjectTemplate> map = getTemplatesMap(context);
    myTemplatesMap.putAllValues(map);
    for (ProjectCategory category : ProjectCategory.EXTENSION_POINT_NAME.getExtensions()) {
        TemplatesGroup group = new TemplatesGroup(category);
        myTemplatesMap.remove(group);
        myTemplatesMap.put(group, new ArrayList<>());
    }
    if (context.isCreatingNewProject()) {
        MultiMap<String, ProjectTemplate> localTemplates = loadLocalTemplates();
        for (TemplatesGroup group : myTemplatesMap.keySet()) {
            myTemplatesMap.putValues(group, localTemplates.get(group.getId()));
        }
    }
    List<TemplatesGroup> groups = new ArrayList<>(myTemplatesMap.keySet());
    // sorting by module type popularity
    final MultiMap<ModuleType, TemplatesGroup> moduleTypes = new MultiMap<>();
    for (TemplatesGroup group : groups) {
        ModuleType type = getModuleType(group);
        moduleTypes.putValue(type, group);
    }
    Collections.sort(groups, (o1, o2) -> {
        int i = o2.getWeight() - o1.getWeight();
        if (i != 0)
            return i;
        int i1 = moduleTypes.get(getModuleType(o2)).size() - moduleTypes.get(getModuleType(o1)).size();
        if (i1 != 0)
            return i1;
        return o1.compareTo(o2);
    });
    Set<String> groupNames = ContainerUtil.map2Set(groups, TemplatesGroup::getParentGroup);
    // move subgroups
    MultiMap<String, TemplatesGroup> subGroups = new MultiMap<>();
    for (ListIterator<TemplatesGroup> iterator = groups.listIterator(); iterator.hasNext(); ) {
        TemplatesGroup group = iterator.next();
        String parentGroup = group.getParentGroup();
        if (parentGroup != null && groupNames.contains(parentGroup) && !group.getName().equals(parentGroup) && groupMap.containsKey(parentGroup)) {
            subGroups.putValue(parentGroup, group);
            iterator.remove();
        }
    }
    for (ListIterator<TemplatesGroup> iterator = groups.listIterator(); iterator.hasNext(); ) {
        TemplatesGroup group = iterator.next();
        for (TemplatesGroup subGroup : subGroups.get(group.getName())) {
            iterator.add(subGroup);
        }
    }
    // remove Static Web group in IDEA Community if no specific templates found (IDEA-120593)
    if (PlatformUtils.isIdeaCommunity()) {
        for (ListIterator<TemplatesGroup> iterator = groups.listIterator(); iterator.hasNext(); ) {
            TemplatesGroup group = iterator.next();
            if (WebModuleTypeBase.WEB_MODULE.equals(group.getId()) && myTemplatesMap.get(group).isEmpty()) {
                iterator.remove();
                break;
            }
        }
    }
    return groups;
}
Also used : THashMap(gnu.trove.THashMap) HashMap(java.util.HashMap) ModuleType(com.intellij.openapi.module.ModuleType) ProjectTemplate(com.intellij.platform.ProjectTemplate)

Aggregations

ProjectTemplate (com.intellij.platform.ProjectTemplate)9 ArchivedProjectTemplate (com.intellij.platform.templates.ArchivedProjectTemplate)2 URL (java.net.URL)2 NotNull (org.jetbrains.annotations.NotNull)2 CommitStepException (com.intellij.ide.wizard.CommitStepException)1 ModuleType (com.intellij.openapi.module.ModuleType)1 ConfigurationException (com.intellij.openapi.options.ConfigurationException)1 ProjectTemplateEP (com.intellij.platform.ProjectTemplateEP)1 ProjectTemplatesFactory (com.intellij.platform.ProjectTemplatesFactory)1 CollectionListModel (com.intellij.ui.CollectionListModel)1 CustomHDInsightTemplateItem (com.microsoft.azure.hdinsight.projects.template.CustomHDInsightTemplateItem)1 CustomProjectTemplate (com.microsoft.azure.hdinsight.projects.template.CustomProjectTemplate)1 THashMap (gnu.trove.THashMap)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 ListSelectionEvent (javax.swing.event.ListSelectionEvent)1 ListSelectionListener (javax.swing.event.ListSelectionListener)1