Search in sources :

Example 21 with IFigure

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);
}
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)

Example 22 with IFigure

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

Example 23 with IFigure

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;
}
Also used : Point(org.eclipse.draw2d.geometry.Point) LookupConnectionPart(org.talend.designer.gefabstractmap.part.LookupConnectionPart) MapperTablePart(org.talend.designer.gefabstractmap.part.MapperTablePart) TableEntityFigure(org.talend.designer.gefabstractmap.figures.table.entity.TableEntityFigure) Point(org.eclipse.draw2d.geometry.Point) IFigure(org.eclipse.draw2d.IFigure) BaseConnectionEditPart(org.talend.designer.gefabstractmap.part.BaseConnectionEditPart) PolylineConnection(org.eclipse.draw2d.PolylineConnection)

Example 24 with IFigure

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

Example 25 with IFigure

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;
}
Also used : FilterContainer(org.talend.designer.gefabstractmap.figures.treesettings.FilterContainer) Point(org.eclipse.draw2d.geometry.Point) LookupConnectionPart(org.talend.designer.gefabstractmap.part.LookupConnectionPart) AbstractTableContainer(org.talend.designer.gefabstractmap.figures.table.AbstractTableContainer) Point(org.eclipse.draw2d.geometry.Point) IFigure(org.eclipse.draw2d.IFigure) BaseConnectionEditPart(org.talend.designer.gefabstractmap.part.BaseConnectionEditPart) PolylineConnection(org.eclipse.draw2d.PolylineConnection)

Aggregations

IFigure (org.eclipse.draw2d.IFigure)440 Rectangle (org.eclipse.draw2d.geometry.Rectangle)120 Point (org.eclipse.draw2d.geometry.Point)77 Dimension (org.eclipse.draw2d.geometry.Dimension)56 Figure (org.eclipse.draw2d.Figure)38 List (java.util.List)37 GraphicalEditPart (org.eclipse.gef.GraphicalEditPart)35 IWidgetPropertyChangeHandler (org.csstudio.opibuilder.properties.IWidgetPropertyChangeHandler)32 Graphics (org.eclipse.draw2d.Graphics)17 Iterator (java.util.Iterator)15 ArrayList (java.util.ArrayList)14 EditPart (org.eclipse.gef.EditPart)13 StackLayout (org.eclipse.draw2d.StackLayout)12 DefaultSizeNodeFigure (org.eclipse.gmf.runtime.gef.ui.figures.DefaultSizeNodeFigure)12 NodeFigure (org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure)12 Insets (org.eclipse.draw2d.geometry.Insets)11 INodeFigure (org.whole.lang.ui.figures.INodeFigure)11 MarginBorder (org.eclipse.draw2d.MarginBorder)10 ToolbarLayout (org.eclipse.draw2d.ToolbarLayout)10 AbstractGraphicalEditPart (org.eclipse.gef.editparts.AbstractGraphicalEditPart)10