Search in sources :

Example 1 with GroupDescription

use of org.eclipse.sirius.components.forms.description.GroupDescription in project sirius-components by eclipse-sirius.

the class NodeStylePropertiesConfigurer method getNodeStyleProperties.

private FormDescription getNodeStyleProperties() {
    // $NON-NLS-1$
    UUID formDescriptionId = UUID.nameUUIDFromBytes("nodestyle".getBytes());
    // @formatter:off
    List<AbstractControlDescription> controls = List.of(// $NON-NLS-1$ //$NON-NLS-2$
    this.createTextField(// $NON-NLS-1$ //$NON-NLS-2$
    "nodestyle.sizeExpression", // $NON-NLS-1$ //$NON-NLS-2$
    "Size Expression", style -> ((NodeStyle) style).getSizeComputationExpression(), (style, newSizeExpression) -> ((NodeStyle) style).setSizeComputationExpression(newSizeExpression), ViewPackage.Literals.NODE_STYLE__SIZE_COMPUTATION_EXPRESSION), // $NON-NLS-1$ //$NON-NLS-2$
    this.createTextField(// $NON-NLS-1$ //$NON-NLS-2$
    "nodestyle.labelColor", // $NON-NLS-1$ //$NON-NLS-2$
    "Label Color", style -> ((NodeStyle) style).getLabelColor(), (style, newLabelColor) -> ((NodeStyle) style).setLabelColor(newLabelColor), ViewPackage.Literals.NODE_STYLE__LABEL_COLOR), // $NON-NLS-1$ //$NON-NLS-2$
    this.createTextField(// $NON-NLS-1$ //$NON-NLS-2$
    "nodestyle.color", // $NON-NLS-1$ //$NON-NLS-2$
    "Color", style -> ((NodeStyle) style).getColor(), (style, newColor) -> ((NodeStyle) style).setColor(newColor), ViewPackage.Literals.STYLE__COLOR), // $NON-NLS-1$ //$NON-NLS-2$
    this.createTextField(// $NON-NLS-1$ //$NON-NLS-2$
    "nodestyle.borderColor", // $NON-NLS-1$ //$NON-NLS-2$
    "Border Color", style -> ((NodeStyle) style).getBorderColor(), (style, newColor) -> ((NodeStyle) style).setBorderColor(newColor), ViewPackage.Literals.BORDER_STYLE__BORDER_COLOR), // $NON-NLS-1$ //$NON-NLS-2$
    this.createTextField(// $NON-NLS-1$ //$NON-NLS-2$
    "nodestyle.borderRadius", // $NON-NLS-1$ //$NON-NLS-2$
    "Border Radius", style -> String.valueOf(((NodeStyle) style).getBorderRadius()), (style, newBorderRadius) -> {
        try {
            ((NodeStyle) style).setBorderRadius(Integer.parseInt(newBorderRadius));
        } catch (NumberFormatException nfe) {
        // Ignore.
        }
    }, ViewPackage.Literals.BORDER_STYLE__BORDER_RADIUS), // $NON-NLS-1$ //$NON-NLS-2$
    this.createTextField(// $NON-NLS-1$ //$NON-NLS-2$
    "nodestyle.borderSize", // $NON-NLS-1$ //$NON-NLS-2$
    "Border Size", style -> String.valueOf(((NodeStyle) style).getBorderSize()), (style, newBorderSize) -> {
        try {
            ((NodeStyle) style).setBorderSize(Integer.parseInt(newBorderSize));
        } catch (NumberFormatException nfe) {
        // Ignore.
        }
    }, ViewPackage.Literals.BORDER_STYLE__BORDER_SIZE), // $NON-NLS-1$
    this.createBorderLineStyleSelectionField("nodestyle.borderstyle", ViewPackage.Literals.BORDER_STYLE__BORDER_LINE_STYLE), // $NON-NLS-1$ //$NON-NLS-2$
    this.createCheckbox(// $NON-NLS-1$ //$NON-NLS-2$
    "nodestyle.listMode", // $NON-NLS-1$ //$NON-NLS-2$
    "List Mode", style -> ((NodeStyle) style).isListMode(), (style, newListMode) -> ((NodeStyle) style).setListMode(newListMode), ViewPackage.Literals.NODE_STYLE__LIST_MODE), // $NON-NLS-1$ //$NON-NLS-2$
    this.createTextField(// $NON-NLS-1$ //$NON-NLS-2$
    "nodestyle.fontSize", // $NON-NLS-1$ //$NON-NLS-2$
    "Font Size", style -> String.valueOf(((LabelStyle) style).getFontSize()), (style, newColor) -> {
        try {
            ((LabelStyle) style).setFontSize(Integer.parseInt(newColor));
        } catch (NumberFormatException nfe) {
        // Ignore.
        }
    }, ViewPackage.Literals.LABEL_STYLE__FONT_SIZE), // $NON-NLS-1$ //$NON-NLS-2$
    this.createCheckbox(// $NON-NLS-1$ //$NON-NLS-2$
    "nodestyle.italic", // $NON-NLS-1$ //$NON-NLS-2$
    "Italic", style -> ((LabelStyle) style).isItalic(), (style, newItalic) -> ((LabelStyle) style).setItalic(newItalic), ViewPackage.Literals.LABEL_STYLE__ITALIC), // $NON-NLS-1$ //$NON-NLS-2$
    this.createCheckbox(// $NON-NLS-1$ //$NON-NLS-2$
    "nodestyle.bold", // $NON-NLS-1$ //$NON-NLS-2$
    "Bold", style -> ((LabelStyle) style).isBold(), (style, newBold) -> ((LabelStyle) style).setBold(newBold), ViewPackage.Literals.LABEL_STYLE__BOLD), // $NON-NLS-1$ //$NON-NLS-2$
    this.createCheckbox(// $NON-NLS-1$ //$NON-NLS-2$
    "nodestyle.underline", // $NON-NLS-1$ //$NON-NLS-2$
    "Underline", style -> ((LabelStyle) style).isUnderline(), (style, newUnderline) -> ((LabelStyle) style).setUnderline(newUnderline), ViewPackage.Literals.LABEL_STYLE__UNDERLINE), // $NON-NLS-1$ //$NON-NLS-2$
    this.createCheckbox(// $NON-NLS-1$ //$NON-NLS-2$
    "nodestyle.strikeThrough", // $NON-NLS-1$ //$NON-NLS-2$
    "Strike Through", style -> ((LabelStyle) style).isStrikeThrough(), (style, newStrikeThrough) -> ((LabelStyle) style).setStrikeThrough(newStrikeThrough), ViewPackage.Literals.LABEL_STYLE__STRIKE_THROUGH), this.createShapeSelectionField(ViewPackage.Literals.NODE_STYLE__SHAPE));
    GroupDescription groupDescription = this.createSimpleGroupDescription(controls);
    Predicate<VariableManager> canCreatePagePredicate = variableManager -> variableManager.get(VariableManager.SELF, Object.class).filter(self -> self instanceof List<?>).map(self -> (List<?>) self).flatMap(self -> self.stream().findFirst()).filter(self -> self instanceof NodeStyle && !(self instanceof ConditionalNodeStyle)).isPresent();
    return FormDescription.newFormDescription(formDescriptionId).label(// $NON-NLS-1$
    "Node Style").labelProvider(variableManager -> variableManager.get(VariableManager.SELF, NodeStyle.class).map(NodeStyle::getColor).orElse(UNNAMED)).canCreatePredicate(variableManager -> true).idProvider(new GetOrCreateRandomIdProvider()).targetObjectIdProvider(this.getTargetObjectIdProvider()).pageDescriptions(List.of(this.createSimplePageDescription(groupDescription, canCreatePagePredicate))).groupDescriptions(List.of(groupDescription)).build();
// @formatter:on
}
Also used : IPropertiesDescriptionRegistryConfigurer(org.eclipse.sirius.components.collaborative.forms.services.api.IPropertiesDescriptionRegistryConfigurer) IEditingContext(org.eclipse.sirius.components.core.api.IEditingContext) LineStyle(org.eclipse.sirius.components.view.LineStyle) PageDescription(org.eclipse.sirius.components.forms.description.PageDescription) BiFunction(java.util.function.BiFunction) SelectComponent(org.eclipse.sirius.components.forms.components.SelectComponent) Function(java.util.function.Function) CustomImage(org.eclipse.sirius.components.emf.view.CustomImage) FormDescription(org.eclipse.sirius.components.forms.description.FormDescription) LabelStyle(org.eclipse.sirius.components.view.LabelStyle) IStatus(org.eclipse.sirius.components.representations.IStatus) TextfieldDescription(org.eclipse.sirius.components.forms.description.TextfieldDescription) ICustomImageSearchService(org.eclipse.sirius.components.emf.view.ICustomImageSearchService) BiConsumer(java.util.function.BiConsumer) IValidationService(org.eclipse.sirius.components.collaborative.validation.api.IValidationService) GroupDescription(org.eclipse.sirius.components.forms.description.GroupDescription) CheckboxDescription(org.eclipse.sirius.components.forms.description.CheckboxDescription) NodeStyle(org.eclipse.sirius.components.view.NodeStyle) Failure(org.eclipse.sirius.components.representations.Failure) Predicate(java.util.function.Predicate) SelectDescription(org.eclipse.sirius.components.forms.description.SelectDescription) Success(org.eclipse.sirius.components.representations.Success) Diagnostic(org.eclipse.emf.common.util.Diagnostic) EcoreUtil(org.eclipse.emf.ecore.util.EcoreUtil) EObject(org.eclipse.emf.ecore.EObject) UUID(java.util.UUID) ConditionalNodeStyle(org.eclipse.sirius.components.view.ConditionalNodeStyle) Collectors(java.util.stream.Collectors) ViewPackage(org.eclipse.sirius.components.view.ViewPackage) Objects(java.util.Objects) List(java.util.List) GetOrCreateRandomIdProvider(org.eclipse.sirius.components.representations.GetOrCreateRandomIdProvider) Component(org.springframework.stereotype.Component) AbstractControlDescription(org.eclipse.sirius.components.forms.description.AbstractControlDescription) BorderStyle(org.eclipse.sirius.components.view.BorderStyle) Optional(java.util.Optional) IPropertiesDescriptionRegistry(org.eclipse.sirius.components.collaborative.forms.services.api.IPropertiesDescriptionRegistry) VariableManager(org.eclipse.sirius.components.representations.VariableManager) Comparator(java.util.Comparator) VariableManager(org.eclipse.sirius.components.representations.VariableManager) NodeStyle(org.eclipse.sirius.components.view.NodeStyle) ConditionalNodeStyle(org.eclipse.sirius.components.view.ConditionalNodeStyle) LabelStyle(org.eclipse.sirius.components.view.LabelStyle) GroupDescription(org.eclipse.sirius.components.forms.description.GroupDescription) AbstractControlDescription(org.eclipse.sirius.components.forms.description.AbstractControlDescription) EObject(org.eclipse.emf.ecore.EObject) List(java.util.List) ConditionalNodeStyle(org.eclipse.sirius.components.view.ConditionalNodeStyle) UUID(java.util.UUID) GetOrCreateRandomIdProvider(org.eclipse.sirius.components.representations.GetOrCreateRandomIdProvider)

