Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[426] Improve GMFHelper.getAbsoluteBounds method #427

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2013, 2021 THALES GLOBAL SERVICES and others.
* Copyright (c) 2013, 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 All @@ -12,13 +12,14 @@
*******************************************************************************/
package org.eclipse.sirius.diagram.model.business.internal.query;

import java.util.Optional;

import org.eclipse.emf.ecore.EObject;
import org.eclipse.sirius.diagram.DDiagramElementContainer;
import org.eclipse.sirius.diagram.DNodeContainer;
import org.eclipse.sirius.diagram.FlatContainerStyle;
import org.eclipse.sirius.diagram.description.style.FlatContainerStyleDescription;
import org.eclipse.sirius.ext.base.Option;
import org.eclipse.sirius.ext.base.Options;
import org.eclipse.sirius.viewpoint.description.style.LabelBorderStyleDescription;
import org.eclipse.sirius.viewpoint.description.style.StyleDescription;

Expand Down Expand Up @@ -94,14 +95,14 @@ public boolean isRegionInVerticalStack() {
*
* @return an {@link Option} with the found label border style if it exists.
*/
public Option<LabelBorderStyleDescription> getLabelBorderStyle() {
public Optional<LabelBorderStyleDescription> getLabelBorderStyle() {
if (container.getStyle() instanceof FlatContainerStyle) {
StyleDescription description = container.getStyle().getDescription();
if (description instanceof FlatContainerStyleDescription) {
FlatContainerStyleDescription fcsd = (FlatContainerStyleDescription) description;
return Options.newSome(fcsd.getLabelBorderStyle());
return Optional.ofNullable(fcsd.getLabelBorderStyle());
}
}
return Options.newNone();
return Optional.empty();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public Range getVerticalRange() {
result = CacheHelper.getViewToRangeCache().get(node);
}
if (result == null) {
Rectangle absoluteBounds = GMFHelper.getAbsoluteBounds(node);
Rectangle absoluteBounds = GMFHelper.getAbsoluteBounds(node, false, false, false, true);
int y = absoluteBounds.y;
int height = absoluteBounds.height;
// GMFHelper.getAbsoluteBounds() use default
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ private void updateEdge(DEdge dEdge) {

private void computeEdgeDataWithoutEdgeLayoutData() {
Point firstClick = new Point(0, 0);
Rectangle sourceBounds = GMFHelper.getAbsoluteBounds((Node) source);
Rectangle sourceBounds = GMFHelper.getAbsoluteBounds((Node) source, false, false, false, true);
if (source.getElement() instanceof AbstractDNode) {
AbstractDNode sourceDNode = (AbstractDNode) source.getElement();
if (sourceDNode.eContainer() instanceof AbstractDNode) {
Expand Down Expand Up @@ -181,7 +181,7 @@ private void computeEdgeDataWithoutEdgeLayoutData() {
sourceTerminal = "(" + sourceRelativeLocation.preciseX() + "," + sourceRelativeLocation.preciseY() + ")"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$

Point secondClick = new Point(0, 0);
Rectangle targetBounds = GMFHelper.getAbsoluteBounds((Node) target);
Rectangle targetBounds = GMFHelper.getAbsoluteBounds((Node) target, false, false, false, true);

if (target.getElement() instanceof AbstractDNode) {
AbstractDNode targetDNode = (AbstractDNode) target.getElement();
Expand Down
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 Expand Up @@ -301,7 +274,7 @@ private Option<Rectangle> getParentBorder() {
* @return The rectangle used for handles
*/
public Rectangle getHandleBounds() {
return GMFHelper.getAbsoluteBounds(node, true, true);
return GMFHelper.getAbsoluteBounds(node, true, true, false, false);
}

/**
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 @@ -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 All @@ -61,8 +64,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 +386,46 @@ 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 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 @@ -389,6 +435,69 @@ 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 contained in an horizontal stack layout container.
*/
public boolean isHorizontalRegion() {
return view.eContainer() instanceof View container && new ViewQuery(container).isHorizontalRegionContainerCompartment();
}

/**
* Return if this GMF node have horizontal stack layout.
*/
public boolean isHorizontalRegionContainer() {
return this.view.getElement() instanceof DDiagramElement element //
&& element.getDiagramElementMapping() instanceof ContainerMapping mapping //
&& new ContainerMappingQuery(mapping).isHorizontalStackContainer();
}

/**
* Return if this GMF node is a compartment of a container having horizontal stack layout.
*/
public boolean isHorizontalRegionContainerCompartment() {
if (isFreeFormCompartment()) {
if (view.eContainer() instanceof Node container) {
return new ViewQuery(container).isHorizontalRegionContainer();
}
}
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 Expand Up @@ -416,7 +525,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
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2012, 2018 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 All @@ -12,6 +12,8 @@
*******************************************************************************/
package org.eclipse.sirius.diagram.ui.business.internal.command;

import java.util.Optional;

import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IProgressMonitor;
Expand All @@ -33,7 +35,6 @@
import org.eclipse.sirius.diagram.ui.internal.refresh.GMFHelper;
import org.eclipse.sirius.diagram.ui.provider.Messages;
import org.eclipse.sirius.diagram.ui.tools.internal.util.GMFNotationUtilities;
import org.eclipse.sirius.ext.base.Option;

/**
* Controls the movement of source and target edge anchor. Use to move vertical
Expand Down Expand Up @@ -92,8 +93,8 @@ protected void setComplementaryData(boolean sourceAnchorChanged, boolean targetA
} else {
// We are in reconnection (compute the sourceRefPoint using
// GMF model data)
Option<Rectangle> optionalSourceBounds = GMFHelper.getAbsoluteBounds(edge.getSource());
if (optionalSourceBounds.some()) {
Optional<Rectangle> optionalSourceBounds = GMFHelper.getAbsoluteBounds(edge.getSource());
if (optionalSourceBounds.isPresent()) {
sourceBounds = optionalSourceBounds.get();
}
}
Expand All @@ -117,8 +118,8 @@ protected void setComplementaryData(boolean sourceAnchorChanged, boolean targetA
} else {
// We are in reconnection (compute the sourceRefPoint using
// GMF model data)
Option<Rectangle> optionalTargetBounds = GMFHelper.getAbsoluteBounds(edge.getTarget());
if (optionalTargetBounds.some()) {
Optional<Rectangle> optionalTargetBounds = GMFHelper.getAbsoluteBounds(edge.getTarget());
if (optionalTargetBounds.isPresent()) {
targetBounds = optionalTargetBounds.get();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ private void avoidOverlaps(Diagram diagram) {
Location location = (Location) layoutConstraint;
constraint = new Rectangle(location.getX(), location.getY(), -1, -1);
}
Point parentAbsoluteLocation = GMFHelper.getAbsoluteLocation(parentNode);
Point parentAbsoluteLocation = GMFHelper.getAbsoluteLocation(parentNode, false, false);
constraint.translate(parentAbsoluteLocation.x, parentAbsoluteLocation.y);
final Point realLocation = borderItemLocator.getValidLocation(constraint, node, otherBorderedNodesToIgnore);
final Dimension d = realLocation.getDifference(parentAbsoluteLocation);
Expand Down Expand Up @@ -215,7 +215,7 @@ private void migrateGraphicalFiltersAndGMFBounds(Diagram diagram) {
LayoutConstraint layoutConstraint = node.getLayoutConstraint();
if (layoutConstraint instanceof Bounds) {
Bounds bounds = (Bounds) layoutConstraint;
Rectangle rectBounds = GMFHelper.getAbsoluteBounds(node);
Rectangle rectBounds = GMFHelper.getAbsoluteBounds(node, false, false, false, true);
// The GMF node size must be stored in collapse
// filter (to can set this size
// when this node is expanded).
Expand Down Expand Up @@ -287,6 +287,7 @@ private void migrateChildrenOfCollapsedNode(Diagram diagram) {
* </UL>
*/
private static class IsStandardDiagramPredicate implements Predicate<Diagram> {
@Override
public boolean apply(Diagram input) {
boolean apply = false;
if (input.getElement() instanceof DDiagram) {
Expand All @@ -311,6 +312,7 @@ public boolean apply(Diagram input) {
*/
private static class IsBorderedNodePredicate implements Predicate<Node> {

@Override
public boolean apply(Node input) {
// Is this node the main view of a DNode and a border
// node ?
Expand All @@ -327,6 +329,7 @@ public boolean apply(Node input) {
*/

private static class IsDirectlyCollapsedNodePredicate implements Predicate<Node> {
@Override
public boolean apply(Node input) {
boolean apply = false;

Expand Down
Loading