Search in sources :

Example 16 with ValidationInfo

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

the class ShelfStorageConfigurationDialog method doValidate.

@Nullable
@Override
protected ValidationInfo doValidate() {
    updateOkAction();
    if (myUseCustomShelfDirectory.isSelected()) {
        File toFile = new File(myShelfDirectoryPath.getText());
        // check that file can be created after OK button pressed;
        if (!toFile.exists())
            return null;
        String validationError = null;
        if (!toFile.canRead()) {
            validationError = "Destination shelf directory should have read access";
        }
        if (!toFile.canWrite()) {
            validationError = "Destination shelf directory should have write access";
        }
        if (validationError != null)
            return new ValidationInfo(validationError, myShelfDirectoryPath);
    }
    return super.doValidate();
}
Also used : ValidationInfo(com.intellij.openapi.ui.ValidationInfo) File(java.io.File) Nullable(org.jetbrains.annotations.Nullable)

Example 17 with ValidationInfo

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

the class GenerateVisitorByHierarchyAction method actionPerformed.

public void actionPerformed(AnActionEvent e) {
    final Ref<String> visitorNameRef = Ref.create("MyVisitor");
    final Ref<PsiClass> parentClassRef = Ref.create(null);
    final Project project = e.getData(CommonDataKeys.PROJECT);
    assert project != null;
    final PsiNameHelper helper = PsiNameHelper.getInstance(project);
    final PackageChooserDialog dialog = new PackageChooserDialog("Choose Target Package and Hierarchy Root Class", project) {

        @Override
        protected ValidationInfo doValidate() {
            PsiDocumentManager.getInstance(project).commitAllDocuments();
            if (!helper.isQualifiedName(visitorNameRef.get())) {
                return new ValidationInfo("Visitor class name is not valid");
            } else if (parentClassRef.isNull()) {
                return new ValidationInfo("Hierarchy root class should be specified");
            } else if (parentClassRef.get().isAnnotationType() || parentClassRef.get().isEnum()) {
                return new ValidationInfo("Hierarchy root class should be an interface or a class");
            }
            return super.doValidate();
        }

        protected JComponent createCenterPanel() {
            final JPanel panel = new JPanel(new BorderLayout());
            panel.add(super.createCenterPanel(), BorderLayout.CENTER);
            panel.add(createNamePanel(), BorderLayout.NORTH);
            panel.add(createBaseClassPanel(), BorderLayout.SOUTH);
            return panel;
        }

        private JComponent createNamePanel() {
            LabeledComponent<JTextField> labeledComponent = new LabeledComponent<>();
            labeledComponent.setText("Visitor class");
            final JTextField nameField = new JTextField(visitorNameRef.get());
            labeledComponent.setComponent(nameField);
            nameField.getDocument().addDocumentListener(new DocumentAdapter() {

                protected void textChanged(final DocumentEvent e) {
                    visitorNameRef.set(nameField.getText());
                }
            });
            return labeledComponent;
        }

        private JComponent createBaseClassPanel() {
            LabeledComponent<EditorTextField> labeledComponent = new LabeledComponent<>();
            labeledComponent.setText("Hierarchy root class");
            final JavaCodeFragmentFactory factory = JavaCodeFragmentFactory.getInstance(project);
            final PsiTypeCodeFragment codeFragment = factory.createTypeCodeFragment("", null, true, JavaCodeFragmentFactory.ALLOW_VOID);
            final Document document = PsiDocumentManager.getInstance(project).getDocument(codeFragment);
            final EditorTextField editorTextField = new EditorTextField(document, project, StdFileTypes.JAVA);
            labeledComponent.setComponent(editorTextField);
            editorTextField.addDocumentListener(new com.intellij.openapi.editor.event.DocumentAdapter() {

                public void documentChanged(final com.intellij.openapi.editor.event.DocumentEvent e) {
                    parentClassRef.set(null);
                    try {
                        final PsiType psiType = codeFragment.getType();
                        final PsiClass psiClass = psiType instanceof PsiClassType ? ((PsiClassType) psiType).resolve() : null;
                        parentClassRef.set(psiClass);
                    } catch (PsiTypeCodeFragment.IncorrectTypeException e1) {
                    // ok
                    }
                }
            });
            return labeledComponent;
        }
    };
    final PsiElement element = CommonDataKeys.PSI_ELEMENT.getData(e.getDataContext());
    if (element instanceof PsiPackage) {
        dialog.selectPackage(((PsiPackage) element).getQualifiedName());
    } else if (element instanceof PsiDirectory) {
        final PsiPackage aPackage = JavaDirectoryService.getInstance().getPackage((PsiDirectory) element);
        if (aPackage != null) {
            dialog.selectPackage(aPackage.getQualifiedName());
        }
    }
    dialog.show();
    if (dialog.getExitCode() != DialogWrapper.OK_EXIT_CODE || dialog.getSelectedPackage() == null || dialog.getSelectedPackage().getQualifiedName().length() == 0 || parentClassRef.isNull()) {
        return;
    }
    final String visitorQName = generateEverything(dialog.getSelectedPackage(), parentClassRef.get(), visitorNameRef.get());
    final IdeView ideView = LangDataKeys.IDE_VIEW.getData(e.getDataContext());
    final PsiClass visitorClass = JavaPsiFacade.getInstance(project).findClass(visitorQName, GlobalSearchScope.projectScope(project));
    if (ideView != null && visitorClass != null) {
        ideView.selectElement(visitorClass);
    }
}
Also used : Document(com.intellij.openapi.editor.Document) IdeView(com.intellij.ide.IdeView) EditorTextField(com.intellij.ui.EditorTextField) DocumentAdapter(com.intellij.ui.DocumentAdapter) DocumentEvent(javax.swing.event.DocumentEvent) LabeledComponent(com.intellij.openapi.ui.LabeledComponent) Project(com.intellij.openapi.project.Project) ValidationInfo(com.intellij.openapi.ui.ValidationInfo) PackageChooserDialog(com.intellij.ide.util.PackageChooserDialog)

