use of com.archimatetool.model.IDiagramModelComponent in project archi by archimatetool.
the class DeleteCommandHandler method getElementsToDelete.
/**
* Create the list of objects to delete and check
* @return
*/
private void getElementsToDelete() {
// Actual elements to delete
fElementsToDelete = new ArrayList<Object>();
// First, gather up the list of Archimate objects to be deleted...
for (Object object : fSelectedObjects) {
if (canDelete(object)) {
addToList(object, fElementsToDelete);
addFolderChildElements(object);
addElementRelationships(object);
}
}
// Gather referenced diagram objects to be deleted checking that the parent diagram model is not also selected to be deleted
for (Object object : new ArrayList<>(fElementsToDelete)) {
// Archimate Components
if (object instanceof IArchimateConcept) {
IArchimateConcept archimateConcept = (IArchimateConcept) object;
for (IDiagramModel diagramModel : archimateConcept.getArchimateModel().getDiagramModels()) {
// Check diagram model is not selected to be deleted - no point in deleting any of its children
if (!fElementsToDelete.contains(diagramModel)) {
for (IDiagramModelComponent dc : DiagramModelUtils.findDiagramModelComponentsForArchimateConcept(diagramModel, archimateConcept)) {
addToList(dc, fElementsToDelete);
}
}
}
}
// Diagram Models and their references
if (object instanceof IDiagramModel) {
IDiagramModel diagramModelDeleted = (IDiagramModel) object;
for (IDiagramModel diagramModel : diagramModelDeleted.getArchimateModel().getDiagramModels()) {
// is there one?
List<IDiagramModelReference> list = DiagramModelUtils.findDiagramModelReferences(diagramModel, diagramModelDeleted);
fElementsToDelete.addAll(list);
}
}
}
}
use of com.archimatetool.model.IDiagramModelComponent in project archi by archimatetool.
the class ValidatorView method selectObjects.
void selectObjects(IStructuredSelection selection) {
if (selection != null) {
List<IArchimateConcept> treeList = new ArrayList<IArchimateConcept>();
List<IDiagramModel> viewList = new ArrayList<IDiagramModel>();
List<IDiagramModelComponent> viewComponentList = new ArrayList<IDiagramModelComponent>();
for (Object o : selection.toArray()) {
if (o instanceof IIssue) {
IIssue issue = (IIssue) o;
if (issue.getObject() instanceof IArchimateConcept) {
treeList.add((IArchimateConcept) issue.getObject());
} else if (issue.getObject() instanceof IDiagramModel) {
viewList.add((IDiagramModel) issue.getObject());
} else if (issue.getObject() instanceof IDiagramModelComponent) {
viewList.add(((IDiagramModelComponent) issue.getObject()).getDiagramModel());
viewComponentList.add(((IDiagramModelComponent) issue.getObject()));
}
}
}
if (!treeList.isEmpty()) {
ITreeModelView view = (ITreeModelView) ViewManager.showViewPart(ITreeModelView.ID, false);
if (view != null) {
view.getViewer().setSelection(new StructuredSelection(treeList), true);
}
}
if (!viewList.isEmpty()) {
for (IDiagramModel dm : viewList) {
IDiagramModelEditor editor = EditorManager.openDiagramEditor(dm);
if (editor instanceof IArchimateDiagramEditor) {
((IArchimateDiagramEditor) editor).selectObjects(viewComponentList.toArray());
}
}
}
}
}
use of com.archimatetool.model.IDiagramModelComponent in project archi by archimatetool.
the class DiagramModelComponentTests method testGetCopy.
@Test
public void testGetCopy() {
component.setName("name");
IDiagramModelComponent copy = (IDiagramModelComponent) component.getCopy();
assertNotSame(component, copy);
assertNull(copy.getId());
assertEquals(component.getName(), copy.getName());
}
use of com.archimatetool.model.IDiagramModelComponent 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.IDiagramModelComponent in project archi by archimatetool.
the class CopySnapshotTests method testCopiedObjectsHaveIdentifiersAndParents.
private void testCopiedObjectsHaveIdentifiersAndParents(IDiagramModel newTargetDiagramModel) {
List<IDiagramModelComponent> selected = new ArrayList<IDiagramModelComponent>();
selected.addAll(getAllDiagramComponents(sourceDiagramModel));
CopySnapshot snapshot = new CopySnapshot(selected);
Command cmd = snapshot.getPasteCommand(newTargetDiagramModel, mock(GraphicalViewer.class), null, false);
cmd.execute();
for (TreeIterator<EObject> iter = newTargetDiagramModel.eAllContents(); iter.hasNext(); ) {
EObject eObject = iter.next();
assertNotNull(eObject.eContainer());
if (eObject instanceof IIdentifier) {
assertNotNull(((IIdentifier) eObject).getId());
}
if (eObject instanceof IDiagramModelArchimateComponent) {
assertNotNull(((IDiagramModelArchimateComponent) eObject).getArchimateConcept());
assertNotNull(((IDiagramModelArchimateComponent) eObject).getArchimateConcept().eContainer());
}
}
}
Aggregations