@Override
  public void updateDataModel() {

    myWizardContext.setProjectBuilder(myModuleBuilder);
    myWizardContext.setProjectName(myNamePathComponent.getNameValue());
    myWizardContext.setProjectFileDirectory(myNamePathComponent.getPath());
    myFormatPanel.updateData(myWizardContext);

    if (myModuleBuilder != null) {
      final String moduleName = getModuleName();
      myModuleBuilder.setName(moduleName);
      myModuleBuilder.setModuleFilePath(
          FileUtil.toSystemIndependentName(myModuleFileLocation.getText())
              + "/"
              + moduleName
              + ModuleFileType.DOT_DEFAULT_EXTENSION);
      myModuleBuilder.setContentEntryPath(FileUtil.toSystemIndependentName(getModuleContentRoot()));
      if (myModuleBuilder instanceof TemplateModuleBuilder) {
        myWizardContext.setProjectStorageFormat(StorageScheme.DIRECTORY_BASED);
      }
    }

    if (mySettingsStep != null) {
      mySettingsStep.updateDataModel();
    }
  }
  @Override
  public boolean validate() throws ConfigurationException {
    ProjectTemplate template = getSelectedTemplate();
    if (template == null) {
      throw new ConfigurationException(
          StringUtil.capitalize(
              ProjectBundle.message(
                  "project.new.wizard.from.template.error", myWizardContext.getPresentationName())),
          "Error");
    }

    if (myWizardContext.isCreatingNewProject()) {
      if (!myNamePathComponent.validateNameAndPath(myWizardContext, myFormatPanel.isDefault()))
        return false;
    }

    if (!validateModulePaths()) return false;
    if (!myWizardContext.isCreatingNewProject()) {
      validateExistingModuleName();
    }

    ValidationInfo info = template.validateSettings();
    if (info != null) {
      throw new ConfigurationException(info.message, "Error");
    }
    if (mySettingsStep != null) {
      return mySettingsStep.validate();
    }
    return true;
  }
 private static NamePathComponent initNamePathComponent(WizardContext context) {
   NamePathComponent component =
       new NamePathComponent(
           IdeBundle.message("label.project.name"),
           IdeBundle.message("label.project.files.location"),
           IdeBundle.message(
               "title.select.project.file.directory",
               IdeBundle.message("project.new.wizard.project.identification")),
           IdeBundle.message(
               "description.select.project.file.directory",
               StringUtil.capitalize(
                   IdeBundle.message("project.new.wizard.project.identification"))),
           true,
           false);
   final String baseDir = context.getProjectFileDirectory();
   final String projectName = context.getProjectName();
   final String initialProjectName =
       projectName != null
           ? projectName
           : ProjectWizardUtil.findNonExistingFileName(baseDir, "untitled", "");
   component.setPath(
       projectName == null ? (baseDir + File.separator + initialProjectName) : baseDir);
   component.setNameValue(initialProjectName);
   component.getNameComponent().select(0, initialProjectName.length());
   return component;
 }
  public void testNewDecoratorWizard() {
    WizardContext context = new WizardContext();
    context.init(
        "org.jboss.tools.cdi.ui.wizard.NewDecoratorCreationWizard", PACK_NAME, DECORATOR_NAME);

    ICDIProject cdi = CDICorePlugin.getCDIProject(context.tck, true);

    try {
      NewDecoratorWizardPage page = (NewDecoratorWizardPage) context.page;

      List<String> interfacesNames = new ArrayList<String>();
      interfacesNames.add("java.util.Map<K,V>");
      page.setSuperInterfaces(interfacesNames, true);

      context.wizard.performFinish();

      String text = context.getNewTypeContent();
      //			System.out.println(text);

      assertTrue(text.contains("@Decorator"));
      assertTrue(text.contains("@Delegate"));
    } finally {
      context.close();
    }
  }
  public void testNewAnnotationLiteralWizardWithMembers() {
    WizardContext context = new WizardContext();
    context.init(
        "org.jboss.tools.cdi.ui.wizard.NewAnnotationLiteralCreationWizard",
        PACK_NAME,
        "NewLiteral");

    ICDIProject cdi = CDICorePlugin.getCDIProject(context.tck, true);

    try {
      NewAnnotationLiteralWizardPage page = (NewAnnotationLiteralWizardPage) context.page;

      page.setQualifier("javax.enterprise.inject.New");

      context.wizard.performFinish();

      String text = context.getNewTypeContent();
      //			System.out.println(text);

      assertTrue(text.contains("AnnotationLiteral<New>"));
      assertTrue(text.contains("private final Class<?> value;"));
    } finally {
      context.close();
    }
  }
