# $Revision$ on $Date$
# The above revision line needs to be the first line for all techtk files
# Copyright (c) 2006 Ansys Inc
#----------------------------------------------------------------------------
#
# PADT---------------------------------------------------- Phoenix Analysis &
#                                                         Design Technologies
#
#----------------------------------------------------------------------------
#
#       Package: AI-Environment GUI Management
#
#
#          File: parser.tcl
#
#
#     Developer: Matt Sutton
#
#
#   Description: This file contains the implementation of the ColumnMultiSelect
#                widget
#   
#
#      09/01/02: Demo release 1. Limited/partial widget support. 
#                Limited error checking.
#
#           
#
#-----------------------------------------------------------------------------
# For support: 1-480-813-4884 ext. 125 -or- matt.sutton@padtinc.com
#-----------------------------------------------------------------------------

namespace eval ::AIEnv::GUIManagement {}

namespace eval ::AIEnv::GUIManagement::ColumnMultiSelect {
	variable Commands
	variable Options
	variable Data
	variable UnderlineFont
	variable NormalFont

	
	set Commands {
		clear
		create
		set
		get
		build
		query
		grey
		ungrey
		select
		unselect
		widgetgrey
		widgetungrey
	}
	
	set Options {
		title
		parent
		nodeID
		dirtyFlag
		rowCol
	}
	
#	if { ![winfo exists .fobarlabel26] } {
#		set lab [label .fobarlabel26]
#		set NormalFont [$lab cget -font]
#		set UnderlineFont [CreateUnderlineFont $NormalFont]
#	}

}
	
	
proc ::AIEnv::GUIManagement::ColumnMultiSelect::RouterProc {Name Cmd args} {
	if {[catch {eval [list RouterProcImpl $Name $Cmd] $args} result] != 0} {
		::AIEnv::GUIManagement::RuntimeError $result
	} else {
		return $result
	}
}

proc ::AIEnv::GUIManagement::ColumnMultiSelect::RouterProcImpl {Name Cmd args} {
	# Check the command to see if it is valid
	variable Commands
	
	if { [lsearch $Commands $Cmd] != -1 } {
		return [eval [list ::AIEnv::GUIManagement::ColumnMultiSelect::_$Cmd $Name] $args]
	} else {
		set Optlist [join $Commands ", "]
		set Optlist [linsert $Optlist "end-1" "or"]
		error "Unknown command: \"$Cmd\" given to the ColumnMultiSelect widget named: \"$Name\".  Valid commands are: \"$Optlist\"."
	}
}


proc ::AIEnv::GUIManagement::ColumnMultiSelect::_set {Name args} {
	if {[catch {eval [list SetImpl $Name] $args} result] != 0} {
		::AIEnv::GUIManagement::RuntimeError $result
	} else {
		return $result
	}
}

proc ::AIEnv::GUIManagement::ColumnMultiSelect::SetImpl {Name args} {
	variable Options
	variable Data
	variable SelectionTypes
	if { [llength $args] >= 3 } {
		set Flag [lindex $args 0]
		set Key [lindex $args 1]
		set Value [lindex $args 2]
		if { $Flag == "-key" } {
			if { [lsearch $Options $Key] != -1 } {
				if { $Key == "type" } {
					set Value [string tolower $Value]
					if { [lsearch $SelectionTypes $Value] == -1 } {
						set Optlist [join $SelectionTypes ", "]
						set Optlist [linsert $Optlist "end-1" "or"]
						error "Invalid selection type: \"$Value\" given for multi-selector: \"$Name\"\n. Valid selection types are: $Optlist."
					}
				} elseif { $Key == "rowCol" } {
					if { [llength $args] == 4 } {
						set RowValue [lindex $args 2]
						set ColValue [lindex $args 3]
						if { [info exists Data($Name,ColumnList)] } {
							if { [lsearch $Data($Name,ColumnList) $ColValue] == -1 } {
								lappend Data($Name,ColumnList) $ColValue
							}
						} else {
							lappend Data($Name,ColumnList) $ColValue
						}
						# Just add the row value by default.  The array item will be created 
						# if needed.
						lappend Data($Name,rowCol,$ColValue) $RowValue
					} else {
						error "Not enough parameters specified for the RowCol key."
					}
					
				} else {
					set Data($Name,$Key) $Value
				}
			} else {
				set Optlist [join $Options ", "]
				set Optlist [linsert $Optlist "end-1" "or"]
				error "Invalid option: \"$Key\" for multi-selector: \"$Name\". Valid options are $Optlist."
			}
		} else {
			error "Invalid flag: \"$Flag\" for multi-selector: \"$Name\". Must be -key"
		}
	} else {
		error "Wrong number of arguments: Should be \"$Name set -key key value\""
	}	
}


