diff --git a/plugins/org.eclipse.sirius.diagram.sequence.ui/src/org/eclipse/sirius/diagram/sequence/ui/tool/internal/edit/policy/SequenceContainerCreationPolicy.java b/plugins/org.eclipse.sirius.diagram.sequence.ui/src/org/eclipse/sirius/diagram/sequence/ui/tool/internal/edit/policy/SequenceContainerCreationPolicy.java index 3972dcf652..9b9eea3731 100644 --- a/plugins/org.eclipse.sirius.diagram.sequence.ui/src/org/eclipse/sirius/diagram/sequence/ui/tool/internal/edit/policy/SequenceContainerCreationPolicy.java +++ b/plugins/org.eclipse.sirius.diagram.sequence.ui/src/org/eclipse/sirius/diagram/sequence/ui/tool/internal/edit/policy/SequenceContainerCreationPolicy.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2010, 2021 THALES GLOBAL SERVICES and others. + * Copyright (c) 2010, 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 @@ -101,7 +101,7 @@ protected Command getCreateNodeOnDiagramCommand(CreateRequest request, NodeCreat finishingEndEndPredecessor = SequenceGraphicalHelper.getEndBefore(diag, location.y + size.height); } - CreationUtil creationUtil = new CreationUtil(request, getDiagramCommandFactory(startingEndPredecessor, finishingEndEndPredecessor, location), getRealLocation(request), request.getSize(), + CreationUtil creationUtil = new CreationUtil(getDiagramCommandFactory(startingEndPredecessor, finishingEndEndPredecessor, location), getRealLocation(request), request.getSize(), getHost()); result = creationUtil.getNodeCreationCommand(diagram, tool); } else if (tool instanceof InstanceRoleCreationTool && diagram instanceof SequenceDDiagram) { @@ -110,7 +110,7 @@ protected Command getCreateNodeOnDiagramCommand(CreateRequest request, NodeCreat GraphicalHelper.screen2logical(location, (IGraphicalEditPart) getHost()); EObject predecessor = SequenceGraphicalHelper.getInstanceRoleBefore(diag, location.x); - CreationUtil creationUtil = new CreationUtil(request, getDiagramCommandFactory(predecessor, location), getRealLocation(request), request.getSize(), getHost()); + CreationUtil creationUtil = new CreationUtil(getDiagramCommandFactory(predecessor, location), getRealLocation(request), request.getSize(), getHost()); result = creationUtil.getNodeCreationCommand(diagram, tool); } else { result = super.getCreateNodeOnDiagramCommand(request, tool, diagram); @@ -140,7 +140,7 @@ protected Command getCreateContainerOnDiagramCommand(CreateRequest request, Cont List coverage = creationValidator.getCoverage(); Range expansionZone = creationValidator.getExpansionZone(); - CreationUtil creationUtil = new CreationUtil(request, getDiagramCommandFactory(startingEndPredecessor, finishingEndPredecessor, coverage, getCreationRange(request)), + CreationUtil creationUtil = new CreationUtil(getDiagramCommandFactory(startingEndPredecessor, finishingEndPredecessor, coverage, getCreationRange(request)), getRealLocation(request), getRealSize(ccdTool, request), getHost()); result = creationUtil.getContainerCreationDescription(diagram, ccdTool); diff --git a/plugins/org.eclipse.sirius.diagram.sequence.ui/src/org/eclipse/sirius/diagram/sequence/ui/tool/internal/edit/policy/SequenceNodeCreationPolicy.java b/plugins/org.eclipse.sirius.diagram.sequence.ui/src/org/eclipse/sirius/diagram/sequence/ui/tool/internal/edit/policy/SequenceNodeCreationPolicy.java index b6556720bc..f4930400bd 100644 --- a/plugins/org.eclipse.sirius.diagram.sequence.ui/src/org/eclipse/sirius/diagram/sequence/ui/tool/internal/edit/policy/SequenceNodeCreationPolicy.java +++ b/plugins/org.eclipse.sirius.diagram.sequence.ui/src/org/eclipse/sirius/diagram/sequence/ui/tool/internal/edit/policy/SequenceNodeCreationPolicy.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2010, 2013 THALES GLOBAL SERVICES. + * Copyright (c) 2010, 2024 THALES GLOBAL SERVICES. * 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 @@ -148,7 +148,7 @@ public void eraseTargetFeedback(Request request) { * {@inheritDoc} */ @Override - protected Command getCreateNodeOnNodeCommand(CreateRequest request, NodeCreationDescription tool, DNode viewnode) { + protected Command getCreateNodeOnNodeCommand(CreateRequest request, NodeCreationDescription tool, DNode viewnode, EditPart parentEditPartToUse) { if (tool instanceof ExecutionCreationTool || tool instanceof StateCreationTool || tool instanceof ObservationPointCreationTool) { SequenceDiagram sequenceDiagram = EditPartsHelper.getSequenceDiagram(getHost()); SequenceDDiagram diagram = sequenceDiagram.getSequenceDDiagram(); @@ -163,11 +163,11 @@ protected Command getCreateNodeOnNodeCommand(CreateRequest request, NodeCreation GraphicalHelper.logical2screen(bottomRight, (IGraphicalEditPart) getHost()); request.setSize(new Dimension(LayoutConstants.DEFAULT_EXECUTION_WIDTH, LayoutConstants.DEFAULT_EXECUTION_HEIGHT)); } - CreationUtil creationUtil = new CreationUtil(request, getDiagramCommandFactory(startingEndPredecessor, startingEndPredecessor, location), getRealLocation(request), request.getSize(), - getHost()); + CreationUtil creationUtil = new CreationUtil(getDiagramCommandFactory(startingEndPredecessor, startingEndPredecessor, location), getRealLocation(request, parentEditPartToUse), + request.getSize(), getHost()); return creationUtil.getNodeCreationCommand(viewnode, tool); } else { - return super.getCreateNodeOnNodeCommand(request, tool, viewnode); + return super.getCreateNodeOnNodeCommand(request, tool, viewnode, parentEditPartToUse); } } @@ -190,7 +190,8 @@ protected Command getCreateContainerInContainerCommand(CreateRequest request, Co Point location = request.getLocation().getCopy(); GraphicalHelper.screen2logical(location, (IGraphicalEditPart) getHost()); - CreationUtil creationUtil = new CreationUtil(request, getDiagramCommandFactory(startingEndPredecessor, startingEndPredecessor, location), getRealLocation(request), getHost()); + CreationUtil creationUtil = new CreationUtil(request, getDiagramCommandFactory(startingEndPredecessor, startingEndPredecessor, location), getRealLocation(request, getHost()), + getHost()); result = creationUtil.getContainerCreationDescription((DDiagramElementContainer) viewNodeContainer.eContainer(), tool); } else { result = UnexecutableCommand.INSTANCE; diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/business/internal/view/DiagramLayoutData.java b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/business/internal/view/DiagramLayoutData.java deleted file mode 100644 index 073ae5f255..0000000000 --- a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/business/internal/view/DiagramLayoutData.java +++ /dev/null @@ -1,130 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009, 2009 THALES GLOBAL SERVICES. - * 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 - * https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Obeo - initial API and implementation - *******************************************************************************/ -package org.eclipse.sirius.diagram.ui.business.internal.view; - -import java.util.ArrayList; - -import org.eclipse.draw2d.geometry.Dimension; -import org.eclipse.draw2d.geometry.Point; -import org.eclipse.gef.EditPart; -import org.eclipse.gmf.runtime.notation.LayoutConstraint; -import org.eclipse.gmf.runtime.notation.Location; -import org.eclipse.gmf.runtime.notation.Node; -import org.eclipse.gmf.runtime.notation.Size; -import org.eclipse.sirius.diagram.AbstractDNode; -import org.eclipse.sirius.diagram.DDiagram; - -/** - * A DiagramLayoutData is the root of an LayoutDataHint. - * - * @author Laurent Redor - * - */ -public class DiagramLayoutData extends RootLayoutData { - - // /** - // * This constructor is used when you want to store the layout data of the - // * DDiagram of editPart and all its children. - // * - // * @param editPart . - // * @param location . - // */ - // public DiagramLayoutData(final ShapeEditPart editPart, final Point - // location) { - // super(editPart, location); - // } - - /** - * This constructor is used when you want to store the layout data of only - * one element which the parent is the DDiagram of editPart. - * - * @param editPart - * . - * @param location - * . - * @param size - * the future size - */ - public DiagramLayoutData(final EditPart editPart, final Point location, final Dimension size) { - super(editPart, location, size); - } - - /** - * Initialize this object (with a new location) and all its children. - * - * @param nodeTarget - * The node to deal with - * @param gmfNode - * the corresponding GMF node - * @param futureLocation - * The future location of the node (or null if the editPart - * location is OK) - */ - @Override - protected void init(final AbstractDNode nodeTarget, final Node gmfNode, final Point futureLocation) { - super.init(nodeTarget, gmfNode); - if (futureLocation != null) { - // Override the location of the nodeTarget - setLocation(futureLocation); - } - } - - /** - * Initialize this object (with a new location and size). The children of - * this object is not added because the - * - * @param parentNodeTarget - * The parent of the node to deal with - * @param parentGmfNode - * the corresponding GMF node - * @param futureLocation - * The future location of the node (or null if the editPart - * location is OK) - * @param futureSize - * The future size of the node (or null if the editPart size is - * OK) - */ - protected void init(final AbstractDNode parentNodeTarget, final Node parentGmfNode, final Point futureLocation, final Dimension futureSize) { - setTarget(parentNodeTarget); - final LayoutConstraint constaint = parentGmfNode.getLayoutConstraint(); - if (futureSize != null) { - setSize(futureSize); - } else if (constaint instanceof Size) { - setSize(new Dimension(((Size) constaint).getWidth(), ((Size) constaint).getHeight())); - } - if (futureLocation != null) { - // Take this location as a priority value if it's not null - setLocation(futureLocation); - } else if (constaint instanceof Location) { - setLocation(new Point(((Location) constaint).getX(), ((Location) constaint).getY())); - } - setChildren(new ArrayList()); - } - - /** - * Search recursively in in all the DiagramLayoutData is there is one which - * have the diagram for target. - * - * @param diagram - * The search diagram - * @param ignoreConsumeState - * true to ignore the consume state and to authorize to consume - * an already consumed data, false otherwise - * @return the corresponding LayoutData or null if not found. - */ - @Override - public LayoutData getData(final DDiagram diagram, boolean ignoreConsumeState) { - final LayoutData result = (ignoreConsumeState || !isConsume()) && getTarget().equals(diagram) ? this : null; - return result; - } -} diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/business/internal/view/LayoutData.java b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/business/internal/view/LayoutData.java index acf17fd6b8..7d8d7bfa7f 100644 --- a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/business/internal/view/LayoutData.java +++ b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/business/internal/view/LayoutData.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2021 THALES GLOBAL SERVICES and others. + * Copyright (c) 2009, 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 @@ -215,7 +215,7 @@ public List getChildren() { } /** - * Search recursively in in all the LayoutData is there is one which have + * Search recursively in in all the LayoutData if there is one which have * the element for target. * * @param node diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/business/internal/view/RootLayoutData.java b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/business/internal/view/RootLayoutData.java index 77fc5305df..082b179e2f 100644 --- a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/business/internal/view/RootLayoutData.java +++ b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/business/internal/view/RootLayoutData.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2021 THALES GLOBAL SERVICES and others. + * Copyright (c) 2009, 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 @@ -57,16 +57,7 @@ public class RootLayoutData extends LayoutData { * the future size */ public RootLayoutData(final EditPart editPart, final Point location, final Dimension size) { - final Object adaptObject = EditPartTools.getParentOfType(editPart, IGraphicalEditPart.class).resolveSemanticElement(); - if (adaptObject instanceof AbstractDNode) { - init((AbstractDNode) adaptObject, location, size); - } else if (adaptObject instanceof DDiagram) { - init((DDiagram) adaptObject, location, size); - } else if (adaptObject instanceof DEdge) { - init((DEdge) adaptObject, location, size); - } else { - AbstractSiriusFormatDataManager.logUnhandledDiagramElementKindMessage(adaptObject); - } + this(EditPartTools.getParentOfType(editPart, IGraphicalEditPart.class).resolveSemanticElement(), location, size); } /** @@ -107,12 +98,10 @@ public RootLayoutData(final AbstractDNode target, final ShapeEditPart editPart, */ public RootLayoutData(final Object adaptObject, final Point location, final Dimension size) { super(); - if (adaptObject instanceof AbstractDNode) { - init((AbstractDNode) adaptObject, location, size); - } else if (adaptObject instanceof DDiagram) { - init((DDiagram) adaptObject, location, size); - } else if (adaptObject instanceof DEdge) { - init((DEdge) adaptObject, location, size); + if (adaptObject instanceof DDiagram // for root + || adaptObject instanceof AbstractDNode // container or simple node + || adaptObject instanceof DEdge) { + init((EObject) adaptObject, location, size); } else { AbstractSiriusFormatDataManager.logUnhandledDiagramElementKindMessage(adaptObject); } @@ -170,8 +159,10 @@ public RootLayoutData getRoot() { } /** - * Search recursively in in all the DiagramLayoutData is there is one which - * have the diagram for target. + * Search if there is data which have the diagram for target. + *

+ * Default implementation does not perform a recursive search. + *

* * @param diagram * The search diagram diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/graphical/edit/policies/CreationUtil.java b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/graphical/edit/policies/CreationUtil.java index 0eafa60966..d76768e5bf 100644 --- a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/graphical/edit/policies/CreationUtil.java +++ b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/graphical/edit/policies/CreationUtil.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2021 THALES GLOBAL SERVICES. + * Copyright (c) 2007, 2024 THALES GLOBAL SERVICES. * 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 @@ -12,6 +12,8 @@ *******************************************************************************/ package org.eclipse.sirius.diagram.ui.graphical.edit.policies; +import java.util.function.Function; + import org.eclipse.draw2d.geometry.Dimension; import org.eclipse.draw2d.geometry.Point; import org.eclipse.emf.ecore.EObject; @@ -51,14 +53,12 @@ import org.eclipse.sirius.diagram.ui.tools.internal.commands.emf.SelectionWizardCommand; import org.eclipse.sirius.tools.api.SiriusPlugin; import org.eclipse.sirius.viewpoint.DSemanticDecorator; +import org.eclipse.sirius.viewpoint.description.tool.AbstractToolDescription; import org.eclipse.sirius.viewpoint.description.tool.PaneBasedSelectionWizardDescription; import org.eclipse.sirius.viewpoint.description.tool.SelectionWizardDescription; import org.eclipse.sirius.viewpoint.description.tool.ToolDescription; import org.eclipse.sirius.viewpoint.description.tool.ToolPackage; -import com.google.common.base.Predicate; -import com.google.common.base.Predicates; - /** * Useful operations for {@link NodeCreationEditPolicy} and {@link ContainerCreationEditPolicy}. * @@ -66,19 +66,13 @@ */ public class CreationUtil { - /** The location of the clicked point. */ - private final Point realLocation; - - /** The computed size of the element to create. */ - private final Dimension realSize; + /** The location of the clicked point, the size and the parent edit part of the element to create. */ + private final RootLayoutData rootLayoutData; /** The EMF Command Factory. */ private final IDiagramCommandFactory emfCommandFactory; - /** The request. */ - private final CreateRequest request; - - /** The edit part. */ + /** The edit part on which the calling policy is installed. */ private final EditPart editPart; /** @@ -91,22 +85,17 @@ public class CreationUtil { * @param realLocation * the location of the clicked point. * @param editPart - * the edit part + * the edit part on which the calling policy is installed. * @since 0.9.0 */ public CreationUtil(final CreateRequest request, final IDiagramCommandFactory commandFactory, final Point realLocation, final EditPart editPart) { - this.realLocation = realLocation; - this.realSize = null; - this.request = request; - this.emfCommandFactory = commandFactory; - this.editPart = editPart; + // The size of the request take into account the zoom (got the size in 100%) + this(commandFactory, new RootLayoutData(editPart, realLocation.getCopy(), CreationUtil.adaptRequestSizeToZoomFactor(request, editPart)), editPart); } /** * Creates a new CreationUtil with the specified request and location. * - * @param request - * the request. * @param commandFactory * the emf command factory. * @param realLocation @@ -114,17 +103,38 @@ public CreationUtil(final CreateRequest request, final IDiagramCommandFactory co * @param realSize * the computed size of the element to create, null if the default size must be used * @param editPart - * the edit part + * the edit part on which the calling policy is installed. + * @since 0.9.0 + */ + public CreationUtil(final IDiagramCommandFactory commandFactory, final Point realLocation, final Dimension realSize, final EditPart editPart) { + this(commandFactory, new RootLayoutData(editPart, realLocation.getCopy(), realSize == null ? null : realSize.getCopy()), editPart); + } + + /** + * Creates a new CreationUtil with the specified request and location. + * + * @param commandFactory + * the emf command factory. + * @param rootLayoutData + * the layout data for the created element (clicked point, size and parent edit part). + * @param editPart + * the edit part on which the calling policy is installed. * @since 0.9.0 */ - public CreationUtil(final CreateRequest request, final IDiagramCommandFactory commandFactory, final Point realLocation, final Dimension realSize, final EditPart editPart) { - this.realLocation = realLocation; - this.realSize = realSize; - this.request = request; + public CreationUtil(final IDiagramCommandFactory commandFactory, final RootLayoutData rootLayoutData, final EditPart editPart) { this.emfCommandFactory = commandFactory; + this.rootLayoutData = rootLayoutData; this.editPart = editPart; } + private CompoundCommand wrapCommandWithLayout(AbstractToolDescription tool, final org.eclipse.emf.common.command.Command emfCommand) { + final CompoundCommand compoundCommand = new CompoundCommand(tool.getName()); + + compoundCommand.add(createLayoutDataCommand()); + compoundCommand.add(new ICommandProxy(new GMFCommandWrapper(getEditingDomain(), emfCommand))); + return compoundCommand; + } + /** * Returns a command that is able to create a node in the specified container with the specified tool. * @@ -136,12 +146,7 @@ public CreationUtil(final CreateRequest request, final IDiagramCommandFactory co */ public Command getNodeCreationCommand(final DDiagramElementContainer container, final NodeCreationDescription tool) { if (new NodeCreationDescriptionQuery(tool).canCreateIn(container)) { - final org.eclipse.emf.common.command.Command command = emfCommandFactory.buildCreateNodeCommandFromTool(container, tool); - final CompoundCommand compoundCommand = new CompoundCommand(tool.getName()); - - compoundCommand.add(createLayoutDataCommand(Predicates. alwaysTrue())); - compoundCommand.add(new ICommandProxy(new GMFCommandWrapper(getEditingDomain(), command))); - return compoundCommand; + return wrapCommandWithLayout(tool, emfCommandFactory.buildCreateNodeCommandFromTool(container, tool)); } return null; } @@ -157,11 +162,7 @@ public Command getNodeCreationCommand(final DDiagramElementContainer container, */ public Command getNodeCreationCommand(final DNode node, final NodeCreationDescription tool) { if (new NodeCreationDescriptionQuery(tool).canCreateIn(node)) { - final CompoundCommand compoundCommand = new CompoundCommand(tool.getName()); - compoundCommand.add(createLayoutDataCommand(Predicates. alwaysTrue())); - final org.eclipse.emf.common.command.Command command = emfCommandFactory.buildCreateNodeCommandFromTool(node, tool); - compoundCommand.add(new ICommandProxy(new GMFCommandWrapper(getEditingDomain(), command))); - return compoundCommand; + return wrapCommandWithLayout(tool, emfCommandFactory.buildCreateNodeCommandFromTool(node, tool)); } return null; } @@ -176,13 +177,8 @@ public Command getNodeCreationCommand(final DNode node, final NodeCreationDescri * @return a command that is able to create a node in the specified viewpoint with the specified tool. */ public Command getNodeCreationCommand(final DDiagram diagram, final NodeCreationDescription tool) { - if (new NodeCreationDescriptionQuery(tool).canCreateIn(diagram)) { - final org.eclipse.emf.common.command.Command command = emfCommandFactory.buildCreateNodeCommandFromTool(diagram, tool); - final CompoundCommand compoundCommand = new CompoundCommand(tool.getName()); - compoundCommand.add(createLayoutDataCommand(Predicates. alwaysTrue())); - compoundCommand.add(new ICommandProxy(new GMFCommandWrapper(getEditingDomain(), command))); - return compoundCommand; + return wrapCommandWithLayout(tool, emfCommandFactory.buildCreateNodeCommandFromTool(diagram, tool)); } return null; } @@ -198,11 +194,7 @@ public Command getNodeCreationCommand(final DDiagram diagram, final NodeCreation */ public Command getContainerCreationDescription(final DDiagramElementContainer viewNodeContainer, final ContainerCreationDescription ccdTool) { if (new ContainerCreationDescriptionQuery(ccdTool).canCreateIn(viewNodeContainer)) { - final org.eclipse.emf.common.command.Command command = emfCommandFactory.buildCreateContainerCommandFromTool(viewNodeContainer, ccdTool); - final CompoundCommand compoundCommand = new CompoundCommand(ccdTool.getName()); - compoundCommand.add(createLayoutDataCommand(Predicates. alwaysTrue())); - compoundCommand.add(new ICommandProxy(new GMFCommandWrapper(getEditingDomain(), command))); - return compoundCommand; + return wrapCommandWithLayout(ccdTool, emfCommandFactory.buildCreateContainerCommandFromTool(viewNodeContainer, ccdTool)); } return null; } @@ -217,13 +209,8 @@ public Command getContainerCreationDescription(final DDiagramElementContainer vi * @return a command that is able to create a container in the specified viewpoint with the specified tool. */ public Command getContainerCreationDescription(final DDiagram diagram, final ContainerCreationDescription ccdTool) { - // if (container instanceof DiagramDescription) { if (new ContainerCreationDescriptionQuery(ccdTool).canCreateIn(diagram)) { - final org.eclipse.emf.common.command.Command command = emfCommandFactory.buildCreateContainerCommandFromTool(diagram, ccdTool); - final CompoundCommand compoundCommand = new CompoundCommand(ccdTool.getName()); - compoundCommand.add(createLayoutDataCommand(Predicates. alwaysTrue())); - compoundCommand.add(new ICommandProxy(new GMFCommandWrapper(getEditingDomain(), command))); - return compoundCommand; + return wrapCommandWithLayout(ccdTool, emfCommandFactory.buildCreateContainerCommandFromTool(diagram, ccdTool)); } return null; } @@ -238,19 +225,8 @@ public Command getContainerCreationDescription(final DDiagram diagram, final Con * @return a command that is able to launch a wizard tool. */ public Command getSelectionWizardCommand(final SelectionWizardDescription selectionTool, final EObject containerView) { - Command cmd = UnexecutableCommand.INSTANCE; - if (containerView != null) { - final CompoundCommand compoundCommand = new CompoundCommand(selectionTool.getName()); - final TreeItemWrapper input = new TreeItemWrapper(null, null); - if (AbstractSelectionWizardCommand.canCreateCommand(selectionTool, containerView, input)) { - compoundCommand.add(createLayoutDataCommand(Predicates. alwaysTrue())); - compoundCommand - .add(new ICommandProxy(new GMFCommandWrapper(getEditingDomain(), new SelectionWizardCommand(emfCommandFactory, selectionTool, input, (DSemanticDecorator) containerView)))); - cmd = compoundCommand; - cmd.setLabel(selectionTool.getName()); - } - } - return cmd; + return getSelectionWizardCommand(selectionTool, containerView, input -> + new SelectionWizardCommand(emfCommandFactory, selectionTool, input, (DSemanticDecorator) containerView)); } /** @@ -263,21 +239,21 @@ public Command getSelectionWizardCommand(final SelectionWizardDescription select * @return a command that is able to launch a wizard tool. */ public Command getPaneBasedSelectionWizardCommand(final PaneBasedSelectionWizardDescription selectionTool, final EObject containerView) { - Command cmd = UnexecutableCommand.INSTANCE; + return getSelectionWizardCommand(selectionTool, containerView, input -> + new PaneBasedSelectionWizardCommand(emfCommandFactory, selectionTool, input, (DSemanticDecorator) containerView)); + } + + private Command getSelectionWizardCommand(final AbstractToolDescription selectionTool, final EObject containerView, + final Function commandFactory) { if (containerView != null) { - final CompoundCommand compoundCommand = new CompoundCommand(selectionTool.getName()); final TreeItemWrapper input = new TreeItemWrapper(null, null); if (AbstractSelectionWizardCommand.canCreateCommand(selectionTool, containerView, input)) { - compoundCommand.add(createLayoutDataCommand(Predicates. alwaysTrue())); - compoundCommand.add( - new ICommandProxy(new GMFCommandWrapper(getEditingDomain(), new PaneBasedSelectionWizardCommand(emfCommandFactory, selectionTool, input, (DSemanticDecorator) containerView)))); - cmd = compoundCommand; - cmd.setLabel(selectionTool.getName()); + return wrapCommandWithLayout(selectionTool, commandFactory.apply(input)); } } - return cmd; + return UnexecutableCommand.INSTANCE; } - + private TransactionalEditingDomain getEditingDomain() { if (editPart instanceof IGraphicalEditPart) { return ((IGraphicalEditPart) editPart).getEditingDomain(); @@ -337,28 +313,14 @@ public Command getRequestToolCommand(final RequestDescription requestDescription * @return a command which executes the specified {@link ToolDescription} in the context of the view element. */ public Command getGenericToolCommand(final EObject containerView, final ToolDescription toolDesc) { - final CompoundCommand compoundCommand = new CompoundCommand(toolDesc.getName()); - final org.eclipse.emf.common.command.Command command = emfCommandFactory.buildGenericToolCommandFromTool(containerView, toolDesc); - compoundCommand.add(createLayoutDataCommand(Predicates. alwaysTrue())); - compoundCommand.add(new ICommandProxy(new GMFCommandWrapper(getEditingDomain(), command))); - return compoundCommand; + return wrapCommandWithLayout(toolDesc, emfCommandFactory.buildGenericToolCommandFromTool(containerView, toolDesc)); } - private Command createLayoutDataCommand(final Predicate pred) { + private Command createLayoutDataCommand() { return new Command() { @Override public void execute() { - if (pred != null && pred.apply(editPart)) { - // The size of the request take into account the zoom (got - // the size in 100%) - Dimension size = null; - if (realSize != null) { - size = realSize.getCopy(); - } else { - size = adaptRequestSizeToZoomFactor(); - } - SiriusLayoutDataManager.INSTANCE.addData(new RootLayoutData(editPart, realLocation.getCopy(), size)); - } + SiriusLayoutDataManager.INSTANCE.addData(rootLayoutData); } }; } @@ -368,7 +330,7 @@ public void execute() { * * @return A new dimension */ - private Dimension adaptRequestSizeToZoomFactor() { + public static Dimension adaptRequestSizeToZoomFactor(CreateRequest request, EditPart editPart) { if (request.getSize() == null) { return null; } diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/graphical/edit/policies/NodeCreationEditPolicy.java b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/graphical/edit/policies/NodeCreationEditPolicy.java index 9417512a02..55a4d5285f 100644 --- a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/graphical/edit/policies/NodeCreationEditPolicy.java +++ b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/graphical/edit/policies/NodeCreationEditPolicy.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2009 THALES GLOBAL SERVICES. + * Copyright (c) 2007, 2024 THALES GLOBAL SERVICES. * 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 @@ -12,23 +12,34 @@ *******************************************************************************/ package org.eclipse.sirius.diagram.ui.graphical.edit.policies; +import java.util.Optional; + import org.eclipse.draw2d.IFigure; import org.eclipse.draw2d.geometry.Point; +import org.eclipse.emf.common.util.EList; import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.transaction.TransactionalEditingDomain; import org.eclipse.emf.transaction.util.TransactionUtil; +import org.eclipse.gef.EditPart; import org.eclipse.gef.commands.Command; import org.eclipse.gef.requests.CreateRequest; import org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart; import org.eclipse.gmf.runtime.diagram.ui.figures.ResizableCompartmentFigure; import org.eclipse.gmf.runtime.notation.Node; +import org.eclipse.sirius.diagram.AbstractDNode; import org.eclipse.sirius.diagram.DDiagramElementContainer; import org.eclipse.sirius.diagram.DNode; +import org.eclipse.sirius.diagram.description.AbstractNodeMapping; +import org.eclipse.sirius.diagram.description.NodeMapping; import org.eclipse.sirius.diagram.description.tool.ContainerCreationDescription; import org.eclipse.sirius.diagram.description.tool.NodeCreationDescription; +import org.eclipse.sirius.diagram.model.business.internal.helper.MappingHelper; import org.eclipse.sirius.diagram.tools.api.command.IDiagramCommandFactory; import org.eclipse.sirius.diagram.tools.api.command.IDiagramCommandFactoryProvider; import org.eclipse.sirius.diagram.ui.business.internal.query.RequestQuery; +import org.eclipse.sirius.diagram.ui.business.internal.view.RootLayoutData; +import org.eclipse.sirius.diagram.ui.edit.api.part.AbstractDiagramContainerEditPart; +import org.eclipse.sirius.diagram.ui.internal.edit.parts.AbstractDNodeListCompartmentEditPart; import org.eclipse.sirius.diagram.ui.tools.api.draw2d.ui.figures.FigureUtilities; import org.eclipse.sirius.diagram.ui.tools.api.editor.DDiagramEditor; import org.eclipse.sirius.viewpoint.description.tool.AbstractToolDescription; @@ -44,28 +55,41 @@ public class NodeCreationEditPolicy extends SiriusContainerEditPolicy { */ @Override protected Command getCreateCommand(CreateRequest request) { - if (!(getHost().getModel() instanceof Node)) { + + AbstractToolDescription tool = getTool(request); + GraphicalEditPart hostEditPartToUse = (GraphicalEditPart) getHost(); + if (getHost() instanceof GraphicalEditPart) { + boolean isBorderNodeCreationRequest = new RequestQuery(request).isDropOrCreationOfBorderNode(); + if (tool instanceof NodeCreationDescription nodeCreationDescriptionTool && isBorderNodeCreationRequest) { + // Search the correct edit part for this tool. It can be different than the host in case of "extra + // mappings" defined in the tool. + Optional optionalEditPartToUse = getParentEditPartWithExpectedMapping((GraphicalEditPart) getHost(), nodeCreationDescriptionTool.getNodeMappings()); + if (optionalEditPartToUse.isPresent()) { + hostEditPartToUse = optionalEditPartToUse.get(); + } + } + } + if (!(hostEditPartToUse.getModel() instanceof Node)) { return null; } + EObject containerElement = ((Node) hostEditPartToUse.getModel()).getElement(); - EObject containerElement = ((Node) getHost().getModel()).getElement(); - AbstractToolDescription tool = getTool(request); /* - * Dispatch to the appropriate specialized command depending on the type - * of the container element and the nature of the tool. + * Dispatch to the appropriate specialized command depending on the type of the container element and the nature + * of the tool. */ Command result = null; if (containerElement instanceof DDiagramElementContainer) { DDiagramElementContainer viewNodeContainer = (DDiagramElementContainer) containerElement; if (tool instanceof NodeCreationDescription) { - result = getCreateNodeInContainerCommand(request, (NodeCreationDescription) tool, viewNodeContainer); + result = getCreateNodeInContainerCommand(request, (NodeCreationDescription) tool, viewNodeContainer, hostEditPartToUse); } else if (tool instanceof ContainerCreationDescription) { result = getCreateContainerInContainerCommand(request, (ContainerCreationDescription) tool, viewNodeContainer); } } else if (containerElement instanceof DNode) { DNode viewNode = (DNode) containerElement; if (tool instanceof NodeCreationDescription) { - result = getCreateNodeOnNodeCommand(request, (NodeCreationDescription) tool, viewNode); + result = getCreateNodeOnNodeCommand(request, (NodeCreationDescription) tool, viewNode, hostEditPartToUse); } } return result; @@ -82,8 +106,8 @@ protected Command getCreateCommand(CreateRequest request) { * the node on which to create the new (bordered) node. * @return a command to create the new node. */ - protected Command getCreateNodeOnNodeCommand(CreateRequest request, NodeCreationDescription tool, DNode viewnode) { - CreationUtil creationUtil = new CreationUtil(request, getDiagramCommandFactory(), getRealLocation(request), getHost()); + protected Command getCreateNodeOnNodeCommand(CreateRequest request, NodeCreationDescription tool, DNode viewnode, EditPart parentEditPartToUse) { + CreationUtil creationUtil = new CreationUtil(getDiagramCommandFactory(), getRealLayoutData(request, parentEditPartToUse), parentEditPartToUse); return creationUtil.getNodeCreationCommand(viewnode, tool); } @@ -99,7 +123,7 @@ protected Command getCreateNodeOnNodeCommand(CreateRequest request, NodeCreation * @return a command to create the new container. */ protected Command getCreateContainerInContainerCommand(CreateRequest request, ContainerCreationDescription tool, DDiagramElementContainer viewNodeContainer) { - CreationUtil creationUtil = new CreationUtil(request, getDiagramCommandFactory(), getRealLocation(request), getHost()); + CreationUtil creationUtil = new CreationUtil(request, getDiagramCommandFactory(), getRealLocation(request, getHost()), getHost()); return creationUtil.getContainerCreationDescription(viewNodeContainer, tool); } @@ -112,10 +136,13 @@ protected Command getCreateContainerInContainerCommand(CreateRequest request, Co * the node creation tool description. * @param viewNodeContainer * the container on which to create the new (bordered) node. + * @param parentEditPartToUse + * parent EditPart to retrieve layout data (can be same as getHost(), but can also be another edit part + * according to extra mapping defined in tool, for border nodes for example). * @return a command to create the new node. */ - protected Command getCreateNodeInContainerCommand(CreateRequest request, NodeCreationDescription tool, DDiagramElementContainer viewNodeContainer) { - CreationUtil creationUtil = new CreationUtil(request, getDiagramCommandFactory(), getRealLocation(request), getHost()); + protected Command getCreateNodeInContainerCommand(CreateRequest request, NodeCreationDescription tool, DDiagramElementContainer viewNodeContainer, EditPart parentEditPartToUse) { + CreationUtil creationUtil = new CreationUtil(getDiagramCommandFactory(), getRealLayoutData(request, parentEditPartToUse), parentEditPartToUse); return creationUtil.getNodeCreationCommand(viewNodeContainer, tool); } @@ -135,18 +162,34 @@ protected AbstractToolDescription getTool(CreateRequest request) { } /** - * Computes the real location where the element must be created from the raw - * information passed in the request. + * Computes the real location where the element must be created from the raw information passed in the request. * * @param request * the creation request. + * @param parentEditPartToUse + * parent EditPart to retrieve layout data (can be same as getHost(), but can also be another edit part + * according to extra mapping defined in tool, for border nodes for example). * @return the real location where the element must be created. */ - protected Point getRealLocation(final CreateRequest request) { + protected Point getRealLocation(final CreateRequest request, EditPart parentEditPartToUse) { + return getRealLayoutData(request, parentEditPartToUse).getLocation(); + } + + /** + * Computes the real location where the element must be created from the raw information passed in the request. + * + * @param request + * the creation request. + * @param parentEditPartToUse + * parent EditPart to retrieve layout data (can be same as getHost(), but can also be another edit part + * according to extra mapping defined in tool, for border nodes for example). + * @return the real location where the element must be created. + */ + protected RootLayoutData getRealLayoutData(final CreateRequest request, EditPart parentEditPartToUse) { Point location = request.getLocation().getCopy(); final Point realLocation; - if (location != null && getHost() instanceof GraphicalEditPart) { - final IFigure fig = ((GraphicalEditPart) getHost()).getFigure(); + if (location != null && parentEditPartToUse instanceof GraphicalEditPart graphicalParentEditPart) { + final IFigure fig = graphicalParentEditPart.getFigure(); fig.translateToRelative(location); final Point containerLocation = fig.getBounds().getLocation(); location = new Point(location.x - containerLocation.x, location.y - containerLocation.y); @@ -160,7 +203,7 @@ protected Point getRealLocation(final CreateRequest request) { } else { scrollOffset = ((ResizableCompartmentFigure) fig).getScrollPane().getViewport().getViewLocation(); } - final Point shiftFromMarginOffset = FigureUtilities.getShiftFromMarginOffset((ResizableCompartmentFigure) fig, isBorderNodeCreationRequest, getHost()); + final Point shiftFromMarginOffset = FigureUtilities.getShiftFromMarginOffset((ResizableCompartmentFigure) fig, isBorderNodeCreationRequest, parentEditPartToUse); realLocation = new Point(location.x + scrollOffset.x - shiftFromMarginOffset.x, location.y + scrollOffset.y - shiftFromMarginOffset.y); } else { @@ -169,7 +212,30 @@ protected Point getRealLocation(final CreateRequest request) { } else { realLocation = location; } - return realLocation; + return new RootLayoutData(parentEditPartToUse, realLocation.getCopy(), CreationUtil.adaptRequestSizeToZoomFactor(request, parentEditPartToUse)); + } + + private Optional getParentEditPartWithExpectedMapping(GraphicalEditPart editPart, EList nodeMappings) { + Optional result = Optional.empty(); + if (editPart instanceof AbstractDNodeListCompartmentEditPart) { + result = getParentEditPartWithExpectedMapping((GraphicalEditPart) editPart.getParent(), nodeMappings); + } else if (editPart.getParent() instanceof AbstractDiagramContainerEditPart && ((AbstractDiagramContainerEditPart) editPart.getParent()).isRegionContainer()) { + result = getParentEditPartWithExpectedMapping((AbstractDiagramContainerEditPart) editPart.getParent(), nodeMappings); + } else { + for (NodeMapping nodeMapping : nodeMappings) { + if (editPart != null && editPart.getModel() instanceof Node node && node.getElement() instanceof AbstractDNode abstractDNode + && abstractDNode.getMapping() instanceof AbstractNodeMapping abstractNodegetMapping) { + if (MappingHelper.getAllBorderedNodeMappings(abstractNodegetMapping).contains(nodeMapping)) { + result = Optional.of(editPart); + break; + } + } + } + } + if (result.isEmpty() && editPart.getParent() instanceof GraphicalEditPart graphicalEditPart) { + result = getParentEditPartWithExpectedMapping(graphicalEditPart, nodeMappings); + } + return result; } /** diff --git a/plugins/org.eclipse.sirius.tests.swtbot/data/unit/tools/creation/borderedNode/borderedNode.aird b/plugins/org.eclipse.sirius.tests.swtbot/data/unit/tools/creation/borderedNode/borderedNode.aird index 8f3992dc58..0c67a4f020 100644 --- a/plugins/org.eclipse.sirius.tests.swtbot/data/unit/tools/creation/borderedNode/borderedNode.aird +++ b/plugins/org.eclipse.sirius.tests.swtbot/data/unit/tools/creation/borderedNode/borderedNode.aird @@ -1,846 +1,882 @@ - - - - - - - - - - - - - + + + borderedNode.ecore + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - + + + - - + + - - - - - - + + + + + + + + + + + + + - - - - - - - - - - + + + - - - + + + + + + + + + + - - - - - - - - - - + + + - - + + - - + + - - - - - - - - - - + + + + + + + + + + - - + + - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + - - - - - - - - - - + + + - - - + + + + + + - - - - - - - - - - + + + - - + + - - - - - - + + + - - - + + + + + + + + + + - - + + - - + + - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - + + + - - - - - - - - - - + + + + + + - - - + + + - - + + + + + + - - - + + + + + + + + + + - - - - - - - - - - + + + - - - - - - - - - - - - - - + + + + + + - - - - - - - - - - + + + - - + + - - - - - - + + + - - - + + + + + + + + + + - - + + - - + + - - - - - + + + - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + - - + + - - - + + + + + + + + + + + + + + - - - + + + - - - + + + + + + + + + + + + + + + + + + + + + - - - + + + - - + + - - + + - - - - - + + + + + + + + + + + - - + + - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - + - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + - - - - - - - - - - - - - - - + + + + + + + - + - - - - - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - - - - - - - - - - - - + + + + + + + + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + - - - - - - - - - - - - - - - + + + + + + + + - + - - - - - + + - + - - - - KEEP_LOCATION - KEEP_SIZE - KEEP_RATIO - - - - - + + + + + + + + + + + + + + + + + + + + + + KEEP_LOCATION + KEEP_SIZE + KEEP_RATIO + + + + + + + + + + + + + + + + + + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - + + + - - + + - - + + - - - - - - - - - - - - - - - - + + + - - - - - - - - - - + + + - - + + - - - - - + + + + + + + + + + + + + + + + - - + + - - - - - - - - - - + + + - - - - - - - - - + + + - - - - - - - - - - - - - - - - - - - - - KEEP_LOCATION - KEEP_SIZE - KEEP_RATIO - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + KEEP_LOCATION KEEP_SIZE KEEP_RATIO - - - - - + + - - - - - KEEP_LOCATION - KEEP_SIZE - KEEP_RATIO - - - - - - - - - - - - - - - - - - - - - - - + + + KEEP_LOCATION + KEEP_SIZE + KEEP_RATIO + + + + + + + KEEP_LOCATION KEEP_SIZE KEEP_RATIO - - - - - - - - - - - - - - - - - - - - - - - strokeColor - - - - - + + - + - - - - - strokeColor - - - - - + + + + + + + + + - - - - - - KEEP_LOCATION - KEEP_SIZE - KEEP_RATIO - - - - - + + + KEEP_LOCATION + KEEP_SIZE + KEEP_RATIO + + + + + + + + + - + - - - - - - - - + + + + + strokeColor + + + + + + + + + + strokeColor + + + + + + + + + KEEP_LOCATION + KEEP_SIZE + KEEP_RATIO + + + + + + + + + + + diff --git a/plugins/org.eclipse.sirius.tests.swtbot/data/unit/tools/creation/borderedNode/borderedNode.ecore b/plugins/org.eclipse.sirius.tests.swtbot/data/unit/tools/creation/borderedNode/borderedNode.ecore index 1916068d87..e842a4d92c 100644 --- a/plugins/org.eclipse.sirius.tests.swtbot/data/unit/tools/creation/borderedNode/borderedNode.ecore +++ b/plugins/org.eclipse.sirius.tests.swtbot/data/unit/tools/creation/borderedNode/borderedNode.ecore @@ -51,4 +51,7 @@ + + + diff --git a/plugins/org.eclipse.sirius.tests.swtbot/data/unit/tools/creation/borderedNode/borderedNode.odesign b/plugins/org.eclipse.sirius.tests.swtbot/data/unit/tools/creation/borderedNode/borderedNode.odesign index 61cfccdfe7..b478003b65 100644 --- a/plugins/org.eclipse.sirius.tests.swtbot/data/unit/tools/creation/borderedNode/borderedNode.odesign +++ b/plugins/org.eclipse.sirius.tests.swtbot/data/unit/tools/creation/borderedNode/borderedNode.odesign @@ -1,10 +1,10 @@ - + - - + + @@ -58,6 +58,45 @@ + + + + + + + + + + + + + + + @@ -197,6 +236,28 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/BorderedNodeCreationTest.java b/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/BorderedNodeCreationTest.java index 21e4d900be..d54d813aa8 100644 --- a/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/BorderedNodeCreationTest.java +++ b/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/BorderedNodeCreationTest.java @@ -113,6 +113,8 @@ public class BorderedNodeCreationTest extends AbstractSiriusSwtBotGefTestCase { /** Name of the fourth package */ protected static final String PACKAGE_4_NAME = "P4"; + private static final String PACKAGE_6_NAME = "P6ForVStack"; + private static final String CLASS_1_NAME = "Class1"; private static final String CLASS_2_NAME = "Class2"; @@ -135,6 +137,11 @@ public class BorderedNodeCreationTest extends AbstractSiriusSwtBotGefTestCase { */ protected boolean createCollapsedBorderedNode; + /** + * If true the tool to create the border node is named "BorderClassOnVStack". + */ + protected boolean createBorderedNodeOnVStack; + /** * {@inheritDoc} */ @@ -276,7 +283,7 @@ protected void testBNC_OnNode(ZoomLevel zoomLevel, String classToRevealName, boo // Get the location of the class (relative the part visible on the // screen) Point classLocation = editor.getLocation(classEditPart); - // Get the absolute location of p2 package from origin (0, 0) + // Get the absolute location of the class from origin (0, 0) Point classAbsoluteLocation = editor.getAbsoluteLocation((GraphicalEditPart) classEditPart.part()); // Get the insertion location for the bordered node (use the relative // coordinate, that's what is send to the request in reality) @@ -495,18 +502,23 @@ private void testBNC_OnContainer(ZoomLevel zoomLevel, String packageToRevealName fail("Problem during getting expanded bounds of the collapse bordered node."); } } else { - // Try to locate the bordered node at 8 pixels to the top-left + // Try to locate the bordered node on the left border, at 8 pixels from the top-left // corner of the package - Point delta = new Point(8, 0); + Point delta = new Point(0, 8); + if (createBorderedNodeOnVStack) { + // For a VStack container try to locate the bordered node a little bit lower to be under the "title" + // area. + delta = delta.getTranslated(0, 22); + } // We compute the location according the the package location, the // zoom factor and an insets to be sure to be in the package and not - // just above. - location = packageLocation.getTranslated(delta.getScaled(zoomLevel.getAmount()).translate(0, 1)); + // just nearby. + location = packageLocation.getTranslated(delta.getScaled(zoomLevel.getAmount()).translate(1, 0)); // The expected location is in absolute coordinate the delta is // translate with -2 in y axis corresponding to the shift of the // bordered node make by BorderItemLocator // (IBorderItemOffsets.DEFAULT_OFFSET - size of the node). - expectedLocation = packageAbsoluteLocation.getTranslated(delta.translate(0, -2)); + expectedLocation = packageAbsoluteLocation.getTranslated(delta.translate(-2, 0)); } expectedLocation = adaptExpectedLocation(((GraphicalEditPart) editPart.part()).getFigure(), packageAbsoluteLocation, expectedLocation); @@ -656,6 +668,18 @@ private void assertBorderedNodeSize(String borderedNodeLabel) { assertEquals("The port size should have 1 pixel height.", 1, size.getHeight()); } + /** + * Ensures that a bordered node created on a vertical stack region (zoom level: 100%) has the expected location. + */ + public void testBNC_OnVStackContainer() { + createBorderedNodeOnVStack = true; + try { + testBNC_OnContainer(ZoomLevel.ZOOM_100, PACKAGE_6_NAME); + } finally { + createBorderedNodeOnVStack = false; + } + } + /** * Ensures that a bordered node created on a Node in Container (zoom level : * 100%) has the expected location. @@ -727,10 +751,18 @@ protected String getBorderedNodeCreationOnClassToolName() { * @return the name of the tool to use. */ protected String getBorderedNodeCreationOnPackageToolName() { - if (createCollapsedBorderedNode) { - return COLLASPED_BORDERED_NODE_CREATION_ON_PACKAGE_TOOL_NAME; + if (createBorderedNodeOnVStack) { + if (createCollapsedBorderedNode) { + return "CollapsedBorderClassOnVStack"; + } else { + return "BorderClassOnVStack"; + } } else { - return BORDERED_NODE_CREATION_ON_PACKAGE_TOOL_NAME; + if (createCollapsedBorderedNode) { + return COLLASPED_BORDERED_NODE_CREATION_ON_PACKAGE_TOOL_NAME; + } else { + return BORDERED_NODE_CREATION_ON_PACKAGE_TOOL_NAME; + } } }