use of org.obeonetwork.dsl.database.PrimaryKey in project InformationSystem by ObeoNetwork.
the class PrimaryKeyPropertiesEditionComponent 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 PrimaryKey primaryKey = (PrimaryKey) elt;
final PrimaryKeyPropertiesEditionPart primaryKeyPart = (PrimaryKeyPropertiesEditionPart) editingPart;
// init values
if (isAccessible(DatabaseViewsRepository.PrimaryKey.Properties.name))
primaryKeyPart.setName(EEFConverterUtil.convertToString(EcorePackage.Literals.ESTRING, primaryKey.getName()));
if (isAccessible(DatabaseViewsRepository.PrimaryKey.Properties.columns)) {
columnsSettings = new ReferencesTableSettings(primaryKey, DatabasePackage.eINSTANCE.getPrimaryKey_Columns());
primaryKeyPart.initColumns(columnsSettings);
}
if (isAccessible(DatabaseViewsRepository.PrimaryKey.Properties.comments))
primaryKeyPart.setComments(EcoreUtil.convertToString(EcorePackage.Literals.ESTRING, primaryKey.getComments()));
if (isAccessible(DatabaseViewsRepository.PrimaryKey.Properties.columns)) {
primaryKeyPart.addFilterToColumns(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) {
if (element instanceof EObject)
return (!primaryKeyPart.isContainedInColumnsTable((EObject) element));
return element instanceof String && element.equals("");
}
});
primaryKeyPart.addFilterToColumns(new EObjectStrictFilter(DatabasePackage.Literals.COLUMN));
// Start of user code for additional businessfilters for columns
// End of user code
}
// init values for referenced views
// init filters for referenced views
}
setInitializing(false);
}
use of org.obeonetwork.dsl.database.PrimaryKey in project InformationSystem by ObeoNetwork.
the class EntityToMLD method createTable.
private void createTable(Entity entity) {
// Retrieve the existing table
Table table = getFromInputTraceabilityMap(entity, DatabasePackage.Literals.TABLE);
Namespace namespace = EntityUtils.getContainingNamespace(entity);
if (table == null) {
// The table does not already exist we have to create a new one
table = DatabaseFactory.eINSTANCE.createTable();
TableContainer targetTableContainer = getTargetTableContainer(namespace);
targetTableContainer.getTables().add(table);
} else {
// We have to ensure the schema name is correct
String realSchemaName = getSchemaNameFromNamespace(namespace);
TableContainer tableContainer = table.getOwner();
if (!realSchemaName.equals(tableContainer.getName())) {
tableContainer.setName(realSchemaName);
}
}
// Add to traceability map
addToOutputTraceability(entity, table);
// The following properties are modified even if they already existed
table.setName(LabelProvider.getTableNameFromEntity(entity));
table.setComments(entity.getDescription());
// Handle attributes
boolean hasPKAttribute = false;
Collection<Attribute> allAttributes = new ArrayList<Attribute>();
// Attributes from the entity and its supertypes
allAttributes.addAll(entity.getAttributes());
// Attributes from associated DTOs
for (StructuredType associatedType : entity.getAssociatedTypes()) {
allAttributes.addAll(associatedType.getAttributes());
}
for (Attribute attribute : allAttributes) {
createColumn(attribute, table);
if (attribute.isIsIdentifier()) {
hasPKAttribute = true;
}
}
// Create an ID column if no attribute was set as "primary key"
if (hasPKAttribute == false) {
createDefaultIdColumn(table);
}
// Update comments on PK
PrimaryKey primaryKey = table.getPrimaryKey();
if (primaryKey != null) {
primaryKey.setName(table.getName() + "_PK");
primaryKey.setComments(getPKComments(primaryKey));
}
// Create constraints
createConstraints(entity, table);
}
use of org.obeonetwork.dsl.database.PrimaryKey in project InformationSystem by ObeoNetwork.
the class UpdatePrimaryKeyItemProvider method getText.
/**
* This returns the label text for the adapted class.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated NOT
*/
@Override
public String getText(Object object) {
UpdatePrimaryKey updatePrimaryKey = (UpdatePrimaryKey) object;
PrimaryKey primaryKey = updatePrimaryKey.getPrimaryKey();
return getString("_UI_UpdatePrimaryKey_type") + " " + primaryKey.getName();
}
use of org.obeonetwork.dsl.database.PrimaryKey in project InformationSystem by ObeoNetwork.
the class AddPrimaryKeyItemProvider method getText.
/**
* This returns the label text for the adapted class.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated NOT
*/
@Override
public String getText(Object object) {
AddPrimaryKey addPrimaryKey = (AddPrimaryKey) object;
PrimaryKey primaryKey = addPrimaryKey.getPrimaryKey();
if (primaryKey != null) {
return getString("_UI_AddPrimaryKey_type") + " " + primaryKey.getName();
} else {
return getString("_UI_AddPrimaryKey_type");
}
}
use of org.obeonetwork.dsl.database.PrimaryKey in project InformationSystem by ObeoNetwork.
the class ColumnSpec method addToPrimaryKey.
@Override
public void addToPrimaryKey() {
// Do nothing if the column is already a PK column or if it does not belong to a table
if (isInPrimaryKey() == false && getOwner() != null && getOwner() instanceof Table) {
Table table = (Table) getOwner();
// First, ensure there is a Primary Key defined on this table
PrimaryKey pk = table.getPrimaryKey();
if (pk == null) {
// Create a new PK
pk = DatabaseFactory.eINSTANCE.createPrimaryKey();
pk.setName(table.getName() + "_PK");
table.setPrimaryKey(pk);
}
// Then attach the column to the primary key
pk.getColumns().add(this);
}
}
Aggregations