Example usage for com.intellij.openapi.ui Messages showErrorDialog

List of usage examples for com.intellij.openapi.ui Messages showErrorDialog

Introduction

In this page you can find the example usage for com.intellij.openapi.ui Messages showErrorDialog.

Prototype

public static void showErrorDialog(@Nullable Component component, String message,
            @NotNull @Nls(capitalization = Nls.Capitalization.Title) String title) 

Source Link

Usage

From source file:com.intellij.ide.util.projectWizard.ExistingModuleLoader.java

License:Apache License

public boolean validate(final Project current, final Project dest) {
    if (getName() == null)
        return false;
    String moduleFilePath = getModuleDirPath();
    if (moduleFilePath == null)
        return false;
    final File file = new File(moduleFilePath);
    if (file.exists()) {
        try {/* w  w  w. ja v a  2 s  .  c o m*/
            final ConversionResult result = ConversionService.getInstance().convertModule(dest, file);
            if (result.openingIsCanceled()) {
                return false;
            }
            final Document document = JDOMUtil.loadDocument(file);
            final Element root = document.getRootElement();
            final Set<String> usedMacros = PathMacrosCollector.getMacroNames(root);
            final Set<String> definedMacros = PathMacros.getInstance().getAllMacroNames();
            usedMacros.remove("$" + PathMacrosImpl.MODULE_DIR_MACRO_NAME + "$");
            usedMacros.removeAll(definedMacros);

            if (usedMacros.size() > 0) {
                final boolean ok = ProjectMacrosUtil.showMacrosConfigurationDialog(current, usedMacros);
                if (!ok) {
                    return false;
                }
            }
        } catch (JDOMException e) {
            Messages.showMessageDialog(e.getMessage(), IdeBundle.message("title.error.reading.file"),
                    Messages.getErrorIcon());
            return false;
        } catch (IOException e) {
            Messages.showMessageDialog(e.getMessage(), IdeBundle.message("title.error.reading.file"),
                    Messages.getErrorIcon());
            return false;
        }
    } else {
        Messages.showErrorDialog(current, IdeBundle.message("title.module.file.does.not.exist", moduleFilePath),
                CommonBundle.message("title.error"));
        return false;
    }
    return true;
}

From source file:com.intellij.ide.util.projectWizard.NameLocationStep.java

License:Apache License

public boolean validate() {
    final String moduleName = getModuleName();
    if (moduleName.length() == 0) {
        Messages.showErrorDialog(myNamePathComponent.getNameComponent(),
                IdeBundle.message("prompt.please.specify.module.name"),
                IdeBundle.message("title.module.name.not.specified"));
        return false;
    }/*ww w.  jav  a2 s  . c  o m*/
    if (isAlreadyExists(moduleName)) {
        Messages.showErrorDialog(IdeBundle.message("error.module.with.name.already.exists", moduleName),
                IdeBundle.message("title.module.already.exists"));
        return false;
    }
    final String moduleLocation = getModuleFileDirectory();
    if (moduleLocation.length() == 0) {
        Messages.showErrorDialog(myNamePathComponent.getPathComponent(),
                IdeBundle.message("error.please.specify.module.file.location"),
                IdeBundle.message("title.module.file.location.not.specified"));
        return false;
    }

    final String contentEntryPath = getContentEntryPath();
    if (contentEntryPath != null) {
        // the check makes sence only for non-null module root
        Module[] modules = myModulesProvider.getModules();
        for (final Module module : modules) {
            ModuleRootModel rootModel = myModulesProvider.getRootModel(module);
            LOG.assertTrue(rootModel != null);
            final VirtualFile[] moduleContentRoots = rootModel.getContentRoots();
            final String moduleContentRoot = contentEntryPath.replace(File.separatorChar, '/');
            for (final VirtualFile root : moduleContentRoots) {
                if (moduleContentRoot.equals(root.getPath())) {
                    Messages.showErrorDialog(myNamePathComponent.getPathComponent(),
                            IdeBundle.message("error.content.root.already.defined.for.module", contentEntryPath,
                                    module.getName()),
                            IdeBundle.message("title.module.content.root.already.exists"));
                    return false;
                }
            }
        }
        if (!ProjectWizardUtil.createDirectoryIfNotExists(IdeBundle.message("directory.module.content.root"),
                contentEntryPath, myNamePathComponent.isPathChangedByUser())) {
            return false;
        }
    }
    final String moduleFileDirectory = getModuleFileDirectory();
    return ProjectWizardUtil.createDirectoryIfNotExists(IdeBundle.message("directory.module.file"),
            moduleFileDirectory, myModuleFileDirectoryChangedByUser);
}

