0

I have a table in a birt report which is bound to a dataset (from a CSV).

In the detail section there are several columns which ordinarily just print the values in the CSV using a DataItem report element. Now I have a case when based on the value of another column in that row then the value is actually an image. I would normally just use the Image report item but as the column is computed I know of no way to change the report item in the cell.

I've tried to do something in the onCreate event handler but I do not have access to the cell content which I would have in the Java API for building the report in the first place.

What other options do I have for changing the report item used to represent the data in my table?

I can't even just manually create all the rows as I do not know how many there will be when I create the report design, that's what the CSV is for.

Please help, I've been Googling and staring at the javadoc and reference for days without getting any closer to finding a solution.

e.g., rule is if A is X then B is just text, but if A is Y then B is an image.

======================
=  A   =   B         =
======================
=  X   =   42        =  
======================
=  Y   =   42.png    =
======================
=  Y   =   42.png    =
======================
=  X   =   42        =  
======================
James
  • 1,541
  • 12
  • 25
  • 1
    I am confused on why you are not able to use a computed column in your data set to get what you want. Can you expand on that part? – James Jenkins Aug 22 '14 at 15:31
  • Sorry, it's not that I can't get it working using a computed column, that's fine because everything in a column would either be an image or text. My problem is that I have columns where some rows are images and some rows are text depending on the value in another column (in the same row). – James Aug 25 '14 at 11:57
  • 1
    I think I am getting closer to understanding your issue (*but still a bit lost*) I think what you want to do is put two items in the cell, one text and one image, then use the "Visibility" Property to define when to show or hide them. – James Jenkins Aug 25 '14 at 13:11
  • Sounds interesting, how would I switch the visibility property? I should have mentioned that the URL is derived from the data in the row. Would it not cause a problem in cells where text should be shown to have an image reference to a file that does not exist or is possibly an invalid URI? – James Aug 26 '14 at 08:22
  • 1
    The basics of visibility are discussed in related question http://stackoverflow.com/questions/25425876 – James Jenkins Aug 26 '14 at 12:05

1 Answers1

0

Add both items to the computed column B

CellHandle detailCell = (CellHandle) detailRow.getCells().get(INDEX_OF_COLUMN_B);
detailCell.getContent().add(createImage(factory));
detailCell.getContent().add(createDataItem(factory));

When you create the items you must specify the visibility property with a HideRule as follows;

private ImageHandle createImage(ElementFactory factory) {
    ImageHandle image = factory.newImage(null);
    image.setURL("\"http://example.com/\" + row[\"B\"]  + \".png\"");
    HideRule rule = StructureFactory.createHideRule();
    rule.setFormat("all");
    rule.setExpression("row[\"A\"] == \"X\"");
    image.getPropertyHandle(IReportItemModel.VISIBILITY_PROP).addItem(rule);
    return image;
}

Notice that for the image the expression returns true to hide the element so in this case if the value of column A is X then we hide the image.

Apply a HideRule condition to the data item to hide that when the image is displayed, i.e,

rule.setExpression("row[\"A\"] == \"Y\"");

or

rule.setExpression("row[\"A\"] != \"X\"");

This works well but I've only tested the PDF output.

See the hide rule documentation for details on formats

Thanks to @James Jenkins comments which guided me to the solution and the helpful answer to which he linked.

James
  • 1,541
  • 12
  • 25