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


001:        /*
002:         * uDig - User Friendly Desktop Internet GIS client http://udig.refractions.net (C) 2004,
003:         * Refractions Research Inc. This library is free software; you can redistribute it and/or modify it
004:         * under the terms of the GNU Lesser General Public License as published by the Free Software
005:         * Foundation; version 2.1 of the License. This library is distributed in the hope that it will be
006:         * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
007:         * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
008:         */
009:        package net.refractions.udig.project.internal.commands;
010:
011:        import java.text.MessageFormat;
012:        import java.util.Collection;
013:        import java.util.Collections;
014:        import java.util.List;
015:
016:        import net.refractions.udig.project.ILayer;
017:        import net.refractions.udig.project.command.AbstractCommand;
018:        import net.refractions.udig.project.command.UndoableMapCommand;
019:        import net.refractions.udig.project.internal.EditManager;
020:        import net.refractions.udig.project.internal.Layer;
021:        import net.refractions.udig.project.internal.Map;
022:        import net.refractions.udig.project.internal.Messages;
023:
024:        import org.eclipse.core.runtime.IProgressMonitor;
025:
026:        /**
027:         * Deletes a layer.
028:         * 
029:         * @author Jesse
030:         * @since 1.0.0
031:         */
032:        public class DeleteLayerCommand extends AbstractCommand implements 
033:                UndoableMapCommand {
034:
035:            private Layer layer;
036:
037:            private int index;
038:
039:            private Map map;
040:
041:            private boolean wasSelected;
042:
043:            /**
044:             * Construct <code>DeleteLayerCommand</code>.
045:             * 
046:             * @param map
047:             */
048:            public DeleteLayerCommand(Layer layer) {
049:                this .map = layer.getMapInternal();
050:                this .layer = layer;
051:            }
052:
053:            /**
054:             * @see net.refractions.udig.project.command.UndoableCommand#rollback()
055:             */
056:            public void rollback(IProgressMonitor monitor) throws Exception {
057:                if (layer == null)
058:                    return;
059:                map.getLayersInternal().add(index, layer);
060:                if (wasSelected)
061:                    map.getEditManagerInternal().setSelectedLayer(layer);
062:            }
063:
064:            /**
065:             * @see net.refractions.udig.project.command.MapCommand#run()
066:             */
067:            public void run(IProgressMonitor monitor) throws Exception {
068:                if (!map.getLayersInternal().contains(layer)) {
069:                    layer = null;
070:                    return;
071:                }
072:                List<Layer> layers = map.getLayersInternal();
073:                index = layers.indexOf(layer);
074:                wasSelected = selectNewLayer(map, Collections.singleton(layer));
075:                layers.remove(layer);
076:                map.getColourScheme().removeItem(layer.getID().toString(),
077:                        layer.getDefaultColor()); //remove from scheme
078:            }
079:
080:            /**
081:             * Selects a new layer if the selected layer is being removed.  The algorithm will try to select the bottom layer above the
082:             * selected layer or if not possible then the top layer below (that isn't being removed).
083:             *
084:             * @param layers Layers in map
085:             * @param toRemove layers being removed
086:             * @param indexOfSelectedLayer
087:             * @return true if the selected layer has been changed
088:             */
089:            static boolean selectNewLayer(Map map,
090:                    Collection<? extends ILayer> toRemove) {
091:                EditManager editManager = map.getEditManagerInternal();
092:                List<Layer> layers = map.getLayersInternal();
093:                Layer selectedLayer = editManager.getSelectedLayer();
094:                if (!toRemove.contains(selectedLayer))
095:                    // nothing to be done since it is not going to be removed
096:                    return false;
097:
098:                // try to select bottom layer above the selected layer that is not being deleted.  If
099:                // not possible then select top layer below the selected layer
100:                for (int i = layers.indexOf(selectedLayer) + 1; i < layers
101:                        .size(); i++) {
102:                    Layer layer = layers.get(i);
103:                    if (!toRemove.contains(layer)) {
104:                        editManager.setSelectedLayer(layer);
105:                        return true;
106:                    }
107:                }
108:                for (int i = layers.indexOf(selectedLayer) - 1; i >= 0; i--) {
109:                    Layer layer = layers.get(i);
110:                    if (!toRemove.contains(layer)) {
111:                        editManager.setSelectedLayer(layer);
112:                        return true;
113:                    }
114:                }
115:
116:                editManager.setSelectedLayer(null);
117:                return true;
118:            }
119:
120:            /**
121:             * @see net.refractions.udig.project.command.MapCommand#getName()
122:             */
123:            public String getName() {
124:                return MessageFormat.format(
125:                        Messages.DeleteLayerCommand_deleteLayer,
126:                        new Object[] { layer.getName() });
127:            }
128:
129:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.