### Eclipse Workspace Patch 1.0 #P org.eclipse.ui.ide Index: src/org/eclipse/ui/internal/ide/ReadOnlyResourceDecorator.java =================================================================== RCS file: src/org/eclipse/ui/internal/ide/ReadOnlyResourceDecorator.java diff -N src/org/eclipse/ui/internal/ide/ReadOnlyResourceDecorator.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/ui/internal/ide/ReadOnlyResourceDecorator.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,88 @@ +/******************************************************************************* + * Copyright (c) 2000, 2006 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Benjamin Muskalla - initial API and implementation + *******************************************************************************/ +package org.eclipse.ui.internal.ide; + +import org.eclipse.core.resources.IResource; +import org.eclipse.core.resources.ResourceAttributes; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.jface.viewers.IDecoration; +import org.eclipse.jface.viewers.ILabelProviderListener; +import org.eclipse.jface.viewers.ILightweightLabelDecorator; +import org.eclipse.ui.plugin.AbstractUIPlugin; + +/** + * A ReadOnlyResourceDecorator decorates an element's image with a ready-only + * resource overlay. + * + * @since 2.1 + */ +public class ReadOnlyResourceDecorator implements ILightweightLabelDecorator { + private static final ImageDescriptor READONLY; + + static { + READONLY = AbstractUIPlugin.imageDescriptorFromPlugin( + IDEWorkbenchPlugin.IDE_WORKBENCH, + "$nl$/icons/full/ovr16/readonly_ovr.gif"); //$NON-NLS-1$ + } + + /** + * Creates a new ReadOnlyResourceDecorator. + */ + public ReadOnlyResourceDecorator() { + } + + /** + * @see org.eclipse.jface.viewers.IBaseLabelProvider#addListener(ILabelProviderListener) + */ + public void addListener(ILabelProviderListener listener) { + } + + /** + * @see org.eclipse.jface.viewers.IBaseLabelProvider#dispose() + */ + public void dispose() { + // no resources to dispose + } + + /** + * @see org.eclipse.jface.viewers.IBaseLabelProvider#isLabelProperty(java.lang.Object, java.lang.String) + */ + public boolean isLabelProperty(Object element, String property) { + return false; + } + + /** + * @see org.eclipse.jface.viewers.IBaseLabelProvider#removeListener(ILabelProviderListener) + */ + public void removeListener(ILabelProviderListener listener) { + } + + /** + * Adds the read-only resource overlay if the given element is read-only + * + * @param element element to decorate + * @param decoration The decoration we are adding to + * @see org.eclipse.jface.viewers.ILightweightLabelDecorator#decorate(Object, IDecoration) + */ + public void decorate(Object element, IDecoration decoration) { + + if (element instanceof IResource == false) { + return; + } + IResource resource = (IResource) element; + ResourceAttributes attributes = resource.getResourceAttributes(); + if (attributes != null && attributes.isReadOnly()) { + decoration.addOverlay(READONLY); + } + + } + +}