Example usage for com.intellij.openapi.ui DialogWrapper OK_EXIT_CODE

List of usage examples for com.intellij.openapi.ui DialogWrapper OK_EXIT_CODE

Introduction

In this page you can find the example usage for com.intellij.openapi.ui DialogWrapper OK_EXIT_CODE.

Prototype

int OK_EXIT_CODE

To view the source code for com.intellij.openapi.ui DialogWrapper OK_EXIT_CODE.

Click Source Link

Document

The default exit code for "OK" action.

Usage

From source file:com.intellij.lang.javascript.generation.BaseJSGenerateHandler.java

License:Apache License

@Override
public void invoke(final Project project, final Editor editor, final PsiFile file) {
    JSClass clazz = findClass(file, editor);

    if (clazz == null) {
        return;/*  w w w. j  av a2 s.c o m*/
    }

    final Collection<JSNamedElementNode> candidates = new ArrayList<JSNamedElementNode>();
    collectCandidates(clazz, candidates);

    final Collection<JSNamedElementNode> selectedElements;

    if (ApplicationManager.getApplication().isUnitTestMode()) {
        selectedElements = candidates;
    } else {
        if (candidates.size() == 0) {
            if (!canHaveEmptySelectedElements()) {
                return;
            }
            selectedElements = Collections.emptyList();
        } else {
            final MemberChooser<JSNamedElementNode> chooser = new MemberChooser<JSNamedElementNode>(
                    candidates.toArray(new JSNamedElementNode[candidates.size()]), false, true, project,
                    false) {
                /*@Override
                  protected void customizeOptionsPanel() {
                        
                 super.customizeOptionsPanel();
                        
                    appendOwnOptions(jComponentList);
                    return jComponentList;
                  } */
            };

            chooser.setTitle(JavaScriptBundle.message(getTitleKey()));
            chooser.setCopyJavadocVisible(false);
            chooser.show();
            if (chooser.getExitCode() != DialogWrapper.OK_EXIT_CODE) {
                return;
            }
            selectedElements = chooser.getSelectedElements();
        }
    }

    if (selectedElements == null) {
        return;
    }

    final JSClass jsClass = clazz;
    final Collection<JSNamedElementNode> selectedElements1 = selectedElements;
    Runnable runnable = new Runnable() {
        @Override
        public void run() {
            ApplicationManager.getApplication().runWriteAction(new Runnable() {
                @Override
                public void run() {
                    try {
                        final BaseCreateMethodsFix createMethodsFix = createFix(jsClass);
                        createMethodsFix.addElementsToProcessFrom(selectedElements1);
                        createMethodsFix.invoke(project, editor, file);
                    } catch (IncorrectOperationException ex) {
                        Logger.getInstance(getClass().getName()).error(ex);
                    }
                }
            });
        }
    };

    if (CommandProcessor.getInstance().getCurrentCommand() == null) {
        CommandProcessor.getInstance().executeCommand(project, runnable, getClass().getName(), null);
    } else {
        runnable.run();
    }
}

From source file:com.intellij.lang.javascript.inspections.CreateClassOrInterfaceAction.java

License:Apache License

