Source Code Cross Referenced for FileComponentsTreeModel.java in  » IDE » Schmortopf » Schmortopf » FileComponents » 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 » IDE » Schmortopf » Schmortopf.FileComponents.Model 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package Schmortopf.FileComponents.Model;
002:
003:        /**         
004:         *  A basic tree model, without climbim yet.
005:         *
006:         *  By a call to initializeTreeFromEditorContent( huge string )
007:         *  it will build a parser tree from the passed string.
008:         *
009:         */
010:
011:        import java.awt.*;
012:        import javax.swing.tree.*;
013:        import java.io.*;
014:
015:        import Schmortopf.JavaLanguageParser.*;
016:        import Schmortopf.JavaLanguageParser.JavaCCParser.*;
017:        import Schmortopf.FileComponents.View.*;
018:        import Schmortopf.JavaSourceEditor.SourceEditorDocument;
019:        import Schmortopf.FileStructure.*;
020:        import Schmortopf.FileStructure.Descriptions.*;
021:        import Schmortopf.ProjectFiles.ProjectFilesTree.ProjectFilesTreeModel;
022:        import Shared.Logging.Log;
023:
024:        public class FileComponentsTreeModel extends DefaultTreeModel {
025:
026:            private DefaultMutableTreeNode rootNode;
027:
028:            public FileComponentsTreeModel() {
029:                super (new DefaultMutableTreeNode("", true), true);
030:                // second parm true -> GUI difference between files and
031:                // directories given by canHaveChildren.
032:                this .rootNode = (DefaultMutableTreeNode) super .getRoot();
033:                // and set it :
034:                super .setRoot(this .rootNode);
035:            }
036:
037:            private void addFileNodes(final File basisFile,
038:                    final DefaultMutableTreeNode basisNode) {
039:                if (basisFile.isDirectory()) {
040:                    File[] children = basisFile.listFiles();
041:                    for (int i = 0; i < children.length; i++) {
042:                        if (children[i].isDirectory()) {
043:                            // add to tree (allowsChildren = 2nd parm = true) :
044:                            final DefaultMutableTreeNode childNode = new DefaultMutableTreeNode(
045:                                    children[i].getName(), true);
046:                            basisNode.add(childNode);
047:                            // continue recursion :
048:                            this .addFileNodes(children[i], childNode);
049:                        } else {
050:                            // Just add that file :
051:                            final String fileName = children[i].getName();
052:                            // add to tree (allowsChildren = 2nd parm = false) :
053:                            final DefaultMutableTreeNode fileNode = new DefaultMutableTreeNode(
054:                                    fileName, false);
055:                            basisNode.add(fileNode);
056:                        }
057:                    } // for
058:                } // if
059:            } // addFileNodes
060:
061:            /**
062:             *  Called by the combined view-controler, when a new
063:             *  file has been selected and has been displayed in the editor.
064:             *
065:             *  NOTE: This method must be threadsafe, because it also is called
066:             *        from outside the eventdispatch thread.
067:             */
068:            final public void initializeTreeFrom(
069:                    final FileStructureDescription fsd) {
070:                // Convert the FSD into a tree model for the fileComponents tree :
071:                final FileComponentsFSDProcessor treeConverter = new FileComponentsFSDProcessor();
072:                final DefaultMutableTreeNode newFileComponentsRootNode = treeConverter
073:                        .convertFSDToTree(fsd);
074:                // Now the view stuff :
075:                // Change to EDT, if we aren't in already :
076:                if (EventQueue.isDispatchThread()) {
077:                    // Remove any nodes without children :
078:                    removeNodesWithoutChildren(newFileComponentsRootNode);
079:                    // Now all is done, so set the new root node [which updates the view automatically, OF COURSE]:
080:                    setRoot(newFileComponentsRootNode);
081:                } else {
082:                    try {
083:                        EventQueue.invokeAndWait(new Runnable() {
084:                            public void run() {
085:                                try {
086:                                    // Remove any nodes without children :
087:                                    removeNodesWithoutChildren(newFileComponentsRootNode);
088:                                    // Now all is done, so set the new root node [which updates the view automatically, OF COURSE]:
089:                                    setRoot(newFileComponentsRootNode);
090:                                } catch (Exception fce) {
091:                                    Log.Error(fce);
092:                                }
093:                            }
094:                        });
095:                    } catch (Exception sdhkwer) {
096:                    }
097:                }
098:            } // initializeTreeFromEditorContent
099:
100:            public void removeAll(final String emptyRootName) {
101:                // Create the package root node :
102:                final DefaultMutableTreeNode emptyRootNode = new DefaultMutableTreeNode(
103:                        emptyRootName, true);
104:                this .setRoot(emptyRootNode);
105:            }
106:
107:            /**
108:             *  recursive method
109:             */
110:            private void removeNodesWithoutChildren(
111:                    final DefaultMutableTreeNode node) {
112:                if (node.getAllowsChildren()) {
113:                    if (node.getChildCount() > 0) {
114:                        // Caution: indices and counts are modified, when one is removed,
115:                        // therefore we go reverse :
116:                        for (int i = node.getChildCount() - 1; i >= 0; i--) {
117:                            final DefaultMutableTreeNode this ChildNode = (DefaultMutableTreeNode) node
118:                                    .getChildAt(i);
119:                            this .removeNodesWithoutChildren(this ChildNode);
120:                        }
121:                    } else {
122:                        node.removeFromParent();
123:                    }
124:                }
125:            }
126:
127:            /**
128:             *  GC assistance, before this object is decoupled from the application.
129:             *  It should release reference connections.
130:             *  Called by the projectframe when it's closed.
131:             *  Calling method is projectframe.doFinalCleanUp() [ in a ThreadEngine thread ]
132:             */
133:            public void terminate() {
134:                this .removeAll("");
135:            } // terminate
136:
137:        } // FileComponentsTreeModel
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.