Source Code Cross Referenced for BookmarkTreeDropTarget.java in  » Database-Client » iSQL-Viewer » org » isqlviewer » ui » dnd » 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 » Database Client » iSQL Viewer » org.isqlviewer.ui.dnd 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * The contents of this file are subject to the Mozilla Public License
003:         * Version 1.1 (the "License"); you may not use this file except in
004:         * compliance with the License. You may obtain a copy of the License at
005:         * http://www.mozilla.org/MPL/
006:         *
007:         * Software distributed under the License is distributed on an "AS IS"
008:         * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
009:         * License for the specific language governing rights and limitations
010:         * under the License.
011:         * 
012:         * The Original Code is iSQL-Viewer, A Mutli-Platform Database Tool.
013:         *
014:         * The Initial Developer of the Original Code is iSQL-Viewer, A Mutli-Platform Database Tool.
015:         * Portions created by Mark A. Kobold are Copyright (C) 2000-2007. All Rights Reserved.
016:         *
017:         * Contributor(s): 
018:         *  Mark A. Kobold [mkobold <at> isqlviewer <dot> com].
019:         *  
020:         * If you didn't download this code from the following link, you should check
021:         * if you aren't using an obsolete version: http://www.isqlviewer.com
022:         */
023:        package org.isqlviewer.ui.dnd;
024:
025:        import java.awt.HeadlessException;
026:        import java.awt.datatransfer.DataFlavor;
027:        import java.awt.datatransfer.Transferable;
028:        import java.awt.datatransfer.UnsupportedFlavorException;
029:        import java.awt.dnd.DnDConstants;
030:        import java.awt.dnd.DropTargetDragEvent;
031:        import java.awt.dnd.DropTargetDropEvent;
032:        import java.awt.dnd.DropTargetEvent;
033:        import java.awt.dnd.DropTargetListener;
034:        import java.awt.event.ActionEvent;
035:        import java.io.IOException;
036:        import java.sql.SQLException;
037:
038:        import javax.swing.JTree;
039:        import javax.swing.tree.TreePath;
040:
041:        import org.isqlviewer.bookmarks.Bookmark;
042:        import org.isqlviewer.bookmarks.BookmarkFolder;
043:        import org.isqlviewer.bookmarks.BookmarkReference;
044:        import org.isqlviewer.history.HistoricalCommand;
045:        import org.isqlviewer.model.BookmarkTreeModel;
046:        import org.isqlviewer.sql.embedded.EmbeddedDatabase;
047:        import org.isqlviewer.swing.action.SharedActions;
048:        import org.isqlviewer.swing.action.SwingEventManager;
049:
050:        /**
051:         * Adapter object for handling drop events for bookmarks, folders, and text within a bookmark tree view.
052:         * <p>
053:         * 
054:         * @author Mark A. Kobold &lt;mkobold at isqlviewer dot com&gt;
055:         * @version 1.0
056:         */
057:        public class BookmarkTreeDropTarget implements  DropTargetListener {
058:
059:            private static final long serialVersionUID = 1L;
060:            private SwingEventManager eventManager = null;
061:
062:            public BookmarkTreeDropTarget(SwingEventManager eventManager)
063:                    throws HeadlessException {
064:
065:                this .eventManager = eventManager;
066:            }
067:
068:            public void drop(DropTargetDropEvent event) {
069:
070:                Transferable transferable = event.getTransferable();
071:                int dropX = event.getLocation().x;
072:                int dropY = event.getLocation().y;
073:
074:                JTree bookmarkView = (JTree) event.getDropTargetContext()
075:                        .getComponent();
076:                TreePath dropTreePath = bookmarkView.getPathForLocation(dropX,
077:                        dropY);
078:                BookmarkTreeModel bookmarkModel = (BookmarkTreeModel) bookmarkView
079:                        .getModel();
080:                Object dropTarget = (dropTreePath != null ? dropTreePath
081:                        .getLastPathComponent() : "/");
082:                BookmarkFolder dropFolder = null;
083:
084:                if (dropTarget instanceof  BookmarkReference) {
085:                    BookmarkReference reference = (BookmarkReference) dropTarget;
086:                    dropFolder = reference.getFolder();
087:                } else if (dropTarget instanceof  BookmarkFolder) {
088:                    dropFolder = (BookmarkFolder) dropTarget;
089:                }
090:
091:                if (dropFolder == null) {
092:                    dropFolder = (BookmarkFolder) bookmarkModel.getRoot();
093:                }
094:
095:                if (transferable
096:                        .isDataFlavorSupported(Bookmark.BOOKMARK_FLAVOR)) {
097:                    event.acceptDrop(event.getDropAction());
098:                    dropBookmark(event, transferable, bookmarkModel, dropFolder);
099:                } else if (transferable
100:                        .isDataFlavorSupported(HistoricalCommand.FLAVOR)) {
101:                    event.acceptDrop(event.getDropAction());
102:                    HistoricalCommand source = null;
103:                    try {
104:                        source = (HistoricalCommand) transferable
105:                                .getTransferData(HistoricalCommand.FLAVOR);
106:                    } catch (UnsupportedFlavorException e) {
107:                        event.rejectDrop();
108:                        return;
109:                    } catch (IOException e) {
110:                        event.rejectDrop();
111:                        return;
112:                    }
113:                    String commandText = dropFolder.getPath();
114:                    int eventId = SharedActions.CONVERT_HISTORY_TO_BOOKMARK;
115:                    ActionEvent convertAction = new ActionEvent(source,
116:                            eventId, commandText);
117:                    eventManager.actionPerformed(convertAction);
118:                    event.dropComplete(true);
119:                } else if (transferable
120:                        .isDataFlavorSupported(DataFlavor.stringFlavor)) {
121:                    event.acceptDrop(event.getDropAction());
122:                    String source = null;
123:                    try {
124:                        source = (String) transferable
125:                                .getTransferData(DataFlavor.stringFlavor);
126:                    } catch (UnsupportedFlavorException e) {
127:                        event.rejectDrop();
128:                        return;
129:                    } catch (IOException e) {
130:                        event.rejectDrop();
131:                        return;
132:                    }
133:                    String commandText = dropFolder.getPath();
134:                    int eventId = SharedActions.CONVERT_TEXT_TO_BOOKMARK;
135:                    ActionEvent convertAction = new ActionEvent(source,
136:                            eventId, commandText);
137:                    eventManager.actionPerformed(convertAction);
138:                    event.dropComplete(true);
139:                } else {
140:                    // unsupported data flavor //
141:                    event.rejectDrop();
142:                }
143:            }
144:
145:            public void dragEnter(DropTargetDragEvent dtde) {
146:
147:            }
148:
149:            public void dragExit(DropTargetEvent dte) {
150:
151:            }
152:
153:            public void dragOver(DropTargetDragEvent dtde) {
154:
155:            }
156:
157:            public void dropActionChanged(DropTargetDragEvent dtde) {
158:
159:            }
160:
161:            private void dropBookmark(DropTargetDropEvent event,
162:                    Transferable transferable, BookmarkTreeModel bookmarkModel,
163:                    BookmarkFolder dropFolder) {
164:
165:                Bookmark source = null;
166:                try {
167:                    source = (Bookmark) transferable
168:                            .getTransferData(Bookmark.BOOKMARK_FLAVOR);
169:                } catch (UnsupportedFlavorException e) {
170:                    event.rejectDrop();
171:                    return;
172:                } catch (IOException e) {
173:                    event.rejectDrop();
174:                    return;
175:                }
176:
177:                BookmarkFolder sourceFolder = source.getFolder();
178:                Bookmark bookmark = null;
179:                boolean doUpdate = false;
180:                int dndOperation = event.getDropAction();
181:
182:                switch (dndOperation) {
183:                case DnDConstants.ACTION_MOVE:
184:                    bookmark = source;
185:                    doUpdate = true;
186:                    break;
187:                case DnDConstants.ACTION_COPY:
188:                    Bookmark copy = source.clone();
189:                    bookmark = copy;
190:                    break;
191:                default:
192:                    event.rejectDrop();
193:                    return;
194:                }
195:
196:                EmbeddedDatabase database = EmbeddedDatabase
197:                        .getSharedInstance();
198:                try {
199:                    if (doUpdate) {
200:                        bookmarkModel.removeBookmark(bookmark);
201:                        bookmarkModel.addBookmark(bookmark, dropFolder);
202:                        database.updateBookmark(bookmark);
203:                    } else {
204:                        bookmarkModel.addBookmark(bookmark, dropFolder);
205:                        database.addBookmark(bookmark);
206:                    }
207:                    event.dropComplete(true);
208:                } catch (SQLException sourceError) {
209:                    // rollback and reject the drop //
210:                    if (doUpdate) {
211:                        bookmarkModel.removeBookmark(bookmark);
212:                        bookmarkModel.addBookmark(bookmark, sourceFolder);
213:                    } else {
214:                        bookmarkModel.removeBookmark(bookmark);
215:                    }
216:                    bookmarkModel.reload(sourceFolder, bookmark);
217:                    event.dropComplete(false);
218:                }
219:            }
220:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.