Search in sources :

Example 21 with ForeignKey

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()));
    }
}
Also used : ForeignKeyElement(org.obeonetwork.dsl.database.ForeignKeyElement) EObjectPropertiesEditionContext(org.eclipse.emf.eef.runtime.context.impl.EObjectPropertiesEditionContext) Table(org.obeonetwork.dsl.database.Table) PropertiesEditingProvider(org.eclipse.emf.eef.runtime.providers.PropertiesEditingProvider) EObject(org.eclipse.emf.ecore.EObject) PropertiesEditingPolicy(org.eclipse.emf.eef.runtime.policies.PropertiesEditingPolicy) CreateEditingPolicy(org.eclipse.emf.eef.runtime.policies.impl.CreateEditingPolicy) ForeignKey(org.obeonetwork.dsl.database.ForeignKey) EReferencePropertiesEditionContext(org.eclipse.emf.eef.runtime.context.impl.EReferencePropertiesEditionContext)

Example 22 with ForeignKey

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);
}
Also used : ForeignKeyElement(org.obeonetwork.dsl.database.ForeignKeyElement) ReferencesTableSettings(org.eclipse.emf.eef.runtime.ui.widgets.referencestable.ReferencesTableSettings) Table(org.obeonetwork.dsl.database.Table) ViewerFilter(org.eclipse.jface.viewers.ViewerFilter) ForeignKeyPropertiesEditionPart(org.obeonetwork.dsl.database.parts.ForeignKeyPropertiesEditionPart) Viewer(org.eclipse.jface.viewers.Viewer) EObject(org.eclipse.emf.ecore.EObject) EObjectFlatComboSettings(org.eclipse.emf.eef.runtime.ui.widgets.eobjflatcombo.EObjectFlatComboSettings) ForeignKey(org.obeonetwork.dsl.database.ForeignKey)

Example 23 with ForeignKey

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);
}
Also used : Table(org.obeonetwork.dsl.database.Table) ForeignKeysPropertiesEditionPart(org.obeonetwork.dsl.database.parts.ForeignKeysPropertiesEditionPart) ReferencesTableSettings(org.eclipse.emf.eef.runtime.ui.widgets.referencestable.ReferencesTableSettings) ViewerFilter(org.eclipse.jface.viewers.ViewerFilter) Viewer(org.eclipse.jface.viewers.Viewer) EObject(org.eclipse.emf.ecore.EObject) ForeignKey(org.obeonetwork.dsl.database.ForeignKey)

Example 24 with ForeignKey

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);
    }
}
Also used : ForeignKeyElement(org.obeonetwork.dsl.database.ForeignKeyElement) AbstractTable(org.obeonetwork.dsl.database.AbstractTable) Table(org.obeonetwork.dsl.database.Table) AbstractTable(org.obeonetwork.dsl.database.AbstractTable) HashMap(java.util.HashMap) Column(org.obeonetwork.dsl.database.Column) ResultSet(java.sql.ResultSet) ForeignKey(org.obeonetwork.dsl.database.ForeignKey) HashMap(java.util.HashMap) Map(java.util.Map) SQLException(java.sql.SQLException)

Example 25 with ForeignKey

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));
}
Also used : ENotificationImpl(org.eclipse.emf.ecore.impl.ENotificationImpl) UpdateForeignKey(org.obeonetwork.dsl.database.dbevolution.UpdateForeignKey) ForeignKey(org.obeonetwork.dsl.database.ForeignKey)

Aggregations

ForeignKey (org.obeonetwork.dsl.database.ForeignKey)27 Table (org.obeonetwork.dsl.database.Table)16 EObject (org.eclipse.emf.ecore.EObject)8 AbstractTable (org.obeonetwork.dsl.database.AbstractTable)8 ForeignKeyElement (org.obeonetwork.dsl.database.ForeignKeyElement)8 Column (org.obeonetwork.dsl.database.Column)7 ArrayList (java.util.ArrayList)6 Reference (org.obeonetwork.dsl.environment.Reference)4 HashMap (java.util.HashMap)3 IStatus (org.eclipse.core.runtime.IStatus)3 Status (org.eclipse.core.runtime.Status)3 Viewer (org.eclipse.jface.viewers.Viewer)3 ViewerFilter (org.eclipse.jface.viewers.ViewerFilter)3 Constraint (org.obeonetwork.dsl.database.Constraint)3 Index (org.obeonetwork.dsl.database.Index)3 IndexElement (org.obeonetwork.dsl.database.IndexElement)3 Entity (org.obeonetwork.dsl.entity.Entity)3 Attribute (org.obeonetwork.dsl.environment.Attribute)3 HashSet (java.util.HashSet)2 LinkedHashMap (java.util.LinkedHashMap)2