Search in sources :

Example 6 with StructuredType

use of org.obeonetwork.dsl.environment.StructuredType in project InformationSystem by ObeoNetwork.

the class TypesServices method reconnectSourceOnInheritanceEdge.

/**
 * Create an inheritance relationship using the reconnect edge to retrieve the supertype.
 * Do nothing and displays an information dialog if the new inheritance would cause a cycle.
 * @param newSubTypeCandidate
 * @param edgeView Edge used to retrieve the super type (i.e.the edge's target node)
 * @return
 */
public StructuredType reconnectSourceOnInheritanceEdge(final StructuredType newSubTypeCandidate, final StructuredType previousSubType, final DEdge edgeView) {
    StructuredType superTypeCandidate = getStructuredTypeFromEdgeTarget(edgeView.getTargetNode());
    if (previousSubType != null && superTypeCandidate != null) {
        if (isSubtype(superTypeCandidate, newSubTypeCandidate)) {
            // The new superType is already a sub-type of the subtype candidate
            // setting the new inheritance relationship would lead to a cycle
            // We warn the user that this is not possible
            new UIServices().displayInfo(newSubTypeCandidate, "Creation of inheritance relationship not allowed !", "Creation has been cancelled.\n\n" + newSubTypeCandidate.getName() + " is already a super-type of " + superTypeCandidate.getName() + ".\n" + "The new inheritance relationship would cause a cycle which is not allowed.");
        } else {
            // Remove old inheritance
            previousSubType.setSupertype(null);
            newSubTypeCandidate.setSupertype(superTypeCandidate);
        }
    }
    return newSubTypeCandidate;
}
Also used : StructuredType(org.obeonetwork.dsl.environment.StructuredType)

Example 7 with StructuredType

use of org.obeonetwork.dsl.environment.StructuredType in project InformationSystem by ObeoNetwork.

the class BindingService method getAllStructuredTypes.

private Collection<StructuredType> getAllStructuredTypes(EObject any) {
    // Collect all structured types
    Collection<StructuredType> structuredTypes = new ArrayList<StructuredType>();
    // First, get all semantic resources in session
    Collection<Resource> semanticResources = getAllSemanticResourcesInSession(any);
    for (Resource resource : semanticResources) {
        TreeIterator<EObject> iterator = EcoreUtil.getAllContents(resource, true);
        while (iterator.hasNext()) {
            EObject eObject = (EObject) iterator.next();
            if (eObject instanceof StructuredType) {
                structuredTypes.add((StructuredType) eObject);
            } else {
                if (!(eObject instanceof TypesDefinition || eObject instanceof NamespacesContainer || isOverviewRootInstance(eObject))) {
                    iterator.prune();
                }
            }
        }
    }
    return structuredTypes;
}
Also used : NamespacesContainer(org.obeonetwork.dsl.environment.NamespacesContainer) EObject(org.eclipse.emf.ecore.EObject) ArrayList(java.util.ArrayList) Resource(org.eclipse.emf.ecore.resource.Resource) StructuredType(org.obeonetwork.dsl.environment.StructuredType) TypesDefinition(org.obeonetwork.dsl.environment.TypesDefinition)

Example 8 with StructuredType

use of org.obeonetwork.dsl.environment.StructuredType in project InformationSystem by ObeoNetwork.

the class DBoundElementContentProvider method getDelegatedChildren.

private EObject[] getDelegatedChildren(EObject object) {
    if (object instanceof StructuredType) {
        StructuredType structuredType = (StructuredType) object;
        List<Property> properties = new ArrayList<Property>();
        properties.addAll(structuredType.getAttributes());
        for (StructuredType associatedType : structuredType.getAssociatedTypes()) {
            properties.addAll(associatedType.getAttributes());
        }
        properties.addAll(structuredType.getReferences());
        return (EObject[]) properties.toArray(new EObject[] {});
    } else if (object instanceof Reference) {
        Reference entityReference = (Reference) object;
        if (entityReference.getReferencedType() != null) {
            return getDelegatedChildren(entityReference.getReferencedType());
        } else {
            return new EObject[] {};
        }
    }
    return new EObject[] {};
}
Also used : Reference(org.obeonetwork.dsl.environment.Reference) EObject(org.eclipse.emf.ecore.EObject) ArrayList(java.util.ArrayList) Property(org.obeonetwork.dsl.environment.Property) StructuredType(org.obeonetwork.dsl.environment.StructuredType)