Ejemplo n.º 6
0
  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());
    }
  }
 private String getDefaultBaseDir(WizardContext wizardContext) {
   if (wizardContext.isCreatingNewProject()) {
     return myNamePathComponent.getPath();
   } else {
     final Project project = wizardContext.getProject();
     assert project != null;
     final VirtualFile baseDir = project.getBaseDir();
     if (baseDir != null) {
       return baseDir.getPath();
     }
     return "";
   }
 }
 private void validateExistingModuleName() throws ConfigurationException {
   final String moduleName = getModuleName();
   final Module module;
   final ProjectStructureConfigurable fromConfigurable =
       ProjectStructureConfigurable.getInstance(myWizardContext.getProject());
   if (fromConfigurable != null) {
     module = fromConfigurable.getModulesConfig().getModule(moduleName);
   } else {
     module = ModuleManager.getInstance(myWizardContext.getProject()).findModuleByName(moduleName);
   }
   if (module != null) {
     throw new ConfigurationException(
         "Module \'" + moduleName + "\' already exist in project. Please, specify another name.");
   }
 }
  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);
    }
  }
  private void setupPanels(@Nullable ProjectTemplate template) {

    restorePanel(myNamePathComponent, 4);
    restorePanel(myModulePanel, myWizardContext.isCreatingNewProject() ? 8 : 6);
    restorePanel(myExpertPanel, myWizardContext.isCreatingNewProject() ? 1 : 0);
    mySettingsStep = myModuleBuilder == null ? null : myModuleBuilder.modifySettingsStep(this);

    String description = null;
    if (template != null) {
      description = template.getDescription();
      if (StringUtil.isNotEmpty(description)) {
        StringBuilder sb = new StringBuilder("<html><body><font ");
        sb.append(SystemInfo.isMac ? "" : "face=\"Verdana\" size=\"-1\"").append('>');
        sb.append(description).append("</font></body></html>");
        description = sb.toString();
        myDescriptionPane.setText(description);
      }
    }

    myExpertPlaceholder.setVisible(
        !(myModuleBuilder instanceof TemplateModuleBuilder)
            && myExpertPanel.getComponentCount() > 0);
    for (int i = 0; i < 6; i++) {
      myModulePanel.getComponent(i).setVisible(!(myModuleBuilder instanceof EmptyModuleBuilder));
    }
    myDescriptionPanel.setVisible(StringUtil.isNotEmpty(description));

    mySettingsPanel.revalidate();
    mySettingsPanel.repaint();
  }
 public ModuleWizardStep createProjectJdkStep(final WizardContext wizardContext) {
   ProjectJdkStep projectSdkStep = wizardContext.getUserData(PROJECT_JDK_STEP_KEY);
   if (projectSdkStep != null) {
     return projectSdkStep;
   }
   projectSdkStep =
       new ProjectJdkStep(wizardContext) {
         public boolean isStepVisible() {
           final Sdk newProjectJdk = AbstractProjectWizard.getProjectSdkByDefault(wizardContext);
           if (newProjectJdk == null) return true;
           final ProjectBuilder projectBuilder = wizardContext.getProjectBuilder();
           return projectBuilder != null && !projectBuilder.isSuitableSdk(newProjectJdk);
         }
       };
   wizardContext.putUserData(PROJECT_JDK_STEP_KEY, projectSdkStep);
   return projectSdkStep;
 }
Ejemplo n.º 12
0
 @Override
 public boolean onStepAction(Wizard wizard, StepKind step) {
   if (step == StepKind.FORWARD) {
     if (!newDigObject.validate()) {
       return false;
     }
     WizardContext wc = getContext();
     MetaModelRecord model = newDigObject.getModel();
     wc.setModel(model);
     String mods = newDigObject.getMods();
     String newPid = newDigObject.getNewPid();
     ClientUtils.fine(
         LOG, "NewDigObjectStep.onStepAction.FORWARD: model: %s pid: %s", model.getId(), newPid);
     saveNewDigitalObject(model.getId(), newPid, mods);
     return false;
   }
   return true;
 }
