From 7d5ef49cce4bbced817e2b5db2251b580bb5fde4 Mon Sep 17 00:00:00 2001 From: Laurent Redor Date: Wed, 17 Jul 2024 15:46:24 +0200 Subject: [PATCH] [426] Handle vertical stack container Before this commit, this kind of container was not correctly handled. Bug: https://github.com/eclipse-sirius/sirius-desktop/issues/426 --- .../ui/business/api/query/ViewQuery.java | 35 +++++++ .../ui/internal/refresh/GMFHelper.java | 99 +++++++++++++++---- 2 files changed, 116 insertions(+), 18 deletions(-) diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/business/api/query/ViewQuery.java b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/business/api/query/ViewQuery.java index cbf7d6bdcd..ebb8b64ced 100644 --- a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/business/api/query/ViewQuery.java +++ b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/business/api/query/ViewQuery.java @@ -32,6 +32,7 @@ import org.eclipse.gmf.runtime.notation.Diagram; import org.eclipse.gmf.runtime.notation.JumpLinkStatus; import org.eclipse.gmf.runtime.notation.JumpLinkType; +import org.eclipse.gmf.runtime.notation.Node; import org.eclipse.gmf.runtime.notation.NotationPackage; import org.eclipse.gmf.runtime.notation.Shape; import org.eclipse.gmf.runtime.notation.Style; @@ -40,10 +41,12 @@ import org.eclipse.jface.preference.PreferenceConverter; import org.eclipse.sirius.diagram.DDiagram; import org.eclipse.sirius.diagram.DDiagramElement; +import org.eclipse.sirius.diagram.DDiagramElementContainer; import org.eclipse.sirius.diagram.LabelPosition; import org.eclipse.sirius.diagram.NodeStyle; import org.eclipse.sirius.diagram.business.api.query.ContainerMappingQuery; import org.eclipse.sirius.diagram.description.ContainerMapping; +import org.eclipse.sirius.diagram.model.business.internal.query.DDiagramElementContainerExperimentalQuery; import org.eclipse.sirius.diagram.tools.api.DiagramPlugin; import org.eclipse.sirius.diagram.tools.api.preferences.SiriusDiagramCorePreferences; import org.eclipse.sirius.diagram.ui.internal.edit.parts.DEdgeBeginNameEditPart; @@ -407,6 +410,15 @@ public boolean isListItem() { int type = SiriusVisualIDRegistry.getVisualID(this.view.getType()); return type == DNodeListElementEditPart.VISUAL_ID; } + + /** + * Return if this GMF node is a region. + */ + public boolean isRegion() { + return this.view.getElement() instanceof DDiagramElementContainer ddec // + && new DDiagramElementContainerExperimentalQuery(ddec).isRegion(); + } + /** * Return if this GMF node have vertical/horizontal stack layout. */ @@ -416,6 +428,29 @@ public boolean isRegionContainer() { && new ContainerMappingQuery(mapping).isRegionContainer(); } + /** + * Return if this GMF node have horizontal stack layout. + */ + public boolean isVerticalRegionContainer() { + return this.view.getElement() instanceof DDiagramElement element // + && element.getDiagramElementMapping() instanceof ContainerMapping mapping // + && new ContainerMappingQuery(mapping).isVerticalStackContainer(); + } + + /** + * Return if this GMF node is a compartment of a container having horizontal stack layout. + */ + public boolean isVerticalRegionContainerCompartment() { + if (isFreeFormCompartment()) { + if (view.eContainer() instanceof Node container) { + return new ViewQuery(container).isVerticalRegionContainer(); + } + + } + return false; + + } + /** * Return if this GMF node is associated to DNode Sirius diagram element. */ diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/internal/refresh/GMFHelper.java b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/internal/refresh/GMFHelper.java index b49ae8d82a..37f6cc9bab 100644 --- a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/internal/refresh/GMFHelper.java +++ b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/internal/refresh/GMFHelper.java @@ -186,8 +186,15 @@ public static Dimension getTopLeftInsets(Node container) { DDiagramElementContainer ddec = (DDiagramElementContainer) element; // RegionContainer do not have containers insets if (ddec instanceof DNodeContainer) { - if (new DNodeContainerExperimentalQuery((DNodeContainer) ddec).isRegionContainer() || hasFullLabelBorder(ddec)) { - result.setHeight(FREEFORM_CONTAINER_INSETS.top + getLabelSize(container) + AbstractDiagramElementContainerEditPart.DEFAULT_SPACING); + if (new DNodeContainerExperimentalQuery((DNodeContainer) ddec).isRegionContainer()) { + // TODO Replace by HStack INSETS + result.setHeight(LIST_CONTAINER_INSETS.top); + } else if (hasFullLabelBorder(ddec)) { + // result.setHeight(FREEFORM_CONTAINER_INSETS.top + getLabelSize(container) + + // AbstractDiagramElementContainerEditPart.DEFAULT_SPACING); + result.setHeight(FREEFORM_CONTAINER_INSETS.top); + } else if (new DDiagramElementContainerExperimentalQuery(ddec).isRegion()) { + // No margin } else { result.setWidth(FREEFORM_CONTAINER_INSETS.left); result.setHeight(FREEFORM_CONTAINER_INSETS.top); @@ -196,16 +203,19 @@ public static Dimension getTopLeftInsets(Node container) { result.setWidth(LIST_CONTAINER_INSETS.left); result.setHeight(LIST_CONTAINER_INSETS.top); } - Dimension borderSize = getBorderSize(ddec); - result.setWidth(result.width() + borderSize.width()); - result.setHeight(result.height() + borderSize.height()); + if (!new DDiagramElementContainerExperimentalQuery(ddec).isRegion()) { + Dimension borderSize = getBorderSize(ddec); + result.setWidth(result.width() + borderSize.width()); + result.setHeight(result.height() + borderSize.height()); + } } } return result; } /** - * Return the top-left insets of the container of this node. The insets also considers its border. + * Return the top-left insets of the container of this node. The insets also considers its border (the + * size of the border). * * @param node * The current node @@ -246,17 +256,28 @@ public static Dimension getBottomRightInsets(Node container) { DDiagramElementContainer ddec = (DDiagramElementContainer) element; // RegionContainer do not have containers insets if (ddec instanceof DNodeContainer) { - if (new DNodeContainerExperimentalQuery((DNodeContainer) ddec).isRegionContainer() || hasFullLabelBorder(ddec)) { - // TODO : Not sure about that, to verify - result.setHeight(FREEFORM_CONTAINER_INSETS.bottom); + if (new DNodeContainerExperimentalQuery((DNodeContainer) ddec).isRegionContainer()) { + result.setWidth(LIST_CONTAINER_INSETS.right); + result.setHeight(LIST_CONTAINER_INSETS.bottom); + // TODO: to verify + Dimension borderSize = getBorderSize(ddec); + result.setWidth(result.width() + borderSize.width()); + result.setHeight(result.height() + borderSize.height()); + } else if (new DDiagramElementContainerExperimentalQuery(ddec).isRegion()) { + // No margin } else { - result.setWidth(FREEFORM_CONTAINER_INSETS.right); - result.setHeight(FREEFORM_CONTAINER_INSETS.bottom); + if (hasFullLabelBorder(ddec)) { + // TODO : Not sure about that, to verify + result.setHeight(FREEFORM_CONTAINER_INSETS.bottom); + } else { + result.setWidth(FREEFORM_CONTAINER_INSETS.right); + result.setHeight(FREEFORM_CONTAINER_INSETS.bottom); + } + Dimension borderSize = getBorderSize(ddec); + // Added twice as this insets is used to compute the "global" size including the border + result.setWidth(result.width() + (borderSize.width() * 2)); + result.setHeight(result.height() + (borderSize.height() * 2)); } - Dimension borderSize = getBorderSize(ddec); - // Added twice as this insets is used to compute the "global" size including the border - result.setWidth(result.width() + (borderSize.width() * 2)); - result.setHeight(result.height() + (borderSize.height() * 2)); } else if (ddec instanceof DNodeList) { result.setWidth(LIST_CONTAINER_INSETS.right); result.setHeight(LIST_CONTAINER_INSETS.bottom); @@ -430,7 +451,18 @@ public static Point getLocation(Node node) { // org.eclipse.sirius.diagram.ui.internal.edit.parts.AbstractDNodeListCompartmentEditPart.createFigure() location.translate(4, 1); // Translate from the spacing (5 pixels) - location.translate(0, 5); + location.translate(0, AbstractDiagramElementContainerEditPart.DEFAULT_SPACING); + // or IContainerLabelOffsets.LABEL_OFFSET + } else if (new ViewQuery(node).isVerticalRegionContainerCompartment()) { + // Translate from the previous children (including title) + Point titleBottomRightCorner = getBottomRight((Node) node.eContainer(), node, false); + location.translate(0, titleBottomRightCorner.preciseY()); + // Add the corresponding margin of {1, 0, 0, 0} of + // org.eclipse.sirius.diagram.ui.edit.internal.part.DiagramContainerEditPartOperation.refreshBorder(AbstractDiagramElementContainerEditPart, + // ViewNodeContainerFigureDesc, ContainerStyle) + location.translate(0, 1); + // Translate from the spacing (5 pixels) + location.translate(0, AbstractDiagramElementContainerEditPart.DEFAULT_SPACING); } return location; } @@ -906,7 +938,7 @@ public static Point getBottomRight(Node container, Node childToStopTo, boolean c Node child = children.next(); if (child.equals(childToStopTo)) { stop = true; - if (containerViewQuery.isListCompartment()) { + if (containerViewQuery.isListCompartment() || containerViewQuery.isVerticalRegionContainerCompartment()) { if (bottom == 0) { // The bottom right is asked for the first list item of the list, add a one margin border over // it. @@ -925,7 +957,38 @@ public static Point getBottomRight(Node container, Node childToStopTo, boolean c // Translate from the title (previous children) bounds.translate(0, bottom); // Translate from the spacing (5 pixels) - bounds.translate(0, 5); + bounds.translate(0, AbstractDiagramElementContainerEditPart.DEFAULT_SPACING); + } else if (new ViewQuery(child).isVerticalRegionContainerCompartment()) { + // Add the corresponding margin of {1, 0, 0, 0} of + // org.eclipse.sirius.diagram.ui.edit.internal.part.DiagramContainerEditPartOperation.refreshBorder(AbstractDiagramElementContainerEditPart, + // ViewNodeContainerFigureDesc, ContainerStyle) + bounds.translate(0, 1); + // Translate from the title (previous children) + bounds.translate(0, bottom); + // Translate from the spacing (5 pixels) + bounds.translate(0, AbstractDiagramElementContainerEditPart.DEFAULT_SPACING); + } else if (containerViewQuery.isVerticalRegionContainerCompartment() && new ViewQuery(child).isFreeFormContainer()) { + if (bottom == 0) { + // This is the first region + // Add a one margin border over the first region + bounds.translate(0, 1); + } else { + // This is one of the following region + // Sometimes, we have not to translate from the previous children, as for region, the + // location is sometimes + // stored in the node. + boolean translateFromPreviousChildren = bounds.preciseY() == 0; + // TODO: Compute border size + int borderSize = 1; + // bounds.translate(0, Math.max(0, borderSize - 1) + IContainerLabelOffsets.LABEL_OFFSET); + bounds.translate(0, Math.max(0, borderSize - 1)); + // Sometimes, we have not to translate from the previous children, as for region, the + // location is sometimes + // stored in the node. + if (translateFromPreviousChildren) { + bounds.translate(0, bottom); + } + } } else if (containerViewQuery.isListCompartment()) { if (bottom == 0) { // Add a one margin border over the first list item