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;
018:
019: import net.refractions.udig.project.internal.Project;
020: import net.refractions.udig.project.internal.ProjectPlugin;
021:
022: import org.eclipse.core.runtime.IAdaptable;
023: import org.eclipse.core.runtime.Platform;
024: import org.geotools.feature.Feature;
025: import org.geotools.feature.FeatureCollection;
026: import org.geotools.feature.FeatureType;
027: import org.geotools.feature.IllegalAttributeException;
028:
029: import com.vividsolutions.jts.geom.Envelope;
030: import com.vividsolutions.jts.geom.Geometry;
031:
032: /**
033: * TODO Purpose of net.refractions.udig.project
034: * <p>
035: * </p>
036: *
037: * @author Jesse
038: * @since 1.0.0
039: */
040: public class AdaptableFeature implements IAdaptable, Feature,
041: UDIGAdaptableDecorator {
042:
043: private Feature feature;
044: private ILayer layer;
045:
046: /**
047: * Construct <code>AdaptableFeature</code>.
048: *
049: * @param feature the wrapped feature
050: * @param evaluationObject the layer that contains the feature.
051: */
052: public AdaptableFeature(Feature feature) {
053: this .feature = feature;
054: }
055:
056: /**
057: * Construct <code>AdaptableFeature</code>.
058: *
059: * @param feature the wrapped feature
060: * @param layer the layer that contains the feature.
061: */
062: public AdaptableFeature(Feature feature, ILayer layer) {
063: this .feature = feature;
064: this .layer = layer;
065: }
066:
067: /**
068: * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class)
069: */
070: public Object getAdapter(Class adapter) {
071: if (ILayer.class.isAssignableFrom(adapter)) {
072: if (layer != null)
073: return layer;
074:
075: for (Project project : ProjectPlugin.getPlugin()
076: .getProjectRegistry().getProjects()) {
077: for (IMap current : project.getElements(IMap.class)) {
078: if (containsThis(current))
079: return current.getEditManager().getEditLayer();
080: }
081: }
082: }
083: return Platform.getAdapterManager().getAdapter(this , adapter);
084: }
085:
086: /**
087: * @see org.geotools.feature.Feature#getParent()
088: */
089: @SuppressWarnings("deprecation")
090: public FeatureCollection getParent() {
091: return feature.getParent();
092: }
093:
094: /**
095: * @see org.geotools.feature.Feature#setParent(org.geotools.feature.FeatureCollection)
096: */
097: public void setParent(FeatureCollection collection) {
098: feature.setParent(collection);
099: }
100:
101: /**
102: * @see org.geotools.feature.Feature#getFeatureType()
103: */
104: public FeatureType getFeatureType() {
105: return feature.getFeatureType();
106: }
107:
108: /**
109: * @see org.geotools.feature.Feature#getID()
110: */
111: public String getID() {
112: return feature.getID();
113: }
114:
115: /**
116: * @see org.geotools.feature.Feature#getAttributes(java.lang.Object[])
117: */
118: public Object[] getAttributes(Object[] attributes) {
119: return feature.getAttributes(attributes);
120: }
121:
122: /**
123: * @see org.geotools.feature.Feature#getAttribute(java.lang.String)
124: */
125: public Object getAttribute(String xPath) {
126: return feature.getAttribute(xPath);
127: }
128:
129: /**
130: * @see org.geotools.feature.Feature#getAttribute(int)
131: */
132: public Object getAttribute(int index) {
133: return feature.getAttribute(index);
134: }
135:
136: /**
137: * @see org.geotools.feature.Feature#setAttribute(int, java.lang.Object)
138: */
139: public void setAttribute(int position, Object val)
140: throws IllegalAttributeException,
141: ArrayIndexOutOfBoundsException {
142: feature.setAttribute(position, val);
143: }
144:
145: /**
146: * @see org.geotools.feature.Feature#getNumberOfAttributes()
147: */
148: public int getNumberOfAttributes() {
149: return feature.getNumberOfAttributes();
150: }
151:
152: /**
153: * @see org.geotools.feature.Feature#setAttribute(java.lang.String, java.lang.Object)
154: */
155: public void setAttribute(String xPath, Object attribute)
156: throws IllegalAttributeException {
157: feature.setAttribute(xPath, attribute);
158: }
159:
160: /**
161: * @see org.geotools.feature.Feature#getDefaultGeometry()
162: */
163: public Geometry getDefaultGeometry() {
164: return feature.getDefaultGeometry();
165: }
166:
167: /**
168: * @see org.geotools.feature.Feature#setDefaultGeometry(com.vividsolutions.jts.geom.Geometry)
169: */
170: public void setDefaultGeometry(Geometry geometry)
171: throws IllegalAttributeException {
172: feature.setDefaultGeometry(geometry);
173: }
174:
175: /**
176: * @see org.geotools.feature.Feature#getBounds()
177: */
178: public Envelope getBounds() {
179: return feature.getBounds();
180: }
181:
182: /**
183: * @see java.lang.Object#equals(java.lang.Object)
184: */
185: public boolean equals(Object obj) {
186: return feature.equals(obj);
187: }
188:
189: /**
190: * @see java.lang.Object#hashCode()
191: */
192: public int hashCode() {
193: return feature.hashCode();
194: }
195:
196: /**
197: * @see net.refractions.udig.project.ui.internal.adapters.UDIGAdaptableDecorator#getObject()
198: */
199: public Object getObject() {
200: return feature;
201: }
202:
203: private boolean containsThis(IMap map) {
204: if (map.getEditManager() == null)
205: return false;
206: return map.getEditManager().getEditFeature() == this
207: || map.getEditManager().getEditFeature() == feature;
208: }
209:
210: @Override
211: public String toString() {
212: return feature.toString();
213: }
214: }
|