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

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

Introduction

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

Prototype

@NotNull
    public static Icon getQuestionIcon() 

Source Link

Usage

From source file:com.intellij.lang.properties.refactoring.ResourceBundleRenameHandler.java

License:Apache License

public void invoke(@NotNull Project project, Editor editor, PsiFile file, DataContext dataContext) {
    ResourceBundle resourceBundle = ResourceBundleUtil.getResourceBundleFromDataContext(dataContext);

    assert resourceBundle != null;
    Messages.showInputDialog(project,/*from ww w .  j a  va2  s  .  co m*/
            PropertiesBundle.message("rename.bundle.enter.new.resource.bundle.base.name.prompt.text"),
            PropertiesBundle.message("rename.resource.bundle.dialog.title"), Messages.getQuestionIcon(),
            resourceBundle.getBaseName(), new MyInputValidator(project, resourceBundle));
}

From source file:com.intellij.lang.properties.ResourceBundleRenameHandler.java

License:Apache License

public void invoke(@NotNull Project project, Editor editor, PsiFile file, DataContext dataContext) {
    ResourceBundle resourceBundle = getResourceBundleFromDataContext(dataContext);

    assert resourceBundle != null;
    Messages.showInputDialog(project,/*from  www .  j  a  v a 2s .c  o m*/
            PropertiesBundle.message("rename.bundle.enter.new.resource.bundle.base.name.prompt.text"),
            PropertiesBundle.message("rename.resource.bundle.dialog.title"), Messages.getQuestionIcon(),
            resourceBundle.getBaseName(), new MyInputValidator(project, resourceBundle));
}

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;
    }/* ww w. j av a  2 s  . c  o  m*/

    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.platform.renameProject.RenameProjectHandler.java

License:Apache License

@Override
public void invoke(@NotNull Project project, @NotNull PsiElement[] elements, DataContext dataContext) {
    LOG.assertTrue(project instanceof ProjectEx);

    final Module module = LangDataKeys.MODULE_CONTEXT.getData(dataContext);
    LOG.assertTrue(module != null);//from www  .j a va  2 s  . c o  m
    Messages.showInputDialog(project, RefactoringBundle.message("enter.new.project.name"),
            RefactoringBundle.message("rename.project"), Messages.getQuestionIcon(), project.getName(),
            new MyInputValidator((ProjectEx) project, module));
}

From source file:com.intellij.plugins.haxe.ide.HaxeFindUsagesHandlerFactory.java

License:Apache License

private String askWhetherToSearchForOverridingMethods(@NotNull PsiElement psiElement) {
    // TODO: Externalize the strings.
    int answer = Messages.showDialog(psiElement.getProject(),
            "Method is implemented in a base class or interface.  Would you like to find callers of the base class(es)?",
            "Find Method Callers", OVERRIDING_OPTIONS, 0, Messages.getQuestionIcon()); // XXX - Add "Don't ask again?  Have to store that and allow a reset if we do.
    if (-1 == answer) {
        throw new ProcessCanceledException(new Throwable("FindUsages canceled by user."));
    }//from   w w  w.  j  a  v  a 2 s .c  o m
    return OVERRIDING_OPTIONS[answer];
}

From source file:com.intellij.profile.codeInspection.ui.actions.AddScopeAction.java

License:Apache License

