146 lines
3.3 KiB
Java
146 lines
3.3 KiB
Java
package org.gcube.portlets.user.reportgenerator.client.targets;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import org.gcube.portlets.d4sreporting.common.shared.SerializableTable;
|
|
import org.gcube.portlets.d4sreporting.common.shared.TableCell;
|
|
import org.gcube.portlets.user.reportgenerator.client.Presenter.Presenter;
|
|
|
|
import com.google.gwt.user.client.ui.Button;
|
|
import com.google.gwt.user.client.ui.Composite;
|
|
import com.google.gwt.user.client.ui.FlexTable;
|
|
import com.google.gwt.user.client.ui.VerticalPanel;
|
|
|
|
/**
|
|
*
|
|
* @author Massimiliano Assante ISTI-CNR
|
|
* @version 1.0
|
|
*
|
|
*/
|
|
public class GenericTable extends Composite {
|
|
private VerticalPanel myPanel;
|
|
private FlexTable myTable;
|
|
|
|
Presenter presenter;
|
|
|
|
private int rows;
|
|
private int cols;
|
|
|
|
private int cellWidth;
|
|
private int cellSpacing = 1;
|
|
private int cellPadding = 0;
|
|
|
|
private GenTableCell selectedCell = null;
|
|
|
|
/**
|
|
* constructor called when reading the model
|
|
* @param sTable
|
|
*/
|
|
public GenericTable(SerializableTable sTable, Presenter presenter, int top, int left, int width, int height) {
|
|
|
|
commonConstructorCode(presenter);
|
|
this.rows = sTable.getRowCount();
|
|
this.cols = sTable.getColsNo();
|
|
|
|
/**
|
|
* construct the table
|
|
*/
|
|
for (int i = 0; i < rows; i++) {
|
|
for (int j = 0; j < sTable.getCellCount(i); j++) {
|
|
TableCell toPut = sTable.getValue(i, j);
|
|
int cellWidth = toPut.getCellWidth();
|
|
int cellHeight = toPut.getCellHeight();
|
|
int colspan = toPut.getColspan();
|
|
GenTableCell toAdd = new GenTableCell(i, j, cellWidth, colspan);
|
|
toAdd.setText(toPut.getContent());
|
|
toAdd.setStyleName("tableBorder");
|
|
toAdd.setWidth(""+cellWidth+"px");
|
|
myTable.setWidget(i, j, toAdd);
|
|
myTable.getFlexCellFormatter().setColSpan(i, j, colspan);
|
|
}
|
|
}
|
|
|
|
myPanel = new VerticalPanel();
|
|
myPanel.setWidth(width+"px");
|
|
myPanel.setStyleName("d4sFrame");
|
|
myPanel.add(myTable);
|
|
initWidget(myPanel);
|
|
}
|
|
/**
|
|
* common Constructors Code
|
|
*/
|
|
private void commonConstructorCode(Presenter presenter) {
|
|
this.presenter = presenter;
|
|
myTable= new FlexTable();
|
|
myTable.setWidth("90%");
|
|
myTable.setCellSpacing(cellSpacing);
|
|
myTable.setCellPadding(cellPadding);
|
|
|
|
}
|
|
|
|
|
|
public FlexTable getMyTable() {
|
|
return myTable;
|
|
}
|
|
|
|
public void setMyTable(FlexTable myTable) {
|
|
this.myTable = myTable;
|
|
}
|
|
|
|
public int getRowsNo() {
|
|
return rows;
|
|
}
|
|
|
|
public void setRows(int rows) {
|
|
this.rows = rows;
|
|
}
|
|
|
|
public int getCols() {
|
|
return cols;
|
|
}
|
|
|
|
public void setCols(int cols) {
|
|
this.cols = cols;
|
|
}
|
|
|
|
/**
|
|
*
|
|
* @return
|
|
*/
|
|
public SerializableTable getSerializable() {
|
|
SerializableTable toReturn = new SerializableTable(this.cols);
|
|
for (int i = 0; i < myTable.getRowCount(); i++) {
|
|
toReturn.addRow(getRow(i));
|
|
}
|
|
|
|
return toReturn;
|
|
}
|
|
|
|
public ArrayList<TableCell> getRow(int i) {
|
|
ArrayList<TableCell> toReturn = new ArrayList<TableCell>();
|
|
for (int j = 0; j < myTable.getCellCount(i); j++) {
|
|
GenTableCell tb = (GenTableCell) myTable.getWidget(i, j);
|
|
int colspan = tb.getColspan();
|
|
|
|
toReturn.add(new TableCell(tb.getText(), colspan, tb.getWidth(), tb.getHeight()));
|
|
}
|
|
return toReturn;
|
|
}
|
|
|
|
|
|
public GenTableCell getSelectedCell() {
|
|
return selectedCell;
|
|
}
|
|
|
|
/**
|
|
* adda a column at the left of the selected cell of the selected table
|
|
* TODO: next version
|
|
*/
|
|
public void addColumnLeft(int colindex) {
|
|
// myTable.insertCell(beforeRow, beforeColumn)
|
|
}
|
|
|
|
|
|
|
|
}
|