use of com.archimatetool.model.IDiagramModelArchimateComponent 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.IDiagramModelArchimateComponent in project archi by archimatetool.
the class ArchimateDiagramConnectionPolicy method getConnectionCreateCommand.
@Override
protected Command getConnectionCreateCommand(CreateConnectionRequest request) {
CreateDiagramConnectionCommand cmd = null;
EClass classType = (EClass) request.getNewObjectType();
IConnectable source = (IConnectable) getHost().getModel();
// Plain Connection
if (classType == IArchimatePackage.eINSTANCE.getDiagramModelConnection()) {
if (isValidConnectionSource(source, classType)) {
cmd = new CreateDiagramConnectionCommand(request);
}
} else // Archimate Model Component Source
if (source instanceof IDiagramModelArchimateComponent) {
if (isValidConnectionSource(source, classType)) {
cmd = new CreateDiagramArchimateConnectionWithDialogCommand(request);
}
}
if (cmd != null) {
cmd.setSource(source);
request.setStartCommand(cmd);
}
return cmd;
}
use of com.archimatetool.model.IDiagramModelArchimateComponent in project archi by archimatetool.
the class DiagramModelUtilsTests method findDiagramModelComponentsForArchimateConcept_Relationship.
@Test
public void findDiagramModelComponentsForArchimateConcept_Relationship() {
IArchimateRelationship relationship = IArchimateFactory.eINSTANCE.createAssociationRelationship();
IDiagramModel diagramModel = tm.addNewArchimateDiagramModel();
// Should not be found
List<IDiagramModelArchimateComponent> list = DiagramModelUtils.findDiagramModelComponentsForArchimateConcept(diagramModel, relationship);
assertTrue(list.isEmpty());
// Create various IDiagramModelArchimateObject objects
createDataForDiagramModelArchimateObjects(IArchimateFactory.eINSTANCE.createBusinessActor(), diagramModel);
// And make some connections using the relationship
createDataForDiagramModelConnections(relationship);
// Found in diagram
list = DiagramModelUtils.findDiagramModelComponentsForArchimateConcept(diagramModel, relationship);
assertEquals(3, list.size());
assertTrue(list.contains(conn1));
assertTrue(list.contains(conn2));
assertTrue(list.contains(conn3));
}
use of com.archimatetool.model.IDiagramModelArchimateComponent in project archi by archimatetool.
the class CreateDiagramArchimateConnectionWithDialogCommand method checkToReuseExistingRelationship.
boolean checkToReuseExistingRelationship() {
EClass classType = (EClass) fRequest.getNewObjectType();
if (fSource instanceof IDiagramModelArchimateComponent && fTarget instanceof IDiagramModelArchimateComponent) {
IDiagramModelArchimateComponent source = (IDiagramModelArchimateComponent) fSource;
IDiagramModelArchimateComponent target = (IDiagramModelArchimateComponent) fTarget;
// If there is already a relation of this type in the model...
IArchimateRelationship relation = getExistingRelationshipOfType(classType, source.getArchimateConcept(), target.getArchimateConcept());
if (relation != null) {
// ...then ask the user if they want to re-use it
boolean answer = MessageDialog.openQuestion(Display.getCurrent().getActiveShell(), Messages.CreateArchimateConnectionWithDialogCommand_0, NLS.bind(Messages.CreateArchimateConnectionWithDialogCommand_1, ArchiLabelProvider.INSTANCE.getLabel(source), ArchiLabelProvider.INSTANCE.getLabel(target)));
// Yes...
if (answer) {
// ...set connection's relationship to the existing relation
fConnection = createNewConnection();
((IDiagramModelArchimateConnection) fConnection).setArchimateRelationship(relation);
return true;
}
}
}
return false;
}
use of com.archimatetool.model.IDiagramModelArchimateComponent in project archi by archimatetool.
the class ObjectUIFactory method getProvider.
public IObjectUIProvider getProvider(EObject eObject) {
EClass eClass = null;
// We need to unwrap these here as this is called from diagram model objects
if (eObject instanceof IDiagramModelArchimateComponent) {
eClass = ((IDiagramModelArchimateComponent) eObject).getArchimateConcept().eClass();
} else if (eObject != null) {
eClass = eObject.eClass();
}
IObjectUIProvider provider = getProviderForClass(eClass);
if (provider != null) {
provider.setInstance(eObject);
}
return provider;
}
Aggregations