Ejemplo n.º 13
0
  public void testNewScopeWizard() {
    WizardContext context = new WizardContext();
    context.init("org.jboss.tools.cdi.ui.wizard.NewScopeCreationWizard", PACK_NAME, SCOPE_NAME);

    try {
      NewScopeWizardPage page = (NewScopeWizardPage) context.page;

      context.wizard.performFinish();

      String text = context.getNewTypeContent();

      assertTrue(text.contains("@NormalScope"));
      assertTrue(text.contains("@Inherited"));
      assertTrue(text.contains("@Target({ TYPE, METHOD, FIELD })"));
      assertTrue(text.contains("@Retention(RUNTIME)"));

    } finally {
      context.close();
    }
  }
Ejemplo n.º 14
0
  /**
   * Existing interceptor binding, taken from TCK, is annotated @Inherited @Target({TYPE}) If this
   * test fails, first check that the existing interceptor binding has not been moved or modified.
   * In the previous version, the result of testNewInterceptorBindingWizard() was used, but that
   * turned to be not safe, since the order of tests is not guaranteed.
   *
   * @throws CoreException
   */
  public void testNewInterceptorBindingWizardWithBinding() throws CoreException {
    IProject tck = ResourcesPlugin.getWorkspace().getRoot().getProject("tck");
    tck.build(IncrementalProjectBuilder.FULL_BUILD, new NullProgressMonitor());

    WizardContext context = new WizardContext();
    context.init(
        "org.jboss.tools.cdi.ui.wizard.NewInterceptorBindingCreationWizard",
        PACK_NAME,
        INTERCEPTOR_BINDING2_NAME);

    try {
      NewInterceptorBindingWizardPage page = (NewInterceptorBindingWizardPage) context.page;
      ICDIProject cdi = CDICorePlugin.getCDIProject(context.tck, true);
      IInterceptorBinding s =
          cdi.getInterceptorBinding(EXISTING_PACK_NAME + "." + EXISTING_INTERCEPTOR_BINDING_NAME);
      assertNotNull(s);

      page.addInterceptorBinding(s);
      String message = page.getErrorMessage();
      assertNull(message);
      message = page.getMessage();
      assertNotNull(message);
      int messageType = page.getMessageType();
      assertEquals(IMessageProvider.WARNING, messageType);
      String testmessage =
          NLS.bind(
              CDIUIMessages.MESSAGE_INTERCEPTOR_BINDING_IS_NOT_COMPATIBLE,
              s.getSourceType().getElementName());
      assertEquals(testmessage, message);

      page.setTarget("TYPE");

      message = page.getErrorMessage();
      assertNull(message);
      message = page.getMessage();
      assertNull(message);

    } finally {
      context.close();
    }
  }
Ejemplo n.º 15
0
  public void testNewQualifierWizard() {
    WizardContext context = new WizardContext();
    context.init(
        "org.jboss.tools.cdi.ui.wizard.NewQualifierCreationWizard", PACK_NAME, QUALIFIER_NAME);

    try {
      NewQualifierWizardPage page = (NewQualifierWizardPage) context.page;
      page.setInherited(true);

      context.wizard.performFinish();

      String text = context.getNewTypeContent();

      assertTrue(text.contains("@Qualifier"));
      assertTrue(text.contains("@Inherited"));
      assertTrue(text.contains("@Target({ TYPE, METHOD, PARAMETER, FIELD })"));
      assertTrue(text.contains("@Retention(RUNTIME)"));

    } finally {
      context.close();
    }
  }
