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.bamboo.BambooPopupInfo;
21 import com.atlassian.theplugin.commons.bamboo.BambooStatusDisplay;
22 import com.atlassian.theplugin.commons.bamboo.BuildStatus;
23 import com.atlassian.theplugin.commons.cfg.CfgManager;
24 import com.atlassian.theplugin.idea.PluginToolWindow;
25 import com.atlassian.theplugin.idea.StatusBarPluginIcon;
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
45
46 public BambooStatusIcon(final Project project, CfgManager cfgManager, final PluginToolWindow pluginToolWindow) {
47
48 super(project, cfgManager);
49
50
51
52
53 addMouseListener(new MouseAdapter() {
54
55
56
57
58
59
60
61
62
63
64 @Override
65 public void mouseClicked(MouseEvent e) {
66 pluginToolWindow.focusPanel(PluginToolWindow.ToolWindowPanels.BUILDS);
67 }
68 });
69
70 }
71
72
73 public void updateBambooStatus(BuildStatus status, BambooPopupInfo notUsed) {
74
75 switch (status) {
76 case FAILURE:
77 setToolTipText("Some builds failed. Click to see details.");
78 setIcon(ICON_RED);
79 break;
80 case UNKNOWN:
81 setIcon(ICON_GREY);
82 break;
83 case SUCCESS:
84 setToolTipText("All builds currently passing.");
85 setIcon(ICON_GREEN);
86 break;
87 default:
88 throw new IllegalArgumentException("Illegal state of build.");
89 }
90 }
91
92 public void showOrHideIcon() {
93 super.showOrHideIcon(ServerType.BAMBOO_SERVER);
94 }
95
96 }