Search in sources :

Example 36 with ValidationInfo

use of com.intellij.openapi.ui.ValidationInfo in project android by JetBrains.

the class ScreenRecorderOptionsDialog method doValidate.

@Nullable
@Override
protected ValidationInfo doValidate() {
    ValidationInfo info = validateIntegerMultipleOf(myBitRateTextField, 1, "Bit Rate must be an integer.");
    if (info != null) {
        return info;
    }
    // MediaEncoder prefers sizes that are multiples of 16 (https://code.google.com/p/android/issues/detail?id=37769).
    info = validateIntegerMultipleOf(myWidthTextField, 16, "Width must be an integer.");
    if (info != null) {
        return info;
    }
    info = validateIntegerMultipleOf(myHeightTextField, 16, "Height must be an integer.");
    if (info != null) {
        return info;
    }
    return super.doValidate();
}
Also used : ValidationInfo(com.intellij.openapi.ui.ValidationInfo) Nullable(org.jetbrains.annotations.Nullable)

Example 37 with ValidationInfo

use of com.intellij.openapi.ui.ValidationInfo in project android by JetBrains.

the class AddLibraryDependencyDialog method doValidate.

@Override
@Nullable
protected ValidationInfo doValidate() {
    List<Exception> searchErrors = myLibraryDependenciesForm.getSearchErrors();
    if (!searchErrors.isEmpty()) {
        StringBuilder buffer = new StringBuilder();
        searchErrors.forEach(e -> buffer.append(getErrorMessage(e)).append("\n"));
        return new ValidationInfo(buffer.toString(), myLibraryDependenciesForm.getPreferredFocusedComponent());
    }
    String selectedLibrary = myLibraryDependenciesForm.getSelectedLibrary();
    if (isEmpty(selectedLibrary)) {
        return new ValidationInfo("Please specify the library to add as dependency", myLibraryDependenciesForm.getPreferredFocusedComponent());
    }
    PsArtifactDependencySpec spec = PsArtifactDependencySpec.create(selectedLibrary);
    PsModule module = getModule();
    if (spec != null && module instanceof PsAndroidModule) {
        PsAndroidModule androidModule = (PsAndroidModule) module;
        Ref<Boolean> found = new Ref<>(false);
        androidModule.forEachDeclaredDependency(dependency -> {
            if (dependency instanceof PsLibraryAndroidDependency) {
                PsLibraryAndroidDependency libraryDependency = (PsLibraryAndroidDependency) dependency;
                PsArtifactDependencySpec resolvedSpec = libraryDependency.getResolvedSpec();
                if (Objects.equals(spec.group, resolvedSpec.group) && Objects.equals(spec.name, resolvedSpec.name)) {
                    found.set(true);
                }
            }
        });
        if (found.get()) {
            String msg = String.format("Library '%1$s' is already a dependency", spec.name);
            return new ValidationInfo(msg, myLibraryDependenciesForm.getPreferredFocusedComponent());
        }
    }
    return getScopesPanel().validateInput();
}
Also used : ValidationInfo(com.intellij.openapi.ui.ValidationInfo) Ref(com.intellij.openapi.util.Ref) PsModule(com.android.tools.idea.gradle.structure.model.PsModule) PsAndroidModule(com.android.tools.idea.gradle.structure.model.android.PsAndroidModule) PsArtifactDependencySpec(com.android.tools.idea.gradle.structure.model.PsArtifactDependencySpec) PsLibraryAndroidDependency(com.android.tools.idea.gradle.structure.model.android.PsLibraryAndroidDependency) UnknownHostException(java.net.UnknownHostException) Nullable(org.jetbrains.annotations.Nullable)

Example 38 with ValidationInfo

use of com.intellij.openapi.ui.ValidationInfo in project android by JetBrains.

the class AndroidDependencyScopesPanel method validateInput.

@Override
@Nullable
public ValidationInfo validateInput() {
    List<Configuration> configurations = myConfigurationsPanel.getSelectedConfigurations();
    if (configurations.isEmpty()) {
        return new ValidationInfo("Please select at least one configuration", myConfigurationsPanel);
    }
    List<PsBuildType> buildTypes = myBuildTypesPanel.getSelectedBuildTypes();
    if (buildTypes.isEmpty()) {
        return new ValidationInfo("Please select at least one build type", myBuildTypesPanel);
    }
    if (mySelectedScopeNames.isEmpty()) {
        if (configurations.size() == 1 && configurations.contains(ANDROID_TEST)) {
            boolean hasDebugBuildType = false;
            for (PsBuildType buildType : buildTypes) {
                if (buildType.getName().equals(DEBUG_BUILD_TYPE)) {
                    hasDebugBuildType = true;
                    break;
                }
            }
            if (!hasDebugBuildType) {
                return new ValidationInfo("For 'Android Tests', the 'debug' build type must be selected", myBuildTypesPanel);
            }
        }
    }
    return null;
}
Also used : ValidationInfo(com.intellij.openapi.ui.ValidationInfo) PsBuildType(com.android.tools.idea.gradle.structure.model.android.PsBuildType) Configuration(com.android.tools.idea.gradle.structure.dependencies.android.Configuration) Nullable(org.jetbrains.annotations.Nullable)

