Search in sources :

Example 31 with IDiagramModelConnection

use of com.archimatetool.model.IDiagramModelConnection in project archi by archimatetool.

the class DeleteNestedConnectionsCommand method createDeleteCommands.

/**
 * Child Objects that have connections
 */
void createDeleteCommands() {
    for (IDiagramModelArchimateObject child : fChildObjects) {
        for (IDiagramModelConnection connection : child.getTargetConnections()) {
            if (connection instanceof IDiagramModelArchimateConnection && DiagramModelUtils.shouldBeHiddenConnection((IDiagramModelArchimateConnection) connection)) {
                for (IDiagramModelConnection subconnection : connection.getTargetConnections()) {
                    Command cmd = DiagramCommandFactory.createDeleteDiagramConnectionCommand(subconnection);
                    add(cmd);
                }
                for (IDiagramModelConnection subconnection : connection.getSourceConnections()) {
                    Command cmd = DiagramCommandFactory.createDeleteDiagramConnectionCommand(subconnection);
                    add(cmd);
                }
            }
        }
    }
}
Also used : Command(org.eclipse.gef.commands.Command) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) IDiagramModelArchimateConnection(com.archimatetool.model.IDiagramModelArchimateConnection) IDiagramModelConnection(com.archimatetool.model.IDiagramModelConnection) IDiagramModelArchimateObject(com.archimatetool.model.IDiagramModelArchimateObject)

Example 32 with IDiagramModelConnection

use of com.archimatetool.model.IDiagramModelConnection in project archi by archimatetool.

the class DiagramModelObjectTests method testAddConnection.

@Test
public void testAddConnection() {
    IDiagramModelConnection conn = IArchimateFactory.eINSTANCE.createDiagramModelConnection();
    // Should not be added if connection source or target not set
    object.addConnection(conn);
    assertTrue(object.getSourceConnections().isEmpty());
    assertTrue(object.getTargetConnections().isEmpty());
    // Now should be OK
    conn.connect(object, object);
    object.addConnection(conn);
    assertTrue(object.getSourceConnections().contains(conn));
    assertTrue(object.getTargetConnections().contains(conn));
}
Also used : IDiagramModelConnection(com.archimatetool.model.IDiagramModelConnection) Test(org.junit.Test)

Example 33 with IDiagramModelConnection

use of com.archimatetool.model.IDiagramModelConnection in project archi by archimatetool.

the class DiagramModelObjectTests method testGetCopy.

@Override
@Test
public void testGetCopy() {
    super.testGetCopy();
    IDiagramModelConnection conn = IArchimateFactory.eINSTANCE.createDiagramModelConnection();
    conn.connect(object, object);
    object.addConnection(conn);
    assertTrue(object.getSourceConnections().contains(conn));
    assertTrue(object.getTargetConnections().contains(conn));
    IBounds bounds = IArchimateFactory.eINSTANCE.createBounds(2, 4, 6, 8);
    object.setBounds(bounds);
    IDiagramModelObject copy = (IDiagramModelObject) object.getCopy();
    assertNotSame(object, copy);
    assertTrue(copy.getSourceConnections().isEmpty());
    assertTrue(copy.getTargetConnections().isEmpty());
    assertNotSame(bounds, copy.getBounds());
    assertEquals(bounds.getX(), copy.getBounds().getX());
    assertEquals(bounds.getY(), copy.getBounds().getY());
    assertEquals(bounds.getWidth(), copy.getBounds().getWidth());
    assertEquals(bounds.getHeight(), copy.getBounds().getHeight());
}
Also used : IBounds(com.archimatetool.model.IBounds) IDiagramModelConnection(com.archimatetool.model.IDiagramModelConnection) IDiagramModelObject(com.archimatetool.model.IDiagramModelObject) Test(org.junit.Test)

Example 34 with IDiagramModelConnection

use of com.archimatetool.model.IDiagramModelConnection in project archi by archimatetool.

the class DeleteCommandHandler method createCommands.

/**
 * Create the Delete Commands
 */
