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 Jul 17, 2024
1 parent f3ec948 commit 7d5ef49
Show file tree
Hide file tree
Showing 2 changed files with 116 additions and 18 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 @@ -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.
*/
Expand All @@ -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.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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 <code>node</code>. The insets also considers its border.
* Return the top-left insets of the container of this <code>node</code>. The insets also considers its border (the
* size of the border).
*
* @param node
* The current node
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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.
Expand All @@ -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
Expand Down

0 comments on commit 7d5ef49

Please sign in to comment.