Search in sources :

Example 16 with IArchimateElement

use of com.archimatetool.model.IArchimateElement in project archi by archimatetool.

the class ZestViewerContentProviderTests method testGetDestination_Relationship.

@Test
public void testGetDestination_Relationship() {
    IArchimateRelationship inputElement = (IArchimateRelationship) tm.getObjectByID("460");
    IArchimateElement expected = (IArchimateElement) tm.getObjectByID("289");
    Object destination = provider.getDestination(inputElement);
    assertEquals(expected, destination);
}
Also used : IArchimateElement(com.archimatetool.model.IArchimateElement) IArchimateRelationship(com.archimatetool.model.IArchimateRelationship) Test(org.junit.Test)

Example 17 with IArchimateElement

use of com.archimatetool.model.IArchimateElement in project archi by archimatetool.

the class CSVExporter method writeElementsInFolder.

/**
 * Write all elements in a given folder and its child folders to Writer
 */
private void writeElementsInFolder(Writer writer, IFolder folder) throws IOException {
    if (folder == null) {
        return;
    }
    List<IArchimateConcept> concepts = getConcepts(folder);
    sort(concepts);
    for (IArchimateConcept concept : concepts) {
        if (concept instanceof IArchimateElement) {
            writer.write(CRLF);
            writer.write(createElementRow((IArchimateElement) concept));
        }
    }
}
Also used : IArchimateConcept(com.archimatetool.model.IArchimateConcept) IArchimateElement(com.archimatetool.model.IArchimateElement)

Example 18 with IArchimateElement

use of com.archimatetool.model.IArchimateElement in project archi by archimatetool.

the class ModelChecker method checkDiagramObjectsReferences.

List<String> checkDiagramObjectsReferences() {
    List<String> messages = new ArrayList<String>();
    for (Iterator<EObject> iter = fModel.getFolder(FolderType.DIAGRAMS).eAllContents(); iter.hasNext(); ) {
        EObject eObject = iter.next();
        if (eObject instanceof IDiagramModelArchimateObject) {
            IDiagramModelArchimateObject dmo = (IDiagramModelArchimateObject) eObject;
            // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
            String name = dmo.getDiagramModel() == null ? Messages.ModelChecker_11 : " '" + dmo.getDiagramModel().getName() + "' (" + dmo.getId() + ")";
            IArchimateElement element = dmo.getArchimateElement();
            if (element == null) {
                messages.add(Messages.ModelChecker_12 + name);
            } else if (element.getArchimateModel() == null) {
                messages.add(Messages.ModelChecker_13 + name);
            }
        }
        if (eObject instanceof IDiagramModelArchimateConnection) {
            IDiagramModelArchimateConnection conn = (IDiagramModelArchimateConnection) eObject;
            // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
            String name = conn.getDiagramModel() == null ? Messages.ModelChecker_14 : " '" + conn.getDiagramModel().getName() + "' (" + conn.getId() + ")";
            IArchimateRelationship relation = conn.getArchimateRelationship();
            if (relation == null) {
                messages.add(Messages.ModelChecker_15 + name);
            } else {
                if (relation.getArchimateModel() == null) {
                    messages.add(Messages.ModelChecker_16 + name);
                }
                if (relation.getSource() != null && relation.getSource().getArchimateModel() == null) {
                    messages.add(Messages.ModelChecker_17 + name);
                }
                if (relation.getTarget() != null && relation.getTarget().getArchimateModel() == null) {
                    messages.add(Messages.ModelChecker_18 + name);
                }
            }
        }
    }
    return messages;
}
Also used : EObject(org.eclipse.emf.ecore.EObject) IDiagramModelArchimateConnection(com.archimatetool.model.IDiagramModelArchimateConnection) ArrayList(java.util.ArrayList) IArchimateElement(com.archimatetool.model.IArchimateElement) IArchimateRelationship(com.archimatetool.model.IArchimateRelationship) IDiagramModelArchimateObject(com.archimatetool.model.IDiagramModelArchimateObject)

Example 19 with IArchimateElement

use of com.archimatetool.model.IArchimateElement 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 20 with IArchimateElement

use of com.archimatetool.model.IArchimateElement 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;
}
Also used : EClass(org.eclipse.emf.ecore.EClass) IArchimateElement(com.archimatetool.model.IArchimateElement) IArchimateRelationship(com.archimatetool.model.IArchimateRelationship)

Aggregations

IArchimateElement (com.archimatetool.model.IArchimateElement)92 Test (org.junit.Test)57 IArchimateRelationship (com.archimatetool.model.IArchimateRelationship)33 IDiagramModelArchimateObject (com.archimatetool.model.IDiagramModelArchimateObject)30 ArrayList (java.util.ArrayList)19 IDiagramModel (com.archimatetool.model.IDiagramModel)16 IArchimateModel (com.archimatetool.model.IArchimateModel)14 IDiagramModelArchimateConnection (com.archimatetool.model.IDiagramModelArchimateConnection)13 IDiagramModelObject (com.archimatetool.model.IDiagramModelObject)11 IFolder (com.archimatetool.model.IFolder)11 EObject (org.eclipse.emf.ecore.EObject)11 IIssue (com.archimatetool.hammer.validation.issues.IIssue)8 ArchimateTestModel (com.archimatetool.testingtools.ArchimateTestModel)8 IArchimateConcept (com.archimatetool.model.IArchimateConcept)6 Command (org.eclipse.gef.commands.Command)5 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)5 WarningType (com.archimatetool.hammer.validation.issues.WarningType)4 IDiagramModelConnection (com.archimatetool.model.IDiagramModelConnection)4 CommandStack (org.eclipse.gef.commands.CommandStack)4 NoteEditPart (com.archimatetool.editor.diagram.editparts.diagram.NoteEditPart)3