Search in sources :

Example 1 with InspectionProfileModifiableModel

use of com.intellij.codeInspection.ex.InspectionProfileModifiableModel in project intellij-community by JetBrains.

the class InspectionProfileSchemesModel method canDeleteScheme.

@Override
public boolean canDeleteScheme(@NotNull InspectionProfileModifiableModel candidateToDelete) {
    boolean projectProfileFound = false;
    boolean ideProfileFound = false;
    for (SingleInspectionProfilePanel profilePanel : myProfilePanels) {
        final InspectionProfileModifiableModel profile = profilePanel.getProfile();
        if (candidateToDelete == profile)
            continue;
        final boolean isProjectProfile = profile.getProfileManager() == myProjectProfileManager;
        projectProfileFound |= isProjectProfile;
        ideProfileFound |= !isProjectProfile;
        if (ideProfileFound && projectProfileFound)
            break;
    }
    return candidateToDelete.getProfileManager() == myProjectProfileManager ? projectProfileFound : ideProfileFound;
}
Also used : InspectionProfileModifiableModel(com.intellij.codeInspection.ex.InspectionProfileModifiableModel) SingleInspectionProfilePanel(com.intellij.profile.codeInspection.ui.SingleInspectionProfilePanel)

Example 2 with InspectionProfileModifiableModel

use of com.intellij.codeInspection.ex.InspectionProfileModifiableModel in project intellij-community by JetBrains.

the class InspectionProfileSchemesPanel method createSchemeActions.

