Search in sources :

Example 11 with IDiagramModelArchimateObject

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);
}
Also used : NonNotifyingCompoundCommand(com.archimatetool.editor.model.commands.NonNotifyingCompoundCommand) IDiagramModelComponent(com.archimatetool.model.IDiagramModelComponent) DeleteArchimateElementCommand(com.archimatetool.editor.model.commands.DeleteArchimateElementCommand) IDiagramModelArchimateConnection(com.archimatetool.model.IDiagramModelArchimateConnection) ArrayList(java.util.ArrayList) EditPart(org.eclipse.gef.EditPart) DeleteArchimateRelationshipCommand(com.archimatetool.editor.model.commands.DeleteArchimateRelationshipCommand) IDiagramModelConnection(com.archimatetool.model.IDiagramModelConnection) IDiagramModelObject(com.archimatetool.model.IDiagramModelObject) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) NonNotifyingCompoundCommand(com.archimatetool.editor.model.commands.NonNotifyingCompoundCommand) IDiagramModel(com.archimatetool.model.IDiagramModel) DeleteArchimateRelationshipCommand(com.archimatetool.editor.model.commands.DeleteArchimateRelationshipCommand) DeleteArchimateElementCommand(com.archimatetool.editor.model.commands.DeleteArchimateElementCommand) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) NonNotifyingCompoundCommand(com.archimatetool.editor.model.commands.NonNotifyingCompoundCommand) Command(org.eclipse.gef.commands.Command) IArchimateConcept(com.archimatetool.model.IArchimateConcept) IArchimateElement(com.archimatetool.model.IArchimateElement) IDiagramModelArchimateObject(com.archimatetool.model.IDiagramModelArchimateObject) IDiagramModelObject(com.archimatetool.model.IDiagramModelObject) IArchimateRelationship(com.archimatetool.model.IArchimateRelationship) IDiagramModelArchimateObject(com.archimatetool.model.IDiagramModelArchimateObject)

Example 12 with IDiagramModelArchimateObject

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;
}
Also used : IGraphicalObjectUIProvider(com.archimatetool.editor.ui.factory.IGraphicalObjectUIProvider) IDiagramModelArchimateObject(com.archimatetool.model.IDiagramModelArchimateObject) Dimension(org.eclipse.draw2d.geometry.Dimension)

Example 13 with IDiagramModelArchimateObject

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);
            }
        }
    }
}
Also used : EClass(org.eclipse.emf.ecore.EClass) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) Command(org.eclipse.gef.commands.Command) ArrayList(java.util.ArrayList) SelectedRelationshipType(com.archimatetool.editor.diagram.dialog.NewNestedRelationsDialog.SelectedRelationshipType) NewNestedRelationDialog(com.archimatetool.editor.diagram.dialog.NewNestedRelationDialog) ArrayList(java.util.ArrayList) List(java.util.List) IDiagramModelArchimateObject(com.archimatetool.model.IDiagramModelArchimateObject) NewNestedRelationsDialog(com.archimatetool.editor.diagram.dialog.NewNestedRelationsDialog)

Example 14 with IDiagramModelArchimateObject

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));
}
Also used : IArchimateElement(com.archimatetool.model.IArchimateElement) IDiagramModelArchimateObject(com.archimatetool.model.IDiagramModelArchimateObject) IDiagramModelGroup(com.archimatetool.model.IDiagramModelGroup) Test(org.junit.Test)

Example 15 with IDiagramModelArchimateObject

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'"));
}
Also used : IArchimateElement(com.archimatetool.model.IArchimateElement) IDiagramModelArchimateObject(com.archimatetool.model.IDiagramModelArchimateObject) Test(org.junit.Test)

Aggregations

IDiagramModelArchimateObject (com.archimatetool.model.IDiagramModelArchimateObject)64 Test (org.junit.Test)34 IArchimateElement (com.archimatetool.model.IArchimateElement)28 IDiagramModelArchimateConnection (com.archimatetool.model.IDiagramModelArchimateConnection)19 IArchimateRelationship (com.archimatetool.model.IArchimateRelationship)14 ArrayList (java.util.ArrayList)13 IDiagramModel (com.archimatetool.model.IDiagramModel)10 IDiagramModelObject (com.archimatetool.model.IDiagramModelObject)10 IArchimateModel (com.archimatetool.model.IArchimateModel)8 EClass (org.eclipse.emf.ecore.EClass)7 Command (org.eclipse.gef.commands.Command)7 IIssue (com.archimatetool.hammer.validation.issues.IIssue)6 IArchimateDiagramModel (com.archimatetool.model.IArchimateDiagramModel)6 EObject (org.eclipse.emf.ecore.EObject)6 CompoundCommand (org.eclipse.gef.commands.CompoundCommand)6 IDiagramModelGroup (com.archimatetool.model.IDiagramModelGroup)5 ArchimateTestModel (com.archimatetool.testingtools.ArchimateTestModel)5 IDiagramModelConnection (com.archimatetool.model.IDiagramModelConnection)4 IDiagramModelContainer (com.archimatetool.model.IDiagramModelContainer)4 Dimension (org.eclipse.draw2d.geometry.Dimension)4