summaryrefslogtreecommitdiff
path: root/project2/common/rowView.cpp
blob: 5e0106141aa9154b6c7824eab988528f14db7c5d (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
#include <pch.hpp>
#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, "rootname"),
	recordName(p, "recordname")
{
	BOOST_FOREACH(xmlpp::Node * node, p->find("columns/*")) {
		if (const xmlpp::Element * elem = dynamic_cast<const xmlpp::Element *>(node)) {
			viewColumns.insert(Columns::value_type(elem->get_name(), Variable(elem, boost::optional<Glib::ustring>())));
		}
	}
	LoaderBase loader(true);
	loader.supportedStorers.insert(Storer::into<ElementLoader>(&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->addNewRow(recordName());
	if (viewColumns.empty()) {
		rs->foreachColumn(boost::bind(&RowSetPresenter::addNamedValue, presenter, _2, _3));
	}
	else {
		BOOST_FOREACH(const Columns::value_type & col, viewColumns) {
			presenter->addNamedValue(col.first, col.second);
		}
	}
	executeChildren();
	presenter->finishRow();
}

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

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