Skip to content

Commit

Permalink
[3464] Improve i18n support for domain and view forms
Browse files Browse the repository at this point in the history
Bug: eclipse-sirius#3464
Signed-off-by: Denis Nikiforov <[email protected]>
  • Loading branch information
AresEkb committed May 13, 2024
1 parent be265b5 commit 3bd4a90
Show file tree
Hide file tree
Showing 35 changed files with 1,164 additions and 104 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ They still support returning an `java.time.Instant` object directly.
- https://github.com/eclipse-sirius/sirius-web/issues/3391[#3391] [diagram] Accept gradient for node background
- https://github.com/eclipse-sirius/sirius-web/issues/3435[#3435] [diagram] Extract diagram style from useDropNode
- https://github.com/eclipse-sirius/sirius-web/issues/3453[#3453] [diagram] Memoizing edges and nodes style
- https://github.com/eclipse-sirius/sirius-web/issues/3464[#3464] [view] Improve i18n support for domain and view forms

== v2024.3.0

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,7 @@ private Function<VariableManager, String> getOptionIdProvider() {
}

private Function<VariableManager, String> getOptionLabelProvider() {
return variableManager -> {
Object litteral = variableManager.getVariables().get(SelectComponent.CANDIDATE_VARIABLE);
if (litteral instanceof Enumerator) {
return ((Enumerator) litteral).getLiteral();
}
return "";
};
return new EEnumLiteralLabelProvider(EMFFormDescriptionProvider.ESTRUCTURAL_FEATURE, this.composedAdapterFactory);
}

private Function<VariableManager, Boolean> getOptionSelectedProvider() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*******************************************************************************
* Copyright (c) 2024 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.forms;

import java.util.Objects;
import java.util.function.Function;

import org.eclipse.emf.common.notify.Adapter;
import org.eclipse.emf.common.notify.AdapterFactory;
import org.eclipse.emf.common.util.Enumerator;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.emf.edit.provider.IItemPropertyDescriptor;
import org.eclipse.emf.edit.provider.IItemPropertySource;
import org.eclipse.sirius.components.forms.components.SelectComponent;
import org.eclipse.sirius.components.representations.VariableManager;

