use of org.obeonetwork.dsl.typeslibrary.TypeInstance 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());
}
}
use of org.obeonetwork.dsl.typeslibrary.TypeInstance in project InformationSystem by ObeoNetwork.
the class CustomColumnPropertiesEditionComponent method updateTypeFieldsVisibility.
private void updateTypeFieldsVisibility(Column column, ColumnPropertiesEditionPart basePart) {
if (column.getType() instanceof TypeInstance) {
TypeInstance typeInstance = (TypeInstance) column.getType();
if (typeInstance.getNativeType() != null) {
NativeTypeKind nativeTypeKind = typeInstance.getNativeType().getSpec();
boolean lengthVisible = (nativeTypeKind == NativeTypeKind.LENGTH || nativeTypeKind == NativeTypeKind.LENGTH_AND_PRECISION);
boolean precisionVisible = (nativeTypeKind == NativeTypeKind.LENGTH_AND_PRECISION);
boolean literalsVisible = (nativeTypeKind == NativeTypeKind.ENUM);
basePart.updateTypeFields(lengthVisible, precisionVisible, literalsVisible);
}
}
}
use of org.obeonetwork.dsl.typeslibrary.TypeInstance in project InformationSystem by ObeoNetwork.
the class DatabaseEditLabelServices method setType.
private void setType(Column column, String typeName, Collection<NativeTypesLibrary> typesLibraries) {
for (NativeTypesLibrary nativeTypesLibrary : typesLibraries) {
for (NativeType nativeType : nativeTypesLibrary.getNativeTypes()) {
String typePattern = getNativeTypePattern(nativeType);
String typeRegexPattern = null;
if (nativeType.getSpec() == NativeTypeKind.ENUM) {
typeRegexPattern = typePattern;
} else {
typeRegexPattern = typePattern.replace("%n", "(.*)");
typeRegexPattern = typeRegexPattern.replace("%p", "(.*)");
}
if (typeRegexPattern != null) {
Pattern ptn = null;
try {
ptn = Pattern.compile(typeRegexPattern, Pattern.CASE_INSENSITIVE);
} catch (Exception e) {
// Do nothing, the loop will try the other types
}
if (ptn != null) {
Matcher matcher = ptn.matcher(typeName);
if (matcher.matches()) {
// Ensure there is a type instance
if (column.getType() == null || (column.getType() instanceof TypeInstance == false)) {
TypeInstance type = TypesLibraryFactory.eINSTANCE.createTypeInstance();
type.setNativeType(nativeType);
column.setType(type);
}
TypeInstance columnType = ((TypeInstance) column.getType());
columnType.setNativeType(nativeType);
switch(nativeType.getSpec()) {
case SIMPLE:
// Nothing special to do
return;
case LENGTH:
// Retrieve length
String lengthString = matcher.group(1).trim();
// Ensure its a string representing an int
int length = getIntValue(lengthString);
columnType.setLength(length);
return;
case LENGTH_AND_PRECISION:
int nPos = typePattern.indexOf("%n");
int pPos = typePattern.indexOf("%p");
String nString = null;
String pString = null;
if (nPos < pPos) {
nString = matcher.group(1).trim();
nString = matcher.group(2).trim();
} else {
nString = matcher.group(2).trim();
pString = matcher.group(1).trim();
}
int nValue = getIntValue(nString);
int pValue = getIntValue(pString);
columnType.setLength(nValue);
columnType.setPrecision(pValue);
break;
case ENUM:
// Retrieves values
columnType.getLiterals().clear();
String valuesString = matcher.group(1).trim();
for (String value : valuesString.split(",")) {
columnType.getLiterals().add(value.trim());
}
return;
}
}
}
}
}
}
}
use of org.obeonetwork.dsl.typeslibrary.TypeInstance in project InformationSystem by ObeoNetwork.
the class SimpleNamedTypePropertiesEditionComponent 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 SimpleNamedType simpleNamedType = (SimpleNamedType) elt;
final SimpleNamedTypePropertiesEditionPart simpleNamedTypePart = (SimpleNamedTypePropertiesEditionPart) editingPart;
// init values
if (isAccessible(TypeslibraryViewsRepository.SimpleNamedType.Properties.name))
simpleNamedTypePart.setName(EEFConverterUtil.convertToString(EcorePackage.Literals.ESTRING, simpleNamedType.getName()));
if (isAccessible(TypeslibraryViewsRepository.SimpleNamedType.Properties.type)) {
// init part
typeSettings = new EObjectFlatComboSettings(simpleNamedType, TypesLibraryPackage.eINSTANCE.getSimpleNamedType_Type());
simpleNamedTypePart.initType(typeSettings);
// set the button mode
simpleNamedTypePart.setTypeButtonMode(ButtonsModeEnum.BROWSE);
}
if (isAccessible(TypeslibraryViewsRepository.SimpleNamedType.Properties.type)) {
simpleNamedTypePart.addFilterToType(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 TypeInstance);
}
});
// Start of user code for additional businessfilters for type
// End of user code
}
// init values for referenced views
// init filters for referenced views
}
setInitializing(false);
}
use of org.obeonetwork.dsl.typeslibrary.TypeInstance in project InformationSystem by ObeoNetwork.
the class TypeInstancePropertiesEditionComponent 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 TypeInstance typeInstance = (TypeInstance) elt;
final TypeInstancePropertiesEditionPart typeInstancePart = (TypeInstancePropertiesEditionPart) editingPart;
// init values
if (isAccessible(TypeslibraryViewsRepository.TypeInstance.Properties.type)) {
typeInstancePart.initType(EEFUtils.choiceOfValues(typeInstance, TypesLibraryPackage.eINSTANCE.getTypeInstance_NativeType()), typeInstance.getNativeType());
}
if (isAccessible(TypeslibraryViewsRepository.TypeInstance.Properties.TypeAttributes.length))
typeInstancePart.setLength(EEFConverterUtil.convertToString(EcorePackage.Literals.EINTEGER_OBJECT, typeInstance.getLength()));
if (isAccessible(TypeslibraryViewsRepository.TypeInstance.Properties.TypeAttributes.precision))
typeInstancePart.setPrecision(EEFConverterUtil.convertToString(EcorePackage.Literals.EINTEGER_OBJECT, typeInstance.getPrecision()));
if (isAccessible(TypeslibraryViewsRepository.TypeInstance.Properties.literals))
typeInstancePart.setLiterals(typeInstance.getLiterals());
// init filters
// Start of user code for additional businessfilters for type
// End of user code
// init values for referenced views
// init filters for referenced views
}
setInitializing(false);
}
Aggregations