Ejemplo n.º 16
0
  public void testNewBeanWizard() throws Exception {
    WizardContext context = new WizardContext();
    context.init("org.jboss.tools.cdi.ui.wizard.NewBeanCreationWizard", PACK_NAME, BEAN_NAME);

    ICDIProject cdi = CDICorePlugin.getCDIProject(context.tck, true);

    try {
      NewBeanWizardPage page = (NewBeanWizardPage) context.page;

      page.setBeanName("myNewBean");

      page.setScope(CDIConstants.SESSION_SCOPED_ANNOTATION_TYPE_NAME);
      String message = page.getMessage();
      assertEquals(CDIUIMessages.MESSAGE_BEAN_SHOULD_BE_SERIALIZABLE, message);
      assertEquals(IMessageProvider.WARNING, page.getMessageType());

      page.setScope(CDIConstants.APPLICATION_SCOPED_ANNOTATION_TYPE_NAME);
      assertEquals(IMessageProvider.NONE, page.getMessageType());

      context.wizard.performFinish();

      String text = context.getNewTypeContent();
      //			System.out.println(text);

      assertTrue(text.contains("@Named"));
      assertTrue(text.contains("\"myNewBean\""));

      IType type = (IType) context.wizard.getCreatedElement();
      int f = type.getFlags();
      assertTrue(Modifier.isPublic(f));
      assertFalse(Modifier.isAbstract(f));
      //			String[] is = type.getSuperInterfaceNames();
      //			assertEquals(1, is.length);
      //			assertEquals("Serializable", is[0]);
    } finally {
      context.close();
    }
  }
Ejemplo n.º 17
0
  public void testNewInterceptorBindingWizard() {
    WizardContext context = new WizardContext();
    context.init(
        "org.jboss.tools.cdi.ui.wizard.NewInterceptorBindingCreationWizard",
        PACK_NAME,
        INTERCEPTOR_BINDING_NAME);

    try {
      NewInterceptorBindingWizardPage page = (NewInterceptorBindingWizardPage) context.page;
      page.setTarget("TYPE");

      context.wizard.performFinish();

      String text = context.getNewTypeContent();

      assertTrue(text.contains("@InterceptorBinding"));
      assertTrue(text.contains("@Inherited"));
      assertTrue(text.contains("@Target({ TYPE })"));
      assertTrue(text.contains("@Retention(RUNTIME)"));

    } finally {
      context.close();
    }
  }
Ejemplo n.º 18
0
  public void testNewAnnotationLiteralWizard() {
    WizardContext context = new WizardContext();
    context.init(
        "org.jboss.tools.cdi.ui.wizard.NewAnnotationLiteralCreationWizard",
        PACK_NAME,
        HAIRY_QUALIFIER + "Literal");

    ICDIProject cdi = CDICorePlugin.getCDIProject(context.tck, true);

    try {
      NewAnnotationLiteralWizardPage page = (NewAnnotationLiteralWizardPage) context.page;

      page.setQualifier(HAIRY_PACK_NAME + "." + HAIRY_QUALIFIER);

      context.wizard.performFinish();

      String text = context.getNewTypeContent();
      //			System.out.println(text);

      assertTrue(text.contains("AnnotationLiteral<" + HAIRY_QUALIFIER + ">"));
    } finally {
      context.close();
    }
  }
 @Override
 public String getHelpId() {
   String helpId =
       myWizardContext.isCreatingNewProject()
           ? "New_Project_Main_Settings"
           : "Add_Module_Main_Settings";
   ProjectTemplate projectTemplate = getSelectedTemplate();
   if (projectTemplate instanceof WebProjectTemplate) {
     WebProjectTemplate webProjectTemplate = (WebProjectTemplate) projectTemplate;
     String subHelpId = webProjectTemplate.getHelpId();
     if (subHelpId != null) {
       helpId = helpId + ":" + subHelpId;
     }
   }
   return helpId;
 }
 @Override
 public void addSettingsComponent(@NotNull JComponent component) {
   JPanel panel = myWizardContext.isCreatingNewProject() ? myNamePathComponent : myModulePanel;
   panel.add(
       component,
       new GridBagConstraints(
           0,
           GridBagConstraints.RELATIVE,
           2,
           1,
           1.0,
           0,
           GridBagConstraints.NORTHWEST,
           GridBagConstraints.HORIZONTAL,
           new Insets(0, 0, 0, 0),
           0,
           0));
 }
