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

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

Introduction

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

Prototype

int OK

To view the source code for com.intellij.openapi.ui Messages OK.

Click Source Link

Usage

From source file:com.intellij.ide.util.projectWizard.ProjectNameStep.java

License:Apache License

public boolean validate() throws ConfigurationException {
    String name = myNamePathComponent.getNameValue();
    if (name.length() == 0) {
        final ApplicationInfo info = ApplicationManager.getApplication().getComponent(ApplicationInfo.class);
        throw new ConfigurationException(IdeBundle.message("prompt.new.project.file.name",
                info.getVersionName(), myWizardContext.getPresentationName()));
    }// w ww. j a va  2 s  . com

    final String projectFileDirectory = getProjectFileDirectory();
    if (projectFileDirectory.length() == 0) {
        throw new ConfigurationException(
                IdeBundle.message("prompt.enter.project.file.location", myWizardContext.getPresentationName()));
    }

    final boolean shouldPromptCreation = myNamePathComponent.isPathChangedByUser();
    if (!ProjectWizardUtil.createDirectoryIfNotExists(
            IdeBundle.message("directory.project.file.directory", myWizardContext.getPresentationName()),
            projectFileDirectory, shouldPromptCreation)) {
        return false;
    }

    boolean shouldContinue = true;

    final String path = getProjectFileDirectory() + "/" + Project.DIRECTORY_STORE_FOLDER;
    final File projectFile = new File(path);
    if (projectFile.exists()) {
        final String title = myWizardContext.isCreatingNewProject() ? IdeBundle.message("title.new.project")
                : IdeBundle.message("title.add.module");
        final String message = IdeBundle.message("prompt.overwrite.project.folder",
                Project.DIRECTORY_STORE_FOLDER, projectFile.getParentFile().getAbsolutePath());
        int answer = Messages.showYesNoDialog(message, title, Messages.getQuestionIcon());
        shouldContinue = answer == Messages.OK;
    }

    return shouldContinue;
}

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  va 2 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.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  ww.  jav a  2s.co  m*/
                            ? "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 a v 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  w w  w.  j a v a  2 s. c  o  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.projectImport.ProjectOpenProcessorBase.java

License:Apache License

@Override
@Nullable//w  w w  . j  ava  2s.  c o  m
public Project doOpenProject(@NotNull VirtualFile virtualFile, Project projectToClose,
        boolean forceOpenInNewFrame) {
    try {
        getBuilder().setUpdate(false);
        final WizardContext wizardContext = new WizardContext(null);
        if (virtualFile.isDirectory()) {
            final String[] supported = getSupportedExtensions();
            for (VirtualFile file : getFileChildren(virtualFile)) {
                if (canOpenFile(file, supported)) {
                    virtualFile = file;
                    break;
                }
            }
        }

        wizardContext.setProjectFileDirectory(virtualFile.getParent().getPath());

        if (!doQuickImport(virtualFile, wizardContext))
            return null;

        if (wizardContext.getProjectName() == null) {
            wizardContext.setProjectName(IdeBundle.message("project.import.default.name.dotIdea", getName()));
        }

        final String dotIdeaFilePath = wizardContext.getProjectFileDirectory() + File.separator
                + Project.DIRECTORY_STORE_FOLDER;

        File dotIdeaFile = new File(dotIdeaFilePath);

        String pathToOpen = dotIdeaFile.getParent();

        boolean shouldOpenExisting = false;
        if (!ApplicationManager.getApplication().isHeadlessEnvironment() && dotIdeaFile.exists()) {
            String existingName = "an existing project";

            int result = Messages.showYesNoCancelDialog(projectToClose,
                    IdeBundle.message("project.import.open.existing", existingName, pathToOpen,
                            virtualFile.getName()),
                    IdeBundle.message("title.open.project"),
                    IdeBundle.message("project.import.open.existing.openExisting"),
                    IdeBundle.message("project.import.open.existing.reimport"),
                    CommonBundle.message("button.cancel"), Messages.getQuestionIcon());
            if (result == Messages.CANCEL)
                return null;
            shouldOpenExisting = result == Messages.OK;
        }

        final Project projectToOpen;
        if (shouldOpenExisting) {
            try {
                projectToOpen = ProjectManagerEx.getInstanceEx().loadProject(pathToOpen);
            } catch (IOException e) {
                return null;
            } catch (JDOMException e) {
                return null;
            } catch (InvalidDataException e) {
                return null;
            }
        } else {
            projectToOpen = ProjectManagerEx.getInstanceEx().newProject(wizardContext.getProjectName(),
                    pathToOpen, true, false);

            if (projectToOpen == null || !getBuilder().validate(projectToClose, projectToOpen)) {
                return null;
            }

            projectToOpen.save();

            getBuilder().commit(projectToOpen, null, ModulesProvider.EMPTY_MODULES_PROVIDER);
        }

        if (!forceOpenInNewFrame) {
            NewProjectUtilPlatform.closePreviousProject(projectToClose);
        }
        ProjectUtil.updateLastProjectLocation(pathToOpen);
        ProjectManagerEx.getInstanceEx().openProject(projectToOpen);

        return projectToOpen;
    } finally {
        getBuilder().cleanup();
    }
}

