Source Code Cross Referenced for TreeExpandedState.java in  » IDE-Netbeans » xml » org » netbeans » modules » xslt » mapper » 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 Netbeans » xml » org.netbeans.modules.xslt.mapper.model 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * The contents of this file are subject to the terms of the Common Development
003:         * and Distribution License (the License). You may not use this file except in
004:         * compliance with the License.
005:         *
006:         * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
007:         * or http://www.netbeans.org/cddl.txt.
008:         *
009:         * When distributing Covered Code, include this CDDL Header Notice in each file
010:         * and include the License file at http://www.netbeans.org/cddl.txt.
011:         * If applicable, add the following below the CDDL Header, with the fields
012:         * enclosed by brackets [] replaced by your own identifying information:
013:         * "Portions Copyrighted [year] [name of copyright owner]"
014:         *
015:         * Portions Copyrighted 2007 Sun Microsystems, Inc.
016:         */
017:        package org.netbeans.modules.xslt.mapper.model;
018:
019:        import java.util.ArrayList;
020:        import java.util.Enumeration;
021:        import java.util.Iterator;
022:        import java.util.List;
023:        import javax.swing.JTree;
024:        import javax.swing.tree.TreePath;
025:        import org.netbeans.modules.xslt.mapper.model.nodes.TreeNode;
026:
027:        /**
028:         *
029:         * @author Alexey
030:         */
031:        public class TreeExpandedState {
032:
033:            private JTree tree;
034:            private ArrayList<ArrayList<Step>> expanedNodes = new ArrayList<ArrayList<Step>>();
035:
036:            private class Step {
037:
038:                protected String name;
039:                protected int index;
040:
041:                public Step(String name, int index) {
042:                    this .name = name;
043:                    this .index = index;
044:                }
045:
046:                public int getIndex() {
047:                    return this .index;
048:                }
049:
050:                public String getName() {
051:                    return this .name;
052:                }
053:            }
054:
055:            public TreeExpandedState(JTree tree) {
056:                this .tree = tree;
057:            }
058:
059:            public void save() {
060:
061:                TreeNode root = (TreeNode) tree.getModel().getRoot();
062:
063:                TreePath root_tp = TreeNode.getTreePath(root);
064:                //save the expanded state
065:                Enumeration<TreePath> expanded = tree
066:                        .getExpandedDescendants(root_tp);
067:                if (expanded != null) {
068:                    while (expanded.hasMoreElements()) {
069:                        TreePath tp = expanded.nextElement();
070:                        ArrayList<Step> path = getStepsByTreePath(tp);
071:                        expanedNodes.add(path);
072:                    }
073:                }
074:            }
075:
076:            public void restore() {
077:
078:                for (ArrayList<Step> steps : expanedNodes) {
079:                    TreePath tp = getTreePathbySteps(steps);
080:                    if (tp != null) {
081:                        tree.expandPath(tp);
082:                    }
083:                }
084:            }
085:
086:            private ArrayList<Step> getStepsByTreePath(TreePath tp) {
087:
088:                ArrayList<Step> result = new ArrayList<Step>();
089:
090:                for (int n = 0; n < tp.getPathCount(); n++) {
091:                    TreeNode node = (TreeNode) tp.getPathComponent(n);
092:                    String name = node.toString();
093:
094:                    TreeNode parent = node.getParent();
095:
096:                    int index = 0;
097:
098:                    //calculate node index
099:                    if (parent != null) {
100:                        List<TreeNode> children = parent.getChildren();
101:                        for (TreeNode tn : children) {
102:                            String name1 = tn.toString();
103:                            if (name1.equals(name)) {
104:                                if (node == tn) {
105:                                    break;
106:                                }
107:                                index++;
108:                            }
109:                        }
110:                    }
111:                    result.add(new Step(name, index));
112:                }
113:                return result;
114:            }
115:
116:            private TreePath getTreePathbySteps(ArrayList<Step> steps) {
117:
118:                TreeNode node = (TreeNode) tree.getModel().getRoot();
119:
120:                if (node == null) {
121:                    return null;
122:                }
123:
124:                if (steps.size() == 0) {
125:                    return null;
126:                }
127:
128:                if (!steps.get(0).getName().equals(node.toString())) {
129:                    return null;
130:                }
131:
132:                Iterator it = steps.iterator();
133:
134:                TreePath result = new TreePath(node);
135:
136:                for (int n = 1; n < steps.size(); n++) {
137:                    Step step = steps.get(n);
138:
139:                    List<TreeNode> children = node.getChildren();
140:
141:                    node = getTreeNodeByStep(children, step);
142:                    if (node == null) {
143:                        return null;
144:                    }
145:
146:                    result = result.pathByAddingChild(node);
147:                }
148:                return result;
149:            }
150:
151:            private TreeNode getTreeNodeByStep(List<TreeNode> children,
152:                    Step step) {
153:                int index = 0;
154:                for (TreeNode tn : children) {
155:                    if (step.getName().equals(tn.toString())) {
156:                        if (index == step.index) {
157:                            return tn;
158:                        }
159:                        index++;
160:                    }
161:                }
162:                return null;
163:            }
164:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.