Source Code Cross Referenced for RouteDataEditor.java in  » XML-UI » xui32 » com » xoetrope » carousel » services » 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 » xui32 » com.xoetrope.carousel.services 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package com.xoetrope.carousel.services;
002:
003:        import com.xoetrope.carousel.services.dialog.NewRouteDlg;
004:        import java.util.Hashtable;
005:        import java.awt.event.ActionEvent;
006:        import java.awt.event.ActionListener;
007:        import java.awt.event.ItemEvent;
008:        import java.awt.event.ItemListener;
009:        import java.awt.event.MouseEvent;
010:        import java.awt.event.MouseListener;
011:        import javax.swing.JMenu;
012:        import javax.swing.JMenuItem;
013:        import javax.swing.JPopupMenu;
014:        import javax.swing.JScrollPane;
015:        import javax.swing.JSeparator;
016:        import javax.swing.JTable;
017:        import javax.swing.JTree;
018:        import javax.swing.event.TableModelEvent;
019:        import javax.swing.event.TableModelListener;
020:        import javax.swing.event.TreeModelEvent;
021:        import javax.swing.event.TreeModelListener;
022:        import javax.swing.event.TreeSelectionEvent;
023:        import javax.swing.event.TreeSelectionListener;
024:        import javax.swing.table.DefaultTableModel;
025:        import javax.swing.table.TableModel;
026:        import javax.swing.tree.DefaultMutableTreeNode;
027:        import javax.swing.tree.DefaultTreeModel;
028:        import javax.swing.tree.TreePath;
029:
030:        import com.xoetrope.carousel.services.events.RouteChangeListener;
031:        import com.xoetrope.carousel.services.table.RouteTableCellEditor;
032:        import java.io.File;
033:        import java.util.EventObject;
034:        import javax.swing.BorderFactory;
035:        import javax.swing.DefaultCellEditor;
036:        import javax.swing.JButton;
037:        import javax.swing.JOptionPane;
038:        import javax.swing.JTextField;
039:        import javax.swing.tree.DefaultTreeCellEditor;
040:        import javax.swing.tree.DefaultTreeCellRenderer;
041:        import javax.swing.tree.TreeCellEditor;
042:        import net.xoetrope.editor.project.XEditorProject;
043:        import net.xoetrope.editor.project.XEditorProjectManager;
044:        import net.xoetrope.editor.ui.KalideoscopeToolbar;
045:        import net.xoetrope.xui.data.XModelHelper;
046:        import net.xoetrope.xui.XProject;
047:        import net.xoetrope.xui.data.XBaseModel;
048:
049:        /**
050:         * JPanel which allows the user to edit the route data which is selected in the
051:         * JTree. As the tree and data is changed the route information is updated
052:         * automatically
053:         * Layers can have attributes which need to be editable. These are displayed
054:         * in a JTable
055:         * <p> Copyright (c) Xoetrope Ltd., 2001-2006, This software is licensed under
056:         * the GNU Public License (GPL), please see license.txt for more details. If
057:         * you make commercial use of this software you must purchase a commercial
058:         * license from Xoetrope.</p>
059:         * <p> $Revision: 1.17 $</p>
060:         */
061:        public class RouteDataEditor extends JScrollPane implements 
062:                ActionListener, TreeSelectionListener, ItemListener,
063:                MouseListener, TreeModelListener, TableModelListener {
064:            private RouteChangeListener routeChangeListener;
065:            private JTree routesTree;
066:            //private JComboBox cmbLayerType;
067:            private DefaultTableModel layerTableModel;
068:            private JTable tblLayerProperties;
069:            private JPopupMenu mnuRoutes, mnuLayers, mnuLayerItem;
070:
071:            // strings which will be used as menu items
072:            public static final String MNU_NEW_ROUTE = "New Route";
073:            public static final String MNU_DELETE_ROUTE = "Delete Route";
074:            public static final String RENAME_ROUTE = "Rename";
075:
076:            public static final String MNU_NEW_LAYER = "New ServiceProxy Layer";
077:            public static final String MNU_DELETE_LAYER = "Delete ServiceProxy Layer";
078:            public static final String MNU_LAYER_MOVEUP = "Move Up";
079:            public static final String MNU_LAYER_MOVEDOWN = "Move Down";
080:            public static final String MNU_CREATE_LAYER = "CreateLayer";
081:
082:            public static final int LEVEL_BASE = 1;
083:            public static final int LEVEL_SPLIT = 2;
084:            public static final int LEVEL_ROUTE = 3;
085:            public static final int LEVEL_SERVICELAYER = 4;
086:
087:            public static final int SIDE_CLIENT = 1;
088:            public static final int SIDE_SERVER = 2;
089:
090:            private int selectedSide = 0;
091:
092:            // the route name which is stored when the TreeNode is clicked or changed.
093:            private String selectedRouteName;
094:
095:            // the layer name which is stored when the TreeNode is clicked or changed.
096:            private String selectedLayerName;
097:
098:            private boolean tableLoading = false;
099:            private RouteManager routeManager;
100:            private KalideoscopeToolbar toolbar;
101:            private RouteEditor routeEditor;
102:
103:            private JButton refreshTool, newTool, deleteTool, renameTool,
104:                    moveupTool;
105:            private JButton movedownTool, createLayer, extendLayer;
106:            private JMenuItem mnuMoveUp, mnuMoveDown;
107:            JMenu mnuNew;
108:
109:            /**
110:             * The owner project and the context in which this object operates.
111:             */
112:            protected XEditorProject currentProject = (XEditorProject) XEditorProjectManager
113:                    .getCurrentProject();
114:
115:            /**
116:             * Holds a table for editing routes.
117:             */
118:            public RouteDataEditor(XProject proj, RouteEditor editor,
119:                    KalideoscopeToolbar tools, KalideoscopeToolbar layerTools) {
120:                routeManager = (RouteManager) currentProject
121:                        .getObject(ProjectRouteManager.ROUTE_MGR_LOOKUP);
122:                routeEditor = editor;
123:                setBorder(BorderFactory.createEmptyBorder());
124:
125:                toolbar = tools;
126:                refreshTool = toolbar.addTool(this , "refresh.gif", "Refresh",
127:                        "Refresh this view of the routes");
128:                toolbar.addSeparator();
129:                newTool = toolbar.addTool(this , "newLayer.gif", MNU_NEW_LAYER,
130:                        "Add a new ServiceProxy layer to the routing stack");
131:                deleteTool = toolbar
132:                        .addTool(this , "deleteLayer.gif", MNU_DELETE_LAYER,
133:                                "Remove the selected ServiceProxy layer from the routing stack");
134:                toolbar.addSeparator();
135:                renameTool = toolbar.addTool(this , "renameRoute.gif",
136:                        RENAME_ROUTE, "Rename the route...");
137:                toolbar.addSeparator();
138:                moveupTool = toolbar.addTool(this , "moveUp.gif",
139:                        MNU_LAYER_MOVEUP,
140:                        "Move the selected ServiceProxy layer up in the stack");
141:                movedownTool = toolbar
142:                        .addTool(this , "moveDown.gif", MNU_LAYER_MOVEDOWN,
143:                                "Move the selected ServiceProxy layer down in the stack");
144:                toolbar.addSeparator();
145:                createLayer = toolbar.addTool(this , "newService.gif",
146:                        MNU_CREATE_LAYER, "Create a custom ServiceProxy layer");
147:
148:                layerTableModel = new DefaultTableModel();
149:                layerTableModel.addColumn("Attribute");
150:                layerTableModel.addColumn("Value");
151:                tblLayerProperties = new JTable(layerTableModel);
152:                tblLayerProperties.setBorder(BorderFactory.createEmptyBorder());
153:                tblLayerProperties.getModel().addTableModelListener(this );
154:                tblLayerProperties.setDefaultEditor(Object.class,
155:                        new RouteTableCellEditor(new JTextField()));
156:                getViewport().removeAll();
157:                getViewport().add(tblLayerProperties);
158:
159:                createPopupMenus();
160:                setToolbarEnabled(LEVEL_BASE);
161:                loadCustomRouteFile();
162:            }
163:
164:            /**
165:             * Create the popup menus which will be displayed when the JTree is right
166:             * clicked. Use constants which can be used when the events are triggered.
167:             */
168:            private void createPopupMenus() {
169:                mnuRoutes = new JPopupMenu();
170:                mnuRoutes.add(createMenuItem(MNU_NEW_ROUTE));
171:
172:                mnuLayers = new JPopupMenu();
173:                mnuNew = new JMenu(MNU_NEW_LAYER);
174:
175:                XBaseModel table = routeManager.getRouteDefs();
176:                for (int i = 0; i < table.getNumChildren(); i++) {
177:                    XBaseModel route = (XBaseModel) table.get(i);
178:                    mnuNew.add(createMenuItem(route.getId()));
179:                }
180:                mnuLayers.add(mnuNew);
181:                mnuLayers.add(new JSeparator());
182:                mnuLayers.add(createMenuItem(MNU_DELETE_ROUTE));
183:
184:                mnuLayerItem = new JPopupMenu();
185:                mnuMoveUp = createMenuItem(MNU_LAYER_MOVEUP);
186:                mnuLayerItem.add(mnuMoveUp);
187:                mnuMoveDown = createMenuItem(MNU_LAYER_MOVEDOWN);
188:                mnuLayerItem.add(mnuMoveDown);
189:                mnuLayerItem.add(createMenuItem(MNU_DELETE_LAYER));
190:            }
191:
192:            public void treeStructureChanged(TreeModelEvent evt) {
193:            }
194:
195:            public void treeNodesRemoved(TreeModelEvent evt) {
196:            }
197:
198:            public void treeNodesInserted(TreeModelEvent evt) {
199:            }
200:
201:            /**
202:             * Determine whether the currently selected node in under the 'Client' or the
203:             * 'Server' node and set the selectedSide class variable accordingly
204:             */
205:            private void getSide() {
206:                TreePath path = routesTree.getSelectionPath().getParentPath();
207:                String side = path.getLastPathComponent().toString();
208:                while ((side.compareTo("Client") != 0)
209:                        && (side.compareTo("Server") != 0)) {
210:                    path = path.getParentPath();
211:                    side = path.getLastPathComponent().toString();
212:                }
213:                if (side.compareTo("Client") == 0) {
214:                    selectedSide = SIDE_CLIENT;
215:                } else {
216:                    selectedSide = SIDE_SERVER;
217:                }
218:            }
219:
220:            /**
221:             * As the tree is editable, we need to find the route which is selected and
222:             * set it to the new name.
223:             * @param evt
224:             */
225:            public void treeNodesChanged(TreeModelEvent evt) {
226:                if (evt.getChildren() == null) {
227:                } else {
228:                    String currentNode = evt.getChildren()[0].toString();
229:                    switch (routesTree.getSelectionPath().getPathCount()) {
230:                    case LEVEL_BASE:
231:                        break;
232:                    case LEVEL_ROUTE:
233:                        routeManager.changeServerRouteName(selectedSide,
234:                                selectedRouteName, currentNode);
235:                        selectedRouteName = currentNode;
236:                        setProjectModified();
237:                        break;
238:                    case LEVEL_SERVICELAYER: // We're working with a layer node
239:                        DefaultMutableTreeNode nod = (DefaultMutableTreeNode) routesTree
240:                                .getSelectionPath().getLastPathComponent();
241:                        nod.setUserObject(selectedLayerName);
242:                    }
243:                }
244:            }
245:
246:            /**
247:             * Layers can have attributes which need to be editable. These are displayed
248:             * in the JTable. We need to iterate the layers Hashtable which is found in
249:             * the routes Hashtable in the XLibPlugRouteManager.
250:             * @param evt the TableModelEvent
251:             */
252:            public void tableChanged(TableModelEvent evt) {
253:                DefaultMutableTreeNode nod = (DefaultMutableTreeNode) routesTree
254:                        .getSelectionPath().getLastPathComponent();
255:                DefaultMutableTreeNode parentNod = (DefaultMutableTreeNode) nod
256:                        .getParent();
257:                XBaseModel routeMdl = routeManager.getRoutes(selectedSide);
258:                XBaseModel layers = (XBaseModel) routeMdl.get(parentNod
259:                        .toString());
260:                for (int i = 0; i < layers.getNumChildren(); i++) {
261:                    XBaseModel child = (XBaseModel) layers.get(i);
262:                    String layerName = child.getId();
263:                    if (layerName.compareTo(selectedLayerName) == 0) {
264:                        //Hashtable newLayer = new Hashtable();
265:                        //newLayer.put( "class", selectedLayerName );
266:                        TableModel tableModel = tblLayerProperties.getModel();
267:                        for (int attribs = 0; attribs < tableModel
268:                                .getRowCount(); attribs++) {
269:                            if (tableModel.getValueAt(attribs, 1) != null)
270:                                XModelHelper.setAttrib(child,
271:                                        (String) tableModel.getValueAt(attribs,
272:                                                0), (String) tableModel
273:                                                .getValueAt(attribs, 1));
274:                        }
275:                    }
276:                }
277:            }
278:
279:            /**
280:             * Create and return a JMenuItem with the passed caption
281:             * @param caption The caption to be used in the new menu
282:             */
283:            private JMenuItem createMenuItem(String caption) {
284:                JMenuItem item = new JMenuItem(caption);
285:                item.addActionListener(this );
286:                return item;
287:            }
288:
289:            /**
290:             * Set the RouteChangeListener interface for updates about route changes
291:             * @param listener the interested RouteChanceListener
292:             */
293:            public void setRouteChangeListener(RouteChangeListener listener) {
294:                routeChangeListener = listener;
295:            }
296:
297:            /**
298:             */
299:            private void addLayerType(String layerName) {
300:                mnuNew.add(createMenuItem(layerName));
301:            }
302:
303:            public void loadCustomRouteFile() {
304:                String customRouteFile = currentProject.getObject(
305:                        "CustomRouteDefs").toString();
306:                if ((customRouteFile != null) && (customRouteFile.length() > 0)) {
307:                    File file = new File(currentProject.getPath()
308:                            + File.separator + customRouteFile);
309:                    routeManager.createCustomRouteDefs();
310:                    if (file.exists()) {
311:                        routeManager.openCustomRouteDefs(file);
312:                        XBaseModel customMdl = routeManager.getCustomRoutes();
313:                        for (int i = 0; i < customMdl.getNumChildren(); i++) {
314:                            XBaseModel child = (XBaseModel) customMdl.get(i);
315:                            addLayerType(child.getId());
316:                        }
317:                    }
318:                }
319:            }
320:
321:            private void setProjectModified() {
322:                currentProject.setModified(true);
323:            }
324:
325:            /**
326:             * Process menu and tool button events
327:             */
328:            public void actionPerformed(ActionEvent evt) {
329:                String command = evt.getActionCommand();
330:                if (command.compareTo("Refresh") == 0) {
331:                    routeEditor.createTree();
332:                    setToolbarEnabled(LEVEL_BASE);
333:                } else if (command.compareTo(MNU_DELETE_ROUTE) == 0) {
334:                    if (selectedRouteName != null) {
335:                        routeManager.removeRoute(selectedRouteName,
336:                                selectedSide);
337:                        routeEditor.createTree();
338:                        setProjectModified();
339:                        setToolbarEnabled(LEVEL_BASE);
340:                    }
341:                } else if (command.equals(MNU_NEW_ROUTE)) {
342:                    insertChildNode(MNU_NEW_ROUTE);
343:                    Hashtable[] layers = new Hashtable[0];
344:                    routeManager.addRoute(MNU_NEW_ROUTE, layers);
345:                    setProjectModified();
346:                } else if (command.compareTo(MNU_CREATE_LAYER) == 0) {
347:                    createNewLayer(false, null);
348:                } else if (command.equals(RENAME_ROUTE)) {
349:                    if (selectedRouteName != null) {
350:                        String name = JOptionPane.showInputDialog(this ,
351:                                "Rename the route: " + selectedRouteName,
352:                                "Enter the new route name",
353:                                JOptionPane.OK_CANCEL_OPTION);
354:                        if (name != null) {
355:                            XBaseModel routeMdl = (XBaseModel) routeManager
356:                                    .getRoutes(selectedSide).get(
357:                                            selectedRouteName);
358:                            routeMdl.setId(name);
359:                            routeEditor.createTree();
360:                            setProjectModified();
361:                        }
362:                    }
363:                } else if (command.equals(MNU_LAYER_MOVEUP)) {
364:                    moveLayerUp();
365:                } else if (command.equals(MNU_LAYER_MOVEDOWN)) {
366:                    moveLayerDown();
367:                } else if (command.equals(MNU_DELETE_LAYER)) {
368:                    XBaseModel layer = (XBaseModel) routeManager.getRoutes(
369:                            selectedSide).get(
370:                            selectedRouteName + "/" + selectedLayerName);
371:                    ((XBaseModel) layer.getParent()).remove(layer);
372:                    routeEditor.createTree();
373:                    setProjectModified();
374:                } else if (evt.getSource() instanceof  JMenuItem) {
375:                    boolean exists = false;
376:                    if (!exists) {
377:                        XBaseModel layerDef = (XBaseModel) routeManager
378:                                .getRouteDefs().get(evt.getActionCommand());
379:                        String layerType = XModelHelper.getAttrib(layerDef,
380:                                "type");
381:                        if ((layerType != null)
382:                                && (layerType.compareTo("abstract") == 0)) {
383:                            command = createNewLayer(true, command);
384:                        }
385:                        if (command != null) {
386:                            insertChildNode(command);
387:                            routeManager.createRouteLayer(selectedRouteName,
388:                                    command, selectedSide);
389:                            setProjectModified();
390:                        }
391:                    } else {
392:                        showError("The '" + command
393:                                + "' service already exists in this route!");
394:                    }
395:                }
396:            }
397:
398:            /**
399:             * Check that the layer below this layer is not a 'clientEndPoint' layer.
400:             */
401:            private void moveLayerDown() {
402:                if ((selectedRouteName != null) && (selectedLayerName != null)) {
403:                    boolean error = false;
404:                    XBaseModel routeMdl = (XBaseModel) routeManager.getRoutes(
405:                            selectedSide).get(selectedRouteName);
406:                    XBaseModel layerMdl = (XBaseModel) routeMdl
407:                            .get(selectedLayerName);
408:                    int pos = XModelHelper.getPositionInModel(layerMdl);
409:                    if ((routeMdl.getNumChildren() - 1) > pos) {
410:                        XBaseModel nextLayer = (XBaseModel) routeMdl
411:                                .get(pos + 1);
412:                        String nextLayerType = XModelHelper.getAttrib(
413:                                nextLayer, "class");
414:                        XBaseModel layerDef = (XBaseModel) routeManager
415:                                .getRouteDefs().get(nextLayerType);
416:                        String layerType = XModelHelper.getAttrib(layerDef,
417:                                "type");
418:                        if ((layerType != null)
419:                                && (layerType.compareTo("clientEndPoint") == 0)) {
420:                            showError("The '"
421:                                    + nextLayerType
422:                                    + "' ServiceProxy layer is an endpoint and can only exist at the end of a route!");
423:                            error = true;
424:                        }
425:                    }
426:                    if (!error) {
427:                        routeManager.moveLayer(selectedRouteName,
428:                                selectedLayerName, false,
429:                                (selectedSide == SIDE_SERVER));
430:                        routeEditor.createTree();
431:                        setProjectModified();
432:                    }
433:                }
434:            }
435:
436:            private void moveLayerUp() {
437:                if ((selectedRouteName != null) && (selectedLayerName != null)) {
438:                    XBaseModel layerDef = (XBaseModel) routeManager
439:                            .getRouteDefs().get(selectedLayerName);
440:                    String layerType = XModelHelper.getAttrib(layerDef, "type");
441:                    if ((layerType != null)
442:                            && (layerType.compareTo("clientEndPoint") == 0)) {
443:                        showError("The '"
444:                                + selectedLayerName
445:                                + "' ServiceProxy layer is an endpoint and can only exist at the end of a route!");
446:                    } else {
447:                        routeManager.moveLayer(selectedRouteName,
448:                                selectedLayerName, true,
449:                                (selectedSide == SIDE_SERVER));
450:                        routeEditor.createTree();
451:                        setProjectModified();
452:                    }
453:                }
454:            }
455:
456:            private String createNewLayer(boolean isAbstract, String baseClass) {
457:                String customRouteFile = currentProject.getObject(
458:                        "CustomRouteDefs").toString();
459:                if (customRouteFile != null) {
460:                    NewRouteDlg dlg = new NewRouteDlg();
461:                    if (dlg.setupNewRoute(routeManager, baseClass)) {
462:                        String newClass = dlg.getNewClassName();
463:                        baseClass = dlg.getBaseClass();
464:                        String[] attribs = dlg.getAttribs();
465:                        String type = dlg.getClassType();
466:                        routeManager.addCustomRouteService(newClass, baseClass,
467:                                attribs);
468:                        addLayerType(newClass);
469:                        setProjectModified();
470:                    }
471:                } else {
472:                    showError("Please set the 'CustomRouteDefs' property in the project screen before proceeding!");
473:                }
474:
475:                return null;
476:            }
477:
478:            private void showError(String msg) {
479:                JOptionPane dlg = new JOptionPane();
480:                dlg.showMessageDialog(this , msg);
481:            }
482:
483:            private int getPosInRoute(String selectedRouteName, String layerName) {
484:                XBaseModel routeMdl = routeManager.getRoutes(selectedSide);
485:                XBaseModel layerMdl = (XBaseModel) routeMdl
486:                        .get(selectedRouteName + "/" + layerName);
487:                return XModelHelper.getPositionInModel(layerMdl);
488:            }
489:
490:            private void insertChildNode(String text) {
491:                DefaultTreeModel treemodel = (DefaultTreeModel) routesTree
492:                        .getModel();
493:                DefaultMutableTreeNode nodParent = (DefaultMutableTreeNode) routesTree
494:                        .getSelectionPath().getLastPathComponent();
495:                DefaultMutableTreeNode nodChild = new DefaultMutableTreeNode(
496:                        text);
497:                treemodel.insertNodeInto(nodChild, nodParent, nodParent
498:                        .getChildCount());
499:            }
500:
501:            public void itemStateChanged(ItemEvent evt) {
502:
503:            }
504:
505:            public void selectLayer(String selectedLayer) {
506:                XBaseModel currentLayer = null;
507:                if (routesTree != null && routesTree.getSelectionPath() != null) {
508:                    DefaultMutableTreeNode nod = (DefaultMutableTreeNode) routesTree
509:                            .getSelectionPath().getLastPathComponent();
510:                    DefaultMutableTreeNode parentNod = (DefaultMutableTreeNode) nod
511:                            .getParent();
512:                    String newLayerName = (selectedLayer);
513:                    nod.setUserObject(newLayerName);
514:                    routesTree.repaint();
515:                    XBaseModel layers = (XBaseModel) routeManager.getRoutes(
516:                            selectedSide).get(parentNod.toString());
517:                    for (int i = 0; i < layers.getNumChildren(); i++) {
518:                        XBaseModel child = (XBaseModel) layers.get(i);
519:                        String layerName = child.getId();
520:                        if (layerName.compareTo(selectedLayer) == 0) {
521:                            currentLayer = child;
522:                        }
523:                    }
524:
525:                    if (!tableLoading) { // Only create a new one if the list was explicitly clicked.
526:                        for (int i = 0; i < layers.getNumChildren(); i++) {
527:                            XBaseModel child = (XBaseModel) layers.get(i);
528:                            String layerName = child.getId();
529:                            if (layerName.compareTo(selectedLayerName) == 0) {
530:                                currentLayer = child;
531:                                Hashtable newLayer = new Hashtable();
532:                                newLayer.put("class", newLayerName);
533:                                TableModel tableModel = tblLayerProperties
534:                                        .getModel();
535:                                for (int attribs = 0; attribs < tableModel
536:                                        .getRowCount(); attribs++) {
537:                                    Object value = tableModel.getValueAt(
538:                                            attribs, 1);
539:                                    newLayer.put(tableModel.getValueAt(attribs,
540:                                            0), value == null ? "" : value
541:                                            .toString());
542:                                }
543:                                currentLayer = child;
544:                            }
545:                        }
546:                    }
547:                    selectedLayerName = newLayerName;
548:                }
549:
550:                tblLayerProperties.getModel().removeTableModelListener(this );
551:                layerTableModel.setNumRows(0);
552:                tblLayerProperties.getModel().addTableModelListener(this );
553:                XBaseModel table = routeManager.getRouteDefs();
554:                XBaseModel targetMdl = (XBaseModel) table.get(selectedLayer
555:                        + "/attribs");
556:                for (int i = 0; i < targetMdl.getNumChildren(); i++) {
557:                    XBaseModel route = (XBaseModel) targetMdl.get(i);
558:                    Object value = "";
559:                    if (currentLayer != null)
560:                        value = XModelHelper.getAttrib(currentLayer, route
561:                                .getId());
562:                    addLayerProperty(route.getId(), value);
563:                }
564:            }
565:
566:            private void addLayerProperty(String name, Object value) {
567:                String[] rowData = { name, (String) value };
568:                tblLayerProperties.getModel().removeTableModelListener(this );
569:                layerTableModel.addRow(rowData);
570:                tblLayerProperties.getModel().addTableModelListener(this );
571:            }
572:
573:            void setRouteTree(JTree tree) {
574:                routesTree = tree;
575:                routesTree.getModel().addTreeModelListener(this );
576:                routesTree.addTreeSelectionListener(this );
577:                routesTree.addMouseListener(this );
578:                CustomCellEditor cedit = new CustomCellEditor(
579:                        routesTree,
580:                        (DefaultTreeCellRenderer) routesTree.getCellRenderer(),
581:                        (TreeCellEditor) new DefaultCellEditor(new JTextField()));
582:                routesTree.setCellEditor(cedit);
583:            }
584:
585:            public void valueChanged(TreeSelectionEvent evt) {
586:                TreePath[] path = evt.getPaths();
587:                int level = evt.getPath().getPathCount();
588:                setToolbarEnabled(level);
589:                switch (level) {
590:                case LEVEL_BASE:
591:                    break;
592:                case LEVEL_ROUTE:
593:                    getSide();
594:                    selectedRouteName = evt.getPath().getLastPathComponent()
595:                            .toString();
596:                    break;
597:                case LEVEL_SERVICELAYER:
598:                    getSide();
599:                    selectedLayerName = evt.getPath().getLastPathComponent()
600:                            .toString();
601:                    selectedRouteName = evt.getPath().getParentPath()
602:                            .getLastPathComponent().toString();
603:                    int pos = 0;
604:                    int layerLength = 0;
605:                    pos = getPosInRoute(selectedRouteName, selectedLayerName);
606:                    XBaseModel routeMdl = (XBaseModel) routeManager.getRoutes(
607:                            selectedSide).get(selectedRouteName);
608:                    layerLength = routeMdl.getNumChildren();
609:                    moveupTool.setEnabled(pos != 0);
610:                    mnuMoveUp.setEnabled(moveupTool.isEnabled());
611:                    movedownTool.setEnabled(layerLength != (pos + 1));
612:                    mnuMoveDown.setEnabled(movedownTool.isEnabled());
613:                    setLayer(evt);
614:                    break;
615:                }
616:            }
617:
618:            private void setToolbarEnabled(int level) {
619:                refreshTool.setEnabled(true);
620:                newTool.setEnabled(false);
621:                deleteTool.setEnabled(false);
622:                renameTool.setEnabled(false);
623:                moveupTool.setEnabled(false);
624:                movedownTool.setEnabled(false);
625:                switch (level) {
626:                case LEVEL_BASE:
627:                    tblLayerProperties.getModel()
628:                            .removeTableModelListener(this );
629:                    layerTableModel.setNumRows(0);
630:                    tblLayerProperties.getModel().addTableModelListener(this );
631:                    break;
632:                case LEVEL_SPLIT:
633:                    tblLayerProperties.getModel()
634:                            .removeTableModelListener(this );
635:                    layerTableModel.setNumRows(0);
636:                    tblLayerProperties.getModel().addTableModelListener(this );
637:                    break;
638:                case LEVEL_ROUTE:
639:                    newTool.setEnabled(true);
640:                    tblLayerProperties.getModel()
641:                            .removeTableModelListener(this );
642:                    layerTableModel.setNumRows(0);
643:                    tblLayerProperties.getModel().addTableModelListener(this );
644:                    renameTool.setEnabled(true);
645:                    break;
646:                case LEVEL_SERVICELAYER:
647:                    deleteTool.setEnabled(true);
648:                    moveupTool.setEnabled(true);
649:                    movedownTool.setEnabled(true);
650:                    break;
651:                }
652:            }
653:
654:            private void setLayer(TreeSelectionEvent evt) {
655:                String className = evt.getPath().getLastPathComponent()
656:                        .toString();
657:                String routeName = evt.getPath().getParentPath()
658:                        .getLastPathComponent().toString();
659:
660:                tableLoading = true;
661:                selectLayer(className);
662:                tableLoading = false;
663:            }
664:
665:            private void saveRoute() {
666:                Hashtable[] layers = { null };
667:                routeChangeListener.routesUpdated();
668:            }
669:
670:            private String getTreePath() {
671:                String modelName = null;
672:                if (routesTree.getSelectionPath() != null) {
673:                    Object path[] = routesTree.getSelectionPath().getPath();
674:
675:                    modelName = "";
676:                    for (int i = 1; i < path.length; i++) {
677:                        modelName += "/" + path[i].toString();
678:                    }
679:                }
680:                if (modelName == null)
681:                    return "";
682:                else if (modelName.trim().compareTo("") != 0)
683:                    return modelName.substring(1);
684:                else
685:                    return "";
686:            }
687:
688:            public String getCustomRouteFile() {
689:                return currentProject.getPath()
690:                        + File.separator
691:                        + currentProject.getObject("CustomRouteDefs")
692:                                .toString();
693:            }
694:
695:            public void mouseExited(MouseEvent evt) {
696:            }
697:
698:            public void mouseEntered(MouseEvent evt) {
699:            }
700:
701:            public void mouseReleased(MouseEvent evt) {
702:            }
703:
704:            public void mouseClicked(MouseEvent evt) {
705:            }
706:
707:            public void mousePressed(MouseEvent evt) {
708:                if ((evt.getButton() == evt.BUTTON3)
709:                        && (routesTree.getSelectionPath() != null)) {
710:                    switch (routesTree.getSelectionPath().getPathCount()) {
711:                    case LEVEL_SPLIT:
712:                        mnuRoutes.show(routesTree, evt.getX(), evt.getY());
713:                        break;
714:                    case LEVEL_ROUTE:
715:                        mnuLayers.show(routesTree, evt.getX(), evt.getY());
716:                        break;
717:                    case LEVEL_SERVICELAYER:
718:                        mnuLayerItem.show(routesTree, evt.getX(), evt.getY());
719:                        break;
720:                    }
721:                }
722:            }
723:
724:            class CustomCellEditor extends DefaultTreeCellEditor {
725:
726:                public CustomCellEditor(JTree tree,
727:                        DefaultTreeCellRenderer renderer, TreeCellEditor editor) {
728:                    super (tree, renderer, editor);
729:                }
730:
731:                protected boolean canEditImmediately(EventObject event) {
732:                    int level = routesTree.getSelectionPath().getPathCount();
733:                    if (level == LEVEL_ROUTE)
734:                        return true;
735:                    else
736:                        return false;
737:                }
738:            }
739:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.