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

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

Introduction

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

Prototype

int CANCEL

To view the source code for com.intellij.openapi.ui Messages CANCEL.

Click Source Link

Usage

From source file:org.jetbrains.android.run.testing.AndroidTestRunConfiguration.java

License:Apache License

@Override
public AndroidRunningState getState(@NotNull Executor executor, @NotNull ExecutionEnvironment env)
        throws ExecutionException {
    final AndroidRunningState state = super.getState(executor, env);

    if (state == null) {
        return null;
    }//from  ww w.j ava 2s.co  m

    final AndroidFacet facet = state.getFacet();
    final AndroidFacetConfiguration configuration = facet.getConfiguration();

    if (!facet.isGradleProject() && !configuration.getState().PACK_TEST_CODE) {
        final Module module = facet.getModule();
        final int count = getTestSourceRootCount(module);

        if (count > 0) {
            final String message = "Code and resources under test source " + (count > 1 ? "roots" : "root")
                    + " aren't included into debug APK.\nWould you like to include them and recompile "
                    + module.getName() + " module?"
                    + "\n(You may change this option in Android facet settings later)";
            final int result = Messages.showYesNoCancelDialog(getProject(), message,
                    "Test code not included into APK", Messages.getQuestionIcon());

            if (result == Messages.YES) {
                configuration.getState().PACK_TEST_CODE = true;
            } else if (result == Messages.CANCEL) {
                return null;
            }
        }
    }
    return state;
}

From source file:org.jetbrains.kotlin.idea.refactoring.move.moveDeclarations.ui.MoveKotlinTopLevelDeclarationsDialog.java

License:Apache License

@Override
protected void doAction() {
    KotlinMoveTarget target = selectMoveTarget();
    if (target == null)
        return;/*from   www . ja  va 2 s . c  o  m*/

    saveRefactoringSettings();

    List<KtNamedDeclaration> elementsToMove = getSelectedElementsToMove();
    final List<KtFile> sourceFiles = getSourceFiles(elementsToMove);
    final PsiDirectory sourceDirectory = getSourceDirectory(sourceFiles);

    for (PsiElement element : elementsToMove) {
        String message = target.verify(element.getContainingFile());
        if (message != null) {
            CommonRefactoringUtil.showErrorMessage(RefactoringBundle.message("error.title"), message, null,
                    myProject);
            return;
        }
    }

    try {
        boolean deleteSourceFile = false;

        if (isFullFileMove()) {
            if (isMoveToPackage()) {
                final MoveDestination moveDestination = selectPackageBasedMoveDestination(false);
                //noinspection ConstantConditions
                PsiDirectory targetDir = moveDestination.getTargetIfExists(sourceDirectory);
                final String targetFileName = sourceFiles.size() > 1 ? null : tfFileNameInPackage.getText();
                List<PsiFile> filesExistingInTargetDir = getFilesExistingInTargetDir(sourceFiles,
                        targetFileName, targetDir);
                if (filesExistingInTargetDir.isEmpty()) {
                    PsiDirectory targetDirectory = ApplicationUtilsKt
                            .runWriteAction(new Function0<PsiDirectory>() {
                                @Override
                                public PsiDirectory invoke() {
                                    return moveDestination.getTargetDirectory(sourceDirectory);
                                }
                            });

                    for (KtFile sourceFile : sourceFiles) {
                        MoveUtilsKt.setUpdatePackageDirective(sourceFile,
                                cbUpdatePackageDirective.isSelected());
                    }

                    invokeRefactoring(new MoveFilesOrDirectoriesProcessor(myProject,
                            sourceFiles.toArray(new PsiElement[sourceFiles.size()]), targetDirectory, true,
                            isSearchInComments(), isSearchInNonJavaFiles(), new MoveCallback() {
                                @Override
                                public void refactoringCompleted() {
                                    try {
                                        if (targetFileName != null) {
                                            CollectionsKt.single(sourceFiles).setName(targetFileName);
                                        }
                                    } finally {
                                        if (moveCallback != null) {
                                            moveCallback.refactoringCompleted();
                                        }
                                    }
                                }
                            }, EmptyRunnable.INSTANCE) {
                        @Override
                        protected String getCommandName() {
                            return targetFileName != null
                                    ? "Move " + CollectionsKt.single(sourceFiles).getName()
                                    : "Move";
                        }

                        @Override
                        protected void performRefactoring(@NotNull UsageInfo[] usages) {
                            if (targetFileName != null) {
                                KtFile sourceFile = CollectionsKt.single(sourceFiles);
                                //noinspection ConstantConditions
                                String temporaryName = UniqueNameGenerator.generateUniqueName("temp", "", ".kt",
                                        ArraysKt.map(sourceFile.getContainingDirectory().getFiles(),
                                                new Function1<PsiFile, String>() {
                                                    @Override
                                                    public String invoke(PsiFile file) {
                                                        return file.getName();
                                                    }
                                                }));
                                sourceFile.setName(temporaryName);
                            }

                            super.performRefactoring(usages);
                        }
                    });

                    return;
                }
            }

            int ret = Messages.showYesNoCancelDialog(myProject,
                    "You are about to move all declarations out of the source file(s). Do you want to delete empty files?",
                    RefactoringBundle.message("move.title"), Messages.getQuestionIcon());
            if (ret == Messages.CANCEL)
                return;
            deleteSourceFile = ret == Messages.YES;
        }

        MoveDeclarationsDescriptor options = new MoveDeclarationsDescriptor(elementsToMove, target,
                MoveDeclarationsDelegate.TopLevel.INSTANCE, isSearchInComments(), isSearchInNonJavaFiles(),
                true, deleteSourceFile, moveCallback, false);
        invokeRefactoring(new MoveKotlinDeclarationsProcessor(myProject, options, Mover.Default.INSTANCE));
    } catch (IncorrectOperationException e) {
        CommonRefactoringUtil.showErrorMessage(RefactoringBundle.message("error.title"), e.getMessage(), null,
                myProject);
    }
}