From source file:com.intellij.ui.tabs.impl.DragHelper.java

License:Apache License

@Override
protected void processDragFinish(MouseEvent event, boolean willDragOutStart) {
    super.processDragFinish(event, willDragOutStart);

    endDrag(willDragOutStart);//  w w  w. ja  v  a 2s  . c  o  m

    final JBTabsPosition position = myTabs.getTabsPosition();

    if (!willDragOutStart && myTabs.isAlphabeticalMode() && position != JBTabsPosition.top
            && position != JBTabsPosition.bottom) {
        Point p = new Point(event.getPoint());
        p = SwingUtilities.convertPoint(event.getComponent(), p, myTabs);
        if (myTabs.getVisibleRect().contains(p)
                && myPressedOnScreenPoint.distance(new RelativePoint(event).getScreenPoint()) > 15) {
            final int answer = Messages.showOkCancelDialog(myTabs,
                    IdeBundle.message("alphabetical.mode.is.on.warning"), IdeBundle.message("title.warning"),
                    Messages.getQuestionIcon());
            if (answer == Messages.OK) {
                JBEditorTabs.setAlphabeticalMode(false);
                myTabs.relayout(true, false);
                myTabs.revalidate();
            }
        }
    }
}

From source file:com.intellij.usages.UsageLimitUtil.java

License:Apache License

@NotNull
public static Result showTooManyUsagesWarning(@NotNull final Project project, @NotNull final String message,
        @NotNull final UsageViewPresentation usageViewPresentation) {
    final String[] buttons = { UsageViewBundle.message("button.text.continue"),
            UsageViewBundle.message("button.text.abort") };
    int result = runOrInvokeAndWait(new Computable<Integer>() {
        @Override/*from   w  ww .  j a  v  a  2 s .  c o  m*/
        public Integer compute() {
            String title = UsageViewBundle.message("find.excessive.usages.title",
                    StringUtil.capitalize(StringUtil.pluralize(usageViewPresentation.getUsagesWord())));
            return Messages.showOkCancelDialog(project, message, title, buttons[0], buttons[1],
                    Messages.getWarningIcon());
        }
    });
    return result == Messages.OK ? Result.CONTINUE : Result.ABORT;
}

From source file:com.jetbrains.lang.dart.ide.actions.DartSortMembersAction.java

License:Apache License

