use of com.archimatetool.model.IArchimateRelationship in project archi by archimatetool.
the class DeleteFromModelAction method run.
@Override
public void run() {
List<?> selection = getSelectedObjects();
List<IArchimateConcept> archimateConcepts = new ArrayList<IArchimateConcept>();
List<IDiagramModelComponent> diagramObjects = new ArrayList<IDiagramModelComponent>();
// Gather Model elements, relations
for (Object object : selection) {
if (object instanceof EditPart) {
Object model = ((EditPart) object).getModel();
if (model instanceof IDiagramModelArchimateObject) {
IArchimateElement element = ((IDiagramModelArchimateObject) model).getArchimateElement();
if (!archimateConcepts.contains(element)) {
archimateConcepts.add(element);
}
// Element's relationships
for (IArchimateRelationship relation : ArchimateModelUtils.getAllRelationshipsForConcept(element)) {
if (!archimateConcepts.contains(relation)) {
archimateConcepts.add(relation);
}
// Relation's relationships
for (IArchimateRelationship r : ArchimateModelUtils.getAllRelationshipsForConcept(relation)) {
if (!archimateConcepts.contains(r)) {
archimateConcepts.add(r);
}
}
}
} else if (model instanceof IDiagramModelArchimateConnection) {
IArchimateRelationship relation = ((IDiagramModelArchimateConnection) model).getArchimateRelationship();
if (!archimateConcepts.contains(relation)) {
archimateConcepts.add(relation);
}
// Relation's relationships
for (IArchimateRelationship r : ArchimateModelUtils.getAllRelationshipsForConcept(relation)) {
if (!archimateConcepts.contains(r)) {
archimateConcepts.add(r);
}
}
}
}
}
// Gather referenced diagram objects
for (IArchimateConcept archimateConcept : archimateConcepts) {
for (IDiagramModel diagramModel : archimateConcept.getArchimateModel().getDiagramModels()) {
for (IDiagramModelComponent dc : DiagramModelUtils.findDiagramModelComponentsForArchimateConcept(diagramModel, archimateConcept)) {
diagramObjects.add(dc);
}
}
}
// Check whether any of these concepts are referenced in other diagrams
if (hasMoreThanOneReference(archimateConcepts, diagramObjects)) {
if (!MessageDialog.openQuestion(Display.getDefault().getActiveShell(), Messages.DeleteFromModelAction_0, Messages.DeleteFromModelAction_1 + // $NON-NLS-1$
"\n\n" + Messages.DeleteFromModelAction_2)) {
return;
}
}
// Create commands
CompoundCommand compoundCommand = new NonNotifyingCompoundCommand(TEXT);
for (IArchimateConcept archimateConcept : archimateConcepts) {
if (archimateConcept instanceof IArchimateElement) {
Command cmd = new DeleteArchimateElementCommand((IArchimateElement) archimateConcept);
compoundCommand.add(cmd);
} else if (archimateConcept instanceof IArchimateRelationship) {
Command cmd = new DeleteArchimateRelationshipCommand((IArchimateRelationship) archimateConcept);
compoundCommand.add(cmd);
}
}
for (IDiagramModelComponent dc : diagramObjects) {
if (dc instanceof IDiagramModelObject) {
Command cmd = DiagramCommandFactory.createDeleteDiagramObjectCommand((IDiagramModelObject) dc);
compoundCommand.add(cmd);
} else if (dc instanceof IDiagramModelConnection) {
Command cmd = DiagramCommandFactory.createDeleteDiagramConnectionCommand((IDiagramModelConnection) dc);
compoundCommand.add(cmd);
}
}
execute(compoundCommand);
}
use of com.archimatetool.model.IArchimateRelationship in project archi by archimatetool.
the class CreateNestedArchimateConnectionsWithDialogCommand method canAddNewRelationship.
/**
* @return true if any new relation can/should be added between parent and child when adding a child element to a parent object
*/
boolean canAddNewRelationship(IDiagramModelArchimateObject parentObject, IDiagramModelArchimateObject childObject) {
IArchimateElement parentElement = parentObject.getArchimateElement();
IArchimateElement childElement = childObject.getArchimateElement();
// Specialization relationship goes the other way around, so check this first
for (IArchimateRelationship relation : parentElement.getTargetRelationships()) {
if (relation.getSource() == childElement && relation.eClass() == IArchimatePackage.eINSTANCE.getSpecializationRelationship()) {
return false;
}
}
// Not if there is already a relationship of an allowed type between parent and child elements
for (IArchimateRelationship relation : parentElement.getSourceRelationships()) {
if (relation.getTarget() == childElement) {
for (EClass eClass : ConnectionPreferences.getRelationsClassesForNewRelations()) {
if (relation.eClass() == eClass) {
return false;
}
}
}
}
// Check this is at least one valid relationship
for (EClass eClass : ConnectionPreferences.getRelationsClassesForNewRelations()) {
// Specialization relationship goes the other way around, so check this first
if (eClass == IArchimatePackage.eINSTANCE.getSpecializationRelationship()) {
if (ArchimateModelUtils.isValidRelationship(childElement, parentElement, eClass)) {
return true;
}
}
if (ArchimateModelUtils.isValidRelationship(parentElement, childElement, eClass)) {
return true;
}
}
return false;
}
use of com.archimatetool.model.IArchimateRelationship in project archi by archimatetool.
the class DiagramModelArchimateConnection method removeArchimateConceptFromModel.
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated NOT
*/
@Override
public void removeArchimateConceptFromModel() {
IArchimateRelationship relationship = getArchimateRelationship();
if (relationship != null) {
IFolder folder = (IFolder) relationship.eContainer();
if (folder != null) {
folder.getElements().remove(relationship);
relationship.disconnect();
}
}
}
use of com.archimatetool.model.IArchimateRelationship in project archi by archimatetool.
the class DiagramModelArchimateConnection method getCopy.
@Override
public EObject getCopy() {
IDiagramModelArchimateConnection newConnection = (IDiagramModelArchimateConnection) super.getCopy();
IArchimateRelationship relationship = (IArchimateRelationship) getArchimateRelationship().getCopy();
newConnection.setArchimateRelationship(relationship);
return newConnection;
}
use of com.archimatetool.model.IArchimateRelationship in project archi by archimatetool.
the class DiagramModelArchimateConnection method reconnect.
@Override
public void reconnect() {
super.reconnect();
// Set the source/target in the Archimate model if need be
if (source instanceof IDiagramModelArchimateComponent && target instanceof IDiagramModelArchimateComponent) {
IArchimateConcept srcConcept = ((IDiagramModelArchimateComponent) source).getArchimateConcept();
IArchimateConcept tgtConcept = ((IDiagramModelArchimateComponent) target).getArchimateConcept();
IArchimateRelationship relationship = getArchimateRelationship();
if (relationship.getSource() != srcConcept) {
// optimised
relationship.setSource(srcConcept);
}
if (relationship.getTarget() != tgtConcept) {
// optimised
relationship.setTarget(tgtConcept);
}
}
}
Aggregations