001: /*******************************************************************************
002: * Copyright (c) 2000, 2006 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.ui.internal.ide;
011:
012: import java.net.URI;
013:
014: import org.eclipse.core.filesystem.IFileInfo;
015: import org.eclipse.core.resources.IResource;
016: import org.eclipse.jface.resource.ImageDescriptor;
017: import org.eclipse.jface.viewers.IDecoration;
018: import org.eclipse.jface.viewers.ILabelProviderListener;
019: import org.eclipse.jface.viewers.ILightweightLabelDecorator;
020: import org.eclipse.ui.internal.ide.dialogs.IDEResourceInfoUtils;
021: import org.eclipse.ui.plugin.AbstractUIPlugin;
022:
023: /**
024: * A LinkedResourceDecorator decorates an element's image with a linked
025: * resource overlay.
026: *
027: * @since 2.1
028: */
029: public class LinkedResourceDecorator implements
030: ILightweightLabelDecorator {
031: private static final ImageDescriptor LINK;
032:
033: private static final ImageDescriptor LINK_WARNING;
034:
035: static {
036: LINK = AbstractUIPlugin.imageDescriptorFromPlugin(
037: IDEWorkbenchPlugin.IDE_WORKBENCH,
038: "$nl$/icons/full/ovr16/link_ovr.gif"); //$NON-NLS-1$
039: LINK_WARNING = AbstractUIPlugin.imageDescriptorFromPlugin(
040: IDEWorkbenchPlugin.IDE_WORKBENCH,
041: "$nl$/icons/full/ovr16/linkwarn_ovr.gif"); //$NON-NLS-1$
042: }
043:
044: /**
045: * Creates a new <code>LinkedResourceDecorator</code>.
046: */
047: public LinkedResourceDecorator() {
048: }
049:
050: /**
051: * @see org.eclipse.jface.viewers.IBaseLabelProvider#addListener(ILabelProviderListener)
052: */
053: public void addListener(ILabelProviderListener listener) {
054: }
055:
056: /**
057: * @see org.eclipse.jface.viewers.IBaseLabelProvider#dispose()
058: */
059: public void dispose() {
060: // no resources to dispose
061: }
062:
063: /**
064: * @see org.eclipse.jface.viewers.IBaseLabelProvider#isLabelProperty(java.lang.Object, java.lang.String)
065: */
066: public boolean isLabelProperty(Object element, String property) {
067: return false;
068: }
069:
070: /**
071: * @see org.eclipse.jface.viewers.IBaseLabelProvider#removeListener(ILabelProviderListener)
072: */
073: public void removeListener(ILabelProviderListener listener) {
074: }
075:
076: /**
077: * Adds the linked resource overlay if the given element is a linked
078: * resource.
079: *
080: * @param element element to decorate
081: * @param decoration The decoration we are adding to
082: * @see org.eclipse.jface.viewers.ILightweightLabelDecorator#decorate(Object, IDecoration)
083: */
084: public void decorate(Object element, IDecoration decoration) {
085:
086: if (element instanceof IResource == false) {
087: return;
088: }
089: IResource resource = (IResource) element;
090: if (resource.isLinked()) {
091: IFileInfo fileInfo = null;
092: URI location = resource.getLocationURI();
093: if (location != null) {
094: fileInfo = IDEResourceInfoUtils.getFileInfo(location);
095: }
096: if (fileInfo != null && fileInfo.exists()) {
097: decoration.addOverlay(LINK);
098: } else {
099: decoration.addOverlay(LINK_WARNING);
100: }
101: }
102:
103: }
104:
105: }
|