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.crucible;
18  
19  import com.intellij.openapi.actionSystem.AnAction;
20  import com.intellij.openapi.actionSystem.AnActionEvent;
21  import com.intellij.openapi.actionSystem.DataKeys;
22  import com.intellij.openapi.vcs.changes.ChangeList;
23  import com.intellij.openapi.project.Project;
24  import com.atlassian.theplugin.idea.crucible.CruciblePatchSubmitCommitSession;
25  import com.atlassian.theplugin.commons.crucible.CrucibleServerFacadeImpl;
26  
27  public class PreCommitReview extends AnAction {
28  
29      public void actionPerformed(AnActionEvent event) {
30          final ChangeList[] changes = DataKeys.CHANGE_LISTS.getData(event.getDataContext());
31          final Project project = DataKeys.PROJECT.getData(event.getDataContext());
32  
33          new Thread(new Runnable() {
34              public void run() {
35                  new CruciblePatchSubmitCommitSession(project, CrucibleServerFacadeImpl.getInstance()).execute(
36                          changes[0].getChanges(), changes[0].getName());
37              }
38          }).start();
39      }
40  
41      public void update(AnActionEvent event) {
42          super.update(event);
43          final ChangeList[] changes = DataKeys.CHANGE_LISTS.getData(event.getDataContext());
44          if (changes != null && changes.length == 1) {
45              event.getPresentation().setEnabled(true);
46          } else {
47              event.getPresentation().setEnabled(false);
48          }
49      }
50  }
51