@Override
public void actionPerformed(AnActionEvent e) {
    final List<Descriptor> descriptors = new ArrayList<Descriptor>();
    final InspectionConfigTreeNode[] selectedNodes = myTree.getSelectedNodes(InspectionConfigTreeNode.class,
            null);/* w w w .  j a  va  2s.c  om*/
    LOG.assertTrue(selectedNodes != null);

    final List<InspectionConfigTreeNode> nodes = new ArrayList<InspectionConfigTreeNode>(
            Arrays.asList(selectedNodes));
    for (InspectionConfigTreeNode node : selectedNodes) {
        collect(descriptors, nodes, node);
    }

    final Project project = getProject(e);
    final List<String> availableScopes = getAvailableScopes(project, descriptors);
    final int idx = Messages.showChooseDialog(myTree, "Scope:", "Choose Scope",
            ArrayUtil.toStringArray(availableScopes), availableScopes.get(0), Messages.getQuestionIcon());
    if (idx == -1)
        return;
    final NamedScope chosenScope = NamedScopesHolder.getScope(project, availableScopes.get(idx));

    for (InspectionConfigTreeNode node : nodes) {
        final Descriptor descriptor = node.getDescriptor();
        if (node.getScopeName() != null || descriptor == null)
            continue;
        final InspectionToolWrapper toolWrapper = descriptor.getToolWrapper(); //copy
        InspectionProfileImpl selectedProfile = getSelectedProfile();
        HighlightDisplayLevel level = selectedProfile.getErrorLevel(descriptor.getKey(), chosenScope, project);
        boolean enabled = selectedProfile.isToolEnabled(descriptor.getKey());
        final ScopeToolState scopeToolState = selectedProfile.addScope(toolWrapper, chosenScope, level, enabled,
                project);
        final Descriptor addedDescriptor = new Descriptor(scopeToolState, selectedProfile, project);
        if (node.getChildCount() == 0) {
            node.add(new InspectionConfigTreeNode(descriptor,
                    selectedProfile.getToolDefaultState(descriptor.getKey().toString(), project), true, true,
                    false));
        }
        node.insert(new InspectionConfigTreeNode(addedDescriptor, scopeToolState, false, false), 0);
        node.setInspectionNode(false);
        node.dropCache();
        ((DefaultTreeModel) myTree.getModel()).reload(node);
        myTree.expandPath(new TreePath(node.getPath()));
    }
    myTree.revalidate();
}

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   ww 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   w w w. j  ava  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.profile.codeInspection.ui.SingleInspectionProfilePanel.java

License:Apache License

@Nullable
public static ModifiableModel createNewProfile(final int initValue, ModifiableModel selectedProfile,
        JPanel parent, String profileName, Set<String> existingProfileNames, @NotNull Project project) {
    profileName = Messages.showInputDialog(parent, profileName, "Create New Inspection Profile",
            Messages.getQuestionIcon());
    if (profileName == null)
        return null;
    final ProfileManager profileManager = selectedProfile.getProfileManager();
    if (existingProfileNames.contains(profileName)) {
        Messages.showErrorDialog(/*from   w w w . j av  a2  s  .  c  om*/
                InspectionsBundle.message("inspection.unable.to.create.profile.message", profileName),
                InspectionsBundle.message("inspection.unable.to.create.profile.dialog.title"));
        return null;
    }
    InspectionProfileImpl inspectionProfile = new InspectionProfileImpl(profileName,
            InspectionToolRegistrar.getInstance(), profileManager);
    if (initValue == -1) {
        inspectionProfile.initInspectionTools(project);
        ModifiableModel profileModifiableModel = inspectionProfile.getModifiableModel();
        final InspectionToolWrapper[] profileEntries = profileModifiableModel.getInspectionTools(null);
        for (InspectionToolWrapper toolWrapper : profileEntries) {
            profileModifiableModel.disableTool(toolWrapper.getShortName(), null, project);
        }
        profileModifiableModel.setProjectLevel(false);
        profileModifiableModel.setModified(true);
        return profileModifiableModel;
    } else if (initValue == 0) {
        inspectionProfile.copyFrom(selectedProfile);
        inspectionProfile.setName(profileName);
        inspectionProfile.initInspectionTools(project);
        inspectionProfile.setModified(true);
        return inspectionProfile;
    }
    return null;
}

From source file:com.intellij.projectImport.ProjectOpenProcessorBase.java

License:Apache License

@Override
@Nullable/*from w  w  w.ja v a  2  s.co  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();
    }
}