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:git4idea.actions.GitPush.java

License:Apache License

@Override
protected void perform(@NotNull Project project, GitVcs vcs, @NotNull List<VcsException> exceptions,
        @NotNull VirtualFile[] affectedFiles) throws VcsException {
    saveAll();//from  w w w .  j a va2  s  .  c  o m

    final VirtualFile[] roots = ProjectLevelVcsManager.getInstance(project).getRootsUnderVcs(vcs);
    for (VirtualFile root : roots) {
        GitCommand command = new GitCommand(project, vcs.getSettings(), root);
        command.push();

        GitCommandRunnable cmdr = new GitCommandRunnable(project, vcs.getSettings(), root);
        cmdr.setCommand(GitCommand.PUSH_CMD);
        cmdr.setArgs(new String[] { "--mirror" });

        ProgressManager manager = ProgressManager.getInstance();
        manager.runProcessWithProgressSynchronously(cmdr,
                "Pushing all commited changes, refs & tags to remote repos", false, project);

        VcsException ex = cmdr.getException();
        if (ex != null) {
            Messages.showErrorDialog(project, ex.getMessage(), "Error occurred during 'git push --mirror'");
        }
    }
}

From source file:git4idea.actions.GitStash.java

License:Apache License

protected void perform(@NotNull Project project, GitVcs vcs, @NotNull List<VcsException> exceptions,
        @NotNull VirtualFile[] affectedFiles) throws VcsException {
    saveAll();//from  w  w w.  ja va  2s  .c  o  m

    if (!ProjectLevelVcsManager.getInstance(project).checkAllFilesAreUnder(GitVcs.getInstance(project),
            affectedFiles))
        return;

    final Map<VirtualFile, List<VirtualFile>> roots = GitUtil.sortFilesByVcsRoot(project, affectedFiles);

    String stashName = Messages.showInputDialog(project, "Enter new stash name/description: ", "Stash",
            Messages.getQuestionIcon(), "", null);

    if (stashName == null || stashName.length() == 0)
        return;

    for (VirtualFile root : roots.keySet()) {
        GitCommandRunnable cmdr = new GitCommandRunnable(project, vcs.getSettings(), root);
        cmdr.setCommand(GitCommand.STASH_CMD);
        cmdr.setArgs(new String[] { "save", stashName });

        ProgressManager manager = ProgressManager.getInstance();
        //TODO: make this async so the git command output can be seen in the version control window as it happens...
        manager.runProcessWithProgressSynchronously(cmdr, "Stashing changes... ", false, project);

        VcsException ex = cmdr.getException();
        if (ex != null) {
            Messages.showErrorDialog(project, ex.getMessage(), "Error occurred during 'git stash'");
            break;
        }
    }
}

From source file:git4idea.actions.GitTag.java

License:Apache License

@Override
public void perform(@NotNull Project project, GitVcs vcs, @NotNull List<VcsException> exceptions,
        @NotNull VirtualFile[] affectedFiles) throws VcsException {
    saveAll();//from w w w .j  a  v  a2  s  .  co  m

    if (!ProjectLevelVcsManager.getInstance(project).checkAllFilesAreUnder(vcs, affectedFiles)) {
        Messages.showErrorDialog(project, "ERROR: Files not tagged, not all are under VCS root!", "Tag Result");
        return;
    }

    final String tagName = Messages.showInputDialog(project, "Specify tag name: ", "Tag",
            Messages.getQuestionIcon());
    if (tagName == null || tagName.length() == 0)
        return;

    final Map<VirtualFile, List<VirtualFile>> roots = GitUtil.sortFilesByVcsRoot(project, affectedFiles);

    for (VirtualFile root : roots.keySet()) {
        GitCommandRunnable cmdr = new GitCommandRunnable(project, vcs.getSettings(), root);
        cmdr.setCommand(GitCommand.TAG_CMD);
        cmdr.setArgs(new String[] { tagName });

        ProgressManager manager = ProgressManager.getInstance();
        //TODO: make this async so the git command output can be seen in the version control window as it happens...
        manager.runProcessWithProgressSynchronously(cmdr, "Tagging files... ", false, project);

        VcsException ex = cmdr.getException();
        if (ex != null) {
            Messages.showErrorDialog(project, ex.getMessage(), "Error occurred during 'git tag'");
            break;
        }
    }
}

