1 11 12 package org.eclipse.jdt.internal.ui.packageview; 13 14 import org.eclipse.core.runtime.Assert; 15 import org.eclipse.core.runtime.CoreException; 16 import org.eclipse.core.runtime.IProgressMonitor; 17 18 import org.eclipse.core.resources.IProject; 19 import org.eclipse.core.resources.IResource; 20 import org.eclipse.core.resources.mapping.ResourceMappingContext; 21 import org.eclipse.core.resources.mapping.ResourceTraversal; 22 23 import org.eclipse.jface.viewers.IDecorationContext; 24 25 import org.eclipse.team.ui.mapping.SynchronizationStateTester; 26 27 import org.eclipse.jdt.core.IJavaElement; 28 import org.eclipse.jdt.core.IPackageFragment; 29 30 import org.eclipse.jdt.internal.corext.util.JavaElementResourceMapping; 31 32 public class HierarchicalDecorationContext implements IDecorationContext { 33 34 private HierarchicalSynchronizationStateTester fStateTester; 35 public static final HierarchicalDecorationContext CONTEXT= new HierarchicalDecorationContext(); 36 37 private HierarchicalDecorationContext() { 38 fStateTester= new HierarchicalSynchronizationStateTester(); 39 } 40 41 44 public String [] getProperties() { 45 return new String [] { SynchronizationStateTester.PROP_TESTER }; 46 } 47 48 51 public Object getProperty(String property) { 52 if (property == SynchronizationStateTester.PROP_TESTER) { 53 return fStateTester; 54 } 55 return null; 56 } 57 58 private static final class HierarchicalSynchronizationStateTester extends SynchronizationStateTester { 59 60 public HierarchicalSynchronizationStateTester() { 61 } 62 63 66 public int getState(Object element, int stateMask, IProgressMonitor monitor) throws CoreException { 67 if (element instanceof JavaElementResourceMapping) { 68 JavaElementResourceMapping mapping= (JavaElementResourceMapping) element; 69 IJavaElement javaElement= mapping.getJavaElement(); 70 if (javaElement instanceof IPackageFragment) { 71 IPackageFragment packageFragment= (IPackageFragment) javaElement; 72 if (!packageFragment.isDefaultPackage()) { 73 element= new HierarchicalPackageFragementResourceMapping(packageFragment); 74 } 75 } 76 } 77 return super.getState(element, stateMask, monitor); 78 } 79 } 80 81 private static final class HierarchicalPackageFragementResourceMapping extends JavaElementResourceMapping { 82 private final IPackageFragment fPack; 83 private HierarchicalPackageFragementResourceMapping(IPackageFragment fragment) { 84 Assert.isNotNull(fragment); 85 fPack= fragment; 86 } 87 public Object getModelObject() { 88 return fPack; 89 } 90 public IProject[] getProjects() { 91 return new IProject[] {fPack.getJavaProject().getProject() }; 92 } 93 public ResourceTraversal[] getTraversals(ResourceMappingContext context, IProgressMonitor monitor) throws CoreException { 94 return new ResourceTraversal[] { 95 new ResourceTraversal(new IResource[] {fPack.getResource()}, IResource.DEPTH_INFINITE, 0) 96 }; 97 } 98 } 99 } 100 | Popular Tags |