Search in sources :

Example 1 with IAssociationRelationship

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

the class XMLModelImporter method parseArchiMateRelations.

// ========================================= Relations ======================================
private void parseArchiMateRelations(Element relationsElement) throws IOException {
    if (relationsElement == null) {
        // Optional
        return;
    }
    class RelationInfo {

        IArchimateRelationship relation;

        String sourceID;

        String targetID;
    }
    List<RelationInfo> relationInfoList = new ArrayList<RelationInfo>();
    IFolder relationshipFolder = fModel.getFolder(FolderType.RELATIONS);
    for (Element childElement : relationsElement.getChildren(ELEMENT_RELATIONSHIP, ARCHIMATE3_NAMESPACE)) {
        String type = childElement.getAttributeValue(ATTRIBUTE_TYPE, XSI_NAMESPACE);
        // If type is bogus ignore
        if (type == null) {
            continue;
        }
        IArchimateRelationship relation = (IArchimateRelationship) XMLTypeMapper.createArchimateConcept(type);
        // If relation is null throw exception
        if (relation == null) {
            throw new IOException(NLS.bind(Messages.XMLModelImporter_2, type));
        }
        // Identifier first
        String id = childElement.getAttributeValue(ATTRIBUTE_IDENTIFIER);
        if (id != null) {
            relation.setId(id);
        }
        // Add to model
        relationshipFolder.getElements().add(relation);
        // Name
        String name = getChildElementText(childElement, ELEMENT_NAME, true);
        if (name != null) {
            relation.setName(name);
        }
        // Documentation
        String documentation = getChildElementText(childElement, ELEMENT_DOCUMENTATION, false);
        if (documentation != null) {
            relation.setDocumentation(documentation);
        }
        // Properties
        addProperties(relation, childElement);
        // Source and target
        String sourceID = childElement.getAttributeValue(ATTRIBUTE_SOURCE);
        String targetID = childElement.getAttributeValue(ATTRIBUTE_TARGET);
        // Access type
        if (relation instanceof IAccessRelationship) {
            String accessType = childElement.getAttributeValue(ATTRIBUTE_ACCESS_TYPE);
            if (accessType != null) {
                IAccessRelationship accessRelationship = (IAccessRelationship) relation;
                switch(accessType) {
                    case ACCESS_TYPE_ACCESS:
                        accessRelationship.setAccessType(IAccessRelationship.UNSPECIFIED_ACCESS);
                        break;
                    case ACCESS_TYPE_READ:
                        accessRelationship.setAccessType(IAccessRelationship.READ_ACCESS);
                        break;
                    case ACCESS_TYPE_READ_WRITE:
                        accessRelationship.setAccessType(IAccessRelationship.READ_WRITE_ACCESS);
                        break;
                    default:
                        accessRelationship.setAccessType(IAccessRelationship.WRITE_ACCESS);
                        break;
                }
            }
        } else // Influence type
        if (relation instanceof IInfluenceRelationship) {
            String influenceStrength = childElement.getAttributeValue(ATTRIBUTE_INFLUENCE_MODIFIER);
            if (influenceStrength != null) {
                ((IInfluenceRelationship) relation).setStrength(influenceStrength);
            }
        } else // Association type
        if (relation instanceof IAssociationRelationship) {
            String isDirected = childElement.getAttributeValue(ATTRIBUTE_ASSOCIATION_DIRECTED);
            if ("true".equalsIgnoreCase(isDirected)) {
                // $NON-NLS-1$
                ((IAssociationRelationship) relation).setDirected(true);
            }
        }
        // Add to lookup table
        fConceptsLookup.put(relation.getId(), relation);
        // Add to relations list for 2nd pass
        RelationInfo rInfo = new RelationInfo();
        rInfo.relation = relation;
        rInfo.sourceID = sourceID;
        rInfo.targetID = targetID;
        relationInfoList.add(rInfo);
    }
    // 2nd pass, add source and target concepts
    for (RelationInfo rInfo : relationInfoList) {
        IArchimateConcept source = fConceptsLookup.get(rInfo.sourceID);
        if (source == null) {
            throw new IOException(Messages.XMLModelImporter_3 + rInfo.sourceID);
        }
        IArchimateConcept target = fConceptsLookup.get(rInfo.targetID);
        if (target == null) {
            throw new IOException(Messages.XMLModelImporter_4 + rInfo.targetID);
        }
        rInfo.relation.setSource(source);
        rInfo.relation.setTarget(target);
    }
}
Also used : IInfluenceRelationship(com.archimatetool.model.IInfluenceRelationship) IAssociationRelationship(com.archimatetool.model.IAssociationRelationship) Element(org.jdom2.Element) IArchimateElement(com.archimatetool.model.IArchimateElement) ArrayList(java.util.ArrayList) IArchimateConcept(com.archimatetool.model.IArchimateConcept) IArchimateRelationship(com.archimatetool.model.IArchimateRelationship) IOException(java.io.IOException) IAccessRelationship(com.archimatetool.model.IAccessRelationship) IFolder(com.archimatetool.model.IFolder)