proc ::AIEnv::GUIManagement::ColumnMultiSelect::_get {Name args} {
	if {[catch {eval [list GetImpl $Name] $args} result] != 0} {
		::AIEnv::GUIManagement::RuntimeError $result
	} else {
		return $result
	}
}

proc ::AIEnv::GUIManagement::ColumnMultiSelect::GetImpl {Name args} {
	variable Options
	variable MultiSelectData
	if { [llength $args] == 2 } {
		set Flag [lindex $args 0]
		set Key [lindex $args 1]
		if { $Flag == "-key" } {
			if { [lsearch $Options $Key] != -1 } {
				if { $Key == "rowCol" } {
					
				} else {
					return $MultiSelectData($Name,$Key)
				}
			} else {
				set Optlist [join $Options ", "]
				set Optlist [linsert $Optlist "end-1" "or"]
				error "Invalid option: \"$Key\" for multi-selector: \"$Name\". Valid options are $Optlist."
			}
		} else {
			error "Invalid flag: \"$Flag\" for multi-selector: \"$Name\". Must be -key"
		}
	} else {
		error "Wrong number of arguments: Should be \"$Name get -key key\""
	}	
}

proc ::AIEnv::GUIManagement::ColumnMultiSelect::_create {Name args} {
	if {[catch {eval [list CreateImpl $Name] $args} result] != 0} {
		::AIEnv::GUIManagement::RuntimeError $result
	} else {
		return $result
	}	
}

proc ::AIEnv::GUIManagement::ColumnMultiSelect::CreateImpl {Name args} {
	variable Data
	set Data($Name,BuiltOnce) 0
}

proc ::AIEnv::GUIManagement::ColumnMultiSelect::_clear {Name args} {
	if {[catch {eval [list ClearImpl $Name] $args} result] != 0} {
		::AIEnv::GUIManagement::RuntimeError $result
	} else {
		return $result
	}		
}

proc ::AIEnv::GUIManagement::ColumnMultiSelect::ClearImpl {Name args} {
	variable Data
	
	# Destroy the widgets
	
	if { [info exists Data($Name,InnerFrame)] } {
		destroy $Data($Name,InnerFrame)
	}
	# Destroy all of the check buttons
#	set Indices [array names Data $Name,CheckButtons,*]
#	foreach i $Indices {
#		destroy $Data($i) 
#		unset Data($i)
#	}
	
	# Destroy all of the labels
#	set Indices [array names Data $Name,Labels,*]
#	foreach i $Indices {
#		destroy $Data($i) 
#		unset Data($i)
#	}
	
	# Unset all of the variables bound to the check buttons
	set Indices [array names Data $Name,SelectData,*]
	foreach i $Indices {
		if { [info exists Data($i)] } {
			trace vdelete Data($i) "w" \
			"::AIEnv::GUIManagement::ColumnMultiSelect::VariableTrace $Name"
			unset Data($i)
		}
	}
	
	# Unset the label data
	set Indices [array names Data $Name,rowCol,*]
	foreach i $Indices {
		if { [info exists Data($i)] } {
			unset Data($i)
		}
	}
	if { [info exists Data($Name,ColumnList)] } {
		unset Data($Name,ColumnList)
	}
	
}

proc ::AIEnv::GUIManagement::ColumnMultiSelect::_build {Name args} {
	if {[catch {eval [list BuildImpl $Name] $args} result] != 0} {
		::AIEnv::GUIManagement::RuntimeError $result
	} else {
		return $result
	}
	
}

