Source Code Cross Referenced for WorkspaceNavigator.java in  » Workflow-Engines » OSWorkflow » com » opensymphony » workflow » designer » 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 » Workflow Engines » OSWorkflow » com.opensymphony.workflow.designer 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package com.opensymphony.workflow.designer;
002:
003:        import java.util.List;
004:        import java.util.*;
005:        import java.awt.*;
006:        import java.awt.event.MouseEvent;
007:        import java.awt.event.MouseAdapter;
008:        import java.net.MalformedURLException;
009:        import java.io.File;
010:        import javax.swing.*;
011:        import javax.swing.event.*;
012:        import javax.swing.tree.*;
013:
014:        import com.opensymphony.workflow.loader.*;
015:        import com.opensymphony.workflow.FactoryException;
016:        import com.opensymphony.workflow.designer.swing.FileDropHandler;
017:        import com.opensymphony.workflow.designer.actions.AssignPalette;
018:        import com.opensymphony.workflow.designer.actions.DeleteWorkflow;
019:        import com.opensymphony.workflow.designer.actions.ImportWorkflow;
020:
021:        /**
022:         * @author Hani Suleiman (hani@formicary.net)
023:         *         Date: May 15, 2003
024:         *         Time: 8:56:07 PM
025:         */
026:        public class WorkspaceNavigator extends JTree implements 
027:                TreeSelectionListener, TreeModelListener {
028:            private WorkflowDesigner designer;
029:            private DefaultMutableTreeNode rootNode;
030:            private String currentWorkflow;
031:            private WorkflowFactory currentWorkspace = null;
032:            private DefaultTreeCellRenderer cellRenderer = new WorkspaceCellRenderer();
033:
034:            private JPopupMenu popup;
035:            private DeleteWorkflow deleteWorkflow;
036:            private AssignPalette assignPalette;
037:
038:            public WorkspaceNavigator(WorkflowDesigner designer) {
039:                super (new DefaultTreeModel(new DefaultMutableTreeNode(
040:                        ResourceManager.getString("workspace.none"))));
041:                rootNode = (DefaultMutableTreeNode) getModel().getRoot();
042:                this .designer = designer;
043:                addTreeSelectionListener(this );
044:                setEditable(false);
045:                getSelectionModel().setSelectionMode(
046:                        TreeSelectionModel.SINGLE_TREE_SELECTION);
047:                setShowsRootHandles(true);
048:                setCellRenderer(cellRenderer);
049:                getModel().addTreeModelListener(this );
050:
051:                popup = new JPopupMenu();
052:                popup.setInvoker(this );
053:                //this is kinda a hack, since we assume that importworkflow has already been registered
054:                //(which it has, but only because the toolbar is created before the nav, so a bit fragile
055:                deleteWorkflow = new DeleteWorkflow(designer);
056:                assignPalette = new AssignPalette(designer);
057:                popup.add(new JMenuItem(ActionManager.register("deleteflow",
058:                        deleteWorkflow)));
059:                ActionManager.register("assign.palette", assignPalette);
060:                assignPalette.setEnabled(false);
061:                popup.add(new JMenuItem(assignPalette));
062:
063:                addMouseListener(new MouseAdapter() {
064:                    public void mousePressed(MouseEvent e) {
065:                        handlePopup(e);
066:                    }
067:
068:                    public void mouseReleased(MouseEvent e) {
069:                        handlePopup(e);
070:                    }
071:
072:                    private void handlePopup(MouseEvent e) {
073:                        if (e.isPopupTrigger()) {
074:                            int row = getRowForLocation(e.getX(), e.getY());
075:                            if (row != -1) {
076:                                TreePath path = getPathForRow(row);
077:                                if (path.getPathCount() != 2)
078:                                    return;
079:                                String workflowName = path
080:                                        .getLastPathComponent().toString();
081:                                Point p = new Point(e.getX(), e.getY());
082:                                SwingUtilities.convertPointToScreen(p,
083:                                        WorkspaceNavigator.this );
084:                                deleteWorkflow.setWorkflow(workflowName);
085:                                assignPalette.setWorkflow(workflowName);
086:                                popup.setLocation(p.x, p.y);
087:                                popup.setVisible(true);
088:                            }
089:                        }
090:                    }
091:                });
092:
093:                new FileDropHandler(this , true) {
094:                    public void filesDropped(File[] files) {
095:                        for (int i = 0; i < files.length; i++) {
096:                            File file = files[i];
097:                            if (file.getName().endsWith(".xml")
098:                                    && !file.isDirectory()) {
099:                                try {
100:                                    ((ImportWorkflow) ActionManager
101:                                            .get("importflow")).importURL(file
102:                                            .toURL());
103:                                } catch (MalformedURLException e) {
104:                                    e.printStackTrace();
105:                                }
106:                            }
107:                        }
108:                    }
109:                };
110:            }
111:
112:            public void selectWorkflow(String name) {
113:                Object root = getModel().getRoot();
114:                int count = getModel().getChildCount(root);
115:                for (int i = 0; i < count; i++) {
116:                    DefaultMutableTreeNode node = (DefaultMutableTreeNode) getModel()
117:                            .getChild(root, i);
118:                    if (node.getUserObject() instanceof  WorkflowDescriptor) {
119:                        WorkflowDescriptor desc = (WorkflowDescriptor) node
120:                                .getUserObject();
121:                        if (desc.getName().equals(name)) {
122:                            designer.selectWorkflow(name);
123:
124:                            TreePath path = new TreePath(new Object[] { root,
125:                                    node });
126:                            getSelectionModel().setSelectionPath(path);
127:                            expandPath(path);
128:                            return;
129:                        }
130:                    }
131:                }
132:            }
133:
134:            public void removeWorkflow(String name) {
135:                Object root = getModel().getRoot();
136:                DefaultTreeModel model = (DefaultTreeModel) getModel();
137:                int count = model.getChildCount(root);
138:                for (int i = 0; i < count; i++) {
139:                    DefaultMutableTreeNode node = (DefaultMutableTreeNode) model
140:                            .getChild(root, i);
141:                    if (node.getUserObject() instanceof  WorkflowDescriptor) {
142:                        WorkflowDescriptor workflow = (WorkflowDescriptor) node
143:                                .getUserObject();
144:                        if (workflow.getName().equals(name)) {
145:                            model.removeNodeFromParent(node);
146:                            return;
147:                        }
148:                    }
149:                }
150:            }
151:
152:            public void valueChanged(TreeSelectionEvent e) {
153:                DefaultMutableTreeNode node = (DefaultMutableTreeNode) getLastSelectedPathComponent();
154:                if (node == null)
155:                    return;
156:                designer.showDetails(node.getUserObject());
157:                Object user = node.getUserObject();
158:                if (user instanceof  AbstractDescriptor) {
159:                    if (user instanceof  WorkflowDescriptor) {
160:                        designer.selectWorkflow(((WorkflowDescriptor) user)
161:                                .getName());
162:                    } else if (user instanceof  ResultDescriptor) {
163:                        // select the current workflow
164:                        TreeNode[] nodes = node.getPath();
165:                        if (nodes.length > 2) {
166:                            DefaultMutableTreeNode workflowNode = (DefaultMutableTreeNode) nodes[1];
167:                            if (workflowNode.getUserObject() instanceof  WorkflowDescriptor) {
168:                                designer
169:                                        .selectWorkflow(((WorkflowDescriptor) workflowNode
170:                                                .getUserObject()).getName());
171:                            }
172:                        }
173:                        designer.selectCell((AbstractDescriptor) user);
174:                    } else {
175:                        AbstractDescriptor parentDescriptor = ((AbstractDescriptor) user)
176:                                .getParent();
177:                        if (parentDescriptor instanceof  WorkflowDescriptor) {
178:                            designer
179:                                    .selectWorkflow(((WorkflowDescriptor) parentDescriptor)
180:                                            .getName());
181:                            designer.selectCell((AbstractDescriptor) user);
182:                        }
183:                    }
184:                }
185:            }
186:
187:            public void treeNodesChanged(TreeModelEvent e) {
188:                DefaultMutableTreeNode node;
189:                node = (DefaultMutableTreeNode) (e.getTreePath()
190:                        .getLastPathComponent());
191:                /*
192:                 * If the event lists children, then the changed
193:                 * node is the child of the node we've already
194:                 * gotten.  Otherwise, the changed node and the
195:                 * specified node are the same.
196:                 */
197:                try {
198:                    int index = e.getChildIndices()[0];
199:                    node = (DefaultMutableTreeNode) (node.getChildAt(index));
200:                } catch (NullPointerException exc) {
201:                }
202:                String newValue = (String) node.getUserObject();
203:                designer.renameWorkflow(currentWorkflow, newValue);
204:                currentWorkflow = newValue;
205:            }
206:
207:            public void setWorkspace(WorkflowFactory workspace) {
208:                removeChildNodes(rootNode);
209:                ((DefaultTreeModel) getModel()).reload();
210:                DefaultMutableTreeNode root = (DefaultMutableTreeNode) getModel()
211:                        .getRoot();
212:                if (workspace != null) {
213:                    String[] workflows;
214:                    currentWorkspace = workspace;
215:                    try {
216:                        workflows = workspace.getWorkflowNames();
217:                    } catch (FactoryException t) {
218:                        return;
219:                    }
220:
221:                    for (int i = 0; i < workflows.length; i++) {
222:                        try {
223:                            WorkflowDescriptor descriptor = workspace
224:                                    .getWorkflow(workflows[i], false);
225:                            addWorkflow(descriptor);
226:                        } catch (FactoryException fe) {
227:                        }
228:                    }
229:                    root.setUserObject(workspace.getName());
230:                    expandRow(0);
231:                } else {
232:                    root.setUserObject(ResourceManager
233:                            .getString("workspace.none"));
234:                }
235:            }
236:
237:            public void addWorkflow(String name) {
238:                if (currentWorkspace != null) {
239:                    try {
240:                        WorkflowDescriptor descriptor = currentWorkspace
241:                                .getWorkflow(name);
242:                        addWorkflow(descriptor);
243:                    } catch (FactoryException fe) {
244:                    }
245:                }
246:            }
247:
248:            public void addWorkflow(WorkflowDescriptor desc) {
249:                if (desc != null) {
250:                    // Add the workflow
251:                    DefaultMutableTreeNode childNode = new DefaultMutableTreeNode(
252:                            desc) {
253:                        public String toString() {
254:                            if (getUserObject() instanceof  WorkflowDescriptor) {
255:                                return ((WorkflowDescriptor) getUserObject())
256:                                        .getName();
257:                            } else {
258:                                return super .toString();
259:                            }
260:                        }
261:                    };
262:                    DefaultTreeModel model = (DefaultTreeModel) getModel();
263:                    DefaultMutableTreeNode root = (DefaultMutableTreeNode) model
264:                            .getRoot();
265:                    model.insertNodeInto(childNode, root, root.getChildCount());
266:
267:                    // Add all the workflow childs (folders)
268:                    // meta
269:                    // registers
270:                    // trigger-functions
271:                    // initial-actions (folder)
272:                    DefaultMutableTreeNode folderNode = new DefaultMutableTreeNode(
273:                            ResourceManager.getString("initialactions.folder"));
274:                    model.insertNodeInto(folderNode, childNode, childNode
275:                            .getChildCount());
276:                    addActions(desc.getInitialActions(), folderNode);
277:                    // global-actions (folder)
278:                    folderNode = new DefaultMutableTreeNode(ResourceManager
279:                            .getString("globalactions.folder"));
280:                    model.insertNodeInto(folderNode, childNode, childNode
281:                            .getChildCount());
282:                    addActions(desc.getGlobalActions(), folderNode);
283:                    // common-actions (folder)
284:                    folderNode = new DefaultMutableTreeNode(ResourceManager
285:                            .getString("commonactions.folder"));
286:                    model.insertNodeInto(folderNode, childNode, childNode
287:                            .getChildCount());
288:                    addCommonActions(desc, folderNode);
289:                    // steps (folder)
290:                    folderNode = new DefaultMutableTreeNode(ResourceManager
291:                            .getString("steps.folder"));
292:                    model.insertNodeInto(folderNode, childNode, childNode
293:                            .getChildCount());
294:                    addSteps(desc, folderNode);
295:                    // splits (folder)
296:                    folderNode = new DefaultMutableTreeNode(ResourceManager
297:                            .getString("splits.folder"));
298:                    model.insertNodeInto(folderNode, childNode, childNode
299:                            .getChildCount());
300:                    addSplits(desc, folderNode);
301:                    // joins (folder)
302:                    folderNode = new DefaultMutableTreeNode(ResourceManager
303:                            .getString("joins.folder"));
304:                    model.insertNodeInto(folderNode, childNode, childNode
305:                            .getChildCount());
306:                    addJoins(desc, folderNode);
307:                }
308:            }
309:
310:            private void addActions(List actions, DefaultMutableTreeNode node) {
311:                if ((actions != null) && (node != null)) {
312:                    DefaultTreeModel model = (DefaultTreeModel) getModel();
313:                    removeChildNodes(node);
314:
315:                    for (Iterator iterator = actions.iterator(); iterator
316:                            .hasNext();) {
317:                        ActionDescriptor action = (ActionDescriptor) iterator
318:                                .next();
319:                        DefaultMutableTreeNode actionNode = new DefaultMutableTreeNode(
320:                                action) {
321:                            public String toString() {
322:                                if (getUserObject() instanceof  ActionDescriptor) {
323:                                    return ((ActionDescriptor) getUserObject())
324:                                            .getName();
325:                                } else {
326:                                    return super .toString();
327:                                }
328:                            }
329:                        };
330:                        model.insertNodeInto(actionNode, node, node
331:                                .getChildCount());
332:                        addActionResults(action, actionNode);
333:                    }
334:                }
335:            }
336:
337:            private void addActionResults(ActionDescriptor action,
338:                    DefaultMutableTreeNode node) {
339:                if ((action == null) || (node == null))
340:                    return;
341:
342:                DefaultTreeModel model = (DefaultTreeModel) getModel();
343:                removeChildNodes(node);
344:
345:                //	add the action unconditional-results
346:                ResultDescriptor unconditional = action
347:                        .getUnconditionalResult();
348:                if (unconditional != null) {
349:                    DefaultMutableTreeNode unconditionalNode = new DefaultMutableTreeNode(
350:                            unconditional) {
351:                        public String toString() {
352:                            if (getUserObject() instanceof  ResultDescriptor) {
353:                                String name = ((ResultDescriptor) getUserObject())
354:                                        .getDisplayName();
355:                                if ((name == null) || (name.length() == 0)) {
356:                                    ActionDescriptor a = (ActionDescriptor) ((ResultDescriptor) getUserObject())
357:                                            .getParent();
358:                                    if (a != null)
359:                                        name = a.getName();
360:                                    else
361:                                        name = "";
362:                                }
363:                                return name;
364:                            } else {
365:                                return super .toString();
366:                            }
367:                        }
368:                    };
369:                    model.insertNodeInto(unconditionalNode, node, node
370:                            .getChildCount());
371:                }
372:                // add the action conditional-results
373:                List results = action.getConditionalResults();
374:                if (results != null) {
375:                    for (Iterator it = results.iterator(); it.hasNext();) {
376:                        ConditionalResultDescriptor conditional = (ConditionalResultDescriptor) it
377:                                .next();
378:                        DefaultMutableTreeNode conditionalNode = new DefaultMutableTreeNode(
379:                                conditional) {
380:                            public String toString() {
381:                                if (getUserObject() instanceof  ConditionalResultDescriptor) {
382:                                    String name = ((ConditionalResultDescriptor) getUserObject())
383:                                            .getDisplayName();
384:                                    if ((name == null) || (name.length() == 0)) {
385:                                        ActionDescriptor a = (ActionDescriptor) ((ConditionalResultDescriptor) getUserObject())
386:                                                .getParent();
387:                                        if (a != null)
388:                                            name = a.getName();
389:                                        else
390:                                            name = "";
391:                                    }
392:                                    return name;
393:                                } else {
394:                                    return super .toString();
395:                                }
396:                            }
397:                        };
398:                        model.insertNodeInto(conditionalNode, node, node
399:                                .getChildCount());
400:                    }
401:                }
402:            }
403:
404:            private void addCommonActions(WorkflowDescriptor desc,
405:                    DefaultMutableTreeNode node) {
406:                if ((desc != null) && (node != null)) {
407:                    DefaultTreeModel model = (DefaultTreeModel) getModel();
408:                    removeChildNodes(node);
409:
410:                    Collection actions = desc.getCommonActions().values();
411:                    for (Iterator iterator = actions.iterator(); iterator
412:                            .hasNext();) {
413:                        ActionDescriptor action = (ActionDescriptor) iterator
414:                                .next();
415:                        DefaultMutableTreeNode actionNode = new DefaultMutableTreeNode(
416:                                action) {
417:                            public String toString() {
418:                                if (getUserObject() instanceof  ActionDescriptor) {
419:                                    return ((ActionDescriptor) getUserObject())
420:                                            .getName();
421:                                } else {
422:                                    return super .toString();
423:                                }
424:                            }
425:                        };
426:                        model.insertNodeInto(actionNode, node, node
427:                                .getChildCount());
428:                        addActionResults(action, actionNode);
429:                    }
430:                }
431:            }
432:
433:            private void addSplitResults(SplitDescriptor split,
434:                    DefaultMutableTreeNode node) {
435:                if ((split == null) || (node == null))
436:                    return;
437:
438:                DefaultTreeModel model = (DefaultTreeModel) getModel();
439:                removeChildNodes(node);
440:
441:                List results = split.getResults();
442:                if (results != null) {
443:                    for (Iterator it = results.iterator(); it.hasNext();) {
444:                        ResultDescriptor unconditional = (ResultDescriptor) it
445:                                .next();
446:                        DefaultMutableTreeNode resultNode = new DefaultMutableTreeNode(
447:                                unconditional) {
448:                            public String toString() {
449:                                if (getUserObject() instanceof  ResultDescriptor) {
450:                                    String name = ((ResultDescriptor) getUserObject())
451:                                            .getDisplayName();
452:                                    if ((name == null) || (name.length() == 0)) {
453:                                        // TODO verificare il nome da assegnare nel caso il displayname sia vuoto
454:                                        name = "Split Result";
455:                                    }
456:                                    return name;
457:                                } else {
458:                                    return super .toString();
459:                                }
460:                            }
461:                        };
462:                        model.insertNodeInto(resultNode, node, node
463:                                .getChildCount());
464:                    }
465:                }
466:            }
467:
468:            private void addJoinResult(JoinDescriptor join,
469:                    DefaultMutableTreeNode node) {
470:                if ((join == null) || (node == null))
471:                    return;
472:
473:                DefaultTreeModel model = (DefaultTreeModel) getModel();
474:                removeChildNodes(node);
475:
476:                ResultDescriptor result = join.getResult();
477:                if (result != null) {
478:                    DefaultMutableTreeNode resultNode = new DefaultMutableTreeNode(
479:                            result) {
480:                        public String toString() {
481:                            if (getUserObject() instanceof  ResultDescriptor) {
482:                                String name = ((ResultDescriptor) getUserObject())
483:                                        .getDisplayName();
484:                                if ((name == null) || (name.length() == 0)) {
485:                                    // TODO verificare il nome da assegnare nel caso il displayname sia vuoto
486:                                    name = "Join Result";
487:                                }
488:                                return name;
489:                            } else {
490:                                return super .toString();
491:                            }
492:                        }
493:                    };
494:                    model
495:                            .insertNodeInto(resultNode, node, node
496:                                    .getChildCount());
497:                }
498:            }
499:
500:            private void addSteps(WorkflowDescriptor desc,
501:                    DefaultMutableTreeNode node) {
502:                if ((desc != null) && (node != null)) {
503:                    DefaultTreeModel model = (DefaultTreeModel) getModel();
504:                    removeChildNodes(node);
505:
506:                    List steps = desc.getSteps();
507:                    for (Iterator iterator = steps.iterator(); iterator
508:                            .hasNext();) {
509:                        StepDescriptor step = (StepDescriptor) iterator.next();
510:                        DefaultMutableTreeNode stepNode = new DefaultMutableTreeNode(
511:                                step) {
512:                            public String toString() {
513:                                if (getUserObject() instanceof  StepDescriptor) {
514:                                    return ((StepDescriptor) getUserObject())
515:                                            .getName();
516:                                } else {
517:                                    return super .toString();
518:                                }
519:                            }
520:                        };
521:                        model.insertNodeInto(stepNode, node, node
522:                                .getChildCount());
523:                        addActions(step.getActions(), stepNode);
524:                    }
525:                }
526:            }
527:
528:            private void addSplits(WorkflowDescriptor desc,
529:                    DefaultMutableTreeNode node) {
530:                if ((desc != null) && (node != null)) {
531:                    DefaultTreeModel model = (DefaultTreeModel) getModel();
532:                    removeChildNodes(node);
533:
534:                    List splits = desc.getSplits();
535:                    for (Iterator iterator = splits.iterator(); iterator
536:                            .hasNext();) {
537:                        SplitDescriptor split = (SplitDescriptor) iterator
538:                                .next();
539:                        DefaultMutableTreeNode splitNode = new DefaultMutableTreeNode(
540:                                split) {
541:                            public String toString() {
542:                                if (getUserObject() instanceof  SplitDescriptor) {
543:                                    String s = "Split #"
544:                                            + ((SplitDescriptor) getUserObject())
545:                                                    .getId();
546:                                    return s;
547:                                } else {
548:                                    return super .toString();
549:                                }
550:                            }
551:                        };
552:                        model.insertNodeInto(splitNode, node, node
553:                                .getChildCount());
554:                        addSplitResults(split, splitNode);
555:                    }
556:                }
557:            }
558:
559:            private void addJoins(WorkflowDescriptor desc,
560:                    DefaultMutableTreeNode node) {
561:                if ((desc != null) && (node != null)) {
562:                    DefaultTreeModel model = (DefaultTreeModel) getModel();
563:                    removeChildNodes(node);
564:
565:                    List joins = desc.getJoins();
566:                    for (Iterator iterator = joins.iterator(); iterator
567:                            .hasNext();) {
568:                        JoinDescriptor join = (JoinDescriptor) iterator.next();
569:                        DefaultMutableTreeNode joinNode = new DefaultMutableTreeNode(
570:                                join) {
571:                            public String toString() {
572:                                if (getUserObject() instanceof  JoinDescriptor) {
573:                                    String s = "Join #"
574:                                            + ((JoinDescriptor) getUserObject())
575:                                                    .getId();
576:                                    return s;
577:                                } else {
578:                                    return super .toString();
579:                                }
580:                            }
581:                        };
582:                        model.insertNodeInto(joinNode, node, node
583:                                .getChildCount());
584:                        addJoinResult(join, joinNode);
585:                    }
586:                }
587:            }
588:
589:            public void selectTreeNode(WorkflowDescriptor workflow,
590:                    AbstractDescriptor desc) {
591:                // select a tree item  
592:                if ((workflow == null) || (desc == null))
593:                    return;
594:                DefaultMutableTreeNode root = (DefaultMutableTreeNode) getModel()
595:                        .getRoot();
596:                // loop over the workspace childs (the workflows)
597:                for (int i = 0; i < root.getChildCount(); i++) {
598:                    DefaultMutableTreeNode workflowNode = (DefaultMutableTreeNode) root
599:                            .getChildAt(i);
600:                    if (workflowNode.getUserObject() == workflow) {
601:                        // search over all the childs of the workflow
602:                        if (workflowNode.getUserObject() == desc) {
603:                            selectExpandNode(workflowNode);
604:                        } else {
605:                            DefaultMutableTreeNode node = findNodeRecursive(
606:                                    workflowNode, desc);
607:                            if (node != null) {
608:                                selectExpandNode(node);
609:                            }
610:                        }
611:                        break;
612:                    }
613:                }
614:            }
615:
616:            private DefaultMutableTreeNode findNodeRecursive(
617:                    DefaultMutableTreeNode parentNode, AbstractDescriptor desc) {
618:                if ((parentNode == null) || (desc == null))
619:                    return null;
620:
621:                for (int i = 0; i < parentNode.getChildCount(); i++) {
622:                    DefaultMutableTreeNode childNode = (DefaultMutableTreeNode) parentNode
623:                            .getChildAt(i);
624:                    if (childNode.getUserObject() == desc) {
625:                        return childNode;
626:                    } else {
627:                        DefaultMutableTreeNode node = findNodeRecursive(
628:                                childNode, desc);
629:                        if (node != null)
630:                            return node;
631:                    }
632:                }
633:                return null;
634:            }
635:
636:            private DefaultMutableTreeNode findFolderNode(
637:                    WorkflowDescriptor workflow, String folderName) {
638:                if (workflow == null)
639:                    return null;
640:                DefaultMutableTreeNode root = (DefaultMutableTreeNode) getModel()
641:                        .getRoot();
642:                DefaultMutableTreeNode workflowNode = findNodeRecursive(root,
643:                        workflow);
644:                if (workflowNode != null) {
645:                    for (int z = 0; z < workflowNode.getChildCount(); z++) {
646:                        DefaultMutableTreeNode folderNode = (DefaultMutableTreeNode) workflowNode
647:                                .getChildAt(z);
648:                        if (folderNode.getUserObject() instanceof  String) {
649:                            String s = (String) folderNode.getUserObject();
650:                            if (s.equals(folderName)) {
651:                                return folderNode;
652:                            }
653:                        }
654:                    }
655:                }
656:                return null;
657:            }
658:
659:            private void selectExpandNode(DefaultMutableTreeNode node) {
660:                TreeNode[] nodes = node.getPath();
661:                TreePath path = new TreePath(nodes);
662:                getSelectionModel().setSelectionPath(path);
663:                expandPath(path);
664:                scrollPathToVisible(path);
665:            }
666:
667:            public void reloadSteps(WorkflowDescriptor workflow) {
668:                DefaultMutableTreeNode stepFolder = findFolderNode(workflow,
669:                        ResourceManager.getString("steps.folder"));
670:                if (stepFolder != null) {
671:                    addSteps(workflow, stepFolder);
672:                }
673:            }
674:
675:            public void reloadSplits(WorkflowDescriptor workflow) {
676:                DefaultMutableTreeNode splitsFolder = findFolderNode(workflow,
677:                        ResourceManager.getString("splits.folder"));
678:                if (splitsFolder != null) {
679:                    addSplits(workflow, splitsFolder);
680:                }
681:            }
682:
683:            public void reloadJoins(WorkflowDescriptor workflow) {
684:                DefaultMutableTreeNode joinsFolder = findFolderNode(workflow,
685:                        ResourceManager.getString("joins.folder"));
686:                if (joinsFolder != null) {
687:                    addJoins(workflow, joinsFolder);
688:                }
689:            }
690:
691:            public void reloadInitialAction(WorkflowDescriptor workflow) {
692:                DefaultMutableTreeNode iaFolder = findFolderNode(workflow,
693:                        ResourceManager.getString("initialactions.folder"));
694:                if (iaFolder != null) {
695:                    addActions(workflow.getInitialActions(), iaFolder);
696:                }
697:            }
698:
699:            public void reloadStep(WorkflowDescriptor workflow,
700:                    StepDescriptor step) {
701:                DefaultMutableTreeNode stepNode = findNodeRecursive(
702:                        findFolderNode(workflow, ResourceManager
703:                                .getString("steps.folder")), step);
704:                if (stepNode != null) {
705:                    addActions(step.getActions(), stepNode);
706:                }
707:            }
708:
709:            public void reloadSplit(WorkflowDescriptor workflow,
710:                    SplitDescriptor split) {
711:                DefaultMutableTreeNode splitNode = findNodeRecursive(
712:                        findFolderNode(workflow, ResourceManager
713:                                .getString("splits.folder")), split);
714:                if (splitNode != null) {
715:                    addSplitResults(split, splitNode);
716:                }
717:            }
718:
719:            public void reloadJoin(WorkflowDescriptor workflow,
720:                    JoinDescriptor join) {
721:                DefaultMutableTreeNode joinNode = findNodeRecursive(
722:                        findFolderNode(workflow, ResourceManager
723:                                .getString("joins.folder")), join);
724:                if (joinNode != null) {
725:                    addJoinResult(join, joinNode);
726:                }
727:            }
728:
729:            public void reloadAction(WorkflowDescriptor workflow,
730:                    ActionDescriptor action) {
731:                DefaultMutableTreeNode root = (DefaultMutableTreeNode) getModel()
732:                        .getRoot();
733:                DefaultMutableTreeNode workflowNode = findNodeRecursive(root,
734:                        workflow);
735:                DefaultMutableTreeNode actionNode = findNodeRecursive(
736:                        workflowNode, action);
737:                if (actionNode != null) {
738:                    addActionResults(action, actionNode);
739:                }
740:            }
741:
742:            public void reloadWorkflow(WorkflowDescriptor workflow) {
743:                reloadInitialAction(workflow);
744:                reloadSteps(workflow);
745:                reloadJoins(workflow);
746:                reloadSplits(workflow);
747:            }
748:
749:            private void removeChildNodes(DefaultMutableTreeNode parentNode) {
750:                DefaultTreeModel model = (DefaultTreeModel) getModel();
751:                while (model.getChildCount(parentNode) > 0) {
752:                    DefaultMutableTreeNode node = (DefaultMutableTreeNode) parentNode
753:                            .getFirstChild();
754:                    model.removeNodeFromParent(node);
755:                }
756:            }
757:
758:            public void treeNodesInserted(TreeModelEvent e) {
759:            }
760:
761:            public void treeNodesRemoved(TreeModelEvent e) {
762:            }
763:
764:            public void treeStructureChanged(TreeModelEvent e) {
765:            }
766:
767:            /*
768:             * @author acapitani
769:             */
770:            static class WorkspaceCellRenderer extends DefaultTreeCellRenderer {
771:                public WorkspaceCellRenderer() {
772:                    super ();
773:                    //	setClosedIcon(ResourceManager.getIcon("action"));
774:                    //	setOpenIcon(ResourceManager.getIcon("action"));
775:                    //	setLeafIcon(ResourceManager.getIcon("step"));
776:                }
777:
778:                public Component getTreeCellRendererComponent(JTree tree,
779:                        Object value, boolean sel, boolean expanded,
780:                        boolean leaf, int row, boolean hasFocus) {
781:                    Component result = super .getTreeCellRendererComponent(tree,
782:                            value, sel, expanded, leaf, row, hasFocus);
783:                    if (value instanceof  DefaultMutableTreeNode) {
784:                        Object obj = ((DefaultMutableTreeNode) value)
785:                                .getUserObject();
786:                        if (obj instanceof  WorkflowDescriptor) {
787:                            // workflow icon
788:                            setIcon(ResourceManager.getIcon("layout"));
789:                        } else if (obj instanceof  ActionDescriptor) {
790:                            // action icon
791:                            setIcon(ResourceManager.getIcon("action"));
792:                        } else if (obj instanceof  ConditionalResultDescriptor) {
793:                            // conditional-result icon
794:                            setIcon(ResourceManager
795:                                    .getIcon("conditional.result"));
796:                        } else if (obj instanceof  ResultDescriptor) {
797:                            // unconditional-result icon
798:                            setIcon(ResourceManager
799:                                    .getIcon("unconditional.result"));
800:                        } else if (obj instanceof  StepDescriptor) {
801:                            // step icon
802:                            setIcon(ResourceManager.getIcon("step"));
803:                        } else if (obj instanceof  SplitDescriptor) {
804:                            // split icon
805:                            setIcon(ResourceManager.getIcon("split"));
806:                        } else if (obj instanceof  JoinDescriptor) {
807:                            setIcon(ResourceManager.getIcon("join"));
808:                        }
809:                    }
810:                    return result;
811:                }
812:            }
813:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.