KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > refactoring > vcs > CheckoutFiles


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.refactoring.vcs;
21 import java.text.MessageFormat JavaDoc;
22 import java.util.Arrays JavaDoc;
23 import java.util.Collection JavaDoc;
24 import javax.swing.Action JavaDoc;
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 /**
35  *
36  * @author Jan Becicka
37  */

38 public class CheckoutFiles implements ProblemDetailsImplementation {
39     
40     private Collection JavaDoc files;
41     private Command editCmd;
42     private static String JavaDoc CHECKOUT_OPTION;
43     private static final String JavaDoc CANCEL_OPTION = NbBundle.getMessage(CheckoutFiles.class, "LBL_Cancel");
44     private Cancellable parent;
45     /** Creates a new instance of CheckoutFiles */
46     public CheckoutFiles(Collection JavaDoc files, Command editCmd) {
47         this.setFiles(files);
48         this.setEditCmd(editCmd);
49     }
50     
51     public void showDetails(Action JavaDoc rerunRefactoringAction, Cancellable parent) {
52         this.parent = parent;
53         CHECKOUT_OPTION = MessageFormat.format(NbBundle.getMessage(CheckoutFiles.class, "LBL_Checkout_And_Rerun"), new Object JavaDoc[]{rerunRefactoringAction.getValue(Action.NAME)});
54         DialogDescriptor desc = new DialogDescriptor(new CheckoutPanel(getFiles()), NbBundle.getMessage(CheckoutFiles.class, "LBL_Title_Update_Files"), true, new String JavaDoc[]{CHECKOUT_OPTION, CANCEL_OPTION}, CHECKOUT_OPTION, DialogDescriptor.DEFAULT_ALIGN, null, null);
55         Object JavaDoc retval = DialogDisplayer.getDefault().notify(desc);
56         if (retval == CHECKOUT_OPTION) {
57             checkoutFiles();
58             rerunRefactoring(rerunRefactoringAction);
59         }
60     }
61     
62     public String JavaDoc 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 JavaDoc iex) {
71             Thread.currentThread().interrupt();
72         }
73     }
74     
75     private void rerunRefactoring(Action JavaDoc rerunRefactoringAction) {
76         parent.cancel();
77         rerunRefactoringAction.actionPerformed(null);
78     }
79
80     void setFiles(Collection JavaDoc files) {
81         this.files = files;
82     }
83
84     void setEditCmd(Command editCmd) {
85         this.editCmd = editCmd;
86     }
87
88     public Collection JavaDoc getFiles() {
89         return files;
90     }
91
92     public Command getEditCmd() {
93         return editCmd;
94     }
95     
96     
97 }
98
Popular Tags