Search in sources :

Example 1 with TemplateMetadata

use of com.android.tools.idea.templates.TemplateMetadata in project android by JetBrains.

the class NewFormFactorModulePath method getAvailableFormFactorModulePaths.

public static List<NewFormFactorModulePath> getAvailableFormFactorModulePaths(@NotNull Disposable disposable) {
    TemplateManager manager = TemplateManager.getInstance();
    List<File> applicationTemplates = manager.getTemplatesInCategory(Template.CATEGORY_APPLICATION);
    List<NewFormFactorModulePath> toReturn = Lists.newArrayList();
    for (File templateFile : applicationTemplates) {
        TemplateMetadata metadata = manager.getTemplateMetadata(templateFile);
        if (metadata == null || metadata.getFormFactor() == null) {
            continue;
        }
        FormFactor formFactor = FormFactor.get(metadata.getFormFactor());
        if (formFactor == FormFactor.GLASS && !AndroidSdkUtils.isGlassInstalled()) {
            // Only show Glass if you've already installed the SDK
            continue;
        }
        NewFormFactorModulePath path = new NewFormFactorModulePath(formFactor, templateFile, disposable);
        toReturn.add(path);
    }
    Collections.sort(toReturn, (p1, p2) -> p1.myFormFactor.compareTo(p2.myFormFactor));
    return toReturn;
}
Also used : TemplateManager(com.android.tools.idea.templates.TemplateManager) File(java.io.File) TemplateMetadata(com.android.tools.idea.templates.TemplateMetadata)

Example 2 with TemplateMetadata

use of com.android.tools.idea.templates.TemplateMetadata in project android by JetBrains.

the class ImportSourceModulePath method createImportTemplateWithCustomName.

@NotNull
protected static MetadataListItem createImportTemplateWithCustomName(@NotNull final String importTemplateName, @Nullable final String description) {
    // Now, we're going to add in two pointers to the same template
    File moduleTemplate = new File(TemplateManager.getTemplateRootFolder(), FileUtil.join(Template.CATEGORY_PROJECTS, "ImportExistingProject"));
    TemplateManager manager = TemplateManager.getInstance();
    TemplateMetadata metadata = manager.getTemplateMetadata(moduleTemplate);
    assert metadata != null;
    return new MetadataListItem(moduleTemplate, metadata) {

        @Override
        public String toString() {
            return importTemplateName;
        }

        @Nullable
        @Override
        public String getDescription() {
            return description == null ? super.getDescription() : description;
        }
    };
}
Also used : MetadataListItem(com.android.tools.idea.npw.ChooseTemplateStep.MetadataListItem) TemplateManager(com.android.tools.idea.templates.TemplateManager) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) TemplateMetadata(com.android.tools.idea.templates.TemplateMetadata) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with TemplateMetadata

use of com.android.tools.idea.templates.TemplateMetadata in project android by JetBrains.

the class TemplateWizardStep method deriveValues.

/**
   * Called by update() to write derived values to the template model.
   */
protected void deriveValues() {
    TemplateMetadata metadata = myTemplateState.getTemplateMetadata();
    if (metadata == null) {
        return;
    }
    for (String changedParamId : myIdsWithNewValues) {
        for (String paramName : myParamFields.keySet()) {
            Parameter param = myTemplateState.hasTemplate() ? metadata.getParameter(paramName) : null;
            // If this parameter is null or doesn't have anything to update (both visibility and suggestion are null or empty), skip it.
            if (param == null || ((param.suggest == null || param.suggest.isEmpty()) && (param.visibility == null || param.visibility.isEmpty()))) {
                continue;
            }
            // If this parameter has dynamic visibility, calculate it and process accordingly
            if (param.visibility != null && param.visibility.contains(changedParamId)) {
                updateVisibility(param);
            }
            // Don't process hidden fields
            if (myTemplateState.myHidden.contains(paramName)) {
                continue;
            }
            // and add it for consideration so that things dependent on it can be updated
            if (param.suggest != null && param.suggest.contains(changedParamId)) {
                final String updated = myStringEvaluator.evaluate(param.suggest, myTemplateState.getParameters());
                if (updated != null && !updated.equals(myTemplateState.get(param.id))) {
                    myIdsWithNewValues.add(param.id);
                    updateDerivedValue(param.id, (JTextField) myParamFields.get(param.id), new Callable<String>() {

                        @Override
                        public String call() throws Exception {
                            return updated;
                        }
                    });
                }
            }
        }
    }
}
Also used : Parameter(com.android.tools.idea.templates.Parameter) TemplateMetadata(com.android.tools.idea.templates.TemplateMetadata)

Example 4 with TemplateMetadata

use of com.android.tools.idea.templates.TemplateMetadata in project android by JetBrains.

the class NewAndroidModuleDescriptionProvider method getDescriptions.

