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 26, 2024
1 parent ba99866 commit cea7cf9
Show file tree
Hide file tree
Showing 4 changed files with 183 additions and 90 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,7 @@
import org.eclipse.sirius.diagram.business.api.query.DDiagramElementQuery;
import org.eclipse.sirius.diagram.business.api.query.DNodeQuery;
import org.eclipse.sirius.diagram.ui.edit.internal.part.PortLayoutHelper;
import org.eclipse.sirius.diagram.ui.internal.edit.parts.DNode2EditPart;
import org.eclipse.sirius.diagram.ui.internal.edit.parts.DNode4EditPart;
import org.eclipse.sirius.diagram.ui.internal.edit.parts.DNodeContainer2EditPart;
import org.eclipse.sirius.diagram.ui.internal.edit.parts.DNodeContainerEditPart;
import org.eclipse.sirius.diagram.ui.internal.edit.parts.DNodeList2EditPart;
import org.eclipse.sirius.diagram.ui.internal.edit.parts.DNodeListEditPart;
import org.eclipse.sirius.diagram.ui.internal.refresh.GMFHelper;
import org.eclipse.sirius.diagram.ui.part.SiriusVisualIDRegistry;
import org.eclipse.sirius.diagram.ui.tools.api.layout.LayoutUtils;
import org.eclipse.sirius.ext.base.Option;
import org.eclipse.sirius.ext.base.Options;
Expand All @@ -51,7 +44,7 @@
*
* @author lredor
*/
public class NodeQuery {
public class NodeQuery extends ViewQuery {

private Node node;

Expand All @@ -62,6 +55,7 @@ public class NodeQuery {
* the starting point.
*/
public NodeQuery(Node node) {
super(node);
this.node = node;
}

Expand Down Expand Up @@ -166,33 +160,12 @@ protected Dimension getDefaultDim(DDiagramElement element) {
return dim;
}

/**
* Tests whether the queried Node corresponds to a bordered node.
*
* @return <code>true</code> if the queried View corresponds to a bordered node.
*/
public boolean isBorderedNode() {
int type = SiriusVisualIDRegistry.getVisualID(this.node.getType());
boolean result = type == DNode2EditPart.VISUAL_ID || type == DNode4EditPart.VISUAL_ID;
return result;
}

/**
* Tests whether the queried Node corresponds to a container (list or not).
*
* @return <code>true</code> if the queried View corresponds to a container node.
*/
public boolean isContainer() {
int type = SiriusVisualIDRegistry.getVisualID(this.node.getType());
boolean result = type == DNodeContainer2EditPart.VISUAL_ID || type == DNodeContainerEditPart.VISUAL_ID || type == DNodeList2EditPart.VISUAL_ID || type == DNodeListEditPart.VISUAL_ID;
return result;
}

/**
* Return the compartment of the GMF node container with "free form" layout.
*
* @return the compartment or Optional.empty if view is not container or compartment not found
*/
@Override
public Optional<Node> getFreeFormContainerCompartment() {
if (new ViewQuery(this.node).isFreeFormContainer()) {
List<View> children = this.node.getChildren();
Expand Down
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,22 @@ 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 is contained in an 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 @@ -416,6 +435,29 @@ 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 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 Expand Up @@ -443,7 +485,7 @@ public boolean isNodeLabel() {
*
* @return the compartment or Optional.empty if view is not container or compartment not found
*/
public Optional<View> getFreeFormContainerCompartment() {
public Optional<? extends View> getFreeFormContainerCompartment() {
if (this.isFreeFormContainer()) {
List<View> children = this.view.getChildren();
return children.stream() //
Expand Down
Loading

0 comments on commit cea7cf9

Please sign in to comment.