From source file:org.jetbrains.kotlin.idea.refactoring.move.moveTopLevelDeclarations.ui.MoveKotlinTopLevelDeclarationsDialog.java

License:Apache License

@Override
protected void doAction() {
    KotlinMoveTarget target = selectMoveTarget();
    if (target == null)
        return;//from  ww  w .j  a  v  a  2  s.  c  o m

    saveRefactoringSettings();

    List<KtNamedDeclaration> elementsToMove = getSelectedElementsToMove();
    final List<KtFile> sourceFiles = getSourceFiles(elementsToMove);
    final PsiDirectory sourceDirectory = getSourceDirectory(sourceFiles);

    for (PsiElement element : elementsToMove) {
        String message = target.verify(element.getContainingFile());
        if (message != null) {
            CommonRefactoringUtil.showErrorMessage(RefactoringBundle.message("error.title"), message, null,
                    myProject);
            return;
        }
    }

    try {
        boolean deleteSourceFile = false;

        if (isFullFileMove()) {
            if (isMoveToPackage()) {
                final MoveDestination moveDestination = selectPackageBasedMoveDestination(false);
                //noinspection ConstantConditions
                PsiDirectory targetDir = moveDestination.getTargetIfExists(sourceDirectory);
                final String targetFileName = sourceFiles.size() > 1 ? null : tfFileNameInPackage.getText();
                List<PsiFile> filesExistingInTargetDir = getFilesExistingInTargetDir(sourceFiles,
                        targetFileName, targetDir);
                if (filesExistingInTargetDir.isEmpty()) {
                    PsiDirectory targetDirectory = ApplicationUtilsKt
                            .runWriteAction(new Function0<PsiDirectory>() {
                                @Override
                                public PsiDirectory invoke() {
                                    return moveDestination.getTargetDirectory(sourceDirectory);
                                }
                            });

                    for (KtFile sourceFile : sourceFiles) {
                        MoveUtilsKt.setUpdatePackageDirective(sourceFile,
                                cbUpdatePackageDirective.isSelected());
                    }

                    invokeRefactoring(new MoveFilesOrDirectoriesProcessor(myProject,
                            sourceFiles.toArray(new PsiElement[sourceFiles.size()]), targetDirectory, true,
                            isSearchInComments(), isSearchInNonJavaFiles(), new MoveCallback() {
                                @Override
                                public void refactoringCompleted() {
                                    try {
                                        if (targetFileName != null) {
                                            CollectionsKt.single(sourceFiles).setName(targetFileName);
                                        }
                                    } finally {
                                        if (moveCallback != null) {
                                            moveCallback.refactoringCompleted();
                                        }
                                    }
                                }
                            }, EmptyRunnable.INSTANCE) {
                        @Override
                        protected String getCommandName() {
                            return targetFileName != null
                                    ? "Move " + CollectionsKt.single(sourceFiles).getName()
                                    : "Move";
                        }

                        @Override
                        protected void performRefactoring(@NotNull UsageInfo[] usages) {
                            if (targetFileName != null) {
                                KtFile sourceFile = CollectionsKt.single(sourceFiles);
                                //noinspection ConstantConditions
                                String temporaryName = UniqueNameGenerator.generateUniqueName("temp", "", ".kt",
                                        ArraysKt.map(sourceFile.getContainingDirectory().getFiles(),
                                                new Function1<PsiFile, String>() {
                                                    @Override
                                                    public String invoke(PsiFile file) {
                                                        return file.getName();
                                                    }
                                                }));
                                sourceFile.setName(temporaryName);
                            }

                            super.performRefactoring(usages);
                        }
                    });

                    return;
                }
            }

            int ret = Messages.showYesNoCancelDialog(myProject,
                    "You are about to move all declarations out of the source file(s). Do you want to delete empty files?",
                    RefactoringBundle.message("move.title"), Messages.getQuestionIcon());
            if (ret == Messages.CANCEL)
                return;
            deleteSourceFile = ret == Messages.YES;
        }

        MoveKotlinTopLevelDeclarationsOptions options = new MoveKotlinTopLevelDeclarationsOptions(
                elementsToMove, target, isSearchInComments(), isSearchInNonJavaFiles(), true, deleteSourceFile,
                moveCallback);
        invokeRefactoring(
                new MoveKotlinTopLevelDeclarationsProcessor(myProject, options, Mover.Default.INSTANCE$));
    } catch (IncorrectOperationException e) {
        CommonRefactoringUtil.showErrorMessage(RefactoringBundle.message("error.title"), e.getMessage(), null,
                myProject);
    }
}

