Skip to content

Commit

Permalink
[1946] Enable child extenders in the View DSL implementation
Browse files Browse the repository at this point in the history
This allows downstream projects and applications to provide their own
sub-types of the DSL types (e.g. new WidgetDescriptions) and they will
be correctly detected and handled (provided they are properly
registered).

Bug: #1946
Signed-off-by: Pierre-Charles David <pierre-charles.david@obeo.fr>
  • Loading branch information
pcdavid committed May 10, 2023
1 parent efeafbd commit 87db7bc
Show file tree
Hide file tree
Showing 22 changed files with 139 additions and 23 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.adoc
Expand Up @@ -34,13 +34,16 @@ In the _styleDescription_, the definition of a color are now a select list of al

=== New Features

- https://github.com/eclipse-sirius/sirius-components/issues/1946[1#946] Enabled child extenders in the View DSL implementation.
This allows downstream projects and applications to provide their own sub-types of the DSL types (e.g. new WidgetDescriptions).
In addition to registering the extension metadmodel itself, users must provide a `ChildExtenderProvider` bean for their extensions to be properly integrated.

=== Improvements

- https://github.com/eclipse-sirius/sirius-components/issues/1869[#1869] [tree] Navigate to the first child with the right arrow if a node is expanded.
Navigate to the parent with the left arrow if a node is collapsed
- https://github.com/eclipse-sirius/sirius-components/issues/1621[#1621] [project] Migrate the onboard area to Material-UI


== v2023.4.0

=== Architectural decision records
Expand Down
@@ -0,0 +1,26 @@
/*******************************************************************************
* Copyright (c) 2023 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
*******************************************************************************/
package org.eclipse.sirius.components.emf.configuration;

import java.util.function.Supplier;

import org.eclipse.emf.edit.provider.IChildCreationExtender;

/**
* Used to extend EMF's global IChildCreationExtender.Descriptor.Registry with new IChildCreationExtender.
* Corresponds to the {@code org.eclipse.emf.edit.childCreationExtenders} extension point configuration.
*
* @author pcdavid
*/
public record ChildExtenderProvider(String nsURI, Supplier<IChildCreationExtender> childExtenderProvider) {
}
Expand Up @@ -12,6 +12,8 @@
*******************************************************************************/
package org.eclipse.sirius.components.emf.configuration;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import org.eclipse.emf.common.notify.AdapterFactory;
Expand All @@ -20,20 +22,31 @@
import org.eclipse.emf.ecore.impl.EPackageRegistryImpl;
import org.eclipse.emf.ecore.impl.EValidatorRegistryImpl;
import org.eclipse.emf.ecore.util.EcoreAdapterFactory;
import org.eclipse.emf.edit.EMFEditPlugin;
import org.eclipse.emf.edit.provider.ComposedAdapterFactory;
import org.eclipse.emf.edit.provider.IChildCreationExtender;
import org.eclipse.emf.edit.provider.IChildCreationExtender.Descriptor;
import org.eclipse.emf.edit.provider.ReflectiveItemProviderAdapterFactory;
import org.eclipse.sirius.components.emf.services.ILabelFeatureProvider;
import org.eclipse.sirius.components.emf.services.LabelFeatureProviderRegistry;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import jakarta.annotation.PostConstruct;

