Search in sources :

Example 11 with CreateConnectionRequest

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);
}
Also used : IDiagramModelArchimateComponent(com.archimatetool.model.IDiagramModelArchimateComponent) GroupEditPart(com.archimatetool.editor.diagram.editparts.diagram.GroupEditPart) AbstractBaseEditPart(com.archimatetool.editor.diagram.editparts.AbstractBaseEditPart) GraphicalEditPart(org.eclipse.gef.GraphicalEditPart) EditPart(org.eclipse.gef.EditPart) IArchimateConcept(com.archimatetool.model.IArchimateConcept) CreateConnectionRequest(org.eclipse.gef.requests.CreateConnectionRequest)

Example 12 with CreateConnectionRequest

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;
}
Also used : CompoundCommand(org.eclipse.gef.commands.CompoundCommand) CreateDiagramArchimateConnectionWithDialogCommand(com.archimatetool.editor.diagram.commands.CreateDiagramArchimateConnectionWithDialogCommand) Command(org.eclipse.gef.commands.Command) GroupEditPart(com.archimatetool.editor.diagram.editparts.diagram.GroupEditPart) AbstractBaseEditPart(com.archimatetool.editor.diagram.editparts.AbstractBaseEditPart) GraphicalEditPart(org.eclipse.gef.GraphicalEditPart) EditPart(org.eclipse.gef.EditPart) IDiagramModelArchimateComponent(com.archimatetool.model.IDiagramModelArchimateComponent) CreateConnectionRequest(org.eclipse.gef.requests.CreateConnectionRequest)

Example 13 with CreateConnectionRequest

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);
}
Also used : ArchimateDiagramModelFactory(com.archimatetool.editor.diagram.ArchimateDiagramModelFactory) CreateConnectionRequest(org.eclipse.gef.requests.CreateConnectionRequest) Before(org.junit.Before)

Example 14 with CreateConnectionRequest

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);
}
Also used : CreateDiagramConnectionCommand(com.archimatetool.editor.diagram.commands.CreateDiagramConnectionCommand) CreateDiagramArchimateConnectionWithDialogCommand(com.archimatetool.editor.diagram.commands.CreateDiagramArchimateConnectionWithDialogCommand) Command(org.eclipse.gef.commands.Command) ArchimateDiagramModelFactory(com.archimatetool.editor.diagram.ArchimateDiagramModelFactory) CreateConnectionRequest(org.eclipse.gef.requests.CreateConnectionRequest) Test(org.junit.Test)

Example 15 with CreateConnectionRequest

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"));
}
Also used : CreateDiagramConnectionCommand(com.archimatetool.editor.diagram.commands.CreateDiagramConnectionCommand) CreateDiagramArchimateConnectionWithDialogCommand(com.archimatetool.editor.diagram.commands.CreateDiagramArchimateConnectionWithDialogCommand) Command(org.eclipse.gef.commands.Command) EditPart(org.eclipse.gef.EditPart) ArchimateDiagramModelFactory(com.archimatetool.editor.diagram.ArchimateDiagramModelFactory) CreateConnectionRequest(org.eclipse.gef.requests.CreateConnectionRequest) Test(org.junit.Test)

Aggregations

CreateConnectionRequest (org.eclipse.gef.requests.CreateConnectionRequest)16 Command (org.eclipse.gef.commands.Command)8 ArchimateDiagramModelFactory (com.archimatetool.editor.diagram.ArchimateDiagramModelFactory)5 CreateDiagramArchimateConnectionWithDialogCommand (com.archimatetool.editor.diagram.commands.CreateDiagramArchimateConnectionWithDialogCommand)5 CreateDiagramConnectionCommand (com.archimatetool.editor.diagram.commands.CreateDiagramConnectionCommand)4 Point (org.eclipse.draw2d.geometry.Point)4 Test (org.junit.Test)4 EditPart (org.eclipse.gef.EditPart)3 ReconnectRequest (org.eclipse.gef.requests.ReconnectRequest)3 AbstractBaseEditPart (com.archimatetool.editor.diagram.editparts.AbstractBaseEditPart)2 GroupEditPart (com.archimatetool.editor.diagram.editparts.diagram.GroupEditPart)2 IDiagramModelArchimateComponent (com.archimatetool.model.IDiagramModelArchimateComponent)2 ChopboxAnchor (org.eclipse.draw2d.ChopboxAnchor)2 IFigure (org.eclipse.draw2d.IFigure)2 PointList (org.eclipse.draw2d.geometry.PointList)2 GraphicalEditPart (org.eclipse.gef.GraphicalEditPart)2 EConnectionCategory (org.talend.core.model.process.EConnectionCategory)2 EConnectionType (org.talend.core.model.process.EConnectionType)2 IConnection (org.talend.core.model.process.IConnection)2 IExternalNode (org.talend.core.model.process.IExternalNode)2