Ejemplo n.º 21
0
 void loadRemoteTemplates(final ChooseTemplateStep chooseTemplateStep) {
   ProgressManager.getInstance()
       .run(
           new Task.Backgroundable(myContext.getProject(), "Loading Templates") {
             @Override
             public void run(@NotNull ProgressIndicator indicator) {
               try {
                 myTemplatesList.setPaintBusy(true);
                 chooseTemplateStep.getTemplateList().setPaintBusy(true);
                 RemoteTemplatesFactory factory = new RemoteTemplatesFactory();
                 String[] groups = factory.getGroups();
                 for (String group : groups) {
                   ProjectTemplate[] templates = factory.createTemplates(group, myContext);
                   for (ProjectTemplate template : templates) {
                     String id = ((ArchivedProjectTemplate) template).getCategory();
                     for (TemplatesGroup templatesGroup : myTemplatesMap.keySet()) {
                       if (Comparing.equal(id, templatesGroup.getId())
                           || Comparing.equal(group, templatesGroup.getName())) {
                         myTemplatesMap.putValue(templatesGroup, template);
                       }
                     }
                   }
                 }
                 //noinspection SSBasedInspection
                 SwingUtilities.invokeLater(
                     new Runnable() {
                       public void run() {
                         TemplatesGroup group = getSelectedGroup();
                         if (group == null) return;
                         Collection<ProjectTemplate> templates = myTemplatesMap.get(group);
                         setTemplatesList(group, templates, true);
                         chooseTemplateStep.updateStep();
                       }
                     });
               } finally {
                 myTemplatesList.setPaintBusy(false);
                 chooseTemplateStep.getTemplateList().setPaintBusy(false);
               }
             }
           });
 }
Ejemplo n.º 22
0
  /**
   * Existing interceptor binding, taken from TCK, is annotated @Inherited @Target({TYPE}) If this
   * test fails, first check that the existing interceptor binding has not been moved or modified.
   * In the previous version, the result of testNewInterceptorBindingWizard() was used, but that
   * turned to be not safe, since the order of tests is not guaranteed.
   *
   * @throws CoreException
   */
  public void testNewInterceptorWizard() throws CoreException {
    WizardContext context = new WizardContext();
    context.init(
        "org.jboss.tools.cdi.ui.wizard.NewInterceptorCreationWizard", PACK_NAME, INTERCEPTOR_NAME);

    ICDIProject cdi = CDICorePlugin.getCDIProject(context.tck, true);
    ICDIAnnotation a =
        cdi.getInterceptorBinding(EXISTING_PACK_NAME + "." + EXISTING_INTERCEPTOR_BINDING_NAME);
    assertNotNull(a);

    try {
      NewInterceptorWizardPage page = (NewInterceptorWizardPage) context.page;

      page.addInterceptorBinding(a);

      assertTrue(page.isToBeRegisteredInBeansXML());
      context.setTypeName("com.acme", "Foo");
      assertFalse(page.isToBeRegisteredInBeansXML());
      context.setTypeName(PACK_NAME, INTERCEPTOR_NAME);
      assertTrue(page.isToBeRegisteredInBeansXML());

      context.wizard.performFinish();

      String text = context.getNewTypeContent();

      assertTrue(text.contains("@Interceptor"));
      assertTrue(text.contains("@" + EXISTING_INTERCEPTOR_BINDING_NAME));

      IProject tck = ResourcesPlugin.getWorkspace().getRoot().getProject("tck");
      IFile f = tck.getFile("WebContent/WEB-INF/beans.xml");
      XModelObject o = EclipseResourceUtil.createObjectForResource(f);
      XModelObject c = o.getChildByPath("Interceptors/" + PACK_NAME + "." + INTERCEPTOR_NAME);
      assertNotNull(c);
    } finally {
      context.close();
    }
  }
