Source Code Cross Referenced for WorkbenchLabelProvider.java in  » IDE-Eclipse » ui-workbench » org » eclipse » ui » model » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » IDE Eclipse » ui workbench » org.eclipse.ui.model 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*******************************************************************************
002:         * Copyright (c) 2000, 2006 IBM Corporation and others.
003:         * All rights reserved. This program and the accompanying materials
004:         * are made available under the terms of the Eclipse Public License v1.0
005:         * which accompanies this distribution, and is available at
006:         * http://www.eclipse.org/legal/epl-v10.html
007:         *
008:         * Contributors:
009:         *     IBM Corporation - initial API and implementation
010:         *******************************************************************************/package org.eclipse.ui.model;
011:
012:        import org.eclipse.jface.resource.ImageDescriptor;
013:        import org.eclipse.jface.viewers.DecoratingLabelProvider;
014:        import org.eclipse.jface.viewers.IColorProvider;
015:        import org.eclipse.jface.viewers.IFontProvider;
016:        import org.eclipse.jface.viewers.ILabelProvider;
017:        import org.eclipse.jface.viewers.LabelProvider;
018:        import org.eclipse.jface.viewers.LabelProviderChangedEvent;
019:        import org.eclipse.swt.graphics.Color;
020:        import org.eclipse.swt.graphics.Font;
021:        import org.eclipse.swt.graphics.FontData;
022:        import org.eclipse.swt.graphics.Image;
023:        import org.eclipse.swt.graphics.RGB;
024:        import org.eclipse.swt.widgets.Display;
025:        import org.eclipse.ui.IEditorRegistry;
026:        import org.eclipse.ui.IPropertyListener;
027:        import org.eclipse.ui.PlatformUI;
028:        import org.eclipse.ui.internal.util.SWTResourceUtil;
029:        import org.eclipse.ui.internal.util.Util;
030:
031:        /**
032:         * Provides basic labels for adaptable objects that have the
033:         * <code>IWorkbenchAdapter</code> adapter associated with them.  All dispensed
034:         * images are cached until the label provider is explicitly disposed.
035:         * This class provides a facility for subclasses to define annotations
036:         * on the labels and icons of adaptable objects.
037:         */
038:        public class WorkbenchLabelProvider extends LabelProvider implements 
039:                IColorProvider, IFontProvider {
040:
041:            /**
042:             * Returns a workbench label provider that is hooked up to the decorator
043:             * mechanism.
044:             * 
045:             * @return a new <code>DecoratingLabelProvider</code> which wraps a <code>
046:             *   new <code>WorkbenchLabelProvider</code>
047:             */
048:            public static ILabelProvider getDecoratingWorkbenchLabelProvider() {
049:                return new DecoratingLabelProvider(
050:                        new WorkbenchLabelProvider(), PlatformUI.getWorkbench()
051:                                .getDecoratorManager().getLabelDecorator());
052:            }
053:
054:            /**
055:             * Listener that tracks changes to the editor registry and does a full update
056:             * when it changes, since many workbench adapters derive their icon from the file
057:             * associations in the registry.
058:             */
059:            private IPropertyListener editorRegistryListener = new IPropertyListener() {
060:                public void propertyChanged(Object source, int propId) {
061:                    if (propId == IEditorRegistry.PROP_CONTENTS) {
062:                        fireLabelProviderChanged(new LabelProviderChangedEvent(
063:                                WorkbenchLabelProvider.this ));
064:                    }
065:                }
066:            };
067:
068:            /**
069:             * Creates a new workbench label provider.
070:             */
071:            public WorkbenchLabelProvider() {
072:                PlatformUI.getWorkbench().getEditorRegistry()
073:                        .addPropertyListener(editorRegistryListener);
074:            }
075:
076:            /**
077:             * Returns an image descriptor that is based on the given descriptor,
078:             * but decorated with additional information relating to the state
079:             * of the provided object.
080:             *
081:             * Subclasses may reimplement this method to decorate an object's
082:             * image.
083:             * 
084:             * @param input The base image to decorate.
085:             * @param element The element used to look up decorations.
086:             * @return the resuling ImageDescriptor.
087:             * @see org.eclipse.jface.resource.CompositeImageDescriptor
088:             */
089:            protected ImageDescriptor decorateImage(ImageDescriptor input,
090:                    Object element) {
091:                return input;
092:            }
093:
094:            /**
095:             * Returns a label that is based on the given label,
096:             * but decorated with additional information relating to the state
097:             * of the provided object.
098:             *
099:             * Subclasses may implement this method to decorate an object's
100:             * label.
101:             * @param input The base text to decorate.
102:             * @param element The element used to look up decorations.
103:             * @return the resulting text
104:             */
105:            protected String decorateText(String input, Object element) {
106:                return input;
107:            }
108:
109:            /* (non-Javadoc)
110:             * Method declared on ILabelProvider
111:             */
112:            public void dispose() {
113:                PlatformUI.getWorkbench().getEditorRegistry()
114:                        .removePropertyListener(editorRegistryListener);
115:                super .dispose();
116:            }
117:
118:            /**
119:             * Returns the implementation of IWorkbenchAdapter for the given
120:             * object.  
121:             * @param o the object to look up.
122:             * @return IWorkbenchAdapter or<code>null</code> if the adapter is not defined or the
123:             * object is not adaptable. 
124:             */
125:            protected final IWorkbenchAdapter getAdapter(Object o) {
126:                return (IWorkbenchAdapter) Util.getAdapter(o,
127:                        IWorkbenchAdapter.class);
128:            }
129:
130:            /**
131:             * Returns the implementation of IWorkbenchAdapter2 for the given
132:             * object.  
133:             * @param o the object to look up.
134:             * @return IWorkbenchAdapter2 or<code>null</code> if the adapter is not defined or the
135:             * object is not adaptable. 
136:             */
137:            protected final IWorkbenchAdapter2 getAdapter2(Object o) {
138:                return (IWorkbenchAdapter2) Util.getAdapter(o,
139:                        IWorkbenchAdapter2.class);
140:            }
141:
142:            /* (non-Javadoc)
143:             * Method declared on ILabelProvider
144:             */
145:            public final Image getImage(Object element) {
146:                //obtain the base image by querying the element
147:                IWorkbenchAdapter adapter = getAdapter(element);
148:                if (adapter == null) {
149:                    return null;
150:                }
151:                ImageDescriptor descriptor = adapter
152:                        .getImageDescriptor(element);
153:                if (descriptor == null) {
154:                    return null;
155:                }
156:
157:                //add any annotations to the image descriptor
158:                descriptor = decorateImage(descriptor, element);
159:
160:                Image image = (Image) SWTResourceUtil.getImageTable().get(
161:                        descriptor);
162:                if (image == null) {
163:                    image = descriptor.createImage();
164:                    SWTResourceUtil.getImageTable().put(descriptor, image);
165:                }
166:                return image;
167:            }
168:
169:            /* (non-Javadoc)
170:             * Method declared on ILabelProvider
171:             */
172:            public final String getText(Object element) {
173:                //query the element for its label
174:                IWorkbenchAdapter adapter = getAdapter(element);
175:                if (adapter == null) {
176:                    return ""; //$NON-NLS-1$
177:                }
178:                String label = adapter.getLabel(element);
179:
180:                //return the decorated label
181:                return decorateText(label, element);
182:            }
183:
184:            /* (non-Javadoc)
185:             * @see org.eclipse.jface.viewers.IColorProvider#getForeground(java.lang.Object)
186:             */
187:            public Color getForeground(Object element) {
188:                return getColor(element, true);
189:            }
190:
191:            /* (non-Javadoc)
192:             * @see org.eclipse.jface.viewers.IColorProvider#getBackground(java.lang.Object)
193:             */
194:            public Color getBackground(Object element) {
195:                return getColor(element, false);
196:            }
197:
198:            /* (non-Javadoc)
199:             * @see org.eclipse.jface.viewers.IFontProvider#getFont(java.lang.Object)
200:             */
201:            public Font getFont(Object element) {
202:                IWorkbenchAdapter2 adapter = getAdapter2(element);
203:                if (adapter == null) {
204:                    return null;
205:                }
206:
207:                FontData descriptor = adapter.getFont(element);
208:                if (descriptor == null) {
209:                    return null;
210:                }
211:
212:                Font font = (Font) SWTResourceUtil.getFontTable().get(
213:                        descriptor);
214:                if (font == null) {
215:                    font = new Font(Display.getCurrent(), descriptor);
216:                    SWTResourceUtil.getFontTable().put(descriptor, font);
217:                }
218:                return font;
219:            }
220:
221:            private Color getColor(Object element, boolean forground) {
222:                IWorkbenchAdapter2 adapter = getAdapter2(element);
223:                if (adapter == null) {
224:                    return null;
225:                }
226:                RGB descriptor = forground ? adapter.getForeground(element)
227:                        : adapter.getBackground(element);
228:                if (descriptor == null) {
229:                    return null;
230:                }
231:
232:                Color color = (Color) SWTResourceUtil.getColorTable().get(
233:                        descriptor);
234:                if (color == null) {
235:                    color = new Color(Display.getCurrent(), descriptor);
236:                    SWTResourceUtil.getColorTable().put(descriptor, color);
237:                }
238:                return color;
239:            }
240:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.