diff options
| author | Laurent Redor | 2014-11-17 15:59:33 +0000 |
|---|---|---|
| committer | Esteban DUGUEPEROUX | 2015-08-20 09:35:24 +0000 |
| commit | 1eaabec2459038849db9b35cea82a2be4dcb74f9 (patch) | |
| tree | d022d061f6f547879f6b8bae09419157712eafdf | |
| parent | edb7de4da37d98f2e36f2a5f713a315f17714292 (diff) | |
| download | org.eclipse.sirius-1eaabec2459038849db9b35cea82a2be4dcb74f9.tar.gz org.eclipse.sirius-1eaabec2459038849db9b35cea82a2be4dcb74f9.tar.xz org.eclipse.sirius-1eaabec2459038849db9b35cea82a2be4dcb74f9.zip | |
[475380] Cleanup of code before doing fix on this class.
Bug: 475380
Change-Id: Ifa455cea37105431620b4b3f79427ade6c0321d0
Signed-off-by: Laurent Redor <laurent.redor@obeo.fr>
| -rw-r--r-- | plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/layout/provider/BorderItemAwareLayoutProvider.java | 176 |
1 files changed, 64 insertions, 112 deletions
diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/layout/provider/BorderItemAwareLayoutProvider.java b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/layout/provider/BorderItemAwareLayoutProvider.java index 4886ffec1a..87dc18c98d 100644 --- a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/layout/provider/BorderItemAwareLayoutProvider.java +++ b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/layout/provider/BorderItemAwareLayoutProvider.java @@ -591,7 +591,8 @@ public class BorderItemAwareLayoutProvider extends AbstractLayoutProvider { resetBounds(compoundCommand, commandName, node, editingDomain); } - //Keep the GMF model consistent for pinned RegionContainer and Regions + // Keep the GMF model consistent for pinned RegionContainer + // and Regions if (graphicalEditPart instanceof IDiagramContainerEditPart && dDiagramElement instanceof DNodeContainer && new DNodeContainerExperimentalQuery((DNodeContainer) dDiagramElement).isRegionContainer()) { AbstractDNodeContainerCompartmentEditPart comp = Iterables.getFirst(Iterables.filter(graphicalEditPart.getChildren(), AbstractDNodeContainerCompartmentEditPart.class), null); @@ -661,10 +662,9 @@ public class BorderItemAwareLayoutProvider extends AbstractLayoutProvider { * * @param selectedObjects * The selected elements - * @param elementsToKeepFixed - * @param launchNormalArrange - * Tell if the normal arrange process will be called before the - * border item arrange + * @param nbIterations + * Number of made iterations. This number corresponds to the + * current iteration. * @param elementsToKeepFixed * IDiagramElementEditPart which are not actually pinned but have * to stay fixed @@ -740,11 +740,7 @@ public class BorderItemAwareLayoutProvider extends AbstractLayoutProvider { * Layout all the border items of this graphicalEditPart. * * @param graphicalEditPart - * The current element to deal with launchNormalArrange - * @param elementsToKeepFixed - * @param launchNormalArrange - * Tell if the normal arrange process will be called before the - * border item arrange + * The current element to deal with * @param elementsToKeepFixed * IDiagramElementEditPart which are not actually pinned but have * to stay fixed @@ -779,9 +775,6 @@ public class BorderItemAwareLayoutProvider extends AbstractLayoutProvider { * * @param borderedShapeEditPart * The current element to deal with - * @param launchNormalArrange - * Tell if the normal arrange process will be called before the - * border item arrange * @param elementsToKeepFixed * IDiagramElementEditPart which are not actually pinned but have * to stay fixed @@ -810,7 +803,8 @@ public class BorderItemAwareLayoutProvider extends AbstractLayoutProvider { // Use the center of the opposite element to determine the ray // (this ray is then use to determine the side on which to put - // the border node) + // the border node). Only the borderItemEditPart with only one + // edge are put in the headings map. final Map<IBorderItemEditPart, Vector> headings = new HashMap<IBorderItemEditPart, Vector>(); for (Object child : castedEditPart.getChildren()) { if (child instanceof IBorderItemEditPart) { @@ -828,10 +822,10 @@ public class BorderItemAwareLayoutProvider extends AbstractLayoutProvider { final double absoluteSin = Math.abs(BorderItemAwareLayoutProvider.sin(new Vector(Math.abs(containerCenterAfterArrangeAll.x - topLeft.x), Math.abs(containerCenterAfterArrangeAll.y - topLeft.y)))); - final List<IBorderItemEditPart> tops = getNorthBorderItems(headings, absoluteCos, scale, containerCenterAfterArrangeAll); - final List<IBorderItemEditPart> bottoms = getSouthBorderItems(headings, absoluteCos, scale, containerCenterAfterArrangeAll); - final List<IBorderItemEditPart> rights = getEastBorderItems(headings, absoluteSin, scale, containerCenterAfterArrangeAll); - final List<IBorderItemEditPart> lefts = getWestBorderItems(headings, absoluteSin, scale, containerCenterAfterArrangeAll); + final List<IBorderItemEditPart> tops = getBorderItems(PositionConstants.NORTH, headings, absoluteCos, scale, containerCenterAfterArrangeAll); + final List<IBorderItemEditPart> bottoms = getBorderItems(PositionConstants.SOUTH, headings, absoluteCos, scale, containerCenterAfterArrangeAll); + final List<IBorderItemEditPart> rights = getBorderItems(PositionConstants.EAST, headings, absoluteSin, scale, containerCenterAfterArrangeAll); + final List<IBorderItemEditPart> lefts = getBorderItems(PositionConstants.WEST, headings, absoluteSin, scale, containerCenterAfterArrangeAll); unfixLocator(tops); unfixLocator(bottoms); @@ -1046,131 +1040,89 @@ public class BorderItemAwareLayoutProvider extends AbstractLayoutProvider { } /** - * Returns the list of border items to be at the North position. This border - * items are sorted. To sort this element we compute again the rays with a - * new distant point to be more precise on the order. + * Returns the list of border items to be at the <code>side</code> position. + * These border items are sorted. To sort these element we compute again the + * rays with a new distant point to be more precise on the order. * + * @param side + * the side to retrieve border nodes on (PositionConstants.NORTH, + * PositionConstants.SOUTH, PositionConstants.WEST or + * PositionConstants.EAST). * @param headings * List of vector by border items - * @param containerAbsoluteCos - * The absolute cos of the container + * @param containerAbsoluteCosOrSin + * The absolute cos of the container if location is NORTH or + * SOUTH and sin of the container if location is WEST or EAST. * @param containerCenter * the center of the container of the border items - * @return the list of border items to be at the North position. + * @return the list of border items to be at the <code>side</code> position. */ - private List<IBorderItemEditPart> getNorthBorderItems(final Map<IBorderItemEditPart, Vector> headings, final double containerAbsoluteCos, double scale, final Point containerCenter) { + private List<IBorderItemEditPart> getBorderItems(int side, final Map<IBorderItemEditPart, Vector> headings, final double containerAbsoluteCosOrSin, double scale, final Point containerCenter) { final List<IBorderItemEditPart> parts = new LinkedList<IBorderItemEditPart>(); for (Map.Entry<IBorderItemEditPart, Vector> entry : headings.entrySet()) { final Vector ray = entry.getValue(); - if (ray.y != 0) { - - final double cos = BorderItemAwareLayoutProvider.cos(ray); - - if (Math.abs(cos) < containerAbsoluteCos && ray.y < 0) { + if (side == PositionConstants.NORTH || side == PositionConstants.SOUTH) { + if (isOnNorthOrSouth(side, containerAbsoluteCosOrSin, entry, ray)) { parts.add(entry.getKey()); } + } else if (isOnWestOrEast(side, containerAbsoluteCosOrSin, entry, ray)) { + parts.add(entry.getKey()); } } - final Map<IBorderItemEditPart, BorderItemOppositeElementData> oppositeElementsDataByEditPart = getOppositeElementsData(parts, scale); - Collections.sort(parts, new NorthCoordinateComparator(oppositeElementsDataByEditPart)); - - return parts; - - } - - /** - * Returns the list of border items to be at the South position. - * - * @param headings - * List of vector by border items - * @param containerAbsoluteCos - * The absolute cos of the container - * @return the list of border items to be at the South position. - */ - private List<IBorderItemEditPart> getSouthBorderItems(final Map<IBorderItemEditPart, Vector> headings, final double absoluteCos, double scale, final Point containerCenter) { - - final List<IBorderItemEditPart> parts = new LinkedList<IBorderItemEditPart>(); - - for (Map.Entry<IBorderItemEditPart, Vector> entry : headings.entrySet()) { - final Vector ray = entry.getValue(); - if (ray.y != 0) { - final double cos = BorderItemAwareLayoutProvider.cos(ray); - - if (Math.abs(cos) < absoluteCos && ray.y > 0) { - parts.add(entry.getKey()); - } + if (!parts.isEmpty()) { + final Map<IBorderItemEditPart, BorderItemOppositeElementData> oppositeElementsDataByEditPart = getOppositeElementsData(parts, scale); + if (side == PositionConstants.NORTH) { + Collections.sort(parts, new NorthCoordinateComparator(oppositeElementsDataByEditPart)); + } else if (side == PositionConstants.SOUTH) { + Collections.sort(parts, new SouthCoordinateComparator(oppositeElementsDataByEditPart)); + } else if (side == PositionConstants.WEST) { + Collections.sort(parts, new WestCoordinateComparator(oppositeElementsDataByEditPart)); + } else if (side == PositionConstants.EAST) { + Collections.sort(parts, new EastCoordinateComparator(oppositeElementsDataByEditPart)); } - } - final Map<IBorderItemEditPart, BorderItemOppositeElementData> oppositeElementsDataByEditPart = getOppositeElementsData(parts, scale); - Collections.sort(parts, new SouthCoordinateComparator(oppositeElementsDataByEditPart)); + } return parts; - } - /** - * Returns the list of border items to be at the East position. - * - * @param headings - * List of vector by border items - * @param containerAbsoluteSin - * The absolute sinus of the container - * @return the list of border items to be at the East position. - */ - private List<IBorderItemEditPart> getEastBorderItems(final Map<IBorderItemEditPart, Vector> headings, final double containerAbsoluteSin, double scale, final Point containerCenter) { - - final List<IBorderItemEditPart> parts = new LinkedList<IBorderItemEditPart>(); - - for (Map.Entry<IBorderItemEditPart, Vector> entry : headings.entrySet()) { - final Vector ray = entry.getValue(); + } - if (ray.x != 0) { - final double sin = BorderItemAwareLayoutProvider.sin(ray); + private boolean isOnNorthOrSouth(int side, final double containerAbsoluteCos, Map.Entry<IBorderItemEditPart, Vector> entry, final Vector ray) { + boolean result = false; + if (ray.y != 0) { + final double cos = BorderItemAwareLayoutProvider.cos(ray); - if (Math.abs(sin) < containerAbsoluteSin && ray.x > 0) { - parts.add(entry.getKey()); + if (Math.abs(cos) < containerAbsoluteCos) { + if (side == PositionConstants.NORTH) { + if (ray.y < 0) { + result = true; + } + } else if (ray.y > 0) { + result = true; } } - } - - final Map<IBorderItemEditPart, BorderItemOppositeElementData> targetPoints = getOppositeElementsData(parts, scale); - Collections.sort(parts, new EastCoordinateComparator(targetPoints)); - - return parts; + return result; } - /** - * Returns the list of border items to be at the West position. - * - * @param headings - * List of vector by border items - * @param containerAbsoluteSin - * The absolute sinus of the container - * @return the list of border items to be at the West position. - */ - private List<IBorderItemEditPart> getWestBorderItems(final Map<IBorderItemEditPart, Vector> headings, final double containerAbsoluteSin, double scale, final Point containerCenter) { - - final List<IBorderItemEditPart> parts = new LinkedList<IBorderItemEditPart>(); - - for (Map.Entry<IBorderItemEditPart, Vector> entry : headings.entrySet()) { - final Vector ray = entry.getValue(); - if (ray.x != 0) { - final double sin = BorderItemAwareLayoutProvider.sin(ray); - - if (Math.abs(sin) < containerAbsoluteSin && ray.x < 0) { - parts.add(entry.getKey()); + private boolean isOnWestOrEast(int side, final double containerAbsoluteSin, Map.Entry<IBorderItemEditPart, Vector> entry, final Vector ray) { + boolean result = false; + if (ray.x != 0) { + final double sin = BorderItemAwareLayoutProvider.sin(ray); + if (Math.abs(sin) < containerAbsoluteSin) { + if (side == PositionConstants.WEST) { + if (ray.x < 0) { + result = true; + } + } else if (ray.x > 0) { + result = true; } } } - - final Map<IBorderItemEditPart, BorderItemOppositeElementData> oppositeElementsDataByEditPart = getOppositeElementsData(parts, scale); - Collections.sort(parts, new WestCoordinateComparator(oppositeElementsDataByEditPart)); - - return parts; + return result; } /** |