Example 39 with ValidationInfo

use of com.intellij.openapi.ui.ValidationInfo in project android by JetBrains.

the class StateListPicker method doValidate.

/**
   * Returns a {@link ValidationInfo} in the case one of the state list state has a value that does not resolve to a valid resource,
   * or a value that is a private framework value. or if one of the state list component requires an API level higher than minApi.
   */
@Nullable
public /*if there is no error*/
ValidationInfo doValidate(int minApi) {
    IAndroidTarget target = myConfiguration.getRealTarget();
    assert target != null;
    final AndroidTargetData androidTargetData = AndroidTargetData.getTargetData(target, myModule);
    assert androidTargetData != null;
    ResourceRepository frameworkResources = myConfiguration.getFrameworkResources();
    assert frameworkResources != null;
    for (StateComponent component : myStateComponents) {
        ValidationInfo error = component.doValidate(minApi, androidTargetData);
        if (error != null) {
            return error;
        }
    }
    return null;
}
Also used : ValidationInfo(com.intellij.openapi.ui.ValidationInfo) IAndroidTarget(com.android.sdklib.IAndroidTarget) ResourceRepository(com.android.ide.common.resources.ResourceRepository) AndroidTargetData(org.jetbrains.android.sdk.AndroidTargetData) Nullable(org.jetbrains.annotations.Nullable)

Example 40 with ValidationInfo

use of com.intellij.openapi.ui.ValidationInfo in project intellij-plugins by JetBrains.

the class KeystorePasswordDialog method doValidate.

protected ValidationInfo doValidate() {
    for (Trinity<AirSigningOptions, JPasswordField, JPasswordField> entry : myKeystoresAndPasswordFields) {
        final AirSigningOptions signingOptions = entry.first;
        final JPasswordField keystorePasswordField = entry.second;
        final String keystorePassword = new String(keystorePasswordField.getPassword());
        final JPasswordField keyPasswordField = entry.third;
        final String keyPassword = keyPasswordField == null ? "" : new String(keyPasswordField.getPassword());
        try {
            PasswordStore.checkPassword(signingOptions, keystorePassword, keyPassword);
        } catch (PasswordStore.SigningOptionsException e) {
            final JPasswordField errorField = e.wrongKeyPassword ? keyPasswordField : e.wrongKeystorePassword ? keystorePasswordField : null;
            final String message = errorField == null ? PathUtil.getFileName(signingOptions.getKeystorePath()) + ": " + e.getMessage() : e.getMessage();
            return new ValidationInfo(message, errorField);
        }
    }
    return null;
}
Also used : ValidationInfo(com.intellij.openapi.ui.ValidationInfo) AirSigningOptions(com.intellij.lang.javascript.flex.projectStructure.model.AirSigningOptions)

Aggregations

ValidationInfo (com.intellij.openapi.ui.ValidationInfo)53 Nullable (org.jetbrains.annotations.Nullable)24 VirtualFile (com.intellij.openapi.vfs.VirtualFile)11 File (java.io.File)7 Module (com.intellij.openapi.module.Module)3 Pattern (java.util.regex.Pattern)3 DocumentEvent (javax.swing.event.DocumentEvent)3 DefaultTableModel (javax.swing.table.DefaultTableModel)3 ActionButton (com.intellij.openapi.actionSystem.impl.ActionButton)2 Project (com.intellij.openapi.project.Project)2 PatternSyntaxException (java.util.regex.PatternSyntaxException)2 ResourceRepository (com.android.ide.common.resources.ResourceRepository)1 IAndroidTarget (com.android.sdklib.IAndroidTarget)1 Configuration (com.android.tools.idea.gradle.structure.dependencies.android.Configuration)1 PsArtifactDependencySpec (com.android.tools.idea.gradle.structure.model.PsArtifactDependencySpec)1 PsModule (com.android.tools.idea.gradle.structure.model.PsModule)1 PsAndroidModule (com.android.tools.idea.gradle.structure.model.android.PsAndroidModule)1 PsBuildType (com.android.tools.idea.gradle.structure.model.android.PsBuildType)1 PsLibraryAndroidDependency (com.android.tools.idea.gradle.structure.model.android.PsLibraryAndroidDependency)1 FilterData (com.android.tools.idea.logcat.PersistentAndroidLogFilters.FilterData)1