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:org.jetbrains.plugins.groovy.actions.generate.missing.GroovyGeneratePropertyMissingHandler.java
License:Apache License
@Nullable @Override// www . j a va2 s .co m protected ClassMember[] chooseOriginalMembers(PsiClass aClass, Project project) { final PsiMethod[] missings = aClass.findMethodsByName("propertyMissing", true); PsiMethod getter = null; PsiMethod setter = null; for (PsiMethod missing : missings) { final PsiParameter[] parameters = missing.getParameterList().getParameters(); if (parameters.length == 1) { if (isNameParam(parameters[0])) { getter = missing; } } else if (parameters.length == 2) { if (isNameParam(parameters[0])) { setter = missing; } } } if (setter != null && getter != null) { String text = GroovyCodeInsightBundle.message("generate.property.missing.already.defined.warning"); if (Messages.showYesNoDialog(project, text, GroovyCodeInsightBundle.message("generate.property.missing.already.defined.title"), Messages.getQuestionIcon()) == DialogWrapper.OK_EXIT_CODE) { final PsiMethod finalGetter = getter; final PsiMethod finalSetter = setter; if (!ApplicationManager.getApplication().runWriteAction(new Computable<Boolean>() { public Boolean compute() { try { finalSetter.delete(); finalGetter.delete(); return Boolean.TRUE; } catch (IncorrectOperationException e) { LOG.error(e); return Boolean.FALSE; } } }).booleanValue()) { return null; } } else { return null; } } return new ClassMember[1]; }
From source file:org.jetbrains.plugins.groovy.annotator.intentions.CreateClassActionBase.java
License:Apache License
@Nullable protected PsiDirectory getTargetDirectory(@NotNull Project project, @NotNull String qualifier, @NotNull String name, @Nullable Module module, @NotNull String title) { CreateClassDialog dialog = new CreateClassDialog(project, title, name, qualifier, getType(), false, module) {//w w w .ja v a 2s .c om @Override protected boolean reportBaseInSourceSelectionInTest() { return true; } }; dialog.show(); if (dialog.getExitCode() != DialogWrapper.OK_EXIT_CODE) return null; return dialog.getTargetDirectory(); }
From source file:org.jetbrains.plugins.groovy.annotator.intentions.dynamic.DynamicToolWindowWrapper.java
License:Apache License
private boolean removeDynamicElement(DefaultMutableTreeNode child, boolean isShowDialog, int rowsCount) { Object namedElement = child.getUserObject(); if (!(namedElement instanceof DNamedElement)) return false; if (isShowDialog) { int result; if (rowsCount > 1) { result = Messages.showOkCancelDialog(myBigPanel, GroovyBundle.message("are.you.sure.to.delete.elements", String.valueOf(rowsCount)), GroovyBundle.message("dynamic.element.deletion"), Messages.getQuestionIcon()); } else {// w w w.j a v a 2 s .c om result = Messages.showOkCancelDialog(myBigPanel, GroovyBundle.message("are.you.sure.to.delete.dynamic.property", ((DNamedElement) namedElement).getName()), GroovyBundle.message("dynamic.property.deletion"), Messages.getQuestionIcon()); } if (result != DialogWrapper.OK_EXIT_CODE) return false; } removeNamedElement(((DNamedElement) namedElement)); return true; }
From source file:org.jetbrains.plugins.groovy.findUsages.GroovyFieldFindUsagesHandlerFactory.java
License:Apache License
@Override public FindUsagesHandler createFindUsagesHandler(@NotNull PsiElement element, boolean forHighlightUsages) { return new JavaFindUsagesHandler(element, this) { @NotNull//w w w. j av a 2s . c o m @Override public PsiElement[] getSecondaryElements() { PsiElement element = getPsiElement(); final PsiField field = (PsiField) element; PsiClass containingClass = field.getContainingClass(); if (containingClass != null) { PsiMethod[] getters = GroovyPropertyUtils.getAllGettersByField(field); PsiMethod[] setters = GroovyPropertyUtils.getAllSettersByField(field); if (getters.length + setters.length > 0) { final boolean doSearch; if (arePhysical(getters) || arePhysical(setters)) { if (ApplicationManager.getApplication().isUnitTestMode()) return PsiElement.EMPTY_ARRAY; doSearch = Messages.showYesNoDialog( FindBundle.message("find.field.accessors.prompt", field.getName()), FindBundle.message("find.field.accessors.title"), Messages.getQuestionIcon()) == DialogWrapper.OK_EXIT_CODE; } else { doSearch = true; } if (doSearch) { final List<PsiElement> elements = new ArrayList<PsiElement>(); for (PsiMethod getter : getters) { ContainerUtil.addAll(elements, SuperMethodWarningUtil.checkSuperMethods(getter, ACTION_STRING)); } for (PsiMethod setter : setters) { ContainerUtil.addAll(elements, SuperMethodWarningUtil.checkSuperMethods(setter, ACTION_STRING)); } for (Iterator<PsiElement> iterator = elements.iterator(); iterator.hasNext();) { if (iterator.next() instanceof GrAccessorMethod) iterator.remove(); } return PsiUtilCore.toPsiElementArray(elements); } else { return PsiElement.EMPTY_ARRAY; } } } return super.getSecondaryElements(); } }; }
From source file:org.jetbrains.plugins.groovy.intentions.conversions.ConvertClosureToMethodIntention.java
License:Apache License
@Override protected void processIntention(@NotNull PsiElement element, Project project, Editor editor) throws IncorrectOperationException { final GrField field; if (element.getParent() instanceof GrField) { field = (GrField) element.getParent(); } else {/*from w ww .j a va 2s . co m*/ final PsiReference ref = element.getReference(); LOG.assertTrue(ref != null); PsiElement resolved = ref.resolve(); if (resolved instanceof GrAccessorMethod) { resolved = ((GrAccessorMethod) resolved).getProperty(); } LOG.assertTrue(resolved instanceof GrField); field = (GrField) resolved; } final HashSet<PsiReference> usages = new HashSet<PsiReference>(); usages.addAll(ReferencesSearch.search(field).findAll()); final GrAccessorMethod[] getters = field.getGetters(); for (GrAccessorMethod getter : getters) { usages.addAll(MethodReferencesSearch.search(getter).findAll()); } final GrAccessorMethod setter = field.getSetter(); if (setter != null) { usages.addAll(MethodReferencesSearch.search(setter).findAll()); } final String fieldName = field.getName(); LOG.assertTrue(fieldName != null); final Collection<PsiElement> fieldUsages = new HashSet<PsiElement>(); MultiMap<PsiElement, String> conflicts = new MultiMap<PsiElement, String>(); for (PsiReference usage : usages) { final PsiElement psiElement = usage.getElement(); if (PsiUtil.isMethodUsage(psiElement)) continue; if (!GroovyFileType.GROOVY_LANGUAGE.equals(psiElement.getLanguage())) { conflicts.putValue(psiElement, GroovyIntentionsBundle.message("closure.is.accessed.outside.of.groovy", fieldName)); } else { if (psiElement instanceof GrReferenceExpression) { fieldUsages.add(psiElement); if (PsiUtil.isAccessedForWriting((GrExpression) psiElement)) { conflicts.putValue(psiElement, GroovyIntentionsBundle.message("write.access.to.closure.variable", fieldName)); } } else if (psiElement instanceof GrArgumentLabel) { conflicts.putValue(psiElement, GroovyIntentionsBundle.message("field.is.used.in.argument.label", fieldName)); } } } final PsiClass containingClass = field.getContainingClass(); final GrExpression initializer = field.getInitializerGroovy(); LOG.assertTrue(initializer != null); final PsiType type = initializer.getType(); LOG.assertTrue(type instanceof GrClosureType); final GrSignature signature = ((GrClosureType) type).getSignature(); final List<MethodSignature> signatures = GrClosureSignatureUtil .generateAllMethodSignaturesBySignature(fieldName, signature); for (MethodSignature s : signatures) { final PsiMethod method = MethodSignatureUtil.findMethodBySignature(containingClass, s, true); if (method != null) { conflicts.putValue(method, GroovyIntentionsBundle.message("method.with.signature.already.exists", GroovyPresentationUtil.getSignaturePresentation(s))); } } if (conflicts.size() > 0) { final ConflictsDialog conflictsDialog = new ConflictsDialog(project, conflicts, new Runnable() { @Override public void run() { execute(field, fieldUsages); } }); conflictsDialog.show(); if (conflictsDialog.getExitCode() != DialogWrapper.OK_EXIT_CODE) return; } execute(field, fieldUsages); }
From source file:org.jetbrains.plugins.groovy.intentions.conversions.ConvertMapToClassIntention.java
License:Apache License
@Override protected void processIntention(@NotNull PsiElement element, final Project project, Editor editor) throws IncorrectOperationException { final GrListOrMap map = (GrListOrMap) element; final GrNamedArgument[] namedArguments = map.getNamedArguments(); LOG.assertTrue(map.getInitializers().length == 0); final PsiFile file = map.getContainingFile(); final String packageName = file instanceof GroovyFileBase ? ((GroovyFileBase) file).getPackageName() : ""; final CreateClassDialog dialog = new CreateClassDialog(project, GroovyBundle.message("create.class.family.name"), "", packageName, CreateClassKind.CLASS, true, ModuleUtil.findModuleForPsiElement(element)); dialog.show();/*from ww w.j a va 2s. c om*/ if (dialog.getExitCode() != DialogWrapper.OK_EXIT_CODE) return; boolean replaceReturnType = checkForReturnFromMethod(map); boolean variableDeclaration = checkForVariableDeclaration(map); final GrParameter methodParameter = checkForMethodParameter(map); final String qualifiedClassName = dialog.getClassName(); final String selectedPackageName = StringUtil.getPackageName(qualifiedClassName); final String shortName = StringUtil.getShortName(qualifiedClassName); final GrTypeDefinition typeDefinition = createClass(project, namedArguments, selectedPackageName, shortName); final PsiClass generatedClass = CreateClassActionBase.createClassByType(dialog.getTargetDirectory(), typeDefinition.getName(), PsiManager.getInstance(project), map, GroovyTemplates.GROOVY_CLASS); final PsiClass replaced = (PsiClass) generatedClass.replace(typeDefinition); replaceMapWithClass(project, map, replaced, replaceReturnType, variableDeclaration, methodParameter); }
From source file:org.jetbrains.plugins.groovy.intentions.conversions.ConvertMethodToClosureIntention.java
License:Apache License
@Override protected void processIntention(@NotNull PsiElement element, Project project, Editor editor) throws IncorrectOperationException { MultiMap<PsiElement, String> conflicts = new MultiMap<PsiElement, String>(); final GrMethod method; if (element.getParent() instanceof GrMethod) { method = (GrMethod) element.getParent(); } else {//from w w w. ja va 2 s . c o m final PsiReference ref = element.getReference(); LOG.assertTrue(ref != null); final PsiElement resolved = ref.resolve(); LOG.assertTrue(resolved instanceof GrMethod); method = (GrMethod) resolved; } final PsiClass containingClass = method.getContainingClass(); final String methodName = method.getName(); final PsiField field = containingClass.findFieldByName(methodName, true); if (field != null) { conflicts.putValue(field, GroovyIntentionsBundle.message("field.already.exists", methodName)); } final Collection<PsiReference> references = MethodReferencesSearch.search(method).findAll(); final Collection<GrReferenceExpression> usagesToConvert = new HashSet<GrReferenceExpression>( references.size()); for (PsiReference ref : references) { final PsiElement psiElement = ref.getElement(); if (!GroovyFileType.GROOVY_LANGUAGE.equals(psiElement.getLanguage())) { conflicts.putValue(psiElement, GroovyIntentionsBundle.message("method.is.used.outside.of.groovy")); } else if (!PsiUtil.isMethodUsage(psiElement)) { if (psiElement instanceof GrReferenceExpression) { if (((GrReferenceExpression) psiElement).hasMemberPointer()) { usagesToConvert.add((GrReferenceExpression) psiElement); } } } } if (conflicts.size() > 0) { ConflictsDialog conflictsDialog = new ConflictsDialog(project, conflicts, new Runnable() { @Override public void run() { execute(method, usagesToConvert); } }); conflictsDialog.show(); if (conflictsDialog.getExitCode() != DialogWrapper.OK_EXIT_CODE) return; } execute(method, usagesToConvert); }
From source file:org.jetbrains.plugins.groovy.refactoring.introduce.parameter.GrIntroduceParameterDialog.java
License:Apache License
protected void invokeRefactoring(BaseRefactoringProcessor processor) { final Runnable prepareSuccessfulCallback = new Runnable() { public void run() { close(DialogWrapper.OK_EXIT_CODE); }/*from ww w. ja v a 2 s . co m*/ }; processor.setPrepareSuccessfulSwingThreadCallback(prepareSuccessfulCallback); processor.setPreviewUsages(false); processor.run(); }
From source file:org.jetbrains.plugins.ruby.rails.facet.BaseRailsFacetBuilder.java
License:Apache License
private static void generateRailsApplication(final Module module, @NotNull final Sdk sdk, final RunContentDescriptorFactory descriptorFactory, @NotNull final RailsWizardSettingsHolder settings, @NotNull final String applicationHomePath, @Nullable final Runnable onDone) { if (settings.getAppGenerateWay() == RailsWizardSettingsHolder.Generate.NEW) { final String preconfigureForDBName = settings.getDBNameToPreconfigure(); // if directory for rails application home already exists // then try to find Rails Application in it final VirtualFile appHomeDir = VirtualFileUtil.findFileByLocalPath(applicationHomePath); // If rails application already exists ask user overwrite existing files or not? final boolean toOverwrite; if (appHomeDir != null && appHomeDir.isDirectory() && RailsUtil.containsRailsApp(applicationHomePath)) { final int dialogResult = Messages.showYesNoDialog(module.getProject(), RBundle.message("module.rails.generateapp.rails.new.overwrite.message", applicationHomePath), RBundle.message("module.rails.generateapp.rails.new.overwrite.title"), Messages.getQuestionIcon()); toOverwrite = dialogResult == DialogWrapper.OK_EXIT_CODE; } else {//from ww w . ja v a2s .c om toOverwrite = false; } RailsUtil.generateRailsApp(module, sdk, applicationHomePath, toOverwrite, preconfigureForDBName, descriptorFactory, onDone); } }
From source file:org.jetbrains.plugins.ruby.ruby.module.wizard.ui.rspec.RubyRSpecInstallComponentsStep.java
License:Apache License
@Override public boolean validate() throws ConfigurationException { final Sdk sdk = myBuilder.getSdk(); if (!RSpecUtil.checkIfRSpecGemExists(sdk)) { final String msg = RBundle .message("module.settings.dialog.select.test.spec.ruby.please.install.rspec.gem.text"); final String title = RBundle .message("module.settings.dialog.select.test.spec.ruby.please.install.rspec.gem.title"); return Messages.showYesNoDialog(myProject, msg, title, UIUtil.getWarningIcon()) == DialogWrapper.OK_EXIT_CODE; }/* www . j av a 2 s . c o m*/ return true; }