Skip to content

Commit

Permalink
[480] Add support for abstract entities
Browse files Browse the repository at this point in the history
This is useful to avoid proposing irrelevant element creation operations.

#480
Signed-off-by: Pierre-Charles David <pierre-charles.david@obeo.fr>
  • Loading branch information
pcdavid committed May 7, 2021
1 parent cc3138d commit d85e512
Show file tree
Hide file tree
Showing 10 changed files with 199 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.emf.edit.provider.ComposeableAdapterFactory;
import org.eclipse.emf.edit.provider.IItemPropertyDescriptor;
import org.eclipse.emf.edit.provider.ItemPropertyDescriptor;
import org.eclipse.emf.edit.provider.ViewerNotification;
import org.eclipse.sirius.web.domain.DomainFactory;
import org.eclipse.sirius.web.domain.DomainPackage;
Expand Down Expand Up @@ -52,6 +53,7 @@ public List<IItemPropertyDescriptor> getPropertyDescriptors(Object object) {
super.getPropertyDescriptors(object);

this.addSuperTypePropertyDescriptor(object);
this.addAbstractPropertyDescriptor(object);
}
return this.itemPropertyDescriptors;
}
Expand All @@ -68,6 +70,18 @@ protected void addSuperTypePropertyDescriptor(Object object) {
DomainPackage.Literals.ENTITY__SUPER_TYPE, true, false, true, null, null, null));
}

/**
* This adds a property descriptor for the Abstract feature. <!-- begin-user-doc --> <!-- end-user-doc -->
*
* @generated
*/
protected void addAbstractPropertyDescriptor(Object object) {
this.itemPropertyDescriptors.add(
this.createItemPropertyDescriptor(((ComposeableAdapterFactory) this.adapterFactory).getRootAdapterFactory(), this.getResourceLocator(), this.getString("_UI_Entity_abstract_feature"), //$NON-NLS-1$
this.getString("_UI_PropertyDescriptor_description", "_UI_Entity_abstract_feature", "_UI_Entity_type"), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
DomainPackage.Literals.ENTITY__ABSTRACT, true, false, false, ItemPropertyDescriptor.BOOLEAN_VALUE_IMAGE, null, null));
}

/**
* This specifies how to implement {@link #getChildren} and is used to deduce an appropriate feature for an
* {@link org.eclipse.emf.edit.command.AddCommand}, {@link org.eclipse.emf.edit.command.RemoveCommand} or
Expand Down Expand Up @@ -143,6 +157,9 @@ public void notifyChanged(Notification notification) {
this.updateChildren(notification);

switch (notification.getFeatureID(Entity.class)) {
case DomainPackage.ENTITY__ABSTRACT:
this.fireNotifyChanged(new ViewerNotification(notification, notification.getNotifier(), false, true));
return;
case DomainPackage.ENTITY__ATTRIBUTES:
case DomainPackage.ENTITY__RELATIONS:
this.fireNotifyChanged(new ViewerNotification(notification, notification.getNotifier(), true, false));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ _UI_Domain_types_feature = Types
_UI_Entity_attributes_feature = Attributes
_UI_Entity_relations_feature = Relations
_UI_Entity_superType_feature = Super Type
_UI_Entity_abstract_feature = Abstract
_UI_Feature_optional_feature = Optional
_UI_Feature_many_feature = Many
_UI_Attribute_type_feature = Type
Expand Down
42 changes: 42 additions & 0 deletions backend/sirius-web-domain/plugin.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.0"?>

<!--
Copyright (c) 2021 Obeo.
This program and the accompanying materials
are made available under the terms of the Eclipse Public License v2.0
which accompanies this distribution, and is available at
https://www.eclipse.org/legal/epl-2.0/
SPDX-License-Identifier: EPL-2.0
Contributors:
Obeo - initial API and implementation
-->

<plugin
name="%pluginName"
id="sirius-web-domain"
version="1.0.0"
provider-name="%providerName">

<requires>
<import plugin="org.eclipse.core.runtime"/>
<import plugin="org.eclipse.emf.ecore" export="true"/>
</requires>

<runtime>
<library name=".">
<export name="*"/>
</library>
</runtime>

<extension point="org.eclipse.emf.ecore.generated_package">
<!-- @generated domain -->
<package
uri="http://www.eclipse.org/sirius-web/domain"
class="org.eclipse.sirius.web.domain.DomainPackage"
genModel="src/main/resources/model/domain.genmodel"/>
</extension>

</plugin>
Original file line number Diff line number Diff line change
Expand Up @@ -192,13 +192,21 @@ public interface DomainPackage extends EPackage {
*/
int ENTITY__SUPER_TYPE = NAMED_ELEMENT_FEATURE_COUNT + 2;

