Search in sources :

Example 1 with ValidationResult

use of com.intellij.facet.ui.ValidationResult in project intellij-community by JetBrains.

the class PyStudyDirectoryProjectGenerator method validate.

@NotNull
@Override
public ValidationResult validate(@NotNull String s) {
    final Project project = ProjectManager.getInstance().getDefaultProject();
    final List<Sdk> sdks = PyConfigurableInterpreterList.getInstance(project).getAllPythonSdks();
    if (sdks.isEmpty()) {
        myValidationResult = new ValidationResult(NO_PYTHON_INTERPRETER);
    }
    return myValidationResult;
}
Also used : Project(com.intellij.openapi.project.Project) PyDetectedSdk(com.jetbrains.python.sdk.PyDetectedSdk) Sdk(com.intellij.openapi.projectRoots.Sdk) ValidationResult(com.intellij.facet.ui.ValidationResult) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with ValidationResult

use of com.intellij.facet.ui.ValidationResult in project intellij-community by JetBrains.

the class TemplateProjectDirectoryGenerator method validate.

@NotNull
@Override
public ValidationResult validate(@NotNull String baseDirPath) {
    String message = "Invalid settings";
    for (WizardInputField field : myTemplate.getInputFields()) {
        try {
            if (field.validate()) {
                continue;
            }
        } catch (ConfigurationException e) {
            message = e.getMessage();
        }
        return new ValidationResult(message);
    }
    ValidationResult result = myTemplate.validate(baseDirPath);
    if (result != null) {
        return result;
    }
    return ValidationResult.OK;
}
Also used : ConfigurationException(com.intellij.openapi.options.ConfigurationException) WizardInputField(com.intellij.ide.util.projectWizard.WizardInputField) ValidationResult(com.intellij.facet.ui.ValidationResult) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with ValidationResult

use of com.intellij.facet.ui.ValidationResult in project intellij-community by JetBrains.

the class ProjectSettingsStepBase method checkValid.

public boolean checkValid() {
    if (myLocationField == null)
        return true;
    final String projectName = myLocationField.getText();
    setErrorText(null);
    if (projectName.trim().isEmpty()) {
        setErrorText("Project name can't be empty");
        return false;
    }
    if (myLocationField.getText().indexOf('$') >= 0) {
        setErrorText("Project directory name must not contain the $ character");
        return false;
    }
    if (myProjectGenerator != null) {
        final String baseDirPath = myLocationField.getTextField().getText();
        ValidationResult validationResult = myProjectGenerator.validate(baseDirPath);
        if (!validationResult.isOk()) {
            setErrorText(validationResult.getErrorMessage());
            return false;
        }
        if (myProjectGenerator instanceof WebProjectTemplate) {
            final WebProjectGenerator.GeneratorPeer peer = ((WebProjectTemplate) myProjectGenerator).getPeer();
            final ValidationInfo validationInfo = peer.validate();
            if (validationInfo != null) {
                setErrorText(validationInfo.message);
                return false;
            }
        }
    }
    return true;
}
Also used : WebProjectGenerator(com.intellij.platform.WebProjectGenerator) ValidationResult(com.intellij.facet.ui.ValidationResult)

Example 4 with ValidationResult

use of com.intellij.facet.ui.ValidationResult in project intellij-community by JetBrains.

the class FacetLibrariesValidatorImpl method check.

@NotNull
public ValidationResult check() {
    if (myRequiredLibraries == null) {
        return ValidationResult.OK;
    }
    List<VirtualFile> roots = collectRoots(myContext.getRootModel());
    RequiredLibrariesInfo.RequiredClassesNotFoundInfo info = myRequiredLibraries.checkLibraries(VfsUtil.toVirtualFileArray(roots));
    if (info == null) {
        return ValidationResult.OK;
    }
    String missingJars = IdeBundle.message("label.missed.libraries.prefix") + " " + info.getMissingJarsText();
    LibraryInfo[] missingLibraries = info.getLibraryInfos();
    CustomLibraryDescription description = new OldCustomLibraryDescription(missingLibraries, myDescription.getDefaultLibraryName());
    return new ValidationResult(missingJars, new LibrariesQuickFix(description));
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) LibraryInfo(com.intellij.facet.ui.libraries.LibraryInfo) OldCustomLibraryDescription(com.intellij.ide.util.frameworkSupport.OldCustomLibraryDescription) ValidationResult(com.intellij.facet.ui.ValidationResult) CustomLibraryDescription(com.intellij.openapi.roots.ui.configuration.libraries.CustomLibraryDescription) OldCustomLibraryDescription(com.intellij.ide.util.frameworkSupport.OldCustomLibraryDescription) NotNull(org.jetbrains.annotations.NotNull)

Example 5 with ValidationResult

use of com.intellij.facet.ui.ValidationResult in project intellij-community by JetBrains.