/**
* Configuration of the EMF beans.
*
* @author sbegaudeau
*/
@Configuration
public class EMFConfiguration {
private final List<ChildExtenderProvider> childExtenderProviders;

public EMFConfiguration(List<ChildExtenderProvider> childExtenderProviders) {
this.childExtenderProviders = List.copyOf(childExtenderProviders);
}

@Bean
public ComposedAdapterFactory composedAdapterFactory(List<AdapterFactory> adapterFactories) {
ComposedAdapterFactory composedAdapterFactory = new ComposedAdapterFactory(adapterFactories);
Expand All @@ -60,4 +73,19 @@ public LabelFeatureProviderRegistry labelFeatureProviderRegistry(List<ILabelFeat
public EValidator.Registry getEValidatorRegistry() {
return new EValidatorRegistryImpl(EValidator.Registry.INSTANCE);
}

@PostConstruct
public void initializeChildExtenders() {
var childExtenderRegistry = (IChildCreationExtender.Descriptor.Registry.Impl) EMFEditPlugin.getChildCreationExtenderDescriptorRegistry();
for (ChildExtenderProvider childExtenderProvider : this.childExtenderProviders) {
Collection<Descriptor> descriptors = childExtenderRegistry.get(childExtenderProvider.nsURI());
if (descriptors == null) {
descriptors = new ArrayList<>();
} else {
descriptors = new ArrayList<>(descriptors);
}
descriptors.add(childExtenderProvider.childExtenderProvider()::get);
childExtenderRegistry.put(childExtenderProvider.nsURI(), descriptors);
}
}
}
Expand Up @@ -14,6 +14,7 @@

import static org.assertj.core.api.Assertions.assertThat;

import java.util.List;
import java.util.Optional;
import java.util.UUID;

Expand Down Expand Up @@ -50,7 +51,7 @@ public Optional<Object> getObject(IEditingContext editingContext, String objectI
return Optional.of(ViewFactory.eINSTANCE.createFlexboxContainerDescription());
}
};
var handler = new AddWidgetEventHandler(objectService, new ICollaborativeFormDescriptionEditorMessageService.NoOp(), new SimpleMeterRegistry());
var handler = new AddWidgetEventHandler(objectService, new ICollaborativeFormDescriptionEditorMessageService.NoOp(), List.of(), new SimpleMeterRegistry());
var input = new AddWidgetInput(UUID.randomUUID(), "editingContextId", "representationId", "containerId", "Checkbox", 0);

assertThat(handler.canHandle(input)).isTrue();
Expand Down
Expand Up @@ -19,6 +19,7 @@
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.util.ResourceLocator;
import org.eclipse.emf.edit.provider.ComposeableAdapterFactory;
import org.eclipse.emf.edit.provider.IChildCreationExtender;
import org.eclipse.emf.edit.provider.IEditingDomainItemProvider;
import org.eclipse.emf.edit.provider.IItemLabelProvider;
import org.eclipse.emf.edit.provider.IItemPropertyDescriptor;
Expand Down Expand Up @@ -142,7 +143,7 @@ protected void collectNewChildDescriptors(Collection<Object> newChildDescriptors
*/
@Override
public ResourceLocator getResourceLocator() {
return ViewEditPlugin.INSTANCE;
return ((IChildCreationExtender) this.adapterFactory).getResourceLocator();
}

}
Expand Up @@ -19,6 +19,7 @@
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.util.ResourceLocator;
import org.eclipse.emf.edit.provider.ComposeableAdapterFactory;
import org.eclipse.emf.edit.provider.IChildCreationExtender;
import org.eclipse.emf.edit.provider.IEditingDomainItemProvider;
import org.eclipse.emf.edit.provider.IItemLabelProvider;
import org.eclipse.emf.edit.provider.IItemPropertyDescriptor;
Expand Down Expand Up @@ -216,7 +217,7 @@ protected void collectNewChildDescriptors(Collection<Object> newChildDescriptors
*/
@Override
public ResourceLocator getResourceLocator() {
return ViewEditPlugin.INSTANCE;
return ((IChildCreationExtender) this.adapterFactory).getResourceLocator();
}

}
Expand Up @@ -19,6 +19,7 @@
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.util.ResourceLocator;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.emf.edit.provider.IChildCreationExtender;
import org.eclipse.emf.edit.provider.IEditingDomainItemProvider;
import org.eclipse.emf.edit.provider.IItemLabelProvider;
import org.eclipse.emf.edit.provider.IItemPropertyDescriptor;
Expand Down Expand Up @@ -165,7 +166,7 @@ protected void collectNewChildDescriptors(Collection<Object> newChildDescriptors
*/
@Override
public ResourceLocator getResourceLocator() {
return ViewEditPlugin.INSTANCE;
return ((IChildCreationExtender) this.adapterFactory).getResourceLocator();
}

}
Expand Up @@ -19,6 +19,7 @@
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.util.ResourceLocator;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.emf.edit.provider.IChildCreationExtender;
import org.eclipse.emf.edit.provider.IEditingDomainItemProvider;
import org.eclipse.emf.edit.provider.IItemLabelProvider;
import org.eclipse.emf.edit.provider.IItemPropertyDescriptor;
Expand Down Expand Up @@ -203,7 +204,7 @@ public String getCreateChildText(Object owner, Object feature, Object child, Col
*/
@Override
public ResourceLocator getResourceLocator() {
return ViewEditPlugin.INSTANCE;
return ((IChildCreationExtender) this.adapterFactory).getResourceLocator();
}

}
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2021, 2022 Obeo.
* Copyright (c) 2021, 2023 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
Expand All @@ -18,6 +18,7 @@
import org.eclipse.emf.common.notify.AdapterFactory;
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.util.ResourceLocator;
import org.eclipse.emf.edit.provider.IChildCreationExtender;
import org.eclipse.emf.edit.provider.IEditingDomainItemProvider;
import org.eclipse.emf.edit.provider.IItemLabelProvider;
import org.eclipse.emf.edit.provider.IItemPropertyDescriptor;
Expand Down Expand Up @@ -118,7 +119,7 @@ protected void collectNewChildDescriptors(Collection<Object> newChildDescriptors
*/
@Override
public ResourceLocator getResourceLocator() {
return ViewEditPlugin.INSTANCE;
return ((IChildCreationExtender) this.adapterFactory).getResourceLocator();
}

}
Expand Up @@ -20,6 +20,7 @@
import org.eclipse.emf.common.util.ResourceLocator;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.emf.edit.provider.ComposeableAdapterFactory;
import org.eclipse.emf.edit.provider.IChildCreationExtender;
import org.eclipse.emf.edit.provider.IEditingDomainItemProvider;
import org.eclipse.emf.edit.provider.IItemLabelProvider;
import org.eclipse.emf.edit.provider.IItemPropertyDescriptor;
Expand Down Expand Up @@ -320,7 +321,7 @@ public String getCreateChildText(Object owner, Object feature, Object child, Col
*/
@Override
public ResourceLocator getResourceLocator() {
return ViewEditPlugin.INSTANCE;
return ((IChildCreationExtender) this.adapterFactory).getResourceLocator();
}

}
Expand Up @@ -19,6 +19,7 @@
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.util.ResourceLocator;
import org.eclipse.emf.edit.provider.ComposeableAdapterFactory;
import org.eclipse.emf.edit.provider.IChildCreationExtender;
import org.eclipse.emf.edit.provider.IEditingDomainItemProvider;
import org.eclipse.emf.edit.provider.IItemLabelProvider;
import org.eclipse.emf.edit.provider.IItemPropertyDescriptor;
Expand Down Expand Up @@ -194,7 +195,7 @@ protected void collectNewChildDescriptors(Collection<Object> newChildDescriptors
*/
@Override
public ResourceLocator getResourceLocator() {
return ViewEditPlugin.INSTANCE;
return ((IChildCreationExtender) this.adapterFactory).getResourceLocator();
}

}
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2021, 2022 Obeo.
* Copyright (c) 2021, 2023 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
Expand All @@ -18,6 +18,7 @@
import org.eclipse.emf.common.notify.AdapterFactory;
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.util.ResourceLocator;
import org.eclipse.emf.edit.provider.IChildCreationExtender;
import org.eclipse.emf.edit.provider.IEditingDomainItemProvider;
import org.eclipse.emf.edit.provider.IItemLabelProvider;
import org.eclipse.emf.edit.provider.IItemPropertyDescriptor;
Expand Down Expand Up @@ -118,7 +119,7 @@ protected void collectNewChildDescriptors(Collection<Object> newChildDescriptors
*/
@Override
public ResourceLocator getResourceLocator() {
return ViewEditPlugin.INSTANCE;
return ((IChildCreationExtender) this.adapterFactory).getResourceLocator();
}

}
Expand Up @@ -19,6 +19,7 @@
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.util.ResourceLocator;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.emf.edit.provider.IChildCreationExtender;
import org.eclipse.emf.edit.provider.IEditingDomainItemProvider;
import org.eclipse.emf.edit.provider.IItemLabelProvider;
import org.eclipse.emf.edit.provider.IItemPropertyDescriptor;
Expand Down Expand Up @@ -170,7 +171,7 @@ protected void collectNewChildDescriptors(Collection<Object> newChildDescriptors
*/
@Override
public ResourceLocator getResourceLocator() {
return ViewEditPlugin.INSTANCE;
return ((IChildCreationExtender) this.adapterFactory).getResourceLocator();
}

}
Expand Up @@ -19,6 +19,7 @@
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.util.ResourceLocator;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.emf.edit.provider.IChildCreationExtender;
import org.eclipse.emf.edit.provider.IEditingDomainItemProvider;
import org.eclipse.emf.edit.provider.IItemLabelProvider;
import org.eclipse.emf.edit.provider.IItemPropertyDescriptor;
Expand Down Expand Up @@ -163,7 +164,7 @@ protected void collectNewChildDescriptors(Collection<Object> newChildDescriptors
*/
@Override
public ResourceLocator getResourceLocator() {
return ViewEditPlugin.INSTANCE;
return ((IChildCreationExtender) this.adapterFactory).getResourceLocator();
}

}
Expand Up @@ -19,6 +19,7 @@
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.util.ResourceLocator;
import org.eclipse.emf.edit.provider.ComposeableAdapterFactory;
import org.eclipse.emf.edit.provider.IChildCreationExtender;
import org.eclipse.emf.edit.provider.IEditingDomainItemProvider;
import org.eclipse.emf.edit.provider.IItemLabelProvider;
import org.eclipse.emf.edit.provider.IItemPropertyDescriptor;
Expand Down Expand Up @@ -186,7 +187,7 @@ protected void collectNewChildDescriptors(Collection<Object> newChildDescriptors
*/
@Override
public ResourceLocator getResourceLocator() {
return ViewEditPlugin.INSTANCE;
return ((IChildCreationExtender) this.adapterFactory).getResourceLocator();
}

}
Expand Up @@ -19,6 +19,7 @@
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.util.ResourceLocator;
import org.eclipse.emf.edit.provider.ComposeableAdapterFactory;
import org.eclipse.emf.edit.provider.IChildCreationExtender;
import org.eclipse.emf.edit.provider.IEditingDomainItemProvider;
import org.eclipse.emf.edit.provider.IItemLabelProvider;
import org.eclipse.emf.edit.provider.IItemPropertyDescriptor;
Expand Down Expand Up @@ -139,7 +140,7 @@ protected void collectNewChildDescriptors(Collection<Object> newChildDescriptors
*/
@Override
public ResourceLocator getResourceLocator() {
return ViewEditPlugin.INSTANCE;
return ((IChildCreationExtender) this.adapterFactory).getResourceLocator();
}

}
Expand Up @@ -20,6 +20,7 @@
import org.eclipse.emf.common.util.ResourceLocator;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.emf.edit.provider.ComposeableAdapterFactory;
import org.eclipse.emf.edit.provider.IChildCreationExtender;
import org.eclipse.emf.edit.provider.IEditingDomainItemProvider;
import org.eclipse.emf.edit.provider.IItemLabelProvider;
import org.eclipse.emf.edit.provider.IItemPropertyDescriptor;
Expand Down Expand Up @@ -180,7 +181,7 @@ protected void collectNewChildDescriptors(Collection<Object> newChildDescriptors
*/
@Override
public ResourceLocator getResourceLocator() {
return ViewEditPlugin.INSTANCE;
return ((IChildCreationExtender) this.adapterFactory).getResourceLocator();
}

}
Expand Up @@ -19,6 +19,7 @@
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.util.ResourceLocator;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.emf.edit.provider.IChildCreationExtender;
import org.eclipse.emf.edit.provider.IEditingDomainItemProvider;
import org.eclipse.emf.edit.provider.IItemLabelProvider;
import org.eclipse.emf.edit.provider.IItemPropertyDescriptor;
Expand Down Expand Up @@ -180,7 +181,7 @@ protected void collectNewChildDescriptors(Collection<Object> newChildDescriptors
*/
@Override
public ResourceLocator getResourceLocator() {
return ViewEditPlugin.INSTANCE;
return ((IChildCreationExtender) this.adapterFactory).getResourceLocator();
}

}

0 comments on commit 87db7bc

Please sign in to comment.