1 11 package org.eclipse.team.internal.ccvs.core.resources; 12 13 import java.util.ArrayList ; 14 15 import org.eclipse.core.runtime.IPath; 16 import org.eclipse.core.runtime.IProgressMonitor; 17 import org.eclipse.core.runtime.Path; 18 import org.eclipse.team.core.TeamException; 19 import org.eclipse.team.internal.ccvs.core.*; 20 import org.eclipse.team.internal.ccvs.core.client.Session; 21 import org.eclipse.team.internal.ccvs.core.client.Update; 22 import org.eclipse.team.internal.ccvs.core.connection.CVSRepositoryLocation; 23 24 27 public class RemoteFolderSandbox extends RemoteFolder { 28 29 public RemoteFolderSandbox(RemoteFolder parent, ICVSRepositoryLocation repository, String repositoryRelativePath, CVSTag tag) { 30 super(parent, repository, repositoryRelativePath, tag); 31 setChildren(new ICVSRemoteResource[0]); 32 } 33 34 public RemoteFolderSandbox(RemoteFolder parent, String name, CVSRepositoryLocation repository, String repositoryRelativePath, CVSEntryLineTag tag, boolean isStatic) { 35 super(parent, name, repository, repositoryRelativePath, tag, isStatic); 36 setChildren(new ICVSRemoteResource[0]); 37 } 38 39 42 public ICVSFile getFile(String name) throws CVSException { 43 try { 44 return super.getFile(name); 45 } catch (CVSException e) { 46 if (e.getStatus().getCode() == CHILD_DOES_NOT_EXIST) { 47 IPath path = new Path(null, name); 48 String fileName = path.lastSegment(); 49 RemoteFolderSandbox parent = getParentFolder(path); 50 RemoteFile file = new RemoteFile(parent, Update.STATE_NONE, fileName, null, null, getTag()); 51 parent.addChild(file); 52 return file; 53 } 54 throw e; 55 } 56 } 57 58 private void addChild(RemoteResource resource) { 59 ICVSRemoteResource[] children = getChildren(); 60 ICVSRemoteResource[] newChildren = new ICVSRemoteResource[children.length + 1]; 61 System.arraycopy(children, 0, newChildren, 0, children.length); 62 newChildren[children.length] = resource; 63 setChildren(newChildren); 64 } 65 66 private RemoteFolderSandbox getParentFolder(IPath path) throws CVSException { 67 IPath parentPath = path.removeLastSegments(1); 68 String parentString; 69 if (parentPath.isEmpty()) { 70 parentString = Session.CURRENT_LOCAL_FOLDER; 71 } else { 72 parentString = path.removeLastSegments(1).toString(); 73 } 74 RemoteFolderSandbox parent = (RemoteFolderSandbox)getFolder(parentString); 75 return parent; 76 } 77 78 81 public ICVSFolder getFolder(String name) throws CVSException { 82 try { 83 return super.getFolder(name); 84 } catch (CVSException e) { 85 if (e.getStatus().getCode() == CHILD_DOES_NOT_EXIST) { 86 IPath path = new Path(null, name); 87 RemoteFolderSandbox parent = getParentFolder(path); 88 String repoPath = new Path(null, parent.getRepositoryRelativePath()).append(path.lastSegment()).removeTrailingSeparator().toString(); 89 RemoteFolderSandbox folder = new RemoteFolderSandbox(parent, getRepository(), repoPath, getTag()); 90 parent.addChild(folder); 91 return folder; 92 } 93 throw e; 94 } 95 } 96 97 100 public ICVSRemoteResource[] getMembers(IProgressMonitor monitor) throws TeamException { 101 return getChildren(); 102 } 103 104 107 public void acceptChildren(ICVSResourceVisitor visitor) throws CVSException { 108 ICVSRemoteResource[] children = getChildren(); 109 if (children == null) return; 110 for (int i=0; i<children.length; i++) { 111 ((ICVSResource)children[i]).accept(visitor); 112 } 113 } 114 115 public void remove(RemoteFile file) { 116 ICVSRemoteResource[] children = getChildren(); 117 ArrayList results = new ArrayList (); 118 for (int i = 0; i < children.length; i++) { 119 if (children[i] != file){ 120 results.add(children[i]); 121 } 122 } 123 setChildren((ICVSRemoteResource[]) results.toArray(new ICVSRemoteResource[results.size()])); 124 } 125 } 126 | Popular Tags |