From source file:git4idea.actions.GitUnstash.java

License:Apache License

protected void perform(@NotNull Project project, GitVcs vcs, @NotNull List<VcsException> exceptions,
        @NotNull VirtualFile[] affectedFiles) throws VcsException {
    saveAll();/*ww  w . j av a2s.c om*/

    if (!ProjectLevelVcsManager.getInstance(project).checkAllFilesAreUnder(GitVcs.getInstance(project),
            affectedFiles))
        return;

    final Map<VirtualFile, List<VirtualFile>> roots = GitUtil.sortFilesByVcsRoot(project, affectedFiles);

    for (VirtualFile root : roots.keySet()) {
        GitCommand command = new GitCommand(project, vcs.getSettings(), root);
        String[] stashList = command.stashList();
        if (stashList == null || stashList.length == 0)
            continue;
        int stashIndex = Messages.showChooseDialog("Select stash to restore: ", "UnStash Changes", stashList,
                stashList[0], Messages.getQuestionIcon());
        if (stashIndex < 0)
            continue;

        GitCommandRunnable cmdr = new GitCommandRunnable(project, vcs.getSettings(), root);
        cmdr.setCommand(GitCommand.STASH_CMD);
        String stashName = stashList[stashIndex].split(":")[0];
        cmdr.setArgs(new String[] { "apply", stashName });

        ProgressManager manager = ProgressManager.getInstance();
        //TODO: make this async so the git command output can be seen in the version control window as it happens...
        manager.runProcessWithProgressSynchronously(cmdr, "UnStashing changes... ", false, project);

        VcsException ex = cmdr.getException();
        if (ex != null) {
            Messages.showErrorDialog(project, ex.getMessage(), "Error occurred during 'git stash apply'");
            break;
        }
    }
}

From source file:git4idea.GitRenameListener.java

License:Apache License

public void elementRenamed(PsiElement newElement) {
    if (newElement == null)
        return;//  w ww . jav  a  2  s  .  co m
    // IDEA has already moved the file at this point...
    GitCommand cmd = new GitCommand(project, GitVcsSettings.getInstance(project), vcsRoot);
    VirtualFile newFile = newElement.getContainingFile().getVirtualFile();
    File newLoc = new File(newFile.getPath());
    File oldLoc = new File(originalFilename);
    try {
        if (newLoc.exists() && !oldLoc.exists()) // file already moved in local fs
            newLoc.renameTo(oldLoc); // move back, let Git do the move
        cmd.move(new GitVirtualFile(project, originalFilename), newFile);
    } catch (SecurityException se) {
        Messages.showErrorDialog(project, se.getMessage(), "Unable to rename file, permission denied.");
    } catch (VcsException ve) {
        Messages.showErrorDialog(project, ve.getMessage(), "Error during rename ('git mv')");
    }
}

From source file:git4idea.GitVcs.java

License:Apache License

public void showErrors(@NotNull java.util.List<VcsException> list, @NotNull String action) {
    if (list.size() > 0) {
        StringBuffer buffer = new StringBuffer();
        buffer.append("\n");
        buffer.append(action).append(" Error: ");
        VcsException e;/*  w  w w. j av  a  2 s .  co  m*/
        for (Iterator<VcsException> iterator = list.iterator(); iterator.hasNext(); buffer
                .append(e.getMessage())) {
            e = iterator.next();
            buffer.append("\n");
        }
        String msg = buffer.toString();
        showMessage(msg, CodeInsightColors.ERRORS_ATTRIBUTES);
        Messages.showErrorDialog(myProject, msg, "Error");
    }
}

From source file:git4idea.GitVcsPanel.java

License:Apache License

private void testConnection() {
    final GitVcsSettings settings = new GitVcsSettings();
    settings.GIT_EXECUTABLE = gitField.getText();
    final VirtualFile baseDir = project.getBaseDir();
    assert baseDir != null;
    final GitCommand command = new GitCommand(project, settings, baseDir);
    final String s;

    try {//from  w  w w .ja  va2  s . co m
        s = command.version();
    } catch (VcsException e) {
        Messages.showErrorDialog(project, e.getMessage(), "Error Running git");
        return;
    }
    Messages.showInfoMessage(project, s, "Git Executed Successfully");
}

From source file:io.flutter.project.FlutterProjectCreator.java

