use of org.eclipse.sirius.viewpoint.description.tool.InitialOperation in project sirius-components by eclipse-sirius.
the class WidgetDescriptionConverter method convertSelect.
private SelectDescription convertSelect(org.eclipse.sirius.properties.SelectDescription selectDescription) {
// @formatter:off
StringValueProvider labelProvider = new StringValueProvider(this.interpreter, selectDescription.getLabelExpression());
Function<VariableManager, String> valueProvider = variableManager -> {
String valueExpression = selectDescription.getValueExpression();
return this.interpreter.evaluateExpression(variableManager.getVariables(), valueExpression).asObject().map(this.objectService::getId).orElse(null);
};
// @formatter:on
Function<VariableManager, List<?>> optionsProvider = (variableManager) -> {
String candidateExpression = selectDescription.getCandidatesExpression();
return this.interpreter.evaluateExpression(variableManager.getVariables(), candidateExpression).asObjects().orElse(new ArrayList<>());
};
// $NON-NLS-1$
String candidateDisplayExpression = Optional.ofNullable(selectDescription.getCandidateDisplayExpression()).orElse("");
StringValueProvider optionLabelProvider = new StringValueProvider(this.interpreter, candidateDisplayExpression);
Function<VariableManager, String> optionIdProvider = variableManager -> {
Object candidate = variableManager.getVariables().get(SelectComponent.CANDIDATE_VARIABLE);
return this.objectService.getId(candidate);
};
BiFunction<VariableManager, String, IStatus> newValueHandler = (variableManager, newValue) -> {
Map<String, Object> variables = variableManager.getVariables();
variables.put(NEW_VALUE, newValue);
InitialOperation initialOperation = selectDescription.getInitialOperation();
ModelOperation modelOperation = initialOperation.getFirstModelOperations();
var modelOperationHandlerSwitch = this.modelOperationHandlerSwitchProvider.getModelOperationHandlerSwitch(this.interpreter);
Optional<IModelOperationHandler> optionalModelOperationHandler = modelOperationHandlerSwitch.apply(modelOperation);
return optionalModelOperationHandler.map(handler -> {
return handler.handle(variables);
}).orElse(// $NON-NLS-1$
new Failure(""));
};
// @formatter:off
return SelectDescription.newSelectDescription(this.identifierProvider.getIdentifier(selectDescription)).idProvider(new WidgetIdProvider()).labelProvider(labelProvider).valueProvider(valueProvider).optionsProvider(optionsProvider).optionIdProvider(optionIdProvider).optionLabelProvider(optionLabelProvider).newValueHandler(newValueHandler).diagnosticsProvider((variableManager) -> List.of()).kindProvider(// $NON-NLS-1$
(object) -> "").messageProvider(// $NON-NLS-1$
(object) -> "").build();
// @formatter:on
}
use of org.eclipse.sirius.viewpoint.description.tool.InitialOperation in project sirius-components by eclipse-sirius.
the class WidgetDescriptionConverter method convertCheckbox.
private CheckboxDescription convertCheckbox(org.eclipse.sirius.properties.CheckboxDescription checkboxDescription) {
StringValueProvider labelProvider = new StringValueProvider(this.interpreter, checkboxDescription.getLabelExpression());
BiFunction<VariableManager, Boolean, IStatus> newValueHandler = (variableManager, newValue) -> {
Map<String, Object> variables = variableManager.getVariables();
variables.put(NEW_VALUE, newValue);
InitialOperation initialOperation = checkboxDescription.getInitialOperation();
ModelOperation modelOperation = initialOperation.getFirstModelOperations();
var modelOperationHandlerSwitch = this.modelOperationHandlerSwitchProvider.getModelOperationHandlerSwitch(this.interpreter);
Optional<IModelOperationHandler> optionalModelOperationHandler = modelOperationHandlerSwitch.apply(modelOperation);
return optionalModelOperationHandler.map(handler -> {
return handler.handle(variables);
}).orElse(// $NON-NLS-1$
new Failure(""));
};
// $NON-NLS-1$
String valueExpression = Optional.ofNullable(checkboxDescription.getValueExpression()).orElse("");
Function<VariableManager, Boolean> valueProvider = new BooleanValueProvider(this.interpreter, valueExpression);
// @formatter:off
return CheckboxDescription.newCheckboxDescription(this.identifierProvider.getIdentifier(checkboxDescription)).idProvider(new WidgetIdProvider()).labelProvider(labelProvider).valueProvider(valueProvider).newValueHandler(newValueHandler).diagnosticsProvider((variableManager) -> List.of()).kindProvider(// $NON-NLS-1$
(object) -> "").messageProvider(// $NON-NLS-1$
(object) -> "").build();
// @formatter:on
}
use of org.eclipse.sirius.viewpoint.description.tool.InitialOperation in project sirius-components by eclipse-sirius.
the class WidgetDescriptionConverter method convertRadio.
private RadioDescription convertRadio(org.eclipse.sirius.properties.RadioDescription radioDescription) {
// $NON-NLS-1$
String labelExpression = Optional.ofNullable(radioDescription.getLabelExpression()).orElse("");
StringValueProvider labelProvider = new StringValueProvider(this.interpreter, labelExpression);
Function<VariableManager, String> optionIdProvider = variableManager -> {
Object candidate = variableManager.getVariables().get(RadioComponent.CANDIDATE_VARIABLE);
return this.objectService.getId(candidate);
};
Function<VariableManager, Boolean> optionSelectedProvider = variableManager -> {
Optional<Object> optionalResult = this.interpreter.evaluateExpression(variableManager.getVariables(), radioDescription.getValueExpression()).asObject();
Object candidate = variableManager.getVariables().get(RadioComponent.CANDIDATE_VARIABLE);
return optionalResult.map(candidate::equals).orElse(Boolean.FALSE);
};
Function<VariableManager, List<?>> optionsProvider = variableManager -> {
Optional<List<Object>> optional = this.interpreter.evaluateExpression(variableManager.getVariables(), radioDescription.getCandidatesExpression()).asObjects();
return optional.orElse(Collections.emptyList());
};
// $NON-NLS-1$
String candidateDisplayExpression = Optional.ofNullable(radioDescription.getCandidateDisplayExpression()).orElse("");
StringValueProvider optionLabelProvider = new StringValueProvider(this.interpreter, candidateDisplayExpression);
BiFunction<VariableManager, String, IStatus> newValueHandler = (variableManager, newValue) -> {
VariableManager childVariableManager = variableManager.createChild();
var optionalEditingContext = variableManager.get(IEditingContext.EDITING_CONTEXT, IEditingContext.class);
Optional<Object> optionalObject = optionalEditingContext.flatMap(context -> this.objectService.getObject(context, newValue));
if (optionalObject.isPresent()) {
childVariableManager.put(NEW_VALUE, optionalObject.get());
} else {
childVariableManager.put(NEW_VALUE, newValue);
}
InitialOperation initialOperation = radioDescription.getInitialOperation();
ModelOperation modelOperation = initialOperation.getFirstModelOperations();
var modelOperationHandlerSwitch = this.modelOperationHandlerSwitchProvider.getModelOperationHandlerSwitch(this.interpreter);
Optional<IModelOperationHandler> optionalModelOperationHandler = modelOperationHandlerSwitch.apply(modelOperation);
return optionalModelOperationHandler.map(handler -> {
return handler.handle(childVariableManager.getVariables());
}).orElse(// $NON-NLS-1$
new Failure(""));
};
// @formatter:off
return RadioDescription.newRadioDescription(this.identifierProvider.getIdentifier(radioDescription)).idProvider(new WidgetIdProvider()).labelProvider(labelProvider).optionIdProvider(optionIdProvider).optionLabelProvider(optionLabelProvider).optionSelectedProvider(optionSelectedProvider).optionsProvider(optionsProvider).newValueHandler(newValueHandler).diagnosticsProvider((variableManager) -> List.of()).kindProvider(// $NON-NLS-1$
(object) -> "").messageProvider(// $NON-NLS-1$
(object) -> "").build();
// @formatter:on
}
use of org.eclipse.sirius.viewpoint.description.tool.InitialOperation in project sirius-components by eclipse-sirius.
the class ToolConverter method createDeleteToolHandler.
public Function<VariableManager, IStatus> createDeleteToolHandler(DeleteElementDescription deleteDescription) {
var optionalInitialOperation = Optional.ofNullable(deleteDescription).map(DeleteElementDescription::getInitialOperation);
if (optionalInitialOperation.isPresent()) {
InitialOperation initialOperation = optionalInitialOperation.get();
return variableManager -> {
Map<String, Object> variables = variableManager.getVariables();
// Sirius Desktop Delete Tools expect an "element" variable to be available with the value
// of the initial invocation context (self).
// $NON-NLS-1$
variables.put("element", variables.get(VariableManager.SELF));
var selectedNode = variableManager.get(Node.SELECTED_NODE, Node.class);
if (selectedNode.isPresent()) {
variables.put(ELEMENT_VIEW, selectedNode.get());
var diagramContext = variableManager.get(IDiagramContext.DIAGRAM_CONTEXT, IDiagramContext.class);
if (diagramContext.isPresent()) {
variableManager.put(CONTAINER_VIEW, this.getParentNode(selectedNode.get(), diagramContext.get().getDiagram()));
}
}
var modelOperationHandlerSwitch = this.modelOperationHandlerSwitchProvider.getModelOperationHandlerSwitch(this.interpreter);
return modelOperationHandlerSwitch.apply(initialOperation.getFirstModelOperations()).map(handler -> {
return handler.handle(variables);
}).orElse(// $NON-NLS-1$
new Failure(""));
};
} else {
// If no delete tool is defined, execute the default behavior: delete the underlying semantic element.
return variableManager -> {
var optionalObject = variableManager.get(VariableManager.SELF, Object.class);
var optionalSelectedNode = variableManager.get(Node.SELECTED_NODE, Node.class);
var optionalDiagramContext = variableManager.get(IDiagramContext.DIAGRAM_CONTEXT, IDiagramContext.class);
if (optionalObject.isPresent()) {
Object object = optionalObject.get();
DeletionPolicy deletionPolicy = variableManager.get(DeleteFromDiagramEventHandler.DELETION_POLICY, DeletionPolicy.class).orElse(DeletionPolicy.SEMANTIC);
if (DeletionPolicy.SEMANTIC == deletionPolicy) {
this.editService.delete(object);
} else if (optionalDiagramContext.isPresent() && optionalSelectedNode.isPresent()) {
IDiagramContext diagramContext = optionalDiagramContext.get();
Node selectedNode = optionalSelectedNode.get();
// @formatter:off
ViewDeletionRequest viewDeletionRequest = ViewDeletionRequest.newViewDeletionRequest().elementId(selectedNode.getId()).build();
// @formatter:on
diagramContext.getViewDeletionRequests().add(viewDeletionRequest);
}
return new Success();
}
// $NON-NLS-1$
return new Failure("");
};
}
}
Aggregations