Search in sources :

Example 1 with ForeignKeyElementPropertiesEditionPart

use of org.obeonetwork.dsl.database.parts.ForeignKeyElementPropertiesEditionPart in project InformationSystem by ObeoNetwork.

the class ForeignKeyElementPropertiesEditionComponent 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)
 * @generated NOT
 */
public void initPart(Object key, int kind, EObject elt, ResourceSet allResource) {
    setInitializing(true);
    if (editingPart != null && key == partKey) {
        editingPart.setContext(elt, allResource);
        final ForeignKeyElement foreignKeyElement = (ForeignKeyElement) elt;
        final ForeignKeyElementPropertiesEditionPart foreignKeyElementPart = (ForeignKeyElementPropertiesEditionPart) editingPart;
        // init values
        if (foreignKeyElement.getComments() != null && isAccessible(DatabaseViewsRepository.ForeignKeyElement.Properties.comments))
            foreignKeyElementPart.setComments(EcoreUtil.convertToString(EcorePackage.Literals.ESTRING, foreignKeyElement.getComments()));
        if (isAccessible(DatabaseViewsRepository.ForeignKeyElement.Properties.fKColumn)) {
            // init part
            fkColumnSettings = new EObjectFlatComboSettings(foreignKeyElement, DatabasePackage.eINSTANCE.getForeignKeyElement_FkColumn());
            foreignKeyElementPart.initFKColumn(fkColumnSettings);
            // set the button mode
            foreignKeyElementPart.setFKColumnButtonMode(ButtonsModeEnum.BROWSE);
        }
        if (isAccessible(DatabaseViewsRepository.ForeignKeyElement.Properties.pKColumn)) {
            // init part
            pkColumnSettings = new EObjectFlatComboSettings(foreignKeyElement, DatabasePackage.eINSTANCE.getForeignKeyElement_PkColumn());
            foreignKeyElementPart.initPKColumn(pkColumnSettings);
            // set the button mode
            foreignKeyElementPart.setPKColumnButtonMode(ButtonsModeEnum.BROWSE);
        }
        // Custom code to prevent NPE when creating new FKElement
        ForeignKeyElement fkElt = (ForeignKeyElement) semanticObject;
        if (fkElt.getFkColumn() != null) {
            if (sourceTableSettings.getValue() != null && isAccessible(DatabaseViewsRepository.ForeignKeyElement.Properties.sourceTable))
                foreignKeyElementPart.setSourceTable(EEFConverterUtil.convertToString(EcorePackage.Literals.ESTRING, sourceTableSettings.getValue()));
        } else {
            EObject container = fkElt.eContainer();
            if (container instanceof ForeignKey) {
                Table table = ((ForeignKey) container).getSourceTable();
                if (table != null) {
                    foreignKeyElementPart.setSourceTable(table.getName());
                }
            }
        }
        if (fkElt.getPkColumn() != null) {
            if (targetTableSettings.getValue() != null && isAccessible(DatabaseViewsRepository.ForeignKeyElement.Properties.targetTable))
                foreignKeyElementPart.setTargetTable(EEFConverterUtil.convertToString(EcorePackage.Literals.ESTRING, targetTableSettings.getValue()));
        } else {
            EObject container = fkElt.eContainer();
            if (container instanceof ForeignKey) {
                Table table = ((ForeignKey) container).getTargetTable();
                if (table != null) {
                    foreignKeyElementPart.setTargetTable(table.getName());
                }
            }
        }
        if (isAccessible(DatabaseViewsRepository.ForeignKeyElement.Properties.fKColumn)) {
            foreignKeyElementPart.addFilterToFKColumn(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 Column);
                }
            });
        // Start of user code for additional businessfilters for fkColumn
        // End of user code
        }
        if (isAccessible(DatabaseViewsRepository.ForeignKeyElement.Properties.pKColumn)) {
            foreignKeyElementPart.addFilterToPKColumn(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 Column);
                }
            });
        // Start of user code for additional businessfilters for pkColumn
        // End of user code
        }
    // init values for referenced views
    // init filters for referenced views
    }
    setInitializing(false);
}
Also used : ForeignKeyElement(org.obeonetwork.dsl.database.ForeignKeyElement) Table(org.obeonetwork.dsl.database.Table) ViewerFilter(org.eclipse.jface.viewers.ViewerFilter) Column(org.obeonetwork.dsl.database.Column) EObject(org.eclipse.emf.ecore.EObject) Viewer(org.eclipse.jface.viewers.Viewer) EObject(org.eclipse.emf.ecore.EObject) EObjectFlatComboSettings(org.eclipse.emf.eef.runtime.ui.widgets.eobjflatcombo.EObjectFlatComboSettings) ForeignKeyElementPropertiesEditionPart(org.obeonetwork.dsl.database.parts.ForeignKeyElementPropertiesEditionPart) ForeignKey(org.obeonetwork.dsl.database.ForeignKey)

Aggregations

EObject (org.eclipse.emf.ecore.EObject)1 EObjectFlatComboSettings (org.eclipse.emf.eef.runtime.ui.widgets.eobjflatcombo.EObjectFlatComboSettings)1 Viewer (org.eclipse.jface.viewers.Viewer)1 ViewerFilter (org.eclipse.jface.viewers.ViewerFilter)1 Column (org.obeonetwork.dsl.database.Column)1 ForeignKey (org.obeonetwork.dsl.database.ForeignKey)1 ForeignKeyElement (org.obeonetwork.dsl.database.ForeignKeyElement)1 Table (org.obeonetwork.dsl.database.Table)1 ForeignKeyElementPropertiesEditionPart (org.obeonetwork.dsl.database.parts.ForeignKeyElementPropertiesEditionPart)1