1 package com.atlassian.theplugin.idea.action.crucible; 2 3 import com.intellij.openapi.actionSystem.AnAction; 4 import com.intellij.openapi.actionSystem.AnActionEvent; 5 import com.intellij.openapi.actionSystem.DataKeys; 6 import com.intellij.openapi.vcs.changes.ChangeList; 7 import com.intellij.openapi.application.ApplicationManager; 8 import com.intellij.openapi.application.ModalityState; 9 import com.intellij.openapi.project.Project; 10 import com.atlassian.theplugin.idea.crucible.CruciblePatchAddWorker; 11 import com.atlassian.theplugin.idea.IdeaHelper; 12 import com.atlassian.theplugin.commons.crucible.CrucibleServerFacadeImpl; 13 import com.atlassian.theplugin.commons.crucible.api.model.PermId; 14 15 public class AddPatchToReviewAction extends AnAction { 16 17 public void actionPerformed(AnActionEvent event) { 18 final ChangeList[] changes = DataKeys.CHANGE_LISTS.getData(event.getDataContext()); 19 final Project project = DataKeys.PROJECT.getData(event.getDataContext()); 20 final PermId permId = IdeaHelper.getCrucibleToolWindowPanel(event).getSelectedReviewId(); 21 22 new Thread(new Runnable() { 23 public void run() { 24 ApplicationManager.getApplication().invokeAndWait( 25 new CruciblePatchAddWorker(CrucibleServerFacadeImpl.getInstance(), permId, project, changes), 26 ModalityState.defaultModalityState()); 27 } 28 }).start(); 29 } 30 31 public void update(AnActionEvent event) { 32 super.update(event); 33 final ChangeList[] changes = DataKeys.CHANGE_LISTS.getData(event.getDataContext()); 34 if (changes != null && changes.length == 1) { 35 event.getPresentation().setEnabled(true); 36 } else { 37 event.getPresentation().setEnabled(false); 38 } 39 } 40 }