diff --git a/python/ide/src/com/jetbrains/python/newProject/actions/AbstractProjectSettingsStep.java b/python/ide/src/com/jetbrains/python/newProject/actions/AbstractProjectSettingsStep.java index 46f2801145a4..04f81871c47a 100644 --- a/python/ide/src/com/jetbrains/python/newProject/actions/AbstractProjectSettingsStep.java +++ b/python/ide/src/com/jetbrains/python/newProject/actions/AbstractProjectSettingsStep.java @@ -107,6 +107,9 @@ abstract public class AbstractProjectSettingsStep extends AbstractActionWithPane final JPanel scrollPanel = new JPanel(new BorderLayout()); mainPanel.setPreferredSize(new Dimension(mainPanel.getPreferredSize().width, 400)); + myErrorLabel = new JLabel(""); + myErrorLabel.setForeground(JBColor.RED); + myCreateButton = new Button(myCreateAction, myCreateAction.getTemplatePresentation()); final JPanel panel = createBasePanel(); scrollPanel.add(panel, BorderLayout.NORTH); @@ -120,11 +123,9 @@ abstract public class AbstractProjectSettingsStep extends AbstractActionWithPane mainPanel.add(scrollPane, BorderLayout.CENTER); final JPanel bottomPanel = new JPanel(new BorderLayout()); - myCreateButton = new Button(myCreateAction, myCreateAction.getTemplatePresentation()); + myCreateButton.setPreferredSize(new Dimension(mainPanel.getPreferredSize().width, 40)); - myErrorLabel = new JLabel(""); - myErrorLabel.setForeground(JBColor.RED); bottomPanel.add(myErrorLabel, BorderLayout.NORTH); bottomPanel.add(myCreateButton, BorderLayout.CENTER); mainPanel.add(bottomPanel, BorderLayout.SOUTH); @@ -242,7 +243,7 @@ abstract public class AbstractProjectSettingsStep extends AbstractActionWithPane return false; } if (myProjectGenerator instanceof PythonProjectGenerator) { - final ValidationResult warningResult = ((PythonProjectGenerator)myProjectGenerator).warningValidation(); + final ValidationResult warningResult = ((PythonProjectGenerator)myProjectGenerator).warningValidation(getSdk()); if (!warningResult.isOk()) { setWarningText(warningResult.getErrorMessage()); } diff --git a/python/openapi/src/com/jetbrains/python/newProject/PythonProjectGenerator.java b/python/openapi/src/com/jetbrains/python/newProject/PythonProjectGenerator.java index 4f98e3f8e0f3..5577959178ce 100644 --- a/python/openapi/src/com/jetbrains/python/newProject/PythonProjectGenerator.java +++ b/python/openapi/src/com/jetbrains/python/newProject/PythonProjectGenerator.java @@ -2,6 +2,7 @@ package com.jetbrains.python.newProject; import com.intellij.facet.ui.ValidationResult; import com.intellij.openapi.progress.ProcessCanceledException; +import com.intellij.openapi.projectRoots.Sdk; import com.intellij.util.containers.ContainerUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -22,7 +23,7 @@ public abstract class PythonProjectGenerator { return new PyNewProjectSettings(); } - public ValidationResult warningValidation() { + public ValidationResult warningValidation(@Nullable final Sdk sdk) { return ValidationResult.OK; } diff --git a/python/openapi/src/com/jetbrains/python/templateLanguages/PyTemplatesUtil.java b/python/openapi/src/com/jetbrains/python/templateLanguages/PyTemplatesUtil.java new file mode 100644 index 000000000000..e660029fe384 --- /dev/null +++ b/python/openapi/src/com/jetbrains/python/templateLanguages/PyTemplatesUtil.java @@ -0,0 +1,65 @@ +/* + * Copyright 2000-2013 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.jetbrains.python.templateLanguages; + +import com.intellij.facet.ui.ValidationResult; +import com.intellij.openapi.projectRoots.Sdk; +import com.jetbrains.python.packaging.PyExternalProcessException; +import com.jetbrains.python.packaging.PyPackage; +import com.jetbrains.python.packaging.PyPackageManager; +import org.jetbrains.annotations.NonNls; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +public class PyTemplatesUtil { + private PyTemplatesUtil(){} + + public static ValidationResult checkInstalled(@Nullable final Sdk sdk, @NotNull final TemplateLanguagePanel templatesPanel, + @NotNull final String prefix) { + if (sdk == null) return ValidationResult.OK; + String templateBinding = null; + @NonNls String language = templatesPanel.getTemplateLanguage(); + if (language != null) { + if (language.equals(TemplatesService.JINJA2)) language = "jinja"; + templateBinding = prefix + language.toLowerCase(); + } + final PyPackageManager packageManager = PyPackageManager.getInstance(sdk); + if (templateBinding != null) { + if (TemplatesService.ALL_TEMPLATE_BINDINGS.contains(templateBinding)) { + try { + final PyPackage installedPackage = packageManager.findInstalledPackage(templateBinding); + if (installedPackage == null) + return new ValidationResult(templateBinding + " will be installed on selected interpreter"); + } + catch (PyExternalProcessException ignored) { + } + } + } + if (language != null) { + try { + final PyPackage installedPackage = packageManager.findInstalledPackage(language); + if (installedPackage == null) { + return new ValidationResult(language + " will be installed on selected interpreter"); + } + } + catch (PyExternalProcessException ignored) { + } + } + return null; + } + +} + diff --git a/python/openapi/src/com/jetbrains/python/templateLanguages/TemplateLanguagePanel.java b/python/openapi/src/com/jetbrains/python/templateLanguages/TemplateLanguagePanel.java index 60a2d60df622..d2c453e785d2 100644 --- a/python/openapi/src/com/jetbrains/python/templateLanguages/TemplateLanguagePanel.java +++ b/python/openapi/src/com/jetbrains/python/templateLanguages/TemplateLanguagePanel.java @@ -1,5 +1,6 @@ package com.jetbrains.python.templateLanguages; +import com.intellij.facet.ui.FacetValidatorsManager; import com.intellij.openapi.fileChooser.FileChooserDescriptor; import com.intellij.openapi.fileChooser.FileChooserDescriptorFactory; import com.intellij.ui.components.JBLabel; @@ -7,6 +8,8 @@ import org.jetbrains.annotations.NotNull; import javax.swing.*; import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; import java.util.List; public class TemplateLanguagePanel extends JPanel { @@ -58,4 +61,13 @@ public class TemplateLanguagePanel extends JPanel { public Dimension getLabelSize() { return new JBLabel("Template language:").getPreferredSize(); } + + public void registerValidators(final FacetValidatorsManager validatorsManager) { + myTemplateLanguage.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + validatorsManager.validate(); + } + }); + } } diff --git a/python/openapi/src/com/jetbrains/python/templateLanguages/TemplatesService.java b/python/openapi/src/com/jetbrains/python/templateLanguages/TemplatesService.java index 3ae31049068d..73603e4b573a 100644 --- a/python/openapi/src/com/jetbrains/python/templateLanguages/TemplatesService.java +++ b/python/openapi/src/com/jetbrains/python/templateLanguages/TemplatesService.java @@ -44,6 +44,9 @@ public abstract class TemplatesService { WEB2PY, CHAMELEON); + public static List ALL_TEMPLATE_BINDINGS = ContainerUtil.immutableList("django-mako", "django-jinja", "django-chameleon", + "flask-mako", "pyramid_jinja2"); + public abstract Language getSelectedTemplateLanguage(); public static TemplatesService getInstance(Module module) {