Search in sources :

Example 31 with Viewport

use of org.eclipse.draw2d.Viewport in project tdi-studio-se by Talend.

the class SearchZoneMapper method moveScrollBarZoneAtSelectedTableItem.

public void moveScrollBarZoneAtSelectedTableItem(Figure entry) {
    if (entry != null) {
        Rectangle bounds = entry.getBounds();
        int selection = bounds.y - 100;
        if (entry instanceof XmlmapTreeNodeFigure) {
            XmlmapTreeNodeFigure xmlMapTreeNodeFigure = (XmlmapTreeNodeFigure) entry;
            TreeNode treeNode = xmlMapTreeNodeFigure.getTreeNode();
            if (treeNode != null) {
                for (Adapter adapter : treeNode.eAdapters()) {
                    TreeNodeEditPart part = (TreeNodeEditPart) adapter;
                    XmlMapDataEditPart xmlMapDataEditPart = part.getMapDataEditPart();
                    if (adapter instanceof OutputTreeNodeEditPart) {
                        Viewport viewport = xmlMapDataEditPart.getOutputScroll().getViewport();
                        viewport.setViewLocation(viewport.getViewLocation().translate(bounds.x, selection));
                    } else if (adapter instanceof TreeNodeEditPart) {
                        Viewport viewport = xmlMapDataEditPart.getInputScroll().getViewport();
                        viewport.setViewLocation(viewport.getViewLocation().translate(bounds.x, selection));
                    }
                }
            }
        } else if (entry instanceof VarNodeFigure) {
            VarNodeFigure varNodeFigure = (VarNodeFigure) entry;
            VarNode varNode = varNodeFigure.getVarNode();
            if (varNode != null) {
                for (Adapter adapter : varNode.eAdapters()) {
                    VarNodeEditPart part = (VarNodeEditPart) adapter;
                    XmlMapDataEditPart xmlMapDataEditPart = part.getMapDataEditPart();
                    Viewport viewport = xmlMapDataEditPart.getVarScroll().getViewport();
                    viewport.setViewLocation(viewport.getViewLocation().translate(bounds.x, selection));
                }
            }
        }
    }
}
Also used : VarNode(org.talend.designer.xmlmap.model.emf.xmlmap.VarNode) VarNodeEditPart(org.talend.designer.xmlmap.parts.VarNodeEditPart) VarNodeFigure(org.talend.designer.xmlmap.figures.varnode.VarNodeFigure) OutputTreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.OutputTreeNode) TreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.TreeNode) Rectangle(org.eclipse.draw2d.geometry.Rectangle) Viewport(org.eclipse.draw2d.Viewport) Adapter(org.eclipse.emf.common.notify.Adapter) XmlmapTreeNodeFigure(org.talend.designer.xmlmap.figures.treeNode.XmlmapTreeNodeFigure) OutputTreeNodeEditPart(org.talend.designer.xmlmap.parts.OutputTreeNodeEditPart) XmlMapDataEditPart(org.talend.designer.xmlmap.parts.XmlMapDataEditPart) TreeNodeEditPart(org.talend.designer.xmlmap.parts.TreeNodeEditPart) OutputTreeNodeEditPart(org.talend.designer.xmlmap.parts.OutputTreeNodeEditPart)

Example 32 with Viewport

use of org.eclipse.draw2d.Viewport in project tdi-studio-se by Talend.

the class TableTreeEntityFigure method collapse.

public void collapse() {
    if (!expanded) {
        return;
    }
    IFigure root = this;
    Viewport port = null;
    Point viewportStart = null;
    while (root.getParent() != null) {
        if (root instanceof Viewport) {
            port = ((Viewport) root);
        }
        root = root.getParent();
        if (port != null) {
            break;
        }
    }
    viewportStart = port.getViewLocation();
    Point elementStart = getElement().getBounds().getLocation();
    setExpanded(false);
    root.validate();
    setExpanded(true);
    animationReset(getElementBounds());
    TreeAnimation.mark(getElement());
    TreeAnimation.captureLayout(getRoot());
    TreeAnimation.swap();
    TreeAnimation.trackLocation = elementStart;
    // root.validate();
    port.setViewLocation(viewportStart);
    while (TreeAnimation.step()) {
        getUpdateManager().performUpdate();
    }
    TreeAnimation.end();
    setExpanded(false);
}
Also used : Viewport(org.eclipse.draw2d.Viewport) Point(org.eclipse.draw2d.geometry.Point) IFigure(org.eclipse.draw2d.IFigure)

Example 33 with Viewport

use of org.eclipse.draw2d.Viewport in project dbeaver by dbeaver.

the class ERDOutlinePage method createControl.

/* (non-Javadoc)
     * @see org.eclipse.ui.part.IPage#createControl(org.eclipse.swt.widgets.Composite)
     */
@Override
public void createControl(Composite parent) {
    // create canvas and lws
    overview = new Canvas(parent, SWT.NONE);
    LightweightSystem lws = new LightweightSystem(overview);
    // create thumbnail
    thumbnail = new ScrollableThumbnail((Viewport) rootEditPart.getFigure());
    thumbnail.setBorder(new MarginBorder(3));
    thumbnail.setSource(rootEditPart.getLayer(LayerConstants.PRINTABLE_LAYERS));
    lws.setContents(thumbnail);
}
Also used : Canvas(org.eclipse.swt.widgets.Canvas) MarginBorder(org.eclipse.draw2d.MarginBorder) Viewport(org.eclipse.draw2d.Viewport) LightweightSystem(org.eclipse.draw2d.LightweightSystem) ScrollableThumbnail(org.eclipse.draw2d.parts.ScrollableThumbnail)

Example 34 with Viewport

