use of org.obeonetwork.dsl.database.ForeignKey in project InformationSystem by ObeoNetwork.
the class ForeignKeyPropertiesEditionComponent 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) {
ForeignKey foreignKey = (ForeignKey) semanticObject;
if (DatabaseViewsRepository.ForeignKey.Properties.name == event.getAffectedEditor()) {
foreignKey.setName((java.lang.String) EEFConverterUtil.createFromString(EcorePackage.Literals.ESTRING, (String) event.getNewValue()));
}
if (DatabaseViewsRepository.ForeignKey.Properties.target == event.getAffectedEditor()) {
if (event.getKind() == PropertiesEditionEvent.SET) {
targetSettings.setToReference((Table) event.getNewValue());
} else if (event.getKind() == PropertiesEditionEvent.ADD) {
Table eObject = DatabaseFactory.eINSTANCE.createTable();
EObjectPropertiesEditionContext context = new EObjectPropertiesEditionContext(editingContext, this, eObject, editingContext.getAdapterFactory());
PropertiesEditingProvider provider = (PropertiesEditingProvider) editingContext.getAdapterFactory().adapt(eObject, PropertiesEditingProvider.class);
if (provider != null) {
PropertiesEditingPolicy policy = provider.getPolicy(context);
if (policy != null) {
policy.execute();
}
}
targetSettings.setToReference(eObject);
}
}
if (DatabaseViewsRepository.ForeignKey.Properties.elements == event.getAffectedEditor()) {
if (event.getKind() == PropertiesEditionEvent.ADD) {
EReferencePropertiesEditionContext context = new EReferencePropertiesEditionContext(editingContext, this, elementsSettings, 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) {
elementsSettings.removeFromReference((EObject) event.getNewValue());
} else if (event.getKind() == PropertiesEditionEvent.MOVE) {
elementsSettings.move(event.getNewIndex(), (ForeignKeyElement) event.getNewValue());
}
}
if (DatabaseViewsRepository.ForeignKey.Properties.comments == event.getAffectedEditor()) {
foreignKey.setComments((java.lang.String) EEFConverterUtil.createFromString(EcorePackage.Literals.ESTRING, (String) event.getNewValue()));
}
}
use of org.obeonetwork.dsl.database.ForeignKey in project InformationSystem by ObeoNetwork.
the class ForeignKeyPropertiesEditionComponent 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 ForeignKey foreignKey = (ForeignKey) elt;
final ForeignKeyPropertiesEditionPart foreignKeyPart = (ForeignKeyPropertiesEditionPart) editingPart;
// init values
if (isAccessible(DatabaseViewsRepository.ForeignKey.Properties.name))
foreignKeyPart.setName(EEFConverterUtil.convertToString(EcorePackage.Literals.ESTRING, foreignKey.getName()));
if (isAccessible(DatabaseViewsRepository.ForeignKey.Properties.target)) {
// init part
targetSettings = new EObjectFlatComboSettings(foreignKey, DatabasePackage.eINSTANCE.getForeignKey_Target());
foreignKeyPart.initTarget(targetSettings);
// set the button mode
foreignKeyPart.setTargetButtonMode(ButtonsModeEnum.BROWSE);
}
if (isAccessible(DatabaseViewsRepository.ForeignKey.Properties.elements)) {
elementsSettings = new ReferencesTableSettings(foreignKey, DatabasePackage.eINSTANCE.getForeignKey_Elements());
foreignKeyPart.initElements(elementsSettings);
}
if (isAccessible(DatabaseViewsRepository.ForeignKey.Properties.comments))
foreignKeyPart.setComments(EcoreUtil.convertToString(EcorePackage.Literals.ESTRING, foreignKey.getComments()));
if (isAccessible(DatabaseViewsRepository.ForeignKey.Properties.target)) {
foreignKeyPart.addFilterToTarget(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 Table);
}
});
// Start of user code for additional businessfilters for target
// End of user code
}
if (isAccessible(DatabaseViewsRepository.ForeignKey.Properties.elements)) {
foreignKeyPart.addFilterToElements(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 ForeignKeyElement);
}
});
// Start of user code for additional businessfilters for elements
// End of user code
}
// init values for referenced views
// init filters for referenced views
}
setInitializing(false);
}
use of org.obeonetwork.dsl.database.ForeignKey in project InformationSystem by ObeoNetwork.
the class TableForeignKeysPropertiesEditionComponent 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 Table table = (Table) elt;
final ForeignKeysPropertiesEditionPart foreignKeysPart = (ForeignKeysPropertiesEditionPart) editingPart;
// init values
if (isAccessible(DatabaseViewsRepository.ForeignKeys.Properties.foreignKeys_)) {
foreignKeysSettings = new ReferencesTableSettings(table, DatabasePackage.eINSTANCE.getTable_ForeignKeys());
foreignKeysPart.initForeignKeys(foreignKeysSettings);
}
// init filters
if (isAccessible(DatabaseViewsRepository.ForeignKeys.Properties.foreignKeys_)) {
foreignKeysPart.addFilterToForeignKeys(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 ForeignKey);
}
});
// Start of user code for additional businessfilters for foreignKeys
// End of user code
}
// init values for referenced views
// init filters for referenced views
}
setInitializing(false);
}
use of org.obeonetwork.dsl.database.ForeignKey in project InformationSystem by ObeoNetwork.
the class DefaultDataBaseBuilder method buildForeignKeys.
protected void buildForeignKeys(Table table) {
Map foreignKeys = new HashMap();
ResultSet rs = null;
try {
rs = metaData.getImportedKeys(null, schemaName, table.getName());
while (rs.next()) {
String pkSchemaName = rs.getString(2);
String pkTableName = rs.getString(3);
String fkName = rs.getString(12);
String pkName = rs.getString(13);
String foreignKeyId = tableContainer.getName() + "::" + table.getName() + "::" + fkName;
ForeignKey foreignKey = (ForeignKey) foreignKeys.get(foreignKeyId);
if (foreignKey == null) {
foreignKey = CreationUtils.createForeignKey(table);
foreignKey.setName(fkName);
foreignKeys.put(foreignKeyId, foreignKey);
}
int keySeq = rs.getInt(9);
ForeignKeyElement foreignKeyElement = CreationUtils.createForeignKeyElement(keySeq, foreignKey);
foreignKey.getElements().add(foreignKeyElement);
String pkColumnName = rs.getString(4);
Column pkColumn = queries.getColumn(tableContainer, pkTableName, pkColumnName);
if (pkColumn != null) {
foreignKeyElement.setPkColumn(pkColumn);
} else {
AbstractTable pkTable = queries.getTable(pkTableName);
if (pkTable == null) {
pkTable = CreationUtils.createTable(tableContainer, pkTableName);
pkColumn = CreationUtils.createColumn(pkTable, pkColumnName);
} else {
pkColumn = queries.getColumn(pkTable, pkColumnName);
}
foreignKeyElement.setPkColumn(pkColumn);
}
String fkSchemaName = rs.getString(6);
String fkTableName = rs.getString(7);
String fkColumnName = rs.getString(8);
Column fkColumn = queries.getColumn(tableContainer, fkTableName, fkColumnName);
foreignKeyElement.setFkColumn(fkColumn);
// Set target table
if (foreignKey.getTarget() == null) {
Table targetTable = (Table) pkColumn.getOwner();
foreignKey.setTarget(targetTable);
}
}
} catch (Exception ex) {
ex.printStackTrace();
} finally {
JdbcUtils.closeResultSet(rs);
}
}
use of org.obeonetwork.dsl.database.ForeignKey in project InformationSystem by ObeoNetwork.
the class UpdateForeignKeyImpl method setNewForeignKey.
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public void setNewForeignKey(ForeignKey newNewForeignKey) {
ForeignKey oldNewForeignKey = newForeignKey;
newForeignKey = newNewForeignKey;
if (eNotificationRequired())
eNotify(new ENotificationImpl(this, Notification.SET, DbevolutionPackage.UPDATE_FOREIGN_KEY__NEW_FOREIGN_KEY, oldNewForeignKey, newForeignKey));
}
Aggregations