Source Code Cross Referenced for EditManagerImpl.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) 


001:        /**
002:         * <copyright></copyright> $Id: EditManagerImpl.java 23502 2006-12-18 20:45:10Z jeichar $
003:         */package net.refractions.udig.project.internal.impl;
004:
005:        import java.io.IOException;
006:        import java.util.HashMap;
007:        import java.util.Iterator;
008:        import java.util.List;
009:        import java.util.Set;
010:        import java.util.concurrent.CopyOnWriteArraySet;
011:
012:        import net.refractions.udig.project.AdaptableFeature;
013:        import net.refractions.udig.project.EditManagerEvent;
014:        import net.refractions.udig.project.IEditManagerListener;
015:        import net.refractions.udig.project.ILayer;
016:        import net.refractions.udig.project.IMap;
017:        import net.refractions.udig.project.internal.EditManager;
018:        import net.refractions.udig.project.internal.Layer;
019:        import net.refractions.udig.project.internal.Map;
020:        import net.refractions.udig.project.internal.ProjectPackage;
021:        import net.refractions.udig.project.internal.ProjectPlugin;
022:        import net.refractions.udig.ui.ProgressManager;
023:
024:        import org.eclipse.core.runtime.IAdaptable;
025:        import org.eclipse.emf.common.notify.Adapter;
026:        import org.eclipse.emf.common.notify.Notification;
027:        import org.eclipse.emf.common.notify.NotificationChain;
028:        import org.eclipse.emf.common.notify.impl.AdapterImpl;
029:        import org.eclipse.emf.ecore.EClass;
030:        import org.eclipse.emf.ecore.EObject;
031:        import org.eclipse.emf.ecore.EStructuralFeature;
032:        import org.eclipse.emf.ecore.InternalEObject;
033:        import org.eclipse.emf.ecore.impl.ENotificationImpl;
034:        import org.eclipse.emf.ecore.impl.EObjectImpl;
035:        import org.eclipse.emf.ecore.util.EcoreUtil;
036:        import org.geotools.data.FeatureEvent;
037:        import org.geotools.data.FeatureSource;
038:        import org.geotools.data.FeatureStore;
039:        import org.geotools.data.Transaction;
040:        import org.geotools.feature.Feature;
041:        import org.geotools.feature.FeatureCollection;
042:        import org.geotools.feature.FeatureIterator;
043:        import org.geotools.filter.Filter;
044:        import org.geotools.filter.FilterFactoryFinder;
045:
046:        import com.vividsolutions.jts.geom.Envelope;
047:
048:        /**
049:         * The default implementation of the EditManager interface.
050:         * 
051:         * @author Jesse
052:         * @since 1.0.0
053:         * @generated
054:         */
055:        public class EditManagerImpl extends EObjectImpl implements  EditManager {
056:
057:            /**
058:             * <!-- begin-user-doc --> <!-- end-user-doc -->
059:             * @generated
060:             */
061:            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$
062:
063:            /**
064:             * The default value of the '{@link #getEditFeature() <em>Edit Feature</em>}' attribute. <!--
065:             * begin-user-doc --> <!-- end-user-doc -->
066:             * 
067:             * @see #getEditFeature()
068:             * @generated
069:             * @ordered
070:             */
071:            protected static final Feature EDIT_FEATURE_EDEFAULT = null;
072:
073:            /**
074:             * The cached value of the '{@link #getEditFeature() <em>Edit Feature</em>}' attribute. <!--
075:             * begin-user-doc --> <!-- end-user-doc -->
076:             * 
077:             * @see #getEditFeature()
078:             * @generated
079:             * @ordered
080:             */
081:            protected Feature editFeature = EDIT_FEATURE_EDEFAULT;
082:
083:            /**
084:             * The cached value of the '{@link #getEditLayerInternal() <em>Edit Layer Internal</em>}' reference.
085:             * <!-- begin-user-doc --> <!-- end-user-doc -->
086:             * @see #getEditLayerInternal()
087:             * @generated
088:             * @ordered
089:             */
090:            protected Layer editLayerInternal = null;
091:
092:            /**
093:             * The default value of the '{@link #getTransactionType() <em>Transaction Type</em>}' attribute.
094:             * <!-- begin-user-doc --> <!-- end-user-doc -->
095:             * @see #getTransactionType()
096:             * @generated
097:             * @ordered
098:             */
099:            protected static final Class TRANSACTION_TYPE_EDEFAULT = null;
100:
101:            /**
102:             * The default value of the '{@link #isEditLayerLocked() <em>Edit Layer Locked</em>}' attribute.
103:             * <!-- begin-user-doc --> <!-- end-user-doc -->
104:             * @see #isEditLayerLocked()
105:             * @generated
106:             * @ordered
107:             */
108:            protected static final boolean EDIT_LAYER_LOCKED_EDEFAULT = false;
109:
110:            final UDIGTransaction transaction = new UDIGTransaction();
111:
112:            /**
113:             * <!-- begin-user-doc --> <!-- end-user-doc -->
114:             * 
115:             * @generated NOT
116:             */
117:            @SuppressWarnings("unchecked")
118:            protected EditManagerImpl() {
119:                super ();
120:                eAdapters().add(eventCreator);
121:            }
122:
123:            /**
124:             * <!-- begin-user-doc --> <!-- end-user-doc -->
125:             * @generated
126:             */
127:            protected EClass eStaticClass() {
128:                return ProjectPackage.eINSTANCE.getEditManager();
129:            }
130:
131:            /**
132:             * <!-- begin-user-doc --> <!-- end-user-doc -->
133:             * @generated
134:             */
135:            public Map getMapInternal() {
136:                if (eContainerFeatureID != ProjectPackage.EDIT_MANAGER__MAP_INTERNAL)
137:                    return null;
138:                return (Map) eContainer;
139:            }
140:
141:            /**
142:             * <!-- begin-user-doc --> <!-- end-user-doc -->
143:             * @generated
144:             */
145:            public void setMapInternal(Map newMapInternal) {
146:                if (newMapInternal != eContainer
147:                        || (eContainerFeatureID != ProjectPackage.EDIT_MANAGER__MAP_INTERNAL && newMapInternal != null)) {
148:                    if (EcoreUtil.isAncestor(this , (EObject) newMapInternal))
149:                        throw new IllegalArgumentException(
150:                                "Recursive containment not allowed for " + toString()); //$NON-NLS-1$
151:                    NotificationChain msgs = null;
152:                    if (eContainer != null)
153:                        msgs = eBasicRemoveFromContainer(msgs);
154:                    if (newMapInternal != null)
155:                        msgs = ((InternalEObject) newMapInternal).eInverseAdd(
156:                                this ,
157:                                ProjectPackage.MAP__EDIT_MANAGER_INTERNAL,
158:                                Map.class, msgs);
159:                    msgs = eBasicSetContainer((InternalEObject) newMapInternal,
160:                            ProjectPackage.EDIT_MANAGER__MAP_INTERNAL, msgs);
161:                    if (msgs != null)
162:                        msgs.dispatch();
163:                } else if (eNotificationRequired())
164:                    eNotify(new ENotificationImpl(this , Notification.SET,
165:                            ProjectPackage.EDIT_MANAGER__MAP_INTERNAL,
166:                            newMapInternal, newMapInternal));
167:            }
168:
169:            /**
170:             * <!-- begin-user-doc --> <!-- end-user-doc -->
171:             * @generated
172:             */
173:            public Feature getEditFeature() {
174:                return editFeature;
175:            }
176:
177:            /**
178:             * <!-- begin-user-doc --> <!-- end-user-doc -->
179:             * @generated
180:             */
181:            public Layer getEditLayerInternal() {
182:                return editLayerInternal;
183:            }
184:
185:            /**
186:             * <!-- begin-user-doc --> <!-- end-user-doc -->
187:             * @generated
188:             */
189:            public Class getTransactionType() {
190:                // TODO: implement this method to return the 'Transaction Type' attribute
191:                // Ensure that you remove @generated or mark it @generated NOT
192:                throw new UnsupportedOperationException();
193:            }
194:
195:            /**
196:             * @see net.refractions.udig.project.internal.EditManager#getTransaction()
197:             * @uml.property name="transaction"
198:             */
199:            public Transaction getTransaction() {
200:                return transaction;
201:            }
202:
203:            /**
204:             * <!-- begin-user-doc --> <!-- end-user-doc -->
205:             * 
206:             * @generated NOT
207:             */
208:            public void setEditFeature(Feature feature, Layer layer) {
209:                if (layer == null && isEditLayerLocked()) {
210:                    layer = editLayerInternal;
211:                }
212:
213:                if (isEditLayerLocked()
214:                        && (layer != editLayerInternal && editLayerInternal != null))
215:                    throw new IllegalArgumentException(
216:                            "Edit Layer is locked so argument 'layer' should be not be changed."); //$NON-NLS-1$
217:
218:                Feature value = getAdaptableFeature(feature, layer);
219:                Feature oldFeature = editFeature;
220:                if (editFeature != null) {
221:                    editFeature = null;
222:                }
223:                if (value != null) {
224:                    editFeature = value;
225:                    this .editLayerInternal = layer;
226:                } else if (layer != null && !isEditLayerLocked()) {
227:                    this .editLayerInternal = layer;
228:                }
229:
230:                if (eNotificationRequired())
231:                    if (oldFeature == value)
232:                        return;
233:                eNotify(new ENotificationImpl(this , Notification.SET,
234:                        ProjectPackage.EDIT_MANAGER__EDIT_FEATURE, oldFeature,
235:                        value));
236:            }
237:
238:            /**
239:             * <!-- begin-user-doc --> <!-- end-user-doc -->
240:             * @generated
241:             */
242:            public void startTransaction() {
243:                // TODO: implement this method
244:                // Ensure that you remove @generated or mark it @generated NOT
245:                throw new UnsupportedOperationException();
246:            }
247:
248:            private Feature getAdaptableFeature(Feature feature, Layer layer) {
249:                if (feature == null || feature instanceof  IAdaptable)
250:                    return feature;
251:
252:                return (Feature) new AdaptableFeature(feature, layer);
253:            }
254:
255:            /**
256:             * <!-- begin-user-doc --> <!-- end-user-doc -->
257:             * 
258:             * @generated NOT
259:             */
260:            public void commitTransaction() throws IOException {
261:                // if (!isEditing() ) return; // check for edit events? May not arrive so lets do what the
262:                // user tells us
263:
264:                fireEvent(new EditManagerEvent(this ,
265:                        EditManagerEvent.PRE_COMMIT, null, null));
266:
267:                try {
268:                    transaction.commitInternal();
269:                    for (Layer layer : getMapInternal().getLayersInternal()) {
270:                        if (layer.getFeatureChanges().size() != 0)
271:                            layer.getFeatureChanges().clear();
272:                    }
273:                } catch (IOException e) {
274:                    e.printStackTrace();
275:                    FeatureIterator reader = null;
276:                    try {
277:                        FeatureSource source = editLayerInternal.getResource(
278:                                FeatureSource.class, null);
279:                        FeatureCollection results = source
280:                                .getFeatures(FilterFactoryFinder
281:                                        .createFilterFactory().createFidFilter(
282:                                                editFeature.getID()));
283:                        reader = results.features();
284:                        setEditFeature(reader.next(), editLayerInternal);
285:                    } catch (Exception e2) {
286:                        setEditFeature(null, null);
287:                    } finally {
288:                        if (reader != null) {
289:                            reader.close();
290:                        }
291:                    }
292:                    ProjectPlugin.getPlugin().log(e);
293:                } finally {
294:                    editComplete();
295:                }
296:
297:                fireEvent(new EditManagerEvent(this ,
298:                        EditManagerEvent.POST_COMMIT, null, null));
299:
300:            }
301:
302:            /**
303:             * Informs the feature store that editing has completed and the transaction should be reset.
304:             *
305:             * @see UDIGFeatureStore#editComplete()
306:             * @throws IOException
307:             */
308:            private void editComplete() throws IOException {
309:                for (Layer layer : getMapInternal().getLayersInternal()) {
310:                    FeatureStore resource = layer.getResource(
311:                            FeatureStore.class, ProgressManager.instance()
312:                                    .get());
313:                    if (resource != null
314:                            && resource instanceof  UDIGFeatureStore) {
315:                        ((UDIGFeatureStore) resource).editComplete();
316:                    }
317:                }
318:            }
319:
320:            // private void setTransaction() throws IOException {
321:            // Class<? extends Transaction> oldtransaction=null;
322:            // if( transaction!=null)
323:            // oldtransaction=transaction.getClass();
324:            //
325:            // for (Layer layer: getMapInternal().getLayersInternal()) {
326:            // FeatureStore fs = layer.getResource(FeatureStore.class, null);
327:            // if (fs != null)
328:            // fs.setTransaction(transaction);
329:            // if (layer.isDirty() && !isEditing())
330:            // layer.setDirty(false);
331:            // }
332:            //
333:            // eNotify(new ENotificationImpl(this, Notification.SET,
334:            // ProjectPackage.EDIT_MANAGER__TRANSACTION_TYPE, oldtransaction, transaction.getClass()));
335:            // }
336:
337:            /**
338:             * <!-- begin-user-doc --> <!-- end-user-doc -->
339:             * 
340:             * @throws IOException
341:             * @generated NOT
342:             */
343:            public void rollbackTransaction() throws IOException {
344:                fireEvent(new EditManagerEvent(this ,
345:                        EditManagerEvent.PRE_ROLLBACK, null, null));
346:                try {
347:                    HashMap<List<FeatureEvent>, FeatureEvent> modified = new HashMap<List<FeatureEvent>, FeatureEvent>();
348:                    synchronized (this ) {
349:
350:                        for (Layer layer : getMapInternal().getLayersInternal()) {
351:                            if (layer.getFeatureChanges().size() != 0) {
352:                                List<FeatureEvent> changes = layer
353:                                        .getFeatureChanges();
354:                                // create an event that notifies listeners that the area has changed again.
355:                                // calculate bounds of all the Changes to date.
356:                                // The reason for this is that otherwise I would have to make the entire
357:                                // viewport re-render on a rollback. This little hack is to
358:                                // get around that.
359:                                Envelope envelope = new Envelope();
360:                                for (FeatureEvent event : changes) {
361:                                    envelope.expandToInclude(event.getBounds());
362:                                }
363:                                FeatureSource source = layer.getResource(
364:                                        FeatureSource.class, null);
365:                                FeatureEvent event = new FeatureEvent(source,
366:                                        FeatureEvent.FEATURES_CHANGED, envelope);
367:
368:                                modified.put(changes, event);
369:                            }
370:                        }
371:                    }
372:                    if (selectedLayer != null)
373:                        selectedLayer.setFilter(Filter.ALL);
374:                    transaction.rollbackInternal();
375:
376:                    for (java.util.Map.Entry<List<FeatureEvent>, FeatureEvent> entry : modified
377:                            .entrySet()) {
378:                        entry.getKey().add(entry.getValue());
379:                        // now that the area has re-rendered (and whatever else) clear all the events so
380:                        // the layer is considered clean.
381:                        entry.getKey().clear();
382:
383:                    }
384:                } catch (IOException e) {
385:                    throw e;
386:                } finally {
387:                    editComplete();
388:                    setEditFeature(null, null);
389:                    fireEvent(new EditManagerEvent(this ,
390:                            EditManagerEvent.POST_ROLLBACK, null, null));
391:                }
392:            }
393:
394:            /**
395:             * <!-- begin-user-doc --> <!-- end-user-doc -->
396:             * @generated
397:             */
398:            public NotificationChain eInverseAdd(InternalEObject otherEnd,
399:                    int featureID, Class baseClass, NotificationChain msgs) {
400:                if (featureID >= 0) {
401:                    switch (eDerivedStructuralFeatureID(featureID, baseClass)) {
402:                    case ProjectPackage.EDIT_MANAGER__MAP_INTERNAL:
403:                        if (eContainer != null)
404:                            msgs = eBasicRemoveFromContainer(msgs);
405:                        return eBasicSetContainer(otherEnd,
406:                                ProjectPackage.EDIT_MANAGER__MAP_INTERNAL, msgs);
407:                    default:
408:                        return eDynamicInverseAdd(otherEnd, featureID,
409:                                baseClass, msgs);
410:                    }
411:                }
412:                if (eContainer != null)
413:                    msgs = eBasicRemoveFromContainer(msgs);
414:                return eBasicSetContainer(otherEnd, featureID, msgs);
415:            }
416:
417:            /**
418:             * <!-- begin-user-doc --> <!-- end-user-doc -->
419:             * @generated
420:             */
421:            public NotificationChain eInverseRemove(InternalEObject otherEnd,
422:                    int featureID, Class baseClass, NotificationChain msgs) {
423:                if (featureID >= 0) {
424:                    switch (eDerivedStructuralFeatureID(featureID, baseClass)) {
425:                    case ProjectPackage.EDIT_MANAGER__MAP_INTERNAL:
426:                        return eBasicSetContainer(null,
427:                                ProjectPackage.EDIT_MANAGER__MAP_INTERNAL, msgs);
428:                    default:
429:                        return eDynamicInverseRemove(otherEnd, featureID,
430:                                baseClass, msgs);
431:                    }
432:                }
433:                return eBasicSetContainer(null, featureID, msgs);
434:            }
435:
436:            /**
437:             * <!-- begin-user-doc --> <!-- end-user-doc -->
438:             * @generated
439:             */
440:            public NotificationChain eBasicRemoveFromContainer(
441:                    NotificationChain msgs) {
442:                if (eContainerFeatureID >= 0) {
443:                    switch (eContainerFeatureID) {
444:                    case ProjectPackage.EDIT_MANAGER__MAP_INTERNAL:
445:                        return eContainer.eInverseRemove(this ,
446:                                ProjectPackage.MAP__EDIT_MANAGER_INTERNAL,
447:                                Map.class, msgs);
448:                    default:
449:                        return eDynamicBasicRemoveFromContainer(msgs);
450:                    }
451:                }
452:                return eContainer.eInverseRemove(this , EOPPOSITE_FEATURE_BASE
453:                        - eContainerFeatureID, null, msgs);
454:            }
455:
456:            /**
457:             * <!-- begin-user-doc --> <!-- end-user-doc -->
458:             * @generated
459:             */
460:            public Object eGet(EStructuralFeature eFeature, boolean resolve) {
461:                switch (eDerivedStructuralFeatureID(eFeature)) {
462:                case ProjectPackage.EDIT_MANAGER__EDIT_FEATURE:
463:                    return getEditFeature();
464:                case ProjectPackage.EDIT_MANAGER__MAP_INTERNAL:
465:                    return getMapInternal();
466:                case ProjectPackage.EDIT_MANAGER__EDIT_LAYER_INTERNAL:
467:                    return getEditLayerInternal();
468:                case ProjectPackage.EDIT_MANAGER__TRANSACTION_TYPE:
469:                    return getTransactionType();
470:                case ProjectPackage.EDIT_MANAGER__EDIT_LAYER_LOCKED:
471:                    return isEditLayerLocked() ? Boolean.TRUE : Boolean.FALSE;
472:                case ProjectPackage.EDIT_MANAGER__SELECTED_LAYER:
473:                    if (resolve)
474:                        return getSelectedLayer();
475:                    return basicGetSelectedLayer();
476:                }
477:                return eDynamicGet(eFeature, resolve);
478:            }
479:
480:            /**
481:             * <!-- begin-user-doc --> <!-- end-user-doc -->
482:             * @generated
483:             */
484:            public void eSet(EStructuralFeature eFeature, Object newValue) {
485:                switch (eDerivedStructuralFeatureID(eFeature)) {
486:                case ProjectPackage.EDIT_MANAGER__MAP_INTERNAL:
487:                    setMapInternal((Map) newValue);
488:                    return;
489:                case ProjectPackage.EDIT_MANAGER__EDIT_LAYER_LOCKED:
490:                    setEditLayerLocked(((Boolean) newValue).booleanValue());
491:                    return;
492:                case ProjectPackage.EDIT_MANAGER__SELECTED_LAYER:
493:                    setSelectedLayer((Layer) newValue);
494:                    return;
495:                }
496:                eDynamicSet(eFeature, newValue);
497:            }
498:
499:            /**
500:             * <!-- begin-user-doc --> <!-- end-user-doc -->
501:             * @generated
502:             */
503:            public void eUnset(EStructuralFeature eFeature) {
504:                switch (eDerivedStructuralFeatureID(eFeature)) {
505:                case ProjectPackage.EDIT_MANAGER__MAP_INTERNAL:
506:                    setMapInternal((Map) null);
507:                    return;
508:                case ProjectPackage.EDIT_MANAGER__EDIT_LAYER_LOCKED:
509:                    setEditLayerLocked(EDIT_LAYER_LOCKED_EDEFAULT);
510:                    return;
511:                case ProjectPackage.EDIT_MANAGER__SELECTED_LAYER:
512:                    setSelectedLayer((Layer) null);
513:                    return;
514:                }
515:                eDynamicUnset(eFeature);
516:            }
517:
518:            /**
519:             * <!-- begin-user-doc --> <!-- end-user-doc -->
520:             * @generated
521:             */
522:            public boolean eIsSet(EStructuralFeature eFeature) {
523:                switch (eDerivedStructuralFeatureID(eFeature)) {
524:                case ProjectPackage.EDIT_MANAGER__EDIT_FEATURE:
525:                    return EDIT_FEATURE_EDEFAULT == null ? editFeature != null
526:                            : !EDIT_FEATURE_EDEFAULT.equals(editFeature);
527:                case ProjectPackage.EDIT_MANAGER__MAP_INTERNAL:
528:                    return getMapInternal() != null;
529:                case ProjectPackage.EDIT_MANAGER__EDIT_LAYER_INTERNAL:
530:                    return editLayerInternal != null;
531:                case ProjectPackage.EDIT_MANAGER__TRANSACTION_TYPE:
532:                    return TRANSACTION_TYPE_EDEFAULT == null ? getTransactionType() != null
533:                            : !TRANSACTION_TYPE_EDEFAULT
534:                                    .equals(getTransactionType());
535:                case ProjectPackage.EDIT_MANAGER__EDIT_LAYER_LOCKED:
536:                    return editLayerLocked != EDIT_LAYER_LOCKED_EDEFAULT;
537:                case ProjectPackage.EDIT_MANAGER__SELECTED_LAYER:
538:                    return selectedLayer != null;
539:                }
540:                return eDynamicIsSet(eFeature);
541:            }
542:
543:            /**
544:             * <!-- begin-user-doc --> <!-- end-user-doc -->
545:             * @generated
546:             */
547:            public String toString() {
548:                if (eIsProxy())
549:                    return super .toString();
550:
551:                StringBuffer result = new StringBuffer(super .toString());
552:                result.append(" (editFeature: "); //$NON-NLS-1$
553:                result.append(editFeature);
554:                result.append(", editLayerLocked: "); //$NON-NLS-1$
555:                result.append(editLayerLocked);
556:                result.append(')');
557:                return result.toString();
558:            }
559:
560:            /**
561:             * @throws IOException
562:             */
563:            public void addFeature(final Feature feature, Layer layer)
564:                    throws IOException {
565:
566:                Feature adaptableFeature = feature;
567:                if (!(feature instanceof  IAdaptable)) {
568:                    adaptableFeature = new AdaptableFeature(feature, layer);
569:
570:                }
571:                final Feature finalFeature = adaptableFeature;
572:                // setEditFeature(feature, layer);
573:                FeatureStore store = layer
574:                        .getResource(FeatureStore.class, null);
575:                FeatureCollection c = new org.geotools.feature.collection.AbstractFeatureCollection(
576:                        store.getSchema()) {
577:
578:                    @Override
579:                    public int size() {
580:                        return 1;
581:                    }
582:
583:                    @Override
584:                    protected Iterator openIterator() {
585:                        return new Iterator() {
586:
587:                            boolean more = true;
588:
589:                            public boolean hasNext() {
590:                                return more;
591:                            }
592:
593:                            public Object next() {
594:                                more = false;
595:                                return finalFeature;
596:                            }
597:
598:                            public void remove() {
599:                                throw new UnsupportedOperationException();
600:                            }
601:
602:                        };
603:                    }
604:
605:                    @Override
606:                    protected void closeIterator(Iterator close) {
607:                    }
608:
609:                };
610:                store.addFeatures(c);
611:            }
612:
613:            /**
614:             * @see net.refractions.udig.project.internal.EditManager#refreshEditFeature()
615:             */
616:            public void refreshEditFeature() {
617:                try {
618:                    FeatureIterator editFeatureReader = getEditLayerInternal()
619:                            .getResource(FeatureStore.class, null).getFeatures(
620:                                    FilterFactoryFinder.createFilterFactory()
621:                                            .createFidFilter(
622:                                                    getEditFeature().getID()))
623:                            .features();
624:                    setEditFeature(editFeatureReader.next(),
625:                            getEditLayerInternal());
626:                } catch (Exception e) {
627:                    ProjectPlugin.log(null, e);
628:                    setEditFeature(null, getEditLayerInternal());
629:                }
630:
631:            }
632:
633:            /**
634:             * Returns the currently selected Layer
635:             * 
636:             * @return the currently selected Layer
637:             */
638:            public Layer getSelectedLayer() {
639:                if (selectedLayer != null
640:                        && !getMap().getMapLayers().contains(selectedLayer)) {
641:                    selectedLayer = null;
642:                }
643:                if (selectedLayer == null) {
644:                    List<Layer> layers = getMapInternal().getLayersInternal();
645:                    if (layers.size() != 0)
646:                        selectedLayer = layers.get(layers.size() - 1);
647:                }
648:
649:                return selectedLayer;
650:            }
651:
652:            /**
653:             * <!-- begin-user-doc -->
654:             * <!-- end-user-doc -->
655:             * @generated
656:             */
657:            public Layer basicGetSelectedLayer() {
658:                return selectedLayer;
659:            }
660:
661:            /**
662:             * Sets the currently selected Layer
663:             * 
664:             * @uml.property name="selectedLayer"
665:             */
666:            public void setSelectedLayer(Layer selectedLayer) {
667:                if (!getMapInternal().getLayersInternal().contains(
668:                        selectedLayer)
669:                        || selectedLayer == this .selectedLayer)
670:                    return;
671:                setSelectedLayerGen(selectedLayer);
672:            }
673:
674:            /**
675:             * @generated
676:             */
677:            public void setSelectedLayerGen(Layer newSelectedLayer) {
678:                Layer oldSelectedLayer = selectedLayer;
679:                selectedLayer = newSelectedLayer;
680:                if (eNotificationRequired())
681:                    eNotify(new ENotificationImpl(this , Notification.SET,
682:                            ProjectPackage.EDIT_MANAGER__SELECTED_LAYER,
683:                            oldSelectedLayer, selectedLayer));
684:            }
685:
686:            /**
687:             * @see net.refractions.udig.project.IEditManager#getMap()
688:             */
689:            public IMap getMap() {
690:                return getMapInternal();
691:            }
692:
693:            /**
694:             * @see net.refractions.udig.project.IEditManager#getEditLayer()
695:             */
696:            public ILayer getEditLayer() {
697:                return getEditLayerInternal();
698:            }
699:
700:            public boolean isEditing() {
701:                for (Layer layer : getMapInternal().getLayersInternal()) {
702:                    if (layer.getFeatureChanges().size() != 0) {
703:                        return true;
704:                    }
705:                }
706:                return false;
707:            }
708:
709:            // Support for normal java style events.
710:            Adapter eventCreator = new AdapterImpl() {
711:                public void notifyChanged(Notification msg) {
712:                    switch (msg.getFeatureID(EditManager.class)) {
713:                    case ProjectPackage.EDIT_MANAGER__EDIT_FEATURE:
714:                        fireEvent(new EditManagerEvent(EditManagerImpl.this ,
715:                                EditManagerEvent.EDIT_FEATURE, msg
716:                                        .getNewValue(), msg.getOldValue()));
717:                        break;
718:                    case ProjectPackage.EDIT_MANAGER__EDIT_LAYER_INTERNAL:
719:                        fireEvent(new EditManagerEvent(EditManagerImpl.this ,
720:                                EditManagerEvent.EDIT_LAYER, msg.getNewValue(),
721:                                msg.getOldValue()));
722:                        break;
723:                    case ProjectPackage.EDIT_MANAGER__SELECTED_LAYER:
724:                        fireEvent(new EditManagerEvent(EditManagerImpl.this ,
725:                                EditManagerEvent.SELECTED_LAYER, msg
726:                                        .getNewValue(), msg.getOldValue()));
727:                        break;
728:                    default:
729:                        break;
730:                    }
731:                }
732:            };
733:
734:            Set<IEditManagerListener> listeners = new CopyOnWriteArraySet<IEditManagerListener>();
735:
736:            private boolean editLayerLocked = false;
737:            Layer selectedLayer;
738:
739:            public void addListener(IEditManagerListener listener) {
740:                listeners.add(listener);
741:            }
742:
743:            public boolean containsListener(IEditManagerListener listener) {
744:                return listeners.contains(listener);
745:            }
746:
747:            public void removeListener(IEditManagerListener listener) {
748:                listeners.remove(listener);
749:            }
750:
751:            void fireEvent(EditManagerEvent event) {
752:                listeners.remove(null);
753:                for (IEditManagerListener object : listeners) {
754:                    try {
755:                        if (object != null)
756:                            object.changed(event);
757:                    } catch (Throwable e) {
758:                        ProjectPlugin
759:                                .log(
760:                                        "Error while notifying listener of event: " + event.getType(), e); //$NON-NLS-1$
761:                    }
762:                }
763:            }
764:
765:            /**
766:             * @return Returns the editLayerLocked.
767:             * @uml.property name="editLayerLocked"
768:             */
769:            public boolean isEditLayerLocked() {
770:                return editLayerLocked;
771:            }
772:
773:            /**
774:             * <!-- begin-user-doc --> <!-- end-user-doc -->
775:             * @generated
776:             */
777:            public void setEditLayerLocked(boolean newEditLayerLocked) {
778:                boolean oldEditLayerLocked = editLayerLocked;
779:                editLayerLocked = newEditLayerLocked;
780:                if (eNotificationRequired())
781:                    eNotify(new ENotificationImpl(this , Notification.SET,
782:                            ProjectPackage.EDIT_MANAGER__EDIT_LAYER_LOCKED,
783:                            oldEditLayerLocked, editLayerLocked));
784:            }
785:
786:        } // LayerManagerImpl
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.