View Javadoc

1   /**
2    * Copyright (C) 2008 Atlassian
3    * 
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
7    * 
8    *    http://www.apache.org/licenses/LICENSE-2.0
9    * 
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.
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  //	private final PluginStatusBarToolTip tooltip;
40  
41  	/**
42  	 * @param project reference to the project (frame) that owns this icon.
43  	 * @param cfgManager
44  	 * @param pluginToolWindow
45  	 */
46      public BambooStatusIcon(final Project project, CfgManager cfgManager, final PluginToolWindow pluginToolWindow) {
47  
48  		super(project, cfgManager);
49  
50  		// show tooltip on mouse over
51  //		tooltip = new PluginStatusBarToolTip(WindowManager.getInstance().getFrame(aProjectComponent.getProject()));
52  
53  		addMouseListener(new MouseAdapter() {
54              /*
55              public void mouseEntered(MouseEvent e) {
56  
57  				tooltip.showToltip(
58  						(int) MouseInfo.getPointerInfo().getLocation().getX(),
59  						(int) MouseInfo.getPointerInfo().getLocation().getY());
60  			}
61  			*/
62  
63  			// show/hide toolbar on click
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  //		tooltip.setHtmlContent(fullInfo);
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  }