1 11 package org.eclipse.team.internal.ccvs.ui.operations; 12 13 import java.util.ArrayList ; 14 import java.util.List ; 15 import org.eclipse.core.runtime.IProgressMonitor; 16 import org.eclipse.core.runtime.IStatus; 17 import org.eclipse.osgi.util.NLS; 18 import org.eclipse.team.core.TeamException; 19 import org.eclipse.team.internal.ccvs.core.*; 20 import org.eclipse.team.internal.ccvs.core.resources.RemoteFolder; 21 import org.eclipse.team.internal.ccvs.core.resources.RemoteFolderMemberFetcher; 22 import org.eclipse.team.internal.ccvs.ui.*; 23 import org.eclipse.team.internal.ccvs.ui.CVSUIPlugin; 24 import org.eclipse.team.internal.ccvs.ui.Policy; 25 import org.eclipse.ui.IWorkbenchPart; 26 import org.eclipse.ui.progress.IElementCollector; 27 28 32 public class FetchMembersOperation extends RemoteOperation { 33 34 IElementCollector collector; 35 RemoteFolderFilter filter = new RemoteFolderFilter(); 36 37 public static class RemoteFolderFilter { 38 public ICVSRemoteResource[] filter(ICVSRemoteResource[] resource) { 39 return resource; 40 } 41 } 42 43 public class InternalRemoteFolderMemberFetcher extends RemoteFolderMemberFetcher { 44 long sendIncrement = 100; 45 List unsent = new ArrayList (); 46 long intervalStart; 47 protected InternalRemoteFolderMemberFetcher(RemoteFolder parentFolder, CVSTag tag) { 48 super(parentFolder, tag); 49 } 50 protected void parentDoesNotExist() { 51 super.parentDoesNotExist(); 52 collector.add(new Object [0], getProgressMonitor()); 54 } 55 protected RemoteFolder recordFolder(String name) { 56 RemoteFolder folder = super.recordFolder(name); 57 unsent.add(folder); 58 if (isTimeToSend()) { 59 sendFolders(); 60 } 61 return folder; 62 } 63 private boolean isTimeToSend() { 64 long currentTime = System.currentTimeMillis(); 65 return ((currentTime - intervalStart) > sendIncrement) || unsent.size() > sendIncrement; 66 } 67 protected IStatus performUpdate(IProgressMonitor progress, CVSTag tag) throws CVSException { 68 intervalStart = System.currentTimeMillis(); 69 IStatus status = super.performUpdate(progress, tag); 70 sendFolders(); 71 return status; 72 } 73 protected void updateFileRevisions(ICVSFile[] files, IProgressMonitor monitor) throws CVSException { 74 super.updateFileRevisions(files, monitor); 75 sendFiles(); 76 } 77 private void sendFolders() { 78 updateParentFolderChildren(); 79 collector.add(filter.filter((ICVSRemoteFolder[]) unsent.toArray(new ICVSRemoteFolder[unsent.size()])), getProgressMonitor()); 80 unsent.clear(); 81 intervalStart = System.currentTimeMillis(); 82 } 83 private void sendFiles() { 84 collector.add(getFiles(), getProgressMonitor()); 85 unsent.clear(); 86 } 87 private IProgressMonitor getProgressMonitor() { 88 return null; 89 } 90 } 91 92 public FetchMembersOperation(IWorkbenchPart part, ICVSRemoteFolder folder, IElementCollector collector) { 93 super(part, new ICVSRemoteResource[] { folder }); 94 this.collector = collector; 95 } 96 97 100 protected void execute(IProgressMonitor monitor) throws CVSException, InterruptedException { 101 ICVSRemoteFolder remote = getRemoteFolder(); 102 if (remote.getClass().equals(RemoteFolder.class)) { 103 monitor = Policy.monitorFor(monitor); 104 boolean isRoot = remote.getName().equals(ICVSRemoteFolder.REPOSITORY_ROOT_FOLDER_NAME); 105 monitor.beginTask(null, 100 + (isRoot ? 30 : 0)); 106 RemoteFolderMemberFetcher fetcher = new InternalRemoteFolderMemberFetcher((RemoteFolder)remote, remote.getTag()); 107 fetcher.fetchMembers(Policy.subMonitorFor(monitor, 100)); 108 if (isRoot) { 109 ICVSRemoteResource[] modules = CVSUIPlugin.getPlugin() 110 .getRepositoryManager() 111 .getRepositoryRootFor(remote.getRepository()) 112 .getDefinedModules(remote.getTag(), Policy.subMonitorFor(monitor, 25)); 113 collector.add(filter.filter(modules), Policy.subMonitorFor(monitor, 5)); 114 } 115 } else { 116 monitor = Policy.monitorFor(monitor); 117 try { 118 monitor.beginTask(null, 100); 119 ICVSRemoteResource[] children = remote.members(Policy.subMonitorFor(monitor, 95)); 120 collector.add(children, Policy.subMonitorFor(monitor, 5)); 121 } catch (TeamException e) { 122 throw CVSException.wrapException(e); 123 } finally { 124 monitor.done(); 125 } 126 } 127 128 } 129 130 133 protected String getTaskName() { 134 return NLS.bind(CVSUIMessages.FetchMembersOperation_0, new String [] { getRemoteFolder().getName() }); 135 } 136 137 private ICVSRemoteFolder getRemoteFolder() { 138 return (ICVSRemoteFolder)getRemoteResources()[0]; 139 } 140 141 public void setFilter(RemoteFolderFilter filter) { 142 this.filter = filter; 143 } 144 145 } 146 | Popular Tags |