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  package com.atlassian.theplugin.idea.action.issues.activetoolbar;
17  
18  import com.atlassian.theplugin.idea.IdeaHelper;
19  import com.atlassian.theplugin.idea.jira.IssueListToolWindowPanel;
20  import com.atlassian.theplugin.jira.api.JIRAException;
21  import com.atlassian.theplugin.jira.api.JIRAIssue;
22  import com.intellij.openapi.actionSystem.AnAction;
23  import com.intellij.openapi.actionSystem.AnActionEvent;
24  import com.intellij.openapi.project.Project;
25  
26  import javax.swing.*;
27  
28  /**
29   * User: pmaruszak
30   */
31  public class OpenActiveJiraIssue extends AnAction {
32  	public void actionPerformed(final AnActionEvent event) {
33  		openIssue(event);
34  	}
35  
36  	public void update(final AnActionEvent event) {
37  		event.getPresentation().setEnabled(ActiveIssueUtils.getActiveJiraIssue(event) != null);
38  	}
39  
40  	private void openIssue(final AnActionEvent event) {
41  		SwingUtilities.invokeLater(new Runnable() {
42  			public void run() {
43  				final Project currentProject = IdeaHelper
44  						.getCurrentProject(event);
45  				final JIRAIssue issue;
46  				if (currentProject != null) {
47  					final IssueListToolWindowPanel panel = IdeaHelper.getIssueListToolWindowPanel(currentProject);
48  					try {
49  						issue = ActiveIssueUtils.getJIRAIssue(currentProject);
50  						if (issue != null) {
51  							if (panel != null) {
52  								panel.openIssue(issue);
53  							}
54  						}
55  					} catch (JIRAException e) {
56  						if (panel != null) {
57  							panel.setStatusErrorMessage("Error opening issue: " + e.getMessage(), e);
58  						}
59  					}
60  				}
61  			}
62  		});
63  	}
64  }