proc ::AIEnv::GUIManagement::ColumnMultiSelect::BuildImpl {Name args} {
	variable Data
	variable UnderlineFont
	variable NormalFont
        variable ::AIEnv::GUIManagement::GUIDisplayData

        set NormalFont $::AIEnv::GUIManagement::GUIDisplayData("MultiSelectFont")
        set UnderlineFont [CreateUnderlineFont $NormalFont]
	
	if { [GetParentType $Name] == "DEZ" } {
		set Columns $Data($Name,ColumnList)
		set NumCols [llength $Columns]
		set MaxNumRows 0
		foreach Col $Columns {
			set Tmp [llength $Data($Name,rowCol,$Col)]
			if { $Tmp > $MaxNumRows } {
				set MaxNumRows $Tmp
			}
		}
		set Data($Name,MaxNumRows) $MaxNumRows
		set ColSpan 3
		if { $Data($Name,BuiltOnce) == 0 } {
			
			set RowParent [::AIEnv::GUIManagement::DEZInsert 1 1.1]
			set TopRow [lindex $RowParent 0]
			set ParentPath [lindex $RowParent 1]
			set Data($Name,DEZRow) $TopRow
			set Data($Name,ParentPath) $ParentPath
			set Data($Name,BuiltOnce) 1
		}
	} else {
		# Somehow RowParent must be set up...
		error "Currently this widget doesn't support placement in any location other than a DEZ."
	}
	
	set Title [GetTitle $Name]
	set NodeID [GetNodeID $Name]
	
	if { [info exists Data($Name,MainFrame)] } {
		set fFrame [$Data($Name,MainFrame) getframe]
		set InnerFrame [frame $fFrame.f]
		set Data($Name,InnerFrame) $InnerFrame
		pack $InnerFrame -fill both -expand yes
	} else {
		set OuterFrame [TitleFrame $Data($Name,ParentPath).$NodeID-tf -text $Title -side left \
				-font $::AIEnv::GUIManagement::GUIDisplayData("DEZTitleFont")]
		set fFrame [$OuterFrame getframe]
		set InnerFrame [frame $fFrame.f]
		pack $InnerFrame -fill both -expand yes
		set Data($Name,InnerFrame) $InnerFrame
		set Data($Name,MainFrame) $OuterFrame
	}
	
	# Iterate over columns and then rows within a column
	set RowIndex 0
	set ColIndex 0
	
	set SeparatorRowSpan [expr $MaxNumRows + 3]
	foreach ColLabel $Columns {
		set Rows $Data($Name,rowCol,$ColLabel)
		set lab [label $InnerFrame.lc${ColIndex} -text $ColLabel \
			 -wraplength $::AIEnv::GUIManagement::GUIDisplayData("ColumnMultiSelectWrapLength") \
			 -font $NormalFont] 
		grid $lab -row $RowIndex -column $ColIndex
	        $lab configure -relief raised -borderwidth 2
		bind $lab <Enter> {
			::AIEnv::GUIManagement::ColumnMultiSelect::HighlightLabel %W 1
		}
		bind $lab <Leave> {
			::AIEnv::GUIManagement::ColumnMultiSelect::HighlightLabel %W 0
		}
		bind $lab <ButtonPress-1> "::AIEnv::GUIManagement::ColumnMultiSelect::SelectColumn $lab $Name \{$ColLabel\}"
		
		incr RowIndex
		set Data($Name,Labels,$ColLabel) $lab
		set Sep [Separator $InnerFrame.seph${ColIndex} -orient horizontal]
		grid $Sep -row $RowIndex -column $ColIndex -sticky ew -pady 1
		
		incr RowIndex
		foreach RowLabel $Rows {
			set CkBox [checkbutton $InnerFrame.ckbtn${RowIndex}-${ColIndex} -text $RowLabel \
				   -wraplength $::AIEnv::GUIManagement::GUIDisplayData("ColumnMultiSelectWrapLength") \
			           -variable ::AIEnv::GUIManagement::ColumnMultiSelect::Data($Name,SelectData,$RowLabel,$ColLabel) \
				   -font $::AIEnv::GUIManagement::GUIDisplayData("CheckButtonFont") \
			           -onvalue 1 -offvalue 0 -justify left]
			grid $CkBox -row $RowIndex -column $ColIndex -sticky w
			set Data($Name,CheckButtons,$RowLabel,$ColLabel) $CkBox
			incr RowIndex
			# Setup the trace
			trace variable Data($Name,SelectData,$RowLabel,$ColLabel) "w" \
			   "::AIEnv::GUIManagement::ColumnMultiSelect::VariableTrace $Name"
		}
		incr ColIndex
		set Sep [Separator $InnerFrame.sep${ColIndex} -orient vertical]
		grid $Sep -row 0 -column $ColIndex -rowspan $SeparatorRowSpan -sticky ns -padx 3
		incr ColIndex
		set RowIndex 0
	}
	
	# Forget the last separator
	grid forget $Sep
	grid $Data($Name,MainFrame) -row $Data($Name,DEZRow) -column 0 -columnspan 3 -sticky nw -pady 3
}


