home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World 2000 December
/
PCWorld_2000-12_cd.bin
/
Komunikace
/
Comanche
/
libplugin
/
plugIn.tcl
< prev
next >
Wrap
Text File
|
2000-11-02
|
10KB
|
387 lines
# plugIn.tcl --
# plugIn --
# This class provides the basic interface that every plugin must comply
# with.
class plugIn {
method init {}
method requestXuiDocument {}
method answerXuiDocument {}
method deleteNodeRequest {}
method populateNodeRequest {}
}
# plugIn::init --
# Initializes plugin. Usually here is where the plugin hooks with the
# namespace, etc.
# TO-DO: add arguments so we can optionally specify where we want to hook
body plugIn::init {} {}
# plugIn::requestXuiDocument --
# Request a XUI document from a node such as a property page, wizard etc.
#
# Arguments
# xuiData
#
# xuiData is the standard XML structure for exchanging data with the
# data section having the following elements
#
# type (xuiLabel): document being requested
# node (xuiNode): node of the document
class basePlugIn {
inherit plugIn
variable xuiRequestAnswer
constructor {} {
set xuiRequestAnswer [xuiStructure ::#auto]
}
method requestXuiDocument
method answerXuiDocument
method deleteNodeRequest
method populateNodeRequest
method _registerWithNamespace {}
method _inquiryForPropertyPages { node } {}
method _inquiryForMenu { node } {}
method _inquiryForWizard { type node } {}
method _receivedWizard { type node } {}
method _inquiryForRightPaneContent { node } {}
method _receivedPropertyPages { node xuiPropertyPages } {}
method _executeCommand { node commandName } {}
method _deleteNodeRequest {node} {}
}
body basePlugIn::populateNodeRequest {args} {}
body basePlugIn::deleteNodeRequest {xuiData} {
set data [::plugInUtils::getDataField $xuiData]
set node [[$data getComponentByName node] getId]
$this _deleteNodeRequest $node
}
body basePlugIn::requestXuiDocument { xuiData } {
set data [::plugInUtils::getDataField $xuiData]
set type [[$data getComponentByName docType] getValue]
set node [[$data getComponentByName node] getId]
switch -glob $type {
propertyPages {
$xuiRequestAnswer forgetComponents
foreach pp [ _inquiryForPropertyPages $node] {
$xuiRequestAnswer addComponent $pp
}
return $xuiRequestAnswer
} description {
_inquiryForRightPaneContent $node
} wizard* {
$xuiRequestAnswer forgetComponents
$xuiRequestAnswer clear
foreach pp [_inquiryForWizard $type $node] {
$xuiRequestAnswer addComponent $pp
}
return $xuiRequestAnswer
} command {
$xuiRequestAnswer forgetComponents
set commandName [[$data getComponentByName extraInfo] getValue]
foreach pp [_executeCommand $node $commandName] {
$xuiRequestAnswer addComponent $pp
}
return $xuiRequestAnswer
} default {
}
}
}
body basePlugIn::answerXuiDocument { xuiData } {
set data [::plugInUtils::getDataField $xuiData]
set type [[$data getComponentByName docType] getValue]
set node [[$data getComponentByName node] getId]
set ppages [$data getComponentByName propertyPages]
switch -glob $type {
propertyPages {
_receivedPropertyPages $node $ppages
return
} wizard* {
_receivedWizard $node $ppages
} default {
return
}
}
}
namespace eval ::plugInUtils:: {
variable addData
variable addStructure
variable addNode
variable addNewNode
variable addCaller
set addData [xuiStructure ::#auto]
set addStructure [xuiStructure ::#auto]
$addStructure setName data
set addCaller [xuiLabel ::#auto]
$addCaller setName caller
set addNewNode [xuiNode ::#auto]
$addNewNode setName newNode
set addNode [xuiNode ::#auto]
$addNode setName node
$addData addComponent $addCaller
$addData addComponent $addStructure
$addStructure addComponent $addNode
$addStructure addComponent $addNewNode
variable removeData
variable removeStructure
variable removeNode
variable removeCaller
set removeData [xuiStructure ::#auto]
set removeStructure [xuiStructure ::#auto]
$removeStructure setName data
set removeCaller [xuiLabel ::#auto]
$removeCaller setName caller
set removeNode [xuiNode ::#auto]
$removeNode setName node
$removeData addComponent $addCaller
$removeData addComponent $removeStructure
$removeStructure addComponent $removeNode
variable queryData
variable queryStructure
variable queryNode
variable queryCaller
set queryData [xuiStructure ::#auto]
set queryStructure [xuiStructure ::#auto]
$queryStructure setName data
set queryCaller [xuiLabel ::#auto]
$queryCaller setName caller
set queryNode [xuiNode ::#auto]
$queryNode setName node
$queryData addComponent $addCaller
$queryData addComponent $queryStructure
$queryStructure addComponent $queryNode
}
proc ::plugInUtils::getDataField { xuiData } {
return [$xuiData getComponentByName data]
}
proc ::plugInUtils::getCallerName { xuiData } {
return [[$xuiData getComponentByName caller] getValue]
}
proc ::plugInUtils::getChildByClass { namespace parentNode name } {
variable queryNode
$queryNode setId $parentNode
foreach child [[$namespace getChildren $queryNode null] getChildren] {
if [$child doYouBelongTo $name] {
return $child
}
}
}
proc ::plugInUtils::addNode { caller namespace parentNode args } {
variable addData
variable addNode
variable addNewNode
variable addCaller
array set options {\
-openIcon openFolder \
-closedIcon closedFolder \
-label {default label} \
-classes container \
-container {} \
-nodeName {} }
array set options $args
$addCaller setValue $caller
$addNode setId $parentNode
$addNewNode setClasses $options(-classes)
$addNewNode setLabel $options(-label)
$addNewNode setOpenIcon $options(-openIcon)
$addNewNode setClosedIcon $options(-closedIcon)
return [$namespace addNode $addData]
}
proc ::plugInUtils::removeNode { caller namespace node } {
variable removeData
variable removeNode
variable removeCaller
$removeCaller setValue $caller
$removeNode setId $node
return [$namespace removeNode $removeData]
}
class nodeManagement {
variable namespace
variable plugIn
variable nameMapping
variable containerMapping
variable childrenMapping
variable parentMapping
variable addData
variable addStructure
variable addNode
variable addNewNode
variable queryData
variable queryStructure
variable queryNode
variable queryNewNode
constructor { ns pg } {
set namespace $ns
set plugIn $pg
set queryData [xuiStructure ::#auto]
set queryStructure [xuiStructure ::#auto]
$queryStructure setName data
set queryCaller [xuiLabel ::#auto]
$queryCaller setName caller
$queryCaller setValue $plugIn
set queryNode [xuiNode ::#auto]
$queryNode setName node
$queryData addComponent $queryCaller
$queryData addComponent $queryStructure
$queryStructure addComponent $queryNode
}
method addNode
method removeNode
method setContainer
method getNodeName
method getContainer
method getChildrenByClass
method getPlugInNodeChildren
method getPlugInNodeChildrenByNodeName
method getRootNode
method getParentNode
}
body nodeManagement::setContainer { node newContainer } {
set containerMapping($node) $newContainer
}
body nodeManagement::addNode { parentNode args } {
array set options {\
-openIcon openFolder \
-closedIcon closedFolder \
-label {default label} \
-classes container \
-container {} \
-nodeName {} }
array set options $args
set node [[eval ::plugInUtils::addNode \
$plugIn $namespace $parentNode $args ] getId]
set nameMapping($node) $options(-nodeName)
set containerMapping($node) $options(-container)
lappend childrenMapping($parentNode) $node
set childrenMapping($node) {}
set parentMapping($node) $parentNode
return $node
}
body nodeManagement::removeNode { node } {
::plugInUtils::removeNode $plugIn $namespace $node
unset nameMapping($node)
unset containerMapping($node)
# lsearch and remove from list of parent node
set parentNode $parentMapping($node)
lremove childrenMapping($parentNode) $node
unset childrenMapping($node)
unset parentMapping($node)
return
}
body nodeManagement::getContainer { node } {
return $containerMapping($node)
}
body nodeManagement::getNodeName { node } {
return $nameMapping($node)
}
body nodeManagement::getChildrenByClass {parentNode class} {
$queryNode setId $parentNode
set childList [$ns getChildren $queryData]
}
body nodeManagement::getParentNode { node } {
return $parentMapping($node)
}
body nodeManagement::getPlugInNodeChildrenByNodeName {parentNode nodeName} {
set result {}
foreach child [ getPlugInNodeChildren $parentNode] {
if { [getNodeName $child] == $nodeName } {
lappend result $child
}
}
return $result
}
body nodeManagement::getPlugInNodeChildren {parentNode} {
return $childrenMapping($parentNode)
}
body nodeManagement::getRootNode {} {
return root
}