Esempio n. 1
0
 public void onWizardFinished() throws CommitStepException {
   if (isFrameworksMode()) {
     boolean ok = myFrameworksPanel.downloadLibraries();
     if (!ok) {
       int answer =
           Messages.showYesNoDialog(
               getComponent(),
               ProjectBundle.message("warning.message.some.required.libraries.wasn.t.downloaded"),
               CommonBundle.getWarningTitle(),
               Messages.getWarningIcon());
       if (answer != Messages.YES) {
         throw new CommitStepException(null);
       }
     }
   }
 }
Esempio n. 2
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);
           }
         });
   }
 }
Esempio n. 3
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();
  }
Esempio n. 4
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();
  }