Search in sources :

Example 1 with JavaCreateFromTemplateHandler

use of com.intellij.ide.fileTemplates.JavaCreateFromTemplateHandler in project android by JetBrains.

the class CreateFileFromTemplateDialog method initKindCombo.

public void initKindCombo() {
    myKindCombo.registerUpDownHint(myNameField);
    myKindCombo.getComboBox().addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent actionEvent) {
            if (actionEvent.getSource().equals(myKindCombo.getComboBox())) {
                configureComponents(Kind.valueOfText(myKindCombo.getSelectedName()));
            }
        }
    });
    addKind(Kind.CLASS);
    addKind(Kind.INTERFACE);
    if (LanguageLevelProjectExtension.getInstance(myProject).getLanguageLevel().isAtLeast(LanguageLevel.JDK_1_5)) {
        addKind(Kind.ENUM);
        addKind(Kind.ANNOTATION);
    }
    final JavaCreateFromTemplateHandler handler = new JavaCreateFromTemplateHandler();
    for (FileTemplate template : FileTemplateManager.getInstance(myProject).getAllTemplates()) {
        if (handler.handlesTemplate(template)) {
            addKind(template);
        }
    }
}
Also used : JavaCreateFromTemplateHandler(com.intellij.ide.fileTemplates.JavaCreateFromTemplateHandler) ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) FileTemplate(com.intellij.ide.fileTemplates.FileTemplate)

Example 2 with JavaCreateFromTemplateHandler

use of com.intellij.ide.fileTemplates.JavaCreateFromTemplateHandler in project intellij-community by JetBrains.

the class CreateClassAction method buildDialog.

@Override
protected void buildDialog(final Project project, PsiDirectory directory, CreateFileFromTemplateDialog.Builder builder) {
    builder.setTitle(IdeBundle.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);
    if (PsiUtil.getLanguageLevel(directory).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(project).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 && !PsiNameHelper.getInstance(project).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;
        }
    });
}
Also used : JavaCreateFromTemplateHandler(com.intellij.ide.fileTemplates.JavaCreateFromTemplateHandler) FileTemplate(com.intellij.ide.fileTemplates.FileTemplate) InputValidatorEx(com.intellij.openapi.ui.InputValidatorEx)

Aggregations

FileTemplate (com.intellij.ide.fileTemplates.FileTemplate)2 JavaCreateFromTemplateHandler (com.intellij.ide.fileTemplates.JavaCreateFromTemplateHandler)2 InputValidatorEx (com.intellij.openapi.ui.InputValidatorEx)1 ActionEvent (java.awt.event.ActionEvent)1 ActionListener (java.awt.event.ActionListener)1