Search in sources :

Example 1 with FileTemplateDescriptor

use of com.intellij.ide.fileTemplates.FileTemplateDescriptor in project qi4j-sdk by Qi4j.

the class Qi4jApplicationComponent method getFileTemplatesDescriptor.

public final FileTemplateGroupDescriptor getFileTemplatesDescriptor() {
    FileTemplateGroupDescriptor group = new FileTemplateGroupDescriptor(message("qi4j.file.template.group.title"), null);
    FileTypeManager fileTypeManager = FileTypeManager.getInstance();
    for (@NonNls String template : FILE_TEMPLATES) {
        Icon icon = fileTypeManager.getFileTypeByFileName(template).getIcon();
        group.addTemplate(new FileTemplateDescriptor(template, icon));
    }
    return group;
}
Also used : NonNls(org.jetbrains.annotations.NonNls) FileTemplateDescriptor(com.intellij.ide.fileTemplates.FileTemplateDescriptor) FileTypeManager(com.intellij.openapi.fileTypes.FileTypeManager) FileTemplateGroupDescriptor(com.intellij.ide.fileTemplates.FileTemplateGroupDescriptor)

Example 2 with FileTemplateDescriptor

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

the class MavenFileTemplateGroupFactory method getFileTemplatesDescriptor.

public FileTemplateGroupDescriptor getFileTemplatesDescriptor() {
    FileTemplateGroupDescriptor group = new FileTemplateGroupDescriptor("Maven", MavenIcons.MavenLogo);
    group.addTemplate(new FileTemplateDescriptor(MAVEN_PROJECT_XML_TEMPLATE, MavenIcons.MavenLogo));
    group.addTemplate(new FileTemplateDescriptor(MAVEN_PROFILES_XML_TEMPLATE, MavenIcons.MavenLogo));
    group.addTemplate(new FileTemplateDescriptor(MAVEN_SETTINGS_XML_TEMPLATE, MavenIcons.MavenLogo));
    return group;
}
Also used : FileTemplateDescriptor(com.intellij.ide.fileTemplates.FileTemplateDescriptor) FileTemplateGroupDescriptor(com.intellij.ide.fileTemplates.FileTemplateGroupDescriptor)

Example 3 with FileTemplateDescriptor

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

the class JavaTestGenerator method createTestClass.

@Nullable
private static PsiClass createTestClass(CreateTestDialog d) {
    final TestFramework testFrameworkDescriptor = d.getSelectedTestFrameworkDescriptor();
    final FileTemplateDescriptor fileTemplateDescriptor = TestIntegrationUtils.MethodKind.TEST_CLASS.getFileTemplateDescriptor(testFrameworkDescriptor);
    final PsiDirectory targetDirectory = d.getTargetDirectory();
    final PsiPackage aPackage = JavaDirectoryService.getInstance().getPackage(targetDirectory);
    if (aPackage != null) {
        final GlobalSearchScope scope = GlobalSearchScopesCore.directoryScope(targetDirectory, false);
        final PsiClass[] classes = aPackage.findClassByShortName(d.getClassName(), scope);
        if (classes.length > 0) {
            if (!FileModificationService.getInstance().preparePsiElementForWrite(classes[0])) {
                return null;
            }
            return classes[0];
        }
    }
    if (fileTemplateDescriptor != null) {
        final PsiClass classFromTemplate = createTestClassFromCodeTemplate(d, fileTemplateDescriptor, targetDirectory);
        if (classFromTemplate != null) {
            return classFromTemplate;
        }
    }
    return JavaDirectoryService.getInstance().createClass(targetDirectory, d.getClassName());
}
Also used : TestFramework(com.intellij.testIntegration.TestFramework) FileTemplateDescriptor(com.intellij.ide.fileTemplates.FileTemplateDescriptor) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) Nullable(org.jetbrains.annotations.Nullable)

Example 4 with FileTemplateDescriptor

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

the class BaseGenerateTestSupportMethodAction method createEditTemplateAction.

