all-workflowsysnavigation.js 52 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973
  1. Ext.ns('App');
  2. App = {
  3. webforms: {},
  4. init: function() {
  5. Ext.QuickTips.init();
  6. this.propertyManager = new App.property.PropertyManager();
  7. this.workbenchWindow = new Gef.ui.support.DefaultWorkbenchWindow();
  8. var viewport = new Ext.Viewport({
  9. id:'viewport',
  10. layout: 'border',
  11. items: [
  12. this.createNorth(),
  13. this.createSouth(),
  14. this.createWest(),
  15. this.createEast(),
  16. this.createCenter()
  17. ],
  18. listeners: {
  19. click: {
  20. element: 'el', //bind to the underlying el property on the panel
  21. fn: function(){ console.log('click el'); }
  22. },
  23. dblclick: {
  24. element: 'body', //bind to the underlying body property on the panel
  25. fn: function(){ console.log('dblclick body'); }
  26. }
  27. }
  28. });
  29. this.initEditor();
  30. setTimeout(function() {
  31. Ext.get('loading').remove();
  32. Ext.get('loading-mask').fadeOut({remove:true});
  33. }, 100);
  34. },
  35. initEditor: function() {
  36. var xml = "",me=this,data = {};;
  37. var editor = new Gef.jbs.ExtEditor();
  38. var input = new Gef.jbs.JBSEditorInput();
  39. var formCondition=getUrlParam('formCondition');
  40. if(formCondition){
  41. var jdId=formCondition.split('IS')[1];
  42. Ext.Ajax.request({
  43. url: basePath + 'common/getJProcessDeployInfo.action',
  44. params: {
  45. jdId: jdId,
  46. type: 'sysnavigation'
  47. },
  48. success: function(response){
  49. var text = new Ext.decode(response.responseText);
  50. xmlInfo = text.xmlInfo;
  51. xml = xmlInfo;
  52. data.pr_defname = text.processDefName;
  53. data.pr_caller = text.caller;
  54. data.pr_enabled = text.enabled;
  55. data.pr_descn = text.processDescription;
  56. input.readXml(xml);
  57. me.workbenchWindow.getActivePage().openEditor(editor, input);
  58. me.workbenchWindow.render();
  59. Gef.activeEditor = editor;
  60. me.propertyManager.initSelectionListener2(Gef.activeEditor,data);
  61. }
  62. });
  63. }else {
  64. xml = "<process xmlns='http://jbpm.org/4.4/jpdl' name='sale'> "+
  65. "<start g='253,67,48,48' name='start 1'>"+
  66. "<transition to='end 1'/></start>"+
  67. "<end g='247,239,48,48' name='end 1'/></process>";
  68. input.readXml(xml);
  69. me.workbenchWindow.getActivePage().openEditor(editor, input);
  70. me.workbenchWindow.render();
  71. Gef.activeEditor = editor;
  72. me.propertyManager.initSelectionListener(Gef.activeEditor);
  73. }
  74. },
  75. getProcessModel: function() {
  76. var viewer = Gef.activeEditor.getGraphicalViewer();
  77. var processEditPart = viewer.getContents();
  78. return processEditPart.model;
  79. },
  80. createNorth: function() {
  81. var p = null;
  82. if (Gef.MODE_DEMO === true) {
  83. p = new Ext.Panel({
  84. region: 'north'
  85. });
  86. } else {
  87. p = new Ext.Panel({
  88. region: 'north'
  89. //height: 60,
  90. /* html: '<div id="plan"><h1 id="pageh1">流程设计器 <h1></div>'*/
  91. });
  92. }
  93. App.northPanel = p;
  94. return p;
  95. },
  96. createSouth: function() {
  97. var p = this.propertyManager.getBottom();
  98. return p;
  99. },
  100. createWest: function() {
  101. var p = new App.PalettePanel({
  102. collapsible: true //修复bug 可以伸缩 zhouy
  103. });
  104. App.westPanel = p;
  105. return p;
  106. },
  107. createEast: function() {
  108. var p = this.propertyManager.getRight();
  109. p.setWidth(450);
  110. p.on('render',function(){
  111. p.getEl().on('mouseover',function(){
  112. Gef.activeEditor.disable();
  113. });
  114. p.getEl().on('mouseout',function(){
  115. Gef.activeEditor.enable();
  116. });
  117. },this);
  118. return p;
  119. },
  120. createCenter: function() {
  121. var p = new App.CanvasPanel();
  122. App.centerPanel = p;
  123. return p;
  124. },
  125. getSelectionListener: function() {
  126. if (!this.selectionListener) {
  127. this.selectionListener = new Gef.jbs.ExtSelectionListener(null);
  128. }
  129. return this.selectionListener;
  130. }
  131. };
  132. Gef.PALETTE_TYPE = 'accordion';
  133. Ext.onReady(App.init, App);
  134. Gef.DEPLOY_URL = '../../console/d!deployJpdl.do';
  135. Gef.SAVE_URL = '../../console/d!saveJpdl.do';
  136. App.CanvasPanel = Ext.extend(Ext.Panel, {
  137. id:'canvaspanel',
  138. xmlValidate:function(){
  139. var xmlString = arguments[0];
  140. var xmlDoc = null;
  141. try //IE 浏览器
  142. {
  143. xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
  144. xmlDoc.async="false";
  145. xmlDoc.loadXML(xmlString);
  146. }
  147. catch(e)
  148. {
  149. console.log(e.message);
  150. try //Firefox, Mozilla, 浏览器
  151. {
  152. parser=new DOMParser();
  153. xmlDoc=parser.parseFromString(xmlString,"text/xml");
  154. var sqls = xmlDoc.getElementsByTagName('sql');
  155. var decisions = xmlDoc.getElementsByTagName('decision');
  156. return true;
  157. }
  158. catch(e) {alert(e.message); return false;}
  159. }
  160. },
  161. initComponent: function() {
  162. this.region = 'center';
  163. this.autoScroll = true;
  164. this.width=500;
  165. var mater=null;
  166. var contents=null;//行选择之后的xml
  167. var resetlength=null;//新建之后的xml的长度
  168. this.tbar = new Ext.Toolbar([{
  169. text: '新建',
  170. iconCls: 'tb-new',
  171. handler: function() {
  172. App.propertyManager.initSelectionListener(Gef.activeEditor);
  173. var model=Gef.activeEditor.getGraphicalViewer().getRootEditPart().getContents().getModel();
  174. if(model.dom.getAttribute('data')){
  175. model.dom.removeAttribute('data');
  176. }
  177. Ext.getCmp('FirstForm').getForm().reset();
  178. // Ext.getCmp('pr_constructor').setValue(en_uu);
  179. Gef.activeEditor.reset();
  180. resetlength=Gef.activeEditor.serial().length;
  181. contents=null;
  182. // App.propertyManager.initSelectionListener(editor);
  183. // Ext.getCmp('pr_constructor').setValue(en_uu);
  184. }
  185. }, {
  186. text: '导入',
  187. iconCls: 'tb-webform',
  188. handler: function() {
  189. var xml = Gef.activeEditor.serial();
  190. //alert(xml);
  191. if (!this.openWin) {
  192. this.openWin = new Ext.Window({
  193. title: 'xml',
  194. layout: 'fit',
  195. width: 500,
  196. height: 300,
  197. closeAction: 'hide',
  198. modal: true,
  199. items: [{
  200. id: '__gef_jbpm4_xml_import__',
  201. xtype: 'textarea'
  202. }],
  203. buttons: [{
  204. text: '导入',
  205. handler: function() {
  206. var xml = Ext.getDom('__gef_jbpm4_xml_import__').value;
  207. Gef.activeEditor.resetAndOpen(xml);
  208. this.openWin.hide();
  209. var viewer = Gef.activeEditor.getGraphicalViewer();
  210. var browserListener = viewer.getBrowserListener();
  211. var editor=Gef.activeEditor;
  212. var data=Ext.getCmp('FirstForm').getForm().getValues();
  213. console.log(data);
  214. App.propertyManager.initSelectionListener2(Gef.activeEditor);
  215. Ext.getCmp("FirstForm").items.items[0].setValue(data.pr_defname);
  216. Ext.getCmp("FirstForm").items.items[1].setValue(data.pr_caller);
  217. Ext.getCmp("FirstForm").items.items[2].setValue(data.pr_descn);
  218. },
  219. scope: this
  220. }, {
  221. text: '取消',
  222. handler: function() {
  223. this.openWin.hide();
  224. },
  225. scope: this
  226. }]
  227. });
  228. this.openWin.on('show', function() {
  229. Gef.activeEditor.disable();
  230. });
  231. this.openWin.on('hide', function() {
  232. Gef.activeEditor.enable();
  233. });
  234. }
  235. this.openWin.show(null, function() {
  236. Ext.getDom('__gef_jbpm4_xml_import__').value = xml;
  237. });
  238. }
  239. }, {
  240. text: '导出',
  241. iconCls: 'tb-prop',
  242. handler: function() {
  243. var xml = Gef.activeEditor.serial();
  244. if (!this.openWin) {
  245. this.openWin = new Ext.Window({
  246. title: 'xml',
  247. layout: 'fit',
  248. width: 500,
  249. height: 300,
  250. closeAction: 'hide',
  251. modal: true,
  252. items: [{
  253. id: '__gef_jbpm4_xml_export__',
  254. xtype: 'textarea'
  255. }],
  256. buttons: [{
  257. text: '关闭',
  258. handler: function() {
  259. this.openWin.hide();
  260. },
  261. scope: this
  262. }]
  263. });
  264. this.openWin.on('show', function() {
  265. Gef.activeEditor.disable();
  266. });
  267. this.openWin.on('hide', function() {
  268. Gef.activeEditor.enable();
  269. });
  270. }
  271. this.openWin.show(null, function() {
  272. Ext.getDom('__gef_jbpm4_xml_export__').value = xml;
  273. /*document.getElementById('__gef_jbpm4_xml_export__').value=xml;*/
  274. });
  275. }
  276. }, {
  277. text: '保存',
  278. iconCls: 'tb-save',
  279. handler: function() {
  280. var editor = Gef.activeEditor;
  281. var xml = editor.serial();
  282. var result =Ext.getCmp('canvaspanel').xmlValidate(xml);// 自定义校验 true/false
  283. if(!result){
  284. console.log("xml 格式错误!");
  285. return ;
  286. }else{
  287. console.log("自定义 校验通过,可以正常保存 !");
  288. }
  289. var model=editor.getGraphicalViewer().getRootEditPart().getContents().getModel();
  290. App.propertyManager.initSelectionListener(editor);//add 选中面板便于拿到form 不是最好的解决办法 2012-08-21
  291. var form=Ext.getCmp('FirstForm');
  292. /** var isValid = new Validation(editor).validate();// 预定义校验器;
  293. if (!isValid) {
  294. return false;
  295. } */
  296. if(form.getForm().isValid()){
  297. if(!form.getForm().isDirty()){
  298. var r = form.getForm().getValues();
  299. if(r.pr_defname==null||r.pr_defname==''){
  300. Ext.Msg.alert("提示","请填写右边属性面板必填项!");
  301. form.items.items[0].fireEvent('focus');
  302. return;
  303. }
  304. Ext.Msg.wait('正在保存...');
  305. Ext.Ajax.request({//保存流程数据到JProcessDeploy表中,存在则修改 2013-3-5 17:23:01 wuw
  306. method: 'post',
  307. url: basePath+'common/deployProcess.action',
  308. success: function(response) {
  309. var o = null;
  310. try {
  311. o = Ext.decode(response.responseText);
  312. if (o.success === true) {
  313. Ext.Msg.alert('提示', '保存成功, 你的流程定义编号为:'+o.id);
  314. } else {
  315. Ext.Msg.alert('错误', o.errors.msg);
  316. }
  317. } catch(e) {
  318. /*Ext.Msg.alert('系统错误', response.responseText);*/
  319. /* if(o.exceptionInfo){
  320. showError(o.exceptionInfo);
  321. }*/
  322. Ext.Msg.alert('保存失败','请检查 xml文件格式!' );
  323. }
  324. },
  325. failure: function(response) {
  326. /* Ext.Msg.alert('系统错误', response.responseText);*/
  327. Ext.Msg.alert('保存失败','请检查 xml文件格式!' );
  328. },
  329. params: {
  330. processDefinitionName: r.pr_defname,
  331. processDescription: r.pr_descn,
  332. caller:r.pr_caller,
  333. type:'sysnavigation',
  334. enabled:r.pr_enabled,
  335. xml: xml,
  336. parentId:0
  337. }
  338. });
  339. }else{
  340. /*Ext.Msg.alert('提示','你未对流程做任何处理!');*/
  341. alert("请填写右边属性面板必填项!");
  342. }
  343. }else{
  344. Ext.Msg.alert('提示','请填写右边必填条款!');
  345. }
  346. }
  347. },{
  348. text: '清空',
  349. iconCls: 'tb-clear',
  350. handler: function() {
  351. Gef.activeEditor.clear();
  352. }
  353. }, {
  354. text: '撤销',
  355. iconCls: 'tb-undo',
  356. handler: function() {
  357. var viewer = Gef.activeEditor.getGraphicalViewer();
  358. var browserListener = viewer.getBrowserListener();
  359. var selectionManager = browserListener.getSelectionManager();
  360. selectionManager.clearAll();
  361. var commandStack = viewer.getEditDomain().getCommandStack();
  362. commandStack.undo();
  363. },
  364. scope: this
  365. },{
  366. text:'流程删除',
  367. iconCls: 'tb-delete',
  368. handler: this.deleteProcess,
  369. scope: this
  370. }, {
  371. text: '删除',
  372. iconCls: 'tb-delete',
  373. handler: this.removeSelected,
  374. scope: this
  375. }]);
  376. App.CanvasPanel.superclass.initComponent.call(this);
  377. },
  378. afterRender: function() {
  379. App.CanvasPanel.superclass.afterRender.call(this);
  380. var width =window.innerWidth-610;
  381. var height =1000;
  382. Ext.DomHelper.append(this.body, [{
  383. id: '__gef_jbs__',
  384. tag: 'div',
  385. style: 'width:' + (width + 10) + 'px;height:' + (height + 10) + 'px;',
  386. children: [{
  387. id: '__gef_jbs_center__',
  388. tag: 'div',
  389. style: 'width:' + width + 'px;height:' + height + 'px;float:left;'
  390. }, {
  391. id: '__gef_jbs_right__',
  392. tag: 'div',
  393. style: 'width:10px;height:' + height + 'px;float:left;background-color:#EEEEEE;cursor:pointer;'
  394. }, {
  395. id: '__gef_jbs_bottom__',
  396. tag: 'div',
  397. style: 'width:' + (width + 10) + 'px;height:10px;float:left;background-color:#EEEEEE;cursor:pointer;'
  398. }]
  399. }]);
  400. var rightEl = Ext.fly('__gef_jbs_right__');
  401. rightEl.on('mouseover', function(e) {
  402. var t = e.getTarget();
  403. t.style.backgroundColor = 'yellow';
  404. t.style.backgroundImage = 'url(images/arrow/arrow-right.png)';
  405. });
  406. rightEl.on('mouseout', function(e) {
  407. var t = e.getTarget();
  408. t.style.backgroundColor = '#EEEEEE';
  409. t.style.backgroundImage = '';
  410. });
  411. rightEl.on('click', function(e) {
  412. Ext.fly('__gef_jbs__').setWidth(Ext.fly('__gef_jbs__').getWidth() + 100);
  413. Ext.fly('__gef_jbs_center__').setWidth(Ext.fly('__gef_jbs_center__').getWidth() + 100);
  414. Ext.fly('__gef_jbs_bottom__').setWidth(Ext.fly('__gef_jbs_bottom__').getWidth() + 100);
  415. Gef.activeEditor.addWidth(100);
  416. });
  417. var bottomEl = Ext.fly('__gef_jbs_bottom__');
  418. bottomEl.on('mouseover', function(e) {
  419. var t = e.getTarget();
  420. t.style.backgroundColor = 'yellow';
  421. t.style.backgroundImage = 'url(images/arrow/arrow-bottom.png)';
  422. });
  423. bottomEl.on('mouseout', function(e) {
  424. var t = e.getTarget();
  425. t.style.backgroundColor = '#EEEEEE';
  426. t.style.backgroundImage = '';
  427. });
  428. rightEl.on('click', function(e) {
  429. Ext.fly('__gef_jbs__').setHeight(Ext.fly('__gef_jbs__').getHeight() + 100);
  430. Ext.fly('__gef_jbs_center__').setHeight(Ext.fly('__gef_jbs_center__').getHeight() + 100);
  431. Ext.fly('__gef_jbs_right__').setHeight(Ext.fly('__gef_jbs_right__').getHeight() + 100);
  432. Gef.activeEditor.addHeight(100);
  433. });
  434. // this.body.on('contextmenu', this.onContextMenu, this);//取消面板上 右键 操作 2012-08-24
  435. },
  436. onContextMenu: function(e) { //面板上右键操作。。。上面已经被注释,现在没用 2013-3-6 10:30:53 wuw
  437. if (!this.contextMenu) {
  438. this.contextMenu = new Ext.menu.Menu({
  439. items: [{
  440. text: '详细配置',
  441. iconCls: 'tb-prop',
  442. handler: this.showWindow,
  443. scope: this
  444. }, {
  445. text: '删除',
  446. iconCls: 'tb-remove',
  447. handler: this.removeSelected,
  448. scope: this
  449. }]
  450. });
  451. }
  452. e.preventDefault();
  453. this.contextMenu.showAt(e.getXY());
  454. },
  455. showWindow: function() {
  456. App.propertyManager.changePropertyStatus('max');
  457. },
  458. deleteProcess:function(){
  459. var id=parent.Ext.getCmp('jd_id').getValue();
  460. if(id){
  461. Ext.Ajax.request({
  462. url : basePath + 'common/deleteProcessDeploy.action',
  463. params: {
  464. id:id
  465. },
  466. method : 'post',
  467. callback : function(options,success,response){
  468. var localJson = new Ext.decode(response.responseText);
  469. if(localJson.exceptionInfo){
  470. showError(localJson.exceptionInfo);
  471. }
  472. if(localJson.success){
  473. Ext.Msg.alert('提示','删除成功!',function(){
  474. var main = parent.parent.Ext.getCmp("content-panel");
  475. main.getActiveTab().close();
  476. });
  477. }
  478. }
  479. });
  480. }
  481. },
  482. removeSelected: function() {
  483. var viewer = Gef.activeEditor.getGraphicalViewer();
  484. var browserListener = viewer.getBrowserListener();
  485. var selectionManager = browserListener.getSelectionManager();
  486. var edge = selectionManager.selectedConnection;
  487. var nodes = selectionManager.items;
  488. var request = {};
  489. if (edge != null) {
  490. request.role = {
  491. name: 'REMOVE_EDGE'
  492. };
  493. this.executeCommand(edge, request);
  494. selectionManager.removeSelectedConnection();
  495. } else if (nodes.length > 0) {
  496. request.role = {
  497. name: 'REMOVE_NODES',
  498. nodes: nodes
  499. };
  500. this.executeCommand(viewer.getContents(), request);
  501. selectionManager.clearAll();
  502. }
  503. },
  504. executeCommand: function(editPart, request) {
  505. var command = editPart.getCommand(request);
  506. // console.log(command); 他妈的,问题就出现在这一行,当一个task 节点 有两个节点时,上一行代码就有问题啊 啊啊啊啊啊啊啊啊啊啊啊啊,哈哈哈
  507. if (command != null) {
  508. Gef.activeEditor.getGraphicalViewer().getEditDomain().getCommandStack().execute(command);
  509. }
  510. }
  511. });
  512. /*
  513. * Compressed by JSA(www.xidea.org)
  514. */
  515. Layout = function(editor) {
  516. this.editor = editor;
  517. this.processEditPart = editor.getGraphicalViewer().getContents();
  518. this.processModel = this.processEditPart.getModel();
  519. };
  520. Layout.prototype = {
  521. doLayout: function() {
  522. var diagram = new Diagram();
  523. diagram.init(this.processModel);
  524. var sorter = new TopologicalSorter(diagram);
  525. var sortedElements = sorter.getSortedElements();
  526. var sortedIds = [];
  527. for (var i = 0; i < sortedElements.length; i++) {
  528. sortedIds.push(sortedElements[i].id);
  529. }
  530. //console.info(sortedIds);
  531. var layouter = new LeftToRightGridLayouter(diagram, sortedIds);
  532. layouter.doLayout();
  533. var edgeMap = diagram.getEdgeMap();
  534. for (var edgeId in edgeMap) {
  535. var edge = edgeMap[edgeId];
  536. new EdgeLayouter(layouter.grid, edge);
  537. }
  538. diagram.updateModel();
  539. }
  540. };
  541. ;
  542. Diagram = function() {
  543. };
  544. Diagram.prototype = {
  545. getNodeMap: function() {
  546. return this.nodeMap;
  547. },
  548. getEdgeMap: function() {
  549. return this.edgeMap;
  550. },
  551. init: function(process) {
  552. this.process = process;
  553. this.nodeMap = {};
  554. this.edgeMap = {};
  555. for (var i = 0; i < this.process.children.length; i++) {
  556. var child = process.children[i];
  557. var node = new Node();
  558. node.id = child.text;
  559. node.type = child.type;
  560. node.x = child.x;
  561. node.y = child.y;
  562. node.w = child.w;
  563. node.h = child.h;
  564. this.nodeMap[node.id] = node;
  565. }
  566. for (var i = 0; i < this.process.children.length; i++) {
  567. var child = process.children[i];
  568. for (var j = 0; j < child.getOutgoingConnections().length; j++) {
  569. var connection = child.getOutgoingConnections()[j];
  570. this.createEdge(connection);
  571. }
  572. }
  573. },
  574. createEdge: function(connection) {
  575. var connectionId = connection.getSource().text + '_' + connection.getTarget().text;
  576. var edge = this.edgeMap[connectionId];
  577. if (!edge) {
  578. edge = new Edge();
  579. edge.id = connectionId;
  580. edge.name = connection.text;
  581. edge.source = this.nodeMap[connection.getSource().text];
  582. edge.target = this.nodeMap[connection.getTarget().text];
  583. edge.source.outgoingLinks.push(edge);
  584. edge.target.incomingLinks.push(edge);
  585. this.edgeMap[connectionId] = edge;
  586. }
  587. },
  588. updateModel: function() {
  589. for (var nodeId in this.nodeMap) {
  590. var item = this.nodeMap[nodeId];
  591. var model = this.getModel(nodeId);
  592. model.x = item.x;
  593. model.y = item.y;
  594. model.getEditPart().getFigure().x = model.x;
  595. model.getEditPart().getFigure().y = model.y;
  596. for (var i = 0; i < item.outgoingLinks.length; i++) {
  597. var connection = item.outgoingLinks[i];
  598. var connectionModel = this.getConnectionModel(model, connection);
  599. if (connectionModel == null) {
  600. continue;
  601. }
  602. connectionModel.innerPoints = typeof connection.innerPoints == 'undefined' ? []
  603. : connection.innerPoints;
  604. connectionModel.textX = 0;
  605. connectionModel.textY = 0;
  606. connectionModel.getEditPart().getFigure().innerPoints = connectionModel.innerPoints;
  607. connectionModel.getEditPart().getFigure().textX = connectionModel.textX;
  608. connectionModel.getEditPart().getFigure().textY = connectionModel.textY;
  609. }
  610. }
  611. this.process.getEditPart().refresh();
  612. },
  613. getModel: function(name) {
  614. var model = null;
  615. Gef.each(this.process.children, function(item) {
  616. if (item.text == name) {
  617. model = item;
  618. return false;
  619. }
  620. });
  621. return model;
  622. },
  623. getConnectionModel: function(nodeModel, edge) {
  624. var model = null;
  625. Gef.each(nodeModel.getOutgoingConnections(), function(item) {
  626. if (item.getTarget().text == edge.getTarget().id) {
  627. model = item;
  628. return false;
  629. }
  630. });
  631. return model;
  632. }
  633. };
  634. ;
  635. //should be change name to LayoutingElement
  636. Node = function() {
  637. this.incomingLinks = [];
  638. this.outgoingLinks = [];
  639. };
  640. Node.prototype = {
  641. getIncomingLinks: function() {
  642. return this.incomingLinks;
  643. },
  644. getOutgoingLinks: function() {
  645. return this.outgoingLinks;
  646. },
  647. getPrecedingElements: function() {
  648. var previousElements = [];
  649. for (var i = 0; i < this.incomingLinks.length; i++) {
  650. previousElements.push(this.incomingLinks[i].source);
  651. }
  652. return previousElements;
  653. },
  654. getFollowingElements: function() {
  655. var followingElements = [];
  656. for (var i = 0; i < this.outgoingLinks.length; i++) {
  657. followingElements.push(this.outgoingLinks[i].target);
  658. }
  659. return followingElements;
  660. },
  661. isJoin: function() {
  662. return this.incomingLinks.length > 1;
  663. },
  664. isSplit: function() {
  665. return this.outgoingLinks.length > 1;
  666. },
  667. prevSplit: function() {
  668. var distance = 1000;
  669. var candidateDistance = 0;
  670. var split = null;
  671. var candidate = null;
  672. var precedingElements = this.getPrecedingElements();
  673. for (var i = 0; i < precedingElements.length; i++) {
  674. var elem = precedingElements[i];
  675. if (elem.isSplit()) {
  676. return elem;
  677. }
  678. candidate = elem.prevSplit();
  679. if (this.isJoin()) {
  680. // if this is not a join, we have only one precedingElement.
  681. candidateDistance = elem.backwardDistanceTo(candidate);
  682. }
  683. if (candidateDistance < distance) {
  684. split = candidate;
  685. distance = candidateDistance;
  686. }
  687. }
  688. return split;
  689. },
  690. backwardDistanceTo: function(other) {
  691. return this._backwardDistanceTo(other, []);
  692. },
  693. _backwardDistanceTo: function(other, historyElements) {
  694. if (other == this) {
  695. return 0;
  696. }
  697. if (historyElements.indexOf(this) != -1) {
  698. return 1000;
  699. }
  700. var d = 1000;
  701. var newHistory = [];
  702. newHistory.push(this);
  703. var precedingElements = this.getPrecedingElements();
  704. for (var i = 0; i < precedingElements.length; i++) {
  705. var el = precedingElements[i];
  706. d = Math.min(d, el._backwardDistanceTo(other, newHistory));
  707. }
  708. return d == 1000 ? d : d + 1;
  709. }
  710. };
  711. ;
  712. Edge = function() {
  713. this.source = null;
  714. this.target = null;
  715. };
  716. Edge.prototype = {
  717. getSource: function() {
  718. return this.source;
  719. },
  720. getTarget: function() {
  721. return this.target;
  722. },
  723. reverseOutgoingAndIncoming: function() {
  724. var index = 0;
  725. var oldSource = this.source;
  726. var oldTarget = this.target;
  727. index = oldSource.outgoingLinks.indexOf(this);
  728. oldSource.outgoingLinks.splice(index, 1);
  729. index = oldTarget.incomingLinks.indexOf(this);
  730. oldTarget.incomingLinks.splice(index, 1);
  731. var newSource = oldTarget;
  732. var newTarget = oldSource;
  733. newSource.outgoingLinks.push(this);
  734. newTarget.incomingLinks.push(this);
  735. this.source = newSource;
  736. this.target = newTarget;
  737. }
  738. };
  739. ;
  740. TopologicalSorter = function(diagram) {
  741. this.diagram = diagram;
  742. this.prepareDataAndSort(true);
  743. this.prepareDataAndSort(false);
  744. };
  745. TopologicalSorter.prototype = {
  746. getSortedElements: function() {
  747. return this.sortedElements;
  748. },
  749. prepareDataAndSort: function(shouldBackpatch) {
  750. this.sortedElements = [];
  751. this.elementsToSort = {};
  752. this.backwardsEdges = [];
  753. this.elementsToSortCount = 0;
  754. this.addAllChildren();
  755. this.topologicalSort();
  756. if (shouldBackpatch === true) {
  757. this.backpatchBackwardsEdges();
  758. }
  759. this.reverseBackwardsEdges();
  760. },
  761. addAllChildren: function() {
  762. for (var nodeId in this.diagram.nodeMap) {
  763. var node = this.diagram.nodeMap[nodeId];
  764. this.elementsToSort[nodeId] = new SortableLayoutingElement(node);
  765. this.elementsToSortCount++;
  766. }
  767. },
  768. topologicalSort: function() {
  769. var count = 0;
  770. var oldCount = 0;
  771. while (this.elementsToSortCount > 0) {
  772. var freeElements = this.getFreeElements();
  773. if (freeElements.length > 0) {
  774. for (var i = 0; i < freeElements.length; i++) {
  775. var freeElement = freeElements[i];
  776. this.sortedElements.push(freeElement.node);
  777. this.freeElementsFrom(freeElement);
  778. delete this.elementsToSort[freeElement.node.id];
  779. }
  780. } else {
  781. var entry = this.getLoopEntryPoint();
  782. for (var i = 0; i < entry.incomingLinks.length; i++) {
  783. var backId = entry.incomingLinks[i];
  784. entry.reverseIncomingLinkFrom(backId);
  785. var elem = this.elementsToSort[backId];
  786. elem.reverseOutgoingLinkTo(entry.node.id);
  787. this.backwardsEdges.push(new BackwardsEdge(backId, entry.node.id));
  788. }
  789. }
  790. }
  791. },
  792. backpatchBackwardsEdges: function() {
  793. var newBackwardsEdges = [];
  794. for (var i = 0; i < this.backwardsEdges.length; i++) {
  795. newBackwardsEdges.push(this.backwardsEdges[i]);
  796. }
  797. for (var i = 0; i < this.backwardsEdges.length; i++) {
  798. var edge = this.backwardsEdges[i];
  799. var sourceId = edge.getSource();
  800. var targetId = edge.getTarget();
  801. var sourceElement = this.diagram.nodeMap[sourceId];
  802. while (!(sourceElement.isJoin() || sourceElement.isSplit())) {
  803. var newSourceElement = sourceElement.getPrecedingElements()[0];
  804. targetId = newSourceElement.id;
  805. newBackwardsEdges.push(new BackwardsEdge(targetId, sourceId));
  806. sourceElement = newSourceElement;
  807. sourceId = targetId;
  808. }
  809. }
  810. this.backwardsEdges = newBackwardsEdges;
  811. },
  812. reverseBackwardsEdges: function() {
  813. var edgeMap = this.diagram.edgeMap;
  814. for (var i = 0; i < this.backwardsEdges.length; i++) {
  815. var backwardsEdge = this.backwardsEdges[i];
  816. var sourceId = backwardsEdge.getSource();
  817. var targetId = backwardsEdge.getTarget();
  818. var sourceElement = this.diagram.nodeMap[sourceId];
  819. var targetElement = this.diagram.nodeMap[targetId];
  820. var edge = this.getEdge(edgeMap, sourceElement, targetElement);
  821. backwardsEdge.setEdge(edge);
  822. if (edge) {
  823. // reverse edge outgoing and incoming
  824. edge.reverseOutgoingAndIncoming();
  825. }
  826. }
  827. },
  828. getFreeElements: function() {
  829. var freeElements = [];
  830. for (var nodeId in this.elementsToSort) {
  831. var elem = this.elementsToSort[nodeId];
  832. if (elem.isFree()) {
  833. freeElements.push(elem);
  834. }
  835. }
  836. return freeElements;
  837. },
  838. freeElementsFrom: function(freeElement) {
  839. for (var i = 0; i < freeElement.outgoingLinks.length; i++) {
  840. var id = freeElement.outgoingLinks[i];
  841. var targetElement = this.elementsToSort[id];
  842. if (targetElement) {
  843. targetElement.removeIncomingLinkFrom(freeElement.node.id);
  844. }
  845. }
  846. this.elementsToSortCount--;
  847. },
  848. getLoopEntryPoint: function() {
  849. for (var nodeId in this.elementsToSort) {
  850. var candidate = this.elementsToSort[nodeId];
  851. if (candidate.oldInCount > 1
  852. && candidate.oldInCount > candidate.incomingLinks.length) {
  853. return candidate;
  854. }
  855. }
  856. throw new Error('Could not find a valid loop entry point');
  857. },
  858. getEdge: function(edgeMap, sourceElement, targetElement) {
  859. for (var i = 0; i < sourceElement.outgoingLinks.length; i++) {
  860. var edge = sourceElement.outgoingLinks[i];
  861. if (edge.getTarget().id == targetElement.id) {
  862. return edge;
  863. }
  864. }
  865. return null;
  866. }
  867. };
  868. ;
  869. SortableLayoutingElement = function(node) {
  870. this.node = node;
  871. this.incomingLinks = [];
  872. this.outgoingLinks = [];
  873. for (var i = 0; i < node.incomingLinks.length; i++) {
  874. this.incomingLinks.push(node.incomingLinks[i].source.id);
  875. }
  876. for (var i = 0; i < node.outgoingLinks.length; i++) {
  877. this.outgoingLinks.push(node.outgoingLinks[i].target.id);
  878. }
  879. this.oldInCount = this.incomingLinks.length;
  880. this.isJoin = node.isJoin();
  881. };
  882. SortableLayoutingElement.prototype = {
  883. isFree: function() {
  884. return this.incomingLinks.length == 0;
  885. },
  886. removeIncomingLinkFrom: function(sourceId) {
  887. var index = this.incomingLinks.indexOf(sourceId);
  888. this.incomingLinks.splice(index, 1);
  889. },
  890. reverseIncomingLinkFrom: function(id) {
  891. this.removeIncomingLinkFrom(id);
  892. this.outgoingLinks.push(id);
  893. },
  894. reverseOutgoingLinkTo: function(id) {
  895. var index = this.outgoingLinks.indexOf(id);
  896. this.outgoingLinks.splice(index, 1);
  897. this.incomingLinks.push(id);
  898. }
  899. };
  900. ;
  901. BackwardsEdge = function(source, target) {
  902. this.source = source;
  903. this.target = target;
  904. };
  905. BackwardsEdge.prototype = {
  906. getEdge: function() {
  907. return this.edge;
  908. },
  909. setEdge: function(edge) {
  910. this.edge = edge;
  911. },
  912. getSource: function() {
  913. return this.source;
  914. },
  915. getTarget: function() {
  916. return this.target;
  917. }
  918. };
  919. ;
  920. LeftToRightGridLayouter = function(diagram, sortedIds) {
  921. this.diagram = diagram;
  922. this.sortedIds = sortedIds;
  923. };
  924. LeftToRightGridLayouter.prototype = {
  925. doLayout: function() {
  926. this.grid = new Grid();
  927. this.layoutElements();
  928. this.calcGeometry(this.grid);
  929. this.writeGeometry(this.grid);
  930. this.diagram.updateModel();
  931. },
  932. layoutElements: function() {
  933. for (var i = 0; i < this.sortedIds.length; i++) {
  934. var sortedId = this.sortedIds[i];
  935. var currentElement = this.diagram.nodeMap[sortedId];
  936. var precedingElements = currentElement.getPrecedingElements();
  937. var cellOfElement = this.placeElement(currentElement, precedingElements);
  938. if (currentElement.isJoin() && precedingElements.length != 0) {
  939. // there is an edge hitting us left, so lets forbid
  940. // interleaving to use the left cell, if this is empty
  941. cellOfElement.getPrevCell().setPackable(false);
  942. }
  943. if (currentElement.isSplit()) {
  944. this.prelayoutSuccessors(currentElement, cellOfElement);
  945. }
  946. }
  947. },
  948. placeElement: function(currentElement, precedingElements) {
  949. var newCell = null;
  950. if (precedingElements.length == 0) {
  951. this.grid.startCell.value = currentElement;
  952. newCell = this.grid.startCell;
  953. } else {
  954. var leftCell = null;
  955. var newCell = this.grid.getCellOfItem(currentElement);
  956. if (currentElement.isJoin()) {
  957. var splitFound = false;
  958. var split = currentElement.prevSplit();
  959. if (split != null) {
  960. var splits = new PriorityQueue(currentElement);
  961. splits.add(split);
  962. for (var i = 0; i < precedingElements.length; i++) {
  963. var elem = precedingElements[i];
  964. split = elem.prevSplit();
  965. if (split != null && !splits.contains(split)) {
  966. splits.add(split);
  967. //console.info(splits.items);
  968. }
  969. }
  970. split = null;
  971. // get split with most connections
  972. var maxCon = 0;
  973. for (var i = 0; i < splits.items.length; i++) {
  974. var target = splits.items[i];
  975. if (target == currentElement) {
  976. continue;
  977. }
  978. // current connections
  979. var curCon = 0;
  980. for (var j = 0; j < precedingElements.length; j++) {
  981. var elem = precedingElements[j];
  982. if (elem.backwardDistanceTo(target) < 1000) {
  983. curCon++;
  984. }
  985. }
  986. if (curCon > maxCon) {
  987. maxCon = curCon;
  988. split = target;
  989. }
  990. }
  991. splitFound = split != null;
  992. }
  993. // current cell position
  994. var x = 0;
  995. var yAcc = 0;
  996. var yCnt = 0;
  997. for (var i = 0; i < precedingElements.length; i++) {
  998. var elem = precedingElements[i];
  999. var tmp = this.grid.getCellOfItem(elem);
  1000. if (tmp == null) {
  1001. tmp = {
  1002. getColIndex: function() {
  1003. return 0;
  1004. }
  1005. };
  1006. } else {
  1007. yAcc += tmp.getRowIndex();
  1008. yCnt++;
  1009. }
  1010. x = Math.max(x, tmp.getColIndex());
  1011. }
  1012. // farthest to the right
  1013. if (splitFound) {
  1014. leftCell = this.grid.getCellOfItem(split).row.cells[x];
  1015. // set path to split unpackable
  1016. for (var c = leftCell; c.value != split; c = c.getPrevCell()) {
  1017. c.setPackable(false);
  1018. }
  1019. } else {
  1020. if (yCnt == 0) {
  1021. leftCell = this.grid.rows[0].above().cells[x];
  1022. } else {
  1023. leftCell = this.grid.rows[yAcc / yCnt].cells[x];
  1024. }
  1025. }
  1026. if (newCell != null && newCell.value == currentElement) {
  1027. newCell.value = null;
  1028. }
  1029. newCell = leftCell.after();
  1030. for (var i = 0; i < precedingElements.length; i++) {
  1031. var el = precedingElements[i];
  1032. var target = this.grid.getCellOfItem(el);
  1033. if (target == null) {
  1034. continue;
  1035. }
  1036. var start = target.row.cells[x + 1];
  1037. for (var c = start; c != target; c = c.getPrevCell()) {
  1038. c.setPackable(false);
  1039. }
  1040. }
  1041. } else if (newCell == null) {
  1042. // if not preLayouted
  1043. var preElem = precedingElements[0];
  1044. leftCell = this.grid.getCellOfItem(preElem);
  1045. newCell = leftCell.after();
  1046. }
  1047. if (newCell.isFilled() && newCell.value != currentElement) {
  1048. newCell.row.insertRowBeneath();
  1049. newCell = newCell.beneath();
  1050. }
  1051. newCell.value = currentElement;
  1052. newCell.getPrevCell().setPackable(false);
  1053. }
  1054. return newCell;
  1055. },
  1056. prelayoutSuccessors: function(currentElement, cellOfElement) {
  1057. var baseCell = cellOfElement.after();
  1058. var topCell = baseCell;
  1059. var followingElements = currentElement.getFollowingElements();
  1060. // heuristic for direct connection to join
  1061. var directJoin = null;
  1062. for (var i = 0; i < followingElements.length; i++) {
  1063. var possibleJoin = followingElements[i];
  1064. if (possibleJoin.isJoin()) {
  1065. directJoin = possibleJoin;
  1066. }
  1067. }
  1068. if (directJoin != null) {
  1069. // put in the middle
  1070. var index = followingElements.indexOf(directJoin);
  1071. // remove
  1072. followingElements.splice(index, 1);
  1073. var position = parseInt(followingElements.length / 2, 10);
  1074. // insert
  1075. followingElements.splice(position, 0, directJoin);
  1076. }
  1077. // normal preLayout following elements
  1078. var follow = parseInt(followingElements.length / 2, 10);
  1079. for (var i = 0; i < follow; i++) {
  1080. topCell.row.insertRowAbove();
  1081. baseCell.row.insertRowBeneath();
  1082. topCell = topCell.above();
  1083. }
  1084. for (var i = 0; i < followingElements.length; i++) {
  1085. var newElem = followingElements[i];
  1086. if (this.grid.getCellOfItem(newElem)) {
  1087. continue;
  1088. }
  1089. topCell.value = newElem;
  1090. topCell = topCell.beneath();
  1091. if (topCell == baseCell && followingElements.length % 2 == 0) {
  1092. topCell = topCell.beneath();
  1093. }
  1094. }
  1095. },
  1096. calcGeometry: function(grid) {
  1097. grid.pack();
  1098. var heightOfRow = [];
  1099. for (var i = 0; i < grid.rowCount; i++) {
  1100. heightOfRow.push(0);
  1101. }
  1102. var widthOfColumn = [];
  1103. for (var i = 0; i < grid.colCount; i++) {
  1104. widthOfColumn.push(0);
  1105. }
  1106. for (var i = 0; i < grid.rowCount; i++) {
  1107. var row = grid.rows[i];
  1108. for (var j = 0; j < grid.colCount; j++) {
  1109. var cell = row.cells[j];
  1110. if (cell.isFilled()) {
  1111. var elem = cell.value;
  1112. widthOfColumn[j] = Math.max(widthOfColumn[j], elem.w + 30);
  1113. heightOfRow[i] = Math.max(heightOfRow[i], elem.h + 30);
  1114. }
  1115. }
  1116. }
  1117. this.heightOfRow = heightOfRow;
  1118. this.widthOfColumn = widthOfColumn;
  1119. this.totalWidth = 0;
  1120. this.totalHeight = 0;
  1121. for (var i = 0; i < grid.colCount; i++) {
  1122. this.totalWidth += widthOfColumn[i];
  1123. }
  1124. for (var i = 0; i < grid.rowCount; i++) {
  1125. this.totalHeight += heightOfRow[i];
  1126. }
  1127. },
  1128. writeGeometry: function(grid) {
  1129. var x = 0;
  1130. var y = 0;
  1131. for (var i = 0; i < grid.rowCount; i++) {
  1132. var row = grid.rows[i];
  1133. var cellHeight = this.heightOfRow[i];
  1134. for (var j = 0; j < grid.colCount; j++) {
  1135. var cell = row.cells[j];
  1136. var cellWidth = this.widthOfColumn[j];
  1137. if (cell.isFilled()) {
  1138. var elem = cell.value;
  1139. var newX = x + cellWidth / 2 - elem.w / 2;
  1140. var newY = y + cellHeight / 2 - elem.h / 2;
  1141. elem.x = newX;
  1142. elem.y = newY;
  1143. }
  1144. x += cellWidth;
  1145. }
  1146. x = 0;
  1147. y += cellHeight;
  1148. }
  1149. }
  1150. };
  1151. ;
  1152. Grid = function() {
  1153. var cell = new Cell();
  1154. var row = new Row();
  1155. row.grid = this;
  1156. row.addCell(cell);
  1157. this.rows = [row];
  1158. this.startCell = cell;
  1159. this.colCount = 1;
  1160. this.rowCount = this.rows.length;
  1161. };
  1162. Grid.prototype = {
  1163. addFirstRow: function() {
  1164. var row = new Row();
  1165. row.grid = this;
  1166. for (var i = 0; i < this.rolCount; i++) {
  1167. var cell = new Cell();
  1168. row.addCell(cell);
  1169. }
  1170. this.rows.unshift(row);
  1171. this.rowCount = this.rows.length;
  1172. },
  1173. addLastRow: function() {
  1174. var row = new Row();
  1175. row.grid = this;
  1176. for (var i = 0; i < this.rolCount; i++) {
  1177. row.addCell(new Cell());
  1178. }
  1179. this.rows.push(row);
  1180. this.rowCount = this.rows.length;
  1181. },
  1182. addLastCol: function() {
  1183. for (var i = 0; i < this.rowCount; i++) {
  1184. var row = this.rows[i];
  1185. row.addCell(new Cell());
  1186. }
  1187. this.colCount++;
  1188. },
  1189. getCellOfItem: function(elem) {
  1190. for (var i = 0; i < this.rowCount; i++) {
  1191. var row = this.rows[i];
  1192. for (var j = 0; j < this.colCount; j++) {
  1193. var cell = row.cells[j];
  1194. if (cell.value == elem) {
  1195. return cell;
  1196. }
  1197. }
  1198. }
  1199. return null;
  1200. },
  1201. pack: function() {
  1202. var changed = false;
  1203. do {
  1204. changed = false;
  1205. for (var i = 0; i < this.rows.length; i++) {
  1206. var row = this.rows[i];
  1207. changed |= row.tryInterleaveWith(row.getPrevRow());
  1208. }
  1209. for (var i = 0; i < this.rows.length; i++) {
  1210. var row = this.rows[i];
  1211. changed |= row.tryInterleaveWith(row.getNextRow());
  1212. }
  1213. } while (changed);
  1214. },
  1215. info: function() {
  1216. var value = '';
  1217. for (var i = 0; i < this.rows.length; i++) {
  1218. var row = this.rows[i];
  1219. for (var j = 0; j < row.cells.length; j++) {
  1220. var cell = row.cells[j];
  1221. var id = '[ ]';
  1222. if (cell.isFilled()) {
  1223. id = cell.value.id;
  1224. } else if (cell.packable === false) {
  1225. id = '[ p ]';
  1226. }
  1227. value += id;
  1228. }
  1229. value += '\n';
  1230. }
  1231. return value;
  1232. }
  1233. };
  1234. ;
  1235. Cell = function() {
  1236. this.packable = true;
  1237. };
  1238. Cell.prototype = {
  1239. isFilled: function() {
  1240. return typeof this.value != 'undefined' && this.value != null;
  1241. },
  1242. isUnpackable: function() {
  1243. return this.isFilled() || (this.packable === false);
  1244. },
  1245. setPackable: function(packable) {
  1246. this.packable = packable;
  1247. },
  1248. getRowIndex: function() {
  1249. return this.row.getIndex();
  1250. },
  1251. getColIndex: function() {
  1252. for (var i = 0; i < this.row.cells.length; i++) {
  1253. if (this.row.cells[i] == this) {
  1254. return i;
  1255. }
  1256. }
  1257. },
  1258. after: function() {
  1259. var colIndex = this.getColIndex();
  1260. if (colIndex == this.row.cells.length - 1) {
  1261. this.grid.addLastCol();
  1262. }
  1263. return this.row.cells[colIndex + 1];
  1264. },
  1265. above: function() {
  1266. var rowIndex = this.getRowIndex();
  1267. var colIndex = this.getColIndex();
  1268. if (rowIndex == 0) {
  1269. this.row.insertRowAbove();
  1270. }
  1271. return this.grid.rows[rowIndex - 1].cells[colIndex];
  1272. },
  1273. beneath: function() {
  1274. var rowIndex = this.getRowIndex();
  1275. var colIndex = this.getColIndex();
  1276. if (rowIndex == this.grid.rowCount - 1) {
  1277. this.row.insertRowBeneath();
  1278. }
  1279. return this.grid.rows[rowIndex + 1].cells[colIndex];
  1280. },
  1281. getPrevCell: function() {
  1282. var index = this.getColIndex();
  1283. return this.row.cells[index - 1];
  1284. },
  1285. getNextCell: function() {
  1286. var index = this.getColIndex();
  1287. return this.row.cells[index + 1];
  1288. }
  1289. };
  1290. ;
  1291. Row = function() {
  1292. this.cells = [];
  1293. };
  1294. Row.prototype = {
  1295. addCell: function(cell) {
  1296. cell.row = this;
  1297. cell.grid = this.grid;
  1298. this.cells.push(cell);
  1299. },
  1300. getIndex: function() {
  1301. for (var i = 0; i < this.grid.rows.length; i++) {
  1302. if (this.grid.rows[i] == this) {
  1303. return i;
  1304. }
  1305. }
  1306. },
  1307. insertRowBeneath: function() {
  1308. var row = new Row();
  1309. row.grid = this.grid;
  1310. for (var i = 0; i < this.grid.colCount; i++) {
  1311. row.addCell(new Cell());
  1312. }
  1313. var rowIndex = this.getIndex();
  1314. var rows = this.grid.rows;
  1315. if (rowIndex == rows.length - 1) {
  1316. rows.push(row);
  1317. } else {
  1318. rows.splice(rowIndex + 1, 0, row);
  1319. }
  1320. this.grid.rowCount = rows.length;
  1321. },
  1322. insertRowAbove: function() {
  1323. var row = new Row();
  1324. row.grid = this.grid;
  1325. for (var i = 0; i < this.grid.colCount; i++) {
  1326. row.addCell(new Cell());
  1327. }
  1328. var rowIndex = this.getIndex();
  1329. var rows = this.grid.rows;
  1330. if (rowIndex == 0) {
  1331. rows.unshift(row);
  1332. } else {
  1333. rows.splice(rowIndex, 0, row);
  1334. }
  1335. this.grid.rowCount = rows.length;
  1336. },
  1337. getPrevRow: function() {
  1338. var index = this.getIndex();
  1339. if (index > 0) {
  1340. return this.grid.rows[index - 1];
  1341. } else {
  1342. return null;
  1343. }
  1344. },
  1345. getNextRow: function() {
  1346. var index = this.getIndex();
  1347. if (index < this.grid.rows.length) {
  1348. return this.grid.rows[index + 1];
  1349. } else {
  1350. return null;
  1351. }
  1352. },
  1353. tryInterleaveWith: function(other) {
  1354. if (!this.isInterleaveWith(other)) {
  1355. return false;
  1356. }
  1357. for (var i = 0; i < this.cells.length; i++) {
  1358. var cell = this.cells[i];
  1359. var otherCell = other.cells[i];
  1360. if (cell.isFilled()) {
  1361. other.cells[i] = cell;
  1362. } else if (cell.isUnpackable()) {
  1363. otherCell.setPackable(false);
  1364. }
  1365. }
  1366. this._remove();
  1367. return true;
  1368. },
  1369. isInterleaveWith: function(other) {
  1370. if (other == null || other == this) {
  1371. return false;
  1372. } else if (other.getPrevRow() != this && other.getNextRow() != this) {
  1373. return false;
  1374. }
  1375. for (var i = 0; i < this.cells.length; i++) {
  1376. var cell = this.cells[i];
  1377. var otherCell = other.cells[i];
  1378. if (cell.isUnpackable() && otherCell.isUnpackable()) {
  1379. return false;
  1380. }
  1381. }
  1382. return true;
  1383. },
  1384. _remove: function() {
  1385. var index = this.getIndex();
  1386. this.grid.rows.splice(index, 1);
  1387. this.grid.rowCount--;
  1388. }
  1389. };
  1390. ;
  1391. PriorityQueue = function(center) {
  1392. this.ce = center;
  1393. this.items = [];
  1394. };
  1395. PriorityQueue.prototype = {
  1396. add: function(element) {
  1397. this.items.push(element);
  1398. var len = this.items.length;
  1399. for (var i = 0; i < len; i++) {
  1400. for (var j = i; j < len; j++) {
  1401. var elem1 = this.items[i];
  1402. var elem2 = this.items[j];
  1403. if (this.compareTo(elem1, elem2) > 0) {
  1404. this.items[i] = elem2;
  1405. this.items[j] = elem1;
  1406. }
  1407. }
  1408. }
  1409. },
  1410. compareTo: function(elem1, elem2) {
  1411. return this.ce.backwardDistanceTo(elem1) - this.ce.backwardDistanceTo(elem2);
  1412. },
  1413. contains: function(element) {
  1414. return this.items.indexOf(element) != -1;
  1415. }
  1416. };
  1417. ;
  1418. EdgeLayouter = function(grid, edge) {
  1419. this.grid = grid;
  1420. this.edge = edge;
  1421. edge.innerPoints = [];
  1422. this.calculateGlobals();
  1423. this.pickLayoutForEdge();
  1424. };
  1425. EdgeLayouter.prototype = {
  1426. calculateGlobals: function() {
  1427. this.source = this.edge.source;
  1428. this.target = this.edge.target;
  1429. this.sourceRelativeCenterX = this.source.w / 2;
  1430. this.sourceRelativeCenterY = this.source.h / 2;
  1431. this.targetRelativeCenterX = this.target.w / 2;
  1432. this.targetRelativeCenterY = this.target.h / 2;
  1433. this.sourceAbsoluteCenterX = this.source.x + this.sourceRelativeCenterX;
  1434. this.sourceAbsoluteCenterY = this.source.y + this.sourceRelativeCenterY;
  1435. this.targetAbsoluteCenterX = this.target.x + this.targetRelativeCenterX;
  1436. this.targetAbsoluteCenterY = this.target.y + this.targetRelativeCenterY;
  1437. this.sourceAbsoluteX = this.source.x;
  1438. this.sourceAbsoluteY = this.source.y;
  1439. this.sourceAbsoluteX2 = this.source.x + this.source.w;
  1440. this.sourceAbsoluteY2 = this.source.y + this.source.h;
  1441. this.targetAbsoluteX = this.target.x;
  1442. this.targetAbsoluteY = this.target.y;
  1443. this.targetAbsoluteX2 = this.target.x + this.target.w;
  1444. this.targetAbsoluteY2 = this.target.y + this.target.h;
  1445. this.sourceJoin = this.source.isJoin();
  1446. this.sourceSplit = this.source.isSplit();
  1447. this.targetJoin = this.target.isJoin();
  1448. this.targetSplit = this.target.isSplit();
  1449. this.backwards = this.sourceAbsoluteCenterX > this.targetAbsoluteCenterX;
  1450. },
  1451. pickLayoutForEdge: function() {
  1452. // sourceX == targetX, up and down
  1453. if (this.sourceAbsoluteCenterX == this.targetAbsoluteCenterX) {
  1454. this.setEdgeDirectCenter();
  1455. return;
  1456. } else if (this.sourceAbsoluteCenterY == this.targetAbsoluteCenterY) {
  1457. if (this.areCellsHorizontalFree()) {
  1458. this.setEdgeDirectCenter();
  1459. } else {
  1460. this.setEdgeAroundTheCorner(true);
  1461. }
  1462. return;
  1463. }
  1464. if (this.sourceAbsoluteCenterX <= this.targetAbsoluteCenterX
  1465. && this.sourceAbsoluteCenterY <= this.targetAbsoluteCenterY) {
  1466. // target is right under
  1467. if (this.sourcejoin && this.sourceSplit) {
  1468. this.setEdgeStepRight();
  1469. return;
  1470. } else if (this.sourceSplit) {
  1471. this.setEdge90DegreeRightUnderAntiClockwise();
  1472. return;
  1473. } else if (this.targetJoin) {
  1474. this.setEdge90DegreeRightUnderClockwise();
  1475. return;
  1476. }
  1477. } else if (this.sourceAbsoluteCenterX <= this.targetAbsoluteCenterX
  1478. && this.sourceAbsoluteCenterY > this.targetAbsoluteCenterY) {
  1479. // target is right above
  1480. if (this.sourcejoin && this.sourceSplit) {
  1481. this.setEdgeStepRight();
  1482. return;
  1483. } else if (this.sourceSplit) {
  1484. this.setEdge90DegreeRightAboveClockwise();
  1485. return;
  1486. } else if (this.targetJoin) {
  1487. this.setEdge90DegreeRightAboveAntiClockwise();
  1488. return;
  1489. }
  1490. }
  1491. if (this.sourceJoin && sourceSplit && (!this.backwards)) {
  1492. this.setEdgeStepRight();
  1493. return;
  1494. }
  1495. if (this.sourceJoin && sourceSplit) {
  1496. this.setEdgeAroundTheCorner(true);
  1497. return;
  1498. }
  1499. this.setEdgeDirectCenter();
  1500. },
  1501. areCellsHorizontalFree: function() {
  1502. var fromCell = null;
  1503. var toCell = null;
  1504. if (this.sourceAbsoluteCenterX < this.targetAbsoluteCenterX) {
  1505. fromCell = this.grid.getCellOfItem(this.source);
  1506. toCell = this.grid.getCellOfItem(this.target);
  1507. } else {
  1508. fromCell = this.grid.getCellOfItem(this.target);
  1509. toCell = this.grid.getCellOfItem(this.source);
  1510. }
  1511. fromCell = fromCell.getNextCell();
  1512. while (fromCell != toCell) {
  1513. if (fromCell == null || fromCell.isFilled()) {
  1514. return false;
  1515. }
  1516. fromCell = fromCell.getNextCell();
  1517. }
  1518. return true;
  1519. },
  1520. setEdgeDirectCenter: function() {
  1521. var boundsMinX = Math.min(this.sourceAbsoluteCenterX,
  1522. this.targetAbsoluteCenterX);
  1523. var boundsMinY = Math.min(this.sourceAbsoluteCenterY,
  1524. this.targetAbsoluteCenterY);
  1525. var boundsMaxX = Math.max(this.sourceAbsoluteCenterX,
  1526. this.targetAbsoluteCenterX);
  1527. var boundsMaxY = Math.max(this.sourceAbsoluteCenterY,
  1528. this.targetAbsoluteCenterY);
  1529. // this.edge.innerPoints = [];
  1530. },
  1531. setEdge90DegreeRightAboveClockwise: function() {
  1532. this.edge.innerPoints = [
  1533. [this.sourceAbsoluteCenterX, this.targetAbsoluteCenterY]
  1534. ];
  1535. },
  1536. setEdge90DegreeRightAboveAntiClockwise: function() {
  1537. this.edge.innerPoints = [
  1538. [this.targetAbsoluteCenterX, this.sourceAbsoluteCenterY]
  1539. ];
  1540. },
  1541. setEdge90DegreeRightUnderClockwise: function() {
  1542. this.edge.innerPoints = [
  1543. [this.targetAbsoluteCenterX, this.sourceAbsoluteCenterY]
  1544. ];
  1545. },
  1546. setEdge90DegreeRightUnderAntiClockwise: function() {
  1547. this.edge.innerPoints = [
  1548. [this.sourceAbsoluteCenterX, this.targetAbsoluteCenterY]
  1549. ];
  1550. },
  1551. setEdgeAroundTheCorner: function(down) {
  1552. var height = Math.max(this.source.h / 2, this.target.h / 2) + 20;
  1553. if (down) {
  1554. height *= -1;
  1555. }
  1556. this.edge.innerPoints = [
  1557. [this.sourceAbsoluteCenterX, this.sourceAbsoluteCenterY + height],
  1558. [this.targetAbsoluteCenterX, this.sourceAbsoluteCenterY + height]
  1559. ];
  1560. }
  1561. };
  1562. Ext.ux.OneCombo = Ext.extend(Ext.form.ComboBox, {
  1563. initComponent: function() {
  1564. this.readOnly = true;
  1565. this.displayField = 'text';
  1566. this.valueField = 'text';
  1567. this.triggerAction = 'all';
  1568. this.mode = 'local';
  1569. this.emptyText = 'Please Select...';
  1570. this.store = new Ext.data.SimpleStore({
  1571. expandData: true,
  1572. fields: ['text']
  1573. });
  1574. this.store.loadData(this.data);
  1575. Ext.ux.OneCombo.superclass.initComponent.call(this);
  1576. }
  1577. });
  1578. Ext.reg('onecombo', Ext.ux.OneCombo);
  1579. App.PalettePanel = Ext.extend(Ext.Panel, {
  1580. initComponent: function() {
  1581. this.region = 'west';
  1582. this.title = '活动环节';
  1583. this.iconCls = 'tb-activity';
  1584. this.width = 130;
  1585. this.initPalette();
  1586. App.PalettePanel.superclass.initComponent.call(this);
  1587. },
  1588. initPalette: function() {
  1589. var paletteType = null;
  1590. if (!Gef.PALETTE_TYPE) {
  1591. paletteType = 'accordion';
  1592. } else {
  1593. paletteType = Gef.PALETTE_TYPE;
  1594. }
  1595. this.configLayout(paletteType);
  1596. this.configItems(paletteType);
  1597. },
  1598. createHtml: function(array, divId) {
  1599. var imageRoot = Gef.IMAGE_ROOT.replace('48/', '');
  1600. var html="";
  1601. if (divId) {
  1602. html = '<div id="' + divId + '" unselectable="on">';
  1603. } else {
  1604. html = '<div unselectable="on">';
  1605. }
  1606. for (var i = 0; i < array.length; i++) {
  1607. var item = array[i];
  1608. html += '<div id="' + item.name
  1609. + '" class="paletteItem-' + item.name
  1610. + '" style="text-align:center;font-size:12px;cursor:pointer;" unselectable="on"><img id="'
  1611. + item.name + '-img" class="paletteItem-' + item.name
  1612. + '" src="' + imageRoot + item.image + '.png" unselectable="on"><br>'
  1613. + item.title + '</div>';
  1614. }
  1615. html += '</div>';
  1616. return html;
  1617. },
  1618. /**
  1619. * this.layout = 'accordion';
  1620. */
  1621. configLayout: function(type) {
  1622. if (!type || type == 'plain') {
  1623. //
  1624. } else if (type && type == 'accordion') {
  1625. this.layout = 'accordion';
  1626. }
  1627. },
  1628. configItems: function(type) {
  1629. if (type && type == 'accordion') {
  1630. this.createItemsForAccordion();
  1631. } else if (!type || type == 'plain') {
  1632. this.createItemsForHtml();
  1633. }
  1634. },
  1635. createItemsForAccordion: function() {
  1636. this.id = '__gef_jbs_palette__';
  1637. this.items = [{
  1638. title: '所有活动',
  1639. iconCls: 'tb-activity',
  1640. autoScroll: true,
  1641. html: this.createHtml([
  1642. {name: 'select', image: 'select32', title: '选择'},
  1643. {name: 'transition', image: '32/flow_sequence', title: '连线'},
  1644. {name: 'custom', image: '32/task_empty', title: '组件'},
  1645. ])
  1646. }];
  1647. },
  1648. createItemsForHtml: function() {
  1649. this.autoScroll = true;
  1650. this.html = this.createHtml([
  1651. {name: 'select', image: 'select32', title: '选择'},
  1652. {name: 'transition', image: '32/flow_sequence', title: '连线'},
  1653. {name: 'start', image: '32/start_event_empty', title: '开始'},
  1654. {name: 'end', image: '32/end_event_terminate', title: '结束'},
  1655. {name: 'cancel', image: '32/end_event_cancel', title: '取消'},
  1656. {name: 'error', image: '32/end_event_error', title: '错误'},
  1657. {name: 'state', image: '32/task_wait', title: '等待'},
  1658. {name: 'task', image: '32/task_empty', title: '任务'},
  1659. {name: 'decision', image: '32/gateway_exclusive', title: '决策'},
  1660. {name: 'fork', image: '32/gateway_parallel', title: '并行'},
  1661. {name: 'join', image: '32/gateway_parallel', title: '汇聚'},
  1662. {name: 'java', image: '32/task_java', title: 'JAVA'},
  1663. {name: 'script', image: '32/task_java', title: '脚本'},
  1664. {name: 'hql', image: '32/task_hql', title: 'HQL'},
  1665. {name: 'sql', image: '32/task_sql', title: 'SQL'},
  1666. {name: 'mail', image: '32/task_empty', title: '邮件'},
  1667. {name: 'custom', image: '32/task_empty', title: '自定义'},
  1668. {name: 'subProcess', image: '32/task_empty', title: '子流程'},
  1669. {name: 'jms', image: '32/task_empty', title: 'JMS'},
  1670. {name: 'ruleDecision', image: '32/gateway_exclusive', title: '规则决策'},
  1671. {name: 'rules', image: '32/task_empty', title: '规则'},
  1672. {name: 'human', image: '32/task_empty', title: '人工节点'},
  1673. {name: 'auto', image: '32/task_empty', title: '自动节点'},
  1674. {name: 'counter-sign', image: '32/task_empty', title: '会签节点'}
  1675. ], '__gef_jbs_palette__');
  1676. }
  1677. });
  1678. Ext.ux.TwoCombo = Ext.extend(Ext.form.ComboBox, {
  1679. initComponent: function() {
  1680. this.readOnly = true;
  1681. this.displayField = 'text';
  1682. this.valueField = 'value';
  1683. this.triggerAction = 'all';
  1684. this.mode = 'local';
  1685. this.emptyText = 'Please Select...';
  1686. this.store = new Ext.data.SimpleStore({
  1687. fields: ['value', 'text']
  1688. });
  1689. this.store.loadData(this.data);
  1690. Ext.ux.TwoCombo.superclass.initComponent.call(this);
  1691. }
  1692. });
  1693. Ext.reg('twocombo', Ext.ux.TwoCombo);