public CreateClassAction() { super( JavaCoreBundle.message("action.NewClass.text"), JavaCoreBundle.message("action.create.new.class.description"), PlatformIcons.CLASS_ICON, true); }
@Override protected String getActionName(PsiDirectory directory, String newName, String templateName) { return JavaCoreBundle.message( "progress.creating.class", StringUtil.getQualifiedName( JavaDirectoryService.getInstance().getPackage(directory).getQualifiedName(), newName)); }
@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; } }); }
@Override protected String getErrorTitle() { return JavaCoreBundle.message("title.cannot.create.class"); }