Search in sources :

Example 6 with IConnectable

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

the class CopySnapshot method getMinimumPoint.

// Find leftmost and topmost origin of top level objects
private Point getMinimumPoint(Set<IConnectable> selectedObjects) {
    // flag values
    int xOrigin = 99999, yOrigin = 99999;
    for (IConnectable object : selectedObjects) {
        if (object instanceof IDiagramModelObject) {
            IDiagramModelObject dmo = (IDiagramModelObject) object;
            Point pt = new Point(dmo.getBounds().getX(), dmo.getBounds().getY());
            translateToAbsolute(dmo, pt);
            // If this object has a parent that is also selected, ignore it
            if (dmo.eContainer() instanceof IDiagramModelObject && selectedObjects.contains(dmo.eContainer())) {
                continue;
            }
            if (pt.x < xOrigin) {
                xOrigin = pt.x;
            }
            if (pt.y < yOrigin) {
                yOrigin = pt.y;
            }
        }
    }
    return (xOrigin == 99999 || yOrigin == 99999) ? null : new Point(xOrigin, yOrigin);
}
Also used : IConnectable(com.archimatetool.model.IConnectable) IDiagramModelObject(com.archimatetool.model.IDiagramModelObject) Point(org.eclipse.draw2d.geometry.Point) Point(org.eclipse.draw2d.geometry.Point)

Example 7 with IConnectable

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

the class CopySnapshot method createSnapshotConnectionsForSelectedComponents.

/*
     * Create copies of connections that have been selected (if source and target also have been selected/mapped)
     */
private void createSnapshotConnectionsForSelectedComponents(List<IDiagramModelComponent> selected) {
    // Create new connection copies for all selected connections, but don't connect them yet
    for (IDiagramModelComponent component : selected) {
        if (component instanceof IDiagramModelConnection) {
            IDiagramModelConnection connection = (IDiagramModelConnection) component;
            // The source and the target object must also be selected
            if (isSelectedConnectionCopyable(connection, selected)) {
                IDiagramModelConnection newConnection = (IDiagramModelConnection) connection.getCopy();
                fOriginalToSnapshotComponentsMapping.put(connection, newConnection);
            }
        }
    }
    // Now connect both ends if both ends are also in the selection/mapping
    for (Entry<IConnectable, IConnectable> entry : fOriginalToSnapshotComponentsMapping.entrySet()) {
        if (entry.getKey() instanceof IDiagramModelConnection) {
            IDiagramModelConnection originalConnection = (IDiagramModelConnection) entry.getKey();
            IConnectable newSource = fOriginalToSnapshotComponentsMapping.get(originalConnection.getSource());
            IConnectable newTarget = fOriginalToSnapshotComponentsMapping.get(originalConnection.getTarget());
            if (newSource != null && newTarget != null) {
                IDiagramModelConnection newConnection = (IDiagramModelConnection) entry.getValue();
                newConnection.connect(newSource, newTarget);
            }
        }
    }
}
Also used : IConnectable(com.archimatetool.model.IConnectable) IDiagramModelComponent(com.archimatetool.model.IDiagramModelComponent) IDiagramModelConnection(com.archimatetool.model.IDiagramModelConnection)

Example 8 with IConnectable

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

the class CopySnapshot method createPasteConnections.

private List<IDiagramModelConnection> createPasteConnections() {
    List<IDiagramModelConnection> connections = new ArrayList<IDiagramModelConnection>();
    // Create new connections from basis of snapshot
    for (IConnectable connectable : fOriginalToSnapshotComponentsMapping.values()) {
        if (connectable instanceof IDiagramModelConnection) {
            IDiagramModelConnection snapshotConnection = (IDiagramModelConnection) connectable;
            IDiagramModelConnection newConnection = (IDiagramModelConnection) snapshotConnection.getCopy();
            createID(newConnection);
            connections.add(newConnection);
            // Mapping
            fSnapshotToNewComponentMapping.put(snapshotConnection, newConnection);
            // Re-use original Archimate relationship if required
            if (!fDoCreateNewArchimateComponents && snapshotConnection instanceof IDiagramModelArchimateConnection) {
                IDiagramModelArchimateConnection originalDiagramConnection = (IDiagramModelArchimateConnection) fOriginalToSnapshotComponentsMapping.getKey(snapshotConnection);
                IArchimateRelationship relationship = originalDiagramConnection.getArchimateRelationship();
                ((IDiagramModelArchimateConnection) newConnection).setArchimateRelationship(relationship);
            }
        }
    }
    // Connect them
    for (Entry<IConnectable, IConnectable> entry : fSnapshotToNewComponentMapping.entrySet()) {
        if (entry.getKey() instanceof IDiagramModelConnection) {
            IDiagramModelConnection snapshotConnection = (IDiagramModelConnection) entry.getKey();
            IConnectable newSource = fSnapshotToNewComponentMapping.get(snapshotConnection.getSource());
            IConnectable newTarget = fSnapshotToNewComponentMapping.get(snapshotConnection.getTarget());
            if (newSource != null && newTarget != null) {
                IDiagramModelConnection newConnection = (IDiagramModelConnection) entry.getValue();
                newConnection.connect(newSource, newTarget);
            }
        }
    }
    return connections;
}
Also used : IConnectable(com.archimatetool.model.IConnectable) IDiagramModelArchimateConnection(com.archimatetool.model.IDiagramModelArchimateConnection) IDiagramModelConnection(com.archimatetool.model.IDiagramModelConnection) ArrayList(java.util.ArrayList) IArchimateRelationship(com.archimatetool.model.IArchimateRelationship)

