Source Code Cross Referenced for XTreeBinding.java in  » XML-UI » XUI » net » xoetrope » swing » tree » 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 » XML UI » XUI » net.xoetrope.swing.tree 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package net.xoetrope.swing.tree;
002:
003:        import java.util.Vector;
004:
005:        import java.awt.Component;
006:        import javax.swing.JTree;
007:        import javax.swing.tree.DefaultTreeModel;
008:        import javax.swing.tree.TreePath;
009:
010:        import net.xoetrope.xui.data.XDataBinding;
011:        import net.xoetrope.xui.data.XModel;
012:        import net.xoetrope.xui.data.XModelAdapter;
013:        import net.xoetrope.xui.XProjectManager;
014:        import java.awt.Component;
015:        import javax.swing.tree.TreeModel;
016:        import javax.swing.tree.DefaultTreeModel;
017:        import java.util.Vector;
018:        import javax.swing.tree.TreePath;
019:        import net.xoetrope.xml.XmlElement;
020:
021:        /**
022:         * This class provides a means of binding a model node and its children to an
023:         * XModel node.
024:         * <p>Copyright: Copyright (c) Xoetrope Ltd., 2001-2004</p>
025:         * <p>$Revision: 1.5 $ </p>
026:         * License see license.txt
027:         */
028:        public class XTreeBinding implements  XDataBinding {
029:            protected JTree comp;
030:            protected XModelAdapter model;
031:            protected XModel outputNode;
032:            protected String srcPath;
033:            protected String outputPath;
034:
035:            /**
036:             * Construct a new data binding
037:             * @param c the JTree component to be bound
038:             * @param node the model node
039:             */
040:            public XTreeBinding(JTree c, XModelAdapter node) {
041:                model = node;
042:                comp = c;
043:                comp.setModel(new DefaultTreeModel((XTreeModelAdapter) model));
044:            }
045:
046:            /**
047:             * Updates the Tree component with the value obtained from the data model.
048:             * Filters the list by ignoring repeat items (note that this does not
049:             * guarantee unique list entries unless the useUnique flag is set).
050:             */
051:            public void get() {
052:                comp.setModel(new DefaultTreeModel(new XTreeModelAdapter(model
053:                        .getModel())));
054:
055:                // in the case of dynamic bindings we want to update the model with what is seleted by default.
056:                set();
057:            }
058:
059:            /**
060:             * Updates the data model with the value retrieved from the TextComponent.
061:             */
062:            public void set() {
063:                if (outputNode != null)
064:                    outputNode.set(getTreePath());
065:            }
066:
067:            /**
068:             * Gets the component on which this binding operates
069:             * @return the bound component
070:             */
071:            public Component getComponent() {
072:                return (Component) comp;
073:            }
074:
075:            /**
076:             * Gets the name of the model node
077:             * @return the name
078:             */
079:            public String getName() {
080:                return ((XTreeModelAdapter) model).getTagName();
081:            }
082:
083:            /**
084:             * Get the model component to which this object binds
085:             * @return
086:             */
087:            public String getSourcePath() {
088:                return srcPath;
089:            }
090:
091:            /**
092:             * Set the model path for the source data
093:             */
094:            public void setSourcePath(String newPath) {
095:                srcPath = newPath;
096:            }
097:
098:            /**
099:             * Set the model path for the output/state data
100:             */
101:            public void setOutputPath(String newPath) {
102:                outputPath = XModel.prefixOutputPath(newPath);
103:            }
104:
105:            /**
106:             * Get the model component to which this object binds
107:             * @return
108:             */
109:            public String getOutputPath() {
110:                return outputPath;
111:            }
112:
113:            /**
114:             * Set the source for this bindings's data
115:             * @param newNode the path to the data in the model
116:             */
117:            public void setSource(XModel newNode) {
118:                if (model.getModel() != newNode) {
119:                    model.setModel(newNode);
120:                    get();
121:                }
122:            }
123:
124:            /**
125:             * Set the output node where state data for this binding will be saved
126:             * @param newPath the path of the output/state node
127:             */
128:            public void setOutput(XModel newNode) {
129:                if ((outputNode == null) || !outputNode.equals(newNode)) {
130:                    outputNode = newNode;
131:                    if ((outputNode.get() == null)
132:                            && (comp.getModel().getChildCount(
133:                                    comp.getModel().getRoot()) > 0)) {
134:                        // Try selecting the previous selection
135:                        try {
136:                            String sel = getTreePath();
137:
138:                            // Split the selection path
139:                            Vector nodes = new Vector();
140:                            int pos = sel.indexOf('/');
141:                            int start = 0;
142:                            while (pos > 0) {
143:                                nodes.add(sel.substring(start, pos++));
144:                                start = pos;
145:                                pos = sel.indexOf('/', start);
146:                            }
147:                            nodes.add(sel.substring(start));
148:
149:                            if (nodes.size() > 0) {
150:                                Object nodeArray[] = nodes.toArray();
151:                                TreePath path = new TreePath(nodeArray);
152:                                comp.setSelectionPath(path);
153:                                comp.scrollPathToVisible(path);
154:                            }
155:                        } catch (Exception e) {
156:                        }
157:                    }
158:                }
159:            }
160:
161:            protected String getTreePath() {
162:                String pathName = null;
163:                if (comp.getSelectionPath() != null) {
164:                    Object path[] = comp.getSelectionPath().getPath();
165:
166:                    pathName = "";
167:                    for (int i = 1; i < path.length; i++) {
168:                        pathName += path[i].toString() + "/";
169:                    }
170:                    if (pathName.length() > 0)
171:                        pathName = pathName.substring(0, pathName.length() - 1);
172:                }
173:
174:                if (pathName == null)
175:                    return "";
176:                else if (pathName.trim().compareTo("") != 0)
177:                    return pathName;
178:                else
179:                    return "";
180:            }
181:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.