use of org.eclipse.draw2d.Viewport in project knime-core by knime.

the class WorkflowEditor method getViewportCenterLocation.

/**
 * @return a location in the middle of the visible part of the editor. These
 *         are relative coordinates (to the current scrolling position)
 */
private Point getViewportCenterLocation() {
    FigureCanvas ctrl = ((FigureCanvas) getViewer().getControl());
    Viewport viewPort = ctrl.getViewport();
    Dimension viewSize = viewPort.getSize();
    int relX = viewSize.width / 2;
    int relY = viewSize.height / 2;
    Point nodeLoc = new Point(relX, relY);
    // make sure we have a free spot
    int stepX = getEditorSnapToGrid() ? getEditorGridXOffset(10) : 10;
    int stepY = getEditorSnapToGrid() ? getEditorGridYOffset(10) : 10;
    while (isNodeAtRel(nodeLoc)) {
        // move it a bit
        nodeLoc.x += stepX;
        nodeLoc.y += stepY;
    }
    return nodeLoc;
}
Also used : FigureCanvas(org.eclipse.draw2d.FigureCanvas) Viewport(org.eclipse.draw2d.Viewport) Dimension(org.eclipse.draw2d.geometry.Dimension) Point(org.eclipse.draw2d.geometry.Point) PrecisionPoint(org.eclipse.draw2d.geometry.PrecisionPoint) Point(org.eclipse.draw2d.geometry.Point) PrecisionPoint(org.eclipse.draw2d.geometry.PrecisionPoint)

Example 35 with Viewport

use of org.eclipse.draw2d.Viewport in project knime-core by knime.

the class AddMetaNodeWizard method createMetaNodeFromPorts.

private void createMetaNodeFromPorts(final PortType[] inPorts, final PortType[] outPorts, final String name) {
    Viewport viewPort = ((ScalableFreeformRootEditPart) m_wfEditor.getViewer().getRootEditPart()).getZoomManager().getViewport();
    // get the currently visible area
    Rectangle rect = viewPort.getClientArea();
    // translate it to absolute coordinates (with respect to the scrolled
    // editor viewer)
    viewPort.translateToAbsolute(rect.getLocation());
    // now we have an absolute point for the new metanode location
    org.eclipse.draw2d.geometry.Point location = new org.eclipse.draw2d.geometry.Point(rect.x + (rect.width / 2), rect.y + (rect.height / 2));
    // in order to get a local (relative position we have to substract the
    // invisible offset
    Point adaptedLoc = new Point(location.x - rect.x, location.y - rect.y);
    EditPart ep;
    // iterate until we have found a free place on the editor
    do {
        // we have to use the adaptedLoc (which is the relative position)
        ep = m_wfEditor.getViewer().findObjectAt(adaptedLoc);
        if (ep instanceof NodeContainerEditPart) {
            // offset the absolute location
            location.x += ((NodeContainerEditPart) ep).getFigure().getBounds().width;
            location.y += ((NodeContainerEditPart) ep).getFigure().getBounds().height;
            // offset the relative position
            adaptedLoc.x += ((NodeContainerEditPart) ep).getFigure().getBounds().width;
            adaptedLoc.y += ((NodeContainerEditPart) ep).getFigure().getBounds().height;
        }
    } while (ep instanceof NodeContainerEditPart);
    AddNewMetaNodeCommand cmd = new AddNewMetaNodeCommand(m_wfEditor.getWorkflowManager().get(), inPorts, outPorts, name, location);
    m_wfEditor.getViewer().getEditDomain().getCommandStack().execute(cmd);
}
Also used : NodeContainerEditPart(org.knime.workbench.editor2.editparts.NodeContainerEditPart) AddNewMetaNodeCommand(org.knime.workbench.editor2.commands.AddNewMetaNodeCommand) Point(org.eclipse.draw2d.geometry.Point) Viewport(org.eclipse.draw2d.Viewport) Rectangle(org.eclipse.draw2d.geometry.Rectangle) NodeContainerEditPart(org.knime.workbench.editor2.editparts.NodeContainerEditPart) ScalableFreeformRootEditPart(org.eclipse.gef.editparts.ScalableFreeformRootEditPart) EditPart(org.eclipse.gef.EditPart) Point(org.eclipse.draw2d.geometry.Point)

Aggregations

Viewport (org.eclipse.draw2d.Viewport)44 Point (org.eclipse.draw2d.geometry.Point)16 Rectangle (org.eclipse.draw2d.geometry.Rectangle)16 IFigure (org.eclipse.draw2d.IFigure)9 LightweightSystem (org.eclipse.draw2d.LightweightSystem)9 MarginBorder (org.eclipse.draw2d.MarginBorder)9 ScrollableThumbnail (org.eclipse.draw2d.parts.ScrollableThumbnail)9 Canvas (org.eclipse.swt.widgets.Canvas)9 Dimension (org.eclipse.draw2d.geometry.Dimension)7 ScalableFreeformRootEditPart (org.eclipse.gef.editparts.ScalableFreeformRootEditPart)6 Iterator (java.util.Iterator)4 FigureCanvas (org.eclipse.draw2d.FigureCanvas)4 ScrollPane (org.eclipse.draw2d.ScrollPane)4 LayeredPane (org.eclipse.draw2d.LayeredPane)3 RangeModel (org.eclipse.draw2d.RangeModel)3 PrecisionPoint (org.eclipse.draw2d.geometry.PrecisionPoint)3 GraphicalEditPart (org.eclipse.gef.GraphicalEditPart)3 RootEditPart (org.eclipse.gef.RootEditPart)3 Insets (org.eclipse.draw2d.geometry.Insets)2 EditPart (org.eclipse.gef.EditPart)2