Skip to content

Commit

Permalink
[396] Adapt NodeCreationEditPolicy to compute the target location
Browse files Browse the repository at this point in the history
- Constructors of CreationUtil have been improved to directly have
LayoutData as parameter instead of location and size. Indeed, the
location is relative to the parent edit part and for border nodes, the
parent edit part is not systematically the "host" of the called policy.
- In NodeCreationEditPolicy, in case of border nodes, the "host edit
part" is not systematically considered (to compute the RootLayoutData
for example). The correct edit part, a parent of the host, is computed
according to the mapping defined in the used tool.

Bug: #396
  • Loading branch information
lredor committed Sep 12, 2024
1 parent 0d981b9 commit 8289b1d
Show file tree
Hide file tree
Showing 4 changed files with 119 additions and 56 deletions.
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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) {
Expand All @@ -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);
Expand Down Expand Up @@ -140,7 +140,7 @@ protected Command getCreateContainerOnDiagramCommand(CreateRequest request, Cont
List<EObject> 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);

Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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();
Expand All @@ -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);
}
}

Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -91,33 +85,45 @@ 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(request, commandFactory, realLocation, null, 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 <code>CreationUtil</code> with the specified request and location.
*
* @param request
* the request.
* @param commandFactory
* the emf command factory.
* @param realLocation
* the location of the clicked point.
* @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 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 Point realLocation, final Dimension realSize, final EditPart editPart) {
this(commandFactory, new RootLayoutData(editPart, realLocation.getCopy(), realSize == null ? null : realSize.getCopy()), editPart);
}

/**
* Creates a new <code>CreationUtil</code> 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 IDiagramCommandFactory commandFactory, final RootLayoutData rootLayoutData, final EditPart editPart) {
this.emfCommandFactory = commandFactory;
this.rootLayoutData = rootLayoutData;
this.editPart = editPart;
}

Expand Down Expand Up @@ -314,15 +320,7 @@ private Command createLayoutDataCommand() {
return new Command() {
@Override
public void execute() {
// 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);
}
};
}
Expand All @@ -332,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;
}
Expand Down
Loading

0 comments on commit 8289b1d

Please sign in to comment.