the class ProjectSpecificSettingsStep method checkValid.

@Override
public boolean checkValid() {
    myInstallFramework = false;
    if (!super.checkValid()) {
        return false;
    }
    if (myProjectGenerator instanceof PythonProjectGenerator) {
        final Sdk sdk = getSdk();
        if (sdk == null) {
            if (!((PythonProjectGenerator) myProjectGenerator).hideInterpreter()) {
                setErrorText("No Python interpreter selected");
                return false;
            }
            return true;
        }
        if (PythonSdkType.isInvalid(sdk)) {
            setErrorText("Choose valid python interpreter");
            return false;
        }
        final List<String> warningList = new ArrayList<>();
        final boolean isPy3k = PythonSdkType.getLanguageLevelForSdk(sdk).isPy3K();
        try {
            acceptsSdk(myProjectGenerator, sdk, new File(myLocationField.getText()));
        } catch (final PythonProjectGenerator.PyNoProjectAllowedOnSdkException e) {
            setErrorText(e.getMessage());
            return false;
        }
        if (myRemotePathRequired && StringUtil.isEmpty(myRemotePathField.getTextField().getText())) {
            setErrorText("Remote path not provided");
            return false;
        }
        if (myProjectGenerator instanceof PyFrameworkProjectGenerator) {
            PyFrameworkProjectGenerator frameworkProjectGenerator = (PyFrameworkProjectGenerator) myProjectGenerator;
            String frameworkName = frameworkProjectGenerator.getFrameworkTitle();
            if (!isFrameworkInstalled(sdk)) {
                if (PyPackageUtil.packageManagementEnabled(sdk)) {
                    myInstallFramework = true;
                    final List<PyPackage> packages = PyPackageUtil.refreshAndGetPackagesModally(sdk);
                    if (packages == null) {
                        warningList.add(frameworkName + " will be installed on the selected interpreter");
                        return false;
                    }
                    if (!PyPackageUtil.hasManagement(packages)) {
                        warningList.add("Python packaging tools and " + frameworkName + " will be installed on the selected interpreter");
                    } else {
                        warningList.add(frameworkName + " will be installed on the selected interpreter");
                    }
                } else {
                    warningList.add(frameworkName + " is not installed on the selected interpreter");
                }
            }
            final ValidationResult warningResult = ((PythonProjectGenerator) myProjectGenerator).warningValidation(sdk);
            if (!warningResult.isOk()) {
                warningList.add(warningResult.getErrorMessage());
            }
            if (!warningList.isEmpty()) {
                final String warning = StringUtil.join(warningList, "<br/>");
                setWarningText(warning);
            }
            if (isPy3k && !((PyFrameworkProjectGenerator) myProjectGenerator).supportsPython3()) {
                setErrorText(frameworkName + " is not supported for the selected interpreter");
                return false;
            }
        }
    }
    return true;
}
Also used : PyPackage(com.jetbrains.python.packaging.PyPackage) PythonProjectGenerator(com.jetbrains.python.newProject.PythonProjectGenerator) PyFrameworkProjectGenerator(com.jetbrains.python.newProject.PyFrameworkProjectGenerator) ArrayList(java.util.ArrayList) Sdk(com.intellij.openapi.projectRoots.Sdk) ValidationResult(com.intellij.facet.ui.ValidationResult) File(java.io.File)

Aggregations

ValidationResult (com.intellij.facet.ui.ValidationResult)9 NotNull (org.jetbrains.annotations.NotNull)6 Sdk (com.intellij.openapi.projectRoots.Sdk)3 FacetErrorPanel (com.intellij.facet.impl.ui.FacetErrorPanel)2 FacetEditorValidator (com.intellij.facet.ui.FacetEditorValidator)2 PythonProjectGenerator (com.jetbrains.python.newProject.PythonProjectGenerator)2 LibraryInfo (com.intellij.facet.ui.libraries.LibraryInfo)1 OldCustomLibraryDescription (com.intellij.ide.util.frameworkSupport.OldCustomLibraryDescription)1 WebProjectTemplate (com.intellij.ide.util.projectWizard.WebProjectTemplate)1 WizardInputField (com.intellij.ide.util.projectWizard.WizardInputField)1 ConfigurationException (com.intellij.openapi.options.ConfigurationException)1 Project (com.intellij.openapi.project.Project)1 CustomLibraryDescription (com.intellij.openapi.roots.ui.configuration.libraries.CustomLibraryDescription)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 WebProjectGenerator (com.intellij.platform.WebProjectGenerator)1 HideableDecorator (com.intellij.ui.HideableDecorator)1 PyFrameworkProjectGenerator (com.jetbrains.python.newProject.PyFrameworkProjectGenerator)1 PyPackage (com.jetbrains.python.packaging.PyPackage)1 PyDetectedSdk (com.jetbrains.python.sdk.PyDetectedSdk)1 File (java.io.File)1