/** {@inheritDoc} */ @Override protected Rectangle getRectangle() { Rectangle rectangle = super.getRectangle(); Category category = (Category) this.getModel(); ERDiagramEditPart rootEditPart = (ERDiagramEditPart) this.getRoot().getContents(); for (Object child : rootEditPart.getChildren()) { if (child instanceof NodeElementEditPart) { NodeElementEditPart editPart = (NodeElementEditPart) child; if (category.contains((NodeElement) editPart.getModel())) { Rectangle bounds = editPart.getFigure().getBounds(); if (bounds.x + bounds.width > rectangle.x + rectangle.width) { rectangle.width = bounds.x + bounds.width - rectangle.x; } if (bounds.y + bounds.height > rectangle.y + rectangle.height) { rectangle.height = bounds.y + bounds.height - rectangle.y; } if (rectangle.width != category.getWidth() || rectangle.height != category.getHeight()) { category.setLocation( new Location(category.getX(), category.getY(), rectangle.width, rectangle.height)); } } } } return rectangle; }
@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); }