@Nullable
@Override
public AnAction createEditTemplateAction(DataContext dataContext) {
    final Project project = CommonDataKeys.PROJECT.getData(dataContext);
    final Editor editor = CommonDataKeys.EDITOR.getData(dataContext);
    final PsiFile file = CommonDataKeys.PSI_FILE.getData(dataContext);
    final PsiClass targetClass = editor == null || file == null ? null : getTargetClass(editor, file);
    if (targetClass != null) {
        final List<TestFramework> frameworks = TestIntegrationUtils.findSuitableFrameworks(targetClass);
        final TestIntegrationUtils.MethodKind methodKind = ((MyHandler) getHandler()).myMethodKind;
        if (!frameworks.isEmpty()) {
            return new AnAction("Edit Template") {

                @Override
                public void actionPerformed(AnActionEvent e) {
                    chooseAndPerform(editor, frameworks, framework -> {
                        final FileTemplateDescriptor descriptor = methodKind.getFileTemplateDescriptor(framework);
                        if (descriptor != null) {
                            final String fileName = descriptor.getFileName();
                            AllFileTemplatesConfigurable.editCodeTemplate(FileUtil.getNameWithoutExtension(fileName), project);
                        } else {
                            HintManager.getInstance().showErrorHint(editor, "No template found for " + framework.getName() + ":" + BaseGenerateTestSupportMethodAction.this.getTemplatePresentation().getText());
                        }
                    });
                }
            };
        }
    }
    return null;
}
Also used : AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) AnAction(com.intellij.openapi.actionSystem.AnAction) Project(com.intellij.openapi.project.Project) FileTemplateDescriptor(com.intellij.ide.fileTemplates.FileTemplateDescriptor) Editor(com.intellij.openapi.editor.Editor) Nullable(org.jetbrains.annotations.Nullable)

Example 5 with FileTemplateDescriptor

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

the class DevKitFileTemplatesFactory method getFileTemplatesDescriptor.

public FileTemplateGroupDescriptor getFileTemplatesDescriptor() {
    FileTemplateGroupDescriptor descriptor = new FileTemplateGroupDescriptor(DevKitBundle.message("plugin.descriptor"), AllIcons.Nodes.Plugin);
    descriptor.addTemplate(new FileTemplateDescriptor("plugin.xml", StdFileTypes.XML.getIcon()));
    descriptor.addTemplate(new FileTemplateDescriptor("ProjectComponent.java", StdFileTypes.JAVA.getIcon()));
    descriptor.addTemplate(new FileTemplateDescriptor("ApplicationComponent.java", StdFileTypes.JAVA.getIcon()));
    descriptor.addTemplate(new FileTemplateDescriptor("ModuleComponent.java", StdFileTypes.JAVA.getIcon()));
    descriptor.addTemplate(new FileTemplateDescriptor("Action.java", StdFileTypes.JAVA.getIcon()));
    descriptor.addTemplate(new FileTemplateDescriptor("InspectionDescription.html", StdFileTypes.HTML.getIcon()));
    return descriptor;
}
Also used : FileTemplateDescriptor(com.intellij.ide.fileTemplates.FileTemplateDescriptor) FileTemplateGroupDescriptor(com.intellij.ide.fileTemplates.FileTemplateGroupDescriptor)

Aggregations

FileTemplateDescriptor (com.intellij.ide.fileTemplates.FileTemplateDescriptor)9 FileTemplateGroupDescriptor (com.intellij.ide.fileTemplates.FileTemplateGroupDescriptor)5 FileTemplate (com.intellij.ide.fileTemplates.FileTemplate)2 IOException (java.io.IOException)2 Nullable (org.jetbrains.annotations.Nullable)2 Expression (com.intellij.codeInsight.template.Expression)1 Template (com.intellij.codeInsight.template.Template)1 ConstantNode (com.intellij.codeInsight.template.impl.ConstantNode)1 AnAction (com.intellij.openapi.actionSystem.AnAction)1 AnActionEvent (com.intellij.openapi.actionSystem.AnActionEvent)1 Editor (com.intellij.openapi.editor.Editor)1 FileTypeManager (com.intellij.openapi.fileTypes.FileTypeManager)1 Project (com.intellij.openapi.project.Project)1 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)1 TestFramework (com.intellij.testIntegration.TestFramework)1 TestNGFramework (com.theoryinpractice.testng.TestNGFramework)1 Properties (java.util.Properties)1 NonNls (org.jetbrains.annotations.NonNls)1