Search in sources :

Example 1 with Literal

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

the class EnumerationEnumerationPropertiesEditionComponent 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 Enumeration enumeration = (Enumeration) elt;
        final EnumerationPropertiesEditionPart enumerationPart = (EnumerationPropertiesEditionPart) editingPart;
        // init values
        if (isAccessible(EnvironmentViewsRepository.Enumeration.Properties.name))
            enumerationPart.setName(EEFConverterUtil.convertToString(EcorePackage.Literals.ESTRING, enumeration.getName()));
        if (isAccessible(EnvironmentViewsRepository.Enumeration.Properties.literals)) {
            literalsSettings = new ReferencesTableSettings(enumeration, EnvironmentPackage.eINSTANCE.getEnumeration_Literals());
            enumerationPart.initLiterals(literalsSettings);
        }
        if (isAccessible(EnvironmentViewsRepository.Enumeration.Properties.description))
            enumerationPart.setDescription(EcoreUtil.convertToString(EcorePackage.Literals.ESTRING, enumeration.getDescription()));
        if (isAccessible(EnvironmentViewsRepository.Enumeration.Properties.literals)) {
            enumerationPart.addFilterToLiterals(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) {
                    return (element instanceof Literal);
                }
            });
        // Start of user code for additional businessfilters for literals
        // End of user code
        }
    // init values for referenced views
    // init filters for referenced views
    }
    setInitializing(false);
}
Also used : EnumerationPropertiesEditionPart(org.obeonetwork.dsl.environment.parts.EnumerationPropertiesEditionPart) Enumeration(org.obeonetwork.dsl.environment.Enumeration) ReferencesTableSettings(org.eclipse.emf.eef.runtime.ui.widgets.referencestable.ReferencesTableSettings) ViewerFilter(org.eclipse.jface.viewers.ViewerFilter) Literal(org.obeonetwork.dsl.environment.Literal) Viewer(org.eclipse.jface.viewers.Viewer) EObject(org.eclipse.emf.ecore.EObject)

Example 2 with Literal

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

the class EnumerationEnumerationPropertiesEditionComponent method updateSemanticModel.

/**
 * {@inheritDoc}
 * @see org.eclipse.emf.eef.runtime.impl.components.StandardPropertiesEditionComponent#updateSemanticModel(org.eclipse.emf.eef.runtime.api.notify.IPropertiesEditionEvent)
 */
public void updateSemanticModel(final IPropertiesEditionEvent event) {
    Enumeration enumeration = (Enumeration) semanticObject;
    if (EnvironmentViewsRepository.Enumeration.Properties.name == event.getAffectedEditor()) {
        enumeration.setName((java.lang.String) EEFConverterUtil.createFromString(EcorePackage.Literals.ESTRING, (String) event.getNewValue()));
    }
    if (EnvironmentViewsRepository.Enumeration.Properties.literals == event.getAffectedEditor()) {
        if (event.getKind() == PropertiesEditionEvent.ADD) {
            EReferencePropertiesEditionContext context = new EReferencePropertiesEditionContext(editingContext, this, literalsSettings, editingContext.getAdapterFactory());
            PropertiesEditingProvider provider = (PropertiesEditingProvider) editingContext.getAdapterFactory().adapt(semanticObject, PropertiesEditingProvider.class);
            if (provider != null) {
                PropertiesEditingPolicy policy = provider.getPolicy(context);
                if (policy instanceof CreateEditingPolicy) {
                    policy.execute();
                }
            }
        } else if (event.getKind() == PropertiesEditionEvent.EDIT) {
            EObjectPropertiesEditionContext context = new EObjectPropertiesEditionContext(editingContext, this, (EObject) event.getNewValue(), editingContext.getAdapterFactory());
            PropertiesEditingProvider provider = (PropertiesEditingProvider) editingContext.getAdapterFactory().adapt((EObject) event.getNewValue(), PropertiesEditingProvider.class);
            if (provider != null) {
                PropertiesEditingPolicy editionPolicy = provider.getPolicy(context);
                if (editionPolicy != null) {
                    editionPolicy.execute();
                }
            }
        } else if (event.getKind() == PropertiesEditionEvent.REMOVE) {
            literalsSettings.removeFromReference((EObject) event.getNewValue());
        } else if (event.getKind() == PropertiesEditionEvent.MOVE) {
            literalsSettings.move(event.getNewIndex(), (Literal) event.getNewValue());
        }
    }
    if (EnvironmentViewsRepository.Enumeration.Properties.description == event.getAffectedEditor()) {
        enumeration.setDescription((java.lang.String) EEFConverterUtil.createFromString(EcorePackage.Literals.ESTRING, (String) event.getNewValue()));
    }
}
Also used : EObjectPropertiesEditionContext(org.eclipse.emf.eef.runtime.context.impl.EObjectPropertiesEditionContext) Enumeration(org.obeonetwork.dsl.environment.Enumeration) PropertiesEditingProvider(org.eclipse.emf.eef.runtime.providers.PropertiesEditingProvider) EObject(org.eclipse.emf.ecore.EObject) Literal(org.obeonetwork.dsl.environment.Literal) PropertiesEditingPolicy(org.eclipse.emf.eef.runtime.policies.PropertiesEditingPolicy) CreateEditingPolicy(org.eclipse.emf.eef.runtime.policies.impl.CreateEditingPolicy) EReferencePropertiesEditionContext(org.eclipse.emf.eef.runtime.context.impl.EReferencePropertiesEditionContext)

