use of org.eclipse.draw2d.geometry.Dimension in project tdi-studio-se by Talend.
the class TableContainerLayout method calculateChildrenSize.
private Dimension calculateChildrenSize(List children, int wHint, int hHint, boolean preferred) {
Dimension childSize;
IFigure child;
int height = 0, width = 0;
for (int i = 0; i < children.size(); i++) {
child = (IFigure) children.get(i);
if (child instanceof AbstractTreeSettingContainer) {
if (!tableMananger.isActivateCondensedTool()) {
continue;
}
}
if (child instanceof FilterContainer) {
if (!tableMananger.isActivateExpressionFilter()) {
continue;
}
}
if (child instanceof AbstractGlobalMapContainer) {
if (!tableMananger.isActivateGlobalMap()) {
continue;
}
}
childSize = transposer.t(preferred ? getChildPreferredSize(child, wHint, hHint) : getChildMinimumSize(child, wHint, hHint));
height += childSize.height;
width = Math.max(width, childSize.width);
// header figure must be the first figure , or there will be problem here
if (tableMananger.isMinimized()) {
break;
}
}
return new Dimension(width, height);
}
use of org.eclipse.draw2d.geometry.Dimension in project tdi-studio-se by Talend.
the class TableContainerLayout method layout.
@Override
public void layout(IFigure parent) {
List children = parent.getChildren();
int numChildren = children.size();
Rectangle clientArea = transposer.t(parent.getClientArea());
int x = clientArea.x;
int y = clientArea.y;
int availableHeight = clientArea.height;
Dimension[] prefSizes = new Dimension[numChildren];
Dimension[] minSizes = new Dimension[numChildren];
int wHint = -1;
int hHint = -1;
if (isHorizontal()) {
hHint = parent.getClientArea(Rectangle.SINGLETON).height;
} else {
wHint = parent.getClientArea(Rectangle.SINGLETON).width;
}
IFigure child;
int totalHeight = 0;
int totalMinHeight = 0;
int prefMinSumHeight = 0;
for (int i = 0; i < numChildren; i++) {
child = (IFigure) children.get(i);
prefSizes[i] = transposer.t(getChildPreferredSize(child, wHint, hHint));
minSizes[i] = transposer.t(getChildMinimumSize(child, wHint, hHint));
totalHeight += prefSizes[i].height;
totalMinHeight += minSizes[i].height;
}
totalHeight += (numChildren - 1) * spacing;
totalMinHeight += (numChildren - 1) * spacing;
prefMinSumHeight = totalHeight - totalMinHeight;
int amntShrinkHeight = totalHeight - Math.max(availableHeight, totalMinHeight);
if (amntShrinkHeight < 0) {
amntShrinkHeight = 0;
}
for (int i = 0; i < numChildren; i++) {
int amntShrinkCurrentHeight = 0;
int prefHeight = prefSizes[i].height;
int minHeight = minSizes[i].height;
int prefWidth = prefSizes[i].width;
int minWidth = minSizes[i].width;
Rectangle newBounds = new Rectangle(x, y, prefWidth, prefHeight);
child = (IFigure) children.get(i);
if (child instanceof AbstractTreeSettingContainer) {
if (!tableMananger.isActivateCondensedTool()) {
child.setBounds(new Rectangle(x, y, 0, 0));
continue;
}
}
if (child instanceof FilterContainer) {
if (!tableMananger.isActivateExpressionFilter()) {
child.setBounds(new Rectangle(x, y, 0, 0));
continue;
}
}
if (child instanceof AbstractGlobalMapContainer) {
if (!tableMananger.isActivateGlobalMap()) {
child.setBounds(new Rectangle(x, y, 0, 0));
continue;
}
}
int width = Math.min(prefWidth, transposer.t(child.getMaximumSize()).width);
if (matchWidth) {
width = transposer.t(child.getMaximumSize()).width;
}
width = Math.max(minWidth, Math.min(clientArea.width, width));
newBounds.width = width;
child.setBounds(transposer.t(newBounds));
amntShrinkHeight -= amntShrinkCurrentHeight;
prefMinSumHeight -= (prefHeight - minHeight);
y += newBounds.height + spacing;
if (child instanceof ScrollPane) {
IFigure contents = ((ScrollPane) child).getViewport().getContents();
if (contents instanceof AbstractTable) {
// ((AbstractTable) contents).setDefautTableWidth(newBounds.width);
}
}
}
}
use of org.eclipse.draw2d.geometry.Dimension in project tdi-studio-se by Talend.
the class TableEntityLayout method calculatePreferredSize.
@Override
protected Dimension calculatePreferredSize(IFigure container, int wHint, int hHint) {
Insets insets = container.getInsets();
if (isHorizontal()) {
wHint = -1;
if (hHint >= 0) {
hHint = Math.max(0, hHint - insets.getHeight());
}
} else {
hHint = -1;
if (wHint >= 0) {
wHint = Math.max(0, wHint - insets.getWidth());
}
}
List children = container.getChildren();
Dimension prefSize = calculateChildrenSize(children, wHint, hHint, true);
// Do a second pass, if necessary
if (wHint >= 0 && prefSize.width > wHint) {
prefSize = calculateChildrenSize(children, prefSize.width, hHint, true);
} else if (hHint >= 0 && prefSize.width > hHint) {
prefSize = calculateChildrenSize(children, wHint, prefSize.width, true);
}
prefSize.height += Math.max(0, children.size() - 1) * spacing;
return transposer.t(prefSize).expand(insets.getWidth(), insets.getHeight()).union(getBorderPreferredSize(container));
}
use of org.eclipse.draw2d.geometry.Dimension 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;
}
}
use of org.eclipse.draw2d.geometry.Dimension in project tdi-studio-se by Talend.
the class TableLayout method layout.
@Override
public void layout(IFigure container) {
Rectangle clientArea = container.getClientArea();
IFigure tableContainer = getTableContainer(container);
int containerWidth = tableContainer.getBounds().width;
int clientWidth = clientArea.width;
if (ajustToDefaultWidth) {
clientWidth = containerWidth;
}
initColumnPercentage(clientWidth, containerWidth);
int columnNum = columns.size();
int toltalWidth = 0;
Dimension[] prefSizes = new Dimension[columnNum];
int titleHeight = 0;
for (int i = 0; i < columnNum; i++) {
TableColumn column = columns.get(i);
prefSizes[i] = column.getPreferredSize();
titleHeight = Math.max(titleHeight, prefSizes[i].height);
}
int X = clientArea.x;
int Y = clientArea.y;
int previousSashOccupied = 0;
for (int i = 0; i < columns.size(); i++) {
TableColumn currentColumn = columns.get(i);
ColumnSash sash = null;
if (i < columns.size() - 1) {
sash = separators.get(i);
}
Double percent = keyAndPercentage.get(currentColumn.getColumnKey());
int width = (int) Math.round(clientWidth * percent);
if (sash != null) {
int halfSashWidth = sash.getSashWidth() / 2;
toltalWidth += width;
Rectangle newBounds = new Rectangle(X, Y, width - halfSashWidth - previousSashOccupied, titleHeight);
currentColumn.setBounds(newBounds);
keyAndLength.put(currentColumn.getColumnKey(), width);
X += newBounds.width;
// don't add sash width to total width
newBounds = new Rectangle(X, Y, sash.getSashWidth(), titleHeight);
sash.setBounds(newBounds);
X += newBounds.width;
previousSashOccupied = halfSashWidth;
} else {
Rectangle newBounds = new Rectangle(X, Y, width - previousSashOccupied, titleHeight);
currentColumn.setBounds(newBounds);
keyAndLength.put(currentColumn.getColumnKey(), width);
toltalWidth += width;
}
}
// in case some blank width
if (toltalWidth != 0) {
int diff = clientWidth - toltalWidth;
if (diff < 0) {
diff = 0;
}
int avg = diff / columnNum;
int remainder = diff % columnNum;
if (avg != 0) {
for (int i = 0; i < columnNum; i++) {
TableColumn tableColumn = columns.get(i);
Rectangle copy = tableColumn.getBounds().getCopy();
if (i > 0) {
copy.x += avg * i;
}
copy.width += avg;
tableColumn.setBounds(copy);
keyAndLength.put(tableColumn.getColumnKey(), keyAndLength.get(tableColumn.getColumnKey()) + avg);
if (i < separators.size()) {
ColumnSash separator = separators.get(i);
copy = separator.getBounds().getCopy();
copy.x += avg * (i + 1);
separator.setBounds(copy);
}
}
}
if (remainder != 0) {
TableColumn lastChild = columns.get(columns.size() - 1);
final Rectangle bounds = lastChild.getBounds();
bounds.width = bounds.width + remainder;
lastChild.setBounds(bounds);
keyAndLength.put(lastChild.getColumnKey(), keyAndLength.get(lastChild.getColumnKey()) + remainder);
}
}
Dimension itemContainerSize = tableItemContainer.getPreferredSize();
Rectangle newBounds = new Rectangle(clientArea.x, clientArea.y + titleHeight, clientWidth, itemContainerSize.height);
tableItemContainer.setBounds(newBounds);
}
Aggregations