proc ::AIEnv::GUIManagement::ColumnMultiSelect::VariableTrace {Name VarName Index Op} {
	set Parent [GetParent $Name]
	$Parent setdirty
}

proc ::AIEnv::GUIManagement::ColumnMultiSelect::CreateUnderlineFont {TemplateFont} {
	set fam [font actual $TemplateFont -family]
	set size [font actual $TemplateFont -size]
	set weight [font actual $TemplateFont -weight]
	
	set fnew [font create -family $fam -weight $weight -size $size -underline true]
	return $fnew	
}

proc ::AIEnv::GUIManagement::ColumnMultiSelect::HighlightLabel {Win Highlight} {
	variable UnderlineFont
	variable NormalFont
	
	set status [$Win cget -state]
	if { $status == "disabled" } {
		return
	}
		
	if { $Highlight } {
		$Win configure -font $UnderlineFont -foreground blue
	} else {
		$Win configure -font $NormalFont -foreground black
	}
}

proc ::AIEnv::GUIManagement::ColumnMultiSelect::SelectColumn {Win Name ColLabel} {
	variable Data
	
	set Rows $Data($Name,rowCol,$ColLabel)
	# Check to see if all are selected
	set AllSelected 1
	foreach Row $Rows {
		if { [$Data($Name,CheckButtons,$Row,$ColLabel) cget -state] == "normal" } {
			if { $Data($Name,SelectData,$Row,$ColLabel) == 0 } {
				set AllSelected 0
				break
			}
		}
		#set Data($Name,SelectData,$Row,$ColLabel) 1
	}
	if { $AllSelected == 1 } {
		UnSelectImpl $Name $ColLabel
	} else {
		SelectImpl $Name $ColLabel
	}
}

proc ::AIEnv::GUIManagement::ColumnMultiSelect::_unselect {Name args} {
	if {[catch {eval [list UnSelectImpl $Name] $args} result] != 0} {
		::AIEnv::GUIManagement::RuntimeError $result
	} else {
		return $result
	}	
}

proc ::AIEnv::GUIManagement::ColumnMultiSelect::_select {Name args} {
	if {[catch {eval [list SelectImpl $Name] $args} result] != 0} {
		::AIEnv::GUIManagement::RuntimeError $result
	} else {
		return $result
	}	
}

proc ::AIEnv::GUIManagement::ColumnMultiSelect::UnSelectImpl {Name args} {
	variable Data
	
	switch [llength $args] {
		
		0 {
			# Unselect everything
			if { [info exists Data($Name,ColumnList)] } {
				set Columns $Data($Name,ColumnList)
				foreach Col $Columns {
					if { [info exists Data($Name,rowCol,$Col)] } {
						set Rows $Data($Name,rowCol,$Col)
						foreach Row $Rows { 
							if { [info exists Data($Name,SelectData,$Row,$Col)] } {
								if { [info exists Data($Name,CheckButtons,$Row,$Col)] } {
									if { [winfo exists $Data($Name,CheckButtons,$Row,$Col)] } {
										if { [$Data($Name,CheckButtons,$Row,$Col) cget -state] == "normal" } {
											set Data($Name,SelectData,$Row,$Col) 0
										}
									}
								}
							}
						}
					}
				}
			}
		}
		
		1 {
			# Unselect a particular column
			set Col [lindex $args 0]
			if { [info exists Data($Name,rowCol,$Col)] } {
				set Rows $Data($Name,rowCol,$Col)
				foreach Row $Rows {
					if { [info exists Data($Name,SelectData,$Row,$Col)] } {
						if { [info exists Data($Name,CheckButtons,$Row,$Col)] } {
							if { [winfo exists $Data($Name,CheckButtons,$Row,$Col)] } {
								if { [$Data($Name,CheckButtons,$Row,$Col) cget -state] == "normal" } {
									set Data($Name,SelectData,$Row,$Col) 0
								}
							}
						}
					}					
				}
			}
		}
		
		2 {
			# Unselect a particular item
			set Row [lindex $args 0]
			set Col [lindex $args 1]
			if { [info exists Data($Name,SelectData,$Row,$Col)] } {
				if { [info exists Data($Name,CheckButtons,$Row,$Col)] } {
					if { [winfo exists $Data($Name,CheckButtons,$Row,$Col)] } {
						if { [$Data($Name,CheckButtons,$Row,$Col) cget -state] == "normal" } {
							set Data($Name,SelectData,$Row,$Col) 0
						}
					}
				}
			}			
		}
	}
}

