provide icons for suppress actions (IDEA-11222 )
[fedora-idea.git] / platform / lang-impl / src / com / intellij / codeInspection / ex / DisableInspectionToolAction.java
bloba003ffc0ad3638dabb79a54f5061090145835fe0
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.CommonBundle;
20 import com.intellij.codeInsight.daemon.DaemonCodeAnalyzer;
21 import com.intellij.codeInsight.daemon.HighlightDisplayKey;
22 import com.intellij.codeInsight.intention.IntentionAction;
23 import com.intellij.codeInspection.InspectionProfile;
24 import com.intellij.codeInspection.InspectionsBundle;
25 import com.intellij.codeInspection.LocalInspectionTool;
26 import com.intellij.codeInspection.ModifiableModel;
27 import com.intellij.openapi.editor.Editor;
28 import com.intellij.openapi.project.Project;
29 import com.intellij.openapi.ui.Messages;
30 import com.intellij.openapi.util.IconLoader;
31 import com.intellij.openapi.util.Iconable;
32 import com.intellij.profile.codeInspection.InspectionProjectProfileManager;
33 import com.intellij.psi.PsiFile;
34 import com.intellij.util.IncorrectOperationException;
35 import org.jetbrains.annotations.NotNull;
37 import javax.swing.*;
38 import java.io.IOException;
40 public class DisableInspectionToolAction implements IntentionAction, Iconable {
41 private final String myToolId;
42 public static final String NAME = InspectionsBundle.message("disable.inspection.action.name");
43 private static final Icon ICON = IconLoader.getIcon("/general/inspectionsOff.png");
45 public DisableInspectionToolAction(LocalInspectionTool tool) {
46 myToolId = tool.getShortName();
49 public DisableInspectionToolAction(final HighlightDisplayKey key) {
50 myToolId = key.toString();
53 @NotNull
54 public String getText() {
55 return NAME;
58 @NotNull
59 public String getFamilyName() {
60 return NAME;
63 public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) {
64 return true;
67 public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
68 final InspectionProjectProfileManager profileManager = InspectionProjectProfileManager.getInstance(file.getProject());
69 InspectionProfile inspectionProfile = profileManager.getInspectionProfile();
70 ModifiableModel model = inspectionProfile.getModifiableModel();
71 model.disableTool(myToolId, file);
72 try {
73 model.commit();
75 catch (IOException e) {
76 Messages.showErrorDialog(project, e.getMessage(), CommonBundle.getErrorTitle());
78 DaemonCodeAnalyzer.getInstance(project).restart();
81 public boolean startInWriteAction() {
82 return false;
85 public Icon getIcon(int flags) {
86 return ICON;