Source Code Cross Referenced for GraphController.java in  » Workflow-Engines » JaWE » org » enhydra » jawe » components » graph » 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 » JaWE » org.enhydra.jawe.components.graph 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        package org.enhydra.jawe.components.graph;
0002:
0003:        import java.awt.Point;
0004:        import java.awt.Rectangle;
0005:        import java.lang.reflect.Constructor;
0006:        import java.util.ArrayList;
0007:        import java.util.HashMap;
0008:        import java.util.Iterator;
0009:        import java.util.List;
0010:        import java.util.Map;
0011:        import java.util.Observable;
0012:        import java.util.Observer;
0013:
0014:        import javax.swing.ToolTipManager;
0015:
0016:        import org.enhydra.jawe.ChoiceButton;
0017:        import org.enhydra.jawe.ChoiceButtonListener;
0018:        import org.enhydra.jawe.HistoryManager;
0019:        import org.enhydra.jawe.JaWEComponent;
0020:        import org.enhydra.jawe.JaWEComponentSettings;
0021:        import org.enhydra.jawe.JaWEComponentView;
0022:        import org.enhydra.jawe.JaWEManager;
0023:        import org.enhydra.jawe.XPDLElementChangeInfo;
0024:        import org.enhydra.jawe.base.xpdlhandler.XPDLHandler;
0025:        import org.enhydra.jawe.components.graph.actions.SimpleGraphLayout;
0026:        import org.enhydra.shark.utilities.SequencedHashMap;
0027:        import org.enhydra.shark.xpdl.XMLCollection;
0028:        import org.enhydra.shark.xpdl.XMLCollectionElement;
0029:        import org.enhydra.shark.xpdl.XMLElement;
0030:        import org.enhydra.shark.xpdl.XMLElementChangeInfo;
0031:        import org.enhydra.shark.xpdl.XMLUtil;
0032:        import org.enhydra.shark.xpdl.elements.Activity;
0033:        import org.enhydra.shark.xpdl.elements.ActivitySet;
0034:        import org.enhydra.shark.xpdl.elements.ExtendedAttribute;
0035:        import org.enhydra.shark.xpdl.elements.Package;
0036:        import org.enhydra.shark.xpdl.elements.Participant;
0037:        import org.enhydra.shark.xpdl.elements.Transition;
0038:        import org.enhydra.shark.xpdl.elements.WorkflowProcess;
0039:        import org.jgraph.event.GraphSelectionEvent;
0040:        import org.jgraph.event.GraphSelectionListener;
0041:
0042:        /**
0043:         *  Used to handle process graphs.
0044:         *
0045:         *  @author Sasa Bojanic
0046:         *  @author Miroslav Popov
0047:         */
0048:        public class GraphController extends Observable implements  Observer,
0049:                JaWEComponent, ChoiceButtonListener, GraphSelectionListener {
0050:
0051:            protected String type = JaWEComponent.MAIN_COMPONENT;
0052:            protected boolean updateInProgress = false;
0053:
0054:            protected GraphObjectFactory graphObjectFactory;
0055:            protected GraphObjectRendererFactory graphObjectRendererFactory;
0056:            protected GraphMarqueeHandler graphMarqueeHandler;
0057:
0058:            protected Graph selectedGraph;
0059:
0060:            protected GraphControllerPanel panel;
0061:            protected GraphOverview overview;
0062:
0063:            protected Map graphMap = new SequencedHashMap();
0064:
0065:            protected CopyOrCutInfo copyOrCutInfo;
0066:
0067:            protected GraphSettings settings;
0068:
0069:            protected HistoryManager hm;
0070:
0071:            public GraphController(JaWEComponentSettings settings)
0072:                    throws Exception {
0073:                this .settings = (GraphSettings) settings;
0074:                this .settings.init(this );
0075:
0076:                try {
0077:                    String hmc = this .settings.historyManagerClass();
0078:                    if (hmc != null && !hmc.equals("")) {
0079:                        hm = (HistoryManager) Class.forName(hmc).newInstance();
0080:                        hm.init(this .settings.historySize());
0081:                    }
0082:                } catch (Exception ex) {
0083:                    System.err
0084:                            .println("Failed to instantiate history manager for "
0085:                                    + this );
0086:                }
0087:
0088:                graphObjectFactory = (GraphObjectFactory) Class.forName(
0089:                        this .settings.getGraphObjectFactory()).newInstance();
0090:                graphObjectRendererFactory = (GraphObjectRendererFactory) Class
0091:                        .forName(this .settings.getGraphObjectRendererFactory())
0092:                        .newInstance();
0093:                Constructor c = Class.forName(
0094:                        this .settings.getGraphMarqueeHandler()).getConstructor(
0095:                        new Class[] { GraphController.class });
0096:                graphMarqueeHandler = (GraphMarqueeHandler) c
0097:                        .newInstance(new Object[] { this  });
0098:
0099:                if (this .settings.shouldShowGraphOverview()) {
0100:                    try {
0101:                        String ovc = this .settings.overviewClass();
0102:                        if (ovc != null && !ovc.equals("")) {
0103:                            overview = (GraphOverview) Class.forName(ovc)
0104:                                    .newInstance();
0105:                            overview.init(this );
0106:                        }
0107:                    } catch (Exception ex) {
0108:                        System.err
0109:                                .println("Failed to instantiate GraphOverview!");
0110:                    }
0111:                }
0112:
0113:                init();
0114:
0115:                JaWEManager.getInstance().getJaWEController().addObserver(this );
0116:                if (overview != null) {
0117:                    JaWEManager.getInstance().getComponentManager()
0118:                            .addComponent(overview);
0119:                    JaWEManager.getInstance().getJaWEController()
0120:                            .registerJaWEComponent(overview);
0121:                }
0122:
0123:            }
0124:
0125:            // ********************** Observable
0126:            // **********************    
0127:
0128:            // ********************** Observer
0129:            public void update(Observable o, Object arg) {
0130:                //      JaWEManager.getInstance().getLoggingManager().info("GraphController -> trying to start update for event "+arg+", update in progress="+updateInProgress);
0131:                if (updateInProgress)
0132:                    return;
0133:                if (!(arg instanceof  XPDLElementChangeInfo))
0134:                    return;
0135:                XPDLElementChangeInfo info = (XPDLElementChangeInfo) arg;
0136:                XMLElement changedElement = info.getChangedElement();
0137:                int action = info.getAction();
0138:                if (info.getSource() == this 
0139:                        || (changedElement == null && action != XPDLElementChangeInfo.SELECTED))
0140:                    return;
0141:                if (!(action == XMLElementChangeInfo.UPDATED
0142:                        || action == XMLElementChangeInfo.INSERTED
0143:                        || action == XMLElementChangeInfo.REMOVED
0144:                        || action == XMLElementChangeInfo.REPOSITIONED
0145:                        || action == XPDLElementChangeInfo.SELECTED
0146:                        || action == XPDLElementChangeInfo.ADJUST_UNDOABLE_ACTION
0147:                        || action == XPDLElementChangeInfo.UNDO
0148:                        || action == XPDLElementChangeInfo.REDO
0149:                        || action == XPDLElementChangeInfo.COPY || action == XPDLElementChangeInfo.CUT))
0150:                    return;
0151:
0152:                long start = System.currentTimeMillis();
0153:                JaWEManager.getInstance().getLoggingManager().info(
0154:                        "GraphController -> update for event " + info
0155:                                + " started ...");
0156:
0157:                updateInProgress = true;
0158:                try {
0159:                    if (action == XPDLElementChangeInfo.COPY
0160:                            || action == XPDLElementChangeInfo.CUT) {
0161:                        copyOrCutInfo = null;
0162:                        if (selectedGraph != null) {
0163:                            GraphManager gm = selectedGraph.getGraphManager();
0164:
0165:                            Map actRectangles = new HashMap();
0166:                            Iterator it = info.getChangedSubElements()
0167:                                    .iterator();
0168:                            while (it.hasNext()) {
0169:                                XMLElement toCopyOrCut = (XMLElement) it.next();
0170:                                if (!(toCopyOrCut instanceof  Activity))
0171:                                    continue;
0172:                                Activity a = (Activity) toCopyOrCut;
0173:                                GraphActivityInterface ga = gm
0174:                                        .getGraphActivity(a);
0175:                                if (ga != null) {
0176:                                    CopiedActivityInfo ai = new CopiedActivityInfo(
0177:                                            GraphUtilities.getParticipantId(a),
0178:                                            GraphUtilities.getOffsetPoint(a));
0179:                                    Rectangle rect = gm.getBounds(ga,
0180:                                            new HashMap());
0181:                                    actRectangles.put(ai, rect);
0182:                                }
0183:                            }
0184:
0185:                            if (actRectangles.size() > 0) {
0186:                                Rectangle[] rarr = new Rectangle[actRectangles
0187:                                        .size()];
0188:                                actRectangles.values().toArray(rarr);
0189:                                Point referencePoint = gm.getUnionBounds(rarr)
0190:                                        .getLocation();
0191:                                copyOrCutInfo = new CopyOrCutInfo(
0192:                                        referencePoint, actRectangles);
0193:                            }
0194:                        }
0195:                    } else if (action == XPDLElementChangeInfo.UNDO
0196:                            || action == XPDLElementChangeInfo.REDO
0197:                            || action == XPDLElementChangeInfo.ADJUST_UNDOABLE_ACTION) {
0198:                        if (action == XPDLElementChangeInfo.ADJUST_UNDOABLE_ACTION) {
0199:                            GraphUtilities
0200:                                    .adjustPackageOnUndoableChangeEvent(info
0201:                                            .getChangedSubElements());
0202:                        } else {
0203:                            GraphUtilities.adjustPackageOnUndoOrRedoEvent(info
0204:                                    .getChangedSubElements());
0205:                        }
0206:                    } else {
0207:                        update(info);
0208:                    }
0209:                } finally {
0210:                    updateInProgress = false;
0211:                }
0212:                JaWEManager.getInstance().getLoggingManager().info(
0213:                        "GraphController -> update ended");
0214:                long end = System.currentTimeMillis();
0215:                double diffs = (end - start) / 1000.0;
0216:                JaWEManager.getInstance().getLoggingManager().debug(
0217:                        "THE UPDATE OF GRAPH COMPONENT LASTED FOR " + diffs
0218:                                + " SECONDS!");
0219:            }
0220:
0221:            // **********************    
0222:
0223:            // ********************** JaWEComponent
0224:            public JaWEComponentSettings getSettings() {
0225:                return settings;
0226:            }
0227:
0228:            public JaWEComponentView getView() {
0229:                return panel;
0230:            }
0231:
0232:            public String getName() {
0233:                return "GraphComponent";
0234:            }
0235:
0236:            public String getType() {
0237:                return type;
0238:            }
0239:
0240:            public void setType(String type) {
0241:                this .type = type;
0242:            }
0243:
0244:            public boolean adjustXPDL(Package pkg) {
0245:                return GraphUtilities.scanExtendedAttributes(pkg);
0246:            }
0247:
0248:            public List checkValidity(XMLElement el, boolean fullCheck) {
0249:                GraphSettings gv = getGraphSettings();
0250:                if (!gv.shouldUseBubbles()) {
0251:                    return null;
0252:                }
0253:
0254:                List graphsToValidate = getGraphsToValidate(el);
0255:                boolean isValid = true;
0256:                List verrors = new ArrayList();
0257:                for (int i = 0; i < graphsToValidate.size(); i++) {
0258:                    Graph toValidate = (Graph) graphsToValidate.get(i);
0259:                    List vers = toValidate.checkConnections(fullCheck);
0260:                    isValid = (vers == null || vers.size() == 0) && isValid;
0261:                    if (vers != null) {
0262:                        verrors.addAll(vers);
0263:                    }
0264:                    if (!(isValid || fullCheck)) {
0265:                        break;
0266:                    }
0267:                }
0268:
0269:                return verrors;
0270:            }
0271:
0272:            protected List getGraphsToValidate(XMLElement el) {
0273:                List graphsToValidate = new ArrayList();
0274:                if (el instanceof  WorkflowProcess || el instanceof  ActivitySet) {
0275:                    Graph g = (Graph) graphMap.get(el);
0276:                    if (g != null) {
0277:                        graphsToValidate.add(g);
0278:                    }
0279:                    if (el instanceof  WorkflowProcess) {
0280:                        Iterator ass = ((WorkflowProcess) el).getActivitySets()
0281:                                .toElements().iterator();
0282:                        while (ass.hasNext()) {
0283:                            ActivitySet as = (ActivitySet) ass.next();
0284:                            g = (Graph) graphMap.get(as);
0285:                            if (g != null) {
0286:                                graphsToValidate.add(g);
0287:                            }
0288:                        }
0289:                    }
0290:                } else if (el instanceof  Package) {
0291:                    Iterator it = ((Package) el).getWorkflowProcesses()
0292:                            .toElements().iterator();
0293:                    while (it.hasNext()) {
0294:                        WorkflowProcess wp = (WorkflowProcess) it.next();
0295:                        graphsToValidate.addAll(getGraphsToValidate(wp));
0296:                    }
0297:                }
0298:                return graphsToValidate;
0299:            }
0300:
0301:            public boolean canCreateElement(XMLCollection col) {
0302:                return true;
0303:            }
0304:
0305:            public boolean canInsertElement(XMLCollection col, XMLElement el) {
0306:                if (el == null)
0307:                    return true;
0308:                ExtendedAttribute ea = null;
0309:                if (el instanceof  ExtendedAttribute) {
0310:                    ea = (ExtendedAttribute) el;
0311:                } else if (el.getParent() instanceof  ExtendedAttribute) {
0312:                    ea = (ExtendedAttribute) el.getParent();
0313:                }
0314:                if (ea != null) {
0315:                    return !GraphUtilities.isMyKindOfExtendedAttribute(ea);
0316:                }
0317:                return true;
0318:            }
0319:
0320:            public boolean canModifyElement(XMLElement el) {
0321:                if (el == null)
0322:                    return true;
0323:                ExtendedAttribute ea = null;
0324:                if (el instanceof  ExtendedAttribute) {
0325:                    ea = (ExtendedAttribute) el;
0326:                } else if (el.getParent() instanceof  ExtendedAttribute) {
0327:                    ea = (ExtendedAttribute) el.getParent();
0328:                }
0329:                if (ea != null) {
0330:                    return !GraphUtilities.isMyKindOfExtendedAttribute(ea);
0331:                }
0332:
0333:                return true;
0334:            }
0335:
0336:            public boolean canRemoveElement(XMLCollection col, XMLElement el) {
0337:                if (el == null)
0338:                    return true;
0339:                ExtendedAttribute ea = null;
0340:                if (el instanceof  ExtendedAttribute) {
0341:                    ea = (ExtendedAttribute) el;
0342:                } else if (el.getParent() instanceof  ExtendedAttribute) {
0343:                    ea = (ExtendedAttribute) el.getParent();
0344:                }
0345:                if (ea != null) {
0346:                    boolean isMyEA = GraphUtilities
0347:                            .isMyKindOfExtendedAttribute(ea);
0348:                    if (isMyEA) {
0349:                        String eaName = ea.getName();
0350:                        if (eaName
0351:                                .equals(GraphEAConstants.EA_JAWE_GRAPH_END_OF_WORKFLOW)
0352:                                || eaName
0353:                                        .equals(GraphEAConstants.EA_JAWE_GRAPH_START_OF_WORKFLOW)
0354:                                || eaName
0355:                                        .equals(GraphEAConstants.EA_JAWE_GRAPH_START_OF_BLOCK)
0356:                                || eaName
0357:                                        .equals(GraphEAConstants.EA_JAWE_GRAPH_END_OF_BLOCK)) {
0358:                            return true;
0359:                        }
0360:                        return false;
0361:                    }
0362:                } else if (el instanceof  FreeTextExpressionParticipant
0363:                        || el instanceof  CommonExpressionParticipant) {
0364:                    return false;
0365:                }
0366:                return true;
0367:            }
0368:
0369:            public boolean canDuplicateElement(XMLCollection col, XMLElement el) {
0370:                if (el == null)
0371:                    return true;
0372:                ExtendedAttribute ea = null;
0373:                if (el instanceof  ExtendedAttribute) {
0374:                    ea = (ExtendedAttribute) el;
0375:                } else if (el.getParent() instanceof  ExtendedAttribute) {
0376:                    ea = (ExtendedAttribute) el.getParent();
0377:                }
0378:                if (ea != null) {
0379:                    return !GraphUtilities.isMyKindOfExtendedAttribute(ea);
0380:                } else if (el instanceof  FreeTextExpressionParticipant
0381:                        || el instanceof  CommonExpressionParticipant) {
0382:                    return false;
0383:                }
0384:                return true;
0385:            }
0386:
0387:            public boolean canRepositionElement(XMLCollection col, XMLElement el) {
0388:                if (el == null)
0389:                    return true;
0390:                ExtendedAttribute ea = null;
0391:                if (el instanceof  ExtendedAttribute) {
0392:                    ea = (ExtendedAttribute) el;
0393:                } else if (el.getParent() instanceof  ExtendedAttribute) {
0394:                    ea = (ExtendedAttribute) el.getParent();
0395:                }
0396:                if (ea != null) {
0397:                    return !GraphUtilities.isMyKindOfExtendedAttribute(ea);
0398:                } else if (el instanceof  FreeTextExpressionParticipant
0399:                        || el instanceof  CommonExpressionParticipant) {
0400:                    return false;
0401:                }
0402:                return true;
0403:            }
0404:
0405:            // **********************      
0406:
0407:            // **********************  ChoiceButtonListener
0408:            public void selectionChanged(ChoiceButton cbutton, Object change) {
0409:                if (updateInProgress)
0410:                    return;
0411:                if (getSelectedGraph() == null)
0412:                    return;
0413:                if (cbutton.getChoiceType() == Participant.class) {
0414:                    Participant par = (Participant) change;
0415:
0416:                    setUpdateInProgress(true);
0417:                    JaWEManager.getInstance().getJaWEController()
0418:                            .startUndouableChange();
0419:                    List vo = GraphUtilities
0420:                            .getParticipantVisualOrder(getSelectedGraph()
0421:                                    .getXPDLObject());
0422:                    vo.add(par.getId());
0423:                    GraphUtilities.setParticipantVisualOrder(getSelectedGraph()
0424:                            .getXPDLObject(), vo);
0425:                    getSelectedGraph().getGraphManager()
0426:                            .insertParticipantAndArrangeParticipants(par);
0427:                    List toSelect = new ArrayList();
0428:                    toSelect.add(par);
0429:                    JaWEManager.getInstance().getJaWEController()
0430:                            .endUndouableChange(toSelect);
0431:                    selectedGraph.selectParticipant(par);
0432:                    setUpdateInProgress(false);
0433:
0434:                    adjustActions();
0435:
0436:                    //         List vo=GraphUtilities.getParticipantVisualOrder(selectedGraph.getXPDLObject());
0437:                    //         vo.add(par.getId());
0438:                    //         GraphUtilities.setParticipantVisualOrder(selectedGraph.getXPDLObject(),vo);
0439:                    //         getSelectedGraph().getGraphManager().insertParticipantAndArrangeParticipants(par);
0440:                } else if (cbutton.getChoiceType() == ActivitySet.class) {
0441:                    ActivitySet aset = (ActivitySet) change;
0442:                    setSelectedGraph(getGraph(aset));
0443:
0444:                    JaWEManager.getInstance().getJaWEController()
0445:                            .getSelectionManager().setSelection(aset, true);
0446:                }
0447:            }
0448:
0449:            public Object getSelectedObject(ChoiceButton cbutton) {
0450:                if (cbutton.getChoiceType() == Participant.class)
0451:                    return null;
0452:
0453:                return null;
0454:            }
0455:
0456:            public List getChoices(ChoiceButton cbutton) {
0457:                List choices = new ArrayList();
0458:                if (selectedGraph == null)
0459:                    return choices;
0460:
0461:                if (cbutton.getChoiceType() == Participant.class) {
0462:                    WorkflowProcess wp = selectedGraph.getWorkflowProcess();
0463:                    SequencedHashMap choiceMap = XMLUtil
0464:                            .getPossibleParticipants(wp, JaWEManager
0465:                                    .getInstance().getXPDLHandler());
0466:                    choiceMap.put(FreeTextExpressionParticipant.getInstance()
0467:                            .getName(), FreeTextExpressionParticipant
0468:                            .getInstance());
0469:                    List toRemove = selectedGraph.getGraphManager()
0470:                            .getDisplayedParticipants();
0471:
0472:                    Iterator it = choiceMap.entrySet().iterator();
0473:                    while (it.hasNext()) {
0474:                        Map.Entry me = (Map.Entry) it.next();
0475:                        if (toRemove.contains(me.getValue())) {
0476:                            it.remove();
0477:                        }
0478:                    }
0479:
0480:                    choices.addAll(choiceMap.values());
0481:                } else if (cbutton.getChoiceType() == ActivitySet.class) {
0482:                    WorkflowProcess wp = selectedGraph.getWorkflowProcess();
0483:                    choices = wp.getActivitySets().toElements();
0484:                }
0485:
0486:                return choices;
0487:            }
0488:
0489:            // **********************   
0490:
0491:            // ********************** GraphSelectionListener
0492:            public void valueChanged(GraphSelectionEvent e) {
0493:                if (updateInProgress)
0494:                    return;
0495:
0496:                Object[] selectedCells = getSelectedGraph().getSelectionCells();
0497:                Participant par = null;
0498:                List selectedElements = new ArrayList();
0499:                if (selectedCells != null) {
0500:                    for (int i = 0; i < selectedCells.length; i++) {
0501:                        if (selectedCells[i] instanceof  WorkflowElement) {
0502:                            WorkflowElement we = (WorkflowElement) selectedCells[i];
0503:                            XMLElement el = we.getPropertyObject();
0504:                            if (el != null) {
0505:                                if (el instanceof  Participant) {
0506:                                    par = (Participant) el;
0507:                                }
0508:                                selectedElements.add(el);
0509:                            }
0510:                        }
0511:                    }
0512:                }
0513:                if (selectedElements.size() != 0) {
0514:                    if (par != null) {
0515:                        //            if (par instanceof FreeTextExpressionParticipant || par instanceof CommonExpressionParticipant) {
0516:                        //               setUpdateInProgress(true);
0517:                        //               JaWEManager.getInstance().getJaWEController().getSelectionManager().setSelection((XMLElement)null, false);
0518:                        //               setUpdateInProgress(false);
0519:                        //               adjustActions();
0520:                        //            } else {
0521:                        JaWEManager.getInstance().getJaWEController()
0522:                                .getSelectionManager().setSelection(
0523:                                        selectedElements, false);
0524:                        //            }
0525:                    } else {
0526:                        JaWEManager.getInstance().getJaWEController()
0527:                                .getSelectionManager().setSelection(
0528:                                        selectedElements, true);
0529:                    }
0530:                } else {
0531:                    JaWEManager.getInstance().getJaWEController()
0532:                            .getSelectionManager().setSelection(
0533:                                    selectedGraph.getXPDLObject(), true);
0534:                    //            JaWEManager.getInstance().getJaWEController().getSelectionManager().setSelection((XMLElement)null, false);
0535:                    //            if (freeOrCommon==null) {
0536:                    //               JaWEManager.getInstance().getJaWEController().getSelectionManager().setSelection(selectedElements);
0537:                    //            }
0538:                }
0539:            }
0540:
0541:            // **********************  
0542:
0543:            protected void init() throws Exception {
0544:                panel = createPanel();
0545:                adjustActions();
0546:            }
0547:
0548:            public GraphSettings getGraphSettings() {
0549:                return settings;
0550:            }
0551:
0552:            public void update(XPDLElementChangeInfo info) {
0553:                XMLElement changedElement = info.getChangedElement();
0554:                List changedElements = info.getChangedSubElements();
0555:                int action = info.getAction();
0556:
0557:                // ********************************* START OF SELECTION EVENT
0558:                if (action == XPDLElementChangeInfo.SELECTED) {
0559:                    // clean old selection
0560:                    if (selectedGraph != null) {
0561:                        if (overview != null) {
0562:                            if (overview.getGraph() != null) {
0563:                                overview.getGraph().clearSelection();
0564:                            }
0565:                        }
0566:
0567:                        selectedGraph.clearSelection();
0568:                    }
0569:
0570:                    if (changedElement != null) {
0571:                        // ***************************** find graph
0572:                        Graph g = null;
0573:                        XMLElement lastSel = changedElement;
0574:                        if (changedElements.size() > 0) {
0575:                            lastSel = (XMLElement) changedElements
0576:                                    .get(changedElements.size() - 1);
0577:                        }
0578:
0579:                        if (graphMap.containsKey(lastSel)) {
0580:                            g = getGraph((XMLCollectionElement) lastSel);
0581:                        }
0582:
0583:                        if (g == null && selectedGraph != null) {
0584:                            if (lastSel instanceof  Participant
0585:                                    && selectedGraph.getGraphManager()
0586:                                            .getGraphParticipant(
0587:                                                    (Participant) lastSel) != null) {
0588:                                g = selectedGraph;
0589:                            } else if (lastSel instanceof  ExtendedAttribute
0590:                                    && selectedGraph
0591:                                            .getGraphManager()
0592:                                            .getBubble(
0593:                                                    (ExtendedAttribute) lastSel) != null) {
0594:                                g = selectedGraph;
0595:                            } else if (lastSel instanceof  Activity
0596:                                    && selectedGraph.getGraphManager()
0597:                                            .getGraphActivity(
0598:                                                    (Activity) lastSel) != null) {
0599:                                g = selectedGraph;
0600:                            } else if (lastSel instanceof  Transition
0601:                                    && selectedGraph.getGraphManager()
0602:                                            .getGraphTransition(
0603:                                                    (Transition) lastSel) != null) {
0604:                                g = selectedGraph;
0605:                            }
0606:                        }
0607:
0608:                        if (g == null) {
0609:                            XMLElement parent = lastSel;
0610:                            do {
0611:                                parent = parent.getParent();
0612:                            } while (parent != null
0613:                                    && !(parent instanceof  ActivitySet || parent instanceof  WorkflowProcess));
0614:                            if (parent != null) {
0615:                                g = getGraph((XMLCollectionElement) parent);
0616:                            } else {
0617:                                if (selectedGraph != null) {
0618:                                    if (XMLUtil.getPackage(lastSel) == XMLUtil
0619:                                            .getPackage(selectedGraph
0620:                                                    .getXPDLObject()))
0621:                                        g = selectedGraph;
0622:                                }
0623:                            }
0624:                        }
0625:
0626:                        if (g == null) {
0627:                            Package sp = XMLUtil.getPackage(lastSel);
0628:                            if (sp != null) {
0629:                                List wps = sp.getWorkflowProcesses()
0630:                                        .toElements();
0631:                                if (wps.size() != 0) {
0632:                                    g = getGraph((XMLCollectionElement) wps
0633:                                            .get(0));
0634:                                }
0635:                            }
0636:                        }
0637:
0638:                        if (g != selectedGraph) {
0639:                            setSelectedGraph(g);
0640:                        }
0641:
0642:                        if (selectedGraph != null)
0643:                            selectedGraph.clearSelection();
0644:                        // ***************************** end of find graph
0645:
0646:                        // **************************** select elements
0647:                        WorkflowElement selectedElement = null;
0648:                        WorkflowElement lastSelected = null;
0649:                        if (selectedGraph != null) {
0650:                            List selectedElements = new ArrayList();
0651:                            List overviewElements = new ArrayList();
0652:                            List toCheck = new ArrayList();
0653:                            if (changedElements == null
0654:                                    || changedElements.size() == 0) {
0655:                                toCheck.add(changedElement);
0656:                            } else {
0657:                                toCheck.addAll(changedElements);
0658:                            }
0659:                            for (Iterator it = toCheck.iterator(); it.hasNext();) {
0660:                                XMLElement el = (XMLElement) it.next();
0661:
0662:                                selectedElement = selectedGraph
0663:                                        .getGraphInterface(el);
0664:                                if (overview != null
0665:                                        && selectedElement != null
0666:                                        && !(selectedElement instanceof  GraphTransitionInterface)) {
0667:                                    overviewElements.add(selectedElement);
0668:                                }
0669:
0670:                                if (selectedElement != null) {
0671:                                    lastSelected = selectedElement;
0672:                                    selectedElements.add(selectedElement);
0673:                                }
0674:                            }
0675:
0676:                            selectedGraph.selectElements(selectedElements
0677:                                    .toArray(), true, true);
0678:                            if (overview != null)
0679:                                overview.getGraph().selectElements(
0680:                                        overviewElements.toArray(), true, true);
0681:                        }
0682:
0683:                        if (lastSelected != null) {
0684:                            selectedGraph.scrollCellToVisible(lastSelected);
0685:                        }
0686:
0687:                    }
0688:                    // ********************************* END OF SELECTION EVENT
0689:                } else {
0690:                    if (changedElement instanceof  Package
0691:                            && (action == XMLElementChangeInfo.INSERTED || action == XMLElementChangeInfo.REMOVED)) {
0692:                        List toHandle = new ArrayList();
0693:                        if (changedElements != null) {
0694:                            toHandle.addAll(changedElements);
0695:                        }
0696:                        if (changedElements.size() == 0) {
0697:                            toHandle.add(changedElement);
0698:                        }
0699:                        Package mainPkg = JaWEManager.getInstance()
0700:                                .getJaWEController().getMainPackage();
0701:                        boolean adjustOtherPkgs = !toHandle.contains(mainPkg);
0702:
0703:                        for (int i = 0; i < changedElements.size(); i++) {
0704:                            Package pkg = (Package) changedElements.get(i);
0705:                            if (action == XMLElementChangeInfo.INSERTED) {
0706:                                insertPackage(pkg);
0707:                            } else if (action == XMLElementChangeInfo.REMOVED) {
0708:                                //System.err.println("Removing package "+pkg.getId());
0709:                                removePackage(pkg);
0710:                            }
0711:                        }
0712:                        //            System.err.println("ADJ OTHER PKGs="+adjustOtherPkgs);
0713:                        if (adjustOtherPkgs) {
0714:                            XPDLHandler xpdlh = JaWEManager.getInstance()
0715:                                    .getXPDLHandler();
0716:                            List allPkgs = new ArrayList(xpdlh.getAllPackages());
0717:                            allPkgs.removeAll(changedElements);
0718:                            Map allExtPkgPars = getAllPackageParticipants(changedElements);
0719:                            List allGraphElements = getAllWorkflowProcessesAndActivitySetsForAdjustment(allPkgs);
0720:
0721:                            //               System.err.println("AIPLGPARS="+allExtPkgPars);
0722:                            //               System.err.println("ALLGETUPD="+allGraphElements);
0723:                            Iterator it = allGraphElements.iterator();
0724:                            while (it.hasNext()) {
0725:                                XMLCollectionElement wpOrAs = (XMLCollectionElement) it
0726:                                        .next();
0727:                                //                  System.err.println("ADJUSTING WPORAS "+wpOrAs.getId()+" AFTER EPCHANGE");
0728:                                GraphUtilities
0729:                                        .adjustWorkflowProcessOrActivitySetOnUndoableChangeEvent(
0730:                                                new ArrayList(),
0731:                                                wpOrAs,
0732:                                                allExtPkgPars,
0733:                                                action == XMLElementChangeInfo.INSERTED);
0734:                            }
0735:                        }
0736:                    } else {
0737:                        if (action == XMLElementChangeInfo.INSERTED
0738:                                || action == XMLElementChangeInfo.REMOVED
0739:                                || action == XMLElementChangeInfo.UPDATED) {
0740:                            List l = new ArrayList();
0741:                            l.add(info);
0742:
0743:                            GraphUtilities
0744:                                    .adjustPackageOnUndoableChangeEvent(l);
0745:                        }
0746:                    }
0747:                }
0748:
0749:                adjustActions();
0750:            }
0751:
0752:            protected List getAllWorkflowProcessesAndActivitySetsForAdjustment(
0753:                    List pkgs) {
0754:                List l = new ArrayList();
0755:                Iterator it = pkgs.iterator();
0756:                while (it.hasNext()) {
0757:                    Package pkg = (Package) it.next();
0758:                    if (pkg.isReadOnly())
0759:                        continue;
0760:                    l.addAll(pkg.getWorkflowProcesses().toElements());
0761:                    Iterator itWPs = pkg.getWorkflowProcesses().toElements()
0762:                            .iterator();
0763:                    while (itWPs.hasNext()) {
0764:                        WorkflowProcess wp = (WorkflowProcess) itWPs.next();
0765:                        l.addAll(wp.getActivitySets().toElements());
0766:                    }
0767:                }
0768:                return l;
0769:            }
0770:
0771:            protected Map getAllPackageParticipants(List pkgs) {
0772:                Map m = new HashMap();
0773:                Iterator it = pkgs.iterator();
0774:                while (it.hasNext()) {
0775:                    Package pkg = (Package) it.next();
0776:                    Iterator itPars = pkg.getParticipants().toElements()
0777:                            .iterator();
0778:                    while (itPars.hasNext()) {
0779:                        Participant par = (Participant) itPars.next();
0780:                        String parId = par.getId();
0781:                        if (!m.containsKey(parId)) {
0782:                            m.put(parId, par);
0783:                        }
0784:                    }
0785:                }
0786:                return m;
0787:            }
0788:
0789:            protected GraphControllerPanel createPanel() {
0790:                GraphControllerPanel p = new GraphControllerPanel(this );
0791:                p.configure();
0792:                p.init();
0793:                return p;
0794:            }
0795:
0796:            public GraphMarqueeHandler getGraphMarqueeHandler() {
0797:                return graphMarqueeHandler;
0798:            }
0799:
0800:            public GraphObjectFactory getGraphObjectFactory() {
0801:                return graphObjectFactory;
0802:            }
0803:
0804:            public GraphObjectRendererFactory getGraphObjectRendererFactory() {
0805:                return graphObjectRendererFactory;
0806:            }
0807:
0808:            public XMLCollectionElement getDisplayedXPDLObject() {
0809:                if (selectedGraph != null)
0810:                    return selectedGraph.getXPDLObject();
0811:
0812:                return null;
0813:            }
0814:
0815:            public void createGraph(WorkflowProcess wp) {
0816:                if (graphMap.get(wp) != null)
0817:                    return;
0818:                Graph g = new Graph(this , new JaWEGraphModel(),
0819:                        graphMarqueeHandler, wp);
0820:                g.addGraphSelectionListener(this );
0821:                graphMap.put(wp, g);
0822:                g.clearSelection();
0823:                ToolTipManager.sharedInstance().registerComponent(g);
0824:                //      selectedGraph=g;
0825:                //      panel.graphAdded(g);
0826:            }
0827:
0828:            public void createGraph(ActivitySet as) {
0829:                if (graphMap.get(as) != null)
0830:                    return;
0831:                Graph g = new Graph(this , new JaWEGraphModel(),
0832:                        graphMarqueeHandler, as);
0833:                g.addGraphSelectionListener(this );
0834:                graphMap.put(as, g);
0835:                g.clearSelection();
0836:                ToolTipManager.sharedInstance().registerComponent(g);
0837:                //      selectedGraph=g;
0838:                //      panel.graphSelected(selectedGraph);
0839:            }
0840:
0841:            // TODO: handle exception
0842:            protected Graph createGraph() {
0843:                try {
0844:                    String gmhc = settings.getGraphClass();
0845:                    Constructor c = Class.forName(gmhc).getConstructor(
0846:                            new Class[] { this .getClass(),
0847:                                    JaWEGraphModel.class,
0848:                                    GraphMarqueeHandler.class });
0849:                    return (Graph) c.newInstance(new Object[] { this ,
0850:                            createGraphModel(), graphMarqueeHandler });
0851:                } catch (Exception ex) {
0852:                    return null;
0853:                }
0854:            }
0855:
0856:            protected JaWEGraphModel createGraphModel() {
0857:                try {
0858:                    String gm = settings.getGraphModelClass();
0859:                    return (JaWEGraphModel) Class.forName(gm).newInstance();
0860:                } catch (Exception ex) {
0861:                    return null;
0862:                }
0863:            }
0864:
0865:            public Graph getSelectedGraph() {
0866:                return selectedGraph;
0867:            }
0868:
0869:            public Graph getGraph(XMLCollectionElement wpOrAs) {
0870:                return (Graph) graphMap.get(wpOrAs);
0871:            }
0872:
0873:            protected void setSelectedGraph(Graph graph) {
0874:                Graph current = selectedGraph;
0875:                if (selectedGraph != null)
0876:                    selectedGraph.clearSelection();
0877:                selectedGraph = graph;
0878:                panel.graphSelected(selectedGraph);
0879:                if (selectedGraph != null) {
0880:                    getGraphMarqueeHandler().setSelectionMode();
0881:                }
0882:                if (overview != null) {
0883:                    overview.displayGraph();
0884:                }
0885:
0886:                if (hm != null) {
0887:                    hm.addToHistory((current != null) ? current.getXPDLObject()
0888:                            : null, (graph != null) ? graph.getXPDLObject()
0889:                            : null);
0890:                }
0891:                adjustActions();
0892:            }
0893:
0894:            public void selectGraphForElement(XMLCollectionElement cel) {
0895:                Graph current = selectedGraph;
0896:                Graph graph = (Graph) graphMap.get(cel);
0897:                selectedGraph = graph;
0898:                panel.graphSelected(selectedGraph);
0899:                if (selectedGraph != null) {
0900:                    JaWEManager.getInstance().getJaWEController()
0901:                            .getSelectionManager().setSelection(
0902:                                    selectedGraph.getXPDLObject(), true);
0903:
0904:                    getGraphMarqueeHandler().setSelectionMode();
0905:
0906:                    if (overview != null) {
0907:                        overview.displayGraph();
0908:                    }
0909:
0910:                }
0911:                if (hm != null) {
0912:                    hm.addToHistory((current != null) ? current.getXPDLObject()
0913:                            : null, (graph != null) ? graph.getXPDLObject()
0914:                            : null);
0915:                }
0916:                adjustActions();
0917:            }
0918:
0919:            protected void removeGraph(XMLCollectionElement wpOrAs) {
0920:                Graph g = (Graph) graphMap.remove(wpOrAs);
0921:                //System.out.println("Graph "+g+" for "+wpOrAs.getId()+" will be removed!");
0922:                ToolTipManager.sharedInstance().unregisterComponent(g);
0923:                g.removeGraphSelectionListener(this );
0924:
0925:                //      g.clearSelection();
0926:                //      Object[] elem = JaWEGraphModel.getAll(g.getModel());
0927:                //      g.getModel().remove(elem);
0928:                //      g.getGraphLayoutCache().removeCells(elem);
0929:
0930:                if (selectedGraph == g) {
0931:                    selectedGraph = null;
0932:                    panel.graphSelected(selectedGraph);
0933:                }
0934:
0935:                g.clearXPDLObjectReferences();
0936:                if (copyOrCutInfo != null) {
0937:                    copyOrCutInfo.removeGraphInfo(g);
0938:                }
0939:                if (overview != null) {
0940:                    overview.displayGraph();
0941:                }
0942:
0943:                if (hm != null) {
0944:                    hm.removeFromHistory(wpOrAs);
0945:                }
0946:                adjustActions();
0947:            }
0948:
0949:            public void displayPreviousGraph() {
0950:                if (hm != null && hm.canGoBack()) {
0951:                    XMLCollectionElement el = (XMLCollectionElement) hm
0952:                            .getPrevious((selectedGraph != null) ? selectedGraph
0953:                                    .getXPDLObject()
0954:                                    : null);
0955:                    Graph g = getGraph(el);
0956:                    if (g != selectedGraph) {
0957:                        selectedGraph = g;
0958:                        panel.graphSelected(selectedGraph);
0959:                        if (selectedGraph != null) {
0960:                            getGraphMarqueeHandler().setSelectionMode();
0961:                        }
0962:                        if (overview != null) {
0963:                            overview.displayGraph();
0964:                        }
0965:
0966:                        if (g != null) {
0967:                            JaWEManager.getInstance().getJaWEController()
0968:                                    .getSelectionManager().setSelection(
0969:                                            g.getXPDLObject(), true);
0970:                        }
0971:                    }
0972:                }
0973:                adjustActions();
0974:            }
0975:
0976:            public void displayNextGraph() {
0977:                if (hm != null && hm.canGoForward()) {
0978:                    XMLCollectionElement el = (XMLCollectionElement) hm
0979:                            .getNext((selectedGraph != null) ? selectedGraph
0980:                                    .getXPDLObject() : null);
0981:                    Graph g = getGraph(el);
0982:                    if (g != selectedGraph) {
0983:                        selectedGraph = g;
0984:                        panel.graphSelected(selectedGraph);
0985:                        if (selectedGraph != null) {
0986:                            getGraphMarqueeHandler().setSelectionMode();
0987:                        }
0988:                        if (overview != null) {
0989:                            overview.displayGraph();
0990:                        }
0991:
0992:                        if (g != null) {
0993:                            JaWEManager.getInstance().getJaWEController()
0994:                                    .getSelectionManager().setSelection(
0995:                                            g.getXPDLObject(), true);
0996:                        }
0997:                    }
0998:                }
0999:                adjustActions();
1000:            }
1001:
1002:            protected void insertPackage(Package pkg) {
1003:                Iterator it = pkg.getWorkflowProcesses().toElements()
1004:                        .iterator();
1005:                boolean isRO = pkg.isReadOnly();
1006:                while (it.hasNext()) {
1007:                    WorkflowProcess wp = (WorkflowProcess) it.next();
1008:                    createGraph(wp);
1009:                    if (settings.performAutomaticLayoutOnInsertion()) {
1010:
1011:                        if (isRO) {
1012:                            wp.setReadOnly(false);
1013:                        }
1014:                        SimpleGraphLayout.layoutGraph(this , getGraph(wp));
1015:                        if (isRO) {
1016:                            wp.setReadOnly(true);
1017:                        }
1018:                    }
1019:                    Iterator asi = wp.getActivitySets().toElements().iterator();
1020:                    while (asi.hasNext()) {
1021:                        ActivitySet as = (ActivitySet) asi.next();
1022:                        createGraph(as);
1023:                        if (settings.performAutomaticLayoutOnInsertion()) {
1024:                            if (isRO) {
1025:                                wp.setReadOnly(false);
1026:                            }
1027:                            SimpleGraphLayout.layoutGraph(this , getGraph(as));
1028:                            if (isRO) {
1029:                                wp.setReadOnly(true);
1030:                            }
1031:                        }
1032:                    }
1033:                }
1034:            }
1035:
1036:            protected void removePackage(Package pkg) {
1037:                Iterator it = pkg.getWorkflowProcesses().toElements()
1038:                        .iterator();
1039:                while (it.hasNext()) {
1040:                    WorkflowProcess wp = (WorkflowProcess) it.next();
1041:                    removeGraph(wp);
1042:                    Iterator asi = wp.getActivitySets().toElements().iterator();
1043:                    while (asi.hasNext()) {
1044:                        ActivitySet as = (ActivitySet) asi.next();
1045:                        removeGraph(as);
1046:                    }
1047:                }
1048:            }
1049:
1050:            protected XPDLElementChangeInfo createInfo(XMLElement main,
1051:                    List elements, int action) {
1052:                XPDLElementChangeInfo info = new XPDLElementChangeInfo();
1053:                info.setChangedElement(main);
1054:                if (elements.size() != 0)
1055:                    info.setChangedElement((XMLElement) elements.iterator()
1056:                            .next());
1057:                info.setChangedSubElements(elements);
1058:                info.setAction(action);
1059:                info.setSource(this );
1060:                return info;
1061:            }
1062:
1063:            public void setUpdateInProgress(boolean isInProgress) {
1064:                updateInProgress = isInProgress;
1065:            }
1066:
1067:            public boolean isUpdateInProgress() {
1068:                return updateInProgress;
1069:            }
1070:
1071:            public CopyOrCutInfo getCopyOrCutInfo() {
1072:                return copyOrCutInfo;
1073:            }
1074:
1075:            public GraphOverview getOverview() {
1076:                return overview;
1077:            }
1078:
1079:            public HistoryManager getHistoryManager() {
1080:                return hm;
1081:            }
1082:
1083:            protected void adjustActions() {
1084:                settings.adjustActions();
1085:                panel.enableDisableButtons();
1086:            }
1087:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.