Search in sources :

Example 16 with IDiagramModelComponent

use of com.archimatetool.model.IDiagramModelComponent 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 17 with IDiagramModelComponent

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

the class CopySnapshot method getTopLevelObjectsToCopy.

/*
     * Create a list of topmost objects to copy.
     * This will eliminate duplicate selected children and give us only the top level objects to copy.
     */
private List<IDiagramModelObject> getTopLevelObjectsToCopy(List<IDiagramModelComponent> selected) {
    List<IDiagramModelObject> objects = new ArrayList<IDiagramModelObject>();
    for (IDiagramModelComponent component : selected) {
        if (component instanceof IDiagramModelObject) {
            if (!hasAncestorSelected((IDiagramModelObject) component, selected)) {
                // if an ancestor is selected don't add that
                objects.add((IDiagramModelObject) component);
            }
        }
    }
    /*
         * Restore the relative Z-Order in this new list by original Z-order in original model
         * If each has the same container parent
         */
    Collections.sort(objects, new Comparator<Object>() {

        public int compare(Object o1, Object o2) {
            if (o1 instanceof IDiagramModelObject && o2 instanceof IDiagramModelObject) {
                IDiagramModelContainer parent1 = (IDiagramModelContainer) ((IDiagramModelObject) o1).eContainer();
                IDiagramModelContainer parent2 = (IDiagramModelContainer) ((IDiagramModelObject) o2).eContainer();
                if (parent1 == parent2) {
                    int index1 = parent1.getChildren().indexOf(o1);
                    int index2 = parent2.getChildren().indexOf(o2);
                    return index1 - index2;
                }
            }
            return 0;
        }
    });
    return objects;
}
Also used : IDiagramModelComponent(com.archimatetool.model.IDiagramModelComponent) ArrayList(java.util.ArrayList) IDiagramModelArchimateObject(com.archimatetool.model.IDiagramModelArchimateObject) IDiagramModelObject(com.archimatetool.model.IDiagramModelObject) EObject(org.eclipse.emf.ecore.EObject) IDiagramModelObject(com.archimatetool.model.IDiagramModelObject) IDiagramModelContainer(com.archimatetool.model.IDiagramModelContainer)

Example 18 with IDiagramModelComponent

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

the class DiagramModelComponent method getCopy.

/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated NOT
 */
public EObject getCopy() {
    IDiagramModelComponent newObject = EcoreUtil.copy(this);
    // need a new ID
    newObject.setId(null);
    return newObject;
}
Also used : IDiagramModelComponent(com.archimatetool.model.IDiagramModelComponent)

Aggregations

IDiagramModelComponent (com.archimatetool.model.IDiagramModelComponent)18 ArrayList (java.util.ArrayList)13 Command (org.eclipse.gef.commands.Command)7 Test (org.junit.Test)6 IArchimateConcept (com.archimatetool.model.IArchimateConcept)5 IDiagramModel (com.archimatetool.model.IDiagramModel)5 IDiagramModelArchimateObject (com.archimatetool.model.IDiagramModelArchimateObject)5 IDiagramModelObject (com.archimatetool.model.IDiagramModelObject)5 IDiagramModelArchimateConnection (com.archimatetool.model.IDiagramModelArchimateConnection)4 EObject (org.eclipse.emf.ecore.EObject)4 IArchimateRelationship (com.archimatetool.model.IArchimateRelationship)3 IDiagramModelArchimateComponent (com.archimatetool.model.IDiagramModelArchimateComponent)3 EditPart (org.eclipse.gef.EditPart)3 CompoundCommand (org.eclipse.gef.commands.CompoundCommand)3 NonNotifyingCompoundCommand (com.archimatetool.editor.model.commands.NonNotifyingCompoundCommand)2 IArchimateElement (com.archimatetool.model.IArchimateElement)2 IDiagramModelReference (com.archimatetool.model.IDiagramModelReference)2 Point (org.eclipse.draw2d.geometry.Point)2 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)2 IArchimateDiagramEditor (com.archimatetool.editor.diagram.IArchimateDiagramEditor)1