Eclipse Birt - Set style cell table dynamically with Event Handler - eclipse

I have Birt table in a report and i want to create a handler class that change the style color of the cell in the table dynamically if the cell contains the max of the column.
I try this for first step and i hooked the class to the row of the table report.
public class RowMinMax implements IRowEventHandler
{
public void onCreate(IRowInstance rowInstance, IReportContext reportContext)
{
double max=0;
IRowData rowData = rowInstance.getRowData();
double cellValue = (double) rowData.getColumnValue("nameColumn");
if(cellValue>max)
{
//change cell style
}
} ... //OTHER METHOD INTERFACE
}
I can not find a suitable method to find the object cell and set the style (es. font color red).
How can I fix this?
Thanks

Why so complicated? You can achieve this with Javascript in the rptdesign file. No need to use a custom Java class.
First, you should compute the maximum (let's call it "maxValue") using BIRT's aggregation columns - either in the DataSet itself or in the Table item definition.
Next, you can define a function like this in the reports's initialize event:
function modifyStyle(cell, row) {
if (row["nameColumn"] >= row["maxValue"]) {
cell.getStyle().borderLeftWidth = "3px";
cell.getStyle().borderRightWidth = "3px";
}
}
In the cell's onCreate event, call the function:
modifyStyle(this, row);

Related

How can I get the row, column clicked in gwt table?

I have a flextable that gets populated with data from a database.
I want to get the ROW number of the clicked row.
So far I figured out only how to get the value of a particular cell in a particular row. You have to know the position and hard code it which isn't practical.
String test =flexTable.getFlexCellFormatter().getElement(2, 2).getInnerHTML();
System.out.println(test);
How can I create a ClickHandler to get the selected row?
//flexTable is a FlexTable object. Add a ClickHandler to it.
flexTable.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
//gets the index of the cell you clicked on
int cellIndex = flexTable.getCellForEvent(event).getCellIndex();
//gets the index of the row you clicked on
int rowIndex = flexTable.getCellForEvent(event).getRowIndex();
//print statements below will verify
System.out.println("cellIndex "+cellIndex);
System.out.println("rowIndex "+rowIndex);
//gets the value of the selected cell
String test =flexTable.getFlexCellFormatter().getElement(rowIndex,cellIndex ).getInnerHTML();
System.out.println(test);
}
});
The FlexTable supports row spans and column spans, allowing you to layout data in a variety of ways. I think you should use CellTable or a DataGrid or for that matter even a CellList if only single column data is being displayed. To these widgets you can add a selectionhandler to which you can achieve your goal. Refer this it has some pre coded examples.

make the gwt celltable row selected

