Search in sources :

Example 11 with TypeInstance

use of org.obeonetwork.dsl.typeslibrary.TypeInstance in project InformationSystem by ObeoNetwork.

the class ColumnServices method typeLength.

/**
 * Returns the length and the precision of the type associated to the column.
 * Result is like follows :
 * <ul>
 * <li>&lt;length&gt; if the type has the NativeKind.LENGTH attribute</li>
 * <li>&lt;length,precision&gt; if the type has the NativeKind.LENGTH_AND_PRECISION attribute</li>
 *
 * @param col
 *            the column
 * @return a description of the length of the column's type.
 */
public String typeLength(Column col) {
    final String res;
    Type type = col.getType();
    if (type instanceof TypeInstance) {
        TypeInstance instance = (TypeInstance) type;
        switch(instance.getNativeType().getSpec()) {
            case LENGTH:
                res = instance.getLength().toString();
                break;
            case LENGTH_AND_PRECISION:
                res = instance.getLength() + "," + instance.getPrecision();
                break;
            default:
                res = "";
        }
    } else {
        res = "";
    }
    return res;
}
Also used : Type(org.obeonetwork.dsl.typeslibrary.Type) TypeInstance(org.obeonetwork.dsl.typeslibrary.TypeInstance)

Example 12 with TypeInstance

use of org.obeonetwork.dsl.typeslibrary.TypeInstance in project InformationSystem by ObeoNetwork.

the class TypeInstancePropertiesEditionComponent 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) {
    TypeInstance typeInstance = (TypeInstance) semanticObject;
    if (TypeslibraryViewsRepository.TypeInstance.Properties.type == event.getAffectedEditor()) {
        typeInstance.setNativeType(!"".equals(event.getNewValue()) ? (NativeType) event.getNewValue() : null);
    }
    if (TypeslibraryViewsRepository.TypeInstance.Properties.TypeAttributes.length == event.getAffectedEditor()) {
        typeInstance.setLength((java.lang.Integer) EEFConverterUtil.createFromString(EcorePackage.Literals.EINTEGER_OBJECT, (String) event.getNewValue()));
    }
    if (TypeslibraryViewsRepository.TypeInstance.Properties.TypeAttributes.precision == event.getAffectedEditor()) {
        typeInstance.setPrecision((java.lang.Integer) EEFConverterUtil.createFromString(EcorePackage.Literals.EINTEGER_OBJECT, (String) event.getNewValue()));
    }
    if (TypeslibraryViewsRepository.TypeInstance.Properties.literals == event.getAffectedEditor()) {
        if (event.getKind() == PropertiesEditionEvent.SET) {
            typeInstance.getLiterals().clear();
            typeInstance.getLiterals().addAll(((EList) event.getNewValue()));
        }
    }
}
Also used : BasicEList(org.eclipse.emf.common.util.BasicEList) EList(org.eclipse.emf.common.util.EList) NativeType(org.obeonetwork.dsl.typeslibrary.NativeType) TypeInstance(org.obeonetwork.dsl.typeslibrary.TypeInstance)

Example 13 with TypeInstance

use of org.obeonetwork.dsl.typeslibrary.TypeInstance in project InformationSystem by ObeoNetwork.

the class DatabaseFactoryImpl method createColumn.

/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated NOT
 */
public Column createColumn() {
    ColumnImpl column = new ColumnSpec();
    column.setTechID(EcoreUtil.generateUUID());
    TypeInstance type = TypesLibraryFactory.eINSTANCE.createTypeInstance();
    column.setType(type);
    return column;
}
Also used : ColumnSpec(org.obeonetwork.dsl.database.spec.ColumnSpec) TypeInstance(org.obeonetwork.dsl.typeslibrary.TypeInstance)

Example 14 with TypeInstance

use of org.obeonetwork.dsl.typeslibrary.TypeInstance in project InformationSystem by ObeoNetwork.

the class ColumnServicesTest method testColumnLengthLENGTH.

@Test
public void testColumnLengthLENGTH() {
    Column col = (Column) EcoreUtil.create(DatabasePackage.Literals.COLUMN);
    TypeInstance type = (TypeInstance) EcoreUtil.create(TypesLibraryPackage.Literals.TYPE_INSTANCE);
    NativeType nType = (NativeType) EcoreUtil.create(TypesLibraryPackage.Literals.NATIVE_TYPE);
    col.setType(type);
    type.setNativeType(nType);
    nType.setSpec(NativeTypeKind.LENGTH);
    type.setLength(255);
    assertEquals("255", new ColumnServices().typeLength(col));
}
Also used : Column(org.obeonetwork.dsl.database.Column) NativeType(org.obeonetwork.dsl.typeslibrary.NativeType) TypeInstance(org.obeonetwork.dsl.typeslibrary.TypeInstance) Test(org.junit.Test) AbstractTest(org.obeonetwork.database.m2doc.services.common.AbstractTest)

Example 15 with TypeInstance

use of org.obeonetwork.dsl.typeslibrary.TypeInstance in project InformationSystem by ObeoNetwork.

the class ColumnServicesTest method testColumnLengthSIMPLE.

@Test
public void testColumnLengthSIMPLE() {
    Column col = (Column) EcoreUtil.create(DatabasePackage.Literals.COLUMN);
    TypeInstance type = (TypeInstance) EcoreUtil.create(TypesLibraryPackage.Literals.TYPE_INSTANCE);
    NativeType nType = (NativeType) EcoreUtil.create(TypesLibraryPackage.Literals.NATIVE_TYPE);
    col.setType(type);
    type.setNativeType(nType);
    nType.setSpec(NativeTypeKind.SIMPLE);
    assertEquals("", new ColumnServices().typeLength(col));
}
Also used : Column(org.obeonetwork.dsl.database.Column) NativeType(org.obeonetwork.dsl.typeslibrary.NativeType) TypeInstance(org.obeonetwork.dsl.typeslibrary.TypeInstance) Test(org.junit.Test) AbstractTest(org.obeonetwork.database.m2doc.services.common.AbstractTest)

Aggregations

TypeInstance (org.obeonetwork.dsl.typeslibrary.TypeInstance)26 Column (org.obeonetwork.dsl.database.Column)11 NativeType (org.obeonetwork.dsl.typeslibrary.NativeType)11 Test (org.junit.Test)4 AbstractTest (org.obeonetwork.database.m2doc.services.common.AbstractTest)4 EObject (org.eclipse.emf.ecore.EObject)2 Constraint (org.obeonetwork.dsl.database.Constraint)2 Type (org.obeonetwork.dsl.typeslibrary.Type)2 ArrayList (java.util.ArrayList)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 BasicEList (org.eclipse.emf.common.util.BasicEList)1 EList (org.eclipse.emf.common.util.EList)1 EObjectFlatComboSettings (org.eclipse.emf.eef.runtime.ui.widgets.eobjflatcombo.EObjectFlatComboSettings)1 Viewer (org.eclipse.jface.viewers.Viewer)1 ViewerFilter (org.eclipse.jface.viewers.ViewerFilter)1 View (org.obeonetwork.dsl.database.View)1 ColumnSpec (org.obeonetwork.dsl.database.spec.ColumnSpec)1 Attribute (org.obeonetwork.dsl.environment.Attribute)1 Literal (org.obeonetwork.dsl.environment.Literal)1