summaryrefslogtreecommitdiff
path: root/project2/common/rowView.cpp
blob: 092192f4e36d1af6244dd1f950db75fc2b6b7417 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include "rowView.h"
#include "presenter.h"
#include "scopeObject.h"
#include "xmlObjectLoader.h"
#include "scopeObject.h"
#include <boost/foreach.hpp>
#include <boost/bind.hpp>
#include <libxml++/nodes/textnode.h>

DECLARE_LOADER("view", RowView);

RowView::RowView(const xmlpp::Element * p) :
	SourceObject(p),
	View(p),
	RowProcessor(p),
	rootName(p->get_attribute_value("rootname")),
	recordName(p->get_attribute_value("recordname"))
{
	BOOST_FOREACH(xmlpp::Node * node, p->find("columns/column")) {
		const xmlpp::Element * elem = dynamic_cast<const xmlpp::Element *>(node);
		if (elem) {
			viewColumns.insert(Columns::value_type(elem->get_attribute_value("name"),
					Variable::makeParent(elem->get_child_text()->get_content(), elem->get_attribute_value("source") == "attribute", 0)));
		}
	}
	LoaderBase loader(true);
	loader.supportedStorers.insert(Storer::into(&subViews));
	loader.collectAll(p, true, IgnoreUnsupported);
}

RowView::~RowView()
{
}

void
RowView::loadComplete(const CommonObjects * co)
{
	RowProcessor::loadComplete(co);
}

void
RowView::rowReady(const RowState * rs) const
{
	presenter->pushSub(recordName);
	if (viewColumns.empty()) {
		rs->foreachColumn(boost::bind(&Presenter::addField, presenter, _2, _3));
	}
	else {
		BOOST_FOREACH(const Columns::value_type & col, viewColumns) {
			presenter->addField(col.first, col.second);
		}
	}
	executeChildren();
	presenter->popSub();
}

void
RowView::execute(const Presenter * p) const
{
	presenter = p;
	presenter->pushSub(rootName);
	ScopeObject pres(boost::bind(&Presenter::popSub, p));
	RowProcessor::execute();
}

void
RowView::executeChildren() const
{
	BOOST_FOREACH(const SubViews::value_type & sq, subViews) {
		sq->execute(presenter);
	}
}