Exemplo n.º 1
0
 public CreateClassAction() {
   super(
       JavaCoreBundle.message("action.NewClass.text"),
       JavaCoreBundle.message("action.create.new.class.description"),
       PlatformIcons.CLASS_ICON,
       true);
 }
Exemplo n.º 2
0
 @Override
 protected String getActionName(PsiDirectory directory, String newName, String templateName) {
   return JavaCoreBundle.message(
       "progress.creating.class",
       StringUtil.getQualifiedName(
           JavaDirectoryService.getInstance().getPackage(directory).getQualifiedName(), newName));
 }
Exemplo n.º 3
0
  @Override
  protected void buildDialog(
      final Project project, PsiDirectory directory, CreateFileFromTemplateDialog.Builder builder) {
    builder
        .setTitle(JavaCoreBundle.message("action.create.new.class"))
        .addKind("Class", PlatformIcons.CLASS_ICON, JavaTemplateUtil.INTERNAL_CLASS_TEMPLATE_NAME)
        .addKind(
            "Interface",
            PlatformIcons.INTERFACE_ICON,
            JavaTemplateUtil.INTERNAL_INTERFACE_TEMPLATE_NAME);

    Module module = ModuleUtilCore.findModuleForPsiElement(directory);
    assert module != null;
    JavaModuleExtensionImpl moduleExtension =
        ModuleRootManager.getInstance(module).getExtension(JavaModuleExtensionImpl.class);

    assert moduleExtension != null;
    if (moduleExtension.getLanguageLevel().isAtLeast(LanguageLevel.JDK_1_5)) {
      builder.addKind(
          "Enum", PlatformIcons.ENUM_ICON, JavaTemplateUtil.INTERNAL_ENUM_TEMPLATE_NAME);
      builder.addKind(
          "Annotation",
          PlatformIcons.ANNOTATION_TYPE_ICON,
          JavaTemplateUtil.INTERNAL_ANNOTATION_TYPE_TEMPLATE_NAME);
    }

    for (FileTemplate template : FileTemplateManager.getInstance().getAllTemplates()) {
      final JavaCreateFromTemplateHandler handler = new JavaCreateFromTemplateHandler();
      if (handler.handlesTemplate(template) && JavaCreateFromTemplateHandler.canCreate(directory)) {
        builder.addKind(template.getName(), JavaFileType.INSTANCE.getIcon(), template.getName());
      }
    }

    builder.setValidator(
        new InputValidatorEx() {
          @Override
          public String getErrorText(String inputString) {
            if (inputString.length() > 0
                && !JavaPsiFacade.getInstance(project)
                    .getNameHelper()
                    .isQualifiedName(inputString)) {
              return "This is not a valid Java qualified name";
            }
            return null;
          }

          @Override
          public boolean checkInput(String inputString) {
            return true;
          }

          @Override
          public boolean canClose(String inputString) {
            return !StringUtil.isEmptyOrSpaces(inputString) && getErrorText(inputString) == null;
          }
        });
  }
Exemplo n.º 4
0
 @Override
 protected String getErrorTitle() {
   return JavaCoreBundle.message("title.cannot.create.class");
 }