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

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

Introduction

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

Prototype

@YesNoResult
public static int showYesNoDialog(@NotNull Component parent, String message,
        @NotNull @Nls(capitalization = Nls.Capitalization.Title) String title, @Nullable Icon icon) 

Source Link

Usage

From source file:com.intellij.lang.ant.config.explorer.AntExplorer.java

License:Apache License

public void removeBuildFile() {
    final AntBuildFile buildFile = getCurrentBuildFile();
    if (buildFile == null) {
        return;/*from   w w w  . j a v  a 2s. c om*/
    }
    final String fileName = buildFile.getPresentableUrl();
    final int result = Messages.showYesNoDialog(myProject,
            AntBundle.message("remove.the.reference.to.file.confirmation.text", fileName),
            AntBundle.message("confirm.remove.dialog.title"), Messages.getQuestionIcon());
    if (result != 0) {
        return;
    }
    myConfig.removeBuildFile(buildFile);
}

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;/*from   www  .j a  v a  2s.  co m*/
    }

    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.lang.properties.editor.actions.RemovePropertyKeyAction.java

License:Apache License

@Override
public void actionPerformed(AnActionEvent e) {
    final Project project = e.getData(CommonDataKeys.PROJECT);
    final List<StructureViewComponent.StructureViewTreeElementWrapper> treeElements = TreeUtil
            .collectSelectedObjectsOfType(myTreeBuilder.getTree(),
                    StructureViewComponent.StructureViewTreeElementWrapper.class);

    String joinedProperties = StringUtil.join(treeElements,
            new Function<StructureViewComponent.StructureViewTreeElementWrapper, String>() {
                @Override/*from  www.  ja  v  a2 s  . c om*/
                public String fun(StructureViewComponent.StructureViewTreeElementWrapper temp) {
                    return temp.getName();
                }
            }, ", ");

    final int result = Messages.showYesNoDialog(project,
            PropertiesBundle.message("remove.dialog.confirm.description", joinedProperties),
            PropertiesBundle.message("remove.dialog.confirm.title"), AllIcons.General.QuestionDialog);
    if (result != Messages.OK) {
        return;
    }

    new WriteCommandAction<Object>(project) {
        @Override
        protected void run(Result<Object> result) throws Throwable {
            final List<PropertiesFile> propertiesFiles = myBundle.getPropertiesFiles(project);
            for (PropertiesFile propertiesFile : propertiesFiles) {
                for (StructureViewComponent.StructureViewTreeElementWrapper treeElement : treeElements) {
                    propertiesFile.removeProperties(treeElement.getName());
                }
            }
            myTreeBuilder.queueUpdate();
        }
    }.execute();
}

From source file:com.intellij.platform.NewDirectoryProjectAction.java

License:Apache License

@Nullable
protected Project generateProject(Project project, @NotNull final NewProjectOrModuleDialog dialog) {
    final File location = new File(dialog.getLocationText());
    final int childCount = location.exists() ? location.list().length : 0;
    if (!location.exists() && !location.mkdirs()) {
        Messages.showErrorDialog(project, "Cannot create directory '" + location + "'", "Create Project");
        return null;
    }//from w ww. j  a v  a  2  s .c om

    final VirtualFile baseDir = ApplicationManager.getApplication()
            .runWriteAction(new Computable<VirtualFile>() {
                @Override
                public VirtualFile compute() {
                    return LocalFileSystem.getInstance().refreshAndFindFileByIoFile(location);
                }
            });
    baseDir.refresh(false, true);

    if (childCount > 0) {
        int rc = Messages.showYesNoDialog(project, "The directory '" + location + "' is not empty. Continue?",
                "Create New Project", Messages.getQuestionIcon());
        if (rc == Messages.NO) {
            return null;
        }
    }

    GeneralSettings.getInstance().setLastProjectCreationLocation(location.getParent());
    return PlatformProjectOpenProcessor.doOpenProject(baseDir, null, false, -1, new Consumer<Project>() {
        @Override
        public void consume(final Project project) {
            dialog.doCreate(project, baseDir);
        }
    });
}

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/* ww  w.  j  av  a 2  s . co  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  w ww .j  av a 2 s .  co m*/
        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.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.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  w  w  w .  j  av  a2s  . 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.introduceField.IntroduceConstantDialog.java

