Search in sources :

Example 1 with AbstractTable

use of org.talend.designer.gefabstractmap.figures.table.AbstractTable in project tdi-studio-se by Talend.

the class MapperDropTargetListener method handleSashDrag.

protected void handleSashDrag(DropTargetEvent event, ISash s) {
    if (s instanceof SashSeparator) {
        SashSeparator separator = (SashSeparator) s;
        final Point dropLocation = getDropLocation();
        Rectangle leftBounds = separator.getLeftFigure().getBounds().getCopy();
        Rectangle rightBounds = separator.getRightFigure().getBounds().getCopy();
        if (dropLocation.x < (leftBounds.x + separator.getZoneMinSize() + separator.getSashWidth()) || dropLocation.x > (rightBounds.x + rightBounds.width - separator.getZoneMinSize() - separator.getSashWidth())) {
            event.detail = DND.DROP_NONE;
            return;
        }
        final LayoutManager layoutManager = separator.getParentFigure().getLayoutManager();
        if (layoutManager instanceof XmlMapDataLayout) {
            XmlMapDataLayout layout = (XmlMapDataLayout) layoutManager;
            int X = getDropLocation().x;
            final Rectangle separatorBounds = separator.getBounds().getCopy();
            separatorBounds.x = X;
            layout.setConstraint(separator, separatorBounds);
            // left figure width
            int wL = X - leftBounds.x;
            // right figure width
            int wR = rightBounds.getTopRight().x - X - separator.getSashWidth();
            int xR = X + separator.getSashWidth();
            if (wL < separator.getZoneMinSize()) {
                wL = separator.getZoneMinSize();
                wR = rightBounds.getTopRight().x - leftBounds.x - separator.getZoneMinSize() - separator.getSashWidth();
                xR = leftBounds.x + separator.getZoneMinSize() + separator.getSashWidth();
            }
            if (wR < separator.getZoneMinSize()) {
                wL = rightBounds.getTopRight().x - separator.getZoneMinSize() - separator.getSashWidth() - leftBounds.x;
                wR = separator.getZoneMinSize();
                xR = rightBounds.getTopRight().x - separator.getZoneMinSize();
            }
            leftBounds.width = wL;
            layout.setConstraint(separator.getLeftFigure(), leftBounds.getCopy());
            separator.getLeftFigure().invalidateTree();
            rightBounds.x = xR;
            rightBounds.width = wR;
            layout.setConstraint(separator.getRightFigure(), rightBounds.getCopy());
            separator.getRightFigure().invalidateTree();
            separator.getParentFigure().revalidate();
        }
    } else if (s instanceof ColumnSash) {
        ColumnSash columnSash = (ColumnSash) s;
        ITable t = columnSash.getTable();
        // if (t instanceof AbstractTable) {
        // AbstractTable table = (AbstractTable) t;
        // Rectangle tableBounds = table.getBounds();
        // int X = getDropLocation().x;
        // if (X < tableBounds.x + columnSash.getSashWidth()
        // || X > tableBounds.x + tableBounds.width - columnSash.getSashWidth()) {
        // event.detail = DND.DROP_NONE;
        // return;
        // }
        //
        // double newExpressionWidth = X - tableBounds.x;
        //
        // double defaultExpressionWidth = table.getDefaultExpressionWidth();
        // double pecnetage = newExpressionWidth / defaultExpressionWidth;
        // table.setExpressWidthPecentage(pecnetage);
        // } else if (t instanceof Table) {
        AbstractTable table = (AbstractTable) t;
        Rectangle tableBounds = table.getBounds();
        int X = getDropLocation().x;
        if (X < tableBounds.x + 10 || X > tableBounds.x + tableBounds.width - 10) {
            event.detail = DND.DROP_NONE;
            return;
        }
        TableColumn leftColumn = columnSash.getLeftColumn();
        TableColumn rightColumn = columnSash.getRightColumn();
        Rectangle leftBounds = leftColumn.getBounds();
        Rectangle rightBounds = rightColumn.getBounds();
        int LW = X - leftBounds.x;
        int RW = rightBounds.x + rightBounds.width - X;
        if (LW < 10) {
            LW = 10;
        }
        if (RW < 10) {
            RW = 10;
        }
        double LP = (double) LW / (double) tableBounds.width;
        double RP = (double) RW / (double) tableBounds.width;
        table.getLayoutManager().setColumnPercentage(leftColumn.getColumnKey(), LP);
        table.getLayoutManager().setColumnPercentage(rightColumn.getColumnKey(), RP);
        table.invalidateTree();
        table.revalidate();
    }
// }
}
Also used : AbstractTable(org.talend.designer.gefabstractmap.figures.table.AbstractTable) XmlMapDataLayout(org.talend.designer.gefabstractmap.figures.layout.XmlMapDataLayout) LayoutManager(org.eclipse.draw2d.LayoutManager) Rectangle(org.eclipse.draw2d.geometry.Rectangle) SashSeparator(org.talend.designer.gefabstractmap.figures.sash.SashSeparator) ITable(org.talend.designer.gefabstractmap.figures.table.ITable) Point(org.eclipse.draw2d.geometry.Point) ColumnSash(org.talend.designer.gefabstractmap.figures.table.ColumnSash) TableColumn(org.talend.designer.gefabstractmap.figures.table.TableColumn) Point(org.eclipse.draw2d.geometry.Point)

Example 2 with AbstractTable

use of org.talend.designer.gefabstractmap.figures.table.AbstractTable 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)

Aggregations

Rectangle (org.eclipse.draw2d.geometry.Rectangle)2 AbstractTable (org.talend.designer.gefabstractmap.figures.table.AbstractTable)2 List (java.util.List)1 IFigure (org.eclipse.draw2d.IFigure)1 LayoutManager (org.eclipse.draw2d.LayoutManager)1 ScrollPane (org.eclipse.draw2d.ScrollPane)1 Dimension (org.eclipse.draw2d.geometry.Dimension)1 Point (org.eclipse.draw2d.geometry.Point)1 XmlMapDataLayout (org.talend.designer.gefabstractmap.figures.layout.XmlMapDataLayout)1 SashSeparator (org.talend.designer.gefabstractmap.figures.sash.SashSeparator)1 AbstractGlobalMapContainer (org.talend.designer.gefabstractmap.figures.table.AbstractGlobalMapContainer)1 ColumnSash (org.talend.designer.gefabstractmap.figures.table.ColumnSash)1 ITable (org.talend.designer.gefabstractmap.figures.table.ITable)1 TableColumn (org.talend.designer.gefabstractmap.figures.table.TableColumn)1 AbstractTreeSettingContainer (org.talend.designer.gefabstractmap.figures.treesettings.AbstractTreeSettingContainer)1 FilterContainer (org.talend.designer.gefabstractmap.figures.treesettings.FilterContainer)1