Example 18 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 19 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)

Example 20 with ValidationInfo

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

the class CreateFileFromTemplateDialog method doValidate.

@Nullable
@Override
protected ValidationInfo doValidate() {
    if (myInputValidator != null) {
        String nameText = myNameField.getText();
        String superclassAsString = mySuperclassField.getText();
        String packageText = myPackageField.getText();
        if (!myInputValidator.checkInput(nameText)) {
            String errorText = LangBundle.message("incorrect.name");
            String message = myInputValidator.getErrorText(nameText);
            if (message != null) {
                errorText = message;
            }
            return new ValidationInfo(errorText, myNameField);
        }
        if (!superclassAsString.isEmpty()) {
            Type superclassAsType = Type.newType(superclassAsString, myProject);
            if (mySuperclassField.isVisible() && (!superclassAsType.canUseAsClass() || !myInputValidator.checkSuperclass(superclassAsString))) {
                return new ValidationInfo(myInputValidator.getSuperclassErrorText(superclassAsString), mySuperclassField);
            }
        }
        for (String interfaceAsString : Splitter.on(',').trimResults().omitEmptyStrings().split(getInterfaces())) {
            Type interfaceAsType = Type.newType(interfaceAsString, myProject);
            if (!interfaceAsType.canUseAsInterface() || !myInputValidator.checkInterface(interfaceAsString)) {
                return new ValidationInfo(myInputValidator.getInterfacesErrorText(interfaceAsString), myInterfacesField);
            }
        }
        if (!myInputValidator.checkPackage(packageText)) {
            return new ValidationInfo(myInputValidator.getPackageErrorText(packageText), myPackageField);
        }
    }
    return super.doValidate();
}
Also used : ValidationInfo(com.intellij.openapi.ui.ValidationInfo) JavaFileType(com.intellij.ide.highlighter.JavaFileType) Nullable(org.jetbrains.annotations.Nullable)

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