License:Apache License

protected void doOKAction() {
    final String targetClassName = getTargetClassName();
    PsiClass newClass = myParentClass;/*ww  w .j a v a2 s  .co  m*/

    if (!"".equals(targetClassName) && !Comparing.strEqual(targetClassName, myParentClass.getQualifiedName())) {
        newClass = JavaPsiFacade.getInstance(myProject).findClass(targetClassName,
                GlobalSearchScope.projectScope(myProject));
        if (newClass == null) {
            if (Messages.showOkCancelDialog(myProject,
                    RefactoringBundle.message("class.does.not.exist.in.the.project"),
                    IntroduceConstantHandler.REFACTORING_NAME, Messages.getErrorIcon()) != OK_EXIT_CODE) {
                return;
            }
            myDestinationClass = new BaseExpressionToFieldHandler.TargetDestination(targetClassName,
                    myParentClass);
        } else {
            myDestinationClass = new BaseExpressionToFieldHandler.TargetDestination(newClass);
        }
    }

    String fieldName = getEnteredName();
    String errorString = null;
    if ("".equals(fieldName)) {
        errorString = RefactoringBundle.message("no.field.name.specified");
    } else if (!PsiNameHelper.getInstance(myProject).isIdentifier(fieldName)) {
        errorString = RefactoringMessageUtil.getIncorrectIdentifierMessage(fieldName);
    } else if (newClass != null && !myParentClass.getLanguage().equals(newClass.getLanguage())) {
        errorString = RefactoringBundle.message("move.to.different.language",
                UsageViewUtil.getType(myParentClass), myParentClass.getQualifiedName(),
                newClass.getQualifiedName());
    }
    if (errorString != null) {
        CommonRefactoringUtil.showErrorMessage(IntroduceFieldHandler.REFACTORING_NAME, errorString,
                HelpID.INTRODUCE_FIELD, myProject);
        return;
    }
    if (newClass != null) {
        PsiField oldField = newClass.findFieldByName(fieldName, true);

        if (oldField != null) {
            int answer = Messages.showYesNoDialog(myProject,
                    RefactoringBundle.message("field.exists", fieldName,
                            oldField.getContainingClass().getQualifiedName()),
                    IntroduceFieldHandler.REFACTORING_NAME, Messages.getWarningIcon());
            if (answer != 0) {
                return;
            }
        }
    }

    JavaRefactoringSettings.getInstance().INTRODUCE_CONSTANT_VISIBILITY = getFieldVisibility();

    RecentsManager.getInstance(myProject).registerRecentEntry(RECENTS_KEY, targetClassName);
    super.doOKAction();
}

From source file:com.intellij.refactoring.introduceField.IntroduceFieldDialog.java

License:Apache License

protected void doOKAction() {
    String fieldName = getEnteredName();
    String errorString = null;//w w  w  .j  av  a 2 s.  co  m
    if ("".equals(fieldName)) {
        errorString = RefactoringBundle.message("no.field.name.specified");
    } else if (!PsiNameHelper.getInstance(myProject).isIdentifier(fieldName)) {
        errorString = RefactoringMessageUtil.getIncorrectIdentifierMessage(fieldName);
    }
    if (errorString != null) {
        CommonRefactoringUtil.showErrorMessage(IntroduceFieldHandler.REFACTORING_NAME, errorString,
                HelpID.INTRODUCE_FIELD, myProject);
        return;
    }

    PsiField oldField = myParentClass.findFieldByName(fieldName, true);

    if (oldField != null) {
        int answer = Messages.showYesNoDialog(myProject,
                RefactoringBundle.message("field.exists", fieldName,
                        oldField.getContainingClass().getQualifiedName()),
                IntroduceFieldHandler.REFACTORING_NAME, Messages.getWarningIcon());
        if (answer != 0) {
            return;
        }
    }

    myCentralPanel.saveFinalState();
    ourLastInitializerPlace = myCentralPanel.getInitializerPlace();
    JavaRefactoringSettings.getInstance().INTRODUCE_FIELD_VISIBILITY = getFieldVisibility();

    myNameSuggestionsManager.nameSelected();
    myTypeSelectorManager.typeSelected(getFieldType());
    super.doOKAction();
}