use of com.archimatetool.model.IDiagramModelArchimateObject 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.IDiagramModelArchimateObject in project archi by archimatetool.
the class ArchimateDiagramModelFactory method createDiagramModelArchimateObject.
/**
* Factory method for creating a new IDiagramModelArchimateObject for an IArchimateElement
* @param element
* @return a new IDiagramModelArchimateObject
*/
public static IDiagramModelArchimateObject createDiagramModelArchimateObject(IArchimateElement element) {
IDiagramModelArchimateObject dmo = IArchimateFactory.eINSTANCE.createDiagramModelArchimateObject();
dmo.setArchimateElement(element);
// Figure Type
dmo.setType(Preferences.STORE.getInt(IPreferenceConstants.DEFAULT_FIGURE_PREFIX + element.eClass().getName()));
// Add new bounds with a default user size
IGraphicalObjectUIProvider provider = (IGraphicalObjectUIProvider) ObjectUIFactory.INSTANCE.getProvider(dmo);
Dimension size = provider.getUserDefaultSize();
dmo.setBounds(0, 0, size.width, size.height);
dmo.setTextPosition(ITextPosition.TEXT_POSITION_TOP);
// Set user default colors as set in prefs
ColorFactory.setDefaultColors(dmo);
return dmo;
}
use of com.archimatetool.model.IDiagramModelArchimateObject in project archi by archimatetool.
the class CreateNestedArchimateConnectionsWithDialogCommand method createConnectionDialogCommands.
/**
* Child Objects that don't have a relationship set with parent - ask user if they want one
*/
void createConnectionDialogCommands() {
// Gather suitable child objects
List<IDiagramModelArchimateObject> childObjectsForDialog = new ArrayList<IDiagramModelArchimateObject>();
for (IDiagramModelArchimateObject childObject : fChildObjects) {
if (canAddNewRelationship(fParentObject, childObject)) {
childObjectsForDialog.add(childObject);
}
}
// One child object
if (childObjectsForDialog.size() == 1) {
NewNestedRelationDialog dialog = new NewNestedRelationDialog(fParentObject, childObjectsForDialog.get(0));
if (dialog.open() == Window.OK) {
EClass eClass = dialog.getSelectedType();
if (eClass != null) {
Command cmd = new CreateRelationshipAndDiagramArchimateConnectionCommand(fParentObject, childObjectsForDialog.get(0), eClass);
add(cmd);
}
}
} else // More than one child object
if (childObjectsForDialog.size() > 1) {
NewNestedRelationsDialog dialog = new NewNestedRelationsDialog(fParentObject, childObjectsForDialog);
if (dialog.open() == Window.OK) {
List<SelectedRelationshipType> selectedTypes = dialog.getSelectedTypes();
for (SelectedRelationshipType selType : selectedTypes) {
Command cmd = new CreateRelationshipAndDiagramArchimateConnectionCommand(fParentObject, selType.childObject, selType.relationshipType);
add(cmd);
}
}
}
}
use of com.archimatetool.model.IDiagramModelArchimateObject in project archi by archimatetool.
the class DiagramModelUtilsTests method isArchimateConceptReferencedInDiagrams.
@Test
public void isArchimateConceptReferencedInDiagrams() {
// This should be in a diagram
IArchimateElement element = (IArchimateElement) tm.getObjectByID(data1[0][0]);
assertNotNull(element);
assertTrue(DiagramModelUtils.isArchimateConceptReferencedInDiagrams(element));
// This should be in a diagram
element = (IArchimateElement) tm.getObjectByID(data2[0][0]);
assertNotNull(element);
assertTrue(DiagramModelUtils.isArchimateConceptReferencedInDiagrams(element));
// This should not be in a diagram
element = IArchimateFactory.eINSTANCE.createBusinessActor();
model.getDefaultFolderForObject(element).getElements().add(element);
assertFalse(DiagramModelUtils.isArchimateConceptReferencedInDiagrams(element));
// Unless we add it to a diagram
// And we'll nest it inside a Group to be cunning
IDiagramModelArchimateObject dmo = ArchimateTestModel.createDiagramModelArchimateObject(element);
IDiagramModelGroup group = IArchimateFactory.eINSTANCE.createDiagramModelGroup();
group.getChildren().add(dmo);
model.getDefaultDiagramModel().getChildren().add(group);
assertTrue(DiagramModelUtils.isArchimateConceptReferencedInDiagrams(element));
}
use of com.archimatetool.model.IDiagramModelArchimateObject in project archi by archimatetool.
the class ModelCheckerTests method checkDiagramObjectsReferences_Object.
@Test
public void checkDiagramObjectsReferences_Object() {
model.getDefaultDiagramModel().setName("dm");
IArchimateElement element = IArchimateFactory.eINSTANCE.createBusinessActor();
model.getFolder(FolderType.BUSINESS).getElements().add(element);
IDiagramModelArchimateObject dmo = IArchimateFactory.eINSTANCE.createDiagramModelArchimateObject();
dmo.setArchimateElement(element);
model.getDefaultDiagramModel().getChildren().add(dmo);
List<String> messages = modelChecker.checkDiagramObjectsReferences();
assertEquals(0, messages.size());
model.getFolder(FolderType.BUSINESS).getElements().remove(element);
messages = modelChecker.checkDiagramObjectsReferences();
assertEquals(1, messages.size());
assertTrue(messages.get(0).startsWith("Diagram Element has orphaned ArchiMate element in 'dm'"));
}
Aggregations