EMMA Coverage Report (generated Mon Sep 29 15:05:28 EDT 2008)
[all classes][org.eclipse.ui.internal.ide.model]

COVERAGE SUMMARY FOR SOURCE FILE [WorkbenchProject.java]

nameclass, %method, %block, %line, %
WorkbenchProject.java100% (1/1)100% (4/4)87%  (135/156)85%  (36.8/43)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class WorkbenchProject100% (1/1)100% (4/4)87%  (135/156)85%  (36.8/43)
testAttribute (Object, String, String): boolean 100% (1/1)63%  (31/49)62%  (6.8/11)
getChildren (Object): Object [] 100% (1/1)92%  (11/12)80%  (4/5)
getBaseImage (IResource): ImageDescriptor 100% (1/1)98%  (84/86)96%  (23.9/25)
WorkbenchProject (): void 100% (1/1)100% (9/9)100% (2/2)

1/*******************************************************************************
2 * Copyright (c) 2000, 2006 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors:
9 *     IBM Corporation - initial API and implementation
10 *******************************************************************************/
11package org.eclipse.ui.internal.ide.model;
12 
13import java.util.HashMap;
14 
15import org.eclipse.core.resources.IProject;
16import org.eclipse.core.resources.IResource;
17import org.eclipse.core.runtime.CoreException;
18import org.eclipse.jface.resource.ImageDescriptor;
19import org.eclipse.swt.graphics.Point;
20import org.eclipse.ui.IProjectActionFilter;
21import org.eclipse.ui.ide.IDE;
22import org.eclipse.ui.internal.ide.IDEInternalWorkbenchImages;
23import org.eclipse.ui.internal.ide.IDEWorkbenchPlugin;
24import org.eclipse.ui.internal.ide.misc.OverlayIcon;
25 
26/**
27 * An IWorkbenchAdapter that represents IProject.
28 */
29public class WorkbenchProject extends WorkbenchResource implements
30        IProjectActionFilter {
31    HashMap imageCache = new HashMap(11);
32 
33    /**
34     *        Answer the appropriate base image to use for the passed resource, optionally
35     *        considering the passed open status as well iff appropriate for the type of
36     *        passed resource
37     */
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                    // Have to use a cache because OverlayIcon does not define its own equality criteria,
48                    // so WorkbenchLabelProvider would always create a new image otherwise.
49                    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    /**
75     * Returns the children of this container.
76     */
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                //don't get the children if there are problems with the project
84            }
85        }
86        return NO_CHILDREN;
87    }
88 
89    /**
90     * Returns whether the specific attribute matches the state of the target
91     * object.
92     *
93     * @param target the target object
94     * @param name the attribute name
95     * @param value the attriute value
96     * @return <code>true</code> if the attribute matches; <code>false</code> otherwise
97     */
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"));//$NON-NLS-1$
112        }
113        return super.testAttribute(target, name, value);
114    }
115}

[all classes][org.eclipse.ui.internal.ide.model]
EMMA 2.0.5312 EclEmma Fix 1 (C) Vladimir Roubtsov