Skip to content

Commit

Permalink
[426] Handle List container and list items
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 6aafad1 commit 9f7b3ff
Show file tree
Hide file tree
Showing 4 changed files with 165 additions and 64 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
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2012, 2021 THALES GLOBAL SERVICES and others.
* Copyright (c) 2012, 2024 THALES GLOBAL SERVICES and others.
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
Expand Down Expand Up @@ -61,8 +61,11 @@
import org.eclipse.sirius.diagram.ui.internal.edit.parts.DNodeEditPart;
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.edit.parts.DNodeListElementEditPart;
import org.eclipse.sirius.diagram.ui.internal.edit.parts.DNodeListName2EditPart;
import org.eclipse.sirius.diagram.ui.internal.edit.parts.DNodeListNameEditPart;
import org.eclipse.sirius.diagram.ui.internal.edit.parts.DNodeListViewNodeListCompartment2EditPart;
import org.eclipse.sirius.diagram.ui.internal.edit.parts.DNodeListViewNodeListCompartmentEditPart;
import org.eclipse.sirius.diagram.ui.internal.edit.parts.NotationViewIDs;
import org.eclipse.sirius.diagram.ui.part.SiriusVisualIDRegistry;
import org.eclipse.sirius.diagram.ui.provider.DiagramUIPlugin;
Expand Down Expand Up @@ -380,6 +383,31 @@ public boolean isFreeFormCompartment() {
|| type == DNodeContainerViewNodeContainerCompartment2EditPart.VISUAL_ID;
}

/**
* Return if this GMF node is associated to DNodeList Sirius diagram element.
*/
public boolean isListContainer() {
int type = SiriusVisualIDRegistry.getVisualID(this.view.getType());
return type == DNodeListEditPart.VISUAL_ID || type == DNodeList2EditPart.VISUAL_ID;
}

/**
* Return if this GMF node is compartment of node corresponding to a Sirius list container.
*/
public boolean isListCompartment() {
int type = SiriusVisualIDRegistry.getVisualID(this.view.getType());
return type == DNodeListViewNodeListCompartmentEditPart.VISUAL_ID //
|| type == DNodeListViewNodeListCompartment2EditPart.VISUAL_ID;
}

/**
* Return if this GMF node is a list item.
*/
public boolean isListItem() {
int type = SiriusVisualIDRegistry.getVisualID(this.view.getType());
return type == DNodeListElementEditPart.VISUAL_ID;
}

/**
* Return if this GMF node have vertical/horizontal stack layout.
*/
Expand Down Expand Up @@ -416,7 +444,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 9f7b3ff

Please sign in to comment.