Example 9 with IConnectable

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

the class CopySnapshot method createAutomaticSnapshotConnections.

/*
     * Create automatic copies of connections (if source and target also have been selected/mapped)
     */
private void createAutomaticSnapshotConnections() {
    List<IDiagramModelConnection> allConnections = new ArrayList<IDiagramModelConnection>();
    // Get all connections from objects
    for (IConnectable connectable : fOriginalToSnapshotComponentsMapping.keySet()) {
        for (IDiagramModelConnection connection : connectable.getSourceConnections()) {
            if (!allConnections.contains(connection)) {
                allConnections.add(connection);
            }
        }
        for (IDiagramModelConnection connection : connectable.getTargetConnections()) {
            if (!allConnections.contains(connection)) {
                allConnections.add(connection);
            }
        }
    }
    // Create copies of ones that have both ends
    for (IDiagramModelConnection connection : allConnections) {
        if (isSelectedConnectionCopyable(connection, allConnections)) {
            IDiagramModelConnection newConnection = (IDiagramModelConnection) connection.getCopy();
            fOriginalToSnapshotComponentsMapping.put(connection, newConnection);
        }
    }
    // Now connect both ends if both ends are also in the mapping
    for (Entry<IConnectable, IConnectable> entry : fOriginalToSnapshotComponentsMapping.entrySet()) {
        if (entry.getKey() instanceof IDiagramModelConnection) {
            IDiagramModelConnection originalConnection = (IDiagramModelConnection) entry.getKey();
            IConnectable newSource = fOriginalToSnapshotComponentsMapping.get(originalConnection.getSource());
            IConnectable newTarget = fOriginalToSnapshotComponentsMapping.get(originalConnection.getTarget());
            if (newSource != null && newTarget != null) {
                IDiagramModelConnection newConnection = (IDiagramModelConnection) entry.getValue();
                newConnection.connect(newSource, newTarget);
            } else {
                // $NON-NLS-1$
                System.err.println("No source or target in CopySnapshot!");
            }
        }
    }
}
Also used : IConnectable(com.archimatetool.model.IConnectable) IDiagramModelConnection(com.archimatetool.model.IDiagramModelConnection) ArrayList(java.util.ArrayList)

Example 10 with IConnectable

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

the class DiagramModelConnection method setSource.

/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
public void setSource(IConnectable newSource) {
    IConnectable oldSource = source;
    source = newSource;
    if (eNotificationRequired())
        eNotify(new ENotificationImpl(this, Notification.SET, IArchimatePackage.DIAGRAM_MODEL_CONNECTION__SOURCE, oldSource, source));
}
Also used : IConnectable(com.archimatetool.model.IConnectable) ENotificationImpl(org.eclipse.emf.ecore.impl.ENotificationImpl)

Aggregations

IConnectable (com.archimatetool.model.IConnectable)14 EClass (org.eclipse.emf.ecore.EClass)5 IDiagramModelArchimateComponent (com.archimatetool.model.IDiagramModelArchimateComponent)4 IDiagramModelArchimateConnection (com.archimatetool.model.IDiagramModelArchimateConnection)4 IDiagramModelConnection (com.archimatetool.model.IDiagramModelConnection)4 CreateDiagramConnectionCommand (com.archimatetool.editor.diagram.commands.CreateDiagramConnectionCommand)3 IArchimateRelationship (com.archimatetool.model.IArchimateRelationship)3 ArrayList (java.util.ArrayList)3 IArchimateConcept (com.archimatetool.model.IArchimateConcept)2 IDiagramModel (com.archimatetool.model.IDiagramModel)2 IDiagramModelArchimateObject (com.archimatetool.model.IDiagramModelArchimateObject)2 IDiagramModelComponent (com.archimatetool.model.IDiagramModelComponent)2 Point (org.eclipse.draw2d.geometry.Point)2 ENotificationImpl (org.eclipse.emf.ecore.impl.ENotificationImpl)2 CompoundCommand (org.eclipse.gef.commands.CompoundCommand)2 AddDiagramModelReferenceCommand (com.archimatetool.editor.diagram.commands.AddDiagramModelReferenceCommand)1 AddDiagramObjectCommand (com.archimatetool.editor.diagram.commands.AddDiagramObjectCommand)1 CreateDiagramArchimateConnectionWithDialogCommand (com.archimatetool.editor.diagram.commands.CreateDiagramArchimateConnectionWithDialogCommand)1 CreateNestedArchimateConnectionsWithDialogCommand (com.archimatetool.editor.diagram.commands.CreateNestedArchimateConnectionsWithDialogCommand)1 ReconnectDiagramConnectionCommand (com.archimatetool.editor.diagram.commands.ReconnectDiagramConnectionCommand)1