From source file:com.intellij.javascript.flex.refactoring.moveMembers.ActionScriptMoveMembersDialog.java

License:Apache License

@Nullable
private JSClass findOrCreateTargetClass(final String fqName) {
    final String className = StringUtil.getShortName(fqName);
    final String packageName = StringUtil.getPackageName(fqName);

    final GlobalSearchScope scope = getScope();
    final JSClassResolver resolver = JSDialectSpecificHandlersFactory
            .forLanguage(JavaScriptSupportLoader.ECMA_SCRIPT_L4).getClassResolver();
    PsiElement aClass = resolver.findClassByQName(fqName, scope);
    if (aClass instanceof JSClass)
        return (JSClass) aClass;

    if (aClass != null) {
        Messages.showErrorDialog(myProject, JSBundle.message("class.0.cannot.be.created", fqName),
                StringUtil.capitalizeWords(JSBundle.message("move.members.refactoring.name"), true));
        return null;
    }/*from  w w w  .  j  av a 2 s  .  co  m*/

    int answer = Messages.showYesNoDialog(myProject,
            RefactoringBundle.message("class.0.does.not.exist", fqName),
            StringUtil.capitalizeWords(JSBundle.message("move.members.refactoring.name"), true),
            Messages.getQuestionIcon());
    if (answer != Messages.YES)
        return null;

    Module module = ModuleUtilCore.findModuleForPsiElement(mySourceClass);
    PsiDirectory baseDir = PlatformPackageUtil.getDirectory(mySourceClass);
    final PsiDirectory targetDirectory = JSRefactoringUtil.chooseOrCreateDirectoryForClass(myProject, module,
            scope, packageName, className, baseDir, ThreeState.UNSURE);
    if (targetDirectory == null) {
        return null;
    }

    final Ref<Exception> error = new Ref<>();
    final Ref<JSClass> newClass = new Ref<>();
    WriteCommandAction.runWriteCommandAction(myProject,
            RefactoringBundle.message("create.class.command", fqName), null, () -> {
                try {
                    ActionScriptCreateClassOrInterfaceFix.createClass(className, packageName, targetDirectory,
                            false);
                    newClass.set((JSClass) resolver.findClassByQName(fqName, scope));
                } catch (Exception e) {
                    error.set(e);
                }
            });

    if (!error.isNull()) {
        CommonRefactoringUtil.showErrorMessage(JSBundle.message("move.members.refactoring.name"),
                error.get().getMessage(), null, myProject);
        return null;
    }
    return newClass.get();
}

From source file:com.intellij.lang.javascript.refactoring.JSBaseIntroduceDialog.java

License:Apache License

@Override
protected void doOKAction() {
    final String name = getVariableName();
    if (name.length() == 0 || !isValidName(name)) {
        Messages.showErrorDialog(myProject,
                JavaScriptBundle.message("javascript.introduce.variable.invalid.name"),
                JavaScriptBundle.message("javascript.introduce.variable.title"));
        getNameField().requestFocus();/*w  w  w .j av a2  s .c  o m*/
        return;
    }

    if (!checkConflicts(name)) {
        return;
    }

    super.doOKAction();
}

From source file:com.intellij.lang.javascript.uml.FlashUmlDataModel.java

License:Apache License

