2
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
4
* Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
6
* The contents of this file are subject to the terms of either the GNU
7
* General Public License Version 2 only ("GPL") or the Common
8
* Development and Distribution License("CDDL") (collectively, the
9
* "License"). You may not use this file except in compliance with the
10
* License. You can obtain a copy of the License at
11
* http://www.netbeans.org/cddl-gplv2.html
12
* or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
* specific language governing permissions and limitations under the
14
* License. When distributing the software, include this License Header
15
* Notice in each file and include the License file at
16
* nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
17
* particular file as subject to the "Classpath" exception as provided
18
* by Sun in the GPL Version 2 section of the License file that
19
* accompanied this code. If applicable, add the following below the
20
* License Header, with the fields enclosed by brackets [] replaced by
21
* your own identifying information:
22
* "Portions Copyrighted [year] [name of copyright owner]"
26
* The Original Software is NetBeans. The Initial Developer of the Original
27
* Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
28
* Microsystems, Inc. All Rights Reserved.
30
* If you wish your version of this file to be governed by only the CDDL
31
* or only the GPL Version 2, indicate your decision by adding
32
* "[Contributor] elects to include this software in this distribution
33
* under the [CDDL or GPL Version 2] license." If you do not indicate a
34
* single choice of license, a recipient has the option to distribute
35
* your version of this file under either the CDDL, the GPL Version 2 or
36
* to extend the choice of license to its licensees as provided above.
37
* However, if you add GPL Version 2 code and therefore, elected the GPL
38
* Version 2 license, then the option applies only if the new code is
39
* made subject to such option by the copyright holder.
42
package org.netbeans.modules.subversion.ui.copy;
45
import org.netbeans.modules.subversion.FileInformation;
46
import org.netbeans.modules.subversion.RepositoryFile;
47
import org.netbeans.modules.subversion.Subversion;
48
import org.netbeans.modules.subversion.client.SvnClient;
49
import org.netbeans.modules.subversion.client.SvnClientExceptionHandler;
50
import org.netbeans.modules.subversion.client.SvnProgressSupport;
51
import org.netbeans.modules.subversion.ui.actions.ContextAction;
52
import org.netbeans.modules.subversion.util.Context;
53
import org.netbeans.modules.subversion.util.SvnUtils;
54
import org.openide.nodes.Node;
55
import org.tigris.subversion.svnclientadapter.ISVNInfo;
56
import org.tigris.subversion.svnclientadapter.SVNClientException;
57
import org.tigris.subversion.svnclientadapter.SVNRevision;
58
import org.tigris.subversion.svnclientadapter.SVNUrl;
62
* @author Tomas Stupka
64
public class CreateCopyAction extends ContextAction {
66
/** Creates a new instance of CreateCopyAction */
67
public CreateCopyAction() {
71
protected String getBaseName(Node[] activatedNodes) {
72
return "CTL_MenuItem_Copy"; // NOI18N
75
protected int getFileEnabledStatus() {
76
return FileInformation.STATUS_MANAGED
77
& ~FileInformation.STATUS_NOTVERSIONED_EXCLUDED;
80
protected int getDirectoryEnabledStatus() {
81
return FileInformation.STATUS_MANAGED
82
& ~FileInformation.STATUS_NOTVERSIONED_EXCLUDED
83
& ~FileInformation.STATUS_NOTVERSIONED_NEWLOCALLY;
86
protected boolean enable(Node[] nodes) {
87
return nodes != null && nodes.length == 1 && getContext(nodes).getRoots().size() > 0;
90
protected void performContextAction(final Node[] nodes) {
92
if(!Subversion.getInstance().checkClientAvailable()) {
96
Context ctx = getContext(nodes);
98
final File root = ctx.getRootFiles()[0];
99
File[] files = Subversion.getInstance().getStatusCache().listFiles(ctx, FileInformation.STATUS_LOCAL_CHANGE);
101
final boolean hasChanges = files.length > 0;
102
final SVNUrl repositoryUrl;
103
final SVNUrl fileUrl;
105
repositoryUrl = SvnUtils.getRepositoryRootUrl(root);
106
fileUrl = SvnUtils.getRepositoryUrl(root);
107
} catch (SVNClientException ex) {
108
SvnClientExceptionHandler.notifyException(ex, true, true);
111
final RepositoryFile repositoryFile = new RepositoryFile(repositoryUrl, fileUrl, SVNRevision.HEAD);
113
final CreateCopy createCopy = new CreateCopy(repositoryFile, root, hasChanges);
115
if(createCopy.showDialog()) {
116
// XXX don't close dialog if error occures!
117
ContextAction.ProgressSupport support = new ContextAction.ProgressSupport(this, nodes) {
118
public void perform() {
119
performCopy(createCopy, this);
122
support.start(createRequestProcessor(nodes));
126
private void performCopy(CreateCopy createCopy, SvnProgressSupport support) {
127
RepositoryFile toRepositoryFile = createCopy.getToRepositoryFile();
132
client = Subversion.getInstance().getClient(toRepositoryFile.getRepositoryUrl());
133
} catch (SVNClientException ex) {
134
SvnClientExceptionHandler.notifyException(ex, true, true);
138
if(!toRepositoryFile.isRepositoryRoot()) {
139
SVNUrl folderToCreate = toRepositoryFile.removeLastSegment().getFileUrl();
140
ISVNInfo info = null;
142
info = client.getInfo(folderToCreate);
143
} catch (SVNClientException ex) {
144
if(!SvnClientExceptionHandler.isWrongUrl(ex.getMessage())) {
149
if(support.isCanceled()) {
154
client.mkdir(folderToCreate,
156
"[Netbeans SVN client generated message: create a new folder for the copy]: '\n" + createCopy.getMessage() + "\n'"); // NOI18N
158
if(createCopy.getLocalFile().isFile()) {
159
// we are copying a file to a destination which already exists. Even if it's a folder - we don't use the exactly same
160
// as the commandline svn client:
161
// - the remote file specified in the GUI has to be exactly the file which has to be created at the repository.
162
// - if the destination is an existent folder the file won't be copied into it, as the svn client would do.
163
throw new SVNClientException("File allready exists");
165
// XXX warnig: do you realy want to? could be already a project folder!
170
if(support.isCanceled()) {
174
if(createCopy.isLocal()) {
175
client.copy(createCopy.getLocalFile(),
176
toRepositoryFile.getFileUrl(),
177
createCopy.getMessage());
179
RepositoryFile fromRepositoryFile = createCopy.getFromRepositoryFile();
180
client.copy(fromRepositoryFile.getFileUrl(),
181
toRepositoryFile.getFileUrl(),
182
createCopy.getMessage(),
183
fromRepositoryFile.getRevision());
186
if(support.isCanceled()) {
190
if(createCopy.switchTo()) {
191
SwitchToAction.performSwitch(toRepositoryFile, createCopy.getLocalFile(), support);
194
} catch (SVNClientException ex) {
195
support.annotate(ex);