Example 2 with IAssociationRelationship

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

the class CSVImporter method createPropertyFromRecord.

/**
 * Create a Property from a given CSVRecord
 */
private void createPropertyFromRecord(CSVRecord csvRecord) throws CSVParseException {
    // ID
    String id = csvRecord.get(0);
    if (!StringUtils.isSet(id)) {
        throw new CSVParseException(Messages.CSVImporter_6);
    } else {
        checkIDForInvalidCharacters(id);
    }
    // Find referenced concept in newly created list
    IProperties propertiesObject = newConcepts.get(id);
    // Not found, check if it's referencing an existing element in the model
    if (propertiesObject == null) {
        EObject eObject = ArchimateModelUtils.getObjectByID(fModel, id);
        if (eObject instanceof IProperties) {
            propertiesObject = (IProperties) eObject;
        }
    }
    // Not found, check if it's referencing the model
    if (propertiesObject == null && id.equals(modelID)) {
        propertiesObject = fModel;
    }
    // Not found at all
    if (propertiesObject == null) {
        throw new CSVParseException(Messages.CSVImporter_7 + id);
    }
    String key = normalise(csvRecord.get(1));
    String value = normalise(csvRecord.get(2));
    // Handle special properties for some concepts' attributes
    if (INFLUENCE_STRENGTH.equals(key) && propertiesObject instanceof IInfluenceRelationship) {
        storeUpdatedConceptFeature((IArchimateConcept) propertiesObject, IArchimatePackage.Literals.INFLUENCE_RELATIONSHIP__STRENGTH, value);
        return;
    } else if (ACCESS_TYPE.equals(key) && propertiesObject instanceof IAccessRelationship) {
        int newvalue = ACCESS_TYPES.indexOf(value);
        storeUpdatedConceptFeature((IArchimateConcept) propertiesObject, IArchimatePackage.Literals.ACCESS_RELATIONSHIP__ACCESS_TYPE, newvalue);
        return;
    } else if (ASSOCIATION_DIRECTED.endsWith(key) && propertiesObject instanceof IAssociationRelationship) {
        // $NON-NLS-1$
        boolean newvalue = "true".equalsIgnoreCase(value);
        storeUpdatedConceptFeature((IArchimateConcept) propertiesObject, IArchimatePackage.Literals.ASSOCIATION_RELATIONSHIP__DIRECTED, newvalue);
        return;
    } else if (JUNCTION_TYPE.equals(key) && propertiesObject instanceof IJunction) {
        if (JUNCTION_AND.equals(value)) {
            value = IJunction.AND_JUNCTION_TYPE;
        } else {
            value = IJunction.OR_JUNCTION_TYPE;
        }
        storeUpdatedConceptFeature((IArchimateConcept) propertiesObject, IArchimatePackage.Literals.JUNCTION__TYPE, value);
        return;
    }
    // Is there already a property with this key?
    IProperty property = getProperty(propertiesObject, key);
    if (property != null) {
        updatedProperties.put(property, value);
    } else // No, create new one
    {
        property = IArchimateFactory.eINSTANCE.createProperty();
        property.setKey(key);
        property.setValue(value);
        newProperties.put(property, propertiesObject);
    }
}
Also used : IInfluenceRelationship(com.archimatetool.model.IInfluenceRelationship) IAssociationRelationship(com.archimatetool.model.IAssociationRelationship) IProperty(com.archimatetool.model.IProperty) EObject(org.eclipse.emf.ecore.EObject) IArchimateConcept(com.archimatetool.model.IArchimateConcept) IProperties(com.archimatetool.model.IProperties) IAccessRelationship(com.archimatetool.model.IAccessRelationship) CSVParseException(com.archimatetool.csv.CSVParseException) IJunction(com.archimatetool.model.IJunction)

Example 3 with IAssociationRelationship

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

the class AbstractTextRendererTests method getActualObject.

