use of org.eclipse.sirius.components.forms.description.FormDescription 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
}
use of org.eclipse.sirius.components.forms.description.FormDescription 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
}
use of org.eclipse.sirius.components.forms.description.FormDescription 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
}
use of org.eclipse.sirius.components.forms.description.FormDescription in project sirius-components by eclipse-sirius.
the class FormEventProcessorFactory method createRepresentationEventProcessor.
@Override
public <T extends IRepresentationEventProcessor> Optional<T> createRepresentationEventProcessor(Class<T> representationEventProcessorClass, IRepresentationConfiguration configuration, IEditingContext editingContext) {
if (IFormEventProcessor.class.isAssignableFrom(representationEventProcessorClass) && configuration instanceof FormConfiguration) {
FormConfiguration formConfiguration = (FormConfiguration) configuration;
Optional<Form> optionalForm = this.representationSearchService.findById(editingContext, formConfiguration.getId(), Form.class);
if (optionalForm.isPresent()) {
Form form = optionalForm.get();
// @formatter:off
Optional<FormDescription> optionalFormDescription = this.representationDescriptionSearchService.findById(editingContext, form.getDescriptionId()).filter(FormDescription.class::isInstance).map(FormDescription.class::cast);
// @formatter:on
Optional<Object> optionalObject = this.objectService.getObject(editingContext, form.getTargetObjectId());
if (optionalFormDescription.isPresent() && optionalObject.isPresent()) {
FormDescription formDescription = optionalFormDescription.get();
Object object = optionalObject.get();
// @formatter:off
FormCreationParameters formCreationParameters = FormCreationParameters.newFormCreationParameters(formConfiguration.getId()).editingContext(editingContext).formDescription(formDescription).objects(List.of(object)).build();
// @formatter:on
IRepresentationEventProcessor formEventProcessor = new FormEventProcessor(formCreationParameters, this.formEventHandlers, this.subscriptionManagerFactory.create(), this.widgetSubscriptionManagerFactory.create(), this.representationRefreshPolicyRegistry);
// @formatter:off
return Optional.of(formEventProcessor).filter(representationEventProcessorClass::isInstance).map(representationEventProcessorClass::cast);
// @formatter:on
}
}
}
return Optional.empty();
}
use of org.eclipse.sirius.components.forms.description.FormDescription in project sirius-components by eclipse-sirius.
the class FormComponent method render.
@Override
public Element render() {
VariableManager variableManager = this.props.getVariableManager();
FormDescription formDescription = this.props.getFormDescription();
String id = formDescription.getIdProvider().apply(variableManager);
String label = formDescription.getLabelProvider().apply(variableManager);
String targetObjectId = formDescription.getTargetObjectIdProvider().apply(variableManager);
List<PageDescription> pageDescriptions = formDescription.getPageDescriptions();
List<Object> candidates = new ArrayList<>();
var optionalSelf = variableManager.get(VariableManager.SELF, Object.class);
if (optionalSelf.isPresent()) {
Object self = optionalSelf.get();
if (self instanceof Collection<?>) {
Collection<?> objects = (Collection<?>) self;
candidates.addAll(objects);
} else {
candidates.add(self);
}
}
// @formatter:off
List<Element> children = candidates.stream().map(candidate -> {
VariableManager childVariableManager = variableManager.createChild();
childVariableManager.put(VariableManager.SELF, candidate);
return childVariableManager;
}).flatMap(childVariableManager -> pageDescriptions.stream().map(pageDescription -> {
PageComponentProps pageComponentProps = new PageComponentProps(childVariableManager, pageDescription);
return new Element(PageComponent.class, pageComponentProps);
})).collect(Collectors.toList());
FormElementProps formElementProps = FormElementProps.newFormElementProps(id).label(label).targetObjectId(targetObjectId).descriptionId(formDescription.getId()).children(children).build();
return new Element(FormElementProps.TYPE, formElementProps);
// @formatter:on
}
Aggregations