Search in sources :

Example 26 with ValidationInfo

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

the class ScreenRecorderOptionsDialog method validateIntegerMultipleOf.

@Nullable
private static ValidationInfo validateIntegerMultipleOf(JTextField textField, int multiple, String errorMessage) {
    String s = getText(textField);
    if (s.isEmpty()) {
        return null;
    }
    int x;
    try {
        x = Integer.parseInt(s);
    } catch (NumberFormatException e) {
        return new ValidationInfo(errorMessage, textField);
    }
    return (x % multiple > 0) ? new ValidationInfo("Must be a multiple of " + multiple, textField) : null;
}
Also used : ValidationInfo(com.intellij.openapi.ui.ValidationInfo) Nullable(org.jetbrains.annotations.Nullable)

Example 27 with ValidationInfo

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

the class ConvertHprofDialog method doValidate.

@Nullable
@Override
protected ValidationInfo doValidate() {
    String path = myPathTextFieldWithButton.getText().trim();
    JTextField textField = myPathTextFieldWithButton.getTextField();
    if (path.isEmpty()) {
        return new ValidationInfo("Destination should not be empty", textField);
    }
    File f = new File(path);
    if (!f.isAbsolute()) {
        return new ValidationInfo("Destination path must be absolute.", textField);
    }
    if (f.getParentFile() == null || !f.getParentFile().isDirectory()) {
        return new ValidationInfo("Invalid path", textField);
    }
    return null;
}
Also used : ValidationInfo(com.intellij.openapi.ui.ValidationInfo) File(java.io.File) Nullable(org.jetbrains.annotations.Nullable)

Example 28 with ValidationInfo

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

the class CreateXmlResourcePanelImpl method doValidate.

/**
   * @see CreateXmlResourceDialog#doValidate()
   */
@Override
public ValidationInfo doValidate() {
    String resourceName = getResourceName();
    Module selectedModule = getModule();
    VirtualFile resourceDir = getResourceDirectory();
    List<String> directoryNames = getDirNames();
    String fileName = getFileName();
    if (myNameField.isVisible() && resourceName.isEmpty()) {
        return new ValidationInfo("specify resource name", myNameField);
    } else if (myNameField.isVisible() && !AndroidResourceUtil.isCorrectAndroidResourceName(resourceName)) {
        return new ValidationInfo(resourceName + " is not correct resource name", myNameField);
    } else if (fileName.isEmpty()) {
        return new ValidationInfo("specify file name", myFileNameCombo);
    } else if (selectedModule == null) {
        return new ValidationInfo("specify module", myModuleCombo);
    } else if (resourceDir == null) {
        return new ValidationInfo("specify a module with resources", myModuleCombo);
    } else if (directoryNames.isEmpty()) {
        return new ValidationInfo("choose directories", myDirectoriesPanel);
    } else if (resourceName.equals(ResourceHelper.prependResourcePrefix(myModule, null, myFolderType))) {
        return new ValidationInfo("specify more than resource prefix", myNameField);
    }
    return CreateXmlResourceDialog.checkIfResourceAlreadyExists(selectedModule.getProject(), resourceDir, resourceName, myResourceType, directoryNames, fileName);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ValidationInfo(com.intellij.openapi.ui.ValidationInfo) Module(com.intellij.openapi.module.Module)

Example 29 with ValidationInfo

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

the class AddAdapterSupportDialog method doValidate.

@Override
@Nullable
protected ValidationInfo doValidate() {
    String text = myDirectoryTextField.getText();
    File dir = new File(text);
    if (!dir.isDirectory() || !dir.isAbsolute()) {
        return new ValidationInfo("Not a valid directory", myDirectoryTextField);
    }
    return null;
}
Also used : ValidationInfo(com.intellij.openapi.ui.ValidationInfo) VirtualFile(com.intellij.openapi.vfs.VirtualFile) PsiFile(com.intellij.psi.PsiFile) File(java.io.File) Nullable(org.jetbrains.annotations.Nullable)

Example 30 with ValidationInfo

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

the class AirPackageDialog method doValidate.

protected ValidationInfo doValidate() {
    final Collection<Pair<Module, FlexBuildConfiguration>> modulesAndBCs = getSelectedBCs();
    if (modulesAndBCs.isEmpty())
        return new ValidationInfo("Please select one or more build configurations");
    if (myApkDebugPortTextField.isVisible() && myApkDebugPortPanel.isEnabled()) {
        try {
            final String portValue = myApkDebugPortTextField.getText().trim();
            final int port = portValue.isEmpty() ? AirPackageUtil.DEBUG_PORT_DEFAULT : Integer.parseInt(portValue);
            if (port <= 0 || port > 65535)
                return new ValidationInfo("Incorrect port", myApkDebugPortPanel);
        } catch (NumberFormatException e) {
            return new ValidationInfo("Incorrect port", myApkDebugPortTextField);
        }
    }
    for (Pair<Module, FlexBuildConfiguration> moduleAndBC : modulesAndBCs) {
        final FlexBuildConfiguration bc = moduleAndBC.second;
        if (bc.isSkipCompile() && LocalFileSystem.getInstance().findFileByPath(bc.getActualOutputFilePath()) == null) {
            return new ValidationInfo(FlexBundle.message("can.not.package.bc", bc.getName(), FlexBundle.message("compilation.is.switched.off")));
        }
        final BuildConfigurationNature nature = bc.getNature();
        if (nature.isMobilePlatform()) {
            if (!bc.getAndroidPackagingOptions().isEnabled() && !bc.getIosPackagingOptions().isEnabled()) {
                return new ValidationInfo(FlexBundle.message("can.not.package.bc", bc.getName(), "both Android and iOS packaging disabled"));
            }
            if (bc.getAndroidPackagingOptions().isEnabled() && bc.getIosPackagingOptions().isEnabled()) {
                final AndroidPackageType androidPackage = (AndroidPackageType) myAndroidTypeCombo.getSelectedItem();
                final IOSPackageType iosPackage = (IOSPackageType) myIOSTypeCombo.getSelectedItem();
                final boolean androidDebug = androidPackage != AndroidPackageType.Release;
                final boolean iosDebug = iosPackage == IOSPackageType.DebugOverNetwork;
                if (androidDebug != iosDebug) {
                    return new ValidationInfo(FlexBundle.message("can.not.package.bc", bc.getName(), FlexBundle.message("different.debug.settings", androidDebug ? 1 : 2)));
                }
            }
        }
        final Ref<String> firstErrorRef = new Ref<>();
        ValidateFlashConfigurationsPrecompileTask.checkPackagingOptions(moduleAndBC.first, bc, problem -> {
            if (problem.severity == ProjectStructureProblemType.Severity.ERROR && firstErrorRef.isNull()) {
                firstErrorRef.set(problem.errorMessage);
            }
        });
        // todo better error reporting. May be just mention that errors exist in some BC and provide link to Project Structure
        if (!firstErrorRef.isNull()) {
            return new ValidationInfo(FlexBundle.message("can.not.package.bc", bc.getName(), firstErrorRef.get()));
        }
    }
    return null;
}
Also used : BuildConfigurationNature(com.intellij.flex.model.bc.BuildConfigurationNature) FlexBuildConfiguration(com.intellij.lang.javascript.flex.projectStructure.model.FlexBuildConfiguration) ValidationInfo(com.intellij.openapi.ui.ValidationInfo) Ref(com.intellij.openapi.util.Ref) Module(com.intellij.openapi.module.Module) Pair(com.intellij.openapi.util.Pair)

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