Skip to content

Commit

Permalink
prmr#416 Move creation of ConstructorCall to SequenceDiagramBuilder
Browse files Browse the repository at this point in the history
When a user attempts to create a constructor call, they use the normal
"CallEdge" creation tool from the tool bar. This design decision was to
avoid forcing the user to use two very similar tools to create call and
constructor edges. However, internally if a constructor call is created,
a ConstructorEdge must be used, so it's necessary to convert the
original CallEdge to a Constructor Edge. This was initially done in the
DiagramCanvasController, leading to a special case and coupling with the
SequenceDiagram Builder. To avoid this design weakness, the conversion
from CallEdge to ConstructorEdge is moved to the SequenceDiagramBuilder.
  • Loading branch information
prmr authored and yingjie-xu committed Mar 9, 2021
1 parent dc7cbee commit fdd4b0f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import ca.mcgill.cs.jetuml.diagram.builder.constraints.EdgeConstraints;
import ca.mcgill.cs.jetuml.diagram.builder.constraints.SequenceDiagramEdgeConstraints;
import ca.mcgill.cs.jetuml.diagram.edges.CallEdge;
import ca.mcgill.cs.jetuml.diagram.edges.ConstructorEdge;
import ca.mcgill.cs.jetuml.diagram.nodes.CallNode;
import ca.mcgill.cs.jetuml.diagram.nodes.ImplicitParameterNode;
import ca.mcgill.cs.jetuml.geom.Point;
Expand Down Expand Up @@ -188,9 +189,12 @@ protected void completeEdgeAdditionOperation( CompoundOperation pOperation, Edge
}
));
int insertionIndex = computeInsertionIndex(start, pStartPoint.getY());
pEdge.connect(start, end, aDiagram);
pOperation.add(new SimpleOperation(()-> aDiagram.addEdge(insertionIndex, pEdge),
()-> aDiagram.removeEdge(pEdge)));

// CSOFF: Needed for assigning to the final variable
final Edge edge = canCreateConstructorCall(pStartPoint, pEndPoint)?new ConstructorEdge():pEdge; // CSON:
edge.connect(start, end, aDiagram);
pOperation.add(new SimpleOperation(()-> aDiagram.addEdge(insertionIndex, edge),
()-> aDiagram.removeEdge(edge)));
}

private int computeInsertionIndex( Node pCaller, int pY)
Expand Down
8 changes: 0 additions & 8 deletions src/ca/mcgill/cs/jetuml/gui/DiagramCanvasController.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@
import ca.mcgill.cs.jetuml.diagram.builder.CompoundOperation;
import ca.mcgill.cs.jetuml.diagram.builder.DiagramBuilder;
import ca.mcgill.cs.jetuml.diagram.builder.DiagramOperationProcessor;
import ca.mcgill.cs.jetuml.diagram.builder.SequenceDiagramBuilder;
import ca.mcgill.cs.jetuml.diagram.edges.ConstructorEdge;
import ca.mcgill.cs.jetuml.diagram.nodes.FieldNode;
import ca.mcgill.cs.jetuml.diagram.nodes.PackageNode;
import ca.mcgill.cs.jetuml.geom.Dimension;
Expand Down Expand Up @@ -478,12 +476,6 @@ private void releaseRubberband(Point pMousePoint)
{
if( aDiagramBuilder.canAdd(newEdge, aMouseDownPoint, pMousePoint))
{
if( aDiagramBuilder instanceof SequenceDiagramBuilder &&
((SequenceDiagramBuilder)aDiagramBuilder).canCreateConstructorCall(aMouseDownPoint, pMousePoint))
{
// Change the edge type if can create a constructor call
newEdge = new ConstructorEdge();
}
aProcessor.executeNewOperation(aDiagramBuilder.createAddEdgeOperation(newEdge,
aMouseDownPoint, pMousePoint));
aSelectionModel.set(newEdge);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,9 @@ public void testCompleteEdgeAdditionOperationWithConstructorCall()
assertEquals(1, numberOfEdges());
assertEquals(1, aImplicitParameterNode1.getChildren().size());
assertEquals(1, aImplicitParameterNode2.getChildren().size());
assertEquals(CallNode.class, aImplicitParameterNode1.getChildren().get(0).getClass());
assertEquals(CallNode.class, aImplicitParameterNode2.getChildren().get(0).getClass());
assertSame(aDiagram.edges().get(0), constructorEdge);
assertSame(CallNode.class, aImplicitParameterNode1.getChildren().get(0).getClass());
assertSame(CallNode.class, aImplicitParameterNode2.getChildren().get(0).getClass());
assertSame(ConstructorEdge.class, aDiagram.edges().get(0).getClass());
}

@Test
Expand Down

0 comments on commit fdd4b0f

Please sign in to comment.