use of org.eclipse.gef.requests.CreateConnectionRequest in project archi by archimatetool.
the class MagicConnectionCreationTool method setTargetEditPart.
@Override
protected void setTargetEditPart(EditPart editpart) {
/*
* Set editpart to null if it's not an Archimate target concept so we can handle it as if we clicked on the canvas.
* This also disables unwanted connection target feedback.
*/
if (editpart != null && !(editpart.getModel() instanceof IDiagramModelArchimateComponent)) {
editpart = null;
}
/*
* Check whether we are trying to connect an element to a relation where the relation is already connected to that element
* If we are, set editpart to null to veto it.
*/
if (editpart != null) {
EditPart sourceEditPart = ((CreateConnectionRequest) getSourceRequest()).getSourceEditPart();
if (sourceEditPart != null) {
if (sourceEditPart.getModel() instanceof IDiagramModelArchimateComponent && editpart.getModel() instanceof IDiagramModelArchimateComponent) {
IArchimateConcept sourceConcept = ((IDiagramModelArchimateComponent) sourceEditPart.getModel()).getArchimateConcept();
IArchimateConcept targetConcept = ((IDiagramModelArchimateComponent) editpart.getModel()).getArchimateConcept();
if (ArchimateModelUtils.hasDirectRelationship(sourceConcept, targetConcept)) {
editpart = null;
}
}
}
}
super.setTargetEditPart(editpart);
}
use of org.eclipse.gef.requests.CreateConnectionRequest in project archi by archimatetool.
the class MagicConnectionCreationTool method handleCreateConnection.
/**
* When this is called, a CreateConnectionRequest will already have been created.
* This CreateConnectionRequest will be passed to the ArchimateDiagramConnectionPolicy.
* ArchimateDiagramConnectionPolicy will, in turn, create a CreateArchimateConnectionCommand.
*
* So, at this point, we already have the source and target edit parts and model objects set in a Command.
* If we want to change this at all we will have to kludge it.
*/
@Override
protected boolean handleCreateConnection() {
// Clear the connection factory first
getFactory().clear();
// Do this first, here (we have to!)
fCanSetCurrentCommand = true;
Command endCommand = getCommand();
setCurrentCommand(endCommand);
// Get this now!
CreateConnectionRequest request = (CreateConnectionRequest) getTargetRequest();
EditPart sourceEditPart = request.getSourceEditPart();
EditPart targetEditPart = request.getTargetEditPart();
// if(sourceEditPart == null || sourceEditPart == targetEditPart) {
if (sourceEditPart == null) {
eraseSourceFeedback();
return false;
}
IDiagramModelArchimateComponent sourceDiagramModelComponent = (IDiagramModelArchimateComponent) sourceEditPart.getModel();
// If targetEditPart is null then user clicked on the diagram or on a non-Archimate concept Editpart
if (targetEditPart == null) {
return createElementAndConnection(sourceDiagramModelComponent, request.getLocation());
}
// User clicked on Archimate target concept edit part
if (targetEditPart.getModel() instanceof IDiagramModelArchimateComponent) {
return createConnection(request, sourceDiagramModelComponent, (IDiagramModelArchimateComponent) targetEditPart.getModel());
}
eraseSourceFeedback();
return false;
}
use of org.eclipse.gef.requests.CreateConnectionRequest in project archi by archimatetool.
the class CreateDiagramArchimateConnectionWithDialogCommandTests method runOnceBeforeEachTest.
@Before
public void runOnceBeforeEachTest() {
CreateConnectionRequest request = new CreateConnectionRequest();
request.setFactory(new ArchimateDiagramModelFactory(IArchimatePackage.eINSTANCE.getAssignmentRelationship()));
cmd = new CreateDiagramArchimateConnectionWithDialogCommand(request);
}
use of org.eclipse.gef.requests.CreateConnectionRequest in project archi by archimatetool.
the class ArchimateDiagramConnectionPolicyTests method testGetConnectionCreateCommand_CreatesNullCommand.
@Test
public void testGetConnectionCreateCommand_CreatesNullCommand() {
setupSourcePolicy(IArchimateFactory.eINSTANCE.createJunction());
CreateConnectionRequest request = new CreateConnectionRequest();
// Use a non-legal relationship
request.setFactory(new ArchimateDiagramModelFactory(IArchimatePackage.eINSTANCE.getSpecializationRelationship()));
// Should be null
Command cmd = sourcePolicy.getConnectionCreateCommand(request);
assertNull(cmd);
}
use of org.eclipse.gef.requests.CreateConnectionRequest in project archi by archimatetool.
the class ArchimateDiagramConnectionPolicyTests method testGetConnectionCompleteCommand.
@Test
public void testGetConnectionCompleteCommand() throws Exception {
setupSourcePolicy(IArchimateFactory.eINSTANCE.createBusinessActor());
setupTargetPolicy(IArchimateFactory.eINSTANCE.createBusinessRole());
CreateConnectionRequest request = new CreateConnectionRequest();
request.setFactory(new ArchimateDiagramModelFactory(IArchimatePackage.eINSTANCE.getAssignmentRelationship()));
EditPart sourceEditPart = mock(EditPart.class);
when(sourceEditPart.getModel()).thenReturn(sourceDiagramObject);
request.setSourceEditPart(sourceEditPart);
Command startCommand = sourcePolicy.getConnectionCreateCommand(request);
assertNotNull(startCommand);
Command endCommand = targetPolicy.getConnectionCompleteCommand(request);
assertNotNull(endCommand);
assertEquals(startCommand, endCommand);
assertEquals(targetDiagramObject, TestUtils.getPrivateField(endCommand, "fTarget"));
}
Aggregations