@Override
protected AbstractSchemeActions<InspectionProfileModifiableModel> createSchemeActions() {
    return new DescriptionAwareSchemeActions<InspectionProfileModifiableModel>(this) {

        @Nullable
        @Override
        public String getDescription(@NotNull InspectionProfileModifiableModel scheme) {
            SingleInspectionProfilePanel inspectionProfile = ((InspectionProfileSchemesModel) getModel()).getProfilePanel(scheme);
            return inspectionProfile.getProfile().getDescription();
        }

        @Override
        protected void setDescription(@NotNull InspectionProfileModifiableModel scheme, @NotNull String newDescription) {
            InspectionProfileModifiableModel inspectionProfile = InspectionProfileSchemesPanel.this.getModel().getProfilePanel(scheme).getProfile();
            if (!Comparing.strEqual(newDescription, inspectionProfile.getDescription())) {
                inspectionProfile.setDescription(newDescription);
                inspectionProfile.setModified(true);
            }
        }

        @Override
        protected void importScheme(@NotNull String importerName) {
            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, myProject, null, file -> {
                if (file != null) {
                    final InspectionProfileImpl profile;
                    try {
                        profile = InspectionToolsConfigurable.importInspectionProfile(JDOMUtil.load(file.getInputStream()), myAppProfileManager, myProject);
                        final SingleInspectionProfilePanel existed = InspectionProfileSchemesPanel.this.getModel().getProfilePanel(profile);
                        if (existed != null) {
                            if (Messages.showOkCancelDialog(myProject, "Profile with name \'" + profile.getName() + "\' already exists. Do you want to overwrite it?", "Warning", Messages.getInformationIcon()) != Messages.OK) {
                                return;
                            }
                            getModel().removeScheme(existed.getProfile());
                        }
                        InspectionProfileModifiableModel model = new InspectionProfileModifiableModel(profile);
                        model.setModified(true);
                        addProfile(model);
                        selectScheme(model);
                    } catch (JDOMException | InvalidDataException | IOException e) {
                        LOG.error(e);
                    }
                }
            });
        }

        @Override
        protected void resetScheme(@NotNull InspectionProfileModifiableModel scheme) {
            final SingleInspectionProfilePanel panel = InspectionProfileSchemesPanel.this.getModel().getProfilePanel(scheme);
            panel.performProfileReset();
        }

        @Override
        protected void duplicateScheme(@NotNull InspectionProfileModifiableModel scheme, @NotNull String newName) {
            final InspectionProfileModifiableModel newProfile = copyToNewProfile(scheme, myProject, newName, false);
            addProfile(newProfile);
            myConfigurable.selectProfile(newProfile);
            selectScheme(newProfile);
        }

        @Override
        protected void exportScheme(@NotNull InspectionProfileModifiableModel scheme, @NotNull String exporterName) {
            FileChooserDescriptor descriptor = FileChooserDescriptorFactory.createSingleFolderDescriptor();
            descriptor.setDescription("Choose directory to store profile file");
            FileChooser.chooseFile(descriptor, myProject, null, dir -> {
                try {
                    LOG.assertTrue(true);
                    Element element = scheme.writeScheme(false);
                    Path file = Paths.get(dir.getPath(), sanitizeFileName(scheme.getName()) + ".xml");
                    if (Files.isRegularFile(file.toAbsolutePath()) && Messages.showOkCancelDialog(myProject, "File \'" + file + "\' already exist. Do you want to overwrite it?", "Warning", Messages.getQuestionIcon()) != Messages.OK) {
                        return;
                    }
                    JdomKt.write(element, file);
                } catch (IOException e1) {
                    LOG.error(e1);
                }
            });
        }

        @Override
        protected void onSchemeChanged(@Nullable InspectionProfileModifiableModel scheme) {
            super.onSchemeChanged(scheme);
            if (scheme != null) {
                myConfigurable.selectProfile(scheme);
            }
        }

        @Override
        protected void renameScheme(@NotNull InspectionProfileModifiableModel scheme, @NotNull String newName) {
            scheme.setName(newName);
        }

        @Override
        protected void copyToProject(@NotNull InspectionProfileModifiableModel scheme) {
            copyToAnotherLevel(scheme, true);
        }

        @Override
        protected void copyToIDE(@NotNull InspectionProfileModifiableModel scheme) {
            copyToAnotherLevel(scheme, false);
        }

        @Override
        protected Class<InspectionProfileModifiableModel> getSchemeType() {
            return InspectionProfileModifiableModel.class;
        }

        private void copyToAnotherLevel(InspectionProfileModifiableModel profile, boolean copyToProject) {
            String name = SchemeNameGenerator.getUniqueName(profile.getName(), schemeName -> ((InspectionProfileSchemesModel) getModel()).hasName(schemeName, copyToProject));
            final InspectionProfileModifiableModel newProfile = copyToNewProfile(profile, myProject, name, true);
            addProfile(newProfile);
            selectScheme(newProfile);
            getSchemesPanel().startEdit();
        }
    };
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Path(java.nio.file.Path) InspectionProfileImpl(com.intellij.codeInspection.ex.InspectionProfileImpl) DescriptionAwareSchemeActions(com.intellij.application.options.schemes.DescriptionAwareSchemeActions) FileChooserDescriptor(com.intellij.openapi.fileChooser.FileChooserDescriptor) Element(org.jdom.Element) IOException(java.io.IOException) JDOMException(org.jdom.JDOMException) NotNull(org.jetbrains.annotations.NotNull) SingleInspectionProfilePanel(com.intellij.profile.codeInspection.ui.SingleInspectionProfilePanel) InspectionProfileModifiableModel(com.intellij.codeInspection.ex.InspectionProfileModifiableModel) InvalidDataException(com.intellij.openapi.util.InvalidDataException) Nullable(org.jetbrains.annotations.Nullable)

Example 3 with InspectionProfileModifiableModel

use of com.intellij.codeInspection.ex.InspectionProfileModifiableModel in project intellij-community by JetBrains.

the class InspectionProfileSchemesPanel method copyToNewProfile.

