1 /******************************************************************************* 2 * Copyright (C) 2012, 2019 Robin Rosenberg <robin.rosenberg@dewire.com> and others. 3 * 4 * 5 * This program and the accompanying materials 6 * are made available under the terms of the Eclipse Public License 2.0 7 * which accompanies this distribution, and is available at 8 * https://www.eclipse.org/legal/epl-2.0/ 9 * 10 * SPDX-License-Identifier: EPL-2.0 11 * Robin Rosenberg <robin.rosenberg@dewire.com> - initial API and implementation 12 * Lars Vogel <Lars.Vogel@gmail.com> - Bug 430694 13 * Alexander Fedorov <alexander.fedorov@arsysop.ru> - Bug 548799 14 *******************************************************************************/ 15 package org.eclipse.ui.internal.ide; 16 17 import java.util.Optional; 18 19 import org.eclipse.core.resources.IResource; 20 import org.eclipse.core.resources.ResourceAttributes; 21 import org.eclipse.core.resources.mapping.ResourceMapping; 22 import org.eclipse.core.runtime.Adapters; 23 import org.eclipse.jface.resource.ImageDescriptor; 24 import org.eclipse.jface.resource.ResourceLocator; 25 import org.eclipse.jface.viewers.IDecoration; 26 import org.eclipse.jface.viewers.ILabelProviderListener; 27 import org.eclipse.jface.viewers.ILightweightLabelDecorator; 28 29 /** 30 * Decorate symbolic links 31 * @since 3.8.200 32 */ 33 public class SymlinkDecorator implements ILightweightLabelDecorator { 34 35 private static Optional<ImageDescriptor> SYMLINK; 36 37 static { 38 SYMLINK = ResourceLocator.imageDescriptorFromBundle( 39 IDEWorkbenchPlugin.IDE_WORKBENCH, 40 "$nl$/icons/full/ovr16/symlink_ovr.png"); //$NON-NLS-1$ 41 42 } 43 44 @Override addListener(ILabelProviderListener listener)45 public void addListener(ILabelProviderListener listener) { 46 // empty 47 } 48 49 @Override dispose()50 public void dispose() { 51 } 52 53 @Override isLabelProperty(Object element, String property)54 public boolean isLabelProperty(Object element, String property) { 55 return false; 56 } 57 58 @Override removeListener(ILabelProviderListener listener)59 public void removeListener(ILabelProviderListener listener) { 60 // empty 61 } 62 63 @Override decorate(Object element, IDecoration decoration)64 public void decorate(Object element, IDecoration decoration) { 65 if (element instanceof ResourceMapping) { 66 element = ((ResourceMapping) element).getModelObject(); 67 } 68 IResource resource = Adapters.adapt(element, IResource.class); 69 if (resource != null) { 70 ResourceAttributes resourceAttributes = resource.getResourceAttributes(); 71 if (resourceAttributes != null && resourceAttributes.isSymbolicLink()) { 72 SYMLINK.ifPresent(decoration::addOverlay); 73 } 74 } 75 } 76 } 77