@Override
public void removeEdge(DiagramEdge<Object> edge) {
    final Object source = edge.getSource().getIdentifyingElement();
    final Object target = edge.getTarget().getIdentifyingElement();
    final DiagramRelationshipInfo relationship = edge.getRelationship();
    if (!(source instanceof JSClass) || !(target instanceof JSClass)
            || relationship == DiagramRelationshipInfo.NO_RELATIONSHIP) {
        return;//from   ww w  .  j a  v  a  2  s.c o  m
    }

    final JSClass fromClass = (JSClass) source;
    final JSClass toClass = (JSClass) target;

    if (JSProjectUtil.isInLibrary(fromClass)) {
        return;
    }

    if (fromClass instanceof XmlBackedJSClassImpl && !toClass.isInterface()) {
        Messages.showErrorDialog(fromClass.getProject(), FlexBundle.message("base.component.needed.message"),
                FlexBundle.message("remove.edge.title"));
        return;
    }

    if (Messages.showYesNoDialog(fromClass.getProject(),
            FlexBundle.message("remove.inheritance.link.prompt", fromClass.getQualifiedName(),
                    toClass.getQualifiedName()),
            FlexBundle.message("remove.edge.title"), Messages.getQuestionIcon()) != Messages.YES) {
        return;
    }

    final Runnable runnable = () -> {
        JSReferenceList refList = !fromClass.isInterface() && toClass.isInterface()
                ? fromClass.getImplementsList()
                : fromClass.getExtendsList();
        List<FormatFixer> formatters = new ArrayList<>();
        JSRefactoringUtil.removeFromReferenceList(refList, toClass, formatters);
        if (!(fromClass instanceof XmlBackedJSClassImpl) && needsImport(fromClass, toClass)) {
            formatters.addAll(ECMAScriptImportOptimizer.executeNoFormat(fromClass.getContainingFile()));
        }
        FormatFixer.fixAll(formatters);
    };

    DiagramAction.performCommand(getBuilder(), runnable, FlexBundle.message("remove.relationship.command.name"),
            null, fromClass.getContainingFile());
}

From source file:com.intellij.lang.properties.references.I18nizeQuickFixDialog.java

License:Apache License

private boolean createPropertiesFileIfNotExists() {
    if (getPropertiesFile() != null)
        return true;
    final String path = FileUtil.toSystemIndependentName(myPropertiesFile.getText());
    if (StringUtil.isEmptyOrSpaces(path)) {
        String message = CodeInsightBundle.message("i18nize.empty.file.path", myPropertiesFile.getText());
        Messages.showErrorDialog(myProject, message,
                CodeInsightBundle.message("i18nize.error.creating.properties.file"));
        myPropertiesFile.requestFocusInWindow();
        return false;
    }//from w w  w. j  a va2s.  co  m
    FileType fileType = FileTypeManager.getInstance().getFileTypeByFileName(path);
    if (fileType != StdFileTypes.PROPERTIES) {
        String message = CodeInsightBundle.message(
                "i18nize.cant.create.properties.file.because.its.name.is.associated",
                myPropertiesFile.getText(), fileType.getDescription());
        Messages.showErrorDialog(myProject, message,
                CodeInsightBundle.message("i18nize.error.creating.properties.file"));
        myPropertiesFile.requestFocusInWindow();
        return false;
    }

    final VirtualFile virtualFile;
    try {
        final File file = new File(path).getCanonicalFile();
        FileUtil.createParentDirs(file);
        final IOException[] e = new IOException[1];
        virtualFile = ApplicationManager.getApplication().runWriteAction(new Computable<VirtualFile>() {
            public VirtualFile compute() {
                VirtualFile dir = LocalFileSystem.getInstance()
                        .refreshAndFindFileByIoFile(file.getParentFile());
                try {
                    if (dir == null) {
                        throw new IOException("Error creating directory structure for file '" + path + "'");
                    }
                    return dir.createChildData(this, file.getName());
                } catch (IOException e1) {
                    e[0] = e1;
                }
                return null;
            }
        });
        if (e[0] != null)
            throw e[0];
    } catch (IOException e) {
        Messages.showErrorDialog(myProject, e.getLocalizedMessage(),
                CodeInsightBundle.message("i18nize.error.creating.properties.file"));
        return false;
    }

    PsiFile psiFile = PsiManager.getInstance(myProject).findFile(virtualFile);
    return psiFile instanceof PropertiesFile;
}

