Source Code Cross Referenced for WorkingSetAdapterFactory.java in  » IDE-Eclipse » ui-ide » org » eclipse » ui » internal » ide » 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 ide » org.eclipse.ui.internal.ide.model 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*******************************************************************************
002:         * Copyright (c) 2005, 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.internal.ide.model;
011:
012:        import java.util.ArrayList;
013:        import java.util.List;
014:
015:        import org.eclipse.core.resources.IResource;
016:        import org.eclipse.core.resources.mapping.ResourceMapping;
017:        import org.eclipse.core.runtime.IAdaptable;
018:        import org.eclipse.core.runtime.IAdapterFactory;
019:        import org.eclipse.core.runtime.Platform;
020:        import org.eclipse.jface.resource.ImageDescriptor;
021:        import org.eclipse.ui.IContributorResourceAdapter;
022:        import org.eclipse.ui.IWorkingSet;
023:        import org.eclipse.ui.ide.IContributorResourceAdapter2;
024:        import org.eclipse.ui.model.IWorkbenchAdapter;
025:
026:        /**
027:         * Adapter factory which provides a ResourceMapping for a working set
028:         */
029:        public class WorkingSetAdapterFactory implements  IAdapterFactory {
030:
031:            /*
032:             * Adapter for converting a working set to a resource mapping for use by
033:             * object contributions.
034:             */
035:            class ContributorResourceAdapter implements 
036:                    IContributorResourceAdapter2 {
037:
038:                public ResourceMapping getAdaptedResourceMapping(
039:                        IAdaptable adaptable) {
040:                    if (adaptable instanceof  IWorkingSet) {
041:                        IWorkingSet workingSet = (IWorkingSet) adaptable;
042:                        IAdaptable[] elements = workingSet.getElements();
043:                        List result = new ArrayList();
044:                        for (int i = 0; i < elements.length; i++) {
045:                            IAdaptable element = elements[i];
046:                            ResourceMapping mapping = getContributedResourceMapping(element);
047:                            if (mapping == null) {
048:                                mapping = getResourceMapping(element);
049:                            }
050:                            if (mapping != null) {
051:                                result.add(mapping);
052:                            }
053:                        }
054:                        if (!result.isEmpty()) {
055:                            return new WorkingSetResourceMapping(workingSet);
056:                        }
057:                    }
058:                    return null;
059:                }
060:
061:                public IResource getAdaptedResource(IAdaptable adaptable) {
062:                    // Working sets don't adapt to IResource
063:                    return null;
064:                }
065:
066:            }
067:
068:            class WorkbenchAdapter implements  IWorkbenchAdapter {
069:
070:                public Object[] getChildren(Object o) {
071:                    if (o instanceof  IWorkingSet) {
072:                        IWorkingSet set = (IWorkingSet) o;
073:                        return set.getElements();
074:                    }
075:                    return null;
076:                }
077:
078:                public ImageDescriptor getImageDescriptor(Object o) {
079:                    if (o instanceof  IWorkingSet) {
080:                        IWorkingSet set = (IWorkingSet) o;
081:                        return set.getImageDescriptor();
082:                    }
083:                    return null;
084:                }
085:
086:                public String getLabel(Object o) {
087:                    if (o instanceof  IWorkingSet) {
088:                        IWorkingSet set = (IWorkingSet) o;
089:                        return set.getLabel();
090:                    }
091:                    return null;
092:                }
093:
094:                public Object getParent(Object o) {
095:                    return null;
096:                }
097:
098:            }
099:
100:            private IContributorResourceAdapter2 contributorResourceAdapter = new ContributorResourceAdapter();
101:
102:            private IWorkbenchAdapter workbenchAdapter = new WorkbenchAdapter();
103:
104:            /*
105:             * (non-Javadoc)
106:             * 
107:             * @see org.eclipse.core.runtime.IAdapterFactory#getAdapter(java.lang.Object,
108:             *      java.lang.Class)
109:             */
110:            public Object getAdapter(Object adaptableObject, Class adapterType) {
111:                if (adaptableObject instanceof  IWorkingSet) {
112:                    if (adapterType == IContributorResourceAdapter.class) {
113:                        return contributorResourceAdapter;
114:                    }
115:                    if (adapterType == IWorkbenchAdapter.class) {
116:                        return workbenchAdapter;
117:                    }
118:                    if (adapterType == ResourceMapping.class) {
119:                        IWorkingSet workingSet = (IWorkingSet) adaptableObject;
120:                        IAdaptable[] elements = workingSet.getElements();
121:                        List result = new ArrayList();
122:                        for (int i = 0; i < elements.length; i++) {
123:                            IAdaptable element = elements[i];
124:                            ResourceMapping mapping = getResourceMapping(element);
125:                            if (mapping != null) {
126:                                result.add(mapping);
127:                            }
128:                        }
129:                        if (!result.isEmpty()) {
130:                            return new WorkingSetResourceMapping(workingSet);
131:                        }
132:                    }
133:                }
134:                return null;
135:            }
136:
137:            /*
138:             * (non-Javadoc)
139:             * 
140:             * @see org.eclipse.core.runtime.IAdapterFactory#getAdapterList()
141:             */
142:            public Class[] getAdapterList() {
143:                return new Class[] { IContributorResourceAdapter2.class,
144:                        IWorkbenchAdapter.class, ResourceMapping.class };
145:            }
146:
147:            static ResourceMapping getResourceMapping(Object o) {
148:                // First, ask the object directly for a resource mapping
149:                Object mapping = internalGetAdapter(o, ResourceMapping.class);
150:                if (mapping instanceof  ResourceMapping) {
151:                    return (ResourceMapping) mapping;
152:                }
153:                // If this fails, ask for a resource and convert to a resource mapping
154:                Object resource = internalGetAdapter(o, IResource.class);
155:                if (resource != null) {
156:                    mapping = internalGetAdapter(resource,
157:                            ResourceMapping.class);
158:                    if (mapping instanceof  ResourceMapping) {
159:                        return (ResourceMapping) mapping;
160:                    }
161:                }
162:                return null;
163:            }
164:
165:            static ResourceMapping getContributedResourceMapping(
166:                    IAdaptable element) {
167:                Object resourceAdapter = internalGetAdapter(element,
168:                        IContributorResourceAdapter.class);
169:                if (resourceAdapter != null) {
170:                    if (resourceAdapter instanceof  IContributorResourceAdapter2) {
171:                        // First, use the mapping contributor adapter to get the mapping
172:                        IContributorResourceAdapter2 mappingAdapter = (IContributorResourceAdapter2) resourceAdapter;
173:                        ResourceMapping mapping = mappingAdapter
174:                                .getAdaptedResourceMapping(element);
175:                        if (mapping != null) {
176:                            return mapping;
177:                        }
178:                    }
179:                    if (resourceAdapter instanceof  IContributorResourceAdapter) {
180:                        // Next, use the resource adapter to get a resource and then get
181:                        // the mapping for that resource
182:                        IResource resource = ((IContributorResourceAdapter) resourceAdapter)
183:                                .getAdaptedResource(element);
184:                        if (resource != null) {
185:                            Object mapping = internalGetAdapter(resource,
186:                                    ResourceMapping.class);
187:                            if (mapping instanceof  ResourceMapping) {
188:                                return (ResourceMapping) mapping;
189:                            }
190:                        }
191:                    }
192:                }
193:                return null;
194:            }
195:
196:            static Object internalGetAdapter(Object o, Class adapter) {
197:                if (o instanceof  IAdaptable) {
198:                    IAdaptable element = (IAdaptable) o;
199:                    Object adapted = element.getAdapter(adapter);
200:                    if (adapted != null) {
201:                        return adapted;
202:                    }
203:                }
204:                // Fallback to the adapter manager in case the object doesn't
205:                // implement getAdapter or in the case where the implementation
206:                // doesn't consult the manager
207:                return Platform.getAdapterManager().getAdapter(o, adapter);
208:            }
209:
210:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.