behavioursc_dialog.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /*******************************************************************************
  2. AToMPM - A Tool for Multi-Paradigm Modelling
  3. Copyright (c) 2011 Raphael Mannadiar (raphael.mannadiar@mail.mcgill.ca)
  4. This file is part of AToMPM.
  5. AToMPM is free software: you can redistribute it and/or modify it under the
  6. terms of the GNU Lesser General Public License as published by the Free Software
  7. Foundation, either version 3 of the License, or (at your option) any later
  8. version.
  9. AToMPM is distributed in the hope that it will be useful, but WITHOUT ANY
  10. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
  11. PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public License along
  13. with AToMPM. If not, see <http://www.gnu.org/licenses/>.
  14. *******************************************************************************/
  15. __dialogBehaviourStatechart = {
  16. '__STATE_OPEN' : 0,
  17. '__STATE_CLOSED': 1,
  18. '__currentState': undefined,
  19. '__entryActions':{
  20. 0:
  21. function(event)
  22. {
  23. WindowManagement.showDialog();
  24. },
  25. 1:
  26. function(event)
  27. {
  28. WindowManagement.closeDialog(event);
  29. }
  30. },
  31. '__exitActions':{},
  32. /* transition to specified state */
  33. '__T' :
  34. function(s,event)
  35. {
  36. if( this.__currentState in this.__exitActions )
  37. this.__exitActions[this.__currentState](event);
  38. this.__currentState = s;
  39. if( s in this.__entryActions )
  40. this.__entryActions[s](event);
  41. },
  42. /* initialise the statechart */
  43. 'init':
  44. function()
  45. {
  46. this.__currentState = this.__STATE_CLOSED;
  47. },
  48. /* handle an event... only discarded events are allowed to propagate to parent
  49. HTML element
  50. name: internal name of the event
  51. event: the javascript event */
  52. 'handleUserEvent':
  53. function(name,event)
  54. {
  55. if( this.__currentState == this.__STATE_OPEN )
  56. {
  57. if( name == __EVENT_KEYUP_ESC ||
  58. name == __EVENT_CANCELED_DIALOG ||
  59. name == __EVENT_KEYUP_ENTER ||
  60. name == __EVENT_OKAYED_DIALOG )
  61. // let's not look at this ever again
  62. if (__dialog_stack.length == 1)
  63. this.__T(this.__STATE_CLOSED,event);
  64. else
  65. WindowManagement.closeDialog();
  66. else if( name == __EVENT_SHOW_DIALOG )
  67. this.__T(this.__STATE_OPEN,event);
  68. else
  69. return;
  70. if( event && event.stopPropagation )
  71. {
  72. event.stopPropagation();
  73. event.preventDefault();
  74. }
  75. }
  76. else if( this.__currentState == this.__STATE_CLOSED )
  77. {
  78. if( name == __EVENT_SHOW_DIALOG )
  79. this.__T(this.__STATE_OPEN,event);
  80. else
  81. return;
  82. if( event && event.stopPropagation )
  83. {
  84. event.stopPropagation();
  85. event.preventDefault();
  86. }
  87. }
  88. }
  89. }