use of org.eclipse.sirius.components.representations.Failure in project sirius-components by eclipse-sirius.
the class NodeStylePropertiesConfigurer method createTextField.
private TextfieldDescription createTextField(String id, String title, Function<Object, String> reader, BiConsumer<Object, String> writer, Object feature) {
Function<VariableManager, String> valueProvider = variableManager -> variableManager.get(VariableManager.SELF, Object.class).map(reader).orElse(EMPTY);
BiFunction<VariableManager, String, IStatus> newValueHandler = (variableManager, newValue) -> {
var optionalDiagramMapping = variableManager.get(VariableManager.SELF, Object.class);
if (optionalDiagramMapping.isPresent()) {
writer.accept(optionalDiagramMapping.get(), newValue);
return new Success();
} else {
// $NON-NLS-1$
return new Failure("");
}
};
// @formatter:off
return TextfieldDescription.newTextfieldDescription(id).idProvider(variableManager -> id).labelProvider(variableManager -> title).valueProvider(valueProvider).newValueHandler(newValueHandler).diagnosticsProvider(this.getDiagnosticsProvider(feature)).kindProvider(this::kindProvider).messageProvider(this::messageProvider).build();
// @formatter:on
}
use of org.eclipse.sirius.components.representations.Failure in project sirius-components by eclipse-sirius.
the class CreateViewOperationHandlerTests method initialize.
@BeforeEach
public void initialize() {
this.operationTestContext = new OperationTestContext();
// @formatter:off
DiagramDescription diagramDescription = DiagramDescription.newDiagramDescription(UUID.randomUUID()).label(// $NON-NLS-1$
"DiagramDescriptionTest").targetObjectIdProvider(// $NON-NLS-1$
variableManager -> "diagramTargetObjectId").canCreatePredicate(variableManager -> true).labelProvider(// $NON-NLS-1$
variableManager -> "Diagram").toolSections(List.of()).nodeDescriptions(List.of(this.getNodeDescription(UUID.randomUUID()))).edgeDescriptions(List.of()).dropHandler(// $NON-NLS-1$
variableManager -> new Failure("")).build();
Diagram diagram = Diagram.newDiagram(UUID.randomUUID().toString()).descriptionId(diagramDescription.getId()).targetObjectId(UUID.randomUUID().toString()).label(// $NON-NLS-1$
"DiagramTest").position(Position.at(0, 0)).size(Size.of(100, 100)).nodes(new ArrayList<>()).edges(List.of()).build();
IDiagramContext diagramContext = new IDiagramContext.NoOp() {
@Override
public List<ViewCreationRequest> getViewCreationRequests() {
return new ArrayList<>();
}
};
this.operationTestContext.getVariables().put(IDiagramContext.DIAGRAM_CONTEXT, diagramContext);
// @formatter:on
AdapterFactoryEditingDomain editingDomain = new EditingDomainFactory().create();
EditingContext editingContext = new EditingContext(UUID.randomUUID().toString(), editingDomain);
this.operationTestContext.getVariables().put(IEditingContext.EDITING_CONTEXT, editingContext);
this.operationTestContext.getVariables().put(CONTAINER_VIEW, diagram);
this.createViewOperation = org.eclipse.sirius.diagram.description.tool.ToolFactory.eINSTANCE.createCreateView();
this.createViewOperationHandler = new CreateViewOperationHandler(this.operationTestContext.getObjectService(), this.operationTestContext.getRepresentationMetadataSearchService(), this.operationTestContext.getIdentifierProvider(), this.operationTestContext.getInterpreter(), new ChildModelOperationHandler(List.of()), this.createViewOperation);
}
use of org.eclipse.sirius.components.representations.Failure in project sirius-components by eclipse-sirius.
the class DeleteViewOperationHandlerTests method initialize.
@BeforeEach
public void initialize() {
this.operationTestContext = new OperationTestContext();
// @formatter:off
DiagramDescription diagramDescription = DiagramDescription.newDiagramDescription(UUID.randomUUID()).label(// $NON-NLS-1$
"DiagramDescriptionTest").targetObjectIdProvider(// $NON-NLS-1$
variableManager -> "diagramTargetObjectId").canCreatePredicate(variableManager -> true).labelProvider(// $NON-NLS-1$
variableManager -> "Diagram").toolSections(List.of()).nodeDescriptions(List.of(this.getNodeDescription(UUID.randomUUID()))).edgeDescriptions(List.of()).dropHandler(// $NON-NLS-1$
variableManager -> new Failure("")).build();
Node node = Node.newNode(UUID.randomUUID().toString()).descriptionId(UUID.randomUUID()).type(// $NON-NLS-1$
"Node").targetObjectId(UUID.randomUUID().toString()).targetObjectKind(// $NON-NLS-1$
"ecore::EPackage").targetObjectLabel(OperationTestContext.ROOT_PACKAGE_NAME).label(Label.newLabel(UUID.randomUUID().toString()).type(// $NON-NLS-1$
"Label").text(OperationTestContext.ROOT_PACKAGE_NAME).position(Position.at(0, 0)).size(Size.of(10, 10)).alignment(Position.at(0, 0)).style(// $NON-NLS-1$ //$NON-NLS-2$
LabelStyle.newLabelStyle().color("").fontSize(0).iconURL("").build()).build()).style(// $NON-NLS-1$
ImageNodeStyle.newImageNodeStyle().imageURL("").scalingFactor(0).build()).position(Position.at(0, 0)).size(Size.of(10, 10)).borderNodes(List.of()).childNodes(List.of()).build();
Diagram diagram = Diagram.newDiagram(UUID.randomUUID().toString()).descriptionId(diagramDescription.getId()).targetObjectId(UUID.randomUUID().toString()).label(// $NON-NLS-1$
"DiagramTest").position(Position.at(0, 0)).size(Size.of(100, 100)).nodes(List.of(node)).edges(List.of()).build();
IDiagramContext diagramContext = new IDiagramContext.NoOp() {
@Override
public List<ViewDeletionRequest> getViewDeletionRequests() {
return new ArrayList<>();
}
};
this.operationTestContext.getVariables().put(IDiagramContext.DIAGRAM_CONTEXT, diagramContext);
// @formatter:on
AdapterFactoryEditingDomain editingDomain = new EditingDomainFactory().create();
EditingContext editingContext = new EditingContext(UUID.randomUUID().toString(), editingDomain);
this.operationTestContext.getVariables().put(IEditingContext.EDITING_CONTEXT, editingContext);
this.operationTestContext.getVariables().put(CONTAINER_VIEW, diagram);
this.operationTestContext.getVariables().put(VariableManager.SELF, diagram.getNodes().get(0));
this.deleteViewOperation = ToolFactory.eINSTANCE.createDeleteView();
this.deleteViewOperationHandler = new DeleteViewOperationHandler(this.operationTestContext.getObjectService(), this.operationTestContext.getRepresentationMetadataSearchService(), this.operationTestContext.getIdentifierProvider(), this.operationTestContext.getInterpreter(), new ChildModelOperationHandler(List.of()), this.deleteViewOperation);
}
use of org.eclipse.sirius.components.representations.Failure in project sirius-components by eclipse-sirius.
the class DropOnDiagramEventHandler method handle.
@Override
public void handle(One<IPayload> payloadSink, Many<ChangeDescription> changeDescriptionSink, IEditingContext editingContext, IDiagramContext diagramContext, IDiagramInput diagramInput) {
String message = this.messageService.invalidInput(diagramInput.getClass().getSimpleName(), DropOnDiagramInput.class.getSimpleName());
var changeDescription = new ChangeDescription(ChangeKind.NOTHING, diagramInput.getRepresentationId(), diagramInput);
IPayload payload = new ErrorPayload(diagramInput.getId(), message);
if (diagramInput instanceof DropOnDiagramInput) {
DropOnDiagramInput input = (DropOnDiagramInput) diagramInput;
List<Object> objects = input.getObjectIds().stream().map(objectId -> this.objectService.getObject(editingContext, objectId)).flatMap(Optional::stream).collect(Collectors.toList());
Diagram diagram = diagramContext.getDiagram();
payload = new ErrorPayload(diagramInput.getId(), this.messageService.invalidDrop());
if (!objects.isEmpty()) {
IStatus status = this.executeTool(editingContext, diagramContext, objects, input.getDiagramTargetElementId(), input.getStartingPositionX(), input.getStartingPositionY());
if (status instanceof Success) {
changeDescription = new ChangeDescription(ChangeKind.SEMANTIC_CHANGE, diagramInput.getRepresentationId(), diagramInput);
payload = new DropOnDiagramSuccessPayload(diagramInput.getId(), diagram);
} else if (status instanceof Failure) {
payload = new ErrorPayload(diagramInput.getId(), ((Failure) status).getMessage());
}
}
}
payloadSink.tryEmitValue(payload);
changeDescriptionSink.tryEmitNext(changeDescription);
}
use of org.eclipse.sirius.components.representations.Failure in project sirius-components by eclipse-sirius.
the class DropOnDiagramEventHandler method executeTool.
private IStatus executeTool(IEditingContext editingContext, IDiagramContext diagramContext, List<Object> objects, String diagramElementId, double startingPositionX, double startingPositionY) {
// $NON-NLS-1$
IStatus result = new Failure("");
Diagram diagram = diagramContext.getDiagram();
Optional<Node> node = this.diagramQueryService.findNodeById(diagram, diagramElementId);
// @formatter:off
var optionalDropHandler = this.representationDescriptionSearchService.findById(editingContext, diagram.getDescriptionId()).filter(DiagramDescription.class::isInstance).map(DiagramDescription.class::cast).map(DiagramDescription::getDropHandler);
if (optionalDropHandler.isPresent()) {
result = new Success();
var dropHandler = optionalDropHandler.get();
Position newPosition = Position.at(startingPositionX, startingPositionY);
diagramContext.setDiagramEvent(new SinglePositionEvent(newPosition));
for (Object self : objects) {
VariableManager variableManager = new VariableManager();
if (node.isPresent()) {
variableManager.put(Node.SELECTED_NODE, node.get());
}
variableManager.put(IEditingContext.EDITING_CONTEXT, editingContext);
variableManager.put(IDiagramContext.DIAGRAM_CONTEXT, diagramContext);
variableManager.put(Environment.ENVIRONMENT, new Environment(Environment.SIRIUS_COMPONENTS));
variableManager.put(VariableManager.SELF, self);
IStatus dropResult = dropHandler.apply(variableManager);
if (dropResult instanceof Failure) {
// Let all drops finished but keep the error state
result = dropResult;
}
}
}
return result;
}
Aggregations