use of com.archimatetool.model.IDiagramModelContainer in project archi by archimatetool.
the class DiagramModelUtils method shouldBeHiddenConnection.
/**
* @param connection The connection to check
* @return true if a connection should be hidden when its source (parent) element contains its target (child) element
*/
public static boolean shouldBeHiddenConnection(IDiagramModelArchimateConnection connection) {
if (!ConnectionPreferences.useNestedConnections()) {
return false;
}
// Only if the connection's source and target are both ArchiMate concepts
if (!(connection.getSource() instanceof IDiagramModelArchimateComponent) && !(connection.getTarget() instanceof IDiagramModelArchimateComponent)) {
return false;
}
IDiagramModelArchimateComponent source = (IDiagramModelArchimateComponent) connection.getSource();
IDiagramModelArchimateComponent target = (IDiagramModelArchimateComponent) connection.getTarget();
// If the connection's source element contains the target element, or the connection's target element contains the source element
if (source instanceof IDiagramModelArchimateObject && target instanceof IDiagramModelArchimateObject) {
if (((IDiagramModelContainer) source).getChildren().contains((IDiagramModelArchimateObject) target) || ((IDiagramModelContainer) target).getChildren().contains((IDiagramModelArchimateObject) source)) {
// And it's a relationship type we have chosen to hide
for (EClass eClass : ConnectionPreferences.getRelationsClassesForHiding()) {
if (connection.getArchimateRelationship().eClass() == eClass) {
return true;
}
}
}
}
// If connection's source is an element and target is a connection
if (source instanceof IDiagramModelArchimateObject && target instanceof IDiagramModelArchimateConnection) {
IDiagramModelArchimateObject parent = (IDiagramModelArchimateObject) source;
IConnectable connectionSource = ((IDiagramModelArchimateConnection) target).getSource();
IConnectable connectionTarget = ((IDiagramModelArchimateConnection) target).getTarget();
if (parent.getChildren().contains(connectionSource) && parent.getChildren().contains(connectionTarget)) {
// And it's a relationship type we have chosen to hide
for (EClass eClass : ConnectionPreferences.getRelationsClassesForHiding()) {
if (connection.getArchimateRelationship().eClass() == eClass) {
return true;
}
}
}
}
// TODO: Not sure if this directionality should be allowed
if (target instanceof IDiagramModelArchimateObject && source instanceof IDiagramModelArchimateConnection) {
IDiagramModelArchimateObject parent = (IDiagramModelArchimateObject) target;
IConnectable connectionSource = ((IDiagramModelArchimateConnection) source).getSource();
IConnectable connectionTarget = ((IDiagramModelArchimateConnection) source).getTarget();
if (parent.getChildren().contains(connectionSource) && parent.getChildren().contains(connectionTarget)) {
// And it's a relationship type we have chosen to hide
for (EClass eClass : ConnectionPreferences.getRelationsClassesForHiding()) {
if (connection.getArchimateRelationship().eClass() == eClass) {
return true;
}
}
}
}
return false;
}
use of com.archimatetool.model.IDiagramModelContainer in project archi by archimatetool.
the class CopySnapshot method createPasteObject.
private IDiagramModelObject createPasteObject(IDiagramModelContainer container, IDiagramModelObject snapshotObject) {
// Don't paste invalid objects
if (!isValidPasteComponent(fTargetDiagramModel, snapshotObject)) {
return null;
}
IDiagramModelObject pasteObject = (IDiagramModelObject) snapshotObject.getCopy();
createID(pasteObject);
// Offset top level objects if container is diagram
if (container instanceof IDiagramModel) {
IDiagramModelObject originalObject = (IDiagramModelObject) fOriginalToSnapshotComponentsMapping.getKey(snapshotObject);
IBounds bounds = originalObject.getBounds().getCopy();
Point pt = new Point(bounds.getX(), bounds.getY());
translateToAbsolute(originalObject, pt);
bounds.setX(pt.x + fXOffSet);
bounds.setY(pt.y + fYOffSet);
pasteObject.setBounds(bounds);
}
// If Archimate object
if (pasteObject instanceof IDiagramModelArchimateObject) {
IDiagramModelArchimateObject dmo = (IDiagramModelArchimateObject) pasteObject;
// Re-use original ArchiMate components
if (!fDoCreateNewArchimateComponents) {
IDiagramModelArchimateObject originalDiagramObject = (IDiagramModelArchimateObject) fOriginalToSnapshotComponentsMapping.getKey(snapshotObject);
IArchimateElement element = originalDiagramObject.getArchimateElement();
dmo.setArchimateElement(element);
}
// Provide new names if required
if (fDoCreateNewArchimateComponents && isSourceAndTargetArchiMateModelSame()) {
String name = dmo.getArchimateElement().getName();
// $NON-NLS-1$
dmo.getArchimateElement().setName(name + " " + Messages.CopySnapshot_1);
}
}
// Add to Mapping
fSnapshotToNewComponentMapping.put(snapshotObject, pasteObject);
// Object is Container, so recurse
if (snapshotObject instanceof IDiagramModelContainer) {
for (IDiagramModelObject child : ((IDiagramModelContainer) snapshotObject).getChildren()) {
IDiagramModelObject dmo = createPasteObject((IDiagramModelContainer) pasteObject, child);
if (dmo != null) {
((IDiagramModelContainer) pasteObject).getChildren().add(dmo);
}
}
}
return pasteObject;
}
use of com.archimatetool.model.IDiagramModelContainer 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.IDiagramModelContainer in project archi by archimatetool.
the class SendBackwardAction method createCommand.
private Command createCommand(List<?> selection) {
GraphicalViewer viewer = getWorkbenchPart().getAdapter(GraphicalViewer.class);
CompoundCommand result = new CompoundCommand(TEXT);
for (Object object : selection) {
if (object instanceof GraphicalEditPart) {
GraphicalEditPart editPart = (GraphicalEditPart) object;
Object model = editPart.getModel();
// This can happen if we do things wrong
if (viewer != editPart.getViewer()) {
// $NON-NLS-1$
System.err.println("Wrong selection for Viewer in " + getClass());
}
// Locked
if (model instanceof ILockable && ((ILockable) model).isLocked()) {
continue;
}
if (model instanceof IDiagramModelObject) {
IDiagramModelObject diagramObject = (IDiagramModelObject) model;
IDiagramModelContainer parent = (IDiagramModelContainer) diagramObject.eContainer();
/*
* Parent can be null when objects are selected (with marquee tool) and transferred from one container
* to another and the Diagram Editor updates the enablement state of Actions.
*/
if (parent == null) {
continue;
}
int originalPos = parent.getChildren().indexOf(diagramObject);
if (originalPos > 0) {
result.add(new SendBackwardCommand(parent, originalPos));
}
}
}
}
return result.unwrap();
}
use of com.archimatetool.model.IDiagramModelContainer in project archi by archimatetool.
the class HTMLReportExporter method addNewBounds.
/**
* Add new bounds for each diagram object in relation to its parent offset x,y
*/
private void addNewBounds(IDiagramModelObject dmo, int offsetX, int offsetY) {
// Add new bounds caled to device zoom
BoundsWithAbsolutePosition newBounds = new BoundsWithAbsolutePosition(dmo.getBounds(), ImageFactory.getDeviceZoom() / 100);
// Add offset
newBounds.setOffset(offsetX, offsetY);
childBoundsMap.put(dmo.getId(), newBounds);
// Children
if (dmo instanceof IDiagramModelArchimateObject || dmo instanceof IDiagramModelGroup) {
for (IDiagramModelObject child : ((IDiagramModelContainer) dmo).getChildren()) {
addNewBounds(child, newBounds.getX1(), newBounds.getY1());
}
}
}
Aggregations