Sidebar.js 41 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186
  1. /**
  2. *$id:Action 。JS,V 2017-12-19
  3. *$author shen.zhi
  4. */
  5. /**
  6. * Construcs a new sidebar for the given editor.
  7. */
  8. function Sidebar(editorUi, container)
  9. {
  10. this.editorUi = editorUi;
  11. this.container = container;
  12. this.palettes = new Object();
  13. this.showTooltips = true;
  14. this.graph = new Graph(document.createElement('div'), null, null, this.editorUi.editor.graph.getStylesheet());
  15. this.graph.foldingEnabled = false;
  16. this.graph.autoScroll = false;
  17. this.graph.setTooltips(false);
  18. this.graph.setConnectable(false);
  19. this.graph.resetViewOnRootChange = false;
  20. this.graph.view.setTranslate(this.thumbBorder, this.thumbBorder);
  21. this.graph.setEnabled(false);
  22. // Workaround for VML rendering in IE8 standards mode where the container must be in the DOM
  23. // so that VML references can be restored via document.getElementById in mxShape.init.
  24. if (document.documentMode == 8)
  25. {
  26. document.body.appendChild(this.graph.container);
  27. }
  28. // Workaround for no rendering in 0 coordinate in FF 10
  29. if (this.shiftThumbs)
  30. {
  31. this.graph.view.canvas.setAttribute('transform', 'translate(1, 1)');
  32. }
  33. if (!mxClient.IS_TOUCH)
  34. {
  35. mxEvent.addListener(document, 'mouseup', mxUtils.bind(this, function()
  36. {
  37. this.showTooltips = true;
  38. }));
  39. // Enables tooltips after scroll
  40. mxEvent.addListener(container, 'scroll', mxUtils.bind(this, function()
  41. {
  42. this.showTooltips = true;
  43. }));
  44. mxEvent.addListener(document, 'mousedown', mxUtils.bind(this, function()
  45. {
  46. this.showTooltips = false;
  47. this.hideTooltip();
  48. }));
  49. mxEvent.addListener(document, 'mousemove', mxUtils.bind(this, function(evt)
  50. {
  51. var src = mxEvent.getSource(evt);
  52. while (src != null)
  53. {
  54. if (src == this.currentElt)
  55. {
  56. return;
  57. }
  58. src = src.parentNode;
  59. }
  60. this.hideTooltip();
  61. }));
  62. // Handles mouse leaving the window
  63. mxEvent.addListener(document, 'mouseout', mxUtils.bind(this, function(evt)
  64. {
  65. if (evt.toElement == null && evt.relatedTarget == null)
  66. {
  67. this.hideTooltip();
  68. }
  69. }));
  70. }
  71. this.init();
  72. //图像预fetches提示
  73. new Image().src = IMAGE_PATH + '/tooltip.png';
  74. };
  75. /**
  76. * 将所有工具栏的侧边栏。
  77. */
  78. Sidebar.prototype.init = function()
  79. {
  80. var dir = STENCIL_PATH;
  81. //this.addGeneralPalette(true);
  82. //this.addUmlPalette(true);
  83. //this.addBpmnPalette(dir, false);
  84. //this.addStencilPalette('flowchart', 'Flowchart', dir + '/flowchart.xml',';fillColor=#ffffff;strokeColor=#000000;strokeWidth=2');
  85. //this.addStencilPalette('basic', mxResources.get('basic'), dir + '/basic.xml',';fillColor=#ffffff;strokeColor=#000000;strokeWidth=2');
  86. //this.addStencilPalette('arrows', mxResources.get('arrows'), dir + '/arrows.xml',';fillColor=#ffffff;strokeColor=#000000;strokeWidth=2');
  87. this.addImagePalette('clipart', mxResources.get('clipart'), dir + '/clipart/', '_128x128.png',
  88. [ 'colud', 'Firewall_02', 'Server_Tower', 'serverDB', 'serverAuth',
  89. 'serverPrint', 'serverEmail', 'serverDisk', 'Router_Icon', 'routerFirewall', 'route1', 'atm', 'police',
  90. 'accessServer','SIP', 'sipProxy', 'ITP', 'CA', '3U', 'ipv6Route',
  91. '3layer', 'pbx', 'IDS', 'actionCheck', 'gateWayVPN', 'server1','server2','normalServer','IPSAN','H3Cswitch']);
  92. this.addImagePalette('clipartB', mxResources.get('clipartB'), dir + '/clipart/', '.png',
  93. [ 'pic1','pic2','pic3','pic4','pic5','pic6','pic7','pic8','pic9','pic10','pic11','pic12','pic13','pic14','pic15']);
  94. };
  95. /**
  96. * 指定工具提示应该是可见的。默认的是真的。
  97. */
  98. Sidebar.prototype.enableTooltips = !mxClient.IS_TOUCH;
  99. /**
  100. * 将缩略图1像素。
  101. */
  102. Sidebar.prototype.shiftThumbs = mxClient.IS_SVG || document.documentMode == 8;
  103. /**
  104. * 指定工具提示的延迟。默认是16像素。
  105. */
  106. Sidebar.prototype.tooltipBorder = 16;
  107. /**
  108. * 指定工具提示的延迟。默认是2像素。
  109. */
  110. Sidebar.prototype.thumbBorder = 2;
  111. /**
  112. * Specifies the delay for the tooltip. Default is 300 ms.
  113. */
  114. Sidebar.prototype.tooltipDelay = 300;
  115. /**
  116. * Specifies if edges should be used as templates if clicked. Default is true.
  117. */
  118. Sidebar.prototype.installEdges = true;
  119. /**
  120. * Specifies the URL of the gear image.
  121. */
  122. Sidebar.prototype.gearImage = STENCIL_PATH + '/clipart/Gear_128x128.png';
  123. /**
  124. * Specifies the width of the thumbnails.
  125. */
  126. Sidebar.prototype.thumbWidth = 26;
  127. /**
  128. * Specifies the height of the thumbnails.
  129. */
  130. Sidebar.prototype.thumbHeight = 26;
  131. /**
  132. * Adds all palettes to the sidebar.
  133. */
  134. Sidebar.prototype.showTooltip = function(elt, cells)
  135. {
  136. if (this.enableTooltips && this.showTooltips)
  137. {
  138. if (this.currentElt != elt)
  139. {
  140. if (this.thread != null)
  141. {
  142. window.clearTimeout(this.thread);
  143. this.thread = null;
  144. }
  145. var show = mxUtils.bind(this, function()
  146. {
  147. // Workaround for off-screen text rendering in IE
  148. var old = mxText.prototype.getTableSize;
  149. if (this.graph.dialect != mxConstants.DIALECT_SVG)
  150. {
  151. mxText.prototype.getTableSize = function(table)
  152. {
  153. var oldParent = table.parentNode;
  154. document.body.appendChild(table);
  155. var size = new mxRectangle(0, 0, table.offsetWidth, table.offsetHeight);
  156. oldParent.appendChild(table);
  157. return size;
  158. };
  159. }
  160. // Lazy creation of the DOM nodes and graph instance
  161. if (this.tooltip == null)
  162. {
  163. this.tooltip = document.createElement('div');
  164. this.tooltip.className = 'geSidebarTooltip';
  165. document.body.appendChild(this.tooltip);
  166. this.graph2 = new Graph(this.tooltip, null, null, this.editorUi.editor.graph.getStylesheet());
  167. this.graph2.view.setTranslate(this.tooltipBorder, this.tooltipBorder);
  168. this.graph2.resetViewOnRootChange = false;
  169. this.graph2.foldingEnabled = false;
  170. this.graph2.autoScroll = false;
  171. this.graph2.setTooltips(false);
  172. this.graph2.setConnectable(false);
  173. this.graph2.setEnabled(false);
  174. this.tooltipImage = mxUtils.createImage(IMAGE_PATH + '/tooltip.png');
  175. this.tooltipImage.style.position = 'absolute';
  176. this.tooltipImage.style.width = '14px';
  177. this.tooltipImage.style.height = '27px';
  178. document.body.appendChild(this.tooltipImage);
  179. }
  180. this.graph2.model.clear();
  181. this.graph2.addCells(cells);
  182. var bounds = this.graph2.getGraphBounds();
  183. var width = bounds.x + bounds.width + this.tooltipBorder;
  184. var height = bounds.y + bounds.height + this.tooltipBorder;
  185. if (mxClient.IS_QUIRKS)
  186. {
  187. width += 4;
  188. height += 4;
  189. }
  190. this.tooltip.style.display = 'block';
  191. this.tooltip.style.overflow = 'visible';
  192. this.tooltipImage.style.visibility = 'visible';
  193. this.tooltip.style.width = width + 'px';
  194. this.tooltip.style.height = height + 'px';
  195. var left = this.container.clientWidth + this.editorUi.splitSize + 3;
  196. var top = Math.max(0, (this.container.offsetTop + elt.offsetTop - this.container.scrollTop - height / 2 + 16));
  197. // Workaround for ignored position CSS style in IE9
  198. // (changes to relative without the following line)
  199. this.tooltip.style.position = 'absolute';
  200. this.tooltip.style.left = left + 'px';
  201. this.tooltip.style.top = top + 'px';
  202. this.tooltipImage.style.left = (left - 13) + 'px';
  203. this.tooltipImage.style.top = (top + height / 2 - 13) + 'px';
  204. mxText.prototype.getTableSize = old;
  205. });
  206. if (this.tooltip != null && this.tooltip.style.display != 'none')
  207. {
  208. show();
  209. }
  210. else
  211. {
  212. this.thread = window.setTimeout(show, this.tooltipDelay);
  213. }
  214. this.currentElt = elt;
  215. }
  216. }
  217. };
  218. /**
  219. * Hides the current tooltip.
  220. */
  221. Sidebar.prototype.hideTooltip = function()
  222. {
  223. if (this.thread != null)
  224. {
  225. window.clearTimeout(this.thread);
  226. this.thread = null;
  227. }
  228. if (this.tooltip != null)
  229. {
  230. this.tooltip.style.display = 'none';
  231. this.tooltipImage.style.visibility = 'hidden';
  232. this.currentElt = null;
  233. }
  234. };
  235. /**
  236. * Adds the general palette to the sidebar.
  237. */
  238. Sidebar.prototype.addGeneralPalette = function(expand)
  239. {
  240. this.addPalette('general', mxResources.get('general'), expand || true, mxUtils.bind(this, function(content)
  241. {
  242. content.appendChild(this.createVertexTemplate('swimlane', 200, 200, 'Container'));
  243. content.appendChild(this.createVertexTemplate('swimlane;horizontal=0', 200, 200, 'Pool'));
  244. content.appendChild(this.createVertexTemplate('text', 40, 26, 'Text'));
  245. content.appendChild(this.createVertexTemplate('icon;image=' + this.gearImage, 60, 60, 'Image'));
  246. content.appendChild(this.createVertexTemplate('label;image=' + this.gearImage, 140, 60, 'Label'));
  247. content.appendChild(this.createVertexTemplate(null, 120, 60));
  248. content.appendChild(this.createVertexTemplate('rounded=1', 120, 60));
  249. content.appendChild(this.createVertexTemplate('ellipse', 80, 80));
  250. content.appendChild(this.createVertexTemplate('ellipse;shape=doubleEllipse', 80, 80));
  251. content.appendChild(this.createVertexTemplate('triangle', 60, 80));
  252. content.appendChild(this.createVertexTemplate('rhombus', 80, 80));
  253. content.appendChild(this.createVertexTemplate('shape=hexagon', 120, 80));
  254. content.appendChild(this.createVertexTemplate('shape=actor;verticalLabelPosition=bottom;verticalAlign=top', 40, 60));
  255. content.appendChild(this.createVertexTemplate('ellipse;shape=cloud', 120, 80));
  256. content.appendChild(this.createVertexTemplate('shape=cylinder', 60, 80));
  257. content.appendChild(this.createVertexTemplate('line', 160, 10));
  258. content.appendChild(this.createVertexTemplate('line;direction=south', 10, 160));
  259. content.appendChild(this.createVertexTemplate('shape=xor', 60, 80));
  260. content.appendChild(this.createVertexTemplate('shape=or', 60, 80));
  261. content.appendChild(this.createVertexTemplate('shape=step', 120, 80));
  262. content.appendChild(this.createVertexTemplate('shape=tape', 120, 100));
  263. content.appendChild(this.createVertexTemplate('shape=cube', 120, 80));
  264. content.appendChild(this.createVertexTemplate('shape=note', 80, 100));
  265. content.appendChild(this.createVertexTemplate('shape=folder', 120, 120));
  266. content.appendChild(this.createVertexTemplate('shape=card', 60, 80));
  267. content.appendChild(this.createVertexTemplate('shape=plus', 20, 20));
  268. content.appendChild(this.createEdgeTemplate('edgeStyle=none;endArrow=none;', 100, 100));
  269. content.appendChild(this.createEdgeTemplate('edgeStyle=none', 100, 100));
  270. content.appendChild(this.createEdgeTemplate('edgeStyle=elbowEdgeStyle;elbow=horizontal', 100, 100));
  271. content.appendChild(this.createEdgeTemplate('edgeStyle=elbowEdgeStyle;elbow=vertical', 100, 100));
  272. content.appendChild(this.createEdgeTemplate('edgeStyle=entityRelationEdgeStyle', 100, 100));
  273. content.appendChild(this.createEdgeTemplate('edgeStyle=segmentEdgeStyle', 100, 100));
  274. content.appendChild(this.createEdgeTemplate('edgeStyle=orthogonalEdgeStyle', 100, 100));
  275. content.appendChild(this.createEdgeTemplate('shape=link', 100, 100));
  276. content.appendChild(this.createEdgeTemplate('arrow', 100, 100));
  277. }));
  278. };
  279. /**
  280. * Adds the general palette to the sidebar.
  281. */
  282. Sidebar.prototype.addUmlPalette = function(expand)
  283. {
  284. this.addPalette('uml', 'UML', expand || false, mxUtils.bind(this, function(content)
  285. {
  286. content.appendChild(this.createVertexTemplate('', 110, 50, 'Object'));
  287. var classCell = new mxCell('<p style="margin:0px;margin-top:4px;text-align:center;">' +
  288. '<b>Class</b></p>' +
  289. '<hr/><div style="height:2px;"></div><hr/>', new mxGeometry(0, 0, 140, 60),
  290. 'verticalAlign=top;align=left;overflow=fill;fontSize=12;fontFamily=Helvetica;html=1');
  291. classCell.vertex = true;
  292. content.appendChild(this.createVertexTemplateFromCells([classCell], 140, 60));
  293. var classCell = new mxCell('<p style="margin:0px;margin-top:4px;text-align:center;">' +
  294. '<b>Class</b></p>' +
  295. '<hr/><p style="margin:0px;margin-left:4px;">+ field: Type</p><hr/>' +
  296. '<p style="margin:0px;margin-left:4px;">+ method(): Type</p>', new mxGeometry(0, 0, 160, 90),
  297. 'verticalAlign=top;align=left;overflow=fill;fontSize=12;fontFamily=Helvetica;html=1');
  298. classCell.vertex = true;
  299. content.appendChild(this.createVertexTemplateFromCells([classCell], 160, 90));
  300. var classCell = new mxCell('<p style="margin:0px;margin-top:4px;text-align:center;">' +
  301. '<i>&lt;&lt;Interface&gt;&gt;</i><br/><b>Interface</b></p>' +
  302. '<hr/><p style="margin:0px;margin-left:4px;">+ field1: Type<br/>' +
  303. '+ field2: Type</p>' +
  304. '<hr/><p style="margin:0px;margin-left:4px;">' +
  305. '+ method1(Type): Type<br/>' +
  306. '+ method2(Type, Type): Type</p>', new mxGeometry(0, 0, 190, 140),
  307. 'verticalAlign=top;align=left;overflow=fill;fontSize=12;fontFamily=Helvetica;html=1');
  308. classCell.vertex = true;
  309. content.appendChild(this.createVertexTemplateFromCells([classCell], 190, 140));
  310. var classCell = new mxCell('Module', new mxGeometry(0, 0, 120, 60),
  311. 'shape=component;align=left;spacingLeft=36');
  312. classCell.vertex = true;
  313. content.appendChild(this.createVertexTemplateFromCells([classCell], 120, 60));
  314. var classCell = new mxCell('&lt;&lt;component&gt;&gt;<br/><b>Component</b>', new mxGeometry(0, 0, 180, 90),
  315. 'overflow=fill;html=1');
  316. classCell.vertex = true;
  317. var classCell1 = new mxCell('', new mxGeometry(1, 0, 20, 20), 'shape=component;jettyWidth=8;jettyHeight=4;');
  318. classCell1.vertex = true;
  319. classCell1.connectable = false;
  320. classCell1.geometry.relative = true;
  321. classCell1.geometry.offset = new mxPoint(-30, 10);
  322. classCell.insert(classCell1);
  323. content.appendChild(this.createVertexTemplateFromCells([classCell], 180, 90));
  324. var classCell = new mxCell('<p style="margin:0px;margin-top:6px;text-align:center;"><b>Component</b></p>' +
  325. '<hr/><p style="margin:0px;margin-left:8px;">+ Attribute1: Type<br/>+ Attribute2: Type</p>', new mxGeometry(0, 0, 180, 90),
  326. 'verticalAlign=top;align=left;overflow=fill;html=1');
  327. classCell.vertex = true;
  328. var classCell1 = new mxCell('', new mxGeometry(1, 0, 20, 20), 'shape=component;jettyWidth=8;jettyHeight=4;');
  329. classCell1.vertex = true;
  330. classCell1.connectable = false;
  331. classCell1.geometry.relative = true;
  332. classCell1.geometry.offset = new mxPoint(-23, 3);
  333. classCell.insert(classCell1);
  334. content.appendChild(this.createVertexTemplateFromCells([classCell], 180, 90));
  335. content.appendChild(this.createVertexTemplate('shape=lollipop;direction=south;', 30, 10));
  336. var cardCell = new mxCell('Block', new mxGeometry(0, 0, 180, 120),
  337. 'verticalAlign=top;align=left;spacingTop=8;spacingLeft=2;spacingRight=12;shape=cube;size=10;direction=south;fontStyle=4;');
  338. cardCell.vertex = true;
  339. content.appendChild(this.createVertexTemplateFromCells([cardCell], 180, 120));
  340. content.appendChild(this.createVertexTemplate('shape=folder;fontStyle=1;spacingTop=10;tabWidth=40;tabHeight=14;tabPosition=left;', 70, 50,
  341. 'package'));
  342. var classCell = new mxCell('<p style="margin:0px;margin-top:4px;text-align:center;text-decoration:underline;">' +
  343. '<b>Object:Type</b></p><hr/>' +
  344. '<p style="margin:0px;margin-left:8px;">field1 = value1<br/>field2 = value2<br>field3 = value3</p>',
  345. new mxGeometry(0, 0, 160, 90),
  346. 'verticalAlign=top;align=left;overflow=fill;fontSize=12;fontFamily=Helvetica;html=1');
  347. classCell.vertex = true;
  348. content.appendChild(this.createVertexTemplateFromCells([classCell], 160, 90));
  349. var tableCell = new mxCell('<table cellpadding="5" style="font-size:9pt;border:none;border-collapse:collapse;width:100%;">' +
  350. '<tr><td colspan="2" style="border:1px solid gray;background:#e4e4e4;">Tablename</td></tr>' +
  351. '<tr><td style="border:1px solid gray;">PK</td><td style="border:1px solid gray;">uniqueId</td></tr>' +
  352. '<tr><td style="border:1px solid gray;">FK1</td><td style="border:1px solid gray;">foreignKey</td></tr>' +
  353. '<tr><td style="border:1px solid gray;"></td><td style="border:1px solid gray;">fieldname</td></tr>' +
  354. '</table>', new mxGeometry(0, 0, 180, 99), 'verticalAlign=top;align=left;overflow=fill;html=1');
  355. tableCell.vertex = true;
  356. content.appendChild(this.createVertexTemplateFromCells([tableCell], 180, 99));
  357. content.appendChild(this.createVertexTemplate('shape=umlActor;verticalLabelPosition=bottom;verticalAlign=top', 40, 80, 'Actor'));
  358. content.appendChild(this.createVertexTemplate('ellipse', 140, 70, 'Use Case'));
  359. var cardCell = new mxCell('', new mxGeometry(0, 0, 30, 30),
  360. 'ellipse;shape=startState;fillColor=#000000;strokeColor=#ff0000;');
  361. cardCell.vertex = true;
  362. var assoc2 = new mxCell('', new mxGeometry(0, 0, 0, 0), 'edgeStyle=elbowEdgeStyle;elbow=horizontal;verticalAlign=bottom;endArrow=open;endSize=8;strokeColor=#ff0000;');
  363. assoc2.geometry.setTerminalPoint(new mxPoint(15, 70), false);
  364. assoc2.edge = true;
  365. cardCell.insertEdge(assoc2, true);
  366. content.appendChild(this.createVertexTemplateFromCells([cardCell, assoc2], 30, 30));
  367. var cardCell = new mxCell('Activity', new mxGeometry(0, 0, 120, 40),
  368. 'rounded=1;arcSize=40;fillColor=#ffffc0;strokeColor=#ff0000;');
  369. cardCell.vertex = true;
  370. var assoc2 = new mxCell('', new mxGeometry(0, 0, 0, 0), 'edgeStyle=elbowEdgeStyle;elbow=horizontal;verticalAlign=bottom;endArrow=open;endSize=8;strokeColor=#ff0000;');
  371. assoc2.geometry.setTerminalPoint(new mxPoint(60, 80), false);
  372. assoc2.edge = true;
  373. cardCell.insertEdge(assoc2, true);
  374. content.appendChild(this.createVertexTemplateFromCells([cardCell, assoc2], 120, 40));
  375. var cardCell = new mxCell('<div style="margin-top:8px;"><b>Composite State</b><hr/>Subtitle</div>', new mxGeometry(0, 0, 160, 60),
  376. 'rounded=1;arcSize=40;overflow=fill;html=1;verticalAlign=top;fillColor=#ffffc0;strokeColor=#ff0000;');
  377. cardCell.vertex = true;
  378. var assoc2 = new mxCell('', new mxGeometry(0, 0, 0, 0), 'edgeStyle=elbowEdgeStyle;elbow=horizontal;verticalAlign=bottom;endArrow=open;endSize=8;strokeColor=#ff0000;');
  379. assoc2.geometry.setTerminalPoint(new mxPoint(80, 100), false);
  380. assoc2.edge = true;
  381. cardCell.insertEdge(assoc2, true);
  382. content.appendChild(this.createVertexTemplateFromCells([cardCell, assoc2], 160, 60));
  383. var cardCell = new mxCell('Condition', new mxGeometry(0, 0, 80, 40),
  384. 'rhombus;fillColor=#ffffc0;strokeColor=#ff0000;');
  385. cardCell.vertex = true;
  386. var assoc1 = new mxCell('no', new mxGeometry(0, 0, 0, 0), 'edgeStyle=elbowEdgeStyle;elbow=horizontal;align=left;verticalAlign=bottom;endArrow=open;endSize=8;strokeColor=#ff0000;');
  387. assoc1.geometry.setTerminalPoint(new mxPoint(120, 20), false);
  388. assoc1.geometry.relative = true;
  389. assoc1.geometry.x = -1;
  390. assoc1.edge = true;
  391. cardCell.insertEdge(assoc1, true);
  392. var assoc2 = new mxCell('yes', new mxGeometry(0, 0, 0, 0), 'edgeStyle=elbowEdgeStyle;elbow=horizontal;align=left;verticalAlign=top;endArrow=open;endSize=8;strokeColor=#ff0000;');
  393. assoc2.geometry.setTerminalPoint(new mxPoint(40, 80), false);
  394. assoc2.geometry.relative = true;
  395. assoc2.geometry.x = -1;
  396. assoc2.edge = true;
  397. cardCell.insertEdge(assoc2, true);
  398. content.appendChild(this.createVertexTemplateFromCells([cardCell, assoc1, assoc2], 80, 40));
  399. var cardCell = new mxCell('', new mxGeometry(0, 0, 200, 10),
  400. 'shape=line;strokeWidth=6;strokeColor=#ff0000;');
  401. cardCell.vertex = true;
  402. var assoc2 = new mxCell('', new mxGeometry(0, 0, 0, 0), 'edgeStyle=elbowEdgeStyle;elbow=horizontal;verticalAlign=bottom;endArrow=open;endSize=8;strokeColor=#ff0000;');
  403. assoc2.geometry.setTerminalPoint(new mxPoint(100, 50), false);
  404. assoc2.edge = true;
  405. cardCell.insertEdge(assoc2, true);
  406. content.appendChild(this.createVertexTemplateFromCells([cardCell, assoc2], 200, 10));
  407. content.appendChild(this.createVertexTemplate('ellipse;shape=endState;fillColor=#000000;strokeColor=#ff0000', 30, 30));
  408. var classCell1 = new mxCell(':Object', new mxGeometry(0, 0, 100, 50));
  409. classCell1.vertex = true;
  410. var classCell2 = new mxCell('', new mxGeometry(40, 50, 20, 240), 'shape=line;direction=north;dashed=1');
  411. classCell2.vertex = true;
  412. content.appendChild(this.createVertexTemplateFromCells([classCell1, classCell2], 100, 290));
  413. var classCell1 = new mxCell('', new mxGeometry(100, 0, 20, 70));
  414. classCell1.vertex = true;
  415. var assoc1 = new mxCell('invoke', new mxGeometry(0, 0, 0, 0), 'edgeStyle=elbowEdgeStyle;elbow=vertical;verticalAlign=bottom;endArrow=block;');
  416. assoc1.geometry.setTerminalPoint(new mxPoint(0, 0), true);
  417. assoc1.edge = true;
  418. classCell1.insertEdge(assoc1, false);
  419. content.appendChild(this.createVertexTemplateFromCells([classCell1, assoc1], 120, 70));
  420. var classCell1 = new mxCell('', new mxGeometry(100, 0, 20, 70));
  421. classCell1.vertex = true;
  422. var assoc1 = new mxCell('invoke', new mxGeometry(0, 0, 0, 0), 'edgeStyle=elbowEdgeStyle;elbow=vertical;verticalAlign=bottom;endArrow=block;');
  423. assoc1.geometry.setTerminalPoint(new mxPoint(0, 0), true);
  424. assoc1.edge = true;
  425. classCell1.insertEdge(assoc1, false);
  426. var assoc2 = new mxCell('return', new mxGeometry(0, 0, 0, 0), 'edgeStyle=elbowEdgeStyle;elbow=vertical;verticalAlign=bottom;dashed=1;endArrow=open;endSize=8;');
  427. assoc2.geometry.setTerminalPoint(new mxPoint(0, 70), false);
  428. assoc2.edge = true;
  429. classCell1.insertEdge(assoc2, true);
  430. var assoc3 = new mxCell('invoke', new mxGeometry(0, 0, 0, 0), 'edgeStyle=elbowEdgeStyle;elbow=vertical;align=left;endArrow=open;');
  431. assoc3.edge = true;
  432. classCell1.insertEdge(assoc3, true);
  433. classCell1.insertEdge(assoc3, false);
  434. content.appendChild(this.createVertexTemplateFromCells([classCell1, assoc1, assoc2, assoc3], 120, 70));
  435. var assoc = new mxCell('name', new mxGeometry(0, 0, 0, 0), 'endArrow=block;endFill=1;edgeStyle=orthogonalEdgeStyle;align=left;verticalAlign=top;');
  436. assoc.geometry.setTerminalPoint(new mxPoint(0, 0), true);
  437. assoc.geometry.setTerminalPoint(new mxPoint(160, 0), false);
  438. assoc.geometry.relative = true;
  439. assoc.geometry.x = -1;
  440. assoc.edge = true;
  441. var sourceLabel = new mxCell('1', new mxGeometry(-1, 0, 0, 0), 'resizable=0;align=left;verticalAlign=bottom;labelBackgroundColor=#ffffff;fontSize=10');
  442. sourceLabel.geometry.relative = true;
  443. sourceLabel.setConnectable(false);
  444. sourceLabel.vertex = true;
  445. assoc.insert(sourceLabel);
  446. content.appendChild(this.createEdgeTemplateFromCells([assoc], 160, 0));
  447. var assoc = new mxCell('', new mxGeometry(0, 0, 0, 0), 'endArrow=none;edgeStyle=orthogonalEdgeStyle;');
  448. assoc.geometry.setTerminalPoint(new mxPoint(0, 0), true);
  449. assoc.geometry.setTerminalPoint(new mxPoint(160, 0), false);
  450. assoc.edge = true;
  451. var sourceLabel = new mxCell('parent', new mxGeometry(-1, 0, 0, 0), 'resizable=0;align=left;verticalAlign=bottom;labelBackgroundColor=#ffffff;fontSize=10');
  452. sourceLabel.geometry.relative = true;
  453. sourceLabel.setConnectable(false);
  454. sourceLabel.vertex = true;
  455. assoc.insert(sourceLabel);
  456. var targetLabel = new mxCell('child', new mxGeometry(1, 0, 0, 0), 'resizable=0;align=right;verticalAlign=bottom;labelBackgroundColor=#ffffff;fontSize=10');
  457. targetLabel.geometry.relative = true;
  458. targetLabel.setConnectable(false);
  459. targetLabel.vertex = true;
  460. assoc.insert(targetLabel);
  461. content.appendChild(this.createEdgeTemplateFromCells([assoc], 160, 0));
  462. var assoc = new mxCell('1', new mxGeometry(0, 0, 0, 0), 'endArrow=open;endSize=12;startArrow=diamondThin;startSize=14;startFill=0;edgeStyle=orthogonalEdgeStyle;align=left;verticalAlign=bottom;');
  463. assoc.geometry.setTerminalPoint(new mxPoint(0, 0), true);
  464. assoc.geometry.setTerminalPoint(new mxPoint(160, 0), false);
  465. assoc.geometry.relative = true;
  466. assoc.geometry.x = -1;
  467. assoc.edge = true;
  468. content.appendChild(this.createEdgeTemplateFromCells([assoc], 160, 0));
  469. var assoc = new mxCell('Relation', new mxGeometry(0, 0, 0, 0), 'endArrow=open;endSize=12;startArrow=diamondThin;startSize=14;startFill=0;edgeStyle=orthogonalEdgeStyle;');
  470. assoc.geometry.setTerminalPoint(new mxPoint(0, 0), true);
  471. assoc.geometry.setTerminalPoint(new mxPoint(160, 0), false);
  472. assoc.edge = true;
  473. var sourceLabel = new mxCell('0..n', new mxGeometry(-1, 0, 0, 0), 'resizable=0;align=left;verticalAlign=top;labelBackgroundColor=#ffffff;fontSize=10');
  474. sourceLabel.geometry.relative = true;
  475. sourceLabel.setConnectable(false);
  476. sourceLabel.vertex = true;
  477. assoc.insert(sourceLabel);
  478. var targetLabel = new mxCell('1', new mxGeometry(1, 0, 0, 0), 'resizable=0;align=right;verticalAlign=top;labelBackgroundColor=#ffffff;fontSize=10');
  479. targetLabel.geometry.relative = true;
  480. targetLabel.setConnectable(false);
  481. targetLabel.vertex = true;
  482. assoc.insert(targetLabel);
  483. content.appendChild(this.createEdgeTemplateFromCells([assoc], 160, 0));
  484. var assoc = new mxCell('Use', new mxGeometry(0, 0, 0, 0), 'endArrow=open;endSize=12;dashed=1');
  485. assoc.geometry.setTerminalPoint(new mxPoint(0, 0), true);
  486. assoc.geometry.setTerminalPoint(new mxPoint(160, 0), false);
  487. assoc.edge = true;
  488. content.appendChild(this.createEdgeTemplateFromCells([assoc], 160, 0));
  489. var assoc = new mxCell('Extends', new mxGeometry(0, 0, 0, 0), 'endArrow=block;endSize=16;endFill=0;dashed=1');
  490. assoc.geometry.setTerminalPoint(new mxPoint(0, 0), true);
  491. assoc.geometry.setTerminalPoint(new mxPoint(160, 0), false);
  492. assoc.edge = true;
  493. content.appendChild(this.createEdgeTemplateFromCells([assoc], 160, 0));
  494. var assoc = new mxCell('', new mxGeometry(0, 0, 0, 0), 'endArrow=block;startArrow=block;endFill=1;startFill=1');
  495. assoc.geometry.setTerminalPoint(new mxPoint(0, 0), true);
  496. assoc.geometry.setTerminalPoint(new mxPoint(160, 0), false);
  497. assoc.edge = true;
  498. content.appendChild(this.createEdgeTemplateFromCells([assoc], 160, 0));
  499. }));
  500. };
  501. /**
  502. * Adds the BPMN library to the sidebar.
  503. */
  504. Sidebar.prototype.addBpmnPalette = function(dir, expand)
  505. {
  506. this.addStencilPalette('bpmn', 'BPMN', dir + '/bpmn.xml',
  507. ';fillColor=#ffffff;strokeColor=#000000;perimeter=ellipsePerimeter;',
  508. ['Cancel', 'Error', 'Link', 'Message', 'Compensation', 'Multiple', 'Rule', 'Timer'],
  509. function(content)
  510. {
  511. content.appendChild(this.createVertexTemplate('swimlane;horizontal=0;', 300, 160, 'Pool'));
  512. var classCell = new mxCell('Process', new mxGeometry(0, 0, 140, 60),
  513. 'rounded=1');
  514. classCell.vertex = true;
  515. var classCell1 = new mxCell('', new mxGeometry(1, 1, 30, 30), 'shape=mxgraph.bpmn.timer_start;perimeter=ellipsePerimeter;');
  516. classCell1.vertex = true;
  517. classCell1.geometry.relative = true;
  518. classCell1.geometry.offset = new mxPoint(-40, -15);
  519. classCell.insert(classCell1);
  520. content.appendChild(this.createVertexTemplateFromCells([classCell], 140, 60));
  521. var classCell = new mxCell('Process', new mxGeometry(0, 0, 140, 60),
  522. 'rounded=1');
  523. classCell.vertex = true;
  524. var classCell1 = new mxCell('', new mxGeometry(0.5, 1, 12, 12), 'shape=plus');
  525. classCell1.vertex = true;
  526. classCell1.connectable = false;
  527. classCell1.geometry.relative = true;
  528. classCell1.geometry.offset = new mxPoint(-6, -12);
  529. classCell.insert(classCell1);
  530. content.appendChild(this.createVertexTemplateFromCells([classCell], 140, 60));
  531. var classCell = new mxCell('Process', new mxGeometry(0, 0, 140, 60),
  532. 'rounded=1');
  533. classCell.vertex = true;
  534. var classCell1 = new mxCell('', new mxGeometry(0, 0, 20, 14), 'shape=message');
  535. classCell1.vertex = true;
  536. classCell1.connectable = false;
  537. classCell1.geometry.relative = true;
  538. classCell1.geometry.offset = new mxPoint(5, 5);
  539. classCell.insert(classCell1);
  540. content.appendChild(this.createVertexTemplateFromCells([classCell], 140, 60));
  541. var classCell = new mxCell('', new mxGeometry(0, 0, 60, 40), 'shape=message');
  542. classCell.vertex = true;
  543. content.appendChild(this.createEdgeTemplateFromCells([classCell], 60, 40));
  544. var assoc = new mxCell('Sequence', new mxGeometry(0, 0, 0, 0), 'endArrow=block;endFill=1;endSize=6');
  545. assoc.geometry.setTerminalPoint(new mxPoint(0, 0), true);
  546. assoc.geometry.setTerminalPoint(new mxPoint(160, 0), false);
  547. assoc.edge = true;
  548. content.appendChild(this.createEdgeTemplateFromCells([assoc], 160, 0));
  549. var assoc = new mxCell('Default', new mxGeometry(0, 0, 0, 0), 'startArrow=dash;startSize=8;endArrow=block;endFill=1;endSize=6');
  550. assoc.geometry.setTerminalPoint(new mxPoint(0, 0), true);
  551. assoc.geometry.setTerminalPoint(new mxPoint(160, 0), false);
  552. assoc.edge = true;
  553. content.appendChild(this.createEdgeTemplateFromCells([assoc], 160, 0));
  554. var assoc = new mxCell('Conditional', new mxGeometry(0, 0, 0, 0), 'startArrow=diamondThin;startFill=0;startSize=14;endArrow=block;endFill=1;endSize=6');
  555. assoc.geometry.setTerminalPoint(new mxPoint(0, 0), true);
  556. assoc.geometry.setTerminalPoint(new mxPoint(160, 0), false);
  557. assoc.edge = true;
  558. content.appendChild(this.createEdgeTemplateFromCells([assoc], 160, 0));
  559. var assoc = new mxCell('', new mxGeometry(0, 0, 0, 0), 'startArrow=oval;startFill=0;startSize=7;endArrow=block;endFill=0;endSize=10;dashed=1');
  560. assoc.geometry.setTerminalPoint(new mxPoint(0, 0), true);
  561. assoc.geometry.setTerminalPoint(new mxPoint(160, 0), false);
  562. assoc.edge = true;
  563. content.appendChild(this.createEdgeTemplateFromCells([assoc], 160, 0));
  564. var assoc = new mxCell('', new mxGeometry(0, 0, 0, 0), 'startArrow=oval;startFill=0;startSize=7;endArrow=block;endFill=0;endSize=10;dashed=1');
  565. assoc.geometry.setTerminalPoint(new mxPoint(0, 0), true);
  566. assoc.geometry.setTerminalPoint(new mxPoint(160, 0), false);
  567. assoc.edge = true;
  568. var sourceLabel = new mxCell('', new mxGeometry(0, 0, 20, 14), 'shape=message');
  569. sourceLabel.geometry.relative = true;
  570. sourceLabel.setConnectable(false);
  571. sourceLabel.vertex = true;
  572. sourceLabel.geometry.offset = new mxPoint(-10, -7);
  573. assoc.insert(sourceLabel);
  574. content.appendChild(this.createEdgeTemplateFromCells([assoc], 160, 0));
  575. var assoc = new mxCell('', new mxGeometry(0, 0, 0, 0), 'shape=link');
  576. assoc.geometry.setTerminalPoint(new mxPoint(0, 0), true);
  577. assoc.geometry.setTerminalPoint(new mxPoint(160, 0), false);
  578. assoc.edge = true;
  579. content.appendChild(this.createEdgeTemplateFromCells([assoc], 160, 0));
  580. }, 0.5);
  581. };
  582. /**
  583. * Creates and returns the given title element.
  584. */
  585. Sidebar.prototype.createTitle = function(label)
  586. {
  587. var elt = document.createElement('a');
  588. elt.setAttribute('href', 'javascript:void(0);');
  589. elt.className = 'geTitle';
  590. mxUtils.write(elt, label);
  591. return elt;
  592. };
  593. /**
  594. * Creates a thumbnail for the given cells.
  595. */
  596. Sidebar.prototype.createThumb = function(cells, width, height, parent)
  597. {
  598. // Workaround for off-screen text rendering in IE
  599. var old = mxText.prototype.getTableSize;
  600. if (this.graph.dialect != mxConstants.DIALECT_SVG)
  601. {
  602. mxText.prototype.getTableSize = function(table)
  603. {
  604. var oldParent = table.parentNode;
  605. document.body.appendChild(table);
  606. var size = new mxRectangle(0, 0, table.offsetWidth, table.offsetHeight);
  607. oldParent.appendChild(table);
  608. return size;
  609. };
  610. }
  611. var prev = mxImageShape.prototype.preserveImageAspect;
  612. mxImageShape.prototype.preserveImageAspect = false;
  613. this.graph.view.rendering = false;
  614. this.graph.view.setScale(1);
  615. this.graph.addCells(cells);
  616. var bounds = this.graph.getGraphBounds();
  617. var corr = (this.shiftThumbs) ? this.thumbBorder + 1 : this.thumbBorder;
  618. var s = Math.min((width - 1) / (bounds.x + bounds.width + corr),
  619. (height - 1) / (bounds.y + bounds.height + corr));
  620. this.graph.view.setScale(s);
  621. this.graph.view.rendering = true;
  622. this.graph.refresh();
  623. mxImageShape.prototype.preserveImageAspect = prev;
  624. bounds = this.graph.getGraphBounds();
  625. var dx = Math.max(0, Math.floor((width - bounds.width) / 2));
  626. var dy = Math.max(0, Math.floor((height - bounds.height) / 2));
  627. var node = null;
  628. // For supporting HTML labels in IE9 standards mode the container is cloned instead
  629. if (this.graph.dialect == mxConstants.DIALECT_SVG && !mxClient.IS_IE)
  630. {
  631. node = this.graph.view.getCanvas().ownerSVGElement.cloneNode(true);
  632. }
  633. // Workaround for VML rendering in IE8 standards mode
  634. else if (document.documentMode == 8)
  635. {
  636. node = this.graph.container.cloneNode(false);
  637. node.innerHTML = this.graph.container.innerHTML;
  638. }
  639. else
  640. {
  641. node = this.graph.container.cloneNode(true);
  642. }
  643. this.graph.getModel().clear();
  644. // Outer dimension is (32, 32)
  645. var dd = (this.shiftThumbs) ? 2 : 3;
  646. node.style.position = 'relative';
  647. node.style.overflow = 'visible';
  648. node.style.cursor = 'pointer';
  649. node.style.left = (dx + dd) + 'px';
  650. node.style.top = (dy + dd) + 'px';
  651. node.style.width = width + 'px';
  652. node.style.height = height + 'px';
  653. parent.appendChild(node);
  654. mxText.prototype.getTableSize = old;
  655. };
  656. /**
  657. * Creates and returns a new palette item for the given image.
  658. */
  659. Sidebar.prototype.createItem = function(cells)
  660. {
  661. var elt = document.createElement('a');
  662. elt.setAttribute('href', 'javascript:void(0);');
  663. elt.className = 'geItem';
  664. // Blocks default click action
  665. mxEvent.addListener(elt, 'click', function(evt)
  666. {
  667. mxEvent.consume(evt);
  668. });
  669. this.createThumb(cells, this.thumbWidth, this.thumbHeight, elt);
  670. return elt;
  671. };
  672. /**
  673. * Creates a drop handler for inserting the given cells.
  674. */
  675. Sidebar.prototype.createDropHandler = function(cells, allowSplit)
  676. {
  677. return function(graph, evt, target, x, y)
  678. {
  679. cells = graph.getImportableCells(cells);
  680. if (cells.length > 0)
  681. {
  682. var validDropTarget = (target != null) ?
  683. graph.isValidDropTarget(target, cells, evt) : false;
  684. var select = null;
  685. if (target != null && !validDropTarget)
  686. {
  687. target = null;
  688. }
  689. // Splits the target edge or inserts into target group
  690. if (allowSplit && graph.isSplitEnabled() && graph.isSplitTarget(target, cells, evt))
  691. {
  692. graph.splitEdge(target, cells, null, x, y);
  693. select = cells;
  694. }
  695. else if (cells.length > 0)
  696. {
  697. select = graph.importCells(cells, x, y, target);
  698. }
  699. if (select != null && select.length > 0)
  700. {
  701. graph.scrollCellToVisible(select[0]);
  702. graph.setSelectionCells(select);
  703. }
  704. }
  705. };
  706. };
  707. /**
  708. * Creates and returns a preview element for the given width and height.
  709. */
  710. Sidebar.prototype.createDragPreview = function(width, height)
  711. {
  712. var elt = document.createElement('div');
  713. elt.style.border = '1px dashed black';
  714. elt.style.width = width + 'px';
  715. elt.style.height = height + 'px';
  716. return elt;
  717. };
  718. /**
  719. * Creates a drag source for the given element.
  720. */
  721. Sidebar.prototype.createDragSource = function(elt, dropHandler, preview)
  722. {
  723. var dragSource = mxUtils.makeDraggable(elt, this.editorUi.editor.graph, dropHandler,
  724. preview, 0, 0, this.editorUi.editor.graph.autoscroll, true, true);
  725. // Allows drop into cell only if target is a valid root
  726. dragSource.getDropTarget = function(graph, x, y)
  727. {
  728. var target = mxDragSource.prototype.getDropTarget.apply(this, arguments);
  729. if (!graph.isValidRoot(target))
  730. {
  731. target = null;
  732. }
  733. return target;
  734. };
  735. return dragSource;
  736. };
  737. /**
  738. * Adds a handler for inserting the cell with a single click.
  739. */
  740. Sidebar.prototype.addClickHandler = function(elt, ds)
  741. {
  742. var graph = this.editorUi.editor.graph;
  743. var first = null;
  744. var md = (mxClient.IS_TOUCH) ? 'touchstart' : 'mousedown';
  745. mxEvent.addListener(elt, md, function(evt)
  746. {
  747. first = new mxPoint(mxEvent.getClientX(evt), mxEvent.getClientY(evt));
  748. });
  749. var oldMouseUp = ds.mouseUp;
  750. ds.mouseUp = function(evt)
  751. {
  752. if (!mxEvent.isPopupTrigger(evt) && this.currentGraph == null && first != null)
  753. {
  754. var tol = graph.tolerance;
  755. if (Math.abs(first.x - mxEvent.getClientX(evt)) <= tol &&
  756. Math.abs(first.y - mxEvent.getClientY(evt)) <= tol)
  757. {
  758. var gs = graph.getGridSize();
  759. ds.drop(graph, evt, null, gs, gs);
  760. }
  761. }
  762. oldMouseUp.apply(this, arguments);
  763. first = null;
  764. };
  765. };
  766. /**
  767. * Creates a drop handler for inserting the given cells.
  768. */
  769. Sidebar.prototype.createVertexTemplate = function(style, width, height, value)
  770. {
  771. var cells = [new mxCell((value != null) ? value : '', new mxGeometry(0, 0, width, height), style)];
  772. cells[0].vertex = true;
  773. return this.createVertexTemplateFromCells(cells, width, height);
  774. };
  775. /**
  776. * Creates a drop handler for inserting the given cells.
  777. */
  778. Sidebar.prototype.createVertexTemplateFromCells = function(cells, width, height)
  779. {
  780. var elt = this.createItem(cells);
  781. var ds = this.createDragSource(elt, this.createDropHandler(cells, true), this.createDragPreview(width, height));
  782. this.addClickHandler(elt, ds);
  783. // Uses guides for vertices only if enabled in graph
  784. ds.isGuidesEnabled = mxUtils.bind(this, function()
  785. {
  786. return this.editorUi.editor.graph.graphHandler.guidesEnabled;
  787. });
  788. // Shows a tooltip with the rendered cell
  789. if (!touchStyle)
  790. {
  791. mxEvent.addListener(elt, 'mousemove', mxUtils.bind(this, function(evt)
  792. {
  793. this.showTooltip(elt, cells);
  794. }));
  795. }
  796. return elt;
  797. };
  798. /**
  799. * Creates a drop handler for inserting the given cells.
  800. */
  801. Sidebar.prototype.createEdgeTemplate = function(style, width, height, value)
  802. {
  803. var cells = [new mxCell((value != null) ? value : '', new mxGeometry(0, 0, width, height), style)];
  804. cells[0].geometry.setTerminalPoint(new mxPoint(0, height), true);
  805. cells[0].geometry.setTerminalPoint(new mxPoint(width, 0), false);
  806. cells[0].edge = true;
  807. return this.createEdgeTemplateFromCells(cells, width, height);
  808. };
  809. /**
  810. * Creates a drop handler for inserting the given cells.
  811. */
  812. Sidebar.prototype.createEdgeTemplateFromCells = function(cells, width, height)
  813. {
  814. var elt = this.createItem(cells);
  815. this.createDragSource(elt, this.createDropHandler(cells, false), this.createDragPreview(width, height));
  816. // Installs the default edge
  817. var graph = this.editorUi.editor.graph;
  818. mxEvent.addListener(elt, 'click', mxUtils.bind(this, function(evt)
  819. {
  820. if (this.installEdges)
  821. {
  822. // Uses edge template for connect preview
  823. graph.connectionHandler.createEdgeState = function(me)
  824. {
  825. return graph.view.createState(cells[0]);
  826. };
  827. // Creates new connections from edge template
  828. graph.connectionHandler.factoryMethod = function()
  829. {
  830. return graph.cloneCells([cells[0]])[0];
  831. };
  832. }
  833. // Highlights the entry for 200ms
  834. elt.style.backgroundColor = '#ffffff';
  835. window.setTimeout(function()
  836. {
  837. elt.style.backgroundColor = '';
  838. }, 200);
  839. mxEvent.consume(evt);
  840. }));
  841. // Shows a tooltip with the rendered cell
  842. if (!touchStyle)
  843. {
  844. mxEvent.addListener(elt, 'mousemove', mxUtils.bind(this, function(evt)
  845. {
  846. this.showTooltip(elt, cells);
  847. }));
  848. }
  849. return elt;
  850. };
  851. /**
  852. * Adds the given palette.
  853. */
  854. Sidebar.prototype.addPalette = function(id, title, expanded, onInit)
  855. {
  856. var elt = this.createTitle(title);
  857. this.container.appendChild(elt);
  858. var div = document.createElement('div');
  859. div.className = 'geSidebar';
  860. if (expanded)
  861. {
  862. onInit(div);
  863. onInit = null;
  864. }
  865. else
  866. {
  867. div.style.display = 'none';
  868. }
  869. this.addFoldingHandler(elt, div, onInit);
  870. var outer = document.createElement('div');
  871. outer.appendChild(div);
  872. this.container.appendChild(outer);
  873. // Keeps references to the DOM nodes
  874. if (id != null)
  875. {
  876. this.palettes[id] = [elt, outer];
  877. }
  878. };
  879. /**
  880. * Create the given title element.
  881. */
  882. Sidebar.prototype.addFoldingHandler = function(title, content, funct)
  883. {
  884. var initialized = false;
  885. title.style.backgroundImage = (content.style.display == 'none') ?
  886. 'url(' + IMAGE_PATH + '/collapsed.gif)' : 'url(' + IMAGE_PATH + '/expanded.gif)';
  887. title.style.backgroundRepeat = 'no-repeat';
  888. title.style.backgroundPosition = '100% 50%';
  889. mxEvent.addListener(title, 'click', function(evt)
  890. {
  891. if (content.style.display == 'none')
  892. {
  893. if (!initialized)
  894. {
  895. initialized = true;
  896. if (funct != null)
  897. {
  898. funct(content);
  899. }
  900. }
  901. title.style.backgroundImage = 'url(' + IMAGE_PATH + '/expanded.gif)';
  902. content.style.display = 'block';
  903. }
  904. else
  905. {
  906. title.style.backgroundImage = 'url(' + IMAGE_PATH + '/collapsed.gif)';
  907. content.style.display = 'none';
  908. }
  909. mxEvent.consume(evt);
  910. });
  911. };
  912. /**
  913. * Removes the palette for the given ID.
  914. */
  915. Sidebar.prototype.removePalette = function(id)
  916. {
  917. var elts = this.palettes[id];
  918. if (elts != null)
  919. {
  920. this.palettes[id] = null;
  921. for (var i = 0; i < elts.length; i++)
  922. {
  923. this.container.removeChild(elts[i]);
  924. }
  925. return true;
  926. }
  927. return false;
  928. };
  929. /**
  930. * Adds the given image palette.
  931. */
  932. Sidebar.prototype.addImagePalette = function(id, title, prefix, postfix, items)
  933. {
  934. this.addPalette(id, title, true, mxUtils.bind(this, function(content)
  935. {
  936. for (var i = 0; i < items.length; i++)
  937. {
  938. var icon = prefix + items[i] + postfix;
  939. content.appendChild(this.createVertexTemplate('image;image=' + icon, 80, 80, ''));
  940. }
  941. }));
  942. };
  943. /**
  944. * Adds the given stencil palette.
  945. */
  946. Sidebar.prototype.addStencilPalette = function(id, title, stencilFile, style, ignore, onInit, scale)
  947. {
  948. scale = (scale != null) ? scale : 1;
  949. this.addPalette(id, title, false, mxUtils.bind(this, function(content)
  950. {
  951. if (style == null)
  952. {
  953. style = '';
  954. }
  955. if (onInit != null)
  956. {
  957. onInit.call(this, content);
  958. }
  959. mxStencilRegistry.loadStencilSet(stencilFile, mxUtils.bind(this, function(packageName, stencilName, displayName, w, h)
  960. {
  961. if (ignore == null || mxUtils.indexOf(ignore, stencilName) < 0)
  962. {
  963. content.appendChild(this.createVertexTemplate('shape=' + packageName + stencilName.toLowerCase() + style,
  964. Math.round(w * scale), Math.round(h * scale), ''));
  965. }
  966. }), true);
  967. }));
  968. };