/**
* The feature id for the '<em><b>Abstract</b></em>' attribute. <!-- begin-user-doc --> <!-- end-user-doc -->
*
* @generated
* @ordered
*/
int ENTITY__ABSTRACT = NAMED_ELEMENT_FEATURE_COUNT + 3;

/**
* The number of structural features of the '<em>Entity</em>' class. <!-- begin-user-doc --> <!-- end-user-doc -->
*
* @generated
* @ordered
*/
int ENTITY_FEATURE_COUNT = NAMED_ELEMENT_FEATURE_COUNT + 3;
int ENTITY_FEATURE_COUNT = NAMED_ELEMENT_FEATURE_COUNT + 4;

/**
* The number of operations of the '<em>Entity</em>' class. <!-- begin-user-doc --> <!-- end-user-doc -->
Expand Down Expand Up @@ -491,6 +499,17 @@ public interface DomainPackage extends EPackage {
*/
EReference getEntity_SuperType();

/**
* Returns the meta object for the attribute '{@link org.eclipse.sirius.web.domain.Entity#isAbstract
* <em>Abstract</em>}'. <!-- begin-user-doc --> <!-- end-user-doc -->
*
* @return the meta object for the attribute '<em>Abstract</em>'.
* @see org.eclipse.sirius.web.domain.Entity#isAbstract()
* @see #getEntity()
* @generated
*/
EAttribute getEntity_Abstract();

/**
* Returns the meta object for class '{@link org.eclipse.sirius.web.domain.Feature <em>Feature</em>}'. <!--
* begin-user-doc --> <!-- end-user-doc -->
Expand Down Expand Up @@ -686,6 +705,14 @@ interface Literals {
*/
EReference ENTITY__SUPER_TYPE = eINSTANCE.getEntity_SuperType();

/**
* The meta object literal for the '<em><b>Abstract</b></em>' attribute feature. <!-- begin-user-doc --> <!--
* end-user-doc -->
*
* @generated
*/
EAttribute ENTITY__ABSTRACT = eINSTANCE.getEntity_Abstract();

/**
* The meta object literal for the '{@link org.eclipse.sirius.web.domain.impl.FeatureImpl <em>Feature</em>}'
* class. <!-- begin-user-doc --> <!-- end-user-doc -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
* <li>{@link org.eclipse.sirius.web.domain.Entity#getAttributes <em>Attributes</em>}</li>
* <li>{@link org.eclipse.sirius.web.domain.Entity#getRelations <em>Relations</em>}</li>
* <li>{@link org.eclipse.sirius.web.domain.Entity#getSuperType <em>Super Type</em>}</li>
* <li>{@link org.eclipse.sirius.web.domain.Entity#isAbstract <em>Abstract</em>}</li>
* </ul>
*
* @see org.eclipse.sirius.web.domain.DomainPackage#getEntity()
Expand Down Expand Up @@ -75,4 +76,26 @@ public interface Entity extends NamedElement {
*/
void setSuperType(Entity value);

/**
* Returns the value of the '<em><b>Abstract</b></em>' attribute. <!-- begin-user-doc --> <!-- end-user-doc -->
*
* @return the value of the '<em>Abstract</em>' attribute.
* @see #setAbstract(boolean)
* @see org.eclipse.sirius.web.domain.DomainPackage#getEntity_Abstract()
* @model required="true"
* @generated
*/
boolean isAbstract();

/**
* Sets the value of the '{@link org.eclipse.sirius.web.domain.Entity#isAbstract <em>Abstract</em>}' attribute. <!--
* begin-user-doc --> <!-- end-user-doc -->
*
* @param value
* the new value of the '<em>Abstract</em>' attribute.
* @see #isAbstract()
* @generated
*/
void setAbstract(boolean value);

} // Entity
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,16 @@ public EReference getEntity_SuperType() {
return (EReference) this.entityEClass.getEStructuralFeatures().get(2);
}