@Override
public void applyFix(@NotNull final Project project, @NotNull final ProblemDescriptor descriptor) {
    PsiFile contextFile = myContext.getContainingFile();
    final PsiElement context = contextFile.getContext();
    if (context != null) {
        contextFile = context.getContainingFile();
    }// w ww  .  jav  a2s . co  m

    packageName = JSResolveUtil.getExpectedPackageNameFromFile(contextFile.getVirtualFile(), project, false);

    if (!ApplicationManager.getApplication().isUnitTestMode()) {
        final CreateClassDialog dialog = new CreateClassDialog(project, classNameToCreate, packageName,
                myIsInterface);
        dialog.show();
        if (dialog.getExitCode() != DialogWrapper.OK_EXIT_CODE) {
            return;
        }
        packageName = dialog.getPackageName().trim();
    } else {
        packageName = "foo";
    }

    final PsiFile contextFile1 = contextFile;
    ApplicationManager.getApplication().runWriteAction(new Runnable() {
        @Override
        public void run() {
            try {
                final FileTemplate template = FileTemplateManager.getInstance().getTemplate(
                        myIsInterface ? JavaScriptSupportLoader.ACTION_SCRIPT_INTERFACE_TEMPLATE_NAME
                                : JavaScriptSupportLoader.ACTION_SCRIPT_CLASS_TEMPLATE_NAME);
                @NonNls
                final String fileName = classNameToCreate + ".as";
                final Properties props = new Properties();
                props.setProperty(FileTemplate.ATTRIBUTE_NAME, classNameToCreate);
                final Module element = ModuleUtil.findModuleForPsiElement(contextFile1);
                VirtualFile base = ModuleRootManager.getInstance(element).getSourceRoots()[0];
                VirtualFile relativeFile = VfsUtil.findRelativeFile(packageName, base);

                if (relativeFile == null) {
                    relativeFile = base;
                    StringTokenizer tokenizer = new StringTokenizer(packageName, ".");
                    while (tokenizer.hasMoreTokens()) {
                        String nextNameSegment = tokenizer.nextToken();
                        VirtualFile next = relativeFile.findChild(nextNameSegment);
                        if (next == null) {
                            next = relativeFile.createChildDirectory(this, nextNameSegment);
                        }
                        relativeFile = next;
                    }
                }

                assert relativeFile != null;
                props.setProperty(FileTemplate.ATTRIBUTE_PACKAGE_NAME, packageName);
                final PsiDirectory psiDirectory = PsiManager.getInstance(project).findDirectory(relativeFile);
                assert psiDirectory != null;
                FileTemplateUtil.createFromTemplate(template, fileName, props, psiDirectory);

                String contextPackage = JSResolveUtil.findPackageStatementQualifier(myContext);
                if (packageName != null && !packageName.equals(contextPackage) && packageName.length() > 0) {
                    ImportUtils.doImport(myContext, packageName + "." + classNameToCreate);
                }
            } catch (Exception e) {
                Logger.getInstance(getClass().getName()).error(e);
            }
        }
    });
}

From source file:com.intellij.lang.javascript.refactoring.extractMethod.JSExtractFunctionHandler.java

License:Apache License

protected JSExtractFunctionSettings getSettings(final Project project, final Editor editor) {
    final JSExtractFunctionDialog dialog = new JSExtractFunctionDialog();
    dialog.show();// w  w  w. j  a  v a 2  s  .  co  m
    if (dialog.getExitCode() != DialogWrapper.OK_EXIT_CODE) {
        return null;
    }
    return dialog;
}

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

License:Apache License

@Nullable
protected S getSettings(Project project, Editor editor, JSExpression expression,
        final JSExpression[] occurrences) {
    ArrayList<RangeHighlighter> highlighters = null;
    if (occurrences.length > 1) {
        highlighters = highlightOccurences(project, editor, occurrences);
    }/*from  ww  w  .  ja  va2  s  .  co m*/

    final D dialog = createDialog(project, expression, occurrences);
    dialog.show();
    if (highlighters != null) {
        for (RangeHighlighter highlighter : highlighters) {
            HighlightManager.getInstance(project).removeSegmentHighlighter(editor, highlighter);
        }
    }

    if (dialog.getExitCode() != DialogWrapper.OK_EXIT_CODE) {
        return null;
    }

    return createSettings(dialog);
}

From source file:com.intellij.packaging.impl.run.AbstractArtifactsBeforeRunTaskProvider.java

License:Apache License

