Skip to content

Commit

Permalink
[1439] Add FormDescription toolbar actions to the View DSL
Browse files Browse the repository at this point in the history
Bug: #1439
Signed-off-by: Pierre-Charles David <pierre-charles.david@obeo.fr>
Signed-off-by: Axel RICHARD <axel.richard@obeo.fr>
  • Loading branch information
pcdavid authored and AxelRICHARD committed Nov 8, 2022
1 parent 60a4e27 commit 05d1073
Show file tree
Hide file tree
Showing 9 changed files with 131 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ public List<IItemPropertyDescriptor> getPropertyDescriptors(Object object) {
public Collection<? extends EStructuralFeature> getChildrenFeatures(Object object) {
if (this.childrenFeatures == null) {
super.getChildrenFeatures(object);
this.childrenFeatures.add(ViewPackage.Literals.FORM_DESCRIPTION__TOOLBAR_ACTIONS);
this.childrenFeatures.add(ViewPackage.Literals.FORM_DESCRIPTION__WIDGETS);
}
return this.childrenFeatures;
Expand Down Expand Up @@ -141,6 +142,7 @@ public void notifyChanged(Notification notification) {
this.updateChildren(notification);

switch (notification.getFeatureID(FormDescription.class)) {
case ViewPackage.FORM_DESCRIPTION__TOOLBAR_ACTIONS:
case ViewPackage.FORM_DESCRIPTION__WIDGETS:
this.fireNotifyChanged(new ViewerNotification(notification, notification.getNotifier(), true, false));
return;
Expand All @@ -158,6 +160,10 @@ public void notifyChanged(Notification notification) {
protected void collectNewChildDescriptors(Collection<Object> newChildDescriptors, Object object) {
super.collectNewChildDescriptors(newChildDescriptors, object);

ButtonDescription toolbarActionDescription = ViewFactory.eINSTANCE.createButtonDescription();
toolbarActionDescription.setStyle(ViewFactory.eINSTANCE.createButtonDescriptionStyle());
newChildDescriptors.add(this.createChildParameter(ViewPackage.Literals.FORM_DESCRIPTION__TOOLBAR_ACTIONS, toolbarActionDescription));

TextfieldDescription textfieldDescription = ViewFactory.eINSTANCE.createTextfieldDescription();
textfieldDescription.setStyle(ViewFactory.eINSTANCE.createTextfieldDescriptionStyle());
newChildDescriptors.add(this.createChildParameter(ViewPackage.Literals.FORM_DESCRIPTION__WIDGETS, textfieldDescription));
Expand Down Expand Up @@ -210,4 +216,24 @@ protected void collectNewChildDescriptors(Collection<Object> newChildDescriptors
newChildDescriptors.add(this.createChildParameter(ViewPackage.Literals.FORM_DESCRIPTION__WIDGETS, flexboxContainerDescription));
}

/**
* This returns the label text for {@link org.eclipse.emf.edit.command.CreateChildCommand}. <!-- begin-user-doc -->
* <!-- end-user-doc -->
*
* @generated
*/
@Override
public String getCreateChildText(Object owner, Object feature, Object child, Collection<?> selection) {
Object childFeature = feature;
Object childObject = child;

boolean qualify = childFeature == ViewPackage.Literals.FORM_DESCRIPTION__TOOLBAR_ACTIONS || childFeature == ViewPackage.Literals.FORM_DESCRIPTION__WIDGETS;

if (qualify) {
return this.getString("_UI_CreateChild_text2", //$NON-NLS-1$
new Object[] { this.getTypeText(childObject), this.getFeatureText(childFeature), this.getTypeText(owner) });
}
return super.getCreateChildText(owner, feature, child, selection);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ _UI_CreateView_variableName_feature = Variable Name
_UI_DeleteView_viewExpression_feature = View Expression
_UI_Conditional_condition_feature = Condition
_UI_ConditionalNodeStyle_style_feature = Style
_UI_FormDescription_toolbarActions_feature = Toolbar Actions
_UI_FormDescription_widgets_feature = Widgets
_UI_WidgetDescription_name_feature = Name
_UI_WidgetDescription_labelExpression_feature = Label Expression
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.eclipse.sirius.components.core.api.IEditService;
import org.eclipse.sirius.components.core.api.IObjectService;
import org.eclipse.sirius.components.forms.description.AbstractControlDescription;
import org.eclipse.sirius.components.forms.description.ButtonDescription;
import org.eclipse.sirius.components.forms.description.FormDescription;
import org.eclipse.sirius.components.forms.description.GroupDescription;
import org.eclipse.sirius.components.forms.description.PageDescription;
Expand Down Expand Up @@ -72,6 +73,12 @@ public IRepresentationDescription convert(RepresentationDescription representati
.map(dispatcher::doSwitch)
.collect(Collectors.toList());

List<ButtonDescription> toolbarActionDescriptions = viewFormDescription.getToolbarActions().stream()
.map(dispatcher::doSwitch)
.filter(ButtonDescription.class::isInstance)
.map(ButtonDescription.class::cast)
.collect(Collectors.toList());

Function<VariableManager, List<?>> semanticElementsProvider = variableManager -> variableManager.get(VariableManager.SELF, Object.class).stream().collect(Collectors.toList());

String descriptionId = this.getDescriptionId(viewFormDescription);
Expand All @@ -80,6 +87,7 @@ public IRepresentationDescription convert(RepresentationDescription representati
.labelProvider(variableManager -> this.computeFormLabel(viewFormDescription, variableManager, interpreter))
.semanticElementsProvider(semanticElementsProvider)
.controlDescriptions(controlDescriptions)
.toolbarActionDescriptions(toolbarActionDescriptions)
.build();
PageDescription pageDescription = PageDescription.newPageDescription(descriptionId + "_page") //$NON-NLS-1$
.idProvider(new GetOrCreateRandomIdProvider())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,17 @@
* @generated
*/
public interface FormDescription extends RepresentationDescription {
/**
* Returns the value of the '<em><b>Toolbar Actions</b></em>' containment reference list. The list contents are of
* type {@link org.eclipse.sirius.components.view.ButtonDescription}. <!-- begin-user-doc --> <!-- end-user-doc -->
*
* @return the value of the '<em>Toolbar Actions</em>' containment reference list.
* @see org.eclipse.sirius.components.view.ViewPackage#getFormDescription_ToolbarActions()
* @model containment="true"
* @generated
*/
EList<ButtonDescription> getToolbarActions();

/**
* Returns the value of the '<em><b>Widgets</b></em>' containment reference list. The list contents are of type
* {@link org.eclipse.sirius.components.view.WidgetDescription}. <!-- begin-user-doc --> <!-- end-user-doc -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2651,14 +2651,23 @@ public interface ViewPackage extends EPackage {
*/
int FORM_DESCRIPTION__TITLE_EXPRESSION = REPRESENTATION_DESCRIPTION__TITLE_EXPRESSION;

/**
* The feature id for the '<em><b>Toolbar Actions</b></em>' containment reference list. <!-- begin-user-doc --> <!--
* end-user-doc -->
*
* @generated
* @ordered
*/
int FORM_DESCRIPTION__TOOLBAR_ACTIONS = REPRESENTATION_DESCRIPTION_FEATURE_COUNT + 0;

/**
* The feature id for the '<em><b>Widgets</b></em>' containment reference list. <!-- begin-user-doc --> <!--
* end-user-doc -->
*
* @generated
* @ordered
*/
int FORM_DESCRIPTION__WIDGETS = REPRESENTATION_DESCRIPTION_FEATURE_COUNT + 0;
int FORM_DESCRIPTION__WIDGETS = REPRESENTATION_DESCRIPTION_FEATURE_COUNT + 1;

/**
* The number of structural features of the '<em>Form Description</em>' class. <!-- begin-user-doc --> <!--
Expand All @@ -2667,7 +2676,7 @@ public interface ViewPackage extends EPackage {
* @generated
* @ordered
*/
int FORM_DESCRIPTION_FEATURE_COUNT = REPRESENTATION_DESCRIPTION_FEATURE_COUNT + 1;
int FORM_DESCRIPTION_FEATURE_COUNT = REPRESENTATION_DESCRIPTION_FEATURE_COUNT + 2;

/**
* The number of operations of the '<em>Form Description</em>' class. <!-- begin-user-doc --> <!-- end-user-doc -->
Expand Down Expand Up @@ -7113,6 +7122,18 @@ public interface ViewPackage extends EPackage {
*/
EClass getFormDescription();

/**
* Returns the meta object for the containment reference list
* '{@link org.eclipse.sirius.components.view.FormDescription#getToolbarActions <em>Toolbar Actions</em>}'. <!--
* begin-user-doc --> <!-- end-user-doc -->
*
* @return the meta object for the containment reference list '<em>Toolbar Actions</em>'.
* @see org.eclipse.sirius.components.view.FormDescription#getToolbarActions()
* @see #getFormDescription()
* @generated
*/
EReference getFormDescription_ToolbarActions();

/**
* Returns the meta object for the containment reference list
* '{@link org.eclipse.sirius.components.view.FormDescription#getWidgets <em>Widgets</em>}'. <!-- begin-user-doc -->
Expand Down Expand Up @@ -9505,6 +9526,14 @@ interface Literals {
*/
EClass FORM_DESCRIPTION = eINSTANCE.getFormDescription();

/**
* The meta object literal for the '<em><b>Toolbar Actions</b></em>' containment reference list feature. <!--
* begin-user-doc --> <!-- end-user-doc -->
*
* @generated
*/
EReference FORM_DESCRIPTION__TOOLBAR_ACTIONS = eINSTANCE.getFormDescription_ToolbarActions();

/**
* The meta object literal for the '<em><b>Widgets</b></em>' containment reference list feature. <!--
* begin-user-doc --> <!-- end-user-doc -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.eclipse.emf.ecore.InternalEObject;
import org.eclipse.emf.ecore.util.EObjectContainmentEList;
import org.eclipse.emf.ecore.util.InternalEList;
import org.eclipse.sirius.components.view.ButtonDescription;
import org.eclipse.sirius.components.view.FormDescription;
import org.eclipse.sirius.components.view.ViewPackage;
import org.eclipse.sirius.components.view.WidgetDescription;
Expand All @@ -37,6 +38,16 @@
* @generated
*/
public class FormDescriptionImpl extends RepresentationDescriptionImpl implements FormDescription {
/**
* The cached value of the '{@link #getToolbarActions() <em>Toolbar Actions</em>}' containment reference list. <!--
* begin-user-doc --> <!-- end-user-doc -->
*
* @see #getToolbarActions()
* @generated
* @ordered
*/
protected EList<ButtonDescription> toolbarActions;

/**
* The cached value of the '{@link #getWidgets() <em>Widgets</em>}' containment reference list. <!-- begin-user-doc
* --> <!-- end-user-doc -->
Expand Down Expand Up @@ -66,6 +77,19 @@ protected EClass eStaticClass() {
return ViewPackage.Literals.FORM_DESCRIPTION;
}

/**
* <!-- begin-user-doc --> <!-- end-user-doc -->
*
* @generated
*/
@Override
public EList<ButtonDescription> getToolbarActions() {
if (this.toolbarActions == null) {
this.toolbarActions = new EObjectContainmentEList<>(ButtonDescription.class, this, ViewPackage.FORM_DESCRIPTION__TOOLBAR_ACTIONS);
}
return this.toolbarActions;
}

/**
* <!-- begin-user-doc --> <!-- end-user-doc -->
*
Expand All @@ -87,6 +111,8 @@ public EList<WidgetDescription> getWidgets() {
@Override
public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
switch (featureID) {
case ViewPackage.FORM_DESCRIPTION__TOOLBAR_ACTIONS:
return ((InternalEList<?>) this.getToolbarActions()).basicRemove(otherEnd, msgs);
case ViewPackage.FORM_DESCRIPTION__WIDGETS:
return ((InternalEList<?>) this.getWidgets()).basicRemove(otherEnd, msgs);
}
Expand All @@ -101,6 +127,8 @@ public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID,
@Override
public Object eGet(int featureID, boolean resolve, boolean coreType) {
switch (featureID) {
case ViewPackage.FORM_DESCRIPTION__TOOLBAR_ACTIONS:
return this.getToolbarActions();
case ViewPackage.FORM_DESCRIPTION__WIDGETS:
return this.getWidgets();
}
Expand All @@ -116,6 +144,10 @@ public Object eGet(int featureID, boolean resolve, boolean coreType) {
@Override
public void eSet(int featureID, Object newValue) {
switch (featureID) {
case ViewPackage.FORM_DESCRIPTION__TOOLBAR_ACTIONS:
this.getToolbarActions().clear();
this.getToolbarActions().addAll((Collection<? extends ButtonDescription>) newValue);
return;
case ViewPackage.FORM_DESCRIPTION__WIDGETS:
this.getWidgets().clear();
this.getWidgets().addAll((Collection<? extends WidgetDescription>) newValue);
Expand All @@ -132,6 +164,9 @@ public void eSet(int featureID, Object newValue) {
@Override
public void eUnset(int featureID) {
switch (featureID) {
case ViewPackage.FORM_DESCRIPTION__TOOLBAR_ACTIONS:
this.getToolbarActions().clear();
return;
case ViewPackage.FORM_DESCRIPTION__WIDGETS:
this.getWidgets().clear();
return;
Expand All @@ -147,6 +182,8 @@ public void eUnset(int featureID) {
@Override
public boolean eIsSet(int featureID) {
switch (featureID) {
case ViewPackage.FORM_DESCRIPTION__TOOLBAR_ACTIONS:
return this.toolbarActions != null && !this.toolbarActions.isEmpty();
case ViewPackage.FORM_DESCRIPTION__WIDGETS:
return this.widgets != null && !this.widgets.isEmpty();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1860,10 +1860,20 @@ public EClass getFormDescription() {
* @generated
*/
@Override
public EReference getFormDescription_Widgets() {
public EReference getFormDescription_ToolbarActions() {
return (EReference) this.formDescriptionEClass.getEStructuralFeatures().get(0);
}

/**
* <!-- begin-user-doc --> <!-- end-user-doc -->
*
* @generated
*/
@Override
public EReference getFormDescription_Widgets() {
return (EReference) this.formDescriptionEClass.getEStructuralFeatures().get(1);
}

/**
* <!-- begin-user-doc --> <!-- end-user-doc -->
*
Expand Down Expand Up @@ -3271,6 +3281,7 @@ public void createPackageContents() {
this.conditionalEdgeStyleEClass = this.createEClass(CONDITIONAL_EDGE_STYLE);

this.formDescriptionEClass = this.createEClass(FORM_DESCRIPTION);
this.createEReference(this.formDescriptionEClass, FORM_DESCRIPTION__TOOLBAR_ACTIONS);
this.createEReference(this.formDescriptionEClass, FORM_DESCRIPTION__WIDGETS);

this.widgetDescriptionEClass = this.createEClass(WIDGET_DESCRIPTION);
Expand Down Expand Up @@ -3782,6 +3793,8 @@ public void initializePackageContents() {
this.initEClass(this.conditionalEdgeStyleEClass, ConditionalEdgeStyle.class, "ConditionalEdgeStyle", !IS_ABSTRACT, !IS_INTERFACE, IS_GENERATED_INSTANCE_CLASS); //$NON-NLS-1$

this.initEClass(this.formDescriptionEClass, FormDescription.class, "FormDescription", !IS_ABSTRACT, !IS_INTERFACE, IS_GENERATED_INSTANCE_CLASS); //$NON-NLS-1$
this.initEReference(this.getFormDescription_ToolbarActions(), this.getButtonDescription(), null, "toolbarActions", null, 0, -1, FormDescription.class, !IS_TRANSIENT, !IS_VOLATILE, //$NON-NLS-1$
IS_CHANGEABLE, IS_COMPOSITE, !IS_RESOLVE_PROXIES, !IS_UNSETTABLE, IS_UNIQUE, !IS_DERIVED, IS_ORDERED);
this.initEReference(this.getFormDescription_Widgets(), this.getWidgetDescription(), null, "widgets", null, 0, -1, FormDescription.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, //$NON-NLS-1$
IS_COMPOSITE, !IS_RESOLVE_PROXIES, !IS_UNSETTABLE, IS_UNIQUE, !IS_DERIVED, IS_ORDERED);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,8 @@
<eLiterals name="UNSYNCHRONIZED" value="1"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="FormDescription" eSuperTypes="#//RepresentationDescription">
<eStructuralFeatures xsi:type="ecore:EReference" name="toolbarActions" upperBound="-1"
eType="#//ButtonDescription" containment="true"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="widgets" upperBound="-1"
eType="#//WidgetDescription" containment="true"/>
</eClassifiers>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@
</genClasses>
<genClasses ecoreClass="view.ecore#//ConditionalEdgeStyle"/>
<genClasses ecoreClass="view.ecore#//FormDescription">
<genFeatures property="None" children="true" createChild="true" ecoreFeature="ecore:EReference view.ecore#//FormDescription/toolbarActions"/>
<genFeatures property="None" children="true" createChild="true" ecoreFeature="ecore:EReference view.ecore#//FormDescription/widgets"/>
</genClasses>
<genClasses image="false" ecoreClass="view.ecore#//WidgetDescription">
Expand Down

0 comments on commit 05d1073

Please sign in to comment.