List of usage examples for com.intellij.openapi.ui Messages YES
int YES
To view the source code for com.intellij.openapi.ui Messages YES.
Click Source Link
From source file:com.intellij.javascript.flex.refactoring.moveMembers.ActionScriptMoveMembersDialog.java
License:Apache License
@Nullable private JSClass findOrCreateTargetClass(final String fqName) { final String className = StringUtil.getShortName(fqName); final String packageName = StringUtil.getPackageName(fqName); final GlobalSearchScope scope = getScope(); final JSClassResolver resolver = JSDialectSpecificHandlersFactory .forLanguage(JavaScriptSupportLoader.ECMA_SCRIPT_L4).getClassResolver(); PsiElement aClass = resolver.findClassByQName(fqName, scope); if (aClass instanceof JSClass) return (JSClass) aClass; if (aClass != null) { Messages.showErrorDialog(myProject, JSBundle.message("class.0.cannot.be.created", fqName), StringUtil.capitalizeWords(JSBundle.message("move.members.refactoring.name"), true)); return null; }// ww w . java 2s. c o m int answer = Messages.showYesNoDialog(myProject, RefactoringBundle.message("class.0.does.not.exist", fqName), StringUtil.capitalizeWords(JSBundle.message("move.members.refactoring.name"), true), Messages.getQuestionIcon()); if (answer != Messages.YES) return null; Module module = ModuleUtilCore.findModuleForPsiElement(mySourceClass); PsiDirectory baseDir = PlatformPackageUtil.getDirectory(mySourceClass); final PsiDirectory targetDirectory = JSRefactoringUtil.chooseOrCreateDirectoryForClass(myProject, module, scope, packageName, className, baseDir, ThreeState.UNSURE); if (targetDirectory == null) { return null; } final Ref<Exception> error = new Ref<>(); final Ref<JSClass> newClass = new Ref<>(); WriteCommandAction.runWriteCommandAction(myProject, RefactoringBundle.message("create.class.command", fqName), null, () -> { try { ActionScriptCreateClassOrInterfaceFix.createClass(className, packageName, targetDirectory, false); newClass.set((JSClass) resolver.findClassByQName(fqName, scope)); } catch (Exception e) { error.set(e); } }); if (!error.isNull()) { CommonRefactoringUtil.showErrorMessage(JSBundle.message("move.members.refactoring.name"), error.get().getMessage(), null, myProject); return null; } return newClass.get(); }
From source file:com.intellij.lang.javascript.uml.FlashUmlDataModel.java
License:Apache License
@Override public void removeEdge(DiagramEdge<Object> edge) { final Object source = edge.getSource().getIdentifyingElement(); final Object target = edge.getTarget().getIdentifyingElement(); final DiagramRelationshipInfo relationship = edge.getRelationship(); if (!(source instanceof JSClass) || !(target instanceof JSClass) || relationship == DiagramRelationshipInfo.NO_RELATIONSHIP) { return;/* ww w. j a v a2 s . c om*/ } final JSClass fromClass = (JSClass) source; final JSClass toClass = (JSClass) target; if (JSProjectUtil.isInLibrary(fromClass)) { return; } if (fromClass instanceof XmlBackedJSClassImpl && !toClass.isInterface()) { Messages.showErrorDialog(fromClass.getProject(), FlexBundle.message("base.component.needed.message"), FlexBundle.message("remove.edge.title")); return; } if (Messages.showYesNoDialog(fromClass.getProject(), FlexBundle.message("remove.inheritance.link.prompt", fromClass.getQualifiedName(), toClass.getQualifiedName()), FlexBundle.message("remove.edge.title"), Messages.getQuestionIcon()) != Messages.YES) { return; } final Runnable runnable = () -> { JSReferenceList refList = !fromClass.isInterface() && toClass.isInterface() ? fromClass.getImplementsList() : fromClass.getExtendsList(); List<FormatFixer> formatters = new ArrayList<>(); JSRefactoringUtil.removeFromReferenceList(refList, toClass, formatters); if (!(fromClass instanceof XmlBackedJSClassImpl) && needsImport(fromClass, toClass)) { formatters.addAll(ECMAScriptImportOptimizer.executeNoFormat(fromClass.getContainingFile())); } FormatFixer.fixAll(formatters); }; DiagramAction.performCommand(getBuilder(), runnable, FlexBundle.message("remove.relationship.command.name"), null, fromClass.getContainingFile()); }
From source file:com.intellij.plugins.haxe.ide.refactoring.memberPushDown.PushDownProcessor.java
License:Apache License
@Override 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 .ja v a2s . 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()) != Messages.OK) { 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 == Messages.YES) { myCreateClassDlg = CreateSubclassAction.chooseSubclassToCreate(myClass); if (myCreateClassDlg != null) { pushDownConflicts.checkTargetClassConflicts(null, false, myCreateClassDlg.getTargetDirectory()); return showConflicts(pushDownConflicts.getConflicts(), usagesIn); } else { return false; } } else if (answer != Messages.NO) return false; } } Runnable runnable = new Runnable() { @Override public void run() { ApplicationManager.getApplication().runReadAction(new Runnable() { @Override 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; } for (UsageInfo info : usagesIn) { final PsiElement element = info.getElement(); if (element instanceof PsiFunctionalExpression) { pushDownConflicts.getConflicts().putValue(element, RefactoringBundle.message("functional.interface.broken")); } } final PsiAnnotation annotation = AnnotationUtil.findAnnotation(myClass, CommonClassNames.JAVA_LANG_FUNCTIONAL_INTERFACE); if (annotation != null && isMoved(LambdaUtil.getFunctionalInterfaceMethod(myClass))) { pushDownConflicts.getConflicts().putValue(annotation, RefactoringBundle.message("functional.interface.broken")); } return showConflicts(pushDownConflicts.getConflicts(), usagesIn); }
From source file:com.intellij.profile.codeInspection.ui.header.InspectionToolsConfigurable.java
License:Apache License
public InspectionToolsConfigurable(@NotNull final InspectionProjectProfileManager projectProfileManager, InspectionProfileManager profileManager) { myWholePanel = new JPanel(new BorderLayout()); final JPanel toolbar = new JPanel(new GridBagLayout()); toolbar.setBorder(BorderFactory.createEmptyBorder(0, 0, 7, 0)); myPanel = new JPanel(); myWholePanel.add(toolbar, BorderLayout.PAGE_START); myWholePanel.add(myPanel, BorderLayout.CENTER); myProfiles = new ProfilesConfigurableComboBox(new ListCellRendererWrapper<Profile>() { @Override//from w w w . j av a 2 s . c o m public void customize(final JList list, final Profile value, final int index, final boolean selected, final boolean hasFocus) { final SingleInspectionProfilePanel singleInspectionProfilePanel = myPanels.get(value); final boolean isShared = singleInspectionProfilePanel.isProfileShared(); setIcon(isShared ? AllIcons.General.ProjectSettings : AllIcons.General.Settings); setText(singleInspectionProfilePanel.getCurrentProfileName()); } }) { @Override public void onProfileChosen(InspectionProfileImpl inspectionProfile) { myLayout.show(myPanel, getCardName(inspectionProfile)); myAuxiliaryRightPanel.showDescription(inspectionProfile.getDescription()); } }; JPanel profilesHolder = new JPanel(); profilesHolder.setLayout(new CardLayout()); JComponent manageButton = new ManageButton(new ManageButtonBuilder() { @Override public boolean isSharedToTeamMembers() { SingleInspectionProfilePanel panel = getSelectedPanel(); return panel != null && panel.isProfileShared(); } @Override public void setShareToTeamMembers(boolean shared) { final SingleInspectionProfilePanel selectedPanel = getSelectedPanel(); LOG.assertTrue(selectedPanel != null, "No settings selectedPanel for: " + getSelectedObject()); final String name = getSelectedPanel().getCurrentProfileName(); for (SingleInspectionProfilePanel p : myPanels.values()) { if (p != selectedPanel && Comparing.equal(p.getCurrentProfileName(), name)) { final boolean curShared = p.isProfileShared(); if (curShared == shared) { Messages.showErrorDialog( (shared ? "Shared" : "Application level") + " profile with same name exists.", "Inspections Settings"); return; } } } selectedPanel.setProfileShared(shared); myProfiles.repaint(); } @Override public void copy() { final InspectionProfileImpl newProfile = copyToNewProfile(getSelectedObject(), getProject()); if (newProfile != null) { final InspectionProfileImpl modifiableModel = (InspectionProfileImpl) newProfile .getModifiableModel(); modifiableModel.setModified(true); modifiableModel.setProjectLevel(false); addProfile(modifiableModel); rename(modifiableModel); } } @Override public boolean canRename() { final InspectionProfileImpl profile = getSelectedObject(); return !profile.isProfileLocked(); } @Override public void rename() { rename(getSelectedObject()); } private void rename(@NotNull final InspectionProfileImpl inspectionProfile) { final String initialName = getSelectedPanel().getCurrentProfileName(); myProfiles.showEditCard(initialName, new SaveInputComponentValidator() { @Override public void doSave(@NotNull String text) { if (!text.equals(initialName)) { getProfilePanel(inspectionProfile).setCurrentProfileName(text); } myProfiles.showComboBoxCard(); } @Override public boolean checkValid(@NotNull String text) { final SingleInspectionProfilePanel singleInspectionProfilePanel = myPanels .get(inspectionProfile); if (singleInspectionProfilePanel == null) { return false; } final boolean isValid = text.equals(initialName) || !hasName(text, singleInspectionProfilePanel.isProfileShared()); if (isValid) { myAuxiliaryRightPanel.showDescription(getSelectedObject().getDescription()); } else { myAuxiliaryRightPanel .showError("Name is already in use. Please change name to unique."); } return isValid; } @Override public void cancel() { myProfiles.showComboBoxCard(); myAuxiliaryRightPanel.showDescription(getSelectedObject().getDescription()); } }); } @Override public boolean canDelete() { return isDeleteEnabled(myProfiles.getSelectedProfile()); } @Override public void delete() { final InspectionProfileImpl selectedProfile = myProfiles.getSelectedProfile(); myProfiles.getModel().removeElement(selectedProfile); myDeletedProfiles.add(selectedProfile); } @Override public boolean canEditDescription() { return true; } @Override public void editDescription() { myAuxiliaryRightPanel.editDescription(getSelectedObject().getDescription()); } @Override public boolean hasDescription() { return !StringUtil.isEmpty(getSelectedObject().getDescription()); } @Override public void export() { final FileChooserDescriptor descriptor = FileChooserDescriptorFactory .createSingleFolderDescriptor(); descriptor.setDescription("Choose directory to store profile file"); FileChooser.chooseFile(descriptor, getProject(), myWholePanel, null, new Consumer<VirtualFile>() { @Override public void consume(VirtualFile file) { final Element element = new Element("inspections"); try { final SingleInspectionProfilePanel panel = getSelectedPanel(); LOG.assertTrue(panel != null); final InspectionProfileImpl profile = getSelectedObject(); LOG.assertTrue(true); profile.writeExternal(element); final String filePath = FileUtil.toSystemDependentName(file.getPath()) + File.separator + FileUtil.sanitizeFileName(profile.getName()) + ".xml"; if (new File(filePath).isFile()) { if (Messages.showOkCancelDialog(myWholePanel, "File \'" + filePath + "\' already exist. Do you want to overwrite it?", "Warning", Messages.getQuestionIcon()) != Messages.OK) { return; } } JDOMUtil.writeDocument(new Document(element), filePath, SystemProperties.getLineSeparator()); } catch (WriteExternalException e1) { LOG.error(e1); } catch (IOException e1) { LOG.error(e1); } } }); } @Override public void doImport() { final FileChooserDescriptor descriptor = new FileChooserDescriptor(true, false, false, false, false, false) { @Override public boolean isFileSelectable(VirtualFile file) { return file.getFileType().equals(InternalStdFileTypes.XML); } }; descriptor.setDescription("Choose profile file"); FileChooser.chooseFile(descriptor, getProject(), myWholePanel, null, new Consumer<VirtualFile>() { @Override public void consume(VirtualFile file) { if (file == null) return; InspectionProfileImpl profile = new InspectionProfileImpl("TempProfile", InspectionToolRegistrar.getInstance(), myProfileManager); try { Element rootElement = JDOMUtil.loadDocument(VfsUtilCore.virtualToIoFile(file)) .getRootElement(); if (Comparing.strEqual(rootElement.getName(), "component")) {//import right from .idea/inspectProfiles/xxx.xml rootElement = rootElement.getChildren().get(0); } final Set<String> levels = new HashSet<String>(); for (Object o : rootElement.getChildren("inspection_tool")) { final Element inspectElement = (Element) o; levels.add(inspectElement.getAttributeValue("level")); for (Object s : inspectElement.getChildren("scope")) { levels.add(((Element) s).getAttributeValue("level")); } } for (Iterator<String> iterator = levels.iterator(); iterator.hasNext();) { String level = iterator.next(); if (myProfileManager.getOwnSeverityRegistrar().getSeverity(level) != null) { iterator.remove(); } } if (!levels.isEmpty()) { if (Messages.showYesNoDialog(myWholePanel, "Undefined severities detected: " + StringUtil.join(levels, ", ") + ". Do you want to create them?", "Warning", Messages.getWarningIcon()) == Messages.YES) { for (String level : levels) { final TextAttributes textAttributes = CodeInsightColors.WARNINGS_ATTRIBUTES .getDefaultAttributes(); HighlightInfoType.HighlightInfoTypeImpl info = new HighlightInfoType.HighlightInfoTypeImpl( new HighlightSeverity(level, 50), TextAttributesKey.createTextAttributesKey(level)); myProfileManager.getOwnSeverityRegistrar().registerSeverity( new SeverityRegistrar.SeverityBasedTextAttributes( textAttributes.clone(), info), textAttributes.getErrorStripeColor()); } } } profile.readExternal(rootElement); profile.setProjectLevel(false); profile.initInspectionTools(getProject()); if (getProfilePanel(profile) != null) { if (Messages.showOkCancelDialog(myWholePanel, "Profile with name \'" + profile.getName() + "\' already exists. Do you want to overwrite it?", "Warning", Messages.getInformationIcon()) != Messages.OK) { return; } } final ModifiableModel model = profile.getModifiableModel(); model.setModified(true); addProfile((InspectionProfileImpl) model); //TODO myDeletedProfiles ? really need this myDeletedProfiles.remove(profile); } catch (InvalidDataException e1) { LOG.error(e1); } catch (JDOMException e1) { LOG.error(e1); } catch (IOException e1) { LOG.error(e1); } } }); } }).build(); myAuxiliaryRightPanel = new AuxiliaryRightPanel(new AuxiliaryRightPanel.DescriptionSaveListener() { @Override public void saveDescription(@NotNull String description) { final InspectionProfileImpl inspectionProfile = getSelectedObject(); if (!Comparing.strEqual(description, inspectionProfile.getDescription())) { inspectionProfile.setDescription(description); inspectionProfile.setModified(true); } myAuxiliaryRightPanel.showDescription(description); } @Override public void cancel() { myAuxiliaryRightPanel.showDescription(getSelectedObject().getDescription()); } }); toolbar.add(new JLabel(HEADER_TITLE), new GridBagConstraints(0, 1, 1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.VERTICAL, new Insets(0, 0, 0, 0), 0, 0)); toolbar.add(myProfiles.getHintLabel(), new GridBagConstraints(1, 0, 1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.VERTICAL, new Insets(0, 6, 6, 0), 0, 0)); toolbar.add(myProfiles, new GridBagConstraints(1, 1, 1, 1, 0, 1.0, GridBagConstraints.WEST, GridBagConstraints.VERTICAL, new Insets(0, 6, 0, 0), 0, 0)); toolbar.add(manageButton, new GridBagConstraints(2, 1, 1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.VERTICAL, new Insets(0, 10, 0, 0), 0, 0)); toolbar.add(myAuxiliaryRightPanel.getHintLabel(), new GridBagConstraints(3, 0, 1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.VERTICAL, new Insets(0, 15, 6, 0), 0, 0)); toolbar.add(myAuxiliaryRightPanel, new GridBagConstraints(3, 1, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 15, 0, 0), 0, 0)); ((InspectionManagerEx) InspectionManager.getInstance(projectProfileManager.getProject())) .buildInspectionSearchIndexIfNecessary(); myProjectProfileManager = projectProfileManager; myProfileManager = profileManager; }
From source file:com.intellij.profile.codeInspection.ui.InspectionToolsConfigurable.java
License:Apache License
public InspectionToolsConfigurable(@NotNull final InspectionProjectProfileManager projectProfileManager, InspectionProfileManager profileManager) { ((InspectionManagerEx) InspectionManager.getInstance(projectProfileManager.getProject())) .buildInspectionSearchIndexIfNecessary(); myAddButton.addActionListener(new ActionListener() { @Override//from ww w . j av a2 s . com public void actionPerformed(ActionEvent e) { final Set<String> existingProfileNames = myPanels.keySet(); final ModifiableModel model = SingleInspectionProfilePanel.createNewProfile(-1, getSelectedObject(), myWholePanel, "", existingProfileNames, projectProfileManager.getProject()); if (model != null) { addProfile((InspectionProfileImpl) model); myDeletedProfiles.remove(getProfilePrefix(model) + model.getName()); myDeleteButton.setEnabled(true); } } }); myDeleteButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { final InspectionProfileImpl selectedProfile = (InspectionProfileImpl) myProfiles.getSelectedItem(); ((DefaultComboBoxModel) myProfiles.getModel()).removeElement(selectedProfile); myDeletedProfiles.add(getProfilePrefix(selectedProfile) + selectedProfile.getName()); myDeleteButton.setEnabled(isDeleteEnabled(selectedProfile)); } }); final Project project = projectProfileManager.getProject(); myImportButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { final FileChooserDescriptor descriptor = new FileChooserDescriptor(true, false, false, false, false, false) { @Override public boolean isFileSelectable(VirtualFile file) { return file.getFileType().equals(StdFileTypes.XML); } }; descriptor.setDescription("Choose profile file"); FileChooser.chooseFile(descriptor, project, myWholePanel, null, new Consumer<VirtualFile>() { @Override public void consume(VirtualFile file) { if (file == null) return; InspectionProfileImpl profile = new InspectionProfileImpl("TempProfile", InspectionToolRegistrar.getInstance(), myProfileManager); try { Element rootElement = JDOMUtil.loadDocument(VfsUtilCore.virtualToIoFile(file)) .getRootElement(); if (Comparing.strEqual(rootElement.getName(), "component")) {//import right from .idea/inspectProfiles/xxx.xml rootElement = rootElement.getChildren().get(0); } final Set<String> levels = new HashSet<String>(); for (Object o : rootElement.getChildren("inspection_tool")) { final Element inspectElement = (Element) o; levels.add(inspectElement.getAttributeValue("level")); for (Object s : inspectElement.getChildren("scope")) { levels.add(((Element) s).getAttributeValue("level")); } } for (Iterator<String> iterator = levels.iterator(); iterator.hasNext();) { String level = iterator.next(); if (myProfileManager.getOwnSeverityRegistrar().getSeverity(level) != null) { iterator.remove(); } } if (!levels.isEmpty()) { if (Messages.showYesNoDialog(myWholePanel, "Undefined severities detected: " + StringUtil.join(levels, ", ") + ". Do you want to create them?", "Warning", Messages.getWarningIcon()) == Messages.YES) { for (String level : levels) { final TextAttributes textAttributes = CodeInsightColors.WARNINGS_ATTRIBUTES .getDefaultAttributes(); HighlightInfoType.HighlightInfoTypeImpl info = new HighlightInfoType.HighlightInfoTypeImpl( new HighlightSeverity(level, 50), com.intellij.openapi.editor.colors.TextAttributesKey .createTextAttributesKey(level)); myProfileManager.getOwnSeverityRegistrar().registerSeverity( new SeverityRegistrar.SeverityBasedTextAttributes( textAttributes.clone(), info), textAttributes.getErrorStripeColor()); } } } profile.readExternal(rootElement); profile.setLocal(true); profile.initInspectionTools(project); if (getProfilePanel(profile) != null) { if (Messages.showOkCancelDialog(myWholePanel, "Profile with name \'" + profile.getName() + "\' already exists. Do you want to overwrite it?", "Warning", Messages.getInformationIcon()) != Messages.OK) return; } final ModifiableModel model = profile.getModifiableModel(); model.setModified(true); addProfile((InspectionProfileImpl) model); myDeletedProfiles.remove(getProfilePrefix(profile) + profile.getName()); myDeleteButton.setEnabled(true); } catch (InvalidDataException e1) { LOG.error(e1); } catch (JDOMException e1) { LOG.error(e1); } catch (IOException e1) { LOG.error(e1); } } }); } }); myExportButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { final FileChooserDescriptor descriptor = FileChooserDescriptorFactory .createSingleFolderDescriptor(); descriptor.setDescription("Choose directory to store profile file"); FileChooser.chooseFile(descriptor, project, myWholePanel, null, new Consumer<VirtualFile>() { @Override public void consume(VirtualFile file) { final Element element = new Element("inspections"); try { final SingleInspectionProfilePanel panel = getSelectedPanel(); LOG.assertTrue(panel != null); final InspectionProfileImpl profile = (InspectionProfileImpl) panel .getSelectedProfile(); profile.writeExternal(element); final String filePath = FileUtil.toSystemDependentName(file.getPath()) + File.separator + FileUtil.sanitizeFileName(profile.getName()) + ".xml"; if (new File(filePath).isFile()) { if (Messages.showOkCancelDialog(myWholePanel, "File \'" + filePath + "\' already exist. Do you want to overwrite it?", "Warning", Messages.getQuestionIcon()) != Messages.OK) return; } JDOMUtil.writeDocument(new Document(element), filePath, SystemProperties.getLineSeparator()); } catch (WriteExternalException e1) { LOG.error(e1); } catch (IOException e1) { LOG.error(e1); } } }); } }); myCopyButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { final Set<String> existingProfileNames = myPanels.keySet(); final InspectionProfileImpl model = (InspectionProfileImpl) SingleInspectionProfilePanel .createNewProfile(0, getSelectedObject(), myWholePanel, "", existingProfileNames, project); if (model != null) { final InspectionProfileImpl modifiableModel = (InspectionProfileImpl) model .getModifiableModel(); modifiableModel.setModified(true); addProfile(modifiableModel); myDeletedProfiles.remove(getProfilePrefix(model) + model.getName()); myDeleteButton.setEnabled(true); } } }); myProjectProfileManager = projectProfileManager; myProfileManager = profileManager; myJBScrollPane.setBorder(null); }
From source file:com.intellij.refactoring.extractMethod.ExtractMethodHelper.java
License:Apache License
private static void replaceDuplicates(PsiElement callElement, Editor editor, Consumer<Pair<SimpleMatch, PsiElement>> replacer, List<SimpleMatch> duplicates) { if (duplicates.size() > 0) { final String message = RefactoringBundle.message( "0.has.detected.1.code.fragments.in.this.file.that.can.be.replaced.with.a.call.to.extracted.method", ApplicationNamesInfo.getInstance().getProductName(), duplicates.size()); final boolean isUnittest = ApplicationManager.getApplication().isUnitTestMode(); final Project project = callElement.getProject(); final int exitCode = !isUnittest ? Messages.showYesNoDialog(project, message, RefactoringBundle.message("refactoring.extract.method.dialog.title"), Messages.getInformationIcon()) : Messages.YES; if (exitCode == Messages.YES) { boolean replaceAll = false; final Map<SimpleMatch, RangeHighlighter> highlighterMap = new HashMap<SimpleMatch, RangeHighlighter>(); for (SimpleMatch match : duplicates) { final Pair<SimpleMatch, PsiElement> replacement = Pair.create(match, callElement); if (!replaceAll) { highlightInEditor(project, match, editor, highlighterMap); int promptResult = FindManager.PromptResult.ALL; //noinspection ConstantConditions if (!isUnittest) { ReplacePromptDialog promptDialog = new ReplacePromptDialog(false, RefactoringBundle.message("replace.fragment"), project); promptDialog.show(); promptResult = promptDialog.getExitCode(); }//from www .j a v a 2s .co m if (promptResult == FindManager.PromptResult.SKIP) { final HighlightManager highlightManager = HighlightManager.getInstance(project); final RangeHighlighter highlighter = highlighterMap.get(match); if (highlighter != null) highlightManager.removeSegmentHighlighter(editor, highlighter); continue; } if (promptResult == FindManager.PromptResult.CANCEL) break; if (promptResult == FindManager.PromptResult.OK) { replaceDuplicate(project, replacer, replacement); } else if (promptResult == FindManager.PromptResult.ALL) { replaceDuplicate(project, replacer, replacement); replaceAll = true; } } else { replaceDuplicate(project, replacer, replacement); } } } } }
From source file:com.intellij.refactoring.lang.ExtractIncludeFileBase.java
License:Apache License
private void replaceDuplicates(final String includePath, final List<IncludeDuplicate<T>> duplicates, final Editor editor, final Project project) { if (duplicates.size() > 0) { final String message = RefactoringBundle.message( "idea.has.found.fragments.that.can.be.replaced.with.include.directive", ApplicationNamesInfo.getInstance().getProductName()); final int exitCode = Messages.showYesNoDialog(project, message, getRefactoringName(), Messages.getInformationIcon()); if (exitCode == Messages.YES) { CommandProcessor.getInstance().executeCommand(project, new Runnable() { @Override//from www . jav a2s. c om public void run() { boolean replaceAll = false; for (IncludeDuplicate<T> pair : duplicates) { if (!replaceAll) { highlightInEditor(project, pair, editor); ReplacePromptDialog promptDialog = new ReplacePromptDialog(false, RefactoringBundle.message("replace.fragment"), project); promptDialog.show(); final int promptResult = promptDialog.getExitCode(); if (promptResult == FindManager.PromptResult.SKIP) continue; if (promptResult == FindManager.PromptResult.CANCEL) break; if (promptResult == FindManager.PromptResult.OK) { doReplaceRange(includePath, pair.getStart(), pair.getEnd()); } else if (promptResult == FindManager.PromptResult.ALL) { doReplaceRange(includePath, pair.getStart(), pair.getEnd()); replaceAll = true; } else { LOG.error("Unknown return status"); } } else { doReplaceRange(includePath, pair.getStart(), pair.getEnd()); } } } }, RefactoringBundle.message("remove.duplicates.command"), null); } } }
From source file:com.intellij.refactoring.rename.PsiElementRenameHandler.java
License:Apache License
public static void invoke(PsiElement element, Project project, PsiElement nameSuggestionContext, Editor editor) {/*from w w w . j av a 2 s . c o m*/ if (element != null && !canRename(project, editor, element)) { return; } if (nameSuggestionContext != null && !PsiManager.getInstance(project).isInProject(nameSuggestionContext)) { final String message = "Selected element is used from non-project files. These usages won't be renamed. Proceed anyway?"; if (ApplicationManager.getApplication().isUnitTestMode()) throw new CommonRefactoringUtil.RefactoringErrorHintException(message); if (Messages.showYesNoDialog(project, message, RefactoringBundle.getCannotRefactorMessage(null), Messages.getWarningIcon()) != Messages.YES) { return; } } FeatureUsageTracker.getInstance().triggerFeatureUsed("refactoring.rename"); rename(element, project, nameSuggestionContext, editor); }
From source file:com.intellij.struts2.facet.ui.FileSetConfigurationTab.java
License:Apache License
private void remove() { final SimpleNode[] nodes = myTree.getSelectedNodesIfUniform(); for (final SimpleNode node : nodes) { if (node instanceof FileSetNode) { final StrutsFileSet fileSet = ((FileSetNode) node).mySet; if (fileSet.getFiles().isEmpty()) { myBuffer.remove(fileSet); return; }//from w ww . j ava 2s .c om final int result = Messages.showYesNoDialog(myPanel, StrutsBundle.message("facet.fileset.remove.fileset.question", fileSet.getName()), StrutsBundle.message("facet.fileset.remove.fileset.title"), Messages.getQuestionIcon()); if (result == Messages.YES) { if (fileSet.isAutodetected()) { fileSet.setRemoved(true); myBuffer.add(fileSet); } else { myBuffer.remove(fileSet); } } } else if (node instanceof ConfigFileNode) { final VirtualFilePointer filePointer = ((ConfigFileNode) node).myFilePointer; final StrutsFileSet fileSet = ((FileSetNode) node.getParent()).mySet; fileSet.removeFile(filePointer); } } }
From source file:com.intellij.ui.mac.MacMessagesImpl.java
License:Apache License
@Override @Messages.YesNoResult/* w w w.ja v a2s .c o m*/ public int showYesNoDialog(@NotNull String title, String message, @NotNull String yesButton, @NotNull String noButton, @Nullable Window window) { return showAlertDialog(title, yesButton, null, noButton, message, window) == Messages.YES ? Messages.YES : Messages.NO; }