List of usage examples for com.intellij.openapi.ui DialogWrapper OK_EXIT_CODE
int OK_EXIT_CODE
To view the source code for com.intellij.openapi.ui DialogWrapper OK_EXIT_CODE.
Click Source Link
From source file:com.intellij.refactoring.move.moveInstanceMethod.MoveInstanceMethodHandler.java
License:Apache License
public void invoke(@NotNull final Project project, @NotNull final PsiElement[] elements, final DataContext dataContext) { if (elements.length != 1 || !(elements[0] instanceof PsiMethod)) return;/* www. j ava 2s . c o m*/ final PsiMethod method = (PsiMethod) elements[0]; String message = null; if (!method.getManager().isInProject(method)) { message = "Move method is not supported for non-project methods"; } else if (method.isConstructor()) { message = RefactoringBundle.message("move.method.is.not.supported.for.constructors"); } else if (method.getLanguage() != JavaLanguage.INSTANCE) { message = RefactoringBundle.message("move.method.is.not.supported.for.0", method.getLanguage().getDisplayName()); } else { final PsiClass containingClass = method.getContainingClass(); if (containingClass != null && PsiUtil.typeParametersIterator(containingClass).hasNext() && TypeParametersSearcher.hasTypeParameters(method)) { message = RefactoringBundle.message("move.method.is.not.supported.for.generic.classes"); } else if (method.findSuperMethods().length > 0 || OverridingMethodsSearch.search(method, true).toArray(PsiMethod.EMPTY_ARRAY).length > 0) { message = RefactoringBundle .message("move.method.is.not.supported.when.method.is.part.of.inheritance.hierarchy"); } else { final Set<PsiClass> classes = MoveInstanceMembersUtil.getThisClassesToMembers(method).keySet(); for (PsiClass aClass : classes) { /* if (aClass instanceof JspClass) { message = RefactoringBundle.message("synthetic.jsp.class.is.referenced.in.the.method"); Editor editor = PlatformDataKeys.EDITOR.getData(dataContext); CommonRefactoringUtil.showErrorHint(project, editor, message, REFACTORING_NAME, HelpID.MOVE_INSTANCE_METHOD); break; } */ } } } if (message != null) { showErrorHint(project, dataContext, message); return; } final List<PsiVariable> suitableVariables = new ArrayList<PsiVariable>(); message = collectSuitableVariables(method, suitableVariables); if (message != null) { final String unableToMakeStaticMessage = MakeStaticHandler.validateTarget(method); if (unableToMakeStaticMessage != null) { showErrorHint(project, dataContext, message); } else { final String suggestToMakeStaticMessage = "Would you like to make method \'" + method.getName() + "\' static and then move?"; if (Messages.showYesNoCancelDialog(project, message + ". " + suggestToMakeStaticMessage, REFACTORING_NAME, Messages.getErrorIcon()) == DialogWrapper.OK_EXIT_CODE) { MakeStaticHandler.invoke(method); } } return; } new MoveInstanceMethodDialog(method, suitableVariables.toArray(new PsiVariable[suitableVariables.size()])) .show(); }
From source file:com.intellij.refactoring.rename.DirectoryAsPackageRenameHandlerBase.java
License:Apache License
private void doRename(PsiElement element, final Project project, PsiElement nameSuggestionContext, Editor editor) {//from w w w . j av a2 s .co m final PsiDirectory psiDirectory = (PsiDirectory) element; final T aPackage = getPackage(psiDirectory); final String qualifiedName = aPackage != null ? getQualifiedName(aPackage) : ""; if (aPackage == null || qualifiedName.length() == 0/*default package*/ || !isIdentifier(psiDirectory.getName(), project)) { PsiElementRenameHandler.rename(element, project, nameSuggestionContext, editor); } else { PsiDirectory[] directories = aPackage.getDirectories(); final VirtualFile[] virtualFiles = occursInPackagePrefixes(aPackage); if (virtualFiles.length == 0 && directories.length == 1) { PsiElementRenameHandler.rename(aPackage, project, nameSuggestionContext, editor); } else { // the directory corresponds to a package that has multiple associated directories final ProjectFileIndex projectFileIndex = ProjectRootManager.getInstance(project).getFileIndex(); boolean inLib = false; for (PsiDirectory directory : directories) { inLib |= !projectFileIndex.isInContent(directory.getVirtualFile()); } final PsiDirectory[] projectDirectories = aPackage .getDirectories(GlobalSearchScope.projectScope(project)); if (inLib) { final Module module = ModuleUtilCore.findModuleForPsiElement(psiDirectory); LOG.assertTrue(module != null); PsiDirectory[] moduleDirs = null; if (nameSuggestionContext instanceof PsiPackageBase) { moduleDirs = aPackage.getDirectories(GlobalSearchScope.moduleScope(module)); if (moduleDirs.length <= 1) { moduleDirs = null; } } final String promptMessage = "Package \'" + aPackage.getName() + "\' contains directories in libraries which cannot be renamed. Do you want to rename " + (moduleDirs == null ? "current directory" : "current module directories"); if (projectDirectories.length > 0) { int ret = Messages.showYesNoCancelDialog(project, promptMessage + " or all directories in project?", RefactoringBundle.message("warning.title"), RefactoringBundle.message("rename.current.directory"), RefactoringBundle.message("rename.directories"), CommonBundle.getCancelButtonText(), Messages.getWarningIcon()); if (ret == 2) return; renameDirs(project, nameSuggestionContext, editor, psiDirectory, aPackage, ret == 0 ? (moduleDirs == null ? new PsiDirectory[] { psiDirectory } : moduleDirs) : projectDirectories); } else { if (Messages.showOkCancelDialog(project, promptMessage + "?", RefactoringBundle.message("warning.title"), Messages.getWarningIcon()) == DialogWrapper.OK_EXIT_CODE) { renameDirs(project, nameSuggestionContext, editor, psiDirectory, aPackage, psiDirectory); } } } else { final StringBuffer message = new StringBuffer(); RenameUtil.buildPackagePrefixChangedMessage(virtualFiles, message, qualifiedName); buildMultipleDirectoriesInPackageMessage(message, getQualifiedName(aPackage), directories); message.append( RefactoringBundle.message("directories.and.all.references.to.package.will.be.renamed", psiDirectory.getVirtualFile().getPresentableUrl())); int ret = Messages.showYesNoCancelDialog(project, message.toString(), RefactoringBundle.message("warning.title"), RefactoringBundle.message("rename.package.button.text"), RefactoringBundle.message("rename.directory.button.text"), CommonBundle.getCancelButtonText(), Messages.getWarningIcon()); if (ret == 0) { PsiElementRenameHandler.rename(aPackage, project, nameSuggestionContext, editor); } else if (ret == 1) { renameDirs(project, nameSuggestionContext, editor, psiDirectory, aPackage, psiDirectory); } } } } }
From source file:com.intellij.refactoring.rename.inplace.InplaceRefactoring.java
License:Apache License
private static void navigateToStarted(final Document oldDocument, final Project project, final int exitCode) { final PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(oldDocument); if (file != null) { final VirtualFile virtualFile = file.getVirtualFile(); if (virtualFile != null) { final FileEditor[] editors = FileEditorManager.getInstance(project).getEditors(virtualFile); for (FileEditor editor : editors) { if (editor instanceof TextEditor) { final Editor textEditor = ((TextEditor) editor).getEditor(); final TemplateState templateState = TemplateManagerImpl.getTemplateState(textEditor); if (templateState != null) { if (exitCode == DialogWrapper.OK_EXIT_CODE) { final TextRange range = templateState.getVariableRange(PRIMARY_VARIABLE_NAME); if (range != null) { new OpenFileDescriptor(project, virtualFile, range.getStartOffset()) .navigate(true); return; }/*from w ww.j a va 2 s .com*/ } else if (exitCode > 0) { templateState.gotoEnd(); return; } } } } } } }
From source file:com.intellij.refactoring.safeDelete.JavaSafeDeleteProcessor.java
License:Apache License
@Nullable @Override/*w w w . ja v a 2 s .c o m*/ public Collection<? extends PsiElement> getElementsToSearch(PsiElement element, @Nullable Module module, Collection<PsiElement> allElementsToDelete) { Project project = element.getProject(); if (element instanceof PsiPackage && module != null) { final PsiDirectory[] directories = ((PsiPackage) element).getDirectories(module.getModuleScope()); if (directories.length == 0) return null; return Arrays.asList(directories); } else if (element instanceof PsiMethod) { final PsiMethod[] methods = SuperMethodWarningUtil.checkSuperMethods((PsiMethod) element, RefactoringBundle.message("to.delete.with.usage.search"), allElementsToDelete); if (methods.length == 0) return null; final ArrayList<PsiMethod> psiMethods = new ArrayList<PsiMethod>(Arrays.asList(methods)); psiMethods.add((PsiMethod) element); return psiMethods; } else if (element instanceof PsiParameter && ((PsiParameter) element).getDeclarationScope() instanceof PsiMethod) { PsiMethod method = (PsiMethod) ((PsiParameter) element).getDeclarationScope(); final Set<PsiParameter> parametersToDelete = new HashSet<PsiParameter>(); parametersToDelete.add((PsiParameter) element); final int parameterIndex = method.getParameterList().getParameterIndex((PsiParameter) element); final List<PsiMethod> superMethods = new ArrayList<PsiMethod>( Arrays.asList(method.findDeepestSuperMethods())); if (superMethods.isEmpty()) { superMethods.add(method); } for (PsiMethod superMethod : superMethods) { parametersToDelete.add(superMethod.getParameterList().getParameters()[parameterIndex]); OverridingMethodsSearch.search(superMethod).forEach(new Processor<PsiMethod>() { public boolean process(PsiMethod overrider) { parametersToDelete.add(overrider.getParameterList().getParameters()[parameterIndex]); return true; } }); } if (parametersToDelete.size() > 1 && !ApplicationManager.getApplication().isUnitTestMode()) { String message = RefactoringBundle.message( "0.is.a.part.of.method.hierarchy.do.you.want.to.delete.multiple.parameters", UsageViewUtil.getLongName(method)); if (Messages.showYesNoDialog(project, message, SafeDeleteHandler.REFACTORING_NAME, Messages.getQuestionIcon()) != DialogWrapper.OK_EXIT_CODE) return null; } return parametersToDelete; } else { return Collections.singletonList(element); } }
From source file:com.intellij.refactoring.typeMigration.TypeMigrationLabeler.java
License:Apache License
boolean addRoot(final TypeMigrationUsageInfo usageInfo, final PsiType type, final PsiElement place, boolean alreadyProcessed) { if (myShowWarning && myMigrationRoots.size() > 10 && !ApplicationManager.getApplication().isUnitTestMode()) { myShowWarning = false;/*from w w w . j a v a2 s.c o m*/ try { final Runnable checkTimeToStopRunnable = new Runnable() { public void run() { if (Messages.showYesNoCancelDialog( "Found more than 10 roots to migrate. Do you want to preview?", "Type Migration", Messages.getWarningIcon()) == DialogWrapper.OK_EXIT_CODE) { myException = new MigrateException(); } } }; SwingUtilities.invokeLater(checkTimeToStopRunnable); } catch (Exception e) { //do nothing } } if (myException != null) throw myException; rememberRootTrace(usageInfo, type, place, alreadyProcessed); if (!alreadyProcessed && !getTypeEvaluator().setType(usageInfo, type)) { alreadyProcessed = true; } if (!alreadyProcessed) myMigrationRoots.addFirst(new Pair<TypeMigrationUsageInfo, PsiType>(usageInfo, type)); return alreadyProcessed; }
From source file:com.intellij.refactoring.typeMigration.ui.TypeMigrationDialog.java
License:Apache License
protected void doAction() { FindSettings.getInstance().setDefaultScopeName(myScopeChooserCombo.getSelectedScopeName()); final PsiType rootType = getRootType(); final CanonicalTypes.Type typeWrapper = CanonicalTypes.createTypeWrapper(getMigrationType()); assert typeWrapper != null : getMigrationType(); final PsiType migrationType = typeWrapper.getType(myRoot, myRoot.getManager()); if (Comparing.equal(rootType, migrationType)) { close(DialogWrapper.OK_EXIT_CODE); return;// ww w . j a va 2 s. com } if (myRules == null) { myRules = new TypeMigrationRules(rootType); myRules.setMigrationRootType(migrationType); myRules.setBoundScope(myScopeChooserCombo.getSelectedScope()); } invokeRefactoring(new TypeMigrationProcessor(myProject, myRoot, myRules)); }
From source file:com.intellij.refactoring.ui.RefactoringDialog.java
License:Apache License
protected void invokeRefactoring(BaseRefactoringProcessor processor) { final Runnable prepareSuccessfulCallback = new Runnable() { @Override//from w w w . ja v a2 s.c o m public void run() { close(DialogWrapper.OK_EXIT_CODE); } }; processor.setPrepareSuccessfulSwingThreadCallback(prepareSuccessfulCallback); processor.setPreviewUsages(isPreviewUsages()); processor.run(); }
From source file:com.intellij.refactoring.util.duplicates.DuplicatesImpl.java
License:Apache License
private static boolean replaceMatch(final Project project, final MatchProvider provider, final Match match, @NotNull final Editor editor, final int idx, final int size, Ref<Boolean> showAll, final String confirmDuplicatePrompt, boolean skipPromptWhenOne) { final ArrayList<RangeHighlighter> highlighters = previewMatch(project, match, editor); if (!ApplicationManager.getApplication().isUnitTestMode()) { if ((!skipPromptWhenOne || size > 1) && (showAll.get() == null || !showAll.get())) { final String prompt = provider.getConfirmDuplicatePrompt(match); final ReplacePromptDialog promptDialog = new ReplacePromptDialog(false, provider.getReplaceDuplicatesTitle(idx, size), project) { @Override/* w w w . ja va2s. c o m*/ protected String getMessage() { final String message = super.getMessage(); return prompt != null ? message + prompt : message; } }; promptDialog.show(); final boolean allChosen = promptDialog.getExitCode() == FindManager.PromptResult.ALL; showAll.set(allChosen); if (allChosen && confirmDuplicatePrompt != null && prompt == null) { if (Messages.showOkCancelDialog(project, "In order to replace all occurrences method signature will be changed. Proceed?", CommonBundle.getWarningTitle(), Messages.getWarningIcon()) != DialogWrapper.OK_EXIT_CODE) return true; } if (promptDialog.getExitCode() == FindManager.PromptResult.SKIP) return false; if (promptDialog.getExitCode() == FindManager.PromptResult.CANCEL) return true; } } HighlightManager.getInstance(project).removeSegmentHighlighter(editor, highlighters.get(0)); new WriteCommandAction(project, MethodDuplicatesHandler.REFACTORING_NAME) { @Override protected void run(Result result) throws Throwable { try { provider.processMatch(match); } catch (IncorrectOperationException e) { LOG.error(e); } } }.execute(); return false; }
From source file:com.intellij.struts2.facet.ui.FileSetConfigurationTab.java
License:Apache License
public FileSetConfigurationTab(@NotNull final StrutsFacetConfiguration strutsFacetConfiguration, @NotNull final FacetEditorContext facetEditorContext) { originalConfiguration = strutsFacetConfiguration; module = facetEditorContext.getModule(); myConfigsSearcher = new StrutsConfigsSearcher(module); // init tree/* ww w.ja va 2 s . c o m*/ final SimpleTreeStructure structure = new SimpleTreeStructure() { public Object getRootElement() { return myRootNode; } }; myTree = new SimpleTree(); myTree.setRootVisible(false); myTree.setShowsRootHandles(true); // show expand/collapse handles myTree.getEmptyText().setText(StrutsBundle.message("facet.fileset.no.filesets.defined"), SimpleTextAttributes.ERROR_ATTRIBUTES); myTreeExpander = new DefaultTreeExpander(myTree); myBuilder = new SimpleTreeBuilder(myTree, (DefaultTreeModel) myTree.getModel(), structure, null); myBuilder.initRoot(); final DumbService dumbService = DumbService.getInstance(facetEditorContext.getProject()); myTree.getSelectionModel().addTreeSelectionListener(new TreeSelectionListener() { public void valueChanged(final TreeSelectionEvent e) { final StrutsFileSet fileSet = getCurrentFileSet(); myEditButton.setEnabled(fileSet != null && !dumbService.isDumb()); myRemoveButton.setEnabled(fileSet != null); } }); final CommonActionsManager actionManager = CommonActionsManager.getInstance(); myTreePanel.add(ToolbarDecorator.createDecorator(myTree).setAddAction(new AnActionButtonRunnable() { @Override public void run(AnActionButton button) { final StrutsFileSet fileSet = new StrutsFileSet(StrutsFileSet.getUniqueId(myBuffer), StrutsFileSet.getUniqueName(StrutsBundle.message("facet.fileset.my.fileset"), myBuffer), originalConfiguration) { public boolean isNew() { return true; } }; final FileSetEditor editor = new FileSetEditor(myPanel, fileSet, facetEditorContext, myConfigsSearcher); editor.show(); if (editor.getExitCode() == DialogWrapper.OK_EXIT_CODE) { final StrutsFileSet editedFileSet = editor.getEditedFileSet(); Disposer.register(strutsFacetConfiguration, editedFileSet); myBuffer.add(editedFileSet); myModified = true; myBuilder.updateFromRoot(); selectFileSet(fileSet); } myTree.requestFocus(); } }).setRemoveAction(new AnActionButtonRunnable() { @Override public void run(AnActionButton button) { remove(); myModified = true; myBuilder.updateFromRoot(); myTree.requestFocus(); } }).setEditAction(new AnActionButtonRunnable() { @Override public void run(AnActionButton button) { final StrutsFileSet fileSet = getCurrentFileSet(); if (fileSet != null) { final FileSetEditor editor = new FileSetEditor(myPanel, fileSet, facetEditorContext, myConfigsSearcher); editor.show(); if (editor.getExitCode() == DialogWrapper.OK_EXIT_CODE) { myModified = true; myBuffer.remove(fileSet); final StrutsFileSet edited = editor.getEditedFileSet(); Disposer.register(strutsFacetConfiguration, edited); myBuffer.add(edited); edited.setAutodetected(false); myBuilder.updateFromRoot(); selectFileSet(edited); } myTree.requestFocus(); } } }).addExtraAction(AnActionButton.fromAction(actionManager.createExpandAllAction(myTreeExpander, myTree))) .addExtraAction( AnActionButton.fromAction(actionManager.createCollapseAllAction(myTreeExpander, myTree))) .addExtraAction(new AnActionButton("Open Struts 2 plugin documentation", AllIcons.Actions.Help) { @Override public void actionPerformed(AnActionEvent e) { BrowserUtil.browse("http://confluence.jetbrains.com/pages/viewpage.action?pageId=35367"); } }) .disableUpDownActions().createPanel()); myEditButton = ToolbarDecorator.findEditButton(myTreePanel); myRemoveButton = ToolbarDecorator.findRemoveButton(myTreePanel); AnActionButton addButton = ToolbarDecorator.findAddButton(myTreePanel); assert addButton != null; dumbService.makeDumbAware(addButton.getContextComponent(), this); dumbService.makeDumbAware(myEditButton.getContextComponent(), this); }
From source file:com.intellij.testIntegration.createTest.CreateTestAction.java
License:Apache License
@Override public void invoke(final @NotNull Project project, Editor editor, @NotNull PsiElement element) throws IncorrectOperationException { if (!FileModificationService.getInstance().preparePsiElementForWrite(element)) return;/*from w w w . j a v a 2 s .com*/ final Module srcModule = ModuleUtilCore.findModuleForPsiElement(element); final PsiClass srcClass = getContainingClass(element); if (srcClass == null) return; PsiDirectory srcDir = element.getContainingFile().getContainingDirectory(); PsiJavaPackage srcPackage = JavaDirectoryService.getInstance().getPackage(srcDir); final PropertiesComponent propertiesComponent = PropertiesComponent.getInstance(); final HashSet<VirtualFile> testFolders = new HashSet<VirtualFile>(); checkForTestRoots(srcModule, testFolders); if (testFolders.isEmpty() && !propertiesComponent.getBoolean(CREATE_TEST_IN_THE_SAME_ROOT, false)) { if (Messages.showOkCancelDialog(project, "Create test in the same source root?", "No Test Roots Found", Messages.getQuestionIcon()) != DialogWrapper.OK_EXIT_CODE) { return; } propertiesComponent.setValue(CREATE_TEST_IN_THE_SAME_ROOT, String.valueOf(true)); } final CreateTestDialog d = new CreateTestDialog(project, getText(), srcClass, srcPackage, srcModule); d.show(); if (!d.isOK()) return; CommandProcessor.getInstance().executeCommand(project, new Runnable() { @Override public void run() { TestFramework framework = d.getSelectedTestFrameworkDescriptor(); TestGenerator generator = TestGenerators.INSTANCE.forLanguage(framework.getLanguage()); generator.generateTest(project, d); } }, CodeInsightBundle.message("intention.create.test"), this); }