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


001:        package org.tcat.citd.sim.udig.bookmarks.internal.actions;
002:
003:        import java.util.Collection;
004:        import java.util.List;
005:
006:        import net.refractions.udig.project.IMap;
007:        import net.refractions.udig.project.command.MapCommand;
008:        import net.refractions.udig.project.render.IViewportModel;
009:        import net.refractions.udig.project.ui.ApplicationGIS;
010:
011:        import org.eclipse.jface.action.Action;
012:        import org.eclipse.jface.action.IAction;
013:        import org.eclipse.jface.dialogs.InputDialog;
014:        import org.eclipse.jface.dialogs.MessageDialog;
015:        import org.eclipse.jface.viewers.DoubleClickEvent;
016:        import org.eclipse.jface.viewers.IDoubleClickListener;
017:        import org.eclipse.jface.viewers.ISelection;
018:        import org.eclipse.jface.viewers.IStructuredSelection;
019:        import org.eclipse.jface.viewers.StructuredSelection;
020:        import org.eclipse.jface.window.Window;
021:        import org.eclipse.swt.widgets.Display;
022:        import org.eclipse.ui.IObjectActionDelegate;
023:        import org.eclipse.ui.IViewActionDelegate;
024:        import org.eclipse.ui.IViewPart;
025:        import org.eclipse.ui.IWorkbenchPart;
026:        import org.geotools.geometry.jts.ReferencedEnvelope;
027:        import org.tcat.citd.sim.udig.bookmarks.Bookmark;
028:        import org.tcat.citd.sim.udig.bookmarks.BookmarkCommandFactory;
029:        import org.tcat.citd.sim.udig.bookmarks.BookmarkManager;
030:        import org.tcat.citd.sim.udig.bookmarks.BookmarksPlugin;
031:        import org.tcat.citd.sim.udig.bookmarks.internal.MapReference;
032:        import org.tcat.citd.sim.udig.bookmarks.internal.MapWrapper;
033:        import org.tcat.citd.sim.udig.bookmarks.internal.Messages;
034:        import org.tcat.citd.sim.udig.bookmarks.internal.ui.BookmarksView;
035:
036:        import com.vividsolutions.jts.geom.Envelope;
037:
038:        /**
039:         * The action delegate the provides all of the actions for working with bookmarks.
040:         * <p>
041:         * </p>
042:         * 
043:         * @author cole.markham
044:         * @since 1.0.0
045:         */
046:        public class BookmarkAction extends Action implements 
047:                IObjectActionDelegate, IViewActionDelegate,
048:                IDoubleClickListener {
049:            /**
050:             * id for action to remove a bookmark
051:             */
052:            public static final String REMOVE_BOOKMARK_ACTION_ID = Messages.BookmarkAction_removebookmarkaction;
053:
054:            /**
055:             * id for action to remove a bookmark
056:             */
057:            public static final String REMOVE_MAP_ACTION_ID = Messages.BookmarkAction_removemapaction;
058:
059:            /**
060:             * id for action to remove a bookmark
061:             */
062:            public static final String REMOVE_PROJECT_ACTION_ID = Messages.BookmarkAction_removeprojectaction;
063:
064:            /**
065:             * id for action to remove all bookmarks
066:             */
067:            public static final String REMOVE_ALL_ACTION_ID = Messages.BookmarkAction_removeallbookmarksaction;
068:
069:            /**
070:             * id for action to go to a bookmark
071:             */
072:            public static final String GOTO_BOOKMARK_ACTION_ID = Messages.BookmarkAction_gotobookmarkaction;
073:
074:            /**
075:             * id for action to add a bookmark
076:             */
077:            public static final String ADD_BOOKMARK_ACTION_ID = Messages.BookmarkAction_addbookmarkaction;
078:
079:            /**
080:             * id for action to rename a bookmark
081:             */
082:            public static final String RENAME_BOOKMARK_ACTION_ID = Messages.BookmarkAction_renamebookmarkaction;
083:
084:            /**
085:             * id for action to save the bookmarks
086:             */
087:            public static final String SAVE_BOOKMARKS_ACTION_ID = Messages.BookmarkAction_savebookmarksaction;
088:
089:            /**
090:             * id for action to restore the bookmarks
091:             */
092:            public static final String RESTORE_BOOKMARKS_ACTION_ID = Messages.BookmarkAction_restorebookmarksaction;
093:
094:            @SuppressWarnings("unused")
095:            private IViewPart view;
096:            private IStructuredSelection selection;
097:            private BookmarkManager bmManager;
098:
099:            /**
100:             * Default Constructor
101:             */
102:            public BookmarkAction() {
103:                // nothing to do
104:            }
105:
106:            // public void run() {
107:            // ViewportModel v = (ViewportModel)(PlatformGIS.getActiveMap().getViewportModel());
108:            // IStructuredSelection selection = (IStructuredSelection)this.view.viewer.getSelection();
109:            // Bookmark bookmark = (Bookmark)selection.getFirstElement();
110:            // v.setBounds(bookmark.getEnvelope());
111:            // }
112:
113:            public void setActivePart(IAction action, IWorkbenchPart targetPart) {
114:                if (targetPart != null && targetPart instanceof  IViewPart) {
115:                    view = (IViewPart) targetPart;
116:                }
117:            }
118:
119:            public void run(IAction action) {
120:                try {
121:                    if (REMOVE_ALL_ACTION_ID.equals(action.getId())) {
122:                        if (MessageDialog
123:                                .openConfirm(
124:                                        Display.getCurrent().getActiveShell(),
125:                                        Messages.BookmarkAction_dialogtitle_removebookmarks,
126:                                        Messages.BookmarkAction_dialogprompt_removeallbookmarks)) {
127:                            if (bmManager == null) {
128:                                bmManager = BookmarksPlugin.getDefault()
129:                                        .getBookmarkManager();
130:                            }
131:                            bmManager.empty();
132:                            refreshView();
133:                        }
134:                    } else if (REMOVE_MAP_ACTION_ID.equals(action.getId())) {
135:                        int size = selection.size();
136:                        if (size > 0) {
137:                            if (size > 1) {
138:                                if (MessageDialog
139:                                        .openConfirm(
140:                                                Display.getCurrent()
141:                                                        .getActiveShell(),
142:                                                Messages.BookmarkAction_dialogtitle_removebookmarks,
143:                                                Messages.BookmarkAction_dialogprompt_removemapbookmarks)) {
144:                                    MapReference map = (MapReference) selection
145:                                            .getFirstElement();
146:                                    if (bmManager == null) {
147:                                        bmManager = BookmarksPlugin
148:                                                .getDefault()
149:                                                .getBookmarkManager();
150:                                    }
151:                                    bmManager.removeMap(map);
152:                                }
153:                            } else {
154:                                if (MessageDialog
155:                                        .openConfirm(
156:                                                Display.getCurrent()
157:                                                        .getActiveShell(),
158:                                                Messages.BookmarkAction_dialogtitle_removebookmarks,
159:                                                Messages.BookmarkAction_dialogprompt_removeselectedmaps)) {
160:                                    if (bmManager == null) {
161:                                        bmManager = BookmarksPlugin
162:                                                .getDefault()
163:                                                .getBookmarkManager();
164:                                    }
165:                                    List wrappedMaps = selection.toList();
166:                                    Collection maps = MapWrapper
167:                                            .unwrap(wrappedMaps);
168:                                    bmManager.removeMaps(maps);
169:                                }
170:                            }
171:                            refreshView();
172:                        }
173:                        // }else if(REMOVE_PROJECT_ACTION_ID.equals(action.getId())){
174:                        // int size = selection.size();
175:                        // if(size > 0){
176:                        // if(size > 1){
177:                        // if( MessageDialog.openConfirm(
178:                        // Display.getCurrent().getActiveShell(),
179:                        // Messages..BOOKMARK_ACTION_DIALOGTITLE_REMOVEBOOKMARKS,
180:                        // //$NON-NLS-1$
181:                        // Messages..BOOKMARK_ACTION_DIALOGPROMPT_REMOVEPROJECTBOOKMARKS)
182:                        // ){ //$NON-NLS-1$
183:                        // ProjectWrapper wrapper = (ProjectWrapper)selection.getFirstElement();
184:                        // if(bmManager == null){
185:                        // bmManager = BookmarksPlugin.getDefault().getBookmarkManager();
186:                        // }
187:                        // // bmManager.removeProject(wrapper.getProject());
188:                        // }
189:                        // }else {
190:                        // if( MessageDialog.openConfirm(
191:                        // Display.getCurrent().getActiveShell(),
192:                        // Messages..BOOKMARK_ACTION_DIALOGTITLE_REMOVEBOOKMARKS,
193:                        // //$NON-NLS-1$
194:                        // Messages..BOOKMARK_ACTION_DIALOGPROMPT_REMOVESELECTEDPROJECTS)
195:                        // ){ //$NON-NLS-1$
196:                        // if(bmManager == null){
197:                        // bmManager = BookmarksPlugin.getDefault().getBookmarkManager();
198:                        // }
199:                        // List wrappedProjects = selection.toList();
200:                        // Collection<IProject> projects = ProjectWrapper.unwrap(wrappedProjects);
201:                        // bmManager.removeProjects(projects);
202:                        // }
203:                        // }
204:                        // refreshView();
205:                        // }
206:                    } else if (REMOVE_BOOKMARK_ACTION_ID.equals(action.getId())) {
207:                        int size = selection.size();
208:                        if (size > 0) {
209:                            if (size > 1) {
210:                                if (MessageDialog
211:                                        .openConfirm(
212:                                                Display.getCurrent()
213:                                                        .getActiveShell(),
214:                                                Messages.BookmarkAction_dialogtitle_removebookmarks,
215:                                                Messages.BookmarkAction_dialogprompt_removeselectedbookmarks)) {
216:                                    List bookmarks = selection.toList();
217:                                    if (bmManager == null) {
218:                                        bmManager = BookmarksPlugin
219:                                                .getDefault()
220:                                                .getBookmarkManager();
221:                                    }
222:                                    bmManager.removeBookmarks(bookmarks);
223:                                }
224:                            } else {
225:                                if (MessageDialog
226:                                        .openConfirm(
227:                                                Display.getCurrent()
228:                                                        .getActiveShell(),
229:                                                Messages.BookmarkAction_dialogtitle_removebookmark,
230:                                                Messages.BookmarkAction_dialogprompt_removebookmark)) {
231:                                    Bookmark bookmark = (Bookmark) selection
232:                                            .getFirstElement();
233:                                    if (bmManager == null) {
234:                                        bmManager = BookmarksPlugin
235:                                                .getDefault()
236:                                                .getBookmarkManager();
237:                                    }
238:                                    bmManager.removeBookmark(bookmark);
239:                                }
240:                            }
241:                            refreshView();
242:                        }
243:                    } else if (GOTO_BOOKMARK_ACTION_ID.equals(action.getId())) {
244:                        Bookmark bookmark = (Bookmark) selection
245:                                .getFirstElement();
246:                        gotoBookmark(bookmark);
247:                    } else if (ADD_BOOKMARK_ACTION_ID.equals(action.getId())) {
248:                        IMap map = ApplicationGIS.getActiveMap();
249:                        if (map != null) {
250:                            IViewportModel v = map.getViewportModel();
251:                            Envelope env = v.getBounds();
252:                            ReferencedEnvelope bounds;
253:                            if (env instanceof  ReferencedEnvelope) {
254:                                bounds = (ReferencedEnvelope) env;
255:                            } else {
256:                                bounds = new ReferencedEnvelope(env, v.getCRS());
257:                            }
258:                            MapReference ref = bmManager.getMapReference(map);
259:                            Bookmark bookmark = new Bookmark(bounds, ref, null);
260:                            InputDialog dialog = new InputDialog(
261:                                    Display.getCurrent().getActiveShell(),
262:                                    Messages.BookmarkAction_dialogtitle_bookmarklocation,
263:                                    Messages.BookmarkAction_dialogprompt_enterbookmarkname,
264:                                    bookmark.getName(), null);
265:                            dialog.open();
266:                            if (dialog.getReturnCode() == Window.OK) {
267:                                String name = dialog.getValue();
268:                                bookmark.setName(name);
269:                                bmManager = BookmarksPlugin.getDefault()
270:                                        .getBookmarkManager();
271:                                bmManager.addBookmark(bookmark);
272:                                refreshView();
273:                            }
274:                            ((BookmarksView) view)
275:                                    .selectReveal(new StructuredSelection(
276:                                            bookmark));
277:                        }
278:                    } else if (RENAME_BOOKMARK_ACTION_ID.equals(action.getId())) {
279:                        Bookmark bookmark = (Bookmark) selection
280:                                .getFirstElement();
281:                        InputDialog dialog = new InputDialog(
282:                                Display.getCurrent().getActiveShell(),
283:                                Messages.BookmarkAction_dialogtitle_renamebookmark,
284:                                Messages.BookmarkAction_dialogprompt_enterbookmarkname,
285:                                bookmark.getName(), null);
286:                        dialog.open();
287:                        if (dialog.getReturnCode() == Window.OK) {
288:                            String name = dialog.getValue();
289:                            bookmark.setName(name);
290:                            refreshView();
291:                        }
292:                    } else if (SAVE_BOOKMARKS_ACTION_ID.equals(action.getId())) {
293:                        BookmarksPlugin.getDefault().storeToPreferences();
294:                    } else if (RESTORE_BOOKMARKS_ACTION_ID.equals(action
295:                            .getId())) {
296:                        BookmarksPlugin.getDefault().restoreFromPreferences();
297:                        refreshView();
298:                    }
299:                } catch (Exception e) {
300:                    e.printStackTrace();
301:                }
302:            }
303:
304:            private void refreshView() {
305:                if (view != null && view instanceof  BookmarksView) {
306:                    BookmarksView bView = ((BookmarksView) view);
307:                    bView.refresh();
308:                }
309:            }
310:
311:            /**
312:             * Go to the given bookmark
313:             * 
314:             * @param bookmark The bookmark to go to
315:             */
316:            private void gotoBookmark(Bookmark bookmark) {
317:                BookmarkCommandFactory factory = BookmarkCommandFactory
318:                        .getInstance();
319:                MapCommand cmd = factory.createGotoBookmarkCommand(bookmark);
320:                ApplicationGIS.getActiveMap().sendCommandASync(cmd);
321:            }
322:
323:            public void init(IViewPart viewPart) {
324:                if (viewPart != null) {
325:                    this .view = viewPart;
326:                }
327:                if (bmManager == null) {
328:                    bmManager = BookmarksPlugin.getDefault()
329:                            .getBookmarkManager();
330:                }
331:            }
332:
333:            public void selectionChanged(IAction action, ISelection newSelection) {
334:                this .selection = (IStructuredSelection) newSelection;
335:            }
336:
337:            public void doubleClick(DoubleClickEvent event) {
338:                final IStructuredSelection eventSelection = (IStructuredSelection) event
339:                        .getSelection();
340:                if (eventSelection.size() > 0
341:                        && eventSelection.getFirstElement() instanceof  Bookmark) {
342:                    Bookmark bookmark = (Bookmark) eventSelection
343:                            .getFirstElement();
344:                    gotoBookmark(bookmark);
345:                }
346:            }
347:
348:        }
w___ww___.__j___ava_2s_.c___o__m___ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.