1 19 20 package org.netbeans.modules.subversion.ui.copy; 21 22 import java.io.File ; 23 import org.netbeans.modules.subversion.FileInformation; 24 import org.netbeans.modules.subversion.RepositoryFile; 25 import org.netbeans.modules.subversion.Subversion; 26 import org.netbeans.modules.subversion.client.ExceptionHandler; 27 import org.netbeans.modules.subversion.client.SvnClient; 28 import org.netbeans.modules.subversion.client.SvnProgressSupport; 29 import org.netbeans.modules.subversion.ui.actions.ContextAction; 30 import org.netbeans.modules.subversion.util.Context; 31 import org.netbeans.modules.subversion.util.SvnUtils; 32 import org.openide.ErrorManager; 33 import org.openide.nodes.Node; 34 import org.tigris.subversion.svnclientadapter.ISVNInfo; 35 import org.tigris.subversion.svnclientadapter.SVNClientException; 36 import org.tigris.subversion.svnclientadapter.SVNRevision; 37 import org.tigris.subversion.svnclientadapter.SVNUrl; 38 39 43 public class CreateCopyAction extends ContextAction { 44 45 46 public CreateCopyAction() { 47 48 } 49 50 protected String getBaseName(Node[] activatedNodes) { 51 return "CTL_MenuItem_Copy"; } 53 54 protected int getFileEnabledStatus() { 55 return FileInformation.STATUS_MANAGED 56 & ~FileInformation.STATUS_NOTVERSIONED_EXCLUDED; 57 } 58 59 protected int getDirectoryEnabledStatus() { 60 return FileInformation.STATUS_MANAGED 61 & ~FileInformation.STATUS_NOTVERSIONED_EXCLUDED 62 & ~FileInformation.STATUS_NOTVERSIONED_NEWLOCALLY; 63 } 64 65 protected void performContextAction(final Node[] nodes) { 66 Context ctx = getContext(nodes); 67 68 final File root = ctx.getRootFiles()[0]; 69 File [] files = Subversion.getInstance().getStatusCache().listFiles(ctx, FileInformation.STATUS_LOCAL_CHANGE); 70 71 final boolean hasChanges = files.length > 0; 72 final SVNUrl repositoryUrl = SvnUtils.getRepositoryRootUrl(root); 73 final SVNUrl fileUrl = SvnUtils.getRepositoryUrl(root); 74 final RepositoryFile repositoryFile = new RepositoryFile(repositoryUrl, fileUrl, SVNRevision.HEAD); 75 76 final CreateCopy createCopy = new CreateCopy(repositoryFile, root, hasChanges); 77 78 if(createCopy.showDialog()) { 79 ContextAction.ProgressSupport support = new ContextAction.ProgressSupport(this, nodes) { 81 public void perform() { 82 performCopy(createCopy, this); 83 } 84 }; 85 support.start(createRequestProcessor(nodes)); 86 } 87 } 88 89 private void performCopy(CreateCopy createCopy, SvnProgressSupport support) { 90 RepositoryFile toRepositoryFile = createCopy.getToRepositoryFile(); 91 92 try { 93 SvnClient client; 94 try { 95 client = Subversion.getInstance().getClient(toRepositoryFile.getRepositoryUrl()); 96 } catch (SVNClientException ex) { 97 ErrorManager.getDefault().notify(ex); 98 return; 99 } 100 101 if(!toRepositoryFile.isRepositoryRoot()) { 102 SVNUrl folderToCreate = toRepositoryFile.removeLastSegment().getFileUrl(); 103 ISVNInfo info = null; 104 try{ 105 info = client.getInfo(folderToCreate); 106 } catch (SVNClientException ex) { 107 if(!ExceptionHandler.isWrongUrl(ex.getMessage())) { 108 throw ex; 109 } 110 } 111 112 if(support.isCanceled()) { 113 return; 114 } 115 116 if(info == null) { 117 client.mkdir(folderToCreate, 118 true, 119 "[Netbeans SVN client generated message: create a new folder for the copy]: '\n" + createCopy.getMessage() + "\n'"); } else { 121 if(createCopy.getLocalFile().isFile()) { 122 throw new SVNClientException("File allready exists"); 127 } else { 128 } 130 } 131 } 132 133 if(support.isCanceled()) { 134 return; 135 } 136 137 if(createCopy.isLocal()) { 138 client.copy(createCopy.getLocalFile(), 139 toRepositoryFile.getFileUrl(), 140 createCopy.getMessage()); 141 } else { 142 RepositoryFile fromRepositoryFile = createCopy.getFromRepositoryFile(); 143 client.copy(fromRepositoryFile.getFileUrl(), 144 toRepositoryFile.getFileUrl(), 145 createCopy.getMessage(), 146 fromRepositoryFile.getRevision()); 147 } 148 149 if(support.isCanceled()) { 150 return; 151 } 152 153 if(createCopy.switchTo()) { 154 SwitchToAction.performSwitch(toRepositoryFile, createCopy.getLocalFile(), support); 155 } 156 157 } catch (SVNClientException ex) { 158 support.annotate(ex); 159 } 160 } 161 } 162 | Popular Tags |