Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 320852

Summary: [EditPolicy] Refactoring of ConstrainedLayoutEditPolicy and XYLayoutEditPolicy to remove duplicate code and ensure consistency
Product: [Tools] GEF Reporter: Alexander Nyßen <nyssen>
Component: GEF-Legacy GEF (MVC)Assignee: Alexander Nyßen <nyssen>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3 Flags: nyssen: indigo+
Version: 3.7   
Target Milestone: 3.7.1 (Indigo) M2   
Hardware: All   
OS: All   
Whiteboard:
Bug Depends on:    
Bug Blocks: 67541    

Description Alexander Nyßen CLA 2010-07-25 14:21:01 EDT
ConstrainedLayoutEditPolicy and XYLayoutEditPolicy contain a lot of duplicate code, some TODO's, as well as an inconsistency w.r.t of calculating constraints for clone requests (in difference to getConstraintFor, which is used by ChangeBoundsRequest, getConstraintForClone misses a translateFromParent() call on the layout container). A refactoring is necessary.
Comment 1 Alexander Nyßen CLA 2010-07-25 14:40:24 EDT
Performed a major refactoring, which removes all todos and duplicate code and better aligns ConstrainedLayoutEditPolicy and XYLayoutEditPolicy. Ensured API remains consistent and backwards compatibility is achieved. Validated refactoring by manual testing with Logic Editor.

In detail, the following was changed:

- Introduced createAddCommand(ChangeBoundsRequest, EditPart, Object) to ConstrainedLayoutEditPolicy, which is now by default called by getAddCommand(EditPart) and delegates to createAddCommand(EditPart, Object). Removed overwritten getAddCommand(EditPart) within LogicXYLayoutEditPolicy, which performed just the same.

- Introduced translateToLayoutRelative to ConstrainedEditPolicy to comprise all duplicate code fragments that were related to this calculation procedure. It is now used from getConstraintFor(ChangeBoundsRequest, GraphicalEditPart) and getConstraintFor(CreateRequest). Fixed inconsistency within getConstraintForClone in this context as well, deprecated it, and made its single caller LogicXYLayoutEditPolicy use getConstraintFor instead.

- Introduced getChangeConstraintCommand method for clarity. It is used from within getResizeChildrenCommand (getMoveChildrenCommand and getAlignChildrenCommand still delegate to getResizeChildrenCommand only for purpose of backwards compatibility, but should be changed to delegate to getChangeConstraintCommand in future as well).

- Introduced new constructor to PrecisionRectangle, taking Point and Dimension, which is now used in getConstraintFor(CreateRequest). 

- Introduced getConstraintFor(Request, GraphicalEditPart, Rectangle), which is now directly called by getConstraintFor(ChangeBoundsRequest, GraphicalEditPart) and getConstraintFor(CreateRequest) and performs the delegation to getConstraintFor(Point) and getConstraintFor(Rectangle). Changed that XYLayoutEditPolicy overwrites this method to ensure that preferred sizes and minimum sizes are maintained, instead of overwriting getConstraintFor(ChangeBoundsRequest, GraphicalEditPart) directly. This way, calculation from superclass can be used and duplicate code could be removed. 

- Increased version number of org.eclipse.gef plug-in, org.eclipse.gef.examples.logic, as well as related features to 3.7.0.