Search in sources :

Example 1 with SashSeparator

use of org.talend.designer.gefabstractmap.figures.sash.SashSeparator 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 SashSeparator

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

the class MapperRootEditPart method createFigure.

@Override
protected IFigure createFigure() {
    Figure mainFigure = new Figure();
    XmlMapDataLayout manager2 = new XmlMapDataLayout(getRootModelManager().getGraphicalViewer());
    mainFigure.setLayoutManager(manager2);
    // input
    Figure inputZone = new Figure();
    inputZone.setLayoutManager(new ZoneLayout());
    inputToolBar = createInputZoneToolBar();
    inputToolBar.setBorder(new LineBorder(ColorProviderMapper.getColor(ColorInfo.COLOR_TREE_BORDER)));
    inputZone.add(inputToolBar);
    inputScroll = new ScrollPane();
    inputScroll.setHorizontalScrollBarVisibility(ScrollPane.NEVER);
    leftFigure = new Figure();
    // ToolbarLayout subManager = new ToolbarLayout();
    ToolbarLayout subManager = createZoneContentLayout();
    subManager.setSpacing(20);
    subManager.setVertical(true);
    leftFigure.setLayoutManager(subManager);
    leftFigure.setBorder(new MarginBorder(20, 40, 20, 40));
    inputScroll.getViewport().setContents(leftFigure);
    inputScroll.getViewport().setContentsTracksWidth(true);
    inputZone.add(inputScroll);
    mainFigure.add(inputZone);
    // separator 1
    SashSeparator separatorLeft = new SashSeparator();
    separatorLeft.setImage(ImageProviderMapper.getImage(ImageInfo.ZONE_SASH));
    mainFigure.add(separatorLeft);
    // search , var
    searchToolBar = createSearchZoneToolBar();
    searchToolBar.setBorder(new LineBorder(ColorProviderMapper.getColor(ColorInfo.COLOR_TREE_BORDER)));
    varScroll = new ScrollPane();
    varScroll.setHorizontalScrollBarVisibility(ScrollPane.NEVER);
    centerFigure = new Figure();
    subManager = createZoneContentLayout();
    subManager.setSpacing(20);
    subManager.setVertical(true);
    centerFigure.setLayoutManager(subManager);
    centerFigure.setBorder(new MarginBorder(10, 40, 10, 40));
    varScroll.getViewport().setContents(centerFigure);
    varScroll.getViewport().setContentsTracksWidth(true);
    centerFigure.add(searchToolBar);
    mainFigure.add(varScroll);
    // separetor 2
    SashSeparator separatorRight = new SashSeparator();
    separatorRight.setImage(ImageProviderMapper.getImage(ImageInfo.ZONE_SASH));
    mainFigure.add(separatorRight);
    // output
    Figure outputZone = new Figure();
    outputZone.setLayoutManager(new ZoneLayout());
    outputToolBar = createOutputZoneToolBar();
    outputToolBar.setBorder(new LineBorder(ColorProviderMapper.getColor(ColorInfo.COLOR_TREE_BORDER)));
    outputZone.add(outputToolBar);
    outputScroll = new ScrollPane();
    outputScroll.setHorizontalScrollBarVisibility(ScrollPane.NEVER);
    rightFigure = new Figure();
    subManager = createZoneContentLayout();
    subManager.setSpacing(20);
    subManager.setVertical(true);
    rightFigure.setLayoutManager(subManager);
    rightFigure.setBorder(new MarginBorder(20, 40, 20, 40));
    outputScroll.getViewport().setContents(rightFigure);
    outputScroll.getViewport().setContentsTracksWidth(true);
    outputZone.add(outputScroll);
    mainFigure.add(outputZone);
    mainFigure.setOpaque(true);
    mainFigure.setBackgroundColor(ColorProviderMapper.getColor(ColorInfo.COLOR_BACKGROUND_LINKS_ZONE));
    separatorLeft.setLeftFigure(inputZone);
    separatorLeft.setRightFigure(varScroll);
    separatorLeft.setParentFigure(mainFigure);
    separatorRight.setLeftFigure(varScroll);
    separatorRight.setRightFigure(outputZone);
    separatorRight.setParentFigure(mainFigure);
    return mainFigure;
}
Also used : ToolbarLayout(org.eclipse.draw2d.ToolbarLayout) XmlMapDataLayout(org.talend.designer.gefabstractmap.figures.layout.XmlMapDataLayout) ScrollPane(org.eclipse.draw2d.ScrollPane) LineBorder(org.eclipse.draw2d.LineBorder) MarginBorder(org.eclipse.draw2d.MarginBorder) SashSeparator(org.talend.designer.gefabstractmap.figures.sash.SashSeparator) IFigure(org.eclipse.draw2d.IFigure) Figure(org.eclipse.draw2d.Figure)

Example 3 with SashSeparator

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

the class XmlMapDataLayout method layout.

/*
     * (non-Javadoc)
     * 
     * @see org.eclipse.draw2d.LayoutManager#layout(org.eclipse.draw2d.IFigure)
     */