Example 2 with GroupDescription

use of org.eclipse.sirius.components.forms.description.GroupDescription in project sirius-components by eclipse-sirius.

the class NodeStylePropertiesConfigurer method getConditionalNodeStyleProperties.

private FormDescription getConditionalNodeStyleProperties() {
    // $NON-NLS-1$
    UUID formDescriptionId = UUID.nameUUIDFromBytes("conditionalnodestyle".getBytes());
    // @formatter:off
    List<AbstractControlDescription> controls = List.of(// $NON-NLS-1$ //$NON-NLS-2$
    this.createTextField(// $NON-NLS-1$ //$NON-NLS-2$
    "conditionalnodestyle.sizeExpression", // $NON-NLS-1$ //$NON-NLS-2$
    "Size Expression", style -> ((NodeStyle) style).getSizeComputationExpression(), (style, newSizeExpression) -> ((NodeStyle) style).setSizeComputationExpression(newSizeExpression), ViewPackage.Literals.NODE_STYLE__SIZE_COMPUTATION_EXPRESSION), // $NON-NLS-1$ //$NON-NLS-2$
    this.createTextField(// $NON-NLS-1$ //$NON-NLS-2$
    "conditionalnodestyle.condition", // $NON-NLS-1$ //$NON-NLS-2$
    "Condition", style -> ((ConditionalNodeStyle) style).getCondition(), (style, newCondition) -> ((ConditionalNodeStyle) style).setCondition(newCondition), ViewPackage.Literals.CONDITIONAL__CONDITION), // $NON-NLS-1$ //$NON-NLS-2$
    this.createTextField(// $NON-NLS-1$ //$NON-NLS-2$
    "conditionalnodestyle.labelColor", // $NON-NLS-1$ //$NON-NLS-2$
    "Label Color", style -> ((NodeStyle) style).getLabelColor(), (style, newLabelColor) -> ((NodeStyle) style).setLabelColor(newLabelColor), ViewPackage.Literals.NODE_STYLE__LABEL_COLOR), // $NON-NLS-1$ //$NON-NLS-2$
    this.createTextField(// $NON-NLS-1$ //$NON-NLS-2$
    "conditionalnodestyle.color", // $NON-NLS-1$ //$NON-NLS-2$
    "Color", style -> ((NodeStyle) style).getColor(), (style, newColor) -> ((NodeStyle) style).setColor(newColor), ViewPackage.Literals.STYLE__COLOR), // $NON-NLS-1$ //$NON-NLS-2$
    this.createTextField(// $NON-NLS-1$ //$NON-NLS-2$
    "conditionalnodestyle.borderColor", // $NON-NLS-1$ //$NON-NLS-2$
    "Border Color", style -> ((NodeStyle) style).getBorderColor(), (style, newColor) -> ((NodeStyle) style).setBorderColor(newColor), ViewPackage.Literals.BORDER_STYLE__BORDER_COLOR), // $NON-NLS-1$ //$NON-NLS-2$
    this.createTextField(// $NON-NLS-1$ //$NON-NLS-2$
    "conditionalnodestyle.borderRadius", // $NON-NLS-1$ //$NON-NLS-2$
    "Border Radius", style -> String.valueOf(((NodeStyle) style).getBorderRadius()), (style, newBorderRadius) -> {
        try {
            ((NodeStyle) style).setBorderRadius(Integer.parseInt(newBorderRadius));
        } catch (NumberFormatException nfe) {
        // Ignore.
        }
    }, ViewPackage.Literals.BORDER_STYLE__BORDER_RADIUS), // $NON-NLS-1$ //$NON-NLS-2$
    this.createTextField(// $NON-NLS-1$ //$NON-NLS-2$
    "conditionalnodestyle.borderSize", // $NON-NLS-1$ //$NON-NLS-2$
    "Border Size", style -> String.valueOf(((NodeStyle) style).getBorderSize()), (style, newBorderSize) -> {
        try {
            ((NodeStyle) style).setBorderSize(Integer.parseInt(newBorderSize));
        } catch (NumberFormatException nfe) {
        // Ignore.
        }
    }, ViewPackage.Literals.BORDER_STYLE__BORDER_SIZE), // $NON-NLS-1$
    this.createBorderLineStyleSelectionField("conditionalnodestyle.borderstyle", ViewPackage.Literals.BORDER_STYLE__BORDER_LINE_STYLE), // $NON-NLS-1$ //$NON-NLS-2$
    this.createCheckbox(// $NON-NLS-1$ //$NON-NLS-2$
    "conditionalnodestyle.listMode", // $NON-NLS-1$ //$NON-NLS-2$
    "List Mode", style -> ((NodeStyle) style).isListMode(), (style, newListMode) -> ((NodeStyle) style).setListMode(newListMode), ViewPackage.Literals.NODE_STYLE__LIST_MODE), // $NON-NLS-1$ //$NON-NLS-2$
    this.createTextField(// $NON-NLS-1$ //$NON-NLS-2$
    "conditionalnodestyle.fontSize", // $NON-NLS-1$ //$NON-NLS-2$
    "Font Size", style -> String.valueOf(((LabelStyle) style).getFontSize()), (style, newColor) -> {
        try {
            ((LabelStyle) style).setFontSize(Integer.parseInt(newColor));
        } catch (NumberFormatException nfe) {
        // Ignore.
        }
    }, ViewPackage.Literals.LABEL_STYLE__FONT_SIZE), // $NON-NLS-1$ //$NON-NLS-2$
    this.createCheckbox(// $NON-NLS-1$ //$NON-NLS-2$
    "conditionalnodestyle.italic", // $NON-NLS-1$ //$NON-NLS-2$
    "Italic", style -> ((LabelStyle) style).isItalic(), (style, newItalic) -> ((LabelStyle) style).setItalic(newItalic), ViewPackage.Literals.LABEL_STYLE__ITALIC), // $NON-NLS-1$ //$NON-NLS-2$
    this.createCheckbox(// $NON-NLS-1$ //$NON-NLS-2$
    "conditionalnodestyle.bold", // $NON-NLS-1$ //$NON-NLS-2$
    "Bold", style -> ((LabelStyle) style).isBold(), (style, newBold) -> ((LabelStyle) style).setBold(newBold), ViewPackage.Literals.LABEL_STYLE__BOLD), // $NON-NLS-1$ //$NON-NLS-2$
    this.createCheckbox(// $NON-NLS-1$ //$NON-NLS-2$
    "conditionalnodestyle.underline", // $NON-NLS-1$ //$NON-NLS-2$
    "Underline", style -> ((LabelStyle) style).isUnderline(), (style, newUnderline) -> ((LabelStyle) style).setUnderline(newUnderline), ViewPackage.Literals.LABEL_STYLE__UNDERLINE), // $NON-NLS-1$ //$NON-NLS-2$
    this.createCheckbox(// $NON-NLS-1$ //$NON-NLS-2$
    "conditionalnodestyle.strikeThrough", // $NON-NLS-1$ //$NON-NLS-2$
    "Strike Through", style -> ((LabelStyle) style).isStrikeThrough(), (style, newStrikeThrough) -> ((LabelStyle) style).setStrikeThrough(newStrikeThrough), ViewPackage.Literals.LABEL_STYLE__STRIKE_THROUGH), this.createShapeSelectionField(ViewPackage.Literals.NODE_STYLE__SHAPE));
    GroupDescription groupDescription = this.createSimpleGroupDescription(controls);
    Predicate<VariableManager> canCreatePagePredicate = variableManager -> variableManager.get(VariableManager.SELF, Object.class).filter(self -> self instanceof List<?>).map(self -> (List<?>) self).flatMap(self -> self.stream().findFirst()).filter(self -> self instanceof ConditionalNodeStyle).isPresent();
    return FormDescription.newFormDescription(formDescriptionId).label(// $NON-NLS-1$
    "Conditional Node Style").labelProvider(variableManager -> variableManager.get(VariableManager.SELF, ConditionalNodeStyle.class).map(ConditionalNodeStyle::getCondition).orElse(UNNAMED)).canCreatePredicate(variableManager -> true).idProvider(new GetOrCreateRandomIdProvider()).targetObjectIdProvider(this.getTargetObjectIdProvider()).pageDescriptions(List.of(this.createSimplePageDescription(groupDescription, canCreatePagePredicate))).groupDescriptions(List.of(groupDescription)).build();
// @formatter:on
}
Also used : IPropertiesDescriptionRegistryConfigurer(org.eclipse.sirius.components.collaborative.forms.services.api.IPropertiesDescriptionRegistryConfigurer) IEditingContext(org.eclipse.sirius.components.core.api.IEditingContext) LineStyle(org.eclipse.sirius.components.view.LineStyle) PageDescription(org.eclipse.sirius.components.forms.description.PageDescription) BiFunction(java.util.function.BiFunction) SelectComponent(org.eclipse.sirius.components.forms.components.SelectComponent) Function(java.util.function.Function) CustomImage(org.eclipse.sirius.components.emf.view.CustomImage) FormDescription(org.eclipse.sirius.components.forms.description.FormDescription) LabelStyle(org.eclipse.sirius.components.view.LabelStyle) IStatus(org.eclipse.sirius.components.representations.IStatus) TextfieldDescription(org.eclipse.sirius.components.forms.description.TextfieldDescription) ICustomImageSearchService(org.eclipse.sirius.components.emf.view.ICustomImageSearchService) BiConsumer(java.util.function.BiConsumer) IValidationService(org.eclipse.sirius.components.collaborative.validation.api.IValidationService) GroupDescription(org.eclipse.sirius.components.forms.description.GroupDescription) CheckboxDescription(org.eclipse.sirius.components.forms.description.CheckboxDescription) NodeStyle(org.eclipse.sirius.components.view.NodeStyle) Failure(org.eclipse.sirius.components.representations.Failure) Predicate(java.util.function.Predicate) SelectDescription(org.eclipse.sirius.components.forms.description.SelectDescription) Success(org.eclipse.sirius.components.representations.Success) Diagnostic(org.eclipse.emf.common.util.Diagnostic) EcoreUtil(org.eclipse.emf.ecore.util.EcoreUtil) EObject(org.eclipse.emf.ecore.EObject) UUID(java.util.UUID) ConditionalNodeStyle(org.eclipse.sirius.components.view.ConditionalNodeStyle) Collectors(java.util.stream.Collectors) ViewPackage(org.eclipse.sirius.components.view.ViewPackage) Objects(java.util.Objects) List(java.util.List) GetOrCreateRandomIdProvider(org.eclipse.sirius.components.representations.GetOrCreateRandomIdProvider) Component(org.springframework.stereotype.Component) AbstractControlDescription(org.eclipse.sirius.components.forms.description.AbstractControlDescription) BorderStyle(org.eclipse.sirius.components.view.BorderStyle) Optional(java.util.Optional) IPropertiesDescriptionRegistry(org.eclipse.sirius.components.collaborative.forms.services.api.IPropertiesDescriptionRegistry) VariableManager(org.eclipse.sirius.components.representations.VariableManager) Comparator(java.util.Comparator) VariableManager(org.eclipse.sirius.components.representations.VariableManager) NodeStyle(org.eclipse.sirius.components.view.NodeStyle) ConditionalNodeStyle(org.eclipse.sirius.components.view.ConditionalNodeStyle) LabelStyle(org.eclipse.sirius.components.view.LabelStyle) GroupDescription(org.eclipse.sirius.components.forms.description.GroupDescription) AbstractControlDescription(org.eclipse.sirius.components.forms.description.AbstractControlDescription) EObject(org.eclipse.emf.ecore.EObject) List(java.util.List) ConditionalNodeStyle(org.eclipse.sirius.components.view.ConditionalNodeStyle) UUID(java.util.UUID) GetOrCreateRandomIdProvider(org.eclipse.sirius.components.representations.GetOrCreateRandomIdProvider)

