Search in sources :

Example 21 with Dimension

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);
}
Also used : FilterContainer(org.talend.designer.gefabstractmap.figures.treesettings.FilterContainer) AbstractGlobalMapContainer(org.talend.designer.gefabstractmap.figures.table.AbstractGlobalMapContainer) Dimension(org.eclipse.draw2d.geometry.Dimension) AbstractTreeSettingContainer(org.talend.designer.gefabstractmap.figures.treesettings.AbstractTreeSettingContainer) IFigure(org.eclipse.draw2d.IFigure)

Example 22 with Dimension

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);
            }
        }
    }
}
Also used : AbstractTable(org.talend.designer.gefabstractmap.figures.table.AbstractTable) ScrollPane(org.eclipse.draw2d.ScrollPane) FilterContainer(org.talend.designer.gefabstractmap.figures.treesettings.FilterContainer) AbstractGlobalMapContainer(org.talend.designer.gefabstractmap.figures.table.AbstractGlobalMapContainer) Rectangle(org.eclipse.draw2d.geometry.Rectangle) List(java.util.List) Dimension(org.eclipse.draw2d.geometry.Dimension) AbstractTreeSettingContainer(org.talend.designer.gefabstractmap.figures.treesettings.AbstractTreeSettingContainer) IFigure(org.eclipse.draw2d.IFigure)

Example 23 with Dimension

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));
}
Also used : Insets(org.eclipse.draw2d.geometry.Insets) List(java.util.List) Dimension(org.eclipse.draw2d.geometry.Dimension)

Example 24 with Dimension

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;
    }
}
Also used : Table(org.talend.designer.gefabstractmap.figures.table.Table) Rectangle(org.eclipse.draw2d.geometry.Rectangle) List(java.util.List) Dimension(org.eclipse.draw2d.geometry.Dimension) TableColumn(org.talend.designer.gefabstractmap.figures.table.TableColumn) Figure(org.eclipse.draw2d.Figure) IFigure(org.eclipse.draw2d.IFigure)

Example 25 with Dimension

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);
}
Also used : Rectangle(org.eclipse.draw2d.geometry.Rectangle) Dimension(org.eclipse.draw2d.geometry.Dimension) ColumnSash(org.talend.designer.gefabstractmap.figures.table.ColumnSash) TableColumn(org.talend.designer.gefabstractmap.figures.table.TableColumn) IFigure(org.eclipse.draw2d.IFigure)

Aggregations

Dimension (org.eclipse.draw2d.geometry.Dimension)105 Point (org.eclipse.draw2d.geometry.Point)46 Rectangle (org.eclipse.draw2d.geometry.Rectangle)43 IFigure (org.eclipse.draw2d.IFigure)20 List (java.util.List)15 Insets (org.eclipse.draw2d.geometry.Insets)8 GraphicalEditPart (org.eclipse.gef.GraphicalEditPart)6 NodeContainer (org.talend.designer.core.ui.editor.nodecontainer.NodeContainer)6 ArrayList (java.util.ArrayList)4 AbstractGraphicalEditPart (org.eclipse.gef.editparts.AbstractGraphicalEditPart)4 SimpleHtmlFigure (org.talend.commons.ui.utils.workbench.gef.SimpleHtmlFigure)3 IElementParameter (org.talend.core.model.process.IElementParameter)3 AbstractJobletContainer (org.talend.designer.core.ui.editor.jobletcontainer.AbstractJobletContainer)3 LinkedList (java.util.LinkedList)2 Figure (org.eclipse.draw2d.Figure)2 Label (org.eclipse.draw2d.Label)2 PolylineConnection (org.eclipse.draw2d.PolylineConnection)2 PointList (org.eclipse.draw2d.geometry.PointList)2 GraphicalViewerKeyHandler (org.eclipse.gef.ui.parts.GraphicalViewerKeyHandler)2 ScrollingGraphicalViewer (org.eclipse.gef.ui.parts.ScrollingGraphicalViewer)2