@Test
public void getActualObject() {
    IDiagramModelGroup group = IArchimateFactory.eINSTANCE.createDiagramModelGroup();
    assertSame(group, getRenderer().getActualObject(group));
    IFolder folder = IArchimateFactory.eINSTANCE.createFolder();
    assertSame(folder, getRenderer().getActualObject(folder));
    IDiagramModelArchimateObject dmo = IArchimateFactory.eINSTANCE.createDiagramModelArchimateObject();
    IBusinessActor ba = IArchimateFactory.eINSTANCE.createBusinessActor();
    dmo.setArchimateConcept(ba);
    assertSame(ba, getRenderer().getActualObject(dmo));
    IDiagramModelArchimateConnection dmc = IArchimateFactory.eINSTANCE.createDiagramModelArchimateConnection();
    IAssociationRelationship relation = IArchimateFactory.eINSTANCE.createAssociationRelationship();
    dmc.setArchimateConcept(relation);
    assertSame(relation, getRenderer().getActualObject(dmc));
}
Also used : IBusinessActor(com.archimatetool.model.IBusinessActor) IAssociationRelationship(com.archimatetool.model.IAssociationRelationship) IDiagramModelArchimateConnection(com.archimatetool.model.IDiagramModelArchimateConnection) IDiagramModelGroup(com.archimatetool.model.IDiagramModelGroup) IDiagramModelArchimateObject(com.archimatetool.model.IDiagramModelArchimateObject) IFolder(com.archimatetool.model.IFolder) Test(org.junit.Test)

Example 4 with IAssociationRelationship

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

the class AbstractTextRendererTests method getObjectFromPrefix_ConnectionSourceTarget.

@Test
public void getObjectFromPrefix_ConnectionSourceTarget() {
    IAssociationRelationship relation = IArchimateFactory.eINSTANCE.createAssociationRelationship();
    IBusinessActor ba1 = IArchimateFactory.eINSTANCE.createBusinessActor();
    IBusinessActor ba2 = IArchimateFactory.eINSTANCE.createBusinessActor();
    relation.connect(ba1, ba2);
    IDiagramModelArchimateObject dmo1 = IArchimateFactory.eINSTANCE.createDiagramModelArchimateObject();
    dmo1.setArchimateConcept(ba1);
    IDiagramModelArchimateObject dmo2 = IArchimateFactory.eINSTANCE.createDiagramModelArchimateObject();
    dmo2.setArchimateConcept(ba2);
    IDiagramModelArchimateConnection dmc = IArchimateFactory.eINSTANCE.createDiagramModelArchimateConnection();
    dmc.setArchimateConcept(relation);
    dmc.connect(dmo1, dmo2);
    assertSame(ba1, getRenderer().getObjectFromPrefix(dmc, ITextRenderer.sourcePrefix));
    assertSame(ba2, getRenderer().getObjectFromPrefix(dmc, ITextRenderer.targetPrefix));
}
Also used : IBusinessActor(com.archimatetool.model.IBusinessActor) IAssociationRelationship(com.archimatetool.model.IAssociationRelationship) IDiagramModelArchimateConnection(com.archimatetool.model.IDiagramModelArchimateConnection) IDiagramModelArchimateObject(com.archimatetool.model.IDiagramModelArchimateObject) Test(org.junit.Test)

Example 5 with IAssociationRelationship

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

the class ZestViewerLabelProvider method selfStyleConnection.

