From 41ac47d732eed8392d60d0f6773e5a279d49b999 Mon Sep 17 00:00:00 2001 From: Adrian Dudau Date: Thu, 12 Dec 2013 13:36:50 +0100 Subject: initial commit of Enea Linux 3.1 Migrated from the internal git server on the dora-enea branch Signed-off-by: Adrian Dudau --- .../src/org/yocto/bc/ui/decorators/ReadOnly.java | 107 +++++++++++++++++++++ 1 file changed, 107 insertions(+) create mode 100644 plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/decorators/ReadOnly.java (limited to 'plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/decorators/ReadOnly.java') diff --git a/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/decorators/ReadOnly.java b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/decorators/ReadOnly.java new file mode 100644 index 0000000..0bb3c20 --- /dev/null +++ b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/decorators/ReadOnly.java @@ -0,0 +1,107 @@ +/******************************************************************************* + * Copyright (c) 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: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.yocto.bc.ui.decorators; + +import java.net.URL; + +import org.eclipse.core.resources.IResource; +import org.eclipse.core.resources.ResourceAttributes; +import org.eclipse.core.runtime.Path; +import org.eclipse.core.runtime.Platform; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.jface.viewers.IDecoration; +import org.eclipse.jface.viewers.ILabelProviderListener; +import org.eclipse.jface.viewers.ILightweightLabelDecorator; + +/** + * An example showing how to control when an element is decorated. This example + * decorates only elements that are instances of IResource and whose attribute + * is 'Read-only'. + * + * @see ILightweightLabelDecorator + */ +public class ReadOnly implements ILightweightLabelDecorator { + /** + * String constants for the various icon placement options from the template + * wizard. + */ + public static final String TOP_RIGHT = "TOP_RIGHT"; + + public static final String TOP_LEFT = "TOP_LEFT"; + + public static final String BOTTOM_RIGHT = "BOTTOM_RIGHT"; + + public static final String BOTTOM_LEFT = "BOTTOM_LEFT"; + + public static final String UNDERLAY = "UNDERLAY"; + + /** The integer value representing the placement options */ + private int quadrant; + + /** The icon image location in the project folder */ + private String iconPath = "icons/read_only.gif"; //NON-NLS-1 + + /** + * The image description used in + * addOverlay(ImageDescriptor, int) + */ + private ImageDescriptor descriptor; + + /* (non-Javadoc) + * @see org.eclipse.jface.viewers.ILightweightLabelDecorator#decorate(java.lang.Object, org.eclipse.jface.viewers.IDecoration) + */ + public void decorate(Object element, IDecoration decoration) { + /** + * Checks that the element is an IResource with the 'Read-only' attribute + * and adds the decorator based on the specified image description and the + * integer representation of the placement option. + */ + IResource resource = (IResource) element; + ResourceAttributes attrs = resource.getResourceAttributes(); + if(attrs!=null) { + if (attrs.isReadOnly()){ + URL url = Platform.find( + Platform.getBundle("org.yocto.bc.ui"), new Path(iconPath)); //NON-NLS-1 + + if (url == null) + return; + descriptor = ImageDescriptor.createFromURL(url); + quadrant = IDecoration.TOP_RIGHT; + decoration.addOverlay(descriptor,quadrant); + } + } + } + + /* (non-Javadoc) + * @see org.eclipse.jface.viewers.IBaseLabelProvider#addListener(org.eclipse.jface.viewers.ILabelProviderListener) + */ + public void addListener(ILabelProviderListener listener) { + } + + /* (non-Javadoc) + * @see org.eclipse.jface.viewers.IBaseLabelProvider#dispose() + */ + public void dispose() { + } + + /* (non-Javadoc) + * @see org.eclipse.jface.viewers.IBaseLabelProvider#isLabelProperty(java.lang.Object, java.lang.String) + */ + public boolean isLabelProperty(Object element, String property) { + return false; + } + + /* (non-Javadoc) + * @see org.eclipse.jface.viewers.IBaseLabelProvider#removeListener(org.eclipse.jface.viewers.ILabelProviderListener) + */ + public void removeListener(ILabelProviderListener listener) { + } +} \ No newline at end of file -- cgit v1.2.3-54-g00ecf