summaryrefslogtreecommitdiffstats
path: root/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/decorators/ReadOnly.java
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/decorators/ReadOnly.java')
-rw-r--r--plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/decorators/ReadOnly.java107
1 files changed, 107 insertions, 0 deletions
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 @@
1/*******************************************************************************
2 * Copyright (c) 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 *******************************************************************************/
11package org.yocto.bc.ui.decorators;
12
13import java.net.URL;
14
15import org.eclipse.core.resources.IResource;
16import org.eclipse.core.resources.ResourceAttributes;
17import org.eclipse.core.runtime.Path;
18import org.eclipse.core.runtime.Platform;
19import org.eclipse.jface.resource.ImageDescriptor;
20import org.eclipse.jface.viewers.IDecoration;
21import org.eclipse.jface.viewers.ILabelProviderListener;
22import org.eclipse.jface.viewers.ILightweightLabelDecorator;
23
24/**
25 * An example showing how to control when an element is decorated. This example
26 * decorates only elements that are instances of IResource and whose attribute
27 * is 'Read-only'.
28 *
29 * @see ILightweightLabelDecorator
30 */
31public class ReadOnly implements ILightweightLabelDecorator {
32 /**
33 * String constants for the various icon placement options from the template
34 * wizard.
35 */
36 public static final String TOP_RIGHT = "TOP_RIGHT";
37
38 public static final String TOP_LEFT = "TOP_LEFT";
39
40 public static final String BOTTOM_RIGHT = "BOTTOM_RIGHT";
41
42 public static final String BOTTOM_LEFT = "BOTTOM_LEFT";
43
44 public static final String UNDERLAY = "UNDERLAY";
45
46 /** The integer value representing the placement options */
47 private int quadrant;
48
49 /** The icon image location in the project folder */
50 private String iconPath = "icons/read_only.gif"; //NON-NLS-1
51
52 /**
53 * The image description used in
54 * <code>addOverlay(ImageDescriptor, int)</code>
55 */
56 private ImageDescriptor descriptor;
57
58 /* (non-Javadoc)
59 * @see org.eclipse.jface.viewers.ILightweightLabelDecorator#decorate(java.lang.Object, org.eclipse.jface.viewers.IDecoration)
60 */
61 public void decorate(Object element, IDecoration decoration) {
62 /**
63 * Checks that the element is an IResource with the 'Read-only' attribute
64 * and adds the decorator based on the specified image description and the
65 * integer representation of the placement option.
66 */
67 IResource resource = (IResource) element;
68 ResourceAttributes attrs = resource.getResourceAttributes();
69 if(attrs!=null) {
70 if (attrs.isReadOnly()){
71 URL url = Platform.find(
72 Platform.getBundle("org.yocto.bc.ui"), new Path(iconPath)); //NON-NLS-1
73
74 if (url == null)
75 return;
76 descriptor = ImageDescriptor.createFromURL(url);
77 quadrant = IDecoration.TOP_RIGHT;
78 decoration.addOverlay(descriptor,quadrant);
79 }
80 }
81 }
82
83 /* (non-Javadoc)
84 * @see org.eclipse.jface.viewers.IBaseLabelProvider#addListener(org.eclipse.jface.viewers.ILabelProviderListener)
85 */
86 public void addListener(ILabelProviderListener listener) {
87 }
88
89 /* (non-Javadoc)
90 * @see org.eclipse.jface.viewers.IBaseLabelProvider#dispose()
91 */
92 public void dispose() {
93 }
94
95 /* (non-Javadoc)
96 * @see org.eclipse.jface.viewers.IBaseLabelProvider#isLabelProperty(java.lang.Object, java.lang.String)
97 */
98 public boolean isLabelProperty(Object element, String property) {
99 return false;
100 }
101
102 /* (non-Javadoc)
103 * @see org.eclipse.jface.viewers.IBaseLabelProvider#removeListener(org.eclipse.jface.viewers.ILabelProviderListener)
104 */
105 public void removeListener(ILabelProviderListener listener) {
106 }
107} \ No newline at end of file