KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > decorators > DeclarativeDecorator


1 /*******************************************************************************
2  * Copyright (c) 2000, 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  *******************************************************************************/

11 package org.eclipse.ui.internal.decorators;
12
13 import java.net.URL JavaDoc;
14
15 import org.eclipse.core.runtime.IConfigurationElement;
16 import org.eclipse.jface.resource.ImageDescriptor;
17 import org.eclipse.jface.viewers.IDecoration;
18 import org.eclipse.jface.viewers.ILabelProviderListener;
19 import org.eclipse.jface.viewers.ILightweightLabelDecorator;
20 import org.eclipse.ui.internal.util.BundleUtility;
21
22 /**
23  * The DeclarativeDecorator is a decorator that is made entirely from an XML
24  * specification.
25  */

26 public class DeclarativeDecorator implements ILightweightLabelDecorator {
27  
28     private String JavaDoc iconLocation;
29
30     private IConfigurationElement configElement;
31
32     private ImageDescriptor descriptor;
33
34     DeclarativeDecorator(IConfigurationElement definingElement, String JavaDoc 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 JavaDoc element, String JavaDoc 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 JavaDoc element, IDecoration decoration) {
71         if (descriptor == null) {
72             URL JavaDoc url = BundleUtility.find(configElement.getDeclaringExtension()
73                     .getNamespace(), iconLocation);
74             if (url == null) {
75                 return;
76             }
77             descriptor = ImageDescriptor.createFromURL(url);
78         }
79         decoration.addOverlay(descriptor);
80     }
81 }
82
Popular Tags