Source Code Cross Referenced for ProcessLinkTool.java in  » Workflow-Engines » osbl-1_0 » newprocess » diagram » cust » tool » 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 » osbl 1_0 » newprocess.diagram.cust.tool 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * 
003:         */package newprocess.diagram.cust.tool;
004:
005:        import java.util.Collection;
006:        import java.util.Iterator;
007:        import java.util.List;
008:
009:        import newprocess.ConditionProxy;
010:        import newprocess.OperatorTerm;
011:        import newprocess.Root;
012:        import newprocess.diagram.edit.parts.ConditionProxyEditPart;
013:        import newprocess.diagram.edit.parts.ConditionTermConditionProxyEditPart;
014:        import newprocess.diagram.edit.parts.ConditionTermEditPart;
015:        import newprocess.diagram.edit.parts.OperatorTermSubTermEditPart;
016:        import newprocess.diagram.edit.parts.RootEditPart;
017:        import newprocess.diagram.providers.New_processElementTypes;
018:
019:        import org.eclipse.core.runtime.IAdaptable;
020:        import org.eclipse.emf.ecore.EObject;
021:        import org.eclipse.gef.EditPart;
022:        import org.eclipse.gef.EditPartViewer;
023:        import org.eclipse.gef.Request;
024:        import org.eclipse.gef.commands.Command;
025:        import org.eclipse.gef.requests.CreateConnectionRequest;
026:        import org.eclipse.gmf.runtime.diagram.core.preferences.PreferencesHint;
027:        import org.eclipse.gmf.runtime.diagram.ui.editparts.ShapeEditPart;
028:        import org.eclipse.gmf.runtime.diagram.ui.parts.DiagramCommandStack;
029:        import org.eclipse.gmf.runtime.diagram.ui.requests.CreateViewRequestFactory;
030:        import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants;
031:        import org.eclipse.gmf.runtime.diagram.ui.tools.UnspecifiedTypeConnectionTool;
032:        import org.eclipse.gmf.runtime.emf.type.core.IElementType;
033:        import org.eclipse.gmf.runtime.notation.Node;
034:        import org.eclipse.gmf.runtime.notation.View;
035:
036:        /**
037:         * @author sh
038:         *
039:         */
040:        public class ProcessLinkTool extends UnspecifiedTypeConnectionTool {
041:            // temporarily disable the autoexpose helper since it interferes with menu
042:            // selection.
043:            private boolean antiScroll = false;
044:
045:            /**
046:             * Constructor
047:             * @param connectionTypes
048:             */
049:            public ProcessLinkTool(List connectionTypes) {
050:                super (connectionTypes);
051:            }
052:
053:            /**
054:             * This method creates a complex link chain by 
055:             * one drag and drob operation from Operator to Proxy.
056:             * It means this link creation tool builds a chain between 
057:             * "EClass:Operator--EReference-->EClass:Port--EReference-->EClass:Proxy" 
058:             * and creates the Node "Port" and two Edges "OperatorHas" and "PortProxy"
059:             */
060:            @Override
061:            protected boolean handleCreateConnection() {
062:                //setAvoidDeactivation(true);
063:                eraseSourceFeedback();
064:
065:                // get edit parts & model objects 
066:                EditPart sourceEP = getSourceEditPart();
067:                EditPart targetEP = getTargetEditPart();
068:                if (sourceEP == null || targetEP == null)
069:                    return false;
070:                if (sourceEP instanceof  ShapeEditPart == false
071:                        || targetEP instanceof  ShapeEditPart == false)
072:                    return false;
073:                EObject sourceEO = (EObject) ((Node) sourceEP.getModel())
074:                        .getElement();
075:                EObject targetEO = (EObject) ((Node) targetEP.getModel())
076:                        .getElement();
077:
078:                // switch inversed link requests
079:                if (sourceEO instanceof  ConditionProxy) {
080:                    EditPart tempEP = sourceEP;
081:                    EObject tempEO = sourceEO;
082:                    sourceEP = targetEP;
083:                    sourceEO = targetEO;
084:                    targetEP = tempEP;
085:                    targetEO = tempEO;
086:                }
087:
088:                if (sourceEO instanceof  OperatorTerm
089:                        && targetEO instanceof  Root) {
090:                    EditPart tempEP = sourceEP;
091:                    EObject tempEO = sourceEO;
092:                    sourceEP = targetEP;
093:                    sourceEO = targetEO;
094:                    targetEP = tempEP;
095:                    targetEO = tempEO;
096:                }
097:
098:                /*
099:                if (sourceEO instanceof AbstractCondition)
100:                	createLink(sourceEP, targetEP);
101:                 */
102:
103:                if (sourceEO instanceof  Root) {
104:                    if (targetEO instanceof  ConditionProxy
105:                            && ((Root) sourceEO).acceptOutgoingLink(Root.PORT))
106:                        createChain();
107:                    if (targetEO instanceof  OperatorTerm
108:                            && ((Root) sourceEO)
109:                                    .acceptOutgoingLink(Root.OPERATOR)
110:                            && ((OperatorTerm) targetEO).acceptIncomingLink())
111:                        createLink(sourceEP, targetEP);
112:                }
113:
114:                if (sourceEO instanceof  OperatorTerm) {
115:                    if (targetEO instanceof  ConditionProxy)
116:                        createChain();
117:                    if (targetEO instanceof  OperatorTerm
118:                            && ((OperatorTerm) targetEO).acceptIncomingLink()
119:                            && sourceEO.eContainer() == targetEO.eContainer())
120:                        createLink(sourceEP, targetEP);
121:                }
122:
123:                return true;
124:            }
125:
126:            /**
127:             * 
128:             * @return
129:             */
130:            private EditPart getSourceEditPart() {
131:                return ((CreateConnectionRequest) getSourceRequest())
132:                        .getSourceEditPart();
133:            }
134:
135:            /**
136:             * @author ts & sh
137:             * The creation of the  Root / AbstractOperator - Term - Proxy chain
138:             */
139:            private void createChain() {
140:                EditPart termEP = null;
141:                ConditionProxyEditPart proxyEP = null;
142:
143:                if (getSourceEditPart() instanceof  ConditionProxyEditPart) {
144:                    termEP = getTargetEditPart();
145:                    proxyEP = (ConditionProxyEditPart) getSourceEditPart();
146:                } else {
147:                    termEP = getSourceEditPart();
148:                    proxyEP = (ConditionProxyEditPart) getTargetEditPart();
149:                }
150:
151:                EditPart conditionEP = null;
152:                if (termEP instanceof  RootEditPart)
153:                    conditionEP = termEP.getParent();
154:                else
155:                    // navigate behind the compartment
156:                    conditionEP = termEP.getParent().getParent();
157:
158:                // create the PortEditPart
159:                ConditionTermEditPart portEP = createPort(conditionEP);
160:
161:                // create Operator || RootPort - Port Link
162:                createLink(termEP, portEP);
163:
164:                // create Port - Proxy Link
165:                createLink(portEP, proxyEP);
166:            }
167:
168:            /**
169:             * Creates the Term
170:             * @param container
171:             * @return created TermEditPart
172:             */
173:            private ConditionTermEditPart createPort(EditPart container) {
174:                if (container == null)
175:                    return null;
176:
177:                // create a Request for fetching the term creation command
178:                IElementType termType = New_processElementTypes.ConditionTerm_3005;
179:                PreferencesHint hint = getPreferencesHint();
180:                Request req = CreateViewRequestFactory.getCreateShapeRequest(
181:                        termType, hint);
182:                setTargetRequest(req);
183:                Command com = container.getCommand(req);
184:
185:                // execute the term creation command
186:                if (com == null)
187:                    return null;
188:                setCurrentCommand(com);
189:                antiScroll = true;
190:                executeCurrentCommand();
191:                antiScroll = false;
192:
193:                // search for the created Term EditPart
194:                EditPart editPart = findEditPart(com, termType);
195:                if (editPart instanceof  ConditionTermEditPart)
196:                    return (ConditionTermEditPart) editPart;
197:
198:                return null;
199:            }
200:
201:            /**
202:             * Creates the link from the given source Edit Part to the given
203:             * Target Edit Part
204:             * @param sourceEP
205:             * @param targetEP
206:             */
207:            private void createLink(EditPart sourceEP, EditPart targetEP) {
208:                if (sourceEP == null || targetEP == null)
209:                    return;
210:
211:                // create the Request for the demanded link
212:                CreateConnectionRequest connectionRequest = (CreateConnectionRequest) createTargetRequest();
213:                connectionRequest.setTargetEditPart(sourceEP);
214:                connectionRequest
215:                        .setType(RequestConstants.REQ_CONNECTION_START);
216:
217:                // only if the connection is supported will we get a non null
218:                // command from the sourceEditPart
219:                if (sourceEP.getCommand(connectionRequest) == null)
220:                    return;
221:                connectionRequest.setSourceEditPart(sourceEP);
222:                connectionRequest.setTargetEditPart(targetEP);
223:                connectionRequest.setType(RequestConstants.REQ_CONNECTION_END);
224:
225:                // get the command of the target to create the link
226:                Command command = targetEP.getCommand(connectionRequest);
227:                if (command == null)
228:                    return;
229:
230:                // execute the link creation command
231:                setCurrentCommand(command);
232:                antiScroll = true;
233:                executeCurrentCommand();
234:                antiScroll = false;
235:
236:                // if no Viewer is set we borrow one from the source EP
237:                if (getCurrentViewer() == null)
238:                    setViewer(sourceEP.getViewer());
239:
240:                selectAddedObject(getCurrentViewer(), DiagramCommandStack
241:                        .getReturnValues(command));
242:
243:                deactivate();
244:            }
245:
246:            /**
247:             * After executing a CreateElementCommand or a CreateRelationshipCommand
248:             * this method searchs for the created EditPart by the given command
249:             * and EdigPart type
250:             * 
251:             * @param command
252:             * @param targetEditPart
253:             * @return
254:             */
255:            private EditPart findEditPart(Command command,
256:                    IElementType editPartType) {
257:                // there is the need to search for the concerning EditPart
258:                // by this silly complex algorithm
259:                Collection objects = DiagramCommandStack
260:                        .getReturnValues(command);
261:                EditPartViewer viewer = getCurrentViewer();
262:
263:                for (Iterator i = objects.iterator(); i.hasNext();) {
264:                    Object object = i.next();
265:                    if (object instanceof  IAdaptable) {
266:                        Object editPart = viewer.getEditPartRegistry().get(
267:                                ((IAdaptable) object).getAdapter(View.class));
268:
269:                        // check for what kind of EditPart we are searching for
270:                        if (editPartType
271:                                .equals(New_processElementTypes.ConditionTerm_3005)) {
272:                            if (editPart instanceof  ConditionTermEditPart)
273:                                return (ConditionTermEditPart) editPart;
274:                        } else if (editPartType
275:                                .equals(New_processElementTypes.ConditionTermConditionProxy_4004)) {
276:                            if (editPart instanceof  ConditionTermConditionProxyEditPart)
277:                                return (ConditionTermConditionProxyEditPart) editPart;
278:                        } else if (editPartType
279:                                .equals(New_processElementTypes.OperatorTermSubTerm_4003)) {
280:                            if (editPart instanceof  OperatorTermSubTermEditPart) {
281:                                return (OperatorTermSubTermEditPart) editPart;
282:                            }
283:                        }
284:                    }
285:                }
286:                return null;
287:            }
288:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.