1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074 |
- Ext.ns('App');
- App = {
- webforms: {},
- init: function() {
- Ext.QuickTips.init();
- this.propertyManager = new App.property.PropertyManager();
- var viewport = new Ext.Viewport({
- layout: 'border',
- items: [
- this.createNorth(),
- this.createSouth(),
- this.createWest(),
- this.createEast(),
- this.createCenter()
- ]
- });
- this.initEditor();
- setTimeout(function() {
- Ext.get('loading').remove();
- Ext.get('loading-mask').fadeOut({remove:true});
- }, 100);
- },
- initEditor: function() {
- var xml = "<?xml version='1.0' encoding='UTF-8'?>"
- + "<process name='untitled' xmlns='http://jbpm.org/4.4/jpdl'>"
- + "<image g='100,100,716,1200' url='images/stenciles/planner/2d/layout.png' />"
- + "<image g='146,614,51,29' url='images/stenciles/planner/2d/hand.png' />"
- + "<image g='268,316,118,147' url='images/stenciles/planner/2d/table.png' />"
- + "<image g='636,134,145,197' url='images/stenciles/planner/2d/desk.png' />"
- + "<image g='602,482,123,51' url='images/stenciles/planner/2d/coach1.png' />"
- + "<image g='132,680,78,42' url='images/stenciles/planner/2d/toilet.png' />"
- + "<image g='360,600,52,170' url='images/stenciles/planner/2d/tv.png' />"
- + "<image g='134,740,190,58' url='images/stenciles/planner/2d/bath.png' />"
- + "<image g='130,932,243,163' url='images/stenciles/planner/2d/bed1.png' />"
- + "<image g='556,930,228,146' url='images/stenciles/planner/2d/bed2.png' />"
- + "<image g='720,880,46,37' url='images/stenciles/planner/2d/chair.png' />"
- + "<image g='138,892,46,37' url='images/stenciles/planner/2d/chair.png' />"
- + "<image g='140,1100,46,37' url='images/stenciles/planner/2d/chair.png' />"
- + "<image g='710,1100,46,37' url='images/stenciles/planner/2d/chair.png' />"
- + "<image g='728,666,57,132' url='images/stenciles/planner/2d/coach2.png' />"
- + "<image g='728,538,57,132' url='images/stenciles/planner/2d/coach2.png' />"
- + "<image g='727,485,56,45' url='images/stenciles/planner/2d/flowers2.png' />"
- + "<rect g='593,835,190,38' rounded=\"1\" fill=\"#FFCC00\" />"
- + "<rect g='137,835,190,38' rounded=\"1\" fill=\"#FFCC00\" />"
- + "<rect g='605,545,105,245' fill=\"#FFCC99\" />"
- + "<rect g='632,602,54,142' rounded=\"1\" />"
- + "<image g='395,133,81,41' url='images/stenciles/planner/2d/disc.png' />"
- + "<image g='659,359,95,60' url='images/stenciles/planner/2d/flowers.png' />"
- + "<image g='299,135,86,35' url='images/stenciles/planner/2d/water.png' />"
- + "</process>";
- var editor = new Gef.jbs.ExtEditor();
- var input = new Gef.jbs.JBSEditorInput();
- input.readXml(xml);
- var workbenchWindow = new Gef.ui.support.DefaultWorkbenchWindow();
- workbenchWindow.getActivePage().openEditor(editor, input);
- workbenchWindow.render();
- Gef.activeEditor = editor;
- this.propertyManager.initSelectionListener(editor);
- },
- getProcessModel: function() {
- var viewer = Gef.activeEditor.getGraphicalViewer();
- var processEditPart = viewer.getContents();
- return processEditPart.model;
- },
- createNorth: function() {
- var p = null;
- if (Gef.MODE_DEMO === true) {
- p = new Ext.Panel({
- region: 'north'
- });
- } else {
- p = new Ext.Panel({
- region: 'north',
- html: '<h1 id="pageh1">Web户型图设计器 - 多比图形控件演示<h1>'
- });
- }
- App.northPanel = p;
- return p;
- },
- createSouth: function() {
- var p = this.propertyManager.getBottom();
- return p;
- },
- createWest: function() {
- var p = new App.PalettePanel({
- collapsible: true
- });
- App.westPanel = p;
- return p;
- },
- createEast: function() {
- var p = this.propertyManager.getRight();
- return p;
- },
- createCenter: function() {
- var p = new App.CanvasPanel();
- App.centerPanel = p;
- return p;
- },
- getSelectionListener: function() {
- if (!this.selectionListener) {
- this.selectionListener = new Gef.jbs.ExtSelectionListener(null);
- }
- return this.selectionListener;
- }
- };
- /*
- Gef.override(App.PalettePanel, {
- configItems: function() {
- this.html = 'sdfasfdfdsa';
- }
- });
- */
- //Gef.PALETTE_TYPE = 'plain';
- Gef.PALETTE_TYPE = 'accordion';
- Ext.onReady(App.init, App);
- App.CanvasPanel = Ext.extend(Ext.Panel, {
- initComponent: function() {
- //this.on('bodyresize', function(p, w, h) {
- // var b = p.body.getBox();
- //});
- this.region = 'center';
- this.autoScroll = true;
- this.tbar = new Ext.Toolbar([{
- text: '新建',
- iconCls: 'tb-new',
- handler: function() {
- Gef.activeEditor.reset();
- }
- }, {
- text: '导入',
- iconCls: 'tb-webform',
- handler: function() {
- var xml = Gef.activeEditor.serial();
- if (!this.openWin) {
- this.openWin = new Ext.Window({
- title: 'xml',
- layout: 'fit',
- width: 500,
- height: 300,
- closeAction: 'hide',
- modal: true,
- items: [{
- id: '__gef_jbpm4_xml_import__',
- xtype: 'textarea'
- }],
- buttons: [{
- text: '导入',
- handler: function() {
- var xml = Ext.getDom('__gef_jbpm4_xml_import__').value;
- Gef.activeEditor.resetAndOpen(xml);
- this.openWin.hide();
- },
- scope: this
- }, {
- text: '取消',
- handler: function() {
- this.openWin.hide();
- },
- scope: this
- }]
- });
- this.openWin.on('show', function() {
- Gef.activeEditor.disable();
- });
- this.openWin.on('hide', function() {
- Gef.activeEditor.enable();
- });
- }
- this.openWin.show(null, function() {
- Ext.getDom('__gef_jbpm4_xml_import__').value = xml;
- });
- }
- }, {
- text: '导出',
- iconCls: 'tb-prop',
- handler: function() {
- var xml = Gef.activeEditor.serial();
- if (!this.openWin) {
- this.openWin = new Ext.Window({
- title: 'xml',
- layout: 'fit',
- width: 500,
- height: 300,
- closeAction: 'hide',
- modal: true,
- items: [{
- id: '__gef_jbpm4_xml_export__',
- xtype: 'textarea'
- }],
- buttons: [{
- text: '关闭',
- handler: function() {
- this.openWin.hide();
- },
- scope: this
- }]
- });
- this.openWin.on('show', function() {
- Gef.activeEditor.disable();
- });
- this.openWin.on('hide', function() {
- Gef.activeEditor.enable();
- });
- }
- this.openWin.show(null, function() {
- Ext.getDom('__gef_jbpm4_xml_export__').value = xml;
- });
- }
- }, {
- text: '保存',
- iconCls: 'tb-save',
- handler: function() {
- var editor = Gef.activeEditor;
- var xml = editor.serial();
- var name = editor.getGraphicalViewer().getContents().getModel().text;
- Ext.Msg.wait('正在保存');
- Ext.Ajax.request({
- method: 'post',
- url: Gef.SAVE_URL,
- success: function(response) {
- try {
- var o = Ext.decode(response.responseText);
- if (o.success === true) {
- Ext.Msg.alert('信息', '操作成功');
- } else {
- Ext.Msg.alert('错误', o.errors.msg);
- }
- } catch(e) {
- Ext.Msg.alert('系统错误', response.responseText);
- }
- },
- failure: function(response) {
- Ext.Msg.alert('系统错误', response.responseText);
- },
- params: {
- id: Gef.PROCESS_ID,
- processName: name,
- xml: xml
- }
- });
- }
- }, {
- text: '发布',
- iconCls: 'tb-deploy',
- handler: function() {
- var editor = Gef.activeEditor;
- var isValid = new Validation(editor).validate();
- if (!isValid) {
- return false;
- }
- var xml = editor.serial();
- var model = editor.getGraphicalViewer().getContents().getModel();
- var name = model.text;
- Ext.Msg.wait('正在发布');
- Ext.Ajax.request({
- method: 'post',
- url: Gef.DEPLOY_URL,
- success: function(response) {
- try {
- var o = Ext.decode(response.responseText);
- if (o.success === true) {
- Ext.Msg.alert('信息', '操作成功');
- } else {
- Ext.Msg.alert('错误', o.errors.msg);
- }
- } catch(e) {
- Ext.Msg.alert('系统错误', response.responseText);
- }
- },
- failure: function(response) {
- Ext.Msg.alert('系统错误', response.responseText);
- },
- params: {
- id: Gef.PROCESS_ID,
- procCatId: model.procCatId,
- procDefName: model.procDefName,
- procDefCode: model.procDefCode,
- procVerName: model.procVerName,
- xml: xml
- }
- });
- }
- }, {
- text: '清空',
- iconCls: 'tb-clear',
- handler: function() {
- Gef.activeEditor.clear();
- }
- }, {
- text: '撤销',
- iconCls: 'tb-undo',
- handler: function() {
- var viewer = Gef.activeEditor.getGraphicalViewer();
- var browserListener = viewer.getBrowserListener();
- var selectionManager = browserListener.getSelectionManager();
- selectionManager.clearAll();
- var commandStack = viewer.getEditDomain().getCommandStack();
- commandStack.undo();
- },
- scope: this
- }, {
- text: '重做',
- iconCls: 'tb-redo',
- handler: function() {
- var viewer = Gef.activeEditor.getGraphicalViewer();
- var browserListener = viewer.getBrowserListener();
- var selectionManager = browserListener.getSelectionManager();
- selectionManager.clearAll();
- var commandStack = viewer.getEditDomain().getCommandStack();
- commandStack.redo();
- },
- scope: this
- }, {
- text: '布局',
- iconCls: 'tb-activity',
- handler: function() {
- var viewer = Gef.activeEditor.getGraphicalViewer();
- var browserListener = viewer.getBrowserListener();
- var selectionManager = browserListener.getSelectionManager();
- selectionManager.clearAll();
- new Layout(Gef.activeEditor).doLayout();
- },
- scope: this
- }, {
- text: '删除',
- iconCls: 'tb-delete',
- handler: this.removeSelected,
- scope: this
- }]);
- App.CanvasPanel.superclass.initComponent.call(this);
- },
- afterRender: function() {
- App.CanvasPanel.superclass.afterRender.call(this);
- var width = 3000;
- var height = 2500;
- Ext.DomHelper.append(this.body, [{
- id: '__gef_jbs__',
- tag: 'div',
- style: 'width:' + (width + 10) + 'px;height:' + (height + 10) + 'px;',
- children: [{
- id: '__gef_jbs_center__',
- tag: 'div',
- style: 'width:' + width + 'px;height:' + height + 'px;float:left;'
- }, {
- id: '__gef_jbs_right__',
- tag: 'div',
- style: 'width:10px;height:' + height + 'px;float:left;background-color:#EEEEEE;cursor:pointer;'
- }, {
- id: '__gef_jbs_bottom__',
- tag: 'div',
- style: 'width:' + (width + 10) + 'px;height:10px;float:left;background-color:#EEEEEE;cursor:pointer;'
- }]
- }]);
- var rightEl = Ext.fly('__gef_jbs_right__');
- rightEl.on('mouseover', function(e) {
- var t = e.getTarget();
- t.style.backgroundColor = 'yellow';
- t.style.backgroundImage = 'url(images/arrow/arrow-right.png)';
- });
- rightEl.on('mouseout', function(e) {
- var t = e.getTarget();
- t.style.backgroundColor = '#EEEEEE';
- t.style.backgroundImage = '';
- });
- rightEl.on('click', function(e) {
- Ext.fly('__gef_jbs__').setWidth(Ext.fly('__gef_jbs__').getWidth() + 100);
- Ext.fly('__gef_jbs_center__').setWidth(Ext.fly('__gef_jbs_center__').getWidth() + 100);
- Ext.fly('__gef_jbs_bottom__').setWidth(Ext.fly('__gef_jbs_bottom__').getWidth() + 100);
- Gef.activeEditor.addWidth(100);
- });
- var bottomEl = Ext.fly('__gef_jbs_bottom__');
- bottomEl.on('mouseover', function(e) {
- var t = e.getTarget();
- t.style.backgroundColor = 'yellow';
- t.style.backgroundImage = 'url(images/arrow/arrow-bottom.png)';
- });
- bottomEl.on('mouseout', function(e) {
- var t = e.getTarget();
- t.style.backgroundColor = '#EEEEEE';
- t.style.backgroundImage = '';
- });
- rightEl.on('click', function(e) {
- Ext.fly('__gef_jbs__').setHeight(Ext.fly('__gef_jbs__').getHeight() + 100);
- Ext.fly('__gef_jbs_center__').setHeight(Ext.fly('__gef_jbs_center__').getHeight() + 100);
- Ext.fly('__gef_jbs_right__').setHeight(Ext.fly('__gef_jbs_right__').getHeight() + 100);
- Gef.activeEditor.addHeight(100);
- });
- this.body.on('contextmenu', this.onContextMenu, this);
- },
- onContextMenu: function(e) {
- if (!this.contextMenu) {
- this.contextMenu = new Ext.menu.Menu({
- items: [{
- text: '详细配置',
- iconCls: 'tb-prop',
- handler: this.showWindow,
- scope: this
- }, {
- text: '删除',
- iconCls: 'tb-remove',
- handler: this.removeSelected,
- scope: this
- }]
- });
- }
- e.preventDefault();
- this.contextMenu.showAt(e.getXY());
- },
- showWindow: function() {
- App.propertyManager.changePropertyStatus('max');
- },
- removeSelected: function() {
- var viewer = Gef.activeEditor.getGraphicalViewer();
- var browserListener = viewer.getBrowserListener();
- var selectionManager = browserListener.getSelectionManager();
- var edge = selectionManager.selectedConnection;
- var nodes = selectionManager.items;
- var request = {};
- if (edge != null) {
- request.role = {
- name: 'REMOVE_EDGE'
- };
- this.executeCommand(edge, request);
- selectionManager.removeSelectedConnection();
- } else if (nodes.length > 0) {
- request.role = {
- name: 'REMOVE_NODES',
- nodes: nodes
- };
- this.executeCommand(viewer.getContents(), request);
- selectionManager.clearAll();
- }
- },
- executeCommand: function(editPart, request) {
- var command = editPart.getCommand(request);
- if (command != null) {
- Gef.activeEditor.getGraphicalViewer().getEditDomain().getCommandStack().execute(command);
- }
- }
- });
- /*
- * Compressed by JSA(www.xidea.org)
- */
- Layout = function(editor) {
- this.editor = editor;
- this.processEditPart = editor.getGraphicalViewer().getContents();
- this.processModel = this.processEditPart.getModel();
- };
- Layout.prototype = {
- doLayout: function() {
- var diagram = new Diagram();
- diagram.init(this.processModel);
- var sorter = new TopologicalSorter(diagram);
- var sortedElements = sorter.getSortedElements();
- var sortedIds = [];
- for (var i = 0; i < sortedElements.length; i++) {
- sortedIds.push(sortedElements[i].id);
- }
- //console.info(sortedIds);
- var layouter = new LeftToRightGridLayouter(diagram, sortedIds);
- layouter.doLayout();
- var edgeMap = diagram.getEdgeMap();
- for (var edgeId in edgeMap) {
- var edge = edgeMap[edgeId];
- new EdgeLayouter(layouter.grid, edge);
- }
- diagram.updateModel();
- }
- };
- ;
- Diagram = function() {
- };
- Diagram.prototype = {
- getNodeMap: function() {
- return this.nodeMap;
- },
- getEdgeMap: function() {
- return this.edgeMap;
- },
- init: function(process) {
- this.process = process;
- this.nodeMap = {};
- this.edgeMap = {};
- for (var i = 0; i < this.process.children.length; i++) {
- var child = process.children[i];
- var node = new Node();
- node.id = child.text;
- node.type = child.type;
- node.x = child.x;
- node.y = child.y;
- node.w = child.w;
- node.h = child.h;
- this.nodeMap[node.id] = node;
- }
- for (var i = 0; i < this.process.children.length; i++) {
- var child = process.children[i];
- for (var j = 0; j < child.getOutgoingConnections().length; j++) {
- var connection = child.getOutgoingConnections()[j];
- this.createEdge(connection);
- }
- }
- },
- createEdge: function(connection) {
- var connectionId = connection.getSource().text + '_' + connection.getTarget().text;
- var edge = this.edgeMap[connectionId];
- if (!edge) {
- edge = new Edge();
- edge.id = connectionId;
- edge.name = connection.text;
- edge.source = this.nodeMap[connection.getSource().text];
- edge.target = this.nodeMap[connection.getTarget().text];
- edge.source.outgoingLinks.push(edge);
- edge.target.incomingLinks.push(edge);
- this.edgeMap[connectionId] = edge;
- }
- },
- updateModel: function() {
- for (var nodeId in this.nodeMap) {
- var item = this.nodeMap[nodeId];
- var model = this.getModel(nodeId);
- model.x = item.x;
- model.y = item.y;
- model.getEditPart().getFigure().x = model.x;
- model.getEditPart().getFigure().y = model.y;
- for (var i = 0; i < item.outgoingLinks.length; i++) {
- var connection = item.outgoingLinks[i];
- var connectionModel = this.getConnectionModel(model, connection);
- if (connectionModel == null) {
- continue;
- }
- connectionModel.innerPoints = typeof connection.innerPoints == 'undefined' ? []
- : connection.innerPoints;
- connectionModel.textX = 0;
- connectionModel.textY = 0;
- connectionModel.getEditPart().getFigure().innerPoints = connectionModel.innerPoints;
- connectionModel.getEditPart().getFigure().textX = connectionModel.textX;
- connectionModel.getEditPart().getFigure().textY = connectionModel.textY;
- }
- }
- this.process.getEditPart().refresh();
- },
- getModel: function(name) {
- var model = null;
- Gef.each(this.process.children, function(item) {
- if (item.text == name) {
- model = item;
- return false;
- }
- });
- return model;
- },
- getConnectionModel: function(nodeModel, edge) {
- var model = null;
- Gef.each(nodeModel.getOutgoingConnections(), function(item) {
- if (item.getTarget().text == edge.getTarget().id) {
- model = item;
- return false;
- }
- });
- return model;
- }
- };
- ;
- // should be change name to LayoutingElement
- Node = function() {
- this.incomingLinks = [];
- this.outgoingLinks = [];
- };
- Node.prototype = {
- getIncomingLinks: function() {
- return this.incomingLinks;
- },
- getOutgoingLinks: function() {
- return this.outgoingLinks;
- },
- getPrecedingElements: function() {
- var previousElements = [];
- for (var i = 0; i < this.incomingLinks.length; i++) {
- previousElements.push(this.incomingLinks[i].source);
- }
- return previousElements;
- },
- getFollowingElements: function() {
- var followingElements = [];
- for (var i = 0; i < this.outgoingLinks.length; i++) {
- followingElements.push(this.outgoingLinks[i].target);
- }
- return followingElements;
- },
- isJoin: function() {
- return this.incomingLinks.length > 1;
- },
- isSplit: function() {
- return this.outgoingLinks.length > 1;
- },
- prevSplit: function() {
- var distance = 1000;
- var candidateDistance = 0;
- var split = null;
- var candidate = null;
- var precedingElements = this.getPrecedingElements();
- for (var i = 0; i < precedingElements.length; i++) {
- var elem = precedingElements[i];
- if (elem.isSplit()) {
- return elem;
- }
- candidate = elem.prevSplit();
- if (this.isJoin()) {
- // if this is not a join, we have only one precedingElement.
- candidateDistance = elem.backwardDistanceTo(candidate);
- }
- if (candidateDistance < distance) {
- split = candidate;
- distance = candidateDistance;
- }
- }
- return split;
- },
- backwardDistanceTo: function(other) {
- return this._backwardDistanceTo(other, []);
- },
- _backwardDistanceTo: function(other, historyElements) {
- if (other == this) {
- return 0;
- }
- if (historyElements.indexOf(this) != -1) {
- return 1000;
- }
- var d = 1000;
- var newHistory = [];
- newHistory.push(this);
- var precedingElements = this.getPrecedingElements();
- for (var i = 0; i < precedingElements.length; i++) {
- var el = precedingElements[i];
- d = Math.min(d, el._backwardDistanceTo(other, newHistory));
- }
- return d == 1000 ? d : d + 1;
- }
- };
- ;
- Edge = function() {
- this.source = null;
- this.target = null;
- };
- Edge.prototype = {
- getSource: function() {
- return this.source;
- },
- getTarget: function() {
- return this.target;
- },
- reverseOutgoingAndIncoming: function() {
- var index = 0;
- var oldSource = this.source;
- var oldTarget = this.target;
- index = oldSource.outgoingLinks.indexOf(this);
- oldSource.outgoingLinks.splice(index, 1);
- index = oldTarget.incomingLinks.indexOf(this);
- oldTarget.incomingLinks.splice(index, 1);
- var newSource = oldTarget;
- var newTarget = oldSource;
- newSource.outgoingLinks.push(this);
- newTarget.incomingLinks.push(this);
- this.source = newSource;
- this.target = newTarget;
- }
- };
- ;
- TopologicalSorter = function(diagram) {
- this.diagram = diagram;
- this.prepareDataAndSort(true);
- this.prepareDataAndSort(false);
- };
- TopologicalSorter.prototype = {
- getSortedElements: function() {
- return this.sortedElements;
- },
- prepareDataAndSort: function(shouldBackpatch) {
- this.sortedElements = [];
- this.elementsToSort = {};
- this.backwardsEdges = [];
- this.elementsToSortCount = 0;
- this.addAllChildren();
- this.topologicalSort();
- if (shouldBackpatch === true) {
- this.backpatchBackwardsEdges();
- }
- this.reverseBackwardsEdges();
- },
- addAllChildren: function() {
- for (var nodeId in this.diagram.nodeMap) {
- var node = this.diagram.nodeMap[nodeId];
- this.elementsToSort[nodeId] = new SortableLayoutingElement(node);
- this.elementsToSortCount++;
- }
- },
- topologicalSort: function() {
- var count = 0;
- var oldCount = 0;
- while (this.elementsToSortCount > 0) {
- var freeElements = this.getFreeElements();
- if (freeElements.length > 0) {
- for (var i = 0; i < freeElements.length; i++) {
- var freeElement = freeElements[i];
- this.sortedElements.push(freeElement.node);
- this.freeElementsFrom(freeElement);
- delete this.elementsToSort[freeElement.node.id];
- }
- } else {
- var entry = this.getLoopEntryPoint();
- for (var i = 0; i < entry.incomingLinks.length; i++) {
- var backId = entry.incomingLinks[i];
- entry.reverseIncomingLinkFrom(backId);
- var elem = this.elementsToSort[backId];
- elem.reverseOutgoingLinkTo(entry.node.id);
- this.backwardsEdges.push(new BackwardsEdge(backId, entry.node.id));
- }
- }
- }
- },
- backpatchBackwardsEdges: function() {
- var newBackwardsEdges = [];
- for (var i = 0; i < this.backwardsEdges.length; i++) {
- newBackwardsEdges.push(this.backwardsEdges[i]);
- }
- for (var i = 0; i < this.backwardsEdges.length; i++) {
- var edge = this.backwardsEdges[i];
- var sourceId = edge.getSource();
- var targetId = edge.getTarget();
- var sourceElement = this.diagram.nodeMap[sourceId];
- while (!(sourceElement.isJoin() || sourceElement.isSplit())) {
- var newSourceElement = sourceElement.getPrecedingElements()[0];
- targetId = newSourceElement.id;
- newBackwardsEdges.push(new BackwardsEdge(targetId, sourceId));
- sourceElement = newSourceElement;
- sourceId = targetId;
- }
- }
- this.backwardsEdges = newBackwardsEdges;
- },
- reverseBackwardsEdges: function() {
- var edgeMap = this.diagram.edgeMap;
- for (var i = 0; i < this.backwardsEdges.length; i++) {
- var backwardsEdge = this.backwardsEdges[i];
- var sourceId = backwardsEdge.getSource();
- var targetId = backwardsEdge.getTarget();
- var sourceElement = this.diagram.nodeMap[sourceId];
- var targetElement = this.diagram.nodeMap[targetId];
- var edge = this.getEdge(edgeMap, sourceElement, targetElement);
- backwardsEdge.setEdge(edge);
- if (edge) {
- // reverse edge outgoing and incoming
- edge.reverseOutgoingAndIncoming();
- }
- }
- },
- getFreeElements: function() {
- var freeElements = [];
- for (var nodeId in this.elementsToSort) {
- var elem = this.elementsToSort[nodeId];
- if (elem.isFree()) {
- freeElements.push(elem);
- }
- }
- return freeElements;
- },
- freeElementsFrom: function(freeElement) {
- for (var i = 0; i < freeElement.outgoingLinks.length; i++) {
- var id = freeElement.outgoingLinks[i];
- var targetElement = this.elementsToSort[id];
- if (targetElement) {
- targetElement.removeIncomingLinkFrom(freeElement.node.id);
- }
- }
- this.elementsToSortCount--;
- },
- getLoopEntryPoint: function() {
- for (var nodeId in this.elementsToSort) {
- var candidate = this.elementsToSort[nodeId];
- if (candidate.oldInCount > 1
- && candidate.oldInCount > candidate.incomingLinks.length) {
- return candidate;
- }
- }
- throw new Error('Could not find a valid loop entry point');
- },
- getEdge: function(edgeMap, sourceElement, targetElement) {
- for (var i = 0; i < sourceElement.outgoingLinks.length; i++) {
- var edge = sourceElement.outgoingLinks[i];
- if (edge.getTarget().id == targetElement.id) {
- return edge;
- }
- }
- return null;
- }
- };
- ;
- SortableLayoutingElement = function(node) {
- this.node = node;
- this.incomingLinks = [];
- this.outgoingLinks = [];
- for (var i = 0; i < node.incomingLinks.length; i++) {
- this.incomingLinks.push(node.incomingLinks[i].source.id);
- }
- for (var i = 0; i < node.outgoingLinks.length; i++) {
- this.outgoingLinks.push(node.outgoingLinks[i].target.id);
- }
- this.oldInCount = this.incomingLinks.length;
- this.isJoin = node.isJoin();
- };
- SortableLayoutingElement.prototype = {
- isFree: function() {
- return this.incomingLinks.length == 0;
- },
- removeIncomingLinkFrom: function(sourceId) {
- var index = this.incomingLinks.indexOf(sourceId);
- this.incomingLinks.splice(index, 1);
- },
- reverseIncomingLinkFrom: function(id) {
- this.removeIncomingLinkFrom(id);
- this.outgoingLinks.push(id);
- },
- reverseOutgoingLinkTo: function(id) {
- var index = this.outgoingLinks.indexOf(id);
- this.outgoingLinks.splice(index, 1);
- this.incomingLinks.push(id);
- }
- };
- ;
- BackwardsEdge = function(source, target) {
- this.source = source;
- this.target = target;
- };
- BackwardsEdge.prototype = {
- getEdge: function() {
- return this.edge;
- },
- setEdge: function(edge) {
- this.edge = edge;
- },
- getSource: function() {
- return this.source;
- },
- getTarget: function() {
- return this.target;
- }
- };
- ;
- LeftToRightGridLayouter = function(diagram, sortedIds) {
- this.diagram = diagram;
- this.sortedIds = sortedIds;
- };
- LeftToRightGridLayouter.prototype = {
- doLayout: function() {
- this.grid = new Grid();
- this.layoutElements();
- this.calcGeometry(this.grid);
- this.writeGeometry(this.grid);
- this.diagram.updateModel();
- },
- layoutElements: function() {
- for (var i = 0; i < this.sortedIds.length; i++) {
- var sortedId = this.sortedIds[i];
- var currentElement = this.diagram.nodeMap[sortedId];
- var precedingElements = currentElement.getPrecedingElements();
- var cellOfElement = this.placeElement(currentElement, precedingElements);
- if (currentElement.isJoin() && precedingElements.length != 0) {
- // there is an edge hitting us left, so lets forbid
- // interleaving to use the left cell, if this is empty
- cellOfElement.getPrevCell().setPackable(false);
- }
- if (currentElement.isSplit()) {
- this.prelayoutSuccessors(currentElement, cellOfElement);
- }
- }
- },
- placeElement: function(currentElement, precedingElements) {
- var newCell = null;
- if (precedingElements.length == 0) {
- this.grid.startCell.value = currentElement;
- newCell = this.grid.startCell;
- } else {
- var leftCell = null;
- var newCell = this.grid.getCellOfItem(currentElement);
- if (currentElement.isJoin()) {
- var splitFound = false;
- var split = currentElement.prevSplit();
- if (split != null) {
- var splits = new PriorityQueue(currentElement);
- splits.add(split);
- for (var i = 0; i < precedingElements.length; i++) {
- var elem = precedingElements[i];
- split = elem.prevSplit();
- if (split != null && !splits.contains(split)) {
- splits.add(split);
- //console.info(splits.items);
- }
- }
- split = null;
- // get split with most connections
- var maxCon = 0;
- for (var i = 0; i < splits.items.length; i++) {
- var target = splits.items[i];
- if (target == currentElement) {
- continue;
- }
- // current connections
- var curCon = 0;
- for (var j = 0; j < precedingElements.length; j++) {
- var elem = precedingElements[j];
- if (elem.backwardDistanceTo(target) < 1000) {
- curCon++;
- }
- }
- if (curCon > maxCon) {
- maxCon = curCon;
- split = target;
- }
- }
- splitFound = split != null;
- }
- // current cell position
- var x = 0;
- var yAcc = 0;
- var yCnt = 0;
- for (var i = 0; i < precedingElements.length; i++) {
- var elem = precedingElements[i];
- var tmp = this.grid.getCellOfItem(elem);
- if (tmp == null) {
- tmp = {
- getColIndex: function() {
- return 0;
- }
- };
- } else {
- yAcc += tmp.getRowIndex();
- yCnt++;
- }
- x = Math.max(x, tmp.getColIndex());
- }
- // farthest to the right
- if (splitFound) {
- leftCell = this.grid.getCellOfItem(split).row.cells[x];
- // set path to split unpackable
- for (var c = leftCell; c.value != split; c = c.getPrevCell()) {
- c.setPackable(false);
- }
- } else {
- if (yCnt == 0) {
- leftCell = this.grid.rows[0].above().cells[x];
- } else {
- leftCell = this.grid.rows[yAcc / yCnt].cells[x];
- }
- }
- if (newCell != null && newCell.value == currentElement) {
- newCell.value = null;
- }
- newCell = leftCell.after();
- // set all incoming pathes unpackable
- for (var i = 0; i < precedingElements.length; i++) {
- var el = precedingElements[i];
- var target = this.grid.getCellOfItem(el);
- if (target == null) {
- continue;
- }
- var start = target.row.cells[x + 1];
- for (var c = start; c != target; c = c.getPrevCell()) {
- c.setPackable(false);
- }
- }
- } else if (newCell == null) {
- // if not preLayouted
- var preElem = precedingElements[0];
- leftCell = this.grid.getCellOfItem(preElem);
- newCell = leftCell.after();
- }
- if (newCell.isFilled() && newCell.value != currentElement) {
- newCell.row.insertRowBeneath();
- newCell = newCell.beneath();
- }
- newCell.value = currentElement;
- newCell.getPrevCell().setPackable(false);
- }
- return newCell;
- },
- prelayoutSuccessors: function(currentElement, cellOfElement) {
- var baseCell = cellOfElement.after();
- var topCell = baseCell;
- var followingElements = currentElement.getFollowingElements();
- // heuristic for direct connection to join
- var directJoin = null;
- for (var i = 0; i < followingElements.length; i++) {
- var possibleJoin = followingElements[i];
- if (possibleJoin.isJoin()) {
- directJoin = possibleJoin;
- }
- }
- if (directJoin != null) {
- // put in the middle
- var index = followingElements.indexOf(directJoin);
- // remove
- followingElements.splice(index, 1);
- var position = parseInt(followingElements.length / 2, 10);
- // insert
- followingElements.splice(position, 0, directJoin);
- }
- // normal preLayout following elements
- var follow = parseInt(followingElements.length / 2, 10);
- for (var i = 0; i < follow; i++) {
- topCell.row.insertRowAbove();
- baseCell.row.insertRowBeneath();
- topCell = topCell.above();
- }
- for (var i = 0; i < followingElements.length; i++) {
- var newElem = followingElements[i];
- if (this.grid.getCellOfItem(newElem)) {
- continue;
- }
- topCell.value = newElem;
- topCell = topCell.beneath();
- if (topCell == baseCell && followingElements.length % 2 == 0) {
- topCell = topCell.beneath();
- }
- }
- },
- calcGeometry: function(grid) {
- grid.pack();
- var heightOfRow = [];
- for (var i = 0; i < grid.rowCount; i++) {
- heightOfRow.push(0);
- }
- var widthOfColumn = [];
- for (var i = 0; i < grid.colCount; i++) {
- widthOfColumn.push(0);
- }
- for (var i = 0; i < grid.rowCount; i++) {
- var row = grid.rows[i];
- for (var j = 0; j < grid.colCount; j++) {
- var cell = row.cells[j];
- if (cell.isFilled()) {
- var elem = cell.value;
- widthOfColumn[j] = Math.max(widthOfColumn[j], elem.w + 30);
- heightOfRow[i] = Math.max(heightOfRow[i], elem.h + 30);
- }
- }
- }
- this.heightOfRow = heightOfRow;
- this.widthOfColumn = widthOfColumn;
- this.totalWidth = 0;
- this.totalHeight = 0;
- for (var i = 0; i < grid.colCount; i++) {
- this.totalWidth += widthOfColumn[i];
- }
- for (var i = 0; i < grid.rowCount; i++) {
- this.totalHeight += heightOfRow[i];
- }
- },
- writeGeometry: function(grid) {
- var x = 0;
- var y = 0;
- for (var i = 0; i < grid.rowCount; i++) {
- var row = grid.rows[i];
- var cellHeight = this.heightOfRow[i];
- for (var j = 0; j < grid.colCount; j++) {
- var cell = row.cells[j];
- var cellWidth = this.widthOfColumn[j];
- if (cell.isFilled()) {
- var elem = cell.value;
- var newX = x + cellWidth / 2 - elem.w / 2;
- var newY = y + cellHeight / 2 - elem.h / 2;
- elem.x = newX;
- elem.y = newY;
- }
- x += cellWidth;
- }
- x = 0;
- y += cellHeight;
- }
- }
- };
- ;
- Grid = function() {
- var cell = new Cell();
- var row = new Row();
- row.grid = this;
- row.addCell(cell);
- this.rows = [row];
- this.startCell = cell;
- this.colCount = 1;
- this.rowCount = this.rows.length;
- };
- Grid.prototype = {
- addFirstRow: function() {
- var row = new Row();
- row.grid = this;
- for (var i = 0; i < this.rolCount; i++) {
- var cell = new Cell();
- row.addCell(cell);
- }
- this.rows.unshift(row);
- this.rowCount = this.rows.length;
- },
- addLastRow: function() {
- var row = new Row();
- row.grid = this;
- for (var i = 0; i < this.rolCount; i++) {
- row.addCell(new Cell());
- }
- this.rows.push(row);
- this.rowCount = this.rows.length;
- },
- addLastCol: function() {
- for (var i = 0; i < this.rowCount; i++) {
- var row = this.rows[i];
- row.addCell(new Cell());
- }
- this.colCount++;
- },
- getCellOfItem: function(elem) {
- for (var i = 0; i < this.rowCount; i++) {
- var row = this.rows[i];
- for (var j = 0; j < this.colCount; j++) {
- var cell = row.cells[j];
- if (cell.value == elem) {
- return cell;
- }
- }
- }
- return null;
- },
- pack: function() {
- var changed = false;
- do {
- changed = false;
- for (var i = 0; i < this.rows.length; i++) {
- var row = this.rows[i];
- changed |= row.tryInterleaveWith(row.getPrevRow());
- }
- for (var i = 0; i < this.rows.length; i++) {
- var row = this.rows[i];
- changed |= row.tryInterleaveWith(row.getNextRow());
- }
- } while (changed);
- },
- info: function() {
- var value = '';
- for (var i = 0; i < this.rows.length; i++) {
- var row = this.rows[i];
- for (var j = 0; j < row.cells.length; j++) {
- var cell = row.cells[j];
- var id = '[ ]';
- if (cell.isFilled()) {
- id = cell.value.id;
- } else if (cell.packable === false) {
- id = '[ p ]';
- }
- value += id;
- }
- value += '\n'
- }
- return value;
- }
- };
- ;
- Cell = function() {
- this.packable = true;
- };
- Cell.prototype = {
- isFilled: function() {
- return typeof this.value != 'undefined' && this.value != null;
- },
- isUnpackable: function() {
- return this.isFilled() || (this.packable === false);
- },
- setPackable: function(packable) {
- this.packable = packable;
- },
- getRowIndex: function() {
- return this.row.getIndex();
- },
- getColIndex: function() {
- for (var i = 0; i < this.row.cells.length; i++) {
- if (this.row.cells[i] == this) {
- return i;
- }
- }
- },
- after: function() {
- var colIndex = this.getColIndex();
- if (colIndex == this.row.cells.length - 1) {
- this.grid.addLastCol();
- }
- return this.row.cells[colIndex + 1];
- },
- above: function() {
- var rowIndex = this.getRowIndex();
- var colIndex = this.getColIndex();
- if (rowIndex == 0) {
- this.row.insertRowAbove();
- }
- return this.grid.rows[rowIndex - 1].cells[colIndex];
- },
- beneath: function() {
- var rowIndex = this.getRowIndex();
- var colIndex = this.getColIndex();
- if (rowIndex == this.grid.rowCount - 1) {
- this.row.insertRowBeneath();
- }
- return this.grid.rows[rowIndex + 1].cells[colIndex];
- },
- getPrevCell: function() {
- var index = this.getColIndex();
- return this.row.cells[index - 1];
- },
- getNextCell: function() {
- var index = this.getColIndex();
- return this.row.cells[index + 1];
- }
- };
- ;
- Row = function() {
- this.cells = [];
- };
- Row.prototype = {
- addCell: function(cell) {
- cell.row = this;
- cell.grid = this.grid;
- this.cells.push(cell);
- },
- getIndex: function() {
- for (var i = 0; i < this.grid.rows.length; i++) {
- if (this.grid.rows[i] == this) {
- return i;
- }
- }
- },
- insertRowBeneath: function() {
- var row = new Row();
- row.grid = this.grid;
- for (var i = 0; i < this.grid.colCount; i++) {
- row.addCell(new Cell());
- }
- var rowIndex = this.getIndex();
- var rows = this.grid.rows;
- if (rowIndex == rows.length - 1) {
- rows.push(row);
- } else {
- rows.splice(rowIndex + 1, 0, row);
- }
- this.grid.rowCount = rows.length;
- },
- insertRowAbove: function() {
- var row = new Row();
- row.grid = this.grid;
- for (var i = 0; i < this.grid.colCount; i++) {
- row.addCell(new Cell());
- }
- var rowIndex = this.getIndex();
- var rows = this.grid.rows;
- if (rowIndex == 0) {
- rows.unshift(row);
- } else {
- rows.splice(rowIndex, 0, row);
- }
- this.grid.rowCount = rows.length;
- },
- getPrevRow: function() {
- var index = this.getIndex();
- if (index > 0) {
- return this.grid.rows[index - 1];
- } else {
- return null;
- }
- },
- getNextRow: function() {
- var index = this.getIndex();
- if (index < this.grid.rows.length) {
- return this.grid.rows[index + 1];
- } else {
- return null;
- }
- },
- tryInterleaveWith: function(other) {
- if (!this.isInterleaveWith(other)) {
- return false;
- }
- for (var i = 0; i < this.cells.length; i++) {
- var cell = this.cells[i];
- var otherCell = other.cells[i];
- if (cell.isFilled()) {
- other.cells[i] = cell;
- } else if (cell.isUnpackable()) {
- otherCell.setPackable(false);
- }
- }
- this._remove();
- return true;
- },
- isInterleaveWith: function(other) {
- if (other == null || other == this) {
- return false;
- } else if (other.getPrevRow() != this && other.getNextRow() != this) {
- return false;
- }
- for (var i = 0; i < this.cells.length; i++) {
- var cell = this.cells[i];
- var otherCell = other.cells[i];
- if (cell.isUnpackable() && otherCell.isUnpackable()) {
- return false;
- }
- }
- return true;
- },
- _remove: function() {
- var index = this.getIndex();
- this.grid.rows.splice(index, 1);
- this.grid.rowCount--;
- }
- };
- ;
- PriorityQueue = function(center) {
- this.ce = center;
- this.items = [];
- };
- PriorityQueue.prototype = {
- add: function(element) {
- this.items.push(element);
- var len = this.items.length;
- for (var i = 0; i < len; i++) {
- for (var j = i; j < len; j++) {
- var elem1 = this.items[i];
- var elem2 = this.items[j];
- if (this.compareTo(elem1, elem2) > 0) {
- this.items[i] = elem2;
- this.items[j] = elem1;
- }
- }
- }
- },
- compareTo: function(elem1, elem2) {
- return this.ce.backwardDistanceTo(elem1) - this.ce.backwardDistanceTo(elem2);
- },
- contains: function(element) {
- return this.items.indexOf(element) != -1;
- }
- };
- ;
- EdgeLayouter = function(grid, edge) {
- this.grid = grid;
- this.edge = edge;
- edge.innerPoints = [];
- this.calculateGlobals();
- this.pickLayoutForEdge();
- };
- EdgeLayouter.prototype = {
- calculateGlobals: function() {
- this.source = this.edge.source;
- this.target = this.edge.target;
- this.sourceRelativeCenterX = this.source.w / 2;
- this.sourceRelativeCenterY = this.source.h / 2;
- this.targetRelativeCenterX = this.target.w / 2;
- this.targetRelativeCenterY = this.target.h / 2;
- this.sourceAbsoluteCenterX = this.source.x + this.sourceRelativeCenterX;
- this.sourceAbsoluteCenterY = this.source.y + this.sourceRelativeCenterY;
- this.targetAbsoluteCenterX = this.target.x + this.targetRelativeCenterX;
- this.targetAbsoluteCenterY = this.target.y + this.targetRelativeCenterY;
- this.sourceAbsoluteX = this.source.x;
- this.sourceAbsoluteY = this.source.y;
- this.sourceAbsoluteX2 = this.source.x + this.source.w;
- this.sourceAbsoluteY2 = this.source.y + this.source.h;
- this.targetAbsoluteX = this.target.x;
- this.targetAbsoluteY = this.target.y;
- this.targetAbsoluteX2 = this.target.x + this.target.w;
- this.targetAbsoluteY2 = this.target.y + this.target.h;
- this.sourceJoin = this.source.isJoin();
- this.sourceSplit = this.source.isSplit();
- this.targetJoin = this.target.isJoin();
- this.targetSplit = this.target.isSplit();
- this.backwards = this.sourceAbsoluteCenterX > this.targetAbsoluteCenterX;
- },
- pickLayoutForEdge: function() {
- // sourceX == targetX, up and down
- if (this.sourceAbsoluteCenterX == this.targetAbsoluteCenterX) {
- this.setEdgeDirectCenter();
- return;
- } else if (this.sourceAbsoluteCenterY == this.targetAbsoluteCenterY) {
- if (this.areCellsHorizontalFree()) {
- this.setEdgeDirectCenter();
- } else {
- this.setEdgeAroundTheCorner(true);
- }
- return;
- }
- if (this.sourceAbsoluteCenterX <= this.targetAbsoluteCenterX
- && this.sourceAbsoluteCenterY <= this.targetAbsoluteCenterY) {
- // target is right under
- if (this.sourcejoin && this.sourceSplit) {
- this.setEdgeStepRight();
- return;
- } else if (this.sourceSplit) {
- this.setEdge90DegreeRightUnderAntiClockwise();
- return;
- } else if (this.targetJoin) {
- this.setEdge90DegreeRightUnderClockwise();
- return;
- }
- } else if (this.sourceAbsoluteCenterX <= this.targetAbsoluteCenterX
- && this.sourceAbsoluteCenterY > this.targetAbsoluteCenterY) {
- // target is right above
- if (this.sourcejoin && this.sourceSplit) {
- this.setEdgeStepRight();
- return;
- } else if (this.sourceSplit) {
- this.setEdge90DegreeRightAboveClockwise();
- return;
- } else if (this.targetJoin) {
- this.setEdge90DegreeRightAboveAntiClockwise();
- return;
- }
- }
- if (this.sourceJoin && sourceSplit && (!this.backwards)) {
- this.setEdgeStepRight();
- return;
- }
- if (this.sourceJoin && sourceSplit) {
- this.setEdgeAroundTheCorner(true);
- return;
- }
- this.setEdgeDirectCenter();
- },
- areCellsHorizontalFree: function() {
- var fromCell = null;
- var toCell = null;
- if (this.sourceAbsoluteCenterX < this.targetAbsoluteCenterX) {
- fromCell = this.grid.getCellOfItem(this.source);
- toCell = this.grid.getCellOfItem(this.target);
- } else {
- fromCell = this.grid.getCellOfItem(this.target);
- toCell = this.grid.getCellOfItem(this.source);
- }
- fromCell = fromCell.getNextCell();
- while (fromCell != toCell) {
- if (fromCell == null || fromCell.isFilled()) {
- return false;
- }
- fromCell = fromCell.getNextCell();
- }
- return true;
- },
- setEdgeDirectCenter: function() {
- var boundsMinX = Math.min(this.sourceAbsoluteCenterX,
- this.targetAbsoluteCenterX);
- var boundsMinY = Math.min(this.sourceAbsoluteCenterY,
- this.targetAbsoluteCenterY);
- var boundsMaxX = Math.max(this.sourceAbsoluteCenterX,
- this.targetAbsoluteCenterX);
- var boundsMaxY = Math.max(this.sourceAbsoluteCenterY,
- this.targetAbsoluteCenterY);
- // this.edge.innerPoints = [];
- },
- setEdge90DegreeRightAboveClockwise: function() {
- this.edge.innerPoints = [
- [this.sourceAbsoluteCenterX, this.targetAbsoluteCenterY]
- ];
- },
- setEdge90DegreeRightAboveAntiClockwise: function() {
- this.edge.innerPoints = [
- [this.targetAbsoluteCenterX, this.sourceAbsoluteCenterY]
- ];
- },
- setEdge90DegreeRightUnderClockwise: function() {
- this.edge.innerPoints = [
- [this.targetAbsoluteCenterX, this.sourceAbsoluteCenterY]
- ];
- },
- setEdge90DegreeRightUnderAntiClockwise: function() {
- this.edge.innerPoints = [
- [this.sourceAbsoluteCenterX, this.targetAbsoluteCenterY]
- ];
- },
- setEdgeAroundTheCorner: function(down) {
- var height = Math.max(this.source.h / 2, this.target.h / 2) + 20;
- if (down) {
- height *= -1;
- }
- this.edge.innerPoints = [
- [this.sourceAbsoluteCenterX, this.sourceAbsoluteCenterY + height],
- [this.targetAbsoluteCenterX, this.sourceAbsoluteCenterY + height]
- ];
- }
- };
- Ext.ux.OneCombo = Ext.extend(Ext.form.ComboBox, {
- initComponent: function() {
- this.readOnly = true;
- this.displayField = 'text';
- this.valueField = 'text';
- this.triggerAction = 'all';
- this.mode = 'local';
- this.emptyText = 'Please Select...';
- this.store = new Ext.data.SimpleStore({
- expandData: true,
- fields: ['text']
- });
- this.store.loadData(this.data);
- Ext.ux.OneCombo.superclass.initComponent.call(this);
- }
- });
- Ext.reg('onecombo', Ext.ux.OneCombo);
- Gef.ns("Gef.planner");
- Gef.ns("Gef.planner.model");
- Gef.ns("Gef.planner.figure");
- Gef.ns("Gef.planner.editpart");
- function registerClass(type, name, url, w, h){
- function capitaliseFirstLetter(string)
- {
- return string.charAt(0).toUpperCase() + string.slice(1);
- }
- var preType = type;
- Gef.planner.model[preType+"Model"] = Gef.extend(Gef.jbs.model.GenericImageModel, {
- type: preType,
- url: url,
- constructor: function(conf) {
- Gef.planner.model[preType+"Model"].superclass.constructor.call(this, conf);
- this.w = w;
- this.h = h;
- }
- });
-
- Gef.planner.figure[preType+"Figure"] = Gef.extend(Gef.jbs.figure.GenericImageFigure, {
- });
- Gef.planner.editpart[preType+"EditPart"] = Gef.extend(Gef.jbs.editpart.GenericImageEditPart, {
- _figureClassName: "Gef.planner.figure." + preType + "Figure"
- });
- Gef.jbs.JBSModelFactory.registerModel(type, "Gef.planner.model." + preType + "Model");
- Gef.jbs.JBSEditPartFactory.registerEditPart(type, "Gef.planner.editpart." + preType + "EditPart");
- }
- var tpls = [
- ["Yupen", '浴盆', 'images/stenciles/planner/2d/bath.png', 190, 58],
- ["Danrenchuang", '单人床', 'images/stenciles/planner/2d/bed1.png', 243, 163],
- ["Shuangrenchuang", '双人床', 'images/stenciles/planner/2d/bed2.png', 228, 146],
- ["Yizi", '椅子', 'images/stenciles/planner/2d/chair.png', 46, 37],
- ["Shafa1", '沙发1', 'images/stenciles/planner/2d/coach1.png', 123, 51],
- ["Shafa2", '沙发2', 'images/stenciles/planner/2d/coach2.png', 57, 132],
- ["Diannaozhuo", '电脑桌', 'images/stenciles/planner/2d/desk.png', 145, 197],
- ["Canju", '餐具', 'images/stenciles/planner/2d/disc.png', 81,41],
- ["Huapen", '花盆', 'images/stenciles/planner/2d/flowers.png', 95, 60],
- ["Huatai", '花台', 'images/stenciles/planner/2d/flowers2.png', 56, 45],
- ["Xishoupen", '洗手盆', 'images/stenciles/planner/2d/hand.png', 51, 29],
- ["Huxing", '户型', 'images/stenciles/planner/2d/layout.png', 716, 1200],
- ["Canzhuo", '餐桌', 'images/stenciles/planner/2d/table.png', 118, 147],
- ["Matong", '马桶', 'images/stenciles/planner/2d/toilet.png', 78, 42],
- ["Dianshi", '电视', 'images/stenciles/planner/2d/tv.png', 52, 170],
- ["Shuichi", '水池', 'images/stenciles/planner/2d/water.png', 86, 35]
- ];
- (function regClasses(arr){
- for(var i=0;i<tpls.length;i++){
- registerClass.apply(this, tpls[i]);
- }
- })(tpls);
- function makePaletteArray(arr){
- var ret = [
- {name: 'select', image: 'scripts/gef/images/activities/select32.png', title: '选择'},
- {name: 'transition', image: 'scripts/gef/images/activities/32/flow_sequence.png', title: '连线'}
- ];
- for(var i=0;i<tpls.length;i++){
- ret.push({name: tpls[i][0], image: tpls[i][2], title: tpls[i][1]});
- }
- return ret;
- }
- function makeModelArray(arr){
- var ret = {
- select: {
- text: 'select',
- creatable: false
- },
- transition: {
- text: 'transition',
- creatable: false,
- isConnection: true
- }
- };
- for(var i=0;i<tpls.length;i++){
- ret[tpls[i][0]] = {
- text: tpls[i][0],
- w: tpls[i][3],
- h: tpls[i][4]
- };
- }
- return ret;
- }
- Gef.jbs.ExtPaletteHelper = Gef.extend(Gef.jbs.JBSPaletteHelper, {
- createSource: function() {
- return makeModelArray();
- },
- getSource: function() {
- if (!this.source) {
- this.source = this.createSource();
- }
- return this.source;
- },
- render: Gef.emptyFn,
- changeActivePalette: function(paletteConfig) {
- var el = null;
- if (this.getActivePalette()) {
- var oldActivePaletteId = this.getActivePalette().text;
- el = document.getElementById(oldActivePaletteId + '-img');
- el.style.border = '';
- }
- this.setActivePalette(paletteConfig);
- el = document.getElementById(paletteConfig.text + '-img');
- el.style.border = '1px dotted black';
- },
- resetActivePalette: function() {
- this.changeActivePalette({
- text: 'select'
- });
- },
- getPaletteConfig: function(p, t) {
- var id = t.parentNode.id;
- if (!id) {
- return null;
- }
- var source = this.getSource();
- var paletteConfig = this.getSource()[id];
- if (!paletteConfig) {
- return null;
- }
- this.changeActivePalette(paletteConfig);
- if (paletteConfig.creatable === false) {
- return null;
- }
- return paletteConfig;
- }
- });
- App.PalettePanel = Ext.extend(Ext.Panel, {
- initComponent: function() {
- this.region = 'west';
- this.title = '图元库';
- this.iconCls = 'tb-activity';
- this.width = 110;
- this.initPalette();
- App.PalettePanel.superclass.initComponent.call(this);
- },
- initPalette: function() {
- var paletteType = null;
- if (!Gef.PALETTE_TYPE) {
- paletteType = 'accordion';
- } else {
- paletteType = Gef.PALETTE_TYPE;
- }
- this.configLayout(paletteType);
- this.configItems(paletteType);
- },
- createHtml: function(array, divId) {
- if (divId) {
- var html = '<div id="' + divId + '" unselectable="on">';
- } else {
- var html = '<div unselectable="on">';
- }
- for (var i = 0; i < array.length; i++) {
- var item = array[i];
- html += '<div id="' + item.name + '" class="paletteItem-' + item.name
- + '" style="text-align:center;font-size:12px;cursor:pointer;" unselectable="on"><img width="32" height="32" id="'
- + item.name + '-img" class="paletteItem-' + item.name
- + '" src="' + item.image + '" unselectable="on"><br>'
- + item.title + '</div>';
- }
- html += '</div>';
- return html;
- },
- /**
- * this.layout = 'accordion';
- */
- configLayout: function(type) {
- if (!type || type == 'plain') {
- //
- } else if (type && type == 'accordion') {
- this.layout = 'accordion';
- }
- },
- configItems: function(type) {
- if (type && type == 'accordion') {
- this.createItemsForAccordion();
- } else if (!type || type == 'plain') {
- this.createItemsForHtml();
- }
- },
- createItemsForAccordion: function() {
- this.id = '__gef_jbs_palette__';
- this.items = [{
- title: '基础图元',
- iconCls: 'tb-activity',
- autoScroll: true,
- html: this.createHtml(makePaletteArray(tpls))
- }, {
- title: '高级图元',
- iconCls: 'tb-activity',
- autoScroll: true,
- html: ''
- }];
- },
- createItemsForHtml: function() {
- this.autoScroll = true;
- this.html = this.createHtml([
- {name: 'select', image: 'select32', title: '选择'},
- {name: 'transition', image: '32/flow_sequence', title: '连线'},
- {name: 'start', image: '32/start_event_empty', title: '开始'},
- {name: 'end', image: '32/end_event_terminate', title: '结束'},
- {name: 'cancel', image: '32/end_event_cancel', title: '取消'},
- {name: 'error', image: '32/end_event_error', title: '错误'},
- {name: 'state', image: '32/task_wait', title: '等待'},
- {name: 'task', image: '32/task_empty', title: '任务'},
- {name: 'decision', image: '32/gateway_exclusive', title: '决策'},
- {name: 'fork', image: '32/gateway_parallel', title: '并行'},
- {name: 'join', image: '32/gateway_parallel', title: '汇聚'},
- {name: 'java', image: '32/task_java', title: 'JAVA'},
- {name: 'script', image: '32/task_java', title: '脚本'},
- {name: 'hql', image: '32/task_hql', title: 'HQL'},
- {name: 'sql', image: '32/task_sql', title: 'SQL'},
- {name: 'mail', image: '32/task_empty', title: '邮件'},
- {name: 'custom', image: '32/task_empty', title: '自定义'},
- {name: 'subProcess', image: '32/task_empty', title: '子流程'},
- {name: 'jms', image: '32/task_empty', title: 'JMS'},
- {name: 'ruleDecision', image: '32/gateway_exclusive', title: '规则决策'},
- {name: 'rules', image: '32/task_empty', title: '规则'},
- {name: 'human', image: '32/task_empty', title: '人工节点'},
- {name: 'auto', image: '32/task_empty', title: '自动节点'},
- {name: 'counter-sign', image: '32/task_empty', title: '会签节点'}
- ], '__gef_jbs_palette__');
- }
- });
- Ext.ux.TwoCombo = Ext.extend(Ext.form.ComboBox, {
- initComponent: function() {
- this.readOnly = true;
- this.displayField = 'text';
- this.valueField = 'value';
- this.triggerAction = 'all';
- this.mode = 'local';
- this.emptyText = 'Please Select...';
- this.store = new Ext.data.SimpleStore({
- fields: ['value', 'text']
- });
- this.store.loadData(this.data);
- Ext.ux.TwoCombo.superclass.initComponent.call(this);
- }
- });
- Ext.reg('twocombo', Ext.ux.TwoCombo);
|