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.action.jira;
18  
19  import com.atlassian.theplugin.commons.ServerType;
20  import com.atlassian.theplugin.commons.Server;
21  import com.atlassian.theplugin.commons.configuration.ProductServerConfiguration;
22  import com.atlassian.theplugin.idea.IdeaHelper;
23  import com.atlassian.theplugin.idea.ThePluginApplicationComponent;
24  import com.intellij.openapi.actionSystem.AnAction;
25  import com.intellij.openapi.actionSystem.AnActionEvent;
26  import com.intellij.openapi.actionSystem.DefaultActionGroup;
27  import com.intellij.openapi.actionSystem.ex.ComboBoxAction;
28  
29  import javax.swing.*;
30  
31  public class SelectJIRAAction extends ComboBoxAction {
32  
33  	protected DefaultActionGroup createPopupActionGroup(JComponent jComponent) {
34  		ThePluginApplicationComponent appComponent = IdeaHelper.getAppComponent();
35  
36  		final DefaultActionGroup g = new DefaultActionGroup();
37  
38  		ProductServerConfiguration jConfig = appComponent.getState().getProductServers(ServerType.JIRA_SERVER);
39  
40  		final ComboBoxButton button = (ComboBoxButton) jComponent;
41  		for (final Server server : jConfig.transientgetEnabledServers()) {
42  			g.add(new AnAction(server.getName()) {
43  				public void actionPerformed(AnActionEvent event) {
44  					button.setText(event.getPresentation().getText());
45  					IdeaHelper.getJIRAToolWindowPanel(event).selectServer(server);
46  				}
47  			});
48  		}
49  		return g;
50  	}
51  
52  	public void update(AnActionEvent event) {
53  		super.update(event);
54  		if (IdeaHelper.getCurrentJIRAServer() != null) {
55  			event.getPresentation().setText(IdeaHelper.getCurrentJIRAServer().getServer().getName());
56  		}
57  	}
58  }