1 11 package org.eclipse.ui.internal.ide.model; 12 13 import java.util.HashMap ; 14 15 import org.eclipse.core.resources.IProject; 16 import org.eclipse.core.resources.IResource; 17 import org.eclipse.core.runtime.CoreException; 18 import org.eclipse.jface.resource.ImageDescriptor; 19 import org.eclipse.swt.graphics.Point; 20 import org.eclipse.ui.IProjectActionFilter; 21 import org.eclipse.ui.ide.IDE; 22 import org.eclipse.ui.internal.ide.IDEInternalWorkbenchImages; 23 import org.eclipse.ui.internal.ide.IDEWorkbenchPlugin; 24 import org.eclipse.ui.internal.ide.misc.OverlayIcon; 25 26 29 public class WorkbenchProject extends WorkbenchResource implements 30 IProjectActionFilter { 31 HashMap imageCache = new HashMap (11); 32 33 38 protected ImageDescriptor getBaseImage(IResource resource) { 39 IProject project = (IProject) resource; 40 boolean isOpen = project.isOpen(); 41 String baseKey = isOpen ? IDE.SharedImages.IMG_OBJ_PROJECT 42 : IDE.SharedImages.IMG_OBJ_PROJECT_CLOSED; 43 if (isOpen) { 44 try { 45 String [] natureIds = project.getDescription().getNatureIds(); 46 for (int i = 0; i < natureIds.length; ++i) { 47 String imageKey = natureIds[i]; 50 ImageDescriptor overlayImage = (ImageDescriptor) imageCache 51 .get(imageKey); 52 if (overlayImage != null) { 53 return overlayImage; 54 } 55 ImageDescriptor natureImage = IDEWorkbenchPlugin 56 .getDefault().getProjectImageRegistry() 57 .getNatureImage(natureIds[i]); 58 if (natureImage != null) { 59 ImageDescriptor baseImage = IDEInternalWorkbenchImages 60 .getImageDescriptor(baseKey); 61 overlayImage = new OverlayIcon(baseImage, 62 new ImageDescriptor[][] { { natureImage } }, 63 new Point(16, 16)); 64 imageCache.put(imageKey, overlayImage); 65 return overlayImage; 66 } 67 } 68 } catch (CoreException e) { 69 } 70 } 71 return IDEInternalWorkbenchImages.getImageDescriptor(baseKey); 72 } 73 74 77 public Object [] getChildren(Object o) { 78 IProject project = (IProject) o; 79 if (project.isOpen()) { 80 try { 81 return project.members(); 82 } catch (CoreException e) { 83 } 85 } 86 return NO_CHILDREN; 87 } 88 89 98 public boolean testAttribute(Object target, String name, String value) { 99 if (!(target instanceof IProject)) { 100 return false; 101 } 102 IProject proj = (IProject) target; 103 if (name.equals(NATURE)) { 104 try { 105 return proj.isAccessible() && proj.hasNature(value); 106 } catch (CoreException e) { 107 return false; 108 } 109 } else if (name.equals(OPEN)) { 110 value = value.toLowerCase(); 111 return (proj.isOpen() == value.equals("true")); } 113 return super.testAttribute(target, name, value); 114 } 115 } 116 | Popular Tags |