public function exchangeWidget(IView $aView, $sWidgetId, $nWay = self::MODEL_TO_WIDGET) { if (!isset($this->arrLinks[$sWidgetId])) { return; } if (!($aModel = $aView->model())) { throw new Exception("视图尚未设置模型,无法进行数据交换"); } if (!($aWidget = $aView->widget($sWidgetId))) { throw new Exception("视图中缺少指定的窗体(%s),无法进行数据交换", $sWidgetId); } switch ($nWay) { // 从模型数据到ui窗体 case self::MODEL_TO_WIDGET: $sModelName = end($this->arrLinks[$sWidgetId]); $aWidget->setValueFromString($aModel->data($sModelName)); break; // 从ui窗体到模型控件 // 从ui窗体到模型控件 case self::WIDGET_TO_MODEL: $widgetVal = $aWidget->valueToString(); foreach ($this->arrLinks[$sWidgetId] as $sModelName) { $aModel->setData($sModelName, $widgetVal); } break; default: throw new Exception("参数(\$nWay)无效"); break; } }
public function __construct($sId = null, $sTemplateName = null, $sTitle = null, IView $aView = null) { parent::__construct(); $this->setId($sId); $this->setTitle($sTitle ? $sTitle : $sId); $this->setTemplateName($sTemplateName); // 消息队列过滤器 $this->messageQueue()->filters()->add(function ($aMsg, $aWidget) { if ($aMsg->poster() != $aWidget) { StopFilterSignal::stop(); } return array($aMsg); }, $this); if ($aView) { $aView->addWidget($this); } }
public function examine(IView $aView) { if ($aView->parent()) { return false; } if (empty($this->arrNames) and empty($this->arrClasses)) { return true; } foreach ($this->arrNames as $sName) { if ($aView->hasName($sName)) { return true; } } foreach ($this->arrClasses as $sClass) { if ($aView instanceof $sClass) { return true; } } return false; }
public function setViewContainer(IView $aViewContainer) { $this->aViewContainer = $aViewContainer; // 记录所有的frame 视图 $this->arrFrameViews[$aViewContainer->name()] = $aViewContainer; }
public function removeView(IView $aView) { $aView->setController(null); $this->mainView()->remove($aView); return $this; }
private function assembleView(&$arrAssemblyList, IView $aView) { if (!($sViewId = $aView->id())) { throw new Exception("在装配视图时,遇到未注册的视图。"); } // 视图已经装配过 if (isset($this->arrViewAssemblyStat[$sViewId])) { // echo "view {$sViewId} has assembled, pre priority: {$this->arrViewAssemblyStat[$sViewId]['priority']}, this time priority: {$arrAssemblyList['filter']['priority']} <br />\r\n" ; // 比较两个 slot 的优先级 if ($arrAssemblyList['filter']['priority'] > $this->arrViewAssemblyStat[$sViewId]['priority']) { // echo "remove {$sViewId} --- <<< {$this->arrViewAssemblyStat[$sViewId]['list']['id']} @ {$this->arrViewAssemblyStat[$sViewId]['listpos']} <br />" ; // 从原装配单中清除 unset($this->arrViewAssemblyStat[$sViewId]['list']['items'][$this->arrViewAssemblyStat[$sViewId]['listpos']]); unset($this->arrViewAssemblyStat[$sViewId]); } else { return; } } // 写入装配单 $arrAssemblyList['items'][] = array('type' => 'view', 'id' => $sViewId, 'object' => $aView); // 记录装配状态 end($arrAssemblyList['items']); $nPos = key($arrAssemblyList['items']); $this->arrViewAssemblyStat[$sViewId] = array('list' => &$arrAssemblyList, 'listpos' => $nPos, 'priority' => $arrAssemblyList['filter']['priority']); // echo "assembling view [ {$sViewId} +++ >>> {$arrAssemblyList['id']} @ {$nPos} ] as priority {$arrAssemblyList['filter']['priority']} <br />" ; }
public static function registerView(IView $aView) { $sName = $aView->name(); if (!isset(self::$arrAssignedId[$sName])) { self::$arrAssignedId[$sName] = 0; } else { self::$arrAssignedId[$sName]++; } $sId = $sName . '-' . self::$arrAssignedId[$sName]; self::$arrRegisteredViews[$sId] = $aView; return $sId; }