home *** CD-ROM | disk | FTP | other *** search
/ PC World 1997 November / PCWorld_1997-11_cd.bin / software / programy / komix / DATA.Z / ctrlpnldia.tcl < prev    next >
Text File  |  1996-11-08  |  9KB  |  352 lines

  1. #---------------------------------------------------------------------------
  2. #
  3. #      (c)     Cayenne Software Inc.    1996
  4. #
  5. #      File:           @(#)ctrlpnldia.tcl    /main/hindenburg/4
  6. #      Author:         <generated>
  7. #      Description:
  8. #---------------------------------------------------------------------------
  9. # SccsId = @(#)ctrlpnldia.tcl    /main/hindenburg/4   8 Nov 1996 Copyright 1996 Cayenne Software Inc.
  10.  
  11. # Start user added include file section
  12. require "ctrlpnlvie.tcl"
  13. require "custfileut.tcl"
  14. # End user added include file section
  15.  
  16.  
  17. Class CtrlPnlDialog : {TemplateDialog} {
  18.     constructor
  19.     method destructor
  20.     method newableObjectList
  21.     method newObjects
  22.     method addObjects
  23.     method removeObjects
  24.     method showResult
  25.     method popUp
  26.     method quit
  27.     method save
  28.     method registerObject
  29.     method getSpec
  30.     method checkButtons
  31.     attribute cadEntries
  32.     attribute stdEntries
  33.     attribute dfdEntries
  34.     attribute etdEntries
  35.     attribute mgdEntries
  36.     attribute ccdEntries
  37.     attribute ucdEntries
  38.     attribute lvlObj
  39.     attribute fileName
  40.     attribute fileType
  41.     attribute editable
  42.     attribute number
  43.     attribute _view
  44. }
  45.  
  46. constructor CtrlPnlDialog {class this name} {
  47.     set this [TemplateDialog::constructor $class $this $name]
  48.     # Start constructor user section
  49.  
  50.     $this cadEntries {cad_class link_attr_box cad_container nary_assoc
  51.                       Vertex more_classes association aggregation 
  52.               qualif_assoc qualif_aggr nary_assoc_conn constraint
  53.                       generalization_conn overlap_gen_conn loop propagation
  54.                       Select}
  55.  
  56.     $this stdEntries {state super_state start_state final_state std_class
  57.                       Vertex transition event_msg Select}
  58.  
  59.     $this dfdEntries {data_proc data_store dfd_actor dfd_anchor Vertex
  60.               data_flow result_flow ctrl_flow update_flow Select}
  61.  
  62.     $this etdEntries {etd_initiator etd_object Vertex etd_event Select}
  63.  
  64.     $this mgdEntries {message_def Vertex message_gen_conn Select}
  65.  
  66.     $this ccdEntries {ccd_class ccd_class_ref ccd_container ccd_actor
  67.                       subject Vertex com_message Select}
  68.  
  69.     $this ucdEntries {use_case ucd_actor Vertex
  70.               und_com_assoc dir_com_assoc use_case_gen Select}
  71.  
  72.     ClassMaker::extend BrowsObject CtrlPnlObj {index id}
  73.  
  74.     global classCount
  75.     incr classCount
  76.     $this number $classCount
  77.  
  78.     $this config \
  79.         -cancelPressed { %this quit } \
  80.         -okPressed { %this save } \
  81.         -helpPressed {.main helpOnName ctrlPnlDialog }
  82.  
  83.     interface DlgColumn $this.top {
  84.         DlgRow menu {
  85.                 verStretchFactor 0
  86.                 verShrinkFactor 0
  87.         horStretchFactor 0
  88.         verStretchFactor 0
  89.         PushButton new {
  90.             label New...
  91.         }
  92.         PushButton test {
  93.             label Test...
  94.         }
  95.         PushButton delete {
  96.             label Delete
  97.         }
  98.         }
  99.         Label contentsLab {
  100.         text "Contents:"
  101.         alignment CENTER
  102.         }
  103.         CtrlPnlView view {
  104.         rowCount 10
  105.         mode DETAIL
  106.         BrowsHeader header0 {
  107.             label Name
  108.             width 20
  109.         }
  110.         }
  111.         HorRadioGroup colCountHRG {
  112.             entrySet {"one column" "two columns" "three columns"}
  113.                     justification CENTER
  114.         }
  115.     }
  116.  
  117.     $this.top.menu.new activated [list $this newObjects]
  118.     $this.top.menu.test activated [list $this showResult]
  119.     $this.top.menu.delete activated [list $this removeObjects]
  120.  
  121.     $this _view $this.top.view
  122.     $this modal Yes
  123.  
  124.     $this.top.view selectionChanged "$this checkButtons"
  125.  
  126.     # End constructor user section
  127.     return $this
  128. }
  129.  
  130. method CtrlPnlDialog::destructor {this} {
  131.     # Start destructor user section
  132.     # End destructor user section
  133. }
  134.  
  135. method CtrlPnlDialog::newableObjectList {this} {
  136.  
  137.     set allEntries [$this [$this fileName]Entries]
  138.     set newEntries $allEntries
  139.  
  140.     foreach obj [[$this _view] objectSet] {
  141.         set name [$obj label]
  142.         set idx [lsearch -exact $newEntries $name]
  143.         if {$idx != -1} {
  144.             # does already exist so it can not be newed
  145.             set newEntries [lreplace $newEntries $idx $idx]
  146.         }
  147.     }
  148.     return $newEntries
  149. }
  150.  
  151. method CtrlPnlDialog::newObjects {this} {
  152.  
  153.     set newEntries [$this newableObjectList]
  154.  
  155.     set box .main.panelListDialog[$this number]
  156.     if {! [isCommand $box]} {
  157.         ListDialog new $box \
  158.             -modal Yes \
  159.             -title "New Panel Entry" \
  160.             -selectionPolicy EXTENDED \
  161.             -rowCount 12 \
  162.             -okPressed "$this addObjects \[%this selectedSet\]"
  163.     }
  164.     $box entrySet $newEntries
  165.     $box popUp
  166. }
  167.  
  168. method CtrlPnlDialog::addObjects {this names} {
  169.  
  170.     foreach name $names {
  171.         set object [$this _view].object$name
  172.             CtrlPnlObj new $object \
  173.             -smallIcon $name \
  174.             -largeIcon $name \
  175.             -label $name \
  176.             -selectState 0 \
  177.             -id $object
  178.         if [$this editable] {
  179.             $object conversionSet "CONTROLPANELENTRY id"
  180.         }
  181.     }    
  182.     [$this _view] reIndex
  183.     $this checkButtons
  184. }
  185.  
  186. method CtrlPnlDialog::removeObjects {this} {
  187.  
  188.     foreach obj [[$this _view] selectedSet] {
  189.         $obj delete
  190.     }
  191.     [$this _view] reIndex
  192.     $this checkButtons
  193. }
  194.  
  195. method CtrlPnlDialog::showResult {this} {
  196.  
  197.     if [isCommand .main.showPanel[$this number]] {
  198.         .main.showPanel[$this number] popDown
  199.         .main.showPanel[$this number] delete 
  200.     }
  201.  
  202.     interface TemplateDialog .main.showPanel[$this number] {
  203.         modal Yes
  204.         DlgColumn DC {
  205.             VerControlPanel VCP {
  206.             }
  207.         }
  208.     }
  209.     .main.showPanel[$this number] delHelpButton
  210.     .main.showPanel[$this number] delCancelButton
  211.  
  212.     set spec [$this getSpec]
  213.     .main.showPanel[$this number].DC.VCP config \
  214.         -entrySet [lindex $spec 0] \
  215.         -columnCount [lindex $spec 1]
  216.     .main.showPanel[$this number] config \
  217.         -title [$this title] \
  218.         -okPressed {%this delete}
  219.     .main.showPanel[$this number] popUp
  220. }
  221.  
  222. method CtrlPnlDialog::popUp {this} {
  223.     eval "proc registerObject {spec} {$this registerObject \$spec}"
  224.     CustFileUtilities::read [$this lvlObj] [$this fileName] [$this fileType]
  225.  
  226.     $this title "'[string toupper [$this fileName]]' Control Panel"
  227.     $this TemplateDialog::popUp
  228.  
  229.     $this.top.menu.new sensitive [$this editable]
  230.     $this.top.menu.delete sensitive [$this editable]
  231.     $this.top.colCountHRG sensitive [$this editable]
  232.  
  233.     if {"[$this lvlObj]" == ""} return
  234.     if [[$this lvlObj] isA Corporate] return
  235.  
  236.     set custFV [[$this lvlObj] findCustomFileVersion \
  237.         [$this fileName] [$this fileType]]
  238.     if [$custFV isNil] return
  239.  
  240.     if [$this editable] {
  241.         if [catch {$custFV edit} msg] {
  242.             wmtkerror $msg
  243.             $this.top.menu.new sensitive 0
  244.             $this.top.menu.delete sensitive 0
  245.             $this.top.colCountHRG sensitive 0
  246.         }
  247.     }
  248.  
  249.     $this checkButtons
  250. }
  251.  
  252. method CtrlPnlDialog::quit {this} {
  253.  
  254.     if {"[$this lvlObj]" == ""} return
  255.     if [[$this lvlObj] isA Corporate] return
  256.  
  257.     set custFV [[$this lvlObj] findCustomFileVersion \
  258.         [$this fileName] [$this fileType]]
  259.     if [$custFV isNil] return
  260.  
  261.     if [$this editable] {
  262.         $custFV quit
  263.     }
  264. }
  265.  
  266. method CtrlPnlDialog::save {this} {
  267.  
  268.     if {![$this editable]} {
  269.         return
  270.     }
  271.  
  272.     set tmpFile [args_file {}]
  273.     set fid [open $tmpFile w]
  274.  
  275.     set spec [$this getSpec]
  276.     set objSpec "entrySet \"[lindex $spec 0]\""
  277.     set objSpec "$objSpec columnCount \"[lindex $spec 1]\""
  278.     puts $fid "registerObject \{$objSpec\}"
  279.     close $fid
  280.     CustFileUtilities::save $tmpFile \
  281.         [$this lvlObj] [$this fileName] [$this fileType]
  282.     unlink $tmpFile
  283.  
  284.     $this quit
  285. }
  286.  
  287. method CtrlPnlDialog::registerObject {this objSpec} {
  288.  
  289.     while {![lempty $objSpec]} {
  290.         set key [lvarpop objSpec]
  291.         set value [lvarpop objSpec]
  292.  
  293.         if {$key == "entrySet"} {
  294.             $this addObjects $value
  295.         }
  296.  
  297.         if {$key == "columnCount"} {
  298.             if {$value == 1} {
  299.                 $this.top.colCountHRG selected "one column"
  300.             } elseif {$value == 2} {
  301.                 $this.top.colCountHRG selected "two columns"
  302.             } elseif {$value == 3} {
  303.                 $this.top.colCountHRG selected "three columns"
  304.             }
  305.         }
  306.     }
  307. }
  308.  
  309. method CtrlPnlDialog::getSpec {this} {
  310.     
  311.     set entrySet {}
  312.     set columnCount 1
  313.  
  314.     foreach obj [[$this _view] objectSet] {
  315.         set entrySet "$entrySet [$obj label]"
  316.     }
  317.  
  318.     
  319.     set selected [$this.top.colCountHRG selected]
  320.     if {$selected == "two columns"} {
  321.         set columnCount 2 
  322.     } elseif {$selected == "three columns"} {
  323.         set columnCount 3 
  324.     }
  325.  
  326.     return [list $entrySet $columnCount]
  327. }
  328.  
  329. method CtrlPnlDialog::checkButtons {this} {
  330.  
  331.     if ![$this editable] {
  332.         # disabled stays disabled
  333.         return
  334.     }
  335.  
  336.     if [lempty [[$this _view] selectedSet]] {
  337.         $this.top.menu.delete sensitive 0
  338.     } else {
  339.         $this.top.menu.delete sensitive 1
  340.     }
  341.  
  342.     
  343.     if [lempty [$this newableObjectList]] {
  344.         $this.top.menu.new sensitive 0
  345.     } else {
  346.         $this.top.menu.new sensitive 1
  347.     }
  348. }
  349.  
  350. # Do not delete this line -- regeneration end marker
  351.  
  352.