License:Open Source License

public void createModule() {
    Project project = myModel.project().getValue();
    VirtualFile baseDir = project.getBaseDir();
    if (baseDir == null) {
        return; // Project was deleted.
    }//from   w  w  w.j a  v a2  s  .  c o  m
    String baseDirPath = baseDir.getPath();
    String moduleName = ProjectWizardUtil.findNonExistingFileName(baseDirPath, myModel.projectName().get(), "");
    String contentRoot = baseDirPath + "/" + moduleName;
    File location = new File(contentRoot);
    if (!location.exists() && !location.mkdirs()) {
        String message = ActionsBundle.message("action.NewDirectoryProject.cannot.create.dir",
                location.getAbsolutePath());
        Messages.showErrorDialog(project, message, ActionsBundle.message("action.NewDirectoryProject.title"));
        return;
    }

    // ModuleBuilder mixes UI and model code too much to easily reuse. We have to override a bunch of stuff to ensure
    // that methods which expect a live UI do not get called.
    FlutterModuleBuilder builder = new FlutterModuleBuilder() {
        @NotNull
        @Override
        public FlutterCreateAdditionalSettings getAdditionalSettings() {
            return makeAdditionalSettings();
        }

        @Override
        protected FlutterSdk getFlutterSdk() {
            return FlutterSdk.forPath(myModel.flutterSdk().get());
        }

        @Override
        public boolean validate(Project current, Project dest) {
            return true;
        }

        @Override
        public ModuleWizardStep getCustomOptionsStep(final WizardContext context,
                final Disposable parentDisposable) {
            return null;
        }

        @Override
        public void setFlutterSdkPath(String s) {
        }

        @Override
        public ModuleWizardStep modifySettingsStep(@NotNull SettingsStep settingsStep) {
            return null;
        }
    };
    builder.setName(myModel.projectName().get());
    builder.setModuleFilePath(
            toSystemIndependentName(contentRoot) + "/" + moduleName + ModuleFileType.DOT_DEFAULT_EXTENSION);
    builder.commitModule(project, null);
}

From source file:io.flutter.project.FlutterProjectCreator.java

License:Open Source License

public void createProject() {
    IdeFrame frame = IdeFocusManager.getGlobalInstance().getLastFocusedFrame();
    final Project projectToClose = frame != null ? frame.getProject() : null;

    final File location = new File(FileUtil.toSystemDependentName(myModel.projectLocation().get()));
    if (!location.exists() && !location.mkdirs()) {
        String message = ActionsBundle.message("action.NewDirectoryProject.cannot.create.dir",
                location.getAbsolutePath());
        Messages.showErrorDialog(projectToClose, message,
                ActionsBundle.message("action.NewDirectoryProject.title"));
        return;/*from  ww w  . j a v  a2 s  .  c o  m*/
    }
    final File baseFile = new File(location, myModel.projectName().get());
    //noinspection ResultOfMethodCallIgnored
    baseFile.mkdirs();
    final VirtualFile baseDir = ApplicationManager.getApplication().runWriteAction(
            (Computable<VirtualFile>) () -> LocalFileSystem.getInstance().refreshAndFindFileByIoFile(baseFile));
    if (baseDir == null) {
        LOG.error("Couldn't find '" + location + "' in VFS");
        return;
    }
    VfsUtil.markDirtyAndRefresh(false, true, true, baseDir);

    RecentProjectsManager.getInstance().setLastProjectCreationLocation(location.getPath());

    ProjectOpenedCallback callback = (project, module) -> ProgressManager.getInstance()
            .run(new Task.Modal(null, "Creating Flutter Project", false) {
                @Override
                public void run(@NotNull ProgressIndicator indicator) {
                    indicator.setIndeterminate(true);

                    // The IDE has already created some files. Flutter won't overwrite them, but we want the versions provided by Flutter.
                    deleteDirectoryContents(baseFile);

                    // Add an Android facet if needed by the project type.
                    if (myModel.projectType().getValue() != FlutterProjectType.PACKAGE) {
                        ModifiableFacetModel model = FacetManager.getInstance(module).createModifiableModel();
                        AndroidFacetType facetType = AndroidFacet.getFacetType();
                        AndroidFacet facet = facetType.createFacet(module, AndroidFacet.NAME,
                                facetType.createDefaultConfiguration(), null);
                        model.addFacet(facet);
                        configureFacet(facet, baseFile, "android");
                        File appLocation = new File(baseFile, "android");
                        //noinspection ResultOfMethodCallIgnored
                        appLocation.mkdirs();
                        AndroidFacet appFacet = facetType.createFacet(module, AndroidFacet.NAME,
                                facetType.createDefaultConfiguration(), null);
                        model.addFacet(appFacet);
                        configureFacet(appFacet, appLocation, "app");
                    }

                    FlutterSmallIDEProjectGenerator.generateProject(project, baseDir,
                            myModel.flutterSdk().get(), module, makeAdditionalSettings());

                    // Reload the project to use the configuration written by Flutter.
                    VfsUtil.markDirtyAndRefresh(false, true, true, baseDir);
                    ConversionService.getInstance().convertSilently(baseDir.getPath(),
                            new MyConversionListener());
                    VfsUtil.markDirtyAndRefresh(false, true, true, baseDir);
                    reloadProjectNow(project);
                }
            });

    EnumSet<PlatformProjectOpenProcessor.Option> options = EnumSet
            .noneOf(PlatformProjectOpenProcessor.Option.class);
    PlatformProjectOpenProcessor.doOpenProject(baseDir, projectToClose, -1, callback, options);
    // The project was reloaded by the callback. Find the new Project object.
    Project newProject = FlutterUtils.findProject(baseDir.getPath());
    if (newProject != null) {
        StartupManager.getInstance(newProject)
                .registerPostStartupActivity(() -> ApplicationManager.getApplication().invokeLater(() -> {
                    disableUserConfig(newProject);
                    // We want to show the Project view, not the Android view since it doesn't make the Dart code visible.
                    ProjectView.getInstance(newProject).changeView(ProjectViewPane.ID);
                    //ProjectManager.getInstance().reloadProject(newProject);
                }, ModalityState.NON_MODAL));
    }
}

