KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > ide > LinkedResourceDecorator


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  *******************************************************************************/

11 package org.eclipse.ui.internal.ide;
12
13 import java.net.URI JavaDoc;
14
15 import org.eclipse.core.filesystem.IFileInfo;
16 import org.eclipse.core.resources.IResource;
17 import org.eclipse.jface.resource.ImageDescriptor;
18 import org.eclipse.jface.viewers.IDecoration;
19 import org.eclipse.jface.viewers.ILabelProviderListener;
20 import org.eclipse.jface.viewers.ILightweightLabelDecorator;
21 import org.eclipse.ui.internal.ide.dialogs.IDEResourceInfoUtils;
22 import org.eclipse.ui.plugin.AbstractUIPlugin;
23
24 /**
25  * A LinkedResourceDecorator decorates an element's image with a linked
26  * resource overlay.
27  *
28  * @since 2.1
29  */

30 public class LinkedResourceDecorator implements ILightweightLabelDecorator {
31     private static final ImageDescriptor LINK;
32
33     private static final ImageDescriptor LINK_WARNING;
34
35     static {
36         LINK = AbstractUIPlugin.imageDescriptorFromPlugin(
37                 IDEWorkbenchPlugin.IDE_WORKBENCH,
38                 "$nl$/icons/full/ovr16/link_ovr.gif"); //$NON-NLS-1$
39
LINK_WARNING = AbstractUIPlugin.imageDescriptorFromPlugin(
40                 IDEWorkbenchPlugin.IDE_WORKBENCH,
41                 "$nl$/icons/full/ovr16/linkwarn_ovr.gif"); //$NON-NLS-1$
42
}
43
44     /**
45      * Creates a new <code>LinkedResourceDecorator</code>.
46      */

47     public LinkedResourceDecorator() {
48     }
49
50     /**
51      * @see org.eclipse.jface.viewers.IBaseLabelProvider#addListener(ILabelProviderListener)
52      */

53     public void addListener(ILabelProviderListener listener) {
54     }
55
56     /**
57      * @see org.eclipse.jface.viewers.IBaseLabelProvider#dispose()
58      */

59     public void dispose() {
60         // no resources to dispose
61
}
62
63     /**
64      * @see org.eclipse.jface.viewers.IBaseLabelProvider#isLabelProperty(java.lang.Object, java.lang.String)
65      */

66     public boolean isLabelProperty(Object JavaDoc element, String JavaDoc property) {
67         return false;
68     }
69
70     /**
71      * @see org.eclipse.jface.viewers.IBaseLabelProvider#removeListener(ILabelProviderListener)
72      */

73     public void removeListener(ILabelProviderListener listener) {
74     }
75
76     /**
77      * Adds the linked resource overlay if the given element is a linked
78      * resource.
79      *
80      * @param element element to decorate
81      * @param decoration The decoration we are adding to
82      * @see org.eclipse.jface.viewers.ILightweightLabelDecorator#decorate(Object, IDecoration)
83      */

84     public void decorate(Object JavaDoc element, IDecoration decoration) {
85
86         if (element instanceof IResource == false) {
87             return;
88         }
89         IResource resource = (IResource) element;
90         if (resource.isLinked()) {
91             IFileInfo fileInfo = null;
92             URI JavaDoc location = resource.getLocationURI();
93             if (location != null) {
94                 fileInfo = IDEResourceInfoUtils.getFileInfo(location);
95             }
96             if (fileInfo != null && fileInfo.exists()) {
97                 decoration.addOverlay(LINK);
98             } else {
99                 decoration.addOverlay(LINK_WARNING);
100             }
101         }
102
103     }
104
105 }
106
Popular Tags