Ejemplo n.º 23
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();
  }
 @Override
 public void addExpertField(@NotNull String label, @NotNull JComponent field) {
   JPanel panel = myWizardContext.isCreatingNewProject() ? myModulePanel : myExpertPanel;
   addField(label, field, panel);
 }
  public void bindModuleSettings() {

    myNamePathComponent
        .getNameComponent()
        .getDocument()
        .addDocumentListener(
            new DocumentAdapter() {
              protected void textChanged(final DocumentEvent e) {
                if (!myModuleNameChangedByUser) {
                  setModuleName(myNamePathComponent.getNameValue());
                }
              }
            });

    myModuleContentRoot.addBrowseFolderListener(
        ProjectBundle.message("project.new.wizard.module.content.root.chooser.title"),
        ProjectBundle.message("project.new.wizard.module.content.root.chooser.description"),
        myWizardContext.getProject(),
        BrowseFilesListener.SINGLE_DIRECTORY_DESCRIPTOR);

    myNamePathComponent
        .getPathComponent()
        .getDocument()
        .addDocumentListener(
            new DocumentAdapter() {
              protected void textChanged(final DocumentEvent e) {
                if (!myContentRootChangedByUser) {
                  setModuleContentRoot(myNamePathComponent.getPath());
                }
              }
            });
    myModuleName
        .getDocument()
        .addDocumentListener(
            new DocumentAdapter() {
              protected void textChanged(final DocumentEvent e) {
                if (myModuleNameDocListenerEnabled) {
                  myModuleNameChangedByUser = true;
                }
                String path = getDefaultBaseDir(myWizardContext);
                final String moduleName = getModuleName();
                if (path.length() > 0
                    && !Comparing.strEqual(moduleName, myNamePathComponent.getNameValue())) {
                  path += "/" + moduleName;
                }
                if (!myContentRootChangedByUser) {
                  final boolean f = myModuleNameChangedByUser;
                  myModuleNameChangedByUser = true;
                  setModuleContentRoot(path);
                  myModuleNameChangedByUser = f;
                }
                if (!myImlLocationChangedByUser) {
                  setImlFileLocation(path);
                }
              }
            });
    myModuleContentRoot
        .getTextField()
        .getDocument()
        .addDocumentListener(
            new DocumentAdapter() {
              protected void textChanged(final DocumentEvent e) {
                if (myContentRootDocListenerEnabled) {
                  myContentRootChangedByUser = true;
                }
                if (!myImlLocationChangedByUser) {
                  setImlFileLocation(getModuleContentRoot());
                }
                if (!myModuleNameChangedByUser) {
                  final String path = FileUtil.toSystemIndependentName(getModuleContentRoot());
                  final int idx = path.lastIndexOf("/");

                  boolean f = myContentRootChangedByUser;
                  myContentRootChangedByUser = true;

                  boolean i = myImlLocationChangedByUser;
                  myImlLocationChangedByUser = true;

                  setModuleName(idx >= 0 ? path.substring(idx + 1) : "");

                  myContentRootChangedByUser = f;
                  myImlLocationChangedByUser = i;
                }
              }
            });

    myModuleFileLocation.addBrowseFolderListener(
        ProjectBundle.message("project.new.wizard.module.file.chooser.title"),
        ProjectBundle.message("project.new.wizard.module.file.description"),
        myWizardContext.getProject(),
        BrowseFilesListener.SINGLE_DIRECTORY_DESCRIPTOR);
    myModuleFileLocation
        .getTextField()
        .getDocument()
        .addDocumentListener(
            new DocumentAdapter() {
              protected void textChanged(final DocumentEvent e) {
                if (myImlLocationDocListenerEnabled) {
                  myImlLocationChangedByUser = true;
                }
              }
            });
    myNamePathComponent
        .getPathComponent()
        .getDocument()
        .addDocumentListener(
            new DocumentAdapter() {
              protected void textChanged(final DocumentEvent e) {
                if (!myImlLocationChangedByUser) {
                  setImlFileLocation(myNamePathComponent.getPath());
                }
              }
            });
    if (myWizardContext.isCreatingNewProject()) {
      setModuleName(myNamePathComponent.getNameValue());
      setModuleContentRoot(myNamePathComponent.getPath());
      setImlFileLocation(myNamePathComponent.getPath());
    } else {
      final Project project = myWizardContext.getProject();
      assert project != null;
      VirtualFile baseDir = project.getBaseDir();
      if (baseDir != null) { // e.g. was deleted
        final String baseDirPath = baseDir.getPath();
        String moduleName = ProjectWizardUtil.findNonExistingFileName(baseDirPath, "untitled", "");
        String contentRoot = baseDirPath + "/" + moduleName;
        if (!Comparing.strEqual(project.getName(), myWizardContext.getProjectName())
            && !myWizardContext.isCreatingNewProject()
            && myWizardContext.getProjectName() != null) {
          moduleName =
              ProjectWizardUtil.findNonExistingFileName(
                  myWizardContext.getProjectFileDirectory(), myWizardContext.getProjectName(), "");
          contentRoot = myWizardContext.getProjectFileDirectory();
        }
        setModuleName(moduleName);
        setModuleContentRoot(contentRoot);
        setImlFileLocation(contentRoot);
        myModuleName.select(0, moduleName.length());
      }
    }
  }
 @Override
 public Icon getIcon() {
   return myWizardContext.getStepIcon();
 }
