Source Code Cross Referenced for MapImpl.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: MapImpl.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.io.IOException;
0007:        import java.lang.reflect.InvocationTargetException;
0008:        import java.util.ArrayList;
0009:        import java.util.Collection;
0010:        import java.util.Collections;
0011:        import java.util.Comparator;
0012:        import java.util.HashMap;
0013:        import java.util.Iterator;
0014:        import java.util.List;
0015:        import java.util.TreeSet;
0016:        import java.util.concurrent.CopyOnWriteArraySet;
0017:        import java.util.concurrent.locks.Lock;
0018:
0019:        import net.refractions.udig.project.IBlackboard;
0020:        import net.refractions.udig.project.IEditManager;
0021:        import net.refractions.udig.project.ILayer;
0022:        import net.refractions.udig.project.IMapCompositionListener;
0023:        import net.refractions.udig.project.IMapListener;
0024:        import net.refractions.udig.project.IProject;
0025:        import net.refractions.udig.project.MapCompositionEvent;
0026:        import net.refractions.udig.project.MapEvent;
0027:        import net.refractions.udig.project.MapCompositionEvent.EventType;
0028:        import net.refractions.udig.project.MapEvent.MapEventType;
0029:        import net.refractions.udig.project.command.CommandListener;
0030:        import net.refractions.udig.project.command.CommandManager;
0031:        import net.refractions.udig.project.command.CommandStack;
0032:        import net.refractions.udig.project.command.EditCommand;
0033:        import net.refractions.udig.project.command.MapCommand;
0034:        import net.refractions.udig.project.command.NavCommand;
0035:        import net.refractions.udig.project.command.NavCommandStack;
0036:        import net.refractions.udig.project.internal.Blackboard;
0037:        import net.refractions.udig.project.internal.ContextModel;
0038:        import net.refractions.udig.project.internal.ContextModelListenerAdapter;
0039:        import net.refractions.udig.project.internal.EditManager;
0040:        import net.refractions.udig.project.internal.Layer;
0041:        import net.refractions.udig.project.internal.LayerFactory;
0042:        import net.refractions.udig.project.internal.Map;
0043:        import net.refractions.udig.project.internal.Messages;
0044:        import net.refractions.udig.project.internal.Project;
0045:        import net.refractions.udig.project.internal.ProjectFactory;
0046:        import net.refractions.udig.project.internal.ProjectPackage;
0047:        import net.refractions.udig.project.internal.ProjectPlugin;
0048:        import net.refractions.udig.project.internal.commands.DefaultErrorHandler;
0049:        import net.refractions.udig.project.internal.render.RenderFactory;
0050:        import net.refractions.udig.project.internal.render.RenderManager;
0051:        import net.refractions.udig.project.internal.render.RenderPackage;
0052:        import net.refractions.udig.project.internal.render.ViewportModel;
0053:        import net.refractions.udig.project.internal.render.impl.ViewportModelImpl;
0054:        import net.refractions.udig.project.preferences.PreferenceConstants;
0055:        import net.refractions.udig.project.render.IRenderManager;
0056:        import net.refractions.udig.project.render.IViewportModel;
0057:        import net.refractions.udig.ui.PlatformGIS;
0058:        import net.refractions.udig.ui.ProgressManager;
0059:        import net.refractions.udig.ui.UDIGDisplaySafeLock;
0060:        import net.refractions.udig.ui.palette.ColourScheme;
0061:
0062:        import org.eclipse.core.runtime.IProgressMonitor;
0063:        import org.eclipse.core.runtime.NullProgressMonitor;
0064:        import org.eclipse.emf.common.notify.Adapter;
0065:        import org.eclipse.emf.common.notify.Notification;
0066:        import org.eclipse.emf.common.notify.NotificationChain;
0067:        import org.eclipse.emf.common.notify.impl.AdapterImpl;
0068:        import org.eclipse.emf.common.util.URI;
0069:        import org.eclipse.emf.ecore.EClass;
0070:        import org.eclipse.emf.ecore.EObject;
0071:        import org.eclipse.emf.ecore.EStructuralFeature;
0072:        import org.eclipse.emf.ecore.InternalEObject;
0073:        import org.eclipse.emf.ecore.impl.ENotificationImpl;
0074:        import org.eclipse.emf.ecore.impl.EObjectImpl;
0075:        import org.eclipse.jface.dialogs.ProgressMonitorDialog;
0076:        import org.eclipse.jface.operation.IRunnableWithProgress;
0077:        import org.eclipse.jface.preference.IPreferenceStore;
0078:        import org.eclipse.swt.widgets.Display;
0079:        import org.eclipse.ui.PlatformUI;
0080:        import org.eclipse.ui.model.IWorkbenchAdapter;
0081:        import org.eclipse.ui.model.WorkbenchAdapter;
0082:        import org.geotools.brewer.color.BrewerPalette;
0083:        import org.geotools.data.FeatureSource;
0084:        import org.geotools.feature.FeatureType;
0085:        import org.geotools.filter.Filter;
0086:        import org.geotools.filter.FilterFactory;
0087:        import org.geotools.filter.FilterFactoryFinder;
0088:        import org.geotools.filter.FilterType;
0089:        import org.geotools.filter.GeometryFilter;
0090:        import org.geotools.filter.IllegalFilterException;
0091:        import org.geotools.filter.LogicFilter;
0092:        import org.geotools.geometry.jts.ReferencedEnvelope;
0093:        import org.geotools.referencing.crs.DefaultGeographicCRS;
0094:        import org.opengis.metadata.extent.BoundingPolygon;
0095:        import org.opengis.metadata.extent.Extent;
0096:        import org.opengis.metadata.extent.GeographicBoundingBox;
0097:        import org.opengis.metadata.extent.GeographicExtent;
0098:        import org.opengis.referencing.FactoryException;
0099:        import org.opengis.referencing.crs.CoordinateReferenceSystem;
0100:        import org.opengis.referencing.operation.TransformException;
0101:        import org.opengis.spatialschema.geometry.Geometry;
0102:        import org.opengis.spatialschema.geometry.geometry.Polygon;
0103:
0104:        import com.vividsolutions.jts.geom.Envelope;
0105:
0106:        /**
0107:         * TODO Purpose of net.refractions.udig.project.internal.impl
0108:         * <p>
0109:         * </p>
0110:         *
0111:         * @author Jesse
0112:         * @since 1.0.0
0113:         * @generated
0114:         */
0115:        public class MapImpl extends EObjectImpl implements  Map {
0116:            /**
0117:             * <!-- begin-user-doc --> <!-- end-user-doc -->
0118:             * @generated
0119:             */
0120:            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$
0121:
0122:            /**
0123:             * The default value of the '{@link #getName() <em>Name</em>}' attribute.
0124:             * <!-- begin-user-doc
0125:             * --> <!-- end-user-doc -->
0126:             * @see #getName()
0127:             * @generated
0128:             * @ordered
0129:             */
0130:            protected static final String NAME_EDEFAULT = null;
0131:
0132:            /**
0133:             * The cached value of the '{@link #getName() <em>Name</em>}' attribute.
0134:             * <!-- begin-user-doc
0135:             * --> <!-- end-user-doc -->
0136:             * @see #getName()
0137:             * @generated NOT
0138:             * @ordered
0139:             */
0140:            protected volatile String name = NAME_EDEFAULT;
0141:
0142:            /**
0143:             * The cached value of the '{@link #getProjectInternal() <em>Project Internal</em>}' reference.
0144:             * <!-- begin-user-doc --> <!-- end-user-doc -->
0145:             * @see #getProjectInternal()
0146:             * @generated not
0147:             * @ordered
0148:             */
0149:            protected volatile Project projectInternal = null;
0150:
0151:            /**
0152:             * The cached value of the '{@link #getContextModel() <em>Context Model</em>}' containment reference.
0153:             * <!-- begin-user-doc --> <!-- end-user-doc -->
0154:             * @see #getContextModel()
0155:             * @generated not
0156:             * @ordered
0157:             */
0158:            protected volatile ContextModel contextModel = null;
0159:
0160:            /**
0161:             * The default value of the '{@link #getAbstract() <em>Abstract</em>}' attribute. <!--
0162:             * begin-user-doc --> <!-- end-user-doc -->
0163:             *
0164:             * @see #getAbstract()
0165:             * @generated
0166:             * @ordered
0167:             */
0168:            protected static final String ABSTRACT_EDEFAULT = null;
0169:
0170:            /**
0171:             * The cached value of the '{@link #getAbstract() <em>Abstract</em>}' attribute. <!--
0172:             * begin-user-doc --> <!-- end-user-doc -->
0173:             *
0174:             * @see #getAbstract()
0175:             * @generated not
0176:             * @ordered
0177:             */
0178:            protected volatile String abstract_ = ABSTRACT_EDEFAULT;
0179:
0180:            /**
0181:             * The default value of the '{@link #getNavCommandStack() <em>Nav Command Stack</em>}' attribute.
0182:             * <!-- begin-user-doc --> <!-- end-user-doc -->
0183:             * @see #getNavCommandStack()
0184:             * @generated
0185:             * @ordered
0186:             */
0187:            protected static final NavCommandStack NAV_COMMAND_STACK_EDEFAULT = null;
0188:
0189:            /**
0190:             * The default value of the '{@link #getCommandStack() <em>Command Stack</em>}' attribute.
0191:             * <!-- begin-user-doc --> <!-- end-user-doc -->
0192:             * @see #getCommandStack()
0193:             * @generated
0194:             * @ordered
0195:             */
0196:            protected static final CommandStack COMMAND_STACK_EDEFAULT = null;
0197:
0198:            /**
0199:             * The cached value of the '{@link #getLayerFactory() <em>Layer Factory</em>}' containment reference.
0200:             * <!-- begin-user-doc --> <!-- end-user-doc -->
0201:             * @see #getLayerFactory()
0202:             * @generated not
0203:             * @ordered
0204:             */
0205:            protected volatile LayerFactory layerFactory = null;
0206:
0207:            /**
0208:             * The cached value of the '{@link #getViewportModelInternal() <em>Viewport Model Internal</em>}' containment reference.
0209:             * <!-- begin-user-doc --> <!-- end-user-doc -->
0210:             * @see #getViewportModelInternal()
0211:             * @generated not
0212:             * @ordered
0213:             */
0214:            protected volatile ViewportModel viewportModelInternal = null;
0215:
0216:            /**
0217:             * The default value of the '{@link #getColorPalette() <em>Color Palette</em>}' attribute.
0218:             * <!-- begin-user-doc --> <!-- end-user-doc -->
0219:             *
0220:             * @see #getColorPalette()
0221:             * @generated NOT
0222:             * @ordered
0223:             */
0224:            protected final BrewerPalette COLOR_PALETTE_EDEFAULT = null;
0225:
0226:            /**
0227:             * The cached value of the '{@link #getColorPalette() <em>Color Palette</em>}' attribute. <!--
0228:             * begin-user-doc --> <!-- end-user-doc -->
0229:             *
0230:             * @see #getColorPalette()
0231:             * @generated not
0232:             * @ordered
0233:             */
0234:            protected volatile BrewerPalette colorPalette = PlatformGIS
0235:                    .getColorBrewer()
0236:                    .getPalette(
0237:                            ProjectPlugin
0238:                                    .getPlugin()
0239:                                    .getPreferenceStore()
0240:                                    .getString(
0241:                                            PreferenceConstants.P_DEFAULT_PALETTE));
0242:
0243:            /**
0244:             * The cached value of the '{@link #getEditManagerInternal() <em>Edit Manager Internal</em>}' containment reference.
0245:             * <!-- begin-user-doc --> <!-- end-user-doc -->
0246:             * @see #getEditManagerInternal()
0247:             * @generated not 
0248:             * @ordered
0249:             */
0250:            protected volatile EditManager editManagerInternal = null;
0251:
0252:            /**
0253:             * The cached value of the '{@link #getRenderManagerInternal() <em>Render Manager Internal</em>}' reference.
0254:             * <!-- begin-user-doc --> <!-- end-user-doc -->
0255:             * @see #getRenderManagerInternal()
0256:             * @generated not 
0257:             * @ordered
0258:             */
0259:            protected volatile RenderManager renderManagerInternal = null;
0260:
0261:            /**
0262:             * The default value of the '{@link #getColourScheme() <em>Colour Scheme</em>}' attribute.
0263:             * <!-- begin-user-doc --> <!-- end-user-doc -->
0264:             *
0265:             * @see #getColourScheme()
0266:             * @generated NOT
0267:             * @ordered
0268:             */
0269:            protected static final ColourScheme COLOUR_SCHEME_EDEFAULT = null;
0270:
0271:            private static final List<Layer> EMPTY_LIST = Collections
0272:                    .<Layer> emptyList();
0273:
0274:            /**
0275:             * The cached value of the '{@link #getColourScheme() <em>Colour Scheme</em>}' attribute. <!--
0276:             * begin-user-doc --> <!-- end-user-doc -->
0277:             *
0278:             * @see #getColourScheme()
0279:             * @generated not 
0280:             * @ordered
0281:             */
0282:            protected volatile ColourScheme colourScheme = ColourScheme
0283:                    .getDefault(getColorPalette());
0284:
0285:            /**
0286:             * The cached value of the '{@link #getBlackBoardInternal() <em>Black Board Internal</em>}' containment reference.
0287:             * <!-- begin-user-doc --> <!-- end-user-doc -->
0288:             * @see #getBlackBoardInternal()
0289:             * @generated not
0290:             * @ordered
0291:             */
0292:            protected volatile Blackboard blackBoardInternal = null;
0293:
0294:            /**
0295:             * <p>
0296:             * A Listener to be passed on to the command manager. Will be notified of command completion.
0297:             * </p>
0298:             *
0299:             * @author aalam
0300:             * @since 0.6.0
0301:             */
0302:            public class MapCommandListener implements  CommandListener {
0303:                /** <code>COMMAND</code> field */
0304:                public static final int COMMAND = 0;
0305:
0306:                /** <code>NAV_COMMAND</code> field */
0307:                public static final int NAV_COMMAND = 1;
0308:
0309:                /**
0310:                 * CommandManager will call this function once the command is completed.
0311:                 *
0312:                 * @param commandType
0313:                 */
0314:                public void commandExecuted(int commandType) {
0315:                    switch (commandType) {
0316:                    case COMMAND:
0317:                        notifyCommandDone();
0318:                        break;
0319:                    case NAV_COMMAND:
0320:                        notifyNavCommandDone();
0321:                        break;
0322:                    }
0323:                }
0324:
0325:            };
0326:
0327:            private volatile CommandManager commandManager;
0328:
0329:            private volatile CommandManager navCommandManager;
0330:
0331:            private final Lock lock = new UDIGDisplaySafeLock();
0332:
0333:            /**
0334:             * <!-- begin-user-doc --> <!-- end-user-doc -->
0335:             *
0336:             * @generated NOT
0337:             */
0338:            public MapImpl() {
0339:                super ();
0340:                addMapListenerAdapter();
0341:                setContextModel(new ContextModelImpl());
0342:            }
0343:
0344:            /**
0345:             * Adds an adapter that fires the events to IMapListeners
0346:             */
0347:            @SuppressWarnings("unchecked")
0348:            private void addMapListenerAdapter() {
0349:                eAdapters().add(new AdapterImpl() {
0350:                    @Override
0351:                    public void notifyChanged(Notification msg) {
0352:                        switch (msg.getFeatureID(Map.class)) {
0353:                        case ProjectPackage.MAP__ABSTRACT:
0354:                            notifyMapListeners(new MapEvent(MapImpl.this ,
0355:                                    MapEventType.ABSTRACT, msg.getNewValue(),
0356:                                    msg.getOldValue()));
0357:                            break;
0358:                        case ProjectPackage.MAP__COLOR_PALETTE:
0359:                            notifyMapListeners(new MapEvent(MapImpl.this ,
0360:                                    MapEventType.COLOR_PALETTE, msg
0361:                                            .getNewValue(), msg.getOldValue()));
0362:                            break;
0363:                        case ProjectPackage.MAP__COLOUR_SCHEME:
0364:                            notifyMapListeners(new MapEvent(MapImpl.this ,
0365:                                    MapEventType.COLOUR_SCHEME, msg
0366:                                            .getNewValue(), msg.getOldValue()));
0367:                            break;
0368:                        case ProjectPackage.MAP__COMMAND_STACK:
0369:                            notifyMapListeners(new MapEvent(MapImpl.this ,
0370:                                    MapEventType.MAP_COMMAND,
0371:                                    msg.getNewValue(), msg.getOldValue()));
0372:                            break;
0373:                        case ProjectPackage.MAP__EDIT_MANAGER_INTERNAL:
0374:                            notifyMapListeners(new MapEvent(MapImpl.this ,
0375:                                    MapEventType.EDIT_MANAGER, msg
0376:                                            .getNewValue(), msg.getOldValue()));
0377:                            break;
0378:                        case ProjectPackage.MAP__LAYER_FACTORY:
0379:                            notifyMapListeners(new MapEvent(MapImpl.this ,
0380:                                    MapEventType.LAYER_FACTORY, msg
0381:                                            .getNewValue(), msg.getOldValue()));
0382:                            break;
0383:                        case ProjectPackage.MAP__NAME:
0384:                            notifyMapListeners(new MapEvent(MapImpl.this ,
0385:                                    MapEventType.NAME, msg.getNewValue(), msg
0386:                                            .getOldValue()));
0387:                            break;
0388:                        case ProjectPackage.MAP__NAV_COMMAND_STACK:
0389:                            notifyMapListeners(new MapEvent(MapImpl.this ,
0390:                                    MapEventType.NAV_COMMAND,
0391:                                    msg.getNewValue(), msg.getOldValue()));
0392:                            break;
0393:                        case ProjectPackage.MAP__PROJECT_INTERNAL:
0394:                            notifyMapListeners(new MapEvent(MapImpl.this ,
0395:                                    MapEventType.PROJECT, msg.getNewValue(),
0396:                                    msg.getOldValue()));
0397:                            break;
0398:                        case ProjectPackage.MAP__RENDER_MANAGER_INTERNAL:
0399:                            notifyMapListeners(new MapEvent(MapImpl.this ,
0400:                                    MapEventType.RENDER_MANAGER, msg
0401:                                            .getNewValue(), msg.getOldValue()));
0402:                            break;
0403:                        case ProjectPackage.MAP__VIEWPORT_MODEL_INTERNAL:
0404:                            notifyMapListeners(new MapEvent(MapImpl.this ,
0405:                                    MapEventType.VIEWPORT_MODEL, msg
0406:                                            .getNewValue(), msg.getOldValue()));
0407:                            break;
0408:                        default:
0409:                            break;
0410:                        }
0411:                    }
0412:                });
0413:            }
0414:
0415:            /**
0416:             * <!-- begin-user-doc --> <!-- end-user-doc -->
0417:             * @generated
0418:             */
0419:            protected EClass eStaticClass() {
0420:                return ProjectPackage.eINSTANCE.getMap();
0421:            }
0422:
0423:            /**
0424:             * Retrieves this map's project, searching its parents until it finds one, or returns null if it
0425:             * can't find one.
0426:             *
0427:             * @uml.property name="projectInternal"
0428:             */
0429:            public Project getProjectInternal() {
0430:                Project genResult = getProjectInternalGen();
0431:                if (genResult == null) {
0432:                    EObject parent = eContainer();
0433:                    while (parent != null) {
0434:                        if (parent instanceof  Project) {
0435:                            return (Project) parent;
0436:                        }
0437:
0438:                        parent = parent.eContainer();
0439:                    }
0440:                }
0441:                return genResult;
0442:            }
0443:
0444:            /**
0445:             * <!-- begin-user-doc --> <!-- end-user-doc -->
0446:             * @generated
0447:             */
0448:            public Project getProjectInternalGen() {
0449:                if (projectInternal != null && projectInternal.eIsProxy()) {
0450:                    Project oldProjectInternal = projectInternal;
0451:                    projectInternal = (Project) eResolveProxy((InternalEObject) projectInternal);
0452:                    if (projectInternal != oldProjectInternal) {
0453:                        if (eNotificationRequired())
0454:                            eNotify(new ENotificationImpl(this ,
0455:                                    Notification.RESOLVE,
0456:                                    ProjectPackage.MAP__PROJECT_INTERNAL,
0457:                                    oldProjectInternal, projectInternal));
0458:                    }
0459:                }
0460:                return projectInternal;
0461:            }
0462:
0463:            /**
0464:             * <!-- begin-user-doc --> <!-- end-user-doc -->
0465:             * @generated
0466:             */
0467:            public Project basicGetProjectInternal() {
0468:                return projectInternal;
0469:            }
0470:
0471:            /**
0472:             * <!-- begin-user-doc --> <!-- end-user-doc -->
0473:             * @generated
0474:             */
0475:            public NotificationChain basicSetProjectInternal(
0476:                    Project newProjectInternal, NotificationChain msgs) {
0477:                Project oldProjectInternal = projectInternal;
0478:                projectInternal = newProjectInternal;
0479:                if (eNotificationRequired()) {
0480:                    ENotificationImpl notification = new ENotificationImpl(
0481:                            this , Notification.SET,
0482:                            ProjectPackage.MAP__PROJECT_INTERNAL,
0483:                            oldProjectInternal, newProjectInternal);
0484:                    if (msgs == null)
0485:                        msgs = notification;
0486:                    else
0487:                        msgs.add(notification);
0488:                }
0489:                return msgs;
0490:            }
0491:
0492:            /**
0493:             * <!-- begin-user-doc --> <!-- end-user-doc -->
0494:             * @generated NOT
0495:             */
0496:            public void setProjectInternal(Project newProjectInternal) {
0497:                if (newProjectInternal != projectInternal) {
0498:                    NotificationChain msgs = null;
0499:
0500:                    if (projectInternal != null) {
0501:                        msgs = ((InternalEObject) projectInternal)
0502:                                .eInverseRemove(
0503:                                        this ,
0504:                                        ProjectPackage.PROJECT__ELEMENTS_INTERNAL,
0505:                                        Project.class, msgs);
0506:                    }
0507:                    if (newProjectInternal != null)
0508:                        msgs = ((InternalEObject) newProjectInternal)
0509:                                .eInverseAdd(
0510:                                        this ,
0511:                                        ProjectPackage.PROJECT__ELEMENTS_INTERNAL,
0512:                                        Project.class, msgs);
0513:                    msgs = basicSetProjectInternal(newProjectInternal, msgs);
0514:                    if (msgs != null)
0515:                        msgs.dispatch();
0516:                } else if (eNotificationRequired())
0517:                    eNotify(new ENotificationImpl(this , Notification.SET,
0518:                            ProjectPackage.MAP__PROJECT_INTERNAL,
0519:                            newProjectInternal, newProjectInternal));
0520:            }
0521:
0522:            /**
0523:             * <!-- begin-user-doc --> <!-- end-user-doc -->
0524:             *
0525:             * @uml.property name="contextModel"
0526:             * @generated NOT
0527:             */
0528:            @SuppressWarnings("deprecation")
0529:            public ContextModel getContextModel() {
0530:                if (contextModel == null) {
0531:                    lock.lock();
0532:                    try {
0533:                        if (contextModel == null)
0534:                            setContextModel(ProjectFactory.eINSTANCE
0535:                                    .createContextModel());
0536:                    } finally {
0537:                        lock.unlock();
0538:                    }
0539:                }
0540:                return contextModel;
0541:            }
0542:
0543:            /**
0544:             * <!-- begin-user-doc --> <!-- end-user-doc -->
0545:             * @generated
0546:             */
0547:            @SuppressWarnings("deprecation")
0548:            public NotificationChain basicSetContextModel(
0549:                    ContextModel newContextModel, NotificationChain msgs) {
0550:                ContextModel oldContextModel = contextModel;
0551:                contextModel = newContextModel;
0552:                if (eNotificationRequired()) {
0553:                    ENotificationImpl notification = new ENotificationImpl(
0554:                            this , Notification.SET,
0555:                            ProjectPackage.MAP__CONTEXT_MODEL, oldContextModel,
0556:                            newContextModel);
0557:                    if (msgs == null)
0558:                        msgs = notification;
0559:                    else
0560:                        msgs.add(notification);
0561:                }
0562:                return msgs;
0563:            }
0564:
0565:            final ContextModelListenerAdapter contextModelListener = new ContextModelListenerAdapter() {
0566:                /**
0567:                 * @see net.refractions.udig.project.internal.ContextModelListenerAdapter#notifyChanged(org.eclipse.emf.common.notify.Notification)
0568:                 */
0569:                @SuppressWarnings("deprecation")
0570:                public void notifyChanged(Notification msg) {
0571:                    if (!(msg.getNotifier() instanceof  ContextModel)) {
0572:                        throw new IllegalArgumentException(
0573:                                "This listener should only be added to Context Models"); //$NON-NLS-1$
0574:                    }
0575:
0576:                    setViewportModelAndBounds(msg);
0577:                    fireEventToCompositionListeners(msg);
0578:                    if (eResource() != null)
0579:                        eResource().setModified(true);
0580:                }
0581:
0582:                @SuppressWarnings("deprecation")
0583:                private void fireEventToCompositionListeners(Notification msg) {
0584:                    if (msg.getFeatureID(ContextModel.class) == ProjectPackage.CONTEXT_MODEL__LAYERS) {
0585:                        switch (msg.getEventType()) {
0586:                        case Notification.ADD:
0587:                            notifyCompositionListeners(new MapCompositionEvent(
0588:                                    MapImpl.this , EventType.ADDED, msg
0589:                                            .getNewValue(), msg.getOldValue(),
0590:                                    (ILayer) msg.getNewValue()));
0591:                            break;
0592:                        case Notification.ADD_MANY:
0593:                            notifyCompositionListeners(new MapCompositionEvent(
0594:                                    MapImpl.this , EventType.MANY_ADDED, msg
0595:                                            .getNewValue(), msg.getOldValue(),
0596:                                    null));
0597:                            break;
0598:                        case Notification.REMOVE:
0599:                            notifyCompositionListeners(new MapCompositionEvent(
0600:                                    MapImpl.this , EventType.REMOVED, msg
0601:                                            .getNewValue(), msg.getOldValue(),
0602:                                    (ILayer) msg.getOldValue()));
0603:                            break;
0604:                        case Notification.REMOVE_MANY:
0605:                            notifyCompositionListeners(new MapCompositionEvent(
0606:                                    MapImpl.this , EventType.MANY_REMOVED, msg
0607:                                            .getNewValue(), msg.getOldValue(),
0608:                                    null));
0609:                            break;
0610:                        case Notification.MOVE:
0611:                            notifyCompositionListeners(new MapCompositionEvent(
0612:                                    MapImpl.this , EventType.REORDERED, msg
0613:                                            .getPosition(), msg.getOldValue(),
0614:                                    (ILayer) msg.getNewValue()));
0615:                            break;
0616:
0617:                        default:
0618:                            break;
0619:                        }
0620:                    }
0621:                }
0622:
0623:                /**
0624:                 *
0625:                 * @param msg
0626:                 */
0627:                private void setViewportModelAndBounds(Notification msg) {
0628:                    //TODO: enable in eclipse 3.2            
0629:                    //if( eResource() instanceof Resource.Internal &&
0630:                    //    ((Resource.Internal)eResource()).isLoading() )
0631:                    //return;
0632:                    // set the ViewportModel and bounds of the map correctly when layers are added.
0633:                    // Mainly only necessary when the first layer is added.
0634:                    if (msg.getFeatureID(ContextModel.class) == ProjectPackage.CONTEXT_MODEL__LAYERS) {
0635:                        if (msg.getEventType() == Notification.MOVE)
0636:                            return;
0637:                        boolean initializeViewportModel = false;
0638:                        switch (msg.getEventType()) {
0639:                        case Notification.ADD:
0640:                            if (shouldInitViewport(Collections
0641:                                    .singleton((Layer) msg.getNewValue()))) {
0642:                                initializeViewportModel = true;
0643:                            }
0644:                            break;
0645:                        case Notification.ADD_MANY:
0646:                            if (shouldInitViewport((Collection<Layer>) msg
0647:                                    .getNewValue())) {
0648:                                initializeViewportModel = true;
0649:                            }
0650:                            break;
0651:                        default:
0652:                            initializeViewportModel = false;
0653:                            break;
0654:                        }
0655:                        if (initializeViewportModel) {
0656:                            /* If it is a loading of EMF model from XML resource then on this stage
0657:                             * viewport model is not created but at least one layer is added. No need
0658:                             * to determine CRS while it willbe loaded also from XML later.
0659:                             * 
0660:                             * vitalus
0661:                             * 
0662:                             */
0663:                            EStructuralFeature viewportModelFeature = ProjectPackage.eINSTANCE
0664:                                    .getMap_ViewportModelInternal();
0665:                            if (eIsSet(viewportModelFeature)) {
0666:                                EStructuralFeature feature = RenderPackage.eINSTANCE
0667:                                        .getViewportModel_CRS();
0668:                                if (!getViewportModelInternal().eIsSet(feature)) {
0669:                                    getViewportModelInternal().eSetDeliver(
0670:                                            false);
0671:                                    IPreferenceStore store = ProjectPlugin
0672:                                            .getPlugin().getPreferenceStore();
0673:                                    int i = store
0674:                                            .getInt(PreferenceConstants.P_DEFAULT_CRS);
0675:                                    CoordinateReferenceSystem determinedCRS;
0676:                                    if (i == -1)
0677:                                        determinedCRS = determineCRS();
0678:                                    else
0679:                                        determinedCRS = ViewportModelImpl
0680:                                                .getDefaultCRS();
0681:                                    getViewportModelInternal().setCRS(
0682:                                            determinedCRS);
0683:                                    //              			getViewportModelInternal().setCRS(ViewportModelImpl.getDefaultCRS());
0684:                                    getViewportModelInternal()
0685:                                            .eSetDeliver(true);
0686:                                }
0687:                                getViewportModelInternal().eSetDeliver(false);
0688:                                getViewportModelInternal().zoomToExtent();
0689:                                getViewportModelInternal().eSetDeliver(true);
0690:
0691:                            }
0692:
0693:                        }
0694:                    }
0695:                }
0696:
0697:                /**
0698:                 * Determines what CRS to use for initiallizing the ViewportModel.  Note: this method should only
0699:                 * be called when the first layer(s) are added to the map.
0700:                 * <p>
0701:                 * If there are many layers added to a blank map then the chosen CRS is the most common CRS otherwise it is the crs of
0702:                 * the first layer added.
0703:                 * </p>
0704:                 * @return
0705:                 */
0706:                @SuppressWarnings("unchecked")
0707:                private CoordinateReferenceSystem determineCRS() {
0708:                    List<ILayer> layer = getMapLayers();
0709:                    class Bag implements  Comparable<Bag> {
0710:                        int count;
0711:                        final CoordinateReferenceSystem crs;
0712:
0713:                        Bag(CoordinateReferenceSystem crs) {
0714:                            this .crs = crs;
0715:                        }
0716:
0717:                        public int compareTo(Bag other) {
0718:                            if (count == other.count)
0719:                                return 0;
0720:                            return count < other.count ? 1 : -1;
0721:                        }
0722:                    }
0723:                    ;
0724:                    java.util.Map<CoordinateReferenceSystem, Bag> bags = new HashMap<CoordinateReferenceSystem, Bag>();
0725:                    for (ILayer layer2 : layer) {
0726:                        CoordinateReferenceSystem crs = layer2.getCRS();
0727:                        Bag bag = bags.get(crs);
0728:                        if (bag == null) {
0729:                            bag = new Bag(crs);
0730:                            bags.put(crs, bag);
0731:                        }
0732:                        bag.count++;
0733:                    }
0734:                    TreeSet<Bag> set = new TreeSet<Bag>();
0735:                    set.addAll(bags.values());
0736:                    if (set.isEmpty())
0737:                        return IViewportModel.DEFAULT_CRS;
0738:                    return set.first().crs;
0739:                }
0740:            };
0741:
0742:            /**
0743:             * @see net.refractions.udig.project.internal.Map#setContextModel(net.refractions.udig.project.ContextModel)
0744:             */
0745:            @SuppressWarnings({"unchecked","deprecation"})
0746:            public void setContextModel(ContextModel newContextModel) {
0747:                if (contextModel != null)
0748:                    contextModel.eAdapters().remove(contextModelListener);
0749:                if (newContextModel != null) {
0750:                    newContextModel.eAdapters().add(contextModelListener);
0751:                }
0752:                setContextModelGen(newContextModel);
0753:            }
0754:
0755:            /**
0756:             * Return true if other layers don't define a non-null bounds (see {@link Envelope#isNull()})
0757:             * or the new layers are the first layers added.
0758:             * @return true if other layers don't define a non-null bounds (see {@link Envelope#isNull()})
0759:             * or the new layers are the first layers added.
0760:             */
0761:            protected boolean shouldInitViewport(Collection<Layer> newLayers) {
0762:                List<Layer> layersInternal = getLayersInternal();
0763:                for (Layer layer : layersInternal) {
0764:                    try {
0765:                        // if layer is not one of the new layers and it has a non null bounds then leave the viewport model alone.
0766:                        if (!layer.getBounds(ProgressManager.instance().get(),
0767:                                null).isNull()
0768:                                && !newLayers.contains(layer))
0769:                            return false;
0770:                    } catch (IOException e) {
0771:                        // continue;
0772:                    }
0773:                }
0774:
0775:                return true;
0776:            }
0777:
0778:            /**
0779:             * @generated
0780:             */
0781:            @SuppressWarnings("deprecation")
0782:            public void setContextModelGen(ContextModel newContextModel) {
0783:                if (newContextModel != contextModel) {
0784:                    NotificationChain msgs = null;
0785:                    if (contextModel != null)
0786:                        msgs = ((InternalEObject) contextModel).eInverseRemove(
0787:                                this , ProjectPackage.CONTEXT_MODEL__MAP,
0788:                                ContextModel.class, msgs);
0789:                    if (newContextModel != null)
0790:                        msgs = ((InternalEObject) newContextModel).eInverseAdd(
0791:                                this , ProjectPackage.CONTEXT_MODEL__MAP,
0792:                                ContextModel.class, msgs);
0793:                    msgs = basicSetContextModel(newContextModel, msgs);
0794:                    if (msgs != null)
0795:                        msgs.dispatch();
0796:                } else if (eNotificationRequired())
0797:                    eNotify(new ENotificationImpl(this , Notification.SET,
0798:                            ProjectPackage.MAP__CONTEXT_MODEL, newContextModel,
0799:                            newContextModel));
0800:            }
0801:
0802:            /**
0803:             * <!-- begin-user-doc --> <!-- end-user-doc -->
0804:             *
0805:             * @uml.property name="viewportModelInternal"
0806:             * @generated NOT
0807:             */
0808:            public ViewportModel getViewportModelInternal() {
0809:                if (viewportModelInternal == null)
0810:                    setViewportModelInternalGen(RenderFactory.eINSTANCE
0811:                            .createViewportModel());
0812:                return viewportModelInternal;
0813:            }
0814:
0815:            /**
0816:             * <!-- begin-user-doc --> <!-- end-user-doc -->
0817:             * @generated
0818:             */
0819:            public NotificationChain basicSetViewportModelInternal(
0820:                    ViewportModel newViewportModelInternal,
0821:                    NotificationChain msgs) {
0822:                ViewportModel oldViewportModelInternal = viewportModelInternal;
0823:                viewportModelInternal = newViewportModelInternal;
0824:                if (eNotificationRequired()) {
0825:                    ENotificationImpl notification = new ENotificationImpl(
0826:                            this , Notification.SET,
0827:                            ProjectPackage.MAP__VIEWPORT_MODEL_INTERNAL,
0828:                            oldViewportModelInternal, newViewportModelInternal);
0829:                    if (msgs == null)
0830:                        msgs = notification;
0831:                    else
0832:                        msgs.add(notification);
0833:                }
0834:                return msgs;
0835:            }
0836:
0837:            /**
0838:             * <!-- begin-user-doc --> <!-- end-user-doc -->
0839:             *
0840:             * @uml.property name="viewportModelInternal"
0841:             */
0842:            @SuppressWarnings("unchecked")
0843:            public void setViewportModelInternal(
0844:                    ViewportModel newViewportModelInternal) {
0845:                setViewportModelInternalGen(newViewportModelInternal);
0846:                if (getRenderManager() != null) {
0847:                    getRenderManagerInternal().setViewportModelInternal(
0848:                            newViewportModelInternal);
0849:                }
0850:                newViewportModelInternal.eAdapters().add(adapter);
0851:            }
0852:
0853:            /**
0854:             * <!-- begin-user-doc --> <!-- end-user-doc -->
0855:             * @generated
0856:             */
0857:            public void setViewportModelInternalGen(
0858:                    ViewportModel newViewportModelInternal) {
0859:                if (newViewportModelInternal != viewportModelInternal) {
0860:                    NotificationChain msgs = null;
0861:                    if (viewportModelInternal != null)
0862:                        msgs = ((InternalEObject) viewportModelInternal)
0863:                                .eInverseRemove(
0864:                                        this ,
0865:                                        RenderPackage.VIEWPORT_MODEL__MAP_INTERNAL,
0866:                                        ViewportModel.class, msgs);
0867:                    if (newViewportModelInternal != null)
0868:                        msgs = ((InternalEObject) newViewportModelInternal)
0869:                                .eInverseAdd(
0870:                                        this ,
0871:                                        RenderPackage.VIEWPORT_MODEL__MAP_INTERNAL,
0872:                                        ViewportModel.class, msgs);
0873:                    msgs = basicSetViewportModelInternal(
0874:                            newViewportModelInternal, msgs);
0875:                    if (msgs != null)
0876:                        msgs.dispatch();
0877:                } else if (eNotificationRequired())
0878:                    eNotify(new ENotificationImpl(this , Notification.SET,
0879:                            ProjectPackage.MAP__VIEWPORT_MODEL_INTERNAL,
0880:                            newViewportModelInternal, newViewportModelInternal));
0881:            }
0882:
0883:            /**
0884:             * <!-- begin-user-doc --> <!-- end-user-doc -->
0885:             * @generated
0886:             */
0887:            public BrewerPalette getColorPalette() {
0888:                if (colorPalette == null) {
0889:                    String defaultPalette = ProjectPlugin.getPlugin()
0890:                            .getPreferenceStore().getString(
0891:                                    PreferenceConstants.P_DEFAULT_PALETTE);
0892:                    if (defaultPalette == null
0893:                            || !PlatformGIS.getColorBrewer().hasPalette(
0894:                                    defaultPalette))
0895:                        defaultPalette = "Dark2"; //failsafe default //$NON-NLS-1$
0896:                    colorPalette = PlatformGIS.getColorBrewer().getPalette(
0897:                            defaultPalette);
0898:                }
0899:                return colorPalette;
0900:            }
0901:
0902:            /**
0903:             * <!-- begin-user-doc --> <!-- end-user-doc -->
0904:             * @generated
0905:             */
0906:            public void setColorPalette(BrewerPalette newColorPalette) {
0907:                BrewerPalette oldColorPalette = colorPalette;
0908:                colorPalette = newColorPalette;
0909:                if (colourScheme.getColourPalette() != colorPalette) {
0910:                    colourScheme.setColourPalette(colorPalette);
0911:                }
0912:                if (eNotificationRequired())
0913:                    eNotify(new ENotificationImpl(this , Notification.SET,
0914:                            ProjectPackage.MAP__COLOR_PALETTE, oldColorPalette,
0915:                            colorPalette));
0916:            }
0917:
0918:            /**
0919:             * <!-- begin-user-doc --> <!-- end-user-doc -->
0920:             * @generated
0921:             */
0922:            public String getAbstract() {
0923:                return abstract_;
0924:            }
0925:
0926:            /**
0927:             * <!-- begin-user-doc --> <!-- end-user-doc -->
0928:             * @generated
0929:             */
0930:            public void setAbstract(String newAbstract) {
0931:                String oldAbstract = abstract_;
0932:                abstract_ = newAbstract;
0933:                if (eNotificationRequired())
0934:                    eNotify(new ENotificationImpl(this , Notification.SET,
0935:                            ProjectPackage.MAP__ABSTRACT, oldAbstract,
0936:                            abstract_));
0937:            }
0938:
0939:            /**
0940:             * <!-- begin-user-doc --> <!-- end-user-doc -->
0941:             * @generated
0942:             */
0943:            public String getName() {
0944:                return name;
0945:            }
0946:
0947:            /**
0948:             * <!-- begin-user-doc --> <!-- end-user-doc -->
0949:             * @generated
0950:             */
0951:            public void setName(String newName) {
0952:                String oldName = name;
0953:                name = newName;
0954:                if (eNotificationRequired())
0955:                    eNotify(new ENotificationImpl(this , Notification.SET,
0956:                            ProjectPackage.MAP__NAME, oldName, name));
0957:            }
0958:
0959:            public URI getID() {
0960:                if (eResource() == null)
0961:                    return URI.createFileURI(getName());
0962:                return eResource().getURI();
0963:            }
0964:
0965:            /**
0966:             * <!-- begin-user-doc --> <!-- end-user-doc -->
0967:             * 
0968:             * @throws IOException
0969:             * @generated NOT
0970:             */
0971:            public ReferencedEnvelope getBounds(IProgressMonitor monitor) {
0972:                if (getLayersInternal() != null) {
0973:                    ReferencedEnvelope bounds = new ReferencedEnvelope(
0974:                            getViewportModel().getCRS());
0975:                    bounds.setToNull();
0976:                    List<Layer> layers = new ArrayList<Layer>(
0977:                            getLayersInternal());
0978:                    for (Layer layer : layers) {
0979:                        ReferencedEnvelope bbox;
0980:                        try {
0981:                            bbox = layer.getBounds(null, getViewportModel()
0982:                                    .getCRS());
0983:
0984:                            if (!bbox.isNull()) {
0985:                                if (bounds.isNull())
0986:                                    bounds.init(bbox);
0987:                                else
0988:                                    bounds.expandToInclude(bbox);
0989:                            }
0990:                        } catch (IOException e) {
0991:                            ProjectPlugin.log(null, e);
0992:                        }
0993:                    }
0994:                    if (getLayersInternal() != EMPTY_LIST) {
0995:                        if (bounds.isNull())
0996:                            return getDefaultBounds();
0997:
0998:                    }
0999:                    return bounds;
1000:                } else {
1001:                    return getDefaultBounds();
1002:                }
1003:
1004:            }
1005:
1006:            private ReferencedEnvelope getDefaultBounds() {
1007:                if (getViewportModel().getCRS().getValidArea() != null) {
1008:                    Extent extent = getViewportModel().getCRS().getValidArea();
1009:                    ReferencedEnvelope env = toReferencedEnvelope(extent,
1010:                            getViewportModel().getCRS());
1011:                    if (env != null) {
1012:                        ProjectPlugin
1013:                                .log("MapImpl#getDefaultBounds(): Returning valid area of " + env.getCoordinateReferenceSystem().getName().toString()); //$NON-NLS-1$
1014:                        return env;
1015:                    }
1016:                }
1017:                ProjectPlugin
1018:                        .log("MapImpl#getDefaultBounds(): Returning Default bounds (entire world)"); //$NON-NLS-1$
1019:                return new ReferencedEnvelope(new Envelope(-180, 180, -90, 90),
1020:                        DefaultGeographicCRS.WGS84);
1021:            }
1022:
1023:            /**
1024:             * Takes an Extent, usually from a {@link CoordinateReferenceSystem}, and converts it to a ReferencedEnvelope
1025:             *
1026:             * @param extent the extent to convert.
1027:             * @param crs the desired CRS of the ReferencedEnvelope.
1028:             * @return
1029:             */
1030:            public static ReferencedEnvelope toReferencedEnvelope(
1031:                    Extent extent, CoordinateReferenceSystem crs) {
1032:                if (extent == null)
1033:                    return null;
1034:                Collection<GeographicExtent> elems = extent
1035:                        .getGeographicElements();
1036:                for (GeographicExtent extent2 : elems) {
1037:                    ReferencedEnvelope env = null;
1038:                    if (extent2 instanceof  GeographicBoundingBox) {
1039:                        GeographicBoundingBox box = (GeographicBoundingBox) extent2;
1040:                        env = new ReferencedEnvelope(box
1041:                                .getWestBoundLongitude(), box
1042:                                .getEastBoundLongitude(), box
1043:                                .getSouthBoundLatitude(), box
1044:                                .getNorthBoundLatitude(),
1045:                                DefaultGeographicCRS.WGS84);
1046:                    } else if (extent2 instanceof  BoundingPolygon) {
1047:                        BoundingPolygon boundingpoly = (BoundingPolygon) extent2;
1048:                        Collection<Geometry> polygons = boundingpoly
1049:                                .getPolygons();
1050:                        for (Geometry geometry : polygons) {
1051:                            Polygon poly = (Polygon) geometry;
1052:                            org.opengis.spatialschema.geometry.Envelope envelope = poly
1053:                                    .getBoundary().getEnvelope();
1054:                            env = new ReferencedEnvelope(
1055:                                    envelope.getMinimum(0), envelope
1056:                                            .getMaximum(0), envelope
1057:                                            .getMinimum(1), envelope
1058:                                            .getMaximum(1), envelope
1059:                                            .getLowerCorner()
1060:                                            .getCoordinateReferenceSystem());
1061:                            break;
1062:                        }
1063:                    }
1064:
1065:                    if (env != null) {
1066:                        try {
1067:                            env = env.transform(crs, true);
1068:                        } catch (TransformException e) {
1069:                            ProjectPlugin
1070:                                    .log(
1071:                                            "error transforming " + env + " to " + crs.getName().toString(), e); //$NON-NLS-1$ //$NON-NLS-2$
1072:                        } catch (FactoryException e) {
1073:                            ProjectPlugin
1074:                                    .log(
1075:                                            "error transforming " + env + " to " + crs.getName().toString(), e); //$NON-NLS-1$ //$NON-NLS-2$
1076:                        }
1077:                        return env;
1078:                    }
1079:                }
1080:                return null;
1081:            }
1082:
1083:            /**
1084:             * <!-- begin-user-doc --> <!-- end-user-doc -->
1085:             * 
1086:             * @generated NOT
1087:             */
1088:            public double getAspectRatio(IProgressMonitor monitor) {
1089:                ReferencedEnvelope bounds = getBounds(monitor);
1090:                return bounds.getWidth() / bounds.getHeight();
1091:            }
1092:
1093:            /**
1094:             * <!-- begin-user-doc --> <!-- end-user-doc -->
1095:             *
1096:             * @generated NOT
1097:             */
1098:            public NavCommandStack getNavCommandStack() {
1099:                synchronized (CommandManager.class) {
1100:                    if (this .navCommandManager == null) {
1101:                        this .navCommandManager = new CommandManager(
1102:                                Messages.MapImpl_NavigationCommandStack,
1103:                                new DefaultErrorHandler(),
1104:                                new MapCommandListener());
1105:
1106:                    }
1107:                }
1108:                return navCommandManager;
1109:            }
1110:
1111:            /**
1112:             * <!-- begin-user-doc --> <!-- end-user-doc -->
1113:             *
1114:             * @generated NOT
1115:             */
1116:            public CommandStack getCommandStack() {
1117:                synchronized (CommandManager.class) {
1118:                    if (this .commandManager == null) {
1119:                        this .commandManager = new CommandManager(
1120:                                Messages.MapImpl_CommandStack,
1121:                                new DefaultErrorHandler(),
1122:                                new MapCommandListener());
1123:
1124:                    }
1125:                }
1126:                return commandManager;
1127:            }
1128:
1129:            /**
1130:             * <!-- begin-user-doc --> <!-- end-user-doc -->
1131:             *
1132:             * @uml.property name="layerFactory"
1133:             * @generated NOT
1134:             */
1135:            public LayerFactory getLayerFactory() {
1136:                if (layerFactory == null)
1137:                    setLayerFactory(ProjectFactory.eINSTANCE
1138:                            .createLayerFactory());
1139:                return layerFactory;
1140:            }
1141:
1142:            /**
1143:             * <!-- begin-user-doc --> <!-- end-user-doc -->
1144:             * @generated
1145:             */
1146:            public NotificationChain basicSetLayerFactory(
1147:                    LayerFactory newLayerFactory, NotificationChain msgs) {
1148:                LayerFactory oldLayerFactory = layerFactory;
1149:                layerFactory = newLayerFactory;
1150:                if (eNotificationRequired()) {
1151:                    ENotificationImpl notification = new ENotificationImpl(
1152:                            this , Notification.SET,
1153:                            ProjectPackage.MAP__LAYER_FACTORY, oldLayerFactory,
1154:                            newLayerFactory);
1155:                    if (msgs == null)
1156:                        msgs = notification;
1157:                    else
1158:                        msgs.add(notification);
1159:                }
1160:                return msgs;
1161:            }
1162:
1163:            /**
1164:             * <!-- begin-user-doc --> <!-- end-user-doc -->
1165:             * @generated
1166:             */
1167:            public void setLayerFactory(LayerFactory newLayerFactory) {
1168:                if (newLayerFactory != layerFactory) {
1169:                    NotificationChain msgs = null;
1170:                    if (layerFactory != null)
1171:                        msgs = ((InternalEObject) layerFactory).eInverseRemove(
1172:                                this , ProjectPackage.LAYER_FACTORY__MAP,
1173:                                LayerFactory.class, msgs);
1174:                    if (newLayerFactory != null)
1175:                        msgs = ((InternalEObject) newLayerFactory).eInverseAdd(
1176:                                this , ProjectPackage.LAYER_FACTORY__MAP,
1177:                                LayerFactory.class, msgs);
1178:                    msgs = basicSetLayerFactory(newLayerFactory, msgs);
1179:                    if (msgs != null)
1180:                        msgs.dispatch();
1181:                } else if (eNotificationRequired())
1182:                    eNotify(new ENotificationImpl(this , Notification.SET,
1183:                            ProjectPackage.MAP__LAYER_FACTORY, newLayerFactory,
1184:                            newLayerFactory));
1185:            }
1186:
1187:            /**
1188:             * <!-- begin-user-doc --> <!-- end-user-doc -->
1189:             *
1190:             * @generated NOT
1191:             */
1192:            private void sendCommand(MapCommand command, boolean async) {
1193:                sendCommandInternal(command, async);
1194:            }
1195:
1196:            /**
1197:             * <!-- begin-user-doc --> <!-- end-user-doc -->
1198:             *
1199:             * @generated NOT
1200:             */
1201:            public void sendCommandInternal(MapCommand command, boolean async) {
1202:                // make sure to initialize command manager
1203:                getCommandStack();
1204:
1205:                command.setMap(this );
1206:                commandManager.execute(command, async);
1207:                //        notifyCommandStackChange();
1208:            }
1209:
1210:            /**
1211:             * <!-- begin-user-doc --> <!-- end-user-doc -->
1212:             *
1213:             * @generated NOT
1214:             */
1215:            private void sendCommand(EditCommand command, boolean async) {
1216:                sendCommandInternal(command, async);
1217:            }
1218:
1219:            /**
1220:             * <!-- begin-user-doc --> <!-- end-user-doc -->
1221:             *
1222:             * @generated NOT
1223:             */
1224:            private void sendCommand(NavCommand command, boolean async) {
1225:
1226:                // init command manager
1227:                getNavCommandStack();
1228:
1229:                command.setMap(this );
1230:                command.setViewportModel(getViewportModelInternal());
1231:                navCommandManager.execute(command, async);
1232:            }
1233:
1234:            private void notifyCommandStackChange() {
1235:                if (eNotificationRequired())
1236:                    eNotify(new ENotificationImpl(this , Notification.SET,
1237:                            ProjectPackage.MAP__COMMAND_STACK, null,
1238:                            commandManager));
1239:            }
1240:
1241:            private void notifyNavCommandStackChange() {
1242:                if (eNotificationRequired())
1243:                    eNotify(new ENotificationImpl(this , Notification.SET,
1244:                            ProjectPackage.MAP__NAV_COMMAND_STACK, null,
1245:                            commandManager));
1246:            }
1247:
1248:            /**
1249:             * notifyNavCommandDone is called by the CommandManager when a nav command is finished running.
1250:             */
1251:            public void notifyNavCommandDone() {
1252:                notifyNavCommandStackChange();
1253:            }
1254:
1255:            /**
1256:             * notifyCommandDone is called by the CommandManager when a non-nav command is finished running.
1257:             */
1258:            public void notifyCommandDone() {
1259:                notifyCommandStackChange();
1260:            }
1261:
1262:            /**
1263:             * Creates and fires a batch notification.
1264:             *
1265:             * @param featureID the id of the layer's feature that has changed
1266:             * @param eventType the type of event that has occurred (see {@linkplain Notification})
1267:             */
1268:            void notifyBatchNotification(int featureID, int eventType) {
1269:                if (eNotificationRequired()) {
1270:                    // create bas notification
1271:                    ENotificationImpl notifications = new BatchNotification(
1272:                            this , eventType, ProjectPackage.MAP__BATCH_EVENT);
1273:                    // Create layer notifications
1274:                    for (Layer layer : getContextModel().getLayers()) {
1275:                        EStructuralFeature feature = layer.eClass()
1276:                                .getEStructuralFeature(featureID);
1277:                        ENotificationImpl notification = new ENotificationImpl(
1278:                                (InternalEObject) layer, eventType, featureID,
1279:                                null, layer.eGet(feature));
1280:                        notifications.add(notification);
1281:                    }
1282:                    eNotify(notifications);
1283:                }
1284:            }
1285:
1286:            private static class BatchNotification extends ENotificationImpl
1287:                    implements  Iterable<Notification> {
1288:
1289:                /**
1290:                 * Construct <code>BatchNotification</code>.
1291:                 */
1292:                public BatchNotification(MapImpl notifier, int eventType,
1293:                        int featureid) {
1294:                    super (notifier, eventType, featureid, null, null);
1295:                }
1296:
1297:                List<Notification> notifications = new ArrayList<Notification>();
1298:
1299:                /**
1300:                 * @see org.eclipse.emf.common.notify.impl.NotificationImpl#add(org.eclipse.emf.common.notify.Notification)
1301:                 */
1302:                public boolean add(Notification newNotification) {
1303:                    if (notifications.contains(newNotification))
1304:                        return false;
1305:
1306:                    notifications.add(newNotification);
1307:                    Collections.sort(notifications,
1308:                            new Comparator<Notification>() {
1309:
1310:                                public int compare(Notification o1,
1311:                                        Notification o2) {
1312:                                    Layer layer1 = (Layer) o1.getNotifier();
1313:                                    Layer layer2 = (Layer) o2.getNotifier();
1314:                                    return layer1.compareTo(layer2);
1315:                                }
1316:
1317:                            });
1318:                    return true;
1319:                }
1320:
1321:                /**
1322:                 * @see java.lang.Iterable#iterator()
1323:                 */
1324:                public Iterator<Notification> iterator() {
1325:                    return notifications.iterator();
1326:                }
1327:
1328:            }
1329:
1330:            /**
1331:             * <!-- begin-user-doc --> <!-- end-user-doc -->
1332:             *
1333:             * @generated NOT
1334:             */
1335:            public void redo() {
1336:                if (commandManager == null
1337:                        || !commandManager.hasForwardHistory())
1338:                    return;
1339:                commandManager.redo(true);
1340:                notifyCommandStackChange();
1341:            }
1342:
1343:            /**
1344:             * <!-- begin-user-doc --> <!-- end-user-doc -->
1345:             *
1346:             * @generated NOT
1347:             */
1348:            public void undo() {
1349:                if (commandManager == null || !commandManager.hasBackHistory())
1350:                    return;
1351:                commandManager.undo(true);
1352:                notifyCommandStackChange();
1353:            }
1354:
1355:            /**
1356:             * <!-- begin-user-doc --> <!-- end-user-doc -->
1357:             *
1358:             * @generated NOT
1359:             */
1360:            public void backwardHistory() {
1361:                if (navCommandManager == null
1362:                        || !navCommandManager.hasBackHistory())
1363:                    return;
1364:                navCommandManager.undo(true);
1365:            }
1366:
1367:            /**
1368:             * <!-- begin-user-doc --> <!-- end-user-doc -->
1369:             *
1370:             * @generated NOT
1371:             */
1372:            public void forwardHistory() {
1373:                if (navCommandManager == null
1374:                        || !navCommandManager.hasForwardHistory())
1375:                    return;
1376:                navCommandManager.redo(true);
1377:            }
1378:
1379:            /**
1380:             * <!-- begin-user-doc --> <!-- end-user-doc -->
1381:             *
1382:             * @uml.property name="editManagerInternal"
1383:             * @generated NOT
1384:             */
1385:            public EditManager getEditManagerInternal() {
1386:                if (editManagerInternal == null) {
1387:                    setEditManagerInternal(ProjectFactory.eINSTANCE
1388:                            .createEditManager());
1389:                }
1390:                return editManagerInternal;
1391:            }
1392:
1393:            /**
1394:             * <!-- begin-user-doc --> <!-- end-user-doc -->
1395:             * @generated
1396:             */
1397:            public NotificationChain basicSetEditManagerInternal(
1398:                    EditManager newEditManagerInternal, NotificationChain msgs) {
1399:                EditManager oldEditManagerInternal = editManagerInternal;
1400:                editManagerInternal = newEditManagerInternal;
1401:                if (eNotificationRequired()) {
1402:                    ENotificationImpl notification = new ENotificationImpl(
1403:                            this , Notification.SET,
1404:                            ProjectPackage.MAP__EDIT_MANAGER_INTERNAL,
1405:                            oldEditManagerInternal, newEditManagerInternal);
1406:                    if (msgs == null)
1407:                        msgs = notification;
1408:                    else
1409:                        msgs.add(notification);
1410:                }
1411:                return msgs;
1412:            }
1413:
1414:            /**
1415:             * <!-- begin-user-doc --> <!-- end-user-doc -->
1416:             * @generated
1417:             */
1418:            public void setEditManagerInternal(
1419:                    EditManager newEditManagerInternal) {
1420:                if (newEditManagerInternal != editManagerInternal) {
1421:                    NotificationChain msgs = null;
1422:                    if (editManagerInternal != null)
1423:                        msgs = ((InternalEObject) editManagerInternal)
1424:                                .eInverseRemove(
1425:                                        this ,
1426:                                        ProjectPackage.EDIT_MANAGER__MAP_INTERNAL,
1427:                                        EditManager.class, msgs);
1428:                    if (newEditManagerInternal != null)
1429:                        msgs = ((InternalEObject) newEditManagerInternal)
1430:                                .eInverseAdd(
1431:                                        this ,
1432:                                        ProjectPackage.EDIT_MANAGER__MAP_INTERNAL,
1433:                                        EditManager.class, msgs);
1434:                    msgs = basicSetEditManagerInternal(newEditManagerInternal,
1435:                            msgs);
1436:                    if (msgs != null)
1437:                        msgs.dispatch();
1438:                } else if (eNotificationRequired())
1439:                    eNotify(new ENotificationImpl(this , Notification.SET,
1440:                            ProjectPackage.MAP__EDIT_MANAGER_INTERNAL,
1441:                            newEditManagerInternal, newEditManagerInternal));
1442:            }
1443:
1444:            /**
1445:             * <!-- begin-user-doc --> <!-- end-user-doc -->
1446:             * @generated
1447:             */
1448:            public RenderManager getRenderManagerInternal() {
1449:                if (renderManagerInternal != null
1450:                        && renderManagerInternal.eIsProxy()) {
1451:                    RenderManager oldRenderManagerInternal = renderManagerInternal;
1452:                    renderManagerInternal = (RenderManager) eResolveProxy((InternalEObject) renderManagerInternal);
1453:                    if (renderManagerInternal != oldRenderManagerInternal) {
1454:                        if (eNotificationRequired())
1455:                            eNotify(new ENotificationImpl(
1456:                                    this ,
1457:                                    Notification.RESOLVE,
1458:                                    ProjectPackage.MAP__RENDER_MANAGER_INTERNAL,
1459:                                    oldRenderManagerInternal,
1460:                                    renderManagerInternal));
1461:                    }
1462:                }
1463:                return renderManagerInternal;
1464:            }
1465:
1466:            /**
1467:             * <!-- begin-user-doc --> <!-- end-user-doc -->
1468:             * @generated
1469:             */
1470:            public RenderManager basicGetRenderManagerInternal() {
1471:                return renderManagerInternal;
1472:            }
1473:
1474:            /**
1475:             * <!-- begin-user-doc --> <!-- end-user-doc -->
1476:             * @generated
1477:             */
1478:            public NotificationChain basicSetRenderManagerInternal(
1479:                    RenderManager newRenderManagerInternal,
1480:                    NotificationChain msgs) {
1481:                RenderManager oldRenderManagerInternal = renderManagerInternal;
1482:                renderManagerInternal = newRenderManagerInternal;
1483:                if (eNotificationRequired()) {
1484:                    ENotificationImpl notification = new ENotificationImpl(
1485:                            this , Notification.SET,
1486:                            ProjectPackage.MAP__RENDER_MANAGER_INTERNAL,
1487:                            oldRenderManagerInternal, newRenderManagerInternal);
1488:                    if (msgs == null)
1489:                        msgs = notification;
1490:                    else
1491:                        msgs.add(notification);
1492:                }
1493:                return msgs;
1494:            }
1495:
1496:            /**
1497:             * <!-- begin-user-doc --> <!-- end-user-doc -->
1498:             * @generated
1499:             */
1500:            public void setRenderManagerInternalGen(
1501:                    RenderManager newRenderManagerInternal) {
1502:                if (newRenderManagerInternal != renderManagerInternal) {
1503:                    NotificationChain msgs = null;
1504:                    if (renderManagerInternal != null)
1505:                        msgs = ((InternalEObject) renderManagerInternal)
1506:                                .eInverseRemove(
1507:                                        this ,
1508:                                        RenderPackage.RENDER_MANAGER__MAP_INTERNAL,
1509:                                        RenderManager.class, msgs);
1510:                    if (newRenderManagerInternal != null)
1511:                        msgs = ((InternalEObject) newRenderManagerInternal)
1512:                                .eInverseAdd(
1513:                                        this ,
1514:                                        RenderPackage.RENDER_MANAGER__MAP_INTERNAL,
1515:                                        RenderManager.class, msgs);
1516:                    msgs = basicSetRenderManagerInternal(
1517:                            newRenderManagerInternal, msgs);
1518:                    if (msgs != null)
1519:                        msgs.dispatch();
1520:                } else if (eNotificationRequired())
1521:                    eNotify(new ENotificationImpl(this , Notification.SET,
1522:                            ProjectPackage.MAP__RENDER_MANAGER_INTERNAL,
1523:                            newRenderManagerInternal, newRenderManagerInternal));
1524:            }
1525:
1526:            Adapter adapter = new AdapterImpl() {
1527:                /**
1528:                 * @see org.eclipse.emf.common.notify.impl.AdapterImpl#notifyChanged(org.eclipse.emf.common.notify.Notification)
1529:                 */
1530:                public void notifyChanged(Notification msg) {
1531:                    switch (msg.getFeatureID(RenderManager.class)) {
1532:                    case RenderPackage.RENDER_MANAGER__VIEWPORT_MODEL_INTERNAL: {
1533:                        if (msg.getEventType() == Notification.ADD)
1534:                            if (getViewportModel() != msg.getNewValue())
1535:                                setViewportModelInternal((ViewportModel) msg
1536:                                        .getNewValue());
1537:                        break;
1538:                    }
1539:                    }
1540:                    switch (msg.getFeatureID(ViewportModel.class)) {
1541:                    case RenderPackage.VIEWPORT_MODEL__RENDER_MANAGER_INTERNAL: {
1542:                        if (msg.getEventType() == Notification.ADD)
1543:                            if (getRenderManager() != msg.getNewValue())
1544:                                setRenderManagerInternal((RenderManager) msg
1545:                                        .getNewValue());
1546:                        break;
1547:                    }
1548:                    }
1549:                }
1550:            };
1551:
1552:            /**
1553:             * @see net.refractions.udig.project.internal.Map#setRenderManager(net.refractions.udig.project.render.RenderManager)
1554:             * @uml.property name="renderManagerInternal"
1555:             */
1556:            @SuppressWarnings("unchecked")
1557:            public void setRenderManagerInternal(RenderManager newRenderManager) {
1558:                setRenderManagerInternalGen(newRenderManager);
1559:                if (newRenderManager != null)
1560:                    newRenderManager.eAdapters().add(adapter);
1561:                if (getViewportModel() != null) {
1562:                    getViewportModelInternal().setRenderManagerInternal(
1563:                            newRenderManager);
1564:                }
1565:            }
1566:
1567:            /**
1568:             * <!-- begin-user-doc --> <!-- end-user-doc -->
1569:             * @generated
1570:             */
1571:            public ColourScheme getColourScheme() {
1572:                return colourScheme;
1573:            }
1574:
1575:            /**
1576:             * <!-- begin-user-doc --> <!-- end-user-doc -->
1577:             * @generated
1578:             */
1579:            public void setColourScheme(ColourScheme newColourScheme) {
1580:                ColourScheme oldColourScheme = colourScheme;
1581:                colourScheme = newColourScheme;
1582:                if (eNotificationRequired())
1583:                    eNotify(new ENotificationImpl(this , Notification.SET,
1584:                            ProjectPackage.MAP__COLOUR_SCHEME, oldColourScheme,
1585:                            colourScheme));
1586:            }
1587:
1588:            /*
1589:             * (non-Javadoc)
1590:             *
1591:             * @see net.refractions.udig.project.IMap#getBlackboard()
1592:             */
1593:            public IBlackboard getBlackboard() {
1594:                return getBlackBoardInternal();
1595:            }
1596:
1597:            /**
1598:             * <!-- begin-user-doc --> <!-- end-user-doc -->
1599:             * @generated
1600:             */
1601:            public Blackboard getBlackBoardInternal() {
1602:                return blackBoardInternal;
1603:            }
1604:
1605:            /**
1606:             * <!-- begin-user-doc --> <!-- end-user-doc -->
1607:             * @generated
1608:             */
1609:            public NotificationChain basicSetBlackBoardInternal(
1610:                    Blackboard newBlackBoardInternal, NotificationChain msgs) {
1611:                Blackboard oldBlackBoardInternal = blackBoardInternal;
1612:                blackBoardInternal = newBlackBoardInternal;
1613:                if (eNotificationRequired()) {
1614:                    ENotificationImpl notification = new ENotificationImpl(
1615:                            this , Notification.SET,
1616:                            ProjectPackage.MAP__BLACK_BOARD_INTERNAL,
1617:                            oldBlackBoardInternal, newBlackBoardInternal);
1618:                    if (msgs == null)
1619:                        msgs = notification;
1620:                    else
1621:                        msgs.add(notification);
1622:                }
1623:                return msgs;
1624:            }
1625:
1626:            /**
1627:             * <!-- begin-user-doc --> <!-- end-user-doc -->
1628:             * @generated
1629:             */
1630:            public void setBlackBoardInternal(Blackboard newBlackBoardInternal) {
1631:                if (newBlackBoardInternal != blackBoardInternal) {
1632:                    NotificationChain msgs = null;
1633:                    if (blackBoardInternal != null)
1634:                        msgs = ((InternalEObject) blackBoardInternal)
1635:                                .eInverseRemove(
1636:                                        this ,
1637:                                        EOPPOSITE_FEATURE_BASE
1638:                                                - ProjectPackage.MAP__BLACK_BOARD_INTERNAL,
1639:                                        null, msgs);
1640:                    if (newBlackBoardInternal != null)
1641:                        msgs = ((InternalEObject) newBlackBoardInternal)
1642:                                .eInverseAdd(
1643:                                        this ,
1644:                                        EOPPOSITE_FEATURE_BASE
1645:                                                - ProjectPackage.MAP__BLACK_BOARD_INTERNAL,
1646:                                        null, msgs);
1647:                    msgs = basicSetBlackBoardInternal(newBlackBoardInternal,
1648:                            msgs);
1649:                    if (msgs != null)
1650:                        msgs.dispatch();
1651:                } else if (eNotificationRequired())
1652:                    eNotify(new ENotificationImpl(this , Notification.SET,
1653:                            ProjectPackage.MAP__BLACK_BOARD_INTERNAL,
1654:                            newBlackBoardInternal, newBlackBoardInternal));
1655:            }
1656:
1657:            /**
1658:             * <!-- begin-user-doc --> <!-- end-user-doc -->
1659:             * @generated
1660:             */
1661:            public NotificationChain eInverseAdd(InternalEObject otherEnd,
1662:                    int featureID, Class baseClass, NotificationChain msgs) {
1663:                if (featureID >= 0) {
1664:                    switch (eDerivedStructuralFeatureID(featureID, baseClass)) {
1665:                    case ProjectPackage.MAP__PROJECT_INTERNAL:
1666:                        if (projectInternal != null)
1667:                            msgs = ((InternalEObject) projectInternal)
1668:                                    .eInverseRemove(
1669:                                            this ,
1670:                                            ProjectPackage.PROJECT__ELEMENTS_INTERNAL,
1671:                                            Project.class, msgs);
1672:                        return basicSetProjectInternal((Project) otherEnd, msgs);
1673:                    case ProjectPackage.MAP__CONTEXT_MODEL:
1674:                        if (contextModel != null)
1675:                            msgs = ((InternalEObject) contextModel)
1676:                                    .eInverseRemove(
1677:                                            this ,
1678:                                            EOPPOSITE_FEATURE_BASE
1679:                                                    - ProjectPackage.MAP__CONTEXT_MODEL,
1680:                                            null, msgs);
1681:                        return basicSetContextModel((ContextModel) otherEnd,
1682:                                msgs);
1683:                    case ProjectPackage.MAP__LAYER_FACTORY:
1684:                        if (layerFactory != null)
1685:                            msgs = ((InternalEObject) layerFactory)
1686:                                    .eInverseRemove(
1687:                                            this ,
1688:                                            EOPPOSITE_FEATURE_BASE
1689:                                                    - ProjectPackage.MAP__LAYER_FACTORY,
1690:                                            null, msgs);
1691:                        return basicSetLayerFactory((LayerFactory) otherEnd,
1692:                                msgs);
1693:                    case ProjectPackage.MAP__VIEWPORT_MODEL_INTERNAL:
1694:                        if (viewportModelInternal != null)
1695:                            msgs = ((InternalEObject) viewportModelInternal)
1696:                                    .eInverseRemove(
1697:                                            this ,
1698:                                            EOPPOSITE_FEATURE_BASE
1699:                                                    - ProjectPackage.MAP__VIEWPORT_MODEL_INTERNAL,
1700:                                            null, msgs);
1701:                        return basicSetViewportModelInternal(
1702:                                (ViewportModel) otherEnd, msgs);
1703:                    case ProjectPackage.MAP__EDIT_MANAGER_INTERNAL:
1704:                        if (editManagerInternal != null)
1705:                            msgs = ((InternalEObject) editManagerInternal)
1706:                                    .eInverseRemove(
1707:                                            this ,
1708:                                            EOPPOSITE_FEATURE_BASE
1709:                                                    - ProjectPackage.MAP__EDIT_MANAGER_INTERNAL,
1710:                                            null, msgs);
1711:                        return basicSetEditManagerInternal(
1712:                                (EditManager) otherEnd, msgs);
1713:                    case ProjectPackage.MAP__RENDER_MANAGER_INTERNAL:
1714:                        if (renderManagerInternal != null)
1715:                            msgs = ((InternalEObject) renderManagerInternal)
1716:                                    .eInverseRemove(
1717:                                            this ,
1718:                                            RenderPackage.RENDER_MANAGER__MAP_INTERNAL,
1719:                                            RenderManager.class, msgs);
1720:                        return basicSetRenderManagerInternal(
1721:                                (RenderManager) otherEnd, msgs);
1722:                    default:
1723:                        return eDynamicInverseAdd(otherEnd, featureID,
1724:                                baseClass, msgs);
1725:                    }
1726:                }
1727:                if (eContainer != null)
1728:                    msgs = eBasicRemoveFromContainer(msgs);
1729:                return eBasicSetContainer(otherEnd, featureID, msgs);
1730:            }
1731:
1732:            /**
1733:             * <!-- begin-user-doc --> <!-- end-user-doc -->
1734:             * @generated
1735:             */
1736:            public NotificationChain eInverseRemove(InternalEObject otherEnd,
1737:                    int featureID, Class baseClass, NotificationChain msgs) {
1738:                if (featureID >= 0) {
1739:                    switch (eDerivedStructuralFeatureID(featureID, baseClass)) {
1740:                    case ProjectPackage.MAP__PROJECT_INTERNAL:
1741:                        return basicSetProjectInternal(null, msgs);
1742:                    case ProjectPackage.MAP__CONTEXT_MODEL:
1743:                        return basicSetContextModel(null, msgs);
1744:                    case ProjectPackage.MAP__LAYER_FACTORY:
1745:                        return basicSetLayerFactory(null, msgs);
1746:                    case ProjectPackage.MAP__VIEWPORT_MODEL_INTERNAL:
1747:                        return basicSetViewportModelInternal(null, msgs);
1748:                    case ProjectPackage.MAP__EDIT_MANAGER_INTERNAL:
1749:                        return basicSetEditManagerInternal(null, msgs);
1750:                    case ProjectPackage.MAP__RENDER_MANAGER_INTERNAL:
1751:                        return basicSetRenderManagerInternal(null, msgs);
1752:                    case ProjectPackage.MAP__BLACK_BOARD_INTERNAL:
1753:                        return basicSetBlackBoardInternal(null, msgs);
1754:                    default:
1755:                        return eDynamicInverseRemove(otherEnd, featureID,
1756:                                baseClass, msgs);
1757:                    }
1758:                }
1759:                return eBasicSetContainer(null, featureID, msgs);
1760:            }
1761:
1762:            /**
1763:             * @see org.eclipse.emf.ecore.impl.BasicEObjectImpl#eGet(org.eclipse.emf.ecore.EStructuralFeature,
1764:             *      boolean)
1765:             */
1766:            public Object eGet(EStructuralFeature eFeature, boolean resolve) {
1767:                return eGetGen(eFeature, resolve);
1768:            }
1769:
1770:            /**
1771:             * EMF will generate to this method instead of eGet
1772:             *
1773:             * @generated
1774:             */
1775:            public Object eGetGen(EStructuralFeature eFeature, boolean resolve) {
1776:                switch (eDerivedStructuralFeatureID(eFeature)) {
1777:                case ProjectPackage.MAP__NAME:
1778:                    return getName();
1779:                case ProjectPackage.MAP__PROJECT_INTERNAL:
1780:                    if (resolve)
1781:                        return getProjectInternal();
1782:                    return basicGetProjectInternal();
1783:                case ProjectPackage.MAP__CONTEXT_MODEL:
1784:                    return getContextModel();
1785:                case ProjectPackage.MAP__ABSTRACT:
1786:                    return getAbstract();
1787:                case ProjectPackage.MAP__NAV_COMMAND_STACK:
1788:                    return getNavCommandStack();
1789:                case ProjectPackage.MAP__COMMAND_STACK:
1790:                    return getCommandStack();
1791:                case ProjectPackage.MAP__LAYER_FACTORY:
1792:                    return getLayerFactory();
1793:                case ProjectPackage.MAP__VIEWPORT_MODEL_INTERNAL:
1794:                    return getViewportModelInternal();
1795:                case ProjectPackage.MAP__COLOR_PALETTE:
1796:                    return getColorPalette();
1797:                case ProjectPackage.MAP__EDIT_MANAGER_INTERNAL:
1798:                    return getEditManagerInternal();
1799:                case ProjectPackage.MAP__RENDER_MANAGER_INTERNAL:
1800:                    if (resolve)
1801:                        return getRenderManagerInternal();
1802:                    return basicGetRenderManagerInternal();
1803:                case ProjectPackage.MAP__COLOUR_SCHEME:
1804:                    return getColourScheme();
1805:                case ProjectPackage.MAP__BLACK_BOARD_INTERNAL:
1806:                    return getBlackBoardInternal();
1807:                }
1808:                return eDynamicGet(eFeature, resolve);
1809:            }
1810:
1811:            /**
1812:             * <!-- begin-user-doc --> <!-- end-user-doc -->
1813:             * @generated
1814:             */
1815:            public void eSet(EStructuralFeature eFeature, Object newValue) {
1816:                switch (eDerivedStructuralFeatureID(eFeature)) {
1817:                case ProjectPackage.MAP__NAME:
1818:                    setName((String) newValue);
1819:                    return;
1820:                case ProjectPackage.MAP__PROJECT_INTERNAL:
1821:                    setProjectInternal((Project) newValue);
1822:                    return;
1823:                case ProjectPackage.MAP__CONTEXT_MODEL:
1824:                    setContextModel((ContextModel) newValue);
1825:                    return;
1826:                case ProjectPackage.MAP__ABSTRACT:
1827:                    setAbstract((String) newValue);
1828:                    return;
1829:                case ProjectPackage.MAP__LAYER_FACTORY:
1830:                    setLayerFactory((LayerFactory) newValue);
1831:                    return;
1832:                case ProjectPackage.MAP__VIEWPORT_MODEL_INTERNAL:
1833:                    setViewportModelInternal((ViewportModel) newValue);
1834:                    return;
1835:                case ProjectPackage.MAP__COLOR_PALETTE:
1836:                    setColorPalette((BrewerPalette) newValue);
1837:                    return;
1838:                case ProjectPackage.MAP__EDIT_MANAGER_INTERNAL:
1839:                    setEditManagerInternal((EditManager) newValue);
1840:                    return;
1841:                case ProjectPackage.MAP__RENDER_MANAGER_INTERNAL:
1842:                    setRenderManagerInternal((RenderManager) newValue);
1843:                    return;
1844:                case ProjectPackage.MAP__COLOUR_SCHEME:
1845:                    setColourScheme((ColourScheme) newValue);
1846:                    return;
1847:                case ProjectPackage.MAP__BLACK_BOARD_INTERNAL:
1848:                    setBlackBoardInternal((Blackboard) newValue);
1849:                    return;
1850:                }
1851:                eDynamicSet(eFeature, newValue);
1852:            }
1853:
1854:            /**
1855:             * <!-- begin-user-doc --> <!-- end-user-doc -->
1856:             * @generated
1857:             */
1858:            public void eUnset(EStructuralFeature eFeature) {
1859:                switch (eDerivedStructuralFeatureID(eFeature)) {
1860:                case ProjectPackage.MAP__NAME:
1861:                    setName(NAME_EDEFAULT);
1862:                    return;
1863:                case ProjectPackage.MAP__PROJECT_INTERNAL:
1864:                    setProjectInternal((Project) null);
1865:                    return;
1866:                case ProjectPackage.MAP__CONTEXT_MODEL:
1867:                    setContextModel((ContextModel) null);
1868:                    return;
1869:                case ProjectPackage.MAP__ABSTRACT:
1870:                    setAbstract(ABSTRACT_EDEFAULT);
1871:                    return;
1872:                case ProjectPackage.MAP__LAYER_FACTORY:
1873:                    setLayerFactory((LayerFactory) null);
1874:                    return;
1875:                case ProjectPackage.MAP__VIEWPORT_MODEL_INTERNAL:
1876:                    setViewportModelInternal((ViewportModel) null);
1877:                    return;
1878:                case ProjectPackage.MAP__COLOR_PALETTE:
1879:                    setColorPalette(COLOR_PALETTE_EDEFAULT);
1880:                    return;
1881:                case ProjectPackage.MAP__EDIT_MANAGER_INTERNAL:
1882:                    setEditManagerInternal((EditManager) null);
1883:                    return;
1884:                case ProjectPackage.MAP__RENDER_MANAGER_INTERNAL:
1885:                    setRenderManagerInternal((RenderManager) null);
1886:                    return;
1887:                case ProjectPackage.MAP__COLOUR_SCHEME:
1888:                    setColourScheme(COLOUR_SCHEME_EDEFAULT);
1889:                    return;
1890:                case ProjectPackage.MAP__BLACK_BOARD_INTERNAL:
1891:                    setBlackBoardInternal((Blackboard) null);
1892:                    return;
1893:                }
1894:                eDynamicUnset(eFeature);
1895:            }
1896:
1897:            /**
1898:             * <!-- begin-user-doc --> <!-- end-user-doc -->
1899:             * @generated
1900:             */
1901:            public boolean eIsSet(EStructuralFeature eFeature) {
1902:                switch (eDerivedStructuralFeatureID(eFeature)) {
1903:                case ProjectPackage.MAP__NAME:
1904:                    return NAME_EDEFAULT == null ? name != null
1905:                            : !NAME_EDEFAULT.equals(name);
1906:                case ProjectPackage.MAP__PROJECT_INTERNAL:
1907:                    return projectInternal != null;
1908:                case ProjectPackage.MAP__CONTEXT_MODEL:
1909:                    return contextModel != null;
1910:                case ProjectPackage.MAP__ABSTRACT:
1911:                    return ABSTRACT_EDEFAULT == null ? abstract_ != null
1912:                            : !ABSTRACT_EDEFAULT.equals(abstract_);
1913:                case ProjectPackage.MAP__NAV_COMMAND_STACK:
1914:                    return NAV_COMMAND_STACK_EDEFAULT == null ? getNavCommandStack() != null
1915:                            : !NAV_COMMAND_STACK_EDEFAULT
1916:                                    .equals(getNavCommandStack());
1917:                case ProjectPackage.MAP__COMMAND_STACK:
1918:                    return COMMAND_STACK_EDEFAULT == null ? getCommandStack() != null
1919:                            : !COMMAND_STACK_EDEFAULT.equals(getCommandStack());
1920:                case ProjectPackage.MAP__LAYER_FACTORY:
1921:                    return layerFactory != null;
1922:                case ProjectPackage.MAP__VIEWPORT_MODEL_INTERNAL:
1923:                    return viewportModelInternal != null;
1924:                case ProjectPackage.MAP__COLOR_PALETTE:
1925:                    return COLOR_PALETTE_EDEFAULT == null ? colorPalette != null
1926:                            : !COLOR_PALETTE_EDEFAULT.equals(colorPalette);
1927:                case ProjectPackage.MAP__EDIT_MANAGER_INTERNAL:
1928:                    return editManagerInternal != null;
1929:                case ProjectPackage.MAP__RENDER_MANAGER_INTERNAL:
1930:                    return renderManagerInternal != null;
1931:                case ProjectPackage.MAP__COLOUR_SCHEME:
1932:                    return COLOUR_SCHEME_EDEFAULT == null ? colourScheme != null
1933:                            : !COLOUR_SCHEME_EDEFAULT.equals(colourScheme);
1934:                case ProjectPackage.MAP__BLACK_BOARD_INTERNAL:
1935:                    return blackBoardInternal != null;
1936:                }
1937:                return eDynamicIsSet(eFeature);
1938:            }
1939:
1940:            /**
1941:             * <!-- begin-user-doc --> <!-- end-user-doc -->
1942:             * @generated
1943:             */
1944:            public String toString() {
1945:                if (eIsProxy())
1946:                    return super .toString();
1947:
1948:                StringBuffer result = new StringBuffer(super .toString());
1949:                result.append(" (name: "); //$NON-NLS-1$
1950:                result.append(name);
1951:                result.append(", abstract: "); //$NON-NLS-1$
1952:                result.append(abstract_);
1953:                result.append(", colorPalette: "); //$NON-NLS-1$
1954:                result.append(colorPalette);
1955:                result.append(", colourScheme: "); //$NON-NLS-1$
1956:                result.append(colourScheme);
1957:                result.append(')');
1958:                return result.toString();
1959:            }
1960:
1961:            /**
1962:             * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class)
1963:             */
1964:            @SuppressWarnings("unchecked")
1965:            public Object getAdapter(Class adapter) {
1966:                for (Iterator i = eAdapters().iterator(); i.hasNext();) {
1967:                    Object o = i.next();
1968:                    if (adapter.isAssignableFrom(o.getClass()))
1969:                        return o;
1970:                }
1971:
1972:                /*
1973:                 * Adapt to an IWorkbenchAdapter. Other aspects of Eclipse can read the
1974:                 * properties we provide access to. (example: Property page dialogs
1975:                 * can read the label and display that in their title.)
1976:                 */
1977:                if (adapter.isAssignableFrom(IWorkbenchAdapter.class)) {
1978:                    return new WorkbenchAdapter() {
1979:
1980:                        @Override
1981:                        public String getLabel(Object object) {
1982:                            return getName();
1983:                        }
1984:
1985:                    };
1986:                }
1987:                return null;
1988:            }
1989:
1990:            /**
1991:             * @see net.refractions.udig.project.IProjectElement#getProject()
1992:             */
1993:            public IProject getProject() {
1994:                return getProjectInternal();
1995:            }
1996:
1997:            /**
1998:             * @see net.refractions.udig.project.IMap#getViewportModel()
1999:             */
2000:            public IViewportModel getViewportModel() {
2001:                return getViewportModelInternal();
2002:            }
2003:
2004:            /**
2005:             * @see net.refractions.udig.project.IMap#getEditManager()
2006:             */
2007:            public IEditManager getEditManager() {
2008:                return getEditManagerInternal();
2009:            }
2010:
2011:            /**
2012:             * @see net.refractions.udig.project.IMap#getRenderManager()
2013:             */
2014:            public IRenderManager getRenderManager() {
2015:                return getRenderManagerInternal();
2016:            }
2017:
2018:            /**
2019:             * @see net.refractions.udig.project.IMap#getMapLayers()
2020:             */
2021:            @SuppressWarnings("unchecked")
2022:            public List getMapLayers() {
2023:                return Collections.unmodifiableList(getLayersInternal());
2024:            }
2025:
2026:            @SuppressWarnings("unchecked")
2027:            public List<Layer> getLayersInternal() {
2028:                if (getContextModel() == null)
2029:                    return EMPTY_LIST;
2030:                return getContextModel().getLayers();
2031:            }
2032:
2033:            public void sendCommandSync(MapCommand command) {
2034:                if (command instanceof  NavCommand)
2035:                    sendCommand((NavCommand) command, false);
2036:                else if (command instanceof  EditCommand)
2037:                    sendCommand((EditCommand) command, false);
2038:                else
2039:                    sendCommand(command, false);
2040:            }
2041:
2042:            public void sendCommandASync(MapCommand command) {
2043:                if (command instanceof  NavCommand)
2044:                    sendCommand((NavCommand) command, true);
2045:                else if (command instanceof  EditCommand)
2046:                    sendCommand((EditCommand) command, true);
2047:                else
2048:                    sendCommand(command, true);
2049:            }
2050:
2051:            public void executeSyncWithoutUndo(final MapCommand command) {
2052:                command.setMap(this );
2053:                if (Display.getCurrent() != null) {
2054:                    ProgressMonitorDialog dialog = new ProgressMonitorDialog(
2055:                            PlatformUI.getWorkbench()
2056:                                    .getActiveWorkbenchWindow().getShell());
2057:                    dialog.setOpenOnRun(true);
2058:                    try {
2059:                        dialog.run(false, false, new IRunnableWithProgress() {
2060:
2061:                            public void run(IProgressMonitor monitor)
2062:                                    throws InvocationTargetException,
2063:                                    InterruptedException {
2064:                                try {
2065:                                    command.run(monitor);
2066:                                } catch (Exception e) {
2067:                                    ProjectPlugin
2068:                                            .log(
2069:                                                    "Error executing command: " + command.getName(), e); //$NON-NLS-1$
2070:                                }
2071:                            }
2072:
2073:                        });
2074:                    } catch (InvocationTargetException e) {
2075:                        ProjectPlugin
2076:                                .log(
2077:                                        "Error executing command: " + command.getName(), e); //$NON-NLS-1$
2078:                    } catch (InterruptedException e) {
2079:                        ProjectPlugin
2080:                                .log(
2081:                                        "Error executing command: " + command.getName(), e); //$NON-NLS-1$
2082:                    }
2083:                } else {
2084:                    try {
2085:                        command.run(new NullProgressMonitor());
2086:                    } catch (Exception e) {
2087:                        ProjectPlugin
2088:                                .log(
2089:                                        "Error executing command: " + command.getName(), e); //$NON-NLS-1$
2090:                    }
2091:                }
2092:            }
2093:
2094:            public void executeASyncWithoutUndo(final MapCommand command) {
2095:                PlatformGIS.run(new IRunnableWithProgress() {
2096:
2097:                    public void run(IProgressMonitor monitor)
2098:                            throws InvocationTargetException,
2099:                            InterruptedException {
2100:                        try {
2101:                            command.run(monitor);
2102:                        } catch (Exception e) {
2103:                            ProjectPlugin
2104:                                    .log(
2105:                                            "Error executing command: " + command.getName(), e); //$NON-NLS-1$
2106:                        }
2107:                    }
2108:
2109:                });
2110:            }
2111:
2112:            public String getFileExtension() {
2113:                return "umap"; //$NON-NLS-1$
2114:            }
2115:
2116:            private void notifyMapListeners(MapEvent event) {
2117:                for (IMapListener listener : mapListeners) {
2118:                    try {
2119:                        listener.changed(event);
2120:                    } catch (Throwable t) {
2121:                        ProjectPlugin.log("", t); //$NON-NLS-1$
2122:                    }
2123:                }
2124:            }
2125:
2126:            private void notifyCompositionListeners(MapCompositionEvent event) {
2127:                for (IMapCompositionListener listener : compositionListeners) {
2128:                    try {
2129:                        listener.changed(event);
2130:                    } catch (Throwable t) {
2131:                        ProjectPlugin.log("", t); //$NON-NLS-1$
2132:                    }
2133:                }
2134:            }
2135:
2136:            CopyOnWriteArraySet<IMapListener> mapListeners = new CopyOnWriteArraySet<IMapListener>();
2137:            CopyOnWriteArraySet<IMapCompositionListener> compositionListeners = new CopyOnWriteArraySet<IMapCompositionListener>();
2138:
2139:            public void addMapListener(IMapListener listener) {
2140:                mapListeners.add(listener);
2141:            }
2142:
2143:            public void removeMapListener(IMapListener listener) {
2144:                mapListeners.remove(listener);
2145:            }
2146:
2147:            public void addMapCompositionListener(
2148:                    IMapCompositionListener listener) {
2149:                compositionListeners.add(listener);
2150:            }
2151:
2152:            public void removeMapCompositionListener(
2153:                    IMapCompositionListener listener) {
2154:                compositionListeners.remove(listener);
2155:            }
2156:
2157:            public List<Color> getMapDefaultColours() {
2158:                List<Layer> layers = getLayersInternal();
2159:                List<Color> colours = new ArrayList<Color>();
2160:                for (Layer layer : layers) {
2161:                    Color this Colour = layer.getDefaultColor();
2162:                    if (this Colour != null) {
2163:                        colours.add(this Colour);
2164:                    }
2165:                }
2166:                return colours;
2167:            }
2168:
2169:            public void addDeepAdapter(Adapter adapter) {
2170:                ((LayersList2) getLayersInternal()).addDeepAdapter(adapter);
2171:            }
2172:
2173:            public void removeDeepAdapter(Adapter adapter) {
2174:                ((LayersList2) getLayersInternal()).removeDeepAdapter(adapter);
2175:            }
2176:
2177:            public void lowerLayer(Layer layer) {
2178:                int index = getLayersInternal().indexOf(layer);
2179:                if (index == 0)
2180:                    return;
2181:                ((LayersList2) getLayersInternal()).move(index--, index);
2182:            }
2183:
2184:            public void raiseLayer(Layer layer) {
2185:                int index = getLayersInternal().indexOf(layer);
2186:                if (index > getLayersInternal().size() - 2)
2187:                    return;
2188:                ((LayersList2) getLayersInternal()).move(index++, index);
2189:            }
2190:
2191:            private GeometryFilter localize(FeatureType schema,
2192:                    GeometryFilter filter) {
2193:                FilterFactory factory = FilterFactoryFinder
2194:                        .createFilterFactory();
2195:
2196:                GeometryFilter copy;
2197:                try {
2198:                    copy = factory.createGeometryFilter(filter.getFilterType());
2199:
2200:                    String geom = schema.getDefaultGeometry().getName();
2201:
2202:                    copy.addLeftGeometry(factory
2203:                            .createAttributeExpression(geom));
2204:                    copy.addRightGeometry(filter.getRightGeometry());
2205:
2206:                    return copy;
2207:                } catch (IllegalFilterException e) {
2208:                    return null;
2209:                }
2210:            }
2211:
2212:            /*
2213:             * Constructs a filter for the provided layer, based on the GeometryFilter.
2214:             */
2215:            private Filter target(Layer layer, Filter filter) {
2216:                if (!layer.isSelectable()) {
2217:                    return Filter.NONE;
2218:                }
2219:                try {
2220:                    FeatureSource featureSource = layer.getResource(
2221:                            FeatureSource.class, null);
2222:                    if (featureSource == null) {
2223:                        return Filter.NONE;
2224:                    }
2225:
2226:                    FeatureType schema = layer.getSchema();
2227:
2228:                    Filter copy;
2229:                    if (filter instanceof  GeometryFilter)
2230:                        copy = localize(schema, (GeometryFilter) filter);
2231:                    else
2232:                        copy = filter;
2233:
2234:                    if (copy == null) {
2235:                        return Filter.NONE;
2236:                    }
2237:                    return copy;
2238:                } catch (IOException e) {
2239:                    ProjectPlugin.log(null, e);
2240:                    return Filter.NONE;
2241:                }
2242:            }
2243:
2244:            public void select(Envelope boundingBox) {
2245:                Layer selected = getEditManagerInternal().getSelectedLayer();
2246:                LAYERS: for (Layer layer : getLayersInternal()) {
2247:                    if (layer == selected) {
2248:                        Filter newFilter = layer.createBBoxFilter(boundingBox,
2249:                                null);
2250:                        if (newFilter == null)
2251:                            continue LAYERS;
2252:                        layer.setFilter(newFilter);
2253:                    } else {
2254:                        layer.setFilter(Filter.ALL);
2255:                    }
2256:                }
2257:                notifyBatchNotification(ProjectPackage.LAYER__FILTER,
2258:                        Notification.SET);
2259:            }
2260:
2261:            public void select(Envelope boundingBox, boolean add) {
2262:                Layer selected = getEditManagerInternal().getSelectedLayer();
2263:                LAYERS: for (Layer layer : getLayersInternal()) {
2264:                    if (layer == selected) {
2265:                        Filter oldFilter = layer.getFilter();
2266:                        Filter newFilter = null;
2267:                        newFilter = layer.createBBoxFilter(boundingBox, null);
2268:                        if (newFilter == null)
2269:                            continue LAYERS;
2270:                        if (oldFilter == null || oldFilter == Filter.ALL
2271:                                || oldFilter.equals(Filter.ALL)) {
2272:                            layer.setFilter(newFilter);
2273:                        } else {
2274:                            FilterFactory createFilterFactory = FilterFactoryFinder
2275:                                    .createFilterFactory();
2276:                            if (!add) {
2277:                                // WARNING: and() is destructive for the target object, ie the object left of '.'
2278:                                // and so which object gets and()'ed to what matters here.  Don't swap unless necessary.
2279:                                try {
2280:                                    LogicFilter logicFilter;
2281:                                    LogicFilter notFilter = createFilterFactory
2282:                                            .createLogicFilter(newFilter,
2283:                                                    FilterType.LOGIC_NOT);
2284:                                    logicFilter = createFilterFactory
2285:                                            .createLogicFilter(notFilter,
2286:                                                    oldFilter,
2287:                                                    FilterType.LOGIC_AND);
2288:                                    layer.setFilter(logicFilter);
2289:                                } catch (IllegalFilterException e) {
2290:                                    ProjectPlugin.log(
2291:                                            "error creating logic filter", e); //$NON-NLS-1$
2292:                                }
2293:                            } else {
2294:                                // WARNING: or() is also destructive on its target, see comment above.
2295:                                // TODO: this is inefficient.  We should switch from using bboxes to a geometry
2296:                                // representing the selected area, then we can just use symmetric difference to handle
2297:                                // deselection instead of continuously appending more LogicFilters.
2298:                                try {
2299:                                    LogicFilter orFilter = createFilterFactory
2300:                                            .createLogicFilter(newFilter,
2301:                                                    oldFilter,
2302:                                                    FilterType.LOGIC_OR);
2303:
2304:                                    layer.setFilter(orFilter);
2305:                                } catch (IllegalFilterException e) {
2306:                                    ProjectPlugin.log(
2307:                                            "error creating logic filter", e); //$NON-NLS-1$
2308:                                }
2309:                            }
2310:                        }
2311:                    } else {
2312:                        layer.setFilter(Filter.ALL);
2313:                    }
2314:
2315:                }
2316:            }
2317:
2318:            /**
2319:             * @see net.refractions.udig.project.internal.ContextModel#select(Filter)
2320:             * @generated NOT
2321:             */
2322:            public void select(Filter filter) {
2323:                Layer selected = getEditManagerInternal().getSelectedLayer();
2324:                for (Layer layer : getLayersInternal()) {
2325:                    if (layer == selected) {
2326:                        layer.setFilter(target(layer, filter)); // replace
2327:                    } else {
2328:                        layer.setFilter(Filter.ALL);
2329:                    }
2330:                }
2331:            }
2332:
2333:            /**
2334:             * @see net.refractions.udig.project.internal.ContextModel#select(Filter, boolean)
2335:             * @generated NOT
2336:             */
2337:            public void select(Filter filter, boolean and) {
2338:                Layer selected = getEditManagerInternal().getSelectedLayer();
2339:                for (Layer layer : getLayersInternal()) {
2340:                    if (layer == selected) {
2341:                        Filter oldFilter = layer.getFilter();
2342:
2343:                        if (oldFilter == null || oldFilter == Filter.ALL
2344:                                || oldFilter.equals(Filter.ALL)) {
2345:                            layer.setFilter(target(layer, filter));
2346:                        } else {
2347:
2348:                            FilterFactory createFilterFactory = FilterFactoryFinder
2349:                                    .createFilterFactory();
2350:
2351:                            if (!and) {
2352:                                try {
2353:                                    LogicFilter logicFilter;
2354:                                    logicFilter = createFilterFactory
2355:                                            .createLogicFilter(oldFilter,
2356:                                                    target(layer, filter),
2357:                                                    FilterType.LOGIC_AND);
2358:                                    layer.setFilter(logicFilter);
2359:                                } catch (IllegalFilterException e) {
2360:                                    ProjectPlugin.log(
2361:                                            "error creating logic filter", e); //$NON-NLS-1$
2362:                                }
2363:                            } else {
2364:                                try {
2365:                                    LogicFilter logicFilter;
2366:                                    logicFilter = createFilterFactory
2367:                                            .createLogicFilter(oldFilter,
2368:                                                    target(layer, filter),
2369:                                                    FilterType.LOGIC_OR);
2370:                                    layer.setFilter(logicFilter);
2371:                                } catch (IllegalFilterException e) {
2372:                                    ProjectPlugin.log(
2373:                                            "error creating logic filter", e); //$NON-NLS-1$
2374:                                }
2375:                            }
2376:                        }
2377:                    } else {
2378:                        layer.setFilter(Filter.ALL);
2379:                    }
2380:                }
2381:            }
2382:
2383:            public void select(Filter filter, ILayer layerObj) {
2384:
2385:                Layer layer = (Layer) layerObj;
2386:                if (getLayersInternal().contains(layer)) {
2387:                    for (Layer layer2 : getLayersInternal()) {
2388:                        if (layer == layer2) {
2389:                            layer2.setFilter(target(layer, filter)); // replace
2390:                        } else {
2391:                            layer2.setFilter(Filter.ALL);
2392:                        }
2393:                    }
2394:                }
2395:            }
2396:
2397:        } // MapImpl
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.