Friday, January 28, 2011
BIRT: Chart DaVinci
Thursday, January 27, 2011
BIRT: Dynamically Adding a Data Set to a Report
public class ReportEventHandler extends ReportEventAdapter {
@Override
public void beforeFactory(IReportDesign report, IReportContext reportContext) {
super.beforeFactory(report, reportContext);
try {
ReportDesignHandle reportDesign = reportContext.getDesignHandle();
OdaDataSetHandle dataSet = reportDesign.getElementFactory().newOdaDataSet("Data Set", "org.eclipse.birt.report.data.oda.jdbc.JdbcSelectDataSet");
dataSet.setDataSource("Data Source");
dataSet.setQueryText("select employeenumber from employees where employeenumber = ?");
OdaDataSetParameter param = new OdaDataSetParameter();
param.setName("param_1");
param.setParamName("empNo");
param.setNativeName("");
param.setDataType("integer");
param.setNativeDataType(4);
param.setPosition(1);
param.setIsInput(true);
param.setIsOutput(false);
dataSet.getPropertyHandle(DataSetHandle.PARAMETERS_PROP).addItem(param);
OdaResultSetColumn result = new OdaResultSetColumn();
result.setColumnName("EMPLOYEENUMBER");
result.setNativeName("EMPLOYEENUMBER");
result.setDataType("integer");
result.setPosition(1);
result.setNativeDataType(4);
dataSet.getPropertyHandle(DataSetHandle.RESULT_SET_PROP).addItem(result);
ColumnHint resultHint = new ColumnHint();
resultHint.setProperty(ColumnHint.COLUMN_NAME_MEMBER, "EMPLOYEENUMBER");
resultHint.setProperty(ColumnHint.COLUMN_NAME_MEMBER, "integer");
dataSet.getPropertyHandle(DataSet.COLUMN_HINTS_PROP).addItem(resultHint);
//this works
reportDesign.getDataSets().add(dataSet);
//and so does this
//reportDesign.getSlot(ReportDesignHandle.DATA_SET_SLOT).add(dataSet);
//just saving for debug purposes, you can ignore this
reportDesign.saveAs("C:/TEMP/MyTestDesign.rptdesign");
} catch (ContentException e) {
e.printStackTrace();
} catch (NameException e) {
e.printStackTrace();
} catch (SemanticException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
Tuesday, January 25, 2011
BIRT: Connecting Data Elements to Existing Table Bindings
Add a Data element in the report designer. Do not change the name or add an expression, just his Escape. It will create a blank placeholder. Then, right-mouse click on this blank data element, and choose Change Data Column. The Select Data Binding dialog will pop up, and you can select which Data Binding to use. Once you hit OK, it will act just like an original Data Report Item. Again, not sure how I never came across that before...
Monday, January 24, 2011
BIRT: BIRT Helper Functions
The BIRT Functions provide a wealth of useful functionality that typically gets overlooked by developers. Simple operations such as compares, divides, string functions are handled by these functions with special handling for those really annoying gotchas that are typical.
Consider the following example. Lets say you have a real simple divide expression, such as:
numA / numB
That’s simple enough, right? But that’s assuming that numb is never 0, otherwise you have to worry about the dreaded divide by 0 error. Or better yet, what if one of the values is null because it is not present in the dataset? Normally you would need to change the expression to look like:
if ((numA != null) && (numB > 0))
{
numA / numB
}
else
{
null;
}
But that gets tedious, especially if you have a lot of divide expressions. That’s where the BIRT Functions come into play. In the above scenario, the BirtMath.safeDivide() method can help alleviate the need to do that. So, in the above example, I would basically just use the following:
BirtMath.safeDivide(numA, numB, 0);
BIRT is full of helpful functions such as this, such as Round, RoundUp, RoundDown, different comparison functions, and Date Time functions to work with anything from Years, Quarters, down to seconds. Plus, this functionality is expandable via the BIRT Script Library extension point. I typically recommend that most report writers use these functions in favor of the native Javascript functions.
Sunday, January 09, 2011
EclipseCon 2011: Getting Started with BIRT
With only 1 talk scheduled for me this year, this provides me with a great chance to attend a lot of talks. Last year the talks I attended steered me towards EMF, which was helpful in helping some of my paying clients. I am really looking forward to a lot of the talks scheduled for this year. I will probably continue my EMF studying by attending this talk by Kenn Hussey, who was helping with a BIRT ODA, and Ed Merks. since GWT is familiar territory for me already, I look forward to the marriage of these two to drive some EMF points home for me. There are some good Window Builder talks on the program, which is exciting for me since I have been a user of Window Builder for years, and this is the first year that they are doing talks after being bought by Google. My friend Benny has a great talk planned about GIT. Benny has had a lot of experience with GIT, and his involvement as a contributor stemmed from his frustration with shortcomings in the Eclipse implementation, so it will be interesting to hear what he has to say on progress with the plugins. Lots of good talks =)
If your planing on attending, feel free to mozy on by my talk or the BIRT booth and say hi!!