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);
}
}
}
}
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;
}
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;
}
Aggregations