proc ::AIEnv::GUIManagement::ColumnMultiSelect::SelectImpl {Name args} {
	variable Data
	
	switch [llength $args] {
		
		0 {
			# Unselect everything
			if { [info exists Data($Name,ColumnList)] } {
				set Columns $Data($Name,ColumnList)
				foreach Col $Columns {
					if { [info exists Data($Name,rowCol,$Col)] } {
						set Rows $Data($Name,rowCol,$Col)
						foreach Row $Rows { 
							if { [info exists Data($Name,SelectData,$Row,$Col)] } {
								if { [info exists Data($Name,CheckButtons,$Row,$Col)] } {
									if { [winfo exists $Data($Name,CheckButtons,$Row,$Col)] } {
										if { [$Data($Name,CheckButtons,$Row,$Col) cget -state] == "normal" } {
											set Data($Name,SelectData,$Row,$Col) 1
										}
									}
								}
							}
						}
					}
				}
			}
		}
		
		1 {
			# Unselect a particular column
			set Col [lindex $args 0]
			if { [info exists Data($Name,rowCol,$Col)] } {
				set Rows $Data($Name,rowCol,$Col)
				foreach Row $Rows {
					if { [info exists Data($Name,SelectData,$Row,$Col)] } {
						if { [info exists Data($Name,CheckButtons,$Row,$Col)] } {
							if { [winfo exists $Data($Name,CheckButtons,$Row,$Col)] } {
								if { [$Data($Name,CheckButtons,$Row,$Col) cget -state] == "normal" } {
									set Data($Name,SelectData,$Row,$Col) 1
								}
							}
						}
					}					
				}
			}
		}
		
		2 {
			# Unselect a particular item
			set Row [lindex $args 0]
			set Col [lindex $args 1]
			if { [info exists Data($Name,SelectData,$Row,$Col)] } {
				if { [info exists Data($Name,CheckButtons,$Row,$Col)] } {
					if { [winfo exists $Data($Name,CheckButtons,$Row,$Col)] } {
						if { [$Data($Name,CheckButtons,$Row,$Col) cget -state] == "normal" } {
							set Data($Name,SelectData,$Row,$Col) 1
						}
					}
				}
			}			
		}
	}
}


proc ::AIEnv::GUIManagement::ColumnMultiSelect::_query {Name args} {
	if {[catch {eval [list QueryImpl $Name] $args} result] != 0} {
		::AIEnv::GUIManagement::RuntimeError $result
	} else {
		return $result
	}	
}

proc ::AIEnv::GUIManagement::ColumnMultiSelect::QueryImpl {Name args} {
	variable Data
	
	if { [llength $args] != 2 } {
		error "Wrong number of arguments passed to \"$Name query\""
	}
	
	set Row [lindex $args 0]
	set Col [lindex $args 1]
	
	if {[info exists Data($Name,SelectData,$Row,$Col)]} {
		return $Data($Name,SelectData,$Row,$Col)
	} else {
		# Can't find variable
		return -1
	}
}

proc ::AIEnv::GUIManagement::ColumnMultiSelect::_grey {Name args} {
	if {[catch {eval [list GreyImpl $Name] $args} result] != 0} {
		::AIEnv::GUIManagement::RuntimeError $result
	} else {
		return $result
	}		
}

