use of com.archimatetool.model.IArchimateRelationship in project archi by archimatetool.
the class UnusedRelationsCheckerTests method testGetIssues.
@Test
public void testGetIssues() {
ArchimateTestModel tm = new ArchimateTestModel();
IArchimateModel model = tm.createNewModel();
List<IArchimateRelationship> relations = new ArrayList<IArchimateRelationship>();
IArchimateRelationship relation = (IArchimateRelationship) tm.createModelElementAndAddToModel(IArchimatePackage.eINSTANCE.getAssociationRelationship());
relations.add(relation);
IArchimateElement e1 = (IArchimateElement) tm.createModelElementAndAddToModel(IArchimatePackage.eINSTANCE.getBusinessActor());
IArchimateElement e2 = (IArchimateElement) tm.createModelElementAndAddToModel(IArchimatePackage.eINSTANCE.getBusinessActor());
relation.connect(e1, e2);
UnusedRelationsChecker checker = new UnusedRelationsChecker(relations);
// Should not be OK
List<IIssue> issues = checker.getIssues();
assertEquals(1, issues.size());
assertSame(relation, issues.get(0).getObject());
// Add it to a diagram
IDiagramModelArchimateObject dmo1 = IArchimateFactory.eINSTANCE.createDiagramModelArchimateObject();
dmo1.setArchimateElement(e1);
model.getDefaultDiagramModel().getChildren().add(dmo1);
IDiagramModelArchimateObject dmo2 = IArchimateFactory.eINSTANCE.createDiagramModelArchimateObject();
dmo2.setArchimateElement(e2);
model.getDefaultDiagramModel().getChildren().add(dmo2);
IDiagramModelArchimateConnection conn = IArchimateFactory.eINSTANCE.createDiagramModelArchimateConnection();
conn.setArchimateRelationship(relation);
conn.connect(dmo1, dmo2);
// Should be OK
issues = checker.getIssues();
assertEquals(0, issues.size());
}
use of com.archimatetool.model.IArchimateRelationship in project archi by archimatetool.
the class FieldDataFactoryTests method testGetFieldValue_RelationSource.
@Test
public void testGetFieldValue_RelationSource() {
IArchimateRelationship relation = IArchimateFactory.eINSTANCE.createServingRelationship();
IArtifact source = IArchimateFactory.eINSTANCE.createArtifact();
source.setName("source");
relation.setSource(source);
Object o = FieldDataFactory.getFieldValue(relation, "relation_source");
assertEquals("source", o);
}
use of com.archimatetool.model.IArchimateRelationship in project archi by archimatetool.
the class AbstractArchimateConnectionFigure method getToolTip.
@Override
public IFigure getToolTip() {
ToolTipFigure toolTipFigure = (ToolTipFigure) super.getToolTip();
if (toolTipFigure == null) {
return null;
}
IArchimateRelationship relation = getModelConnection().getArchimateRelationship();
String text = ArchiLabelProvider.INSTANCE.getLabel(relation);
toolTipFigure.setText(text);
String type = ArchiLabelProvider.INSTANCE.getDefaultName(relation.eClass());
// $NON-NLS-1$
toolTipFigure.setType(Messages.AbstractArchimateConnectionFigure_0 + " " + type);
String rubric = ArchiLabelProvider.INSTANCE.getRelationshipSentence(relation);
toolTipFigure.setRubric(rubric);
return toolTipFigure;
}
use of com.archimatetool.model.IArchimateRelationship 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.IArchimateRelationship 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?
*/
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;
// Specialization relationship is the other way around
for (IArchimateRelationship relation : parentElement.getTargetRelationships()) {
if (relation.getSource() == childElement && relation.eClass() == IArchimatePackage.eINSTANCE.getSpecializationRelationship() && DiagramModelUtils.isNestedConnectionTypeRelationship(relation)) {
if (DiagramModelUtils.hasDiagramModelArchimateConnection(childObject, fParentObject, relation)) {
aConnectionExists = true;
break;
}
}
}
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) {
// Specialization relationship is the other way around
for (IArchimateRelationship relation : parentElement.getTargetRelationships()) {
if (relation.getSource() == childElement && relation.eClass() == IArchimatePackage.eINSTANCE.getSpecializationRelationship() && DiagramModelUtils.isNestedConnectionTypeRelationship(relation)) {
add(new CreateDiagramArchimateConnectionCommand(childObject, fParentObject, relation));
}
}
for (IArchimateRelationship relation : parentElement.getSourceRelationships()) {
if (relation.getTarget() == childElement && DiagramModelUtils.isNestedConnectionTypeRelationship(relation)) {
add(new CreateDiagramArchimateConnectionCommand(fParentObject, childObject, 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