Skip to content

Commit

Permalink
[426] Handle vertical stack container
Browse files Browse the repository at this point in the history
Before this commit, this kind of container was not correctly handled.

Bug: #426
  • Loading branch information
lredor committed Sep 10, 2024
1 parent 9f7b3ff commit f65a8fa
Show file tree
Hide file tree
Showing 3 changed files with 126 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -408,6 +411,21 @@ public boolean isListItem() {
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 is contained in a vertical stack layout container.
*/
public boolean isVerticalRegion() {
return view.eContainer() instanceof View container && new ViewQuery(container).isVerticalRegionContainerCompartment();
}

/**
* Return if this GMF node have vertical/horizontal stack layout.
*/
Expand All @@ -417,6 +435,41 @@ public boolean isRegionContainer() {
&& new ContainerMappingQuery(mapping).isRegionContainer();
}

/**
* Return if this GMF node have vertical 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 vertical 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 a compartment of a container having an horizontal or a vertical stack layout.
*/
public boolean isRegionContainerCompartment() {
if (isFreeFormCompartment()) {
if (view.eContainer() instanceof Node container) {
return new ViewQuery(container).isRegionContainer();
}

}
return false;
}

/**
* Return if this GMF node is associated to DNode Sirius diagram element.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ public final class GMFHelper {

private static final Insets LIST_CONTAINER_INSETS = new Insets(4, 0, 0, 0);

private static final Insets HV_STACK_CONTAINER_INSETS = new Insets(4, 0, 0, 0);

/**
* The gap in pixels between the Label's icon and its text
* (org.eclipse.sirius.ext.gmf.runtime.gef.ui.figures.SiriusWrapLabel.getIconTextGap()).
Expand Down Expand Up @@ -163,7 +165,8 @@ public static Point getAbsoluteLocation(Node node, boolean insetsAware) {

Point location = new Point(0, 0);
LayoutConstraint layoutConstraint = node.getLayoutConstraint();
if (layoutConstraint instanceof Bounds) {
if (layoutConstraint instanceof Bounds && !(new ViewQuery(node).isRegion())) {
// The bounds is computed for horizontal or vertical regions, even if it is stored in GMF data
Bounds gmfBounds = (Bounds) layoutConstraint;
location.setX(gmfBounds.getX());
location.setY(gmfBounds.getY());
Expand Down Expand Up @@ -205,6 +208,27 @@ public static Point getAbsoluteLocation(Node node, boolean insetsAware) {
location.translate(previousChildBounds.preciseX(), previousChildBounds.preciseY() + previousChildBounds.preciseHeight());
}
}
} else if (viewQuery.isRegionContainerCompartment()) {
// Translate the compartment to be just below the the title, the x coordinate is also the same (same parent
// insets)
Rectangle titleBounds = getAbsoluteBounds(getPreviousChild(node), true);
location.translate(titleBounds.preciseX(), titleBounds.preciseY() + titleBounds.preciseHeight());
// Translate from the spacing (5 pixels)
location.translate(0, IContainerLabelOffsets.LABEL_OFFSET);
} else if (viewQuery.isVerticalRegion()) {
if (node.eContainer() instanceof Node container) {
if (container.getChildren().get(0) == node) {
Point parentNodeLocation = getAbsoluteLocation(container, insetsAware);
location.translate(parentNodeLocation);
if (insetsAware) {
translateWithInsets(location, node);
}
} else {
// Translate from the previous children
Rectangle previousChildBounds = getAbsoluteBounds(getPreviousChild(node), true);
location.translate(previousChildBounds.preciseX(), previousChildBounds.preciseY() + previousChildBounds.preciseHeight());
}
}
} else if (node.eContainer() instanceof Node container) {
Point parentNodeLocation = getAbsoluteLocation(container, insetsAware);
location.translate(parentNodeLocation);
Expand Down Expand Up @@ -252,8 +276,12 @@ 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 + getLabelDimension(container, new Dimension(50, 20)).width() + AbstractDiagramElementContainerEditPart.DEFAULT_SPACING);
if (new DNodeContainerExperimentalQuery((DNodeContainer) ddec).isRegionContainer()) {
result.setHeight(HV_STACK_CONTAINER_INSETS.top);
} else if (hasFullLabelBorder(ddec)) {
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);
Expand All @@ -262,15 +290,24 @@ 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());
}
}
} else if (nodeQuery.isListCompartment()) {
// Add the corresponding margin of {1, 4, 0, 4} of
// org.eclipse.sirius.diagram.ui.internal.edit.parts.AbstractDNodeListCompartmentEditPart.createFigure()
result.setWidth(4);
result.setHeight(1);
} else if (nodeQuery.isRegionContainerCompartment()) {
// Add the corresponding OneLineMarginBorder of {1, 0, 0, 0} corresponding to
// org.eclipse.sirius.diagram.ui.edit.internal.part.DiagramContainerEditPartOperation.refreshBorder(AbstractDiagramElementContainerEditPart,
// ViewNodeContainerFigureDesc, ContainerStyle)
// TODO : 1 should be replace by borderSize (style.getBorderSize().intValue())
result.setWidth(0);
result.setHeight(1);
}
return result;
}
Expand All @@ -292,7 +329,7 @@ public static Dimension getContainerTopLeftInsets(Node node, boolean searchFirst
if (nodeContainer instanceof Node) {
Node parentNode = (Node) nodeContainer;
NodeQuery nodeQuery = new NodeQuery(parentNode);
if (nodeQuery.isContainer() || nodeQuery.isListCompartment()) {
if (nodeQuery.isContainer() || nodeQuery.isListCompartment() || nodeQuery.isRegionContainerCompartment()) {
result = getTopLeftInsets(parentNode);
} else if (searchFirstParentContainer) {
result = getContainerTopLeftInsets(parentNode, searchFirstParentContainer);
Expand All @@ -318,17 +355,30 @@ private 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()) {
Dimension borderSize = getBorderSize(ddec);
result.setWidth(result.width() + borderSize.width());
result.setHeight(result.height() + borderSize.height());
} 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);
Expand Down Expand Up @@ -400,7 +450,7 @@ public static Dimension getBorderSize(DDiagramElementContainer ddec) {
result.setWidth(isFirstRegion(ddec) ? 0 : borderSize);
result.setHeight(1);
} else if (regionQuery.isRegionInVerticalStack()) {
result.setWidth(1);
result.setWidth(0);
result.setHeight(isFirstRegion(ddec) ? 1 : borderSize);
} else {
result.setWidth(borderSize);
Expand Down Expand Up @@ -809,7 +859,7 @@ private static void replaceAutoSize(Node node, PrecisionRectangle bounds, boolea
if (nodeQuery.isFreeFormCompartment() || nodeQuery.isListCompartment()) {
defaultSize = new Dimension(ResizableCompartmentFigure.MIN_CLIENT_DP, ResizableCompartmentFigure.MIN_CLIENT_DP);
if (node.getChildren().isEmpty()) {
if (nodeQuery.isListCompartment()) {
if (nodeQuery.isListCompartment() || nodeQuery.isVerticalRegionContainerCompartment()) {
// Add one margin border (even if empty)
defaultSize.expand(0, 1);
}
Expand Down Expand Up @@ -964,7 +1014,7 @@ private static Rectangle getChildrenBounds(Node container, boolean considerBorde
result = new PrecisionRectangle();
}
ViewQuery containerViewQuery = new ViewQuery(container);
if (containerViewQuery.isListContainer() || containerViewQuery.isListCompartment()) {
if (containerViewQuery.isListContainer() || containerViewQuery.isListCompartment() || containerViewQuery.isVerticalRegionContainerCompartment()) {
if (!container.getChildren().isEmpty()) {
Node lastChild = getLastChild(container, considerBorderNodes);
result = getAbsoluteBounds(lastChild, true, false, true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,21 +264,21 @@ private String getTextFor(IDiagramElementEditPart part) {
} else if (part instanceof AbstractDiagramContainerEditPart && ((AbstractDiagramContainerEditPart) part).isRegionContainer()) {
IGraphicalEditPart compartment = null;
for (IGraphicalEditPart child : Iterables.filter(part.getChildren(), IGraphicalEditPart.class)) {
sb.append("Children bounds:\n");
sb.append("Children bounds (" + child.getClass().getSimpleName() + "):\n");
appendBoundsDetails(child, sb);
compartment = child;
}

for (IGraphicalEditPart child2 : Iterables.filter(compartment.getChildren(), IGraphicalEditPart.class)) {
sb.append("Region bounds:\n");
sb.append("Region bounds (" + child2.getClass().getSimpleName() + "):\n");
appendBoundsDetails(child2, sb);
}
} else if (part instanceof AbstractDiagramElementContainerEditPart && ((AbstractDiagramElementContainerEditPart) part).isRegion()) {
IGraphicalEditPart parent = (IGraphicalEditPart) part.getParent();
sb.append("Compartment bounds:\n");
sb.append("Compartment bounds (" + parent.getClass().getSimpleName() + "):\n");
appendBoundsDetails(parent, sb);
parent = (IGraphicalEditPart) parent.getParent();
sb.append("Region Container bounds:\n");
sb.append("Region Container bounds (" + parent.getClass().getSimpleName() + "):\n");
appendBoundsDetails(parent, sb);
} else if (part instanceof InstanceRoleEditPart) {
LifelineEditPart lep = Iterables.filter(part.getChildren(), LifelineEditPart.class).iterator().next();
Expand Down

0 comments on commit f65a8fa

Please sign in to comment.