@Override
public Collection<ModuleTemplateGalleryEntry> getDescriptions() {
    ArrayList<ModuleTemplateGalleryEntry> res = new ArrayList<>();
    TemplateManager manager = TemplateManager.getInstance();
    List<File> applicationTemplates = manager.getTemplatesInCategory(Template.CATEGORY_APPLICATION);
    for (File templateFile : applicationTemplates) {
        TemplateMetadata metadata = manager.getTemplateMetadata(templateFile);
        if (metadata == null || metadata.getFormFactor() == null) {
            continue;
        }
        int minSdk = metadata.getMinSdk();
        FormFactor formFactor = FormFactor.get(metadata.getFormFactor());
        if (formFactor == FormFactor.CAR) {
        // Auto is not a standalone module (but rather a modification to a mobile module)
        } else if (formFactor == FormFactor.GLASS && !AndroidSdkUtils.isGlassInstalled()) {
        // Hidden if not installed
        } else if (formFactor.equals(FormFactor.MOBILE)) {
            res.add(new AndroidModuleTemplateGalleryEntry(templateFile, formFactor, minSdk, false, AndroidIcons.ModuleTemplates.Mobile, message("android.wizard.module.new.mobile"), metadata.getTitle()));
            res.add(new AndroidModuleTemplateGalleryEntry(templateFile, formFactor, minSdk, true, AndroidIcons.ModuleTemplates.Android, message("android.wizard.module.new.library"), metadata.getDescription()));
        } else {
            res.add(new AndroidModuleTemplateGalleryEntry(templateFile, formFactor, minSdk, false, getModuleTypeIcon(formFactor), metadata.getTitle(), metadata.getDescription()));
        }
    }
    return res;
}
Also used : FormFactor(com.android.tools.idea.npw.FormFactor) ArrayList(java.util.ArrayList) TemplateManager(com.android.tools.idea.templates.TemplateManager) File(java.io.File) TemplateMetadata(com.android.tools.idea.templates.TemplateMetadata)

Example 5 with TemplateMetadata

use of com.android.tools.idea.templates.TemplateMetadata in project android by JetBrains.

the class TemplateListProvider method getTemplateList.

/**
   * Search the given folder for a list of templates and populate the display list.
   */
private static TemplateEntry[] getTemplateList(@NotNull FormFactor formFactor, @NotNull String category, @Nullable Set<String> excluded) {
    TemplateManager manager = TemplateManager.getInstance();
    List<File> templates = manager.getTemplatesInCategory(category);
    List<TemplateEntry> metadataList = new ArrayList<>(templates.size());
    for (File template : templates) {
        TemplateMetadata metadata = manager.getTemplateMetadata(template);
        if (metadata == null || !metadata.isSupported()) {
            continue;
        }
        // Don't include this template if it's been excluded
        if (excluded != null && excluded.contains(metadata.getTitle())) {
            continue;
        }
        // If a form factor has been specified, ensure that requirement is met.
        if (!formFactor.id.equalsIgnoreCase(metadata.getFormFactor())) {
            continue;
        }
        metadataList.add(new TemplateEntry(template, metadata));
    }
    return ArrayUtil.toObjectArray(metadataList, TemplateEntry.class);
}
Also used : TemplateManager(com.android.tools.idea.templates.TemplateManager) File(java.io.File) TemplateMetadata(com.android.tools.idea.templates.TemplateMetadata)

Aggregations

TemplateMetadata (com.android.tools.idea.templates.TemplateMetadata)13 File (java.io.File)9 TemplateManager (com.android.tools.idea.templates.TemplateManager)7 TemplateWizardState (com.android.tools.idea.wizard.template.TemplateWizardState)2 ArrayList (java.util.ArrayList)2 NotNull (org.jetbrains.annotations.NotNull)2 Element (org.w3c.dom.Element)2 SourceProvider (com.android.builder.model.SourceProvider)1 AndroidVersion (com.android.sdklib.AndroidVersion)1 IAndroidTarget (com.android.sdklib.IAndroidTarget)1 AndroidModuleInfo (com.android.tools.idea.model.AndroidModuleInfo)1 MetadataListItem (com.android.tools.idea.npw.ChooseTemplateStep.MetadataListItem)1 FormFactor (com.android.tools.idea.npw.FormFactor)1 NewProjectWizardState (com.android.tools.idea.npw.NewProjectWizardState)1 TemplateProcessingException (com.android.tools.idea.templates.FreemarkerUtils.TemplateProcessingException)1 TemplateUserVisibleException (com.android.tools.idea.templates.FreemarkerUtils.TemplateUserVisibleException)1 Parameter (com.android.tools.idea.templates.Parameter)1 Constraint (com.android.tools.idea.templates.Parameter.Constraint)1 Module (com.intellij.openapi.module.Module)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1