Source Code Cross Referenced for FeatureAdapterFactory.java in  » GIS » udig-1.1 » net » refractions » udig » project » ui » internal » adapters » 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 » GIS » udig 1.1 » net.refractions.udig.project.ui.internal.adapters 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *    uDig - User Friendly Desktop Internet GIS client
003:         *    http://udig.refractions.net
004:         *    (C) 2004, Refractions Research Inc.
005:         *
006:         *    This library is free software; you can redistribute it and/or
007:         *    modify it under the terms of the GNU Lesser General Public
008:         *    License as published by the Free Software Foundation;
009:         *    version 2.1 of the License.
010:         *
011:         *    This library is distributed in the hope that it will be useful,
012:         *    but WITHOUT ANY WARRANTY; without even the implied warranty of
013:         *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014:         *    Lesser General Public License for more details.
015:         *
016:         */
017:        package net.refractions.udig.project.ui.internal.adapters;
018:
019:        import net.refractions.udig.catalog.IGeoResource;
020:        import net.refractions.udig.project.AdaptableFeature;
021:        import net.refractions.udig.project.ui.internal.properties.CoordinatePropertySource;
022:        import net.refractions.udig.project.ui.internal.properties.FeaturePropertySource;
023:        import net.refractions.udig.project.ui.internal.properties.GeomPropertySource;
024:        import net.refractions.udig.project.ui.internal.properties.IGeoResourcePropertySource;
025:
026:        import org.eclipse.core.runtime.IAdaptable;
027:        import org.eclipse.core.runtime.IAdapterFactory;
028:        import org.eclipse.jface.viewers.IContentProvider;
029:        import org.eclipse.jface.viewers.ILabelProvider;
030:        import org.eclipse.jface.viewers.IStructuredContentProvider;
031:        import org.eclipse.jface.viewers.ITableColorProvider;
032:        import org.eclipse.jface.viewers.ITableLabelProvider;
033:        import org.eclipse.jface.viewers.ITreeContentProvider;
034:        import org.eclipse.ui.views.properties.IPropertySource;
035:        import org.eclipse.ui.views.properties.IPropertySource2;
036:        import org.geotools.feature.Feature;
037:        import org.geotools.feature.SimpleFeature;
038:
039:        import com.vividsolutions.jts.geom.Coordinate;
040:        import com.vividsolutions.jts.geom.Geometry;
041:
042:        /**
043:         * Adapts Geotools objects to Eclipse objects, such as Adaptable objects, property sources, etc...
044:         * 
045:         * @author jeichar
046:         * @since 0.3
047:         */
048:        public class FeatureAdapterFactory implements  IAdapterFactory {
049:
050:            static final Class[] adapters = new Class[] {
051:                    IPropertySource2.class, IPropertySource.class,
052:                    ITreeContentProvider.class, ILabelProvider.class,
053:                    IContentProvider.class, IStructuredContentProvider.class,
054:                    ITableLabelProvider.class, ITableColorProvider.class,
055:                    FeatureTableProvider.class, IAdaptable.class };
056:
057:            static final Class[] adaptableClasses = new Class[] {
058:                    Feature.class, Coordinate.class, Coordinate[].class,
059:                    Geometry.class, IGeoResource.class };
060:
061:            /**
062:             * @see org.eclipse.core.runtime.IAdapterFactory#getAdapter(java.lang.Object, java.lang.Class)
063:             */
064:            public Object getAdapter(Object adaptableObject, Class adapterType) {
065:                if (!canAdaptTo(adapterType) || !canAdapt(adaptableObject))
066:                    return null;
067:                if (IPropertySource.class.isAssignableFrom(adapterType)) {
068:                    if (Feature.class.isAssignableFrom(adaptableObject
069:                            .getClass()))
070:                        return createFeaturePropertySource(adaptableObject);
071:
072:                    if (Coordinate.class.isAssignableFrom(adaptableObject
073:                            .getClass()))
074:                        return createCoordinatePropertySource(adaptableObject);
075:
076:                    if (Coordinate[].class.isAssignableFrom(adaptableObject
077:                            .getClass()))
078:                        return createCoordinatePropertySource(adaptableObject);
079:
080:                    if (Geometry.class.isAssignableFrom(adaptableObject
081:                            .getClass()))
082:                        return createGeometryPropertySource(adaptableObject);
083:
084:                    if (IGeoResource.class.isAssignableFrom(adaptableObject
085:                            .getClass()))
086:                        return createServicePropertySource(adaptableObject);
087:                }
088:                if (ITableColorProvider.class.isAssignableFrom(adapterType)
089:                        || ITableLabelProvider.class
090:                                .isAssignableFrom(adapterType)
091:                        || FeatureTableProvider.class
092:                                .isAssignableFrom(adapterType))
093:                    return new FeatureTableProvider();
094:                if (IContentProvider.class.isAssignableFrom(adapterType)
095:                        || ILabelProvider.class.isAssignableFrom(adapterType))
096:                    return new FeatureViewerProvider();
097:
098:                if (IAdaptable.class.isAssignableFrom(adapterType)) {
099:                    if (SimpleFeature.class.isAssignableFrom(adaptableObject
100:                            .getClass()))
101:                        return new AdaptableFeature(
102:                                (SimpleFeature) adaptableObject);
103:                }
104:                return null;
105:            }
106:
107:            /**
108:             * Returns true if the adaptableObject can be adapted to one of the supported adapters.
109:             * 
110:             * @param adaptableObject the object to adapt
111:             * @return true if the adaptableObject can be adapted to one of the supported adapters.
112:             */
113:            public boolean canAdapt(Object adaptableObject) {
114:                for (int i = 0; i < adaptableClasses.length; i++) {
115:                    if (adaptableClasses[i].isAssignableFrom(adaptableObject
116:                            .getClass()))
117:                        return true;
118:                }
119:                return false;
120:            }
121:
122:            /**
123:             * Returns true if this factory can adapt to the adapterType class.
124:             * <p>
125:             * A convenience method that searches the array from getAdapterList()
126:             * </p>
127:             * 
128:             * @param adapterType the class to see if the factory can create an adapter for.
129:             * @return true if an adapter can be made for the type.
130:             */
131:            public boolean canAdaptTo(Class adapterType) {
132:                for (int i = 0; i < adapters.length; i++) {
133:                    if (adapterType.isAssignableFrom(adapters[i]))
134:                        return true;
135:                }
136:                return false;
137:            }
138:
139:            /**
140:             * Creates a PropertySource for Features
141:             * 
142:             * @param adaptableObject
143:             * @return a PropertySource for Features
144:             */
145:            private IPropertySource2 createFeaturePropertySource(
146:                    Object adaptableObject) {
147:                return new FeaturePropertySource((Feature) adaptableObject);
148:            }
149:
150:            /**
151:             * Creates a PropertySource for Features
152:             * 
153:             * @param adaptableObject
154:             * @return a PropertySource for Features
155:             */
156:            private IPropertySource2 createCoordinatePropertySource(
157:                    Object adaptableObject) {
158:                return new CoordinatePropertySource(
159:                        (Coordinate) adaptableObject);
160:            }
161:
162:            /**
163:             * Creates a PropertySource for Features
164:             * 
165:             * @param adaptableObject
166:             * @return a PropertySource for Features
167:             */
168:            private IPropertySource2 createGeometryPropertySource(
169:                    Object adaptableObject) {
170:                return new GeomPropertySource((Geometry) adaptableObject);
171:            }
172:
173:            /**
174:             * Creates a PropertySource for Features
175:             * 
176:             * @param adaptableObject
177:             * @return a PropertySource for Features
178:             */
179:            private IPropertySource2 createServicePropertySource(
180:                    Object adaptableObject) {
181:                return new IGeoResourcePropertySource(
182:                        (IGeoResource) adaptableObject);
183:            }
184:
185:            /**
186:             * @see org.eclipse.core.runtime.IAdapterFactory#getAdapterList()
187:             */
188:            public Class[] getAdapterList() {
189:                Class[] c = new Class[adapters.length];
190:                System.arraycopy(adapters, 0, c, 0, c.length);
191:                return c;
192:            }
193:
194:        }
ww___w__._j__av___a_2__s_.c__o___m | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.