file level inspection ui
[fedora-idea.git] / platform / lang-impl / src / com / intellij / codeInsight / intention / impl / FileLevelIntentionComponent.java
blob93a5870e8813bc1ac83bc1a525b6f236cb867317
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.codeInsight.intention.impl;
19 import com.intellij.codeInsight.daemon.impl.HighlightInfo;
20 import com.intellij.codeInsight.daemon.impl.SeverityRegistrar;
21 import com.intellij.codeInsight.daemon.impl.ShowIntentionsPass;
22 import com.intellij.lang.annotation.HighlightSeverity;
23 import com.intellij.openapi.editor.Editor;
24 import com.intellij.openapi.project.Project;
25 import com.intellij.openapi.ui.popup.JBPopupFactory;
26 import com.intellij.openapi.util.IconLoader;
27 import com.intellij.openapi.util.Pair;
28 import com.intellij.openapi.util.TextRange;
29 import com.intellij.psi.PsiFile;
30 import com.intellij.ui.EditorNotificationPanel;
31 import com.intellij.ui.LightColors;
33 import javax.swing.*;
34 import java.awt.*;
35 import java.awt.event.MouseAdapter;
36 import java.awt.event.MouseEvent;
37 import java.util.List;
39 /**
40 * @author max
42 public class FileLevelIntentionComponent extends EditorNotificationPanel {
43 private static final Icon ourIntentionIcon = IconLoader.getIcon("/actions/intentionBulb.png");
44 private static final Icon ourQuickFixIcon = IconLoader.getIcon("/actions/quickfixBulb.png");
46 private final Project myProject;
48 public FileLevelIntentionComponent(final String description,
49 final HighlightSeverity severity,
50 final List<Pair<HighlightInfo.IntentionActionDescriptor, TextRange>> intentions,
51 final Project project, final PsiFile psiFile, final Editor editor) {
52 super();
53 myProject = project;
55 final ShowIntentionsPass.IntentionsInfo info = new ShowIntentionsPass.IntentionsInfo();
57 if (intentions != null) {
58 for (Pair<HighlightInfo.IntentionActionDescriptor, TextRange> intention : intentions) {
59 final HighlightInfo.IntentionActionDescriptor descriptor = intention.getFirst();
60 info.intentionsToShow.add(descriptor);
61 createActionLabel(descriptor.getAction().getText(), new Runnable() {
62 public void run() {
63 descriptor.getAction().invoke(project, editor, psiFile);
65 });
69 myLabel.setText(description);
70 myLabel.setIcon(SeverityRegistrar.getInstance(project).compare(severity, HighlightSeverity.ERROR) >= 0 ? ourQuickFixIcon : ourIntentionIcon);
71 setBackground(getColor(severity));
73 myLabel.addMouseListener(new MouseAdapter() {
74 public void mouseClicked(MouseEvent e) {
75 IntentionListStep step = new IntentionListStep(null, info, editor, psiFile, project);
76 if (intentions != null && !intentions.isEmpty()) {
77 HighlightInfo.IntentionActionDescriptor descriptor = intentions.get(0).getFirst();
78 IntentionActionWithTextCaching actionWithTextCaching = step.wrapAction(psiFile, descriptor);
79 step = step.getSubStep(actionWithTextCaching, null);
81 JBPopupFactory.getInstance().createListPopup(step).showUnderneathOf(myLabel);
83 });
88 private Color getColor(HighlightSeverity severity) {
89 if (SeverityRegistrar.getInstance(myProject).compare(severity, HighlightSeverity.ERROR) >= 0) {
90 return LightColors.RED;
93 if (SeverityRegistrar.getInstance(myProject).compare(severity, HighlightSeverity.WARNING) >= 0) {
94 return LightColors.YELLOW;
97 return Color.white;