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.BuildStatus;
21  import com.atlassian.theplugin.commons.bamboo.BambooStatusDisplay;
22  import com.atlassian.theplugin.commons.bamboo.BambooPopupInfo;
23  import com.atlassian.theplugin.idea.StatusBarPluginIcon;
24  import com.atlassian.theplugin.idea.PluginToolWindow;
25  import com.intellij.openapi.project.Project;
26  import com.intellij.openapi.util.IconLoader;
27  
28  import javax.swing.*;
29  import java.awt.event.MouseAdapter;
30  import java.awt.event.MouseEvent;
31  
32  public class BambooStatusIcon extends StatusBarPluginIcon implements BambooStatusDisplay {
33  
34  	private static final Icon ICON_RED = IconLoader.getIcon("/icons/red-16.png");
35  	private static final Icon ICON_GREEN = IconLoader.getIcon("/icons/green-16.png");
36  	private static final Icon ICON_GREY = IconLoader.getIcon("/icons/grey-16.png");
37  
38  //	private final PluginStatusBarToolTip tooltip;
39  
40  	/**
41  	 * @param project reference to the project that owns this icon.
42  	 */
43      public BambooStatusIcon(final Project project) {
44  
45  		super(project);
46  
47  		// show tooltip on mouse over
48  //		tooltip = new PluginStatusBarToolTip(WindowManager.getInstance().getFrame(aProjectComponent.getProject()));
49  
50  		addMouseListener(new MouseAdapter() {
51              /*
52              public void mouseEntered(MouseEvent e) {
53  
54  				tooltip.showToltip(
55  						(int) MouseInfo.getPointerInfo().getLocation().getX(),
56  						(int) MouseInfo.getPointerInfo().getLocation().getY());
57  			}
58  			*/
59  
60  			// show/hide toolbar on click
61  			public void mouseClicked(MouseEvent e) {
62  				PluginToolWindow.focusPanel(project, PluginToolWindow.ToolWindowPanels.BAMBOO);
63              }
64  		});
65  
66  	}
67  
68  
69  	public void updateBambooStatus(BuildStatus status, BambooPopupInfo notUsed) {
70  //		tooltip.setHtmlContent(fullInfo);
71  		switch (status) {
72  			case BUILD_FAILED:
73                  setToolTipText("Some builds failed. Click to see details.");
74  				setIcon(ICON_RED);
75                  break;
76  			case UNKNOWN:
77  				setIcon(ICON_GREY);
78  				break;
79  			case BUILD_SUCCEED:
80                  setToolTipText("All builds currently passing.");
81  				setIcon(ICON_GREEN);
82  				break;
83  			default:
84  				throw new IllegalArgumentException("Illegal state of build.");
85  		}
86  	}
87  
88  	public void showOrHideIcon() {
89  		super.showOrHideIcon(ServerType.BAMBOO_SERVER);
90  	}
91  
92  }