@Override public void mouseDown(MouseEvent e, EditPartViewer viewer) { if (viewer.getContents() instanceof ERDiagramEditPart) { ERDiagramEditPart editPart = (ERDiagramEditPart) viewer.getContents(); ERDiagram diagram = (ERDiagram) editPart.getModel(); diagram.mousePoint = new Point(e.x, e.y); editPart.getFigure().translateToRelative(diagram.mousePoint); } super.mouseDown(e, viewer); }
/** * Computes actual grid specification (origin + single cell width and height) in the absolute * coordinate system. Note, in contrast to {@link #getRelativeGridSpec(EditPartViewer)} this * specification depends on the active zoom or scroll and can't be cached by clients. * * @param viewer * @return absolute grid specification, or <code>null</code> if grid is not enabled */ public static PrecisionRectangle getAbsoluteGridSpec(EditPartViewer viewer) { PrecisionRectangle spec = getRelativeGridSpec(viewer); if (spec != null) { GraphicalEditPart diagramEP = (GraphicalEditPart) viewer.getContents(); diagramEP.getContentPane().translateToAbsolute(spec); } return spec; }
/** * Always returns the same instance to avoid endless creation * * @return active grid specification in absolute coordinates or <code>null</code> if not enabled */ public PrecisionRectangle getAbsoluteGridSpec() { PrecisionRectangle result = getRelativeGridSpec(); if (result == null) { return null; } if (myAbsoluteGridSpec == null) { myAbsoluteGridSpec = new PrecisionRectangle(); } myAbsoluteGridSpec.setPreciseBounds( result.preciseX(), result.preciseY(), result.preciseWidth(), result.preciseHeight()); GraphicalEditPart diagramEP = (GraphicalEditPart) myViewer.getContents(); diagramEP.getContentPane().translateToAbsolute(myAbsoluteGridSpec); return myAbsoluteGridSpec; }