Source Code Cross Referenced for BookmarkTreeModel.java in  » Database-Client » iSQL-Viewer » org » isqlviewer » model » 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.model 
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.model;
024:
025:        import java.sql.SQLException;
026:
027:        import javax.swing.event.TreeModelEvent;
028:        import javax.swing.tree.TreePath;
029:
030:        import org.isqlviewer.bookmarks.BookmarkFolder;
031:        import org.isqlviewer.bookmarks.BookmarkReference;
032:        import org.isqlviewer.sql.embedded.EmbeddedDatabase;
033:        import org.isqlviewer.swing.AbstractTreeModel;
034:
035:        /**
036:         * Datamodel for managing Bookmark objects similar to a local-filesystem.
037:         * <p>
038:         * This model mimics a file-system such that there are folders and bookmarks. This model provides various utility
039:         * methods for creating paths and adding bookmarks. The filesystem if will is based of an internal hashmap of
040:         * fully-qualified paths as the key(s) and for each path an array list of full-paths as sub paths and Bookmark object(s)
041:         * represent a folder in a logical sense.
042:         * <p>
043:         * In terms of paths they are of the form '/my folder/sub-1/sub-2/' using '/' is obviously always the root-path as well
044:         * as the root-node of this tree model.
045:         * <p>
046:         * This object provides it's own persistence methods to ensure that this model is properly encoded in UTF-8 for XML
047:         * format. iSQL-Viewer will store a 'bookmarks.xml' file in the designated $isql.home property. The persistence
048:         * mechanisims ensure UTF8 format by using Charset object of the nio packages.
049:         * 
050:         * @see java.nio.charset.Charset
051:         * @author Markus A. Kobold &lt;mkobold at sprintpcs dot com&gt;
052:         * @version 1.0
053:         */
054:        public class BookmarkTreeModel extends AbstractTreeModel {
055:
056:            private BookmarkFolder rootFolder = null;
057:
058:            /**
059:             * @param rootFolder
060:             */
061:            public BookmarkTreeModel(BookmarkFolder rootFolder) {
062:
063:                this .rootFolder = rootFolder;
064:            }
065:
066:            public Object getChild(Object parent, int index) {
067:
068:                if (parent != null && parent instanceof  BookmarkFolder) {
069:                    BookmarkFolder folder = (BookmarkFolder) parent;
070:                    return folder.getChild(index);
071:                }
072:                return null;
073:            }
074:
075:            public int getChildCount(Object parent) {
076:
077:                if (parent != null && parent instanceof  BookmarkFolder) {
078:                    BookmarkFolder folder = (BookmarkFolder) parent;
079:                    return folder.getChildCount();
080:                }
081:                return 0;
082:            }
083:
084:            public int getIndexOfChild(Object parent, Object child) {
085:
086:                if (parent != null && parent instanceof  BookmarkFolder) {
087:                    BookmarkFolder folder = (BookmarkFolder) parent;
088:                    return folder.indexOfChild(child);
089:                }
090:                return 0;
091:            }
092:
093:            public Object getRoot() {
094:
095:                return rootFolder;
096:            }
097:
098:            public boolean isLeaf(Object node) {
099:
100:                return (node == null || node instanceof  BookmarkReference);
101:            }
102:
103:            public void valueForPathChanged(TreePath path, Object newValue) {
104:
105:                System.out.println("path:" + path + "; " + newValue);
106:                Object changedObject = path.getLastPathComponent();
107:                String changedName = newValue.toString();
108:                EmbeddedDatabase database = EmbeddedDatabase
109:                        .getSharedInstance();
110:                if (changedObject instanceof  BookmarkReference) {
111:                    BookmarkReference reference = (BookmarkReference) changedObject;
112:                    String previousName = reference.getName();
113:                    try {
114:                        reference.setName(changedName);
115:                        database.updateBookmark(reference);
116:                    } catch (SQLException e) {
117:                        reference.setName(previousName);
118:                    }
119:                } else if (changedObject instanceof  BookmarkFolder) {
120:                    BookmarkFolder folder = (BookmarkFolder) changedObject;
121:                    String previousName = folder.getName();
122:                    String existingPath = folder.getPath();
123:                    try {
124:                        folder.setName(changedName);
125:                        String newPath = folder.getPath();
126:                        database.renameBookmarkFolder(existingPath, newPath);
127:                    } catch (SQLException e) {
128:                        folder.setName(previousName);
129:                    }
130:                }
131:            }
132:
133:            public void removeBookmark(BookmarkReference bookmark) {
134:
135:                BookmarkFolder parentFolder = rootFolder.findChildPath(bookmark
136:                        .getPath());
137:                parentFolder = (parentFolder == null) ? rootFolder
138:                        : parentFolder;
139:
140:                Object[] objectPath = BookmarkFolder
141:                        .getPathElements(parentFolder);
142:                Object[] children = new Object[] { bookmark };
143:                int[] indicies = new int[] { parentFolder
144:                        .indexOfChild(bookmark) };
145:                parentFolder.removeBookmark(bookmark);
146:
147:                TreeModelEvent removeEvent = new TreeModelEvent(this ,
148:                        objectPath, indicies, children);
149:                fireTreeNodesRemoved(removeEvent);
150:            }
151:
152:            public void removeBookmarkFolder(BookmarkFolder folder) {
153:
154:                BookmarkFolder parentFolder = folder.getParentFolder();
155:                parentFolder = (parentFolder == null) ? rootFolder
156:                        : parentFolder;
157:
158:                Object[] objectPath = BookmarkFolder
159:                        .getPathElements(parentFolder);
160:                Object[] children = new Object[] { folder };
161:                int[] indicies = new int[] { parentFolder.indexOfChild(folder) };
162:                parentFolder.removeFolder(folder);
163:
164:                TreeModelEvent removeEvent = new TreeModelEvent(this ,
165:                        objectPath, indicies, children);
166:                fireTreeNodesRemoved(removeEvent);
167:            }
168:
169:            public void addBookmark(BookmarkReference bookmark,
170:                    BookmarkFolder parentFolder) {
171:
172:                parentFolder.addBookmark(bookmark);
173:                Object[] objectPath = BookmarkFolder
174:                        .getPathElements(parentFolder);
175:                Object[] children = new Object[] { bookmark };
176:                int[] indicies = new int[] { parentFolder
177:                        .indexOfChild(bookmark) };
178:
179:                TreeModelEvent addEvent = new TreeModelEvent(this , objectPath,
180:                        indicies, children);
181:                fireTreeNodesInserted(addEvent);
182:            }
183:
184:            public void addBookmarkFolder(BookmarkFolder parentFolder,
185:                    String folderName) {
186:
187:                BookmarkFolder childFolder = parentFolder
188:                        .addChildFolder(folderName);
189:
190:                Object[] objectPath = BookmarkFolder
191:                        .getPathElements(parentFolder);
192:                Object[] children = new Object[] { childFolder };
193:                int[] indicies = new int[] { parentFolder
194:                        .indexOfChild(childFolder) };
195:
196:                TreeModelEvent removeEvent = new TreeModelEvent(this ,
197:                        objectPath, indicies, children);
198:                fireTreeNodesInserted(removeEvent);
199:            }
200:
201:            public void reload(BookmarkFolder parentFolder,
202:                    BookmarkReference bookmark) {
203:
204:                Object[] objectPath = BookmarkFolder
205:                        .getPathElements(parentFolder);
206:                Object[] children = new Object[] { bookmark };
207:                int[] indicies = new int[] { parentFolder
208:                        .indexOfChild(bookmark) };
209:                parentFolder.addBookmark(bookmark);
210:
211:                TreeModelEvent changeEvent = new TreeModelEvent(this,
212:                        objectPath, indicies, children);
213:                fireTreeNodesChanged(changeEvent);
214:            }
215:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.