KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > subversion > ui > checkout > CheckoutAction


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 package org.netbeans.modules.subversion.ui.checkout;
20
21 import java.io.File JavaDoc;
22 import org.netbeans.modules.subversion.RepositoryFile;
23 import org.netbeans.modules.subversion.Subversion;
24 import org.netbeans.modules.subversion.SvnModuleConfig;
25 import org.netbeans.modules.subversion.client.SvnProgressSupport;
26 import org.netbeans.modules.subversion.client.SvnClient;
27 import org.netbeans.modules.subversion.ui.wizards.*;
28 import org.openide.ErrorManager;
29 import org.openide.filesystems.FileUtil;
30 import org.openide.util.HelpCtx;
31 import org.openide.util.NbBundle;
32 import org.openide.util.actions.CallableSystemAction;
33 import org.tigris.subversion.svnclientadapter.SVNClientException;
34 import org.tigris.subversion.svnclientadapter.SVNUrl;
35
36 /**
37  *
38  * @author Tomas Stupka
39  */

40 public final class CheckoutAction extends CallableSystemAction {
41            
42     public void performAction() {
43         CheckoutWizard wizard = new CheckoutWizard();
44         if (!wizard.show()) return;
45         
46         final SVNUrl repository = wizard.getRepositoryRoot();
47         final RepositoryFile[] repositoryFiles = wizard.getRepositoryFiles();
48         final File JavaDoc file = wizard.getWorkdir();
49         final boolean atWorkingDirLevel = wizard.isAtWorkingDirLevel();
50         
51         SvnProgressSupport support = new SvnProgressSupport() {
52             public void perform() {
53                 final SvnClient client;
54                 try {
55                     client = Subversion.getInstance().getClient(repository);
56                 } catch (SVNClientException ex) {
57                     ErrorManager.getDefault().notify(ex); // should not happen
58
return;
59                 }
60         
61                 try {
62                     setDisplayName(java.util.ResourceBundle.getBundle("org/netbeans/modules/subversion/ui/checkout/Bundle").getString("LBL_Checkout_Progress"));
63                     checkout(client, repository, repositoryFiles, file, atWorkingDirLevel, this);
64                 } catch (SVNClientException ex) {
65                     annotate(ex);
66                     return;
67                 }
68                 if(isCanceled()) {
69                     return;
70                 }
71                 
72                 setDisplayName(java.util.ResourceBundle.getBundle("org/netbeans/modules/subversion/ui/checkout/Bundle").getString("LBL_ScanFolders_Progress"));
73                 if (SvnModuleConfig.getDefault().getShowCheckoutCompleted()) {
74                     String JavaDoc[] folders;
75                     if(atWorkingDirLevel) {
76                         folders = new String JavaDoc[1];
77                         folders[0] = "."; // NOI18N
78
} else {
79                         folders = new String JavaDoc[repositoryFiles.length];
80                         for (int i = 0; i < repositoryFiles.length; i++) {
81                             if(isCanceled()) {
82                                 return;
83                             }
84                             if(repositoryFiles[i].isRepositoryRoot()) {
85                                 folders[i] = "."; // NOI18N
86
} else {
87                                 folders[i] = repositoryFiles[i].getFileUrl().getLastPathSegment();
88                             }
89                         }
90                     }
91                     CheckoutCompleted cc = new CheckoutCompleted(file, folders, true);
92                     if(isCanceled()) {
93                         return;
94                     }
95                     cc.scanForProjects(this);
96                 }
97             }
98         };
99         support.start(Subversion.getInstance().getRequestProcessor(repository), repository, java.util.ResourceBundle.getBundle("org/netbeans/modules/subversion/ui/checkout/Bundle").getString("LBL_Checkout_Progress"));
100
101     }
102     
103     public String JavaDoc getName() {
104         return NbBundle.getMessage(CheckoutAction.class, "CTL_CheckoutAction"); // NOI18N
105
}
106     
107     protected void initialize() {
108         super.initialize();
109         putValue("noIconInMenu", Boolean.TRUE); // NOI18N
110
}
111     
112     public HelpCtx getHelpCtx() {
113         return HelpCtx.DEFAULT_HELP;
114     }
115     
116     protected boolean asynchronous() {
117         return false;
118     }
119
120     public static void checkout(final SvnClient client,
121                                 final SVNUrl repository,
122                                 final RepositoryFile[] repositoryFiles,
123                                 final File JavaDoc workingDir,
124                                 final boolean atWorkingDirLevel,
125                                 final SvnProgressSupport support)
126     throws SVNClientException
127     {
128         for (int i = 0; i < repositoryFiles.length; i++) {
129             File JavaDoc destination;
130             if(!atWorkingDirLevel) {
131                 destination = new File JavaDoc(workingDir.getAbsolutePath() +
132                                        "/" + // NOI18N
133
repositoryFiles[i].getName()); // XXX what if the whole repository is seletcted
134
destination = FileUtil.normalizeFile(destination);
135                 destination.mkdir();
136             } else {
137                 destination = workingDir;
138             }
139             if(support!=null && support.isCanceled()) {
140                 return;
141             }
142             client.checkout(repositoryFiles[i].getFileUrl(), destination, repositoryFiles[i].getRevision(), true);
143             if(support!=null && support.isCanceled()) {
144                 return;
145             }
146         }
147     }
148
149 }
150
Popular Tags