all-editor.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477
  1. Gef.ns('Gef.jbs');
  2. Gef.jbs.ExtEditor = Gef.extend(Gef.jbs.JBSEditor, {
  3. constructor: function() {
  4. Gef.jbs.ExtEditor.superclass.constructor.call(this);
  5. this.modelFactory = new Gef.jbs.JBSModelFactory();
  6. this.editPartFactory = new Gef.jbs.JBSEditPartFactory();
  7. },
  8. createGraphicalViewer: function() {
  9. return new Gef.jbs.ExtGraphicalViewer(this);
  10. },
  11. getPaletteHelper: function() {
  12. if (!this.paletteHelper) {
  13. this.paletteHelper = new Gef.jbs.ExtPaletteHelper(this);
  14. }
  15. return this.paletteHelper;
  16. },
  17. addSelectionListener: function(selectionListener) {
  18. this.getGraphicalViewer()
  19. .getBrowserListener()
  20. .selectionListenerTracker
  21. .addSelectionListener(selectionListener);
  22. },
  23. enable: function() {
  24. this.getGraphicalViewer().getBrowserListener().enable();
  25. },
  26. disable: function() {
  27. this.getGraphicalViewer().getBrowserListener().disable();
  28. }
  29. });
  30. Gef.override(Gef.jbs.tool.ChangeTypeTool, {
  31. handleMenuClick: function(item, e) {
  32. var toolTracker = this.toolTracker;
  33. var type = item.changedType;
  34. var oldModel = this.node.editPart.model;
  35. var newModel = toolTracker.getModelFactory().createModel(type);
  36. var compoundCommand = new Gef.commands.CompoundCommand();
  37. compoundCommand.addCommand(new Gef.gef.command.CreateNodeCommand(newModel, oldModel.getParent(), {
  38. x: oldModel.x,
  39. y: oldModel.y,
  40. w: oldModel.w,
  41. h: oldModel.h
  42. }));
  43. Gef.each(oldModel.getIncomingConnections(), function(connection) {
  44. var connectionType = connection.getType();
  45. var newConnection = toolTracker.getModelFactory().createModel(connectionType);
  46. newConnection.text = connection.text;
  47. compoundCommand.addCommand(new Gef.gef.command.RemoveConnectionCommand(
  48. connection
  49. ));
  50. compoundCommand.addCommand(new Gef.gef.command.CreateConnectionCommand(
  51. newConnection,
  52. connection.getSource(),
  53. newModel
  54. ));
  55. compoundCommand.addCommand(new Gef.gef.command.ResizeConnectionCommand(
  56. newConnection,
  57. [],
  58. connection.innerPoints
  59. ));
  60. });
  61. Gef.each(oldModel.getOutgoingConnections(), function(connection) {
  62. var connectionType = connection.getType();
  63. var newConnection = toolTracker.getModelFactory().createModel(connectionType);
  64. newConnection.text = connection.text;
  65. compoundCommand.addCommand(new Gef.gef.command.RemoveConnectionCommand(
  66. connection
  67. ));
  68. compoundCommand.addCommand(new Gef.gef.command.CreateConnectionCommand(
  69. newConnection,
  70. newModel,
  71. connection.getTarget()
  72. ));
  73. compoundCommand.addCommand(new Gef.gef.command.ResizeConnectionCommand(
  74. newConnection,
  75. [],
  76. connection.innerPoints
  77. ));
  78. });
  79. compoundCommand.addCommand(new Gef.gef.command.RemoveNodeCommand(oldModel));
  80. toolTracker.getCommandStack().execute(compoundCommand);
  81. toolTracker.getSelectionManager().addSelectedNode(newModel.editPart);
  82. },
  83. drag: function(toolTracker, request) {
  84. this.toolTracker = toolTracker;
  85. var items = [];
  86. Gef.each(this.allowedTypes, function(item) {
  87. if (item.type == this.node.editPart.model.getType()) {
  88. return true;
  89. }
  90. items.push({
  91. text: item.name,
  92. changedType: item.type,
  93. handler: this.handleMenuClick,
  94. scope: this
  95. });
  96. }, this);
  97. var contextMenu = new Ext.menu.Menu({
  98. items: items
  99. });
  100. contextMenu.showAt([
  101. request.point.absoluteX,
  102. request.point.absoluteY
  103. ]);
  104. },
  105. move: function(toolTracker, request) {
  106. },
  107. drop: function(toolTracker, request) {
  108. }
  109. });
  110. Gef.ns("Gef.jbs");
  111. Gef.jbs.ExtGraphicalViewer = Gef.extend(Gef.gef.support.DefaultGraphicalViewer, {
  112. render: function() {
  113. this.canvasEl = Ext.getDom('__gef_jbs_center__');
  114. this.rootEditPart.render();
  115. this.rendered = true;
  116. },
  117. getPaletteLocation: function() {
  118. if (!this.paletteLocation) {
  119. var paletteBox = Ext.get('__gef_jbs_palette__').getBox();
  120. this.paletteLocation = {
  121. x: paletteBox.x,
  122. y: paletteBox.y,
  123. w: paletteBox.width,
  124. h: paletteBox.height
  125. };
  126. }
  127. return this.paletteLocation;
  128. },
  129. getCanvasLocation: function() {
  130. //if (!this.canvasLocation) {
  131. var box = Ext.get('__gef_jbs_center__').getBox();
  132. var scroll = Ext.get('__gef_jbs_center__').getScroll();
  133. this.canvasLocation = {
  134. x: box.x,
  135. y: box.y,
  136. w: box.width,
  137. h: box.height
  138. };
  139. //}
  140. return this.canvasLocation;
  141. }
  142. });
  143. Gef.jbs.ExtPaletteHelper = Gef.extend(Gef.jbs.JBSPaletteHelper, {
  144. createSource: function() {
  145. return {
  146. select: {
  147. text: 'select',
  148. creatable: false
  149. },
  150. transition: {
  151. text: 'transition',
  152. creatable: false,
  153. isConnection: true
  154. },
  155. start: {
  156. text: 'start',
  157. w: 48,
  158. h: 48
  159. },
  160. end: {
  161. text: 'end',
  162. w: 48,
  163. h: 48
  164. },
  165. cancel: {
  166. text: 'cancel',
  167. w: 48,
  168. h: 48
  169. },
  170. error: {
  171. text: 'error',
  172. w: 48,
  173. h: 48
  174. },
  175. state: {
  176. text: 'state',
  177. w: 90,
  178. h: 50
  179. },
  180. task: {
  181. text: 'task',
  182. w: 90,
  183. h: 50
  184. },
  185. decision: {
  186. text: 'decision',
  187. w: 48,
  188. h: 48
  189. },
  190. fork: {
  191. text: 'fork',
  192. w: 48,
  193. h: 48
  194. },
  195. join: {
  196. text: 'join',
  197. w: 48,
  198. h: 48
  199. },
  200. java: {
  201. text: 'java',
  202. w: 90,
  203. h: 50
  204. },
  205. script: {
  206. text: 'script',
  207. w: 90,
  208. h: 50
  209. },
  210. hql: {
  211. text: 'hql',
  212. w: 90,
  213. h: 50
  214. },
  215. sql: {
  216. text: 'sql',
  217. w: 90,
  218. h: 50
  219. },
  220. custom: {
  221. text: 'custom',
  222. w: 90,
  223. h: 50
  224. },
  225. mail: {
  226. text: 'mail',
  227. w: 90,
  228. h: 50
  229. },
  230. subProcess: {
  231. text: 'subProcess',
  232. w: 90,
  233. h: 50
  234. },
  235. jms: {
  236. text: 'jms',
  237. w: 90,
  238. h: 50
  239. },
  240. ruleDecision: {
  241. text: 'ruleDecision',
  242. w: 48,
  243. h: 48
  244. },
  245. rules: {
  246. text: 'rules',
  247. w: 90,
  248. h: 50
  249. },
  250. auto: {
  251. text: 'auto',
  252. w: 90,
  253. h: 50
  254. },
  255. human: {
  256. text: 'human',
  257. w: 90,
  258. h: 50
  259. },
  260. 'counter-sign': {
  261. text: 'counter-sign',
  262. w: 90,
  263. h: 50
  264. },
  265. foreach: {
  266. text: 'foreach',
  267. w: 48,
  268. h: 48
  269. }
  270. };
  271. },
  272. getSource: function() {
  273. if (!this.source) {
  274. this.source = this.createSource();
  275. }
  276. return this.source;
  277. },
  278. render: Gef.emptyFn,
  279. changeActivePalette: function(paletteConfig) {
  280. var el = null;
  281. if (this.getActivePalette()) {
  282. var oldActivePaletteId = this.getActivePalette().text;
  283. el = document.getElementById(oldActivePaletteId + '-img');
  284. el.style.border = '';
  285. }
  286. this.setActivePalette(paletteConfig);
  287. el = document.getElementById(paletteConfig.text + '-img');
  288. el.style.border = '1px dotted black';
  289. },
  290. resetActivePalette: function() {
  291. this.changeActivePalette({
  292. text: 'select'
  293. });
  294. },
  295. getPaletteConfig: function(p, t) {
  296. var id = t.parentNode.id;
  297. if (!id) {
  298. return null;
  299. }
  300. var source = this.getSource();
  301. var paletteConfig = this.getSource()[id];
  302. if (!paletteConfig) {
  303. return null;
  304. }
  305. this.changeActivePalette(paletteConfig);
  306. if (paletteConfig.creatable === false) {
  307. return null;
  308. }
  309. return paletteConfig;
  310. }
  311. });
  312. Gef.ns('Gef.jbs');
  313. //监听 2013-12-18 zhouy
  314. Gef.jbs.ExtSelectionListener = Gef.extend(Gef.gef.tracker.DefaultSelectionListener, {
  315. constructor: function(propertyGrid) {
  316. this.propertyGrid = propertyGrid;
  317. },
  318. selectNode: function(editPart) {
  319. var node = editPart.getModel();
  320. if (this.propertyGrid) {
  321. this.propertyGrid.updateForm(node);
  322. }
  323. var formCondition=getUrlParam('formCondition');
  324. if(node.dom && node.dom.tagName=='custom' && !formCondition){
  325. var arr=new Array();
  326. for(var i=0;i<node.dom.elements.length;i++){
  327. arr.push({
  328. text:node.dom.elements[i].attributes.name,
  329. url:node.dom.elements[i].attributes.type,
  330. handler:this.openCard,
  331. sysid:node.dom.elements[i].attributes.id,
  332. selectlistener:this,
  333. currentEditPart: editPart
  334. });
  335. }
  336. var contextMenu = new Ext.menu.Menu({
  337. items: arr
  338. });
  339. contextMenu.showAt([
  340. node.x+20,
  341. node.y+40
  342. ]);
  343. }
  344. this.model = node;
  345. },
  346. selectConnection: function(editPart) {
  347. var connection = editPart.getModel();
  348. if (this.propertyGrid) {
  349. this.propertyGrid.updateForm(connection);
  350. }
  351. this.model = connection;
  352. },
  353. selectDefault: function(editPart) {
  354. var process = editPart.getModel();
  355. if (this.propertyGrid) {
  356. this.propertyGrid.updateForm(process);
  357. }
  358. this.model = process;
  359. },
  360. setEditor: function(editor) {
  361. this.editor = editor;
  362. this.model = editor.getGraphicalViewer().getContents().getModel();
  363. },
  364. editText: function(model, text) {
  365. var command = new Gef.gef.command.EditTextCommand(model, text);
  366. this.editor.getEditDomain().getCommandStack().execute(command);
  367. },
  368. getModel: function() {
  369. return this.model;
  370. },
  371. parseUrl: function(url){
  372. var id = url.substring(url.lastIndexOf('?')+1);//将作为新tab的id
  373. if (id == null) {
  374. id = url.substring(0,url.lastIndexOf('.'));
  375. }
  376. if(url.indexOf('session:em_uu')>-1){//对url中session值的处理
  377. url = url.replace(/session:em_uu/,em_uu);
  378. }
  379. if(url.indexOf('session:em_code')>-1){//对url中em_code值的处理
  380. url = url.replace(/session:em_code/, "'" + em_code + "'");
  381. }
  382. if(url.indexOf('sysdate')>-1){//对url中系统时间sysdate的处理
  383. url = url.replace(/sysdate/, "to_date('" + Ext.Date.toString(new Date()) + "','yyyy-mm-dd')");
  384. }
  385. if(url.indexOf('session:em_name')>-1){
  386. url = url.replace(/session:em_name/,"'"+em_name+"'" );
  387. }
  388. return url;
  389. },
  390. openCard: function(){
  391. var me = this;
  392. var panel =Ext.getCmp(me.sysid);
  393. var url=me.selectlistener.parseUrl( me.url);
  394. if(!panel){
  395. panel = {
  396. title : me.text,
  397. tag : 'iframe',
  398. id : me.sysid,
  399. tabConfig: {tooltip:me.text},
  400. frame : true,
  401. border : false,
  402. layout : 'fit',
  403. bodyPadding: 0,
  404. html : '<iframe id="iframe_ext-window" src="' + basePath + url + '" height="100%" width="100%" frameborder="0" style="border-width: 0px;padding: 0px;" scrolling="auto"></iframe>',
  405. closable : true,
  406. listeners : {
  407. close : function(){
  408. var main = parent.Ext.getCmp("content-panel");
  409. main.setActiveTab(Ext.getCmp("HomePage"));
  410. }
  411. }
  412. };
  413. var o = (typeof panel == "string" ? panel : panel.id);
  414. var main = parent.Ext.getCmp("content-panel");
  415. var tab = main.getComponent(o);
  416. if (tab) {
  417. main.setActiveTab(tab);
  418. } else if(typeof panel!="string"){
  419. panel.id = o;
  420. var p = main.add(panel);
  421. main.setActiveTab(p);
  422. }
  423. } else{
  424. var main = Ext.getCmp("content-panel");
  425. main.setActiveTab(panel);
  426. }
  427. }
  428. });