Example 3 with GroupDescription

use of org.eclipse.sirius.components.forms.description.GroupDescription in project sirius-components by eclipse-sirius.

the class FormDescriptionAggregator method aggregate.

public Optional<FormDescription> aggregate(List<FormDescription> formDescriptions, List<Object> objects, IObjectService objectService) {
    VariableManager pageVariableManager = new VariableManager();
    pageVariableManager.put(VariableManager.SELF, objects);
    // @formatter:off
    List<PageDescription> pageDescriptions = formDescriptions.stream().flatMap(formDescription -> formDescription.getPageDescriptions().stream()).filter(pageDescription -> pageDescription.getCanCreatePredicate().test(pageVariableManager)).collect(Collectors.toList());
    if (pageDescriptions.isEmpty()) {
        return Optional.empty();
    }
    // @formatter:off
    List<GroupDescription> groupDescriptions = pageDescriptions.stream().flatMap(pageDescription -> pageDescription.getGroupDescriptions().stream()).collect(Collectors.toUnmodifiableList());
    Function<VariableManager, String> labelProvider = variableManager -> variableManager.get(VariableManager.SELF, Object.class).filter(self -> self instanceof List<?>).map(self -> (List<?>) self).flatMap(self -> self.stream().findFirst()).map(objectService::getFullLabel).orElse(// $NON-NLS-1$
    "Properties");
    // @formatter:on
    // @formatter:off
    Function<VariableManager, String> targetObjectIdProvider = variableManager -> variableManager.get(VariableManager.SELF, Object.class).filter(self -> self instanceof List<?>).map(self -> (List<?>) self).flatMap(self -> self.stream().findFirst()).map(objectService::getId).orElse(null);
    return Optional.of(FormDescription.newFormDescription(UUID.randomUUID()).label(// $NON-NLS-1$
    "Aggregated form description").idProvider(new GetOrCreateRandomIdProvider()).labelProvider(labelProvider).targetObjectIdProvider(targetObjectIdProvider).canCreatePredicate(variableManager -> false).pageDescriptions(pageDescriptions).groupDescriptions(groupDescriptions).build());
// @formatter:on
}
Also used : VariableManager(org.eclipse.sirius.components.representations.VariableManager) FormDescription(org.eclipse.sirius.components.forms.description.FormDescription) List(java.util.List) GetOrCreateRandomIdProvider(org.eclipse.sirius.components.representations.GetOrCreateRandomIdProvider) PageDescription(org.eclipse.sirius.components.forms.description.PageDescription) IObjectService(org.eclipse.sirius.components.core.api.IObjectService) Optional(java.util.Optional) GroupDescription(org.eclipse.sirius.components.forms.description.GroupDescription) UUID(java.util.UUID) VariableManager(org.eclipse.sirius.components.representations.VariableManager) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) GroupDescription(org.eclipse.sirius.components.forms.description.GroupDescription) PageDescription(org.eclipse.sirius.components.forms.description.PageDescription) List(java.util.List) GetOrCreateRandomIdProvider(org.eclipse.sirius.components.representations.GetOrCreateRandomIdProvider)