Example 9 with StructuredType

use of org.obeonetwork.dsl.environment.StructuredType in project InformationSystem by ObeoNetwork.

the class EntityToMLD method createTable.

private void createTable(Entity entity) {
    // Retrieve the existing table
    Table table = getFromInputTraceabilityMap(entity, DatabasePackage.Literals.TABLE);
    Namespace namespace = EntityUtils.getContainingNamespace(entity);
    if (table == null) {
        // The table does not already exist we have to create a new one
        table = DatabaseFactory.eINSTANCE.createTable();
        TableContainer targetTableContainer = getTargetTableContainer(namespace);
        targetTableContainer.getTables().add(table);
    } else {
        // We have to ensure the schema name is correct
        String realSchemaName = getSchemaNameFromNamespace(namespace);
        TableContainer tableContainer = table.getOwner();
        if (!realSchemaName.equals(tableContainer.getName())) {
            tableContainer.setName(realSchemaName);
        }
    }
    // Add to traceability map
    addToOutputTraceability(entity, table);
    // The following properties are modified even if they already existed
    table.setName(LabelProvider.getTableNameFromEntity(entity));
    table.setComments(entity.getDescription());
    // Handle attributes
    boolean hasPKAttribute = false;
    Collection<Attribute> allAttributes = new ArrayList<Attribute>();
    // Attributes from the entity and its supertypes
    allAttributes.addAll(entity.getAttributes());
    // Attributes from associated DTOs
    for (StructuredType associatedType : entity.getAssociatedTypes()) {
        allAttributes.addAll(associatedType.getAttributes());
    }
    for (Attribute attribute : allAttributes) {
        createColumn(attribute, table);
        if (attribute.isIsIdentifier()) {
            hasPKAttribute = true;
        }
    }
    // Create an ID column if no attribute was set as "primary key"
    if (hasPKAttribute == false) {
        createDefaultIdColumn(table);
    }
    // Update comments on PK
    PrimaryKey primaryKey = table.getPrimaryKey();
    if (primaryKey != null) {
        primaryKey.setName(table.getName() + "_PK");
        primaryKey.setComments(getPKComments(primaryKey));
    }
    // Create constraints
    createConstraints(entity, table);
}
Also used : Table(org.obeonetwork.dsl.database.Table) Attribute(org.obeonetwork.dsl.environment.Attribute) TableContainer(org.obeonetwork.dsl.database.TableContainer) ArrayList(java.util.ArrayList) PrimaryKey(org.obeonetwork.dsl.database.PrimaryKey) Namespace(org.obeonetwork.dsl.environment.Namespace) StructuredType(org.obeonetwork.dsl.environment.StructuredType)

Example 10 with StructuredType

use of org.obeonetwork.dsl.environment.StructuredType in project InformationSystem by ObeoNetwork.

the class DtoDtoPropertiesEditionComponent method initPart.

/**
 * {@inheritDoc}
 *
 * @see org.eclipse.emf.eef.runtime.api.component.IPropertiesEditionComponent#initPart(java.lang.Object, int, org.eclipse.emf.ecore.EObject,
 *      org.eclipse.emf.ecore.resource.ResourceSet)
 */