I have a cell Table in GWT with columns , there are 3 rows in each column, I want the first row to get selected by default when the application starts
some thing like this
mycelltable.setselectedrow(index);
is it possible ?
Thanks
her is the code
display.getShortListedCVsBasedOnJob().getResumeDescriptionColumn().setFieldUpdater(
new FieldUpdater<CandidateSummary, String>() {
public void update(int index, CandidateSummary object,
String value) {
fetchResume(cvSelected, shortListedFlag);
}
});
This fetchResume() method calls but only when i select cell of this column , I want to call this fetchResume() method as my application starts, i.e i want to make the 1st cell of the column to be selected byDefault.
Selection is handled by a SelectionModel, based on objects (not indices); so you have to select the first object from your data in the SelectionModel used by the CellTable (have a look at the Using a key provider to track objects as they change sample code in the Celltable javadoc for an example (last sample before nested classes summary).
This could work?
setSelected(Element elem, boolean selected)
see GWT Documentation
CellTable Google Web Toolkit
Hmm I dont see what´s the Celltable is there. I would set the initial Value like this:
int INITAL_SET_ROW = 0;
TableRowElement initalSetElement = yourCellTable.getRowElement(INITAL_SET_ROW);
yourCellTable.setSelected(initialSetElement, true);
You can try to implement it in you´re main Method. Haven´t tested it tho, hope it helps.
Simply;
List<RowType> source = new LinkedList<RowType>();
//put some data to this list
//populate the table
table.setRowCount(source.size(), true);
table.setRowData(0, source);
//for example, you can select the first row
RowType firstRow = source.get(0);
selectionModel.setSelected(firstRow, true);

How to do single row expansion with CellTable?

I'm trying to use the new GWT CellTable widget but my table needs to support one row expansion, i.e. there is a zippy on the left of a row and when it's clicked, the row should expand to provide more detail information and this row should span across all columns. Is it possible to achieve this with the CellTable? How do I add a row that spans all columns between other rows dynamically?
Any help will be appreciated!
GWT 2.5 will add a CellTableBuilder with the exact goal of allowing this kind of things.
You can find a live example at http://showcase2.jlabanca-testing.appspot.com/#!CwCustomDataGrid (click on the "show friends" cells)
Can you not make the additional row invisible using getRowElement(int row) and using DOM methods to set display 'none' when rendered and as blank when the button, to show it, is hit.
I am working on the solution too and my plan for now is to use CSS classes + manual styles manipulation to make it look as I need. Not sure if I be able to merry it with GWT though: http://jsfiddle.net/7WFcF/
I took a different approach to solve this same problem.
The basic concept is using dom elements to add and remove rows based on an event. The following code is an abstract extension of CellTable. You'll want to call this method from your event that gets fired from the click to expand a row.
import com.google.gwt.dom.client.Document;
import com.google.gwt.dom.client.Element;
import com.google.gwt.dom.client.NodeList;
public abstract class ActionCellTable<T> extends CellTable<T> {
protected abstract void addActionsColumn();
Integer previousSelectedRow = null;
public void displayRowDetail(int selectedRow, Element e){
//Get the tbody of the Cell Table
//Assumption that we want the first (only?) tbody.
Element tbody = this.getElement().getElementsByTagName("tbody").getItem(0);
//Get all the trs in the body
NodeList<Element> trs = tbody.getElementsByTagName("tr");
//remove previously selected view, if there was one
if(previousSelectedRow!=null){
trs.getItem(previousSelectedRow+1).removeFromParent();
//If the current is further down the list then the current your index will be one off.
if(selectedRow>previousSelectedRow)selectedRow--;
}
if(previousSelectedRow==null || selectedRow != previousSelectedRow){// if the are equal we don't want to do anything else
Element td = Document.get().createTDElement();
td.setAttribute("colspan", Integer.toString(trs.getItem(selectedRow).getChildNodes().getLength()));
td.appendChild(e);
Element tr = Document.get().createTRElement();
tr.appendChild(td);
tbody.insertAfter(tr, trs.getItem(selectedRow));
previousSelectedRow=selectedRow;
} else {
previousSelectedRow=null;
}
}
}
previousSelectedRow is used to track which item is "expanded", this could probably be achieved using classes or IDs. If needed I can elaborate more on the CellTable, events, views, and activities.

iPhone UIPickerViewModel Multiple components

I have set a picker's model to a custom class which inherits UIPickerViewModel
I can get the picker to display the first component's data (there are 2) but I don't see a way to tell the picker what the values are for the second column?
I'm using MontoTouch.net , but Obj-C answers are fine.
override GetRowsInComponent (UIPickerView pickerView, int component)
This doesn't let me specify the data for the 2nd column like I could when using a datasource and delegate.
You need to override the GetComponentCount method and return 2 in that case. You want something like:
public override int GetComponentCount (UIPickerView pickerView)
{
return 2;
}
public override int GetRowsInComponent (UIPickerView pickerView, int component)
{
// component will be 0 or 1:
return values [component].Length;
}

Getting events in a button in a panel used as a Table cell

I'm using GWT 1.6.
I am creating a panel that contains a Button and a Label, which I then add to a FlexTable as one of its cells.
The Button is not receiving any Click events. I see that the table supports determining which Cell is clicked on, but in this case, I want the Mouse events to propagate to the various widgets inside the cell. Any idea on how to do that?
Yeah, I hit that, too - no widgets in the table will receive events. I ended up using code like this:
FixedWidthGrid dataTable = createDataTable();
...
dataTable.addTableListener(new TableListener() {
public void onCellClicked(SourcesTableEvents sender, int row, int cell) {
storyViewer.showStory(table.getRowValue(row));
}
});
You could probably start with something like that, then programmatically send events to your button widget to make the appearance of clicking.
If you know how big your table will be use a Grid instead. All of your widgets will receive there events. I have done this and created my own sortable table.
You have to subclass the Button google Class and add a constructor with two additional arguments (int col, int row).
e.g.
public class RuleButton extends Button {
private int row;
private int col;
public RuleButton(String html, ClickListener listener, int row, int col) {
super(html, listener);
setRow(row);
setCol(col);
}
// getters and setters for row and col attributes.
}
When adding the button, call this constructor and pass row and col indexes to it.