@Override
public boolean configureTask(RunConfiguration runConfiguration, T task) {
    final Artifact[] artifacts = ArtifactManager.getInstance(myProject).getArtifacts();
    Set<ArtifactPointer> pointers = new THashSet<ArtifactPointer>();
    for (Artifact artifact : artifacts) {
        pointers.add(ArtifactPointerUtil.getPointerManager(myProject).create(artifact));
    }/*from ww w.ja v  a2 s. c o  m*/
    pointers.addAll(task.getArtifactPointers());
    ArtifactChooser chooser = new ArtifactChooser(new ArrayList<ArtifactPointer>(pointers));
    chooser.markElements(task.getArtifactPointers());
    chooser.setPreferredSize(new Dimension(400, 300));

    DialogBuilder builder = new DialogBuilder(myProject);
    builder.setTitle(CompilerBundle.message("build.artifacts.before.run.selector.title"));
    builder.setDimensionServiceKey("#BuildArtifactsBeforeRunChooser");
    builder.addOkAction();
    builder.addCancelAction();
    builder.setCenterPanel(chooser);
    builder.setPreferredFocusComponent(chooser);
    if (builder.show() == DialogWrapper.OK_EXIT_CODE) {
        task.setArtifactPointers(chooser.getMarkedElements());
        return true;
    }
    return false;
}

From source file:com.intellij.profile.codeInspection.ui.ProfilesComboBox.java

License:Apache License

public void createProfilesCombo(final Profile selectedProfile, final Set<Profile> availableProfiles,
        final ProfileManager profileManager) {
    reloadProfiles(profileManager, availableProfiles, selectedProfile);

    setRenderer(new DefaultListCellRenderer() {
        @Override//from  www  .  ja va2s. c  o  m
        public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected,
                boolean cellHasFocus) {
            final Component rendererComponent = super.getListCellRendererComponent(list, value, index,
                    isSelected, cellHasFocus);
            if (value instanceof Profile) {
                final Profile profile = (Profile) value;
                setText(profile.getName());
                setIcon(profile.isLocal() ? AllIcons.General.Settings : AllIcons.General.ProjectSettings);
            } else if (value instanceof String) {
                setText((String) value);
            }
            return rendererComponent;
        }
    });
    addItemListener(new ItemListener() {
        private Object myDeselectedItem = null;

        @Override
        public void itemStateChanged(ItemEvent e) {
            if (myFrozenProfilesCombo)
                return; //do not update during reloading
            if (ItemEvent.SELECTED == e.getStateChange()) {
                final Object item = e.getItem();
                if (profileManager instanceof ProjectProfileManager && item instanceof Profile
                        && ((Profile) item).isLocal()) {
                    if (Messages.showOkCancelDialog(
                            InspectionsBundle.message("inspection.new.profile.ide.to.project.warning.message"),
                            InspectionsBundle.message("inspection.new.profile.ide.to.project.warning.title"),
                            Messages.getErrorIcon()) == DialogWrapper.OK_EXIT_CODE) {
                        final String newName = Messages.showInputDialog(
                                InspectionsBundle.message("inspection.new.profile.text"),
                                InspectionsBundle.message("inspection.new.profile.dialog.title"),
                                Messages.getInformationIcon());
                        final Object selectedItem = getSelectedItem();
                        if (newName != null && newName.length() > 0 && selectedItem instanceof Profile) {
                            if (ArrayUtil.find(profileManager.getAvailableProfileNames(), newName) == -1
                                    && ArrayUtil.find(
                                            InspectionProfileManager.getInstance().getAvailableProfileNames(),
                                            newName) == -1) {
                                saveNewProjectProfile(newName, (Profile) selectedItem, profileManager);
                                return;
                            } else {
                                Messages.showErrorDialog(
                                        InspectionsBundle.message("inspection.unable.to.create.profile.message",
                                                newName),
                                        InspectionsBundle
                                                .message("inspection.unable.to.create.profile.dialog.title"));
                            }
                        }
                    }
                    setSelectedItem(myDeselectedItem);
                }
            } else {
                myDeselectedItem = e.getItem();
            }
        }
    });
}

From source file:com.intellij.refactoring.changeSignature.ChangeSignatureProcessor.java

License:Apache License

protected boolean isProcessCovariantOverriders() {
    return Messages.showYesNoDialog(myProject,
            RefactoringBundle.message("do.you.want.to.process.overriding.methods.with.covariant.return.type"),
            JavaChangeSignatureHandler.REFACTORING_NAME,
            Messages.getQuestionIcon()) == DialogWrapper.OK_EXIT_CODE;
}

