void PropertyGridContainerWidget::BuildPropertiesGrid(UIControl* activeControl,
        BaseMetadata* metaData,
        HierarchyTreeNode::HIERARCHYTREENODEID activeNodeID)
{
    METADATAPARAMSVECT params;
    params.push_back(BaseMetadataParams(activeNodeID, activeControl));
    BuildPropertiesGrid(metaData, params);
}
void PropertyGridContainerWidget::BuildCustomPropertiesGrid(HierarchyTreeScreenNode* screenNode)
{
    if (!screenNode)
    {
        return;
    }

    BaseMetadata* customMetadata = MetadataFactory::Instance()->GetCustomMetadata(screenNode);
    if (!customMetadata)
    {
        return;
    }

    METADATAPARAMSVECT params;
    params.push_back(BaseMetadataParams(HierarchyTreeNode::HIERARCHYTREENODEID_EMPTY, NULL));
    BuildPropertiesGrid(customMetadata, params);
}
void PropertyGridContainerWidget::BuildPropertiesGridList()
{
    // Need to understand which Metadata we need. Since multiple controls of different
    // type might be selected, we are looking for the most common Metadata.
    const HierarchyTreeController::SELECTEDCONTROLNODES &activeNodes = PropertiesGridController::Instance()->GetActiveTreeNodesList();
    BaseMetadata* metaData = GetActiveMetadata(activeNodes);

    METADATAPARAMSVECT params;
    for (HierarchyTreeController::SELECTEDCONTROLNODES::const_iterator iter = activeNodes.begin();
            iter != activeNodes.end(); iter ++)
    {
        const HierarchyTreeControlNode* controlNode = *iter;
        BaseMetadataParams controlNodeParam(controlNode->GetId(), controlNode->GetUIObject());
        params.push_back(controlNodeParam);
    }

    BuildPropertiesGrid(metaData, params);
}
HierarchyTreeControlNode* LibraryController::CreateNewControl(HierarchyTreeNode* parentNode, const QString& strType, const QString& name, const Vector2& position)
{
	String type = strType.toStdString();

	HierarchyTreeControlNode* controlNode = NULL;
	UIControl* control = NULL;
	CONTROLS::iterator iter;
	
	for (iter = controls.begin(); iter != controls.end(); ++iter)
	{
		HierarchyTreeNode* node = iter->first;
		if (strType == node->GetName())
			break;
	}
	
	if (iter == controls.end() ||
		dynamic_cast<HierarchyTreeControlNode*>(iter->first))
	{
		//create standart control
		BaseObject* object = ObjectFactory::Instance()->New(type);
		control = dynamic_cast<UIControl*>(object);
		if (!control)
		{
			SafeRelease(object);
			return NULL;
		}
		 
		controlNode = new HierarchyTreeControlNode(parentNode, control, name);
	}
	else
	{
		//create aggregator
		HierarchyTreeAggregatorNode* aggregator = dynamic_cast<HierarchyTreeAggregatorNode*>(iter->first);
		if (aggregator)
		{
			controlNode = aggregator->CreateChild(parentNode, name);
			control = controlNode->GetUIObject();
		}
	}
	
	parentNode->AddTreeNode(controlNode);
	
	// In case the control has subcontrols - they should be added to the control node too.
	if (control && !control->GetSubcontrols().empty())
	{
		List<UIControl*> subControls = control->GetSubcontrols();
		for (List<UIControl*>::iterator iter = subControls.begin(); iter != subControls.end(); iter ++)
		{
			UIControl* subControl = (*iter);
			if (!subControl)
			{
				continue;
			}

			HierarchyTreeControlNode* subControlNode =
				new HierarchyTreeControlNode(controlNode, subControl,
											 QString::fromStdString(subControl->GetName()));
			controlNode->AddTreeNode(subControlNode);
		}
	}

	// Initialize a control through its metadata.
	BaseMetadata* newControlMetadata = MetadataFactory::Instance()->GetMetadataForUIControl(control);

	METADATAPARAMSVECT params;
	params.push_back(BaseMetadataParams(controlNode->GetId(), control));
	newControlMetadata->SetupParams(params);

	// Ready to do initialization!
	newControlMetadata->InitializeControl(name.toStdString(), position);

	SAFE_DELETE(newControlMetadata);

	SafeRelease(control);
	return controlNode;
}