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.FileStatusCache; 25 import org.netbeans.modules.subversion.RepositoryFile; 26 import org.netbeans.modules.subversion.Subversion; 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.netbeans.modules.versioning.util.Utils; 33 import org.openide.ErrorManager; 34 import org.openide.nodes.Node; 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 SwitchToAction extends ContextAction { 44 45 48 public SwitchToAction() { 49 } 50 51 protected String getBaseName(Node[] activatedNodes) { 52 return "CTL_MenuItem_Switch"; } 54 55 protected int getFileEnabledStatus() { 56 return FileInformation.STATUS_MANAGED 57 & ~FileInformation.STATUS_NOTVERSIONED_EXCLUDED 58 & ~FileInformation.STATUS_NOTVERSIONED_NEWLOCALLY; 59 } 60 61 protected int getDirectoryEnabledStatus() { 62 return FileInformation.STATUS_MANAGED 63 & ~FileInformation.STATUS_NOTVERSIONED_EXCLUDED 64 & ~FileInformation.STATUS_NOTVERSIONED_NEWLOCALLY; 65 } 66 67 protected boolean enable(Node[] nodes) { 68 return nodes != null && nodes.length == 1 && getContext(nodes).getRoots().size() > 0; 69 } 70 71 protected void performContextAction(final Node[] nodes) { 72 Context ctx = getContext(nodes); 73 74 final File root = ctx.getRootFiles()[0]; 75 SVNUrl url = SvnUtils.getRepositoryRootUrl(root); 76 final RepositoryFile repositoryRoot = new RepositoryFile(url, url, SVNRevision.HEAD); 77 File [] files = Subversion.getInstance().getStatusCache().listFiles(ctx, FileInformation.STATUS_LOCAL_CHANGE); 78 boolean hasChanges = files.length > 0; 79 80 final SwitchTo switchTo = new SwitchTo(repositoryRoot, root, hasChanges); 81 if(switchTo.showDialog()) { 82 ContextAction.ProgressSupport support = new ContextAction.ProgressSupport(this, nodes) { 83 public void perform() { 84 RepositoryFile toRepositoryFile = switchTo.getRepositoryFile(); 85 performSwitch(toRepositoryFile, root, this); 86 } 87 }; 88 support.start(createRequestProcessor(nodes)); 89 } 90 } 91 92 static void performSwitch(RepositoryFile toRepositoryFile, File root, SvnProgressSupport support) { 93 File [][] split = Utils.splitFlatOthers(new File [] {root} ); 94 boolean recursive; 95 if(split[0].length > 0) { 97 recursive = false; 98 } else { 99 recursive = true; 100 } 101 102 try { 103 SvnClient client; 104 try { 105 client = Subversion.getInstance().getClient(toRepositoryFile.getRepositoryUrl()); 106 } catch (SVNClientException ex) { 107 ErrorManager.getDefault().notify(ex); 108 return; 109 } 110 client.switchToUrl(root, toRepositoryFile.getFileUrl(), toRepositoryFile.getRevision(), recursive); 112 refreshRecursively(root); Subversion.getInstance().refreshAllAnnotations(); 115 } catch (SVNClientException ex) { 116 support.annotate(ex); 117 } 118 } 119 120 private static void refreshRecursively(File file) { 121 Subversion.getInstance().getStatusCache().refresh(file, FileStatusCache.REPOSITORY_STATUS_UNKNOWN); 122 if(!file.isFile()) { 123 File [] files = file.listFiles(); 124 for (int i = 0; i < files.length; i++) { 125 refreshRecursively(files[i]); 126 } 127 } 128 } 129 } 130 | Popular Tags |