From source file:com.intellij.lang.properties.references.I18nizeQuickFixDialog.java

License:Apache License

protected void doOKAction() {
    if (!createPropertiesFileIfNotExists())
        return;/*from   ww w . j  ava 2 s .  c  om*/
    Collection<PropertiesFile> propertiesFiles = getAllPropertiesFiles();
    for (PropertiesFile propertiesFile : propertiesFiles) {
        Property existingProperty = propertiesFile.findPropertyByKey(getKey());
        final String propValue = myValue.getText();
        if (existingProperty != null && !Comparing.strEqual(existingProperty.getValue(), propValue)) {
            Messages.showErrorDialog(myProject,
                    CodeInsightBundle.message("i18nize.dialog.error.property.already.defined.message", getKey(),
                            propertiesFile.getName()),
                    CodeInsightBundle.message("i18nize.dialog.error.property.already.defined.title"));
            return;
        }
    }

    super.doOKAction();
}

From source file:com.intellij.packaging.impl.artifacts.JarFromModulesTemplate.java

License:Apache License

@Nullable
public NewArtifactConfiguration doCreateArtifact(final Module[] modules, final String mainClassName,
        final String directoryForManifest, final boolean extractLibrariesToJar, final boolean includeTests) {
    VirtualFile manifestFile = null;/*from w  w  w  .j a v  a 2s.c  om*/
    final Project project = myContext.getProject();
    if (mainClassName != null && !mainClassName.isEmpty() || !extractLibrariesToJar) {
        final VirtualFile directory;
        try {
            directory = ApplicationManager.getApplication()
                    .runWriteAction(new ThrowableComputable<VirtualFile, IOException>() {
                        @Override
                        public VirtualFile compute() throws IOException {
                            return VfsUtil.createDirectoryIfMissing(directoryForManifest);
                        }
                    });
        } catch (IOException e) {
            LOG.info(e);
            Messages.showErrorDialog(project,
                    "Cannot create directory '" + directoryForManifest + "': " + e.getMessage(),
                    CommonBundle.getErrorTitle());
            return null;
        }
        if (directory == null)
            return null;

        manifestFile = ManifestFileUtil.createManifestFile(directory, project);
        if (manifestFile == null) {
            return null;
        }
        ManifestFileUtil.updateManifest(manifestFile, mainClassName, null, true);
    }

    String name = modules.length == 1 ? modules[0].getName() : project.getName();

    final PackagingElementFactory factory = PackagingElementFactory.getInstance();
    final CompositePackagingElement<?> archive = factory
            .createZipArchive(ArtifactUtil.suggestArtifactFileName(name) + ".jar");

    OrderEnumerator orderEnumerator = ProjectRootManager.getInstance(project)
            .orderEntries(Arrays.asList(modules));

    final Set<Library> libraries = new THashSet<Library>();
    if (!includeTests) {
        orderEnumerator = orderEnumerator.productionOnly();
    }
    final ModulesProvider modulesProvider = myContext.getModulesProvider();
    final OrderEnumerator enumerator = orderEnumerator.using(modulesProvider).withoutSdk().runtimeOnly()
            .recursively();
    enumerator.forEachLibrary(new CommonProcessors.CollectProcessor<Library>(libraries));
    enumerator.forEachModule(new Processor<Module>() {
        @Override
        public boolean process(Module module) {
            if (ProductionModuleOutputElementType.getInstance().isSuitableModule(modulesProvider, module)) {
                archive.addOrFindChild(factory.createModuleOutput(module));
            }
            if (includeTests
                    && TestModuleOutputElementType.getInstance().isSuitableModule(modulesProvider, module)) {
                archive.addOrFindChild(factory.createTestModuleOutput(module));
            }
            return true;
        }
    });

    final JarArtifactType jarArtifactType = JarArtifactType.getInstance();
    if (manifestFile != null
            && !manifestFile.equals(ManifestFileUtil.findManifestFile(archive, myContext, jarArtifactType))) {
        archive.addFirstChild(factory.createFileCopyWithParentDirectories(manifestFile.getPath(),
                ManifestFileUtil.MANIFEST_DIR_NAME));
    }

    final String artifactName = name + ":jar";
    if (extractLibrariesToJar) {
        addExtractedLibrariesToJar(archive, factory, libraries);
        return new NewArtifactConfiguration(archive, artifactName, jarArtifactType);
    } else {
        final ArtifactRootElement<?> root = factory.createArtifactRootElement();
        List<String> classpath = new ArrayList<String>();
        root.addOrFindChild(archive);
        addLibraries(libraries, root, archive, classpath);
        ManifestFileUtil.updateManifest(manifestFile, mainClassName, classpath, true);
        return new NewArtifactConfiguration(root, artifactName, PlainArtifactType.getInstance());
    }
}

