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