01: /*******************************************************************************
02: * Copyright (c) 2000, 2006 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.ui.internal.decorators;
11:
12: import java.net.URL;
13:
14: import org.eclipse.core.runtime.IConfigurationElement;
15: import org.eclipse.jface.resource.ImageDescriptor;
16: import org.eclipse.jface.viewers.IDecoration;
17: import org.eclipse.jface.viewers.ILabelProviderListener;
18: import org.eclipse.jface.viewers.ILightweightLabelDecorator;
19: import org.eclipse.ui.internal.util.BundleUtility;
20:
21: /**
22: * The DeclarativeDecorator is a decorator that is made entirely from an XML
23: * specification.
24: */
25: public class DeclarativeDecorator implements ILightweightLabelDecorator {
26:
27: private String iconLocation;
28:
29: private IConfigurationElement configElement;
30:
31: private ImageDescriptor descriptor;
32:
33: DeclarativeDecorator(IConfigurationElement definingElement,
34: String iconPath) {
35: this .iconLocation = iconPath;
36: this .configElement = definingElement;
37: }
38:
39: /**
40: * @see org.eclipse.jface.viewers.IBaseLabelProvider#addListener(org.eclipse.jface.viewers.ILabelProviderListener)
41: */
42: public void addListener(ILabelProviderListener listener) {
43: }
44:
45: /**
46: * @see org.eclipse.jface.viewers.IBaseLabelProvider#dispose()
47: */
48: public void dispose() {
49: //Nothing to do here
50: }
51:
52: /**
53: * @see org.eclipse.jface.viewers.IBaseLabelProvider#isLabelProperty(java.lang.Object,
54: * java.lang.String)
55: */
56: public boolean isLabelProperty(Object element, String property) {
57: return false;
58: }
59:
60: /**
61: * @see org.eclipse.jface.viewers.IBaseLabelProvider#removeListener(org.eclipse.jface.viewers.ILabelProviderListener)
62: */
63: public void removeListener(ILabelProviderListener listener) {
64: }
65:
66: /**
67: * @see org.eclipse.jface.viewers.ILightweightLabelDecorator#decorate(java.lang.Object,
68: * org.eclipse.jface.viewers.IDecoration)
69: */
70: public void decorate(Object element, IDecoration decoration) {
71: if (descriptor == null) {
72: URL url = BundleUtility.find(configElement
73: .getDeclaringExtension().getNamespace(),
74: iconLocation);
75: if (url == null) {
76: return;
77: }
78: descriptor = ImageDescriptor.createFromURL(url);
79: }
80: decoration.addOverlay(descriptor);
81: }
82: }
|