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.atlassian.theplugin.commons.crucible.CrucibleServerFacadeImpl;
20  import com.atlassian.theplugin.commons.crucible.api.model.PermId;
21  import com.atlassian.theplugin.idea.IdeaHelper;
22  import com.atlassian.theplugin.idea.crucible.CrucibleRevisionAddWorker;
23  import com.atlassian.theplugin.idea.crucible.ReviewData;
24  import com.intellij.openapi.actionSystem.AnActionEvent;
25  import com.intellij.openapi.actionSystem.DataKeys;
26  import com.intellij.openapi.application.ApplicationManager;
27  import com.intellij.openapi.application.ModalityState;
28  import com.intellij.openapi.vcs.changes.ChangeList;
29  import com.intellij.openapi.project.Project;
30  
31  public class AddRevisionToReviewAction extends Crucible16RepositoryAction {
32      public void actionPerformed(AnActionEvent event) {
33          final ChangeList[] changes = DataKeys.CHANGE_LISTS.getData(event.getDataContext());
34          final PermId permId = IdeaHelper.getCrucibleToolWindowPanel(event).getSelectedReviewId();
35  		final Project project = event.getData(DataKeys.PROJECT);
36  
37          new Thread(new Runnable() {
38              public void run() {
39                  ApplicationManager.getApplication().invokeAndWait(
40                          new CrucibleRevisionAddWorker(project, CrucibleServerFacadeImpl.getInstance(), permId, changes),
41                          ModalityState.defaultModalityState());
42              }
43          }).start();
44      }
45  
46      public void update(AnActionEvent event) {
47          super.update(event);
48          if (IdeaHelper.getCrucibleToolWindowPanel(event) != null) {
49              if (event.getPresentation().isEnabled()) {
50                  if (IdeaHelper.getCrucibleToolWindowPanel(event).getSelectedReview() == null) {
51                      event.getPresentation().setEnabled(false);
52                  } else {
53                      ReviewData rd = IdeaHelper.getCrucibleToolWindowPanel(event).getSelectedReview();
54                      event.getPresentation().setEnabled(
55                              rd.getCreator().getUserName().equals(rd.getServer().getUsername()));                    
56                  }
57              }
58          } else {
59              event.getPresentation().setEnabled(false);
60          }
61      }
62  }