use of com.archimatetool.model.IDiagramModelArchimateConnection in project archi-modelrepository-plugin by archi-contribs.
the class GraficoModelImporter method resolveProxies.
/**
* Iterate through all model objects, and resolve proxies on known classes
*/
private void resolveProxies() {
fUnresolvedObjects = null;
for (Iterator<EObject> iter = fModel.eAllContents(); iter.hasNext(); ) {
EObject eObject = iter.next();
if (eObject instanceof IArchimateConcept) {
// Resolve proxies for profiles
IArchimateConcept concept = (IArchimateConcept) eObject;
EList<IProfile> profiles = concept.getProfiles();
// Assumption: most concepts don't have profiles so checking for empty has a positive impact on performance
if (!profiles.isEmpty()) {
ListIterator<IProfile> iterator = profiles.listIterator();
while (iterator.hasNext()) {
IProfile profile = iterator.next();
iterator.set((IProfile) resolve(profile, concept));
}
}
}
if (eObject instanceof IArchimateRelationship) {
// Resolve proxies for Relations
IArchimateRelationship relation = (IArchimateRelationship) eObject;
relation.setSource((IArchimateConcept) resolve(relation.getSource(), relation));
relation.setTarget((IArchimateConcept) resolve(relation.getTarget(), relation));
} else if (eObject instanceof IDiagramModelArchimateObject) {
// Resolve proxies for Elements
IDiagramModelArchimateObject element = (IDiagramModelArchimateObject) eObject;
element.setArchimateElement((IArchimateElement) resolve(element.getArchimateElement(), element));
} else if (eObject instanceof IDiagramModelArchimateConnection) {
// Resolve proxies for Connections
IDiagramModelArchimateConnection archiConnection = (IDiagramModelArchimateConnection) eObject;
archiConnection.setArchimateRelationship((IArchimateRelationship) resolve(archiConnection.getArchimateRelationship(), archiConnection));
} else if (eObject instanceof IDiagramModelReference) {
// Resolve proxies for Model References
IDiagramModelReference element = (IDiagramModelReference) eObject;
element.setReferencedModel((IDiagramModel) resolve(element.getReferencedModel(), element));
}
}
}
use of com.archimatetool.model.IDiagramModelArchimateConnection in project archi by archimatetool.
the class DiagramModelUtilsTests method testFindDiagramModelObjectsAndConnections_AfterDuplicateDiagram.
// =================================================================================================
@Test
public void testFindDiagramModelObjectsAndConnections_AfterDuplicateDiagram() {
ArchimateTestModel tm = new ArchimateTestModel();
IArchimateModel model = tm.createNewModel();
IDiagramModel dm = model.getDefaultDiagramModel();
IArchimateElement actor = IArchimateFactory.eINSTANCE.createBusinessActor();
IDiagramModelArchimateObject dmo1 = tm.createDiagramModelArchimateObjectAndAddToModel(actor);
dm.getChildren().add(dmo1);
IArchimateElement role = IArchimateFactory.eINSTANCE.createBusinessRole();
IDiagramModelArchimateObject dmo2 = tm.createDiagramModelArchimateObjectAndAddToModel(role);
dm.getChildren().add(dmo2);
IAssignmentRelationship relation = IArchimateFactory.eINSTANCE.createAssignmentRelationship();
relation.setSource(actor);
relation.setTarget(role);
IDiagramModelArchimateConnection dmc1 = tm.createDiagramModelArchimateConnectionAndAddToModel(relation);
dmc1.connect(dmo1, dmo2);
List<?> list = DiagramModelUtils.findDiagramModelObjectsForElement(actor);
assertEquals(1, list.size());
list = DiagramModelUtils.findDiagramModelObjectsForElement(role);
assertEquals(1, list.size());
list = DiagramModelUtils.findDiagramModelConnectionsForRelation(relation);
assertEquals(1, list.size());
// Duplicate
DuplicateCommandHandler handler = new DuplicateCommandHandler(new Object[] { dm });
handler.duplicate();
list = DiagramModelUtils.findDiagramModelObjectsForElement(actor);
assertEquals(2, list.size());
list = DiagramModelUtils.findDiagramModelObjectsForElement(role);
assertEquals(2, list.size());
list = DiagramModelUtils.findDiagramModelConnectionsForRelation(relation);
assertEquals(2, list.size());
}
use of com.archimatetool.model.IDiagramModelArchimateConnection in project archi by archimatetool.
the class CopySnapshot method createPasteConnections.
private List<IDiagramModelConnection> createPasteConnections() {
List<IDiagramModelConnection> connections = new ArrayList<IDiagramModelConnection>();
// Create new connections from basis of snapshot
for (IConnectable connectable : fOriginalToSnapshotComponentsMapping.values()) {
if (connectable instanceof IDiagramModelConnection) {
IDiagramModelConnection snapshotConnection = (IDiagramModelConnection) connectable;
IDiagramModelConnection newConnection = (IDiagramModelConnection) snapshotConnection.getCopy();
connections.add(newConnection);
// Mapping
fSnapshotToNewComponentMapping.put(snapshotConnection, newConnection);
// Re-use original Archimate relationship if required
if (!fDoCreateNewArchimateComponents && snapshotConnection instanceof IDiagramModelArchimateConnection) {
IDiagramModelArchimateConnection originalDiagramConnection = (IDiagramModelArchimateConnection) fOriginalToSnapshotComponentsMapping.getKey(snapshotConnection);
IArchimateRelationship relationship = originalDiagramConnection.getArchimateRelationship();
((IDiagramModelArchimateConnection) newConnection).setArchimateRelationship(relationship);
}
}
}
// Connect them
for (Entry<IConnectable, IConnectable> entry : fSnapshotToNewComponentMapping.entrySet()) {
if (entry.getKey() instanceof IDiagramModelConnection) {
IDiagramModelConnection snapshotConnection = (IDiagramModelConnection) entry.getKey();
IConnectable newSource = fSnapshotToNewComponentMapping.get(snapshotConnection.getSource());
IConnectable newTarget = fSnapshotToNewComponentMapping.get(snapshotConnection.getTarget());
if (newSource != null && newTarget != null) {
IDiagramModelConnection newConnection = (IDiagramModelConnection) entry.getValue();
newConnection.connect(newSource, newTarget);
}
}
}
return connections;
}
use of com.archimatetool.model.IDiagramModelArchimateConnection in project archi by archimatetool.
the class CreateDiagramArchimateConnectionWithDialogCommand method checkToReuseExistingRelationship.
private boolean checkToReuseExistingRelationship() {
if (fSource instanceof IDiagramModelArchimateComponent && fTarget instanceof IDiagramModelArchimateComponent) {
IDiagramModelArchimateComponent source = (IDiagramModelArchimateComponent) fSource;
IDiagramModelArchimateComponent target = (IDiagramModelArchimateComponent) fTarget;
EClass classType = (EClass) fRequest.getNewObjectType();
// Find any relations of this type connecting source and target concepts
List<IArchimateRelationship> relations = getExistingRelationshipsOfType(classType, source.getArchimateConcept(), target.getArchimateConcept());
// If there is already a relation of this type connecting source and target concepts...
if (!relations.isEmpty()) {
// Ask user in dialog if they want to reference an existing one
ChooseRelationDialog dialog = new ChooseRelationDialog(ArchiLabelProvider.INSTANCE.getDefaultName(classType), NLS.bind(Messages.CreateArchimateConnectionWithDialogCommand_1, ArchiLabelProvider.INSTANCE.getLabel(source), ArchiLabelProvider.INSTANCE.getLabel(target)), relations);
if (dialog.open() == Window.OK) {
// Create a new connection
fConnection = createNewConnection();
// set the connection's relationship to the chosen relation
((IDiagramModelArchimateConnection) fConnection).setArchimateRelationship(dialog.getSelected());
return true;
}
}
}
return false;
}
use of com.archimatetool.model.IDiagramModelArchimateConnection in project archi by archimatetool.
the class CreateNestedArchimateConnectionsWithDialogCommand method createNewConnectionCommands.
/**
* Create Commands for child objects that don't have connections and need new ones
*
* TODO A3: If O1--C1--O2. C1 is also connected to parent.
* O1 or O2 is added to parent - should add connection from C1 to parent?
* Or should it be only when O1 AND O2 are added to parent?
*/
private void createNewConnectionCommands() {
IArchimateElement parentElement = fParentObject.getArchimateElement();
// Check connections between parent and child objects that are being dragged in
for (IDiagramModelArchimateObject childObject : fChildObjects) {
IArchimateElement childElement = childObject.getArchimateElement();
boolean aConnectionExists = false;
for (IArchimateRelationship relation : parentElement.getSourceRelationships()) {
if (relation.getTarget() == childElement && DiagramModelUtils.isNestedConnectionTypeRelationship(relation)) {
if (DiagramModelUtils.hasDiagramModelArchimateConnection(fParentObject, childObject, relation)) {
aConnectionExists = true;
break;
}
}
}
// Create connections from relationships if none already exists
if (!aConnectionExists) {
for (IArchimateRelationship relation : parentElement.getSourceRelationships()) {
if (relation.getTarget() == childElement && DiagramModelUtils.isNestedConnectionTypeRelationship(relation)) {
add(new CreateDiagramArchimateConnectionCommand(fParentObject, childObject, relation));
}
}
}
// Now do the reverse direction...
aConnectionExists = false;
for (IArchimateRelationship relation : parentElement.getTargetRelationships()) {
if (relation.getSource() == childElement && DiagramModelUtils.isNestedConnectionTypeRelationship(relation)) {
if (DiagramModelUtils.hasDiagramModelArchimateConnection(childObject, fParentObject, relation)) {
aConnectionExists = true;
break;
}
}
}
// Create connections from relationships if none already exists
if (!aConnectionExists) {
for (IArchimateRelationship relation : parentElement.getTargetRelationships()) {
if (relation.getSource() == childElement && DiagramModelUtils.isNestedConnectionTypeRelationship(relation)) {
add(new CreateDiagramArchimateConnectionCommand(childObject, fParentObject, relation));
}
}
}
}
// Check connections between parent and child connections of objects
for (IArchimateRelationship relation : parentElement.getSourceRelationships()) {
if (relation.getTarget() instanceof IArchimateRelationship) {
IDiagramModelArchimateConnection dmc = findConnection((IArchimateRelationship) relation.getTarget());
if (dmc != null) {
if (!DiagramModelUtils.hasDiagramModelArchimateConnection(fParentObject, dmc, relation)) {
add(new CreateDiagramArchimateConnectionCommand(fParentObject, dmc, relation));
}
}
}
}
for (IArchimateRelationship relation : parentElement.getTargetRelationships()) {
if (relation.getSource() instanceof IArchimateRelationship) {
IDiagramModelArchimateConnection dmc = findConnection((IArchimateRelationship) relation.getSource());
if (dmc != null) {
if (!DiagramModelUtils.hasDiagramModelArchimateConnection(fParentObject, dmc, relation)) {
add(new CreateDiagramArchimateConnectionCommand(fParentObject, dmc, relation));
}
}
}
}
}
Aggregations