1 19 20 package org.netbeans.modules.refactoring.vcs; 21 import java.text.MessageFormat ; 22 import java.util.Arrays ; 23 import java.util.Collection ; 24 import javax.swing.Action ; 25 import org.netbeans.api.vcs.commands.Command; 26 import org.netbeans.api.vcs.commands.CommandTask; 27 import org.netbeans.modules.refactoring.spi.ProblemDetailsImplementation; 28 import org.openide.DialogDescriptor; 29 import org.openide.DialogDisplayer; 30 import org.openide.filesystems.FileObject; 31 import org.openide.util.Cancellable; 32 import org.openide.util.NbBundle; 33 34 38 public class CheckoutFiles implements ProblemDetailsImplementation { 39 40 private Collection files; 41 private Command editCmd; 42 private static String CHECKOUT_OPTION; 43 private static final String CANCEL_OPTION = NbBundle.getMessage(CheckoutFiles.class, "LBL_Cancel"); 44 private Cancellable parent; 45 46 public CheckoutFiles(Collection files, Command editCmd) { 47 this.setFiles(files); 48 this.setEditCmd(editCmd); 49 } 50 51 public void showDetails(Action rerunRefactoringAction, Cancellable parent) { 52 this.parent = parent; 53 CHECKOUT_OPTION = MessageFormat.format(NbBundle.getMessage(CheckoutFiles.class, "LBL_Checkout_And_Rerun"), new Object []{rerunRefactoringAction.getValue(Action.NAME)}); 54 DialogDescriptor desc = new DialogDescriptor(new CheckoutPanel(getFiles()), NbBundle.getMessage(CheckoutFiles.class, "LBL_Title_Update_Files"), true, new String []{CHECKOUT_OPTION, CANCEL_OPTION}, CHECKOUT_OPTION, DialogDescriptor.DEFAULT_ALIGN, null, null); 55 Object retval = DialogDisplayer.getDefault().notify(desc); 56 if (retval == CHECKOUT_OPTION) { 57 checkoutFiles(); 58 rerunRefactoring(rerunRefactoringAction); 59 } 60 } 61 62 public String getDetailsHint() { 63 return NbBundle.getMessage(CheckoutFiles.class, "LBL_Update_Files"); 64 } 65 66 private void checkoutFiles() { 67 CommandTask task = getEditCmd().execute(); 68 try { 69 task.waitFinished(0); 70 } catch (InterruptedException iex) { 71 Thread.currentThread().interrupt(); 72 } 73 } 74 75 private void rerunRefactoring(Action rerunRefactoringAction) { 76 parent.cancel(); 77 rerunRefactoringAction.actionPerformed(null); 78 } 79 80 void setFiles(Collection files) { 81 this.files = files; 82 } 83 84 void setEditCmd(Command editCmd) { 85 this.editCmd = editCmd; 86 } 87 88 public Collection getFiles() { 89 return files; 90 } 91 92 public Command getEditCmd() { 93 return editCmd; 94 } 95 96 97 } 98 | Popular Tags |