Source Code Cross Referenced for BookmarkManager.java in  » GIS » udig-1.1 » org » tcat » citd » sim » udig » bookmarks » 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 » org.tcat.citd.sim.udig.bookmarks 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.tcat.citd.sim.udig.bookmarks;
002:
003:        import java.util.Collection;
004:        import java.util.HashMap;
005:        import java.util.Vector;
006:
007:        import net.refractions.udig.project.IMap;
008:        import net.refractions.udig.project.internal.Project;
009:
010:        import org.eclipse.emf.common.util.URI;
011:        import org.tcat.citd.sim.udig.bookmarks.internal.MapReference;
012:        import org.tcat.citd.sim.udig.bookmarks.internal.Messages;
013:
014:        /**
015:         * This class provides a bookmark repository and associated management functions.
016:         * <p>
017:         * </p>
018:         * 
019:         * @author cole.markham
020:         * @since 1.0.0
021:         */
022:        public class BookmarkManager {
023:            private HashMap<URI, Vector<MapReference>> projectsHash;
024:            private HashMap<URI, Vector<Bookmark>> mapsHash;
025:            private HashMap<URI, MapReference> mapReferences;
026:            private int count = 0;
027:
028:            /**
029:             * 
030:             */
031:            public BookmarkManager() {
032:                projectsHash = new HashMap<URI, Vector<MapReference>>();
033:                mapsHash = new HashMap<URI, Vector<Bookmark>>();
034:                mapReferences = new HashMap<URI, MapReference>();
035:            }
036:
037:            /**
038:             * Add the given bookmark.
039:             * 
040:             * @param bookmark
041:             */
042:            public void addBookmark(Bookmark bookmark) {
043:                if (bookmark.getName() == null || bookmark.getName() == "") { //$NON-NLS-1$
044:                    bookmark
045:                            .setName(Messages.BookmarkManager_bookmarkdefaultname
046:                                    + (++count));
047:                }
048:                MapReference map = bookmark.getMap();
049:                URI project = map.getProjectID();
050:                if (!projectsHash.containsKey(project)) {
051:                    Vector<MapReference> projectMaps = new Vector<MapReference>();
052:                    projectMaps.add(map);
053:                    projectsHash.put(project, projectMaps);
054:                } else {
055:                    Vector<MapReference> projectMaps = projectsHash
056:                            .get(project);
057:                    if (!projectMaps.contains(map)) {
058:                        projectMaps.add(map);
059:                    }
060:                }
061:                if (!mapsHash.containsKey(map.getMapID())) {
062:                    Vector<Bookmark> bookmarks = new Vector<Bookmark>();
063:                    bookmarks.add(bookmark);
064:                    mapsHash.put(map.getMapID(), bookmarks);
065:                } else {
066:                    Vector<Bookmark> bmarks = mapsHash.get(map.getMapID());
067:                    if (!bmarks.contains(bookmark)) {
068:                        bmarks.add(bookmark);
069:                    }
070:                }
071:            }
072:
073:            /**
074:             * Empties the list of bookmarks
075:             */
076:            public void empty() {
077:                projectsHash.clear();
078:                mapsHash.clear();
079:            }
080:
081:            /**
082:             * Returns whether the list is empty
083:             * 
084:             * @return whether this list is empty
085:             */
086:            public boolean isEmpty() {
087:                boolean isEmpty = mapsHash.isEmpty();
088:                return isEmpty;
089:            }
090:
091:            /**
092:             * Returns the list of projects as an array of objects
093:             * 
094:             * @return array of IProject objects
095:             */
096:            public Collection<URI> getProjects() {
097:                Vector<URI> projects = new Vector<URI>(this .projectsHash
098:                        .keySet());
099:                return projects;
100:            }
101:
102:            /**
103:             * Returns the list of maps which are contained in the specified project
104:             * 
105:             * @param project The project for which the maps will be returned
106:             * @return array of MapReference objects
107:             */
108:            public Collection<MapReference> getMaps(URI project) {
109:                Vector<MapReference> maps = projectsHash.get(project);
110:                return maps;
111:            }
112:
113:            /**
114:             * Return the list of bookmarks associated with the specified map
115:             * 
116:             * @param map The map for which the bookmarks will be returned
117:             * @return A vector of Bookmark objects
118:             */
119:            public Collection<Bookmark> getBookmarks(MapReference map) {
120:                if (!mapsHash.containsKey(map.getMapID())) {
121:                    mapsHash.put(map.getMapID(), new Vector<Bookmark>());
122:                }
123:                Vector<Bookmark> bookmarks = mapsHash.get(map.getMapID());
124:                return bookmarks;
125:            }
126:
127:            /**
128:             * Get the name of this bookmark manager for display It's just a static string for now
129:             * 
130:             * @return the name
131:             */
132:            public String getName() {
133:                return Messages.BookmarkManager_name_bookmarkmanager;
134:            }
135:
136:            @Override
137:            public String toString() {
138:                return this .getName();
139:            }
140:
141:            /**
142:             * Remove the given bookmark.
143:             * 
144:             * @param bookmark
145:             */
146:            public void removeBookmark(Bookmark bookmark) {
147:                MapReference map = bookmark.getMap();
148:                mapsHash.get(map.getMapID()).remove(bookmark);
149:                if (mapsHash.get(map.getMapID()).isEmpty()) {
150:                    URI projectID = map.getProjectID();
151:                    mapsHash.remove(map.getMapID());
152:                    projectsHash.get(projectID).remove(map);
153:                    if (projectsHash.get(projectID).isEmpty()) {
154:                        projectsHash.remove(projectID);
155:                    }
156:                }
157:            }
158:
159:            /**
160:             * Remove all of the bookmarks in the given list.
161:             * 
162:             * @param elements
163:             */
164:            public void removeBookmarks(Collection elements) {
165:                for (Object element : elements) {
166:                    if (element instanceof  Bookmark) {
167:                        Bookmark bmark = (Bookmark) element;
168:                        this .removeBookmark(bmark);
169:                    }
170:                }
171:            }
172:
173:            /**
174:             * Remove the map and all it's associated bookmarks
175:             * 
176:             * @param map
177:             */
178:            public void removeMap(MapReference map) {
179:                mapsHash.remove(map.getMapID());
180:                URI projectID = map.getProjectID();
181:                Vector<MapReference> maps = projectsHash.get(projectID);
182:                if (maps != null && maps.size() > 0) {
183:                    maps.remove(map);
184:                    if (maps.isEmpty()) {
185:                        projectsHash.remove(projectID);
186:                    }
187:                }
188:            }
189:
190:            /**
191:             * Remove all of the maps in the given list and their associated bookmarks.
192:             * 
193:             * @param elements
194:             */
195:            public void removeMaps(Collection elements) {
196:                for (Object element : elements) {
197:                    if (element instanceof  MapReference) {
198:                        MapReference map = (MapReference) element;
199:                        this .removeMap(map);
200:                    }
201:                }
202:            }
203:
204:            /**
205:             * Remove the project and all it's associated maps and bookmarks
206:             * 
207:             * @param project
208:             */
209:            public void removeProject(URI project) {
210:                Vector<MapReference> maps = projectsHash.get(project);
211:                projectsHash.remove(project);
212:                for (MapReference map : maps) {
213:                    maps.remove(map);
214:                }
215:            }
216:
217:            /**
218:             * Remove all of the projects in the given list and their associated maps and bookmarks.
219:             * 
220:             * @param elements
221:             */
222:            public void removeProjects(Collection elements) {
223:                for (Object element : elements) {
224:                    if (element instanceof  URI) {
225:                        URI project = (URI) element;
226:                        this .removeProject(project);
227:                    }
228:                }
229:            }
230:
231:            /**
232:             * @param map
233:             * @return the MapReference singleton for the given IMap
234:             */
235:            public MapReference getMapReference(IMap map) {
236:                MapReference ref = null;
237:                if (!mapReferences.containsKey(map.getID())) {
238:                    // HACK: fix this when IProject has a getID() method
239:                    Project project = (Project) map.getProject();
240:                    URI projectURI = project.eResource().getURI();
241:                    ref = new MapReference(map.getID(), projectURI, map
242:                            .getName());
243:                    mapReferences.put(map.getID(), ref);
244:                } else {
245:                    ref = mapReferences.get(map.getID());
246:                }
247:                return ref;
248:            }
249:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.