Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
PUBLIC CLOUD
PRIVATE CLOUD
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Intelligence (Analytics)
Working with all items
Guest16
Hello,
i would like to know if it is possible with BIRT to make an iterator that will get each items 1 by 1 (labels , dynamic text , text , filters etc...) and then work with them 1 by 1 like if it is a label then get the current display caption and modify it , if it is a textbox then get the text contect and modify it etc..
is there a way ?
thank you in advance
Regards
Find more posts tagged with
Comments
johnw
Yes,<br />
<br />
You can do this by opening the report design in the beforeFactory or initialize event, and using the getChildren() method recursively to iterate the object tree of the report design. Each container report item type should have a getChildren() call containing other report items. <br />
<br />
If your using Javascript, your going to need to probably use the getClass().getName() method to get the name of the object since I do not believe there is an instanceof operator in Javascript. If your using a Java event handler, there shouldn't be any issues.<br />
<br />
John<br />
<br />
<blockquote class='ipsBlockquote' data-author="'Guest16'" data-cid="68392" data-time="1284469645" data-date="14 September 2010 - 06:07 AM"><p>
Hello,<br />
i would like to know if it is possible with BIRT to make an iterator that will get each items 1 by 1 (labels , dynamic text , text , filters etc...) and then work with them 1 by 1 like if it is a label then get the current display caption and modify it , if it is a textbox then get the text contect and modify it etc..<br />
<br />
is there a way ?<br />
<br />
thank you in advance<br />
<br />
Regards<br /></p></blockquote>
Guest16
<blockquote class='ipsBlockquote' data-author="'johnw'" data-cid="68402" data-time="1284480356" data-date="14 September 2010 - 09:05 AM"><p>
Yes,<br />
<br />
You can do this by opening the report design in the beforeFactory or initialize event, and using the getChildren() method recursively to iterate the object tree of the report design. Each container report item type should have a getChildren() call containing other report items. <br />
<br />
If your using Javascript, your going to need to probably use the getClass().getName() method to get the name of the object since I do not believe there is an instanceof operator in Javascript. If your using a Java event handler, there shouldn't be any issues.<br />
<br />
John<br /></p></blockquote>
<br />
first Thanks for you reply<br />
i try to search in many ways but i can't get it work i am new in BIRT is their some example of how to make an iterator on all items and get each items contents ?<br />
ps : i use JAVA BIRT API not javascript <br />
<br />
thanks in advance
johnw
I was in a bit of a hurry, so I just threw this together real quick. This will give you an idea how to work with the slots and contents in BIRT containers. I thought the call was getChildren, but I was wrong.
<?xml version="1.0" encoding="UTF-8"?>
<report xmlns="
http://www.eclipse.org/birt/2005/design"
; version="3.2.21" id="1">
<property name="createdBy">Eclipse BIRT Designer Version 2.6.0.v20100531 Build <2.6.0.v20100609-1613></property>
<property name="units">in</property>
<method name="beforeFactory"><![CDATA[var reportRoot = reportContext.getDesignHandle().getBody();
var contentCount = reportRoot.getContents().size();
for (x = 0; x < contentCount; x++)
{
var object = reportRoot.getContents().get(x);
var name = object.getClass().getName();
//test if it is a container. I am using the object name.
if (name.contains("GridHandle"))
{
reportContext.getDesignHandle().getElementFactory().newCell().getSlot(0).getContents()
//iterate over rows
var rowSize = object.getRows().getCount();
for (y = 0; y < rowSize; y++)
{
var currentRow = object.getRows().get(y);
//get each child column
var cellCount = currentRow.getSlot(0).getContents().size();
for (z = 0; z < cellCount; z++)
{
var currentCell = currentRow.getSlot(0).getContents().get(z);
for (z1 = 0; z1 < currentCell.getSlot(0).getContents().size(); z1++)
{
var currentItem = currentCell.getSlot(0).getContents().get(z1);
var currentName = currentItem.getClass().getName();
if (currentName.contains("LabelHandle"))
{
currentItem.text = "Inside of the grid, column: " + z + " , row: " + y;
}
}
}
}
}
else
{
object.text = "Changed to: " + x;
}
}]]></method>
<property name="iconFile">/templates/blank_report.gif</property>
<property name="bidiLayoutOrientation">ltr</property>
<property name="imageDPI">96</property>
<styles>
<style name="report" id="4">
<property name="fontFamily">sans-serif</property>
<property name="fontSize">10pt</property>
</style>
<style name="crosstab" id="5">
<property name="borderBottomColor">#CCCCCC</property>
<property name="borderBottomStyle">solid</property>
<property name="borderBottomWidth">1pt</property>
<property name="borderLeftColor">#CCCCCC</property>
<property name="borderLeftStyle">solid</property>
<property name="borderLeftWidth">1pt</property>
<property name="borderRightColor">#CCCCCC</property>
<property name="borderRightStyle">solid</property>
<property name="borderRightWidth">1pt</property>
<property name="borderTopColor">#CCCCCC</property>
<property name="borderTopStyle">solid</property>
<property name="borderTopWidth">1pt</property>
</style>
<style name="crosstab-cell" id="6">
<property name="borderBottomColor">#CCCCCC</property>
<property name="borderBottomStyle">solid</property>
<property name="borderBottomWidth">1pt</property>
<property name="borderLeftColor">#CCCCCC</property>
<property name="borderLeftStyle">solid</property>
<property name="borderLeftWidth">1pt</property>
<property name="borderRightColor">#CCCCCC</property>
<property name="borderRightStyle">solid</property>
<property name="borderRightWidth">1pt</property>
<property name="borderTopColor">#CCCCCC</property>
<property name="borderTopStyle">solid</property>
<property name="borderTopWidth">1pt</property>
</style>
</styles>
<page-setup>
<simple-master-page name="Simple MasterPage" id="2">
<page-footer>
<text id="3">
<property name="contentType">html</property>
<text-property name="content"><![CDATA[<value-of>new Date()</value-of>]]></text-property>
</text>
</page-footer>
</simple-master-page>
</page-setup>
<body>
<label id="7">
<text-property name="text">Label1</text-property>
</label>
<label id="8">
<text-property name="text">Label2</text-property>
</label>
<grid id="9">
<column id="10"/>
<column id="23"/>
<row id="11">
<cell id="12">
<label id="17">
<text-property name="text">Label3</text-property>
</label>
</cell>
<cell id="20">
<label id="24">
<text-property name="text">Label3</text-property>
</label>
</cell>
</row>
<row id="13">
<cell id="14">
<label id="18">
<text-property name="text">Label4</text-property>
</label>
</cell>
<cell id="21">
<label id="25">
<text-property name="text">Label3</text-property>
</label>
</cell>
</row>
<row id="15">
<cell id="16">
<label id="19">
<text-property name="text">Label5</text-property>
</label>
</cell>
<cell id="22">
<label id="27">
<text-property name="text">Label3</text-property>
</label>
</cell>
</row>
</grid>
</body>
</report>
Guest16
<blockquote class='ipsBlockquote' data-author="'johnw'" data-cid="68451" data-time="1284578928" data-date="15 September 2010 - 12:28 PM"><p>
I was in a bit of a hurry, so I just threw this together real quick. This will give you an idea how to work with the slots and contents in BIRT containers. I thought the call was getChildren, but I was wrong. <br />
<br />
<?xml version="1.0" encoding="UTF-8"?><br />
<report xmlns="<a class='bbc_url' href='
http://www.eclipse.org/birt/2005/design'>http://www.eclipse.org/birt/2005/design"</a>
; version="3.2.21" id="1"><br />
<property name="createdBy">Eclipse BIRT Designer Version 2.6.0.v20100531 Build <2.6.0.v20100609-1613></property><br />
<property name="units">in</property><br />
<method name="beforeFactory"><![CDATA[var reportRoot = reportContext.getDesignHandle().getBody();<br />
<br />
var contentCount = reportRoot.getContents().size();<br />
<br />
for (x = 0; x < contentCount; x++)<br />
{<br />
var object = reportRoot.getContents().get(x);<br />
<br />
var name = object.getClass().getName();<br />
//test if it is a container. I am using the object name.<br />
if (name.contains("GridHandle"))<br />
{<br />
reportContext.getDesignHandle().getElementFactory().newCell().getSlot(0).getContents()<br />
<br />
//iterate over rows<br />
var rowSize = object.getRows().getCount();<br />
<br />
for (y = 0; y < rowSize; y++)<br />
{<br />
var currentRow = object.getRows().get(y);<br />
<br />
//get each child column<br />
var cellCount = currentRow.getSlot(0).getContents().size();<br />
for (z = 0; z < cellCount; z++)<br />
{<br />
var currentCell = currentRow.getSlot(0).getContents().get(z);<br />
<br />
for (z1 = 0; z1 < currentCell.getSlot(0).getContents().size(); z1++)<br />
{<br />
var currentItem = currentCell.getSlot(0).getContents().get(z1);<br />
var currentName = currentItem.getClass().getName();<br />
<br />
if (currentName.contains("LabelHandle"))<br />
{<br />
currentItem.text = "Inside of the grid, column: " + z + " , row: " + y;<br />
}<br />
}<br />
}<br />
}<br />
<br />
}<br />
else<br />
{<br />
object.text = "Changed to: " + x;<br />
}<br />
}]]></method><br />
<property name="iconFile">/templates/blank_report.gif</property><br />
<property name="bidiLayoutOrientation">ltr</property><br />
<property name="imageDPI">96</property><br />
<styles><br />
<style name="report" id="4"><br />
<property name="fontFamily">sans-serif</property><br />
<property name="fontSize">10pt</property><br />
</style><br />
<style name="crosstab" id="5"><br />
<property name="borderBottomColor">#CCCCCC</property><br />
<property name="borderBottomStyle">solid</property><br />
<property name="borderBottomWidth">1pt</property><br />
<property name="borderLeftColor">#CCCCCC</property><br />
<property name="borderLeftStyle">solid</property><br />
<property name="borderLeftWidth">1pt</property><br />
<property name="borderRightColor">#CCCCCC</property><br />
<property name="borderRightStyle">solid</property><br />
<property name="borderRightWidth">1pt</property><br />
<property name="borderTopColor">#CCCCCC</property><br />
<property name="borderTopStyle">solid</property><br />
<property name="borderTopWidth">1pt</property><br />
</style><br />
<style name="crosstab-cell" id="6"><br />
<property name="borderBottomColor">#CCCCCC</property><br />
<property name="borderBottomStyle">solid</property><br />
<property name="borderBottomWidth">1pt</property><br />
<property name="borderLeftColor">#CCCCCC</property><br />
<property name="borderLeftStyle">solid</property><br />
<property name="borderLeftWidth">1pt</property><br />
<property name="borderRightColor">#CCCCCC</property><br />
<property name="borderRightStyle">solid</property><br />
<property name="borderRightWidth">1pt</property><br />
<property name="borderTopColor">#CCCCCC</property><br />
<property name="borderTopStyle">solid</property><br />
<property name="borderTopWidth">1pt</property><br />
</style><br />
</styles><br />
<page-setup><br />
<simple-master-page name="Simple MasterPage" id="2"><br />
<page-footer><br />
<text id="3"><br />
<property name="contentType">html</property><br />
<text-property name="content"><![CDATA[<value-of>new Date()</value-of>]]></text-property><br />
</text><br />
</page-footer><br />
</simple-master-page><br />
</page-setup><br />
<body><br />
<label id="7"><br />
<text-property name="text">Label1</text-property><br />
</label><br />
<label id="8"><br />
<text-property name="text">Label2</text-property><br />
</label><br />
<grid id="9"><br />
<column id="10"/><br />
<column id="23"/><br />
<row id="11"><br />
<cell id="12"><br />
<label id="17"><br />
<text-property name="text">Label3</text-property><br />
</label><br />
</cell><br />
<cell id="20"><br />
<label id="24"><br />
<text-property name="text">Label3</text-property><br />
</label><br />
</cell><br />
</row><br />
<row id="13"><br />
<cell id="14"><br />
<label id="18"><br />
<text-property name="text">Label4</text-property><br />
</label><br />
</cell><br />
<cell id="21"><br />
<label id="25"><br />
<text-property name="text">Label3</text-property><br />
</label><br />
</cell><br />
</row><br />
<row id="15"><br />
<cell id="16"><br />
<label id="19"><br />
<text-property name="text">Label5</text-property><br />
</label><br />
</cell><br />
<cell id="22"><br />
<label id="27"><br />
<text-property name="text">Label3</text-property><br />
</label><br />
</cell><br />
</row><br />
</grid><br />
</body><br />
</report><br /></p></blockquote>
<br />
thank you very much i will take a look !
Guest16
a last question
is it possible to do the same in JAVA BIRT API i'm trying to port this to JAVA but some of the functions are not understand
johnw
Yes. Its actually much easier to do in the Java BIRT Api. You run into 1 limitation, and that is in Java, not all of the properties are public. In the Javascript event handlers, the reflection of private members is already done. But that would be the only issue.<br />
<br />
<blockquote class='ipsBlockquote' data-author="'Guest16'" data-cid="68576" data-time="1284994318" data-date="20 September 2010 - 07:51 AM"><p>
a last question<br />
is it possible to do the same in JAVA BIRT API i'm trying to port this to JAVA but some of the functions are not understand<br /></p></blockquote>