From source file:com.intellij.refactoring.lang.ExtractIncludeFileBase.java

License:Apache License

@Override
public void invoke(@NotNull final Project project, final Editor editor, final PsiFile file,
        DataContext dataContext) {/*from  www  .j  a va  2 s.co  m*/
    myIncludingFile = file;
    if (!editor.getSelectionModel().hasSelection()) {
        String message = RefactoringBundle.getCannotRefactorMessage(RefactoringBundle.message("no.selection"));
        CommonRefactoringUtil.showErrorHint(project, editor, message, getRefactoringName(), HELP_ID);
        return;
    }
    final int start = editor.getSelectionModel().getSelectionStart();
    final int end = editor.getSelectionModel().getSelectionEnd();

    final Pair<T, T> children = findPairToExtract(start, end);
    if (children == null) {
        String message = RefactoringBundle.getCannotRefactorMessage(
                RefactoringBundle.message("selection.does.not.form.a.fragment.for.extraction"));
        CommonRefactoringUtil.showErrorHint(project, editor, message, getRefactoringName(), HELP_ID);
        return;
    }

    if (!verifyChildRange(children.getFirst(), children.getSecond())) {
        String message = RefactoringBundle.getCannotRefactorMessage(
                RefactoringBundle.message("cannot.extract.selected.elements.into.include.file"));
        CommonRefactoringUtil.showErrorHint(project, editor, message, getRefactoringName(), HELP_ID);
        return;
    }

    final FileType fileType = getFileType(getLanguageForExtract(children.getFirst()));
    if (!(fileType instanceof LanguageFileType)) {
        String message = RefactoringBundle
                .message("the.language.for.selected.elements.has.no.associated.file.type");
        CommonRefactoringUtil.showErrorHint(project, editor, message, getRefactoringName(), HELP_ID);
        return;
    }

    if (!CommonRefactoringUtil.checkReadOnlyStatus(project, file))
        return;

    ExtractIncludeDialog dialog = createDialog(file.getContainingDirectory(),
            getExtractExtension(fileType, children.first));
    dialog.show();
    if (dialog.getExitCode() == DialogWrapper.OK_EXIT_CODE) {
        final PsiDirectory targetDirectory = dialog.getTargetDirectory();
        LOG.assertTrue(targetDirectory != null);
        final String targetfileName = dialog.getTargetFileName();
        CommandProcessor.getInstance().executeCommand(project, new Runnable() {
            @Override
            public void run() {
                ApplicationManager.getApplication().runWriteAction(new Runnable() {
                    @Override
                    public void run() {
                        try {
                            final List<IncludeDuplicate<T>> duplicates = new ArrayList<IncludeDuplicate<T>>();
                            final T first = children.getFirst();
                            final T second = children.getSecond();
                            PsiEquivalenceUtil.findChildRangeDuplicates(first, second, file,
                                    new PairConsumer<PsiElement, PsiElement>() {
                                        @Override
                                        public void consume(final PsiElement start, final PsiElement end) {
                                            duplicates.add(new IncludeDuplicate<T>((T) start, (T) end));
                                        }
                                    });
                            final String includePath = processPrimaryFragment(first, second, targetDirectory,
                                    targetfileName, file);
                            editor.getCaretModel().moveToOffset(first.getTextRange().getStartOffset());

                            ApplicationManager.getApplication().invokeLater(new Runnable() {
                                @Override
                                public void run() {
                                    replaceDuplicates(includePath, duplicates, editor, project);
                                }
                            });
                        } catch (IncorrectOperationException e) {
                            CommonRefactoringUtil.showErrorMessage(getRefactoringName(), e.getMessage(), null,
                                    project);
                        }

                        editor.getSelectionModel().removeSelection();
                    }
                });
            }
        }, getRefactoringName(), null);

    }
}

From source file:com.intellij.refactoring.memberPushDown.PushDownProcessor.java

License:Apache License