public void initPart(Object key, int kind, EObject elt, ResourceSet allResource) {
    setInitializing(true);
    if (editingPart != null && key == partKey) {
        editingPart.setContext(elt, allResource);
        final DTO dTO = (DTO) elt;
        final DtoPropertiesEditionPart dtoPart = (DtoPropertiesEditionPart) editingPart;
        // init values
        if (isAccessible(EnvironmentViewsRepository.Dto.Properties.name))
            dtoPart.setName(EEFConverterUtil.convertToString(EcorePackage.Literals.ESTRING, dTO.getName()));
        if (isAccessible(EnvironmentViewsRepository.Dto.Properties.supertype)) {
            // init part
            supertypeSettings = new EObjectFlatComboSettings(dTO, EnvironmentPackage.eINSTANCE.getStructuredType_Supertype());
            dtoPart.initSupertype(supertypeSettings);
            // set the button mode
            dtoPart.setSupertypeButtonMode(ButtonsModeEnum.BROWSE);
        }
        if (isAccessible(EnvironmentViewsRepository.Dto.Properties.description))
            dtoPart.setDescription(EcoreUtil.convertToString(EcorePackage.Literals.ESTRING, dTO.getDescription()));
        if (isAccessible(EnvironmentViewsRepository.Dto.Properties.associatedTypes)) {
            associatedTypesSettings = new ReferencesTableSettings(dTO, EnvironmentPackage.eINSTANCE.getStructuredType_AssociatedTypes());
            dtoPart.initAssociatedTypes(associatedTypesSettings);
        }
        if (isAccessible(EnvironmentViewsRepository.Dto.Properties.supertype)) {
            dtoPart.addFilterToSupertype(new ViewerFilter() {

                /**
                 * {@inheritDoc}
                 *
                 * @see org.eclipse.jface.viewers.ViewerFilter#select(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
                 */
                public boolean select(Viewer viewer, Object parentElement, Object element) {
                    // $NON-NLS-1$
                    return (element instanceof String && element.equals("")) || (element instanceof StructuredType);
                }
            });
        // Start of user code for additional businessfilters for supertype
        // End of user code
        }
        if (isAccessible(EnvironmentViewsRepository.Dto.Properties.associatedTypes)) {
            dtoPart.addFilterToAssociatedTypes(new EObjectFilter(EnvironmentPackage.Literals.STRUCTURED_TYPE));
        // Start of user code for additional businessfilters for associatedTypes
        // End of user code
        }
    // init values for referenced views
    // init filters for referenced views
    }
    setInitializing(false);
}
Also used : EObjectFilter(org.eclipse.emf.eef.runtime.impl.filters.EObjectFilter) ReferencesTableSettings(org.eclipse.emf.eef.runtime.ui.widgets.referencestable.ReferencesTableSettings) ViewerFilter(org.eclipse.jface.viewers.ViewerFilter) DtoPropertiesEditionPart(org.obeonetwork.dsl.environment.parts.DtoPropertiesEditionPart) Viewer(org.eclipse.jface.viewers.Viewer) EObject(org.eclipse.emf.ecore.EObject) EObjectFlatComboSettings(org.eclipse.emf.eef.runtime.ui.widgets.eobjflatcombo.EObjectFlatComboSettings) DTO(org.obeonetwork.dsl.environment.DTO) StructuredType(org.obeonetwork.dsl.environment.StructuredType)

Aggregations

StructuredType (org.obeonetwork.dsl.environment.StructuredType)22 ArrayList (java.util.ArrayList)11 Reference (org.obeonetwork.dsl.environment.Reference)9 EObject (org.eclipse.emf.ecore.EObject)8 HashSet (java.util.HashSet)5 Attribute (org.obeonetwork.dsl.environment.Attribute)3 Type (org.obeonetwork.dsl.environment.Type)3 HashMap (java.util.HashMap)2 Resource (org.eclipse.emf.ecore.resource.Resource)2 EObjectFlatComboSettings (org.eclipse.emf.eef.runtime.ui.widgets.eobjflatcombo.EObjectFlatComboSettings)2 Viewer (org.eclipse.jface.viewers.Viewer)2 ViewerFilter (org.eclipse.jface.viewers.ViewerFilter)2 BindingInfo (org.obeonetwork.dsl.environment.BindingInfo)2 DataType (org.obeonetwork.dsl.environment.DataType)2 Enumeration (org.obeonetwork.dsl.environment.Enumeration)2 Namespace (org.obeonetwork.dsl.environment.Namespace)2 Collator (java.text.Collator)1 LinkedHashSet (java.util.LinkedHashSet)1 NotificationChain (org.eclipse.emf.common.notify.NotificationChain)1 EClass (org.eclipse.emf.ecore.EClass)1