1 11 package org.eclipse.core.resources.team; 12 13 import java.util.HashSet ; 14 import org.eclipse.core.resources.*; 15 import org.eclipse.core.runtime.IPath; 16 import org.eclipse.core.runtime.jobs.ISchedulingRule; 17 import org.eclipse.core.runtime.jobs.MultiRule; 18 19 27 public class ResourceRuleFactory implements IResourceRuleFactory { 28 private final IWorkspace workspace = ResourcesPlugin.getWorkspace(); 29 30 34 protected ResourceRuleFactory() { 35 super(); 36 } 37 38 46 public final ISchedulingRule buildRule() { 47 return workspace.getRoot(); 48 } 49 50 64 public ISchedulingRule charsetRule(IResource resource) { 65 if (resource.getType() == IResource.ROOT) 66 return null; 67 return resource.getProject(); 68 } 69 70 81 public ISchedulingRule copyRule(IResource source, IResource destination) { 82 return parent(destination); 84 } 85 86 97 public ISchedulingRule createRule(IResource resource) { 98 return parent(resource); 99 } 100 101 112 public ISchedulingRule deleteRule(IResource resource) { 113 return parent(resource); 114 } 115 116 private boolean isReadOnly(IResource resource) { 117 ResourceAttributes attributes = resource.getResourceAttributes(); 118 return attributes == null ? false : attributes.isReadOnly(); 119 } 120 121 129 public final ISchedulingRule markerRule(IResource resource) { 130 return null; 131 } 132 133 147 public ISchedulingRule modifyRule(IResource resource) { 148 if (resource.getType() == IResource.PROJECT) 150 return workspace.getRoot(); 151 IPath path = resource.getFullPath(); 152 if (path.segmentCount() == 2 && path.segment(1).equals(IProjectDescription.DESCRIPTION_FILE_NAME)) 154 return parent(resource); 155 return resource; 156 } 157 158 169 public ISchedulingRule moveRule(IResource source, IResource destination) { 170 return MultiRule.combine(parent(source), parent(destination)); 172 } 173 174 181 protected final ISchedulingRule parent(IResource resource) { 182 switch (resource.getType()) { 183 case IResource.ROOT : 184 case IResource.PROJECT : 185 return resource; 186 default : 187 return resource.getParent(); 188 } 189 } 190 191 202 public ISchedulingRule refreshRule(IResource resource) { 203 return parent(resource); 204 } 205 206 218 public ISchedulingRule validateEditRule(IResource[] resources) { 219 if (resources.length == 0) 220 return null; 221 if (resources.length == 1) 223 return isReadOnly(resources[0]) ? parent(resources[0]) : null; 224 HashSet rules = new HashSet (); 226 for (int i = 0; i < resources.length; i++) 227 if (isReadOnly(resources[i])) 228 rules.add(parent(resources[i])); 229 if (rules.isEmpty()) 230 return null; 231 if (rules.size() == 1) 232 return (ISchedulingRule) rules.iterator().next(); 233 ISchedulingRule[] ruleArray = (ISchedulingRule[]) rules.toArray(new ISchedulingRule[rules.size()]); 234 return new MultiRule(ruleArray); 235 } 236 } 237 | Popular Tags |