proc ::AIEnv::GUIManagement::ColumnMultiSelect::GreyImpl {Name args} {
	variable Data
	
	switch [llength $args] {
		0 {
			# Grey everything
			_widgetgrey $Name
		}
		
		1 {
			# Grey out a column
			set Col [lindex $args 0]
			if { [info exists Data($Name,ColumnList)] } {
				if { [lsearch $Data($Name,ColumnList) $Col] != -1 } {
					# Grey out the label
					if { [info exists Data($Name,Labels,$Col)] } {
						if { [winfo exists $Data($Name,Labels,$Col)] } {
							$Data($Name,Labels,$Col) configure -state disabled
						}
					}
					# Iterate over all of the rows for this column
					if { [info exists Data($Name,rowCol,$Col)] } {
						set RowLabels $Data($Name,rowCol,$Col)
						foreach Row $RowLabels {
							if { [info exists Data($Name,CheckButtons,$Row,$Col)] } {
								if {[winfo exists $Data($Name,CheckButtons,$Row,$Col)]} {
									$Data($Name,CheckButtons,$Row,$Col) configure -state disabled
								} else {
									error "The checkbutton window for Row: \"$Row\" and Col: \"$Col\" doesn't exist in columnMultiSelect: \"$Name\""
								}
							} else {
								error "The checkbutton path for Row: \"$Row\" and Col: \"$Col\" doesn't exist in columnMultiSelect: \"$Name\""
							}
						}
					} else {
						error "Can't read the rows for column: \"$Col\" in columnMultiSelect: \"$Name\""
					}
				} else {
					error "Can't find the column: \"$Col\" in columnMultiSelect: \"$Name\""
				}
			} else {
				error "The columnMultiSelect: \"$Name\" is not properly configured."
			}
		}
		
		2 {
			# Grey out an item
			set Row [lindex $args 0]
			set Col [lindex $args 1]

			if { [info exists Data($Name,CheckButtons,$Row,$Col)] } {
				if {[winfo exists $Data($Name,CheckButtons,$Row,$Col)]} {
					$Data($Name,CheckButtons,$Row,$Col) configure -state disabled
				} else {
					error "The checkbutton window for Row: \"$Row\" and Col: \"$Col\" doesn't exist in columnMultiSelect: \"$Name\""
				}
			} else {
				error "The checkbutton path for Row: \"$Row\" and Col: \"$Col\" doesn't exist in columnMultiSelect: \"$Name\""
			}
		}
		
		default {
			error "Wrong number of arguments passed to \"$Name grey\""
		}
		
	}
}

proc ::AIEnv::GUIManagement::ColumnMultiSelect::_ungrey {Name args} {
	if {[catch {eval [list UngreyImpl $Name] $args} result] != 0} {
		::AIEnv::GUIManagement::RuntimeError $result
	} else {
		return $result
	}		
}

proc ::AIEnv::GUIManagement::ColumnMultiSelect::UngreyImpl {Name args} {
	variable Data
	
	switch [llength $args] {
		0 {
			# UnGrey everything
			_widgetungrey $Name
		}
		1 {
			# UnGrey out a column
			set Col [lindex $args 0]
			if { [info exists Data($Name,ColumnList)] } {
				if { [lsearch $Data($Name,ColumnList) $Col] != -1 } {
					# Grey out the label
					if { [info exists Data($Name,Labels,$Col)] } {
						if { [winfo exists $Data($Name,Labels,$Col)] } {
							$Data($Name,Labels,$Col) configure -state normal
						}
					}
					# Iterate over all of the rows for this column
					if { [info exists Data($Name,rowCol,$Col)] } {
						set RowLabels $Data($Name,rowCol,$Col)
						foreach Row $RowLabels {
							if { [info exists Data($Name,CheckButtons,$Row,$Col)] } {
								if {[winfo exists $Data($Name,CheckButtons,$Row,$Col)]} {
									$Data($Name,CheckButtons,$Row,$Col) configure -state normal
								} else {
									error "The checkbutton window for Row: \"$Row\" and Col: \"$Col\" doesn't exist in columnMultiSelect: \"$Name\""
								}
							} else {
								error "The checkbutton path for Row: \"$Row\" and Col: \"$Col\" doesn't exist in columnMultiSelect: \"$Name\""
							}
						}
					} else {
						error "Can't read the rows for column: \"$Col\" in columnMultiSelect: \"$Name\""
					}
				} else {
					error "Can't find the column: \"$Col\" in columnMultiSelect: \"$Name\""
				}
			} else {
				error "The columnMultiSelect: \"$Name\" is not properly configured."
			}
		}
		2 {
			# UnGrey out an item
			set Row [lindex $args 0]
			set Col [lindex $args 1]

			if { [info exists Data($Name,CheckButtons,$Row,$Col)] } {
				if {[winfo exists $Data($Name,CheckButtons,$Row,$Col)]} {
					$Data($Name,CheckButtons,$Row,$Col) configure -state normal
				} else {
					error "The checkbutton window for Row: \"$Row\" and Col: \"$Col\" doesn't exist in columnMultiSelect: \"$Name\""
				}
			} else {
				error "The checkbutton path for Row: \"$Row\" and Col: \"$Col\" doesn't exist in columnMultiSelect: \"$Name\""
			}
		}
		default {
			error "Wrong number of arguments passed to \"$Name ungrey\""
		}
		
	}
}