From source file:manuylov.maxim.ocaml.actions.SwitchModuleFileAction.java

License:Open Source License

public void actionPerformed(final AnActionEvent e) {
    final Project project = e.getProject();
    if (project == null) {
        return;/*from w w w .j  a v  a 2  s. c  om*/
    }

    final IdeView view = e.getData(LangDataKeys.IDE_VIEW);
    if (view == null) {
        return;
    }

    final VirtualFile file = e.getData(PlatformDataKeys.VIRTUAL_FILE);
    if (file == null) {
        return;
    }

    final VirtualFile parent = file.getParent();
    if (parent == null) {
        return;
    }

    final File anotherFile = new File(parent.getPath(), OCamlFileUtil.getAnotherFileName(file));
    VirtualFile anotherVirtualFile = LocalFileSystem.getInstance().findFileByIoFile(anotherFile);

    if (anotherVirtualFile == null) {
        final String anotherFilePath = FileUtil.toSystemDependentName(anotherFile.getAbsolutePath());
        final Module module = ModuleUtil.findModuleForFile(file, project);
        if (OCamlModuleUtil.hasOCamlExtension(module)
                && ModuleRootManager.getInstance(module).getFileIndex().isInSourceContent(file)) {
            if (Messages.showYesNoCancelDialog(project,
                    "File \"" + anotherFilePath + "\" does not exist. Do you want to create it?",
                    "Open file \"" + anotherFilePath + "\"", Messages.getQuestionIcon()) != 0) {
                return;
            }
            ApplicationManager.getApplication().runWriteAction(new Runnable() {
                public void run() {
                    try {
                        parent.createChildData(SwitchModuleFileAction.this, anotherFile.getName());
                    } catch (final IOException e) {
                        Messages.showErrorDialog(project, e.getMessage(), "Error");
                    }
                }
            });
            anotherVirtualFile = LocalFileSystem.getInstance().findFileByIoFile(anotherFile);
            if (anotherVirtualFile == null) {
                return;
            }
        } else {
            Messages.showErrorDialog(project, "File \"" + anotherFilePath + "\" does not exist.",
                    "Open file \"" + anotherFilePath + "\"");
            return;
        }
    }

    final PsiFile anotherPsiFile = PsiManager.getInstance(project).findFile(anotherVirtualFile);
    if (anotherPsiFile == null) {
        return;
    }

    view.selectElement(anotherPsiFile);
}