Search in sources :

Example 6 with Entity

use of org.obeonetwork.dsl.entity.Entity in project InformationSystem by ObeoNetwork.

the class EntityEntityPropertiesEditionComponent 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 Entity entity = (Entity) elt;
        final EntityPropertiesEditionPart entityPart = (EntityPropertiesEditionPart) editingPart;
        // init values
        if (isAccessible(EntityViewsRepository.Entity_.Properties.name))
            entityPart.setName(EEFConverterUtil.convertToString(EcorePackage.Literals.ESTRING, entity.getName()));
        if (isAccessible(EntityViewsRepository.Entity_.Properties.superType)) {
            // init part
            superTypeSettings = new EObjectFlatComboSettings(entity, EnvironmentPackage.eINSTANCE.getStructuredType_Supertype());
            entityPart.initSuperType(superTypeSettings);
            // set the button mode
            entityPart.setSuperTypeButtonMode(ButtonsModeEnum.BROWSE);
        }
        if (isAccessible(EntityViewsRepository.Entity_.Properties.description))
            entityPart.setDescription(EcoreUtil.convertToString(EcorePackage.Literals.ESTRING, entity.getDescription()));
        if (isAccessible(EntityViewsRepository.Entity_.Properties.associatedTypes)) {
            associatedTypesSettings = new ReferencesTableSettings(entity, EnvironmentPackage.eINSTANCE.getStructuredType_AssociatedTypes());
            entityPart.initAssociatedTypes(associatedTypesSettings);
        }
        if (isAccessible(EntityViewsRepository.Entity_.Properties.associatedTypes)) {
            entityPart.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) Entity(org.obeonetwork.dsl.entity.Entity) EntityPropertiesEditionPart(org.obeonetwork.dsl.entity.parts.EntityPropertiesEditionPart) ReferencesTableSettings(org.eclipse.emf.eef.runtime.ui.widgets.referencestable.ReferencesTableSettings) EObjectFlatComboSettings(org.eclipse.emf.eef.runtime.ui.widgets.eobjflatcombo.EObjectFlatComboSettings)

Example 7 with Entity

use of org.obeonetwork.dsl.entity.Entity in project InformationSystem by ObeoNetwork.

the class EntityPersistencePropertiesEditionComponent 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 Entity entity = (Entity) elt;
        final PersistencePropertiesEditionPart persistencePart = (PersistencePropertiesEditionPart) editingPart;
        // init values
        if (isAccessible(EntityViewsRepository.Persistence.Properties.estimatedVolumetry)) {
            persistencePart.setEstimatedVolumetry(EEFConverterUtil.convertToString(EcorePackage.Literals.EINT, entity.getEstimatedVolumetry()));
        }
        if (isAccessible(EntityViewsRepository.Persistence.Properties.estimatedAccess)) {
            persistencePart.setEstimatedAccess(EEFConverterUtil.convertToString(EcorePackage.Literals.EINT, entity.getEstimatedAccess()));
        }
        if (isAccessible(EntityViewsRepository.Persistence.Properties.historized)) {
            persistencePart.setHistorized(entity.isHistorized());
        }
        if (isAccessible(EntityViewsRepository.Persistence.Properties.inheritanceKind)) {
            persistencePart.initInheritanceKind(EEFUtils.choiceOfValues(entity, EntityPackage.eINSTANCE.getEntity_InheritanceKind()), entity.getInheritanceKind());
        }
    // init filters
    // init values for referenced views
    // init filters for referenced views
    }
    setInitializing(false);
}
Also used : Entity(org.obeonetwork.dsl.entity.Entity) PersistencePropertiesEditionPart(org.obeonetwork.dsl.entity.parts.PersistencePropertiesEditionPart)

Example 8 with Entity

use of org.obeonetwork.dsl.entity.Entity in project InformationSystem by ObeoNetwork.

the class EntityToMLD method processNamespaceAndCreateAdditionalFields.

private void processNamespaceAndCreateAdditionalFields(Namespace namespace) {
    // create tables
    for (Entity entity : EntityUtils.getEntitiesInNamespace(namespace)) {
        // Create technical fields
        Table table = getFromOutputTraceabilityMap(entity, DatabasePackage.Literals.TABLE);
        createAdditionalFields(table);
    }
    // process sub-namespaces
    for (Namespace subnamespace : namespace.getOwnedNamespaces()) {
        processNamespaceAndCreateAdditionalFields(subnamespace);
    }
}
Also used : Entity(org.obeonetwork.dsl.entity.Entity) Table(org.obeonetwork.dsl.database.Table) Namespace(org.obeonetwork.dsl.environment.Namespace)

Example 9 with Entity

use of org.obeonetwork.dsl.entity.Entity in project InformationSystem by ObeoNetwork.

the class EntityToMLD method handleForeignKey.

