use of org.talend.designer.gefabstractmap.figures.table.Table in project tdi-studio-se by Talend.
the class TableItemLayout method layout.
@Override
public void layout(IFigure parent) {
if (parent.getParent() == null || !(parent.getParent().getParent() instanceof Table)) {
throw new RuntimeException("Can't find table");
}
Table table = (Table) parent.getParent().getParent();
Rectangle clientArea = parent.getClientArea();
int X = clientArea.x;
int Y = clientArea.y;
List<TableColumn> columns = table.getColumns();
List children = parent.getChildren();
if (columns.size() != children.size()) {
throw new RuntimeException("Table items size don't match column size");
}
int rowheight = 0;
for (int i = 0; i < children.size(); i++) {
Figure figure = (Figure) children.get(i);
Dimension size = figure.getPreferredSize();
rowheight = Math.max(rowheight, size.height);
}
for (int i = 0; i < columns.size(); i++) {
TableColumn tableColumn = columns.get(i);
Figure figure = (Figure) children.get(i);
int columnWidth = table.getColumnWidth(tableColumn.getColumnKey());
Rectangle newBounds = new Rectangle(X, Y, columnWidth, rowheight);
figure.setBounds(newBounds);
X += columnWidth;
}
}
Aggregations