Search in sources :

Example 11 with IndexElement

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

the class IndexElementItemProvider 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) {
    IndexElement indexElement = (IndexElement) object;
    String label = "";
    if (indexElement.getColumn() != null) {
        label += indexElement.getColumn().getName();
    }
    label += " ";
    if (indexElement.isAsc() == true) {
        label += getString("_UI_IndexElement_ASC");
    } else {
        label += getString("_UI_IndexElement_DESC");
    }
    return label == null || label.length() == 0 ? getString("_UI_IndexElement_type") : label;
}
Also used : IndexElement(org.obeonetwork.dsl.database.IndexElement)

Example 12 with IndexElement

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

the class ColumnSpec method addToUniqueIndex.

@Override
public void addToUniqueIndex() {
    if (isUnique() == false && getOwner() != null && getOwner() instanceof Table) {
        Table table = (Table) getOwner();
        // Check if there is a unique index defined on the table
        Index uniqueIndex = null;
        for (Index index : table.getIndexes()) {
            if (index.isUnique()) {
                uniqueIndex = index;
                break;
            }
        }
        if (uniqueIndex == null) {
            // Create a new unique index
            uniqueIndex = DatabaseFactory.eINSTANCE.createIndex();
            uniqueIndex.setName(table.getName() + "_UNIQUE_INDEX");
            uniqueIndex.setUnique(true);
            table.getIndexes().add(uniqueIndex);
        }
        // We are sure we have a unique index here
        IndexElement indexElt = DatabaseFactory.eINSTANCE.createIndexElement();
        uniqueIndex.getElements().add(indexElt);
        indexElt.setAsc(true);
        indexElt.setColumn(this);
    }
}
Also used : Table(org.obeonetwork.dsl.database.Table) Index(org.obeonetwork.dsl.database.Index) IndexElement(org.obeonetwork.dsl.database.IndexElement)

Example 13 with IndexElement

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

the class IndexPropertiesEditionComponent 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) {
    Index index = (Index) semanticObject;
    if (DatabaseViewsRepository.Index.Properties.name == event.getAffectedEditor()) {
        index.setName((java.lang.String) EEFConverterUtil.createFromString(EcorePackage.Literals.ESTRING, (String) event.getNewValue()));
    }
    if (DatabaseViewsRepository.Index.Properties.qualifier == event.getAffectedEditor()) {
        index.setQualifier((java.lang.String) EEFConverterUtil.createFromString(EcorePackage.Literals.ESTRING, (String) event.getNewValue()));
    }
    if (DatabaseViewsRepository.Index.Properties.unique == event.getAffectedEditor()) {
        index.setUnique((Boolean) event.getNewValue());
    }
    if (DatabaseViewsRepository.Index.Properties.cardinality == event.getAffectedEditor()) {
        index.setCardinality((EEFConverterUtil.createIntFromString(EcorePackage.Literals.EINT, (String) event.getNewValue())));
    }
    if (DatabaseViewsRepository.Index.Properties.indexType == event.getAffectedEditor()) {
        index.setIndexType((java.lang.String) EEFConverterUtil.createFromString(EcorePackage.Literals.ESTRING, (String) event.getNewValue()));
    }
    if (DatabaseViewsRepository.Index.Properties.comments == event.getAffectedEditor()) {
        index.setComments((java.lang.String) EEFConverterUtil.createFromString(EcorePackage.Literals.ESTRING, (String) event.getNewValue()));
    }
    if (DatabaseViewsRepository.Index.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(), (IndexElement) event.getNewValue());
        }
    }
}
Also used : EObjectPropertiesEditionContext(org.eclipse.emf.eef.runtime.context.impl.EObjectPropertiesEditionContext) PropertiesEditingProvider(org.eclipse.emf.eef.runtime.providers.PropertiesEditingProvider) EObject(org.eclipse.emf.ecore.EObject) Index(org.obeonetwork.dsl.database.Index) PropertiesEditingPolicy(org.eclipse.emf.eef.runtime.policies.PropertiesEditingPolicy) CreateEditingPolicy(org.eclipse.emf.eef.runtime.policies.impl.CreateEditingPolicy) EReferencePropertiesEditionContext(org.eclipse.emf.eef.runtime.context.impl.EReferencePropertiesEditionContext) IndexElement(org.obeonetwork.dsl.database.IndexElement)

Example 14 with IndexElement

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

the class CreationUtils method createIndexElement.

public static IndexElement createIndexElement(Index index) {
    IndexElement indexElement = DatabaseFactory.eINSTANCE.createIndexElement();
    index.getElements().add(indexElement);
    return indexElement;
}
Also used : IndexElement(org.obeonetwork.dsl.database.IndexElement)

Aggregations

IndexElement (org.obeonetwork.dsl.database.IndexElement)14 Index (org.obeonetwork.dsl.database.Index)7 Column (org.obeonetwork.dsl.database.Column)4 EObject (org.eclipse.emf.ecore.EObject)3 Constraint (org.obeonetwork.dsl.database.Constraint)3 ForeignKey (org.obeonetwork.dsl.database.ForeignKey)3 Table (org.obeonetwork.dsl.database.Table)3 ArrayList (java.util.ArrayList)2 Viewer (org.eclipse.jface.viewers.Viewer)2 ViewerFilter (org.eclipse.jface.viewers.ViewerFilter)2 Attribute (org.obeonetwork.dsl.environment.Attribute)2 Reference (org.obeonetwork.dsl.environment.Reference)2 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 IStatus (org.eclipse.core.runtime.IStatus)1 Status (org.eclipse.core.runtime.Status)1 EReference (org.eclipse.emf.ecore.EReference)1 EObjectPropertiesEditionContext (org.eclipse.emf.eef.runtime.context.impl.EObjectPropertiesEditionContext)1