Source Code Cross Referenced for NSTree.java in  » Collaboration » JacORB » org » jacorb » naming » namemanager » 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 » Collaboration » JacORB » org.jacorb.naming.namemanager 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *        JacORB - a free Java ORB
003:         *
004:         *   Copyright (C) 1997-2004 Gerald Brose.
005:         *
006:         *   This library is free software; you can redistribute it and/or
007:         *   modify it under the terms of the GNU Library General Public
008:         *   License as published by the Free Software Foundation; either
009:         *   version 2 of the License, or (at your option) any later version.
010:         *
011:         *   This library is distributed in the hope that it will be useful,
012:         *   but WITHOUT ANY WARRANTY; without even the implied warranty of
013:         *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014:         *   Library General Public License for more details.
015:         *
016:         *   You should have received a copy of the GNU Library General Public
017:         *   License along with this library; if not, write to the Free
018:         *   Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
019:         */
020:
021:        package org.jacorb.naming.namemanager;
022:
023:        import java.awt.*;
024:        import javax.swing.tree.*;
025:        import javax.swing.event.*;
026:        import javax.swing.*;
027:        import org.omg.CosNaming.*;
028:        import org.omg.CosNaming.NamingContextPackage.*;
029:        import org.jacorb.naming.*;
030:
031:        /**
032:         *  @author Gerald Brose, FU Berlin/XTRADYNE Technologies AG
033:         *  @version $Id: NSTree.java,v 1.9 2004/05/06 12:39:59 nicolas Exp $
034:         */
035:
036:        public class NSTree extends JTree {
037:            public static final int MAX_BIND = 40;
038:            private NamingContextExt rootContext;
039:            private ContextNode rootNode;
040:            private Dimension size;
041:            private boolean created;
042:            private org.omg.CORBA.ORB orb;
043:
044:            public static NSTable nsTable;
045:
046:            public NSTree(int width, int height, NSTable theTable,
047:                    NamingContextExt rootCntxt, org.omg.CORBA.ORB orb) {
048:                this .orb = orb;
049:                DefaultMutableTreeNode root = new DefaultMutableTreeNode(
050:                        "RootContext");
051:                root.setAllowsChildren(true);
052:                setModel(new DefaultTreeModel(root, true));
053:                created = false;
054:                size = new Dimension(width, height);
055:                nsTable = theTable;
056:                rootContext = rootCntxt;
057:                ContextNode cn = new ContextNode(rootContext,
058:                        (DefaultTreeModel) getModel());
059:                cn.setNode(root);
060:                root.setUserObject(cn);
061:            }
062:
063:            /**
064:             * Bind a new name context and insert it
065:             */
066:
067:            public void bind(String name) throws NotFound, CannotProceed,
068:                    InvalidName, AlreadyBound {
069:                TreePath path = null;
070:                int length = 0;
071:                try {
072:                    path = getSelectionPath();
073:                    length = path.getPathCount();
074:                } catch (Exception e) {
075:                    JOptionPane.showMessageDialog(this , "Nothing selected",
076:                            "Selection error", JOptionPane.ERROR_MESSAGE);
077:                    return;
078:                }
079:
080:                DefaultMutableTreeNode node = (DefaultMutableTreeNode) getModel()
081:                        .getRoot();
082:                NamingContextExt context = rootContext;
083:
084:                if (length > 1) {
085:                    for (int i = 1; i < length; i++) {
086:                        node = (DefaultMutableTreeNode) path
087:                                .getPathComponent(i);
088:                        ContextNode bind = (ContextNode) node.getUserObject();
089:                        context = NamingContextExtHelper.narrow(context
090:                                .resolve(bind.getName()));
091:                        if (context == null) {
092:                            System.err.println("Naming context narrow failed!");
093:                            System.exit(1);
094:                        }
095:                    }
096:                }
097:                if (node.getAllowsChildren()) {
098:                    Name bindname = new Name(name);
099:                    if (context == null)
100:                        System.err.println("context null ");
101:
102:                    if (bindname.components() == null)
103:                        System.err.println("name is null ");
104:
105:                    context.bind_new_context(bindname.components());
106:                    update();
107:                } else {
108:                    JOptionPane.showMessageDialog(this ,
109:                            "Please select a naming context",
110:                            "Selection error", JOptionPane.ERROR_MESSAGE);
111:                }
112:            }
113:
114:            public void bindObject(String name, String ior, boolean isRebind)
115:                    throws NotFound, CannotProceed, InvalidName, AlreadyBound {
116:                TreePath path = null;
117:                int length = 0;
118:                try {
119:                    path = getSelectionPath();
120:                    length = path.getPathCount();
121:                } catch (Exception e) {
122:                    JOptionPane.showMessageDialog(this , "Nothing selected",
123:                            "Selection error", JOptionPane.ERROR_MESSAGE);
124:                    return;
125:                }
126:
127:                DefaultMutableTreeNode node = (DefaultMutableTreeNode) getModel()
128:                        .getRoot();
129:                NamingContextExt context = rootContext;
130:
131:                if (length > 1) {
132:                    for (int i = 1; i < length; i++) {
133:                        node = (DefaultMutableTreeNode) path
134:                                .getPathComponent(i);
135:                        ContextNode bind = (ContextNode) node.getUserObject();
136:                        context = NamingContextExtHelper.narrow(context
137:                                .resolve(bind.getName()));
138:                        if (context == null) {
139:                            System.err.println("Naming context narrow failed!");
140:                            System.exit(1);
141:                        }
142:                    }
143:                }
144:                if (node.getAllowsChildren()) {
145:                    Name bindname = new Name(name);
146:                    if (context == null)
147:                        System.err.println("context null ");
148:
149:                    if (bindname.components() == null)
150:                        System.err.println("name is null ");
151:
152:                    try {
153:                        context.bind(bindname.components(), orb
154:                                .string_to_object(ior));
155:                    } catch (AlreadyBound ab) {
156:                        if (isRebind)
157:                            context.rebind(bindname.components(), orb
158:                                    .string_to_object(ior));
159:                        else
160:                            throw ab;
161:                    }
162:                    update();
163:                } else {
164:                    JOptionPane.showMessageDialog(this ,
165:                            "Please select a naming context",
166:                            "Selection error", JOptionPane.ERROR_MESSAGE);
167:                }
168:            }
169:
170:            public Dimension getPreferredSize() {
171:                if (!created) {
172:                    created = true;
173:                    return size;
174:                } else
175:                    return super .getPreferredSize();
176:            }
177:
178:            /**
179:             * unbind a context and remove it from this tree
180:             */
181:
182:            public void unbind() {
183:                DefaultMutableTreeNode node;
184:                NamingContextExt context = rootContext;
185:                TreePath path = null;
186:                int length = 0;
187:                try {
188:                    path = getSelectionPath();
189:                    length = path.getPathCount();
190:                    if (length > 1) {
191:                        for (int i = 1; i < length - 1; i++) {
192:                            node = (DefaultMutableTreeNode) path
193:                                    .getPathComponent(i);
194:                            ContextNode bind = (ContextNode) node
195:                                    .getUserObject();
196:                            context = NamingContextExtHelper.narrow(context
197:                                    .resolve(bind.getName()));
198:                        }
199:                    }
200:
201:                    if (length > 0) {
202:                        node = (DefaultMutableTreeNode) path
203:                                .getPathComponent(length - 1);
204:                        ContextNode binding = (ContextNode) node
205:                                .getUserObject();
206:                        context.unbind(binding.getName());
207:                        DefaultTreeModel model = (DefaultTreeModel) getModel();
208:                        model.removeNodeFromParent(node);
209:
210:                        // select the parent node and display its content
211:                        DefaultMutableTreeNode parent = (DefaultMutableTreeNode) path
212:                                .getPathComponent(length - 2);
213:                        setSelectionPath(new TreePath(parent.getPath()));
214:                        ((ContextNode) parent.getUserObject()).display();
215:                    }
216:                } catch (Exception e) {
217:                    e.printStackTrace();
218:
219:                    JOptionPane.showMessageDialog(this ,
220:                            "Nothing selected or invalid selection",
221:                            "Selection error", JOptionPane.ERROR_MESSAGE);
222:                }
223:            }
224:
225:            /**
226:             * update the entire tree of contexts
227:             */
228:
229:            public synchronized void update() {
230:                DefaultTreeModel model = (DefaultTreeModel) getModel();
231:                ((ContextNode) ((DefaultMutableTreeNode) model.getRoot())
232:                        .getUserObject()).update();
233:                nsTable.update();
234:            }
235:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.