1 11 package org.eclipse.team.ui.synchronize; 12 13 import java.util.ArrayList ; 14 import java.util.List ; 15 16 import org.eclipse.core.resources.IResource; 17 import org.eclipse.core.resources.ResourcesPlugin; 18 import org.eclipse.core.runtime.IPath; 19 import org.eclipse.core.runtime.Path; 20 import org.eclipse.team.internal.ui.Utils; 21 import org.eclipse.ui.IMemento; 22 23 30 public class ResourceScope extends AbstractSynchronizeScope { 31 32 35 private final static String CTX_ROOT = "resource_scope_roots"; private final static String CTX_ROOT_PATH = "resource_scope_root_resource"; 38 41 private IResource[] resources; 42 43 48 public ResourceScope(IResource[] resources) { 49 this.resources = resources; 50 } 51 52 57 protected ResourceScope(IMemento memento) { 58 super(memento); 59 } 60 61 66 public void setResources(IResource[] resources) { 67 this.resources = resources; 68 fireRootsChanges(); 69 } 70 71 74 public String getName() { 75 return Utils.convertSelection(resources); 76 } 77 78 81 public IResource[] getRoots() { 82 return resources; 83 } 84 85 88 public void dispose() { 89 } 91 92 95 public void saveState(IMemento memento) { 96 if (resources != null) { 97 for (int i = 0; i < resources.length; i++) { 98 IResource resource = resources[i]; 99 IMemento rootNode = memento.createChild(CTX_ROOT); 100 rootNode.putString(CTX_ROOT_PATH, resource.getFullPath().toString()); 101 } 102 } 103 } 104 105 108 protected void init(IMemento memento) { 109 IMemento[] rootNodes = memento.getChildren(CTX_ROOT); 110 if(rootNodes != null) { 111 List resources = new ArrayList (); 112 for (int i = 0; i < rootNodes.length; i++) { 113 IMemento rootNode = rootNodes[i]; 114 IPath path = new Path(rootNode.getString(CTX_ROOT_PATH)); 115 IResource resource = ResourcesPlugin.getWorkspace().getRoot().findMember(path, true ); 116 if(resource != null) { 117 resources.add(resource); 118 } 119 } 120 this.resources = (IResource[]) resources.toArray(new IResource[resources.size()]); 121 } 122 } 123 } 124 | Popular Tags |