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.bamboo;
18  
19  import com.atlassian.theplugin.commons.bamboo.BambooStatusChecker;
20  import com.atlassian.theplugin.commons.util.Logger;
21  import com.atlassian.theplugin.idea.IdeaHelper;
22  import com.atlassian.theplugin.idea.ProgressAnimationProvider;
23  import com.atlassian.theplugin.idea.ThePluginProjectComponent;
24  import com.atlassian.theplugin.util.PluginUtil;
25  import com.intellij.openapi.actionSystem.AnAction;
26  import com.intellij.openapi.actionSystem.AnActionEvent;
27  
28  public class RefreshBambooPanelAction extends AnAction {
29  
30  	@Override
31  	public void actionPerformed(final AnActionEvent e) {
32  		final ThePluginProjectComponent currentProject = IdeaHelper.getCurrentProjectComponent(e);
33  		if (currentProject == null) {
34  			return;
35  		}
36  
37  		final BambooStatusChecker checker = currentProject.getBambooStatusChecker();
38  
39  		if (checker.canSchedule()) {
40  
41  			final ProgressAnimationProvider animator =
42  					IdeaHelper.getBambooToolWindowPanel(e).getProgressAnimation();
43  
44  			final Logger log = PluginUtil.getLogger();
45  
46  			new Thread(new Runnable() {
47  				public void run() {
48  
49  					Thread t = new Thread(checker.newTimerTask(), "Manual Bamboo panel refresh (checker)");
50  
51  					animator.startProgressAnimation();
52  
53  					t.start();
54  					try {
55  						t.join();
56  					} catch (InterruptedException e) {
57  						log.warn(e.toString());
58  					} finally {
59  						animator.stopProgressAnimation();
60  					}
61  
62  
63  				}
64  			}, "Manual Bamboo panel refresh").start();
65  
66  		}
67  	}
68  }