/**
* Utility class used to provide a label for an enumeration literal in the variable manager.
*
* @author aresekb
*/
public class EEnumLiteralLabelProvider implements Function<VariableManager, String> {

private final String featureVariableName;

private final AdapterFactory adapterFactory;

public EEnumLiteralLabelProvider(String featureVariableName, AdapterFactory adapterFactory) {
this.featureVariableName = Objects.requireNonNull(featureVariableName);
this.adapterFactory = Objects.requireNonNull(adapterFactory);
}

@Override
public String apply(VariableManager variableManager) {
Object object = variableManager.getVariables().get(VariableManager.SELF);
Object feature = variableManager.getVariables().get(this.featureVariableName);
Object literal = variableManager.getVariables().get(SelectComponent.CANDIDATE_VARIABLE);

String result = "";
if (object instanceof EObject eObject && feature instanceof EStructuralFeature eStructuralFeature) {
Adapter adapter = this.adapterFactory.adapt(eObject, IItemPropertySource.class);
if (adapter instanceof IItemPropertySource itemPropertySource) {
IItemPropertyDescriptor descriptor = itemPropertySource.getPropertyDescriptor(eObject, eStructuralFeature);
if (descriptor != null) {
result = descriptor.getLabelProvider(eObject).getText(literal);
}
}
}
if (result.isEmpty() && literal instanceof Enumerator enumerator) {
result = enumerator.getLiteral();
}
return result;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ private GroupDescription getGroupDescription() {

return GroupDescription.newGroupDescription("groupId")
.idProvider(variableManager -> "Core Properties")
.labelProvider(variableManager -> "Core Properties")
.labelProvider(variableManager -> this.emfMessageService.coreProperties())
.semanticElementsProvider(variableManager -> Collections.singletonList(variableManager.getVariables().get(VariableManager.SELF)))
.controlDescriptions(controlDescriptions)
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,8 @@ public List<ChildCreationDescription> getChildCreationDescriptions(IEditingConte

@Override
public Optional<Object> createChild(IEditingContext editingContext, Object object, String childCreationDescriptionId) {
String childEClassName = childCreationDescriptionId.replace(" ", "");

var optionalEditingDomain = Optional.of(editingContext)
.filter(IEMFEditingContext.class::isInstance)
.map(IEMFEditingContext.class::cast)
Expand All @@ -181,16 +183,9 @@ public Optional<Object> createChild(IEditingContext editingContext, Object objec
.map(CommandParameter.class::cast)
.toList();

Adapter adapter = editingDomain.getAdapterFactory().adapt(eObject, IEditingDomainItemProvider.class);
if (adapter instanceof IEditingDomainItemProvider editingDomainItemProvider) {
if (editingDomainItemProvider instanceof Helper helper) {
for (CommandParameter commandParameter : commandParameters) {
String text = helper.getCreateChildText(eObject, commandParameter.getFeature(), commandParameter.getValue(), null);

if (childCreationDescriptionId.equals(text)) {
return this.createObject(editingDomain, eObject, commandParameter);
}
}
for (CommandParameter commandParameter : commandParameters) {
if (commandParameter.getValue() instanceof EObject value && childEClassName.equals(value.eClass().getName())) {
return this.createObject(editingDomain, eObject, commandParameter);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2019, 2023 Obeo.
* Copyright (c) 2019, 2024 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 Down Expand Up @@ -52,4 +52,24 @@ public String upperBoundaryReached(String newInstanceClass, String feature) {
return this.messageSourceAccessor.getMessage("UPPER_BOUNDARY_REACHED", new Object[] { newInstanceClass, feature });
}

@Override
public String properties() {
return this.messageSourceAccessor.getMessage("PROPERTIES");
}

@Override
public String coreProperties() {
return this.messageSourceAccessor.getMessage("CORE_PROPERTIES");
}

@Override
public String general() {
return this.messageSourceAccessor.getMessage("GENERAL");
}

@Override
public String shapePreview() {
return this.messageSourceAccessor.getMessage("SHAPE_PREVIEW");
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2019, 2023 Obeo.
* Copyright (c) 2019, 2024 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 Down Expand Up @@ -27,6 +27,14 @@ public interface IEMFMessageService {

String upperBoundaryReached(String newInstanceClass, String feature);

String properties();

String coreProperties();

String general();

String shapePreview();

/**
* Implementation which does nothing, used for mocks in unit tests.
*
Expand All @@ -53,5 +61,25 @@ public String invalidNumber(String newValue) {
public String upperBoundaryReached(String newInstanceClass, String feature) {
return "";
}

@Override
public String properties() {
return "";
}

@Override
public String coreProperties() {
return "";
}

@Override
public String general() {
return "";
}

@Override
public String shapePreview() {
return "";
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
################################################################################
# Copyright (c) 2019, 2023 Obeo.
# Copyright (c) 2019, 2024 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 @@ -14,3 +14,7 @@ INVALID_INPUT = Invalid input type, "{0}" has been received while "{1}" was expe
UNEXPECTED_ERROR = An unexpected error has occurred, please contact the server administrator
INVALID_NUMBER = The new value "{0}" is not a valid number
UPPER_BOUNDARY_REACHED = Unable to create a new instance of "{0}" in feature "{1}" because it has reached its upper-bound cardinality.
PROPERTIES = Properties
CORE_PROPERTIES = Core Properties
GENERAL = General
SHAPE_PREVIEW = Shape Preview
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
################################################################################
# Copyright (c) 2024 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
#################################################################################
INVALID_INPUT = \u041D\u0435\u043A\u043E\u0440\u0440\u0435\u043A\u0442\u043D\u044B\u0439 \u0442\u0438\u043F, \u0431\u044B\u043B\u043E \u043F\u043E\u043B\u0443\u0447\u0435\u043D\u043E "{0}", \u0430 \u043E\u0436\u0438\u0434\u0430\u043B\u043E\u0441\u044C "{1}"
UNEXPECTED_ERROR = \u041F\u0440\u043E\u0438\u0437\u043E\u0448\u043B\u0430 \u043D\u0435\u043E\u0436\u0438\u0434\u0430\u043D\u043D\u0430\u044F \u043E\u0448\u0438\u0431\u043A\u0430, \u0441\u0432\u044F\u0436\u0438\u0442\u0435\u0441\u044C, \u043F\u043E\u0436\u0430\u043B\u0443\u0439\u0441\u0442\u0430, \u0441 \u0430\u0434\u043C\u0438\u043D\u0438\u0441\u0442\u0440\u0430\u0442\u043E\u0440\u043E\u043C
INVALID_NUMBER = \u041D\u043E\u0432\u043E\u0435 \u0437\u043D\u0430\u0447\u0435\u043D\u0438\u0435 "{0}" \u043D\u0435 \u044F\u0432\u043B\u044F\u0435\u0442\u0441\u044F \u0447\u0438\u0441\u043B\u043E\u043C
UPPER_BOUNDARY_REACHED = \u041D\u0435 \u0443\u0434\u0430\u043B\u043E\u0441\u044C \u0441\u043E\u0437\u0434\u0430\u0442\u044C \u043E\u0431\u044A\u0435\u043A\u0442 "{0}" \u0432 \u043A\u043E\u043B\u043B\u0435\u043A\u0446\u0438\u0438 "{1}", \u043F\u043E\u0442\u043E\u043C\u0443 \u0447\u0442\u043E \u0434\u043E\u0441\u0442\u0438\u0433\u043D\u0443\u0442 \u043F\u0440\u0435\u0434\u0435\u043B \u043D\u0430 \u043C\u0430\u043A\u0441\u0438\u043C\u0430\u043B\u044C\u043D\u043E\u0435 \u043A\u043E\u043B\u0438\u0447\u0435\u0441\u0442\u0432\u043E \u044D\u043B\u0435\u043C\u0435\u043D\u0442\u043E\u0432.
PROPERTIES = \u0421\u0432\u043E\u0439\u0441\u0442\u0432\u0430
CORE_PROPERTIES = \u041E\u0441\u043D\u043E\u0432\u043D\u044B\u0435 \u0441\u0432\u043E\u0439\u0441\u0442\u0432\u0430
GENERAL = \u041E\u0431\u0449\u0438\u0435
SHAPE_PREVIEW = \u041F\u0440\u0435\u0434\u043F\u0440\u043E\u0441\u043C\u043E\u0442\u0440 \u0444\u0438\u0433\u0443\u0440\u044B
Loading

0 comments on commit 3bd4a90

Please sign in to comment.