use of com.archimatetool.model.IDiagramModelArchimateConnection in project archi by archimatetool.
the class NestedElementsChecker method isNestedWithoutValidRelation.
private boolean isNestedWithoutValidRelation(IDiagramModelArchimateObject parent, IDiagramModelArchimateObject child) {
IArchimateElement parentElement = parent.getArchimateElement();
IArchimateElement childElement = child.getArchimateElement();
// Ignore nested Junctions
if (childElement instanceof IJunction) {
return false;
}
// Get all diagram connections between parent and child objects
List<IDiagramModelConnection> connections = new ArrayList<>(parent.getSourceConnections());
connections.addAll(parent.getTargetConnections());
for (IDiagramModelConnection connection : connections) {
// If this is an ArchiMate connection...
if (connection instanceof IDiagramModelArchimateConnection && (connection.getSource() == child || connection.getTarget() == child)) {
// Get its relationship
IArchimateRelationship relation = ((IDiagramModelArchimateConnection) connection).getArchimateRelationship();
// Check for non-nested type relationships
if (!isNestedTypeRelationship(relation)) {
return true;
}
// Specialization relationship needs a special check as it goes the other way around
if (relation instanceof ISpecializationRelationship) {
if (relation.getTarget() == childElement) {
return true;
}
} else // Else reversed nested
if (relation.getSource() == childElement && isNestedTypeRelationship(relation)) {
return true;
}
}
}
// Check for any nested type relationships in the model, return false if one is found
for (IArchimateRelationship relation : ArchimateModelUtils.getAllRelationshipsForConcept(parentElement)) {
if ((relation.getTarget() == childElement || relation.getSource() == childElement) && isNestedTypeRelationship(relation)) {
return false;
}
}
return true;
}
use of com.archimatetool.model.IDiagramModelArchimateConnection in project archi by archimatetool.
the class CreateDiagramArchimateConnectionWithDialogCommandTests method testCreationOfConnectionAndRelationship.
@Test
public void testCreationOfConnectionAndRelationship() {
ArchimateTestModel tm = new ArchimateTestModel();
IArchimateModel model = tm.createNewModel();
IDiagramModelArchimateObject dmo1 = tm.createDiagramModelArchimateObjectAndAddToModel(IArchimateFactory.eINSTANCE.createBusinessActor());
IDiagramModelArchimateObject dmo2 = tm.createDiagramModelArchimateObjectAndAddToModel(IArchimateFactory.eINSTANCE.createBusinessRole());
model.getDefaultDiagramModel().getChildren().add(dmo1);
model.getDefaultDiagramModel().getChildren().add(dmo2);
cmd.setSource(dmo1);
cmd.setTarget(dmo2);
cmd.execute();
IDiagramModelConnection connection = cmd.fConnection;
assertTrue(connection instanceof IDiagramModelArchimateConnection);
assertSame(dmo1, connection.getSource());
assertSame(dmo2, connection.getTarget());
IArchimateRelationship relationship = ((IDiagramModelArchimateConnection) connection).getArchimateRelationship();
assertTrue(relationship instanceof IAssignmentRelationship);
assertNotNull(relationship.eContainer());
cmd.undo();
assertNull(relationship.eContainer());
}
use of com.archimatetool.model.IDiagramModelArchimateConnection in project archi by archimatetool.
the class XMLModelImporter method addConnections.
// ======================================= Connections ====================================
private void addConnections(Element viewElement) throws XMLModelParserException {
class ConnectionInfo {
IDiagramModelConnection connection;
Element connectionElement;
}
List<ConnectionInfo> connectionInfoList = new ArrayList<>();
// 1st pass - Create all connections
for (Element connectionElement : viewElement.getChildren(ELEMENT_CONNECTION, ARCHIMATE3_NAMESPACE)) {
IDiagramModelConnection connection = null;
// An ArchiMate relationship connection
String relationshipRef = connectionElement.getAttributeValue(ATTRIBUTE_RELATIONSHIPREF);
if (hasValue(relationshipRef)) {
// Get relationship
IArchimateConcept concept = fConceptsLookup.get(relationshipRef);
if (!(concept instanceof IArchimateRelationship)) {
throw new XMLModelParserException(Messages.XMLModelImporter_7 + relationshipRef);
}
// Create new ArchiMate connection with relationship
connection = ArchimateDiagramModelFactory.createDiagramModelArchimateConnection((IArchimateRelationship) concept);
} else // Create new ordinary connection
{
connection = IArchimateFactory.eINSTANCE.createDiagramModelConnection();
}
// Add id and add to lookup table
if (connection != null) {
// Add Identifier before adding to model
String identifier = connectionElement.getAttributeValue(ATTRIBUTE_IDENTIFIER);
connection.setId(identifier);
// Add to connection list for 2nd pass
ConnectionInfo cInfo = new ConnectionInfo();
cInfo.connection = connection;
cInfo.connectionElement = connectionElement;
connectionInfoList.add(cInfo);
// Add to lookup
fConnectionsNodesLookup.put(connection.getId(), connection);
}
}
// 2nd pass
for (ConnectionInfo cInfo : connectionInfoList) {
// Get connection source node/connection
String sourceRef = cInfo.connectionElement.getAttributeValue(ATTRIBUTE_SOURCE);
IConnectable connectableSource = fConnectionsNodesLookup.get(sourceRef);
if (connectableSource == null) {
throw new XMLModelParserException(Messages.XMLModelImporter_9 + sourceRef);
}
// Get connection target node/connection
String targetRef = cInfo.connectionElement.getAttributeValue(ATTRIBUTE_TARGET);
IConnectable connectableTarget = fConnectionsNodesLookup.get(targetRef);
if (connectableTarget == null) {
throw new XMLModelParserException(Messages.XMLModelImporter_10 + targetRef);
}
// If an ArchiMate connection, source and target must be also
if (cInfo.connection instanceof IDiagramModelArchimateConnection) {
// Must be ArchiMate type source
if (!(connectableSource instanceof IDiagramModelArchimateComponent)) {
throw new XMLModelParserException(Messages.XMLModelImporter_11 + sourceRef);
}
// Must be ArchiMate type target
if (!(connectableTarget instanceof IDiagramModelArchimateComponent)) {
throw new XMLModelParserException(Messages.XMLModelImporter_12 + targetRef);
}
} else // Another connection type
{
// Only connect between notes and groups
if (connectableSource instanceof IDiagramModelArchimateComponent && connectableTarget instanceof IDiagramModelArchimateComponent) {
continue;
}
// Don't connect to other connections
if (connectableSource instanceof IDiagramModelConnection || connectableTarget instanceof IDiagramModelConnection) {
continue;
}
}
// Connect
cInfo.connection.connect(connectableSource, connectableTarget);
// Bendpoints
addBendpoints(cInfo.connection, cInfo.connectionElement);
// Style
addConnectionStyle(cInfo.connection, cInfo.connectionElement.getChild(ELEMENT_STYLE, ARCHIMATE3_NAMESPACE));
}
// Add implicit nested connections
addNestedConnections();
}
use of com.archimatetool.model.IDiagramModelArchimateConnection in project archi by archimatetool.
the class XMLModelImporter method addNestedConnections.
/**
* Add implicit nested connections
* 1. Iterate through all diagram ArchiMate nodes and look for nested nodes
* 2. If there is a relationship between the ArchiMate elements of the nodes and no existing connection, add one
*/
private void addNestedConnections() {
for (IDiagramModel dm : fModel.getDiagramModels()) {
// All diagrams
for (Iterator<EObject> iter = dm.eAllContents(); iter.hasNext(); ) {
// Contents of the diagram
EObject eObject = iter.next();
if (eObject instanceof IDiagramModelArchimateObject) {
// ArchiMate node
IDiagramModelArchimateObject parent = (IDiagramModelArchimateObject) eObject;
for (IDiagramModelObject dmo : parent.getChildren()) {
if (dmo instanceof IDiagramModelArchimateObject) {
// ArchiMate child node
IDiagramModelArchimateObject child = (IDiagramModelArchimateObject) dmo;
IArchimateElement parentElement = parent.getArchimateElement();
IArchimateElement childElement = child.getArchimateElement();
// Parent -> Child
for (IArchimateRelationship relation : List.copyOf(parentElement.getSourceRelationships())) {
// work on a copy of the list
if (relation.getTarget() == childElement && !DiagramModelUtils.hasDiagramModelArchimateConnection(parent, child, relation)) {
IDiagramModelArchimateConnection connection = ArchimateDiagramModelFactory.createDiagramModelArchimateConnection(relation);
connection.connect(parent, child);
}
}
// Child -> Parent
for (IArchimateRelationship relation : List.copyOf(childElement.getSourceRelationships())) {
// work on a copy of the list
if (relation.getTarget() == parentElement && !DiagramModelUtils.hasDiagramModelArchimateConnection(child, parent, relation)) {
IDiagramModelArchimateConnection connection = ArchimateDiagramModelFactory.createDiagramModelArchimateConnection(relation);
connection.connect(child, parent);
}
}
}
}
}
}
}
}
use of com.archimatetool.model.IDiagramModelArchimateConnection in project archi by archimatetool.
the class FormatPainterToolTests method testCreateCommandForDiagramModelArchimateConnection.
@Test
public void testCreateCommandForDiagramModelArchimateConnection() throws Exception {
// Source component
IDiagramModelArchimateConnection sourceComponent = ArchimateTestModel.createDiagramModelArchimateConnection(IArchimateFactory.eINSTANCE.createAccessRelationship());
// Target component
IDiagramModelArchimateConnection targetComponent = ArchimateTestModel.createDiagramModelArchimateConnection(IArchimateFactory.eINSTANCE.createAccessRelationship());
// Set FormatPainterInfo to Source component
FormatPainterInfo.INSTANCE.updatePaintFormat(sourceComponent);
PaintFormat pf = FormatPainterInfo.INSTANCE.getPaintFormat();
// Execute command
FormatPainterTool tool = new FormatPainterTool();
CompoundCommand compoundCmd = tool.createCommand(pf, targetComponent);
// Should be no commands
assertEquals(0, compoundCmd.getCommands().size());
// Now change some properties on the source component
sourceComponent.setFont("Consolas");
sourceComponent.setFontColor("#eeeeee");
sourceComponent.setLineColor("#eeeeee");
sourceComponent.setLineWidth(3);
sourceComponent.setTextPosition(3);
compoundCmd = tool.createCommand(pf, targetComponent);
assertEquals(5, compoundCmd.getCommands().size());
}
Aggregations