use of org.obeonetwork.dsl.typeslibrary.NativeTypesLibrary in project InformationSystem by ObeoNetwork.
the class TypesLibraryUtil method getLogicalTypesLibrary.
public static NativeTypesLibrary getLogicalTypesLibrary(ResourceSet resourceSet) {
URI typeslibraryURI = URI.createURI(LOGICAL_PATHMAP);
Resource resource = resourceSet.getResource(typeslibraryURI, true);
NativeTypesLibrary nativeTypesLibrary = (NativeTypesLibrary) resource.getContents().get(0);
return nativeTypesLibrary;
}
use of org.obeonetwork.dsl.typeslibrary.NativeTypesLibrary in project InformationSystem by ObeoNetwork.
the class DatabaseGen method computeTargetFolder.
private File computeTargetFolder(File folder, Comparison comparison) {
String folderName = "";
String dbtypeFolderName = "";
if (comparison != null) {
DataBase database = (DataBase) comparison.getMatches().get(0).getLeft();
TypesLibrary physicalTypesLibrary = new TypesServices().getPhysicalTypesLibrary(database);
if (physicalTypesLibrary instanceof NativeTypesLibrary) {
dbtypeFolderName += ((NativeTypesLibrary) physicalTypesLibrary).getName() + "/";
} else if (physicalTypesLibrary instanceof UserDefinedTypesLibrary) {
dbtypeFolderName += ((UserDefinedTypesLibrary) physicalTypesLibrary).getName() + "/";
}
folderName = database.getName();
if (database.getSchemas().size() > 0) {
Schema schema = database.getSchemas().get(0);
folderName = schema.getName();
}
folderName += "-";
}
java.sql.Timestamp timeStampDate = new Timestamp(System.currentTimeMillis());
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd/HH-mm-ss");
String timestamp = formatter.format(timeStampDate);
folderName += timestamp;
File targetFolder = new File(folder.getAbsolutePath() + "/" + dbtypeFolderName + folderName);
return targetFolder;
}
use of org.obeonetwork.dsl.typeslibrary.NativeTypesLibrary in project InformationSystem by ObeoNetwork.
the class NativeTypesLibraryPropertiesEditionComponent 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 NativeTypesLibrary nativeTypesLibrary = (NativeTypesLibrary) elt;
final NativeTypesLibraryPropertiesEditionPart nativeTypesLibraryPart = (NativeTypesLibraryPropertiesEditionPart) editingPart;
// init values
if (isAccessible(TypeslibraryViewsRepository.NativeTypesLibrary.Properties.name))
nativeTypesLibraryPart.setName(EEFConverterUtil.convertToString(EcorePackage.Literals.ESTRING, nativeTypesLibrary.getName()));
if (isAccessible(TypeslibraryViewsRepository.NativeTypesLibrary.Properties.nativeTypes)) {
nativeTypesSettings = new ReferencesTableSettings(nativeTypesLibrary, TypesLibraryPackage.eINSTANCE.getNativeTypesLibrary_NativeTypes());
nativeTypesLibraryPart.initNativeTypes(nativeTypesSettings);
}
if (isAccessible(TypeslibraryViewsRepository.NativeTypesLibrary.Properties.nativeTypes)) {
nativeTypesLibraryPart.addFilterToNativeTypes(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 NativeType);
}
});
// Start of user code for additional businessfilters for nativeTypes
// End of user code
}
// init values for referenced views
// init filters for referenced views
}
setInitializing(false);
}
use of org.obeonetwork.dsl.typeslibrary.NativeTypesLibrary in project InformationSystem by ObeoNetwork.
the class DatabaseEditLabelServices method caseColumn.
@Override
public DatabaseElement caseColumn(Column column) {
// the label can be in the form "attributeName : typeName (precision, length)"
int pos = editedLabelContent.indexOf(':');
if (pos != -1) {
String attributeName = editedLabelContent.substring(0, pos).trim();
column.setName(attributeName);
String typeDef = editedLabelContent.substring(pos + 1).trim();
// Retrieve types libraries
DataBase database = getDataBase(column);
if (database != null) {
Collection<NativeTypesLibrary> nativeTypesLibraries = new ArrayList<NativeTypesLibrary>();
for (TypesLibrary library : database.getUsedLibraries()) {
if (library instanceof NativeTypesLibrary) {
nativeTypesLibraries.add((NativeTypesLibrary) library);
}
}
setType(column, typeDef, nativeTypesLibraries);
}
} else {
// there is only a name
return super.caseNamedElement(column);
}
return column;
}
use of org.obeonetwork.dsl.typeslibrary.NativeTypesLibrary 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;
}
}
}
}
}
}
}
Aggregations