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


0001:        /**
0002:         * <copyright></copyright> $Id: LayerImpl.java 25737 2007-06-05 09:45:54Z jeichar $
0003:         */package net.refractions.udig.project.internal.impl;
0004:
0005:        import java.awt.Color;
0006:        import java.awt.geom.AffineTransform;
0007:        import java.io.IOException;
0008:        import java.lang.reflect.InvocationTargetException;
0009:        import java.net.URL;
0010:        import java.util.ArrayList;
0011:        import java.util.Collection;
0012:        import java.util.Collections;
0013:        import java.util.Iterator;
0014:        import java.util.List;
0015:        import java.util.concurrent.CopyOnWriteArraySet;
0016:        import java.util.concurrent.atomic.AtomicBoolean;
0017:        import java.util.concurrent.locks.Lock;
0018:
0019:        import net.refractions.udig.catalog.CatalogPlugin;
0020:        import net.refractions.udig.catalog.ICatalog;
0021:        import net.refractions.udig.catalog.IGeoResource;
0022:        import net.refractions.udig.catalog.IGeoResourceInfo;
0023:        import net.refractions.udig.catalog.IResolve;
0024:        import net.refractions.udig.catalog.IResolveChangeEvent;
0025:        import net.refractions.udig.catalog.IResolveDelta;
0026:        import net.refractions.udig.catalog.URLUtils;
0027:        import net.refractions.udig.catalog.IResolve.Status;
0028:        import net.refractions.udig.catalog.IResolveDelta.Kind;
0029:        import net.refractions.udig.catalog.util.SearchIDDeltaVisitor;
0030:        import net.refractions.udig.project.IBlackboard;
0031:        import net.refractions.udig.project.ILayer;
0032:        import net.refractions.udig.project.ILayerListener;
0033:        import net.refractions.udig.project.IMap;
0034:        import net.refractions.udig.project.LayerEvent;
0035:        import net.refractions.udig.project.internal.CatalogRef;
0036:        import net.refractions.udig.project.internal.ContextModel;
0037:        import net.refractions.udig.project.internal.Layer;
0038:        import net.refractions.udig.project.internal.Messages;
0039:        import net.refractions.udig.project.internal.ProjectFactory;
0040:        import net.refractions.udig.project.internal.ProjectPackage;
0041:        import net.refractions.udig.project.internal.ProjectPlugin;
0042:        import net.refractions.udig.project.internal.SimpleBlackboard;
0043:        import net.refractions.udig.project.internal.StyleBlackboard;
0044:        import net.refractions.udig.project.internal.Trace;
0045:        import net.refractions.udig.ui.PlatformGIS;
0046:        import net.refractions.udig.ui.ProgressManager;
0047:        import net.refractions.udig.ui.UDIGDisplaySafeLock;
0048:        import net.refractions.udig.ui.palette.ColourScheme;
0049:
0050:        import org.eclipse.core.runtime.IProgressMonitor;
0051:        import org.eclipse.core.runtime.ISafeRunnable;
0052:        import org.eclipse.core.runtime.NullProgressMonitor;
0053:        import org.eclipse.emf.common.notify.Adapter;
0054:        import org.eclipse.emf.common.notify.Notification;
0055:        import org.eclipse.emf.common.notify.NotificationChain;
0056:        import org.eclipse.emf.common.notify.impl.AdapterImpl;
0057:        import org.eclipse.emf.common.util.BasicEList;
0058:        import org.eclipse.emf.common.util.EList;
0059:        import org.eclipse.emf.ecore.EClass;
0060:        import org.eclipse.emf.ecore.EObject;
0061:        import org.eclipse.emf.ecore.EStructuralFeature;
0062:        import org.eclipse.emf.ecore.InternalEObject;
0063:        import org.eclipse.emf.ecore.impl.ENotificationImpl;
0064:        import org.eclipse.emf.ecore.impl.EObjectImpl;
0065:        import org.eclipse.emf.ecore.util.EDataTypeUniqueEList;
0066:        import org.eclipse.emf.ecore.util.EcoreUtil;
0067:        import org.eclipse.jface.operation.IRunnableWithProgress;
0068:        import org.eclipse.jface.resource.ImageDescriptor;
0069:        import org.eclipse.swt.widgets.Display;
0070:        import org.eclipse.ui.PlatformUI;
0071:        import org.eclipse.ui.model.IWorkbenchAdapter;
0072:        import org.eclipse.ui.model.WorkbenchAdapter;
0073:        import org.geotools.data.DefaultQuery;
0074:        import org.geotools.data.FeatureEvent;
0075:        import org.geotools.data.FeatureListener;
0076:        import org.geotools.data.FeatureSource;
0077:        import org.geotools.data.Query;
0078:        import org.geotools.feature.FeatureType;
0079:        import org.geotools.filter.BBoxExpression;
0080:        import org.geotools.filter.Filter;
0081:        import org.geotools.filter.FilterFactory;
0082:        import org.geotools.filter.FilterFactoryFinder;
0083:        import org.geotools.filter.FilterType;
0084:        import org.geotools.filter.GeometryFilter;
0085:        import org.geotools.geometry.jts.JTS;
0086:        import org.geotools.geometry.jts.ReferencedEnvelope;
0087:        import org.geotools.referencing.CRS;
0088:        import org.geotools.referencing.FactoryFinder;
0089:        import org.geotools.referencing.crs.DefaultGeographicCRS;
0090:        import org.geotools.referencing.operation.matrix.GeneralMatrix;
0091:        import org.opengis.referencing.crs.CoordinateReferenceSystem;
0092:        import org.opengis.referencing.operation.MathTransform;
0093:        import org.opengis.referencing.operation.MathTransform2D;
0094:        import org.opengis.referencing.operation.TransformException;
0095:
0096:        import com.vividsolutions.jts.geom.Coordinate;
0097:        import com.vividsolutions.jts.geom.Envelope;
0098:
0099:        /**
0100:         * Standard implementation of a Layer.
0101:         * 
0102:         * @author Jesse
0103:         * @since 1.0.0
0104:         * @generated
0105:         */
0106:        public class LayerImpl extends EObjectImpl implements  Layer {
0107:            /**
0108:             * <!-- begin-user-doc --> <!-- end-user-doc -->
0109:             * @generated
0110:             */
0111:            public static final String copyright = "uDig - User Friendly Desktop Internet GIS client http://udig.refractions.net (C) 2004, Refractions Research Inc. This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; version 2.1 of the License. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details."; //$NON-NLS-1$
0112:
0113:            /** <code>IDENTITY</code> transform */
0114:            public static final MathTransform2D IDENTITY;
0115:            static {
0116:                MathTransform2D t = null;
0117:                try {
0118:                    t = (MathTransform2D) FactoryFinder
0119:                            .getMathTransformFactory(null)
0120:                            .createAffineTransform(
0121:                                    new GeneralMatrix(new AffineTransform()));
0122:                } catch (Exception e1) {
0123:                    // should not occur
0124:                }
0125:                IDENTITY = t;
0126:            }
0127:
0128:            /**
0129:             * The default value of the '{@link #getFilter() <em>Filter</em>}' attribute. 
0130:             * @see #getFilter()
0131:             * @generated NOT
0132:             * @ordered
0133:             */
0134:            protected static final Filter FILTER_EDEFAULT = Filter.ALL;
0135:
0136:            /**
0137:             * The cached value of the '{@link #getFilter() <em>Filter</em>}' attribute. <!--
0138:             * begin-user-doc --> <!-- end-user-doc -->
0139:             * 
0140:             * @see #getFilter()
0141:             * @generated NOT
0142:             * @ordered
0143:             */
0144:            protected volatile Filter filter = FILTER_EDEFAULT;
0145:
0146:            /**
0147:             * The cached value of the '{@link #getStyleBlackboard() <em>Style Blackboard</em>}'
0148:             * containment reference. <!-- begin-user-doc --> <!-- end-user-doc -->
0149:             * 
0150:             * @see #getStyleBlackboard()
0151:             * @generated NOT
0152:             * @ordered
0153:             */
0154:            protected volatile StyleBlackboard styleBlackboard = ProjectFactory.eINSTANCE
0155:                    .createStyleBlackboard();
0156:
0157:            /**
0158:             * The default value of the '{@link #getZorder() <em>Zorder</em>}' attribute. <!--
0159:             * begin-user-doc --> <!-- end-user-doc -->
0160:             * 
0161:             * @see #getZorder()
0162:             * @generated
0163:             * @ordered
0164:             */
0165:            protected static final int ZORDER_EDEFAULT = 0;
0166:
0167:            /**
0168:             * The default value of the '{@link #getStatus() <em>Status</em>}' attribute. <!--
0169:             * begin-user-doc --> <!-- end-user-doc -->
0170:             * 
0171:             * @see #getStatus()
0172:             * @generated
0173:             * @ordered
0174:             */
0175:            protected static final int STATUS_EDEFAULT = 0;
0176:
0177:            /**
0178:             * The following adapter registers itself with a contextmodel when one is assigned it also
0179:             * deregisters itself when reassigned.
0180:             * <p>
0181:             * As for functionality the adapter listens for zorder changes and notifies its listeners when a
0182:             * change occurs
0183:             * </p>
0184:             */
0185:            Adapter contextModelAdapter = new AdapterImpl() {
0186:                /**
0187:                 * @see org.eclipse.emf.common.notify.impl.AdapterImpl#notifyChanged(org.eclipse.emf.common.notify.Notification)
0188:                 */
0189:                @SuppressWarnings("unchecked")
0190:                public void notifyChanged(Notification msg) {
0191:                    registerWithContainers(msg);
0192:                    raiseEvents(msg);
0193:
0194:                }
0195:
0196:                private void raiseEvents(Notification msg) {
0197:                    switch (msg.getFeatureID(Layer.class)) {
0198:                    case ProjectPackage.LAYER__FILTER:
0199:                        fireLayerChange(new LayerEvent(LayerImpl.this ,
0200:                                LayerEvent.EventType.FILTER, msg.getOldValue(),
0201:                                msg.getNewValue()));
0202:                        break;
0203:                    case ProjectPackage.LAYER__NAME:
0204:                        fireLayerChange(new LayerEvent(LayerImpl.this ,
0205:                                LayerEvent.EventType.NAME, msg.getOldValue(),
0206:                                msg.getNewValue()));
0207:                        break;
0208:                    case ProjectPackage.LAYER__GEO_RESOURCES:
0209:                        fireLayerChange(new LayerEvent(LayerImpl.this ,
0210:                                LayerEvent.EventType.RESOURCE, msg
0211:                                        .getOldValue(), msg.getNewValue()));
0212:                        break;
0213:                    case ProjectPackage.LAYER__VISIBLE:
0214:                        fireLayerChange(new LayerEvent(LayerImpl.this ,
0215:                                LayerEvent.EventType.VISIBILITY, msg
0216:                                        .getOldValue(), msg.getNewValue()));
0217:                        break;
0218:                    case ProjectPackage.LAYER__ZORDER:
0219:                        fireLayerChange(new LayerEvent(LayerImpl.this ,
0220:                                LayerEvent.EventType.ZORDER, msg.getOldValue(),
0221:                                msg.getNewValue()));
0222:                        break;
0223:                    case ProjectPackage.LAYER__FEATURE_CHANGES:
0224:                        fireLayerChange(new LayerEvent(LayerImpl.this ,
0225:                                LayerEvent.EventType.EDIT_EVENT, msg
0226:                                        .getOldValue(), msg.getNewValue()));
0227:                        break;
0228:
0229:                    default:
0230:                        break;
0231:                    }
0232:                }
0233:
0234:                @SuppressWarnings("unchecked")
0235:                private void registerWithContainers(Notification msg) {
0236:                    // register itself with container objects
0237:                    switch (msg.getEventType()) {
0238:                    case Notification.SET: {
0239:                        if (msg.getFeatureID(Layer.class) == ProjectPackage.LAYER__CONTEXT_MODEL) {
0240:                            if (msg.getOldValue() instanceof  ContextModel)
0241:                                ((ContextModel) msg.getOldValue()).eAdapters()
0242:                                        .remove(this );
0243:                            if (msg.getNewValue() instanceof  ContextModel)
0244:                                ((ContextModel) msg.getNewValue()).eAdapters()
0245:                                        .add(this );
0246:                        }
0247:                        return;
0248:                    }
0249:                    case Notification.MOVE: {
0250:                        if (msg.getFeatureID(Layer.class) == ProjectPackage.LAYER__CONTEXT_MODEL)
0251:                            if (LayerImpl.this .eNotificationRequired())
0252:                                zorderNotify(((Integer) msg.getOldValue())
0253:                                        .intValue(),
0254:                                        ((Layer) msg.getNewValue()).getZorder());
0255:                        return;
0256:                    }
0257:                    }// switch
0258:                }
0259:            };
0260:
0261:            FeatureListener featureListener = new FeatureListener() {
0262:
0263:                public void changed(FeatureEvent featureEvent) {
0264:                    try {
0265:                        FeatureSource featureSource = featureEvent
0266:                                .getFeatureSource();
0267:                        FeatureSource resource = getResource(
0268:                                FeatureSource.class, new NullProgressMonitor());
0269:                        if (resource instanceof  UDIGFeatureStore) {
0270:                            UDIGFeatureStore layerResource = (UDIGFeatureStore) resource;
0271:                            if (featureSource != layerResource.wrapped)
0272:                                featureSource.removeFeatureListener(this );
0273:
0274:                        }
0275:                    } catch (IOException e) {
0276:                        ProjectPlugin.log("", e); //$NON-NLS-1$
0277:                    }
0278:                    if (featureEvent.getBounds() != null) {
0279:                        if (featureEvent.getEventType() == FeatureEvent.FEATURES_ADDED
0280:                                || featureEvent.getEventType() == FeatureEvent.FEATURES_CHANGED) {
0281:                            if (bounds == null) {
0282:                                ReferencedEnvelope bounds2;
0283:                                try {
0284:                                    bounds2 = getGeoResource().getInfo(
0285:                                            new NullProgressMonitor())
0286:                                            .getBounds();
0287:                                } catch (IOException e) {
0288:                                    bounds2 = new ReferencedEnvelope(getCRS());
0289:                                }
0290:                                if (bounds2 == null
0291:                                        || bounds2.isNull()
0292:                                        || !bounds2.contains(featureEvent
0293:                                                .getBounds())) {
0294:                                    if (bounds2 == null)
0295:                                        bounds2 = new ReferencedEnvelope(
0296:                                                getCRS());
0297:                                    bounds = bounds2;
0298:                                }
0299:                            } else {
0300:                                bounds
0301:                                        .expandToInclude(featureEvent
0302:                                                .getBounds());
0303:                            }
0304:                        }
0305:                        getFeatureChanges().add(featureEvent);
0306:                    } else {
0307:                        if (getFeatureChanges().size() != 0) {
0308:                            bounds = null;
0309:                            getFeatureChanges().clear();
0310:                        }
0311:                    }
0312:
0313:                }
0314:            };
0315:
0316:            /**
0317:             * Listeners to this layer.
0318:             * <p>
0319:             * Note this will need to be hooked into the usual EMF adapater mechasim.
0320:             * </p>
0321:             */
0322:            CopyOnWriteArraySet<ILayerListener> listeners = new CopyOnWriteArraySet<ILayerListener>();
0323:
0324:            /**
0325:             * Ensures that a warning about georesources not found is only logged once
0326:             */
0327:            private volatile boolean warned = false;
0328:            /**
0329:             * Lock used for wait and notify. ONLY used by {@link #getGeoResources()}!.
0330:             */
0331:            private final Lock geoResourceLock = new UDIGDisplaySafeLock();
0332:            /**
0333:             * Lock used for protecting {@link #getGeoResource()}. ONLY used by getGeoResource()!.
0334:             */
0335:            private final Lock geoResourceCacheLock = new UDIGDisplaySafeLock();
0336:
0337:            /**
0338:             * indicates whether or not the CRS is a known CRS (the georesources return null when asked for a CRS).
0339:             * If null then it has not been computed yet.  if false and crsLoader !=null then it is being computed. 
0340:             */
0341:            private volatile AtomicBoolean unknownCRS;
0342:
0343:            /**
0344:             * Used in {@link #isUnknownCRS()} to lazily compute the CRS.  If null and unknownCRS is null then 
0345:             * the crs has not been computed.  if not null then the computatin is taking place.
0346:             */
0347:            private volatile ISafeRunnable crsLoader;
0348:
0349:            private Lock unknownCRSLock = new UDIGDisplaySafeLock();
0350:
0351:            /**
0352:             * <!-- begin-user-doc --> <!-- end-user-doc -->
0353:             * 
0354:             * @generated NOT
0355:             */
0356:            @SuppressWarnings("unchecked")
0357:            protected LayerImpl() {
0358:                super ();
0359:                eAdapters().add(contextModelAdapter);
0360:                CatalogPlugin.addListener(this );
0361:            }
0362:
0363:            @Override
0364:            protected void finalize() throws Throwable {
0365:                CatalogPlugin.removeListener(this );
0366:            }
0367:
0368:            /*
0369:             * @see net.refractions.udig.project.Layer#addListener(net.refractions.udig.project.LayerListener)
0370:             */
0371:            public void addListener(final ILayerListener listener) {
0372:                listeners.add(listener);
0373:            }
0374:
0375:            /*
0376:             * @see net.refractions.udig.project.Layer#removeListener(net.refractions.udig.project.LayerListener)
0377:             */
0378:            public void removeListener(final ILayerListener listener) {
0379:                listeners.remove(listener);
0380:            }
0381:
0382:            protected void fireLayerChange(LayerEvent event) {
0383:                for (ILayerListener listener : listeners) {
0384:                    try {
0385:                        if (listener != null)
0386:                            listener.refresh(event);
0387:                    } catch (Throwable t) {
0388:                        ProjectPlugin.log("", t); //$NON-NLS-1$
0389:                    }
0390:                }
0391:            }
0392:
0393:            protected void zorderNotify(int old, int current) {
0394:                if (old == current)
0395:                    return;
0396:                ENotificationImpl notification = new ENotificationImpl(
0397:                        LayerImpl.this , Notification.SET,
0398:                        ProjectPackage.LAYER__ZORDER, old, current,
0399:                        old == current);
0400:                LayerImpl.this .eNotify(notification);
0401:            }
0402:
0403:            /**
0404:             * <!-- begin-user-doc --> <!-- end-user-doc -->
0405:             * @generated
0406:             */
0407:            protected EClass eStaticClass() {
0408:                return ProjectPackage.eINSTANCE.getLayer();
0409:            }
0410:
0411:            /**
0412:             * <!-- begin-user-doc --> <!-- end-user-doc -->
0413:             * @generated
0414:             */
0415:            public ContextModel getContextModel() {
0416:                if (eContainerFeatureID != ProjectPackage.LAYER__CONTEXT_MODEL)
0417:                    return null;
0418:                return (ContextModel) eContainer;
0419:            }
0420:
0421:            /**
0422:             * <!-- begin-user-doc --> <!-- end-user-doc -->
0423:             * @generated
0424:             */
0425:            public void setContextModel(ContextModel newContextModel) {
0426:                if (newContextModel != eContainer
0427:                        || (eContainerFeatureID != ProjectPackage.LAYER__CONTEXT_MODEL && newContextModel != null)) {
0428:                    if (EcoreUtil.isAncestor(this , (EObject) newContextModel))
0429:                        throw new IllegalArgumentException(
0430:                                "Recursive containment not allowed for " + toString()); //$NON-NLS-1$
0431:                    NotificationChain msgs = null;
0432:                    if (eContainer != null)
0433:                        msgs = eBasicRemoveFromContainer(msgs);
0434:                    if (newContextModel != null)
0435:                        msgs = ((InternalEObject) newContextModel).eInverseAdd(
0436:                                this , ProjectPackage.CONTEXT_MODEL__LAYERS,
0437:                                ContextModel.class, msgs);
0438:                    msgs = eBasicSetContainer(
0439:                            (InternalEObject) newContextModel,
0440:                            ProjectPackage.LAYER__CONTEXT_MODEL, msgs);
0441:                    if (msgs != null)
0442:                        msgs.dispatch();
0443:                } else if (eNotificationRequired())
0444:                    eNotify(new ENotificationImpl(this , Notification.SET,
0445:                            ProjectPackage.LAYER__CONTEXT_MODEL,
0446:                            newContextModel, newContextModel));
0447:            }
0448:
0449:            public int getZorder() {
0450:                if (getContextModel() == null)
0451:                    return Integer.MAX_VALUE;
0452:                return getMap().getMapLayers().indexOf(this );
0453:            }
0454:
0455:            /**
0456:             * <!-- begin-user-doc --> <!-- end-user-doc -->
0457:             * 
0458:             * @generated NOT
0459:             */
0460:            @SuppressWarnings("unchecked")
0461:            public void setZorder(int newZorder) {
0462:                if (getContextModel() == null
0463:                        || getMapInternal().getLayersInternal() == null) {
0464:                    return;
0465:                }
0466:
0467:                if (newZorder >= getMapInternal().getLayersInternal().size())
0468:                    ((EList) getMapInternal().getLayersInternal()).move(
0469:                            getMapInternal().getLayersInternal().size() - 1,
0470:                            getMapInternal().getLayersInternal().indexOf(this ));
0471:                else
0472:                    ((EList) getMapInternal().getLayersInternal()).move(
0473:                            newZorder, getMapInternal().getLayersInternal()
0474:                                    .indexOf(this ));
0475:            }
0476:
0477:            /**
0478:             * <!-- begin-user-doc --> <!-- end-user-doc -->
0479:             * @generated
0480:             */
0481:            public String getName() {
0482:                return name;
0483:            }
0484:
0485:            /**
0486:             * <!-- begin-user-doc --> <!-- end-user-doc -->
0487:             * @generated
0488:             */
0489:            public void setName(String newName) {
0490:                String oldName = name;
0491:                name = newName;
0492:                if (eNotificationRequired())
0493:                    eNotify(new ENotificationImpl(this , Notification.SET,
0494:                            ProjectPackage.LAYER__NAME, oldName, name));
0495:            }
0496:
0497:            /**
0498:             * <!-- begin-user-doc --> <!-- end-user-doc -->
0499:             * @generated
0500:             */
0501:            public URL getID() {
0502:                return iD;
0503:            }
0504:
0505:            /**
0506:             * <!-- begin-user-doc --> <!-- end-user-doc -->
0507:             * @generated
0508:             */
0509:            public void setID(URL newID) {
0510:                URL oldID = iD;
0511:                iD = newID;
0512:                if (eNotificationRequired())
0513:                    eNotify(new ENotificationImpl(this , Notification.SET,
0514:                            ProjectPackage.LAYER__ID, oldID, iD));
0515:            }
0516:
0517:            /**
0518:             * <!-- begin-user-doc --> <!-- end-user-doc -->
0519:             * @generated
0520:             */
0521:            public boolean isVisible() {
0522:                return visible;
0523:            }
0524:
0525:            /**
0526:             * <!-- begin-user-doc --> <!-- end-user-doc -->
0527:             * @generated
0528:             */
0529:            public void setVisible(boolean newVisible) {
0530:                boolean oldVisible = visible;
0531:                visible = newVisible;
0532:                if (eNotificationRequired())
0533:                    eNotify(new ENotificationImpl(this , Notification.SET,
0534:                            ProjectPackage.LAYER__VISIBLE, oldVisible, visible));
0535:            }
0536:
0537:            /**
0538:             * <!-- begin-user-doc --> Used to find the associated service in the catalog.
0539:             * <p>
0540:             * On the off chance *no* services exist an empty list is returned. All this means is that the
0541:             * service is down, or the user has not connected to it yet (perhaps they are waiting on
0542:             * security permissions.
0543:             * </p>
0544:             * <p>
0545:             * When the real service comes along we will find out based on catalog events.
0546:             * </p>
0547:             * <b>New implementation of the method:
0548:             * <p>
0549:             * getGeoResource() is a blocking method but it must not block UI thread. With this
0550:             * purpose the new imlementation is done to avoid UI thread blocking because of
0551:             * synchronization.
0552:             * </b>
0553:             * 
0554:             * <!-- end-user-doc -->
0555:             * 
0556:             * @uml.property name="geoResources"
0557:             * @generated NOT
0558:             */
0559:            @SuppressWarnings("unchecked")
0560:            public List<IGeoResource> getGeoResources() {
0561:
0562:                assert assertNotInDisplayAccess();
0563:
0564:                if (eIsProxy() || getMap() == null)
0565:                    return geoResources == null ? NULL : geoResources;
0566:
0567:                if (geoResources != null || geoResources == NULL)
0568:                    return geoResources;
0569:
0570:                geoResourceLock.lock();
0571:                gettingResources.set(true);
0572:                try {
0573:
0574:                    final URL id = getID();
0575:                    if (id == null) {
0576:                        return NULL;
0577:                    }
0578:
0579:                    if (geoResources != null && geoResources != NULL)
0580:                        return geoResources;
0581:
0582:                    if (!catalogRef.isLoaded()) {
0583:                        catalogRef.load();
0584:                    }
0585:                    final List<IGeoResource> resourceList = new ArrayList<IGeoResource>();
0586:
0587:                    final ICatalog connections = CatalogPlugin.getDefault()
0588:                            .getLocalCatalog();
0589:
0590:                    try {
0591:                        IProgressMonitor monitor = new NullProgressMonitor();
0592:
0593:                        IRunnableWithProgress object = new IRunnableWithProgress() {
0594:                            public void run(IProgressMonitor monitor)
0595:                                    throws InvocationTargetException {
0596:                                try {
0597:                                    List<IResolve> resources = connections
0598:                                            .find(getID(), monitor);
0599:                                    for (IResolve resolve : resources) {
0600:                                        if (resolve.getStatus() == Status.BROKEN
0601:                                                || resolve.getStatus() == Status.BROKEN)
0602:                                            continue;
0603:                                        if (resolve instanceof  IGeoResource)
0604:                                            resourceList.add(new LayerResource(
0605:                                                    LayerImpl.this ,
0606:                                                    (IGeoResource) resolve));
0607:                                    }
0608:                                } catch (Exception e) {
0609:                                    throw new InvocationTargetException(e);
0610:                                }
0611:                            }
0612:                        };
0613:                        if (Display.getCurrent() != null)
0614:                            PlatformGIS.runBlockingOperation(object, monitor);
0615:                        else {
0616:                            object.run(monitor);
0617:                        }
0618:                    } catch (Exception e) {
0619:                        ProjectPlugin.log("Error getting layer resources", e); //$NON-NLS-1$
0620:                    }
0621:
0622:                    if (resourceList.size() == 0) {
0623:                        if (!warned) {
0624:                            ProjectPlugin
0625:                                    .log("Layer: " + getName() + " could not find a GeoResource with id:" + getID()); //$NON-NLS-1$//$NON-NLS-2$
0626:                            warned = true;
0627:                        }
0628:                        setStatus(ERROR);
0629:                        setStatusMessage(Messages.LayerImpl_connectionFailed);
0630:                        geoResources = NULL;
0631:                    } else {
0632:                        eSetDeliver(false);
0633:                        geoResources = new EDataTypeUniqueEList(
0634:                                IGeoResource.class, this ,
0635:                                ProjectPackage.LAYER__GEO_RESOURCES);
0636:                        geoResources.addAll(resourceList);
0637:                        eSetDeliver(true);
0638:
0639:                        if (status == ERROR
0640:                                && statusMessage
0641:                                        .equals(Messages.LayerImpl_connectionFailed)) {
0642:                            setStatus(ILayer.DONE);
0643:                            setStatusMessage(""); //$NON-NLS-1$
0644:                        }
0645:                    }
0646:                } finally {
0647:
0648:                    gettingResources.set(false);
0649:                    geoResourceLock.unlock();
0650:                }
0651:                return geoResources;
0652:            }
0653:
0654:            private boolean assertNotInDisplayAccess() {
0655:                if (Display.getCurrent() != null) {
0656:                    //            ProjectPlugin.log("getGeoResources was called in display Thread", new Exception("JUST A WARNING NOT CRITICAL")); //$NON-NLS-1$ //$NON-NLS-2$
0657:                }
0658:                return true;
0659:            }
0660:
0661:            /**
0662:             * will be returned by getGeoResources and getGeoResource in the real connection is broken.
0663:             */
0664:            static public final EList NULL;
0665:            static {
0666:                NULL = new BasicEList(Collections
0667:                        .singletonList(new NullGeoResource()));
0668:            }
0669:
0670:            /**
0671:             * @see net.refractions.udig.project.internal.Layer#getGeoResources(int)
0672:             * @deprecated
0673:             */
0674:            public <T> IGeoResource getGeoResource(Class<T> clazz) {
0675:                List<IGeoResource> resources = getGeoResources();
0676:                for (IGeoResource resource : resources) {
0677:                    if (resource.canResolve(clazz))
0678:                        return resource;
0679:                }
0680:
0681:                return null;
0682:            }
0683:
0684:            public IGeoResource getGeoResource() {
0685:                if (geoResource == null) {
0686:                    geoResourceCacheLock.lock();
0687:                    try {
0688:                        if (geoResource == null) {
0689:                            if (getGeoResources() != NULL
0690:                                    && getGeoResources().size() > 0)
0691:                                geoResource = getGeoResources().get(0);
0692:                            else {
0693:                                return (IGeoResource) NULL.get(0);
0694:                            }
0695:                        }
0696:                    } finally {
0697:                        geoResourceCacheLock.unlock();
0698:                    }
0699:                }
0700:                return geoResource;
0701:            }
0702:
0703:            /**
0704:             * <!-- begin-user-doc --> <!-- end-user-doc -->
0705:             * 
0706:             * @uml.property name="geoResource"
0707:             * @generated NOT
0708:             */
0709:            public void setGeoResource(IGeoResource newPreferredGeoResource) {
0710:                IGeoResource oldPreferredGeoResource = geoResource;
0711:                geoResource = newPreferredGeoResource;
0712:                if (eNotificationRequired())
0713:                    eNotify(new ENotificationImpl(this , Notification.SET,
0714:                            ProjectPackage.LAYER__GEO_RESOURCE,
0715:                            oldPreferredGeoResource, geoResource));
0716:            }
0717:
0718:            public <E> E getResource(Class<E> resourceType,
0719:                    IProgressMonitor monitor) throws IOException {
0720:
0721:                IProgressMonitor monitor2 = monitor;
0722:                if (monitor2 == null)
0723:                    monitor2 = ProgressManager.instance().get();
0724:                try {
0725:                    for (IGeoResource georesource : getGeoResources()) {
0726:                        if (georesource.canResolve(resourceType)) {
0727:                            return georesource.resolve(resourceType, monitor2);
0728:                        }
0729:                    }
0730:                    return null;
0731:                } finally {
0732:                    monitor2.done();
0733:                }
0734:            }
0735:
0736:            /**
0737:             * <!-- begin-user-doc --> <!-- end-user-doc -->
0738:             * 
0739:             * @uml.property name="catalogRef"
0740:             * @generated NOT
0741:             */
0742:            public CatalogRef getCatalogRef() {
0743:                if (catalogRef.getLayer() != this )
0744:                    catalogRef.setLayer(this );
0745:                return catalogRef;
0746:            }
0747:
0748:            /**
0749:             * <!-- begin-user-doc --> <!-- end-user-doc -->
0750:             * @generated
0751:             */
0752:            public void setCatalogRef(CatalogRef newCatalogRef) {
0753:                CatalogRef oldCatalogRef = catalogRef;
0754:                catalogRef = newCatalogRef;
0755:                if (eNotificationRequired())
0756:                    eNotify(new ENotificationImpl(this , Notification.SET,
0757:                            ProjectPackage.LAYER__CATALOG_REF, oldCatalogRef,
0758:                            catalogRef));
0759:            }
0760:
0761:            /**
0762:             * <!-- begin-user-doc --> <!-- end-user-doc -->
0763:             * @generated
0764:             */
0765:            public StyleBlackboard getStyleBlackboard() {
0766:                return styleBlackboard;
0767:            }
0768:
0769:            /**
0770:             * <!-- begin-user-doc --> <!-- end-user-doc -->
0771:             * @generated
0772:             */
0773:            public NotificationChain basicSetStyleBlackboard(
0774:                    StyleBlackboard newStyleBlackboard, NotificationChain msgs) {
0775:                StyleBlackboard oldStyleBlackboard = styleBlackboard;
0776:                styleBlackboard = newStyleBlackboard;
0777:                if (eNotificationRequired()) {
0778:                    ENotificationImpl notification = new ENotificationImpl(
0779:                            this , Notification.SET,
0780:                            ProjectPackage.LAYER__STYLE_BLACKBOARD,
0781:                            oldStyleBlackboard, newStyleBlackboard);
0782:                    if (msgs == null)
0783:                        msgs = notification;
0784:                    else
0785:                        msgs.add(notification);
0786:                }
0787:                return msgs;
0788:            }
0789:
0790:            /**
0791:             * <!-- begin-user-doc --> <!-- end-user-doc -->
0792:             * 
0793:             * @uml.property name="styleBlackboard"
0794:             * @generated NOT
0795:             */
0796:            public void setStyleBlackboard(StyleBlackboard newStyleBlackboard) {
0797:                if (newStyleBlackboard != styleBlackboard) {
0798:                    NotificationChain msgs = null;
0799:                    if (styleBlackboard != null)
0800:                        msgs = ((InternalEObject) styleBlackboard)
0801:                                .eInverseRemove(
0802:                                        this ,
0803:                                        EOPPOSITE_FEATURE_BASE
0804:                                                - ProjectPackage.LAYER__STYLE_BLACKBOARD,
0805:                                        null, msgs);
0806:                    if (newStyleBlackboard != null)
0807:                        msgs = ((InternalEObject) newStyleBlackboard)
0808:                                .eInverseAdd(
0809:                                        this ,
0810:                                        EOPPOSITE_FEATURE_BASE
0811:                                                - ProjectPackage.LAYER__STYLE_BLACKBOARD,
0812:                                        null, msgs);
0813:                    msgs = basicSetStyleBlackboard(newStyleBlackboard, msgs);
0814:                    if (msgs != null)
0815:                        msgs.dispatch();
0816:                } else if (eNotificationRequired())
0817:                    eNotify(new ENotificationImpl(this , Notification.SET,
0818:                            ProjectPackage.LAYER__STYLE_BLACKBOARD,
0819:                            newStyleBlackboard, newStyleBlackboard));
0820:            }
0821:
0822:            /**
0823:             * <!-- begin-user-doc --> <!-- end-user-doc -->
0824:             * @generated
0825:             */
0826:            public Filter getFilter() {
0827:                return filter;
0828:            }
0829:
0830:            /**
0831:             * <!-- begin-user-doc --> <!-- end-user-doc -->
0832:             * @generated
0833:             */
0834:            public void setFilter(Filter newFilter) {
0835:                Filter oldFilter = filter;
0836:                filter = newFilter;
0837:                if (eNotificationRequired())
0838:                    eNotify(new ENotificationImpl(this , Notification.SET,
0839:                            ProjectPackage.LAYER__FILTER, oldFilter, filter));
0840:            }
0841:
0842:            /**
0843:             * <!-- begin-user-doc --> <!-- end-user-doc -->
0844:             * @generated
0845:             */
0846:            public int getStatus() {
0847:                if (geoResources == NULL || status == ILayer.ERROR)
0848:                    return status;
0849:                if (isUnknownCRS())
0850:                    return ILayer.WARNING;
0851:
0852:                return status;
0853:            }
0854:
0855:            private boolean isUnknownCRS() {
0856:                unknownCRSLock.lock();
0857:                try {
0858:                    if (unknownCRS == null) {
0859:                        if (crsLoader == null) {
0860:                            crsLoader = new ISafeRunnable() {
0861:
0862:                                public void handleException(Throwable exception) {
0863:                                    ProjectPlugin.log("", exception); //$NON-NLS-1$
0864:                                }
0865:
0866:                                public void run() throws Exception {
0867:                                    if (getCRS() == UNKNOWN_CRS) {
0868:                                        synchronized (LayerImpl.this ) {
0869:                                            if (unknownCRS == null) {
0870:                                                unknownCRS = new AtomicBoolean(
0871:                                                        true);
0872:                                                setStatus(WARNING);
0873:                                                crsLoader = null;
0874:                                            }
0875:                                        }
0876:                                    }
0877:                                }
0878:
0879:                            };
0880:                            PlatformGIS.run(crsLoader);
0881:                        }
0882:                        return false;
0883:                    } else {
0884:                        return unknownCRS.get();
0885:                    }
0886:                } finally {
0887:                    unknownCRSLock.unlock();
0888:
0889:                }
0890:            }
0891:
0892:            /**
0893:             * <!-- begin-user-doc --> <!-- end-user-doc -->
0894:             * @generated NOT
0895:             */
0896:            public void setStatus(int newStatus) {
0897:                int oldStatus = status;
0898:                status = newStatus;
0899:                if (eNotificationRequired())
0900:                    eNotify(new ENotificationImpl(this , Notification.SET,
0901:                            ProjectPackage.LAYER__STATUS, oldStatus, status));
0902:            }
0903:
0904:            public <T> IGeoResource findGeoResource(Class<T> resourceType) {
0905:                for (IGeoResource resource : getGeoResources()) {
0906:                    if (resource.canResolve(resourceType)) {
0907:                        return resource;
0908:                    }
0909:                }
0910:                return null;
0911:            }
0912:
0913:            /**
0914:             * @deprecated
0915:             */
0916:            public <T> boolean isType(Class<T> resourceType) {
0917:                return hasResource(resourceType);
0918:            }
0919:
0920:            public <T> boolean hasResource(Class<T> resourceType) {
0921:                for (IGeoResource resource : getGeoResources()) {
0922:                    if (resource.canResolve(resourceType))
0923:                        return true;
0924:                }
0925:                return false;
0926:            }
0927:
0928:            /**
0929:             * <!-- begin-user-doc --> <!-- end-user-doc -->
0930:             * @generated
0931:             */
0932:            public ImageDescriptor getGlyph() {
0933:                return glyph;
0934:            }
0935:
0936:            /**
0937:             * <!-- begin-user-doc --> <!-- end-user-doc -->
0938:             * @generated
0939:             */
0940:            public void setGlyph(ImageDescriptor newGlyph) {
0941:                ImageDescriptor oldGlyph = glyph;
0942:                glyph = newGlyph;
0943:                if (eNotificationRequired())
0944:                    eNotify(new ENotificationImpl(this , Notification.SET,
0945:                            ProjectPackage.LAYER__GLYPH, oldGlyph, glyph));
0946:            }
0947:
0948:            /**
0949:             * <!-- begin-user-doc --> <!-- end-user-doc -->
0950:             * @generated
0951:             */
0952:            public boolean isSelectable() {
0953:                return selectable;
0954:            }
0955:
0956:            /**
0957:             * <!-- begin-user-doc --> <!-- end-user-doc -->
0958:             * @generated
0959:             */
0960:            public void setSelectable(boolean newSelectable) {
0961:                boolean oldSelectable = selectable;
0962:                selectable = newSelectable;
0963:                if (eNotificationRequired())
0964:                    eNotify(new ENotificationImpl(this , Notification.SET,
0965:                            ProjectPackage.LAYER__SELECTABLE, oldSelectable,
0966:                            selectable));
0967:            }
0968:
0969:            /**
0970:             * <!-- begin-user-doc --> <!-- end-user-doc -->
0971:             * @generated
0972:             */
0973:            public NotificationChain eInverseAdd(InternalEObject otherEnd,
0974:                    int featureID, Class baseClass, NotificationChain msgs) {
0975:                if (featureID >= 0) {
0976:                    switch (eDerivedStructuralFeatureID(featureID, baseClass)) {
0977:                    case ProjectPackage.LAYER__CONTEXT_MODEL:
0978:                        if (eContainer != null)
0979:                            msgs = eBasicRemoveFromContainer(msgs);
0980:                        return eBasicSetContainer(otherEnd,
0981:                                ProjectPackage.LAYER__CONTEXT_MODEL, msgs);
0982:                    default:
0983:                        return eDynamicInverseAdd(otherEnd, featureID,
0984:                                baseClass, msgs);
0985:                    }
0986:                }
0987:                if (eContainer != null)
0988:                    msgs = eBasicRemoveFromContainer(msgs);
0989:                return eBasicSetContainer(otherEnd, featureID, msgs);
0990:            }
0991:
0992:            /**
0993:             * <!-- begin-user-doc --> <!-- end-user-doc -->
0994:             * @generated
0995:             */
0996:            public NotificationChain eInverseRemove(InternalEObject otherEnd,
0997:                    int featureID, Class baseClass, NotificationChain msgs) {
0998:                if (featureID >= 0) {
0999:                    switch (eDerivedStructuralFeatureID(featureID, baseClass)) {
1000:                    case ProjectPackage.LAYER__CONTEXT_MODEL:
1001:                        return eBasicSetContainer(null,
1002:                                ProjectPackage.LAYER__CONTEXT_MODEL, msgs);
1003:                    case ProjectPackage.LAYER__STYLE_BLACKBOARD:
1004:                        return basicSetStyleBlackboard(null, msgs);
1005:                    default:
1006:                        return eDynamicInverseRemove(otherEnd, featureID,
1007:                                baseClass, msgs);
1008:                    }
1009:                }
1010:                return eBasicSetContainer(null, featureID, msgs);
1011:            }
1012:
1013:            /**
1014:             * <!-- begin-user-doc --> <!-- end-user-doc -->
1015:             * @generated
1016:             */
1017:            public NotificationChain eBasicRemoveFromContainer(
1018:                    NotificationChain msgs) {
1019:                if (eContainerFeatureID >= 0) {
1020:                    switch (eContainerFeatureID) {
1021:                    case ProjectPackage.LAYER__CONTEXT_MODEL:
1022:                        return eContainer.eInverseRemove(this ,
1023:                                ProjectPackage.CONTEXT_MODEL__LAYERS,
1024:                                ContextModel.class, msgs);
1025:                    default:
1026:                        return eDynamicBasicRemoveFromContainer(msgs);
1027:                    }
1028:                }
1029:                return eContainer.eInverseRemove(this , EOPPOSITE_FEATURE_BASE
1030:                        - eContainerFeatureID, null, msgs);
1031:            }
1032:
1033:            /**
1034:             * <!-- begin-user-doc --> <!-- end-user-doc -->
1035:             * @generated
1036:             */
1037:            public Object eGet(EStructuralFeature eFeature, boolean resolve) {
1038:                switch (eDerivedStructuralFeatureID(eFeature)) {
1039:                case ProjectPackage.LAYER__CONTEXT_MODEL:
1040:                    return getContextModel();
1041:                case ProjectPackage.LAYER__FILTER:
1042:                    return getFilter();
1043:                case ProjectPackage.LAYER__STYLE_BLACKBOARD:
1044:                    return getStyleBlackboard();
1045:                case ProjectPackage.LAYER__ZORDER:
1046:                    return new Integer(getZorder());
1047:                case ProjectPackage.LAYER__STATUS:
1048:                    return new Integer(getStatus());
1049:                case ProjectPackage.LAYER__SELECTABLE:
1050:                    return isSelectable() ? Boolean.TRUE : Boolean.FALSE;
1051:                case ProjectPackage.LAYER__NAME:
1052:                    return getName();
1053:                case ProjectPackage.LAYER__CATALOG_REF:
1054:                    return getCatalogRef();
1055:                case ProjectPackage.LAYER__ID:
1056:                    return getID();
1057:                case ProjectPackage.LAYER__VISIBLE:
1058:                    return isVisible() ? Boolean.TRUE : Boolean.FALSE;
1059:                case ProjectPackage.LAYER__GEO_RESOURCE:
1060:                    return getGeoResource();
1061:                case ProjectPackage.LAYER__GEO_RESOURCES:
1062:                    return getGeoResources();
1063:                case ProjectPackage.LAYER__GLYPH:
1064:                    return getGlyph();
1065:                case ProjectPackage.LAYER__CRS:
1066:                    return getCRS();
1067:                case ProjectPackage.LAYER__PROPERTIES:
1068:                    return getProperties();
1069:                case ProjectPackage.LAYER__COLOUR_SCHEME:
1070:                    return getColourScheme();
1071:                case ProjectPackage.LAYER__DEFAULT_COLOR:
1072:                    return getDefaultColor();
1073:                case ProjectPackage.LAYER__FEATURE_CHANGES:
1074:                    return getFeatureChanges();
1075:                }
1076:                return eDynamicGet(eFeature, resolve);
1077:            }
1078:
1079:            /**
1080:             * <!-- begin-user-doc --> <!-- end-user-doc -->
1081:             * @generated
1082:             */
1083:            @SuppressWarnings("unchecked")
1084:            public void eSet(EStructuralFeature eFeature, Object newValue) {
1085:                switch (eDerivedStructuralFeatureID(eFeature)) {
1086:                case ProjectPackage.LAYER__CONTEXT_MODEL:
1087:                    setContextModel((ContextModel) newValue);
1088:                    return;
1089:                case ProjectPackage.LAYER__FILTER:
1090:                    setFilter((Filter) newValue);
1091:                    return;
1092:                case ProjectPackage.LAYER__STYLE_BLACKBOARD:
1093:                    setStyleBlackboard((StyleBlackboard) newValue);
1094:                    return;
1095:                case ProjectPackage.LAYER__ZORDER:
1096:                    setZorder(((Integer) newValue).intValue());
1097:                    return;
1098:                case ProjectPackage.LAYER__STATUS:
1099:                    setStatus(((Integer) newValue).intValue());
1100:                    return;
1101:                case ProjectPackage.LAYER__SELECTABLE:
1102:                    setSelectable(((Boolean) newValue).booleanValue());
1103:                    return;
1104:                case ProjectPackage.LAYER__NAME:
1105:                    setName((String) newValue);
1106:                    return;
1107:                case ProjectPackage.LAYER__CATALOG_REF:
1108:                    setCatalogRef((CatalogRef) newValue);
1109:                    return;
1110:                case ProjectPackage.LAYER__ID:
1111:                    setID((URL) newValue);
1112:                    return;
1113:                case ProjectPackage.LAYER__VISIBLE:
1114:                    setVisible(((Boolean) newValue).booleanValue());
1115:                    return;
1116:                case ProjectPackage.LAYER__GEO_RESOURCE:
1117:                    setGeoResource((IGeoResource) newValue);
1118:                    return;
1119:                case ProjectPackage.LAYER__GLYPH:
1120:                    setGlyph((ImageDescriptor) newValue);
1121:                    return;
1122:                case ProjectPackage.LAYER__CRS:
1123:                    setCRS((CoordinateReferenceSystem) newValue);
1124:                    return;
1125:                case ProjectPackage.LAYER__COLOUR_SCHEME:
1126:                    setColourScheme((ColourScheme) newValue);
1127:                    return;
1128:                case ProjectPackage.LAYER__DEFAULT_COLOR:
1129:                    setDefaultColor((Color) newValue);
1130:                    return;
1131:                case ProjectPackage.LAYER__FEATURE_CHANGES:
1132:                    getFeatureChanges().clear();
1133:                    getFeatureChanges().addAll((Collection) newValue);
1134:                    return;
1135:                }
1136:                eDynamicSet(eFeature, newValue);
1137:            }
1138:
1139:            /**
1140:             * <!-- begin-user-doc --> <!-- end-user-doc -->
1141:             * @generated
1142:             */
1143:            public void eUnset(EStructuralFeature eFeature) {
1144:                switch (eDerivedStructuralFeatureID(eFeature)) {
1145:                case ProjectPackage.LAYER__CONTEXT_MODEL:
1146:                    setContextModel((ContextModel) null);
1147:                    return;
1148:                case ProjectPackage.LAYER__FILTER:
1149:                    setFilter(FILTER_EDEFAULT);
1150:                    return;
1151:                case ProjectPackage.LAYER__STYLE_BLACKBOARD:
1152:                    setStyleBlackboard((StyleBlackboard) null);
1153:                    return;
1154:                case ProjectPackage.LAYER__ZORDER:
1155:                    setZorder(ZORDER_EDEFAULT);
1156:                    return;
1157:                case ProjectPackage.LAYER__STATUS:
1158:                    setStatus(STATUS_EDEFAULT);
1159:                    return;
1160:                case ProjectPackage.LAYER__SELECTABLE:
1161:                    setSelectable(SELECTABLE_EDEFAULT);
1162:                    return;
1163:                case ProjectPackage.LAYER__NAME:
1164:                    setName(NAME_EDEFAULT);
1165:                    return;
1166:                case ProjectPackage.LAYER__CATALOG_REF:
1167:                    setCatalogRef(CATALOG_REF_EDEFAULT);
1168:                    return;
1169:                case ProjectPackage.LAYER__ID:
1170:                    setID(ID_EDEFAULT);
1171:                    return;
1172:                case ProjectPackage.LAYER__VISIBLE:
1173:                    setVisible(VISIBLE_EDEFAULT);
1174:                    return;
1175:                case ProjectPackage.LAYER__GEO_RESOURCE:
1176:                    setGeoResource(GEO_RESOURCE_EDEFAULT);
1177:                    return;
1178:                case ProjectPackage.LAYER__GLYPH:
1179:                    setGlyph(GLYPH_EDEFAULT);
1180:                    return;
1181:                case ProjectPackage.LAYER__CRS:
1182:                    setCRS(CRS_EDEFAULT);
1183:                    return;
1184:                case ProjectPackage.LAYER__COLOUR_SCHEME:
1185:                    setColourScheme(COLOUR_SCHEME_EDEFAULT);
1186:                    return;
1187:                case ProjectPackage.LAYER__DEFAULT_COLOR:
1188:                    setDefaultColor(DEFAULT_COLOR_EDEFAULT);
1189:                    return;
1190:                case ProjectPackage.LAYER__FEATURE_CHANGES:
1191:                    getFeatureChanges().clear();
1192:                    return;
1193:                }
1194:                eDynamicUnset(eFeature);
1195:            }
1196:
1197:            /**
1198:             * <!-- begin-user-doc --> <!-- end-user-doc -->
1199:             * @generated
1200:             */
1201:            public boolean eIsSet(EStructuralFeature eFeature) {
1202:                switch (eDerivedStructuralFeatureID(eFeature)) {
1203:                case ProjectPackage.LAYER__CONTEXT_MODEL:
1204:                    return getContextModel() != null;
1205:                case ProjectPackage.LAYER__FILTER:
1206:                    return FILTER_EDEFAULT == null ? filter != null
1207:                            : !FILTER_EDEFAULT.equals(filter);
1208:                case ProjectPackage.LAYER__STYLE_BLACKBOARD:
1209:                    return styleBlackboard != null;
1210:                case ProjectPackage.LAYER__ZORDER:
1211:                    return getZorder() != ZORDER_EDEFAULT;
1212:                case ProjectPackage.LAYER__STATUS:
1213:                    return status != STATUS_EDEFAULT;
1214:                case ProjectPackage.LAYER__SELECTABLE:
1215:                    return selectable != SELECTABLE_EDEFAULT;
1216:                case ProjectPackage.LAYER__NAME:
1217:                    return NAME_EDEFAULT == null ? name != null
1218:                            : !NAME_EDEFAULT.equals(name);
1219:                case ProjectPackage.LAYER__CATALOG_REF:
1220:                    return CATALOG_REF_EDEFAULT == null ? catalogRef != null
1221:                            : !CATALOG_REF_EDEFAULT.equals(catalogRef);
1222:                case ProjectPackage.LAYER__ID:
1223:                    return ID_EDEFAULT == null ? iD != null : !ID_EDEFAULT
1224:                            .equals(iD);
1225:                case ProjectPackage.LAYER__VISIBLE:
1226:                    return visible != VISIBLE_EDEFAULT;
1227:                case ProjectPackage.LAYER__GEO_RESOURCE:
1228:                    return GEO_RESOURCE_EDEFAULT == null ? geoResource != null
1229:                            : !GEO_RESOURCE_EDEFAULT.equals(geoResource);
1230:                case ProjectPackage.LAYER__GEO_RESOURCES:
1231:                    return geoResources != null && !geoResources.isEmpty();
1232:                case ProjectPackage.LAYER__GLYPH:
1233:                    return GLYPH_EDEFAULT == null ? glyph != null
1234:                            : !GLYPH_EDEFAULT.equals(glyph);
1235:                case ProjectPackage.LAYER__CRS:
1236:                    return CRS_EDEFAULT == null ? cRS != null : !CRS_EDEFAULT
1237:                            .equals(cRS);
1238:                case ProjectPackage.LAYER__PROPERTIES:
1239:                    return properties != null;
1240:                case ProjectPackage.LAYER__COLOUR_SCHEME:
1241:                    return COLOUR_SCHEME_EDEFAULT == null ? colourScheme != null
1242:                            : !COLOUR_SCHEME_EDEFAULT.equals(colourScheme);
1243:                case ProjectPackage.LAYER__DEFAULT_COLOR:
1244:                    return DEFAULT_COLOR_EDEFAULT == null ? defaultColor != null
1245:                            : !DEFAULT_COLOR_EDEFAULT.equals(defaultColor);
1246:                case ProjectPackage.LAYER__FEATURE_CHANGES:
1247:                    return featureChanges != null && !featureChanges.isEmpty();
1248:                }
1249:                return eDynamicIsSet(eFeature);
1250:            }
1251:
1252:            /**
1253:             * <!-- begin-user-doc --> <!-- end-user-doc -->
1254:             * 
1255:             * @generated NOT
1256:             */
1257:            public String toString() {
1258:                if (eIsProxy())
1259:                    return super .toString();
1260:
1261:                StringBuffer result = new StringBuffer();
1262:                result.append(" (name: "); //$NON-NLS-1$
1263:                result.append(name);
1264:                result.append(')');
1265:                return result.toString();
1266:            }
1267:
1268:            /**
1269:             * @see net.refractions.udig.project.internal.Layer#getQuery(net.refractions.udig.project.Layer,
1270:             *      boolean)
1271:             * @generated NOT
1272:             */
1273:            public Query getQuery(boolean selection) {
1274:                try {
1275:                    if (selection)
1276:                        return new DefaultQuery(getSchema().getTypeName(),
1277:                                getFilter());
1278:                    else
1279:                        return Query.ALL;
1280:                } catch (Exception e) {
1281:                    if (selection) {
1282:                        DefaultQuery q = new DefaultQuery();
1283:                        q.setFilter(Filter.ALL);
1284:                        return q;
1285:                    } else
1286:                        return Query.ALL;
1287:                }
1288:            }
1289:
1290:            private volatile int status;
1291:
1292:            /**
1293:             * The default value of the '{@link #isSelectable() <em>Selectable</em>}' attribute. <!--
1294:             * begin-user-doc --> <!-- end-user-doc -->
1295:             * 
1296:             * @see #isSelectable()
1297:             * @generated
1298:             * @ordered
1299:             */
1300:            protected static final boolean SELECTABLE_EDEFAULT = true;
1301:
1302:            /**
1303:             * The cached value of the '{@link #isSelectable() <em>Selectable</em>}' attribute. <!--
1304:             * begin-user-doc --> <!-- end-user-doc -->
1305:             * 
1306:             * @see #isSelectable()
1307:             * @generated not
1308:             * @ordered
1309:             */
1310:            protected volatile boolean selectable = SELECTABLE_EDEFAULT;
1311:
1312:            /**
1313:             * The default value of the '{@link #getName() <em>Name</em>}' attribute.
1314:             * <!-- begin-user-doc
1315:             * --> <!-- end-user-doc -->
1316:             * @see #getName()
1317:             * @generated
1318:             * @ordered
1319:             */
1320:            protected static final String NAME_EDEFAULT = null;
1321:
1322:            /**
1323:             * The cached value of the '{@link #getName() <em>Name</em>}' attribute.
1324:             * <!-- begin-user-doc
1325:             * --> <!-- end-user-doc -->
1326:             * @see #getName()
1327:             * @generated not
1328:             * @ordered
1329:             */
1330:            protected volatile String name = NAME_EDEFAULT;
1331:
1332:            /**
1333:             * The default value of the '{@link #getCatalogRef() <em>Catalog Ref</em>}' attribute. <!--
1334:             * begin-user-doc --> <!-- end-user-doc -->
1335:             * 
1336:             * @see #getCatalogRef()
1337:             * @generated
1338:             * @ordered
1339:             */
1340:            protected static final CatalogRef CATALOG_REF_EDEFAULT = null;
1341:
1342:            /**
1343:             * The cached value of the '{@link #getCatalogRef() <em>Catalog Ref</em>}' attribute. <!--
1344:             * begin-user-doc --> <!-- end-user-doc -->
1345:             * 
1346:             * @see #getCatalogRef()
1347:             * @generated NOT
1348:             * @ordered
1349:             */
1350:            protected volatile CatalogRef catalogRef = new CatalogRef(this );
1351:
1352:            /**
1353:             * The default value of the '{@link #getID() <em>ID</em>}' attribute.
1354:             * <!-- begin-user-doc -->
1355:             * <!-- end-user-doc -->
1356:             * @see #getID()
1357:             * @generated
1358:             * @ordered
1359:             */
1360:            protected static final URL ID_EDEFAULT = null;
1361:
1362:            /**
1363:             * The cached value of the '{@link #getID() <em>ID</em>}' attribute.
1364:             * <!-- begin-user-doc -->
1365:             * <!-- end-user-doc -->
1366:             * @see #getID()
1367:             * @generated NOT
1368:             * @ordered
1369:             */
1370:            protected volatile URL iD = ID_EDEFAULT;
1371:
1372:            /**
1373:             * The default value of the '{@link #isVisible() <em>Visible</em>}' attribute. <!--
1374:             * begin-user-doc --> <!-- end-user-doc -->
1375:             * 
1376:             * @see #isVisible()
1377:             * @generated NOT
1378:             * @ordered
1379:             */
1380:            protected static final boolean VISIBLE_EDEFAULT = true;
1381:
1382:            /**
1383:             * The cached value of the '{@link #isVisible() <em>Visible</em>}' attribute. <!--
1384:             * begin-user-doc --> <!-- end-user-doc -->
1385:             * 
1386:             * @see #isVisible()
1387:             * @generated not
1388:             * @ordered
1389:             */
1390:            protected volatile boolean visible = VISIBLE_EDEFAULT;
1391:
1392:            /**
1393:             * The default value of the '{@link #getGeoResource() <em>Geo Resource</em>}' attribute. <!--
1394:             * begin-user-doc --> <!-- end-user-doc -->
1395:             * 
1396:             * @see #getGeoResource()
1397:             * @generated
1398:             * @ordered
1399:             */
1400:            protected static final IGeoResource GEO_RESOURCE_EDEFAULT = null;
1401:
1402:            /**
1403:             * The cached value of the '{@link #getGeoResource() <em>Geo Resource</em>}' attribute. <!--
1404:             * begin-user-doc --> <!-- end-user-doc -->
1405:             * 
1406:             * @see #getGeoResource()
1407:             * @generated NOT
1408:             * @ordered
1409:             */
1410:            protected volatile IGeoResource geoResource = GEO_RESOURCE_EDEFAULT;
1411:
1412:            /**
1413:             * The cached value of the '{@link #getGeoResources() <em>Geo Resources</em>}' attribute list.
1414:             * <!-- begin-user-doc --> <!-- end-user-doc -->
1415:             * @see #getGeoResources()
1416:             * @generated NOT
1417:             * @ordered
1418:             */
1419:            protected volatile EList geoResources = null;
1420:
1421:            /**
1422:             * The default value of the '{@link #getGlyph() <em>Glyph</em>}' attribute. <!--
1423:             * begin-user-doc --> <!-- end-user-doc -->
1424:             * 
1425:             * @see #getGlyph()
1426:             * @generated
1427:             * @ordered
1428:             */
1429:            protected static final ImageDescriptor GLYPH_EDEFAULT = null;
1430:
1431:            /**
1432:             * The cached value of the '{@link #getGlyph() <em>Glyph</em>}' attribute.
1433:             * <!-- begin-user-doc
1434:             * --> <!-- end-user-doc -->
1435:             * @see #getGlyph()
1436:             * @generated NOT
1437:             * @ordered
1438:             */
1439:            protected volatile ImageDescriptor glyph = GLYPH_EDEFAULT;
1440:
1441:            /**
1442:             * The default value of the '{@link #getCRS() <em>CRS</em>}' attribute.
1443:             * <!-- begin-user-doc
1444:             * --> <!-- end-user-doc -->
1445:             * @see #getCRS()
1446:             * @generated
1447:             * @ordered
1448:             */
1449:            protected static final CoordinateReferenceSystem CRS_EDEFAULT = null;
1450:
1451:            /**
1452:             * The cached value of the '{@link #getCRS() <em>CRS</em>}' attribute.
1453:             * <!-- begin-user-doc -->
1454:             * <!-- end-user-doc -->
1455:             * @see #getCRS()
1456:             * @generated NOT
1457:             * @ordered
1458:             */
1459:            protected volatile CoordinateReferenceSystem cRS = CRS_EDEFAULT;
1460:
1461:            /**
1462:             * The cached value of the '{@link #getProperties() <em>Properties</em>}' attribute. <!--
1463:             * begin-user-doc --> <!-- end-user-doc -->
1464:             * 
1465:             * @see #getProperties()
1466:             * @generated NOT
1467:             * @ordered
1468:             */
1469:            protected final IBlackboard properties = new SimpleBlackboard();
1470:
1471:            /**
1472:             * The default value of the '{@link #getColourScheme() <em>Colour Scheme</em>}' attribute.
1473:             * <!-- begin-user-doc --> <!-- end-user-doc -->
1474:             * @see #getColourScheme()
1475:             * @generated
1476:             * @ordered
1477:             */
1478:            protected static final ColourScheme COLOUR_SCHEME_EDEFAULT = null;
1479:
1480:            /**
1481:             * The cached value of the '{@link #getColourScheme() <em>Colour Scheme</em>}' attribute. <!--
1482:             * begin-user-doc --> <!-- end-user-doc -->
1483:             * 
1484:             * @see #getColourScheme()
1485:             * @generated not
1486:             * @ordered
1487:             */
1488:            protected volatile ColourScheme colourScheme = COLOUR_SCHEME_EDEFAULT;
1489:
1490:            /**
1491:             * The default value of the '{@link #getDefaultColor() <em>Default Color</em>}' attribute.
1492:             * <!-- begin-user-doc --> <!-- end-user-doc -->
1493:             * @see #getDefaultColor()
1494:             * @generated
1495:             * @ordered
1496:             */
1497:            protected static final Color DEFAULT_COLOR_EDEFAULT = null;
1498:
1499:            /**
1500:             * The cached value of the '{@link #getDefaultColor() <em>Default Color</em>}' attribute. <!--
1501:             * begin-user-doc --> <!-- end-user-doc -->
1502:             * 
1503:             * @see #getDefaultColor()
1504:             * @generated NOT
1505:             * @ordered
1506:             */
1507:            protected volatile Color defaultColor = DEFAULT_COLOR_EDEFAULT;
1508:
1509:            /**
1510:             * The cached value of the '{@link #getFeatureChanges() <em>Feature Changes</em>}' attribute list.
1511:             * <!-- begin-user-doc --> <!-- end-user-doc -->
1512:             * @see #getFeatureChanges()
1513:             * @generated NOT
1514:             * @ordered
1515:             */
1516:            protected volatile EList featureChanges = null;
1517:
1518:            /**
1519:             * The default value of the '{@link #getMinScaleDenominator() <em>Min Scale Denominator</em>}' attribute.
1520:             * <!-- begin-user-doc -->
1521:             * <!-- end-user-doc -->
1522:             * @see #getMinScaleDenominator()
1523:             * @generated not
1524:             * @ordered
1525:             */
1526:            protected static final double MIN_SCALE_DENOMINATOR_EDEFAULT = Double.NaN;
1527:
1528:            /**
1529:             * The cached value of the '{@link #getMinScaleDenominator() <em>Min Scale Denominator</em>}' attribute.
1530:             * <!-- begin-user-doc -->
1531:             * <!-- end-user-doc -->
1532:             * @see #getMinScaleDenominator()
1533:             * @generated not
1534:             * @ordered
1535:             */
1536:            protected volatile double minScaleDenominator = MIN_SCALE_DENOMINATOR_EDEFAULT;
1537:
1538:            /**
1539:             * The default value of the '{@link #getMaxScaleDenominator() <em>Max Scale Denominator</em>}' attribute.
1540:             * <!-- begin-user-doc -->
1541:             * <!-- end-user-doc -->
1542:             * @see #getMaxScaleDenominator()
1543:             * @generated not
1544:             * @ordered
1545:             */
1546:            protected static final double MAX_SCALE_DENOMINATOR_EDEFAULT = Double.NaN;
1547:
1548:            /**
1549:             * The cached value of the '{@link #getMaxScaleDenominator() <em>Max Scale Denominator</em>}' attribute.
1550:             * <!-- begin-user-doc -->
1551:             * <!-- end-user-doc -->
1552:             * @see #getMaxScaleDenominator()
1553:             * @generated not
1554:             * @ordered
1555:             */
1556:            protected volatile double maxScaleDenominator = MAX_SCALE_DENOMINATOR_EDEFAULT;
1557:
1558:            private volatile String statusMessage = Messages.LayerImpl_status;
1559:
1560:            /**
1561:             * @see net.refractions.udig.project.internal.Layer#getSchema()
1562:             */
1563:            public FeatureType getSchema() {
1564:                FeatureSource data;
1565:                try {
1566:                    data = getResource(FeatureSource.class, null);
1567:                    if (data != null) {
1568:                        return data.getSchema();
1569:                    }
1570:                } catch (IOException e) {
1571:                    ProjectPlugin.log(null, e);
1572:                }
1573:                // XXX: rgould how do I process a getWMS().createDescribeLayerRequest()?
1574:
1575:                // URL wfsURL = null;
1576:                //        
1577:                // try {
1578:                // DescribeLayerRequest request = null;
1579:                // request = getWMS().createDescribeLayerRequest();
1580:                // request.setLayers(getName());
1581:                // DescribeLayerResponse response = (DescribeLayerResponse)
1582:                // getWMS().issueRequest(request);
1583:                // wfsURL = response.getLayerDescs()[0].getWfs();
1584:                // } catch (SAXException e1) {
1585:                // // TODO Catch e1
1586:                // } catch (UnsupportedOperationException e) {
1587:                // // TODO Catch e
1588:                // } catch (IOException e) {
1589:                // // TODO Catch e
1590:                // }
1591:
1592:                // WFS URL now possibly has a URL
1593:
1594:                return null;
1595:            }
1596:
1597:            /**
1598:             * @see java.lang.Comparable#compareTo(java.lang.Object)
1599:             */
1600:            public int compareTo(ILayer arg0) {
1601:                return doComparison(this , arg0);
1602:            }
1603:
1604:            /**
1605:             * @see net.refractions.udig.project.internal.Layer#isApplicable(java.lang.String)
1606:             */
1607:            public boolean isApplicable(String toolsetID) {
1608:                if (getProperties().get(toolsetID) == null)
1609:                    return true;
1610:                return (Boolean) getProperties().get(toolsetID);
1611:            }
1612:
1613:            /**
1614:             * @see net.refractions.udig.project.internal.Layer#setApplicable(java.lang.String, boolean)
1615:             */
1616:            public void setApplicable(String toolsetID, boolean applicable) {
1617:                getProperties().put(toolsetID, applicable);
1618:                // XXX just to send an event needs to change.
1619:                setSelectable(isSelectable());
1620:            }
1621:
1622:            /**
1623:             * <!-- begin-user-doc --> <!-- end-user-doc -->
1624:             * 
1625:             * @uml.property name="cRS"
1626:             * @generated NOT
1627:             */
1628:            public CoordinateReferenceSystem getCRS() {
1629:                return getCRS(null);
1630:            }
1631:
1632:            /**
1633:             * <!-- begin-user-doc --> <!-- end-user-doc -->
1634:             */
1635:            public void setCRS(CoordinateReferenceSystem newCRS) {
1636:
1637:                setCRSGen(newCRS);
1638:                boolean setStatus = false;
1639:                synchronized (this ) {
1640:                    if (unknownCRS == null) {
1641:                        unknownCRS = new AtomicBoolean(false);
1642:                    } else if (unknownCRS.get()) {
1643:                        unknownCRS.set(false);
1644:                        setStatus = true;
1645:                    }
1646:                }
1647:                if (setStatus)
1648:                    setStatus(status);
1649:            }
1650:
1651:            /**
1652:             * <!-- begin-user-doc --> <!-- end-user-doc -->
1653:             * @generated
1654:             */
1655:            public void setCRSGen(CoordinateReferenceSystem newCRS) {
1656:                CoordinateReferenceSystem oldCRS = cRS;
1657:                cRS = newCRS;
1658:                if (eNotificationRequired())
1659:                    eNotify(new ENotificationImpl(this , Notification.SET,
1660:                            ProjectPackage.LAYER__CRS, oldCRS, cRS));
1661:            }
1662:
1663:            /**
1664:             * <!-- begin-user-doc --> <!-- end-user-doc -->
1665:             */
1666:            public IBlackboard getProperties() {
1667:                return properties;
1668:            }
1669:
1670:            public IBlackboard getBlackboard() {
1671:                return properties;
1672:            }
1673:
1674:            /**
1675:             * <!-- begin-user-doc --> <!-- end-user-doc -->
1676:             * @generated
1677:             */
1678:            public ColourScheme getColourScheme() {
1679:                return colourScheme;
1680:            }
1681:
1682:            /**
1683:             * <!-- begin-user-doc --> <!-- end-user-doc -->
1684:             * @generated
1685:             */
1686:            public void setColourScheme(ColourScheme newColourScheme) {
1687:                ColourScheme oldColourScheme = colourScheme;
1688:                colourScheme = newColourScheme;
1689:                if (eNotificationRequired())
1690:                    eNotify(new ENotificationImpl(this , Notification.SET,
1691:                            ProjectPackage.LAYER__COLOUR_SCHEME,
1692:                            oldColourScheme, colourScheme));
1693:            }
1694:
1695:            /**
1696:             * <!-- begin-user-doc --> <!-- end-user-doc -->
1697:             * @generated
1698:             */
1699:            public Color getDefaultColor() {
1700:                return defaultColor;
1701:            }
1702:
1703:            /**
1704:             * <!-- begin-user-doc --> <!-- end-user-doc -->
1705:             * @generated
1706:             */
1707:            public void setDefaultColor(Color newDefaultColor) {
1708:                Color oldDefaultColor = defaultColor;
1709:                defaultColor = newDefaultColor;
1710:                if (eNotificationRequired())
1711:                    eNotify(new ENotificationImpl(this , Notification.SET,
1712:                            ProjectPackage.LAYER__DEFAULT_COLOR,
1713:                            oldDefaultColor, defaultColor));
1714:            }
1715:
1716:            /**
1717:             * <!-- begin-user-doc --> <!-- end-user-doc -->
1718:             * @generated
1719:             */
1720:            @SuppressWarnings({"unchecked","serial"})//$NON-NLS-1$ //$NON-NLS-2$
1721:            public List<FeatureEvent> getFeatureChanges() {
1722:                if (featureChanges == null) {
1723:                    featureChanges = new EDataTypeUniqueEList(
1724:                            FeatureEvent.class, this ,
1725:                            ProjectPackage.LAYER__FEATURE_CHANGES) {
1726:                        @Override
1727:                        public void add(int index, Object object) {
1728:                            if (size() > 10) {
1729:                                clear();
1730:                            }
1731:                            super .add(index, object);
1732:                        }
1733:                    };
1734:                }
1735:                return featureChanges;
1736:            }
1737:
1738:            /**
1739:             * <!-- begin-user-doc -->
1740:             * <!-- end-user-doc -->
1741:             * @generated
1742:             */
1743:            public double getMinScaleDenominator() {
1744:                return minScaleDenominator;
1745:            }
1746:
1747:            /**
1748:             * <!-- begin-user-doc -->
1749:             * <!-- end-user-doc -->
1750:             * @generated
1751:             */
1752:            public void setMinScaleDenominator(double newMinScaleDenominator) {
1753:                double oldMinScaleDenominator = minScaleDenominator;
1754:                minScaleDenominator = newMinScaleDenominator;
1755:                if (eNotificationRequired())
1756:                    eNotify(new ENotificationImpl(this , Notification.SET,
1757:                            ProjectPackage.LAYER__MIN_SCALE_DENOMINATOR,
1758:                            oldMinScaleDenominator, minScaleDenominator));
1759:            }
1760:
1761:            /**
1762:             * <!-- begin-user-doc -->
1763:             * <!-- end-user-doc -->
1764:             * @generated
1765:             */
1766:            public double getMaxScaleDenominator() {
1767:                return maxScaleDenominator;
1768:            }
1769:
1770:            /**
1771:             * <!-- begin-user-doc -->
1772:             * <!-- end-user-doc -->
1773:             * @generated
1774:             */
1775:            public void setMaxScaleDenominator(double newMaxScaleDenominator) {
1776:                double oldMaxScaleDenominator = maxScaleDenominator;
1777:                maxScaleDenominator = newMaxScaleDenominator;
1778:                if (eNotificationRequired())
1779:                    eNotify(new ENotificationImpl(this , Notification.SET,
1780:                            ProjectPackage.LAYER__MAX_SCALE_DENOMINATOR,
1781:                            oldMaxScaleDenominator, maxScaleDenominator));
1782:            }
1783:
1784:            /**
1785:             * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class)
1786:             */
1787:            @SuppressWarnings("unchecked")
1788:            public Object getAdapter(final Class adapter) {
1789:                EList adapters = eAdapters();
1790:                if (adapters instanceof  SynchronizedEList) {
1791:                    ((SynchronizedEList) adapters).lock();
1792:                }
1793:                try {
1794:                    for (Iterator i = adapters.iterator(); i.hasNext();) {
1795:                        Object o = i.next();
1796:                        if (adapter.isAssignableFrom(o.getClass()))
1797:                            return o;
1798:                    }
1799:                } finally {
1800:                    if (adapters instanceof  SynchronizedEList) {
1801:                        ((SynchronizedEList) adapters).unlock();
1802:                    }
1803:                }
1804:
1805:                /*
1806:                 * Adapt to an IWorkbenchAdapter. Other aspects of Eclipse can read the
1807:                 * properties we provide access to. (example: Property page dialogs
1808:                 * can read the label and display that in their title.)
1809:                 */
1810:                if (adapter.isAssignableFrom(IWorkbenchAdapter.class)) {
1811:                    return new WorkbenchAdapter() {
1812:
1813:                        @Override
1814:                        public String getLabel(Object object) {
1815:                            return getName();
1816:                        }
1817:
1818:                    };
1819:                }
1820:
1821:                return null;
1822:            }
1823:
1824:            public CoordinateReferenceSystem getCRS(IProgressMonitor monitor) {
1825:
1826:                if (cRS != null)
1827:                    return cRS;
1828:                return getCRSInternal(monitor);
1829:            }
1830:
1831:            /**
1832:             * queries the georesources for a CRS
1833:             *
1834:             * @param monitor
1835:             * @return
1836:             */
1837:            private CoordinateReferenceSystem getCRSInternal(
1838:                    IProgressMonitor monitor) {
1839:                try {
1840:                    CoordinateReferenceSystem crs = getGeoResource().getInfo(
1841:                            monitor).getCRS();
1842:                    if (crs != null)
1843:                        return crs;
1844:                } catch (Exception e) {
1845:                    ProjectPlugin.log(null, e);
1846:                }
1847:
1848:                List<IGeoResource> list = getGeoResources();
1849:                for (IGeoResource resource : list) {
1850:                    try {
1851:                        if (resource.getInfo(monitor).getCRS() != null)
1852:                            return resource.getInfo(monitor).getCRS();
1853:                    } catch (Exception e) {
1854:                        ProjectPlugin.log(null, e);
1855:                    }
1856:                }
1857:
1858:                return UNKNOWN_CRS;
1859:            }
1860:
1861:            public void refresh(Envelope bounds) {
1862:                if (!isVisible())
1863:                    return;
1864:                if (getMap() == null || getMap().getRenderManager() == null)
1865:                    return;
1866:                Envelope transformedbounds = bounds;
1867:                if (bounds != null) {
1868:                    try {
1869:                        transformedbounds = JTS.transform(bounds,
1870:                                layerToMapTransform());
1871:                    } catch (TransformException e) {
1872:                        ProjectPlugin.log("", e); //$NON-NLS-1$
1873:                        transformedbounds = bounds;
1874:                    }
1875:                }
1876:                getMap().getRenderManager().refresh(this , transformedbounds);
1877:
1878:            }
1879:
1880:            /**
1881:             * Layers bounds.  Usually null but not null if an edit has caused the 
1882:             * bounds to be changed.  If null then getBounds will obtain the bounds from the 
1883:             * IGeoResource.  Else will use this bounds.
1884:             */
1885:            private volatile ReferencedEnvelope bounds;
1886:
1887:            public MathTransform layerToMapTransform() {
1888:                MathTransform layerToMapTransform;
1889:                try {
1890:                    layerToMapTransform = CRS.findMathTransform(getCRS(),
1891:                            getMap().getViewportModel().getCRS(), true);
1892:                } catch (Exception e) {
1893:                    layerToMapTransform = IDENTITY;
1894:                }
1895:                return layerToMapTransform;
1896:            }
1897:
1898:            public MathTransform mapToLayerTransform() {
1899:                MathTransform mapToLayerTransform;
1900:                try {
1901:                    mapToLayerTransform = CRS.findMathTransform(getMap()
1902:                            .getViewportModel().getCRS(), getCRS(), true);
1903:                } catch (Exception e) {
1904:                    mapToLayerTransform = IDENTITY;
1905:                }
1906:                return mapToLayerTransform;
1907:            }
1908:
1909:            public void setBounds(ReferencedEnvelope bounds) {
1910:                this .bounds = bounds;
1911:            }
1912:
1913:            public ReferencedEnvelope getBounds(IProgressMonitor monitor,
1914:                    CoordinateReferenceSystem crs) {
1915:                if (bounds != null) {
1916:                    try {
1917:                        return bounds.transform(crs, true);
1918:                    } catch (Throwable fe) {
1919:                        return bounds;
1920:                    }
1921:                }
1922:                for (IGeoResource resource : getGeoResources()) {
1923:                    try {
1924:                        IGeoResourceInfo info = resource.getInfo(monitor);
1925:                        Envelope tmp = null;
1926:                        if (info != null)
1927:                            tmp = info.getBounds();
1928:
1929:                        ReferencedEnvelope bounds;
1930:                        if (tmp instanceof  ReferencedEnvelope
1931:                                && ((ReferencedEnvelope) tmp)
1932:                                        .getCoordinateReferenceSystem() != null) {
1933:                            bounds = (ReferencedEnvelope) tmp;
1934:                        } else {
1935:                            bounds = new ReferencedEnvelope(tmp.getMinX(), tmp
1936:                                    .getMaxX(), tmp.getMinY(), tmp.getMaxY(),
1937:                                    getCRS());
1938:                        }
1939:                        if (crs == null || bounds.isNull()) {
1940:                            return bounds;
1941:                        }
1942:                        try {
1943:                            return bounds.transform(crs, true);
1944:                        } catch (Exception fe) {
1945:                            return bounds;
1946:                        }
1947:                    } catch (IOException e) {
1948:                        // continue to next
1949:                    }
1950:                }
1951:                return new ReferencedEnvelope(new Envelope(), null);
1952:            }
1953:
1954:            /**
1955:             * Creates A geometry filter for the given layer.
1956:             * 
1957:             * @param boundingBox in the same crs as the viewport model.
1958:             * @return a Geometry filter in the correct CRS or null if an exception occurs.
1959:             */
1960:            public Filter createBBoxFilter(Envelope boundingBox,
1961:                    IProgressMonitor monitor) {
1962:                FilterFactory factory = FilterFactoryFinder
1963:                        .createFilterFactory();
1964:                GeometryFilter bboxFilter = null;
1965:                if (!isType(FeatureSource.class))
1966:                    return Filter.ALL;
1967:                try {
1968:
1969:                    Envelope bbox;
1970:                    try {
1971:                        MathTransform transform = mapToLayerTransform();
1972:                        bbox = JTS.transform(boundingBox, transform);
1973:                    } catch (Exception e) {
1974:                        bbox = boundingBox;
1975:                    }
1976:                    BBoxExpression bb = factory.createBBoxExpression(bbox);
1977:                    bboxFilter = factory
1978:                            .createGeometryFilter(FilterType.GEOMETRY_INTERSECTS);
1979:                    bboxFilter.addRightGeometry(bb);
1980:
1981:                    String geom = getSchema().getDefaultGeometry().getName();
1982:
1983:                    bboxFilter.addLeftGeometry(factory
1984:                            .createAttributeExpression(geom));
1985:
1986:                } catch (Exception e) {
1987:                    ProjectPlugin.getPlugin().log(e);
1988:                }
1989:                return bboxFilter;
1990:            }
1991:
1992:            /**
1993:             * @see net.refractions.udig.project.internal.Layer#getMap()
1994:             */
1995:            public net.refractions.udig.project.internal.Map getMapInternal() {
1996:                ContextModel context = getContextModel();
1997:                if (context == null)
1998:                    return null;
1999:                return context.getMap();
2000:            }
2001:
2002:            /**
2003:             * @see net.refractions.udig.project.ILayer#getMap()
2004:             */
2005:            public IMap getMap() {
2006:                return getMapInternal();
2007:            }
2008:
2009:            /**
2010:             * @see net.refractions.udig.core.IBlockingAdaptable#getAdapter(java.lang.Class,
2011:             *      org.eclipse.core.runtime.IProgressMonitor)
2012:             */
2013:            public <T> T getAdapter(final Class<T> adapter,
2014:                    IProgressMonitor monitor) throws IOException {
2015:                if (hasResource(adapter)) {
2016:                    final List<T> list = new ArrayList<T>();
2017:                    monitor.beginTask(Messages.LayerImpl_resolveAdapter,
2018:                            IProgressMonitor.UNKNOWN);
2019:                    list.add(getResource(adapter, monitor));
2020:                    return list.get(0);
2021:                }
2022:                return null;
2023:            }
2024:
2025:            /**
2026:             * @see net.refractions.udig.core.IBlockingAdaptable#canAdaptTo(java.lang.Class)
2027:             */
2028:            public <T> boolean canAdaptTo(Class<T> adapter) {
2029:                return hasResource(adapter);
2030:            }
2031:
2032:            /**
2033:             * @see net.refractions.udig.project.internal.LayerDecorator#setStatusMessage(java.lang.String)
2034:             * @uml.property name="statusMessage"
2035:             */
2036:            public void setStatusMessage(String message) {
2037:                if (message == null) {
2038:                    this .statusMessage = ""; //$NON-NLS-1$
2039:                } else
2040:                    this .statusMessage = message;
2041:            }
2042:
2043:            /**
2044:             * @see net.refractions.udig.project.internal.LayerDecorator#getStatusMessage()
2045:             * @uml.property name="statusMessage"
2046:             */
2047:            public String getStatusMessage() {
2048:                if (geoResources == NULL || status == ILayer.ERROR)
2049:                    return statusMessage;
2050:                if (isUnknownCRS())
2051:                    return Messages.LayerImpl_unkownCRS;
2052:                return statusMessage;
2053:            }
2054:
2055:            private volatile EList eAdapters;
2056:
2057:            private AtomicBoolean gettingResources = new AtomicBoolean(false);
2058:
2059:            @Override
2060:            public EList eAdapters() {
2061:                if (eAdapters == null) {
2062:                    synchronized (this ) {
2063:                        if (eAdapters == null) {
2064:                            eAdapters = new SynchronizedEList(super .eAdapters());
2065:                        }
2066:                    }
2067:                }
2068:                return eAdapters;
2069:            }
2070:
2071:            void resetConnection(IResolveDelta delta) {
2072:                if (PlatformUI.getWorkbench().isClosing())
2073:                    return;
2074:
2075:                warned = false;
2076:                this .geoResources = null;
2077:                if (delta.getKind() == Kind.CHANGED) {
2078:                    if (delta.getNewValue() == null) {
2079:                        // no change
2080:                        if (delta.getOldValue() == null)
2081:                            return;
2082:                        else {
2083:                            // TODO do something
2084:                            return;
2085:                        }
2086:                    }
2087:                    // no change
2088:                    if (delta.getNewValue().equals(delta.getOldValue()))
2089:                        return;
2090:
2091:                    if (delta.getNewValue() instanceof  Envelope) {
2092:
2093:                        updateBounds();
2094:                    } else {
2095:                        // look for things we're interested in...
2096:                        resetGeoResources();
2097:                    }
2098:
2099:                }
2100:            }
2101:
2102:            /**
2103:             *
2104:             */
2105:            private void updateBounds() {
2106:                ProjectPlugin.trace(Trace.MODEL, getClass(),
2107:                        "bounds changed " + getID(), null); //$NON-NLS-1$
2108:                refresh(null);
2109:            }
2110:
2111:            /**
2112:             *
2113:             */
2114:            private void resetGeoResources() {
2115:                if (eNotificationRequired()) {
2116:                    eNotify(new ENotificationImpl(this , Notification.SET,
2117:                            ProjectPackage.LAYER__GEO_RESOURCES, null, null));
2118:                    eNotify(new ENotificationImpl(this , Notification.SET,
2119:                            ProjectPackage.LAYER__GEO_RESOURCE, null, null));
2120:
2121:                    ProjectPlugin.trace(Trace.MODEL, getClass(),
2122:                            "Smack " + getID(), null); //$NON-NLS-1$
2123:                    refresh(null);
2124:                }
2125:            }
2126:
2127:            @SuppressWarnings("unchecked")
2128:            public void changed(IResolveChangeEvent event) {
2129:                if (eIsProxy()) {
2130:                    CatalogPlugin.removeListener(this );
2131:                    return;
2132:                }
2133:
2134:                if (getMap() == null) {
2135:                    geoResources = null;
2136:                    return;
2137:                }
2138:
2139:                if (geoResources == null)
2140:                    return;
2141:
2142:                if (gettingResources.get()) {
2143:                    return;
2144:                }
2145:
2146:                IResolveDelta delta = event.getDelta();
2147:                IResolve hit = event.getResolve();
2148:
2149:                //Temporary solution while migrating to URI identifiers
2150:                if (delta.getKind() == IResolveDelta.Kind.CHANGED
2151:                        && hit != null) {
2152:
2153:                    URL affected = hit.getIdentifier();
2154:                    URL id = getID();
2155:                    if (id == null)
2156:                        return;
2157:
2158:                    List<IGeoResource> resources = geoResources;
2159:                    for (IGeoResource resource : resources) {
2160:                        if (URLUtils.urlEquals(resource.getIdentifier(),
2161:                                affected, false)) {
2162:                            resetConnection(delta);
2163:                            return;
2164:                        }
2165:                    }
2166:                }
2167:
2168:                // should search throug the whole delta?
2169:                delta = SearchIDDeltaVisitor.search(getID(), event);
2170:                if (delta != null) {
2171:                    ProjectPlugin.trace(Trace.MODEL, getClass(),
2172:                            "Reset resource" + getID(), null); //$NON-NLS-1$
2173:                    resetConnection(delta);
2174:                }
2175:            }
2176:
2177:            public static int doComparison(ILayer layer, ILayer layer2) {
2178:                if (layer2 == null)
2179:                    return 1;
2180:
2181:                if (layer2 == layer)
2182:                    return 0;
2183:
2184:                int i1 = layer.getZorder();
2185:                int i2 = layer2.getZorder();
2186:
2187:                if (i1 == i2)
2188:                    return 0;
2189:                return i1 < i2 ? -1 : 1;
2190:            }
2191:
2192:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.