1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package com.atlassian.theplugin.idea.bamboo;
18
19 import com.atlassian.theplugin.commons.ServerType;
20 import com.atlassian.theplugin.commons.cfg.CfgManager;
21 import com.atlassian.theplugin.commons.bamboo.BuildStatus;
22 import com.atlassian.theplugin.commons.bamboo.BambooStatusDisplay;
23 import com.atlassian.theplugin.commons.bamboo.BambooPopupInfo;
24 import com.atlassian.theplugin.idea.StatusBarPluginIcon;
25 import com.atlassian.theplugin.idea.PluginToolWindow;
26 import com.intellij.openapi.project.Project;
27 import com.intellij.openapi.util.IconLoader;
28
29 import javax.swing.*;
30 import java.awt.event.MouseAdapter;
31 import java.awt.event.MouseEvent;
32
33 public class BambooStatusIcon extends StatusBarPluginIcon implements BambooStatusDisplay {
34
35 private static final Icon ICON_RED = IconLoader.getIcon("/icons/red-16.png");
36 private static final Icon ICON_GREEN = IconLoader.getIcon("/icons/green-16.png");
37 private static final Icon ICON_GREY = IconLoader.getIcon("/icons/grey-16.png");
38
39
40
41
42
43
44 public BambooStatusIcon(final Project project, CfgManager cfgManager) {
45
46 super(project, cfgManager);
47
48
49
50
51 addMouseListener(new MouseAdapter() {
52
53
54
55
56
57
58
59
60
61
62 public void mouseClicked(MouseEvent e) {
63 PluginToolWindow.focusPanel(project, PluginToolWindow.ToolWindowPanels.BAMBOO);
64 }
65 });
66
67 }
68
69
70 public void updateBambooStatus(BuildStatus status, BambooPopupInfo notUsed) {
71
72 switch (status) {
73 case BUILD_FAILED:
74 setToolTipText("Some builds failed. Click to see details.");
75 setIcon(ICON_RED);
76 break;
77 case UNKNOWN:
78 setIcon(ICON_GREY);
79 break;
80 case BUILD_SUCCEED:
81 setToolTipText("All builds currently passing.");
82 setIcon(ICON_GREEN);
83 break;
84 default:
85 throw new IllegalArgumentException("Illegal state of build.");
86 }
87 }
88
89 public void showOrHideIcon() {
90 super.showOrHideIcon(ServerType.BAMBOO_SERVER);
91 }
92
93 }