Search in sources :

Example 1 with RenderedDiagramRootEditPart

use of org.eclipse.gmf.runtime.diagram.ui.render.editparts.RenderedDiagramRootEditPart in project elk by eclipse.

the class GmfDiagramLayoutConnector method applyLayout.

@Override
public void applyLayout(final LayoutMapping mapping, final IPropertyHolder settings) {
    boolean zoomToFit = settings.getProperty(CoreOptions.ZOOM_TO_FIT);
    IWorkbenchPart workbenchPart = mapping.getWorkbenchPart();
    int animationTime = calcAnimationTime(mapping, settings, workbenchPart != null && !workbenchPart.getSite().getPage().isPartVisible(workbenchPart));
    mapping.setProperty(ANIMATION_TIME, animationTime);
    Object layoutGraphObj = mapping.getParentElement();
    if (zoomToFit && layoutGraphObj instanceof EditPart) {
        // determine pre- or post-layout zoom
        DiagramEditPart diagramEditPart = GmfDiagramLayoutConnector.getDiagramEditPart((EditPart) layoutGraphObj);
        if (diagramEditPart == null) {
            applyLayout(mapping, animationTime);
            return;
        }
        ZoomManager zoomManager = ((RenderedDiagramRootEditPart) diagramEditPart.getRoot()).getZoomManager();
        ElkNode parentNode = mapping.getLayoutGraph();
        Dimension available = zoomManager.getViewport().getClientArea().getSize();
        double desiredWidth = parentNode.getWidth();
        double scaleX = Math.min(available.width / desiredWidth, zoomManager.getMaxZoom());
        double desiredHeight = parentNode.getHeight();
        double scaleY = Math.min(available.height / desiredHeight, zoomManager.getMaxZoom());
        final double scale = Math.min(scaleX, scaleY);
        final double oldScale = zoomManager.getZoom();
        if (scale < oldScale) {
            // we're zooming out, so do it before layout is applied
            zoomManager.setViewLocation(new Point(0, 0));
            zoomManager.setZoom(scale);
            zoomManager.setViewLocation(new Point(0, 0));
        }
        applyLayout(mapping, animationTime);
        if (scale > oldScale) {
            // we're zooming in, so do it after layout is applied
            zoomManager.setViewLocation(new Point(0, 0));
            zoomManager.setZoom(scale);
            zoomManager.setViewLocation(new Point(0, 0));
        }
    } else {
        applyLayout(mapping, animationTime);
    }
}
Also used : RenderedDiagramRootEditPart(org.eclipse.gmf.runtime.diagram.ui.render.editparts.RenderedDiagramRootEditPart) DiagramEditPart(org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramEditPart) ElkNode(org.eclipse.elk.graph.ElkNode) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) ZoomManager(org.eclipse.gef.editparts.ZoomManager) ResizableCompartmentEditPart(org.eclipse.gmf.runtime.diagram.ui.editparts.ResizableCompartmentEditPart) ShapeNodeEditPart(org.eclipse.gmf.runtime.diagram.ui.editparts.ShapeNodeEditPart) RootEditPart(org.eclipse.gef.RootEditPart) CompartmentEditPart(org.eclipse.gmf.runtime.diagram.ui.editparts.CompartmentEditPart) RenderedDiagramRootEditPart(org.eclipse.gmf.runtime.diagram.ui.render.editparts.RenderedDiagramRootEditPart) EditPart(org.eclipse.gef.EditPart) IGraphicalEditPart(org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart) AbstractBorderItemEditPart(org.eclipse.gmf.runtime.diagram.ui.editparts.AbstractBorderItemEditPart) LabelEditPart(org.eclipse.gmf.runtime.diagram.ui.editparts.LabelEditPart) ConnectionEditPart(org.eclipse.gmf.runtime.diagram.ui.editparts.ConnectionEditPart) DiagramEditPart(org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramEditPart) EObject(org.eclipse.emf.ecore.EObject) Dimension(org.eclipse.draw2d.geometry.Dimension) Point(org.eclipse.draw2d.geometry.Point) Point(org.eclipse.draw2d.geometry.Point)

Aggregations

Dimension (org.eclipse.draw2d.geometry.Dimension)1 Point (org.eclipse.draw2d.geometry.Point)1 ElkNode (org.eclipse.elk.graph.ElkNode)1 EObject (org.eclipse.emf.ecore.EObject)1 EditPart (org.eclipse.gef.EditPart)1 RootEditPart (org.eclipse.gef.RootEditPart)1 ZoomManager (org.eclipse.gef.editparts.ZoomManager)1 AbstractBorderItemEditPart (org.eclipse.gmf.runtime.diagram.ui.editparts.AbstractBorderItemEditPart)1 CompartmentEditPart (org.eclipse.gmf.runtime.diagram.ui.editparts.CompartmentEditPart)1 ConnectionEditPart (org.eclipse.gmf.runtime.diagram.ui.editparts.ConnectionEditPart)1 DiagramEditPart (org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramEditPart)1 IGraphicalEditPart (org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart)1 LabelEditPart (org.eclipse.gmf.runtime.diagram.ui.editparts.LabelEditPart)1 ResizableCompartmentEditPart (org.eclipse.gmf.runtime.diagram.ui.editparts.ResizableCompartmentEditPart)1 ShapeNodeEditPart (org.eclipse.gmf.runtime.diagram.ui.editparts.ShapeNodeEditPart)1 RenderedDiagramRootEditPart (org.eclipse.gmf.runtime.diagram.ui.render.editparts.RenderedDiagramRootEditPart)1 IWorkbenchPart (org.eclipse.ui.IWorkbenchPart)1