Search in sources :

Example 26 with FileTemplate

use of com.intellij.ide.fileTemplates.FileTemplate 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 27 with FileTemplate

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

the class AndroidResourceUtil method createFileResource.

@NotNull
public static XmlFile createFileResource(@NotNull String fileName, @NotNull PsiDirectory resSubdir, @NotNull String rootTagName, @NotNull String resourceType, boolean valuesResourceFile) throws Exception {
    FileTemplateManager manager = FileTemplateManager.getInstance(resSubdir.getProject());
    String templateName = getTemplateName(resourceType, valuesResourceFile, rootTagName);
    FileTemplate template = manager.getJ2eeTemplate(templateName);
    Properties properties = new Properties();
    if (!valuesResourceFile) {
        properties.setProperty(ROOT_TAG_PROPERTY, rootTagName);
    }
    if (ResourceType.LAYOUT.getName().equals(resourceType)) {
        final Module module = ModuleUtilCore.findModuleForPsiElement(resSubdir);
        final AndroidPlatform platform = module != null ? AndroidPlatform.getInstance(module) : null;
        final int apiLevel = platform != null ? platform.getApiLevel() : -1;
        final String value = apiLevel == -1 || apiLevel >= 8 ? "match_parent" : "fill_parent";
        properties.setProperty(LAYOUT_WIDTH_PROPERTY, value);
        properties.setProperty(LAYOUT_HEIGHT_PROPERTY, value);
    }
    PsiElement createdElement = FileTemplateUtil.createFromTemplate(template, fileName, properties, resSubdir);
    assert createdElement instanceof XmlFile;
    return (XmlFile) createdElement;
}
Also used : XmlFile(com.intellij.psi.xml.XmlFile) FileTemplate(com.intellij.ide.fileTemplates.FileTemplate) FileTemplateManager(com.intellij.ide.fileTemplates.FileTemplateManager) AndroidPlatform(org.jetbrains.android.sdk.AndroidPlatform) Module(com.intellij.openapi.module.Module) NotNull(org.jetbrains.annotations.NotNull)

Example 28 with FileTemplate

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

the class AndroidStudioInitializer method setUpNewProjectActions.

private static void setUpNewProjectActions() {
    replaceAction("NewClass", new CreateClassAction());
    // Update the text for the file creation templates.
    FileTemplateManager fileTemplateManager = FileTemplateManager.getDefaultInstance();
    fileTemplateManager.getTemplate("Singleton").setText(fileTemplateManager.getJ2eeTemplate("Singleton").getText());
    for (String templateName : new String[] { "Class", "Interface", "Enum", "AnnotationType" }) {
        FileTemplate template = fileTemplateManager.getInternalTemplate(templateName);
        template.setText(fileTemplateManager.getJ2eeTemplate(templateName).getText());
    }
}
Also used : CreateClassAction(com.android.tools.idea.actions.CreateClassAction) FileTemplate(com.intellij.ide.fileTemplates.FileTemplate) FileTemplateManager(com.intellij.ide.fileTemplates.FileTemplateManager)

Example 29 with FileTemplate

use of com.intellij.ide.fileTemplates.FileTemplate in project intellij-plugins by JetBrains.

the class FlexMainStep method commit.

@Override
public void commit(final CommitType commitType) throws CommitStepException {
    super.commit(commitType);
    // let's replace parent component only if template contains 'Superclass' macro
    final FileTemplate template;
    try {
        template = ClassLoaderUtil.runWithClassLoader(ActionScriptCreateClassOrInterfaceFix.class.getClassLoader(), new ThrowableComputable<FileTemplate, IOException>() {

            @Override
            public FileTemplate compute() throws IOException {
                return FileTemplateManager.getDefaultInstance().getInternalTemplate(myModel.getTemplateName());
            }
        });
        String[] attributes = FileTemplateUtil.calculateAttributes(template.getText(), new Properties(), true, myProject);
        if (ArrayUtil.contains(ActionScriptCreateClassOrInterfaceFix.SUPERCLASS, attributes)) {
            myModel.setSuperclassFqn(getSuperclassFqn());
        }
    } catch (IOException e) {
    // ignore as the action will not succeed
    } catch (ParseException e) {
    // ignore as the action will not succeed
    }
}
Also used : FileTemplate(com.intellij.ide.fileTemplates.FileTemplate) ThrowableComputable(com.intellij.openapi.util.ThrowableComputable) IOException(java.io.IOException) ParseException(org.apache.velocity.runtime.parser.ParseException) Properties(java.util.Properties)

Example 30 with FileTemplate

use of com.intellij.ide.fileTemplates.FileTemplate in project intellij-plugins by JetBrains.

the class CreateStrutsXmlAction method create.

@NotNull
protected PsiElement[] create(final String newName, final PsiDirectory directory) throws Exception {
    @NonNls final String fileName = getFileName(newName);
    final Module module = ModuleUtilCore.findModuleForPsiElement(directory);
    StrutsFileTemplateProvider templateProvider = new StrutsFileTemplateProvider(module);
    final FileTemplate strutsXmlTemplate = templateProvider.determineFileTemplate(directory.getProject());
    final PsiElement file = FileTemplateUtil.createFromTemplate(strutsXmlTemplate, fileName, null, directory);
    return new PsiElement[] { file };
}
Also used : NonNls(org.jetbrains.annotations.NonNls) FileTemplate(com.intellij.ide.fileTemplates.FileTemplate) Module(com.intellij.openapi.module.Module) PsiElement(com.intellij.psi.PsiElement) StrutsFileTemplateProvider(com.intellij.struts2.StrutsFileTemplateProvider) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

FileTemplate (com.intellij.ide.fileTemplates.FileTemplate)66 FileTemplateManager (com.intellij.ide.fileTemplates.FileTemplateManager)20 Project (com.intellij.openapi.project.Project)13 IOException (java.io.IOException)12 PsiFile (com.intellij.psi.PsiFile)10 Properties (java.util.Properties)10 VirtualFile (com.intellij.openapi.vfs.VirtualFile)8 IncorrectOperationException (com.intellij.util.IncorrectOperationException)8 PsiDirectory (com.intellij.psi.PsiDirectory)7 NotNull (org.jetbrains.annotations.NotNull)7 PsiElement (com.intellij.psi.PsiElement)6 Module (com.intellij.openapi.module.Module)5 File (java.io.File)5 GrMethod (org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod)5 Nullable (org.jetbrains.annotations.Nullable)4 Editor (com.intellij.openapi.editor.Editor)3 ConfigurationException (com.intellij.openapi.options.ConfigurationException)3 ArrayList (java.util.ArrayList)3 Pattern (java.util.regex.Pattern)3 ReformatCodeProcessor (com.intellij.codeInsight.actions.ReformatCodeProcessor)2