use of org.eclipse.sirius.components.core.api.WorkbenchSelection in project sirius-components by eclipse-sirius.
the class NavigationOperationHandlerTests method testMultipleChildModelOperationWithSelection.
@Test
public void testMultipleChildModelOperationWithSelection() {
DiagramDescription firstDiagramDescription = DescriptionFactory.eINSTANCE.createDiagramDescription();
firstDiagramDescription.setLabel(FIRST_DIAGRAM_DESCRIPTION_ID.toString());
Navigation firstNavigation = ToolFactory.eINSTANCE.createNavigation();
firstNavigation.setCreateIfNotExistent(false);
firstNavigation.setDiagramDescription(firstDiagramDescription);
DiagramDescription secondDiagramDescription = DescriptionFactory.eINSTANCE.createDiagramDescription();
secondDiagramDescription.setLabel(SECOND_DIAGRAM_DESCRIPTION_ID.toString());
Navigation secondNavigation = ToolFactory.eINSTANCE.createNavigation();
secondNavigation.setCreateIfNotExistent(false);
secondNavigation.setDiagramDescription(secondDiagramDescription);
IStatus status = new ChildModelOperationHandler(List.of()).handle(new IObjectService.NoOp(), this.representationMetadataSearchService, this.diagramDescriptionIdentifierProvider, new AQLInterpreter(List.of(), List.of()), Map.of(IEditingContext.EDITING_CONTEXT, new IEditingContext.NoOp()), List.of(firstNavigation, secondNavigation));
assertThat(status).isInstanceOf(Success.class);
Success success = (Success) status;
Object selectionParameter = success.getParameters().get(Success.NEW_SELECTION);
assertThat(selectionParameter).isInstanceOf(WorkbenchSelection.class);
WorkbenchSelection selection = (WorkbenchSelection) selectionParameter;
// @formatter:off
assertThat(selection).isEqualTo(new WorkbenchSelection(List.of(new WorkbenchSelectionEntry(FIRST_DIAGRAM_ID, FIRST_DIAGRAM_LABEL, Diagram.KIND), new WorkbenchSelectionEntry(SECOND_DIAGRAM_ID, SECOND_DIAGRAM_LABEL, Diagram.KIND), new WorkbenchSelectionEntry(THIRD_DIAGRAM_ID, THIRD_DIAGRAM_LABEL, Diagram.KIND))));
// @formatter:on
}
use of org.eclipse.sirius.components.core.api.WorkbenchSelection in project sirius-components by eclipse-sirius.
the class InvokeSingleClickOnDiagramElementToolEventHandler method handle.
@Override
public void handle(One<IPayload> payloadSink, Many<ChangeDescription> changeDescriptionSink, IEditingContext editingContext, IDiagramContext diagramContext, IDiagramInput diagramInput) {
this.counter.increment();
String message = this.messageService.invalidInput(diagramInput.getClass().getSimpleName(), InvokeSingleClickOnDiagramElementToolInput.class.getSimpleName());
IPayload payload = new ErrorPayload(diagramInput.getId(), message);
ChangeDescription changeDescription = new ChangeDescription(ChangeKind.NOTHING, diagramInput.getRepresentationId(), diagramInput);
if (diagramInput instanceof InvokeSingleClickOnDiagramElementToolInput) {
InvokeSingleClickOnDiagramElementToolInput input = (InvokeSingleClickOnDiagramElementToolInput) diagramInput;
Diagram diagram = diagramContext.getDiagram();
// @formatter:off
var optionalTool = this.toolService.findToolById(editingContext, diagram, input.getToolId()).filter(SingleClickOnDiagramElementTool.class::isInstance).map(SingleClickOnDiagramElementTool.class::cast);
// @formatter:on
if (optionalTool.isPresent()) {
IStatus status = this.executeTool(editingContext, diagramContext, input.getDiagramElementId(), optionalTool.get(), input.getStartingPositionX(), input.getStartingPositionY(), input.getSelectedObjectId());
if (status instanceof Success) {
WorkbenchSelection newSelection = null;
Object newSelectionParameter = ((Success) status).getParameters().get(Success.NEW_SELECTION);
if (newSelectionParameter instanceof WorkbenchSelection) {
newSelection = (WorkbenchSelection) newSelectionParameter;
}
payload = new InvokeSingleClickOnDiagramElementToolSuccessPayload(diagramInput.getId(), newSelection);
changeDescription = new ChangeDescription(ChangeKind.SEMANTIC_CHANGE, diagramInput.getRepresentationId(), diagramInput);
} 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.core.api.WorkbenchSelection in project sirius-components by eclipse-sirius.
the class ChildModelOperationHandler method handle.
public IStatus handle(IObjectService objectService, IRepresentationMetadataSearchService representationMetadataSearchService, IIdentifierProvider identifierProvider, AQLInterpreter interpreter, Map<String, Object> variables, List<ModelOperation> modelOperations) {
Success success = new Success();
boolean hasBeenSuccessfullyExecuted = true;
ModelOperationHandlerSwitch modelOperationHandlerSwitch = new ModelOperationHandlerSwitch(objectService, representationMetadataSearchService, identifierProvider, this.externalJavaActionProviders, interpreter);
for (ModelOperation modelOperation : modelOperations) {
Optional<IModelOperationHandler> optionalModelOperationHandler = modelOperationHandlerSwitch.apply(modelOperation);
IStatus status = optionalModelOperationHandler.map(handler -> {
return handler.handle(variables);
}).orElse(// $NON-NLS-1$
new Failure(""));
hasBeenSuccessfullyExecuted = hasBeenSuccessfullyExecuted && status instanceof Success;
if (hasBeenSuccessfullyExecuted) {
// @formatter:off
var optionalChildModelOperationNewSelection = Optional.of(status).filter(Success.class::isInstance).map(Success.class::cast).map(result -> result.getParameters().get(Success.NEW_SELECTION)).filter(WorkbenchSelection.class::isInstance).map(WorkbenchSelection.class::cast);
if (optionalChildModelOperationNewSelection.isPresent()) {
WorkbenchSelection childWorkbenchSelection = optionalChildModelOperationNewSelection.get();
Object newSelection = success.getParameters().get(Success.NEW_SELECTION);
if (newSelection instanceof WorkbenchSelection) {
((WorkbenchSelection) newSelection).getEntries().addAll(childWorkbenchSelection.getEntries());
} else if (newSelection == null) {
success.getParameters().put(Success.NEW_SELECTION, new WorkbenchSelection(childWorkbenchSelection.getEntries()));
}
}
}
}
if (hasBeenSuccessfullyExecuted) {
return success;
}
// $NON-NLS-1$
return new Failure("");
}
use of org.eclipse.sirius.components.core.api.WorkbenchSelection in project sirius-components by eclipse-sirius.
the class InvokeSingleClickOnTwoDiagramElementsToolEventHandler method handle.
@Override
public void handle(One<IPayload> payloadSink, Many<ChangeDescription> changeDescriptionSink, IEditingContext editingContext, IDiagramContext diagramContext, IDiagramInput diagramInput) {
this.counter.increment();
String message = this.messageService.invalidInput(diagramInput.getClass().getSimpleName(), InvokeSingleClickOnTwoDiagramElementsToolInput.class.getSimpleName());
IPayload payload = new ErrorPayload(diagramInput.getId(), message);
ChangeDescription changeDescription = new ChangeDescription(ChangeKind.NOTHING, diagramInput.getRepresentationId(), diagramInput);
if (diagramInput instanceof InvokeSingleClickOnTwoDiagramElementsToolInput) {
InvokeSingleClickOnTwoDiagramElementsToolInput input = (InvokeSingleClickOnTwoDiagramElementsToolInput) diagramInput;
Diagram diagram = diagramContext.getDiagram();
// @formatter:off
var optionalTool = this.toolService.findToolById(editingContext, diagram, input.getToolId()).filter(SingleClickOnTwoDiagramElementsTool.class::isInstance).map(SingleClickOnTwoDiagramElementsTool.class::cast);
// @formatter:on
if (optionalTool.isPresent()) {
Position sourcePosition = Position.at(input.getSourcePositionX(), input.getSourcePositionY());
Position targetPosition = Position.at(input.getTargetPositionX(), input.getTargetPositionY());
IStatus status = this.executeTool(editingContext, diagramContext, input.getDiagramSourceElementId(), input.getDiagramTargetElementId(), optionalTool.get(), sourcePosition, targetPosition);
if (status instanceof Success) {
WorkbenchSelection newSelection = null;
Object newSelectionParameter = ((Success) status).getParameters().get(Success.NEW_SELECTION);
if (newSelectionParameter instanceof WorkbenchSelection) {
newSelection = (WorkbenchSelection) newSelectionParameter;
}
payload = new InvokeSingleClickOnTwoDiagramElementsToolSuccessPayload(diagramInput.getId(), newSelection);
changeDescription = new ChangeDescription(ChangeKind.SEMANTIC_CHANGE, diagramInput.getRepresentationId(), diagramInput);
} 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.core.api.WorkbenchSelection in project sirius-components by eclipse-sirius.
the class NavigationOperationHandler method handle.
@Override
public IStatus handle(Map<String, Object> variables) {
Success success = new Success();
Object editingContextVariable = variables.get(IEditingContext.EDITING_CONTEXT);
boolean createIfNotExistent = this.navigation.isCreateIfNotExistent();
if (!createIfNotExistent && editingContextVariable instanceof IEditingContext) {
IEditingContext editingContext = (IEditingContext) editingContextVariable;
DiagramDescription diagramDescription = this.navigation.getDiagramDescription();
String diagramDescriptionIdString = this.identifierProvider.getIdentifier(diagramDescription);
UUID diagramDescriptionId = UUID.fromString(diagramDescriptionIdString);
Object self = variables.get(VariableManager.SELF);
String selfId = this.objectService.getId(self);
// @formatter:off
List<WorkbenchSelectionEntry> entries = this.representationMetadataSearchService.findAllByTargetObjectId(editingContext, selfId).stream().filter(representationMetadata -> representationMetadata.getDescriptionId().equals(diagramDescriptionId)).map(representationMetadata -> {
String id = representationMetadata.getId();
String label = representationMetadata.getLabel();
String kind = representationMetadata.getKind();
return new WorkbenchSelectionEntry(id, label, kind);
}).collect(Collectors.toList());
// @formatter:on
if (!entries.isEmpty()) {
WorkbenchSelection newSelection = new WorkbenchSelection(entries);
success.getParameters().put(Success.NEW_SELECTION, newSelection);
}
}
return success;
}
Aggregations