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


001:        package org.tcat.citd.sim.udig.bookmarks.internal;
002:
003:        import java.util.Collection;
004:        import java.util.HashMap;
005:
006:        import net.refractions.udig.project.IMap;
007:        import net.refractions.udig.project.ui.ApplicationGIS;
008:        import net.refractions.udig.project.ui.internal.MapEditor;
009:        import net.refractions.udig.ui.PlatformGIS;
010:
011:        import org.eclipse.jface.viewers.IStructuredContentProvider;
012:        import org.eclipse.jface.viewers.ITreeContentProvider;
013:        import org.eclipse.jface.viewers.TreeViewer;
014:        import org.eclipse.jface.viewers.Viewer;
015:        import org.eclipse.swt.widgets.Display;
016:        import org.eclipse.ui.IPartListener;
017:        import org.eclipse.ui.IWorkbenchPart;
018:        import org.eclipse.ui.PlatformUI;
019:        import org.tcat.citd.sim.udig.bookmarks.Bookmark;
020:        import org.tcat.citd.sim.udig.bookmarks.BookmarkManager;
021:        import org.tcat.citd.sim.udig.bookmarks.BookmarksPlugin;
022:        import org.tcat.citd.sim.udig.bookmarks.internal.ui.BookmarksView;
023:
024:        /**
025:         * The content provider class is responsible for providing objects to the view. It can wrap existing
026:         * objects in adapters or simply return objects as-is. These objects may be sensitive to the current
027:         * input of the view, or ignore it and always show the same content (like Task List, for example).
028:         * 
029:         * @author cole.markham
030:         * @since 1.0.0
031:         */
032:        public class BookmarksContentProvider implements 
033:                IStructuredContentProvider, ITreeContentProvider, IPartListener {
034:            private HashMap<Viewer, Object> viewers;
035:
036:            private IWorkbenchPart currentPart;
037:
038:            private BookmarkManager bManager;
039:
040:            private MapReference currentMap;
041:
042:            /**
043:             * Default constructor
044:             */
045:            public BookmarksContentProvider() {
046:                viewers = new HashMap<Viewer, Object>();
047:                bManager = BookmarksPlugin.getDefault().getBookmarkManager();
048:                currentPart = null;
049:                currentMap = null;
050:            }
051:
052:            public void inputChanged(Viewer viewer, Object oldInput,
053:                    Object newInput) {
054:                if (newInput == null)
055:                    viewers.remove(viewer);
056:                else
057:                    viewers.put(viewer, newInput);
058:            }
059:
060:            /**
061:             * returns current mapping of registered viewers and input objects Usually this involves a Viewe
062:             * object
063:             * 
064:             * @return a map of the viewers to input objects
065:             */
066:            protected HashMap getViewers() {
067:                return viewers;
068:            }
069:
070:            public void dispose() {
071:                PlatformUI.getWorkbench().getActiveWorkbenchWindow()
072:                        .getPartService().removePartListener(this );
073:                viewers.clear();
074:                bManager = null;
075:            }
076:
077:            /**
078:             * Get the root element -- a single IMap object corresonding to the current map
079:             * 
080:             * @return array of Objects
081:             */
082:            public Object[] getElements(Object parent) {
083:                Object[] elements = new Object[1];
084:                if (currentMap == null) {
085:                    elements[0] = Messages.BookmarksContentProvider_emptybookmarkslist;
086:                } else {
087:                    elements[0] = currentMap;
088:                }
089:                return elements;
090:            }
091:
092:            public Object[] getChildren(Object parentElement) {
093:                Object[] children = null;
094:                if (parentElement instanceof  MapReference) {
095:                    MapReference map = (MapReference) parentElement;
096:                    children = bManager.getBookmarks(map).toArray();
097:                }
098:                return children;
099:            }
100:
101:            public Object getParent(Object element) {
102:                Object parent = null;
103:                if (element instanceof  Bookmark) {
104:                    Bookmark bookmark = (Bookmark) element;
105:                    parent = bookmark.getMap();
106:                }
107:                return parent;
108:            }
109:
110:            public boolean hasChildren(Object element) {
111:                boolean hasChildren = false;
112:                if (element instanceof  MapReference) {
113:                    hasChildren = true;
114:                }
115:                return hasChildren;
116:            }
117:
118:            /**
119:             * refreshes the given viewer in the UI thread
120:             * 
121:             * @param asynch set to true for asynchronous refresh, false for synchronous
122:             * @param v viewer to refresh
123:             */
124:            public void refresh(final Viewer v, boolean asynch) {
125:                if (v.getControl().isDisposed())
126:                    return;
127:                Display display = v.getControl().getDisplay();
128:                if (display != null && !display.isDisposed()) {
129:                    Runnable r = new Runnable() {
130:                        public void run() {
131:                            if (v != null && !v.getControl().isDisposed()) {
132:                                v.refresh();
133:                                if (v instanceof  TreeViewer) {
134:                                    ((TreeViewer) v).expandToLevel(currentMap,
135:                                            1);
136:                                }
137:                            }
138:                        }
139:                    };
140:                    if (asynch)
141:                        display.asyncExec(r);
142:                    else
143:                        PlatformGIS.syncInDisplayThread(r);
144:                }
145:            }
146:
147:            /**
148:             * refreshes the given collection of viewers in the UI thread
149:             * 
150:             * @param c
151:             * @param asynch set to true for asynchronous refresh, false for synchronous
152:             */
153:            public void refresh(final Collection<Viewer> c, boolean asynch) {
154:                for (Viewer v : c) {
155:                    refresh(v, asynch);
156:                }
157:            }
158:
159:            /**
160:             * @return Returns the currentMap.
161:             */
162:            public MapReference getCurrentMap() {
163:                return currentMap;
164:            }
165:
166:            /**
167:             * @param currentMap The currentMap to set.
168:             */
169:            public void setCurrentMap(MapReference currentMap) {
170:                this .currentMap = currentMap;
171:            }
172:
173:            public void partActivated(IWorkbenchPart part) {
174:                if (part == currentPart)
175:                    return;
176:                if (part instanceof  MapEditor) {
177:                    currentPart = part;
178:                    IMap map = ((MapEditor) part).getMap();
179:                    MapReference ref = bManager.getMapReference(map);
180:                    setCurrentMap(ref);
181:                    refresh(viewers.keySet(), true);
182:                } else if (part instanceof  BookmarksView) {
183:                    currentPart = part;
184:                    IMap map = ApplicationGIS.getActiveMap();
185:                    if (map != null) {
186:                        setCurrentMap(bManager.getMapReference(map));
187:                    } else
188:                        setCurrentMap(null);
189:                    refresh(viewers.keySet(), true);
190:                }
191:            }
192:
193:            public void partBroughtToTop(IWorkbenchPart part) {
194:                // nothing to do
195:            }
196:
197:            public void partClosed(IWorkbenchPart part) {
198:                if (part == this ) {
199:                    dispose();
200:                    return;
201:                }
202:                if (part != currentPart)
203:                    return;
204:                currentPart = null;
205:                if (part instanceof  MapEditor) {
206:                    setCurrentMap(null);
207:                }
208:                refresh(viewers.keySet(), true);
209:            }
210:
211:            public void partDeactivated(IWorkbenchPart part) {
212:                // nothing to do
213:            }
214:
215:            public void partOpened(IWorkbenchPart part) {
216:                // nothing to do
217:            }
218:        }
ww_w_.___j__a___v___a__2___s_.__co_m___ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.