protected void runOverFiles(@NotNull final Project project, @NotNull final List<VirtualFile> dartFiles) {
    if (dartFiles.isEmpty()) {
        Messages.showInfoMessage(project, DartBundle.message("dart.sort.members.files.no.dart.files"),
                DartBundle.message("dart.sort.members.action.name"));
        return;/*from   ww w.j  a  va 2s  .co  m*/
    }

    if (Messages.showOkCancelDialog(project,
            DartBundle.message("dart.sort.members.files.dialog.question", dartFiles.size()),
            DartBundle.message("dart.sort.members.action.name"), null) != Messages.OK) {
        return;
    }

    final Map<VirtualFile, SourceFileEdit> fileToFileEditMap = Maps.newHashMap();

    final Runnable runnable = () -> {
        double fraction = 0.0;
        for (final VirtualFile virtualFile : dartFiles) {
            fraction += 1.0;
            final ProgressIndicator indicator = ProgressManager.getInstance().getProgressIndicator();
            if (indicator != null) {
                indicator.checkCanceled();
                indicator.setFraction(fraction / dartFiles.size());
                indicator.setText2(FileUtil.toSystemDependentName(virtualFile.getPath()));
            }

            final String path = virtualFile.getPath();
            final SourceFileEdit fileEdit = DartAnalysisServerService.getInstance(project)
                    .edit_sortMembers(path);
            if (fileEdit != null) {
                fileToFileEditMap.put(virtualFile, fileEdit);
            }
        }
    };

    DartAnalysisServerService.getInstance(project).updateFilesContent();

    final boolean ok = ApplicationManagerEx.getApplicationEx().runProcessWithProgressSynchronously(runnable,
            DartBundle.message("dart.sort.members.action.name"), true, project);

    if (ok) {
        final Runnable onSuccessRunnable = () -> {
            CommandProcessor.getInstance().markCurrentCommandAsGlobal(project);

            for (Map.Entry<VirtualFile, SourceFileEdit> entry : fileToFileEditMap.entrySet()) {
                final VirtualFile file = entry.getKey();
                final Document document = FileDocumentManager.getInstance().getDocument(file);
                final SourceFileEdit fileEdit = entry.getValue();
                if (document != null) {
                    AssistUtils.applySourceEdits(project, file, document, fileEdit.getEdits(),
                            Collections.emptySet());
                }
            }
        };

        ApplicationManager.getApplication()
                .runWriteAction(() -> CommandProcessor.getInstance().executeCommand(project, onSuccessRunnable,
                        DartBundle.message("dart.sort.members.action.name"), null));
    }
}

From source file:com.mbeddr.pluginmanager.com.intellij.ide.plugins.InstalledPluginsManagerMain.java

License:Apache License

private static void checkInstalledPluginDependencies(@NotNull InstalledPluginsTableModel model,
        @NotNull IdeaPluginDescriptorImpl pluginDescriptor, @Nullable Component parent) {
    final Set<PluginId> notInstalled = new HashSet<PluginId>();
    final Set<PluginId> disabledIds = new HashSet<PluginId>();
    final PluginId[] dependentPluginIds = pluginDescriptor.getDependentPluginIds();
    final PluginId[] optionalDependentPluginIds = pluginDescriptor.getOptionalDependentPluginIds();
    for (PluginId id : dependentPluginIds) {
        if (ArrayUtilRt.find(optionalDependentPluginIds, id) > -1)
            continue;
        final boolean disabled = model.isDisabled(id);
        final boolean enabled = model.isEnabled(id);
        if (!enabled && !disabled && !ReflectionUtil.isModuleDependency(id)) {
            notInstalled.add(id);//w  w  w  . j  a  v a 2  s. c  o m
        } else if (disabled) {
            disabledIds.add(id);
        }
    }
    if (!notInstalled.isEmpty()) {
        String deps = StringUtil.join(notInstalled, new Function<PluginId, String>() {
            @Override
            public String fun(PluginId id) {
                return id.toString();
            }
        }, ", ");
        String message = "Plugin " + pluginDescriptor.getName() + " depends on unknown plugin"
                + (notInstalled.size() > 1 ? "s " : " ") + deps;
        MessagesEx.showWarningDialog(parent, message, CommonBundle.getWarningTitle());
    }
    if (!disabledIds.isEmpty()) {
        final Set<IdeaPluginDescriptor> dependencies = new HashSet<IdeaPluginDescriptor>();
        for (IdeaPluginDescriptor ideaPluginDescriptor : model.getAllPlugins()) {
            if (disabledIds.contains(ideaPluginDescriptor.getPluginId())) {
                dependencies.add(ideaPluginDescriptor);
            }
        }
        String part = "disabled plugin" + (dependencies.size() > 1 ? "s " : " ");
        String deps = StringUtil.join(dependencies, new Function<IdeaPluginDescriptor, String>() {
            @Override
            public String fun(IdeaPluginDescriptor descriptor) {
                return descriptor.getName();
            }
        }, ", ");
        String message = "Plugin " + pluginDescriptor.getName() + " depends on " + part + deps + ". Enable "
                + part.trim() + "?";
        if (MessagesEx.showOkCancelDialog(parent, message, CommonBundle.getWarningTitle(),
                Messages.getWarningIcon()) == Messages.OK) {
            model.enableRows(dependencies.toArray(new IdeaPluginDescriptor[dependencies.size()]), Boolean.TRUE);
        }
    }
}