behavioursc_dialog.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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); // HUSEYIN-ENTER
  29. //WindowManagement.closeDialog();
  30. }
  31. },
  32. '__exitActions':{},
  33. /* transition to specified state */
  34. '__T' :
  35. function(s,event)
  36. {
  37. if( this.__currentState in this.__exitActions )
  38. this.__exitActions[this.__currentState](event);
  39. this.__currentState = s;
  40. if( s in this.__entryActions )
  41. this.__entryActions[s](event);
  42. },
  43. /* initialise the statechart */
  44. 'init':
  45. function()
  46. {
  47. this.__currentState = this.__STATE_CLOSED;
  48. },
  49. /* handle an event... only discarded events are allowed to propagate to parent
  50. HTML element
  51. name: internal name of the event
  52. event: the javascript event */
  53. 'handleUserEvent':
  54. function(name,event)
  55. {
  56. if( this.__currentState == this.__STATE_OPEN )
  57. {
  58. if( name == __EVENT_KEYUP_ESC ||
  59. name == __EVENT_CANCELED_DIALOG ||
  60. name == __EVENT_KEYUP_ENTER || // HUSEYIN-ENTER
  61. name == __EVENT_OKAYED_DIALOG )
  62. this.__T(this.__STATE_CLOSED,event);
  63. else
  64. return;
  65. if( event && event.stopPropagation )
  66. {
  67. event.stopPropagation();
  68. event.preventDefault();
  69. }
  70. }
  71. else if( this.__currentState == this.__STATE_CLOSED )
  72. {
  73. if( name == __EVENT_SHOW_DIALOG )
  74. this.__T(this.__STATE_OPEN,event);
  75. else
  76. return;
  77. if( event && event.stopPropagation )
  78. {
  79. event.stopPropagation();
  80. event.preventDefault();
  81. }
  82. }
  83. }
  84. }