From source file:com.intellij.packaging.impl.ManifestFileUtil.java

License:Apache License

@Nullable
public static VirtualFile createManifestFile(final @NotNull VirtualFile directory,
        final @NotNull Project project) {
    ApplicationManager.getApplication().assertIsDispatchThread();
    final Ref<IOException> exc = Ref.create(null);
    final VirtualFile file = new WriteAction<VirtualFile>() {
        protected void run(final Result<VirtualFile> result) {
            VirtualFile dir = directory;
            try {
                if (!dir.getName().equals(MANIFEST_DIR_NAME)) {
                    dir = VfsUtil.createDirectoryIfMissing(dir, MANIFEST_DIR_NAME);
                }/*from w ww .j a v  a 2 s .  c  o  m*/
                final VirtualFile file = dir.createChildData(this, MANIFEST_FILE_NAME);
                final OutputStream output = file.getOutputStream(this);
                try {
                    final Manifest manifest = new Manifest();
                    ManifestBuilder.setVersionAttribute(manifest.getMainAttributes());
                    manifest.write(output);
                } finally {
                    output.close();
                }
                result.setResult(file);
            } catch (IOException e) {
                exc.set(e);
            }
        }
    }.execute().getResultObject();

    final IOException exception = exc.get();
    if (exception != null) {
        LOGGER.info(exception);
        Messages.showErrorDialog(project, exception.getMessage(), CommonBundle.getErrorTitle());
        return null;
    }
    return file;
}

From source file:com.intellij.platform.NewDirectoryProjectAction.java

License:Apache License

@Nullable
protected Project generateProject(Project project, @NotNull final NewProjectOrModuleDialog dialog) {
    final File location = new File(dialog.getLocationText());
    final int childCount = location.exists() ? location.list().length : 0;
    if (!location.exists() && !location.mkdirs()) {
        Messages.showErrorDialog(project, "Cannot create directory '" + location + "'", "Create Project");
        return null;
    }/*from w w w  .ja v  a 2  s .  c om*/

    final VirtualFile baseDir = ApplicationManager.getApplication()
            .runWriteAction(new Computable<VirtualFile>() {
                @Override
                public VirtualFile compute() {
                    return LocalFileSystem.getInstance().refreshAndFindFileByIoFile(location);
                }
            });
    baseDir.refresh(false, true);

    if (childCount > 0) {
        int rc = Messages.showYesNoDialog(project, "The directory '" + location + "' is not empty. Continue?",
                "Create New Project", Messages.getQuestionIcon());
        if (rc == Messages.NO) {
            return null;
        }
    }

    GeneralSettings.getInstance().setLastProjectCreationLocation(location.getParent());
    return PlatformProjectOpenProcessor.doOpenProject(baseDir, null, false, -1, new Consumer<Project>() {
        @Override
        public void consume(final Project project) {
            dialog.doCreate(project, baseDir);
        }
    });
}