// ========================================================================================
// ISelfStyleProvider
// ========================================================================================
@Override
public void selfStyleConnection(Object element, GraphConnection connection) {
    connection.setLineWidth(0);
    connection.setTooltip(getTooltip(element));
    connection.setLineColor(ColorConstants.black);
    connection.setText(getText(element));
    PolylineConnection conn = (PolylineConnection) connection.getConnectionFigure();
    if (element instanceof ISpecializationRelationship) {
        conn.setTargetDecoration(SpecializationConnectionFigure.createFigureTargetDecoration());
    } else if (element instanceof ICompositionRelationship) {
        conn.setSourceDecoration(CompositionConnectionFigure.createFigureSourceDecoration());
    } else if (element instanceof IAggregationRelationship) {
        conn.setSourceDecoration(AggregationConnectionFigure.createFigureSourceDecoration());
    } else if (element instanceof IAssignmentRelationship) {
        conn.setSourceDecoration(AssignmentConnectionFigure.createFigureSourceDecoration());
        conn.setTargetDecoration(AssignmentConnectionFigure.createFigureTargetDecoration());
    } else if (element instanceof IRealizationRelationship) {
        conn.setTargetDecoration(RealizationConnectionFigure.createFigureTargetDecoration());
        connection.setLineStyle(SWT.LINE_CUSTOM);
        conn.setLineDash(new float[] { 2 });
    } else if (element instanceof ITriggeringRelationship) {
        conn.setTargetDecoration(TriggeringConnectionFigure.createFigureTargetDecoration());
    } else if (element instanceof IFlowRelationship) {
        conn.setTargetDecoration(FlowConnectionFigure.createFigureTargetDecoration());
        connection.setLineStyle(SWT.LINE_CUSTOM);
        conn.setLineDash(new float[] { 6, 3 });
    } else if (element instanceof IServingRelationship) {
        conn.setTargetDecoration(ServingConnectionFigure.createFigureTargetDecoration());
    } else if (element instanceof IAccessRelationship) {
        switch(((IAccessRelationship) element).getAccessType()) {
            case IAccessRelationship.WRITE_ACCESS:
            default:
                conn.setSourceDecoration(null);
                // arrow at target endpoint
                conn.setTargetDecoration(AccessConnectionFigure.createFigureTargetDecoration());
                break;
            case IAccessRelationship.READ_ACCESS:
                // arrow at source endpoint
                conn.setSourceDecoration(AccessConnectionFigure.createFigureTargetDecoration());
                conn.setTargetDecoration(null);
                break;
            case IAccessRelationship.UNSPECIFIED_ACCESS:
                // no arrows
                conn.setSourceDecoration(null);
                conn.setTargetDecoration(null);
                break;
            case IAccessRelationship.READ_WRITE_ACCESS:
                // both arrows
                conn.setSourceDecoration(AccessConnectionFigure.createFigureTargetDecoration());
                conn.setTargetDecoration(AccessConnectionFigure.createFigureTargetDecoration());
                break;
        }
        connection.setLineStyle(SWT.LINE_CUSTOM);
        conn.setLineDash(new float[] { 2 });
    } else if (element instanceof IInfluenceRelationship) {
        conn.setTargetDecoration(InfluenceConnectionFigure.createFigureTargetDecoration());
        connection.setLineStyle(SWT.LINE_CUSTOM);
        conn.setLineDash(new float[] { 6, 3 });
    } else if (element instanceof IAssociationRelationship) {
        if (((IAssociationRelationship) element).isDirected()) {
            conn.setTargetDecoration(AssociationConnectionFigure.createFigureTargetDecoration());
        } else {
            conn.setTargetDecoration(null);
        }
    }
    conn.setAntialias(SWT.ON);
}
Also used : IInfluenceRelationship(com.archimatetool.model.IInfluenceRelationship) ICompositionRelationship(com.archimatetool.model.ICompositionRelationship) IRealizationRelationship(com.archimatetool.model.IRealizationRelationship) IAssociationRelationship(com.archimatetool.model.IAssociationRelationship) ITriggeringRelationship(com.archimatetool.model.ITriggeringRelationship) ISpecializationRelationship(com.archimatetool.model.ISpecializationRelationship) IAssignmentRelationship(com.archimatetool.model.IAssignmentRelationship) IAggregationRelationship(com.archimatetool.model.IAggregationRelationship) IFlowRelationship(com.archimatetool.model.IFlowRelationship) IAccessRelationship(com.archimatetool.model.IAccessRelationship) IServingRelationship(com.archimatetool.model.IServingRelationship) PolylineConnection(org.eclipse.draw2d.PolylineConnection)

Aggregations

IAssociationRelationship (com.archimatetool.model.IAssociationRelationship)8 IInfluenceRelationship (com.archimatetool.model.IInfluenceRelationship)4 IAccessRelationship (com.archimatetool.model.IAccessRelationship)3 Test (org.junit.Test)3 IArchimateConcept (com.archimatetool.model.IArchimateConcept)2 IArchimateElement (com.archimatetool.model.IArchimateElement)2 IBusinessActor (com.archimatetool.model.IBusinessActor)2 IDiagramModelArchimateConnection (com.archimatetool.model.IDiagramModelArchimateConnection)2 IDiagramModelArchimateObject (com.archimatetool.model.IDiagramModelArchimateObject)2 IFolder (com.archimatetool.model.IFolder)2 Element (org.jdom2.Element)2 CSVParseException (com.archimatetool.csv.CSVParseException)1 IAggregationRelationship (com.archimatetool.model.IAggregationRelationship)1 IArchimateRelationship (com.archimatetool.model.IArchimateRelationship)1 IAssignmentRelationship (com.archimatetool.model.IAssignmentRelationship)1 ICompositionRelationship (com.archimatetool.model.ICompositionRelationship)1 IDiagramModelGroup (com.archimatetool.model.IDiagramModelGroup)1 IFlowRelationship (com.archimatetool.model.IFlowRelationship)1 IJunction (com.archimatetool.model.IJunction)1 IProperties (com.archimatetool.model.IProperties)1