private void createCommands() {
    /*
         *  We need to ensure that the Delete Diagram Model Commands are called first in order to close
         *  any open diagram editors before removing their models from parent folders.
         */
    for (Object object : fElementsToDelete) {
        if (object instanceof IDiagramModel) {
            CompoundCommand compoundCommand = getCompoundCommand((IAdapter) object);
            if (compoundCommand != null) {
                Command cmd = new DeleteDiagramModelCommand((IDiagramModel) object);
                compoundCommand.add(cmd);
            } else {
                // $NON-NLS-1$
                System.err.println("Could not get CompoundCommand in " + getClass());
            }
        }
    }
    /*
         * Then the other types
         */
    for (Object object : fElementsToDelete) {
        if (object instanceof IDiagramModel) {
            // already done
            continue;
        }
        CompoundCommand compoundCommand = getCompoundCommand((IAdapter) object);
        if (compoundCommand == null) {
            // sanity check
            // $NON-NLS-1$
            System.err.println("Could not get CompoundCommand in " + getClass());
            continue;
        }
        if (object instanceof IFolder) {
            Command cmd = new DeleteFolderCommand((IFolder) object);
            compoundCommand.add(cmd);
        } else if (object instanceof IArchimateElement) {
            Command cmd = new DeleteArchimateElementCommand((IArchimateElement) object);
            compoundCommand.add(cmd);
        } else if (object instanceof IArchimateRelationship) {
            Command cmd = new DeleteArchimateRelationshipCommand((IArchimateRelationship) object);
            compoundCommand.add(cmd);
        } else if (object instanceof IDiagramModelObject) {
            Command cmd = DiagramCommandFactory.createDeleteDiagramObjectCommand((IDiagramModelObject) object);
            compoundCommand.add(cmd);
        } else if (object instanceof IDiagramModelConnection) {
            Command cmd = DiagramCommandFactory.createDeleteDiagramConnectionCommand((IDiagramModelConnection) object);
            compoundCommand.add(cmd);
        }
    }
}
Also used : DeleteArchimateElementCommand(com.archimatetool.editor.model.commands.DeleteArchimateElementCommand) DeleteArchimateRelationshipCommand(com.archimatetool.editor.model.commands.DeleteArchimateRelationshipCommand) IDiagramModelConnection(com.archimatetool.model.IDiagramModelConnection) IDiagramModelObject(com.archimatetool.model.IDiagramModelObject) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) DeleteFolderCommand(com.archimatetool.editor.model.commands.DeleteFolderCommand) IDiagramModel(com.archimatetool.model.IDiagramModel) DeleteArchimateRelationshipCommand(com.archimatetool.editor.model.commands.DeleteArchimateRelationshipCommand) DeleteArchimateElementCommand(com.archimatetool.editor.model.commands.DeleteArchimateElementCommand) DeleteDiagramModelCommand(com.archimatetool.editor.model.commands.DeleteDiagramModelCommand) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) DeleteFolderCommand(com.archimatetool.editor.model.commands.DeleteFolderCommand) Command(org.eclipse.gef.commands.Command) DeleteDiagramModelCommand(com.archimatetool.editor.model.commands.DeleteDiagramModelCommand) IArchimateElement(com.archimatetool.model.IArchimateElement) IDiagramModelObject(com.archimatetool.model.IDiagramModelObject) EObject(org.eclipse.emf.ecore.EObject) IArchimateRelationship(com.archimatetool.model.IArchimateRelationship) IFolder(com.archimatetool.model.IFolder)

Aggregations

IDiagramModelConnection (com.archimatetool.model.IDiagramModelConnection)34 Test (org.junit.Test)15 IDiagramModelObject (com.archimatetool.model.IDiagramModelObject)10 IArchimateRelationship (com.archimatetool.model.IArchimateRelationship)7 IDiagramModelArchimateConnection (com.archimatetool.model.IDiagramModelArchimateConnection)6 CompoundCommand (org.eclipse.gef.commands.CompoundCommand)6 IDiagramModelArchimateObject (com.archimatetool.model.IDiagramModelArchimateObject)5 Command (org.eclipse.gef.commands.Command)5 IArchimateElement (com.archimatetool.model.IArchimateElement)4 IConnectable (com.archimatetool.model.IConnectable)4 IDiagramModel (com.archimatetool.model.IDiagramModel)4 EditPart (org.eclipse.gef.EditPart)4 ReconnectDiagramConnectionCommand (com.archimatetool.editor.diagram.commands.ReconnectDiagramConnectionCommand)3 EmptyEditPart (com.archimatetool.editor.diagram.editparts.diagram.EmptyEditPart)3 ArrayList (java.util.ArrayList)3 ConnectionTextPositionCommand (com.archimatetool.editor.diagram.commands.ConnectionTextPositionCommand)2 LineWidthCommand (com.archimatetool.editor.diagram.commands.LineWidthCommand)2 DiagramConnectionEditPart (com.archimatetool.editor.diagram.editparts.DiagramConnectionEditPart)2 DeleteArchimateElementCommand (com.archimatetool.editor.model.commands.DeleteArchimateElementCommand)2 DeleteArchimateRelationshipCommand (com.archimatetool.editor.model.commands.DeleteArchimateRelationshipCommand)2