Ejemplo n.º 27
0
 private void initContext() {
   this.wc = new WizardContext();
   wc.setParentPid(parentPid);
 }
Ejemplo n.º 28
0
 private boolean isFrameworksMode() {
   return FRAMEWORKS_CARD.equals(myCurrentCard)
       && getSelectedBuilder().equals(myContext.getProjectBuilder());
 }
Ejemplo n.º 29
0
  public void testNewStereotypeWizard() {
    WizardContext context = new WizardContext();
    context.init(
        "org.jboss.tools.cdi.ui.wizard.NewStereotypeCreationWizard", PACK_NAME, STEREOTYPE_NAME);

    try {
      NewStereotypeWizardPage page = (NewStereotypeWizardPage) context.page;
      page.setInherited(true);
      page.setTarget("METHOD,FIELD");
      page.setNamed(true);
      page.setAlternative(true);
      page.setToBeRegisteredInBeansXML(true);

      assertTrue(page.isToBeRegisteredInBeansXML());

      context.wizard.performFinish();

      String text = context.getNewTypeContent();

      assertTrue(text.contains("@Stereotype"));
      assertTrue(text.contains("@Inherited"));
      assertTrue(text.contains("@Named"));
      assertTrue(text.contains("@Target({ METHOD, FIELD })"));
      assertTrue(text.contains("@Retention(RUNTIME)"));

      IProject tck = ResourcesPlugin.getWorkspace().getRoot().getProject("tck");
      IFile f = tck.getFile("WebContent/WEB-INF/beans.xml");
      XModelObject o = EclipseResourceUtil.createObjectForResource(f);
      XModelObject c = o.getChildByPath("Alternatives/" + PACK_NAME + "." + STEREOTYPE_NAME);
      assertNotNull(c);

    } finally {
      context.close();
    }

    // testNewStereotypeWizardWithStereotype()
    context = new WizardContext();
    context.init(
        "org.jboss.tools.cdi.ui.wizard.NewStereotypeCreationWizard", PACK_NAME, STEREOTYPE2_NAME);
    try {
      context.tck.build(IncrementalProjectBuilder.INCREMENTAL_BUILD, null);
    } catch (CoreException e) {
      e.printStackTrace();
    }
    ICDIProject cdi = CDICorePlugin.getCDIProject(context.tck, true);
    IStereotype s = cdi.getStereotype(PACK_NAME + "." + STEREOTYPE_NAME);
    IStereotype d = cdi.getStereotype(CDIConstants.DECORATOR_STEREOTYPE_TYPE_NAME);
    assertNotNull(s);
    assertNotNull(d);

    try {
      NewStereotypeWizardPage page = (NewStereotypeWizardPage) context.page;
      page.setInherited(true);
      page.setTarget("METHOD,FIELD");
      page.setNamed(true);

      page.addStereotype(d);
      String message = page.getErrorMessage();
      assertNull(message);
      message = page.getMessage();
      assertNotNull(message);
      int messageType = page.getMessageType();
      assertEquals(IMessageProvider.WARNING, messageType);
      String testmessage =
          NLS.bind(
              CDIUIMessages.MESSAGE_STEREOTYPE_IS_NOT_COMPATIBLE,
              d.getSourceType().getElementName());
      assertEquals(testmessage, message);

      page.addStereotype(s);
      message = page.getErrorMessage();
      testmessage =
          NLS.bind(
              CDIUIMessages.MESSAGE_STEREOTYPE_CANNOT_BE_APPLIED_TO_TYPE,
              s.getSourceType().getElementName());
      assertEquals(testmessage, message);
    } finally {
      context.close();
    }
  }
Ejemplo n.º 30
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;
  }