Skip to content

Commit

Permalink
[2163] Make EMF default form support non changeable features
Browse files Browse the repository at this point in the history
Bug: #2163
Signed-off-by: Laurent Fasani <[email protected]>
Signed-off-by: Florian ROUËNÉ <[email protected]>
  • Loading branch information
lfasani authored and sbegaudeau committed Oct 11, 2024
1 parent debe92a commit 148e0eb
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 15 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ This will allow specifier to create images that fir perfectly in the project tem
- https://github.com/eclipse-sirius/sirius-web/issues/4027[#4027] [forms] List widgets in read-only mode now still allow the selection of their items, but still prevent the invocation of the corresponding single or double-click handlers (which can perform mutations).
- https://github.com/eclipse-sirius/sirius-web/issues/3816[#3816] [form] Make EMF default form support Integer null value
- https://github.com/eclipse-sirius/sirius-web/issues/3826[#3826] [form] Make EMF default form support attributes with a date
- https://github.com/eclipse-sirius/sirius-web/issues/2163[#2163] [form] Make EMF default form support non changeable features


== v2024.9.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ private BiFunction<VariableManager, Boolean, IStatus> getNewValueHandler() {

private Function<VariableManager, Boolean> getIsReadOnlyProvider() {
return variableManager -> variableManager.get(EMFFormDescriptionProvider.ESTRUCTURAL_FEATURE, EAttribute.class)
.map(attr -> !attr.isChangeable())
.map(eAttribute -> !eAttribute.isChangeable())
.orElse(false);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,16 @@ private RadioDescription getRadioDescription() {
.diagnosticsProvider(this.propertiesValidationProvider.getDiagnosticsProvider())
.kindProvider(this.propertiesValidationProvider.getKindProvider())
.messageProvider(this.propertiesValidationProvider.getMessageProvider())
.isReadOnlyProvider(this.getIsReadOnlyProvider())
.build();
}

private Function<VariableManager, Boolean> getIsReadOnlyProvider() {
return variableManager -> variableManager.get(EMFFormDescriptionProvider.ESTRUCTURAL_FEATURE, EAttribute.class)
.map(eAttribute -> !eAttribute.isChangeable())
.orElse(false);
}

private Function<VariableManager, String> getLabelProvider() {
return new EStructuralFeatureLabelProvider(EMFFormDescriptionProvider.ESTRUCTURAL_FEATURE, this.composedAdapterFactory);
}
Expand Down Expand Up @@ -172,8 +179,7 @@ private BiFunction<VariableManager, String, IStatus> getNewValueHandler() {
EObject eObject = optionalEObject.get();
EAttribute eAttribute = optionalEAttribute.get();
EClassifier eType = eAttribute.getEType();
if (eType instanceof EEnum) {
EEnum eEnum = (EEnum) eType;
if (eType instanceof EEnum eEnum) {
EEnumLiteral literal = eEnum.getEEnumLiteral(id);
if (literal != null) {
Object value = EcoreUtil.createFromString(eEnum, literal.getLiteral());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
* @author sbegaudeau
*/
public class EStringIfDescriptionProvider {

private static final String IF_DESCRIPTION_ID = "EString";

private static final String TEXTAREA_DESCRIPTION_ID = "Textarea";
Expand Down Expand Up @@ -82,9 +83,16 @@ private TextareaDescription getTextareaDescription() {
.diagnosticsProvider(this.propertiesValidationProvider.getDiagnosticsProvider())
.kindProvider(this.propertiesValidationProvider.getKindProvider())
.messageProvider(this.propertiesValidationProvider.getMessageProvider())
.isReadOnlyProvider(this.getIsReadOnlyProvider())
.build();
}

private Function<VariableManager, Boolean> getIsReadOnlyProvider() {
return variableManager -> variableManager.get(EMFFormDescriptionProvider.ESTRUCTURAL_FEATURE, EAttribute.class)
.map(eAttribute -> !eAttribute.isChangeable())
.orElse(false);
}

private Function<VariableManager, String> getLabelProvider() {
return new EStructuralFeatureLabelProvider(EMFFormDescriptionProvider.ESTRUCTURAL_FEATURE, this.composedAdapterFactory);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
* @author lfasani
*/
public class InstantIfDescriptionProvider {

private static final String IF_DESCRIPTION_ID = "java.time.Instant";

private static final String DATE_TIME_DESCRIPTION_ID = "DateTime";
Expand Down Expand Up @@ -84,9 +85,16 @@ private DateTimeDescription getDateTimeDescription() {
.kindProvider(this.propertiesValidationProvider.getKindProvider())
.messageProvider(this.propertiesValidationProvider.getMessageProvider())
.type(DateTimeType.DATE_TIME)
.isReadOnlyProvider(this.getIsReadOnlyProvider())
.build();
}

private Function<VariableManager, Boolean> getIsReadOnlyProvider() {
return variableManager -> variableManager.get(EMFFormDescriptionProvider.ESTRUCTURAL_FEATURE, EAttribute.class)
.map(eAttribute -> !eAttribute.isChangeable())
.orElse(false);
}

private Function<VariableManager, String> getLabelProvider() {
return new EStructuralFeatureLabelProvider(EMFFormDescriptionProvider.ESTRUCTURAL_FEATURE, this.composedAdapterFactory);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,7 @@
*******************************************************************************/
package org.eclipse.sirius.components.emf.forms;

import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;
import java.util.List;
import java.util.Objects;
Expand All @@ -43,6 +39,7 @@
* @author lfasani
*/
public class LocalDateIfDescriptionProvider {

private static final String IF_DESCRIPTION_ID = "java.time.LocalDate";

private static final String DATE_DESCRIPTION_ID = "Date";
Expand Down Expand Up @@ -88,9 +85,16 @@ private DateTimeDescription getDateTimeDescription() {
.kindProvider(this.propertiesValidationProvider.getKindProvider())
.messageProvider(this.propertiesValidationProvider.getMessageProvider())
.type(DateTimeType.DATE)
.isReadOnlyProvider(this.getIsReadOnlyProvider())
.build();
}

private Function<VariableManager, Boolean> getIsReadOnlyProvider() {
return variableManager -> variableManager.get(EMFFormDescriptionProvider.ESTRUCTURAL_FEATURE, EAttribute.class)
.map(eAttribute -> !eAttribute.isChangeable())
.orElse(false);
}

private Function<VariableManager, String> getLabelProvider() {
return new EStructuralFeatureLabelProvider(EMFFormDescriptionProvider.ESTRUCTURAL_FEATURE, this.composedAdapterFactory);
}
Expand All @@ -106,8 +110,7 @@ private Function<VariableManager, String> getValueProvider() {

Object value = eObject.eGet(eAttribute);
if (value instanceof LocalDate localDate) {
Instant instant = localDate.atStartOfDay(ZoneId.of("UTC")).toInstant();
return DateTimeFormatter.ISO_INSTANT.format(instant);
return DateTimeFormatter.ISO_LOCAL_DATE.format(localDate);
}
}
return "";
Expand All @@ -127,8 +130,7 @@ private BiFunction<VariableManager, String, IStatus> getNewValueHandler() {
eObject.eSet(eAttribute, null);
status = new Success();
} else {
Instant instant = Instant.parse(newValue);
LocalDate localDate = LocalDateTime.ofInstant(instant, ZoneOffset.UTC).toLocalDate();
LocalDate localDate = LocalDate.parse(newValue);
eObject.eSet(eAttribute, localDate);
status = new Success();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,16 @@ private ReferenceWidgetDescription getReferenceWidgetDescription() {
.setHandlerProvider(this::handleSetReference)
.addHandlerProvider(this::handleAddReferenceValues)
.moveHandlerProvider(this::handleMoveReferenceValue)
.isReadOnlyProvider(this.getIsReadOnlyProvider())
.build();
}

private Function<VariableManager, Boolean> getIsReadOnlyProvider() {
return variableManager -> variableManager.get(EMFFormDescriptionProvider.ESTRUCTURAL_FEATURE, EStructuralFeature.class)
.map(eStructuralFeature -> !eStructuralFeature.isChangeable())
.orElse(false);
}

private List<?> getReferenceValue(VariableManager variableManager) {
List<?> value = List.of();
EStructuralFeature.Setting setting = this.resolveSetting(variableManager);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ private TextfieldDescription getTextfieldDescription() {
.diagnosticsProvider(this.propertiesValidationProvider.getDiagnosticsProvider())
.kindProvider(this.propertiesValidationProvider.getKindProvider())
.messageProvider(this.propertiesValidationProvider.getMessageProvider())
.isReadOnlyProvider(this.getIsReadOnlyProvider())
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export const DateTimeWidgetPropertySection: PropertySectionComponent<GQLDateTime
editingContextId,
representationId: formId,
widgetId: widget.id,
newValue: convertToUTCDateTimeString(state.editedValue),
newValue: convertToUTCDateTimeString(widget.type, state.editedValue),
};
const variables: GQLEditDateTimeMutationVariables = {
input,
Expand All @@ -116,7 +116,7 @@ export const DateTimeWidgetPropertySection: PropertySectionComponent<GQLDateTime

const onChange = (event: React.ChangeEvent<HTMLInputElement>) => {
const { value } = event.target;
if (value?.length > 0) {
if (value != null) {
setState((prevState) => ({ ...prevState, editedValue: value }));
}
};
Expand All @@ -127,7 +127,6 @@ export const DateTimeWidgetPropertySection: PropertySectionComponent<GQLDateTime
} else if (widget.type === 'TIME') {
type = 'time';
}

return (
<div
onBlur={(event: FocusEvent<HTMLDivElement, Element>) => {
Expand Down Expand Up @@ -179,9 +178,12 @@ const convertToLocalDateTimeString = (dateTimeType: string, dateTimeString: stri
return `${year}-${month}-${day}T${hours}:${minutes}`;
};

const convertToUTCDateTimeString = (dateTimeString: string): string => {
const convertToUTCDateTimeString = (dateTimeType: string, dateTimeString: string): string => {
const dateTime = new Date(dateTimeString);

if (dateTimeString.length == 0) {
return '';
}
// Get the local date and time components
const year = String(dateTime.getUTCFullYear()).padStart(4, '0');
const month = String(dateTime.getUTCMonth() + 1).padStart(2, '0');
Expand All @@ -190,5 +192,11 @@ const convertToUTCDateTimeString = (dateTimeString: string): string => {
const minutes = String(dateTime.getUTCMinutes()).padStart(2, '0');
const seconds = String(dateTime.getUTCSeconds()).padStart(2, '0');

if (dateTimeType === 'DATE') {
return `${year}-${month}-${day}`;
} else if (dateTimeType === 'TIME') {
return `${hours}:${minutes}`;
}

return `${year}-${month}-${day}T${hours}:${minutes}:${seconds}Z`;
};

0 comments on commit 148e0eb

Please sign in to comment.