use of org.eclipse.draw2d.IFigure 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);
}
use of org.eclipse.draw2d.IFigure in project tdi-studio-se by Talend.
the class TreeBranchLayout method paintLines.
public void paintLines(Graphics g) {
int gap = treeBranch.getGaps();
g.setLineStyle(getBranchLineStyle());
IFigure startFig = treeBranch.getTitle();
int x = startFig.getBounds().x + gap;
int y = startFig.getBounds().bottom() - 2;
if (getTreeNodeFigure() != null) {
List children = getTreeNodeFigure().getContents().getChildren();
if (children.size() == 0) {
return;
}
int bottom = y;
for (int i = 0; i < children.size(); i++) {
TableTreeEntityFigure treeNode = (TableTreeEntityFigure) children.get(i);
Rectangle childStartBounds = treeNode.getTreeBranch().getTitle().getBounds();
Point pt = childStartBounds.getLeft();
g.drawLine(x, pt.y, pt.x, pt.y);
bottom = Math.max(bottom, pt.y);
}
g.drawLine(x, y, x, bottom);
}
}
use of org.eclipse.draw2d.IFigure in project tdi-studio-se by Talend.
the class LookupColumnAnchor method getReferencePoint.
@Override
public Point getReferencePoint() {
if (connectionPart == null) {
return getOwner().getBounds().getLeft();
}
MapperTablePart mapperTablePart = MapperUtils.getMapperTablePart(entityManager.getEditPart());
Point ref = null;
if (mapperTablePart != null && entityManager.isTableMinimized()) {
ref = mapperTablePart.getFigure().getBounds().getLeft();
} else {
if (getOwner() == null) {
return null;
} else if (getOwner() instanceof TableEntityFigure) {
TableEntityFigure nodeFigure = (TableEntityFigure) getOwner();
if (nodeFigure.getElement() != null) {
ref = nodeFigure.getElement().getBounds().getLeft();
getOwner().translateToAbsolute(ref);
}
} else {
ref = getOwner().getBounds().getCenter();
getOwner().translateToAbsolute(ref);
}
}
if (mapperTablePart != null && ref != null) {
IFigure treeFigure = mapperTablePart.getFigure();
int avialableX = treeFigure.getBounds().x;
if (ref.x < avialableX) {
ref.x = avialableX;
}
}
if (connectionPart instanceof BaseConnectionEditPart && connectionPart.getFigure() instanceof PolylineConnection) {
BaseConnectionEditPart baseConnectionPart = (BaseConnectionEditPart) connectionPart;
PolylineConnection connFigure = (PolylineConnection) connectionPart.getFigure();
org.eclipse.swt.graphics.Point avilableSize = entityManager.getGraphicalViewer().getControl().getSize();
if (ref != null) {
if (ref.y < 0) {
if (!(baseConnectionPart instanceof LookupConnectionPart)) {
ref.y = 0;
}
baseConnectionPart.setTargetContained(false);
if (baseConnectionPart.isDOTStyle()) {
connFigure.setLineStyle(SWT.LINE_DASHDOTDOT);
} else {
connFigure.setLineStyle(SWT.LINE_SOLID);
}
} else if (ref.y > avilableSize.y) {
if (!(baseConnectionPart instanceof LookupConnectionPart)) {
ref.y = avilableSize.y;
}
baseConnectionPart.setTargetContained(false);
if (baseConnectionPart.isDOTStyle()) {
connFigure.setLineStyle(SWT.LINE_DASHDOTDOT);
} else {
connFigure.setLineStyle(SWT.LINE_SOLID);
}
} else {
baseConnectionPart.setTargetContained(true);
if (!baseConnectionPart.isDOTStyle()) {
connFigure.setLineStyle(SWT.LINE_SOLID);
}
}
}
}
return ref;
}
use of org.eclipse.draw2d.IFigure in project tdi-studio-se by Talend.
the class RowLayout method calculateChildrenSize.
private Dimension calculateChildrenSize(List children, int wHint, int hHint, int tableContainerWidth, Map<Integer, Double> weight) {
Dimension childSize;
IFigure child;
int height = 0, width = 0;
for (int i = 0; i < children.size(); i++) {
child = (IFigure) children.get(i);
childSize = getChildPreferredSize(child, wHint, hHint);
if (weight != null && weight.containsKey(i) && tableContainerWidth > 0) {
childSize.width = (int) (tableContainerWidth * weight.get(i));
}
// height += childSize.height;
width += childSize.width;
}
return new Dimension(width, height);
}
use of org.eclipse.draw2d.IFigure in project tdi-studio-se by Talend.
the class FilterTreeAnchor method getReferencePoint.
@Override
public Point getReferencePoint() {
Point ref = null;
if (tableManager.isMinimized()) {
ref = tableManager.getEditPart().getFigure().getBounds().getLeft();
} else {
if (getOwner() == null) {
return null;
} else if (getOwner() instanceof AbstractTableContainer) {
AbstractTableContainer treeFigure = (AbstractTableContainer) getOwner();
FilterContainer filterContainer = treeFigure.getFilterContainer();
if (filterContainer != null) {
ref = filterContainer.getBounds().getLeft();
}
}
}
if (ref != null) {
IFigure treeFigure = tableManager.getEditPart().getFigure();
int avialableX = treeFigure.getBounds().x;
if (ref.x < avialableX) {
ref.x = avialableX;
}
}
if (connectionPart instanceof BaseConnectionEditPart && connectionPart.getFigure() instanceof PolylineConnection) {
BaseConnectionEditPart baseConnectionPart = (BaseConnectionEditPart) connectionPart;
PolylineConnection connFigure = (PolylineConnection) connectionPart.getFigure();
org.eclipse.swt.graphics.Point avilableSize = tableManager.getGraphicalViewer().getControl().getSize();
if (ref != null) {
if (ref.y < 0) {
if (!(baseConnectionPart instanceof LookupConnectionPart)) {
ref.y = 0;
}
baseConnectionPart.setTargetContained(false);
if (baseConnectionPart.isDOTStyle()) {
connFigure.setLineStyle(SWT.LINE_DASHDOTDOT);
} else {
connFigure.setLineStyle(SWT.LINE_SOLID);
}
} else if (ref.y > avilableSize.y) {
if (!(baseConnectionPart instanceof LookupConnectionPart)) {
ref.y = avilableSize.y;
}
baseConnectionPart.setTargetContained(false);
if (baseConnectionPart.isDOTStyle()) {
connFigure.setLineStyle(SWT.LINE_DASHDOTDOT);
} else {
connFigure.setLineStyle(SWT.LINE_SOLID);
}
} else {
baseConnectionPart.setTargetContained(true);
if (!baseConnectionPart.isDOTStyle()) {
connFigure.setLineStyle(SWT.LINE_SOLID);
}
}
}
}
return ref;
}
Aggregations