Ejemplo n.º 1
0
 @TestOnly
 public boolean setSelectedTemplate(String group, String name) {
   ListModel model = myProjectTypeList.getModel();
   for (int i = 0; i < model.getSize(); i++) {
     TemplatesGroup templatesGroup = (TemplatesGroup) model.getElementAt(i);
     if (group.equals(templatesGroup.getName())) {
       myProjectTypeList.setSelectedIndex(i);
       if (name == null) return getSelectedGroup().getName().equals(group);
       Collection<ProjectTemplate> templates = myTemplatesMap.get(templatesGroup);
       setTemplatesList(templatesGroup, templates, false);
       return myTemplatesList.setSelectedTemplate(name);
     }
   }
   return false;
 }
Ejemplo n.º 2
0
 private MultiMap<String, ProjectTemplate> loadLocalTemplates() {
   ConcurrentMultiMap<String, ProjectTemplate> map =
       new ConcurrentMultiMap<String, ProjectTemplate>();
   ProjectTemplateEP[] extensions = ProjectTemplateEP.EP_NAME.getExtensions();
   for (ProjectTemplateEP ep : extensions) {
     ClassLoader classLoader = ep.getLoaderForClass();
     URL url = classLoader.getResource(ep.templatePath);
     if (url != null) {
       LocalArchivedTemplate template = new LocalArchivedTemplate(url, classLoader);
       if (ep.category) {
         TemplateBasedCategory category = new TemplateBasedCategory(template, ep.projectType);
         myTemplatesMap.putValue(new TemplatesGroup(category), template);
       } else {
         map.putValue(ep.projectType, template);
       }
     }
   }
   return map;
 }
Ejemplo n.º 3
0
 public Collection<ProjectTemplate> getAvailableTemplates() {
   if (myCurrentCard != FRAMEWORKS_CARD) {
     return Collections.emptyList();
   } else {
     Collection<ProjectTemplate> templates = myTemplatesMap.get(getSelectedGroup());
     List<FrameworkSupportNode> nodes = myFrameworksPanel.getSelectedNodes();
     if (nodes.isEmpty()) return templates;
     final List<String> selectedFrameworks = ContainerUtil.map(nodes, NODE_STRING_FUNCTION);
     return ContainerUtil.filter(
         templates,
         new Condition<ProjectTemplate>() {
           @Override
           public boolean value(ProjectTemplate template) {
             if (!(template instanceof ArchivedProjectTemplate)) return true;
             List<String> frameworks = ((ArchivedProjectTemplate) template).getFrameworks();
             return frameworks.containsAll(selectedFrameworks);
           }
         });
   }
 }
Ejemplo n.º 4
0
 private void showTemplates(TemplatesGroup group) {
   Collection<ProjectTemplate> templates = myTemplatesMap.get(group);
   setTemplatesList(group, templates, false);
   showCard(TEMPLATES_CARD);
 }
Ejemplo n.º 5
0
  private List<TemplatesGroup> fillTemplatesMap(WizardContext context) {

    List<ModuleBuilder> builders = ModuleBuilder.getAllBuilders();
    if (context.isCreatingNewProject()) {
      builders.add(new EmptyModuleBuilder());
    }
    Map<String, TemplatesGroup> groupMap = new HashMap<String, TemplatesGroup>();
    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<ProjectTemplate>());
      }
    }

    MultiMap<TemplatesGroup, ProjectTemplate> map = CreateFromTemplateMode.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<ProjectTemplate>());
    }

    if (context.isCreatingNewProject()) {
      MultiMap<String, ProjectTemplate> localTemplates = loadLocalTemplates();
      for (TemplatesGroup group : myTemplatesMap.keySet()) {
        myTemplatesMap.putValues(group, localTemplates.get(group.getId()));
      }
    }

    // remove Static Web group in IDEA Community if no specific templates found (IDEA-120593)
    if (PlatformUtils.isIdeaCommunity()) {
      for (TemplatesGroup group : myTemplatesMap.keySet()) {
        if (WebModuleTypeBase.WEB_MODULE.equals(group.getId())
            && myTemplatesMap.get(group).isEmpty()) {
          myTemplatesMap.remove(group);
          break;
        }
      }
    }

    List<TemplatesGroup> groups = new ArrayList<TemplatesGroup>(myTemplatesMap.keySet());

    // sorting by module type popularity
    final MultiMap<ModuleType, TemplatesGroup> moduleTypes =
        new MultiMap<ModuleType, TemplatesGroup>();
    for (TemplatesGroup group : groups) {
      ModuleType type = getModuleType(group);
      moduleTypes.putValue(type, group);
    }
    Collections.sort(
        groups,
        new Comparator<TemplatesGroup>() {
          @Override
          public int compare(TemplatesGroup o1, TemplatesGroup 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,
            new Function<TemplatesGroup, String>() {
              @Override
              public String fun(TemplatesGroup group) {
                return group.getParentGroup();
              }
            });

    // move subgroups
    MultiMap<String, TemplatesGroup> subGroups = new MultiMap<String, TemplatesGroup>();
    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);
      }
    }
    return groups;
  }
Ejemplo n.º 6
0
  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();
  }