Example 4 with GroupDescription

use of org.eclipse.sirius.components.forms.description.GroupDescription in project sirius-components by eclipse-sirius.

the class PropertiesDefaultDescriptionProvider method getGroupDescription.

private GroupDescription getGroupDescription() {
    List<AbstractControlDescription> controlDescriptions = new ArrayList<>();
    Function<VariableManager, List<?>> iterableProvider = variableManager -> {
        List<Object> objects = new ArrayList<>();
        Object self = variableManager.getVariables().get(VariableManager.SELF);
        if (self instanceof EObject) {
            EObject eObject = (EObject) self;
            // @formatter:off
            List<IItemPropertyDescriptor> propertyDescriptors = Optional.ofNullable(this.composedAdapterFactory.adapt(eObject, IItemPropertySource.class)).filter(IItemPropertySource.class::isInstance).map(IItemPropertySource.class::cast).map(iItemPropertySource -> iItemPropertySource.getPropertyDescriptors(eObject)).orElse(new ArrayList<>());
            propertyDescriptors.stream().map(propertyDescriptor -> propertyDescriptor.getFeature(eObject)).filter(EStructuralFeature.class::isInstance).map(EStructuralFeature.class::cast).forEach(objects::add);
        // @formatter:on
        }
        return objects;
    };
    List<IfDescription> ifDescriptions = new ArrayList<>();
    ifDescriptions.add(new EStringIfDescriptionProvider(this.composedAdapterFactory, this.propertiesValidationProvider).getIfDescription());
    ifDescriptions.add(new EBooleanIfDescriptionProvider(this.composedAdapterFactory, this.propertiesValidationProvider).getIfDescription());
    ifDescriptions.add(new EEnumIfDescriptionProvider(this.composedAdapterFactory, this.propertiesValidationProvider).getIfDescription());
    ifDescriptions.add(new MonoValuedNonContainmentReferenceIfDescriptionProvider(this.composedAdapterFactory, this.objectService, this.propertiesValidationProvider).getIfDescription());
    ifDescriptions.add(new MultiValuedNonContainmentReferenceIfDescriptionProvider(this.composedAdapterFactory, this.objectService, this.propertiesValidationProvider).getIfDescription());
    // @formatter:off
    var numericDataTypes = List.of(EcorePackage.Literals.EINT, EcorePackage.Literals.EINTEGER_OBJECT, EcorePackage.Literals.EDOUBLE, EcorePackage.Literals.EDOUBLE_OBJECT, EcorePackage.Literals.EFLOAT, EcorePackage.Literals.EFLOAT_OBJECT, EcorePackage.Literals.ELONG, EcorePackage.Literals.ELONG_OBJECT, EcorePackage.Literals.ESHORT, EcorePackage.Literals.ESHORT_OBJECT);
    // @formatter:on
    for (var dataType : numericDataTypes) {
        ifDescriptions.add(new NumberIfDescriptionProvider(dataType, this.composedAdapterFactory, this.propertiesValidationProvider, this.emfMessageService).getIfDescription());
    }
    // @formatter:off
    ForDescription forDescription = // $NON-NLS-1$
    ForDescription.newForDescription("forId").iterator(ESTRUCTURAL_FEATURE).iterableProvider(iterableProvider).ifDescriptions(ifDescriptions).build();
    // @formatter:on
    controlDescriptions.add(forDescription);
    // @formatter:off
    return // $NON-NLS-1$
    GroupDescription.newGroupDescription("groupId").idProvider(// $NON-NLS-1$
    variableManager -> "Core Properties").labelProvider(// $NON-NLS-1$
    variableManager -> "Core Properties").semanticElementsProvider(variableManager -> Collections.singletonList(variableManager.getVariables().get(VariableManager.SELF))).controlDescriptions(controlDescriptions).build();
// @formatter:on
}
Also used : VariableManager(org.eclipse.sirius.components.representations.VariableManager) PageDescription(org.eclipse.sirius.components.forms.description.PageDescription) EcorePackage(org.eclipse.emf.ecore.EcorePackage) IObjectService(org.eclipse.sirius.components.core.api.IObjectService) IfDescription(org.eclipse.sirius.components.forms.description.IfDescription) IItemPropertyDescriptor(org.eclipse.emf.edit.provider.IItemPropertyDescriptor) EStructuralFeature(org.eclipse.emf.ecore.EStructuralFeature) Function(java.util.function.Function) ArrayList(java.util.ArrayList) FormDescription(org.eclipse.sirius.components.forms.description.FormDescription) Service(org.springframework.stereotype.Service) IPropertiesValidationProvider(org.eclipse.sirius.components.emf.compatibility.properties.api.IPropertiesValidationProvider) ForDescription(org.eclipse.sirius.components.forms.description.ForDescription) GroupDescription(org.eclipse.sirius.components.forms.description.GroupDescription) IEMFMessageService(org.eclipse.sirius.components.emf.services.messages.IEMFMessageService) EObject(org.eclipse.emf.ecore.EObject) UUID(java.util.UUID) IPropertiesDefaultDescriptionProvider(org.eclipse.sirius.components.collaborative.forms.api.IPropertiesDefaultDescriptionProvider) IItemPropertySource(org.eclipse.emf.edit.provider.IItemPropertySource) Objects(java.util.Objects) List(java.util.List) GetOrCreateRandomIdProvider(org.eclipse.sirius.components.representations.GetOrCreateRandomIdProvider) AbstractControlDescription(org.eclipse.sirius.components.forms.description.AbstractControlDescription) Optional(java.util.Optional) VariableManager(org.eclipse.sirius.components.representations.VariableManager) Collections(java.util.Collections) ComposedAdapterFactory(org.eclipse.emf.edit.provider.ComposedAdapterFactory) ArrayList(java.util.ArrayList) EStructuralFeature(org.eclipse.emf.ecore.EStructuralFeature) IItemPropertySource(org.eclipse.emf.edit.provider.IItemPropertySource) AbstractControlDescription(org.eclipse.sirius.components.forms.description.AbstractControlDescription) EObject(org.eclipse.emf.ecore.EObject) ArrayList(java.util.ArrayList) List(java.util.List) EObject(org.eclipse.emf.ecore.EObject) IfDescription(org.eclipse.sirius.components.forms.description.IfDescription) ForDescription(org.eclipse.sirius.components.forms.description.ForDescription)

