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 [WorkbenchFile.java]

nameclass, %method, %block, %line, %
WorkbenchFile.java100% (1/1)100% (3/3)87%  (41/47)81%  (13/16)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class WorkbenchFile100% (1/1)100% (3/3)87%  (41/47)81%  (13/16)
getBaseImage (IResource): ImageDescriptor 100% (1/1)84%  (31/37)79%  (11/14)
<static initializer> 100% (1/1)100% (7/7)100% (2/2)
WorkbenchFile (): void 100% (1/1)100% (3/3)100% (1/1)

1/*******************************************************************************
2 * Copyright (c) 2000, 2008 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 org.eclipse.core.resources.IFile;
14import org.eclipse.core.resources.IResource;
15import org.eclipse.core.runtime.CoreException;
16import org.eclipse.core.runtime.QualifiedName;
17import org.eclipse.core.runtime.content.IContentType;
18import org.eclipse.jface.resource.ImageDescriptor;
19import org.eclipse.ui.ISharedImages;
20import org.eclipse.ui.PlatformUI;
21import org.eclipse.ui.ide.IDE;
22import org.eclipse.ui.internal.WorkbenchPlugin;
23 
24/**
25 * An IWorkbenchAdapter that represents IFiles.
26 */
27public class WorkbenchFile extends WorkbenchResource {
28 
29        /**
30         * Constant that is used as the key of a session property on IFile objects
31         * to cache the result of doing a proper content type lookup. This will be
32         * set by the ContentTypeDecorator (if enabled) and used instead of the
33         * "guessed" content type in {@link #getBaseImage(IResource)}.
34         * 
35         * @since 3.4
36         */
37        public static QualifiedName IMAGE_CACHE_KEY = new QualifiedName(WorkbenchPlugin.PI_WORKBENCH, "WorkbenchFileImage"); //$NON-NLS-1$
38        
39        /**
40     *        Answer the appropriate base image to use for the passed resource, optionally
41     *        considering the passed open status as well iff appropriate for the type of
42     *        passed resource
43     */
44    protected ImageDescriptor getBaseImage(IResource resource) {
45                IContentType contentType = null;
46                // do we need to worry about checking here?
47                if (resource instanceof IFile) {
48                        IFile file = (IFile)resource;
49                        // cached images come from ContentTypeDecorator
50                        ImageDescriptor cached;
51                        try {
52                                cached = (ImageDescriptor) file.getSessionProperty(IMAGE_CACHE_KEY);
53                                if (cached != null) {
54                                        return cached;
55                                }
56                        } catch (CoreException e) {
57                                // ignore - not having a cached image descriptor is not fatal
58                        }
59                        contentType = IDE.guessContentType(file);
60                }
61        // @issue move IDE specific images
62        ImageDescriptor image = PlatformUI.getWorkbench().getEditorRegistry()
63                .getImageDescriptor(resource.getName(), contentType);
64        if (image == null) {
65                        image = PlatformUI.getWorkbench().getSharedImages()
66                    .getImageDescriptor(ISharedImages.IMG_OBJ_FILE);
67                }
68        return image;
69    }
70}

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