@Override
public void layout(IFigure parent) {
    List children = parent.getChildren();
    int numChildren = children.size();
    org.eclipse.swt.graphics.Point avilableSize = viewer.getControl().getSize();
    double shrinkWidth = 1;
    if (previousAvilableSize != null && previousAvilableSize != avilableSize) {
        shrinkWidth = (double) avilableSize.x / (double) previousAvilableSize.x;
        previousAvilableSize = avilableSize;
    } else {
        previousAvilableSize = avilableSize;
    }
    // get the number of separators and the total width, the width of separator for zone is fixed
    int separatorWith = 0;
    int separatorNum = 0;
    for (int i = 0; i < numChildren; i++) {
        IFigure child = (IFigure) children.get(i);
        if (child instanceof SashSeparator) {
            separatorNum++;
            SashSeparator separator = (SashSeparator) child;
            separatorWith = separatorWith + separator.getSashWidth();
        }
    }
    zoneWidth = (avilableSize.x - separatorWith) / (numChildren - separatorNum);
    // zoneWidth = (avilableSize.x - separatorWith - 1) / (numChildren - separatorNum);
    Rectangle clientArea = parent.getClientArea();
    int x = clientArea.x;
    int y = clientArea.y;
    Point offset = parent.getClientArea().getLocation();
    int toltalWidth = 0;
    for (int i = 0; i < numChildren; i++) {
        IFigure f = (IFigure) children.get(i);
        Rectangle bounds = (Rectangle) getConstraint(f);
        if (bounds == null) {
            Rectangle newBounds = null;
            if (f instanceof SashSeparator) {
                SashSeparator separator = (SashSeparator) f;
                newBounds = new Rectangle(x, y, separator.getSashWidth(), avilableSize.y);
                f.setBounds(newBounds);
                x = x + separator.getSashWidth();
            } else {
                newBounds = new Rectangle(x, y, zoneWidth, avilableSize.y);
                f.setBounds(newBounds);
                x = x + zoneWidth;
            }
            setConstraint(f, newBounds);
            continue;
        }
        bounds = bounds.getCopy();
        // avialable size changed.
        if (shrinkWidth != 1) {
            bounds.x = x;
            if (!(f instanceof SashSeparator)) {
                int w = (int) Math.floor(bounds.width * shrinkWidth);
                bounds.width = w;
            }
            x = x + bounds.width;
        }
        if (bounds.width == -1 || bounds.height == -1) {
            Dimension preferredSize = f.getPreferredSize(bounds.width, bounds.height);
            bounds = bounds.getCopy();
            if (bounds.width == -1) {
                bounds.width = preferredSize.width;
            }
            if (bounds.height == -1) {
                bounds.height = preferredSize.height;
            }
        }
        bounds = bounds.getTranslated(offset);
        bounds.height = avilableSize.y;
        toltalWidth = toltalWidth + bounds.width;
        f.setBounds(bounds);
        setConstraint(f, bounds);
    }
    // in case some blank width
    if (toltalWidth != 0) {
        int diff = avilableSize.x - toltalWidth;
        if (diff < 0) {
            diff = 0;
        }
        int avg = diff / (numChildren - separatorNum);
        int remainder = diff % (numChildren - separatorNum);
        if (avg != 0) {
            x = clientArea.x;
            for (int i = 0; i < numChildren; i++) {
                IFigure f = (IFigure) children.get(i);
                Rectangle bounds = f.getBounds();
                bounds.x = x;
                if (!(f instanceof SashSeparator)) {
                    bounds.width = bounds.width + avg;
                }
                f.setBounds(bounds);
                x = x + bounds.width;
            }
        }
        if (remainder != 0) {
            IFigure lastChild = (IFigure) children.get(children.size() - 1);
            final Rectangle bounds = lastChild.getBounds();
            bounds.width = bounds.width + remainder;
            lastChild.setBounds(bounds);
        }
    }
}
Also used : Rectangle(org.eclipse.draw2d.geometry.Rectangle) List(java.util.List) SashSeparator(org.talend.designer.gefabstractmap.figures.sash.SashSeparator) Point(org.eclipse.draw2d.geometry.Point) Dimension(org.eclipse.draw2d.geometry.Dimension) Point(org.eclipse.draw2d.geometry.Point) IFigure(org.eclipse.draw2d.IFigure)

Aggregations

SashSeparator (org.talend.designer.gefabstractmap.figures.sash.SashSeparator)3 IFigure (org.eclipse.draw2d.IFigure)2 Point (org.eclipse.draw2d.geometry.Point)2 Rectangle (org.eclipse.draw2d.geometry.Rectangle)2 XmlMapDataLayout (org.talend.designer.gefabstractmap.figures.layout.XmlMapDataLayout)2 List (java.util.List)1 Figure (org.eclipse.draw2d.Figure)1 LayoutManager (org.eclipse.draw2d.LayoutManager)1 LineBorder (org.eclipse.draw2d.LineBorder)1 MarginBorder (org.eclipse.draw2d.MarginBorder)1 ScrollPane (org.eclipse.draw2d.ScrollPane)1 ToolbarLayout (org.eclipse.draw2d.ToolbarLayout)1 Dimension (org.eclipse.draw2d.geometry.Dimension)1 AbstractTable (org.talend.designer.gefabstractmap.figures.table.AbstractTable)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