protected boolean preprocessUsages(final Ref<UsageInfo[]> refUsages) {
    final UsageInfo[] usagesIn = refUsages.get();
    final PushDownConflicts pushDownConflicts = new PushDownConflicts(myClass, myMemberInfos);
    pushDownConflicts.checkSourceClassConflicts();

    if (usagesIn.length == 0) {
        if (myClass.isEnum() || myClass.hasModifierProperty(PsiModifier.FINAL)) {
            if (Messages.showOkCancelDialog(
                    (myClass.isEnum()// w w w .j ava  2s  .  c om
                            ? "Enum " + myClass.getQualifiedName() + " doesn't have constants to inline to. "
                            : "Final class " + myClass.getQualifiedName() + "does not have inheritors. ")
                            + "Pushing members down will result in them being deleted. "
                            + "Would you like to proceed?",
                    JavaPushDownHandler.REFACTORING_NAME,
                    Messages.getWarningIcon()) != DialogWrapper.OK_EXIT_CODE) {
                return false;
            }
        } else {
            String noInheritors = myClass.isInterface()
                    ? RefactoringBundle.message("interface.0.does.not.have.inheritors",
                            myClass.getQualifiedName())
                    : RefactoringBundle.message("class.0.does.not.have.inheritors", myClass.getQualifiedName());
            final String message = noInheritors + "\n"
                    + RefactoringBundle.message("push.down.will.delete.members");
            final int answer = Messages.showYesNoCancelDialog(message, JavaPushDownHandler.REFACTORING_NAME,
                    Messages.getWarningIcon());
            if (answer == DialogWrapper.OK_EXIT_CODE) {
                myCreateClassDlg = CreateSubclassAction.chooseSubclassToCreate(myClass);
                if (myCreateClassDlg != null) {
                    pushDownConflicts.checkTargetClassConflicts(null, false,
                            myCreateClassDlg.getTargetDirectory());
                    return showConflicts(pushDownConflicts.getConflicts(), usagesIn);
                } else {
                    return false;
                }
            } else if (answer != 1)
                return false;
        }
    }
    Runnable runnable = new Runnable() {
        public void run() {
            for (UsageInfo usage : usagesIn) {
                final PsiElement element = usage.getElement();
                if (element instanceof PsiClass) {
                    pushDownConflicts.checkTargetClassConflicts((PsiClass) element, usagesIn.length > 1,
                            element);
                }
            }
        }
    };

    if (!ProgressManager.getInstance().runProcessWithProgressSynchronously(runnable,
            RefactoringBundle.message("detecting.possible.conflicts"), true, myProject)) {
        return false;
    }
    return showConflicts(pushDownConflicts.getConflicts(), usagesIn);
}

From source file:com.intellij.refactoring.move.moveClassesOrPackages.JavaMoveClassesOrPackagesHandler.java

License:Apache License

private static void moveDirectoriesLibrariesSafe(Project project, PsiElement targetContainer,
        MoveCallback callback, PsiDirectory[] directories, String prompt) {
    final PsiJavaPackage aPackage = JavaDirectoryService.getInstance().getPackage(directories[0]);
    LOG.assertTrue(aPackage != null);//from   w ww .  jav  a 2 s  . c  om
    final PsiDirectory[] projectDirectories = aPackage.getDirectories(GlobalSearchScope.projectScope(project));
    if (projectDirectories.length > 1) {
        int ret = Messages.showYesNoCancelDialog(project, prompt + " or all directories in project?",
                RefactoringBundle.message("warning.title"), RefactoringBundle.message("move.current.directory"),
                RefactoringBundle.message("move.directories"), CommonBundle.getCancelButtonText(),
                Messages.getWarningIcon());
        if (ret == 0) {
            moveAsDirectory(project, targetContainer, callback, directories);
        } else if (ret == 1) {
            moveAsDirectory(project, targetContainer, callback, projectDirectories);
        }
    } else if (Messages.showOkCancelDialog(project, prompt + "?", RefactoringBundle.message("warning.title"),
            Messages.getWarningIcon()) == DialogWrapper.OK_EXIT_CODE) {
        moveAsDirectory(project, targetContainer, callback, directories);
    }
}