proc ::AIEnv::GUIManagement::ColumnMultiSelect::_widgetgrey {Name args} {
	if {[catch {eval [list WidgetGreyImpl $Name] $args} result] != 0} {
		::AIEnv::GUIManagement::RuntimeError $result
	} else {
		return $result
	}	
}

proc ::AIEnv::GUIManagement::ColumnMultiSelect::WidgetGreyImpl {Name args} {
	
	variable Data
	
	# Grey everything out
	
	# Grey out the main frame
	if { [info exists Data($Name,MainFrame)] } {
		if { [winfo exists $Data($Name,MainFrame)] } {
			$Data($Name,MainFrame) configure -state disabled
		}
	}
	# Grey out the rows and columns
	if { [info exists Data($Name,ColumnList)] } {
		set Columns $Data($Name,ColumnList)
		foreach Col $Columns {
			if { [info exists Data($Name,Labels,$Col)] } {
				if { [winfo exists $Data($Name,Labels,$Col)] } {
					$Data($Name,Labels,$Col) configure -state disabled
				}
			}
			if { [info exists Data($Name,rowCol,$Col)] } {
				set Rows $Data($Name,rowCol,$Col)
				foreach Row $Rows {
					if { [info exists Data($Name,CheckButtons,$Row,$Col)] } {
						if { [winfo exists $Data($Name,CheckButtons,$Row,$Col)] } {
							$Data($Name,CheckButtons,$Row,$Col) configure -state disabled
						}
					}
				}
			}
		}
	}	
}

proc ::AIEnv::GUIManagement::ColumnMultiSelect::_widgetungrey {Name args} {
	if {[catch {eval [list WidgetUngreyImpl $Name] $args} result] != 0} {
		::AIEnv::GUIManagement::RuntimeError $result
	} else {
		return $result
	}		
}

proc ::AIEnv::GUIManagement::ColumnMultiSelect::WidgetUngreyImpl {Name args} {
	
	variable Data
	
	# Grey everything out
	
	# Grey out the main frame
	if { [info exists Data($Name,MainFrame)] } {
		if { [winfo exists $Data($Name,MainFrame)] } {
			$Data($Name,MainFrame) configure -state normal
		}
	}
	# Grey out the rows and columns
	if { [info exists Data($Name,ColumnList)] } {
		set Columns $Data($Name,ColumnList)
		foreach Col $Columns {
			if { [info exists Data($Name,Labels,$Col)] } {
				if { [winfo exists $Data($Name,Labels,$Col)] } {
					$Data($Name,Labels,$Col) configure -state normal
				}
			}
			if { [info exists Data($Name,rowCol,$Col)] } {
				set Rows $Data($Name,rowCol,$Col)
				foreach Row $Rows {
					if { [info exists Data($Name,CheckButtons,$Row,$Col)] } {
						if { [winfo exists $Data($Name,CheckButtons,$Row,$Col)] } {
							$Data($Name,CheckButtons,$Row,$Col) configure -state normal
						}
					}
				}
			}
		}
	}	
}

proc ::AIEnv::GUIManagement::ColumnMultiSelect::GetParentType {Name} {
	variable Data
	if { [array names Data "$Name,parent"] != "" } {
		set Parent $Data($Name,parent)
		return [$Parent get type]
	} else {
		error "The parent object has not been set for the multiselect widget named: \"$Name\""
	}	
}

proc ::AIEnv::GUIManagement::ColumnMultiSelect::GetTitle {Name} {
	variable Data
	if { [array names Data "$Name,title"] != "" } {
		return $Data($Name,title)
	} else {
		error "The parent object has not been set for the multiselect widget named: \"$Name\""
	}	
}

proc ::AIEnv::GUIManagement::ColumnMultiSelect::GetNodeID {Name} {
	variable Data
	if { [array names Data "$Name,nodeID"] != "" } {
		return $Data($Name,nodeID)
	} else {
		error "The nodeID has not been set for the multiselect widget named: \"$Name\""
	}	
}

proc ::AIEnv::GUIManagement::ColumnMultiSelect::GetParent {Name} {
	variable Data
	if { [array names Data "$Name,parent"] != "" } {
		return $Data($Name,parent)
	} else {
		error "The parent object has not been set for the multiselect widget named: \"$Name\""
	}	
}
