Skip to main content



      Home
Home » Archived » BIRT » Changing Cell/DataItem CSS through Script
Changing Cell/DataItem CSS through Script [message #254449] Tue, 04 September 2007 16:50 Go to next message
Eclipse UserFriend
Originally posted by: uswapnil2000.yahoo.co.in

Hi,

Is there a way to change CSS for cell/dataItem dynamically?

Problem:
I am building table contents through scripted datasource. While building
it, I need to color background of data Item depending on certain threshold
conditions.
All the data item values and threshold values are dynamic and there is one
threshold per detail row. I can change the style of the whole row by using
"IRowInstance" but is there a way to change the style of particular
dataItem/cell of the row so that some cells will have green
background/some with red and some with purple.

Workaround:
I know, I can do this through highlight option of BIRT designer but it
involves lot of manual work as each row can have more than 40 cells.

Any response will be appreciated.

Thanks!
Swapnil.
Re: Changing Cell/DataItem CSS through Script [message #254466 is a reply to message #254449] Tue, 04 September 2007 17:29 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: jasonweathersby.alltel.net

You can change the cell color using
this.getStyle().backgroundColor = "red"
In the onCreate script for the cell. I am not certain this is what you
want though.


Jason

Swapnil wrote:
> Hi,
>
> Is there a way to change CSS for cell/dataItem dynamically?
>
> Problem:
> I am building table contents through scripted datasource. While building
> it, I need to color background of data Item depending on certain
> threshold conditions.
> All the data item values and threshold values are dynamic and there is
> one threshold per detail row. I can change the style of the whole row by
> using "IRowInstance" but is there a way to change the style of
> particular dataItem/cell of the row so that some cells will have green
> background/some with red and some with purple.
>
> Workaround:
> I know, I can do this through highlight option of BIRT designer but it
> involves lot of manual work as each row can have more than 40 cells.
>
> Any response will be appreciated.
>
> Thanks!
> Swapnil.
>
>
Re: Changing Cell/DataItem CSS through Script [message #254474 is a reply to message #254466] Tue, 04 September 2007 18:20 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: uswapnil2000.yahoo.co.in

Jason,

Thanks for the speedy reply.

I know I can call getStyle() on RowInstance as depicted in the following
code but how should I call getStyle() on IDataItemInstance, there seems to
be no method associated with it. Sorry if I am missing something here.



import
org.eclipse.birt.report.engine.api.script.eventadapter.RowEv entAdapter;
import org.eclipse.birt.report.engine.api.script.IReportContext;
import org.eclipse.birt.report.engine.api.script.ScriptException;
import org.eclipse.birt.report.engine.api.script.instance.IRowInsta nce;
import org.eclipse.birt.report.engine.api.script.IRowData;
import org.eclipse.birt.report.engine.api.script.element.ICell;


public class RowEH extends RowEventAdapter {
public void onCreate(IRowInstance row, IReportContext context) {

IRowData data = row.getRowData();
double minThresh = 0.0;
double expectedThresh = 100.0;
try {
minThresh =
((Double)data.getColumnValue(("row[\"ServiceValueMinimum\"] "))).doubleValue();
expectedThresh =
((Double)data.getColumnValue(("row[\"ServiceValueExpected\ "]"))).doubleValue();
} catch (ScriptException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
try {
for (int i = 0 ; i <= data.getColumnCount(); i++){
if (data.getColumnName(i).equalsIgnoreCase("ServiceExpected") ||
data.getColumnName(i).equalsIgnoreCase("Minimum")
|| data.getColumnName(i).equalsIgnoreCase("CustomerName"))
if (((Double) data.getColumnValue(i)).doubleValue() >= expectedThresh &&
((Double) data.getColumnValue(i)).doubleValue() > minThresh ) {
row.getStyle( ).setBackgroundColor("#80FF80");
}else if (((Double) data.getColumnValue(i)).doubleValue() >= minThresh &&
((Double) data.getColumnValue(i)).doubleValue() < expectedThresh ) {
row.getStyle( ).setBackgroundColor("#FEA342");
}else if (((Double) data.getColumnValue(i)).doubleValue() < expectedThresh
&& ((Double) data.getColumnValue(i)).doubleValue() < minThresh ) {
row.getStyle( ).setBackgroundColor("#FF4040");
}
}

} catch (Exception e) {
e.printStackTrace();
}
}
Re: Changing Cell/DataItem CSS through Script [message #254489 is a reply to message #254474] Tue, 04 September 2007 20:55 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: jasonweathersby.alltel.net

Are you using BIRT 2.2. Try this:

import
org.eclipse.birt.report.engine.api.script.eventadapter.DataI temEventAdapter;
import org.eclipse.birt.report.engine.api.script.instance.IDataItem Instance;
import org.eclipse.birt.report.engine.api.script.IReportContext;

public class mydataevent extends DataItemEventAdapter {
public void onCreate( IDataItemInstance data, IReportContext
reportContext )
{
data.getStyle().setBackgroundColor("red");

}
}

Jason

Swapnil wrote:
> Jason,
>
> Thanks for the speedy reply.
>
> I know I can call getStyle() on RowInstance as depicted in the following
> code but how should I call getStyle() on IDataItemInstance, there seems
> to be no method associated with it. Sorry if I am missing something here.
>
>
>
> import
> org.eclipse.birt.report.engine.api.script.eventadapter.RowEv entAdapter;
> import org.eclipse.birt.report.engine.api.script.IReportContext;
> import org.eclipse.birt.report.engine.api.script.ScriptException;
> import org.eclipse.birt.report.engine.api.script.instance.IRowInsta nce;
> import org.eclipse.birt.report.engine.api.script.IRowData;
> import org.eclipse.birt.report.engine.api.script.element.ICell;
>
>
> public class RowEH extends RowEventAdapter {
> public void onCreate(IRowInstance row, IReportContext context) {
>
> IRowData data = row.getRowData();
> double minThresh = 0.0;
> double expectedThresh = 100.0;
> try {
> minThresh =
> ((Double)data.getColumnValue(("row[\"ServiceValueMinimum\"] "))).doubleValue();
>
> expectedThresh =
> ((Double)data.getColumnValue(("row[\"ServiceValueExpected\ "]"))).doubleValue();
>
> } catch (ScriptException e1) {
> // TODO Auto-generated catch block
> e1.printStackTrace();
> }
> try {
> for (int i = 0 ; i <= data.getColumnCount(); i++){
> if (data.getColumnName(i).equalsIgnoreCase("ServiceExpected") ||
> data.getColumnName(i).equalsIgnoreCase("Minimum")
> || data.getColumnName(i).equalsIgnoreCase("CustomerName"))
> if (((Double) data.getColumnValue(i)).doubleValue() >= expectedThresh &&
> ((Double) data.getColumnValue(i)).doubleValue() > minThresh ) {
> row.getStyle( ).setBackgroundColor("#80FF80");
> }else if (((Double) data.getColumnValue(i)).doubleValue() >= minThresh
> && ((Double) data.getColumnValue(i)).doubleValue() < expectedThresh ) {
> row.getStyle( ).setBackgroundColor("#FEA342");
> }else if (((Double) data.getColumnValue(i)).doubleValue() <
> expectedThresh && ((Double) data.getColumnValue(i)).doubleValue() <
> minThresh ) {
> row.getStyle( ).setBackgroundColor("#FF4040");
> }
> }
>
> } catch (Exception e) {
> e.printStackTrace();
> }
> }
>
Re: Changing Cell/DataItem CSS through Script [message #254572 is a reply to message #254489] Wed, 05 September 2007 20:33 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: uswapnil2000.yahoo.co.in

Thanks for the suggestion. Upgrading to 2.2 worked....

I have one more question on the similiar lines.

In my row there are total 40 cells and each cell gets a color depending on
the value of first two cells. How can I compare two cell values as event
handler is placed on the cell level? I tried to get the values of the
first two cells by using RowEventHandlerClass like this:

import
org.eclipse.birt.report.engine.api.script.eventadapter.RowEv entAdapter;
import org.eclipse.birt.report.engine.api.script.IReportContext;
import org.eclipse.birt.report.engine.api.script.instance.IRowInsta nce;
import org.eclipse.birt.report.engine.api.script.IRowData;


public class RowEventHandler extends RowEventAdapter {

/* table onPrepare event */
public void onPrepare( IRowInstance row, IReportContext context)

{
double minThresh = 0.0;
double expectedThresh = 100.0;
try
{
IRowData data = row.getRowData();
inThresh =
((Double)data.getColumnValue(("row[\"ServiceMinimum\"]"))).doubleValue();
expectedThresh =
((Double)data.getColumnValue(("row[\"ServiceExpected\"]"))).doubleValue();

row.setUserPropertyValue( "expectedThreshold", expectedThresh );
row.setUserPropertyValue( "minimumThreshold", minThresh );
} catch ( Exception e ) {
e.printStackTrace( );
}
}
}



And then later using IDataItemInstance's class like:

parent = iDataItemInstanceReference.getParent().getParent();
String exp= parent.getUserPropertyValue("expectedThreshold");
String min = parent.getUserPropertyValue("minimumThreshold");

I also tried:
IRowData rowData = parent.getRowData();
try {
minimumThresh =
((Double)rowData.getColumnValue(("row[\"ServiceMinimum\"] "))).doubleValue();
} catch (ScriptException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
expectedThresh =
((Double)rowData.getColumnValue(("row[\"ServiceExpected\"] "))).doubleValue();
} catch (ScriptException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}




but both of these always return null.

Thanks in advance.

Swapnil.
Re: Changing Cell/DataItem CSS through Script [message #254654 is a reply to message #254572] Thu, 06 September 2007 14:00 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: uswapnil2000.yahoo.co.in

Does anybody has answer on this?

Any response will be appreciated.

Thanks!

Swapnil.
Re: Changing Cell/DataItem CSS through Script [message #254828 is a reply to message #254572] Mon, 10 September 2007 10:39 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: jasonweathersby.alltel.net

Swapnil,

Try something like this:

import
org.eclipse.birt.report.engine.api.script.eventadapter.DataI temEventAdapter;
import org.eclipse.birt.report.engine.api.script.instance.IDataItem Instance;
import org.eclipse.birt.report.engine.api.script.IReportContext;

public class mydataevent extends DataItemEventAdapter {
public void onCreate( IDataItemInstance data, IReportContext
reportContext )
{
try{
Integer jj = (Integer)data.getRowData().getColumnValue("QUANTITYORDERED");
if( jj == 50){
data.getStyle().setBackgroundColor("red");
}
}catch (Exception e){

e.printStackTrace();
}

}
}


Jason

Swapnil wrote:
> Thanks for the suggestion. Upgrading to 2.2 worked....
>
> I have one more question on the similiar lines.
>
> In my row there are total 40 cells and each cell gets a color depending
> on the value of first two cells. How can I compare two cell values as
> event handler is placed on the cell level? I tried to get the values of
> the first two cells by using RowEventHandlerClass like this:
>
> import
> org.eclipse.birt.report.engine.api.script.eventadapter.RowEv entAdapter;
> import org.eclipse.birt.report.engine.api.script.IReportContext;
> import org.eclipse.birt.report.engine.api.script.instance.IRowInsta nce;
> import org.eclipse.birt.report.engine.api.script.IRowData;
>
>
> public class RowEventHandler extends RowEventAdapter {
>
> /* table onPrepare event */
> public void onPrepare( IRowInstance row, IReportContext context)
> {
> double minThresh = 0.0;
> double expectedThresh = 100.0;
> try {
> IRowData data = row.getRowData();
> inThresh =
> ((Double)data.getColumnValue(("row[\"ServiceMinimum\"]"))).doubleValue();
> expectedThresh =
> ((Double)data.getColumnValue(("row[\"ServiceExpected\"]"))).doubleValue();
>
> row.setUserPropertyValue( "expectedThreshold", expectedThresh );
> row.setUserPropertyValue( "minimumThreshold", minThresh );
> } catch ( Exception e ) {
> e.printStackTrace( );
> }
> }
> }
>
>
>
> And then later using IDataItemInstance's class like:
>
> parent = iDataItemInstanceReference.getParent().getParent();
> String exp= parent.getUserPropertyValue("expectedThreshold");
> String min = parent.getUserPropertyValue("minimumThreshold");
>
> I also tried:
> IRowData rowData = parent.getRowData();
> try {
> minimumThresh =
> ((Double)rowData.getColumnValue(("row[\"ServiceMinimum\"] "))).doubleValue();
>
> } catch (ScriptException e) {
> // TODO Auto-generated catch block
> e.printStackTrace();
> }
> try {
> expectedThresh =
> ((Double)rowData.getColumnValue(("row[\"ServiceExpected\"] "))).doubleValue();
>
> } catch (ScriptException e) {
> // TODO Auto-generated catch block
> e.printStackTrace();
> }
>
>
>
>
> but both of these always return null.
>
> Thanks in advance.
>
> Swapnil.
>
>
>
>
>
Re: Changing Cell/DataItem CSS through Script [message #255616 is a reply to message #254654] Mon, 17 September 2007 02:50 Go to previous messageGo to next message
Eclipse UserFriend
What's about CellEventHandler, something like that:

public class MyCellEventHandler extends CellEventAdapter{

public void onCreate(ICellInstance cellInstance, IReportContext
reportContext) {
try {
if(cellInstance.getRowData().getColumnValue("column1")>cellInstance.
getRowData().getColumnValue("column2")){
cellInstance.getStyle().setColor(...);
cellInstance.getStyle().setBackground(...);
cellInstance.getStyle().setFontWeight("bolder");
}
} catch (ScriptException e) {
e.printStackTrace();
}
}
}
Re: Changing Cell/DataItem CSS through Script [message #256006 is a reply to message #254489] Mon, 24 September 2007 10:27 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: uswapnil2000.yahoo.co.in

Jason,

Is there a way to toggle the visiblility of row if data item contents are
empty?

Swapnil.
Re: Changing Cell/DataItem CSS through Script [message #256029 is a reply to message #256006] Mon, 24 September 2007 12:04 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: jasonweathersby.alltel.net

Swapnil,

You should be able to use a visibility expression on the data item to
check for null.

Jason

Swapnil wrote:
> Jason,
>
> Is there a way to toggle the visiblility of row if data item contents
> are empty?
>
> Swapnil.
>
Re: Changing Cell/DataItem CSS through Script [message #256043 is a reply to message #256029] Mon, 24 September 2007 12:43 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: uswapnil2000.yahoo.co.in

Jason,

Thanks for the reply.

I know, I can use Visbility feature to do this but is it possible to do
this from script?

Something like:

check if cell/dataitem contents are null...
if yes then
getParent() -- which will be row
and disable the visibility of the row.
I didn't find any references to setVisibility() in API....

Swapnil.
Re: Changing Cell/DataItem CSS through Script [message #256064 is a reply to message #256043] Mon, 24 September 2007 14:32 Go to previous message
Eclipse UserFriend
Originally posted by: jasonweathersby.alltel.net

Swapnil,

I believe when the scripts run it will be to late to set the visibility
using the API.

Jason

Swapnil wrote:
> Jason,
>
> Thanks for the reply.
>
> I know, I can use Visbility feature to do this but is it possible to do
> this from script?
>
> Something like:
>
> check if cell/dataitem contents are null...
> if yes then
> getParent() -- which will be row
> and disable the visibility of the row.
> I didn't find any references to setVisibility() in API....
>
> Swapnil.
>
Previous Topic:"BIRT Report Viewer" text in report and title bar
Next Topic:Finding out report format type
Goto Forum:
  


Current Time: Thu May 22 01:16:27 EDT 2025

Powered by FUDForum. Page generated in 0.04996 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top