/**
* <!-- begin-user-doc --> <!-- end-user-doc -->
*
* @generated
*/
@Override
public EAttribute getEntity_Abstract() {
return (EAttribute) this.entityEClass.getEStructuralFeatures().get(3);
}

/**
* <!-- begin-user-doc --> <!-- end-user-doc -->
*
Expand Down Expand Up @@ -364,6 +374,7 @@ public void createPackageContents() {
this.createEReference(this.entityEClass, ENTITY__ATTRIBUTES);
this.createEReference(this.entityEClass, ENTITY__RELATIONS);
this.createEReference(this.entityEClass, ENTITY__SUPER_TYPE);
this.createEAttribute(this.entityEClass, ENTITY__ABSTRACT);

this.featureEClass = this.createEClass(FEATURE);
this.createEAttribute(this.featureEClass, FEATURE__OPTIONAL);
Expand Down Expand Up @@ -432,6 +443,8 @@ public void initializePackageContents() {
!IS_UNSETTABLE, IS_UNIQUE, !IS_DERIVED, IS_ORDERED);
this.initEReference(this.getEntity_SuperType(), this.getEntity(), null, "superType", null, 0, 1, Entity.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_COMPOSITE, IS_RESOLVE_PROXIES, //$NON-NLS-1$
!IS_UNSETTABLE, IS_UNIQUE, !IS_DERIVED, IS_ORDERED);
this.initEAttribute(this.getEntity_Abstract(), this.ecorePackage.getEBoolean(), "abstract", null, 1, 1, Entity.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_UNSETTABLE, !IS_ID, //$NON-NLS-1$
IS_UNIQUE, !IS_DERIVED, IS_ORDERED);

this.initEClass(this.featureEClass, Feature.class, "Feature", !IS_ABSTRACT, !IS_INTERFACE, IS_GENERATED_INSTANCE_CLASS); //$NON-NLS-1$
this.initEAttribute(this.getFeature_Optional(), this.ecorePackage.getEBoolean(), "optional", "false", 1, 1, Feature.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_UNSETTABLE, !IS_ID, //$NON-NLS-1$//$NON-NLS-2$
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
* <li>{@link org.eclipse.sirius.web.domain.impl.EntityImpl#getAttributes <em>Attributes</em>}</li>
* <li>{@link org.eclipse.sirius.web.domain.impl.EntityImpl#getRelations <em>Relations</em>}</li>
* <li>{@link org.eclipse.sirius.web.domain.impl.EntityImpl#getSuperType <em>Super Type</em>}</li>
* <li>{@link org.eclipse.sirius.web.domain.impl.EntityImpl#isAbstract <em>Abstract</em>}</li>
* </ul>
*
* @generated
Expand Down Expand Up @@ -71,6 +72,26 @@ public class EntityImpl extends NamedElementImpl implements Entity {
*/
protected Entity superType;

/**
* The default value of the '{@link #isAbstract() <em>Abstract</em>}' attribute. <!-- begin-user-doc --> <!--
* end-user-doc -->
*
* @see #isAbstract()
* @generated
* @ordered
*/
protected static final boolean ABSTRACT_EDEFAULT = false;

/**
* The cached value of the '{@link #isAbstract() <em>Abstract</em>}' attribute. <!-- begin-user-doc --> <!--
* end-user-doc -->
*
* @see #isAbstract()
* @generated
* @ordered
*/
protected boolean abstract_ = ABSTRACT_EDEFAULT;

/**
* <!-- begin-user-doc --> <!-- end-user-doc -->
*
Expand Down Expand Up @@ -156,6 +177,29 @@ public void setSuperType(Entity newSuperType) {
this.eNotify(new ENotificationImpl(this, Notification.SET, DomainPackage.ENTITY__SUPER_TYPE, oldSuperType, this.superType));
}

/**
* <!-- begin-user-doc --> <!-- end-user-doc -->
*
* @generated
*/
@Override
public boolean isAbstract() {
return this.abstract_;
}

