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.cfg.CfgUtil;
20  import com.atlassian.theplugin.commons.cfg.JiraServerCfg;
21  import com.atlassian.theplugin.idea.IdeaHelper;
22  import com.atlassian.theplugin.jira.JIRAServer;
23  import com.intellij.openapi.actionSystem.AnAction;
24  import com.intellij.openapi.actionSystem.AnActionEvent;
25  import com.intellij.openapi.actionSystem.DefaultActionGroup;
26  import com.intellij.openapi.actionSystem.ex.ComboBoxAction;
27  import com.intellij.openapi.project.Project;
28  import org.jetbrains.annotations.NotNull;
29  
30  import javax.swing.*;
31  import java.util.Collection;
32  
33  public class SelectJIRAAction extends ComboBoxAction {
34  
35  	@NotNull
36  	@Override
37  	protected DefaultActionGroup createPopupActionGroup(JComponent jComponent) {
38  
39  		final Project project = IdeaHelper.getCurrentProject(jComponent);
40  
41  		final DefaultActionGroup g = new DefaultActionGroup();
42  
43  		Collection<JiraServerCfg> servers = IdeaHelper.getCfgManager().getAllEnabledJiraServers(
44  				CfgUtil.getProjectId(project));
45  
46  		final ComboBoxButton button = (ComboBoxButton) jComponent;
47  		for (final JiraServerCfg server : servers) {
48  			g.add(new AnAction(server.getName()) {
49  				@Override
50  				public void actionPerformed(AnActionEvent event) {
51  					button.setText(event.getPresentation().getText());
52  					IdeaHelper.getJIRAToolWindowPanel(event).selectServer(server);
53  				}
54  			});
55  		}
56  		return g;
57  	}
58  
59  	@Override
60  	public void update(AnActionEvent event) {
61  		super.update(event);
62  		JIRAServer jiraServer = IdeaHelper.getCurrentJIRAServer(event.getDataContext()); 
63  		if (jiraServer != null) {
64  			event.getPresentation().setText(jiraServer.getServer().getName());
65  		}
66  	}
67  }