Example 3 with Literal

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

the class LiteralLiteralPropertiesEditionComponent 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 Literal literal = (Literal) elt;
        final LiteralPropertiesEditionPart literalPart = (LiteralPropertiesEditionPart) editingPart;
        // init values
        if (isAccessible(EnvironmentViewsRepository.Literal.Properties.name))
            literalPart.setName(EEFConverterUtil.convertToString(EcorePackage.Literals.ESTRING, literal.getName()));
        if (isAccessible(EnvironmentViewsRepository.Literal.Properties.description))
            literalPart.setDescription(EcoreUtil.convertToString(EcorePackage.Literals.ESTRING, literal.getDescription()));
    // init filters
    // init values for referenced views
    // init filters for referenced views
    }
    setInitializing(false);
}
Also used : Literal(org.obeonetwork.dsl.environment.Literal) LiteralPropertiesEditionPart(org.obeonetwork.dsl.environment.parts.LiteralPropertiesEditionPart)

Example 4 with Literal

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

the class EntityToMLD method handleEnumType.

private void handleEnumType(Column column, Enumeration enumeration, Table table) {
    // For an enumeration
    // Column has type Texte
    TypeInstance typeInstance = TypesLibraryFactory.eINSTANCE.createTypeInstance();
    typeInstance.setNativeType(nativeTypesMap.get(ENUM_COLUMN_TYPE));
    column.setType(typeInstance);
    // Column size is the maximum length of the literals
    int maxSize = 0;
    List<String> literalValues = new ArrayList<String>();
    for (Literal literal : enumeration.getLiterals()) {
        String value = literal.getName();
        if (value != null) {
            literalValues.add("''" + value + "''");
            int length = value.length();
            if (maxSize < length) {
                maxSize = length;
            }
        }
    }
    if (maxSize > 0) {
        typeInstance.setLength(maxSize);
    }
    // A check constraint is added with all literals
    String expression = MessageFormat.format("{0} in ({1})", column.getName(), Joiner.on(",").join(literalValues));
    Constraint validityConstraint = findOrCreateConstraint(table, expression);
    validityConstraint.setName("ENUM_CONSTRAINT");
    validityConstraint.setComments(MessageFormat.format(ENUM_CONSTRAINTS_COMMENTS, column.getName()));
    addToObjectsToBeKept(validityConstraint);
    // A default value is added, it is the first literal
    if (!enumeration.getLiterals().isEmpty()) {
        column.setDefaultValue(enumeration.getLiterals().get(0).getName());
    }
}
Also used : Constraint(org.obeonetwork.dsl.database.Constraint) Literal(org.obeonetwork.dsl.environment.Literal) ArrayList(java.util.ArrayList) TypeInstance(org.obeonetwork.dsl.typeslibrary.TypeInstance) Constraint(org.obeonetwork.dsl.database.Constraint)

Aggregations

Literal (org.obeonetwork.dsl.environment.Literal)4 EObject (org.eclipse.emf.ecore.EObject)2 Enumeration (org.obeonetwork.dsl.environment.Enumeration)2 ArrayList (java.util.ArrayList)1 EObjectPropertiesEditionContext (org.eclipse.emf.eef.runtime.context.impl.EObjectPropertiesEditionContext)1 EReferencePropertiesEditionContext (org.eclipse.emf.eef.runtime.context.impl.EReferencePropertiesEditionContext)1 PropertiesEditingPolicy (org.eclipse.emf.eef.runtime.policies.PropertiesEditingPolicy)1 CreateEditingPolicy (org.eclipse.emf.eef.runtime.policies.impl.CreateEditingPolicy)1 PropertiesEditingProvider (org.eclipse.emf.eef.runtime.providers.PropertiesEditingProvider)1 ReferencesTableSettings (org.eclipse.emf.eef.runtime.ui.widgets.referencestable.ReferencesTableSettings)1 Viewer (org.eclipse.jface.viewers.Viewer)1 ViewerFilter (org.eclipse.jface.viewers.ViewerFilter)1 Constraint (org.obeonetwork.dsl.database.Constraint)1 EnumerationPropertiesEditionPart (org.obeonetwork.dsl.environment.parts.EnumerationPropertiesEditionPart)1 LiteralPropertiesEditionPart (org.obeonetwork.dsl.environment.parts.LiteralPropertiesEditionPart)1 TypeInstance (org.obeonetwork.dsl.typeslibrary.TypeInstance)1