Example 5 with GroupDescription

use of org.eclipse.sirius.components.forms.description.GroupDescription in project sirius-components by eclipse-sirius.

the class ViewExtensionDescriptionConverter method convert.

@Override
public FormDescription convert(ViewExtensionDescription viewExtensionDescription) {
    AQLInterpreter interpreter = this.interpreterFactory.create(viewExtensionDescription);
    PageDescriptionConverter pageDescriptionConverter = new PageDescriptionConverter(interpreter, this.identifierProvider, this.semanticCandidatesProviderFactory);
    GroupDescriptionConverter groupDescriptionConverter = new GroupDescriptionConverter(interpreter, this.objectService, this.identifierProvider, this.modelOperationHandlerSwitchProvider);
    // @formatter:off
    Map<org.eclipse.sirius.properties.GroupDescription, GroupDescription> siriusGroup2SiriusWebGroup = new HashMap<>();
    List<GroupDescription> groupDescriptions = viewExtensionDescription.getCategories().stream().flatMap(category -> category.getPages().stream()).flatMap(page -> page.getGroups().stream()).map(groupDescription -> groupDescriptionConverter.convert(groupDescription, siriusGroup2SiriusWebGroup)).collect(Collectors.toList());
    List<PageDescription> pageDescriptions = viewExtensionDescription.getCategories().stream().flatMap(category -> category.getPages().stream()).map(pageDescription -> pageDescriptionConverter.convert(pageDescription, siriusGroup2SiriusWebGroup)).collect(Collectors.toList());
    Function<VariableManager, String> labelProvider = variableManager -> variableManager.get(VariableManager.SELF, Object.class).filter(self -> self instanceof List<?>).map(self -> (List<?>) self).flatMap(self -> self.stream().findFirst()).map(this.objectService::getFullLabel).orElse(// $NON-NLS-1$
    "Properties");
    Function<VariableManager, String> targetObjectIdProvider = variableManager -> variableManager.get(VariableManager.SELF, Object.class).filter(self -> self instanceof List<?>).map(self -> (List<?>) self).flatMap(self -> self.stream().findFirst()).map(this.objectService::getId).orElse(null);
    return FormDescription.newFormDescription(UUID.fromString(this.identifierProvider.getIdentifier(viewExtensionDescription))).label(this.identifiedElementLabelProvider.getLabel(viewExtensionDescription)).idProvider(new GetOrCreateRandomIdProvider()).labelProvider(labelProvider).canCreatePredicate(variableManager -> false).targetObjectIdProvider(targetObjectIdProvider).pageDescriptions(pageDescriptions).groupDescriptions(groupDescriptions).build();
// @formatter:on
}
Also used : PageDescription(org.eclipse.sirius.components.forms.description.PageDescription) IModelOperationHandlerSwitchProvider(org.eclipse.sirius.components.compatibility.api.IModelOperationHandlerSwitchProvider) IObjectService(org.eclipse.sirius.components.core.api.IObjectService) HashMap(java.util.HashMap) UUID(java.util.UUID) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) AQLInterpreter(org.eclipse.sirius.components.interpreter.AQLInterpreter) ViewExtensionDescription(org.eclipse.sirius.properties.ViewExtensionDescription) Objects(java.util.Objects) FormDescription(org.eclipse.sirius.components.forms.description.FormDescription) List(java.util.List) GetOrCreateRandomIdProvider(org.eclipse.sirius.components.representations.GetOrCreateRandomIdProvider) IViewExtensionDescriptionConverter(org.eclipse.sirius.components.compatibility.services.forms.api.IViewExtensionDescriptionConverter) Service(org.springframework.stereotype.Service) Map(java.util.Map) ISemanticCandidatesProviderFactory(org.eclipse.sirius.components.compatibility.api.ISemanticCandidatesProviderFactory) GroupDescription(org.eclipse.sirius.components.forms.description.GroupDescription) VariableManager(org.eclipse.sirius.components.representations.VariableManager) IdentifiedElementLabelProvider(org.eclipse.sirius.components.compatibility.services.representations.IdentifiedElementLabelProvider) IIdentifierProvider(org.eclipse.sirius.components.compatibility.api.IIdentifierProvider) IAQLInterpreterFactory(org.eclipse.sirius.components.compatibility.api.IAQLInterpreterFactory) VariableManager(org.eclipse.sirius.components.representations.VariableManager) AQLInterpreter(org.eclipse.sirius.components.interpreter.AQLInterpreter) HashMap(java.util.HashMap) PageDescription(org.eclipse.sirius.components.forms.description.PageDescription) GroupDescription(org.eclipse.sirius.components.forms.description.GroupDescription) List(java.util.List) GetOrCreateRandomIdProvider(org.eclipse.sirius.components.representations.GetOrCreateRandomIdProvider)

Aggregations

GroupDescription (org.eclipse.sirius.components.forms.description.GroupDescription)12 List (java.util.List)11 VariableManager (org.eclipse.sirius.components.representations.VariableManager)11 Optional (java.util.Optional)10 PageDescription (org.eclipse.sirius.components.forms.description.PageDescription)10 Objects (java.util.Objects)9 UUID (java.util.UUID)9 Function (java.util.function.Function)9 FormDescription (org.eclipse.sirius.components.forms.description.FormDescription)9 IObjectService (org.eclipse.sirius.components.core.api.IObjectService)8 AbstractControlDescription (org.eclipse.sirius.components.forms.description.AbstractControlDescription)8 GetOrCreateRandomIdProvider (org.eclipse.sirius.components.representations.GetOrCreateRandomIdProvider)8 ArrayList (java.util.ArrayList)6 Collections (java.util.Collections)6 Collectors (java.util.stream.Collectors)6 Map (java.util.Map)5 Service (org.springframework.stereotype.Service)5 EObject (org.eclipse.emf.ecore.EObject)4 IEditingContext (org.eclipse.sirius.components.core.api.IEditingContext)4 HashMap (java.util.HashMap)3