use of com.archimatetool.model.IArchimateElement in project archi by archimatetool.
the class DuplicateElementChecker method findDuplicateNamesElements.
List<IIssue> findDuplicateNamesElements() {
List<IIssue> issues = new ArrayList<IIssue>();
Set<IArchimateElement> dupes = new LinkedHashSet<IArchimateElement>();
for (int i = 0; i < fArchimateElements.size(); i++) {
for (int j = i + 1; j < fArchimateElements.size(); j++) {
IArchimateElement element1 = fArchimateElements.get(i);
IArchimateElement element2 = fArchimateElements.get(j);
if (isDuplicate(element1, element2)) {
dupes.add(element1);
dupes.add(element2);
}
}
}
for (IArchimateElement element : dupes) {
String description = NLS.bind(DESCRIPTION, new Object[] { element.getName(), ArchiLabelProvider.INSTANCE.getDefaultName(element.eClass()) });
IIssue issue = new WarningType(NAME, description, EXPLANATION, element);
issues.add(issue);
}
return issues;
}
use of com.archimatetool.model.IArchimateElement in project archi by archimatetool.
the class NestedElementsChecker method isNestedWithoutValidRelation.
boolean isNestedWithoutValidRelation(IDiagramModelArchimateObject parent, IDiagramModelArchimateObject child) {
IArchimateElement parentElement = parent.getArchimateElement();
IArchimateElement childElement = child.getArchimateElement();
// Ignore nested Junctions
if (childElement instanceof IJunction) {
return false;
}
// Specialization relationship goes the other way around
for (IArchimateRelationship relation : parentElement.getTargetRelationships()) {
if (relation.getSource() == childElement) {
if (relation instanceof ISpecializationRelationship) {
return false;
}
}
}
// Other relationships
for (IArchimateRelationship relation : parentElement.getSourceRelationships()) {
if (relation.getTarget() == childElement) {
if (relation instanceof ICompositionRelationship || relation instanceof IAggregationRelationship || relation instanceof IAssignmentRelationship || relation instanceof IRealizationRelationship || relation instanceof IAccessRelationship) {
return false;
}
}
}
return true;
}
use of com.archimatetool.model.IArchimateElement in project archi by archimatetool.
the class TreeModelViewerDragDropHandlerTests method __doTestHasCommonAncestorFolderWithTheseFolders.
private void __doTestHasCommonAncestorFolderWithTheseFolders(IFolder parentFolder1, IFolder parentFolder2) {
/*
businessFolder
|-- f2
|-- e1
|-- f3
|-- e2
appFolder
|-- f4
|-- e3
|-- f5
|-- e4
*/
IFolder f2 = IArchimateFactory.eINSTANCE.createFolder();
IFolder f3 = IArchimateFactory.eINSTANCE.createFolder();
parentFolder1.getFolders().add(f2);
parentFolder1.getFolders().add(f3);
IArchimateElement e1 = IArchimateFactory.eINSTANCE.createBusinessActor();
f2.getElements().add(e1);
IArchimateElement e2 = IArchimateFactory.eINSTANCE.createBusinessActor();
f3.getElements().add(e2);
IFolder f4 = IArchimateFactory.eINSTANCE.createFolder();
IFolder f5 = IArchimateFactory.eINSTANCE.createFolder();
parentFolder2.getFolders().add(f4);
parentFolder2.getFolders().add(f5);
IArchimateElement e3 = IArchimateFactory.eINSTANCE.createApplicationComponent();
f4.getElements().add(e3);
IArchimateElement e4 = IArchimateFactory.eINSTANCE.createApplicationComponent();
f5.getElements().add(e4);
// Same common ancestor
assertTrue(dragHandler.hasCommonAncestorFolder(f2, f3));
assertTrue(dragHandler.hasCommonAncestorFolder(f2, e1));
assertTrue(dragHandler.hasCommonAncestorFolder(f3, e1));
assertTrue(dragHandler.hasCommonAncestorFolder(e1, e2));
// Different common ancestors
assertFalse(dragHandler.hasCommonAncestorFolder(f2, f4));
assertFalse(dragHandler.hasCommonAncestorFolder(f3, f5));
assertFalse(dragHandler.hasCommonAncestorFolder(f3, e3));
assertFalse(dragHandler.hasCommonAncestorFolder(e1, e4));
}
use of com.archimatetool.model.IArchimateElement in project archi by archimatetool.
the class TreeModelViewerDragDropHandlerTests method testIsValidTreeSelection.
@Test
public void testIsValidTreeSelection() {
// Null selection is not valid
StructuredSelection selection = null;
assertFalse(dragHandler.isValidTreeSelection(selection));
// Set up some data
IFolder userFolder = IArchimateFactory.eINSTANCE.createFolder();
model.getFolder(FolderType.DIAGRAMS).getFolders().add(userFolder);
IFolder businessFolder = model.getFolder(FolderType.BUSINESS);
IArchimateElement e1 = IArchimateFactory.eINSTANCE.createBusinessActor();
businessFolder.getElements().add(e1);
IArchimateElement e2 = IArchimateFactory.eINSTANCE.createBusinessActor();
businessFolder.getElements().add(e2);
// Elements from the same root parent are OK
selection = new StructuredSelection(new Object[] { e1, e2 });
assertTrue(dragHandler.isValidTreeSelection(selection));
// Can't DnD a model
selection = new StructuredSelection(new Object[] { model });
assertFalse(dragHandler.isValidTreeSelection(selection));
// Can DnD a user folder
selection = new StructuredSelection(new Object[] { userFolder });
assertTrue(dragHandler.isValidTreeSelection(selection));
// Can't DnD a system folder
selection = new StructuredSelection(new Object[] { businessFolder });
assertFalse(dragHandler.isValidTreeSelection(selection));
// Can't DnD Mixed parent models
IArchimateModel model2 = IArchimateFactory.eINSTANCE.createArchimateModel();
model2.setDefaults();
IArchimateElement e3 = IArchimateFactory.eINSTANCE.createBusinessActor();
model2.getFolder(FolderType.BUSINESS).getElements().add(e3);
selection = new StructuredSelection(new Object[] { e1, e3 });
assertFalse(dragHandler.isValidTreeSelection(selection));
}
use of com.archimatetool.model.IArchimateElement in project archi by archimatetool.
the class TreeModelViewerDragDropHandlerTests method moveTreeObjects_DropChildElementsOntoDifferentParent.
/**
* Drag and dropping child elements onto different parent
*/
@Test
public void moveTreeObjects_DropChildElementsOntoDifferentParent() {
// Add child elements to a folder
IFolder sourceParentFolder = model.getFolder(FolderType.BUSINESS);
IArchimateElement childElement1 = IArchimateFactory.eINSTANCE.createBusinessActor();
sourceParentFolder.getElements().add(childElement1);
IArchimateElement childElement2 = IArchimateFactory.eINSTANCE.createBusinessActor();
sourceParentFolder.getElements().add(childElement2);
// Check all is well
assertEquals(2, sourceParentFolder.getElements().size());
assertEquals(childElement1, sourceParentFolder.getElements().get(0));
assertEquals(childElement2, sourceParentFolder.getElements().get(1));
// New target parent folder and all is well
IFolder targetParentFolder = model.getFolder(FolderType.APPLICATION);
assertTrue(targetParentFolder.getFolders().isEmpty());
assertTrue(targetParentFolder.getElements().isEmpty());
// Move child element to the different target parent folder
dragHandler.moveTreeObjects(targetParentFolder, new Object[] { childElement1, childElement2 });
// Source should be empty
assertTrue(sourceParentFolder.getElements().isEmpty());
// Shouldn't affect folders
assertEquals(2, targetParentFolder.getElements().size());
// Target should be populated
assertEquals(childElement1, targetParentFolder.getElements().get(0));
assertEquals(childElement2, targetParentFolder.getElements().get(1));
assertTrue(targetParentFolder.getFolders().isEmpty());
}
Aggregations