From source file:org.sonarlint.intellij.trigger.SonarLintCheckinHandler.java

License:Open Source License

private ReturnResult showYesNoCancel(String resultStr) {
    final int answer = Messages.showYesNoCancelDialog(project, resultStr, "SonarLint Analysis Results",
            "Review Issues", "Commit Anyway", "Close", UIUtil.getWarningIcon());

    if (answer == Messages.YES) {
        showChangedFilesTab();//w w w .  ja  v  a 2 s  .c o  m
        return ReturnResult.CLOSE_WINDOW;
    } else if (answer == Messages.CANCEL) {
        return ReturnResult.CANCEL;
    } else {
        return ReturnResult.COMMIT;
    }
}

From source file:org.twodividedbyzero.idea.findbugs.core.CheckinHandlerFactoryImpl.java

License:Open Source License

@NotNull
@Override// w ww.j ava 2  s .c o  m
public CheckinHandler createHandler(@NotNull final CheckinProjectPanel panel,
        @NotNull final CommitContext commitContext) {
    return new CheckinHandler() {
        @Override
        public RefreshableOnComponent getBeforeCheckinConfigurationPanel() {
            final JCheckBox run = new JCheckBox(ResourcesLoader.getString("checkin.text"));
            return new RefreshableOnComponent() {
                public JComponent getComponent() {
                    return JBUI.Panels.simplePanel().addToLeft(run);
                }

                @Override
                public void refresh() {
                }

                @Override
                public void saveState() {
                    WorkspaceSettings.getInstance(panel.getProject()).analyzeBeforeCheckIn = run.isSelected();
                }

                @Override
                public void restoreState() {
                    run.setSelected(WorkspaceSettings.getInstance(panel.getProject()).analyzeBeforeCheckIn);
                }
            };
        }

        @Override
        public ReturnResult beforeCheckin(@Nullable final CommitExecutor executor,
                final PairConsumer<Object, Object> additionalDataConsumer) {
            if (!WorkspaceSettings.getInstance(panel.getProject()).analyzeBeforeCheckIn) {
                return super.beforeCheckin(executor, additionalDataConsumer);
            }

            new FindBugsStarter(panel.getProject(), "Running FindBugs analysis for affected files...",
                    ProgressStartType.Modal) {
                @Override
                protected boolean isCompileBeforeAnalyze() {
                    return false; // CompilerManager#make start asynchronous task
                }

                @Override
                protected void createCompileScope(@NotNull final CompilerManager compilerManager,
                        @NotNull final Consumer<CompileScope> consumer) {
                    throw new UnsupportedOperationException();
                }

                @Override
                protected boolean configure(@NotNull final ProgressIndicator indicator,
                        @NotNull final FindBugsProjects projects, final boolean justCompiled) {
                    final Collection<VirtualFile> virtualFiles = panel.getVirtualFiles();
                    projects.addFiles(virtualFiles, false, hasTests(virtualFiles));
                    return true;
                }
            }.start();
            final ToolWindowPanel toolWindowPanel = ToolWindowPanel.getInstance(panel.getProject());
            if (toolWindowPanel != null && toolWindowPanel.getResult() != null) {
                if (!toolWindowPanel.getResult().isBugCollectionEmpty()) {
                    // Based on com.intellij.openapi.vcs.checkin.CodeAnalysisBeforeCheckinHandler#processFoundCodeSmells
                    String commitButtonText = executor != null ? executor.getActionText()
                            : panel.getCommitActionName();
                    commitButtonText = StringUtil.trimEnd(commitButtonText, "...");
                    final int answer = Messages.showYesNoCancelDialog(panel.getProject(),
                            ResourcesLoader.getString("checkin.problem.text"),
                            StringUtil.capitalizeWords(ResourcesLoader.getString("checkin.problem.title"),
                                    true),
                            ResourcesLoader.getString("checkin.problem.review"), commitButtonText,
                            CommonBundle.getCancelButtonText(), UIUtil.getWarningIcon());
                    if (answer == Messages.YES) {
                        ToolWindowPanel.showWindow(panel.getProject());
                        return ReturnResult.CLOSE_WINDOW;
                    } else if (answer == Messages.CANCEL) {
                        return ReturnResult.CANCEL;
                    }
                }
            }
            return super.beforeCheckin(executor, additionalDataConsumer);
        }
    };
}