private void handleForeignKey(Reference reference) {
    Table targetTable = getFromOutputTraceabilityMap(EntityUtils.getContainingEntity(reference), DatabasePackage.Literals.TABLE);
    Entity targetEntity = EntityUtils.getReferencedEntity(reference);
    if (targetEntity == null) {
        Activator.getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "No entity referenced by " + EntityUtils.getContainingEntity(reference).getName() + "." + reference.getName()));
        return;
    }
    Table sourceTable = getFromOutputTraceabilityMap(targetEntity, DatabasePackage.Literals.TABLE);
    if (sourceTable == null) {
        // Table was not found among the newly created tables
        // try to retrieve it from additional resources
        String targetEntityKey = LabelProvider.getTableKeyForEntity(targetEntity);
        EObject targetObject = getAdditionalResourcesMap().get(targetEntityKey);
        if (targetObject instanceof Table) {
            sourceTable = (Table) targetObject;
        } else {
            Activator.getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Cannot resolve table: " + targetEntityKey + " for Reference!"));
            return;
        }
    }
    if (shouldCreateJoinTable(reference)) {
        createJoinTable(reference, sourceTable, targetTable);
    } else {
        boolean nullable = getNullableValueForFK(reference);
        if (shouldCreateFKInSource(reference)) {
            createForeignKey(reference, targetTable, sourceTable, nullable);
        } else if (shouldCreateFKInTarget(reference)) {
            createForeignKey(reference, sourceTable, targetTable, nullable);
        }
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) Entity(org.obeonetwork.dsl.entity.Entity) Table(org.obeonetwork.dsl.database.Table) EObject(org.eclipse.emf.ecore.EObject)

Example 10 with Entity

use of org.obeonetwork.dsl.entity.Entity in project InformationSystem by ObeoNetwork.

the class MLDToEntity method createEntity.

private void createEntity(Table table) {
    Entity entity = getFromInputTraceabilityMap(table, EntityPackage.Literals.ENTITY);
    if (entity == null) {
        // The entity does not already exist
        // We have to create a new one
        entity = EntityFactory.eINSTANCE.createEntity();
        getTargetNamespace(table.getOwner()).getTypes().add(entity);
        entity.setName(LabelProvider.getEntityNameFromTable(table));
    }
    // Add to new traceability map
    addToOutputTraceability(table, entity);
    // The following properties are modified even if they already existed
    AnnotationHelper.setPhysicalNameAnnotation(entity, LabelProvider.getEntityPhysicalNameFromTable(table));
    entity.setDescription(table.getComments());
    AnnotationHelper.removePhysicalUniqueAnnotations(entity);
    for (Column column : table.getColumns()) {
        if (!column.isInForeignKey() && !column.isInPrimaryKey() && !AdditionalFieldsUtils.isAdditionalColumn(column)) {
            createAttribute(column, entity);
        }
    }
    AnnotationHelper.removePhysicalCheckAnnotations(entity);
    List<Constraint> constraintsToCreate = new ArrayList<Constraint>();
    for (Constraint constraint : table.getConstraints()) {
        if (!AdditionalFieldsUtils.isAdditionalConstraint(constraint)) {
            constraintsToCreate.add(constraint);
        }
    }
    AnnotationHelper.setAllConstraints(entity, constraintsToCreate);
}
Also used : Entity(org.obeonetwork.dsl.entity.Entity) Column(org.obeonetwork.dsl.database.Column) Constraint(org.obeonetwork.dsl.database.Constraint) ArrayList(java.util.ArrayList)

Aggregations

Entity (org.obeonetwork.dsl.entity.Entity)11 EObject (org.eclipse.emf.ecore.EObject)5 Table (org.obeonetwork.dsl.database.Table)4 Reference (org.obeonetwork.dsl.environment.Reference)4 ArrayList (java.util.ArrayList)3 Constraint (org.obeonetwork.dsl.database.Constraint)3 ForeignKey (org.obeonetwork.dsl.database.ForeignKey)3 IStatus (org.eclipse.core.runtime.IStatus)2 Status (org.eclipse.core.runtime.Status)2 Column (org.obeonetwork.dsl.database.Column)2 Attribute (org.obeonetwork.dsl.environment.Attribute)2 Namespace (org.obeonetwork.dsl.environment.Namespace)2 Collection (java.util.Collection)1 EReference (org.eclipse.emf.ecore.EReference)1 EStructuralFeature (org.eclipse.emf.ecore.EStructuralFeature)1 Setting (org.eclipse.emf.ecore.EStructuralFeature.Setting)1 EcoreUtil (org.eclipse.emf.ecore.util.EcoreUtil)1 EObjectFilter (org.eclipse.emf.eef.runtime.impl.filters.EObjectFilter)1 EObjectFlatComboSettings (org.eclipse.emf.eef.runtime.ui.widgets.eobjflatcombo.EObjectFlatComboSettings)1 ReferencesTableSettings (org.eclipse.emf.eef.runtime.ui.widgets.referencestable.ReferencesTableSettings)1