private void sortFrameworks(final List<FrameworkSupportNode> nodes) {
   final Comparator<FrameworkSupportInModuleProvider> comparator =
       FrameworkSupportUtil.getFrameworkSupportProvidersComparator(myProviders);
   Collections.sort(
       nodes,
       new Comparator<FrameworkSupportNode>() {
         public int compare(final FrameworkSupportNode o1, final FrameworkSupportNode o2) {
           return comparator.compare(o1.getUserObject(), o2.getUserObject());
         }
       });
 }
 @Nullable
 private FrameworkSupportNode createNode(
     final FrameworkSupportInModuleProvider provider,
     final Map<String, FrameworkSupportNode> nodes,
     final Map<FrameworkGroup<?>, FrameworkGroupNode> groupNodes,
     List<FrameworkSupportNodeBase> roots,
     List<FrameworkSupportInModuleProvider> providers,
     Set<String> associated,
     Map<String, FrameworkSupportNodeBase> associatedNodes) {
   String id = provider.getFrameworkType().getId();
   FrameworkSupportNode node = nodes.get(id);
   if (node != null || associatedNodes.containsKey(id)) {
     return node;
   }
   String underlyingTypeId = provider.getFrameworkType().getUnderlyingFrameworkTypeId();
   FrameworkSupportNodeBase parentNode = null;
   final FrameworkGroup<?> group = provider.getFrameworkType().getParentGroup();
   if (underlyingTypeId != null) {
     FrameworkSupportInModuleProvider parentProvider =
         FrameworkSupportUtil.findProvider(underlyingTypeId, providers);
     if (parentProvider == null) {
       LOG.info("Cannot find id = " + underlyingTypeId);
       return null;
     }
     parentNode =
         createNode(
             parentProvider, nodes, groupNodes, roots, providers, associated, associatedNodes);
   } else if (group != null) {
     parentNode = groupNodes.get(group);
     if (parentNode == null) {
       FrameworkGroupNode groupNode = new FrameworkGroupNode(group, null);
       if (associated.contains(groupNode.getId())) {
         associatedNodes.put(groupNode.getId(), groupNode);
       } else {
         groupNodes.put(group, groupNode);
         parentNode = groupNode;
         roots.add(groupNode);
       }
     }
   }
   node = new FrameworkSupportNode(provider, parentNode, myModel, this);
   if (associated.contains(id)) {
     associatedNodes.put(id, node);
   } else {
     nodes.put(id, node);
     if (parentNode == null) {
       roots.add(node);
     }
   }
   return node;
 }
 @Override
 public ModuleWizardStep createSupportForFrameworksStep(
     @NotNull WizardContext context,
     @NotNull ModuleBuilder builder,
     @NotNull ModulesProvider modulesProvider) {
   Map<String, Boolean> availableFrameworks = builder.getAvailableFrameworks();
   if ((FrameworkSupportUtil.getProviders(builder).isEmpty()
           || availableFrameworks != null && availableFrameworks.isEmpty())
       && !ApplicationManager.getApplication().isUnitTestMode()) {
     return null;
   }
   final LibrariesContainer container =
       LibrariesContainerFactory.createContainer(context, modulesProvider);
   return new SupportForFrameworksStep(context, builder, container);
 }
  public static AddSupportForSingleFrameworkDialogFixed createDialog(
      @NotNull Module module, @NotNull FrameworkSupportInModuleProvider provider) {
    VirtualFile[] roots = ModuleRootManager.getInstance(module).getContentRoots();
    if (roots.length == 0) return null;

    List<FrameworkSupportInModuleProvider> providers =
        FrameworkSupportUtil.getProviders(module, DefaultFacetsProvider.INSTANCE);
    if (providers.isEmpty()) return null;

    final LibrariesContainer container =
        LibrariesContainerFactory.createContainer(module.getProject());
    final IdeaModifiableModelsProvider modifiableModelsProvider =
        new IdeaModifiableModelsProvider();

    return new AddSupportForSingleFrameworkDialogFixed(
        module,
        roots[0].getPath(),
        provider.getFrameworkType(),
        provider,
        container,
        modifiableModelsProvider);
  }
Exemplo n.º 5
0
  // new TemplatesGroup selected
  public void projectTypeChanged() {
    TemplatesGroup group = getSelectedGroup();
    if (group == null || group == myLastSelectedGroup) return;
    myLastSelectedGroup = group;
    PropertiesComponent.getInstance().setValue(PROJECT_WIZARD_GROUP, group.getId());
    ModuleBuilder groupModuleBuilder = group.getModuleBuilder();

    mySettingsStep = null;
    myHeaderPanel.removeAll();
    if (groupModuleBuilder != null && groupModuleBuilder.getModuleType() != null) {
      mySettingsStep = groupModuleBuilder.modifyProjectTypeStep(this);
    }

    if (groupModuleBuilder == null || groupModuleBuilder.isTemplateBased()) {
      showTemplates(group);
    } else if (!showCustomOptions(groupModuleBuilder)) {
      List<FrameworkSupportInModuleProvider> providers =
          FrameworkSupportUtil.getProviders(groupModuleBuilder);
      final ProjectCategory category = group.getProjectCategory();
      if (category != null) {
        List<FrameworkSupportInModuleProvider> filtered =
            ContainerUtil.filter(
                providers,
                new Condition<FrameworkSupportInModuleProvider>() {
                  @Override
                  public boolean value(FrameworkSupportInModuleProvider provider) {
                    return matchFramework(category, provider);
                  }
                });
        // add associated
        Map<String, FrameworkSupportInModuleProvider> map =
            ContainerUtil.newMapFromValues(providers.iterator(), PROVIDER_STRING_CONVERTOR);
        Set<FrameworkSupportInModuleProvider> set =
            new HashSet<FrameworkSupportInModuleProvider>(filtered);
        for (FrameworkSupportInModuleProvider provider : filtered) {
          for (FrameworkSupportInModuleProvider.FrameworkDependency depId :
              provider.getDependenciesFrameworkIds()) {
            FrameworkSupportInModuleProvider dependency = map.get(depId.getFrameworkId());
            set.add(dependency);
          }
        }

        myFrameworksPanel.setProviders(
            new ArrayList<FrameworkSupportInModuleProvider>(set),
            new HashSet<String>(Arrays.asList(category.getAssociatedFrameworkIds())),
            new HashSet<String>(Arrays.asList(category.getPreselectedFrameworkIds())));
      } else {
        myFrameworksPanel.setProviders(providers);
      }
      getSelectedBuilder().addModuleConfigurationUpdater(myConfigurationUpdater);

      showCard(FRAMEWORKS_CARD);
    }

    myHeaderPanel.setVisible(myHeaderPanel.getComponentCount() > 0);
    // align header labels
    List<JLabel> labels = UIUtil.findComponentsOfType(myHeaderPanel, JLabel.class);
    int width = 0;
    for (JLabel label : labels) {
      int width1 = label.getPreferredSize().width;
      width = Math.max(width, width1);
    }
    for (JLabel label : labels) {
      label.setPreferredSize(new Dimension(width, label.getPreferredSize().height));
    }
    myHeaderPanel.revalidate();
    myHeaderPanel.repaint();

    updateSelection();
  }