@NotNull
private InspectionProfileModifiableModel copyToNewProfile(@NotNull InspectionProfileImpl selectedProfile, @NotNull Project project, @NotNull String newName, boolean modifyLevel) {
    final boolean isProjectLevel = selectedProfile.isProjectLevel() ^ modifyLevel;
    BaseInspectionProfileManager profileManager = isProjectLevel ? myProjectProfileManager : myAppProfileManager;
    InspectionProfileImpl inspectionProfile = new InspectionProfileImpl(newName, InspectionToolRegistrar.getInstance(), profileManager);
    inspectionProfile.copyFrom(selectedProfile);
    inspectionProfile.setName(newName);
    inspectionProfile.initInspectionTools(project);
    inspectionProfile.setProjectLevel(isProjectLevel);
    InspectionProfileModifiableModel modifiableModel = new InspectionProfileModifiableModel(inspectionProfile);
    modifiableModel.setModified(true);
    return modifiableModel;
}
Also used : BaseInspectionProfileManager(com.intellij.profile.codeInspection.BaseInspectionProfileManager) InspectionProfileImpl(com.intellij.codeInspection.ex.InspectionProfileImpl) InspectionProfileModifiableModel(com.intellij.codeInspection.ex.InspectionProfileModifiableModel) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with InspectionProfileModifiableModel

use of com.intellij.codeInspection.ex.InspectionProfileModifiableModel in project intellij-community by JetBrains.

the class InspectionProfileSchemesPanel method addProfile.

private void addProfile(InspectionProfileModifiableModel profile) {
    final InspectionProfileModifiableModel selected = getSelectedScheme();
    getModel().addProfile(profile);
    getModel().updatePanel(this);
    selectScheme(selected);
}
Also used : InspectionProfileModifiableModel(com.intellij.codeInspection.ex.InspectionProfileModifiableModel)

Example 5 with InspectionProfileModifiableModel

use of com.intellij.codeInspection.ex.InspectionProfileModifiableModel in project intellij-community by JetBrains.

the class InspectionToolsConfigurable method doReset.

private void doReset() {
    disposeUIResources();
    myAbstractSchemesPanel.reset();
    final InspectionProfileModifiableModel currentModifiableModel = myAbstractSchemesPanel.getModel().getModifiableModelFor(getCurrentProfile());
    myAbstractSchemesPanel.selectScheme(currentModifiableModel);
    showProfile(currentModifiableModel);
    final SingleInspectionProfilePanel panel = getSelectedPanel();
    if (panel != null) {
        //make sure that UI was initialized
        panel.setVisible(true);
        mySelectionAlarm = new Alarm(Alarm.ThreadToUse.SWING_THREAD);
        mySelectionAlarm.cancelAllRequests();
        mySelectionAlarm.addRequest(panel::updateSelection, 200);
    }
}
Also used : InspectionProfileModifiableModel(com.intellij.codeInspection.ex.InspectionProfileModifiableModel) Alarm(com.intellij.util.Alarm) SingleInspectionProfilePanel(com.intellij.profile.codeInspection.ui.SingleInspectionProfilePanel)

Aggregations

InspectionProfileModifiableModel (com.intellij.codeInspection.ex.InspectionProfileModifiableModel)7 SingleInspectionProfilePanel (com.intellij.profile.codeInspection.ui.SingleInspectionProfilePanel)4 InspectionProfileImpl (com.intellij.codeInspection.ex.InspectionProfileImpl)2 NotNull (org.jetbrains.annotations.NotNull)2 DescriptionAwareSchemeActions (com.intellij.application.options.schemes.DescriptionAwareSchemeActions)1 FileChooserDescriptor (com.intellij.openapi.fileChooser.FileChooserDescriptor)1 InvalidDataException (com.intellij.openapi.util.InvalidDataException)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 BaseInspectionProfileManager (com.intellij.profile.codeInspection.BaseInspectionProfileManager)1 Alarm (com.intellij.util.Alarm)1 IOException (java.io.IOException)1 Path (java.nio.file.Path)1 Element (org.jdom.Element)1 JDOMException (org.jdom.JDOMException)1 Nullable (org.jetbrains.annotations.Nullable)1