/**
* <!-- begin-user-doc --> <!-- end-user-doc -->
*
* @generated
*/
@Override
public void setAbstract(boolean newAbstract) {
boolean oldAbstract = this.abstract_;
this.abstract_ = newAbstract;
if (this.eNotificationRequired())
this.eNotify(new ENotificationImpl(this, Notification.SET, DomainPackage.ENTITY__ABSTRACT, oldAbstract, this.abstract_));
}

/**
* <!-- begin-user-doc --> <!-- end-user-doc -->
*
Expand Down Expand Up @@ -188,6 +232,8 @@ public Object eGet(int featureID, boolean resolve, boolean coreType) {
if (resolve)
return this.getSuperType();
return this.basicGetSuperType();
case DomainPackage.ENTITY__ABSTRACT:
return this.isAbstract();
}
return super.eGet(featureID, resolve, coreType);
}
Expand All @@ -212,6 +258,9 @@ public void eSet(int featureID, Object newValue) {
case DomainPackage.ENTITY__SUPER_TYPE:
this.setSuperType((Entity) newValue);
return;
case DomainPackage.ENTITY__ABSTRACT:
this.setAbstract((Boolean) newValue);
return;
}
super.eSet(featureID, newValue);
}
Expand All @@ -233,6 +282,9 @@ public void eUnset(int featureID) {
case DomainPackage.ENTITY__SUPER_TYPE:
this.setSuperType((Entity) null);
return;
case DomainPackage.ENTITY__ABSTRACT:
this.setAbstract(ABSTRACT_EDEFAULT);
return;
}
super.eUnset(featureID);
}
Expand All @@ -251,8 +303,27 @@ public boolean eIsSet(int featureID) {
return this.relations != null && !this.relations.isEmpty();
case DomainPackage.ENTITY__SUPER_TYPE:
return this.superType != null;
case DomainPackage.ENTITY__ABSTRACT:
return this.abstract_ != ABSTRACT_EDEFAULT;
}
return super.eIsSet(featureID);
}

/**
* <!-- begin-user-doc --> <!-- end-user-doc -->
*
* @generated
*/
@Override
public String toString() {
if (this.eIsProxy())
return super.toString();

StringBuilder result = new StringBuilder(super.toString());
result.append(" (abstract: "); //$NON-NLS-1$
result.append(this.abstract_);
result.append(')');
return result.toString();
}

} // EntityImpl
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
<eStructuralFeatures xsi:type="ecore:EReference" name="relations" upperBound="-1"
eType="#//Relation" containment="true"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="superType" eType="#//Entity"/>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="abstract" lowerBound="1"
eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EBoolean"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="Feature" eSuperTypes="#//NamedElement">
<eStructuralFeatures xsi:type="ecore:EAttribute" name="optional" lowerBound="1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
<genFeatures property="None" children="true" createChild="true" ecoreFeature="ecore:EReference domain.ecore#//Entity/attributes"/>
<genFeatures property="None" children="true" createChild="true" ecoreFeature="ecore:EReference domain.ecore#//Entity/relations"/>
<genFeatures notify="false" createChild="false" propertySortChoices="true" ecoreFeature="ecore:EReference domain.ecore#//Entity/superType"/>
<genFeatures createChild="false" ecoreFeature="ecore:EAttribute domain.ecore#//Entity/abstract"/>
</genClasses>
<genClasses ecoreClass="domain.ecore#//Feature">
<genFeatures createChild="false" ecoreFeature="ecore:EAttribute domain.ecore#//Feature/optional"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ public Optional<EPackage> convert(Domain domain) {
private EClass convert(Entity entity, Map<Entity, EClass> convertedTypes) {
EClass eClass = EcoreFactory.eINSTANCE.createEClass();
eClass.setName(entity.getName());
eClass.setAbstract(entity.isAbstract());
entity.getAttributes().forEach(attribute -> eClass.getEStructuralFeatures().add(this.convert(attribute)));
if (entity.getSuperType() != null && convertedTypes.containsKey(entity.getSuperType())) {
eClass.getESuperTypes().add(convertedTypes.get(entity.getSuperType()));
Expand Down

0 comments on commit d85e512

Please sign in to comment.