ComponentWithBrowseButton - optional remove listener on hide
[fedora-idea.git] / platform / lang-impl / src / com / intellij / codeInspection / ex / EditInspectionToolsSettingsAction.java
bloba87aaede970971ffdf459348bce22f7c400756c3
1 /*
2 * Copyright 2000-2009 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package com.intellij.codeInspection.ex;
19 import com.intellij.codeInsight.daemon.HighlightDisplayKey;
20 import com.intellij.codeInsight.intention.IntentionAction;
21 import com.intellij.codeInspection.InspectionProfile;
22 import com.intellij.codeInspection.InspectionsBundle;
23 import com.intellij.codeInspection.LocalInspectionTool;
24 import com.intellij.openapi.editor.Editor;
25 import com.intellij.openapi.options.ShowSettingsUtil;
26 import com.intellij.openapi.project.Project;
27 import com.intellij.openapi.util.IconLoader;
28 import com.intellij.openapi.util.Iconable;
29 import com.intellij.profile.codeInspection.InspectionProfileManager;
30 import com.intellij.profile.codeInspection.InspectionProjectProfileManager;
31 import com.intellij.profile.codeInspection.ui.ErrorsConfigurable;
32 import com.intellij.profile.codeInspection.ui.IDEInspectionToolsConfigurable;
33 import com.intellij.psi.PsiFile;
34 import com.intellij.util.IncorrectOperationException;
35 import org.jetbrains.annotations.NotNull;
37 import javax.swing.*;
39 /**
40 * User: anna
41 * Date: Feb 7, 2005
43 public class EditInspectionToolsSettingsAction implements IntentionAction, Iconable {
44 private final String myShortName;
45 private static final Icon ICON = IconLoader.getIcon("/general/ideOptions.png");
47 public EditInspectionToolsSettingsAction(@NotNull LocalInspectionTool tool) {
48 myShortName = tool.getShortName();
51 public EditInspectionToolsSettingsAction(@NotNull HighlightDisplayKey key) {
52 myShortName = key.toString();
55 @NotNull
56 public String getText() {
57 return InspectionsBundle.message("edit.options.of.reporter.inspection.text");
60 @NotNull
61 public String getFamilyName() {
62 return InspectionsBundle.message("edit.options.of.reporter.inspection.family");
65 public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) {
66 return true;
69 public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
70 final InspectionProjectProfileManager projectProfileManager = InspectionProjectProfileManager.getInstance(file.getProject());
71 InspectionProfile inspectionProfile = projectProfileManager.getInspectionProfile();
72 editToolSettings(project,
73 inspectionProfile, true,
74 myShortName);
77 public boolean editToolSettings(final Project project,
78 final InspectionProfileImpl inspectionProfile,
79 final boolean canChooseDifferentProfiles) {
80 return editToolSettings(project,
81 inspectionProfile,
82 canChooseDifferentProfiles,
83 myShortName);
86 public static boolean editToolSettings(final Project project,
87 final InspectionProfile inspectionProfile,
88 final boolean canChooseDifferentProfile,
89 final String selectedToolShortName) {
90 final ShowSettingsUtil settingsUtil = ShowSettingsUtil.getInstance();
91 final ErrorsConfigurable errorsConfigurable;
92 if (!canChooseDifferentProfile) {
93 errorsConfigurable = new IDEInspectionToolsConfigurable(InspectionProjectProfileManager.getInstance(project), InspectionProfileManager.getInstance());
95 else {
96 errorsConfigurable = ErrorsConfigurable.SERVICE.getInstance(project);
98 return settingsUtil.editConfigurable(project, errorsConfigurable, new Runnable() {
99 public void run() {
100 errorsConfigurable.selectProfile(inspectionProfile.getName());
101 SwingUtilities.invokeLater(new Runnable() {
102 public void run() {
103 errorsConfigurable.selectInspectionTool(selectedToolShortName);
111 public boolean startInWriteAction() {
112 return false;
115 public Icon getIcon(int flags) {
116 return ICON;