DecoratedConnection.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. /**
  2. * 节点连线
  3. */
  4. draw2d.DecoratedConnection=function(){
  5. draw2d.Connection.call(this);
  6. var decorator = new draw2d.ArrowConnectionDecorator();
  7. var black = new draw2d.Color(0,0,0);
  8. decorator.setBackgroundColor(black);
  9. this.setTargetDecorator(decorator);
  10. this.setRouter(new draw2d.ManhattanConnectionRouter());
  11. this.setLineWidth(1);
  12. this.setColor(black);
  13. this.lineId=null;
  14. this.lineName=null;
  15. this.condition=null;
  16. this.listeners=new draw2d.ArrayList();
  17. this.label=null;
  18. };
  19. draw2d.DecoratedConnection.prototype=new draw2d.Connection();
  20. draw2d.DecoratedConnection.prototype.type="DecoratedConnection";
  21. draw2d.DecoratedConnection.prototype.getConditionXML=function(){
  22. var xml = '';
  23. if(this.condition != null&&this.condition!=''){
  24. //author:zhangdaihao date:20140802 for:去掉空格
  25. var condition_value = this.condition.replace(/(^\s*)|(\s*$)/g,"");
  26. xml = '<conditionExpression xsi:type="tFormalExpression"><![CDATA['+condition_value+']]></conditionExpression>\n';
  27. }
  28. return xml;
  29. }
  30. draw2d.DecoratedConnection.prototype.toXML=function(){
  31. var sourceId = null;
  32. var type=this.getSource().getParent().type;
  33. if(type=='draw2d.Start'){
  34. sourceId = this.getSource().getParent().eventId;
  35. }
  36. else if(type=='draw2d.ExclusiveGateway'){
  37. sourceId = this.getSource().getParent().gatewayId;
  38. }else if(type=='draw2d.ParallelGateway'){
  39. sourceId = this.getSource().getParent().gatewayId;
  40. }else if(type=='draw2d.TimerBoundary'){
  41. sourceId = this.getSource().getParent().boundaryId;
  42. }else if(type=='draw2d.ErrorBoundary'){
  43. sourceId = this.getSource().getParent().boundaryId;
  44. }else if(type=='draw2d.CallActivity'){
  45. sourceId = this.getSource().getParent().subProcessId;
  46. }else{
  47. sourceId = this.getSource().getParent().taskId;
  48. }
  49. var targetId = null;
  50. type=this.getTarget().getParent().type;
  51. if(type=='draw2d.End'){
  52. targetId = this.getTarget().getParent().eventId;
  53. }else if(type=='draw2d.ExclusiveGateway'){
  54. targetId = this.getTarget().getParent().gatewayId;
  55. }else if(type=='draw2d.ParallelGateway'){
  56. targetId = this.getTarget().getParent().gatewayId;
  57. }else if(type=='draw2d.TimerBoundary'){
  58. targetId = this.getTarget().getParent().boundaryId;
  59. }else if(type=='draw2d.ErrorBoundary'){
  60. targetId = this.getTarget().getParent().boundaryId;
  61. }else if(type=='draw2d.CallActivity'){
  62. targetId = this.getTarget().getParent().subProcessId;
  63. }else{
  64. targetId = this.getTarget().getParent().taskId;
  65. }
  66. var name="";
  67. var lineName = trim(this.lineName);
  68. if(lineName != null && lineName != "")
  69. name = lineName;
  70. var xml = '<sequenceFlow id="'+this.lineId+'" name="'+name+'" sourceRef="'+sourceId+'" targetRef="'+targetId+'">\n';
  71. xml = xml+this.getConditionXML();
  72. xml+=this.getListenersXML();
  73. xml = xml+'</sequenceFlow>\n';
  74. return xml;
  75. };
  76. draw2d.DecoratedConnection.prototype.setLabel=function(text){
  77. if(this.label == null){
  78. this.label=new draw2d.Label(text);
  79. this.label.setFontSize(8);
  80. this.label.setAlign("center");
  81. //this.label.setBackgroundColor(new draw2d.Color(230,230,250));
  82. //this.label.setBorder(new draw2d.LineBorder(1));
  83. this.addFigure(this.label,new draw2d.ManhattanMidpointLocator(this));
  84. }else{
  85. this.label.setText(text);
  86. }
  87. };
  88. draw2d.DecoratedConnection.prototype.toBpmnDI=function(){
  89. var xml='<bpmndi:BPMNEdge bpmnElement="'+this.lineId+'" id="BPMNEdge_'+this.lineId+'">\n';
  90. // var startX = this.getSource().getAbsoluteX();
  91. // var startY = this.getSource().getAbsoluteY();
  92. // var endX = this.getTarget().getAbsoluteX();
  93. // var endY = this.getTarget().getAbsoluteY();
  94. var points=this.getPoints();
  95. for(var i=0;i<points.size;i++){
  96. xml=xml+'<omgdi:waypoint x="'+points.get(i).x+'" y="'+points.get(i).y+'" />\n';
  97. }
  98. xml=xml+'</bpmndi:BPMNEdge>\n';
  99. return xml;
  100. };
  101. draw2d.DecoratedConnection.prototype.onDoubleClick=function(){
  102. nodeid= this.getId();
  103. openProperties(nodeid,'flowProperties');
  104. };
  105. draw2d.DecoratedConnection.prototype.getContextMenu=function(){
  106. if(this.workflow.disabled)return null;
  107. var menu =new draw2d.ContextMenu(100, 50);
  108. var data = {line:this};
  109. menu.appendMenuItem(new draw2d.ContextMenuItem("属性", "properties-icon",data,function(x,y)
  110. {
  111. var data = this.getData();
  112. var line = data.line;
  113. nodeid = line.getId();
  114. if(typeof openFlowProperties != "undefined"){
  115. openProperties(nodeid,'flowProperties');
  116. }
  117. }));
  118. menu.appendMenuItem(new draw2d.ContextMenuItem("删除", "icon-remove",data,function(x,y)
  119. {
  120. var data = this.getData();
  121. var line = data.line;
  122. var lid = line.getId();
  123. var wf = line.getWorkflow();
  124. wf.getCommandStack().execute(new draw2d.CommandDelete(line));
  125. //wf.removeFigure(line);
  126. }));
  127. return menu;
  128. };
  129. draw2d.DecoratedConnection.prototype.getListenersXML=function(){
  130. var xml = '';
  131. for(var i=0;i<this.listeners.getSize();i++){
  132. var listener = this.listeners.get(i);
  133. xml=xml+listener.toXML();
  134. }
  135. if(xml!=null && xml!=''){
  136. xml = '<extensionElements> '+ xml +' </extensionElements>';
  137. }
  138. return xml;
  139. };
  140. draw2d.DecoratedConnection.prototype.getListener=function(id){
  141. for(var i=0;i<this.listeners.getSize();i++){
  142. var listener = this.listeners.get(i);
  143. if(listener.getId()=== id){
  144. return listener;
  145. }
  146. }
  147. };
  148. draw2d.DecoratedConnection.prototype.deleteListener=function(id){
  149. var listener = this.getListener(id);
  150. this.listeners.remove(listener);
  151. };
  152. draw2d.DecoratedConnection.prototype.setListener=function(listener){
  153. this.listeners.add(listener);
  154. };