1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package com.atlassian.theplugin.idea;
18
19 import com.atlassian.theplugin.idea.bamboo.BambooTableToolWindowPanel;
20 import com.atlassian.theplugin.idea.crucible.CrucibleTableToolWindowPanel;
21 import com.atlassian.theplugin.idea.crucible.ReviewItemVirtualFile;
22 import com.atlassian.theplugin.idea.crucible.comments.CrucibleReviewActionListener;
23 import com.atlassian.theplugin.idea.crucible.comments.ReviewActionEventBroker;
24 import com.atlassian.theplugin.idea.jira.JIRAToolWindowPanel;
25 import com.atlassian.theplugin.jira.JIRAServer;
26 import com.atlassian.theplugin.commons.configuration.PluginConfigurationBean;
27 import com.intellij.ide.DataManager;
28 import com.intellij.openapi.actionSystem.AnActionEvent;
29 import com.intellij.openapi.actionSystem.DataContext;
30 import com.intellij.openapi.actionSystem.DataKeys;
31 import com.intellij.openapi.application.ApplicationManager;
32 import com.intellij.openapi.project.Project;
33 import com.intellij.openapi.wm.ToolWindow;
34 import com.intellij.openapi.wm.ToolWindowManager;
35 import com.intellij.ui.content.Content;
36 import org.jetbrains.annotations.Nullable;
37
38 import java.util.List;
39
40
41
42
43 public final class IdeaHelper {
44
45 private IdeaHelper() {
46 }
47
48 @Nullable
49 public static Project getCurrentProject() {
50 return getCurrentProject(DataManager.getInstance().getDataContext());
51 }
52
53 @Nullable
54 public static Project getCurrentProject(DataContext dataContext) {
55 return DataKeys.PROJECT.getData(dataContext);
56 }
57
58 @Nullable
59 public static Project getCurrentProject(AnActionEvent e) {
60 return getCurrentProject(e.getDataContext());
61 }
62
63 @Nullable
64 public static JIRAServer getCurrentJIRAServer() {
65 Project p = getCurrentProject(DataManager.getInstance().getDataContext());
66 if (p == null) {
67 return null;
68 }
69 return p.getComponent(ThePluginProjectComponent.class).getCurrentJiraServer();
70 }
71
72 public static List<ReviewItemVirtualFile> getScopeFiles() {
73 Project p = getCurrentProject(DataManager.getInstance().getDataContext());
74 return p.getComponent(ThePluginProjectComponent.class).getReviewScopeFiles();
75 }
76
77 public static ThePluginProjectComponent getCurrentProjectComponent() {
78 Project p = getCurrentProject(DataManager.getInstance().getDataContext());
79 return p.getComponent(ThePluginProjectComponent.class);
80 }
81
82 @Nullable
83 public static void setCurrentJIRAServer(JIRAServer jiraServer) {
84 Project p = getCurrentProject(DataManager.getInstance().getDataContext());
85 if (p == null) {
86 return;
87 }
88 p.getComponent(ThePluginProjectComponent.class).setCurrentJiraServer(jiraServer);
89 }
90
91 public static com.intellij.openapi.wm.ToolWindow getToolWindow(Project p) {
92 return ToolWindowManager.getInstance(p).getToolWindow(PluginToolWindow.TOOL_WINDOW_NAME);
93 }
94
95 public static com.intellij.openapi.wm.ToolWindow getBottomIdeaToolWindow(Project p) {
96 return ToolWindowManager.getInstance(p).getToolWindow(PluginToolWindow.BOTTOM_WINDOW_NAME);
97 }
98
99 public static ThePluginApplicationComponent getAppComponent() {
100 return ApplicationManager.getApplication().getComponent(ThePluginApplicationComponent.class);
101 }
102
103 public static PluginConfigurationBean getPluginConfiguration() {
104 return getAppComponent().getState();
105 }
106
107 public static ToolWindow getCurrentBottomIdeaToolWindow(DataContext dataContext) {
108 Project p = getCurrentProject(dataContext);
109 if (p == null) {
110 return null;
111 }
112 com.intellij.openapi.wm.ToolWindow tw = getBottomIdeaToolWindow(p);
113 return tw;
114 }
115
116
117 public static JIRAToolWindowPanel getJIRAToolWindowPanel(Project p){
118 if (p == null){
119 return null;
120 }
121 com.intellij.openapi.wm.ToolWindow tw = getToolWindow(p);
122 Content content = tw.getContentManager().findContent(PluginToolWindow.ToolWindowPanels.JIRA.toString());
123 if (content == null) {
124 return null;
125 }
126 return (JIRAToolWindowPanel) content.getComponent();
127 }
128 public static JIRAToolWindowPanel getJIRAToolWindowPanel(AnActionEvent event) {
129 Project p = getCurrentProject(event.getDataContext());
130 if (p == null) {
131 return null;
132 }
133 com.intellij.openapi.wm.ToolWindow tw = getToolWindow(p);
134 Content content = tw.getContentManager().findContent(PluginToolWindow.ToolWindowPanels.JIRA.toString());
135 if (content == null) {
136 return null;
137 }
138 return (JIRAToolWindowPanel) content.getComponent();
139 }
140
141
142 public static BambooTableToolWindowPanel getBambooToolWindowPanel(AnActionEvent event) {
143 Project p = getCurrentProject(event.getDataContext());
144 if (p == null) {
145 return null;
146 }
147
148 ToolWindow tw = getToolWindow(p);
149 Content content = tw.getContentManager().findContent(PluginToolWindow.ToolWindowPanels.BAMBOO.toString());
150 if (content == null) {
151 return null;
152 }
153 return (BambooTableToolWindowPanel) content.getComponent();
154 }
155
156 public static ThePluginProjectComponent getCurrentProjectComponent(AnActionEvent e) {
157 Project project = getCurrentProject(e.getDataContext());
158
159 if (project == null) {
160 return null;
161 } else {
162 return project.getComponent(ThePluginProjectComponent.class);
163 }
164 }
165
166 public static CrucibleTableToolWindowPanel getCrucibleToolWindowPanel(AnActionEvent e) {
167 Project p = getCurrentProject(e.getDataContext());
168 if (p == null) {
169 return null;
170 }
171
172 ToolWindow tw = getToolWindow(p);
173 Content content = tw.getContentManager().findContent(PluginToolWindow.ToolWindowPanels.CRUCIBLE.toString());
174 if (content == null) {
175 return null;
176 }
177 return (CrucibleTableToolWindowPanel) content.getComponent();
178 }
179
180 public static ReviewActionEventBroker getReviewActionEventBroker() {
181 return ReviewActionEventBroker.getInstance();
182 }
183 }